diff options
author | Ka Ho Ng <khng@FreeBSD.org> | 2021-05-05 15:16:29 +0000 |
---|---|---|
committer | Ka Ho Ng <khng@FreeBSD.org> | 2021-06-28 15:16:39 +0000 |
commit | 6fd5a4a6f3ac3cb7bb3e6d55359a5ba087b76cd9 (patch) | |
tree | 62fb74605a80ff4faceaf2f4efa0529a49b6e781 | |
parent | 4bb2057c13b5894393034d82899c930e36c34153 (diff) | |
download | src-6fd5a4a6f3ac3cb7bb3e6d55359a5ba087b76cd9.tar.gz src-6fd5a4a6f3ac3cb7bb3e6d55359a5ba087b76cd9.zip |
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.
Sponsored by: The FreeBSD Foundation
Reviewed by: grehan
Approved by: lwhsu (mentor)
Differential Revision: https://reviews.freebsd.org/D30049
(cherry picked from commit 4e1e1d667fc84460c131dfe617b39072e87473ab)
-rw-r--r-- | sys/dev/virtio/block/virtio_blk.c | 20 |
1 files 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: @@ -462,6 +462,22 @@ vtblk_shutdown(device_t dev) } 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) { struct vtblk_softc *sc; |