summaryrefslogtreecommitdiff
path: root/util/qemu-option.c
AgeCommit message (Collapse)AuthorFilesLines
2014-06-16QemuOpts: change opt->name|str from (const char *) to (char *)Chunyan Liu1-2/+2
qemu_opt_del() already assumes that all QemuOpt instances contain malloc'd name and value; but it had to cast away const because opts_start_struct() was doing its own thing and using static storage instead. By using the correct type and malloced strings everywhere, the usage of this struct becomes clearer. Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Leandro Dorileo <l@dorileo.org> Signed-off-by: Chunyan Liu <cyliu@suse.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-06-16QemuOpts: add def_value_str to QemuOptDescChunyan Liu1-7/+49
Add def_value_str (default value) to QemuOptDesc, to replace function of the default value in QEMUOptionParameter. Improve qemu_opts_get_* functions: if find opt, return opt->str; otherwise, if desc->def_value_str is set, return desc->def_value_str; otherwise, return input defval. Improve qemu_opts_print: if option is set, print opt->str; otherwise, if desc->def_value_str is set, print it. Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Chunyan Liu <cyliu@suse.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-06-16QemuOpts: repurpose qemu_opts_print to replace print_option_parametersChunyan Liu1-6/+4
Currently this function is not used anywhere. In later patches, it will replace print_option_parameters. To avoid print info changes, change qemu_opts_print from fprintf stderr to printf, and remove last printf. Signed-off-by: Chunyan Liu <cyliu@suse.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-06-16QemuOpts: move find_desc_by_name ahead for later callingChunyan Liu1-14/+14
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Chunyan Liu <cyliu@suse.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-05-09qemu-option: Clean up fragile use of error_is_set()Markus Armbruster1-1/+1
Using error_is_set(ERRP) to find out whether to bail out due to previous error is either wrong, fragile, or unnecessarily opaque. It's wrong when ERRP may be null, because errors go undetected when it is. It's fragile when proving ERRP non-null involves a non-local argument. Else, it's unnecessarily opaque (see commit 84d18f0). The error_is_set(state->errp) in qemu_opts_from_qdict_1() is merely fragile, because the callers never pass state argument with null state->errp. Make the code more robust and more obviously correct: test *state->errp directly. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-04-25qerror.h: Remove QERR defines that are only used onceCole Robinson1-1/+1
Just hardcode them in the callers Cc: Luiz Capitulino <lcapitulino@redhat.com> Cc: Markus Armbruster <armbru@redhat.com> Signed-off-by: Cole Robinson <crobinso@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-02-21qemu-option: has_help_option() and is_valid_option_list()Kevin Wolf1-0/+49
has_help_option() checks if any help option ('help' or '?') occurs anywhere in an option string, so that things like 'cluster_size=4k,help' are recognised. is_valid_option_list() ensures that the option list doesn't have options with leading commas or trailing unescaped commas. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Jeff Cody <jcody@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
2014-02-17Use error_is_set() only when necessaryMarkus Armbruster1-11/+11
error_is_set(&var) is the same as var != NULL, but it takes whole-program analysis to figure that out. Unnecessarily hard for optimizers, static checkers, and human readers. Dumb it down to obvious. Gets rid of several dozen Coverity false positives. Note that the obvious form is already used in many places. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-01-06qemu-option: Remove qemu_opts_create_nofailPeter Crosthwaite1-9/+0
This is a boiler-plate _nofail variant of qemu_opts_create. Remove and use error_abort in call sites. null/0 arguments needs to be added for the id and fail_if_exists fields in affected callsites due to argument inconsistency between the normal and no_fail variants. Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2013-10-11blockdev: Separate ID generation from DriveInfo creationKevin Wolf1-0/+6
blockdev-add shouldn't automatically generate IDs, but will keep most of the DriveInfo creation code. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com> Reviewed-by: Eric Blake <eblake@redhat.com>
2013-08-30option: Add assigned flag to QEMUOptionParameterMax Reitz1-0/+9
Adds an "assigned" flag to QEMUOptionParameter which is cleared at the beginning of parse_option_parameters and set on (successful) set_option_parameter and set_option_parameter_int. Signed-off-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2013-08-12qemu-option: Guard against qemu_opts_set_defaults() misuseMarkus Armbruster1-0/+9
Commit 6d4cd40 fixed qemu_opts_set_defaults() for an existing corner case, but broke it for another one that can't be reached in current code. Quote from its commit message: I believe [opts_parse()] attempts to do the following: If options don't yet exist, create new options Else, if defaults, modify the existing options Else, if list->merge_lists, modify the existing options Else, fail The only caller that passes true for defaults is qemu_opts_set_defaults(). The commit message then claims: A straightforward call of qemu_opts_create() does exactly that. Wrong. When !list->merge_lists, and the option string doesn't contain id=, and options without ID exist, then we don't actually modify the existing options, we create new ones. Not reachable, because we never pass lists with !list->merge_lists to qemu_opts_set_defaults(). Guard against possible (if unlikely) future misuse with assert(). Reported-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 1375428840-5275-1-git-send-email-armbru@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-07-29qdev: Add SIZE type to qdev propertiesVasilis Liaskovitis1-2/+2
This patch adds a 'SIZE' type property to qdev. Signed-off-by: Ian Molton <ian.molton@collabora.co.uk> Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Signed-off-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Andreas Färber <afaerber@suse.de> Message-id: 1375109277-25561-7-git-send-email-imammedo@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-07-26QemuOpts: Add qemu_opt_unset()Kevin Wolf1-0/+14
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
2013-07-09qemu-option: Fix qemu_opts_set_defaults() for corner casesMarkus Armbruster1-9/+1
Commit 4f6dd9a changed the initialization of opts in opts_parse() to this: if (defaults) { if (!id && !QTAILQ_EMPTY(&list->head)) { opts = qemu_opts_find(list, NULL); } else { opts = qemu_opts_create(list, id, 0); } } else { opts = qemu_opts_create(list, id, 1); } Same as before for !defaults. If defaults is true, and params has no ID, and options exist, we use the first assignment. It sets opts to null if all options have an ID. opts_parse() then returns null. qemu_opts_set_defaults() asserts the value is non-null. It's the only caller that passes true for defaults. To reproduce, try "-M xenpv -machine id=foo" (yes, "id=foo" is silly, but it shouldn't crash). I believe the function attempts to do the following: If options don't yet exist, create new options Else, if defaults, modify the existing options Else, if list->merge_lists, modify the existing options Else, fail A straightforward call of qemu_opts_create() does exactly that. Cc: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-id: 1372943363-24081-3-git-send-email-armbru@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-07-09qemu-option: Fix qemu_opts_find() for null id argumentsMarkus Armbruster1-8/+4
Crashes when the first list member has an ID. Admittedly nonsensical reproducer: $ qemu-system-x86_64 -nodefaults -machine id=foo -machine "" Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 1372943363-24081-2-git-send-email-armbru@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-06-19qemu-option: check_params() is now unused, drop itMarkus Armbruster1-30/+0
Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Message-id: 1371208516-7857-3-git-send-email-armbru@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-03-15qemu-option: Add qemu_opts_absorb_qdict()Kevin Wolf1-0/+34
This adds a function that adds all entries of a QDict to a QemuOpts if the keys are known, and leaves only the rest in the QDict. This way a single QDict of -drive options can be processed in multiple places (generic block layer, block driver, backing file block driver, etc.), where each part picks the options it knows. If at the end of the process the QDict isn't empty, the user specified an invalid option. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-02-11qemu-option: Disable two helpful messages that got broken recentlyMarkus Armbruster1-0/+4
commit 8be7e7e4 and commit ec7b2ccb messed up the ordering of error message and the helpful explanation that should follow it, like this: $ qemu-system-x86_64 --nodefaults -S --vnc :0 --chardev null,id=, Identifiers consist of letters, digits, '-', '.', '_', starting with a letter. qemu-system-x86_64: -chardev null,id=,: Parameter 'id' expects an identifier $ qemu-system-x86_64 --nodefaults -S --vnc :0 --machine kvm_shadow_mem=dunno You may use k, M, G or T suffixes for kilobytes, megabytes, gigabytes and terabytes. qemu-system-x86_64: -machine kvm_shadow_mem=dunno: Parameter 'kvm_shadow_mem' expects a size Pity. Disable them for now. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-id: 1360354939-10994-5-git-send-email-armbru@redhat.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-01-30g_strdup(NULL) returns NULL; simplifyMarkus Armbruster1-6/+2
Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-01-12build: move libqemuutil.a components to util/Paolo Bonzini1-0/+1134
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>