* [PATCH v3] Btrfs: fix a bug of per-file nocow
@ 2012-09-11 14:33 Liu Bo
2012-09-13 15:42 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Liu Bo @ 2012-09-11 14:33 UTC (permalink / raw)
To: linux-btrfs; +Cc: jbacik
Users report a bug, the reproducer is:
$ mkfs.btrfs /dev/loop0
$ mount /dev/loop0 /mnt/btrfs/
$ mkdir /mnt/btrfs/dir
$ chattr +C /mnt/btrfs/dir/
$ dd if=/dev/zero of=/mnt/btrfs/dir/foo bs=4K count=10;
$ lsattr /mnt/btrfs/dir/foo
---------------C- /mnt/btrfs/dir/foo
$ filefrag /mnt/btrfs/dir/foo
/mnt/btrfs/dir/foo: 1 extent found ---> an extent
$ dd if=/dev/zero of=/mnt/btrfs/dir/foo bs=4K count=1 seek=5 conv=notrunc,nocreat; sync
$ filefrag /mnt/btrfs/dir/foo
/mnt/btrfs/dir/foo: 3 extents found ---> with nocow, btrfs breaks the extent into three parts
The new created file should not only inherit the NODATACOW flag, but also
honor NODATASUM flag, because we must do COW on a file extent with checksum.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
v3: fix my stupid finger error.
fs/btrfs/inode.c | 3 +--
fs/btrfs/ioctl.c | 5 ++++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index b2c3514..9bce6e9 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4720,8 +4720,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
if (S_ISREG(mode)) {
if (btrfs_test_opt(root, NODATASUM))
BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
- if (btrfs_test_opt(root, NODATACOW) ||
- (BTRFS_I(dir)->flags & BTRFS_INODE_NODATACOW))
+ if (btrfs_test_opt(root, NODATACOW))
BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW;
}
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 00ddf22..6c867ec 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -140,8 +140,11 @@ void btrfs_inherit_iflags(struct inode *inode, struct inode *dir)
BTRFS_I(inode)->flags |= BTRFS_INODE_COMPRESS;
}
- if (flags & BTRFS_INODE_NODATACOW)
+ if (flags & BTRFS_INODE_NODATACOW) {
BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW;
+ if (S_ISREG(inode->i_mode))
+ BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
+ }
btrfs_update_iflags(inode);
}
--
1.7.7.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] Btrfs: fix a bug of per-file nocow
2012-09-11 14:33 [PATCH v3] Btrfs: fix a bug of per-file nocow Liu Bo
@ 2012-09-13 15:42 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2012-09-13 15:42 UTC (permalink / raw)
To: Liu Bo; +Cc: linux-btrfs, jbacik
On Tue, Sep 11, 2012 at 10:33:50PM +0800, Liu Bo wrote:
> Users report a bug, the reproducer is:
> $ mkfs.btrfs /dev/loop0
> $ mount /dev/loop0 /mnt/btrfs/
> $ mkdir /mnt/btrfs/dir
> $ chattr +C /mnt/btrfs/dir/
> $ dd if=/dev/zero of=/mnt/btrfs/dir/foo bs=4K count=10;
> $ lsattr /mnt/btrfs/dir/foo
> ---------------C- /mnt/btrfs/dir/foo
> $ filefrag /mnt/btrfs/dir/foo
> /mnt/btrfs/dir/foo: 1 extent found ---> an extent
> $ dd if=/dev/zero of=/mnt/btrfs/dir/foo bs=4K count=1 seek=5 conv=notrunc,nocreat; sync
> $ filefrag /mnt/btrfs/dir/foo
> /mnt/btrfs/dir/foo: 3 extents found ---> with nocow, btrfs breaks the extent into three parts
>
> The new created file should not only inherit the NODATACOW flag, but also
> honor NODATASUM flag, because we must do COW on a file extent with checksum.
>
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.cz>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-13 15:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-11 14:33 [PATCH v3] Btrfs: fix a bug of per-file nocow Liu Bo
2012-09-13 15:42 ` David Sterba
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).