Skip to content

Commit bc2543a

Browse files
committed
sg_sanitize+sg_format: add --timeout=SEC option; sg_reassign+sg_write_same: fix ULONG_MAX problem
git-svn-id: svn://localhost/trunk@680 6180dd3e-e324-4e3e-922d-17de1ae2f315
1 parent ce73068 commit bc2543a

18 files changed

+268
-173
lines changed

ChangeLog

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ Each utility has its own version number, date of last change and
22
some description at the top of its ".c" file. All utilities in the main
33
directory have their own "man" pages. There is also a sg3_utils man page.
44

5-
Changelog for sg3_utils-1.43 [20160224] [svn: r679]
5+
Changelog for sg3_utils-1.43 [20160226] [svn: r680]
66
- sg_senddiag: add --timeout=SEC option
7+
- sg_sanitize: add --timeout=SEC option
8+
- sg_format: add --timeout=SEC option
9+
- sg_reassign+sg_write_same: fix ULONG_MAX problem
10+
- sg_turs+sg_requests: make both accept '--num=NUM'
11+
and '--number=NUM' for mutual compatibility
712
- shellcheck cleanup on scripts
813

914
Changelog for sg3_utils-1.42 [20160217] [svn: r663]

doc/sg_format.8

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH SG_FORMAT "8" "February 2016" "sg3_utils\-1.42" SG3_UTILS
1+
.TH SG_FORMAT "8" "February 2016" "sg3_utils\-1.43" SG3_UTILS
22
.SH NAME
33
sg_format \- format, resize a SCSI disk or format a tape
44
.SH SYNOPSIS
@@ -9,7 +9,8 @@ sg_format \- format, resize a SCSI disk or format a tape
99
[\fI\-\-mode=MP\fR] [\fI\-\-pfu=PFU\fR] [\fI\-\-pie=PIE\fR] [\fI\-\-pinfo\fR]
1010
[\fI\-\-poll=PT\fR] [\fI\-\-resize\fR] [\fI\-\-rto_req\fR]
1111
[\fI\-\-security\fR] [\fI\-\-six\fR] [\fI\-\-size=SIZE\fR] [\fI\-\-tape=FM\fR]
12-
[\fI\-\-verbose\fR] [\fI\-\-verify\fR] [\fI\-\-version\fR] [\fI\-\-wait\fR]
12+
[\fI\-\-timeout=SEC\fR] [\fI\-\-verbose\fR] [\fI\-\-verify\fR]
13+
[\fI\-\-version\fR] [\fI\-\-wait\fR]
1314
\fIDEVICE\fR
1415
.SH DESCRIPTION
1516
.\" Add any additional description here
@@ -266,6 +267,18 @@ set to \fIFM\fR. This option is used to prepare a tape (i.e. the "medium")
266267
in a tape drive for use. Values for \fIFM\fR include 0 to do the "default"
267268
format; 1 to partition a volume and 2 to do a default format then partition.
268269
.TP
270+
\fB\-m\fR, \fB\-\-timeout\fR=\fISEC\fR
271+
where \fISEC\fR is the FORMAT UNIT or FORMAT MEDIUM command timeout in
272+
seconds. \fISEC\fR will only be used if it exceeds the internal timeout
273+
which is 20 seconds if the IMMED bit is set and 72000 seconds (20 hours)
274+
if the IMMED bit is not set. If the timeout is exceeded then the
275+
operating system will typically abort the command. Aborting a command
276+
may escalate to a LUN reset (or worse). A timeout may also leave
277+
the disk or tape format operation incomplete. And that may result in the
278+
disk or tape being in a "format corrupt" state requiring another format
279+
to remedy the situation. So for various reasons timeouts are best
280+
avoided.
281+
.TP
269282
\fB\-v\fR, \fB\-\-verbose\fR
270283
increase the level of verbosity, (i.e. debug output). "\-vvv" gives
271284
a lot more debug output.
@@ -280,12 +293,10 @@ print the version string and then exit.
280293
\fB\-w\fR, \fB\-\-wait\fR
281294
the default format action is to set the "IMMED" bit in the FORMAT UNIT
282295
command's (short) parameter header. If this option (i.e. \fI\-\-wait\fR) is
283-
given then the "IMMED" bit is not set. If \fI\-\-wait\fR is given the
284-
FORMAT UNIT command waits until the format operation completes before
285-
returning its response. This can be many hours on large disks. This
286-
utility sets a 15 hour timeout on such a FORMAT UNIT command! Some recent
287-
SSDs go to the other extreme of completing a format operation in 1.5
288-
seconds hence waiting is not an issue.
296+
given then the "IMMED" bit is not set. If \fI\-\-wait\fR is given then the
297+
FORMAT UNIT or FORMAT MEDIUM command waits until the format operation
298+
completes before returning its response. This can be many hours on large
299+
disks. See the \fI\-\-timeout=SEC\fR option.
289300
.SH LISTS
290301
The SBC\-3 draft (revision 36) defines PLIST, CLIST, DLIST and GLIST in
291302
section 4.13 on "Medium defects". Briefly, the PLIST is the "primary"
@@ -381,15 +392,18 @@ can be terminated (e.g. with control\-C) without affecting the format
381392
operation which continues. However a target or device reset (or a power
382393
cycle) will probably cause the device to become "format corrupt".
383394
.PP
384-
When the \fI\-\-format\fR and \fI\-\-wait\fR options are both given then
385-
this utility may take a long time to return. In this case care should be
386-
taken not to send any other SCSI commands to the disk as it may not respond
387-
leaving those commands queued behind the active format command. This may
388-
cause a timeout in the OS driver (in a lot shorter period than 15 hours
389-
applicable to some format operations). This may result in the OS resetting
390-
the disk leaving the format operation incomplete. This may leave the
391-
disk in a "format corrupt" state requiring another format to remedy
392-
the situation.
395+
When the \fI\-\-format\fR (or \fI\-\-tape\fR) and \fI\-\-wait\fR options are
396+
both given then this utility may take a long time to return. In this case
397+
care should be taken not to send any other SCSI commands to the disk as it
398+
may not respond leaving those commands queued behind the active format
399+
command. This may cause a timeout in the OS driver (in a lot shorter period
400+
than 20 hours applicable to some format operations). This may result in the
401+
OS resetting the disk leaving the format operation incomplete. This may leave
402+
the disk in a "format corrupt" state requiring another format to remedy
403+
the situation. Modern SCSI devices should yield a "not ready" sense key
404+
with an additional sense indicating a format is in progress. With older
405+
devices the user should take precautions that nothing attempts to access
406+
a device while it is being formatted.
393407
.PP
394408
When the block size (i.e. the number of bytes in each block) is changed
395409
on a disk two SCSI commands must be sent: a MODE SELECT to change the block

doc/sg_requests.8

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
.TH SG_REQUESTS "8" "May 2014" "sg3_utils\-1.39" SG3_UTILS
1+
.TH SG_REQUESTS "8" "February 2016" "sg3_utils\-1.43" SG3_UTILS
22
.SH NAME
33
sg_requests \- send one or more SCSI REQUEST SENSE commands
44
.SH SYNOPSIS
55
.B sg_requests
66
[\fI\-\-desc\fR] [\fI\-\-help\fR] [\fI\-\-hex\fR] [\fI\-\-maxlen=LEN\fR]
7-
[\fI\-\-num=NUM\fR] [\fI\-\-progress\fR] [\fI\-\-raw\fR] [\fI\-\-status\fR]
8-
[\fI\-\-time\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR
7+
[\fI\-\-num=NUM\fR] [\fI\-\-number=NUM\fR] [\fI\-\-progress\fR]
8+
[\fI\-\-raw\fR] [\fI\-\-status\fR] [\fI\-\-time\fR] [\fI\-\-verbose\fR]
9+
[\fI\-\-version\fR] \fIDEVICE\fR
910
.SH DESCRIPTION
1011
.\" Add any additional description here
1112
.PP
@@ -42,6 +43,9 @@ cdb's "allocation length" field. If not given (or \fILEN\fR is zero) then
4243
perform \fINUM\fR SCSI REQUEST SENSE commands, stopping when either \fINUM\fR
4344
is reached or an error occurs. The default value for \fINUM\fR is 1 .
4445
.TP
46+
\fB\-\-number\fR=\fINUM\fR
47+
same action as \fI\-\-num=NUM\fR. Added for compatibility with sg_turs.
48+
.TP
4549
\fB\-p\fR, \fB\-\-progress\fR
4650
show progress indication (a percentage) if available. If \fI\-\-number=NUM\fR
4751
is given, \fINUM\fR is greater than 1 and an initial progress indication
@@ -103,8 +107,8 @@ SBC\-3). Several long duration SCSI commands associated with tape drives also
103107
use the progress indication (see SSC\-3).
104108
.PP
105109
Early standards suggested that the SCSI TEST UNIT READY command be used for
106-
polling the progress indication. More recent standards seem to suggest
107-
the SCSI REQUEST SENSE command should be used instead.
110+
polling the progress indication (see the sg_turs utility). Since SPC\-3 the
111+
standards suggest that the SCSI REQUEST SENSE command should be used instead.
108112
.PP
109113
The \fIDEVICE\fR is opened with a read\-only flag (e.g. in Unix with the
110114
O_RDONLY flag).
@@ -116,9 +120,9 @@ Written by Douglas Gilbert.
116120
.SH "REPORTING BUGS"
117121
Report bugs to <dgilbert at interlog dot com>.
118122
.SH COPYRIGHT
119-
Copyright \(co 2004\-2014 Douglas Gilbert
123+
Copyright \(co 2004\-2016 Douglas Gilbert
120124
.br
121125
This software is distributed under a FreeBSD license. There is NO
122126
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
123127
.SH "SEE ALSO"
124-
.B sg3_utils
128+
.B sg_turs (sg3_utils)

doc/sg_sanitize.8

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH SG_SANITIZE "8" "November 2015" "sg3_utils\-1.42" SG3_UTILS
1+
.TH SG_SANITIZE "8" "February 2016" "sg3_utils\-1.43" SG3_UTILS
22
.SH NAME
33
sg_sanitize \- remove all user data from disk with SCSI SANITIZE command
44
.SH SYNOPSIS
@@ -7,8 +7,8 @@ sg_sanitize \- remove all user data from disk with SCSI SANITIZE command
77
[\fI\-\-desc\fR] [\fI\-\-early\fR] [\fI\-\-fail\fR] [\fI\-\-help\fR]
88
[\fI\-\-invert\fR] [\fI\-\-ipl=LEN\fR] [\fI\-\-overwrite\fR]
99
[\fI\-\-pattern=PF\fR] [\fI\-\-quick\fR] [\fI\-\-test=TE\fR]
10-
[\fI\-\-verbose\fR] [\fI\-\-version\fR] [\fI\-\-wait\fR] [\fI\-\-zero\fR]
11-
[\fI\-\-znr\fR] \fIDEVICE\fR
10+
[\fI\-\-timeout=SEC\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR]
11+
[\fI\-\-wait\fR] [\fI\-\-zero\fR] [\fI\-\-znr\fR] \fIDEVICE\fR
1212
.SH DESCRIPTION
1313
.\" Add any additional description here
1414
.PP
@@ -36,7 +36,7 @@ in case the wrong \fIDEVICE\fR has been given.
3636
If the \fI\-\-early\fR option is given then this utility will exit soon
3737
after starting the SANITIZE command with the IMMED bit set. The user can
3838
monitor the progress of the sanitize operation with
39-
the "sg_request \-\-num=9999 \-\-progress" which sends a REQUEST SENSE
39+
the "sg_requests \-\-num=9999 \-\-progress" which sends a REQUEST SENSE
4040
command every 30 seconds. Otherwise if the \fI\-\-wait\fR option is given
4141
then this utility will wait until the SANITIZE command completes (or fails)
4242
and that can be many hours.
@@ -124,6 +124,10 @@ set the TEST field in the overwrite service action parameter list. This
124124
only affects the "overwrite" sanitize operation. The default is to place
125125
0 in that field.
126126
.TP
127+
\fB\-t\fR, \fB\-\-timeout\fR=\fISEC\fR
128+
where \fISEC\fR is the number of seconds used for the timeout on the
129+
SANITIZE command.
130+
.TP
127131
\fB\-v\fR, \fB\-\-verbose\fR
128132
increase the level of verbosity, (i.e. debug output).
129133
.TP
@@ -230,7 +234,7 @@ Written by Douglas Gilbert.
230234
.SH "REPORTING BUGS"
231235
Report bugs to <dgilbert at interlog dot com>.
232236
.SH COPYRIGHT
233-
Copyright \(co 2011\-2015 Douglas Gilbert
237+
Copyright \(co 2011\-2016 Douglas Gilbert
234238
.br
235239
This software is distributed under a FreeBSD license. There is NO
236240
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

doc/sg_sync.8

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
.TH SG_SYNC "8" "July 2013" "sg3_utils\-1.37" SG3_UTILS
1+
.TH SG_SYNC "8" "February 2016" "sg3_utils\-1.43" SG3_UTILS
22
.SH NAME
33
sg_sync \- send SCSI SYNCHRONIZE CACHE command
44
.SH SYNOPSIS
55
.B sg_sync
66
[\fI\-\-16\fR] [\fI\-\-count=COUNT\fR] [\fI\-\-group=GN\fR]
77
[\fI\-\-help\fR] [\fI\-\-immed\fR] [\fI\-\-lba=LBA\fR] [\fI\-\-sync\-nv\fR]
8-
[\fI\-\-timeout=SECS\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR
8+
[\fI\-\-timeout=SEC\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR
99
.SH DESCRIPTION
1010
.\" Add any additional description here
1111
.PP
@@ -58,8 +58,8 @@ option (or if there is no non\-volatile cache in the device) the
5858
synchronization is with the medium. The SYNC_NV bit was made obsolete in
5959
SBC\-3 revision 35d.
6060
.TP
61-
\fB\-t\fR, \fB\-\-timeout\fR=\fISECS\fR
62-
where \fISECS\fR is the number of seconds the OS allows the SYNCHRONIZE
61+
\fB\-t\fR, \fB\-\-timeout\fR=\fISEC\fR
62+
where \fISEC\fR is the number of seconds the OS allows the SYNCHRONIZE
6363
CACHE(16) to complete before it tries to cancel the command. Cancelling
6464
commands (typically with the task management function "abort task") is
6565
best avoided. Note this option is only active together with the \fI\-\-16\fR
@@ -89,7 +89,7 @@ Written by Douglas Gilbert.
8989
.SH "REPORTING BUGS"
9090
Report bugs to <dgilbert at interlog dot com>.
9191
.SH COPYRIGHT
92-
Copyright \(co 2004\-2013 Douglas Gilbert
92+
Copyright \(co 2004\-2016 Douglas Gilbert
9393
.br
9494
This software is distributed under a FreeBSD license. There is NO
9595
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

doc/sg_turs.8

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
.TH SG_TURS "8" "May 2014" "sg3_utils\-1.39" SG3_UTILS
1+
.TH SG_TURS "8" "Fenruary 2016" "sg3_utils\-1.43" SG3_UTILS
22
.SH NAME
33
sg_turs \- send one or more SCSI TEST UNIT READY commands
44
.SH SYNOPSIS
55
.B sg_turs
6-
[\fI\-\-help\fR] [\fI\-\-number=NUM\fR] [\fI\-\-progress\fR] [\fI\-\-time\fR]
7-
[\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR
6+
[\fI\-\-help\fR] [\fI\-\-number=NUM\fR] [\fI\-\-num=NUM\fR]
7+
[\fI\-\-progress\fR] [\fI\-\-time\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR]
8+
\fIDEVICE\fR
89
.PP
910
.B sg_turs
1011
[\fI\-n=NUM\fR] [\fI\-p\fR] [\fI\-t\fR] [\fI\-v\fR] [\fI\-V\fR]
@@ -34,6 +35,10 @@ g G GiB *1,073,741,824; and GB *1,000,000,000 . Also a suffix of the
3435
form "x<n>" multiplies the leading number by <n>. Alternatively a hex
3536
number may be given, prefixed by either '0x' or has a trailing 'h'.
3637
.TP
38+
\fB\-\-num\fR=\fINUM\fR
39+
same as \fI\-\-number=NUM\fR. Added for compatibility with sg_requests
40+
which has taken over the role of polling the progress indication.
41+
.TP
3742
\fB\-O\fR, \fB\-\-old\fR
3843
switch to older style options.
3944
.TP
@@ -57,7 +62,9 @@ print version string then exit.
5762
The progress indication is optionally part of the sense data. When a prior
5863
command that takes a long time to complete (and typically precludes other
5964
media access commands) is still underway, the progress indication can be used
60-
to determine how long before the device returns to its normal state.
65+
to determine how long before the device returns to its normal state. Around
66+
SPC\-3 T10 changed the preferred command for polling the progress indication
67+
from TEST UNIT READY to REQUEST SENSE (see the sg_requests utilty).
6168
.PP
6269
The SCSI FORMAT command for disks used with the IMMED bit set is an example
6370
of an operation that takes a significant amount of time and precludes other
@@ -108,9 +115,9 @@ print out version string then exit.
108115
.SH AUTHORS
109116
Written by D. Gilbert
110117
.SH COPYRIGHT
111-
Copyright \(co 2000\-2014 Douglas Gilbert
118+
Copyright \(co 2000\-2016 Douglas Gilbert
112119
.br
113120
This software is distributed under the GPL version 2. There is NO
114121
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
115122
.SH "SEE ALSO"
116-
.B sg_inq, sg_request (sg3_utils)
123+
.B sg_inq, sg_requests (sg3_utils)

lib/sg_cmds_extra.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ sg_ll_report_referrals(int sg_fd, uint64_t start_llba, int one_seg,
354354
}
355355

356356
/* Invokes a SCSI SEND DIAGNOSTIC command. Foreground, extended self tests can
357-
* take a long time, if so set long_duration flag in which case the timout
357+
* take a long time, if so set long_duration flag in which case the timeout
358358
* is set to 7200 seconds; if the value of long_duration is > 7200 then that
359359
* value is taken as the timeout value in seconds. Return of 0 -> success,
360360
* various SG_LIB_CAT_* positive values or -1 -> other errors */
@@ -372,21 +372,24 @@ sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, int devofl_bit,
372372
senddiagCmdBlk[1] = (unsigned char)((sf_code << 5) | (pf_bit << 4) |
373373
(sf_bit << 2) | (devofl_bit << 1) | unitofl_bit);
374374
sg_put_unaligned_be16((uint16_t)param_len, senddiagCmdBlk + 3);
375+
if (long_duration > LONG_PT_TIMEOUT)
376+
tmout = long_duration;
377+
else
378+
tmout = long_duration ? LONG_PT_TIMEOUT : DEF_PT_TIMEOUT;
375379

376380
if (verbose) {
377381
pr2ws(" Send diagnostic cmd: ");
378382
for (k = 0; k < SEND_DIAGNOSTIC_CMDLEN; ++k)
379383
pr2ws("%02x ", senddiagCmdBlk[k]);
380384
pr2ws("\n");
381-
if ((verbose > 1) && paramp && param_len) {
382-
pr2ws(" Send diagnostic parameter list:\n");
383-
dStrHexErr((const char *)paramp, param_len, -1);
385+
if (verbose > 1) {
386+
if (paramp && param_len) {
387+
pr2ws(" Send diagnostic parameter list:\n");
388+
dStrHexErr((const char *)paramp, param_len, -1);
389+
}
390+
pr2ws(" Send diagnostic timeout: %d seconds\n", tmout);
384391
}
385392
}
386-
if (long_duration > LONG_PT_TIMEOUT)
387-
tmout = long_duration;
388-
else
389-
tmout = long_duration ? LONG_PT_TIMEOUT : DEF_PT_TIMEOUT;
390393

391394
ptvp = construct_scsi_pt_obj();
392395
if (NULL == ptvp) {
@@ -756,10 +759,13 @@ sg_ll_format_unit2(int sg_fd, int fmtpinfo, int longlist, int fmtdata,
756759
for (k = 0; k < 6; ++k)
757760
pr2ws("%02x ", fuCmdBlk[k]);
758761
pr2ws("\n");
759-
}
760-
if ((verbose > 1) && (param_len > 0)) {
761-
pr2ws(" format parameter list:\n");
762-
dStrHexErr((const char *)paramp, param_len, -1);
762+
if (verbose > 1) {
763+
if (param_len > 0) {
764+
pr2ws(" format unit parameter list:\n");
765+
dStrHexErr((const char *)paramp, param_len, -1);
766+
}
767+
pr2ws(" format unit timeout: %d seconds\n", tmout);
768+
}
763769
}
764770

765771
ptvp = construct_scsi_pt_obj();

src/sg_copy_results.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2015 Hannes Reinecke, SUSE Labs
2+
* Copyright (c) 2011-2016 Hannes Reinecke, SUSE Labs
33
* All rights reserved.
44
* Use of this source code is governed by a BSD-style
55
* license that can be found in the BSD_LICENSE file.
@@ -36,7 +36,7 @@
3636
and the optional list identifier passed as the list_id argument.
3737
*/
3838

39-
static const char * version_str = "1.12 20150227";
39+
static const char * version_str = "1.13 20160227";
4040

4141

4242
#define MAX_XFER_LEN 10000
@@ -408,7 +408,8 @@ main(int argc, char * argv[])
408408
if (sg_fd < 0) {
409409
pr2serr(ME "open error: %s: %s\n", device_name,
410410
safe_strerror(-sg_fd));
411-
return SG_LIB_FILE_ERROR;
411+
ret = SG_LIB_FILE_ERROR;
412+
goto finish;
412413
}
413414

414415
if ((sa < 0) || (sa >= (int)(sizeof(rec_copy_name_arr) / sizeof(char *))))

0 commit comments

Comments
 (0)