From patchwork Wed Jul 13 12:31:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 9227481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4A47B6075D for ; Wed, 13 Jul 2016 12:31:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3989D26A4D for ; Wed, 13 Jul 2016 12:31:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BE03271FD; Wed, 13 Jul 2016 12:31:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B2BE326A4D for ; Wed, 13 Jul 2016 12:31:30 +0000 (UTC) Received: from localhost ([::1]:47140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNJK5-0000QJ-Vq for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Jul 2016 08:31:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNJJp-0000Q9-LW for qemu-devel@nongnu.org; Wed, 13 Jul 2016 08:31:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNJJm-0008Ed-DB for qemu-devel@nongnu.org; Wed, 13 Jul 2016 08:31:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:37707) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNJJm-0008EN-6M for qemu-devel@nongnu.org; Wed, 13 Jul 2016 08:31:10 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0E6FFAC32; Wed, 13 Jul 2016 12:31:08 +0000 (UTC) From: Juergen Gross To: qemu-devel@nongnu.org, xen-devel@lists.xensource.com Date: Wed, 13 Jul 2016 14:31:05 +0200 Message-Id: <1468413065-10299-1-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH] xen: remove xenstore watches of backends when terminating qemu X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: anthony.perard@citrix.com, Juergen Gross , sstabellini@kernel.org, kraxel@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Xenstore watches of the /local/domain//backend/ 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 --- 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; }