Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/xen Make kernel command line parsing support additi...



details:   https://anonhg.NetBSD.org/src/rev/20de69e51e57
branches:  trunk
changeset: 565968:20de69e51e57
user:      cl <cl%NetBSD.org@localhost>
date:      Sat Apr 24 18:55:02 2004 +0000

description:
Make kernel command line parsing support additional keywords without
having to change existing code which calls the parser.

diffstat:

 sys/arch/xen/i386/autoconf.c    |   26 ++++---
 sys/arch/xen/i386/xen_machdep.c |  124 +++++++++++++++++++++++----------------
 sys/arch/xen/include/cpu.h      |    3 +-
 sys/arch/xen/include/xen.h      |   14 ++++-
 sys/arch/xen/xen/if_xennet.c    |   22 +++---
 5 files changed, 112 insertions(+), 77 deletions(-)

diffs (truncated from 333 to 300 lines):

diff -r bdec70487f8f -r 20de69e51e57 sys/arch/xen/i386/autoconf.c
--- a/sys/arch/xen/i386/autoconf.c      Sat Apr 24 18:24:14 2004 +0000
+++ b/sys/arch/xen/i386/autoconf.c      Sat Apr 24 18:55:02 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.c,v 1.3 2004/04/21 18:06:51 cl Exp $  */
+/*     $NetBSD: autoconf.c,v 1.4 2004/04/24 18:55:02 cl Exp $  */
 /*     NetBSD: autoconf.c,v 1.75 2003/12/30 12:33:22 pk Exp    */
 
 /*-
@@ -45,7 +45,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.3 2004/04/21 18:06:51 cl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.4 2004/04/24 18:55:02 cl Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_multiprocessor.h"
@@ -398,7 +398,7 @@
 {
        struct btinfo_bootdisk *bid;
        struct device *dv;
-       char bootdev[16]; /* sizeof(dv_xname) */
+       union xen_cmdline_parseinfo xcp;
 #ifdef COMPAT_OLDBOOT
        int i, majdev, unit, part;
        char buf[32];
@@ -477,20 +477,22 @@
                        return;
        }
 
-       xen_parse_cmdline(bootdev, NULL);
-       if (bootdev[0] == 0)
-               strcat(bootdev, "xbd0");
+       xen_parse_cmdline(XEN_PARSE_BOOTDEV, &xcp);
+       if (xcp.xcp_bootdev[0] == 0)
+               strcat(xcp.xcp_bootdev, "xbd0");
 
        for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
                if (is_valid_disk(dv) == 0)
                        continue;
 
-               if (strncmp(bootdev, dv->dv_xname, strlen(dv->dv_xname)))
+               if (strncmp(xcp.xcp_bootdev, dv->dv_xname,
+                   strlen(dv->dv_xname)))
                        continue;
 
-               if (strlen(bootdev) != strlen(dv->dv_xname)) {
+               if (strlen(xcp.xcp_bootdev) != strlen(dv->dv_xname)) {
                        booted_partition =
-                               toupper(bootdev[strlen(dv->dv_xname)]) - 'A';
+                               toupper(xcp.xcp_bootdev[strlen(dv->dv_xname)])
+                               - 'A';
                }
 
                booted_device = dv;
@@ -544,10 +546,10 @@
         */
 #ifdef XEN
        if (dev->dv_class == DV_IFNET) {
-               char bootdev[16]; /* sizeof(dv_xname) */
+               union xen_cmdline_parseinfo xcp;
 
-               xen_parse_cmdline(bootdev, NULL);
-               if (strncmp(bootdev, dev->dv_xname, 16) == 0) {
+               xen_parse_cmdline(XEN_PARSE_BOOTDEV, &xcp);
+               if (strncmp(xcp.xcp_bootdev, dev->dv_xname, 16) == 0) {
 #ifdef NFS_BOOT_BOOTSTATIC
                        nfs_bootstatic_callback = xennet_bootstatic_callback;
 #endif
diff -r bdec70487f8f -r 20de69e51e57 sys/arch/xen/i386/xen_machdep.c
--- a/sys/arch/xen/i386/xen_machdep.c   Sat Apr 24 18:24:14 2004 +0000
+++ b/sys/arch/xen/i386/xen_machdep.c   Sat Apr 24 18:55:02 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xen_machdep.c,v 1.2 2004/04/10 23:33:50 cl Exp $       */
+/*     $NetBSD: xen_machdep.c,v 1.3 2004/04/24 18:55:02 cl Exp $       */
 
 /*
  *
@@ -33,7 +33,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.2 2004/04/10 23:33:50 cl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.3 2004/04/24 18:55:02 cl Exp $");
 
 #include "opt_xen.h"
 
@@ -119,7 +119,7 @@
 }
 
 void
-xen_parse_cmdline(char *bootdev, struct xen_netinfo *xi)
+xen_parse_cmdline(int what, union xen_cmdline_parseinfo *xcp)
 {
        char *cmd_line, *opt, *s;
        int b, i, ipidx = 0;
@@ -127,69 +127,91 @@
 
        cmd_line = xen_start_info.cmd_line;
 
-       if (bootdev)
-               bootdev[0] = 0;
+       switch (what) {
+       case XEN_PARSE_BOOTDEV:
+               xcp->xcp_bootdev[0] = 0;
+               break;
+       case XEN_PARSE_CONSOLE:
+               xcp->xcp_console[0] = 0;
+               break;
+       }
 
        while (cmd_line && *cmd_line) {
                opt = cmd_line;
                cmd_line = strchr(opt, ' ');
-               if (strlen(opt) == 0)
-                       continue;
-
                if (cmd_line)
                        *cmd_line = 0;
 
-               if (bootdev && strncasecmp(opt, "bootdev=", 8) == 0)
-                       strncpy(bootdev, opt + 8, 16); /* dv_xname */
+               switch (what) {
+               case XEN_PARSE_BOOTDEV:
+                       if (strncasecmp(opt, "bootdev=", 8) == 0)
+                               strncpy(xcp->xcp_bootdev, opt + 8,
+                                   sizeof(xcp->xcp_console));
+                       break;
 
-               if (xi && xi->xi_root && strncasecmp(opt, "nfsroot=", 8) == 0)
-                       strncpy(xi->xi_root, opt + 8, MNAMELEN);
+               case XEN_PARSE_NETINFO:
+                       if (xcp->xcp_netinfo.xi_root &&
+                           strncasecmp(opt, "nfsroot=", 8) == 0)
+                               strncpy(xcp->xcp_netinfo.xi_root, opt + 8,
+                                   MNAMELEN);
 
-               if (xi && strncasecmp(opt, "ip=", 3) == 0) {
-                       memset(xi_ip, 0, sizeof(xi_ip));
-                       opt += 3;
-                       while (opt && *opt) {
-                               s = opt;
-                               opt = strchr(opt, ':');
-                               if (opt)
-                                       *opt = 0;
+                       if (strncasecmp(opt, "ip=", 3) == 0) {
+                               memset(xi_ip, 0, sizeof(xi_ip));
+                               opt += 3;
+                               ipidx = 0;
+                               while (opt && *opt) {
+                                       s = opt;
+                                       opt = strchr(opt, ':');
+                                       if (opt)
+                                               *opt = 0;
 
-                               switch (ipidx) {
-                               case 0: /* ip */
-                               case 1: /* nfs server */
-                               case 2: /* gw */
-                               case 3: /* mask */
-                               case 4: /* host */
-                                       if (*s == 0)
+                                       switch (ipidx) {
+                                       case 0: /* ip */
+                                       case 1: /* nfs server */
+                                       case 2: /* gw */
+                                       case 3: /* mask */
+                                       case 4: /* host */
+                                               if (*s == 0)
+                                                       break;
+                                               for (i = 0; i < 4; i++) {
+                                                       b = strtoul(s, &s, 10);
+                                                       xi_ip[ipidx] = b + 256
+                                                               * xi_ip[ipidx];
+                                                       if (*s != '.')
+                                                               break;
+                                                       s++;
+                                               }
+                                               if (i < 3)
+                                                       xi_ip[ipidx] = 0;
                                                break;
-                                       for (i = 0; i < 4; i++) {
-                                               b = strtoul(s, &s, 10);
-                                               xi_ip[ipidx] =
-                                                       256 * xi_ip[ipidx] + b;
-                                               if (*s != '.')
+                                       case 5: /* interface */
+                                               if (!strncmp(s, "xennet", 6))
+                                                       s += 6;
+                                               else if (!strncmp(s, "eth", 3))
+                                                       s += 3;
+                                               else
                                                        break;
-                                               s++;
+                                               if (xcp->xcp_netinfo.xi_ifno
+                                                   == strtoul(s, NULL, 10))
+                                                       memcpy(xcp->
+                                                           xcp_netinfo.xi_ip,
+                                                           xi_ip,
+                                                           sizeof(xi_ip));
+                                               break;
                                        }
-                                       if (i < 3)
-                                               xi_ip[ipidx] = 0;
-                                       break;
-                               case 5: /* interface */
-                                       if (strncmp(s, "xennet", 6) == 0)
-                                               s += 6;
-                                       else if (strncmp(s, "eth", 3) == 0)
-                                               s += 3;
-                                       else
-                                               break;
-                                       if (xi->xi_ifno == strtoul(s, NULL, 10))
-                                               memcpy(xi->xi_ip, xi_ip,
-                                                   sizeof(xi->xi_ip));
-                                       break;
+                                       ipidx++;
+
+                                       if (opt)
+                                               *opt++ = ':';
                                }
-                               ipidx++;
+                       }
 
-                               if (opt)
-                                       *opt++ = ':';
-                       }
+               case XEN_PARSE_CONSOLE:
+                       if (strncasecmp(opt, "console=", 8) == 0)
+                               strncpy(xcp->xcp_console, opt + 8,
+                                   sizeof(xcp->xcp_console));
+                       break;
+
                }
 
                if (cmd_line)
diff -r bdec70487f8f -r 20de69e51e57 sys/arch/xen/include/cpu.h
--- a/sys/arch/xen/include/cpu.h        Sat Apr 24 18:24:14 2004 +0000
+++ b/sys/arch/xen/include/cpu.h        Sat Apr 24 18:55:02 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.1 2004/03/11 21:44:08 cl Exp $       */
+/*     $NetBSD: cpu.h,v 1.2 2004/04/24 18:55:02 cl Exp $       */
 /*     NetBSD: cpu.h,v 1.113 2004/02/20 17:35:01 yamt Exp      */
 
 /*-
@@ -360,7 +360,6 @@
 void   cpu_reset(void);
 void   i386_init_pcb_tss_ldt(struct cpu_info *);
 void   i386_proc0_tss_ldt_init(void);
-void   xen_parse_cmdline(char *, struct xen_netinfo *xi);
 
 /* identcpu.c */
 extern int tmx86_has_longrun;
diff -r bdec70487f8f -r 20de69e51e57 sys/arch/xen/include/xen.h
--- a/sys/arch/xen/include/xen.h        Sat Apr 24 18:24:14 2004 +0000
+++ b/sys/arch/xen/include/xen.h        Sat Apr 24 18:55:02 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xen.h,v 1.3 2004/04/24 18:24:14 cl Exp $       */
+/*     $NetBSD: xen.h,v 1.4 2004/04/24 18:55:02 cl Exp $       */
 
 /*
  *
@@ -30,6 +30,18 @@
 
 #ifndef _LOCORE
 
+union xen_cmdline_parseinfo {
+       char                    xcp_bootdev[16]; /* sizeof(dv_xname) */
+       struct xen_netinfo      xcp_netinfo;
+       char                    xcp_console[16];
+};
+
+#define        XEN_PARSE_BOOTDEV       0
+#define        XEN_PARSE_NETINFO       1
+#define        XEN_PARSE_CONSOLE       2
+
+void   xen_parse_cmdline(int, union xen_cmdline_parseinfo *);
+
 void   xenconscn_attach(void);
 
 typedef uint16_t u16;
diff -r bdec70487f8f -r 20de69e51e57 sys/arch/xen/xen/if_xennet.c
--- a/sys/arch/xen/xen/if_xennet.c      Sat Apr 24 18:24:14 2004 +0000
+++ b/sys/arch/xen/xen/if_xennet.c      Sat Apr 24 18:55:02 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_xennet.c,v 1.6 2004/04/24 17:35:28 cl Exp $ */
+/*     $NetBSD: if_xennet.c,v 1.7 2004/04/24 18:55:02 cl Exp $ */
 
 /*
  *
@@ -33,7 +33,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_xennet.c,v 1.6 2004/04/24 17:35:28 cl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet.c,v 1.7 2004/04/24 18:55:02 cl Exp $");
 
 #include "opt_inet.h"
 



Home | Main Index | Thread Index | Old Index