Add trivial resize handling to gnop(8).

Reviewed by:	mav
Sponsored by:	FreeBSD Foundation
This commit is contained in:
Edward Tomasz Napierala 2012-07-07 22:22:13 +00:00
parent 74badfa6ba
commit 7027e4dac4
2 changed files with 29 additions and 0 deletions

View File

@ -71,6 +71,30 @@ g_nop_orphan(struct g_consumer *cp)
g_nop_destroy(cp->geom, 1);
}
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)
{
@ -146,6 +170,7 @@ g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
struct g_consumer *cp;
char name[64];
int error;
off_t explicitsize;
g_topology_assert();
@ -165,6 +190,7 @@ g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
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) {
@ -192,6 +218,7 @@ g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
gp = g_new_geomf(mp, name);
sc = g_malloc(sizeof(*sc), M_WAITOK);
sc->sc_offset = offset;
sc->sc_explicitsize = explicitsize;
sc->sc_error = ioerror;
sc->sc_rfailprob = rfailprob;
sc->sc_wfailprob = wfailprob;
@ -202,6 +229,7 @@ g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
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;

View File

@ -57,6 +57,7 @@
struct g_nop_softc {
int sc_error;
off_t sc_offset;
off_t sc_explicitsize;
u_int sc_rfailprob;
u_int sc_wfailprob;
uintmax_t sc_reads;