From nobody Tue Apr 12 08:07:04 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 595B011D41B4; Tue, 12 Apr 2022 08:07:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KcyxP1pfWz3GmL; Tue, 12 Apr 2022 08:07:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649750825; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=j03PXHZgUjt6/mGHhJe2qQ4Td6Y6VH7Dhp+j/FU3FWE=; b=Pfya7aFz3tn0uDbzd62fwc4ApjaHgutTcprR6LjtQ4UMSxqlihoAXiY41CFcWgOWfUhD2t JxhvU8Ur91vQPXRyZGo5062hGarZnrsGqXu/hqExwYD8ZX+dN0IxhbRzCN11fOSd1Eoqhr VrPXMJTZYhQBPu8ZYAdVbuMThvgtFeamuCpkpLKQ+f4iVGrThbowqkn0Po6hOPghwBMTYr 1lwuc4sMmv0sBv93jOMDDHIuXpemiruvPe3xuK4eHO+7DlvvGKEF2gg1iwQsdvdmbQjuMB V1TjLCivnnvIyccJz+yLEemhoc8I48DzMGhb7sebeLxkJb33I7ZKfXgKq0I0vA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1D8F413D8E; Tue, 12 Apr 2022 08:07:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23C874ST012795; Tue, 12 Apr 2022 08:07:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23C874uB012794; Tue, 12 Apr 2022 08:07:04 GMT (envelope-from git) Date: Tue, 12 Apr 2022 08:07:04 GMT Message-Id: <202204120807.23C874uB012794@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Roger Pau Monn=C3=A9?= Subject: git: 590f093f74f2 - stable/13 - xen/blkback: fix reconnection of backend List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: royger X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 590f093f74f2f60f7a49f0b8707970189d2faaef Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649750825; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=j03PXHZgUjt6/mGHhJe2qQ4Td6Y6VH7Dhp+j/FU3FWE=; b=t3hMl/rNcOzz0qAsk3KgAIvrb0lZ1/SLFjl75OYUQDhcbf9hcHuiY6qbQa6M8foKk/RRd9 h5MkoBFWRhdto6IZ+6HrqNKjkBn8VxK/uCEA72gkrN/maeidcMrPLzOpkDj3gJiXoQIWKp Y8sXeHGMh8vc08zeGrHSmSMwzHk5r/Fbhne/tUAOhQy4b5lYGFUejWVXtBi7oX1GNv4U57 kFLxzFiUzqq43sIWlSsIeKchIfC8D9VcAjufOYU/Ml+A9FzbxPY9oC+f2rXPkXYzth9Tc1 ESeLEUoJjWBY6XOVczD3jIJHOAmdyNL2ElZr6K7mnubAw0ZfkR19ZDUSslW6+g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649750825; a=rsa-sha256; cv=none; b=PwrdQ/1nXcWVG5h7imtGVV519s4cJm7OlHD4G26LAAAAGBZiqDdXomYhIEw/0NuWot8ihh nOL8PUHT8aUJLp5nARo1SKHhI2ZPCuC00+Vs/P8bdDL9H+y4yxCXyTBEUohAl6KHkakGyo UWIPE1Mzn9zrJD5V4q+1rJhqdiH4ZJxNgSxWfrsL3S2/EahE1bMLj/g1JhWwvnxQsHZa+P N/LleTen+H8kzfkCb22Xjw936wHIRId3FXaNNkW6O4fDzIr71H+uqQZ58QqRq7W0QAqFF/ +goNU0g0ePump3WnPE96+QARvKesPGNEVpIKy+RLA2f3GWiIuHt6tDvR5cUhDA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=590f093f74f2f60f7a49f0b8707970189d2faaef commit 590f093f74f2f60f7a49f0b8707970189d2faaef Author: Roger Pau Monné AuthorDate: 2021-05-11 10:19:29 +0000 Commit: Roger Pau Monné CommitDate: 2022-04-12 08:05:47 +0000 xen/blkback: fix reconnection of backend The hotplug script will be executed only once for each backend, regardless of the frontend triggering reconnections. Fix blkback to deal with the hotplug script being executed only once, so that reconnections don't stall waiting for a hotplug script execution that will never happen. As a result of the fix move the initialization of dev_mode, dev_type and dev_name to the watch callback, as they should be set only once the first time the backend connects. This fix is specially relevant for guests wanting to use UEFI OVMF firmware, because OVMF will use Xen PV block devices and disconnect afterwards, thus allowing them to be used by the guest OS. Without this change the guest OS will stall waiting for the block backed to attach. Fixes: de0bad00010c ('blkback: add support for hotplug scripts') Sponsored by: Citrix Systems R&D (cherry picked from commit 4772e86beb089ee08a3bff8ad359e83a4c623238) --- sys/dev/xen/blkback/blkback.c | 83 +++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/sys/dev/xen/blkback/blkback.c b/sys/dev/xen/blkback/blkback.c index 678472cc2ab8..010e737740b8 100644 --- a/sys/dev/xen/blkback/blkback.c +++ b/sys/dev/xen/blkback/blkback.c @@ -3412,7 +3412,6 @@ xbb_shutdown(struct xbb_softc *xbb) free(xbb->hotplug_watch.node, M_XENBLOCKBACK); xbb->hotplug_watch.node = NULL; } - xbb->hotplug_done = false; if (xenbus_get_state(xbb->dev) < XenbusStateClosing) xenbus_set_state(xbb->dev, XenbusStateClosing); @@ -3597,39 +3596,14 @@ xbb_setup_sysctl(struct xbb_softc *xbb) } static void -xbb_attach_disk(struct xs_watch *watch, const char **vec, unsigned int len) +xbb_attach_disk(device_t dev) { - device_t dev; struct xbb_softc *xbb; int error; - dev = (device_t) watch->callback_data; xbb = device_get_softc(dev); - error = xs_gather(XST_NIL, xenbus_get_node(dev), "physical-device-path", - NULL, &xbb->dev_name, NULL); - if (error != 0) - return; - - xs_unregister_watch(watch); - free(watch->node, M_XENBLOCKBACK); - watch->node = NULL; - - /* Collect physical device information. */ - error = xs_gather(XST_NIL, xenbus_get_otherend_path(xbb->dev), - "device-type", NULL, &xbb->dev_type, - NULL); - if (error != 0) - xbb->dev_type = NULL; - - error = xs_gather(XST_NIL, xenbus_get_node(dev), - "mode", NULL, &xbb->dev_mode, - NULL); - if (error != 0) { - xbb_attach_failed(xbb, error, "reading backend fields at %s", - xenbus_get_node(dev)); - return; - } + KASSERT(xbb->hotplug_done, ("Missing hotplug execution")); /* Parse fopen style mode flags. */ if (strchr(xbb->dev_mode, 'w') == NULL) @@ -3693,13 +3667,48 @@ xbb_attach_disk(struct xs_watch *watch, const char **vec, unsigned int len) return; } - xbb->hotplug_done = true; - /* The front end might be waiting for the backend, attach if so. */ if (xenbus_get_otherend_state(xbb->dev) == XenbusStateInitialised) xbb_connect(xbb); } +static void +xbb_attach_cb(struct xs_watch *watch, const char **vec, unsigned int len) +{ + device_t dev; + struct xbb_softc *xbb; + int error; + + dev = (device_t)watch->callback_data; + xbb = device_get_softc(dev); + + error = xs_gather(XST_NIL, xenbus_get_node(dev), "physical-device-path", + NULL, &xbb->dev_name, NULL); + if (error != 0) + return; + + xs_unregister_watch(watch); + free(watch->node, M_XENBLOCKBACK); + watch->node = NULL; + xbb->hotplug_done = true; + + /* Collect physical device information. */ + error = xs_gather(XST_NIL, xenbus_get_otherend_path(dev), "device-type", + NULL, &xbb->dev_type, NULL); + if (error != 0) + xbb->dev_type = NULL; + + error = xs_gather(XST_NIL, xenbus_get_node(dev), "mode", NULL, + &xbb->dev_mode, NULL); + if (error != 0) { + xbb_attach_failed(xbb, error, "reading backend fields at %s", + xenbus_get_node(dev)); + return; + } + + xbb_attach_disk(dev); +} + /** * Attach to a XenBus device that has been claimed by our probe routine. * @@ -3757,14 +3766,21 @@ xbb_attach(device_t dev) return (error); } + /* Tell the toolstack blkback has attached. */ + xenbus_set_state(dev, XenbusStateInitWait); + + if (xbb->hotplug_done) { + xbb_attach_disk(dev); + return (0); + } + /* * We need to wait for hotplug script execution before * moving forward. */ - KASSERT(!xbb->hotplug_done, ("Hotplug scripts already executed")); watch_path = xs_join(xenbus_get_node(xbb->dev), "physical-device-path"); xbb->hotplug_watch.callback_data = (uintptr_t)dev; - xbb->hotplug_watch.callback = xbb_attach_disk; + xbb->hotplug_watch.callback = xbb_attach_cb; KASSERT(xbb->hotplug_watch.node == NULL, ("watch node already setup")); xbb->hotplug_watch.node = strdup(sbuf_data(watch_path), M_XENBLOCKBACK); /* @@ -3782,9 +3798,6 @@ xbb_attach(device_t dev) return (error); } - /* Tell the toolstack blkback has attached. */ - xenbus_set_state(dev, XenbusStateInitWait); - return (0); }