Make USN related stuff completed. Unfortunately, it can break existing cluster setups...
authorvlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Wed, 28 Jan 2009 18:44:59 +0000 (18:44 +0000)
committervlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Wed, 28 Jan 2009 18:44:59 +0000 (18:44 +0000)
git-svn-id: https://scst.svn.sourceforge.net/svnroot/scst/trunk@645 d57e44dd-8a1f-0410-8b47-8ef2f437770f

scst/src/dev_handlers/scst_vdisk.c
usr/fileio/common.c
usr/fileio/common.h
usr/fileio/fileio.c

index 4a72cee..d982144 100644 (file)
@@ -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 scst_cmd *cmd)
                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 scst_cmd *cmd)
                        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 scst_cmd *cmd)
                 * 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, char **start, off_t offset,
 
                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 *name)
 
        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);
 
index 25a7c41..0cffdb5 100644 (file)
@@ -906,20 +906,17 @@ out:
        return (void *)(long)res;
 }
 
-int gen_dev_id_num(const struct vdisk_dev *dev)
+uint64_t gen_dev_id_num(const struct vdisk_dev *dev)
 {
-       int dev_id_num, i;
+       unsigned int dev_id_num, i;
 
        for (dev_id_num = 0, i = 0; i < (int)strlen(dev->name); i++) {
                unsigned int rv = random_values[(int)(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)));
        }
 
-       return dev_id_num;
+       return ((uint64_t)vdisk_ID << 32) | dev_id_num;
 }
 
 static void exec_inquiry(struct vdisk_cmd *vcmd)
@@ -948,15 +945,16 @@ static void exec_inquiry(struct vdisk_cmd *vcmd)
                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  = gen_dev_id_num(dev);
-               dev_id_len = snprintf(dev_id_str, sizeof(dev_id_str), "%d",
+               dev_id_len = snprintf(dev_id_str, sizeof(dev_id_str), "%llx",
                                        dev_id_num);
                if (dev_id_len >= (signed)sizeof(dev_id_str))
                        dev_id_len = sizeof(dev_id_str) - 1;
-               TRACE_DBG("dev_id num %d, str %s, len %d", dev_id_num,
+               TRACE_DBG("dev_id num %llx, str %s, len %d", dev_id_num,
                        dev_id_str, dev_id_len);
                if (0 == cmd->cdb[2]) { /* supported vital product data pages */
                        buf[3] = 3;
@@ -977,14 +975,13 @@ static void exec_inquiry(struct vdisk_cmd *vcmd)
                        /* 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 */
                        memcpy(&buf[num + 4], VENDOR, 8);
-                       memset(&buf[num + 12], ' ', 16);
-                       i = min(strlen(dev->name), (size_t)16);
-                       memcpy(&buf[num + 12], dev->name, i);
-                       memcpy(&buf[num + 28], dev_id_str, dev_id_len);
-                       buf[num + 3] = 8 + 16 + dev_id_len;
+                       i = strlen(dev->name) + 1; /* for ' ' */
+                       memset(&buf[num + 12], ' ', i + dev_id_len);
+                       memcpy(&buf[num + 12], 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 */
@@ -1038,8 +1035,7 @@ static void exec_inquiry(struct vdisk_cmd *vcmd)
 
                /* 16 byte ASCII Product Identification of the target - left aligned */
                memset(&buf[16], ' ', 16);
-               len = strlen(dev->name);
-               len = len < 16 ? len : 16;
+               len = min(strlen(dev->name), (size_t)16);
                memcpy(&buf[16], dev->name, len);
 
                /* 4 byte ASCII Product Revision Level of the target - left aligned */
index d43b23a..155c531 100644 (file)
@@ -118,5 +118,7 @@ struct vdisk_cmd
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
-int gen_dev_id_num(const struct vdisk_dev *dev);
+extern int vdisk_ID;
+
+uint64_t gen_dev_id_num(const struct vdisk_dev *dev);
 void *main_loop(void *arg);
index 3dcdc69..8484da1 100644 (file)
@@ -69,6 +69,8 @@ unsigned long trace_flag = DEFAULT_LOG_FLAGS;
 #define VERSION_STR            "1.0.1"
 #define THREADS                        7
 
+int vdisk_ID;
+
 static struct option const long_options[] =
 {
        {"block", required_argument, 0, 'b'},
@@ -82,6 +84,7 @@ static struct option const long_options[] =
        {"on_free", required_argument, 0, 'f'},
        {"mem_reuse", required_argument, 0, 'm'},
        {"non_blocking", no_argument, 0, 'l'},
+       {"vdisk_id", required_argument, 0, 'I'},
 #if defined(DEBUG) || defined(TRACING)
        {"debug", required_argument, 0, 'd'},
 #endif
@@ -111,6 +114,7 @@ static void usage(void)
        printf("  -m, --mem_reuse=type  Memory reuse type, one of \"all\" "
                "(default), \"read\", \"write\" or \"none\"\n");
        printf("  -l, --non_blocking    Use non-blocking operations\n");
+       printf("  -I, --vdisk_id=ID     Vdisk ID (used in multi-targets setups)\n");
 #if defined(DEBUG) || defined(TRACING)
        printf("  -d, --debug=level     Debug tracing level\n");
 #endif
@@ -177,7 +181,7 @@ int main(int argc, char **argv)
        dev.type = TYPE_DISK;
        dev.alloc_fn = align_alloc;
 
-       while ((ch = getopt_long(argc, argv, "+b:e:tronglcp:f:m:d:vh", long_options,
+       while ((ch = getopt_long(argc, argv, "+b:e:tronglI:cp:f:m:d:vh", long_options,
                                &longindex)) >= 0) {
                switch (ch) {
                case 'b':
@@ -247,6 +251,9 @@ int main(int argc, char **argv)
                case 'l':
                        dev.non_blocking = 1;
                        break;
+               case 'I':
+                       vdisk_ID = strtol(optarg, (char **)NULL, 0);
+                       break;
 #if defined(DEBUG_TM_IGNORE) || defined(DEBUG_TM_IGNORE_ALL)
                case 'g':
                        dev.debug_tm_ignore = 1;
@@ -358,7 +365,7 @@ int main(int argc, char **argv)
        PRINT_INFO("trace_flag %lx", trace_flag);
 #endif
 
-       snprintf(dev.usn, sizeof(dev.usn), "%x", gen_dev_id_num(&dev));
+       snprintf(dev.usn, sizeof(dev.usn), "%llx", gen_dev_id_num(&dev));
        TRACE_DBG("usn %s", dev.usn);
 
        dev.scst_usr_fd = open(DEV_USER_PATH DEV_USER_NAME, O_RDWR |