Blame SOURCES/bz1507091-fsck_gfs2_Make_p_n_and_y_conflicting_options.patch

744fcf
commit 1061c4767b1d511a9461cd3bcf2e40239cf77d8a
744fcf
Author: Andrew Price <anprice@redhat.com>
744fcf
Date:   Tue Oct 31 11:19:38 2017 +0000
744fcf
744fcf
    fsck.gfs2: Make -p, -n and -y conflicting options
744fcf
    
744fcf
    Exit with FSCK_USAGE when these options are used in combination. Also
744fcf
    update the man page to make this behaviour explicit with other tweaks
744fcf
    for conciseness. Tests included.
744fcf
    
744fcf
    Resolves: rhbz#1507091
744fcf
    
744fcf
    Signed-off-by: Andrew Price <anprice@redhat.com>
744fcf
744fcf
diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c
744fcf
index cd260ef3..ecdcd0f6 100644
744fcf
--- a/gfs2/fsck/main.c
744fcf
+++ b/gfs2/fsck/main.c
744fcf
@@ -75,6 +75,11 @@ static int read_cmdline(int argc, char **argv, struct gfs2_options *gopts)
744fcf
 		switch(c) {
744fcf
 
744fcf
 		case 'a':
744fcf
+		case 'p':
744fcf
+			if (gopts->yes || gopts->no) {
744fcf
+				fprintf(stderr, _("Options -p/-a, -y and -n may not be used together\n"));
744fcf
+				return FSCK_USAGE;
744fcf
+			}
744fcf
 			preen = 1;
744fcf
 			gopts->yes = 1;
744fcf
 			break;
744fcf
@@ -86,12 +91,12 @@ static int read_cmdline(int argc, char **argv, struct gfs2_options *gopts)
744fcf
 			exit(FSCK_OK);
744fcf
 			break;
744fcf
 		case 'n':
744fcf
+			if (gopts->yes || preen) {
744fcf
+				fprintf(stderr, _("Options -p/-a, -y and -n may not be used together\n"));
744fcf
+				return FSCK_USAGE;
744fcf
+			}
744fcf
 			gopts->no = 1;
744fcf
 			break;
744fcf
-		case 'p':
744fcf
-			preen = 1;
744fcf
-			gopts->yes = 1;
744fcf
-			break;
744fcf
 		case 'q':
744fcf
 			decrease_verbosity();
744fcf
 			break;
744fcf
@@ -103,6 +108,10 @@ static int read_cmdline(int argc, char **argv, struct gfs2_options *gopts)
744fcf
 			exit(FSCK_OK);
744fcf
 			break;
744fcf
 		case 'y':
744fcf
+			if (gopts->no || preen) {
744fcf
+				fprintf(stderr, _("Options -p/-a, -y and -n may not be used together\n"));
744fcf
+				return FSCK_USAGE;
744fcf
+			}
744fcf
 			gopts->yes = 1;
744fcf
 			break;
744fcf
 		case ':':
744fcf
diff --git a/gfs2/man/fsck.gfs2.8 b/gfs2/man/fsck.gfs2.8
744fcf
index 56dcddcd..b2b326fb 100644
744fcf
--- a/gfs2/man/fsck.gfs2.8
744fcf
+++ b/gfs2/man/fsck.gfs2.8
744fcf
@@ -40,7 +40,7 @@ administration.
744fcf
 .SH OPTIONS
744fcf
 .TP
744fcf
 \fB-a\fP
744fcf
-Same as the -p (preen) option.
744fcf
+Same as the \fB-p\fP (preen) option.
744fcf
 .TP
744fcf
 \fB-f\fP
744fcf
 Force checking even if the file system seems clean.
744fcf
@@ -54,29 +54,26 @@ This prints out the proper command line usage syntax.
744fcf
 Quiet.
744fcf
 .TP
744fcf
 \fB-n\fP
744fcf
-No to all questions.
744fcf
-
744fcf
-By specifying this option, fsck.gfs2 will only show the changes that
744fcf
+No to all questions. By specifying this option, fsck.gfs2 will only show the changes that
744fcf
 would be made, but not make any changes to the filesystem.
744fcf
+
744fcf
+This option may not be used with the \fB-y\fP or \fB-p\fP/\fB-a\fP options.
744fcf
 .TP
744fcf
 \fB-p\fP
744fcf
-Preen (same as -a: automatically repair the file system if it is dirty,
744fcf
-and safe to do so, otherwise exit.)
744fcf
+Automatically repair ("preen") the file system if it is dirty and safe to do so,
744fcf
+otherwise exit.
744fcf
+
744fcf
+If the file system has locking protocol \fIlock_nolock\fR, it is considered a
744fcf
+non-shared storage device and it is considered safe.  If the locking protocol
744fcf
+is lock_dlm and \fB-a\fP or \fB-p\fP was specified, the check is considered unsafe as it
744fcf
+cannot be determined whether the device is mounted by other nodes in the cluster.
744fcf
+In this case a warning is given if any damage or dirty journals are found. The
744fcf
+file system should then be unmounted from all nodes in the cluster and
744fcf
+fsck.gfs2 should be run manually without the \fB-a\fP or \fB-p\fP options.
744fcf
 
744fcf
-Note: If the file system has locking protocol lock_nolock, the file system
744fcf
-is considered a non-shared storage device and the fsck is deemed safe.
744fcf
-However, fsck.gfs2 does not know whether it was called automatically
744fcf
-from the init process, due to options in the /etc/fstab file.  Therefore, if
744fcf
-the locking protocol is lock_dlm and -a or -p was specified, fsck.gfs2
744fcf
-cannot determine whether the disk is mounted by other nodes in the cluster.
744fcf
-Therefore, the fsck is deemed to be unsafe and a warning is given
744fcf
-if any damage or dirty journals are found.  In that case, the file system
744fcf
-should be unmounted from all nodes in the cluster and fsck.gfs2 should be
744fcf
-run manually without the -a or -p options.
744fcf
+This option may not be used with the \fB-n\fP or \fB-y\fP options.
744fcf
 .TP
744fcf
 \fB-V\fP
744fcf
-Version.
744fcf
-
744fcf
 Print out the program version information.
744fcf
 .TP
744fcf
 \fB-v\fP
744fcf
@@ -85,7 +82,7 @@ Verbose operation.
744fcf
 Print more information while running.
744fcf
 .TP
744fcf
 \fB-y\fP
744fcf
-Yes to all questions.
744fcf
-
744fcf
-By specifying this option, fsck.gfs2 will not prompt before making
744fcf
+Yes to all questions. By specifying this option, fsck.gfs2 will not prompt before making
744fcf
 changes.
744fcf
+
744fcf
+This option may not be used with the \fB-n\fP or \fB-p\fP/\fB-a\fP options.
744fcf
diff --git a/tests/fsck.at b/tests/fsck.at
744fcf
index b9953fb4..0dfeac33 100644
744fcf
--- a/tests/fsck.at
744fcf
+++ b/tests/fsck.at
744fcf
@@ -1,6 +1,17 @@
744fcf
 AT_TESTED([fsck.gfs2])
744fcf
 AT_BANNER([fsck.gfs2 tests])
744fcf
 
744fcf
+AT_SETUP([Conflicting options])
744fcf
+AT_KEYWORDS(fsck.gfs2 fsck)
744fcf
+# Error code 16 is FSCK_USAGE
744fcf
+AT_CHECK([fsck.gfs2 -y -n $GFS_TGT], 16, [ignore], [ignore])
744fcf
+AT_CHECK([fsck.gfs2 -n -y $GFS_TGT], 16, [ignore], [ignore])
744fcf
+AT_CHECK([fsck.gfs2 -n -p $GFS_TGT], 16, [ignore], [ignore])
744fcf
+AT_CHECK([fsck.gfs2 -p -n $GFS_TGT], 16, [ignore], [ignore])
744fcf
+AT_CHECK([fsck.gfs2 -y -p $GFS_TGT], 16, [ignore], [ignore])
744fcf
+AT_CHECK([fsck.gfs2 -p -y $GFS_TGT], 16, [ignore], [ignore])
744fcf
+AT_CLEANUP
744fcf
+
744fcf
 AT_SETUP([Fix invalid block sizes])
744fcf
 AT_KEYWORDS(fsck.gfs2 fsck)
744fcf
 GFS_LANG_CHECK([mkfs.gfs2 -O -p lock_nolock $GFS_TGT], [set sb { sb_bsize: 0 }])