path: root/mkfs.c
diff options
authorDavid Sterba <>2016-08-22 16:32:24 +0200
committerDavid Sterba <>2016-08-24 14:37:31 +0200
commit2ff04db5f4fbf28cf990804b4ed4ad2bd605e677 (patch)
treeceec1a34bd9f49d2ede1c8cc9d9c8dcad1d50a40 /mkfs.c
parent974cfeeebb42b4911737876241c13dd12685b412 (diff)
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 <>
Diffstat (limited to 'mkfs.c')
1 files changed, 6 insertions, 1 deletions
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)
- 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");
@@ -1858,6 +1858,11 @@ raid_groups:
+ /*
+ * 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;
ret = close_ctree(root);