diff mbox series

[v8,07/41] btrfs: disallow NODATACOW in ZONED mode

Message ID c5f6be584aea6de94506d91093be11c6c22e6088.1601574234.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: zoned block device support | expand

Commit Message

Naohiro Aota Oct. 1, 2020, 6:36 p.m. UTC
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: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/ioctl.c | 3 +++
 fs/btrfs/zoned.c | 6 ++++++
 2 files changed, 9 insertions(+)

Comments

David Sterba Oct. 13, 2020, 3:39 p.m. UTC | #1
On Fri, Oct 02, 2020 at 03:36:14AM +0900, Naohiro Aota wrote:
> 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: Johannes Thumshirn <jthumshirn@suse.de>
> Reviewed-by: Josef Bacik <josef@toxicpanda.com>
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> ---
>  fs/btrfs/ioctl.c | 3 +++
>  fs/btrfs/zoned.c | 6 ++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index ab408a23ba32..5d592da4e2ff 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -91,6 +91,9 @@ struct btrfs_ioctl_send_args_32 {
>  static unsigned int btrfs_mask_fsflags_for_type(struct inode *inode,
>  		unsigned int flags)
>  {
> +	if (btrfs_fs_incompat(btrfs_sb(inode->i_sb), ZONED))
> +		flags &= ~FS_NOCOW_FL;
> +

This can't be inside the function, the 'type' here is for inode that
does not know anything about zoned mode. The right place is after
check_fsflags in btrfs_ioctl_setflags in a helper like:

	ret = check_fsflags_compatible(fs_info, flags));
	if (ret)
		goto out_unlock;

and check_fsflags_compatible checks for zoned mode and NOCOW and returns
-EPERM, not silently unmasking it.

>  	if (S_ISDIR(inode->i_mode))
>  		return flags;
>  	else if (S_ISREG(inode->i_mode))
Johannes Thumshirn Oct. 21, 2020, 8:53 a.m. UTC | #2
On 13/10/2020 17:40, David Sterba wrote:
> This can't be inside the function, the 'type' here is for inode that
> does not know anything about zoned mode. The right place is after
> check_fsflags in btrfs_ioctl_setflags in a helper like:
> 
> 	ret = check_fsflags_compatible(fs_info, flags));
> 	if (ret)
> 		goto out_unlock;
> 
> and check_fsflags_compatible checks for zoned mode and NOCOW and returns
> -EPERM, not silently unmasking it.

And done as well.
diff mbox series

Patch

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index ab408a23ba32..5d592da4e2ff 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -91,6 +91,9 @@  struct btrfs_ioctl_send_args_32 {
 static unsigned int btrfs_mask_fsflags_for_type(struct inode *inode,
 		unsigned int flags)
 {
+	if (btrfs_fs_incompat(btrfs_sb(inode->i_sb), ZONED))
+		flags &= ~FS_NOCOW_FL;
+
 	if (S_ISDIR(inode->i_mode))
 		return flags;
 	else if (S_ISREG(inode->i_mode))
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 1629e585ba8c..6bce654bb0e8 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -284,5 +284,11 @@  int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info)
 		return -EOPNOTSUPP;
 	}
 
+	if (btrfs_test_opt(info, NODATACOW)) {
+		btrfs_err(info,
+		  "cannot enable nodatacow with ZONED mode");
+		return -EOPNOTSUPP;
+	}
+
 	return 0;
 }