[PATCH 2/3] storage: Introduce virStorageVol{Save|Delete}Status

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

This patch introduces two generic storage_conf functions to handle
saving and deleting the volume XML to/from the stateDir.

The virStorageVolSaveStatus will format the volume XML into a file
and save the file in pool->stateDir.

The virStorageVolDeleteStatus will search for the file in the stateDir
and remove it.

These are useful for certain fields/data in the volume XML that cannot
be determined or saved along with the volume or in some meta-data for
the volume. Prior to a pool refresh operation the pool's volume list
is cleared in order to be restored during the refresh. If there were
fields that are not otherwise obtainable, the defaults will be used
which may or may not be correct.

Additionally, the libvirtd daemon reload/restart processing will be
able to make use of the saved XML data and follow the same path with
respect to regenerating the list of volumes in the pool and thus not
having the same issue.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/storage_conf.c  | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/storage_conf.h  |  6 +++++
 src/libvirt_private.syms |  2 ++
 3 files changed, 65 insertions(+)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 0901dca..9ea00e5 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1662,6 +1662,63 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
 }
 
 
+int
+virStorageVolSaveStatus(virStoragePoolObjPtr pool,
+                        virStorageVolDefPtr vol)
+{
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+    char *xml = NULL;
+    char *statusFile = NULL;
+    int ret = -1;
+
+    if (virAsprintf(&statusFile, "%s/%s.xml", pool->stateDir, vol->name) < 0)
+        goto cleanup;
+
+    if (!(xml = virStorageVolDefFormat(pool->def, vol))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("failed to generate XML"));
+        goto cleanup;
+    }
+
+    virUUIDFormat(pool->def->uuid, uuidstr);
+    ret = virXMLSaveFile(statusFile,
+                         virXMLPickShellSafeComment(vol->name, uuidstr),
+                         "vol-edit", xml);
+ cleanup:
+    VIR_FREE(xml);
+    VIR_FREE(statusFile);
+    return ret;
+}
+
+
+int
+virStorageVolDeleteStatus(virStoragePoolObjPtr pool,
+                          virStorageVolDefPtr vol)
+{
+    char *statusFile = NULL;
+    int ret = -1;
+
+    if (virAsprintf(&statusFile, "%s/%s.xml", pool->stateDir, vol->name) < 0)
+        goto cleanup;
+
+    if (virFileExists(statusFile)) {
+        if (unlink(statusFile) < 0) {
+            virReportSystemError(errno,
+                                 _("cannot remove vol status file '%s'"),
+                                 statusFile);
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(statusFile);
+
+    return ret;
+}
+
+
 virStoragePoolObjPtr
 virStoragePoolObjFindByUUID(virStoragePoolObjListPtr pools,
                             const unsigned char *uuid)
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 064c78c..9f25287 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -360,6 +360,12 @@ virStorageVolDefParseNode(virStoragePoolDefPtr pool,
                           xmlNodePtr root);
 char *virStorageVolDefFormat(virStoragePoolDefPtr pool,
                              virStorageVolDefPtr def);
+int virStorageVolSaveStatus(virStoragePoolObjPtr pool,
+                            virStorageVolDefPtr vol)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+int virStorageVolDeleteStatus(virStoragePoolObjPtr pool,
+                              virStorageVolDefPtr vol)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
 virStoragePoolObjPtr
 virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7ceb54d..a84a293 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -784,6 +784,8 @@ virStorageVolDefFree;
 virStorageVolDefParseFile;
 virStorageVolDefParseNode;
 virStorageVolDefParseString;
+virStorageVolDeleteStatus;
+virStorageVolSaveStatus;
 virStorageVolTypeFromString;
 virStorageVolTypeToString;
 
-- 
2.1.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]