]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Added support for virtualization-management command
authorSushma Kalakota <sushmax.kalakota@intel.com>
Thu, 6 Dec 2018 20:30:13 +0000 (12:30 -0800)
committerSushma Kalakota <sushmax.kalakota@intel.com>
Fri, 14 Dec 2018 00:24:29 +0000 (16:24 -0800)
nvme-builtin.h
nvme-ioctl.c
nvme-ioctl.h
nvme.c

index a7ea5ae8f454e3dc56728ada8e67523959493e81..2eb34cbaca62e7ac8741e2cb4761df4f408b625d 100644 (file)
@@ -67,6 +67,7 @@ COMMAND_LIST(
        ENTRY("gen-hostnqn", "Generate NVMeoF host NQN", gen_hostnqn_cmd)
        ENTRY("dir-receive", "Submit a Directive Receive command, return results", dir_receive)
        ENTRY("dir-send", "Submit a Directive Send command, return results", dir_send)
+       ENTRY("virt-mgmt", "Manage Flexible Resources between Primary and Secondary Controller ", virtual_mgmt)
 );
 
 #endif
index be0823dfbcc20813b63cc351a8c31d449efe04c4..8b35c98036afeffbe8bab3f625057348684f6ecd 100644 (file)
@@ -867,3 +867,19 @@ int nvme_self_test_start(int fd, __u32 nsid, __u32 cdw10)
 
        return nvme_submit_admin_passthru(fd, &cmd);
 }
+
+int nvme_virtual_mgmt(int fd, __u32 cdw10, __u32 cdw11, __u32 *result)
+{
+       struct nvme_admin_cmd cmd = {
+               .opcode = nvme_admin_virtual_mgmt,
+               .cdw10  = cdw10,
+               .cdw11  = cdw11,
+       };
+       int err;
+
+       err = nvme_submit_admin_passthru(fd, &cmd);
+       if (!err && result)
+               *result = cmd.result;
+
+       return err;
+}
index 3fb740c323417e3c1bca3f8aa6e0349f76ba0585..08feb89b291967437e82c0c5bdcae32aba9d156e 100644 (file)
@@ -136,4 +136,5 @@ int nvme_sanitize(int fd, __u8 sanact, __u8 ause, __u8 owpass, __u8 oipbp,
                  __u8 no_dealloc, __u32 ovrpat);
 int nvme_self_test_start(int fd, __u32 nsid, __u32 cdw10);
 int nvme_self_test_log(int fd, struct nvme_self_test_log *self_test_log);
+int nvme_virtual_mgmt(int fd, __u32 cdw10, __u32 cdw11, __u32 *result);
 #endif                         /* _NVME_LIB_H */
diff --git a/nvme.c b/nvme.c
index 0e53472e8b7dec9cfc07c84803eebabba9ce32fa..f06d70107fa3449e4703f11d3a2c84ed84b668f1 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -2148,6 +2148,74 @@ static int get_ns_id(int argc, char **argv, struct command *cmd, struct plugin *
        return 0;
 }
 
+static int virtual_mgmt(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+       const char *desc  = "The Virtualization Management command is supported by primary controllers "\
+               "that support the Virtualization Enhancements capability.This command is used for "\
+               "1. Modifying Flexible Resource allocation for the primary controller  "\
+               "2. Assigning Flexible Resources for secondary controllers; and "\
+               "3. Setting the Online and Offline state for secondary controllers";
+       const char *cntlid = "This field indicates the controller for which controller resources "\
+               "are to be modified.";
+       const char *rt = "Indicate the Resource Type (RT) : \n"\
+               "1. 0 - VQ Resources.\n"\
+               "2. 1 - VI Resources.\n\n";
+       const char *act = "Indicate the Action (ACT) : \n"\
+               "1. 1 - Primary Controller Flexible Allocation\n"\
+               "2. 7 - Secondary Controller Offline\n"\
+               "3. 8 - Secondary Controller Assign\n"\
+               "4. 9 - Secondary Controller Online";
+       const char *nr = "Indicate the Number of Controller Resources (NR)";
+       int fd, err;
+       __u32 result;
+
+       struct config {
+               int     cntlid;
+               int     rt;
+               int     act;
+               __u32   cdw10;
+               __u32   cdw11;
+       };
+
+       struct config cfg = {
+               .cntlid   = 0,
+               .rt       = 0,
+               .act      = 0,
+               .cdw10    = 0,
+               .cdw11    = 0,
+       };
+
+       const struct argconfig_commandline_options command_line_options[] = {
+               {"Controller-identifier",          'c', "NUM", CFG_POSITIVE, &cfg.cntlid, required_argument, cntlid},
+               {"Resource-type",                  'r', "NUM", CFG_POSITIVE, &cfg.rt,     required_argument, rt},
+               {"Action",                         'a', "NUM", CFG_POSITIVE, &cfg.act,    required_argument, act},
+               {"Number-of-controller-resources", 'n', "NUM", CFG_POSITIVE, &cfg.cdw11,  required_argument, nr},
+               {NULL}
+       };
+
+       fd = parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
+       if (fd < 0)
+               return fd;
+
+       cfg.cdw10 = cfg.cntlid << 16;
+       cfg.cdw10 = cfg.cdw10 | (cfg.rt << 8);
+       cfg.cdw10 = cfg.cdw10 | cfg.act;
+
+       err = nvme_virtual_mgmt(fd, cfg.cdw10, cfg.cdw11, &result);
+       if (!err) {
+               printf("success, Number of Resources allocated:%#x\n", result);
+       }
+       else if (err > 0) {
+               fprintf(stderr, "NVMe Status:%s(%x)\n",
+                               nvme_status_to_string(err), err);
+       } else
+               perror("virt-mgmt");
+
+       close(fd);
+       return err;
+
+}
+
 static int device_self_test(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
        const char *desc  = "Implementing the device self-test feature"\