Source-Changes-HG archive

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

[src/trunk]: src/sys Rework the sysctl initialization to avoid creating new n...



details:   https://anonhg.NetBSD.org/src/rev/14b381ad05e7
branches:  trunk
changeset: 820433:14b381ad05e7
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Jan 10 00:50:57 2017 +0000

description:
Rework the sysctl initialization to avoid creating new nodes from
within the helper function.  This should avoid the "locking against
myself" error reported earlier.

diffstat:

 sys/kern/kern_history.c |  30 +++++++++++++++++++-----------
 sys/sys/kernhist.h      |   5 ++++-
 2 files changed, 23 insertions(+), 12 deletions(-)

diffs (120 lines):

diff -r 3c976b40250c -r 14b381ad05e7 sys/kern/kern_history.c
--- a/sys/kern/kern_history.c   Tue Jan 10 00:48:37 2017 +0000
+++ b/sys/kern/kern_history.c   Tue Jan 10 00:50:57 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_history.c,v 1.12 2017/01/08 19:49:25 christos Exp $        */
+/*     $NetBSD: kern_history.c,v 1.13 2017/01/10 00:50:57 pgoyette Exp $        */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_history.c,v 1.12 2017/01/08 19:49:25 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_history.c,v 1.13 2017/01/10 00:50:57 pgoyette Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kernhist.h"
@@ -77,6 +77,7 @@
  */
 
 struct kern_history_head kern_histories;
+bool kernhist_sysctl_ready = 0;
 
 int kernhist_print_enabled = 1;
 
@@ -275,20 +276,25 @@
  */
 
 /*
- * sysctl_hist_new()
+ * sysctl_kernhist_new()
  *
- *     Scan the list of histories;  for any history that does not already
- *     have a sysctl node (under kern.hist) we create a new one and record
- *     it's node number.
+ *     If the specified history (or, if no history is specified, any
+ *     history) does not already have a sysctl node (under kern.hist)
+ *     we create a new one and record it's node number.
  */
-static void
-sysctl_hist_new(void)
+void
+sysctl_kernhist_new(struct kern_history *hist)
 {
        int error;
        struct kern_history *h;
        const struct sysctlnode *rnode = NULL;
 
+       if (kernhist_sysctl_ready == 0)
+               return;
+
        LIST_FOREACH(h, &kern_histories, list) {
+               if (hist && h != hist)
+                       continue;
                if (h->s != 0)
                        continue;
                error = sysctl_createv(NULL, 0, NULL, &rnode,
@@ -299,6 +305,8 @@
                            CTL_KERN, sysctl_hist_node, CTL_CREATE, CTL_EOL);
                if (error == 0)
                        h->s = rnode->sysctl_num;
+               if (hist == h)
+                       break;
        }
 }
 
@@ -320,7 +328,9 @@
                        CTL_KERN, CTL_CREATE, CTL_EOL);
        sysctl_hist_node = rnode->sysctl_num;
 
-       sysctl_hist_new();
+       kernhist_sysctl_ready = 1;
+
+       sysctl_kernhist_new(NULL);
 }
 
 /*
@@ -386,8 +396,6 @@
        int i, j;
        int error;
 
-       sysctl_hist_new();      /* make sure we're up to date */
-
        if (namelen == 1 && name[0] == CTL_QUERY)
                return sysctl_query(SYSCTLFN_CALL(rnode));
 
diff -r 3c976b40250c -r 14b381ad05e7 sys/sys/kernhist.h
--- a/sys/sys/kernhist.h        Tue Jan 10 00:48:37 2017 +0000
+++ b/sys/sys/kernhist.h        Tue Jan 10 00:50:57 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kernhist.h,v 1.17 2017/01/05 03:40:33 pgoyette Exp $   */
+/*     $NetBSD: kernhist.h,v 1.18 2017/01/10 00:50:57 pgoyette Exp $   */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -157,6 +157,7 @@
                kmem_zalloc(sizeof(struct kern_history_ent) * (N), KM_SLEEP); \
        (NAME).s = 0; \
        LIST_INSERT_HEAD(&kern_histories, &(NAME), list); \
+       sysctl_kernhist_new(&(NAME)); \
 } while (/*CONSTCOND*/ 0)
 
 #define KERNHIST_INITIALIZER(NAME,BUF) \
@@ -183,6 +184,7 @@
        (NAME).s = 0; \
        memset((NAME).e, 0, sizeof(struct kern_history_ent) * (NAME).n); \
        KERNHIST_LINK_STATIC(NAME); \
+       sysctl_kernhist_new(&(NAME)); \
 } while (/*CONSTCOND*/ 0)
 
 #ifndef KERNHIST_DELAY
@@ -271,6 +273,7 @@
 #endif /* DDB */
 
 void sysctl_kernhist_init(void);
+void sysctl_kernhist_new(struct kern_history *);
 
 #endif /* KERNHIST */
 



Home | Main Index | Thread Index | Old Index