From 5d4d146cfe4ab4e52c8ba0300f6a05949bc558d4 Mon Sep 17 00:00:00 2001 Message-Id: <5d4d146cfe4ab4e52c8ba0300f6a05949bc558d4@dist-git> From: John Ferlan Date: Wed, 26 Apr 2017 08:41:11 -0400 Subject: [PATCH] storage: Introduce virStorageBackendZeroPartitionTable https://bugzilla.redhat.com/show_bug.cgi?id=1439132 Create a wrapper/helper that can be used to call the storage backend wipe helper - storageBackendVolWipeLocalFile for future use by logical and disk backends to clear out the partition table rather than having each open code the same algorithm. (cherry picked from commit e8b02124580e134c8a6d51750016811b1d68b80e) Signed-off-by: John Ferlan Signed-off-by: Jiri Denemark --- src/storage/storage_util.c | 22 ++++++++++++++++++++++ src/storage/storage_util.h | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 8dbdc770e..da2396b34 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -4071,3 +4071,25 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, return found; } + + +/* + * @path: Path to the device to initialize + * @size: Size to be cleared + * + * Zero out possible partition table information for the specified + * bytes from the start of the @path and from the end of @path + * + * Returns 0 on success, -1 on failure with error message set + */ +int +virStorageBackendZeroPartitionTable(const char *path, + unsigned long long size) +{ + if (storageBackendVolWipeLocalFile(path, VIR_STORAGE_VOL_WIPE_ALG_ZERO, + size, false) < 0) + return -1; + + return storageBackendVolWipeLocalFile(path, VIR_STORAGE_VOL_WIPE_ALG_ZERO, + size, true); +} diff --git a/src/storage/storage_util.h b/src/storage/storage_util.h index fa3b6522c..2c48027f4 100644 --- a/src/storage/storage_util.h +++ b/src/storage/storage_util.h @@ -163,4 +163,8 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, int virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, uint32_t scanhost); +int +virStorageBackendZeroPartitionTable(const char *path, + unsigned long long size); + #endif /* __VIR_STORAGE_UTIL_H__ */ -- 2.12.2