diff options
author | Christoph Hellwig <hch@lst.de> | 2011-01-24 13:32:33 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2011-01-31 10:03:00 +0100 |
commit | 8f12799d10cf521847ba024da22f54845f984820 (patch) | |
tree | 6be8245970b9b4b505bfc2b9cc5cb260dfd85834 /blockdev.c | |
parent | 817223efee106c6a49fcc589378c9258dc3403df (diff) | |
download | qemu-8f12799d10cf521847ba024da22f54845f984820.tar.gz qemu-8f12799d10cf521847ba024da22f54845f984820.tar.bz2 qemu-8f12799d10cf521847ba024da22f54845f984820.zip |
block: add block_resize monitor command
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>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r-- | blockdev.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/blockdev.c b/blockdev.c index f7f591fe78..e48d33dd29 100644 --- a/blockdev.c +++ b/blockdev.c @@ -705,3 +705,33 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) 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_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + const char *device = qdict_get_str(qdict, "device"); + int64_t size = qdict_get_int(qdict, "size"); + BlockDriverState *bs; + + bs = bdrv_find(device); + if (!bs) { + qerror_report(QERR_DEVICE_NOT_FOUND, device); + 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; +} |