All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Rostecki <mrostecki@suse.de>
To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org (open list:BTRFS FILE SYSTEM),
	linux-kernel@vger.kernel.org (open list)
Cc: Michal Rostecki <mrostecki@suse.com>
Subject: [PATCH RFC 5/6] btrfs: sysfs: Add directory for read policies
Date: Tue,  9 Feb 2021 21:30:39 +0100	[thread overview]
Message-ID: <20210209203041.21493-6-mrostecki@suse.de> (raw)
In-Reply-To: <20210209203041.21493-1-mrostecki@suse.de>

From: Michal Rostecki <mrostecki@suse.com>

Before this change, raid1 read policy could be selected by using the
/sys/fs/btrfs/[fsid]/read_policy file.

Change it to /sys/fs/btrfs/[fsid]/read_policies/policy.

The motivation behing creating the read_policies directory is that the
next changes and new read policies are going to intruduce settings
specific to read policies.

Signed-off-by: Michal Rostecki <mrostecki@suse.com>
---
 fs/btrfs/sysfs.c   | 51 +++++++++++++++++++++++++++++++++-------------
 fs/btrfs/volumes.h |  1 +
 2 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 19b9fffa2c9c..a8f528eb4e50 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -896,6 +896,19 @@ static ssize_t btrfs_generation_show(struct kobject *kobj,
 }
 BTRFS_ATTR(, generation, btrfs_generation_show);
 
+static const struct attribute *btrfs_attrs[] = {
+	BTRFS_ATTR_PTR(, label),
+	BTRFS_ATTR_PTR(, nodesize),
+	BTRFS_ATTR_PTR(, sectorsize),
+	BTRFS_ATTR_PTR(, clone_alignment),
+	BTRFS_ATTR_PTR(, quota_override),
+	BTRFS_ATTR_PTR(, metadata_uuid),
+	BTRFS_ATTR_PTR(, checksum),
+	BTRFS_ATTR_PTR(, exclusive_operation),
+	BTRFS_ATTR_PTR(, generation),
+	NULL,
+};
+
 /*
  * Look for an exact string @string in @buffer with possible leading or
  * trailing whitespace
@@ -920,7 +933,7 @@ static const char * const btrfs_read_policy_name[] = { "pid" };
 static ssize_t btrfs_read_policy_show(struct kobject *kobj,
 				      struct kobj_attribute *a, char *buf)
 {
-	struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj);
+	struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj->parent);
 	ssize_t ret = 0;
 	int i;
 
@@ -944,7 +957,7 @@ static ssize_t btrfs_read_policy_store(struct kobject *kobj,
 				       struct kobj_attribute *a,
 				       const char *buf, size_t len)
 {
-	struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj);
+	struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj->parent);
 	int i;
 
 	for (i = 0; i < BTRFS_NR_READ_POLICY; i++) {
@@ -961,19 +974,10 @@ static ssize_t btrfs_read_policy_store(struct kobject *kobj,
 
 	return -EINVAL;
 }
-BTRFS_ATTR_RW(, read_policy, btrfs_read_policy_show, btrfs_read_policy_store);
+BTRFS_ATTR_RW(read_policies, policy, btrfs_read_policy_show, btrfs_read_policy_store);
 
-static const struct attribute *btrfs_attrs[] = {
-	BTRFS_ATTR_PTR(, label),
-	BTRFS_ATTR_PTR(, nodesize),
-	BTRFS_ATTR_PTR(, sectorsize),
-	BTRFS_ATTR_PTR(, clone_alignment),
-	BTRFS_ATTR_PTR(, quota_override),
-	BTRFS_ATTR_PTR(, metadata_uuid),
-	BTRFS_ATTR_PTR(, checksum),
-	BTRFS_ATTR_PTR(, exclusive_operation),
-	BTRFS_ATTR_PTR(, generation),
-	BTRFS_ATTR_PTR(, read_policy),
+static const struct attribute *read_policies_attrs[] = {
+	BTRFS_ATTR_PTR(read_policies, policy),
 	NULL,
 };
 
@@ -1112,6 +1116,12 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)
 
 	sysfs_remove_link(fsid_kobj, "bdi");
 
+	if (fs_info->fs_devices->read_policies_kobj) {
+		sysfs_remove_files(fs_info->fs_devices->read_policies_kobj,
+				   read_policies_attrs);
+		kobject_del(fs_info->fs_devices->read_policies_kobj);
+		kobject_put(fs_info->fs_devices->read_policies_kobj);
+	}
 	if (fs_info->space_info_kobj) {
 		sysfs_remove_files(fs_info->space_info_kobj, allocation_attrs);
 		kobject_del(fs_info->space_info_kobj);
@@ -1658,6 +1668,19 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
 	if (error)
 		goto failure;
 
+	fs_devs->read_policies_kobj = kobject_create_and_add("read_policies",
+							     fsid_kobj);
+
+	if (!fs_devs->read_policies_kobj) {
+		error = -ENOMEM;
+		goto failure;
+	}
+
+	error = sysfs_create_files(fs_devs->read_policies_kobj,
+				   read_policies_attrs);
+	if (error)
+		goto failure;
+
 	return 0;
 failure:
 	btrfs_sysfs_remove_mounted(fs_info);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 594f1207281c..ee050fd48042 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -287,6 +287,7 @@ struct btrfs_fs_devices {
 	struct kobject fsid_kobj;
 	struct kobject *devices_kobj;
 	struct kobject *devinfo_kobj;
+	struct kobject *read_policies_kobj;
 	struct completion kobj_unregister;
 
 	enum btrfs_chunk_allocation_policy chunk_alloc_policy;
-- 
2.30.0


  parent reply	other threads:[~2021-02-09 20:40 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 20:30 [PATCH RFC 0/6] Add roundrobin raid1 read policy Michal Rostecki
2021-02-09 20:30 ` [PATCH RFC 1/6] btrfs: Add inflight BIO request counter Michal Rostecki
2021-02-09 20:30 ` [PATCH RFC 2/6] btrfs: Store the last device I/O offset Michal Rostecki
2021-02-09 20:30 ` [PATCH RFC 3/6] btrfs: Add stripe_physical function Michal Rostecki
2021-02-09 20:30 ` [PATCH RFC 4/6] btrfs: Check if the filesystem is has mixed type of devices Michal Rostecki
2021-02-10  4:08   ` Michał Mirosław
2021-02-10 12:50     ` Michal Rostecki
2021-02-12 18:26     ` Michal Rostecki
2021-02-12 23:36       ` Michał Mirosław
2021-02-15 14:40         ` Michal Rostecki
2021-02-10  8:09   ` Dan Carpenter
2021-02-10  8:09     ` Dan Carpenter
2021-02-10 10:09   ` Filipe Manana
2021-02-10 12:55     ` Michal Rostecki
2021-02-09 20:30 ` Michal Rostecki [this message]
2021-02-13 10:19   ` [PATCH RFC 5/6] btrfs: sysfs: Add directory for read policies Greg KH
2021-02-15 14:35     ` Michal Rostecki
2021-02-15 14:59       ` Greg KH
2021-02-09 20:30 ` [PATCH RFC 6/6] btrfs: Add roundrobin raid1 read policy Michal Rostecki
2021-02-10  4:24   ` Michał Mirosław
2021-02-10 12:29     ` Michal Rostecki
2021-02-10 12:58       ` Michał Mirosław
2021-02-10 19:23         ` Michal Rostecki
2021-02-11  2:27           ` Michał Mirosław
2021-02-11 12:35             ` Michal Rostecki
2021-02-10  8:20   ` Anand Jain
2021-02-11 15:55     ` Michal Rostecki
2021-02-12 17:12       ` Michal Rostecki
2021-02-10  6:52 ` [PATCH RFC 0/6] " Anand Jain
2021-02-10 12:18   ` Michal Rostecki
2021-02-10 14:00     ` Michal Rostecki

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=20210209203041.21493-6-mrostecki@suse.de \
    --to=mrostecki@suse.de \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mrostecki@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.