All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Roesch <shr@fb.com>
To: Nikolay Borisov <nborisov@suse.com>,
	<linux-btrfs@vger.kernel.org>, <kernel-team@fb.com>
Subject: Re: [PATCH v4 2/4] btrfs: expose chunk size in sysfs.
Date: Mon, 8 Nov 2021 17:57:53 -0800	[thread overview]
Message-ID: <aabdab98-f712-8345-decc-c83e84f009c2@fb.com> (raw)
In-Reply-To: <1b9cde85-a7ee-42f9-f7ed-49169757e86a@suse.com>



On 11/5/21 2:27 AM, Nikolay Borisov wrote:
> 
> 
> On 29.10.21 г. 21:39, Stefan Roesch wrote:
>> This adds a new sysfs entry in /sys/fs/btrfs/<uuid>/allocation/<block
>> type>/chunk_size. This allows to query the chunk size and also set the
>> chunk size.
>>
>> Signed-off-by: Stefan Roesch <shr@fb.com>
>> ---
>>  fs/btrfs/sysfs.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 80 insertions(+)
>>
>> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
>> index f9eff3b0f77c..3b0bcbc2ed2e 100644
>> --- a/fs/btrfs/sysfs.c
>> +++ b/fs/btrfs/sysfs.c
>> @@ -21,6 +21,7 @@
>>  #include "space-info.h"
>>  #include "block-group.h"
>>  #include "qgroup.h"
>> +#include "misc.h"
>>  
>>  /*
>>   * Structure name                       Path
>> @@ -92,6 +93,7 @@ static struct btrfs_feature_attr btrfs_attr_features_##_name = {	     \
>>  
>>  static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj);
>>  static inline struct btrfs_fs_devices *to_fs_devs(struct kobject *kobj);
>> +static inline struct kobject *get_btrfs_kobj(struct kobject *kobj);
>>  
>>  static struct btrfs_feature_attr *to_btrfs_feature_attr(struct kobj_attribute *a)
>>  {
>> @@ -708,6 +710,67 @@ static ssize_t btrfs_space_info_show_##field(struct kobject *kobj,	\
>>  }									\
>>  BTRFS_ATTR(space_info, field, btrfs_space_info_show_##field)
>>  
>> +/*
>> + * Return space info chunk size.
>> + */
>> +static ssize_t btrfs_chunk_size_show(struct kobject *kobj,
>> +				     struct kobj_attribute *a, char *buf)
>> +{
>> +	struct btrfs_space_info *sinfo = to_space_info(kobj);
>> +
>> +	return btrfs_show_u64(&sinfo->default_chunk_size, &sinfo->lock, buf);
>> +}
>> +
>> +/*
>> + * Store new user supplied chunk size in space info.
>> + *
>> + * Note: If the new chunk size value is larger than 10% of free space it is
>> + *       reduced to match that limit.
>> + */
>> +static ssize_t btrfs_chunk_size_store(struct kobject *kobj,
>> +				      struct kobj_attribute *a,
>> +				      const char *buf, size_t len)
>> +{
>> +	struct btrfs_space_info *space_info = to_space_info(kobj);
>> +	struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj));
>> +	u64 val;
>> +	int ret;
>> +
>> +	if (!capable(CAP_SYS_ADMIN))
>> +		return -EPERM;
>> +
>> +	if (!fs_info) {
>> +		pr_err("couldn't get fs_info\n");
>> +		return -EPERM;
>> +	}
>> +
>> +	if (sb_rdonly(fs_info->sb))
>> +		return -EROFS;
>> +
>> +	if (!fs_info->fs_devices)
>> +		return -EINVAL;
>> +
>> +	if (btrfs_is_zoned(fs_info))
>> +		return -EINVAL;
>> +
>> +	if (!space_info) {
>> +		btrfs_err(fs_info, "couldn't get space_info\n");
>> +		return -EPERM;
>> +	}
>> +
>> +	ret = kstrtoull(buf, 10, &val);
>> +	if (ret)
>> +		return ret;
>> +
>> +	/*
>> +	 * Limit stripe size to 10% of available space.
>> +	 */
>> +	val = min(div_factor(fs_info->fs_devices->total_rw_bytes, 1), val);
>> +	btrfs_update_space_info_chunk_size(space_info, space_info->flags, val);
> 
> I wonder if we need to enforce some sort of alignment i.e 128/256m
> otherwise we give the user to give all kinds of funky byte sizes?
> 
> <snip>
> 

That makes sense. As the default size is 256M. I propose the following:
- Sizes smaller than 256M are not allowed.
- Sizes are aligned on 256M boundary otherwise.


  reply	other threads:[~2021-11-09  1:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29 18:39 [PATCH v4 0/4] btrfs: sysfs: set / query btrfs chunk size Stefan Roesch
2021-10-29 18:39 ` [PATCH v4 1/4] btrfs: store chunk size in space-info struct Stefan Roesch
2021-11-05  8:52   ` Nikolay Borisov
2021-11-09 19:44     ` Stefan Roesch
2021-10-29 18:39 ` [PATCH v4 2/4] btrfs: expose chunk size in sysfs Stefan Roesch
2021-11-05  9:27   ` Nikolay Borisov
2021-11-09  1:57     ` Stefan Roesch [this message]
2021-11-09  6:36       ` Nikolay Borisov
2021-10-29 18:39 ` [PATCH v4 3/4] btrfs: add force_chunk_alloc sysfs entry to force allocation Stefan Roesch
2021-11-05 10:04   ` Nikolay Borisov
2021-11-09  1:09     ` Stefan Roesch
2021-10-29 18:39 ` [PATCH v4 4/4] btrfs: increase metadata alloc size to 5GB for volumes > 50GB Stefan Roesch
2021-11-05 10:11   ` Nikolay Borisov
2021-11-09 21:19     ` Stefan Roesch
2021-11-02 16:15 ` [PATCH v4 0/4] btrfs: sysfs: set / query btrfs chunk size Josef Bacik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aabdab98-f712-8345-decc-c83e84f009c2@fb.com \
    --to=shr@fb.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.