[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 4/4] hmp: Add read-only option to change command
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v2 4/4] hmp: Add read-only option to change command |
Date: |
Fri, 5 Dec 2014 11:08:56 +0100 |
Expose the new read-only option of 'blockdev-change-medium' for the
'change' HMP command.
Signed-off-by: Max Reitz <address@hidden>
---
hmp-commands.hx | 20 +++++++++++++++++---
hmp.c | 21 ++++++++++++++++++++-
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index e37bc8b..70cb7d7 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -196,8 +196,8 @@ ETEXI
{
.name = "change",
- .args_type = "device:B,target:F,arg:s?",
- .params = "device filename [format]",
+ .args_type = "device:B,target:F,arg:s?,read-only:s?",
+ .params = "device filename [format [read-only]]",
.help = "change a removable medium, optional format",
.mhandler.cmd = hmp_change,
},
@@ -209,7 +209,7 @@ STEXI
Change the configuration of a device.
@table @option
address@hidden change @var{diskdevice} @var{filename} address@hidden
address@hidden change @var{diskdevice} @var{filename} address@hidden
address@hidden
Change the medium for a removable disk device to point to @var{filename}. eg
@example
@@ -218,6 +218,20 @@ Change the medium for a removable disk device to point to
@var{filename}. eg
@var{format} is optional.
address@hidden may be used to change the read-only status of the device. It
+accepts the following values:
+
address@hidden @var
address@hidden retain
+Retains the current status; this is the default.
+
address@hidden ro
+Makes the device read-only.
+
address@hidden rw
+Makes the device writable.
address@hidden table
+
@item change vnc @var{display},@var{options}
Change the configuration of the VNC server. The valid syntax for @var{display}
and @var{options} are described at @ref{sec_invocation}. eg
diff --git a/hmp.c b/hmp.c
index 840da5c..f8769b9 100644
--- a/hmp.c
+++ b/hmp.c
@@ -23,6 +23,7 @@
#include "monitor/monitor.h"
#include "qapi/opts-visitor.h"
#include "qapi/string-output-visitor.h"
+#include "qapi/util.h"
#include "qapi-visit.h"
#include "ui/console.h"
#include "block/qapi.h"
@@ -1177,9 +1178,15 @@ void hmp_change(Monitor *mon, const QDict *qdict)
const char *device = qdict_get_str(qdict, "device");
const char *target = qdict_get_str(qdict, "target");
const char *arg = qdict_get_try_str(qdict, "arg");
+ const char *read_only = qdict_get_try_str(qdict, "read-only");
+ BlockdevChangeReadOnlyMode read_only_mode = 0;
Error *err = NULL;
if (strcmp(device, "vnc") == 0) {
+ if (read_only) {
+ monitor_printf(mon, "Parameter 'read-only' is invalid for VNC");
+ return;
+ }
if (strcmp(target, "passwd") == 0 ||
strcmp(target, "password") == 0) {
if (!arg) {
@@ -1189,7 +1196,19 @@ void hmp_change(Monitor *mon, const QDict *qdict)
}
qmp_change("vnc", target, !!arg, arg, &err);
} else {
- qmp_blockdev_change_medium(device, target, !!arg, arg, false, 0, &err);
+ if (read_only) {
+ read_only_mode =
+ qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
+ read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE_MAX,
+ BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
+ if (err) {
+ hmp_handle_error(mon, &err);
+ return;
+ }
+ }
+
+ qmp_blockdev_change_medium(device, target, !!arg, arg,
+ !!read_only, read_only_mode, &err);
if (err &&
error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
error_free(err);
--
1.9.3
[Qemu-devel] [PATCH v2 4/4] hmp: Add read-only option to change command,
Max Reitz <=
Re: [Qemu-devel] [PATCH v2 0/4] blockdev: Add blockdev-change-medium with read-only option, Eric Blake, 2014/12/05
Re: [Qemu-devel] [PATCH v2 0/4] blockdev: Add blockdev-change-medium with read-only option, Markus Armbruster, 2014/12/05