From patchwork Tue Oct 25 05:50:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Condrea X-Patchwork-Id: 9394029 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 6C89460231 for ; Tue, 25 Oct 2016 05:54:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E5B82935D for ; Tue, 25 Oct 2016 05:54:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52F4229360; Tue, 25 Oct 2016 05:54:47 +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=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 D86D22935D for ; Tue, 25 Oct 2016 05:54:46 +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 1byueg-0000l2-86; Tue, 25 Oct 2016 05:52:10 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1byuef-0000jp-21 for xen-devel@lists.xen.org; Tue, 25 Oct 2016 05:52:09 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id 08/A4-19721-803FE085; Tue, 25 Oct 2016 05:52:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHIsWRWlGSWpSXmKPExsXiVRvkrMv+mS/ CoOGOhsWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmrF4/iPmglc6FcvXTGRqYPyu3MXIySEk0M8o 8ehbTRcjFweLwEsWiX/7/7GDOBIC/awSq15uY+5i5AByYiSWTuABaZAQqJSY834CO0SzisS8H 5uZQOqFBH4wSpzavJcRJMEmoCXxefkaNhBbREBS4nfXaWYQm1ngFqPEu/2RILawgL/Evh3/wQ axCKhKfPtzhgVkF6+Aq8Ty2RYQu+QkTh6bzApicwq4STyacYINYq+rxITm7awTGAUWMDKsYtQ oTi0qSy3SNTTXSyrKTM8oyU3MzNE1NDDVy00tLk5MT81JTCrWS87P3cQIDCsGINjBePG05yFG SQ4mJVHeZef4IoT4kvJTKjMSizPii0pzUosPMcpwcChJ8Bp9AsoJFqWmp1akZeYAAxwmLcHBo yTCawqS5i0uSMwtzkyHSJ1i1OXYMvXeWiYhlrz8vFQpcV4TkCIBkKKM0jy4EbBou8QoKyXMyw h0lBBPQWpRbmYJqvwrRnEORiVhXiuQKTyZeSVwm14BHcEEdIRgPA/IESWJCCmpBsbn53SsH52 b0187NzMg5datLfFJtpJKDfuUN+sa/M7+8u7moZu8u3gC84X6imS4rhr4rExsVp3YONdmUuXV q7dn78vo47fJftIqt/z4cvdpoZPuynSnZ8hNv1b176/wpOdTJmzRFjB8dyrCSKxOyEInZMbfC Wrvzxwt5AmMW2rOHKl9vnpd93ElluKMREMt5qLiRABd7QVFsQIAAA== X-Env-Sender: emilcondrea@gmail.com X-Msg-Ref: server-10.tower-206.messagelabs.com!1477374727!49444889!1 X-Originating-IP: [74.125.82.67] 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 7722 invoked from network); 25 Oct 2016 05:52:07 -0000 Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by server-10.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 25 Oct 2016 05:52:07 -0000 Received: by mail-wm0-f67.google.com with SMTP id m83so252967wmc.6 for ; Mon, 24 Oct 2016 22:52:07 -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=P+q4qMLNxUfShlvkhDIeVGV8ovUKYERmGpMe34RJIzs=; b=ou0LshP1YpX4AOEESAjY2WWKgpN1q8FfLX7Vnl3aXoJM/A5qYzqhZRxiiVb+fjIQox zlxQWoiNY9LguR5t9/M94KBJAol3ybUTZGsxGYwrQhtVsfXMCMVxerDclos249F9Z4v2 epkBSaqI8/yhkWfx5OOe6Kj4XFkoQomhS65CDspNMsMwc4DjujvZ9ShFm7W6R/lHXDwZ wtlO2A7g+vP7ttQhdBRspP8DNBp+F4VGnEOKhc2utPH+S6sps9J/yMmNbyeZFl1bPqBC O+4XFtlBJhXCjSRwZEDeeD4bt4DhvtHOZmYTiZBkQiF/NS78v0ZkS9Z7OTsLaA/BbcKC 8S6g== 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=P+q4qMLNxUfShlvkhDIeVGV8ovUKYERmGpMe34RJIzs=; b=E5CnHounxs7AX4b/NFeCADggY57HR34FZAaP1ihTD7keZJobmqO+g/Xl5F21lVrMWr 9ifMRUOkqYuxppLGAWO5vjhh7S6CJODHBviPtfnvfeQKJ7rVEt6nqV0vubJqZhWOdMr8 8siquEIGkzv6jDZggIYyVotPmdVF/png86oEDHTG+KaQx5XEi8uGWcaZqarkih1JERtK 2ECmvgOiidovZ+jAYGDq5Qh5w2bcUu5gi4M9fVTDwQRsfdXj1cUTweaVtI3Swt30e2IQ ZWfUOarOAJeZmXvmW1xz22yws7ogtPor9umT6jfP+5q2h46er7IT87J8uzRrEKZVEAZ1 xPbA== X-Gm-Message-State: ABUngveI/Ed1fMVyAcxJMZw54fo1TIT+SdkHmgYXlGvScEhDcLUMdRL3b1aaMiwbow6qBQ== X-Received: by 10.194.40.42 with SMTP id u10mr14297317wjk.35.1477374727170; Mon, 24 Oct 2016 22:52:07 -0700 (PDT) Received: from localhost.localdomain ([79.112.79.134]) by smtp.gmail.com with ESMTPSA id gk6sm1358053wjc.21.2016.10.24.22.52.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Oct 2016 22:52:06 -0700 (PDT) From: Emil Condrea To: qemu-devel@nongnu.org Date: Tue, 25 Oct 2016 08:50:12 +0300 Message-Id: <1477374619-13149-7-git-send-email-emilcondrea@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477374619-13149-1-git-send-email-emilcondrea@gmail.com> References: <1477374619-13149-1-git-send-email-emilcondrea@gmail.com> 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, pbonzini@redhat.com, dgdegra@tycho.nsa.gov, eblake@redhat.com Subject: [Xen-devel] [PATCH v3 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 * 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_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);