Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3028519pxf; Sun, 21 Mar 2021 16:08:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOMseFjwklCSQKTmufcfjMcUUxpD3iM7do9fZhNbkyppQ1zaQn+jS+a7+FHYSfePqhkHWe X-Received: by 2002:a17:906:ecb8:: with SMTP id qh24mr122687ejb.162.1616368110564; Sun, 21 Mar 2021 16:08:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616368110; cv=none; d=google.com; s=arc-20160816; b=whA06Mi/SzgXn0dC/iZTtSQcC/NNU782aTl0qUYXJVSXLZBDqN1KpSn4ObE9O1Xdm7 Khg4Dwrf6UBsM6lGYHzrlE7vB+PzvWkQeoUZsCX1aw7ljioBoQSedtWlUq7YDD7avCwV Ruq005enV7j3SfBzI9KarKYl8XGeOjmVfhsRrZuxKniED+Cy4YF5B4Xl9bf5lvrmP8PR 2Bn4N5Jmf440aKu6TJydh+s8Wt10w/W05jcLUtBp/U1tsr2JOaS5Gb4gcShLr/tzL1er eFTpBeWZmXTn3bUNLc/oIANq8tIpQmLhrCoXWn/b93EnhjKbSGYNRrfH2O8ITDrL+OBq gHpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FHVroE09bYfHZ55DaPFtDs49Byg6Kj1pwjra28kTtDc=; b=XBhxakW5I4vvPT/Uwx+VwLAEqcBIGWmyMXSpQBnrKwXwQZ+0OlI3KBjwFbl9LbLjHr mn9EdIJkzzPvqSyRrpyfM0Aw47PN2GPN+HVnF1Jhvmy9O/Xe0gbaAPFnP3aElQS12QIL Fz3ntTPoZ6T+xUXcYdxZ3jr6Pg3Kd4l26SiU2G1+lrafHV0CQdXI1q1ynV2XWeQDIwgG 1jpohhksb84bVTxajMKTf2UYzlpbcQ+WPtLR4zBTfVuaIj0DMnP2JCqVUCwreGxd89L+ Hs75nVBCrDkBj4sPTTb8tJSwJz1lKRrUp/tXBMzWxULrVTpzuQx8/dPu+88Qss+J31/9 UgCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cZ3Z2iqz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o11si9788247eja.149.2021.03.21.16.08.07; Sun, 21 Mar 2021 16:08:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cZ3Z2iqz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231395AbhCUVrQ (ORCPT + 99 others); Sun, 21 Mar 2021 17:47:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230360AbhCUVrA (ORCPT ); Sun, 21 Mar 2021 17:47:00 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02AD3C061574; Sun, 21 Mar 2021 14:46:59 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id d8-20020a1c1d080000b029010f15546281so7971355wmd.4; Sun, 21 Mar 2021 14:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FHVroE09bYfHZ55DaPFtDs49Byg6Kj1pwjra28kTtDc=; b=cZ3Z2iqzc+HKxMSXTVl8O24XA5V5hy2iN4NP/8/PjkvFpBZCd5gdSVYl0jUpUfwIuA oaOqEibaWW7Iap2K8KNEGQJI8KHJvQW1s4nS01J4X/P+DcRJFI0oPj1sj2Z4Buk/cARN avf+dspseEpjBQ+SyJ7IbJIxunAiI6PADPwaZHygb55lJTV9kobgH5gPmNfhbqrD8uet JZz+TuYSWX0A6D46KUzU1hPcENmX7RaOMKlvMndrrYN/pO5PeNvIBuBsCuz/83cPeqP6 /8b4wuZ7IGnZigambPX0p9poYN3hBywSxu7LvX/aeXHq9mjbD5T3JsebQ0CqEJU5iMVQ /i4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FHVroE09bYfHZ55DaPFtDs49Byg6Kj1pwjra28kTtDc=; b=WBj9qxoQaw8cds546usm/BIVBacbkhSeJOwN+/2g9B8xyml514lNzAUeG5qdJyX0hQ CanspalEODrRWnurEo98rvD8DCxkLty3gMOhbZa3Mxe2rlETfCprSSCdmPWRgqw6yc4s NQgWUgCD7LYZtfXLHRNSYFX0t1CwxjZDKAVByovvK++jQyKp6OeYI2BK4C74DcnQKFL0 EXuMq5o1Mczm9MQ2BcpGUPrV8DIM6pMSeS2mNK7ddkd/4lEFMWzY3knITkIb6X2CvN74 yqDoxbLZr1g8UY+1jG9J/kvVCek6VfAzy2hFH8S4K0s2Xtd6bXQi+XZpNiDlKNssaVL0 9Bqw== X-Gm-Message-State: AOAM5325ONrw0cQe4hBhfDAxd33BW6pdfFTeVYjMxqtJp7NpLe8HOiZm ZVKrflm278BMilr1eL7nRld9PLOh55otOZtL X-Received: by 2002:a7b:c0c4:: with SMTP id s4mr13400834wmh.9.1616363217170; Sun, 21 Mar 2021 14:46:57 -0700 (PDT) Received: from localhost.localdomain ([46.109.162.86]) by smtp.gmail.com with ESMTPSA id p12sm17651849wrx.28.2021.03.21.14.46.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:46:56 -0700 (PDT) From: =?UTF-8?q?D=C4=81vis=20Mos=C4=81ns?= To: linux-btrfs@vger.kernel.org Cc: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, linux-kernel@vger.kernel.org, ce3g8jdj@umail.furryterror.org, =?UTF-8?q?D=C4=81vis=20Mos=C4=81ns?= Subject: [PATCH] btrfs: Allow read-only mount with corrupted extent tree Date: Sun, 21 Mar 2021 23:49:39 +0200 Message-Id: <20210321214939.6984-1-davispuh@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210317012054.238334-1-davispuh@gmail.com> References: <20210317012054.238334-1-davispuh@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently if there's any corruption at all in extent tree (eg. even single bit) then mounting will fail with: "failed to read block groups: -5" (-EIO) It happens because we immediately abort on first error when searching in extent tree for block groups. Now with this patch if `ignorebadroots` option is specified then we handle such case and continue by removing already created block groups and creating dummy block groups. Signed-off-by: Dāvis Mosāns --- fs/btrfs/block-group.c | 20 ++++++++++++++++++++ fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/disk-io.h | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 48ebc106a606..f485cf14c2f8 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2048,6 +2048,26 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info) ret = check_chunk_block_group_mappings(info); error: btrfs_free_path(path); + + if (ret == -EIO && btrfs_test_opt(info, IGNOREBADROOTS)) { + + if (btrfs_super_log_root(info->super_copy) != 0) { + btrfs_warn(info, "Ignoring tree-log replay due to extent tree corruption!"); + btrfs_set_super_log_root(info->super_copy, 0); + } + + btrfs_put_block_group_cache(info); + btrfs_stop_all_workers(info); + btrfs_free_block_groups(info); + ret = btrfs_init_workqueues(info, NULL); + if (ret) + return ret; + ret = btrfs_init_space_info(info); + if (ret) + return ret; + return fill_dummy_bgs(info); + } + return ret; } diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 07a2b4f69b10..dc744f76d075 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1955,7 +1955,7 @@ static int read_backup_root(struct btrfs_fs_info *fs_info, u8 priority) } /* helper to cleanup workers */ -static void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) +void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info) { btrfs_destroy_workqueue(fs_info->fixup_workers); btrfs_destroy_workqueue(fs_info->delalloc_workers); @@ -2122,7 +2122,7 @@ static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info) mutex_init(&fs_info->qgroup_rescan_lock); } -static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, +int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, struct btrfs_fs_devices *fs_devices) { u32 max_active = fs_info->thread_pool_size; diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index e45057c0c016..f9bfcba86a04 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -137,6 +137,8 @@ int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid); int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid); int __init btrfs_end_io_wq_init(void); void __cold btrfs_end_io_wq_exit(void); +void btrfs_stop_all_workers(struct btrfs_fs_info *fs_info); +int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, struct btrfs_fs_devices *fs_devices); #ifdef CONFIG_DEBUG_LOCK_ALLOC void btrfs_set_buffer_lockdep_class(u64 objectid, -- 2.30.2