btrfs-progs: Rename OPEN_CTREE_FS_PARTIAL to OPEN_CTREE_TEMPORARY_SUPER
The old flag OPEN_CTREE_FS_PARTIAL is in fact quite easy to be confused
with OPEN_CTREE_PARTIAL, which allow btrfs-progs to open damaged
filesystem (like corrupted extent/csum tree).
However OPEN_CTREE_FS_PARTIAL, unlike its name, is just allowing
btrfs-progs to open fs with temporary superblocks (which only has 6
basic trees on SINGLE meta/sys chunks).
The usage of FS_PARTIAL is really confusing here.
So rename OPEN_CTREE_FS_PARTIAL to OPEN_CTREE_TEMPORARY_SUPER, and add
extra comment for its behavior.
Also rename BTRFS_MAGIC_PARTIAL to BTRFS_MAGIC_TEMPORARY to keep the
naming consistent.
And with above comment, the usage of FS_PARTIAL in dump-tree is
obviously incorrect, fix it.
Fixes: 8698a2b9ba
("btrfs-progs: Allow inspect dump-tree to show specified tree block even some tree roots are corrupted")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
cc66055f97
commit
c57ed6ca6b
9 changed files with 25 additions and 19 deletions
|
@ -221,7 +221,7 @@ int cmd_inspect_dump_tree(int argc, char **argv)
|
|||
int uuid_tree_only = 0;
|
||||
int roots_only = 0;
|
||||
int root_backups = 0;
|
||||
unsigned open_ctree_flags = OPEN_CTREE_FS_PARTIAL;
|
||||
unsigned open_ctree_flags = OPEN_CTREE_PARTIAL;
|
||||
u64 block_only = 0;
|
||||
struct btrfs_root *tree_root_scan;
|
||||
u64 tree_id = 0;
|
||||
|
|
|
@ -116,7 +116,7 @@ static int setup_temp_super(int fd, struct btrfs_mkfs_config *cfg,
|
|||
|
||||
btrfs_set_super_bytenr(super, cfg->super_bytenr);
|
||||
btrfs_set_super_num_devices(super, 1);
|
||||
btrfs_set_super_magic(super, BTRFS_MAGIC_PARTIAL);
|
||||
btrfs_set_super_magic(super, BTRFS_MAGIC_TEMPORARY);
|
||||
btrfs_set_super_generation(super, 1);
|
||||
btrfs_set_super_root(super, root_bytenr);
|
||||
btrfs_set_super_chunk_root(super, chunk_bytenr);
|
||||
|
|
|
@ -1140,7 +1140,7 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
|
|||
}
|
||||
|
||||
root = open_ctree_fd(fd, devname, mkfs_cfg.super_bytenr,
|
||||
OPEN_CTREE_WRITES | OPEN_CTREE_FS_PARTIAL);
|
||||
OPEN_CTREE_WRITES | OPEN_CTREE_TEMPORARY_SUPER);
|
||||
if (!root) {
|
||||
error("unable to open ctree");
|
||||
goto fail;
|
||||
|
@ -1230,7 +1230,7 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
|
|||
}
|
||||
|
||||
root = open_ctree_fd(fd, devname, 0,
|
||||
OPEN_CTREE_WRITES | OPEN_CTREE_FS_PARTIAL);
|
||||
OPEN_CTREE_WRITES | OPEN_CTREE_TEMPORARY_SUPER);
|
||||
if (!root) {
|
||||
error("unable to open ctree for finalization");
|
||||
goto fail;
|
||||
|
|
8
ctree.h
8
ctree.h
|
@ -45,10 +45,12 @@ struct btrfs_free_space_ctl;
|
|||
#define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
|
||||
|
||||
/*
|
||||
* Fake signature for an unfinalized filesystem, structures might be partially
|
||||
* created or missing.
|
||||
* Fake signature for an unfinalized filesystem, which only has barebone tree
|
||||
* structures (normally 6 near empty trees, on SINGLE meta/sys temporary chunks)
|
||||
*
|
||||
* ascii !BHRfS_M, no null
|
||||
*/
|
||||
#define BTRFS_MAGIC_PARTIAL 0x4D5F536652484221ULL /* ascii !BHRfS_M, no null */
|
||||
#define BTRFS_MAGIC_TEMPORARY 0x4D5F536652484221ULL
|
||||
|
||||
#define BTRFS_MAX_MIRRORS 3
|
||||
|
||||
|
|
12
disk-io.c
12
disk-io.c
|
@ -1116,14 +1116,14 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
|
|||
fs_info->ignore_chunk_tree_error = 1;
|
||||
|
||||
if ((flags & OPEN_CTREE_RECOVER_SUPER)
|
||||
&& (flags & OPEN_CTREE_FS_PARTIAL)) {
|
||||
&& (flags & OPEN_CTREE_TEMPORARY_SUPER)) {
|
||||
fprintf(stderr,
|
||||
"cannot open a partially created filesystem for recovery");
|
||||
"cannot open a filesystem with temporary super block for recovery");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (flags & OPEN_CTREE_FS_PARTIAL)
|
||||
sbflags = SBREAD_PARTIAL;
|
||||
if (flags & OPEN_CTREE_TEMPORARY_SUPER)
|
||||
sbflags = SBREAD_TEMPORARY;
|
||||
|
||||
ret = btrfs_scan_fs_devices(fp, path, &fs_devices, sb_bytenr, sbflags,
|
||||
(flags & OPEN_CTREE_NO_DEVICES));
|
||||
|
@ -1284,8 +1284,8 @@ static int check_super(struct btrfs_super_block *sb, unsigned sbflags)
|
|||
int csum_size;
|
||||
|
||||
if (btrfs_super_magic(sb) != BTRFS_MAGIC) {
|
||||
if (btrfs_super_magic(sb) == BTRFS_MAGIC_PARTIAL) {
|
||||
if (!(sbflags & SBREAD_PARTIAL)) {
|
||||
if (btrfs_super_magic(sb) == BTRFS_MAGIC_TEMPORARY) {
|
||||
if (!(sbflags & SBREAD_TEMPORARY)) {
|
||||
error("superblock magic doesn't match");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
10
disk-io.h
10
disk-io.h
|
@ -73,8 +73,12 @@ enum btrfs_open_ctree_flags {
|
|||
*/
|
||||
OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR = (1U << 11),
|
||||
|
||||
/* Allow to open a partially created filesystem */
|
||||
OPEN_CTREE_FS_PARTIAL = (1U << 12),
|
||||
/*
|
||||
* Allow to open fs with temporary superblock (BTRFS_MAGIC_PARTIAL),
|
||||
* such fs contains very basic tree layout, just able to be opened.
|
||||
* Such temporary super is used for mkfs or convert.
|
||||
*/
|
||||
OPEN_CTREE_TEMPORARY_SUPER = (1U << 12),
|
||||
|
||||
/*
|
||||
* Invalidate the free space tree (i.e., clear the FREE_SPACE_TREE_VALID
|
||||
|
@ -95,7 +99,7 @@ enum btrfs_read_sb_flags {
|
|||
* Read superblock with the fake signature, cannot be used with
|
||||
* SBREAD_RECOVER
|
||||
*/
|
||||
SBREAD_PARTIAL = (1 << 1),
|
||||
SBREAD_TEMPORARY = (1 << 1),
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -189,7 +189,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
|
|||
|
||||
btrfs_set_super_bytenr(&super, cfg->blocks[MKFS_SUPER_BLOCK]);
|
||||
btrfs_set_super_num_devices(&super, 1);
|
||||
btrfs_set_super_magic(&super, BTRFS_MAGIC_PARTIAL);
|
||||
btrfs_set_super_magic(&super, BTRFS_MAGIC_TEMPORARY);
|
||||
btrfs_set_super_generation(&super, 1);
|
||||
btrfs_set_super_root(&super, cfg->blocks[MKFS_ROOT_TREE]);
|
||||
btrfs_set_super_chunk_root(&super, cfg->blocks[MKFS_CHUNK_TREE]);
|
||||
|
|
|
@ -1099,7 +1099,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
fs_info = open_ctree_fs_info(file, 0, 0, 0,
|
||||
OPEN_CTREE_WRITES | OPEN_CTREE_FS_PARTIAL);
|
||||
OPEN_CTREE_WRITES | OPEN_CTREE_TEMPORARY_SUPER);
|
||||
if (!fs_info) {
|
||||
error("open ctree failed");
|
||||
goto error;
|
||||
|
|
2
utils.c
2
utils.c
|
@ -1050,7 +1050,7 @@ int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
|
|||
* structures.
|
||||
*/
|
||||
if (btrfs_super_magic(disk_super) != BTRFS_MAGIC &&
|
||||
btrfs_super_magic(disk_super) != BTRFS_MAGIC_PARTIAL)
|
||||
btrfs_super_magic(disk_super) != BTRFS_MAGIC_TEMPORARY)
|
||||
goto brelse;
|
||||
|
||||
if (!memcmp(disk_super->fsid, root->fs_info->super_copy->fsid,
|
||||
|
|
Loading…
Reference in a new issue