From patchwork Sun Jul 10 17:35:47 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: 9222723 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 165B060890 for ; Sun, 10 Jul 2016 17:46:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07F1525404 for ; Sun, 10 Jul 2016 17:46:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE07226E8A; Sun, 10 Jul 2016 17:46: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=-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 A5A5D25404 for ; Sun, 10 Jul 2016 17:46:17 +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 1bMIkz-0007cn-8q; Sun, 10 Jul 2016 17:43:05 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bMIkx-0007ch-Qb for xen-devel@lists.xen.org; Sun, 10 Jul 2016 17:43:03 +0000 Received: from [193.109.254.147] by server-3.bemta-14.messagelabs.com id 33/22-17627-72982875; Sun, 10 Jul 2016 17:43:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBIsWRWlGSWpSXmKPExsVykCGBTVetsyn c4N4ZYYslHxezODB6HN39mymAMYo1My8pvyKBNePTk2OMBVckKo6smMnUwHhasIuRk0NIYC6j xP0PzCC2hICOxJdJj5i6GLmA4rsZJZpnXmeCKMqXmP32CBuIzSYQKtG+fQYriC0iIC1x7fNlR pAGZpBBMzZ8BCsSFoiU+L5qOlARBweLgKrEtBcJIGFeAT+JnuM7WSGWyUls27KHESIuKHFy5h MWkHJmAXWJ9fOEQML8AkoS29ZfBithFpCXaN46m3kCI/8sJB2zEDpmIalawMi8ilGjOLWoLLV I19BCL6koMz2jJDcxM0fX0NBELze1uDgxPTUnMalYLzk/dxMjMATrGRgYdzAe2e55iFGSg0lJ lPeCbUO4EF9SfkplRmJxRnxRaU5q8SFGGQ4OJQnezvamcCHBotT01Iq0zBxgNMCkJTh4lER4v 4GkeYsLEnOLM9MhUqcYFaXEeTeDJARAEhmleXBtsAi8xCgrJczLyMDAIMRTkFqUm1mCKv+KUZ yDUUmY9wfIFJ7MvBK46a+AFjMBLTYIqAdZXJKIkJJqYJR8P9MyacW+SwZNi93P3F8sE5a03EF kf3D78vg2/obQu+0uE7ZWpX8y2XlvgmZ6UPPcE53x0Wm73DdOlcovLBbprDj0z8l5l/j6qjKe nv+hNlb3pj9L0PaS/KGSZ2K9xbKjqO9p77xXOVLaW1Xz77Au5VjRerDg95rIisYV88MLvbjct 1/crcRSnJFoqMVcVJwIANJcZai7AgAA X-Env-Sender: marmarek@mimuw.edu.pl X-Msg-Ref: server-8.tower-27.messagelabs.com!1468172581!42506127!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 17130 invoked from network); 10 Jul 2016 17:43:02 -0000 Received: from mail.mimuw.edu.pl (HELO mail.mimuw.edu.pl) (193.0.96.6) by server-8.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Jul 2016 17:43:02 -0000 Received: from localhost (localhost [127.0.0.1] ident=amavis) by duch.mimuw.edu.pl (Postfix) with ESMTP id ECB2A3F2; Sun, 10 Jul 2016 19:43: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 KoBGAMxTs1Zs; Sun, 10 Jul 2016 19:42:59 +0200 (CEST) Received: by duch.mimuw.edu.pl (Postfix, from userid 1575) id 61F2C3F1; Sun, 10 Jul 2016 19:42:59 +0200 (CEST) From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xen.org Date: Sun, 10 Jul 2016 19:35:47 +0200 Message-Id: <1468172147-8702-1-git-send-email-marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.5.5 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] 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 --- tools/libxl/libxl.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 1c81239..99815a7 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -4743,8 +4743,16 @@ 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; + xs_transaction_t t; ddomain.ao = ao; + FILLZERO(ddomain.watch); LIBXL_SLIST_INIT(&ddomain.guests); rc = libxl__get_domid(gc, &domid); @@ -4762,9 +4770,41 @@ int libxl_device_events_handler(libxl_ctx *ctx, be_path); if (rc) goto out; + rc = libxl__xs_transaction_start(gc, &t); + if (rc) goto out; + kinds = libxl__xs_directory(gc, t, be_path, &nkinds); + if (kinds) { + for (i = 0; i < nkinds; i++) { + domains = libxl__xs_directory(gc, t, + GCSPRINTF("%s/%s", be_path, kinds[i]), &ndomains); + if (!domains) + continue; + for (j = 0; j < ndomains; j++) { + devs = libxl__xs_directory(gc, t, + 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, t, state_path, &sstate); + if (rc) + continue; + state = atoi(sstate); + if (state == XenbusStateInitWait) + backend_watch_callback(egc, &ddomain.watch, + be_path, state_path); + } + } + } + } + + libxl__xs_transaction_abort(gc, &t); + return AO_INPROGRESS; out: + libxl__ev_xswatch_deregister(gc, &ddomain.watch); return AO_CREATE_FAIL(rc); }