Source-Changes-HG archive

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

[src/trunk]: src/sys/kern group msgbuf sysctls with the msgbuf code



details:   https://anonhg.NetBSD.org/src/rev/b700437baf02
branches:  trunk
changeset: 808513:b700437baf02
user:      pooka <pooka%NetBSD.org@localhost>
date:      Wed May 20 11:17:24 2015 +0000

description:
group msgbuf sysctls with the msgbuf code
(init_sysctl.c -> subr_log.c)

diffstat:

 sys/kern/init_sysctl.c |   95 +---------------------------------------------
 sys/kern/subr_log.c    |  100 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 100 insertions(+), 95 deletions(-)

diffs (285 lines):

diff -r 8c8b00de5483 -r b700437baf02 sys/kern/init_sysctl.c
--- a/sys/kern/init_sysctl.c    Wed May 20 11:02:54 2015 +0000
+++ b/sys/kern/init_sysctl.c    Wed May 20 11:17:24 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init_sysctl.c,v 1.206 2015/05/13 01:00:16 pgoyette Exp $ */
+/*     $NetBSD: init_sysctl.c,v 1.207 2015/05/20 11:17:24 pooka Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.206 2015/05/13 01:00:16 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.207 2015/05/20 11:17:24 pooka Exp $");
 
 #include "opt_sysv.h"
 #include "opt_compat_netbsd.h"
@@ -50,7 +50,6 @@
 #include <sys/vnode.h>
 #include <sys/mount.h>
 #include <sys/namei.h>
-#include <sys/msgbuf.h>
 #include <dev/cons.h>
 #include <sys/socketvar.h>
 #include <sys/file.h>
@@ -115,7 +114,6 @@
 static int sysctl_kern_rtc_offset(SYSCTLFN_PROTO);
 static int sysctl_kern_maxproc(SYSCTLFN_PROTO);
 static int sysctl_kern_hostid(SYSCTLFN_PROTO);
-static int sysctl_msgbuf(SYSCTLFN_PROTO);
 static int sysctl_kern_defcorename(SYSCTLFN_PROTO);
 static int sysctl_kern_cptime(SYSCTLFN_PROTO);
 #if NPTY > 0
@@ -266,12 +264,6 @@
                       sysctl_root_device, 0, NULL, 0,
                       CTL_KERN, KERN_ROOT_DEVICE, CTL_EOL);
        sysctl_createv(clog, 0, NULL, NULL,
-                      CTLFLAG_PERMANENT,
-                      CTLTYPE_INT, "msgbufsize",
-                      SYSCTL_DESCR("Size of the kernel message buffer"),
-                      sysctl_msgbuf, 0, NULL, 0,
-                      CTL_KERN, KERN_MSGBUFSIZE, CTL_EOL);
-       sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
                       CTLTYPE_INT, "fsync",
                       SYSCTL_DESCR("Whether the POSIX 1003.1b File "
@@ -388,12 +380,6 @@
                       CTL_KERN, KERN_CP_TIME, CTL_EOL);
        sysctl_createv(clog, 0, NULL, NULL,
                       CTLFLAG_PERMANENT,
-                      CTLTYPE_INT, "msgbuf",
-                      SYSCTL_DESCR("Kernel message buffer"),
-                      sysctl_msgbuf, 0, NULL, 0,
-                      CTL_KERN, KERN_MSGBUF, CTL_EOL);
-       sysctl_createv(clog, 0, NULL, NULL,
-                      CTLFLAG_PERMANENT,
                       CTLTYPE_STRUCT, "consdev",
                       SYSCTL_DESCR("Console device"),
                       sysctl_consdev, 0, NULL, sizeof(dev_t),
@@ -939,83 +925,6 @@
 }
 
 /*
- * sysctl helper routine for kern.msgbufsize and kern.msgbuf. For the
- * former it merely checks the message buffer is set up. For the latter,
- * it also copies out the data if necessary.
- */
-static int
-sysctl_msgbuf(SYSCTLFN_ARGS)
-{
-       char *where = oldp;
-       size_t len, maxlen;
-       long beg, end;
-       extern kmutex_t log_lock;
-       int error;
-
-       if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
-               msgbufenabled = 0;
-               return (ENXIO);
-       }
-
-       switch (rnode->sysctl_num) {
-       case KERN_MSGBUFSIZE: {
-               struct sysctlnode node = *rnode;
-               int msg_bufs = (int)msgbufp->msg_bufs;
-               node.sysctl_data = &msg_bufs;
-               return (sysctl_lookup(SYSCTLFN_CALL(&node)));
-       }
-       case KERN_MSGBUF:
-               break;
-       default:
-               return (EOPNOTSUPP);
-       }
-
-       if (newp != NULL)
-               return (EPERM);
-
-       if (oldp == NULL) {
-               /* always return full buffer size */
-               *oldlenp = msgbufp->msg_bufs;
-               return (0);
-       }
-
-       sysctl_unlock();
-
-       /*
-        * First, copy from the write pointer to the end of
-        * message buffer.
-        */
-       error = 0;
-       mutex_spin_enter(&log_lock);
-       maxlen = MIN(msgbufp->msg_bufs, *oldlenp);
-       beg = msgbufp->msg_bufx;
-       end = msgbufp->msg_bufs;
-       mutex_spin_exit(&log_lock);
-
-       while (maxlen > 0) {
-               len = MIN(end - beg, maxlen);
-               if (len == 0)
-                       break;
-               /* XXX unlocked, but hardly matters. */
-               error = dcopyout(l, &msgbufp->msg_bufc[beg], where, len);
-               if (error)
-                       break;
-               where += len;
-               maxlen -= len;
-
-               /*
-                * ... then, copy from the beginning of message buffer to
-                * the write pointer.
-                */
-               beg = 0;
-               end = msgbufp->msg_bufx;
-       }
-
-       sysctl_relock();
-       return (error);
-}
-
-/*
  * sysctl helper routine for kern.defcorename. In the case of a new
  * string being assigned, check that it's not a zero-length string.
  * (XXX the check in -current doesn't work, but do we really care?)
diff -r 8c8b00de5483 -r b700437baf02 sys/kern/subr_log.c
--- a/sys/kern/subr_log.c       Wed May 20 11:02:54 2015 +0000
+++ b/sys/kern/subr_log.c       Wed May 20 11:17:24 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_log.c,v 1.53 2014/07/25 08:10:40 dholland Exp $   */
+/*     $NetBSD: subr_log.c,v 1.54 2015/05/20 11:17:24 pooka Exp $      */
 
 /*-
  * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_log.c,v 1.53 2014/07/25 08:10:40 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_log.c,v 1.54 2015/05/20 11:17:24 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -80,6 +80,10 @@
 #include <sys/select.h>
 #include <sys/poll.h> 
 #include <sys/intr.h>
+#include <sys/sysctl.h>
+#include <sys/ktrace.h>
+
+static int sysctl_msgbuf(SYSCTLFN_PROTO);
 
 static void    logsoftintr(void *);
 
@@ -129,12 +133,26 @@
 void
 loginit(void)
 {
+       struct sysctllog *log = NULL;
 
        mutex_init(&log_lock, MUTEX_DEFAULT, IPL_VM);
        selinit(&log_selp);
        cv_init(&log_cv, "klog");
        log_sih = softint_establish(SOFTINT_CLOCK | SOFTINT_MPSAFE,
            logsoftintr, NULL);
+
+       sysctl_createv(&log, 0, NULL, NULL,
+                      CTLFLAG_PERMANENT,
+                      CTLTYPE_INT, "msgbufsize",
+                      SYSCTL_DESCR("Size of the kernel message buffer"),
+                      sysctl_msgbuf, 0, NULL, 0,
+                      CTL_KERN, KERN_MSGBUFSIZE, CTL_EOL);
+       sysctl_createv(&log, 0, NULL, NULL,
+                      CTLFLAG_PERMANENT,
+                      CTLTYPE_INT, "msgbuf",
+                      SYSCTL_DESCR("Kernel message buffer"),
+                      sysctl_msgbuf, 0, NULL, 0,
+                      CTL_KERN, KERN_MSGBUF, CTL_EOL);
 }
 
 /*ARGSUSED*/
@@ -414,6 +432,84 @@
                mutex_spin_exit(&log_lock);
 }
 
+/*
+ * sysctl helper routine for kern.msgbufsize and kern.msgbuf. For the
+ * former it merely checks the message buffer is set up. For the latter,
+ * it also copies out the data if necessary.
+ */
+static int
+sysctl_msgbuf(SYSCTLFN_ARGS)
+{
+       char *where = oldp;
+       size_t len, maxlen;
+       long beg, end;
+       extern kmutex_t log_lock;
+       int error;
+
+       if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
+               msgbufenabled = 0;
+               return (ENXIO);
+       }
+
+       switch (rnode->sysctl_num) {
+       case KERN_MSGBUFSIZE: {
+               struct sysctlnode node = *rnode;
+               int msg_bufs = (int)msgbufp->msg_bufs;
+               node.sysctl_data = &msg_bufs;
+               return (sysctl_lookup(SYSCTLFN_CALL(&node)));
+       }
+       case KERN_MSGBUF:
+               break;
+       default:
+               return (EOPNOTSUPP);
+       }
+
+       if (newp != NULL)
+               return (EPERM);
+
+       if (oldp == NULL) {
+               /* always return full buffer size */
+               *oldlenp = msgbufp->msg_bufs;
+               return (0);
+       }
+
+       sysctl_unlock();
+
+       /*
+        * First, copy from the write pointer to the end of
+        * message buffer.
+        */
+       error = 0;
+       mutex_spin_enter(&log_lock);
+       maxlen = MIN(msgbufp->msg_bufs, *oldlenp);
+       beg = msgbufp->msg_bufx;
+       end = msgbufp->msg_bufs;
+       mutex_spin_exit(&log_lock);
+
+       while (maxlen > 0) {
+               len = MIN(end - beg, maxlen);
+               if (len == 0)
+                       break;
+               /* XXX unlocked, but hardly matters. */
+               error = copyout(&msgbufp->msg_bufc[beg], where, len);
+               ktrmibio(-1, UIO_READ, where, len, error);
+               if (error)
+                       break;
+               where += len;
+               maxlen -= len;
+
+               /*
+                * ... then, copy from the beginning of message buffer to
+                * the write pointer.
+                */
+               beg = 0;
+               end = msgbufp->msg_bufx;
+       }
+
+       sysctl_relock();
+       return (error);
+}
+
 const struct cdevsw log_cdevsw = {
        .d_open = logopen,
        .d_close = logclose,



Home | Main Index | Thread Index | Old Index