From patchwork Thu Dec 5 03:15:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygo Blaxell X-Patchwork-Id: 11274093 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 9C90F13A4 for ; Thu, 5 Dec 2019 03:15:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8495A21835 for ; Thu, 5 Dec 2019 03:15:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728804AbfLEDPz (ORCPT ); Wed, 4 Dec 2019 22:15:55 -0500 Received: from james.kirk.hungrycats.org ([174.142.39.145]:47030 "EHLO james.kirk.hungrycats.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728470AbfLEDPz (ORCPT ); Wed, 4 Dec 2019 22:15:55 -0500 X-Envelope-Mail-From: zblaxell@waya.furryterror.org X-Envelope-Mail-From: zblaxell@waya.furryterror.org Received: from waya.furryterror.org (waya.vpn7.hungrycats.org [10.132.226.63]) by james.kirk.hungrycats.org (Postfix) with ESMTP id 392A050D7FA; Wed, 4 Dec 2019 22:15:54 -0500 (EST) Received: from zblaxell by waya.furryterror.org with local (Exim 4.92) (envelope-from ) id 1ichcQ-0007yO-22; Wed, 04 Dec 2019 22:15:54 -0500 From: Zygo Blaxell To: linux-btrfs@vger.kernel.org Subject: [PATCH v2] btrfs-progs: scrub: add start/end position for scrub Date: Wed, 4 Dec 2019 22:15:24 -0500 Message-Id: <20191205031523.11593-2-ce3g8jdj@umail.furryterror.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191205031523.11593-1-ce3g8jdj@umail.furryterror.org> References: <20191205031523.11593-1-ce3g8jdj@umail.furryterror.org> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Allow user to specify start (-s) and end (-e) position directly during btrfs scrub start, by giving device offsets on the command line. This allows scrubs to be targeted toward specific areas of disk. These options may be used with either device names or mounted filesystem paths, though it is probably more useful with the former. The intended use case is to verify that data areas identified in previous scrubs as being unreadable or containing uncorrectable errors have since been remapped or removed, without having to rescan entire disks. Note that some of the printed statistics (ETA, totals) will be significantly inaccurate if these options are used. Signed-off-by: Zygo Blaxell --- Documentation/btrfs-scrub.asciidoc | 6 +++++- cmds/scrub.c | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Documentation/btrfs-scrub.asciidoc b/Documentation/btrfs-scrub.asciidoc index 03f7f008..467345d6 100644 --- a/Documentation/btrfs-scrub.asciidoc +++ b/Documentation/btrfs-scrub.asciidoc @@ -51,7 +51,7 @@ Does not start a new scrub if the last scrub finished successfully. + see *scrub start*. -*start* [-BdqrRf] [-c -n ] |:: +*start* [-BdqrRf] [-c -n -s -e ] |:: Start a scrub on all devices of the filesystem identified by 'path' or on a single 'device'. If a scrub is already running, the new one fails. + @@ -77,6 +77,10 @@ raw print mode, print full data instead of summary set IO priority class (see `ionice`(1) manpage) -n :::: set IO priority classdata (see `ionice`(1) manpage) +-s :::: +set start position, device physical address (default 0) +-e :::: +set end position, device physical address (default end of disk) -f:::: force starting new scrub even if a scrub is already running, this can useful when scrub status file is damaged and reports a running diff --git a/cmds/scrub.c b/cmds/scrub.c index 9fe59822..e60505e0 100644 --- a/cmds/scrub.c +++ b/cmds/scrub.c @@ -1172,8 +1172,10 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv, DIR *dirstream = NULL; int force = 0; int nothing_to_resume = 0; + u64 start_pos = 0; + u64 end_pos = -1ULL; - while ((c = getopt(argc, argv, "BdqrRc:n:f")) != -1) { + while ((c = getopt(argc, argv, "BdqrRc:n:fs:e:")) != -1) { switch (c) { case 'B': do_background = 0; @@ -1198,6 +1200,12 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv, case 'n': ioprio_classdata = (int)strtol(optarg, NULL, 10); break; + case 's': + start_pos = strtoull(optarg, NULL, 0); + break; + case 'e': + end_pos = strtoull(optarg, NULL, 0); + break; case 'f': force = 1; break; @@ -1319,11 +1327,11 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv, continue; } else { ++n_start; - sp[i].scrub_args.start = 0ll; + sp[i].scrub_args.start = start_pos; sp[i].resumed = NULL; } sp[i].skip = 0; - sp[i].scrub_args.end = (u64)-1ll; + sp[i].scrub_args.end = end_pos; sp[i].scrub_args.flags = readonly ? BTRFS_SCRUB_READONLY : 0; sp[i].ioprio_class = ioprio_class; sp[i].ioprio_classdata = ioprio_classdata; @@ -1599,7 +1607,7 @@ out: } static const char * const cmd_scrub_start_usage[] = { - "btrfs scrub start [-BdqrRf] [-c ioprio_class -n ioprio_classdata] |", + "btrfs scrub start [-BdqrRf] [-c ioprio_class -n ioprio_classdata -s start_pos -e end_pos] |", "Start a new scrub. If a scrub is already running, the new one fails.", "", "-B do not background", @@ -1609,6 +1617,8 @@ static const char * const cmd_scrub_start_usage[] = { "-R raw print mode, print full data instead of summary", "-c set ioprio class (see ionice(1) manpage)", "-n set ioprio classdata (see ionice(1) manpage)", + "-s start scrub at position (default 0)", + "-e end scrub at position (default end of device)", "-f force starting new scrub even if a scrub is already running", " this is useful when scrub stats record file is damaged", NULL