diff mbox

xen: remove xenstore watches of backends when terminating qemu

Message ID 1468413065-10299-1-git-send-email-jgross@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jürgen Groß July 13, 2016, 12:31 p.m. UTC
Xenstore watches of the /local/domain/<dom>/backend/<type> directories
are never removed. This can lead to a memory leak in xenstored,
especially when xenstored is running in another domain (this will be
the case either for a system with xenstore-stubdom, or with driver
domains running qemu-based backends).

Avoid this problem by calling xs_unwatch() for these directories when
terminating qemu.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 hw/xen/xen_backend.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

Comments

Jürgen Groß July 14, 2016, 9:58 a.m. UTC | #1
On 13/07/16 14:31, Juergen Gross wrote:
> Xenstore watches of the /local/domain/<dom>/backend/<type> directories
> are never removed. This can lead to a memory leak in xenstored,
> especially when xenstored is running in another domain (this will be
> the case either for a system with xenstore-stubdom, or with driver
> domains running qemu-based backends).
> 
> Avoid this problem by calling xs_unwatch() for these directories when
> terminating qemu.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Please ignore this patch. It is not needed. The issue in xenstored is
_not_ due to not removed watches, but due to non freed memory after
sending a watch event.


Juergen
diff mbox

Patch

diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index bab79b1..6413475 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -52,6 +52,13 @@  struct xs_dirs {
 };
 static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup =
     QTAILQ_HEAD_INITIALIZER(xs_cleanup);
+struct xs_watches {
+    char path[XEN_BUFSIZE];
+    char token[XEN_BUFSIZE];
+    QTAILQ_ENTRY(xs_watches) list;
+};
+static QTAILQ_HEAD(xs_watches_head, xs_watches) xs_w_cleanup =
+    QTAILQ_HEAD_INITIALIZER(xs_w_cleanup);
 
 static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs);
 static int debug = 0;
@@ -70,10 +77,14 @@  static void xenstore_cleanup_dir(char *dir)
 void xen_config_cleanup(void)
 {
     struct xs_dirs *d;
+    struct xs_watches *w;
 
     QTAILQ_FOREACH(d, &xs_cleanup, list) {
         xs_rm(xenstore, 0, d->xs_dir);
     }
+    QTAILQ_FOREACH(w, &xs_w_cleanup, list) {
+        xs_unwatch(xenstore, w->path, w->token);
+    }
 }
 
 int xenstore_write_str(const char *base, const char *node, const char *val)
@@ -629,20 +640,25 @@  void xen_be_check_state(struct XenDevice *xendev)
 static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops)
 {
     struct XenDevice *xendev;
-    char path[XEN_BUFSIZE], token[XEN_BUFSIZE];
+    struct xs_watches *w;
     char **dev = NULL;
     unsigned int cdev, j;
 
     /* setup watch */
-    snprintf(token, sizeof(token), "be:%p:%d:%p", type, dom, ops);
-    snprintf(path, sizeof(path), "backend/%s/%d", type, dom);
-    if (!xs_watch(xenstore, path, token)) {
-        xen_be_printf(NULL, 0, "xen be: watching backend path (%s) failed\n", path);
+    w = g_malloc(sizeof(*w));
+
+    snprintf(w->token, sizeof(w->token), "be:%p:%d:%p", type, dom, ops);
+    snprintf(w->path, sizeof(w->path), "backend/%s/%d", type, dom);
+    if (!xs_watch(xenstore, w->path, w->token)) {
+        xen_be_printf(NULL, 0, "xen be: watching backend path (%s) failed\n",
+                      w->path);
+        g_free(w);
         return -1;
     }
+    QTAILQ_INSERT_TAIL(&xs_w_cleanup, w, list);
 
     /* look for backends */
-    dev = xs_directory(xenstore, 0, path, &cdev);
+    dev = xs_directory(xenstore, 0, w->path, &cdev);
     if (!dev) {
         return 0;
     }