linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thieu Le <thieule@chromium.org>
To: hch@infradead.org
Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, Thieu Le <thieule@chromium.org>
Subject: [PATCH] vfs: Export fallocate facility to kernel modules
Date: Wed,  2 Nov 2011 14:27:05 -0700	[thread overview]
Message-ID: <1320269225-18489-1-git-send-email-thieule@chromium.org> (raw)
In-Reply-To: <20111102075328.GA28954@infradead.org>

The patch below illustrates the use of vfs_allocate() by ecryptfs.

---

eCryptfs does not allocate space in the lower file until writepage.  In
low free space situation, this leads to the application thinking the
write succeeds but it actually fails later when the page is written out.
This patch preallocates the space in the write path using fallocate()
first.  For lower file systems that do not support fallocate(), it falls back
to writing the encrypted page directly to the lower file.  The
preallocation is only done for writes that extend the file.

Signed-off-by: Thieu Le <thieule@chromium.org>
---
 fs/ecryptfs/mmap.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 6a44148..ed0eace 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -520,9 +520,29 @@ static int ecryptfs_write_end(struct file *file,
 		goto out;
 	}
 	set_page_dirty(page);
-	unlock_page(page);
-	need_unlock_page = 0;
 	if (pos + copied > i_size_read(ecryptfs_inode)) {
+		struct ecryptfs_inode_info *inode_info =
+			ecryptfs_inode_to_private(ecryptfs_inode);
+		loff_t offset = ecryptfs_lower_header_size(crypt_stat) + pos;
+		BUG_ON(!inode_info->lower_file);
+		rc = vfs_fallocate(inode_info->lower_file, 0, offset,
+				   PAGE_CACHE_SIZE);
+		if (rc == -EOPNOTSUPP)
+			rc = ecryptfs_encrypt_page(page);
+		if (rc) {
+			if (rc != -ENOSPC) {
+				ecryptfs_printk(KERN_ERR,
+						"Error preallocating page "
+						"(upper index "
+						"[0x%.16lx], rc = [%d])\n",
+						index, rc);
+			}
+			goto out;
+		}
+
+		unlock_page(page);
+		need_unlock_page = 0;
+
 		i_size_write(ecryptfs_inode, pos + copied);
 		ecryptfs_printk(KERN_DEBUG, "Expanded file size to "
 			"[0x%.16llx]\n",
@@ -540,6 +560,8 @@ out:
 	if (need_unlock_page)
 		unlock_page(page);
 	page_cache_release(page);
+	if (rc)
+		truncate_inode_pages(mapping, i_size_read(ecryptfs_inode));
 	return rc;
 }
 
-- 
1.7.3.1


  reply	other threads:[~2011-11-02 21:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-31 19:14 [PATCH] vfs: Export fallocate facility to kernel modules Thieu Le
2011-11-02  7:53 ` Christoph Hellwig
2011-11-02 21:27   ` Thieu Le [this message]
2011-11-05 12:30 ` Tyler Hicks
2011-11-05 17:04   ` Tyler Hicks
2011-11-16 20:22     ` Thieu Le
2011-11-18 19:53       ` Tyler Hicks
2011-11-21 18:55         ` Thieu Le

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=1320269225-18489-1-git-send-email-thieule@chromium.org \
    --to=thieule@chromium.org \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).