btrfs-progs: introduce signature for a partially set up filesystem

Currently the superblock is created first, with a valid signaure, but
the rest of the filesystem is missing. When the creation process is
interrupted, the filesystem still might be considered as valid.

To prevent that, create the filesytem with an invalid signature that
would be still recognized during the mkfs process, and finalize at the
end.

Signed-off-by: David Sterba <dsterba@suse.com>
master
David Sterba 2016-08-19 16:40:14 +02:00
parent 059832da5f
commit 3c350dec06
2 changed files with 12 additions and 1 deletions

View File

@ -40,6 +40,12 @@ struct btrfs_trans_handle;
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.
*/
#define BTRFS_MAGIC_PARTIAL 0x4D5F536652484221ULL /* ascii !BHRfS_M, no null */
#define BTRFS_MAX_MIRRORS 3
#define BTRFS_MAX_LEVEL 8

View File

@ -2400,7 +2400,12 @@ int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
ret = 0;
disk_super = (struct btrfs_super_block *)buf;
if (btrfs_super_magic(disk_super) != BTRFS_MAGIC)
/*
* Accept devices from the same filesystem, allow partially created
* structures.
*/
if (btrfs_super_magic(disk_super) != BTRFS_MAGIC &&
btrfs_super_magic(disk_super) != BTRFS_MAGIC_PARTIAL)
goto brelse;
if (!memcmp(disk_super->fsid, root->fs_info->super_copy->fsid,