Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755102AbZA3SUK (ORCPT ); Fri, 30 Jan 2009 13:20:10 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753181AbZA3ST4 (ORCPT ); Fri, 30 Jan 2009 13:19:56 -0500 Received: from moutng.kundenserver.de ([212.227.17.8]:52449 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753172AbZA3STz (ORCPT ); Fri, 30 Jan 2009 13:19:55 -0500 Message-ID: <498344D1.9000208@vlnb.net> Date: Fri, 30 Jan 2009 21:20:01 +0300 From: Vladislav Bolkhovitin User-Agent: Thunderbird 2.0.0.17 (X11/20081009) MIME-Version: 1.0 To: linux-scsi@vger.kernel.org CC: linux-kernel@vger.kernel.org, scst-devel@lists.sourceforge.net Subject: [PATCH][SCST]: Make USN autogeneration completed Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V01U2FsdGVkX1/4OX3crpuUHa6TWkVOXZ+MUsRXH3YTPN4LO9P td5EaerV7JI7XYskfFVQpW8Q/aXHWUVN736R1pUWfe6OEoQb0w k83Pfo5LsjXX2Cbk/mSmQ== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4404 Lines: 124 Module scst_vdisk autogenerates EVPD INQUERY pages 0x80 and 0x83 from virtual devices names. For cases if several targets with identical configuration are created, scst_vdisk has module parameter scst_vdisk_ID to make the INQUERY data different for those targets. This patch makes this functionality complete by making more scalable and reducing chances for collisions of the autogenerated data. Signed-off-by: Vladislav Bolkhovitin scst_vdisk.c | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) Index: scst/src/dev_handlers/scst_vdisk.c =================================================================== --- scst/src/dev_handlers/scst_vdisk.c (revision 643) +++ scst/src/dev_handlers/scst_vdisk.c (working copy) @@ -1119,21 +1119,17 @@ out_done: goto out; } -static int vdisk_gen_dev_id_num(struct scst_vdisk_dev *virt_dev) +static uint64_t vdisk_gen_dev_id_num(struct scst_vdisk_dev *virt_dev) { - int dev_id_num, i; + unsigned int dev_id_num, i; - for (dev_id_num = 0, i = 0; i < (int)strlen(virt_dev->name); i++) { + for (dev_id_num = 0, i = 0; i < strlen(virt_dev->name); i++) { unsigned int rv = random_values[(int)(virt_dev->name[i])]; - /* - * Device name maximum length = 16, do some rotating of the - * bits. - */ + /* Do some rotating of the bits */ dev_id_num ^= ((rv << i) | (rv >> (32 - i))); } - dev_id_num += scst_vdisk_ID; - return dev_id_num; + return ((uint64_t)scst_vdisk_ID << 32) | dev_id_num; } static void vdisk_exec_inquiry(struct scst_cmd *cmd) @@ -1183,13 +1179,14 @@ static void vdisk_exec_inquiry(struct sc buf[1] = 0x80; /* removable */ /* Vital Product */ if (cmd->cdb[1] & EVPD) { - int dev_id_num, dev_id_len; - char dev_id_str[6]; + uint64_t dev_id_num; + int dev_id_len; + char dev_id_str[17]; dev_id_num = vdisk_gen_dev_id_num(virt_dev); - dev_id_len = scnprintf(dev_id_str, sizeof(dev_id_str), "%d", + dev_id_len = scnprintf(dev_id_str, sizeof(dev_id_str), "%llx", dev_id_num); - TRACE_DBG("dev_id num %d, str %s, len %d", dev_id_num, + TRACE_DBG("dev_id num %lld, str %s, len %d", dev_id_num, dev_id_str, dev_id_len); if (0 == cmd->cdb[2]) { /* supported vital product data pages */ @@ -1210,21 +1207,19 @@ static void vdisk_exec_inquiry(struct sc int num = 4; buf[1] = 0x83; - /* Two identification descriptors: */ /* T10 vendor identifier field format (faked) */ buf[num + 0] = 0x2; /* ASCII */ - buf[num + 1] = 0x1; - buf[num + 2] = 0x0; + buf[num + 1] = 0x1; /* Vendor ID */ if (virt_dev->blockio) memcpy(&buf[num + 4], SCST_BIO_VENDOR, 8); else memcpy(&buf[num + 4], SCST_FIO_VENDOR, 8); - memset(&buf[num + 12], ' ', 16); - i = min(strlen(virt_dev->name), (size_t)16); - memcpy(&buf[num + 12], virt_dev->name, i); - memcpy(&buf[num + 28], dev_id_str, dev_id_len); - buf[num + 3] = 8 + 16 + dev_id_len; + i = strlen(virt_dev->name) + 1; /* for ' ' */ + memset(&buf[num + 12], ' ', i + dev_id_len); + memcpy(&buf[num + 12], virt_dev->name, i-1); + memcpy(&buf[num + 12 + i], dev_id_str, dev_id_len); + buf[num + 3] = 8 + i + dev_id_len; num += buf[num + 3]; #if 0 /* This isn't required and can be misleading, so let's disable it */ @@ -1287,8 +1282,7 @@ static void vdisk_exec_inquiry(struct sc * aligned. */ memset(&buf[16], ' ', 16); - len = strlen(virt_dev->name); - len = len < 16 ? len : 16; + len = min(strlen(virt_dev->name), (size_t)16); memcpy(&buf[16], virt_dev->name, len); /* @@ -2955,7 +2949,7 @@ static int vdisk_write_proc(char *buffer strcpy(virt_dev->name, name); - scnprintf(virt_dev->usn, sizeof(virt_dev->usn), "%x", + scnprintf(virt_dev->usn, sizeof(virt_dev->usn), "%llx", vdisk_gen_dev_id_num(virt_dev)); TRACE_DBG("usn %s", virt_dev->usn); @@ -3092,7 +3086,7 @@ static int vcdrom_open(char *p, char *na strcpy(virt_dev->name, name); - scnprintf(virt_dev->usn, sizeof(virt_dev->usn), "%x", + scnprintf(virt_dev->usn, sizeof(virt_dev->usn), "%llx", vdisk_gen_dev_id_num(virt_dev)); TRACE_DBG("usn %s", virt_dev->usn); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/