block: Improve warnings for doubly-connected drives
v2 cover block: Improve warnings for doubly-connected drives
This patchset attempts to improve the warning and error messages for bad user command lines that attempt to connect a drive up to two devices. The motivation here is patch #4, which changes the default interface for the virt board to virtio. That will break some existing command lines which forgot to specify if=none, and so I would like us to at least diagnose that user error in a helpful way that points the user towards adding the missing if=none.
Version 2 reduces scope, because it turns out that it is harder than we thought to identify whether a use of an if=something drive is the auto-plugging or a manual wiring up to a device. So all we do here is improve the error messages for two situations which were already errors but with rather cryptic messages:
(1) Drive specified as to be auto-connected and also manually connected (and the board does handle this if= type):
qemu-system-x86_64 -nodefaults -display none \
-drive if=scsi,file=tmp.qcow2,id=foo -device ide-hd,drive=foo
Previously:
qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive' can't take value 'foo', it's in use
Now:
qemu-system-x86_64: -device ide-hd,drive=foo: Drive 'foo' is already in use because it has been automatically connected to another device (did you need 'if=none' in the drive options?)
(2) Drive specified to be manually connected in two different ways:
qemu-system-x86_64 -nodefaults -display none \
-drive if=none,file=tmp.qcow2,id=foo -device ide-hd,drive=foo \
-device ide-hd,drive=foo
Previously:
qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive' can't take value 'foo', it's in use
Now:
qemu-system-x86_64: -device ide-hd,drive=foo: Drive 'foo' is already in use by another device
(We'll also produce message 1 in the oddball case where the user creates a drive if=something-not-handled-by-machine and then wires it up manually to two different devices; in this case their command line is doubly broken and if they use if=none as suggested by message 1 they'll then get message 2 and can fix their own double-usage...)
Changes v1->v2:
* drop "warn if an if=<something> drive was also connected manually" patch
* change implementation of "improve error message" patch
Peter Maydell (3):
qdev-properties-system: Change set_pointer's parse callback to use
Error
qdev-properties-system: Improve error message for drive assignment
conflict
hw/arm/virt: Make block devices default to virtio
hw/arm/virt.c | 2 ++ hw/core/qdev-properties-system.c | 42 +++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 13 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 1/3 qdev-properties-system: Change set_pointer's parse callback to use Error
Instead of having set_pointer() call a parse callback which returns an error number that we then convert to an Error string with error_set_from_qdev_prop_error(), make the parse callback take an Error** and set the error itself. This will allow parse routines to provide more helpful error messages than the generic ones.
--- hw/core/qdev-properties-system.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
hw/core/qdev-properties-system.c +20 -13
@@ -35,15 +35,15 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop, }static void set_pointer (Object *obj,Visitor *v,Property *prop, -int (*parse)(DeviceState *dev,const char *str, -void **ptr), +void (*parse)(DeviceState *dev,const char *str, +void **ptr,const char *propname, +Error **errp),const char *name,Error **errp) {DeviceState *dev =DEVICE (obj);Error *local_err =NULL ;void **ptr =qdev_get_prop_ptr (dev, prop);char *str; -int ret;if (dev->realized) {qdev_prop_set_after_realize (dev, name, errp);
@@ -60,26 +60,29 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop, *ptr =NULL ;return ; } - ret =parse (dev, str, ptr); -error_set_from_qdev_prop_error (errp, ret, dev, prop, str); +parse (dev, str, ptr, prop->name, errp);g_free (str); }/* --- drive --- */ -static int parse_drive (DeviceState *dev,const char *str,void **ptr) +static void parse_drive (DeviceState *dev,const char *str,void **ptr, +const char *propname,Error **errp) {BlockBackend *blk; blk =blk_by_name (str);if (!blk) { -return -ENOENT ; +error_setg (errp,"Property '%s.%s' can't find value '%s'" , +object_get_typename (OBJECT (dev)), propname, str); +return ; }if (blk_attach_dev (blk, dev) <0 ) { -return -EEXIST ; +error_setg (errp,"Property '%s.%s' can't take value '%s', it's in use" , +object_get_typename (OBJECT (dev)), propname, str); +return ; } *ptr = blk; -return 0 ; }static void release_drive (Object *obj,const char *name,void *opaque)
@@ -121,17 +124,21 @@ PropertyInfo qdev_prop_drive = {/* --- character device --- */ -static int parse_chr (DeviceState *dev,const char *str,void **ptr) +static void parse_chr (DeviceState *dev,const char *str,void **ptr, +const char *propname,Error **errp) {CharDriverState *chr =qemu_chr_find (str);if (chr ==NULL ) { -return -ENOENT ; +error_setg (errp,"Property '%s.%s' can't find value '%s'" , +object_get_typename (OBJECT (dev)), propname, str); +return ; }if (qemu_chr_fe_claim (chr) !=0 ) { -return -EEXIST ; +error_setg (errp,"Property '%s.%s' can't take value '%s', it's in use" , +object_get_typename (OBJECT (dev)), propname, str); +return ; } *ptr = chr; -return 0 ; }static void release_chr (Object *obj,const char *name,void *opaque)
Signature · 1 line
1.9.1
PATCH v2 2/3 qdev-properties-system: Improve error message for drive assignment conflict
In reply to Peter MaydellIf the user forgot if=none on their drive specification they're likely to get an error message because the drive is assigned once automatically by QEMU and once by the manual id=/drive= user command line specification. Improve the error message produced in this case to explicitly guide the user towards if=none.
We rephrase the "drive conflict but not for an if=something" error as well to keep the wording in line.
The two cases that change are:
(1) Drive specified as to be auto-connected and also manually connected (and the board does handle this if= type):
qemu-system-x86_64 -nodefaults -display none \
-drive if=scsi,file=tmp.qcow2,id=foo -device ide-hd,drive=fooPreviously:
qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive' can't take value 'foo', it's in use
Now:
qemu-system-x86_64: -device ide-hd,drive=foo: Drive 'foo' is already in use because it has been automatically connected to another device (did you need 'if=none' in the drive options?)
(2) Drive specified to be manually connected in two different ways:
qemu-system-x86_64 -nodefaults -display none \ -drive if=none,file=tmp.qcow2,id=foo -device ide-hd,drive=foo \ -device ide-hd,drive=foo
Previously:
qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive' can't take value 'foo', it's in use
Now:
qemu-system-x86_64: -device ide-hd,drive=foo: Drive 'foo' is already in use by another device
--- hw/core/qdev-properties-system.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
hw/core/qdev-properties-system.c +11 -2
@@ -78,8 +78,17 @@ static void parse_drive(DeviceState *dev, const char *str, void **ptr,return ; }if (blk_attach_dev (blk, dev) <0 ) { -error_setg (errp,"Property '%s.%s' can't take value '%s', it's in use" , -object_get_typename (OBJECT (dev)), propname, str); +DriveInfo *dinfo =blk_legacy_dinfo (blk); + +if (dinfo->type !=IF_NONE ) { +error_setg (errp,"Drive '%s' is already in use because " +"it has been automatically connected to another " +"device (did you need 'if=none' in the drive options?)" , + str); + }else { +error_setg (errp,"Drive '%s' is already in use by another device" , + str); + }return ; } *ptr = blk;
Signature · 1 line
1.9.1
PATCH v2 3/3 hw/arm/virt: Make block devices default to virtio
In reply to Peter MaydellNow we have virtio-pci, we can make the virt board's default block device type be IF_VIRTIO. This allows users to use simplified command lines that don't have to explicitly create virtio-pci-blk devices; the -hda &c very short options now also work.
This means we also need to set no_cdrom to avoid getting a default cdrom device -- this is needed because the virtio-blk device will fail if it is connected to a block backend with no media, which is what the default cdrom device typically is. Providing a cdrom with media via -cdrom will still work.
Note that this change means that some command lines which used to work (by accident) will stop working. Where a drive was connected manually to a device but without 'if=none' being specified, we used to treat this as an IDE drive, which we would then not autoplug because the board doesn't support IDE. Now we will treat it as a virtio disk and autoplug it, which means the attempt to use the drive manually will fail:
qemu-system-arm: -drive file=img.qcow2,id=foo: Drive 'foo' is already in use because it has been automatically connected to another device (did you need 'if=none' in the drive options?)
The command line will be changed to include 'if=none', as the error message suggests.
--- hw/arm/virt.c | 2 ++ 1 file changed, 2 insertions(+)
hw/arm/virt.c +2 -0
@@ -966,6 +966,8 @@ static void virt_class_init(ObjectClass *oc, void *data) mc->init = machvirt_init; mc->max_cpus =8 ; mc->has_dynamic_sysbus = true; + mc->block_default_type =IF_VIRTIO ; + mc->no_cdrom =1 ; }static const TypeInfo machvirt_info = {
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH v2 for-2.4 3/3] hw/arm/virt: Make block devices default to virtio
Quoted 10 lines · Peter Maydell
Now we have virtio-pci, we can make the virt board's default block device type be
IF_VIRTIO. This allows users to use simplified command lines that don't have to explicitly create virtio-pci-blk devices; the -hda &c very short options now also work.This means we also need to set
no_cdromto avoid getting a default cdrom device -- this is needed because the virtio-blk device will fail if it is connected to a block backend with no media, which is what the default cdrom device typically is. Providing a cdrom with media via -cdrom will still work.
It'll create a virtio-blk device with non-removable medium, won't it?
Quoted 11 lines
Note that this change means that some command lines which used to work (by accident) will stop working. Where a drive was connected manually to a device but without 'if=none' being specified, we used to treat this as an IDE drive, which we would then not autoplug because the board doesn't support IDE. Now we will treat it as a virtio disk and autoplug it, which means the attempt to use the drive manually will fail:
qemu-system-arm: -drive file=img.qcow2,id=foo: Drive 'foo' is already in use because it has been automatically connected to another device (did you need 'if=none' in the drive options?)
The command line will be changed to include 'if=none', as the
will have to be changed
Quoted 20 lines
error message suggests.
Signed-off-by Peter Maydell <[email protected]>--- hw/arm/virt.c | 2 ++ 1 file changed, 2 insertions(+)hw/arm/virt.c +2
-0@@ -966,6 +966,8 @@ static void virt_class_init(ObjectClass *oc, void *data) mc->init = machvirt_init; mc->max_cpus =8 ; mc->has_dynamic_sysbus = true; + mc->block_default_type =IF_VIRTIO ; + mc->no_cdrom =1 ; }static const TypeInfo machvirt_info = {
Re: [Qemu-devel] [PATCH v2 for-2.4 3/3] hw/arm/virt: Make block devices default to virtio
Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Peter Maydell
Now we have virtio-pci, we can make the virt board's default block device type be
IF_VIRTIO. This allows users to use simplified command lines that don't have to explicitly create virtio-pci-blk devices; the -hda &c very short options now also work.
Quoted 7 lines
Quoted 5 lines
This means we also need to set
no_cdromto avoid getting a default cdrom device -- this is needed because the virtio-blk device will fail if it is connected to a block backend with no media, which is what the default cdrom device typically is. Providing a cdrom with media via -cdrom will still work.It'll create a virtio-blk device with non-removable medium, won't it?
Yes, I think so. Mostly I cared that -cdrom won't make qemu die with a confusing error.
(Without no_cdrom, qemu dies even if you don't say -cdrom, because of the default empty drive.)
Quoted 3 lines
Quoted 1 line
The command line will be changed to include 'if=none', as the
will have to be changed
Yes.
-- PMM
Re: [Qemu-devel] [PATCH v2 for-2.4 3/3] hw/arm/virt: Make block devices default to virtio
Quoted 14 lines · Peter Maydell
Quoted 13 lines · Markus Armbruster
Quoted 10 lines · Peter Maydell
Now we have virtio-pci, we can make the virt board's default block device type be
IF_VIRTIO. This allows users to use simplified command lines that don't have to explicitly create virtio-pci-blk devices; the -hda &c very short options now also work.This means we also need to set
no_cdromto avoid getting a default cdrom device -- this is needed because the virtio-blk device will fail if it is connected to a block backend with no media, which is what the default cdrom device typically is. Providing a cdrom with media via -cdrom will still work.
Quoted 7 lines
Quoted 1 line
It'll create a virtio-blk device with non-removable medium, won't it?
Yes, I think so. Mostly I cared that -cdrom won't make qemu die with a confusing error.
(Without
no_cdrom, qemu dies even if you don't say -cdrom, because of the default empty drive.)
Instead of "will still work", I'd like to see something like "will succeed, but silently create a device with non-removable medium, which is probably not what you want, but the best we can do now".
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
The command line will be changed to include 'if=none', as the
will have to be changed
Yes.
-- PMM
Quoted 43 lines · Peter Maydell
This patchset attempts to improve the warning and error messages for bad user command lines that attempt to connect a drive up to two devices. The motivation here is patch #4, which changes the default interface for the virt board to virtio. That will break some existing command lines which forgot to specify if=none, and so I would like us to at least diagnose that user error in a helpful way that points the user towards adding the missing if=none.
Version 2 reduces scope, because it turns out that it is harder than we thought to identify whether a use of an if=something drive is the auto-plugging or a manual wiring up to a device. So all we do here is improve the error messages for two situations which were already errors but with rather cryptic messages:
(1) Drive specified as to be auto-connected and also manually connected (and the board does handle this if= type):
qemu-system-x86_64 -nodefaults -display none \
-drive if=scsi,file=tmp.qcow2,id=foo -device ide-hd,drive=fooPreviously:
qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive' can't take value 'foo', it's in useNow:
qemu-system-x86_64: -device ide-hd,drive=foo: Drive 'foo' is already in use because it has been automatically connected to another device (did you need 'if=none' in the drive options?)(2) Drive specified to be manually connected in two different ways:
qemu-system-x86_64 -nodefaults -display none \
-drive if=none,file=tmp.qcow2,id=foo -device ide-hd,drive=foo \
-device ide-hd,drive=fooPreviously:
qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive' can't take value 'foo', it's in useNow:
qemu-system-x86_64: -device ide-hd,drive=foo: Drive 'foo' is already in use by another device
Quoted 5 lines
(We'll also produce message 1 in the oddball case where the user creates a drive if=something-not-handled-by-machine and then wires it up manually to two different devices; in this case their command line is doubly broken and if they use if=none as suggested by message 1 they'll then get message 2 and can fix their own double-usage...)
With the commit message of PATCH 3 amended, series
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Peter Maydell
This patchset attempts to improve the warning and error messages for bad user command lines that attempt to connect a drive up to two devices. The motivation here is patch #4, which changes the default interface for the virt board to virtio. That will break some existing command lines which forgot to specify if=none, and so I would like us to at least diagnose that user error in a helpful way that points the user towards adding the missing if=none.
Quoted 2 lines
With the commit message of PATCH 3 amended, series
Reviewed-by Markus Armbruster <[email protected]>
Thanks. Do you want to take this through a block tree or are you happy for me to put it through target-arm.next?
-- PMM
Quoted 11 lines · Peter Maydell
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Peter Maydell
This patchset attempts to improve the warning and error messages for bad user command lines that attempt to connect a drive up to two devices. The motivation here is patch #4, which changes the default interface for the virt board to virtio. That will break some existing command lines which forgot to specify if=none, and so I would like us to at least diagnose that user error in a helpful way that points the user towards adding the missing if=none.
Quoted 5 lines
Quoted 2 lines
With the commit message of PATCH 3 amended, series
Reviewed-by Markus Armbruster <[email protected]>Thanks. Do you want to take this through a block tree or are you happy for me to put it through target-arm.next?
I'm fine with target-arm. Copying Stefan in the unlikely case he's not.
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Peter Maydell
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Peter Maydell
This patchset attempts to improve the warning and error messages for bad user command lines that attempt to connect a drive up to two devices. The motivation here is patch #4, which changes the default interface for the virt board to virtio. That will break some existing command lines which forgot to specify if=none, and so I would like us to at least diagnose that user error in a helpful way that points the user towards adding the missing if=none.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
With the commit message of PATCH 3 amended, series
Reviewed-by Markus Armbruster <[email protected]>Thanks. Do you want to take this through a block tree or are you happy for me to put it through target-arm.next?
I'm fine with target-arm. Copying Stefan in the unlikely case he's not.
Thanks, I'm happy with this series. Please take it through the arm tree.
Quoted 61 lines · Peter Maydell
This patchset attempts to improve the warning and error messages for bad user command lines that attempt to connect a drive up to two devices. The motivation here is patch #4, which changes the default interface for the virt board to virtio. That will break some existing command lines which forgot to specify if=none, and so I would like us to at least diagnose that user error in a helpful way that points the user towards adding the missing if=none.
Version 2 reduces scope, because it turns out that it is harder than we thought to identify whether a use of an if=something drive is the auto-plugging or a manual wiring up to a device. So all we do here is improve the error messages for two situations which were already errors but with rather cryptic messages:
(1) Drive specified as to be auto-connected and also manually connected (and the board does handle this if= type):
qemu-system-x86_64 -nodefaults -display none \
-drive if=scsi,file=tmp.qcow2,id=foo -device ide-hd,drive=fooPreviously:
qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive' can't take value 'foo', it's in useNow:
qemu-system-x86_64: -device ide-hd,drive=foo: Drive 'foo' is already in use because it has been automatically connected to another device (did you need 'if=none' in the drive options?)(2) Drive specified to be manually connected in two different ways:
qemu-system-x86_64 -nodefaults -display none \
-drive if=none,file=tmp.qcow2,id=foo -device ide-hd,drive=foo \
-device ide-hd,drive=fooPreviously:
qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive' can't take value 'foo', it's in useNow:
qemu-system-x86_64: -device ide-hd,drive=foo: Drive 'foo' is already in use by another device(We'll also produce message 1 in the oddball case where the user creates a drive if=something-not-handled-by-machine and then wires it up manually to two different devices; in this case their command line is doubly broken and if they use if=none as suggested by message 1 they'll then get message 2 and can fix their own double-usage...)
Changes
v1->v2:
* drop "warn if an if=<something> drive was also connected manually" patch
* change implementation of "improve error message" patchPeter Maydell (3):
qdev-properties-system: Change set_pointer's parse callback to use
Error
qdev-properties-system: Improve error message for drive assignment
conflict
hw/arm/virt: Make block devices default to virtio
Quoted 8 lines
hw/arm/virt.c | 2 ++ hw/core/qdev-properties-system.c | 42 +++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 13 deletions(-)Signature · 1 line
1.9.1