All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/2] btrfs-progs: prepare helper device_is_seed
Date: Tue, 19 Oct 2021 08:23:44 +0800	[thread overview]
Message-ID: <25c937de157f6a14f389e73c1198b779cfb0b5c3.1634598659.git.anand.jain@oracle.com> (raw)
In-Reply-To: <cover.1634598659.git.anand.jain@oracle.com>

load_device_info() checks if the device is a seed device by reading
superblock::fsid and comparing it with the mount fsid, and it fails
to work if the device is missing (a RAID1 seed fs). Move this part
of the code into a new helper function device_is_seed() in
preparation to make device_is_seed() work with the new sysfs
devinfo/<devid>/fsid interface.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds/filesystem-usage.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c
index 6c0f9aa977d6..0dfc798e8dcc 100644
--- a/cmds/filesystem-usage.c
+++ b/cmds/filesystem-usage.c
@@ -25,6 +25,7 @@
 #include <getopt.h>
 #include <fcntl.h>
 #include <linux/limits.h>
+#include <uuid/uuid.h>
 
 #include "common/utils.h"
 #include "kerncompat.h"
@@ -705,6 +706,21 @@ out:
 	return ret;
 }
 
+static int device_is_seed(const char *dev_path, u8 *mnt_fsid)
+{
+	uuid_t fsid;
+	int ret;
+
+	ret = dev_to_fsid(dev_path, fsid);
+	if (ret)
+		return ret;
+
+	if (memcmp(mnt_fsid, fsid, BTRFS_FSID_SIZE))
+		return 0;
+
+	return -1;
+}
+
 /*
  *  This function loads the device_info structure and put them in an array
  */
@@ -715,7 +731,6 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
 	struct btrfs_ioctl_fs_info_args fi_args;
 	struct btrfs_ioctl_dev_info_args dev_info;
 	struct device_info *info;
-	u8 fsid[BTRFS_UUID_SIZE];
 
 	*device_info_count = 0;
 	*device_info_ptr = NULL;
@@ -759,8 +774,8 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
 		 * Ignore any other error including -EACCES, which is seen when
 		 * a non-root process calls dev_to_fsid(path)->open(path).
 		 */
-		ret = dev_to_fsid((const char *)dev_info.path, fsid);
-		if (!ret && memcmp(fi_args.fsid, fsid, BTRFS_FSID_SIZE) != 0)
+		ret = device_is_seed((const char *)dev_info.path, fi_args.fsid);
+		if (!ret)
 			continue;
 
 		info[ndevs].devid = dev_info.devid;
-- 
2.31.1


  reply	other threads:[~2021-10-19  0:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19  0:23 [PATCH 0/2] btrfs-progs: read device fsid from the sysfs Anand Jain
2021-10-19  0:23 ` Anand Jain [this message]
2021-10-19  0:23 ` [PATCH 2/2] btrfs-progs: read fsid from the sysfs in device_is_seed Anand Jain
2021-10-19 14:03   ` Josef Bacik
2021-10-20  2:40     ` Anand Jain
2021-10-20 13:47       ` Josef Bacik
2021-10-19 14:04 ` [PATCH 0/2] btrfs-progs: read device fsid from the sysfs Josef Bacik
2021-10-20  2:41   ` Anand Jain
2022-01-06  0:04 ` Anand Jain
2022-01-11 15:19   ` Nikolay Borisov
2022-01-21  9:29     ` Anand Jain
2022-08-26  0:14       ` Wang Yugui
2022-08-26 10:18         ` Anand Jain
2022-08-27  0:52           ` Wang Yugui
2022-08-10 10:18 ` Qu Wenruo
2022-08-10 11:18   ` Anand Jain
2022-08-10 11:43     ` Qu Wenruo
2023-02-13  9:37 [PATCH v2 " Anand Jain
2023-02-13  9:37 ` [PATCH 1/2] btrfs-progs: prepare helper device_is_seed Anand Jain
2023-02-21 23:16   ` David Sterba

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=25c937de157f6a14f389e73c1198b779cfb0b5c3.1634598659.git.anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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.