mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 01:18:00 +03:00
qemu: migration: Extract validation of disk target list
The migration code is checking the disk list provided via VIR_MIGRATE_PARAM_MIGRATE_DISKS against existing disks. Extract it to a helper function as we'll be passing another list of disk targets soon. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
4ebf1acb83
commit
aaefaabf5a
@ -2576,6 +2576,37 @@ qemuMigrationSrcBeginXML(virDomainObj *vm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qemuMigrationSrcBeginPhaseValidateDiskTargetList:
|
||||||
|
* @vm: domain object
|
||||||
|
* @disks: NULL-terminated list of disk 'dst' strings to validate
|
||||||
|
*
|
||||||
|
* Validates that all members of the @disk list are valid disk targets.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
qemuMigrationSrcBeginPhaseValidateDiskTargetList(virDomainObj *vm,
|
||||||
|
const char **disks)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
const char **d;
|
||||||
|
|
||||||
|
for (d = disks; *d; d++) {
|
||||||
|
for (i = 0; i < vm->def->ndisks; i++) {
|
||||||
|
if (STREQ(vm->def->disks[i]->dst, *d))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == vm->def->ndisks) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("disk target %1$s not found"), *d);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* The caller is supposed to lock the vm and start a migration job. */
|
/* The caller is supposed to lock the vm and start a migration job. */
|
||||||
static char *
|
static char *
|
||||||
qemuMigrationSrcBeginPhase(virQEMUDriver *driver,
|
qemuMigrationSrcBeginPhase(virQEMUDriver *driver,
|
||||||
@ -2660,24 +2691,9 @@ qemuMigrationSrcBeginPhase(virQEMUDriver *driver,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (migrate_disks) {
|
if (migrate_disks &&
|
||||||
size_t j;
|
qemuMigrationSrcBeginPhaseValidateDiskTargetList(vm, migrate_disks) < 0)
|
||||||
const char **d;
|
return NULL;
|
||||||
|
|
||||||
/* Check user requested only known disk targets. */
|
|
||||||
for (d = migrate_disks; *d; d++) {
|
|
||||||
for (j = 0; j < vm->def->ndisks; j++) {
|
|
||||||
if (STREQ(vm->def->disks[j]->dst, *d))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (j == vm->def->ndisks) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("disk target %1$s not found"), *d);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->nbdPort = 0;
|
priv->nbdPort = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user