diff mbox series

[v10,07/41] btrfs: disallow space_cache in ZONED mode

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

Commit Message

Naohiro Aota Nov. 10, 2020, 11:26 a.m. UTC
As updates to the space cache v1 are in-place, the space cache cannot be
located over sequential zones and there is no guarantees that the device
will have enough conventional zones to store this cache. Resolve this
problem by disabling completely the space cache v1.  This does not
introduces any problems with sequential block groups: all the free space is
located after the allocation pointer and no free space before the pointer.
There is no need to have such cache.

Note: we can technically use free-space-tree (space cache v2) on ZONED
mode. But, since ZONED mode now always allocate extents in a block group
sequentially regardless of underlying device zone type, it's no use to
enable and maintain the tree.

For the same reason, NODATACOW is also disabled.

In summary, ZONED will disable:

| Disabled features | Reason                                              |
|-------------------+-----------------------------------------------------|
| RAID/Dup          | Cannot handle two zone append writes to different   |
|                   | zones                                               |
|-------------------+-----------------------------------------------------|
| space_cache (v1)  | In-place updating                                   |
| NODATACOW         | In-place updating                                   |
|-------------------+-----------------------------------------------------|
| fallocate         | Reserved extent will be a write hole                |
|-------------------+-----------------------------------------------------|
| MIXED_BG          | Allocated metadata region will be write holes for   |
|                   | data writes                                         |

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/super.c | 13 +++++++++++--
 fs/btrfs/zoned.c | 18 ++++++++++++++++++
 fs/btrfs/zoned.h |  6 ++++++
 3 files changed, 35 insertions(+), 2 deletions(-)

Comments

Anand Jain Nov. 19, 2020, 10:42 a.m. UTC | #1
> @@ -985,6 +992,8 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
>   		ret = -EINVAL;
>   
>   	}
> +	if (!ret)
> +		ret = btrfs_check_mountopts_zoned(info);
>   	if (!ret && btrfs_test_opt(info, SPACE_CACHE))
>   		btrfs_info(info, "disk space caching is enabled");
>   	if (!ret && btrfs_test_opt(info, FREE_SPACE_TREE))
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index 2897432eb43c..d6b8165e2c91 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -274,3 +274,21 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
>   out:
>   	return ret;
>   }
> +
> +int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info)
> +{
> +	if (!btrfs_is_zoned(info))
> +		return 0;
> +
> +	/*
> +	 * Space cache writing is not COWed. Disable that to avoid write
> +	 * errors in sequential zones.
> +	 */
> +	if (btrfs_test_opt(info, SPACE_CACHE)) {
> +		btrfs_err(info,
> +			  "zoned: space cache v1 is not supported");
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
> index 52aa6af5d8dc..81c00a3ed202 100644
> --- a/fs/btrfs/zoned.h
> +++ b/fs/btrfs/zoned.h
> @@ -25,6 +25,7 @@ int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
>   int btrfs_get_dev_zone_info(struct btrfs_device *device);
>   void btrfs_destroy_dev_zone_info(struct btrfs_device *device);
>   int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info);
> +int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info);
>   #else /* CONFIG_BLK_DEV_ZONED */
>   static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
>   				     struct blk_zone *zone)
> @@ -48,6 +49,11 @@ static inline int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
>   	return -EOPNOTSUPP;
>   }
>   
> +static inline int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info)
> +{
> +	return 0;
> +}
> +
>   #endif
>   
>   static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos)
> 

The whole of the above code can be replaced by..

-------------------
@@ -810,8 +810,15 @@ int btrfs_parse_options(struct btrfs_fs_info *info, 
char *options,
                         break;
                 case Opt_space_cache:
                 case Opt_space_cache_version:
                         if (token == Opt_space_cache ||
                             strcmp(args[0].from, "v1") == 0) {
+                               if (btrfs_is_zoned(info)) {
+                                       btrfs_err(info,
+                                       "zoned: space cache v1 is not 
supported");
+                                       ret = -EINVAL;
+                                       goto out;
+                               }
                                 btrfs_clear_opt(info->mount_opt,
                                                 FREE_SPACE_TREE);
                                 btrfs_set_and_info(info, SPACE_CACHE,
-------------------

Thanks.
Anand Jain Nov. 20, 2020, 4:08 a.m. UTC | #2
On 19/11/20 6:42 pm, Anand Jain wrote:
> 
> 
>> @@ -985,6 +992,8 @@ int btrfs_parse_options(struct btrfs_fs_info 
>> *info, char *options,
>>           ret = -EINVAL;
>>       }
>> +    if (!ret)
>> +        ret = btrfs_check_mountopts_zoned(info);
>>       if (!ret && btrfs_test_opt(info, SPACE_CACHE))
>>           btrfs_info(info, "disk space caching is enabled");
>>       if (!ret && btrfs_test_opt(info, FREE_SPACE_TREE))
>> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
>> index 2897432eb43c..d6b8165e2c91 100644
>> --- a/fs/btrfs/zoned.c
>> +++ b/fs/btrfs/zoned.c
>> @@ -274,3 +274,21 @@ int btrfs_check_zoned_mode(struct btrfs_fs_info 
>> *fs_info)
>>   out:
>>       return ret;
>>   }
>> +
>> +int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info)
>> +{
>> +    if (!btrfs_is_zoned(info))
>> +        return 0;
>> +
>> +    /*
>> +     * Space cache writing is not COWed. Disable that to avoid write
>> +     * errors in sequential zones.
>> +     */
>> +    if (btrfs_test_opt(info, SPACE_CACHE)) {
>> +        btrfs_err(info,
>> +              "zoned: space cache v1 is not supported");
>> +        return -EINVAL;
>> +    }
>> +
>> +    return 0;
>> +}
>> diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
>> index 52aa6af5d8dc..81c00a3ed202 100644
>> --- a/fs/btrfs/zoned.h
>> +++ b/fs/btrfs/zoned.h
>> @@ -25,6 +25,7 @@ int btrfs_get_dev_zone(struct btrfs_device *device, 
>> u64 pos,
>>   int btrfs_get_dev_zone_info(struct btrfs_device *device);
>>   void btrfs_destroy_dev_zone_info(struct btrfs_device *device);
>>   int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info);
>> +int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info);
>>   #else /* CONFIG_BLK_DEV_ZONED */
>>   static inline int btrfs_get_dev_zone(struct btrfs_device *device, 
>> u64 pos,
>>                        struct blk_zone *zone)
>> @@ -48,6 +49,11 @@ static inline int btrfs_check_zoned_mode(struct 
>> btrfs_fs_info *fs_info)
>>       return -EOPNOTSUPP;
>>   }
>> +static inline int btrfs_check_mountopts_zoned(struct btrfs_fs_info 
>> *info)
>> +{
>> +    return 0;
>> +}
>> +
>>   #endif
>>   static inline bool btrfs_dev_is_sequential(struct btrfs_device 
>> *device, u64 pos)
>>
> 
> The whole of the above code can be replaced by..
> 



> -------------------
> @@ -810,8 +810,15 @@ int btrfs_parse_options(struct btrfs_fs_info *info, 
> char *options,
>                          break;
>                  case Opt_space_cache:
>                  case Opt_space_cache_version:
>                          if (token == Opt_space_cache ||
>                              strcmp(args[0].from, "v1") == 0) {
> +                               if (btrfs_is_zoned(info)) {
> +                                       btrfs_err(info,
> +                                       "zoned: space cache v1 is not 
> supported");
> +                                       ret = -EINVAL;
> +                                       goto out;
> +                               }
>                                  btrfs_clear_opt(info->mount_opt,
>                                                  FREE_SPACE_TREE);
>                                  btrfs_set_and_info(info, SPACE_CACHE,
> -------------------
> 


Later patches add more flag-checks to btrfs_check_mountopts_zoned(),
I have no preference for either this way or adding those checks
individually in btrfs_parse_options(). So you may ignore this.

Thanks.

> Thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 3312fe08168f..1adbbeebc649 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -525,8 +525,15 @@  int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
 	cache_gen = btrfs_super_cache_generation(info->super_copy);
 	if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE))
 		btrfs_set_opt(info->mount_opt, FREE_SPACE_TREE);
-	else if (cache_gen)
-		btrfs_set_opt(info->mount_opt, SPACE_CACHE);
+	else if (cache_gen) {
+		if (btrfs_is_zoned(info)) {
+			btrfs_info(info,
+			"zoned: clearing existing space cache");
+			btrfs_set_super_cache_generation(info->super_copy, 0);
+		} else {
+			btrfs_set_opt(info->mount_opt, SPACE_CACHE);
+		}
+	}
 
 	/*
 	 * Even the options are empty, we still need to do extra check
@@ -985,6 +992,8 @@  int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
 		ret = -EINVAL;
 
 	}
+	if (!ret)
+		ret = btrfs_check_mountopts_zoned(info);
 	if (!ret && btrfs_test_opt(info, SPACE_CACHE))
 		btrfs_info(info, "disk space caching is enabled");
 	if (!ret && btrfs_test_opt(info, FREE_SPACE_TREE))
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 2897432eb43c..d6b8165e2c91 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -274,3 +274,21 @@  int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
 out:
 	return ret;
 }
+
+int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info)
+{
+	if (!btrfs_is_zoned(info))
+		return 0;
+
+	/*
+	 * Space cache writing is not COWed. Disable that to avoid write
+	 * errors in sequential zones.
+	 */
+	if (btrfs_test_opt(info, SPACE_CACHE)) {
+		btrfs_err(info,
+			  "zoned: space cache v1 is not supported");
+		return -EINVAL;
+	}
+
+	return 0;
+}
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index 52aa6af5d8dc..81c00a3ed202 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -25,6 +25,7 @@  int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
 int btrfs_get_dev_zone_info(struct btrfs_device *device);
 void btrfs_destroy_dev_zone_info(struct btrfs_device *device);
 int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info);
+int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info);
 #else /* CONFIG_BLK_DEV_ZONED */
 static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
 				     struct blk_zone *zone)
@@ -48,6 +49,11 @@  static inline int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
 	return -EOPNOTSUPP;
 }
 
+static inline int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info)
+{
+	return 0;
+}
+
 #endif
 
 static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos)