qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: qemu-devel@nongnu.org, xen-devel@lists.xensource.com
Cc: kraxel@redhat.com, sstabellini@kernel.org,
	anthony.perard@citrix.com, Juergen Gross <jgross@suse.com>
Subject: [Qemu-devel] [PATCH] xen: remove xenstore watches of backends when terminating qemu
Date: Wed, 13 Jul 2016 14:31:05 +0200	[thread overview]
Message-ID: <1468413065-10299-1-git-send-email-jgross@suse.com> (raw)

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(-)

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;
     }
-- 
2.6.6

             reply	other threads:[~2016-07-13 12:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-13 12:31 Juergen Gross [this message]
2016-07-14  9:58 ` [Qemu-devel] [Xen-devel] [PATCH] xen: remove xenstore watches of backends when terminating qemu Juergen Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468413065-10299-1-git-send-email-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=anthony.perard@citrix.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).