All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/3] block: add block_resize monitor command
Date: Tue, 25 Jan 2011 13:01:04 +0100	[thread overview]
Message-ID: <4D3EBB80.1000107@redhat.com> (raw)
In-Reply-To: <20110124174416.GA6178@amt.cnet>

Am 24.01.2011 18:44, schrieb Marcelo Tosatti:
> On Mon, Jan 24, 2011 at 01:32:33PM +0100, Christoph Hellwig wrote:
>> 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-24 11:55:36.744254374 +0100
>> +++ qemu/hmp-commands.hx	2011-01-24 11:56:23.619254094 +0100
>> @@ -53,6 +53,25 @@ Quit the emulator.
>>  ETEXI
>>  
>>      {
>> +        .name       = "block_resize",
>> +        .args_type  = "device:B,size:o",
>> +        .params     = "device size",
>> +        .help       = "resize a block image",
>> +        .user_print = monitor_user_noop,
>> +        .mhandler.cmd_new = do_block_resize,
>> +    },
>> +
>> +STEXI
>> +@item block_resize
>> +@findex block_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-24 11:56:20.903004129 +0100
>> +++ qemu/blockdev.c	2011-01-24 11:56:38.391254165 +0100
>> @@ -705,3 +705,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_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;
>> +    }
> 
> Can't resize if block migration is in progress. Don't see a problem 
> with simply disallowing resize in that case.

Then we should add a check to bdrv_truncate.

Kevin

  reply	other threads:[~2011-01-25 11:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-24 12:32 [Qemu-devel] [PATCH 0/3 v3] allow online resizing of block devices Christoph Hellwig
2011-01-24 12:32 ` [Qemu-devel] [PATCH 1/3] block: add block_resize monitor command Christoph Hellwig
2011-01-24 17:44   ` Marcelo Tosatti
2011-01-25 12:01     ` Kevin Wolf [this message]
2011-01-25 18:05       ` Christoph Hellwig
2011-01-26 11:56         ` Marcelo Tosatti
2011-01-24 12:32 ` [Qemu-devel] [PATCH 2/3] block: tell drivers about an image resize Christoph Hellwig
2011-01-24 12:32 ` [Qemu-devel] [PATCH 3/3] virtio-blk: tell the guest about size changes Christoph Hellwig
2011-01-26 10:32 ` [Qemu-devel] [PATCH 0/3 v3] allow online resizing of block devices Kevin Wolf
2011-01-26 10:49 ` Stefan Hajnoczi

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=4D3EBB80.1000107@redhat.com \
    --to=kwolf@redhat.com \
    --cc=hch@lst.de \
    --cc=mtosatti@redhat.com \
    --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.