lib/scsi: use bkdr hash to avoid naa identifier collision

fix: If the first six characters of two scsi lun's name are the same,
such as aaaaaa0 and aaaaaa1, so do theirs naa identifier

Signed-off-by: Bin Yang <bin.yang@jaguarmicro.com>
Change-Id: I4e0541b372a0e20e95e0a24d62dd3d85b7abe230
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13824
Community-CI: Mellanox Build Bot
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Bin Yang 2022-07-26 17:31:39 +08:00 committed by Tomasz Zawadzki
parent 23f7470db8
commit 1cddc829ff

View File

@ -28,42 +28,27 @@
static void bdev_scsi_process_block_resubmit(void *arg);
static int
hex2bin(char ch)
{
if ((ch >= '0') && (ch <= '9')) {
return ch - '0';
}
ch = tolower(ch);
if ((ch >= 'a') && (ch <= 'f')) {
return ch - 'a' + 10;
}
return (int)ch;
}
static void
bdev_scsi_set_naa_ieee_extended(const char *name, uint8_t *buf)
{
int i, value, count = 0;
uint64_t local_value;
int i;
uint64_t local_value = 0, id_a, seed = 131;
for (i = 0; (i < 16) && (name[i] != '\0'); i++) {
value = hex2bin(name[i]);
if (i % 2) {
buf[count++] |= value << 4;
} else {
buf[count] = value;
}
for (i = 0; name[i] != '\0'; i++) {
local_value = (local_value * seed) + name[i];
}
local_value = *(uint64_t *)buf;
/*
* see spc3r23 7.6.3.6.2,
* NAA IEEE Extended identifer format
*/
local_value &= 0x0fff000000ffffffull;
id_a = local_value & 0x0000000fff000000ull;
id_a = id_a << 24;
local_value &= 0x0000000000ffffffull;
/* NAA 02, and 00 03 47 for IEEE Intel */
local_value |= 0x2000000347000000ull;
local_value |= id_a;
to_be64((void *)buf, local_value);
}