Reimplement aliases in geom

The alias needs to be part of the provider instead of the geom to work
properly. To bind the DEV geom, we need to look at the provider's names and
aliases and create the dev entries from there. If this lives in the GEOM, then
it won't propigate down the tree properly. Remove it from geom, add it provider.

Update geli, gmountver, gnop, gpart, and guzip to use it, which handles the bulk
of the uses in FreeBSD. I think this is all the providers that create a new name
based on their parent's name.
This commit is contained in:
Warner Losh 2020-05-13 19:17:28 +00:00
parent f272bc03cc
commit ae1cce524e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=361015
10 changed files with 73 additions and 55 deletions

View File

@ -843,6 +843,7 @@ g_eli_create(struct gctl_req *req, struct g_class *mp, struct g_provider *bpp,
struct g_geom *gp;
struct g_provider *pp;
struct g_consumer *cp;
struct g_geom_alias *gap;
u_int i, threads;
int dcw, error;
@ -971,6 +972,8 @@ g_eli_create(struct gctl_req *req, struct g_class *mp, struct g_provider *bpp,
pp = g_new_providerf(gp, "%s%s", bpp->name, G_ELI_SUFFIX);
pp->mediasize = sc->sc_mediasize;
pp->sectorsize = sc->sc_sectorsize;
LIST_FOREACH(gap, &bpp->aliases, ga_next)
g_provider_add_alias(pp, "%s%s", gap->ga_alias, G_ELI_SUFFIX);
g_error_provider(pp, 0);

View File

@ -122,15 +122,6 @@ struct g_class {
LIST_HEAD(,g_geom) geom;
};
/*
* The g_geom_alias is a list node for aliases for the geom name
* for device node creation.
*/
struct g_geom_alias {
LIST_ENTRY(g_geom_alias) ga_next;
const char *ga_alias;
};
#define G_VERSION_00 0x19950323
#define G_VERSION_01 0x20041207 /* add fflag to g_ioctl_t */
#define G_VERSION G_VERSION_01
@ -163,7 +154,6 @@ struct g_geom {
#define G_GEOM_VOLATILE_BIO 0x02
#define G_GEOM_IN_ACCESS 0x04
#define G_GEOM_ACCESS_WAIT 0x08
LIST_HEAD(,g_geom_alias) aliases;
};
/*
@ -202,6 +192,15 @@ struct g_consumer {
u_int index;
};
/*
* The g_geom_alias is a list node for aliases for the provider name for device
* node creation.
*/
struct g_geom_alias {
LIST_ENTRY(g_geom_alias) ga_next;
const char *ga_alias;
};
/*
* A g_provider is a "logical disk".
*/
@ -226,6 +225,7 @@ struct g_provider {
#define G_PF_ACCEPT_UNMAPPED 0x8
#define G_PF_DIRECT_SEND 0x10
#define G_PF_DIRECT_RECEIVE 0x20
LIST_HEAD(,g_geom_alias) aliases;
/* Two fields for the implementing class to use */
void *private;
@ -280,7 +280,6 @@ void g_destroy_provider(struct g_provider *pp);
void g_detach(struct g_consumer *cp);
void g_error_provider(struct g_provider *pp, int error);
struct g_provider *g_provider_by_name(char const *arg);
void g_geom_add_alias(struct g_geom *gp, const char *alias);
int g_getattr__(const char *attr, struct g_consumer *cp, void *var, int len);
#define g_getattr(a, c, v) g_getattr__((a), (c), (v), sizeof *(v))
int g_handleattr(struct bio *bp, const char *attribute, const void *val,
@ -294,6 +293,8 @@ 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, ...)
__printflike(2, 3);
void g_provider_add_alias(struct g_provider *pp, const char *fmt, ...)
__printflike(2, 3);
void g_resize_provider(struct g_provider *pp, off_t size);
int g_retaste(struct g_class *mp);
void g_spoil(struct g_provider *pp, struct g_consumer *cp);

View File

@ -383,7 +383,7 @@ g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
/*
* Now add all the aliases for this drive
*/
LIST_FOREACH(gap, &pp->geom->aliases, ga_next) {
LIST_FOREACH(gap, &pp->aliases, ga_next) {
error = make_dev_alias_p(MAKEDEV_CHECKNAME | MAKEDEV_WAITOK, &adev, dev,
"%s", gap->ga_alias);
if (error) {

View File

@ -718,11 +718,9 @@ 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;
LIST_FOREACH(dap, &dp->d_aliases, da_next) {
snprintf(tmpstr, sizeof(tmpstr), "%s%d", dap->da_alias, dp->d_unit);
g_geom_add_alias(gp, tmpstr);
}
pp = g_new_providerf(gp, "%s", 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);
pp->stat = NULL;
dp->d_devstat->id = pp;

View File

@ -211,6 +211,7 @@ g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
static void
g_conf_provider(struct sbuf *sb, struct g_provider *pp)
{
struct g_geom_alias *gap;
sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp);
sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", pp->geom);
@ -219,6 +220,11 @@ g_conf_provider(struct sbuf *sb, struct g_provider *pp)
sbuf_cat(sb, "\t <name>");
g_conf_cat_escaped(sb, pp->name);
sbuf_cat(sb, "</name>\n");
LIST_FOREACH(gap, &pp->aliases, ga_next) {
sbuf_cat(sb, "\t <alias>");
g_conf_cat_escaped(sb, gap->ga_alias);
sbuf_cat(sb, "</alias>\n");
}
sbuf_printf(sb, "\t <mediasize>%jd</mediasize>\n",
(intmax_t)pp->mediasize);
sbuf_printf(sb, "\t <sectorsize>%u</sectorsize>\n", pp->sectorsize);
@ -242,7 +248,6 @@ g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_
{
struct g_consumer *cp2;
struct g_provider *pp2;
struct g_geom_alias *gap;
sbuf_printf(sb, " <geom id=\"%p\">\n", gp);
sbuf_printf(sb, " <class ref=\"%p\"/>\n", gp->class);
@ -268,11 +273,6 @@ g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_
continue;
g_conf_provider(sb, pp2);
}
LIST_FOREACH(gap, &gp->aliases, ga_next) {
sbuf_cat(sb, " <alias>\n");
g_conf_cat_escaped(sb, gap->ga_alias);
sbuf_cat(sb, " </alias>\n");
}
sbuf_cat(sb, " </geom>\n");
}

View File

@ -391,7 +391,6 @@ g_new_geomf(struct g_class *mp, const char *fmt, ...)
gp->rank = 1;
LIST_INIT(&gp->consumer);
LIST_INIT(&gp->provider);
LIST_INIT(&gp->aliases);
LIST_INSERT_HEAD(&mp->geom, gp, geom);
TAILQ_INSERT_HEAD(&geoms, gp, geoms);
strcpy(gp->name, sbuf_data(sb));
@ -412,7 +411,6 @@ g_new_geomf(struct g_class *mp, const char *fmt, ...)
void
g_destroy_geom(struct g_geom *gp)
{
struct g_geom_alias *gap, *gaptmp;
g_topology_assert();
G_VALID_GEOM(gp);
@ -426,8 +424,6 @@ g_destroy_geom(struct g_geom *gp)
g_cancel_event(gp);
LIST_REMOVE(gp, geom);
TAILQ_REMOVE(&geoms, gp, geoms);
LIST_FOREACH_SAFE(gap, &gp->aliases, ga_next, gaptmp)
g_free(gap);
g_free(gp->name);
g_free(gp);
}
@ -631,6 +627,7 @@ g_new_providerf(struct g_geom *gp, const char *fmt, ...)
strcpy(pp->name, sbuf_data(sb));
sbuf_delete(sb);
LIST_INIT(&pp->consumers);
LIST_INIT(&pp->aliases);
pp->error = ENXIO;
pp->geom = gp;
pp->stat = devstat_new_entry(pp, -1, 0, DEVSTAT_ALL_SUPPORTED,
@ -640,6 +637,28 @@ g_new_providerf(struct g_geom *gp, const char *fmt, ...)
return (pp);
}
void
g_provider_add_alias(struct g_provider *pp, const char *fmt, ...)
{
struct sbuf *sb;
struct g_geom_alias *gap;
va_list ap;
/*
* Generate the alias string and save it in the list.
*/
sb = sbuf_new_auto();
va_start(ap, fmt);
sbuf_vprintf(sb, fmt, ap);
va_end(ap);
sbuf_finish(sb);
gap = g_malloc(sizeof(*gap) + sbuf_len(sb) + 1, M_WAITOK | M_ZERO);
memcpy((char *)(gap + 1), sbuf_data(sb), sbuf_len(sb));
sbuf_delete(sb);
gap->ga_alias = (const char *)(gap + 1);
LIST_INSERT_HEAD(&pp->aliases, gap, ga_next);
}
void
g_error_provider(struct g_provider *pp, int error)
{
@ -768,6 +787,7 @@ void
g_destroy_provider(struct g_provider *pp)
{
struct g_geom *gp;
struct g_geom_alias *gap, *gaptmp;
g_topology_assert();
G_VALID_PROVIDER(pp);
@ -786,7 +806,8 @@ g_destroy_provider(struct g_provider *pp)
*/
if (gp->providergone != NULL)
gp->providergone(pp);
LIST_FOREACH_SAFE(gap, &pp->aliases, ga_next, gaptmp)
g_free(gap);
g_free(pp);
if ((gp->flags & G_GEOM_WITHER))
g_do_wither();
@ -1316,18 +1337,6 @@ g_compare_names(const char *namea, const char *nameb)
return (0);
}
void
g_geom_add_alias(struct g_geom *gp, const char *alias)
{
struct g_geom_alias *gap;
gap = (struct g_geom_alias *)g_malloc(
sizeof(struct g_geom_alias) + strlen(alias) + 1, M_WAITOK);
strcpy((char *)(gap + 1), alias);
gap->ga_alias = (const char *)(gap + 1);
LIST_INSERT_HEAD(&gp->aliases, gap, ga_next);
}
#if defined(DIAGNOSTIC) || defined(DDB)
/*
* This function walks the mesh and returns a non-zero integer if it

View File

@ -276,6 +276,7 @@ g_mountver_create(struct gctl_req *req, struct g_class *mp, struct g_provider *p
struct g_geom *gp;
struct g_provider *newpp;
struct g_consumer *cp;
struct g_geom_alias *gap;
char name[64];
int error;
int identsize = DISK_IDENT_SIZE;
@ -309,6 +310,8 @@ g_mountver_create(struct gctl_req *req, struct g_class *mp, struct g_provider *p
newpp->mediasize = pp->mediasize;
newpp->sectorsize = pp->sectorsize;
newpp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
LIST_FOREACH(gap, &pp->aliases, ga_next)
g_provider_add_alias(newpp, "%s%s", gap->ga_alias, G_MOUNTVER_SUFFIX);
if ((pp->flags & G_PF_ACCEPT_UNMAPPED) != 0) {
G_MOUNTVER_DEBUG(0, "Unmapped supported for %s.", gp->name);

View File

@ -346,6 +346,7 @@ g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
struct g_geom *gp;
struct g_provider *newpp;
struct g_consumer *cp;
struct g_geom_alias *gap;
char name[64];
int error, n;
off_t explicitsize;
@ -458,6 +459,8 @@ g_nop_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp,
newpp->sectorsize = secsize;
newpp->stripesize = stripesize;
newpp->stripeoffset = stripeoffset;
LIST_FOREACH(gap, &pp->aliases, ga_next)
g_provider_add_alias(newpp, "%s%s", gap->ga_alias, G_NOP_SUFFIX);
cp = g_new_consumer(gp);
cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;

View File

@ -481,24 +481,25 @@ g_part_new_provider(struct g_geom *gp, struct g_part_table *table,
entry->gpe_offset = offset;
if (entry->gpe_pp == NULL) {
/*
* Add aliases to the geom before we create the provider so that
* geom_dev can taste it with all the aliases in place so all
* the aliased dev_t instances get created for each partition
* (eg foo5p7 gets created for bar5p7 when foo is an alias of bar).
*/
LIST_FOREACH(gap, &table->gpt_gp->aliases, ga_next) {
sb = sbuf_new_auto();
G_PART_FULLNAME(table, entry, sb, gap->ga_alias);
sbuf_finish(sb);
g_geom_add_alias(gp, sbuf_data(sb));
sbuf_delete(sb);
}
sb = sbuf_new_auto();
G_PART_FULLNAME(table, entry, sb, gp->name);
sbuf_finish(sb);
entry->gpe_pp = g_new_providerf(gp, "%s", sbuf_data(sb));
sbuf_delete(sb);
/*
* If our parent provider had any aliases, then copy them to our
* provider so when geom DEV tastes things later, they will be
* there for it to create the aliases with those name used in
* place of the geom's name we use to create the provider. The
* kobj interface that generates names makes this awkward.
*/
LIST_FOREACH(gap, &pp->aliases, ga_next) {
sb = sbuf_new_auto();
G_PART_FULLNAME(table, entry, sb, gap->ga_alias);
sbuf_finish(sb);
g_provider_add_alias(entry->gpe_pp, "%s", sbuf_data(sb));
sbuf_delete(sb);
}
entry->gpe_pp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE;
entry->gpe_pp->private = entry; /* Close the circle. */
}
@ -1968,7 +1969,6 @@ g_part_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
struct g_part_entry *entry;
struct g_part_table *table;
struct root_hold_token *rht;
struct g_geom_alias *gap;
int attr, depth;
int error;
@ -1985,8 +1985,6 @@ g_part_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
* to the provider.
*/
gp = g_new_geomf(mp, "%s", pp->name);
LIST_FOREACH(gap, &pp->geom->aliases, ga_next)
g_geom_add_alias(gp, gap->ga_alias);
cp = g_new_consumer(gp);
cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
error = g_attach(cp, pp);

View File

@ -677,6 +677,7 @@ g_uzip_taste(struct g_class *mp, struct g_provider *pp, int flags)
struct g_geom *gp;
struct g_provider *pp2;
struct g_uzip_softc *sc;
struct g_geom_alias *gap;
enum {
G_UZIP = 1,
G_ULZMA,
@ -910,6 +911,8 @@ g_uzip_taste(struct g_class *mp, struct g_provider *pp, int flags)
pp2->mediasize = (off_t)sc->nblocks * sc->blksz;
pp2->stripesize = pp->stripesize;
pp2->stripeoffset = pp->stripeoffset;
LIST_FOREACH(gap, &pp->aliases, ga_next)
g_provider_add_alias(pp2, GUZ_DEV_NAME("%s"), gap->ga_alias);
g_error_provider(pp2, 0);
g_access(cp, -1, 0, 0);