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