From owner-dev-commits-src-main@freebsd.org Wed May 5 15:22:30 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 539F05FA2DD; Wed, 5 May 2021 15:22:30 +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 4Fb0nf1ykvz4S7D; Wed, 5 May 2021 15:22:30 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 2C6CD2712D; Wed, 5 May 2021 15:22:30 +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 145FMUlK090701; Wed, 5 May 2021 15:22:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 145FMUgw090700; Wed, 5 May 2021 15:22:30 GMT (envelope-from git) Date: Wed, 5 May 2021 15:22:30 GMT Message-Id: <202105051522.145FMUgw090700@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ka Ho Ng Subject: git: 4e1e1d667fc8 - main - virtio_blk: Fix issuing T_GET_ID before DRIVER_OK status MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: khng X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4e1e1d667fc84460c131dfe617b39072e87473ab Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 May 2021 15:22:30 -0000 The branch main has been updated by khng: URL: https://cgit.FreeBSD.org/src/commit/?id=4e1e1d667fc84460c131dfe617b39072e87473ab commit 4e1e1d667fc84460c131dfe617b39072e87473ab Author: Ka Ho Ng AuthorDate: 2021-05-05 15:16:29 +0000 Commit: Ka Ho Ng CommitDate: 2021-05-05 15:22:16 +0000 virtio_blk: Fix issuing T_GET_ID before DRIVER_OK status DRIVER_OK status is set after device_attach() succeeds. For now postpone disk_create to attach_completed() method. MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Reviewed by: grehan Approved by: lwhsu (mentor) Differential Revision: https://reviews.freebsd.org/D30049 --- sys/dev/virtio/block/virtio_blk.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sys/dev/virtio/block/virtio_blk.c b/sys/dev/virtio/block/virtio_blk.c index 50642fb0b009..8a5558f4571d 100644 --- a/sys/dev/virtio/block/virtio_blk.c +++ b/sys/dev/virtio/block/virtio_blk.c @@ -126,6 +126,7 @@ static int vtblk_detach(device_t); static int vtblk_suspend(device_t); static int vtblk_resume(device_t); static int vtblk_shutdown(device_t); +static int vtblk_attach_completed(device_t); static int vtblk_config_change(device_t); static int vtblk_open(struct disk *); @@ -255,6 +256,7 @@ static device_method_t vtblk_methods[] = { DEVMETHOD(device_shutdown, vtblk_shutdown), /* VirtIO methods. */ + DEVMETHOD(virtio_attach_completed, vtblk_attach_completed), DEVMETHOD(virtio_config_change, vtblk_config_change), DEVMETHOD_END @@ -378,8 +380,6 @@ vtblk_attach(device_t dev) goto fail; } - vtblk_create_disk(sc); - virtqueue_enable_intr(sc->vtblk_vq); fail: @@ -461,6 +461,22 @@ vtblk_shutdown(device_t dev) return (0); } +static int +vtblk_attach_completed(device_t dev) +{ + struct vtblk_softc *sc; + + sc = device_get_softc(dev); + + /* + * Create disk after attach as VIRTIO_BLK_T_GET_ID can only be + * processed after the device acknowledged + * VIRTIO_CONFIG_STATUS_DRIVER_OK. + */ + vtblk_create_disk(sc); + return (0); +} + static int vtblk_config_change(device_t dev) {