[pve-devel] [PATCH manager] Fix #2051: sub wipe_disks wipes partitions too
Alwin Antreich
a.antreich at proxmox.com
Mon Jan 21 13:44:31 CET 2019
'pveceph osd destroy <num> --cleanup'
When executing the command above, all disks associated with the OSD are
at the moment wiped with dd (incl. separate disks with DB/WAL).
The patch adds the ability to 'wipe_disks' to wipe the partition instead
of the whole disk. This preserves the sparate DB/WAL disks.
Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
PVE/API2/Ceph/OSD.pm | 8 +++-----
PVE/Ceph/Tools.pm | 20 ++++++++++++++++----
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/PVE/API2/Ceph/OSD.pm b/PVE/API2/Ceph/OSD.pm
index b4dc277e..939958d9 100644
--- a/PVE/API2/Ceph/OSD.pm
+++ b/PVE/API2/Ceph/OSD.pm
@@ -1,5 +1,6 @@
package PVE::API2::Ceph::OSD;
+
use strict;
use warnings;
@@ -394,19 +395,18 @@ __PACKAGE__->register_method ({
# try to unmount from standard mount point
my $mountpoint = "/var/lib/ceph/osd/ceph-$osdid";
- my $disks_to_wipe = {};
my $remove_partition = sub {
my ($part) = @_;
return if !$part || (! -b $part );
+ ($part) = $part =~ m|^(/.+)|; # untaint $part
my $partnum = PVE::Diskmanage::get_partnum($part);
my $devpath = PVE::Diskmanage::get_blockdev($part);
+ PVE::Ceph::Tools::wipe_disks($part);
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 = [];
@@ -443,8 +443,6 @@ __PACKAGE__->register_method ({
foreach my $part (@$partitions_to_remove) {
$remove_partition->($part);
}
-
- PVE::Ceph::Tools::wipe_disks(keys %$disks_to_wipe);
}
};
diff --git a/PVE/Ceph/Tools.pm b/PVE/Ceph/Tools.pm
index 0ada98cf..f0a3cb54 100644
--- a/PVE/Ceph/Tools.pm
+++ b/PVE/Ceph/Tools.pm
@@ -232,11 +232,23 @@ sub systemd_managed {
sub wipe_disks {
my (@devs) = @_;
- my @wipe_cmd = qw(/bin/dd if=/dev/zero bs=1M count=200 conv=fdatasync);
+ my @wipe_cmd = qw(/bin/dd if=/dev/zero bs=1M conv=fdatasync);
+ my $count = 200;
+ my @blockdev = qw(/sbin/blockdev --getsize64);
+ my $dev_size = 0;
+
foreach my $devpath (@devs) {
- print "wipe disk: $devpath\n";
- eval { run_command([@wipe_cmd, "of=${devpath}"]) };
- warn $@ if $@;
+ eval { run_command([@blockdev, "$devpath"],
+ outfunc => sub { $dev_size = shift; })};
+ warn $@ if $@;
+
+ my $size = ($dev_size / 1024 / 1024);
+ $count = $size if ($size lt $count);
+ push @wipe_cmd, "count=$count";
+
+ print "wipe disk/partition: $devpath\n";
+ eval { run_command([@wipe_cmd, "of=${devpath}"]) };
+ warn $@ if $@;
}
};
--
2.11.0
More information about the pve-devel
mailing list