virtio-scsi: Allocate op blocker reason before blocking
PATCH 1/1 virtio-scsi: Allocate op blocker reason before blocking
s->blocker is really only used in hw/scsi/virtio-scsi.c; the only places where it is used in hw/scsi/virtio-scsi-dataplane.c is when it is allocated and when it is freed. That does not make a whole lot of sense (and is actually wrong because this leads to s->blocker potentially being NULL when blk_op_block_all() is called in virtio-scsi.c), so move the allocation and destruction of s->blocker to blk_op_block_all() and blk_op_unblock_all() in virtio-scsi.c, respectively.
---
Try:
$ echo -e 'eject drv\nquit' | \
x86_64-softmmu/qemu-system-x86_64 \
-monitor stdio -machine accel=qtest -display none \
-object iothread,id=thr -device virtio-scsi-pci,iothread=thr \
-drive if=none,file=test.qcow2,format=qcow2,id=drv \
-device scsi-cd,drive=drvWhat it should do:
QEMU 2.2.50 monitor - type 'help' for more information (qemu) eject drv
Device 'drv' is busy: block device is in use by data plane (qemu) quit
What it should not do:
QEMU 2.2.50 monitor - type 'help' for more information (qemu) eject drv
[1] 10102 done
10103 segmentation fault (core dumped)
--- hw/scsi/virtio-scsi-dataplane.c | 4 ---- hw/scsi/virtio-scsi.c | 6 +++++- 2 files changed, 5 insertions(+), 5 deletions(-)
hw/scsi/virtio-scsi-dataplane.c +0 -4
@@ -211,8 +211,6 @@ void virtio_scsi_dataplane_start(VirtIOSCSI *s) s->dataplane_starting = true; -assert (!s->blocker); -error_setg (&s->blocker,"block device is in use by data plane" );/* Set up guest notifier (irq) */ rc = k->set_guest_notifiers (qbus->parent, vs->conf.num_queues +2 , true);if (rc !=0 ) {
@@ -279,8 +277,6 @@ void virtio_scsi_dataplane_stop(VirtIOSCSI *s)if (!s->dataplane_started || s->dataplane_stopping) {return ; } -error_free (s->blocker); - s->blocker =NULL ; s->dataplane_stopping = true;assert (s->ctx ==iothread_get_aio_context (vs->conf.iothread));
hw/scsi/virtio-scsi.c +5 -1
@@ -766,6 +766,8 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,if (blk_op_is_blocked (sd->conf.blk,BLOCK_OP_TYPE_DATAPLANE , errp)) {return ; } +assert (!s->blocker); +error_setg (&s->blocker,"block device is in use by data plane" );blk_op_block_all (sd->conf.blk, s->blocker); }
@@ -789,8 +791,10 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev, VIRTIO_SCSI_EVT_RESET_REMOVED); } -if (s->ctx) { +if (s->ctx && s->blocker) {blk_op_unblock_all (sd->conf.blk, s->blocker); +error_free (s->blocker); + s->blocker =NULL ; }qdev_simple_device_unplug_cb (hotplug_dev, dev, errp); }
Signature · 1 line
2.1.0
Quoted 26 lines · Max Reitz
s->blockeris really only used inhw/scsi/virtio-scsi.c; the only places where it is used inhw/scsi/virtio-scsi-dataplane.cis when it is allocated and when it is freed. That does not make a whole lot of sense (and is actually wrong because this leads tos->blockerpotentially being NULL whenblk_op_block_all()is called invirtio-scsi.c), so move the allocation and destruction ofs->blockertoblk_op_block_all()andblk_op_unblock_all()invirtio-scsi.c, respectively.Signed-off-by Max Reitz <[email protected]>---
Try:$ echo -e 'eject drv\nquit' | \ x86_64-softmmu/qemu-system-x86_64 \ -monitor stdio -machine accel=qtest -display none \ -object iothread,id=thr -device virtio-scsi-pci,iothread=thr \ -drive if=none,file=test.qcow2,format=qcow2,id=drv \ -device scsi-cd,drive=drvWhat it should do:
QEMU 2.2.50 monitor - type 'help' for more information (qemu) eject drv
Device 'drv' is busy: block device is in use by data plane (qemu) quit
Quoted 6 lines
What it should not do:
QEMU 2.2.50 monitor - type 'help' for more information (qemu) eject drv
[1] 10102 done
10103 segmentation fault (core dumped)
Why do you put your nice reproducer below the --- divider? I rather like bug fixing commits come with reproducers in the commit message.
[...]
Quoted 30 lines · Markus Armbruster
Quoted 28 lines · Max Reitz
s->blockeris really only used inhw/scsi/virtio-scsi.c; the only places where it is used inhw/scsi/virtio-scsi-dataplane.cis when it is allocated and when it is freed. That does not make a whole lot of sense (and is actually wrong because this leads tos->blockerpotentially being NULL whenblk_op_block_all()is called invirtio-scsi.c), so move the allocation and destruction ofs->blockertoblk_op_block_all()andblk_op_unblock_all()invirtio-scsi.c, respectively.Signed-off-by Max Reitz <[email protected]>---
Try:$ echo -e 'eject drv\nquit' | \ x86_64-softmmu/qemu-system-x86_64 \ -monitor stdio -machine accel=qtest -display none \ -object iothread,id=thr -device virtio-scsi-pci,iothread=thr \ -drive if=none,file=test.qcow2,format=qcow2,id=drv \ -device scsi-cd,drive=drvWhat it should do:
QEMU 2.2.50 monitor - type 'help' for more information (qemu) eject drv
Device 'drv' is busy: block device is in use by data plane (qemu) quitWhat it should not do:
Quoted 8 lines
Quoted 4 lines
QEMU 2.2.50 monitor - type 'help' for more information (qemu) eject drv
[1] 10102 done
10103 segmentation fault (core dumped)Why do you put your nice reproducer below the --- divider? I rather like bug fixing commits come with reproducers in the commit message.
[...]
Because then I'm afraid that Eric complains because I used echo -e instead of printf.
Seriously speaking, I don't mind putting it into the commit message. I'll wait for reviews on the change itself, and then either send a v2 with the reproducer included in the commit message or hope for a maintainer to fix it up himself (which I'd be totally fine with *hint hint*).
Max
Eric Blake
Reviewed-byQuoted 11 lines · Max Reitz
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Max Reitz
s->blockeris really only used inhw/scsi/virtio-scsi.c; the only places where it is used inhw/scsi/virtio-scsi-dataplane.cis when it is allocated and when it is freed. That does not make a whole lot of sense (and is actually wrong because this leads tos->blockerpotentially being NULL whenblk_op_block_all()is called invirtio-scsi.c), so move the allocation and destruction ofs->blockertoblk_op_block_all()andblk_op_unblock_all()invirtio-scsi.c, respectively.
Quoted 2 lines
Quoted 2 lines
Why do you put your nice reproducer below the --- divider? I rather like bug fixing commits come with reproducers in the commit message.
As do I :)
Quoted 5 lines
Quoted 2 lines
[...]
Because then I'm afraid that Eric complains because I used echo -e instead of printf.
I might point out the non-portability, but for a commit message, I'm perfectly fine leaving a non-portable construct in place. I'm only going to ask for a respin if 'echo -e' is used in the patch body.
Quoted 6 lines
Seriously speaking, I don't mind putting it into the commit message. I'll wait for reviews on the change itself, and then either send a v2 with the reproducer included in the commit message or hope for a maintainer to fix it up himself (which I'd be totally fine with *hint hint*).
Up to the maintainer on that front, but if it helps, then with the amended commit message:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 88 lines · Max Reitz
s->blockeris really only used inhw/scsi/virtio-scsi.c; the only places where it is used inhw/scsi/virtio-scsi-dataplane.cis when it is allocated and when it is freed. That does not make a whole lot of sense (and is actually wrong because this leads tos->blockerpotentially being NULL whenblk_op_block_all()is called invirtio-scsi.c), so move the allocation and destruction ofs->blockertoblk_op_block_all()andblk_op_unblock_all()invirtio-scsi.c, respectively.Signed-off-by Max Reitz <[email protected]>---
Try:$ echo -e 'eject drv\nquit' | \ x86_64-softmmu/qemu-system-x86_64 \ -monitor stdio -machine accel=qtest -display none \ -object iothread,id=thr -device virtio-scsi-pci,iothread=thr \ -drive if=none,file=test.qcow2,format=qcow2,id=drv \ -device scsi-cd,drive=drvWhat it should do:
QEMU 2.2.50 monitor - type 'help' for more information (qemu) eject drv
Device 'drv' is busy: block device is in use by data plane (qemu) quitWhat it should not do:
QEMU 2.2.50 monitor - type 'help' for more information (qemu) eject drv
[1] 10102 done
10103 segmentation fault (core dumped)--- hw/scsi/virtio-scsi-dataplane.c | 4 ---- hw/scsi/virtio-scsi.c | 6 +++++- 2 files changed, 5 insertions(+), 5 deletions(-)hw/scsi/virtio-scsi-dataplane.c +0
-4@@ -211,8 +211,6 @@ void virtio_scsi_dataplane_start(VirtIOSCSI *s) s->dataplane_starting = true; -assert (!s->blocker); -error_setg (&s->blocker,"block device is in use by data plane" );/* Set up guest notifier (irq) */ rc = k->set_guest_notifiers (qbus->parent, vs->conf.num_queues +2 , true);if (rc !=0 ) {@@ -279,8 +277,6 @@ void virtio_scsi_dataplane_stop(VirtIOSCSI *s)if (!s->dataplane_started || s->dataplane_stopping) {return ; } -error_free (s->blocker); - s->blocker =NULL ; s->dataplane_stopping = true;assert (s->ctx ==iothread_get_aio_context (vs->conf.iothread));hw/scsi/virtio-scsi.c +5
-1@@ -766,6 +766,8 @@ static void virtio_scsi_hotplug(HotplugHandler *hotplug_dev, DeviceState *dev,if (blk_op_is_blocked (sd->conf.blk,BLOCK_OP_TYPE_DATAPLANE , errp)) {return ; } +assert (!s->blocker); +error_setg (&s->blocker,"block device is in use by data plane" );blk_op_block_all (sd->conf.blk, s->blocker); }@@ -789,8 +791,10 @@ static void virtio_scsi_hotunplug(HotplugHandler *hotplug_dev, DeviceState *dev, VIRTIO_SCSI_EVT_RESET_REMOVED); } -if (s->ctx) { +if (s->ctx && s->blocker) {blk_op_unblock_all (sd->conf.blk, s->blocker); +error_free (s->blocker); + s->blocker =NULL ; }qdev_simple_device_unplug_cb (hotplug_dev, dev, errp); }Signature · 1 line
2.1.0