Current-Users archive

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

MODULAR option and advertised semaphore support



Hi,

While testing semaphore support, i noticed that advertised support is
currently hardcoded ... which does not deals nicely with the currently
available module framework.

By example, you'll loose if you have a kernel without
P1003_1B_SEMAPHORE option, but the module cannot be loaded for
whatever reason.

The attached patch aims at making it fully dynamic, at the cost of
loading the ksem module.

njoly@lanfeust [~]> sysctl kern.posix_semaphores
kern.posix_semaphores = 200112
njoly@lanfeust [~]> modstat -n ksem
NAME             CLASS      SOURCE     REFS  SIZE     REQUIRES
ksem             misc       builtin    0     -        -
njoly@lanfeust [~]> sudo modunload ksem
njoly@lanfeust [~]> modstat -n ksem
NAME             CLASS      SOURCE     REFS  SIZE     REQUIRES
ksem             misc       builtin    -1    -        -
njoly@lanfeust [~]> sysctl kern.posix_semaphores
kern.posix_semaphores = 0
njoly@lanfeust [~]> sudo modload -f ksem
njoly@lanfeust [~]> modstat -n ksem
NAME             CLASS      SOURCE     REFS  SIZE     REQUIRES
ksem             misc       builtin    0     -        -
njoly@lanfeust [~]> sysctl kern.posix_semaphores
kern.posix_semaphores = 200112

Comment ?

-- 
Nicolas Joly

Biological Software and Databanks.
Institut Pasteur, Paris.
Index: sys/kern/init_sysctl.c
===================================================================
RCS file: /cvsroot/src/sys/kern/init_sysctl.c,v
retrieving revision 1.175
diff -u -p -r1.175 init_sysctl.c
--- sys/kern/init_sysctl.c      1 Jul 2010 02:38:30 -0000       1.175
+++ sys/kern/init_sysctl.c      5 Nov 2010 13:56:53 -0000
@@ -35,7 +35,6 @@ __KERNEL_RCSID(0, "$NetBSD: init_sysctl.
 #include "opt_sysv.h"
 #include "opt_compat_netbsd32.h"
 #include "opt_compat_netbsd.h"
-#include "opt_modular.h"
 #include "opt_sa.h"
 #include "opt_posix.h"
 #include "pty.h"
@@ -70,6 +69,7 @@ __KERNEL_RCSID(0, "$NetBSD: init_sysctl.
 #include <sys/kauth.h>
 #include <sys/ktrace.h>
 #include <sys/ksem.h>
+#include <sys/module.h>
 
 #ifdef COMPAT_NETBSD32
 #include <compat/netbsd32/netbsd32.h>
@@ -84,10 +84,10 @@ __KERNEL_RCSID(0, "$NetBSD: init_sysctl.
 
 #include <sys/cpu.h>
 
-#if defined(MODULAR) || defined(P1003_1B_SEMAPHORE)
+#if defined(P1003_1B_SEMAPHORE)
 int posix_semaphores = 200112;
 #else
-int posix_semaphores;
+int posix_semaphores = 0;
 #endif
 
 int security_setidcore_dump;
@@ -201,6 +201,7 @@ static int sysctl_doeproc(SYSCTLFN_PROTO
 static int sysctl_kern_proc_args(SYSCTLFN_PROTO);
 static int sysctl_hw_usermem(SYSCTLFN_PROTO);
 static int sysctl_hw_cnmagic(SYSCTLFN_PROTO);
+static int sysctl_kern_posix_semaphores(SYSCTLFN_PROTO);
 
 static u_int sysctl_map_flags(const u_int *, u_int);
 static void fill_kproc2(struct proc *, struct kinfo_proc2 *, bool);
@@ -644,9 +645,9 @@ SYSCTL_SETUP(sysctl_kern_setup, "sysctl 
                       CTLTYPE_INT, "posix_semaphores",
                       SYSCTL_DESCR("Version of IEEE Std 1003.1 and its "
                                    "Semaphores option to which the system "
-                                   "attempts to conform"), NULL,
-                      0, &posix_semaphores,
-                      0, CTL_KERN, KERN_POSIX_SEMAPHORES, CTL_EOL);
+                                   "attempts to conform"),
+                      sysctl_kern_posix_semaphores, 0, NULL, 0,
+                      CTL_KERN, KERN_POSIX_SEMAPHORES, CTL_EOL);
        sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
                       CTLTYPE_INT, "posix_barriers",
@@ -2810,6 +2811,20 @@ sysctl_hw_cnmagic(SYSCTLFN_ARGS)
 }
 
 /*
+ * sysctl helper routine for kern.posix_semaphores
+ */
+static int
+sysctl_kern_posix_semaphores(SYSCTLFN_ARGS)
+{
+       struct sysctlnode node = *rnode;
+
+       module_autoload("ksem", MODULE_CLASS_MISC);
+
+       node.sysctl_data = &posix_semaphores;
+       return (sysctl_lookup(SYSCTLFN_CALL(&node)));
+}
+
+/*
  * ********************************************************************
  * section 3: public helper routines that are used for more than one
  * node
Index: sys/kern/uipc_sem.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_sem.c,v
retrieving revision 1.29
diff -u -p -r1.29 uipc_sem.c
--- sys/kern/uipc_sem.c 14 Nov 2008 15:49:21 -0000      1.29
+++ sys/kern/uipc_sem.c 5 Nov 2010 13:56:53 -0000
@@ -81,6 +81,8 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v
 #define SEM_TO_ID(x)   (((x)->ks_id))
 #define SEM_HASH(id)   ((id) % SEM_HASHTBL_SIZE)
 
+extern int posix_semaphores;
+
 MODULE(MODULE_CLASS_MISC, ksem, NULL);
 
 static const struct syscall_package ksem_syscalls[] = {
@@ -850,6 +852,7 @@ ksem_fini(bool interface)
        forkhook_disestablish(ksem_fhook);
        proc_specific_key_delete(ksem_specificdata_key);
        mutex_destroy(&ksem_mutex);
+       posix_semaphores = 0;
        return 0;
 }
 
@@ -872,8 +875,10 @@ ksem_init(void)
        error = syscall_establish(NULL, ksem_syscalls);
        if (error != 0) {
                (void)ksem_fini(false);
+               return error;
        }
-       return error;
+       posix_semaphores = 200112;
+       return 0;
 }
 
 static int


Home | Main Index | Thread Index | Old Index