Skip to contentSkip to conversation

nvmet: add simple file backed ns support

PATCH Superseded Chaitanya Kulkarni 3 participants 4 messages May 10, 2018 – May 14, 2018

Subsystems (2)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 nvmet: add simple file backed ns support

This patch adds simple file backed namespace support for NVMeOF target.

In current implementation NVMeOF supports block device backed namespaces on the target side. With this implementation regular file(s) can be used to initialize the namespace(s) via target side configfs interface.

For admin smart log command on the target side, we only use block device backed namespaces to compute target side smart log.

We isolate the code for each ns handle type (file/block device) and add wrapper routines to manipulate the respective ns handle types.

Signed-off-by Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>

---
Changes since V3:-

1. Fix the comment in the smart-log target code.
2. Change suffix from blk to blkdev.
3. Get rid of flags variable in nvmet_ns_enable_[blkdev|file]().
4. Skip the error print when path is not block device for nvmet_ns_enable_blkkdev().
5. Return PTR_ERR if blkdev open fails.
6. Remove NULL check after filp_open() and return PTR_ERR on filp_open() error.
7. Use AT_STATX_FORCE_SYNC and STATX_SIZE for vfs_getattr().
8. Separate line for each assignment
9. Remove new lines before return.
10. Remove nvmet_ns_dev_enable() and call nvmet_ns_enable_[blkdev|file]() to enable ns handle from nvmet_ns_enable().
11. Use workqueue for discard and write zeroes.
12. Separate the block device and file parsing commands.
13. Move #include <linux/file.h> core.c (needed for fput) and

    #include <linux/falloc.h> io-cmd.c from nvmet.h.

14. Unionize file and block device handles.
15. Only initialize iocb for file IO.
16. Add WARN_ON_ONCE() in nvmet_ns_dev_disable().

Note :- Replacing kmalloc_array() with bvec_alloc() is not done in this version, as discusison is in progress.

Changes since V2:-

1. Adjust this patch for 4.17.0-rc4.

Changes since V1:-

1. Replace filp to file, filp_close to fput, call_[read|write]_iter() to [read|write]_iter().
2. Add code for the offloading flush operation for file-backed ns.
3. Aggregate the patches for O_DIRECT implementation.
4. Use inline bvec for smaller I/Os for file-backed ns.
5. Use file_inode() instead of open coding.
6. Get rid of bvec calculation macro and use DIV_ROUND_UP for the number of bvec calculation.
7. Avoid multiplication on the IO code patch.
8. Remove the req->bvec = NULL in IO completion callback.
9. Remove the sg mapping iterator and use simple for_each_sg_page() to iterate the pages.

---
 drivers/nvme/target/admin-cmd.c |   9 ++
 drivers/nvme/target/core.c      |  87 +++++++++++---
 drivers/nvme/target/io-cmd.c    | 246 +++++++++++++++++++++++++++++++++++++---
 drivers/nvme/target/nvmet.h     |  19 +++-
 4 files changed, 327 insertions(+), 34 deletions(-)
drivers/nvme/target/admin-cmd.c +9 -0
index 5e0e9fc..f88c83d 100644
@@ -45,6 +45,10 @@ static u16 nvmet_get_smart_log_nsid(struct nvmet_req *req,
 		return NVME_SC_INVALID_NS;
 	}
 
+	/* we don't have the right data for file backed ns */
+	if (!ns->bdev)
+		goto out;
+
 	host_reads = part_stat_read(ns->bdev->bd_part, ios[READ]);
 	data_units_read = part_stat_read(ns->bdev->bd_part, sectors[READ]);
 	host_writes = part_stat_read(ns->bdev->bd_part, ios[WRITE]);
@@ -54,6 +58,8 @@ static u16 nvmet_get_smart_log_nsid(struct nvmet_req *req,
 	put_unaligned_le64(data_units_read, &slog->data_units_read[0]);
 	put_unaligned_le64(host_writes, &slog->host_writes[0]);
 	put_unaligned_le64(data_units_written, &slog->data_units_written[0]);
+
+out:
 	nvmet_put_namespace(ns);
 
 	return NVME_SC_SUCCESS;
@@ -71,6 +77,9 @@ static u16 nvmet_get_smart_log_all(struct nvmet_req *req,
 
 	rcu_read_lock();
 	list_for_each_entry_rcu(ns, &ctrl->subsys->namespaces, dev_link) {
+		/* we don't have the right data for file backed ns */
+		if (!ns->bdev)
+			continue;
 		host_reads += part_stat_read(ns->bdev->bd_part, ios[READ]);
 		data_units_read +=
 			part_stat_read(ns->bdev->bd_part, sectors[READ]);
drivers/nvme/target/core.c +70 -17

122 lines not on this page · raw message

drivers/nvme/target/io-cmd.c +230 -16

301 lines not on this page · raw message

drivers/nvme/target/nvmet.h +18 -1
index 15fd84a..5a91d9b 100644
@@ -43,6 +43,7 @@ struct nvmet_ns {
 	struct list_head	dev_link;
 	struct percpu_ref	ref;
 	struct block_device	*bdev;
+	struct file		*file;
 	u32			nsid;
 	u32			blksize_shift;
 	loff_t			size;
@@ -215,6 +216,22 @@ struct nvmet_fabrics_ops {
 
 #define NVMET_MAX_INLINE_BIOVEC	8
 
+
+struct nvmet_ns_bdev_handle {
+	struct bio		inline_bio;
+};
+
+struct nvmet_ns_file_handle {
+	struct kiocb		iocb;
+	struct bio_vec		*bvec;
+	struct work_struct	io_work;
+};
+
+union ns_handle {
+	struct nvmet_ns_bdev_handle	b;
+	struct nvmet_ns_file_handle	f;
+};
+
 struct nvmet_req {
 	struct nvme_command	*cmd;
 	struct nvme_completion	*rsp;
@@ -222,8 +239,8 @@ struct nvmet_req {
 	struct nvmet_cq		*cq;
 	struct nvmet_ns		*ns;
 	struct scatterlist	*sg;
-	struct bio		inline_bio;
 	struct bio_vec		inline_bvec[NVMET_MAX_INLINE_BIOVEC];
+	union  ns_handle	handle;
 	int			sg_cnt;
 	/* data length as parsed from the command: */
 	size_t			data_len;
Signature · 1 line
2.9.5
#1 lore raw

PATCH v4 1/1 nvmet: add simple file backed ns support

Quoted 9 lines · Chaitanya Kulkarni

This patch adds simple file backed namespace support for NVMeOF target.

In current implementation NVMeOF supports block device backed namespaces on the target side. With this implementation regular file(s) can be used to initialize the namespace(s) via target side configfs interface.

Quoted 7 lines

For admin smart log command on the target side, we only use block device backed namespaces to compute target side smart log.

We isolate the code for each ns handle type (file/block device) and add wrapper routines to manipulate the respective ns handle types.

Please use up to 75 characters per line for your changelog.

drivers/nvme/target/io-cmd.c

Quoted 4 lines
drivers/nvme/target/io-cmd.c +0 -0
index cd23441..a5f787b 100644

Btw, I think now that the file code doesn't really reuse any block code maybe it is a better idea to have a separate io-cmd-file.c file after all. I had initially envisioned the file code reusing the bio for the bvec allocation, but without that there is basically no code sharing left.

Quoted 6 lines
drivers/nvme/target/io-cmd.c +6 -0
+static void nvmet_execute_rw_file(struct nvmet_req *req)
+{
+	int rw = req->cmd->rw.opcode == nvme_cmd_write ? WRITE : READ;
+	u32 nr_bvec = DIV_ROUND_UP(req->data_len, PAGE_SIZE);
+	struct sg_page_iter sg_pg_iter;
+	struct bio_vec *bvec;

drivers/nvme/target/io-cmd.c static void nvmet_execute_rw(struct nvmet_req *req) · line 133

Quoted 10 lines
drivers/nvme/target/io-cmd.c +10 -0
+	struct iov_iter iter;
+	struct kiocb *iocb;
+	ssize_t len = 0, ret;
+	int bv_cnt = 0;
+	loff_t pos;
+
+	bvec = req->inline_bvec;
+	if (nr_bvec > NVMET_MAX_INLINE_BIOVEC) {
+		bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec),
+				GFP_KERNEL);

So we still don't have the mempool or anything guaranteeing forward progress here.

Quoted 18 lines
drivers/nvme/target/io-cmd.c +18 -0
+u16 nvmet_parse_io_cmd_file(struct nvmet_req *req)
+{
+	struct nvme_command *cmd = req->cmd;
+
+	switch (cmd->common.opcode) {
+	case nvme_cmd_read:
+	case nvme_cmd_write:
+		req->handle.f.bvec = NULL;
+		memset(&req->handle.f.iocb, 0, sizeof(req->handle.f.iocb));
+		req->execute = nvmet_execute_rw_file;
+		req->data_len = nvmet_rw_len(req);
+		return 0;
+	case nvme_cmd_flush:
+		req->execute = nvmet_execute_flush_file;
+		INIT_WORK(&req->handle.f.io_work, nvmet_flush_work_file);
+		req->data_len = 0;
+		return 0;
+	case nvme_cmd_dsm:

drivers/nvme/target/io-cmd.c u16 nvmet_parse_io_cmd(struct nvmet_req *req) · line 416

Quoted 10 lines
drivers/nvme/target/io-cmd.c +10 -0
+		INIT_WORK(&req->handle.f.io_work, nvmet_dsm_work_file);
+		req->execute = nvmet_execute_dsm_file;
+		req->data_len = (le32_to_cpu(cmd->dsm.nr) + 1) *
+			sizeof(struct nvme_dsm_range);
+		return 0;
+	case nvme_cmd_write_zeroes:
+		INIT_WORK(&req->handle.f.io_work, nvmet_write_zeroes_work_file);
+		req->execute = nvmet_execute_write_zeroes_file;
+		req->data_len = 0;
+		return 0;

I'd be tempted to keep the INIT_WORK and memset calls in the actual handlers and leave this as a pure dispatcher just setting the execute callbacl and the data_len.

drivers/nvme/target/io-cmd.c struct nvmet_req { · line 243

Quoted 7 lines
drivers/nvme/target/io-cmd.c +1 -1
@@ -222,8 +239,8 @@ struct nvmet_req {
 	struct nvmet_cq		*cq;
 	struct nvmet_ns		*ns;
 	struct scatterlist	*sg;
-	struct bio		inline_bio;
 	struct bio_vec		inline_bvec[NVMET_MAX_INLINE_BIOVEC];
+	union  ns_handle	handle;

Can you just make this an anonymous union so that identifiers stay short and crispy?

#2 lore raw

PATCH v4 1/1 nvmet: add simple file backed ns support

Quoted 14 lines · Christoph Hellwig
Quoted 13 lines · Chaitanya Kulkarni

This patch adds simple file backed namespace support for NVMeOF target.

In current implementation NVMeOF supports block device backed namespaces on the target side. With this implementation regular file(s) can be used to initialize the namespace(s) via target side configfs interface.

For admin smart log command on the target side, we only use block device backed namespaces to compute target side smart log.

Quoted 5 lines
Quoted 3 lines

We isolate the code for each ns handle type (file/block device) and add wrapper routines to manipulate the respective ns handle types.

Please use up to 75 characters per line for your changelog.

Okay, checkpatch.pl didn't complain, I'll keep in mind.

Quoted 12 lines

drivers/nvme/target/io-cmd.c

Quoted 5 lines
drivers/nvme/target/io-cmd.c +0 -0
index cd23441..a5f787b 100644

Btw, I think now that the file code doesn't really reuse any block code maybe it is a better idea to have a separate io-cmd-file.c file after all. I had initially envisioned the file code reusing the bio for the bvec allocation, but without that there is basically no code sharing left.

Sounds good.

Quoted 11 lines
Quoted 11 lines
drivers/nvme/target/io-cmd.c +11 -0
+static void nvmet_execute_rw_file(struct nvmet_req *req)
+{
+     int rw = req->cmd->rw.opcode == nvme_cmd_write ? WRITE : READ;
+     u32 nr_bvec = DIV_ROUND_UP(req->data_len, PAGE_SIZE);
+     struct sg_page_iter sg_pg_iter;
+     struct bio_vec *bvec;
+     struct iov_iter iter;
+     struct kiocb *iocb;
+     ssize_t len = 0, ret;
+     int bv_cnt = 0;
+     loff_t pos;
Quoted 9 lines

drivers/nvme/target/io-cmd.c static void nvmet_execute_rw(struct nvmet_req *req) · line 133

Quoted 5 lines
drivers/nvme/target/io-cmd.c +5 -0
+
+     bvec = req->inline_bvec;
+     if (nr_bvec > NVMET_MAX_INLINE_BIOVEC) {
+             bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec),
+                             GFP_KERNEL);

So we still don't have the mempool or anything guaranteeing forward progress here.

I was actually debating if we can export bvec_alloc instead of allocating bios given that for the file read/write interface which we are using here is actually based on the bvec and allocation function is available with global
mempool as per the earlier suggestion.

Quoted 24 lines
Quoted 24 lines
drivers/nvme/target/io-cmd.c +24 -0
+u16 nvmet_parse_io_cmd_file(struct nvmet_req *req)
+{
+     struct nvme_command *cmd = req->cmd;
+
+     switch (cmd->common.opcode) {
+     case nvme_cmd_read:
+     case nvme_cmd_write:
+             req->handle.f.bvec = NULL;
+             memset(&req->handle.f.iocb, 0, sizeof(req->handle.f.iocb));
+             req->execute = nvmet_execute_rw_file;
+             req->data_len = nvmet_rw_len(req);
+             return 0;
+     case nvme_cmd_flush:
+             req->execute = nvmet_execute_flush_file;
+             INIT_WORK(&req->handle.f.io_work, nvmet_flush_work_file);
+             req->data_len = 0;
+             return 0;
+     case nvme_cmd_dsm:
+             INIT_WORK(&req->handle.f.io_work, nvmet_dsm_work_file);
+             req->execute = nvmet_execute_dsm_file;
+             req->data_len = (le32_to_cpu(cmd->dsm.nr) + 1) *
+                     sizeof(struct nvme_dsm_range);
+             return 0;
+     case nvme_cmd_write_zeroes:
Quoted 9 lines

drivers/nvme/target/io-cmd.c u16 nvmet_parse_io_cmd(struct nvmet_req *req) · line 416

Quoted 4 lines
drivers/nvme/target/io-cmd.c +4 -0
+             INIT_WORK(&req->handle.f.io_work, nvmet_write_zeroes_work_file);
+             req->execute = nvmet_execute_write_zeroes_file;
+             req->data_len = 0;
+             return 0;

I'd be tempted to keep the INIT_WORK and memset calls in the actual handlers and leave this as a pure dispatcher just setting the execute callbacl and the data_len.

Sounds, good.

Quoted 11 lines

drivers/nvme/target/io-cmd.c struct nvmet_req { · line 243

Quoted 7 lines
drivers/nvme/target/io-cmd.c +1 -1
@@ -222,8 +239,8 @@ struct nvmet_req {
      struct nvmet_cq         *cq;
      struct nvmet_ns         *ns;
      struct scatterlist      *sg;
-     struct bio              inline_bio;
      struct bio_vec          inline_bvec[NVMET_MAX_INLINE_BIOVEC];
+     union  ns_handle        handle;

Can you just make this an anonymous union so that identifiers stay short and crispy?

I was not able to find a way to use container_of with anonymous unions so kept the code without anonymous unions for now.

Quoted 4 lines

_______________________________________________
Linux-nvme mailing list
Linux-nvme at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

#3 lore raw

PATCH v4 1/1 nvmet: add simple file backed ns support

Quoted 6 lines · chaitany kulkarni
Quoted 3 lines

Can you just make this an anonymous union so that identifiers stay short and crispy?

I was not able to find a way to use container_of with anonymous unions so kept the code without anonymous unions for now.

Relative patch to your below that uses an anonymous union:

drivers/nvme/target/io-cmd.c +28 -43
index a5f787b21a75..b0550737e39e 100644
@@ -19,15 +19,6 @@
 
 #include "nvmet.h"
 
-static struct nvmet_req *nvmet_get_req_from_work(struct work_struct *w)
-{
-	struct nvmet_ns_file_handle *f =
-		container_of(w, struct nvmet_ns_file_handle, io_work);
-	union ns_handle *u =  container_of(f, union ns_handle, f);
-
-	return container_of(u, struct nvmet_req, handle);
-}
-
 static void nvmet_bio_done(struct bio *bio)
 {
 	struct nvmet_req *req = bio->bi_private;
@@ -35,7 +26,7 @@ static void nvmet_bio_done(struct bio *bio)
 	nvmet_req_complete(req,
 		bio->bi_status ? NVME_SC_INTERNAL | NVME_SC_DNR : 0);
 
-	if (bio != &req->handle.b.inline_bio)
+	if (bio != &req->b.inline_bio)
 		bio_put(bio);
 }
 
@@ -48,7 +39,7 @@ static inline u32 nvmet_rw_len(struct nvmet_req *req)
 static void nvmet_execute_rw(struct nvmet_req *req)
 {
 	int sg_cnt = req->sg_cnt;
-	struct bio *bio = &req->handle.b.inline_bio;
+	struct bio *bio = &req->b.inline_bio;
 	struct scatterlist *sg;
 	sector_t sector;
 	blk_qc_t cookie;
@@ -103,13 +94,10 @@ static void nvmet_execute_rw(struct nvmet_req *req)
 
 static void nvmet_file_io_complete(struct kiocb *iocb, long ret, long ret2)
 {
-	struct nvmet_ns_file_handle *f =
-		container_of(iocb, struct nvmet_ns_file_handle, iocb);
-	union ns_handle *u =  container_of(f, union ns_handle, f);
-	struct nvmet_req *req = container_of(u, struct nvmet_req, handle);
+	struct nvmet_req *req = container_of(iocb, struct nvmet_req, f.iocb);
 
-	if (req->handle.f.bvec != req->inline_bvec)
-		kfree(req->handle.f.bvec);
+	if (req->f.bvec != req->inline_bvec)
+		kfree(req->f.bvec);
 
 	nvmet_req_complete(req, ret != req->data_len ?
 			NVME_SC_INTERNAL | NVME_SC_DNR : 0);
@@ -120,36 +108,35 @@ static void nvmet_execute_rw_file(struct nvmet_req *req)
 	int rw = req->cmd->rw.opcode == nvme_cmd_write ? WRITE : READ;
 	u32 nr_bvec = DIV_ROUND_UP(req->data_len, PAGE_SIZE);
 	struct sg_page_iter sg_pg_iter;
-	struct bio_vec *bvec;
 	struct iov_iter iter;
-	struct kiocb *iocb;
+	struct kiocb *iocb = &req->f.iocb;
 	ssize_t len = 0, ret;
 	int bv_cnt = 0;
 	loff_t pos;
 
-	bvec = req->inline_bvec;
 	if (nr_bvec > NVMET_MAX_INLINE_BIOVEC) {
-		bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec),
+		req->f.bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec),
 				GFP_KERNEL);
-		if (!bvec)
+		if (!req->f.bvec)
 			goto out;
+	} else {
+		req->f.bvec = req->inline_bvec;
 	}
-	req->handle.f.bvec = bvec;
-	iocb = &req->handle.f.iocb;
 
 	for_each_sg_page(req->sg, &sg_pg_iter, req->sg_cnt, 0) {
-		bvec[bv_cnt].bv_page = sg_page_iter_page(&sg_pg_iter);
-		bvec[bv_cnt].bv_offset = sg_pg_iter.sg->offset;
-		bvec[bv_cnt].bv_len = PAGE_SIZE - sg_pg_iter.sg->offset;
-		len += bvec[bv_cnt].bv_len;
+		req->f.bvec[bv_cnt].bv_page = sg_page_iter_page(&sg_pg_iter);
+		req->f.bvec[bv_cnt].bv_offset = sg_pg_iter.sg->offset;
+		req->f.bvec[bv_cnt].bv_len = PAGE_SIZE - sg_pg_iter.sg->offset;
+		len += req->f.bvec[bv_cnt].bv_len;
 		bv_cnt++;
 	}
 
 	if (len != req->data_len)
 		goto free;
 
-	iov_iter_bvec(&iter, ITER_BVEC | rw, bvec, bv_cnt, len);
+	iov_iter_bvec(&iter, ITER_BVEC | rw, req->f.bvec, bv_cnt, len);
 	pos = le64_to_cpu(req->cmd->rw.slba) << req->ns->blksize_shift;
+	memset(iocb, 0, sizeof(*iocb));
 	iocb->ki_pos = pos;
 	iocb->ki_filp = req->ns->file;
 	iocb->ki_flags = IOCB_DIRECT;
@@ -166,15 +153,15 @@ static void nvmet_execute_rw_file(struct nvmet_req *req)
 		nvmet_file_io_complete(iocb, ret, 0);
 	return;
 free:
-	if (bvec != req->inline_bvec)
-		kfree(req->handle.f.bvec);
+	if (req->f.bvec != req->inline_bvec)
+		kfree(req->f.bvec);
 out:
 	nvmet_req_complete(req, NVME_SC_INTERNAL | NVME_SC_DNR);
 }
 
 static void nvmet_execute_flush(struct nvmet_req *req)
 {
-	struct bio *bio = &req->handle.b.inline_bio;
+	struct bio *bio = &req->b.inline_bio;
 
 	bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec));
 	bio_set_dev(bio, req->ns->bdev);
@@ -187,7 +174,7 @@ static void nvmet_execute_flush(struct nvmet_req *req)
 
 static void nvmet_flush_work_file(struct work_struct *w)
 {
-	struct nvmet_req *req = nvmet_get_req_from_work(w);
+	struct nvmet_req *req = container_of(w, struct nvmet_req, f.work);
 	u16 status = NVME_SC_SUCCESS;
 	int ret;
 
@@ -200,7 +187,8 @@ static void nvmet_flush_work_file(struct work_struct *w)
 
 static void nvmet_execute_flush_file(struct nvmet_req *req)
 {
-	schedule_work(&req->handle.f.io_work);
+	INIT_WORK(&req->f.work, nvmet_flush_work_file);
+	schedule_work(&req->f.work);
 }
 
 static u16 nvmet_discard_range(struct nvmet_ns *ns,
@@ -288,7 +276,7 @@ static void nvmet_execute_discard_file(struct nvmet_req *req)
 
 static void nvmet_dsm_work_file(struct work_struct *w)
 {
-	struct nvmet_req *req = nvmet_get_req_from_work(w);
+	struct nvmet_req *req = container_of(w, struct nvmet_req, f.work);
 
 	switch (le32_to_cpu(req->cmd->dsm.attributes)) {
 	case NVME_DSMGMT_AD:
@@ -305,7 +293,8 @@ static void nvmet_dsm_work_file(struct work_struct *w)
 
 static void nvmet_execute_dsm_file(struct nvmet_req *req)
 {
-	schedule_work(&req->handle.f.io_work);
+	INIT_WORK(&req->f.work, nvmet_dsm_work_file);
+	schedule_work(&req->f.work);
 }
 
 static void nvmet_execute_write_zeroes(struct nvmet_req *req)
@@ -336,7 +325,7 @@ static void nvmet_execute_write_zeroes(struct nvmet_req *req)
 
 static void nvmet_write_zeroes_work_file(struct work_struct *w)
 {
-	struct nvmet_req *req = nvmet_get_req_from_work(w);
+	struct nvmet_req *req = container_of(w, struct nvmet_req, f.work);
 	struct nvme_write_zeroes_cmd *write_zeroes = &req->cmd->write_zeroes;
 	int mode = FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE;
 	loff_t offset;
@@ -353,7 +342,8 @@ static void nvmet_write_zeroes_work_file(struct work_struct *w)
 
 static void nvmet_execute_write_zeroes_file(struct nvmet_req *req)
 {
-	schedule_work(&req->handle.f.io_work);
+	INIT_WORK(&req->f.work, nvmet_write_zeroes_work_file);
+	schedule_work(&req->f.work);
 }
 
 static u16 nvmet_parse_io_cmd_blkdev(struct nvmet_req *req)
@@ -393,24 +383,19 @@ u16 nvmet_parse_io_cmd_file(struct nvmet_req *req)
 	switch (cmd->common.opcode) {
 	case nvme_cmd_read:
 	case nvme_cmd_write:
-		req->handle.f.bvec = NULL;
-		memset(&req->handle.f.iocb, 0, sizeof(req->handle.f.iocb));
 		req->execute = nvmet_execute_rw_file;
 		req->data_len = nvmet_rw_len(req);
 		return 0;
 	case nvme_cmd_flush:
 		req->execute = nvmet_execute_flush_file;
-		INIT_WORK(&req->handle.f.io_work, nvmet_flush_work_file);
 		req->data_len = 0;
 		return 0;
 	case nvme_cmd_dsm:
-		INIT_WORK(&req->handle.f.io_work, nvmet_dsm_work_file);
 		req->execute = nvmet_execute_dsm_file;
 		req->data_len = (le32_to_cpu(cmd->dsm.nr) + 1) *
 			sizeof(struct nvme_dsm_range);
 		return 0;
 	case nvme_cmd_write_zeroes:
-		INIT_WORK(&req->handle.f.io_work, nvmet_write_zeroes_work_file);
 		req->execute = nvmet_execute_write_zeroes_file;
 		req->data_len = 0;
 		return 0;
drivers/nvme/target/nvmet.h +10 -17
index 5a91d9ba464b..04c76aa67e3c 100644
@@ -216,22 +216,6 @@ struct nvmet_fabrics_ops {
 
 #define NVMET_MAX_INLINE_BIOVEC	8
 
-
-struct nvmet_ns_bdev_handle {
-	struct bio		inline_bio;
-};
-
-struct nvmet_ns_file_handle {
-	struct kiocb		iocb;
-	struct bio_vec		*bvec;
-	struct work_struct	io_work;
-};
-
-union ns_handle {
-	struct nvmet_ns_bdev_handle	b;
-	struct nvmet_ns_file_handle	f;
-};
-
 struct nvmet_req {
 	struct nvme_command	*cmd;
 	struct nvme_completion	*rsp;
@@ -240,7 +224,16 @@ struct nvmet_req {
 	struct nvmet_ns		*ns;
 	struct scatterlist	*sg;
 	struct bio_vec		inline_bvec[NVMET_MAX_INLINE_BIOVEC];
-	union  ns_handle	handle;
+	union {
+		struct {
+			struct bio	inline_bio;
+		} b;
+		struct {
+			struct kiocb		iocb;
+			struct bio_vec		*bvec;
+			struct work_struct	work;
+		} f;
+	};
 	int			sg_cnt;
 	/* data length as parsed from the command: */
 	size_t			data_len;