Exemplo n.º 1
0
static int
dumpout(int unit)
{
	static int v;
	struct gctl_req *grq;
	int ncp;
	char *cp;
	char const *errstr;

	grq = gctl_get_handle();
	ncp = 65536;
	cp = malloc(ncp);
	gctl_ro_param(grq, "verb", -1, "list");
	gctl_ro_param(grq, "class", -1, "CCD");
	gctl_ro_param(grq, "unit", sizeof(unit), &unit);
	gctl_rw_param(grq, "output", ncp, cp);
	errstr = gctl_issue(grq);
	if (errstr != NULL)
		errx(1, "%s\nor possibly kernel and ccdconfig out of sync",
			errstr);
	if (strlen(cp) == 0)
		errx(1, "ccd%d not configured", unit);
	if (verbose && !v) {
		printf("# ccd\t\tileave\tflags\tcomponent devices\n");
		v = 1;
	}
	printf("%s", cp);
	free(cp);
	return (0);
}
Exemplo n.º 2
0
/*
 * The guts of printconfig.  This is called from gvinum_printconfig and from
 * gvinum_create when called without an argument, in order to give the user
 * something to edit.
 */
void
printconfig(FILE *of, char *comment)
{
	struct gctl_req *req;
	struct utsname uname_s;
	const char *errstr;
	time_t now;
	char buf[GV_CFG_LEN + 1];
	
	uname(&uname_s);
	time(&now);

	req = gctl_get_handle();
	gctl_ro_param(req, "class", -1, "VINUM");
	gctl_ro_param(req, "verb", -1, "getconfig");
	gctl_ro_param(req, "comment", -1, comment);
	gctl_rw_param(req, "config", sizeof(buf), buf);
	errstr = gctl_issue(req);
	if (errstr != NULL) {
		warnx("can't get configuration: %s", errstr);
		return;
	}
	gctl_free(req);

	fprintf(of, "# Vinum configuration of %s, saved at %s",
	    uname_s.nodename,
	    ctime(&now));
	
	if (*comment != '\0')
	    fprintf(of, "# Current configuration:\n");

	fprintf(of, "%s", buf);
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
	struct retval *rv;
	struct gctl_req *req;
	char *param, *value;
	const char *s;
	int c, len;

	req = gctl_get_handle();
	gctl_ro_param(req, "class", -1, "GPT");

	while ((c = getopt(argc, argv, "v")) != -1) {
		switch (c) {
		case 'v':
			verbose = 1;
			break;
		case '?':
		default:
			usage();
			/* NOTREACHED */
			break;
		}
	}

	while (optind < argc) {
		if (!parse(argv[optind++], &param, &value, &len)) {
			if (len > 0) {
				rv = malloc(sizeof(struct retval));
				rv->param = param;
				rv->value = value;
				rv->retval = retval;
				retval = rv;
				gctl_rw_param(req, param, len, value);
			} else
				gctl_ro_param(req, param, -1, value);
		}
	}

	if (verbose)
		gctl_dump(req, stdout);

	s = gctl_issue(req);
	if (s == NULL) {
		printf("PASS");
		while (retval != NULL) {
			rv = retval->retval;
			printf(" %s=%s", retval->param, retval->value);
			free(retval->value);
			free(retval);
			retval = rv;
		}
		printf("\n");
	} else
		printf("FAIL %s\n", s);

	gctl_free(req);
	return (0);
}
Exemplo n.º 4
0
static int
do_single(int argc, char **argv, int action)
{
	char *cp, *cp2;
	int ccd, noflags = 0, i, ileave, flags = 0;
	struct gctl_req *grq;
	char const *errstr;
	char buf1[BUFSIZ];
	int ex;

	/*
	 * If unconfiguring, all arguments are treated as ccds.
	 */
	if (action == CCD_UNCONFIG || action == CCD_UNCONFIGALL) {
		ex = 0;
		for (; argc != 0;) {
			cp = *argv++; --argc;
			if ((ccd = resolve_ccdname(cp)) < 0) {
				warnx("invalid ccd name: %s", cp);
				continue;
			}
			grq = gctl_get_handle();
			gctl_ro_param(grq, "verb", -1, "destroy geom");
			gctl_ro_param(grq, "class", -1, "CCD");
			sprintf(buf1, "ccd%d", ccd);
			gctl_ro_param(grq, "geom", -1, buf1);
			errstr = gctl_issue(grq);
			if (errstr == NULL) {		
				if (verbose)
					printf("%s unconfigured\n", cp);
				gctl_free(grq);
				continue;
			}
			warnx(
			    "%s\nor possibly kernel and ccdconfig out of sync",
			    errstr);
			ex = 1;
		}
		return (ex);
	}

	/* Make sure there are enough arguments. */
	if (argc < 4) {
		if (argc == 3) {
			/* Assume that no flags are specified. */
			noflags = 1;
		} else {
			if (action == CCD_CONFIGALL) {
				warnx("%s: bad line: %d", ccdconf, lineno);
				return (1);
			} else
				usage();
		}
	}

	/* First argument is the ccd to configure. */
	cp = *argv++; --argc;
	if ((ccd = resolve_ccdname(cp)) < 0) {
		warnx("invalid ccd name: %s", cp);
		return (1);
	}

	/* Next argument is the interleave factor. */
	cp = *argv++; --argc;
	errno = 0;	/* to check for ERANGE */
	ileave = (int)strtol(cp, &cp2, 10);
	if ((errno == ERANGE) || (ileave < 0) || (*cp2 != '\0')) {
		warnx("invalid interleave factor: %s", cp);
		return (1);
	}

	if (noflags == 0) {
		/* Next argument is the ccd configuration flags. */
		cp = *argv++; --argc;
		if ((flags = flags_to_val(cp)) < 0) {
			warnx("invalid flags argument: %s", cp);
			return (1);
		}
	}
	grq = gctl_get_handle();
	gctl_ro_param(grq, "verb", -1, "create geom");
	gctl_ro_param(grq, "class", -1, "CCD");
	gctl_ro_param(grq, "unit", sizeof(ccd), &ccd);
	gctl_ro_param(grq, "ileave", sizeof(ileave), &ileave);
	if (flags & CCDF_UNIFORM)
		gctl_ro_param(grq, "uniform", -1, "");
	if (flags & CCDF_MIRROR)
		gctl_ro_param(grq, "mirror", -1, "");
	if (flags & CCDF_NO_OFFSET)
		gctl_ro_param(grq, "no_offset", -1, "");
	if (flags & CCDF_LINUX)
		gctl_ro_param(grq, "linux", -1, "");
	gctl_ro_param(grq, "nprovider", sizeof(argc), &argc);
	for (i = 0; i < argc; i++) {
		sprintf(buf1, "provider%d", i);
		cp = argv[i];
		if (!strncmp(cp, _PATH_DEV, strlen(_PATH_DEV)))
			cp += strlen(_PATH_DEV);
		gctl_ro_param(grq, buf1, -1, cp);
	}
	gctl_rw_param(grq, "output", sizeof(buf1), buf1);
	errstr = gctl_issue(grq);
	if (errstr == NULL) {		
		if (verbose) {
			printf("%s", buf1);
		}
		gctl_free(grq);
		return (0);
	}
	warnx(
	    "%s\nor possibly kernel and ccdconfig out of sync",
	    errstr);
	return (1);
}
Exemplo n.º 5
0
void
gvinum_list(int argc, char **argv)
{
	struct gctl_req *req;
	int flags, i, j;
	const char *errstr;
	char buf[20], *cmd, config[GV_CFG_LEN + 1];

	flags = 0;
	cmd = "list";

	if (argc) {
		optreset = 1;
		optind = 1;
		cmd = argv[0];
		while ((j = getopt(argc, argv, "rsvV")) != -1) {
			switch (j) {
			case 'r':
				flags |= GV_FLAG_R;
				break;
			case 's':
				flags |= GV_FLAG_S;
				break;
			case 'v':
				flags |= GV_FLAG_V;
				break;
			case 'V':
				flags |= GV_FLAG_V;
				flags |= GV_FLAG_VV;
				break;
			case '?':
			default:
				return;
			}
		}
		argc -= optind;
		argv += optind;

	}

	req = gctl_get_handle();
	gctl_ro_param(req, "class", -1, "VINUM");
	gctl_ro_param(req, "verb", -1, "list");
	gctl_ro_param(req, "cmd", -1, cmd);
	gctl_ro_param(req, "argc", sizeof(int), &argc);
	gctl_ro_param(req, "flags", sizeof(int), &flags);
	gctl_rw_param(req, "config", sizeof(config), config);
	if (argc) {
		for (i = 0; i < argc; i++) {
			snprintf(buf, sizeof(buf), "argv%d", i);
			gctl_ro_param(req, buf, -1, argv[i]);
		}
	}
	errstr = gctl_issue(req);
	if (errstr != NULL) {
		warnx("can't get configuration: %s", errstr);
		gctl_free(req);
		return;
	}

	printf("%s", config);
	gctl_free(req);
	return;
}
Exemplo n.º 6
0
/* Find a free name for an object given a a prefix. */
char *
find_name(const char *prefix, int type, int namelen)
{
	struct gctl_req *req;
	char comment[1], buf[GV_CFG_LEN - 1], *name, *sname, *ptr;
	const char *errstr;
	int i, n, begin, len, conflict;
	char line[1024];

	comment[0] = '\0';

	/* Find a name. Fetch out configuration first. */
	req = gctl_get_handle();
	gctl_ro_param(req, "class", -1, "VINUM");
	gctl_ro_param(req, "verb", -1, "getconfig");
	gctl_ro_param(req, "comment", -1, comment);
	gctl_rw_param(req, "config", sizeof(buf), buf);
	errstr = gctl_issue(req);
	if (errstr != NULL) {
		warnx("can't get configuration: %s", errstr);
		return (NULL);
	}
	gctl_free(req);

	begin = 0;
	len = strlen(buf);
	i = 0;
	sname = malloc(namelen + 1);

	/* XXX: Max object setting? */
	for (n = 0; n < 10000; n++) {
		snprintf(sname, namelen, "%s%d", prefix, n);
		conflict = 0;
		begin = 0;
		/* Loop through the configuration line by line. */
		for (i = 0; i < len; i++) {
			if (buf[i] == '\n' || buf[i] == '\0') {
				ptr = buf + begin;
				strlcpy(line, ptr, (i - begin) + 1);
				begin = i + 1;
				switch (type) {
				case GV_TYPE_DRIVE:
					name = find_pattern(line, "drive");
					break;
				case GV_TYPE_VOL:
					name = find_pattern(line, "volume");
					break;
				case GV_TYPE_PLEX:
				case GV_TYPE_SD:
					name = find_pattern(line, "name");
					break;
				default:
					printf("Invalid type given\n");
					continue;
				}
				if (name == NULL)
					continue;
				if (!strcmp(sname, name)) {
					conflict = 1;
					/* XXX: Could quit the loop earlier. */
				}
			}
		}
		if (!conflict)
			return (sname);
	}
	free(sname);
	return (NULL);
}