]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Introduce virStoragePoolObjBuildTempFilePath
authorJohn Ferlan <jferlan@redhat.com>
Tue, 21 Jun 2016 22:17:51 +0000 (18:17 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 24 Jun 2016 17:42:38 +0000 (13:42 -0400)
Create a function to return a temporary file path to be used in a mkostemp
type call using the path to the stateDir + pool->def->name + vol->name

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/storage/storage_driver.c
src/storage/storage_driver.h

index cef21249dabf1f2e2c3492f4bf5b48bd606b9631..831e6b04ecab943584ae6fe745dffeaf476411a3 100644 (file)
@@ -3602,3 +3602,27 @@ virStoragePoolObjFindPoolByUUID(const unsigned char *uuid)
     storageDriverUnlock();
     return pool;
 }
+
+
+/*
+ * virStoragePoolObjBuildTempFilePath
+ * @pool: pool object pointer
+ * @vol: volume definition
+ *
+ * Generate a name for a temporary file using the driver stateDir
+ * as a path, the pool name, and the volume name to be used as input
+ * for a mkostemp
+ *
+ * Returns a string pointer on success, NULL on failure
+ */
+char *
+virStoragePoolObjBuildTempFilePath(virStoragePoolObjPtr pool,
+                                   virStorageVolDefPtr vol)
+
+{
+    char *tmp = NULL;
+
+    ignore_value(virAsprintf(&tmp, "%s/%s.%s.secret.XXXXXX",
+                             driver->stateDir, pool->def->name, vol->name));
+    return tmp;
+}
index 912c232c38076119e96ff295581ae4da682cd1dd..3f2549da54b832201bee356122d1111fdb66e2a5 100644 (file)
@@ -65,6 +65,10 @@ storagePoolLookupByTargetPath(virConnectPtr conn,
                               const char *path)
     ATTRIBUTE_NONNULL(2);
 
+char *virStoragePoolObjBuildTempFilePath(virStoragePoolObjPtr pool,
+                                         virStorageVolDefPtr vol)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+
 int storageRegister(void);
 
 #endif /* __VIR_STORAGE_DRIVER_H__ */