2009-05-18 16:42:09 +02:00
|
|
|
/*
|
|
|
|
* Commandline option parsing functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
|
* Copyright (c) 2009 Kevin Wolf <kwolf@redhat.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QEMU_OPTIONS_H
|
|
|
|
#define QEMU_OPTIONS_H
|
|
|
|
|
2009-09-20 09:51:06 +02:00
|
|
|
#include <stdint.h>
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/queue.h"
|
2012-12-17 18:19:43 +01:00
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "qapi/qmp/qdict.h"
|
2009-07-22 16:43:03 +02:00
|
|
|
|
2009-05-18 16:42:09 +02:00
|
|
|
const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
|
|
|
|
const char *get_opt_value(char *buf, int buf_size, const char *p);
|
2009-07-22 16:43:00 +02:00
|
|
|
int get_next_param_value(char *buf, int buf_size,
|
|
|
|
const char *tag, const char **pstr);
|
|
|
|
int get_param_value(char *buf, int buf_size,
|
|
|
|
const char *tag, const char *str);
|
2009-05-18 16:42:09 +02:00
|
|
|
|
|
|
|
|
2013-07-29 16:47:56 +02:00
|
|
|
void parse_option_size(const char *name, const char *value,
|
|
|
|
uint64_t *ret, Error **errp);
|
2014-02-21 16:24:03 +01:00
|
|
|
bool has_help_option(const char *param);
|
|
|
|
bool is_valid_option_list(const char *param);
|
2009-05-18 16:42:09 +02:00
|
|
|
|
2009-07-22 16:43:03 +02:00
|
|
|
typedef struct QemuOpt QemuOpt;
|
|
|
|
typedef struct QemuOpts QemuOpts;
|
|
|
|
typedef struct QemuOptsList QemuOptsList;
|
|
|
|
|
|
|
|
enum QemuOptType {
|
|
|
|
QEMU_OPT_STRING = 0, /* no parsing (use string as-is) */
|
|
|
|
QEMU_OPT_BOOL, /* on/off */
|
|
|
|
QEMU_OPT_NUMBER, /* simple number */
|
|
|
|
QEMU_OPT_SIZE, /* size, accepts (K)ilo, (M)ega, (G)iga, (T)era postfix */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct QemuOptDesc {
|
|
|
|
const char *name;
|
|
|
|
enum QemuOptType type;
|
|
|
|
const char *help;
|
2014-06-05 11:20:42 +02:00
|
|
|
const char *def_value_str;
|
2009-07-22 16:43:03 +02:00
|
|
|
} QemuOptDesc;
|
|
|
|
|
|
|
|
struct QemuOptsList {
|
|
|
|
const char *name;
|
2010-02-10 19:52:18 +01:00
|
|
|
const char *implied_opt_name;
|
2012-02-08 06:41:37 +01:00
|
|
|
bool merge_lists; /* Merge multiple uses of option into a single list? */
|
2009-09-12 09:36:22 +02:00
|
|
|
QTAILQ_HEAD(, QemuOpts) head;
|
2009-07-22 16:43:03 +02:00
|
|
|
QemuOptDesc desc[];
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *qemu_opt_get(QemuOpts *opts, const char *name);
|
QemuOpts: add qemu_opt_get_*_del functions for replace work
Add qemu_opt_get_del, qemu_opt_get_bool_del, qemu_opt_get_number_del and
qemu_opt_get_size_del to replace the same handling of QEMUOptionParameter
(get and delete).
Several drivers are coded to parse a known subset of options, then
remove them from the list before handing all remaining options to a
second driver for further option processing. get_*_del makes it easier
to retrieve a known option (or its default) and remove it from the list
all in one action.
Share common helper function:
For qemu_opt_get_bool/size/number, they and their get_*_del counterpart
could share most of the code except whether or not deleting the opt from
option list, so generate common helper functions.
For qemu_opt_get and qemu_opt_get_del, keep code duplication, since
1. qemu_opt_get_del returns malloc'd memory while qemu_opt_get returns
in-place memory
2. qemu_opt_get_del returns (char *), qemu_opt_get returns (const char *),
and could not change to (char *), since in one case, it will return
desc->def_value_str, which is (const char *).
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-06-05 11:20:46 +02:00
|
|
|
char *qemu_opt_get_del(QemuOpts *opts, const char *name);
|
2012-08-02 14:45:54 +02:00
|
|
|
/**
|
|
|
|
* qemu_opt_has_help_opt:
|
|
|
|
* @opts: options to search for a help request
|
|
|
|
*
|
|
|
|
* Check whether the options specified by @opts include one of the
|
|
|
|
* standard strings which indicate that the user is asking for a
|
|
|
|
* list of the valid values for a command line option (as defined
|
|
|
|
* by is_help_option()).
|
|
|
|
*
|
|
|
|
* Returns: true if @opts includes 'help' or equivalent.
|
|
|
|
*/
|
|
|
|
bool qemu_opt_has_help_opt(QemuOpts *opts);
|
2014-06-05 11:20:58 +02:00
|
|
|
QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name);
|
2011-10-25 08:40:39 +02:00
|
|
|
bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
|
2009-07-22 16:43:03 +02:00
|
|
|
uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval);
|
|
|
|
uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
|
QemuOpts: add qemu_opt_get_*_del functions for replace work
Add qemu_opt_get_del, qemu_opt_get_bool_del, qemu_opt_get_number_del and
qemu_opt_get_size_del to replace the same handling of QEMUOptionParameter
(get and delete).
Several drivers are coded to parse a known subset of options, then
remove them from the list before handing all remaining options to a
second driver for further option processing. get_*_del makes it easier
to retrieve a known option (or its default) and remove it from the list
all in one action.
Share common helper function:
For qemu_opt_get_bool/size/number, they and their get_*_del counterpart
could share most of the code except whether or not deleting the opt from
option list, so generate common helper functions.
For qemu_opt_get and qemu_opt_get_del, keep code duplication, since
1. qemu_opt_get_del returns malloc'd memory while qemu_opt_get returns
in-place memory
2. qemu_opt_get_del returns (char *), qemu_opt_get returns (const char *),
and could not change to (char *), since in one case, it will return
desc->def_value_str, which is (const char *).
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Chunyan Liu <cyliu@suse.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2014-06-05 11:20:46 +02:00
|
|
|
bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
|
|
|
|
uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
|
|
|
|
uint64_t defval);
|
|
|
|
uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
|
|
|
|
uint64_t defval);
|
2013-07-17 14:40:37 +02:00
|
|
|
int qemu_opt_unset(QemuOpts *opts, const char *name);
|
2009-07-22 16:43:03 +02:00
|
|
|
int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
|
2012-03-21 20:17:21 +01:00
|
|
|
void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
|
|
|
|
Error **errp);
|
2015-02-12 16:37:44 +01:00
|
|
|
void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val,
|
|
|
|
Error **errp);
|
2015-02-12 16:46:36 +01:00
|
|
|
void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val,
|
|
|
|
Error **errp);
|
2009-07-31 12:25:32 +02:00
|
|
|
typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque);
|
|
|
|
int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
|
|
|
|
int abort_on_failure);
|
2009-07-22 16:43:03 +02:00
|
|
|
|
|
|
|
QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
|
2012-03-20 19:51:57 +01:00
|
|
|
QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
|
|
|
|
int fail_if_exists, Error **errp);
|
2010-06-01 10:47:34 +02:00
|
|
|
void qemu_opts_reset(QemuOptsList *list);
|
2010-05-27 21:06:04 +02:00
|
|
|
void qemu_opts_loc_restore(QemuOpts *opts);
|
2015-02-12 17:07:34 +01:00
|
|
|
void qemu_opts_set(QemuOptsList *list, const char *id,
|
|
|
|
const char *name, const char *value, Error **errp);
|
2009-07-31 12:25:32 +02:00
|
|
|
const char *qemu_opts_id(QemuOpts *opts);
|
2013-07-11 12:52:34 +02:00
|
|
|
void qemu_opts_set_id(QemuOpts *opts, char *id);
|
2009-07-22 16:43:03 +02:00
|
|
|
void qemu_opts_del(QemuOpts *opts);
|
2012-04-12 16:58:57 +02:00
|
|
|
void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp);
|
2009-09-10 10:58:33 +02:00
|
|
|
int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname);
|
2010-02-10 19:52:18 +01:00
|
|
|
QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int permit_abbrev);
|
2012-01-27 19:54:54 +01:00
|
|
|
void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
|
|
|
|
int permit_abbrev);
|
2012-04-18 22:24:01 +02:00
|
|
|
QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict,
|
|
|
|
Error **errp);
|
2010-02-10 20:15:29 +01:00
|
|
|
QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
|
2013-03-15 10:35:05 +01:00
|
|
|
void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
|
2009-07-22 16:43:03 +02:00
|
|
|
|
|
|
|
typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
|
2014-12-09 08:38:04 +01:00
|
|
|
void qemu_opts_print(QemuOpts *opts, const char *sep);
|
2009-07-22 16:43:03 +02:00
|
|
|
int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
|
|
|
|
int abort_on_failure);
|
2014-06-05 11:20:47 +02:00
|
|
|
void qemu_opts_print_help(QemuOptsList *list);
|
2014-06-05 11:20:48 +02:00
|
|
|
void qemu_opts_free(QemuOptsList *list);
|
2014-06-05 11:21:11 +02:00
|
|
|
QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
|
2009-07-22 16:43:03 +02:00
|
|
|
|
2009-05-18 16:42:09 +02:00
|
|
|
#endif
|