aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2020-05-13 05:04:24 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2020-05-13 05:04:24 +0000
commiteda62fa0cd1d5886bd9893ba2831a37c5e24d4c7 (patch)
tree38069e363793c431e6b151501bb7f28f290207a6
parent0083e58d85910aa7c8599d06bfff48ea5f8c98d1 (diff)
downloadsg3_utils-eda62fa0cd1d5886bd9893ba2831a37c5e24d4c7.tar.gz
testing/sgh_dd: check for bs/READ_CAPACITY(LBsize) mismatch; fix some compile warnings and some --version issues
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@851 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog2
-rw-r--r--debian/changelog2
-rw-r--r--sg3_utils.spec2
-rw-r--r--src/sg_compare_and_write.c4
-rw-r--r--src/sg_xcopy.c6
-rw-r--r--src/sgm_dd.c12
-rw-r--r--src/sgp_dd.c10
-rw-r--r--testing/sgh_dd.cpp90
8 files changed, 73 insertions, 55 deletions
diff --git a/ChangeLog b/ChangeLog
index 9c08a8c6..fc9fe37c 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.46 [20200503] [svn: r850]
+Changelog for sg3_utils-1.46 [20200513] [svn: r851]
- sg_dd: separate category for miscompare errors
- sg_get_elem_status: add ralwd bit sbc4r20a
- sg_write_x: add dld bits to write(32) [sbc4r19a]
diff --git a/debian/changelog b/debian/changelog
index 5947daa9..f2dd3dba 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,7 +2,7 @@ sg3-utils (1.46-0.1) unstable; urgency=low
* New upstream version
- -- Douglas Gilbert <dgilbert@interlog.com> Sun, 05 May 2020 18:00:00 -0400
+ -- Douglas Gilbert <dgilbert@interlog.com> Wed, 13 May 2020 01:00:00 -0400
sg3-utils (1.45-0.1) unstable; urgency=low
diff --git a/sg3_utils.spec b/sg3_utils.spec
index 29eed7a3..78ab59d6 100644
--- a/sg3_utils.spec
+++ b/sg3_utils.spec
@@ -84,7 +84,7 @@ fi
%{_libdir}/*.la
%changelog
-* Sun May 03 2020 - dgilbert at interlog dot com
+* Wed May 13 2020 - dgilbert at interlog dot com
- track t10 changes
* sg3_utils-1.46
diff --git a/src/sg_compare_and_write.c b/src/sg_compare_and_write.c
index 11f5e859..23d69b3a 100644
--- a/src/sg_compare_and_write.c
+++ b/src/sg_compare_and_write.c
@@ -56,7 +56,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.28 20200429";
+static const char * version_str = "1.29 20200509";
#define DEF_BLOCK_SIZE 512
#define DEF_NUM_BLOCKS (1)
@@ -292,6 +292,8 @@ parse_args(int argc, char* argv[], struct opts_t * op)
goto out_err;
}
}
+ if (op->version_given && (! op->verbose_given))
+ return 0;
if (NULL == op->device_name) {
pr2serr("missing device name!\n");
goto out_err;
diff --git a/src/sg_xcopy.c b/src/sg_xcopy.c
index 984dda5d..352b3887 100644
--- a/src/sg_xcopy.c
+++ b/src/sg_xcopy.c
@@ -1,7 +1,7 @@
/* A utility program for copying files. Similar to 'dd' but using
* the 'Extended Copy' command.
*
- * Copyright (c) 2011-2019 Hannes Reinecke, SUSE Labs
+ * Copyright (c) 2011-2020 Hannes Reinecke, SUSE Labs
*
* Largely taken from 'sg_dd', which has the
*
@@ -27,7 +27,7 @@
* in this case) is transferred to or from the sg device in a single SCSI
* command.
*
- * This version is designed for the linux kernel 2.4, 2.6, 3 and 4 series.
+ * This version is designed for the linux kernel 2.4, 2.6, 3, 4 and 5 series.
*/
#define _XOPEN_SOURCE 600
@@ -69,7 +69,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "0.70 20190501";
+static const char * version_str = "0.71 20200510";
#define ME "sg_xcopy: "
diff --git a/src/sgm_dd.c b/src/sgm_dd.c
index 2992e20a..bbd10e22 100644
--- a/src/sgm_dd.c
+++ b/src/sgm_dd.c
@@ -27,7 +27,7 @@
then only the read side will be mmap-ed, while the write side will
use normal IO.
- This version is designed for the linux kernel 2.4, 2.6, 3 and 4 series.
+ This version is designed for the linux kernel 2.4, 2.6, 3, 4 and 5 series.
*/
#define _XOPEN_SOURCE 600
@@ -69,7 +69,7 @@
#include "sg_pr2serr.h"
-static const char * version_str = "1.66 20200429";
+static const char * version_str = "1.67 20200510";
#define DEF_BLOCK_SIZE 512
#define DEF_BLOCKS_PER_TRANSFER 128
@@ -541,13 +541,13 @@ sg_read(int sg_fd, uint8_t * buff, int blocks, int64_t from_block,
return res;
case SG_LIB_CAT_ILLEGAL_REQ:
if (verbose)
- print_cdb_after = true;
+ print_cdb_after = true;
/* FALL THROUGH */
case SG_LIB_CAT_ABORTED_COMMAND:
case SG_LIB_CAT_UNIT_ATTENTION:
default:
sg_chk_n_print3("reading", &io_hdr, verbose > 1);
- if (print_cdb_after)
+ if (print_cdb_after)
sg_print_command_len(rdCmd, cdbsz);
return res;
}
@@ -640,13 +640,13 @@ sg_write(int sg_fd, uint8_t * buff, int blocks, int64_t to_block,
return res;
case SG_LIB_CAT_ILLEGAL_REQ:
if (verbose)
- print_cdb_after = true;
+ print_cdb_after = true;
/* FALL THROUGH */
case SG_LIB_CAT_ABORTED_COMMAND:
case SG_LIB_CAT_UNIT_ATTENTION:
default:
sg_chk_n_print3("writing", &io_hdr, verbose > 1);
- if (print_cdb_after)
+ if (print_cdb_after)
sg_print_command_len(wrCmd, cdbsz);
return res;
}
diff --git a/src/sgp_dd.c b/src/sgp_dd.c
index 9dd089d1..3975f038 100644
--- a/src/sgp_dd.c
+++ b/src/sgp_dd.c
@@ -22,7 +22,7 @@
* in this case) are transferred to or from the sg device in a single SCSI
* command.
*
- * This version is designed for the linux kernel 2.4, 2.6, 3 and 4 series.
+ * This version is designed for the linux kernel 2.4, 2.6, 3, 4 and 5 series.
*
* sgp_dd is a Posix threads specialization of the sg_dd utility. Both
* sgp_dd and sg_dd only perform special tasks when one or both of the given
@@ -84,7 +84,7 @@
#include "sg_pr2serr.h"
-static const char * version_str = "5.75 20200219";
+static const char * version_str = "5.76 20200510";
#define DEF_BLOCK_SIZE 512
#define DEF_BLOCKS_PER_TRANSFER 128
@@ -370,7 +370,7 @@ tsafe_strerror(int code, char * ebp)
* ISBN 0-201-63392-2 . [Highly recommended book.] Changed __FILE__
* to __func__ */
#define err_exit(code,text) do { \
- char strerr_buff[STRERR_BUFF_LEN]; \
+ char strerr_buff[STRERR_BUFF_LEN + 1]; \
pr2serr("%s at \"%s\":%d: %s\n", \
text, __func__, __LINE__, tsafe_strerror(code, strerr_buff)); \
exit(1); \
@@ -836,7 +836,7 @@ normal_in_operation(Rq_coll * clp, Rq_elem * rep, int blocks)
{
bool stop_after_write = false;
int res;
- char strerr_buff[STRERR_BUFF_LEN];
+ char strerr_buff[STRERR_BUFF_LEN + 1];
/* enters holding in_mutex */
while (((res = read(rep->infd, rep->buffp, blocks * clp->bs)) < 0) &&
@@ -882,7 +882,7 @@ static void
normal_out_operation(Rq_coll * clp, Rq_elem * rep, int blocks)
{
int res;
- char strerr_buff[STRERR_BUFF_LEN];
+ char strerr_buff[STRERR_BUFF_LEN + 1];
/* enters holding out_mutex */
while (((res = write(rep->outfd, rep->buffp, rep->num_blks * clp->bs))
diff --git a/testing/sgh_dd.cpp b/testing/sgh_dd.cpp
index 599ee4bc..2dfcd71d 100644
--- a/testing/sgh_dd.cpp
+++ b/testing/sgh_dd.cpp
@@ -194,7 +194,7 @@ struct flags_t {
int mmap;
};
-typedef struct global_collection
+struct global_collection
{ /* one instance visible to all threads */
int infd;
int64_t skip;
@@ -257,7 +257,7 @@ typedef struct global_collection
const char * infp;
const char * outfp;
const char * out2fp;
-} Gbl_coll;
+};
typedef struct mrq_abort_info
{
@@ -269,7 +269,7 @@ typedef struct mrq_abort_info
typedef struct request_element
{ /* one instance per worker thread */
- Gbl_coll *clp;
+ struct global_collection *clp;
bool wr;
bool has_share;
bool both_sg;
@@ -311,7 +311,7 @@ typedef struct request_element
typedef struct thread_info
{
int id;
- Gbl_coll * gcp;
+ struct global_collection * gcp;
pthread_t a_pthr;
} Thread_info;
@@ -365,7 +365,8 @@ static pthread_t sig_listen_thread_id;
static const char * proc_allow_dio = "/proc/scsi/sg/allow_dio";
-static void sg_in_rd_cmd(Gbl_coll * clp, Rq_elem * rep, mrq_arr_t & def_arr);
+static void sg_in_rd_cmd(struct global_collection * clp, Rq_elem * rep,
+ mrq_arr_t & def_arr);
static void sg_out_wr_cmd(Rq_elem * rep, mrq_arr_t & def_arr, bool is_wr2,
bool prefetch);
static bool normal_in_rd(Rq_elem * rep, int blocks);
@@ -374,11 +375,11 @@ static int sg_start_io(Rq_elem * rep, mrq_arr_t & def_arr, int & pack_id,
struct sg_io_extra *xtrp);
static int sg_finish_io(bool wr, Rq_elem * rep, int pack_id,
struct sg_io_extra *xtrp);
-static int sg_in_open(Gbl_coll *clp, const char *inf, uint8_t **mmpp,
- int *mmap_len);
-static int sg_out_open(Gbl_coll *clp, const char *outf, uint8_t **mmpp,
- int *mmap_len);
-static void sg_in_out_interleave(Gbl_coll *clp, Rq_elem * rep,
+static int sg_in_open(struct global_collection *clp, const char *inf,
+ uint8_t **mmpp, int *mmap_len);
+static int sg_out_open(struct global_collection *clp, const char *outf,
+ uint8_t **mmpp, int *mmap_len);
+static void sg_in_out_interleave(struct global_collection *clp, Rq_elem * rep,
mrq_arr_t & def_arr);
static int sgh_do_deferred_mrq(Rq_elem * rep, mrq_arr_t & def_arr);
@@ -393,7 +394,7 @@ static bool sg_version_ge_40030 = false;
static bool shutting_down = false;
static bool do_sync = false;
static int do_time = 1;
-static Gbl_coll gcoll;
+static struct global_collection gcoll;
static struct timeval start_tm;
static int64_t dd_count = -1;
static int num_threads = DEF_NUM_THREADS;
@@ -755,7 +756,7 @@ siginfo_handler(int sig)
static void
siginfo2_handler(int sig)
{
- Gbl_coll * clp = &gcoll;
+ struct global_collection * clp = &gcoll;
if (sig) { ; } /* unused, dummy to suppress warning */
pr2serr("Progress report, continuing ...\n");
@@ -1053,7 +1054,7 @@ page4:
}
static inline void
-stop_both(Gbl_coll * clp)
+stop_both(struct global_collection * clp)
{
clp->in_stop = true;
clp->out_stop = true;
@@ -1127,7 +1128,7 @@ read_blkdev_capacity(int sg_fd, int64_t * num_sect, int * sect_sz)
static void *
sig_listen_thread(void * v_clp)
{
- Gbl_coll * clp = (Gbl_coll *)v_clp;
+ struct global_collection * clp = (struct global_collection *)v_clp;
int sig_number;
while (1) {
@@ -1291,7 +1292,7 @@ sg_take_snap(int sg_fd, int id, bool vb_b)
static void
cleanup_in(void * v_clp)
{
- Gbl_coll * clp = (Gbl_coll *)v_clp;
+ struct global_collection * clp = (struct global_collection *)v_clp;
pr2serr("thread cancelled while in mutex held\n");
stop_both(clp);
@@ -1302,7 +1303,7 @@ cleanup_in(void * v_clp)
static void
cleanup_out(void * v_clp)
{
- Gbl_coll * clp = (Gbl_coll *)v_clp;
+ struct global_collection * clp = (struct global_collection *)v_clp;
pr2serr("thread cancelled while out_mutex held\n");
stop_both(clp);
@@ -1312,7 +1313,7 @@ cleanup_out(void * v_clp)
static void inline buffp_onto_next(Rq_elem * rep)
{
- Gbl_coll * clp = rep->clp;
+ struct global_collection * clp = rep->clp;
if ((clp->nmrqs > 0) && clp->unbalanced_mrq) {
++rep->mrq_index;
@@ -1324,7 +1325,7 @@ static void inline buffp_onto_next(Rq_elem * rep)
static inline uint8_t *
get_buffp(Rq_elem * rep)
{
- Gbl_coll * clp = rep->clp;
+ struct global_collection * clp = rep->clp;
if ((clp->nmrqs > 0) && clp->unbalanced_mrq && (rep->mrq_index > 0))
return rep->buffp + (rep->mrq_index * clp->bs * clp->bpt);
@@ -1336,7 +1337,7 @@ static void *
read_write_thread(void * v_tip)
{
Thread_info * tip;
- Gbl_coll * clp;
+ struct global_collection * clp;
Rq_elem rel;
Rq_elem * rep = &rel;
int n, sz, blocks, status, vb, err, res, wr_blks;
@@ -1695,7 +1696,7 @@ fini:
static bool
normal_in_rd(Rq_elem * rep, int blocks)
{
- Gbl_coll * clp = rep->clp;
+ struct global_collection * clp = rep->clp;
bool stop_after_write = false;
bool same_fds = clp->in_flags.same_fds || clp->out_flags.same_fds;
int res;
@@ -1758,7 +1759,7 @@ static void
normal_out_wr(Rq_elem * rep, int blocks)
{
int res;
- Gbl_coll * clp = rep->clp;
+ struct global_collection * clp = rep->clp;
char strerr_buff[STRERR_BUFF_LEN];
/* enters holding out_mutex */
@@ -1880,7 +1881,8 @@ sg_build_scsi_cdb(uint8_t * cdbp, int cdb_sz, unsigned int blocks,
/* Enters this function holding in_mutex */
static void
-sg_in_rd_cmd(Gbl_coll * clp, Rq_elem * rep, mrq_arr_t & def_arr)
+sg_in_rd_cmd(struct global_collection * clp, Rq_elem * rep,
+ mrq_arr_t & def_arr)
{
int res, status, pack_id;
@@ -1958,7 +1960,7 @@ sg_wr_swap_share(Rq_elem * rep, int to_fd, bool before)
int err = 0;
int k;
int master_fd = rep->infd; /* in (READ) side is master */
- Gbl_coll * clp = rep->clp;
+ struct global_collection * clp = rep->clp;
struct sg_extended_info sei;
struct sg_extended_info * seip = &sei;
@@ -2008,7 +2010,7 @@ static void
sg_out_wr_cmd(Rq_elem * rep, mrq_arr_t & def_arr, bool is_wr2, bool prefetch)
{
int res, status, pack_id, nblks;
- Gbl_coll * clp = rep->clp;
+ struct global_collection * clp = rep->clp;
uint32_t ofsplit = clp->ofsplit;
pthread_mutex_t * mutexp = is_wr2 ? &clp->out2_mutex : &clp->out_mutex;
struct sg_io_extra xtr;
@@ -2159,7 +2161,7 @@ chk_mrq_response(Rq_elem * rep, const struct sg_io_v4 * ctl_v4p,
const struct sg_io_v4 * a_v4p, int nrq,
uint32_t * good_inblksp, uint32_t * good_outblksp)
{
- Gbl_coll * clp = rep->clp;
+ struct global_collection * clp = rep->clp;
bool ok;
int id = rep->id;
int resid = ctl_v4p->din_resid;
@@ -2274,7 +2276,7 @@ sgh_do_async_mrq(Rq_elem * rep, mrq_arr_t & def_arr, int fd,
uint32_t in_fin_blks, out_fin_blks;
struct sg_io_v4 * a_v4p;
struct sg_io_v4 hold_ctlo;
- Gbl_coll * clp = rep->clp;
+ struct global_collection * clp = rep->clp;
char b[80];
hold_ctlo = *ctlop;
@@ -2498,7 +2500,7 @@ sgh_do_deferred_mrq(Rq_elem * rep, mrq_arr_t & def_arr)
struct sg_io_v4 * a_v4p;
struct sg_io_v4 ctl_v4;
uint8_t * cmd_ap = NULL;
- Gbl_coll * clp = rep->clp;
+ struct global_collection * clp = rep->clp;
const char * iosub_str;
char b[80];
@@ -2775,7 +2777,7 @@ static int
sg_start_io(Rq_elem * rep, mrq_arr_t & def_arr, int & pack_id,
struct sg_io_extra *xtrp)
{
- Gbl_coll * clp = rep->clp;
+ struct global_collection * clp = rep->clp;
bool wr = rep->wr;
bool fua = wr ? clp->out_flags.fua : clp->in_flags.fua;
bool dpo = wr ? clp->out_flags.dpo : clp->in_flags.dpo;
@@ -3074,7 +3076,7 @@ do_v4:
static int
sg_finish_io(bool wr, Rq_elem * rep, int pack_id, struct sg_io_extra *xtrp)
{
- Gbl_coll * clp = rep->clp;
+ struct global_collection * clp = rep->clp;
bool v4 = wr ? clp->out_flags.v4 : clp->in_flags.v4;
bool is_wr2 = xtrp ? xtrp->is_wr2 : false;
bool prefetch = xtrp ? xtrp->prefetch : false;
@@ -3259,7 +3261,8 @@ do_v4:
/* Enter holding in_mutex, exits holding nothing */
static void
-sg_in_out_interleave(Gbl_coll *clp, Rq_elem * rep, mrq_arr_t & def_arr)
+sg_in_out_interleave(struct global_collection *clp, Rq_elem * rep,
+ mrq_arr_t & def_arr)
{
int res, pid_read, pid_write;
int status;
@@ -3649,7 +3652,8 @@ num_chs_in_str(const char * s, int slen, int ch)
}
static int
-sg_in_open(Gbl_coll *clp, const char *inf, uint8_t **mmpp, int * mmap_lenp)
+sg_in_open(struct global_collection *clp, const char *inf, uint8_t **mmpp,
+ int * mmap_lenp)
{
int fd, err, n;
int flags = O_RDWR;
@@ -3683,7 +3687,8 @@ sg_in_open(Gbl_coll *clp, const char *inf, uint8_t **mmpp, int * mmap_lenp)
}
static int
-sg_out_open(Gbl_coll *clp, const char *outf, uint8_t **mmpp, int * mmap_lenp)
+sg_out_open(struct global_collection *clp, const char *outf, uint8_t **mmpp,
+ int * mmap_lenp)
{
int fd, err, n;
int flags = O_RDWR;
@@ -3720,8 +3725,8 @@ sg_out_open(Gbl_coll *clp, const char *outf, uint8_t **mmpp, int * mmap_lenp)
#define INOUTF_SZ 512
static int
-parse_cmdline_sanity(int argc, char * argv[], Gbl_coll * clp, char * inf,
- char * outf, char * out2f, char * outregf)
+parse_cmdline_sanity(int argc, char * argv[], struct global_collection * clp,
+ char * inf, char * outf, char * out2f, char * outregf)
{
bool verbose_given = false;
bool version_given = false;
@@ -4111,7 +4116,7 @@ main(int argc, char * argv[])
int64_t out_num_sect = 0;
int in_sect_sz, out_sect_sz, status, flags;
void * vp;
- Gbl_coll * clp = &gcoll;
+ struct global_collection * clp = &gcoll;
Thread_info thread_arr[MAX_NUM_THREADS];
char ebuff[EBUFF_SZ];
#if SG_LIB_ANDROID
@@ -4124,7 +4129,7 @@ main(int argc, char * argv[])
sigaction(SIGUSR1, &actions, NULL);
sigaction(SIGUSR2, &actions, NULL);
#endif
- memset(clp, 0, sizeof(*clp));
+ /* memset(clp, 0, sizeof(*clp)); */
memset(thread_arr, 0, sizeof(thread_arr));
clp->bpt = DEF_BLOCKS_PER_TRANSFER;
clp->in_type = FT_OTHER;
@@ -4435,7 +4440,12 @@ main(int argc, char * argv[])
pr2serr("read capacity failed, %s not ready\n", inf);
else
pr2serr("Unable to read capacity on %s\n", inf);
- in_num_sect = -1;
+ return SG_LIB_FILE_ERROR;
+ } else if (clp->bs != in_sect_sz) {
+ pr2serr(">> warning: logical block size on %s confusion: "
+ "bs=%d, device claims=%d\n", clp->infp, clp->bs,
+ in_sect_sz);
+ return SG_LIB_FILE_ERROR;
}
} else if (FT_BLOCK == clp->in_type) {
if (0 != read_blkdev_capacity(clp->infd, &in_num_sect,
@@ -4468,6 +4478,12 @@ main(int argc, char * argv[])
else
pr2serr("Unable to read capacity on %s\n", outf);
out_num_sect = -1;
+ return SG_LIB_FILE_ERROR;
+ } else if (clp->bs != out_sect_sz) {
+ pr2serr(">> warning: logical block size on %s confusion: "
+ "bs=%d, device claims=%d\n", clp->outfp, clp->bs,
+ out_sect_sz);
+ return SG_LIB_FILE_ERROR;
}
} else if (FT_BLOCK == clp->out_type) {
if (0 != read_blkdev_capacity(clp->outfd, &out_num_sect,