]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-print: Unify flag passing into functions
authorDaniel Wagner <dwagner@suse.de>
Tue, 30 May 2023 07:42:59 +0000 (09:42 +0200)
committerDaniel Wagner <wagi@monom.org>
Mon, 5 Jun 2023 06:43:35 +0000 (08:43 +0200)
Use the 'enum nvme_print_flags' type consistently everywhere.
Furthermore, move the flag as last argument where needed.

While at it also do properly indent the functions arguments.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
nvme-print.c
nvme-print.h
nvme.c
plugins/zns/zns.c

index 22206e7fa0d49057f3bde73240b5ef94605c0709..1530036b900c938e6189211015f665e9420a2d6d 100644 (file)
@@ -1634,9 +1634,10 @@ void nvme_show_ctrl_registers(void *bar, bool fabrics, enum nvme_print_flags fla
        }
 }
 
-void nvme_show_single_property(int offset, uint64_t value64, int human)
+void nvme_show_single_property(int offset, uint64_t value64, enum nvme_print_flags flags)
 {
        uint32_t value32;
+       int human = flags & VERBOSE;
 
        if (!human) {
                if (nvme_is_64bit_reg(offset))
@@ -2119,7 +2120,7 @@ static void nvme_show_id_ctrl_unvmcap(__u8 *unvmcap)
        printf("\tUnallocated NVM Capacity (UNVMCAP)\n\n");
 }
 
-void nvme_show_id_ctrl_rpmbs(__le32 ctrl_rpmbs)
+void nvme_show_id_ctrl_rpmbs(__le32 ctrl_rpmbs, enum nvme_print_flags flags)
 {
        __u32 rpmbs = le32_to_cpu(ctrl_rpmbs);
        __u32 asz = (rpmbs & 0xFF000000) >> 24;
@@ -3054,7 +3055,7 @@ void nvme_show_id_ctrl(struct nvme_id_ctrl *ctrl, enum nvme_print_flags flags,
                nvme_show_id_ctrl_unvmcap(ctrl->unvmcap);
        printf("rpmbs     : %#x\n", le32_to_cpu(ctrl->rpmbs));
        if (human)
-               nvme_show_id_ctrl_rpmbs(ctrl->rpmbs);
+               nvme_show_id_ctrl_rpmbs(ctrl->rpmbs, flags);
        printf("edstt     : %d\n", le16_to_cpu(ctrl->edstt));
        printf("dsto      : %d\n", ctrl->dsto);
        printf("fwug      : %d\n", ctrl->fwug);
@@ -3221,11 +3222,12 @@ void nvme_show_nvm_id_ns(struct nvme_nvm_id_ns *nvm_ns, unsigned int nsid,
        }
 }
 
-void nvme_show_zns_id_ctrl(struct nvme_zns_id_ctrl *ctrl, unsigned int mode)
+void nvme_show_zns_id_ctrl(struct nvme_zns_id_ctrl *ctrl,
+                          enum nvme_print_flags flags)
 {
-       if (mode & BINARY)
+       if (flags & BINARY)
                return d_raw((unsigned char *)ctrl, sizeof(*ctrl));
-       else if (mode & JSON)
+       else if (flags & JSON)
                return json_nvme_zns_id_ctrl(ctrl);
 
        printf("NVMe ZNS Identify Controller:\n");
@@ -3284,7 +3286,8 @@ static void nvme_show_zns_id_ns_zrwacap(__u8 zrwacap)
 }
 
 void nvme_show_zns_id_ns(struct nvme_zns_id_ns *ns,
-       struct nvme_id_ns *id_ns, unsigned long flags)
+                        struct nvme_id_ns *id_ns,
+                        enum nvme_print_flags flags)
 {
        int human = flags & VERBOSE, vs = flags & VS;
        uint8_t lbaf;
@@ -3383,7 +3386,7 @@ void nvme_show_list_ns(struct nvme_ns_list *ns_list, enum nvme_print_flags flags
 }
 
 void nvme_show_zns_changed(struct nvme_zns_changed_zone_log *log,
-       unsigned long flags)
+                          enum nvme_print_flags flags)
 {
        uint16_t nrzid;
        int i;
@@ -3455,8 +3458,9 @@ static void nvme_show_zns_report_zone_attributes(__u8 za, __u8 zai)
 }
 
 void nvme_show_zns_report_zones(void *report, __u32 descs,
-       __u8 ext_size, __u32 report_size, unsigned long flags,
-       struct json_object *zone_list)
+                               __u8 ext_size, __u32 report_size,
+                               struct json_object *zone_list,
+                               enum nvme_print_flags flags)
 {
        struct nvme_zone_report *r = report;
        struct nvme_zns_desc *desc;
@@ -3743,7 +3747,7 @@ void nvme_show_endurance_group_list(struct nvme_id_endurance_group_list *endgrp_
        }
 }
 
-void nvme_show_id_iocs(struct nvme_id_iocs *iocs)
+void nvme_show_id_iocs(struct nvme_id_iocs *iocs, enum nvme_print_flags flags)
 {
        __u16 i;
 
@@ -3993,7 +3997,10 @@ void nvme_print_effects_log_segment(int admin, int a, int b, struct nvme_cmd_eff
        free(stream_location);
 }
 
-void nvme_print_effects_log_page(enum nvme_csi csi, struct nvme_cmd_effects_log *effects, int flags) {
+void nvme_print_effects_log_page(enum nvme_csi csi,
+                                struct nvme_cmd_effects_log *effects,
+                                enum nvme_print_flags flags)
+{
        int human = flags & VERBOSE;
 
        switch (csi) {
@@ -4018,7 +4025,7 @@ void nvme_print_effects_log_page(enum nvme_csi csi, struct nvme_cmd_effects_log
 }
 
 void nvme_print_effects_log_pages(struct list_head *list,
-                          int flags)
+                                 enum nvme_print_flags flags)
 {
        if (flags & JSON)
                return json_effects_log_list(list);
@@ -4224,7 +4231,7 @@ void nvme_show_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
 }
 
 void nvme_show_ana_log(struct nvme_ana_log *ana_log, const char *devname,
-                       enum nvme_print_flags flags, size_t len)
+                      size_t len, enum nvme_print_flags flags)
 {
        int offset = sizeof(struct nvme_ana_log);
        struct nvme_ana_log *hdr = ana_log;
@@ -4548,7 +4555,8 @@ const char *nvme_feature_lba_type_to_string(__u8 type)
        }
 }
 
-void nvme_show_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges)
+void nvme_show_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges,
+                        enum nvme_print_flags flags)
 {
        int i, j;
 
@@ -4913,7 +4921,7 @@ void nvme_feature_show_fields(enum nvme_features_id fid, unsigned int result, un
                field = result & 0x0000003f;
                printf("\tNumber of LBA Ranges (NUM): %u\n", field + 1);
                if (buf)
-                       nvme_show_lba_range((struct nvme_lba_range_type *)buf, field);
+                       nvme_show_lba_range((struct nvme_lba_range_type *)buf, field, 0);
                break;
        case NVME_FEAT_FID_TEMP_THRESH:
                field = (result & 0x00300000) >> 20;
@@ -5448,8 +5456,9 @@ static void nvme_show_simple_topology(nvme_root_t r,
        }
 }
 
-void nvme_show_topology(nvme_root_t r, enum nvme_print_flags flags,
-                       enum nvme_cli_topo_ranking ranking)
+void nvme_show_topology(nvme_root_t r,
+                       enum nvme_cli_topo_ranking ranking,
+                       enum nvme_print_flags flags)
 {
        if (flags & JSON)
                json_simple_topology(r);
index 2eb2f4fb5a439b6261c92fb541b731101f4410ef..df9631f6ccc7c9886da2bad18b3bf9ed6c024b2d 100644 (file)
@@ -23,7 +23,7 @@ void nvme_show_status(int status);
 void nvme_show_lba_status_info(__u32 result);
 void nvme_show_relatives(const char *name);
 
-void nvme_show_id_iocs(struct nvme_id_iocs *iocs);
+void nvme_show_id_iocs(struct nvme_id_iocs *iocs, enum nvme_print_flags flags);
 void nvme_show_id_ctrl(struct nvme_id_ctrl *ctrl, enum nvme_print_flags flags,
        void (*vendor_show)(__u8 *vs, struct json_object *root));
 void nvme_show_id_ns(struct nvme_id_ns *ns, unsigned int nsid,
@@ -33,7 +33,8 @@ void nvme_show_cmd_set_independent_id_ns(
        enum nvme_print_flags flags);
 void nvme_show_resv_report(struct nvme_resv_status *status, int bytes, bool eds,
        enum nvme_print_flags flags);
-void nvme_show_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges);
+void nvme_show_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges,
+       enum nvme_print_flags flags);
 void nvme_show_supported_log(struct nvme_supported_log_pages *support,
        const char *devname, enum nvme_print_flags flags);
 void nvme_show_error_log(struct nvme_error_log_page *err_log, int entries,
@@ -41,12 +42,13 @@ void nvme_show_error_log(struct nvme_error_log_page *err_log, int entries,
 void nvme_show_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
        const char *devname, enum nvme_print_flags flags);
 void nvme_show_ana_log(struct nvme_ana_log *ana_log, const char *devname,
-       enum nvme_print_flags flags, size_t len);
+                      size_t len, enum nvme_print_flags flags);
 void nvme_show_self_test_log(struct nvme_self_test_log *self_test, __u8 dst_entries,
        __u32 size, const char *devname, enum nvme_print_flags flags);
 void nvme_show_fw_log(struct nvme_firmware_slot *fw_log, const char *devname,
        enum nvme_print_flags flags);
-void nvme_print_effects_log_pages(struct list_head *list, int flags);
+void nvme_print_effects_log_pages(struct list_head *list,
+                                 enum nvme_print_flags flags);
 void nvme_show_changed_ns_list_log(struct nvme_ns_list *log,
        const char *devname, enum nvme_print_flags flags);
 void nvme_show_endurance_log(struct nvme_endurance_group_log *endurance_log,
@@ -82,7 +84,7 @@ void nvme_show_media_unit_stat_log(struct nvme_media_unit_stat_log *mus,
 void nvme_show_supported_cap_config_log(struct nvme_supported_cap_config_list_log *caplog,
                                enum nvme_print_flags flags);
 void nvme_show_ctrl_registers(void *bar, bool fabrics, enum nvme_print_flags flags);
-void nvme_show_single_property(int offset, uint64_t prop, int human);
+void nvme_show_single_property(int offset, uint64_t prop, enum nvme_print_flags flags);
 void nvme_show_id_ns_descs(void *data, unsigned nsid, enum nvme_print_flags flags);
 void nvme_show_lba_status(struct nvme_lba_status *list, unsigned long len,
        enum nvme_print_flags flags);
@@ -107,27 +109,30 @@ void nvme_show_endurance_group_list(struct nvme_id_endurance_group_list *endgrp_
        enum nvme_print_flags flags);
 void nvme_show_list_ns(struct nvme_ns_list *ns_list,
        enum nvme_print_flags flags);
-void nvme_show_topology(nvme_root_t t, enum nvme_print_flags flags,
-                       enum nvme_cli_topo_ranking ranking);
+void nvme_show_topology(nvme_root_t t,
+                       enum nvme_cli_topo_ranking ranking,
+                       enum nvme_print_flags flags);
 
 void nvme_feature_show_fields(enum nvme_features_id fid, unsigned int result, unsigned char *buf);
 void nvme_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __u32 result,
        void *buf, __u32 len, enum nvme_print_flags flags);
 void nvme_show_select_result(__u32 result);
 
-void nvme_show_zns_id_ctrl(struct nvme_zns_id_ctrl *ctrl, unsigned int mode);
+void nvme_show_zns_id_ctrl(struct nvme_zns_id_ctrl *ctrl,
+                          enum nvme_print_flags flags);
 void nvme_show_id_ctrl_nvm(struct nvme_id_ctrl_nvm *ctrl_nvm,
        enum nvme_print_flags flags);
 void nvme_show_nvm_id_ns(struct nvme_nvm_id_ns *nvm_ns, unsigned int nsid,
                                                struct nvme_id_ns *ns, unsigned int lba_index,
                                                bool cap_only, enum nvme_print_flags flags);
 void nvme_show_zns_id_ns(struct nvme_zns_id_ns *ns,
-       struct nvme_id_ns *id_ns, unsigned long flags);
-void nvme_show_zns_changed( struct nvme_zns_changed_zone_log *log,
-       unsigned long flags);
+                        struct nvme_id_ns *id_ns, enum nvme_print_flags flags);
+void nvme_show_zns_changed(struct nvme_zns_changed_zone_log *log,
+                          enum nvme_print_flags flags);
 void nvme_show_zns_report_zones(void *report, __u32 descs,
-       __u8 ext_size, __u32 report_size, unsigned long flags,
-       struct json_object *zone_list);
+                               __u8 ext_size, __u32 report_size,
+                               struct json_object *zone_list,
+                               enum nvme_print_flags flags);
 void json_nvme_finish_zone_list(__u64 nr_zones, 
        struct json_object *zone_list);
 void nvme_show_list_item(nvme_ns_t n);
diff --git a/nvme.c b/nvme.c
index 1520a7e849a4aec7757dd0c5006317bd853ab595..b75dddaf8bad87e96e39b8530a7a1637152d78db 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -4072,7 +4072,7 @@ static int id_iocs(int argc, char **argv, struct command *cmd, struct plugin *pl
        err = nvme_identify_iocs(dev_fd(dev), cfg.cntid, &iocs);
        if (!err) {
                printf("NVMe Identify I/O Command Set:\n");
-               nvme_show_id_iocs(&iocs);
+               nvme_show_id_iocs(&iocs, 0);
        } else if (err > 0) {
                nvme_show_status(err);
        } else {
@@ -6098,7 +6098,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
                        nvme_show_lba_status_info(result);
                if (buf) {
                        if (cfg.feature_id == NVME_FEAT_FID_LBA_RANGE)
-                               nvme_show_lba_range((struct nvme_lba_range_type *)buf, result);
+                               nvme_show_lba_range((struct nvme_lba_range_type *)buf, result, 0);
                        else
                                d(buf, cfg.data_len, 16, 1);
                }
@@ -9213,7 +9213,7 @@ static int show_topology_cmd(int argc, char **argv, struct command *command, str
                return err;
        }
 
-       nvme_show_topology(r, flags, rank);
+       nvme_show_topology(r, rank, flags);
        nvme_free_tree(r);
 
        return err;
index 4348184914d978bb1a9c4c7389a20bcff7c119be..7966c227b541e2b8d3a7542f9b36c9bcbce7c09d 100644 (file)
@@ -995,7 +995,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi
 
                if (!err)
                        nvme_show_zns_report_zones(report, nr_zones_chunks, 
-                                       zdes, log_len, flags, zone_list);
+                                       zdes, log_len, zone_list, flags);
 
                nr_zones_retrieved += nr_zones_chunks;
                offset = le64_to_cpu(report->entries[nr_zones_chunks-1].zslba) + zsze;