Subject: making an existing feature optional (Re: CVS commit: src/sys/arch)
To: None <tech-kern@netbsd.org>
From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
List: tech-kern
Date: 08/06/2005 13:23:04
--NextPart-20050806130700-0769400
Content-Type: Text/Plain; charset=us-ascii

[moved from source-changes@]

> please let me think a little more about a way to avoid negative options.
> i guess i will just give up, tho. :-)

background:
- i want to swap support optional.  say, "options VMSWAP".
- i don't want to add negative options like "options VMNOSWAP".
  because it's confusing, IMO.
- many people don't want to edit their own kernel config files
  when they update kernel souce.  so it's better not to break
  existing kernel config files as far as possible.

proposal:
see the attached diff.
- introduce "default-options".
  (an alternative might be just to allow "options" in one_def.)
- allow duplicated "options" and "no options".
  it effectively changes the semantics of "no options XXX" from
  "undo the previous options XXX" to "disable XXX".

as a result, given "default-options VMSWAP" in conf/files,
your kernel config file can contain:
	- "options VMSWAP" to enable VMSWAP.
	- "no options VMSWAP" to disable VMSWAP.
	- nothing.  same effect as "options VMSWAP".

honestly speaking, i'm not entirely happy with this
because it can even look more messy than negative options. :)
any opinions?

YAMAMOTO Takashi

--NextPart-20050806130700-0769400
Content-Type: Text/Plain; charset=us-ascii
Content-Disposition: attachment; filename="a.diff"

? obj
Index: gram.y
===================================================================
RCS file: /cvsroot/src/usr.bin/config/gram.y,v
retrieving revision 1.1
diff -u -p -r1.1 gram.y
--- gram.y	5 Jun 2005 18:19:53 -0000	1.1
+++ gram.y	6 Aug 2005 04:01:30 -0000
@@ -104,6 +104,7 @@ static	struct nvlist *mk_ns(const char *
 %token	CHAR CINCLUDE COMPILE_WITH CONFIG
 %token	DEFFS DEFINE DEFOPT DEFPARAM DEFFLAG DEFPSEUDO DEVICE DEVCLASS DUMPS
 %token	DEVICE_MAJOR
+%token	DEFAULT_OPTIONS
 %token	ENDFILE
 %token	XFILE FILE_SYSTEM FLAGS
 %token	IDENT INCLUDE
@@ -300,6 +301,7 @@ one_def:
 	MAXPARTITIONS NUMBER		{ maxpartitions = $2.val; } |
 	MAXUSERS NUMBER NUMBER NUMBER	{ setdefmaxusers($2.val, $3.val, $4.val); } |
 	MAKEOPTIONS condmkopt_list |
+	DEFAULT_OPTIONS opt_list |
 	DEFPSEUDO devbase interface_opt attrs_opt
 					{ defdev($2, $3, $4, 1); } |
 	MAJOR '{' majorlist '}';
Index: main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/config/main.c,v
retrieving revision 1.1
diff -u -p -r1.1 main.c
--- main.c	5 Jun 2005 18:19:53 -0000	1.1
+++ main.c	6 Aug 2005 04:01:30 -0000
@@ -918,6 +918,7 @@ do_option(struct hashtab *ht, struct nvl
 	  const char *value, const char *type)
 {
 	struct nvlist *nv;
+	struct nvlist *oldnv;
 
 	/*
 	 * If a defopt'ed or defflag'ed option was enabled but without
@@ -937,14 +938,19 @@ do_option(struct hashtab *ht, struct nvl
 	}
 
 	/* oops, already got that option */
-	nvfree(nv);
-	if ((nv = ht_lookup(ht, name)) == NULL)
+	if ((oldnv = ht_lookup(ht, name)) == NULL)
 		panic("do_option");
-	if (nv->nv_str != NULL && !OPT_FSOPT(name))
-		error("already have %s `%s=%s'", type, name, nv->nv_str);
-	else
-		error("already have %s `%s'", type, name);
-	return (1);
+	if (vflag) {
+		if (oldnv->nv_str != NULL && !OPT_FSOPT(name)) {
+			warn("already have %s `%s=%s'", type, name,
+			    oldnv->nv_str);
+		} else {
+			warn("already have %s `%s'", type, name);
+		}
+	}
+	oldnv->nv_str = nv->nv_str;
+	nvfree(nv);
+	return (0);
 }
 
 /*
@@ -958,8 +964,10 @@ undo_option(struct hashtab *ht, struct n
 	struct nvlist *nv;
 	
 	if (ht_remove(ht, name)) {
-		error("%s `%s' is not defined", type, name);
-		return (1);
+		if (vflag) {
+			warn("%s `%s' is not defined", type, name);
+		}
+		return (0);
 	}
 	if (npp == NULL)
 		return (0);
Index: scan.l
===================================================================
RCS file: /cvsroot/src/usr.bin/config/scan.l,v
retrieving revision 1.1
diff -u -p -r1.1 scan.l
--- scan.l	5 Jun 2005 18:19:53 -0000	1.1
+++ scan.l	6 Aug 2005 04:01:30 -0000
@@ -93,6 +93,7 @@ deffs		return DEFFS;
 define		return DEFINE;
 defflag		return DEFFLAG;
 defopt		return DEFOPT;
+default-options	return DEFAULT_OPTIONS;
 defparam	return DEFPARAM;
 defpseudo	return DEFPSEUDO;
 devclass	return DEVCLASS;

--NextPart-20050806130700-0769400--