From patchwork Wed Jan 19 17:02:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 79496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 68AFEB708B for ; Thu, 20 Jan 2011 04:08:05 +1100 (EST) Received: from localhost ([127.0.0.1]:38715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PfbVf-0000G9-4E for incoming@patchwork.ozlabs.org; Wed, 19 Jan 2011 12:07:51 -0500 Received: from [140.186.70.92] (port=45788 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PfbQr-0006E6-A6 for qemu-devel@nongnu.org; Wed, 19 Jan 2011 12:02:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PfbQn-0000j7-Uq for qemu-devel@nongnu.org; Wed, 19 Jan 2011 12:02:53 -0500 Received: from verein.lst.de ([213.95.11.210]:41109) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PfbQn-0000ir-M4 for qemu-devel@nongnu.org; Wed, 19 Jan 2011 12:02:49 -0500 Received: from verein.lst.de (localhost [127.0.0.1]) by verein.lst.de (8.12.3/8.12.3/Debian-7.1) with ESMTP id p0JH2mE5009830 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Wed, 19 Jan 2011 18:02:48 +0100 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-7.2) id p0JH2m4A009829 for qemu-devel@nongnu.org; Wed, 19 Jan 2011 18:02:48 +0100 Date: Wed, 19 Jan 2011 18:02:48 +0100 From: Christoph Hellwig To: qemu-devel@nongnu.org Message-ID: <20110119170248.GA9819@lst.de> References: <20110119170238.GA9615@lst.de> Mime-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110119170238.GA9615@lst.de> User-Agent: Mutt/1.3.28i X-Scanned-By: MIMEDefang 2.39 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 1/3] block: add resize monitor command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add a monitor command that allows resizing of block devices while qemu is running. It uses the existing bdrv_truncate method already used by qemu-img to do it's work. Compared to qemu-img the size parsing is very simplicistic, but I think having a properly numering object is more useful for non-humand monitor users than having the units and relative resize parsing. For SCSI devices the new size can be updated in Linux guests by doing the following shell command: echo > /sys/class/scsi_device/0:0:0:0/device/rescan For ATA devices I don't know of a way to update the block device size in Linux system, and for virtio-blk the next two patches will provide an automatic update of the size when this command is issued on the host. Signed-off-by: Christoph Hellwig Index: qemu/hmp-commands.hx =================================================================== --- qemu.orig/hmp-commands.hx 2011-01-19 17:47:10.444004409 +0100 +++ qemu/hmp-commands.hx 2011-01-19 17:49:51.673254095 +0100 @@ -53,6 +53,25 @@ Quit the emulator. ETEXI { + .name = "resize", + .args_type = "id:s,size:o", + .params = "device size", + .help = "resize a block image", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_resize, + }, + +STEXI +@item resize +@findex resize +Resize a block image while a guest is running. Usually requires guest +action to see the updated size. Resize to a lower size is supported, +but should be used with extreme caution. Note that this command only +resizes image files, it can not resize block devices like LVM volumes. +ETEXI + + + { .name = "eject", .args_type = "force:-f,device:B", .params = "[-f] device", Index: qemu/blockdev.c =================================================================== --- qemu.orig/blockdev.c 2011-01-19 17:47:10.455004828 +0100 +++ qemu/blockdev.c 2011-01-19 17:49:51.674253955 +0100 @@ -706,3 +706,33 @@ int do_drive_del(Monitor *mon, const QDi return 0; } + +/* + * XXX: replace the QERR_UNDEFINED_ERROR errors with real values once the + * existing QERR_ macro mess is cleaned up. A good example for better + * error reports can be found in the qemu-img resize code. + */ +int do_resize(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + const char *id = qdict_get_str(qdict, "id"); + int64_t size = qdict_get_int(qdict, "size"); + BlockDriverState *bs; + + bs = bdrv_find(id); + if (!bs) { + qerror_report(QERR_DEVICE_NOT_FOUND, id); + return -1; + } + + if (size < 0) { + qerror_report(QERR_UNDEFINED_ERROR); + return -1; + } + + if (bdrv_truncate(bs, size)) { + qerror_report(QERR_UNDEFINED_ERROR); + return -1; + } + + return 0; +} Index: qemu/blockdev.h =================================================================== --- qemu.orig/blockdev.h 2011-01-19 17:47:10.464012091 +0100 +++ qemu/blockdev.h 2011-01-19 17:49:51.677282590 +0100 @@ -53,5 +53,6 @@ int do_change_block(Monitor *mon, const const char *filename, const char *fmt); 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_resize(Monitor *mon, const QDict *qdict, QObject **ret_data); #endif Index: qemu/qmp-commands.hx =================================================================== --- qemu.orig/qmp-commands.hx 2011-01-19 17:47:10.478012371 +0100 +++ qemu/qmp-commands.hx 2011-01-19 17:50:07.406016841 +0100 @@ -601,6 +601,34 @@ Example: -> { "execute": "netdev_del", "arguments": { "id": "netdev1" } } <- { "return": {} } + +EQMP + + { + .name = "block_resize", + .args_type = "id:s,size:o", + .params = "id size", + .help = "resize a block image", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_resize, + }, + +SQMP +block_resize +------------ + +Resize a block image while a guest is running. + +Arguments: + +- "id": the device's ID, must be unique (json-string) +- "size": new size + +Example: + +-> { "execute": "block_resize", "arguments": { "id": "scratch", "size": 1073741824 } } +<- { "return": {} } + EQMP {