It comes very handy to have source path for chardevs. We already have such function: virDomainAuditChardevPath() but it's static and has name not suitable for exposing. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/domain_audit.c | 44 ++++++-------------------------------------- src/conf/domain_conf.c | 33 +++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index 1e667af73..484420a21 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -68,38 +68,6 @@ virDomainAuditGetRdev(const char *path ATTRIBUTE_UNUSED) #endif -static const char * -virDomainAuditChardevPath(virDomainChrSourceDefPtr chr) -{ - if (!chr) - return NULL; - - switch ((virDomainChrType) chr->type) { - case VIR_DOMAIN_CHR_TYPE_PTY: - case VIR_DOMAIN_CHR_TYPE_DEV: - case VIR_DOMAIN_CHR_TYPE_FILE: - case VIR_DOMAIN_CHR_TYPE_PIPE: - case VIR_DOMAIN_CHR_TYPE_NMDM: - return chr->data.file.path; - - case VIR_DOMAIN_CHR_TYPE_UNIX: - return chr->data.nix.path; - - case VIR_DOMAIN_CHR_TYPE_TCP: - case VIR_DOMAIN_CHR_TYPE_UDP: - case VIR_DOMAIN_CHR_TYPE_NULL: - case VIR_DOMAIN_CHR_TYPE_VC: - case VIR_DOMAIN_CHR_TYPE_STDIO: - case VIR_DOMAIN_CHR_TYPE_SPICEVMC: - case VIR_DOMAIN_CHR_TYPE_SPICEPORT: - case VIR_DOMAIN_CHR_TYPE_LAST: - return NULL; - } - - return NULL; -} - - static void virDomainAuditGenericDev(virDomainObjPtr vm, const char *type, @@ -178,8 +146,8 @@ virDomainAuditChardev(virDomainObjPtr vm, newsrc = newDef->source; virDomainAuditGenericDev(vm, "chardev", - virDomainAuditChardevPath(oldsrc), - virDomainAuditChardevPath(newsrc), + virDomainChrSourceDefPath(oldsrc), + virDomainChrSourceDefPath(newsrc), reason, success); } @@ -218,7 +186,7 @@ virDomainAuditSmartcard(virDomainObjPtr vm, case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH: virDomainAuditGenericDev(vm, "smartcard", NULL, - virDomainAuditChardevPath(def->data.passthru), + virDomainChrSourceDefPath(def->data.passthru), reason, success); break; @@ -264,7 +232,7 @@ virDomainAuditRNG(virDomainObjPtr vm, break; case VIR_DOMAIN_RNG_BACKEND_EGD: - newsrcpath = virDomainAuditChardevPath(newDef->source.chardev); + newsrcpath = virDomainChrSourceDefPath(newDef->source.chardev); break; case VIR_DOMAIN_RNG_BACKEND_LAST: @@ -279,7 +247,7 @@ virDomainAuditRNG(virDomainObjPtr vm, break; case VIR_DOMAIN_RNG_BACKEND_EGD: - oldsrcpath = virDomainAuditChardevPath(oldDef->source.chardev); + oldsrcpath = virDomainChrSourceDefPath(oldDef->source.chardev); break; case VIR_DOMAIN_RNG_BACKEND_LAST: @@ -982,7 +950,7 @@ virDomainAuditShmem(virDomainObjPtr vm, { char uuidstr[VIR_UUID_STRING_BUFLEN]; char *vmname = virAuditEncode("vm", vm->def->name); - const char *srcpath = virDomainAuditChardevPath(&def->server.chr); + const char *srcpath = virDomainChrSourceDefPath(&def->server.chr); const char *virt = virDomainVirtTypeToString(vm->def->virtType); char *shmpath = NULL; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0409c62ef..2cbe96b6e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2034,6 +2034,39 @@ virDomainNetDefFree(virDomainNetDefPtr def) VIR_FREE(def); } + +const char * +virDomainChrSourceDefPath(virDomainChrSourceDefPtr chr) +{ + if (!chr) + return NULL; + + switch ((virDomainChrType) chr->type) { + case VIR_DOMAIN_CHR_TYPE_PTY: + case VIR_DOMAIN_CHR_TYPE_DEV: + case VIR_DOMAIN_CHR_TYPE_FILE: + case VIR_DOMAIN_CHR_TYPE_PIPE: + case VIR_DOMAIN_CHR_TYPE_NMDM: + return chr->data.file.path; + + case VIR_DOMAIN_CHR_TYPE_UNIX: + return chr->data.nix.path; + + case VIR_DOMAIN_CHR_TYPE_TCP: + case VIR_DOMAIN_CHR_TYPE_UDP: + case VIR_DOMAIN_CHR_TYPE_NULL: + case VIR_DOMAIN_CHR_TYPE_VC: + case VIR_DOMAIN_CHR_TYPE_STDIO: + case VIR_DOMAIN_CHR_TYPE_SPICEVMC: + case VIR_DOMAIN_CHR_TYPE_SPICEPORT: + case VIR_DOMAIN_CHR_TYPE_LAST: + return NULL; + } + + return NULL; +} + + void ATTRIBUTE_NONNULL(1) virDomainChrSourceDefClear(virDomainChrSourceDefPtr def) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 6d9ee9787..51b830917 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3256,6 +3256,8 @@ int virDomainDefFindDevice(virDomainDefPtr def, virDomainDeviceDefPtr dev, bool reportError); +const char *virDomainChrSourceDefPath(virDomainChrSourceDefPtr chr); + void virDomainChrSourceDefClear(virDomainChrSourceDefPtr def); char *virDomainObjGetMetadata(virDomainObjPtr vm, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c1e9471c5..f671da9d5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -208,6 +208,7 @@ virDomainChrSerialTargetTypeToString; virDomainChrSourceDefClear; virDomainChrSourceDefCopy; virDomainChrSourceDefFree; +virDomainChrSourceDefPath; virDomainChrSpicevmcTypeFromString; virDomainChrSpicevmcTypeToString; virDomainChrTcpProtocolTypeFromString; -- 2.13.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list