From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: Anand Jain <anand.jain@oracle.com>
Subject: [PATCH 06/11] btrfs-progs: factor out btrfs_scan_stdin_devices
Date: Wed, 7 Jun 2023 17:59:11 +0800 [thread overview]
Message-ID: <44721179d1ba7264ba8bdbbd160dde414ff3861d.1686131669.git.anand.jain@oracle.com> (raw)
In-Reply-To: <cover.1686131669.git.anand.jain@oracle.com>
As a preparatory to take btrfstune device list from the arguments factor
out btrfs_scan_stdin_devices().
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
cmds/inspect-dump-tree.c | 37 +++----------------------------------
common/device-scan.c | 39 +++++++++++++++++++++++++++++++++++++++
common/device-scan.h | 1 +
3 files changed, 43 insertions(+), 34 deletions(-)
diff --git a/cmds/inspect-dump-tree.c b/cmds/inspect-dump-tree.c
index 35920d14b7e9..311dfbfddab6 100644
--- a/cmds/inspect-dump-tree.c
+++ b/cmds/inspect-dump-tree.c
@@ -327,7 +327,6 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,
bool roots_only = false;
bool root_backups = false;
int traverse = BTRFS_PRINT_TREE_DEFAULT;
- int dev_optind;
unsigned open_ctree_flags;
u64 block_bytenr;
struct btrfs_root *tree_root_scan;
@@ -456,39 +455,9 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,
if (check_argc_min(argc - optind, 1))
return 1;
- dev_optind = optind;
- while (dev_optind < argc) {
- int fd;
- struct btrfs_fs_devices *fs_devices;
- u64 num_devices;
-
- ret = check_arg_type(argv[optind]);
- if (ret != BTRFS_ARG_BLKDEV && ret != BTRFS_ARG_REG) {
- if (ret < 0) {
- errno = -ret;
- error("invalid argument %s: %m", argv[dev_optind]);
- } else {
- error("not a block device or regular file: %s",
- argv[dev_optind]);
- }
- }
- fd = open(argv[dev_optind], O_RDONLY);
- if (fd < 0) {
- error("cannot open %s: %m", argv[dev_optind]);
- return -EINVAL;
- }
- ret = btrfs_scan_one_device(fd, argv[dev_optind], &fs_devices,
- &num_devices,
- BTRFS_SUPER_INFO_OFFSET,
- SBREAD_DEFAULT);
- close(fd);
- if (ret < 0) {
- errno = -ret;
- error("device scan %s: %m", argv[dev_optind]);
- return ret;
- }
- dev_optind++;
- }
+ ret = btrfs_scan_stdin_devices(optind, argc, argv);
+ if (ret)
+ return ret;
pr_verbose(LOG_DEFAULT, "%s\n", PACKAGE_STRING);
diff --git a/common/device-scan.c b/common/device-scan.c
index 515481a6efa9..38f986df810f 100644
--- a/common/device-scan.c
+++ b/common/device-scan.c
@@ -500,3 +500,42 @@ int btrfs_scan_devices(int verbose)
return 0;
}
+int btrfs_scan_stdin_devices(int dev_optind, int argc, char **argv)
+{
+ int ret;
+
+ while (dev_optind < argc) {
+ int fd;
+ u64 num_devices;
+ struct btrfs_fs_devices *fs_devices;
+
+ ret = check_arg_type(argv[optind]);
+ if (ret != BTRFS_ARG_BLKDEV && ret != BTRFS_ARG_REG) {
+ if (ret < 0) {
+ errno = -ret;
+ error("invalid argument %s: %m", argv[dev_optind]);
+ } else {
+ error("not a block device or regular file: %s",
+ argv[dev_optind]);
+ }
+ }
+ fd = open(argv[dev_optind], O_RDONLY);
+ if (fd < 0) {
+ error("cannot open %s: %m", argv[dev_optind]);
+ return -EINVAL;
+ }
+ ret = btrfs_scan_one_device(fd, argv[dev_optind], &fs_devices,
+ &num_devices,
+ BTRFS_SUPER_INFO_OFFSET,
+ SBREAD_DEFAULT);
+ close(fd);
+ if (ret < 0) {
+ errno = -ret;
+ error("device scan %s: %m", argv[dev_optind]);
+ return ret;
+ }
+ dev_optind++;
+ }
+
+ return 0;
+}
diff --git a/common/device-scan.h b/common/device-scan.h
index f805b489f595..e2480d3eb168 100644
--- a/common/device-scan.h
+++ b/common/device-scan.h
@@ -58,5 +58,6 @@ int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[],
int fd, DIR *dirstream);
void free_seen_fsid(struct seen_fsid *seen_fsid_hash[]);
int test_uuid_unique(const char *uuid_str);
+int btrfs_scan_stdin_devices(int dev_optind, int argc, char **argv);
#endif
--
2.31.1
next prev parent reply other threads:[~2023-06-07 10:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-07 9:59 [PATCH 0/9] btrfs-progs: btrfstune: accept multiple devices and cleanup Anand Jain
2023-06-07 9:59 ` [PATCH 01/11] btrfs-progs: check_mounted_where declare is_btrfs as bool Anand Jain
2023-06-07 9:59 ` [PATCH 02/11] btrfs-progs: check_mounted_where pack varibles type by size Anand Jain
2023-06-07 9:59 ` [PATCH 03/11] btrfs-progs: rename struct open_ctree_flags to open_ctree_args Anand Jain
2023-06-07 9:59 ` [PATCH 04/11] btrfs-progs: optimize device_list_add Anand Jain
2023-06-07 9:59 ` [PATCH 05/11] btrfs-progs: simplify btrfs_scan_one_device() Anand Jain
2023-06-07 9:59 ` Anand Jain [this message]
2023-06-07 9:59 ` [PATCH 07/11] btrfs-progs: tune: add stdin device list Anand Jain
2023-06-07 9:59 ` [PATCH 08/11] btrfs-progs: refactor check_where_mounted with noscan option Anand Jain
2023-06-07 9:59 ` [PATCH 09/11] btrfs-progs: tune: add " Anand Jain
2023-06-07 9:59 ` [PATCH 10/11] btrfs-progs: tune: add help for multiple devices and " Anand Jain
2023-06-07 9:59 ` [PATCH 11/11] btrfs-progs: Documentation: update btrfstune --noscan option Anand Jain
2023-06-07 10:43 ` [PATCH 0/9] btrfs-progs: btrfstune: accept multiple devices and cleanup Anand Jain
2023-06-07 11:06 ` Qu Wenruo
2023-06-08 0:20 ` Anand Jain
2023-06-08 1:42 ` Qu Wenruo
2023-06-08 4:26 ` Anand Jain
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=44721179d1ba7264ba8bdbbd160dde414ff3861d.1686131669.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).