[pve-devel] [PATCH storage 1/2] Move wipe_disks to Diskmanage
Fabian Grünbichler
f.gruenbichler at proxmox.com
Mon Jan 27 15:57:07 CET 2020
On January 27, 2020 1:38 pm, Dominic Jäger wrote:
> Signed-off-by: Dominic Jäger <d.jaeger at 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) = @_;
these are assumed to be full blockdevs - might make sense to assert this
here and/or have a comment up top that states this assumption
> +
> + 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));
(copied) typo
> +
> + my $size = ($dev_size * 512 / 1024 / 1024);
getting the size (and other info) is already available as a helper here
in Diskmanage.pm, why not reuse it?
> + my $count = ($size < 200) ? $size : 200;
might make sense to pass this constant in as a variable?
> +
> + 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 at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>
More information about the pve-devel
mailing list