Sage Weil
2011-Aug-09 19:00 UTC
[PATCH] Btrfs: truncate pages from clone ioctl target range
We need to truncate page cache pages for the clone ioctl target range or else we''ll confuse ourselves to no end. If the old data was cached, we''ll still see it (until remount). If it was dirty we''ll get a mix of old and new data if the page(s) are partially updated. Signed-off-by: Sage Weil <sage@newdream.net> --- fs/btrfs/ioctl.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index a3c4751..cac9491 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2243,6 +2243,10 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, btrfs_wait_ordered_range(src, off, len); } + /* truncate page cache pages from target inode range */ + truncate_inode_pages_range(&inode->i_data, off, + ((off+len+PAGE_CACHE_SIZE-1)&PAGE_CACHE_MASK)-1); + /* clone data */ key.objectid = btrfs_ino(src); key.type = BTRFS_EXTENT_DATA_KEY; -- 1.7.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2011-Aug-09 20:12 UTC
Re: [PATCH] Btrfs: truncate pages from clone ioctl target range
just a readability issue: On Tue, Aug 09, 2011 at 12:00:41PM -0700, Sage Weil wrote:> --- a/fs/btrfs/ioctl.c > +++ b/fs/btrfs/ioctl.c > @@ -2243,6 +2243,10 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, > btrfs_wait_ordered_range(src, off, len); > } > > + /* truncate page cache pages from target inode range */ > + truncate_inode_pages_range(&inode->i_data, off, > + ((off+len+PAGE_CACHE_SIZE-1)&PAGE_CACHE_MASK)-1);ALIGN(off + len, PAGE_CACHE_SIZE) - 1) I''ll give it some testing too :) thanks for catching this! david> + > /* clone data */ > key.objectid = btrfs_ino(src); > key.type = BTRFS_EXTENT_DATA_KEY; > ---- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Sage Weil
2011-Aug-10 18:04 UTC
[PATCH] Btrfs: truncate pages from clone ioctl target range
We need to truncate page cache pages for the clone ioctl target range or else we''ll confuse ourselves to no end. If the old data was cached, we used to still see it (until remount). If the page was partially updated we used to get a mix of old and new data. Signed-off-by: Sage Weil <sage@newdream.net> --- v1->v2: use ALIGN macro fs/btrfs/ioctl.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 514c0eb..5acb8e1 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2243,6 +2243,10 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, btrfs_wait_ordered_range(src, off, len); } + /* truncate page cache pages from target inode range */ + truncate_inode_pages_range(&inode->i_data, off, + ALIGN(off + len, PAGE_CACHE_SIZE) - 1); + /* clone data */ key.objectid = btrfs_ino(src); key.type = BTRFS_EXTENT_DATA_KEY; -- 1.7.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Apparently Analagous Threads
- [PATCH 0/4] btrfs: out-of-band (aka offline) dedupe v4
- [PATCH] Btrfs: allow cloning ranges within the same file
- [PATCH] Btrfs: turn to readonly if btrfs_start_transaction() fails
- [PATCH 1/2 v3] Btrfs: use flag EXTENT_DEFRAG for snapshot-aware defrag
- [GIT PULL v3] Btrfs: improve write ahead log with sub transaction