From da3373aae10e29483883e4215e07ce30d032d864 Mon Sep 17 00:00:00 2001 From: Steven Seungcheol Lee Date: Mon, 13 Feb 2023 21:28:38 +0900 Subject: [PATCH] nvme: Add ns-mgmt host software specified fields nphndls, phndl from TP4146 Flexible Data Placement 2022.11.30 Ratified Reported-by: Youngjin Jung Signed-off-by: Steven Seungcheol Lee --- Documentation/nvme-create-ns.txt | 13 +++++++++++++ completions/bash-nvme-completion.sh | 2 +- nvme-wrap.c | 10 ++++++---- nvme-wrap.h | 3 ++- nvme.c | 28 +++++++++++++++++++++++++--- 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Documentation/nvme-create-ns.txt b/Documentation/nvme-create-ns.txt index 5035b132..e13aabdf 100644 --- a/Documentation/nvme-create-ns.txt +++ b/Documentation/nvme-create-ns.txt @@ -17,10 +17,12 @@ SYNOPSIS [--nvmset-id= | -i ] [--csi= | -y ] [--lbstm= | -l ] + [--nphndls= | -n ] [--block-size= | -b ] [--timeout= | -t ] [--nsze-si= | -S ] [--ncap-si= | -C ] + [--phndls= | -p ] DESCRIPTION ----------- @@ -72,6 +74,12 @@ OPTIONS --lbstm=:: Logical Block Storage Tag Mask for end-to-end protection. +-n :: +--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 :: +--phndls=:: + The comma separated list of Reclaim Unit Handle Identifier to be associated + with each Placement Handle. + EXAMPLES -------- * Create a namespace: diff --git a/completions/bash-nvme-completion.sh b/completions/bash-nvme-completion.sh index 2fc73e50..e7440185 100644 --- a/completions/bash-nvme-completion.sh +++ b/completions/bash-nvme-completion.sh @@ -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" diff --git a/nvme-wrap.c b/nvme-wrap.c index cee9b235..4d2906a9 100644 --- a/nvme-wrap.c +++ b/nvme-wrap.c @@ -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; } diff --git a/nvme-wrap.h b/nvme-wrap.h index e44a4f28..f4bec986 100644 --- a/nvme-wrap.h +++ b/nvme-wrap.h @@ -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 ca1f0aba..10f7d189 100644 --- 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) -- 2.50.1