All of lore.kernel.org
 help / color / mirror / Atom feed
From: Long Li <longli@linuxonhyperv.com>
To: Steve French <sfrench@samba.org>,
	linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
	linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org
Cc: Long Li <longli@microsoft.com>
Subject: [Patch v2 13/15] CIFS: Add support for direct I/O read
Date: Wed, 30 May 2018 12:48:05 -0700	[thread overview]
Message-ID: <20180530194807.31657-14-longli@linuxonhyperv.com> (raw)
In-Reply-To: <20180530194807.31657-1-longli@linuxonhyperv.com>

From: Long Li <longli@microsoft.com>

Implement the function for direct I/O read. It doesn't support AIO, which
will be implemented in a follow up patch.

Signed-off-by: Long Li <longli@microsoft.com>
---
 fs/cifs/cifsfs.h |   1 +
 fs/cifs/file.c   | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 150 insertions(+)

diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index 5f02318..7fba9aa 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -102,6 +102,7 @@ extern int cifs_open(struct inode *inode, struct file *file);
 extern int cifs_close(struct inode *inode, struct file *file);
 extern int cifs_closedir(struct inode *inode, struct file *file);
 extern ssize_t cifs_user_readv(struct kiocb *iocb, struct iov_iter *to);
+extern ssize_t cifs_direct_readv(struct kiocb *iocb, struct iov_iter *to);
 extern ssize_t cifs_strict_readv(struct kiocb *iocb, struct iov_iter *to);
 extern ssize_t cifs_user_writev(struct kiocb *iocb, struct iov_iter *from);
 extern ssize_t cifs_strict_writev(struct kiocb *iocb, struct iov_iter *from);
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 87eece6..e6e6f24 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2955,6 +2955,18 @@ cifs_read_allocate_pages(struct cifs_readdata *rdata, unsigned int nr_pages)
 	return rc;
 }
 
+static void cifs_direct_readdata_release(struct kref *refcount)
+{
+	struct cifs_readdata *rdata = container_of(refcount,
+					struct cifs_readdata, refcount);
+	unsigned int i;
+
+	for (i = 0; i < rdata->nr_pages; i++)
+		put_page(rdata->pages[i]);
+
+	cifs_readdata_release(refcount);
+}
+
 static void
 cifs_uncached_readdata_release(struct kref *refcount)
 {
@@ -3267,6 +3279,143 @@ collect_uncached_read_data(struct cifs_aio_ctx *ctx)
 		complete(&ctx->done);
 }
 
+static void cifs_direct_readv_complete(struct work_struct *work)
+{
+	struct cifs_readdata *rdata =
+		container_of(work, struct cifs_readdata, work);
+
+	complete(&rdata->done);
+	kref_put(&rdata->refcount, cifs_direct_readdata_release);
+}
+
+ssize_t cifs_direct_readv(struct kiocb *iocb, struct iov_iter *to)
+{
+	size_t len, cur_len, start;
+	unsigned int npages, rsize, credits;
+	struct file *file;
+	struct cifs_sb_info *cifs_sb;
+	struct cifsFileInfo *cfile;
+	struct cifs_tcon *tcon;
+	struct page **pagevec;
+	ssize_t rc, total_read = 0;
+	struct TCP_Server_Info *server;
+	loff_t offset = iocb->ki_pos;
+	pid_t pid;
+	struct cifs_readdata *rdata;
+
+	/*
+	 * iov_iter_get_pages_alloc() doesn't work with ITER_KVEC,
+	 * fall back to data copy read path
+	 */
+	if (to->type & ITER_KVEC) {
+		cifs_dbg(FYI, "use non-direct cifs_user_readv for kvec I/O\n");
+		return cifs_user_readv(iocb, to);
+	}
+
+	len = iov_iter_count(to);
+	if (!len)
+		return 0;
+
+	file = iocb->ki_filp;
+	cifs_sb = CIFS_FILE_SB(file);
+	cfile = file->private_data;
+	tcon = tlink_tcon(cfile->tlink);
+	server = tcon->ses->server;
+
+	if (!server->ops->async_readv)
+		return -ENOSYS;
+
+	if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
+		pid = cfile->pid;
+	else
+		pid = current->tgid;
+
+	if ((file->f_flags & O_ACCMODE) == O_WRONLY)
+		cifs_dbg(FYI, "attempting read on write only file instance\n");
+
+	do {
+		rc = server->ops->wait_mtu_credits(server, cifs_sb->rsize,
+					&rsize, &credits);
+		if (rc)
+			break;
+
+		cur_len = min_t(const size_t, len, rsize);
+
+		rc = iov_iter_get_pages_alloc(to, &pagevec, cur_len, &start);
+		if (rc < 0) {
+			cifs_dbg(VFS,
+				"couldn't get user pages (rc=%zd) iter type %d"
+				" iov_offset %lu count %lu\n",
+				rc, to->type, to->iov_offset, to->count);
+			dump_stack();
+			break;
+		}
+
+		rdata = cifs_readdata_direct_alloc(
+				pagevec, cifs_direct_readv_complete);
+		if (!rdata) {
+			add_credits_and_wake_if(server, credits, 0);
+			rc = -ENOMEM;
+			break;
+		}
+
+		npages = (rc + start + PAGE_SIZE-1) / PAGE_SIZE;
+		rdata->nr_pages = npages;
+		rdata->page_offset = start;
+		rdata->pagesz = PAGE_SIZE;
+		rdata->tailsz = npages > 1 ?
+				rc-(PAGE_SIZE-start)-(npages-2)*PAGE_SIZE :
+				rc;
+		cur_len = rc;
+
+		rdata->cfile = cifsFileInfo_get(cfile);
+		rdata->offset = offset;
+		rdata->bytes = rc;
+		rdata->pid = pid;
+		rdata->read_into_pages = cifs_uncached_read_into_pages;
+		rdata->copy_into_pages = cifs_uncached_copy_into_pages;
+		rdata->credits = credits;
+
+		rc = 0;
+		if (rdata->cfile->invalidHandle)
+			rc = cifs_reopen_file(rdata->cfile, true);
+
+		if (!rc)
+			rc = server->ops->async_readv(rdata);
+
+		if (rc) {
+			add_credits_and_wake_if(server, rdata->credits, 0);
+			kref_put(&rdata->refcount,
+				 cifs_direct_readdata_release);
+			if (rc == -EAGAIN)
+				continue;
+			break;
+		}
+
+		wait_for_completion(&rdata->done);
+		rc = rdata->result;
+		if (rc) {
+			kref_put(
+				&rdata->refcount,
+				cifs_direct_readdata_release);
+			if (rc == -EAGAIN)
+				continue;
+			break;
+		}
+
+		total_read += rdata->got_bytes;
+		kref_put(&rdata->refcount, cifs_direct_readdata_release);
+
+		iov_iter_advance(to, cur_len);
+		len -= cur_len;
+		offset += cur_len;
+	} while (len);
+
+	iocb->ki_pos += total_read;
+
+	return total_read;
+}
+
 ssize_t cifs_user_readv(struct kiocb *iocb, struct iov_iter *to)
 {
 	struct file *file = iocb->ki_filp;
-- 
2.7.4

  parent reply	other threads:[~2018-05-30 19:48 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-30 19:47 [Patch v2 00/15] CIFS: Add direct I/O support Long Li
2018-05-30 19:47 ` [Patch v2 01/15] CIFS: Introduce offset for the 1st page in data transfer structures Long Li
2018-05-30 19:47 ` [Patch v2 02/15] CIFS: Add support for direct pages in rdata Long Li
2018-05-30 20:27   ` Ruhl, Michael J
2018-05-30 20:57     ` Long Li
2018-06-24  1:50   ` Tom Talpey
2018-06-25 20:25     ` Long Li
2018-06-25 21:01     ` Jason Gunthorpe
2018-06-26 15:13       ` Tom Talpey
2018-06-27  3:21         ` Long Li
2018-05-30 19:47 ` [Patch v2 03/15] CIFS: Use offset when reading pages Long Li
2018-06-24  1:58   ` Tom Talpey
2018-06-25 20:27     ` Long Li
2018-05-30 19:47 ` [Patch v2 04/15] CIFS: Add support for direct pages in wdata Long Li
2018-06-24  2:01   ` Tom Talpey
2018-06-25 20:34     ` Long Li
2018-05-30 19:47 ` [Patch v2 05/15] CIFS: Calculate the correct request length based on page offset and tail size Long Li
2018-06-24  2:07   ` Tom Talpey
2018-06-25 21:07     ` Long Li
2018-05-30 19:47 ` [Patch v2 06/15] CIFS: Introduce helper function to get page offset and length in smb_rqst Long Li
2018-06-24  2:09   ` Tom Talpey
2018-06-25 21:14     ` Long Li
2018-06-26 13:16       ` Tom Talpey
2018-06-27  3:24         ` Long Li
2018-05-30 19:47 ` [Patch v2 07/15] CIFS: When sending data on socket, pass the correct page offset Long Li
2018-05-30 19:48 ` [Patch v2 08/15] CIFS: SMBD: Support page offset in RDMA send Long Li
2018-06-24  2:11   ` Tom Talpey
2018-06-25 21:23     ` Long Li
2018-05-30 19:48 ` [Patch v2 09/15] CIFS: SMBD: Support page offset in RDMA recv Long Li
2018-06-24  2:16   ` Tom Talpey
2018-06-25 21:29     ` Long Li
2018-05-30 19:48 ` [Patch v2 10/15] CIFS: SMBD: Support page offset in memory registration Long Li
2018-06-24  2:24   ` Tom Talpey
2018-05-30 19:48 ` [Patch v2 11/15] CIFS: Pass page offset for calculating signature Long Li
2018-06-24  2:27   ` Tom Talpey
2018-06-26  4:15     ` Long Li
2018-05-30 19:48 ` [Patch v2 12/15] CIFS: Pass page offset for encrypting Long Li
2018-06-24  2:28   ` Tom Talpey
2018-05-30 19:48 ` Long Li [this message]
2018-06-02  5:51   ` [Patch v2 13/15] CIFS: Add support for direct I/O read kbuild test robot
2018-06-02  7:15   ` kbuild test robot
2018-06-24  2:39   ` Tom Talpey
2018-06-26  4:34     ` Long Li
2018-05-30 19:48 ` [Patch v2 14/15] CIFS: Add support for direct I/O write Long Li
2018-06-24  2:48   ` Tom Talpey
2018-06-26  4:39     ` Long Li
2018-06-26 13:29       ` Tom Talpey
2018-06-27  3:44         ` Long Li
2018-05-30 19:48 ` [Patch v2 15/15] CIFS: Add direct I/O functions to file_operations Long Li
2018-06-07 11:17   ` Pavel Shilovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180530194807.31657-14-longli@linuxonhyperv.com \
    --to=longli@linuxonhyperv.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=longli@microsoft.com \
    --cc=samba-technical@lists.samba.org \
    --cc=sfrench@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.