btrfs-progs: cleanup and preparatory around device scan
v3 cover btrfs-progs: cleanup and preparatory around device scan
v3: Contains fixes as per review comments; details are in the individual
patches.
Patches dropped:
btrfs-progs: check_mounted_where: pack varibles type by size
btrfs-progs: btrfs_scan_one_device: drop local variable ret
Patch added:
btrfs-progs: drop open_ctree_flags in cmd_inspect_dump_tree
v2: I have separated preparatory and cleanups from the introduction of new
features so that they can be easily modified with a smaller set of patches.
Added missing git changelogs. (Looks like sshfs lost my last few changes, now fixed).
--- original cover page ---
In an attempt to enable btrfstune to accept multiple devices from the command line, this patch includes some cleanup around the related preparatory work around the device scan code.
Patches 1 to 5 primarily consist of cleanups. Patches 6 and 7 serve as preparatory changes.
Anand Jain (6):
btrfs-progs: check_mounted_where: declare is_btrfs as bool
btrfs-progs: rename struct open_ctree_flags to open_ctree_args
btrfs-progs: drop open_ctree_flags in cmd_inspect_dump_tree
btrfs-progs: device_list_add: optimize arguments drop devid
btrfs-progs: factor out btrfs_scan_argv_devices
btrfs-progs: refactor check_where_mounted with noscan argument
btrfs-find-root.c | 8 +++--- check/main.c | 14 +++++----- cmds/filesystem.c | 8 +++--- cmds/inspect-dump-tree.c | 55 ++++++++-------------------------------- cmds/rescue.c | 16 ++++++------ cmds/restore.c | 12 ++++----- common/device-scan.c | 40 +++++++++++++++++++++++++++++ common/device-scan.h | 1 + common/open-utils.c | 11 +++++--- common/open-utils.h | 3 ++- common/utils.c | 3 ++- image/main.c | 16 ++++++------ kernel-shared/disk-io.c | 50 ++++++++++++++++++------------------ kernel-shared/disk-io.h | 4 +-- kernel-shared/volumes.c | 10 +++----- mkfs/main.c | 8 +++--- tune/main.c | 2 +- 17 files changed, 136 insertions(+), 125 deletions(-)
Signature · 1 line
2.38.1
PATCH v3 1/6 btrfs-progs: check_mounted_where: declare is_btrfs as bool
The variable 'is_btrfs' is declared as an integer but could be a boolean instead.
--- common/open-utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/open-utils.c +1 -1
@@ -57,7 +57,7 @@ int check_mounted_where(int fd, const char *file, char *where, int size, {int ret;u64 total_devs =1 ; -int is_btrfs; +bool is_btrfs;struct btrfs_fs_devices *fs_devices_mnt =NULL ;FILE *f;struct mntent *mnt;
Signature · 1 line
2.38.1
PATCH v3 2/6 btrfs-progs: rename struct open_ctree_flags to open_ctree_args
In reply to Anand JainThe struct open_ctree_flags currently holds arguments for open_ctree_fs_info(), it can be confusing when mixed with a local variable named open_ctree_flags as below in the function cmd_inspect_dump_tree().
cmd_inspect_dump_tree()
::
struct open_ctree_flags ocf = { 0 };
::
unsigned open_ctree_flags;So rename struct open_ctree_flags to struct open_ctree_args.
---
v3: Also rename struct open_ctree_args' variable to oca.
btrfs-find-root.c | 8 +++---- check/main.c | 14 +++++------ cmds/filesystem.c | 8 +++---- cmds/inspect-dump-tree.c | 8 +++---- cmds/rescue.c | 16 ++++++------- cmds/restore.c | 12 +++++----- image/main.c | 16 ++++++------- kernel-shared/disk-io.c | 50 ++++++++++++++++++++-------------------- kernel-shared/disk-io.h | 4 ++-- mkfs/main.c | 8 +++---- 10 files changed, 72 insertions(+), 72 deletions(-)
btrfs-find-root.c +4 -4
@@ -335,7 +335,7 @@ int main(int argc, char **argv)struct btrfs_find_root_filter filter = {0 };struct cache_tree result;struct cache_extent *found; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };int ret;/* Default to search root tree */
@@ -378,9 +378,9 @@ int main(int argc, char **argv)if (check_argc_min (argc - optind,1 ))return 1 ; - ocf.filename = argv[optind]; - ocf.flags =OPEN_CTREE_CHUNK_ROOT_ONLY |OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR ; - fs_info =open_ctree_fs_info (&ocf); + oca.filename = argv[optind]; + oca.flags =OPEN_CTREE_CHUNK_ROOT_ONLY |OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR ; + fs_info =open_ctree_fs_info (&oca);if (!fs_info) {error ("open ctree failed" );return 1 ;
check/main.c +7 -7
@@ -9983,7 +9983,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) {struct cache_tree root_cache;struct btrfs_root *root; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };u64 bytenr =0 ;u64 subvolid =0 ;u64 tree_root_bytenr =0 ;
@@ -10204,12 +10204,12 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)if (opt_check_repair) ctree_flags |=OPEN_CTREE_PARTIAL ; - ocf.filename = argv[optind]; - ocf.sb_bytenr = bytenr; - ocf.root_tree_bytenr = tree_root_bytenr; - ocf.chunk_tree_bytenr = chunk_root_bytenr; - ocf.flags = ctree_flags; - gfs_info =open_ctree_fs_info (&ocf); + oca.filename = argv[optind]; + oca.sb_bytenr = bytenr; + oca.root_tree_bytenr = tree_root_bytenr; + oca.chunk_tree_bytenr = chunk_root_bytenr; + oca.flags = ctree_flags; + gfs_info =open_ctree_fs_info (&oca);if (!gfs_info) {error ("cannot open file system" ); ret = -EIO ;
cmds/filesystem.c +4 -4
@@ -636,7 +636,7 @@ static int map_seed_devices(struct list_head *all_uuids) fs_uuids =btrfs_scanned_uuids ();list_for_each_entry (cur_fs, all_uuids, list) { -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 }; device =list_first_entry (&cur_fs->devices, struct btrfs_device, dev_list);
@@ -650,9 +650,9 @@ static int map_seed_devices(struct list_head *all_uuids)/* * open_ctree_* detects seed/sprout mapping */ - ocf.filename = device->name; - ocf.flags =OPEN_CTREE_PARTIAL ; - fs_info =open_ctree_fs_info (&ocf); + oca.filename = device->name; + oca.flags =OPEN_CTREE_PARTIAL ; + fs_info =open_ctree_fs_info (&oca);if (!fs_info)continue ;
cmds/inspect-dump-tree.c +4 -4
@@ -317,7 +317,7 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,struct btrfs_disk_key disk_key;struct btrfs_key found_key;struct cache_tree block_root;/* for multiple --block parameters */ -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };char uuidbuf[BTRFS_UUID_UNPARSED_SIZE ];int ret =0 ;int slot;
@@ -492,9 +492,9 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,pr_verbose (LOG_DEFAULT ,"%s\n" ,PACKAGE_STRING ); - ocf.filename = argv[optind]; - ocf.flags = open_ctree_flags; - info =open_ctree_fs_info (&ocf); + oca.filename = argv[optind]; + oca.flags = open_ctree_flags; + info =open_ctree_fs_info (&oca);if (!info) {error ("unable to open %s" , argv[optind]); goto out;
cmds/rescue.c +8 -8
@@ -233,7 +233,7 @@ static int cmd_rescue_fix_device_size(const struct cmd_struct *cmd, int argc, char **argv) { struct btrfs_fs_info *fs_info; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };char *devname;int ret;
@@ -254,9 +254,9 @@ static int cmd_rescue_fix_device_size(const struct cmd_struct *cmd, goto out; } - ocf.filename = devname; - ocf.flags =OPEN_CTREE_WRITES |OPEN_CTREE_PARTIAL ; - fs_info =open_ctree_fs_info (&ocf); + oca.filename = devname; + oca.flags =OPEN_CTREE_WRITES |OPEN_CTREE_PARTIAL ; + fs_info =open_ctree_fs_info (&oca);if (!fs_info) {error ("could not open btrfs" ); ret = -EIO ;
@@ -368,7 +368,7 @@ static int cmd_rescue_clear_uuid_tree(const struct cmd_struct *cmd, int argc, char **argv) { struct btrfs_fs_info *fs_info; -struct open_ctree_flags ocf = {}; +struct open_ctree_args oca = {};char *devname;int ret;
@@ -387,9 +387,9 @@ static int cmd_rescue_clear_uuid_tree(const struct cmd_struct *cmd, ret = -EBUSY ; goto out; } - ocf.filename = devname; - ocf.flags =OPEN_CTREE_WRITES |OPEN_CTREE_PARTIAL ; - fs_info =open_ctree_fs_info (&ocf); + oca.filename = devname; + oca.flags =OPEN_CTREE_WRITES |OPEN_CTREE_PARTIAL ; + fs_info =open_ctree_fs_info (&oca);if (!fs_info) {error ("could not open btrfs" ); ret = -EIO ;
cmds/restore.c +6 -6
@@ -1216,7 +1216,7 @@ static struct btrfs_root *open_fs(const char *dev, u64 root_location, {struct btrfs_fs_info *fs_info =NULL ;struct btrfs_root *root =NULL ; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };u64 bytenr;int i;
@@ -1228,12 +1228,12 @@ static struct btrfs_root *open_fs(const char *dev, u64 root_location,* in extent tree. Skip block group item search will allow * restore to be executed on heavily damaged fs. */ - ocf.filename = dev; - ocf.sb_bytenr = bytenr; - ocf.root_tree_bytenr = root_location; - ocf.flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_NO_BLOCK_GROUPS | + oca.filename = dev; + oca.sb_bytenr = bytenr; + oca.root_tree_bytenr = root_location; + oca.flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_NO_BLOCK_GROUPS |OPEN_CTREE_ALLOW_TRANSID_MISMATCH ; - fs_info =open_ctree_fs_info (&ocf); + fs_info =open_ctree_fs_info (&oca);if (fs_info)break ;pr_stderr (LOG_DEFAULT ,"Could not open root, trying backup super\n" );
image/main.c +8 -8
@@ -2795,12 +2795,12 @@ static int restore_metadump(const char *input, FILE *out, int old_restore,/* NOTE: open with write mode */ if (fixup_offset) { -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 }; - ocf.filename = target; - ocf.flags =OPEN_CTREE_WRITES |OPEN_CTREE_RESTORE | + oca.filename = target; + oca.flags =OPEN_CTREE_WRITES |OPEN_CTREE_RESTORE |OPEN_CTREE_PARTIAL |OPEN_CTREE_SKIP_LEAF_ITEM_CHECKS ; - info =open_ctree_fs_info (&ocf); + info =open_ctree_fs_info (&oca);if (!info) {error ("open ctree failed" ); ret = -EIO ;
@@ -3223,15 +3223,15 @@ int BOX_MAIN(image)(int argc, char *argv[])/* extended support for multiple devices */ if (!create && multi_devices) { -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };struct btrfs_fs_info *info;u64 total_devs;int i; - ocf.filename = target; - ocf.flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_RESTORE | + oca.filename = target; + oca.flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_RESTORE |OPEN_CTREE_SKIP_LEAF_ITEM_CHECKS ; - info =open_ctree_fs_info (&ocf); + info =open_ctree_fs_info (&oca);if (!info) {error ("open ctree failed at %s" , target);return 1 ;
kernel-shared/disk-io.c +25 -25
127 lines not on this page · raw message
kernel-shared/disk-io.h +2 -2
@@ -175,7 +175,7 @@ struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, unsigned flags);struct btrfs_root *open_ctree_fd (int fp,const char *path,u64 sb_bytenr,unsigned flags); -struct open_ctree_flags { +struct open_ctree_args {const char *filename;u64 sb_bytenr;u64 root_tree_bytenr;
@@ -183,7 +183,7 @@ struct open_ctree_flags {unsigned flags; }; -struct btrfs_fs_info *open_ctree_fs_info (struct open_ctree_flags *ocf); +struct btrfs_fs_info *open_ctree_fs_info (struct open_ctree_args *oca);int close_ctree_fs_info (struct btrfs_fs_info *fs_info);static inline int close_ctree (struct btrfs_root *root) {
mkfs/main.c +4 -4
@@ -990,7 +990,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)struct btrfs_root *root;struct btrfs_fs_info *fs_info;struct btrfs_trans_handle *trans; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };int ret =0 ;int close_ret;int i;
@@ -1569,9 +1569,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv) goto error; } - ocf.filename = file; - ocf.flags =OPEN_CTREE_WRITES |OPEN_CTREE_TEMPORARY_SUPER ; - fs_info =open_ctree_fs_info (&ocf); + oca.filename = file; + oca.flags =OPEN_CTREE_WRITES |OPEN_CTREE_TEMPORARY_SUPER ; + fs_info =open_ctree_fs_info (&oca);if (!fs_info) {error ("open ctree failed" ); goto error;
Signature · 1 line
2.38.1
Re: [PATCH 2/6] btrfs-progs: rename struct open_ctree_flags to open_ctree_args
Quoted 10 lines · Anand Jain
The struct
open_ctree_flagscurrently holds arguments foropen_ctree_fs_info(), it can be confusing when mixed with a local variable namedopen_ctree_flagsas below in the functioncmd_inspect_dump_tree().cmd_inspect_dump_tree() :: struct open_ctree_flags ocf = { 0 }; :: unsigned open_ctree_flags;
Quoted 3 lines
So rename struct
open_ctree_flagsto structopen_ctree_args.Signed-off-by Anand Jain <[email protected]>
Thanks,
Qu
Quoted 434 lines
---
v3: Also rename structopen_ctree_args' variable to oca.btrfs-find-root.c | 8 +++---- check/main.c | 14 +++++------ cmds/filesystem.c | 8 +++---- cmds/inspect-dump-tree.c | 8 +++---- cmds/rescue.c | 16 ++++++------- cmds/restore.c | 12 +++++----- image/main.c | 16 ++++++------- kernel-shared/disk-io.c | 50 ++++++++++++++++++++-------------------- kernel-shared/disk-io.h | 4 ++-- mkfs/main.c | 8 +++---- 10 files changed, 72 insertions(+), 72 deletions(-)btrfs-find-root.c +4
-4@@ -335,7 +335,7 @@ int main(int argc, char **argv)struct btrfs_find_root_filter filter = {0 };struct cache_tree result;struct cache_extent *found; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };int ret;/* Default to search root tree */ @@ -378,9 +378,9 @@ int main(int argc, char **argv)if (check_argc_min (argc - optind,1 ))return 1 ; - ocf.filename = argv[optind]; - ocf.flags =OPEN_CTREE_CHUNK_ROOT_ONLY |OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR ; - fs_info =open_ctree_fs_info (&ocf); + oca.filename = argv[optind]; + oca.flags =OPEN_CTREE_CHUNK_ROOT_ONLY |OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR ; + fs_info =open_ctree_fs_info (&oca);if (!fs_info) {error ("open ctree failed" );return 1 ;check/main.c +7
-7@@ -9983,7 +9983,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) {struct cache_tree root_cache;struct btrfs_root *root; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };u64 bytenr =0 ;u64 subvolid =0 ;u64 tree_root_bytenr =0 ;@@ -10204,12 +10204,12 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)if (opt_check_repair) ctree_flags |=OPEN_CTREE_PARTIAL ; - ocf.filename = argv[optind]; - ocf.sb_bytenr = bytenr; - ocf.root_tree_bytenr = tree_root_bytenr; - ocf.chunk_tree_bytenr = chunk_root_bytenr; - ocf.flags = ctree_flags; - gfs_info =open_ctree_fs_info (&ocf); + oca.filename = argv[optind]; + oca.sb_bytenr = bytenr; + oca.root_tree_bytenr = tree_root_bytenr; + oca.chunk_tree_bytenr = chunk_root_bytenr; + oca.flags = ctree_flags; + gfs_info =open_ctree_fs_info (&oca);if (!gfs_info) {error ("cannot open file system" ); ret = -EIO ;cmds/filesystem.c +4
-4@@ -636,7 +636,7 @@ static int map_seed_devices(struct list_head *all_uuids) fs_uuids =btrfs_scanned_uuids ();list_for_each_entry (cur_fs, all_uuids, list) { -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 }; device =list_first_entry (&cur_fs->devices, struct btrfs_device, dev_list);@@ -650,9 +650,9 @@ static int map_seed_devices(struct list_head *all_uuids)/* * open_ctree_* detects seed/sprout mapping */ - ocf.filename = device->name; - ocf.flags =OPEN_CTREE_PARTIAL ; - fs_info =open_ctree_fs_info (&ocf); + oca.filename = device->name; + oca.flags =OPEN_CTREE_PARTIAL ; + fs_info =open_ctree_fs_info (&oca);if (!fs_info)continue ;cmds/inspect-dump-tree.c +4
-4@@ -317,7 +317,7 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,struct btrfs_disk_key disk_key;struct btrfs_key found_key;struct cache_tree block_root;/* for multiple --block parameters */ -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };char uuidbuf[BTRFS_UUID_UNPARSED_SIZE ];int ret =0 ;int slot;@@ -492,9 +492,9 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,pr_verbose (LOG_DEFAULT ,"%s\n" ,PACKAGE_STRING ); - ocf.filename = argv[optind]; - ocf.flags = open_ctree_flags; - info =open_ctree_fs_info (&ocf); + oca.filename = argv[optind]; + oca.flags = open_ctree_flags; + info =open_ctree_fs_info (&oca);if (!info) {error ("unable to open %s" , argv[optind]); goto out;cmds/rescue.c +8
-8@@ -233,7 +233,7 @@ static int cmd_rescue_fix_device_size(const struct cmd_struct *cmd, int argc, char **argv) { struct btrfs_fs_info *fs_info; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };char *devname;int ret;@@ -254,9 +254,9 @@ static int cmd_rescue_fix_device_size(const struct cmd_struct *cmd, goto out; } - ocf.filename = devname; - ocf.flags =OPEN_CTREE_WRITES |OPEN_CTREE_PARTIAL ; - fs_info =open_ctree_fs_info (&ocf); + oca.filename = devname; + oca.flags =OPEN_CTREE_WRITES |OPEN_CTREE_PARTIAL ; + fs_info =open_ctree_fs_info (&oca);if (!fs_info) {error ("could not open btrfs" ); ret = -EIO ;@@ -368,7 +368,7 @@ static int cmd_rescue_clear_uuid_tree(const struct cmd_struct *cmd, int argc, char **argv) { struct btrfs_fs_info *fs_info; -struct open_ctree_flags ocf = {}; +struct open_ctree_args oca = {};char *devname;int ret;@@ -387,9 +387,9 @@ static int cmd_rescue_clear_uuid_tree(const struct cmd_struct *cmd, ret = -EBUSY ; goto out; } - ocf.filename = devname; - ocf.flags =OPEN_CTREE_WRITES |OPEN_CTREE_PARTIAL ; - fs_info =open_ctree_fs_info (&ocf); + oca.filename = devname; + oca.flags =OPEN_CTREE_WRITES |OPEN_CTREE_PARTIAL ; + fs_info =open_ctree_fs_info (&oca);if (!fs_info) {error ("could not open btrfs" ); ret = -EIO ;cmds/restore.c +6
-6@@ -1216,7 +1216,7 @@ static struct btrfs_root *open_fs(const char *dev, u64 root_location, {struct btrfs_fs_info *fs_info =NULL ;struct btrfs_root *root =NULL ; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };u64 bytenr;int i;@@ -1228,12 +1228,12 @@ static struct btrfs_root *open_fs(const char *dev, u64 root_location,* in extent tree. Skip block group item search will allow * restore to be executed on heavily damaged fs. */ - ocf.filename = dev; - ocf.sb_bytenr = bytenr; - ocf.root_tree_bytenr = root_location; - ocf.flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_NO_BLOCK_GROUPS | + oca.filename = dev; + oca.sb_bytenr = bytenr; + oca.root_tree_bytenr = root_location; + oca.flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_NO_BLOCK_GROUPS |OPEN_CTREE_ALLOW_TRANSID_MISMATCH ; - fs_info =open_ctree_fs_info (&ocf); + fs_info =open_ctree_fs_info (&oca);if (fs_info)break ;pr_stderr (LOG_DEFAULT ,"Could not open root, trying backup super\n" );image/main.c +8
-8@@ -2795,12 +2795,12 @@ static int restore_metadump(const char *input, FILE *out, int old_restore,/* NOTE: open with write mode */ if (fixup_offset) { -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 }; - ocf.filename = target; - ocf.flags =OPEN_CTREE_WRITES |OPEN_CTREE_RESTORE | + oca.filename = target; + oca.flags =OPEN_CTREE_WRITES |OPEN_CTREE_RESTORE |OPEN_CTREE_PARTIAL |OPEN_CTREE_SKIP_LEAF_ITEM_CHECKS ; - info =open_ctree_fs_info (&ocf); + info =open_ctree_fs_info (&oca);if (!info) {error ("open ctree failed" ); ret = -EIO ;@@ -3223,15 +3223,15 @@ int BOX_MAIN(image)(int argc, char *argv[])/* extended support for multiple devices */ if (!create && multi_devices) { -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };struct btrfs_fs_info *info;u64 total_devs;int i; - ocf.filename = target; - ocf.flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_RESTORE | + oca.filename = target; + oca.flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_RESTORE |OPEN_CTREE_SKIP_LEAF_ITEM_CHECKS ; - info =open_ctree_fs_info (&ocf); + info =open_ctree_fs_info (&oca);if (!info) {error ("open ctree failed at %s" , target);return 1 ;kernel-shared/disk-io.c +25
-25@@ -1437,7 +1437,7 @@ int btrfs_setup_chunk_tree_and_device_map(struct btrfs_fs_info *fs_info,return 0 ; } -static struct btrfs_fs_info *__open_ctree_fd (int fp,struct open_ctree_flags *ocf) +static struct btrfs_fs_info *__open_ctree_fd (int fp,struct open_ctree_args *oca) {struct btrfs_fs_info *fs_info;struct btrfs_super_block *disk_super;@@ -1446,8 +1446,8 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_flags *ocint ret;int oflags;unsigned sbflags =SBREAD_DEFAULT ; -unsigned flags = ocf->flags; -u64 sb_bytenr = ocf->sb_bytenr; +unsigned flags = oca->flags; +u64 sb_bytenr = oca->sb_bytenr;if (sb_bytenr ==0 ) sb_bytenr =BTRFS_SUPER_INFO_OFFSET ;@@ -1491,7 +1491,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_flags *ocif (flags &OPEN_CTREE_IGNORE_FSID_MISMATCH ) sbflags |=SBREAD_IGNORE_FSID_MISMATCH ; - ret =btrfs_scan_fs_devices (fp, ocf->filename, &fs_devices, sb_bytenr, + ret =btrfs_scan_fs_devices (fp, oca->filename, &fs_devices, sb_bytenr, sbflags, (flags &OPEN_CTREE_NO_DEVICES ));if (ret) goto out;@@ -1559,7 +1559,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_flags *ocif (fcntl (fp,F_GETFL ) &O_DIRECT ) fs_info->zoned =1 ; - ret =btrfs_setup_chunk_tree_and_device_map (fs_info, ocf->chunk_tree_bytenr); + ret =btrfs_setup_chunk_tree_and_device_map (fs_info, oca->chunk_tree_bytenr);if (ret) goto out_chunk;@@ -1591,7 +1591,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_flags *ocbtrfs_header_chunk_tree_uuid (eb), BTRFS_UUID_SIZE); - ret =btrfs_setup_all_roots (fs_info, ocf->root_tree_bytenr, flags); + ret =btrfs_setup_all_roots (fs_info, oca->root_tree_bytenr, flags);if (ret && !(flags & __OPEN_CTREE_RETURN_CHUNK_ROOT) && !fs_info->ignore_chunk_tree_error) goto out_chunk;@@ -1608,7 +1608,7 @@ out:return NULL ; } -struct btrfs_fs_info *open_ctree_fs_info (struct open_ctree_flags *ocf) +struct btrfs_fs_info *open_ctree_fs_info (struct open_ctree_args *oca) {int fp;int ret;@@ -1616,28 +1616,28 @@ struct btrfs_fs_info *open_ctree_fs_info(struct open_ctree_flags *ocf)int oflags =O_RDWR ;struct stat st; - ret =stat (ocf->filename, &st); + ret =stat (oca->filename, &st);if (ret <0 ) { -error ("cannot stat '%s': %m" , ocf->filename); +error ("cannot stat '%s': %m" , oca->filename);return NULL ; }if (!(((st.st_mode &S_IFMT ) ==S_IFREG ) || ((st.st_mode &S_IFMT ) ==S_IFBLK ))) { -error ("not a regular file or block device: %s" , ocf->filename); +error ("not a regular file or block device: %s" , oca->filename);return NULL ; } -if (!(ocf->flags &OPEN_CTREE_WRITES )) +if (!(oca->flags &OPEN_CTREE_WRITES )) oflags =O_RDONLY ; -if ((oflags &O_RDWR ) &&zoned_model (ocf->filename) ==ZONED_HOST_MANAGED ) +if ((oflags &O_RDWR ) &&zoned_model (oca->filename) ==ZONED_HOST_MANAGED ) oflags |=O_DIRECT ; - fp =open (ocf->filename, oflags); + fp =open (oca->filename, oflags);if (fp <0 ) { -error ("cannot open '%s': %m" , ocf->filename); +error ("cannot open '%s': %m" , oca->filename);return NULL ; } - info =__open_ctree_fd (fp, ocf); + info =__open_ctree_fd (fp, oca);close (fp);return info; }@@ -1646,14 +1646,14 @@ struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, unsigned flags) {struct btrfs_fs_info *info; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };/* This flags may not return fs_info with any valid root */ BUG_ON (flags &OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR ); - ocf.filename = filename; - ocf.sb_bytenr = sb_bytenr; - ocf.flags = flags; - info =open_ctree_fs_info (&ocf); + oca.filename = filename; + oca.sb_bytenr = sb_bytenr; + oca.flags = flags; + info =open_ctree_fs_info (&oca);if (!info)return NULL ;if (flags & __OPEN_CTREE_RETURN_CHUNK_ROOT)@@ -1665,7 +1665,7 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr, unsigned flags) {struct btrfs_fs_info *info; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };/* This flags may not return fs_info with any valid root */ if (flags &OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR ) {@@ -1673,10 +1673,10 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr, (unsigned long long)flags);return NULL ; } - ocf.filename = path; - ocf.sb_bytenr = sb_bytenr; - ocf.flags = flags; - info =__open_ctree_fd (fp, &ocf); + oca.filename = path; + oca.sb_bytenr = sb_bytenr; + oca.flags = flags; + info =__open_ctree_fd (fp, &oca);if (!info)return NULL ;if (flags & __OPEN_CTREE_RETURN_CHUNK_ROOT)kernel-shared/disk-io.h +2
-2@@ -175,7 +175,7 @@ struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, unsigned flags);struct btrfs_root *open_ctree_fd (int fp,const char *path,u64 sb_bytenr,unsigned flags); -struct open_ctree_flags { +struct open_ctree_args {const char *filename;u64 sb_bytenr;u64 root_tree_bytenr;@@ -183,7 +183,7 @@ struct open_ctree_flags {unsigned flags; }; -struct btrfs_fs_info *open_ctree_fs_info (struct open_ctree_flags *ocf); +struct btrfs_fs_info *open_ctree_fs_info (struct open_ctree_args *oca);int close_ctree_fs_info (struct btrfs_fs_info *fs_info);static inline int close_ctree (struct btrfs_root *root) {mkfs/main.c +4
-4@@ -990,7 +990,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)struct btrfs_root *root;struct btrfs_fs_info *fs_info;struct btrfs_trans_handle *trans; -struct open_ctree_flags ocf = {0 }; +struct open_ctree_args oca = {0 };int ret =0 ;int close_ret;int i;@@ -1569,9 +1569,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv) goto error; } - ocf.filename = file; - ocf.flags =OPEN_CTREE_WRITES |OPEN_CTREE_TEMPORARY_SUPER ; - fs_info =open_ctree_fs_info (&ocf); + oca.filename = file; + oca.flags =OPEN_CTREE_WRITES |OPEN_CTREE_TEMPORARY_SUPER ; + fs_info =open_ctree_fs_info (&oca);if (!fs_info) {error ("open ctree failed" ); goto error;
PATCH v3 3/6 btrfs-progs: drop open_ctree_flags in cmd_inspect_dump_tree
In reply to Anand JainLocal variable open_ctree_flags carries the flags whose final update is for the locally declared struct variable oca_flags. Just use oca.flags directly.
--- cmds/inspect-dump-tree.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
cmds/inspect-dump-tree.c +5 -7
@@ -328,7 +328,6 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,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;u64 tree_id =0 ;
@@ -346,8 +345,8 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,* And we want to avoid tree-checker, which can rejects the target tree * block completely, while we may be debugging the problem. */ - open_ctree_flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_NO_BLOCK_GROUPS | -OPEN_CTREE_SKIP_LEAF_ITEM_CHECKS ; + oca.flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_NO_BLOCK_GROUPS | +OPEN_CTREE_SKIP_LEAF_ITEM_CHECKS ;cache_tree_init (&block_root); optind =0 ;while (1 ) {
@@ -400,7 +399,7 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,* If only showing one block, no need to fill roots * other than chunk root */ - open_ctree_flags |= __OPEN_CTREE_RETURN_CHUNK_ROOT; + oca.flags |= __OPEN_CTREE_RETURN_CHUNK_ROOT; block_bytenr =arg_strtou64 (optarg); ret =dump_add_tree_block (&block_root, block_bytenr);if (ret <0 )
@@ -437,10 +436,10 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd, traverse =BTRFS_PRINT_TREE_BFS ;break ;case GETOPT_VAL_NOSCAN : - open_ctree_flags |=OPEN_CTREE_NO_DEVICES ; + oca.flags |=OPEN_CTREE_NO_DEVICES ;break ;case GETOPT_VAL_HIDE_NAMES : - open_ctree_flags |=OPEN_CTREE_HIDE_NAMES ; + oca.flags |=OPEN_CTREE_HIDE_NAMES ;break ;case GETOPT_VAL_CSUM_HEADERS : csum_mode |=BTRFS_PRINT_TREE_CSUM_HEADERS ;
@@ -493,7 +492,6 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,pr_verbose (LOG_DEFAULT ,"%s\n" ,PACKAGE_STRING ); oca.filename = argv[optind]; - oca.flags = open_ctree_flags; info =open_ctree_fs_info (&oca);if (!info) {error ("unable to open %s" , argv[optind]);
Signature · 1 line
2.38.1
Re: [PATCH 3/6] btrfs-progs: drop open_ctree_flags in cmd_inspect_dump_tree
Quoted 5 lines · Anand Jain
Local variable
open_ctree_flagscarries the flags whose final update is for the locally declared struct variableoca_flags. Just use oca.flags directly.Signed-off-by Anand Jain <[email protected]>
Thanks,
Qu
Quoted 57 lines
--- cmds/inspect-dump-tree.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)cmds/inspect-dump-tree.c +5
-7@@ -328,7 +328,6 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,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;u64 tree_id =0 ;@@ -346,8 +345,8 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,* And we want to avoid tree-checker, which can rejects the target tree * block completely, while we may be debugging the problem. */ - open_ctree_flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_NO_BLOCK_GROUPS | -OPEN_CTREE_SKIP_LEAF_ITEM_CHECKS ; + oca.flags =OPEN_CTREE_PARTIAL |OPEN_CTREE_NO_BLOCK_GROUPS | +OPEN_CTREE_SKIP_LEAF_ITEM_CHECKS ;cache_tree_init (&block_root); optind =0 ;while (1 ) {@@ -400,7 +399,7 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,* If only showing one block, no need to fill roots * other than chunk root */ - open_ctree_flags |= __OPEN_CTREE_RETURN_CHUNK_ROOT; + oca.flags |= __OPEN_CTREE_RETURN_CHUNK_ROOT; block_bytenr =arg_strtou64 (optarg); ret =dump_add_tree_block (&block_root, block_bytenr);if (ret <0 )@@ -437,10 +436,10 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd, traverse =BTRFS_PRINT_TREE_BFS ;break ;case GETOPT_VAL_NOSCAN : - open_ctree_flags |=OPEN_CTREE_NO_DEVICES ; + oca.flags |=OPEN_CTREE_NO_DEVICES ;break ;case GETOPT_VAL_HIDE_NAMES : - open_ctree_flags |=OPEN_CTREE_HIDE_NAMES ; + oca.flags |=OPEN_CTREE_HIDE_NAMES ;break ;case GETOPT_VAL_CSUM_HEADERS : csum_mode |=BTRFS_PRINT_TREE_CSUM_HEADERS ;@@ -493,7 +492,6 @@ static int cmd_inspect_dump_tree(const struct cmd_struct *cmd,pr_verbose (LOG_DEFAULT ,"%s\n" ,PACKAGE_STRING ); oca.filename = argv[optind]; - oca.flags = open_ctree_flags; info =open_ctree_fs_info (&oca);if (!info) {error ("unable to open %s" , argv[optind]);
PATCH v3 4/6 btrfs-progs: device_list_add: optimize arguments drop devid
In reply to Anand JainDrop the devid argument; instead, it can be fetched from the disk_super argument.
--- kernel-shared/volumes.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel-shared/volumes.c +4 -4
@@ -334,11 +334,12 @@ static struct btrfs_fs_devices *find_fsid(u8 *fsid, u8 *metadata_uuid)static int device_list_add (const char *path,struct btrfs_super_block *disk_super, -u64 devid,struct btrfs_fs_devices **fs_devices_ret) +struct btrfs_fs_devices **fs_devices_ret) {struct btrfs_device *device;struct btrfs_fs_devices *fs_devices;u64 found_transid =btrfs_super_generation (disk_super); +u64 devid =btrfs_stack_device_id (&disk_super->dev_item);bool metadata_uuid = (btrfs_super_incompat_flags (disk_super) &BTRFS_FEATURE_INCOMPAT_METADATA_UUID );
@@ -545,18 +546,17 @@ int btrfs_scan_one_device(int fd, const char *path, {struct btrfs_super_block disk_super;int ret; -u64 devid; ret =btrfs_read_dev_super (fd, &disk_super, super_offset, sbflags);if (ret <0 )return -EIO ; - devid =btrfs_stack_device_id (&disk_super.dev_item); +if (btrfs_super_flags (&disk_super) &BTRFS_SUPER_FLAG_METADUMP ) *total_devs =1 ;else *total_devs =btrfs_super_num_devices (&disk_super); - ret =device_list_add (path, &disk_super, devid, fs_devices_ret); + ret =device_list_add (path, &disk_super, fs_devices_ret);return ret; }
Signature · 1 line
2.38.1
PATCH 5/7 btrfs-progs: factor out btrfs_scan_argv_devices
In reply to Anand JainTo prepare for handling command line given devices factor out btrfs_scan_argv_devices().
---
v3: Rename args of btrfs_scan_argv_devices()
Rename factored out function name from btrfs_scan_sdin_devices()
to btrfs_scan_argv_devices()
cmds/inspect-dump-tree.c | 37 +++---------------------------------- common/device-scan.c | 40 ++++++++++++++++++++++++++++++++++++++++ common/device-scan.h | 1 + 3 files changed, 44 insertions(+), 34 deletions(-)
cmds/inspect-dump-tree.c +3 -34
@@ -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;u64 block_bytenr;struct btrfs_root *tree_root_scan;u64 tree_id =0 ;
@@ -455,39 +454,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_argv_devices (optind, argc, argv); +if (ret) +return ret;pr_verbose (LOG_DEFAULT ,"%s\n" ,PACKAGE_STRING );
common/device-scan.c +40 -0
@@ -500,3 +500,43 @@ int btrfs_scan_devices(int verbose)return 0 ; } +int btrfs_scan_argv_devices (int dev_optind,int dev_argc,char **dev_argv) +{ +int ret; + +while (dev_optind < dev_argc) { +int fd; +u64 num_devices; +struct btrfs_fs_devices *fs_devices; + + ret =check_arg_type (dev_argv[dev_optind]); +if (ret !=BTRFS_ARG_BLKDEV && ret !=BTRFS_ARG_REG ) { +if (ret <0 ) { + errno = -ret; +error ("invalid argument %s: %m" , + dev_argv[dev_optind]); + }else { +error ("not a block device or regular file: %s" , + dev_argv[dev_optind]); + } + } + fd =open (dev_argv[dev_optind],O_RDONLY ); +if (fd <0 ) { +error ("cannot open %s: %m" , dev_argv[dev_optind]); +return -EINVAL ; + } + ret =btrfs_scan_one_device (fd, dev_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" , dev_argv[dev_optind]); +return ret; + } + dev_optind++; + } + +return 0 ; +}
common/device-scan.h +1 -0
@@ -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_argv_devices (int dev_optind,int argc,char **argv);#endif
Signature · 1 line
2.38.1
Re: [PATCH 5/7] btrfs-progs: factor out btrfs_scan_argv_devices
Quoted 2 lines · Anand Jain
To prepare for handling command line given devices factor out
btrfs_scan_argv_devices().
Is there something wrong with the thread?
This patch is showing 5/7 but the next is only 6/6.
The same problem happens to your tune patchset too, which seems worse, as what I got is 1/5, 1/1, 3/5, 3/5 and 5/5.
Thanks,
Qu
Quoted 126 lines
Signed-off-by Anand Jain <[email protected]>---
v3: Rename args ofbtrfs_scan_argv_devices()
Rename factored out function name frombtrfs_scan_sdin_devices()
tobtrfs_scan_argv_devices()cmds/inspect-dump-tree.c | 37 +++---------------------------------- common/device-scan.c | 40 ++++++++++++++++++++++++++++++++++++++++ common/device-scan.h | 1 + 3 files changed, 44 insertions(+), 34 deletions(-)cmds/inspect-dump-tree.c +3
-34@@ -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;u64 block_bytenr;struct btrfs_root *tree_root_scan;u64 tree_id =0 ;@@ -455,39 +454,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_argv_devices (optind, argc, argv); +if (ret) +return ret;pr_verbose (LOG_DEFAULT ,"%s\n" ,PACKAGE_STRING );common/device-scan.c +40
-0@@ -500,3 +500,43 @@ int btrfs_scan_devices(int verbose)return 0 ; } +int btrfs_scan_argv_devices (int dev_optind,int dev_argc,char **dev_argv) +{ +int ret; + +while (dev_optind < dev_argc) { +int fd; +u64 num_devices; +struct btrfs_fs_devices *fs_devices; + + ret =check_arg_type (dev_argv[dev_optind]); +if (ret !=BTRFS_ARG_BLKDEV && ret !=BTRFS_ARG_REG ) { +if (ret <0 ) { + errno = -ret; +error ("invalid argument %s: %m" , + dev_argv[dev_optind]); + }else { +error ("not a block device or regular file: %s" , + dev_argv[dev_optind]); + } + } + fd =open (dev_argv[dev_optind],O_RDONLY ); +if (fd <0 ) { +error ("cannot open %s: %m" , dev_argv[dev_optind]); +return -EINVAL ; + } + ret =btrfs_scan_one_device (fd, dev_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" , dev_argv[dev_optind]); +return ret; + } + dev_optind++; + } + +return 0 ; +}common/device-scan.h +1
-0@@ -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_argv_devices (int dev_optind,int argc,char **argv);#endif
Re: [PATCH 5/7] btrfs-progs: factor out btrfs_scan_argv_devices
Quoted 9 lines · Qu Wenruo
Quoted 2 lines · Anand Jain
To prepare for handling command line given devices factor out
btrfs_scan_argv_devices().Is there something wrong with the thread?
This patch is showing 5/7 but the next is only 6/6.
Sorry for the confusion. Please read the patch number as 5/6.
Quoted 3 lines
The same problem happens to your tune patchset too, which seems worse, as what I got is 1/5, 1/1, 3/5, 3/5 and 5/5.
I noticed it a little late, but 1/1 should be updated to 2/5.
Thanks, Anand
PATCH v3 6/6 btrfs-progs: refactor check_where_mounted with noscan argument
In reply to Anand JainThe function check_where_mounted() scans the system for all other btrfs devices, which is necessary for its operation.
However, in certain cases, devices remained in the scanned state is undesirable.
So introduces the 'noscan' argument to make devices unscanned before return.
--- common/open-utils.c | 9 ++++++--- common/open-utils.h | 3 ++- common/utils.c | 3 ++- tune/main.c | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-)
common/open-utils.c +6 -3
@@ -53,7 +53,8 @@ static int blk_file_in_dev_list(struct btrfs_fs_devices* fs_devices, }int check_mounted_where (int fd,const char *file,char *where,int size, -struct btrfs_fs_devices **fs_dev_ret,unsigned sbflags) +struct btrfs_fs_devices **fs_dev_ret,unsigned sbflags, +bool noscan) {int ret;u64 total_devs =1 ;
@@ -108,6 +109,8 @@ int check_mounted_where(int fd, const char *file, char *where, int size, }if (fs_dev_ret) *fs_dev_ret = fs_devices_mnt; +else if (noscan) +btrfs_close_all_devices (); ret = (mnt !=NULL );
@@ -132,7 +135,7 @@ int check_mounted(const char* file)return -errno; } - ret =check_mounted_where (fd, file,NULL ,0 ,NULL ,SBREAD_DEFAULT ); + ret =check_mounted_where (fd, file,NULL ,0 ,NULL ,SBREAD_DEFAULT , false);close (fd);return ret;
@@ -168,7 +171,7 @@ int get_btrfs_mount(const char *dev, char *mp, size_t mp_size) goto out; } - ret =check_mounted_where (fd, dev, mp, mp_size,NULL ,SBREAD_DEFAULT ); + ret =check_mounted_where (fd, dev, mp, mp_size,NULL ,SBREAD_DEFAULT , false);if (!ret) { ret = -EINVAL ; }else {/* mounted, all good */
common/open-utils.h +2 -1
@@ -23,7 +23,8 @@struct btrfs_fs_devices ;int check_mounted_where (int fd,const char *file,char *where,int size, -struct btrfs_fs_devices **fs_dev_ret,unsigned sbflags); +struct btrfs_fs_devices **fs_dev_ret,unsigned sbflags, +bool noscan);int check_mounted (const char * file);int get_btrfs_mount (const char *dev,char *mp,size_t mp_size);int open_path_or_dev_mnt (const char *path,DIR **dirstream,int verbose);
common/utils.c +2 -1
@@ -230,7 +230,8 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args, goto out; } ret =check_mounted_where (fd, path, mp,sizeof (mp), - &fs_devices_mnt,SBREAD_DEFAULT ); + &fs_devices_mnt,SBREAD_DEFAULT , + false);if (!ret) { ret = -EINVAL ; goto out;
tune/main.c +1 -1
@@ -268,7 +268,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[]) } ret =check_mounted_where (fd, device,NULL ,0 ,NULL , -SBREAD_IGNORE_FSID_MISMATCH ); +SBREAD_IGNORE_FSID_MISMATCH , false);if (ret <0 ) { errno = -ret;error ("could not check mount status of %s: %m" , device);
Signature · 1 line
2.38.1
Quoted 23 lines · Anand Jain
v3: Contains fixes as per review comments; details are in the individual
patches.Patches dropped:
btrfs-progs:check_mounted_where: pack varibles type by size
btrfs-progs:btrfs_scan_one_device: drop local variable ret
Patch added:
btrfs-progs: dropopen_ctree_flagsincmd_inspect_dump_treev2: I have separated preparatory and cleanups from the introduction of new
features so that they can be easily modified with a smaller set of patches.Added missing git changelogs. (Looks like sshfs lost my last few changes, now fixed).
--- original cover page ---
In an attempt to enable btrfstune to accept multiple devices from the command line, this patch includes some cleanup around the related preparatory work around the device scan code.Patches 1 to 5 primarily consist of cleanups. Patches 6 and 7 serve as preparatory changes.
Quoted 7 lines
Anand Jain (6):
btrfs-progs:check_mounted_where: declareis_btrfsas bool
btrfs-progs: rename structopen_ctree_flagstoopen_ctree_args
btrfs-progs: dropopen_ctree_flagsincmd_inspect_dump_tree
btrfs-progs:device_list_add: optimize arguments drop devid
btrfs-progs: factor outbtrfs_scan_argv_devices
btrfs-progs: refactorcheck_where_mountedwith noscan argument
Added to devel, thanks.