blockdev-add QMP command
cover blockdev-add QMP command
This series adds a blockdev-add QMP command and a row of cleanup patches to separate legacy -drive/drive_add behaviour from blockdev_init() to the wrapper function drive_init().
Kevin Wolf (17):
qapi-types/visit.py: Pass whole expr dict for structs qapi-types/visit.py: Inheritance for structs
blockdev: Introduce DriveInfo.enable_auto_del
blockdev: 'blockdev-add' QMP command
blockdev: Separate ID generation from DriveInfo creation
blockdev: Pass QDict to blockdev_init()
blockdev: Move parsing of 'media' option to drive_init
blockdev: Move parsing of 'if' option to drive_init
blockdev: Moving parsing of geometry options to drive_init
blockdev: Move parsing of 'boot' option to drive_init
blockdev: Move bus/unit/index processing to drive_init
blockdev: Move virtio-blk device creation to drive_init
blockdev: Remove IF_* check for read-only blockdev_init
qemu-iotests: Check autodel behaviour for device_del
blockdev: Remove 'media' parameter from blockdev_init()
blockdev: Don't disable COR automatically with blockdev-add
blockdev: blockdev_init() error conversion
block.c | 9 +- blockdev.c | 664 +++++++++++++++++++++++---------------- docs/qapi-code-gen.txt | 17 + hw/block/m25p80.c | 5 + hw/block/xen_disk.c | 6 + hw/sd/milkymist-memcard.c | 4 + hw/sd/omap_mmc.c | 8 + hw/sd/pl181.c | 4 + hw/sd/pxa2xx_mmci.c | 4 + hw/sd/sd.c | 5 + hw/sd/sdhci.c | 4 + hw/sd/ssi-sd.c | 3 + include/qemu/option.h | 1 + include/sysemu/blockdev.h | 1 + qapi-schema.json | 270 ++++++++++++++++ qmp-commands.hx | 59 ++++ scripts/qapi-types.py | 15 +- scripts/qapi-visit.py | 26 +- tests/qemu-iotests/051.out | 5 +- tests/qemu-iotests/064 | 133 ++++++++ tests/qemu-iotests/064.out | 80 +++++ tests/qemu-iotests/common.filter | 8 + tests/qemu-iotests/group | 1 + util/qemu-option.c | 6 + 24 files changed, 1050 insertions(+), 288 deletions(-) create mode 100755 tests/qemu-iotests/064 create mode 100644 tests/qemu-iotests/064.out
Signature · 1 line
1.8.1.4
PATCH 1/17 qapi-types/visit.py: Pass whole expr dict for structs
--- scripts/qapi-types.py | 11 ++++++++--- scripts/qapi-visit.py | 8 ++++++-- 2 files changed, 14 insertions(+), 5 deletions(-)
scripts/qapi-types.py +8 -3
@@ -71,7 +71,7 @@ def generate_struct_fields(members): c_name=c_var(argname)) if structured: push_indent() - ret += generate_struct("", argname, argentry) + ret += generate_struct({ "field": argname, "data": argentry}) pop_indent() else: ret += mcgen('''
@@ -81,7 +81,12 @@ def generate_struct_fields(members): return ret -def generate_struct(structname, fieldname, members): +def generate_struct(expr): + + structname = expr.get('type', "") + fieldname = expr.get('field', "") + members = expr['data'] + ret = mcgen(''' struct %(name)s {
@@ -417,7 +422,7 @@ if do_builtins: for expr in exprs: ret = "\n" if expr.has_key('type'): - ret += generate_struct(expr['type'], "", expr['data']) + "\n" + ret += generate_struct(expr) + "\n" ret += generate_type_cleanup_decl(expr['type'] + "List") fdef.write(generate_type_cleanup(expr['type'] + "List") + "\n") ret += generate_type_cleanup_decl(expr['type'])
scripts/qapi-visit.py +6 -2
@@ -120,7 +120,11 @@ if (!err) { ''') return ret -def generate_visit_struct(name, members): +def generate_visit_struct(expr): + + name = expr['type'] + members = expr['data'] + ret = generate_visit_struct_fields(name, "", "", members) ret += mcgen('''
@@ -472,7 +476,7 @@ if do_builtins: for expr in exprs: if expr.has_key('type'): - ret = generate_visit_struct(expr['type'], expr['data']) + ret = generate_visit_struct(expr) ret += generate_visit_list(expr['type'], expr['data']) fdef.write(ret)
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 01/17] qapi-types/visit.py: Pass whole expr dict for structs
Quoted 34 lines · Kevin Wolf
Signed-off-by Kevin Wolf <[email protected]>--- scripts/qapi-types.py | 11 ++++++++--- scripts/qapi-visit.py | 8 ++++++-- 2 files changed, 14 insertions(+), 5 deletions(-)scripts/qapi-types.py +7
-2@@ -71,7 +71,7 @@ def generate_struct_fields(members): c_name=c_var(argname)) if structured: push_indent() - ret += generate_struct("", argname, argentry) + ret += generate_struct({ "field": argname, "data": argentry}) pop_indent() else: ret += mcgen('''@@ -81,7 +81,12 @@ def generate_struct_fields(members): return ret -def generate_struct(structname, fieldname, members): +def generate_struct(expr): + + structname = expr.get('type', "") + fieldname = expr.get('field', "") + members = expr['data'] + ret = mcgen(''' struct %(name)s {
scripts/qapi-types.py if do_builtins: · line 425
Quoted 5 lines
scripts/qapi-types.py +1
-1@@ -417,7 +422,7 @@ if do_builtins: for expr in exprs: ret = "\n" if expr.has_key('type'): - ret += generate_struct(expr['type'], "", expr['data']) + "\n" + ret += generate_struct(expr) + "\n"
This change passes expr['filter'] to generate_struct, if that field is set (in contrast to before, where an empty string was passed). This doesn't really make a difference, since defining the "field" key now results in linking errors (multiple definitions of that variable) where it was just ignored before (however, the behavior was undefined anyway). I just thought I'd say it. ;)
Max
Quoted 29 lines
scripts/qapi-types.py +0
-0ret += generate_type_cleanup_decl(expr['type'] + "List") fdef.write(generate_type_cleanup(expr['type'] + "List") + "\n") ret += generate_type_cleanup_decl(expr['type'])scripts/qapi-visit.py +6
-2@@ -120,7 +120,11 @@ if (!err) { ''') return ret -def generate_visit_struct(name, members): +def generate_visit_struct(expr): + + name = expr['type'] + members = expr['data'] + ret = generate_visit_struct_fields(name, "", "", members) ret += mcgen('''@@ -472,7 +476,7 @@ if do_builtins: for expr in exprs: if expr.has_key('type'): - ret = generate_visit_struct(expr['type'], expr['data']) + ret = generate_visit_struct(expr) ret += generate_visit_list(expr['type'], expr['data']) fdef.write(ret)
Re: [Qemu-devel] [PATCH 01/17] qapi-types/visit.py: Pass whole expr dict for structs
In reply to Kevin WolfQuoted 5 lines · Kevin Wolf
Signed-off-by Kevin Wolf <[email protected]>--- scripts/qapi-types.py | 11 ++++++++--- scripts/qapi-visit.py | 8 ++++++-- 2 files changed, 14 insertions(+), 5 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 2/17 qapi-types/visit.py: Inheritance for structs
In reply to Kevin WolfThis introduces a new 'base' key for struct definitions that refers to another struct type. On the JSON level, the fields of the base type are included directly into the same namespace as the fields of the defined type, like with unions. On the C level, a pointer to a struct of the base type is included.
--- docs/qapi-code-gen.txt | 17 +++++++++++++++++ scripts/qapi-types.py | 4 ++++ scripts/qapi-visit.py | 18 ++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-)
docs/qapi-code-gen.txt +17 -0
@@ -53,6 +53,23 @@ The use of '*' as a prefix to the name means the member is optional. Optional members should always be added to the end of the dictionary to preserve backwards compatibility. + +A complex type definition can specify another complex type as its base. +In this case, the fields of the base type are included as top-level fields +of the new complex type's dictionary in the QMP wire format. An example +definition is: + + { 'type': 'BlockdevOptionsGenericFormat', 'data': { 'file': 'str' } } + { 'type': 'BlockdevOptionsGenericCOWFormat', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*backing': 'str' } } + +An example BlockdevOptionsGenericCOWFormat object on the wire could use +both fields like this: + + { "file": "/some/place/my-image" + "backing": "/some/place/my-backing-file" } } + === Enumeration types === An enumeration type is a dictionary containing a single key whose value is a
scripts/qapi-types.py +4 -0
@@ -86,6 +86,7 @@ def generate_struct(expr): structname = expr.get('type', "") fieldname = expr.get('field', "") members = expr['data'] + base = expr.get('base') ret = mcgen(''' struct %(name)s
@@ -93,6 +94,9 @@ struct %(name)s ''', name=structname) + if base: + ret += generate_struct_fields({'base': base}) + ret += generate_struct_fields(members) if len(fieldname):
scripts/qapi-visit.py +16 -2
@@ -17,7 +17,7 @@ import os import getopt import errno -def generate_visit_struct_fields(name, field_prefix, fn_prefix, members): +def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base = None): substructs = [] ret = '' full_name = name if not fn_prefix else "%s_%s" % (name, fn_prefix)
@@ -42,6 +42,19 @@ static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error * name=name, full_name=full_name) push_indent() + if base: + ret += mcgen(''' +visit_start_implicit_struct(m, (void**) &(*obj)->%(c_name)s, sizeof(%(type)s), &err); +if (!err) { + visit_type_%(type)s_fields(m, obj ? &(*obj)->%(c_prefix)s%(c_name)s : NULL, &err); + error_propagate(errp, err); + err = NULL; + visit_end_implicit_struct(m, &err); +} +''', + c_prefix=c_var(field_prefix), + type=type_name(base), c_name=c_var('base')) + for argname, argentry, optional, structured in parse_args(members): if optional: ret += mcgen('''
@@ -124,8 +137,9 @@ def generate_visit_struct(expr): name = expr['type'] members = expr['data'] + base = expr.get('base') - ret = generate_visit_struct_fields(name, "", "", members) + ret = generate_visit_struct_fields(name, "", "", members, base) ret += mcgen('''
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 02/17] qapi-types/visit.py: Inheritance for structs
Quoted 77 lines · Kevin Wolf
This introduces a new 'base' key for struct definitions that refers to another struct type. On the JSON level, the fields of the base type are included directly into the same namespace as the fields of the defined type, like with unions. On the C level, a pointer to a struct of the base type is included.
Signed-off-by Kevin Wolf <[email protected]>--- docs/qapi-code-gen.txt | 17 +++++++++++++++++ scripts/qapi-types.py | 4 ++++ scripts/qapi-visit.py | 18 ++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-)docs/qapi-code-gen.txt +17
-0@@ -53,6 +53,23 @@ The use of '*' as a prefix to the name means the member is optional. Optional members should always be added to the end of the dictionary to preserve backwards compatibility. + +A complex type definition can specify another complex type as its base. +In this case, the fields of the base type are included as top-level fields +of the new complex type's dictionary in the QMP wire format. An example +definition is: + + { 'type': 'BlockdevOptionsGenericFormat', 'data': { 'file': 'str' } } + { 'type': 'BlockdevOptionsGenericCOWFormat', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*backing': 'str' } } + +An example BlockdevOptionsGenericCOWFormat object on the wire could use +both fields like this: + + { "file": "/some/place/my-image" + "backing": "/some/place/my-backing-file" } } + === Enumeration types === An enumeration type is a dictionary containing a single key whose value is ascripts/qapi-types.py +4
-0@@ -86,6 +86,7 @@ def generate_struct(expr): structname = expr.get('type', "") fieldname = expr.get('field', "") members = expr['data'] + base = expr.get('base') ret = mcgen(''' struct %(name)s@@ -93,6 +94,9 @@ struct %(name)s ''', name=structname) + if base: + ret += generate_struct_fields({'base': base}) + ret += generate_struct_fields(members) if len(fieldname):scripts/qapi-visit.py +1
-1@@ -17,7 +17,7 @@ import os import getopt import errno -def generate_visit_struct_fields(name, field_prefix, fn_prefix, members): +def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base = None): substructs = [] ret = '' full_name = name if not fn_prefix else "%s_%s" % (name, fn_prefix)
scripts/qapi-visit.py static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error * · line 47
Quoted 6 lines
scripts/qapi-visit.py +3
-0@@ -42,6 +42,19 @@ static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error * name=name, full_name=full_name) push_indent() + if base: + ret += mcgen(''' +visit_start_implicit_struct(m, (void**) &(*obj)->%(c_name)s, sizeof(%(type)s), &err);
Why do you just dereference obj here (implying it will never be NULL)...
scripts/qapi-visit.py static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error * · line 49
Quoted 2 lines
scripts/qapi-visit.py +2
-0+if (!err) { + visit_type_%(type)s_fields(m, obj ? &(*obj)->%(c_prefix)s%(c_name)s : NULL, &err);
...but then you're checking whether it is NULL before dereferencing?
Max
Quoted 22 lines
scripts/qapi-visit.py +10
-1+ error_propagate(errp, err); + err = NULL; + visit_end_implicit_struct(m, &err); +} +''', + c_prefix=c_var(field_prefix), + type=type_name(base), c_name=c_var('base')) + for argname, argentry, optional, structured in parse_args(members): if optional: ret += mcgen('''@@ -124,8 +137,9 @@ def generate_visit_struct(expr): name = expr['type'] members = expr['data'] + base = expr.get('base') - ret = generate_visit_struct_fields(name, "", "", members) + ret = generate_visit_struct_fields(name, "", "", members, base) ret += mcgen('''
Re: [Qemu-devel] [PATCH 02/17] qapi-types/visit.py: Inheritance for structs
Am 20.09.2013 um 15:33 hat Max Reitz geschrieben:
Quoted 29 lines · Kevin Wolf
Quoted 21 lines
This introduces a new 'base' key for struct definitions that refers to another struct type. On the JSON level, the fields of the base type are included directly into the same namespace as the fields of the defined type, like with unions. On the C level, a pointer to a struct of the base type is included.
Signed-off-by Kevin Wolf <[email protected]>scripts/qapi-visit.py +1
-1@@ -17,7 +17,7 @@ import os import getopt import errno -def generate_visit_struct_fields(name, field_prefix, fn_prefix, members): +def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base = None): substructs = [] ret = '' full_name = name if not fn_prefix else "%s_%s" % (name, fn_prefix)scripts/qapi-visit.py static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error * · line 46
Quoted 5 lines
scripts/qapi-visit.py +3
-0@@ -42,6 +42,19 @@ static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error * name=name, full_name=full_name) push_indent() + if base: + ret += mcgen(''' +visit_start_implicit_struct(m, (void**) &(*obj)->%(c_name)s, sizeof(%(type)s), &err);Why do you just dereference obj here (implying it will never be NULL)...
Quoted 3 lines
scripts/qapi-visit.py static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error * · line 49
Quoted 2 lines
scripts/qapi-visit.py +2
-0+if (!err) { + visit_type_%(type)s_fields(m, obj ? &(*obj)->%(c_prefix)s%(c_name)s : NULL, &err);...but then you're checking whether it is NULL before dereferencing?
Because I'm clearly not understanding what I'm doing here... I can change the first line into this:
visit_start_implicit_struct(m, obj ? (void**) &(*obj)->%(c_name)s : NULL, sizeof(%(type)s), &err);
I'm not sure what cases it would fix, but the surrounding code looks like it's doing the check, so it can't hurt. visit_start_implicit_struct seems to be able to handle NULL pointers.
Kevin
Re: [Qemu-devel] [PATCH 02/17] qapi-types/visit.py: Inheritance for structs
In reply to Kevin WolfQuoted 13 lines · Kevin Wolf
This introduces a new 'base' key for struct definitions that refers to another struct type. On the JSON level, the fields of the base type are included directly into the same namespace as the fields of the defined type, like with unions. On the C level, a pointer to a struct of the base type is included.
Signed-off-by Kevin Wolf <[email protected]>--- docs/qapi-code-gen.txt | 17 +++++++++++++++++ scripts/qapi-types.py | 4 ++++ scripts/qapi-visit.py | 18 ++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-)
docs/qapi-code-gen.txt The use of '*' as a prefix to the name means the member is optional. Optional · line 70
Quoted 5 lines
docs/qapi-code-gen.txt +5
-0+ +An example BlockdevOptionsGenericCOWFormat object on the wire could use +both fields like this: + + { "file": "/some/place/my-image"
Missing a comma.
Quoted 1 line
+ "backing": "/some/place/my-backing-file" } }
Mismatch - too many }.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 3/17 blockdev: Introduce DriveInfo.enable_auto_del
In reply to Kevin WolfBlockDriverStates shouldn't be affected by an unplugged guest device, except if created with the legacy -drive command line option or the drive_add HMP command.
Make the automatic deletion as well as cancelling of jobs conditional on an enable_auto_del boolean that is only set in drive_init().
--- blockdev.c | 17 ++++++++++++++++- include/sysemu/blockdev.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-)
blockdev.c +16 -1
@@ -89,6 +89,10 @@ void blockdev_mark_auto_del(BlockDriverState *bs) {DriveInfo *dinfo =drive_get_by_blockdev (bs); +if (dinfo && !dinfo->enable_auto_del) { +return ; + } +if (bs->job) {block_job_cancel (bs->job); }
@@ -750,6 +754,7 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to)DriveInfo *drive_init (QemuOpts *all_opts,BlockInterfaceType block_default_type) {const char *value; +DriveInfo *dinfo;/* Change legacy command line options into QMP ones */ qemu_opt_rename (all_opts,"iops" ,"throttling.iops-total" );
@@ -798,7 +803,17 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)qemu_opt_unset (all_opts,"cache" ); } -return blockdev_init (all_opts, block_default_type); +/* Actual block device init: Functionality shared with blockdev-add */ + dinfo =blockdev_init (all_opts, block_default_type); +if (dinfo ==NULL ) { + goto fail; + } + +/* Set legacy DriveInfo fields */ + dinfo->enable_auto_del = true; + +fail: +return dinfo; }void do_commit (Monitor *mon,const QDict *qdict)
include/sysemu/blockdev.h +1 -0
@@ -37,6 +37,7 @@ struct DriveInfo {int bus;int unit;int auto_del;/* see blockdev_mark_auto_del() */ +bool enable_auto_del;/* Only for legacy drive_init() */ int media_cd;int cyls, heads, secs, trans;QemuOpts *opts;
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 03/17] blockdev: Introduce DriveInfo.enable_auto_del
Quoted 12 lines · Kevin Wolf
BlockDriverStates shouldn't be affected by an unplugged guest device, except if created with the legacy -drive command line option or the
drive_addHMP command.Make the automatic deletion as well as cancelling of jobs conditional on an
enable_auto_delboolean that is only set indrive_init().Signed-off-by Kevin Wolf <[email protected]>---
+++
b/include/sysemu/blockdev.h
include/sysemu/blockdev.h struct DriveInfo { · line 40
Quoted 4 lines
include/sysemu/blockdev.h +1
-0@@ -37,6 +37,7 @@ struct DriveInfo {int bus;int unit;int auto_del;/* see blockdev_mark_auto_del() */ +bool enable_auto_del;/* Only for legacy drive_init() */
auto_del is 0-initialized, and only ever assigned to 1. Should it also be bool?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 03/17] blockdev: Introduce DriveInfo.enable_auto_del
Am 20.09.2013 um 17:03 hat Eric Blake geschrieben:
Quoted 11 lines · Kevin Wolf
Quoted 9 lines
BlockDriverStates shouldn't be affected by an unplugged guest device, except if created with the legacy -drive command line option or the
drive_addHMP command.Make the automatic deletion as well as cancelling of jobs conditional on an
enable_auto_delboolean that is only set indrive_init().Signed-off-by Kevin Wolf <[email protected]>---
Quoted 9 lines
include/sysemu/blockdev.h struct DriveInfo { · line 40
Quoted 6 lines
+++
b/include/sysemu/blockdev.hinclude/sysemu/blockdev.h +1
-0@@ -37,6 +37,7 @@ struct DriveInfo {int bus;int unit;int auto_del;/* see blockdev_mark_auto_del() */ +bool enable_auto_del;/* Only for legacy drive_init() */
auto_delis 0-initialized, and only ever assigned to 1. Should it also be bool?
Probably. A lot of qemu code uses int for boolean values. I'm trying to get rid of them in the block layer in the long run, but so far I haven't aggressively converted fields that I don't touch otherwise.
Kevin
Eric Blake
Reviewed-byRe: [Qemu-devel] [PATCH 03/17] blockdev: Introduce DriveInfo.enable_auto_del
Quoted 22 lines · Kevin Wolf
Am 20.09.2013 um 17:03 hat Eric Blake geschrieben:
Quoted 11 lines · Kevin Wolf
Quoted 9 lines
BlockDriverStates shouldn't be affected by an unplugged guest device, except if created with the legacy -drive command line option or the
drive_addHMP command.Make the automatic deletion as well as cancelling of jobs conditional on an
enable_auto_delboolean that is only set indrive_init().Signed-off-by Kevin Wolf <[email protected]>---
Quoted 9 lines
include/sysemu/blockdev.h struct DriveInfo { · line 40
Quoted 6 lines
+++
b/include/sysemu/blockdev.hinclude/sysemu/blockdev.h +1
-0@@ -37,6 +37,7 @@ struct DriveInfo {int bus;int unit;int auto_del;/* see blockdev_mark_auto_del() */ +bool enable_auto_del;/* Only for legacy drive_init() */
auto_delis 0-initialized, and only ever assigned to 1. Should it also be bool?
Quoted 3 lines
Probably. A lot of qemu code uses int for boolean values. I'm trying to get rid of them in the block layer in the long run, but so far I haven't aggressively converted fields that I don't touch otherwise.
At any rate, that's an independent question; I forgot to mention:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 03/17] blockdev: Introduce DriveInfo.enable_auto_del
In reply to Kevin WolfPATCH 4/17 blockdev: 'blockdev-add' QMP command
In reply to Kevin WolfFor examples see the changes to qmp-commands.hx.
--- blockdev.c | 57 ++++++++++++ qapi-schema.json | 270 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 59 ++++++++++++ 3 files changed, 386 insertions(+)
blockdev.c +57 -0
@@ -38,6 +38,8 @@#include "qemu/option.h" #include "qemu/config-file.h" #include "qapi/qmp/types.h" +#include "qapi-visit.h" +#include "qapi/qmp-output-visitor.h" #include "sysemu/sysemu.h" #include "block/block_int.h" #include "qmp-commands.h"
@@ -2066,6 +2068,61 @@ void qmp_block_job_complete(const char *device, Error **errp)block_job_complete (job, errp); } +void qmp_blockdev_add (BlockdevOptions *options,Error **errp) +{ +QmpOutputVisitor *ov =qmp_output_visitor_new (); +QObject *obj; +QDict *qdict; +DriveInfo *dinfo; +Error *local_err =NULL ; + +/* Require an ID in the top level */ +if (!options->has_id) { +error_setg (errp,"Block device needs an ID" ); +return ; + } + +/* TODO Sort it out in raw-posix and drive_init: Reject aio=native with +* cache.direct=false instead of silently switching to aio=threads, except +* if called from drive_init. +* +* For now, simply forbidding the combination for all drivers will do. */ +if (options->has_aio && options->aio ==BLOCKDEV_A_I_O_OPTIONS_NATIVE ) { +bool direct = options->cache->has_direct && options->cache->direct; +if (!options->has_cache && !direct) { +error_setg (errp,"aio=native requires cache.direct=true" ); + goto fail; + } + } + +visit_type_BlockdevOptions (qmp_output_get_visitor (ov), + &options,NULL , &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail; + } + + obj =qmp_output_get_qobject (ov); + qdict =qobject_to_qdict (obj); + +qdict_flatten (qdict); + +QemuOpts *opts =qemu_opts_from_qdict (&qemu_drive_opts, qdict, &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail; + }else { + dinfo =blockdev_init (opts,IF_NONE ); +if (!dinfo) { +error_setg (errp,"Could not open image" ); + goto fail; + } + } + +fail: +qmp_output_visitor_cleanup (ov); +} +static void do_qmp_query_block_jobs_one (void *opaque,BlockDriverState *bs) {BlockJobInfoList **prev = opaque;
qapi-schema.json +270 -0
273 lines not on this page · raw message
qmp-commands.hx +59 -0
62 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command
Quoted 150 lines · Kevin Wolf
For examples see the changes to qmp-commands.hx.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 57 ++++++++++++ qapi-schema.json | 270 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 59 ++++++++++++ 3 files changed, 386 insertions(+)blockdev.c +57
-0@@ -38,6 +38,8 @@#include "qemu/option.h" #include "qemu/config-file.h" #include "qapi/qmp/types.h" +#include "qapi-visit.h" +#include "qapi/qmp-output-visitor.h" #include "sysemu/sysemu.h" #include "block/block_int.h" #include "qmp-commands.h" @@ -2066,6 +2068,61 @@ void qmp_block_job_complete(const char *device, Error **errp)block_job_complete (job, errp); } +void qmp_blockdev_add (BlockdevOptions *options,Error **errp) +{ +QmpOutputVisitor *ov =qmp_output_visitor_new (); +QObject *obj; +QDict *qdict; +DriveInfo *dinfo; +Error *local_err =NULL ; + +/* Require an ID in the top level */ +if (!options->has_id) { +error_setg (errp,"Block device needs an ID" ); +return ; + } + +/* TODO Sort it out in raw-posix and drive_init: Reject aio=native with +* cache.direct=false instead of silently switching to aio=threads, except +* if called from drive_init. +* +* For now, simply forbidding the combination for all drivers will do. */ +if (options->has_aio && options->aio ==BLOCKDEV_A_I_O_OPTIONS_NATIVE ) { +bool direct = options->cache->has_direct && options->cache->direct; +if (!options->has_cache && !direct) { +error_setg (errp,"aio=native requires cache.direct=true" ); + goto fail; + } + } + +visit_type_BlockdevOptions (qmp_output_get_visitor (ov), + &options,NULL , &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail; + } + + obj =qmp_output_get_qobject (ov); + qdict =qobject_to_qdict (obj); + +qdict_flatten (qdict); + +QemuOpts *opts =qemu_opts_from_qdict (&qemu_drive_opts, qdict, &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail; + }else { + dinfo =blockdev_init (opts,IF_NONE ); +if (!dinfo) { +error_setg (errp,"Could not open image" ); + goto fail; + } + } + +fail: +qmp_output_visitor_cleanup (ov); +} +static void do_qmp_query_block_jobs_one (void *opaque,BlockDriverState *bs) {BlockJobInfoList **prev = opaque;qapi-schema.json +58
-0@@ -3902,3 +3902,273 @@ ## { 'command': 'query-rx-filter', 'data': { '*name': 'str' }, 'returns': ['RxFilterInfo'] } + + +## +# @BlockdevDiscardOptions +# +# Determines how to handle discard requests. +# +# @ignore: Ignore the request +# @unmap: Forward as an unmap request +# +# Since: 1.7 +## +{ 'enum': 'BlockdevDiscardOptions', + 'data': [ 'ignore', 'unmap' ] } + +## +# @BlockdevAIOOptions +# +# Selects the AIO backend to handle I/O requests +# +# @threads: Use qemu's thread pool +# @native: Use native AIO backend (only Linux and Windows) +# +# Since: 1.7 +## +{ 'enum': 'BlockdevAIOOptions', + 'data': [ 'threads', 'native' ] } + +## +# @BlockdevCacheOptions +# +# Includes cache-related options for block devices +# +# @writeback: #optional enables writeback mode for any caches (default: true) +# @direct: #optional enables use of O_DIRECT (bypass the host page cache; +# default: false) +# @no-flush: #optional ignore any flush requests for the device (default: +# false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevCacheOptions', + 'data': { '*writeback': 'bool', + '*direct': 'bool', + '*no-flush': 'bool' } } + +## +# @BlockdevThrottlingOptions +# +# Includes block device options related to I/O throttling. Leaving an option out +# means the same as assigning 0 and applies no throttling. +# +# @bps-total: #optional limit total bytes per second +# @bps-read: #optional limit read bytes per second +# @bps-write: #optional limit written bytes per second +# @iops-total: #optional limit total I/O operations per second +# @iops-read: #optional limit read operations per second +# @iops-write: #optional limit write operations per second
qapi-schema.json line 3972
Quoted 10 lines
qapi-schema.json +10
-0+# +# Since: 1.7 +## +{ 'type': 'BlockdevThrottlingOptions', + 'data': { '*bps-total': 'int', + '*bps-read': 'int', + '*bps-write': 'int', + '*iops-total': 'int', + '*iops-read': 'int', + '*iops-write': 'int' } }
Hm, what about burst throttling?
Quoted 46 lines
qapi-schema.json +46
-0+ +## +# @BlockdevOptionsBase +# +# Options that are available for all block devices, independent of the block +# driver. +# +# @driver: block driver name +# @id: #optional id by which the new block device can be referred to. +# This is a required option on the top level of blockdev-add, and +# currently not allowed on any other level. +# @discard: #optional discard-related options (default: ignore) +# @cache: #optional cache-related options +# @aio: #optional AIO backend (default: threads) +# @rerror: #optional how to handle read errors on the device +# (default: report) +# @werror: #optional how to handle write errors on the device +# (default: enospc) +# @throttling: #optional I/O throttling related options +# @read-only: #optional whether the block device should be read-only +# (default: false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsBase', + 'data': { 'driver': 'str', + '*id': 'str', + '*discard': 'BlockdevDiscardOptions', + '*cache': 'BlockdevCacheOptions', + '*aio': 'BlockdevAIOOptions', + '*rerror': 'BlockdevOnError', + '*werror': 'BlockdevOnError', + '*throttling': 'BlockdevThrottlingOptions', + '*read-only': 'bool' } } + +## +# @BlockdevOptionsFile +# +# Driver specific block device options for the file backend and similar +# protocols. +# +# @filename: path to the image file +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsFile',
qapi-schema.json line 4028
Quoted 10 lines
qapi-schema.json +10
-0+ 'data': { 'filename': 'str' } } + +## +# @BlockdevOptionsVVFAT +# +# Driver specific block device options for the vvfat protocol. +# +# @dir: directory to be exported as FAT image +# @fat-type: #optional FAT type: 12, 16 or 32 +# @floppy: #optional whether to export a floppy imae (true) or partitioned
s/imae/image/
Max
Quoted 213 lines
qapi-schema.json +146
-0+# hard disk (false; default) +# @rw: #optional whether to allow write operations (default: false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsVVFAT', + 'data': { 'dir': 'str', '*fat-type': 'int', '*floppy': 'bool', + '*rw': 'bool' } } + +## +# @BlockdevOptionsGenericFormat +# +# Driver specific block device options for image format that have no option +# besides their data source. +# +# @file: reference to or definition of the data source block device +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsGenericFormat', + 'data': { 'file': 'BlockdevRef' } } + +## +# @BlockdevOptionsGenericCOWFormat +# +# Driver specific block device options for image format that have no option +# besides their data source and an optional backing file. +# +# @file: reference to or definition of the data source block device +# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content). It is +# allowed to pass an empty string here in order to disable the +# default backing file. +# @copy-on-read: #optional whether to enable copy on read for the device +# (default: false). Copy on read can only be used if the +# image is not read-only. +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsGenericCOWFormat', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*backing': 'BlockdevRef', + '*copy-on-read': 'bool' } } +## +# @BlockdevOptionsQcow2 +# +# Driver specific block device options for qcow2. +# +# @file: reference to or definition of the data source block device +# +# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content) +# +# @lazy-refcounts: #optional whether to enable the lazy refcounts feature +# (default is taken from the image file) +# +# @pass-discard-request: #optional whether discard requests to the qcow2 device +# should be forwarded to the data source +# +# @pass-discard-snapshot: #optional whether discard requests for the data source +# should be issued when a snapshot operation (e.g. +# deleting a snapshot) frees clusters in the qcow2 file +# +# @pass-discard-other: #optional whether discard requests for the data source +# should be issued on other occasions where a cluster gets +# freed +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsQcow2', + 'base': 'BlockdevOptionsGenericCOWFormat', + 'data': { '*lazy-refcounts': 'bool', + '*pass-discard-request': 'bool', + '*pass-discard-snapshot': 'bool', + '*pass-discard-other': 'bool' } } + +## +# @BlockdevOptions +# +# Options for creating a block device. +# +# Since: 1.7 +## +{ 'union': 'BlockdevOptions', + 'base': 'BlockdevOptionsBase', + 'discriminator': 'driver', + 'data': { + 'file': 'BlockdevOptionsFile', + 'http': 'BlockdevOptionsFile', + 'https': 'BlockdevOptionsFile', + 'ftp': 'BlockdevOptionsFile', + 'ftps': 'BlockdevOptionsFile', + 'tftp': 'BlockdevOptionsFile', +# TODO gluster: Wait for structured options +# TODO iscsi: Wait for structured options +# TODO nbd: Should take InetSocketAddress for 'host'? +# TODO rbd: Wait for structured options +# TODO sheepdog: Wait for structured options +# TODO ssh: Should take InetSocketAddress for 'host'? + 'vvfat': 'BlockdevOptionsVVFAT', + +# TODO blkdebug: Wait for structured options +# TODO blkverify: Wait for structured options + + 'bochs': 'BlockdevOptionsGenericFormat', + 'cloop': 'BlockdevOptionsGenericFormat', + 'cow': 'BlockdevOptionsGenericCOWFormat', + 'dmg': 'BlockdevOptionsGenericFormat', + 'parallels': 'BlockdevOptionsGenericFormat', + 'qcow': 'BlockdevOptionsGenericCOWFormat', + 'qcow2': 'BlockdevOptionsQcow2', + 'qed': 'BlockdevOptionsGenericCOWFormat', + 'raw': 'BlockdevOptionsGenericFormat', + 'vdi': 'BlockdevOptionsGenericFormat', + 'vhdx': 'BlockdevOptionsGenericFormat', + 'vmdk': 'BlockdevOptionsGenericCOWFormat', + 'vpc': 'BlockdevOptionsGenericFormat' + } } + +## +# @BlockdevRef +# +# Reference to a block device. +# +# @definition: defines a new block device inline +# @reference: references the ID of an existing block device. An +# empty string means that no block device should be +# referenced. +# +# Since: 1.7 +## +{ 'union': 'BlockdevRef', + 'discriminator': {}, + 'data': { 'definition': 'BlockdevOptions', + 'reference': 'str' } } + +## +# @blockdev-add: +# +# Creates a new block device. +# +# @options: block device options for the new device +# +# Since: 1.7 +## +{ 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }qmp-commands.hx +59
-0@@ -3240,3 +3240,62 @@ Example: } EQMP + + { + .name = "blockdev-add", + .args_type = "options:q", + .mhandler.cmd_new = qmp_marshal_input_blockdev_add, + }, + +SQMP +blockdev-add +------------ + +Add a block device. + +Arguments: + +- "options": block driver options + +Example (1): + +-> { "execute": "blockdev-add", + "arguments": { "options" : { "driver": "qcow2", + "file": { "driver": "file", + "filename": "test.qcow2" } } } } +<- { "return": {} } + +Example (2): + +-> { "execute": "blockdev-add", + "arguments": { + "options": { + "driver": "qcow2", + "id": "my_disk", + "discard": "unmap", + "throttling": { + "bps-total": 1234567, + "iops-write": 100 + }, + "cache": { + "direct": true, + "writeback": true + }, + "file": { + "driver": "file", + "filename": "/tmp/test.qcow2" + }, + "backing": { + "driver": "raw", + "file": { + "driver": "file", + "filename": "/dev/fdset/4" + } + } + } + } + } + +<- { "return": {} } + +EQMP
Re: [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command
Am 20.09.2013 um 15:34 hat Max Reitz geschrieben:
Quoted 5 lines · Kevin Wolf
Quoted 3 lines
For examples see the changes to qmp-commands.hx.
Signed-off-by Kevin Wolf <[email protected]>
Quoted 8 lines
qapi-schema.json line 3972
Quoted 7 lines
qapi-schema.json +7
-0+{ 'type': 'BlockdevThrottlingOptions', + 'data': { '*bps-total': 'int', + '*bps-read': 'int', + '*bps-write': 'int', + '*iops-total': 'int', + '*iops-read': 'int', + '*iops-write': 'int' } }Hm, what about burst throttling?
Good catch. They were introduced only after I started this patch.
But in fact, as we discussed on Monday, I/O throttling and copy on read should be completely removed from the interface for now so that we can move them to a filter driver as soon as the infrastructure for them is there.
Kevin
Re: [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command
In reply to Kevin WolfQuoted 59 lines · Kevin Wolf
For examples see the changes to qmp-commands.hx.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 57 ++++++++++++ qapi-schema.json | 270 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 59 ++++++++++++ 3 files changed, 386 insertions(+)blockdev.c +35
-0@@ -38,6 +38,8 @@#include "qemu/option.h" #include "qemu/config-file.h" #include "qapi/qmp/types.h" +#include "qapi-visit.h" +#include "qapi/qmp-output-visitor.h" #include "sysemu/sysemu.h" #include "block/block_int.h" #include "qmp-commands.h" @@ -2066,6 +2068,61 @@ void qmp_block_job_complete(const char *device, Error **errp)block_job_complete (job, errp); } +void qmp_blockdev_add (BlockdevOptions *options,Error **errp) +{ +QmpOutputVisitor *ov =qmp_output_visitor_new (); +QObject *obj; +QDict *qdict; +DriveInfo *dinfo; +Error *local_err =NULL ; + +/* Require an ID in the top level */ +if (!options->has_id) { +error_setg (errp,"Block device needs an ID" ); +return ; + } + +/* TODO Sort it out in raw-posix and drive_init: Reject aio=native with +* cache.direct=false instead of silently switching to aio=threads, except +* if called from drive_init. +* +* For now, simply forbidding the combination for all drivers will do. */ +if (options->has_aio && options->aio ==BLOCKDEV_A_I_O_OPTIONS_NATIVE ) { +bool direct = options->cache->has_direct && options->cache->direct; +if (!options->has_cache && !direct) { +error_setg (errp,"aio=native requires cache.direct=true" ); + goto fail; + } + } + +visit_type_BlockdevOptions (qmp_output_get_visitor (ov), + &options,NULL , &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail; + }
blockdev.c void qmp_block_job_complete(const char *device, Error **errp) · line 2113
Quoted 10 lines
blockdev.c +10
-0+ + obj =qmp_output_get_qobject (ov); + qdict =qobject_to_qdict (obj); + +qdict_flatten (qdict); + +QemuOpts *opts =qemu_opts_from_qdict (&qemu_drive_opts, qdict, &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail;
There is nothing to execute between error_propagate and fail: maybe we could get rid of the goto.
blockdev.c void qmp_block_job_complete(const char *device, Error **errp) · line 2118
Quoted 5 lines
blockdev.c +5
-0+ }else { + dinfo =blockdev_init (opts,IF_NONE ); +if (!dinfo) { +error_setg (errp,"Could not open image" ); + goto fail;
Same.
Quoted 359 lines
blockdev.c +7
-0+ } + } + +fail: +qmp_output_visitor_cleanup (ov); +} +static void do_qmp_query_block_jobs_one (void *opaque,BlockDriverState *bs) {BlockJobInfoList **prev = opaque;qapi-schema.json +270
-0@@ -3902,3 +3902,273 @@ ## { 'command': 'query-rx-filter', 'data': { '*name': 'str' }, 'returns': ['RxFilterInfo'] } + + +## +# @BlockdevDiscardOptions +# +# Determines how to handle discard requests. +# +# @ignore: Ignore the request +# @unmap: Forward as an unmap request +# +# Since: 1.7 +## +{ 'enum': 'BlockdevDiscardOptions', + 'data': [ 'ignore', 'unmap' ] } + +## +# @BlockdevAIOOptions +# +# Selects the AIO backend to handle I/O requests +# +# @threads: Use qemu's thread pool +# @native: Use native AIO backend (only Linux and Windows) +# +# Since: 1.7 +## +{ 'enum': 'BlockdevAIOOptions', + 'data': [ 'threads', 'native' ] } + +## +# @BlockdevCacheOptions +# +# Includes cache-related options for block devices +# +# @writeback: #optional enables writeback mode for any caches (default: true) +# @direct: #optional enables use of O_DIRECT (bypass the host page cache; +# default: false) +# @no-flush: #optional ignore any flush requests for the device (default: +# false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevCacheOptions', + 'data': { '*writeback': 'bool', + '*direct': 'bool', + '*no-flush': 'bool' } } + +## +# @BlockdevThrottlingOptions +# +# Includes block device options related to I/O throttling. Leaving an option out +# means the same as assigning 0 and applies no throttling. +# +# @bps-total: #optional limit total bytes per second +# @bps-read: #optional limit read bytes per second +# @bps-write: #optional limit written bytes per second +# @iops-total: #optional limit total I/O operations per second +# @iops-read: #optional limit read operations per second +# @iops-write: #optional limit write operations per second +# +# Since: 1.7 +## +{ 'type': 'BlockdevThrottlingOptions', + 'data': { '*bps-total': 'int', + '*bps-read': 'int', + '*bps-write': 'int', + '*iops-total': 'int', + '*iops-read': 'int', + '*iops-write': 'int' } } + +## +# @BlockdevOptionsBase +# +# Options that are available for all block devices, independent of the block +# driver. +# +# @driver: block driver name +# @id: #optional id by which the new block device can be referred to. +# This is a required option on the top level of blockdev-add, and +# currently not allowed on any other level. +# @discard: #optional discard-related options (default: ignore) +# @cache: #optional cache-related options +# @aio: #optional AIO backend (default: threads) +# @rerror: #optional how to handle read errors on the device +# (default: report) +# @werror: #optional how to handle write errors on the device +# (default: enospc) +# @throttling: #optional I/O throttling related options +# @read-only: #optional whether the block device should be read-only +# (default: false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsBase', + 'data': { 'driver': 'str', + '*id': 'str', + '*discard': 'BlockdevDiscardOptions', + '*cache': 'BlockdevCacheOptions', + '*aio': 'BlockdevAIOOptions', + '*rerror': 'BlockdevOnError', + '*werror': 'BlockdevOnError', + '*throttling': 'BlockdevThrottlingOptions', + '*read-only': 'bool' } } + +## +# @BlockdevOptionsFile +# +# Driver specific block device options for the file backend and similar +# protocols. +# +# @filename: path to the image file +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsFile', + 'data': { 'filename': 'str' } } + +## +# @BlockdevOptionsVVFAT +# +# Driver specific block device options for the vvfat protocol. +# +# @dir: directory to be exported as FAT image +# @fat-type: #optional FAT type: 12, 16 or 32 +# @floppy: #optional whether to export a floppy imae (true) or partitioned +# hard disk (false; default) +# @rw: #optional whether to allow write operations (default: false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsVVFAT', + 'data': { 'dir': 'str', '*fat-type': 'int', '*floppy': 'bool', + '*rw': 'bool' } } + +## +# @BlockdevOptionsGenericFormat +# +# Driver specific block device options for image format that have no option +# besides their data source. +# +# @file: reference to or definition of the data source block device +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsGenericFormat', + 'data': { 'file': 'BlockdevRef' } } + +## +# @BlockdevOptionsGenericCOWFormat +# +# Driver specific block device options for image format that have no option +# besides their data source and an optional backing file. +# +# @file: reference to or definition of the data source block device +# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content). It is +# allowed to pass an empty string here in order to disable the +# default backing file. +# @copy-on-read: #optional whether to enable copy on read for the device +# (default: false). Copy on read can only be used if the +# image is not read-only. +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsGenericCOWFormat', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*backing': 'BlockdevRef', + '*copy-on-read': 'bool' } } +## +# @BlockdevOptionsQcow2 +# +# Driver specific block device options for qcow2. +# +# @file: reference to or definition of the data source block device +# +# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content) +# +# @lazy-refcounts: #optional whether to enable the lazy refcounts feature +# (default is taken from the image file) +# +# @pass-discard-request: #optional whether discard requests to the qcow2 device +# should be forwarded to the data source +# +# @pass-discard-snapshot: #optional whether discard requests for the data source +# should be issued when a snapshot operation (e.g. +# deleting a snapshot) frees clusters in the qcow2 file +# +# @pass-discard-other: #optional whether discard requests for the data source +# should be issued on other occasions where a cluster gets +# freed +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsQcow2', + 'base': 'BlockdevOptionsGenericCOWFormat', + 'data': { '*lazy-refcounts': 'bool', + '*pass-discard-request': 'bool', + '*pass-discard-snapshot': 'bool', + '*pass-discard-other': 'bool' } } + +## +# @BlockdevOptions +# +# Options for creating a block device. +# +# Since: 1.7 +## +{ 'union': 'BlockdevOptions', + 'base': 'BlockdevOptionsBase', + 'discriminator': 'driver', + 'data': { + 'file': 'BlockdevOptionsFile', + 'http': 'BlockdevOptionsFile', + 'https': 'BlockdevOptionsFile', + 'ftp': 'BlockdevOptionsFile', + 'ftps': 'BlockdevOptionsFile', + 'tftp': 'BlockdevOptionsFile', +# TODO gluster: Wait for structured options +# TODO iscsi: Wait for structured options +# TODO nbd: Should take InetSocketAddress for 'host'? +# TODO rbd: Wait for structured options +# TODO sheepdog: Wait for structured options +# TODO ssh: Should take InetSocketAddress for 'host'? + 'vvfat': 'BlockdevOptionsVVFAT', + +# TODO blkdebug: Wait for structured options +# TODO blkverify: Wait for structured options + + 'bochs': 'BlockdevOptionsGenericFormat', + 'cloop': 'BlockdevOptionsGenericFormat', + 'cow': 'BlockdevOptionsGenericCOWFormat', + 'dmg': 'BlockdevOptionsGenericFormat', + 'parallels': 'BlockdevOptionsGenericFormat', + 'qcow': 'BlockdevOptionsGenericCOWFormat', + 'qcow2': 'BlockdevOptionsQcow2', + 'qed': 'BlockdevOptionsGenericCOWFormat', + 'raw': 'BlockdevOptionsGenericFormat', + 'vdi': 'BlockdevOptionsGenericFormat', + 'vhdx': 'BlockdevOptionsGenericFormat', + 'vmdk': 'BlockdevOptionsGenericCOWFormat', + 'vpc': 'BlockdevOptionsGenericFormat' + } } + +## +# @BlockdevRef +# +# Reference to a block device. +# +# @definition: defines a new block device inline +# @reference: references the ID of an existing block device. An +# empty string means that no block device should be +# referenced. +# +# Since: 1.7 +## +{ 'union': 'BlockdevRef', + 'discriminator': {}, + 'data': { 'definition': 'BlockdevOptions', + 'reference': 'str' } } + +## +# @blockdev-add: +# +# Creates a new block device. +# +# @options: block device options for the new device +# +# Since: 1.7 +## +{ 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }qmp-commands.hx +59
-0@@ -3240,3 +3240,62 @@ Example: } EQMP + + { + .name = "blockdev-add", + .args_type = "options:q", + .mhandler.cmd_new = qmp_marshal_input_blockdev_add, + }, + +SQMP +blockdev-add +------------ + +Add a block device. + +Arguments: + +- "options": block driver options + +Example (1): + +-> { "execute": "blockdev-add", + "arguments": { "options" : { "driver": "qcow2", + "file": { "driver": "file", + "filename": "test.qcow2" } } } } +<- { "return": {} } + +Example (2): + +-> { "execute": "blockdev-add", + "arguments": { + "options": { + "driver": "qcow2", + "id": "my_disk", + "discard": "unmap", + "throttling": { + "bps-total": 1234567, + "iops-write": 100 + }, + "cache": { + "direct": true, + "writeback": true + }, + "file": { + "driver": "file", + "filename": "/tmp/test.qcow2" + }, + "backing": { + "driver": "raw", + "file": { + "driver": "file", + "filename": "/dev/fdset/4" + } + } + } + } + } + +<- { "return": {} } + +EQMPSignature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command
Il 20/09/2013 16:01, Benoît Canet ha scritto:
Quoted 5 lines
Quoted 3 lines
blockdev.c void qmp_block_job_complete(const char *device, Error **errp) · line 2102
Quoted 3 lines
blockdev.c +3
-0+if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail;There is nothing to execute between
error_propagateand fail: maybe we could get rid of the goto.
Or perhaps of the "else".
Paolo
Quoted 8 lines
Quoted 5 lines
blockdev.c void qmp_block_job_complete(const char *device, Error **errp) · line 2118
Quoted 5 lines
blockdev.c +5
-0+ }else { + dinfo =blockdev_init (opts,IF_NONE ); +if (!dinfo) { +error_setg (errp,"Could not open image" ); + goto fail;Same.
Quoted 2 lines
Quoted 2 lines
(quoted diff) +2
-0+ } + }
Re: [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command
Am 24.09.2013 um 12:41 hat Paolo Bonzini geschrieben:
Quoted 8 lines
Il 20/09/2013 16:01, Benoît Canet ha scritto:
Quoted 5 lines
Quoted 3 lines
blockdev.c void qmp_block_job_complete(const char *device, Error **errp) · line 2102
Quoted 3 lines
blockdev.c +3
-0+if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail;There is nothing to execute between
error_propagateand fail: maybe we could get rid of the goto.Or perhaps of the "else".
Indeed, that looks a bit strange now... It doesn't survive until the end of the series anyway, but I can remove it here. (The else branch has a useless goto as well, but I'd prefer to leave it there in case new code is added later - it's easy to miss when a goto becomes necessary.)
Kevin
Re: [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command
In reply to Kevin WolfQuoted 11 lines · Kevin Wolf
For examples see the changes to qmp-commands.hx.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 57 ++++++++++++ qapi-schema.json | 270 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 59 ++++++++++++ 3 files changed, 386 insertions(+)
qapi-schema.json line 4002
Quoted 8 lines
qapi-schema.json +8
-0+# Since: 1.7 +## +{ 'type': 'BlockdevOptionsBase', + 'data': { 'driver': 'str', + '*id': 'str', + '*discard': 'BlockdevDiscardOptions', + '*cache': 'BlockdevCacheOptions', + '*aio': 'BlockdevAIOOptions',
Is the double space intentional? Harmless, but inconsistent.
Quoted 4 lines
qapi-schema.json +4
-0+ '*rerror': 'BlockdevOnError', + '*werror': 'BlockdevOnError', + '*throttling': 'BlockdevThrottlingOptions', + '*read-only': 'bool' } }
...
qapi-schema.json line 4030
Quoted 10 lines
qapi-schema.json +10
-0+## +# @BlockdevOptionsVVFAT +# +# Driver specific block device options for the vvfat protocol. +# +# @dir: directory to be exported as FAT image +# @fat-type: #optional FAT type: 12, 16 or 32 +# @floppy: #optional whether to export a floppy imae (true) or partitioned +# hard disk (false; default) +# @rw: #optional whether to allow write operations (default: false)
Why do we have 'read-only' in base, and 'rw' in vvfat? It feels like the vvfat option is redundant.
qapi-schema.json line 4057
Quoted 7 lines
qapi-schema.json +7
-0+## +# @BlockdevOptionsGenericCOWFormat +# +# Driver specific block device options for image format that have no option +# besides their data source and an optional backing file. +# +# @file: reference to or definition of the data source block device
Do you need to document this field...
Quoted 4 lines
qapi-schema.json +4
-0+# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content). It is +# allowed to pass an empty string here in order to disable the +# default backing file.
qapi-schema.json line 4071
Quoted 10 lines
qapi-schema.json +10
-0+# @copy-on-read: #optional whether to enable copy on read for the device +# (default: false). Copy on read can only be used if the +# image is not read-only. +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsGenericCOWFormat', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*backing': 'BlockdevRef', + '*copy-on-read': 'bool' } }
...given that it is only present by inheritence?
qapi-schema.json line 4080
Quoted 9 lines
qapi-schema.json +9
-0+## +# @BlockdevOptionsQcow2 +# +# Driver specific block device options for qcow2. +# +# @file: reference to or definition of the data source block device +# +# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content)
Same question. If you DO document inherited fields, you missed @copy-on-read; if you DON'T document inherited fields, these two aren't necessary (instead, you could just have some statement about: "In addition to the fields documented in BlockdevOptionsGenericCOWFormat, this struct includes:")
qapi-schema.json line 4174
Quoted 10 lines
qapi-schema.json +10
-0+## +# @blockdev-add: +# +# Creates a new block device. +# +# @options: block device options for the new device +# +# Since: 1.7 +## +{ 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }
So deceptively simple :) All the real work is in the rest of the (cool!) enhancements to the qapi type generator.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command
Am 20.09.2013 um 17:22 hat Eric Blake geschrieben:
Quoted 12 lines · Kevin Wolf
Quoted 9 lines
For examples see the changes to qmp-commands.hx.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 57 ++++++++++++ qapi-schema.json | 270 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 59 ++++++++++++ 3 files changed, 386 insertions(+)
Quoted 10 lines
qapi-schema.json line 4002
Quoted 8 lines
qapi-schema.json +8
-0+# Since: 1.7 +## +{ 'type': 'BlockdevOptionsBase', + 'data': { 'driver': 'str', + '*id': 'str', + '*discard': 'BlockdevDiscardOptions', + '*cache': 'BlockdevCacheOptions', + '*aio': 'BlockdevAIOOptions',Is the double space intentional? Harmless, but inconsistent.
No, I'll fix it.
Quoted 6 lines
Quoted 4 lines
qapi-schema.json +4
-0+ '*rerror': 'BlockdevOnError', + '*werror': 'BlockdevOnError', + '*throttling': 'BlockdevThrottlingOptions', + '*read-only': 'bool' } }...
Quoted 13 lines
qapi-schema.json line 4030
Quoted 10 lines
qapi-schema.json +10
-0+## +# @BlockdevOptionsVVFAT +# +# Driver specific block device options for the vvfat protocol. +# +# @dir: directory to be exported as FAT image +# @fat-type: #optional FAT type: 12, 16 or 32 +# @floppy: #optional whether to export a floppy imae (true) or partitioned +# hard disk (false; default) +# @rw: #optional whether to allow write operations (default: false)Why do we have 'read-only' in base, and 'rw' in vvfat? It feels like the vvfat option is redundant.
I guess it is kind of redundant. The reason for it is that it's always been there, encoded in the filename as "fat:rw:..." - and the reason for that is that read-write vvfat is even more unreliable than read-only vvfat. So we have a read-only=false default in base, and a read-only=true default in vvfat.
I'm not sure if changing this without breaking the command line is possible; but if it is, it involves vvfat-specific magic in drive_init(), which this simply isn't worth.
Quoted 27 lines
qapi-schema.json line 4057
Quoted 7 lines
qapi-schema.json +7
-0+## +# @BlockdevOptionsGenericCOWFormat +# +# Driver specific block device options for image format that have no option +# besides their data source and an optional backing file. +# +# @file: reference to or definition of the data source block deviceDo you need to document this field...
Quoted 4 lines
qapi-schema.json +4
-0+# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content). It is +# allowed to pass an empty string here in order to disable the +# default backing file.qapi-schema.json line 4071
Quoted 10 lines
qapi-schema.json +10
-0+# @copy-on-read: #optional whether to enable copy on read for the device +# (default: false). Copy on read can only be used if the +# image is not read-only. +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsGenericCOWFormat', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*backing': 'BlockdevRef', + '*copy-on-read': 'bool' } }...given that it is only present by inheritence?
Quoted 15 lines
qapi-schema.json line 4080
Quoted 9 lines
qapi-schema.json +9
-0+## +# @BlockdevOptionsQcow2 +# +# Driver specific block device options for qcow2. +# +# @file: reference to or definition of the data source block device +# +# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content)Same question. If you DO document inherited fields, you missed @copy-on-read; if you DON'T document inherited fields, these two aren't necessary (instead, you could just have some statement about: "In addition to the fields documented in BlockdevOptionsGenericCOWFormat, this struct includes:")
Nope, I don't think they are necessary. I just wasn't careful enough when I added the inheritance. I'll drop them.
Kevin
Re: [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command
In reply to Kevin WolfQuoted 412 lines · Kevin Wolf
For examples see the changes to qmp-commands.hx.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 57 ++++++++++++ qapi-schema.json | 270 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 59 ++++++++++++ 3 files changed, 386 insertions(+)blockdev.c +57
-0@@ -38,6 +38,8 @@#include "qemu/option.h" #include "qemu/config-file.h" #include "qapi/qmp/types.h" +#include "qapi-visit.h" +#include "qapi/qmp-output-visitor.h" #include "sysemu/sysemu.h" #include "block/block_int.h" #include "qmp-commands.h" @@ -2066,6 +2068,61 @@ void qmp_block_job_complete(const char *device, Error **errp)block_job_complete (job, errp); } +void qmp_blockdev_add (BlockdevOptions *options,Error **errp) +{ +QmpOutputVisitor *ov =qmp_output_visitor_new (); +QObject *obj; +QDict *qdict; +DriveInfo *dinfo; +Error *local_err =NULL ; + +/* Require an ID in the top level */ +if (!options->has_id) { +error_setg (errp,"Block device needs an ID" ); +return ; + } + +/* TODO Sort it out in raw-posix and drive_init: Reject aio=native with +* cache.direct=false instead of silently switching to aio=threads, except +* if called from drive_init. +* +* For now, simply forbidding the combination for all drivers will do. */ +if (options->has_aio && options->aio ==BLOCKDEV_A_I_O_OPTIONS_NATIVE ) { +bool direct = options->cache->has_direct && options->cache->direct; +if (!options->has_cache && !direct) { +error_setg (errp,"aio=native requires cache.direct=true" ); + goto fail; + } + } + +visit_type_BlockdevOptions (qmp_output_get_visitor (ov), + &options,NULL , &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail; + } + + obj =qmp_output_get_qobject (ov); + qdict =qobject_to_qdict (obj); + +qdict_flatten (qdict); + +QemuOpts *opts =qemu_opts_from_qdict (&qemu_drive_opts, qdict, &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail; + }else { + dinfo =blockdev_init (opts,IF_NONE ); +if (!dinfo) { +error_setg (errp,"Could not open image" ); + goto fail; + } + } + +fail: +qmp_output_visitor_cleanup (ov); +} +static void do_qmp_query_block_jobs_one (void *opaque,BlockDriverState *bs) {BlockJobInfoList **prev = opaque;qapi-schema.json +270
-0@@ -3902,3 +3902,273 @@ ## { 'command': 'query-rx-filter', 'data': { '*name': 'str' }, 'returns': ['RxFilterInfo'] } + + +## +# @BlockdevDiscardOptions +# +# Determines how to handle discard requests. +# +# @ignore: Ignore the request +# @unmap: Forward as an unmap request +# +# Since: 1.7 +## +{ 'enum': 'BlockdevDiscardOptions', + 'data': [ 'ignore', 'unmap' ] } + +## +# @BlockdevAIOOptions +# +# Selects the AIO backend to handle I/O requests +# +# @threads: Use qemu's thread pool +# @native: Use native AIO backend (only Linux and Windows) +# +# Since: 1.7 +## +{ 'enum': 'BlockdevAIOOptions', + 'data': [ 'threads', 'native' ] } + +## +# @BlockdevCacheOptions +# +# Includes cache-related options for block devices +# +# @writeback: #optional enables writeback mode for any caches (default: true) +# @direct: #optional enables use of O_DIRECT (bypass the host page cache; +# default: false) +# @no-flush: #optional ignore any flush requests for the device (default: +# false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevCacheOptions', + 'data': { '*writeback': 'bool', + '*direct': 'bool', + '*no-flush': 'bool' } } + +## +# @BlockdevThrottlingOptions +# +# Includes block device options related to I/O throttling. Leaving an option out +# means the same as assigning 0 and applies no throttling. +# +# @bps-total: #optional limit total bytes per second +# @bps-read: #optional limit read bytes per second +# @bps-write: #optional limit written bytes per second +# @iops-total: #optional limit total I/O operations per second +# @iops-read: #optional limit read operations per second +# @iops-write: #optional limit write operations per second +# +# Since: 1.7 +## +{ 'type': 'BlockdevThrottlingOptions', + 'data': { '*bps-total': 'int', + '*bps-read': 'int', + '*bps-write': 'int', + '*iops-total': 'int', + '*iops-read': 'int', + '*iops-write': 'int' } } + +## +# @BlockdevOptionsBase +# +# Options that are available for all block devices, independent of the block +# driver. +# +# @driver: block driver name +# @id: #optional id by which the new block device can be referred to. +# This is a required option on the top level of blockdev-add, and +# currently not allowed on any other level. +# @discard: #optional discard-related options (default: ignore) +# @cache: #optional cache-related options +# @aio: #optional AIO backend (default: threads) +# @rerror: #optional how to handle read errors on the device +# (default: report) +# @werror: #optional how to handle write errors on the device +# (default: enospc) +# @throttling: #optional I/O throttling related options +# @read-only: #optional whether the block device should be read-only +# (default: false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsBase', + 'data': { 'driver': 'str', + '*id': 'str', + '*discard': 'BlockdevDiscardOptions', + '*cache': 'BlockdevCacheOptions', + '*aio': 'BlockdevAIOOptions', + '*rerror': 'BlockdevOnError', + '*werror': 'BlockdevOnError', + '*throttling': 'BlockdevThrottlingOptions', + '*read-only': 'bool' } } + +## +# @BlockdevOptionsFile +# +# Driver specific block device options for the file backend and similar +# protocols. +# +# @filename: path to the image file +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsFile', + 'data': { 'filename': 'str' } } + +## +# @BlockdevOptionsVVFAT +# +# Driver specific block device options for the vvfat protocol. +# +# @dir: directory to be exported as FAT image +# @fat-type: #optional FAT type: 12, 16 or 32 +# @floppy: #optional whether to export a floppy imae (true) or partitioned +# hard disk (false; default) +# @rw: #optional whether to allow write operations (default: false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsVVFAT', + 'data': { 'dir': 'str', '*fat-type': 'int', '*floppy': 'bool', + '*rw': 'bool' } } + +## +# @BlockdevOptionsGenericFormat +# +# Driver specific block device options for image format that have no option +# besides their data source. +# +# @file: reference to or definition of the data source block device +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsGenericFormat', + 'data': { 'file': 'BlockdevRef' } } + +## +# @BlockdevOptionsGenericCOWFormat +# +# Driver specific block device options for image format that have no option +# besides their data source and an optional backing file. +# +# @file: reference to or definition of the data source block device +# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content). It is +# allowed to pass an empty string here in order to disable the +# default backing file. +# @copy-on-read: #optional whether to enable copy on read for the device +# (default: false). Copy on read can only be used if the +# image is not read-only. +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsGenericCOWFormat', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*backing': 'BlockdevRef', + '*copy-on-read': 'bool' } } +## +# @BlockdevOptionsQcow2 +# +# Driver specific block device options for qcow2. +# +# @file: reference to or definition of the data source block device +# +# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content) +# +# @lazy-refcounts: #optional whether to enable the lazy refcounts feature +# (default is taken from the image file) +# +# @pass-discard-request: #optional whether discard requests to the qcow2 device +# should be forwarded to the data source +# +# @pass-discard-snapshot: #optional whether discard requests for the data source +# should be issued when a snapshot operation (e.g. +# deleting a snapshot) frees clusters in the qcow2 file +# +# @pass-discard-other: #optional whether discard requests for the data source +# should be issued on other occasions where a cluster gets +# freed +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsQcow2', + 'base': 'BlockdevOptionsGenericCOWFormat', + 'data': { '*lazy-refcounts': 'bool', + '*pass-discard-request': 'bool', + '*pass-discard-snapshot': 'bool', + '*pass-discard-other': 'bool' } } + +## +# @BlockdevOptions +# +# Options for creating a block device. +# +# Since: 1.7 +## +{ 'union': 'BlockdevOptions', + 'base': 'BlockdevOptionsBase', + 'discriminator': 'driver', + 'data': { + 'file': 'BlockdevOptionsFile', + 'http': 'BlockdevOptionsFile', + 'https': 'BlockdevOptionsFile', + 'ftp': 'BlockdevOptionsFile', + 'ftps': 'BlockdevOptionsFile', + 'tftp': 'BlockdevOptionsFile', +# TODO gluster: Wait for structured options +# TODO iscsi: Wait for structured options +# TODO nbd: Should take InetSocketAddress for 'host'? +# TODO rbd: Wait for structured options +# TODO sheepdog: Wait for structured options +# TODO ssh: Should take InetSocketAddress for 'host'? + 'vvfat': 'BlockdevOptionsVVFAT', + +# TODO blkdebug: Wait for structured options +# TODO blkverify: Wait for structured options + + 'bochs': 'BlockdevOptionsGenericFormat', + 'cloop': 'BlockdevOptionsGenericFormat', + 'cow': 'BlockdevOptionsGenericCOWFormat', + 'dmg': 'BlockdevOptionsGenericFormat', + 'parallels': 'BlockdevOptionsGenericFormat', + 'qcow': 'BlockdevOptionsGenericCOWFormat', + 'qcow2': 'BlockdevOptionsQcow2', + 'qed': 'BlockdevOptionsGenericCOWFormat', + 'raw': 'BlockdevOptionsGenericFormat', + 'vdi': 'BlockdevOptionsGenericFormat', + 'vhdx': 'BlockdevOptionsGenericFormat', + 'vmdk': 'BlockdevOptionsGenericCOWFormat', + 'vpc': 'BlockdevOptionsGenericFormat' + } } + +## +# @BlockdevRef +# +# Reference to a block device. +# +# @definition: defines a new block device inline +# @reference: references the ID of an existing block device. An +# empty string means that no block device should be +# referenced. +# +# Since: 1.7 +## +{ 'union': 'BlockdevRef', + 'discriminator': {}, + 'data': { 'definition': 'BlockdevOptions', + 'reference': 'str' } } + +## +# @blockdev-add: +# +# Creates a new block device. +# +# @options: block device options for the new device +# +# Since: 1.7 +## +{ 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }qmp-commands.hx +42
-0@@ -3240,3 +3240,62 @@ Example: } EQMP + + { + .name = "blockdev-add", + .args_type = "options:q", + .mhandler.cmd_new = qmp_marshal_input_blockdev_add, + }, + +SQMP +blockdev-add +------------ + +Add a block device. + +Arguments: + +- "options": block driver options + +Example (1): + +-> { "execute": "blockdev-add", + "arguments": { "options" : { "driver": "qcow2", + "file": { "driver": "file", + "filename": "test.qcow2" } } } } +<- { "return": {} } + +Example (2): + +-> { "execute": "blockdev-add", + "arguments": { + "options": { + "driver": "qcow2", + "id": "my_disk", + "discard": "unmap", + "throttling": { + "bps-total": 1234567, + "iops-write": 100 + }, + "cache": { + "direct": true, + "writeback": true + }, + "file": {
qmp-commands.hx Example: · line 3294
Quoted 10 lines
qmp-commands.hx +10
-0+ "driver": "file", + "filename": "/tmp/test.qcow2" + }, + "backing": { + "driver": "raw", + "file": { + "driver": "file", + "filename": "/dev/fdset/4" + } + }
How will BDS reference be used? Like this?
"backing": "ide0-hd0",
[As I tested this is not supported with this series, the option "backing" is not parsed in bdrv_open(). Asking because image fleecing needs this, is it already in your todo list?]
Thanks,
Fam
Quoted 11 lines
qmp-commands.hx +7
-0+ } + } + } + +<- { "return": {} } + +EQMPSignature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command
Am 24.09.2013 um 07:18 hat Fam Zheng geschrieben:
Quoted 426 lines · Kevin Wolf
Quoted 412 lines
For examples see the changes to qmp-commands.hx.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 57 ++++++++++++ qapi-schema.json | 270 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 59 ++++++++++++ 3 files changed, 386 insertions(+)blockdev.c +57
-0@@ -38,6 +38,8 @@#include "qemu/option.h" #include "qemu/config-file.h" #include "qapi/qmp/types.h" +#include "qapi-visit.h" +#include "qapi/qmp-output-visitor.h" #include "sysemu/sysemu.h" #include "block/block_int.h" #include "qmp-commands.h" @@ -2066,6 +2068,61 @@ void qmp_block_job_complete(const char *device, Error **errp)block_job_complete (job, errp); } +void qmp_blockdev_add (BlockdevOptions *options,Error **errp) +{ +QmpOutputVisitor *ov =qmp_output_visitor_new (); +QObject *obj; +QDict *qdict; +DriveInfo *dinfo; +Error *local_err =NULL ; + +/* Require an ID in the top level */ +if (!options->has_id) { +error_setg (errp,"Block device needs an ID" ); +return ; + } + +/* TODO Sort it out in raw-posix and drive_init: Reject aio=native with +* cache.direct=false instead of silently switching to aio=threads, except +* if called from drive_init. +* +* For now, simply forbidding the combination for all drivers will do. */ +if (options->has_aio && options->aio ==BLOCKDEV_A_I_O_OPTIONS_NATIVE ) { +bool direct = options->cache->has_direct && options->cache->direct; +if (!options->has_cache && !direct) { +error_setg (errp,"aio=native requires cache.direct=true" ); + goto fail; + } + } + +visit_type_BlockdevOptions (qmp_output_get_visitor (ov), + &options,NULL , &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail; + } + + obj =qmp_output_get_qobject (ov); + qdict =qobject_to_qdict (obj); + +qdict_flatten (qdict); + +QemuOpts *opts =qemu_opts_from_qdict (&qemu_drive_opts, qdict, &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); + goto fail; + }else { + dinfo =blockdev_init (opts,IF_NONE ); +if (!dinfo) { +error_setg (errp,"Could not open image" ); + goto fail; + } + } + +fail: +qmp_output_visitor_cleanup (ov); +} +static void do_qmp_query_block_jobs_one (void *opaque,BlockDriverState *bs) {BlockJobInfoList **prev = opaque;qapi-schema.json +270
-0@@ -3902,3 +3902,273 @@ ## { 'command': 'query-rx-filter', 'data': { '*name': 'str' }, 'returns': ['RxFilterInfo'] } + + +## +# @BlockdevDiscardOptions +# +# Determines how to handle discard requests. +# +# @ignore: Ignore the request +# @unmap: Forward as an unmap request +# +# Since: 1.7 +## +{ 'enum': 'BlockdevDiscardOptions', + 'data': [ 'ignore', 'unmap' ] } + +## +# @BlockdevAIOOptions +# +# Selects the AIO backend to handle I/O requests +# +# @threads: Use qemu's thread pool +# @native: Use native AIO backend (only Linux and Windows) +# +# Since: 1.7 +## +{ 'enum': 'BlockdevAIOOptions', + 'data': [ 'threads', 'native' ] } + +## +# @BlockdevCacheOptions +# +# Includes cache-related options for block devices +# +# @writeback: #optional enables writeback mode for any caches (default: true) +# @direct: #optional enables use of O_DIRECT (bypass the host page cache; +# default: false) +# @no-flush: #optional ignore any flush requests for the device (default: +# false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevCacheOptions', + 'data': { '*writeback': 'bool', + '*direct': 'bool', + '*no-flush': 'bool' } } + +## +# @BlockdevThrottlingOptions +# +# Includes block device options related to I/O throttling. Leaving an option out +# means the same as assigning 0 and applies no throttling. +# +# @bps-total: #optional limit total bytes per second +# @bps-read: #optional limit read bytes per second +# @bps-write: #optional limit written bytes per second +# @iops-total: #optional limit total I/O operations per second +# @iops-read: #optional limit read operations per second +# @iops-write: #optional limit write operations per second +# +# Since: 1.7 +## +{ 'type': 'BlockdevThrottlingOptions', + 'data': { '*bps-total': 'int', + '*bps-read': 'int', + '*bps-write': 'int', + '*iops-total': 'int', + '*iops-read': 'int', + '*iops-write': 'int' } } + +## +# @BlockdevOptionsBase +# +# Options that are available for all block devices, independent of the block +# driver. +# +# @driver: block driver name +# @id: #optional id by which the new block device can be referred to. +# This is a required option on the top level of blockdev-add, and +# currently not allowed on any other level. +# @discard: #optional discard-related options (default: ignore) +# @cache: #optional cache-related options +# @aio: #optional AIO backend (default: threads) +# @rerror: #optional how to handle read errors on the device +# (default: report) +# @werror: #optional how to handle write errors on the device +# (default: enospc) +# @throttling: #optional I/O throttling related options +# @read-only: #optional whether the block device should be read-only +# (default: false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsBase', + 'data': { 'driver': 'str', + '*id': 'str', + '*discard': 'BlockdevDiscardOptions', + '*cache': 'BlockdevCacheOptions', + '*aio': 'BlockdevAIOOptions', + '*rerror': 'BlockdevOnError', + '*werror': 'BlockdevOnError', + '*throttling': 'BlockdevThrottlingOptions', + '*read-only': 'bool' } } + +## +# @BlockdevOptionsFile +# +# Driver specific block device options for the file backend and similar +# protocols. +# +# @filename: path to the image file +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsFile', + 'data': { 'filename': 'str' } } + +## +# @BlockdevOptionsVVFAT +# +# Driver specific block device options for the vvfat protocol. +# +# @dir: directory to be exported as FAT image +# @fat-type: #optional FAT type: 12, 16 or 32 +# @floppy: #optional whether to export a floppy imae (true) or partitioned +# hard disk (false; default) +# @rw: #optional whether to allow write operations (default: false) +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsVVFAT', + 'data': { 'dir': 'str', '*fat-type': 'int', '*floppy': 'bool', + '*rw': 'bool' } } + +## +# @BlockdevOptionsGenericFormat +# +# Driver specific block device options for image format that have no option +# besides their data source. +# +# @file: reference to or definition of the data source block device +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsGenericFormat', + 'data': { 'file': 'BlockdevRef' } } + +## +# @BlockdevOptionsGenericCOWFormat +# +# Driver specific block device options for image format that have no option +# besides their data source and an optional backing file. +# +# @file: reference to or definition of the data source block device +# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content). It is +# allowed to pass an empty string here in order to disable the +# default backing file. +# @copy-on-read: #optional whether to enable copy on read for the device +# (default: false). Copy on read can only be used if the +# image is not read-only. +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsGenericCOWFormat', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*backing': 'BlockdevRef', + '*copy-on-read': 'bool' } } +## +# @BlockdevOptionsQcow2 +# +# Driver specific block device options for qcow2. +# +# @file: reference to or definition of the data source block device +# +# @backing: #optional reference to or definition of the backing file block +# device (if missing, taken from the image file content) +# +# @lazy-refcounts: #optional whether to enable the lazy refcounts feature +# (default is taken from the image file) +# +# @pass-discard-request: #optional whether discard requests to the qcow2 device +# should be forwarded to the data source +# +# @pass-discard-snapshot: #optional whether discard requests for the data source +# should be issued when a snapshot operation (e.g. +# deleting a snapshot) frees clusters in the qcow2 file +# +# @pass-discard-other: #optional whether discard requests for the data source +# should be issued on other occasions where a cluster gets +# freed +# +# Since: 1.7 +## +{ 'type': 'BlockdevOptionsQcow2', + 'base': 'BlockdevOptionsGenericCOWFormat', + 'data': { '*lazy-refcounts': 'bool', + '*pass-discard-request': 'bool', + '*pass-discard-snapshot': 'bool', + '*pass-discard-other': 'bool' } } + +## +# @BlockdevOptions +# +# Options for creating a block device. +# +# Since: 1.7 +## +{ 'union': 'BlockdevOptions', + 'base': 'BlockdevOptionsBase', + 'discriminator': 'driver', + 'data': { + 'file': 'BlockdevOptionsFile', + 'http': 'BlockdevOptionsFile', + 'https': 'BlockdevOptionsFile', + 'ftp': 'BlockdevOptionsFile', + 'ftps': 'BlockdevOptionsFile', + 'tftp': 'BlockdevOptionsFile', +# TODO gluster: Wait for structured options +# TODO iscsi: Wait for structured options +# TODO nbd: Should take InetSocketAddress for 'host'? +# TODO rbd: Wait for structured options +# TODO sheepdog: Wait for structured options +# TODO ssh: Should take InetSocketAddress for 'host'? + 'vvfat': 'BlockdevOptionsVVFAT', + +# TODO blkdebug: Wait for structured options +# TODO blkverify: Wait for structured options + + 'bochs': 'BlockdevOptionsGenericFormat', + 'cloop': 'BlockdevOptionsGenericFormat', + 'cow': 'BlockdevOptionsGenericCOWFormat', + 'dmg': 'BlockdevOptionsGenericFormat', + 'parallels': 'BlockdevOptionsGenericFormat', + 'qcow': 'BlockdevOptionsGenericCOWFormat', + 'qcow2': 'BlockdevOptionsQcow2', + 'qed': 'BlockdevOptionsGenericCOWFormat', + 'raw': 'BlockdevOptionsGenericFormat', + 'vdi': 'BlockdevOptionsGenericFormat', + 'vhdx': 'BlockdevOptionsGenericFormat', + 'vmdk': 'BlockdevOptionsGenericCOWFormat', + 'vpc': 'BlockdevOptionsGenericFormat' + } } + +## +# @BlockdevRef +# +# Reference to a block device. +# +# @definition: defines a new block device inline +# @reference: references the ID of an existing block device. An +# empty string means that no block device should be +# referenced. +# +# Since: 1.7 +## +{ 'union': 'BlockdevRef', + 'discriminator': {}, + 'data': { 'definition': 'BlockdevOptions', + 'reference': 'str' } } + +## +# @blockdev-add: +# +# Creates a new block device. +# +# @options: block device options for the new device +# +# Since: 1.7 +## +{ 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }qmp-commands.hx +42
-0@@ -3240,3 +3240,62 @@ Example: } EQMP + + { + .name = "blockdev-add", + .args_type = "options:q", + .mhandler.cmd_new = qmp_marshal_input_blockdev_add, + }, + +SQMP +blockdev-add +------------ + +Add a block device. + +Arguments: + +- "options": block driver options + +Example (1): + +-> { "execute": "blockdev-add", + "arguments": { "options" : { "driver": "qcow2", + "file": { "driver": "file", + "filename": "test.qcow2" } } } } +<- { "return": {} } + +Example (2): + +-> { "execute": "blockdev-add", + "arguments": { + "options": { + "driver": "qcow2", + "id": "my_disk", + "discard": "unmap", + "throttling": { + "bps-total": 1234567, + "iops-write": 100 + }, + "cache": { + "direct": true, + "writeback": true + }, + "file": {qmp-commands.hx Example: · line 3294
Quoted 10 lines
qmp-commands.hx +10
-0+ "driver": "file", + "filename": "/tmp/test.qcow2" + }, + "backing": { + "driver": "raw", + "file": { + "driver": "file", + "filename": "/dev/fdset/4" + } + }How will BDS reference be used? Like this?
Quoted 5 lines
"backing": "ide0-hd0",[As I tested this is not supported with this series, the option "backing" is not parsed in
bdrv_open(). Asking because image fleecing needs this, is it already in your todo list?]
Yes, this is what the syntax will be (and is already described in the schema, even though it's not actually implemented yet).
It's in my todo list, but it won't come immediately after this series. Leaving other todo items aside, one dependency that is missing for it is that we make sure that having a named BDS in the middle of a tree doesn't (allow users to) break things.
Kevin
Re: [Qemu-devel] [PATCH 04/17] blockdev: 'blockdev-add' QMP command
In reply to Kevin WolfIl 20/09/2013 13:54, Kevin Wolf ha scritto:
blockdev.c void qmp_block_job_complete(const char *device, Error **errp) · line 2090
Quoted 2 lines
blockdev.c +2
-0+* For now, simply forbidding the combination for all drivers will do. */ +if (options->has_aio && options->aio ==BLOCKDEV_A_I_O_OPTIONS_NATIVE ) {
Let's call it BlockdevAioOptions instead?
Paolo
Quoted 3 lines
blockdev.c +3
-0+bool direct = options->cache->has_direct && options->cache->direct; +if (!options->has_cache && !direct) { +error_setg (errp,"aio=native requires cache.direct=true" );
PATCH 5/17 blockdev: Separate ID generation from DriveInfo creation
In reply to Kevin Wolfblockdev-add shouldn't automatically generate IDs, but will keep most of the DriveInfo creation code.
--- blockdev.c | 32 +++++++++++++++++--------------- include/qemu/option.h | 1 + util/qemu-option.c | 6 ++++++ 3 files changed, 24 insertions(+), 15 deletions(-)
blockdev.c +17 -15
@@ -604,23 +604,25 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,return NULL ; } -/* init */ - - dinfo =g_malloc0 (sizeof (*dinfo)); -if ((buf =qemu_opts_id (opts)) !=NULL ) { - dinfo->id =g_strdup (buf); - }else { -/* no id supplied -> create one */ - dinfo->id =g_malloc0 (32 ); -if (type ==IF_IDE || type ==IF_SCSI ) +/* no id supplied -> create one */ +if (qemu_opts_id (opts) ==NULL ) { +char *new_id; +if (type ==IF_IDE || type ==IF_SCSI ) { mediastr = (media ==MEDIA_CDROM ) ?"-cd" :"-hd" ; -if (max_devs) -snprintf (dinfo->id,32 ,"%s%i%s%i" , - if_name[type], bus_id, mediastr, unit_id); -else -snprintf (dinfo->id,32 ,"%s%s%i" , - if_name[type], mediastr, unit_id); + } +if (max_devs) { + new_id =g_strdup_printf ("%s%i%s%i" , if_name[type], bus_id, + mediastr, unit_id); + }else { + new_id =g_strdup_printf ("%s%s%i" , if_name[type], + mediastr, unit_id); + } +qemu_opts_set_id (opts, new_id); } + +/* init */ + dinfo =g_malloc0 (sizeof (*dinfo)); + dinfo->id =g_strdup (qemu_opts_id (opts)); dinfo->bdrv =bdrv_new (dinfo->id); dinfo->bdrv->open_flags = snapshot ?BDRV_O_SNAPSHOT :0 ; dinfo->bdrv->read_only = ro;
include/qemu/option.h +1 -0
@@ -142,6 +142,7 @@ void qemu_opts_loc_restore(QemuOpts *opts);int qemu_opts_set (QemuOptsList *list,const char *id,const char *name,const char *value);const char *qemu_opts_id (QemuOpts *opts); +void qemu_opts_set_id (QemuOpts *opts,char *id);void qemu_opts_del (QemuOpts *opts);void qemu_opts_validate (QemuOpts *opts,const QemuOptDesc *desc,Error **errp);int qemu_opts_do_parse (QemuOpts *opts,const char *params,const char *firstname);
util/qemu-option.c +6 -0
@@ -834,6 +834,12 @@ const char *qemu_opts_id(QemuOpts *opts)return opts->id; } +/* The id string will be g_free()d by qemu_opts_del */ +void qemu_opts_set_id (QemuOpts *opts,char *id) +{ + opts->id = id; +} +void qemu_opts_del (QemuOpts *opts) {QemuOpt *opt;
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 05/17] blockdev: Separate ID generation from DriveInfo creation
Quoted 9 lines · Kevin Wolf
blockdev-add shouldn't automatically generate IDs, but will keep most of the DriveInfo creation code.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 32 +++++++++++++++++--------------- include/qemu/option.h | 1 + util/qemu-option.c | 6 ++++++ 3 files changed, 24 insertions(+), 15 deletions(-)
Re: [Qemu-devel] [PATCH 05/17] blockdev: Separate ID generation from DriveInfo creation
In reply to Kevin WolfQuoted 10 lines · Kevin Wolf
blockdev-add shouldn't automatically generate IDs, but will keep most of the DriveInfo creation code.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 32 +++++++++++++++++--------------- include/qemu/option.h | 1 + util/qemu-option.c | 6 ++++++ 3 files changed, 24 insertions(+), 15 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 05/17] blockdev: Separate ID generation from DriveInfo creation
In reply to Kevin WolfPATCH 6/17 blockdev: Pass QDict to blockdev_init()
In reply to Kevin WolfWorking on a QDict instead of a QemuOpts that accepts anything is more in line with bdrv_open(). A QDict is what qmp_blockdev_add() already has anyway, so this saves additional conversions. And last, but not least, it allows later patches to easily extract legacy options into a separate, typed QemuOpts for drive_init() (the untyped QemuOpts that drive_init already has doesn't allow access to numbers, only strings, and is therefore useless without conversion).
--- blockdev.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)
blockdev.c +15 -18
@@ -302,7 +302,8 @@ static bool check_throttle_config(ThrottleConfig *cfg, Error **errp)return true; } -static DriveInfo *blockdev_init (QemuOpts *all_opts, +/* Takes the ownership of bs_opts */ +static DriveInfo *blockdev_init (QDict *bs_opts,BlockInterfaceType block_default_type) {const char *buf;
@@ -326,7 +327,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,int ret;Error *error =NULL ;QemuOpts *opts; -QDict *bs_opts;const char *id;bool has_driver_specific_opts;BlockDriver *drv =NULL ;
@@ -334,9 +334,9 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts, translation =BIOS_ATA_TRANSLATION_AUTO ; media =MEDIA_DISK ; -/* Check common options by copying from all_opts to opts, all other options -* are stored in bs_opts. */ - id =qemu_opts_id (all_opts); +/* Check common options by copying from bs_opts to opts, all other options +* stay in bs_opts for processing by bdrv_open(). */ + id =qdict_get_try_str (bs_opts,"id" ); opts =qemu_opts_create (&qemu_common_drive_opts, id,1 , &error);if (error_is_set (&error)) {qerror_report_err (error);
@@ -344,8 +344,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,return NULL ; } - bs_opts =qdict_new (); -qemu_opts_to_qdict (all_opts, bs_opts);qemu_opts_absorb_qdict (opts, bs_opts, &error);if (error_is_set (&error)) {qerror_report_err (error);
@@ -634,7 +632,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts, dinfo->heads = heads; dinfo->secs = secs; dinfo->trans = translation; - dinfo->opts = all_opts; dinfo->refcount =1 ;if (serial !=NULL ) { dinfo->serial =g_strdup (serial);
@@ -759,6 +756,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) {const char *value;DriveInfo *dinfo; +QDict *bs_opts;/* Change legacy command line options into QMP ones */ qemu_opt_rename (all_opts,"iops" ,"throttling.iops-total" );
@@ -807,14 +805,19 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)qemu_opt_unset (all_opts,"cache" ); } +/* Get a QDict for processing the options */ + bs_opts =qdict_new (); +qemu_opts_to_qdict (all_opts, bs_opts); +/* Actual block device init: Functionality shared with blockdev-add */ - dinfo =blockdev_init (all_opts, block_default_type); + dinfo =blockdev_init (bs_opts, block_default_type);if (dinfo ==NULL ) { goto fail; }/* Set legacy DriveInfo fields */ dinfo->enable_auto_del = true; + dinfo->opts = all_opts; fail:return dinfo;
@@ -2109,16 +2112,10 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)qdict_flatten (qdict); -QemuOpts *opts =qemu_opts_from_qdict (&qemu_drive_opts, qdict, &local_err); -if (error_is_set (&local_err)) { -error_propagate (errp, local_err); + dinfo =blockdev_init (qdict,IF_NONE ); +if (!dinfo) { +error_setg (errp,"Could not open image" ); goto fail; - }else { - dinfo =blockdev_init (opts,IF_NONE ); -if (!dinfo) { -error_setg (errp,"Could not open image" ); - goto fail; - } } fail:
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 06/17] blockdev: Pass QDict to blockdev_init()
Quoted 118 lines · Kevin Wolf
Working on a QDict instead of a QemuOpts that accepts anything is more in line with
bdrv_open(). A QDict is whatqmp_blockdev_add()already has anyway, so this saves additional conversions. And last, but not least, it allows later patches to easily extract legacy options into a separate, typed QemuOpts fordrive_init()(the untyped QemuOpts thatdrive_initalready has doesn't allow access to numbers, only strings, and is therefore useless without conversion).Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)blockdev.c +15
-18@@ -302,7 +302,8 @@ static bool check_throttle_config(ThrottleConfig *cfg, Error **errp)return true; } -static DriveInfo *blockdev_init (QemuOpts *all_opts, +/* Takes the ownership of bs_opts */ +static DriveInfo *blockdev_init (QDict *bs_opts,BlockInterfaceType block_default_type) {const char *buf;@@ -326,7 +327,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,int ret;Error *error =NULL ;QemuOpts *opts; -QDict *bs_opts;const char *id;bool has_driver_specific_opts;BlockDriver *drv =NULL ;@@ -334,9 +334,9 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts, translation =BIOS_ATA_TRANSLATION_AUTO ; media =MEDIA_DISK ; -/* Check common options by copying from all_opts to opts, all other options -* are stored in bs_opts. */ - id =qemu_opts_id (all_opts); +/* Check common options by copying from bs_opts to opts, all other options +* stay in bs_opts for processing by bdrv_open(). */ + id =qdict_get_try_str (bs_opts,"id" ); opts =qemu_opts_create (&qemu_common_drive_opts, id,1 , &error);if (error_is_set (&error)) {qerror_report_err (error);@@ -344,8 +344,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,return NULL ; } - bs_opts =qdict_new (); -qemu_opts_to_qdict (all_opts, bs_opts);qemu_opts_absorb_qdict (opts, bs_opts, &error);if (error_is_set (&error)) {qerror_report_err (error);@@ -634,7 +632,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts, dinfo->heads = heads; dinfo->secs = secs; dinfo->trans = translation; - dinfo->opts = all_opts; dinfo->refcount =1 ;if (serial !=NULL ) { dinfo->serial =g_strdup (serial);@@ -759,6 +756,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) {const char *value;DriveInfo *dinfo; +QDict *bs_opts;/* Change legacy command line options into QMP ones */ qemu_opt_rename (all_opts,"iops" ,"throttling.iops-total" );@@ -807,14 +805,19 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)qemu_opt_unset (all_opts,"cache" ); } +/* Get a QDict for processing the options */ + bs_opts =qdict_new (); +qemu_opts_to_qdict (all_opts, bs_opts); +/* Actual block device init: Functionality shared with blockdev-add */ - dinfo =blockdev_init (all_opts, block_default_type); + dinfo =blockdev_init (bs_opts, block_default_type);if (dinfo ==NULL ) { goto fail; }/* Set legacy DriveInfo fields */ dinfo->enable_auto_del = true; + dinfo->opts = all_opts; fail:return dinfo;@@ -2109,16 +2112,10 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)qdict_flatten (qdict); -QemuOpts *opts =qemu_opts_from_qdict (&qemu_drive_opts, qdict, &local_err); -if (error_is_set (&local_err)) { -error_propagate (errp, local_err); + dinfo =blockdev_init (qdict,IF_NONE ); +if (!dinfo) { +error_setg (errp,"Could not open image" ); goto fail; - }else { - dinfo =blockdev_init (opts,IF_NONE ); -if (!dinfo) { -error_setg (errp,"Could not open image" ); - goto fail; - } } fail:Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 06/17] blockdev: Pass QDict to blockdev_init()
In reply to Kevin WolfQuoted 58 lines · Kevin Wolf
Working on a QDict instead of a QemuOpts that accepts anything is more in line with
bdrv_open(). A QDict is whatqmp_blockdev_add()already has anyway, so this saves additional conversions. And last, but not least, it allows later patches to easily extract legacy options into a separate, typed QemuOpts fordrive_init()(the untyped QemuOpts thatdrive_initalready has doesn't allow access to numbers, only strings, and is therefore useless without conversion).Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)blockdev.c +5
-7@@ -302,7 +302,8 @@ static bool check_throttle_config(ThrottleConfig *cfg, Error **errp)return true; } -static DriveInfo *blockdev_init (QemuOpts *all_opts, +/* Takes the ownership of bs_opts */ +static DriveInfo *blockdev_init (QDict *bs_opts,BlockInterfaceType block_default_type) {const char *buf;@@ -326,7 +327,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,int ret;Error *error =NULL ;QemuOpts *opts; -QDict *bs_opts;const char *id;bool has_driver_specific_opts;BlockDriver *drv =NULL ;@@ -334,9 +334,9 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts, translation =BIOS_ATA_TRANSLATION_AUTO ; media =MEDIA_DISK ; -/* Check common options by copying from all_opts to opts, all other options -* are stored in bs_opts. */ - id =qemu_opts_id (all_opts); +/* Check common options by copying from bs_opts to opts, all other options +* stay in bs_opts for processing by bdrv_open(). */ + id =qdict_get_try_str (bs_opts,"id" ); opts =qemu_opts_create (&qemu_common_drive_opts, id,1 , &error);if (error_is_set (&error)) {qerror_report_err (error);@@ -344,8 +344,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,return NULL ; } - bs_opts =qdict_new (); -qemu_opts_to_qdict (all_opts, bs_opts);qemu_opts_absorb_qdict (opts, bs_opts, &error);if (error_is_set (&error)) {qerror_report_err (error);
blockdev.c static DriveInfo *blockdev_init(QemuOpts *all_opts, · line 637
Quoted 4 lines
blockdev.c +0
-1@@ -634,7 +632,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts, dinfo->heads = heads; dinfo->secs = secs; dinfo->trans = translation; - dinfo->opts = all_opts;
Not setting dinfo->opts in blockdev-add will SIGSEGV drive_del:
static void drive_uninit(DriveInfo *dinfo)
{
qemu_opts_del(dinfo->opts);
...and:
void qemu_opts_del(QemuOpts *opts)
{
QemuOpt *opt;
for (;;) {
opt = QTAILQ_FIRST(&opts->head);
...Fam
Quoted 56 lines
blockdev.c +10
-10dinfo->refcount =1 ;if (serial !=NULL ) { dinfo->serial =g_strdup (serial);@@ -759,6 +756,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) {const char *value;DriveInfo *dinfo; +QDict *bs_opts;/* Change legacy command line options into QMP ones */ qemu_opt_rename (all_opts,"iops" ,"throttling.iops-total" );@@ -807,14 +805,19 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)qemu_opt_unset (all_opts,"cache" ); } +/* Get a QDict for processing the options */ + bs_opts =qdict_new (); +qemu_opts_to_qdict (all_opts, bs_opts); +/* Actual block device init: Functionality shared with blockdev-add */ - dinfo =blockdev_init (all_opts, block_default_type); + dinfo =blockdev_init (bs_opts, block_default_type);if (dinfo ==NULL ) { goto fail; }/* Set legacy DriveInfo fields */ dinfo->enable_auto_del = true; + dinfo->opts = all_opts; fail:return dinfo;@@ -2109,16 +2112,10 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)qdict_flatten (qdict); -QemuOpts *opts =qemu_opts_from_qdict (&qemu_drive_opts, qdict, &local_err); -if (error_is_set (&local_err)) { -error_propagate (errp, local_err); + dinfo =blockdev_init (qdict,IF_NONE ); +if (!dinfo) { +error_setg (errp,"Could not open image" ); goto fail; - }else { - dinfo =blockdev_init (opts,IF_NONE ); -if (!dinfo) { -error_setg (errp,"Could not open image" ); - goto fail; - } } fail:Signature · 1 line
1.8.1.4
PATCH 7/17 blockdev: Move parsing of 'media' option to drive_init
In reply to Kevin WolfThis moves as much as possible of the processing of the 'media' option to drive_init so that it can only be accessed using legacy functions, but never with anything blockdev-add related.
--- blockdev.c | 73 ++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 23 deletions(-)
blockdev.c +50 -23
@@ -302,16 +302,18 @@ static bool check_throttle_config(ThrottleConfig *cfg, Error **errp)return true; } +typedef enum {MEDIA_DISK ,MEDIA_CDROM }DriveMediaType ; +/* Takes the ownership of bs_opts */ static DriveInfo *blockdev_init (QDict *bs_opts, -BlockInterfaceType block_default_type) +BlockInterfaceType block_default_type, +DriveMediaType media) {const char *buf;const char *file =NULL ;const char *serial;const char *mediastr ="" ;BlockInterfaceType type; -enum {MEDIA_DISK ,MEDIA_CDROM } media;int bus_id, unit_id;int cyls, heads, secs, translation;int max_devs;
@@ -332,7 +334,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,BlockDriver *drv =NULL ; translation =BIOS_ATA_TRANSLATION_AUTO ; - media =MEDIA_DISK ;/* Check common options by copying from bs_opts to opts, all other options * stay in bs_opts for processing by bdrv_open(). */
@@ -419,19 +420,11 @@ static DriveInfo *blockdev_init(QDict *bs_opts, } } -if ((buf =qemu_opt_get (opts,"media" )) !=NULL ) { -if (!strcmp (buf,"disk" )) { - media =MEDIA_DISK ; - }else if (!strcmp (buf,"cdrom" )) { -if (cyls || secs || heads) { -error_report ("CHS can't be set with media=%s" , buf); -return NULL ; - } - media =MEDIA_CDROM ; - }else { -error_report ("'%s' invalid media" , buf); -return NULL ; - } +if (media ==MEDIA_CDROM ) { +if (cyls || secs || heads) { +error_report ("CHS can't be set with media=cdrom" ); +return NULL ; + } }if ((buf =qemu_opt_get (opts,"discard" )) !=NULL ) {
@@ -752,11 +745,27 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to) } } +QemuOptsList qemu_legacy_drive_opts = { + .name ="drive" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_legacy_drive_opts.head), + .desc = { + { + .name ="media" , + .type =QEMU_OPT_STRING , + .help ="media type (disk, cdrom)" , + }, + {/* end of list */ } + }, +}; +DriveInfo *drive_init (QemuOpts *all_opts,BlockInterfaceType block_default_type) {const char *value; -DriveInfo *dinfo; +DriveInfo *dinfo =NULL ;QDict *bs_opts; +QemuOpts *legacy_opts; +DriveMediaType media =MEDIA_DISK ; +Error *local_err =NULL ;/* Change legacy command line options into QMP ones */ qemu_opt_rename (all_opts,"iops" ,"throttling.iops-total" );
@@ -809,8 +818,29 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) bs_opts =qdict_new ();qemu_opts_to_qdict (all_opts, bs_opts); + legacy_opts =qemu_opts_create_nofail (&qemu_legacy_drive_opts); +qemu_opts_absorb_qdict (legacy_opts, bs_opts, &local_err); +if (error_is_set (&local_err)) { +qerror_report_err (local_err); +error_free (local_err); + goto fail; + } + +/* Media type */ + value =qemu_opt_get (legacy_opts,"media" ); +if (value) { +if (!strcmp (value,"disk" )) { + media =MEDIA_DISK ; + }else if (!strcmp (value,"cdrom" )) { + media =MEDIA_CDROM ; + }else { +error_report ("'%s' invalid media" , value); + goto fail; + } + } +/* Actual block device init: Functionality shared with blockdev-add */ - dinfo =blockdev_init (bs_opts, block_default_type); + dinfo =blockdev_init (bs_opts, block_default_type, media);if (dinfo ==NULL ) { goto fail; }
@@ -820,6 +850,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) dinfo->opts = all_opts; fail: +qemu_opts_del (legacy_opts);return dinfo; }
@@ -2112,7 +2143,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)qdict_flatten (qdict); - dinfo =blockdev_init (qdict,IF_NONE ); + dinfo =blockdev_init (qdict,IF_NONE ,MEDIA_DISK );if (!dinfo) {error_setg (errp,"Could not open image" ); goto fail;
@@ -2181,10 +2212,6 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_STRING, .help = "chs translation (auto, lba. none)", },{ - .name = "media", - .type = QEMU_OPT_STRING, - .help = "media type (disk, cdrom)", - },{ .name = "snapshot", .type = QEMU_OPT_BOOL, .help = "enable/disable snapshot mode",
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 07/17] blockdev: Move parsing of 'media' option to drive_init
Quoted 159 lines · Kevin Wolf
This moves as much as possible of the processing of the 'media' option to
drive_initso that it can only be accessed using legacy functions, but never with anything blockdev-add related.Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 73 ++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 23 deletions(-)blockdev.c +50
-23@@ -302,16 +302,18 @@ static bool check_throttle_config(ThrottleConfig *cfg, Error **errp)return true; } +typedef enum {MEDIA_DISK ,MEDIA_CDROM }DriveMediaType ; +/* Takes the ownership of bs_opts */ static DriveInfo *blockdev_init (QDict *bs_opts, -BlockInterfaceType block_default_type) +BlockInterfaceType block_default_type, +DriveMediaType media) {const char *buf;const char *file =NULL ;const char *serial;const char *mediastr ="" ;BlockInterfaceType type; -enum {MEDIA_DISK ,MEDIA_CDROM } media;int bus_id, unit_id;int cyls, heads, secs, translation;int max_devs;@@ -332,7 +334,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,BlockDriver *drv =NULL ; translation =BIOS_ATA_TRANSLATION_AUTO ; - media =MEDIA_DISK ;/* Check common options by copying from bs_opts to opts, all other options * stay in bs_opts for processing by bdrv_open(). */ @@ -419,19 +420,11 @@ static DriveInfo *blockdev_init(QDict *bs_opts, } } -if ((buf =qemu_opt_get (opts,"media" )) !=NULL ) { -if (!strcmp (buf,"disk" )) { - media =MEDIA_DISK ; - }else if (!strcmp (buf,"cdrom" )) { -if (cyls || secs || heads) { -error_report ("CHS can't be set with media=%s" , buf); -return NULL ; - } - media =MEDIA_CDROM ; - }else { -error_report ("'%s' invalid media" , buf); -return NULL ; - } +if (media ==MEDIA_CDROM ) { +if (cyls || secs || heads) { +error_report ("CHS can't be set with media=cdrom" ); +return NULL ; + } }if ((buf =qemu_opt_get (opts,"discard" )) !=NULL ) {@@ -752,11 +745,27 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to) } } +QemuOptsList qemu_legacy_drive_opts = { + .name ="drive" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_legacy_drive_opts.head), + .desc = { + { + .name ="media" , + .type =QEMU_OPT_STRING , + .help ="media type (disk, cdrom)" , + }, + {/* end of list */ } + }, +}; +DriveInfo *drive_init (QemuOpts *all_opts,BlockInterfaceType block_default_type) {const char *value; -DriveInfo *dinfo; +DriveInfo *dinfo =NULL ;QDict *bs_opts; +QemuOpts *legacy_opts; +DriveMediaType media =MEDIA_DISK ; +Error *local_err =NULL ;/* Change legacy command line options into QMP ones */ qemu_opt_rename (all_opts,"iops" ,"throttling.iops-total" );@@ -809,8 +818,29 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) bs_opts =qdict_new ();qemu_opts_to_qdict (all_opts, bs_opts); + legacy_opts =qemu_opts_create_nofail (&qemu_legacy_drive_opts); +qemu_opts_absorb_qdict (legacy_opts, bs_opts, &local_err); +if (error_is_set (&local_err)) { +qerror_report_err (local_err); +error_free (local_err); + goto fail; + } + +/* Media type */ + value =qemu_opt_get (legacy_opts,"media" ); +if (value) { +if (!strcmp (value,"disk" )) { + media =MEDIA_DISK ; + }else if (!strcmp (value,"cdrom" )) { + media =MEDIA_CDROM ; + }else { +error_report ("'%s' invalid media" , value); + goto fail; + } + } +/* Actual block device init: Functionality shared with blockdev-add */ - dinfo =blockdev_init (bs_opts, block_default_type); + dinfo =blockdev_init (bs_opts, block_default_type, media);if (dinfo ==NULL ) { goto fail; }@@ -820,6 +850,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) dinfo->opts = all_opts; fail: +qemu_opts_del (legacy_opts);return dinfo; }@@ -2112,7 +2143,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)qdict_flatten (qdict); - dinfo =blockdev_init (qdict,IF_NONE ); + dinfo =blockdev_init (qdict,IF_NONE ,MEDIA_DISK );if (!dinfo) {error_setg (errp,"Could not open image" ); goto fail;@@ -2181,10 +2212,6 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_STRING, .help = "chs translation (auto, lba. none)", },{ - .name = "media", - .type = QEMU_OPT_STRING, - .help = "media type (disk, cdrom)", - },{ .name = "snapshot", .type = QEMU_OPT_BOOL, .help = "enable/disable snapshot mode",Signature · 1 line
1.8.1.4
PATCH 8/17 blockdev: Move parsing of 'if' option to drive_init
In reply to Kevin WolfIt's always IF_NONE for blockdev-add.
--- blockdev.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-)
blockdev.c +22 -18
@@ -306,14 +306,13 @@ typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;/* Takes the ownership of bs_opts */ static DriveInfo *blockdev_init (QDict *bs_opts, -BlockInterfaceType block_default_type, +BlockInterfaceType type,DriveMediaType media) {const char *buf;const char *file =NULL ;const char *serial;const char *mediastr ="" ; -BlockInterfaceType type;int bus_id, unit_id;int cyls, heads, secs, translation;int max_devs;
@@ -374,17 +373,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, file =qemu_opt_get (opts,"file" ); serial =qemu_opt_get (opts,"serial" ); -if ((buf =qemu_opt_get (opts,"if" )) !=NULL ) { -for (type =0 ; type <IF_COUNT &&strcmp (buf, if_name[type]); type++) - ; -if (type ==IF_COUNT ) { -error_report ("unsupported bus type '%s'" , buf); -return NULL ; - } - }else { - type = block_default_type; - } - max_devs = if_max_devs[type];if (cyls || heads || secs) {
@@ -753,6 +741,10 @@ QemuOptsList qemu_legacy_drive_opts = { .name = "media", .type = QEMU_OPT_STRING, .help = "media type (disk, cdrom)", + },{ + .name = "if", + .type = QEMU_OPT_STRING, + .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", }, {/* end of list */ } },
@@ -765,6 +757,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)QDict *bs_opts;QemuOpts *legacy_opts;DriveMediaType media =MEDIA_DISK ; +BlockInterfaceType type;Error *local_err =NULL ;/* Change legacy command line options into QMP ones */
@@ -839,8 +832,23 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) } } +/* Controller type */ + value =qemu_opt_get (legacy_opts,"if" ); +if (value) { +for (type =0 ; + type <IF_COUNT &&strcmp (value, if_name[type]); + type++) { + } +if (type ==IF_COUNT ) { +error_report ("unsupported bus type '%s'" , value); +return NULL ; + } + }else { + type = block_default_type; + } +/* Actual block device init: Functionality shared with blockdev-add */ - dinfo =blockdev_init (bs_opts, block_default_type, media); + dinfo =blockdev_init (bs_opts, type, media);if (dinfo ==NULL ) { goto fail; }
@@ -2188,10 +2196,6 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_NUMBER, .help = "unit number (i.e. lun for scsi)", },{ - .name = "if", - .type = QEMU_OPT_STRING, - .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", - },{ .name = "index", .type = QEMU_OPT_NUMBER, .help = "index number",
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 08/17] blockdev: Move parsing of 'if' option to drive_init
Quoted 68 lines · Kevin Wolf
It's always
IF_NONEfor blockdev-add.Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-)blockdev.c +6
-13@@ -306,14 +306,13 @@ typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;/* Takes the ownership of bs_opts */ static DriveInfo *blockdev_init (QDict *bs_opts, -BlockInterfaceType block_default_type, +BlockInterfaceType type,DriveMediaType media) {const char *buf;const char *file =NULL ;const char *serial;const char *mediastr ="" ; -BlockInterfaceType type;int bus_id, unit_id;int cyls, heads, secs, translation;int max_devs;@@ -374,17 +373,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, file =qemu_opt_get (opts,"file" ); serial =qemu_opt_get (opts,"serial" ); -if ((buf =qemu_opt_get (opts,"if" )) !=NULL ) { -for (type =0 ; type <IF_COUNT &&strcmp (buf, if_name[type]); type++) - ; -if (type ==IF_COUNT ) { -error_report ("unsupported bus type '%s'" , buf); -return NULL ; - } - }else { - type = block_default_type; - } - max_devs = if_max_devs[type];if (cyls || heads || secs) {@@ -753,6 +741,10 @@ QemuOptsList qemu_legacy_drive_opts = { .name = "media", .type = QEMU_OPT_STRING, .help = "media type (disk, cdrom)", + },{ + .name = "if", + .type = QEMU_OPT_STRING, + .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", }, {/* end of list */ } },@@ -765,6 +757,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)QDict *bs_opts;QemuOpts *legacy_opts;DriveMediaType media =MEDIA_DISK ; +BlockInterfaceType type;Error *local_err =NULL ;/* Change legacy command line options into QMP ones */ @@ -839,8 +832,23 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) } }
blockdev.c DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 844
Quoted 10 lines
blockdev.c +10
-0+/* Controller type */ + value =qemu_opt_get (legacy_opts,"if" ); +if (value) { +for (type =0 ; + type <IF_COUNT &&strcmp (value, if_name[type]); + type++) { + } +if (type ==IF_COUNT ) { +error_report ("unsupported bus type '%s'" , value); +return NULL ;
I'd suggest "goto fail;" instead.
Max
Quoted 22 lines
blockdev.c +6
-5+ } + }else { + type = block_default_type; + } +/* Actual block device init: Functionality shared with blockdev-add */ - dinfo =blockdev_init (bs_opts, block_default_type, media); + dinfo =blockdev_init (bs_opts, type, media);if (dinfo ==NULL ) { goto fail; }@@ -2188,10 +2196,6 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_NUMBER, .help = "unit number (i.e. lun for scsi)", },{ - .name = "if", - .type = QEMU_OPT_STRING, - .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", - },{ .name = "index", .type = QEMU_OPT_NUMBER, .help = "index number",
Re: [Qemu-devel] [PATCH 08/17] blockdev: Move parsing of 'if' option to drive_init
Am 20.09.2013 um 16:47 hat Max Reitz geschrieben:
Quoted 5 lines · Kevin Wolf
Quoted 3 lines
It's always
IF_NONEfor blockdev-add.Signed-off-by Kevin Wolf <[email protected]>
Quoted 14 lines
blockdev.c DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 843
Quoted 13 lines
blockdev.c +10
-0@@ -839,8 +832,23 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) } } +/* Controller type */ + value =qemu_opt_get (legacy_opts,"if" ); +if (value) { +for (type =0 ; + type <IF_COUNT &&strcmp (value, if_name[type]); + type++) { + } +if (type ==IF_COUNT ) { +error_report ("unsupported bus type '%s'" , value); +return NULL ;I'd suggest "goto fail;" instead.
Yup, otherwise we leak legacy_opts. More instances of the same bug follow throughout the series, I'll fix them all. Thanks.
Kevin
Re: [Qemu-devel] [PATCH 08/17] blockdev: Move parsing of 'if' option to drive_init
In reply to Kevin WolfQuoted 68 lines · Kevin Wolf
It's always
IF_NONEfor blockdev-add.Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-)blockdev.c +6
-13@@ -306,14 +306,13 @@ typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;/* Takes the ownership of bs_opts */ static DriveInfo *blockdev_init (QDict *bs_opts, -BlockInterfaceType block_default_type, +BlockInterfaceType type,DriveMediaType media) {const char *buf;const char *file =NULL ;const char *serial;const char *mediastr ="" ; -BlockInterfaceType type;int bus_id, unit_id;int cyls, heads, secs, translation;int max_devs;@@ -374,17 +373,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, file =qemu_opt_get (opts,"file" ); serial =qemu_opt_get (opts,"serial" ); -if ((buf =qemu_opt_get (opts,"if" )) !=NULL ) { -for (type =0 ; type <IF_COUNT &&strcmp (buf, if_name[type]); type++) - ; -if (type ==IF_COUNT ) { -error_report ("unsupported bus type '%s'" , buf); -return NULL ; - } - }else { - type = block_default_type; - } - max_devs = if_max_devs[type];if (cyls || heads || secs) {@@ -753,6 +741,10 @@ QemuOptsList qemu_legacy_drive_opts = { .name = "media", .type = QEMU_OPT_STRING, .help = "media type (disk, cdrom)", + },{ + .name = "if", + .type = QEMU_OPT_STRING, + .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", }, {/* end of list */ } },@@ -765,6 +757,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)QDict *bs_opts;QemuOpts *legacy_opts;DriveMediaType media =MEDIA_DISK ; +BlockInterfaceType type;Error *local_err =NULL ;/* Change legacy command line options into QMP ones */ @@ -839,8 +832,23 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) } }
blockdev.c DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 844
Quoted 10 lines
blockdev.c +10
-0+/* Controller type */ + value =qemu_opt_get (legacy_opts,"if" ); +if (value) { +for (type =0 ; + type <IF_COUNT &&strcmp (value, if_name[type]); + type++) { + } +if (type ==IF_COUNT ) { +error_report ("unsupported bus type '%s'" , value); +return NULL ;
goto fail; here ?
Quoted 26 lines
blockdev.c +6
-5+ } + }else { + type = block_default_type; + } +/* Actual block device init: Functionality shared with blockdev-add */ - dinfo =blockdev_init (bs_opts, block_default_type, media); + dinfo =blockdev_init (bs_opts, type, media);if (dinfo ==NULL ) { goto fail; }@@ -2188,10 +2196,6 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_NUMBER, .help = "unit number (i.e. lun for scsi)", },{ - .name = "if", - .type = QEMU_OPT_STRING, - .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", - },{ .name = "index", .type = QEMU_OPT_NUMBER, .help = "index number",Signature · 1 line
1.8.1.4
PATCH 9/17 blockdev: Moving parsing of geometry options to drive_init
In reply to Kevin WolfThis moves all of the geometry options (cyls/heads/secs/trans) to drive_init so that they can only be accessed using legacy functions, but never with anything blockdev-add related.
--- blockdev.c | 136 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 69 insertions(+), 67 deletions(-)
blockdev.c +69 -67
@@ -314,7 +314,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,const char *serial;const char *mediastr ="" ;int bus_id, unit_id; -int cyls, heads, secs, translation;int max_devs;int index;int ro =0 ;
@@ -332,8 +331,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,bool has_driver_specific_opts;BlockDriver *drv =NULL ; - translation =BIOS_ATA_TRANSLATION_AUTO ; -/* Check common options by copying from bs_opts to opts, all other options * stay in bs_opts for processing by bdrv_open(). */ id =qdict_get_try_str (bs_opts,"id" );
@@ -362,10 +359,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, unit_id =qemu_opt_get_number (opts,"unit" ,-1 ); index =qemu_opt_get_number (opts,"index" ,-1 ); - cyls =qemu_opt_get_number (opts,"cyls" ,0 ); - heads =qemu_opt_get_number (opts,"heads" ,0 ); - secs =qemu_opt_get_number (opts,"secs" ,0 ); - snapshot =qemu_opt_get_bool (opts,"snapshot" ,0 ); ro =qemu_opt_get_bool (opts,"read-only" ,0 ); copy_on_read =qemu_opt_get_bool (opts,"copy-on-read" , false);
@@ -375,46 +368,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, max_devs = if_max_devs[type]; -if (cyls || heads || secs) { -if (cyls <1 ) { -error_report ("invalid physical cyls number" ); -return NULL ; - } -if (heads <1 ) { -error_report ("invalid physical heads number" ); -return NULL ; - } -if (secs <1 ) { -error_report ("invalid physical secs number" ); -return NULL ; - } - } - -if ((buf =qemu_opt_get (opts,"trans" )) !=NULL ) { -if (!cyls) { -error_report ("'%s' trans must be used with cyls, heads and secs" , - buf); -return NULL ; - } -if (!strcmp (buf,"none" )) - translation =BIOS_ATA_TRANSLATION_NONE ; -else if (!strcmp (buf,"lba" )) - translation =BIOS_ATA_TRANSLATION_LBA ; -else if (!strcmp (buf,"auto" )) - translation =BIOS_ATA_TRANSLATION_AUTO ; -else { -error_report ("'%s' invalid translation type" , buf); -return NULL ; - } - } - -if (media ==MEDIA_CDROM ) { -if (cyls || secs || heads) { -error_report ("CHS can't be set with media=cdrom" ); -return NULL ; - } - } -if ((buf =qemu_opt_get (opts,"discard" )) !=NULL ) {if (bdrv_parse_discard_flags (buf, &bdrv_flags) !=0 ) {error_report ("invalid discard option" );
@@ -609,10 +562,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, dinfo->type = type; dinfo->bus = bus_id; dinfo->unit = unit_id; - dinfo->cyls = cyls; - dinfo->heads = heads; - dinfo->secs = secs; - dinfo->trans = translation; dinfo->refcount =1 ;if (serial !=NULL ) { dinfo->serial =g_strdup (serial);
@@ -745,6 +694,22 @@ QemuOptsList qemu_legacy_drive_opts = { .name = "if", .type = QEMU_OPT_STRING, .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", + },{ + .name = "cyls", + .type = QEMU_OPT_NUMBER, + .help = "number of cylinders (ide disk geometry)", + },{ + .name = "heads", + .type = QEMU_OPT_NUMBER, + .help = "number of heads (ide disk geometry)", + },{ + .name = "secs", + .type = QEMU_OPT_NUMBER, + .help = "number of sectors (ide disk geometry)", + },{ + .name = "trans", + .type = QEMU_OPT_STRING, + .help = "chs translation (auto, lba. none)", }, { /* end of list */ } },
@@ -758,6 +723,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)QemuOpts *legacy_opts;DriveMediaType media =MEDIA_DISK ;BlockInterfaceType type; +int cyls, heads, secs, translation;Error *local_err =NULL ;/* Change legacy command line options into QMP ones */
@@ -847,6 +813,53 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) type = block_default_type; } +/* Geometry */ + cyls =qemu_opt_get_number (legacy_opts,"cyls" ,0 ); + heads =qemu_opt_get_number (legacy_opts,"heads" ,0 ); + secs =qemu_opt_get_number (legacy_opts,"secs" ,0 ); + +if (cyls || heads || secs) { +if (cyls <1 ) { +error_report ("invalid physical cyls number" ); +return NULL ; + } +if (heads <1 ) { +error_report ("invalid physical heads number" ); +return NULL ; + } +if (secs <1 ) { +error_report ("invalid physical secs number" ); +return NULL ; + } + } + + translation =BIOS_ATA_TRANSLATION_AUTO ; + value =qemu_opt_get (legacy_opts,"trans" ); +if (value !=NULL ) { +if (!cyls) { +error_report ("'%s' trans must be used with cyls, heads and secs" , + value); +return NULL ; + } +if (!strcmp (value,"none" )) { + translation =BIOS_ATA_TRANSLATION_NONE ; + }else if (!strcmp (value,"lba" )) { + translation =BIOS_ATA_TRANSLATION_LBA ; + }else if (!strcmp (value,"auto" )) { + translation =BIOS_ATA_TRANSLATION_AUTO ; + }else { +error_report ("'%s' invalid translation type" , value); +return NULL ; + } + } + +if (media ==MEDIA_CDROM ) { +if (cyls || secs || heads) { +error_report ("CHS can't be set with media=cdrom" ); +return NULL ; + } + } +/* Actual block device init: Functionality shared with blockdev-add */ dinfo =blockdev_init (bs_opts, type, media);if (dinfo ==NULL ) {
@@ -857,6 +870,11 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) dinfo->enable_auto_del = true; dinfo->opts = all_opts; + dinfo->cyls = cyls; + dinfo->heads = heads; + dinfo->secs = secs; + dinfo->trans = translation; + fail:qemu_opts_del (legacy_opts);return dinfo;
@@ -2200,22 +2218,6 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_NUMBER, .help = "index number", },{ - .name = "cyls", - .type = QEMU_OPT_NUMBER, - .help = "number of cylinders (ide disk geometry)", - },{ - .name = "heads", - .type = QEMU_OPT_NUMBER, - .help = "number of heads (ide disk geometry)", - },{ - .name = "secs", - .type = QEMU_OPT_NUMBER, - .help = "number of sectors (ide disk geometry)", - },{ - .name = "trans", - .type = QEMU_OPT_STRING, - .help = "chs translation (auto, lba. none)", - },{ .name = "snapshot", .type = QEMU_OPT_BOOL, .help = "enable/disable snapshot mode",
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 09/17] blockdev: Moving parsing of geometry options to drive_init
Quoted 223 lines · Kevin Wolf
This moves all of the geometry options (cyls/heads/secs/trans) to
drive_initso that they can only be accessed using legacy functions, but never with anything blockdev-add related.Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 136 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 69 insertions(+), 67 deletions(-)blockdev.c +69
-67@@ -314,7 +314,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,const char *serial;const char *mediastr ="" ;int bus_id, unit_id; -int cyls, heads, secs, translation;int max_devs;int index;int ro =0 ;@@ -332,8 +331,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,bool has_driver_specific_opts;BlockDriver *drv =NULL ; - translation =BIOS_ATA_TRANSLATION_AUTO ; -/* Check common options by copying from bs_opts to opts, all other options * stay in bs_opts for processing by bdrv_open(). */ id =qdict_get_try_str (bs_opts,"id" );@@ -362,10 +359,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, unit_id =qemu_opt_get_number (opts,"unit" ,-1 ); index =qemu_opt_get_number (opts,"index" ,-1 ); - cyls =qemu_opt_get_number (opts,"cyls" ,0 ); - heads =qemu_opt_get_number (opts,"heads" ,0 ); - secs =qemu_opt_get_number (opts,"secs" ,0 ); - snapshot =qemu_opt_get_bool (opts,"snapshot" ,0 ); ro =qemu_opt_get_bool (opts,"read-only" ,0 ); copy_on_read =qemu_opt_get_bool (opts,"copy-on-read" , false);@@ -375,46 +368,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, max_devs = if_max_devs[type]; -if (cyls || heads || secs) { -if (cyls <1 ) { -error_report ("invalid physical cyls number" ); -return NULL ; - } -if (heads <1 ) { -error_report ("invalid physical heads number" ); -return NULL ; - } -if (secs <1 ) { -error_report ("invalid physical secs number" ); -return NULL ; - } - } - -if ((buf =qemu_opt_get (opts,"trans" )) !=NULL ) { -if (!cyls) { -error_report ("'%s' trans must be used with cyls, heads and secs" , - buf); -return NULL ; - } -if (!strcmp (buf,"none" )) - translation =BIOS_ATA_TRANSLATION_NONE ; -else if (!strcmp (buf,"lba" )) - translation =BIOS_ATA_TRANSLATION_LBA ; -else if (!strcmp (buf,"auto" )) - translation =BIOS_ATA_TRANSLATION_AUTO ; -else { -error_report ("'%s' invalid translation type" , buf); -return NULL ; - } - } - -if (media ==MEDIA_CDROM ) { -if (cyls || secs || heads) { -error_report ("CHS can't be set with media=cdrom" ); -return NULL ; - } - } -if ((buf =qemu_opt_get (opts,"discard" )) !=NULL ) {if (bdrv_parse_discard_flags (buf, &bdrv_flags) !=0 ) {error_report ("invalid discard option" );@@ -609,10 +562,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, dinfo->type = type; dinfo->bus = bus_id; dinfo->unit = unit_id; - dinfo->cyls = cyls; - dinfo->heads = heads; - dinfo->secs = secs; - dinfo->trans = translation; dinfo->refcount =1 ;if (serial !=NULL ) { dinfo->serial =g_strdup (serial);@@ -745,6 +694,22 @@ QemuOptsList qemu_legacy_drive_opts = { .name = "if", .type = QEMU_OPT_STRING, .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", + },{ + .name = "cyls", + .type = QEMU_OPT_NUMBER, + .help = "number of cylinders (ide disk geometry)", + },{ + .name = "heads", + .type = QEMU_OPT_NUMBER, + .help = "number of heads (ide disk geometry)", + },{ + .name = "secs", + .type = QEMU_OPT_NUMBER, + .help = "number of sectors (ide disk geometry)", + },{ + .name = "trans", + .type = QEMU_OPT_STRING, + .help = "chs translation (auto, lba. none)", }, { /* end of list */ } },@@ -758,6 +723,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)QemuOpts *legacy_opts;DriveMediaType media =MEDIA_DISK ;BlockInterfaceType type; +int cyls, heads, secs, translation;Error *local_err =NULL ;/* Change legacy command line options into QMP ones */ @@ -847,6 +813,53 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) type = block_default_type; } +/* Geometry */ + cyls =qemu_opt_get_number (legacy_opts,"cyls" ,0 ); + heads =qemu_opt_get_number (legacy_opts,"heads" ,0 ); + secs =qemu_opt_get_number (legacy_opts,"secs" ,0 ); + +if (cyls || heads || secs) { +if (cyls <1 ) { +error_report ("invalid physical cyls number" ); +return NULL ; + } +if (heads <1 ) { +error_report ("invalid physical heads number" ); +return NULL ; + } +if (secs <1 ) { +error_report ("invalid physical secs number" ); +return NULL ; + } + } + + translation =BIOS_ATA_TRANSLATION_AUTO ; + value =qemu_opt_get (legacy_opts,"trans" ); +if (value !=NULL ) { +if (!cyls) { +error_report ("'%s' trans must be used with cyls, heads and secs" , + value); +return NULL ; + } +if (!strcmp (value,"none" )) { + translation =BIOS_ATA_TRANSLATION_NONE ; + }else if (!strcmp (value,"lba" )) { + translation =BIOS_ATA_TRANSLATION_LBA ; + }else if (!strcmp (value,"auto" )) { + translation =BIOS_ATA_TRANSLATION_AUTO ; + }else { +error_report ("'%s' invalid translation type" , value); +return NULL ; + } + } + +if (media ==MEDIA_CDROM ) { +if (cyls || secs || heads) { +error_report ("CHS can't be set with media=cdrom" ); +return NULL ; + } + } +/* Actual block device init: Functionality shared with blockdev-add */ dinfo =blockdev_init (bs_opts, type, media);if (dinfo ==NULL ) {@@ -857,6 +870,11 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) dinfo->enable_auto_del = true; dinfo->opts = all_opts; + dinfo->cyls = cyls; + dinfo->heads = heads; + dinfo->secs = secs; + dinfo->trans = translation; + fail:qemu_opts_del (legacy_opts);return dinfo;@@ -2200,22 +2218,6 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_NUMBER, .help = "index number", },{ - .name = "cyls", - .type = QEMU_OPT_NUMBER, - .help = "number of cylinders (ide disk geometry)", - },{ - .name = "heads", - .type = QEMU_OPT_NUMBER, - .help = "number of heads (ide disk geometry)", - },{ - .name = "secs", - .type = QEMU_OPT_NUMBER, - .help = "number of sectors (ide disk geometry)", - },{ - .name = "trans", - .type = QEMU_OPT_STRING, - .help = "chs translation (auto, lba. none)", - },{ .name = "snapshot", .type = QEMU_OPT_BOOL, .help = "enable/disable snapshot mode",Signature · 1 line
1.8.1.4
Aside from the "goto fail;" impacting multiple patch:
PATCH 10/17 blockdev: Move parsing of 'boot' option to drive_init
In reply to Kevin WolfIt's already ignored and only prints a deprecation message. No use in making it available in new interfaces.
--- blockdev.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
blockdev.c +11 -10
@@ -453,12 +453,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,return NULL ; } -if (qemu_opt_get (opts,"boot" ) !=NULL ) { -fprintf (stderr,"qemu-kvm: boot=on|off is deprecated and will be " -"ignored. Future versions will reject this parameter. Please " -"update your scripts.\n" ); - } - on_write_error =BLOCKDEV_ON_ERROR_ENOSPC ;if ((buf =qemu_opt_get (opts,"werror" )) !=NULL ) {if (type !=IF_IDE && type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_NONE ) {
@@ -710,6 +704,10 @@ QemuOptsList qemu_legacy_drive_opts = { .name = "trans", .type = QEMU_OPT_STRING, .help = "chs translation (auto, lba. none)", + },{ + .name = "boot", + .type = QEMU_OPT_BOOL, + .help = "(deprecated, ignored)", }, {/* end of list */ } },
@@ -785,6 +783,13 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) goto fail; } +/* Deprecated option boot=[on|off] */ +if (qemu_opt_get (legacy_opts,"boot" ) !=NULL ) { +fprintf (stderr,"qemu-kvm: boot=on|off is deprecated and will be " +"ignored. Future versions will reject this parameter. Please " +"update your scripts.\n" ); + } +/* Media type */ value =qemu_opt_get (legacy_opts,"media" );if (value) {
@@ -2325,10 +2330,6 @@ QemuOptsList qemu_common_drive_opts = { .name = "copy-on-read", .type = QEMU_OPT_BOOL, .help = "copy read data from backing file into image file", - },{ - .name = "boot", - .type = QEMU_OPT_BOOL, - .help = "(deprecated, ignored)", }, {/* end of list */ } },
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 10/17] blockdev: Move parsing of 'boot' option to drive_init
Quoted 65 lines · Kevin Wolf
It's already ignored and only prints a deprecation message. No use in making it available in new interfaces.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)blockdev.c +11
-10@@ -453,12 +453,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,return NULL ; } -if (qemu_opt_get (opts,"boot" ) !=NULL ) { -fprintf (stderr,"qemu-kvm: boot=on|off is deprecated and will be " -"ignored. Future versions will reject this parameter. Please " -"update your scripts.\n" ); - } - on_write_error =BLOCKDEV_ON_ERROR_ENOSPC ;if ((buf =qemu_opt_get (opts,"werror" )) !=NULL ) {if (type !=IF_IDE && type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_NONE ) {@@ -710,6 +704,10 @@ QemuOptsList qemu_legacy_drive_opts = { .name = "trans", .type = QEMU_OPT_STRING, .help = "chs translation (auto, lba. none)", + },{ + .name = "boot", + .type = QEMU_OPT_BOOL, + .help = "(deprecated, ignored)", }, {/* end of list */ } },@@ -785,6 +783,13 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) goto fail; } +/* Deprecated option boot=[on|off] */ +if (qemu_opt_get (legacy_opts,"boot" ) !=NULL ) { +fprintf (stderr,"qemu-kvm: boot=on|off is deprecated and will be " +"ignored. Future versions will reject this parameter. Please " +"update your scripts.\n" ); + } +/* Media type */ value =qemu_opt_get (legacy_opts,"media" );if (value) {@@ -2325,10 +2330,6 @@ QemuOptsList qemu_common_drive_opts = { .name = "copy-on-read", .type = QEMU_OPT_BOOL, .help = "copy read data from backing file into image file", - },{ - .name = "boot", - .type = QEMU_OPT_BOOL, - .help = "(deprecated, ignored)", }, {/* end of list */ } },Signature · 1 line
1.8.1.4
PATCH 11/17 blockdev: Move bus/unit/index processing to drive_init
In reply to Kevin WolfThis requires moving the automatic ID generation at the same time, so let's do that as well.
--- blockdev.c | 157 ++++++++++++++++++++++++++++--------------------------------- 1 file changed, 73 insertions(+), 84 deletions(-)
blockdev.c +73 -84
@@ -312,10 +312,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,const char *buf;const char *file =NULL ;const char *serial; -const char *mediastr ="" ; -int bus_id, unit_id; -int max_devs; -int index;int ro =0 ;int bdrv_flags =0 ;int on_read_error, on_write_error;
@@ -355,10 +351,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, has_driver_specific_opts = !!qdict_size (bs_opts);/* extract parameters */ - bus_id =qemu_opt_get_number (opts,"bus" ,0 ); - unit_id =qemu_opt_get_number (opts,"unit" ,-1 ); - index =qemu_opt_get_number (opts,"index" ,-1 ); - snapshot =qemu_opt_get_bool (opts,"snapshot" ,0 ); ro =qemu_opt_get_bool (opts,"read-only" ,0 ); copy_on_read =qemu_opt_get_bool (opts,"copy-on-read" , false);
@@ -366,8 +358,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, file =qemu_opt_get (opts,"file" ); serial =qemu_opt_get (opts,"serial" ); - max_devs = if_max_devs[type]; -if ((buf =qemu_opt_get (opts,"discard" )) !=NULL ) {if (bdrv_parse_discard_flags (buf, &bdrv_flags) !=0 ) {error_report ("invalid discard option" );
@@ -486,66 +476,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, } } -/* compute bus and unit according index */ - -if (index !=-1 ) { -if (bus_id !=0 || unit_id !=-1 ) { -error_report ("index cannot be used with bus and unit" ); -return NULL ; - } - bus_id =drive_index_to_bus_id (type, index); - unit_id =drive_index_to_unit_id (type, index); - } - -/* if user doesn't specify a unit_id, -* try to find the first free -*/ - -if (unit_id ==-1 ) { - unit_id =0 ; -while (drive_get (type, bus_id, unit_id) !=NULL ) { - unit_id++; -if (max_devs && unit_id >= max_devs) { - unit_id -= max_devs; - bus_id++; - } - } - } - -/* check unit id */ - -if (max_devs && unit_id >= max_devs) { -error_report ("unit %d too big (max is %d)" , - unit_id, max_devs -1 ); -return NULL ; - } - -/* -* catch multiple definitions -*/ - -if (drive_get (type, bus_id, unit_id) !=NULL ) { -error_report ("drive with bus=%d, unit=%d (index=%d) exists" , - bus_id, unit_id, index); -return NULL ; - } - -/* no id supplied -> create one */ -if (qemu_opts_id (opts) ==NULL ) { -char *new_id; -if (type ==IF_IDE || type ==IF_SCSI ) { - mediastr = (media ==MEDIA_CDROM ) ?"-cd" :"-hd" ; - } -if (max_devs) { - new_id =g_strdup_printf ("%s%i%s%i" , if_name[type], bus_id, - mediastr, unit_id); - }else { - new_id =g_strdup_printf ("%s%s%i" , if_name[type], - mediastr, unit_id); - } -qemu_opts_set_id (opts, new_id); - } -/* init */ dinfo =g_malloc0 (sizeof (*dinfo)); dinfo->id =g_strdup (qemu_opts_id (opts));
@@ -554,8 +484,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, dinfo->bdrv->read_only = ro; dinfo->devaddr = devaddr; dinfo->type = type; - dinfo->bus = bus_id; - dinfo->unit = unit_id; dinfo->refcount =1 ;if (serial !=NULL ) { dinfo->serial =g_strdup (serial);
@@ -681,6 +609,18 @@ QemuOptsList qemu_legacy_drive_opts = { .head = QTAILQ_HEAD_INITIALIZER(qemu_legacy_drive_opts.head), .desc = { { + .name = "bus", + .type = QEMU_OPT_NUMBER, + .help = "bus number", + },{ + .name = "unit", + .type = QEMU_OPT_NUMBER, + .help = "unit number (i.e. lun for scsi)", + },{ + .name = "index", + .type = QEMU_OPT_NUMBER, + .help = "index number", + },{ .name = "media", .type = QEMU_OPT_STRING, .help = "media type (disk, cdrom)",
@@ -722,6 +662,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)DriveMediaType media =MEDIA_DISK ;BlockInterfaceType type;int cyls, heads, secs, translation; +int max_devs, bus_id, unit_id, index;Error *local_err =NULL ;/* Change legacy command line options into QMP ones */
@@ -865,6 +806,63 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) } } +/* Device address specified by bus/unit or index. +* If none was specified, try to find the first free one. */ + bus_id =qemu_opt_get_number (legacy_opts,"bus" ,0 ); + unit_id =qemu_opt_get_number (legacy_opts,"unit" ,-1 ); + index =qemu_opt_get_number (legacy_opts,"index" ,-1 ); + + max_devs = if_max_devs[type]; + +if (index !=-1 ) { +if (bus_id !=0 || unit_id !=-1 ) { +error_report ("index cannot be used with bus and unit" ); + goto fail; + } + bus_id =drive_index_to_bus_id (type, index); + unit_id =drive_index_to_unit_id (type, index); + } + +if (unit_id ==-1 ) { + unit_id =0 ; +while (drive_get (type, bus_id, unit_id) !=NULL ) { + unit_id++; +if (max_devs && unit_id >= max_devs) { + unit_id -= max_devs; + bus_id++; + } + } + } + +if (max_devs && unit_id >= max_devs) { +error_report ("unit %d too big (max is %d)" , unit_id, max_devs -1 ); + goto fail; + } + +if (drive_get (type, bus_id, unit_id) !=NULL ) { +error_report ("drive with bus=%d, unit=%d (index=%d) exists" , + bus_id, unit_id, index); + goto fail; + } + +/* no id supplied -> create one */ +if (qemu_opts_id (all_opts) ==NULL ) { +char *new_id; +const char *mediastr ="" ; +if (type ==IF_IDE || type ==IF_SCSI ) { + mediastr = (media ==MEDIA_CDROM ) ?"-cd" :"-hd" ; + } +if (max_devs) { + new_id =g_strdup_printf ("%s%i%s%i" , if_name[type], bus_id, + mediastr, unit_id); + }else { + new_id =g_strdup_printf ("%s%s%i" , if_name[type], + mediastr, unit_id); + } +qdict_put (bs_opts,"id" ,qstring_from_str (new_id)); +g_free (new_id); + } +/* Actual block device init: Functionality shared with blockdev-add */ dinfo =blockdev_init (bs_opts, type, media);if (dinfo ==NULL ) {
@@ -880,6 +878,9 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) dinfo->secs = secs; dinfo->trans = translation; + dinfo->bus = bus_id; + dinfo->unit = unit_id; + fail:qemu_opts_del (legacy_opts);return dinfo;
@@ -2211,18 +2212,6 @@ QemuOptsList qemu_common_drive_opts = { .head = QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head), .desc = { { - .name = "bus", - .type = QEMU_OPT_NUMBER, - .help = "bus number", - },{ - .name = "unit", - .type = QEMU_OPT_NUMBER, - .help = "unit number (i.e. lun for scsi)", - },{ - .name = "index", - .type = QEMU_OPT_NUMBER, - .help = "index number", - },{ .name = "snapshot", .type = QEMU_OPT_BOOL, .help = "enable/disable snapshot mode",
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 11/17] blockdev: Move bus/unit/index processing to drive_init
Quoted 7 lines · Kevin Wolf
This requires moving the automatic ID generation at the same time, so let's do that as well.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 157 ++++++++++++++++++++++++++++--------------------------------- 1 file changed, 73 insertions(+), 84 deletions(-)
PATCH 12/17 blockdev: Move virtio-blk device creation to drive_init
In reply to Kevin Wolf--- blockdev.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-)
blockdev.c +27 -27
@@ -315,7 +315,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,int ro =0 ;int bdrv_flags =0 ;int on_read_error, on_write_error; -const char *devaddr;DriveInfo *dinfo;ThrottleConfig cfg;int snapshot =0 ;
@@ -469,20 +468,12 @@ static DriveInfo *blockdev_init(QDict *bs_opts, } } -if ((devaddr =qemu_opt_get (opts,"addr" )) !=NULL ) { -if (type !=IF_VIRTIO ) { -error_report ("addr is not supported by this bus type" ); -return NULL ; - } - } -/* init */ dinfo =g_malloc0 (sizeof (*dinfo)); dinfo->id =g_strdup (qemu_opts_id (opts)); dinfo->bdrv =bdrv_new (dinfo->id); dinfo->bdrv->open_flags = snapshot ?BDRV_O_SNAPSHOT :0 ; dinfo->bdrv->read_only = ro; - dinfo->devaddr = devaddr; dinfo->type = type; dinfo->refcount =1 ;if (serial !=NULL ) {
@@ -509,22 +500,8 @@ static DriveInfo *blockdev_init(QDict *bs_opts,case IF_FLOPPY :case IF_PFLASH :case IF_MTD : -break ;case IF_VIRTIO : - { -/* add virtio block device */ -QemuOpts *devopts; - devopts =qemu_opts_create_nofail (qemu_find_opts ("device" )); -if (arch_type ==QEMU_ARCH_S390X ) { -qemu_opt_set (devopts,"driver" ,"virtio-blk-s390" ); - }else { -qemu_opt_set (devopts,"driver" ,"virtio-blk-pci" ); - } -qemu_opt_set (devopts,"drive" , dinfo->id); -if (devaddr) -qemu_opt_set (devopts,"addr" , devaddr);break ; - }default :abort (); }
@@ -648,6 +625,10 @@ QemuOptsList qemu_legacy_drive_opts = { .name = "boot", .type = QEMU_OPT_BOOL, .help = "(deprecated, ignored)", + },{ + .name = "addr", + .type = QEMU_OPT_STRING, + .help = "pci address (virtio only)", }, {/* end of list */ } },
@@ -663,6 +644,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)BlockInterfaceType type;int cyls, heads, secs, translation;int max_devs, bus_id, unit_id, index; +const char *devaddr;Error *local_err =NULL ;/* Change legacy command line options into QMP ones */
@@ -863,6 +845,27 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)g_free (new_id); } +/* Add virtio block device */ + devaddr =qemu_opt_get (legacy_opts,"addr" ); +if (devaddr && type !=IF_VIRTIO ) { +error_report ("addr is not supported by this bus type" ); +return NULL ; + } + +if (type ==IF_VIRTIO ) { +QemuOpts *devopts; + devopts =qemu_opts_create_nofail (qemu_find_opts ("device" )); +if (arch_type ==QEMU_ARCH_S390X ) { +qemu_opt_set (devopts,"driver" ,"virtio-blk-s390" ); + }else { +qemu_opt_set (devopts,"driver" ,"virtio-blk-pci" ); + } +qemu_opt_set (devopts,"drive" ,qdict_get_str (bs_opts,"id" )); +if (devaddr) { +qemu_opt_set (devopts,"addr" , devaddr); + } + } +/* Actual block device init: Functionality shared with blockdev-add */ dinfo =blockdev_init (bs_opts, type, media);if (dinfo ==NULL ) {
@@ -880,6 +883,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) dinfo->bus = bus_id; dinfo->unit = unit_id; + dinfo->devaddr = devaddr; fail:qemu_opts_del (legacy_opts);
@@ -2256,10 +2260,6 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_STRING, .help = "write error action", },{ - .name = "addr", - .type = QEMU_OPT_STRING, - .help = "pci address (virtio only)", - },{ .name = "read-only", .type = QEMU_OPT_BOOL, .help = "open drive file as read-only",
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 12/17] blockdev: Move virtio-blk device creation to drive_init
Quoted 4 lines · Kevin Wolf
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-)
Aside from return NULL instead of goto fail:
PATCH 13/17 blockdev: Remove IF_* check for read-only blockdev_init
In reply to Kevin WolfIF_NONE allows read-only, which makes forbidding it in this place for other types pretty much pointless.
Instead, make sure that all devices for which the check would have errored out check in their init function that they don't get a read-only BlockDriverState. This catches even cases where IF_NONE and -device is used.
--- blockdev.c | 6 ------ hw/block/m25p80.c | 5 +++++ hw/block/xen_disk.c | 6 ++++++ hw/sd/milkymist-memcard.c | 4 ++++ hw/sd/omap_mmc.c | 8 ++++++++ hw/sd/pl181.c | 4 ++++ hw/sd/pxa2xx_mmci.c | 4 ++++ hw/sd/sd.c | 5 +++++ hw/sd/sdhci.c | 4 ++++ hw/sd/ssi-sd.c | 3 +++ tests/qemu-iotests/051.out | 5 ++++- 11 files changed, 47 insertions(+), 7 deletions(-)
blockdev.c +0 -6
@@ -529,12 +529,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,if (media ==MEDIA_CDROM ) {/* CDROM is fine for any interface, don't check. */ ro =1 ; - }else if (ro ==1 ) { -if (type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_FLOPPY && - type !=IF_NONE && type !=IF_PFLASH ) { -error_report ("read-only not supported by this bus type" ); - goto err; - } } bdrv_flags |= ro ?0 :BDRV_O_RDWR ;
hw/block/m25p80.c +5 -0
@@ -624,6 +624,11 @@ static int m25p80_init(SSISlave *ss)if (dinfo && dinfo->bdrv) {DB_PRINT_L (0 ,"Binding to IF_MTD drive\n" ); s->bdrv = dinfo->bdrv; +if (bdrv_is_read_only (s->bdrv)) { +fprintf (stderr,"Can't use a read-only drive" ); +return 1 ; + } +/* FIXME: Move to late init */ if (bdrv_read (s->bdrv,0 , s->storage,DIV_ROUND_UP (s->size,BDRV_SECTOR_SIZE ))) {
hw/block/xen_disk.c +6 -0
@@ -39,6 +39,7 @@#include "hw/xen/xen_backend.h" #include "xen_blkif.h" #include "sysemu/blockdev.h" +#include "qemu/error-report.h" /* ------------------------------------------------------------- */
@@ -829,6 +830,11 @@ static int blk_connect(struct XenDevice *xendev)/* setup via qemu cmdline -> already setup for us */ xen_be_printf (&blkdev->xendev,2 ,"get configured bdrv (cmdline setup)\n" ); blkdev->bs = blkdev->dinfo->bdrv; +if (bdrv_is_read_only (blkdev->bs) && !readonly) { +error_report ("Unexpected read-only drive" ); + blkdev->bs =NULL ; +return -1 ; + }/* blkdev->bs is not create by us, we get a reference * so we can bdrv_unref() unconditionally */ bdrv_ref (blkdev->bs);
hw/sd/milkymist-memcard.c +4 -0
@@ -255,6 +255,10 @@ static int milkymist_memcard_init(SysBusDevice *dev) dinfo =drive_get_next (IF_SD ); s->card =sd_init (dinfo ? dinfo->bdrv :NULL , false); +if (s->card ==NULL ) { +return -1 ; + } + s->enabled = dinfo ?bdrv_is_inserted (dinfo->bdrv) :0 ; memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s,
hw/sd/omap_mmc.c +8 -0
@@ -593,6 +593,10 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base,/* Instantiate the storage */ s->card =sd_init (bd, false); +if (s->card ==NULL ) { +fprintf (stderr,"Failed to initialise SD card\n" ); +exit (1 ); + }return s; }
@@ -618,6 +622,10 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,/* Instantiate the storage */ s->card =sd_init (bd, false); +if (s->card ==NULL ) { +fprintf (stderr,"Failed to initialise SD card\n" ); +exit (1 ); + } s->cdet =qemu_allocate_irqs (omap_mmc_cover_cb, s,1 )[0 ];sd_set_cb (s->card,NULL , s->cdet);
hw/sd/pl181.c +4 -0
@@ -491,6 +491,10 @@ static int pl181_init(SysBusDevice *sbd)qdev_init_gpio_out (dev, s->cardstatus,2 ); dinfo =drive_get_next (IF_SD ); s->card =sd_init (dinfo ? dinfo->bdrv :NULL , false); +if (s->card ==NULL ) { +return -1 ; + } +return 0 ; }
hw/sd/pxa2xx_mmci.c +4 -0
@@ -539,6 +539,10 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,/* Instantiate the actual storage */ s->card =sd_init (bd, false); +if (s->card ==NULL ) { +fprintf (stderr,"Failed to initialise SD card\n" ); +exit (1 ); + }register_savevm (NULL ,"pxa2xx_mmci" ,0 ,0 , pxa2xx_mmci_save, pxa2xx_mmci_load, s);
hw/sd/sd.c +5 -0
@@ -494,6 +494,11 @@ SDState *sd_init(BlockDriverState *bs, bool is_spi) {SDState *sd; +if (bdrv_is_read_only (bs)) { +fprintf (stderr,"sd_init: Cannot use read-only drive\n" ); +return NULL ; + } + sd = (SDState *)g_malloc0 (sizeof (SDState)); sd->buf =qemu_blockalign (bs,512 ); sd->spi = is_spi;
hw/sd/sdhci.c +4 -0
@@ -1166,6 +1166,10 @@ static void sdhci_initfn(Object *obj) di =drive_get_next (IF_SD ); s->card =sd_init (di ? di->bdrv :NULL , false); +if (s->card ==NULL ) { +fprintf (stderr,"Failed to initialise SD card\n" ); +exit (1 ); + } s->eject_cb =qemu_allocate_irqs (sdhci_insert_eject_cb, s,1 )[0 ]; s->ro_cb =qemu_allocate_irqs (sdhci_card_readonly_cb, s,1 )[0 ];sd_set_cb (s->card, s->ro_cb, s->eject_cb);
hw/sd/ssi-sd.c +3 -0
@@ -246,6 +246,9 @@ static int ssi_sd_init(SSISlave *dev) s->mode =SSI_SD_CMD ; dinfo =drive_get_next (IF_SD ); s->sd =sd_init (dinfo ? dinfo->bdrv :NULL , true); +if (s->sd ==NULL ) { +return -1 ; + }register_savevm (&dev->qdev,"ssi_sd" ,-1 ,1 , ssi_sd_save, ssi_sd_load, s);return 0 ; }
tests/qemu-iotests/051.out +4 -1
@@ -128,7 +128,10 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) q[K[Dqu[K[D[Dqui[K[D[D[Dquit[K Testing: -drive file=TEST_DIR/t.qcow2,if=ide,readonly=on -QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=ide,readonly=on: read-only not supported by this bus type +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) QEMU_PROG: Can't use a read-only drive +QEMU_PROG: Device initialization failed. +QEMU_PROG: Initialization of device ide-hd failed Testing: -drive file=TEST_DIR/t.qcow2,if=virtio,readonly=on QEMU X.Y.Z monitor - type 'help' for more information
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 13/17] blockdev: Remove IF_* check for read-only blockdev_init
Quoted 69 lines · Kevin Wolf
IF_NONEallows read-only, which makes forbidding it in this place for other types pretty much pointless.Instead, make sure that all devices for which the check would have errored out check in their init function that they don't get a read-only BlockDriverState. This catches even cases where
IF_NONEand -device is used.Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 6 ------ hw/block/m25p80.c | 5 +++++ hw/block/xen_disk.c | 6 ++++++ hw/sd/milkymist-memcard.c | 4 ++++ hw/sd/omap_mmc.c | 8 ++++++++ hw/sd/pl181.c | 4 ++++ hw/sd/pxa2xx_mmci.c | 4 ++++ hw/sd/sd.c | 5 +++++ hw/sd/sdhci.c | 4 ++++ hw/sd/ssi-sd.c | 3 +++ tests/qemu-iotests/051.out | 5 ++++- 11 files changed, 47 insertions(+), 7 deletions(-)blockdev.c +0
-6@@ -529,12 +529,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,if (media ==MEDIA_CDROM ) {/* CDROM is fine for any interface, don't check. */ ro =1 ; - }else if (ro ==1 ) { -if (type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_FLOPPY && - type !=IF_NONE && type !=IF_PFLASH ) { -error_report ("read-only not supported by this bus type" ); - goto err; - } } bdrv_flags |= ro ?0 :BDRV_O_RDWR ;hw/block/m25p80.c +5
-0@@ -624,6 +624,11 @@ static int m25p80_init(SSISlave *ss)if (dinfo && dinfo->bdrv) {DB_PRINT_L (0 ,"Binding to IF_MTD drive\n" ); s->bdrv = dinfo->bdrv; +if (bdrv_is_read_only (s->bdrv)) { +fprintf (stderr,"Can't use a read-only drive" ); +return 1 ; + } +/* FIXME: Move to late init */ if (bdrv_read (s->bdrv,0 , s->storage,DIV_ROUND_UP (s->size,BDRV_SECTOR_SIZE ))) {hw/block/xen_disk.c +1
-0@@ -39,6 +39,7 @@#include "hw/xen/xen_backend.h" #include "xen_blkif.h" #include "sysemu/blockdev.h" +#include "qemu/error-report.h" /* ------------------------------------------------------------- */
hw/block/xen_disk.c static int blk_connect(struct XenDevice *xendev) · line 837
Quoted 8 lines
hw/block/xen_disk.c +5
-0@@ -829,6 +830,11 @@ static int blk_connect(struct XenDevice *xendev)/* setup via qemu cmdline -> already setup for us */ xen_be_printf (&blkdev->xendev,2 ,"get configured bdrv (cmdline setup)\n" ); blkdev->bs = blkdev->dinfo->bdrv; +if (bdrv_is_read_only (blkdev->bs) && !readonly) { +error_report ("Unexpected read-only drive" ); + blkdev->bs =NULL ; +return -1 ; + }
Just out of curiosity, why do you use error_report here but fprintf(stderr) in most other places?
Max
Quoted 135 lines
hw/block/xen_disk.c +0
-0/* blkdev->bs is not create by us, we get a reference * so we can bdrv_unref() unconditionally */ bdrv_ref (blkdev->bs);hw/sd/milkymist-memcard.c +4
-0@@ -255,6 +255,10 @@ static int milkymist_memcard_init(SysBusDevice *dev) dinfo =drive_get_next (IF_SD ); s->card =sd_init (dinfo ? dinfo->bdrv :NULL , false); +if (s->card ==NULL ) { +return -1 ; + } + s->enabled = dinfo ?bdrv_is_inserted (dinfo->bdrv) :0 ; memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s,hw/sd/omap_mmc.c +8
-0@@ -593,6 +593,10 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base,/* Instantiate the storage */ s->card =sd_init (bd, false); +if (s->card ==NULL ) { +fprintf (stderr,"Failed to initialise SD card\n" ); +exit (1 ); + }return s; }@@ -618,6 +622,10 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,/* Instantiate the storage */ s->card =sd_init (bd, false); +if (s->card ==NULL ) { +fprintf (stderr,"Failed to initialise SD card\n" ); +exit (1 ); + } s->cdet =qemu_allocate_irqs (omap_mmc_cover_cb, s,1 )[0 ];sd_set_cb (s->card,NULL , s->cdet);hw/sd/pl181.c +4
-0@@ -491,6 +491,10 @@ static int pl181_init(SysBusDevice *sbd)qdev_init_gpio_out (dev, s->cardstatus,2 ); dinfo =drive_get_next (IF_SD ); s->card =sd_init (dinfo ? dinfo->bdrv :NULL , false); +if (s->card ==NULL ) { +return -1 ; + } +return 0 ; }hw/sd/pxa2xx_mmci.c +4
-0@@ -539,6 +539,10 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,/* Instantiate the actual storage */ s->card =sd_init (bd, false); +if (s->card ==NULL ) { +fprintf (stderr,"Failed to initialise SD card\n" ); +exit (1 ); + }register_savevm (NULL ,"pxa2xx_mmci" ,0 ,0 , pxa2xx_mmci_save, pxa2xx_mmci_load, s);hw/sd/sd.c +5
-0@@ -494,6 +494,11 @@ SDState *sd_init(BlockDriverState *bs, bool is_spi) {SDState *sd; +if (bdrv_is_read_only (bs)) { +fprintf (stderr,"sd_init: Cannot use read-only drive\n" ); +return NULL ; + } + sd = (SDState *)g_malloc0 (sizeof (SDState)); sd->buf =qemu_blockalign (bs,512 ); sd->spi = is_spi;hw/sd/sdhci.c +4
-0@@ -1166,6 +1166,10 @@ static void sdhci_initfn(Object *obj) di =drive_get_next (IF_SD ); s->card =sd_init (di ? di->bdrv :NULL , false); +if (s->card ==NULL ) { +fprintf (stderr,"Failed to initialise SD card\n" ); +exit (1 ); + } s->eject_cb =qemu_allocate_irqs (sdhci_insert_eject_cb, s,1 )[0 ]; s->ro_cb =qemu_allocate_irqs (sdhci_card_readonly_cb, s,1 )[0 ];sd_set_cb (s->card, s->ro_cb, s->eject_cb);hw/sd/ssi-sd.c +3
-0@@ -246,6 +246,9 @@ static int ssi_sd_init(SSISlave *dev) s->mode =SSI_SD_CMD ; dinfo =drive_get_next (IF_SD ); s->sd =sd_init (dinfo ? dinfo->bdrv :NULL , true); +if (s->sd ==NULL ) { +return -1 ; + }register_savevm (&dev->qdev,"ssi_sd" ,-1 ,1 , ssi_sd_save, ssi_sd_load, s);return 0 ; }tests/qemu-iotests/051.out +4
-1@@ -128,7 +128,10 @@ QEMU X.Y.Z monitor - type 'help' for more information (qemu) q[K[Dqu[K[D[Dqui[K[D[D[Dquit[K Testing: -drive file=TEST_DIR/t.qcow2,if=ide,readonly=on -QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=ide,readonly=on: read-only not supported by this bus type +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) QEMU_PROG: Can't use a read-only drive +QEMU_PROG: Device initialization failed. +QEMU_PROG: Initialization of device ide-hd failed Testing: -drive file=TEST_DIR/t.qcow2,if=virtio,readonly=on QEMU X.Y.Z monitor - type 'help' for more information
Re: [Qemu-devel] [PATCH 13/17] blockdev: Remove IF_* check for read-only blockdev_init
Am 23.09.2013 um 10:00 hat Max Reitz geschrieben:
Quoted 69 lines · Kevin Wolf
Quoted 68 lines
IF_NONEallows read-only, which makes forbidding it in this place for other types pretty much pointless.Instead, make sure that all devices for which the check would have errored out check in their init function that they don't get a read-only BlockDriverState. This catches even cases where
IF_NONEand -device is used.Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 6 ------ hw/block/m25p80.c | 5 +++++ hw/block/xen_disk.c | 6 ++++++ hw/sd/milkymist-memcard.c | 4 ++++ hw/sd/omap_mmc.c | 8 ++++++++ hw/sd/pl181.c | 4 ++++ hw/sd/pxa2xx_mmci.c | 4 ++++ hw/sd/sd.c | 5 +++++ hw/sd/sdhci.c | 4 ++++ hw/sd/ssi-sd.c | 3 +++ tests/qemu-iotests/051.out | 5 ++++- 11 files changed, 47 insertions(+), 7 deletions(-)blockdev.c +0
-6@@ -529,12 +529,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,if (media ==MEDIA_CDROM ) {/* CDROM is fine for any interface, don't check. */ ro =1 ; - }else if (ro ==1 ) { -if (type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_FLOPPY && - type !=IF_NONE && type !=IF_PFLASH ) { -error_report ("read-only not supported by this bus type" ); - goto err; - } } bdrv_flags |= ro ?0 :BDRV_O_RDWR ;hw/block/m25p80.c +5
-0@@ -624,6 +624,11 @@ static int m25p80_init(SSISlave *ss)if (dinfo && dinfo->bdrv) {DB_PRINT_L (0 ,"Binding to IF_MTD drive\n" ); s->bdrv = dinfo->bdrv; +if (bdrv_is_read_only (s->bdrv)) { +fprintf (stderr,"Can't use a read-only drive" ); +return 1 ; + } +/* FIXME: Move to late init */ if (bdrv_read (s->bdrv,0 , s->storage,DIV_ROUND_UP (s->size,BDRV_SECTOR_SIZE ))) {hw/block/xen_disk.c +1
-0@@ -39,6 +39,7 @@#include "hw/xen/xen_backend.h" #include "xen_blkif.h" #include "sysemu/blockdev.h" +#include "qemu/error-report.h" /* ------------------------------------------------------------- */ @@ -829,6 +830,11 @@ static int blk_connect(struct XenDevice *xendev)/* setup via qemu cmdline -> already setup for us */ xen_be_printf (&blkdev->xendev,2 ,"get configured bdrv (cmdline setup)\n" );
Quoted 8 lines
hw/block/xen_disk.c static int blk_connect(struct XenDevice *xendev) · line 837
Quoted 6 lines
hw/block/xen_disk.c +5
-0blkdev->bs = blkdev->dinfo->bdrv; +if (bdrv_is_read_only (blkdev->bs) && !readonly) { +error_report ("Unexpected read-only drive" ); + blkdev->bs =NULL ; +return -1 ; + }Just out of curiosity, why do you use
error_reporthere but fprintf(stderr) in most other places?
Variatio delectat. ;-)
I guess fprintf + exit was a common pattern elsewhere, so I used it, whereas error_report() is my default function. But now that I look at this file again, maybe it should really be xen_be_printf() here...
Kevin
PATCH 14/17 qemu-iotests: Check autodel behaviour for device_del
In reply to Kevin WolfBlock devices creates with -drive and drive_add should automatically disappear if the guest device is unplugged. blockdev-add ones shouldn't.
--- tests/qemu-iotests/064 | 133 +++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/064.out | 80 +++++++++++++++++++++++ tests/qemu-iotests/common.filter | 8 +++ tests/qemu-iotests/group | 1 + 4 files changed, 222 insertions(+) create mode 100755 tests/qemu-iotests/064 create mode 100644 tests/qemu-iotests/064.out
tests/qemu-iotests/064 new file +133 -0
@@ -0,0 +1,133 @@ +#!/bin/bash +# +# Test automatic deletion of BDSes created by -drive/drive_add +# +# Copyright (C) 2013 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +function do_run_qemu() +{ + echo Testing: "$@" + $QEMU -nographic -qmp stdio -serial none "$@" + echo +} + +function run_qemu() +{ + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp +} + +size=128M + +_make_test_img $size + +echo +echo === -drive/-device and device_del === +echo + +run_qemu -drive file=$TEST_IMG,format=$IMGFMT,if=none,id=disk -device virtio-blk-pci,drive=disk,id=virtio0 <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "query-block" } +{ "execute": "device_del", "arguments": { "id": "virtio0" } } +{ "execute": "system_reset" } +{ "execute": "query-block" } +{ "execute": "quit" } +EOF + +echo +echo === -drive/device_add and device_del === +echo + +run_qemu -drive file=$TEST_IMG,format=$IMGFMT,if=none,id=disk <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "query-block" } +{ "execute": "device_add", + "arguments": { "driver": "virtio-blk-pci", "drive": "disk", + "id": "virtio0" } } +{ "execute": "device_del", "arguments": { "id": "virtio0" } } +{ "execute": "system_reset" } +{ "execute": "query-block" } +{ "execute": "quit" } +EOF + +echo +echo === drive_add/device_add and device_del === +echo + +run_qemu <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "human-monitor-command", + "arguments": { "command-line": "drive_add 0 file=$TEST_IMG,format=$IMGFMT,if=none,id=disk" } } +{ "execute": "query-block" } +{ "execute": "device_add", + "arguments": { "driver": "virtio-blk-pci", "drive": "disk", + "id": "virtio0" } } +{ "execute": "device_del", "arguments": { "id": "virtio0" } } +{ "execute": "system_reset" } +{ "execute": "query-block" } +{ "execute": "quit" } +EOF + +echo +echo === blockdev_add/device_add and device_del === +echo + +run_qemu <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "blockdev-add", + "arguments": { + "options": { + "driver": "$IMGFMT", + "id": "disk", + "file": { + "driver": "file", + "filename": "$TEST_IMG" + } + } + } + } +{ "execute": "query-block" } +{ "execute": "device_add", + "arguments": { "driver": "virtio-blk-pci", "drive": "disk", + "id": "virtio0" } } +{ "execute": "device_del", "arguments": { "id": "virtio0" } } +{ "execute": "system_reset" } +{ "execute": "query-block" } +{ "execute": "quit" } +EOF + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/064.out new file +80 -0
80 lines not on this page · raw message
tests/qemu-iotests/common.filter +8 -0
@@ -159,5 +159,13 @@ _filter_qemu() -e 's#^QEMU [0-9]\+\.[0-9]\+\.[0-9]\+ monitor#QEMU X.Y.Z monitor#' } +# replace problematic QMP output like timestamps +_filter_qmp() +{ + _filter_win32 | \ + sed -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \ + -e 's#^{"QMP":.*}$#QMP_VERSION#' +} + # make sure this script returns success /bin/true
tests/qemu-iotests/group +1 -0
@@ -69,3 +69,4 @@ 061 rw auto 062 rw auto 063 rw auto +064 rw auto
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 14/17] qemu-iotests: Check autodel behaviour for device_del
Quoted 4 lines · Kevin Wolf
Block devices creates with -drive and
drive_addshould automatically disappear if the guest device is unplugged. blockdev-add ones shouldn't.Signed-off-by Kevin Wolf <[email protected]>
Quoted 8 lines
--- tests/qemu-iotests/064 | 133 +++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/064.out | 80 +++++++++++++++++++++++ tests/qemu-iotests/common.filter | 8 +++ tests/qemu-iotests/group | 1 + 4 files changed, 222 insertions(+)create mode 100755 tests/qemu-iotests/064
create mode 100644 tests/qemu-iotests/064.out
With manual CR reconstruction:
PATCH 15/17 blockdev: Remove 'media' parameter from blockdev_init()
In reply to Kevin WolfThe remaining users shouldn't be there with blockdev-add and are easy to move to drive_init().
Bonus bug fix: As a side effect, CD-ROM drives can now use block drivers on the read-only whitelist without explicitly specifying read-only=on, even if a format is explicitly specified.
--- blockdev.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-)
blockdev.c +15 -25
@@ -306,8 +306,7 @@ typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;/* Takes the ownership of bs_opts */ static DriveInfo *blockdev_init (QDict *bs_opts, -BlockInterfaceType type, -DriveMediaType media) +BlockInterfaceType type) {const char *buf;const char *file =NULL ;
@@ -489,22 +488,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,bdrv_set_io_limits (dinfo->bdrv, &cfg); } -switch (type) { -case IF_IDE : -case IF_SCSI : -case IF_XEN : -case IF_NONE : - dinfo->media_cd = media ==MEDIA_CDROM ; -break ; -case IF_SD : -case IF_FLOPPY : -case IF_PFLASH : -case IF_MTD : -case IF_VIRTIO : -break ; -default : -abort (); - }if (!file || !*file) {if (has_driver_specific_opts) { file =NULL ;
@@ -526,11 +509,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, bdrv_flags |=BDRV_O_INCOMING ; } -if (media ==MEDIA_CDROM ) { -/* CDROM is fine for any interface, don't check. */ - ro =1 ; - } - bdrv_flags |= ro ?0 :BDRV_O_RDWR ;if (ro && copy_on_read) {
@@ -714,6 +692,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) media =MEDIA_DISK ; }else if (!strcmp (value,"cdrom" )) { media =MEDIA_CDROM ; +qdict_put (bs_opts,"read-only" ,qstring_from_str ("on" )); }else {error_report ("'%s' invalid media" , value); goto fail;
@@ -861,7 +840,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) }/* Actual block device init: Functionality shared with blockdev-add */ - dinfo =blockdev_init (bs_opts, type, media); + dinfo =blockdev_init (bs_opts, type);if (dinfo ==NULL ) { goto fail; }
@@ -879,6 +858,17 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) dinfo->unit = unit_id; dinfo->devaddr = devaddr; +switch (type) { +case IF_IDE : +case IF_SCSI : +case IF_XEN : +case IF_NONE : + dinfo->media_cd = media ==MEDIA_CDROM ; +break ; +default : +break ; + } + fail:qemu_opts_del (legacy_opts);return dinfo;
@@ -2173,7 +2163,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)qdict_flatten (qdict); - dinfo =blockdev_init (qdict,IF_NONE ,MEDIA_DISK ); + dinfo =blockdev_init (qdict,IF_NONE );if (!dinfo) {error_setg (errp,"Could not open image" ); goto fail;
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 15/17] blockdev: Remove 'media' parameter from blockdev_init()
Quoted 11 lines · Kevin Wolf
The remaining users shouldn't be there with blockdev-add and are easy to move to
drive_init().Bonus bug fix: As a side effect, CD-ROM drives can now use block drivers on the read-only whitelist without explicitly specifying read-only=on, even if a format is explicitly specified.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-)
PATCH 16/17 blockdev: Don't disable COR automatically with blockdev-add
In reply to Kevin WolfIf a read-only device is configured with copy-on-read=on, the old code only prints a warning and automatically disables copy on read. Make it a real error for blockdev-add.
--- block.c | 9 +++++++-- blockdev.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-)
block.c +7 -2
@@ -774,8 +774,13 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, }assert (bs->copy_on_read ==0 );/* bdrv_new() and bdrv_close() make it so */ -if (!bs->read_only && (flags &BDRV_O_COPY_ON_READ )) { -bdrv_enable_copy_on_read (bs); +if (flags &BDRV_O_COPY_ON_READ ) { +if (!bs->read_only) { +bdrv_enable_copy_on_read (bs); + }else { +error_setg (errp,"Can't use copy-on-read on read-only device" ); +return -EINVAL ; + } }if (filename !=NULL ) {
blockdev.c +27 -4
@@ -511,10 +511,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, bdrv_flags |= ro ?0 :BDRV_O_RDWR ; -if (ro && copy_on_read) { -error_report ("warning: disabling copy_on_read on read-only drive" ); - } -QINCREF (bs_opts); ret =bdrv_open (dinfo->bdrv, file, bs_opts, bdrv_flags, drv, &error);
@@ -602,6 +598,18 @@ QemuOptsList qemu_legacy_drive_opts = { .type = QEMU_OPT_STRING, .help = "pci address (virtio only)", }, + +/* Options that are passed on, but have special semantics with -drive */ + { + .name = "read-only", + .type = QEMU_OPT_BOOL, + .help = "open drive file as read-only", + },{ + .name = "copy-on-read", + .type = QEMU_OPT_BOOL, + .help = "copy read data from backing file into image file", + }, + {/* end of list */ } }, };
@@ -617,6 +625,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)int cyls, heads, secs, translation;int max_devs, bus_id, unit_id, index;const char *devaddr; +bool read_only, copy_on_read;Error *local_err =NULL ;/* Change legacy command line options into QMP ones */
@@ -699,6 +708,20 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) } } +/* copy-on-read is disabled with a warning for read-only devices */ + read_only =qemu_opt_get_bool (legacy_opts,"read-only" , false); + copy_on_read =qemu_opt_get_bool (legacy_opts,"copy-on-read" , false); + +if (read_only && copy_on_read) { +error_report ("warning: disabling copy-on-read on read-only drive" ); + copy_on_read = false; + } + +qdict_put (bs_opts,"read-only" , +qstring_from_str (read_only ?"on" :"off" )); +qdict_put (bs_opts,"copy-on-read" , +qstring_from_str (copy_on_read ?"on" :"off" )); +/* Controller type */ value =qemu_opt_get (legacy_opts,"if" );if (value) {
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 16/17] blockdev: Don't disable COR automatically with blockdev-add
Quoted 9 lines · Kevin Wolf
If a read-only device is configured with copy-on-read=on, the old code only prints a warning and automatically disables copy on read. Make it a real error for blockdev-add.
Signed-off-by Kevin Wolf <[email protected]>--- block.c | 9 +++++++-- blockdev.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-)
PATCH 17/17 blockdev: blockdev_init() error conversion
In reply to Kevin WolfThis gives us meaningful error messages for the blockdev-add QMP command.
--- blockdev.c | 59 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 26 deletions(-)
blockdev.c +33 -26
@@ -269,7 +269,7 @@ static void bdrv_put_ref_bh_schedule(BlockDriverState *bs)qemu_bh_schedule (s->bh); } -static int parse_block_error_action (const char *buf,bool is_read) +static int parse_block_error_action (const char *buf,bool is_read,Error **errp) {if (!strcmp (buf,"ignore" )) {return BLOCKDEV_ON_ERROR_IGNORE ;
@@ -280,8 +280,8 @@ static int parse_block_error_action(const char *buf, bool is_read) }else if (!strcmp (buf,"report" )) {return BLOCKDEV_ON_ERROR_REPORT ; }else { -error_report ("'%s' invalid %s error action" , - buf, is_read ?"read" :"write" ); +error_setg (errp,"'%s' invalid %s error action" , + buf, is_read ?"read" :"write" );return -1 ; } }
@@ -306,7 +306,8 @@ typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;/* Takes the ownership of bs_opts */ static DriveInfo *blockdev_init (QDict *bs_opts, -BlockInterfaceType type) +BlockInterfaceType type, +Error **errp) {const char *buf;const char *file =NULL ;
@@ -330,15 +331,13 @@ static DriveInfo *blockdev_init(QDict *bs_opts, id =qdict_get_try_str (bs_opts,"id" ); opts =qemu_opts_create (&qemu_common_drive_opts, id,1 , &error);if (error_is_set (&error)) { -qerror_report_err (error); -error_free (error); +error_propagate (errp, error);return NULL ; }qemu_opts_absorb_qdict (opts, bs_opts, &error);if (error_is_set (&error)) { -qerror_report_err (error); -error_free (error); +error_propagate (errp, error);return NULL ; }
@@ -358,7 +357,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts,if ((buf =qemu_opt_get (opts,"discard" )) !=NULL ) {if (bdrv_parse_discard_flags (buf, &bdrv_flags) !=0 ) { -error_report ("invalid discard option" ); +error_setg (errp,"invalid discard option" );return NULL ; } }
@@ -380,7 +379,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts, }else if (!strcmp (buf,"threads" )) {/* this is the default */ }else { -error_report ("invalid aio option" ); +error_setg (errp,"invalid aio option" );return NULL ; } }
@@ -397,9 +396,10 @@ static DriveInfo *blockdev_init(QDict *bs_opts, drv =bdrv_find_whitelisted_format (buf, ro);if (!drv) {if (!ro &&bdrv_find_whitelisted_format (buf, !ro)) { -error_report ("'%s' can be only used as read-only device." , buf); +error_setg (errp,"'%s' can be only used as read-only device." , + buf); }else { -error_report ("'%s' invalid format" , buf); +error_setg (errp,"'%s' invalid format" , buf); }return NULL ; }
@@ -436,20 +436,20 @@ static DriveInfo *blockdev_init(QDict *bs_opts, cfg.op_size =qemu_opt_get_number (opts,"throttling.iops-size" ,0 );if (!check_throttle_config (&cfg, &error)) { -error_report ("%s" ,error_get_pretty (error)); -error_free (error); +error_propagate (errp, error);return NULL ; } on_write_error =BLOCKDEV_ON_ERROR_ENOSPC ;if ((buf =qemu_opt_get (opts,"werror" )) !=NULL ) {if (type !=IF_IDE && type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_NONE ) { -error_report ("werror is not supported by this bus type" ); +error_setg (errp,"werror is not supported by this bus type" );return NULL ; } - on_write_error =parse_block_error_action (buf,0 ); -if (on_write_error <0 ) { + on_write_error =parse_block_error_action (buf,0 , &error); +if (error_is_set (&error)) { +error_propagate (errp, error);return NULL ; } }
@@ -461,8 +461,9 @@ static DriveInfo *blockdev_init(QDict *bs_opts,return NULL ; } - on_read_error =parse_block_error_action (buf,1 ); -if (on_read_error <0 ) { + on_read_error =parse_block_error_action (buf,1 , &error); +if (error_is_set (&error)) { +error_propagate (errp, error);return NULL ; } }
@@ -515,8 +516,9 @@ static DriveInfo *blockdev_init(QDict *bs_opts, ret =bdrv_open (dinfo->bdrv, file, bs_opts, bdrv_flags, drv, &error);if (ret <0 ) { -error_report ("could not open disk image %s: %s" , - file ?: dinfo->id,error_get_pretty (error)); +error_setg (errp,"could not open disk image %s: %s" , + file ?: dinfo->id,error_get_pretty (error)); +error_free (error); goto err; }
@@ -863,9 +865,15 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) }/* Actual block device init: Functionality shared with blockdev-add */ - dinfo =blockdev_init (bs_opts, type); + dinfo =blockdev_init (bs_opts, type, &local_err);if (dinfo ==NULL ) { +if (error_is_set (&local_err)) { +qerror_report_err (local_err); +error_free (local_err); + } goto fail; + }else { +assert (!error_is_set (&local_err)); }/* Set legacy DriveInfo fields */
@@ -2152,7 +2160,6 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)QmpOutputVisitor *ov =qmp_output_visitor_new ();QObject *obj;QDict *qdict; -DriveInfo *dinfo;Error *local_err =NULL ;/* Require an ID in the top level */
@@ -2186,9 +2193,9 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)qdict_flatten (qdict); - dinfo =blockdev_init (qdict,IF_NONE ); -if (!dinfo) { -error_setg (errp,"Could not open image" ); +blockdev_init (qdict,IF_NONE , &local_err); +if (error_is_set (&local_err)) { +error_propagate (errp, local_err); goto fail; }
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH 17/17] blockdev: blockdev_init() error conversion
Quoted 7 lines · Kevin Wolf
This gives us meaningful error messages for the blockdev-add QMP command.
Signed-off-by Kevin Wolf <[email protected]>--- blockdev.c | 59 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 26 deletions(-)