From: "Daniel P. Berrange" <berrange@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] QEMU online guest disk resize wrt host block devices
Date: Fri, 2 Sep 2011 16:00:56 +0100 [thread overview]
Message-ID: <20110902150056.GG27508@redhat.com> (raw)
In-Reply-To: <20110901155543.GA11219@lst.de>
On Thu, Sep 01, 2011 at 05:55:43PM +0200, Christoph Hellwig wrote:
> Please try the attached (untested) patch:
Yes, this patch worked succesfully with the following test case:
$ dd if=/dev/zero of=loop.img bs=1M seek=100 count=0
$ losetup -f loop.img
$ ./x86_64-softmmu/qemu-system-x86_64 -hda /dev/loop0 -monitor stdio
(qemu) info block
ide0-hd0: removable=0 file=/dev/loop0 sectors=204800 ro=0 drv=raw encrypted=0
ide1-cd0: removable=1 locked=0 [not inserted]
floppy0: removable=1 locked=0 [not inserted]
sd0: removable=1 locked=0 [not inserted]
$ dd if=/dev/zero of=loop.img bs=1M seek=200 count=0
$ losetup -c /dev/loop0
(qemu) block_resize ide0-hd0 200
(qemu) info block
ide0-hd0: removable=0 file=/dev/loop0 sectors=409600 ro=0 drv=raw encrypted=0
ide1-cd0: removable=1 locked=0 [not inserted]
floppy0: removable=1 locked=0 [not inserted]
sd0: removable=1 locked=0 [not inserted]
Regards,
Daniel
> Index: qemu/block/raw-posix.c
> ===================================================================
> --- qemu.orig/block/raw-posix.c 2011-09-01 17:37:42.579651525 +0200
> +++ qemu/block/raw-posix.c 2011-09-01 17:43:28.882967337 +0200
> @@ -645,10 +645,23 @@ static void raw_close(BlockDriverState *
> static int raw_truncate(BlockDriverState *bs, int64_t offset)
> {
> BDRVRawState *s = bs->opaque;
> - if (s->type != FTYPE_FILE)
> - return -ENOTSUP;
> - if (ftruncate(s->fd, offset) < 0)
> + struct stat st;
> +
> + if (fstat(s->fd, &st))
> return -errno;
> +
> + if (S_ISREG(st.st_mode)) {
> + if (ftruncate(s->fd, offset) < 0)
> + return -errno;
> + } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
> + if (offset > raw_getlength(bs)) {
> + return -EINVAL;
> + }
> + return 0;
> +
> + } else {
> + return -ENOTSUP;
> + }
> return 0;
> }
>
> @@ -1167,6 +1180,7 @@ static BlockDriver bdrv_host_device = {
>
> .bdrv_read = raw_read,
> .bdrv_write = raw_write,
> + .bdrv_truncate = raw_truncate,
> .bdrv_getlength = raw_getlength,
> .bdrv_get_allocated_file_size
> = raw_get_allocated_file_size,
> @@ -1288,6 +1302,7 @@ static BlockDriver bdrv_host_floppy = {
>
> .bdrv_read = raw_read,
> .bdrv_write = raw_write,
> + .bdrv_truncate = raw_truncate,
> .bdrv_getlength = raw_getlength,
> .bdrv_get_allocated_file_size
> = raw_get_allocated_file_size,
> @@ -1389,6 +1404,7 @@ static BlockDriver bdrv_host_cdrom = {
>
> .bdrv_read = raw_read,
> .bdrv_write = raw_write,
> + .bdrv_truncate = raw_truncate,
> .bdrv_getlength = raw_getlength,
> .bdrv_get_allocated_file_size
> = raw_get_allocated_file_size,
> @@ -1510,6 +1526,7 @@ static BlockDriver bdrv_host_cdrom = {
>
> .bdrv_read = raw_read,
> .bdrv_write = raw_write,
> + .bdrv_truncate = raw_truncate,
> .bdrv_getlength = raw_getlength,
> .bdrv_get_allocated_file_size
> = raw_get_allocated_file_size,
next prev parent reply other threads:[~2011-09-02 15:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-01 13:27 [Qemu-devel] QEMU online guest disk resize wrt host block devices Daniel P. Berrange
2011-09-01 14:05 ` Christoph Hellwig
2011-09-01 14:30 ` Daniel P. Berrange
2011-09-01 15:55 ` Christoph Hellwig
2011-09-02 15:00 ` Daniel P. Berrange [this message]
2011-09-07 11:02 ` [Qemu-devel] [PATCH] block: allow resizing of images residing on host devices Christoph Hellwig
2011-09-09 9:37 ` Kevin Wolf
2011-09-01 14:27 ` [Qemu-devel] QEMU online guest disk resize wrt host block devices Daniel P. Berrange
2011-09-01 15:56 ` Christoph Hellwig
2011-09-05 13:03 ` Kevin Wolf
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=20110902150056.GG27508@redhat.com \
--to=berrange@redhat.com \
--cc=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.