mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
virSysinfoDef: Exempt SYSTEM variables
Move all the system_* fields into a separate struct. Not only this simplifies the code a bit it also helps us to identify whether BIOS info is present. We don't have to check all the four variables for being not-NULL, but we can just check the pointer to the struct. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
3f9cae18fe
commit
0b92974c15
@ -11152,6 +11152,81 @@ virSysinfoBIOSParseXML(xmlNodePtr node,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
virSysinfoSystemParseXML(xmlNodePtr node,
|
||||||
|
xmlXPathContextPtr ctxt,
|
||||||
|
virSysinfoSystemDefPtr *system,
|
||||||
|
unsigned char *domUUID,
|
||||||
|
bool uuid_generated)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
virSysinfoSystemDefPtr def;
|
||||||
|
char *tmpUUID = NULL;
|
||||||
|
|
||||||
|
if (!xmlStrEqual(node->name, BAD_CAST "system")) {
|
||||||
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
|
_("XML does not contain expected 'system' element"));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_ALLOC(def) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
def->manufacturer =
|
||||||
|
virXPathString("string(entry[@name='manufacturer'])", ctxt);
|
||||||
|
def->product =
|
||||||
|
virXPathString("string(entry[@name='product'])", ctxt);
|
||||||
|
def->version =
|
||||||
|
virXPathString("string(entry[@name='version'])", ctxt);
|
||||||
|
def->serial =
|
||||||
|
virXPathString("string(entry[@name='serial'])", ctxt);
|
||||||
|
tmpUUID = virXPathString("string(entry[@name='uuid'])", ctxt);
|
||||||
|
if (tmpUUID) {
|
||||||
|
unsigned char uuidbuf[VIR_UUID_BUFLEN];
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
|
if (virUUIDParse(tmpUUID, uuidbuf) < 0) {
|
||||||
|
virReportError(VIR_ERR_XML_DETAIL,
|
||||||
|
"%s", _("malformed <sysinfo> uuid element"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (uuid_generated) {
|
||||||
|
memcpy(domUUID, uuidbuf, VIR_UUID_BUFLEN);
|
||||||
|
} else if (memcmp(domUUID, uuidbuf, VIR_UUID_BUFLEN) != 0) {
|
||||||
|
virReportError(VIR_ERR_XML_DETAIL, "%s",
|
||||||
|
_("UUID mismatch between <uuid> and "
|
||||||
|
"<sysinfo>"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
/* Although we've validated the UUID as good, virUUIDParse() is
|
||||||
|
* lax with respect to allowing extraneous "-" and " ", but the
|
||||||
|
* underlying hypervisor may be less forgiving. Use virUUIDFormat()
|
||||||
|
* to validate format in xml is right. If not, then format it
|
||||||
|
* properly so that it's used correctly later.
|
||||||
|
*/
|
||||||
|
virUUIDFormat(uuidbuf, uuidstr);
|
||||||
|
if (VIR_STRDUP(def->uuid, uuidstr) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
def->sku =
|
||||||
|
virXPathString("string(entry[@name='sku'])", ctxt);
|
||||||
|
def->family =
|
||||||
|
virXPathString("string(entry[@name='family'])", ctxt);
|
||||||
|
|
||||||
|
if (!def->manufacturer && !def->product && !def->version &&
|
||||||
|
!def->serial && !def->uuid && !def->sku && !def->family) {
|
||||||
|
virSysinfoSystemDefFree(def);
|
||||||
|
def = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*system = def;
|
||||||
|
def = NULL;
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
virSysinfoSystemDefFree(def);
|
||||||
|
VIR_FREE(tmpUUID);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static virSysinfoDefPtr
|
static virSysinfoDefPtr
|
||||||
virSysinfoParseXML(xmlNodePtr node,
|
virSysinfoParseXML(xmlNodePtr node,
|
||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
@ -11161,7 +11236,6 @@ virSysinfoParseXML(xmlNodePtr node,
|
|||||||
virSysinfoDefPtr def;
|
virSysinfoDefPtr def;
|
||||||
xmlNodePtr oldnode, tmpnode;
|
xmlNodePtr oldnode, tmpnode;
|
||||||
char *type;
|
char *type;
|
||||||
char *tmpUUID = NULL;
|
|
||||||
|
|
||||||
if (!xmlStrEqual(node->name, BAD_CAST "sysinfo")) {
|
if (!xmlStrEqual(node->name, BAD_CAST "sysinfo")) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
@ -11196,49 +11270,19 @@ virSysinfoParseXML(xmlNodePtr node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Extract system related metadata */
|
/* Extract system related metadata */
|
||||||
def->system_manufacturer =
|
if ((tmpnode = virXPathNode("./system[1]", ctxt)) != NULL) {
|
||||||
virXPathString("string(system/entry[@name='manufacturer'])", ctxt);
|
oldnode = ctxt->node;
|
||||||
def->system_product =
|
ctxt->node = tmpnode;
|
||||||
virXPathString("string(system/entry[@name='product'])", ctxt);
|
if (virSysinfoSystemParseXML(tmpnode, ctxt, &def->system,
|
||||||
def->system_version =
|
domUUID, uuid_generated) < 0) {
|
||||||
virXPathString("string(system/entry[@name='version'])", ctxt);
|
ctxt->node = oldnode;
|
||||||
def->system_serial =
|
|
||||||
virXPathString("string(system/entry[@name='serial'])", ctxt);
|
|
||||||
tmpUUID = virXPathString("string(system/entry[@name='uuid'])", ctxt);
|
|
||||||
if (tmpUUID) {
|
|
||||||
unsigned char uuidbuf[VIR_UUID_BUFLEN];
|
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
||||||
if (virUUIDParse(tmpUUID, uuidbuf) < 0) {
|
|
||||||
virReportError(VIR_ERR_XML_DETAIL,
|
|
||||||
"%s", _("malformed <sysinfo> uuid element"));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (uuid_generated) {
|
ctxt->node = oldnode;
|
||||||
memcpy(domUUID, uuidbuf, VIR_UUID_BUFLEN);
|
|
||||||
} else if (memcmp(domUUID, uuidbuf, VIR_UUID_BUFLEN) != 0) {
|
|
||||||
virReportError(VIR_ERR_XML_DETAIL, "%s",
|
|
||||||
_("UUID mismatch between <uuid> and "
|
|
||||||
"<sysinfo>"));
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
/* Although we've validated the UUID as good, virUUIDParse() is
|
|
||||||
* lax with respect to allowing extraneous "-" and " ", but the
|
|
||||||
* underlying hypervisor may be less forgiving. Use virUUIDFormat()
|
|
||||||
* to validate format in xml is right. If not, then format it
|
|
||||||
* properly so that it's used correctly later.
|
|
||||||
*/
|
|
||||||
virUUIDFormat(uuidbuf, uuidstr);
|
|
||||||
if (VIR_STRDUP(def->system_uuid, uuidstr) < 0)
|
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
def->system_sku =
|
|
||||||
virXPathString("string(system/entry[@name='sku'])", ctxt);
|
|
||||||
def->system_family =
|
|
||||||
virXPathString("string(system/entry[@name='family'])", ctxt);
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(type);
|
VIR_FREE(type);
|
||||||
VIR_FREE(tmpUUID);
|
|
||||||
return def;
|
return def;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -2187,6 +2187,7 @@ virSysinfoDefFree;
|
|||||||
virSysinfoFormat;
|
virSysinfoFormat;
|
||||||
virSysinfoRead;
|
virSysinfoRead;
|
||||||
virSysinfoSetup;
|
virSysinfoSetup;
|
||||||
|
virSysinfoSystemDefFree;
|
||||||
|
|
||||||
|
|
||||||
# util/virsystemd.h
|
# util/virsystemd.h
|
||||||
|
@ -6733,40 +6733,41 @@ static char *qemuBuildSmbiosBiosStr(virSysinfoBIOSDefPtr def)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *qemuBuildSmbiosSystemStr(virSysinfoDefPtr def, bool skip_uuid)
|
static char *qemuBuildSmbiosSystemStr(virSysinfoSystemDefPtr def,
|
||||||
|
bool skip_uuid)
|
||||||
{
|
{
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
if ((def->system_manufacturer == NULL) && (def->system_sku == NULL) &&
|
if (!def ||
|
||||||
(def->system_product == NULL) && (def->system_version == NULL) &&
|
(!def->manufacturer && !def->product && !def->version &&
|
||||||
(def->system_serial == NULL) && (def->system_family == NULL) &&
|
!def->serial && (!def->uuid || skip_uuid) &&
|
||||||
(def->system_uuid == NULL || skip_uuid))
|
def->sku && !def->family))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
virBufferAddLit(&buf, "type=1");
|
virBufferAddLit(&buf, "type=1");
|
||||||
|
|
||||||
/* 1:Manufacturer */
|
/* 1:Manufacturer */
|
||||||
if (def->system_manufacturer)
|
if (def->manufacturer)
|
||||||
virBufferAsprintf(&buf, ",manufacturer=%s",
|
virBufferAsprintf(&buf, ",manufacturer=%s",
|
||||||
def->system_manufacturer);
|
def->manufacturer);
|
||||||
/* 1:Product Name */
|
/* 1:Product Name */
|
||||||
if (def->system_product)
|
if (def->product)
|
||||||
virBufferAsprintf(&buf, ",product=%s", def->system_product);
|
virBufferAsprintf(&buf, ",product=%s", def->product);
|
||||||
/* 1:Version */
|
/* 1:Version */
|
||||||
if (def->system_version)
|
if (def->version)
|
||||||
virBufferAsprintf(&buf, ",version=%s", def->system_version);
|
virBufferAsprintf(&buf, ",version=%s", def->version);
|
||||||
/* 1:Serial Number */
|
/* 1:Serial Number */
|
||||||
if (def->system_serial)
|
if (def->serial)
|
||||||
virBufferAsprintf(&buf, ",serial=%s", def->system_serial);
|
virBufferAsprintf(&buf, ",serial=%s", def->serial);
|
||||||
/* 1:UUID */
|
/* 1:UUID */
|
||||||
if (def->system_uuid && !skip_uuid)
|
if (def->uuid && !skip_uuid)
|
||||||
virBufferAsprintf(&buf, ",uuid=%s", def->system_uuid);
|
virBufferAsprintf(&buf, ",uuid=%s", def->uuid);
|
||||||
/* 1:SKU Number */
|
/* 1:SKU Number */
|
||||||
if (def->system_sku)
|
if (def->sku)
|
||||||
virBufferAsprintf(&buf, ",sku=%s", def->system_sku);
|
virBufferAsprintf(&buf, ",sku=%s", def->sku);
|
||||||
/* 1:Family */
|
/* 1:Family */
|
||||||
if (def->system_family)
|
if (def->family)
|
||||||
virBufferAsprintf(&buf, ",family=%s", def->system_family);
|
virBufferAsprintf(&buf, ",family=%s", def->family);
|
||||||
|
|
||||||
if (virBufferCheckError(&buf) < 0)
|
if (virBufferCheckError(&buf) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -9051,7 +9052,7 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
virCommandAddArgList(cmd, "-smbios", smbioscmd, NULL);
|
virCommandAddArgList(cmd, "-smbios", smbioscmd, NULL);
|
||||||
VIR_FREE(smbioscmd);
|
VIR_FREE(smbioscmd);
|
||||||
}
|
}
|
||||||
smbioscmd = qemuBuildSmbiosSystemStr(source, skip_uuid);
|
smbioscmd = qemuBuildSmbiosSystemStr(source->system, skip_uuid);
|
||||||
if (smbioscmd != NULL) {
|
if (smbioscmd != NULL) {
|
||||||
virCommandAddArgList(cmd, "-smbios", smbioscmd, NULL);
|
virCommandAddArgList(cmd, "-smbios", smbioscmd, NULL);
|
||||||
VIR_FREE(smbioscmd);
|
VIR_FREE(smbioscmd);
|
||||||
|
@ -76,6 +76,22 @@ void virSysinfoBIOSDefFree(virSysinfoBIOSDefPtr def)
|
|||||||
VIR_FREE(def);
|
VIR_FREE(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void virSysinfoSystemDefFree(virSysinfoSystemDefPtr def)
|
||||||
|
{
|
||||||
|
if (def == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
VIR_FREE(def->manufacturer);
|
||||||
|
VIR_FREE(def->product);
|
||||||
|
VIR_FREE(def->version);
|
||||||
|
VIR_FREE(def->serial);
|
||||||
|
VIR_FREE(def->uuid);
|
||||||
|
VIR_FREE(def->sku);
|
||||||
|
VIR_FREE(def->family);
|
||||||
|
VIR_FREE(def);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virSysinfoDefFree:
|
* virSysinfoDefFree:
|
||||||
* @def: a sysinfo structure
|
* @def: a sysinfo structure
|
||||||
@ -91,14 +107,7 @@ void virSysinfoDefFree(virSysinfoDefPtr def)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
virSysinfoBIOSDefFree(def->bios);
|
virSysinfoBIOSDefFree(def->bios);
|
||||||
|
virSysinfoSystemDefFree(def->system);
|
||||||
VIR_FREE(def->system_manufacturer);
|
|
||||||
VIR_FREE(def->system_product);
|
|
||||||
VIR_FREE(def->system_version);
|
|
||||||
VIR_FREE(def->system_serial);
|
|
||||||
VIR_FREE(def->system_uuid);
|
|
||||||
VIR_FREE(def->system_sku);
|
|
||||||
VIR_FREE(def->system_family);
|
|
||||||
|
|
||||||
for (i = 0; i < def->nprocessor; i++) {
|
for (i = 0; i < def->nprocessor; i++) {
|
||||||
VIR_FREE(def->processor[i].processor_socket_destination);
|
VIR_FREE(def->processor[i].processor_socket_destination);
|
||||||
@ -141,39 +150,55 @@ void virSysinfoDefFree(virSysinfoDefPtr def)
|
|||||||
|
|
||||||
#if defined(__powerpc__)
|
#if defined(__powerpc__)
|
||||||
static int
|
static int
|
||||||
virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
|
virSysinfoParseSystem(const char *base, virSysinfoSystemDefPtr *system)
|
||||||
{
|
{
|
||||||
|
int ret = -1;
|
||||||
char *eol = NULL;
|
char *eol = NULL;
|
||||||
const char *cur;
|
const char *cur;
|
||||||
|
virSysinfoSystemDefPtr def;
|
||||||
|
|
||||||
if ((cur = strstr(base, "platform")) == NULL)
|
if ((cur = strstr(base, "platform")) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (VIR_ALLOC(def) < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
base = cur;
|
base = cur;
|
||||||
/* Account for format 'platform : XXXX'*/
|
/* Account for format 'platform : XXXX'*/
|
||||||
cur = strchr(cur, ':') + 1;
|
cur = strchr(cur, ':') + 1;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
virSkipSpaces(&cur);
|
virSkipSpaces(&cur);
|
||||||
if (eol && VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
|
||||||
if ((cur = strstr(base, "model")) != NULL) {
|
if ((cur = strstr(base, "model")) != NULL) {
|
||||||
cur = strchr(cur, ':') + 1;
|
cur = strchr(cur, ':') + 1;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
virSkipSpaces(&cur);
|
virSkipSpaces(&cur);
|
||||||
if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cur = strstr(base, "machine")) != NULL) {
|
if ((cur = strstr(base, "machine")) != NULL) {
|
||||||
cur = strchr(cur, ':') + 1;
|
cur = strchr(cur, ':') + 1;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
virSkipSpaces(&cur);
|
virSkipSpaces(&cur);
|
||||||
if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (!def->manufacturer && !def->product && !def->version &&
|
||||||
|
!def->serial && !def->uuid && !def->sku && !def->family) {
|
||||||
|
virSysinfoSystemDefFree(def);
|
||||||
|
def = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*system = def;
|
||||||
|
def = NULL;
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
virSysinfoSystemDefFree(def);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -243,7 +268,7 @@ virSysinfoRead(void)
|
|||||||
if (virSysinfoParseProcessor(outbuf, ret) < 0)
|
if (virSysinfoParseProcessor(outbuf, ret) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
if (virSysinfoParseSystem(outbuf, ret) < 0)
|
if (virSysinfoParseSystem(outbuf, &ret->system) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -255,39 +280,55 @@ virSysinfoRead(void)
|
|||||||
|
|
||||||
#elif defined(__arm__) || defined(__aarch64__)
|
#elif defined(__arm__) || defined(__aarch64__)
|
||||||
static int
|
static int
|
||||||
virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
|
virSysinfoParseSystem(const char *base, virSysinfoSystemDefPtr *system)
|
||||||
{
|
{
|
||||||
|
int ret = -1;
|
||||||
char *eol = NULL;
|
char *eol = NULL;
|
||||||
const char *cur;
|
const char *cur;
|
||||||
|
virSysinfoSystemDefPtr def;
|
||||||
|
|
||||||
if ((cur = strstr(base, "platform")) == NULL)
|
if ((cur = strstr(base, "platform")) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (VIR_ALLOC(def) < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
base = cur;
|
base = cur;
|
||||||
/* Account for format 'platform : XXXX'*/
|
/* Account for format 'platform : XXXX'*/
|
||||||
cur = strchr(cur, ':') + 1;
|
cur = strchr(cur, ':') + 1;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
virSkipSpaces(&cur);
|
virSkipSpaces(&cur);
|
||||||
if (eol && VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
|
||||||
if ((cur = strstr(base, "model")) != NULL) {
|
if ((cur = strstr(base, "model")) != NULL) {
|
||||||
cur = strchr(cur, ':') + 1;
|
cur = strchr(cur, ':') + 1;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
virSkipSpaces(&cur);
|
virSkipSpaces(&cur);
|
||||||
if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cur = strstr(base, "machine")) != NULL) {
|
if ((cur = strstr(base, "machine")) != NULL) {
|
||||||
cur = strchr(cur, ':') + 1;
|
cur = strchr(cur, ':') + 1;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
virSkipSpaces(&cur);
|
virSkipSpaces(&cur);
|
||||||
if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (!def->manufacturer && !def->product && !def->version &&
|
||||||
|
!def->serial && !def->uuid && !def->sku && !def->family) {
|
||||||
|
virSysinfoSystemDefFree(def);
|
||||||
|
def = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*system = def;
|
||||||
|
def = NULL;
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
virSysinfoSystemDefFree(def);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -359,7 +400,7 @@ virSysinfoRead(void)
|
|||||||
if (virSysinfoParseProcessor(outbuf, ret) < 0)
|
if (virSysinfoParseProcessor(outbuf, ret) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
if (virSysinfoParseSystem(outbuf, ret) < 0)
|
if (virSysinfoParseSystem(outbuf, &ret->system) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -411,17 +452,38 @@ virSysinfoParseLine(const char *base, const char *name, char **value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
|
virSysinfoParseSystem(const char *base, virSysinfoSystemDefPtr *system)
|
||||||
{
|
{
|
||||||
if (virSysinfoParseLine(base, "Manufacturer",
|
int ret = -1;
|
||||||
&ret->system_manufacturer) &&
|
virSysinfoSystemDefPtr def;
|
||||||
virSysinfoParseLine(base, "Type",
|
|
||||||
&ret->system_family) &&
|
if (VIR_ALLOC(def) < 0)
|
||||||
virSysinfoParseLine(base, "Sequence Code",
|
return ret;
|
||||||
&ret->system_serial))
|
|
||||||
return 0;
|
if (!virSysinfoParseLine(base, "Manufacturer",
|
||||||
else
|
&def->manufacturer))
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!virSysinfoParseLine(base, "Type",
|
||||||
|
&def->family))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!virSysinfoParseLine(base, "Sequence Code",
|
||||||
|
&def->serial))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!def->manufacturer && !def->product && !def->version &&
|
||||||
|
!def->serial && !def->uuid && !def->sku && !def->family) {
|
||||||
|
virSysinfoSystemDefFree(def);
|
||||||
|
def = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*system = def;
|
||||||
|
def = NULL;
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
virSysinfoSystemDefFree(def);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -498,7 +560,7 @@ virSysinfoRead(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSysinfoParseSystem(outbuf, ret) < 0)
|
if (virSysinfoParseSystem(outbuf, &ret->system) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -584,58 +646,74 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
|
virSysinfoParseSystem(const char *base, virSysinfoSystemDefPtr *system)
|
||||||
{
|
{
|
||||||
|
int ret = -1;
|
||||||
const char *cur, *eol = NULL;
|
const char *cur, *eol = NULL;
|
||||||
|
virSysinfoSystemDefPtr def;
|
||||||
|
|
||||||
if ((cur = strstr(base, "System Information")) == NULL)
|
if ((cur = strstr(base, "System Information")) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (VIR_ALLOC(def) < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
base = cur;
|
base = cur;
|
||||||
if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
|
if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
|
||||||
cur += 14;
|
cur += 14;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
if (eol && VIR_STRNDUP(ret->system_manufacturer, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((cur = strstr(base, "Product Name: ")) != NULL) {
|
if ((cur = strstr(base, "Product Name: ")) != NULL) {
|
||||||
cur += 14;
|
cur += 14;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
if (eol && VIR_STRNDUP(ret->system_product, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((cur = strstr(base, "Version: ")) != NULL) {
|
if ((cur = strstr(base, "Version: ")) != NULL) {
|
||||||
cur += 9;
|
cur += 9;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
if (eol && VIR_STRNDUP(ret->system_version, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((cur = strstr(base, "Serial Number: ")) != NULL) {
|
if ((cur = strstr(base, "Serial Number: ")) != NULL) {
|
||||||
cur += 15;
|
cur += 15;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
if (eol && VIR_STRNDUP(ret->system_serial, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((cur = strstr(base, "UUID: ")) != NULL) {
|
if ((cur = strstr(base, "UUID: ")) != NULL) {
|
||||||
cur += 6;
|
cur += 6;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
if (eol && VIR_STRNDUP(ret->system_uuid, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->uuid, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((cur = strstr(base, "SKU Number: ")) != NULL) {
|
if ((cur = strstr(base, "SKU Number: ")) != NULL) {
|
||||||
cur += 12;
|
cur += 12;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
if (eol && VIR_STRNDUP(ret->system_sku, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((cur = strstr(base, "Family: ")) != NULL) {
|
if ((cur = strstr(base, "Family: ")) != NULL) {
|
||||||
cur += 8;
|
cur += 8;
|
||||||
eol = strchr(cur, '\n');
|
eol = strchr(cur, '\n');
|
||||||
if (eol && VIR_STRNDUP(ret->system_family, cur, eol - cur) < 0)
|
if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (!def->manufacturer && !def->product && !def->version &&
|
||||||
|
!def->serial && !def->uuid && !def->sku && !def->family) {
|
||||||
|
virSysinfoSystemDefFree(def);
|
||||||
|
def = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*system = def;
|
||||||
|
def = NULL;
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
virSysinfoSystemDefFree(def);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -874,7 +952,7 @@ virSysinfoRead(void)
|
|||||||
if (virSysinfoParseBIOS(outbuf, &ret->bios) < 0)
|
if (virSysinfoParseBIOS(outbuf, &ret->bios) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virSysinfoParseSystem(outbuf, ret) < 0)
|
if (virSysinfoParseSystem(outbuf, &ret->system) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
ret->nprocessor = 0;
|
ret->nprocessor = 0;
|
||||||
@ -921,29 +999,27 @@ virSysinfoBIOSFormat(virBufferPtr buf, virSysinfoBIOSDefPtr def)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virSysinfoSystemFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
virSysinfoSystemFormat(virBufferPtr buf, virSysinfoSystemDefPtr def)
|
||||||
{
|
{
|
||||||
if (!def->system_manufacturer && !def->system_product &&
|
if (!def)
|
||||||
!def->system_version && !def->system_serial &&
|
|
||||||
!def->system_uuid && !def->system_sku && !def->system_family)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virBufferAddLit(buf, "<system>\n");
|
virBufferAddLit(buf, "<system>\n");
|
||||||
virBufferAdjustIndent(buf, 2);
|
virBufferAdjustIndent(buf, 2);
|
||||||
virBufferEscapeString(buf, "<entry name='manufacturer'>%s</entry>\n",
|
virBufferEscapeString(buf, "<entry name='manufacturer'>%s</entry>\n",
|
||||||
def->system_manufacturer);
|
def->manufacturer);
|
||||||
virBufferEscapeString(buf, "<entry name='product'>%s</entry>\n",
|
virBufferEscapeString(buf, "<entry name='product'>%s</entry>\n",
|
||||||
def->system_product);
|
def->product);
|
||||||
virBufferEscapeString(buf, "<entry name='version'>%s</entry>\n",
|
virBufferEscapeString(buf, "<entry name='version'>%s</entry>\n",
|
||||||
def->system_version);
|
def->version);
|
||||||
virBufferEscapeString(buf, "<entry name='serial'>%s</entry>\n",
|
virBufferEscapeString(buf, "<entry name='serial'>%s</entry>\n",
|
||||||
def->system_serial);
|
def->serial);
|
||||||
virBufferEscapeString(buf, "<entry name='uuid'>%s</entry>\n",
|
virBufferEscapeString(buf, "<entry name='uuid'>%s</entry>\n",
|
||||||
def->system_uuid);
|
def->uuid);
|
||||||
virBufferEscapeString(buf, "<entry name='sku'>%s</entry>\n",
|
virBufferEscapeString(buf, "<entry name='sku'>%s</entry>\n",
|
||||||
def->system_sku);
|
def->sku);
|
||||||
virBufferEscapeString(buf, "<entry name='family'>%s</entry>\n",
|
virBufferEscapeString(buf, "<entry name='family'>%s</entry>\n",
|
||||||
def->system_family);
|
def->family);
|
||||||
virBufferAdjustIndent(buf, -2);
|
virBufferAdjustIndent(buf, -2);
|
||||||
virBufferAddLit(buf, "</system>\n");
|
virBufferAddLit(buf, "</system>\n");
|
||||||
}
|
}
|
||||||
@ -1080,7 +1156,7 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
|||||||
virBufferAdjustIndent(&childrenBuf, indent + 2);
|
virBufferAdjustIndent(&childrenBuf, indent + 2);
|
||||||
|
|
||||||
virSysinfoBIOSFormat(&childrenBuf, def->bios);
|
virSysinfoBIOSFormat(&childrenBuf, def->bios);
|
||||||
virSysinfoSystemFormat(&childrenBuf, def);
|
virSysinfoSystemFormat(&childrenBuf, def->system);
|
||||||
virSysinfoProcessorFormat(&childrenBuf, def);
|
virSysinfoProcessorFormat(&childrenBuf, def);
|
||||||
virSysinfoMemoryFormat(&childrenBuf, def);
|
virSysinfoMemoryFormat(&childrenBuf, def);
|
||||||
|
|
||||||
@ -1137,6 +1213,36 @@ virSysinfoBIOSIsEqual(virSysinfoBIOSDefPtr src,
|
|||||||
return identical;
|
return identical;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
virSysinfoSystemIsEqual(virSysinfoSystemDefPtr src,
|
||||||
|
virSysinfoSystemDefPtr dst)
|
||||||
|
{
|
||||||
|
bool identical = false;
|
||||||
|
|
||||||
|
if (!src && !dst)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if ((src && !dst) || (!src && dst)) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("Target sysinfo does not match source"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK_FIELD(manufacturer, "system vendor");
|
||||||
|
CHECK_FIELD(product, "system product");
|
||||||
|
CHECK_FIELD(version, "system version");
|
||||||
|
CHECK_FIELD(serial, "system serial");
|
||||||
|
CHECK_FIELD(uuid, "system uuid");
|
||||||
|
CHECK_FIELD(sku, "system sku");
|
||||||
|
CHECK_FIELD(family, "system family");
|
||||||
|
|
||||||
|
identical = true;
|
||||||
|
cleanup:
|
||||||
|
return identical;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef CHECK_FIELD
|
||||||
|
|
||||||
bool virSysinfoIsEqual(virSysinfoDefPtr src,
|
bool virSysinfoIsEqual(virSysinfoDefPtr src,
|
||||||
virSysinfoDefPtr dst)
|
virSysinfoDefPtr dst)
|
||||||
{
|
{
|
||||||
@ -1162,15 +1268,8 @@ bool virSysinfoIsEqual(virSysinfoDefPtr src,
|
|||||||
if (!virSysinfoBIOSIsEqual(src->bios, dst->bios))
|
if (!virSysinfoBIOSIsEqual(src->bios, dst->bios))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
CHECK_FIELD(system_manufacturer, "system vendor");
|
if (!virSysinfoSystemIsEqual(src->system, dst->system))
|
||||||
CHECK_FIELD(system_product, "system product");
|
goto cleanup;
|
||||||
CHECK_FIELD(system_version, "system version");
|
|
||||||
CHECK_FIELD(system_serial, "system serial");
|
|
||||||
CHECK_FIELD(system_uuid, "system uuid");
|
|
||||||
CHECK_FIELD(system_sku, "system sku");
|
|
||||||
CHECK_FIELD(system_family, "system family");
|
|
||||||
|
|
||||||
#undef CHECK_FIELD
|
|
||||||
|
|
||||||
identical = true;
|
identical = true;
|
||||||
|
|
||||||
|
@ -74,20 +74,25 @@ struct _virSysinfoBIOSDef {
|
|||||||
char *release;
|
char *release;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct _virSysinfoSystemDef virSysinfoSystemDef;
|
||||||
|
typedef virSysinfoSystemDef *virSysinfoSystemDefPtr;
|
||||||
|
struct _virSysinfoSystemDef {
|
||||||
|
char *manufacturer;
|
||||||
|
char *product;
|
||||||
|
char *version;
|
||||||
|
char *serial;
|
||||||
|
char *uuid;
|
||||||
|
char *sku;
|
||||||
|
char *family;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct _virSysinfoDef virSysinfoDef;
|
typedef struct _virSysinfoDef virSysinfoDef;
|
||||||
typedef virSysinfoDef *virSysinfoDefPtr;
|
typedef virSysinfoDef *virSysinfoDefPtr;
|
||||||
struct _virSysinfoDef {
|
struct _virSysinfoDef {
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
virSysinfoBIOSDefPtr bios;
|
virSysinfoBIOSDefPtr bios;
|
||||||
|
virSysinfoSystemDefPtr system;
|
||||||
char *system_manufacturer;
|
|
||||||
char *system_product;
|
|
||||||
char *system_version;
|
|
||||||
char *system_serial;
|
|
||||||
char *system_uuid;
|
|
||||||
char *system_sku;
|
|
||||||
char *system_family;
|
|
||||||
|
|
||||||
size_t nprocessor;
|
size_t nprocessor;
|
||||||
virSysinfoProcessorDefPtr processor;
|
virSysinfoProcessorDefPtr processor;
|
||||||
@ -99,6 +104,7 @@ struct _virSysinfoDef {
|
|||||||
virSysinfoDefPtr virSysinfoRead(void);
|
virSysinfoDefPtr virSysinfoRead(void);
|
||||||
|
|
||||||
void virSysinfoBIOSDefFree(virSysinfoBIOSDefPtr def);
|
void virSysinfoBIOSDefFree(virSysinfoBIOSDefPtr def);
|
||||||
|
void virSysinfoSystemDefFree(virSysinfoSystemDefPtr def);
|
||||||
void virSysinfoDefFree(virSysinfoDefPtr def);
|
void virSysinfoDefFree(virSysinfoDefPtr def);
|
||||||
|
|
||||||
int virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
int virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||||
|
Loading…
Reference in New Issue
Block a user