Module Name: src Committed By: jdolecek Date: Tue Apr 7 14:07:01 UTC 2020
Modified Files: src/sys/arch/xen/include: xenbus.h src/sys/arch/xen/xen: xbdback_xenbus.c src/sys/arch/xen/xenbus: xenbus_client.c xenbus_probe.c Log Message: convert the node watch code to use kmem_alloc() instead of malloc() To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sys/arch/xen/include/xenbus.h cvs rdiff -u -r1.76 -r1.77 src/sys/arch/xen/xen/xbdback_xenbus.c cvs rdiff -u -r1.15 -r1.16 src/sys/arch/xen/xenbus/xenbus_client.c cvs rdiff -u -r1.43 -r1.44 src/sys/arch/xen/xenbus/xenbus_probe.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/xen/include/xenbus.h diff -u src/sys/arch/xen/include/xenbus.h:1.18 src/sys/arch/xen/include/xenbus.h:1.19 --- src/sys/arch/xen/include/xenbus.h:1.18 Tue Apr 7 13:38:50 2020 +++ src/sys/arch/xen/include/xenbus.h Tue Apr 7 14:07:01 2020 @@ -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 @@ struct xenbus_watch { /* 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 @@ int xenbus_watch_path2(struct xenbus_dev 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. Index: src/sys/arch/xen/xen/xbdback_xenbus.c diff -u src/sys/arch/xen/xen/xbdback_xenbus.c:1.76 src/sys/arch/xen/xen/xbdback_xenbus.c:1.77 --- src/sys/arch/xen/xen/xbdback_xenbus.c:1.76 Tue Apr 7 13:36:22 2020 +++ src/sys/arch/xen/xen/xbdback_xenbus.c Tue Apr 7 14:07:01 2020 @@ -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_xenbus_destroy(void *arg) 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; Index: src/sys/arch/xen/xenbus/xenbus_client.c diff -u src/sys/arch/xen/xenbus/xenbus_client.c:1.15 src/sys/arch/xen/xenbus/xenbus_client.c:1.16 --- src/sys/arch/xen/xenbus/xenbus_client.c:1.15 Tue Apr 7 13:38:50 2020 +++ src/sys/arch/xen/xenbus/xenbus_client.c Tue Apr 7 14:07:01 2020 @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: xenbus_clien #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 @@ __KERNEL_RCSID(0, "$NetBSD: xenbus_clien #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 @@ xenbus_watch_path2(struct xenbus_device 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, Index: src/sys/arch/xen/xenbus/xenbus_probe.c diff -u src/sys/arch/xen/xenbus/xenbus_probe.c:1.43 src/sys/arch/xen/xenbus/xenbus_probe.c:1.44 --- src/sys/arch/xen/xenbus/xenbus_probe.c:1.43 Tue Apr 7 13:36:22 2020 +++ src/sys/arch/xen/xenbus/xenbus_probe.c Tue Apr 7 14:07:01 2020 @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: xenbus_probe #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 @@ free_otherend_details(struct xenbus_devi 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(void *unused) 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);