From: Hugh Dickins <hugh@veritas.com>
To: Erez Zadok <ezk@cs.sunysb.edu>
Cc: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] unionfs: fix truncation order
Date: Tue, 18 Dec 2007 22:14:58 +0000 (GMT) [thread overview]
Message-ID: <Pine.LNX.4.64.0712182214180.28390@blonde.wat.veritas.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0712182207400.28390@blonde.wat.veritas.com>
fsx-linux in a unionfs soon fails (with oops on tmpfs): truncation doesn't
work right.
When shrinking a file, unionfs_setattr needs to vmtruncate the upper level
before notifying change to the lower level, to eliminate those dirty pages
beyond new eof which otherwise drift down to the lower level's writepage,
writing beyond its eof (and later uncovered when the file is expanded).
Also truncate the upper level first when expanding, in the case when
the upper level's s_maxbytes is more limiting than the lower level's.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
---
fs/unionfs/inode.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
--- unionfs3/fs/unionfs/inode.c 2007-12-05 18:50:52.000000000 +0000
+++ unionfs4/fs/unionfs/inode.c 2007-12-05 18:58:51.000000000 +0000
@@ -1060,23 +1060,30 @@ static int unionfs_setattr(struct dentry
break;
}
}
+ lower_inode = unionfs_lower_inode(inode);
- err = notify_change(lower_dentry, ia);
- if (err)
- goto out;
-
- /* for mmap */
+ /*
+ * If shrinking, first truncate upper level to cancel writing dirty
+ * pages beyond the new eof; and also if its maxbytes is more limiting
+ * (fail with -EFBIG before making any change to the lower level).
+ * There is no need to vmtruncate the upper level afterwards in the
+ * other cases: we fsstack_copy_inode_size from the lower level.
+ */
if (ia->ia_valid & ATTR_SIZE) {
- if (ia->ia_size != i_size_read(inode)) {
+ size = i_size_read(inode);
+ if (ia->ia_size < size || (ia->ia_size > size &&
+ inode->i_sb->s_maxbytes < lower_inode->i_sb->s_maxbytes)) {
err = vmtruncate(inode, ia->ia_size);
if (err)
- printk(KERN_ERR
- "unionfs: setattr: vmtruncate failed\n");
+ goto out;
}
}
- /* get the size from the first lower inode */
- lower_inode = unionfs_lower_inode(inode);
+ err = notify_change(lower_dentry, ia);
+ if (err)
+ goto out;
+
+ /* get attributes from the first lower inode */
unionfs_copy_attr_all(inode, lower_inode);
/*
* unionfs_copy_attr_all will copy the lower times to our inode if
next prev parent reply other threads:[~2007-12-18 22:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-18 22:10 [PATCH 0/4] unionfs: work better with tmpfs Hugh Dickins
2007-12-18 22:12 ` [PATCH 1/4] unionfs: remove cap_writeback_dirty test Hugh Dickins
2007-12-18 22:13 ` [PATCH 2/4] unionfs: 32-bit needs lock for i_size Hugh Dickins
2007-12-18 22:14 ` [PATCH 3/4] unionfs: restructure unionfs_setattr Hugh Dickins
2007-12-18 23:09 ` Erez Zadok
2007-12-19 0:53 ` Hugh Dickins
2007-12-19 1:14 ` Erez Zadok
2007-12-18 22:14 ` Hugh Dickins [this message]
2007-12-28 21:09 ` [PATCH 0/4] unionfs: work better with tmpfs Erez Zadok
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=Pine.LNX.4.64.0712182214180.28390@blonde.wat.veritas.com \
--to=hugh@veritas.com \
--cc=akpm@linux-foundation.org \
--cc=ezk@cs.sunysb.edu \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®