Source-Changes-HG archive

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

[src/netbsd-8]: src/sbin/raidctl Pull up following revision(s) (requested by ...



details:   https://anonhg.NetBSD.org/src/rev/ff785cf5f68a
branches:  netbsd-8
changeset: 435257:ff785cf5f68a
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Sep 10 17:56:00 2018 +0000

description:
Pull up following revision(s) (requested by nakayama in ticket #1019):

        sbin/raidctl/rf_configure.h: revision 1.2
        sbin/raidctl/rf_configure.c: revision 1.27
        sbin/raidctl/rf_configure.c: revision 1.28
        sbin/raidctl/rf_configure.c: revision 1.29
        sbin/raidctl/raidctl.8: revision 1.73
        sbin/raidctl/rf_configure.c: revision 1.30
        sbin/raidctl/rf_configure.c: revision 1.31
        sbin/raidctl/rf_configure.c: revision 1.32

support NAME=<wedge name> syntax for disks and spares

 -

stop using magic constants
wrap long lines
use warn{,x}
make static
knf

 -

White space and comment formatting.   NFC.

 -

With char bug[SIZE]  using sizeof(bug[0]) is kind of boring, use
sizeof(bug) instead...

 -

Avoid needless pointer calisthenics: &foo[0] -> foo

 -

Several more cleanups:
1. Don't force use of "for" when "while" works better.
2. No need to check c != '\0' when we also check (c == ' ' || c == '\t')
3. Use the size of the buffer we're using, rather than a different one
   (not really a concern, they're the same size)
4. Don't use fscanf() to read file data, use fgets() & sscanf().
5. After using a pointer as a char *, validate alignment before switching
   to int * (can only fail if kernel #define gets set stupidly)   Or #6...
6. Validate sparemap file name isn't too long for assigned space.
7. recognise that strlen() returns size_t - don't shove it into an int.
8. On out of mem, be more clear which allocation failed in warning msg.

ATF tests all pass.   But I don't think they use sparemap files.

diffstat:

 sbin/raidctl/raidctl.8      |    3 +-
 sbin/raidctl/rf_configure.c |  341 +++++++++++++++++++++++++------------------
 sbin/raidctl/rf_configure.h |   12 +-
 3 files changed, 208 insertions(+), 148 deletions(-)

diffs (truncated from 684 to 300 lines):

diff -r 91498cc53e81 -r ff785cf5f68a sbin/raidctl/raidctl.8
--- a/sbin/raidctl/raidctl.8    Mon Sep 10 16:00:09 2018 +0000
+++ b/sbin/raidctl/raidctl.8    Mon Sep 10 17:56:00 2018 +0000
@@ -1,4 +1,4 @@
-.\"     $NetBSD: raidctl.8,v 1.71 2016/01/06 22:57:44 wiz Exp $
+.\"     $NetBSD: raidctl.8,v 1.71.8.1 2018/09/10 17:56:00 martin Exp $
 .\"
 .\" Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -388,6 +388,7 @@
 .Ed
 .Pp
 specifies the three component disks to be used in the RAID device.
+Disk wedges may also be specified with the NAME=<wedge name> syntax.
 If any of the specified drives cannot be found when the RAID device is
 configured, then they will be marked as
 .Sq failed ,
diff -r 91498cc53e81 -r ff785cf5f68a sbin/raidctl/rf_configure.c
--- a/sbin/raidctl/rf_configure.c       Mon Sep 10 16:00:09 2018 +0000
+++ b/sbin/raidctl/rf_configure.c       Mon Sep 10 17:56:00 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_configure.c,v 1.26 2016/03/09 19:53:32 christos Exp $       */
+/*     $NetBSD: rf_configure.c,v 1.26.8.1 2018/09/10 17:56:00 martin Exp $ */
 
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
@@ -49,7 +49,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: rf_configure.c,v 1.26 2016/03/09 19:53:32 christos Exp $");
+__RCSID("$NetBSD: rf_configure.c,v 1.26.8.1 2018/09/10 17:56:00 martin Exp $");
 #endif
 
 
@@ -58,6 +58,7 @@
 #include <errno.h>
 #include <strings.h>
 #include <err.h>
+#include <util.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -65,22 +66,23 @@
 #include <dev/raidframe/raidframeio.h>
 #include "rf_configure.h"
 
-RF_LayoutSW_t *rf_GetLayout(RF_ParityConfig_t parityConfig);
-char   *rf_find_non_white(char *p);
-char   *rf_find_white(char *p);
+static char   *rf_find_non_white(char *, int);
+static char   *rf_find_white(char *);
+static int rf_search_file_for_start_of(const char *, char *, int, FILE *);
+static int rf_get_next_nonblank_line(char *, int, FILE *, const char *);
+
 #define RF_MIN(a,b) (((a) < (b)) ? (a) : (b))
-#define RF_ERRORMSG(s)            printf((s))
-#define RF_ERRORMSG1(s,a)         printf((s),(a))
-#define RF_ERRORMSG2(s,a,b)       printf((s),(a),(b))
 
-int     distSpareYes = 1;
-int     distSpareNo = 0;
+static int     distSpareYes = 1;
+static int     distSpareNo = 0;
 
-/* The mapsw[] table below contains all the various RAID types that might
-be supported by the kernel.  The actual supported types are found
-in sys/dev/raidframe/rf_layout.c. */
+/*
+ * The mapsw[] table below contains all the various RAID types that might
+ * be supported by the kernel.  The actual supported types are found
+ * in sys/dev/raidframe/rf_layout.c.
+ */
 
-static RF_LayoutSW_t mapsw[] = {
+static const RF_LayoutSW_t mapsw[] = {
        /* parity declustering */
        {'T', "Parity declustering",
         rf_MakeLayoutSpecificDeclustered, &distSpareNo},
@@ -114,61 +116,61 @@
        /* end-of-list marker */
        {'\0', NULL, NULL, NULL}
 };
-RF_LayoutSW_t *
+
+static const RF_LayoutSW_t *
 rf_GetLayout(RF_ParityConfig_t parityConfig)
 {
-       RF_LayoutSW_t *p;
+       const RF_LayoutSW_t *p;
 
        /* look up the specific layout */
        for (p = &mapsw[0]; p->parityConfig; p++)
                if (p->parityConfig == parityConfig)
                        break;
        if (!p->parityConfig)
-               return (NULL);
-       return (p);
+               return NULL;
+       return p;
 }
 
-static int rf_search_file_for_start_of(const char *string, char *buf,
-    int len, FILE * fp);
-static int rf_get_next_nonblank_line(char *buf, int len, FILE * fp,
-    const char *errmsg);
-
 /*
  * called from user level to read the configuration file and create
  * a configuration control structure.  This is used in the user-level
  * version of the driver, and in the user-level program that configures
  * the system via ioctl.
  */
-int 
+int
 rf_MakeConfig(char *configname, RF_Config_t *cfgPtr)
 {
        int numscanned, val, r, c, retcode, aa, bb, cc;
-       char buf[256], buf1[256], *cp;
-       RF_LayoutSW_t *lp;
+       char buf[BUFSIZ], buf1[BUFSIZ], *cp;
+       const RF_LayoutSW_t *lp;
        FILE *fp;
 
-       bzero((char *) cfgPtr, sizeof(RF_Config_t));
+       memset(cfgPtr, 0, sizeof(*cfgPtr));
 
        fp = fopen(configname, "r");
        if (!fp) {
-               printf("Can't open config file %s\n", configname);
-               return (-1);
+               warnx("Can't open config file %s", configname);
+               return -1;
        }
        rewind(fp);
-       if (rf_search_file_for_start_of("array", buf, 256, fp)) {
-               printf("Unable to find start of \"array\" params in config file %s\n", configname);
+       if (rf_search_file_for_start_of("array", buf, sizeof(buf), fp)) {
+               warnx("Unable to find start of \"array\" params in config "
+                   "file %s", configname);
                retcode = -1;
                goto out;
        }
-       rf_get_next_nonblank_line(buf, 256, fp, "Config file error (\"array\" section):  unable to get numRow and numCol\n");
+       rf_get_next_nonblank_line(buf, sizeof(buf), fp,
+           "Config file error (\"array\" section):  unable to get numRow "
+           "and numCol");
 
        /*
-         * wackiness with aa, bb, cc to get around size problems on
-         * different platforms
-         */
+        * wackiness with aa, bb, cc to get around size problems on
+        * different platforms
+        */
        numscanned = sscanf(buf, "%d %d %d", &aa, &bb, &cc);
        if (numscanned != 3) {
-               printf("Config file error (\"array\" section):  unable to get numRow, numCol, numSpare\n");
+               warnx("Config file error (\"array\" section): unable to get "
+                   "numRow, numCol, numSpare");
                retcode = -1;
                goto out;
        }
@@ -180,38 +182,42 @@
        for (c = 0; c < RF_MAXDBGV; c++)
                cfgPtr->debugVars[c][0] = '\0';
        rewind(fp);
-       if (!rf_search_file_for_start_of("debug", buf, 256, fp)) {
+       if (!rf_search_file_for_start_of("debug", buf, sizeof(buf), fp)) {
                for (c = 0; c < RF_MAXDBGV; c++) {
-                       if (rf_get_next_nonblank_line(buf, 256, fp, NULL))
+                       if (rf_get_next_nonblank_line(buf, sizeof(buf), fp,
+                           NULL))
                                break;
-                       cp = rf_find_non_white(buf);
-                       if (!strncmp(cp, "START", strlen("START")))
+                       cp = rf_find_non_white(buf, 0);
+                       if (!strncmp(cp, "START", sizeof("START") - 1))
                                break;
-                       (void) strlcpy(&cfgPtr->debugVars[c][0], cp,
+                       (void) strlcpy(cfgPtr->debugVars[c], cp,
                            sizeof(cfgPtr->debugVars[c]));
                }
        }
        rewind(fp);
        strlcpy(cfgPtr->diskQueueType, "fifo", sizeof(cfgPtr->diskQueueType));
        cfgPtr->maxOutstandingDiskReqs = 1;
+
        /* scan the file for the block related to disk queues */
-       if (rf_search_file_for_start_of("queue", buf, 256, fp)) {
-               RF_ERRORMSG2("[No disk queue discipline specified in config file %s.  Using %s.]\n", configname, cfgPtr->diskQueueType);
-       } else {
-               if (rf_get_next_nonblank_line(buf, 256, fp, NULL)) {
-                       RF_ERRORMSG2("[No disk queue discipline specified in config file %s.  Using %s.]\n", configname, cfgPtr->diskQueueType);
-               }
+       if (rf_search_file_for_start_of("queue", buf, sizeof(buf), fp) ||
+           rf_get_next_nonblank_line(buf, sizeof(buf), fp, NULL)) {
+               warnx("[No disk queue discipline specified in config file %s. "
+                   "Using %s.]", configname, cfgPtr->diskQueueType);
        }
 
-       /* the queue specifier line contains two entries: 1st char of first
+       /*
+        * the queue specifier line contains two entries: 1st char of first
         * word specifies queue to be used 2nd word specifies max num reqs
-        * that can be outstanding on the disk itself (typically 1) */
-       if (sscanf(buf, "%255s %d", buf1, &val) != 2) {
-               RF_ERRORMSG1("Can't determine queue type and/or max outstanding reqs from line: %s", buf);
-               RF_ERRORMSG2("Using %s-%d\n", cfgPtr->diskQueueType, cfgPtr->maxOutstandingDiskReqs);
+        * that can be outstanding on the disk itself (typically 1)
+        */
+       if (sscanf(buf, "%s %d", buf1, &val) != 2) {
+               warnx("Can't determine queue type and/or max outstanding "
+                   "reqs from line: %*s", (int)(sizeof(buf) - 1), buf);
+               warnx("Using %s-%d", cfgPtr->diskQueueType,
+                   cfgPtr->maxOutstandingDiskReqs);
        } else {
                char *ch;
-               bcopy(buf1, cfgPtr->diskQueueType,
+               memcpy(cfgPtr->diskQueueType, buf1,
                    RF_MIN(sizeof(cfgPtr->diskQueueType), strlen(buf1) + 1));
                for (ch = buf1; *ch; ch++) {
                        if (*ch == ' ') {
@@ -224,44 +230,75 @@
 
        rewind(fp);
 
-       if (rf_search_file_for_start_of("disks", buf, 256, fp)) {
-               RF_ERRORMSG1("Can't find \"disks\" section in config file %s\n", configname);
+       if (rf_search_file_for_start_of("disks", buf, sizeof(buf), fp)) {
+               warnx("Can't find \"disks\" section in config file %s",
+                   configname);
                retcode = -1;
                goto out;
        }
        for (r = 0; r < cfgPtr->numRow; r++) {
                for (c = 0; c < cfgPtr->numCol; c++) {
+                       char b1[MAXPATHLEN];
+                       const char *b;
+
                        if (rf_get_next_nonblank_line(
-                           &cfgPtr->devnames[r][c][0], 50, fp, NULL)) {
-                               RF_ERRORMSG2("Config file error: unable to get device file for disk at row %d col %d\n", r, c);
+                           buf, sizeof(buf), fp, NULL)) {
+                               warnx("Config file error: unable to get device "
+                                   "file for disk at row %d col %d", r, c);
                                retcode = -1;
                                goto out;
                        }
+
+                       b = getfsspecname(b1, sizeof(b1), buf);
+                       if (b == NULL) {
+                               warnx("Config file error: warning: unable to "
+                                   "get device file for disk at row %d col "
+                                   "%d: %s", r, c, b1);
+                               b = buf;
+                       }
+
+                       strlcpy(cfgPtr->devnames[r][c], b,
+                           sizeof(cfgPtr->devnames[r][c]));
                }
        }
 
        /* "spare" section is optional */
        rewind(fp);
-       if (rf_search_file_for_start_of("spare", buf, 256, fp))
+       if (rf_search_file_for_start_of("spare", buf, sizeof(buf), fp))
                cfgPtr->numSpare = 0;
        for (c = 0; c < cfgPtr->numSpare; c++) {
-               if (rf_get_next_nonblank_line(&cfgPtr->spare_names[c][0],
-                   256, fp, NULL)) {
-                       RF_ERRORMSG1("Config file error: unable to get device file for spare disk %d\n", c);
+               char b1[MAXPATHLEN];
+               const char *b;
+
+               if (rf_get_next_nonblank_line(buf, sizeof(buf), fp, NULL)) {
+                       warnx("Config file error: unable to get device file "
+                           "for spare disk %d", c);
                        retcode = -1;
                        goto out;
                }
+
+               b = getfsspecname(b1, sizeof(b1), buf);
+               if (b == NULL) {
+                       warnx("Config file error: warning: unable to get "
+                           "device file for spare disk %d: %s", c, b);
+                       b = buf;
+               }
+
+               strlcpy(cfgPtr->spare_names[r], b,
+                   sizeof(cfgPtr->spare_names[r]));
        }
 
        /* scan the file for the block related to layout */
        rewind(fp);
-       if (rf_search_file_for_start_of("layout", buf, 256, fp)) {
-               RF_ERRORMSG1("Can't find \"layout\" section in configuration file %s\n", configname);
+       if (rf_search_file_for_start_of("layout", buf, sizeof(buf), fp)) {
+               warnx("Can't find \"layout\" section in configuration file %s",
+                   configname);



Home | Main Index | Thread Index | Old Index