OSDN Git Service

btrfs: disallow NODATACOW in ZONED mode
authorNaohiro Aota <naohiro.aota@wdc.com>
Tue, 10 Nov 2020 11:26:11 +0000 (20:26 +0900)
committerDavid Sterba <dsterba@suse.com>
Wed, 9 Dec 2020 18:16:04 +0000 (19:16 +0100)
NODATACOW implies overwriting the file data on a device, which is
impossible in sequential required zones. Disable NODATACOW globally with
mount option and per-file NODATACOW attribute by masking FS_NOCOW_FL.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ioctl.c
fs/btrfs/zoned.c

index a5dc7cc..0b5e1df 100644 (file)
@@ -193,6 +193,15 @@ static int check_fsflags(unsigned int old_flags, unsigned int flags)
        return 0;
 }
 
+static int check_fsflags_compatible(struct btrfs_fs_info *fs_info,
+                                   unsigned int flags)
+{
+       if (btrfs_is_zoned(fs_info) && (flags & FS_NOCOW_FL))
+               return -EPERM;
+
+       return 0;
+}
+
 static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
 {
        struct inode *inode = file_inode(file);
@@ -230,6 +239,10 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
        if (ret)
                goto out_unlock;
 
+       ret = check_fsflags_compatible(fs_info, fsflags);
+       if (ret)
+               goto out_unlock;
+
        binode_flags = binode->flags;
        if (fsflags & FS_SYNC_FL)
                binode_flags |= BTRFS_INODE_SYNC;
index 3bc6a5e..6ef9799 100644 (file)
@@ -274,5 +274,10 @@ int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info)
                return -EINVAL;
        }
 
+       if (btrfs_test_opt(info, NODATACOW)) {
+               btrfs_err(info, "zoned: NODATACOW not supported");
+               return -EINVAL;
+       }
+
        return 0;
 }