- Change T10 ID and USN generations to get the random part be CRC32 from the device name in the first 8 characters as many MPIO implementations expect

- Cleanup



git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@3324 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Vladislav Bolkhovitin
2011-03-29 19:08:56 +00:00
parent daa2c6e05e
commit be49977abb
5 changed files with 19 additions and 177 deletions

View File

@@ -1981,8 +1981,6 @@ Thanks to:
* Alessandro Premoli <a.premoli@andxor.it> for fixes
* Nathan Bullock <nbullock@yottayotta.com> for fixes.
* Terry Greeniaus <tgreeniaus@yottayotta.com> for fixes.
* Krzysztof Blaszkowski <kb@sysmikro.com.pl> for many fixes and bug reports.

View File

@@ -43,6 +43,7 @@
#include <asm/unaligned.h>
#include <linux/slab.h>
#include <linux/bio.h>
#include <linux/crc32c.h>
#define LOG_PREFIX "dev_vdisk"
@@ -124,73 +125,6 @@ static struct scst_trace_log vdisk_local_trace_tbl[] = {
#define VDISK_PROC_HELP "help"
#endif
static unsigned int random_values[256] = {
9862592UL, 3744545211UL, 2348289082UL, 4036111983UL,
435574201UL, 3110343764UL, 2383055570UL, 1826499182UL,
4076766377UL, 1549935812UL, 3696752161UL, 1200276050UL,
3878162706UL, 1783530428UL, 2291072214UL, 125807985UL,
3407668966UL, 547437109UL, 3961389597UL, 969093968UL,
56006179UL, 2591023451UL, 1849465UL, 1614540336UL,
3699757935UL, 479961779UL, 3768703953UL, 2529621525UL,
4157893312UL, 3673555386UL, 4091110867UL, 2193909423UL,
2800464448UL, 3052113233UL, 450394455UL, 3424338713UL,
2113709130UL, 4082064373UL, 3708640918UL, 3841182218UL,
3141803315UL, 1032476030UL, 1166423150UL, 1169646901UL,
2686611738UL, 575517645UL, 2829331065UL, 1351103339UL,
2856560215UL, 2402488288UL, 867847666UL, 8524618UL,
704790297UL, 2228765657UL, 231508411UL, 1425523814UL,
2146764591UL, 1287631730UL, 4142687914UL, 3879884598UL,
729945311UL, 310596427UL, 2263511876UL, 1983091134UL,
3500916580UL, 1642490324UL, 3858376049UL, 695342182UL,
780528366UL, 1372613640UL, 1100993200UL, 1314818946UL,
572029783UL, 3775573540UL, 776262915UL, 2684520905UL,
1007252738UL, 3505856396UL, 1974886670UL, 3115856627UL,
4194842288UL, 2135793908UL, 3566210707UL, 7929775UL,
1321130213UL, 2627281746UL, 3587067247UL, 2025159890UL,
2587032000UL, 3098513342UL, 3289360258UL, 130594898UL,
2258149812UL, 2275857755UL, 3966929942UL, 1521739999UL,
4191192765UL, 958953550UL, 4153558347UL, 1011030335UL,
524382185UL, 4099757640UL, 498828115UL, 2396978754UL,
328688935UL, 826399828UL, 3174103611UL, 3921966365UL,
2187456284UL, 2631406787UL, 3930669674UL, 4282803915UL,
1776755417UL, 374959755UL, 2483763076UL, 844956392UL,
2209187588UL, 3647277868UL, 291047860UL, 3485867047UL,
2223103546UL, 2526736133UL, 3153407604UL, 3828961796UL,
3355731910UL, 2322269798UL, 2752144379UL, 519897942UL,
3430536488UL, 1801511593UL, 1953975728UL, 3286944283UL,
1511612621UL, 1050133852UL, 409321604UL, 1037601109UL,
3352316843UL, 4198371381UL, 617863284UL, 994672213UL,
1540735436UL, 2337363549UL, 1242368492UL, 665473059UL,
2330728163UL, 3443103219UL, 2291025133UL, 3420108120UL,
2663305280UL, 1608969839UL, 2278959931UL, 1389747794UL,
2226946970UL, 2131266900UL, 3856979144UL, 1894169043UL,
2692697628UL, 3797290626UL, 3248126844UL, 3922786277UL,
343705271UL, 3739749888UL, 2191310783UL, 2962488787UL,
4119364141UL, 1403351302UL, 2984008923UL, 3822407178UL,
1932139782UL, 2323869332UL, 2793574182UL, 1852626483UL,
2722460269UL, 1136097522UL, 1005121083UL, 1805201184UL,
2212824936UL, 2979547931UL, 4133075915UL, 2585731003UL,
2431626071UL, 134370235UL, 3763236829UL, 1171434827UL,
2251806994UL, 1289341038UL, 3616320525UL, 392218563UL,
1544502546UL, 2993937212UL, 1957503701UL, 3579140080UL,
4270846116UL, 2030149142UL, 1792286022UL, 366604999UL,
2625579499UL, 790898158UL, 770833822UL, 815540197UL,
2747711781UL, 3570468835UL, 3976195842UL, 1257621341UL,
1198342980UL, 1860626190UL, 3247856686UL, 351473955UL,
993440563UL, 340807146UL, 1041994520UL, 3573925241UL,
480246395UL, 2104806831UL, 1020782793UL, 3362132583UL,
2272911358UL, 3440096248UL, 2356596804UL, 259492703UL,
3899500740UL, 252071876UL, 2177024041UL, 4284810959UL,
2775999888UL, 2653420445UL, 2876046047UL, 1025771859UL,
1994475651UL, 3564987377UL, 4112956647UL, 1821511719UL,
3113447247UL, 455315102UL, 1585273189UL, 2311494568UL,
774051541UL, 1898115372UL, 2637499516UL, 247231365UL,
1475014417UL, 803585727UL, 3911097303UL, 1714292230UL,
476579326UL, 2496900974UL, 3397613314UL, 341202244UL,
807790202UL, 4221326173UL, 499979741UL, 1301488547UL,
1056807896UL, 3525009458UL, 1174811641UL, 3049738746UL,
};
struct scst_vdisk_dev {
uint32_t block_size;
uint64_t nblocks;
@@ -1295,13 +1229,9 @@ out_done:
static uint64_t vdisk_gen_dev_id_num(const char *virt_dev_name)
{
unsigned int dev_id_num, i;
uint32_t dev_id_num;
for (dev_id_num = 0, i = 0; i < strlen(virt_dev_name); i++) {
unsigned int rv = random_values[(int)(virt_dev_name[i])];
/* Do some rotating of the bits */
dev_id_num ^= ((rv << i) | (rv >> (32 - i)));
}
dev_id_num = crc32c(0, virt_dev_name, strlen(virt_dev_name)+1);
#ifdef CONFIG_SCST_PROC
return ((uint64_t)scst_vdisk_ID << 32) | dev_id_num;
@@ -3327,9 +3257,6 @@ static int vdev_create(struct scst_dev_type *devt,
int res = 0;
struct scst_vdisk_dev *virt_dev;
uint64_t dev_id_num;
int dev_id_len;
char dev_id_str[17];
int32_t i;
virt_dev = kzalloc(sizeof(*virt_dev), GFP_KERNEL);
if (virt_dev == NULL) {
@@ -3358,22 +3285,14 @@ static int vdev_create(struct scst_dev_type *devt,
strcpy(virt_dev->name, name);
dev_id_num = vdisk_gen_dev_id_num(virt_dev->name);
dev_id_len = scnprintf(dev_id_str, sizeof(dev_id_str), "%llx",
dev_id_num);
i = strlen(virt_dev->name) + 1; /* for ' ' */
memset(virt_dev->t10_dev_id, ' ', i + dev_id_len);
memcpy(virt_dev->t10_dev_id, virt_dev->name, i-1);
memcpy(virt_dev->t10_dev_id + i, dev_id_str, dev_id_len);
snprintf(virt_dev->t10_dev_id, sizeof(virt_dev->t10_dev_id),
"%llx-%s", dev_id_num, virt_dev->name);
TRACE_DBG("t10_dev_id %s", virt_dev->t10_dev_id);
virt_dev->t10_dev_id_set = 1; /* temporary */
scnprintf(virt_dev->usn, sizeof(virt_dev->usn), "%llx", dev_id_num);
TRACE_DBG("usn %s", virt_dev->usn);
virt_dev->usn_set = 1; /* temporary */
*res_virt_dev = virt_dev;
out:

View File

@@ -17,7 +17,7 @@
SHELL=/bin/bash
SRCS_F = fileio.c common.c debug.c
SRCS_F = fileio.c common.c debug.c crc32.c
OBJS_F = $(SRCS_F:.c=.o)
#SRCS_C =

View File

@@ -36,73 +36,6 @@
#include "common.h"
static unsigned int random_values[256] = {
9862592UL, 3744545211UL, 2348289082UL, 4036111983UL,
435574201UL, 3110343764UL, 2383055570UL, 1826499182UL,
4076766377UL, 1549935812UL, 3696752161UL, 1200276050UL,
3878162706UL, 1783530428UL, 2291072214UL, 125807985UL,
3407668966UL, 547437109UL, 3961389597UL, 969093968UL,
56006179UL, 2591023451UL, 1849465UL, 1614540336UL,
3699757935UL, 479961779UL, 3768703953UL, 2529621525UL,
4157893312UL, 3673555386UL, 4091110867UL, 2193909423UL,
2800464448UL, 3052113233UL, 450394455UL, 3424338713UL,
2113709130UL, 4082064373UL, 3708640918UL, 3841182218UL,
3141803315UL, 1032476030UL, 1166423150UL, 1169646901UL,
2686611738UL, 575517645UL, 2829331065UL, 1351103339UL,
2856560215UL, 2402488288UL, 867847666UL, 8524618UL,
704790297UL, 2228765657UL, 231508411UL, 1425523814UL,
2146764591UL, 1287631730UL, 4142687914UL, 3879884598UL,
729945311UL, 310596427UL, 2263511876UL, 1983091134UL,
3500916580UL, 1642490324UL, 3858376049UL, 695342182UL,
780528366UL, 1372613640UL, 1100993200UL, 1314818946UL,
572029783UL, 3775573540UL, 776262915UL, 2684520905UL,
1007252738UL, 3505856396UL, 1974886670UL, 3115856627UL,
4194842288UL, 2135793908UL, 3566210707UL, 7929775UL,
1321130213UL, 2627281746UL, 3587067247UL, 2025159890UL,
2587032000UL, 3098513342UL, 3289360258UL, 130594898UL,
2258149812UL, 2275857755UL, 3966929942UL, 1521739999UL,
4191192765UL, 958953550UL, 4153558347UL, 1011030335UL,
524382185UL, 4099757640UL, 498828115UL, 2396978754UL,
328688935UL, 826399828UL, 3174103611UL, 3921966365UL,
2187456284UL, 2631406787UL, 3930669674UL, 4282803915UL,
1776755417UL, 374959755UL, 2483763076UL, 844956392UL,
2209187588UL, 3647277868UL, 291047860UL, 3485867047UL,
2223103546UL, 2526736133UL, 3153407604UL, 3828961796UL,
3355731910UL, 2322269798UL, 2752144379UL, 519897942UL,
3430536488UL, 1801511593UL, 1953975728UL, 3286944283UL,
1511612621UL, 1050133852UL, 409321604UL, 1037601109UL,
3352316843UL, 4198371381UL, 617863284UL, 994672213UL,
1540735436UL, 2337363549UL, 1242368492UL, 665473059UL,
2330728163UL, 3443103219UL, 2291025133UL, 3420108120UL,
2663305280UL, 1608969839UL, 2278959931UL, 1389747794UL,
2226946970UL, 2131266900UL, 3856979144UL, 1894169043UL,
2692697628UL, 3797290626UL, 3248126844UL, 3922786277UL,
343705271UL, 3739749888UL, 2191310783UL, 2962488787UL,
4119364141UL, 1403351302UL, 2984008923UL, 3822407178UL,
1932139782UL, 2323869332UL, 2793574182UL, 1852626483UL,
2722460269UL, 1136097522UL, 1005121083UL, 1805201184UL,
2212824936UL, 2979547931UL, 4133075915UL, 2585731003UL,
2431626071UL, 134370235UL, 3763236829UL, 1171434827UL,
2251806994UL, 1289341038UL, 3616320525UL, 392218563UL,
1544502546UL, 2993937212UL, 1957503701UL, 3579140080UL,
4270846116UL, 2030149142UL, 1792286022UL, 366604999UL,
2625579499UL, 790898158UL, 770833822UL, 815540197UL,
2747711781UL, 3570468835UL, 3976195842UL, 1257621341UL,
1198342980UL, 1860626190UL, 3247856686UL, 351473955UL,
993440563UL, 340807146UL, 1041994520UL, 3573925241UL,
480246395UL, 2104806831UL, 1020782793UL, 3362132583UL,
2272911358UL, 3440096248UL, 2356596804UL, 259492703UL,
3899500740UL, 252071876UL, 2177024041UL, 4284810959UL,
2775999888UL, 2653420445UL, 2876046047UL, 1025771859UL,
1994475651UL, 3564987377UL, 4112956647UL, 1821511719UL,
3113447247UL, 455315102UL, 1585273189UL, 2311494568UL,
774051541UL, 1898115372UL, 2637499516UL, 247231365UL,
1475014417UL, 803585727UL, 3911097303UL, 1714292230UL,
476579326UL, 2496900974UL, 3397613314UL, 341202244UL,
807790202UL, 4221326173UL, 499979741UL, 1301488547UL,
1056807896UL, 3525009458UL, 1174811641UL, 3049738746UL,
};
static void exec_inquiry(struct vdisk_cmd *vcmd);
static void exec_request_sense(struct vdisk_cmd *vcmd);
static void exec_mode_sense(struct vdisk_cmd *vcmd);
@@ -899,13 +832,9 @@ out:
uint64_t gen_dev_id_num(const struct vdisk_dev *dev)
{
unsigned int dev_id_num, i;
uint32_t dev_id_num;
for (dev_id_num = 0, i = 0; i < strlen(dev->name); i++) {
unsigned int rv = random_values[(int)(dev->name[i])];
/* do some rotating of the bits */
dev_id_num ^= ((rv << i) | (rv >> (32 - i)));
}
dev_id_num = crc32buf(dev->name, strlen(dev->name)+1);
return ((uint64_t)vdisk_ID << 32) | dev_id_num;
}
@@ -936,17 +865,8 @@ static void exec_inquiry(struct vdisk_cmd *vcmd)
buf[1] = 0x80; /* removable */
/* Vital Product */
if (cmd->cdb[1] & EVPD) {
uint64_t dev_id_num;
int dev_id_len;
char dev_id_str[17];
uint64_t dev_id_num = gen_dev_id_num(dev);
dev_id_num = gen_dev_id_num(dev);
dev_id_len = snprintf(dev_id_str, sizeof(dev_id_str), "%"PRIx64,
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 %"PRIx64", 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;
buf[4] = 0x0; /* this page */
@@ -961,6 +881,7 @@ static void exec_inquiry(struct vdisk_cmd *vcmd)
resp_len = buf[3] + 4;
} else if (0x83 == cmd->cdb[2]) { /* device identification */
int num = 4;
char *t10_id = (char *)&buf[num + 12];
buf[1] = 0x83;
/* Two identification descriptors: */
@@ -968,11 +889,11 @@ static void exec_inquiry(struct vdisk_cmd *vcmd)
buf[num + 0] = 0x2; /* ASCII */
buf[num + 1] = 0x1; /* Vendor ID */
memcpy(&buf[num + 4], VENDOR, 8);
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;
snprintf(t10_id, sizeof(buf) - num - 12,
"%llx-%s", dev_id_num, dev->name);
i = strlen(t10_id) + 1;
TRACE_DBG("t10_dev_id %s", t10_id);
buf[num + 3] = 8 + i;
num += buf[num + 3];
#if 0 /* This isn't required and can be misleading, so let's disable it */

View File

@@ -16,6 +16,8 @@
* GNU General Public License for more details.
*/
#include <stdint.h>
#include <scst_user.h>
#include "debug.h"
@@ -115,5 +117,7 @@ struct vdisk_cmd
extern int vdisk_ID;
uint32_t crc32buf(const char *buf, size_t len);
uint64_t gen_dev_id_num(const struct vdisk_dev *dev);
void *main_loop(void *arg);