tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: patch - cgdconfig do_all mode gracefully ignore detached devices



Added explicit flag to preserve semantics of -C
Moved the check lower in the flow to catch finalized device name
(thanks Michael for catching that)
Updated man page to reflect changes
Tested and working as expected

Ok?

Index: cgdconfig.8
===================================================================
RCS file: /cvsroot/src/sbin/cgdconfig/cgdconfig.8,v
retrieving revision 1.44
diff -B -b -u -r1.44 cgdconfig.8
--- cgdconfig.8    29 Dec 2018 18:34:01 -0000    1.44
+++ cgdconfig.8    11 Nov 2019 15:28:18 -0000
@@ -41,7 +41,7 @@
 .Op Ar paramsfile
 .Nm
 .Fl C
-.Op Fl enpv
+.Op Fl enpvj
 .Op Fl f Ar configfile
 .Nm
 .Fl G
@@ -89,6 +89,9 @@
 .Bl -tag -width configfilexxxx
 .It Fl C
 Configure all the devices listed in the cgd configuration file.
+.It Fl j
+When used with -C, gracefully skip cgd device configuration if
+the backing device is detached.
 .It Fl e
 Echo the passphrase.
 .It Fl f Ar configfile
Index: cgdconfig.c
===================================================================
RCS file: /cvsroot/src/sbin/cgdconfig/cgdconfig.c,v
retrieving revision 1.50
diff -B -b -u -r1.50 cgdconfig.c
--- cgdconfig.c    10 Apr 2019 06:11:37 -0000    1.50
+++ cgdconfig.c    11 Nov 2019 15:28:18 -0000
@@ -95,6 +95,11 @@
 #define    PFLAG_STDIN        0x04
 int    pflag = PFLAG_GETPASS;

+/* if jflag is set, do_all configure ignores lines */
+/* with detached backing devices */
+
+int    jflag = 0;
+
 static int    configure(int, char **, struct params *, int);
 static int    configure_stdin(struct params *, int argc, char **);
 static int    generate(struct params *, int, char **, const char *);
@@ -125,6 +130,7 @@
 static int     verify_reenter(struct params *);
 static int     verify_mbr(int);
 static int     verify_gpt(int);
+static int     verify_attached(const char * opath);

 __dead static void     usage(void);

@@ -203,7 +209,7 @@
     p = params_new();
     kg = NULL;

-    while ((ch = getopt(argc, argv, "CGUV:b:ef:gi:k:lno:spuv")) != -1)
+    while ((ch = getopt(argc, argv, "CGUV:b:ef:gi:k:lno:spuvj")) != -1)
         switch (ch) {
         case 'C':
             set_action(&action, ACTION_CONFIGALL);
@@ -232,6 +238,9 @@
                 p = params_combine(p, tp);
             }
             break;
+        case 'j':
+            jflag = 1;
+            break;
         case 'e':
             pflag = PFLAG_GETPASS_ECHO;
             break;
@@ -589,6 +598,18 @@
         return -1;
     }

+    /* if called from do_all, then ignore if device is not attached */
+    if (jflag && (flags == CONFIG_FLAGS_FROMALL)) {
+        ret = verify_attached(dev);
+
+        /* device unattached */
+        if (ret == 0) {
+            VPRINTF(1, ("skipping %s: device is not attached\n", dev));
+            return 0;
+        }
+        /* pass-through success and errors */
+    }
+
     /*
      * loop over configuring the disk and checking to see if it
      * verifies properly.  We open and close the disk device each
@@ -1282,3 +1303,19 @@
     if (setrlimit(RLIMIT_CORE, &rlp) == -1)
         err(EXIT_FAILURE, "Can't disable cores");
 }
+
+static int
+verify_attached(const char * opath)
+{
+    int fd;
+
+    if ((fd = open(opath,O_RDWR)) == -1) {
+        if (errno == ENXIO) {
+            return 0;
+        }
+        return -1;
+    }
+    close(fd);
+
+    return 1;
+}

On Sun, Nov 10, 2019 at 5:43 PM Robert Elz <kre%munnari.oz.au@localhost> wrote:
>
>     Date:        Sun, 10 Nov 2019 10:00:48 -0600
>     From:        Jason High <json.high%gmail.com@localhost>
>     Message-ID:  <CALt+oR=8kdG=2d5=BFtnwOzugpkGAo7pSOah+hC7YRHK8TjaBA%mail.gmail.com@localhost>
>
>   | Ok?
>
> Aside from other issues, this should still be enabled by a new
> flag (whether the new flag causes -C or is used in conjunction
> with -C doesn't matter) - simply doing "cgdconfig -C" should not
> change behaviour - if a device that is needed is not present, then
> cgdconfig should complain, not just skip it.
>
> But "cgdconfig -A" or "cgdconfig -C -I" can skip non-present devices
> (here assuming that -I would be the "ignore cgd's on devices not found"
> and "-A" would mean "-C -I", though adding both -A and -I would be overkill,
> pick one of them - and of course, I don't care which actual option names
> (letters) are used.
>
> kre
>


Home | Main Index | Thread Index | Old Index