On Mon, 14 Mar 2011 17:31:49 +0800
Wen Congyang <wency(a)cn.fujitsu.com> wrote:
At 03/03/2011 09:12 AM, KAMEZAWA Hiroyuki Write:
>>From 8d2544bc773a2222c8aa1fdfc5cade20d8c1e958 Mon Sep 17 00:00:00 2001
> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu(a)jp.fujitsu.com>
> Date: Thu, 3 Mar 2011 09:53:08 +0900
> Subject: [PATCH 4/5] libvirt/qemu - support modification of disks in inactive
domain
>
> This patch adds support for persistent modification of disks in
> inactive domain.
>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu(a)jp.fujitsu.com>
> ---
> src/qemu/qemu_driver.c | 42 ++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 42 insertions(+), 0 deletions(-)
>
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 3248cdc..4df6bf9 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -4099,6 +4099,18 @@ cleanup:
> return ret;
> }
>
> +static int qemuDomainFindDiskByName(virDomainDefPtr vmdef, const char *name)
> +{
> + virDomainDiskDefPtr vdisk;
> + int i;
> +
> + for (i = 0; i < vmdef->ndisks; i++) {
> + vdisk = vmdef->disks[i];
> + if (STREQ(vdisk->dst, name))
> + return i;
> + }
> + return -1;
> +}
This function can be moved into src/conf/domain_conf.c, and it may be used by other
driver if this driver supports attach/detach device into inactive domain.
ok, will move.
> /*
> * Attach a device given by XML, the change will be persistent
> * and domain XML definition file is updated.
> @@ -4106,9 +4118,26 @@ cleanup:
> static int qemuDomainAttachDevicePersistent(virDomainDefPtr vmdef,
> virDomainDeviceDefPtr newdev)
> {
> + virDomainDiskDefPtr disk;
>
> /* At first, check device confliction */
> switch(newdev->type) {
> + case VIR_DOMAIN_DEVICE_DISK:
> + disk = newdev->data.disk;
> + if (qemuDomainFindDiskByName(vmdef, disk->dst) >= 0) {
> + qemuReportError(VIR_ERR_INVALID_ARG,
> + _("target %s already exists."), disk->dst);
> + return -1;
> + }
> +
> + if (virDomainDiskInsert(vmdef, disk)) /* only failed with OOM */
> + return -1;
> +
> + if (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO &&
> + qemuDomainAssignPCIAddresses(vmdef) < 0)
> + return -1;
Use virDomainDefAddImplicitControllers() to add any implied controllers
which aren't present and used by attached disk.
For ide or scsi ? ok.
> + newdev->data.disk = NULL;
> + break;
> default:
> qemuReportError(VIR_ERR_INVALID_ARG, "%s",
> _("Sorry, the device is not suppored for now"));
> @@ -4121,7 +4150,20 @@ static int qemuDomainAttachDevicePersistent(virDomainDefPtr
vmdef,
> static int qemuDomainDetachDevicePersistent(virDomainDefPtr vmdef,
> virDomainDeviceDefPtr device)
> {
> + int x;
> + virDomainDiskDefPtr disk;
> +
> switch(device->type) {
> + case VIR_DOMAIN_DEVICE_DISK:
> + disk = device->data.disk;
> + x = qemuDomainFindDiskByName(vmdef, disk->dst);
> + if (x < 0) {
> + qemuReportError(VIR_ERR_INVALID_ARG,
> + _("target %s doesn't exist."), disk->dst);
> + return -1;
> + }
> + virDomainDiskRemove(vmdef, x);
> + break;
> default:
> qemuReportError(VIR_ERR_INVALID_ARG, "%s",
> _("Sorry, the device is not suppored for now"));
Thanks,
-Kame