diff options
author | MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp> | 2010-05-26 11:35:36 +0900 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2010-05-28 13:14:25 +0200 |
commit | b50cbabc1bc12e6b0082089c70015c1b97db86a1 (patch) | |
tree | a15c87269cdba3aa8ba9f0bf2c1dd15f21a20681 /qemu-option.c | |
parent | 776cbbbd788686e9735e8d1c008d8bc105fb1fab (diff) | |
download | qemu-b50cbabc1bc12e6b0082089c70015c1b97db86a1.tar.gz qemu-b50cbabc1bc12e6b0082089c70015c1b97db86a1.tar.bz2 qemu-b50cbabc1bc12e6b0082089c70015c1b97db86a1.zip |
add support for protocol driver create_options
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>
Diffstat (limited to 'qemu-option.c')
-rw-r--r-- | qemu-option.c | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/qemu-option.c b/qemu-option.c index 076dddfc02..acd74f9124 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -346,6 +346,51 @@ void free_option_parameters(QEMUOptionParameter *list) } /* + * Count valid options in list + */ +static size_t count_option_parameters(QEMUOptionParameter *list) +{ + size_t num_options = 0; + + while (list && list->name) { + num_options++; + list++; + } + + return num_options; +} + +/* + * Append an option list (list) to an option list (dest). + * + * If dest is NULL, a new copy of list is created. + * + * Returns a pointer to the first element of dest (or the newly allocated copy) + */ +QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, + QEMUOptionParameter *list) +{ + size_t num_options, num_dest_options; + + num_options = count_option_parameters(dest); + num_dest_options = num_options; + + num_options += count_option_parameters(list); + + dest = qemu_realloc(dest, (num_options + 1) * sizeof(QEMUOptionParameter)); + + while (list && list->name) { + if (get_option_parameter(dest, list->name) == NULL) { + dest[num_dest_options++] = *list; + dest[num_dest_options].name = NULL; + } + list++; + } + + return dest; +} + +/* * Parses a parameter string (param) into an option list (dest). * * list is the templace is. If dest is NULL, a new copy of list is created for @@ -365,7 +410,6 @@ void free_option_parameters(QEMUOptionParameter *list) QEMUOptionParameter *parse_option_parameters(const char *param, QEMUOptionParameter *list, QEMUOptionParameter *dest) { - QEMUOptionParameter *cur; QEMUOptionParameter *allocated = NULL; char name[256]; char value[256]; @@ -379,12 +423,7 @@ QEMUOptionParameter *parse_option_parameters(const char *param, if (dest == NULL) { // Count valid options - num_options = 0; - cur = list; - while (cur->name) { - num_options++; - cur++; - } + num_options = count_option_parameters(list); // Create a copy of the option list to fill in values dest = qemu_mallocz((num_options + 1) * sizeof(QEMUOptionParameter)); |