On Sat, Jun 16, 2012 at 03:37:12PM +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@xxxxxxxx> > --- > 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; > you cannot switch on NODATASUM for a file that already has extents that are checksummed. The invariant here is that either all the extents or none are checksummed. Setting NODATASUM is safe only on a zero sized file, that's what you saw in your test. Theoretically it's possible to add/remove all checksums from a given file, but it's a potentially longtime operation, the file has to be in some intermediate state where the checksums partially exist but have to be ignored (for the csum->nocsum) until the file is fully converted, this brings more special cases to extent handling, it has to survive power failure and remain consistent, and probably needs to be restarted after next mount. david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html
