From 456a7f4d34d1ae35df4f8ba58943013baf939d84 Mon Sep 17 00:00:00 2001 From: Alwin Antreich Date: Tue, 27 Nov 2018 16:02:56 +0100 Subject: [PATCH] Factoring the wipe_disk out into CephTools Signed-off-by: Alwin Antreich --- 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 3f2bb11d..401c0e5b 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.39.5