From patchwork Fri Jul 15 23:47:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= X-Patchwork-Id: 9232921 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 2805460574 for ; Fri, 15 Jul 2016 23:52:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B06B22230 for ; Fri, 15 Jul 2016 23:52:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F1BA262F2; Fri, 15 Jul 2016 23:52:14 +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 CBF9C22230 for ; Fri, 15 Jul 2016 23:52:11 +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 1bOCqu-0000y7-M8; Fri, 15 Jul 2016 23:49:04 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bOCqs-0000y1-O3 for xen-devel@lists.xen.org; Fri, 15 Jul 2016 23:49:02 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id D2/8F-12614-D6679875; Fri, 15 Jul 2016 23:49:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrAIsWRWlGSWpSXmKPExsVykCGBTTe3rDP cYE+rpMWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmtF0dzdTwWzximm31RoYNwh0MXJxCAnMZZS4 tuQAWxcjJ4eEgI7El0mPmCASuxklDr38zg6SEBLIl9hw5DETiM0mECrRvn0GK4gtIiAtce3zZ UaQBmaQSTM2fASbJCwQI/Fi2iZmEJtFQFXiY+t2sGZeAT+JB9/uMUJsk5PYtmUPmM0pYCBx9f UGFohl+hLrdz9nhqgXlDg58wlQnANogbrE+nlCIGF+ASWJbesvg7UyC8hLNG+dzTyBUXAWko5 ZCB2zkFQtYGRexahenFpUllqka6mXVJSZnlGSm5iZo2toYKqXm1pcnJiempOYVKyXnJ+7iREY sgxAsINxbavzIUZJDiYlUd6+wM5wIb6k/JTKjMTijPii0pzU4kOMMhwcShK8x0qAcoJFqempF WmZOcDogUlLcPAoifDqlAKleYsLEnOLM9MhUqcYFaXEeXeD9AmAJDJK8+DaYBF7iVFWSpiXEe gQIZ6C1KLczBJU+VeM4hyMSsK8TCDjeTLzSuCmvwJazAS02Nq8HWRxSSJCSqqBUUU078ncNW+ 7st+aq3W+6PuifzN1flWt6iWVx9E/7kWJv1DNLJ7AE561psmA4ermLdry6hus7mew7V7aJv3l QXT+6Xa/ZY/fiXi9jIp9FbulZvcRH5cJ3oIZG3VeP2ySFpSsWjevk/d/vne6TZpwu+GDXZwz8 h9svJa18vDxi6t4lKI3REywVGIpzkg01GIuKk4EAE5qG0LTAgAA X-Env-Sender: marmarek@mimuw.edu.pl X-Msg-Ref: server-14.tower-206.messagelabs.com!1468626541!13491236!1 X-Originating-IP: [193.0.96.6] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 16421 invoked from network); 15 Jul 2016 23:49:01 -0000 Received: from mail.mimuw.edu.pl (HELO mail.mimuw.edu.pl) (193.0.96.6) by server-14.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Jul 2016 23:49:01 -0000 Received: from localhost (localhost [127.0.0.1] ident=amavis) by duch.mimuw.edu.pl (Postfix) with ESMTP id 9D7D624D; Sat, 16 Jul 2016 01:49:00 +0200 (CEST) X-Virus-Scanned: amavisd-new at mimuw.edu.pl Received: from mail.mimuw.edu.pl ([193.0.96.6]) by localhost (mail.mimuw.edu.pl [127.0.0.1]) (amavisd-new, port 10028) with ESMTP id daDil_LE0KeY; Sat, 16 Jul 2016 01:48:59 +0200 (CEST) Received: by duch.mimuw.edu.pl (Postfix, from userid 1575) id 5AFC224B; Sat, 16 Jul 2016 01:48:59 +0200 (CEST) From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xen.org Date: Sat, 16 Jul 2016 01:47:56 +0200 Message-Id: <1468626476-3072-1-git-send-email-marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <20160714093617.GO31770@citrix.com> References: <20160714093617.GO31770@citrix.com> MIME-Version: 1.0 Organization: Invisible Things Lab Cc: Wei Liu , Ian Jackson , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Subject: [Xen-devel] [PATCH v3] libxl: trigger attach events for devices attached before xl devd startup 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP When this daemon is started after creating backend device, that device will not be configured. Racy situation: 1. driver domain is started 2. frontend domain is started (just after kicking driver domain off) 3. device in frontend domain is connected to the backend (as specified in frontend domain configuration) 4. xl devd is started in driver domain End result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work. Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state). Cc: Ian Jackson Cc: Wei Liu Signed-off-by: Marek Marczykowski-Górecki Acked-by: Wei Liu --- Changes since v2: - check for sstate being NULL - minor indentation tools/libxl/libxl.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 1c81239..b69466f 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -4743,6 +4743,12 @@ int libxl_device_events_handler(libxl_ctx *ctx, uint32_t domid; libxl__ddomain ddomain; char *be_path; + char **kinds = NULL, **domains = NULL, **devs = NULL; + const char *sstate; + char *state_path; + int state; + unsigned int nkinds, ndomains, ndevs; + int i, j, k; ddomain.ao = ao; LIBXL_SLIST_INIT(&ddomain.guests); @@ -4762,6 +4768,33 @@ int libxl_device_events_handler(libxl_ctx *ctx, be_path); if (rc) goto out; + kinds = libxl__xs_directory(gc, XBT_NULL, be_path, &nkinds); + if (kinds) { + for (i = 0; i < nkinds; i++) { + domains = libxl__xs_directory(gc, XBT_NULL, + GCSPRINTF("%s/%s", be_path, kinds[i]), &ndomains); + if (!domains) + continue; + for (j = 0; j < ndomains; j++) { + devs = libxl__xs_directory(gc, XBT_NULL, + GCSPRINTF("%s/%s/%s", be_path, kinds[i], domains[j]), &ndevs); + if (!devs) + continue; + for (k = 0; k < ndevs; k++) { + state_path = GCSPRINTF("%s/%s/%s/%s/state", + be_path, kinds[i], domains[j], devs[k]); + rc = libxl__xs_read_checked(gc, XBT_NULL, state_path, &sstate); + if (rc || !sstate) + continue; + state = atoi(sstate); + if (state == XenbusStateInitWait) + backend_watch_callback(egc, &ddomain.watch, + be_path, state_path); + } + } + } + } + return AO_INPROGRESS; out: