]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: modify flbas rsvd bits to be used
authorSteven Seungcheol Lee <sc108.lee@samsung.com>
Fri, 7 Jan 2022 06:56:24 +0000 (15:56 +0900)
committerSteven Seungcheol Lee <sc108.lee@samsung.com>
Fri, 21 Jan 2022 03:18:09 +0000 (12:18 +0900)
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 <sc108.lee@samsung.com>
nvme-print.c
nvme.c
plugins/huawei/huawei-nvme.c
plugins/netapp/netapp-nvme.c
plugins/virtium/virtium-nvme.c
plugins/zns/zns.c
subprojects/libnvme.wrap

index 894d25711ede52c55f72df7630eb46248d317b92..e0dac13607827dda1e6003acf54972c7f4ea9d23 100644 (file)
@@ -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 b3caa523dbb97a405b76422a75fa8fee3355a88a..ca40e9bdee19ea0800de28d2e33217be2ebcc64e 100644 (file)
--- 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) {
index e9e9145bbc4f7bbf4729d627d1eefc16b1754631..116025b7f48b5b43b2f9337f1f86fc0560e2f70f 100644 (file)
@@ -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;
 
index 766c0d3c2c87056312691346dfb2e552a45e264b..eea32e3f2119c8f69bb1668ba3328cbcaf3ba5db 100644 (file)
@@ -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];
index dab2fe33ec464834cdf630ae562389839526b126..7c2ebec377b557f7a89d50713804617047213ef8 100644 (file)
@@ -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,
index 83d6c98f65de7ae314c387c7e1922957fc8aafe2..2734c0dac6e5862164eb67f4ca5450032f8224ff 100644 (file)
@@ -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,
index 67bd0653cefa58ac6908a591f7df2c877563c9a6..2e3a5182ad86d1517fe068a56c3ebeeda260beb4 100644 (file)
@@ -1,6 +1,6 @@
 [wrap-git]
 url = https://github.com/linux-nvme/libnvme.git
-revision = 209c5abbeb27eca607cbc3adfb0509b0f4cd7722
+revision = 014c8e9cda65327e0bf28c510a39e491cf268017
 
 [provide]
 libnvme = libnvme_dep