All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES.
       [not found] <cover.1614028083.git.kreijack@inwind.it>
@ 2021-02-22 21:19 ` Goffredo Baroncelli
  2021-02-23  4:28     ` kernel test robot
  2021-02-23 13:53   ` David Sterba
  2021-02-22 21:19 ` [PATCH 2/4] btrfs: add flags to give an hint to the chunk allocator Goffredo Baroncelli
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 13+ messages in thread
From: Goffredo Baroncelli @ 2021-02-22 21:19 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Goffredo Baroncelli

From: Goffredo Baroncelli <kreijack@inwind.it>

This ioctl is a base for returning / setting information from / to  the
fields of the btrfs_dev_item object.

For now only the "type" field is returned / set.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
---
 fs/btrfs/ioctl.c           | 68 ++++++++++++++++++++++++++++++++++++++
 fs/btrfs/volumes.c         |  2 +-
 fs/btrfs/volumes.h         |  2 ++
 include/uapi/linux/btrfs.h | 39 ++++++++++++++++++++++
 4 files changed, 110 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index a8c60d46d19c..07898ee3a08d 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -4851,6 +4851,72 @@ static int btrfs_ioctl_set_features(struct file *file, void __user *arg)
 	return ret;
 }
 
+static long btrfs_ioctl_dev_properties(struct file *file,
+						void __user *argp)
+{
+	struct inode *inode = file_inode(file);
+	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
+	struct btrfs_ioctl_dev_properties dev_props;
+	struct btrfs_device	*device;
+	struct btrfs_root *root = fs_info->chunk_root;
+	struct btrfs_trans_handle *trans;
+	int ret;
+	u64 prev_type;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (copy_from_user(&dev_props, argp, sizeof(dev_props)))
+		return -EFAULT;
+
+	device = btrfs_find_device(fs_info->fs_devices, dev_props.devid,
+				NULL, NULL);
+	if (!device) {
+		btrfs_info(fs_info, "change_dev_properties: unable to find device %llu",
+			   dev_props.devid);
+		return -ENODEV;
+	}
+
+	if (dev_props.properties & BTRFS_DEV_PROPERTY_READ) {
+		u64 props = dev_props.properties;
+
+		memset(&dev_props, 0, sizeof(dev_props));
+		if (props & BTRFS_DEV_PROPERTY_TYPE) {
+			dev_props.properties = BTRFS_DEV_PROPERTY_TYPE;
+			dev_props.type = device->type;
+		}
+		if (copy_to_user(argp, &dev_props, sizeof(dev_props)))
+			return -EFAULT;
+		return 0;
+	}
+
+	/* it is possible to set only BTRFS_DEV_PROPERTY_TYPE for now */
+	if (dev_props.properties & ~(BTRFS_DEV_PROPERTY_TYPE))
+		return -EPERM;
+
+	trans = btrfs_start_transaction(root, 1);
+	if (IS_ERR(trans))
+		return PTR_ERR(trans);
+
+	prev_type = device->type;
+	device->type = dev_props.type;
+	ret = btrfs_update_device(trans, device);
+
+	if (ret < 0) {
+		btrfs_abort_transaction(trans, ret);
+		btrfs_end_transaction(trans);
+		device->type = prev_type;
+		return  ret;
+	}
+
+	ret = btrfs_commit_transaction(trans);
+	if (ret < 0)
+		device->type = prev_type;
+
+	return ret;
+
+}
+
 static int _btrfs_ioctl_send(struct file *file, void __user *argp, bool compat)
 {
 	struct btrfs_ioctl_send_args *arg;
@@ -5034,6 +5100,8 @@ long btrfs_ioctl(struct file *file, unsigned int
 		return btrfs_ioctl_get_subvol_rootref(file, argp);
 	case BTRFS_IOC_INO_LOOKUP_USER:
 		return btrfs_ioctl_ino_lookup_user(file, argp);
+	case BTRFS_IOC_DEV_PROPERTIES:
+		return btrfs_ioctl_dev_properties(file, argp);
 	}
 
 	return -ENOTTY;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index b8fab44394f5..0c649b444dcd 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2809,7 +2809,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 	return ret;
 }
 
-static noinline int btrfs_update_device(struct btrfs_trans_handle *trans,
+int btrfs_update_device(struct btrfs_trans_handle *trans,
 					struct btrfs_device *device)
 {
 	int ret;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index d4c3e0dd32b8..0c07b8deecab 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -600,5 +600,7 @@ int btrfs_bg_type_to_factor(u64 flags);
 const char *btrfs_bg_type_to_raid_name(u64 flags);
 int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
 int btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical);
+int btrfs_update_device(struct btrfs_trans_handle *trans,
+					struct btrfs_device *device);
 
 #endif
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index 5df73001aad4..bab35d3f819c 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -860,6 +860,43 @@ struct btrfs_ioctl_get_subvol_rootref_args {
 		__u8 align[7];
 };
 
+#define BTRFS_DEV_PROPERTY_TYPE		(1ULL << 0)
+#define BTRFS_DEV_PROPERTY_DEV_GROUP	(1ULL << 1)
+#define BTRFS_DEV_PROPERTY_SEEK_SPEED	(1ULL << 2)
+#define BTRFS_DEV_PROPERTY_BANDWIDTH	(1ULL << 3)
+#define BTRFS_DEV_PROPERTY_READ		(1ULL << 60)
+
+/*
+ * The ioctl BTRFS_IOC_DEV_PROPERTIES can read and write the device properties.
+ *
+ * The properties that the user want to write have to be set
+ * in the 'properties' field using the BTRFS_DEV_PROPERTY_xxxx constants.
+ *
+ * If the ioctl is used to read the device properties, the bit
+ * BTRFS_DEV_PROPERTY_READ has to be set in the 'properties' field.
+ * In this case the properties that the user want have to be set in the
+ * 'properties' field. The kernel doesn't return a property that was not
+ * required, however it may return a subset of the requested properties.
+ * The returned properties have the corrispondent BTRFS_DEV_PROPERTY_xxxx
+ * flag set in the 'properties' field.
+ *
+ * Up to 2020/05/11 the only properties that can be read/write is the 'type'
+ * one.
+ */
+struct btrfs_ioctl_dev_properties {
+	__u64	devid;
+	__u64	properties;
+	__u64	type;
+	__u32	dev_group;
+	__u8	seek_speed;
+	__u8	bandwidth;
+
+	/*
+	 * for future expansion, pad up to 1k
+	 */
+	__u8	reserved[1024-30];
+};
+
 /* Error codes as returned by the kernel */
 enum btrfs_err_code {
 	BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
@@ -988,5 +1025,7 @@ enum btrfs_err_code {
 				struct btrfs_ioctl_ino_lookup_user_args)
 #define BTRFS_IOC_SNAP_DESTROY_V2 _IOW(BTRFS_IOCTL_MAGIC, 63, \
 				struct btrfs_ioctl_vol_args_v2)
+#define BTRFS_IOC_DEV_PROPERTIES _IOW(BTRFS_IOCTL_MAGIC, 64, \
+				struct btrfs_ioctl_dev_properties)
 
 #endif /* _UAPI_LINUX_BTRFS_H */
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/4] btrfs: add flags to give an hint to the chunk allocator
       [not found] <cover.1614028083.git.kreijack@inwind.it>
  2021-02-22 21:19 ` [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES Goffredo Baroncelli
@ 2021-02-22 21:19 ` Goffredo Baroncelli
  2021-02-22 21:19 ` [PATCH 3/4] btrfs: export dev_item.type in /sys/fs/btrfs/<uuid>/devinfo/<devid>/type Goffredo Baroncelli
  2021-02-22 21:19 ` [PATCH 4/4] btrfs: add allocator_hint mode Goffredo Baroncelli
  3 siblings, 0 replies; 13+ messages in thread
From: Goffredo Baroncelli @ 2021-02-22 21:19 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Goffredo Baroncelli, Goffredo Baroncelli

From: Goffredo Baroncelli <kreijack@inwind.it>

Add the following flags to give an hint about which chunk should be
allocated in which a disk.
The following flags are created:

- BTRFS_DEV_ALLOCATION_PREFERRED_DATA
  preferred data chunk, but metadata chunk allowed
- BTRFS_DEV_ALLOCATION_PREFERRED_METADATA
  preferred metadata chunk, but data chunk allowed
- BTRFS_DEV_ALLOCATION_METADATA_ONLY
  only metadata chunk allowed
- BTRFS_DEV_ALLOCATION_DATA_ONLY
  only data chunk allowed

Signed-off-by: Goffredo Baroncelli <kreijack@inwid.it>
---
 include/uapi/linux/btrfs_tree.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
index 58d7cff9afb1..25f522bcdadc 100644
--- a/include/uapi/linux/btrfs_tree.h
+++ b/include/uapi/linux/btrfs_tree.h
@@ -361,6 +361,20 @@ struct btrfs_key {
 	__u64 offset;
 } __attribute__ ((__packed__));
 
+/* dev_item.type */
+
+/* btrfs chunk allocation hints */
+#define BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT	3
+/* preferred data chunk, but metadata chunk allowed */
+#define BTRFS_DEV_ALLOCATION_PREFERRED_DATA	(0ULL)
+/* preferred metadata chunk, but data chunk allowed */
+#define BTRFS_DEV_ALLOCATION_PREFERRED_METADATA	(1ULL)
+/* only metadata chunk are allowed */
+#define BTRFS_DEV_ALLOCATION_METADATA_ONLY	(2ULL)
+/* only data chunk allowed */
+#define BTRFS_DEV_ALLOCATION_DATA_ONLY		(3ULL)
+/* 5..7 are unused values */
+
 struct btrfs_dev_item {
 	/* the internal btrfs device id */
 	__le64 devid;
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/4] btrfs: export dev_item.type in /sys/fs/btrfs/<uuid>/devinfo/<devid>/type
       [not found] <cover.1614028083.git.kreijack@inwind.it>
  2021-02-22 21:19 ` [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES Goffredo Baroncelli
  2021-02-22 21:19 ` [PATCH 2/4] btrfs: add flags to give an hint to the chunk allocator Goffredo Baroncelli
@ 2021-02-22 21:19 ` Goffredo Baroncelli
  2021-02-22 21:19 ` [PATCH 4/4] btrfs: add allocator_hint mode Goffredo Baroncelli
  3 siblings, 0 replies; 13+ messages in thread
From: Goffredo Baroncelli @ 2021-02-22 21:19 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Goffredo Baroncelli

From: Goffredo Baroncelli <kreijack@inwind.it>

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
---
 fs/btrfs/sysfs.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 6eb1c50fa98c..9b2a18911de6 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1418,11 +1418,22 @@ static ssize_t btrfs_devinfo_writeable_show(struct kobject *kobj,
 }
 BTRFS_ATTR(devid, writeable, btrfs_devinfo_writeable_show);
 
+static ssize_t btrfs_devinfo_type_show(struct kobject *kobj,
+					    struct kobj_attribute *a, char *buf)
+{
+	struct btrfs_device *device = container_of(kobj, struct btrfs_device,
+						   devid_kobj);
+
+	return scnprintf(buf, PAGE_SIZE, "0x%08llx\n", device->type);
+}
+BTRFS_ATTR(devid, type, btrfs_devinfo_type_show);
+
 static struct attribute *devid_attrs[] = {
 	BTRFS_ATTR_PTR(devid, in_fs_metadata),
 	BTRFS_ATTR_PTR(devid, missing),
 	BTRFS_ATTR_PTR(devid, replace_target),
 	BTRFS_ATTR_PTR(devid, writeable),
+	BTRFS_ATTR_PTR(devid, type),
 	NULL
 };
 ATTRIBUTE_GROUPS(devid);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/4] btrfs: add allocator_hint mode
       [not found] <cover.1614028083.git.kreijack@inwind.it>
                   ` (2 preceding siblings ...)
  2021-02-22 21:19 ` [PATCH 3/4] btrfs: export dev_item.type in /sys/fs/btrfs/<uuid>/devinfo/<devid>/type Goffredo Baroncelli
@ 2021-02-22 21:19 ` Goffredo Baroncelli
  3 siblings, 0 replies; 13+ messages in thread
From: Goffredo Baroncelli @ 2021-02-22 21:19 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Goffredo Baroncelli

From: Goffredo Baroncelli <kreijack@inwind.it>

When this mode is enabled, the chunk allocation policy is modified as
follow.

Each disk may have a different tag:
- BTRFS_DEV_ALLOCATION_PREFERRED_METADATA
- BTRFS_DEV_ALLOCATION_METADATA_ONLY
- BTRFS_DEV_ALLOCATION_DATA_ONLY
- BTRFS_DEV_ALLOCATION_PREFERRED_DATA (default)

Where:
- ALLOCATION_PREFERRED_X means that it is preferred to use this disk for
the X chunk type (the other type may be allowed when the space is low)
- ALLOCATION_X_ONLY means that it is used *only* for the X chunk type.
This means also that it is a preferred choice.

Each time the allocator allocates a chunk of type X , first it takes the
disks tagged as ALLOCATION_X_ONLY or ALLOCATION_PREFERRED_X; if the space
is not enough, it uses also the disks tagged as ALLOCATION_METADATA_ONLY;
if the space is not enough, it uses also the other disks, with the
exception of the one marked as ALLOCATION_PREFERRED_Y, where Y the other
type of chunk (i.e. not X).

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
---
 fs/btrfs/volumes.c | 98 +++++++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/volumes.h |  1 +
 2 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 0c649b444dcd..7ab10640758c 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -153,6 +153,20 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 	},
 };
 
+#define BTRFS_DEV_ALLOCATION_MASK ((1ULL << \
+		BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT) - 1)
+#define BTRFS_DEV_ALLOCATION_MASK_COUNT (1ULL << \
+		BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT)
+
+static const char alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = {
+	[BTRFS_DEV_ALLOCATION_DATA_ONLY] = -1,
+	[BTRFS_DEV_ALLOCATION_PREFERRED_DATA] = 0,
+	[BTRFS_DEV_ALLOCATION_PREFERRED_METADATA] = 1,
+	[BTRFS_DEV_ALLOCATION_METADATA_ONLY] = 2,
+	/* the other values are set to 0 */
+};
+
+
 const char *btrfs_bg_type_to_raid_name(u64 flags)
 {
 	const int index = btrfs_bg_flags_to_raid_index(flags);
@@ -4872,13 +4886,18 @@ static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info,
 }
 
 /*
- * sort the devices in descending order by max_avail, total_avail
+ * sort the devices in descending order by alloc_hint,
+ * max_avail, total_avail
  */
 static int btrfs_cmp_device_info(const void *a, const void *b)
 {
 	const struct btrfs_device_info *di_a = a;
 	const struct btrfs_device_info *di_b = b;
 
+	if (di_a->alloc_hint > di_b->alloc_hint)
+		return -1;
+	if (di_a->alloc_hint < di_b->alloc_hint)
+		return 1;
 	if (di_a->max_avail > di_b->max_avail)
 		return -1;
 	if (di_a->max_avail < di_b->max_avail)
@@ -5039,6 +5058,8 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
 	int ndevs = 0;
 	u64 max_avail;
 	u64 dev_offset;
+	int hint;
+	int i;
 
 	/*
 	 * in the first pass through the devices list, we gather information
@@ -5091,16 +5112,91 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
 		devices_info[ndevs].max_avail = max_avail;
 		devices_info[ndevs].total_avail = total_avail;
 		devices_info[ndevs].dev = device;
+
+		if ((ctl->type & BTRFS_BLOCK_GROUP_DATA) &&
+		     (ctl->type & BTRFS_BLOCK_GROUP_METADATA)) {
+			/*
+			 * if mixed bg set all the alloc_hint
+			 * fields to the same value, so the sorting
+			 * is not affected
+			 */
+			devices_info[ndevs].alloc_hint = 0;
+		} else if (ctl->type & BTRFS_BLOCK_GROUP_DATA) {
+			hint = device->type & BTRFS_DEV_ALLOCATION_MASK;
+
+			/*
+			 * skip BTRFS_DEV_METADATA_ONLY disks
+			 */
+			if (hint == BTRFS_DEV_ALLOCATION_METADATA_ONLY)
+				continue;
+			/*
+			 * if a data chunk must be allocated,
+			 * sort also by hint (data disk
+			 * higher priority)
+			 */
+			devices_info[ndevs].alloc_hint = -alloc_hint_map[hint];
+		} else { /* BTRFS_BLOCK_GROUP_METADATA */
+			hint = device->type & BTRFS_DEV_ALLOCATION_MASK;
+
+			/*
+			 * skip BTRFS_DEV_DATA_ONLY disks
+			 */
+			if (hint == BTRFS_DEV_ALLOCATION_DATA_ONLY)
+				continue;
+			/*
+			 * if a data chunk must be allocated,
+			 * sort also by hint (metadata hint
+			 * higher priority)
+			 */
+			devices_info[ndevs].alloc_hint = alloc_hint_map[hint];
+		}
+
 		++ndevs;
 	}
 	ctl->ndevs = ndevs;
 
+	/*
+	 * no devices available
+	 */
+	if (!ndevs)
+		return 0;
+
 	/*
 	 * now sort the devices by hole size / available space
 	 */
 	sort(devices_info, ndevs, sizeof(struct btrfs_device_info),
 	     btrfs_cmp_device_info, NULL);
 
+	/*
+	 * select the minimum set of disks grouped by hint that
+	 * can host the chunk
+	 */
+	ndevs = 0;
+	while (ndevs < ctl->ndevs) {
+		hint = devices_info[ndevs++].alloc_hint;
+		while (ndevs < ctl->ndevs &&
+		       devices_info[ndevs].alloc_hint == hint)
+				ndevs++;
+		if (ndevs >= ctl->devs_min)
+			break;
+	}
+
+	BUG_ON(ndevs > ctl->ndevs);
+	ctl->ndevs = ndevs;
+
+	/*
+	 * the next layers require the devices_info ordered by
+	 * max_avail. If we are returing two (or more) different
+	 * group of alloc_hint, this is not always true. So sort
+	 * these gain.
+	 */
+
+	for (i = 0 ; i < ndevs ; i++)
+		devices_info[i].alloc_hint = 0;
+
+	sort(devices_info, ndevs, sizeof(struct btrfs_device_info),
+	     btrfs_cmp_device_info, NULL);
+
 	return 0;
 }
 
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 0c07b8deecab..d192aa78f03f 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -366,6 +366,7 @@ struct btrfs_device_info {
 	u64 dev_offset;
 	u64 max_avail;
 	u64 total_avail;
+	int alloc_hint;
 };
 
 struct btrfs_raid_attr {
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES.
  2021-02-22 21:19 ` [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES Goffredo Baroncelli
@ 2021-02-23  4:28     ` kernel test robot
  2021-02-23 13:53   ` David Sterba
  1 sibling, 0 replies; 13+ messages in thread
From: kernel test robot @ 2021-02-23  4:28 UTC (permalink / raw)
  To: Goffredo Baroncelli, linux-btrfs; +Cc: kbuild-all, Goffredo Baroncelli

[-- Attachment #1: Type: text/plain, Size: 3739 bytes --]

Hi Goffredo,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on next-20210222]
[cannot apply to v5.11]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Goffredo-Baroncelli/btrfs-add-ioctl-BTRFS_IOC_DEV_PROPERTIES/20210223-062001
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
config: i386-randconfig-r011-20210222 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/62c95ccebf2c45bb8e91d379b454dd720734da34
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Goffredo-Baroncelli/btrfs-add-ioctl-BTRFS_IOC_DEV_PROPERTIES/20210223-062001
        git checkout 62c95ccebf2c45bb8e91d379b454dd720734da34
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   fs/btrfs/ioctl.c: In function 'btrfs_ioctl_dev_properties':
>> fs/btrfs/ioctl.c:4923:1: warning: the frame size of 1036 bytes is larger than 1024 bytes [-Wframe-larger-than=]
    4923 | }
         | ^


vim +4923 fs/btrfs/ioctl.c

  4858	
  4859	static long btrfs_ioctl_dev_properties(struct file *file,
  4860							void __user *argp)
  4861	{
  4862		struct inode *inode = file_inode(file);
  4863		struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
  4864		struct btrfs_ioctl_dev_properties dev_props;
  4865		struct btrfs_device	*device;
  4866		struct btrfs_root *root = fs_info->chunk_root;
  4867		struct btrfs_trans_handle *trans;
  4868		int ret;
  4869		u64 prev_type;
  4870	
  4871		if (!capable(CAP_SYS_ADMIN))
  4872			return -EPERM;
  4873	
  4874		if (copy_from_user(&dev_props, argp, sizeof(dev_props)))
  4875			return -EFAULT;
  4876	
  4877		device = btrfs_find_device(fs_info->fs_devices, dev_props.devid,
  4878					NULL, NULL);
  4879		if (!device) {
  4880			btrfs_info(fs_info, "change_dev_properties: unable to find device %llu",
  4881				   dev_props.devid);
  4882			return -ENODEV;
  4883		}
  4884	
  4885		if (dev_props.properties & BTRFS_DEV_PROPERTY_READ) {
  4886			u64 props = dev_props.properties;
  4887	
  4888			memset(&dev_props, 0, sizeof(dev_props));
  4889			if (props & BTRFS_DEV_PROPERTY_TYPE) {
  4890				dev_props.properties = BTRFS_DEV_PROPERTY_TYPE;
  4891				dev_props.type = device->type;
  4892			}
  4893			if (copy_to_user(argp, &dev_props, sizeof(dev_props)))
  4894				return -EFAULT;
  4895			return 0;
  4896		}
  4897	
  4898		/* it is possible to set only BTRFS_DEV_PROPERTY_TYPE for now */
  4899		if (dev_props.properties & ~(BTRFS_DEV_PROPERTY_TYPE))
  4900			return -EPERM;
  4901	
  4902		trans = btrfs_start_transaction(root, 1);
  4903		if (IS_ERR(trans))
  4904			return PTR_ERR(trans);
  4905	
  4906		prev_type = device->type;
  4907		device->type = dev_props.type;
  4908		ret = btrfs_update_device(trans, device);
  4909	
  4910		if (ret < 0) {
  4911			btrfs_abort_transaction(trans, ret);
  4912			btrfs_end_transaction(trans);
  4913			device->type = prev_type;
  4914			return  ret;
  4915		}
  4916	
  4917		ret = btrfs_commit_transaction(trans);
  4918		if (ret < 0)
  4919			device->type = prev_type;
  4920	
  4921		return ret;
  4922	
> 4923	}
  4924	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 31521 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES.
@ 2021-02-23  4:28     ` kernel test robot
  0 siblings, 0 replies; 13+ messages in thread
From: kernel test robot @ 2021-02-23  4:28 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3848 bytes --]

Hi Goffredo,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on next-20210222]
[cannot apply to v5.11]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Goffredo-Baroncelli/btrfs-add-ioctl-BTRFS_IOC_DEV_PROPERTIES/20210223-062001
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
config: i386-randconfig-r011-20210222 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/62c95ccebf2c45bb8e91d379b454dd720734da34
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Goffredo-Baroncelli/btrfs-add-ioctl-BTRFS_IOC_DEV_PROPERTIES/20210223-062001
        git checkout 62c95ccebf2c45bb8e91d379b454dd720734da34
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   fs/btrfs/ioctl.c: In function 'btrfs_ioctl_dev_properties':
>> fs/btrfs/ioctl.c:4923:1: warning: the frame size of 1036 bytes is larger than 1024 bytes [-Wframe-larger-than=]
    4923 | }
         | ^


vim +4923 fs/btrfs/ioctl.c

  4858	
  4859	static long btrfs_ioctl_dev_properties(struct file *file,
  4860							void __user *argp)
  4861	{
  4862		struct inode *inode = file_inode(file);
  4863		struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
  4864		struct btrfs_ioctl_dev_properties dev_props;
  4865		struct btrfs_device	*device;
  4866		struct btrfs_root *root = fs_info->chunk_root;
  4867		struct btrfs_trans_handle *trans;
  4868		int ret;
  4869		u64 prev_type;
  4870	
  4871		if (!capable(CAP_SYS_ADMIN))
  4872			return -EPERM;
  4873	
  4874		if (copy_from_user(&dev_props, argp, sizeof(dev_props)))
  4875			return -EFAULT;
  4876	
  4877		device = btrfs_find_device(fs_info->fs_devices, dev_props.devid,
  4878					NULL, NULL);
  4879		if (!device) {
  4880			btrfs_info(fs_info, "change_dev_properties: unable to find device %llu",
  4881				   dev_props.devid);
  4882			return -ENODEV;
  4883		}
  4884	
  4885		if (dev_props.properties & BTRFS_DEV_PROPERTY_READ) {
  4886			u64 props = dev_props.properties;
  4887	
  4888			memset(&dev_props, 0, sizeof(dev_props));
  4889			if (props & BTRFS_DEV_PROPERTY_TYPE) {
  4890				dev_props.properties = BTRFS_DEV_PROPERTY_TYPE;
  4891				dev_props.type = device->type;
  4892			}
  4893			if (copy_to_user(argp, &dev_props, sizeof(dev_props)))
  4894				return -EFAULT;
  4895			return 0;
  4896		}
  4897	
  4898		/* it is possible to set only BTRFS_DEV_PROPERTY_TYPE for now */
  4899		if (dev_props.properties & ~(BTRFS_DEV_PROPERTY_TYPE))
  4900			return -EPERM;
  4901	
  4902		trans = btrfs_start_transaction(root, 1);
  4903		if (IS_ERR(trans))
  4904			return PTR_ERR(trans);
  4905	
  4906		prev_type = device->type;
  4907		device->type = dev_props.type;
  4908		ret = btrfs_update_device(trans, device);
  4909	
  4910		if (ret < 0) {
  4911			btrfs_abort_transaction(trans, ret);
  4912			btrfs_end_transaction(trans);
  4913			device->type = prev_type;
  4914			return  ret;
  4915		}
  4916	
  4917		ret = btrfs_commit_transaction(trans);
  4918		if (ret < 0)
  4919			device->type = prev_type;
  4920	
  4921		return ret;
  4922	
> 4923	}
  4924	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 31521 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES.
  2021-02-22 21:19 ` [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES Goffredo Baroncelli
  2021-02-23  4:28     ` kernel test robot
@ 2021-02-23 13:53   ` David Sterba
  2021-02-23 17:59     ` Goffredo Baroncelli
                       ` (2 more replies)
  1 sibling, 3 replies; 13+ messages in thread
From: David Sterba @ 2021-02-23 13:53 UTC (permalink / raw)
  To: Goffredo Baroncelli; +Cc: linux-btrfs, Goffredo Baroncelli

On Mon, Feb 22, 2021 at 10:19:06PM +0100, Goffredo Baroncelli wrote:
> From: Goffredo Baroncelli <kreijack@inwind.it>
> 
> This ioctl is a base for returning / setting information from / to  the
> fields of the btrfs_dev_item object.

Please don't add a new ioctl for properties, they're using the xattr as
interface alrady.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES.
  2021-02-23 13:53   ` David Sterba
@ 2021-02-23 17:59     ` Goffredo Baroncelli
  2021-02-23 18:01       ` Goffredo Baroncelli
  2021-02-24  2:27     ` Anand Jain
  2021-02-27 15:58     ` Zygo Blaxell
  2 siblings, 1 reply; 13+ messages in thread
From: Goffredo Baroncelli @ 2021-02-23 17:59 UTC (permalink / raw)
  To: dsterba, linux-btrfs, Goffredo Baroncelli

On 2/23/21 2:53 PM, David Sterba wrote:
> On Mon, Feb 22, 2021 at 10:19:06PM +0100, Goffredo Baroncelli wrote:
>> From: Goffredo Baroncelli <kreijack@inwind.it>
>>
>> This ioctl is a base for returning / setting information from / to  the
>> fields of the btrfs_dev_item object.

Hi David,

> 
> Please don't add a new ioctl for properties, they're using the xattr as
> interface alrady.
> how it is supposed to work with a device ?

I have to point out that the property is already exported in sysfs.
However I read a comment in sysfs code that discourages
to make a filesystem updating (open a new transaction) in the sysfs
handler. Do you have any suggestion ?

Thanks in advance
BR
Goffredo

-- 
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES.
  2021-02-23 17:59     ` Goffredo Baroncelli
@ 2021-02-23 18:01       ` Goffredo Baroncelli
  0 siblings, 0 replies; 13+ messages in thread
From: Goffredo Baroncelli @ 2021-02-23 18:01 UTC (permalink / raw)
  To: dsterba, linux-btrfs

I resend it because I made a little mess with the quotation

On 2/23/21 6:59 PM, Goffredo Baroncelli wrote:
> On 2/23/21 2:53 PM, David Sterba wrote:
>> On Mon, Feb 22, 2021 at 10:19:06PM +0100, Goffredo Baroncelli wrote:
>>> From: Goffredo Baroncelli <kreijack@inwind.it>
>>>
>>> This ioctl is a base for returning / setting information from / to  the
>>> fields of the btrfs_dev_item object.
> 

Hi David,

> 
>>
>> Please don't add a new ioctl for properties, they're using the xattr as
>> interface alrady.

How it is supposed to work with a device ?
  
I have to point out that the property is already exported in sysfs.
However I read a comment in sysfs code that discourages
to make a filesystem updating (open a new transaction) in the sysfs
handler. Do you have any suggestion ?



> 
> Thanks in advance
> BR
> Goffredo
> 


-- 
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES.
  2021-02-23  4:28     ` kernel test robot
  (?)
@ 2021-02-23 18:03     ` Goffredo Baroncelli
  -1 siblings, 0 replies; 13+ messages in thread
From: Goffredo Baroncelli @ 2021-02-23 18:03 UTC (permalink / raw)
  To: kernel test robot, linux-btrfs; +Cc: kbuild-all, Goffredo Baroncelli

On 2/23/21 5:28 AM, kernel test robot wrote:
> Hi Goffredo,
> 
> Thank you for the patch! Perhaps something to improve:
> 
> [auto build test WARNING on kdave/for-next]
> [also build test WARNING on next-20210222]
> [cannot apply to v5.11]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:    https://github.com/0day-ci/linux/commits/Goffredo-Baroncelli/btrfs-add-ioctl-BTRFS_IOC_DEV_PROPERTIES/20210223-062001
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
> config: i386-randconfig-r011-20210222 (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
> reproduce (this is a W=1 build):
>          # https://github.com/0day-ci/linux/commit/62c95ccebf2c45bb8e91d379b454dd720734da34
>          git remote add linux-review https://github.com/0day-ci/linux
>          git fetch --no-tags linux-review Goffredo-Baroncelli/btrfs-add-ioctl-BTRFS_IOC_DEV_PROPERTIES/20210223-062001
>          git checkout 62c95ccebf2c45bb8e91d379b454dd720734da34
>          # save the attached .config to linux build tree
>          make W=1 ARCH=i386
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):
> 
>     fs/btrfs/ioctl.c: In function 'btrfs_ioctl_dev_properties':
>>> fs/btrfs/ioctl.c:4923:1: warning: the frame size of 1036 bytes is larger than 1024 bytes [-Wframe-larger-than=]
>      4923 | }
>           | ^
> 
> 
> vim +4923 fs/btrfs/ioctl.c
> 
>    4858	
>    4859	static long btrfs_ioctl_dev_properties(struct file *file,
>    4860							void __user *argp)
>    4861	{
>    4862		struct inode *inode = file_inode(file);
>    4863		struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
>    4864		struct btrfs_ioctl_dev_properties dev_props;

Right, now that btrfs_ioctl_dev_properties is large 1k, it is not nice to store it in the stack...


>    4865		struct btrfs_device	*device;
>    4866		struct btrfs_root *root = fs_info->chunk_root;
>    4867		struct btrfs_trans_handle *trans;
>    4868		int ret;
>    4869		u64 prev_type;
>    4870	
>    4871		if (!capable(CAP_SYS_ADMIN))
>    4872			return -EPERM;
>    4873	
>    4874		if (copy_from_user(&dev_props, argp, sizeof(dev_props)))
>    4875			return -EFAULT;
>    4876	
>    4877		device = btrfs_find_device(fs_info->fs_devices, dev_props.devid,
>    4878					NULL, NULL);
>    4879		if (!device) {
>    4880			btrfs_info(fs_info, "change_dev_properties: unable to find device %llu",
>    4881				   dev_props.devid);
>    4882			return -ENODEV;
>    4883		}
>    4884	
>    4885		if (dev_props.properties & BTRFS_DEV_PROPERTY_READ) {
>    4886			u64 props = dev_props.properties;
>    4887	
>    4888			memset(&dev_props, 0, sizeof(dev_props));
>    4889			if (props & BTRFS_DEV_PROPERTY_TYPE) {
>    4890				dev_props.properties = BTRFS_DEV_PROPERTY_TYPE;
>    4891				dev_props.type = device->type;
>    4892			}
>    4893			if (copy_to_user(argp, &dev_props, sizeof(dev_props)))
>    4894				return -EFAULT;
>    4895			return 0;
>    4896		}
>    4897	
>    4898		/* it is possible to set only BTRFS_DEV_PROPERTY_TYPE for now */
>    4899		if (dev_props.properties & ~(BTRFS_DEV_PROPERTY_TYPE))
>    4900			return -EPERM;
>    4901	
>    4902		trans = btrfs_start_transaction(root, 1);
>    4903		if (IS_ERR(trans))
>    4904			return PTR_ERR(trans);
>    4905	
>    4906		prev_type = device->type;
>    4907		device->type = dev_props.type;
>    4908		ret = btrfs_update_device(trans, device);
>    4909	
>    4910		if (ret < 0) {
>    4911			btrfs_abort_transaction(trans, ret);
>    4912			btrfs_end_transaction(trans);
>    4913			device->type = prev_type;
>    4914			return  ret;
>    4915		}
>    4916	
>    4917		ret = btrfs_commit_transaction(trans);
>    4918		if (ret < 0)
>    4919			device->type = prev_type;
>    4920	
>    4921		return ret;
>    4922	
>> 4923	}
>    4924	
> 
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
> 


-- 
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES.
  2021-02-23 13:53   ` David Sterba
  2021-02-23 17:59     ` Goffredo Baroncelli
@ 2021-02-24  2:27     ` Anand Jain
  2021-02-27 15:52       ` Zygo Blaxell
  2021-02-27 15:58     ` Zygo Blaxell
  2 siblings, 1 reply; 13+ messages in thread
From: Anand Jain @ 2021-02-24  2:27 UTC (permalink / raw)
  To: dsterba, Goffredo Baroncelli, linux-btrfs, Goffredo Baroncelli

On 23/02/2021 21:53, David Sterba wrote:
> On Mon, Feb 22, 2021 at 10:19:06PM +0100, Goffredo Baroncelli wrote:
>> From: Goffredo Baroncelli <kreijack@inwind.it>
>>
>> This ioctl is a base for returning / setting information from / to  the
>> fields of the btrfs_dev_item object.
> 
> Please don't add a new ioctl for properties, they're using the xattr as
> interface alrady.
> 

IMO a feature like this can be in memory only initially[1]. And later
when this feature is stable, add its on-disk.

[1] 
https://patchwork.kernel.org/project/linux-btrfs/patch/0ed770d6d5e37fc942f3034d917d2b38477d7d20.1613668002.git.anand.jain@oracle.com/


Thanks, Anand


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES.
  2021-02-24  2:27     ` Anand Jain
@ 2021-02-27 15:52       ` Zygo Blaxell
  0 siblings, 0 replies; 13+ messages in thread
From: Zygo Blaxell @ 2021-02-27 15:52 UTC (permalink / raw)
  To: Anand Jain; +Cc: dsterba, Goffredo Baroncelli, linux-btrfs, Goffredo Baroncelli

On Wed, Feb 24, 2021 at 10:27:45AM +0800, Anand Jain wrote:
> On 23/02/2021 21:53, David Sterba wrote:
> > On Mon, Feb 22, 2021 at 10:19:06PM +0100, Goffredo Baroncelli wrote:
> > > From: Goffredo Baroncelli <kreijack@inwind.it>
> > > 
> > > This ioctl is a base for returning / setting information from / to  the
> > > fields of the btrfs_dev_item object.
> > 
> > Please don't add a new ioctl for properties, they're using the xattr as
> > interface alrady.
> > 
> 
> IMO a feature like this can be in memory only initially[1]. And later
> when this feature is stable, add its on-disk.

The "metadata_only" and "data_only" settings need to be persistent for
the feature to really work.

It is very expensive to recover (need to balance metadata on a spinning
disk) if the filesystem allocates a new chunk after mount but before
userspace can reestablish the preferences.  The whole point of
metadata_only and data_only is that we never have to do that.

> [1] https://patchwork.kernel.org/project/linux-btrfs/patch/0ed770d6d5e37fc942f3034d917d2b38477d7d20.1613668002.git.anand.jain@oracle.com/
> 
> 
> Thanks, Anand
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES.
  2021-02-23 13:53   ` David Sterba
  2021-02-23 17:59     ` Goffredo Baroncelli
  2021-02-24  2:27     ` Anand Jain
@ 2021-02-27 15:58     ` Zygo Blaxell
  2 siblings, 0 replies; 13+ messages in thread
From: Zygo Blaxell @ 2021-02-27 15:58 UTC (permalink / raw)
  To: dsterba, Goffredo Baroncelli, linux-btrfs, Goffredo Baroncelli

On Tue, Feb 23, 2021 at 02:53:30PM +0100, David Sterba wrote:
> On Mon, Feb 22, 2021 at 10:19:06PM +0100, Goffredo Baroncelli wrote:
> > From: Goffredo Baroncelli <kreijack@inwind.it>
> > 
> > This ioctl is a base for returning / setting information from / to  the
> > fields of the btrfs_dev_item object.
> 
> Please don't add a new ioctl for properties, they're using the xattr as
> interface alrady.

We had some earlier discussion about why xattrs on an inode are a
bad idea for this feature:

	https://lore.kernel.org/linux-btrfs/20210123172118.GJ28049@hungrycats.org/

TL;DR they shouldn't be copied from one filesystem to another.

Maybe it's better from a CLI UI point of view to put them under 'btrfs
dev' instead of 'btrfs property'?

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-02-27 15:59 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <cover.1614028083.git.kreijack@inwind.it>
2021-02-22 21:19 ` [PATCH 1/4] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES Goffredo Baroncelli
2021-02-23  4:28   ` kernel test robot
2021-02-23  4:28     ` kernel test robot
2021-02-23 18:03     ` Goffredo Baroncelli
2021-02-23 13:53   ` David Sterba
2021-02-23 17:59     ` Goffredo Baroncelli
2021-02-23 18:01       ` Goffredo Baroncelli
2021-02-24  2:27     ` Anand Jain
2021-02-27 15:52       ` Zygo Blaxell
2021-02-27 15:58     ` Zygo Blaxell
2021-02-22 21:19 ` [PATCH 2/4] btrfs: add flags to give an hint to the chunk allocator Goffredo Baroncelli
2021-02-22 21:19 ` [PATCH 3/4] btrfs: export dev_item.type in /sys/fs/btrfs/<uuid>/devinfo/<devid>/type Goffredo Baroncelli
2021-02-22 21:19 ` [PATCH 4/4] btrfs: add allocator_hint mode Goffredo Baroncelli

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.