From: John Ferlan Date: Tue, 21 Jun 2016 22:17:51 +0000 (-0400) Subject: storage: Introduce virStoragePoolObjBuildTempFilePath X-Git-Tag: v2.0.0-rc1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01f4a4a070c00a85d67ce0123517a8ddb09d10e5;p=thirdparty%2Flibvirt.git 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 --- 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__ */