Duh! forgot this bit of the NCCD patch.

Submitted by:	sobomax
Reviewed by:	phk
This commit is contained in:
Poul-Henning Kamp 2001-09-04 09:19:48 +00:00
parent 772d958c9f
commit ae919cce4a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=82943
3 changed files with 84 additions and 153 deletions

View File

@ -3,9 +3,4 @@
PROG= ccdconfig PROG= ccdconfig
MAN= ccdconfig.8 MAN= ccdconfig.8
LDADD+= -lkvm
DPADD+= ${LIBKVM}
BINGRP= kmem
BINMODE= 2555
.include <bsd.prog.mk> .include <bsd.prog.mk>

View File

@ -61,8 +61,6 @@
.Op Fl f Ar config_file .Op Fl f Ar config_file
.Nm .Nm
.Fl g .Fl g
.Op Fl M Ar core
.Op Fl N Ar system
.Op Ar ccd Op Ar ... .Op Ar ccd Op Ar ...
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm Ccdconfig .Nm Ccdconfig
@ -86,16 +84,6 @@ instead of the default
Dump the current ccd configuration in a format suitable for use as the Dump the current ccd configuration in a format suitable for use as the
ccd configuration file. If no arguments are specified, every configured ccd configuration file. If no arguments are specified, every configured
ccd is dumped. Otherwise, the configuration of each listed ccd is dumped. ccd is dumped. Otherwise, the configuration of each listed ccd is dumped.
.It Fl M Ar core
Extract values associated with the name list from
.Pa core
instead of the default
.Pa /dev/mem .
.It Fl N Ar system
Use
.Ar system
as the kernel instead of the running kernel (as determined from
.Xr getbootfile 3 ) .
.It Fl u .It Fl u
Unconfigure a ccd. Unconfigure a ccd.
.It Fl U .It Fl U

View File

@ -46,7 +46,6 @@ static const char rcsid[] =
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <kvm.h>
#include <limits.h> #include <limits.h>
#include <paths.h> #include <paths.h>
#include <stdio.h> #include <stdio.h>
@ -63,9 +62,6 @@ static int lineno = 0;
static int verbose = 0; static int verbose = 0;
static char *ccdconf = _PATH_CCDCONF; static char *ccdconf = _PATH_CCDCONF;
static char *core = NULL;
static char *kernel = NULL;
struct flagval { struct flagval {
char *fv_flag; char *fv_flag;
int fv_val; int fv_val;
@ -77,14 +73,6 @@ struct flagval {
{ NULL, 0 }, { NULL, 0 },
}; };
static struct nlist nl[] = {
{ "_ccd_softc" },
#define SYM_CCDSOFTC 0
{ "_numccd" },
#define SYM_NUMCCD 1
{ NULL },
};
#define CCD_CONFIG 0 /* configure a device */ #define CCD_CONFIG 0 /* configure a device */
#define CCD_CONFIGALL 1 /* configure all devices */ #define CCD_CONFIGALL 1 /* configure all devices */
#define CCD_UNCONFIG 2 /* unconfigure a device */ #define CCD_UNCONFIG 2 /* unconfigure a device */
@ -99,7 +87,7 @@ static int dump_ccd __P((int, char **));
static int getmaxpartitions __P((void)); static int getmaxpartitions __P((void));
static int getrawpartition __P((void)); static int getrawpartition __P((void));
static int flags_to_val __P((char *)); static int flags_to_val __P((char *));
static void print_ccd_info __P((struct ccd_softc *, kvm_t *)); static void print_ccd_info __P((struct ccd_s *));
static char *resolve_ccdname __P((char *)); static char *resolve_ccdname __P((char *));
static void usage __P((void)); static void usage __P((void));
@ -130,14 +118,6 @@ main(argc, argv)
action = CCD_DUMP; action = CCD_DUMP;
break; break;
case 'M':
core = optarg;
break;
case 'N':
kernel = optarg;
break;
case 'u': case 'u':
action = CCD_UNCONFIG; action = CCD_UNCONFIG;
++options; ++options;
@ -162,15 +142,6 @@ main(argc, argv)
if (options > 1) if (options > 1)
usage(); usage();
/*
* Discard setgid privileges if not the running kernel so that bad
* guys can't print interesting stuff from kernel memory.
*/
if (core != NULL || kernel != NULL || action != CCD_DUMP) {
setegid(getgid());
setgid(getgid());
}
if (modfind("ccd") < 0) { if (modfind("ccd") < 0) {
/* Not present in kernel, try loading it */ /* Not present in kernel, try loading it */
if (kldload("ccd") < 0 || modfind("ccd") < 0) if (kldload("ccd") < 0 || modfind("ccd") < 0)
@ -476,6 +447,14 @@ do_io(path, cmd, cciop)
cp = "CCDIOCCLR"; cp = "CCDIOCCLR";
break; break;
case CCDCONFINFO:
cp = "CCDCONFINFO";
break;
case CCDCPPINFO:
cp = "CCDCPPINFO";
break;
default: default:
cp = "unknown"; cp = "unknown";
} }
@ -486,78 +465,44 @@ do_io(path, cmd, cciop)
return (0); return (0);
} }
#define KVM_ABORT(kd, str) { \
(void)kvm_close((kd)); \
warnx("%s", (str)); \
warnx("%s", kvm_geterr((kd))); \
return (1); \
}
static int static int
dump_ccd(argc, argv) dump_ccd(argc, argv)
int argc; int argc;
char **argv; char **argv;
{ {
char errbuf[_POSIX2_LINE_MAX], *ccd, *cp; char *ccd, *cp;
struct ccd_softc *cs, *kcs;
size_t readsize;
int i, error, numccd, numconfiged = 0; int i, error, numccd, numconfiged = 0;
kvm_t *kd; struct ccdconf conf;
bzero(errbuf, sizeof(errbuf));
if ((kd = kvm_openfiles(kernel, core, NULL, O_RDONLY,
errbuf)) == NULL) {
warnx("can't open kvm: %s", errbuf);
return (1);
}
setegid(getgid());
setgid(getgid());
if (kvm_nlist(kd, nl))
KVM_ABORT(kd, "ccd-related symbols not available");
/* Check to see how many ccds are currently configured. */
if (kvm_read(kd, nl[SYM_NUMCCD].n_value, (char *)&numccd,
sizeof(numccd)) != sizeof(numccd))
KVM_ABORT(kd, "can't determine number of configured ccds");
if (numccd == 0) {
printf("ccd driver in kernel, but is uninitialized\n");
goto done;
}
/* Allocate space for the configuration data. */
readsize = numccd * sizeof(struct ccd_softc);
if ((cs = malloc(readsize)) == NULL) {
warnx("no memory for configuration data");
goto bad;
}
bzero(cs, readsize);
/* /*
* Read the ccd configuration data from the kernel and dump * Read the ccd configuration data from the kernel and dump
* it to stdout. * it to stdout.
*/ */
if (kvm_read(kd, nl[SYM_CCDSOFTC].n_value, (char *)&kcs, if ((ccd = resolve_ccdname("ccd0")) == NULL) { /* XXX */
sizeof(kcs)) != sizeof(kcs)) { warnx("invalid ccd name: %s", cp);
free(cs); return (1);
KVM_ABORT(kd, "can't find pointer to configuration data");
} }
if (kvm_read(kd, (u_long)kcs, (char *)cs, readsize) != readsize) { conf.size = 0;
free(cs); if (do_io(ccd, CCDCONFINFO, (struct ccd_ioctl *) &conf))
KVM_ABORT(kd, "can't read configuration data"); return (1);
if (conf.size == 0) {
printf("no concatenated disks configured\n");
return (0);
} }
/* Allocate space for the configuration data. */
conf.buffer = alloca(conf.size);
if (conf.buffer == NULL) {
warnx("no memory for configuration data");
return (1);
}
if (do_io(ccd, CCDCONFINFO, (struct ccd_ioctl *) &conf))
return (1);
numconfiged = conf.size / sizeof(struct ccd_s);
if (argc == 0) { if (argc == 0) {
for (i = 0; i < numccd; ++i) for (i = 0; i < numconfiged; i++)
if (cs[i].sc_flags & CCDF_INITED) { print_ccd_info(&(conf.buffer[i]));
++numconfiged;
print_ccd_info(&cs[i], kd);
}
if (numconfiged == 0)
printf("no concatenated disks configured\n");
} else { } else {
while (argc) { while (argc) {
cp = *argv++; --argc; cp = *argv++; --argc;
@ -565,85 +510,88 @@ dump_ccd(argc, argv)
warnx("invalid ccd name: %s", cp); warnx("invalid ccd name: %s", cp);
continue; continue;
} }
if ((error = pathtounit(ccd, &i)) != 0) { if ((error = pathtounit(ccd, &numccd)) != 0) {
warnx("%s: %s", ccd, strerror(error)); warnx("%s: %s", ccd, strerror(error));
continue; continue;
} }
if (i >= numccd) { error = 1;
warnx("ccd%d not configured", i); for (i = 0; i < numconfiged; i++) {
if (conf.buffer[i].sc_unit == numccd) {
print_ccd_info(&(conf.buffer[i]));
error = 0;
break;
}
}
if (error) {
warnx("ccd%d not configured", numccd);
continue; continue;
} }
if (cs[i].sc_flags & CCDF_INITED)
print_ccd_info(&cs[i], kd);
else
printf("ccd%d not configured\n", i);
} }
} }
free(cs);
done:
(void)kvm_close(kd);
return (0); return (0);
bad:
(void)kvm_close(kd);
return (1);
} }
static void static void
print_ccd_info(cs, kd) print_ccd_info(cs)
struct ccd_softc *cs; struct ccd_s *cs;
kvm_t *kd;
{ {
char *cp, *ccd;
static int header_printed = 0; static int header_printed = 0;
struct ccdcinfo *cip; struct ccdcpps cpps;
size_t readsize;
char path[MAXPATHLEN];
int i;
/* Print out header if necessary*/
if (header_printed == 0 && verbose) { if (header_printed == 0 && verbose) {
printf("# ccd\t\tileave\tflags\tcompnent devices\n"); printf("# ccd\t\tileave\tflags\tcompnent devices\n");
header_printed = 1; header_printed = 1;
} }
readsize = cs->sc_nccdisks * sizeof(struct ccdcinfo);
if ((cip = malloc(readsize)) == NULL) {
warn("ccd%d: can't allocate memory for component info",
cs->sc_unit);
return;
}
bzero(cip, readsize);
/* Dump out softc information. */ /* Dump out softc information. */
printf("ccd%d\t\t%d\t%d\t", cs->sc_unit, cs->sc_ileave, printf("ccd%d\t\t%d\t%d\t", cs->sc_unit, cs->sc_ileave,
cs->sc_cflags & CCDF_USERMASK); cs->sc_cflags & CCDF_USERMASK);
fflush(stdout); fflush(stdout);
/* Read in the component info. */ /* Read in the component info. */
if (kvm_read(kd, (u_long)cs->sc_cinfo, (char *)cip, asprintf(&cp, "%s%d", cs->device_stats.device_name,
readsize) != readsize) { cs->device_stats.unit_number);
if (cp == NULL) {
printf("\n");
warn("ccd%d: can't allocate memory",
cs->sc_unit);
return;
}
if ((ccd = resolve_ccdname(cp)) == NULL) {
printf("\n");
warnx("can't read component info: invalid ccd name: %s", cp);
return;
}
cpps.size = 0;
if (do_io(ccd, CCDCPPINFO, (struct ccd_ioctl *) &cpps)) {
printf("\n"); printf("\n");
warnx("can't read component info"); warnx("can't read component info");
warnx("%s", kvm_geterr(kd)); return;
goto done; }
cpps.buffer = alloca(cpps.size);
if (cpps.buffer == NULL) {
printf("\n");
warn("ccd%d: can't allocate memory for component info",
cs->sc_unit);
return;
}
if (do_io(ccd, CCDCPPINFO, (struct ccd_ioctl *) &cpps)) {
printf("\n");
warnx("can't read component info");
return;
} }
/* Read component pathname and display component info. */ /* Display component info. */
for (i = 0; i < cs->sc_nccdisks; ++i) { for (cp = cpps.buffer; cp - cpps.buffer < cpps.size; cp += strlen(cp) + 1) {
if (kvm_read(kd, (u_long)cip[i].ci_path, (char *)path, printf((cp + strlen(cp) + 1) < (cpps.buffer + cpps.size) ?
cip[i].ci_pathlen) != cip[i].ci_pathlen) { "%s " : "%s\n", cp);
printf("\n");
warnx("can't read component pathname");
warnx("%s", kvm_geterr(kd));
goto done;
}
printf((i + 1 < cs->sc_nccdisks) ? "%s " : "%s\n", path);
fflush(stdout); fflush(stdout);
} }
return;
done:
free(cip);
} }
static int static int
@ -725,7 +673,7 @@ usage()
" ccdconfig -C [-v] [-f config_file]", " ccdconfig -C [-v] [-f config_file]",
" ccdconfig -u [-v] ccd [...]", " ccdconfig -u [-v] ccd [...]",
" ccdconfig -U [-v] [-f config_file]", " ccdconfig -U [-v] [-f config_file]",
" ccdconfig -g [-M core] [-N system] [ccd [...]]"); " ccdconfig -g [ccd [...]]");
exit(1); exit(1);
} }