Skip to content

Commit 4302c3e

Browse files
committed
ch: Add domain validation function for vcpu info
Once hotplug support is available we need to be able to validate the information read from the system matches our expectations. In this case, we check that thread ids for cpus exist if and only if a cpu is online.
1 parent 86a9ce2 commit 4302c3e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/ch/ch_domain.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,47 @@ char *virCHDomainGetMachineName(virDomainObjPtr vm)
416416
return ret;
417417
}
418418

419+
/**
420+
* virCHDomainValidateVcpuInfo:
421+
*
422+
* Validates vcpu thread information. If vcpu thread IDs are available,
423+
* this function validates that online vcpus have thread info present and
424+
* offline vcpus don't.
425+
*
426+
* Returns 0 on success -1 on error.
427+
*/
428+
int
429+
virCHDomainValidateVcpuInfo(virDomainObjPtr vm)
430+
{
431+
size_t maxvcpus = virDomainDefGetVcpusMax(vm->def);
432+
virDomainVcpuDefPtr vcpu;
433+
virCHDomainVcpuPrivatePtr vcpupriv;
434+
size_t i;
435+
436+
if (!virCHDomainHasVcpuPids(vm))
437+
return 0;
438+
439+
for (i = 0; i < maxvcpus; i++) {
440+
vcpu = virDomainDefGetVcpu(vm->def, i);
441+
vcpupriv = CH_DOMAIN_VCPU_PRIVATE(vcpu);
442+
443+
if (vcpu->online && vcpupriv->tid == 0) {
444+
virReportError(VIR_ERR_INTERNAL_ERROR,
445+
_("Didn't find thread id for vcpu '%zu'"), i);
446+
return -1;
447+
}
448+
449+
if (!vcpu->online && vcpupriv->tid != 0) {
450+
virReportError(VIR_ERR_INTERNAL_ERROR,
451+
_("Found thread id for inactive vcpu '%zu'"),
452+
i);
453+
return -1;
454+
}
455+
}
456+
457+
return 0;
458+
}
459+
419460
/**
420461
* virCHDomainObjFromDomain:
421462
* @domain: Domain pointer that has to be looked up

src/ch/ch_domain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ pid_t virCHDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpuid);
127127
bool virCHDomainHasVcpuPids(virDomainObjPtr vm);
128128

129129
char *virCHDomainGetMachineName(virDomainObjPtr vm);
130+
131+
int
132+
virCHDomainValidateVcpuInfo(virDomainObjPtr vm);
133+
130134
virDomainObjPtr virCHDomainObjFromDomain(virDomainPtr domain);
131135

132136
int

0 commit comments

Comments
 (0)