From patchwork Tue Aug 23 10:25:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 9295437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8DDA960757 for ; Tue, 23 Aug 2016 10:45:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8001428BBC for ; Tue, 23 Aug 2016 10:45:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7523E28BE1; Tue, 23 Aug 2016 10:45:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1264428BBC for ; Tue, 23 Aug 2016 10:45:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755256AbcHWKpR (ORCPT ); Tue, 23 Aug 2016 06:45:17 -0400 Received: from mx2.suse.de ([195.135.220.15]:59415 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757076AbcHWKnp (ORCPT ); Tue, 23 Aug 2016 06:43:45 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 442FBAD43 for ; Tue, 23 Aug 2016 10:26:25 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 05397DAA2E; Tue, 23 Aug 2016 12:25:19 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 03/13] btrfs-progs: introduce signature for a partially set up filesystem Date: Tue, 23 Aug 2016 12:25:07 +0200 Message-Id: <1471947917-5324-4-git-send-email-dsterba@suse.com> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1471947917-5324-1-git-send-email-dsterba@suse.com> References: <1471947917-5324-1-git-send-email-dsterba@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- ctree.h | 6 ++++++ utils.c | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ctree.h b/ctree.h index b9fb732c0d40..89e47abd9d14 100644 --- a/ctree.h +++ b/ctree.h @@ -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 diff --git a/utils.c b/utils.c index 8be0e7537f8f..e7195b53b015 100644 --- a/utils.c +++ b/utils.c @@ -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,