[pve-devel] [PATCH v3 manager] add wipe_disk option when destroying ceph disk

David Limbeck d.limbeck at proxmox.com
Wed Oct 24 11:13:41 CEST 2018


this allows the disk to be reused as ceph disk by zeroing the first 200M
of the destroyed disk. disks are iterated separately from partitions to
prevent duplicate wipes.

Signed-off-by: David Limbeck <d.limbeck at proxmox.com>
---
since v2:
    incorporated Thomas' suggestions combining remove_partition and the
    generation of the disk set

 PVE/API2/Ceph.pm | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index 69489a70..493131e6 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -398,7 +398,7 @@ __PACKAGE__->register_method ({
 	    my $mountpoint = "/var/lib/ceph/osd/ceph-$osdid";
 
 	    my $remove_partition = sub {
-		my ($part) = @_;
+		my ($part, $disks_to_wipe) = @_;
 
 		return if !$part || (! -b $part );
 		my $partnum = PVE::Diskmanage::get_partnum($part);
@@ -407,6 +407,8 @@ __PACKAGE__->register_method ({
 		print "remove partition $part (disk '${devpath}', partnum $partnum)\n";
 		eval { run_command(['/sbin/sgdisk', '-d', $partnum, "${devpath}"]); };
 		warn $@ if $@;
+
+		$disks_to_wipe->{$devpath} = 1;
 	    };
 
 	    my $partitions_to_remove = [];
@@ -434,14 +436,21 @@ __PACKAGE__->register_method ({
 		}
 	    }
 
+
 	    print "Unmount OSD $osdsection from  $mountpoint\n";
 	    eval { run_command(['/bin/umount', $mountpoint]); };
 	    if (my $err = $@) {
 		warn $err;
 	    } elsif ($param->{cleanup}) {
 		#be aware of the ceph udev rules which can remount.
+		my $disks_to_wipe = {};
 		foreach my $part (@$partitions_to_remove) {
-		    $remove_partition->($part);
+		    $remove_partition->($part, $disks_to_wipe);
+		}
+		foreach my $devpath (keys %$disks_to_wipe) {
+		    print "wipe disk: $devpath\n";
+		    eval { run_command(['/bin/dd', 'if=/dev/zero', "of=${devpath}", 'bs=1M', 'count=200', 'conv=fdatasync']); };
+		    warn $@ if $@;
 		}
 	    }
 	};
-- 
2.11.0





More information about the pve-devel mailing list