From 72bb4b61718aa3dadd6bae3c66d449a70c3d37ed Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 8 Sep 2016 15:24:38 -0700 Subject: [PATCH] scsi: always zero unused INQUIRY bytes up to 96 if allocated Our SCSI translation layer only fills 4 version descriptors meaning the last 30 bytes of the 96 byte standard inquiry data format are not used. Some compliance tests expect the full 96 bytes to be returned, even if they are unused. So zero the remaining bytes (up to 96) if those bytes were allocated. This fixes a regression introduced by recent commit d3b58c006. Signed-off-by: Jim Harris Change-Id: Id61614b904b5dff39f034b7ba4da624be1b25bae --- lib/scsi/scsi_bdev.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/scsi/scsi_bdev.c b/lib/scsi/scsi_bdev.c index c74062e4c3..cc2718b182 100644 --- a/lib/scsi/scsi_bdev.c +++ b/lib/scsi/scsi_bdev.c @@ -745,6 +745,22 @@ spdk_bdev_scsi_inquiry(struct spdk_bdev *bdev, struct spdk_scsi_task *task, len += 2; } + /* + * We only fill out 4 descriptors, but if the allocation length goes past + * that, zero the remaining bytes. This fixes some SCSI compliance tests + * which expect a full 96 bytes to be returned, including the unpopulated + * version descriptors 5-8 (4 * 2 = 8 bytes) plus the 22 bytes of reserved + * space (bytes 74-95) - for a total of 30 bytes. + */ + if (alloc_len > INQUIRY_OFFSET(reserved) + 8) { + i = alloc_len - (INQUIRY_OFFSET(reserved) + 8); + if (i > 30) { + i = 30; + } + memset(&inqdata->desc[8], 0, i); + len += i; + } + /* ADDITIONAL LENGTH */ inqdata->add_len = len; }