[Midnightbsd-cvs] src [9969] trunk/sys/geom/nop: sync with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat May 26 11:24:14 EDT 2018
Revision: 9969
http://svnweb.midnightbsd.org/src/?rev=9969
Author: laffer1
Date: 2018-05-26 11:24:14 -0400 (Sat, 26 May 2018)
Log Message:
-----------
sync with freebsd
Modified Paths:
--------------
trunk/sys/geom/nop/g_nop.c
trunk/sys/geom/nop/g_nop.h
Modified: trunk/sys/geom/nop/g_nop.c
===================================================================
--- trunk/sys/geom/nop/g_nop.c 2018-05-26 15:23:19 UTC (rev 9968)
+++ trunk/sys/geom/nop/g_nop.c 2018-05-26 15:24:14 UTC (rev 9969)
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/geom/nop/g_nop.c,v 1.19 2006/09/08 13:46:18 pjd Exp $");
+__FBSDID("$FreeBSD: stable/10/sys/geom/nop/g_nop.c 293738 2016-01-12 09:27:01Z trasz $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -73,6 +73,30 @@
}
static void
+g_nop_resize(struct g_consumer *cp)
+{
+ struct g_nop_softc *sc;
+ struct g_geom *gp;
+ struct g_provider *pp;
+ off_t size;
+
+ g_topology_assert();
+
+ gp = cp->geom;
+ sc = gp->softc;
+
+ if (sc->sc_explicitsize != 0)
+ return;
+ if (cp->provider->mediasize < sc->sc_offset) {
+ g_nop_destroy(gp, 1);
+ return;
+ }
+ size = cp->provider->mediasize - sc->sc_offset;
+ LIST_FOREACH(pp, &gp->provider, provider)
+ g_resize_provider(pp, size);
+}
+
+static void
g_nop_start(struct bio *bp)
{
struct g_nop_softc *sc;
@@ -84,6 +108,7 @@
gp = bp->bio_to->geom;
sc = gp->softc;
G_NOP_LOGREQ(bp, "Request received.");
+ mtx_lock(&sc->sc_lock);
switch (bp->bio_cmd) {
case BIO_READ:
sc->sc_reads++;
@@ -95,13 +120,32 @@
sc->sc_wrotebytes += bp->bio_length;
failprob = sc->sc_wfailprob;
break;
+ case BIO_DELETE:
+ sc->sc_deletes++;
+ break;
+ case BIO_GETATTR:
+ sc->sc_getattrs++;
+ break;
+ case BIO_FLUSH:
+ sc->sc_flushes++;
+ break;
+ case BIO_CMD0:
+ sc->sc_cmd0s++;
+ break;
+ case BIO_CMD1:
+ sc->sc_cmd1s++;
+ break;
+ case BIO_CMD2:
+ sc->sc_cmd2s++;
+ break;
}
+ mtx_unlock(&sc->sc_lock);
if (failprob > 0) {
u_int rval;
rval = arc4random() % 100;
if (rval < failprob) {
- G_NOP_LOGREQ(bp, "Returning error=%d.", sc->sc_error);
+ G_NOP_LOGREQLVL(1, bp, "Returning error=%d.", sc->sc_error);
g_io_deliver(bp, sc->sc_error);
return;
}
@@ -113,8 +157,6 @@
}
cbp->bio_done = g_std_done;
cbp->bio_offset = bp->bio_offset + sc->sc_offset;
- cbp->bio_data = bp->bio_data;
- cbp->bio_length = bp->bio_length;
pp = LIST_FIRST(&gp->provider);
KASSERT(pp != NULL, ("NULL pp"));
cbp->bio_to = pp;
@@ -139,7 +181,7 @@
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;
@@ -147,6 +189,7 @@
struct g_consumer *cp;
char name[64];
int error;
+ off_t explicitsize;
g_topology_assert();
@@ -166,6 +209,7 @@
gctl_error(req, "Invalid offset for provider %s.", pp->name);
return (EINVAL);
}
+ explicitsize = size;
if (size == 0)
size = pp->mediasize - offset;
if (offset + size > pp->mediasize) {
@@ -183,6 +227,18 @@
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) {
@@ -191,26 +247,41 @@
}
}
gp = g_new_geomf(mp, "%s", name);
- sc = g_malloc(sizeof(*sc), M_WAITOK);
+ 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;
sc->sc_reads = 0;
sc->sc_writes = 0;
+ sc->sc_deletes = 0;
+ sc->sc_getattrs = 0;
+ sc->sc_flushes = 0;
+ sc->sc_cmd0s = 0;
+ sc->sc_cmd1s = 0;
+ sc->sc_cmd2s = 0;
sc->sc_readbytes = 0;
sc->sc_wrotebytes = 0;
+ mtx_init(&sc->sc_lock, "gnop lock", NULL, MTX_DEF);
gp->softc = sc;
gp->start = g_nop_start;
gp->orphan = g_nop_orphan;
+ gp->resize = g_nop_resize;
gp->access = g_nop_access;
gp->dumpconf = g_nop_dumpconf;
newpp = g_new_providerf(gp, "%s", gp->name);
+ 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;
error = g_attach(cp, pp);
if (error != 0) {
gctl_error(req, "Cannot attach to provider %s.", pp->name);
@@ -217,6 +288,7 @@
goto fail;
}
+ newpp->flags |= pp->flags & G_PF_ACCEPT_UNMAPPED;
g_error_provider(newpp, 0);
G_NOP_DEBUG(0, "Device %s created.", gp->name);
return (0);
@@ -225,6 +297,7 @@
g_detach(cp);
g_destroy_consumer(cp);
g_destroy_provider(newpp);
+ mtx_destroy(&sc->sc_lock);
g_free(gp->softc);
g_destroy_geom(gp);
return (error);
@@ -233,10 +306,12 @@
static int
g_nop_destroy(struct g_geom *gp, boolean_t force)
{
+ struct g_nop_softc *sc;
struct g_provider *pp;
g_topology_assert();
- if (gp->softc == NULL)
+ sc = gp->softc;
+ if (sc == NULL)
return (ENXIO);
pp = LIST_FIRST(&gp->provider);
if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) {
@@ -251,8 +326,9 @@
} else {
G_NOP_DEBUG(0, "Device %s removed.", gp->name);
}
- g_free(gp->softc);
gp->softc = NULL;
+ mtx_destroy(&sc->sc_lock);
+ g_free(sc);
g_wither_geom(gp, ENXIO);
return (0);
@@ -269,7 +345,8 @@
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;
@@ -335,6 +412,24 @@
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);
@@ -355,7 +450,8 @@
*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;
}
}
@@ -531,6 +627,12 @@
sc = pp->geom->softc;
sc->sc_reads = 0;
sc->sc_writes = 0;
+ sc->sc_deletes = 0;
+ sc->sc_getattrs = 0;
+ sc->sc_flushes = 0;
+ sc->sc_cmd0s = 0;
+ sc->sc_cmd1s = 0;
+ sc->sc_cmd2s = 0;
sc->sc_readbytes = 0;
sc->sc_wrotebytes = 0;
}
@@ -588,6 +690,12 @@
sbuf_printf(sb, "%s<Error>%d</Error>\n", indent, sc->sc_error);
sbuf_printf(sb, "%s<Reads>%ju</Reads>\n", indent, sc->sc_reads);
sbuf_printf(sb, "%s<Writes>%ju</Writes>\n", indent, sc->sc_writes);
+ sbuf_printf(sb, "%s<Deletes>%ju</Deletes>\n", indent, sc->sc_deletes);
+ sbuf_printf(sb, "%s<Getattrs>%ju</Getattrs>\n", indent, sc->sc_getattrs);
+ sbuf_printf(sb, "%s<Flushes>%ju</Flushes>\n", indent, sc->sc_flushes);
+ sbuf_printf(sb, "%s<Cmd0s>%ju</Cmd0s>\n", indent, sc->sc_cmd0s);
+ sbuf_printf(sb, "%s<Cmd1s>%ju</Cmd1s>\n", indent, sc->sc_cmd1s);
+ sbuf_printf(sb, "%s<Cmd2s>%ju</Cmd2s>\n", indent, sc->sc_cmd2s);
sbuf_printf(sb, "%s<ReadBytes>%ju</ReadBytes>\n", indent,
sc->sc_readbytes);
sbuf_printf(sb, "%s<WroteBytes>%ju</WroteBytes>\n", indent,
Modified: trunk/sys/geom/nop/g_nop.h
===================================================================
--- trunk/sys/geom/nop/g_nop.h 2018-05-26 15:23:19 UTC (rev 9968)
+++ trunk/sys/geom/nop/g_nop.h 2018-05-26 15:24:14 UTC (rev 9969)
@@ -24,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/sys/geom/nop/g_nop.h,v 1.7 2006/09/30 08:16:49 pjd Exp $
+ * $FreeBSD: stable/10/sys/geom/nop/g_nop.h 293738 2016-01-12 09:27:01Z trasz $
*/
#ifndef _G_NOP_H_
@@ -45,9 +45,10 @@
printf("\n"); \
} \
} while (0)
-#define G_NOP_LOGREQ(bp, ...) do { \
- if (g_nop_debug >= 2) { \
- printf("GEOM_NOP[2]: "); \
+#define G_NOP_LOGREQ(bp, ...) G_NOP_LOGREQLVL(2, bp, __VA_ARGS__)
+#define G_NOP_LOGREQLVL(lvl, bp, ...) do { \
+ if (g_nop_debug >= (lvl)) { \
+ printf("GEOM_NOP[%d]: ", (lvl)); \
printf(__VA_ARGS__); \
printf(" "); \
g_print_bio(bp); \
@@ -58,12 +59,22 @@
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;
uintmax_t sc_writes;
+ uintmax_t sc_deletes;
+ uintmax_t sc_getattrs;
+ uintmax_t sc_flushes;
+ uintmax_t sc_cmd0s;
+ uintmax_t sc_cmd1s;
+ uintmax_t sc_cmd2s;
uintmax_t sc_readbytes;
uintmax_t sc_wrotebytes;
+ struct mtx sc_lock;
};
#endif /* _KERNEL */
More information about the Midnightbsd-cvs
mailing list