]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
sfx: support query-cap change-cap for sfx csd3000
authoryuekunjin <104486991+yuekunjin@users.noreply.github.com>
Thu, 28 Apr 2022 11:53:47 +0000 (19:53 +0800)
committerDaniel Wagner <dwagner@suse.de>
Fri, 13 May 2022 14:12:37 +0000 (16:12 +0200)
Support query-cap change-cap for myrtle

Co-authored-by: yjin <yuekun.jin@scaleflux.com>
Signed-off-by: Wei Hou <wei.hou@scaleflux.com>
plugins/scaleflux/sfx-nvme.c

index b18fd9ff1d1d36b076c87d5d0e5cce9b38b21ba0..90ad8bd8c206390d524814b180b0777d8970f910 100644 (file)
@@ -58,6 +58,7 @@ struct sfx_freespace_ctx
        __u64 user_space;       /* user required space, in unit of sector*/
        __u64 hw_used;          /* hw space used in 4K */
        __u64 app_written;      /* app data written in 4K */
+       __u64 out_of_space;
 };
 
 struct nvme_capacity_info {
@@ -113,6 +114,19 @@ struct nvme_additional_smart_log {
        struct nvme_additional_smart_log_item    grown_bb; //grown bad block
 };
 
+int nvme_query_cap(int fd, __u32 nsid, __u32 data_len, void *data)
+{
+        int rc = 0;
+        struct nvme_passthru_cmd cmd = {
+        .opcode          = nvme_admin_query_cap_info,
+        .nsid            = nsid,
+        .addr            = (__u64)(uintptr_t) data,
+        .data_len        = data_len,
+        };
+
+        rc = ioctl(fd, SFX_GET_FREESPACE, data);
+        return rc == 0 ? 0 : nvme_submit_admin_passthru(fd, &cmd, NULL);
+}
 int nvme_change_cap(int fd, __u32 nsid, __u64 capacity)
 {
        struct nvme_passthru_cmd cmd = {
@@ -659,7 +673,7 @@ static int query_cap_info(int argc, char **argv, struct command *cmd, struct plu
 {
        struct sfx_freespace_ctx ctx = { 0 };
        int err = 0, fd;
-       char *desc = "query current capacity info of vanda";
+       char *desc = "query current capacity info";
        const char *raw = "dump output in binary format";
        const char *json= "Dump output in json format";
        struct config {
@@ -679,10 +693,9 @@ static int query_cap_info(int argc, char **argv, struct command *cmd, struct plu
                return fd;
        }
 
-       if (ioctl(fd, SFX_GET_FREESPACE, &ctx)) {
-               fprintf(stderr, "vu ioctl fail, errno %d\r\n", errno);
-               close(fd);
-               return -1;
+       if (nvme_query_cap(fd, 0xffffffff, sizeof(ctx), &ctx)) {
+           perror("sfx-query-cap");
+           return -1;
        }
 
        show_cap_info(&ctx);
@@ -697,14 +710,10 @@ static int change_sanity_check(int fd, __u64 trg_in_4k, int *shrink)
        __u64 mem_need = 0;
        __u64 cur_in_4k = 0;
        __u64 provisoned_cap_4k = 0;
-       __u32 cnt_ms = 0;
        int extend = 0;
 
-       while (ioctl(fd, SFX_GET_FREESPACE, &freespace_ctx)) {
-               if (cnt_ms++ > 600) {//1min
-                       return -1;
-               }
-               usleep(100000);
+       if (nvme_query_cap(fd, 0xffffffff, sizeof(freespace_ctx), &freespace_ctx)) {
+           return -1;
        }
 
        /*
@@ -781,7 +790,7 @@ static int sfx_confirm_change(const char *str)
 static int change_cap(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
        int err = -1, fd;
-       char *desc = "query current capacity info of vanda";
+       char *desc = "dynamic change capacity";
        const char *raw = "dump output in binary format";
        const char *json= "Dump output in json format";
        const char *cap_gb = "cap size in GB";