From: Goldwyn Rodrigues <rgoldwyn@suse.de>
To: linux-btrfs@vger.kernel.org
Cc: Goldwyn Rodrigues <rgoldwyn@suse.com>
Subject: [PATCH 1/4] btrfs-progs: get_fsid_fd() for getting fsid using fd
Date: Mon, 27 Jul 2020 17:08:09 -0500 [thread overview]
Message-ID: <20200727220812.2187-1-rgoldwyn@suse.de> (raw)
In-Reply-To: <20200727220451.30680-1-rgoldwyn@suse.de>
From: Goldwyn Rodrigues <rgoldwyn@suse.com>
Add a function get_fsid_fd() to use an open file fd to get the
fsid of the mounted filesystem.
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
common/utils.c | 31 +++++++++++++++++--------------
common/utils.h | 1 +
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/common/utils.c b/common/utils.c
index 9742c2e1..8a691846 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -1097,35 +1097,38 @@ out:
return ret;
}
+int get_fsid_fd(int fd, u8 *fsid)
+{
+ int ret;
+ struct btrfs_ioctl_fs_info_args args;
+
+ ret = ioctl(fd, BTRFS_IOC_FS_INFO, &args);
+ if (ret < 0)
+ return -errno;
+
+ memcpy(fsid, args.fsid, BTRFS_FSID_SIZE);
+ return 0;
+}
+
int get_fsid(const char *path, u8 *fsid, int silent)
{
int ret;
int fd;
- struct btrfs_ioctl_fs_info_args args;
fd = open(path, O_RDONLY);
if (fd < 0) {
- ret = -errno;
if (!silent)
error("failed to open %s: %m", path);
- goto out;
- }
-
- ret = ioctl(fd, BTRFS_IOC_FS_INFO, &args);
- if (ret < 0) {
- ret = -errno;
- goto out;
+ return -errno;
}
- memcpy(fsid, args.fsid, BTRFS_FSID_SIZE);
- ret = 0;
+ ret = get_fsid_fd(fd, fsid);
+ close(fd);
-out:
- if (fd != -1)
- close(fd);
return ret;
}
+
static int group_profile_devs_min(u64 flag)
{
switch (flag & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
diff --git a/common/utils.h b/common/utils.h
index 43e7f471..e34bb5a4 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -75,6 +75,7 @@ void close_file_or_dir(int fd, DIR *dirstream);
int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args,
struct btrfs_ioctl_dev_info_args **di_ret);
int get_fsid(const char *path, u8 *fsid, int silent);
+int get_fsid_fd(int fd, u8 *fsid);
int get_label(const char *btrfs_dev, char *label);
int set_label(const char *btrfs_dev, const char *label);
--
2.26.2
next prev parent reply other threads:[~2020-07-27 22:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-27 22:04 [PATCH 0/3] btrfs: Enumerate and export exclusive operations Goldwyn Rodrigues
2020-07-27 22:04 ` [PATCH 1/3] btrfs: enumerate the type of exclusive operation in progress Goldwyn Rodrigues
2020-07-28 8:45 ` Johannes Thumshirn
2020-07-27 22:04 ` [PATCH 2/3] btrfs: export currently executing exclusive operation via sysfs Goldwyn Rodrigues
2020-07-27 22:04 ` [PATCH 3/3] btrfs: add more information for balance Goldwyn Rodrigues
2020-07-27 22:08 ` Goldwyn Rodrigues [this message]
2020-07-27 22:08 ` [PATCH 2/4] btrfs-progs: add sysfs file reading functions Goldwyn Rodrigues
2020-07-27 22:08 ` [PATCH 3/4] btrfs-progs: Check for exclusive operation before issuing ioctl Goldwyn Rodrigues
2020-07-27 22:08 ` [PATCH 4/4] btrfs-progs: Enqueue command if it can't be performed immediately Goldwyn Rodrigues
2020-07-28 8:38 ` [PATCH 1/4] btrfs-progs: get_fsid_fd() for getting fsid using fd Johannes Thumshirn
-- strict thread matches above, loose matches on Subject: below --
2020-08-03 20:29 [PATCH v2 0/3] btrfs: Enumerate and export exclusive operations Goldwyn Rodrigues
2020-08-03 20:30 ` [PATCH 1/4] btrfs-progs: get_fsid_fd() for getting fsid using fd Goldwyn Rodrigues
2020-08-25 15:02 [PATCH v3 0/2] btrfs: Enumerate and export exclusive operations Goldwyn Rodrigues
2020-08-25 15:03 ` [PATCH 1/4] btrfs-progs: get_fsid_fd() for getting fsid using fd Goldwyn Rodrigues
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=20200727220812.2187-1-rgoldwyn@suse.de \
--to=rgoldwyn@suse.de \
--cc=linux-btrfs@vger.kernel.org \
--cc=rgoldwyn@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox