render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 0ea93040c8172ff8848b6295e53b7bd26f66ef05 Mon Sep 17 00:00:00 2001
Message-Id: <0ea93040c8172ff8848b6295e53b7bd26f66ef05@dist-git>
From: John Ferlan <jferlan@redhat.com>
Date: Wed, 26 Apr 2017 08:41:12 -0400
Subject: [PATCH] logical: Use virStorageBackendZeroPartitionTable

https://bugzilla.redhat.com/show_bug.cgi?id=1439132
https://bugzilla.redhat.com/show_bug.cgi?id=1373711

Rather than open code it, use the new function which uses the wipe algorithm
in order to zero the front and tail of the partition.

(cherry picked from commit c6aa81c65abe3f327af870d5789a98a0c9b276d1)
Signed-off-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/storage/storage_backend_logical.c | 44 +----------------------------------
 1 file changed, 1 insertion(+), 43 deletions(-)

diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index d87aaf0b6..a8650368b 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -92,9 +92,6 @@ virStorageBackendLogicalRemoveDevice(const char *path)
 static int
 virStorageBackendLogicalInitializeDevice(const char *path)
 {
-    int fd = -1;
-    char zeros[4 * PV_BLANK_SECTOR_SIZE] = {0};
-    off_t size;
     int ret = -1;
     virCommandPtr pvcmd = NULL;
 
@@ -103,46 +100,8 @@ virStorageBackendLogicalInitializeDevice(const char *path)
      * a whole disk as a PV. So we just blank them out regardless
      * rather than trying to figure out if we're a disk or partition
      */
-    if ((fd = open(path, O_WRONLY)) < 0) {
-        virReportSystemError(errno, _("cannot open device '%s'"), path);
+    if (virStorageBackendZeroPartitionTable(path, 4 * PV_BLANK_SECTOR_SIZE) < 0)
         return -1;
-    }
-
-    if ((size = lseek(fd, 0, SEEK_END)) == (off_t)-1) {
-        virReportSystemError(errno,
-                             _("failed to seek to end of %s"), path);
-        goto cleanup;
-    }
-
-    if (size < 4 * PV_BLANK_SECTOR_SIZE) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
-                       _("cannot initialize '%s' detected size='%zd' less "
-                         "than minimum required='%d"),
-                         path, (ssize_t) size, 4 * PV_BLANK_SECTOR_SIZE);
-        goto cleanup;
-    }
-    if ((size = lseek(fd, 0, SEEK_SET)) == (off_t)-1) {
-        virReportSystemError(errno,
-                             _("failed to seek to start of %s"), path);
-        goto cleanup;
-    }
-
-    if (safewrite(fd, zeros, sizeof(zeros)) < 0) {
-        virReportSystemError(errno, _("cannot clear device header of '%s'"),
-                             path);
-        goto cleanup;
-    }
-
-    if (fsync(fd) < 0) {
-        virReportSystemError(errno, _("cannot flush header of device'%s'"),
-                             path);
-        goto cleanup;
-    }
-
-    if (VIR_CLOSE(fd) < 0) {
-        virReportSystemError(errno, _("cannot close device '%s'"), path);
-        goto cleanup;
-    }
 
     /*
      * Initialize the physical volume because vgcreate is not
@@ -155,7 +114,6 @@ virStorageBackendLogicalInitializeDevice(const char *path)
     ret = 0;
 
  cleanup:
-    VIR_FORCE_CLOSE(fd);
     virCommandFree(pvcmd);
 
     return ret;
-- 
2.12.2