Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion share/man/man9/g_provider.9
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
.Os
.Sh NAME
.Nm g_new_providerf ,
.Nm g_new_provider ,
.Nm g_destroy_provider ,
.Nm g_error_provider
.Nd "GEOM providers management"
.Sh SYNOPSIS
.In geom/geom.h
.Ft "struct g_provider *"
.Fn g_new_providerf "struct g_geom *gp" "const char *fmt" ...
.Ft "struct g_provider *"
.Fn g_new_provider "struct g_geom *gp" "const char *name"
.Ft void
.Fn g_destroy_provider "struct g_provider *pp"
.Ft void
Expand Down Expand Up @@ -66,6 +69,14 @@ to reset the provider's error, which is initially set to
.Er ENXIO .
.Pp
The
.Fn g_new_provider
function is very similar to
.Fn g_new_providerf
except that it accepts a regular string instead of a
.Xr printf 3 Ns
-like format string as provider's name.
.Pp
The
.Fn g_destroy_provider
function destroys the given provider, cancels all related pending events and
removes the corresponding devfs entry.
Expand All @@ -78,6 +89,8 @@ as well as increasing its access count will not be possible (error
.Fa error
will be returned).
.Sh RESTRICTIONS/CONDITIONS
.Fn g_new_providerf
and
.Fn g_new_provider :
.Bl -item -offset indent
.It
Expand Down Expand Up @@ -106,7 +119,9 @@ The topology lock has to be held.
.Sh RETURN VALUES
The
.Fn g_new_providerf
function returns a pointer to the newly created provider.
and
.Fn g_new_provider
functions return a pointer to the newly created provider.
.Sh EXAMPLES
Create an example provider, set its parameters and make it usable.
.Bd -literal -offset indent
Expand Down
2 changes: 1 addition & 1 deletion sys/geom/gate/g_gate.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ g_gate_create(struct g_gate_ctl_create *ggio)

ggio->gctl_unit = sc->sc_unit;

pp = g_new_providerf(gp, "%s", name);
pp = g_new_provider(gp, name);
pp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
pp->mediasize = ggio->gctl_mediasize;
pp->sectorsize = ggio->gctl_sectorsize;
Expand Down
3 changes: 2 additions & 1 deletion sys/geom/geom.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ int g_handleattr_str(struct bio *bp, const char *attribute, const char *str);
struct g_consumer * g_new_consumer(struct g_geom *gp);
struct g_geom * g_new_geomf(struct g_class *mp, const char *fmt, ...)
__printflike(2, 3);
struct g_provider * g_new_providerf(struct g_geom *gp, const char *fmt, ...)
struct g_provider *g_new_provider(struct g_geom *gp, const char *name);
struct g_provider *g_new_providerf(struct g_geom *gp, const char *fmt, ...)
__printflike(2, 3);
void g_provider_add_alias(struct g_provider *pp, const char *fmt, ...)
__printflike(2, 3);
Expand Down
2 changes: 1 addition & 1 deletion sys/geom/geom_ccd.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ g_ccd_create(struct gctl_req *req, struct g_class *mp)
return;
}

pp = g_new_providerf(gp, "%s", gp->name);
pp = g_new_provider(gp, gp->name);
pp->mediasize = sc->sc_size * (off_t)sc->sc_secsize;
pp->sectorsize = sc->sc_secsize;
g_error_provider(pp, 0);
Expand Down
2 changes: 1 addition & 1 deletion sys/geom/geom_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ g_disk_create(void *arg, int flag)
sc->d_devstat = dp->d_devstat;
gp = g_new_geomf(&g_disk_class, "%s%d", dp->d_name, dp->d_unit);
gp->softc = sc;
pp = g_new_providerf(gp, "%s", gp->name);
pp = g_new_provider(gp, gp->name);
LIST_FOREACH(dap, &dp->d_aliases, da_next)
g_provider_add_alias(pp, "%s%d", dap->da_alias, dp->d_unit);
devstat_remove_entry(pp->stat);
Expand Down
2 changes: 1 addition & 1 deletion sys/geom/geom_slice.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ g_slice_config(struct g_geom *gp, u_int idx, int how, off_t offset, off_t length
sbuf_vprintf(sb, fmt, ap);
va_end(ap);
sbuf_finish(sb);
pp = g_new_providerf(gp, "%s", sbuf_data(sb));
pp = g_new_provider(gp, sbuf_data(sb));
pp2 = LIST_FIRST(&gp->consumer)->provider;
pp->stripesize = pp2->stripesize;
pp->stripeoffset = pp2->stripeoffset + offset;
Expand Down
33 changes: 22 additions & 11 deletions sys/geom/geom_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,10 @@ g_new_provider_event(void *arg, int flag)
}

struct g_provider *
g_new_providerf(struct g_geom *gp, const char *fmt, ...)
g_new_provider(struct g_geom *gp, const char *name)
{
int len;
struct g_provider *pp;
struct sbuf *sb;
va_list ap;

g_topology_assert();
G_VALID_GEOM(gp);
Expand All @@ -611,15 +610,10 @@ g_new_providerf(struct g_geom *gp, const char *fmt, ...)
KASSERT(!(gp->flags & G_GEOM_WITHER),
("new provider on WITHERing geom(%s) (class %s)",
gp->name, gp->class->name));
sb = sbuf_new_auto();
va_start(ap, fmt);
sbuf_vprintf(sb, fmt, ap);
va_end(ap);
sbuf_finish(sb);
pp = g_malloc(sizeof *pp + sbuf_len(sb) + 1, M_WAITOK | M_ZERO);
len = strlen(name);
pp = g_malloc(sizeof(*pp) + len + 1, M_WAITOK | M_ZERO);
pp->name = (char *)(pp + 1);
strcpy(pp->name, sbuf_data(sb));
sbuf_delete(sb);
memcpy(pp->name, name, len);
LIST_INIT(&pp->consumers);
LIST_INIT(&pp->aliases);
pp->error = ENXIO;
Expand All @@ -631,6 +625,23 @@ g_new_providerf(struct g_geom *gp, const char *fmt, ...)
return (pp);
}

struct g_provider *
g_new_providerf(struct g_geom *gp, const char *fmt, ...)
{
struct g_provider *pp;
struct sbuf *sb;
va_list ap;

sb = sbuf_new_auto();
va_start(ap, fmt);
sbuf_vprintf(sb, fmt, ap);
va_end(ap);
sbuf_finish(sb);
pp = g_new_provider(gp, sbuf_data(sb));
sbuf_delete(sb);
return (pp);
}

void
g_provider_add_alias(struct g_provider *pp, const char *fmt, ...)
{
Expand Down
2 changes: 1 addition & 1 deletion sys/geom/mountver/g_mountver.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ g_mountver_create(struct gctl_req *req, struct g_class *mp, struct g_provider *p
gp->access = g_mountver_access;
gp->dumpconf = g_mountver_dumpconf;

newpp = g_new_providerf(gp, "%s", gp->name);
newpp = g_new_provider(gp, gp->name);
newpp->mediasize = pp->mediasize;
newpp->sectorsize = pp->sectorsize;
newpp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
Expand Down
2 changes: 1 addition & 1 deletion sys/geom/nop/g_nop.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
mtx_init(&sc->sc_lock, "gnop lock", NULL, MTX_DEF);
gp->softc = sc;

newpp = g_new_providerf(gp, "%s", gp->name);
newpp = g_new_provider(gp, gp->name);
newpp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
newpp->mediasize = size;
newpp->sectorsize = secsize;
Expand Down
2 changes: 1 addition & 1 deletion sys/geom/part/g_part_if.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
sb = sbuf_new_auto();
G_PART_FULLNAME(table, entry, sb, pfx);
sbuf_finish(sb);
ret = g_new_providerf(gp, "%s", sbuf_data(sb));
ret = g_new_provider(gp, sbuf_data(sb));
sbuf_delete(sb);
return (ret);
}
Expand Down
2 changes: 1 addition & 1 deletion sys/geom/raid/g_raid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ g_raid_launch_provider(struct g_raid_volume *vol)
snprintf(name, sizeof(name), "raid/r%d", vol->v_global_id);
}

pp = g_new_providerf(sc->sc_geom, "%s", name);
pp = g_new_provider(sc->sc_geom, name);
pp->flags |= G_PF_DIRECT_RECEIVE;
if (vol->v_tr->tro_class->trc_accept_unmapped) {
pp->flags |= G_PF_ACCEPT_UNMAPPED;
Expand Down
2 changes: 1 addition & 1 deletion sys/geom/union/g_union.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ g_union_ctl_create(struct gctl_req *req, struct g_class *mp, bool verbose)
sc->sc_writemap_memory = 0;
gp->softc = sc;

newpp = g_new_providerf(gp, "%s", gp->name);
newpp = g_new_provider(gp, gp->name);
newpp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
newpp->mediasize = size;
newpp->sectorsize = secsize;
Expand Down
2 changes: 1 addition & 1 deletion sys/geom/uzip/g_uzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ g_uzip_taste(struct g_class *mp, struct g_provider *pp, int flags)
}

g_topology_lock();
pp2 = g_new_providerf(gp, "%s", gp->name);
pp2 = g_new_provider(gp, gp->name);
pp2->sectorsize = 512;
pp2->mediasize = (off_t)sc->nblocks * sc->blksz;
pp2->stripesize = pp->stripesize;
Expand Down
2 changes: 1 addition & 1 deletion sys/geom/zero/g_zero.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ g_zero_init(struct g_class *mp)
gp = g_new_geomf(mp, "gzero");
gp->start = g_zero_start;
gp->access = g_std_access;
gpp = pp = g_new_providerf(gp, "%s", gp->name);
gpp = pp = g_new_provider(gp, gp->name);
pp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
if (!g_zero_clear)
pp->flags |= G_PF_ACCEPT_UNMAPPED;
Expand Down