mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
libvirt/qemu - support persistent attach/detach disks
Support changes of disks by MODIFY_CONFIG for qemu. This patch includes patches for qemu's disk to support virDomainAt(De)tachDeviceFlags with VIR_DOMAIN_DEVICE_MODIFY_CONFIG. Other devices can be added incrementally. Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> * /src/conf/domain_conf.c (virDomainDiskIndexByName): returns array index of disk in vmdef. (virDomainDiskRemoveByName): removes a disk which has the name in vmdef. * src/qemu/qemu_driver.c (qemuDomainAttachDeviceConfig): add support for Disks. (qemuDomainDetachDeviceConfig): add support for Disks.
This commit is contained in:
parent
da1eba6bc8
commit
ab9102c232
@ -5007,6 +5007,19 @@ virVirtualPortProfileFormat(virBufferPtr buf,
|
|||||||
virBufferVSprintf(buf, "%s</virtualport>\n", indent);
|
virBufferVSprintf(buf, "%s</virtualport>\n", indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int virDomainDiskIndexByName(virDomainDefPtr def, const char *name)
|
||||||
|
{
|
||||||
|
virDomainDiskDefPtr vdisk;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < def->ndisks; i++) {
|
||||||
|
vdisk = def->disks[i];
|
||||||
|
if (STREQ(vdisk->dst, name))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int virDomainDiskInsert(virDomainDefPtr def,
|
int virDomainDiskInsert(virDomainDefPtr def,
|
||||||
virDomainDiskDefPtr disk)
|
virDomainDiskDefPtr disk)
|
||||||
{
|
{
|
||||||
@ -5078,6 +5091,15 @@ void virDomainDiskRemove(virDomainDefPtr def, size_t i)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int virDomainDiskRemoveByName(virDomainDefPtr def, const char *name)
|
||||||
|
{
|
||||||
|
int i = virDomainDiskIndexByName(def, name);
|
||||||
|
if (i < 0)
|
||||||
|
return -1;
|
||||||
|
virDomainDiskRemove(def, i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int virDomainControllerInsert(virDomainDefPtr def,
|
int virDomainControllerInsert(virDomainDefPtr def,
|
||||||
virDomainControllerDefPtr controller)
|
virDomainControllerDefPtr controller)
|
||||||
|
@ -1329,6 +1329,7 @@ int virDomainVcpupinAdd(virDomainDefPtr def,
|
|||||||
int maplen,
|
int maplen,
|
||||||
int vcpu);
|
int vcpu);
|
||||||
|
|
||||||
|
int virDomainDiskIndexByName(virDomainDefPtr def, const char *name);
|
||||||
int virDomainDiskInsert(virDomainDefPtr def,
|
int virDomainDiskInsert(virDomainDefPtr def,
|
||||||
virDomainDiskDefPtr disk);
|
virDomainDiskDefPtr disk);
|
||||||
void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
|
void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
|
||||||
@ -1336,6 +1337,7 @@ void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
|
|||||||
int virDomainDiskDefAssignAddress(virCapsPtr caps, virDomainDiskDefPtr def);
|
int virDomainDiskDefAssignAddress(virCapsPtr caps, virDomainDiskDefPtr def);
|
||||||
|
|
||||||
void virDomainDiskRemove(virDomainDefPtr def, size_t i);
|
void virDomainDiskRemove(virDomainDefPtr def, size_t i);
|
||||||
|
int virDomainDiskRemoveByName(virDomainDefPtr def, const char *name);
|
||||||
|
|
||||||
int virDomainControllerInsert(virDomainDefPtr def,
|
int virDomainControllerInsert(virDomainDefPtr def,
|
||||||
virDomainControllerDefPtr controller);
|
virDomainControllerDefPtr controller);
|
||||||
|
@ -246,11 +246,13 @@ virDomainDiskDefFree;
|
|||||||
virDomainDiskDeviceTypeToString;
|
virDomainDiskDeviceTypeToString;
|
||||||
virDomainDiskErrorPolicyTypeFromString;
|
virDomainDiskErrorPolicyTypeFromString;
|
||||||
virDomainDiskErrorPolicyTypeToString;
|
virDomainDiskErrorPolicyTypeToString;
|
||||||
|
virDomainDiskIndexByName;
|
||||||
virDomainDiskInsert;
|
virDomainDiskInsert;
|
||||||
virDomainDiskInsertPreAlloced;
|
virDomainDiskInsertPreAlloced;
|
||||||
virDomainDiskIoTypeFromString;
|
virDomainDiskIoTypeFromString;
|
||||||
virDomainDiskIoTypeToString;
|
virDomainDiskIoTypeToString;
|
||||||
virDomainDiskRemove;
|
virDomainDiskRemove;
|
||||||
|
virDomainDiskRemoveByName;
|
||||||
virDomainDiskTypeFromString;
|
virDomainDiskTypeFromString;
|
||||||
virDomainDiskTypeToString;
|
virDomainDiskTypeToString;
|
||||||
virDomainFSDefFree;
|
virDomainFSDefFree;
|
||||||
|
@ -4077,10 +4077,32 @@ qemuDomainUpdateDeviceLive(virDomainObjPtr vm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef ATTRIBUTE_UNUSED,
|
qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
|
||||||
virDomainDeviceDefPtr dev)
|
virDomainDeviceDefPtr dev)
|
||||||
{
|
{
|
||||||
|
virDomainDiskDefPtr disk;
|
||||||
|
|
||||||
switch (dev->type) {
|
switch (dev->type) {
|
||||||
|
case VIR_DOMAIN_DEVICE_DISK:
|
||||||
|
disk = dev->data.disk;
|
||||||
|
if (virDomainDiskIndexByName(vmdef, disk->dst) >= 0) {
|
||||||
|
qemuReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("target %s already exists."), disk->dst);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (virDomainDiskInsert(vmdef, disk)) {
|
||||||
|
virReportOOMError();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* vmdef has the pointer. Generic codes for vmdef will do all jobs */
|
||||||
|
dev->data.disk = NULL;
|
||||||
|
if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO)
|
||||||
|
if (virDomainDefAddImplicitControllers(vmdef) < 0)
|
||||||
|
return -1;
|
||||||
|
if (qemuDomainAssignPCIAddresses(vmdef) < 0)
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("persistent attach of device is not supported"));
|
_("persistent attach of device is not supported"));
|
||||||
@ -4091,10 +4113,20 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef ATTRIBUTE_UNUSED,
|
qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
|
||||||
virDomainDeviceDefPtr dev)
|
virDomainDeviceDefPtr dev)
|
||||||
{
|
{
|
||||||
|
virDomainDiskDefPtr disk;
|
||||||
|
|
||||||
switch (dev->type) {
|
switch (dev->type) {
|
||||||
|
case VIR_DOMAIN_DEVICE_DISK:
|
||||||
|
disk = dev->data.disk;
|
||||||
|
if (virDomainDiskRemoveByName(vmdef, disk->dst)) {
|
||||||
|
qemuReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("no target device %s"), disk->dst);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("persistent detach of device is not supported"));
|
_("persistent detach of device is not supported"));
|
||||||
|
Loading…
Reference in New Issue
Block a user