From patchwork Fri Oct 9 20:07:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11829481 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 203AD109B for ; Fri, 9 Oct 2020 20:10:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 060AF2067D for ; Fri, 9 Oct 2020 20:10:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="Nx3n4n7G" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390934AbgJIUKA (ORCPT ); Fri, 9 Oct 2020 16:10:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390859AbgJIUIY (ORCPT ); Fri, 9 Oct 2020 16:08:24 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9974C0613E6 for ; Fri, 9 Oct 2020 13:07:25 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id o21so8930147qtp.2 for ; Fri, 09 Oct 2020 13:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LO9AU2zdbNOLCT1So1fmNre7jP2ZElUZILMO7GqF+OE=; b=Nx3n4n7GSQ04i7vasiPDdSBR+THHxsdt0R1K5Irim2FgJpUdItsYjDLq2WZ69aTAPS IW9dHi1utm0ijiAMkh/x71o/Z1FSKEyja8MtNMakLoB/x9MUDhSJgiWaN9csbhT4YZW5 xC7FRW1lmjjRiiQfOmgkiULpBaHrKVMPY/zvqb/RjUi16Lycbn9gRI77aUvne1tYO2y8 BNf33YK/FuxnROgn2m5zDcefc5oBQQoku39Jl5OvbS7/PouVTVfQJBEya1P3TNw2WEIs fKmO0CLYV47xWaISMIWVk9I+LPWBPdJoi3LoZMUhlvUvxyuuEM/4YtJTbiG6RIjEYwGg uX1g== 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=LO9AU2zdbNOLCT1So1fmNre7jP2ZElUZILMO7GqF+OE=; b=kPC6q45Oj13/D9Tn3iPh3h/QNwb1XUiEkaLP1IzYsxyUs0qc5tnD4cDbwSt443YGex Bau9clE+C0sqqTZF7McI4/Yruc8V4I2ILJ+yjEwTcVri2rD9r7gR17WIARhelgTOkXmW kvNPj9LNCvfDxX5HZ16OueuKLpavYmbSNiwkzrxDvfW2xZv0UZ9knbhwiI7qvcwZ8X/T tyuPkBhlVhwLMucKyO5BvIThyqziHB58C0KpIcMiOYUhqmhIom3Cet4GMkvgckyKR5yb oDtXyaAVOb54Dcu5rroaieEIsKa2HqRQTis206ChL+c7fDO+gPDoV5kcPo0p3sxQrmYv LXig== X-Gm-Message-State: AOAM533Agv4L1lyPkLStaqdX7zr8ULQ5dtlIz1GiSzjASQq8Axo0/Q9d Ql+2jjpnS85/fFI9Mjd0D828DZlXpJ0oyDEf X-Google-Smtp-Source: ABdhPJw6AHrtGqLGBF5GWxEwMwJGYWvZCzfx6hVvZkfXqhTbXkDU1BG3UbX93MBlz8v4E4yhM3WkaQ== X-Received: by 2002:ac8:6d2d:: with SMTP id r13mr9465021qtu.279.1602274044624; Fri, 09 Oct 2020 13:07:24 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id g1sm6914123qtp.74.2020.10.09.13.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 13:07:23 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v3 1/8] btrfs: unify the ro checking for mount options Date: Fri, 9 Oct 2020 16:07:13 -0400 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're going to be adding more options that require RDONLY, so add a helper to do the check and error out if we don't have RDONLY set. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/super.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 8840a4fa81eb..f99e89ec46b2 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -458,6 +458,17 @@ static const match_table_t rescue_tokens = { {Opt_err, NULL}, }; +static bool check_ro_option(struct btrfs_fs_info *fs_info, unsigned long opt, + const char *opt_name) +{ + if (fs_info->mount_opt & opt) { + btrfs_err(fs_info, "%s must be used with ro mount option", + opt_name); + return true; + } + return false; +} + static int parse_rescue_options(struct btrfs_fs_info *info, const char *options) { char *opts; @@ -968,14 +979,12 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, } } check: - /* - * Extra check for current option against current flag - */ - if (btrfs_test_opt(info, NOLOGREPLAY) && !(new_flags & SB_RDONLY)) { - btrfs_err(info, - "nologreplay must be used with ro mount option"); + /* We're read-only, don't have to check. */ + if (new_flags & SB_RDONLY) + goto out; + + if (check_ro_option(info, BTRFS_MOUNT_NOLOGREPLAY, "nologreplay")) ret = -EINVAL; - } out: if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE) && !btrfs_test_opt(info, FREE_SPACE_TREE) && From patchwork Fri Oct 9 20:07:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11829483 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4AADD17CA for ; Fri, 9 Oct 2020 20:10:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F6BA2067D for ; Fri, 9 Oct 2020 20:10:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="LyaaMB7q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391018AbgJIUKA (ORCPT ); Fri, 9 Oct 2020 16:10:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390847AbgJIUIX (ORCPT ); Fri, 9 Oct 2020 16:08:23 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A03F8C0613A7 for ; Fri, 9 Oct 2020 13:07:27 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id w12so11884765qki.6 for ; Fri, 09 Oct 2020 13:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=78sPD/imWiDIsa2rzloBZkC1dL8B6n9ak9VaEkzrNVo=; b=LyaaMB7q73jfibfd/klzPuiY/AzaOG00XH84vQLWe7seh+5l0M7y4ddZbIGQFAevP5 7LAvySi8BQKSBnycfTpNUZCpcvFqNSBT/d+mxkaQGGk/FzbVApTjfd3+8fj9cZ9KFQnv jk6lCiGCus+9DucCy4slT4Dldhg8VzFWFrL2a4wRUjVEMeZ2g8agcKgYaXA+7N/OJCMb UVfZXvUteQx+fVczJrQK+3SYUyODEM49CIN4PNbysvfB0MoR6b7qMjMu259c0KnrqeSs AoLTa6oAfvjlqkw8wvdrNbS3DQqhsaPYdg7d1KS66byLlYJ/Bkri9XK+IYu9Z9eXRDpS ElxQ== 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=78sPD/imWiDIsa2rzloBZkC1dL8B6n9ak9VaEkzrNVo=; b=gyK9EO9MFF2F9W+dX8/19eYFW4YiuCXyBsHQVXFwRKno/ck2QeHRQ8gt6mqk89J9D3 mdjU9rkJ7K8cVyODDHcJ5MWOll005R0ucguIPHlqA54012SnNIilzJZ5dZsCfnA05erN pozwOKAGIHCzALNmEimJxkoDEpRrh8b1jgn25PDId+FH0wyt8pRkfJYwzNT92yO86QBX Z+QjhIOt6H3Lqcw/Z+Tr2CZ1Jh30Rb6L9TeU92LbONfDKPVrlBOzWTxJSX9kLMG2yugm Hv9CCRtH1n4HkTwnSaHcIQBSFuEU4NR9ayJvy3jAURLoMRPSQf078Q10r5S4mXNb8Dd1 Huig== X-Gm-Message-State: AOAM533Q1rfhlzW2VkPXe0nnjdw1BdgqBgM+EWMgs1S//PKzbi6DNl3r 6brFX37bEkB4kGktYlIQmRfm8tnJno3Fk064 X-Google-Smtp-Source: ABdhPJz7T8qphhVzZJVJLrFg4cK2xaNv8JvmweGmHM3ljMLVKT0wcJc5y6JGmOjWyxs7MoIvZu7s/w== X-Received: by 2002:a37:6413:: with SMTP id y19mr15003063qkb.139.1602274046466; Fri, 09 Oct 2020 13:07:26 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id i22sm1687058qki.74.2020.10.09.13.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 13:07:25 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v3 2/8] btrfs: push the NODATASUM check into btrfs_lookup_bio_sums Date: Fri, 9 Oct 2020 16:07:14 -0400 Message-Id: <668ac60b9f619639eaedca3b3fe026f546751517.1602273837.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When we move to being able to handle NULL csum_roots it'll be cleaner to just check in btrfs_lookup_bio_sums instead of at all of the caller locations, so push the NODATASUM check into it as well so it's unified. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/compression.c | 14 +++++--------- fs/btrfs/file-item.c | 3 +++ fs/btrfs/inode.c | 12 +++++++++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index eeface30facd..7e1eb57b923c 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -722,11 +722,9 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, */ refcount_inc(&cb->pending_bios); - if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) { - ret = btrfs_lookup_bio_sums(inode, comp_bio, - (u64)-1, sums); - BUG_ON(ret); /* -ENOMEM */ - } + ret = btrfs_lookup_bio_sums(inode, comp_bio, (u64)-1, + sums); + BUG_ON(ret); /* -ENOMEM */ nr_sectors = DIV_ROUND_UP(comp_bio->bi_iter.bi_size, fs_info->sectorsize); @@ -751,10 +749,8 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, ret = btrfs_bio_wq_end_io(fs_info, comp_bio, BTRFS_WQ_ENDIO_DATA); BUG_ON(ret); /* -ENOMEM */ - if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) { - ret = btrfs_lookup_bio_sums(inode, comp_bio, (u64)-1, sums); - BUG_ON(ret); /* -ENOMEM */ - } + ret = btrfs_lookup_bio_sums(inode, comp_bio, (u64)-1, sums); + BUG_ON(ret); /* -ENOMEM */ ret = btrfs_map_bio(fs_info, comp_bio, mirror_num); if (ret) { diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 8f4f2bd6d9b9..8083d71d6af6 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -272,6 +272,9 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, int count = 0; u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); + if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) + return BLK_STS_OK; + path = btrfs_alloc_path(); if (!path) return BLK_STS_RESOURCE; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 936c3137c646..9f77e9e9c31d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2202,7 +2202,12 @@ blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio, mirror_num, bio_flags); goto out; - } else if (!skip_sum) { + } else { + /* + * Lookup bio sums does extra checks around whether we + * need to csum or not, which is why we ignore skip_sum + * here. + */ ret = btrfs_lookup_bio_sums(inode, bio, (u64)-1, NULL); if (ret) goto out; @@ -7778,7 +7783,6 @@ static blk_qc_t btrfs_submit_direct(struct inode *inode, struct iomap *iomap, struct bio *dio_bio, loff_t file_offset) { const bool write = (bio_op(dio_bio) == REQ_OP_WRITE); - const bool csum = !(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); const bool raid56 = (btrfs_data_alloc_profile(fs_info) & BTRFS_BLOCK_GROUP_RAID56_MASK); @@ -7805,10 +7809,12 @@ static blk_qc_t btrfs_submit_direct(struct inode *inode, struct iomap *iomap, return BLK_QC_T_NONE; } - if (!write && csum) { + if (!write) { /* * Load the csums up front to reduce csum tree searches and * contention when submitting bios. + * + * If we have csums disabled this will do nothing. */ status = btrfs_lookup_bio_sums(inode, dio_bio, file_offset, dip->csums); From patchwork Fri Oct 9 20:07:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11829471 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5DD71744 for ; Fri, 9 Oct 2020 20:09:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A458C2067D for ; Fri, 9 Oct 2020 20:09:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="L1WTA/q3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390826AbgJIUJv (ORCPT ); Fri, 9 Oct 2020 16:09:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391090AbgJIUIY (ORCPT ); Fri, 9 Oct 2020 16:08:24 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 707C2C0613AA for ; Fri, 9 Oct 2020 13:07:29 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id z33so5046954qth.8 for ; Fri, 09 Oct 2020 13:07:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=SpGBSwJV9+4FQISbzDXxU0agkkm03QSM5d/DDpeMQfY=; b=L1WTA/q3usWdQyjiW/hHocW4+9LpUJnZSEa1fxiVHJW4ctY6DsHhmSE2YveU5m+pDX uMhaugcnMe0IFygEG9cbMBxRO5CGVXrl15IEHbGVaENs1Gh/aeZL45hDks8KC70M22Ha jeOLoN8j3zg5bgXDVvvT13LQokEVJmtYOkgFMWxn/Zdzvk/Zs+RP6epfz1Uz0nsPxdQu aWSNUPBAgipKJOykwtQ7TJaSSAQfy8jUinXbc0hp0RlNWqdSyky+361uzhh3Z+qCK6cU WHeqw3A4DxhSh8LFjOKFaBSCAeDPRmSxuemmyYgVYI4+3SRwQDKVOZmoBHOBxTeOjaKO YkjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SpGBSwJV9+4FQISbzDXxU0agkkm03QSM5d/DDpeMQfY=; b=ENsSfydJhqApk+G1yOrIlWo5p+sbviBwKWZTeiYzeY7R5r0WRVU9YVD1x2ZE2m5K90 D5N55m/2gqVG4jdUH6h2O74/mxP09weMWsH5+S4KxV2QadzJGd2J4SXoXmQfBvttIFPO XjSkONjNv/TqJay1cjMx78bCc+/m0AOZPiFjGPeaDpR2yzC6jnL+E6W1FH6wZtJ3jw4n HpX1Ty7FzKjjYxYVTz7ipK5BU7ZzP0KW/sEDWmG4Ya4K8Ww4FghIrtABDGMEQR1pWB3b bd2JZ06z0qig2cZ3oPQl1af6budiS+2C/54IjsdZldsdKZ02bt+wsN5lzXGvE4aYmJM6 4sNw== X-Gm-Message-State: AOAM53172GVa3sQS9uExdmejYNsC8hUFW7djh/NQ8eDQnUT3x1UkStWM l23sNpxfMbCAIwlCvbuDV8uOLuW8qB/nJpqL X-Google-Smtp-Source: ABdhPJzTdpfI0xBR3E46Tbiza98W6QS5X7E5LHYTYlor1sBOOuSFT77kYGotQckjNGi22bEcbyc30w== X-Received: by 2002:ac8:7281:: with SMTP id v1mr14872671qto.229.1602274048168; Fri, 09 Oct 2020 13:07:28 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id h199sm7010512qke.112.2020.10.09.13.07.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 13:07:27 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 3/8] btrfs: add a supported_rescue_options file to sysfs Date: Fri, 9 Oct 2020 16:07:15 -0400 Message-Id: <8ac207c64e2917d7980570e6c9f696e234baf070.1602273837.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're going to be adding a variety of different rescue options, we should advertise which ones we support to make user spaces life easier in the future. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/sysfs.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 279d9262b676..5c558e65c1ba 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -329,10 +329,32 @@ static ssize_t send_stream_version_show(struct kobject *kobj, } BTRFS_ATTR(static_feature, send_stream_version, send_stream_version_show); +static const char *rescue_opts[] = { + "usebackuproot", + "nologreplay", +}; + +static ssize_t supported_rescue_options_show(struct kobject *kobj, + struct kobj_attribute *a, + char *buf) +{ + ssize_t ret = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(rescue_opts); i++) + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s%s", + (i ? " " : ""), rescue_opts[i]); + ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n"); + return ret; +} +BTRFS_ATTR(static_feature, supported_rescue_options, + supported_rescue_options_show); + static struct attribute *btrfs_supported_static_feature_attrs[] = { BTRFS_ATTR_PTR(static_feature, rmdir_subvol), BTRFS_ATTR_PTR(static_feature, supported_checksums), BTRFS_ATTR_PTR(static_feature, send_stream_version), + BTRFS_ATTR_PTR(static_feature, supported_rescue_options), NULL }; From patchwork Fri Oct 9 20:07:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11829479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C52D1744 for ; Fri, 9 Oct 2020 20:10:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08EBB2067D for ; Fri, 9 Oct 2020 20:10:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="YI35wXCP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733213AbgJIUJ7 (ORCPT ); Fri, 9 Oct 2020 16:09:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391110AbgJIUIY (ORCPT ); Fri, 9 Oct 2020 16:08:24 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1406AC0613AB for ; Fri, 9 Oct 2020 13:07:31 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id q63so11899419qkf.3 for ; Fri, 09 Oct 2020 13:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=l2yK7ssGtYclsDwXxCx9nxPY11OspLOvX43o0ydPIMc=; b=YI35wXCPqSeRyfrZJV7tOPDhIb3Fb3FQrRyfsbqKG0T8n4Ng/1Ap6CLihnZ52GTG0D POh053s+UJx59BrK3O7i6qptuAJ7EaMoyeWqXLb6H+rHDuw14i65rdU66iDGCRLG9kXO LCzk9NaWPtuDJr/DDRGr8mDTh0E2jzqnZsddAOKocvPr6C4J1K/TqsiRJ2JLBMnFOiUf 7yM0a3Va0bPdW/DQvmwDEDUmJMn7bovgglwLP58ug+0h55fr05OBSuY7/NRY4WQ9ECJw 7dg0g14nvxR8VUmKRgQo8ny6DdPta7jlG3MLoyCBE07rklVvapinw6tzHBkZcicmeLsx kCiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l2yK7ssGtYclsDwXxCx9nxPY11OspLOvX43o0ydPIMc=; b=eOGr32Hv7FPzhCrxMTzrs5FVNfVFHAgIJh9axGZJ9KPXpnOpmtWi6C8B7k5jDeVKdM 1vhxG7NQtgj2DbP3Ts+1US73mVC4g507yRis2o7Vh5kPqd1c0LWgEa9zVpfPGFSi2VWn Zirgnjm0plHTqI/VSD+3AUee6ynFwTwtFr82liBXC0cSC2F8owduZhIE4wImo5oU3PZI kZKZKgICHC+PqDaRKNfkr1yXbZ5mT/2ZQbOMimf0nN5EYanK1p9BipkB909Eotzlr6J0 UsfpbczqFoF3jfPyfgKQZcXxZvFuckrkn36J1/XQVT94upyX9vCb35SDFg64eCf3WqpL u+7Q== X-Gm-Message-State: AOAM532vm4VRQxjvNF53g956Y7yohnzF56UOk/rOspdgGGnNYH62TpwG hCMbx7aW7w+UdH7n2cX4/qETXbL7uL3Jk9eo X-Google-Smtp-Source: ABdhPJyOaJZQJeO38Wi0txkaltPbIq5grFhhpMxrvS3Fd5HlC1rV9tCq/dFfn4BehWyLhmBzoFFnbQ== X-Received: by 2002:a37:bf87:: with SMTP id p129mr15169612qkf.203.1602274049910; Fri, 09 Oct 2020 13:07:29 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id g7sm7133847qtc.19.2020.10.09.13.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 13:07:29 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 4/8] btrfs: add a helper to print out rescue= options Date: Fri, 9 Oct 2020 16:07:16 -0400 Message-Id: <9519d52d87d0cd2d65ba651a8a1282106d988d76.1602273837.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We're going to have a lot of rescue options, add a helper to collapse the /proc/mounts output to rescue=option1:option2:option3 format. Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index f99e89ec46b2..be56fe15cd74 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1392,11 +1392,18 @@ int btrfs_sync_fs(struct super_block *sb, int wait) return btrfs_commit_transaction(trans); } +#define print_rescue_option(opt, name) \ + if (btrfs_test_opt(info, opt)) { \ + seq_printf(seq, "%s%s", printed ? ":" : ",rescue=", name); \ + printed = true; \ + } \ + static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) { struct btrfs_fs_info *info = btrfs_sb(dentry->d_sb); const char *compress_type; const char *subvol_name; + bool printed = false; if (btrfs_test_opt(info, DEGRADED)) seq_puts(seq, ",degraded"); @@ -1428,8 +1435,7 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) seq_puts(seq, ",ssd"); if (btrfs_test_opt(info, NOTREELOG)) seq_puts(seq, ",notreelog"); - if (btrfs_test_opt(info, NOLOGREPLAY)) - seq_puts(seq, ",rescue=nologreplay"); + print_rescue_option(NOLOGREPLAY, "nologreplay"); if (btrfs_test_opt(info, FLUSHONCOMMIT)) seq_puts(seq, ",flushoncommit"); if (btrfs_test_opt(info, DISCARD_SYNC)) From patchwork Fri Oct 9 20:07:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11829475 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D1CF109B for ; Fri, 9 Oct 2020 20:09:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7138420659 for ; Fri, 9 Oct 2020 20:09:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="ZPuCPVJ/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390510AbgJIUJy (ORCPT ); Fri, 9 Oct 2020 16:09:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391552AbgJIUIY (ORCPT ); Fri, 9 Oct 2020 16:08:24 -0400 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B52CDC0613AC for ; Fri, 9 Oct 2020 13:07:32 -0700 (PDT) Received: by mail-qv1-xf2d.google.com with SMTP id w5so5351812qvn.12 for ; Fri, 09 Oct 2020 13:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Ac1qx01ErdfXoxCL4GvK14Cn43Znmfo8Fb5I7SlNNaw=; b=ZPuCPVJ/paSRfPK6S3L9XUrnwNyk57xs6AxsJpfU9BCV0PaFUerOcc/iSh1lSEY0SW WCJEUtLENth5tWGNFhjTgtAcMXjD05fXO/t7zjrij0a+htQ+bJnyhkS7gMA0oBEtalW3 F6QMzERRVM7oSU87hkcZEwBh0B3jsPeKdAc/bnAklx5WP6yFZUbpNX6b27JpY8oCoFFA VGdhVeEDO1hv5rmT5Tj4CUWkYWOpk2EUIxg26UyuWtCkU+ri+/Te6ELTbVWy6PiXIi4N wYUIe0iMKEabtW+2a1TCF7TWlYhg9niGsczEJaBu3ucMUpc3rt8jLvgBU0agAyNdPypE cymg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ac1qx01ErdfXoxCL4GvK14Cn43Znmfo8Fb5I7SlNNaw=; b=lu81KE+32ZZKNx1l6LY7BlA55d1B5J+6/QX/K10FlIfkkQwrzUFcnmj/fbssMNQIhP Lm6LKOgxc+ldWuiGYh7OJdbxHpeCHFtGTkPCY254cXvzLxugFhuaL6AI2dbwonk50zqf Tf+VB/y/EVw6SRZHEn/rYZEBPIwyVVG8/D4uDotrgq8MG5wthQ91S51Fe2yQYbu+AFoh UxaPBpgNrivZLU+nJv8vSjknpmK/GaPmebrlNPLiJ8vhECMFe9rqoSJh12J8/2/ROpuy WukckKxBEJMjZGDr7/AZiJjK7xr/7co1O5AMPY+pvovHOTE8wUqDd3tz2hf0so9r1/lS OVbw== X-Gm-Message-State: AOAM531vQkcM/i8oj1Zxt5z3hUr9MYDjgDujL0piws77Bpunj/+fb0T8 WbwrPV1OgDMC9BBVXv/oTsUqMrMpArUJI1kn X-Google-Smtp-Source: ABdhPJzbdxGI87U6N1UNdZGU0Rbq+ff1G3MzCFzHtlmZVi4vpoh8eLdR6BdvGr5xbccKLaxO04Y4Cw== X-Received: by 2002:a0c:8b02:: with SMTP id q2mr14853299qva.48.1602274051684; Fri, 09 Oct 2020 13:07:31 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id l134sm7130842qke.17.2020.10.09.13.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 13:07:31 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 5/8] btrfs: show rescue=usebackuproot in /proc/mounts Date: Fri, 9 Oct 2020 16:07:17 -0400 Message-Id: <64b9c0fc1b1bdf7bbf8630ffa31f3f296e63ccf3.1602273837.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This got missed somehow, so add it in. Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index be56fe15cd74..833b7eb91536 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1436,6 +1436,7 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) if (btrfs_test_opt(info, NOTREELOG)) seq_puts(seq, ",notreelog"); print_rescue_option(NOLOGREPLAY, "nologreplay"); + print_rescue_option(USEBACKUPROOT, "usebackuproot"); if (btrfs_test_opt(info, FLUSHONCOMMIT)) seq_puts(seq, ",flushoncommit"); if (btrfs_test_opt(info, DISCARD_SYNC)) From patchwork Fri Oct 9 20:07:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11829469 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0D6C109B for ; Fri, 9 Oct 2020 20:09:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DF0220659 for ; Fri, 9 Oct 2020 20:09:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="ZxOsX6aZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390070AbgJIUJu (ORCPT ); Fri, 9 Oct 2020 16:09:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391343AbgJIUIY (ORCPT ); Fri, 9 Oct 2020 16:08:24 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBDD8C0613AE for ; Fri, 9 Oct 2020 13:07:34 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id 188so11826232qkk.12 for ; Fri, 09 Oct 2020 13:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ftTs+U31YKAAWO3mY773spMIkOJL5Cg3a24UxQNNEsY=; b=ZxOsX6aZJD6InEBZjYGaqJcBsut9GNb2zozwC3QpLExk6kXplyTqCasGB+laEViq+V q2dfb9WYcZ4Z2PTZGTS1MV65SE1sTY074ZzZEL1tJTXViBKKzTlKujOysmpSxPn4zkUj mPOCgSVFjdWtngF5s2NmjIHgurT0LU6PqiCnoK1Bvh8K66YZxY2lUltZylKiwoNTkjiX M4MPWFFxJVcA9E2rmsAQx+XRRj94pzlfacxmYu2tFfwXyQDbcEH0m35sL/yzZPOLr9ZT +wv0JVqn14rmgB4RCRTMuyg3yLOoZ2WVOzxyN3qPrS4Nka6nIoOJZ3Ej6AXHfEP9R0T5 +/KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ftTs+U31YKAAWO3mY773spMIkOJL5Cg3a24UxQNNEsY=; b=K1ooiUy0DkYIo7j54sV5GgRFnAxHwDL28EWr88kz4mAcEnDiC8q+VZQfZOFSzKz6Qc Jdki3VkGAu1MnzqU68FIeq8hC7T2hrZeLad8/7goqEMc3L93RcorMYFnmm7SXEZXVcpG 0hGzFaq7AHlkoN+sJqgp8oZUDQdOLJDxGYjQ4uH568q8RjnHJITJmEfk3Kjm//t9enV6 zwd0IzIB1xvAh7fwj8swwzPY9eSKQoANq1Q1g+XHjQKe2p+jBrdnekXYBuTmKsZElUj1 Te3NwSxgyEvZ4GDJQT1cPqDTawhYJAbweVOowwLgFMwc7dVilgCTaGVnPhToMb+sipnP 6OHg== X-Gm-Message-State: AOAM533oKgrNdYClwCT3XVVM6MkcuJMFwUMqqk9QTyR5r9kkdTh0hNMu 3J2h+FRNZtua3+E8UxnCEzeGW0kvHu+8qQuj X-Google-Smtp-Source: ABdhPJzsxTUKxg1LTqOvzYl/DRHzD9MBMMB4sbv6RuMiVUj1PJL9AXnmWsKYC/VmNCDKu/kM1GtBxQ== X-Received: by 2002:a05:620a:653:: with SMTP id a19mr15170803qka.440.1602274053460; Fri, 09 Oct 2020 13:07:33 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id h4sm6808489qtq.41.2020.10.09.13.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 13:07:32 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v3 6/8] btrfs: introduce rescue=ignorebadroots Date: Fri, 9 Oct 2020 16:07:18 -0400 Message-Id: <2baf880894a1a49b59a369acad832222973d5932.1602273837.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In the face of extent root corruption, or any other core fs wide root corruption we will fail to mount the file system. This makes recovery kind of a pain, because you need to fall back to userspace tools to scrape off data. Instead provide a mechanism to gracefully handle bad roots, so we can at least mount read-only and possibly recover data from the file system. Signed-off-by: Josef Bacik --- fs/btrfs/block-group.c | 48 +++++++++++++++++++++++++++++++ fs/btrfs/block-rsv.c | 8 ++++++ fs/btrfs/compression.c | 3 +- fs/btrfs/ctree.h | 1 + fs/btrfs/disk-io.c | 65 ++++++++++++++++++++++++++---------------- fs/btrfs/file-item.c | 3 +- fs/btrfs/inode.c | 6 +++- fs/btrfs/super.c | 11 ++++++- fs/btrfs/sysfs.c | 1 + fs/btrfs/volumes.c | 13 +++++++++ 10 files changed, 131 insertions(+), 28 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index c0f1d6818df7..7e32f7820543 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1985,6 +1985,51 @@ static int read_one_block_group(struct btrfs_fs_info *info, return ret; } +static int fill_dummy_bgs(struct btrfs_fs_info *fs_info) +{ + struct extent_map_tree *em_tree = &fs_info->mapping_tree; + struct extent_map *em; + struct map_lookup *map; + struct btrfs_block_group *bg; + struct btrfs_space_info *space_info; + struct rb_node *node; + int ret = 0; + + for (node = rb_first_cached(&em_tree->map); node; + node = rb_next(node)) { + em = rb_entry(node, struct extent_map, rb_node); + map = em->map_lookup; + bg = btrfs_create_block_group_cache(fs_info, em->start); + if (!bg) { + ret = -ENOMEM; + break; + } + + /* Fill dummy cache as FULL */ + bg->length = em->len; + bg->flags = map->type; + bg->last_byte_to_unpin = (u64)-1; + bg->cached = BTRFS_CACHE_FINISHED; + bg->used = em->len; + bg->flags = map->type; + ret = btrfs_add_block_group_cache(fs_info, bg); + if (ret) { + btrfs_remove_free_space_cache(bg); + btrfs_put_block_group(bg); + break; + } + btrfs_update_space_info(fs_info, bg->flags, em->len, em->len, + 0, &space_info); + bg->space_info = space_info; + link_block_group(bg); + + set_avail_alloc_bits(fs_info, bg->flags); + } + if (!ret) + btrfs_init_global_block_rsv(fs_info); + return ret; +} + int btrfs_read_block_groups(struct btrfs_fs_info *info) { struct btrfs_path *path; @@ -1995,6 +2040,9 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info) int need_clear = 0; u64 cache_gen; + if (!info->extent_root) + return fill_dummy_bgs(info); + key.objectid = 0; key.offset = 0; key.type = BTRFS_BLOCK_GROUP_ITEM_KEY; diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index 7e1549a84fcc..58b38912498d 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -426,6 +426,14 @@ void btrfs_init_global_block_rsv(struct btrfs_fs_info *fs_info) fs_info->delayed_block_rsv.space_info = space_info; fs_info->delayed_refs_rsv.space_info = space_info; + /* + * Our various recovery options can leave us with NULL roots, so check + * here and just bail before we go deref'ing NULLS everywhere. + */ + if (!fs_info->extent_root || !fs_info->csum_root || + !fs_info->dev_root || !fs_info->chunk_root || !fs_info->tree_root) + return; + fs_info->extent_root->block_rsv = &fs_info->delayed_refs_rsv; fs_info->csum_root->block_rsv = &fs_info->delayed_refs_rsv; fs_info->dev_root->block_rsv = &fs_info->global_block_rsv; diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 7e1eb57b923c..46dc621f599d 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -150,7 +150,8 @@ static int check_compressed_csum(struct btrfs_inode *inode, struct bio *bio, struct compressed_bio *cb = bio->bi_private; u8 *cb_sum = cb->sums; - if (inode->flags & BTRFS_INODE_NODATASUM) + if (!fs_info->csum_root || + inode->flags & BTRFS_INODE_NODATASUM) return 0; shash->tfm = fs_info->csum_shash; diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index aac3d6f4e35b..fb3cfd0aaf1e 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1295,6 +1295,7 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) #define BTRFS_MOUNT_NOLOGREPLAY (1 << 27) #define BTRFS_MOUNT_REF_VERIFY (1 << 28) #define BTRFS_MOUNT_DISCARD_ASYNC (1 << 29) +#define BTRFS_MOUNT_IGNOREBADROOTS (1 << 30) #define BTRFS_DEFAULT_COMMIT_INTERVAL (30) #define BTRFS_DEFAULT_MAX_INLINE (2048) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 764001609a15..f08887703915 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2247,30 +2247,39 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) root = btrfs_read_tree_root(tree_root, &location); if (IS_ERR(root)) { - ret = PTR_ERR(root); - goto out; + if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { + ret = PTR_ERR(root); + goto out; + } + } else { + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); + fs_info->extent_root = root; } - set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); - fs_info->extent_root = root; location.objectid = BTRFS_DEV_TREE_OBJECTID; root = btrfs_read_tree_root(tree_root, &location); if (IS_ERR(root)) { - ret = PTR_ERR(root); - goto out; + if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { + ret = PTR_ERR(root); + goto out; + } + } else { + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); + fs_info->dev_root = root; + btrfs_init_devices_late(fs_info); } - set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); - fs_info->dev_root = root; - btrfs_init_devices_late(fs_info); location.objectid = BTRFS_CSUM_TREE_OBJECTID; root = btrfs_read_tree_root(tree_root, &location); if (IS_ERR(root)) { - ret = PTR_ERR(root); - goto out; + if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { + ret = PTR_ERR(root); + goto out; + } + } else { + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); + fs_info->csum_root = root; } - set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); - fs_info->csum_root = root; /* * This tree can share blocks with some other fs tree during relocation @@ -2279,11 +2288,14 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) root = btrfs_get_fs_root(tree_root->fs_info, BTRFS_DATA_RELOC_TREE_OBJECTID, true); if (IS_ERR(root)) { - ret = PTR_ERR(root); - goto out; + if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { + ret = PTR_ERR(root); + goto out; + } + } else { + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); + fs_info->data_reloc_root = root; } - set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); - fs_info->data_reloc_root = root; location.objectid = BTRFS_QUOTA_TREE_OBJECTID; root = btrfs_read_tree_root(tree_root, &location); @@ -2296,9 +2308,11 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) location.objectid = BTRFS_UUID_TREE_OBJECTID; root = btrfs_read_tree_root(tree_root, &location); if (IS_ERR(root)) { - ret = PTR_ERR(root); - if (ret != -ENOENT) - goto out; + if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { + ret = PTR_ERR(root); + if (ret != -ENOENT) + goto out; + } } else { set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); fs_info->uuid_root = root; @@ -2308,11 +2322,14 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) location.objectid = BTRFS_FREE_SPACE_TREE_OBJECTID; root = btrfs_read_tree_root(tree_root, &location); if (IS_ERR(root)) { - ret = PTR_ERR(root); - goto out; + if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { + ret = PTR_ERR(root); + goto out; + } + } else { + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); + fs_info->free_space_root = root; } - set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); - fs_info->free_space_root = root; } return 0; diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 8083d71d6af6..90c728652033 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -272,7 +272,8 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, int count = 0; u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); - if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) + if (!fs_info->csum_root || + BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) return BLK_STS_OK; path = btrfs_alloc_path(); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9f77e9e9c31d..4834a2565dac 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2187,7 +2187,8 @@ blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio, int skip_sum; int async = !atomic_read(&BTRFS_I(inode)->sync_writers); - skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; + skip_sum = (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) || + !fs_info->csum_root; if (btrfs_is_free_space_inode(BTRFS_I(inode))) metadata = BTRFS_WQ_ENDIO_FREE_SPACE; @@ -2844,6 +2845,9 @@ int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u64 phy_offset, if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM) return 0; + if (!root->fs_info->csum_root) + return 0; + if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID && test_range_bit(io_tree, start, end, EXTENT_NODATASUM, 1, NULL)) { clear_extent_bits(io_tree, start, end, EXTENT_NODATASUM); diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 833b7eb91536..dccdc670998d 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -360,6 +360,7 @@ enum { Opt_rescue, Opt_usebackuproot, Opt_nologreplay, + Opt_ignorebadroots, /* Deprecated options */ Opt_recovery, @@ -455,6 +456,8 @@ static const match_table_t tokens = { static const match_table_t rescue_tokens = { {Opt_usebackuproot, "usebackuproot"}, {Opt_nologreplay, "nologreplay"}, + {Opt_ignorebadroots, "ignorebadroots"}, + {Opt_ignorebadroots, "ibadroots"}, {Opt_err, NULL}, }; @@ -498,6 +501,10 @@ static int parse_rescue_options(struct btrfs_fs_info *info, const char *options) btrfs_set_and_info(info, NOLOGREPLAY, "disabling log replay at mount time"); break; + case Opt_ignorebadroots: + btrfs_set_and_info(info, IGNOREBADROOTS, + "ignoring bad roots"); + break; case Opt_err: btrfs_info(info, "unrecognized rescue option '%s'", p); ret = -EINVAL; @@ -983,7 +990,8 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, if (new_flags & SB_RDONLY) goto out; - if (check_ro_option(info, BTRFS_MOUNT_NOLOGREPLAY, "nologreplay")) + if (check_ro_option(info, BTRFS_MOUNT_NOLOGREPLAY, "nologreplay") || + check_ro_option(info, BTRFS_MOUNT_IGNOREBADROOTS, "ignorebadroots")) ret = -EINVAL; out: if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE) && @@ -1437,6 +1445,7 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) seq_puts(seq, ",notreelog"); print_rescue_option(NOLOGREPLAY, "nologreplay"); print_rescue_option(USEBACKUPROOT, "usebackuproot"); + print_rescue_option(IGNOREBADROOTS, "ignorebadroots"); if (btrfs_test_opt(info, FLUSHONCOMMIT)) seq_puts(seq, ",flushoncommit"); if (btrfs_test_opt(info, DISCARD_SYNC)) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 5c558e65c1ba..c60240d0d7e6 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -332,6 +332,7 @@ BTRFS_ATTR(static_feature, send_stream_version, send_stream_version_show); static const char *rescue_opts[] = { "usebackuproot", "nologreplay", + "ignorebadroots", }; static ssize_t supported_rescue_options_show(struct kobject *kobj, diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 58b9c419a2b6..1dc0b9425a28 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -7662,6 +7662,19 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info) u64 prev_dev_ext_end = 0; int ret = 0; + /* + * We don't have a dev_root because we mounted with ignorebadroots and + * failed to load the root, so we want to skip the verification in this + * case for sure. + * + * However if the dev root is fine, but the tree itself is corrupt we'd + * still fail to mount. This verification is only to make sure writes + * can happen safely, so instead just bypass this check completely in + * the case of IGNOREBADROOTS. + */ + if (btrfs_test_opt(fs_info, IGNOREBADROOTS)) + return 0; + key.objectid = 1; key.type = BTRFS_DEV_EXTENT_KEY; key.offset = 0; From patchwork Fri Oct 9 20:07:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11829467 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46F95109B for ; Fri, 9 Oct 2020 20:09:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 270962067D for ; Fri, 9 Oct 2020 20:09:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="zxOZfcKC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732677AbgJIUJs (ORCPT ); Fri, 9 Oct 2020 16:09:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391551AbgJIUIZ (ORCPT ); Fri, 9 Oct 2020 16:08:25 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62473C0613B1 for ; Fri, 9 Oct 2020 13:07:36 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id b69so11870659qkg.8 for ; Fri, 09 Oct 2020 13:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l1Q/E5ajjkHF2MyVXehvEF7edFEQTRyiEXftw9I8XQo=; b=zxOZfcKCBZL2sePvXDO9FhLIM1n6gEbN2ETpjaVybPTyuwUnpw3+zpnYYfcPSfgqlU eCaMjPmO8UrobXciWkDLZuElv0Of5QbV3wt3rFyj5DWxkfMMfewD9hegu28rx1yZ+wMI eiYTV4kjMTJCQDDAv/yZzZse112rm8cxaJ8Q7zy8DGKtfl94t/9YPvhX6IDOJ0IhQssK byIvT/csnAXo4i3O0vi2hd8XHLUA2XOQ/h3Bo/sMQr+oKTx4UEUdLgLSHqvaMtNNqbxw cizlhhKnOpUT8AVl5TuMCihpTB4Z2Gn8oz/tvrYCLz18fCXLsGtgw0Sd2tMLc8crfYWX muQA== 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=l1Q/E5ajjkHF2MyVXehvEF7edFEQTRyiEXftw9I8XQo=; b=NNwkrVpGp+umyGTTUJqOsCWoWPQjU1dzPQ85pzgVvD9nHGKh/qVEVxFd0jLBMXWZSk 2e5SAOFTJ2cM6Ghr6Ep8EVRNYYuwh32uQUaWdptVHF9mN9dmHo19wmh2FMRxNchIfdbe p37XTmuJ6bQjpYm7T/1heQZyLhOnGgmZJ135WmGCD18gaFKA/mb2L9lV2OHyi3BhalU/ Xoy21SUp2t7KViDtQGivHMOAmmbDv9DF5KaDKa3rD0OH+scBnbKt03RljU9TeFdHsAQK qhI2moD1Q40mqa1fbnpZXZbfvnNRNjCWDh5smV8Rd1IG/aNyuL+teUF5oZexjD6H/omd 3JnQ== X-Gm-Message-State: AOAM531M6hcRmXmsxDTNeXcQ+yfxibAdw6QQrabZp4LdeTd5sSOXoY+g ciDKe3LgNbvoMN2FWJQz+SLvrvgDlJsXbMvl X-Google-Smtp-Source: ABdhPJzRmPaMgN/dKhq6zsoNXouxn0hmNUHJ/3GEOMnmRxpHl5OmYOtxFXbGBh6xYLla7XkvroTpyQ== X-Received: by 2002:a37:9e8e:: with SMTP id h136mr15822570qke.205.1602274055185; Fri, 09 Oct 2020 13:07:35 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id 17sm6613262qky.0.2020.10.09.13.07.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 13:07:34 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v3 7/8] btrfs: introduce rescue=ignoredatacsums Date: Fri, 9 Oct 2020 16:07:19 -0400 Message-Id: <7eb79c39ce53c3989aa3842773cb0384c70b21aa.1602273837.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There are cases where you can end up with bad data csums because of misbehaving applications. This happens when an application modifies a buffer in-flight when doing an O_DIRECT write. In order to recover the file we need a way to turn off data checksums so you can copy the file off, and then you can delete the file and restore it properly later. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/ctree.h | 1 + fs/btrfs/disk-io.c | 21 ++++++++++++--------- fs/btrfs/super.c | 13 ++++++++++++- fs/btrfs/sysfs.c | 1 + 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index fb3cfd0aaf1e..397f5f6b88a4 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1296,6 +1296,7 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) #define BTRFS_MOUNT_REF_VERIFY (1 << 28) #define BTRFS_MOUNT_DISCARD_ASYNC (1 << 29) #define BTRFS_MOUNT_IGNOREBADROOTS (1 << 30) +#define BTRFS_MOUNT_IGNOREDATACSUMS (1 << 31) #define BTRFS_DEFAULT_COMMIT_INTERVAL (30) #define BTRFS_DEFAULT_MAX_INLINE (2048) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index f08887703915..0d105398fdcf 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2269,16 +2269,19 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) btrfs_init_devices_late(fs_info); } - location.objectid = BTRFS_CSUM_TREE_OBJECTID; - root = btrfs_read_tree_root(tree_root, &location); - if (IS_ERR(root)) { - if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { - ret = PTR_ERR(root); - goto out; + /* If IGNOREDATASCUMS is set don't bother reading the csum root. */ + if (!btrfs_test_opt(fs_info, IGNOREDATACSUMS)) { + location.objectid = BTRFS_CSUM_TREE_OBJECTID; + root = btrfs_read_tree_root(tree_root, &location); + if (IS_ERR(root)) { + if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { + ret = PTR_ERR(root); + goto out; + } + } else { + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); + fs_info->csum_root = root; } - } else { - set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); - fs_info->csum_root = root; } /* diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index dccdc670998d..becb61204eb5 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -361,6 +361,7 @@ enum { Opt_usebackuproot, Opt_nologreplay, Opt_ignorebadroots, + Opt_ignoredatacsums, /* Deprecated options */ Opt_recovery, @@ -458,6 +459,8 @@ static const match_table_t rescue_tokens = { {Opt_nologreplay, "nologreplay"}, {Opt_ignorebadroots, "ignorebadroots"}, {Opt_ignorebadroots, "ibadroots"}, + {Opt_ignoredatacsums, "ignoredatacsums"}, + {Opt_ignoredatacsums, "idatacsums"}, {Opt_err, NULL}, }; @@ -505,6 +508,10 @@ static int parse_rescue_options(struct btrfs_fs_info *info, const char *options) btrfs_set_and_info(info, IGNOREBADROOTS, "ignoring bad roots"); break; + case Opt_ignoredatacsums: + btrfs_set_and_info(info, IGNOREDATACSUMS, + "ignoring data csums"); + break; case Opt_err: btrfs_info(info, "unrecognized rescue option '%s'", p); ret = -EINVAL; @@ -991,7 +998,10 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, goto out; if (check_ro_option(info, BTRFS_MOUNT_NOLOGREPLAY, "nologreplay") || - check_ro_option(info, BTRFS_MOUNT_IGNOREBADROOTS, "ignorebadroots")) + check_ro_option(info, BTRFS_MOUNT_IGNOREBADROOTS, + "ignorebadroots") || + check_ro_option(info, BTRFS_MOUNT_IGNOREDATACSUMS, + "ignoredatacsums")) ret = -EINVAL; out: if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE) && @@ -1446,6 +1456,7 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) print_rescue_option(NOLOGREPLAY, "nologreplay"); print_rescue_option(USEBACKUPROOT, "usebackuproot"); print_rescue_option(IGNOREBADROOTS, "ignorebadroots"); + print_rescue_option(IGNOREDATACSUMS, "ignoredatacsums"); if (btrfs_test_opt(info, FLUSHONCOMMIT)) seq_puts(seq, ",flushoncommit"); if (btrfs_test_opt(info, DISCARD_SYNC)) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index c60240d0d7e6..8edc51f3d894 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -333,6 +333,7 @@ static const char *rescue_opts[] = { "usebackuproot", "nologreplay", "ignorebadroots", + "ignoredatacsums", }; static ssize_t supported_rescue_options_show(struct kobject *kobj, From patchwork Fri Oct 9 20:07:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 11829473 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 55C1C1744 for ; Fri, 9 Oct 2020 20:09:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2ED81206A5 for ; Fri, 9 Oct 2020 20:09:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20150623.gappssmtp.com header.i=@toxicpanda-com.20150623.gappssmtp.com header.b="UFyd8qUD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390919AbgJIUJw (ORCPT ); Fri, 9 Oct 2020 16:09:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391547AbgJIUIY (ORCPT ); Fri, 9 Oct 2020 16:08:24 -0400 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32FFAC0613B2 for ; Fri, 9 Oct 2020 13:07:38 -0700 (PDT) Received: by mail-qv1-xf41.google.com with SMTP id 13so5340779qvc.9 for ; Fri, 09 Oct 2020 13:07:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yIK7tVifUGgk58DzxwFwK37ndYe6FMYgsBUKVRozxME=; b=UFyd8qUDjO/XMXTXKNMNdwSvjuFRCHldEebqRLU3u/sccSI3GSvqF4BGQRZ9ICoFqH Ra2OFBsbddP1GrtAR9YZxNHaMyLg2dWaw5MpG5oAdw7T+TUReqgVG3RrA2xKaqjWK50Z xqi9Wea9BYSN7wrXeDwIwbigSteZree+75scqdeK58yMZW2XDfU+TixuRk3Siig2gyUK qnsXhJY0g2MwXwfnYoMuYAo9QH8zpUb5ZnORFHnj45x2EhWzcH5Tg8w5Z8q5YwMgqSgf KLtMnQu8E6YB3ppikL1X1zlr5TaMeugQgLe3egp4DlWTtZun7QCcugeZaAT3JYNPcTrE hoHA== 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=yIK7tVifUGgk58DzxwFwK37ndYe6FMYgsBUKVRozxME=; b=ZvQb2ufnxt59lOJR/RtopzrB9VgpifeQdbM/RmIEiFfS2IMwbnuCwlMwj/SfvmOkTG BKN/ODgyYM3xUTv+n7fVKA5Jgc3z0it8hQV13Q2vjDphZjAXuNPXdmeFLu8d1/mEUZk6 JTisGJM5UeV5cwCYmcV/21XGTLEzvrz0Mb6Qmjc/19UTsWYlSGMH7RMpN6wKyqAUxBiC Ic/yk8XPP7G2S+ysto4XoTz7xCexQllT/sPqMYBC7085h5k9nDC3q9g3uatuSmU4xD2V PGROkbmFR0jas3cuIoLZHhrJ16SL0dwWtU00jJsTVL6TqhR/BNnFm+wm3KCMpLylJTDB MTUA== X-Gm-Message-State: AOAM531pY3pyQVxQlbBn25pYbqFYrADm7+84zxixHi+6TFAplK00jb+w hUjxHSzMKR/poeOzhPSD3lN6o/46zIVdnVzI X-Google-Smtp-Source: ABdhPJz82NYgkHMXLH+jXfyzJb9/MiGyLSmCcDpsl48NC9bjheTvMO5cg7idimwsLeunCbyQIrHw9g== X-Received: by 2002:a05:6214:1267:: with SMTP id r7mr14698877qvv.50.1602274057016; Fri, 09 Oct 2020 13:07:37 -0700 (PDT) Received: from localhost (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id r190sm7192305qkf.101.2020.10.09.13.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 13:07:36 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Qu Wenruo Subject: [PATCH v3 8/8] btrfs: introduce rescue=all Date: Fri, 9 Oct 2020 16:07:20 -0400 Message-Id: <168dc328f4643647a9d9302a7adc7a259233fe7d.1602273837.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that we have the building blocks for some better recovery options with corrupted file systems, add a rescue=all option to enable all of the relevant rescue options. This will allow distro's to simply default to rescue=all for the "oh dear lord the world's on fire" recovery without needing to know all the different options that we have and may add in the future. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 11 +++++++++++ fs/btrfs/sysfs.c | 1 + 2 files changed, 12 insertions(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index becb61204eb5..fb468bab1114 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -362,6 +362,7 @@ enum { Opt_nologreplay, Opt_ignorebadroots, Opt_ignoredatacsums, + Opt_all, /* Deprecated options */ Opt_recovery, @@ -461,6 +462,7 @@ static const match_table_t rescue_tokens = { {Opt_ignorebadroots, "ibadroots"}, {Opt_ignoredatacsums, "ignoredatacsums"}, {Opt_ignoredatacsums, "idatacsums"}, + {Opt_all, "all"}, {Opt_err, NULL}, }; @@ -512,6 +514,15 @@ static int parse_rescue_options(struct btrfs_fs_info *info, const char *options) btrfs_set_and_info(info, IGNOREDATACSUMS, "ignoring data csums"); break; + case Opt_all: + btrfs_info(info, "enabling all of the rescue options"); + btrfs_set_and_info(info, IGNOREDATACSUMS, + "ignoring data csums"); + btrfs_set_and_info(info, IGNOREBADROOTS, + "ignoring bad roots"); + btrfs_set_and_info(info, NOLOGREPLAY, + "disabling log replay at mount time"); + break; case Opt_err: btrfs_info(info, "unrecognized rescue option '%s'", p); ret = -EINVAL; diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 8edc51f3d894..862c954b7f69 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -334,6 +334,7 @@ static const char *rescue_opts[] = { "nologreplay", "ignorebadroots", "ignoredatacsums", + "all", }; static ssize_t supported_rescue_options_show(struct kobject *kobj,