Skip to contentSkip to conversation

improve xfsinvutil man page and argument processing

PATCH In review Bill Kendall 2 participants 5 messages Dec 21, 2009 – Dec 23, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 improve xfsinvutil man page and argument processing

xfsinvtuil's man page is not clear about which options may be used together. The argument processing was not very complete either. Document and enforce the following:

* -F and -i are mutually exclusive.
* -u and -M are mutually exclusive.
* -m requires -u or -M.
* Date string can only be passed when using -u and -M.
* -n is equivalent to -F. Remove it from the man page, but still support it in case there are scripts out there using it.

Also fix an issue parsing time strings which occur during DST.

---
 invutil/getopt.h      |    2
 invutil/invutil.c     |  143 +++++++++++++++++++++++++-------------------------
 man/man8/xfsinvutil.8 |   78 +++++----------------------
 3 files changed, 89 insertions(+), 134 deletions(-)
invutil/invutil.c +72 -71
Index: xfsdump-kernel.org/invutil/invutil.c
===================================================================
@@ -76,10 +76,23 @@ main(int argc, char *argv[])
 	    debug = BOOL_TRUE;
 	    break;
 	case GETOPT_INTERACTIVE:
+	    if (force) {
+		fprintf( stderr, "%s: may not specify both -%c and -%c\n",
+			 g_programName,
+			 GETOPT_FORCE,
+			 c );
+		usage();
+	    }
 	    interactive_option = BOOL_TRUE;
 	    break;
-	case GETOPT_NONINTERACTIVE:
-	    interactive_option = BOOL_FALSE;
+	case GETOPT_NONINTERACTIVE: /* obsoleted by -F */
+	    if (interactive_option) {
+		fprintf( stderr, "%s: may not specify both -%c and -%c\n",
+			 g_programName,
+			 GETOPT_INTERACTIVE,
+			 c );
+		usage();
+	    }
 	    force = BOOL_TRUE;
 	    break;
 	case GETOPT_UUID:
@@ -90,6 +103,13 @@ main(int argc, char *argv[])
 			 c );
 		usage();
 	    }
+	    if (mntpnt_option) {
+		fprintf( stderr, "%s: may not specify both -%c and -%c\n",
+			 g_programName,
+			 GETOPT_PRUNEMNT,
+			 c );
+		usage();
+	    }
 	    uuid_option = BOOL_TRUE;
 	    uuid_parse(optarg, uuid);
 	    break;
@@ -104,13 +124,6 @@ main(int argc, char *argv[])
 			 c );
 		usage();
 	    }
-	    if (r_mf_label) {
-		fprintf( stderr, "%s: may not specify both -%c and -%c\n",
-			 g_programName,
-			 GETOPT_PRUNEMEDIALABEL,
-			 c );
-		usage();
-	    }
 	    if (uuid_option) {
 		fprintf( stderr, "%s: may not specify both -%c and -%c\n",
 			 g_programName,
@@ -121,6 +134,13 @@ main(int argc, char *argv[])
 	    check_option = BOOL_TRUE;
 	    break;
 	case GETOPT_FORCE:
+	    if (interactive_option) {
+		fprintf( stderr, "%s: may not specify both -%c and -%c\n",
+			 g_programName,
+			 GETOPT_INTERACTIVE,
+			 c );
+		usage();
+	    }
 	    force = BOOL_TRUE;
 	    break;
 	case GETOPT_PRUNEMNT:
@@ -131,17 +151,17 @@ main(int argc, char *argv[])
 			 c );
 		usage();
 	    }
-	    mntpnt_option = BOOL_TRUE;
-	    mntPoint = optarg;
-	    break;
-	case GETOPT_PRUNEMEDIALABEL:
-	    if (check_option) {
+	    if (uuid_option) {
 		fprintf( stderr, "%s: may not specify both -%c and -%c\n",
 			 g_programName,
-			 GETOPT_CHECKPRUNEFSTAB,
+			 GETOPT_UUID,
 			 c );
 		usage();
 	    }
+	    mntpnt_option = BOOL_TRUE;
+	    mntPoint = optarg;
+	    break;
+	case GETOPT_PRUNEMEDIALABEL:
 	    r_mf_label = optarg;
 	    break;
 	default:
@@ -150,6 +170,31 @@ main(int argc, char *argv[])
 	}
     }
 
+    if (r_mf_label != NULL && !(mntpnt_option || uuid_option)) {
+	    fprintf( stderr, "%s: -%c requires either -%c or -%c\n",
+			 g_programName,
+			 GETOPT_PRUNEMEDIALABEL,
+			 GETOPT_PRUNEMNT,
+			 GETOPT_UUID );
+	    usage();
+    }
+
+    /* date string only passed for -u and -M */
+    if (uuid_option || mntpnt_option) {
+	    if (optind != (argc - 1)) {
+		    fprintf(stderr, "%s: Date missing for -%c option\n",
+		    	 g_programName,
+			 uuid_option ? GETOPT_UUID : GETOPT_PRUNEMNT);
+		    usage();
+	    }
+    } else {
+	    if (optind != argc) {
+		    fprintf(stderr, "%s: Extra arguments specified\n",
+		    	 g_programName);
+		    usage();
+	    }
+    }
+
     /* sanity check the inventory database directory, setup global paths
      */
     if (!inv_setup_base()) {
@@ -167,16 +212,7 @@ main(int argc, char *argv[])
 		temptime, NULL);
     }
     else if (uuid_option || mntpnt_option) {
-        char *dateStr;
-        time32_t timeSecs;
-
-        if (optind != (argc - 1) ) {
-            fprintf( stderr, "%s: Date missing for prune option\n",
-		     g_programName );
-            usage();
-        }
-        dateStr = argv[optind];
-        timeSecs = ParseDate(dateStr);
+        time32_t timeSecs = ParseDate(argv[optind]);
 
 	if (interactive_option) {
 	    invutil_interactive(inventory_path, mntPoint, &uuid, timeSecs);
@@ -189,18 +225,7 @@ main(int argc, char *argv[])
 	}
     }
     else if ( interactive_option ) {
-        char *dateStr;
-        time32_t timeSecs;
-
-        if (optind != (argc - 1) ) {
-	    timeSecs = 0;
-        }
-	else {
-	    dateStr = argv[optind];
-	    timeSecs = ParseDate(dateStr);
-	}
-
-	invutil_interactive(inventory_path, NULL, NULL, timeSecs);
+	invutil_interactive(inventory_path, mntPoint, &uuid, 0);
 	printf("\n");
     }
     else {
@@ -293,14 +318,15 @@ ParseDate(char *strDate)
 #endif
 
     if (*fmt == NULL || (date = mktime(&tm)) < 0) {
-        fprintf(stderr, "%s: bad date, \"%s\" for -M option\n",
-                g_programName, strDate );
+        fprintf(stderr, "%s: bad date, \"%s\"\n", g_programName, strDate );
         usage();
     }
 
     /* HACK to ensure tm_isdst is set BEFORE calling mktime(3) */
     if (tm.tm_isdst) {
         int dst = tm.tm_isdst;
+	memset (&tm, 0, sizeof (struct tm));
+	tm.tm_isdst = dst;
         (void)strptime(strDate, *fmt, &tm);
         tm.tm_isdst = dst;
         date = mktime(&tm);
@@ -1074,44 +1100,19 @@ mmap_n_bytes(int fd, size_t count, bool_
     return temp;
 }
 
-/* ULO and ULN are taken from dump/common/main.c */
-
-#define ULO( f, o )	fprintf( stderr,		\
-				 "%*s[ -%c " f " ]\n",	\
-				 ps,			\
-				 ns,			\
-				 o ),			\
-			ps = pfxsz
-
-#define ULN( f )	fprintf( stderr,		\
-				 "%*s[ " f " ]\n",	\
-				 ps,			\
-				 ns ),			\
-			ps = pfxsz
-
 void
 usage (void)
 {
     int pfxsz;
-    int ps = 0;
-    char *ns = "";
 
     fprintf(stderr, "%s: %s\n", g_programName, g_programVersion);
-    pfxsz = fprintf(stderr, "Usage: %s ", g_programName);
-
-#ifdef REVEAL
-    ULO( "(output debug information)", GETOPT_DEBUG );
-#endif /* REVEAL */
-    ULO( "(interactive)", GETOPT_INTERACTIVE );
-    ULO( "<uuid> (prune uuid)", GETOPT_UUID );
-#ifdef REVEAL
-    ULO( "(wait for locks)", GETOPT_WAITFORLOCKS );
-#endif /* REVEAL */
-    ULO( "(don't prompt)", GETOPT_FORCE );
-    ULO( "<mountpoint> (prune mountpoint)", GETOPT_PRUNEMNT );
-    ULO( "<medialabel> (prune specific media)", GETOPT_PRUNEMEDIALABEL );
-    ULO( "(check inventory inconsistencies)", GETOPT_CHECKPRUNEFSTAB );
-    ULN( "<mm/dd/yyyy> (date for mountpoint and uuid prune)" );
+    pfxsz = fprintf(stderr, "Usage: \n");
+    fprintf(stderr, "%*s%s [-F|-i] [-m media_label] -M mount_point mm/dd/yyyy\n",
+		    pfxsz, "", g_programName);
+    fprintf(stderr, "%*s%s [-F|-i] [-m media_label] -u UUID mm/dd/yyyy\n",
+		    pfxsz, "", g_programName);
+    fprintf(stderr, "%*s%s -i\n", pfxsz, "", g_programName);
+    fprintf(stderr, "%*s%s -C\n", pfxsz, "", g_programName);
 
     exit(1);
 }
invutil/getopt.h +1 -1
Index: xfsdump-kernel.org/invutil/getopt.h
===================================================================
@@ -22,7 +22,7 @@
 
 #define GETOPT_DEBUG		'd'	/* debug */
 #define GETOPT_INTERACTIVE	'i'	/* interactive mode */
-#define GETOPT_NONINTERACTIVE	'n'	/* non interactive mode (default) */
+#define GETOPT_NONINTERACTIVE	'n'	/* non interactive mode - obsoleted by -F */
 #define GETOPT_UUID		'u'	/* prune uuid */
 #define GETOPT_WAITFORLOCKS	'w'	/* wait for locks */
 #define GETOPT_CHECKPRUNEFSTAB	'C'	/* check and prune fstab */
man/man8/xfsinvutil.8 +16 -62

111 lines not on this page · raw message

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines · Bill Kendall

xfsinvtuil's man page is not clear about which options may be used together. The argument processing was not very complete either. Document and enforce the following:

Looks good,

Reposting to fix whitespace issues introduced by mailer.

---

invutil/invutil.c +72 -71
Index: xfsdump-kernel.org/invutil/invutil.c
===================================================================
@@ -76,10 +76,23 @@ main(int argc, char *argv[])
 	    debug = BOOL_TRUE;
 	    break;
 	case GETOPT_INTERACTIVE:
+	    if (force) {
+		fprintf( stderr, "%s: may not specify both -%c and -%c\n",
+			 g_programName,
+			 GETOPT_FORCE,
+			 c );
+		usage();
+	    }
 	    interactive_option = BOOL_TRUE;
 	    break;
-	case GETOPT_NONINTERACTIVE:
-	    interactive_option = BOOL_FALSE;
+	case GETOPT_NONINTERACTIVE: /* obsoleted by -F */
+	    if (interactive_option) {
+		fprintf( stderr, "%s: may not specify both -%c and -%c\n",
+			 g_programName,
+			 GETOPT_INTERACTIVE,
+			 c );
+		usage();
+	    }
 	    force = BOOL_TRUE;
 	    break;
 	case GETOPT_UUID:
@@ -90,6 +103,13 @@ main(int argc, char *argv[])
 			 c );
 		usage();
 	    }
+	    if (mntpnt_option) {
+		fprintf( stderr, "%s: may not specify both -%c and -%c\n",
+			 g_programName,
+			 GETOPT_PRUNEMNT,
+			 c );
+		usage();
+	    }
 	    uuid_option = BOOL_TRUE;
 	    uuid_parse(optarg, uuid);
 	    break;
@@ -104,13 +124,6 @@ main(int argc, char *argv[])
 			 c );
 		usage();
 	    }
-	    if (r_mf_label) {
-		fprintf( stderr, "%s: may not specify both -%c and -%c\n", 
-			 g_programName,
-			 GETOPT_PRUNEMEDIALABEL,
-			 c );
-		usage();
-	    }
 	    if (uuid_option) {
 		fprintf( stderr, "%s: may not specify both -%c and -%c\n", 
 			 g_programName,
@@ -121,6 +134,13 @@ main(int argc, char *argv[])
 	    check_option = BOOL_TRUE;
 	    break;
 	case GETOPT_FORCE:
+	    if (interactive_option) {
+		fprintf( stderr, "%s: may not specify both -%c and -%c\n",
+			 g_programName,
+			 GETOPT_INTERACTIVE,
+			 c );
+		usage();
+	    }
 	    force = BOOL_TRUE;
 	    break;
 	case GETOPT_PRUNEMNT:
@@ -131,17 +151,17 @@ main(int argc, char *argv[])
 			 c );
 		usage();
 	    }
-	    mntpnt_option = BOOL_TRUE;
-	    mntPoint = optarg;
-	    break;
-	case GETOPT_PRUNEMEDIALABEL:
-	    if (check_option) {
+	    if (uuid_option) {
 		fprintf( stderr, "%s: may not specify both -%c and -%c\n", 
 			 g_programName,
-			 GETOPT_CHECKPRUNEFSTAB,
+			 GETOPT_UUID,
 			 c );
 		usage();
 	    }
+	    mntpnt_option = BOOL_TRUE;
+	    mntPoint = optarg;
+	    break;
+	case GETOPT_PRUNEMEDIALABEL:
 	    r_mf_label = optarg;
 	    break;
 	default:
@@ -150,6 +170,31 @@ main(int argc, char *argv[])
 	}
     }
 
+    if (r_mf_label != NULL && !(mntpnt_option || uuid_option)) {
+	    fprintf( stderr, "%s: -%c requires either -%c or -%c\n",
+			 g_programName,
+			 GETOPT_PRUNEMEDIALABEL,
+			 GETOPT_PRUNEMNT,
+			 GETOPT_UUID );
+	    usage();
+    }
+
+    /* date string only passed for -u and -M */
+    if (uuid_option || mntpnt_option) {
+	    if (optind != (argc - 1)) {
+		    fprintf(stderr, "%s: Date missing for -%c option\n",
+		    	 g_programName,
+			 uuid_option ? GETOPT_UUID : GETOPT_PRUNEMNT);
+		    usage();
+	    }
+    } else {
+	    if (optind != argc) {
+		    fprintf(stderr, "%s: Extra arguments specified\n",
+		    	 g_programName);
+		    usage();
+	    }
+    }
+
     /* sanity check the inventory database directory, setup global paths
      */
     if (!inv_setup_base()) {
@@ -167,16 +212,7 @@ main(int argc, char *argv[])
 		temptime, NULL);
     }
     else if (uuid_option || mntpnt_option) {
-        char *dateStr;
-        time32_t timeSecs;
-
-        if (optind != (argc - 1) ) {
-            fprintf( stderr, "%s: Date missing for prune option\n", 
-		     g_programName );
-            usage();
-        }
-        dateStr = argv[optind];
-        timeSecs = ParseDate(dateStr);
+        time32_t timeSecs = ParseDate(argv[optind]);
 
 	if (interactive_option) {
 	    invutil_interactive(inventory_path, mntPoint, &uuid, timeSecs);
@@ -189,18 +225,7 @@ main(int argc, char *argv[])
 	}
     }
     else if ( interactive_option ) {
-        char *dateStr;
-        time32_t timeSecs;
-
-        if (optind != (argc - 1) ) {
-	    timeSecs = 0;
-        }
-	else {
-	    dateStr = argv[optind];
-	    timeSecs = ParseDate(dateStr);
-	}
-
-	invutil_interactive(inventory_path, NULL, NULL, timeSecs);
+	invutil_interactive(inventory_path, mntPoint, &uuid, 0);
 	printf("\n");
     }
     else {
@@ -293,14 +318,15 @@ ParseDate(char *strDate)
 #endif
 
     if (*fmt == NULL || (date = mktime(&tm)) < 0) {
-        fprintf(stderr, "%s: bad date, \"%s\" for -M option\n",
-                g_programName, strDate );
+        fprintf(stderr, "%s: bad date, \"%s\"\n", g_programName, strDate );
         usage(); 
     }
 
     /* HACK to ensure tm_isdst is set BEFORE calling mktime(3) */ 
     if (tm.tm_isdst) {
         int dst = tm.tm_isdst;
+        memset (&tm, 0, sizeof (struct tm));
+        tm.tm_isdst = dst;
         (void)strptime(strDate, *fmt, &tm); 
         tm.tm_isdst = dst;
         date = mktime(&tm);
@@ -1074,44 +1100,19 @@ mmap_n_bytes(int fd, size_t count, bool_
     return temp;
 }
 
-/* ULO and ULN are taken from dump/common/main.c */
-
-#define ULO( f, o )	fprintf( stderr,		\
-				 "%*s[ -%c " f " ]\n",	\
-				 ps,			\
-				 ns,			\
-				 o ),			\
-			ps = pfxsz
-
-#define ULN( f )	fprintf( stderr,		\
-				 "%*s[ " f " ]\n",	\
-				 ps,			\
-				 ns ),			\
-			ps = pfxsz
-
 void
 usage (void)
 {
     int pfxsz;
-    int ps = 0;
-    char *ns = "";
 
     fprintf(stderr, "%s: %s\n", g_programName, g_programVersion);
-    pfxsz = fprintf(stderr, "Usage: %s ", g_programName);
-
-#ifdef REVEAL
-    ULO( "(output debug information)", GETOPT_DEBUG );
-#endif /* REVEAL */
-    ULO( "(interactive)", GETOPT_INTERACTIVE );
-    ULO( "<uuid> (prune uuid)", GETOPT_UUID );
-#ifdef REVEAL
-    ULO( "(wait for locks)", GETOPT_WAITFORLOCKS );
-#endif /* REVEAL */
-    ULO( "(don't prompt)", GETOPT_FORCE );
-    ULO( "<mountpoint> (prune mountpoint)", GETOPT_PRUNEMNT );
-    ULO( "<medialabel> (prune specific media)", GETOPT_PRUNEMEDIALABEL );
-    ULO( "(check inventory inconsistencies)", GETOPT_CHECKPRUNEFSTAB );
-    ULN( "<mm/dd/yyyy> (date for mountpoint and uuid prune)" );
+    pfxsz = fprintf(stderr, "Usage: \n");
+    fprintf(stderr, "%*s%s [-F|-i] [-m media_label] -M mount_point mm/dd/yyyy\n",
+		    pfxsz, "", g_programName);
+    fprintf(stderr, "%*s%s [-F|-i] [-m media_label] -u UUID mm/dd/yyyy\n",
+		    pfxsz, "", g_programName);
+    fprintf(stderr, "%*s%s -i\n", pfxsz, "", g_programName);
+    fprintf(stderr, "%*s%s -C\n", pfxsz, "", g_programName);
 
     exit(1);
 }
invutil/getopt.h +1 -1
Index: xfsdump-kernel.org/invutil/getopt.h
===================================================================
@@ -22,7 +22,7 @@
 
 #define GETOPT_DEBUG		'd'	/* debug */
 #define GETOPT_INTERACTIVE	'i'	/* interactive mode */
-#define GETOPT_NONINTERACTIVE	'n'	/* non interactive mode (default) */
+#define GETOPT_NONINTERACTIVE	'n'	/* non interactive mode - obsoleted by -F */
 #define GETOPT_UUID		'u'	/* prune uuid */
 #define GETOPT_WAITFORLOCKS	'w'	/* wait for locks */
 #define GETOPT_CHECKPRUNEFSTAB	'C'	/* check and prune fstab */
man/man8/xfsinvutil.8 +16 -62

111 lines not on this page · raw message

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by
#3 lore raw
Quoted 1 line · Bill Kendall

Reposting to fix whitespace issues introduced by mailer.

The patch looks good and applies cleanly now,

Some notes to look into after this patch:

- can you provide a testcase for the problems caused by the wrong time_t usage? A patch to xfstests would be perfect, but if you have a raw testcase I'll vounteer to wire it up.
- why do we wrap both ctime and ctime_r? Currently xfsdump isn't multithreaded so we shouldn't need it. But if the parallel dump/restore ever gets merged from IRIX we need to get rid of the plain ctime calls. (Btw, are there any plans for the parallel dump/restore port?)

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by
#4 lore raw
Quoted 10 lines · Christoph Hellwig

Some notes to look into after this patch:

- can you provide a testcase for the problems caused by the wrong time_t usage? A patch to xfstests would be perfect, but if you have a raw testcase I'll vounteer to wire it up.
- why do we wrap both ctime and ctime_r? Currently xfsdump isn't multithreaded so we shouldn't need it. But if the parallel dump/restore ever gets merged from IRIX we need to get rid of the plain ctime calls. (Btw, are there any plans for the parallel dump/restore port?)

Err, sorry - thos comments were for the time32 patch, but this patch also looks good,

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs