[libvirt] [PATCH] Misc win32 build fixes

* daemon/Makefile.am: Fix missing sasl rule * src/datatypes.c: Add unistd.h to avoid gnulib bug * src/util/cgroup.c: Disable mntent if not available --- daemon/Makefile.am | 3 ++ src/datatypes.c | 1 + src/util/cgroup.c | 66 ++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 26347d6..84aab04 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -243,6 +243,9 @@ install-data-sasl: uninstall-data-sasl: rm -f $(DESTDIR)$(sysconfdir)/sasl2/libvirt.conf rmdir $(DESTDIR)$(sysconfdir)/sasl2/ +else +install-data-sasl: +uninstall-data-sasl: endif diff --git a/src/datatypes.c b/src/datatypes.c index 6741b9e..89ad309 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -20,6 +20,7 @@ */ #include <config.h> +#include <unistd.h> #include "datatypes.h" #include "virterror_internal.h" diff --git a/src/util/cgroup.c b/src/util/cgroup.c index 2e646fd..66297b9 100644 --- a/src/util/cgroup.c +++ b/src/util/cgroup.c @@ -13,7 +13,9 @@ #include <stdio.h> #include <stdint.h> #include <inttypes.h> +#ifdef HAVE_MNTENT_H #include <mntent.h> +#endif #include <fcntl.h> #include <string.h> #include <errno.h> @@ -68,7 +70,7 @@ void virCgroupFree(virCgroupPtr *group) VIR_FREE(*group); } - +#ifdef HAVE_MNTENT_H /* * Process /proc/mounts figuring out what controllers are * mounted and where @@ -233,6 +235,7 @@ static int virCgroupDetect(virCgroupPtr group) return rc; } +#endif static int virCgroupPathOfController(virCgroupPtr group, @@ -317,12 +320,12 @@ static int virCgroupGetValueStr(virCgroupPtr group, static int virCgroupSetValueU64(virCgroupPtr group, int controller, const char *key, - uint64_t value) + unsigned long long int value) { char *strval = NULL; int rc; - if (virAsprintf(&strval, "%" PRIu64, value) == -1) + if (virAsprintf(&strval, "%llu", value) == -1) return -ENOMEM; rc = virCgroupSetValueStr(group, controller, key, strval); @@ -339,12 +342,12 @@ static int virCgroupSetValueU64(virCgroupPtr group, static int virCgroupSetValueI64(virCgroupPtr group, int controller, const char *key, - int64_t value) + long long int value) { char *strval = NULL; int rc; - if (virAsprintf(&strval, "%" PRIi64, value) == -1) + if (virAsprintf(&strval, "%lld", value) == -1) return -ENOMEM; rc = virCgroupSetValueStr(group, controller, key, strval); @@ -357,7 +360,7 @@ static int virCgroupSetValueI64(virCgroupPtr group, static int virCgroupGetValueI64(virCgroupPtr group, int controller, const char *key, - int64_t *value) + long long int *value) { char *strval = NULL; int rc = 0; @@ -378,7 +381,7 @@ out: static int virCgroupGetValueU64(virCgroupPtr group, int controller, const char *key, - uint64_t *value) + unsigned long long int *value) { char *strval = NULL; int rc = 0; @@ -387,7 +390,7 @@ static int virCgroupGetValueU64(virCgroupPtr group, if (rc != 0) goto out; - if (sscanf(strval, "%" SCNu64, value) != 1) + if (virStrToLong_ull(strval, NULL, 10, value) < 0) rc = -EINVAL; out: VIR_FREE(strval); @@ -396,6 +399,7 @@ out: } +#ifdef HAVE_MNTENT_H static int virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPtr group) { int i; @@ -546,7 +550,7 @@ cleanup: virCgroupFree(&rootgrp); return rc; } - +#endif /** * virCgroupRemove: @@ -617,6 +621,7 @@ int virCgroupAddTask(virCgroupPtr group, pid_t pid) * * Returns 0 on success */ +#ifdef HAVE_MNTENT_H int virCgroupForDriver(const char *name, virCgroupPtr *group, int privileged, @@ -650,6 +655,16 @@ out: return rc; } +#else +int virCgroupForDriver(const char *name ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED, + int privileged ATTRIBUTE_UNUSED, + int create ATTRIBUTE_UNUSED) +{ + /* Claim no support */ + return -ENXIO; +} +#endif /** @@ -661,6 +676,7 @@ out: * * Returns 0 on success */ +#ifdef HAVE_MNTENT_H int virCgroupForDomain(virCgroupPtr driver, const char *name, virCgroupPtr *group, @@ -684,6 +700,15 @@ int virCgroupForDomain(virCgroupPtr driver, return rc; } +#else +int virCgroupForDomain(virCgroupPtr driver ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED, + virCgroupPtr *group ATTRIBUTE_UNUSED, + int create ATTRIBUTE_UNUSED) +{ + return -ENXIO; +} +#endif /** * virCgroupSetMemory: @@ -786,6 +811,7 @@ int virCgroupAllowDeviceMajor(virCgroupPtr group, char type, int major) * * Returns: 0 on success */ +#if defined(major) && defined(minor) int virCgroupAllowDevicePath(virCgroupPtr group, const char *path) { struct stat sb; @@ -801,6 +827,14 @@ int virCgroupAllowDevicePath(virCgroupPtr group, const char *path) major(sb.st_rdev), minor(sb.st_rdev)); } +#else +int virCgroupAllowDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED) +{ + return -ENOSYS; +} +#endif + /** * virCgroupDenyDevice: @@ -861,6 +895,7 @@ int virCgroupDenyDeviceMajor(virCgroupPtr group, char type, int major) return rc; } +#if defined(major) && defined(minor) int virCgroupDenyDevicePath(virCgroupPtr group, const char *path) { struct stat sb; @@ -876,26 +911,33 @@ int virCgroupDenyDevicePath(virCgroupPtr group, const char *path) major(sb.st_rdev), minor(sb.st_rdev)); } +#else +int virCgroupDenyDevicePath(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED) +{ + return -ENOSYS; +} +#endif int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares) { return virCgroupSetValueU64(group, VIR_CGROUP_CONTROLLER_CPU, - "cpu.shares", (uint64_t)shares); + "cpu.shares", shares); } int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares) { return virCgroupGetValueU64(group, VIR_CGROUP_CONTROLLER_CPU, - "cpu.shares", (uint64_t *)shares); + "cpu.shares", shares); } int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) { return virCgroupGetValueU64(group, VIR_CGROUP_CONTROLLER_CPUACCT, - "cpuacct.usage", (uint64_t *)usage); + "cpuacct.usage", usage); } int virCgroupSetFreezerState(virCgroupPtr group, const char *state) -- 1.6.2.5

On Wed, Oct 07, 2009 at 11:42:19AM +0100, Daniel P. Berrange wrote:
* daemon/Makefile.am: Fix missing sasl rule * src/datatypes.c: Add unistd.h to avoid gnulib bug * src/util/cgroup.c: Disable mntent if not available ---
ACK, also unification of type we use long long in libvirt to denotate 64 bits ints, it's actually the largest change in that patch. Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Wed, Oct 07, 2009 at 03:56:12PM +0200, Daniel Veillard wrote:
On Wed, Oct 07, 2009 at 11:42:19AM +0100, Daniel P. Berrange wrote:
* daemon/Makefile.am: Fix missing sasl rule * src/datatypes.c: Add unistd.h to avoid gnulib bug * src/util/cgroup.c: Disable mntent if not available ---
ACK, also unification of type we use long long in libvirt to denotate 64 bits ints, it's actually the largest change in that patch.
Opps, I should have mentioned why I did that too... The PRIi64 constants is intended to expand to the OS specific printf format required for a 64 bit integer type. All Win32 runtimes have broken 64-bit integer printf support - their definition of PRIi64 in fact wants a type of 'long' which is only 32bits. libvirt though uses GNULIB which provides a replacement printf impl which works properly, but it does not replace the PRIi64 constant which still refers to the Microsoft impl's requirements. Thus we switch to just using the fixed %llu which we know GNULIB guarentees to support, so does not need "portability" constants. Of course using int64_t with %llu then generates a warning, unless you cast to unsigned long long. So in the end the simple solution is just to say %llu and unsigned long long everywhere, and ignore all this portability stuff which is not in fact portable or reliable Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Wed, Oct 07, 2009 at 03:08:24PM +0100, Daniel P. Berrange wrote:
On Wed, Oct 07, 2009 at 03:56:12PM +0200, Daniel Veillard wrote:
On Wed, Oct 07, 2009 at 11:42:19AM +0100, Daniel P. Berrange wrote:
* daemon/Makefile.am: Fix missing sasl rule * src/datatypes.c: Add unistd.h to avoid gnulib bug * src/util/cgroup.c: Disable mntent if not available ---
ACK, also unification of type we use long long in libvirt to denotate 64 bits ints, it's actually the largest change in that patch.
Opps, I should have mentioned why I did that too...
The PRIi64 constants is intended to expand to the OS specific printf format required for a 64 bit integer type. All Win32 runtimes have broken 64-bit integer printf support - their definition of PRIi64 in fact wants a type of 'long' which is only 32bits. libvirt though uses GNULIB which provides a replacement printf impl which works properly, but it does not replace the PRIi64 constant which still refers to the Microsoft impl's requirements. Thus we switch to just using the fixed %llu which we know GNULIB guarentees to support, so does not need "portability" constants. Of course using int64_t with %llu then generates a warning, unless you cast to unsigned long long. So in the end the simple solution is just to say
%llu and unsigned long long
everywhere, and ignore all this portability stuff which is not in fact portable or reliable
Okay, I basically guessed so except I didn;t know the details of the PRIx64 breakages, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (2)
-
Daniel P. Berrange
-
Daniel Veillard