From 01f4a4a070c00a85d67ce0123517a8ddb09d10e5 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Tue, 21 Jun 2016 18:17:51 -0400 Subject: [PATCH] storage: Introduce virStoragePoolObjBuildTempFilePath 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 --- src/storage/storage_driver.c | 24 ++++++++++++++++++++++++ src/storage/storage_driver.h | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index cef21249da..831e6b04ec 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -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; +} diff --git a/src/storage/storage_driver.h b/src/storage/storage_driver.h index 912c232c38..3f2549da54 100644 --- a/src/storage/storage_driver.h +++ b/src/storage/storage_driver.h @@ -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.47.2