test-tool: remove the --usb argument and use BLCSECTGET to read max xfer

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
Ronnie Sahlberg
2015-02-16 16:04:28 -08:00
parent cb7882a84c
commit 51bd0ce3ec
3 changed files with 16 additions and 38 deletions

View File

@@ -36,6 +36,7 @@
#include <fcntl.h>
#include <sys/ioctl.h>
#include <scsi/sg.h>
#include <sys/mount.h>
#endif
#include <CUnit/CUnit.h>
@@ -54,6 +55,7 @@
int loglevel = LOG_NORMAL;
struct scsi_device *sd;
static unsigned int maxsectbytes;
/*
* this allows us to redefine how PDU are queued, at times, for
@@ -630,9 +632,6 @@ print_usage(void)
" -f|--fail Error Action: FAIL if any tests fail\n");
fprintf(stderr,
" -A|--abort Error Action: ABORT if any tests fail\n");
fprintf(stderr,
" -u|--usb The device is attached to a USB bus.\n"
" Additional restrictions apply, such as maximum transfer length 120kb.\n");
fprintf(stderr,
" -s|--silent Test Mode: Silent\n");
fprintf(stderr,
@@ -885,7 +884,7 @@ static int connect_scsi_device(struct scsi_device *sdev, const char *initiatorna
if (sdev->sgio_dev) {
int version;
if ((sdev->sgio_fd = open(sdev->sgio_dev, O_RDWR)) == -1) {
if ((sdev->sgio_fd = open(sdev->sgio_dev, O_RDWR|O_NONBLOCK)) == -1) {
fprintf(stderr, "Failed to open SG_IO device %s. Error:%s\n", sdev->sgio_dev,
strerror(errno));
return -1;
@@ -895,6 +894,11 @@ static int connect_scsi_device(struct scsi_device *sdev, const char *initiatorna
close(sdev->sgio_fd);
return -1;
}
if (ioctl(sdev->sgio_fd, BLKSECTGET, &maxsectbytes) < 0) {
fprintf(stderr, "%s failed to read BLKMAXSECT\n", sdev->sgio_dev);
close(sdev->sgio_fd);
return -1;
}
return 0;
}
#endif
@@ -943,7 +947,6 @@ main(int argc, char *argv[])
struct scsi_task *rc16_task = NULL;
struct scsi_task *rsop_task = NULL;
int full_size;
int is_usb = 0;
int xml_mode = 0;
static struct option long_opts[] = {
{ "help", no_argument, 0, '?' },
@@ -958,7 +961,6 @@ main(int argc, char *argv[])
{ "abort", no_argument, 0, 'A' },
{ "silent", no_argument, 0, 's' },
{ "normal", no_argument, 0, 'n' },
{ "usb", no_argument, 0, 'u' },
{ "verbose", no_argument, 0, 'v' },
{ "xml", no_argument, 0, 'x' },
{ "Verbose-scsi", no_argument, 0, 'V' },
@@ -971,7 +973,7 @@ main(int argc, char *argv[])
memset(sd, '\0', sizeof(struct scsi_device));
sd->sgio_fd = -1;
while ((c = getopt_long(argc, argv, "?hli:I:t:sdgfAsSnuvxV", long_opts,
while ((c = getopt_long(argc, argv, "?hli:I:t:sdgfAsSnvxV", long_opts,
&opt_idx)) > 0) {
switch (c) {
case 'h':
@@ -1011,9 +1013,6 @@ main(int argc, char *argv[])
case 'n':
mode = CU_BRM_NORMAL;
break;
case 'u':
is_usb = 1;
break;
case 'v':
mode = CU_BRM_VERBOSE; /* default */
break;
@@ -1259,9 +1258,10 @@ main(int argc, char *argv[])
}
scsi_free_scsi_task(task);
if (is_usb) {
printf("USB device. Clamping maximum transfer length to 120k\n");
maximum_transfer_length = 120 *1024 / block_size;
if (maxsectbytes) {
maximum_transfer_length = maxsectbytes / block_size;
printf("Bus transfer size is limited to %d bytes. Clamping "
"max transfers accordingly.\n", maxsectbytes);
}
if (CU_initialize_registry() != 0) {