aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--debian/changelog2
-rw-r--r--include/sg_lib.h6
-rw-r--r--lib/sg_lib.c40
-rw-r--r--sg3_utils.spec2
-rw-r--r--src/sg_inq.c4
-rw-r--r--src/sg_modes.c1
-rw-r--r--src/sg_vpd.c8
-rw-r--r--testing/sgh_dd.cpp51
9 files changed, 67 insertions, 49 deletions
diff --git a/ChangeLog b/ChangeLog
index 96940c48..3dbfda29 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.45 [20200220] [svn: r842]
+Changelog for sg3_utils-1.45 [20200229] [svn: r843]
- sg_get_elem_status: new utility [sbc4r16]
- sg_ses: bug: --page= being overridden when --control
and --data= also given; fix
diff --git a/debian/changelog b/debian/changelog
index 5d080f23..2d0e7922 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,7 +2,7 @@ sg3-utils (1.45-0.1) unstable; urgency=low
* New upstream version
- -- Douglas Gilbert <dgilbert@interlog.com> Wed, 19 Feb 2020 22:00:00 -0500
+ -- Douglas Gilbert <dgilbert@interlog.com> Sat, 29 Feb 2020 20:00:00 -0500
sg3-utils (1.44-0.1) unstable; urgency=low
diff --git a/include/sg_lib.h b/include/sg_lib.h
index 35fe3196..1ece717f 100644
--- a/include/sg_lib.h
+++ b/include/sg_lib.h
@@ -378,15 +378,15 @@ extern FILE * sg_warnings_strm;
void sg_set_warnings_strm(FILE * warnings_strm);
-/* Given a SCSI command pointed to by cmdp of sz bytes this function forms a
+/* Given a SCSI command pointed to by cdbp of sz bytes this function forms a
* SCSI command in ASCII hex surrounded by square brackets in 'b'. 'b' is at
* least blen bytes long. If cmd_name is true then the command is prefixed
* by its SCSI command name (e.g. "VERIFY(10) [2f ...]". The command is
* shown as spaced separated pairs of hexadecimal digits (i.e. 0-9, a-f).
- * Each pair represents byte. The leftmost pair of digits is cmdp[0] . If
+ * Each pair represents byte. The leftmost pair of digits is cdbp[0] . If
* sz <= 0 then this function tries to guess the length of the command. */
char *
-sg_get_command_str(const uint8_t * cmdp, int sz, bool cmd_name, int blen,
+sg_get_command_str(const uint8_t * cdbp, int sz, bool cmd_name, int blen,
char * b);
/* The following "print" functions send ASCII to 'sg_warnings_strm' file
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
index b89bb500..43a2ebbe 100644
--- a/lib/sg_lib.c
+++ b/lib/sg_lib.c
@@ -162,23 +162,23 @@ static char bin2hexascii[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-/* Given a SCSI command pointed to by cmdp of sz bytes this function forms
+/* Given a SCSI command pointed to by cdbp of sz bytes this function forms
* a SCSI command in ASCII surrounded by square brackets in 'b'. 'b' is at
* least blen bytes long. If cmd_name is true then the command is prefixed
* by its SCSI command name (e.g. "VERIFY(10) [2f ...]". The command is
* shown as spaced separated pairs of hexadecimal digits (i.e. 0-9, a-f).
- * Each pair represents byte. The leftmost pair of digits is cmdp[0] . If
+ * Each pair represents byte. The leftmost pair of digits is cdbp[0] . If
* sz <= 0 then this function tries to guess the length of the command. */
char *
-sg_get_command_str(const uint8_t * cmdp, int sz, bool cmd_name, int blen,
+sg_get_command_str(const uint8_t * cdbp, int sz, bool cmd_name, int blen,
char * b)
{
int k, j, jj;
- if ((cmdp == NULL) || (b == NULL) || (blen < 1))
+ if ((cdbp == NULL) || (b == NULL) || (blen < 1))
return b;
if (cmd_name && (blen > 16)) {
- sg_get_command_name(cmdp, 0, blen, b);
+ sg_get_command_name(cdbp, 0, blen, b);
j = (int)strlen(b);
if (j < (blen - 1))
b[j++] = ' ';
@@ -190,15 +190,15 @@ sg_get_command_str(const uint8_t * cmdp, int sz, bool cmd_name, int blen,
if (j >= blen)
goto fini;
if (sz <= 0) {
- if (SG_VARIABLE_LENGTH_CMD == cmdp[0])
- sz = cmdp[7] + 8;
+ if (SG_VARIABLE_LENGTH_CMD == cdbp[0])
+ sz = cdbp[7] + 8;
else
- sz = sg_get_command_size(cmdp[0]);
+ sz = sg_get_command_size(cdbp[0]);
}
jj = j;
- for (k = 0; (k < sz) && (j < (blen - 3)); ++k, j += 3, ++cmdp) {
- b[j] = bin2hexascii[(*cmdp >> 4) & 0xf];
- b[j + 1] = bin2hexascii[*cmdp & 0xf];
+ for (k = 0; (k < sz) && (j < (blen - 3)); ++k, j += 3, ++cdbp) {
+ b[j] = bin2hexascii[(*cdbp >> 4) & 0xf];
+ b[j + 1] = bin2hexascii[*cdbp & 0xf];
b[j + 2] = ' ';
}
if (j > jj)
@@ -217,18 +217,18 @@ fini:
#define CMD_NAME_LEN 128
void
-sg_print_command_len(const uint8_t * cmdp, int sz)
+sg_print_command_len(const uint8_t * cdbp, int sz)
{
char buff[CMD_NAME_LEN];
- sg_get_command_str(cmdp, sz, true, sizeof(buff), buff);
+ sg_get_command_str(cdbp, sz, true, sizeof(buff), buff);
pr2ws("%s\n", buff);
}
void
-sg_print_command(const uint8_t * cmdp)
+sg_print_command(const uint8_t * cdbp)
{
- sg_print_command_len(cmdp, 0);
+ sg_print_command_len(cdbp, 0);
}
/* SCSI Status values */
@@ -2222,7 +2222,7 @@ sg_get_command_size(uint8_t opcode)
}
void
-sg_get_command_name(const uint8_t * cmdp, int peri_type, int buff_len,
+sg_get_command_name(const uint8_t * cdbp, int peri_type, int buff_len,
char * buff)
{
int service_action;
@@ -2233,13 +2233,13 @@ sg_get_command_name(const uint8_t * cmdp, int peri_type, int buff_len,
buff[0] = '\0';
return;
}
- if (NULL == cmdp) {
+ if (NULL == cdbp) {
sg_scnpr(buff, buff_len, "%s", "<null> command pointer");
return;
}
- service_action = (SG_VARIABLE_LENGTH_CMD == cmdp[0]) ?
- sg_get_unaligned_be16(cmdp + 8) : (cmdp[1] & 0x1f);
- sg_get_opcode_sa_name(cmdp[0], service_action, peri_type, buff_len, buff);
+ service_action = (SG_VARIABLE_LENGTH_CMD == cdbp[0]) ?
+ sg_get_unaligned_be16(cdbp + 8) : (cdbp[1] & 0x1f);
+ sg_get_opcode_sa_name(cdbp[0], service_action, peri_type, buff_len, buff);
}
struct op_code2sa_t {
diff --git a/sg3_utils.spec b/sg3_utils.spec
index 0e8fb015..6ddc4716 100644
--- a/sg3_utils.spec
+++ b/sg3_utils.spec
@@ -84,7 +84,7 @@ fi
%{_libdir}/*.la
%changelog
-* Wed Feb 19 2020 - dgilbert at interlog dot com
+* Sat Feb 29 2020 - dgilbert at interlog dot com
- track t10 changes
* sg3_utils-1.45
diff --git a/src/sg_inq.c b/src/sg_inq.c
index 8aec3763..3580b9af 100644
--- a/src/sg_inq.c
+++ b/src/sg_inq.c
@@ -51,7 +51,7 @@
#include "sg_pt_nvme.h"
#endif
-static const char * version_str = "2.04 20200123"; /* SPC-6 rev 01 */
+static const char * version_str = "2.05 20200223"; /* SPC-6 rev 01 */
/* INQUIRY notes:
* It is recommended that the initial allocation length given to a
@@ -211,7 +211,7 @@ static struct svpd_values_name_t vpd_pg[] = {
{VPD_SCSI_PORTS, 0, -1, 0, "sp", "SCSI ports"},
{VPD_SUPPORTED_VPDS, 0, -1, 0, "sv", "Supported VPD pages"},
{VPD_3PARTY_COPY, 0, -1, 0, "tpc", "Third party copy"},
- {VPD_ZBC_DEV_CHARS, 0, -1, 0, "zbdc", "Zoned block device "
+ {VPD_ZBC_DEV_CHARS, 0, -1, 0, "zbdch", "Zoned block device "
"characteristics"},
/* Following are vendor specific */
{SG_NVME_VPD_NICR, 0, -1, 1, "nicr",
diff --git a/src/sg_modes.c b/src/sg_modes.c
index 06d96334..a6335cdb 100644
--- a/src/sg_modes.c
+++ b/src/sg_modes.c
@@ -258,6 +258,7 @@ static struct page_code_desc pc_desc_zbc[] = {
{0x7, 0x0, "ve", "Verify error recovery"},
{0x8, 0x0, "ca", "Caching"},
{0xa, 0x2, "atag", "Application tag"},
+ {0xa, 0xf, "zbdct", "Zoned block device control"}, /* zbc2r04a */
{0x1c, 0x1, "bc", "Background control"},
{0x0, 0x0, NULL, NULL},
};
diff --git a/src/sg_vpd.c b/src/sg_vpd.c
index b91261af..72403aca 100644
--- a/src/sg_vpd.c
+++ b/src/sg_vpd.c
@@ -40,7 +40,7 @@
*/
-static const char * version_str = "1.57 20200123"; /* spc6r01 + sbc4r18 */
+static const char * version_str = "1.58 20200223"; /* spc6r01 + sbc4r18 */
/* standard VPD pages, in ascending page number order */
#define VPD_SUPPORTED_VPDS 0x0
@@ -241,7 +241,7 @@ static struct svpd_values_name_t standard_vpd_pg[] = {
{VPD_SUPPORTED_VPDS, 0, -1, "sv", "Supported VPD pages"},
{VPD_TA_SUPPORTED, 0, 1, "tas", "TapeAlert supported flags (SSC)"},
{VPD_3PARTY_COPY, 0, -1, "tpc", "Third party copy"},
- {VPD_ZBC_DEV_CHARS, 0, -1, "zbdc", "Zoned block device characteristics"},
+ {VPD_ZBC_DEV_CHARS, 0, -1, "zbdch", "Zoned block device characteristics"},
/* Use pdt of -1 since this page both for pdt=0 and pdt=0x14 */
{0, 0, 0, NULL, NULL},
};
@@ -2530,7 +2530,7 @@ decode_b5_vpd(uint8_t * b, int len, int do_hex, int pdt)
/* VPD_ZBC_DEV_CHARS 0xb6 sbc or zbc [zbc2r04] */
static void
-decode_zbdc_vpd(uint8_t * b, int len, int do_hex)
+decode_zbdch_vpd(uint8_t * b, int len, int do_hex)
{
uint32_t u;
@@ -3382,7 +3382,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
sg_get_pdt_str(pdt, sizeof(b), b));
- decode_zbdc_vpd(rp, len, op->do_hex);
+ decode_zbdch_vpd(rp, len, op->do_hex);
}
return 0;
} else if ((! op->do_raw) && (! op->do_quiet) && (op->do_hex < 3) &&
diff --git a/testing/sgh_dd.cpp b/testing/sgh_dd.cpp
index 3f4d4433..f48be00f 100644
--- a/testing/sgh_dd.cpp
+++ b/testing/sgh_dd.cpp
@@ -108,7 +108,7 @@
using namespace std;
-static const char * version_str = "1.73 20200215";
+static const char * version_str = "1.75 20200227";
#ifdef __GNUC__
#ifndef __clang__
@@ -176,7 +176,6 @@ struct flags_t {
bool excl;
bool fua;
bool masync; /* more async sg v4 driver flag */
- bool mmap;
bool mrq_immed; /* mrq submit non-blocking */
bool mrq_svb; /* mrq shared_variable_block, for sg->sg copy */
bool no_dur;
@@ -192,6 +191,7 @@ struct flags_t {
bool v4;
bool v4_given;
bool wq_excl;
+ int mmap;
};
typedef struct global_collection
@@ -272,7 +272,6 @@ typedef struct request_element
bool wr;
bool has_share;
bool both_sg;
- bool mmap_active;
bool same_sg;
bool only_in_sg;
bool only_out_sg;
@@ -294,6 +293,7 @@ typedef struct request_element
uint8_t cmd[MAX_SCSI_CDBSZ];
uint8_t sb[SENSE_BUFF_LEN];
int dio_incomplete_count;
+ int mmap_active;
int resid;
int rd_p_id;
int rep_count;
@@ -968,6 +968,7 @@ page3:
" masync set 'more async' flag on this sg device\n"
" mmap setup mmap IO on IFILE or OFILE; OFILE only "
"with noshare\n"
+ " mmap,mmap when used twice, doesn't call munmap()\n"
" mrq_immed if mrq active, do submit non-blocking (def: "
"ordered\n"
" blocking)\n"
@@ -1347,16 +1348,16 @@ read_write_thread(void * v_tip)
vb = clp->debug;
sz = clp->bpt * clp->bs;
in_is_sg = (FT_SG == clp->in_type);
- in_mmap = (in_is_sg && clp->in_flags.mmap);
+ in_mmap = (in_is_sg && (clp->in_flags.mmap > 0));
out_is_sg = (FT_SG == clp->out_type);
- out_mmap = (out_is_sg && clp->out_flags.mmap);
+ out_mmap = (out_is_sg && (clp->out_flags.mmap > 0));
memset(rep, 0, sizeof(Rq_elem));
/* Following clp members are constant during lifetime of thread */
rep->clp = clp;
rep->id = tip->id;
if (vb > 2)
pr2serr_lk("%d <-- Starting worker thread\n", rep->id);
- if (! in_mmap) {
+ if (! (in_mmap || out_mmap)) {
int n = sz;
if (clp->unbalanced_mrq)
@@ -1399,7 +1400,7 @@ read_write_thread(void * v_tip)
if (fd < 0)
goto fini;
rep->infd = fd;
- rep->mmap_active = in_mmap;
+ rep->mmap_active = in_mmap ? clp->in_flags.mmap : 0;
if (in_mmap && (vb > 4))
pr2serr_lk("thread=%d: mmap buffp=%p\n", rep->id, rep->buffp);
own_infd = true;
@@ -1414,7 +1415,7 @@ read_write_thread(void * v_tip)
goto fini;
rep->outfd = fd;
if (! rep->mmap_active)
- rep->mmap_active = out_mmap;
+ rep->mmap_active = out_mmap ? clp->out_flags.mmap : 0;
if (out_mmap && (vb > 4))
pr2serr_lk("thread=%d: mmap buffp=%p\n", rep->id, rep->buffp);
own_outfd = true;
@@ -1624,7 +1625,9 @@ skip_force_out_sequence:
if (0 != status) err_exit(status, "unlock in_mutex");
fini:
- if (rep->mmap_active && (rep->mmap_len > 0)) {
+ if ((rep->mmap_active == 0) && rep->alloc_bp)
+ free(rep->alloc_bp);
+ if ((1 == rep->mmap_active) && (rep->mmap_len > 0)) {
if (munmap(rep->buffp, rep->mmap_len) < 0) {
int err = errno;
char bb[64];
@@ -1635,9 +1638,8 @@ fini:
if (vb > 4)
pr2serr_lk("thread=%d: munmap(%p, %d)\n", rep->id, rep->buffp,
rep->mmap_len);
- rep->mmap_active = false;
- } else if (rep->alloc_bp)
- free(rep->alloc_bp);
+ rep->mmap_active = 0;
+ }
if (sg_version_ge_40030) {
if (clp->noshare) {
@@ -3148,7 +3150,7 @@ sg_finish_io(bool wr, Rq_elem * rep, int pack_id, struct sg_io_extra *xtrp)
if (0 == (++testing % 100)) return -1;
#endif
if ((wr ? clp->out_flags.dio : clp->in_flags.dio) &&
- ((hp->info & SG_INFO_DIRECT_IO_MASK) != SG_INFO_DIRECT_IO))
+ (! (hp->info & SG_INFO_DIRECT_IO_MASK)))
rep->dio_incomplete_count = 1; /* count dios done as indirect IO */
else
rep->dio_incomplete_count = 0;
@@ -3225,7 +3227,7 @@ do_v4:
if (0 == (++testing % 100)) return -1;
#endif
if ((wr ? clp->out_flags.dio : clp->in_flags.dio) &&
- (h4p->info & SG_INFO_DIRECT_IO))
+ ! (h4p->info & SG_INFO_DIRECT_IO))
rep->dio_incomplete_count = 1; /* count dios done as indirect IO */
else
rep->dio_incomplete_count = 0;
@@ -3477,9 +3479,24 @@ bypass:
if (! def_res) {
num = bs * bpt;
res = ioctl(fd, SG_SET_RESERVED_SIZE, &num);
- if (res < 0)
+ if (res < 0) {
perror("sgh_dd: SG_SET_RESERVED_SIZE error");
- else if (mmpp) {
+ return 0;
+ } else {
+ int nn;
+
+ res = ioctl(fd, SG_GET_RESERVED_SIZE, &nn);
+ if (res < 0) {
+ perror("sgh_dd: SG_GET_RESERVED_SIZE error");
+ return 0;
+ }
+ if (nn < num) {
+ pr2serr_lk("%s: SG_GET_RESERVED_SIZE shows size truncated, "
+ "wanted %d got %d\n", __func__, num, nn);
+ return 0;
+ }
+ }
+ if (mmpp) {
mmp = (uint8_t *)mmap(NULL, num, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if (MAP_FAILED == mmp) {
@@ -3550,7 +3567,7 @@ process_flags(const char * arg, struct flags_t * fp)
else if (0 == strcmp(cp, "masync"))
fp->masync = true;
else if (0 == strcmp(cp, "mmap"))
- fp->mmap = true;
+ ++fp->mmap; /* mmap > 1 stops munmap() being called */
else if (0 == strcmp(cp, "mrq_imm"))
fp->mrq_immed = true;
else if (0 == strcmp(cp, "mrq_immed"))