tech-kern archive

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

Move boottime50 and related sysctl to compat module?



Currently, even though it is conditionalized on COMPAT_50, boottime50 (and the related kern.oboottime sysctl variable) are built only within the kernel. Therefore, a modular kernel that does not include COMPAT_50 cannot access these values, even if the compat module is loaded. See PR/47579

The attached diffs move all parts of boottime50 into the compat module code. I would appreciate reviews and comments. I'd like to get this committed in the next week or so, unless there are some substantial objections.



-------------------------------------------------------------------------
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:       |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com    |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |                          | pgoyette at netbsd.org  |
-------------------------------------------------------------------------
Index: compat_mod.h
--- /dev/null   2013-02-19 20:39:42.000000000 -0800
+++ compat_mod.h        2013-02-19 20:47:02.000000000 -0800
@@ -0,0 +1,41 @@
+/*     $NetBSD$        */
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef        _COMPAT_MOD_H
+#define        _COMPAT_MOD_H
+
+void compat_sysctl_init(void);
+void compat_sysctl_fini(void);
+
+void compat_sysctl_time(struct sysctllog **);
+void compat_sysctl_vfs(struct sysctllog **);
+
+#endif /* !_COMPAT_MOD_H_ */
Index: compat_mod.c
===================================================================
RCS file: /cvsroot/src/sys/compat/common/compat_mod.c,v
retrieving revision 1.15
diff -u -p -r1.15 compat_mod.c
--- compat_mod.c        22 Jan 2013 01:47:20 -0000      1.15
+++ compat_mod.c        20 Feb 2013 04:49:07 -0000
@@ -52,12 +52,18 @@ __KERNEL_RCSID(0, "$NetBSD: compat_mod.c
 #include <sys/syscall.h>
 #include <sys/syscallargs.h>
 #include <sys/syscallvar.h>
+#include <sys/sysctl.h>
 
 #include <uvm/uvm_extern.h>
 #include <uvm/uvm_object.h>
 
 #include <compat/common/compat_util.h>
+#include <compat/common/compat_mod.h>
 
+#if defined(COMPAT_09) || defined(COMPAT_43) || defined(COMPAT_50)
+static struct sysctllog *compat_clog = NULL;
+#endif
+ 
 MODULE(MODULE_CLASS_MISC, compat, NULL);
 
 int    ttcompat(struct tty *, u_long, void *, int, struct lwp *);
@@ -240,6 +246,9 @@ static const struct syscall_package comp
        { 0, 0, NULL },
 };
 
+#if defined(COMPAT_09) || defined(COMPAT_43) || defined(COMPAT_50)
+#endif
+
 static int
 compat_modcmd(modcmd_t cmd, void *arg)
 {
@@ -270,9 +279,7 @@ compat_modcmd(modcmd_t cmd, void *arg)
                sendsig_sigcontext_vec = sendsig_sigcontext;
 #endif
 #endif
-#if defined(COMPAT_09) || defined(COMPAT_43)
                compat_sysctl_init();
-#endif
                return 0;
 
        case MODULE_CMD_FINI:
@@ -329,12 +336,29 @@ compat_modcmd(modcmd_t cmd, void *arg)
                rw_exit(&exec_lock);
 #endif
 #endif /* COMPAT_16 */
-#if defined(COMPAT_09) || defined(COMPAT_43)
                compat_sysctl_fini();
-#endif
                return 0;
 
        default:
                return ENOTTY;
        }
 }
+
+void
+compat_sysctl_init(void)
+{
+
+#if defined(COMPAT_09) || defined(COMPAT_43)
+       compat_sysctl_vfs(&compat_clog);
+#endif
+#if defined(COMPAT_50)
+       compat_sysctl_time(&compat_clog);
+#endif
+}
+
+void
+compat_sysctl_fini(void)
+{
+ 
+        sysctl_teardown(&compat_clog);
+}
Index: compat_util.h
===================================================================
RCS file: /cvsroot/src/sys/compat/common/compat_util.h,v
retrieving revision 1.22
diff -u -p -r1.22 compat_util.h
--- compat_util.h       14 Dec 2009 04:09:38 -0000      1.22
+++ compat_util.h       20 Feb 2013 04:49:07 -0000
@@ -82,7 +82,4 @@ void compat_offseterr(struct vnode *, co
 
 int compat_elf_check_interp(struct exec_package *, char *, const char *);
 
-void compat_sysctl_init(void);
-void compat_sysctl_fini(void);
-
 #endif /* !_COMPAT_UTIL_H_ */
Index: kern_time_50.c
===================================================================
RCS file: /cvsroot/src/sys/compat/common/kern_time_50.c,v
retrieving revision 1.24
diff -u -p -r1.24 kern_time_50.c
--- kern_time_50.c      3 Nov 2012 23:22:21 -0000       1.24
+++ kern_time_50.c      20 Feb 2013 04:49:07 -0000
@@ -58,14 +58,18 @@ __KERNEL_RCSID(0, "$NetBSD: kern_time_50
 #include <sys/aio.h>
 #include <sys/poll.h>
 #include <sys/syscallargs.h>
+#include <sys/sysctl.h>
 #include <sys/resource.h>
 
 #include <compat/common/compat_util.h>
+#include <compat/common/compat_mod.h>
 #include <compat/sys/time.h>
 #include <compat/sys/timex.h>
 #include <compat/sys/resource.h>
 #include <compat/sys/clockctl.h>
 
+struct timeval50 boottime50; 
+
 int
 compat_50_sys_clock_gettime(struct lwp *l,
     const struct compat_50_sys_clock_gettime_args *uap, register_t *retval)
@@ -706,3 +710,19 @@ compat_50_sys_wait4(struct lwp *l, const
 
        return error;
 }
+
+void
+compat_sysctl_time(struct sysctllog **clog)
+{
+       struct timeval tv;
+
+       TIMESPEC_TO_TIMEVAL(&tv, &boottime);
+       timeval_to_timeval50(&tv, &boottime50);
+
+       sysctl_createv(clog, 0, NULL, NULL,
+               CTLFLAG_PERMANENT, 
+               CTLTYPE_STRUCT, "oboottime", 
+               SYSCTL_DESCR("System boot time"),
+               NULL, 0, &boottime50, sizeof(boottime50),
+               CTL_KERN, KERN_OBOOTTIME, CTL_EOL);
+}
Index: vfs_syscalls_43.c
===================================================================
RCS file: /cvsroot/src/sys/compat/common/vfs_syscalls_43.c,v
retrieving revision 1.54
diff -u -p -r1.54 vfs_syscalls_43.c
--- vfs_syscalls_43.c   19 Nov 2010 06:44:36 -0000      1.54
+++ vfs_syscalls_43.c   20 Feb 2013 04:49:07 -0000
@@ -58,6 +58,7 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls
 #include <sys/malloc.h>
 #include <sys/ioctl.h>
 #include <sys/fcntl.h>
+#include <sys/sysctl.h>
 #include <sys/syslog.h>
 #include <sys/unistd.h>
 #include <sys/resourcevar.h>
@@ -71,6 +72,7 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls
 #include <compat/sys/mount.h>
 
 #include <compat/common/compat_util.h>
+#include <compat/common/compat_mod.h>
 
 static void cvtstat(struct stat *, struct stat43 *);
 
@@ -458,7 +460,6 @@ unionread:
  * sysctl helper routine for vfs.generic.conf lookups.
  */
 #if defined(COMPAT_09) || defined(COMPAT_43) || defined(COMPAT_44)
-static struct sysctllog *compat_clog;
 
 static int
 sysctl_vfs_generic_conf(SYSCTLFN_ARGS)
@@ -498,17 +499,17 @@ sysctl_vfs_generic_conf(SYSCTLFN_ARGS)
  * Top level filesystem related information gathering.
  */
 void
-compat_sysctl_init(void)
+compat_sysctl_vfs(struct sysctllog **clog)
 {
        extern int nmountcompatnames;
 
-       sysctl_createv(&compat_clog, 0, NULL, NULL,
+       sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
                       CTLTYPE_INT, "maxtypenum",
                       SYSCTL_DESCR("Highest valid filesystem type number"),
                       NULL, nmountcompatnames, NULL, 0,
                       CTL_VFS, VFS_GENERIC, VFS_MAXTYPENUM, CTL_EOL);
-       sysctl_createv(&compat_clog, 0, NULL, NULL,
+       sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT,
                       CTLTYPE_STRUCT, "conf",
                       SYSCTL_DESCR("Filesystem configuration information"),
@@ -516,11 +517,4 @@ compat_sysctl_init(void)
                       sizeof(struct vfsconf),
                       CTL_VFS, VFS_GENERIC, VFS_CONF, CTL_EOL);
 }
-
-void
-compat_sysctl_fini(void)
-{
-
-       sysctl_teardown(&compat_clog);
-}
 #endif
Index: init_main.c
===================================================================
RCS file: /cvsroot/src/sys/kern/init_main.c,v
retrieving revision 1.446
diff -u -p -r1.446 init_main.c
--- init_main.c 9 Feb 2013 00:31:21 -0000       1.446
+++ init_main.c 20 Feb 2013 04:49:14 -0000
@@ -235,11 +235,6 @@ __KERNEL_RCSID(0, "$NetBSD: init_main.c,
 
 #include <prop/proplib.h>
 
-#ifdef COMPAT_50
-#include <compat/sys/time.h>
-struct timeval50 boottime50;
-#endif
-
 #include <sys/userconf.h>
 
 extern struct lwp lwp0;
@@ -664,13 +659,7 @@ main(void)
         */
        getnanotime(&time);
        boottime = time;
-#ifdef COMPAT_50
-       {
-               struct timeval tv;
-               TIMESPEC_TO_TIMEVAL(&tv, &time);
-               timeval_to_timeval50(&tv, &boottime50);
-       }
-#endif
+
        mutex_enter(proc_lock);
        LIST_FOREACH(p, &allproc, p_list) {
                KASSERT((p->p_flag & PK_MARKER) == 0);
Index: init_sysctl.c
===================================================================
RCS file: /cvsroot/src/sys/kern/init_sysctl.c,v
retrieving revision 1.194
diff -u -p -r1.194 init_sysctl.c
--- init_sysctl.c       2 Feb 2013 14:02:09 -0000       1.194
+++ init_sysctl.c       20 Feb 2013 04:49:14 -0000
@@ -69,10 +69,6 @@ __KERNEL_RCSID(0, "$NetBSD: init_sysctl.
 #include <sys/ktrace.h>
 #include <sys/ksem.h>
 
-#ifdef COMPAT_50
-#include <compat/sys/time.h>
-#endif
-
 #include <sys/cpu.h>
 
 int security_setidcore_dump;
@@ -328,17 +324,6 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl 
                       SYSCTL_DESCR("System boot time"),
                       NULL, 0, &boottime, sizeof(boottime),
                       CTL_KERN, KERN_BOOTTIME, CTL_EOL);
-#ifdef COMPAT_50
-       {
-               extern struct timeval50 boottime50;
-               sysctl_createv(clog, 0, NULL, NULL,
-                              CTLFLAG_PERMANENT,
-                              CTLTYPE_STRUCT, "oboottime",
-                              SYSCTL_DESCR("System boot time"),
-                              NULL, 0, &boottime50, sizeof(boottime50),
-                              CTL_KERN, KERN_OBOOTTIME, CTL_EOL);
-       }
-#endif
        sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                       CTLTYPE_STRING, "domainname",


Home | Main Index | Thread Index | Old Index