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

These patches enable libvirtd to work on Mac OS X. We still cannot build libvirtd from git repository due to a rpcgen problem(*) though, we can build it with a libvirt tarball, that means that we can use libvirtd installed by HomeBrew. (*) https://www.redhat.com/archives/libvirt-users/2013-February/msg00033.html ozaki-r 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.3.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.3.4

On 05.10.2013 07:56, Ryota Ozaki wrote:
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);
Indentation off. Fixed and pushed. You can use 'make syntax-check' to catch these problems. Although, you need cppi installed. ACK Michal NB: Cole, I think this is yet another candidate for maint branches.

On Mon, Oct 07, 2013 at 10:33:44AM +0200, Michal Privoznik wrote:
On 05.10.2013 07:56, Ryota Ozaki wrote:
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);
Indentation off. Fixed and pushed. You can use 'make syntax-check' to catch these problems. Although, you need cppi installed.
ACK
IIUC, this error was present on BSD too, so I think probably we should not have the conditional here, but just use SOL_LOCAL for everything (this code block is already conditionalized) Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Hi Daniel, On Mon, Oct 7, 2013 at 6:51 PM, Daniel P. Berrange <berrange@redhat.com> wrote:
On Mon, Oct 07, 2013 at 10:33:44AM +0200, Michal Privoznik wrote:
On 05.10.2013 07:56, Ryota Ozaki wrote:
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);
Indentation off. Fixed and pushed. You can use 'make syntax-check' to catch these problems. Although, you need cppi installed.
ACK
IIUC, this error was present on BSD too, so I think probably we should not have the conditional here, but just use SOL_LOCAL for everything (this code block is already conditionalized)
It seems that there is not SOL_LOCAL on FreeBSD (9.2) and LOCAL_PEERCRED works with SOL_SOCKET. If we want to have only one getsockopt, we may be able to use 0 for the level (*). I confirmed it works on both Mac OS X (because SOL_LOCAL == 0) and FreeBSD (I don't know why). (*) http://doxygen.postgresql.org/getpeereid_8c_source.html Thanks, ozaki-r
Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Hi Michal, On Mon, Oct 7, 2013 at 5:33 PM, Michal Privoznik <mprivozn@redhat.com> wrote:
On 05.10.2013 07:56, Ryota Ozaki wrote:
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);
Indentation off. Fixed and pushed. You can use 'make syntax-check' to catch these problems. Although, you need cppi installed.
I did make syntax-check, however I'm sorry, I ignored warnings for cppi... I've installed cppi via 'brew create' and confirmed the syntax problems. Thanks, ozaki-r
ACK
Michal
NB: Cole, I think this is yet another candidate for maint branches.

On 10/07/2013 04:33 AM, Michal Privoznik wrote:
On 05.10.2013 07:56, Ryota Ozaki wrote:
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);
Indentation off. Fixed and pushed. You can use 'make syntax-check' to catch these problems. Although, you need cppi installed.
ACK
Michal
NB: Cole, I think this is yet another candidate for maint branches.
I pushed it to v1.1.3-maint Thanks, Cole

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.3.4

On 05.10.2013 07:56, Ryota Ozaki wrote:
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)
This function is now called on apple too. I'm renaming it to appleFreebsdNodeGetCPUCount().
{ @@ -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
Again, indentation is off.
/* get memory information */ int mib[2] = { CTL_HW, HW_PHYSMEM };
ACKed, fixed and pushed. Michal
participants (4)
-
Cole Robinson
-
Daniel P. Berrange
-
Michal Privoznik
-
Ryota Ozaki