Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/raidctl stop using magic constants
details: https://anonhg.NetBSD.org/src/rev/437ae8cae3ce
branches: trunk
changeset: 357654:437ae8cae3ce
user: christos <christos%NetBSD.org@localhost>
date: Mon Nov 20 19:10:45 2017 +0000
description:
stop using magic constants
wrap long lines
use warn{,x}
make static
knf
diffstat:
sbin/raidctl/rf_configure.c | 250 ++++++++++++++++++++++---------------------
sbin/raidctl/rf_configure.h | 12 +-
2 files changed, 134 insertions(+), 128 deletions(-)
diffs (truncated from 557 to 300 lines):
diff -r 64e53ddf05ab -r 437ae8cae3ce sbin/raidctl/rf_configure.c
--- a/sbin/raidctl/rf_configure.c Mon Nov 20 18:37:56 2017 +0000
+++ b/sbin/raidctl/rf_configure.c Mon Nov 20 19:10:45 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rf_configure.c,v 1.27 2017/11/20 18:37:56 kardel Exp $ */
+/* $NetBSD: rf_configure.c,v 1.28 2017/11/20 19:10:45 christos Exp $ */
/*
* Copyright (c) 1995 Carnegie-Mellon University.
@@ -49,7 +49,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: rf_configure.c,v 1.27 2017/11/20 18:37:56 kardel Exp $");
+__RCSID("$NetBSD: rf_configure.c,v 1.28 2017/11/20 19:10:45 christos Exp $");
#endif
@@ -66,23 +66,21 @@
#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))
-#define RF_ERRORMSG3(s,a,b,c) printf((s),(a),(b),(c))
-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. */
-static RF_LayoutSW_t mapsw[] = {
+static const RF_LayoutSW_t mapsw[] = {
/* parity declustering */
{'T', "Parity declustering",
rf_MakeLayoutSpecificDeclustered, &distSpareNo},
@@ -116,25 +114,21 @@
/* 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
@@ -145,24 +139,27 @@
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
@@ -170,7 +167,8 @@
*/
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;
}
@@ -182,12 +180,13 @@
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,
sizeof(cfgPtr->debugVars[c]));
@@ -197,23 +196,23 @@
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
* 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);
+ 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 == ' ') {
@@ -226,68 +225,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[80];
+ char b1[MAXPATHLEN];
const char *b;
if (rf_get_next_nonblank_line(
buf, sizeof(buf), fp, NULL)) {
- RF_ERRORMSG2("Config file error: unable to get device file for disk at row %d col %d\n", r, c);
+ 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) {
- RF_ERRORMSG3(
- "Config file error: warning: unable to get device file for disk at row %d col %d: %s\n",
- r, c, b1);
+ warnx("Config file error: warning: unable to "
+ "get device file for disk at row %d col "
+ "%d: %s", r, c, b1);
b = buf;
}
- strncpy(&cfgPtr->devnames[r][c][0], b, 50);
+ strlcpy(&cfgPtr->devnames[r][c][0], b,
+ sizeof(cfgPtr->devnames[r][c][0]));
}
}
/* "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++) {
- char b1[80];
+ char b1[MAXPATHLEN];
const char *b;
- if (rf_get_next_nonblank_line(buf,
- sizeof(buf), fp, NULL)) {
- RF_ERRORMSG1("Config file error: unable to get device file for spare disk %d\n", c);
+ 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) {
- RF_ERRORMSG2("Config file error: warning: unable to get device file for spare disk %d: %s\n", c, b);
+ warnx("Config file error: warning: unable to get "
+ "device file for spare disk %d: %s", c, b);
b = buf;
}
- strncpy(&cfgPtr->spare_names[r][0], b, 50);
+ strlcpy(&cfgPtr->spare_names[r][0], b,
+ sizeof(cfgPtr->spare_names[r][0]));
}
/* 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);
retcode = -1;
goto out;
}
- if (rf_get_next_nonblank_line(buf, 256, fp, NULL)) {
- RF_ERRORMSG("Config file error (\"layout\" section): unable to find common layout param line\n");
+ if (rf_get_next_nonblank_line(buf, sizeof(buf), fp, NULL)) {
+ warnx("Config file error (\"layout\" section): unable to find "
+ "common layout param line");
retcode = -1;
goto out;
}
@@ -296,26 +302,27 @@
cfgPtr->SUsPerPU = (RF_StripeNum_t) bb;
cfgPtr->SUsPerRU = (RF_StripeNum_t) cc;
if (c != 4) {
- RF_ERRORMSG("Unable to scan common layout line\n");
+ warnx("Unable to scan common layout line");
retcode = -1;
goto out;
}
lp = rf_GetLayout(cfgPtr->parityConfig);
if (lp == NULL) {
- RF_ERRORMSG1("Unknown parity config '%c'\n",
+ warnx("Unknown parity config '%c'",
cfgPtr->parityConfig);
retcode = -1;
goto out;
}
- retcode = lp->MakeLayoutSpecific(fp, cfgPtr, lp->makeLayoutSpecificArg);
+ retcode = lp->MakeLayoutSpecific(fp, cfgPtr,
+ lp->makeLayoutSpecificArg);
out:
fclose(fp);
if (retcode < 0)
retcode = errno = EINVAL;
else
Home |
Main Index |
Thread Index |
Old Index