From patchwork Sun Jul 10 11:47:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Condrea X-Patchwork-Id: 9222527 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 38F3260890 for ; Sun, 10 Jul 2016 11:49:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 297482521F for ; Sun, 10 Jul 2016 11:49:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D9D6264FB; Sun, 10 Jul 2016 11:49:06 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 782D72521F for ; Sun, 10 Jul 2016 11:49:05 +0000 (UTC) Received: from localhost ([::1]:54212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMDEO-00066D-GU for patchwork-qemu-devel@patchwork.kernel.org; Sun, 10 Jul 2016 07:49:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMDDf-00060U-IN for qemu-devel@nongnu.org; Sun, 10 Jul 2016 07:48:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMDDd-0001ft-5q for qemu-devel@nongnu.org; Sun, 10 Jul 2016 07:48:18 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:35730) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMDDc-0001fp-SW for qemu-devel@nongnu.org; Sun, 10 Jul 2016 07:48:17 -0400 Received: by mail-wm0-x244.google.com with SMTP id k123so13138426wme.2 for ; Sun, 10 Jul 2016 04:48:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vGm9DBcja9L+E/AyNA5saei8knUxSa1GeTGJuo0nlCA=; b=SK5dmnrYfxZTUm+PVMq18uEKZpb8GO4e4RenKuLF9gW1AxJR+SFRLm0bJo/oXn3jlw bdcJ3w0EJnaiaw35Dwe4IeEUlUc8SH60bsTRx8rGWWReTk4wLiosihGX34SeEAf+vIqo sWHcHuCDelYoYivS5taHiqZWtGn5d9yvHOY0w3UZ8JLEjuM4URgo8RY5mWoR03Jjol+l IoMFHyJrv5bC/vJPvDlVqO3jVJfs8/8O2V1rqkeGvZtWx6ww6LvZR4ITcTpe9UuiQQoj EEFx6A3EXVRBfy77fBscAruAbUdcmpRD92c4IyG3BNj7aCNroeIjZgMPHrHAmbDYypCw O6lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vGm9DBcja9L+E/AyNA5saei8knUxSa1GeTGJuo0nlCA=; b=GJqidvC750Vv4GTB4Kgi/SDlfgx+PxZITvZRWb1SVEZHJ57qPD3qbhoIlTQN3JVhva d36Jjy6dIFgzrUEYZ8MYl3lhzxeVTEpxoaBxxZD6cCY9Dp2rYVQIR9iaYtkzWzD2SOgB /11OMtuyspAVZFCrSuXX7hEsswbOM1nRyma4iPDZm1Hq9w1cGuQz7aSlEiHLoo5UsmX7 PVRNIzGLYQECG3+td/cfl2e7t8unv7g41xGgkeJ6XIQvjlp6t7luDjplJjjF0yx8pfpN oK3BO5bezZPY6lTM9HcUJ9bV/irv+xED+kBrD+onJvvMmSf4PzcjJHYLERDw7ASkaSWD i4kQ== X-Gm-Message-State: ALyK8tJH1A1M0ZP2UBr/g7NE1B0IV/xjJs8ghRvBkrUeEZv89JToWeTSX/SUZDq03kGHIg== X-Received: by 10.28.55.197 with SMTP id e188mr7215970wma.32.1468151296228; Sun, 10 Jul 2016 04:48:16 -0700 (PDT) Received: from localhost.localdomain ([79.112.8.37]) by smtp.gmail.com with ESMTPSA id d137sm6888378wmd.12.2016.07.10.04.48.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 10 Jul 2016 04:48:15 -0700 (PDT) From: Emil Condrea To: qemu-devel@nongnu.org Date: Sun, 10 Jul 2016 14:47:36 +0300 Message-Id: <1468151270-12984-6-git-send-email-emilcondrea@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468151270-12984-1-git-send-email-emilcondrea@gmail.com> References: <1468151270-12984-1-git-send-email-emilcondrea@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PATCH 05/19] xen: Prepare xendev qtail to be shared with frontends 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: wei.liu2@citrix.com, stefanb@linux.vnet.ibm.com, stefano.stabellini@eu.citrix.com, xen-devel@lists.xen.org, quan.xu@intel.com, dgdegra@tycho.nsa.gov, emilcondrea@gmail.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP * move xendevs qtail to xen_pvdev.c * change xen_be_get_xendev to use a new function: xen_pv_insert_xendev Signed-off-by: Emil Condrea --- hw/xen/xen_backend.c | 70 +--------------------------------------- hw/xen/xen_pvdev.c | 75 +++++++++++++++++++++++++++++++++++++++++++ include/hw/xen/xen_backend.h | 1 - include/hw/xen/xen_frontend.h | 2 ++ include/hw/xen/xen_pvdev.h | 4 +++ 5 files changed, 82 insertions(+), 70 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 5f2821a..2f7f1a6 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -55,7 +55,6 @@ struct xs_dirs { static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = QTAILQ_HEAD_INITIALIZER(xs_cleanup); -static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs); static int debug = 0; static void xenstore_cleanup_dir(char *dir) @@ -141,27 +140,6 @@ int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state) return 0; } -/* ------------------------------------------------------------- */ - -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) -{ - struct XenDevice *xendev; - - QTAILQ_FOREACH(xendev, &xendevs, next) { - if (xendev->dom != dom) { - continue; - } - if (xendev->dev != dev) { - continue; - } - if (strcmp(xendev->type, type) != 0) { - continue; - } - return xendev; - } - return NULL; -} - /* * get xen backend device, allocate a new one if it doesn't exist. */ @@ -210,7 +188,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->gnttabdev = NULL; } - QTAILQ_INSERT_TAIL(&xendevs, xendev, next); + xen_pv_insert_xendev(xendev); if (xendev->ops->alloc) { xendev->ops->alloc(xendev); @@ -219,52 +197,6 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, return xendev; } -/* - * release xen backend device. - */ -static struct XenDevice *xen_be_del_xendev(int dom, int dev) -{ - struct XenDevice *xendev, *xnext; - - /* - * This is pretty much like QTAILQ_FOREACH(xendev, &xendevs, next) but - * we save the next pointer in xnext because we might free xendev. - */ - xnext = xendevs.tqh_first; - while (xnext) { - xendev = xnext; - xnext = xendev->next.tqe_next; - - if (xendev->dom != dom) { - continue; - } - if (xendev->dev != dev && dev != -1) { - continue; - } - - if (xendev->ops->free) { - xendev->ops->free(xendev); - } - - if (xendev->fe) { - char token[XEN_BUFSIZE]; - snprintf(token, sizeof(token), "fe:%p", xendev); - xs_unwatch(xenstore, xendev->fe, token); - g_free(xendev->fe); - } - - if (xendev->evtchndev != NULL) { - xenevtchn_close(xendev->evtchndev); - } - if (xendev->gnttabdev != NULL) { - xengnttab_close(xendev->gnttabdev); - } - - QTAILQ_REMOVE(&xendevs, xendev, next); - g_free(xendev); - } - return NULL; -} /* * Sync internal data structures on xenstore updates. diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 7876724..042adeb 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -23,7 +23,9 @@ #include "hw/xen/xen_frontend.h" #include "hw/xen/xen_pvdev.h" +/* private */ static int debug = 0; +static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs); /* ------------------------------------------------------------- */ int xenstore_write_str(const char *base, const char *node, const char *val) @@ -206,3 +208,76 @@ int xen_be_send_notify(struct XenDevice *xendev) { return xenevtchn_notify(xendev->evtchndev, xendev->local_port); } + +/* ------------------------------------------------------------- */ + +struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) +{ + struct XenDevice *xendev; + + QTAILQ_FOREACH(xendev, &xendevs, next) { + if (xendev->dom != dom) { + continue; + } + if (xendev->dev != dev) { + continue; + } + if (strcmp(xendev->type, type) != 0) { + continue; + } + return xendev; + } + return NULL; +} + +/* + * release xen backend device. + */ +struct XenDevice *xen_be_del_xendev(int dom, int dev) +{ + struct XenDevice *xendev, *xnext; + + /* + * This is pretty much like QTAILQ_FOREACH(xendev, &xendevs, next) but + * we save the next pointer in xnext because we might free xendev. + */ + xnext = xendevs.tqh_first; + while (xnext) { + xendev = xnext; + xnext = xendev->next.tqe_next; + + if (xendev->dom != dom) { + continue; + } + if (xendev->dev != dev && dev != -1) { + continue; + } + + if (xendev->ops->free) { + xendev->ops->free(xendev); + } + + if (xendev->fe) { + char token[XEN_BUFSIZE]; + snprintf(token, sizeof(token), "fe:%p", xendev); + xs_unwatch(xenstore, xendev->fe, token); + g_free(xendev->fe); + } + + if (xendev->evtchndev != NULL) { + xenevtchn_close(xendev->evtchndev); + } + if (xendev->gnttabdev != NULL) { + xengnttab_close(xendev->gnttabdev); + } + + QTAILQ_REMOVE(&xendevs, xendev, next); + g_free(xendev); + } + return NULL; +} + +void xen_pv_insert_xendev(struct XenDevice *xendev) +{ + QTAILQ_INSERT_TAIL(&xendevs, xendev, next); +} diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 60b634e..71dd158 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -21,7 +21,6 @@ char *xenstore_read_be_str(struct XenDevice *xendev, const char *node); int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival); void xenstore_update_be(char *watch, char *type, int dom, struct XenDevOps *ops); -struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); void xen_be_check_state(struct XenDevice *xendev); /* xen backend driver bits */ diff --git a/include/hw/xen/xen_frontend.h b/include/hw/xen/xen_frontend.h index 7d87da4..ae587e1 100644 --- a/include/hw/xen/xen_frontend.h +++ b/include/hw/xen/xen_frontend.h @@ -1,6 +1,8 @@ #ifndef QEMU_HW_XEN_FRONTEND_H #define QEMU_HW_XEN_FRONTEND_H 1 +#include "hw/xen/xen_pvdev.h" + char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node); int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival); int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, uint64_t *uval); diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index f269b04..234e111 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -67,6 +67,10 @@ void xenstore_update(void *unused); const char *xenbus_strstate(enum xenbus_state state); void xen_be_evtchn_event(void *opaque); +void xen_pv_insert_xendev(struct XenDevice *xendev); +struct XenDevice *xen_be_del_xendev(int dom, int dev); +struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev); + void xen_be_unbind_evtchn(struct XenDevice *xendev); int xen_be_send_notify(struct XenDevice *xendev);