]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: Add ns-mgmt host software specified fields
authorSteven Seungcheol Lee <sc108.lee@samsung.com>
Mon, 13 Feb 2023 12:28:38 +0000 (21:28 +0900)
committerDaniel Wagner <wagi@monom.org>
Thu, 13 Apr 2023 11:14:22 +0000 (13:14 +0200)
nphndls, phndl from TP4146 Flexible Data Placement 2022.11.30 Ratified

Reported-by: Youngjin Jung <yj4369.jung@samsung.com>
Signed-off-by: Steven Seungcheol Lee <sc108.lee@samsung.com>
Documentation/nvme-create-ns.txt
completions/bash-nvme-completion.sh
nvme-wrap.c
nvme-wrap.h
nvme.c

index 5035b1327b914af20c5220d056f4a777423236bd..e13aabdf57f317cdcc904a8d8d1c5d4ad8d557ed 100644 (file)
@@ -17,10 +17,12 @@ SYNOPSIS
                        [--nvmset-id=<nvmsetid> | -i <nvmsetid>]
                        [--csi=<command_set_identifier> | -y <command_set_identifier>]
                        [--lbstm=<lbstm> | -l <lbstm>]
+                       [--nphndls=<nphndls> | -n <nphndls>]
                        [--block-size=<block-size> | -b <block-size>]
                        [--timeout=<timeout> | -t <timeout>]
                        [--nsze-si=<nsze-si> | -S <nsze-si>]
                        [--ncap-si=<ncap-si> | -C <ncap-si>]
+                       [--phndls=<placement-handle-list,> | -p <placement-handle-list,>]
 
 DESCRIPTION
 -----------
@@ -72,6 +74,12 @@ OPTIONS
 --lbstm=<lbstm>::
        Logical Block Storage Tag Mask for end-to-end protection.
 
+-n <nphndls>::
+--nphndls=<nphndls>::
+       Number of Placement Handle included in the Placement Handle List.
+       If the Flexible Data Placement capability is not supported or not enabled
+       in specified Endurance Group, then the controller shall ignore this field.
+
 -b::
 --block-size::
        Target block size the new namespace should be formatted as. Potential FLBAS
@@ -90,6 +98,11 @@ OPTIONS
        The value SI suffixed is divided by the namespace LBA size to set as NCAP.
        If the value not suffixed it is set as same with the ncap option.
 
+-p <placement-handle-list,>::
+--phndls=<placement-handle-list,>::
+       The comma separated list of Reclaim Unit Handle Identifier to be associated
+       with each Placement Handle.
+
 EXAMPLES
 --------
 * Create a namespace:
index 2fc73e50ad91e002e8ebc539f8a6739e48c80a52..e7440185e858fca4f3f2262ad5ef39fbb96c7f38 100644 (file)
@@ -94,7 +94,7 @@ nvme_list_opts () {
                opts+=" --nsze= -s --ncap= -c --flbas= -f \
                        --dps= -d --nmic= -m --anagrp-id= -a --nvmset-id= -i \
                        --block-size= -b --timeout= -t --csi= -y --lbstm= -l \
-                       --nsze-si= -S --ncap-si= -C"
+                       --nphndls= -n --nsze-si= -S --ncap-si= -C --phndls= -p"
                        ;;
                "delete-ns")
                opts+=" -namespace-id= -n --timeout= -t"
index cee9b235d3d5412d1759d130cf4e6a36cc53dff8..4d2906a910ad26d7bd435a7fddf687d38d6ddf9d 100644 (file)
@@ -377,14 +377,16 @@ int nvme_cli_admin_passthru(struct nvme_dev *dev, __u8 opcode, __u8 flags,
 /* The MI & direct interfaces don't have an exactly-matching API for
  * ns_mgmt_create, as we don't support a timeout for MI.
  */
-int nvme_cli_ns_mgmt_create(struct nvme_dev *dev, struct nvme_id_ns *ns,
+int nvme_cli_ns_mgmt_create(struct nvme_dev *dev,
+                       struct nvme_ns_mgmt_host_sw_specified *data,
                        __u32 *nsid, __u32 timeout, __u8 csi)
 {
        if (dev->type == NVME_DEV_DIRECT)
-               return nvme_ns_mgmt_create(dev_fd(dev), ns, nsid, timeout, csi);
+               return nvme_ns_mgmt_create(dev_fd(dev), NULL, nsid, timeout,
+                                                       csi, data);
        if (dev->type == NVME_DEV_MI)
-               return nvme_mi_admin_ns_mgmt_create(dev->mi.ctrl, ns,
-                                                   csi, nsid);
+               return nvme_mi_admin_ns_mgmt_create(dev->mi.ctrl, NULL,
+                                                   csi, nsid, data);
 
        return -ENODEV;
 }
index e44a4f28395f177a0f30b7b8c2ff3742eedaeee8..f4bec9863604c1f16e270f15547d8a58ff823585 100644 (file)
@@ -32,7 +32,8 @@ int nvme_cli_identify_secondary_ctrl_list(struct nvme_dev *dev, __u32 nsid,
                                          __u16 ctrl_id,
                                          struct nvme_secondary_ctrl_list *sc_list);
 int nvme_cli_ns_mgmt_delete(struct nvme_dev *dev, __u32 nsid);
-int nvme_cli_ns_mgmt_create(struct nvme_dev *dev, struct nvme_id_ns *ns,
+int nvme_cli_ns_mgmt_create(struct nvme_dev *dev,
+                       struct nvme_ns_mgmt_host_sw_specified *data,
                        __u32 *nsid, __u32 timeout, __u8 csi);
 
 int nvme_cli_ns_attach(struct nvme_dev *dev, struct nvme_ns_attach_args *args);
diff --git a/nvme.c b/nvme.c
index ca1f0abacbf85e26cc0479170ae27b1a9f61b62f..10f7d1890b31ac9b189d55dcf41bb0083bf45248 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -2993,15 +2993,20 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
        const char *nvmsetid = "NVM Set Identifier (NVMSETID)";
        const char *csi = "command set identifier (CSI)";
        const char *lbstm = "logical block storage tag mask (LBSTM)";
+       const char *nphndls = "Number of Placement Handles (NPHNDLS)";
        const char *bs = "target block size, specify only if \'FLBAS\' "\
                "value not entered";
        const char *nsze_si = "size of ns (NSZE) in standard SI units";
        const char *ncap_si = "capacity of ns (NCAP) in standard SI units";
+       const char *phndls = "Comma separated list of Placement Handle "\
+               "Associated RUH";
 
        struct nvme_id_ns ns;
        struct nvme_dev *dev;
        int err = 0, i;
        __u32 nsid;
+       uint16_t num_phandle;
+       uint16_t phndl[128] = { 0, };
 
        struct config {
                __u64   nsze;
@@ -3015,8 +3020,10 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
                __u32   timeout;
                __u8    csi;
                __u64   lbstm;
+               __u16   nphndls;
                char    *nsze_si;
                char    *ncap_si;
+               char    *phndls;
        };
 
        struct config cfg = {
@@ -3027,12 +3034,14 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
                .nmic           = 0,
                .anagrpid       = 0,
                .nvmsetid       = 0,
-               .bs             = 0x00,
+               .bs                     = 0x00,
                .timeout        = 120000,
                .csi            = 0,
                .lbstm          = 0,
+               .nphndls        = 0,
                .nsze_si        = NULL,
                .ncap_si        = NULL,
+               .phndls         = "",
        };
 
        OPT_ARGS(opts) = {
@@ -3047,8 +3056,10 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
                OPT_UINT("timeout",      't', &cfg.timeout,  timeout),
                OPT_BYTE("csi",          'y', &cfg.csi,      csi),
                OPT_SUFFIX("lbstm",      'l', &cfg.lbstm,    lbstm),
+               OPT_SHRT("nphndls",          'n', &cfg.nphndls,  nphndls),
                OPT_STR("nsze-si",       'S', &cfg.nsze_si,  nsze_si),
                OPT_STR("ncap-si",       'C', &cfg.ncap_si,  ncap_si),
+               OPT_LIST("phndls",           'p', &cfg.phndls,   phndls),
                OPT_END()
        };
 
@@ -3108,7 +3119,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
        if (err)
                goto close_dev;
 
-       struct nvme_id_ns ns2 = {
+       struct nvme_ns_mgmt_host_sw_specified data = {
                .nsze = cpu_to_le64(cfg.nsze),
                .ncap = cpu_to_le64(cfg.ncap),
                .flbas = cfg.flbas,
@@ -3117,9 +3128,20 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
                .anagrpid = cpu_to_le32(cfg.anagrpid),
                .nvmsetid = cpu_to_le16(cfg.nvmsetid),
                .lbstm = cpu_to_le64(cfg.lbstm),
+               .nphndls = cpu_to_le16(cfg.nphndls),
        };
 
-       err = nvme_cli_ns_mgmt_create(dev, &ns2, &nsid, cfg.timeout, cfg.csi);
+       num_phandle = argconfig_parse_comma_sep_array_short(cfg.phndls, phndl, ARRAY_SIZE(phndl));
+       if (cfg.nphndls != num_phandle) {
+               fprintf(stderr, "Invaild Placement handle list\n");
+               err = -EINVAL;
+               goto close_dev;
+       }
+
+       for (i = 0; i < num_phandle; i++)
+               data.phndl[i] = cpu_to_le16(phndl[i]);
+
+       err = nvme_cli_ns_mgmt_create(dev, &data, &nsid, cfg.timeout, cfg.csi);
        if (!err)
                printf("%s: Success, created nsid:%d\n", cmd->name, nsid);
        else if (err > 0)