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: 9394061 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 1CB3C60231 for ; Tue, 25 Oct 2016 06:01:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DDE72935C for ; Tue, 25 Oct 2016 06:01:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0171A2936E; Tue, 25 Oct 2016 06:01:18 +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 C2E942935C for ; Tue, 25 Oct 2016 06:01:17 +0000 (UTC) Received: from localhost ([::1]:51940 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byunU-0008Dt-Kt for patchwork-qemu-devel@patchwork.kernel.org; Tue, 25 Oct 2016 02:01:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byueh-00010e-A3 for qemu-devel@nongnu.org; Tue, 25 Oct 2016 01:52:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byuee-0004WZ-Nx for qemu-devel@nongnu.org; Tue, 25 Oct 2016 01:52:11 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:40795) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1byuee-0004WI-Ee for qemu-devel@nongnu.org; Tue, 25 Oct 2016 01:52:08 -0400 Received: by mail-wm0-x241.google.com with SMTP id b80so252466wme.7 for ; Mon, 24 Oct 2016 22:52:08 -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=AM2hLftOlrNkDLEAT6k7JpZ+bccIFWrD0ZrTYGBB4eVpNKpKKHCmfEZAQKe57I/06T XHa7RsbRxVqHJCPcOjGkIW21PsDjq8OvZ60DMKzJV5gQVETcLnaeCIZZiWeraxVhtEK6 TT/b9ort/u0PC/4dBiox9cBapKC/QtCQwVYEI0L4lspKz+EEMe5PiGHS74kyXqBEkIrH z1sNvya+PEs7KFQ62aiCfAiQeEuDdw+uTqLjByFyvQBgW7xBrqkHuuPiSmtJiHAGOIrY 5egb3PVr9o2Hf9Se4YDqoIDxDx78OhNjWR3iG9j8m4K3ijNXhOwPwBz4YoYxD7+d71iv XrRw== X-Gm-Message-State: ABUngvdAuiWx5j8BR/ip9O7D+W2fnB9yws6vOLCUkbhwSoaH9GSzU2kZjgYX/vaaLwujwA== 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> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH v3 06/13] 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, pbonzini@redhat.com, dgdegra@tycho.nsa.gov 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_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);