From patchwork Thu Nov 5 18:17:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 540630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7D3C41402B6 for ; Fri, 6 Nov 2015 05:52:46 +1100 (AEDT) Received: from localhost ([::1]:34483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuPeO-0004h0-4s for incoming@patchwork.ozlabs.org; Thu, 05 Nov 2015 13:52:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuP7J-0001ZX-70 for qemu-devel@nongnu.org; Thu, 05 Nov 2015 13:18:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZuP7I-0005sM-Ap for qemu-devel@nongnu.org; Thu, 05 Nov 2015 13:18:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36646) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuP7G-0005r9-1Q; Thu, 05 Nov 2015 13:18:30 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 8B8198E36D; Thu, 5 Nov 2015 18:18:29 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-32.ams2.redhat.com [10.36.116.32]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tA5II7Vb025730; Thu, 5 Nov 2015 13:18:27 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 5 Nov 2015 19:17:43 +0100 Message-Id: <1446747485-6562-16-git-send-email-kwolf@redhat.com> In-Reply-To: <1446747485-6562-1-git-send-email-kwolf@redhat.com> References: <1446747485-6562-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 15/37] hmp: Add read-only-mode option to change command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Max Reitz Expose the new read-only-mode option of 'blockdev-change-medium' for the 'change' HMP command. Signed-off-by: Max Reitz Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- hmp-commands.hx | 20 +++++++++++++++++--- hmp.c | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 3a4ae39..814ea86 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -194,8 +194,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-mode:s?", + .params = "device filename [format [read-only-mode]]", .help = "change a removable medium, optional format", .mhandler.cmd = hmp_change, }, @@ -206,7 +206,7 @@ STEXI Change the configuration of a device. @table @option -@item change @var{diskdevice} @var{filename} [@var{format}] +@item change @var{diskdevice} @var{filename} [@var{format} [@var{read-only-mode}]] Change the medium for a removable disk device to point to @var{filename}. eg @example @@ -215,6 +215,20 @@ Change the medium for a removable disk device to point to @var{filename}. eg @var{format} is optional. +@var{read-only-mode} may be used to change the read-only status of the device. +It accepts the following values: + +@table @var +@item retain +Retains the current status; this is the default. + +@item read-only +Makes the device read-only. + +@item read-write +Makes the device writable. +@end 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 efa07a2..8166fd2 100644 --- a/hmp.c +++ b/hmp.c @@ -27,6 +27,7 @@ #include "qapi/opts-visitor.h" #include "qapi/qmp/qerror.h" #include "qapi/string-output-visitor.h" +#include "qapi/util.h" #include "qapi-visit.h" #include "ui/console.h" #include "block/qapi.h" @@ -1336,9 +1337,16 @@ 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-mode"); + BlockdevChangeReadOnlyMode read_only_mode = 0; Error *err = NULL; if (strcmp(device, "vnc") == 0) { + if (read_only) { + monitor_printf(mon, + "Parameter 'read-only-mode' is invalid for VNC\n"); + return; + } if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) { if (!arg) { @@ -1348,7 +1356,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);