From patchwork Wed Jul 5 21:50:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9827209 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 6D81760351 for ; Wed, 5 Jul 2017 21:53:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B36D25223 for ; Wed, 5 Jul 2017 21:53:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F18C2850D; Wed, 5 Jul 2017 21:53:29 +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 6DCEC25223 for ; Wed, 5 Jul 2017 21:53:28 +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 1dSsCP-00039q-VF; Wed, 05 Jul 2017 21:51:05 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSsCP-00038P-Eb for xen-devel@lists.xen.org; Wed, 05 Jul 2017 21:51:05 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id F5/4F-02181-84F5D595; Wed, 05 Jul 2017 21:51:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrPLMWRWlGSWpSXmKPExsVybKJssq57fGy kwZL/1hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bbd98ZC2arVjx51cjYwNgq38XIxSEksI5J YsPXpaxdjJwcLAIOEiu2T2DqYuTgYBSIkXjwwxokzCgQJjH58hKwEjYBQ4m/TzaxgdgiAtIS1 z5fZgSZwywwmVHi9btfzCAJYQEbib9PP4LNYRFQlVj8zBUkzCvgJrF+UgcTiC0hICdx8thksJ mcAu4SZ1oXskLc08Yosff5D6YJjLwLGBlWMaoXpxaVpRbpWuolFWWmZ5TkJmbm6BoaGOvlphY XJ6an5iQmFesl5+duYgQGQz0DA+MOxtc/nQ4xSnIwKYny/tGPjRTiS8pPqcxILM6ILyrNSS0+ xCjDwaEkwfs7FignWJSanlqRlpkDDEuYtAQHj5II72phoDRvcUFibnFmOkTqFKMxx4bV678wc bya8P8bkxBLXn5eqpQ4r1AcUKkASGlGaR7cIFi8XGKUlRLmZWRgYBDiKUgtys0sQZV/xSjOwa gkzLsN5B6ezLwSuH2vgE5hAjpFsTEG5JSSRISUVANjx1V9p+eGUZr7jP+vXVp5bpHhlKXrNwU dbSkw+ztl8qI+/Tl7ljwqjJna7RZRInOSY0bp5f3Olelu90N5neS3p4u/+iDeMel1QfAy7y8r /9wKimwtMe5Pj2O6+fqd5oXLadpd389u+XZ205OQh2lvGd9HHLgbPc1eMuZozR+2ideWnX2t/ fqSvRJLcUaioRZzUXEiACC+wCqSAgAA X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-2.tower-31.messagelabs.com!1499291462!92439997!1 X-Originating-IP: [198.145.29.99] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5947 invoked from network); 5 Jul 2017 21:51:03 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-2.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Jul 2017 21:51:03 -0000 Received: from localhost.localdomain (162-198-228-33.lightspeed.wlfrct.sbcglobal.net [162.198.228.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BE73522C7D; Wed, 5 Jul 2017 21:51:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE73522C7D From: Stefano Stabellini To: xen-devel@lists.xen.org Date: Wed, 5 Jul 2017 14:50:44 -0700 Message-Id: <1499291458-30231-4-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1499291458-30231-1-git-send-email-sstabellini@kernel.org> References: <1499291458-30231-1-git-send-email-sstabellini@kernel.org> Cc: jgross@suse.com, Stefano Stabellini , boris.ostrovsky@oracle.com, sstabellini@kernel.org, linux-kernel@vger.kernel.org Subject: [Xen-devel] [PATCH v7 04/18] xen/pvcalls: xenbus state handling 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 Introduce the code to handle xenbus state changes. Implement the probe function for the pvcalls backend. Write the supported versions, max-page-order and function-calls nodes to xenstore, as required by the protocol. Introduce stub functions for disconnecting/connecting to a frontend. Signed-off-by: Stefano Stabellini Reviewed-by: Boris Ostrovsky CC: boris.ostrovsky@oracle.com CC: jgross@suse.com Reviewed-by: Juergen Gross --- drivers/xen/pvcalls-back.c | 155 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c index 9044cf2..72d2fce 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -25,20 +25,175 @@ #include #include +#define PVCALLS_VERSIONS "1" +#define MAX_RING_ORDER XENBUS_MAX_RING_GRANT_ORDER + struct pvcalls_back_global { struct list_head frontends; struct semaphore frontends_lock; } pvcalls_back_global; +static int backend_connect(struct xenbus_device *dev) +{ + return 0; +} + +static int backend_disconnect(struct xenbus_device *dev) +{ + return 0; +} + static int pvcalls_back_probe(struct xenbus_device *dev, const struct xenbus_device_id *id) { + int err, abort; + struct xenbus_transaction xbt; + +again: + abort = 1; + + err = xenbus_transaction_start(&xbt); + if (err) { + pr_warn("%s cannot create xenstore transaction\n", __func__); + return err; + } + + err = xenbus_printf(xbt, dev->nodename, "versions", "%s", + PVCALLS_VERSIONS); + if (err) { + pr_warn("%s write out 'versions' failed\n", __func__); + goto abort; + } + + err = xenbus_printf(xbt, dev->nodename, "max-page-order", "%u", + MAX_RING_ORDER); + if (err) { + pr_warn("%s write out 'max-page-order' failed\n", __func__); + goto abort; + } + + err = xenbus_printf(xbt, dev->nodename, "function-calls", + XENBUS_FUNCTIONS_CALLS); + if (err) { + pr_warn("%s write out 'function-calls' failed\n", __func__); + goto abort; + } + + abort = 0; +abort: + err = xenbus_transaction_end(xbt, abort); + if (err) { + if (err == -EAGAIN && !abort) + goto again; + pr_warn("%s cannot complete xenstore transaction\n", __func__); + return err; + } + + if (abort) + return -EFAULT; + + xenbus_switch_state(dev, XenbusStateInitWait); + return 0; } +static void set_backend_state(struct xenbus_device *dev, + enum xenbus_state state) +{ + while (dev->state != state) { + switch (dev->state) { + case XenbusStateClosed: + switch (state) { + case XenbusStateInitWait: + case XenbusStateConnected: + xenbus_switch_state(dev, XenbusStateInitWait); + break; + case XenbusStateClosing: + xenbus_switch_state(dev, XenbusStateClosing); + break; + default: + __WARN(); + } + break; + case XenbusStateInitWait: + case XenbusStateInitialised: + switch (state) { + case XenbusStateConnected: + backend_connect(dev); + xenbus_switch_state(dev, XenbusStateConnected); + break; + case XenbusStateClosing: + case XenbusStateClosed: + xenbus_switch_state(dev, XenbusStateClosing); + break; + default: + __WARN(); + } + break; + case XenbusStateConnected: + switch (state) { + case XenbusStateInitWait: + case XenbusStateClosing: + case XenbusStateClosed: + down(&pvcalls_back_global.frontends_lock); + backend_disconnect(dev); + up(&pvcalls_back_global.frontends_lock); + xenbus_switch_state(dev, XenbusStateClosing); + break; + default: + __WARN(); + } + break; + case XenbusStateClosing: + switch (state) { + case XenbusStateInitWait: + case XenbusStateConnected: + case XenbusStateClosed: + xenbus_switch_state(dev, XenbusStateClosed); + break; + default: + __WARN(); + } + break; + default: + __WARN(); + } + } +} + static void pvcalls_back_changed(struct xenbus_device *dev, enum xenbus_state frontend_state) { + switch (frontend_state) { + case XenbusStateInitialising: + set_backend_state(dev, XenbusStateInitWait); + break; + + case XenbusStateInitialised: + case XenbusStateConnected: + set_backend_state(dev, XenbusStateConnected); + break; + + case XenbusStateClosing: + set_backend_state(dev, XenbusStateClosing); + break; + + case XenbusStateClosed: + set_backend_state(dev, XenbusStateClosed); + if (xenbus_dev_is_online(dev)) + break; + device_unregister(&dev->dev); + break; + case XenbusStateUnknown: + set_backend_state(dev, XenbusStateClosed); + device_unregister(&dev->dev); + break; + + default: + xenbus_dev_fatal(dev, -EINVAL, "saw state %d at frontend", + frontend_state); + break; + } } static int pvcalls_back_remove(struct xenbus_device *dev)