mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
conf: storage: Remove virStoragePoolDefParseNode
Replace it by proper use of virXMLParse to validate the root node and allocate the context. The use in the test driver can be directly replaced by virStoragePoolDefParseXML as both are validated. The change to the storage driver isn't trivial though as it requires careful xpath context juggling to parse the nested volumes properly. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
ee3b96bcb0
commit
b3e33a0ef7
@ -972,43 +972,21 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
||||
}
|
||||
|
||||
|
||||
virStoragePoolDef *
|
||||
virStoragePoolDefParseNode(xmlDocPtr xml,
|
||||
xmlNodePtr root)
|
||||
{
|
||||
g_autoptr(xmlXPathContext) ctxt = NULL;
|
||||
|
||||
if (!virXMLNodeNameEqual(root, "pool")) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("unexpected root element <%s>, "
|
||||
"expecting <pool>"),
|
||||
root->name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(ctxt = virXMLXPathContextNew(xml)))
|
||||
return NULL;
|
||||
|
||||
ctxt->node = root;
|
||||
return virStoragePoolDefParseXML(ctxt);
|
||||
}
|
||||
|
||||
|
||||
static virStoragePoolDef *
|
||||
virStoragePoolDefParse(const char *xmlStr,
|
||||
const char *filename,
|
||||
unsigned int flags)
|
||||
{
|
||||
virStoragePoolDef *ret = NULL;
|
||||
g_autoptr(xmlDoc) xml = NULL;
|
||||
g_autoptr(xmlXPathContext) ctxt = NULL;
|
||||
bool validate = flags & VIR_STORAGE_POOL_DEFINE_VALIDATE;
|
||||
|
||||
if ((xml = virXMLParse(filename, xmlStr, _("(storage_pool_definition)"),
|
||||
NULL, NULL, "storagepool.rng", validate))) {
|
||||
ret = virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml));
|
||||
}
|
||||
|
||||
return ret;
|
||||
if (!(xml = virXMLParse(filename, xmlStr, _("(storage_pool_definition)"),
|
||||
"pool", &ctxt, "storagepool.rng", validate)))
|
||||
return NULL;
|
||||
|
||||
return virStoragePoolDefParseXML(ctxt);
|
||||
}
|
||||
|
||||
|
||||
|
@ -278,10 +278,6 @@ virStoragePoolDefParseString(const char *xml,
|
||||
virStoragePoolDef *
|
||||
virStoragePoolDefParseFile(const char *filename);
|
||||
|
||||
virStoragePoolDef *
|
||||
virStoragePoolDefParseNode(xmlDocPtr xml,
|
||||
xmlNodePtr root);
|
||||
|
||||
char *
|
||||
virStoragePoolDefFormat(virStoragePoolDef *def);
|
||||
|
||||
|
@ -1054,7 +1054,6 @@ virStoragePartedFsTypeToString;
|
||||
virStoragePoolDefFormat;
|
||||
virStoragePoolDefFree;
|
||||
virStoragePoolDefParseFile;
|
||||
virStoragePoolDefParseNode;
|
||||
virStoragePoolDefParseSourceString;
|
||||
virStoragePoolDefParseString;
|
||||
virStoragePoolFormatDiskTypeFromString;
|
||||
|
@ -1145,20 +1145,15 @@ testParseInterfaces(testDriver *privconn,
|
||||
static int
|
||||
testOpenVolumesForPool(const char *file,
|
||||
xmlXPathContextPtr ctxt,
|
||||
virStoragePoolObj *obj,
|
||||
int objidx)
|
||||
virStoragePoolObj *obj)
|
||||
{
|
||||
virStoragePoolDef *def = virStoragePoolObjGetDef(obj);
|
||||
size_t i;
|
||||
int num;
|
||||
g_autofree char *vol_xpath = NULL;
|
||||
g_autofree xmlNodePtr *nodes = NULL;
|
||||
g_autoptr(virStorageVolDef) volDef = NULL;
|
||||
|
||||
/* Find storage volumes */
|
||||
vol_xpath = g_strdup_printf("/node/pool[%d]/volume", objidx);
|
||||
|
||||
num = virXPathNodeSet(vol_xpath, ctxt, &nodes);
|
||||
num = virXPathNodeSet("/pool/volume", ctxt, &nodes);
|
||||
if (num < 0)
|
||||
return -1;
|
||||
|
||||
@ -1195,6 +1190,7 @@ testParseStorage(testDriver *privconn,
|
||||
const char *file,
|
||||
xmlXPathContextPtr ctxt)
|
||||
{
|
||||
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
||||
int num;
|
||||
size_t i;
|
||||
virStoragePoolObj *obj;
|
||||
@ -1206,12 +1202,11 @@ testParseStorage(testDriver *privconn,
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
virStoragePoolDef *def;
|
||||
xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file);
|
||||
if (!node)
|
||||
|
||||
if (!(ctxt->node = testParseXMLDocFromFile(nodes[i], file)))
|
||||
return -1;
|
||||
|
||||
def = virStoragePoolDefParseNode(ctxt->doc, node);
|
||||
if (!def)
|
||||
if (!(def = virStoragePoolDefParseXML(ctxt)))
|
||||
return -1;
|
||||
|
||||
if (!(obj = virStoragePoolObjListAdd(privconn->pools, &def, 0))) {
|
||||
@ -1226,7 +1221,7 @@ testParseStorage(testDriver *privconn,
|
||||
virStoragePoolObjSetActive(obj, true);
|
||||
|
||||
/* Find storage volumes */
|
||||
if (testOpenVolumesForPool(file, ctxt, obj, i+1) < 0) {
|
||||
if (testOpenVolumesForPool(file, ctxt, obj) < 0) {
|
||||
virStoragePoolObjEndAPI(&obj);
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user