From patchwork Tue Oct 10 07:51:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9995231 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 BE63F603B5 for ; Tue, 10 Oct 2017 07:51:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0D5428066 for ; Tue, 10 Oct 2017 07:51:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5F5C280FC; Tue, 10 Oct 2017 07:51:34 +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,FREEMAIL_FROM, 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 3A37728066 for ; Tue, 10 Oct 2017 07:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755556AbdJJHvc (ORCPT ); Tue, 10 Oct 2017 03:51:32 -0400 Received: from mout.gmx.net ([212.227.15.18]:60367 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754894AbdJJHv1 (ORCPT ); Tue, 10 Oct 2017 03:51:27 -0400 Received: from localhost.localdomain ([104.207.157.105]) by mail.gmx.com (mrgmx001 [212.227.17.184]) with ESMTPSA (Nemesis) id 0LfCX2-1dUuCS3aLg-00orLu; Tue, 10 Oct 2017 09:51:25 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, yoasif@gmail.com, rrauenza@gmail.com Subject: [PATCH 2/4] btrfs-progs: fsck: Introduce --fix-dev-size option Date: Tue, 10 Oct 2017 07:51:11 +0000 Message-Id: <20171010075113.10718-3-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171010075113.10718-1-quwenruo.btrfs@gmx.com> References: <20171010075113.10718-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:rUzGwC3czIDZp7ka+DnvX9X8dwmZJdR5JvyEKcQ2GqsFBQMZ1y4 CToUHlS7+UbltCWy10jEFpj5wWobRTW58HxIS9KSOK+NruV0V7F1tvWOZ5tsnjGpD7q4xw+ 9rRzDn9h30jxvUB6+FILicLFunD/cW5k893okxFeo7GMHRnLogrPsfwCxt3p+ro08uvehwv 4cu+UNqESYNP/6LQnrp1g== X-UI-Out-Filterresults: notjunk:1; V01:K0:U07aCHU6+lM=:GUmlwEp4ivT3BSN2lmF5EW Mfo+A1Twvoe0Xwem3RDDFX4BTTEVDTUcnemaL6Yqjqoc9BQMiQLk68SnNl6hT5o44tTZqx8ma rMDi/efX9zA9U6QVQjH70hDUVV21+QDjui7LVo/mLT0zzcbHCkdbFtgVE6qhNH5djkWXZHYg/ GAtfUJ+HjMAfjX8re1KmB3TfxQ6IlMbD6Bkq0xEiXHGVniNOD7PBQvu8hvlJ8ekvlC8Be1Oy0 kU7sZ3iUAVglby4IcdPq+lvODOL50FiQI3VIu4XnMvF+5RKZuXckOC+ODr4TuoRDwAGQwtC2z 1Xshel7wMILRGZkLqQOrjNq8PZdjheYEiZv+5Ino/XvI8YkpIJQXobG3wqSrmT06VxUsOCHrJ EPtBHDRWN7+QU0AqxDM1cdL9yEoSmRgtTyA5S2AqxvqBWmXr0S/efMDU8Dx6m1/RvGA2kl+ct 7gEfgsIA2XSpug7E71MI0YXTGk7vtqn+19ioMb2Lm4NRvbXEnkt9Fj4emv59xit9BurRcL4YW FhqRqmT5VjPEumYT19kIsBL+Bl418tpJQyb1SHzmVb2D311YCUXBN/afgMiba5rhp20EvIka+ 8KR6hsDDOebjW4ptJ2McdEWBPzuI6IE61I90T1tqfTG5Ym8SFTcMmMyvHIvioq+VxLnfXdShr a83b5Ws4U3vebK4E9yb6zDLTy/H5LV3m6lSoY2U0DFAFjMABlBoxK+yIoUwKy6kQsqkT7jiSa Q2IOtvOOXDq9aACnUyJ7gh4aGYcdqsGpPEd97ecUp2TGbAwsUfQyrD2z/ZonMuaqylW04x0fW A32wY4jwyUzkEvbLhsZr6t1YfrOrw== 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 Introduce --fix-dev-size option to fix device related problems. This repairing is also included in --repair, but considering the safety and potential affected users, it's better to provide a option to fix and only fix device size related problem to avoid full --repair. Reported-by: Asif Youssuff Reported-by: Rich Rauenzahn Signed-off-by: Qu Wenruo --- Documentation/btrfs-check.asciidoc | 23 +++++++++++++++++++++++ cmds-check.c | 28 +++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Documentation/btrfs-check.asciidoc b/Documentation/btrfs-check.asciidoc index fbf48847ac25..e45c7a457bac 100644 --- a/Documentation/btrfs-check.asciidoc +++ b/Documentation/btrfs-check.asciidoc @@ -93,6 +93,29 @@ the entire free space cache. This option with 'v2' provides an alternative method of clearing the free space cache that doesn't require mounting the filesystem. +--fix-dev-size:: +From v4.14-rc kernels, a more restrict device size checker is introduced, while +old kernel doesn't strictly align its device size, so it may cause noisy kernel +warning for newer kernel, like: ++ +.... +WARNING: CPU: 3 PID: 439 at fs/btrfs/ctree.h:1559 btrfs_update_device+0x1c5/0x1d0 [btrfs] +.... ++ +And for some case where super block total device size may mismatch with all +devices, and the filesystem will be unable to be mounted, with kernel message +like: ++ +.... +BTRFS error (device sdb): super_total_bytes 92017859088384 mismatch with fs_devices total_rw_bytes 92017859094528 +.... ++ +This option will fix both problems by aligning all size of devices, and +re-calculating superblock total bytes. ++ +Although such repairing is included in *--repair* option, considering the +safety of *--repair*, this option is provided to suppress all other dangerous +repairing and only fix device sizes related problems. DANGEROUS OPTIONS ----------------- diff --git a/cmds-check.c b/cmds-check.c index 007781fa5d1b..fdb6d832eee1 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -11746,6 +11746,8 @@ out: return err; } +static int reset_devs_size(struct btrfs_fs_info *fs_info); + static int do_check_chunks_and_extents(struct btrfs_fs_info *fs_info) { int ret; @@ -11756,6 +11758,12 @@ static int do_check_chunks_and_extents(struct btrfs_fs_info *fs_info) ret = check_chunks_and_extents_v2(fs_info); else ret = check_chunks_and_extents(fs_info); + /* Also repair device sizes if needed */ + if (repair && !ret) { + ret = reset_devs_size(fs_info); + if (ret > 0) + ret = 0; + } return ret; } @@ -13088,6 +13096,8 @@ const char * const cmd_check_usage[] = { "-b|--backup use the first valid backup root copy", "--force skip mount checks, repair is not possible", "--repair try to repair the filesystem", + "--fix-dev-size repair device size related problem", + " will not trigger other repair", "--readonly run in read-only mode (default)", "--init-csum-tree create a new CRC tree", "--init-extent-tree create a new extent tree", @@ -13128,6 +13138,7 @@ int cmd_check(int argc, char **argv) int qgroups_repaired = 0; unsigned ctree_flags = OPEN_CTREE_EXCLUSIVE; int force = 0; + bool fix_dev_size = false; while(1) { int c; @@ -13135,7 +13146,7 @@ int cmd_check(int argc, char **argv) GETOPT_VAL_INIT_EXTENT, GETOPT_VAL_CHECK_CSUM, GETOPT_VAL_READONLY, GETOPT_VAL_CHUNK_TREE, GETOPT_VAL_MODE, GETOPT_VAL_CLEAR_SPACE_CACHE, - GETOPT_VAL_FORCE }; + GETOPT_VAL_FORCE, GETOPT_VAL_FIX_DEV_SIZE }; static const struct option long_options[] = { { "super", required_argument, NULL, 's' }, { "repair", no_argument, NULL, GETOPT_VAL_REPAIR }, @@ -13158,6 +13169,8 @@ int cmd_check(int argc, char **argv) { "clear-space-cache", required_argument, NULL, GETOPT_VAL_CLEAR_SPACE_CACHE}, { "force", no_argument, NULL, GETOPT_VAL_FORCE }, + { "fix-dev-size", no_argument, NULL, + GETOPT_VAL_FIX_DEV_SIZE }, { NULL, 0, NULL, 0} }; @@ -13245,6 +13258,11 @@ int cmd_check(int argc, char **argv) case GETOPT_VAL_FORCE: force = 1; break; + case GETOPT_VAL_FIX_DEV_SIZE: + fix_dev_size = true; + repair = 1; + ctree_flags |= OPEN_CTREE_WRITES; + break; } } @@ -13371,6 +13389,14 @@ int cmd_check(int argc, char **argv) report_qgroups(1); goto close_out; } + + if (fix_dev_size) { + ret = reset_devs_size(info); + if (ret > 0) + ret = 0; + err |= !!ret; + goto close_out; + } if (subvolid) { printf("Print extent state for subvolume %llu on %s\nUUID: %s\n", subvolid, argv[optind], uuidbuf);