Author: imp
Date: Mon Aug  7 21:12:28 2017
New Revision: 322196
URL: https://svnweb.freebsd.org/changeset/base/322196

Log:
  Add aliasing concept to geom.
  
  Add an alias name list to geoms. Use them in geom_dev to create
  aliases. Previously, geom_dev would create an device node for the name
  of the geom. Now, additional nodes are created pointing back to the
  primary node with make_dev_alias_p. Aliases must be in place on the
  geom before any tasting occurs.
  
  Differential Revision: https://reviews.freebsd.org/D11873

Modified:
  head/sys/geom/geom.h
  head/sys/geom/geom_dev.c
  head/sys/geom/geom_dump.c
  head/sys/geom/geom_subr.c

Modified: head/sys/geom/geom.h
==============================================================================
--- head/sys/geom/geom.h        Mon Aug  7 19:56:09 2017        (r322195)
+++ head/sys/geom/geom.h        Mon Aug  7 21:12:28 2017        (r322196)
@@ -120,6 +120,15 @@ 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
@@ -150,6 +159,7 @@ struct g_geom {
        unsigned                flags;
 #define        G_GEOM_WITHER           1
 #define        G_GEOM_VOLATILE_BIO     2
+       LIST_HEAD(,g_geom_alias) aliases;
 };
 
 /*
@@ -269,6 +279,7 @@ 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,

Modified: head/sys/geom/geom_dev.c
==============================================================================
--- head/sys/geom/geom_dev.c    Mon Aug  7 19:56:09 2017        (r322195)
+++ head/sys/geom/geom_dev.c    Mon Aug  7 21:12:28 2017        (r322196)
@@ -315,10 +315,11 @@ static struct g_geom *
 g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
 {
        struct g_geom *gp;
+       struct g_geom_alias *gap;
        struct g_consumer *cp;
        struct g_dev_softc *sc;
        int error;
-       struct cdev *dev;
+       struct cdev *dev, *adev;
        char buf[SPECNAMELEN + 6];
 
        g_trace(G_T_TOPOLOGY, "dev_taste(%s,%s)", mp->name, pp->name);
@@ -357,6 +358,23 @@ g_dev_taste(struct g_class *mp, struct g_provider *pp,
        g_dev_attrchanged(cp, "GEOM::physpath");
        snprintf(buf, sizeof(buf), "cdev=%s", gp->name);
        devctl_notify_f("GEOM", "DEV", "CREATE", buf, M_WAITOK);
+       /*
+        * Now add all the aliases for this drive
+        */
+       LIST_FOREACH(gap, &pp->geom->aliases, ga_next) {
+               error = make_dev_alias_p(MAKEDEV_CHECKNAME | MAKEDEV_WAITOK, 
&adev, dev,
+                   "%s", gap->ga_alias);
+               if (error) {
+                       printf("%s: make_dev_alias_p() failed (name=%s, 
error=%d)\n",
+                           __func__, gap->ga_alias, error);
+                       continue;
+               }
+               adev->si_flags |= SI_UNMAPPED;
+               adev->si_iosize_max = dev->si_iosize_max;
+               adev->si_drv2 = dev->si_drv2;
+               snprintf(buf, sizeof(buf), "cdev=%s", gap->ga_alias);
+               devctl_notify_f("GEOM", "DEV", "CREATE", buf, M_WAITOK);
+       }
 
        return (gp);
 }

Modified: head/sys/geom/geom_dump.c
==============================================================================
--- head/sys/geom/geom_dump.c   Mon Aug  7 19:56:09 2017        (r322195)
+++ head/sys/geom/geom_dump.c   Mon Aug  7 21:12:28 2017        (r322196)
@@ -234,6 +234,7 @@ g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct
 {
        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);
@@ -258,6 +259,11 @@ g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct
                if (pp != NULL && pp != pp2)
                        continue;
                g_conf_provider(sb, pp2);
+       }
+       LIST_FOREACH(gap, &gp->aliases, ga_next) {
+               sbuf_printf(sb, "      <alias>\n");
+               g_conf_printf_escaped(sb, "%s", gap->ga_alias);
+               sbuf_printf(sb, "      </alias>\n");
        }
        sbuf_printf(sb, "    </geom>\n");
 }

Modified: head/sys/geom/geom_subr.c
==============================================================================
--- head/sys/geom/geom_subr.c   Mon Aug  7 19:56:09 2017        (r322195)
+++ head/sys/geom/geom_subr.c   Mon Aug  7 21:12:28 2017        (r322196)
@@ -347,6 +347,7 @@ 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));
@@ -367,6 +368,7 @@ 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);
@@ -380,6 +382,8 @@ 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);
 }
@@ -1210,6 +1214,18 @@ g_compare_names(const char *namea, const char *nameb)
        if (strcmp(namea + deva, nameb + devb) == 0)
                return (1);
        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)
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to