Skip to contentSkip to conversation

btrfs-progs: allocation_hint disk property

PATCH New Goffredo Baroncelli 1 participant 3 messages Feb 22, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover btrfs-progs: allocation_hint disk property

From: Goffredo Baroncelli <[email protected]>

This patches set is the userspace portion of the serie "[PATCH V7] btrfs: allocation_hint mode".

Look this patches set for further information.

G.Baroncelli

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

Goffredo Baroncelli (2):
btrfs-progs: add ioctl BTRFS_IOC_DEV_PROPERTIES.
btrfs-progs: new "allocation_hint" property.

 ioctl.h               |  39 ++++++++++
 kernel-shared/ctree.h |  15 ++++
 props.c               | 171 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 225 insertions(+)
Signature · 1 line
2.30.0
#1 lore raw

PATCH 1/2 btrfs-progs: add ioctl BTRFS_IOC_DEV_PROPERTIES.

From: Goffredo Baroncelli <[email protected]>

Update the header to add the BTRFS_IOC_DEV_PROPERTIES ioctl:
- add ioctl BTRFS_IOC_DEV_PROPERTIES define
- add struct btrfs_ioctl_dev_properties
- add the BTRFS_DEV_PROPERTY_ define

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.

---
 ioctl.h | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
ioctl.h +39 -0
index ade6dcb9..22a9c7a3 100644
@@ -775,6 +775,43 @@ struct btrfs_ioctl_get_subvol_rootref_args {
 };
 BUILD_ASSERT(sizeof(struct btrfs_ioctl_get_subvol_rootref_args) == 4096);
 
+#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 {
 	notused,
@@ -949,6 +986,8 @@ static inline char *btrfs_err_str(enum btrfs_err_code 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)
 
 #ifdef __cplusplus
 }
Signature · 1 line
2.30.0
#2 lore raw

PATCH 2/2 btrfs-progs: new "allocation_hint" property.

In reply to Goffredo Baroncelli

From: Goffredo Baroncelli <[email protected]>

Handle the property allocation_hint of a btrfs device. Below an example of use:

$ # set a new value
$ sudo btrfs property set /dev/vde allocation_hint DATA_ONLY
$ # get the current value
$ sudo btrfs property get /dev/vde allocation_hint
devid=4, path=/dev/vde: dedicated_metadata=DATA_ONLY

The following properties are availables:
- DATA_ONLY
- PREFERRED_DATA (default)
- PREFERRED_METADATA
- METADATA_ONLY

Root privileges are required.

---
 kernel-shared/ctree.h |  15 ++++
 props.c               | 171 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+)
kernel-shared/ctree.h +15 -0
index 7683b8bb..1c9cb22d 100644
@@ -219,6 +219,21 @@ struct btrfs_mapping_tree {
 	struct cache_tree cache_tree;
 };
 
+/* btrfs chunk allocation hints */
+#define BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT    3
+#define BTRFS_DEV_ALLOCATION_MASK ((1ULL << \
+	       BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT) - 1)
+/* 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)
+/* preferred data chunk, but metadata chunk allowed */
+#define BTRFS_DEV_ALLOCATION_PREFERRED_DATA    (0ULL)
+/* 5..7 are unused values */
+
+
 #define BTRFS_UUID_SIZE 16
 struct btrfs_dev_item {
 	/* the internal btrfs device id */
props.c +171 -0

188 lines not on this page · raw message

Signature · 1 line
2.30.0