From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/nvme/target/io-cmd-file.c

Change-Id: I37d9f4cc3591c88ef8883dac99c10a9dcd5d3c49
---
 drivers/nvme/target/io-cmd-file.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -4,6 +4,7 @@
  * Copyright (c) 2017-2018 Western Digital Corporation or its
  * affiliates.
  */
+#ifdef HAVE_FS_HAS_KIOCB
 #ifdef pr_fmt
 #undef pr_fmt
 #endif
@@ -22,8 +23,12 @@ int nvmet_file_ns_revalidate(struct nvme
 	struct kstat stat;
 	int ret;
 
+#ifdef HAVE_VFS_GETATTR_HAS_4_PARAMS
 	ret = vfs_getattr(&ns->file->f_path, &stat, STATX_SIZE,
 			  AT_STATX_FORCE_SYNC);
+#else
+	ret = vfs_getattr(&ns->file->f_path, &stat);
+#endif
 	if (!ret)
 		ns->size = stat.size;
 	return ret;
@@ -120,7 +125,11 @@ static ssize_t nvmet_file_submit_bvec(st
 		rw = READ;
 	}
 
+#ifdef HAVE_IOV_ITER_IS_BVEC_SET
 	iov_iter_bvec(&iter, rw, req->f.bvec, nr_segs, count);
+#else
+	iov_iter_bvec(&iter, ITER_BVEC | rw, req->f.bvec, nr_segs, count);
+#endif
 
 	iocb->ki_pos = pos;
 	iocb->ki_filp = req->ns->file;
@@ -129,7 +138,11 @@ static ssize_t nvmet_file_submit_bvec(st
 	return call_iter(iocb, &iter);
 }
 
+#ifdef HAVE_FS_KIOCB_KI_COMPLETE_2_ARG
 static void nvmet_file_io_done(struct kiocb *iocb, long ret)
+#else
+static void nvmet_file_io_done(struct kiocb *iocb, long ret, long ret2)
+#endif
 {
 	struct nvmet_req *req = container_of(iocb, struct nvmet_req, f.iocb);
 	u16 status = NVME_SC_SUCCESS;
@@ -202,7 +215,9 @@ static bool nvmet_file_execute_io(struct
 	 * A NULL ki_complete ask for synchronous execution, which we want
 	 * for the IOCB_NOWAIT case.
 	 */
+#ifdef HAVE_IOCB_NOWAIT
 	if (!(ki_flags & IOCB_NOWAIT))
+#endif
 		req->f.iocb.ki_complete = nvmet_file_io_done;
 
 	ret = nvmet_file_submit_bvec(req, pos, bv_cnt, total_len, ki_flags);
@@ -210,6 +225,7 @@ static bool nvmet_file_execute_io(struct
 	switch (ret) {
 	case -EIOCBQUEUED:
 		return true;
+#ifdef HAVE_IOCB_NOWAIT
 	case -EAGAIN:
 		if (WARN_ON_ONCE(!(ki_flags & IOCB_NOWAIT)))
 			goto complete;
@@ -223,10 +239,15 @@ static bool nvmet_file_execute_io(struct
 		if ((ki_flags & IOCB_NOWAIT))
 			return false;
 		break;
+#endif
 	}
 
 complete:
+#ifdef HAVE_FS_KIOCB_KI_COMPLETE_2_ARG
 	nvmet_file_io_done(&req->f.iocb, ret);
+#else
+	nvmet_file_io_done(&req->f.iocb, ret, 0);
+#endif
 	return true;
 }
 
@@ -269,10 +290,14 @@ static void nvmet_file_execute_rw(struct
 		req->f.mpool_alloc = false;
 
 	if (req->ns->buffered_io) {
+#ifdef HAVE_IOCB_NOWAIT
 		if (likely(!req->f.mpool_alloc) &&
+#ifdef HAVE_FMODE_NOWAIT
 		    (req->ns->file->f_mode & FMODE_NOWAIT) &&
+#endif
 		    nvmet_file_execute_io(req, IOCB_NOWAIT))
 			return;
+#endif
 		nvmet_file_submit_buffered_io(req);
 	} else
 		nvmet_file_execute_io(req, 0);
@@ -408,3 +433,4 @@ u16 nvmet_file_parse_io_cmd(struct nvmet
 		return nvmet_report_invalid_opcode(req);
 	}
 }
+#endif /* HAVE_FS_HAS_KIOCB */
