mirror of https://gitee.com/openkylin/libvirt.git
conf: Properly instantiate virDomainChrSourceDef in virDomainTPMDef
'virDomainChrSourceDef' contains private data so 'virDomainChrSourceDefNew' must be used to allocate it. 'virDomainTPMDef' was using it directly which won't work with the chardev helper functions. Convert it to a pointer to properly allocate private data. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
5dc77b7d32
commit
42b0000699
|
@ -536,7 +536,7 @@ virDomainAuditTPM(virDomainObj *vm, virDomainTPMDef *tpm,
|
|||
|
||||
switch (tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
path = tpm->data.passthrough.source.data.file.path;
|
||||
path = tpm->data.passthrough.source->data.file.path;
|
||||
if (!(device = virAuditEncode("device", VIR_AUDIT_STR(path)))) {
|
||||
VIR_WARN("OOM while encoding audit message");
|
||||
goto cleanup;
|
||||
|
@ -547,7 +547,7 @@ virDomainAuditTPM(virDomainObj *vm, virDomainTPMDef *tpm,
|
|||
virt, reason, vmname, uuidstr, device);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
path = tpm->data.emulator.source.data.nix.path;
|
||||
path = tpm->data.emulator.source->data.nix.path;
|
||||
if (!(device = virAuditEncode("device", VIR_AUDIT_STR(path)))) {
|
||||
VIR_WARN("OOM while encoding audit message");
|
||||
goto cleanup;
|
||||
|
|
|
@ -3211,10 +3211,10 @@ void virDomainTPMDefFree(virDomainTPMDef *def)
|
|||
|
||||
switch (def->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
virDomainChrSourceDefClear(&def->data.passthrough.source);
|
||||
virObjectUnref(def->data.passthrough.source);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
virDomainChrSourceDefClear(&def->data.emulator.source);
|
||||
virObjectUnref(def->data.emulator.source);
|
||||
g_free(def->data.emulator.storagepath);
|
||||
g_free(def->data.emulator.logfile);
|
||||
break;
|
||||
|
@ -11831,13 +11831,17 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
|
|||
|
||||
switch (def->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
if (!(def->data.passthrough.source = virDomainChrSourceDefNew(xmlopt)))
|
||||
goto error;
|
||||
path = virXPathString("string(./backend/device/@path)", ctxt);
|
||||
if (!path)
|
||||
path = g_strdup(VIR_DOMAIN_TPM_DEFAULT_DEVICE);
|
||||
def->data.passthrough.source.data.file.path = g_steal_pointer(&path);
|
||||
def->data.passthrough.source.type = VIR_DOMAIN_CHR_TYPE_DEV;
|
||||
def->data.passthrough.source->type = VIR_DOMAIN_CHR_TYPE_DEV;
|
||||
def->data.passthrough.source->data.file.path = g_steal_pointer(&path);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
if (!(def->data.emulator.source = virDomainChrSourceDefNew(xmlopt)))
|
||||
goto error;
|
||||
secretuuid = virXPathString("string(./backend/encryption/@secret)", ctxt);
|
||||
if (secretuuid) {
|
||||
if (virUUIDParse(secretuuid, def->data.emulator.secretuuid) < 0) {
|
||||
|
@ -25456,7 +25460,7 @@ virDomainTPMDefFormat(virBuffer *buf,
|
|||
virBufferAddLit(buf, ">\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
virBufferEscapeString(buf, "<device path='%s'/>\n",
|
||||
def->data.passthrough.source.data.file.path);
|
||||
def->data.passthrough.source->data.file.path);
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</backend>\n");
|
||||
break;
|
||||
|
|
|
@ -1381,10 +1381,10 @@ struct _virDomainTPMDef {
|
|||
int version; /* virDomainTPMVersion */
|
||||
union {
|
||||
struct {
|
||||
virDomainChrSourceDef source;
|
||||
virDomainChrSourceDef *source;
|
||||
} passthrough;
|
||||
struct {
|
||||
virDomainChrSourceDef source;
|
||||
virDomainChrSourceDef *source;
|
||||
char *storagepath;
|
||||
char *logfile;
|
||||
unsigned char secretuuid[VIR_UUID_BUFLEN];
|
||||
|
|
|
@ -340,7 +340,7 @@ qemuSetupTPMCgroup(virDomainObj *vm,
|
|||
|
||||
switch (dev->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
ret = qemuSetupChrSourceCgroup(vm, &dev->data.passthrough.source);
|
||||
ret = qemuSetupChrSourceCgroup(vm, dev->data.passthrough.source);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
|
|
|
@ -9947,7 +9947,7 @@ qemuBuildTPMBackendStr(virCommand *cmd,
|
|||
|
||||
switch (tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
tpmdev = tpm->data.passthrough.source.data.file.path;
|
||||
tpmdev = tpm->data.passthrough.source->data.file.path;
|
||||
if (!(cancel_path = virTPMCreateCancelPath(tpmdev)))
|
||||
return NULL;
|
||||
|
||||
|
@ -9972,7 +9972,7 @@ qemuBuildTPMBackendStr(virCommand *cmd,
|
|||
virBufferAddLit(&buf, ",chardev=chrtpm");
|
||||
|
||||
*chardev = g_strdup_printf("socket,id=chrtpm,path=%s",
|
||||
tpm->data.emulator.source.data.nix.path);
|
||||
tpm->data.emulator.source->data.nix.path);
|
||||
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
|
@ -10041,7 +10041,7 @@ qemuBuildTPMProxyCommandLine(virCommand *cmd,
|
|||
if (virJSONValueObjectAdd(&props,
|
||||
"s:driver", virDomainTPMModelTypeToString(tpm->model),
|
||||
"s:id", tpm->info.alias,
|
||||
"s:host-path", tpm->data.passthrough.source.data.file.path,
|
||||
"s:host-path", tpm->data.passthrough.source->data.file.path,
|
||||
NULL) < 0)
|
||||
return -1;
|
||||
|
||||
|
|
|
@ -422,7 +422,7 @@ qemuDomainSetupTPM(virDomainTPMDef *dev,
|
|||
{
|
||||
switch (dev->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
*paths = g_slist_prepend(*paths, g_strdup(dev->data.passthrough.source.data.file.path));
|
||||
*paths = g_slist_prepend(*paths, g_strdup(dev->data.passthrough.source->data.file.path));
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
|
|
|
@ -332,11 +332,11 @@ qemuTPMEmulatorPrepareHost(virDomainTPMDef *tpm,
|
|||
return -1;
|
||||
|
||||
/* create the socket filename */
|
||||
if (!tpm->data.emulator.source.data.nix.path &&
|
||||
!(tpm->data.emulator.source.data.nix.path =
|
||||
if (!tpm->data.emulator.source->data.nix.path &&
|
||||
!(tpm->data.emulator.source->data.nix.path =
|
||||
qemuTPMCreateEmulatorSocket(swtpmStateDir, shortName)))
|
||||
return -1;
|
||||
tpm->data.emulator.source.type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
||||
tpm->data.emulator.source->type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -716,7 +716,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm,
|
|||
secretuuid) < 0)
|
||||
goto error;
|
||||
|
||||
unlink(tpm->data.emulator.source.data.nix.path);
|
||||
unlink(tpm->data.emulator.source->data.nix.path);
|
||||
|
||||
cmd = virCommandNew(swtpm);
|
||||
if (!cmd)
|
||||
|
@ -726,7 +726,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm,
|
|||
|
||||
virCommandAddArgList(cmd, "socket", "--daemon", "--ctrl", NULL);
|
||||
virCommandAddArgFormat(cmd, "type=unixio,path=%s,mode=0600",
|
||||
tpm->data.emulator.source.data.nix.path);
|
||||
tpm->data.emulator.source->data.nix.path);
|
||||
|
||||
virCommandAddArg(cmd, "--tpmstate");
|
||||
virCommandAddArgFormat(cmd, "dir=%s,mode=0600",
|
||||
|
|
|
@ -1686,12 +1686,12 @@ virSecurityDACSetTPMFileLabel(virSecurityManager *mgr,
|
|||
switch (tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
ret = virSecurityDACSetChardevLabelHelper(mgr, def,
|
||||
&tpm->data.passthrough.source,
|
||||
tpm->data.passthrough.source,
|
||||
false, false);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
ret = virSecurityDACSetChardevLabelHelper(mgr, def,
|
||||
&tpm->data.emulator.source,
|
||||
tpm->data.emulator.source,
|
||||
false, false);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
|
@ -1712,7 +1712,7 @@ virSecurityDACRestoreTPMFileLabel(virSecurityManager *mgr,
|
|||
switch (tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
ret = virSecurityDACRestoreChardevLabelHelper(mgr, def,
|
||||
&tpm->data.passthrough.source,
|
||||
tpm->data.passthrough.source,
|
||||
false, false);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
|
|
|
@ -1637,7 +1637,7 @@ virSecuritySELinuxSetTPMFileLabel(virSecurityManager *mgr,
|
|||
|
||||
switch (tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
tpmdev = tpm->data.passthrough.source.data.file.path;
|
||||
tpmdev = tpm->data.passthrough.source->data.file.path;
|
||||
rc = virSecuritySELinuxSetFilecon(mgr, tpmdev, seclabel->imagelabel, false);
|
||||
if (rc < 0)
|
||||
return -1;
|
||||
|
@ -1656,7 +1656,7 @@ virSecuritySELinuxSetTPMFileLabel(virSecurityManager *mgr,
|
|||
}
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
tpmdev = tpm->data.emulator.source.data.nix.path;
|
||||
tpmdev = tpm->data.emulator.source->data.nix.path;
|
||||
rc = virSecuritySELinuxSetFilecon(mgr, tpmdev, seclabel->imagelabel, false);
|
||||
if (rc < 0)
|
||||
return -1;
|
||||
|
@ -1685,7 +1685,7 @@ virSecuritySELinuxRestoreTPMFileLabelInt(virSecurityManager *mgr,
|
|||
|
||||
switch (tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
tpmdev = tpm->data.passthrough.source.data.file.path;
|
||||
tpmdev = tpm->data.passthrough.source->data.file.path;
|
||||
rc = virSecuritySELinuxRestoreFileLabel(mgr, tpmdev, false);
|
||||
|
||||
if ((cancel_path = virTPMCreateCancelPath(tpmdev)) != NULL) {
|
||||
|
|
|
@ -450,9 +450,9 @@ testCompareXMLToArgvCreateArgs(virQEMUDriver *drv,
|
|||
if (vm->def->tpms[i]->type != VIR_DOMAIN_TPM_TYPE_EMULATOR)
|
||||
continue;
|
||||
|
||||
VIR_FREE(vm->def->tpms[i]->data.emulator.source.data.file.path);
|
||||
vm->def->tpms[i]->data.emulator.source.data.file.path = g_strdup("/dev/test");
|
||||
vm->def->tpms[i]->data.emulator.source.type = VIR_DOMAIN_CHR_TYPE_FILE;
|
||||
VIR_FREE(vm->def->tpms[i]->data.emulator.source->data.file.path);
|
||||
vm->def->tpms[i]->data.emulator.source->data.file.path = g_strdup("/dev/test");
|
||||
vm->def->tpms[i]->data.emulator.source->type = VIR_DOMAIN_CHR_TYPE_FILE;
|
||||
}
|
||||
|
||||
for (i = 0; i < vm->def->nvideos; i++) {
|
||||
|
|
Loading…
Reference in New Issue