[libvirt] [PATCH v2 10/15] storage: Introduce virStoragePoolObjBuildTempFilePath

John Ferlan jferlan at redhat.com
Thu Jun 23 17:29:06 UTC 2016


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 at redhat.com>
---
 src/storage/storage_driver.c | 24 ++++++++++++++++++++++++
 src/storage/storage_driver.h |  6 +++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 4b5419d..92a1fb9 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -3608,3 +3608,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;
+}
diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h
index 912c232..99c58bc 100644
--- a/src/storage/storage_driver.h
+++ b/src/storage/storage_driver.h
@@ -1,7 +1,7 @@
 /*
  * storage_driver.h: core driver for storage APIs
  *
- * Copyright (C) 2006-2008, 2014 Red Hat, Inc.
+ * Copyright (C) 2006-2008, 2014-2016 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -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__ */
-- 
2.5.5




More information about the libvir-list mailing list