From 9f491be4fa7a17689de9d78e8ec9bbedde96c873 Mon Sep 17 00:00:00 2001 From: Steven Seungcheol Lee Date: Fri, 7 Jan 2022 15:56:24 +0900 Subject: [PATCH] nvme: modify flbas rsvd bits to be used flbas Bits 6:5 indicate the most significant 2 bits of the Format Index of the supported LBA Format indicated in this data structure that was used to format the namespace using libnvme util function nvme_id_ns_flbas_to_lbaf_inuse to extract currently used lba index Signed-off-by: Steven Seungcheol Lee --- nvme-print.c | 25 ++++++++++++++++--------- nvme.c | 4 ++-- plugins/huawei/huawei-nvme.c | 4 +++- plugins/netapp/netapp-nvme.c | 8 ++++++-- plugins/virtium/virtium-nvme.c | 4 +++- plugins/zns/zns.c | 10 ++++++---- subprojects/libnvme.wrap | 2 +- 7 files changed, 37 insertions(+), 20 deletions(-) diff --git a/nvme-print.c b/nvme-print.c index 894d2571..e0dac136 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -3567,14 +3567,19 @@ static void nvme_show_id_ns_nsfeat(__u8 nsfeat) static void nvme_show_id_ns_flbas(__u8 flbas) { - __u8 rsvd = (flbas & 0xE0) >> 5; + __u8 rsvd = (flbas & 0x80) >> 7; + __u8 msb2_lbaf = (flbas & NVME_NS_FLBAS_HIGHER_MASK) >> 5; __u8 mdedata = (flbas & 0x10) >> 4; - __u8 lbaf = flbas & 0xF; + __u8 lsb4_lbaf = flbas & NVME_NS_FLBAS_LOWER_MASK; + if (rsvd) - printf(" [7:5] : %#x\tReserved\n", rsvd); + printf(" [7:7] : %#x\tReserved\n", rsvd); + printf(" [6:5] : %#x\tMost significant 2 bits of Current LBA Format Selected\n", + msb2_lbaf); printf(" [4:4] : %#x\tMetadata Transferred %s\n", mdedata, mdedata ? "at End of Data LBA" : "in Separate Contiguous Buffer"); - printf(" [3:0] : %#x\tCurrent LBA Format Selected\n", lbaf); + printf(" [3:0] : %#x\tLeast significant 4 bits of Current LBA Format Selected\n", + lsb4_lbaf); printf("\n"); } @@ -3710,6 +3715,7 @@ void nvme_show_id_ns(struct nvme_id_ns *ns, unsigned int nsid, bool human = flags & VERBOSE; int vs = flags & VS; int i; + __u8 flbas; if (flags & BINARY) return d_raw((unsigned char *)ns, sizeof(*ns)); @@ -3780,7 +3786,7 @@ void nvme_show_id_ns(struct nvme_id_ns *ns, unsigned int nsid, for (i = 0; i < 8; i++) printf("%02x", ns->eui64[i]); printf("\n"); - + nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &flbas); for (i = 0; i <= ns->nlbaf; i++) { if (human) printf("LBA Format %2d : Metadata Size: %-3d bytes - " @@ -3790,12 +3796,11 @@ void nvme_show_id_ns(struct nvme_id_ns *ns, unsigned int nsid, ns->lbaf[i].rp == 3 ? "Degraded" : ns->lbaf[i].rp == 2 ? "Good" : ns->lbaf[i].rp == 1 ? "Better" : "Best", - i == (ns->flbas & 0xf) ? "(in use)" : ""); + i == flbas ? "(in use)" : ""); else printf("lbaf %2d : ms:%-3d lbads:%-2d rp:%#x %s\n", i, le16_to_cpu(ns->lbaf[i].ms), ns->lbaf[i].ds, - ns->lbaf[i].rp, - i == (ns->flbas & 0xf) ? "(in use)" : ""); + ns->lbaf[i].rp, i == flbas ? "(in use)" : ""); } if (vs) { @@ -4448,9 +4453,11 @@ void nvme_show_zns_id_ns(struct nvme_zns_id_ns *ns, struct nvme_id_ns *id_ns, unsigned long flags) { int human = flags & VERBOSE, vs = flags & VS; - uint8_t lbaf = id_ns->flbas & NVME_NS_FLBAS_LBA_MASK; + uint8_t lbaf; int i; + nvme_id_ns_flbas_to_lbaf_inuse(id_ns->flbas, &lbaf); + if (flags & BINARY) return d_raw((unsigned char *)ns, sizeof(*ns)); else if (flags & JSON) diff --git a/nvme.c b/nvme.c index b3caa523..ca40e9bd 100644 --- a/nvme.c +++ b/nvme.c @@ -4270,7 +4270,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu } goto close_fd; } - prev_lbaf = ns.flbas & 0xf; + nvme_id_ns_flbas_to_lbaf_inuse(ns.flbas, &prev_lbaf); if (cfg.bs) { for (i = 0; i < 16; ++i) { @@ -5919,7 +5919,7 @@ static int submit_io(int opcode, char *command, const char *desc, perror("identify namespace"); goto free_buffer; } - lba_index = ns.flbas & NVME_NS_FLBAS_LBA_MASK; + nvme_id_ns_flbas_to_lbaf_inuse(ns.flbas, &lba_index); ms = ns.lbaf[lba_index].ms; mbuffer_size = (cfg.block_count + 1) * ms; if (ms && cfg.metadata_size < mbuffer_size) { diff --git a/plugins/huawei/huawei-nvme.c b/plugins/huawei/huawei-nvme.c index e9e9145b..116025b7 100644 --- a/plugins/huawei/huawei-nvme.c +++ b/plugins/huawei/huawei-nvme.c @@ -207,7 +207,9 @@ static void huawei_print_list_head(struct huawei_list_element_len element_len) static void huawei_print_list_item(struct huawei_list_item list_item, struct huawei_list_element_len element_len) { - long long int lba = 1 << list_item.ns.lbaf[(list_item.ns.flbas & 0x0f)].ds; + __u8 lba_index; + nvme_id_ns_flbas_to_lbaf_inuse(list_item.ns.flbas, &lba_index); + long long int lba = 1 << list_item.ns.lbaf[lba_index].ds; double nsze = le64_to_cpu(list_item.ns.nsze) * lba; double nuse = le64_to_cpu(list_item.ns.nuse) * lba; diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c index 766c0d3c..eea32e3f 100644 --- a/plugins/netapp/netapp-nvme.c +++ b/plugins/netapp/netapp-nvme.c @@ -106,7 +106,9 @@ static void netapp_nguid_to_str(char *str, __u8 *nguid) static void netapp_get_ns_size(char *size, long long *lba, struct nvme_id_ns *ns) { - *lba = 1 << ns->lbaf[(ns->flbas & 0x0F)].ds; + __u8 lba_index; + nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &lba_index); + *lba = 1 << ns->lbaf[lba_index].ds; double nsze = le64_to_cpu(ns->nsze) * (*lba); const char *s_suffix = suffix_si_get(&nsze); @@ -250,6 +252,7 @@ static void netapp_smdevices_print(struct smdevice_info *devices, int count, int "Volume ID %s, Controller %c, Access State %s, %s\n"; char columnstr[] = "%-16s %-30s %-30s %4d %32s %c %-12s %9s\n"; char *formatstr = basestr; /* default to "normal" output format */ + __u8 lba_index; if (format == NCOLUMN) { /* for column output, change output string and print column headers */ @@ -270,7 +273,8 @@ static void netapp_smdevices_print(struct smdevice_info *devices, int count, int } for (i = 0; i < count; i++) { - long long int lba = 1 << devices[i].ns.lbaf[(devices[i].ns.flbas & 0x0F)].ds; + nvme_id_ns_flbas_to_lbaf_inuse(devices[i].ns.flbas, &lba_index); + long long int lba = 1 << devices[i].ns.lbaf[lba_index].ds; double nsze = le64_to_cpu(devices[i].ns.nsze) * lba; const char *s_suffix = suffix_si_get(&nsze); char size[128]; diff --git a/plugins/virtium/virtium-nvme.c b/plugins/virtium/virtium-nvme.c index dab2fe33..7c2ebec3 100644 --- a/plugins/virtium/virtium-nvme.c +++ b/plugins/virtium/virtium-nvme.c @@ -121,6 +121,8 @@ static void vt_convert_smart_data_to_human_readable_format(struct vtview_smart_l double capacity; char *curlocale; char *templocale; + __u8 lba_index; + nvme_id_ns_flbas_to_lbaf_inuse(smart->raw_ns.flbas, &lba_index); curlocale = setlocale(LC_ALL, NULL); templocale = strdup(curlocale); @@ -130,7 +132,7 @@ static void vt_convert_smart_data_to_human_readable_format(struct vtview_smart_l setlocale(LC_ALL, "C"); - long long int lba = 1 << smart->raw_ns.lbaf[(smart->raw_ns.flbas & 0x0f)].ds; + long long int lba = 1 << smart->raw_ns.lbaf[lba_index].ds; capacity = le64_to_cpu(smart->raw_ns.nsze) * lba; snprintf(tempbuff, sizeof(tempbuff), "log;%s;%lu;%s;%s;%-.*s;", smart->raw_ctrl.sn, smart->time_stamp, smart->path, diff --git a/plugins/zns/zns.c b/plugins/zns/zns.c index 83d6c98f..2734c0da 100644 --- a/plugins/zns/zns.c +++ b/plugins/zns/zns.c @@ -328,7 +328,7 @@ static int get_zdes_bytes(int fd, __u32 nsid) return -1; } - lbaf = id_ns.flbas & NVME_NS_FLBAS_LBA_MASK; + nvme_id_ns_flbas_to_lbaf_inuse(id_ns.flbas, &lbaf); return ns.lbafe[lbaf].zdes << 6; } @@ -914,7 +914,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi err = nvme_zns_identify_ns(fd, cfg.namespace_id, &id_zns); if (!err) { /* get zsze field from zns id ns data - needed for offset calculation */ - lbaf = id_ns.flbas & NVME_NS_FLBAS_LBA_MASK; + nvme_id_ns_flbas_to_lbaf_inuse(id_ns.flbas, &lbaf); zsze = le64_to_cpu(id_zns.lbafe[lbaf].zsze); } else { @@ -1030,6 +1030,7 @@ static int zone_append(int argc, char **argv, struct command *cmd, struct plugin void *buf = NULL, *mbuf = NULL; __u16 nblocks, control = 0; __u64 result; + __u8 lba_index; struct timeval start_time, end_time; struct nvme_id_ns ns; @@ -1095,7 +1096,8 @@ static int zone_append(int argc, char **argv, struct command *cmd, struct plugin goto close_fd; } - lba_size = 1 << ns.lbaf[(ns.flbas & 0x0f)].ds; + nvme_id_ns_flbas_to_lbaf_inuse(ns.flbas, &lba_index); + lba_size = 1 << ns.lbaf[lba_index].ds; if (cfg.data_size & (lba_size - 1)) { fprintf(stderr, "Data size:%#"PRIx64" not aligned to lba size:%#x\n", @@ -1104,7 +1106,7 @@ static int zone_append(int argc, char **argv, struct command *cmd, struct plugin goto close_fd; } - meta_size = ns.lbaf[(ns.flbas & 0x0f)].ms; + meta_size = ns.lbaf[lba_index].ms; if (meta_size && !(meta_size == 8 && (cfg.prinfo & 0x8)) && (!cfg.metadata_size || cfg.metadata_size % meta_size)) { fprintf(stderr, diff --git a/subprojects/libnvme.wrap b/subprojects/libnvme.wrap index 67bd0653..2e3a5182 100644 --- a/subprojects/libnvme.wrap +++ b/subprojects/libnvme.wrap @@ -1,6 +1,6 @@ [wrap-git] url = https://github.com/linux-nvme/libnvme.git -revision = 209c5abbeb27eca607cbc3adfb0509b0f4cd7722 +revision = 014c8e9cda65327e0bf28c510a39e491cf268017 [provide] libnvme = libnvme_dep -- 2.50.1