/* * Options Visitor * * Copyright Red Hat, Inc. 2012-2016 * * Author: Laszlo Ersek * * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. * See the COPYING.LIB file in the top-level directory. * */ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu/cutils.h" #include "qapi/qmp/qerror.h" #include "qapi/opts-visitor.h" #include "qemu/queue.h" #include "qemu/option_int.h" #include "qapi/visitor-impl.h" enum ListMode { LM_NONE, /* not traversing a list of repeated options */ LM_STARTED, /* opts_start_list() succeeded */ LM_IN_PROGRESS, /* opts_next_list() has been called. * * Generating the next list link will consume the most * recently parsed QemuOpt instance of the repeated * option. * * Parsing a value into the list link will examine the * next QemuOpt instance of the repeated option, and * possibly enter LM_SIGNED_INTERVAL or * LM_UNSIGNED_INTERVAL. */ LM_SIGNED_INTERVAL, /* opts_next_list() has been called. * * Generating the next list link will consume the most * recently stored element from the signed interval, * parsed from the most recent QemuOpt instance of the * repeated option. This may consume QemuOpt itself * and return to LM_IN_PROGRESS. * * Parsing a value into the list link will store the * next element of the signed interval. */ LM_UNSIGNED_INTERVAL /* Same as above, only for an unsigned interval. */ }; typedef enum ListMode ListMode; struct OptsVisitor { Visitor visitor; /* Ownership remains with opts_visitor_new()'s caller. */ const QemuOpts *opts_root; unsigned depth; /* Non-null iff depth is positive. Each key is a QemuOpt name. Each value * is a non-empty GQueue, enumerating all QemuOpt occurrences with that * name. */ GHashTable *unprocessed_opts; /* The list currently being traversed with opts_start_list() / * opts_next_list(). The list must have a struct element type in the * schema, with a single mandatory scalar member. */ ListMode list_mode; GQueue *repeated_opts; /* When parsing a list of repeating options as integers, values of the form * "a-b", representing a closed interval, are allowed. Elements in the * range are generated individually. */ union { int64_t s; uint64_t u; } range_next, range_limit; /* If "opts_root->id" is set, reinstantiate it as a fake QemuOpt for * uniformity. Only its "name" and "str" fields are set. "fake_id_opt" does * not survive or escape the OptsVisitor object. */ QemuOpt *fake_id_opt; }; static OptsVisitor *to_ov(Visitor *v) { return container_of(v, OptsVisitor, visitor); } static void destroy_list(gpointer list) { g_queue_free(list); } static void opts_visitor_insert(GHashTable *unprocessed_opts, const QemuOpt *opt) { GQueue *list; list = g_hash_table_lookup(unprocessed_opts, opt->name); if (list == NULL) { list = g_queue_new(); /* GHashTable will never try to free the keys -- we supply NULL as * "key_destroy_func" in opts_start_struct(). Thus cast away key * const-ness in order to suppress gcc's warning. */ g_hash_table_insert(unprocessed_opts, (gpointer)opt->name, list); } /* Similarly, destroy_list() doesn't call g_queue_free_full(). */ g_queue_push_tail(list, (gpointer)opt); } static void opts_start_struct(Visitor *v, const char *name, void **obj, size_t size, Error **errp) { OptsVisitor *ov = to_ov(v); const QemuOpt *opt; if (obj) { *obj = g_malloc0(size > 0 ? size : 1); } if (ov->depth++ > 0) { return; } ov->unprocessed_opts = g_hash_table_new_full(&g_str_hash, &g_str_equal, NULL, &destroy_list); QTAILQ_FOREACH(opt, &ov->opts_root->head, next) { /* ensured by qemu-option.c::opts_do_parse() */ assert(strcmp(opt->name, "id") != 0); opts_visitor_insert(ov->unprocessed_opts, opt); } if (ov->opts_root->id != NULL) { ov->fake_id_opt = g_malloc0(sizeof *ov->fake_id_opt); ov->fake_id_opt->name = g_strdup("id"); ov->fake_id_opt->str = g_strdup(ov->opts_root->id); opts_visitor_insert(ov->unprocessed_opts, ov->fake_id_opt); } } static void opts_end_struct(Visitor *v, Error **errp) { OptsVisitor *ov = to_ov(v); GHashTableIter iter; GQueue *any; if (--ov->depth > 0) { return; } /* we should have processed all (distinct) QemuOpt instances */ g_hash_table_iter_init(&iter, ov->unprocessed_opts); if (g_hash_table_iter_next(&iter, NULL, (void **)&any)) { const QemuOpt *first; first = g_queue_peek_head(any); error_setg(errp, QERR_INV
##############################################################################
# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
---
# Sample test case for ha

schema: "yardstick:task:0.1"

scenarios:
-
  type: