From: Christoph Hellwig <hch@lst.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/3] block: add resize monitor command
Date: Fri, 14 Jan 2011 17:20:57 +0100 [thread overview]
Message-ID: <20110114162057.GA19184@lst.de> (raw)
In-Reply-To: <20110114162044.GA19114@lst.de>
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 <hch@lst.de>
Index: qemu/hmp-commands.hx
===================================================================
--- qemu.orig/hmp-commands.hx 2011-01-14 15:11:48.527004132 +0100
+++ qemu/hmp-commands.hx 2011-01-14 15:40:14.407006506 +0100
@@ -53,6 +53,24 @@ Quit the emulator.
ETEXI
{
+ .name = "resize",
+ .args_type = "id:s,size:l",
+ .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. Usuaully requires guest
+action to see the updated size. Resize to a lower size is supported,
+but should be used with extreme caution.
+ETEXI
+
+
+ {
.name = "eject",
.args_type = "force:-f,device:B",
.params = "[-f] device",
Index: qemu/blockdev.c
===================================================================
--- qemu.orig/blockdev.c 2011-01-14 15:11:48.539261151 +0100
+++ qemu/blockdev.c 2011-01-14 15:50:35.604293558 +0100
@@ -700,3 +700,41 @@ int do_drive_del(Monitor *mon, const QDi
return 0;
}
+
+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 (bdrv_get_type_hint(bs) == BDRV_TYPE_CDROM) {
+ error_report("Can not resize CDROM devices\n");
+ return -1;
+ }
+
+ if (size < 0) {
+ error_report("Can only resize to positive sizes");
+ return -1;
+ }
+
+ switch (bdrv_truncate(bs, size)) {
+ case 0:
+ return 0;
+ case -ENOTSUP:
+ error_report("This image format does not support resize");
+ return -1;
+ case -EACCES:
+ error_report("Image is read-only");
+ return -1;
+ default:
+ error_report("Error resizing image");
+ return -1;
+ }
+}
+
Index: qemu/blockdev.h
===================================================================
--- qemu.orig/blockdev.h 2011-01-14 15:11:48.548263456 +0100
+++ qemu/blockdev.h 2011-01-14 15:12:00.965047363 +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
next prev parent reply other threads:[~2011-01-14 16:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-14 16:20 [Qemu-devel] [PATCH 0/3] allow online resizing of block devices Christoph Hellwig
2011-01-14 16:20 ` Christoph Hellwig [this message]
2011-01-17 11:28 ` [Qemu-devel] [PATCH 1/3] block: add resize monitor command Stefan Hajnoczi
2011-01-17 15:59 ` Christoph Hellwig
2011-01-17 17:36 ` Kevin Wolf
2011-01-18 12:28 ` Christoph Hellwig
2011-01-19 15:35 ` Christoph Hellwig
2011-01-19 15:49 ` Kevin Wolf
2011-01-19 15:52 ` Christoph Hellwig
2011-01-19 16:01 ` Kevin Wolf
2011-01-19 16:31 ` Christoph Hellwig
2011-01-14 16:21 ` [Qemu-devel] [PATCH 2/3] block: tell drivers about an image resize Christoph Hellwig
2011-01-14 21:06 ` Ryan Harper
2011-01-17 9:14 ` Christoph Hellwig
2011-01-14 16:21 ` [Qemu-devel] [PATCH 3/3] virtio-blk: tell the guest about size changes Christoph Hellwig
2011-01-18 12:35 ` [Qemu-devel] [PATCH 0/3] allow online resizing of block devices Luiz Capitulino
2011-01-18 12:48 ` Christoph Hellwig
2011-01-18 13:17 ` Luiz Capitulino
-- strict thread matches above, loose matches on Subject: below --
2011-01-19 17:02 [Qemu-devel] [PATCH 0/3 v2] " Christoph Hellwig
2011-01-19 17:02 ` [Qemu-devel] [PATCH 1/3] block: add resize monitor command Christoph Hellwig
2011-01-20 8:56 ` Stefan Hajnoczi
2011-01-20 9:43 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110114162057.GA19184@lst.de \
--to=hch@lst.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).