[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH WIP 08/30] qemu-io: add support for --object command
From: |
Daniel P. Berrange |
Subject: |
[Qemu-block] [PATCH WIP 08/30] qemu-io: add support for --object command line arg |
Date: |
Fri, 20 Nov 2015 18:04:08 +0000 |
Allow creation of user creatable object types with qemu-io
via a --object command line arg. This will be used to supply
passwords and/or encryption keys to the various block driver
backends via the recently added 'secret' object type.
# echo -n letmein > mypasswd.txt
# qemu-io --object secret,id=sec0,file=mypasswd.txt \
...other args...
Signed-off-by: Daniel P. Berrange <address@hidden>
---
qemu-io.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 87 insertions(+)
diff --git a/qemu-io.c b/qemu-io.c
index 269f17c..cf1dac6 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -21,6 +21,8 @@
#include "qemu/config-file.h"
#include "qemu/readline.h"
#include "qapi/qmp/qstring.h"
+#include "qapi/opts-visitor.h"
+#include "qom/object_interfaces.h"
#include "sysemu/block-backend.h"
#include "block/block_int.h"
#include "trace/control.h"
@@ -205,6 +207,9 @@ static void usage(const char *name)
"Usage: %s [-h] [-V] [-rsnm] [-f FMT] [-c STRING] ... [file]\n"
"QEMU Disk exerciser\n"
"\n"
+" --object OBJECTDEF define a object such as 'secret' for\n"
+" providing passwords and/or encryption\n"
+" keys\n"
" -c, --cmd STRING execute command with its arguments\n"
" from the given string\n"
" -f, --format FMT specifies the block driver to use\n"
@@ -366,6 +371,71 @@ static void reenable_tty_echo(void)
qemu_set_tty_echo(STDIN_FILENO, true);
}
+enum {
+ OPTION_OBJECT = 258,
+};
+
+static QemuOptsList qemu_object_opts = {
+ .name = "object",
+ .implied_opt_name = "qom-type",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
+ .desc = {
+ { }
+ },
+};
+
+static int object_create(void *opaque, QemuOpts *opts, Error **errp)
+{
+ Error *err = NULL;
+ char *type = NULL;
+ char *id = NULL;
+ void *dummy = NULL;
+ OptsVisitor *ov;
+ QDict *pdict;
+
+ ov = opts_visitor_new(opts);
+ pdict = qemu_opts_to_qdict(opts, NULL);
+
+ visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
+ if (err) {
+ goto out;
+ }
+
+ qdict_del(pdict, "qom-type");
+ visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
+ if (err) {
+ goto out;
+ }
+
+ qdict_del(pdict, "id");
+ visit_type_str(opts_get_visitor(ov), &id, "id", &err);
+ if (err) {
+ goto out;
+ }
+
+ user_creatable_add(type, id, pdict, opts_get_visitor(ov), &err);
+ if (err) {
+ goto out;
+ }
+ visit_end_struct(opts_get_visitor(ov), &err);
+ if (err) {
+ user_creatable_del(id, NULL);
+ }
+
+out:
+ opts_visitor_cleanup(ov);
+
+ QDECREF(pdict);
+ g_free(id);
+ g_free(type);
+ g_free(dummy);
+ if (err) {
+ error_report_err(err);
+ return -1;
+ }
+ return 0;
+}
+
int main(int argc, char **argv)
{
int readonly = 0;
@@ -384,6 +454,7 @@ int main(int argc, char **argv)
{ "discard", 1, NULL, 'd' },
{ "cache", 1, NULL, 't' },
{ "trace", 1, NULL, 'T' },
+ { "object", 1, NULL, OPTION_OBJECT },
{ NULL, 0, NULL, 0 }
};
int c;
@@ -391,6 +462,7 @@ int main(int argc, char **argv)
int flags = BDRV_O_UNMAP;
Error *local_error = NULL;
QDict *opts = NULL;
+ QemuOpts *qopts = NULL;
#ifdef CONFIG_POSIX
signal(SIGPIPE, SIG_IGN);
@@ -399,6 +471,8 @@ int main(int argc, char **argv)
progname = basename(argv[0]);
qemu_init_exec_dir(argv[0]);
+ module_call_init(MODULE_INIT_QOM);
+ qemu_add_opts(&qemu_object_opts);
bdrv_init();
while ((c = getopt_long(argc, argv, sopt, lopt, &opt_index)) != -1) {
@@ -450,6 +524,13 @@ int main(int argc, char **argv)
case 'h':
usage(progname);
exit(0);
+ case OPTION_OBJECT:
+ qopts = qemu_opts_parse_noisily(qemu_find_opts("object"),
+ optarg, true);
+ if (!qopts) {
+ exit(1);
+ }
+ break;
default:
usage(progname);
exit(1);
@@ -466,6 +547,12 @@ int main(int argc, char **argv)
exit(1);
}
+ if (qemu_opts_foreach(qemu_find_opts("object"),
+ object_create,
+ NULL, NULL)) {
+ exit(1);
+ }
+
/* initialize commands */
qemuio_add_command(&quit_cmd);
qemuio_add_command(&open_cmd);
--
2.5.0
- [Qemu-block] [PATCH WIP 00/30] Support for full disk encryption, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 02/30] crypto: add support for loading encrypted x509 keys, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 04/30] qcow2: add a 'keyid' parameter to qcow2 options, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 01/30] crypto: add QCryptoSecret object class for password/key handling, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 03/30] qcow: add a 'keyid' parameter to qcow options, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 05/30] qom: add user_creatable_add & user_creatable_del methods, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 07/30] qemu-nbd: add support for --object command line arg, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 06/30] qemu-img: add support for --object command line arg, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 08/30] qemu-io: add support for --object command line arg,
Daniel P. Berrange <=
- [Qemu-block] [PATCH WIP 09/30] qemu-io: allow specifying image as a set of options args, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 16/30] crypto: add ability to query the cipher key, block & IV lens, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 15/30] qcow2: make qcow2_encrypt_sectors encrypt in place, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 17/30] crypto: add method for querying hash digest size, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 13/30] block: remove all encryption handling APIs, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 10/30] qemu-nbd: allow specifying image as a set of options args, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 21/30] crypto: add cryptographic random byte source, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 18/30] crypto: move QCryptoHashAlgorithm enum definition into QAPI, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 23/30] crypto: add support for generating initialization vectors, Daniel P. Berrange, 2015/11/20
- [Qemu-block] [PATCH WIP 14/30] block: remove support for writing to qcow/qcow2 encrypted images, Daniel P. Berrange, 2015/11/20