From patchwork Tue Aug 13 04:32:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 266713 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (unknown [IPv6:2001:4830:134:3::12]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5FB072C013E for ; Tue, 13 Aug 2013 15:18:32 +1000 (EST) Received: from localhost ([::1]:37056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V96QK-0007jN-Sr for incoming@patchwork.ozlabs.org; Tue, 13 Aug 2013 00:41:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V96JN-0008WS-Tr for qemu-devel@nongnu.org; Tue, 13 Aug 2013 00:34:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V96JF-00011l-6F for qemu-devel@nongnu.org; Tue, 13 Aug 2013 00:34:25 -0400 Received: from mail-pb0-x236.google.com ([2607:f8b0:400e:c01::236]:58759) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V96JE-00011Y-T3 for qemu-devel@nongnu.org; Tue, 13 Aug 2013 00:34:17 -0400 Received: by mail-pb0-f54.google.com with SMTP id ro12so7532979pbb.41 for ; Mon, 12 Aug 2013 21:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=HIYeyidqXqpaM9YBM4K9r0Fg5QNExVMGGGIoMu+/KVo=; b=PbY6uWdbuGSpkwF88fvNd6EILh8Ps0S8RwgX1fzVBB6uIW4+m96E2Yjd8SI28a+aak gy7JIkrpI1/MRdVY8/SjkFHnY9IJZ2tZW0raakLF9Jfxy/9ZhB6Bsk4WL/zczd7zeJRc dUGv5Dsn34ChUjcO6MjVhNFqla7qOnlLSACPCi4iKQwCRJjFayYP0AMgXwAB0xgHE92e VIup0plug8NtG2B0z61ZuEQxHYoUmSx/iKqGfS0eHFowtJH1lyUsKjnBqmt5XSPmHgrD ZBZpLBViwEpeTslCXJin45e6yDOV7ZGl3QoqYMnP3i+OyfxOt5xqAAPgUyb4U7ztGLSW jKug== X-Received: by 10.68.139.201 with SMTP id ra9mr2467404pbb.46.1376368456123; Mon, 12 Aug 2013 21:34:16 -0700 (PDT) Received: from 11.wdongxu.kvm58 ([202.108.130.153]) by mx.google.com with ESMTPSA id mz5sm10285023pbc.18.2013.08.12.21.34.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 12 Aug 2013 21:34:15 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Tue, 13 Aug 2013 12:32:06 +0800 Message-Id: <1376368326-7433-26-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1376368326-7433-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1376368326-7433-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::236 Cc: kwolf@redhat.com, wdongxu@cn.ibm.com, stefanha@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH V18 25/25] qemu-option: remove QEMUOptionParameter related functions and struct X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Dong Xu Wang Conflicts: include/qemu/option.h --- block.c | 1 - include/qemu/option.h | 39 ------- util/qemu-option.c | 285 -------------------------------------------------- 3 files changed, 325 deletions(-) diff --git a/block.c b/block.c index c1130b8..e7ed659 100644 --- a/block.c +++ b/block.c @@ -365,7 +365,6 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name, typedef struct CreateCo { BlockDriver *drv; char *filename; - QEMUOptionParameter *options; QemuOpts *opts; int ret; } CreateCo; diff --git a/include/qemu/option.h b/include/qemu/option.h index 64d7327..c7c8379 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -31,24 +31,6 @@ #include "qapi/error.h" #include "qapi/qmp/qdict.h" -enum QEMUOptionParType { - OPT_FLAG, - OPT_NUMBER, - OPT_SIZE, - OPT_STRING, -}; - -typedef struct QEMUOptionParameter { - const char *name; - enum QEMUOptionParType type; - union { - uint64_t n; - char* s; - } value; - const char *help; -} QEMUOptionParameter; - - 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); int get_next_param_value(char *buf, int buf_size, @@ -56,29 +38,8 @@ int get_next_param_value(char *buf, int buf_size, int get_param_value(char *buf, int buf_size, const char *tag, const char *str); - -/* - * The following functions take a parameter list as input. This is a pointer to - * the first element of a QEMUOptionParameter array which is terminated by an - * entry with entry->name == NULL. - */ - -QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list, - const char *name); -int set_option_parameter(QEMUOptionParameter *list, const char *name, - const char *value); -int set_option_parameter_int(QEMUOptionParameter *list, const char *name, - uint64_t value); -QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, - QEMUOptionParameter *list); -QEMUOptionParameter *parse_option_parameters(const char *param, - QEMUOptionParameter *list, QEMUOptionParameter *dest); void parse_option_size(const char *name, const char *value, uint64_t *ret, Error **errp); -void free_option_parameters(QEMUOptionParameter *list); -void print_option_parameters(QEMUOptionParameter *list); -void print_option_help(QEMUOptionParameter *list); - /* ------------------------------------------------------------------ */ typedef struct QemuOpt QemuOpt; diff --git a/util/qemu-option.c b/util/qemu-option.c index 861929d..94e0339 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -123,22 +123,6 @@ int get_param_value(char *buf, int buf_size, return get_next_param_value(buf, buf_size, tag, &str); } -/* - * Searches an option list for an option with the given name - */ -QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list, - const char *name) -{ - while (list && list->name) { - if (!strcmp(list->name, name)) { - return list; - } - list++; - } - - return NULL; -} - static void parse_option_bool(const char *name, const char *value, bool *ret, Error **errp) { @@ -212,275 +196,6 @@ void parse_option_size(const char *name, const char *value, } } -/* - * Sets the value of a parameter in a given option list. The parsing of the - * value depends on the type of option: - * - * OPT_FLAG (uses value.n): - * If no value is given, the flag is set to 1. - * Otherwise the value must be "on" (set to 1) or "off" (set to 0) - * - * OPT_STRING (uses value.s): - * value is strdup()ed and assigned as option value - * - * OPT_SIZE (uses value.n): - * The value is converted to an integer. Suffixes for kilobytes etc. are - * allowed (powers of 1024). - * - * Returns 0 on succes, -1 in error cases - */ -int set_option_parameter(QEMUOptionParameter *list, const char *name, - const char *value) -{ - bool flag; - Error *local_err = NULL; - - // Find a matching parameter - list = get_option_parameter(list, name); - if (list == NULL) { - fprintf(stderr, "Unknown option '%s'\n", name); - return -1; - } - - // Process parameter - switch (list->type) { - case OPT_FLAG: - parse_option_bool(name, value, &flag, &local_err); - if (!error_is_set(&local_err)) { - list->value.n = flag; - } - break; - - case OPT_STRING: - if (value != NULL) { - list->value.s = g_strdup(value); - } else { - fprintf(stderr, "Option '%s' needs a parameter\n", name); - return -1; - } - break; - - case OPT_SIZE: - parse_option_size(name, value, &list->value.n, &local_err); - break; - - default: - fprintf(stderr, "Bug: Option '%s' has an unknown type\n", name); - return -1; - } - - if (error_is_set(&local_err)) { - qerror_report_err(local_err); - error_free(local_err); - return -1; - } - - return 0; -} - -/* - * Sets the given parameter to an integer instead of a string. - * This function cannot be used to set string options. - * - * Returns 0 on success, -1 in error cases - */ -int set_option_parameter_int(QEMUOptionParameter *list, const char *name, - uint64_t value) -{ - // Find a matching parameter - list = get_option_parameter(list, name); - if (list == NULL) { - fprintf(stderr, "Unknown option '%s'\n", name); - return -1; - } - - // Process parameter - switch (list->type) { - case OPT_FLAG: - case OPT_NUMBER: - case OPT_SIZE: - list->value.n = value; - break; - - default: - return -1; - } - - return 0; -} - -/* - * Frees a option list. If it contains strings, the strings are freed as well. - */ -void free_option_parameters(QEMUOptionParameter *list) -{ - QEMUOptionParameter *cur = list; - - while (cur && cur->name) { - if (cur->type == OPT_STRING) { - g_free(cur->value.s); - } - cur++; - } - - g_free(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 = g_realloc(dest, (num_options + 1) * sizeof(QEMUOptionParameter)); - dest[num_dest_options].name = NULL; - - 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 template option list. If dest is NULL, a new copy of list is - * created. If list is NULL, this function fails. - * - * A parameter string consists of one or more parameters, separated by commas. - * Each parameter consists of its name and possibly of a value. In the latter - * case, the value is delimited by an = character. To specify a value which - * contains commas, double each comma so it won't be recognized as the end of - * the parameter. - * - * For more details of the parsing see above. - * - * Returns a pointer to the first element of dest (or the newly allocated copy) - * or NULL in error cases - */ -QEMUOptionParameter *parse_option_parameters(const char *param, - QEMUOptionParameter *list, QEMUOptionParameter *dest) -{ - QEMUOptionParameter *allocated = NULL; - char name[256]; - char value[256]; - char *param_delim, *value_delim; - char next_delim; - - if (list == NULL) { - return NULL; - } - - if (dest == NULL) { - dest = allocated = append_option_parameters(NULL, list); - } - - while (*param) { - - // Find parameter name and value in the string - param_delim = strchr(param, ','); - value_delim = strchr(param, '='); - - if (value_delim && (value_delim < param_delim || !param_delim)) { - next_delim = '='; - } else { - next_delim = ','; - value_delim = NULL; - } - - param = get_opt_name(name, sizeof(name), param, next_delim); - if (value_delim) { - param = get_opt_value(value, sizeof(value), param + 1); - } - if (*param != '\0') { - param++; - } - - // Set the parameter - if (set_option_parameter(dest, name, value_delim ? value : NULL)) { - goto fail; - } - } - - return dest; - -fail: - // Only free the list if it was newly allocated - free_option_parameters(allocated); - return NULL; -} - -/* - * Prints all options of a list that have a value to stdout - */ -void print_option_parameters(QEMUOptionParameter *list) -{ - while (list && list->name) { - switch (list->type) { - case OPT_STRING: - if (list->value.s != NULL) { - printf("%s='%s' ", list->name, list->value.s); - } - break; - case OPT_FLAG: - printf("%s=%s ", list->name, list->value.n ? "on" : "off"); - break; - case OPT_SIZE: - case OPT_NUMBER: - printf("%s=%" PRId64 " ", list->name, list->value.n); - break; - default: - printf("%s=(unknown type) ", list->name); - break; - } - list++; - } -} - -/* - * Prints an overview of all available options - */ -void print_option_help(QEMUOptionParameter *list) -{ - printf("Supported options:\n"); - while (list && list->name) { - printf("%-16s %s\n", list->name, - list->help ? list->help : "No description available"); - list++; - } -} - /* ------------------------------------------------------------------ */ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char *name)