conf: domain: Add helper to check whether a domain def requires use of PR

Extract the lookup code so that it can be reused later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Peter Krempa 2018-05-14 07:53:09 +02:00
parent b4f113ee44
commit 26c72a76dc
4 changed files with 27 additions and 21 deletions

View File

@ -29579,3 +29579,24 @@ virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard discard,
return detect_zeroes; return detect_zeroes;
} }
/**
* virDomainDefHasManagedPR:
* @def: domain definition
*
* Returns true if any of the domain disks requires the use of the managed
* persistent reservations infrastructure.
*/
bool
virDomainDefHasManagedPR(const virDomainDef *def)
{
size_t i;
for (i = 0; i < def->ndisks; i++) {
if (virStoragePRDefIsManaged(def->disks[i]->src->pr))
return true;
}
return false;
}

View File

@ -3544,4 +3544,7 @@ int
virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard discard, virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard discard,
virDomainDiskDetectZeroes detect_zeroes); virDomainDiskDetectZeroes detect_zeroes);
bool
virDomainDefHasManagedPR(const virDomainDef *def);
#endif /* __DOMAIN_CONF_H */ #endif /* __DOMAIN_CONF_H */

View File

@ -275,6 +275,7 @@ virDomainDefGetVcpus;
virDomainDefGetVcpusMax; virDomainDefGetVcpusMax;
virDomainDefGetVcpusTopology; virDomainDefGetVcpusTopology;
virDomainDefHasDeviceAddress; virDomainDefHasDeviceAddress;
virDomainDefHasManagedPR;
virDomainDefHasMemballoon; virDomainDefHasMemballoon;
virDomainDefHasMemoryHotplug; virDomainDefHasMemoryHotplug;
virDomainDefHasUSB; virDomainDefHasUSB;

View File

@ -2748,26 +2748,6 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm)
} }
static int
qemuProcessMaybeStartManagedPRDaemon(virDomainObjPtr vm)
{
bool hasManaged = false;
size_t i;
for (i = 0; i < vm->def->ndisks; i++) {
if (virStoragePRDefIsManaged(vm->def->disks[i]->src->pr)) {
hasManaged = true;
break;
}
}
if (!hasManaged)
return 0;
return qemuProcessStartManagedPRDaemon(vm);
}
static int static int
qemuProcessInitPasswords(virQEMUDriverPtr driver, qemuProcessInitPasswords(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
@ -6285,7 +6265,8 @@ qemuProcessLaunch(virConnectPtr conn,
goto cleanup; goto cleanup;
VIR_DEBUG("Setting up managed PR daemon"); VIR_DEBUG("Setting up managed PR daemon");
if (qemuProcessMaybeStartManagedPRDaemon(vm) < 0) if (virDomainDefHasManagedPR(vm->def) &&
qemuProcessStartManagedPRDaemon(vm) < 0)
goto cleanup; goto cleanup;
VIR_DEBUG("Setting domain security labels"); VIR_DEBUG("Setting domain security labels");