virObjectUnref(def->data.emulator.source);
g_free(def->data.emulator.storagepath);
g_free(def->data.emulator.logfile);
+ virBitmapFree(def->data.emulator.activePcrBanks);
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
if ((nnodes = virXPathNodeSet("./backend/active_pcr_banks/*", ctxt, &nodes)) < 0)
break;
+ if (nnodes > 0)
+ def->data.emulator.activePcrBanks = virBitmapNew(0);
for (i = 0; i < nnodes; i++) {
if ((bank = virDomainTPMPcrBankTypeFromString((const char *)nodes[i]->name)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
nodes[i]->name);
goto error;
}
- def->data.emulator.activePcrBanks |= (1 << bank);
+ virBitmapSetBitExpand(def->data.emulator.activePcrBanks, bank);
}
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
return false;
}
- if (src->data.emulator.activePcrBanks != dst->data.emulator.activePcrBanks) {
+ if (!virBitmapEqual(src->data.emulator.activePcrBanks,
+ dst->data.emulator.activePcrBanks)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Target active PCR banks doesn't match source"));
return false;
}
if (def->data.emulator.activePcrBanks) {
g_auto(virBuffer) activePcrBanksBuf = VIR_BUFFER_INIT_CHILD(&backendChildBuf);
- size_t i;
+ ssize_t bank = -1;
- for (i = VIR_DOMAIN_TPM_PCR_BANK_SHA1; i < VIR_DOMAIN_TPM_PCR_BANK_LAST; i++) {
- if ((def->data.emulator.activePcrBanks & (1 << i)))
- virBufferAsprintf(&activePcrBanksBuf, "<%s/>\n",
- virDomainTPMPcrBankTypeToString(i));
- }
+ while ((bank = virBitmapNextSetBit(def->data.emulator.activePcrBanks, bank)) > -1)
+ virBufferAsprintf(&activePcrBanksBuf, "<%s/>\n", virDomainTPMPcrBankTypeToString(bank));
virXMLFormatElement(&backendChildBuf, "active_pcr_banks", NULL, &activePcrBanksBuf);
}
static char *
-qemuTPMPcrBankBitmapToStr(unsigned int pcrBanks)
+qemuTPMPcrBankBitmapToStr(virBitmap *activePcrBanks)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
- const char *comma = "";
- size_t i;
-
- for (i = VIR_DOMAIN_TPM_PCR_BANK_SHA1; i < VIR_DOMAIN_TPM_PCR_BANK_LAST; i++) {
- if (pcrBanks & (1 << i)) {
- virBufferAsprintf(&buf, "%s%s",
- comma, virDomainTPMPcrBankTypeToString(i));
- comma = ",";
- }
- }
+ ssize_t bank = -1;
+
+ while ((bank = virBitmapNextSetBit(activePcrBanks, bank)) > -1)
+ virBufferAsprintf(&buf, "%s,", virDomainTPMPcrBankTypeToString(bank));
+
+ virBufferTrim(&buf, ",");
+
return virBufferContentAndReset(&buf);
}
qemuTPMEmulatorReconfigure(const char *storagepath,
uid_t swtpm_user,
gid_t swtpm_group,
- unsigned int activePcrBanks,
+ virBitmap *activePcrBanks,
const char *logfile,
const virDomainTPMVersion tpmversion,
const unsigned char *secretuuid)