From owner-svn-src-all@freebsd.org Fri Jun 3 11:39:37 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 42624B68B1A; Fri, 3 Jun 2016 11:39:37 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E564B14E9; Fri, 3 Jun 2016 11:39:36 +0000 (UTC) (envelope-from royger@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u53BdauI085408; Fri, 3 Jun 2016 11:39:36 GMT (envelope-from royger@FreeBSD.org) Received: (from royger@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u53BdakP085407; Fri, 3 Jun 2016 11:39:36 GMT (envelope-from royger@FreeBSD.org) Message-Id: <201606031139.u53BdakP085407@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: royger set sender to royger@FreeBSD.org using -f From: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Date: Fri, 3 Jun 2016 11:39:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r301269 - head/sys/dev/xen/blkback X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Jun 2016 11:39:37 -0000 Author: royger Date: Fri Jun 3 11:39:35 2016 New Revision: 301269 URL: https://svnweb.freebsd.org/changeset/base/301269 Log: xen-blkback: fix error path on failed attach The current error path in case of failure during attach/initialization is not correct and leaves blkback in a stuck state. This is due to blkback waiting for blkfront to switch to state XenbusStateClosed, but if blkfront never attached (because the guest is not even started) it cannot possibly make it to that state. Instead just wait for the frontend to be in a state different than XenbusStateConnected in order to proceed with the shutdown. Also, it is wrong to call xbb_detach directly because it destroys the lock which can still be used by xbb_frontend_changed. Sponsored by: Citrix Systems R&D Modified: head/sys/dev/xen/blkback/blkback.c Modified: head/sys/dev/xen/blkback/blkback.c ============================================================================== --- head/sys/dev/xen/blkback/blkback.c Fri Jun 3 11:38:52 2016 (r301268) +++ head/sys/dev/xen/blkback/blkback.c Fri Jun 3 11:39:35 2016 (r301269) @@ -172,7 +172,6 @@ struct xbb_xen_req; static void xbb_attach_failed(struct xbb_softc *xbb, int err, const char *fmt, ...) __attribute__((format(printf, 3, 4))); static int xbb_shutdown(struct xbb_softc *xbb); -static int xbb_detach(device_t dev); /*------------------------------ Data Structures -----------------------------*/ @@ -3419,8 +3418,8 @@ xbb_shutdown(struct xbb_softc *xbb) mtx_lock(&xbb->lock); xbb->flags &= ~XBBF_IN_SHUTDOWN; - /* The front can submit I/O until entering the closed state. */ - if (frontState < XenbusStateClosed) + /* Wait for the frontend to disconnect (if it's connected). */ + if (frontState == XenbusStateConnected) return (EAGAIN); DPRINTF("\n"); @@ -3477,7 +3476,9 @@ xbb_attach_failed(struct xbb_softc *xbb, xs_printf(XST_NIL, xenbus_get_node(xbb->dev), "online", "0"); - xbb_detach(xbb->dev); + mtx_lock(&xbb->lock); + xbb_shutdown(xbb); + mtx_unlock(&xbb->lock); } /*---------------------------- NewBus Entrypoints ----------------------------*/