[libvirt] [PATCH 0/2] Fixes for Mac OS X

These patches enable libvirtd to run on Mac OS X. We still cannot build libvirtd from libvirt git repository due to a prcgen problem(*) though, we can build with libvirt tarballs, that means that we can use libvirtd installed by HomeBrew. (*) https://www.redhat.com/archives/libvirt-users/2013-February/msg00033.html I tested the patches on Mac OS X 10.8.5. Ryota Ozaki (2): rpc: fix getsockopt for LOCAL_PEERCRED on Mac OS X nodeinfo: make freebsdNodeGetCPUCount work on Mac OS X src/nodeinfo.c | 15 ++++++++++++--- src/rpc/virnetsocket.c | 4 ++++ 2 files changed, 16 insertions(+), 3 deletions(-) -- 1.8.4

This fixes the following error: error : virGetUserEnt:703 : Failed to find user record for uid '32654' '32654' (it's random and varies) comes from getsockopt with LOCAL_PEERCRED option. getsockopt returns w/o error but seems to not set any value to the buffer for uid. For Mac OS X, LOCAL_PEERCRED has to be used with SOL_LOCAL level. With SOL_LOCAL, getsockopt returns a correct uid. Note that SOL_LOCAL can be found in /System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/un.h. Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com> --- src/rpc/virnetsocket.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 152c5fc..a6ef07a 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -1159,7 +1159,11 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock, socklen_t cr_len = sizeof(cr); virObjectLock(sock); +#if defined(__APPLE__) + if (getsockopt(sock->fd, SOL_LOCAL, LOCAL_PEERCRED, &cr, &cr_len) < 0) { +#else if (getsockopt(sock->fd, SOL_SOCKET, LOCAL_PEERCRED, &cr, &cr_len) < 0) { +#endif virReportSystemError(errno, "%s", _("Failed to get client socket identity")); virObjectUnlock(sock); -- 1.8.4

This fixes the following error: error : nodeGetInfo:933 : this function is not supported by the connection driver: node info not implemented on this platform Mac OS X can use sysctlbyname as same as FreeBSD to get the CPU frequency. However, the MIB style name is different from FreeBSD's. And the unit of the return frequency is also different. Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com> --- src/nodeinfo.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 33a79b7..0c92cfa 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -38,7 +38,7 @@ # include <numa.h> #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__APPLE__) # include <sys/types.h> # include <sys/sysctl.h> #endif @@ -58,7 +58,7 @@ #define VIR_FROM_THIS VIR_FROM_NONE -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__APPLE__) static int freebsdNodeGetCPUCount(void) { @@ -882,7 +882,7 @@ cleanup: VIR_FORCE_FCLOSE(cpuinfo); return ret; } -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__APPLE__) { nodeinfo->nodes = 1; nodeinfo->sockets = 1; @@ -897,12 +897,21 @@ cleanup: unsigned long cpu_freq; size_t cpu_freq_len = sizeof(cpu_freq); +#ifdef __FreeBSD__ if (sysctlbyname("dev.cpu.0.freq", &cpu_freq, &cpu_freq_len, NULL, 0) < 0) { virReportSystemError(errno, "%s", _("cannot obtain CPU freq")); return -1; } nodeinfo->mhz = cpu_freq; +#else + if (sysctlbyname("hw.cpufrequency", &cpu_freq, &cpu_freq_len, NULL, 0) < 0) { + virReportSystemError(errno, "%s", _("cannot obtain CPU freq")); + return -1; + } + + nodeinfo->mhz = cpu_freq / 1000000; +#endif /* get memory information */ int mib[2] = { CTL_HW, HW_PHYSMEM }; -- 1.8.4
participants (1)
-
Ryota Ozaki