Signed-off-by: Dominic Jäger <d.jae...@proxmox.com> --- PVE/Diskmanage.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm index abb90a7..261082f 100644 --- a/PVE/Diskmanage.pm +++ b/PVE/Diskmanage.pm @@ -4,6 +4,7 @@ use strict; use warnings; use PVE::ProcFSTools; use Data::Dumper; +use File::Basename; use Cwd qw(abs_path); use Fcntl ':mode'; use JSON; @@ -761,4 +762,27 @@ sub append_partition { return $partition; } +# wipe the first 200 MB to clear off leftovers from previous use, otherwise a +# create OSD fails or create directory can fail +sub wipe_disks { + my (@devs) = @_; + + my @wipe_cmd = qw(/bin/dd if=/dev/zero bs=1M conv=fdatasync); + + foreach my $devpath (@devs) { + my $devname = basename($devpath); + my $dev_size = PVE::Tools::file_get_contents("/sys/class/block/$devname/size"); + + ($dev_size) = $dev_size =~ m|(\d+)|; # untaint $dev_size + die "Coulnd't get the size of the device $devname\n" if (!defined($dev_size)); + + my $size = ($dev_size * 512 / 1024 / 1024); + my $count = ($size < 200) ? $size : 200; + + print "wipe disk/partition: $devpath\n"; + eval { run_command([@wipe_cmd, "count=$count", "of=${devpath}"]) }; + warn $@ if $@; + } +} + 1; -- 2.20.1 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel