aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2018-05-07 05:28:08 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2018-05-07 05:28:08 +0000
commit5a4b80a31b1caeb62fdab8d732582d898b3da9e0 (patch)
treeda413dd462b4945d62a0741ef55edd2733fe6755
parenta59b767b38f08c0dafc011a58e8791aa06d4feb0 (diff)
downloadsg3_utils-5a4b80a31b1caeb62fdab8d732582d898b3da9e0.tar.gz
sg_zone: add --sequentialize, --count=ZC options; sg_reset_wp add --count=ZC option [both zbc2r01b]
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@770 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--COVERAGE3
-rw-r--r--ChangeLog4
-rw-r--r--doc/sg_reset_wp.816
-rw-r--r--doc/sg_zone.831
-rw-r--r--lib/sg_lib_data.c3
-rw-r--r--src/sg_reset_wp.c42
-rw-r--r--src/sg_zone.c64
7 files changed, 119 insertions, 44 deletions
diff --git a/COVERAGE b/COVERAGE
index d822857d..84bd4d42 100644
--- a/COVERAGE
+++ b/COVERAGE
@@ -83,6 +83,7 @@ RESET WRITE POINTER sg_reset_wp
SANITIZE sg_sanitize
SEEK(10) sg_seek ++
SEND DIAGNOSTIC sg_senddiag, sg_ses, sg_ses_microcode ++
+SEQUENTIALIZE ZONE sg_zone
SET IDENTIFYING INFORMATION sg_ident, ++ (3)
SET TARGET PORT GROUPS sg_stpg, ++
SET TIMESTAMP sg_timestamp
@@ -157,4 +158,4 @@ THIRD PARTY COPY IN (0x83).
Douglas Gilbert
-27th January 2018
+6th May 2018
diff --git a/ChangeLog b/ChangeLog
index 9a8cd47e..711170e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and
some description at the top of its ".c" file. All utilities in the main
directory have their own "man" pages. There is also a sg3_utils man page.
-Changelog for sg3_utils-1.43 [20180502] [svn: r769]
+Changelog for sg3_utils-1.43 [20180506] [svn: r770]
- sg_write_x: where x can be normal, atomic, or(write),
same, scattered, or stream writes with 16 or 32 byte
cdbs (sbc4r04 for atomic, sbc4r11 for scattered)
@@ -86,6 +86,8 @@ Changelog for sg3_utils-1.43 [20180502] [svn: r769]
and '--number=NUM' for mutual compatibility
- sg_turs: add --low option
- sg_zone: fix debug cdb naming
+ - add --sequentialize, --count=ZC options, zbc2r01b
+ - sg_reset_wp add --count=ZC option, zbc2r01b
- sg_persist: add --maxlen-LEN option, LEN defaults to
decimal, similar to --alloc-length= which takes hex
- sgp_dd: pthread_cancel() has issues in C++ (and
diff --git a/doc/sg_reset_wp.8 b/doc/sg_reset_wp.8
index 036f80a9..1627e04c 100644
--- a/doc/sg_reset_wp.8
+++ b/doc/sg_reset_wp.8
@@ -1,15 +1,16 @@
-.TH SG_RESET_WP "8" "November 2015" "sg3_utils\-1.42" SG3_UTILS
+.TH SG_RESET_WP "8" "May 2018" "sg3_utils\-1.43" SG3_UTILS
.SH NAME
sg_reset_wp \- send SCSI RESET WRITE POINTER command
.SH SYNOPSIS
.B sg_reset_wp
-[\fI\-\-all\fR] [\fI\-\-help\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR]
-[\fI\-\-zone=ID\fR] \fIDEVICE\fR
+[\fI\-\-all\fR] [\fI\-\-count=ZC\fR] [\fI\-\-help\fR] [\fI\-\-verbose\fR]
+[\fI\-\-version\fR] [\fI\-\-zone=ID\fR] \fIDEVICE\fR
.SH DESCRIPTION
.\" Add any additional description here
.PP
Sends a SCSI RESET WRITE POINTER command to the \fIDEVICE\fR. This command
-is found in the ZBC draft standard revision 4c (zbc\-r04c.pdf).
+is found in the soon to be released ZBC standard (draft prior to standard:
+zbc\-r05.pdf).
.SH OPTIONS
Arguments to long options are mandatory for short options as well.
.TP
@@ -19,6 +20,11 @@ all open zones and full zones. When this option is given then the
\fI\-\-zone=ID\fR option is ignored. Either this option or the
\fI\-\-zone=ID\fR option is required.
.TP
+\fB\-C\fR, \fB\-\-count\fR=\fIZC\fR
+ZC is placed in the Zone Count field in the cdb of the RESET WRITE POINTER
+command supported by this utility. ZC should be a value from 0 to
+65535 (0xffff) inclusive.
+.TP
\fB\-h\fR, \fB\-\-help\fR
output the usage message then exit.
.TP
@@ -43,7 +49,7 @@ Written by Douglas Gilbert.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2014\-2015 Douglas Gilbert
+Copyright \(co 2014\-2018 Douglas Gilbert
.br
This software is distributed under a FreeBSD license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/doc/sg_zone.8 b/doc/sg_zone.8
index 44a0cd65..e3dfd3c7 100644
--- a/doc/sg_zone.8
+++ b/doc/sg_zone.8
@@ -1,20 +1,21 @@
-.TH SG_ZONE "8" "November 2015" "sg3_utils\-1.42" SG3_UTILS
+.TH SG_ZONE "8" "May 2018" "sg3_utils\-1.43" SG3_UTILS
.SH NAME
-sg_zone \- send SCSI OPEN, CLOSE or FINISH ZONE command
+sg_zone \- send SCSI OPEN, CLOSE, FINISH or SEQUENTIALIZE ZONE command
.SH SYNOPSIS
.B sg_zone
-[\fI\-\-all\fR] [\fI\-\-close\fR] [\fI\-\-finish\fR] [\fI\-\-help\fR]
-[\fI\-\-open\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR] [\fI\-\-zone=ID\fR]
-\fIDEVICE\fR
+[\fI\-\-all\fR] [\fI\-\-close\fR] [\fI\-\-count=ZC\fR] [\fI\-\-finish\fR]
+[\fI\-\-help\fR] [\fI\-\-open\fR] [\fI\-\-sequentialize\fR]
+[\fI\-\-verbose\fR] [\fI\-\-version\fR] [\fI\-\-zone=ID\fR] \fIDEVICE\fR
.SH DESCRIPTION
.\" Add any additional description here
.PP
-Sends a SCSI OPEN ZONE, CLOSE ZONE or FINISH ZONE command to the \fIDEVICE\fR.
-These commands are found in the ZBC draft standard revision
-4c (zbc\-r04c.pdf).
+Sends a SCSI OPEN ZONE, CLOSE ZONE, FINISH ZONE or SEQUENTIALIZE ZONE
+command to the \fIDEVICE\fR. All but the last are found in the soon to
+be released ZBC standard (close to draft ZBC BSR INCITS 536 revision 05).
+The SEQUENTIALIZE ZONE command was added in zbc2r01b.
.PP
-One and only one of the \fI\-\-open\fR, \fI\-\-close\fR and \fI\-\-finish\fR
-options can be chosen.
+One and only one of the \fI\-\-open\fR, \fI\-\-close\fR, \fI\-\-finish\fR
+and \fI\-\-sequentialize\fR options can be chosen.
.SH OPTIONS
Arguments to long options are mandatory for short options as well.
.TP
@@ -24,6 +25,11 @@ sets the ALL field in the cdb.
\fB\-c\fR, \fB\-\-close\fR
causes the CLOSE ZONE command to be sent to the \fIDEVICE\fR.
.TP
+\fB\-C\fR, \fB\-\-count\fR=\fIZC\fR
+ZC is placed in the Zone Count field in the cdb of all four commands
+supported by this utility. ZC should be a value from 0 to 65535 (0xffff)
+inclusive.
+.TP
\fB\-f\fR, \fB\-\-finish\fR
causes the FINISH ZONE command to be sent to the \fIDEVICE\fR.
.TP
@@ -33,6 +39,9 @@ output the usage message then exit.
\fB\-o\fR, \fB\-\-open\fR
causes the OPEN ZONE command to be sent to the \fIDEVICE\fR.
.TP
+\fB\-S\fR, \fB\-\-sequentialize\fR
+causes the SEQUENTIALIZE ZONE command to be sent to the \fIDEVICE\fR.
+.TP
\fB\-v\fR, \fB\-\-verbose\fR
increase the level of verbosity, (i.e. debug output).
.TP
@@ -52,7 +61,7 @@ Written by Douglas Gilbert.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2014\-2015 Douglas Gilbert
+Copyright \(co 2014\-2018 Douglas Gilbert
.br
This software is distributed under a FreeBSD license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c
index 453d0c1b..1700d0f7 100644
--- a/lib/sg_lib_data.c
+++ b/lib/sg_lib_data.c
@@ -17,7 +17,7 @@
#include "sg_lib_data.h"
-const char * sg_lib_version_str = "2.43 20180405";/* spc5r19, sbc4r15 */
+const char * sg_lib_version_str = "2.43 20180504";/* spc5r19, sbc4r15 */
/* indexed by pdt; those that map to own index do not decay */
@@ -517,6 +517,7 @@ struct sg_lib_value_name_t sg_lib_zoning_out_arr[] = {
{0x2, PDT_ZBC, "Finish zone"},
{0x3, PDT_ZBC, "Open zone"},
{0x4, PDT_ZBC, "Reset write pointer"},
+ {0x10, PDT_ZBC, "Sequentialize zone"}, /* zbc2r01b */
{0xffff, 0, NULL},
};
diff --git a/src/sg_reset_wp.c b/src/sg_reset_wp.c
index 11999ed5..5542283b 100644
--- a/src/sg_reset_wp.c
+++ b/src/sg_reset_wp.c
@@ -35,7 +35,7 @@
* device. Based on zbc-r04c.pdf .
*/
-static const char * version_str = "1.09 20180219";
+static const char * version_str = "1.10 20180504";
#define SG_ZONING_OUT_CMDLEN 16
#define RESET_WRITE_POINTER_SA 0x4
@@ -46,6 +46,7 @@ static const char * version_str = "1.09 20180219";
static struct option long_options[] = {
{"all", no_argument, 0, 'a'},
+ {"count", required_argument, 0, 'C'},
{"help", no_argument, 0, 'h'},
{"reset-all", no_argument, 0, 'R'},
{"reset_all", no_argument, 0, 'R'},
@@ -60,10 +61,11 @@ static void
usage()
{
pr2serr("Usage: "
- "sg_reset_wp [--all] [--help] [--verbose] [--version]\n"
- " [--zone=ID] DEVICE\n");
+ "sg_reset_wp [--all] [--count=ZC] [--help] [--verbose]\n"
+ " [--version] [--zone=ID] DEVICE\n");
pr2serr(" where:\n"
" --all|-a sets the ALL flag in the cdb\n"
+ " --count=ZC|-C ZC set zone count field (def: 0)\n"
" --help|-h print out usage message\n"
" --verbose|-v increase verbosity\n"
" --version|-V print version string and exit\n"
@@ -78,8 +80,8 @@ usage()
/* Invokes a SCSI RESET WRITE POINTER command (ZBC). Return of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
static int
-sg_ll_reset_write_pointer(int sg_fd, uint64_t zid, bool all, bool noisy,
- int verbose)
+sg_ll_reset_write_pointer(int sg_fd, uint64_t zid, uint16_t zc, bool all,
+ bool noisy, int verbose)
{
int k, ret, res, sense_cat;
uint8_t rwp_cdb[SG_ZONING_OUT_CMDLEN] = {SG_ZONING_OUT,
@@ -88,6 +90,7 @@ sg_ll_reset_write_pointer(int sg_fd, uint64_t zid, bool all, bool noisy,
struct sg_pt_base * ptvp;
sg_put_unaligned_be64(zid, rwp_cdb + 2);
+ sg_put_unaligned_be16(zc, rwp_cdb + 12);
if (all)
rwp_cdb[14] = 0x1;
if (verbose) {
@@ -132,9 +135,10 @@ main(int argc, char * argv[])
{
bool all = false;
bool zid_given = false;
- int sg_fd, res, c;
+ int sg_fd, res, c, n;
int ret = 0;
int verbose = 0;
+ uint16_t zc = 0;
uint64_t zid = 0;
int64_t ll;
const char * device_name = NULL;
@@ -142,7 +146,7 @@ main(int argc, char * argv[])
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "ahRvVz:", long_options,
+ c = getopt_long(argc, argv, "aC:hRvVz:", long_options,
&option_index);
if (c == -1)
break;
@@ -152,6 +156,15 @@ main(int argc, char * argv[])
case 'R':
all = true;
break;
+ case 'C':
+ n = sg_get_num(optarg);
+ if ((n < 0) || (n > 0xffff)) {
+ pr2serr("--count= expects an argument between 0 and 0xffff "
+ "inclusive\n");
+ return SG_LIB_SYNTAX_ERROR;
+ }
+ zc = (uint16_t)n;
+ break;
case 'h':
case '?':
usage();
@@ -204,12 +217,14 @@ main(int argc, char * argv[])
sg_fd = sg_cmds_open_device(device_name, false /* rw */, verbose);
if (sg_fd < 0) {
+ int err = -sg_fd;
+
pr2serr("open error: %s: %s\n", device_name,
- safe_strerror(-sg_fd));
- return SG_LIB_FILE_ERROR;
+ safe_strerror(err));
+ return sg_convert_errno(err);
}
- res = sg_ll_reset_write_pointer(sg_fd, zid, all, true, verbose);
+ res = sg_ll_reset_write_pointer(sg_fd, zid, zc, all, true, verbose);
ret = res;
if (res) {
if (SG_LIB_CAT_INVALID_OP == res)
@@ -222,11 +237,16 @@ main(int argc, char * argv[])
}
}
+ if (0 == verbose) {
+ if (! sg_if_can2stderr("sg_reset_wp failed: ", ret))
+ pr2serr("Some error occurred, try again with '-v' or '-vv' for "
+ "more information\n");
+ }
res = sg_cmds_close_device(sg_fd);
if (res < 0) {
pr2serr("close error: %s\n", safe_strerror(-res));
if (0 == ret)
- return SG_LIB_FILE_ERROR;
+ ret = sg_convert_errno(-res);
}
return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
}
diff --git a/src/sg_zone.c b/src/sg_zone.c
index b7511e8f..7b2c616a 100644
--- a/src/sg_zone.c
+++ b/src/sg_zone.c
@@ -35,12 +35,13 @@
* to the given SCSI device. Based on zbc-r04c.pdf .
*/
-static const char * version_str = "1.07 20180219";
+static const char * version_str = "1.08 20180504";
#define SG_ZONING_OUT_CMDLEN 16
#define CLOSE_ZONE_SA 0x1
#define FINISH_ZONE_SA 0x2
#define OPEN_ZONE_SA 0x3
+#define SEQUENTIALIZE_ZONE_SA 0x10
#define SENSE_BUFF_LEN 64 /* Arbitrary, could be larger */
#define DEF_PT_TIMEOUT 60 /* 60 seconds */
@@ -49,11 +50,13 @@ static const char * version_str = "1.07 20180219";
static struct option long_options[] = {
{"all", no_argument, 0, 'a'},
{"close", no_argument, 0, 'c'},
+ {"count", required_argument, 0, 'C'},
{"finish", no_argument, 0, 'f'},
{"help", no_argument, 0, 'h'},
{"open", no_argument, 0, 'o'},
{"reset-all", no_argument, 0, 'R'},
{"reset_all", no_argument, 0, 'R'},
+ {"sequentialize", no_argument, 0, 'S'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{"zone", required_argument, 0, 'z'},
@@ -66,6 +69,13 @@ static const char * sa_name_arr[] = {
"Close zone",
"Finish zone",
"Open zone",
+ "-", "-", "-", "-",
+ "-", /* 0x8 */
+ "-", "-", "-", "-",
+ "-",
+ "-",
+ "-",
+ "Sequentialize zone", /* 0x10 */
};
@@ -73,14 +83,18 @@ static void
usage()
{
pr2serr("Usage: "
- "sg_zone [--all] [--close] [--finish] [--help] [--open]\n"
- " [--verbose] [--version] [--zone=ID] DEVICE\n");
+ "sg_zone [--all] [--close] [--count=ZC] [--finish] [--help]\n"
+ " [--open] [--sequentialize] [--verbose] "
+ "[--version]\n"
+ " [--zone=ID] DEVICE\n");
pr2serr(" where:\n"
" --all|-a sets the ALL flag in the cdb\n"
" --close|-c issue CLOSE ZONE command\n"
+ " --count=ZC|-C ZC set zone count field (def: 0)\n"
" --finish|-f issue FINISH ZONE command\n"
" --help|-h print out usage message\n"
" --open|-o issue OPEN ZONE command\n"
+ " --sequentialize|-S issue SEQUENTIALIZE ZONE command\n"
" --verbose|-v increase verbosity\n"
" --version|-V print version string and exit\n"
" --zone=ID|-z ID ID is the starting LBA of the zone "
@@ -94,8 +108,8 @@ usage()
/* Invokes the zone out command indicated by 'sa' (ZBC). Return of 0
* -> success, various SG_LIB_CAT_* positive values or -1 -> other errors */
static int
-sg_ll_zone_out(int sg_fd, int sa, uint64_t zid, bool all, bool noisy,
- int verbose)
+sg_ll_zone_out(int sg_fd, int sa, uint64_t zid, uint16_t zc, bool all,
+ bool noisy, int verbose)
{
int k, ret, res, sense_cat;
struct sg_pt_base * ptvp;
@@ -106,6 +120,7 @@ sg_ll_zone_out(int sg_fd, int sa, uint64_t zid, bool all, bool noisy,
zo_cdb[1] = 0x1f & sa;
sg_put_unaligned_be64(zid, zo_cdb + 2);
+ sg_put_unaligned_be16(zc, zo_cdb + 12);
if (all)
zo_cdb[14] = 0x1;
sg_get_opcode_sa_name(zo_cdb[0], sa, -1, sizeof(b), b);
@@ -153,10 +168,12 @@ main(int argc, char * argv[])
bool close = false;
bool finish = false;
bool open = false;
- int sg_fd, res, c;
+ bool sequentialize = false;
+ int sg_fd, res, c, n;
int verbose = 0;
int ret = 0;
int sa = 0;
+ uint16_t zc = 0;
uint64_t zid = 0;
int64_t ll;
const char * device_name = NULL;
@@ -165,7 +182,7 @@ main(int argc, char * argv[])
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "acfhoRvVz:", long_options,
+ c = getopt_long(argc, argv, "acC:fhoRSvVz:", long_options,
&option_index);
if (c == -1)
break;
@@ -179,6 +196,15 @@ main(int argc, char * argv[])
close = true;
sa = CLOSE_ZONE_SA;
break;
+ case 'C':
+ n = sg_get_num(optarg);
+ if ((n < 0) || (n > 0xffff)) {
+ pr2serr("--count= expects an argument between 0 and 0xffff "
+ "inclusive\n");
+ return SG_LIB_SYNTAX_ERROR;
+ }
+ zc = (uint16_t)n;
+ break;
case 'f':
finish = true;
sa = FINISH_ZONE_SA;
@@ -191,6 +217,10 @@ main(int argc, char * argv[])
open = true;
sa = OPEN_ZONE_SA;
break;
+ case 'S':
+ sequentialize = true;
+ sa = SEQUENTIALIZE_ZONE_SA;
+ break;
case 'v':
++verbose;
break;
@@ -225,9 +255,9 @@ main(int argc, char * argv[])
}
}
- if (1 != ((int)close + (int)finish + (int)open)) {
- pr2serr("one from the --close, --finish and --open options must be "
- "given\n");
+ if (1 != ((int)close + (int)finish + (int)open + (int)sequentialize)) {
+ pr2serr("one from the --close, --finish, --open and --sequentialize "
+ "options must be given\n");
usage();
return SG_LIB_SYNTAX_ERROR;
}
@@ -241,12 +271,13 @@ main(int argc, char * argv[])
sg_fd = sg_cmds_open_device(device_name, false /* rw */, verbose);
if (sg_fd < 0) {
+ int err = -sg_fd;
pr2serr("open error: %s: %s\n", device_name,
- safe_strerror(-sg_fd));
- return SG_LIB_FILE_ERROR;
+ safe_strerror(err));
+ return sg_convert_errno(err);
}
- res = sg_ll_zone_out(sg_fd, sa, zid, all, true, verbose);
+ res = sg_ll_zone_out(sg_fd, sa, zid, zc, all, true, verbose);
ret = res;
if (res) {
if (SG_LIB_CAT_INVALID_OP == res)
@@ -259,11 +290,16 @@ main(int argc, char * argv[])
}
}
+ if (0 == verbose) {
+ if (! sg_if_can2stderr("sg_zone failed: ", ret))
+ pr2serr("Some error occurred, try again with '-v' or '-vv' for "
+ "more information\n");
+ }
res = sg_cmds_close_device(sg_fd);
if (res < 0) {
pr2serr("close error: %s\n", safe_strerror(-res));
if (0 == ret)
- return SG_LIB_FILE_ERROR;
+ ret = sg_convert_errno(-res);
}
return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
}