Whamcloud - gitweb
tune2fs: teach tune2fs to use a random value for "-c random"
authorTheodore Ts'o <tytso@mit.edu>
Sun, 14 Feb 2021 15:37:00 +0000 (10:37 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 14 Feb 2021 15:37:00 +0000 (10:37 -0500)
Addresses-Debian-Bug: #926293
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/tune2fs.8.in
misc/tune2fs.c

index 1a181a7..b963f30 100644 (file)
@@ -117,6 +117,9 @@ Adjust the number of mounts after which the filesystem will be checked by
 .BR e2fsck (8).
 If
 .I max-mount-counts
+is the string "random", tune2fs will use a random value between 20 and 40.
+If
+.I max-mount-counts
 is 0 or \-1, the number of times the filesystem is mounted will be disregarded
 by
 .BR e2fsck (8)
@@ -127,21 +130,13 @@ checked will avoid all filesystems being checked at one time
 when using journaled filesystems.
 .sp
 Mount-count-dependent checking is disabled by default to avoid
-unanticipated long reboots while e2fsck does its work.  However,
-you may wish to consider the consequences of disabling
-mount-count-dependent checking entirely.  Bad disk drives, cables,
-memory, and kernel bugs could all corrupt a filesystem without
-marking the filesystem dirty or in error.  If you are using
-journaling on your filesystem, your filesystem will
-.B never
-be marked dirty, so it will not normally be checked.  A
-filesystem error detected by the kernel will still force
-an fsck on the next reboot, but it may already be too late
-to prevent data loss at that point.
-.sp
-See also the
-.B \-i
-option for time-dependent checking.
+unanticipated long reboots while e2fsck does its work.  If you
+are concerned about file system corruptions caused by potential hardware
+problems of kernel bugs, a better solution than mount-count-dependent
+checking is to use the
+.BR e2scrub (8)
+program.  This does require placing the file system on an LVM volume,
+however.
 .TP
 .BI \-C " mount-count"
 Set the number of times the filesystem has been mounted.
index 11715ba..f739f16 100644 (file)
@@ -1826,8 +1826,15 @@ static void parse_tune2fs_options(int argc, char **argv)
        while ((c = getopt(argc, argv, optstring)) != EOF)
                switch (c) {
                case 'c':
+                       open_flag = EXT2_FLAG_RW;
+                       c_flag = 1;
+                       if (strcmp(optarg, "random") == 0) {
+                               max_mount_count = 65536;
+                               break;
+                       }
                        max_mount_count = strtol(optarg, &tmp, 0);
-                       if (*tmp || max_mount_count > 16000) {
+                       if (*tmp || max_mount_count > 16000 ||
+                           max_mount_count < -16000) {
                                com_err(program_name, 0,
                                        _("bad mounts count - %s"),
                                        optarg);
@@ -1835,8 +1842,6 @@ static void parse_tune2fs_options(int argc, char **argv)
                        }
                        if (max_mount_count == 0)
                                max_mount_count = -1;
-                       c_flag = 1;
-                       open_flag = EXT2_FLAG_RW;
                        break;
                case 'C':
                        mount_count = strtoul(optarg, &tmp, 0);
@@ -3104,6 +3109,9 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
        fs->flags |= EXT2_FLAG_SUPER_ONLY;
 
        if (c_flag) {
+               if (max_mount_count == 65536)
+                       max_mount_count = EXT2_DFL_MAX_MNT_COUNT +
+                               (random() % EXT2_DFL_MAX_MNT_COUNT);
                sb->s_max_mnt_count = max_mount_count;
                ext2fs_mark_super_dirty(fs);
                printf(_("Setting maximal mount count to %d\n"),