[libvirt] [PATCH 0/2] Implement virConnectGetSysinfo in libxl and xen drivers

While discussing a recent libxl patch, we realized virConnectGetSysinfo was never implemented in the libxl and legacy xen drivers. This small series provides an implementation for these drivers. Jim Fehlig (2): libxl: Implement virConnectGetSysinfo xen: Implement virConnectGetSysinfo src/libxl/libxl_conf.h | 1 + src/libxl/libxl_driver.c | 29 +++++++++++++++++++++++++++++ src/xen/xen_driver.c | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletions(-) -- 1.7.7

virConnectGetSysinfo was never implemented in the libxl driver. This patch provides an implementation based on the qemu driver. --- src/libxl/libxl_conf.h | 1 + src/libxl/libxl_driver.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index 754fc40..ea741bc 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -70,6 +70,7 @@ struct _libxlDriverPrivate { virDomainObjListPtr domains; virDomainEventStatePtr domainEventState; + virSysinfoDefPtr hostsysinfo; char *configDir; char *autostartDir; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 935919b..0cdce86 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -45,6 +45,7 @@ #include "virtypedparam.h" #include "viruri.h" #include "virstring.h" +#include "virsysinfo.h" #define VIR_FROM_THIS VIR_FROM_LIBXL @@ -1137,6 +1138,7 @@ libxlStateCleanup(void) VIR_FREE(libxl_driver->saveDir); virDomainEventStateFree(libxl_driver->domainEventState); + virSysinfoDefFree(libxl_driver->hostsysinfo); libxlDriverUnlock(libxl_driver); virMutexDestroy(&libxl_driver->lock); @@ -1242,6 +1244,10 @@ libxlStateInitialize(bool privileged, } VIR_FREE(log_file); + /* read the host sysinfo */ + if (privileged) + libxl_driver->hostsysinfo = virSysinfoRead(); + libxl_driver->domainEventState = virDomainEventStateNew(); if (!libxl_driver->domainEventState) goto error; @@ -1425,6 +1431,28 @@ static char *libxlConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED) return virGetHostname(); } +static char * +libxlConnectGetSysinfo(virConnectPtr conn, unsigned int flags) +{ + libxlDriverPrivatePtr driver = conn->privateData; + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virCheckFlags(0, NULL); + + if (!driver->hostsysinfo) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Host SMBIOS information is not available")); + return NULL; + } + + if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0) + return NULL; + if (virBufferError(&buf)) { + virReportOOMError(); + return NULL; + } + return virBufferContentAndReset(&buf); +} static int libxlConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED) @@ -4363,6 +4391,7 @@ static virDriver libxlDriver = { .connectGetType = libxlConnectGetType, /* 0.9.0 */ .connectGetVersion = libxlConnectGetVersion, /* 0.9.0 */ .connectGetHostname = libxlConnectGetHostname, /* 0.9.0 */ + .connectGetSysinfo = libxlConnectGetSysinfo, /* 1.0.7 */ .connectGetMaxVcpus = libxlConnectGetMaxVcpus, /* 0.9.0 */ .nodeGetInfo = libxlNodeGetInfo, /* 0.9.0 */ .connectGetCapabilities = libxlConnectGetCapabilities, /* 0.9.0 */ -- 1.7.7

virConnectGetSysinfo was never implemented in the legacy xen driver. This patch provides an implementation based on the qemu driver. --- src/xen/xen_driver.c | 37 ++++++++++++++++++++++++++++++++++++- 1 files changed, 36 insertions(+), 1 deletions(-) diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 217d380..3efc27a 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -81,6 +81,7 @@ xenUnifiedDomainGetVcpus(virDomainPtr dom, static bool is_privileged = false; +static virSysinfoDefPtr hostsysinfo = NULL; static virDomainDefPtr xenGetDomainDefForID(virConnectPtr conn, int id) { @@ -254,14 +255,25 @@ xenUnifiedStateInitialize(bool privileged, void *opaque ATTRIBUTE_UNUSED) { /* Don't allow driver to work in non-root libvirtd */ - if (privileged) + if (privileged) { is_privileged = true; + hostsysinfo = virSysinfoRead(); + } + + return 0; +} + +static int +xenUnifiedStateCleanup(void) +{ + virSysinfoDefFree(hostsysinfo); return 0; } static virStateDriver state_driver = { .name = "Xen", .stateInitialize = xenUnifiedStateInitialize, + .stateCleanup = xenUnifiedStateCleanup, }; /*----- Dispatch functions. -----*/ @@ -572,6 +584,28 @@ static char *xenUnifiedConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED) return virGetHostname(); } +static char * +xenUnifiedConnectGetSysinfo(virConnectPtr conn ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virCheckFlags(0, NULL); + + if (!hostsysinfo) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Host SMBIOS information is not available")); + return NULL; + } + + if (virSysinfoFormat(&buf, hostsysinfo) < 0) + return NULL; + if (virBufferError(&buf)) { + virReportOOMError(); + return NULL; + } + return virBufferContentAndReset(&buf); +} static int xenUnifiedConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) @@ -2437,6 +2471,7 @@ static virDriver xenUnifiedDriver = { .connectGetType = xenUnifiedConnectGetType, /* 0.0.3 */ .connectGetVersion = xenUnifiedConnectGetVersion, /* 0.0.3 */ .connectGetHostname = xenUnifiedConnectGetHostname, /* 0.7.3 */ + .connectGetSysinfo = xenUnifiedConnectGetSysinfo, /* 1.0.7 */ .connectGetMaxVcpus = xenUnifiedConnectGetMaxVcpus, /* 0.2.1 */ .nodeGetInfo = xenUnifiedNodeGetInfo, /* 0.1.0 */ .connectGetCapabilities = xenUnifiedConnectGetCapabilities, /* 0.2.1 */ -- 1.7.7

Jim Fehlig wrote:
While discussing a recent libxl patch, we realized virConnectGetSysinfo was never implemented in the libxl and legacy xen drivers. This small series provides an implementation for these drivers.
I'll need to update the version to 1.1.0, but otherwise any comment on this series? It's rather trivial. Regards, Jim
Jim Fehlig (2): libxl: Implement virConnectGetSysinfo xen: Implement virConnectGetSysinfo
src/libxl/libxl_conf.h | 1 + src/libxl/libxl_driver.c | 29 +++++++++++++++++++++++++++++ src/xen/xen_driver.c | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletions(-)

On Fri, Jun 21, 2013 at 10:40:31AM -0600, Jim Fehlig wrote:
Jim Fehlig wrote:
While discussing a recent libxl patch, we realized virConnectGetSysinfo was never implemented in the libxl and legacy xen drivers. This small series provides an implementation for these drivers.
I'll need to update the version to 1.1.0, but otherwise any comment on this series? It's rather trivial.
ACK to both - they're exactly the same as the QEMU / LXC impls, which is a fine starting point. 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 :|

Daniel P. Berrange wrote:
On Fri, Jun 21, 2013 at 10:40:31AM -0600, Jim Fehlig wrote:
Jim Fehlig wrote:
While discussing a recent libxl patch, we realized virConnectGetSysinfo was never implemented in the libxl and legacy xen drivers. This small series provides an implementation for these drivers.
I'll need to update the version to 1.1.0, but otherwise any comment on this series? It's rather trivial.
ACK to both - they're exactly the same as the QEMU / LXC impls, which is a fine starting point.
Thanks, pushed. Regards, Jim
participants (2)
-
Daniel P. Berrange
-
Jim Fehlig