mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
qemu: support to drop disk with 'optional' startupPolicy
Go through disks of guest, if one disk doesn't exist or its backing chain is broken, with 'optional' startupPolicy, for CDROM and Floppy we only discard its source path definition in xml, for disks we drop it from disk list and free it.
This commit is contained in:
parent
93319da42c
commit
8a160f11af
@ -4727,6 +4727,7 @@ typedef void (*virConnectDomainEventBlockJobCallback)(virConnectPtr conn,
|
|||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START = 0, /* oldSrcPath is set */
|
VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START = 0, /* oldSrcPath is set */
|
||||||
|
VIR_DOMAIN_EVENT_DISK_DROP_MISSING_ON_START = 1,
|
||||||
|
|
||||||
#ifdef VIR_ENUM_SENTINELS
|
#ifdef VIR_ENUM_SENTINELS
|
||||||
VIR_DOMAIN_EVENT_DISK_CHANGE_LAST
|
VIR_DOMAIN_EVENT_DISK_CHANGE_LAST
|
||||||
|
@ -2067,6 +2067,47 @@ cleanup:
|
|||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuDomainCheckRemoveOptionalDisk(virQEMUDriverPtr driver,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
virDomainDiskDefPtr disk)
|
||||||
|
{
|
||||||
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
|
virDomainEventPtr event = NULL;
|
||||||
|
virDomainDiskDefPtr del_disk = NULL;
|
||||||
|
|
||||||
|
virUUIDFormat(vm->def->uuid, uuid);
|
||||||
|
|
||||||
|
VIR_DEBUG("Dropping disk '%s' on domain '%s' (UUID '%s') "
|
||||||
|
"due to inaccessible source '%s'",
|
||||||
|
disk->dst, vm->def->name, uuid, disk->src);
|
||||||
|
|
||||||
|
if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM ||
|
||||||
|
disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
|
||||||
|
|
||||||
|
event = virDomainEventDiskChangeNewFromObj(vm, disk->src, NULL,
|
||||||
|
disk->info.alias,
|
||||||
|
VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START);
|
||||||
|
VIR_FREE(disk->src);
|
||||||
|
} else {
|
||||||
|
event = virDomainEventDiskChangeNewFromObj(vm, disk->src, NULL,
|
||||||
|
disk->info.alias,
|
||||||
|
VIR_DOMAIN_EVENT_DISK_DROP_MISSING_ON_START);
|
||||||
|
|
||||||
|
if (!(del_disk = virDomainDiskRemoveByName(vm->def, disk->src))) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("no source device %s"), disk->src);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
virDomainDiskDefFree(del_disk);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event)
|
||||||
|
qemuDomainEventQueue(driver, event);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
|
qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
@ -2074,7 +2115,6 @@ qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
|
|||||||
bool cold_boot)
|
bool cold_boot)
|
||||||
{
|
{
|
||||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
virDomainEventPtr event = NULL;
|
|
||||||
int startupPolicy = disk->startupPolicy;
|
int startupPolicy = disk->startupPolicy;
|
||||||
|
|
||||||
virUUIDFormat(vm->def->uuid, uuid);
|
virUUIDFormat(vm->def->uuid, uuid);
|
||||||
@ -2097,17 +2137,8 @@ qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
virResetLastError();
|
if (qemuDomainCheckRemoveOptionalDisk(driver, vm, disk) < 0)
|
||||||
VIR_DEBUG("Dropping disk '%s' on domain '%s' (UUID '%s') "
|
goto error;
|
||||||
"due to inaccessible source '%s'",
|
|
||||||
disk->dst, vm->def->name, uuid, disk->src);
|
|
||||||
|
|
||||||
event = virDomainEventDiskChangeNewFromObj(vm, disk->src, NULL, disk->info.alias,
|
|
||||||
VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START);
|
|
||||||
if (event)
|
|
||||||
qemuDomainEventQueue(driver, event);
|
|
||||||
|
|
||||||
VIR_FREE(disk->src);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -2125,8 +2156,8 @@ qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
|
|||||||
virDomainDiskDefPtr disk;
|
virDomainDiskDefPtr disk;
|
||||||
|
|
||||||
VIR_DEBUG("Checking for disk presence");
|
VIR_DEBUG("Checking for disk presence");
|
||||||
for (i = 0; i < vm->def->ndisks; i++) {
|
for (i = vm->def->ndisks; i > 0; i--) {
|
||||||
disk = vm->def->disks[i];
|
disk = vm->def->disks[i - 1];
|
||||||
|
|
||||||
if (!disk->src)
|
if (!disk->src)
|
||||||
continue;
|
continue;
|
||||||
@ -2135,10 +2166,11 @@ qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
|
|||||||
qemuDiskChainCheckBroken(disk) >= 0)
|
qemuDiskChainCheckBroken(disk) >= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (disk->startupPolicy) {
|
if (disk->startupPolicy &&
|
||||||
if (qemuDomainCheckDiskStartupPolicy(driver, vm, disk,
|
qemuDomainCheckDiskStartupPolicy(driver, vm, disk,
|
||||||
cold_boot) >= 0)
|
cold_boot) >= 0) {
|
||||||
continue;
|
virResetLastError();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
goto error;
|
goto error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user