On Sun, May 13, 2012 at 08:51:53PM +0300, Avi Kivity wrote: > On Sat, Apr 21, 2012 at 3:15 AM, Chris Mason <chris.mason@xxxxxxxxxx> wrote: > >> > >> Are there plans to allow per-subvolume nodatasum/nodatacow? > > > > It can be set on a per file basis, let me push out a commit to btrfs > > progs with ioctls to set it. > > Did this not happen, or am I barking up the wrong btrfs-progs.git tree? Taking minimalistic approach, the following patch allows to enable true NOCOW feature on a file (limted to files of 0 size), no specific mount options are needed. Tested on a ~350MB file, filled with /dev/urandom, then randomly rewritten with zeros, filefrag output is same before and after the operation. Please note that due to the simplicity of implementation, only a zero-sized file really becomes NOCOW, but in fact this mimics what creating a file under -o nodatacow will produce. The change is done by setting NOCOW attribute, with patched chattr http://www.spinics.net/lists/linux-btrfs/msg09605.html (or using the ioctl directly) david --- --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -234,10 +234,22 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ip->flags |= BTRFS_INODE_DIRSYNC; else ip->flags &= ~BTRFS_INODE_DIRSYNC; - if (flags & FS_NOCOW_FL) + if (flags & FS_NOCOW_FL) { ip->flags |= BTRFS_INODE_NODATACOW; - else + /* + * Half-workaround for a NOCOW file. + * It's safe to turn of csums here, no extents exist + */ + if (inode->i_size == 0) + ip->flags |= BTRFS_INODE_NODATASUM; + } else { + /* + * Revert back under same assuptions as before + */ + if (inode->i_size == 0) + ip->flags &= ~BTRFS_INODE_NODATASUM; ip->flags &= ~BTRFS_INODE_NODATACOW; + } /* * The COMPRESS flag can only be changed by users, while the NOCOMPRESS -- 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
