Source-Changes-HG archive

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

[src/trunk]: src Modularize drvctl(4)



details:   https://anonhg.NetBSD.org/src/rev/e1571f37684e
branches:  trunk
changeset: 342121:e1571f37684e
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Mon Dec 07 11:38:46 2015 +0000

description:
Modularize drvctl(4)

diffstat:

 distrib/sets/lists/modules/mi    |   4 +-
 sys/kern/init_main.c             |   8 +--
 sys/kern/kern_drvctl.c           |  87 +++++++++++++++++++++++++++++++++++++--
 sys/kern/subr_autoconf.c         |  24 ++++++++--
 sys/modules/Makefile             |   3 +-
 sys/modules/drvctl/Makefile      |  11 +++++
 sys/modules/drvctl/drvctl.ioconf |   7 +++
 sys/sys/device.h                 |   3 +-
 sys/sys/devmon.h                 |   4 +-
 9 files changed, 130 insertions(+), 21 deletions(-)

diffs (truncated from 350 to 300 lines):

diff -r 7b698a5ad47c -r e1571f37684e distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi     Mon Dec 07 09:59:26 2015 +0000
+++ b/distrib/sets/lists/modules/mi     Mon Dec 07 11:38:46 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.81 2015/12/07 03:25:57 pgoyette Exp $
+# $NetBSD: mi,v 1.82 2015/12/07 11:38:46 pgoyette Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -62,6 +62,8 @@
 ./@MODULEDIR@/dk_subr/dk_subr.kmod             base-kernel-modules     kmod
 ./@MODULEDIR@/dm                               base-kernel-modules     lvm,kmod
 ./@MODULEDIR@/dm/dm.kmod                       base-kernel-modules     lvm,kmod
+./@MODULEDIR@/drvctl                           base-kernel-modules     lvm,kmod
+./@MODULEDIR@/drvctl/drvctl.kmod               base-kernel-modules     lvm,kmod
 ./@MODULEDIR@/dtrace                           base-kernel-modules     kmod,dtrace
 ./@MODULEDIR@/dtrace/dtrace.kmod               base-kernel-modules     kmod,dtrace
 ./@MODULEDIR@/dtrace_fbt                               base-kernel-modules     kmod,dtrace
diff -r 7b698a5ad47c -r e1571f37684e sys/kern/init_main.c
--- a/sys/kern/init_main.c      Mon Dec 07 09:59:26 2015 +0000
+++ b/sys/kern/init_main.c      Mon Dec 07 11:38:46 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init_main.c,v 1.475 2015/11/26 01:41:20 ozaki-r Exp $  */
+/*     $NetBSD: init_main.c,v 1.476 2015/12/07 11:38:46 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.475 2015/11/26 01:41:20 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.476 2015/12/07 11:38:46 pgoyette Exp $");
 
 #include "opt_ddb.h"
 #include "opt_inet.h"
@@ -121,7 +121,6 @@
 extern void *_binary_splash_image_end;
 #endif
 
-#include "drvctl.h"
 #include "ksyms.h"
 
 #include "veriexec.h"
@@ -713,9 +712,6 @@
        config_twiddle_init();
 
        pmf_init();
-#if NDRVCTL > 0
-       drvctl_init();
-#endif
 
        /* Initialize driver modules */
        module_init_class(MODULE_CLASS_DRIVER);
diff -r 7b698a5ad47c -r e1571f37684e sys/kern/kern_drvctl.c
--- a/sys/kern/kern_drvctl.c    Mon Dec 07 09:59:26 2015 +0000
+++ b/sys/kern/kern_drvctl.c    Mon Dec 07 11:38:46 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_drvctl.c,v 1.39 2015/08/20 09:45:45 christos Exp $ */
+/* $NetBSD: kern_drvctl.c,v 1.40 2015/12/07 11:38:46 pgoyette Exp $ */
 
 /*
  * Copyright (c) 2004
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.39 2015/08/20 09:45:45 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.40 2015/12/07 11:38:46 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -47,6 +47,7 @@
 #include <sys/stat.h>
 #include <sys/kauth.h>
 #include <sys/lwp.h>
+#include <sys/module.h>
 
 #include "ioconf.h"
 
@@ -105,6 +106,9 @@
 
 #define MAXLOCATORS 100
 
+extern int (*devmon_insert_vec)(const char *, prop_dictionary_t);
+static int (*saved_insert_vec)(const char *, prop_dictionary_t) = NULL;
+
 static int drvctl_command(struct lwp *, struct plistref *, u_long, int);
 static int drvctl_getevent(struct lwp *, struct plistref *, u_long, int);
 
@@ -118,6 +122,15 @@
 }
 
 void
+drvctl_fini(void)
+{
+
+       seldestroy(&drvctl_rdsel);
+       cv_destroy(&drvctl_cond);
+       mutex_destroy(&drvctl_lock);
+}
+
+int
 devmon_insert(const char *event, prop_dictionary_t ev)
 {
        struct drvctl_event *dce, *odce;
@@ -127,21 +140,21 @@
        if (drvctl_nopen == 0) {
                prop_object_release(ev);
                mutex_exit(&drvctl_lock);
-               return;
+               return 0;
        }
 
        /* Fill in mandatory member */
        if (!prop_dictionary_set_cstring_nocopy(ev, "event", event)) {
                prop_object_release(ev);
                mutex_exit(&drvctl_lock);
-               return;
+               return 0;
        }
 
        dce = kmem_alloc(sizeof(*dce), KM_SLEEP);
        if (dce == NULL) {
                prop_object_release(ev);
                mutex_exit(&drvctl_lock);
-               return;
+               return 0;
        }
 
        dce->dce_event = ev;
@@ -160,6 +173,7 @@
        selnotify(&drvctl_rdsel, 0, 0);
 
        mutex_exit(&drvctl_lock);
+       return 0;
 }
 
 int
@@ -580,3 +594,66 @@
 
        return ret;
 }
+
+/*
+ * Module glue
+ */
+
+MODULE(MODULE_CLASS_DRIVER, drvctl, NULL);
+
+int
+drvctl_modcmd(modcmd_t cmd, void *arg)
+{
+       int error;
+#ifdef _MODULE
+       int bmajor, cmajor;
+#endif
+
+       error = 0;
+       switch (cmd) {
+       case MODULE_CMD_INIT:
+               drvctl_init();
+
+#ifdef _MODULE
+               mutex_enter(&drvctl_lock);
+               bmajor = cmajor = -1;
+               error = devsw_attach("drvctl", NULL, &bmajor,
+                   &drvctl_cdevsw, &cmajor);
+#endif
+               if (error == 0) {
+                       KASSERT(saved_insert_vec == NULL);
+                       saved_insert_vec = devmon_insert_vec;
+                       devmon_insert_vec = devmon_insert;
+               }
+
+               mutex_exit(&drvctl_lock);
+               break;
+
+       case MODULE_CMD_FINI:
+               mutex_enter(&drvctl_lock);
+               if (drvctl_nopen != 0 || drvctl_eventcnt != 0 ) {
+                       mutex_exit(&drvctl_lock);
+                       return EBUSY;
+               }
+               KASSERT(saved_insert_vec != NULL);
+               devmon_insert_vec = saved_insert_vec;
+               saved_insert_vec = NULL;
+#ifdef _MODULE
+               error = devsw_detach(NULL, &drvctl_cdevsw);
+               if (error != 0) {
+                       saved_insert_vec = devmon_insert_vec;
+                       devmon_insert_vec = devmon_insert;
+               }
+#endif
+               mutex_exit(&drvctl_lock);
+               if (error == 0)
+                       drvctl_fini();
+
+               break;
+       default:
+               error = ENOTTY;
+               break;
+       }
+
+       return error;
+}
diff -r 7b698a5ad47c -r e1571f37684e sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Mon Dec 07 09:59:26 2015 +0000
+++ b/sys/kern/subr_autoconf.c  Mon Dec 07 11:38:46 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.236 2015/11/08 21:03:00 joerg Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.237 2015/12/07 11:38:46 pgoyette Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.236 2015/11/08 21:03:00 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.237 2015/12/07 11:38:46 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -242,6 +242,9 @@
 
 static void sysctl_detach_setup(struct sysctllog **);
 
+int no_devmon_insert(const char *, prop_dictionary_t);
+int (*devmon_insert_vec)(const char *, prop_dictionary_t) = no_devmon_insert;
+
 typedef int (*cfdriver_fn)(struct cfdriver *);
 static int
 frob_cfdrivervec(struct cfdriver * const *cfdriverv,
@@ -517,15 +520,26 @@
 /*
  * Announce device attach/detach to userland listeners.
  */
+
+int
+no_devmon_insert(const char *name, prop_dictionary_t p)
+{
+
+       return ENODEV;
+}
+
 static void
 devmon_report_device(device_t dev, bool isattach)
 {
-#if NDRVCTL > 0
        prop_dictionary_t ev;
        const char *parent;
        const char *what;
        device_t pdev = device_parent(dev);
 
+       /* If currently no drvctl device, just return */
+       if (devmon_insert_vec == no_devmon_insert)
+               return;
+
        ev = prop_dictionary_create();
        if (ev == NULL)
                return;
@@ -538,8 +552,8 @@
                return;
        }
 
-       devmon_insert(what, ev);
-#endif
+       if ((*devmon_insert_vec)(what, ev) != 0)
+               prop_object_release(ev);
 }
 
 /*
diff -r 7b698a5ad47c -r e1571f37684e sys/modules/Makefile
--- a/sys/modules/Makefile      Mon Dec 07 09:59:26 2015 +0000
+++ b/sys/modules/Makefile      Mon Dec 07 11:38:46 2015 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.163 2015/12/07 03:25:57 pgoyette Exp $
+#      $NetBSD: Makefile,v 1.164 2015/12/07 11:38:46 pgoyette Exp $
 
 .include <bsd.own.mk>
 
@@ -26,6 +26,7 @@
 SUBDIR+=       dbcool
 SUBDIR+=       des
 SUBDIR+=       dk_subr
+SUBDIR+=       drvctl
 SUBDIR+=       efs
 SUBDIR+=       ext2fs
 SUBDIR+=       exec_script
diff -r 7b698a5ad47c -r e1571f37684e sys/modules/drvctl/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/modules/drvctl/Makefile       Mon Dec 07 11:38:46 2015 +0000
@@ -0,0 +1,11 @@
+# $NetBSD: Makefile,v 1.1 2015/12/07 11:38:46 pgoyette Exp $
+
+.include "../Makefile.inc"
+
+.PATH: ${S}/kern
+



Home | Main Index | Thread Index | Old Index