From 7f56ce8e6fee435e423db318d494096e32f0f520 Mon Sep 17 00:00:00 2001 From: yuekunjin <104486991+yuekunjin@users.noreply.github.com> Date: Thu, 28 Apr 2022 19:53:47 +0800 Subject: [PATCH] sfx: support query-cap change-cap for sfx csd3000 Support query-cap change-cap for myrtle Co-authored-by: yjin Signed-off-by: Wei Hou --- plugins/scaleflux/sfx-nvme.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/plugins/scaleflux/sfx-nvme.c b/plugins/scaleflux/sfx-nvme.c index b18fd9ff..90ad8bd8 100644 --- a/plugins/scaleflux/sfx-nvme.c +++ b/plugins/scaleflux/sfx-nvme.c @@ -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"; -- 2.50.1