summaryrefslogtreecommitdiffstats
path: root/sys/geom
diff options
context:
space:
mode:
Diffstat (limited to 'sys/geom')
-rw-r--r--sys/geom/geom_dev.c21
-rw-r--r--sys/geom/nop/g_nop.c42
-rw-r--r--sys/geom/nop/g_nop.h2
3 files changed, 62 insertions, 3 deletions
diff --git a/sys/geom/geom_dev.c b/sys/geom/geom_dev.c
index 621a037..1123323 100644
--- a/sys/geom/geom_dev.c
+++ b/sys/geom/geom_dev.c
@@ -356,6 +356,13 @@ g_dev_open(struct cdev *dev, int flags, int fmt, struct thread *td)
#else
e = 0;
#endif
+
+ /*
+ * This happens on attempt to open a device node with O_EXEC.
+ */
+ if (r + w + e == 0)
+ return (EINVAL);
+
if (w) {
/*
* When running in very secure mode, do not allow
@@ -399,6 +406,20 @@ g_dev_close(struct cdev *dev, int flags, int fmt, struct thread *td)
#else
e = 0;
#endif
+
+ /*
+ * The vgonel(9) - caused by eg. forced unmount of devfs - calls
+ * VOP_CLOSE(9) on devfs vnode without any FREAD or FWRITE flags,
+ * which would result in zero deltas, which in turn would cause
+ * panic in g_access(9).
+ *
+ * Note that we cannot zero the counters (ie. do "r = cp->acr"
+ * etc) instead, because the consumer might be opened in another
+ * devfs instance.
+ */
+ if (r + w + e == 0)
+ return (EINVAL);
+
sc = cp->private;
mtx_lock(&sc->sc_mtx);
sc->sc_open += r + w + e;
diff --git a/sys/geom/nop/g_nop.c b/sys/geom/nop/g_nop.c
index bd72d78..837f3f4 100644
--- a/sys/geom/nop/g_nop.c
+++ b/sys/geom/nop/g_nop.c
@@ -162,7 +162,7 @@ g_nop_access(struct g_provider *pp, int dr, int dw, int de)
static int
g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
int ioerror, u_int rfailprob, u_int wfailprob, off_t offset, off_t size,
- u_int secsize)
+ u_int secsize, u_int stripesize, u_int stripeoffset)
{
struct g_nop_softc *sc;
struct g_geom *gp;
@@ -208,6 +208,18 @@ g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
return (EINVAL);
}
size -= size % secsize;
+ if ((stripesize % pp->sectorsize) != 0) {
+ gctl_error(req, "Invalid stripesize for provider %s.", pp->name);
+ return (EINVAL);
+ }
+ if ((stripeoffset % pp->sectorsize) != 0) {
+ gctl_error(req, "Invalid stripeoffset for provider %s.", pp->name);
+ return (EINVAL);
+ }
+ if (stripesize != 0 && stripeoffset >= stripesize) {
+ gctl_error(req, "stripeoffset is too big.");
+ return (EINVAL);
+ }
snprintf(name, sizeof(name), "%s%s", pp->name, G_NOP_SUFFIX);
LIST_FOREACH(gp, &mp->geom, geom) {
if (strcmp(gp->name, name) == 0) {
@@ -219,6 +231,8 @@ g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO);
sc->sc_offset = offset;
sc->sc_explicitsize = explicitsize;
+ sc->sc_stripesize = stripesize;
+ sc->sc_stripeoffset = stripeoffset;
sc->sc_error = ioerror;
sc->sc_rfailprob = rfailprob;
sc->sc_wfailprob = wfailprob;
@@ -238,6 +252,8 @@ g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
newpp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
newpp->mediasize = size;
newpp->sectorsize = secsize;
+ newpp->stripesize = stripesize;
+ newpp->stripeoffset = stripeoffset;
cp = g_new_consumer(gp);
cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
@@ -304,7 +320,8 @@ static void
g_nop_ctl_create(struct gctl_req *req, struct g_class *mp)
{
struct g_provider *pp;
- intmax_t *error, *rfailprob, *wfailprob, *offset, *secsize, *size;
+ intmax_t *error, *rfailprob, *wfailprob, *offset, *secsize, *size,
+ *stripesize, *stripeoffset;
const char *name;
char param[16];
int i, *nargs;
@@ -370,6 +387,24 @@ g_nop_ctl_create(struct gctl_req *req, struct g_class *mp)
gctl_error(req, "Invalid '%s' argument", "secsize");
return;
}
+ stripesize = gctl_get_paraml(req, "stripesize", sizeof(*stripesize));
+ if (stripesize == NULL) {
+ gctl_error(req, "No '%s' argument", "stripesize");
+ return;
+ }
+ if (*stripesize < 0) {
+ gctl_error(req, "Invalid '%s' argument", "stripesize");
+ return;
+ }
+ stripeoffset = gctl_get_paraml(req, "stripeoffset", sizeof(*stripeoffset));
+ if (stripeoffset == NULL) {
+ gctl_error(req, "No '%s' argument", "stripeoffset");
+ return;
+ }
+ if (*stripeoffset < 0) {
+ gctl_error(req, "Invalid '%s' argument", "stripeoffset");
+ return;
+ }
for (i = 0; i < *nargs; i++) {
snprintf(param, sizeof(param), "arg%d", i);
@@ -390,7 +425,8 @@ g_nop_ctl_create(struct gctl_req *req, struct g_class *mp)
*error == -1 ? EIO : (int)*error,
*rfailprob == -1 ? 0 : (u_int)*rfailprob,
*wfailprob == -1 ? 0 : (u_int)*wfailprob,
- (off_t)*offset, (off_t)*size, (u_int)*secsize) != 0) {
+ (off_t)*offset, (off_t)*size, (u_int)*secsize,
+ (u_int)*stripesize, (u_int)*stripeoffset) != 0) {
return;
}
}
diff --git a/sys/geom/nop/g_nop.h b/sys/geom/nop/g_nop.h
index 3e37c05..b5e954a 100644
--- a/sys/geom/nop/g_nop.h
+++ b/sys/geom/nop/g_nop.h
@@ -59,6 +59,8 @@ struct g_nop_softc {
int sc_error;
off_t sc_offset;
off_t sc_explicitsize;
+ off_t sc_stripesize;
+ off_t sc_stripeoffset;
u_int sc_rfailprob;
u_int sc_wfailprob;
uintmax_t sc_reads;
OpenPOWER on IntegriCloud