]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: enable users to bump information messages to warnings
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:23:05 +0000 (16:23 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:07 +0000 (17:01 -0700)
Add a -o iwarn option that enables users to specify that informational
messages (such as incomplete scans, or confusing names) should be
treated as warnings.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
man/man8/xfs_scrub.8
scrub/common.c
scrub/xfs_scrub.c
scrub/xfs_scrub.h

index e881ae76acb323d77b6b37add6c83423d2d92c57..404baba696e16c587bf9f1cee013532f736d7dfd 100644 (file)
@@ -85,6 +85,25 @@ Search this file for mounted filesystems instead of /etc/mtab.
 .B \-n
 Only check filesystem metadata.
 Do not repair or optimize anything.
+.HP
+.B \-o
+.I subopt\c
+[\c
+.B =\c
+.IR value ]
+.BR
+Override what the program might conclude about the filesystem
+if left to its own devices.
+.IP
+The
+.IR subopt ions
+supported are:
+.RS 1.0i
+.TP
+.BI iwarn
+Treat informational messages as warnings.
+This will result in a nonzero return code, and a higher logging level.
+.RE
 .TP
 .BI \-T
 Print timing and memory usage information for each phase.
index 283ac84e232469f9a718cb2d36fc7d471efcf115..aca596487113162e596d1271c4e964afb670f41a 100644 (file)
@@ -110,6 +110,8 @@ __str_out(
        /* print strerror or format of choice but not both */
        assert(!(error && format));
 
+       if (level == S_INFO && info_is_warning)
+               level = S_WARN;
        if (level >= S_INFO)
                stream = stdout;
 
index 50565857ddd81aa8c551350e2cc7bd2ebe0ec84a..e49538ca1cdd98f040fb91d13be09aa18d026a6d 100644 (file)
@@ -160,6 +160,9 @@ bool                                is_service;
 /* Set to true if the kernel supports XFS_SCRUB_IFLAG_FORCE_REBUILD */
 bool                           use_force_rebuild;
 
+/* Should we count informational messages as warnings? */
+bool                           info_is_warning;
+
 #define SCRUB_RET_SUCCESS      (0)     /* no problems left behind */
 #define SCRUB_RET_CORRUPT      (1)     /* corruption remains on fs */
 #define SCRUB_RET_UNOPTIMIZED  (2)     /* fs could be optimized */
@@ -604,6 +607,43 @@ report_outcome(
 # define XFS_SCRUB_HAVE_UNICODE        "-"
 #endif
 
+/*
+ * -o: user-supplied override options
+ */
+enum o_opt_nums {
+       IWARN = 0,
+       O_MAX_OPTS,
+};
+
+static char *o_opts[] = {
+       [IWARN]                 = "iwarn",
+       [O_MAX_OPTS]            = NULL,
+};
+
+static void
+parse_o_opts(
+       struct scrub_ctx        *ctx,
+       char                    *p)
+{
+       while (*p != '\0')  {
+               char            *val;
+
+               switch (getsubopt(&p, o_opts, &val))  {
+               case IWARN:
+                       if (val) {
+                               fprintf(stderr,
+ _("iwarn does not take an argument\n"));
+                               usage();
+                       }
+                       info_is_warning = true;
+                       break;
+               default:
+                       usage();
+                       break;
+               }
+       }
+}
+
 int
 main(
        int                     argc,
@@ -637,7 +677,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:nTvxV")) != EOF) {
+       while ((c = getopt(argc, argv, "a:bC:de:km:no:TvxV")) != EOF) {
                switch (c) {
                case 'a':
                        ctx.max_errors = cvt_u64(optarg, 10);
@@ -687,6 +727,9 @@ main(
                case 'n':
                        ctx.mode = SCRUB_MODE_DRY_RUN;
                        break;
+               case 'o':
+                       parse_o_opts(&ctx, optarg);
+                       break;
                case 'T':
                        display_rusage = true;
                        break;
index 34d850d8db36705c4148a798835f2e42d57b3621..1151ee9ff3a2e4d7fd5425ae0c91c72280d9fc84 100644 (file)
@@ -22,6 +22,7 @@ extern bool                   stderr_isatty;
 extern bool                    stdout_isatty;
 extern bool                    is_service;
 extern bool                    use_force_rebuild;
+extern bool                    info_is_warning;
 
 enum scrub_mode {
        SCRUB_MODE_DRY_RUN,