mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
snapshot: simplify indentation of sysinfo
The improvements to virBuffer, along with a paradigm shift to pass the original buffer through rather than creating a second buffer, allow us to shave off quite a few lines of code. * src/util/sysinfo.h (virSysinfoFormat): Alter signature. * src/util/sysinfo.c (virSysinfoFormat, virSysinfoBIOSFormat) (virSysinfoSystemFormat, virSysinfoProcessorFormat) (virSysinfoMemoryFormat): Change indentation parameter. * src/conf/domain_conf.c (virDomainSysinfoDefFormat): Adjust caller. * src/qemu/qemu_driver.c (qemuGetSysinfo): Likewise.
This commit is contained in:
parent
27b3b303d9
commit
9a220665e7
@ -9973,13 +9973,11 @@ static int
|
|||||||
virDomainSysinfoDefFormat(virBufferPtr buf,
|
virDomainSysinfoDefFormat(virBufferPtr buf,
|
||||||
virSysinfoDefPtr def)
|
virSysinfoDefPtr def)
|
||||||
{
|
{
|
||||||
char *format = virSysinfoFormat(def, " ");
|
int ret;
|
||||||
|
virBufferAdjustIndent(buf, 2);
|
||||||
if (!format)
|
ret = virSysinfoFormat(buf, def);
|
||||||
return -1;
|
virBufferAdjustIndent(buf, -2);
|
||||||
virBufferAdd(buf, format, strlen(format));
|
return ret;
|
||||||
VIR_FREE(format);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -967,6 +967,7 @@ static char *
|
|||||||
qemuGetSysinfo(virConnectPtr conn, unsigned int flags)
|
qemuGetSysinfo(virConnectPtr conn, unsigned int flags)
|
||||||
{
|
{
|
||||||
struct qemud_driver *driver = conn->privateData;
|
struct qemud_driver *driver = conn->privateData;
|
||||||
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
virCheckFlags(0, NULL);
|
virCheckFlags(0, NULL);
|
||||||
|
|
||||||
@ -976,7 +977,13 @@ qemuGetSysinfo(virConnectPtr conn, unsigned int flags)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return virSysinfoFormat(driver->hostsysinfo, "");
|
if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0)
|
||||||
|
return NULL;
|
||||||
|
if (virBufferError(&buf)) {
|
||||||
|
virReportOOMError();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return virBufferContentAndReset(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudGetMaxVCPUs(virConnectPtr conn ATTRIBUTE_UNUSED, const char *type) {
|
static int qemudGetMaxVCPUs(virConnectPtr conn ATTRIBUTE_UNUSED, const char *type) {
|
||||||
|
@ -515,324 +515,189 @@ no_memory:
|
|||||||
#endif /* !WIN32 && x86 */
|
#endif /* !WIN32 && x86 */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virSysinfoBIOSFormat(virSysinfoDefPtr def, const char *prefix,
|
virSysinfoBIOSFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||||
virBufferPtr buf)
|
|
||||||
{
|
{
|
||||||
int len = strlen(prefix);
|
if (!def->bios_vendor && !def->bios_version &&
|
||||||
|
!def->bios_date && !def->bios_release)
|
||||||
|
return;
|
||||||
|
|
||||||
if ((def->bios_vendor != NULL) || (def->bios_version != NULL) ||
|
virBufferAddLit(buf, " <bios>\n");
|
||||||
(def->bios_date != NULL) || (def->bios_release != NULL)) {
|
virBufferEscapeString(buf, " <entry name='vendor'>%s</entry>\n",
|
||||||
virBufferAsprintf(buf, "%s <bios>\n", prefix);
|
def->bios_vendor);
|
||||||
if (def->bios_vendor != NULL) {
|
virBufferEscapeString(buf, " <entry name='version'>%s</entry>\n",
|
||||||
virBufferAdd(buf, prefix, len);
|
def->bios_version);
|
||||||
virBufferEscapeString(buf,
|
virBufferEscapeString(buf, " <entry name='date'>%s</entry>\n",
|
||||||
" <entry name='vendor'>%s</entry>\n",
|
def->bios_date);
|
||||||
def->bios_vendor);
|
virBufferEscapeString(buf, " <entry name='release'>%s</entry>\n",
|
||||||
}
|
def->bios_release);
|
||||||
if (def->bios_version != NULL) {
|
virBufferAddLit(buf, " </bios>\n");
|
||||||
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);
|
|
||||||
}
|
|
||||||
virBufferAsprintf(buf, "%s </bios>\n", prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virSysinfoSystemFormat(virSysinfoDefPtr def, const char *prefix,
|
virSysinfoSystemFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||||
virBufferPtr buf)
|
|
||||||
{
|
{
|
||||||
int len = strlen(prefix);
|
if (!def->system_manufacturer && !def->system_product &&
|
||||||
|
!def->system_version && !def->system_serial &&
|
||||||
|
!def->system_uuid && !def->system_sku && !def->system_family)
|
||||||
|
return;
|
||||||
|
|
||||||
if ((def->system_manufacturer != NULL) || (def->system_product != NULL) ||
|
virBufferAddLit(buf, " <system>\n");
|
||||||
(def->system_version != NULL) || (def->system_serial != NULL) ||
|
virBufferEscapeString(buf, " <entry name='manufacturer'>%s</entry>\n",
|
||||||
(def->system_uuid != NULL) || (def->system_sku != NULL) ||
|
def->system_manufacturer);
|
||||||
(def->system_family != NULL)) {
|
virBufferEscapeString(buf, " <entry name='product'>%s</entry>\n",
|
||||||
virBufferAsprintf(buf, "%s <system>\n", prefix);
|
def->system_product);
|
||||||
if (def->system_manufacturer != NULL) {
|
virBufferEscapeString(buf, " <entry name='version'>%s</entry>\n",
|
||||||
virBufferAdd(buf, prefix, len);
|
def->system_version);
|
||||||
virBufferEscapeString(buf,
|
virBufferEscapeString(buf, " <entry name='serial'>%s</entry>\n",
|
||||||
" <entry name='manufacturer'>%s</entry>\n",
|
def->system_serial);
|
||||||
def->system_manufacturer);
|
virBufferEscapeString(buf, " <entry name='uuid'>%s</entry>\n",
|
||||||
}
|
def->system_uuid);
|
||||||
if (def->system_product != NULL) {
|
virBufferEscapeString(buf, " <entry name='sku'>%s</entry>\n",
|
||||||
virBufferAdd(buf, prefix, len);
|
def->system_sku);
|
||||||
virBufferEscapeString(buf,
|
virBufferEscapeString(buf, " <entry name='family'>%s</entry>\n",
|
||||||
" <entry name='product'>%s</entry>\n",
|
def->system_family);
|
||||||
def->system_product);
|
virBufferAddLit(buf, " </system>\n");
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
virBufferAsprintf(buf, "%s </system>\n", prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virSysinfoProcessorFormat(virSysinfoDefPtr def, const char *prefix,
|
virSysinfoProcessorFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||||
virBufferPtr buf)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int len = strlen(prefix);
|
|
||||||
virSysinfoProcessorDefPtr processor;
|
virSysinfoProcessorDefPtr processor;
|
||||||
|
|
||||||
for (i = 0; i < def->nprocessor; i++) {
|
for (i = 0; i < def->nprocessor; i++) {
|
||||||
processor = &def->processor[i];
|
processor = &def->processor[i];
|
||||||
|
|
||||||
if ((processor->processor_socket_destination != NULL) ||
|
if (!processor->processor_socket_destination &&
|
||||||
(processor->processor_type != NULL) ||
|
!processor->processor_type &&
|
||||||
(processor->processor_family != NULL) ||
|
!processor->processor_family &&
|
||||||
(processor->processor_manufacturer != NULL) ||
|
!processor->processor_manufacturer &&
|
||||||
(processor->processor_signature != NULL) ||
|
!processor->processor_signature &&
|
||||||
(processor->processor_version != NULL) ||
|
!processor->processor_version &&
|
||||||
(processor->processor_external_clock != NULL) ||
|
!processor->processor_external_clock &&
|
||||||
(processor->processor_max_speed != NULL) ||
|
!processor->processor_max_speed &&
|
||||||
(processor->processor_status != NULL) ||
|
!processor->processor_status &&
|
||||||
(processor->processor_serial_number != NULL) ||
|
!processor->processor_serial_number &&
|
||||||
(processor->processor_part_number != NULL)) {
|
!processor->processor_part_number)
|
||||||
virBufferAsprintf(buf, "%s <processor>\n", prefix);
|
continue;
|
||||||
if (processor->processor_socket_destination != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='socket_destination'>%s</entry>\n",
|
|
||||||
processor->processor_socket_destination);
|
|
||||||
}
|
|
||||||
if (processor->processor_type != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='type'>%s</entry>\n",
|
|
||||||
processor->processor_type);
|
|
||||||
}
|
|
||||||
if (processor->processor_family != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='family'>%s</entry>\n",
|
|
||||||
processor->processor_family);
|
|
||||||
}
|
|
||||||
if (processor->processor_manufacturer != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='manufacturer'>%s</entry>\n",
|
|
||||||
processor->processor_manufacturer);
|
|
||||||
}
|
|
||||||
if (processor->processor_signature != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='signature'>%s</entry>\n",
|
|
||||||
processor->processor_signature);
|
|
||||||
}
|
|
||||||
if (processor->processor_version != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='version'>%s</entry>\n",
|
|
||||||
processor->processor_version);
|
|
||||||
}
|
|
||||||
if (processor->processor_external_clock != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='external_clock'>%s</entry>\n",
|
|
||||||
processor->processor_external_clock);
|
|
||||||
}
|
|
||||||
if (processor->processor_max_speed != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='max_speed'>%s</entry>\n",
|
|
||||||
processor->processor_max_speed);
|
|
||||||
}
|
|
||||||
if (processor->processor_status != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='status'>%s</entry>\n",
|
|
||||||
processor->processor_status);
|
|
||||||
}
|
|
||||||
if (processor->processor_serial_number != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='serial_number'>%s</entry>\n",
|
|
||||||
processor->processor_serial_number);
|
|
||||||
}
|
|
||||||
if (processor->processor_part_number != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='part_number'>%s</entry>\n",
|
|
||||||
processor->processor_part_number);
|
|
||||||
}
|
|
||||||
virBufferAsprintf(buf, "%s </processor>\n", prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
virBufferAddLit(buf, " <processor>\n");
|
||||||
|
virBufferAdjustIndent(buf, 4);
|
||||||
|
virBufferEscapeString(buf,
|
||||||
|
"<entry name='socket_destination'>%s</entry>\n",
|
||||||
|
processor->processor_socket_destination);
|
||||||
|
virBufferEscapeString(buf, "<entry name='type'>%s</entry>\n",
|
||||||
|
processor->processor_type);
|
||||||
|
virBufferEscapeString(buf, "<entry name='family'>%s</entry>\n",
|
||||||
|
processor->processor_family);
|
||||||
|
virBufferEscapeString(buf, "<entry name='manufacturer'>%s</entry>\n",
|
||||||
|
processor->processor_manufacturer);
|
||||||
|
virBufferEscapeString(buf, "<entry name='signature'>%s</entry>\n",
|
||||||
|
processor->processor_signature);
|
||||||
|
virBufferEscapeString(buf, "<entry name='version'>%s</entry>\n",
|
||||||
|
processor->processor_version);
|
||||||
|
virBufferEscapeString(buf, "<entry name='external_clock'>%s</entry>\n",
|
||||||
|
processor->processor_external_clock);
|
||||||
|
virBufferEscapeString(buf, "<entry name='max_speed'>%s</entry>\n",
|
||||||
|
processor->processor_max_speed);
|
||||||
|
virBufferEscapeString(buf, "<entry name='status'>%s</entry>\n",
|
||||||
|
processor->processor_status);
|
||||||
|
virBufferEscapeString(buf, "<entry name='serial_number'>%s</entry>\n",
|
||||||
|
processor->processor_serial_number);
|
||||||
|
virBufferEscapeString(buf, "<entry name='part_number'>%s</entry>\n",
|
||||||
|
processor->processor_part_number);
|
||||||
|
virBufferAdjustIndent(buf, -4);
|
||||||
|
virBufferAddLit(buf, " </processor>\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virSysinfoMemoryFormat(virSysinfoDefPtr def, const char *prefix,
|
virSysinfoMemoryFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||||
virBufferPtr buf)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int len = strlen(prefix);
|
|
||||||
virSysinfoMemoryDefPtr memory;
|
virSysinfoMemoryDefPtr memory;
|
||||||
|
|
||||||
for (i = 0; i < def->nmemory; i++) {
|
for (i = 0; i < def->nmemory; i++) {
|
||||||
memory = &def->memory[i];
|
memory = &def->memory[i];
|
||||||
|
|
||||||
if ((memory->memory_size != NULL) ||
|
if (!memory->memory_size &&
|
||||||
(memory->memory_form_factor != NULL) ||
|
!memory->memory_form_factor &&
|
||||||
(memory->memory_locator != NULL) ||
|
!memory->memory_locator &&
|
||||||
(memory->memory_bank_locator != NULL) ||
|
!memory->memory_bank_locator &&
|
||||||
(memory->memory_type != NULL) ||
|
!memory->memory_type &&
|
||||||
(memory->memory_type_detail != NULL) ||
|
!memory->memory_type_detail &&
|
||||||
(memory->memory_speed != NULL) ||
|
!memory->memory_speed &&
|
||||||
(memory->memory_manufacturer != NULL) ||
|
!memory->memory_manufacturer &&
|
||||||
(memory->memory_serial_number != NULL) ||
|
!memory->memory_serial_number &&
|
||||||
(memory->memory_part_number != NULL)) {
|
!memory->memory_part_number)
|
||||||
virBufferAsprintf(buf, "%s <memory_device>\n", prefix);
|
continue;
|
||||||
if (memory->memory_size != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='size'>%s</entry>\n",
|
|
||||||
memory->memory_size);
|
|
||||||
}
|
|
||||||
if (memory->memory_form_factor != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='form_factor'>%s</entry>\n",
|
|
||||||
memory->memory_form_factor);
|
|
||||||
}
|
|
||||||
if (memory->memory_locator != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='locator'>%s</entry>\n",
|
|
||||||
memory->memory_locator);
|
|
||||||
}
|
|
||||||
if (memory->memory_bank_locator != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='bank_locator'>%s</entry>\n",
|
|
||||||
memory->memory_bank_locator);
|
|
||||||
}
|
|
||||||
if (memory->memory_type != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='type'>%s</entry>\n",
|
|
||||||
memory->memory_type);
|
|
||||||
}
|
|
||||||
if (memory->memory_type_detail != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='type_detail'>%s</entry>\n",
|
|
||||||
memory->memory_type_detail);
|
|
||||||
}
|
|
||||||
if (memory->memory_speed != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='speed'>%s</entry>\n",
|
|
||||||
memory->memory_speed);
|
|
||||||
}
|
|
||||||
if (memory->memory_manufacturer != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='manufacturer'>%s</entry>\n",
|
|
||||||
memory->memory_manufacturer);
|
|
||||||
}
|
|
||||||
if (memory->memory_serial_number != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='serial_number'>%s</entry>\n",
|
|
||||||
memory->memory_serial_number);
|
|
||||||
}
|
|
||||||
if (memory->memory_part_number != NULL) {
|
|
||||||
virBufferAdd(buf, prefix, len);
|
|
||||||
virBufferEscapeString(buf,
|
|
||||||
" <entry name='part_number'>%s</entry>\n",
|
|
||||||
memory->memory_part_number);
|
|
||||||
}
|
|
||||||
virBufferAsprintf(buf, "%s </memory_device>\n", prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
virBufferAddLit(buf, " <memory_device>\n");
|
||||||
|
virBufferEscapeString(buf, " <entry name='size'>%s</entry>\n",
|
||||||
|
memory->memory_size);
|
||||||
|
virBufferEscapeString(buf,
|
||||||
|
" <entry name='form_factor'>%s</entry>\n",
|
||||||
|
memory->memory_form_factor);
|
||||||
|
virBufferEscapeString(buf, " <entry name='locator'>%s</entry>\n",
|
||||||
|
memory->memory_locator);
|
||||||
|
virBufferEscapeString(buf,
|
||||||
|
" <entry name='bank_locator'>%s</entry>\n",
|
||||||
|
memory->memory_bank_locator);
|
||||||
|
virBufferEscapeString(buf, " <entry name='type'>%s</entry>\n",
|
||||||
|
memory->memory_type);
|
||||||
|
virBufferEscapeString(buf,
|
||||||
|
" <entry name='type_detail'>%s</entry>\n",
|
||||||
|
memory->memory_type_detail);
|
||||||
|
virBufferEscapeString(buf, " <entry name='speed'>%s</entry>\n",
|
||||||
|
memory->memory_speed);
|
||||||
|
virBufferEscapeString(buf,
|
||||||
|
" <entry name='manufacturer'>%s</entry>\n",
|
||||||
|
memory->memory_manufacturer);
|
||||||
|
virBufferEscapeString(buf,
|
||||||
|
" <entry name='serial_number'>%s</entry>\n",
|
||||||
|
memory->memory_serial_number);
|
||||||
|
virBufferEscapeString(buf,
|
||||||
|
" <entry name='part_number'>%s</entry>\n",
|
||||||
|
memory->memory_part_number);
|
||||||
|
virBufferAddLit(buf, " </memory_device>\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virSysinfoFormat:
|
* virSysinfoFormat:
|
||||||
|
* @buf: buffer to append output to (may use auto-indentation)
|
||||||
* @def: structure to convert to xml string
|
* @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
|
* Returns 0 on success, -1 on failure after generating an error message.
|
||||||
* generating an error message.
|
|
||||||
*/
|
*/
|
||||||
char *
|
int
|
||||||
virSysinfoFormat(virSysinfoDefPtr def, const char *prefix)
|
virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||||
{
|
{
|
||||||
const char *type = virSysinfoTypeToString(def->type);
|
const char *type = virSysinfoTypeToString(def->type);
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
virSmbiosReportError(VIR_ERR_INTERNAL_ERROR,
|
virSmbiosReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unexpected sysinfo type model %d"),
|
_("unexpected sysinfo type model %d"),
|
||||||
def->type);
|
def->type);
|
||||||
return NULL;
|
virBufferFreeAndReset(buf);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferAsprintf(&buf, "%s<sysinfo type='%s'>\n", prefix, type);
|
virBufferAsprintf(buf, "<sysinfo type='%s'>\n", type);
|
||||||
|
|
||||||
virSysinfoBIOSFormat(def, prefix, &buf);
|
virSysinfoBIOSFormat(buf, def);
|
||||||
virSysinfoSystemFormat(def, prefix, &buf);
|
virSysinfoSystemFormat(buf, def);
|
||||||
virSysinfoProcessorFormat(def, prefix, &buf);
|
virSysinfoProcessorFormat(buf, def);
|
||||||
virSysinfoMemoryFormat(def, prefix, &buf);
|
virSysinfoMemoryFormat(buf, def);
|
||||||
|
|
||||||
virBufferAsprintf(&buf, "%s</sysinfo>\n", prefix);
|
virBufferAddLit(buf, "</sysinfo>\n");
|
||||||
|
|
||||||
if (virBufferError(&buf)) {
|
if (virBufferError(buf)) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return virBufferContentAndReset(&buf);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool virSysinfoIsEqual(virSysinfoDefPtr src,
|
bool virSysinfoIsEqual(virSysinfoDefPtr src,
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
# include "internal.h"
|
# include "internal.h"
|
||||||
# include "util.h"
|
# include "util.h"
|
||||||
|
# include "buf.h"
|
||||||
|
|
||||||
enum virSysinfoType {
|
enum virSysinfoType {
|
||||||
VIR_SYSINFO_SMBIOS,
|
VIR_SYSINFO_SMBIOS,
|
||||||
@ -93,7 +94,7 @@ virSysinfoDefPtr virSysinfoRead(void);
|
|||||||
|
|
||||||
void virSysinfoDefFree(virSysinfoDefPtr def);
|
void virSysinfoDefFree(virSysinfoDefPtr def);
|
||||||
|
|
||||||
char *virSysinfoFormat(virSysinfoDefPtr def, const char *prefix)
|
int virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||||
|
|
||||||
bool virSysinfoIsEqual(virSysinfoDefPtr src,
|
bool virSysinfoIsEqual(virSysinfoDefPtr src,
|
||||||
|
Loading…
Reference in New Issue
Block a user