Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Overhaul the way parent attachments are specified; instead o...



details:   https://anonhg.NetBSD.org/src/rev/7fc33bdf3cee
branches:  trunk
changeset: 537049:7fc33bdf3cee
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Sep 26 04:07:35 2002 +0000

description:
Overhaul the way parent attachments are specified; instead of using
a vector of indices into the cfdata table to specify potential parents,
record the interface attributes that devices have and add a new "parent
spec" structure which lists the iattr, as well as optionally listing
specific parent device instances.

See:

    http://mail-index.netbsd.org/tech-kern/2002/09/25/0014.html

...for a detailed description.

While here, const poison some things, as suggested by Matt Thomas.

diffstat:

 sys/kern/subr_autoconf.c   |   88 +++++++++++++---
 sys/kern/subr_userconf.c   |   24 ++--
 sys/kern/vfs_init.c        |    6 +-
 sys/sys/device.h           |   20 +++-
 usr.sbin/config/defs.h     |   32 +++--
 usr.sbin/config/main.c     |   23 ++-
 usr.sbin/config/mkioconf.c |  148 ++++++++++++++++++--------
 usr.sbin/config/pack.c     |  245 +++-----------------------------------------
 usr.sbin/config/sem.c      |   51 ++++++++-
 9 files changed, 303 insertions(+), 334 deletions(-)

diffs (truncated from 1211 to 300 lines):

diff -r 06b96824ac7c -r 7fc33bdf3cee sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Thu Sep 26 03:25:29 2002 +0000
+++ b/sys/kern/subr_autoconf.c  Thu Sep 26 04:07:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.65 2002/09/23 23:16:06 thorpej Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.66 2002/09/26 04:07:35 thorpej Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -81,7 +81,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.65 2002/09/23 23:16:06 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.66 2002/09/26 04:07:35 thorpej Exp $");
 
 #include "opt_ddb.h"
 
@@ -222,6 +222,58 @@
 }
 
 /*
+ * Determine if `parent' is a potential parent for a device spec based
+ * on `cfp'.
+ */
+static int
+cfparent_match(struct device *parent, const struct cfparent *cfp)
+{
+       struct cfdriver *pcd = parent->dv_cfdata->cf_driver;
+       const char * const *cpp;
+       const char *cp;
+
+       /*
+        * First, ensure this parent has the correct interface
+        * attribute.
+        */
+       if (pcd->cd_attrs == NULL)
+               return (0);     /* no interface attributes -> no children */
+       for (cpp = pcd->cd_attrs; (cp = *cpp) != NULL; cpp++) {
+               if (cp[0] == cfp->cfp_iattr[0] &&
+                   strcmp(cp, cfp->cfp_iattr) == 0) {
+                       /* Match. */
+                       break;
+               }
+       }
+       if (cp == NULL)
+               return (0);     /* doesn't carry the req'd attribute */
+
+       /*
+        * If no specific parent device instance was specified (i.e.
+        * we're attaching to the attribute only), we're done!
+        */
+       if (cfp->cfp_parent == NULL)
+               return (1);
+
+       /*
+        * Check the parent device's name.
+        */
+       if (pcd->cd_name[0] != cfp->cfp_parent[0] ||
+           strcmp(pcd->cd_name, cfp->cfp_parent) != 0)
+               return (0);     /* not the same parent */
+
+       /*
+        * Make sure the unit number matches.
+        */
+       if (cfp->cfp_unit == -1 ||      /* wildcard */
+           cfp->cfp_unit == parent->dv_unit)
+               return (1);
+
+       /* Unit numbers don't match. */
+       return (0);
+}
+
+/*
  * Iterate over all potential children of some device, calling the given
  * function (default being the child's match function) for each one.
  * Nonzero returns are matches; the highest value returned is considered
@@ -237,7 +289,6 @@
 {
        struct cftable *ct;
        struct cfdata *cf;
-       short *p;
        struct matchinfo m;
 
        m.fn = fn;
@@ -258,9 +309,8 @@
                        if (cf->cf_fstate == FSTATE_DNOTFOUND ||
                            cf->cf_fstate == FSTATE_DSTAR)
                                continue;
-                       for (p = cf->cf_parents; *p >= 0; p++)
-                               if (parent->dv_cfdata == &(ct->ct_cfdata)[*p])
-                                       mapply(&m, cf);
+                       if (cfparent_match(parent, cf->cf_pspec))
+                               mapply(&m, cf);
                }
        }
        return (m.match);
@@ -404,6 +454,7 @@
        ca = cf->cf_attach;
        if (ca->ca_devsize < sizeof(struct device))
                panic("config_attach");
+
 #ifndef __BROKEN_CONFIG_UNIT_USAGE
        if (cf->cf_fstate == FSTATE_STAR) {
                for (myunit = cf->cf_unit; myunit < cd->cd_ndevs; myunit++)
@@ -415,15 +466,18 @@
                 */
        } else {
                myunit = cf->cf_unit;
-#else /* __BROKEN_CONFIG_UNIT_USAGE */
+               KASSERT(cf->cf_fstate == FSTATE_NOTFOUND);
+               cf->cf_fstate = FSTATE_FOUND;
+       }
+#else
        myunit = cf->cf_unit;
        if (cf->cf_fstate == FSTATE_STAR)
                cf->cf_unit++;
        else {
-#endif /* __BROKEN_CONFIG_UNIT_USAGE */
                KASSERT(cf->cf_fstate == FSTATE_NOTFOUND);
                cf->cf_fstate = FSTATE_FOUND;
        }
+#endif /* ! __BROKEN_CONFIG_UNIT_USAGE */
 
        /* compute length of name and decimal expansion of unit number */
        lname = strlen(cd->cd_name);
@@ -465,9 +519,6 @@
         * Before attaching, clobber any unfound devices that are
         * otherwise identical.
         */
-#ifdef __BROKEN_CONFIG_UNIT_USAGE
-       /* bump the unit number on all starred cfdata for this device. */
-#endif /* __BROKEN_CONFIG_UNIT_USAGE */
        TAILQ_FOREACH(ct, &allcftables, ct_list) {
                for (cf = ct->ct_cfdata; cf->cf_driver; cf++) {
                        if (cf->cf_driver == cd &&
@@ -475,6 +526,10 @@
                                if (cf->cf_fstate == FSTATE_NOTFOUND)
                                        cf->cf_fstate = FSTATE_FOUND;
 #ifdef __BROKEN_CONFIG_UNIT_USAGE
+                               /*
+                                * Bump the unit number on all starred cfdata
+                                * entries for this device.
+                                */
                                if (cf->cf_fstate == FSTATE_STAR)
                                        cf->cf_unit++;
 #endif /* __BROKEN_CONFIG_UNIT_USAGE */
@@ -570,12 +625,6 @@
        /*
         * Mark cfdata to show that the unit can be reused, if possible.
         */
-#ifdef __BROKEN_CONFIG_UNIT_USAGE
-       /*
-        * Note that we can only re-use a starred unit number if the unit
-        * being detached had the last assigned unit number.
-        */
-#endif /* __BROKEN_CONFIG_UNIT_USAGE */
        TAILQ_FOREACH(ct, &allcftables, ct_list) {
                for (cf = ct->ct_cfdata; cf->cf_driver; cf++) {
                        if (cf->cf_driver == cd) {
@@ -583,6 +632,11 @@
                                    cf->cf_unit == dev->dv_unit)
                                        cf->cf_fstate = FSTATE_NOTFOUND;
 #ifdef __BROKEN_CONFIG_UNIT_USAGE
+                               /*
+                                * Note that we can only re-use a starred
+                                * unit number if the unit being detached
+                                * had the last assigned unit number.
+                                */
                                if (cf->cf_fstate == FSTATE_STAR &&
                                    cf->cf_unit == dev->dv_unit + 1)
                                        cf->cf_unit--;
diff -r 06b96824ac7c -r 7fc33bdf3cee sys/kern/subr_userconf.c
--- a/sys/kern/subr_userconf.c  Thu Sep 26 03:25:29 2002 +0000
+++ b/sys/kern/subr_userconf.c  Thu Sep 26 04:07:35 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_userconf.c,v 1.6 2002/09/23 05:51:11 simonb Exp $ */
+/*     $NetBSD: subr_userconf.c,v 1.7 2002/09/26 04:07:35 thorpej Exp $        */
 
 /*
  * Copyright (c) 1996 Mats O Jansson <moj%stacken.kth.se@localhost>
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_userconf.c,v 1.6 2002/09/23 05:51:11 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_userconf.c,v 1.7 2002/09/26 04:07:35 thorpej Exp $");
 
 #include "opt_userconf.h"
 
@@ -227,9 +227,9 @@
        short devno;
 {
        struct cfdata *cd;
-       short *p;
+       const struct cfparent *cfp;
        int   *l;
-       const char **ln;
+       const char * const *ln;
        char c;
 
        if (devno > userconf_maxdev) {
@@ -243,14 +243,14 @@
        userconf_pdevnam(devno);
        printf(" at");
        c = ' ';
-       p = cd->cf_parents;
-       if (*p == -1)
+       cfp = cd->cf_pspec;
+       if (cfp == NULL)
                printf(" root");
-       while (*p != -1) {
-               printf("%c", c);
-               userconf_pdevnam(*p++);
-               c = '|';
-       }
+       else if (cfp->cfp_parent != NULL && cfp->cfp_unit != -1)
+               printf(" %s%d", cfp->cfp_parent, cfp->cfp_unit);
+       else
+               printf(" %s?", cfp->cfp_parent != NULL ? cfp->cfp_parent
+                                                      : cfp->cfp_iattr);
        switch (cd->cf_fstate) {
        case FSTATE_NOTFOUND:
        case FSTATE_FOUND:
@@ -397,7 +397,7 @@
        char c = '\0';
        int   *l;
        int   ln;
-       const char **locnames;
+       const char * const *locnames;
 
        if (devno <=  userconf_maxdev) {
 
diff -r 06b96824ac7c -r 7fc33bdf3cee sys/kern/vfs_init.c
--- a/sys/kern/vfs_init.c       Thu Sep 26 03:25:29 2002 +0000
+++ b/sys/kern/vfs_init.c       Thu Sep 26 04:07:35 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_init.c,v 1.21 2002/03/08 20:48:42 thorpej Exp $    */
+/*     $NetBSD: vfs_init.c,v 1.22 2002/09/26 04:07:35 thorpej Exp $    */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_init.c,v 1.21 2002/03/08 20:48:42 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_init.c,v 1.22 2002/09/26 04:07:35 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/mount.h>
@@ -323,7 +323,7 @@
 void
 vfsinit()
 {
-       extern struct vfsops *vfs_list_initial[];
+       extern struct vfsops * const vfs_list_initial[];
        int i;
 
        /*
diff -r 06b96824ac7c -r 7fc33bdf3cee sys/sys/device.h
--- a/sys/sys/device.h  Thu Sep 26 03:25:29 2002 +0000
+++ b/sys/sys/device.h  Thu Sep 26 04:07:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.50 2002/09/23 23:16:07 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.51 2002/09/26 04:07:36 thorpej Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -162,6 +162,19 @@
     }
 
 /*
+ * Description of a configuration parent.  Each device attachment attaches
+ * to an "interface attribute", which is given in this structure.  The parent
+ * *must* carry this attribute.  Optionally, an individual device instance
+ * may also specify a specific parent device instance.
+ */
+struct cfparent {
+       const char *cfp_iattr;          /* interface attribute */
+       const char *cfp_parent;         /* optional specific parent */
+       int cfp_unit;                   /* optional specific unit
+                                          (-1 to wildcard) */
+};
+
+/*
  * Configuration data (i.e., data placed in ioconf.c).
  */
 struct cfdata {
@@ -171,8 +184,8 @@
        short   cf_fstate;              /* finding state (below) */
        int     *cf_loc;                /* locators (machine dependent) */
        int     cf_flags;               /* flags from config */
-       short   *cf_parents;            /* potential parents */
-       const char **cf_locnames;       /* locator names (machine dependent) */
+       const struct cfparent *cf_pspec;/* parent specification */
+       const char * const *cf_locnames;/* locator names (machine dependent) */
 };
 #define FSTATE_NOTFOUND                0       /* has not been found */
 #define        FSTATE_FOUND            1       /* has been found */



Home | Main Index | Thread Index | Old Index