Hi,
I''ve used the following to test the patch:
rm a
touch a
chattr +C a
dd if=/dev/zero of=a bs=32k conv=notrunc,nocreat count=1
sync
filefrag -v a
dd if=/dev/zero of=a bs=32k conv=notrunc,nocreat count=1
sync
filefrag -v a
Before the patch:
ierdnac-hp btrfs # ./test
+ rm a
+ touch a
+ chattr +C a
+ dd if=/dev/zero of=a bs=32k conv=notrunc,nocreat count=1
+ sync
+ filefrag -v a
Filesystem type is: 9123683e
File size of a is 32768 (8 blocks, blocksize 4096)
ext logical physical expected length flags
0 0 1473536 8 eof
a: 1 extent found
+ dd if=/dev/zero of=a bs=32k conv=notrunc,nocreat count=1
+ sync
+ filefrag -v a
Filesystem type is: 9123683e
File size of a is 32768 (8 blocks, blocksize 4096)
ext logical physical expected length flags
0 0 1473560 8 eof
a: 1 extent found
ierdnac-hp btrfs #
After the patch:
ierdnac-hp btrfs # ./test
+ rm a
+ touch a
+ chattr +C a
+ dd if=/dev/zero of=a bs=32k conv=notrunc,nocreat count=1
1+0 records in
1+0 records out
32768 bytes (33 kB) copied, 3.651e-05 s, 898 MB/s
+ sync
+ filefrag -v a
Filesystem type is: 9123683e
File size of a is 32768 (8 blocks, blocksize 4096)
ext logical physical expected length flags
0 0 1473560 8 eof
a: 1 extent found
+ dd if=/dev/zero of=a bs=32k conv=notrunc,nocreat count=1
1+0 records in
1+0 records out
32768 bytes (33 kB) copied, 4.6666e-05 s, 702 MB/s
+ sync
+ filefrag -v a
Filesystem type is: 9123683e
File size of a is 32768 (8 blocks, blocksize 4096)
ext logical physical expected length flags
0 0 1473560 8 eof
a: 1 extent found
ierdnac-hp btrfs #
My question is what is the expected behaviour for setting the chattr
after the file is filed with bytes like this:
rm a
touch a
# chattr +C a -> before chattr was here and we move it below
dd if=/dev/zero of=a bs=32k conv=notrunc,nocreat count=1
sync
filefrag -v a
chattr +C a
dd if=/dev/zero of=a bs=32k conv=notrunc,nocreat count=1
sync
filefrag -v a
Because in this case btrfs doesn''t honour the NOCOW attribute:
+ rm a
+ touch a
+ dd if=/dev/zero of=a bs=32k conv=notrunc,nocreat count=1
1+0 records in
1+0 records out
32768 bytes (33 kB) copied, 3.5127e-05 s, 933 MB/s
+ sync
+ filefrag -v a
Filesystem type is: 9123683e
File size of a is 32768 (8 blocks, blocksize 4096)
ext logical physical expected length flags
0 0 1473544 8 eof
a: 1 extent found
+ chattr +C a
+ dd if=/dev/zero of=a bs=32k conv=notrunc,nocreat count=1
1+0 records in
1+0 records out
32768 bytes (33 kB) copied, 3.4169e-05 s, 959 MB/s
+ sync
+ filefrag -v a
Filesystem type is: 9123683e
File size of a is 32768 (8 blocks, blocksize 4096)
ext logical physical expected length flags
0 0 1473536 8 eof
a: 1 extent found
It''s supposed to honour the NOCOW attribute or not ?
On Sat, 2012-06-16 at 15:37 +0300, Andrei Popa wrote:> Adds BTRFS_INODE_NODATASUM to inode flags when setting NOCOW for a file
(chattr +C file).
> In btrfs, NOCOW implies NODATASUM and without setting NODATASUM, btrfs
doesn''t honour correctly the NOCOW attribute.
>
> Signed-off-by: Andrei Popa <andrei.popa@i-neo.ro>
> ---
> fs/btrfs/ioctl.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 0e92e57..8a7be76 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -139,7 +139,7 @@ void btrfs_inherit_iflags(struct inode *inode, struct
inode *dir)
> }
>
> if (flags & BTRFS_INODE_NODATACOW)
> - BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW;
> + BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW |
BTRFS_INODE_NODATASUM;
>
> btrfs_update_iflags(inode);
> }
> @@ -236,7 +236,7 @@ static int btrfs_ioctl_setflags(struct file *file, void
__user *arg)
> else
> ip->flags &= ~BTRFS_INODE_DIRSYNC;
> if (flags & FS_NOCOW_FL)
> - ip->flags |= BTRFS_INODE_NODATACOW;
> + ip->flags |= BTRFS_INODE_NODATACOW | BTRFS_INODE_NODATASUM;
> else
> ip->flags &= ~BTRFS_INODE_NODATACOW;
>
--
Andrei Popa
(+4) 0741.57.80.90