6d3351
From 0ea93040c8172ff8848b6295e53b7bd26f66ef05 Mon Sep 17 00:00:00 2001
6d3351
Message-Id: <0ea93040c8172ff8848b6295e53b7bd26f66ef05@dist-git>
6d3351
From: John Ferlan <jferlan@redhat.com>
6d3351
Date: Wed, 26 Apr 2017 08:41:12 -0400
6d3351
Subject: [PATCH] logical: Use virStorageBackendZeroPartitionTable
6d3351
6d3351
https://bugzilla.redhat.com/show_bug.cgi?id=1439132
6d3351
https://bugzilla.redhat.com/show_bug.cgi?id=1373711
6d3351
6d3351
Rather than open code it, use the new function which uses the wipe algorithm
6d3351
in order to zero the front and tail of the partition.
6d3351
6d3351
(cherry picked from commit c6aa81c65abe3f327af870d5789a98a0c9b276d1)
6d3351
Signed-off-by: John Ferlan <jferlan@redhat.com>
6d3351
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6d3351
---
6d3351
 src/storage/storage_backend_logical.c | 44 +----------------------------------
6d3351
 1 file changed, 1 insertion(+), 43 deletions(-)
6d3351
6d3351
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
6d3351
index d87aaf0b6..a8650368b 100644
6d3351
--- a/src/storage/storage_backend_logical.c
6d3351
+++ b/src/storage/storage_backend_logical.c
6d3351
@@ -92,9 +92,6 @@ virStorageBackendLogicalRemoveDevice(const char *path)
6d3351
 static int
6d3351
 virStorageBackendLogicalInitializeDevice(const char *path)
6d3351
 {
6d3351
-    int fd = -1;
6d3351
-    char zeros[4 * PV_BLANK_SECTOR_SIZE] = {0};
6d3351
-    off_t size;
6d3351
     int ret = -1;
6d3351
     virCommandPtr pvcmd = NULL;
6d3351
 
6d3351
@@ -103,46 +100,8 @@ virStorageBackendLogicalInitializeDevice(const char *path)
6d3351
      * a whole disk as a PV. So we just blank them out regardless
6d3351
      * rather than trying to figure out if we're a disk or partition
6d3351
      */
6d3351
-    if ((fd = open(path, O_WRONLY)) < 0) {
6d3351
-        virReportSystemError(errno, _("cannot open device '%s'"), path);
6d3351
+    if (virStorageBackendZeroPartitionTable(path, 4 * PV_BLANK_SECTOR_SIZE) < 0)
6d3351
         return -1;
6d3351
-    }
6d3351
-
6d3351
-    if ((size = lseek(fd, 0, SEEK_END)) == (off_t)-1) {
6d3351
-        virReportSystemError(errno,
6d3351
-                             _("failed to seek to end of %s"), path);
6d3351
-        goto cleanup;
6d3351
-    }
6d3351
-
6d3351
-    if (size < 4 * PV_BLANK_SECTOR_SIZE) {
6d3351
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
6d3351
-                       _("cannot initialize '%s' detected size='%zd' less "
6d3351
-                         "than minimum required='%d"),
6d3351
-                         path, (ssize_t) size, 4 * PV_BLANK_SECTOR_SIZE);
6d3351
-        goto cleanup;
6d3351
-    }
6d3351
-    if ((size = lseek(fd, 0, SEEK_SET)) == (off_t)-1) {
6d3351
-        virReportSystemError(errno,
6d3351
-                             _("failed to seek to start of %s"), path);
6d3351
-        goto cleanup;
6d3351
-    }
6d3351
-
6d3351
-    if (safewrite(fd, zeros, sizeof(zeros)) < 0) {
6d3351
-        virReportSystemError(errno, _("cannot clear device header of '%s'"),
6d3351
-                             path);
6d3351
-        goto cleanup;
6d3351
-    }
6d3351
-
6d3351
-    if (fsync(fd) < 0) {
6d3351
-        virReportSystemError(errno, _("cannot flush header of device'%s'"),
6d3351
-                             path);
6d3351
-        goto cleanup;
6d3351
-    }
6d3351
-
6d3351
-    if (VIR_CLOSE(fd) < 0) {
6d3351
-        virReportSystemError(errno, _("cannot close device '%s'"), path);
6d3351
-        goto cleanup;
6d3351
-    }
6d3351
 
6d3351
     /*
6d3351
      * Initialize the physical volume because vgcreate is not
6d3351
@@ -155,7 +114,6 @@ virStorageBackendLogicalInitializeDevice(const char *path)
6d3351
     ret = 0;
6d3351
 
6d3351
  cleanup:
6d3351
-    VIR_FORCE_CLOSE(fd);
6d3351
     virCommandFree(pvcmd);
6d3351
 
6d3351
     return ret;
6d3351
-- 
6d3351
2.12.2
6d3351