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