]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: append huge to nvme_{alloc|free} function
authorDaniel Wagner <dwagner@suse.de>
Thu, 14 Sep 2023 08:12:56 +0000 (10:12 +0200)
committerDaniel Wagner <wagi@monom.org>
Wed, 20 Sep 2023 10:04:25 +0000 (12:04 +0200)
These two function are abstracting the libhugebtl API. Let's rename
Rename these functions because we want to introduce a generic alloc
function with alignment support.

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

diff --git a/nvme.c b/nvme.c
index d13eee732689a1240dcca21a61b0f52377abf62c..354c6dad89bd30671a5e69bc78a52262061f9901 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -184,6 +184,7 @@ static const char space[51] = {[0 ... 49] = ' ', '\0'};
 static void *mmap_registers(nvme_root_t r, struct nvme_dev *dev);
 
 static void *__nvme_alloc(size_t len, bool *huge)
+static void *__nvme_alloc_huge(size_t len, bool *huge)
 {
        void *p;
 
@@ -198,7 +199,7 @@ static void *__nvme_alloc(size_t len, bool *huge)
 #define HUGE_MIN 0x80000
 
 #ifdef CONFIG_LIBHUGETLBFS
-void nvme_free(void *p, bool huge)
+void nvme_free_huge(void *p, bool huge)
 {
        if (huge) {
                if (p)
@@ -208,29 +209,29 @@ void nvme_free(void *p, bool huge)
        }
 }
 
-void *nvme_alloc(size_t len, bool *huge)
+void *nvme_alloc_huge(size_t len, bool *huge)
 {
        void *p;
 
        if (len < HUGE_MIN)
-               return __nvme_alloc(len, huge);
+               return __nvme_alloc_huge(len, huge);
 
        p = get_hugepage_region(len, GHR_DEFAULT);
        if (!p)
-               return __nvme_alloc(len, huge);
+               return __nvme_alloc_huge(len, huge);
 
        *huge = true;
        return p;
 }
 #else
-void nvme_free(void *p, bool huge)
+void nvme_free_huge(void *p, bool huge)
 {
        free(p);
 }
 
-void *nvme_alloc(size_t len, bool *huge)
+void *nvme_alloc_huge(size_t len, bool *huge)
 {
-       return __nvme_alloc(len, huge);
+       return __nvme_alloc_huge(len, huge);
 }
 #endif
 
@@ -1569,7 +1570,7 @@ static int get_persistent_event_log(int argc, char **argv,
        if (cfg.action == NVME_PEVENT_LOG_EST_CTX_AND_READ)
                cfg.action = NVME_PEVENT_LOG_READ;
 
-       pevent_log_info = nvme_alloc(cfg.log_len, &huge);
+       pevent_log_info = nvme_alloc_huge(cfg.log_len, &huge);
        if (!pevent_log_info) {
                err = -ENOMEM;
                goto free_pevent;
@@ -1603,7 +1604,7 @@ static int get_persistent_event_log(int argc, char **argv,
        }
 
 free:
-       nvme_free(pevent_log_info, huge);
+       nvme_free_huge(pevent_log_info, huge);
 free_pevent:
        free(pevent);
 close_dev:
@@ -5037,7 +5038,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin
        } else if (cfg.xfer % 4096)
                cfg.xfer = 4096;
 
-       fw_buf = nvme_alloc(fw_size, &huge);
+       fw_buf = nvme_alloc_huge(fw_size, &huge);
 
        if (!fw_buf) {
                err = -ENOMEM;
@@ -5070,7 +5071,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin
        }
 
 free:
-       nvme_free(fw_buf, huge);
+       nvme_free_huge(fw_buf, huge);
 close_fw_fd:
        close(fw_fd);
 close_dev:
@@ -7570,7 +7571,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
        /* Update the data size based on the required block count */
        buffer_size = (nblocks + 1) * logical_block_size;
 
-       buffer = nvme_alloc(buffer_size, &huge);
+       buffer = nvme_alloc_huge(buffer_size, &huge);
        if (!buffer) {
                err = -ENOMEM;
                goto close_mfd;
@@ -7692,7 +7693,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
 free_mbuffer:
        free(mbuffer);
 free_buffer:
-       nvme_free(buffer, huge);
+       nvme_free_huge(buffer, huge);
 close_mfd:
        if (strlen(cfg.metadata))
                close(mfd);
@@ -8540,7 +8541,7 @@ static int passthru(int argc, char **argv, bool admin,
        }
 
        if (cfg.data_len) {
-               data = nvme_alloc(cfg.data_len, &huge);
+               data = nvme_alloc_huge(cfg.data_len, &huge);
                if (!data) {
                        err = -ENOMEM;
                        goto free_metadata;
@@ -8625,7 +8626,7 @@ static int passthru(int argc, char **argv, bool admin,
 free_metadata:
        free(mdata);
 free_data:
-       nvme_free(data, huge);
+       nvme_free_huge(data, huge);
 close_dfd:
        if (strlen(cfg.input_file))
                close(dfd);
@@ -9336,7 +9337,7 @@ static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc)
        }
 
        if (cfg.data_len) {
-               data = nvme_alloc(cfg.data_len, &huge);
+               data = nvme_alloc_huge(cfg.data_len, &huge);
                if (!data) {
                        err = -ENOMEM;
                        goto close_fd;
@@ -9372,7 +9373,7 @@ static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc)
        }
 
 free_data:
-       nvme_free(data, huge);
+       nvme_free_huge(data, huge);
 close_fd:
        if (strlen(cfg.input_file))
                close(fd);
diff --git a/nvme.h b/nvme.h
index d859983e7e08af89a142860678ebc63bd7ca07b9..e5f0b186823391522402fa663e8606dbe2f0ee41 100644 (file)
--- a/nvme.h
+++ b/nvme.h
@@ -107,8 +107,8 @@ int __id_ctrl(int argc, char **argv, struct command *cmd,
        struct plugin *plugin, void (*vs)(uint8_t *vs, struct json_object *root));
 
 extern int current_index;
-void *nvme_alloc(size_t len, bool *huge);
-void nvme_free(void *p, bool huge);
+void *nvme_alloc_huge(size_t len, bool *huge);
+void nvme_free_huge(void *p, bool huge);
 const char *nvme_strerror(int errnum);
 
 unsigned long long elapsed_utime(struct timeval start_time,
index d6fb6017774eafb5ca67b4608e2ec681b52e3d36..195c971e840cf52024046d6d840782dc538e4ba7 100644 (file)
@@ -1799,7 +1799,7 @@ static void GetGenericLogs(int fd, const char *dir)
        }
 
        log_len = le64_to_cpu(pevent_log.tll);
-       pevent_log_info = nvme_alloc(log_len, &huge);
+       pevent_log_info = nvme_alloc_huge(log_len, &huge);
        if (!pevent_log_info) {
                perror("could not alloc buffer for persistent event log page (ignored)!\n");
                return;
@@ -1809,7 +1809,7 @@ static void GetGenericLogs(int fd, const char *dir)
        if (!err)
                WriteData((__u8 *)pevent_log_info, log_len, dir,
                          "persistent_event_log.bin", "persistent event log");
-       nvme_free(pevent_log_info, huge);
+       nvme_free_huge(pevent_log_info, huge);
 }
 
 static void GetNSIDDInfo(int fd, const char *dir, int nsid)
index 01867c71a5017b2516d53fc8a8a177c0ae51c889..e7f3b9907aa61abe582562fbf43cc5f47dc44d7f 100644 (file)
@@ -1410,7 +1410,7 @@ static int nvme_dump_evtlog(struct nvme_dev *dev, __u32 namespace_id, __u32 stor
        if (log_len % 4)
                log_len = (log_len / 4 + 1) * 4;
 
-       pevent_log_info = nvme_alloc(single_len, &huge);
+       pevent_log_info = nvme_alloc_huge(single_len, &huge);
        if (!pevent_log_info) {
                err = -ENOMEM;
                goto free_pevent;
@@ -1453,8 +1453,8 @@ static int nvme_dump_evtlog(struct nvme_dev *dev, __u32 namespace_id, __u32 stor
        printf("\nDump-evtlog: Success\n");
 
        if (parse) {
-               nvme_free(pevent_log_info, huge);
-               pevent_log_info = nvme_alloc(log_len, &huge);
+               nvme_free_huge(pevent_log_info, huge);
+               pevent_log_info = nvme_alloc_huge(log_len, &huge);
                if (!pevent_log_info) {
                        fprintf(stderr, "Failed to alloc enough memory 0x%x to parse evtlog\n", log_len);
                        err = -ENOMEM;
@@ -1479,7 +1479,7 @@ static int nvme_dump_evtlog(struct nvme_dev *dev, __u32 namespace_id, __u32 stor
 close_fd:
        fclose(fd);
 free:
-       nvme_free(pevent_log_info, huge);
+       nvme_free_huge(pevent_log_info, huge);
 free_pevent:
        free(pevent);
 ret:
index 49ede5c31e04be7f9f96b5aff20b13fdd39c3d5d..ae57e85f68cce717c455f61964928b22e3e87b9c 100644 (file)
@@ -10386,7 +10386,7 @@ static int wdc_vs_pcie_stats(int argc, char **argv, struct command *command,
                goto out;
        }
 
-       pcieStatsPtr = nvme_alloc(pcie_stats_size, &huge);
+       pcieStatsPtr = nvme_alloc_huge(pcie_stats_size, &huge);
        if (!pcieStatsPtr) {
                fprintf(stderr, "ERROR: WDC: PCIE Stats alloc: %s\n", strerror(errno));
                ret = -1;
@@ -10417,7 +10417,7 @@ static int wdc_vs_pcie_stats(int argc, char **argv, struct command *command,
                }
        }
 
-       nvme_free(pcieStatsPtr, huge);
+       nvme_free_huge(pcieStatsPtr, huge);
 
 out:
        nvme_free_tree(r);
index f88ad8bd14bdbfd284838b0d901397382c6179ed..7b1b191b6e3746cf4ea219b20d173e386b98ce29 100644 (file)
@@ -949,7 +949,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi
        log_len = sizeof(struct nvme_zone_report) + ((sizeof(struct nvme_zns_desc) * nr_zones_chunks) + (nr_zones_chunks * zdes));
        report_size = log_len;
 
-       report = nvme_alloc(report_size, &huge);
+       report = nvme_alloc_huge(report_size, &huge);
        if (!report) {
                perror("alloc");
                err = -ENOMEM;
@@ -997,7 +997,7 @@ static int report_zones(int argc, char **argv, struct command *cmd, struct plugi
                        ops->zns_finish_zone_list(total_nr_zones, zone_list);
        }
 
-       nvme_free(report, huge);
+       nvme_free_huge(report, huge);
 
 free_buff:
        free(buff);