[pve-devel] [PATCH manager v2] Factoring the wipe_disk out into CephTools

Alwin Antreich a.antreich at proxmox.com
Tue Nov 27 16:02:56 CET 2018


Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
 PVE/API2/Ceph.pm |  9 +++------
 PVE/CephTools.pm | 13 +++++++++++++
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index d74bd016..f9be80e4 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -312,6 +312,7 @@ __PACKAGE__->register_method ({
 		}
 	    }
 
+	    PVE::CephTools::wipe_disk($devpath);
 
 	    run_command($cmd);
 	};
@@ -439,12 +440,8 @@ __PACKAGE__->register_method ({
 		foreach my $part (@$partitions_to_remove) {
 		    $remove_partition->($part);
 		}
-		my @wipe_cmd = qw(/bin/dd if=/dev/zero bs=1M count=200 conv=fdatasync);
-		foreach my $devpath (keys %$disks_to_wipe) {
-		    print "wipe disk: $devpath\n";
-		    eval { run_command([@wipe_cmd, "of=${devpath}"]) };
-		    warn $@ if $@;
-		}
+
+		PVE::CephTools::wipe_disk(keys %$disks_to_wipe);
 	    }
 	};
 
diff --git a/PVE/CephTools.pm b/PVE/CephTools.pm
index 8ee34d14..8d445621 100644
--- a/PVE/CephTools.pm
+++ b/PVE/CephTools.pm
@@ -469,4 +469,17 @@ sub destroy_mds {
     return undef;
 };
 
+# wipe the first 200 MB to clear off leftovers from previous use, otherwise a
+# create OSD fails.
+sub wipe_disk {
+    my (@devs) = @_;
+
+    my @wipe_cmd = qw(/bin/dd if=/dev/zero bs=1M count=200 conv=fdatasync);
+    foreach my $devpath (values @devs) {
+        print "wipe disk: $devpath\n";
+        eval { run_command([@wipe_cmd, "of=${devpath}"]) };
+        warn $@ if $@;
+    }
+};
+
 1;
-- 
2.11.0





More information about the pve-devel mailing list