From 08c776fc36fd1ac98b3783b641a7b0f529a06c5c Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Tue, 26 Jan 2016 11:44:09 +0100 Subject: [PATCH] marsadm: allow devices as size argument --- userspace/marsadm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/userspace/marsadm b/userspace/marsadm index 0b63e400..9048c682 100755 --- a/userspace/marsadm +++ b/userspace/marsadm @@ -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"; }