Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/xen convert the node watch code to use kmem_alloc()...



details:   https://anonhg.NetBSD.org/src/rev/f775c5c0a587
branches:  trunk
changeset: 970942:f775c5c0a587
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Tue Apr 07 14:07:01 2020 +0000

description:
convert the node watch code to use kmem_alloc() instead of malloc()

diffstat:

 sys/arch/xen/include/xenbus.h       |   5 ++-
 sys/arch/xen/xen/xbdback_xenbus.c   |  12 +++----
 sys/arch/xen/xenbus/xenbus_client.c |  55 ++++++++++++++++--------------------
 sys/arch/xen/xenbus/xenbus_probe.c  |  19 ++++++------
 4 files changed, 43 insertions(+), 48 deletions(-)

diffs (216 lines):

diff -r afc3417868b1 -r f775c5c0a587 sys/arch/xen/include/xenbus.h
--- a/sys/arch/xen/include/xenbus.h     Tue Apr 07 13:38:50 2020 +0000
+++ b/sys/arch/xen/include/xenbus.h     Tue Apr 07 14:07:01 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus.h,v 1.18 2020/04/07 13:38:50 jdolecek Exp $ */
+/* $NetBSD: xenbus.h,v 1.19 2020/04/07 14:07:01 jdolecek Exp $ */
 /******************************************************************************
  * xenbus.h
  *
@@ -58,6 +58,7 @@
 
        /* Path being watched. */
        char *node;
+       size_t node_sz;
 
        /* Callback (executed in a process context with no locks held). */
        void (*xbw_callback)(struct xenbus_watch *,
@@ -180,6 +181,8 @@
                       void (*callback)(struct xenbus_watch *,
                                        const char **, unsigned int));
 
+/* Unregister the watch, and free associated internal structures. */
+void xenbus_unwatch_path(struct xenbus_watch *);
 
 /**
  * Advertise in the store a change of the given driver to the given new_state.
diff -r afc3417868b1 -r f775c5c0a587 sys/arch/xen/xen/xbdback_xenbus.c
--- a/sys/arch/xen/xen/xbdback_xenbus.c Tue Apr 07 13:38:50 2020 +0000
+++ b/sys/arch/xen/xen/xbdback_xenbus.c Tue Apr 07 14:07:01 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: xbdback_xenbus.c,v 1.76 2020/04/07 13:36:22 jdolecek Exp $      */
+/*      $NetBSD: xbdback_xenbus.c,v 1.77 2020/04/07 14:07:01 jdolecek Exp $      */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.76 2020/04/07 13:36:22 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xbdback_xenbus.c,v 1.77 2020/04/07 14:07:01 jdolecek Exp $");
 
 #include <sys/atomic.h>
 #include <sys/buf.h>
@@ -487,11 +487,9 @@
        xbdback_disconnect(xbdi);
 
        /* unregister watch */
-       if (xbdi->xbdi_watch.node) {
-               unregister_xenbus_watch(&xbdi->xbdi_watch);
-               free(xbdi->xbdi_watch.node, M_DEVBUF);
-               xbdi->xbdi_watch.node = NULL;
-       }
+       if (xbdi->xbdi_watch.node)
+               xenbus_unwatch_path(&xbdi->xbdi_watch);
+
        /* unmap ring */
        if (xbdi->xbdi_ring_va != 0) {
                ungrop.host_addr = xbdi->xbdi_ring_va;
diff -r afc3417868b1 -r f775c5c0a587 sys/arch/xen/xenbus/xenbus_client.c
--- a/sys/arch/xen/xenbus/xenbus_client.c       Tue Apr 07 13:38:50 2020 +0000
+++ b/sys/arch/xen/xenbus/xenbus_client.c       Tue Apr 07 14:07:01 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_client.c,v 1.15 2020/04/07 13:38:50 jdolecek Exp $ */
+/* $NetBSD: xenbus_client.c,v 1.16 2020/04/07 14:07:01 jdolecek Exp $ */
 /******************************************************************************
  * Client-facing interface for the Xenbus driver.  In other words, the
  * interface between the Xenbus and the device-specific code, be it the
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xenbus_client.c,v 1.15 2020/04/07 13:38:50 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_client.c,v 1.16 2020/04/07 14:07:01 jdolecek Exp $");
 
 #if 0
 #define DPRINTK(fmt, args...) \
@@ -42,6 +42,7 @@
 #include <sys/null.h>
 #include <sys/errno.h>
 #include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/systm.h>
 
 #include <xen/xen.h>
@@ -50,30 +51,6 @@
 #include <xen/xenbus.h>
 #include <xen/granttables.h>
 
-
-static int
-xenbus_watch_path(struct xenbus_device *dev, char *path,
-                     struct xenbus_watch *watch, 
-                     void (*callback)(struct xenbus_watch *,
-                                      const char **, unsigned int))
-{
-       int err;
-
-       watch->node = path;
-       watch->xbw_callback = callback;
-
-       err = register_xenbus_watch(watch);
-
-       if (err) {
-               watch->node = NULL;
-               watch->xbw_callback = NULL;
-               xenbus_dev_fatal(dev, err, "adding watch on %s", path);
-       }
-       err = 0;
-
-       return err;
-}
-
 int
 xenbus_watch_path2(struct xenbus_device *dev, const char *path,
                       const char *path2, struct xenbus_watch *watch, 
@@ -84,21 +61,37 @@
        char *state;
 
        DPRINTK("xenbus_watch_path2 path %s path2 %s\n", path, path2);
-       state =
-               malloc(strlen(path) + 1 + strlen(path2) + 1, M_DEVBUF,
-                   M_WAITOK);
+
+       watch->node_sz = strlen(path) + 1 + strlen(path2) + 1;
+       state = kmem_alloc(watch->node_sz, KM_SLEEP);
        strcpy(state, path);
        strcat(state, "/");
        strcat(state, path2);
 
-       err = xenbus_watch_path(dev, state, watch, callback);
+       watch->node = state;
+       watch->xbw_callback = callback;
+
+       err = register_xenbus_watch(watch);
 
        if (err) {
-               free(state, M_DEVBUF);
+               watch->node = NULL;
+               watch->node_sz = 0;
+               watch->xbw_callback = NULL;
+               xenbus_dev_fatal(dev, err, "adding watch on %s", state);
+               kmem_free(state, watch->node_sz);
        }
        return err;
 }
 
+void
+xenbus_unwatch_path(struct xenbus_watch *watch)
+{
+       if (watch->node != NULL) {
+               unregister_xenbus_watch(watch);
+               kmem_free(watch->node, watch->node_sz);
+               watch->node = NULL;
+       }
+}
 
 int
 xenbus_switch_state(struct xenbus_device *dev,
diff -r afc3417868b1 -r f775c5c0a587 sys/arch/xen/xenbus/xenbus_probe.c
--- a/sys/arch/xen/xenbus/xenbus_probe.c        Tue Apr 07 13:38:50 2020 +0000
+++ b/sys/arch/xen/xenbus/xenbus_probe.c        Tue Apr 07 14:07:01 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenbus_probe.c,v 1.43 2020/04/07 13:36:22 jdolecek Exp $ */
+/* $NetBSD: xenbus_probe.c,v 1.44 2020/04/07 14:07:01 jdolecek Exp $ */
 /******************************************************************************
  * Talks to Xen Store to figure out what devices we have.
  *
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.43 2020/04/07 13:36:22 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xenbus_probe.c,v 1.44 2020/04/07 14:07:01 jdolecek Exp $");
 
 #if 0
 #define DPRINTK(fmt, args...) \
@@ -42,6 +42,7 @@
 #include <sys/null.h>
 #include <sys/errno.h>
 #include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/systm.h>
 #include <sys/param.h>
 #include <sys/kthread.h>
@@ -232,11 +233,8 @@
 static void
 free_otherend_watch(struct xenbus_device *dev)
 {
-       if (dev->xbusd_otherend_watch.node) {
-               unregister_xenbus_watch(&dev->xbusd_otherend_watch);
-               free(dev->xbusd_otherend_watch.node, M_DEVBUF);
-               dev->xbusd_otherend_watch.node = NULL;
-       }
+       if (dev->xbusd_otherend_watch.node)
+               xenbus_unwatch_path(&dev->xbusd_otherend_watch);
 }
 
 static void
@@ -615,11 +613,14 @@
        xenbus_probe_backends();
 
        /* Watch for changes. */
-       fe_watch.node = malloc(strlen("device") + 1, M_DEVBUF, M_NOWAIT);
+       fe_watch.node_sz = strlen("device") + 1;
+       fe_watch.node = kmem_alloc(fe_watch.node_sz, KM_SLEEP);
        strcpy(fe_watch.node, "device");
        fe_watch.xbw_callback = frontend_changed;
        register_xenbus_watch(&fe_watch);
-       be_watch.node = malloc(strlen("backend") + 1, M_DEVBUF, M_NOWAIT);
+
+       be_watch.node_sz = strlen("backend") + 1;
+       be_watch.node = kmem_alloc(be_watch.node_sz, KM_SLEEP);
        strcpy(be_watch.node, "backend");
        be_watch.xbw_callback = backend_changed;
        register_xenbus_watch(&be_watch);



Home | Main Index | Thread Index | Old Index