diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/Makefile.cplus | 2 | ||||
-rw-r--r-- | testing/sg_tst_async.cpp | 46 | ||||
-rw-r--r-- | testing/sgh_dd.cpp | 4 | ||||
-rw-r--r-- | testing/sgs_dd.c | 24 |
4 files changed, 50 insertions, 26 deletions
diff --git a/testing/Makefile.cplus b/testing/Makefile.cplus index 052e815e..871136ff 100644 --- a/testing/Makefile.cplus +++ b/testing/Makefile.cplus @@ -67,7 +67,7 @@ sg_tst_async: sg_tst_async.o $(LIBFILESNEW) $(CXXLD) -o $@ $(LDFLAGS) $^ sgh_dd: sgh_dd.o $(LIBFILESNEW) - $(CXXLD) -o $@ $(LDFLAGS) -pthread $^ + $(CXXLD) -o $@ $(LDFLAGS) -pthread -latomic $^ install: $(EXECS) install -d $(INSTDIR) diff --git a/testing/sg_tst_async.cpp b/testing/sg_tst_async.cpp index 74123456..aa05ca95 100644 --- a/testing/sg_tst_async.cpp +++ b/testing/sg_tst_async.cpp @@ -89,7 +89,7 @@ #include "sg_pt.h" #include "sg_cmds.h" -static const char * version_str = "1.37 20190618"; +static const char * version_str = "1.38 20190728"; static const char * util_name = "sg_tst_async"; /* This is a test program for checking the async usage of the Linux sg @@ -191,6 +191,7 @@ struct opts_t { bool block; bool cmd_time; bool direct; + bool excl; bool generic_sync; bool masync; bool mmap_io; @@ -274,6 +275,7 @@ static struct option long_options[] = { {"cmd-time", no_argument, 0, 'c'}, {"cmd_time", no_argument, 0, 'c'}, {"direct", no_argument, 0, 'd'}, + {"excl", no_argument, 0, 'e'}, {"force", no_argument, 0, 'f'}, {"generic-sync", no_argument, 0, 'g'}, {"generic_sync", no_argument, 0, 'g'}, @@ -309,23 +311,24 @@ static struct option long_options[] = { static void usage(void) { - printf("Usage: %s [--cmd-time] [--direct] [--force] [--generic-sync]\n" - " [--help] [--lba=LBA+] [--lbsz=LBSZ] " - "[--masync]\n" - " [--maxqpt=QPT] [--mmap-io] [--numpt=NPT] " - "[--noxfer]\n" - " [--override=OVN] [--pack-id] [--qat=AT] " - "[-qfav=FAV]\n" - " [--read] [--stats] [--submit] " - "[--szlb=LB[,NLBS]]\n" - " [--tnum=NT] [--tur] [--v3] [--v4] " - "[--verbose]\n" - " [--version] [--wait=MS] [--write] " - "<sg_disk_device>*\n", + printf("Usage: %s [--cmd-time] [--direct] [--excl] [--force]\n" + " [--generic-sync] [--help] [--lba=LBA+] " + "[--lbsz=LBSZ]\n" + " [--masync] [--maxqpt=QPT] [--mmap-io] " + "[--numpt=NPT]\n" + " [--noxfer] [--override=OVN] [--pack-id] " + "[--qat=AT]\n" + " [-qfav=FAV] [--read] [--stats] [--submit]\n" + " [--szlb=LB[,NLBS]] [--tnum=NT] [--tur] " + "[--v3] [--v4]\n" + " [--verbose] [--version] [--wait=MS] " + "[--write]\n" + " <sg_disk_device>*\n", util_name); printf(" where\n"); printf(" --cmd-time|-c calculate per command average time (ns)\n"); printf(" --direct|-d do direct_io (def: indirect)\n"); + printf(" --excl|-e do wait_exclusive calls\n"); printf(" --force|-f force: any sg device (def: only scsi_debug " "owned)\n"); printf(" WARNING: <lba> written to if '-W' given\n"); @@ -883,6 +886,8 @@ work_sync_thread(int id, const char * dev_name, unsigned int /* hi_lba */, pr_rusage(id); goto err_out; } + if (vb > 2) + pr2serr_lk(">>>> id=%d: open(%s) --> fd=%d\n", id, dev_name, sg_fd); ptp = construct_scsi_pt_obj_with_fd(sg_fd, vb); err = 0; @@ -897,7 +902,7 @@ work_sync_thread(int id, const char * dev_name, unsigned int /* hi_lba */, memset(cdb, 0, sizeof(cdb)); /* TUR's cdb is 6 zeros */ set_scsi_pt_cdb(ptp, cdb, sizeof(cdb)); set_scsi_pt_sense(ptp, sense_b, sizeof(sense_b)); - set_scsi_pt_packet_id(ptp, uniq_pack_id.fetch_add(1)); + set_scsi_pt_packet_id(ptp, uniq_pack_id.fetch_add(1)); ++thr_sync_starts; rs = do_scsi_pt(ptp, -1, DEF_PT_TIMEOUT, vb); n = sg_cmds_process_resp(ptp, "Test unit ready", rs, @@ -1026,6 +1031,8 @@ work_thread(int id, struct opts_t * op) pr_rusage(id); return; } + if (vb > 2) + pr2serr_lk(">>>> id=%d: open(%s) --> fd=%d\n", id, dev_name, sg_fd); if (op->pack_id_force) { k = 1; if (ioctl(sg_fd, SG_SET_FORCE_PACK_ID, &k) < 0) @@ -1054,6 +1061,10 @@ work_thread(int id, struct opts_t * op) seip->ctl_flags_wr_mask |= SG_CTL_FLAGM_MORE_ASYNC; seip->ctl_flags |= SG_CTL_FLAGM_MORE_ASYNC; } + if (op->excl) { + seip->ctl_flags_wr_mask |= SG_CTL_FLAGM_EXCL_WAITQ; + seip->ctl_flags |= SG_CTL_FLAGM_EXCL_WAITQ; + } if (ioctl(sg_fd, SG_SET_GET_EXTENDED, seip) < 0) { pr2serr_lk("ioctl(EXTENDED(TIME_IN_NS)) failed, errno=%d %s\n", errno, strerror(errno)); @@ -1764,7 +1775,7 @@ main(int argc, char * argv[]) while (1) { int option_index = 0; - c = getopt_long(argc, argv, "34acdfghl:L:mM:n:NO:pq:Q:Rs:St:TuvVw:W", + c = getopt_long(argc, argv, "34acdefghl:L:mM:n:NO:pq:Q:Rs:St:TuvVw:W", long_options, &option_index); if (c == -1) break; @@ -1791,6 +1802,9 @@ main(int argc, char * argv[]) case 'd': op->direct = true; break; + case 'e': + op->excl = true; + break; case 'f': force = true; break; diff --git a/testing/sgh_dd.cpp b/testing/sgh_dd.cpp index 48b195b1..c5bb731a 100644 --- a/testing/sgh_dd.cpp +++ b/testing/sgh_dd.cpp @@ -108,7 +108,7 @@ using namespace std; -static const char * version_str = "1.40 20190725"; +static const char * version_str = "1.41 20190817"; #ifdef __GNUC__ #ifndef __clang__ @@ -852,7 +852,7 @@ page4: "probably jumped out of active state and\nthe slave request " "entered it while some other nodes were being printed.\n\n"); pr2serr("Busy state:\n" - "Busy state (abreviated to 'bsy' in the /proc/scsi/sg/debug " + "Busy state (abbreviated to 'bsy' in the /proc/scsi/sg/debug " "output)\nis entered during request setup and completion. It " "is intended to be\na temporary state. It should not block " "but does sometimes (e.g. in\nblock_get_request()). Even so " diff --git a/testing/sgs_dd.c b/testing/sgs_dd.c index 022f528e..6f71283c 100644 --- a/testing/sgs_dd.c +++ b/testing/sgs_dd.c @@ -81,7 +81,7 @@ #include "sg_unaligned.h" -static const char * version_str = "4.11 20190625"; +static const char * version_str = "4.12 20190824"; static const char * my_name = "sgs_dd"; #define DEF_BLOCK_SIZE 512 @@ -226,8 +226,9 @@ read_capacity(int sg_fd, int * num_sect, int * sect_sz) io_hdr.timeout = DEF_TIMEOUT; if (ioctl(sg_fd, SG_IO, &io_hdr) < 0) { + res = -errno; perror("read_capacity (SG_IO) error"); - return -1; + return res; } res = sg_err_category3(&io_hdr); if (SG_LIB_CAT_UNIT_ATTENTION == res) @@ -387,11 +388,12 @@ sg_finish_io(Rq_coll * clp, bool wr, Rq_elem ** repp) if (rep) dio = rep->wr ? clp->oflag.dio : clp->iflag.dio; if (res < 0) { + res = -errno; fprintf(stderr, "%s: read(): %s [%d]\n", __func__, strerror(errno), errno); if (rep) rep->state = SGQ_IO_ERR; - return -1; + return res; } if (! (rep && (SGQ_IO_STARTED == rep->state))) { fprintf(stderr, "%s: bad usr_ptr\n", __func__); @@ -432,15 +434,17 @@ do_v4: if (use_pack || use_tag) { while (true) { if ( ((res = ioctl(fd, SG_GET_NUM_WAITING, &n))) < 0) { + res = -errno; fprintf(stderr, "%s: ioctl(SG_GET_NUM_WAITING): %s [%d]\n", __func__, strerror(errno), errno); - return -1; + return res; } if (n > 0) { if ( ((res = ioctl(fd, SG_GET_PACK_ID, &id))) < 0) { + res = -errno; fprintf(stderr, "%s: ioctl(SG_GET_PACK_ID): %s [%d]\n", __func__, strerror(errno), errno); - return -1; + return res; } /* got pack_id or tag of first waiting */ break; @@ -459,11 +463,12 @@ do_v4: ; rep = (Rq_elem *)(unsigned long)io_v4.usr_ptr; if (res < 0) { + res = -errno; fprintf(stderr, "%s: ioctl(SG_IORECEIVE): %s [%d]\n", __func__, strerror(errno), errno); if (rep) rep->state = SGQ_IO_ERR; - return -1; + return res; } if (! (rep && (SGQ_IO_STARTED == rep->state))) { fprintf(stderr, "%s: bad usr_ptr=0x%p\n", __func__, rep); @@ -649,6 +654,7 @@ start_read(Rq_coll * clp) res = sg_start_io(clp, rep); if (1 == res) { /* ENOMEM, find what's available+try that */ if ((res = ioctl(clp->infd, SG_GET_RESERVED_SIZE, &buf_sz)) < 0) { + res = -errno; perror("RESERVED_SIZE ioctls failed"); return res; } @@ -673,6 +679,7 @@ start_read(Rq_coll * clp) (EINTR == errno)) ; if (res < 0) { + res = -errno; snprintf(ebuff, EBUFF_SZ, "sgs_dd: reading, in_blk=%d ", rep->blk); perror(ebuff); rep->state = SGQ_IO_ERR; @@ -736,6 +743,7 @@ start_write(Rq_coll * clp) rep->num_blks * clp->bs)) < 0) && (EINTR == errno)) ; if (res < 0) { + res = -errno; snprintf(ebuff, EBUFF_SZ, "sgs_dd: output, out_blk=%d ", rep->blk); perror(ebuff); rep->state = SGQ_IO_ERR; @@ -1296,6 +1304,7 @@ main(int argc, char * argv[]) fprintf(stderr, "start_read: res=%d\n", res); break; } + res = 0; } if (SGQ_CAN_WRITE & crw) { res = start_write(clp); @@ -1303,6 +1312,7 @@ main(int argc, char * argv[]) fprintf(stderr, "start_write: res=%d\n", res); break; } + res = 0; } } @@ -1329,5 +1339,5 @@ main(int argc, char * argv[]) fprintf(stderr, "SIGIO/SIGPOLL signals received: %d, RT sigs: %d\n", clp->sigs_io_received, clp->sigs_rt_received); remove_elems(clp); - return res; + return res < 0 ? 99 : res; } |