marsadm: allow devices as size argument

This commit is contained in:
Thomas Schoebel-Theuer 2016-01-26 11:44:09 +01:00 committed by Thomas Schoebel-Theuer
parent f4f9ba93e2
commit 08c776fc36
1 changed files with 8 additions and 0 deletions

View File

@ -1095,6 +1095,14 @@ sub try_to_avoid_splitbrain {
sub get_size {
my $arg = shift;
my $orig_arg = $arg;
# Do what I mean: when given a device, take its actual size.
if (-b $arg) {
my $mangled = $arg;
$mangled =~ s:/dev/::;
$mangled =~ s:/:!:g;
my $path = "/sys/block/$mangled/size";
$arg = `cat $path` * 512 if -r $path;
}
if ($arg !~ m/^([0-9]+(?:\.[0-9]*)?)([kmgtp]?)$/i) {
ldie "Size argument '$arg' must be a number, optionally followed by a suffix [kKmMgGtTpP]. Lowercase = multiples of 1000, Uppercase = multiples of 1024.\n";
}