From 91155c42e410f7d385411949beb6cd272f094072 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Thu, 27 Dec 2012 11:47:34 -0800 Subject: [PATCH] TESTS: Read standard inq page before we spawn the tests We dont need to call inq so often from the tests if we read the standard page once before the tests begin --- test-tool/0103_read10_rdprotect.c | 37 +---------- test-tool/0104_read10_flags.c | 15 +---- test-tool/0202_read16_flags.c | 15 +---- test-tool/0212_read12_flags.c | 15 +---- test-tool/0222_write16_flags.c | 15 +---- test-tool/0232_write12_flags.c | 15 +---- test-tool/0292_write10_flags.c | 15 +---- test-tool/0300_readonly.c | 19 +----- test-tool/0360_startstopunit_simple.c | 30 +-------- test-tool/0361_startstopunit_pwrcnd.c | 30 +-------- test-tool/0362_startstopunit_noloej.c | 30 +-------- test-tool/0370_nomedia.c | 35 +---------- test-tool/0380_preventallow_simple.c | 30 +-------- test-tool/0381_preventallow_eject.c | 37 ++--------- test-tool/0382_preventallow_itnexus_loss.c | 30 +-------- .../0383_preventallow_target_warm_reset.c | 37 ++--------- .../0384_preventallow_target_cold_reset.c | 37 ++--------- test-tool/0385_preventallow_lun_reset.c | 37 ++--------- test-tool/0386_preventallow_2_it_nexuses.c | 36 +---------- test-tool/0390_mandatory_opcodes_sbc.c | 50 ++------------- test-tool/iscsi-test.c | 61 +++++++++++++++++++ test-tool/iscsi-test.h | 5 ++ 22 files changed, 106 insertions(+), 525 deletions(-) diff --git a/test-tool/0103_read10_rdprotect.c b/test-tool/0103_read10_rdprotect.c index 8646a94..64db44e 100644 --- a/test-tool/0103_read10_rdprotect.c +++ b/test-tool/0103_read10_rdprotect.c @@ -26,8 +26,6 @@ int T0103_read10_rdprotect(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - int full_size; - struct scsi_inquiry_standard *inq; int ret, i, lun; printf("0103_read10_rdprotect:\n"); @@ -45,44 +43,11 @@ int T0103_read10_rdprotect(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - - if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { + if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { printf("LUN is not SBC device. Skipping test\n"); - scsi_free_scsi_task(task); return -2; } - if (inq->protect) { - printf("LUN is formatted with protection information. Skipping test\n"); - scsi_free_scsi_task(task); - return -2; - } - - scsi_free_scsi_task(task); - ret = 0; diff --git a/test-tool/0104_read10_flags.c b/test-tool/0104_read10_flags.c index bb18fbb..94bc31f 100644 --- a/test-tool/0104_read10_flags.c +++ b/test-tool/0104_read10_flags.c @@ -26,7 +26,6 @@ int T0104_read10_flags(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; int ret, lun; printf("0104_read10_flags:\n"); @@ -49,20 +48,8 @@ int T0104_read10_flags(const char *initiator, const char *url) } /* This test is only valid for SBC devices */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { + if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { printf("LUN is not SBC device. Skipping test\n"); - scsi_free_scsi_task(task); return -2; } diff --git a/test-tool/0202_read16_flags.c b/test-tool/0202_read16_flags.c index 66e077a..89077d3 100644 --- a/test-tool/0202_read16_flags.c +++ b/test-tool/0202_read16_flags.c @@ -24,7 +24,6 @@ int T0202_read16_flags(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; int ret = 0, lun; printf("0202_read16_flags:\n"); @@ -46,20 +45,8 @@ int T0202_read16_flags(const char *initiator, const char *url) } /* This test is only valid for SBC devices */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { + if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { printf("LUN is not SBC device. Skipping test\n"); - scsi_free_scsi_task(task); return -2; } diff --git a/test-tool/0212_read12_flags.c b/test-tool/0212_read12_flags.c index a67f129..995fb8f 100644 --- a/test-tool/0212_read12_flags.c +++ b/test-tool/0212_read12_flags.c @@ -24,7 +24,6 @@ int T0212_read12_flags(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; int ret = 0, lun; printf("0212_read12_flags:\n"); @@ -46,20 +45,8 @@ int T0212_read12_flags(const char *initiator, const char *url) } /* This test is only valid for SBC devices */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { + if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { printf("LUN is not SBC device. Skipping test\n"); - scsi_free_scsi_task(task); return -2; } diff --git a/test-tool/0222_write16_flags.c b/test-tool/0222_write16_flags.c index 1eacb65..c80a549 100644 --- a/test-tool/0222_write16_flags.c +++ b/test-tool/0222_write16_flags.c @@ -24,7 +24,6 @@ int T0222_write16_flags(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; int ret = 0, lun; unsigned char data[4096 * 256]; @@ -47,20 +46,8 @@ int T0222_write16_flags(const char *initiator, const char *url) } /* This test is only valid for SBC devices */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { + if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { printf("LUN is not SBC device. Skipping test\n"); - scsi_free_scsi_task(task); return -2; } diff --git a/test-tool/0232_write12_flags.c b/test-tool/0232_write12_flags.c index 2b98b20..96541b9 100644 --- a/test-tool/0232_write12_flags.c +++ b/test-tool/0232_write12_flags.c @@ -24,7 +24,6 @@ int T0232_write12_flags(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; int ret = 0, lun; unsigned char data[4096]; @@ -47,20 +46,8 @@ int T0232_write12_flags(const char *initiator, const char *url) } /* This test is only valid for SBC devices */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { + if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { printf("LUN is not SBC device. Skipping test\n"); - scsi_free_scsi_task(task); return -2; } diff --git a/test-tool/0292_write10_flags.c b/test-tool/0292_write10_flags.c index 31a85ac..3ea948d 100644 --- a/test-tool/0292_write10_flags.c +++ b/test-tool/0292_write10_flags.c @@ -24,7 +24,6 @@ int T0292_write10_flags(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; int ret = 0, lun; unsigned char data[4096]; @@ -47,20 +46,8 @@ int T0292_write10_flags(const char *initiator, const char *url) } /* This test is only valid for SBC devices */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { + if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { printf("LUN is not SBC device. Skipping test\n"); - scsi_free_scsi_task(task); return -2; } diff --git a/test-tool/0300_readonly.c b/test-tool/0300_readonly.c index 5e439e4..23e9685 100644 --- a/test-tool/0300_readonly.c +++ b/test-tool/0300_readonly.c @@ -24,12 +24,11 @@ int T0300_readonly(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; struct scsi_mode_sense *ms; int ret, lun; unsigned char data[4096]; - int full_size; struct unmap_list list[1]; + int full_size; ret = -1; @@ -67,21 +66,9 @@ int T0300_readonly(const char *initiator, const char *url) } /* This test is only valid for SBC devices */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { + if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { printf("LUN is not SBC device. Skipping test\n"); - scsi_free_scsi_task(task); - return -1; + return -2; } /* verify the device is readonly */ diff --git a/test-tool/0360_startstopunit_simple.c b/test-tool/0360_startstopunit_simple.c index 087755b..a80a9cf 100644 --- a/test-tool/0360_startstopunit_simple.c +++ b/test-tool/0360_startstopunit_simple.c @@ -25,9 +25,7 @@ int T0360_startstopunit_simple(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret, lun, removable; - int full_size; + int ret, lun; printf("0360_startstopunit_simple:\n"); printf("===================\n"); @@ -47,32 +45,6 @@ int T0360_startstopunit_simple(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - removable = inq->rmb; - - scsi_free_scsi_task(task); - if (!data_loss) { printf("--dataloss flag is not set. Skipping test\n"); ret = -2; diff --git a/test-tool/0361_startstopunit_pwrcnd.c b/test-tool/0361_startstopunit_pwrcnd.c index 5b8ba8e..ba92b6a 100644 --- a/test-tool/0361_startstopunit_pwrcnd.c +++ b/test-tool/0361_startstopunit_pwrcnd.c @@ -25,9 +25,7 @@ int T0361_startstopunit_pwrcnd(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret, i, lun, removable; - int full_size; + int ret, i, lun; printf("0361_startstopunit_pwrcnd:\n"); printf("===================\n"); @@ -45,32 +43,6 @@ int T0361_startstopunit_pwrcnd(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - removable = inq->rmb; - - scsi_free_scsi_task(task); - if (!data_loss) { printf("--dataloss flag is not set. Skipping test\n"); ret = -2; diff --git a/test-tool/0362_startstopunit_noloej.c b/test-tool/0362_startstopunit_noloej.c index 96a45d0..2d0b056 100644 --- a/test-tool/0362_startstopunit_noloej.c +++ b/test-tool/0362_startstopunit_noloej.c @@ -25,9 +25,7 @@ int T0362_startstopunit_noloej(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret, lun, removable; - int full_size; + int ret, lun; printf("0362_startstopunit_noloej:\n"); printf("===================\n"); @@ -51,32 +49,6 @@ int T0362_startstopunit_noloej(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - removable = inq->rmb; - - scsi_free_scsi_task(task); - if (!data_loss) { printf("--dataloss flag is not set. Skipping test\n"); ret = -2; diff --git a/test-tool/0370_nomedia.c b/test-tool/0370_nomedia.c index 3f67ffa..9281fee 100644 --- a/test-tool/0370_nomedia.c +++ b/test-tool/0370_nomedia.c @@ -25,9 +25,7 @@ int T0370_nomedia(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret, lun, removable; - int full_size; + int ret, lun; unsigned char buf[4096]; printf("0370_nomedia:\n"); @@ -73,42 +71,13 @@ int T0370_nomedia(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - removable = inq->rmb; - - scsi_free_scsi_task(task); - - ret = 0; - - if (!removable) { printf("Media is not removable. Skipping test.\n"); ret = -2; goto finished; } - + ret = 0; printf("Try to eject the media ... "); task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0); diff --git a/test-tool/0380_preventallow_simple.c b/test-tool/0380_preventallow_simple.c index 466d398..abc8bbc 100644 --- a/test-tool/0380_preventallow_simple.c +++ b/test-tool/0380_preventallow_simple.c @@ -25,9 +25,7 @@ int T0380_preventallow_simple(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret, lun, removable; - int full_size; + int ret, lun; printf("0380_preventallow_simple:\n"); printf("=========================\n"); @@ -45,32 +43,6 @@ int T0380_preventallow_simple(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - removable = inq->rmb; - - scsi_free_scsi_task(task); - if (!data_loss) { printf("--dataloss flag is not set. Skipping test\n"); ret = -2; diff --git a/test-tool/0381_preventallow_eject.c b/test-tool/0381_preventallow_eject.c index b4cc647..e3aee4b 100644 --- a/test-tool/0381_preventallow_eject.c +++ b/test-tool/0381_preventallow_eject.c @@ -25,9 +25,7 @@ int T0381_preventallow_eject(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret, lun, removable; - int full_size; + int ret, lun; printf("0381_preventallow_eject:\n"); printf("========================\n"); @@ -47,48 +45,21 @@ int T0381_preventallow_eject(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - removable = inq->rmb; - - scsi_free_scsi_task(task); - if (!data_loss) { printf("--dataloss flag is not set. Skipping test\n"); ret = -2; goto finished; } - - ret = 0; - - if (!removable) { printf("Media is not removable. Skipping tests\n"); ret = -2; goto finished; } + ret = 0; + + printf("Try to set PREVENTALLOW ... "); task = iscsi_preventallow_sync(iscsi, lun, 1); if (task == NULL) { diff --git a/test-tool/0382_preventallow_itnexus_loss.c b/test-tool/0382_preventallow_itnexus_loss.c index 944fbc4..6c57da2 100644 --- a/test-tool/0382_preventallow_itnexus_loss.c +++ b/test-tool/0382_preventallow_itnexus_loss.c @@ -25,9 +25,7 @@ int T0382_preventallow_itnexus_loss(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret, lun, removable; - int full_size; + int ret, lun; printf("0382_preventallow_itnexus_loss:\n"); printf("===============================\n"); @@ -49,32 +47,6 @@ int T0382_preventallow_itnexus_loss(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - removable = inq->rmb; - - scsi_free_scsi_task(task); - if (!data_loss) { printf("--dataloss flag is not set. Skipping test\n"); ret = -2; diff --git a/test-tool/0383_preventallow_target_warm_reset.c b/test-tool/0383_preventallow_target_warm_reset.c index a4be3bc..5c91591 100644 --- a/test-tool/0383_preventallow_target_warm_reset.c +++ b/test-tool/0383_preventallow_target_warm_reset.c @@ -41,9 +41,7 @@ int T0383_preventallow_target_warm_reset(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret, lun, removable; - int full_size; + int ret, lun; struct mgmt_task mgmt_task = {0, 0}; struct pollfd pfd; @@ -67,48 +65,21 @@ int T0383_preventallow_target_warm_reset(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - removable = inq->rmb; - - scsi_free_scsi_task(task); - if (!data_loss) { printf("--dataloss flag is not set. Skipping test\n"); ret = -2; goto finished; } - - ret = 0; - - if (!removable) { printf("Media is not removable. Skipping tests\n"); ret = -2; goto finished; } + ret = 0; + + printf("Try to set PREVENTALLOW ... "); task = iscsi_preventallow_sync(iscsi, lun, 1); if (task == NULL) { diff --git a/test-tool/0384_preventallow_target_cold_reset.c b/test-tool/0384_preventallow_target_cold_reset.c index 0873001..00eadbd 100644 --- a/test-tool/0384_preventallow_target_cold_reset.c +++ b/test-tool/0384_preventallow_target_cold_reset.c @@ -41,9 +41,7 @@ int T0384_preventallow_target_cold_reset(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret, lun, removable; - int full_size; + int ret, lun; struct mgmt_task mgmt_task = {0, 0}; struct pollfd pfd; @@ -67,47 +65,20 @@ int T0384_preventallow_target_cold_reset(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - removable = inq->rmb; - - scsi_free_scsi_task(task); - if (!data_loss) { printf("--dataloss flag is not set. Skipping test\n"); ret = -2; goto finished; } - - - ret = 0; - if (!removable) { printf("Media is not removable. Skipping tests\n"); ret = -2; goto finished; } + + ret = 0; + printf("Try to set PREVENTALLOW ... "); task = iscsi_preventallow_sync(iscsi, lun, 1); diff --git a/test-tool/0385_preventallow_lun_reset.c b/test-tool/0385_preventallow_lun_reset.c index 52f8048..bdb770b 100644 --- a/test-tool/0385_preventallow_lun_reset.c +++ b/test-tool/0385_preventallow_lun_reset.c @@ -41,9 +41,7 @@ int T0385_preventallow_lun_reset(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret, lun, removable; - int full_size; + int ret, lun; struct mgmt_task mgmt_task = {0, 0}; struct pollfd pfd; @@ -67,47 +65,20 @@ int T0385_preventallow_lun_reset(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - removable = inq->rmb; - - scsi_free_scsi_task(task); - if (!data_loss) { printf("--dataloss flag is not set. Skipping test\n"); ret = -2; goto finished; } - - - ret = 0; - if (!removable) { printf("Media is not removable. Skipping tests\n"); ret = -2; goto finished; } + + ret = 0; + printf("Try to set PREVENTALLOW ... "); task = iscsi_preventallow_sync(iscsi, lun, 1); diff --git a/test-tool/0386_preventallow_2_it_nexuses.c b/test-tool/0386_preventallow_2_it_nexuses.c index b1be112..bed2b99 100644 --- a/test-tool/0386_preventallow_2_it_nexuses.c +++ b/test-tool/0386_preventallow_2_it_nexuses.c @@ -26,9 +26,7 @@ int T0386_preventallow_2_itl_nexuses(const char *initiator, const char *url) struct iscsi_context *iscsi; struct iscsi_context *iscsi2 = NULL; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret, lun, removable; - int full_size; + int ret, lun; printf("0386_preventallow_2_itl_nexuses:\n"); printf("============================\n"); @@ -50,41 +48,11 @@ int T0386_preventallow_2_itl_nexuses(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - removable = inq->rmb; - - scsi_free_scsi_task(task); - if (!data_loss) { printf("--dataloss flag is not set. Skipping test\n"); ret = -2; goto finished; } - - - ret = 0; - if (!removable) { printf("Media is not removable. Skipping tests\n"); @@ -92,6 +60,8 @@ int T0386_preventallow_2_itl_nexuses(const char *initiator, const char *url) goto finished; } + ret = 0; + printf("Try to set PREVENTALLOW on 2 different IT_Nexusen ... "); task = iscsi_preventallow_sync(iscsi, lun, 1); diff --git a/test-tool/0390_mandatory_opcodes_sbc.c b/test-tool/0390_mandatory_opcodes_sbc.c index b8579c7..c7474d5 100644 --- a/test-tool/0390_mandatory_opcodes_sbc.c +++ b/test-tool/0390_mandatory_opcodes_sbc.c @@ -25,10 +25,8 @@ int T0390_mandatory_opcodes_sbc(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; - struct scsi_inquiry_standard *inq; - int ret = 0, lun, sccs, encserv; + int ret = 0, lun; unsigned char data[4096]; - int full_size; printf("0390_mandatory_opcodes_sbc:\n"); printf("===========================\n"); @@ -64,39 +62,12 @@ int T0390_mandatory_opcodes_sbc(const char *initiator, const char *url) return -1; } - /* See how big this inquiry data is */ - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - full_size = scsi_datain_getfullsize(task); - if (full_size > task->datain.size) { - scsi_free_scsi_task(task); - - /* we need more data for the full list */ - if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); - return -1; - } - } - inq = scsi_datain_unmarshall(task); - if (inq == NULL) { - printf("failed to unmarshall inquiry datain blob\n"); - scsi_free_scsi_task(task); - return -1; - } - sccs = inq->sccs; - encserv = inq->encserv; - if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { + if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { printf("Not a SBC device. Skipping test\n"); - scsi_free_scsi_task(task); ret = -2; goto finished; } - scsi_free_scsi_task(task); - if (!data_loss) { printf("--dataloss flag is not set. Skipping test\n"); ret = -2; @@ -104,27 +75,14 @@ int T0390_mandatory_opcodes_sbc(const char *initiator, const char *url) } - printf("Test FORMAT UNIT ... "); printf("[TEST NOT IMPLEMENTED YET]\n"); - printf("Test INQUIRY ... "); - task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send INQUIRY command: %s\n", iscsi_get_error(iscsi)); + printf("Test INQUIRY.\n"); + if (inquiry(iscsi, lun, 0, 0, 64) == -1) { ret = -1; - goto finished; } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("INQUIRY command: failed with sense %s\n", iscsi_get_error(iscsi)); - ret = -1; - } else { - printf("[OK]\n"); - } - scsi_free_scsi_task(task); printf("Test MAINTENANCE IN ... "); diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index 9f13ef2..1450355 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -47,6 +47,10 @@ uint64_t num_blocks; int lbpme; int lbppb; int lbpme; +int removable; +enum scsi_inquiry_peripheral_device_type device_type; +int sccs; +int encserv; int data_loss; int show_info; @@ -1404,6 +1408,30 @@ int verify16_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char * return 0; } +int inquiry(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize) +{ + struct scsi_task *task; + + printf("Send INQUIRY evpd:%d page_code:%d ... ", evpd, page_code); + task = iscsi_inquiry_sync(iscsi, lun, evpd, page_code, maxsize); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send INQUIRY command: %s\n", iscsi_get_error(iscsi)); + return -1; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("INQUIRY command: failed with sense. %s\n", iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + printf("[OK]\n"); + scsi_free_scsi_task(task); + return 0; +} + + int main(int argc, const char *argv[]) { poptContext pc; @@ -1420,6 +1448,8 @@ int main(int argc, const char *argv[]) struct scsi_task *task; struct scsi_readcapacity10 *rc10; struct scsi_readcapacity16 *rc16; + struct scsi_inquiry_standard *inq; + int full_size; struct poptOption popt_options[] = { { "help", '?', POPT_ARG_NONE, &show_help, 0, "Show this help message", NULL }, @@ -1536,6 +1566,37 @@ int main(int argc, const char *argv[]) scsi_free_scsi_task(task); } + + + task = iscsi_inquiry_sync(iscsi, lun, 0, 0, 64); + if (task == NULL || task->status != SCSI_STATUS_GOOD) { + printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); + return -1; + } + full_size = scsi_datain_getfullsize(task); + if (full_size > task->datain.size) { + scsi_free_scsi_task(task); + + /* we need more data for the full list */ + if ((task = iscsi_inquiry_sync(iscsi, lun, 0, 0, full_size)) == NULL) { + printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); + return -1; + } + } + inq = scsi_datain_unmarshall(task); + if (inq == NULL) { + printf("failed to unmarshall inquiry datain blob\n"); + scsi_free_scsi_task(task); + return -1; + } + removable = inq->rmb; + device_type = inq->device_type; + sccs = inq->sccs; + encserv = inq->encserv; + scsi_free_scsi_task(task); + + + iscsi_logout_sync(iscsi); iscsi_destroy_context(iscsi); diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index 74a7b0c..5dd97db 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -35,6 +35,10 @@ extern int lbppb; extern int lbpme; extern int data_loss; extern int show_info; +extern int removable; +extern enum scsi_inquiry_peripheral_device_type device_type; +extern int sccs; +extern int encserv; struct iscsi_context *iscsi_context_login(const char *initiatorname, const char *url, int *lun); @@ -274,5 +278,6 @@ int verify16(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t int verify16_nomedium(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize); int verify16_miscompare(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize); int verify16_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize); +int inquiry(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize); #endif /* _ISCSI_TEST_H_ */