summaryrefslogtreecommitdiffstats
path: root/qemu-option.c
Commit message (Collapse)AuthorAgeFilesLines
* build: move libqemuutil.a components to util/Paolo Bonzini2013-01-121-1134/+0Star
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* misc: move include files to include/qemu/Paolo Bonzini2012-12-191-2/+2
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qapi: move include files to include/qobject/Paolo Bonzini2012-12-191-3/+3
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* create new function: qemu_opt_set_numberDong Xu Wang2012-12-111-0/+22
| | | | | Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* introduce qemu_opts_create_nofail functionDong Xu Wang2012-12-111-0/+9
| | | | | | | | While id is NULL, qemu_opts_create can not fail, so ignore errors is fine. Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-option: qemu_opt_set_bool(): fix code duplicationDong Xu Wang2012-12-111-18/+9Star
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It will set opt->str in qemu_opt_set_bool, without opt->str, there will be some potential bugs. These are uses of opt->str, and what happens when it isn't set: * qemu_opt_get(): returns NULL, which means "not set". Bug can bite when value isn't the default value. * qemu_opt_parse(): passes NULL to parse_option_bool(), which treats it like "on". Wrong if the value is actually false. Bug can bite when qemu_opts_validate() runs after qemu_opt_set_bool(). * qemu_opt_del(): passes NULL to g_free(), which is just fine. * qemu_opt_foreach(): passes NULL to the callback, which is unlikely to be prepared for it. * qemu_opts_print(): prints NULL, which crashes on some systems. * qemu_opts_to_qdict(): passes NULL to qstring_from_str(), which crashes. It also makes qemu_opt_set_bool more readable by using find_desc_by_name and opts_accepts_any. It is based on Luiz's patch and uses Markus's comments. Discussions can be found at: http://lists.nongnu.org/archive/html/qemu-devel/2012-07/msg02716.html Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-option: qemu_opts_validate(): fix duplicated codeDong Xu Wang2012-12-111-11/+3Star
| | | | | | | | Use opts_accepts_any() and find_desc_by_name(). Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-option: opt_set(): split it up into more functionsDong Xu Wang2012-12-111-16/+24
| | | | | | | | | | | The new functions are opts_accepts_any() and find_desc_by_name(), which are also going to be used by qemu_opts_validate() (see next commit). This also makes opt_set() slightly more readable. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* Support 'help' as a synonym for '?' in command line optionsPeter Maydell2012-08-021-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | For command line options which permit '?' meaning 'please list the permitted values', add support for 'help' as a synonym, by abstracting the check out into a helper function. This change means that in some cases where we were being lazy in our string parsing, "?junk" will now be rejected as an invalid option rather than being (undocumentedly) treated the same way as "?". Update the documentation to use 'help' rather than '?', since '?' is a shell metacharacter and thus prone to fail confusingly if there is a single character filename in the current working directory and the '?' has not been escaped. It's therefore better to steer users towards 'help', though '?' is retained for backwards compatibility. We do not, however, update the output of the system emulator's -help (or any documentation autogenerated from the qemu-options.hx which is the source of the -help text) because libvirt parses our -help output and will break. At a later date when QEMU provides a better interface so libvirt can avoid having to do this, we can update the -help text too. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* expose QemuOpt and QemuOpts struct definitions to interested partiesLaszlo Ersek2012-07-231-23/+1Star
| | | | | | | | The only clients should be the existent "qemu-option.c", and the upcoming "qapi/opts-visitor.c". Signed-off-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
* qemu-option: qemu_opts_from_qdict(): use error_set()Luiz Capitulino2012-06-041-7/+24
| | | | | | | | do_device_add() and do_netdev_add() call qerror_report_err() to maintain their QError semantics. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
* qemu-option: introduce qemu_opt_set_err()Luiz Capitulino2012-06-041-0/+6
| | | | | | | | | | This is like qemu_opt_set(), except that it takes an Error argument. This new function allows for a incremental conversion of code using qemu_opt_set(). Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
* qemu-option: opt_set(): use error_set()Luiz Capitulino2012-06-041-11/+20
| | | | | | | | | The functions qemu_opt_set() and opts_do_parse() both call opt_set(), but their callers expect QError semantics. Thus, both functions call qerro_report_err() to keep the expected semantics. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
* qemu-option: qemu_opts_validate(): use error_set()Luiz Capitulino2012-06-041-8/+5Star
| | | | | | | | net_client_init() propagates the error up by calling qerror_report_err(), because its users expect QError semantics. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
* qemu-option: qemu_opt_parse(): use error_set()Luiz Capitulino2012-06-041-19/+17Star
| | | | | | | | | The functions opt_set() and qemu_opts_validate() both call qemu_opt_parse(), but their callers expect QError semantics. Thus, both functions call qerro_report_err() to keep the expected semantics. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
* qemu-option: parse_option_size(): use error_set()Luiz Capitulino2012-06-041-9/+8Star
| | | | | Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
* qemu-option: parse_option_bool(): use error_set()Luiz Capitulino2012-06-041-8/+16
| | | | | | | | | Note that set_option_parameter() callers still expect automatic error reporting with QError, so set_option_parameter() calls qerror_report_err() to keep the same semantics. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
* qemu-option: parse_option_number(): use error_set()Luiz Capitulino2012-06-041-7/+19
| | | | | | | | | Note that qemu_opt_parse() callers still expect automatic error reporting with QError, so qemu_opts_parse() calls qerror_report_err() to keep the same semantics. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
* qemu-option: qemu_opts_create(): use error_set()Luiz Capitulino2012-06-041-10/+27
| | | | | | | | | | | | | | | | | | | | | | | This commit converts qemu_opts_create() from qerror_report() to error_set(). Currently, most calls to qemu_opts_create() can't fail, so most callers don't need any changes. The two cases where code checks for qemu_opts_create() erros are: 1. Initialization code in vl.c. All of them print their own error messages directly to stderr, no need to pass the Error object 2. The functions opts_parse(), qemu_opts_from_qdict() and qemu_chr_parse_compat() make use of the error information and they can be called from HMP or QMP. In this case, to allow for incremental conversion, we propagate the error up using qerror_report_err(), which keeps the QError semantics Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
* qemu-option: Add support for merged QemuOptsListsPeter Maydell2012-02-171-1/+6
| | | | | | | | | Add support for option lists which are merged together, so that "-listname foo=bar -listname bar=baz" is equivalent to "-listname foo=bar,bar=baz" rather than generating two separate lists of options. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Andrzej Zaborowski <andrew.zaborowski@intel.com>
* qemu-option: Introduce default mechanismJan Kiszka2012-02-011-8/+50
| | | | | | | | | | | This adds qemu_opts_set_defaults, an interface provide default values for a QemuOpts set. Default options are parsed from a string and then prepended to the list of existing options, or they serve as the sole QemuOpts set. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Add 'fall through' comments to case statements without breakStefan Weil2012-01-131-0/+4
| | | | | | | | | | | These comments are used by static code analysis tools and in code reviews to avoid false warnings because of missing break statements. The case statements handled here were reported by coverity. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
* fix spelling in main directoryDong Xu Wang2011-12-021-1/+1
| | | | | Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
* qemu: Add opt_set_bool functionalityM. Mohan Kumar2011-10-311-4/+35
| | | | | Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
* Use glib memory allocation and free functionsAnthony Liguori2011-08-211-14/+14
| | | | | | qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-option: Fix parse_option_parameters() documentation typoStefan Hajnoczi2010-12-141-2/+2
| | | | | | | Yoda said, "list is the templace is". Fix this. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-option: Don't reinvent append_option_parameters()Stefan Hajnoczi2010-12-141-8/+1Star
| | | | | | | | | parse_option_parameters() may need to create a new option parameter list from a template list. Use append_option_parameters() instead of duplicating the code. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* error: New qemu_opts_loc_restore()Markus Armbruster2010-07-061-0/+5
| | | | | | | | | Needed for decent error locations when complaining about options outside of qemu_opts_foreach(). That one sets the location already. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-option: New qemu_opts_reset()Markus Armbruster2010-07-021-0/+9
| | | | | Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-option: Reject anti-social IDsMarkus Armbruster2010-06-141-0/+20
| | | | | | | | | | Restrict IDs to letters, digits, '-', '.', '_', starting with a letter. This takes care of '/' in qdev IDs breaking qbus_find(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-option: Fix uninitialized value in append_option_parameterKevin Wolf2010-06-141-0/+1
| | | | | | | | When dest is NULL, i.e. a new copy of the list is created, we don't get a properly terminated list after the realloc. Initialize it as an empty list. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* add support for protocol driver create_optionsMORITA Kazutaka2010-05-281-7/+46
| | | | | | | | | This patch enables protocol drivers to use their create options which are not supported by the format. For example, protcol drivers can use a backing_file option with raw format. Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* Fix tiny leak in qemu_opts_parseJan Kiszka2010-05-031-2/+2
| | | | | | | | | qemu_opts_create duplicates the id we pass in case it shall be stored in the opts. So we do not need to dup it in qemu_opts_parse, leaking a few bytes this way. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* error: Convert qemu_opts_validate() to QErrorMarkus Armbruster2010-04-181-2/+1Star
| | | | | Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* error: Convert qemu_opts_set() to QErrorMarkus Armbruster2010-04-181-10/+7Star
| | | | | Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* error: Convert qemu_opts_create() to QErrorMarkus Armbruster2010-04-181-2/+2
| | | | | | | | Fixes device_add to report duplicate ID properly in QMP, as DuplicateId instead of UndefinedError. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* Fix OpenBSD linker warningBlue Swirl2010-03-181-1/+2
| | | | | | | qemu-option.o(.text+0x20f8): In function `qemu_opts_from_qdict_1': /src/qemu/qemu-option.c:813: warning: strcpy() is almost always misused, please use strlcpy() Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* qemu-option: Move the implied first name into QemuOptsListMarkus Armbruster2010-03-161-1/+6
| | | | | | | | | | | We sometimes permit omitting the first option name, for example -device foo is short for -device driver=foo. The name to use ("driver" in the example) is passed as argument to qemu_opts_parse(). For each QemuOptsList, we use at most one such name. Move the name into QemuOptsList, and pass whether to permit the abbreviation. This ensures continued consistency, and simplifies the commit after next in this series.
* qemu-option: Functions to convert to/from QDictMarkus Armbruster2010-03-161-0/+79
| | | | | The functions are somewhat restricted. Good enough for the job at hand. We'll extend them when we need more.
* error: Infrastructure to track locations for error reportingMarkus Armbruster2010-03-161-0/+7
| | | | | | | | | | | | | | | | | | New struct Location holds a location. So far, the only location is LOC_NONE, so this doesn't do anything useful yet. Passing the current location all over the place would be too cumbersome. Hide it away in static cur_loc instead, and provide accessors. Print it in error_report(). Store it in QError, and print it in qerror_print(). Store it in QemuOpt, for use by qemu_opts_foreach(). This makes error_report() do the right thing when it runs within qemu_opts_foreach(). We may still have to store it in other data structures holding user input for better error messages. Left for another day.
* Allow const QemuOptDescBlue Swirl2010-02-211-3/+3
| | | | Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* qemu-option: Make qemu_opts_foreach() accumulate return valuesMarkus Armbruster2010-02-031-1/+1
| | | | | | | | | | | | | Return the bitwise inclusive or of all return values instead of the last call's value. This lets you find out whether any of the calls returned a non-zero value. No functional change, as existing users either don't care for the value, or pass non-zero abort_on_failure, which breaks the loop on the first non-zero return value. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* QemuOpts: allow larger option values.Gerd Hoffmann2009-12-121-2/+2
| | | | | | | Use case: loooooooooooooooooong file names for -drive file=... Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-opts: Release id on deletionJan Kiszka2009-12-031-1/+2
| | | | | | | | The opts id is always allocated via qemu_strdup, so it need not be const, but it has to be released on opts deletion. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Never overwrite a QemuOptMark McLoughlin2009-10-061-28/+23Star
| | | | | | | | | | | | | Rather than overwriting a QemuOpt, just add a new one to the tail and always do a reverse search for parameters to preserve the same behaviour. We use this order so that foreach() iterates over the opts in their original order. This will allow us handle options where multiple values for the same parameter is allowed - e.g. -net user,hostfwd= Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Add qemu_opts_validate() for post parsing validationMark McLoughlin2009-10-061-0/+33
| | | | | | | | | | | | | Several qemu command line options have a parameter whose value affects what other parameters are accepted for the option. In these cases, we can have an empty description table in the QemuOptsList and once the option has been parsed we can use a suitable description table to validate the other parameters based on the value of that parameter. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Make qemu_opts_parse() handle empty stringsMark McLoughlin2009-10-061-3/+1Star
| | | | | | | | | Rather than making callers explicitly handle empty strings by using qemu_opts_create(), we can easily have qemu_opts_parse() handle empty parameter strings. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Remove bogus error message from qemu_opts_set()Mark McLoughlin2009-10-061-2/+0Star
| | | | | | | | | The only way qemu_opts_create() can fail is if a QemuOpts with that id already exists and fail_if_exists=1. In that case, we already print an error which makes more sense than the one in qemu_opts_set(). Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-option: rename bool -> booleanJuan Quintela2009-09-261-3/+3
| | | | | | | | We need this to allow the use of <stdbool.h> Signed-off-by: Juan Quintela <quintela@redhat.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* Fix coding style issueMark McLoughlin2009-09-251-3/+3
| | | | | | | | | | | | | | | | | | | | | | | Replace: if (-1 == foo()) with: if (foo() == -1) While this coding style is not in direct contravention of our currently ratified CODING_STYLE treaty, it could be argued that the Article 3 of the European Convention on Human Rights (prohibiting torture and "inhuman or degrading treatment") reads on the matter. [This commit message was brought to you without humour, as is evidenced by the absence of any emoticons] Signed-off-by: Mark McLoughlin <markmc@redhat.com> Cc: Avi Kivity <avi@redhat.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>