From patchwork Thu Nov 20 12:44:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 412696 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 65C02140170 for ; Thu, 20 Nov 2014 23:48:09 +1100 (AEDT) Received: from localhost ([::1]:35022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrR9b-0001T5-Ea for incoming@patchwork.ozlabs.org; Thu, 20 Nov 2014 07:48:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrR6l-0006T2-77 for qemu-devel@nongnu.org; Thu, 20 Nov 2014 07:45:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XrR6Z-0005bY-33 for qemu-devel@nongnu.org; Thu, 20 Nov 2014 07:45:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrR6Y-0005bC-Sb for qemu-devel@nongnu.org; Thu, 20 Nov 2014 07:44:59 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAKCisYs026785 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 20 Nov 2014 07:44:54 -0500 Received: from localhost (dhcp-192-247.str.redhat.com [10.33.192.247]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sAKCirVA016172 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Thu, 20 Nov 2014 07:44:54 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Thu, 20 Nov 2014 13:44:47 +0100 Message-Id: <1416487488-8423-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1416487488-8423-1-git-send-email-mreitz@redhat.com> References: <1416487488-8423-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Peter Lieven , Markus Armbruster , Luiz Capitulino , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH 2/3] qmp: Expose read-only option for 'change' 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 Expose the new read-only option of qmp_change_blockdev() for the 'change' QMP command. Leave it unset for HMP for now. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- hmp.c | 2 +- qapi-schema.json | 7 ++++++- qmp-commands.hx | 24 +++++++++++++++++++++++- qmp.c | 15 ++++++++++++--- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/hmp.c b/hmp.c index 94b27df..0719fa3 100644 --- a/hmp.c +++ b/hmp.c @@ -1133,7 +1133,7 @@ void hmp_change(Monitor *mon, const QDict *qdict) } } - qmp_change(device, target, !!arg, arg, &err); + qmp_change(device, target, !!arg, arg, false, 0, &err); if (err && error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) { error_free(err); diff --git a/qapi-schema.json b/qapi-schema.json index 441e001..80aaa63 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1581,6 +1581,10 @@ # password to set. If this argument is an empty string, then no future # logins will be allowed. # +# @read-only: #optional, only valid for block devices. This option allows +# changing the read-only mode of the block device; defaults to +# 'retain'. (Since 2.3) +# # Returns: Nothing on success. # If @device is not a valid block device, DeviceNotFound # If the new block device is encrypted, DeviceEncrypted. Note that @@ -1595,7 +1599,8 @@ # Since: 0.14.0 ## { 'command': 'change', - 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} } + 'data': {'device': 'str', 'target': 'str', '*arg': 'str', + '*read-only': 'BlockdevChangeReadOnlyMode'} } ## # @ObjectTypeInfo: diff --git a/qmp-commands.hx b/qmp-commands.hx index 6ef1b28..edc1783 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -109,7 +109,7 @@ EQMP { .name = "change", - .args_type = "device:B,target:F,arg:s?", + .args_type = "device:B,target:F,arg:s?,read-only:s?", .mhandler.cmd_new = qmp_marshal_input_change, }, @@ -124,6 +124,8 @@ Arguments: - "device": device name (json-string) - "target": filename or item (json-string) - "arg": additional argument (json-string, optional) +- "read-only": new read-only mode (json-string, optional) + - Possible values: "retain" (default), "ro", "rw", "auto" Examples: @@ -141,6 +143,26 @@ Examples: "arg": "foobar1" } } <- { "return": {} } +3. Load a read-only medium into a writable drive + +-> { "execute": "change", + "arguments": { "device": "isa-fd0", + "target": "/srv/images/ro.img", + "arg": "raw", + "read-only": "retain" } } + +<- { "error": + { "class": "GenericError", + "desc": "Could not open '/srv/images/ro.img': Permission denied" } } + +-> { "execute": "change", + "arguments": { "device": "isa-fd0", + "target": "/srv/images/ro.img", + "arg": "raw", + "read-only": "auto" } } + +<- { "return": {} } + EQMP { diff --git a/qmp.c b/qmp.c index bd63cf4..d12035b 100644 --- a/qmp.c +++ b/qmp.c @@ -397,13 +397,22 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, #endif /* !CONFIG_VNC */ void qmp_change(const char *device, const char *target, - bool has_arg, const char *arg, Error **errp) + bool has_arg, const char *arg, + bool has_read_only, BlockdevChangeReadOnlyMode read_only, + Error **errp) { + if (!has_read_only) { + read_only = BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN; + } + if (strcmp(device, "vnc") == 0) { + if (has_read_only) { + error_setg(errp, "Parameter 'read-only' is invalid for VNC"); + return; + } qmp_change_vnc(target, has_arg, arg, errp); } else { - qmp_change_blockdev(device, target, arg, - BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, errp); + qmp_change_blockdev(device, target, arg, read_only, errp); } }