]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage.pm
14 use PVE
::Tools
qw(run_command file_read_firstline);
15 use PVE
::Cluster
qw(cfs_read_file cfs_lock_file);
16 use PVE
::Exception
qw(raise_param_exc);
19 use PVE
::RPCEnvironment
;
21 use PVE
::Storage
::Plugin
;
22 use PVE
::Storage
::DirPlugin
;
23 use PVE
::Storage
::LVMPlugin
;
24 use PVE
::Storage
::NFSPlugin
;
25 use PVE
::Storage
::ISCSIPlugin
;
26 use PVE
::Storage
::RBDPlugin
;
27 use PVE
::Storage
::SheepdogPlugin
;
28 use PVE
::Storage
::ISCSIDirectPlugin
;
29 use PVE
::Storage
::GlusterfsPlugin
;
30 use PVE
::Storage
::ZFSPlugin
;
32 # load and initialize all plugins
33 PVE
::Storage
::DirPlugin-
>register();
34 PVE
::Storage
::LVMPlugin-
>register();
35 PVE
::Storage
::NFSPlugin-
>register();
36 PVE
::Storage
::ISCSIPlugin-
>register();
37 PVE
::Storage
::RBDPlugin-
>register();
38 PVE
::Storage
::SheepdogPlugin-
>register();
39 PVE
::Storage
::ISCSIDirectPlugin-
>register();
40 PVE
::Storage
::GlusterfsPlugin-
>register();
41 PVE
::Storage
::ZFSPlugin-
>register();
42 PVE
::Storage
::Plugin-
>init();
44 my $UDEVADM = '/sbin/udevadm';
46 # PVE::Storage utility functions
49 return cfs_read_file
("storage.cfg");
52 sub lock_storage_config
{
53 my ($code, $errmsg) = @_;
55 cfs_lock_file
("storage.cfg", undef, $code);
58 $errmsg ?
die "$errmsg: $err" : die $err;
63 my ($cfg, $storeid, $noerr) = @_;
65 die "no storage id specified\n" if !$storeid;
67 my $scfg = $cfg->{ids
}->{$storeid};
69 die "storage '$storeid' does not exists\n" if (!$noerr && !$scfg);
74 sub storage_check_node
{
75 my ($cfg, $storeid, $node, $noerr) = @_;
77 my $scfg = storage_config
($cfg, $storeid);
80 $node = PVE
::INotify
::nodename
() if !$node || ($node eq 'localhost');
81 if (!$scfg->{nodes
}->{$node}) {
82 die "storage '$storeid' is not available on node '$node'\n" if !$noerr;
90 sub storage_check_enabled
{
91 my ($cfg, $storeid, $node, $noerr) = @_;
93 my $scfg = storage_config
($cfg, $storeid);
95 if ($scfg->{disable
}) {
96 die "storage '$storeid' is disabled\n" if !$noerr;
100 return storage_check_node
($cfg, $storeid, $node, $noerr);
106 return keys %{$cfg->{ids
}};
110 my ($filename, $timeout) = @_;
112 return PVE
::Storage
::Plugin
::file_size_info
($filename, $timeout);
115 sub volume_size_info
{
116 my ($cfg, $volid, $timeout) = @_;
118 my ($storeid, $volname) = parse_volume_id
($volid, 1);
120 my $scfg = storage_config
($cfg, $storeid);
121 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
122 return $plugin->volume_size_info($scfg, $storeid, $volname, $timeout);
123 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
124 return file_size_info
($volid, $timeout);
131 my ($cfg, $volid, $size, $running) = @_;
133 my ($storeid, $volname) = parse_volume_id
($volid, 1);
135 my $scfg = storage_config
($cfg, $storeid);
136 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
137 return $plugin->volume_resize($scfg, $storeid, $volname, $size, $running);
138 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
139 die "resize device is not possible";
145 sub volume_snapshot
{
146 my ($cfg, $volid, $snap, $running) = @_;
148 my ($storeid, $volname) = parse_volume_id
($volid, 1);
150 my $scfg = storage_config
($cfg, $storeid);
151 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
152 return $plugin->volume_snapshot($scfg, $storeid, $volname, $snap, $running);
153 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
154 die "snapshot device is not possible";
156 die "can't snapshot";
160 sub volume_snapshot_rollback
{
161 my ($cfg, $volid, $snap) = @_;
163 my ($storeid, $volname) = parse_volume_id
($volid, 1);
165 my $scfg = storage_config
($cfg, $storeid);
166 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
167 return $plugin->volume_snapshot_rollback($scfg, $storeid, $volname, $snap);
168 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
169 die "snapshot rollback device is not possible";
171 die "can't snapshot";
175 sub volume_snapshot_delete
{
176 my ($cfg, $volid, $snap, $running) = @_;
178 my ($storeid, $volname) = parse_volume_id
($volid, 1);
180 my $scfg = storage_config
($cfg, $storeid);
181 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
182 return $plugin->volume_snapshot_delete($scfg, $storeid, $volname, $snap, $running);
183 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
184 die "snapshot delete device is not possible";
186 die "can't delete snapshot";
190 sub volume_has_feature
{
191 my ($cfg, $feature, $volid, $snap, $running) = @_;
193 my ($storeid, $volname) = parse_volume_id
($volid, 1);
195 my $scfg = storage_config
($cfg, $storeid);
196 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
197 return $plugin->volume_has_feature($scfg, $feature, $storeid, $volname, $snap, $running);
198 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
206 my ($cfg, $storeid, $vmid) = @_;
208 my $scfg = storage_config
($cfg, $storeid);
209 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
211 my $path = $plugin->get_subdir($scfg, 'images');
213 return $vmid ?
"$path/$vmid" : $path;
216 sub get_private_dir
{
217 my ($cfg, $storeid, $vmid) = @_;
219 my $scfg = storage_config
($cfg, $storeid);
220 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
222 my $path = $plugin->get_subdir($scfg, 'rootdir');
224 return $vmid ?
"$path/$vmid" : $path;
228 my ($cfg, $storeid) = @_;
230 my $scfg = storage_config
($cfg, $storeid);
231 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
233 return $plugin->get_subdir($scfg, 'iso');
237 my ($cfg, $storeid) = @_;
239 my $scfg = storage_config
($cfg, $storeid);
240 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
242 return $plugin->get_subdir($scfg, 'vztmpl');
246 my ($cfg, $storeid) = @_;
248 my $scfg = storage_config
($cfg, $storeid);
249 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
251 return $plugin->get_subdir($scfg, 'backup');
254 # library implementation
259 die "VMID '$vmid' contains illegal characters\n" if $vmid !~ m/^\d+$/;
265 my ($cfg, $volid) = @_;
267 my ($storeid, $volname) = parse_volume_id
($volid);
269 my $scfg = storage_config
($cfg, $storeid);
271 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
272 return $plugin->parse_volname($volname);
275 sub parse_volume_id
{
276 my ($volid, $noerr) = @_;
278 return PVE
::Storage
::Plugin
::parse_volume_id
($volid, $noerr);
282 my ($cfg, $volid) = @_;
284 my ($sid, $volname) = parse_volume_id
($volid, 1);
287 if (my $scfg = $cfg->{ids
}->{$sid}) {
288 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
289 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
290 $plugin->parse_volname($volname);
291 return $isBase ?
1 : 0;
293 # stale volid with undefined storage - so we can just guess
294 if ($volid =~ m/base-/) {
302 # try to map a filesystem path to a volume identifier
303 sub path_to_volume_id
{
304 my ($cfg, $path) = @_;
306 my $ids = $cfg->{ids
};
308 my ($sid, $volname) = parse_volume_id
($path, 1);
310 if (my $scfg = $ids->{$sid}) {
312 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
313 my ($vtype, $name, $vmid) = $plugin->parse_volname($volname);
314 return ($vtype, $path);
320 # Note: abs_path() return undef if $path doesn not exist
321 # for example when nfs storage is not mounted
322 $path = abs_path
($path) || $path;
324 foreach my $sid (keys %$ids) {
325 my $scfg = $ids->{$sid};
326 next if !$scfg->{path
};
327 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
328 my $imagedir = $plugin->get_subdir($scfg, 'images');
329 my $isodir = $plugin->get_subdir($scfg, 'iso');
330 my $tmpldir = $plugin->get_subdir($scfg, 'vztmpl');
331 my $backupdir = $plugin->get_subdir($scfg, 'backup');
332 my $privatedir = $plugin->get_subdir($scfg, 'rootdir');
334 if ($path =~ m!^$imagedir/(\d+)/([^/\s]+)$!) {
338 my $vollist = $plugin->list_images($sid, $scfg, $vmid);
339 foreach my $info (@$vollist) {
340 my ($storeid, $volname) = parse_volume_id
($info->{volid
});
341 my $volpath = $plugin->path($scfg, $volname, $storeid);
342 if ($volpath eq $path) {
343 return ('images', $info->{volid
});
346 } elsif ($path =~ m!^$isodir/([^/]+\.[Ii][Ss][Oo])$!) {
348 return ('iso', "$sid:iso/$name");
349 } elsif ($path =~ m!^$tmpldir/([^/]+\.tar\.gz)$!) {
351 return ('vztmpl', "$sid:vztmpl/$name");
352 } elsif ($path =~ m!^$privatedir/(\d+)$!) {
354 return ('rootdir', "$sid:rootdir/$vmid");
355 } elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!) {
357 return ('iso', "$sid:backup/$name");
361 # can't map path to volume id
366 my ($cfg, $volid, $snapname) = @_;
368 my ($storeid, $volname) = parse_volume_id
($volid);
370 my $scfg = storage_config
($cfg, $storeid);
372 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
373 my ($path, $owner, $vtype) = $plugin->path($scfg, $volname, $storeid, $snapname);
374 return wantarray ?
($path, $owner, $vtype) : $path;
377 sub abs_filesystem_path
{
378 my ($cfg, $volid) = @_;
381 if (PVE
::Storage
::parse_volume_id
($volid, 1)) {
382 PVE
::Storage
::activate_volumes
($cfg, [ $volid ]);
383 $path = PVE
::Storage
::path
($cfg, $volid);
386 my $abspath = abs_path
($volid);
387 if ($abspath && $abspath =~ m
|^(/.+)$|) {
388 $path = $1; # untaint any path
393 die "can't find file '$volid'\n" if !($path && -f
$path);
398 sub storage_migrate
{
399 my ($cfg, $volid, $target_host, $target_storeid, $target_volname) = @_;
401 my ($storeid, $volname) = parse_volume_id
($volid);
402 $target_volname = $volname if !$target_volname;
404 my $scfg = storage_config
($cfg, $storeid);
406 # no need to migrate shared content
407 return if $storeid eq $target_storeid && $scfg->{shared
};
409 my $tcfg = storage_config
($cfg, $target_storeid);
411 my $target_volid = "${target_storeid}:${target_volname}";
413 my $errstr = "unable to migrate '$volid' to '${target_volid}' on host '$target_host'";
415 my $sshoptions = "-o 'BatchMode=yes'";
416 my $ssh = "/usr/bin/ssh $sshoptions";
418 local $ENV{RSYNC_RSH
} = $ssh;
420 # only implemented for file system based storage
424 my $src_plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
425 my $dst_plugin = PVE
::Storage
::Plugin-
>lookup($tcfg->{type
});
426 my $src = $src_plugin->path($scfg, $volname, $storeid);
427 my $dst = $dst_plugin->path($tcfg, $target_volname, $target_storeid);
429 my $dirname = dirname
($dst);
431 if ($tcfg->{shared
}) { # we can do a local copy
433 run_command
(['/bin/mkdir', '-p', $dirname]);
435 run_command
(['/bin/cp', $src, $dst]);
439 run_command
(['/usr/bin/ssh', "root\@${target_host}",
440 '/bin/mkdir', '-p', $dirname]);
442 # we use rsync with --sparse, so we can't use --inplace,
443 # so we remove file on the target if it already exists to
445 my ($size, $format) = PVE
::Storage
::Plugin
::file_size_info
($src);
446 if ($format && ($format eq 'raw') && $size) {
447 run_command
(['/usr/bin/ssh', "root\@${target_host}",
452 my $cmd = ['/usr/bin/rsync', '--progress', '--sparse', '--whole-file',
453 $src, "root\@${target_host}:$dst"];
457 run_command
($cmd, outfunc
=> sub {
460 if ($line =~ m/^\s*(\d+\s+(\d+)%\s.*)$/) {
463 print "rsync status: $1\n";
473 die "$errstr - target type '$tcfg->{type}' not implemented\n";
476 die "$errstr - source type '$scfg->{type}' not implemented\n";
481 my ($cfg, $volid, $vmid) = @_;
483 my ($storeid, $volname) = parse_volume_id
($volid);
485 my $scfg = storage_config
($cfg, $storeid);
487 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
489 activate_storage
($cfg, $storeid);
491 # lock shared storage
492 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
493 my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid);
494 return "$storeid:$volname";
498 sub vdisk_create_base
{
499 my ($cfg, $volid) = @_;
501 my ($storeid, $volname) = parse_volume_id
($volid);
503 my $scfg = storage_config
($cfg, $storeid);
505 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
507 activate_storage
($cfg, $storeid);
509 # lock shared storage
510 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
511 my $volname = $plugin->create_base($storeid, $scfg, $volname);
512 return "$storeid:$volname";
517 my ($cfg, $storeid, $vmid, $fmt, $name, $size) = @_;
519 die "no storage id specified\n" if !$storeid;
521 PVE
::JSONSchema
::parse_storage_id
($storeid);
523 my $scfg = storage_config
($cfg, $storeid);
525 die "no VMID specified\n" if !$vmid;
527 $vmid = parse_vmid
($vmid);
529 my $defformat = PVE
::Storage
::Plugin
::default_format
($scfg);
531 $fmt = $defformat if !$fmt;
533 activate_storage
($cfg, $storeid);
535 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
537 # lock shared storage
538 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
539 my $volname = $plugin->alloc_image($storeid, $scfg, $vmid, $fmt, $name, $size);
540 return "$storeid:$volname";
545 my ($cfg, $volid) = @_;
547 my ($storeid, $volname) = parse_volume_id
($volid);
549 my $scfg = storage_config
($cfg, $storeid);
551 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
553 activate_storage
($cfg, $storeid);
557 # lock shared storage
558 $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
560 my ($vtype, $name, $vmid, undef, undef, $isBase) =
561 $plugin->parse_volname($volname);
563 my $vollist = $plugin->list_images($storeid, $scfg);
564 foreach my $info (@$vollist) {
565 my (undef, $tmpvolname) = parse_volume_id
($info->{volid
});
566 my $basename = undef;
567 my $basevmid = undef;
570 (undef, undef, undef, $basename, $basevmid) =
571 $plugin->parse_volname($tmpvolname);
574 if ($basename && defined($basevmid) && $basevmid == $vmid && $basename eq $name) {
575 die "base volume '$volname' is still in use " .
576 "(use by '$tmpvolname')\n";
580 my $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname, $isBase);
583 return if !$cleanup_worker;
585 my $rpcenv = PVE
::RPCEnvironment
::get
();
586 my $authuser = $rpcenv->get_user();
588 $rpcenv->fork_worker('imgdel', undef, $authuser, $cleanup_worker);
591 #list iso or openvz template ($tt = <iso|vztmpl|backup>)
593 my ($cfg, $storeid, $tt) = @_;
595 die "unknown template type '$tt'\n"
596 if !($tt eq 'iso' || $tt eq 'vztmpl' || $tt eq 'backup');
598 my $ids = $cfg->{ids
};
600 storage_check_enabled
($cfg, $storeid) if ($storeid);
606 foreach my $sid (keys %$ids) {
607 next if $storeid && $storeid ne $sid;
609 my $scfg = $ids->{$sid};
610 my $type = $scfg->{type
};
612 next if !storage_check_enabled
($cfg, $sid, undef, 1);
614 next if $tt eq 'iso' && !$scfg->{content
}->{iso
};
615 next if $tt eq 'vztmpl' && !$scfg->{content
}->{vztmpl
};
616 next if $tt eq 'backup' && !$scfg->{content
}->{backup
};
618 activate_storage
($cfg, $sid);
621 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
623 my $path = $plugin->get_subdir($scfg, $tt);
625 foreach my $fn (<$path/*>) {
630 next if $fn !~ m!/([^/]+\.[Ii][Ss][Oo])$!;
632 $info = { volid
=> "$sid:iso/$1", format
=> 'iso' };
634 } elsif ($tt eq 'vztmpl') {
635 next if $fn !~ m!/([^/]+\.tar\.gz)$!;
637 $info = { volid
=> "$sid:vztmpl/$1", format
=> 'tgz' };
639 } elsif ($tt eq 'backup') {
640 next if $fn !~ m!/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!;
642 $info = { volid
=> "$sid:backup/$1", format
=> $2 };
645 $info->{size
} = -s
$fn;
647 push @{$res->{$sid}}, $info;
652 @{$res->{$sid}} = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @{$res->{$sid}} if $res->{$sid};
660 my ($cfg, $storeid, $vmid, $vollist) = @_;
662 my $ids = $cfg->{ids
};
664 storage_check_enabled
($cfg, $storeid) if ($storeid);
668 # prepare/activate/refresh all storages
670 my $storage_list = [];
672 foreach my $volid (@$vollist) {
673 my ($sid, undef) = parse_volume_id
($volid);
674 next if !defined($ids->{$sid});
675 next if !storage_check_enabled
($cfg, $sid, undef, 1);
676 push @$storage_list, $sid;
679 foreach my $sid (keys %$ids) {
680 next if $storeid && $storeid ne $sid;
681 next if !storage_check_enabled
($cfg, $sid, undef, 1);
682 push @$storage_list, $sid;
688 activate_storage_list
($cfg, $storage_list, $cache);
690 foreach my $sid (keys %$ids) {
691 next if $storeid && $storeid ne $sid;
692 next if !storage_check_enabled
($cfg, $sid, undef, 1);
694 my $scfg = $ids->{$sid};
695 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
696 $res->{$sid} = $plugin->list_images($sid, $scfg, $vmid, $vollist, $cache);
697 @{$res->{$sid}} = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @{$res->{$sid}} if $res->{$sid};
705 my $filename = "/sys/kernel/uevent_seqnum";
708 if (my $fh = IO
::File-
>new($filename, "r")) {
710 if ($line =~ m/^(\d+)$/) {
718 sub activate_storage
{
719 my ($cfg, $storeid, $cache) = @_;
721 $cache = {} if !$cache;
723 my $scfg = storage_check_enabled
($cfg, $storeid);
725 return if $cache->{activated
}->{$storeid};
727 $cache->{uevent_seqnum
} = uevent_seqnum
() if !$cache->{uevent_seqnum
};
729 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
732 my ($baseid, undef) = parse_volume_id
($scfg->{base
});
733 activate_storage
($cfg, $baseid, $cache);
736 if (!$plugin->check_connection($storeid, $scfg)) {
737 die "storage '$storeid' is not online\n";
740 $plugin->activate_storage($storeid, $scfg, $cache);
742 my $newseq = uevent_seqnum
();
744 # only call udevsettle if there are events
745 if ($newseq > $cache->{uevent_seqnum
}) {
747 system ("$UDEVADM settle --timeout=$timeout"); # ignore errors
748 $cache->{uevent_seqnum
} = $newseq;
751 $cache->{activated
}->{$storeid} = 1;
754 sub activate_storage_list
{
755 my ($cfg, $storeid_list, $cache) = @_;
757 $cache = {} if !$cache;
759 foreach my $storeid (@$storeid_list) {
760 activate_storage
($cfg, $storeid, $cache);
764 sub deactivate_storage
{
765 my ($cfg, $storeid) = @_;
767 my $scfg = storage_config
($cfg, $storeid);
768 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
771 $plugin->deactivate_storage($storeid, $scfg, $cache);
774 sub activate_volumes
{
775 my ($cfg, $vollist, $exclusive) = @_;
777 return if !($vollist && scalar(@$vollist));
779 my $storagehash = {};
780 foreach my $volid (@$vollist) {
781 my ($storeid, undef) = parse_volume_id
($volid);
782 $storagehash->{$storeid} = 1;
787 activate_storage_list
($cfg, [keys %$storagehash], $cache);
789 foreach my $volid (@$vollist) {
790 my ($storeid, $volname) = parse_volume_id
($volid);
791 my $scfg = storage_config
($cfg, $storeid);
792 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
793 $plugin->activate_volume($storeid, $scfg, $volname, $exclusive, $cache);
797 sub deactivate_volumes
{
798 my ($cfg, $vollist) = @_;
800 return if !($vollist && scalar(@$vollist));
805 foreach my $volid (@$vollist) {
806 my ($storeid, $volname) = parse_volume_id
($volid);
808 my $scfg = storage_config
($cfg, $storeid);
809 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
812 $plugin->deactivate_volume($storeid, $scfg, $volname, $cache);
816 push @errlist, $volid;
820 die "volume deativation failed: " . join(' ', @errlist)
825 my ($cfg, $content) = @_;
827 my $ids = $cfg->{ids
};
832 foreach my $storeid (keys %$ids) {
834 next if $content && !$ids->{$storeid}->{content
}->{$content};
836 next if !storage_check_enabled
($cfg, $storeid, undef, 1);
838 my $type = $ids->{$storeid}->{type
};
840 $info->{$storeid} = {
845 shared
=> $ids->{$storeid}->{shared
} ?
1 : 0,
846 content
=> PVE
::Storage
::Plugin
::content_hash_to_string
($ids->{$storeid}->{content
}),
850 push @$slist, $storeid;
855 foreach my $storeid (keys %$ids) {
856 my $scfg = $ids->{$storeid};
857 next if !$info->{$storeid};
859 eval { activate_storage
($cfg, $storeid, $cache); };
865 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
866 my ($total, $avail, $used, $active);
867 eval { ($total, $avail, $used, $active) = $plugin->status($storeid, $scfg, $cache); };
870 $info->{$storeid}->{total
} = $total;
871 $info->{$storeid}->{avail
} = $avail;
872 $info->{$storeid}->{used
} = $used;
873 $info->{$storeid}->{active
} = $active;
882 my $packed_ip = gethostbyname($server);
883 if (defined $packed_ip) {
884 return inet_ntoa
($packed_ip);
890 my ($server_in) = @_;
893 if (!($server = resolv_server
($server_in))) {
894 die "unable to resolve address for server '${server_in}'\n";
897 my $cmd = ['/sbin/showmount', '--no-headers', '--exports', $server];
900 run_command
($cmd, outfunc
=> sub {
903 # note: howto handle white spaces in export path??
904 if ($line =~ m!^(/\S+)\s+(.+)$!) {
913 my ($portal, $noerr) = @_;
915 if ($portal =~ m/^([^:]+)(:(\d+))?$/) {
919 if (my $ip = resolv_server
($server)) {
921 return $port ?
"$server:$port" : $server;
924 return undef if $noerr;
926 raise_param_exc
({ portal
=> "unable to resolve portal address '$portal'" });
929 # idea is from usbutils package (/usr/bin/usb-devices) script
930 sub __scan_usb_device
{
931 my ($res, $devpath, $parent, $level) = @_;
933 return if ! -d
$devpath;
934 return if $level && $devpath !~ m/^.*[-.](\d+)$/;
935 my $port = $level ?
int($1 - 1) : 0;
937 my $busnum = int(file_read_firstline
("$devpath/busnum"));
938 my $devnum = int(file_read_firstline
("$devpath/devnum"));
945 speed
=> file_read_firstline
("$devpath/speed"),
946 class => hex(file_read_firstline
("$devpath/bDeviceClass")),
947 vendid
=> file_read_firstline
("$devpath/idVendor"),
948 prodid
=> file_read_firstline
("$devpath/idProduct"),
952 my $usbpath = $devpath;
953 $usbpath =~ s
|^.*/\d
+\
-||;
954 $d->{usbpath
} = $usbpath;
957 my $product = file_read_firstline
("$devpath/product");
958 $d->{product
} = $product if $product;
960 my $manu = file_read_firstline
("$devpath/manufacturer");
961 $d->{manufacturer
} = $manu if $manu;
963 my $serial => file_read_firstline
("$devpath/serial");
964 $d->{serial
} = $serial if $serial;
968 foreach my $subdev (<$devpath/$busnum-*>) {
969 next if $subdev !~ m
|/$busnum-[0-9]+(\
.[0-9]+)*$|;
970 __scan_usb_device
($res, $subdev, $devnum, $level + 1);
979 foreach my $device (</sys/bus
/usb
/devices
/usb
*>) {
980 __scan_usb_device
($devlist, $device, 0, 0);
987 my ($portal_in) = @_;
990 if (!($portal = resolv_portal
($portal_in))) {
991 die "unable to parse/resolve portal address '${portal_in}'\n";
994 return PVE
::Storage
::ISCSIPlugin
::iscsi_discovery
($portal);
997 sub storage_default_format
{
998 my ($cfg, $storeid) = @_;
1000 my $scfg = storage_config
($cfg, $storeid);
1002 return PVE
::Storage
::Plugin
::default_format
($scfg);
1005 sub vgroup_is_used
{
1006 my ($cfg, $vgname) = @_;
1008 foreach my $storeid (keys %{$cfg->{ids
}}) {
1009 my $scfg = storage_config
($cfg, $storeid);
1010 if ($scfg->{type
} eq 'lvm' && $scfg->{vgname
} eq $vgname) {
1018 sub target_is_used
{
1019 my ($cfg, $target) = @_;
1021 foreach my $storeid (keys %{$cfg->{ids
}}) {
1022 my $scfg = storage_config
($cfg, $storeid);
1023 if ($scfg->{type
} eq 'iscsi' && $scfg->{target
} eq $target) {
1031 sub volume_is_used
{
1032 my ($cfg, $volid) = @_;
1034 foreach my $storeid (keys %{$cfg->{ids
}}) {
1035 my $scfg = storage_config
($cfg, $storeid);
1036 if ($scfg->{base
} && $scfg->{base
} eq $volid) {
1044 sub storage_is_used
{
1045 my ($cfg, $storeid) = @_;
1047 foreach my $sid (keys %{$cfg->{ids
}}) {
1048 my $scfg = storage_config
($cfg, $sid);
1049 next if !$scfg->{base
};
1050 my ($st) = parse_volume_id
($scfg->{base
});
1051 return 1 if $st && $st eq $storeid;
1058 my ($list, $func) = @_;
1062 foreach my $sid (keys %$list) {
1063 foreach my $info (@{$list->{$sid}}) {
1064 my $volid = $info->{volid
};
1065 my ($sid1, $volname) = parse_volume_id
($volid, 1);
1066 if ($sid1 && $sid1 eq $sid) {
1067 &$func ($volid, $sid, $info);
1069 warn "detected strange volid '$volid' in volume list for '$sid'\n";