Btrfs-progs: rework open_ctree to take flags, add a new one
PATCH 1/1 Btrfs-progs: rework open_ctree to take flags, add a new one
So I needed to add a flag to not try to read block groups when doing --init-extent-tree since we could hang there, but that meant adding a whole other 0/1 type flag to open_ctree_fs_info. So instead I've converted it all over to using a flags setting and added the flag that I needed. This has been tested with xfstests and make test. Thanks,
Signed-off-by Josef Bacik <[email protected]>
--- btrfs-convert.c | 6 +-- btrfs-corrupt-block.c | 2 +- btrfs-debug-tree.c | 2 +- btrfs-image.c | 9 ++++- btrfs-zero-log.c | 2 +- btrfstune.c | 2 +- cmds-check.c | 14 +++---- disk-io.c | 107 ++++++++++++++------------------------------------ disk-io.h | 26 ++++++------ mkfs.c | 2 +- quick-test.c | 10 ++--- super-recover.c | 4 +- utils.c | 2 +- 13 files changed, 75 insertions(+), 113 deletions(-)
btrfs-convert.c +3 -3
@@ -2256,7 +2256,7 @@ static int do_convert(const char *devname, int datacsum, int packing,fprintf (stderr,"unable to update system chunk\n" ); goto fail; } - root =open_ctree_fd (fd, devname, super_bytenr,O_RDWR ); + root =open_ctree_fd (fd, devname, super_bytenr,OPEN_CTREE_WRITES );if (!root) {fprintf (stderr,"unable to open ctree\n" ); goto fail;
@@ -2317,7 +2317,7 @@ static int do_convert(const char *devname, int datacsum, int packing, goto fail; } - root =open_ctree_fd (fd, devname,0 ,O_RDWR ); + root =open_ctree_fd (fd, devname,0 ,OPEN_CTREE_WRITES );if (!root) {fprintf (stderr,"unable to open ctree\n" ); goto fail;
@@ -2418,7 +2418,7 @@ static int do_rollback(const char *devname, int force)fprintf (stderr,"unable to open %s\n" , devname); goto fail; } - root =open_ctree_fd (fd, devname,0 ,O_RDWR ); + root =open_ctree_fd (fd, devname,0 ,OPEN_CTREE_WRITES );if (!root) {fprintf (stderr,"unable to open ctree\n" ); goto fail;
btrfs-corrupt-block.c +1 -1
@@ -799,7 +799,7 @@ int main(int ac, char **av)radix_tree_init ();cache_tree_init (&root_cache); - root =open_ctree (dev,0 ,1 ); + root =open_ctree (dev,0 ,OPEN_CTREE_WRITES );if (!root) {fprintf (stderr,"Open ctree failed\n" );exit (1 );
btrfs-debug-tree.c +1 -1
@@ -171,7 +171,7 @@ int main(int ac, char **av)if (ac !=1 )print_usage (); - info =open_ctree_fs_info (av[optind],0 ,0 ,0 ,1 ,0 ); + info =open_ctree_fs_info (av[optind],0 ,0 ,OPEN_CTREE_PARTIAL );if (!info) {fprintf (stderr,"unable to open %s\n" , av[optind]);exit (1 );
btrfs-image.c +7 -2
@@ -2267,7 +2267,10 @@ static int __restore_metadump(const char *input, FILE *out, int old_restore,/* NOTE: open with write mode */ if (fixup_offset) {BUG_ON (!target); - info =open_ctree_fs_info_restore (target,0 ,0 ,1 ,1 ); + info =open_ctree_fs_info (target,0 ,0 , +OPEN_CTREE_WRITES | +OPEN_CTREE_RESTORE | +OPEN_CTREE_PARTIAL );if (!info) {fprintf (stderr,"%s: open ctree failed\n" , __func__); ret = -EIO ;
@@ -2555,7 +2558,9 @@ int main(int argc, char *argv[])u64 total_devs;int i; - info =open_ctree_fs_info_restore (target,0 ,0 ,0 ,1 ); + info =open_ctree_fs_info (target,0 ,0 , +OPEN_CTREE_PARTIAL | +OPEN_CTREE_RESTORE );if (!info) {int e = errno; fprintf(stderr, "unable to open %s error = %s\n",
btrfs-zero-log.c +1 -1
@@ -60,7 +60,7 @@ int main(int ac, char **av) goto out; } - root =open_ctree (av[1 ],0 ,1 ); + root =open_ctree (av[1 ],0 ,OPEN_CTREE_WRITES );if (root ==NULL )return 1 ;
btrfstune.c +1 -1
@@ -148,7 +148,7 @@ int main(int argc, char *argv[])return 1 ; } - root =open_ctree (device,0 ,1 ); + root =open_ctree (device,0 ,OPEN_CTREE_WRITES );if (!root) {fprintf (stderr,"Open ctree failed\n" );
cmds-check.c +7 -7
@@ -6047,13 +6047,12 @@ int cmd_check(int argc, char **argv)struct btrfs_fs_info *info;u64 bytenr =0 ;char uuidbuf[37 ]; -int backup_root =0 ;int ret;int num;int option_index =0 ;int init_csum_tree =0 ;int init_extent_tree =0 ; -int rw =0 ; +enum btrfs_open_ctree_flags ctree_flags =OPEN_CTREE_PARTIAL ;while (1 ) {int c;
@@ -6064,7 +6063,7 @@ int cmd_check(int argc, char **argv)switch (c) {case 'a' :/* ignored */ break ;case 'b' : - backup_root =1 ; + ctree_flags |=OPEN_CTREE_BACKUP_ROOT ;break ;case 's' : num =atol (optarg);
@@ -6079,14 +6078,15 @@ int cmd_check(int argc, char **argv)if (option_index ==1 ) {printf ("enabling repair mode\n" ); repair =1 ; - rw =1 ; + ctree_flags |=OPEN_CTREE_WRITES ; }else if (option_index ==2 ) {printf ("Creating a new CRC tree\n" ); init_csum_tree =1 ; - rw =1 ; + ctree_flags |=OPEN_CTREE_WRITES ; }else if (option_index ==3 ) { init_extent_tree =1 ; - rw =1 ; + ctree_flags |= (OPEN_CTREE_WRITES | +OPEN_CTREE_NO_BLOCK_GROUPS ); repair =1 ; }
@@ -6107,7 +6107,7 @@ int cmd_check(int argc, char **argv)return -EBUSY ; } - info =open_ctree_fs_info (argv[optind], bytenr,0 , rw,1 , backup_root); + info =open_ctree_fs_info (argv[optind], bytenr,0 , ctree_flags);if (!info) {fprintf (stderr,"Couldn't open file system\n" );return -EIO ;
disk-io.c +30 -77
218 lines not on this page · raw message
disk-io.h +15 -11
@@ -25,6 +25,15 @@#define BTRFS_SUPER_MIRROR_MAX 3#define BTRFS_SUPER_MIRROR_SHIFT 12 +enum btrfs_open_ctree_flags { +OPEN_CTREE_WRITES =1 , +OPEN_CTREE_PARTIAL =2 , +OPEN_CTREE_BACKUP_ROOT =4 , +OPEN_CTREE_RECOVER_SUPER =8 , +OPEN_CTREE_RESTORE =16 , +OPEN_CTREE_NO_BLOCK_GROUPS =32 , +}; +static inline u64 btrfs_sb_offset (int mirror) {u64 start =16 *1024 ;
@@ -52,8 +61,8 @@ int clean_tree_block(struct btrfs_trans_handle *trans,void btrfs_free_fs_info (struct btrfs_fs_info *fs_info);struct btrfs_fs_info *btrfs_new_fs_info (int writable,u64 sb_bytenr);int btrfs_check_fs_compatibility (struct btrfs_super_block *sb,int writable); -int btrfs_setup_all_roots (struct btrfs_fs_info *fs_info, -u64 root_tree_bytenr,int partial,int backup_root); +int btrfs_setup_all_roots (struct btrfs_fs_info *fs_info,u64 root_tree_bytenr, +enum btrfs_open_ctree_flags flags);void btrfs_release_all_roots (struct btrfs_fs_info *fs_info);void btrfs_cleanup_all_caches (struct btrfs_fs_info *fs_info); int btrfs_scan_fs_devices(int fd, const char *path,
@@ -61,18 +70,13 @@ int btrfs_scan_fs_devices(int fd, const char *path, int run_ioctl);int btrfs_setup_chunk_tree_and_device_map (struct btrfs_fs_info *fs_info); -struct btrfs_root *open_ctree (const char *filename,u64 sb_bytenr,int writes); +struct btrfs_root *open_ctree (const char *filename,u64 sb_bytenr, +enum btrfs_open_ctree_flags flags);struct btrfs_root *open_ctree_fd (int fp,const char *path,u64 sb_bytenr, -int writes); -struct btrfs_fs_info *open_ctree_fs_info_restore (const char *filename, -u64 sb_bytenr,u64 root_tree_bytenr, -int writes,int partial); +enum btrfs_open_ctree_flags flags);struct btrfs_fs_info *open_ctree_fs_info (const char *filename,u64 sb_bytenr,u64 root_tree_bytenr, -int writes,int partial, -int backup_root); -struct btrfs_root *open_ctree_with_broken_super (const char *filename, -u64 sb_bytenr,int writes); +enum btrfs_open_ctree_flags flags);int close_ctree (struct btrfs_root *root);int write_all_supers (struct btrfs_root *root); int write_ctree_super(struct btrfs_trans_handle *trans,
mkfs.c +1 -1
@@ -1478,7 +1478,7 @@ int main(int ac, char **av)exit (1 ); } - root =open_ctree (file,0 ,O_RDWR ); + root =open_ctree (file,0 ,OPEN_CTREE_WRITES );if (!root) {fprintf (stderr,"Open ctree failed\n" );close (fd);
quick-test.c +5 -5
@@ -51,7 +51,7 @@ int main(int ac, char **av) {radix_tree_init (); - root =open_ctree (av[1 ],BTRFS_SUPER_INFO_OFFSET ,O_RDWR ); + root =open_ctree (av[1 ],BTRFS_SUPER_INFO_OFFSET ,OPEN_CTREE_WRITES );if (!root) {fprintf (stderr,"Open ctree failed\n" );exit (1 );
@@ -78,7 +78,7 @@ int main(int ac, char **av) {btrfs_commit_transaction (trans, root);close_ctree (root);exit (1 ); - root =open_ctree (av[1 ],BTRFS_SUPER_INFO_OFFSET ,O_RDWR ); + root =open_ctree (av[1 ],BTRFS_SUPER_INFO_OFFSET ,OPEN_CTREE_WRITES );if (!root) {fprintf (stderr,"Open ctree failed\n" );exit (1 );
@@ -101,7 +101,7 @@ int main(int ac, char **av) { }close_ctree (root); - root =open_ctree (av[1 ],BTRFS_SUPER_INFO_OFFSET ,O_RDWR ); + root =open_ctree (av[1 ],BTRFS_SUPER_INFO_OFFSET ,OPEN_CTREE_WRITES );if (!root) {fprintf (stderr,"Open ctree failed\n" );exit (1 );
@@ -133,7 +133,7 @@ int main(int ac, char **av) {btrfs_commit_transaction (trans, root);close_ctree (root); - root =open_ctree (av[1 ],BTRFS_SUPER_INFO_OFFSET ,O_RDWR ); + root =open_ctree (av[1 ],BTRFS_SUPER_INFO_OFFSET ,OPEN_CTREE_WRITES );if (!root) {fprintf (stderr,"Open ctree failed\n" );exit (1 );
@@ -153,7 +153,7 @@ int main(int ac, char **av) {btrfs_commit_transaction (trans, root);close_ctree (root); - root =open_ctree (av[1 ],BTRFS_SUPER_INFO_OFFSET ,O_RDWR ); + root =open_ctree (av[1 ],BTRFS_SUPER_INFO_OFFSET ,OPEN_CTREE_WRITES );if (!root) {fprintf (stderr,"Open ctree failed\n" );exit (1 );
super-recover.c +2 -2
@@ -323,8 +323,8 @@ int btrfs_recover_superblocks(const char *dname, } } record =recover_get_good_super (&recover); - root =open_ctree_with_broken_super (record->device_name, - record->bytenr,1 ); + root =open_ctree (record->device_name, record->bytenr, +OPEN_CTREE_RECOVER_SUPER |OPEN_CTREE_WRITES );if (!root) { ret =3 ; goto no_recover;
utils.c +1 -1
@@ -1279,7 +1279,7 @@ static int set_label_unmounted(const char *dev, const char *label)/* Open the super_block at the default location * and as read-write. */ - root =open_ctree (dev,0 ,1 ); + root =open_ctree (dev,0 ,OPEN_CTREE_WRITES );if (!root)/* errors are printed by open_ctree() */ return -1 ;
Signature · 1 line
1.8.3.1