]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage.pm
710c7ae25a35879e42f5da7244cb2bcbd0935727
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";
186 sub volume_has_feature
{
187 my ($cfg, $feature, $volid, $snap, $running) = @_;
189 my ($storeid, $volname) = parse_volume_id
($volid, 1);
191 my $scfg = storage_config
($cfg, $storeid);
192 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
193 return $plugin->volume_has_feature($scfg, $feature, $storeid, $volname, $snap, $running);
194 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
202 my ($cfg, $storeid, $vmid) = @_;
204 my $scfg = storage_config
($cfg, $storeid);
205 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
207 my $path = $plugin->get_subdir($scfg, 'images');
209 return $vmid ?
"$path/$vmid" : $path;
212 sub get_private_dir
{
213 my ($cfg, $storeid, $vmid) = @_;
215 my $scfg = storage_config
($cfg, $storeid);
216 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
218 my $path = $plugin->get_subdir($scfg, 'rootdir');
220 return $vmid ?
"$path/$vmid" : $path;
224 my ($cfg, $storeid) = @_;
226 my $scfg = storage_config
($cfg, $storeid);
227 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
229 return $plugin->get_subdir($scfg, 'iso');
233 my ($cfg, $storeid) = @_;
235 my $scfg = storage_config
($cfg, $storeid);
236 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
238 return $plugin->get_subdir($scfg, 'vztmpl');
242 my ($cfg, $storeid) = @_;
244 my $scfg = storage_config
($cfg, $storeid);
245 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
247 return $plugin->get_subdir($scfg, 'backup');
250 # library implementation
255 die "VMID '$vmid' contains illegal characters\n" if $vmid !~ m/^\d+$/;
260 PVE
::JSONSchema
::register_format
('pve-volume-id', \
&parse_volume_id
);
261 sub parse_volume_id
{
262 my ($volid, $noerr) = @_;
264 if ($volid =~ m/^([a-z][a-z0-9\-\_\.]*[a-z0-9]):(.+)$/i) {
265 return wantarray ?
($1, $2) : $1;
267 return undef if $noerr;
268 die "unable to parse volume ID '$volid'\n";
272 my ($cfg, $volid) = @_;
274 my ($sid, $volname) = parse_volume_id
($volid, 1);
277 if (my $scfg = $cfg->{ids
}->{$sid}) {
278 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
279 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
280 $plugin->parse_volname($volname);
281 return $isBase ?
1 : 0;
283 # stale volid with undefined storage - so we can just guess
284 if ($volid =~ m/base-/) {
292 # try to map a filesystem path to a volume identifier
293 sub path_to_volume_id
{
294 my ($cfg, $path) = @_;
296 my $ids = $cfg->{ids
};
298 my ($sid, $volname) = parse_volume_id
($path, 1);
300 if (my $scfg = $ids->{$sid}) {
302 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
303 my ($vtype, $name, $vmid) = $plugin->parse_volname($volname);
304 return ($vtype, $path);
310 # Note: abs_path() return undef if $path doesn not exist
311 # for example when nfs storage is not mounted
312 $path = abs_path
($path) || $path;
314 foreach my $sid (keys %$ids) {
315 my $scfg = $ids->{$sid};
316 next if !$scfg->{path
};
317 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
318 my $imagedir = $plugin->get_subdir($scfg, 'images');
319 my $isodir = $plugin->get_subdir($scfg, 'iso');
320 my $tmpldir = $plugin->get_subdir($scfg, 'vztmpl');
321 my $backupdir = $plugin->get_subdir($scfg, 'backup');
322 my $privatedir = $plugin->get_subdir($scfg, 'rootdir');
324 if ($path =~ m!^$imagedir/(\d+)/([^/\s]+)$!) {
328 my $vollist = $plugin->list_images($sid, $scfg, $vmid);
329 foreach my $info (@$vollist) {
330 my ($storeid, $volname) = parse_volume_id
($info->{volid
});
331 my $volpath = $plugin->path($scfg, $volname, $storeid);
332 if ($volpath eq $path) {
333 return ('images', $info->{volid
});
336 } elsif ($path =~ m!^$isodir/([^/]+\.[Ii][Ss][Oo])$!) {
338 return ('iso', "$sid:iso/$name");
339 } elsif ($path =~ m!^$tmpldir/([^/]+\.tar\.gz)$!) {
341 return ('vztmpl', "$sid:vztmpl/$name");
342 } elsif ($path =~ m!^$privatedir/(\d+)$!) {
344 return ('rootdir', "$sid:rootdir/$vmid");
345 } elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!) {
347 return ('iso', "$sid:backup/$name");
351 # can't map path to volume id
356 my ($cfg, $volid) = @_;
358 my ($storeid, $volname) = parse_volume_id
($volid);
360 my $scfg = storage_config
($cfg, $storeid);
362 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
363 my ($path, $owner, $vtype) = $plugin->path($scfg, $volname, $storeid);
364 return wantarray ?
($path, $owner, $vtype) : $path;
367 sub storage_migrate
{
368 my ($cfg, $volid, $target_host, $target_storeid, $target_volname) = @_;
370 my ($storeid, $volname) = parse_volume_id
($volid);
371 $target_volname = $volname if !$target_volname;
373 my $scfg = storage_config
($cfg, $storeid);
375 # no need to migrate shared content
376 return if $storeid eq $target_storeid && $scfg->{shared
};
378 my $tcfg = storage_config
($cfg, $target_storeid);
380 my $target_volid = "${target_storeid}:${target_volname}";
382 my $errstr = "unable to migrate '$volid' to '${target_volid}' on host '$target_host'";
384 my $sshoptions = "-o 'BatchMode=yes'";
385 my $ssh = "/usr/bin/ssh $sshoptions";
387 local $ENV{RSYNC_RSH
} = $ssh;
389 # only implemented for file system based storage
393 my $src_plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
394 my $dst_plugin = PVE
::Storage
::Plugin-
>lookup($tcfg->{type
});
395 my $src = $src_plugin->path($scfg, $volname, $storeid);
396 my $dst = $dst_plugin->path($tcfg, $target_volname, $target_storeid);
398 my $dirname = dirname
($dst);
400 if ($tcfg->{shared
}) { # we can do a local copy
402 run_command
(['/bin/mkdir', '-p', $dirname]);
404 run_command
(['/bin/cp', $src, $dst]);
408 run_command
(['/usr/bin/ssh', "root\@${target_host}",
409 '/bin/mkdir', '-p', $dirname]);
411 # we use rsync with --sparse, so we can't use --inplace,
412 # so we remove file on the target if it already exists to
414 my ($size, $format) = PVE
::Storage
::Plugin
::file_size_info
($src);
415 if ($format && ($format eq 'raw') && $size) {
416 run_command
(['/usr/bin/ssh', "root\@${target_host}",
421 my $cmd = ['/usr/bin/rsync', '--progress', '--sparse', '--whole-file',
422 $src, "root\@${target_host}:$dst"];
426 run_command
($cmd, outfunc
=> sub {
429 if ($line =~ m/^\s*(\d+\s+(\d+)%\s.*)$/) {
432 print "rsync status: $1\n";
442 die "$errstr - target type '$tcfg->{type}' not implemented\n";
445 die "$errstr - source type '$scfg->{type}' not implemented\n";
450 my ($cfg, $volid, $vmid) = @_;
452 my ($storeid, $volname) = parse_volume_id
($volid);
454 my $scfg = storage_config
($cfg, $storeid);
456 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
458 activate_storage
($cfg, $storeid);
460 # lock shared storage
461 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
462 my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid);
463 return "$storeid:$volname";
467 sub vdisk_create_base
{
468 my ($cfg, $volid) = @_;
470 my ($storeid, $volname) = parse_volume_id
($volid);
472 my $scfg = storage_config
($cfg, $storeid);
474 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
476 activate_storage
($cfg, $storeid);
478 # lock shared storage
479 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
480 my $volname = $plugin->create_base($storeid, $scfg, $volname);
481 return "$storeid:$volname";
486 my ($cfg, $storeid, $vmid, $fmt, $name, $size) = @_;
488 die "no storage id specified\n" if !$storeid;
490 PVE
::JSONSchema
::parse_storage_id
($storeid);
492 my $scfg = storage_config
($cfg, $storeid);
494 die "no VMID specified\n" if !$vmid;
496 $vmid = parse_vmid
($vmid);
498 my $defformat = PVE
::Storage
::Plugin
::default_format
($scfg);
500 $fmt = $defformat if !$fmt;
502 activate_storage
($cfg, $storeid);
504 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
506 # lock shared storage
507 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
508 my $volname = $plugin->alloc_image($storeid, $scfg, $vmid, $fmt, $name, $size);
509 return "$storeid:$volname";
514 my ($cfg, $volid) = @_;
516 my ($storeid, $volname) = parse_volume_id
($volid);
518 my $scfg = storage_config
($cfg, $storeid);
520 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
522 activate_storage
($cfg, $storeid);
526 # lock shared storage
527 $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
528 my $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname);
531 return if !$cleanup_worker;
533 my $rpcenv = PVE
::RPCEnvironment
::get
();
534 my $authuser = $rpcenv->get_user();
536 $rpcenv->fork_worker('imgdel', undef, $authuser, $cleanup_worker);
539 #list iso or openvz template ($tt = <iso|vztmpl|backup>)
541 my ($cfg, $storeid, $tt) = @_;
543 die "unknown template type '$tt'\n"
544 if !($tt eq 'iso' || $tt eq 'vztmpl' || $tt eq 'backup');
546 my $ids = $cfg->{ids
};
548 storage_check_enabled
($cfg, $storeid) if ($storeid);
554 foreach my $sid (keys %$ids) {
555 next if $storeid && $storeid ne $sid;
557 my $scfg = $ids->{$sid};
558 my $type = $scfg->{type
};
560 next if !storage_check_enabled
($cfg, $sid, undef, 1);
562 next if $tt eq 'iso' && !$scfg->{content
}->{iso
};
563 next if $tt eq 'vztmpl' && !$scfg->{content
}->{vztmpl
};
564 next if $tt eq 'backup' && !$scfg->{content
}->{backup
};
566 activate_storage
($cfg, $sid);
569 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
571 my $path = $plugin->get_subdir($scfg, $tt);
573 foreach my $fn (<$path/*>) {
578 next if $fn !~ m!/([^/]+\.[Ii][Ss][Oo])$!;
580 $info = { volid
=> "$sid:iso/$1", format
=> 'iso' };
582 } elsif ($tt eq 'vztmpl') {
583 next if $fn !~ m!/([^/]+\.tar\.gz)$!;
585 $info = { volid
=> "$sid:vztmpl/$1", format
=> 'tgz' };
587 } elsif ($tt eq 'backup') {
588 next if $fn !~ m!/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!;
590 $info = { volid
=> "$sid:backup/$1", format
=> $2 };
593 $info->{size
} = -s
$fn;
595 push @{$res->{$sid}}, $info;
600 @{$res->{$sid}} = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @{$res->{$sid}} if $res->{$sid};
608 my ($cfg, $storeid, $vmid, $vollist) = @_;
610 my $ids = $cfg->{ids
};
612 storage_check_enabled
($cfg, $storeid) if ($storeid);
616 # prepare/activate/refresh all storages
618 my $storage_list = [];
620 foreach my $volid (@$vollist) {
621 my ($sid, undef) = parse_volume_id
($volid);
622 next if !defined($ids->{$sid});
623 next if !storage_check_enabled
($cfg, $sid, undef, 1);
624 push @$storage_list, $sid;
627 foreach my $sid (keys %$ids) {
628 next if $storeid && $storeid ne $sid;
629 next if !storage_check_enabled
($cfg, $sid, undef, 1);
630 push @$storage_list, $sid;
636 activate_storage_list
($cfg, $storage_list, $cache);
638 foreach my $sid (keys %$ids) {
639 next if $storeid && $storeid ne $sid;
640 next if !storage_check_enabled
($cfg, $sid, undef, 1);
642 my $scfg = $ids->{$sid};
643 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
644 $res->{$sid} = $plugin->list_images($sid, $scfg, $vmid, $vollist, $cache);
645 @{$res->{$sid}} = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @{$res->{$sid}} if $res->{$sid};
653 my $filename = "/sys/kernel/uevent_seqnum";
656 if (my $fh = IO
::File-
>new($filename, "r")) {
658 if ($line =~ m/^(\d+)$/) {
666 sub activate_storage
{
667 my ($cfg, $storeid, $cache) = @_;
669 $cache = {} if !$cache;
671 my $scfg = storage_check_enabled
($cfg, $storeid);
673 return if $cache->{activated
}->{$storeid};
675 $cache->{uevent_seqnum
} = uevent_seqnum
() if !$cache->{uevent_seqnum
};
677 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
680 my ($baseid, undef) = parse_volume_id
($scfg->{base
});
681 activate_storage
($cfg, $baseid, $cache);
684 if (!$plugin->check_connection($storeid, $scfg)) {
685 die "storage '$storeid' is not online\n";
688 $plugin->activate_storage($storeid, $scfg, $cache);
690 my $newseq = uevent_seqnum
();
692 # only call udevsettle if there are events
693 if ($newseq > $cache->{uevent_seqnum
}) {
695 system ("$UDEVADM settle --timeout=$timeout"); # ignore errors
696 $cache->{uevent_seqnum
} = $newseq;
699 $cache->{activated
}->{$storeid} = 1;
702 sub activate_storage_list
{
703 my ($cfg, $storeid_list, $cache) = @_;
705 $cache = {} if !$cache;
707 foreach my $storeid (@$storeid_list) {
708 activate_storage
($cfg, $storeid, $cache);
712 sub deactivate_storage
{
713 my ($cfg, $storeid) = @_;
715 my $scfg = storage_config
($cfg, $storeid);
716 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
719 $plugin->deactivate_storage($storeid, $scfg, $cache);
722 sub activate_volumes
{
723 my ($cfg, $vollist, $exclusive) = @_;
725 return if !($vollist && scalar(@$vollist));
727 my $storagehash = {};
728 foreach my $volid (@$vollist) {
729 my ($storeid, undef) = parse_volume_id
($volid);
730 $storagehash->{$storeid} = 1;
735 activate_storage_list
($cfg, [keys %$storagehash], $cache);
737 foreach my $volid (@$vollist) {
738 my ($storeid, $volname) = parse_volume_id
($volid);
739 my $scfg = storage_config
($cfg, $storeid);
740 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
741 $plugin->activate_volume($storeid, $scfg, $volname, $exclusive, $cache);
745 sub deactivate_volumes
{
746 my ($cfg, $vollist) = @_;
748 return if !($vollist && scalar(@$vollist));
753 foreach my $volid (@$vollist) {
754 my ($storeid, $volname) = parse_volume_id
($volid);
756 my $scfg = storage_config
($cfg, $storeid);
757 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
760 $plugin->deactivate_volume($storeid, $scfg, $volname, $cache);
764 push @errlist, $volid;
768 die "volume deativation failed: " . join(' ', @errlist)
773 my ($cfg, $content) = @_;
775 my $ids = $cfg->{ids
};
780 foreach my $storeid (keys %$ids) {
782 next if $content && !$ids->{$storeid}->{content
}->{$content};
784 next if !storage_check_enabled
($cfg, $storeid, undef, 1);
786 my $type = $ids->{$storeid}->{type
};
788 $info->{$storeid} = {
793 shared
=> $ids->{$storeid}->{shared
} ?
1 : 0,
794 content
=> PVE
::Storage
::Plugin
::content_hash_to_string
($ids->{$storeid}->{content
}),
798 push @$slist, $storeid;
803 foreach my $storeid (keys %$ids) {
804 my $scfg = $ids->{$storeid};
805 next if !$info->{$storeid};
807 eval { activate_storage
($cfg, $storeid, $cache); };
813 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
814 my ($total, $avail, $used, $active);
815 eval { ($total, $avail, $used, $active) = $plugin->status($storeid, $scfg, $cache); };
818 $info->{$storeid}->{total
} = $total;
819 $info->{$storeid}->{avail
} = $avail;
820 $info->{$storeid}->{used
} = $used;
821 $info->{$storeid}->{active
} = $active;
830 my $packed_ip = gethostbyname($server);
831 if (defined $packed_ip) {
832 return inet_ntoa
($packed_ip);
838 my ($server_in) = @_;
841 if (!($server = resolv_server
($server_in))) {
842 die "unable to resolve address for server '${server_in}'\n";
845 my $cmd = ['/sbin/showmount', '--no-headers', '--exports', $server];
848 run_command
($cmd, outfunc
=> sub {
851 # note: howto handle white spaces in export path??
852 if ($line =~ m!^(/\S+)\s+(.+)$!) {
861 my ($portal, $noerr) = @_;
863 if ($portal =~ m/^([^:]+)(:(\d+))?$/) {
867 if (my $ip = resolv_server
($server)) {
869 return $port ?
"$server:$port" : $server;
872 return undef if $noerr;
874 raise_param_exc
({ portal
=> "unable to resolve portal address '$portal'" });
877 # idea is from usbutils package (/usr/bin/usb-devices) script
878 sub __scan_usb_device
{
879 my ($res, $devpath, $parent, $level) = @_;
881 return if ! -d
$devpath;
882 return if $level && $devpath !~ m/^.*[-.](\d+)$/;
883 my $port = $level ?
int($1 - 1) : 0;
885 my $busnum = int(file_read_firstline
("$devpath/busnum"));
886 my $devnum = int(file_read_firstline
("$devpath/devnum"));
893 speed
=> file_read_firstline
("$devpath/speed"),
894 class => hex(file_read_firstline
("$devpath/bDeviceClass")),
895 vendid
=> file_read_firstline
("$devpath/idVendor"),
896 prodid
=> file_read_firstline
("$devpath/idProduct"),
900 my $usbpath = $devpath;
901 $usbpath =~ s
|^.*/\d
+\
-||;
902 $d->{usbpath
} = $usbpath;
905 my $product = file_read_firstline
("$devpath/product");
906 $d->{product
} = $product if $product;
908 my $manu = file_read_firstline
("$devpath/manufacturer");
909 $d->{manufacturer
} = $manu if $manu;
911 my $serial => file_read_firstline
("$devpath/serial");
912 $d->{serial
} = $serial if $serial;
916 foreach my $subdev (<$devpath/$busnum-*>) {
917 next if $subdev !~ m
|/$busnum-[0-9]+(\
.[0-9]+)*$|;
918 __scan_usb_device
($res, $subdev, $devnum, $level + 1);
927 foreach my $device (</sys/bus
/usb
/devices
/usb
*>) {
928 __scan_usb_device
($devlist, $device, 0, 0);
935 my ($portal_in) = @_;
938 if (!($portal = resolv_portal
($portal_in))) {
939 die "unable to parse/resolve portal address '${portal_in}'\n";
942 return PVE
::Storage
::ISCSIPlugin
::iscsi_discovery
($portal);
945 sub storage_default_format
{
946 my ($cfg, $storeid) = @_;
948 my $scfg = storage_config
($cfg, $storeid);
950 return PVE
::Storage
::Plugin
::default_format
($scfg);
954 my ($cfg, $vgname) = @_;
956 foreach my $storeid (keys %{$cfg->{ids
}}) {
957 my $scfg = storage_config
($cfg, $storeid);
958 if ($scfg->{type
} eq 'lvm' && $scfg->{vgname
} eq $vgname) {
967 my ($cfg, $target) = @_;
969 foreach my $storeid (keys %{$cfg->{ids
}}) {
970 my $scfg = storage_config
($cfg, $storeid);
971 if ($scfg->{type
} eq 'iscsi' && $scfg->{target
} eq $target) {
980 my ($cfg, $volid) = @_;
982 foreach my $storeid (keys %{$cfg->{ids
}}) {
983 my $scfg = storage_config
($cfg, $storeid);
984 if ($scfg->{base
} && $scfg->{base
} eq $volid) {
992 sub storage_is_used
{
993 my ($cfg, $storeid) = @_;
995 foreach my $sid (keys %{$cfg->{ids
}}) {
996 my $scfg = storage_config
($cfg, $sid);
997 next if !$scfg->{base
};
998 my ($st) = parse_volume_id
($scfg->{base
});
999 return 1 if $st && $st eq $storeid;
1006 my ($list, $func) = @_;
1010 foreach my $sid (keys %$list) {
1011 foreach my $info (@{$list->{$sid}}) {
1012 my $volid = $info->{volid
};
1013 my ($sid1, $volname) = parse_volume_id
($volid, 1);
1014 if ($sid1 && $sid1 eq $sid) {
1015 &$func ($volid, $sid, $info);
1017 warn "detected strange volid '$volid' in volume list for '$sid'\n";