storage: Introduce virStoragePoolSaveConfig

https://bugzilla.redhat.com/show_bug.cgi?id=1160926

Introduce the ability to save a configuration of a persistent configuration
that may be changed by storage pool backend activity, such as start or stop
This commit is contained in:
John Ferlan 2014-11-10 12:23:46 -05:00
parent 5b226fcdc6
commit 523c6908f8
3 changed files with 25 additions and 15 deletions

View File

@ -1884,14 +1884,33 @@ virStoragePoolLoadAllConfigs(virStoragePoolObjListPtr pools,
} }
int int
virStoragePoolObjSaveDef(virStorageDriverStatePtr driver, virStoragePoolSaveConfig(const char *configFile,
virStoragePoolObjPtr pool,
virStoragePoolDefPtr def) virStoragePoolDefPtr def)
{ {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
char *xml; char *xml;
int ret = -1; int ret = -1;
if (!(xml = virStoragePoolDefFormat(def))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to generate XML"));
return -1;
}
virUUIDFormat(def->uuid, uuidstr);
ret = virXMLSaveFile(configFile,
virXMLPickShellSafeComment(def->name, uuidstr),
"pool-edit", xml);
VIR_FREE(xml);
return ret;
}
int
virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
virStoragePoolObjPtr pool,
virStoragePoolDefPtr def)
{
if (!pool->configFile) { if (!pool->configFile) {
if (virFileMakePath(driver->configDir) < 0) { if (virFileMakePath(driver->configDir) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
@ -1912,19 +1931,7 @@ virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
} }
} }
if (!(xml = virStoragePoolDefFormat(def))) { return virStoragePoolSaveConfig(pool->configFile, def);
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to generate XML"));
return -1;
}
virUUIDFormat(def->uuid, uuidstr);
ret = virXMLSaveFile(pool->configFile,
virXMLPickShellSafeComment(def->name, uuidstr),
"pool-edit", xml);
VIR_FREE(xml);
return ret;
} }
int int

View File

@ -360,6 +360,8 @@ virStoragePoolObjPtr
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
virStoragePoolDefPtr def); virStoragePoolDefPtr def);
int virStoragePoolSaveConfig(const char *configDir,
virStoragePoolDefPtr def);
int virStoragePoolObjSaveDef(virStorageDriverStatePtr driver, int virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
virStoragePoolObjPtr pool, virStoragePoolObjPtr pool,
virStoragePoolDefPtr def); virStoragePoolDefPtr def);

View File

@ -753,6 +753,7 @@ virStoragePoolObjLock;
virStoragePoolObjRemove; virStoragePoolObjRemove;
virStoragePoolObjSaveDef; virStoragePoolObjSaveDef;
virStoragePoolObjUnlock; virStoragePoolObjUnlock;
virStoragePoolSaveConfig;
virStoragePoolSourceAdapterTypeFromString; virStoragePoolSourceAdapterTypeFromString;
virStoragePoolSourceAdapterTypeToString; virStoragePoolSourceAdapterTypeToString;
virStoragePoolSourceClear; virStoragePoolSourceClear;