2002-10-13 20:33:33 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002 Poul-Henning Kamp
|
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by Poul-Henning Kamp
|
|
|
|
* and NAI Labs, the Security Research Division of Network Associates, Inc.
|
|
|
|
* under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
|
|
|
|
* DARPA CHATS research program.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The names of the authors may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 06:49:16 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-10-13 20:33:33 +00:00
|
|
|
#include "opt_geom.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/sysctl.h>
|
2003-04-23 07:50:01 +00:00
|
|
|
#include <sys/sbuf.h>
|
2002-10-13 20:33:33 +00:00
|
|
|
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2003-03-23 10:16:14 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
|
2002-10-13 20:33:33 +00:00
|
|
|
#include <geom/geom.h>
|
|
|
|
#include <geom/geom_int.h>
|
2003-03-27 14:35:00 +00:00
|
|
|
#define GCTL_TABLE 1
|
2003-03-23 10:16:14 +00:00
|
|
|
#include <geom/geom_ctl.h>
|
|
|
|
|
2003-04-23 07:50:01 +00:00
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
2002-10-13 20:33:33 +00:00
|
|
|
static d_ioctl_t g_ctl_ioctl;
|
|
|
|
|
2003-03-24 13:37:15 +00:00
|
|
|
static struct cdevsw g_ctl_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_flags = D_NEEDGIANT,
|
2003-03-24 13:37:15 +00:00
|
|
|
.d_ioctl = g_ctl_ioctl,
|
|
|
|
.d_name = "g_ctl",
|
2002-10-13 20:33:33 +00:00
|
|
|
};
|
|
|
|
|
2003-03-24 13:37:15 +00:00
|
|
|
void
|
2002-10-13 20:33:33 +00:00
|
|
|
g_ctl_init(void)
|
|
|
|
{
|
|
|
|
|
2003-03-24 13:37:15 +00:00
|
|
|
make_dev(&g_ctl_cdevsw, 0,
|
|
|
|
UID_ROOT, GID_OPERATOR, 0640, PATH_GEOM_CTL);
|
2003-03-27 14:35:00 +00:00
|
|
|
KASSERT(GCTL_PARAM_RD == VM_PROT_READ,
|
|
|
|
("GCTL_PARAM_RD != VM_PROT_READ"));
|
|
|
|
KASSERT(GCTL_PARAM_WR == VM_PROT_WRITE,
|
|
|
|
("GCTL_PARAM_WR != VM_PROT_WRITE"));
|
2002-10-13 20:33:33 +00:00
|
|
|
}
|
|
|
|
|
2003-03-23 10:16:14 +00:00
|
|
|
/*
|
|
|
|
* Report an error back to the user in ascii format. Return whatever copyout
|
|
|
|
* returned, or EINVAL if it succeeded.
|
|
|
|
*/
|
2003-03-27 14:35:00 +00:00
|
|
|
int
|
2003-04-23 07:50:01 +00:00
|
|
|
gctl_error(struct gctl_req *req, const char *fmt, ...)
|
2003-03-23 10:16:14 +00:00
|
|
|
{
|
2003-04-23 07:50:01 +00:00
|
|
|
va_list ap;
|
2003-06-01 13:47:51 +00:00
|
|
|
|
|
|
|
if (req == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* We only record the first error */
|
2005-04-08 09:28:08 +00:00
|
|
|
if (sbuf_done(req->serror)) {
|
|
|
|
if (!req->nerror)
|
|
|
|
req->nerror = EEXIST;
|
|
|
|
}
|
2003-06-01 13:47:51 +00:00
|
|
|
if (req->nerror)
|
|
|
|
return (req->nerror);
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
sbuf_vprintf(req->serror, fmt, ap);
|
2003-06-07 10:16:53 +00:00
|
|
|
va_end(ap);
|
2003-06-01 13:47:51 +00:00
|
|
|
sbuf_finish(req->serror);
|
|
|
|
if (g_debugflags & G_F_CTLDUMP)
|
|
|
|
printf("gctl %p error \"%s\"\n", req, sbuf_data(req->serror));
|
2005-04-08 09:28:08 +00:00
|
|
|
return (0);
|
2003-03-23 10:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate space and copyin() something.
|
|
|
|
* XXX: this should really be a standard function in the kernel.
|
|
|
|
*/
|
|
|
|
static void *
|
2003-06-01 13:47:51 +00:00
|
|
|
geom_alloc_copyin(struct gctl_req *req, void *uaddr, size_t len)
|
2003-03-23 10:16:14 +00:00
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
ptr = g_malloc(len, M_WAITOK);
|
|
|
|
if (ptr == NULL)
|
2003-06-01 13:47:51 +00:00
|
|
|
req->nerror = ENOMEM;
|
2003-03-23 10:16:14 +00:00
|
|
|
else
|
2003-06-01 13:47:51 +00:00
|
|
|
req->nerror = copyin(uaddr, ptr, len);
|
|
|
|
if (!req->nerror)
|
2003-03-23 10:16:14 +00:00
|
|
|
return (ptr);
|
|
|
|
if (ptr != NULL)
|
|
|
|
g_free(ptr);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
static void
|
2003-03-27 14:35:00 +00:00
|
|
|
gctl_copyin(struct gctl_req *req)
|
2003-03-23 10:16:14 +00:00
|
|
|
{
|
2003-06-01 13:47:51 +00:00
|
|
|
int error, i;
|
2003-03-27 14:35:00 +00:00
|
|
|
struct gctl_req_arg *ap;
|
2003-03-23 10:16:14 +00:00
|
|
|
char *p;
|
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
ap = geom_alloc_copyin(req, req->arg, req->narg * sizeof(*ap));
|
2003-03-27 14:35:00 +00:00
|
|
|
if (ap == NULL) {
|
2003-06-01 13:47:51 +00:00
|
|
|
req->nerror = ENOMEM;
|
|
|
|
req->arg = NULL;
|
|
|
|
return;
|
2003-03-27 14:35:00 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
/* Nothing have been copyin()'ed yet */
|
|
|
|
for (i = 0; i < req->narg; i++) {
|
|
|
|
ap[i].flag &= ~(GCTL_PARAM_NAMEKERNEL|GCTL_PARAM_VALUEKERNEL);
|
|
|
|
ap[i].flag &= ~GCTL_PARAM_CHANGED;
|
|
|
|
ap[i].kvalue = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
for (i = 0; i < req->narg; i++) {
|
2003-03-27 14:35:00 +00:00
|
|
|
if (ap[i].nlen < 1 || ap[i].nlen > SPECNAMELEN) {
|
2003-06-01 13:47:51 +00:00
|
|
|
error = gctl_error(req,
|
|
|
|
"wrong param name length %d: %d", i, ap[i].nlen);
|
2003-03-23 10:16:14 +00:00
|
|
|
break;
|
2003-03-27 14:35:00 +00:00
|
|
|
}
|
2003-06-01 13:47:51 +00:00
|
|
|
p = geom_alloc_copyin(req, ap[i].name, ap[i].nlen);
|
2003-03-27 14:35:00 +00:00
|
|
|
if (p == NULL)
|
2003-03-23 10:16:14 +00:00
|
|
|
break;
|
2003-03-27 14:35:00 +00:00
|
|
|
if (p[ap[i].nlen - 1] != '\0') {
|
|
|
|
error = gctl_error(req, "unterminated param name");
|
2003-03-23 10:16:14 +00:00
|
|
|
g_free(p);
|
|
|
|
break;
|
|
|
|
}
|
2003-03-27 14:35:00 +00:00
|
|
|
ap[i].name = p;
|
2003-06-01 13:47:51 +00:00
|
|
|
ap[i].flag |= GCTL_PARAM_NAMEKERNEL;
|
2005-01-17 07:14:24 +00:00
|
|
|
if (ap[i].len <= 0) {
|
2003-06-01 13:47:51 +00:00
|
|
|
error = gctl_error(req, "negative param length");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = geom_alloc_copyin(req, ap[i].value, ap[i].len);
|
|
|
|
if (p == NULL)
|
|
|
|
break;
|
|
|
|
if ((ap[i].flag & GCTL_PARAM_ASCII) &&
|
|
|
|
p[ap[i].len - 1] != '\0') {
|
|
|
|
error = gctl_error(req, "unterminated param value");
|
|
|
|
g_free(p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ap[i].kvalue = p;
|
|
|
|
ap[i].flag |= GCTL_PARAM_VALUEKERNEL;
|
2003-03-23 10:16:14 +00:00
|
|
|
}
|
2003-06-01 13:47:51 +00:00
|
|
|
req->arg = ap;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gctl_copyout(struct gctl_req *req)
|
|
|
|
{
|
|
|
|
int error, i;
|
|
|
|
struct gctl_req_arg *ap;
|
|
|
|
|
|
|
|
if (req->nerror)
|
|
|
|
return;
|
|
|
|
error = 0;
|
|
|
|
ap = req->arg;
|
|
|
|
for (i = 0; i < req->narg; i++, ap++) {
|
|
|
|
if (!(ap->flag & GCTL_PARAM_CHANGED))
|
|
|
|
continue;
|
|
|
|
error = copyout(ap->kvalue, ap->value, ap->len);
|
|
|
|
if (!error)
|
|
|
|
continue;
|
|
|
|
req->nerror = error;
|
|
|
|
return;
|
2003-03-23 10:16:14 +00:00
|
|
|
}
|
2003-06-01 13:47:51 +00:00
|
|
|
return;
|
2003-03-23 10:16:14 +00:00
|
|
|
}
|
|
|
|
|
2003-05-02 12:49:41 +00:00
|
|
|
static void
|
|
|
|
gctl_free(struct gctl_req *req)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
if (req->arg == NULL)
|
|
|
|
return;
|
2003-05-02 12:49:41 +00:00
|
|
|
for (i = 0; i < req->narg; i++) {
|
2003-06-01 13:47:51 +00:00
|
|
|
if (req->arg[i].flag & GCTL_PARAM_NAMEKERNEL)
|
2003-05-02 12:49:41 +00:00
|
|
|
g_free(req->arg[i].name);
|
2003-06-01 13:47:51 +00:00
|
|
|
if ((req->arg[i].flag & GCTL_PARAM_VALUEKERNEL) &&
|
|
|
|
req->arg[i].len > 0)
|
|
|
|
g_free(req->arg[i].kvalue);
|
2003-05-02 12:49:41 +00:00
|
|
|
}
|
|
|
|
g_free(req->arg);
|
2003-06-01 13:47:51 +00:00
|
|
|
sbuf_delete(req->serror);
|
2003-05-02 12:49:41 +00:00
|
|
|
}
|
|
|
|
|
2003-03-23 10:16:14 +00:00
|
|
|
static void
|
2003-03-27 14:35:00 +00:00
|
|
|
gctl_dump(struct gctl_req *req)
|
2003-03-23 10:16:14 +00:00
|
|
|
{
|
|
|
|
u_int i;
|
2003-06-01 13:47:51 +00:00
|
|
|
int j;
|
2003-03-27 14:35:00 +00:00
|
|
|
struct gctl_req_arg *ap;
|
2003-03-23 10:16:14 +00:00
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
printf("Dump of gctl request at %p:\n", req);
|
|
|
|
if (req->nerror > 0) {
|
|
|
|
printf(" nerror:\t%d\n", req->nerror);
|
|
|
|
if (sbuf_len(req->serror) > 0)
|
|
|
|
printf(" error:\t\"%s\"\n", sbuf_data(req->serror));
|
2003-03-23 10:16:14 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < req->narg; i++) {
|
|
|
|
ap = &req->arg[i];
|
2003-06-01 13:47:51 +00:00
|
|
|
if (!(ap->flag & GCTL_PARAM_NAMEKERNEL))
|
|
|
|
printf(" param:\t%d@%p", ap->nlen, ap->name);
|
|
|
|
else
|
|
|
|
printf(" param:\t\"%s\"", ap->name);
|
2003-03-27 14:35:00 +00:00
|
|
|
printf(" [%s%s%d] = ",
|
|
|
|
ap->flag & GCTL_PARAM_RD ? "R" : "",
|
|
|
|
ap->flag & GCTL_PARAM_WR ? "W" : "",
|
|
|
|
ap->len);
|
2003-06-01 13:47:51 +00:00
|
|
|
if (!(ap->flag & GCTL_PARAM_VALUEKERNEL)) {
|
|
|
|
printf(" =@ %p", ap->value);
|
|
|
|
} else if (ap->flag & GCTL_PARAM_ASCII) {
|
|
|
|
printf("\"%s\"", (char *)ap->kvalue);
|
2003-03-23 10:16:14 +00:00
|
|
|
} else if (ap->len > 0) {
|
2003-07-02 08:07:07 +00:00
|
|
|
for (j = 0; j < ap->len && j < 512; j++)
|
2003-06-01 13:47:51 +00:00
|
|
|
printf(" %02x", ((u_char *)ap->kvalue)[j]);
|
2003-03-23 10:16:14 +00:00
|
|
|
} else {
|
2003-06-01 13:47:51 +00:00
|
|
|
printf(" = %p", ap->kvalue);
|
2003-03-23 10:16:14 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-07 16:19:48 +00:00
|
|
|
int
|
|
|
|
gctl_set_param(struct gctl_req *req, const char *param, void const *ptr,
|
|
|
|
int len)
|
2003-05-04 19:24:34 +00:00
|
|
|
{
|
2003-06-01 13:47:51 +00:00
|
|
|
int i;
|
2003-05-04 19:24:34 +00:00
|
|
|
struct gctl_req_arg *ap;
|
|
|
|
|
|
|
|
for (i = 0; i < req->narg; i++) {
|
|
|
|
ap = &req->arg[i];
|
|
|
|
if (strcmp(param, ap->name))
|
|
|
|
continue;
|
2006-04-07 16:19:48 +00:00
|
|
|
if (!(ap->flag & GCTL_PARAM_WR))
|
|
|
|
return (EPERM);
|
|
|
|
ap->flag |= GCTL_PARAM_CHANGED;
|
2003-06-01 13:47:51 +00:00
|
|
|
if (ap->len < len) {
|
2006-04-07 16:19:48 +00:00
|
|
|
bcopy(ptr, ap->kvalue, ap->len);
|
|
|
|
return (ENOSPC);
|
2003-05-04 19:24:34 +00:00
|
|
|
}
|
2003-06-01 13:47:51 +00:00
|
|
|
bcopy(ptr, ap->kvalue, len);
|
2006-04-07 16:19:48 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gctl_set_param_err(struct gctl_req *req, const char *param, void const *ptr,
|
|
|
|
int len)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (gctl_set_param(req, param, ptr, len)) {
|
|
|
|
case EPERM:
|
|
|
|
gctl_error(req, "No write access %s argument", param);
|
|
|
|
break;
|
|
|
|
case ENOSPC:
|
|
|
|
gctl_error(req, "Wrong length %s argument", param);
|
|
|
|
break;
|
|
|
|
case EINVAL:
|
|
|
|
gctl_error(req, "Missing %s argument", param);
|
|
|
|
break;
|
2003-05-04 19:24:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-27 14:35:00 +00:00
|
|
|
void *
|
|
|
|
gctl_get_param(struct gctl_req *req, const char *param, int *len)
|
|
|
|
{
|
2003-06-01 13:47:51 +00:00
|
|
|
int i;
|
2003-03-27 14:35:00 +00:00
|
|
|
void *p;
|
|
|
|
struct gctl_req_arg *ap;
|
|
|
|
|
|
|
|
for (i = 0; i < req->narg; i++) {
|
|
|
|
ap = &req->arg[i];
|
|
|
|
if (strcmp(param, ap->name))
|
|
|
|
continue;
|
|
|
|
if (!(ap->flag & GCTL_PARAM_RD))
|
|
|
|
continue;
|
2003-06-01 13:47:51 +00:00
|
|
|
p = ap->kvalue;
|
2003-03-27 14:35:00 +00:00
|
|
|
if (len != NULL)
|
2003-06-01 13:47:51 +00:00
|
|
|
*len = ap->len;
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
char const *
|
|
|
|
gctl_get_asciiparam(struct gctl_req *req, const char *param)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char const *p;
|
|
|
|
struct gctl_req_arg *ap;
|
|
|
|
|
|
|
|
for (i = 0; i < req->narg; i++) {
|
|
|
|
ap = &req->arg[i];
|
|
|
|
if (strcmp(param, ap->name))
|
|
|
|
continue;
|
|
|
|
if (!(ap->flag & GCTL_PARAM_RD))
|
|
|
|
continue;
|
|
|
|
p = ap->kvalue;
|
|
|
|
if (ap->len < 1) {
|
|
|
|
gctl_error(req, "No length argument (%s)", param);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (p[ap->len - 1] != '\0') {
|
|
|
|
gctl_error(req, "Unterminated argument (%s)", param);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2003-03-27 14:35:00 +00:00
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2003-04-23 08:03:47 +00:00
|
|
|
void *
|
|
|
|
gctl_get_paraml(struct gctl_req *req, const char *param, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
p = gctl_get_param(req, param, &i);
|
|
|
|
if (p == NULL)
|
|
|
|
gctl_error(req, "Missing %s argument", param);
|
|
|
|
else if (i != len) {
|
|
|
|
p = NULL;
|
|
|
|
gctl_error(req, "Wrong length %s argument", param);
|
|
|
|
}
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
struct g_class *
|
|
|
|
gctl_get_class(struct gctl_req *req, char const *arg)
|
2003-03-27 14:35:00 +00:00
|
|
|
{
|
2003-06-01 13:47:51 +00:00
|
|
|
char const *p;
|
2003-03-27 14:35:00 +00:00
|
|
|
struct g_class *cp;
|
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
p = gctl_get_asciiparam(req, arg);
|
2003-03-27 14:35:00 +00:00
|
|
|
if (p == NULL)
|
|
|
|
return (NULL);
|
|
|
|
LIST_FOREACH(cp, &g_classes, class) {
|
2003-06-01 13:47:51 +00:00
|
|
|
if (!strcmp(p, cp->name))
|
2003-03-27 14:35:00 +00:00
|
|
|
return (cp);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
struct g_geom *
|
|
|
|
gctl_get_geom(struct gctl_req *req, struct g_class *mpr, char const *arg)
|
2003-03-27 14:35:00 +00:00
|
|
|
{
|
2003-06-01 13:47:51 +00:00
|
|
|
char const *p;
|
2003-03-27 14:35:00 +00:00
|
|
|
struct g_class *mp;
|
|
|
|
struct g_geom *gp;
|
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
p = gctl_get_asciiparam(req, arg);
|
2007-03-30 16:32:08 +00:00
|
|
|
if (p == NULL)
|
|
|
|
return (NULL);
|
|
|
|
LIST_FOREACH(mp, &g_classes, class) {
|
|
|
|
if (mpr != NULL && mpr != mp)
|
|
|
|
continue;
|
|
|
|
LIST_FOREACH(gp, &mp->geom, geom) {
|
|
|
|
if (!strcmp(p, gp->name))
|
|
|
|
return (gp);
|
2003-03-27 14:35:00 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-30 16:32:08 +00:00
|
|
|
gctl_error(req, "Geom not found: \"%s\"", p);
|
2003-03-27 14:35:00 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
struct g_provider *
|
|
|
|
gctl_get_provider(struct gctl_req *req, char const *arg)
|
2003-03-27 14:35:00 +00:00
|
|
|
{
|
2003-06-01 13:47:51 +00:00
|
|
|
char const *p;
|
2003-03-27 14:35:00 +00:00
|
|
|
struct g_provider *pp;
|
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
p = gctl_get_asciiparam(req, arg);
|
2003-03-27 14:35:00 +00:00
|
|
|
if (p == NULL)
|
|
|
|
return (NULL);
|
2003-06-04 18:17:52 +00:00
|
|
|
pp = g_provider_by_name(p);
|
|
|
|
if (pp != NULL)
|
|
|
|
return (pp);
|
2007-03-30 16:32:08 +00:00
|
|
|
gctl_error(req, "Provider not found: \"%s\"", p);
|
2003-03-27 14:35:00 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2003-06-01 13:47:51 +00:00
|
|
|
static void
|
|
|
|
g_ctl_req(void *arg, int flag __unused)
|
2003-03-27 14:35:00 +00:00
|
|
|
{
|
|
|
|
struct g_class *mp;
|
2003-06-01 13:47:51 +00:00
|
|
|
struct gctl_req *req;
|
|
|
|
char const *verb;
|
2003-03-27 14:35:00 +00:00
|
|
|
|
|
|
|
g_topology_assert();
|
2003-06-01 13:47:51 +00:00
|
|
|
req = arg;
|
|
|
|
mp = gctl_get_class(req, "class");
|
2003-06-02 20:35:37 +00:00
|
|
|
if (mp == NULL) {
|
|
|
|
gctl_error(req, "Class not found");
|
2003-06-01 13:47:51 +00:00
|
|
|
return;
|
2003-06-02 20:35:37 +00:00
|
|
|
}
|
2005-09-18 23:54:40 +00:00
|
|
|
if (mp->ctlreq == NULL) {
|
2003-06-01 13:47:51 +00:00
|
|
|
gctl_error(req, "Class takes no requests");
|
2005-09-18 23:54:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
verb = gctl_get_param(req, "verb", NULL);
|
|
|
|
if (verb == NULL) {
|
|
|
|
gctl_error(req, "Verb missing");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mp->ctlreq(req, mp, verb);
|
2003-03-27 14:35:00 +00:00
|
|
|
g_topology_assert();
|
|
|
|
}
|
|
|
|
|
2003-04-22 21:01:46 +00:00
|
|
|
|
2003-03-23 10:16:14 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
g_ctl_ioctl_ctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
|
2003-03-23 10:16:14 +00:00
|
|
|
{
|
2003-03-27 14:35:00 +00:00
|
|
|
struct gctl_req *req;
|
2004-10-23 20:52:15 +00:00
|
|
|
int nerror;
|
2003-03-23 10:16:14 +00:00
|
|
|
|
|
|
|
req = (void *)data;
|
2003-06-01 13:47:51 +00:00
|
|
|
req->nerror = 0;
|
|
|
|
req->serror = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
|
2003-03-27 14:35:00 +00:00
|
|
|
/* It is an error if we cannot return an error text */
|
2003-06-01 13:47:51 +00:00
|
|
|
if (req->lerror < 2)
|
2003-03-23 10:16:14 +00:00
|
|
|
return (EINVAL);
|
2003-03-27 14:35:00 +00:00
|
|
|
if (!useracc(req->error, req->lerror, VM_PROT_WRITE))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* Check the version */
|
|
|
|
if (req->version != GCTL_VERSION)
|
|
|
|
return (gctl_error(req,
|
|
|
|
"kernel and libgeom version mismatch."));
|
|
|
|
|
|
|
|
/* Get things on board */
|
2003-06-01 13:47:51 +00:00
|
|
|
gctl_copyin(req);
|
2003-03-27 14:35:00 +00:00
|
|
|
|
2003-03-31 18:35:37 +00:00
|
|
|
if (g_debugflags & G_F_CTLDUMP)
|
|
|
|
gctl_dump(req);
|
2003-06-01 13:47:51 +00:00
|
|
|
|
|
|
|
if (!req->nerror) {
|
|
|
|
g_waitfor_event(g_ctl_req, req, M_WAITOK, NULL);
|
|
|
|
gctl_copyout(req);
|
2003-03-27 14:35:00 +00:00
|
|
|
}
|
2005-04-08 09:28:08 +00:00
|
|
|
if (sbuf_done(req->serror)) {
|
|
|
|
req->nerror = copyout(sbuf_data(req->serror), req->error,
|
|
|
|
imin(req->lerror, sbuf_len(req->serror) + 1));
|
|
|
|
}
|
2003-06-01 13:47:51 +00:00
|
|
|
|
2004-10-23 20:52:15 +00:00
|
|
|
nerror = req->nerror;
|
2003-05-02 12:49:41 +00:00
|
|
|
gctl_free(req);
|
2004-10-23 20:52:15 +00:00
|
|
|
return (nerror);
|
2003-03-23 10:16:14 +00:00
|
|
|
}
|
|
|
|
|
2002-10-13 20:33:33 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
g_ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
|
2002-10-13 20:33:33 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
switch(cmd) {
|
2003-03-23 10:16:14 +00:00
|
|
|
case GEOM_CTL:
|
|
|
|
error = g_ctl_ioctl_ctl(dev, cmd, data, fflag, td);
|
|
|
|
break;
|
2002-10-13 20:33:33 +00:00
|
|
|
default:
|
2003-06-01 13:47:51 +00:00
|
|
|
error = ENOIOCTL;
|
2002-10-13 20:33:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
}
|