From patchwork Sat Oct 29 01:10:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9402977 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 617676022E for ; Sat, 29 Oct 2016 01:13:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E2A72A6F5 for ; Sat, 29 Oct 2016 01:13:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 428392A718; Sat, 29 Oct 2016 01:13:08 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 37E1A2A70A for ; Sat, 29 Oct 2016 01:13:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c0IAJ-0003zN-G9; Sat, 29 Oct 2016 01:10:31 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c0IAH-0003yE-Jm for xen-devel@lists.xenproject.org; Sat, 29 Oct 2016 01:10:29 +0000 Received: from [85.158.139.211] by server-10.bemta-5.messagelabs.com id B6/81-21400-407F3185; Sat, 29 Oct 2016 01:10:28 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLLMWRWlGSWpSXmKPExsVybKJshy7Ld+E Ig7+vWS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1owJ7VMZCzbrVSzf18XSwLhOtYuRi0NIYCqj xN0nS9kgnO1MEr+b9rF2MXJysAkYSvx9sokNxBYRkJHovLSIEaSIWWAro8TPC1/AEsIC3hJHG ieDNbAIqEos+DmLEcTmFXCTuPj3NAuILSEgJ3HyGEQNp4C7xI+Vf1kgtrUxSjzpvA5VlCExr2 cOK4TtJbHoxiUoW03i6rlNzBMY+RYwMqxi1ChOLSpLLdI1NNFLKspMzyjJTczM0TU0MNXLTS0 uTkxPzUlMKtZLzs/dxAgMFgYg2MF49rTnIUZJDiYlUd5vX4QjhPiS8lMqMxKLM+KLSnNSiw8x ynBwKEnwMn4DygkWpaanVqRl5gDDFiYtwcGjJML76CtQmre4IDG3ODMdInWKUVFKnJcZpE8AJ JFRmgfXBouVS4yyUsK8jECHCPEUpBblZpagyr9iFOdgVBLmtQKZwpOZVwI3/RXQYiagxdPTBU AWlyQipKQaGBe7ZuX0HMhZ8TBb7l7H89CJ60N8jtq7rE985HP9y+r9ryU1E75mp5TrXKhN23T NM/OnEe9s3cQ9SZ0rZ/09+9LO8fi0lc4LJ048lLfhT1dZlaJXb0Xj2miG9EKfinkr8m9e8E88 9uyxlTM3a0KNaOr0nJPH5zvLVZbfjT3DKWF+jjFgz/oIAyWW4oxEQy3mouJEAJsg8LKQAgAA X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-6.tower-206.messagelabs.com!1477703426!67228950!1 X-Originating-IP: [198.145.29.136] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.13; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54230 invoked from network); 29 Oct 2016 01:10:27 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.136) by server-6.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 29 Oct 2016 01:10:27 -0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 64C912041F; Sat, 29 Oct 2016 01:10:25 +0000 (UTC) Received: from sstabellini-ThinkPad-X260.hsd1.ca.comcast.net (96-82-76-110-static.hfc.comcastbusiness.net [96.82.76.110]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 083F420494; Sat, 29 Oct 2016 01:10:23 +0000 (UTC) From: Stefano Stabellini To: peter.maydell@linaro.org Date: Fri, 28 Oct 2016 18:10:06 -0700 Message-Id: <1477703413-18852-6-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477703413-18852-1-git-send-email-sstabellini@kernel.org> References: <1477703413-18852-1-git-send-email-sstabellini@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP Cc: Quan Xu , sstabellini@kernel.org, qemu-devel@nongnu.org, anthony.perard@citrix.com, xen-devel@lists.xenproject.org, Emil Condrea Subject: [Xen-devel] [PULL 06/13] xen: Prepare xendev qtail to be shared with frontends X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Emil Condrea * 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 Signed-off-by: Stefano Stabellini Signed-off-by: Quan Xu Acked-by: Anthony PERARD --- hw/xen/xen_backend.c | 51 +-------------------------------------- hw/xen/xen_pvdev.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/xen/xen_backend.h | 1 - include/hw/xen/xen_pvdev.h | 4 ++++ 4 files changed, 62 insertions(+), 51 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 1487db2..2875e7c 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -54,8 +54,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) @@ -157,27 +155,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. */ @@ -226,7 +203,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); @@ -235,32 +212,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 7607e44..96ed2a3 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -22,7 +22,11 @@ #include "hw/xen/xen_backend.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) @@ -206,3 +210,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 6c617d9..cbda40e 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -27,7 +27,6 @@ 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); -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_pvdev.h b/include/hw/xen/xen_pvdev.h index a8da3da..517537a 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);