Convert commands to QAPI (batch 1) (v2)
Subsystems (2)
cover Convert commands to QAPI (batch 1) (v2)
This is my attempt to jump-start the QAPI switch over. All of the hard work is already done in my qapi branch, we just need to start merging stuff.
To simplify the merge process, I've introduced a new mode to the code generator that lets us do conversions without using the new QMP server.
Once this series is merged, anything that touchs QMP (to modify a command or add a new command) must do it through QAPI--no exceptions.
This series also includes Dans change to the 'change' command. I'm not thrilled about people using this command but its better to err on the side of caution. It's now officially deprecated with much more robust replacement commands.
Since v1, I've tried to address all review comments. I've also tested the modified commands extensively.
PATCH 1/15 error: let error_is_type take a NULL error
--- error.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
error.c +4 -0
@@ -97,6 +97,10 @@ bool error_is_type(Error *err, const char *fmt)char *ptr;char *end; +if (!err) { +return false; + } + ptr =strstr (fmt,"'class': '" );assert (ptr !=NULL ); ptr +=strlen ("'class': '" );
Signature · 1 line
1.7.4.1
PATCH 2/15 qerror: add qerror_report_err() (v2)
In reply to Anthony LiguoriThis provides a bridge between Error (new error mechanism) and QError (old error mechanism). Errors can be propagated whereas QError cannot.
The minor evilness avoids layering violations. Since QError should go away RSN, it seems like a reasonable hack.
---
v1 -> v2
- Fix propagation of error to the monitor (Luiz)
--- qerror.c | 33 +++++++++++++++++++++++++++++++++ qerror.h | 2 ++ 2 files changed, 35 insertions(+), 0 deletions(-)
qerror.c +33 -0
@@ -478,6 +478,39 @@ void qerror_report_internal(const char *file, int linenr, const char *func, } } +/* Evil... */ +struct Error +{ +QDict *obj; +const char *fmt; +char *msg; +}; + +void qerror_report_err (Error *err) +{ +QError *qerr; +int i; + + qerr =qerror_new (); +loc_save (&qerr->loc); +QINCREF (err->obj); + qerr->error = err->obj; + +for (i =0 ; qerror_table[i].error_fmt; i++) { +if (strcmp (qerror_table[i].error_fmt, err->fmt) ==0 ) { + qerr->entry = &qerror_table[i]; +break ; + } + } + +if (monitor_cur_is_qmp ()) { +monitor_set_error (cur_mon, qerr); + }else { +qerror_print (qerr); +QDECREF (qerr); + } +} +/** * qobject_to_qerror(): Convert a QObject into a QError */
qerror.h +2 -0
@@ -15,6 +15,7 @@#include "qdict.h" #include "qstring.h" #include "qemu-error.h" +#include "error.h" #include <stdarg.h> typedef struct QErrorStringTable {
@@ -39,6 +40,7 @@ QString *qerror_human(const QError *qerror);void qerror_print (QError *qerror); void qerror_report_internal(const char *file, int linenr, const char *func, const char *fmt, ...) GCC_FMT_ATTR(4, 5); +void qerror_report_err (Error *err);QString *qerror_format (const char *fmt,QDict *error);#define qerror_report (fmt, ...) \ qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
Signature · 1 line
1.7.4.1
PATCH 3/15 qapi: add code generation support for middle mode
In reply to Anthony LiguoriTo get the ball rolling merging QAPI, this patch introduces a "middle mode" to the code generator. In middle mode, the code generator generates marshalling functions that are compatible with the current QMP server. We absolutely need to replace the current QMP server in order to support proper asynchronous commands but using a middle mode provides a middle-ground that lets us start converting commands in tree.
Note that all of the commands have been converted already in my glib branch. Middle mode only exists until we finish merging them from my branch into the main tree.
--- qapi/qapi-types-core.h | 3 ++ scripts/qapi-commands.py | 79 +++++++++++++++++++++++++++++++++++++-------- scripts/qapi-types.py | 3 ++ scripts/qapi.py | 4 ++- 4 files changed, 74 insertions(+), 15 deletions(-)
qapi/qapi-types-core.h +3 -0
@@ -17,4 +17,7 @@#include "qemu-common.h" #include "error.h" +/* FIXME this is temporary until we remove middle mode */ +#include "monitor.h" +#endif
scripts/qapi-commands.py +65 -14
150 lines not on this page · raw message
scripts/qapi-types.py +3 -0
@@ -268,3 +268,6 @@ fdecl.write(''' fdecl.flush() fdecl.close() + +fdef.flush() +fdef.close()
scripts/qapi.py +3 -1
@@ -200,4 +200,6 @@ def basename(filename): return filename.split("/")[-1] def guardname(filename): - return filename.replace("/", "_").replace("-", "_").split(".")[0].upper() + if filename.startswith('./'): + filename = filename[2:] + return filename.replace("/", "_").replace("-", "_").split(".")[0].upper() + '_H'
Signature · 1 line
1.7.4.1
PATCH 4/15 qapi: use middle mode in QMP server (v2)
In reply to Anthony LiguoriUse the new middle mode within the existing QMP server.
---
v1 -> v2
- fixed some of the generated header dependencies
--- Makefile | 12 ++++++++++++ Makefile.objs | 2 ++ Makefile.target | 6 +++--- monitor.c | 11 ++++++++--- qapi-schema.json | 3 +++ 5 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 qapi-schema.json
Makefile +12 -0
@@ -4,6 +4,7 @@ GENERATED_HEADERS = config-host.h trace.h qemu-options.def ifeq ($(TRACE_BACKEND),dtrace) GENERATED_HEADERS += trace-dtrace.h endif +GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h ifneq ($(wildcard config-host.mak),) # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -184,9 +185,20 @@ $(qapi-dir)/qga-qapi-types.h: $(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scr $(qapi-dir)/qga-qapi-visit.c: $(qapi-dir)/qga-qapi-visit.h $(qapi-dir)/qga-qapi-visit.h: $(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-visit.py $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "$(qapi-dir)" -p "qga-" < $<, " GEN $@") +$(qapi-dir)/qga-qmp-commands.h: $(qapi-dir)/qga-qmp-marshal.c $(qapi-dir)/qga-qmp-marshal.c: $(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-commands.py $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -o "$(qapi-dir)" -p "qga-" < $<, " GEN $@") +qapi-types.c: qapi-types.h +qapi-types.h: $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py -o "." < $<, " GEN $@") +qapi-visit.c: qapi-visit.h +qapi-visit.h: $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "." < $<, " GEN $@") +qmp-commands.h: qmp-marshal.c +qmp-marshal.c: $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -m -o "." < $<, " GEN $@") + test-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) test-visitor: test-visitor.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o $(qapi-obj-y) error.o osdep.o $(oslib-obj-y) qjson.o json-streamer.o json-lexer.o json-parser.o qerror.o qemu-error.o qemu-tool.o $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o
Makefile.objs +2 -0
@@ -402,6 +402,8 @@ qapi-nested-y = qapi-visit-core.o qmp-input-visitor.o qmp-output-visitor.o qapi- qapi-nested-y += qmp-registry.o qmp-dispatch.o qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y)) +common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y) + ###################################################################### # guest agent
Makefile.target +3 -3
@@ -371,7 +371,7 @@ obj-alpha-y += vga.o cirrus_vga.o main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) -monitor.o: hmp-commands.h qmp-commands.h +monitor.o: hmp-commands.h qmp-commands-old.h $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
@@ -403,13 +403,13 @@ gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/scripts/feature_to_c.sh hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $(TARGET_DIR)$@") -qmp-commands.h: $(SRC_PATH)/qmp-commands.hx +qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $(TARGET_DIR)$@") clean: rm -f *.o *.a *~ $(PROGS) nwfpe/*.o fpu/*.o rm -f *.d */*.d tcg/*.o ide/*.o 9pfs/*.o - rm -f hmp-commands.h qmp-commands.h gdbstub-xml.c + rm -f hmp-commands.h qmp-commands-old.h gdbstub-xml.c ifdef CONFIG_TRACE_SYSTEMTAP rm -f *.stp endif
monitor.c +8 -3
@@ -121,6 +121,7 @@ typedef struct mon_cmd_t {int (*cmd_async)(Monitor *mon,const QDict *params,MonitorCompletion *cb,void *opaque); } mhandler; +bool qapi;int flags; } mon_cmd_t;
@@ -3159,7 +3160,7 @@ static const mon_cmd_t info_cmds[] = { };static const mon_cmd_t qmp_cmds[] = { -#include "qmp-commands.h" +#include "qmp-commands-old.h" {/* NULL */ }, };
@@ -5029,10 +5030,14 @@ static void qmp_call_query_cmd(Monitor *mon, const mon_cmd_t *cmd)if (monitor_has_error (mon)) {monitor_protocol_emitter (mon,NULL ); } - }else { - cmd->mhandler.info_new (mon, &ret_data); + }else if (cmd->qapi) { +QDict *args =qdict_new (); + + cmd->mhandler.cmd_new (mon, args, &ret_data);monitor_protocol_emitter (mon, ret_data);qobject_decref (ret_data); + +QDECREF (args); } }
qapi-schema.json new file +3 -0
@@ -0,0 +1,3 @@ +# -*- Mode: Python -*- +# +# QAPI Schema
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH 04/15] qapi: use middle mode in QMP server (v2)
Quoted 112 lines · On Fri, 2 Sep 2011 12:34:47 -0500 Anthony Liguori <[email protected]> wrote:
Use the new middle mode within the existing QMP server.
Signed-off-by Anthony Liguori <[email protected]>---
v1 -> v2
- fixed some of the generated header dependencies--- Makefile | 12 ++++++++++++ Makefile.objs | 2 ++ Makefile.target | 6 +++--- monitor.c | 11 ++++++++--- qapi-schema.json | 3 +++ 5 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 qapi-schema.jsonMakefile +12
-0@@ -4,6 +4,7 @@ GENERATED_HEADERS = config-host.h trace.h qemu-options.def ifeq ($(TRACE_BACKEND),dtrace) GENERATED_HEADERS += trace-dtrace.h endif +GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h ifneq ($(wildcard config-host.mak),) # Put the all: rule here so that config-host.mak can contain dependencies.@@ -184,9 +185,20 @@ $(qapi-dir)/qga-qapi-types.h: $(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scr $(qapi-dir)/qga-qapi-visit.c: $(qapi-dir)/qga-qapi-visit.h $(qapi-dir)/qga-qapi-visit.h: $(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-visit.py $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "$(qapi-dir)" -p "qga-" < $<, " GEN $@") +$(qapi-dir)/qga-qmp-commands.h: $(qapi-dir)/qga-qmp-marshal.c $(qapi-dir)/qga-qmp-marshal.c: $(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-commands.py $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -o "$(qapi-dir)" -p "qga-" < $<, " GEN $@") +qapi-types.c: qapi-types.h +qapi-types.h: $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py -o "." < $<, " GEN $@") +qapi-visit.c: qapi-visit.h +qapi-visit.h: $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "." < $<, " GEN $@") +qmp-commands.h: qmp-marshal.c +qmp-marshal.c: $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -m -o "." < $<, " GEN $@") + test-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y) test-visitor: test-visitor.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o $(qapi-obj-y) error.o osdep.o $(oslib-obj-y) qjson.o json-streamer.o json-lexer.o json-parser.o qerror.o qemu-error.o qemu-tool.o $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.oMakefile.objs +2
-0@@ -402,6 +402,8 @@ qapi-nested-y = qapi-visit-core.o qmp-input-visitor.o qmp-output-visitor.o qapi- qapi-nested-y += qmp-registry.o qmp-dispatch.o qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y)) +common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y) + ###################################################################### # guest agentMakefile.target +3
-3@@ -371,7 +371,7 @@ obj-alpha-y += vga.o cirrus_vga.o main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) -monitor.o: hmp-commands.h qmp-commands.h +monitor.o: hmp-commands.h qmp-commands-old.h $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)@@ -403,13 +403,13 @@ gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/scripts/feature_to_c.sh hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $(TARGET_DIR)$@") -qmp-commands.h: $(SRC_PATH)/qmp-commands.hx +qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@," GEN $(TARGET_DIR)$@") clean: rm -f *.o *.a *~ $(PROGS) nwfpe/*.o fpu/*.o rm -f *.d */*.d tcg/*.o ide/*.o 9pfs/*.o - rm -f hmp-commands.h qmp-commands.h gdbstub-xml.c + rm -f hmp-commands.h qmp-commands-old.h gdbstub-xml.c ifdef CONFIG_TRACE_SYSTEMTAP rm -f *.stp endifmonitor.c +2
-1@@ -121,6 +121,7 @@ typedef struct mon_cmd_t {int (*cmd_async)(Monitor *mon,const QDict *params,MonitorCompletion *cb,void *opaque); } mhandler; +bool qapi;int flags; } mon_cmd_t;@@ -3159,7 +3160,7 @@ static const mon_cmd_t info_cmds[] = { };static const mon_cmd_t qmp_cmds[] = { -#include "qmp-commands.h" +#include "qmp-commands-old.h" {/* NULL */ }, };
monitor.c static void qmp_call_query_cmd(Monitor *mon, const mon_cmd_t *cmd) · line 5033
Quoted 5 lines
monitor.c +0
-2@@ -5029,10 +5030,14 @@ static void qmp_call_query_cmd(Monitor *mon, const mon_cmd_t *cmd)if (monitor_has_error (mon)) {monitor_protocol_emitter (mon,NULL ); } - }else { - cmd->mhandler.info_new (mon, &ret_data);
The else clause can't be dropped, otherwise non-qapi converted query commands won't work.
I can fix it myself in case this is going through my tree (and in case there isn't any other change request).
Quoted 20 lines
monitor.c +6
-0+ }else if (cmd->qapi) { +QDict *args =qdict_new (); + + cmd->mhandler.cmd_new (mon, args, &ret_data);monitor_protocol_emitter (mon, ret_data);qobject_decref (ret_data); + +QDECREF (args); } }qapi-schema.json new file +3
-0@@ -0,0 +1,3 @@ +# -*- Mode: Python -*- +# +# QAPI Schema
PATCH 5/15 qapi: convert query-name
In reply to Anthony LiguoriA simple example conversion 'info name'. This also adds the new files for QMP and HMP.
--- Makefile.objs | 1 + hmp.c | 26 ++++++++++++++++++++++++++ hmp.h | 22 ++++++++++++++++++++++ monitor.c | 27 +++++---------------------- qapi-schema.json | 23 +++++++++++++++++++++++ qmp.c | 28 ++++++++++++++++++++++++++++ 6 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 hmp.c create mode 100644 hmp.h create mode 100644 qmp.c
Makefile.objs +1 -0
@@ -403,6 +403,7 @@ qapi-nested-y += qmp-registry.o qmp-dispatch.o qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y)) common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y) +common-obj-y += qmp.o hmp.o ###################################################################### # guest agent
hmp.c new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Human Monitor Interface +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* Anthony Liguori <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#include "hmp.h" +#include "qmp-commands.h" + +void hmp_info_name (Monitor *mon) +{ +NameInfo *info; + + info =qmp_query_name (NULL ); +if (info->has_name) { +monitor_printf (mon,"%s\n" , info->name); + } +qapi_free_NameInfo (info); +}
hmp.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Human Monitor Interface +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* Anthony Liguori <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#ifndef HMP_H +#define HMP_H + +#include "qemu-common.h" +#include "qapi-types.h" + +void hmp_info_name (Monitor *mon); + +#endif
monitor.c +5 -22
@@ -63,6 +63,8 @@#endif #include "trace/control.h" #include "ui/qemu-spice.h" +#include "qmp-commands.h" +#include "hmp.h" //#define DEBUG //#define DEBUG_COMPLETION
@@ -759,24 +761,6 @@ static void do_info_version(Monitor *mon, QObject **ret_data) 'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION); } -static void do_info_name_print (Monitor *mon,const QObject *data) -{ -QDict *qdict; - - qdict =qobject_to_qdict (data); -if (qdict_size (qdict) ==0 ) { -return ; - } - -monitor_printf (mon,"%s\n" ,qdict_get_str (qdict,"name" )); -} - -static void do_info_name (Monitor *mon,QObject **ret_data) -{ - *ret_data = qemu_name ?qobject_from_jsonf ("{'name': %s }" , qemu_name) : -qobject_from_jsonf ("{}" ); -} -static QObject *get_cmd_dict (const char *name) {const char *p;
@@ -3071,8 +3055,7 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the current VM name", - .user_print = do_info_name_print, - .mhandler.info_new = do_info_name, + .mhandler.info = hmp_info_name, }, { .name = "uuid",
@@ -3268,8 +3251,8 @@ static const mon_cmd_t qmp_query_cmds[] = { .args_type = "", .params = "", .help = "show the current VM name", - .user_print = do_info_name_print, - .mhandler.info_new = do_info_name, + .mhandler.cmd_new = qmp_marshal_input_query_name, + .qapi = true, }, { .name = "uuid",
qapi-schema.json +23 -0
@@ -1,3 +1,26 @@ # -*- Mode: Python -*- # # QAPI Schema + +## +# @NameInfo: +# +# Guest name information. +# +# @name: #optional The name of the guest +# +# Since 0.14.0 +## +{ 'type': 'NameInfo', 'data': {'*name': 'str'} } + +## +# @query-name: +# +# Return the name information of a guest. +# +# Returns: @NameInfo of the guest +# +# Since 0.14.0 +## +{ 'command': 'query-name', 'returns': 'NameInfo' } +
qmp.c new file +28 -0
@@ -0,0 +1,28 @@ +/* +* QEMU Management Protocol +* +* Copyright IBM, Corp. 2011 +* +* Authors: +* Anthony Liguori <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +*/ + +#include "qemu-common.h" +#include "sysemu.h" +#include "qmp-commands.h" + +NameInfo *qmp_query_name (Error **errp) +{ +NameInfo *info =g_malloc0 (sizeof (*info)); + +if (qemu_name) { + info->has_name = true; + info->name =g_strdup (qemu_name); + } + +return info; +}
Signature · 1 line
1.7.4.1
PATCH 6/15 block: add unsafe_probe
In reply to Anthony LiguoriMark formats that cannot be probed with 100% reliability (just raw). This is necessary to implement change-blockdev.
--- block/raw.c | 2 ++ block_int.h | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)
block/raw.c +2 -0
@@ -145,6 +145,8 @@ static BlockDriver bdrv_raw = { .bdrv_create = raw_create, .create_options = raw_create_options, .bdrv_has_zero_init = raw_has_zero_init, + + .unsafe_probe = true, };static void bdrv_raw_init (void )
block_int.h +2 -0
@@ -146,6 +146,8 @@ struct BlockDriver {*/ int (*bdrv_has_zero_init)(BlockDriverState *bs); +bool unsafe_probe; +QLIST_ENTRY (BlockDriver) list; };
Signature · 1 line
1.7.4.1
PATCH 7/15 monitor: expose readline state
In reply to Anthony LiguoriHMP is now implemented in terms of QMP. The monitor has a bunch of logic to deal with HMP right now like readline support. Export it from the monitor so we can consume it in hmp.c.
In short time, hmp.c will take over all of the readline bits.
--- monitor.c | 11 ++++++++--- monitor.h | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-)
monitor.c +8 -3
@@ -223,7 +223,7 @@ int monitor_cur_is_qmp(void)return cur_mon &&monitor_ctrl_mode (cur_mon); } -static void monitor_read_command (Monitor *mon,int show_prompt) +void monitor_read_command (Monitor *mon,int show_prompt) {if (!mon->rs)return ;
@@ -233,8 +233,8 @@ static void monitor_read_command(Monitor *mon, int show_prompt)readline_show_prompt (mon->rs); } -static int monitor_read_password (Monitor *mon,ReadLineFunc *readline_func, -void *opaque) +int monitor_read_password (Monitor *mon,ReadLineFunc *readline_func, +void *opaque) {if (monitor_ctrl_mode (mon)) {qerror_report (QERR_MISSING_PARAMETER ,"password" );
@@ -5303,6 +5303,11 @@ static void bdrv_password_cb(Monitor *mon, const char *password, void *opaque)monitor_read_command (mon,1 ); } +ReadLineState *monitor_get_rs (Monitor *mon) +{ +return mon->rs; +} +int monitor_read_bdrv_key_start (Monitor *mon,BlockDriverState *bs,BlockDriverCompletionFunc *completion_cb,void *opaque)
monitor.h +5 -0
@@ -6,6 +6,7 @@#include "qerror.h" #include "qdict.h" #include "block.h" +#include "readline.h" extern Monitor *cur_mon;extern Monitor *default_mon;
@@ -61,5 +62,9 @@ void monitor_flush(Monitor *mon);typedef void (MonitorCompletion )(void *opaque,QObject *ret_data);void monitor_set_error (Monitor *mon,QError *qerror); +void monitor_read_command (Monitor *mon,int show_prompt); +ReadLineState *monitor_get_rs (Monitor *mon); +int monitor_read_password (Monitor *mon,ReadLineFunc *readline_func, +void *opaque);#endif /* !MONITOR_H */
Signature · 1 line
1.7.4.1
PATCH 8/15 qerror: add additional parameter to QERR_DEVICE_ENCRYPTED
In reply to Anthony LiguoriChanging an encrypted block device requires a flow of:
1) change device
2) receive error from change
3) block_passwd
DeviceEncrypted receives the device name but with a block backend with multiple backing files, any one of the backing files could be encrypted. From a UI perspective, you have no way of knowing which file is encrypted without parsing the qcow2 files :-/
Add the actual encrypted filename to the error message so that a UI can display that information to the user.
--- monitor.c | 3 ++- qerror.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
monitor.c +2 -1
@@ -5321,7 +5321,8 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, }if (monitor_ctrl_mode (mon)) { -qerror_report (QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs)); +qerror_report (QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs), +bdrv_get_encrypted_filename (bs));return -1 ; }
qerror.h +1 -1
@@ -64,7 +64,7 @@ QError *qobject_to_qerror(const QObject *obj); "{ 'class': 'CommandNotFound', 'data': { 'name': %s } }"#define QERR_DEVICE_ENCRYPTED \ - "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }" + "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s, 'filename': %s} }"#define QERR_DEVICE_INIT_FAILED \ "{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }"
Signature · 1 line
1.7.4.1
PATCH 9/15 qapi: convert eject (qmp and hmp) to QAPI
In reply to Anthony LiguoriN.B. This temporarily changes the error semantics of eject. Errors are not stable in QMP so this is not technically a breakage. The last patch restores the previous error semantics.
--- blockdev.c | 22 +++++++++++----------- blockdev.h | 1 - hmp-commands.hx | 3 +-- hmp.c | 14 ++++++++++++++ hmp.h | 1 + qapi-schema.json | 25 +++++++++++++++++++++++++ qmp-commands.hx | 3 +-- 7 files changed, 53 insertions(+), 16 deletions(-)
blockdev.c +11 -11
@@ -16,6 +16,7 @@#include "sysemu.h" #include "hw/qdev.h" #include "block_int.h" +#include "qmp-commands.h" static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
@@ -635,32 +636,31 @@ out:return ret; } -static int eject_device (Monitor *mon,BlockDriverState *bs,int force) +static int eject_device (BlockDriverState *bs,int force,Error **errp) {if (!bdrv_is_removable (bs)) { -qerror_report (QERR_DEVICE_NOT_REMOVABLE ,bdrv_get_device_name (bs)); +error_set (errp,QERR_DEVICE_NOT_REMOVABLE ,bdrv_get_device_name (bs));return -1 ; }if (!force &&bdrv_is_locked (bs)) { -qerror_report (QERR_DEVICE_LOCKED ,bdrv_get_device_name (bs)); +error_set (errp,QERR_DEVICE_LOCKED ,bdrv_get_device_name (bs));return -1 ; }bdrv_close (bs);return 0 ; } -int do_eject (Monitor *mon,const QDict *qdict,QObject **ret_data) +void qmp_eject (const char *device,bool has_force,bool force,Error **errp) {BlockDriverState *bs; -int force =qdict_get_try_bool (qdict,"force" ,0 ); -const char *filename =qdict_get_str (qdict,"device" ); - bs =bdrv_find (filename); + bs =bdrv_find (device);if (!bs) { -qerror_report (QERR_DEVICE_NOT_FOUND , filename); -return -1 ; +error_set (errp,QERR_DEVICE_NOT_FOUND , device); +return ; } -return eject_device (mon, bs, force); + +eject_device (bs, force, errp); } int do_block_set_passwd(Monitor *mon, const QDict *qdict,
@@ -706,7 +706,7 @@ int do_change_block(Monitor *mon, const char *device,return -1 ; } } -if (eject_device (mon, bs,0 ) <0 ) { +if (eject_device (bs,0 ,NULL ) <0 ) {return -1 ; } bdrv_flags =bdrv_is_read_only (bs) ?0 :BDRV_O_RDWR ;
blockdev.h +0 -1
@@ -58,7 +58,6 @@ DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi);DriveInfo *add_init_drive (const char *opts);void do_commit (Monitor *mon,const QDict *qdict); -int do_eject (Monitor *mon,const QDict *qdict,QObject **ret_data);int do_block_set_passwd (Monitor *mon,const QDict *qdict,QObject **ret_data);int do_change_block (Monitor *mon,const char *device,const char *filename,const char *fmt);
hmp-commands.hx +1 -2
@@ -76,8 +76,7 @@ ETEXI .args_type = "force:-f,device:B", .params = "[-f] device", .help = "eject a removable medium (use -f to force it)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_eject, + .mhandler.cmd = hmp_eject, }, STEXI
hmp.c +14 -0
@@ -24,3 +24,17 @@ void hmp_info_name(Monitor *mon) }qapi_free_NameInfo (info); } + +void hmp_eject (Monitor *mon,const QDict *qdict) +{ +int force =qdict_get_try_bool (qdict,"force" ,0 ); +const char *device =qdict_get_str (qdict,"device" ); +Error *err =NULL ; + +qmp_eject (device, true, force, &err); +if (err) { +monitor_printf (mon,"eject: %s\n" ,error_get_pretty (err)); +error_free (err); + } +} +
hmp.h +1 -0
@@ -18,5 +18,6 @@#include "qapi-types.h" void hmp_info_name (Monitor *mon); +void hmp_eject (Monitor *mon,const QDict *args);#endif
qapi-schema.json +25 -0
@@ -24,3 +24,28 @@ ## { 'command': 'query-name', 'returns': 'NameInfo' } +## +# @eject: +# +# Ejects a device from a removable drive. +# +# @device: The name of the device +# +# @force: @optional If true, eject regardless of whether the drive is locked. +# If not specified, the default value is false. +# +# Returns: Nothing on success +# If @device is not a valid block device, DeviceNotFound +# If @device is not removable and @force is false, DeviceNotRemovable +# If @force is false and @device is locked, DeviceLocked +# +# Notes: If the @force flag is used, the backing file will be closed +# regardless of whether the device is removable. This may result in +# a badly broken guest. +# +# Ejecting a device with no media results in success +# +# Since: 0.14.0 +## +{ 'command': 'eject', 'data': {'device': 'str', '*force': 'bool'} } +
qmp-commands.hx +1 -2
@@ -89,8 +89,7 @@ EQMP .args_type = "force:-f,device:B", .params = "[-f] device", .help = "eject a removable medium (use -f to force it)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_eject, + .mhandler.cmd_new = qmp_marshal_input_eject, }, SQMP
Signature · 1 line
1.7.4.1
PATCH 10/15 qapi: convert block_passwd and add set-blockdev-password
In reply to Anthony Liguoriblock_passwd is unfortunately named so while converting block_passwd to QAPI, introduce a more properly named alias.
--- blockdev.c | 29 +++++++++++++++-------------- hmp-commands.hx | 2 +- hmp.c | 12 ++++++++++++ hmp.h | 1 + qapi-schema.json | 47 +++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 11 +++++++++-- 6 files changed, 85 insertions(+), 17 deletions(-)
blockdev.c +15 -14
@@ -663,28 +663,29 @@ void qmp_eject(const char *device, bool has_force, bool force, Error **errp)eject_device (bs, force, errp); } -int do_block_set_passwd (Monitor *mon,const QDict *qdict, -QObject **ret_data) +void qmp_set_blockdev_password (const char *device,const char *password, +Error **err) {BlockDriverState *bs; -int err; +int ret; - bs =bdrv_find (qdict_get_str (qdict,"device" )); + bs =bdrv_find (device);if (!bs) { -qerror_report (QERR_DEVICE_NOT_FOUND ,qdict_get_str (qdict,"device" )); -return -1 ; +error_set (err,QERR_DEVICE_NOT_FOUND , device); +return ; } - err =bdrv_set_key (bs,qdict_get_str (qdict,"password" )); -if (err == -EINVAL ) { -qerror_report (QERR_DEVICE_NOT_ENCRYPTED ,bdrv_get_device_name (bs)); -return -1 ; - }else if (err <0 ) { -qerror_report (QERR_INVALID_PASSWORD ); -return -1 ; + ret =bdrv_set_key (bs, password); +if (ret == -EINVAL ) { +error_set (err,QERR_DEVICE_NOT_ENCRYPTED ,bdrv_get_device_name (bs)); + }else if (ret <0 ) { +error_set (err,QERR_INVALID_PASSWORD ); } +} -return 0 ; +void qmp_block_passwd (const char *device,const char *password,Error **err) +{ +qmp_set_blockdev_password (device, password, err); } int do_change_block(Monitor *mon, const char *device,
hmp-commands.hx +1 -1
@@ -1205,7 +1205,7 @@ ETEXI .params = "block_passwd device password", .help = "set the password of encrypted block devices", .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_set_passwd, + .mhandler.cmd = hmp_block_passwd, }, STEXI
hmp.c +12 -0
@@ -38,3 +38,15 @@ void hmp_eject(Monitor *mon, const QDict *qdict) } } +void hmp_block_passwd (Monitor *mon,const QDict *qdict) +{ +const char *device =qdict_get_str (qdict,"device" ); +const char *password =qdict_get_str (qdict,"password" ); +Error *err =NULL ; + +qmp_set_blockdev_password (device, password, &err); +if (err) { +monitor_printf (mon,"block_passwd: %s\n" ,error_get_pretty (err)); +error_free (err); + } +}
hmp.h +1 -0
@@ -19,5 +19,6 @@void hmp_info_name (Monitor *mon);void hmp_eject (Monitor *mon,const QDict *args); +void hmp_block_passwd (Monitor *mon,const QDict *qdict);#endif
qapi-schema.json +47 -0
50 lines not on this page · raw message
qmp-commands.hx +9 -2
@@ -837,8 +837,15 @@ EQMP .args_type = "device:B,password:s", .params = "block_passwd device password", .help = "set the password of encrypted block devices", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_set_passwd, + .mhandler.cmd_new = qmp_marshal_input_block_passwd, + }, + + { + .name = "set-blockdev-password", + .args_type = "device:B,password:s", + .params = "block_passwd device password", + .help = "set the password of encrypted block devices", + .mhandler.cmd_new = qmp_marshal_input_set_blockdev_password, }, SQMP
Signature · 1 line
1.7.4.1
PATCH 11/15 qapi: add change-vnc-password (v2)
In reply to Anthony LiguoriThis is a new QMP only command that only changes the VNC password.
---
v1 -> v2
- fix schema documentation
--- qapi-schema.json | 13 +++++++++++++ qmp-commands.hx | 8 ++++++++ qmp.c | 11 ++++++++++- 3 files changed, 31 insertions(+), 1 deletions(-)
qapi-schema.json +13 -0
@@ -96,3 +96,16 @@ { 'command': 'set-blockdev-password', 'data': {'device': 'str', 'password': 'str'} } +## +# @change-vnc-password: +# +# Change the VNC server password. +# +# @password: the new password to use with VNC authentication +# +# Since: 1.0 +# +# Notes: An empty password in this command will set the password to the empty +# string. Existing clients are unaffected by executing this command. +## +{ 'command': 'change-vnc-password', 'data': {'password': 'str'} }
qmp-commands.hx +8 -0
@@ -868,6 +868,14 @@ Example: EQMP { + .name = "change-vnc-password", + .args_type = "password:s", + .params = "password", + .help = "set vnc password", + .mhandler.cmd_new = qmp_marshal_input_change_vnc_password, + }, + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", .params = "protocol password action-if-connected",
qmp.c +10 -1
@@ -12,9 +12,11 @@*/ #include "qemu-common.h" -#include "sysemu.h" #include "qmp-commands.h" +#include "sysemu.h" +#include "console.h" +NameInfo *qmp_query_name (Error **errp) {NameInfo *info =g_malloc0 (sizeof (*info));
@@ -26,3 +28,10 @@ NameInfo *qmp_query_name(Error **errp)return info; } + +void qmp_change_vnc_password (const char *password,Error **err) +{ +if (vnc_display_password (NULL , password) <0 ) { +error_set (err,QERR_SET_PASSWD_FAILED ); + } +}
Signature · 1 line
1.7.4.1
PATCH 12/15 qapi: add change-vnc-listen (v2)
In reply to Anthony LiguoriNew QMP only command to change the VNC server's listening address.
---
v1 -> v2
- Enhanced docs (Luiz)
--- qapi-schema.json | 15 +++++++++++++++ qmp-commands.hx | 8 ++++++++ qmp.c | 7 +++++++ 3 files changed, 30 insertions(+), 0 deletions(-)
qapi-schema.json +15 -0
@@ -109,3 +109,18 @@ # string. Existing clients are unaffected by executing this command. ## { 'command': 'change-vnc-password', 'data': {'password': 'str'} } + +## +# @change-vnc-listen: +# +# Change the host that the VNC server listens on. +# +# @target: the new server specification to listen on +# +# Since: 1.0 +# +# Notes: At this moment in time, the behavior of existing client connections +# when this command is executed is undefined. The authentication +# settings may change after executing this command. +## +{ 'command': 'change-vnc-listen', 'data': {'target': 'str'} }
qmp-commands.hx +8 -0
@@ -876,6 +876,14 @@ EQMP }, { + .name = "change-vnc-listen", + .args_type = "target:s", + .params = "target", + .help = "set vnc listening address", + .mhandler.cmd_new = qmp_marshal_input_change_vnc_listen, + }, + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", .params = "protocol password action-if-connected",
qmp.c +7 -0
@@ -35,3 +35,10 @@ void qmp_change_vnc_password(const char *password, Error **err)error_set (err,QERR_SET_PASSWD_FAILED ); } } + +void qmp_change_vnc_listen (const char *target,Error **err) +{ +if (vnc_display_open (NULL , target) <0 ) { +error_set (err,QERR_VNC_SERVER_FAILED , target); + } +}
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH 12/15] qapi: add change-vnc-listen (v2)
Quoted 23 lines · On Fri, 2 Sep 2011 12:34:55 -0500 Anthony Liguori <[email protected]> wrote:
New QMP only command to change the VNC server's listening address.
Signed-off-by Anthony Liguori <[email protected]>---
v1 -> v2
- Enhanced docs (Luiz)--- qapi-schema.json | 15 +++++++++++++++ qmp-commands.hx | 8 ++++++++ qmp.c | 7 +++++++ 3 files changed, 30 insertions(+), 0 deletions(-)qapi-schema.json +3
-0@@ -109,3 +109,18 @@ # string. Existing clients are unaffected by executing this command. ## { 'command': 'change-vnc-password', 'data': {'password': 'str'} } + +## +# @change-vnc-listen:
qapi-schema.json line 124
Quoted 10 lines
qapi-schema.json +10
-0+# +# Change the host that the VNC server listens on. +# +# @target: the new server specification to listen on +# +# Since: 1.0 +# +# Notes: At this moment in time, the behavior of existing client connections +# when this command is executed is undefined. The authentication +# settings may change after executing this command.
It seems to completely disable authentication. At least when using password auth. I'd be very clear about that.
Quoted 36 lines
qapi-schema.json +2
-0+## +{ 'command': 'change-vnc-listen', 'data': {'target': 'str'} }qmp-commands.hx +8
-0@@ -876,6 +876,14 @@ EQMP }, { + .name = "change-vnc-listen", + .args_type = "target:s", + .params = "target", + .help = "set vnc listening address", + .mhandler.cmd_new = qmp_marshal_input_change_vnc_listen, + }, + + { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", .params = "protocol password action-if-connected",qmp.c +7
-0@@ -35,3 +35,10 @@ void qmp_change_vnc_password(const char *password, Error **err)error_set (err,QERR_SET_PASSWD_FAILED ); } } + +void qmp_change_vnc_listen (const char *target,Error **err) +{ +if (vnc_display_open (NULL , target) <0 ) { +error_set (err,QERR_VNC_SERVER_FAILED , target); + } +}
Re: [Qemu-devel] [PATCH 12/15] qapi: add change-vnc-listen (v2)
Quoted 31 lines · Luiz Capitulino
Quoted 28 lines · On Fri, 2 Sep 2011 12:34:55 -0500 Anthony Liguori <[email protected]> wrote:
New QMP only command to change the VNC server's listening address.
Signed-off-by Anthony Liguori <[email protected]>---
v1 -> v2
- Enhanced docs (Luiz)--- qapi-schema.json | 15 +++++++++++++++ qmp-commands.hx | 8 ++++++++ qmp.c | 7 +++++++ 3 files changed, 30 insertions(+), 0 deletions(-)qapi-schema.json +8
-0@@ -109,3 +109,18 @@ # string. Existing clients are unaffected by executing this command. ## { 'command': 'change-vnc-password', 'data': {'password': 'str'} } + +## +# @change-vnc-listen: +# +# Change the host that the VNC server listens on. +# +# @target: the new server specification to listen on +#
Quoted 8 lines
qapi-schema.json line 124
Quoted 5 lines
qapi-schema.json +5
-0+# Since: 1.0 +# +# Notes: At this moment in time, the behavior of existing client connections +# when this command is executed is undefined. The authentication +# settings may change after executing this command.It seems to completely disable authentication. At least when using password auth. I'd be very clear about that.
That is really bad, since even if we have another command to set the authentication mode, this creates a designed-in race condition. To be securely race-free, we need to be able to set the desired auth mode first, and then change the listen address without it affecting auth.
change-vnc-auth tls
change-vnc-listen 123.2.3.5:5901If we really want vnc-listen to have possible side-effects on auth, then we need to be able to put the VNC server in an offline mode while making a sequence of configuration changes eg, something like
change-vnc-status offline
change-vnc-listen 123.2.3.5:5901
change-vnc-auth tls
change-vnc-status onlineNo incoming client connections would be allowed while it is offline
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Re: [Qemu-devel] [PATCH 12/15] qapi: add change-vnc-listen (v2)
Quoted 41 lines · Daniel P. Berrange
Quoted 31 lines · Luiz Capitulino
Quoted 28 lines · On Fri, 2 Sep 2011 12:34:55 -0500 Anthony Liguori <[email protected]> wrote:
New QMP only command to change the VNC server's listening address.
Signed-off-by Anthony Liguori <[email protected]>---
v1 -> v2
- Enhanced docs (Luiz)--- qapi-schema.json | 15 +++++++++++++++ qmp-commands.hx | 8 ++++++++ qmp.c | 7 +++++++ 3 files changed, 30 insertions(+), 0 deletions(-)qapi-schema.json +8
-0@@ -109,3 +109,18 @@ # string. Existing clients are unaffected by executing this command. ## { 'command': 'change-vnc-password', 'data': {'password': 'str'} } + +## +# @change-vnc-listen: +# +# Change the host that the VNC server listens on. +# +# @target: the new server specification to listen on +#Quoted 8 lines
qapi-schema.json line 124
Quoted 5 lines
qapi-schema.json +5
-0+# Since: 1.0 +# +# Notes: At this moment in time, the behavior of existing client connections +# when this command is executed is undefined. The authentication +# settings may change after executing this command.It seems to completely disable authentication. At least when using password auth. I'd be very clear about that.
Quoted 7 lines
That is really bad, since even if we have another command to set the authentication mode, this creates a designed-in race condition. To be securely race-free, we need to be able to set the desired auth mode first, and then change the listen address without it affecting auth.
change-vnc-auth tls change-vnc-listen 123.2.3.5:5901
On closer inspection, I see that 'change-vnc-listen' just accepts the full string with encoded options, that is used for the '-vnc' command line. I thought that for QMP we going to make sure we didn't use any encoded strings, and gave each option a dedicated parameter ?
eg instead of:
{ 'command': 'change-vnc-password', 'data': {'target': 'str'} }
Wouldn't we want something like:
{ 'command': 'change-vnc-password', 'data': {
'listen': bool, /* Whether to listen, or do a reverse connection */
'address': 'str',
'port': 'int',
'password': 'string',
'sasl': bool,
'tls': bool,
'x509': bool,
'lossy': bool,
'no-lock-key-sync': bool,
...
}
}At which point we could also make '-vnc' use qemu-config for its option parsing ?
Or is your idea that we just do the more straightforward QMP command for change-vnc-listen now, with the view that everything will be changed for the future QEMU Object model rewrite ?
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
PATCH 13/15 qapi: introduce drive-change (v2)
In reply to Anthony LiguoriA new QMP only command to change the blockdev associated with a block device. The semantics of change right now are just plain scary. This command introduces sane semantics. For more details, see the documentation in the schema file.
---
v1 -> v2
- Rename command to drive-change (Kevin)
--- blockdev.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++--- qapi-schema.json | 30 +++++++++++++++ qmp-commands.hx | 8 ++++ 3 files changed, 140 insertions(+), 6 deletions(-)
blockdev.c +102 -6
@@ -688,12 +688,101 @@ void qmp_block_passwd(const char *device, const char *password, Error **err)qmp_set_blockdev_password (device, password, err); } +static void qmp_bdrv_open_encrypted (BlockDriverState *bs,const char *filename, +int bdrv_flags,BlockDriver *drv, +const char *password,Error **errp) +{ +if (bdrv_open (bs, filename, bdrv_flags, drv) <0 ) { +error_set (errp,QERR_OPEN_FILE_FAILED , filename); +return ; + } + +if (bdrv_key_required (bs)) { +if (password) { +if (bdrv_set_key (bs, password) <0 ) { +error_set (errp,QERR_INVALID_PASSWORD ); + } + }else { +error_set (errp,QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs), +bdrv_get_encrypted_filename (bs)); + } + }else if (password) { +error_set (errp,QERR_DEVICE_NOT_ENCRYPTED ,bdrv_get_device_name (bs)); + } +} + +void qmp_drive_change (const char *device,const char *filename, +bool has_format,const char *format, +bool has_password,const char *password, +Error **errp) +{ +BlockDriverState *bs, *bs1; +BlockDriver *drv =NULL ; +int bdrv_flags; +Error *err =NULL ; +bool probed_raw = false; + + bs =bdrv_find (device); +if (!bs) { +error_set (errp,QERR_DEVICE_NOT_FOUND , device); +return ; + } + +if (has_format) { + drv =bdrv_find_whitelisted_format (format); +if (!drv) { +error_set (errp,QERR_INVALID_BLOCK_FORMAT , format); +return ; + } + } + + bdrv_flags =bdrv_is_read_only (bs) ?0 :BDRV_O_RDWR ; + bdrv_flags |=bdrv_is_snapshot (bs) ?BDRV_O_SNAPSHOT :0 ; + +if (!has_password) { + password =NULL ; + } + +/* Try to open once with a temporary block device to make sure that +* the disk isn't encrypted and we lack a key. This also helps keep +* this operation as a transaction. That is, if we fail, we try very +* hard to make sure that the state is the same as before the operation +* was started. +*/ + bs1 =bdrv_new ("" ); +qmp_bdrv_open_encrypted (bs1, filename, bdrv_flags, drv, password, &err); +if (!has_format && bs1->drv->unsafe_probe) { + probed_raw = true; + } +bdrv_delete (bs1); + +if (err) { +error_propagate (errp, err); +return ; + } + +if (probed_raw) { +/* We will not auto probe raw files. */ +error_set (errp,QERR_MISSING_PARAMETER ,"format" ); +return ; + } + +eject_device (bs,0 , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +qmp_bdrv_open_encrypted (bs, filename, bdrv_flags, drv, password, errp); +} +int do_change_block (Monitor *mon,const char *device,const char *filename,const char *fmt) {BlockDriverState *bs;BlockDriver *drv =NULL ;int bdrv_flags; +Error *err =NULL ; bs =bdrv_find (device);if (!bs) {
@@ -707,16 +796,23 @@ int do_change_block(Monitor *mon, const char *device,return -1 ; } } -if (eject_device (bs,0 ,NULL ) <0 ) { -return -1 ; - } + bdrv_flags =bdrv_is_read_only (bs) ?0 :BDRV_O_RDWR ; bdrv_flags |=bdrv_is_snapshot (bs) ?BDRV_O_SNAPSHOT :0 ; -if (bdrv_open (bs, filename, bdrv_flags, drv) <0 ) { -qerror_report (QERR_OPEN_FILE_FAILED , filename); + +eject_device (bs,0 , &err); +if (err) { +qerror_report_err (err); +return -1 ; + } + +qmp_bdrv_open_encrypted (bs, filename, bdrv_flags, drv,NULL , &err); +if (err) { +qerror_report_err (err);return -1 ; } -return monitor_read_bdrv_key_start (mon, bs,NULL ,NULL ); + +return 0 ; }int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data)
qapi-schema.json +30 -0
@@ -124,3 +124,33 @@ # settings may change after executing this command. ## { 'command': 'change-vnc-listen', 'data': {'target': 'str'} } + +## +# @drive-change: +# +# This is the preferred interface for changing a block device. +# +# @device: The block device name. +# +# @filename: The new filename for the block device. This may contain options +# encoded in a format specified by @format. +# +# @format: #optional The format to use open the block device +# +# @password: #optional The password to use if the block device is encrypted +# +# Returns: Nothing on success. +# If @device is not a valid block device, DeviceNotFound +# If @format is not a valid block format, InvalidBlockFormat +# If @filename is encrypted and @password isn't supplied, +# DeviceEncrypted. The call should be repeated with @password +# supplied. +# If @format is not specified and @filename is a format that cannot +# be safely probed, MissingParameter. +# If @filename cannot be opened, OpenFileFailed +# +# Since: 1.0 +## +{ 'command': 'drive-change', + 'data': {'device': 'str', 'filename': 'str', '*format': 'str', + '*password': 'str'} }
qmp-commands.hx +8 -0
@@ -121,6 +121,14 @@ EQMP .mhandler.cmd_new = do_change, }, + { + .name = "drive-change", + .args_type = "device:B,filename:F,format:s?password:s?", + .params = "device filename [format] [password]", + .help = "change a removable medium, optional format", + .mhandler.cmd_new = qmp_marshal_input_drive_change, + }, + SQMP change ------
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH 13/15] qapi: introduce drive-change (v2)
Quoted 90 lines · On Fri, 2 Sep 2011 12:34:56 -0500 Anthony Liguori <[email protected]> wrote:
A new QMP only command to change the blockdev associated with a block device. The semantics of change right now are just plain scary. This command introduces sane semantics. For more details, see the documentation in the schema file.
Signed-off-by Anthony Liguori <[email protected]>---
v1 -> v2
- Rename command to drive-change (Kevin)--- blockdev.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++--- qapi-schema.json | 30 +++++++++++++++ qmp-commands.hx | 8 ++++ 3 files changed, 140 insertions(+), 6 deletions(-)blockdev.c +68
-0@@ -688,12 +688,101 @@ void qmp_block_passwd(const char *device, const char *password, Error **err)qmp_set_blockdev_password (device, password, err); } +static void qmp_bdrv_open_encrypted (BlockDriverState *bs,const char *filename, +int bdrv_flags,BlockDriver *drv, +const char *password,Error **errp) +{ +if (bdrv_open (bs, filename, bdrv_flags, drv) <0 ) { +error_set (errp,QERR_OPEN_FILE_FAILED , filename); +return ; + } + +if (bdrv_key_required (bs)) { +if (password) { +if (bdrv_set_key (bs, password) <0 ) { +error_set (errp,QERR_INVALID_PASSWORD ); + } + }else { +error_set (errp,QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs), +bdrv_get_encrypted_filename (bs)); + } + }else if (password) { +error_set (errp,QERR_DEVICE_NOT_ENCRYPTED ,bdrv_get_device_name (bs)); + } +} + +void qmp_drive_change (const char *device,const char *filename, +bool has_format,const char *format, +bool has_password,const char *password, +Error **errp) +{ +BlockDriverState *bs, *bs1; +BlockDriver *drv =NULL ; +int bdrv_flags; +Error *err =NULL ; +bool probed_raw = false; + + bs =bdrv_find (device); +if (!bs) { +error_set (errp,QERR_DEVICE_NOT_FOUND , device); +return ; + } + +if (has_format) { + drv =bdrv_find_whitelisted_format (format); +if (!drv) { +error_set (errp,QERR_INVALID_BLOCK_FORMAT , format); +return ; + } + } + + bdrv_flags =bdrv_is_read_only (bs) ?0 :BDRV_O_RDWR ; + bdrv_flags |=bdrv_is_snapshot (bs) ?BDRV_O_SNAPSHOT :0 ; + +if (!has_password) { + password =NULL ; + } + +/* Try to open once with a temporary block device to make sure that +* the disk isn't encrypted and we lack a key. This also helps keep +* this operation as a transaction. That is, if we fail, we try very +* hard to make sure that the state is the same as before the operation +* was started. +*/ + bs1 =bdrv_new ("" ); +qmp_bdrv_open_encrypted (bs1, filename, bdrv_flags, drv, password, &err); +if (!has_format && bs1->drv->unsafe_probe) { + probed_raw = true; + } +bdrv_delete (bs1); +
blockdev.c void qmp_block_passwd(const char *device, const char *password, Error **err) · line 768
Quoted 10 lines
blockdev.c +10
-0+if (err) { +error_propagate (errp, err); +return ; + } + +if (probed_raw) { +/* We will not auto probe raw files. */ +error_set (errp,QERR_MISSING_PARAMETER ,"format" ); +return ; + }
This has to be noted in the documentation.
blockdev.c void qmp_block_passwd(const char *device, const char *password, Error **err) · line 774
Quoted 6 lines
blockdev.c +6
-0+ +eject_device (bs,0 , &err); +if (err) { +error_propagate (errp, err); +return ; + }
Hm. I'm not wondering if this command isn't actually overloading two distinct operations: eject and insert. Maybe what we want here is drive-insert?
Quoted 101 lines
blockdev.c +18
-6+ +qmp_bdrv_open_encrypted (bs, filename, bdrv_flags, drv, password, errp); +} +int do_change_block (Monitor *mon,const char *device,const char *filename,const char *fmt) {BlockDriverState *bs;BlockDriver *drv =NULL ;int bdrv_flags; +Error *err =NULL ; bs =bdrv_find (device);if (!bs) {@@ -707,16 +796,23 @@ int do_change_block(Monitor *mon, const char *device,return -1 ; } } -if (eject_device (bs,0 ,NULL ) <0 ) { -return -1 ; - } + bdrv_flags =bdrv_is_read_only (bs) ?0 :BDRV_O_RDWR ; bdrv_flags |=bdrv_is_snapshot (bs) ?BDRV_O_SNAPSHOT :0 ; -if (bdrv_open (bs, filename, bdrv_flags, drv) <0 ) { -qerror_report (QERR_OPEN_FILE_FAILED , filename); + +eject_device (bs,0 , &err); +if (err) { +qerror_report_err (err); +return -1 ; + } + +qmp_bdrv_open_encrypted (bs, filename, bdrv_flags, drv,NULL , &err); +if (err) { +qerror_report_err (err);return -1 ; } -return monitor_read_bdrv_key_start (mon, bs,NULL ,NULL ); + +return 0 ; }int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data)qapi-schema.json +30
-0@@ -124,3 +124,33 @@ # settings may change after executing this command. ## { 'command': 'change-vnc-listen', 'data': {'target': 'str'} } + +## +# @drive-change: +# +# This is the preferred interface for changing a block device. +# +# @device: The block device name. +# +# @filename: The new filename for the block device. This may contain options +# encoded in a format specified by @format. +# +# @format: #optional The format to use open the block device +# +# @password: #optional The password to use if the block device is encrypted +# +# Returns: Nothing on success. +# If @device is not a valid block device, DeviceNotFound +# If @format is not a valid block format, InvalidBlockFormat +# If @filename is encrypted and @password isn't supplied, +# DeviceEncrypted. The call should be repeated with @password +# supplied. +# If @format is not specified and @filename is a format that cannot +# be safely probed, MissingParameter. +# If @filename cannot be opened, OpenFileFailed +# +# Since: 1.0 +## +{ 'command': 'drive-change', + 'data': {'device': 'str', 'filename': 'str', '*format': 'str', + '*password': 'str'} }qmp-commands.hx +8
-0@@ -121,6 +121,14 @@ EQMP .mhandler.cmd_new = do_change, }, + { + .name = "drive-change", + .args_type = "device:B,filename:F,format:s?password:s?", + .params = "device filename [format] [password]", + .help = "change a removable medium, optional format", + .mhandler.cmd_new = qmp_marshal_input_drive_change, + }, + SQMP change ------
Re: [Qemu-devel] [PATCH 13/15] qapi: introduce drive-change (v2)
Quoted 106 lines · On Fri, 2 Sep 2011 18:06:13 -0300 Luiz Capitulino <[email protected]>…
Quoted 90 lines · On Fri, 2 Sep 2011 12:34:56 -0500 Anthony Liguori <[email protected]> wrote:
A new QMP only command to change the blockdev associated with a block device. The semantics of change right now are just plain scary. This command introduces sane semantics. For more details, see the documentation in the schema file.
Signed-off-by Anthony Liguori <[email protected]>---
v1 -> v2
- Rename command to drive-change (Kevin)--- blockdev.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++--- qapi-schema.json | 30 +++++++++++++++ qmp-commands.hx | 8 ++++ 3 files changed, 140 insertions(+), 6 deletions(-)blockdev.c +68
-0@@ -688,12 +688,101 @@ void qmp_block_passwd(const char *device, const char *password, Error **err)qmp_set_blockdev_password (device, password, err); } +static void qmp_bdrv_open_encrypted (BlockDriverState *bs,const char *filename, +int bdrv_flags,BlockDriver *drv, +const char *password,Error **errp) +{ +if (bdrv_open (bs, filename, bdrv_flags, drv) <0 ) { +error_set (errp,QERR_OPEN_FILE_FAILED , filename); +return ; + } + +if (bdrv_key_required (bs)) { +if (password) { +if (bdrv_set_key (bs, password) <0 ) { +error_set (errp,QERR_INVALID_PASSWORD ); + } + }else { +error_set (errp,QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs), +bdrv_get_encrypted_filename (bs)); + } + }else if (password) { +error_set (errp,QERR_DEVICE_NOT_ENCRYPTED ,bdrv_get_device_name (bs)); + } +} + +void qmp_drive_change (const char *device,const char *filename, +bool has_format,const char *format, +bool has_password,const char *password, +Error **errp) +{ +BlockDriverState *bs, *bs1; +BlockDriver *drv =NULL ; +int bdrv_flags; +Error *err =NULL ; +bool probed_raw = false; + + bs =bdrv_find (device); +if (!bs) { +error_set (errp,QERR_DEVICE_NOT_FOUND , device); +return ; + } + +if (has_format) { + drv =bdrv_find_whitelisted_format (format); +if (!drv) { +error_set (errp,QERR_INVALID_BLOCK_FORMAT , format); +return ; + } + } + + bdrv_flags =bdrv_is_read_only (bs) ?0 :BDRV_O_RDWR ; + bdrv_flags |=bdrv_is_snapshot (bs) ?BDRV_O_SNAPSHOT :0 ; + +if (!has_password) { + password =NULL ; + } + +/* Try to open once with a temporary block device to make sure that +* the disk isn't encrypted and we lack a key. This also helps keep +* this operation as a transaction. That is, if we fail, we try very +* hard to make sure that the state is the same as before the operation +* was started. +*/ + bs1 =bdrv_new ("" ); +qmp_bdrv_open_encrypted (bs1, filename, bdrv_flags, drv, password, &err); +if (!has_format && bs1->drv->unsafe_probe) { + probed_raw = true; + } +bdrv_delete (bs1); +blockdev.c void qmp_block_passwd(const char *device, const char *password, Error **err) · line 768
Quoted 10 lines
blockdev.c +10
-0+if (err) { +error_propagate (errp, err); +return ; + } + +if (probed_raw) { +/* We will not auto probe raw files. */ +error_set (errp,QERR_MISSING_PARAMETER ,"format" ); +return ; + }This has to be noted in the documentation.
Quoted 8 lines
blockdev.c void qmp_block_passwd(const char *device, const char *password, Error **err) · line 774
Quoted 6 lines
blockdev.c +6
-0+ +eject_device (bs,0 , &err); +if (err) { +error_propagate (errp, err); +return ; + }Hm. I'm not wondering if this command isn't actually overloading two
s/not/now
Quoted 104 lines
distinct operations: eject and insert. Maybe what we want here is drive-insert?
Quoted 101 lines
blockdev.c +18
-6+ +qmp_bdrv_open_encrypted (bs, filename, bdrv_flags, drv, password, errp); +} +int do_change_block (Monitor *mon,const char *device,const char *filename,const char *fmt) {BlockDriverState *bs;BlockDriver *drv =NULL ;int bdrv_flags; +Error *err =NULL ; bs =bdrv_find (device);if (!bs) {@@ -707,16 +796,23 @@ int do_change_block(Monitor *mon, const char *device,return -1 ; } } -if (eject_device (bs,0 ,NULL ) <0 ) { -return -1 ; - } + bdrv_flags =bdrv_is_read_only (bs) ?0 :BDRV_O_RDWR ; bdrv_flags |=bdrv_is_snapshot (bs) ?BDRV_O_SNAPSHOT :0 ; -if (bdrv_open (bs, filename, bdrv_flags, drv) <0 ) { -qerror_report (QERR_OPEN_FILE_FAILED , filename); + +eject_device (bs,0 , &err); +if (err) { +qerror_report_err (err); +return -1 ; + } + +qmp_bdrv_open_encrypted (bs, filename, bdrv_flags, drv,NULL , &err); +if (err) { +qerror_report_err (err);return -1 ; } -return monitor_read_bdrv_key_start (mon, bs,NULL ,NULL ); + +return 0 ; }int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data)qapi-schema.json +30
-0@@ -124,3 +124,33 @@ # settings may change after executing this command. ## { 'command': 'change-vnc-listen', 'data': {'target': 'str'} } + +## +# @drive-change: +# +# This is the preferred interface for changing a block device. +# +# @device: The block device name. +# +# @filename: The new filename for the block device. This may contain options +# encoded in a format specified by @format. +# +# @format: #optional The format to use open the block device +# +# @password: #optional The password to use if the block device is encrypted +# +# Returns: Nothing on success. +# If @device is not a valid block device, DeviceNotFound +# If @format is not a valid block format, InvalidBlockFormat +# If @filename is encrypted and @password isn't supplied, +# DeviceEncrypted. The call should be repeated with @password +# supplied. +# If @format is not specified and @filename is a format that cannot +# be safely probed, MissingParameter. +# If @filename cannot be opened, OpenFileFailed +# +# Since: 1.0 +## +{ 'command': 'drive-change', + 'data': {'device': 'str', 'filename': 'str', '*format': 'str', + '*password': 'str'} }qmp-commands.hx +8
-0@@ -121,6 +121,14 @@ EQMP .mhandler.cmd_new = do_change, }, + { + .name = "drive-change", + .args_type = "device:B,filename:F,format:s?password:s?", + .params = "device filename [format] [password]", + .help = "change a removable medium, optional format", + .mhandler.cmd_new = qmp_marshal_input_drive_change, + }, + SQMP change ------
PATCH 14/15 qapi: convert change (v2)
In reply to Anthony LiguoriConvert the change command to QAPI and document all of its gloriousness.
---
v1 -> v2
- Fix docs (Luiz)
fix hmp change command
--- blockdev.c | 27 ++++++++---------- blockdev.h | 6 +++- hmp-commands.hx | 3 +- hmp.c | 59 ++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + monitor.c | 78 +++++++---------------------------------------------- qapi-schema.json | 38 ++++++++++++++++++++++++++ qmp-commands.hx | 3 +- 8 files changed, 127 insertions(+), 88 deletions(-)
blockdev.c +12 -15
@@ -776,8 +776,9 @@ void qmp_drive_change(const char *device, const char *filename,qmp_bdrv_open_encrypted (bs, filename, bdrv_flags, drv, password, errp); } -int do_change_block (Monitor *mon,const char *device, -const char *filename,const char *fmt) +void deprecated_qmp_change_blockdev (const char *device,const char *filename, +bool has_format,const char *format, +Error **errp) {BlockDriverState *bs;BlockDriver *drv =NULL ;
@@ -786,14 +787,14 @@ int do_change_block(Monitor *mon, const char *device, bs =bdrv_find (device);if (!bs) { -qerror_report (QERR_DEVICE_NOT_FOUND , device); -return -1 ; +error_set (errp,QERR_DEVICE_NOT_FOUND , device); +return ; } -if (fmt) { - drv =bdrv_find_whitelisted_format (fmt); +if (has_format) { + drv =bdrv_find_whitelisted_format (format);if (!drv) { -qerror_report (QERR_INVALID_BLOCK_FORMAT , fmt); -return -1 ; +error_set (errp,QERR_INVALID_BLOCK_FORMAT , format); +return ; } }
@@ -802,17 +803,13 @@ int do_change_block(Monitor *mon, const char *device,eject_device (bs,0 , &err);if (err) { -qerror_report_err (err); -return -1 ; +error_propagate (errp, err); +return ; }qmp_bdrv_open_encrypted (bs, filename, bdrv_flags, drv,NULL , &err); -if (err) { -qerror_report_err (err); -return -1 ; - } -return 0 ; +error_propagate (errp, err); }int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data)
blockdev.h +4 -2
@@ -12,6 +12,7 @@#include "block.h" #include "qemu-queue.h" +#include "error.h" void blockdev_mark_auto_del (BlockDriverState *bs);void blockdev_auto_del (BlockDriverState *bs);
@@ -59,8 +60,9 @@ DriveInfo *add_init_drive(const char *opts);void do_commit (Monitor *mon,const QDict *qdict);int do_block_set_passwd (Monitor *mon,const QDict *qdict,QObject **ret_data); -int do_change_block (Monitor *mon,const char *device, -const char *filename,const char *fmt); +void deprecated_qmp_change_blockdev (const char *device,const char *filename, +bool has_format,const char *format, +Error **errp);int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data);int do_snapshot_blkdev (Monitor *mon,const QDict *qdict,QObject **ret_data);int do_block_resize (Monitor *mon,const QDict *qdict,QObject **ret_data);
hmp-commands.hx +1 -2
@@ -108,8 +108,7 @@ ETEXI .args_type = "device:B,target:F,arg:s?", .params = "device filename [format]", .help = "change a removable medium, optional format", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_change, + .mhandler.cmd = hmp_change, }, STEXI
hmp.c +59 -0
62 lines not on this page · raw message
hmp.h +1 -0
@@ -20,5 +20,6 @@void hmp_info_name (Monitor *mon);void hmp_eject (Monitor *mon,const QDict *args);void hmp_block_passwd (Monitor *mon,const QDict *qdict); +void hmp_change (Monitor *mon,const QDict *qdict);#endif
monitor.c +11 -67
89 lines not on this page · raw message
qapi-schema.json +38 -0
@@ -84,6 +84,44 @@ 'data': {'device': 'str', 'password': 'str'} } ## +# @change: +# +# This command is multiple commands multiplexed together. Generally speaking, +# it should not be used in favor of the single purpose alternatives such as +# @change-vnc-listen, @change-vnc-password, and @change-blockdev. +# +# @device: This is normally the name of a block device but it may also be 'vnc'. +# when it's 'vnc', then sub command depends on @target +# +# @target: If @device is a block device, then this is the new filename. +# If @device is 'vnc', then if the value 'password' selects the vnc +# change password command. Otherwise, this specifies a new server URI +# address to listen to for VNC connections. +# +# @arg: If @device is a block device, then this is an optional format to open +# the device with. +# If @device is 'vnc' and @target is 'password', this is the new VNC +# password to set. If this argument is an empty string, then no future +# logins will be allowed. +# +# Returns: Nothing on success. +# If @device is not a valid block device, DeviceNotFound +# If @format is not a valid block format, InvalidBlockFormat +# If the new block device is encrypted, DeviceEncrypted. Note that +# if this error is returned, the device has been opened successfully +# and an additional call to @block_passwd is required to set the +# device's password. The behavior of reads and writes to the block +# device between when these calls are executed is undefined. +# +# Notes: It is strongly recommended that this interface is not used for +# changing block devices. +# +# Since: 0.14.0 +## +{ 'command': 'change', + 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} } + +## # @set-blockdev-password: # # Alias for @block_passwd.
qmp-commands.hx +1 -2
@@ -117,8 +117,7 @@ EQMP .args_type = "device:B,target:F,arg:s?", .params = "device filename [format]", .help = "change a removable medium, optional format", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_change, + .mhandler.cmd_new = qmp_marshal_input_change, }, {
Signature · 1 line
1.7.4.1
PATCH 15/15 vnc: don't demote authentication protocol when disabling login
In reply to Anthony LiguoriCurrently when disabling login in VNC, the password is cleared out and the authentication protocol is forced to AUTH_VNC. If you're using a stronger authentication protocol, this has the effect of downgrading your security protocol.
Fix this by only changing the authentication protocol if the current authentication protocol is AUTH_NONE. That ensures we're never downgrading.
---
v1 -> v2
- Make sure to not demote when changing password (Daniel)
--- monitor.c | 18 ------------------ qmp.c | 19 +++++++++++++++++++ ui/vnc.c | 8 ++++++-- 3 files changed, 25 insertions(+), 20 deletions(-)
monitor.c +0 -18
@@ -1007,24 +1007,6 @@ static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data)return 0 ; } -void qmp_change (const char *device,const char *target, -bool has_arg,const char *arg,Error **err) -{ -if (strcmp (device,"vnc" ) ==0 ) { -if (strcmp (target,"passwd" ) ==0 ||strcmp (target,"password" ) ==0 ) { -if (!has_arg || !arg[0 ]) { -vnc_display_disable_login (NULL ); - }else { -qmp_change_vnc_password (arg, err); - } - }else { -qmp_change_vnc_listen (target, err); - } - }else { -deprecated_qmp_change_blockdev (device, target, has_arg, arg, err); - } -} -static int set_password (Monitor *mon,const QDict *qdict,QObject **ret_data) {const char *protocol =qdict_get_str (qdict,"protocol" );
qmp.c +19 -0
@@ -16,6 +16,7 @@#include "sysemu.h" #include "console.h" +#include "blockdev.h" NameInfo *qmp_query_name (Error **errp) {
@@ -42,3 +43,21 @@ void qmp_change_vnc_listen(const char *target, Error **err)error_set (err,QERR_VNC_SERVER_FAILED , target); } } + +void qmp_change (const char *device,const char *target, +bool has_arg,const char *arg,Error **err) +{ +if (strcmp (device,"vnc" ) ==0 ) { +if (strcmp (target,"passwd" ) ==0 ||strcmp (target,"password" ) ==0 ) { +if (!has_arg || !arg[0 ]) { +vnc_display_disable_login (NULL ); + }else { +qmp_change_vnc_password (arg, err); + } + }else { +qmp_change_vnc_listen (target, err); + } + }else { +deprecated_qmp_change_blockdev (device, target, has_arg, arg, err); + } +}
ui/vnc.c +6 -2
@@ -2648,7 +2648,9 @@ int vnc_display_disable_login(DisplayState *ds) } vs->password =NULL ; - vs->auth =VNC_AUTH_VNC ; +if (vs->auth ==VNC_AUTH_NONE ) { + vs->auth =VNC_AUTH_VNC ; + }return 0 ; }
@@ -2675,7 +2677,9 @@ int vnc_display_password(DisplayState *ds, const char *password) vs->password =NULL ; } vs->password =g_strdup (password); - vs->auth =VNC_AUTH_VNC ; +if (vs->auth ==VNC_AUTH_NONE ) { + vs->auth =VNC_AUTH_VNC ; + } out:if (ret !=0 ) {qerror_report (QERR_SET_PASSWD_FAILED );
Signature · 1 line
1.7.4.1
Quoted 9 lines · Anthony Liguori
This is my attempt to jump-start the QAPI switch over. All of the hard work is already done in my qapi branch, we just need to start merging stuff.
To simplify the merge process, I've introduced a new mode to the code generator that lets us do conversions without using the new QMP server.
Once this series is merged, anything that touchs QMP (to modify a command or add a new command) must do it through QAPI--no exceptions.
Quoted 6 lines
This series also includes Dans change to the 'change' command. I'm not thrilled about people using this command but its better to err on the side of caution. It's now officially deprecated with much more robust replacement commands.
Since v1, I've tried to address all review comments. I've also tested the modified commands extensively.
Just stumbled over this while trying to build. Smells like missing Makefile dependencies (works just fine with -j1), but I figured I'd give you a heads up on this. It's a fresh checkout with nothing done but ./configure; make -j.
agraf@e77:/dev/shm/qemu> make -j
GEN i386-softmmu/config-devices.mak GEN arm-softmmu/config-devices.mak GEN x86_64-softmmu/config-devices.mak GEN cris-softmmu/config-devices.mak GEN lm32-softmmu/config-devices.mak GEN m68k-softmmu/config-devices.mak GEN microblaze-softmmu/config-devices.mak GEN microblazeel-softmmu/config-devices.mak GEN mips-softmmu/config-devices.mak GEN mipsel-softmmu/config-devices.mak GEN mips64-softmmu/config-devices.mak GEN mips64el-softmmu/config-devices.mak GEN ppcemb-softmmu/config-devices.mak GEN ppc-softmmu/config-devices.mak GEN ppc64-softmmu/config-devices.mak GEN sh4-softmmu/config-devices.mak GEN sh4eb-softmmu/config-devices.mak GEN sparc-softmmu/config-devices.mak GEN sparc64-softmmu/config-devices.mak GEN i386-linux-user/config-devices.mak GEN s390x-softmmu/config-devices.mak GEN x86_64-linux-user/config-devices.mak GEN alpha-linux-user/config-devices.mak GEN arm-linux-user/config-devices.mak GEN armeb-linux-user/config-devices.mak GEN cris-linux-user/config-devices.mak GEN m68k-linux-user/config-devices.mak GEN microblaze-linux-user/config-devices.mak GEN microblazeel-linux-user/config-devices.mak GEN mips-linux-user/config-devices.mak GEN mipsel-linux-user/config-devices.mak GEN ppc-linux-user/config-devices.mak GEN ppc64-linux-user/config-devices.mak GEN sh4-linux-user/config-devices.mak GEN ppc64abi32-linux-user/config-devices.mak GEN sh4eb-linux-user/config-devices.mak GEN sparc64-linux-user/config-devices.mak GEN sparc32plus-linux-user/config-devices.mak GEN unicore32-linux-user/config-devices.mak GEN sparc-linux-user/config-devices.mak GEN s390x-linux-user/config-devices.mak GEN config-all-devices.mak GEN config-host.h GEN trace.h GEN qemu-options.def GEN qapi-generated/qga-qapi-visit.h GEN trace.c CC trace/default.o CC trace/control.o GEN qemu-img-cmds.h
cc1: error: qapi-generated: No such file or directory
cc1: error: qapi-generated: No such file or directory
make: *** [trace/default.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [trace/control.o] Error 1
Quoted 73 lines · Alexander Graf
Quoted 9 lines · Anthony Liguori
This is my attempt to jump-start the QAPI switch over. All of the hard work is already done in my qapi branch, we just need to start merging stuff.
To simplify the merge process, I've introduced a new mode to the code generator that lets us do conversions without using the new QMP server.
Once this series is merged, anything that touchs QMP (to modify a command or add a new command) must do it through QAPI--no exceptions.
Quoted 6 lines
This series also includes Dans change to the 'change' command. I'm not thrilled about people using this command but its better to err on the side of caution. It's now officially deprecated with much more robust replacement commands.
Since v1, I've tried to address all review comments. I've also tested the modified commands extensively.
Just stumbled over this while trying to build. Smells like missing
Makefiledependencies (works just fine with -j1), but I figured I'd give you a heads up on this. It's a fresh checkout with nothing done but ./configure; make -j.agraf@e77:/dev/shm/qemu> make -j
GEN i386-softmmu/config-devices.mak GEN arm-softmmu/config-devices.mak GEN x86_64-softmmu/config-devices.mak GEN cris-softmmu/config-devices.mak GEN lm32-softmmu/config-devices.mak GEN m68k-softmmu/config-devices.mak GEN microblaze-softmmu/config-devices.mak GEN microblazeel-softmmu/config-devices.mak GEN mips-softmmu/config-devices.mak GEN mipsel-softmmu/config-devices.mak GEN mips64-softmmu/config-devices.mak GEN mips64el-softmmu/config-devices.mak GEN ppcemb-softmmu/config-devices.mak GEN ppc-softmmu/config-devices.mak GEN ppc64-softmmu/config-devices.mak GEN sh4-softmmu/config-devices.mak GEN sh4eb-softmmu/config-devices.mak GEN sparc-softmmu/config-devices.mak GEN sparc64-softmmu/config-devices.mak GEN i386-linux-user/config-devices.mak GEN s390x-softmmu/config-devices.mak GEN x86_64-linux-user/config-devices.mak GEN alpha-linux-user/config-devices.mak GEN arm-linux-user/config-devices.mak GEN armeb-linux-user/config-devices.mak GEN cris-linux-user/config-devices.mak GEN m68k-linux-user/config-devices.mak GEN microblaze-linux-user/config-devices.mak GEN microblazeel-linux-user/config-devices.mak GEN mips-linux-user/config-devices.mak GEN mipsel-linux-user/config-devices.mak GEN ppc-linux-user/config-devices.mak GEN ppc64-linux-user/config-devices.mak GEN sh4-linux-user/config-devices.mak GEN ppc64abi32-linux-user/config-devices.mak GEN sh4eb-linux-user/config-devices.mak GEN sparc64-linux-user/config-devices.mak GEN sparc32plus-linux-user/config-devices.mak GEN unicore32-linux-user/config-devices.mak GEN sparc-linux-user/config-devices.mak GEN s390x-linux-user/config-devices.mak GEN config-all-devices.mak GEN config-host.h GEN trace.h GEN qemu-options.def GEN qapi-generated/qga-qapi-visit.h GEN trace.c CC trace/default.o CC trace/control.o GEN qemu-img-cmds.h
Quoted 2 lines
cc1: error: qapi-generated: No such file or directory
cc1: error: qapi-generated: No such file or directory
I've seen this before too but this is due to guest-agent, not this patch series.
Mike, have you seen this before?
Regards,
Anthony Liguori
Quoted 6 lines
make: *** [
trace/default.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [trace/control.o] Error 1
Quoted 77 lines · Anthony Liguori
Quoted 73 lines · Alexander Graf
Quoted 9 lines · Anthony Liguori
This is my attempt to jump-start the QAPI switch over. All of the hard work is already done in my qapi branch, we just need to start merging stuff.
To simplify the merge process, I've introduced a new mode to the code generator that lets us do conversions without using the new QMP server.
Once this series is merged, anything that touchs QMP (to modify a command or add a new command) must do it through QAPI--no exceptions.
Quoted 6 lines
This series also includes Dans change to the 'change' command. I'm not thrilled about people using this command but its better to err on the side of caution. It's now officially deprecated with much more robust replacement commands.
Since v1, I've tried to address all review comments. I've also tested the modified commands extensively.
Just stumbled over this while trying to build. Smells like missing
Makefiledependencies (works just fine with -j1), but I figured I'd give you a heads up on this. It's a fresh checkout with nothing done but ./configure; make -j.agraf@e77:/dev/shm/qemu> make -j
GEN i386-softmmu/config-devices.mak GEN arm-softmmu/config-devices.mak GEN x86_64-softmmu/config-devices.mak GEN cris-softmmu/config-devices.mak GEN lm32-softmmu/config-devices.mak GEN m68k-softmmu/config-devices.mak GEN microblaze-softmmu/config-devices.mak GEN microblazeel-softmmu/config-devices.mak GEN mips-softmmu/config-devices.mak GEN mipsel-softmmu/config-devices.mak GEN mips64-softmmu/config-devices.mak GEN mips64el-softmmu/config-devices.mak GEN ppcemb-softmmu/config-devices.mak GEN ppc-softmmu/config-devices.mak GEN ppc64-softmmu/config-devices.mak GEN sh4-softmmu/config-devices.mak GEN sh4eb-softmmu/config-devices.mak GEN sparc-softmmu/config-devices.mak GEN sparc64-softmmu/config-devices.mak GEN i386-linux-user/config-devices.mak GEN s390x-softmmu/config-devices.mak GEN x86_64-linux-user/config-devices.mak GEN alpha-linux-user/config-devices.mak GEN arm-linux-user/config-devices.mak GEN armeb-linux-user/config-devices.mak GEN cris-linux-user/config-devices.mak GEN m68k-linux-user/config-devices.mak GEN microblaze-linux-user/config-devices.mak GEN microblazeel-linux-user/config-devices.mak GEN mips-linux-user/config-devices.mak GEN mipsel-linux-user/config-devices.mak GEN ppc-linux-user/config-devices.mak GEN ppc64-linux-user/config-devices.mak GEN sh4-linux-user/config-devices.mak GEN ppc64abi32-linux-user/config-devices.mak GEN sh4eb-linux-user/config-devices.mak GEN sparc64-linux-user/config-devices.mak GEN sparc32plus-linux-user/config-devices.mak GEN unicore32-linux-user/config-devices.mak GEN sparc-linux-user/config-devices.mak GEN s390x-linux-user/config-devices.mak GEN config-all-devices.mak GEN config-host.h GEN trace.h GEN qemu-options.def GEN qapi-generated/qga-qapi-visit.h GEN trace.c CC trace/default.o CC trace/control.o GEN qemu-img-cmds.hQuoted 2 lines
cc1: error: qapi-generated: No such file or directory
cc1: error: qapi-generated: No such file or directory
Quoted 1 line
I've seen this before too but this is due to guest-agent, not this patch series.
Ah, sorry, didn't track down what exactly was going wrong where and figured since it fails on qapi, it'd be related :)
Alex
Quoted 80 lines · Alexander Graf
Quoted 77 lines · Anthony Liguori
Quoted 75 lines · Alexander Graf
Quoted 9 lines · Anthony Liguori
This is my attempt to jump-start the QAPI switch over. All of the hard work is already done in my qapi branch, we just need to start merging stuff.
To simplify the merge process, I've introduced a new mode to the code generator that lets us do conversions without using the new QMP server.
Once this series is merged, anything that touchs QMP (to modify a command or add a new command) must do it through QAPI--no exceptions.
Quoted 6 lines
This series also includes Dans change to the 'change' command. I'm not thrilled about people using this command but its better to err on the side of caution. It's now officially deprecated with much more robust replacement commands.
Since v1, I've tried to address all review comments. I've also tested the modified commands extensively.
Just stumbled over this while trying to build. Smells like missing
Makefiledependencies (works just fine with -j1), but I figured I'd give you a heads up on this. It's a fresh checkout with nothing done but ./configure; make -j.agraf@e77:/dev/shm/qemu> make -j
GEN i386-softmmu/config-devices.mak GEN arm-softmmu/config-devices.mak GEN x86_64-softmmu/config-devices.mak GEN cris-softmmu/config-devices.mak GEN lm32-softmmu/config-devices.mak GEN m68k-softmmu/config-devices.mak GEN microblaze-softmmu/config-devices.mak GEN microblazeel-softmmu/config-devices.mak GEN mips-softmmu/config-devices.mak GEN mipsel-softmmu/config-devices.mak GEN mips64-softmmu/config-devices.mak GEN mips64el-softmmu/config-devices.mak GEN ppcemb-softmmu/config-devices.mak GEN ppc-softmmu/config-devices.mak GEN ppc64-softmmu/config-devices.mak GEN sh4-softmmu/config-devices.mak GEN sh4eb-softmmu/config-devices.mak GEN sparc-softmmu/config-devices.mak GEN sparc64-softmmu/config-devices.mak GEN i386-linux-user/config-devices.mak GEN s390x-softmmu/config-devices.mak GEN x86_64-linux-user/config-devices.mak GEN alpha-linux-user/config-devices.mak GEN arm-linux-user/config-devices.mak GEN armeb-linux-user/config-devices.mak GEN cris-linux-user/config-devices.mak GEN m68k-linux-user/config-devices.mak GEN microblaze-linux-user/config-devices.mak GEN microblazeel-linux-user/config-devices.mak GEN mips-linux-user/config-devices.mak GEN mipsel-linux-user/config-devices.mak GEN ppc-linux-user/config-devices.mak GEN ppc64-linux-user/config-devices.mak GEN sh4-linux-user/config-devices.mak GEN ppc64abi32-linux-user/config-devices.mak GEN sh4eb-linux-user/config-devices.mak GEN sparc64-linux-user/config-devices.mak GEN sparc32plus-linux-user/config-devices.mak GEN unicore32-linux-user/config-devices.mak GEN sparc-linux-user/config-devices.mak GEN s390x-linux-user/config-devices.mak GEN config-all-devices.mak GEN config-host.h GEN trace.h GEN qemu-options.def GEN qapi-generated/qga-qapi-visit.h GEN trace.c CC trace/default.o CC trace/control.o GEN qemu-img-cmds.hcc1: error: qapi-generated: No such file or directory
cc1: error: qapi-generated: No such file or directory
Quoted 3 lines
Quoted 1 line
I've seen this before too but this is due to guest-agent, not this patch series.
Ah, sorry, didn't track down what exactly was going wrong where and figured since it fails on qapi, it'd be related :)
I assume the root cause is that qapi-generated is being generated by make instead of by configure. Mike, care to throw together a quick patch to change that? Then there's no guess work tracking down dependencies.
Regards,
Anthony Liguori
Quoted 2 lines
Alex
Quoted 92 lines · Anthony Liguori
Quoted 91 lines · Alexander Graf
Quoted 88 lines · Anthony Liguori
Quoted 86 lines · Alexander Graf
Quoted 20 lines · Anthony Liguori
This is my attempt to jump-start the QAPI switch over. All of the hard work
is already done in my qapi branch, we just need to start merging stuff.To simplify the merge process, I've introduced a new mode to the code generator
that lets us do conversions without using the new QMP server.Once this series is merged, anything that touchs QMP (to modify a command or
add a new command) must do it through QAPI--no exceptions.This series also includes Dans change to the 'change' command. I'm not thrilled
about people using this command but its better to err on the side of caution.
It's now officially deprecated with much more robust replacement commands.Quoted 3 lines
Since v1, I've tried to address all review comments. I've also tested the
modified commands extensively.Just stumbled over this while trying to build. Smells like missing
Makefiledependencies (works just fine with -j1), but I figured I'd give you a heads up on this. It's a fresh checkout with nothing done but ./configure; make -j.agraf@e77:/dev/shm/qemu> make -j
GEN i386-softmmu/config-devices.mak
GEN arm-softmmu/config-devices.mak
GEN x86_64-softmmu/config-devices.mak
GEN cris-softmmu/config-devices.mak
GEN lm32-softmmu/config-devices.mak
GEN m68k-softmmu/config-devices.mak
GEN microblaze-softmmu/config-devices.mak
GEN microblazeel-softmmu/config-devices.mak GEN mips-softmmu/config-devices.mak
GEN mipsel-softmmu/config-devices.mak
GEN mips64-softmmu/config-devices.mak
GEN mips64el-softmmu/config-devices.mak
GEN ppcemb-softmmu/config-devices.mak
GEN ppc-softmmu/config-devices.mak
GEN ppc64-softmmu/config-devices.mak
GEN sh4-softmmu/config-devices.mak
GEN sh4eb-softmmu/config-devices.mak
GEN sparc-softmmu/config-devices.mak
GEN sparc64-softmmu/config-devices.mak
GEN i386-linux-user/config-devices.mak
GEN s390x-softmmu/config-devices.mak
GEN x86_64-linux-user/config-devices.mak
GEN alpha-linux-user/config-devices.mak
GEN arm-linux-user/config-devices.mak
GEN armeb-linux-user/config-devices.mak
GEN cris-linux-user/config-devices.mak
GEN m68k-linux-user/config-devices.mak
GEN microblaze-linux-user/config-devices.mak GEN microblazeel-linux-user/config-devices.mak GEN mips-linux-user/config-devices.mak
GEN mipsel-linux-user/config-devices.mak
GEN ppc-linux-user/config-devices.mak
GEN ppc64-linux-user/config-devices.mak
GEN sh4-linux-user/config-devices.mak
GEN ppc64abi32-linux-user/config-devices.mak GEN sh4eb-linux-user/config-devices.mak
GEN sparc64-linux-user/config-devices.mak
GEN sparc32plus-linux-user/config-devices.mak GEN unicore32-linux-user/config-devices.mak GEN sparc-linux-user/config-devices.mak
GEN s390x-linux-user/config-devices.mak
GEN config-all-devices.mak
GENconfig-host.h
GENtrace.h
GEN qemu-options.def
GENqapi-generated/qga-qapi-visit.h
GENtrace.c
CCtrace/default.o
CCtrace/control.o
GENqemu-img-cmds.h
cc1: error: qapi-generated: No such file or directory
cc1: error: qapi-generated: No such file or directory
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I've seen this before too but this is due to guest-agent, not this patch series.
Ah, sorry, didn't track down what exactly was going wrong where and figured since it fails on qapi, it'd be related :)
I assume the root cause is that qapi-generated is being generated by make instead of by configure. Mike, care to throw together a quick patch
Yah, QGA's code generators create qapi-generated/, and that code doesn't execute until a dependency on GENERATED_HEADERS is met. So it seems there was a pre-existing race to begin with, which got exacerbated by e4858974ec36afd8a6b3a9e2b0ad8f357f28efc7 which is missing some deps on GENERATED_HEADERS, so it got in more ahead of the code generation scripts than we'd seen previously.
Quoted 2 lines
to change that? Then there's no guess work tracking down dependencies.
Sure, ill send that in a few. Looks like will still get make -j build failures from that tracing patch though so I'll look at that as well.
Quoted 7 lines
Regards,
Anthony Liguori
Quoted 2 lines
Alex