|
39 | 39 | #include "private.h" |
40 | 40 |
|
41 | 41 | #define NVMF_HOSTID_SIZE 37 |
42 | | -#define UUID_SIZE 37 /* 1b4e28ba-2fa1-11d2-883f-0016d3cca427 + \0 */ |
43 | 42 |
|
44 | 43 | #define NVMF_HOSTNQN_FILE SYSCONFDIR "/nvme/hostnqn" |
45 | 44 | #define NVMF_HOSTID_FILE SYSCONFDIR "/nvme/hostid" |
@@ -929,8 +928,8 @@ static int uuid_from_device_tree(char *system_uuid) |
929 | 928 | if (f < 0) |
930 | 929 | return -ENXIO; |
931 | 930 |
|
932 | | - memset(system_uuid, 0, UUID_SIZE); |
933 | | - len = read(f, system_uuid, UUID_SIZE - 1); |
| 931 | + memset(system_uuid, 0, NVME_UUID_LEN_STRING); |
| 932 | + len = read(f, system_uuid, NVME_UUID_LEN_STRING - 1); |
934 | 933 | close(f); |
935 | 934 | if (len < 0) |
936 | 935 | return -ENXIO; |
@@ -1018,16 +1017,16 @@ static int uuid_from_product_uuid(char *system_uuid) |
1018 | 1017 | system_uuid[0] = '\0'; |
1019 | 1018 |
|
1020 | 1019 | nread = getline(&line, &len, stream); |
1021 | | - if (nread != UUID_SIZE) { |
| 1020 | + if (nread != NVME_UUID_LEN_STRING) { |
1022 | 1021 | ret = -ENXIO; |
1023 | 1022 | goto out; |
1024 | 1023 | } |
1025 | 1024 |
|
1026 | 1025 | /* The kernel is handling the byte swapping according DMTF |
1027 | 1026 | * SMBIOS 3.0 Section 7.2.1 System UUID */ |
1028 | 1027 |
|
1029 | | - memcpy(system_uuid, line, UUID_SIZE - 1); |
1030 | | - system_uuid[UUID_SIZE - 1] = '\0'; |
| 1028 | + memcpy(system_uuid, line, NVME_UUID_LEN_STRING - 1); |
| 1029 | + system_uuid[NVME_UUID_LEN_STRING - 1] = '\0'; |
1031 | 1030 |
|
1032 | 1031 | ret = 0; |
1033 | 1032 |
|
@@ -1063,16 +1062,17 @@ char *nvmf_hostnqn_generate() |
1063 | 1062 | { |
1064 | 1063 | char *hostnqn; |
1065 | 1064 | int ret; |
1066 | | - char uuid_str[UUID_SIZE]; |
1067 | | - uuid_t uuid; |
| 1065 | + char uuid_str[NVME_UUID_LEN_STRING]; |
| 1066 | + unsigned char uuid[NVME_UUID_LEN]; |
1068 | 1067 |
|
1069 | 1068 | ret = uuid_from_dmi(uuid_str); |
1070 | 1069 | if (ret < 0) { |
1071 | 1070 | ret = uuid_from_device_tree(uuid_str); |
1072 | 1071 | } |
1073 | 1072 | if (ret < 0) { |
1074 | | - uuid_generate_random(uuid); |
1075 | | - uuid_unparse_lower(uuid, uuid_str); |
| 1073 | + if (nvme_uuid_random(uuid) < 0) |
| 1074 | + memset(uuid, 0, NVME_UUID_LEN); |
| 1075 | + nvme_uuid_to_string(uuid, uuid_str); |
1076 | 1076 | } |
1077 | 1077 |
|
1078 | 1078 | if (asprintf(&hostnqn, "nqn.2014-08.org.nvmexpress:uuid:%s", uuid_str) < 0) |
@@ -1125,7 +1125,7 @@ static __u32 nvmf_get_tel(const char *hostsymname) |
1125 | 1125 | __u16 len; |
1126 | 1126 |
|
1127 | 1127 | /* Host ID is mandatory */ |
1128 | | - tel += nvmf_exat_size(sizeof(uuid_t)); |
| 1128 | + tel += nvmf_exat_size(NVME_UUID_LEN_STRING); |
1129 | 1129 |
|
1130 | 1130 | /* Symbolic name is optional */ |
1131 | 1131 | len = hostsymname ? strlen(hostsymname) : 0; |
@@ -1169,8 +1169,8 @@ static void nvmf_fill_die(struct nvmf_ext_die *die, struct nvme_host *h, |
1169 | 1169 | numexat++; |
1170 | 1170 | exat = die->exat; |
1171 | 1171 | exat->exattype = cpu_to_le16(NVMF_EXATTYPE_HOSTID); |
1172 | | - exat->exatlen = cpu_to_le16(nvmf_exat_len(sizeof(uuid_t))); |
1173 | | - uuid_parse(h->hostid, exat->exatval); |
| 1172 | + exat->exatlen = cpu_to_le16(nvmf_exat_len(NVME_UUID_LEN)); |
| 1173 | + nvme_uuid_from_string(h->hostid, exat->exatval); |
1174 | 1174 |
|
1175 | 1175 | /* Extended Attribute for the Symbolic Name (optional) */ |
1176 | 1176 | symname_len = h->hostsymname ? strlen(h->hostsymname) : 0; |
|
0 commit comments