[libvirt] [PATCH 0/2] Couple of build fixes

Spotted by our CI. Michal Privoznik (2): qemu_domain: Move qemuDomainGetPreservedMounts virSecuritySELinuxSetFileconHelper: Fix build with broken selinux.h src/qemu/qemu_domain.c | 140 ++++++++++++++++++++-------------------- src/security/security_selinux.c | 2 +- 2 files changed, 71 insertions(+), 71 deletions(-) -- 2.11.0

This function is used only from code compiled on Linux. Therefore on non-Linux platforms it triggers compilation error: ../../src/qemu/qemu_domain.c:209:1: error: unused function 'qemuDomainGetPreservedMounts' [-Werror,-Wunused-function] Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_domain.c | 140 ++++++++++++++++++++++++------------------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 01765dc28..b26c02bda 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -194,76 +194,6 @@ qemuDomainEnableNamespace(virDomainObjPtr vm, } -/** - * qemuDomainGetPreservedMounts: - * - * Process list of mounted filesystems and: - * a) save all FSs mounted under /dev to @devPath - * b) generate backup path for all the entries in a) - * - * Any of the return pointers can be NULL. - * - * Returns 0 on success, -1 otherwise (with error reported) - */ -static int -qemuDomainGetPreservedMounts(virQEMUDriverPtr driver, - virDomainObjPtr vm, - char ***devPath, - char ***devSavePath, - size_t *ndevPath) -{ - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - char **paths = NULL, **mounts = NULL; - size_t i, nmounts; - - if (virFileGetMountSubtree(PROC_MOUNTS, "/dev", - &mounts, &nmounts) < 0) - goto error; - - if (!nmounts) { - if (ndevPath) - *ndevPath = 0; - return 0; - } - - if (VIR_ALLOC_N(paths, nmounts) < 0) - goto error; - - for (i = 0; i < nmounts; i++) { - const char *suffix = mounts[i] + strlen(DEVPREFIX); - - if (STREQ(mounts[i], "/dev")) - suffix = "dev"; - - if (virAsprintf(&paths[i], "%s/%s.%s", - cfg->stateDir, vm->def->name, suffix) < 0) - goto error; - } - - if (devPath) - *devPath = mounts; - else - virStringListFreeCount(mounts, nmounts); - - if (devSavePath) - *devSavePath = paths; - else - virStringListFreeCount(paths, nmounts); - - if (ndevPath) - *ndevPath = nmounts; - - virObjectUnref(cfg); - return 0; - - error: - virStringListFreeCount(mounts, nmounts); - virStringListFreeCount(paths, nmounts); - virObjectUnref(cfg); - return -1; -} - - void qemuDomainEventQueue(virQEMUDriverPtr driver, virObjectEventPtr event) { @@ -6950,6 +6880,76 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, #if defined(__linux__) +/** + * qemuDomainGetPreservedMounts: + * + * Process list of mounted filesystems and: + * a) save all FSs mounted under /dev to @devPath + * b) generate backup path for all the entries in a) + * + * Any of the return pointers can be NULL. + * + * Returns 0 on success, -1 otherwise (with error reported) + */ +static int +qemuDomainGetPreservedMounts(virQEMUDriverPtr driver, + virDomainObjPtr vm, + char ***devPath, + char ***devSavePath, + size_t *ndevPath) +{ + virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + char **paths = NULL, **mounts = NULL; + size_t i, nmounts; + + if (virFileGetMountSubtree(PROC_MOUNTS, "/dev", + &mounts, &nmounts) < 0) + goto error; + + if (!nmounts) { + if (ndevPath) + *ndevPath = 0; + return 0; + } + + if (VIR_ALLOC_N(paths, nmounts) < 0) + goto error; + + for (i = 0; i < nmounts; i++) { + const char *suffix = mounts[i] + strlen(DEVPREFIX); + + if (STREQ(mounts[i], "/dev")) + suffix = "dev"; + + if (virAsprintf(&paths[i], "%s/%s.%s", + cfg->stateDir, vm->def->name, suffix) < 0) + goto error; + } + + if (devPath) + *devPath = mounts; + else + virStringListFreeCount(mounts, nmounts); + + if (devSavePath) + *devSavePath = paths; + else + virStringListFreeCount(paths, nmounts); + + if (ndevPath) + *ndevPath = nmounts; + + virObjectUnref(cfg); + return 0; + + error: + virStringListFreeCount(mounts, nmounts); + virStringListFreeCount(paths, nmounts); + virObjectUnref(cfg); + return -1; +} + + static int qemuDomainCreateDevice(const char *device, const char *path, -- 2.11.0

There are still some systems out there that have broken setfilecon*() prototypes. Instead of taking 'const char *tcon' it is taking 'char *tcon'. The function should just set the context, not modify it. We had been bitten with this problem before which resulted in 292d3f2d and subsequently b109c09765. However, with one my latest commits (4674fc6afd6d) I've changed the type of @tcon variable to 'const char *' which results in build failure on the systems from above. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/security/security_selinux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 92267e8fc..f229b5139 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1138,7 +1138,7 @@ virSecuritySELinuxSetFileconHelper(const char *path, const char *tcon, VIR_INFO("Setting SELinux context on '%s' to '%s'", path, tcon); - if (setfilecon_raw(path, tcon) < 0) { + if (setfilecon_raw(path, (VIR_SELINUX_CTX_CONST char *) tcon) < 0) { int setfilecon_errno = errno; if (getfilecon_raw(path, &econ) >= 0) { -- 2.11.0

On Tue, 2017-01-10 at 16:33 +0100, Michal Privoznik wrote:
Spotted by our CI. Michal Privoznik (2): qemu_domain: Move qemuDomainGetPreservedMounts virSecuritySELinuxSetFileconHelper: Fix build with broken selinux.h src/qemu/qemu_domain.c | 140 ++++++++++++++++++++-------------------- src/security/security_selinux.c | 2 +- 2 files changed, 71 insertions(+), 71 deletions(-)
ACK series (and pushed). -- Andrea Bolognani / Red Hat / Virtualization
participants (2)
-
Andrea Bolognani
-
Michal Privoznik