2 # Common functions for managing VGs, PVs and LVs
4 BEGIN { push(@INC, ".."); };
7 &foreign_require("mount");
8 if (&foreign_check("raid")) {
9 &foreign_require("raid");
12 &foreign_require("fdisk");
14 $lvm_proc = "/proc/lvm";
15 $lvm_tab = "/etc/lvmtab";
17 # list_physical_volumes(vg)
18 # Returns a list of all physical volumes for some volume group
19 sub list_physical_volumes
23 # Get list from /proc/lvm
24 opendir(DIR, "$lvm_proc/VGs/$_[0]/PVs");
25 foreach $f (readdir(DIR)) {
26 next if ($f eq '.' || $f eq '..');
27 local $pv = { 'name' => $f,
29 local %p = &parse_colon_file("$lvm_proc/VGs/$_[0]/PVs/$f");
30 $pv->{'device'} = $p{'name'};
31 $pv->{'number'} = $p{'number'};
32 $pv->{'size'} = $p{'size'}/2;
33 $pv->{'status'} = $p{'status'};
34 $pv->{'number'} = $p{'number'};
35 $pv->{'pe_size'} = $p{'PE size'};
36 $pv->{'pe_total'} = $p{'PE total'};
37 $pv->{'pe_alloc'} = $p{'PE allocated'};
38 $pv->{'alloc'} = $p{'allocatable'} == 2 ? 'y' : 'n';
44 # Use pvdisplay command
47 open(DISPLAY, "pvdisplay 2>/dev/null |");
50 if (/PV\s+Name\s+(.*)/i) {
53 'number' => scalar(@rv) };
54 $pv->{'name'} =~ s/^\/dev\///;
57 elsif (/VG\s+Name\s+(.*)/i) {
59 $pv->{'vg'} =~ s/\s+\(.*\)//;
61 elsif (/PV\s+Size\s+(\S+)\s+(\S+)/i) {
62 $pv->{'size'} = &mult_units($1, $2);
64 elsif (/PE\s+Size\s+\(\S+\)\s+(\S+)/i) {
65 $pv->{'pe_size'} = $1;
67 elsif (/PE\s+Size\s+(\S+)\s+(\S+)/i) {
68 $pv->{'pe_size'} = &mult_units($1, $2);
70 elsif (/Total\s+PE\s+(\S+)/i) {
71 $pv->{'pe_total'} = $1;
73 elsif (/Allocated\s+PE\s+(\S+)/i) {
74 $pv->{'pe_alloc'} = $1;
76 elsif (/Allocatable\s+(\S+)/i) {
77 $pv->{'alloc'} = lc($1) eq 'yes' ? 'y' : 'n';
81 @rv = grep { $_->{'vg'} eq $_[0] } @rv;
86 # get_physical_volume_usage(&lv)
87 # Returns a list of LVs and blocks used on this physical volume
88 sub get_physical_volume_usage
91 open(DISPLAY, "pvdisplay -m ".quotemeta($_[0]->{'device'})." 2>/dev/null |");
94 if (/Physical\s+extent\s+(\d+)\s+to\s+(\d+)/) {
95 $lastlen = $2 - $1 + 1;
97 elsif (/Logical\s+volume\s+\/dev\/(\S+)\/(\S+)/) {
98 push(@rv, [ $2, $lastlen ]);
105 # create_physical_volume(&pv, [force])
106 # Add a new physical volume to a volume group
107 sub create_physical_volume
109 local $cmd = "pvcreate -y ".($_[1] ? "-ff " : "-f ");
110 $cmd .= quotemeta($_[0]->{'device'});
111 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
113 $cmd = "vgextend ".quotemeta($_[0]->{'vg'})." ".quotemeta($_[0]->{'device'});
114 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
115 return $? ? $out : undef;
118 # change_physical_volume(&pv)
119 # Change the allocation flag for a physical volume
120 sub change_physical_volume
122 local $cmd = "pvchange -x ".quotemeta($_[0]->{'alloc'}).
123 " ".quotemeta($_[0]->{'device'});
124 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
125 return $? ? $out : undef;
128 # delete_physical_volume(&pv)
129 # Remove a physical volume from a volume group
130 sub delete_physical_volume
132 if ($_[0]->{'pe_alloc'}) {
134 if (&get_lvm_version() >= 2) {
135 $cmd = "yes | pvmove ".quotemeta($_[0]->{'device'});
138 $cmd = "pvmove -f ".quotemeta($_[0]->{'device'});
140 local $out = &backquote_logged("$cmd 2>&1");
141 return $out if ($? && $out !~ /\-\-\s+f/);
143 local $cmd = "vgreduce ".quotemeta($_[0]->{'vg'})." ".
144 quotemeta($_[0]->{'device'});
145 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
146 return $? ? $out : undef;
149 # resize_physical_volume(&pv)
150 # Set the size of a physical volume to match the underlying device
151 sub resize_physical_volume
153 local $cmd = "pvresize ".quotemeta($_[0]->{'device'});
154 local $out = &backquote_logged("$cmd 2>&1");
155 return $? ? $out : undef;
158 # list_volume_groups()
159 # Returns a list of all volume groups
160 sub list_volume_groups
165 opendir(DIR, "$lvm_proc/VGs");
166 foreach $f (readdir(DIR)) {
167 next if ($f eq '.' || $f eq '..');
168 local $vg = { 'name' => $f };
169 local %g = &parse_colon_file("$lvm_proc/VGs/$f/group");
170 $vg->{'number'} = $g{'number'};
171 $vg->{'size'} = $g{'size'};
172 $vg->{'pe_size'} = $g{'PE size'};
173 $vg->{'pe_total'} = $g{'PE total'};
174 $vg->{'pe_alloc'} = $g{'PE allocated'};
180 # Parse output of vgdisplay
182 open(DISPLAY, "vgdisplay 2>/dev/null |");
185 if (/VG\s+Name\s+(.*)/i) {
186 $vg = { 'name' => $1 };
189 elsif (/VG\s+Size\s+(\S+)\s+(\S+)/i) {
190 $vg->{'size'} = &mult_units($1, $2);
192 elsif (/PE\s+Size\s+(\S+)\s+(\S+)/i) {
193 $vg->{'pe_size'} = &mult_units($1, $2);
195 elsif (/Total\s+PE\s+(\d+)/i) {
196 $vg->{'pe_total'} = $1;
198 elsif (/Alloc\s+PE\s+\/\s+Size\s+(\d+)/i) {
199 $vg->{'pe_alloc'} = $1;
210 return $n*(uc($u) eq "KB" || uc($u) eq "KIB" ? 1 :
211 uc($u) eq "MB" || uc($u) eq "MIB" ? 1024 :
212 uc($u) eq "GB" || uc($u) eq "GIB" ? 1024*1024 :
213 uc($u) eq "TB" || uc($u) eq "TIB" ? 1024*1024*1024 :
214 uc($u) eq "PB" || uc($u) eq "PIB" ? 1024*1024*1024 : 1);
217 # delete_volume_group(&vg)
218 sub delete_volume_group
220 local $cmd = "vgchange -a n ".quotemeta($_[0]->{'name'});
221 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
223 $cmd = "vgremove ".quotemeta($_[0]->{'name'});
224 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
225 return $? ? $out : undef;
228 # create_volume_group(&vg, device)
229 sub create_volume_group
231 &system_logged("vgscan >/dev/null 2>&1 </dev/null");
232 local $cmd = "pvcreate -f -y ".quotemeta($_[1]);
233 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
236 $cmd .= " -s ".quotemeta($_[0]->{'pe_size'})."k" if ($_[0]->{'pe_size'});
237 $cmd .= " ".quotemeta($_[0]->{'name'})." ".quotemeta($_[1]);
238 $out = &backquote_logged("$cmd 2>&1 </dev/null");
239 return $? ? $out : undef;
242 # rename_volume_group(&vg, name)
243 sub rename_volume_group
245 local $cmd = "vgrename ".quotemeta($_[0]->{'name'})." ".quotemeta($_[1]);
246 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
248 $cmd = "vgchange -a n ".quotemeta($_[1]);
249 $out = &backquote_logged("$cmd 2>&1 </dev/null");
251 $cmd = "vgchange -a y ".quotemeta($_[1]);
252 $out = &backquote_logged("$cmd 2>&1 </dev/null");
253 return $? ? $out : undef;
257 # list_logical_volumes(vg)
258 sub list_logical_volumes
262 # Get LVs from /proc/lvm
263 opendir(DIR, "$lvm_proc/VGs/$_[0]/LVs");
264 foreach $f (readdir(DIR)) {
265 next if ($f eq '.' || $f eq '..');
266 local $lv = { 'name' => $f,
268 local %p = &parse_colon_file("$lvm_proc/VGs/$_[0]/LVs/$f");
269 $lv->{'device'} = $p{'name'};
270 $lv->{'number'} = $p{'number'};
271 $lv->{'size'} = $p{'size'}/2;
272 $lv->{'perm'} = $p{'access'} == 3 ? 'rw' : 'r';
273 $lv->{'alloc'} = $p{'allocation'} == 2 ? 'y' : 'n';
274 $lv->{'has_snap'} = $p{'access'} == 11;
275 $lv->{'is_snap'} = $p{'access'} == 5;
276 $lv->{'stripes'} = $p{'stripes'};
279 # For snapshots, use the lvdisplay command to get usage
280 if ($lv->{'is_snap'}) {
281 local $out = &backquote_command(
282 "lvdisplay ".quotemeta($lv->{'device'}).
284 if ($out =~/Allocated\s+to\s+snapshot\s+([0-9\.]+)%/i) {
285 $lv->{'snapusage'} = $1;
292 # Use the lvdisplay command
295 local ($vg) = grep { $_->{'name'} eq $_[0] } &list_volume_groups();
296 open(DISPLAY, "lvdisplay -m 2>/dev/null |");
299 if (/LV\s+Name\s+(.*\/(\S+))/i) {
300 $lv = { 'name' => $2,
302 'number' => scalar(@rv) };
305 elsif (/VG\s+Name\s+(.*)/) {
308 elsif (/LV\s+Size\s+(\S+)\s+(\S+)/i) {
309 $lv->{'size'} = &mult_units($1, $2);
311 elsif (/Current\s+LE\s+(\d+)/ && $vg) {
312 $lv->{'size'} = $1 * $vg->{'pe_size'};
314 elsif (/LV\s+Write\s+Access\s+(\S+)/i) {
315 $lv->{'perm'} = $1 eq 'read/write' ? 'rw' : 'r';
317 elsif (/Allocation\s+(.*)/i) {
318 $lv->{'alloc'} = $1 eq 'contiguous' ? 'y' : 'n';
320 elsif (/LV\s+snapshot\s+status\s+(.*)/i) {
321 if ($1 =~ /source/) {
322 $lv->{'has_snap'} = 1;
325 $lv->{'is_snap'} = 1;
327 if (/destination\s+for\s+\/dev\/[^\/]+\/(\S+)/) {
328 $lv->{'snap_of'} = $1;
331 elsif (/Read ahead sectors\s+(\d+)/) {
332 $lv->{'readahead'} = $1;
334 elsif (/Stripes\s+(\d+)/) {
335 $lv->{'stripes'} = $1;
337 elsif (/Stripe\s+size\s+(\S+)\s+(\S+)/) {
338 $lv->{'stripesize'} = &mult_units($1, $2);
340 elsif (/Allocated\s+to\s+snapshot\s+([0-9\.]+)%/i) {
341 $lv->{'snapusage'} = $1;
345 @rv = grep { $_->{'vg'} eq $_[0] } @rv;
350 # get_logical_volume_usage(&lv)
351 # Returns a list of PVs and blocks used by this logical volume. Each is an
352 # array ref of : device physical-blocks reads writes
353 sub get_logical_volume_usage
356 if (&get_lvm_version() >= 2) {
357 # LVdisplay has new format in version 2
358 open(DISPLAY, "lvdisplay -m ".quotemeta($_[0]->{'device'})." 2>/dev/null |");
360 if (/\s+Physical\s+volume\s+\/dev\/(\S+)/) {
361 push(@rv, [ $1, undef ]);
363 elsif (/\s+Physical\s+extents\s+(\d+)\s+to\s+(\d+)/ && @rv) {
364 $rv[$#rv]->[1] = $2-$1+1;
370 # Old version 1 format
371 open(DISPLAY, "lvdisplay -v ".quotemeta($_[0]->{'device'})." 2>/dev/null |");
374 if (/^\s*PV\s+Name/i) {
377 elsif ($started && /^\s*\/dev\/(\S+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
378 push(@rv, [ $1, $2, $3, $4 ]);
389 # create_logical_volume(&lv)
390 sub create_logical_volume
392 local $cmd = "lvcreate -n".quotemeta($_[0]->{'name'})." ";
394 if ($_[0]->{'size_of'} eq 'VG' || $_[0]->{'size_of'} eq 'FREE') {
395 $cmd .= "-l ".quotemeta("$_[0]->{'size'}%$_[0]->{'size_of'}");
397 elsif ($_[0]->{'size_of'}) {
398 $cmd .= "-l $_[0]->{'size'}%PVS";
399 $suffix = " ".quotemeta("/dev/".$_[0]->{'size_of'});
402 $cmd .= "-L$_[0]->{'size'}k";
404 if ($_[0]->{'is_snap'}) {
405 $cmd .= " -s ".quotemeta("/dev/$_[0]->{'vg'}/$_[0]->{'snapof'}");
408 $cmd .= " -p ".quotemeta($_[0]->{'perm'});
409 $cmd .= " -C ".quotemeta($_[0]->{'alloc'});
410 $cmd .= " -r ".quotemeta($_[0]->{'readahead'})
411 if ($_[0]->{'readahead'});
412 $cmd .= " -i ".quotemeta($_[0]->{'stripe'})
413 if ($_[0]->{'stripe'});
414 $cmd .= " -I ".quotemeta($_[0]->{'stripesize'})
415 if ($_[0]->{'stripesize'} && $_[0]->{'stripe'});
416 $cmd .= " ".quotemeta($_[0]->{'vg'});
419 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
420 return $? ? $out : undef;
423 # delete_logical_volume(&lv)
424 sub delete_logical_volume
426 local $cmd = "lvremove -f ".quotemeta($_[0]->{'device'});
427 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
428 return $? ? $out : undef;
431 # resize_logical_volume(&lv, size)
432 sub resize_logical_volume
434 local $cmd = $_[1] > $_[0]->{'size'} ? "lvextend" : "lvreduce -f";
435 $cmd .= " -L".quotemeta($_[1])."k";
436 $cmd .= " ".quotemeta($_[0]->{'device'});
437 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
438 return $? ? $out : undef;
441 # change_logical_volume(&lv, [&old-lv])
442 sub change_logical_volume
444 local $cmd = "lvchange ";
445 $cmd .= " -p ".quotemeta($_[0]->{'perm'})
446 if (!$_[1] || $_[0]->{'perm'} ne $_[1]->{'perm'});
447 $cmd .= " -r ".quotemeta($_[0]->{'readahead'})
448 if (!$_[1] || $_[0]->{'readahead'} ne $_[1]->{'readahead'});
449 $cmd .= " -C ".quotemeta($_[0]->{'alloc'})
450 if (!$_[1] || $_[0]->{'alloc'} ne $_[1]->{'alloc'});
451 $cmd .= " ".quotemeta($_[0]->{'device'});
452 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
453 return $? ? $out : undef;
456 # rename_logical_volume(&lv, name)
457 sub rename_logical_volume
459 local $cmd = "lvrename ".quotemeta($_[0]->{'device'})." ".
460 quotemeta("/dev/$_[0]->{'vg'}/$_[1]");
461 local $out = &backquote_logged("$cmd 2>&1 </dev/null");
462 return $? ? $out : undef;
465 # can_resize_filesystem(type)
466 # 0 = no, 1 = enlarge only, 2 = enlarge or shrink
467 sub can_resize_filesystem
469 if ($_[0] =~ /^ext\d+$/) {
470 if (&has_command("e2fsadm")) {
471 return 2; # Can extend and reduce
473 elsif (&has_command("resize2fs")) {
474 # Only new versions can reduce a FS
475 local $out = &backquote_command("resize2fs 2>&1");
476 return $out =~ /resize2fs\s+([0-9\.]+)/i && $1 >= 1.4 ? 2 : 1;
482 elsif ($_[0] eq "xfs") {
483 return &has_command("xfs_growfs") ? 1 : 0;
485 elsif ($_[0] eq "reiserfs") {
486 return &has_command("resize_reiserfs") ? 2 : 0;
488 elsif ($_[0] eq "jfs") {
496 # can_resize_lv_stat(dir, type, mounted)
497 # Returns 1 if some LV can be enlarged, 2 if enlarged or shrunk, or 0
498 # if neither, based on the details provided by device_status
499 sub can_resize_lv_stat
501 local ($dir, $type, $mounted) = @_;
503 # No FS known, assume can resize safely
507 my $can = &can_resize_filesystem($type);
508 if ($can && $mounted) {
509 # If currently mounted, check if resizing is possible
514 elsif ($type =~ /^ext[3-9]$/ || $type eq "xfs" ||
515 $type eq "reiserfs" || $type eq "jfs") {
516 # ext*, xfs, jfs and reiserfs can be resized up
528 # resize_filesystem(&lv, type, size)
529 sub resize_filesystem
531 if ($_[1] =~ /^ext\d+$/) {
532 &foreign_require("proc");
533 if (&has_command("e2fsadm")) {
534 # The e2fsadm command can re-size an LVM and filesystem together
535 local $cmd = "e2fsadm -v -L ".quotemeta($_[2])."k ".
536 quotemeta($_[0]->{'device'});
537 local ($fh, $fpid) = &proc::pty_process_exec($cmd);
545 &additional_log("exec", undef, $cmd);
546 return $? ? $out : undef;
549 if ($_[2] > $_[0]->{'size'}) {
550 # Need to enlarge LV first, then filesystem
551 local $err = &resize_logical_volume($_[0], $_[2]);
552 return $err if ($err);
554 local $cmd = "resize2fs -f ".
555 quotemeta($_[0]->{'device'});
556 local $out = &backquote_logged("$cmd 2>&1");
557 return $? ? $out : undef;
560 # Need to shrink filesystem first, then LV
561 local $cmd = "resize2fs -f ".
562 quotemeta($_[0]->{'device'})." ".
563 quotemeta($_[2])."k";
564 local $out = &backquote_logged("$cmd 2>&1");
567 local $err = &resize_logical_volume($_[0], $_[2]);
572 elsif ($_[1] eq "xfs") {
573 # Resize the logical volume first
574 local $err = &resize_logical_volume($_[0], $_[2]);
575 return $err if ($err);
577 # Resize the filesystem .. which must be mounted!
578 local @stat = &device_status($_[0]->{'device'});
580 foreach $m (&mount::list_mounts()) {
581 if ($m->[1] eq $_[0]->{'device'}) {
586 $mount || return "Mount not found";
587 &mount::mount_dir(@$mount);
589 local $cmd = "xfs_growfs ".quotemeta($stat[0] || $mount->[0]);
590 local $out = &backquote_logged("$cmd 2>&1");
593 &mount::unmount_dir(@$mount);
595 return $q ? $out : undef;
597 elsif ($_[1] eq "reiserfs") {
598 if ($_[2] > $_[0]->{'size'}) {
599 # Enlarge the logical volume first
600 local $err = &resize_logical_volume($_[0], $_[2]);
601 return $err if ($err);
603 # Now enlarge the reiserfs filesystem
604 local $cmd = "resize_reiserfs ".quotemeta($_[0]->{'device'});
605 local $out = &backquote_logged("$cmd 2>&1");
606 return $? ? $out : undef;
609 # Try to shrink the filesystem
610 local $cmd = "yes | resize_reiserfs -s ".
611 quotemeta($_[2])."K ".quotemeta($_[0]->{'device'});
612 local $out = &backquote_logged("$cmd 2>&1");
615 # Now shrink the logical volume
616 local $err = &resize_logical_volume($_[0], $_[2]);
617 return $err ? $err : undef;
620 elsif ($_[1] eq "jfs") {
621 # Enlarge the logical volume first
622 local $err = &resize_logical_volume($_[0], $_[2]);
623 return $err if ($err);
625 # Now enlarge the jfs filesystem with a remount - must be mounted first
626 local @stat = &device_status($_[0]->{'device'});
628 foreach $m (&mount::list_mounts()) {
629 if ($m->[1] eq $_[0]->{'device'}) {
634 $mount || return "Mount not found";
635 &mount::mount_dir(@$mount);
637 local $ropts = $mount->[3];
638 $ropts = $ropts eq "-" ? "resize,remount" : "$ropts,resize,remount";
639 local $err = &mount::mount_dir($mount->[0], $mount->[1],
640 $mount->[2], $ropts);
642 &mount::unmount_dir(@$mount);
644 return $err ? $err : undef;
652 # parse_colon_file(file)
658 if (/^([^:]+):\s*(.*)/) {
666 # device_status(device)
667 # Returns an array of directory, type, mounted
670 @mounted = &mount::list_mounted() if (!@mounted);
671 @mounts = &mount::list_mounts() if (!@mounts);
672 my $label = &fdisk::get_label($_[0]);
674 my ($mounted) = grep { &same_file($_->[1], $_[0]) ||
675 $_->[1] eq "LABEL=$label" } @mounted;
676 my ($mount) = grep { &same_file($_->[1], $_[0]) ||
677 $_->[1] eq "LABEL=$label" } @mounts;
678 if ($mounted) { return ($mounted->[0], $mounted->[2], 1,
679 &indexof($mount, @mounts),
680 &indexof($mounted, @mounted)); }
681 elsif ($mount) { return ($mount->[0], $mount->[2], 0,
682 &indexof($mount, @mounts)); }
684 $raidconf = &raid::get_raidtab() if (!$raidconf);
685 foreach my $c (@$raidconf) {
686 foreach my $d (&raid::find_value('device', $c->{'members'})) {
687 return ( $c->{'value'}, "raid", 1 ) if ($d eq $_[0]);
691 if (&foreign_check("server-manager")) {
692 # Look for Cloudmin systems using the disk, hosted on this system
693 if (!@server_manager_systems) {
694 &foreign_require("server-manager");
695 @server_manager_systems =
696 grep { my $p = &server_manager::get_parent_server($_);
697 $p && $p->{'id'} eq '0' }
698 &server_manager::list_managed_servers();
700 foreach my $s (@server_manager_systems) {
701 if ($s->{$s->{'manager'}.'_filesystem'} eq $_[0]) {
702 return ( $s->{'host'}, 'cloudmin',
703 $s->{'status'} ne 'down' );
705 my $ffunc = "type_".$s->{'manager'}."_list_disk_devices";
706 if (&foreign_defined("server-manager", $ffunc)) {
707 my @disks = &foreign_call("server-manager", $ffunc, $s);
708 if (&indexof($_[0], @disks) >= 0) {
709 return ( $s->{'host'}, 'cloudmin',
710 $s->{'status'} ne 'down' );
718 # device_message(stat)
719 # Returns a text string about the status of an LV
723 if ($_[1] eq 'cloudmin') {
724 # Used by Cloudmin system
725 $msg = $_[2] ? 'lv_mountcm' : 'lv_umountcm';
726 return &text($msg, "<tt>$_[0]</tt>");
729 # Used by filesystem or RAID
730 $msg = $_[2] ? 'lv_mount' : 'lv_umount';
731 $msg .= 'vm' if ($_[1] eq 'swap');
732 $msg .= 'raid' if ($_[1] eq 'raid');
733 return &text($msg, "<tt>$_[0]</tt>", "<tt>$_[1]</tt>");
745 push(@rv, $_) if ($_);
752 # Returns a selector for a free device
755 local (%used, $vg, $pv, $d, $p);
757 # Find partitions that are part of an LVM
758 foreach $vg (&list_volume_groups()) {
759 foreach $pv (&list_physical_volumes($vg->{'name'})) {
760 $used{$pv->{'device'}}++;
764 # Show available partitions
766 foreach $d (&fdisk::list_disks_partitions()) {
767 foreach $p (@{$d->{'parts'}}) {
768 next if ($used{$p->{'device'}} || $p->{'extended'});
769 local @ds = &device_status($p->{'device'});
771 if ($p->{'type'} eq '83' || $p->{'type'} eq 'ext2') {
772 local $label = &fdisk::get_label($p->{'device'});
773 next if ($used{"LABEL=$label"});
775 local $tag = &fdisk::tag_name($p->{'type'});
776 push(@opts, [ $p->{'device'},
778 ($tag ? " ($tag)" : "").
779 ($d->{'cylsize'} ? " (".&nice_size($d->{'cylsize'}*($p->{'end'} - $p->{'start'} + 1)).")" :
780 " ($p->{'blocks'} $text{'blocks'})") ]);
784 # Show available RAID devices
785 local $conf = &raid::get_raidtab();
786 foreach $c (@$conf) {
787 next if ($used{$c->{'value'}});
788 local @ds = &device_status($c->{'value'});
790 push(@opts, [ $c->{'value'}, &text('pv_raid', $c->{'value'} =~ /md(\d+)$/ ? "$1" : $c->{'value'}) ]);
793 push(@opts, [ '', $text{'pv_other'} ]);
794 return &ui_select("device", $opts[0]->[0], \@opts)." ".
795 &ui_textbox("other", undef, 30)." ".&file_chooser_button("other").
796 "<br>\n<b>$text{'pv_warn'}</b>";
800 # Returns the lvm version number and optionally output from the vgdisplay
801 # command used to get it.
804 local $out = `vgdisplay --version 2>&1`;
805 local $ver = $out =~ /\s+([0-9\.]+)/ ? $1 : undef;
806 return wantarray ? ( $ver, $out ) : $ver;
810 # Round some number to TB, GB, MB or kB, depending on size
815 if ($bytes >= 10*1024*1024*1024*1024) {
816 $units = 1024*1024*1024*1024;
818 elsif ($bytes >= 10*1024*1024*1024) {
819 $units = 1024*1024*1024;
821 elsif ($bytes >= 10*1024*1024) {
824 elsif ($bytes >= 10*1024) {
830 return int($bytes / $units) * $units;