From patchwork Thu Nov 29 01:01:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 10703741 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65E4F15A8 for ; Thu, 29 Nov 2018 01:02:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CD542E18F for ; Thu, 29 Nov 2018 01:02:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 500752E1A3; Thu, 29 Nov 2018 01:02:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1A402E185 for ; Thu, 29 Nov 2018 01:02:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726771AbeK2MFi (ORCPT ); Thu, 29 Nov 2018 07:05:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:39804 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726565AbeK2MFi (ORCPT ); Thu, 29 Nov 2018 07:05:38 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DEDF3AE0C; Thu, 29 Nov 2018 01:02:04 +0000 (UTC) From: David Disseldorp To: target-devel@vger.kernel.org Cc: hare@suse.com, lduncan@suse.com, cvubrugier@fastmail.fm, Mike Christie , martin.petersen@oracle.com, linux-scsi@vger.kernel.org, David Disseldorp Subject: [PATCH v4 1/7] target: use consistent left-aligned ASCII INQUIRY data Date: Thu, 29 Nov 2018 02:01:51 +0100 Message-Id: <20181129010157.12687-2-ddiss@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181129010157.12687-1-ddiss@suse.de> References: <20181129010157.12687-1-ddiss@suse.de> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP spc5r17.pdf specifies: 4.3.1 ASCII data field requirements ASCII data fields shall contain only ASCII printable characters (i.e., code values 20h to 7Eh) and may be terminated with one or more ASCII null (00h) characters. ASCII data fields described as being left-aligned shall have any unused bytes at the end of the field (i.e., highest offset) and the unused bytes shall be filled with ASCII space characters (20h). LIO currently space-pads the T10 VENDOR IDENTIFICATION and PRODUCT IDENTIFICATION fields in the standard INQUIRY data. However, the PRODUCT REVISION LEVEL field in the standard INQUIRY data as well as the T10 VENDOR IDENTIFICATION field in the INQUIRY Device Identification VPD Page are zero-terminated/zero-padded. Fix this inconsistency by using space-padding for all of the above fields. Signed-off-by: David Disseldorp Reviewed-by: Christoph Hellwig Reviewed-by: Bryant G. Ly bly@catalogicsoftware.com Reviewed-by: Lee Duncan --- drivers/target/target_core_spc.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index f459118bc11b..c37dd36ec77d 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -108,12 +108,17 @@ spc_emulate_inquiry_std(struct se_cmd *cmd, unsigned char *buf) buf[7] = 0x2; /* CmdQue=1 */ - memcpy(&buf[8], "LIO-ORG ", 8); - memset(&buf[16], 0x20, 16); + /* + * ASCII data fields described as being left-aligned shall have any + * unused bytes at the end of the field (i.e., highest offset) and the + * unused bytes shall be filled with ASCII space characters (20h). + */ + memset(&buf[8], 0x20, 8 + 16 + 4); + memcpy(&buf[8], "LIO-ORG", sizeof("LIO-ORG") - 1); memcpy(&buf[16], dev->t10_wwn.model, - min_t(size_t, strlen(dev->t10_wwn.model), 16)); + strnlen(dev->t10_wwn.model, 16)); memcpy(&buf[32], dev->t10_wwn.revision, - min_t(size_t, strlen(dev->t10_wwn.revision), 4)); + strnlen(dev->t10_wwn.revision, 4)); buf[4] = 31; /* Set additional length to 31 */ return 0; @@ -251,7 +256,9 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf) buf[off] = 0x2; /* ASCII */ buf[off+1] = 0x1; /* T10 Vendor ID */ buf[off+2] = 0x0; - memcpy(&buf[off+4], "LIO-ORG", 8); + /* left align Vendor ID and pad with spaces */ + memset(&buf[off+4], 0x20, 8); + memcpy(&buf[off+4], "LIO-ORG", sizeof("LIO-ORG") - 1); /* Extra Byte for NULL Terminator */ id_len++; /* Identifier Length */ From patchwork Thu Nov 29 01:01:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 10703745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C23C2109C for ; Thu, 29 Nov 2018 01:02:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B75642E196 for ; Thu, 29 Nov 2018 01:02:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB44C2E194; Thu, 29 Nov 2018 01:02:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E62B2E1A1 for ; Thu, 29 Nov 2018 01:02:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726812AbeK2MFj (ORCPT ); Thu, 29 Nov 2018 07:05:39 -0500 Received: from mx2.suse.de ([195.135.220.15]:39820 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726617AbeK2MFi (ORCPT ); Thu, 29 Nov 2018 07:05:38 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 525B8AEA3; Thu, 29 Nov 2018 01:02:05 +0000 (UTC) From: David Disseldorp To: target-devel@vger.kernel.org Cc: hare@suse.com, lduncan@suse.com, cvubrugier@fastmail.fm, Mike Christie , martin.petersen@oracle.com, linux-scsi@vger.kernel.org, David Disseldorp Subject: [PATCH v4 2/7] target: consistently null-terminate t10_wwn.vendor Date: Thu, 29 Nov 2018 02:01:52 +0100 Message-Id: <20181129010157.12687-3-ddiss@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181129010157.12687-1-ddiss@suse.de> References: <20181129010157.12687-1-ddiss@suse.de> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In preparation for supporting user provided vendor strings, add an extra byte to t10_wwn.vendor which will ensure null string termination when an eight byte vendor string is provided by the user. Signed-off-by: David Disseldorp Reviewed-by: Bryant G. Ly bly@catalogicsoftware.com Reviewed-by: Lee Duncan --- drivers/target/target_core_device.c | 6 ++++-- drivers/target/target_core_pscsi.c | 6 ++++-- drivers/target/target_core_stat.c | 4 ++-- include/target/target_core_base.h | 8 +++++++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 47b5ef153135..fe4c4db51137 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -725,7 +725,7 @@ static void scsi_dump_inquiry(struct se_device *dev) /* * Print Linux/SCSI style INQUIRY formatting to the kernel ring buffer */ - for (i = 0; i < 8; i++) + for (i = 0; i < INQUIRY_VENDOR_LEN; i++) if (wwn->vendor[i] >= 0x20) buf[i] = wwn->vendor[i]; else @@ -1008,8 +1008,10 @@ int target_configure_device(struct se_device *dev) * anything virtual (IBLOCK, FILEIO, RAMDISK), but not for TCM/pSCSI * passthrough because this is being provided by the backend LLD. */ + BUILD_BUG_ON(sizeof(dev->t10_wwn.vendor) != INQUIRY_VENDOR_LEN + 1); if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)) { - strncpy(&dev->t10_wwn.vendor[0], "LIO-ORG", 8); + strncpy(&dev->t10_wwn.vendor[0], "LIO-ORG", INQUIRY_VENDOR_LEN); + dev->t10_wwn.vendor[INQUIRY_VENDOR_LEN] = '\0'; strncpy(&dev->t10_wwn.model[0], dev->transport->inquiry_prod, 16); strncpy(&dev->t10_wwn.revision[0], diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index 47d76c862014..ee65b5bb674c 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -190,7 +190,9 @@ pscsi_set_inquiry_info(struct scsi_device *sdev, struct t10_wwn *wwn) /* * Use sdev->inquiry from drivers/scsi/scsi_scan.c:scsi_alloc_sdev() */ - memcpy(&wwn->vendor[0], &buf[8], sizeof(wwn->vendor)); + BUILD_BUG_ON(sizeof(wwn->vendor) != INQUIRY_VENDOR_LEN + 1); + memcpy(&wwn->vendor[0], &buf[8], INQUIRY_VENDOR_LEN); + wwn->vendor[INQUIRY_VENDOR_LEN] = '\0'; memcpy(&wwn->model[0], &buf[16], sizeof(wwn->model)); memcpy(&wwn->revision[0], &buf[32], sizeof(wwn->revision)); } @@ -826,7 +828,7 @@ static ssize_t pscsi_show_configfs_dev_params(struct se_device *dev, char *b) if (sd) { bl += sprintf(b + bl, " "); bl += sprintf(b + bl, "Vendor: "); - for (i = 0; i < 8; i++) { + for (i = 0; i < INQUIRY_VENDOR_LEN; i++) { if (ISPRINT(sd->vendor[i])) /* printable character? */ bl += sprintf(b + bl, "%c", sd->vendor[i]); else diff --git a/drivers/target/target_core_stat.c b/drivers/target/target_core_stat.c index f0db91ebd735..4210cf625d84 100644 --- a/drivers/target/target_core_stat.c +++ b/drivers/target/target_core_stat.c @@ -247,10 +247,10 @@ static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page) { struct se_device *dev = to_stat_lu_dev(item); int i; - char str[sizeof(dev->t10_wwn.vendor)+1]; + char str[INQUIRY_VENDOR_LEN+1]; /* scsiLuVendorId */ - for (i = 0; i < sizeof(dev->t10_wwn.vendor); i++) + for (i = 0; i < INQUIRY_VENDOR_LEN; i++) str[i] = ISPRINT(dev->t10_wwn.vendor[i]) ? dev->t10_wwn.vendor[i] : ' '; str[i] = '\0'; diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index e3bdb0550a59..cb1f3f574e2a 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -46,6 +46,8 @@ /* Used by transport_get_inquiry_vpd_device_ident() */ #define INQUIRY_VPD_DEVICE_IDENTIFIER_LEN 254 +#define INQUIRY_VENDOR_LEN 8 + /* Attempts before moving from SHORT to LONG */ #define PYX_TRANSPORT_WINDOW_CLOSED_THRESHOLD 3 #define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_SHORT 3 /* In milliseconds */ @@ -314,7 +316,11 @@ struct t10_vpd { }; struct t10_wwn { - char vendor[8]; + /* + * SCSI left aligned strings may not be null terminated. +1 to ensure a + * null terminator is always present. + */ + char vendor[INQUIRY_VENDOR_LEN + 1]; char model[16]; char revision[4]; char unit_serial[INQUIRY_VPD_SERIAL_LEN]; From patchwork Thu Nov 29 01:01:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 10703759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61AE0109C for ; Thu, 29 Nov 2018 01:02:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 531D32E1AB for ; Thu, 29 Nov 2018 01:02:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46C122E1BB; Thu, 29 Nov 2018 01:02:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9838F2E1AA for ; Thu, 29 Nov 2018 01:02:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726870AbeK2MFk (ORCPT ); Thu, 29 Nov 2018 07:05:40 -0500 Received: from mx2.suse.de ([195.135.220.15]:39832 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726655AbeK2MFk (ORCPT ); Thu, 29 Nov 2018 07:05:40 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C68DFAD6F; Thu, 29 Nov 2018 01:02:05 +0000 (UTC) From: David Disseldorp To: target-devel@vger.kernel.org Cc: hare@suse.com, lduncan@suse.com, cvubrugier@fastmail.fm, Mike Christie , martin.petersen@oracle.com, linux-scsi@vger.kernel.org, David Disseldorp Subject: [PATCH v4 3/7] target: consistently null-terminate t10_wwn.model Date: Thu, 29 Nov 2018 02:01:53 +0100 Message-Id: <20181129010157.12687-4-ddiss@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181129010157.12687-1-ddiss@suse.de> References: <20181129010157.12687-1-ddiss@suse.de> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The pscsi_set_inquiry_info() and emulate_model_alias_store() codepaths don't currently explicitly null-terminate t10_wwn.model. Add an extra byte to the t10_wwn.model buffer and perform null string termination in all cases. dev_set_t10_wwn_model_alias() continues to truncate at the same length to avoid changing the model string for existing deployments. Signed-off-by: David Disseldorp Reviewed-by: Bryant G. Ly bly@catalogicsoftware.com Reviewed-by: Lee Duncan --- drivers/target/target_core_configfs.c | 8 +++++--- drivers/target/target_core_device.c | 8 +++++--- drivers/target/target_core_pscsi.c | 6 ++++-- drivers/target/target_core_spc.c | 2 +- drivers/target/target_core_stat.c | 4 ++-- include/target/target_core_base.h | 3 ++- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index f6b1549f4142..9f49b1afd685 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -613,12 +613,12 @@ static void dev_set_t10_wwn_model_alias(struct se_device *dev) const char *configname; configname = config_item_name(&dev->dev_group.cg_item); - if (strlen(configname) >= 16) { + if (strlen(configname) >= INQUIRY_MODEL_LEN) { pr_warn("dev[%p]: Backstore name '%s' is too long for " "INQUIRY_MODEL, truncating to 16 bytes\n", dev, configname); } - snprintf(&dev->t10_wwn.model[0], 16, "%s", configname); + snprintf(&dev->t10_wwn.model[0], INQUIRY_MODEL_LEN, "%s", configname); } static ssize_t emulate_model_alias_store(struct config_item *item, @@ -640,11 +640,13 @@ static ssize_t emulate_model_alias_store(struct config_item *item, if (ret < 0) return ret; + BUILD_BUG_ON(sizeof(dev->t10_wwn.model) != INQUIRY_MODEL_LEN + 1); if (flag) { dev_set_t10_wwn_model_alias(dev); } else { strncpy(&dev->t10_wwn.model[0], - dev->transport->inquiry_prod, 16); + dev->transport->inquiry_prod, INQUIRY_MODEL_LEN); + dev->t10_wwn.model[INQUIRY_MODEL_LEN] = '\0'; } da->emulate_model_alias = flag; return count; diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index fe4c4db51137..0d7382efb2d4 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -720,7 +720,7 @@ void core_dev_free_initiator_node_lun_acl( static void scsi_dump_inquiry(struct se_device *dev) { struct t10_wwn *wwn = &dev->t10_wwn; - char buf[17]; + char buf[INQUIRY_MODEL_LEN + 1]; int i, device_type; /* * Print Linux/SCSI style INQUIRY formatting to the kernel ring buffer @@ -733,7 +733,7 @@ static void scsi_dump_inquiry(struct se_device *dev) buf[i] = '\0'; pr_debug(" Vendor: %s\n", buf); - for (i = 0; i < 16; i++) + for (i = 0; i < INQUIRY_MODEL_LEN; i++) if (wwn->model[i] >= 0x20) buf[i] = wwn->model[i]; else @@ -1009,11 +1009,13 @@ int target_configure_device(struct se_device *dev) * passthrough because this is being provided by the backend LLD. */ BUILD_BUG_ON(sizeof(dev->t10_wwn.vendor) != INQUIRY_VENDOR_LEN + 1); + BUILD_BUG_ON(sizeof(dev->t10_wwn.model) != INQUIRY_MODEL_LEN + 1); if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)) { strncpy(&dev->t10_wwn.vendor[0], "LIO-ORG", INQUIRY_VENDOR_LEN); dev->t10_wwn.vendor[INQUIRY_VENDOR_LEN] = '\0'; strncpy(&dev->t10_wwn.model[0], - dev->transport->inquiry_prod, 16); + dev->transport->inquiry_prod, INQUIRY_MODEL_LEN); + dev->t10_wwn.model[INQUIRY_MODEL_LEN] = '\0'; strncpy(&dev->t10_wwn.revision[0], dev->transport->inquiry_rev, 4); } diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index ee65b5bb674c..1633babc2d4e 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -193,7 +193,9 @@ pscsi_set_inquiry_info(struct scsi_device *sdev, struct t10_wwn *wwn) BUILD_BUG_ON(sizeof(wwn->vendor) != INQUIRY_VENDOR_LEN + 1); memcpy(&wwn->vendor[0], &buf[8], INQUIRY_VENDOR_LEN); wwn->vendor[INQUIRY_VENDOR_LEN] = '\0'; - memcpy(&wwn->model[0], &buf[16], sizeof(wwn->model)); + BUILD_BUG_ON(sizeof(wwn->model) != INQUIRY_MODEL_LEN + 1); + memcpy(&wwn->model[0], &buf[16], INQUIRY_MODEL_LEN); + wwn->model[INQUIRY_MODEL_LEN] = '\0'; memcpy(&wwn->revision[0], &buf[32], sizeof(wwn->revision)); } @@ -835,7 +837,7 @@ static ssize_t pscsi_show_configfs_dev_params(struct se_device *dev, char *b) bl += sprintf(b + bl, " "); } bl += sprintf(b + bl, " Model: "); - for (i = 0; i < 16; i++) { + for (i = 0; i < INQUIRY_MODEL_LEN; i++) { if (ISPRINT(sd->model[i])) /* printable character ? */ bl += sprintf(b + bl, "%c", sd->model[i]); else diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index c37dd36ec77d..78eddee4b6e6 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -116,7 +116,7 @@ spc_emulate_inquiry_std(struct se_cmd *cmd, unsigned char *buf) memset(&buf[8], 0x20, 8 + 16 + 4); memcpy(&buf[8], "LIO-ORG", sizeof("LIO-ORG") - 1); memcpy(&buf[16], dev->t10_wwn.model, - strnlen(dev->t10_wwn.model, 16)); + strnlen(dev->t10_wwn.model, INQUIRY_MODEL_LEN)); memcpy(&buf[32], dev->t10_wwn.revision, strnlen(dev->t10_wwn.revision, 4)); buf[4] = 31; /* Set additional length to 31 */ diff --git a/drivers/target/target_core_stat.c b/drivers/target/target_core_stat.c index 4210cf625d84..9123c5137da5 100644 --- a/drivers/target/target_core_stat.c +++ b/drivers/target/target_core_stat.c @@ -261,10 +261,10 @@ static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page) { struct se_device *dev = to_stat_lu_dev(item); int i; - char str[sizeof(dev->t10_wwn.model)+1]; + char str[INQUIRY_MODEL_LEN+1]; /* scsiLuProductId */ - for (i = 0; i < sizeof(dev->t10_wwn.model); i++) + for (i = 0; i < INQUIRY_MODEL_LEN; i++) str[i] = ISPRINT(dev->t10_wwn.model[i]) ? dev->t10_wwn.model[i] : ' '; str[i] = '\0'; diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index cb1f3f574e2a..cfc279686cf4 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -47,6 +47,7 @@ #define INQUIRY_VPD_DEVICE_IDENTIFIER_LEN 254 #define INQUIRY_VENDOR_LEN 8 +#define INQUIRY_MODEL_LEN 16 /* Attempts before moving from SHORT to LONG */ #define PYX_TRANSPORT_WINDOW_CLOSED_THRESHOLD 3 @@ -321,7 +322,7 @@ struct t10_wwn { * null terminator is always present. */ char vendor[INQUIRY_VENDOR_LEN + 1]; - char model[16]; + char model[INQUIRY_MODEL_LEN + 1]; char revision[4]; char unit_serial[INQUIRY_VPD_SERIAL_LEN]; spinlock_t t10_vpd_lock; From patchwork Thu Nov 29 01:01:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 10703767 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D96B109C for ; Thu, 29 Nov 2018 01:02:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 643902E185 for ; Thu, 29 Nov 2018 01:02:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 589722E1B1; Thu, 29 Nov 2018 01:02:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCE9A2E185 for ; Thu, 29 Nov 2018 01:02:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726818AbeK2MFj (ORCPT ); Thu, 29 Nov 2018 07:05:39 -0500 Received: from mx2.suse.de ([195.135.220.15]:39844 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726297AbeK2MFj (ORCPT ); Thu, 29 Nov 2018 07:05:39 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 38E33AF5D; Thu, 29 Nov 2018 01:02:06 +0000 (UTC) From: David Disseldorp To: target-devel@vger.kernel.org Cc: hare@suse.com, lduncan@suse.com, cvubrugier@fastmail.fm, Mike Christie , martin.petersen@oracle.com, linux-scsi@vger.kernel.org, David Disseldorp Subject: [PATCH v4 4/7] target: consistently null-terminate t10_wwn.revision Date: Thu, 29 Nov 2018 02:01:54 +0100 Message-Id: <20181129010157.12687-5-ddiss@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181129010157.12687-1-ddiss@suse.de> References: <20181129010157.12687-1-ddiss@suse.de> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The pscsi_set_inquiry_info() codepath doesn't currently explicitly null-terminate t10_wwn.revision. Add an extra byte to the t10_wwn.model buffer and perform null string termination in all cases. Signed-off-by: David Disseldorp Reviewed-by: Bryant G. Ly bly@catalogicsoftware.com Reviewed-by: Lee Duncan --- drivers/target/target_core_device.c | 6 ++++-- drivers/target/target_core_pscsi.c | 4 +++- drivers/target/target_core_spc.c | 5 +++-- drivers/target/target_core_stat.c | 4 ++-- include/target/target_core_base.h | 3 ++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 0d7382efb2d4..b3d0bd1ab09f 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -741,7 +741,7 @@ static void scsi_dump_inquiry(struct se_device *dev) buf[i] = '\0'; pr_debug(" Model: %s\n", buf); - for (i = 0; i < 4; i++) + for (i = 0; i < INQUIRY_REVISION_LEN; i++) if (wwn->revision[i] >= 0x20) buf[i] = wwn->revision[i]; else @@ -1010,6 +1010,7 @@ int target_configure_device(struct se_device *dev) */ BUILD_BUG_ON(sizeof(dev->t10_wwn.vendor) != INQUIRY_VENDOR_LEN + 1); BUILD_BUG_ON(sizeof(dev->t10_wwn.model) != INQUIRY_MODEL_LEN + 1); + BUILD_BUG_ON(sizeof(dev->t10_wwn.revision) != INQUIRY_REVISION_LEN + 1); if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)) { strncpy(&dev->t10_wwn.vendor[0], "LIO-ORG", INQUIRY_VENDOR_LEN); dev->t10_wwn.vendor[INQUIRY_VENDOR_LEN] = '\0'; @@ -1017,7 +1018,8 @@ int target_configure_device(struct se_device *dev) dev->transport->inquiry_prod, INQUIRY_MODEL_LEN); dev->t10_wwn.model[INQUIRY_MODEL_LEN] = '\0'; strncpy(&dev->t10_wwn.revision[0], - dev->transport->inquiry_rev, 4); + dev->transport->inquiry_rev, INQUIRY_REVISION_LEN); + dev->t10_wwn.revision[INQUIRY_REVISION_LEN] = '\0'; } scsi_dump_inquiry(dev); diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index 1633babc2d4e..5493f620b7f4 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -196,7 +196,9 @@ pscsi_set_inquiry_info(struct scsi_device *sdev, struct t10_wwn *wwn) BUILD_BUG_ON(sizeof(wwn->model) != INQUIRY_MODEL_LEN + 1); memcpy(&wwn->model[0], &buf[16], INQUIRY_MODEL_LEN); wwn->model[INQUIRY_MODEL_LEN] = '\0'; - memcpy(&wwn->revision[0], &buf[32], sizeof(wwn->revision)); + BUILD_BUG_ON(sizeof(wwn->revision) != INQUIRY_REVISION_LEN + 1); + memcpy(&wwn->revision[0], &buf[32], INQUIRY_REVISION_LEN); + wwn->revision[INQUIRY_REVISION_LEN] = '\0'; } static int diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index 78eddee4b6e6..8ffe712cb44d 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -113,12 +113,13 @@ spc_emulate_inquiry_std(struct se_cmd *cmd, unsigned char *buf) * unused bytes at the end of the field (i.e., highest offset) and the * unused bytes shall be filled with ASCII space characters (20h). */ - memset(&buf[8], 0x20, 8 + 16 + 4); + memset(&buf[8], 0x20, + INQUIRY_VENDOR_LEN + INQUIRY_MODEL_LEN + INQUIRY_REVISION_LEN); memcpy(&buf[8], "LIO-ORG", sizeof("LIO-ORG") - 1); memcpy(&buf[16], dev->t10_wwn.model, strnlen(dev->t10_wwn.model, INQUIRY_MODEL_LEN)); memcpy(&buf[32], dev->t10_wwn.revision, - strnlen(dev->t10_wwn.revision, 4)); + strnlen(dev->t10_wwn.revision, INQUIRY_REVISION_LEN)); buf[4] = 31; /* Set additional length to 31 */ return 0; diff --git a/drivers/target/target_core_stat.c b/drivers/target/target_core_stat.c index 9123c5137da5..e437ba494865 100644 --- a/drivers/target/target_core_stat.c +++ b/drivers/target/target_core_stat.c @@ -275,10 +275,10 @@ static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page) { struct se_device *dev = to_stat_lu_dev(item); int i; - char str[sizeof(dev->t10_wwn.revision)+1]; + char str[INQUIRY_REVISION_LEN+1]; /* scsiLuRevisionId */ - for (i = 0; i < sizeof(dev->t10_wwn.revision); i++) + for (i = 0; i < INQUIRY_REVISION_LEN; i++) str[i] = ISPRINT(dev->t10_wwn.revision[i]) ? dev->t10_wwn.revision[i] : ' '; str[i] = '\0'; diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index cfc279686cf4..497853a09fee 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -48,6 +48,7 @@ #define INQUIRY_VENDOR_LEN 8 #define INQUIRY_MODEL_LEN 16 +#define INQUIRY_REVISION_LEN 4 /* Attempts before moving from SHORT to LONG */ #define PYX_TRANSPORT_WINDOW_CLOSED_THRESHOLD 3 @@ -323,7 +324,7 @@ struct t10_wwn { */ char vendor[INQUIRY_VENDOR_LEN + 1]; char model[INQUIRY_MODEL_LEN + 1]; - char revision[4]; + char revision[INQUIRY_REVISION_LEN + 1]; char unit_serial[INQUIRY_VPD_SERIAL_LEN]; spinlock_t t10_vpd_lock; struct se_device *t10_dev; From patchwork Thu Nov 29 01:01:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 10703753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F5E815A8 for ; Thu, 29 Nov 2018 01:02:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 843FD2E1A0 for ; Thu, 29 Nov 2018 01:02:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7861D2E1AE; Thu, 29 Nov 2018 01:02:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20C882E1A0 for ; Thu, 29 Nov 2018 01:02:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726895AbeK2MFl (ORCPT ); Thu, 29 Nov 2018 07:05:41 -0500 Received: from mx2.suse.de ([195.135.220.15]:39850 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726770AbeK2MFk (ORCPT ); Thu, 29 Nov 2018 07:05:40 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9AD22AFE2; Thu, 29 Nov 2018 01:02:06 +0000 (UTC) From: David Disseldorp To: target-devel@vger.kernel.org Cc: hare@suse.com, lduncan@suse.com, cvubrugier@fastmail.fm, Mike Christie , martin.petersen@oracle.com, linux-scsi@vger.kernel.org, David Disseldorp Subject: [PATCH v4 5/7] target: add device vendor_id configfs attribute Date: Thu, 29 Nov 2018 02:01:55 +0100 Message-Id: <20181129010157.12687-6-ddiss@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181129010157.12687-1-ddiss@suse.de> References: <20181129010157.12687-1-ddiss@suse.de> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The vendor_id attribute will allow for the modification of the T10 Vendor Identification string returned in inquiry responses. Its value can be viewed and modified via the ConfigFS path at: target/core/$backstore/$name/wwn/vendor_id "LIO-ORG" remains the default value, which is set when the backstore device is enabled. Signed-off-by: David Disseldorp Reviewed-by: Bryant G. Ly bly@catalogicsoftware.com Reviewed-by: Lee Duncan --- drivers/target/target_core_configfs.c | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 9f49b1afd685..fc60c4db718d 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -1213,6 +1213,52 @@ static struct t10_wwn *to_t10_wwn(struct config_item *item) } /* + * STANDARD and VPD page 0x80 T10 Vendor Identification + */ +static ssize_t target_wwn_vendor_id_show(struct config_item *item, + char *page) +{ + return sprintf(page, "%s\n", &to_t10_wwn(item)->vendor[0]); +} + +static ssize_t target_wwn_vendor_id_store(struct config_item *item, + const char *page, size_t count) +{ + struct t10_wwn *t10_wwn = to_t10_wwn(item); + struct se_device *dev = t10_wwn->t10_dev; + unsigned char buf[INQUIRY_VENDOR_LEN + 1]; + + if (strlen(page) > INQUIRY_VENDOR_LEN) { + pr_err("Emulated T10 Vendor Identification exceeds" + " INQUIRY_VENDOR_LEN: " __stringify(INQUIRY_VENDOR_LEN) + "\n"); + return -EOVERFLOW; + } + strlcpy(buf, page, sizeof(buf)); + /* + * Check to see if any active exports exist. If they do exist, fail + * here as changing this information on the fly (underneath the + * initiator side OS dependent multipath code) could cause negative + * effects. + */ + if (dev->export_count) { + pr_err("Unable to set T10 Vendor Identification while" + " active %d exports exist\n", dev->export_count); + return -EINVAL; + } + + /* Assume ASCII encoding. Strip any newline added from userspace. */ + BUILD_BUG_ON(sizeof(dev->t10_wwn.vendor) != INQUIRY_VENDOR_LEN + 1); + strlcpy(dev->t10_wwn.vendor, strstrip(buf), + sizeof(dev->t10_wwn.vendor)); + + pr_debug("Target_Core_ConfigFS: Set emulated T10 Vendor Identification:" + " %s\n", dev->t10_wwn.vendor); + + return count; +} + +/* * VPD page 0x80 Unit serial */ static ssize_t target_wwn_vpd_unit_serial_show(struct config_item *item, @@ -1358,6 +1404,7 @@ DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port, 0x10); /* VPD page 0x83 Association: SCSI Target Device */ DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20); +CONFIGFS_ATTR(target_wwn_, vendor_id); CONFIGFS_ATTR(target_wwn_, vpd_unit_serial); CONFIGFS_ATTR_RO(target_wwn_, vpd_protocol_identifier); CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_logical_unit); @@ -1365,6 +1412,7 @@ CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_target_port); CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_scsi_target_device); static struct configfs_attribute *target_core_dev_wwn_attrs[] = { + &target_wwn_attr_vendor_id, &target_wwn_attr_vpd_unit_serial, &target_wwn_attr_vpd_protocol_identifier, &target_wwn_attr_vpd_assoc_logical_unit, From patchwork Thu Nov 29 01:01:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 10703761 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 703B8679F for ; Thu, 29 Nov 2018 01:02:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 663692E173 for ; Thu, 29 Nov 2018 01:02:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 571542E1C2; Thu, 29 Nov 2018 01:02:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDC1A2E173 for ; Thu, 29 Nov 2018 01:02:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726878AbeK2MFk (ORCPT ); Thu, 29 Nov 2018 07:05:40 -0500 Received: from mx2.suse.de ([195.135.220.15]:39866 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726795AbeK2MFk (ORCPT ); Thu, 29 Nov 2018 07:05:40 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 11E34AFE6; Thu, 29 Nov 2018 01:02:07 +0000 (UTC) From: David Disseldorp To: target-devel@vger.kernel.org Cc: hare@suse.com, lduncan@suse.com, cvubrugier@fastmail.fm, Mike Christie , martin.petersen@oracle.com, linux-scsi@vger.kernel.org, David Disseldorp Subject: [PATCH v4 6/7] target: remove hardcoded T10 Vendor ID in INQUIRY response Date: Thu, 29 Nov 2018 02:01:56 +0100 Message-Id: <20181129010157.12687-7-ddiss@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181129010157.12687-1-ddiss@suse.de> References: <20181129010157.12687-1-ddiss@suse.de> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the value stored in t10_wwn.vendor, which defaults to "LIO-ORG", but can be reconfigured via the vendor_id ConfigFS attribute. Signed-off-by: David Disseldorp Reviewed-by: Bryant G. Ly bly@catalogicsoftware.com Reviewed-by: Lee Duncan --- drivers/target/target_core_spc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index 8ffe712cb44d..4503f3336bc2 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -115,7 +115,8 @@ spc_emulate_inquiry_std(struct se_cmd *cmd, unsigned char *buf) */ memset(&buf[8], 0x20, INQUIRY_VENDOR_LEN + INQUIRY_MODEL_LEN + INQUIRY_REVISION_LEN); - memcpy(&buf[8], "LIO-ORG", sizeof("LIO-ORG") - 1); + memcpy(&buf[8], dev->t10_wwn.vendor, + strnlen(dev->t10_wwn.vendor, INQUIRY_VENDOR_LEN)); memcpy(&buf[16], dev->t10_wwn.model, strnlen(dev->t10_wwn.model, INQUIRY_MODEL_LEN)); memcpy(&buf[32], dev->t10_wwn.revision, @@ -258,8 +259,9 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf) buf[off+1] = 0x1; /* T10 Vendor ID */ buf[off+2] = 0x0; /* left align Vendor ID and pad with spaces */ - memset(&buf[off+4], 0x20, 8); - memcpy(&buf[off+4], "LIO-ORG", sizeof("LIO-ORG") - 1); + memset(&buf[off+4], 0x20, INQUIRY_VENDOR_LEN); + memcpy(&buf[off+4], dev->t10_wwn.vendor, + strnlen(dev->t10_wwn.vendor, INQUIRY_VENDOR_LEN)); /* Extra Byte for NULL Terminator */ id_len++; /* Identifier Length */ From patchwork Thu Nov 29 01:01:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 10703755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E42D817F0 for ; Thu, 29 Nov 2018 01:02:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D92B42E173 for ; Thu, 29 Nov 2018 01:02:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC6FF2E1B1; Thu, 29 Nov 2018 01:02:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 643322E196 for ; Thu, 29 Nov 2018 01:02:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726905AbeK2MFl (ORCPT ); Thu, 29 Nov 2018 07:05:41 -0500 Received: from mx2.suse.de ([195.135.220.15]:39876 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726617AbeK2MFl (ORCPT ); Thu, 29 Nov 2018 07:05:41 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 849D6AFE7; Thu, 29 Nov 2018 01:02:07 +0000 (UTC) From: David Disseldorp To: target-devel@vger.kernel.org Cc: hare@suse.com, lduncan@suse.com, cvubrugier@fastmail.fm, Mike Christie , martin.petersen@oracle.com, linux-scsi@vger.kernel.org, Bart Van Assche , David Disseldorp Subject: [PATCH v4 7/7] target: use printf width specifier for t10_wwn field dumps Date: Thu, 29 Nov 2018 02:01:57 +0100 Message-Id: <20181129010157.12687-8-ddiss@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181129010157.12687-1-ddiss@suse.de> References: <20181129010157.12687-1-ddiss@suse.de> Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Bart Van Assche The existing for loops step over null-terminators for right-padding. Padding can be achieved in a much simpler way using printf width specifiers. Signed-off-by: David Disseldorp Reviewed-by: Lee Duncan --- drivers/target/target_core_device.c | 35 ++++++++--------------------------- drivers/target/target_core_stat.c | 32 +++++++------------------------- 2 files changed, 15 insertions(+), 52 deletions(-) diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index b3d0bd1ab09f..7f2d307e411b 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -720,36 +720,17 @@ void core_dev_free_initiator_node_lun_acl( static void scsi_dump_inquiry(struct se_device *dev) { struct t10_wwn *wwn = &dev->t10_wwn; - char buf[INQUIRY_MODEL_LEN + 1]; - int i, device_type; + int device_type = dev->transport->get_device_type(dev); + /* * Print Linux/SCSI style INQUIRY formatting to the kernel ring buffer */ - for (i = 0; i < INQUIRY_VENDOR_LEN; i++) - if (wwn->vendor[i] >= 0x20) - buf[i] = wwn->vendor[i]; - else - buf[i] = ' '; - buf[i] = '\0'; - pr_debug(" Vendor: %s\n", buf); - - for (i = 0; i < INQUIRY_MODEL_LEN; i++) - if (wwn->model[i] >= 0x20) - buf[i] = wwn->model[i]; - else - buf[i] = ' '; - buf[i] = '\0'; - pr_debug(" Model: %s\n", buf); - - for (i = 0; i < INQUIRY_REVISION_LEN; i++) - if (wwn->revision[i] >= 0x20) - buf[i] = wwn->revision[i]; - else - buf[i] = ' '; - buf[i] = '\0'; - pr_debug(" Revision: %s\n", buf); - - device_type = dev->transport->get_device_type(dev); + pr_debug(" Vendor: %-" __stringify(INQUIRY_VENDOR_LEN) "s\n", + wwn->vendor); + pr_debug(" Model: %-" __stringify(INQUIRY_MODEL_LEN) "s\n", + wwn->model); + pr_debug(" Revision: %-" __stringify(INQUIRY_REVISION_LEN) "s\n", + wwn->revision); pr_debug(" Type: %s ", scsi_device_type(device_type)); } diff --git a/drivers/target/target_core_stat.c b/drivers/target/target_core_stat.c index e437ba494865..87fd2b11fe3b 100644 --- a/drivers/target/target_core_stat.c +++ b/drivers/target/target_core_stat.c @@ -246,43 +246,25 @@ static ssize_t target_stat_lu_lu_name_show(struct config_item *item, char *page) static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page) { struct se_device *dev = to_stat_lu_dev(item); - int i; - char str[INQUIRY_VENDOR_LEN+1]; - /* scsiLuVendorId */ - for (i = 0; i < INQUIRY_VENDOR_LEN; i++) - str[i] = ISPRINT(dev->t10_wwn.vendor[i]) ? - dev->t10_wwn.vendor[i] : ' '; - str[i] = '\0'; - return snprintf(page, PAGE_SIZE, "%s\n", str); + return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_VENDOR_LEN) + "s\n", dev->t10_wwn.vendor); } static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page) { struct se_device *dev = to_stat_lu_dev(item); - int i; - char str[INQUIRY_MODEL_LEN+1]; - /* scsiLuProductId */ - for (i = 0; i < INQUIRY_MODEL_LEN; i++) - str[i] = ISPRINT(dev->t10_wwn.model[i]) ? - dev->t10_wwn.model[i] : ' '; - str[i] = '\0'; - return snprintf(page, PAGE_SIZE, "%s\n", str); + return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_MODEL_LEN) + "s\n", dev->t10_wwn.model); } static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page) { struct se_device *dev = to_stat_lu_dev(item); - int i; - char str[INQUIRY_REVISION_LEN+1]; - - /* scsiLuRevisionId */ - for (i = 0; i < INQUIRY_REVISION_LEN; i++) - str[i] = ISPRINT(dev->t10_wwn.revision[i]) ? - dev->t10_wwn.revision[i] : ' '; - str[i] = '\0'; - return snprintf(page, PAGE_SIZE, "%s\n", str); + + return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_REVISION_LEN) + "s\n", dev->t10_wwn.revision); } static ssize_t target_stat_lu_dev_type_show(struct config_item *item, char *page)