* [PATCH] xen: remove xenstore watches of backends when terminating qemu
@ 2016-07-13 12:31 Juergen Gross
2016-07-14 9:58 ` [Xen-devel] " Juergen Gross
0 siblings, 1 reply; 2+ messages in thread
From: Juergen Gross @ 2016-07-13 12:31 UTC (permalink / raw)
To: qemu-devel, xen-devel; +Cc: anthony.perard, Juergen Gross, sstabellini, kraxel
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Xen-devel] [PATCH] xen: remove xenstore watches of backends when terminating qemu
2016-07-13 12:31 [PATCH] xen: remove xenstore watches of backends when terminating qemu Juergen Gross
@ 2016-07-14 9:58 ` Juergen Gross
0 siblings, 0 replies; 2+ messages in thread
From: Juergen Gross @ 2016-07-14 9:58 UTC (permalink / raw)
To: qemu-devel, xen-devel; +Cc: anthony.perard, sstabellini, kraxel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-14 9:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-13 12:31 [PATCH] xen: remove xenstore watches of backends when terminating qemu Juergen Gross
2016-07-14 9:58 ` [Xen-devel] " Juergen Gross
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).