[libvirt] [PATCH 0/6] sysinfo: expose host <sysinfo> data from virsh

First requested here: https://www.redhat.com/archives/libvir-list/2011-January/msg00889.html and useful enough that I coded it in one day, hopefully to be in time for the 0.8.8 feature freeze :) Food for thought - right now, only qemu supports this. Should I do a followup patch that moves hostsysinfo out of qemu_conf.h and into src/datatypes.h virConnect instead, as well as some utility routines that make it easier for all hypervisors to choose to cache sysinfo data (if privileged)? Compare to how many (but not all) hypervisors share util.c virGetHostname rather than duplicating the work. Eric Blake (6): sysinfo: expose new API sysinfo: define internal driver API sysinfo: implement the public API sysinfo: implement the remote protocol sysinfo: implement virsh support sysinfo: implement qemu support daemon/remote.c | 25 +++++++- daemon/remote_dispatch_args.h | 1 + daemon/remote_dispatch_prototypes.h | 8 ++ daemon/remote_dispatch_ret.h | 1 + daemon/remote_dispatch_table.h | 5 ++ docs/formatdomain.html.in | 4 +- include/libvirt/libvirt.h.in | 4 +- src/conf/domain_conf.c | 71 +------------------- src/driver.h | 4 + src/esx/esx_driver.c | 3 +- src/libvirt.c | 42 +++++++++++- src/libvirt_private.syms | 1 + src/libvirt_public.syms | 5 ++ src/lxc/lxc_driver.c | 1 + src/opennebula/one_driver.c | 3 +- src/openvz/openvz_driver.c | 3 +- src/phyp/phyp_driver.c | 3 +- src/qemu/qemu_driver.c | 17 +++++ src/remote/remote_driver.c | 28 ++++++++- src/remote/remote_protocol.c | 18 +++++ src/remote/remote_protocol.h | 15 ++++ src/remote/remote_protocol.x | 13 +++- src/remote_protocol-structs | 6 ++ src/test/test_driver.c | 3 +- src/uml/uml_driver.c | 1 + src/util/sysinfo.c | 125 ++++++++++++++++++++++++++++++++++- src/util/sysinfo.h | 5 +- src/vbox/vbox_tmpl.c | 1 + src/vmware/vmware_driver.c | 5 +- src/xen/xen_driver.c | 1 + src/xenapi/xenapi_driver.c | 2 + tools/virsh.c | 33 +++++++++- tools/virsh.pod | 5 ++ 33 files changed, 377 insertions(+), 85 deletions(-) -- 1.7.4

* include/libvirt/libvirt.h.in (virConnectGetSysinfo): Declare. * src/libvirt_public.syms: Export new symbol. --- I don't know how the flags argument might be used, if ever, but better safe than sorry :) include/libvirt/libvirt.h.in | 4 +++- src/libvirt_public.syms | 5 +++++ 2 files changed, 8 insertions(+), 1 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 7ecbeb6..3913a28 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -4,7 +4,7 @@ * Description: Provides the interfaces of the libvirt library to handle * virtualized domains * - * Copy: Copyright (C) 2005,2006,2010 Red Hat, Inc. + * Copy: Copyright (C) 2005-2006 2010-2011 Red Hat, Inc. * * See COPYING.LIB for the License of this software * @@ -575,6 +575,8 @@ int virConnectGetLibVersion (virConnectPtr conn, unsigned long *libVer); char * virConnectGetHostname (virConnectPtr conn); char * virConnectGetURI (virConnectPtr conn); +char * virConnectGetSysinfo (virConnectPtr conn, + unsigned int flags); /* diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 96084ff..1a45be1 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -419,4 +419,9 @@ LIBVIRT_0.8.6 { virDomainIsUpdated; } LIBVIRT_0.8.5; +LIBVIRT_0.8.8 { + global: + virConnectGetSysinfo; +} LIBVIRT_0.8.6; + # .... define new API here using predicted next version number .... -- 1.7.4

On Mon, Feb 07, 2011 at 05:08:45PM -0700, Eric Blake wrote:
* include/libvirt/libvirt.h.in (virConnectGetSysinfo): Declare. * src/libvirt_public.syms: Export new symbol. ---
I don't know how the flags argument might be used, if ever, but better safe than sorry :)
include/libvirt/libvirt.h.in | 4 +++- src/libvirt_public.syms | 5 +++++ 2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 7ecbeb6..3913a28 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -4,7 +4,7 @@ * Description: Provides the interfaces of the libvirt library to handle * virtualized domains * - * Copy: Copyright (C) 2005,2006,2010 Red Hat, Inc. + * Copy: Copyright (C) 2005-2006 2010-2011 Red Hat, Inc. * * See COPYING.LIB for the License of this software * @@ -575,6 +575,8 @@ int virConnectGetLibVersion (virConnectPtr conn, unsigned long *libVer); char * virConnectGetHostname (virConnectPtr conn); char * virConnectGetURI (virConnectPtr conn); +char * virConnectGetSysinfo (virConnectPtr conn, + unsigned int flags);
Agreed looks fine to me, it's a generally useful API, people don't like (rightfully) to write XML and we need a convenient way to extract this. The flags may be useful in the future to limit the amount of informations extracted, for example if we don't want the UUID exported or something similar, 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/

* src/driver.h (virDrvGetSysinfo): New typedef. (_virDriver): New callback member. * src/esx/esx_driver.c (esxDriver): Add stub for driver. * src/lxc/lxc_driver.c (lxcDriver): Likewise. * src/opennebula/one_driver.c (oneDriver): Likewise. * src/openvz/openvz_driver.c (openvzDriver): Likewise. * src/phyp/phyp_driver.c (phypDriver): Likewise. * src/qemu/qemu_driver.c (qemuDriver): Likewise. * src/remote/remote_driver.c (remote_driver): Likewise. * src/test/test_driver.c (testDriver): Likewise. * src/uml/uml_driver.c (umlDriver): Likewise. * src/vbox/vbox_tmpl.c (Driver): Likewise. * src/vmware/vmware_driver.c (vmwareDriver): Likewise. * src/xen/xen_driver.c (xenUnifiedDriver): Likewise. * src/xenapi/xenapi_driver.c (xenapiDriver): Likewise. --- src/driver.h | 4 ++++ src/esx/esx_driver.c | 3 ++- src/lxc/lxc_driver.c | 1 + src/opennebula/one_driver.c | 3 ++- src/openvz/openvz_driver.c | 3 ++- src/phyp/phyp_driver.c | 3 ++- src/qemu/qemu_driver.c | 1 + src/remote/remote_driver.c | 3 ++- src/test/test_driver.c | 3 ++- src/uml/uml_driver.c | 1 + src/vbox/vbox_tmpl.c | 1 + src/vmware/vmware_driver.c | 5 ++++- src/xen/xen_driver.c | 1 + src/xenapi/xenapi_driver.c | 2 ++ 14 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/driver.h b/src/driver.h index 114002d..7451004 100644 --- a/src/driver.h +++ b/src/driver.h @@ -83,6 +83,9 @@ typedef char * (*virDrvGetHostname) (virConnectPtr conn); typedef char * (*virDrvGetURI) (virConnectPtr conn); +typedef char * + (*virDrvGetSysinfo) (virConnectPtr conn, + unsigned int flags); typedef int (*virDrvGetMaxVcpus) (virConnectPtr conn, const char *type); @@ -515,6 +518,7 @@ struct _virDriver { virDrvGetVersion version; virDrvGetLibVersion libvirtVersion; virDrvGetHostname getHostname; + virDrvGetSysinfo getSysinfo; virDrvGetMaxVcpus getMaxVcpus; virDrvNodeGetInfo nodeGetInfo; virDrvGetCapabilities getCapabilities; diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index c66df0e..97f3dbe 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -2,7 +2,7 @@ /* * esx_driver.c: core driver functions for managing VMware ESX hosts * - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010-2011 Red Hat, Inc. * Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte@googlemail.com> * Copyright (C) 2009 Maximilian Wilhelm <max@rfc2324.org> * @@ -4557,6 +4557,7 @@ static virDriver esxDriver = { esxGetVersion, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ esxGetHostname, /* hostname */ + NULL, /* getSysinfo */ NULL, /* getMaxVcpus */ esxNodeGetInfo, /* nodeGetInfo */ esxGetCapabilities, /* getCapabilities */ diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 2e8a845..0f78579 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2833,6 +2833,7 @@ static virDriver lxcDriver = { lxcVersion, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ virGetHostname, /* getHostname */ + NULL, /* getSysinfo */ NULL, /* getMaxVcpus */ nodeGetInfo, /* nodeGetInfo */ lxcGetCapabilities, /* getCapabilities */ diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c index 6945f91..75d7b9a 100644 --- a/src/opennebula/one_driver.c +++ b/src/opennebula/one_driver.c @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------*/ /* - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010-2011 Red Hat, Inc. * Copyright 2002-2009, Distributed Systems Architecture Group, Universidad * Complutense de Madrid (dsa-research.org) * @@ -732,6 +732,7 @@ static virDriver oneDriver = { oneVersion, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ NULL, /* getHostname */ + NULL, /* getSysinfo */ NULL, /* getMaxVcpus */ NULL, /* nodeGetInfo */ oneGetCapabilities, /* getCapabilities */ diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 1dde004..00d378a 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1,7 +1,7 @@ /* * openvz_driver.c: core driver methods for managing OpenVZ VEs * - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010-2011 Red Hat, Inc. * Copyright (C) 2006, 2007 Binary Karma * Copyright (C) 2006 Shuveb Hussain * Copyright (C) 2007 Anoop Joe Cyriac @@ -1572,6 +1572,7 @@ static virDriver openvzDriver = { openvzGetVersion, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ NULL, /* getHostname */ + NULL, /* getSysinfo */ openvzGetMaxVCPUs, /* getMaxVcpus */ nodeGetInfo, /* nodeGetInfo */ openvzGetCapabilities, /* getCapabilities */ diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 3508891..d954f2a 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010-2011 Red Hat, Inc. * Copyright IBM Corp. 2009 * * phyp_driver.c: ssh layer to access Power Hypervisors @@ -3954,6 +3954,7 @@ static virDriver phypDriver = { NULL, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ NULL, /* getHostname */ + NULL, /* getSysinfo */ NULL, /* getMaxVcpus */ NULL, /* nodeGetInfo */ phypConnectGetCapabilities, /* getCapabilities */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b936735..87d228b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10375,6 +10375,7 @@ static virDriver qemuDriver = { qemudGetVersion, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ virGetHostname, /* getHostname */ + NULL, /* getSysinfo */ qemudGetMaxVCPUs, /* getMaxVcpus */ nodeGetInfo, /* nodeGetInfo */ qemudGetCapabilities, /* getCapabilities */ diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 8bae697..1d9209d 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -2,7 +2,7 @@ * remote_internal.c: driver to provide access to libvirtd running * on a remote machine * - * Copyright (C) 2007-2010 Red Hat, Inc. + * Copyright (C) 2007-2011 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -10823,6 +10823,7 @@ static virDriver remote_driver = { remoteGetVersion, /* version */ remoteGetLibVersion, /* libvirtVersion */ remoteGetHostname, /* getHostname */ + NULL, /* getSysinfo */ remoteGetMaxVcpus, /* getMaxVcpus */ remoteNodeGetInfo, /* nodeGetInfo */ remoteGetCapabilities, /* getCapabilities */ diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 15e90c8..1937da0 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1,7 +1,7 @@ /* * test.c: A "mock" hypervisor for use by application unit tests * - * Copyright (C) 2006-2010 Red Hat, Inc. + * Copyright (C) 2006-2011 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -5346,6 +5346,7 @@ static virDriver testDriver = { testGetVersion, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ virGetHostname, /* getHostname */ + NULL, /* getSysinfo */ testGetMaxVCPUs, /* getMaxVcpus */ testNodeGetInfo, /* nodeGetInfo */ testGetCapabilities, /* getCapabilities */ diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index d248b45..2af8002 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -2148,6 +2148,7 @@ static virDriver umlDriver = { umlGetVersion, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ virGetHostname, /* getHostname */ + NULL, /* getSysinfo */ NULL, /* getMaxVcpus */ nodeGetInfo, /* nodeGetInfo */ umlGetCapabilities, /* getCapabilities */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index b5cde1f..cf3cbc6 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -8537,6 +8537,7 @@ virDriver NAME(Driver) = { vboxGetVersion, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ virGetHostname, /* getHostname */ + NULL, /* getSysinfo */ vboxGetMaxVcpus, /* getMaxVcpus */ nodeGetInfo, /* nodeGetInfo */ vboxGetCapabilities, /* getCapabilities */ diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index f176c2f..22b29d1 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -1,5 +1,7 @@ /*---------------------------------------------------------------------------*/ -/* Copyright 2010, diateam (www.diateam.net) +/* + * Copyright (C) 2011 Red Hat, Inc. + * Copyright 2010, diateam (www.diateam.net) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -906,6 +908,7 @@ static virDriver vmwareDriver = { vmwareGetVersion, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ NULL, /* getHostname */ + NULL, /* getSysinfo */ NULL, /* getMaxVcpus */ NULL, /* nodeGetInfo */ NULL, /* getCapabilities */ diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index f3613f0..b14c8db 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -2004,6 +2004,7 @@ static virDriver xenUnifiedDriver = { xenUnifiedGetVersion, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ virGetHostname, /* getHostname */ + NULL, /* getSysinfo */ xenUnifiedGetMaxVcpus, /* getMaxVcpus */ xenUnifiedNodeGetInfo, /* nodeGetInfo */ xenUnifiedGetCapabilities, /* getCapabilities */ diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index aac112b..7851e93 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -1,5 +1,6 @@ /* * xenapi_driver.c: Xen API driver. + * Copyright (C) 2011 Red Hat, Inc. * Copyright (C) 2009, 2010 Citrix Ltd. * * This library is free software; you can redistribute it and/or @@ -1783,6 +1784,7 @@ static virDriver xenapiDriver = { xenapiGetVersion, /* version */ NULL, /*getlibvirtVersion */ xenapiGetHostname, /* getHostname */ + NULL, /* getSysinfo */ xenapiGetMaxVcpus, /* getMaxVcpus */ xenapiNodeGetInfo, /* nodeGetInfo */ xenapiGetCapabilities, /* getCapabilities */ -- 1.7.4

* src/libvirt.c (virConnectGetSysinfo): New function. * docs/formatdomain.html.in: Mention it. --- Is my cross-page link in formatdomain correct? I didn't see any other examples of XML documentation linking to an API call. docs/formatdomain.html.in | 4 +++- src/libvirt.c | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 43c78fc..dd91de7 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -125,7 +125,9 @@ The <code>mode</code> attribute must be specified, and is either "emulate" (let the hypervisor generate all values), "host" (copy all of Block 0 and Block 1, except for the UUID, from the host's - SMBIOS values), or "sysinfo" (use the values in + SMBIOS values; the <a href="libvirt-libvirt.html#virConnectGetSysinfo"> + <code>virConnectGetSysinfo</code></a> call can be + used to see what values are copied), or "sysinfo" (use the values in the <a href="#elementsSysinfo">sysinfo</a> element). If not specified, the hypervisor default is used. <span class="since"> Since 0.8.7</span> diff --git a/src/libvirt.c b/src/libvirt.c index c65b1e5..479a9b5 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -776,7 +776,7 @@ virRegisterStateDriver(virStateDriverPtr driver) /** * virStateInitialize: - * @privileged: set to 1 if running with root priviledge, 0 otherwise + * @privileged: set to 1 if running with root privilege, 0 otherwise * * Initialize all virtualization drivers. * @@ -1594,6 +1594,46 @@ error: } /** + * virConnectGetSysinfo: + * @conn: pointer to a hypervisor connection + * @flags: callers should always pass 0 + * + * This returns the XML description of the sysinfo details for the + * host on which the hypervisor is running, in the same format as the + * <sysinfo> element of a domain XML. This information is generally + * available only for hypervisors running with root privileges. + * + * Returns the XML string which must be freed by the caller, or + * NULL if there was an error. + */ +char * +virConnectGetSysinfo (virConnectPtr conn, unsigned int flags) +{ + DEBUG("conn=%p", conn); + + virResetLastError(); + + if (!VIR_IS_CONNECT(conn)) { + virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__); + virDispatchError(NULL); + return NULL; + } + + if (conn->driver->getSysinfo) { + char *ret = conn->driver->getSysinfo (conn, flags); + if (!ret) + goto error; + return ret; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + virDispatchError(conn); + return NULL; +} + +/** * virConnectGetMaxVcpus: * @conn: pointer to the hypervisor connection * @type: value of the 'type' attribute in the <domain> element -- 1.7.4

On Mon, Feb 07, 2011 at 05:08:47PM -0700, Eric Blake wrote:
* src/libvirt.c (virConnectGetSysinfo): New function. * docs/formatdomain.html.in: Mention it. ---
Is my cross-page link in formatdomain correct? I didn't see any other examples of XML documentation linking to an API call.
docs/formatdomain.html.in | 4 +++- src/libvirt.c | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 43c78fc..dd91de7 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -125,7 +125,9 @@ The <code>mode</code> attribute must be specified, and is either "emulate" (let the hypervisor generate all values), "host" (copy all of Block 0 and Block 1, except for the UUID, from the host's - SMBIOS values), or "sysinfo" (use the values in + SMBIOS values; the <a href="libvirt-libvirt.html#virConnectGetSysinfo"> + <code>virConnectGetSysinfo</code></a> call can be + used to see what values are copied), or "sysinfo" (use the values in
Actually that should be <a href="html/libvirt-libvirt.html#virConnectGetSysinfo"> as the API pages are placed in an html subdir of the top documentation. That's true for both the web site and html installed witha devel package, once fixed, ACK, 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/

Done by editing the first three files, then running 'make -C src rpcgen', then editing src/remote_protocol-structs to match. * daemon/remote.c (remoteDispatchGetSysinfo): New function. * src/remote/remote_driver.c (remoteGetSysinfo, remote_driver): Client side serialization. * src/remote/remote_protocol.x (remote_get_sysinfo_args) (remote_get_sysinfo_ret): New types. (REMOTE_PROC_GET_SYSINFO): New enum value. * daemon/remote_dispatch_args.h: Regenerate. * daemon/remote_dispatch_prototypes.h: Likewise. * daemon/remote_dispatch_ret.h: Likewise. * daemon/remote_dispatch_table.h: Likewise. * src/remote/remote_protocol.c: Likewise. * src/remote/remote_protocol.h: Likewise. * src/remote_protocol-structs: Likewise. --- daemon/remote.c | 25 ++++++++++++++++++++++++- daemon/remote_dispatch_args.h | 1 + daemon/remote_dispatch_prototypes.h | 8 ++++++++ daemon/remote_dispatch_ret.h | 1 + daemon/remote_dispatch_table.h | 5 +++++ src/remote/remote_driver.c | 27 ++++++++++++++++++++++++++- src/remote/remote_protocol.c | 18 ++++++++++++++++++ src/remote/remote_protocol.h | 15 +++++++++++++++ src/remote/remote_protocol.x | 13 +++++++++++-- src/remote_protocol-structs | 6 ++++++ 10 files changed, 115 insertions(+), 4 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index aa6a1a4..de45ff9 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1,7 +1,7 @@ /* * remote.c: handlers for RPC method calls * - * Copyright (C) 2007-2010 Red Hat, Inc. + * Copyright (C) 2007-2011 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -585,6 +585,29 @@ remoteDispatchGetUri (struct qemud_server *server ATTRIBUTE_UNUSED, } static int +remoteDispatchGetSysinfo (struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *rerr, + remote_get_sysinfo_args *args, + remote_get_sysinfo_ret *ret) +{ + unsigned int flags; + char *sysinfo; + + flags = args->flags; + sysinfo = virConnectGetSysinfo (conn, flags); + if (sysinfo == NULL) { + remoteDispatchConnError(rerr, conn); + return -1; + } + + ret->sysinfo = sysinfo; + return 0; +} + +static int remoteDispatchGetMaxVcpus (struct qemud_server *server ATTRIBUTE_UNUSED, struct qemud_client *client ATTRIBUTE_UNUSED, virConnectPtr conn, diff --git a/daemon/remote_dispatch_args.h b/daemon/remote_dispatch_args.h index 221af88..57962d1 100644 --- a/daemon/remote_dispatch_args.h +++ b/daemon/remote_dispatch_args.h @@ -171,3 +171,4 @@ remote_domain_get_vcpus_flags_args val_remote_domain_get_vcpus_flags_args; remote_domain_open_console_args val_remote_domain_open_console_args; remote_domain_is_updated_args val_remote_domain_is_updated_args; + remote_get_sysinfo_args val_remote_get_sysinfo_args; diff --git a/daemon/remote_dispatch_prototypes.h b/daemon/remote_dispatch_prototypes.h index 4a5246f..e59701a 100644 --- a/daemon/remote_dispatch_prototypes.h +++ b/daemon/remote_dispatch_prototypes.h @@ -730,6 +730,14 @@ static int remoteDispatchGetMaxVcpus( remote_error *err, remote_get_max_vcpus_args *args, remote_get_max_vcpus_ret *ret); +static int remoteDispatchGetSysinfo( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + remote_get_sysinfo_args *args, + remote_get_sysinfo_ret *ret); static int remoteDispatchGetType( struct qemud_server *server, struct qemud_client *client, diff --git a/daemon/remote_dispatch_ret.h b/daemon/remote_dispatch_ret.h index c01f3ba..78e5469 100644 --- a/daemon/remote_dispatch_ret.h +++ b/daemon/remote_dispatch_ret.h @@ -138,3 +138,4 @@ remote_domain_get_memory_parameters_ret val_remote_domain_get_memory_parameters_ret; remote_domain_get_vcpus_flags_ret val_remote_domain_get_vcpus_flags_ret; remote_domain_is_updated_ret val_remote_domain_is_updated_ret; + remote_get_sysinfo_ret val_remote_get_sysinfo_ret; diff --git a/daemon/remote_dispatch_table.h b/daemon/remote_dispatch_table.h index 3e55424..5d27390 100644 --- a/daemon/remote_dispatch_table.h +++ b/daemon/remote_dispatch_table.h @@ -1017,3 +1017,8 @@ .args_filter = (xdrproc_t) xdr_remote_domain_is_updated_args, .ret_filter = (xdrproc_t) xdr_remote_domain_is_updated_ret, }, +{ /* GetSysinfo => 203 */ + .fn = (dispatch_fn) remoteDispatchGetSysinfo, + .args_filter = (xdrproc_t) xdr_remote_get_sysinfo_args, + .ret_filter = (xdrproc_t) xdr_remote_get_sysinfo_ret, +}, diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 1d9209d..c33a930 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1748,6 +1748,31 @@ done: return rv; } +static char * +remoteGetSysinfo (virConnectPtr conn, unsigned int flags) +{ + char *rv = NULL; + remote_get_sysinfo_args args; + remote_get_sysinfo_ret ret; + struct private_data *priv = conn->privateData; + + remoteDriverLock(priv); + + memset (&ret, 0, sizeof ret); + args.flags = flags; + if (call (conn, priv, 0, REMOTE_PROC_GET_SYSINFO, + (xdrproc_t) xdr_remote_get_sysinfo_args, (char *) &args, + (xdrproc_t) xdr_remote_get_sysinfo_ret, (char *) &ret) == -1) + goto done; + + /* Caller frees this. */ + rv = ret.sysinfo; + +done: + remoteDriverUnlock(priv); + return rv; +} + static int remoteIsSecure(virConnectPtr conn) { int rv = -1; @@ -10823,7 +10848,7 @@ static virDriver remote_driver = { remoteGetVersion, /* version */ remoteGetLibVersion, /* libvirtVersion */ remoteGetHostname, /* getHostname */ - NULL, /* getSysinfo */ + remoteGetSysinfo, /* getSysinfo */ remoteGetMaxVcpus, /* getMaxVcpus */ remoteNodeGetInfo, /* nodeGetInfo */ remoteGetCapabilities, /* getCapabilities */ diff --git a/src/remote/remote_protocol.c b/src/remote/remote_protocol.c index 6e07b70..bae92ca 100644 --- a/src/remote/remote_protocol.c +++ b/src/remote/remote_protocol.c @@ -420,6 +420,24 @@ xdr_remote_get_hostname_ret (XDR *xdrs, remote_get_hostname_ret *objp) } bool_t +xdr_remote_get_sysinfo_args (XDR *xdrs, remote_get_sysinfo_args *objp) +{ + + if (!xdr_u_int (xdrs, &objp->flags)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_get_sysinfo_ret (XDR *xdrs, remote_get_sysinfo_ret *objp) +{ + + if (!xdr_remote_nonnull_string (xdrs, &objp->sysinfo)) + return FALSE; + return TRUE; +} + +bool_t xdr_remote_get_uri_ret (XDR *xdrs, remote_get_uri_ret *objp) { diff --git a/src/remote/remote_protocol.h b/src/remote/remote_protocol.h index 4240963..46d526a 100644 --- a/src/remote/remote_protocol.h +++ b/src/remote/remote_protocol.h @@ -242,6 +242,16 @@ struct remote_get_hostname_ret { }; typedef struct remote_get_hostname_ret remote_get_hostname_ret; +struct remote_get_sysinfo_args { + u_int flags; +}; +typedef struct remote_get_sysinfo_args remote_get_sysinfo_args; + +struct remote_get_sysinfo_ret { + remote_nonnull_string sysinfo; +}; +typedef struct remote_get_sysinfo_ret remote_get_sysinfo_ret; + struct remote_get_uri_ret { remote_nonnull_string uri; }; @@ -2320,6 +2330,7 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_GET_VCPUS_FLAGS = 200, REMOTE_PROC_DOMAIN_OPEN_CONSOLE = 201, REMOTE_PROC_DOMAIN_IS_UPDATED = 202, + REMOTE_PROC_GET_SYSINFO = 203, }; typedef enum remote_procedure remote_procedure; @@ -2384,6 +2395,8 @@ extern bool_t xdr_remote_get_type_ret (XDR *, remote_get_type_ret*); extern bool_t xdr_remote_get_version_ret (XDR *, remote_get_version_ret*); extern bool_t xdr_remote_get_lib_version_ret (XDR *, remote_get_lib_version_ret*); extern bool_t xdr_remote_get_hostname_ret (XDR *, remote_get_hostname_ret*); +extern bool_t xdr_remote_get_sysinfo_args (XDR *, remote_get_sysinfo_args*); +extern bool_t xdr_remote_get_sysinfo_ret (XDR *, remote_get_sysinfo_ret*); extern bool_t xdr_remote_get_uri_ret (XDR *, remote_get_uri_ret*); extern bool_t xdr_remote_get_max_vcpus_args (XDR *, remote_get_max_vcpus_args*); extern bool_t xdr_remote_get_max_vcpus_ret (XDR *, remote_get_max_vcpus_ret*); @@ -2730,6 +2743,8 @@ extern bool_t xdr_remote_get_type_ret (); extern bool_t xdr_remote_get_version_ret (); extern bool_t xdr_remote_get_lib_version_ret (); extern bool_t xdr_remote_get_hostname_ret (); +extern bool_t xdr_remote_get_sysinfo_args (); +extern bool_t xdr_remote_get_sysinfo_ret (); extern bool_t xdr_remote_get_uri_ret (); extern bool_t xdr_remote_get_max_vcpus_args (); extern bool_t xdr_remote_get_max_vcpus_ret (); diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index e1981fd..e77aca1 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3,7 +3,7 @@ * remote_internal driver and libvirtd. This protocol is * internal and may change at any time. * - * Copyright (C) 2006-2010 Red Hat, Inc. + * Copyright (C) 2006-2011 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -379,6 +379,14 @@ struct remote_get_hostname_ret { remote_nonnull_string hostname; }; +struct remote_get_sysinfo_args { + unsigned int flags; +}; + +struct remote_get_sysinfo_ret { + remote_nonnull_string sysinfo; +}; + struct remote_get_uri_ret { remote_nonnull_string uri; }; @@ -2094,7 +2102,8 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_GET_VCPUS_FLAGS = 200, REMOTE_PROC_DOMAIN_OPEN_CONSOLE = 201, - REMOTE_PROC_DOMAIN_IS_UPDATED = 202 + REMOTE_PROC_DOMAIN_IS_UPDATED = 202, + REMOTE_PROC_GET_SYSINFO = 203 /* * Notice how the entries are grouped in sets of 10 ? diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 7ca968f..6a7f03d 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -107,6 +107,12 @@ struct remote_get_lib_version_ret { struct remote_get_hostname_ret { remote_nonnull_string hostname; }; +struct remote_get_sysinfo_args { + u_int flags; +}; +struct remote_get_sysinfo_ret { + remote_nonnull_string sysinfo; +}; struct remote_get_uri_ret { remote_nonnull_string uri; }; -- 1.7.4

* tools/virsh.c (cmdSysinfo): New function. (hostAndHypervisorCmds): Add it. * tools/virsh.pod: Document it. --- Implementing this before qemu support let me test the fallback cases. tools/virsh.c | 33 ++++++++++++++++++++++++++++++++- tools/virsh.pod | 5 +++++ 2 files changed, 37 insertions(+), 1 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 1f820e8..be2cd67 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -8223,7 +8223,7 @@ cmdNodeDeviceReset (vshControl *ctl, const vshCmd *cmd) } /* - * "hostkey" command + * "hostname" command */ static const vshCmdInfo info_hostname[] = { {"help", N_("print the hypervisor hostname")}, @@ -8281,6 +8281,36 @@ cmdURI (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) } /* + * "sysinfo" command + */ +static const vshCmdInfo info_sysinfo[] = { + {"help", N_("print the hypervisor sysinfo")}, + {"desc", + N_("output an XML string for the hypervisor sysinfo, if available")}, + {NULL, NULL} +}; + +static int +cmdSysinfo (vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) +{ + char *sysinfo; + + if (!vshConnectionUsability(ctl, ctl->conn)) + return FALSE; + + sysinfo = virConnectGetSysinfo (ctl->conn, 0); + if (sysinfo == NULL) { + vshError(ctl, "%s", _("failed to get sysinfo")); + return FALSE; + } + + vshPrint (ctl, "%s", sysinfo); + VIR_FREE(sysinfo); + + return TRUE; +} + +/* * "vncdisplay" command */ static const vshCmdInfo info_vncdisplay[] = { @@ -10417,6 +10447,7 @@ static const vshCmdDef hostAndHypervisorCmds[] = { {"hostname", cmdHostname, NULL, info_hostname}, {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo}, {"qemu-monitor-command", cmdQemuMonitorCommand, opts_qemu_monitor_command, info_qemu_monitor_command}, + {"sysinfo", cmdSysinfo, NULL, info_sysinfo}, {"uri", cmdURI, NULL, info_uri}, {NULL, NULL, NULL, NULL} }; diff --git a/tools/virsh.pod b/tools/virsh.pod index bfaa67e..a2ca384 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -132,6 +132,7 @@ group as an option. For example: freecell NUMA free memory hostname print the hypervisor hostname qemu-monitor-command Qemu Monitor Command + sysinfo print the hypervisor sysinfo uri print the hypervisor canonical URI To display detailed information for a specific command, give its name as the @@ -227,6 +228,10 @@ Prints the hypervisor canonical URI, can be useful in shell mode. Print the hypervisor hostname. +=item B<sysinfo> + +Print the XML representation of the hypervisor sysinfo, if available. + =item B<nodeinfo> Returns basic information about the node, like number and type of CPU, -- 1.7.4

* src/util/sysinfo.h (virSysinfoFormat): New prototype. * src/conf/domain_conf.c (virDomainSysinfoDefFormat): Move guts... * src/util/sysinfo.c (virSysinfoFormat): ...into new function. * src/libvirt_private.syms: Export it. * src/qemu/qemu_driver.c (qemuGetSysinfo): New function. (qemuDriver): Install it. --- Tested both with qemu:///system (works!) and qemu:///session (error: unsupported configuration: Host SMBIOS information is not available) The prefix hack is necessary so that I can use "" or " " as the leading indentation, depending on host sysinfo vs. domain, so it's not quite straight code motion. src/conf/domain_conf.c | 71 ++------------------------ src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 18 ++++++- src/util/sysinfo.c | 125 ++++++++++++++++++++++++++++++++++++++++++++- src/util/sysinfo.h | 5 ++- 5 files changed, 148 insertions(+), 72 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9369ed4..401aee7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7143,75 +7143,12 @@ static int virDomainSysinfoDefFormat(virBufferPtr buf, virSysinfoDefPtr def) { - const char *type = virDomainSysinfoTypeToString(def->type); + char *format = virSysinfoFormat(def, " "); - if (!type) { - virDomainReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected sysinfo type model %d"), - def->type); + if (!format) return -1; - } - - virBufferVSprintf(buf, " <sysinfo type='%s'>\n", type); - if ((def->bios_vendor != NULL) || (def->bios_version != NULL) || - (def->bios_date != NULL) || (def->bios_release != NULL)) { - virBufferAddLit(buf, " <bios>\n"); - if (def->bios_vendor != NULL) - virBufferEscapeString(buf, - " <entry name='vendor'>%s</entry>\n", - def->bios_vendor); - if (def->bios_version != NULL) - virBufferEscapeString(buf, - " <entry name='version'>%s</entry>\n", - def->bios_version); - if (def->bios_date != NULL) - virBufferEscapeString(buf, - " <entry name='date'>%s</entry>\n", - def->bios_date); - if (def->bios_release != NULL) - virBufferEscapeString(buf, - " <entry name='release'>%s</entry>\n", - def->bios_release); - virBufferAddLit(buf, " </bios>\n"); - } - if ((def->system_manufacturer != NULL) || (def->system_product != NULL) || - (def->system_version != NULL) || (def->system_serial != NULL) || - (def->system_uuid != NULL) || (def->system_sku != NULL) || - (def->system_family != NULL)) { - virBufferAddLit(buf, " <system>\n"); - if (def->system_manufacturer != NULL) - virBufferEscapeString(buf, - " <entry name='manufacturer'>%s</entry>\n", - def->system_manufacturer); - if (def->system_product != NULL) - virBufferEscapeString(buf, - " <entry name='product'>%s</entry>\n", - def->system_product); - if (def->system_version != NULL) - virBufferEscapeString(buf, - " <entry name='version'>%s</entry>\n", - def->system_version); - if (def->system_serial != NULL) - virBufferEscapeString(buf, - " <entry name='serial'>%s</entry>\n", - def->system_serial); - if (def->system_uuid != NULL) - virBufferEscapeString(buf, - " <entry name='uuid'>%s</entry>\n", - def->system_uuid); - if (def->system_sku != NULL) - virBufferEscapeString(buf, - " <entry name='sku'>%s</entry>\n", - def->system_sku); - if (def->system_family != NULL) - virBufferEscapeString(buf, - " <entry name='family'>%s</entry>\n", - def->system_family); - virBufferAddLit(buf, " </system>\n"); - } - - virBufferAddLit(buf, " </sysinfo>\n"); - + virBufferAdd(buf, format, strlen(format)); + VIR_FREE(format); return 0; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 88e270c..6348e0d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -798,6 +798,7 @@ virStorageFileProbeFormatFromFD; # sysinfo.h virSysinfoDefFree; +virSysinfoFormat; virSysinfoRead; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 87d228b..52ea98e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3275,6 +3275,22 @@ static int kvmGetMaxVCPUs(void) { } +static char * +qemuGetSysinfo(virConnectPtr conn, unsigned int flags) +{ + struct qemud_driver *driver = conn->privateData; + + virCheckFlags(0, NULL); + + if (!driver->hostsysinfo) { + qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Host SMBIOS information is not available")); + return NULL; + } + + return virSysinfoFormat(driver->hostsysinfo, ""); +} + static int qemudGetMaxVCPUs(virConnectPtr conn ATTRIBUTE_UNUSED, const char *type) { if (!type) return 16; @@ -10375,7 +10391,7 @@ static virDriver qemuDriver = { qemudGetVersion, /* version */ NULL, /* libvirtVersion (impl. in libvirt.c) */ virGetHostname, /* getHostname */ - NULL, /* getSysinfo */ + qemuGetSysinfo, /* getSysinfo */ qemudGetMaxVCPUs, /* getMaxVcpus */ nodeGetInfo, /* nodeGetInfo */ qemudGetCapabilities, /* getCapabilities */ diff --git a/src/util/sysinfo.c b/src/util/sysinfo.c index 48ab267..2b764ae 100644 --- a/src/util/sysinfo.c +++ b/src/util/sysinfo.c @@ -1,7 +1,7 @@ /* * sysinfo.c: get SMBIOS/sysinfo information from the host * - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010-2011 Red Hat, Inc. * Copyright (C) 2010 Daniel Veillard * * This library is free software; you can redistribute it and/or @@ -91,7 +91,18 @@ virSysinfoRead(void) { _("Host sysinfo extraction not supported on this platform")); return NULL; } -#else + +char * +virSysinfoFormat(virSysinfoDefPtr def ATTRIBUTE_UNUSED, + const char *prefix ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Host sysinfo extraction not supported on this platform")); + return NULL; +} + +#else /* !WIN32 */ + virSysinfoDefPtr virSysinfoRead(void) { char *path, *cur, *eol, *base; @@ -207,4 +218,112 @@ no_memory: ret = NULL; goto cleanup; } -#endif + +/** + * virSysinfoFormat: + * @def: structure to convert to xml string + * @prefix: string to prefix before each line of xml + * + * This returns the XML description of the sysinfo, or NULL after + * generating an error message. + */ +char * +virSysinfoFormat(virSysinfoDefPtr def, const char *prefix) +{ + const char *type = virDomainSysinfoTypeToString(def->type); + virBuffer buf = VIR_BUFFER_INITIALIZER; + size_t len = strlen(prefix); + + if (!type) { + virSmbiosReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected sysinfo type model %d"), + def->type); + return NULL; + } + + virBufferVSprintf(&buf, "%s<sysinfo type='%s'>\n", prefix, type); + if ((def->bios_vendor != NULL) || (def->bios_version != NULL) || + (def->bios_date != NULL) || (def->bios_release != NULL)) { + virBufferVSprintf(&buf, "%s <bios>\n", prefix); + if (def->bios_vendor != NULL) { + virBufferAdd(&buf, prefix, len); + virBufferEscapeString(&buf, + " <entry name='vendor'>%s</entry>\n", + def->bios_vendor); + } + if (def->bios_version != NULL) { + virBufferAdd(&buf, prefix, len); + virBufferEscapeString(&buf, + " <entry name='version'>%s</entry>\n", + def->bios_version); + } + if (def->bios_date != NULL) { + virBufferAdd(&buf, prefix, len); + virBufferEscapeString(&buf, + " <entry name='date'>%s</entry>\n", + def->bios_date); + } + if (def->bios_release != NULL) { + virBufferAdd(&buf, prefix, len); + virBufferEscapeString(&buf, + " <entry name='release'>%s</entry>\n", + def->bios_release); + } + virBufferVSprintf(&buf, "%s </bios>\n", prefix); + } + if ((def->system_manufacturer != NULL) || (def->system_product != NULL) || + (def->system_version != NULL) || (def->system_serial != NULL) || + (def->system_uuid != NULL) || (def->system_sku != NULL) || + (def->system_family != NULL)) { + virBufferVSprintf(&buf, "%s <system>\n", prefix); + if (def->system_manufacturer != NULL) { + virBufferAdd(&buf, prefix, len); + virBufferEscapeString(&buf, + " <entry name='manufacturer'>%s</entry>\n", + def->system_manufacturer); + } + if (def->system_product != NULL) { + virBufferAdd(&buf, prefix, len); + virBufferEscapeString(&buf, + " <entry name='product'>%s</entry>\n", + def->system_product); + } + if (def->system_version != NULL) { + virBufferAdd(&buf, prefix, len); + virBufferEscapeString(&buf, + " <entry name='version'>%s</entry>\n", + def->system_version); + } + if (def->system_serial != NULL) { + virBufferAdd(&buf, prefix, len); + virBufferEscapeString(&buf, + " <entry name='serial'>%s</entry>\n", + def->system_serial); + } + if (def->system_uuid != NULL) { + virBufferAdd(&buf, prefix, len); + virBufferEscapeString(&buf, + " <entry name='uuid'>%s</entry>\n", + def->system_uuid); + } + if (def->system_sku != NULL) { + virBufferAdd(&buf, prefix, len); + virBufferEscapeString(&buf, + " <entry name='sku'>%s</entry>\n", + def->system_sku); + } + if (def->system_family != NULL) { + virBufferAdd(&buf, prefix, len); + virBufferEscapeString(&buf, + " <entry name='family'>%s</entry>\n", + def->system_family); + } + virBufferVSprintf(&buf, "%s </system>\n", prefix); + } + + virBufferVSprintf(&buf, "%s</sysinfo>\n", prefix); + + return virBufferContentAndReset(&buf); +} + +#endif /* !WIN32 */ diff --git a/src/util/sysinfo.h b/src/util/sysinfo.h index 1af7ef6..66a59db 100644 --- a/src/util/sysinfo.h +++ b/src/util/sysinfo.h @@ -1,7 +1,7 @@ /* * sysinfo.h: structure and entry points for sysinfo support * - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010-2011 Red Hat, Inc. * Copyright (C) 2010 Daniel Veillard * * This library is free software; you can redistribute it and/or @@ -56,4 +56,7 @@ virSysinfoDefPtr virSysinfoRead(void); void virSysinfoDefFree(virSysinfoDefPtr def); +char *virSysinfoFormat(virSysinfoDefPtr def, const char *prefix) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + #endif /* __VIR_SYSINFOS_H__ */ -- 1.7.4

On Mon, Feb 07, 2011 at 05:08:50PM -0700, Eric Blake wrote:
* src/util/sysinfo.h (virSysinfoFormat): New prototype. * src/conf/domain_conf.c (virDomainSysinfoDefFormat): Move guts... * src/util/sysinfo.c (virSysinfoFormat): ...into new function. * src/libvirt_private.syms: Export it. * src/qemu/qemu_driver.c (qemuGetSysinfo): New function. (qemuDriver): Install it. ---
Tested both with qemu:///system (works!) and qemu:///session (error: unsupported configuration: Host SMBIOS information is not available)
The prefix hack is necessary so that I can use "" or " " as the leading indentation, depending on host sysinfo vs. domain, so it's not quite straight code motion.
Yeah, the only unfortunate thing is that if people want to reuse the output they will have to reindent (well not strictly needed, just nicer). but it's better to generate a nice output. on input formatting is ignored anyway ! ACK, 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 Mon, Feb 07, 2011 at 05:08:44PM -0700, Eric Blake wrote:
First requested here: https://www.redhat.com/archives/libvir-list/2011-January/msg00889.html
and useful enough that I coded it in one day, hopefully to be in time for the 0.8.8 feature freeze :)
Food for thought - right now, only qemu supports this. Should I do a followup patch that moves hostsysinfo out of qemu_conf.h and into src/datatypes.h virConnect instead, as well as some utility routines that make it easier for all hypervisors to choose to cache sysinfo data (if privileged)? Compare to how many (but not all) hypervisors share util.c virGetHostname rather than duplicating the work.
Yes I think we can do that small reorg, but as a separate step after 0.8.8 is out. ACK for me with the few small nits changed 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 02/08/2011 07:36 PM, Daniel Veillard wrote:
On Mon, Feb 07, 2011 at 05:08:44PM -0700, Eric Blake wrote:
First requested here: https://www.redhat.com/archives/libvir-list/2011-January/msg00889.html
and useful enough that I coded it in one day, hopefully to be in time for the 0.8.8 feature freeze :)
Food for thought - right now, only qemu supports this. Should I do a followup patch that moves hostsysinfo out of qemu_conf.h and into src/datatypes.h virConnect instead, as well as some utility routines that make it easier for all hypervisors to choose to cache sysinfo data (if privileged)? Compare to how many (but not all) hypervisors share util.c virGetHostname rather than duplicating the work.
Yes I think we can do that small reorg, but as a separate step after 0.8.8 is out. ACK for me with the few small nits changed
Thanks; series pushed. (Actually, I also split patch 6 into two - the domain_conf formatting change, vs. qemu using that change; that way, if we ever add future smbios entries, backporting just the formatting of those new entries will not drag in API changes; on my radar is adding support for the block 3 Asset Tag entry.) -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Daniel Veillard
-
Eric Blake