nvmet: Add support for multi-tenant configfs
Subsystems (3)
cover nvmet: Add support for multi-tenant configfs
From: Nicholas Bellinger <[email protected]>
Hi folks,
Here's the first pass of a nvmet multi-tenant configfs layout, following what we've learned in target_core_fabric_configfs.c wrt to independent operation of storage endpoints.
Here is how the running RFC-v1 code currently looks:
/sys/kernel/config/nvmet/subsystems/
??? nqn.2003-01.org.linux-iscsi.NVMf.skylake-ep
??? namespaces
??? ??? 1
??? ??? ramdisk0 -> ../../../../../target/core/rd_mcp_1/ramdisk0
??? ports
??? loop
??? addr_adrfam
??? addr_portid
??? addr_traddr
??? addr_treq
??? addr_trsvcid
??? addr_trtype
??? enableNamely, it allows existing /sys/kernel/config/target/core/ backends to be configfs symlinked into ../nvmet/subsystems/$SUBSYS_NQN/ as nvme namespaces.
The series exposes T10-PI from /sys/kernel/config/target/core/ as ID_NS.ms + ID_NS.dps feature bits, and enables block integrity support with nvme/loop driver.
Note this series depends upon the following prerequisites of target-core:
http://marc.info/?l=linux-scsi&m=146527281416606&w=2
and of course, today's earlier release of nvmet + friends:
http://lists.infradead.org/pipermail/linux-nvme/2016-June/004754.html
Note the full set of patches is available from:
https://git.kernel.org/cgit/linux/kernel/git/nab/target-pending.git/log/?h=nvmet-configfs-ng
Comments..?
--nab
Nicholas Bellinger (8):
nvmet: Add nvmet_fabric_ops get/put transport helpers
nvmet: Add support for configfs-ng multi-tenant logic
nvmet: Hookup nvmet_ns->dev to nvmet_ns_enable nvmet/io-cmd: Hookup sbc_ops->execute_rw backend ops nvmet/io-cmd: Hookup sbc_ops->execute_sync_cache backend ops nvmet/io-cmd: Hookup sbc_ops->execute_unmap backend ops nvmet/admin-cmd: Hookup T10-PI to ID_NS.ms + ID_NS.dps feature bits nvme/loop: Add support for bio integrity handling
drivers/nvme/target/Makefile | 2 +- drivers/nvme/target/admin-cmd.c | 17 ++ drivers/nvme/target/configfs-ng.c | 585 ++++++++++++++++++++++++++++++++++++++ drivers/nvme/target/configfs.c | 5 +- drivers/nvme/target/core.c | 83 +++--- drivers/nvme/target/io-cmd.c | 169 ++++++----- drivers/nvme/target/loop.c | 19 ++ drivers/nvme/target/nvmet.h | 27 +- 8 files changed, 799 insertions(+), 108 deletions(-) create mode 100644 drivers/nvme/target/configfs-ng.c
Signature · 1 line
1.9.1
RFC 1/8 nvmet: Add nvmet_fabric_ops get/put transport helpers
From: Nicholas Bellinger <[email protected]>
This patch introduces two helpers for obtaining + releasing nvmet_fabric_ops for nvmet_port usage, and the associated struct module ops->owner reference.
This is required in order to support nvmet/configfs-ng and multiple nvmet_port configfs groups living under /sys/kernel/config/nvmet/subsystems/$SUBSYS_NQN/ports/
--- drivers/nvme/target/core.c | 31 +++++++++++++++++++++++++++++++ drivers/nvme/target/nvmet.h | 3 +++ 2 files changed, 34 insertions(+)
drivers/nvme/target/core.c +31 -0
@@ -191,6 +191,37 @@ void nvmet_disable_port(struct nvmet_port *port)module_put (ops->owner); } +struct nvmet_fabrics_ops *nvmet_get_transport (struct nvmet_port *port) +{ +struct nvmet_fabrics_ops *ops; + +down_write (&nvmet_config_sem); + ops = nvmet_transports[port->disc_addr.trtype]; +if (!ops) { +pr_err ("transport type %d not supported\n" , + port->disc_addr.trtype); +return ERR_PTR (-EINVAL ); + } + +if (!try_module_get (ops->owner)) { +up_write (&nvmet_config_sem); +return ERR_PTR (-EINVAL ); + } +up_write (&nvmet_config_sem); + +return ops; +} + +void nvmet_put_transport (struct nvmet_port *port) +{ +struct nvmet_fabrics_ops *ops; + +down_write (&nvmet_config_sem); + ops = nvmet_transports[port->disc_addr.trtype]; +module_put (ops->owner); +up_write (&nvmet_config_sem); +} +static void nvmet_keep_alive_timer (struct work_struct *work) { struct nvmet_ctrl *ctrl = container_of(to_delayed_work(work),
drivers/nvme/target/nvmet.h +3 -0
@@ -299,6 +299,9 @@ void nvmet_unregister_transport(struct nvmet_fabrics_ops *ops);int nvmet_enable_port (struct nvmet_port *port);void nvmet_disable_port (struct nvmet_port *port); +struct nvmet_fabrics_ops *nvmet_get_transport (struct nvmet_port *port); +void nvmet_put_transport (struct nvmet_port *port); +void nvmet_referral_enable (struct nvmet_port *parent,struct nvmet_port *port);void nvmet_referral_disable (struct nvmet_port *port);
Signature · 1 line
1.9.1
RFC 2/8 nvmet: Add support for configfs-ng multi-tenant logic
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch introduces support for configfs-ng, that allows for multi-tenant /sys/kernel/config/nvmet/subsystems/$SUBSYS_NQN/ operation, using existing /sys/kernel/config/target/core/ backends from target-core to be configfs symlinked as per nvme-target subsystem NQN namespaces.
Here's how the layout looks:
/sys/kernel/config/nvmet/
??? subsystems
??? nqn.2003-01.org.linux-iscsi.NVMf.skylake-ep
??? namespaces
??? ??? 1
??? ??? ramdisk0 -> ../../../../../target/core/rd_mcp_1/ramdisk0
??? ports
??? loop
??? addr_adrfam
??? addr_portid
??? addr_traddr
??? addr_treq
??? addr_trsvcid
??? addr_trtype
??? enableAlso convert nvmet_find_get_subsys to port->nf_subsys, and do the same for nvmet_host_discovery_allowed.
--- drivers/nvme/target/Makefile | 2 +- drivers/nvme/target/configfs-ng.c | 586 ++++++++++++++++++++++++++++++++++++++ drivers/nvme/target/configfs.c | 5 +- drivers/nvme/target/core.c | 22 +- drivers/nvme/target/nvmet.h | 11 + 5 files changed, 608 insertions(+), 18 deletions(-) create mode 100644 drivers/nvme/target/configfs-ng.c
drivers/nvme/target/Makefile +1 -1
@@ -3,7 +3,7 @@ obj-$(CONFIG_NVME_TARGET) += nvmet.o obj-$(CONFIG_NVME_TARGET_LOOP) += nvme-loop.o obj-$(CONFIG_NVME_TARGET_RDMA) += nvmet-rdma.o -nvmet-y += core.o configfs.o admin-cmd.o io-cmd.o fabrics-cmd.o \ +nvmet-y += core.o configfs-ng.o admin-cmd.o io-cmd.o fabrics-cmd.o \ discovery.o nvme-loop-y += loop.o nvmet-rdma-y += rdma.o
drivers/nvme/target/configfs-ng.c new file +586 -0
586 lines not on this page · raw message
drivers/nvme/target/configfs.c +4 -1
@@ -441,7 +441,9 @@ static int nvmet_port_subsys_allow_link(struct config_item *parent,if (!link)return -ENOMEM ; link->subsys = subsys; - +#if 1 +BUG_ON (1 ); +#else down_write (&nvmet_config_sem); ret = -EEXIST ;list_for_each_entry (p, &port->subsystems, entry) {
@@ -458,6 +460,7 @@ static int nvmet_port_subsys_allow_link(struct config_item *parent,list_add_tail (&link->entry, &port->subsystems); nvmet_genctr++;up_write (&nvmet_config_sem); +#endif return 0 ; out_free_link:
drivers/nvme/target/core.c +6 -16
@@ -696,10 +696,8 @@ static bool __nvmet_host_allowed(struct nvmet_subsys *subsys,static bool nvmet_host_discovery_allowed (struct nvmet_req *req,const char *hostnqn) { -struct nvmet_subsys_link *s; - -list_for_each_entry (s, &req->port->subsystems, entry) { -if (__nvmet_host_allowed (s->subsys, hostnqn)) +if (req->port && req->port->nf_subsys) { +if (__nvmet_host_allowed (req->port->nf_subsys, hostnqn))return true; }
@@ -874,8 +872,6 @@ EXPORT_SYMBOL_GPL(nvmet_ctrl_fatal_error);static struct nvmet_subsys *nvmet_find_get_subsys (struct nvmet_port *port,const char *subsysnqn) { -struct nvmet_subsys_link *p; -if (!port)return NULL ;
@@ -886,17 +882,11 @@ static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port,return nvmet_disc_subsys; } -down_read (&nvmet_config_sem); -list_for_each_entry (p, &port->subsystems, entry) { -if (!strncmp (p->subsys->subsysnqn, subsysnqn, -NVMF_NQN_SIZE )) { -if (!kref_get_unless_zero (&p->subsys->ref)) -break ; -up_read (&nvmet_config_sem); -return p->subsys; - } +if (port->nf_subsys) { +if (kref_get_unless_zero (&port->nf_subsys->ref)) +return port->nf_subsys; } -up_read (&nvmet_config_sem); +return NULL ; }
drivers/nvme/target/nvmet.h +11 -0
@@ -98,6 +98,9 @@ struct nvmet_port {struct list_head referrals;void *priv;bool enabled; + +struct nvmet_subsys *nf_subsys; +struct nvmet_fabrics_ops *nf_ops; };static inline struct nvmet_port *to_nvmet_port (struct config_item *item)
@@ -158,6 +161,7 @@ struct nvmet_subsys {struct config_group group;struct config_group namespaces_group; +struct config_group ports_group;struct config_group allowed_hosts_group; };
@@ -173,6 +177,13 @@ static inline struct nvmet_subsys *namespaces_to_subsys( namespaces_group); } +static inline struct nvmet_subsys *ports_to_subsys ( +struct config_item *item) +{ + return container_of(to_config_group(item), struct nvmet_subsys, + ports_group); +} +struct nvmet_host {struct config_group group; };
Signature · 1 line
1.9.1
RFC 3/8 nvmet: Hookup nvmet_ns->dev to nvmet_ns_enable
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch hooks up nvmet_ns_enable() to accept the RCU protected struct se_device provided as a configfs symlink from existing /sys/kernel/config/target/core/ driver backends.
Also, drop the now unused internal ns->bdev + ns->device_path usage, and add WIP stubs for nvmet/io-cmd sbc_ops backend conversion to be added in subsequent patches.
--- drivers/nvme/target/configfs-ng.c | 3 +-- drivers/nvme/target/core.c | 30 ++++++++---------------------- drivers/nvme/target/io-cmd.c | 17 +++++++++++++++-- drivers/nvme/target/nvmet.h | 6 ++---- 4 files changed, 26 insertions(+), 30 deletions(-)
drivers/nvme/target/configfs-ng.c +1 -2
@@ -392,8 +392,7 @@ static int nvmet_ns_link(struct config_item *ns_ci, struct config_item *dev_ci)return -ENOSYS ; } -// XXX: Pass in struct se_device into nvmet_ns_enable -return nvmet_ns_enable (ns); +return nvmet_ns_enable (ns, dev); }static int nvmet_ns_unlink (struct config_item *ns_ci,struct config_item *dev_ci)
drivers/nvme/target/core.c +8 -22
@@ -13,6 +13,8 @@*/ #define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/module.h> +#include <target/target_core_base.h> +#include <target/target_core_backend.h> #include "nvmet.h" static struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX ];
@@ -287,7 +289,7 @@ void nvmet_put_namespace(struct nvmet_ns *ns)percpu_ref_put (&ns->ref); } -int nvmet_ns_enable (struct nvmet_ns *ns) +int nvmet_ns_enable (struct nvmet_ns *ns,struct se_device *dev) {struct nvmet_subsys *subsys = ns->subsys;struct nvmet_ctrl *ctrl;
@@ -297,23 +299,14 @@ int nvmet_ns_enable(struct nvmet_ns *ns)if (!list_empty (&ns->dev_link)) goto out_unlock; - ns->bdev =blkdev_get_by_path (ns->device_path,FMODE_READ |FMODE_WRITE , -NULL ); -if (IS_ERR (ns->bdev)) { -pr_err ("nvmet: failed to open block device %s: (%ld)\n" , - ns->device_path,PTR_ERR (ns->bdev)); - ret =PTR_ERR (ns->bdev); - ns->bdev =NULL ; - goto out_unlock; - } - - ns->size =i_size_read (ns->bdev->bd_inode); - ns->blksize_shift =blksize_bits (bdev_logical_block_size (ns->bdev)); +rcu_assign_pointer (ns->dev, dev); + ns->size = dev->transport->get_blocks (dev) * dev->dev_attrib.hw_block_size; + ns->blksize_shift =blksize_bits (dev->dev_attrib.hw_block_size); ret =percpu_ref_init (&ns->ref, nvmet_destroy_namespace,0 ,GFP_KERNEL );if (ret) - goto out_blkdev_put; + goto out_unlock;if (ns->nsid > subsys->max_nsid) subsys->max_nsid = ns->nsid;
@@ -343,10 +336,6 @@ int nvmet_ns_enable(struct nvmet_ns *ns) out_unlock:mutex_unlock (&subsys->lock);return ret; -out_blkdev_put: -blkdev_put (ns->bdev,FMODE_WRITE |FMODE_READ ); - ns->bdev =NULL ; - goto out_unlock; }void nvmet_ns_disable (struct nvmet_ns *ns)
@@ -379,16 +368,13 @@ void nvmet_ns_disable(struct nvmet_ns *ns)list_for_each_entry (ctrl, &subsys->ctrls, subsys_entry)nvmet_add_async_event (ctrl,NVME_AER_TYPE_NOTICE ,0 ,0 ); -if (ns->bdev) -blkdev_put (ns->bdev,FMODE_WRITE |FMODE_READ ); +rcu_assign_pointer (ns->dev,NULL );mutex_unlock (&subsys->lock); }void nvmet_ns_free (struct nvmet_ns *ns) {nvmet_ns_disable (ns); - -kfree (ns->device_path);kfree (ns); }
drivers/nvme/target/io-cmd.c +15 -2
@@ -16,6 +16,7 @@#include <linux/module.h> #include "nvmet.h" +#if 0 static void nvmet_bio_done (struct bio *bio) {struct nvmet_req *req = bio->bi_private;
@@ -26,6 +27,7 @@ static void nvmet_bio_done(struct bio *bio)if (bio != &req->inline_bio) bio_put(bio); } +#endif static inline u32 nvmet_rw_len (struct nvmet_req *req) {
@@ -33,6 +35,7 @@ static inline u32 nvmet_rw_len(struct nvmet_req *req) req->ns->blksize_shift; } +#if 0 static void nvmet_inline_bio_init (struct nvmet_req *req) {struct bio *bio = &req->inline_bio;
@@ -41,21 +44,23 @@ static void nvmet_inline_bio_init(struct nvmet_req *req) bio->bi_max_vecs =NVMET_MAX_INLINE_BIOVEC ; bio->bi_io_vec = req->inline_bvec; } +#endif static void nvmet_execute_rw (struct nvmet_req *req) { +#if 0 int sg_cnt = req->sg_cnt;struct scatterlist *sg;struct bio *bio;sector_t sector;blk_qc_t cookie;int rw, i; - +#endif if (!req->sg_cnt) {nvmet_req_complete (req,0 );return ; } - +#if 0 if (req->cmd->rw.opcode == nvme_cmd_write) {if (req->cmd->rw.control &cpu_to_le16 (NVME_RW_FUA )) rw =WRITE_FUA ;
@@ -95,10 +100,12 @@ static void nvmet_execute_rw(struct nvmet_req *req) cookie =submit_bio (rw, bio);blk_poll (bdev_get_queue (req->ns->bdev), cookie); +#endif }static void nvmet_execute_flush (struct nvmet_req *req) { +#if 0 struct bio *bio;nvmet_inline_bio_init (req);
@@ -109,8 +116,10 @@ static void nvmet_execute_flush(struct nvmet_req *req) bio->bi_end_io = nvmet_bio_done;submit_bio (WRITE_FLUSH , bio); +#endif } +#if 0 static u16 nvmet_discard_range (struct nvmet_ns *ns,struct nvme_dsm_range *range,int type,struct bio **bio) {
@@ -119,11 +128,14 @@ static u16 nvmet_discard_range(struct nvmet_ns *ns, le32_to_cpu(range->nlb) << (ns->blksize_shift - 9), GFP_KERNEL, type, bio))return NVME_SC_INTERNAL |NVME_SC_DNR ; + return 0; } +#endif static void nvmet_execute_discard (struct nvmet_req *req) { +#if 0 struct nvme_dsm_range range;struct bio *bio =NULL ;int type =REQ_WRITE |REQ_DISCARD , i;
@@ -152,6 +164,7 @@ static void nvmet_execute_discard(struct nvmet_req *req) } else {nvmet_req_complete (req, status); } +#endif }static void nvmet_execute_dsm (struct nvmet_req *req)
drivers/nvme/target/nvmet.h +2 -4
@@ -41,15 +41,13 @@struct nvmet_ns {struct list_head dev_link;struct percpu_ref ref; -struct block_device *bdev; +struct se_device __rcu *dev;u32 nsid;u32 blksize_shift;loff_t size;u8 nguid[16 ];struct nvmet_subsys *subsys; -const char *device_path; -struct config_group device_group;struct config_group group;
@@ -299,7 +297,7 @@ void nvmet_subsys_put(struct nvmet_subsys *subsys);struct nvmet_ns *nvmet_find_namespace (struct nvmet_ctrl *ctrl,__le32 nsid);void nvmet_put_namespace (struct nvmet_ns *ns); -int nvmet_ns_enable (struct nvmet_ns *ns); +int nvmet_ns_enable (struct nvmet_ns *ns,struct se_device *dev);void nvmet_ns_disable (struct nvmet_ns *ns);struct nvmet_ns *nvmet_ns_alloc (struct nvmet_subsys *subsys,u32 nsid);void nvmet_ns_free (struct nvmet_ns *ns);
Signature · 1 line
1.9.1
RFC 4/8 nvmet/io-cmd: Hookup sbc_ops->execute_rw backend ops
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch converts nvmet_execute_rw() to utilize sbc_ops->execute_rw() for target_iostate + target_iomem based I/O submission into existing backends drivers via configfs in /sys/kernel/config/target/core/.
This includes support for passing T10-PI scatterlists via target_iomem into existing sbc_ops->execute_rw() logic, and is functioning with IBLOCK, FILEIO, and RAMDISK.
Note the preceeding target/iblock patch absorbs inline bio + bvecs and blk_poll() optimizations from Ming + Sagi in nvmet/io-cmd into target_core_iblock.c code.
--- drivers/nvme/target/io-cmd.c | 116 ++++++++++++++++++++++--------------------- drivers/nvme/target/nvmet.h | 7 +++ 2 files changed, 67 insertions(+), 56 deletions(-)
drivers/nvme/target/io-cmd.c +60 -56
@@ -14,20 +14,16 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/blkdev.h> #include <linux/module.h> +#include <target/target_core_base.h> +#include <target/target_core_backend.h> #include "nvmet.h" -#if 0 -static void nvmet_bio_done (struct bio *bio) +static void nvmet_complete_ios (struct target_iostate *ios,u16 status) { -struct nvmet_req *req = bio->bi_private; - -nvmet_req_complete (req, - bio->bi_error ?NVME_SC_INTERNAL |NVME_SC_DNR :0 ); + struct nvmet_req *req = container_of(ios, struct nvmet_req, t_iostate); -if (bio != &req->inline_bio) -bio_put (bio); +nvmet_req_complete (req, status ?NVME_SC_INTERNAL |NVME_SC_DNR :0 ); } -#endif static inline u32 nvmet_rw_len (struct nvmet_req *req) {
@@ -35,72 +31,80 @@ static inline u32 nvmet_rw_len(struct nvmet_req *req) req->ns->blksize_shift; } -#if 0 -static void nvmet_inline_bio_init (struct nvmet_req *req) -{ -struct bio *bio = &req->inline_bio; - -bio_init (bio); - bio->bi_max_vecs =NVMET_MAX_INLINE_BIOVEC ; - bio->bi_io_vec = req->inline_bvec; -} -#endif -static void nvmet_execute_rw (struct nvmet_req *req) { -#if 0 -int sg_cnt = req->sg_cnt; -struct scatterlist *sg; -struct bio *bio; +struct target_iostate *ios = &req->t_iostate; +struct target_iomem *iomem = &req->t_iomem; +struct se_device *dev =rcu_dereference_raw (req->ns->dev); +struct sbc_ops *sbc_ops = dev->transport->sbc_ops;sector_t sector; -blk_qc_t cookie; -int rw, i; -#endif +enum dma_data_direction data_direction; +sense_reason_t rc; +bool fua_write = false, prot_enabled = false; + +if (!sbc_ops || !sbc_ops->execute_rw) { +nvmet_req_complete (req,NVME_SC_INTERNAL |NVME_SC_DNR ); +return ; + } +if (!req->sg_cnt) {nvmet_req_complete (req,0 );return ; } -#if 0 +if (req->cmd->rw.opcode == nvme_cmd_write) {if (req->cmd->rw.control &cpu_to_le16 (NVME_RW_FUA )) - rw =WRITE_FUA ; -else - rw =WRITE ; + fua_write = true; + + data_direction =DMA_TO_DEVICE ; }else { - rw =READ ; + data_direction =DMA_FROM_DEVICE ; } sector =le64_to_cpu (req->cmd->rw.slba); sector <<= (req->ns->blksize_shift -9 ); -nvmet_inline_bio_init (req); - bio = &req->inline_bio; - bio->bi_bdev = req->ns->bdev; - bio->bi_iter.bi_sector = sector; - bio->bi_private = req; - bio->bi_end_io = nvmet_bio_done; - -for_each_sg (req->sg, sg, req->sg_cnt, i) { -while (bio_add_page (bio,sg_page (sg), sg->length, sg->offset) - != sg->length) { -struct bio *prev = bio; - - bio =bio_alloc (GFP_KERNEL ,min (sg_cnt,BIO_MAX_PAGES )); - bio->bi_bdev = req->ns->bdev; - bio->bi_iter.bi_sector = sector; - -bio_chain (bio, prev); - cookie =submit_bio (rw, prev); - } + ios->t_task_lba = sector; + ios->data_length =nvmet_rw_len (req); + ios->data_direction = data_direction; + iomem->t_data_sg = req->sg; + iomem->t_data_nents = req->sg_cnt; + iomem->t_prot_sg = req->prot_sg; + iomem->t_prot_nents = req->prot_sg_cnt; + +// XXX: Make common between sbc_check_prot and nvme-target +switch (dev->dev_attrib.pi_prot_type) { +case TARGET_DIF_TYPE3_PROT : + ios->reftag_seed =0xffffffff ; + prot_enabled = true; +break ; +case TARGET_DIF_TYPE1_PROT : + ios->reftag_seed = ios->t_task_lba; + prot_enabled = true; +break ; +default : +break ; + } - sector += sg->length >>9 ; - sg_cnt--; +if (prot_enabled) { + ios->prot_type = dev->dev_attrib.pi_prot_type; + ios->prot_length = dev->prot_length * + (le16_to_cpu (req->cmd->rw.length) +1 ); +#if 0 +printk ("req->cmd->rw.length: %u\n" ,le16_to_cpu (req->cmd->rw.length)); +printk ("nvmet_rw_len: %u\n" ,nvmet_rw_len (req)); +printk ("req->se_cmd.prot_type: %d\n" , req->se_cmd.prot_type); +printk ("req->se_cmd.prot_length: %u\n" , req->se_cmd.prot_length); +#endif } - cookie =submit_bio (rw, bio); + ios->se_dev = dev; + ios->iomem = iomem; + ios->t_comp_func = &nvmet_complete_ios; -blk_poll (bdev_get_queue (req->ns->bdev), cookie); -#endif + rc = sbc_ops->execute_rw (ios, iomem->t_data_sg, iomem->t_data_nents, + ios->data_direction, fua_write, + &nvmet_complete_ios); }static void nvmet_execute_flush (struct nvmet_req *req)
drivers/nvme/target/nvmet.h +7 -0
@@ -25,6 +25,7 @@#include <linux/configfs.h> #include <linux/rcupdate.h> #include <linux/blkdev.h> +#include <target/target_core_base.h> #define NVMET_ASYNC_EVENTS 4#define NVMET_ERROR_LOG_SLOTS 128
@@ -233,6 +234,12 @@ struct nvmet_req {int sg_cnt;size_t data_len; +struct scatterlist *prot_sg; +int prot_sg_cnt; + +struct target_iostate t_iostate; +struct target_iomem t_iomem; +struct nvmet_port *port;void (*execute)(struct nvmet_req *req);
Signature · 1 line
1.9.1
RFC 5/8 nvmet/io-cmd: Hookup sbc_ops->execute_sync_cache backend ops
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch converts nvmet_execute_flush() to utilize sbc_ops->execute_sync_cache() for target_iostate submission into existing backends drivers via configfs in /sys/kernel/config/target/core/.
--- drivers/nvme/target/io-cmd.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/nvme/target/io-cmd.c +12 -9
@@ -109,18 +109,21 @@ static void nvmet_execute_rw(struct nvmet_req *req)static void nvmet_execute_flush (struct nvmet_req *req) { -#if 0 -struct bio *bio; +struct target_iostate *ios = &req->t_iostate; +struct se_device *dev =rcu_dereference_raw (req->ns->dev); +struct sbc_ops *sbc_ops = dev->transport->sbc_ops; +sense_reason_t rc; -nvmet_inline_bio_init (req); - bio = &req->inline_bio; +if (!sbc_ops || !sbc_ops->execute_sync_cache) { +nvmet_req_complete (req,NVME_SC_INTERNAL |NVME_SC_DNR ); +return ; + } - bio->bi_bdev = req->ns->bdev; - bio->bi_private = req; - bio->bi_end_io = nvmet_bio_done; + ios->se_dev = dev; + ios->iomem =NULL ; + ios->t_comp_func = &nvmet_complete_ios; -submit_bio (WRITE_FLUSH , bio); -#endif + rc = sbc_ops->execute_sync_cache (ios, false); }#if 0
Signature · 1 line
1.9.1
RFC 6/8 nvmet/io-cmd: Hookup sbc_ops->execute_unmap backend ops
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch converts nvmet_execute_discard() to utilize sbc_ops->execute_unmap() for target_iostate submission into existing backends drivers via configfs in /sys/kernel/config/target/core/.
--- drivers/nvme/target/io-cmd.c | 47 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-)
drivers/nvme/target/io-cmd.c +34 -13
@@ -126,52 +126,73 @@ static void nvmet_execute_flush(struct nvmet_req *req) rc = sbc_ops->execute_sync_cache (ios, false); } -#if 0 -static u16 nvmet_discard_range (struct nvmet_ns *ns, -struct nvme_dsm_range *range,int type,struct bio **bio) +static u16 nvmet_discard_range (struct nvmet_req *req,struct sbc_ops *sbc_ops, +struct nvme_dsm_range *range,struct bio **bio) { -if (__blkdev_issue_discard (ns->bdev, +struct nvmet_ns *ns = req->ns; +sense_reason_t rc; + + rc = sbc_ops->execute_unmap (&req->t_iostate,le64_to_cpu (range->slba) << (ns->blksize_shift -9 ),le32_to_cpu (range->nlb) << (ns->blksize_shift -9 ), -GFP_KERNEL , type, bio)) + bio); +if (rc)return NVME_SC_INTERNAL |NVME_SC_DNR ;return 0 ; } -#endif + +static void nvmet_discard_bio_done (struct bio *bio) +{ +struct nvmet_req *req = bio->bi_private; +int err = bio->bi_error; + +bio_put (bio); +nvmet_req_complete (req, err ?NVME_SC_INTERNAL |NVME_SC_DNR :0 ); +}static void nvmet_execute_discard (struct nvmet_req *req) { -#if 0 -struct nvme_dsm_range range; +struct target_iostate *ios = &req->t_iostate; +struct se_device *dev =rcu_dereference_raw (req->ns->dev); +struct sbc_ops *sbc_ops = dev->transport->sbc_ops;struct bio *bio =NULL ; -int type =REQ_WRITE |REQ_DISCARD , i; +struct nvme_dsm_range range; +int i;u16 status; +if (!sbc_ops || !sbc_ops->execute_unmap) { +nvmet_req_complete (req,NVME_SC_INTERNAL |NVME_SC_DNR ); +return ; + } + + ios->se_dev = dev; + ios->iomem =NULL ; + ios->t_comp_func =NULL ; +for (i =0 ; i <=le32_to_cpu (req->cmd->dsm.nr); i++) { status =nvmet_copy_from_sgl (req, i *sizeof (range), &range,sizeof (range));if (status)break ; - status =nvmet_discard_range (req->ns, &range, type, &bio); + status =nvmet_discard_range (req, sbc_ops, &range, &bio);if (status)break ; }if (bio) { bio->bi_private = req; - bio->bi_end_io = nvmet_bio_done; + bio->bi_end_io = nvmet_discard_bio_done;if (status) { bio->bi_error = -EIO ;bio_endio (bio); }else { -submit_bio (type, bio); +submit_bio (REQ_WRITE |REQ_DISCARD , bio); } }else {nvmet_req_complete (req, status); } -#endif }static void nvmet_execute_dsm (struct nvmet_req *req)
Signature · 1 line
1.9.1
RFC 7/8 nvmet/admin-cmd: Hookup T10-PI to ID_NS.ms + ID_NS.dps feature bits
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch updates nvmet_execute_identify_ns() to report target-core backend T10-PI related feature bits to the NVMe host controller.
Note this assumes support for NVME_NS_DPC_PI_TYPE1 and NVME_NS_DPC_PI_TYPE3 as reported by backend drivers via /sys/kernel/config/target/core/*/*/attrib/pi_prot_type.
--- drivers/nvme/target/admin-cmd.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/nvme/target/admin-cmd.c +17 -0
@@ -200,6 +200,7 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req) {struct nvmet_ns *ns;struct nvme_id_ns *id; +struct se_device *dev;u16 status =0 ; ns =nvmet_find_namespace (req->sq->ctrl, req->cmd->identify.nsid);
@@ -228,6 +229,22 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req) id->nlbaf =0 ; id->flbas =0 ; +/* Populate bits for T10-PI from se_device backend */ +rcu_read_lock (); + dev =rcu_dereference (ns->dev); +if (dev && dev->dev_attrib.pi_prot_type) { +int pi_prot_type = dev->dev_attrib.pi_prot_type; + + id->lbaf[0 ].ms =cpu_to_le16 (sizeof (struct t10_pi_tuple )); +printk ("nvmet_set_id_ns: ms: %u\n" , id->lbaf[0 ].ms); + +if (pi_prot_type ==1 ) + id->dps =NVME_NS_DPC_PI_TYPE1 ; +else if (pi_prot_type ==3 ) + id->dps =NVME_NS_DPC_PI_TYPE3 ; + } +rcu_read_unlock (); +/* * Our namespace might always be shared. Not just with other * controllers, but also with any other user of the block device.
Signature · 1 line
1.9.1
Christoph Hellwig
maintainerRFC 7/8 nvmet/admin-cmd: Hookup T10-PI to ID_NS.ms + ID_NS.dps feature bits
FYI: NVMf requires metadata to be interleaved in the data, and you need to indicate that in the Identify data. Note that this is only a requirement for the on the wire format and for the way the Namespaces are exposed at the protocol level as RDMA HCA and FB HBAs should still be able to handle our separate SGL.
RFC 7/8 nvmet/admin-cmd: Hookup T10-PI to ID_NS.ms + ID_NS.dps feature bits
Quoted 5 lines · Christoph Hellwig
FYI: NVMf requires metadata to be interleaved in the data, and you need to indicate that in the Identify data. Note that this is only a requirement for the on the wire format and for the way the Namespaces are exposed at the protocol level as RDMA HCA and FB HBAs should still be able to handle our separate SGL.
Btw, nvmet needs something similar for controller creation, like how target_port_op works with target_alloc_session(), so hw capabilities can signal to host controllers when PI should be enabled for a namespace, but actual namespace backends don't support it.
Eg: TARGET_PROT_DOUT_STRIP and TARGET_PROT_DIN_INSERT ops
RFC 8/8 nvme/loop: Add support for bio integrity handling
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch adds support for nvme/loop block integrity, based upon the reported ID_NS.ms + ID_NS.dps feature bits in nvmet_execute_identify_ns().
--- drivers/nvme/target/loop.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/nvme/target/loop.c +19 -0
@@ -42,6 +42,7 @@ struct nvme_loop_iod {struct nvme_loop_queue *queue;struct work_struct work;struct sg_table sg_table; +struct scatterlist meta_sg;struct scatterlist first_sgl[]; };
@@ -193,6 +194,24 @@ static int nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx,BUG_ON (iod->req.sg_cnt > req->nr_phys_segments); } +if (blk_integrity_rq (req)) { +int count; + +if (blk_rq_count_integrity_sg (hctx->queue, req->bio) !=1 ) +BUG_ON (1 ); + +sg_init_table (&iod->meta_sg,1 ); + count =blk_rq_map_integrity_sg (hctx->queue, req->bio, + &iod->meta_sg); + + iod->req.prot_sg = &iod->meta_sg; + iod->req.prot_sg_cnt =1 ; +#if 0 +printk ("nvme/loop: Set prot_sg %p and prot_sg_cnt: %d\n" , + iod->req.prot_sg, iod->req.prot_sg_cnt); +#endif + } + iod->cmd.common.command_id = req->tag;blk_mq_start_request (req);
Signature · 1 line
1.9.1