From 2ff04db5f4fbf28cf990804b4ed4ad2bd605e677 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Mon, 22 Aug 2016 16:32:24 +0200 Subject: btrfs-progs: two staged filesystem creation The filesystem existence on a device is manifested by the signature, during the mkfs process we write it first and then create other structures. Such filesystem is not valid and should not be registered during device scan nor listed among devices from blkid. This patch will introduce two staged creation. In the first phase, the signature is wrong, but recognized as a partially created filesystem (by open or scan helpers). Once we successfully create and write everything, we fixup the signature. At this point automated scanning should find a valid filesystem on all devices. We can also rely on the partially created filesystem to do better error handling during creation. We can just bail out and do not need to clean up. The partial signature is '!BHRfS_M', can be shown by btrfs inspect-internal dump-super -F image Reviewed-by: Anand Jain Signed-off-by: David Sterba --- mkfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'mkfs.c') diff --git a/mkfs.c b/mkfs.c index 0b081dd4..ee5a30da 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1708,7 +1708,7 @@ int main(int argc, char **argv) exit(1); } - root = open_ctree(file, 0, OPEN_CTREE_WRITES); + root = open_ctree(file, 0, OPEN_CTREE_WRITES | OPEN_CTREE_FS_PARTIAL); if (!root) { error("open ctree failed"); close(fd); @@ -1858,6 +1858,11 @@ raid_groups: list_all_devices(root); } + /* + * The filesystem is now fully set up, commit the remaining changes and + * fix the signature as the last step before closing the devices. + */ + root->fs_info->finalize_on_close = 1; out: ret = close_ctree(root); BUG_ON(ret); -- cgit v1.2.3