Module Name: src Committed By: pooka Date: Mon Mar 8 10:19:15 UTC 2010
Modified Files: src/usr.bin/config: defs.h gram.y main.c pack.c scan.l sem.c sem.h Log Message: Add a highly experimental pseudo-root feature to be used in conjuction with the also-experimental ioconf keyword. pseudo-root allows to specify a root at any point in the device tree without having attachments from the actual root. For example, instead of having a config file like this: mainbus0 at root bus_a? at mainbus0 bus_b? at bus_a* device7 at bus_b? You can have one like this: pseudo-root bus_b* device7 at bus_b? This will produce the relevant ioconf.c glue for device number 7 only instead of the whole 9 yards from root. Perhaps needless to say, this can be used to generate snippets of config glue for modules and, let's not deny that my main motivation for doing this, rump components. This is part 2/3 of my modifications to config (the last part is autogenerating source file lists and component Makefiles). No strong objection from cube (after a little pressuring ;), but like he said, the implementation will most likely need some more tweaking and may not work correctly under all pseudo-root uses yet. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/usr.bin/config/defs.h cvs rdiff -u -r1.21 -r1.22 src/usr.bin/config/gram.y cvs rdiff -u -r1.40 -r1.41 src/usr.bin/config/main.c cvs rdiff -u -r1.7 -r1.8 src/usr.bin/config/pack.c cvs rdiff -u -r1.14 -r1.15 src/usr.bin/config/scan.l cvs rdiff -u -r1.33 -r1.34 src/usr.bin/config/sem.c cvs rdiff -u -r1.5 -r1.6 src/usr.bin/config/sem.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/config/defs.h diff -u src/usr.bin/config/defs.h:1.32 src/usr.bin/config/defs.h:1.33 --- src/usr.bin/config/defs.h:1.32 Wed Mar 3 13:53:22 2010 +++ src/usr.bin/config/defs.h Mon Mar 8 10:19:14 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: defs.h,v 1.32 2010/03/03 13:53:22 pooka Exp $ */ +/* $NetBSD: defs.h,v 1.33 2010/03/08 10:19:14 pooka Exp $ */ /* * Copyright (c) 1992, 1993 @@ -260,6 +260,7 @@ #define DEVI_ACTIVE 1 /* instance has an active parent */ #define DEVI_IGNORED 2 /* instance's parent has been removed */ #define DEVI_BROKEN 3 /* instance is broken (syntax error) */ + int i_pseudoroot; /* instance is pseudoroot */ /* created during packing or ioconf.c generation */ short i_collapsed; /* set => this alias no longer needed */ Index: src/usr.bin/config/gram.y diff -u src/usr.bin/config/gram.y:1.21 src/usr.bin/config/gram.y:1.22 --- src/usr.bin/config/gram.y:1.21 Wed Mar 3 13:53:22 2010 +++ src/usr.bin/config/gram.y Mon Mar 8 10:19:14 2010 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: gram.y,v 1.21 2010/03/03 13:53:22 pooka Exp $ */ +/* $NetBSD: gram.y,v 1.22 2010/03/08 10:19:14 pooka Exp $ */ /* * Copyright (c) 1992, 1993 @@ -111,7 +111,7 @@ %token XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR %token NEEDS_COUNT NEEDS_FLAG NO %token XOBJECT OBSOLETE ON OPTIONS -%token PACKAGE PLUSEQ PREFIX PSEUDO_DEVICE +%token PACKAGE PLUSEQ PREFIX PSEUDO_DEVICE PSEUDO_ROOT %token ROOT %token SOURCE %token TYPE @@ -464,6 +464,7 @@ NO CONFIG WORD { delconf($3); } | NO PSEUDO_DEVICE WORD { delpseudo($3); } | PSEUDO_DEVICE WORD npseudo { addpseudo($2, $3); } | + PSEUDO_ROOT device_instance { addpseudoroot($2); } | NO device_instance AT attachment { deldevi($2, $4); } | NO DEVICE AT attachment { deldeva($4); } | Index: src/usr.bin/config/main.c diff -u src/usr.bin/config/main.c:1.40 src/usr.bin/config/main.c:1.41 --- src/usr.bin/config/main.c:1.40 Wed Mar 3 13:56:29 2010 +++ src/usr.bin/config/main.c Mon Mar 8 10:19:14 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.40 2010/03/03 13:56:29 pooka Exp $ */ +/* $NetBSD: main.c,v 1.41 2010/03/08 10:19:14 pooka Exp $ */ /* * Copyright (c) 1992, 1993 @@ -1026,8 +1026,14 @@ { struct devi *i; + /* + * EHAMMERTOOBIG: we shouldn't check i_pseudoroot here. + * What we want by this check is them to appear non-present + * except for purposes of other devices being able to attach + * to them. + */ for (i = deva->d_ihead; i != NULL; i = i->i_asame) - if (i->i_active == DEVI_ACTIVE && + if (i->i_active == DEVI_ACTIVE && i->i_pseudoroot == 0 && (unit == WILD || unit == i->i_unit || i->i_unit == STAR)) return (1); return (0); Index: src/usr.bin/config/pack.c diff -u src/usr.bin/config/pack.c:1.7 src/usr.bin/config/pack.c:1.8 --- src/usr.bin/config/pack.c:1.7 Thu Jan 21 18:06:38 2010 +++ src/usr.bin/config/pack.c Mon Mar 8 10:19:14 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: pack.c,v 1.7 2010/01/21 18:06:38 pooka Exp $ */ +/* $NetBSD: pack.c,v 1.8 2010/03/08 10:19:14 pooka Exp $ */ /* * Copyright (c) 1992, 1993 @@ -187,7 +187,8 @@ for (i = d->d_ihead; i != NULL; i = i->i_bsame) { m = n; for (l = i; l != NULL; l = l->i_alias) { - if (l->i_active != DEVI_ACTIVE) + if (l->i_active != DEVI_ACTIVE + || i->i_pseudoroot) continue; l->i_locoff = -1; /* try to find an equivalent for l */ Index: src/usr.bin/config/scan.l diff -u src/usr.bin/config/scan.l:1.14 src/usr.bin/config/scan.l:1.15 --- src/usr.bin/config/scan.l:1.14 Wed Feb 3 21:00:49 2010 +++ src/usr.bin/config/scan.l Mon Mar 8 10:19:14 2010 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: scan.l,v 1.14 2010/02/03 21:00:49 pooka Exp $ */ +/* $NetBSD: scan.l,v 1.15 2010/03/08 10:19:14 pooka Exp $ */ /* * Copyright (c) 1992, 1993 @@ -161,6 +161,7 @@ options return OPTIONS; prefix return PREFIX; pseudo-device return PSEUDO_DEVICE; +pseudo-root return PSEUDO_ROOT; root return ROOT; source return SOURCE; type return TYPE; Index: src/usr.bin/config/sem.c diff -u src/usr.bin/config/sem.c:1.33 src/usr.bin/config/sem.c:1.34 --- src/usr.bin/config/sem.c:1.33 Sat Apr 11 12:41:10 2009 +++ src/usr.bin/config/sem.c Mon Mar 8 10:19:15 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: sem.c,v 1.33 2009/04/11 12:41:10 lukem Exp $ */ +/* $NetBSD: sem.c,v 1.34 2010/03/08 10:19:15 pooka Exp $ */ /* * Copyright (c) 1992, 1993 @@ -922,6 +922,7 @@ i->i_srcfile = yyfile; i->i_active = DEVI_ORPHAN; /* Proper analysis comes later */ i->i_level = devilevel; + i->i_pseudoroot = 0; if (unit >= d->d_umax) d->d_umax = unit + 1; return (i); @@ -1407,6 +1408,33 @@ } void +addpseudoroot(const char *name) +{ + struct devi *i; + struct deva *iba; + struct devbase *ib; + + fprintf(stderr, "WARNING: pseudo-root is an experimental feature\n"); + + i = getdevi(name); + if (i == NULL) + return; + ib = i->i_base; + iba = ib->d_ahead; /* XXX: take the first for now, revisit later */ + + i->i_atdeva = iba; + i->i_cfflags = 0; + i->i_locs = fixloc(name, &errattr, NULL); + i->i_pseudoroot = 1; + i->i_active = DEVI_ORPHAN; /* set active by kill_orphans() */ + + *iba->d_ipp = i; + iba->d_ipp = &i->i_asame; + + ht_insert(devroottab, ib->d_name, ib); +} + +void addpseudo(const char *name, int number) { struct devbase *d; Index: src/usr.bin/config/sem.h diff -u src/usr.bin/config/sem.h:1.5 src/usr.bin/config/sem.h:1.6 --- src/usr.bin/config/sem.h:1.5 Sat Feb 11 20:15:53 2006 +++ src/usr.bin/config/sem.h Mon Mar 8 10:19:15 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: sem.h,v 1.5 2006/02/11 20:15:53 cube Exp $ */ +/* $NetBSD: sem.h,v 1.6 2010/03/08 10:19:15 pooka Exp $ */ /* * Copyright (c) 1992, 1993 @@ -66,6 +66,7 @@ void deldev(const char *); void addpseudo(const char *, int); void delpseudo(const char *); +void addpseudoroot(const char *); void adddevm(const char *, int, int, struct nvlist *); int fixdevis(void); const char *ref(const char *);