From patchwork Tue Jul 30 01:17:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746156 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F782881E for ; Tue, 30 Jul 2024 01:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302253; cv=none; b=VqPXB7Mj39AE1cPN3N+u9pJm97wt1SBXnJpvJ5L0sXDAdwAQanWskwpU2CYSGrbm8hrcStXkRgQjS9I3jSLU37Yx0uEjq9wf4/Vn8X/01FSXgcmP549jf7y1mhKFhgu5oQutI33W2bAu2w/qSuGiheEFrrY8dN7sqMMw7UnJECw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302253; c=relaxed/simple; bh=5B5eF+TkujdaoJdxutQVCkKp4IWuNS0J04iIKVwzhRo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aBA5M/cFSFMUh8InGn5nB5T5CakcG/Gl9W+7TTwhf3vOuUTMBVZ2un5pBEeX7W2vadLCMr3dbuzne+YNF0IOXuwNA10JTiuJCaqrz3zDv5PYhwP1dZN1x5QMxYlZFXw7l+yKdVI7i4c76JpAk7vQq36QCMeRrTSyYpCG/riye40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h0ALb5Ej; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h0ALb5Ej" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0775CC32786; Tue, 30 Jul 2024 01:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722302253; bh=5B5eF+TkujdaoJdxutQVCkKp4IWuNS0J04iIKVwzhRo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=h0ALb5Ejs1AASK7TqlalKYf/hEr/ZK+lvun0qAQ9+NNp6n2Iy7AyM5VHFKoJFMUxe ff1k7TcwWWomdYPB31iwj+1ncAm0G9qLjtcwgIuKssDadDREG49AVPATmBXoX5R0Kq F9TTCvSCwqLGzYmgZD0zoJPEQhmmXUBwD6DikXR96yQ7dwS7BeRd54ePN4+srq4T3U ILLl4tDPCCu0E6YKQvJbCHaPlhonp1VAyJylY+c4n4Ahx2iWg5R2ISOAdg1VbSMEST npMg6Bvjrb4rV3lJzEbOLDFj91tyw6a5QvqvbJcrO5xLmwwlZy5fR9JCyDPArcg7Bm nRvP5T0WkEiag== Date: Mon, 29 Jul 2024 18:17:32 -0700 Subject: [PATCH 1/6] xfs_scrub_all: fail fast on masked units From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172229850069.1350643.14681171051215463285.stgit@frogsfrogsfrogs> In-Reply-To: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> References: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong If xfs_scrub_all tries to start a masked xfs_scrub@ unit, that's a sign that the system administrator really didn't want us to scrub that filesystem. Instead of retrying pointlessly, just make a note of the failure and move on. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/xfs_scrub_all.in | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in index 5440e51c0..5e2e0446a 100644 --- a/scrub/xfs_scrub_all.in +++ b/scrub/xfs_scrub_all.in @@ -181,6 +181,10 @@ def fibonacci(max_ret): y = z z = x + y +def was_unit_masked(ex): + '''Decide if this dbus exception occurred because we tried to start a masked unit.''' + return ex.get_dbus_name() == "org.freedesktop.systemd1.UnitMasked" + class scrub_service(scrub_control): '''Control object for xfs_scrub systemd service.''' def __init__(self, mnt, scrub_media): @@ -219,6 +223,12 @@ class scrub_service(scrub_control): if debug: print(e) fatal_ex = e + + # If the unit is masked, there's no point in + # retrying any operations on it. + if was_unit_masked(e): + break + time.sleep(i) self.bind() raise fatal_ex @@ -270,6 +280,13 @@ class scrub_service(scrub_control): try: self.__dbusrun(lambda: self.unit.Start('replace')) return self.wait() + except dbus.exceptions.DBusException as e: + # If the unit was masked, the sysadmin doesn't want us + # running it. Pretend that we finished it. + if was_unit_masked(e): + return 32 + print(e, file = sys.stderr) + return -1 except Exception as e: print(e, file = sys.stderr) return -1 @@ -317,6 +334,10 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs): # are running as a systemd service. if 'SERVICE_MODE' in os.environ: ret = run_service(mnt, scrub_media, killfuncs) + if ret == 32: + print("Scrubbing %s disabled by administrator, (err=%d)" % (mnt, ret)) + sys.stdout.flush() + return if ret == 0 or ret == 1: print("Scrubbing %s done, (err=%d)" % (mnt, ret)) sys.stdout.flush() From patchwork Tue Jul 30 01:17:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746157 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16FC2944E for ; Tue, 30 Jul 2024 01:17:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302269; cv=none; b=G3eF96IiVgNBVdt1D4xSxeb/iOyebysXoSwNwz6ZI5qpui6AnHmK7maPmGMoRENqLrneYhP4uuiGjvG6ltSSPFD+Oe4q4KYDNrzZDABM2NdCV7BS+w3vhTQnIpYzci7jk7tpc/eTPC/kT0Yr+qyhGHf1URrJkAsmWCCIrMsBvQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302269; c=relaxed/simple; bh=ZIKmKBHFKAycVsHWnJ7ZX38vm7/9GkgWIXJC6ute17I=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lmT4LdAKIoRm1IwgNbBKvUMQVJ9qutIH+aSPb9kw4kmEHOt5DGtV/bGjoXgXLRIpid8taIoerVmT86lKrE++d4xGyTW0IIXOybw+ovkyoMV5/rwEnKwOryLFtO5sx3Mvon9TJEGjCM3y3M9dw1X9bO0u6z5N889psfdG+cocjMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q4Y7rpjF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Q4Y7rpjF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8E49C4AF0B; Tue, 30 Jul 2024 01:17:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722302268; bh=ZIKmKBHFKAycVsHWnJ7ZX38vm7/9GkgWIXJC6ute17I=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Q4Y7rpjFkTPlO7nhcJ4t/c6CmnU4XiTipiVFRTYkOZEulVS5vy6Bv8GrA8BSo68vo xG3jiOhLljQ51eSTawMH9bi+Lq145MCmmVqIBvH3n5kur2mSX+FGXqW8L6wDIKDb9D DnxQyZikHHCgKCMS1PUemOWqy8e8iKVMwjrabizMJC8iJooOuiOkcnqCLa67Yhwdpa VMsX8aN9xY9XzURGiHn0wKTpJSqzPImwTSoxiaH3K+jDMsP241bhPQp6f+PC8Vl/jg P5zQTEGW3z8wq0GhUjEm+Kly0rJ4a2ddnMxcuW7JinlxtZXpjFqu8NM6diRdF40r71 LTgGJgFzmrrww== Date: Mon, 29 Jul 2024 18:17:48 -0700 Subject: [PATCH 2/6] xfs_scrub: automatic downgrades to dry-run mode in service mode From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172229850085.1350643.9970598031270770152.stgit@frogsfrogsfrogs> In-Reply-To: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> References: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong When service mode is enabled, xfs_scrub is being run within the context of a systemd service. The service description language doesn't have any particularly good constructs for adding in a '-n' argument if the filesystem is readonly, which means that xfs_scrub is passed a path, and needs to switch to dry-run mode on its own if the fs is mounted readonly or the kernel doesn't support repairs. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase1.c | 13 +++++++++++++ scrub/repair.c | 33 +++++++++++++++++++++++++++++++++ scrub/repair.h | 2 ++ 3 files changed, 48 insertions(+) diff --git a/scrub/phase1.c b/scrub/phase1.c index 516d929d6..095c04591 100644 --- a/scrub/phase1.c +++ b/scrub/phase1.c @@ -216,6 +216,19 @@ _("Kernel metadata scrubbing facility is not available.")); return ECANCELED; } + /* + * Normally, callers are required to pass -n if the provided path is a + * readonly filesystem or the kernel wasn't built with online repair + * enabled. However, systemd services are not scripts and cannot + * determine either of these conditions programmatically. Change the + * behavior to dry-run mode if either condition is detected. + */ + if (repair_want_service_downgrade(ctx)) { + str_info(ctx, ctx->mntpoint, +_("Filesystem cannot be repaired in service mode, downgrading to dry-run mode.")); + ctx->mode = SCRUB_MODE_DRY_RUN; + } + /* Do we need kernel-assisted metadata repair? */ if (ctx->mode != SCRUB_MODE_DRY_RUN && !can_repair(ctx)) { str_error(ctx, ctx->mntpoint, diff --git a/scrub/repair.c b/scrub/repair.c index 19f5c9052..2883f98af 100644 --- a/scrub/repair.c +++ b/scrub/repair.c @@ -45,6 +45,39 @@ static const unsigned int repair_deps[XFS_SCRUB_TYPE_NR] = { }; #undef DEP +/* + * Decide if we want an automatic downgrade to dry-run mode. This is only + * for service mode, where we are fed a path and have to figure out if the fs + * is repairable or not. + */ +bool +repair_want_service_downgrade( + struct scrub_ctx *ctx) +{ + struct xfs_scrub_metadata meta = { + .sm_type = XFS_SCRUB_TYPE_PROBE, + .sm_flags = XFS_SCRUB_IFLAG_REPAIR, + }; + int error; + + if (ctx->mode == SCRUB_MODE_DRY_RUN) + return false; + if (!is_service) + return false; + if (debug_tweak_on("XFS_SCRUB_NO_KERNEL")) + return false; + + error = -xfrog_scrub_metadata(&ctx->mnt, &meta); + switch (error) { + case EROFS: + case ENOTRECOVERABLE: + case EOPNOTSUPP: + return true; + } + + return false; +} + /* Repair some metadata. */ static int xfs_repair_metadata( diff --git a/scrub/repair.h b/scrub/repair.h index a685e9037..411a379f6 100644 --- a/scrub/repair.h +++ b/scrub/repair.h @@ -102,4 +102,6 @@ repair_item_completely( return repair_item(ctx, sri, XRM_FINAL_WARNING | XRM_NOPROGRESS); } +bool repair_want_service_downgrade(struct scrub_ctx *ctx); + #endif /* XFS_SCRUB_REPAIR_H_ */ From patchwork Tue Jul 30 01:18:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746158 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7561D8827 for ; Tue, 30 Jul 2024 01:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302284; cv=none; b=cNYuSETdQkZ3FG7ychkmmJTV2ZzDYbb4KouvkGK5dvWeHKN1Gv0qjZ37AwyjNB18z2ma6RorLO8+TDa+pGk9c9RVYIy4jHzz1I5hJ142Ddsumslcy2HYBjcC9yXDrHBMqXkmamo8ovNSRchNwcVuIvT9PQNsgqVHa0YwVKWlMIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302284; c=relaxed/simple; bh=8+Di6C745a9HhuKX6lC5dMuZsJkgDwFz08dtvYHetiY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cjnQ8Q3XP08fQKWCigpzyBMbyrMY8cV+JiVHvaAFe0Sekvj5IJffg5NkF2aQj9IPBzaVDyKIdrHl3alCnZLQ7vyrN78Noy7q2Q9iEcP8CfTcYRovBgGeiaXcPbZBPcnRALI4BBmt9ankiZ4gaEOFbtEMgF5uQd2mzV8kOAgKmGg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Tn7ercWD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Tn7ercWD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A5B0C32786; Tue, 30 Jul 2024 01:18:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722302284; bh=8+Di6C745a9HhuKX6lC5dMuZsJkgDwFz08dtvYHetiY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Tn7ercWDrc7Fwz6mujmmdsZwERVH//jykF2ZqSziMljS1e936XXdj5PNmqRQyF6Xj dMfQWZBzn/vESgcBBlG6adnh1QkzaH1Kpv+in/gKVaijZd3zY2R7KNU03LNTB8zwqM dqRn9TQWVNsDdT63uET9KXNI9w3W5DHaJEZEaxyxrE5i3lZ+WaKfrwFGKlW7FYGw9H Gx3EfBEC4bA/185Hq/uesqo2rRfGFggXRDfvSdd0k3OeBLr13qmi1BnVSY5IeMtve9 I+6SOD8MvmkNkwtzt+cv0uJp5IDJd28dtTVh/lDTi1mg/DrA/YpUZuf3IhMNUxG5qV HHe7zuZIfO7vw== Date: Mon, 29 Jul 2024 18:18:03 -0700 Subject: [PATCH 3/6] xfs_scrub: add an optimization-only mode From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172229850100.1350643.17695303156049884569.stgit@frogsfrogsfrogs> In-Reply-To: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> References: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Add a "preen" mode in which we only optimize filesystem metadata. Repairs will result in early exits. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- man/man8/xfs_scrub.8 | 6 +++++- scrub/Makefile | 2 +- scrub/phase4.c | 6 ++++++ scrub/repair.c | 4 +++- scrub/scrub.c | 4 ++-- scrub/xfs_scrub.c | 21 +++++++++++++++++++-- scrub/xfs_scrub.h | 1 + 7 files changed, 37 insertions(+), 7 deletions(-) diff --git a/man/man8/xfs_scrub.8 b/man/man8/xfs_scrub.8 index 615401127..1fd122f2a 100644 --- a/man/man8/xfs_scrub.8 +++ b/man/man8/xfs_scrub.8 @@ -4,7 +4,7 @@ xfs_scrub \- check and repair the contents of a mounted XFS filesystem .SH SYNOPSIS .B xfs_scrub [ -.B \-abCeMmnTvx +.B \-abCeMmnpTvx ] .I mount-point .br @@ -128,6 +128,10 @@ Treat informational messages as warnings. This will result in a nonzero return code, and a higher logging level. .RE .TP +.B \-p +Only optimize filesystem metadata. +If repairs are required, report them and exit. +.TP .BI \-T Print timing and memory usage information for each phase. .TP diff --git a/scrub/Makefile b/scrub/Makefile index 7e6882450..885b43e99 100644 --- a/scrub/Makefile +++ b/scrub/Makefile @@ -16,7 +16,7 @@ LTCOMMAND = xfs_scrub INSTALL_SCRUB = install-scrub XFS_SCRUB_ALL_PROG = xfs_scrub_all XFS_SCRUB_FAIL_PROG = xfs_scrub_fail -XFS_SCRUB_ARGS = -n +XFS_SCRUB_ARGS = -p XFS_SCRUB_SERVICE_ARGS = -b ifeq ($(HAVE_SYSTEMD),yes) INSTALL_SCRUB += install-systemd diff --git a/scrub/phase4.c b/scrub/phase4.c index 451101811..88cb53aea 100644 --- a/scrub/phase4.c +++ b/scrub/phase4.c @@ -240,6 +240,12 @@ phase4_func( action_list_empty(ctx->file_repair_list)) return 0; + if (ctx->mode == SCRUB_MODE_PREEN && ctx->corruptions_found) { + str_info(ctx, ctx->mntpoint, + _("Corruptions found; will not optimize. Re-run without -p.\n")); + return 0; + } + /* * Check the resource usage counters early. Normally we do this during * phase 7, but some of the cross-referencing requires fairly accurate diff --git a/scrub/repair.c b/scrub/repair.c index 2883f98af..025821072 100644 --- a/scrub/repair.c +++ b/scrub/repair.c @@ -651,7 +651,9 @@ repair_item_class( unsigned int scrub_type; int error = 0; - if (ctx->mode < SCRUB_MODE_REPAIR) + if (ctx->mode == SCRUB_MODE_DRY_RUN) + return 0; + if (ctx->mode == SCRUB_MODE_PREEN && !(repair_mask & SCRUB_ITEM_PREEN)) return 0; /* diff --git a/scrub/scrub.c b/scrub/scrub.c index 2b6b6274e..1b0609e74 100644 --- a/scrub/scrub.c +++ b/scrub/scrub.c @@ -174,7 +174,7 @@ _("Filesystem is shut down, aborting.")); * repair if desired, otherwise complain. */ if (is_corrupt(&meta) || xref_disagrees(&meta)) { - if (ctx->mode < SCRUB_MODE_REPAIR) { + if (ctx->mode != SCRUB_MODE_REPAIR) { /* Dry-run mode, so log an error and forget it. */ str_corrupt(ctx, descr_render(&dsc), _("Repairs are required.")); @@ -192,7 +192,7 @@ _("Repairs are required.")); * otherwise complain. */ if (is_unoptimized(&meta)) { - if (ctx->mode != SCRUB_MODE_REPAIR) { + if (ctx->mode == SCRUB_MODE_DRY_RUN) { /* Dry-run mode, so log an error and forget it. */ if (group != XFROG_SCRUB_GROUP_INODE) { /* AG or FS metadata, always warn. */ diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c index d7cef115d..bb316f73e 100644 --- a/scrub/xfs_scrub.c +++ b/scrub/xfs_scrub.c @@ -183,6 +183,7 @@ usage(void) fprintf(stderr, _(" -k Do not FITRIM the free space.\n")); fprintf(stderr, _(" -m path Path to /etc/mtab.\n")); fprintf(stderr, _(" -n Dry run. Do not modify anything.\n")); + fprintf(stderr, _(" -p Only optimize, do not fix corruptions.\n")); fprintf(stderr, _(" -T Display timing/usage information.\n")); fprintf(stderr, _(" -v Verbose output.\n")); fprintf(stderr, _(" -V Print version.\n")); @@ -463,6 +464,11 @@ run_scrub_phases( sp->descr = _("Repair filesystem."); sp->fn = phase4_func; sp->must_run = true; + } else if (sp->fn == REPAIR_DUMMY_FN && + ctx->mode == SCRUB_MODE_PREEN) { + sp->descr = _("Optimize filesystem."); + sp->fn = phase4_func; + sp->must_run = true; } /* Skip certain phases unless they're turned on. */ @@ -601,7 +607,7 @@ report_outcome( if (ctx->scrub_setup_succeeded && actionable_errors > 0) { char *msg; - if (ctx->mode == SCRUB_MODE_DRY_RUN) + if (ctx->mode != SCRUB_MODE_REPAIR) msg = _("%s: Re-run xfs_scrub without -n.\n"); else msg = _("%s: Unmount and run xfs_repair.\n"); @@ -725,7 +731,7 @@ main( pthread_mutex_init(&ctx.lock, NULL); ctx.mode = SCRUB_MODE_REPAIR; ctx.error_action = ERRORS_CONTINUE; - while ((c = getopt(argc, argv, "a:bC:de:kM:m:no:TvxV")) != EOF) { + while ((c = getopt(argc, argv, "a:bC:de:kM:m:no:pTvxV")) != EOF) { switch (c) { case 'a': ctx.max_errors = cvt_u64(optarg, 10); @@ -776,11 +782,22 @@ main( mtab = optarg; break; case 'n': + if (ctx.mode != SCRUB_MODE_REPAIR) { + fprintf(stderr, _("Cannot use -n with -p.\n")); + usage(); + } ctx.mode = SCRUB_MODE_DRY_RUN; break; case 'o': parse_o_opts(&ctx, optarg); break; + case 'p': + if (ctx.mode != SCRUB_MODE_REPAIR) { + fprintf(stderr, _("Cannot use -p with -n.\n")); + usage(); + } + ctx.mode = SCRUB_MODE_PREEN; + break; case 'T': display_rusage = true; break; diff --git a/scrub/xfs_scrub.h b/scrub/xfs_scrub.h index b0aa9fcc6..4d9a02892 100644 --- a/scrub/xfs_scrub.h +++ b/scrub/xfs_scrub.h @@ -27,6 +27,7 @@ extern bool info_is_warning; enum scrub_mode { SCRUB_MODE_DRY_RUN, + SCRUB_MODE_PREEN, SCRUB_MODE_REPAIR, }; From patchwork Tue Jul 30 01:18:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746159 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DDF7C8D1 for ; Tue, 30 Jul 2024 01:18:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302300; cv=none; b=uNzDv4aFqN20QBKHM5xV+TCRwn41fQ6MWX6QXAHk3cJZhNlEOYsuuQtK1LVUhQD48kXveWKVI+cXegebDLt3qoHYUsOVkueIyqheLC+EYfiddcbkY2zSbUi/vfJ03UA+Ttm/hdd/xiyxAf4UX9EbCFJhPkIAFjcfnrYYvt3mFz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302300; c=relaxed/simple; bh=R1dERec+ClNCpWgNlj5ar7lJx//+tXFcL9PEFt0BBlk=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l/rWVMPqMlZrtNkgKygvyk5Rz/fDgfU4OQI5oV/g0g67xn0+s6KaNKwRUvjsN0dLhZK5+xVw7BPy/8mv1ljW8CwiPQP2aM1EuoXVZ1XdUmAoBVkV9gOqdO6FreatioC+mm8PoOdQn81kIB0A7avOi6++7SSfDYpguEgDI6J6N34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fuQ6hL+M; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fuQ6hL+M" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 002A2C32786; Tue, 30 Jul 2024 01:18:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722302300; bh=R1dERec+ClNCpWgNlj5ar7lJx//+tXFcL9PEFt0BBlk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=fuQ6hL+MQnKZE/IKEacLfexg1GKNmmG/daeNl5XQ4ThFVE9ztVonkGIZjjdbYQiv0 Fq0Oxl265dCyJ+YMGcRDpXEctbZE0HGwEV0qrf7sC95daFqPr+bUnbo7Aj4thMPR/E YTUdCrgPBsXUxOeHEbk/LQ1PW+YMPC5UislL7xrw147c0GRBfE8hbFSsTx1+mHekbn kLuEqBf0XTmYrlA0AaXw8ddPfkxs+WBFbT/XEfowpzJJglhJBNgtFMg6svybLAVWnY zJKir84wbjOz3sayh/8c214vESfw+J0zAxhsOq7/AwRV0Ux9SSkvt5G5mLAGJxPJZl rNWJvYHsja2bQ== Date: Mon, 29 Jul 2024 18:18:19 -0700 Subject: [PATCH 4/6] xfs_repair: check free space requirements before allowing upgrades From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Chandan Babu R , Dave Chinner , Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172229850115.1350643.6076292905911986162.stgit@frogsfrogsfrogs> In-Reply-To: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> References: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Currently, the V5 feature upgrades permitted by xfs_repair do not affect filesystem space usage, so we haven't needed to verify the geometry. However, this will change once we start to allow the sysadmin to add new metadata indexes to existing filesystems. Add all the infrastructure we need to ensure that there's enough space for metadata space reservations and per-AG reservations the next time the filesystem will be mounted. Signed-off-by: Darrick J. Wong Signed-off-by: Chandan Babu R [david: Recompute transaction reservation values; Exit with error if upgrade fails] Signed-off-by: Dave Chinner [djwong: Refuse to upgrade if any part of the fs has < 10% free] Reviewed-by: Christoph Hellwig --- include/libxfs.h | 1 repair/phase2.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) diff --git a/include/libxfs.h b/include/libxfs.h index e760a46d8..bb00b71b1 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -91,6 +91,7 @@ struct iomap; #include "libxfs/buf_mem.h" #include "xfs_btree_mem.h" #include "xfs_parent.h" +#include "xfs_ag_resv.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/repair/phase2.c b/repair/phase2.c index 83f0c539b..3418da523 100644 --- a/repair/phase2.c +++ b/repair/phase2.c @@ -249,6 +249,137 @@ install_new_state( libxfs_trans_init(mp); } +#define GIGABYTES(count, blog) ((uint64_t)(count) << (30 - (blog))) +static inline bool +check_free_space( + struct xfs_mount *mp, + unsigned long long avail, + unsigned long long total) +{ + /* Ok if there's more than 10% free. */ + if (avail >= total / 10) + return true; + + /* Not ok if there's less than 5% free. */ + if (avail < total / 5) + return false; + + /* Let it slide if there's at least 10GB free. */ + return avail > GIGABYTES(10, mp->m_sb.sb_blocklog); +} + +static void +check_fs_free_space( + struct xfs_mount *mp, + const struct check_state *old, + struct xfs_sb *new_sb) +{ + struct xfs_perag *pag; + xfs_agnumber_t agno; + int error; + + /* Make sure we have enough space for per-AG reservations. */ + for_each_perag(mp, agno, pag) { + struct xfs_trans *tp; + struct xfs_agf *agf; + struct xfs_buf *agi_bp, *agf_bp; + unsigned int avail, agblocks; + + /* Put back the old super so that we can read AG headers. */ + restore_old_state(mp, old); + + /* + * Create a dummy transaction so that we can load the AGI and + * AGF buffers in memory with the old fs geometry and pin them + * there while we try to make a per-AG reservation with the new + * geometry. + */ + error = -libxfs_trans_alloc_empty(mp, &tp); + if (error) + do_error( + _("Cannot reserve resources for upgrade check, err=%d.\n"), + error); + + error = -libxfs_ialloc_read_agi(pag, tp, 0, &agi_bp); + if (error) + do_error( + _("Cannot read AGI %u for upgrade check, err=%d.\n"), + pag->pag_agno, error); + + error = -libxfs_alloc_read_agf(pag, tp, 0, &agf_bp); + if (error) + do_error( + _("Cannot read AGF %u for upgrade check, err=%d.\n"), + pag->pag_agno, error); + agf = agf_bp->b_addr; + agblocks = be32_to_cpu(agf->agf_length); + + /* + * Install the new superblock and try to make a per-AG space + * reservation with the new geometry. We pinned the AG header + * buffers to the transaction, so we shouldn't hit any + * corruption errors on account of the new geometry. + */ + install_new_state(mp, new_sb); + + error = -libxfs_ag_resv_init(pag, tp); + if (error == ENOSPC) { + printf( + _("Not enough free space would remain in AG %u for metadata.\n"), + pag->pag_agno); + exit(1); + } + if (error) + do_error( + _("Error %d while checking AG %u space reservation.\n"), + error, pag->pag_agno); + + /* + * Would the post-upgrade filesystem have enough free space in + * this AG after making per-AG reservations? + */ + avail = pag->pagf_freeblks + pag->pagf_flcount; + avail -= pag->pag_meta_resv.ar_reserved; + avail -= pag->pag_rmapbt_resv.ar_asked; + + if (!check_free_space(mp, avail, agblocks)) { + printf( + _("AG %u will be low on space after upgrade.\n"), + pag->pag_agno); + exit(1); + } + libxfs_trans_cancel(tp); + } + + /* + * Would the post-upgrade filesystem have enough free space on the data + * device after making per-AG reservations? + */ + if (!check_free_space(mp, mp->m_sb.sb_fdblocks, mp->m_sb.sb_dblocks)) { + printf(_("Filesystem will be low on space after upgrade.\n")); + exit(1); + } + + /* + * Release the per-AG reservations and mark the per-AG structure as + * uninitialized so that we don't trip over stale cached counters + * after the upgrade/ + */ + for_each_perag(mp, agno, pag) { + libxfs_ag_resv_free(pag); + clear_bit(XFS_AGSTATE_AGF_INIT, &pag->pag_opstate); + clear_bit(XFS_AGSTATE_AGI_INIT, &pag->pag_opstate); + } +} + +static bool +need_check_fs_free_space( + struct xfs_mount *mp, + const struct check_state *old) +{ + return false; +} + /* * Make sure we can actually upgrade this (v5) filesystem without running afoul * of root inode or log size requirements that would prevent us from mounting @@ -291,6 +422,9 @@ install_new_geometry( exit(1); } + if (need_check_fs_free_space(mp, &old)) + check_fs_free_space(mp, &old, new_sb); + /* * Restore the old state to get everything back to a clean state, * upgrade the featureset one more time, and recompute the btree max From patchwork Tue Jul 30 01:18:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746160 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2A13D502 for ; Tue, 30 Jul 2024 01:18:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302315; cv=none; b=bC4gaEQuXaopI1PYCraIlHkPKlVWCV9SNK+1DWsAqRBBgWyy9D99IaZMB2l+IR5oQGXj0M52fvi9oyU7KZFYmK1huHqVkJUe8/OBozt7OiwYiKjARAKjSEqqb/x2wGKNPjwZwi2JbpbPRh+Vj9xVqJey6YTQu79BRBO0IIZpd70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302315; c=relaxed/simple; bh=39WB5NaJM51hDmCFZ/Xm5rsWeDbWi3TJ/3sCJs66TOo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d/MCxcqQBNE6ik/2GSmnAs1xW0lMJfslUcq5gilzHUw5dhZYWzgFCfWWG28/n37M5I2Ofn5FK0kYWBGqdQ+PbU7SEg7O1wbAv845cS5q9KTI1eip/0nOgnKNmCjOScCYLsxHgSbzOUIUeU+1Mwo3HXAk0QVkdD31z1Jf5kJUbG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YvmLbgyY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YvmLbgyY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9F84C32786; Tue, 30 Jul 2024 01:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722302315; bh=39WB5NaJM51hDmCFZ/Xm5rsWeDbWi3TJ/3sCJs66TOo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YvmLbgyYNXYavGxJVlYrZFgN/PhL380N/zcdCPeZJn6jPWOpYlaTSzZI7K+Erzu3D YGirPrVAlDtRbizcwq5a4YGON/6jNRw4xJiXtXB8k36lqywozNFtBpSNetYeu6+ztc 5mOthk6UpqIzdIrGIK/mmnmX+85bocypFwWfN9VCRfwapWW+E9yIHLNe5EdMTIc8QU V8JFsx6jsdHZEHRPAodkZR0lc62wCyURDLiCrKJNk0c+sTIxRISq+FAiQiC+IpEwj/ sUo4txCoLetiN83VarYi9tXqcgBDUHMFFpmS13+WFcXw4V9xXLa2zc6bos7CsC76cA tV7tQWOsDNCDQ== Date: Mon, 29 Jul 2024 18:18:35 -0700 Subject: [PATCH 5/6] xfs_repair: enforce one namespace bit per extended attribute From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172229850130.1350643.14668236146679133676.stgit@frogsfrogsfrogs> In-Reply-To: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> References: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Enforce that all extended attributes have at most one namespace bit. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/libxfs_api_defs.h | 1 + repair/attr_repair.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index cc670d93a..2d858580a 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -36,6 +36,7 @@ #define xfs_ascii_ci_hashname libxfs_ascii_ci_hashname +#define xfs_attr_check_namespace libxfs_attr_check_namespace #define xfs_attr_get libxfs_attr_get #define xfs_attr_leaf_newentsize libxfs_attr_leaf_newentsize #define xfs_attr_namecheck libxfs_attr_namecheck diff --git a/repair/attr_repair.c b/repair/attr_repair.c index 0f2f7a284..a756a40db 100644 --- a/repair/attr_repair.c +++ b/repair/attr_repair.c @@ -291,6 +291,13 @@ process_shortform_attr( } } + if (!libxfs_attr_check_namespace(currententry->flags)) { + do_warn( + _("multiple namespaces for shortform attribute %d in inode %" PRIu64 "\n"), + i, ino); + junkit = 1; + } + /* namecheck checks for null chars in attr names. */ if (!libxfs_attr_namecheck(currententry->flags, currententry->nameval, @@ -641,6 +648,14 @@ process_leaf_attr_block( break; } + if (!libxfs_attr_check_namespace(entry->flags)) { + do_warn( + _("multiple namespaces for attribute entry %d in attr block %u, inode %" PRIu64 "\n"), + i, da_bno, ino); + clearit = 1; + break; + } + if (entry->flags & XFS_ATTR_INCOMPLETE) { /* we are inconsistent state. get rid of us */ do_warn( From patchwork Tue Jul 30 01:18:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746161 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7485D2905 for ; Tue, 30 Jul 2024 01:18:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302331; cv=none; b=HNAzVyzVOUpIEWIlHoTaNOPNFo3gDrnVVrw7FUrHF6fT4ttwQbKrs3yc5802sjMucc6touwEOoRfIUt1RaS75c0E/MAFqV/NM1lP4WStu7A5Kid09zx1yZ14hfSlJzjnpcRVqLsGHUkjNCmU65/uYW8e4nBOB0I3pqr9cEPswHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722302331; c=relaxed/simple; bh=xsXM0gOFimYj6+zqWWOgXD7qd2Ir7CLY7CCBQdD3cUY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gNrOFAB/SJI1sEHg3MG38t61D31X1rEGGy0vUBPvmi/AUWfmudS4aesz4vebece+fBcdoQz7ZM4crKVPCSzvr64aTif6x+p8l5l1tqsFQL5t4tEYrexSsX807EUCIO26GrVv5zuKWopzmMeHQyeuJATl/S4QbfMVgHFvMpkHlW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d/sNnZ6o; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d/sNnZ6o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52452C32786; Tue, 30 Jul 2024 01:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722302331; bh=xsXM0gOFimYj6+zqWWOgXD7qd2Ir7CLY7CCBQdD3cUY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=d/sNnZ6o1HMn6+LlrqOj6GDdEiSHbMy8K+X3GG0i0WTHR5IbHGCWy+aamXouaTyRA kPF9N09vekMo8OELbRniYHeJwc0h9n8YgMl+8rXn5rwv+EZ38rl+vh3ObU4eswNn1z fCQYub6RqvmfXIt4wVDzFOQZVvPDZJeWCl3V7dbXS7ytJAUiAZ1LAFfA3VsOkkunJJ 7H4fUnf+wzQ1+ywA7zfJbCF6WGWwXERRnd0uf69uByR5fjRqjmBnQvslz88E/w+2W2 0BPjRl9tj79ypZBprWoo7pmQr3LWkdnMlhgLLYbJ/xgOpMTzTQ2aGTGFItxgBg1M0M FW3FlN5lIl6lQ== Date: Mon, 29 Jul 2024 18:18:50 -0700 Subject: [PATCH 6/6] xfs_repair: check for unknown flags in attr entries From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <172229850145.1350643.9201433814080449584.stgit@frogsfrogsfrogs> In-Reply-To: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> References: <172229850048.1350643.5520120825070703831.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Explicitly check for unknown bits being set in the shortform and leaf attr entries. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- repair/attr_repair.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/repair/attr_repair.c b/repair/attr_repair.c index a756a40db..37b5852b8 100644 --- a/repair/attr_repair.c +++ b/repair/attr_repair.c @@ -291,6 +291,13 @@ process_shortform_attr( } } + if (currententry->flags & ~XFS_ATTR_ONDISK_MASK) { + do_warn( + _("unknown flags 0x%x in shortform attribute %d in inode %" PRIu64 "\n"), + currententry->flags, i, ino); + junkit = 1; + } + if (!libxfs_attr_check_namespace(currententry->flags)) { do_warn( _("multiple namespaces for shortform attribute %d in inode %" PRIu64 "\n"), @@ -648,6 +655,14 @@ process_leaf_attr_block( break; } + if (entry->flags & ~XFS_ATTR_ONDISK_MASK) { + do_warn( + _("unknown flags 0x%x in attribute entry #%d in attr block %u, inode %" PRIu64 "\n"), + entry->flags, i, da_bno, ino); + clearit = 1; + break; + } + if (!libxfs_attr_check_namespace(entry->flags)) { do_warn( _("multiple namespaces for attribute entry %d in attr block %u, inode %" PRIu64 "\n"),