[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 38/38] qom: Add user_creatable_parse_str()
From: |
Kevin Wolf |
Subject: |
[PULL 38/38] qom: Add user_creatable_parse_str() |
Date: |
Thu, 11 Mar 2021 15:48:11 +0100 |
The system emulator has a more complicated way of handling command line
options in that it reorders options before it processes them. This means
that parsing object options and creating the object happen at two
different points. Split the parsing part into a separate function that
can be reused by the system emulator command line.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
include/qom/object_interfaces.h | 15 +++++++++++++++
qom/object_interfaces.c | 20 ++++++++++++++------
2 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
index 07511e6cff..fb32330901 100644
--- a/include/qom/object_interfaces.h
+++ b/include/qom/object_interfaces.h
@@ -144,6 +144,21 @@ typedef bool (*user_creatable_add_opts_predicate)(const
char *type);
int user_creatable_add_opts_foreach(void *opaque,
QemuOpts *opts, Error **errp);
+/**
+ * user_creatable_parse_str:
+ * @optarg: the object definition string as passed on the command line
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Parses the option for the user creatable object with a keyval parser and
+ * implicit key 'qom-type', converting the result to ObjectOptions.
+ *
+ * If a help option is given, print help instead.
+ *
+ * Returns: ObjectOptions on success, NULL when an error occurred (*errp is set
+ * then) or help was printed (*errp is not set).
+ */
+ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp);
+
/**
* user_creatable_add_from_str:
* @optarg: the object definition string as passed on the command line
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 6dcab60f09..62d7db7629 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -292,7 +292,7 @@ static void user_creatable_print_help_from_qdict(QDict
*args)
}
}
-bool user_creatable_add_from_str(const char *optarg, Error **errp)
+ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
{
ERRP_GUARD();
QDict *args;
@@ -302,12 +302,12 @@ bool user_creatable_add_from_str(const char *optarg,
Error **errp)
args = keyval_parse(optarg, "qom-type", &help, errp);
if (*errp) {
- return false;
+ return NULL;
}
if (help) {
user_creatable_print_help_from_qdict(args);
qobject_unref(args);
- return false;
+ return NULL;
}
v = qobject_input_visitor_new_keyval(QOBJECT(args));
@@ -315,12 +315,20 @@ bool user_creatable_add_from_str(const char *optarg,
Error **errp)
visit_free(v);
qobject_unref(args);
- if (*errp) {
- goto out;
+ return options;
+}
+
+bool user_creatable_add_from_str(const char *optarg, Error **errp)
+{
+ ERRP_GUARD();
+ ObjectOptions *options;
+
+ options = user_creatable_parse_str(optarg, errp);
+ if (!options) {
+ return false;
}
user_creatable_add_qapi(options, errp);
-out:
qapi_free_ObjectOptions(options);
return !*errp;
}
--
2.29.2
- [PULL 29/38] qom: Make "object" QemuOptsList optional, (continued)
- [PULL 29/38] qom: Make "object" QemuOptsList optional, Kevin Wolf, 2021/03/11
- [PULL 32/38] qom: Factor out user_creatable_process_cmdline(), Kevin Wolf, 2021/03/11
- [PULL 31/38] qom: Remove user_creatable_add_dict(), Kevin Wolf, 2021/03/11
- [PULL 25/38] qapi/qom: Add ObjectOptions for confidential-guest-support, Kevin Wolf, 2021/03/11
- [PULL 28/38] qapi/qom: QAPIfy object-add, Kevin Wolf, 2021/03/11
- [PULL 26/38] qapi/qom: Add ObjectOptions for input-*, Kevin Wolf, 2021/03/11
- [PULL 30/38] qemu-storage-daemon: Implement --object with qmp_object_add(), Kevin Wolf, 2021/03/11
- [PULL 34/38] qemu-nbd: Use user_creatable_process_cmdline() for --object, Kevin Wolf, 2021/03/11
- [PULL 33/38] qemu-io: Use user_creatable_process_cmdline() for --object, Kevin Wolf, 2021/03/11
- [PULL 35/38] qom: Add user_creatable_add_from_str(), Kevin Wolf, 2021/03/11
- [PULL 38/38] qom: Add user_creatable_parse_str(),
Kevin Wolf <=
- [PULL 37/38] hmp: QAPIfy object_add, Kevin Wolf, 2021/03/11
- [PULL 36/38] qemu-img: Use user_creatable_process_cmdline() for --object, Kevin Wolf, 2021/03/11
- Re: [PULL 00/38] Block layer patches and object-add QAPIfication, Peter Maydell, 2021/03/12