]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage.pm
12 use PVE
::Tools
qw(run_command file_read_firstline);
13 use PVE
::Cluster
qw(cfs_read_file cfs_lock_file);
14 use PVE
::Exception
qw(raise_param_exc);
17 use PVE
::RPCEnvironment
;
19 use PVE
::Storage
::Plugin
;
20 use PVE
::Storage
::DirPlugin
;
21 use PVE
::Storage
::LVMPlugin
;
22 use PVE
::Storage
::NFSPlugin
;
23 use PVE
::Storage
::ISCSIPlugin
;
24 use PVE
::Storage
::RBDPlugin
;
25 use PVE
::Storage
::SheepdogPlugin
;
26 use PVE
::Storage
::ISCSIDirectPlugin
;
27 use PVE
::Storage
::NexentaPlugin
;
29 # load and initialize all plugins
30 PVE
::Storage
::DirPlugin-
>register();
31 PVE
::Storage
::LVMPlugin-
>register();
32 PVE
::Storage
::NFSPlugin-
>register();
33 PVE
::Storage
::ISCSIPlugin-
>register();
34 PVE
::Storage
::RBDPlugin-
>register();
35 PVE
::Storage
::SheepdogPlugin-
>register();
36 PVE
::Storage
::ISCSIDirectPlugin-
>register();
37 PVE
::Storage
::NexentaPlugin-
>register();
38 PVE
::Storage
::Plugin-
>init();
40 my $UDEVADM = '/sbin/udevadm';
42 # PVE::Storage utility functions
45 return cfs_read_file
("storage.cfg");
48 sub lock_storage_config
{
49 my ($code, $errmsg) = @_;
51 cfs_lock_file
("storage.cfg", undef, $code);
54 $errmsg ?
die "$errmsg: $err" : die $err;
59 my ($cfg, $storeid, $noerr) = @_;
61 die "no storage id specified\n" if !$storeid;
63 my $scfg = $cfg->{ids
}->{$storeid};
65 die "storage '$storeid' does not exists\n" if (!$noerr && !$scfg);
70 sub storage_check_node
{
71 my ($cfg, $storeid, $node, $noerr) = @_;
73 my $scfg = storage_config
($cfg, $storeid);
76 $node = PVE
::INotify
::nodename
() if !$node || ($node eq 'localhost');
77 if (!$scfg->{nodes
}->{$node}) {
78 die "storage '$storeid' is not available on node '$node'\n" if !$noerr;
86 sub storage_check_enabled
{
87 my ($cfg, $storeid, $node, $noerr) = @_;
89 my $scfg = storage_config
($cfg, $storeid);
91 if ($scfg->{disable
}) {
92 die "storage '$storeid' is disabled\n" if !$noerr;
96 return storage_check_node
($cfg, $storeid, $node, $noerr);
102 return keys %{$cfg->{ids
}};
106 my ($filename, $timeout) = @_;
108 return PVE
::Storage
::Plugin
::file_size_info
($filename, $timeout);
111 sub volume_size_info
{
112 my ($cfg, $volid, $timeout) = @_;
114 my ($storeid, $volname) = parse_volume_id
($volid, 1);
116 my $scfg = storage_config
($cfg, $storeid);
117 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
118 return $plugin->volume_size_info($scfg, $storeid, $volname, $timeout);
119 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
120 return file_size_info
($volid, $timeout);
127 my ($cfg, $volid, $size, $running) = @_;
129 my ($storeid, $volname) = parse_volume_id
($volid, 1);
131 my $scfg = storage_config
($cfg, $storeid);
132 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
133 return $plugin->volume_resize($scfg, $storeid, $volname, $size, $running);
134 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
135 die "resize device is not possible";
141 sub volume_snapshot
{
142 my ($cfg, $volid, $snap, $running) = @_;
144 my ($storeid, $volname) = parse_volume_id
($volid, 1);
146 my $scfg = storage_config
($cfg, $storeid);
147 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
148 return $plugin->volume_snapshot($scfg, $storeid, $volname, $snap, $running);
149 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
150 die "snapshot device is not possible";
152 die "can't snapshot";
156 sub volume_snapshot_rollback
{
157 my ($cfg, $volid, $snap) = @_;
159 my ($storeid, $volname) = parse_volume_id
($volid, 1);
161 my $scfg = storage_config
($cfg, $storeid);
162 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
163 return $plugin->volume_snapshot_rollback($scfg, $storeid, $volname, $snap);
164 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
165 die "snapshot rollback device is not possible";
167 die "can't snapshot";
171 sub volume_snapshot_delete
{
172 my ($cfg, $volid, $snap, $running) = @_;
174 my ($storeid, $volname) = parse_volume_id
($volid, 1);
176 my $scfg = storage_config
($cfg, $storeid);
177 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
178 return $plugin->volume_snapshot_delete($scfg, $storeid, $volname, $snap, $running);
179 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
180 die "snapshot delete device is not possible";
182 die "can't delete snapshot";
187 my ($cfg, $storeid, $vmid) = @_;
189 my $scfg = storage_config
($cfg, $storeid);
190 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
192 my $path = $plugin->get_subdir($scfg, 'images');
194 return $vmid ?
"$path/$vmid" : $path;
197 sub get_private_dir
{
198 my ($cfg, $storeid, $vmid) = @_;
200 my $scfg = storage_config
($cfg, $storeid);
201 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
203 my $path = $plugin->get_subdir($scfg, 'rootdir');
205 return $vmid ?
"$path/$vmid" : $path;
209 my ($cfg, $storeid) = @_;
211 my $scfg = storage_config
($cfg, $storeid);
212 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
214 return $plugin->get_subdir($scfg, 'iso');
218 my ($cfg, $storeid) = @_;
220 my $scfg = storage_config
($cfg, $storeid);
221 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
223 return $plugin->get_subdir($scfg, 'vztmpl');
227 my ($cfg, $storeid) = @_;
229 my $scfg = storage_config
($cfg, $storeid);
230 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
232 return $plugin->get_subdir($scfg, 'backup');
235 # library implementation
240 die "VMID '$vmid' contains illegal characters\n" if $vmid !~ m/^\d+$/;
245 PVE
::JSONSchema
::register_format
('pve-volume-id', \
&parse_volume_id
);
246 sub parse_volume_id
{
247 my ($volid, $noerr) = @_;
249 if ($volid =~ m/^([a-z][a-z0-9\-\_\.]*[a-z0-9]):(.+)$/i) {
250 return wantarray ?
($1, $2) : $1;
252 return undef if $noerr;
253 die "unable to parse volume ID '$volid'\n";
256 # try to map a filesystem path to a volume identifier
257 sub path_to_volume_id
{
258 my ($cfg, $path) = @_;
260 my $ids = $cfg->{ids
};
262 my ($sid, $volname) = parse_volume_id
($path, 1);
264 if (my $scfg = $ids->{$sid}) {
265 if (my $path = $scfg->{path
}) {
266 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
267 my ($vtype, $name, $vmid) = $plugin->parse_volname($volname);
268 return ($vtype, $path);
274 # Note: abs_path() return undef if $path doesn not exist
275 # for example when nfs storage is not mounted
276 $path = abs_path
($path) || $path;
278 foreach my $sid (keys %$ids) {
279 my $scfg = $ids->{$sid};
280 next if !$scfg->{path
};
281 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
282 my $imagedir = $plugin->get_subdir($scfg, 'images');
283 my $isodir = $plugin->get_subdir($scfg, 'iso');
284 my $tmpldir = $plugin->get_subdir($scfg, 'vztmpl');
285 my $backupdir = $plugin->get_subdir($scfg, 'backup');
286 my $privatedir = $plugin->get_subdir($scfg, 'rootdir');
288 if ($path =~ m!^$imagedir/(\d+)/([^/\s]+)$!) {
291 return ('images', "$sid:$vmid/$name");
292 } elsif ($path =~ m!^$isodir/([^/]+\.[Ii][Ss][Oo])$!) {
294 return ('iso', "$sid:iso/$name");
295 } elsif ($path =~ m!^$tmpldir/([^/]+\.tar\.gz)$!) {
297 return ('vztmpl', "$sid:vztmpl/$name");
298 } elsif ($path =~ m!^$privatedir/(\d+)$!) {
300 return ('rootdir', "$sid:rootdir/$vmid");
301 } elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz))$!) {
303 return ('iso', "$sid:backup/$name");
307 # can't map path to volume id
312 my ($cfg, $volid) = @_;
314 my ($storeid, $volname) = parse_volume_id
($volid);
316 my $scfg = storage_config
($cfg, $storeid);
318 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
319 my ($path, $owner, $vtype) = $plugin->path($scfg, $volname, $storeid);
320 return wantarray ?
($path, $owner, $vtype) : $path;
323 sub storage_migrate
{
324 my ($cfg, $volid, $target_host, $target_storeid, $target_volname) = @_;
326 my ($storeid, $volname) = parse_volume_id
($volid);
327 $target_volname = $volname if !$target_volname;
329 my $scfg = storage_config
($cfg, $storeid);
331 # no need to migrate shared content
332 return if $storeid eq $target_storeid && $scfg->{shared
};
334 my $tcfg = storage_config
($cfg, $target_storeid);
336 my $target_volid = "${target_storeid}:${target_volname}";
338 my $errstr = "unable to migrate '$volid' to '${target_volid}' on host '$target_host'";
340 # blowfish is a fast block cipher, much faster then 3des
341 my $sshoptions = "-c blowfish -o 'BatchMode=yes'";
342 my $ssh = "/usr/bin/ssh $sshoptions";
344 local $ENV{RSYNC_RSH
} = $ssh;
346 # only implemented for file system based storage
350 my $src_plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
351 my $dst_plugin = PVE
::Storage
::Plugin-
>lookup($tcfg->{type
});
352 my $src = $src_plugin->path($scfg, $volname, $storeid);
353 my $dst = $dst_plugin->path($tcfg, $target_volname, $target_storeid);
355 my $dirname = dirname
($dst);
357 if ($tcfg->{shared
}) { # we can do a local copy
359 run_command
(['/bin/mkdir', '-p', $dirname]);
361 run_command
(['/bin/cp', $src, $dst]);
365 run_command
(['/usr/bin/ssh', "root\@${target_host}",
366 '/bin/mkdir', '-p', $dirname]);
368 # we use rsync with --sparse, so we can't use --inplace,
369 # so we remove file on the target if it already exists to
371 my ($size, $format) = PVE
::Storage
::Plugin
::file_size_info
($src);
372 if ($format && ($format eq 'raw') && $size) {
373 run_command
(['/usr/bin/ssh', "root\@${target_host}",
378 my $cmd = ['/usr/bin/rsync', '--progress', '--sparse', '--whole-file',
379 $src, "root\@${target_host}:$dst"];
383 run_command
($cmd, outfunc
=> sub {
386 if ($line =~ m/^\s*(\d+\s+(\d+)%\s.*)$/) {
389 print "rsync status: $1\n";
399 die "$errstr - target type '$tcfg->{type}' not implemented\n";
402 die "$errstr - source type '$scfg->{type}' not implemented\n";
407 my ($cfg, $storeid, $vmid, $fmt, $name, $size) = @_;
409 die "no storage id specified\n" if !$storeid;
411 PVE
::JSONSchema
::parse_storage_id
($storeid);
413 my $scfg = storage_config
($cfg, $storeid);
415 die "no VMID specified\n" if !$vmid;
417 $vmid = parse_vmid
($vmid);
419 my $defformat = PVE
::Storage
::Plugin
::default_format
($scfg);
421 $fmt = $defformat if !$fmt;
423 activate_storage
($cfg, $storeid);
425 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
427 # lock shared storage
428 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
429 my $volname = $plugin->alloc_image($storeid, $scfg, $vmid, $fmt, $name, $size);
430 return "$storeid:$volname";
435 my ($cfg, $volid) = @_;
437 my ($storeid, $volname) = parse_volume_id
($volid);
439 my $scfg = storage_config
($cfg, $storeid);
441 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
443 activate_storage
($cfg, $storeid);
447 # lock shared storage
448 $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
449 my $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname);
452 return if !$cleanup_worker;
454 my $rpcenv = PVE
::RPCEnvironment
::get
();
455 my $authuser = $rpcenv->get_user();
457 $rpcenv->fork_worker('imgdel', undef, $authuser, $cleanup_worker);
460 #list iso or openvz template ($tt = <iso|vztmpl|backup>)
462 my ($cfg, $storeid, $tt) = @_;
464 die "unknown template type '$tt'\n"
465 if !($tt eq 'iso' || $tt eq 'vztmpl' || $tt eq 'backup');
467 my $ids = $cfg->{ids
};
469 storage_check_enabled
($cfg, $storeid) if ($storeid);
475 foreach my $sid (keys %$ids) {
476 next if $storeid && $storeid ne $sid;
478 my $scfg = $ids->{$sid};
479 my $type = $scfg->{type
};
481 next if !storage_check_enabled
($cfg, $sid, undef, 1);
483 next if $tt eq 'iso' && !$scfg->{content
}->{iso
};
484 next if $tt eq 'vztmpl' && !$scfg->{content
}->{vztmpl
};
485 next if $tt eq 'backup' && !$scfg->{content
}->{backup
};
487 activate_storage
($cfg, $sid);
490 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
492 my $path = $plugin->get_subdir($scfg, $tt);
494 foreach my $fn (<$path/*>) {
499 next if $fn !~ m!/([^/]+\.[Ii][Ss][Oo])$!;
501 $info = { volid
=> "$sid:iso/$1", format
=> 'iso' };
503 } elsif ($tt eq 'vztmpl') {
504 next if $fn !~ m!/([^/]+\.tar\.gz)$!;
506 $info = { volid
=> "$sid:vztmpl/$1", format
=> 'tgz' };
508 } elsif ($tt eq 'backup') {
509 next if $fn !~ m!/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz))$!;
511 $info = { volid
=> "$sid:backup/$1", format
=> $2 };
514 $info->{size
} = -s
$fn;
516 push @{$res->{$sid}}, $info;
521 @{$res->{$sid}} = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @{$res->{$sid}} if $res->{$sid};
529 my ($cfg, $storeid, $vmid, $vollist) = @_;
531 my $ids = $cfg->{ids
};
533 storage_check_enabled
($cfg, $storeid) if ($storeid);
537 # prepare/activate/refresh all storages
539 my $storage_list = [];
541 foreach my $volid (@$vollist) {
542 my ($sid, undef) = parse_volume_id
($volid);
543 next if !defined($ids->{$sid});
544 next if !storage_check_enabled
($cfg, $sid, undef, 1);
545 push @$storage_list, $sid;
548 foreach my $sid (keys %$ids) {
549 next if $storeid && $storeid ne $sid;
550 next if !storage_check_enabled
($cfg, $sid, undef, 1);
551 push @$storage_list, $sid;
557 activate_storage_list
($cfg, $storage_list, $cache);
559 foreach my $sid (keys %$ids) {
560 next if $storeid && $storeid ne $sid;
561 next if !storage_check_enabled
($cfg, $sid, undef, 1);
563 my $scfg = $ids->{$sid};
564 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
565 $res->{$sid} = $plugin->list_images($sid, $scfg, $vmid, $vollist, $cache);
566 @{$res->{$sid}} = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @{$res->{$sid}} if $res->{$sid};
574 my $filename = "/sys/kernel/uevent_seqnum";
577 if (my $fh = IO
::File-
>new($filename, "r")) {
579 if ($line =~ m/^(\d+)$/) {
587 sub activate_storage
{
588 my ($cfg, $storeid, $cache) = @_;
590 $cache = {} if !$cache;
592 my $scfg = storage_check_enabled
($cfg, $storeid);
594 return if $cache->{activated
}->{$storeid};
596 $cache->{uevent_seqnum
} = uevent_seqnum
() if !$cache->{uevent_seqnum
};
598 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
601 my ($baseid, undef) = parse_volume_id
($scfg->{base
});
602 activate_storage
($cfg, $baseid, $cache);
605 if (!$plugin->check_connection($storeid, $scfg)) {
606 die "storage '$storeid' is not online\n";
609 $plugin->activate_storage($storeid, $scfg, $cache);
611 my $newseq = uevent_seqnum
();
613 # only call udevsettle if there are events
614 if ($newseq > $cache->{uevent_seqnum
}) {
616 system ("$UDEVADM settle --timeout=$timeout"); # ignore errors
617 $cache->{uevent_seqnum
} = $newseq;
620 $cache->{activated
}->{$storeid} = 1;
623 sub activate_storage_list
{
624 my ($cfg, $storeid_list, $cache) = @_;
626 $cache = {} if !$cache;
628 foreach my $storeid (@$storeid_list) {
629 activate_storage
($cfg, $storeid, $cache);
633 sub deactivate_storage
{
634 my ($cfg, $storeid) = @_;
636 my $scfg = storage_config
($cfg, $storeid);
637 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
640 $plugin->deactivate_storage($storeid, $scfg, $cache);
643 sub activate_volumes
{
644 my ($cfg, $vollist, $exclusive) = @_;
646 return if !($vollist && scalar(@$vollist));
648 my $storagehash = {};
649 foreach my $volid (@$vollist) {
650 my ($storeid, undef) = parse_volume_id
($volid);
651 $storagehash->{$storeid} = 1;
656 activate_storage_list
($cfg, [keys %$storagehash], $cache);
658 foreach my $volid (@$vollist) {
659 my ($storeid, $volname) = parse_volume_id
($volid);
660 my $scfg = storage_config
($cfg, $storeid);
661 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
662 $plugin->activate_volume($storeid, $scfg, $volname, $exclusive, $cache);
666 sub deactivate_volumes
{
667 my ($cfg, $vollist) = @_;
669 return if !($vollist && scalar(@$vollist));
674 foreach my $volid (@$vollist) {
675 my ($storeid, $volname) = parse_volume_id
($volid);
677 my $scfg = storage_config
($cfg, $storeid);
678 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
681 $plugin->deactivate_volume($storeid, $scfg, $volname, $cache);
685 push @errlist, $volid;
689 die "volume deativation failed: " . join(' ', @errlist)
694 my ($cfg, $content) = @_;
696 my $ids = $cfg->{ids
};
701 foreach my $storeid (keys %$ids) {
703 next if $content && !$ids->{$storeid}->{content
}->{$content};
705 next if !storage_check_enabled
($cfg, $storeid, undef, 1);
707 my $type = $ids->{$storeid}->{type
};
709 $info->{$storeid} = {
714 shared
=> $ids->{$storeid}->{shared
} ?
1 : 0,
715 content
=> PVE
::Storage
::Plugin
::content_hash_to_string
($ids->{$storeid}->{content
}),
719 push @$slist, $storeid;
724 foreach my $storeid (keys %$ids) {
725 my $scfg = $ids->{$storeid};
726 next if !$info->{$storeid};
728 eval { activate_storage
($cfg, $storeid, $cache); };
734 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
735 my ($total, $avail, $used, $active);
736 eval { ($total, $avail, $used, $active) = $plugin->status($storeid, $scfg, $cache); };
739 $info->{$storeid}->{total
} = $total;
740 $info->{$storeid}->{avail
} = $avail;
741 $info->{$storeid}->{used
} = $used;
742 $info->{$storeid}->{active
} = $active;
751 my $packed_ip = gethostbyname($server);
752 if (defined $packed_ip) {
753 return inet_ntoa
($packed_ip);
759 my ($server_in) = @_;
762 if (!($server = resolv_server
($server_in))) {
763 die "unable to resolve address for server '${server_in}'\n";
766 my $cmd = ['/sbin/showmount', '--no-headers', '--exports', $server];
769 run_command
($cmd, outfunc
=> sub {
772 # note: howto handle white spaces in export path??
773 if ($line =~ m!^(/\S+)\s+(.+)$!) {
782 my ($portal, $noerr) = @_;
784 if ($portal =~ m/^([^:]+)(:(\d+))?$/) {
788 if (my $ip = resolv_server
($server)) {
790 return $port ?
"$server:$port" : $server;
793 return undef if $noerr;
795 raise_param_exc
({ portal
=> "unable to resolve portal address '$portal'" });
798 # idea is from usbutils package (/usr/bin/usb-devices) script
799 sub __scan_usb_device
{
800 my ($res, $devpath, $parent, $level) = @_;
802 return if ! -d
$devpath;
803 return if $level && $devpath !~ m/^.*[-.](\d+)$/;
804 my $port = $level ?
int($1 - 1) : 0;
806 my $busnum = int(file_read_firstline
("$devpath/busnum"));
807 my $devnum = int(file_read_firstline
("$devpath/devnum"));
814 speed
=> file_read_firstline
("$devpath/speed"),
815 class => hex(file_read_firstline
("$devpath/bDeviceClass")),
816 vendid
=> file_read_firstline
("$devpath/idVendor"),
817 prodid
=> file_read_firstline
("$devpath/idProduct"),
821 my $usbpath = $devpath;
822 $usbpath =~ s
|^.*/\d
+\
-||;
823 $d->{usbpath
} = $usbpath;
826 my $product = file_read_firstline
("$devpath/product");
827 $d->{product
} = $product if $product;
829 my $manu = file_read_firstline
("$devpath/manufacturer");
830 $d->{manufacturer
} = $manu if $manu;
832 my $serial => file_read_firstline
("$devpath/serial");
833 $d->{serial
} = $serial if $serial;
837 foreach my $subdev (<$devpath/$busnum-*>) {
838 next if $subdev !~ m
|/$busnum-[0-9]+(\
.[0-9]+)*$|;
839 __scan_usb_device
($res, $subdev, $devnum, $level + 1);
848 foreach my $device (</sys/bus
/usb
/devices
/usb
*>) {
849 __scan_usb_device
($devlist, $device, 0, 0);
856 my ($portal_in) = @_;
859 if (!($portal = resolv_portal
($portal_in))) {
860 die "unable to parse/resolve portal address '${portal_in}'\n";
863 return PVE
::Storage
::ISCSIPlugin
::iscsi_discovery
($portal);
866 sub storage_default_format
{
867 my ($cfg, $storeid) = @_;
869 my $scfg = storage_config
($cfg, $storeid);
871 return PVE
::Storage
::Plugin
::default_format
($scfg);
875 my ($cfg, $vgname) = @_;
877 foreach my $storeid (keys %{$cfg->{ids
}}) {
878 my $scfg = storage_config
($cfg, $storeid);
879 if ($scfg->{type
} eq 'lvm' && $scfg->{vgname
} eq $vgname) {
888 my ($cfg, $target) = @_;
890 foreach my $storeid (keys %{$cfg->{ids
}}) {
891 my $scfg = storage_config
($cfg, $storeid);
892 if ($scfg->{type
} eq 'iscsi' && $scfg->{target
} eq $target) {
901 my ($cfg, $volid) = @_;
903 foreach my $storeid (keys %{$cfg->{ids
}}) {
904 my $scfg = storage_config
($cfg, $storeid);
905 if ($scfg->{base
} && $scfg->{base
} eq $volid) {
913 sub storage_is_used
{
914 my ($cfg, $storeid) = @_;
916 foreach my $sid (keys %{$cfg->{ids
}}) {
917 my $scfg = storage_config
($cfg, $sid);
918 next if !$scfg->{base
};
919 my ($st) = parse_volume_id
($scfg->{base
});
920 return 1 if $st && $st eq $storeid;
927 my ($list, $func) = @_;
931 foreach my $sid (keys %$list) {
932 foreach my $info (@{$list->{$sid}}) {
933 my $volid = $info->{volid
};
934 my ($sid1, $volname) = parse_volume_id
($volid, 1);
935 if ($sid1 && $sid1 eq $sid) {
936 &$func ($volid, $sid, $info);
938 warn "detected strange volid '$volid' in volume list for '$sid'\n";