Implement -y "force yes" option for hammer utility.
authorMichael Neumann <mneumann@ntecs.de>
Sun, 14 Jun 2009 16:43:16 +0000 (18:43 +0200)
committerMichael Neumann <mneumann@ntecs.de>
Sun, 14 Jun 2009 16:43:16 +0000 (18:43 +0200)
This fixes a problem with terminals when operating remotely via ssh while
using the auto-PFS creation feature of hammer mirror-stream or
hammer mirror-copy.

For more information see the following thread (off-box mirror-stream and
friends):

http://leaf.dragonflybsd.org/mailarchive/users/2009-02/msg00017.html

sbin/hammer/cmd_mirror.c
sbin/hammer/hammer.8
sbin/hammer/hammer.c
sbin/hammer/hammer.h

index 880eb81..2569297 100644 (file)
@@ -307,13 +307,22 @@ done:
 static void
 create_pfs(const char *filesystem, uuid_t *s_uuid)
 {
-       fprintf(stderr, "PFS slave %s does not exist.\n"
+       if (ForceYesOpt != 0)
+       {
+               fprintf(stderr, "PFS slave %s does not exist. "
+                       "Auto create new slave PFS!\n", filesystem);
+
+       }
+       else
+       {
+               fprintf(stderr, "PFS slave %s does not exist.\n"
                        "Do you want to create a new slave PFS? (yes|no) ",
                        filesystem);
-       fflush(stderr);
-       if (getyn() != 1) {
-               fprintf(stderr, "Aborting operation\n");
-               exit(1);
+               fflush(stderr);
+               if (getyn() != 1) {
+                       fprintf(stderr, "Aborting operation\n");
+                       exit(1);
+               }
        }
 
        u_int32_t status;
@@ -687,6 +696,9 @@ hammer_cmd_mirror_copy(char **av, int ac, int streaming)
                                xav[xac++] = "-vvv";
                                break;
                        }
+                       if (ForceYesOpt) {
+                               xav[xac++] = "-y";
+                       }
                        xav[xac++] = "-2";
                        if (TimeoutOpt) {
                                snprintf(tbuf, sizeof(tbuf), "%d", TimeoutOpt);
@@ -736,7 +748,9 @@ hammer_cmd_mirror_copy(char **av, int ac, int streaming)
                                xav[xac++] = "-vvv";
                                break;
                        }
-
+                       if (ForceYesOpt) {
+                               xav[xac++] = "-y";
+                       }
                        xav[xac++] = "-2";
                        xav[xac++] = "mirror-write";
                        xav[xac++] = ptr;
index e622a13..45efe14 100644 (file)
@@ -121,6 +121,8 @@ option to prune or reblock a portion of the file system incrementally.
 .It Fl v
 Increase verboseness.
 May be specified multiple times.
+.It Fl y
+Force "yes" for any interactive question.
 .El
 .Pp
 The commands are as follows:
index 4935de4..fa127c8 100644 (file)
@@ -50,6 +50,7 @@ int NoSyncOpt;
 int TwoWayPipeOpt;
 int TimeoutOpt;
 int DelayOpt = 5;
+int ForceYesOpt = 0;
 int RunningIoctl;
 int DidInterrupt;
 u_int64_t BandwidthOpt;
@@ -64,11 +65,14 @@ main(int ac, char **av)
        u_int32_t status;
        int ch;
 
-       while ((ch = getopt(ac, av, "b:c:dhf:i:qrs:t:v2")) != -1) {
+       while ((ch = getopt(ac, av, "b:c:dhf:i:qrs:t:v2y")) != -1) {
                switch(ch) {
                case '2':
                        TwoWayPipeOpt = 1;
                        break;
+               case 'y':
+                       ForceYesOpt = 1;
+                       break;
                case 'b':
                        BandwidthOpt = strtoull(optarg, &ptr, 0);
                        switch(*ptr) {
@@ -383,7 +387,7 @@ usage(int exit_code)
 {
        fprintf(stderr, 
                "hammer -h\n"
-               "hammer [-2qrv] [-b bandwidth] [-c cyclefile] [-f blkdev[:blkdev]*]\n"
+               "hammer [-2qrvy] [-b bandwidth] [-c cyclefile] [-f blkdev[:blkdev]*]\n"
                "       [-i delay ] [-t seconds] command [argument ...]\n"
                "hammer synctid <filesystem> [quick]\n"
                "hammer -f blkdev[:blkdev]* blockmap\n"
index 3422319..2b23eb9 100644 (file)
@@ -66,6 +66,7 @@ extern int QuietOpt;
 extern int TwoWayPipeOpt;
 extern int TimeoutOpt;
 extern int DelayOpt;
+extern int ForceYesOpt;
 extern int RunningIoctl;
 extern int DidInterrupt;
 extern u_int64_t BandwidthOpt;