From 662416ecb4297ad7d9cfe90e04f4abbab59119be Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Fri, 21 Nov 2008 01:40:47 +0000 Subject: [PATCH] Nice size field for new LVs --- lvm/edit_lv.cgi | 13 +++++++++++-- lvm/lvm-lib.pl | 24 ++++++++++++++++++++++++ lvm/save_lv.cgi | 5 +++++ ui-lib.pl | 12 +++++++++--- web-lib-funcs.pl | 1 + 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/lvm/edit_lv.cgi b/lvm/edit_lv.cgi index 6695c46e3..d101e5ab3 100755 --- a/lvm/edit_lv.cgi +++ b/lvm/edit_lv.cgi @@ -21,6 +21,7 @@ else { 'is_snap' => $in{'snap'}, 'size' => ($vg->{'pe_total'} - $vg->{'pe_alloc'})* $vg->{'pe_size'} }; + $lv->{'size'} = &nice_round($lv->{'size'}); } print &ui_form_start("save_lv.cgi"); @@ -40,8 +41,16 @@ else { print &ui_table_row($text{'lv_name'}, &ui_textbox("name", $lv->{'name'}, 20)); - print &ui_table_row($text{'lv_size'}, - &ui_textbox("size", $lv->{'size'}, 8)." kB"); + if (!$in{'lv'}) { + # Can show nice size chooser + print &ui_table_row($text{'lv_size'}, + &ui_bytesbox("size", $lv->{'size'}*1024, 8)); + } + else { + # Show in exactly kB + print &ui_table_row($text{'lv_size'}, + &ui_textbox("size", $lv->{'size'}, 8)." kB"); + } } # Number of physical extents diff --git a/lvm/lvm-lib.pl b/lvm/lvm-lib.pl index f87f88faa..705d1d2f2 100644 --- a/lvm/lvm-lib.pl +++ b/lvm/lvm-lib.pl @@ -657,5 +657,29 @@ local $ver = $out =~ /\s+([0-9\.]+)/ ? $1 : undef; return wantarray ? ( $ver, $out ) : $ver; } +# nice_round(number) +# Round some number to TB, GB, MB or kB, depending on size +sub nice_round +{ +local ($bytes) = @_; +my $units; +if ($bytes >= 10*1024*1024*1024*1024) { + $units = 1024*1024*1024*1024; + } +elsif ($bytes >= 10*1024*1024*1024) { + $units = 1024*1024*1024; + } +elsif ($bytes >= 10*1024*1024) { + $units = 1024*1024; + } +elsif ($bytes >= 10*1024) { + $units = 1024; + } +else { + $units = 1; + } +return int($bytes / $units) * $units; +} + 1; diff --git a/lvm/save_lv.cgi b/lvm/save_lv.cgi index 483f5db5a..79727931a 100755 --- a/lvm/save_lv.cgi +++ b/lvm/save_lv.cgi @@ -40,6 +40,11 @@ else { $same && (!$in{'lv'} || $in{'lv'} ne $in{'name'}) && &error($text{'lv_esame'}); $in{'size'} =~ /^\d+$/ || &error($text{'lv_esize'}); + if (defined($in{'size_units'})) { + # Convert selected units to kB + $in{'size'} = $in{'size'}*$in{'size_units'}/1024; + delete($in{'size_units'}); + } $in{'snap'} || $in{'lv'} || $in{'stripe_def'} || $in{'stripe'} =~ /^[1-9]\d*$/ || &error($text{'lv_estripe'}); diff --git a/ui-lib.pl b/ui-lib.pl index a20a1480b..8a9a1c9ed 100644 --- a/ui-lib.pl +++ b/ui-lib.pl @@ -466,7 +466,10 @@ sub ui_bytesbox { my ($name, $bytes, $size, $dis) = @_; my $units = 1; -if ($bytes >= 10*1024*1024*1024) { +if ($bytes >= 10*1024*1024*1024*1024) { + $units = 1024*1024*1024*1024; + } +elsif ($bytes >= 10*1024*1024*1024) { $units = 1024*1024*1024; } elsif ($bytes >= 10*1024*1024) { @@ -485,8 +488,11 @@ if ($bytes ne "") { $size = &ui_max_text_width($size || 8); return &ui_textbox($name, $bytes, $size, $dis)." ". &ui_select($name."_units", $units, - [ [ 1, "bytes" ], [ 1024, "kB" ], [ 1024*1024, "MB" ], - [ 1024*1024*1024, "GB" ] ], undef, undef, undef, $dis); + [ [ 1, "bytes" ], + [ 1024, "kB" ], + [ 1024*1024, "MB" ], + [ 1024*1024*1024, "GB" ], + [ 1024*1024*1024*1024, "TB" ] ], undef, undef, undef, $dis); } # ui_upload(name, size, [disabled?], [tags]) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 22e39656e..b3b35f349 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -1597,6 +1597,7 @@ if ($rcode == 303 || $rcode == 302 || $rcode == 301) { $page = $header{'location'}; } elsif ($header{'location'}) { + # Assume relative to same dir if ($_[2]) { ${$_[2]} = "Invalid Location header $header{'location'}"; return; } else { &error("Invalid Location header $header{'location'}"); } }