提交 a9700771 编写于 作者: E Erik Skultety

conf: Introduce virStoragePoolLoadAllState && virStoragePoolLoadState

These functions operate exactly the same as their network equivalents
virNetworkLoadAllState, virNetworkLoadState.
上级 723143a1
......@@ -1860,6 +1860,100 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
}
virStoragePoolObjPtr
virStoragePoolLoadState(virStoragePoolObjListPtr pools,
const char *stateDir,
const char *name)
{
char *stateFile = NULL;
virStoragePoolDefPtr def = NULL;
virStoragePoolObjPtr pool = NULL;
xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr node = NULL;
if (!(stateFile = virFileBuildPath(stateDir, name, ".xml")))
goto error;
if (!(xml = virXMLParseCtxt(stateFile, NULL, _("(pool state)"), &ctxt)))
goto error;
if (!(node = virXPathNode("//pool", ctxt))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not find any 'pool' element in state file"));
goto error;
}
ctxt->node = node;
if (!(def = virStoragePoolDefParseXML(ctxt)))
goto error;
if (!STREQ(name, def->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Storage pool state file '%s' does not match "
"pool name '%s'"),
stateFile, def->name);
goto error;
}
/* create the object */
if (!(pool = virStoragePoolObjAssignDef(pools, def)))
goto error;
/* XXX: future handling of some additional useful status data,
* for now, if a status file for a pool exists, the pool will be marked
* as active
*/
pool->active = 1;
cleanup:
VIR_FREE(stateFile);
xmlFree(xml);
xmlXPathFreeContext(ctxt);
return pool;
error:
virStoragePoolDefFree(def);
goto cleanup;
}
int
virStoragePoolLoadAllState(virStoragePoolObjListPtr pools,
const char *stateDir)
{
DIR *dir;
struct dirent *entry;
int ret = -1;
if (!(dir = opendir(stateDir))) {
if (errno == ENOENT)
return 0;
virReportSystemError(errno, _("Failed to open dir '%s'"), stateDir);
return -1;
}
while ((ret = virDirRead(dir, &entry, stateDir)) > 0) {
virStoragePoolObjPtr pool;
if (entry->d_name[0] == '.')
continue;
if (!virFileStripSuffix(entry->d_name, ".xml"))
continue;
if (!(pool = virStoragePoolLoadState(pools, stateDir, entry->d_name)))
continue;
virStoragePoolObjUnlock(pool);
}
closedir(dir);
return ret;
}
int
virStoragePoolLoadAllConfigs(virStoragePoolObjListPtr pools,
const char *configDir,
......
......@@ -318,6 +318,13 @@ int virStoragePoolLoadAllConfigs(virStoragePoolObjListPtr pools,
const char *configDir,
const char *autostartDir);
int virStoragePoolLoadAllState(virStoragePoolObjListPtr pools,
const char *stateDir);
virStoragePoolObjPtr
virStoragePoolLoadState(virStoragePoolObjListPtr pools,
const char *stateDir,
const char *name);
virStoragePoolObjPtr
virStoragePoolObjFindByUUID(virStoragePoolObjListPtr pools,
const unsigned char *uuid);
......
......@@ -811,6 +811,7 @@ virStoragePoolFormatFileSystemNetTypeToString;
virStoragePoolFormatFileSystemTypeToString;
virStoragePoolGetVhbaSCSIHostParent;
virStoragePoolLoadAllConfigs;
virStoragePoolLoadAllState;
virStoragePoolObjAssignDef;
virStoragePoolObjClearVols;
virStoragePoolObjDeleteDef;
......
......@@ -197,6 +197,17 @@ storageStateInitialize(bool privileged,
}
driver->privileged = privileged;
if (virFileMakePath(driver->stateDir) < 0) {
virReportError(errno,
_("cannot create directory %s"),
driver->stateDir);
goto error;
}
if (virStoragePoolLoadAllState(&driver->pools,
driver->stateDir) < 0)
goto error;
if (virStoragePoolLoadAllConfigs(&driver->pools,
driver->configDir,
driver->autostartDir) < 0)
......@@ -245,6 +256,8 @@ storageStateReload(void)
return -1;
storageDriverLock();
virStoragePoolLoadAllState(&driver->pools,
driver->stateDir);
virStoragePoolLoadAllConfigs(&driver->pools,
driver->configDir,
driver->autostartDir);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册