From patchwork Tue Oct 4 06:43: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: 9361241 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 6DC39600C8 for ; Tue, 4 Oct 2016 06:58:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BA8A28A3D for ; Tue, 4 Oct 2016 06:58:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EC1728AE0; Tue, 4 Oct 2016 06:58:10 +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 A848D28A3D for ; Tue, 4 Oct 2016 06:58:09 +0000 (UTC) Received: from localhost ([::1]:40502 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brJg0-0003q5-JL for patchwork-qemu-devel@patchwork.kernel.org; Tue, 04 Oct 2016 02:58:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54661) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brJSz-0001lm-QA for qemu-devel@nongnu.org; Tue, 04 Oct 2016 02:44:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brJSw-0005lL-Dd for qemu-devel@nongnu.org; Tue, 04 Oct 2016 02:44:40 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:33128) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brJSw-0005kd-0P for qemu-devel@nongnu.org; Tue, 04 Oct 2016 02:44:38 -0400 Received: by mail-wm0-x243.google.com with SMTP id p138so18017486wmb.0 for ; Mon, 03 Oct 2016 23:44:37 -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=SJG2XVadnwSacttoQyf267PEM0h1dTRXVhkTU3ythBU=; b=DjCCxj9Xz/U3s+j0tmKnt63kaPpK9Azkge858+dQNkvuq7j+94Bc2j2LQskb+jUqJ3 K17JoHIsisjhWOqTxScURfrHXWKyvKZVd8tD6Y5ZoMDpD6xfsnI7IjHXVpb0Cg5QwkTH Fk1mUTJGBmPoErkERZeSMp6NmJqRWP8gIvm5JQIaZwP1VXVL5CI62snbCiQoQLqVHcbS XhxxSzCWXgFrcgcKMgYPZHf4umNoA2Vh/vAUss7lbAf3K0ehzRSPeQr3nUXa+hxJQSHi wqT+SMCvPUCGsjScnzZ4zrNsC6LnhnDWB2HLrUhcl7X/iXREldvx/pSXN13RZo/O4M5z J1Pw== 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=SJG2XVadnwSacttoQyf267PEM0h1dTRXVhkTU3ythBU=; b=OBTS43MkGavde6wa5qBUGs3+YrnZzSUHhVm/H5yt2+dhTnVedncC1fCs3PF1B3o6ST RStaSXD1JgDTH4FW8R99awP6Lz0bgXDaQWuRt7lRpEKLuQHcUPYTZh44QHzvXqlXNYQi fzt/49H1Ae2JTp+wnjb53/e6lozWetK2dLG8JfRLu4h5iNr1/HCJa/o6fp9oytXpcwvZ i2V8ltd00GfpR+FGt9TdAMBxyNOrpXpSN2r0ysSPvNQTlk1ir7TyP/eLr7UhL/eS1lkT q8DIwH02my3QGPc1fkrhdD7EdNDRY/xeICfh2DVYFHabaW1DJRFht32lhzDTWhjqUoOf 23zg== X-Gm-Message-State: AA6/9Rkvz3dP5QIpvr9FNJO40TrVl//WvK57fSLqpoePY9Na0BAZhAN9V5oSCIyeVBdjzg== X-Received: by 10.28.189.197 with SMTP id n188mr8692651wmf.80.1475563477266; Mon, 03 Oct 2016 23:44:37 -0700 (PDT) Received: from localhost.localdomain ([79.112.35.35]) by smtp.gmail.com with ESMTPSA id f142sm2341423wmf.19.2016.10.03.23.44.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Oct 2016 23:44:36 -0700 (PDT) From: Emil Condrea To: qemu-devel@nongnu.org Date: Tue, 4 Oct 2016 09:43:36 +0300 Message-Id: <1475563424-6604-8-git-send-email-emilcondrea@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1475563424-6604-1-git-send-email-emilcondrea@gmail.com> References: <1475563424-6604-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::243 Subject: [Qemu-devel] [PATCH 07/15] 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: xuquan8@huawei.com, sstabellini@kernel.org, wei.liu2@citrix.com, stefanb@linux.vnet.ibm.com, xen-devel@lists.xen.org, anthony.perard@citrix.com, dgdegra@tycho.nsa.gov, Emil Condrea 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 | 51 +------------------------------------- hw/xen/xen_pvdev.c | 57 +++++++++++++++++++++++++++++++++++++++++++ include/hw/xen/xen_backend.h | 1 - include/hw/xen/xen_frontend.h | 2 ++ include/hw/xen/xen_pvdev.h | 4 +++ 5 files changed, 64 insertions(+), 51 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index c7db068..d572cd0 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -55,8 +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; static void xenstore_cleanup_dir(char *dir) @@ -142,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. */ @@ -211,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); @@ -220,32 +197,6 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, return xendev; } -/* - * release xen backend device. - */ -static void xen_be_del_xendev(struct XenDevice *xendev) -{ - 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); -} /* * Sync internal data structures on xenstore updates. diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 91101fd..72e2e79 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -23,7 +23,11 @@ #include "hw/xen/xen_frontend.h" #include "hw/xen/xen_pvdev.h" +/* private */ static int debug; +static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = + QTAILQ_HEAD_INITIALIZER(xendevs); + /* ------------------------------------------------------------- */ int xenstore_write_str(const char *base, const char *node, const char *val) @@ -207,3 +211,56 @@ 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. + */ +void xen_be_del_xendev(struct XenDevice *xendev) +{ + 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); +} + +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 d0dbee5..64d4fe3 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -22,7 +22,6 @@ 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 69a7694..bb0bc23 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 +#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, diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index cf44a87..337457e 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -65,6 +65,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); +void xen_be_del_xendev(struct XenDevice *xendev); +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);