mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxim Patlasov <mpatlasov@parallels.com>
To: miklos@szeredi.hu
Cc: fuse-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org,
	devel@openvz.org
Subject: [PATCH 5/6] fuse: rework fuse_perform_write()
Date: Fri, 07 Sep 2012 21:41:49 +0400	[thread overview]
Message-ID: <20120907174145.1343.35017.stgit@maximpc.sw.ru> (raw)
In-Reply-To: <20120907172536.1343.80497.stgit@maximpc.sw.ru>

The patch allocates as many page pointers in fuse_req as needed to cover
interval [pos .. pos+len-1]. FUSE_WR_PAGES macro is introduced to hide this
cumbersome arithmetics.
---
 fs/fuse/file.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 9a6dcc6..84cc83c 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -815,7 +815,8 @@ static size_t fuse_send_write_pages(struct fuse_req *req, struct file *file,
 
 static ssize_t fuse_fill_write_pages(struct fuse_req *req,
 			       struct address_space *mapping,
-			       struct iov_iter *ii, loff_t pos)
+			       struct iov_iter *ii, loff_t pos,
+			       unsigned nr_pages)
 {
 	struct fuse_conn *fc = get_fuse_conn(mapping->host);
 	unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
@@ -875,11 +876,16 @@ static ssize_t fuse_fill_write_pages(struct fuse_req *req,
 		if (!fc->big_writes)
 			break;
 	} while (iov_iter_count(ii) && count < fc->max_write &&
-		 req->num_pages < FUSE_MAX_PAGES_PER_REQ && offset == 0);
+		 req->num_pages < nr_pages && offset == 0);
 
 	return count > 0 ? count : err;
 }
 
+#define FUSE_WR_PAGES(pos, len) min_t(unsigned,				      \
+				      ((pos + len - 1) >> PAGE_CACHE_SHIFT) - \
+				      (pos >> PAGE_CACHE_SHIFT) + 1,	      \
+				      FUSE_MAX_PAGES_PER_REQ)
+
 static ssize_t fuse_perform_write(struct file *file,
 				  struct address_space *mapping,
 				  struct iov_iter *ii, loff_t pos)
@@ -895,14 +901,15 @@ static ssize_t fuse_perform_write(struct file *file,
 	do {
 		struct fuse_req *req;
 		ssize_t count;
+		unsigned nr_pages = FUSE_WR_PAGES(pos, iov_iter_count(ii));
 
-		req = fuse_get_req_multipage(fc, FUSE_MAX_PAGES_PER_REQ);
+		req = fuse_get_req_multipage(fc, nr_pages);
 		if (IS_ERR(req)) {
 			err = PTR_ERR(req);
 			break;
 		}
 
-		count = fuse_fill_write_pages(req, mapping, ii, pos);
+		count = fuse_fill_write_pages(req, mapping, ii, pos, nr_pages);
 		if (count <= 0) {
 			err = count;
 		} else {


  parent reply	other threads:[~2012-09-07 17:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-07 17:40 [PATCH 0/6] fuse: allocate req->pages[] dynamically Maxim Patlasov
2012-09-07 17:41 ` [PATCH 1/6] fuse: general infrastructure for pages[] of variable size Maxim Patlasov
2012-09-12 16:09   ` Miklos Szeredi
2012-09-07 17:41 ` [PATCH 2/6] fuse: categorize fuse_get_req() Maxim Patlasov
2012-09-12 16:20   ` Miklos Szeredi
2012-09-07 17:41 ` [PATCH 3/6] fuse: rework fuse_retrieve() Maxim Patlasov
2012-09-12 16:24   ` Miklos Szeredi
2012-09-07 17:41 ` [PATCH 4/6] fuse: rework fuse_readpages() Maxim Patlasov
2012-09-12 16:42   ` Miklos Szeredi
2012-09-07 17:41 ` Maxim Patlasov [this message]
2012-09-12 16:44   ` [PATCH 5/6] fuse: rework fuse_perform_write() Miklos Szeredi
2012-09-07 17:41 ` [PATCH 6/6] fuse: rework fuse_do_ioctl() Maxim Patlasov
2012-09-10 10:18 ` [PATCH 0/6] fuse: allocate req->pages[] dynamically Maxim V. Patlasov
2012-09-12 16:07 ` Maxim V. Patlasov
2012-09-12 16:49   ` Miklos Szeredi
2012-09-14 13:18     ` Maxim V. Patlasov
2012-09-14 14:39       ` Miklos Szeredi

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=20120907174145.1343.35017.stgit@maximpc.sw.ru \
    --to=mpatlasov@parallels.com \
    --cc=devel@openvz.org \
    --cc=fuse-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome