16 use PVE
::Tools
qw(run_command file_read_firstline dir_glob_foreach $IPV6RE);
17 use PVE
::Cluster
qw(cfs_read_file cfs_write_file cfs_lock_file);
18 use PVE
::Exception
qw(raise_param_exc);
21 use PVE
::RPCEnvironment
;
23 use PVE
::Storage
::Plugin
;
24 use PVE
::Storage
::DirPlugin
;
25 use PVE
::Storage
::LVMPlugin
;
26 use PVE
::Storage
::LvmThinPlugin
;
27 use PVE
::Storage
::NFSPlugin
;
28 use PVE
::Storage
::CIFSPlugin
;
29 use PVE
::Storage
::ISCSIPlugin
;
30 use PVE
::Storage
::RBDPlugin
;
31 use PVE
::Storage
::CephFSPlugin
;
32 use PVE
::Storage
::ISCSIDirectPlugin
;
33 use PVE
::Storage
::GlusterfsPlugin
;
34 use PVE
::Storage
::ZFSPoolPlugin
;
35 use PVE
::Storage
::ZFSPlugin
;
36 use PVE
::Storage
::DRBDPlugin
;
38 # Storage API version. Icrement it on changes in storage API interface.
39 use constant APIVER
=> 3;
40 # Age is the number of versions we're backward compatible with.
41 # This is like having 'current=APIVER' and age='APIAGE' in libtool,
42 # see https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
43 use constant APIAGE
=> 2;
45 # load standard plugins
46 PVE
::Storage
::DirPlugin-
>register();
47 PVE
::Storage
::LVMPlugin-
>register();
48 PVE
::Storage
::LvmThinPlugin-
>register();
49 PVE
::Storage
::NFSPlugin-
>register();
50 PVE
::Storage
::CIFSPlugin-
>register();
51 PVE
::Storage
::ISCSIPlugin-
>register();
52 PVE
::Storage
::RBDPlugin-
>register();
53 PVE
::Storage
::CephFSPlugin-
>register();
54 PVE
::Storage
::ISCSIDirectPlugin-
>register();
55 PVE
::Storage
::GlusterfsPlugin-
>register();
56 PVE
::Storage
::ZFSPoolPlugin-
>register();
57 PVE
::Storage
::ZFSPlugin-
>register();
58 PVE
::Storage
::DRBDPlugin-
>register();
60 # load third-party plugins
61 if ( -d
'/usr/share/perl5/PVE/Storage/Custom' ) {
62 dir_glob_foreach
('/usr/share/perl5/PVE/Storage/Custom', '.*\.pm$', sub {
64 my $modname = 'PVE::Storage::Custom::' . $file;
65 $modname =~ s!\.pm$!!;
66 $file = 'PVE/Storage/Custom/' . $file;
71 # Check perl interface:
72 die "not derived from PVE::Storage::Plugin\n"
73 if !$modname->isa('PVE::Storage::Plugin');
74 die "does not provide an api() method\n"
75 if !$modname->can('api');
76 # Check storage API version and that file is really storage plugin.
77 my $version = $modname->api();
78 die "implements an API version newer than current ($version > " . APIVER
. ")\n"
80 my $min_version = (APIVER
- APIAGE
);
81 die "API version too old, please update the plugin ($version < $min_version)\n"
82 if $version < $min_version;
86 # If we got this far and the API version is not the same, make some
88 warn "Plugin \"$modname\" is implementing an older storage API
, an upgrade
is recommended
\n"
89 if $version != APIVER;
92 warn "Error loading storage plugin
\"$modname\": $@";
97 # initialize all plugins
98 PVE
::Storage
::Plugin-
>init();
100 my $UDEVADM = '/sbin/udevadm';
102 # PVE::Storage utility functions
105 return cfs_read_file
("storage.cfg");
111 cfs_write_file
('storage.cfg', $cfg);
114 sub lock_storage_config
{
115 my ($code, $errmsg) = @_;
117 cfs_lock_file
("storage.cfg", undef, $code);
120 $errmsg ?
die "$errmsg: $err" : die $err;
125 my ($cfg, $storeid, $noerr) = @_;
127 die "no storage ID specified\n" if !$storeid;
129 my $scfg = $cfg->{ids
}->{$storeid};
131 die "storage '$storeid' does not exists\n" if (!$noerr && !$scfg);
136 sub storage_check_node
{
137 my ($cfg, $storeid, $node, $noerr) = @_;
139 my $scfg = storage_config
($cfg, $storeid);
141 if ($scfg->{nodes
}) {
142 $node = PVE
::INotify
::nodename
() if !$node || ($node eq 'localhost');
143 if (!$scfg->{nodes
}->{$node}) {
144 die "storage '$storeid' is not available on node '$node'\n" if !$noerr;
152 sub storage_check_enabled
{
153 my ($cfg, $storeid, $node, $noerr) = @_;
155 my $scfg = storage_config
($cfg, $storeid);
157 if ($scfg->{disable
}) {
158 die "storage '$storeid' is disabled\n" if !$noerr;
162 return storage_check_node
($cfg, $storeid, $node, $noerr);
165 # storage_can_replicate:
166 # return true if storage supports replication
167 # (volumes alocated with vdisk_alloc() has replication feature)
168 sub storage_can_replicate
{
169 my ($cfg, $storeid, $format) = @_;
171 my $scfg = storage_config
($cfg, $storeid);
172 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
173 return $plugin->storage_can_replicate($scfg, $storeid, $format);
179 return keys %{$cfg->{ids
}};
183 my ($filename, $timeout) = @_;
185 return PVE
::Storage
::Plugin
::file_size_info
($filename, $timeout);
188 sub volume_size_info
{
189 my ($cfg, $volid, $timeout) = @_;
191 my ($storeid, $volname) = parse_volume_id
($volid, 1);
193 my $scfg = storage_config
($cfg, $storeid);
194 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
195 return $plugin->volume_size_info($scfg, $storeid, $volname, $timeout);
196 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
197 return file_size_info
($volid, $timeout);
204 my ($cfg, $volid, $size, $running) = @_;
206 my ($storeid, $volname) = parse_volume_id
($volid, 1);
208 my $scfg = storage_config
($cfg, $storeid);
209 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
210 return $plugin->volume_resize($scfg, $storeid, $volname, $size, $running);
211 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
212 die "resize file/device '$volid' is not possible\n";
214 die "unable to parse volume ID '$volid'\n";
218 sub volume_rollback_is_possible
{
219 my ($cfg, $volid, $snap) = @_;
221 my ($storeid, $volname) = parse_volume_id
($volid, 1);
223 my $scfg = storage_config
($cfg, $storeid);
224 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
225 return $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
226 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
227 die "snapshot rollback file/device '$volid' is not possible\n";
229 die "unable to parse volume ID '$volid'\n";
233 sub volume_snapshot
{
234 my ($cfg, $volid, $snap) = @_;
236 my ($storeid, $volname) = parse_volume_id
($volid, 1);
238 my $scfg = storage_config
($cfg, $storeid);
239 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
240 return $plugin->volume_snapshot($scfg, $storeid, $volname, $snap);
241 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
242 die "snapshot file/device '$volid' is not possible\n";
244 die "unable to parse volume ID '$volid'\n";
248 sub volume_snapshot_rollback
{
249 my ($cfg, $volid, $snap) = @_;
251 my ($storeid, $volname) = parse_volume_id
($volid, 1);
253 my $scfg = storage_config
($cfg, $storeid);
254 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
255 $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
256 return $plugin->volume_snapshot_rollback($scfg, $storeid, $volname, $snap);
257 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
258 die "snapshot rollback file/device '$volid' is not possible\n";
260 die "unable to parse volume ID '$volid'\n";
264 sub volume_snapshot_delete
{
265 my ($cfg, $volid, $snap, $running) = @_;
267 my ($storeid, $volname) = parse_volume_id
($volid, 1);
269 my $scfg = storage_config
($cfg, $storeid);
270 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
271 return $plugin->volume_snapshot_delete($scfg, $storeid, $volname, $snap, $running);
272 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
273 die "snapshot delete file/device '$volid' is not possible\n";
275 die "unable to parse volume ID '$volid'\n";
279 sub volume_has_feature
{
280 my ($cfg, $feature, $volid, $snap, $running) = @_;
282 my ($storeid, $volname) = parse_volume_id
($volid, 1);
284 my $scfg = storage_config
($cfg, $storeid);
285 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
286 return $plugin->volume_has_feature($scfg, $feature, $storeid, $volname, $snap, $running);
287 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
294 sub volume_snapshot_list
{
295 my ($cfg, $volid) = @_;
297 my ($storeid, $volname) = parse_volume_id
($volid, 1);
299 my $scfg = storage_config
($cfg, $storeid);
300 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
301 return $plugin->volume_snapshot_list($scfg, $storeid, $volname);
302 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
303 die "send file/device '$volid' is not possible\n";
305 die "unable to parse volume ID '$volid'\n";
307 # return an empty array if dataset does not exist.
311 my ($cfg, $storeid, $vmid) = @_;
313 my $scfg = storage_config
($cfg, $storeid);
314 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
316 my $path = $plugin->get_subdir($scfg, 'images');
318 return $vmid ?
"$path/$vmid" : $path;
321 sub get_private_dir
{
322 my ($cfg, $storeid, $vmid) = @_;
324 my $scfg = storage_config
($cfg, $storeid);
325 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
327 my $path = $plugin->get_subdir($scfg, 'rootdir');
329 return $vmid ?
"$path/$vmid" : $path;
333 my ($cfg, $storeid) = @_;
335 my $scfg = storage_config
($cfg, $storeid);
336 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
338 return $plugin->get_subdir($scfg, 'iso');
342 my ($cfg, $storeid) = @_;
344 my $scfg = storage_config
($cfg, $storeid);
345 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
347 return $plugin->get_subdir($scfg, 'vztmpl');
351 my ($cfg, $storeid) = @_;
353 my $scfg = storage_config
($cfg, $storeid);
354 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
356 return $plugin->get_subdir($scfg, 'backup');
359 # library implementation
364 die "VMID '$vmid' contains illegal characters\n" if $vmid !~ m/^\d+$/;
369 # NOTE: basename and basevmid are always undef for LVM-thin, where the
370 # clone -> base reference is not encoded in the volume ID.
371 # see note in PVE::Storage::LvmThinPlugin for details.
373 my ($cfg, $volid) = @_;
375 my ($storeid, $volname) = parse_volume_id
($volid);
377 my $scfg = storage_config
($cfg, $storeid);
379 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
381 # returns ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format)
383 return $plugin->parse_volname($volname);
386 sub parse_volume_id
{
387 my ($volid, $noerr) = @_;
389 return PVE
::Storage
::Plugin
::parse_volume_id
($volid, $noerr);
392 # test if we have read access to volid
393 sub check_volume_access
{
394 my ($rpcenv, $user, $cfg, $vmid, $volid) = @_;
396 my ($sid, $volname) = parse_volume_id
($volid, 1);
398 my ($vtype, undef, $ownervm) = parse_volname
($cfg, $volid);
399 if ($vtype eq 'iso' || $vtype eq 'vztmpl') {
400 # require at least read access to storage, (custom) templates/ISOs could be sensitive
401 $rpcenv->check_any($user, "/storage/$sid", ['Datastore.AllocateSpace', 'Datastore.Audit']);
402 } elsif (defined($ownervm) && defined($vmid) && ($ownervm == $vmid)) {
403 # we are owner - allow access
404 } elsif ($vtype eq 'backup' && $ownervm) {
405 $rpcenv->check($user, "/storage/$sid", ['Datastore.AllocateSpace']);
406 $rpcenv->check($user, "/vms/$ownervm", ['VM.Backup']);
408 # allow if we are Datastore administrator
409 $rpcenv->check($user, "/storage/$sid", ['Datastore.Allocate']);
412 die "Only root can pass arbitrary filesystem paths."
413 if $user ne 'root@pam';
419 my $volume_is_base_and_used__no_lock = sub {
420 my ($scfg, $storeid, $plugin, $volname) = @_;
422 my ($vtype, $name, $vmid, undef, undef, $isBase, undef) =
423 $plugin->parse_volname($volname);
426 my $vollist = $plugin->list_images($storeid, $scfg);
427 foreach my $info (@$vollist) {
428 my (undef, $tmpvolname) = parse_volume_id
($info->{volid
});
429 my $basename = undef;
430 my $basevmid = undef;
433 (undef, undef, undef, $basename, $basevmid) =
434 $plugin->parse_volname($tmpvolname);
437 if ($basename && defined($basevmid) && $basevmid == $vmid && $basename eq $name) {
445 # NOTE: this check does not work for LVM-thin, where the clone -> base
446 # reference is not encoded in the volume ID.
447 # see note in PVE::Storage::LvmThinPlugin for details.
448 sub volume_is_base_and_used
{
449 my ($cfg, $volid) = @_;
451 my ($storeid, $volname) = parse_volume_id
($volid);
452 my $scfg = storage_config
($cfg, $storeid);
453 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
455 $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
456 return &$volume_is_base_and_used__no_lock($scfg, $storeid, $plugin, $volname);
460 # try to map a filesystem path to a volume identifier
461 sub path_to_volume_id
{
462 my ($cfg, $path) = @_;
464 my $ids = $cfg->{ids
};
466 my ($sid, $volname) = parse_volume_id
($path, 1);
468 if (my $scfg = $ids->{$sid}) {
470 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
471 my ($vtype, $name, $vmid) = $plugin->parse_volname($volname);
472 return ($vtype, $path);
478 # Note: abs_path() return undef if $path doesn not exist
479 # for example when nfs storage is not mounted
480 $path = abs_path
($path) || $path;
482 foreach my $sid (keys %$ids) {
483 my $scfg = $ids->{$sid};
484 next if !$scfg->{path
};
485 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
486 my $imagedir = $plugin->get_subdir($scfg, 'images');
487 my $isodir = $plugin->get_subdir($scfg, 'iso');
488 my $tmpldir = $plugin->get_subdir($scfg, 'vztmpl');
489 my $backupdir = $plugin->get_subdir($scfg, 'backup');
490 my $privatedir = $plugin->get_subdir($scfg, 'rootdir');
492 if ($path =~ m!^$imagedir/(\d+)/([^/\s]+)$!) {
496 my $vollist = $plugin->list_images($sid, $scfg, $vmid);
497 foreach my $info (@$vollist) {
498 my ($storeid, $volname) = parse_volume_id
($info->{volid
});
499 my $volpath = $plugin->path($scfg, $volname, $storeid);
500 if ($volpath eq $path) {
501 return ('images', $info->{volid
});
504 } elsif ($path =~ m!^$isodir/([^/]+\.[Ii][Ss][Oo])$!) {
506 return ('iso', "$sid:iso/$name");
507 } elsif ($path =~ m!^$tmpldir/([^/]+\.tar\.gz)$!) {
509 return ('vztmpl', "$sid:vztmpl/$name");
510 } elsif ($path =~ m!^$privatedir/(\d+)$!) {
512 return ('rootdir', "$sid:rootdir/$vmid");
513 } elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!) {
515 return ('iso', "$sid:backup/$name");
519 # can't map path to volume id
524 my ($cfg, $volid, $snapname) = @_;
526 my ($storeid, $volname) = parse_volume_id
($volid);
528 my $scfg = storage_config
($cfg, $storeid);
530 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
531 my ($path, $owner, $vtype) = $plugin->path($scfg, $volname, $storeid, $snapname);
532 return wantarray ?
($path, $owner, $vtype) : $path;
535 sub abs_filesystem_path
{
536 my ($cfg, $volid) = @_;
539 if (PVE
::Storage
::parse_volume_id
($volid, 1)) {
540 PVE
::Storage
::activate_volumes
($cfg, [ $volid ]);
541 $path = PVE
::Storage
::path
($cfg, $volid);
544 my $abspath = abs_path
($volid);
545 if ($abspath && $abspath =~ m
|^(/.+)$|) {
546 $path = $1; # untaint any path
551 die "can't find file '$volid'\n" if !($path && -f
$path);
556 sub storage_migrate
{
557 my ($cfg, $volid, $target_sshinfo, $target_storeid, $target_volname, $base_snapshot, $snapshot, $ratelimit_bps, $insecure, $with_snapshots, $logfunc) = @_;
559 my ($storeid, $volname) = parse_volume_id
($volid);
560 $target_volname = $volname if !$target_volname;
562 my $scfg = storage_config
($cfg, $storeid);
564 # no need to migrate shared content
565 return if $storeid eq $target_storeid && $scfg->{shared
};
567 my $tcfg = storage_config
($cfg, $target_storeid);
569 my $target_volid = "${target_storeid}:${target_volname}";
571 my $target_ip = $target_sshinfo->{ip
};
572 my $errstr = "unable to migrate '$volid' to '${target_volid}' on host '$target_sshinfo->{name}'";
574 my $ssh = PVE
::Cluster
::ssh_info_to_command
($target_sshinfo);
575 my $ssh_base = PVE
::Cluster
::ssh_info_to_command_base
($target_sshinfo);
576 local $ENV{RSYNC_RSH
} = PVE
::Tools
::cmd2string
($ssh_base);
578 my @cstream = ([ '/usr/bin/cstream', '-t', $ratelimit_bps ])
579 if defined($ratelimit_bps);
581 my $migration_snapshot;
582 if (!defined($snapshot)) {
583 if ($scfg->{type
} eq 'zfspool') {
584 $migration_snapshot = 1;
585 $snapshot = '__migration__';
589 my @formats = volume_transfer_formats
($cfg, $volid, $volid, $snapshot, $base_snapshot, $with_snapshots);
590 die "cannot migrate from storage type '$scfg->{type}' to '$tcfg->{type}'\n" if !@formats;
591 my $format = $formats[0];
593 my $import_fn = '-'; # let pvesm import read from stdin per default
595 my $net = $target_sshinfo->{network
} // $target_sshinfo->{ip
};
596 $import_fn = "tcp://$net";
599 $with_snapshots = $with_snapshots ?
1 : 0; # sanitize for passing as cli parameter
600 my $send = ['pvesm', 'export', $volid, $format, '-', '-with-snapshots', $with_snapshots];
601 my $recv = [@$ssh, '--', 'pvesm', 'import', $volid, $format, $import_fn, '-with-snapshots', $with_snapshots];
602 if (defined($snapshot)) {
603 push @$send, '-snapshot', $snapshot
605 if ($migration_snapshot) {
606 push @$recv, '-delete-snapshot', $snapshot;
609 if (defined($base_snapshot)) {
610 # Check if the snapshot exists on the remote side:
611 push @$send, '-base', $base_snapshot;
612 push @$recv, '-base', $base_snapshot;
615 volume_snapshot
($cfg, $volid, $snapshot) if $migration_snapshot;
618 open(my $info, '-|', @$recv)
619 or die "receive command failed: $!\n";
620 my ($ip) = <$info> =~ /^($PVE::Tools::IPRE)$/ or die "no tunnel IP received\n";
621 my ($port) = <$info> =~ /^(\d+)$/ or die "no tunnel port received\n";
622 my $socket = IO
::Socket
::IP-
>new(PeerHost
=> $ip, PeerPort
=> $port, Type
=> SOCK_STREAM
)
623 or die "failed to connect to tunnel at $ip:$port\n";
624 # we won't be reading from the socket
625 shutdown($socket, 0);
626 run_command
([$send, @cstream], output
=> '>&'.fileno($socket));
627 # don't close the connection entirely otherwise the receiving end
628 # might not get all buffered data (and fails with 'connection reset by peer')
629 shutdown($socket, 1);
630 1 while <$info>; # wait for the remote process to finish
631 # now close the socket
633 if (!close($info)) { # does waitpid()
634 die "import failed: $!\n" if $!;
635 die "import failed: exit code ".($?>>8)."\n";
638 run_command
([$send, @cstream, $recv], logfunc
=> $logfunc);
642 warn "send/receive failed, cleaning up snapshot(s)..\n" if $err;
643 if ($migration_snapshot) {
644 eval { volume_snapshot_delete
($cfg, $volid, $snapshot, 0) };
645 warn "could not remove source snapshot: $@\n" if $@;
651 my ($cfg, $volid, $vmid, $snap) = @_;
653 my ($storeid, $volname) = parse_volume_id
($volid);
655 my $scfg = storage_config
($cfg, $storeid);
657 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
659 activate_storage
($cfg, $storeid);
661 # lock shared storage
662 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
663 my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid, $snap);
664 return "$storeid:$volname";
668 sub vdisk_create_base
{
669 my ($cfg, $volid) = @_;
671 my ($storeid, $volname) = parse_volume_id
($volid);
673 my $scfg = storage_config
($cfg, $storeid);
675 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
677 activate_storage
($cfg, $storeid);
679 # lock shared storage
680 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
681 my $volname = $plugin->create_base($storeid, $scfg, $volname);
682 return "$storeid:$volname";
687 my ($cfg, $volid, $snapname) = @_;
689 my ($storeid, $volname) = parse_volume_id
($volid);
691 my $scfg = storage_config
($cfg, $storeid);
693 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
695 return $plugin->map_volume($storeid, $scfg, $volname, $snapname);
699 my ($cfg, $volid, $snapname) = @_;
701 my ($storeid, $volname) = parse_volume_id
($volid);
703 my $scfg = storage_config
($cfg, $storeid);
705 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
707 return $plugin->unmap_volume($storeid, $scfg, $volname, $snapname);
711 my ($cfg, $storeid, $vmid, $fmt, $name, $size) = @_;
713 die "no storage ID specified\n" if !$storeid;
715 PVE
::JSONSchema
::parse_storage_id
($storeid);
717 my $scfg = storage_config
($cfg, $storeid);
719 die "no VMID specified\n" if !$vmid;
721 $vmid = parse_vmid
($vmid);
723 my $defformat = PVE
::Storage
::Plugin
::default_format
($scfg);
725 $fmt = $defformat if !$fmt;
727 activate_storage
($cfg, $storeid);
729 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
731 # lock shared storage
732 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
733 my $old_umask = umask(umask|0037);
734 my $volname = eval { $plugin->alloc_image($storeid, $scfg, $vmid, $fmt, $name, $size) };
738 return "$storeid:$volname";
743 my ($cfg, $volid) = @_;
745 my ($storeid, $volname) = parse_volume_id
($volid);
746 my $scfg = storage_config
($cfg, $storeid);
747 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
749 activate_storage
($cfg, $storeid);
753 # lock shared storage
754 $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
755 # LVM-thin allows deletion of still referenced base volumes!
756 die "base volume '$volname' is still in use by linked clones\n"
757 if &$volume_is_base_and_used__no_lock($scfg, $storeid, $plugin, $volname);
759 my (undef, undef, undef, undef, undef, $isBase, $format) =
760 $plugin->parse_volname($volname);
761 $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname, $isBase, $format);
764 return if !$cleanup_worker;
766 my $rpcenv = PVE
::RPCEnvironment
::get
();
767 my $authuser = $rpcenv->get_user();
769 $rpcenv->fork_worker('imgdel', undef, $authuser, $cleanup_worker);
773 my ($cfg, $storeid, $vmid, $vollist) = @_;
775 my $ids = $cfg->{ids
};
777 storage_check_enabled
($cfg, $storeid) if ($storeid);
781 # prepare/activate/refresh all storages
783 my $storage_list = [];
785 foreach my $volid (@$vollist) {
786 my ($sid, undef) = parse_volume_id
($volid);
787 next if !defined($ids->{$sid});
788 next if !storage_check_enabled
($cfg, $sid, undef, 1);
789 push @$storage_list, $sid;
792 foreach my $sid (keys %$ids) {
793 next if $storeid && $storeid ne $sid;
794 next if !storage_check_enabled
($cfg, $sid, undef, 1);
795 push @$storage_list, $sid;
801 activate_storage_list
($cfg, $storage_list, $cache);
803 foreach my $sid (keys %$ids) {
804 next if $storeid && $storeid ne $sid;
805 next if !storage_check_enabled
($cfg, $sid, undef, 1);
807 my $scfg = $ids->{$sid};
808 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
809 $res->{$sid} = $plugin->list_images($sid, $scfg, $vmid, $vollist, $cache);
810 @{$res->{$sid}} = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @{$res->{$sid}} if $res->{$sid};
817 my ($cfg, $storeid, $tt) = @_;
819 die "unknown template type '$tt'\n"
820 if !($tt eq 'iso' || $tt eq 'vztmpl' || $tt eq 'backup' || $tt eq 'snippets');
822 my $ids = $cfg->{ids
};
824 storage_check_enabled
($cfg, $storeid) if ($storeid);
829 foreach my $sid (keys %$ids) {
830 next if $storeid && $storeid ne $sid;
832 my $scfg = $ids->{$sid};
833 my $type = $scfg->{type
};
835 next if !$scfg->{content
}->{$tt};
837 next if !storage_check_enabled
($cfg, $sid, undef, 1);
839 $res->{$sid} = volume_list
($cfg, $sid, undef, $tt);
846 my ($cfg, $storeid, $vmid, $content) = @_;
848 my @ctypes = qw(images vztmpl iso backup snippets);
850 my $cts = $content ?
[ $content ] : [ @ctypes ];
852 my $scfg = PVE
::Storage
::storage_config
($cfg, $storeid);
854 $cts = [ grep { defined($scfg->{content
}->{$_}) } @$cts ];
856 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
858 activate_storage
($cfg, $storeid);
860 my $res = $plugin->list_volumes($storeid, $scfg, $vmid, $cts);
862 @$res = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @$res;
869 my $filename = "/sys/kernel/uevent_seqnum";
872 if (my $fh = IO
::File-
>new($filename, "r")) {
874 if ($line =~ m/^(\d+)$/) {
882 sub activate_storage
{
883 my ($cfg, $storeid, $cache) = @_;
885 $cache = {} if !$cache;
887 my $scfg = storage_check_enabled
($cfg, $storeid);
889 return if $cache->{activated
}->{$storeid};
891 $cache->{uevent_seqnum
} = uevent_seqnum
() if !$cache->{uevent_seqnum
};
893 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
896 my ($baseid, undef) = parse_volume_id
($scfg->{base
});
897 activate_storage
($cfg, $baseid, $cache);
900 if (!$plugin->check_connection($storeid, $scfg)) {
901 die "storage '$storeid' is not online\n";
904 $plugin->activate_storage($storeid, $scfg, $cache);
906 my $newseq = uevent_seqnum
();
908 # only call udevsettle if there are events
909 if ($newseq > $cache->{uevent_seqnum
}) {
911 system ("$UDEVADM settle --timeout=$timeout"); # ignore errors
912 $cache->{uevent_seqnum
} = $newseq;
915 $cache->{activated
}->{$storeid} = 1;
918 sub activate_storage_list
{
919 my ($cfg, $storeid_list, $cache) = @_;
921 $cache = {} if !$cache;
923 foreach my $storeid (@$storeid_list) {
924 activate_storage
($cfg, $storeid, $cache);
928 sub deactivate_storage
{
929 my ($cfg, $storeid) = @_;
931 my $scfg = storage_config
($cfg, $storeid);
932 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
935 $plugin->deactivate_storage($storeid, $scfg, $cache);
938 sub activate_volumes
{
939 my ($cfg, $vollist, $snapname) = @_;
941 return if !($vollist && scalar(@$vollist));
943 my $storagehash = {};
944 foreach my $volid (@$vollist) {
945 my ($storeid, undef) = parse_volume_id
($volid);
946 $storagehash->{$storeid} = 1;
951 activate_storage_list
($cfg, [keys %$storagehash], $cache);
953 foreach my $volid (@$vollist) {
954 my ($storeid, $volname) = parse_volume_id
($volid);
955 my $scfg = storage_config
($cfg, $storeid);
956 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
957 $plugin->activate_volume($storeid, $scfg, $volname, $snapname, $cache);
961 sub deactivate_volumes
{
962 my ($cfg, $vollist, $snapname) = @_;
964 return if !($vollist && scalar(@$vollist));
969 foreach my $volid (@$vollist) {
970 my ($storeid, $volname) = parse_volume_id
($volid);
972 my $scfg = storage_config
($cfg, $storeid);
973 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
976 $plugin->deactivate_volume($storeid, $scfg, $volname, $snapname, $cache);
980 push @errlist, $volid;
984 die "volume deactivation failed: " . join(' ', @errlist)
989 my ($cfg, $content, $includeformat) = @_;
991 my $ids = $cfg->{ids
};
995 my @ctypes = PVE
::Tools
::split_list
($content);
998 foreach my $storeid (keys %$ids) {
999 my $storage_enabled = defined(storage_check_enabled
($cfg, $storeid, undef, 1));
1001 if (defined($content)) {
1003 foreach my $ctype (@ctypes) {
1004 if ($ids->{$storeid}->{content
}->{$ctype}) {
1009 next if !$want_ctype || !$storage_enabled;
1012 my $type = $ids->{$storeid}->{type
};
1014 $info->{$storeid} = {
1019 shared
=> $ids->{$storeid}->{shared
} ?
1 : 0,
1020 content
=> PVE
::Storage
::Plugin
::content_hash_to_string
($ids->{$storeid}->{content
}),
1022 enabled
=> $storage_enabled ?
1 : 0,
1025 push @$slist, $storeid;
1030 foreach my $storeid (keys %$ids) {
1031 my $scfg = $ids->{$storeid};
1033 next if !$info->{$storeid};
1034 next if !$info->{$storeid}->{enabled
};
1036 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1037 if ($includeformat) {
1038 my $pd = $plugin->plugindata();
1039 $info->{$storeid}->{format
} = $pd->{format
}
1041 $info->{$storeid}->{select_existing
} = $pd->{select_existing
}
1042 if $pd->{select_existing
};
1045 eval { activate_storage
($cfg, $storeid, $cache); };
1051 my ($total, $avail, $used, $active) = eval { $plugin->status($storeid, $scfg, $cache); };
1054 $info->{$storeid}->{total
} = int($total);
1055 $info->{$storeid}->{avail
} = int($avail);
1056 $info->{$storeid}->{used
} = int($used);
1057 $info->{$storeid}->{active
} = $active;
1066 my ($packed_ip, $family);
1068 my @res = PVE
::Tools
::getaddrinfo_all
($server);
1069 $family = $res[0]->{family
};
1070 $packed_ip = (PVE
::Tools
::unpack_sockaddr_in46
($res[0]->{addr
}))[2];
1072 if (defined $packed_ip) {
1073 return Socket
::inet_ntop
($family, $packed_ip);
1079 my ($server_in) = @_;
1082 if (!($server = resolv_server
($server_in))) {
1083 die "unable to resolve address for server '${server_in}'\n";
1086 my $cmd = ['/sbin/showmount', '--no-headers', '--exports', $server];
1089 run_command
($cmd, outfunc
=> sub {
1092 # note: howto handle white spaces in export path??
1093 if ($line =~ m!^(/\S+)\s+(.+)$!) {
1102 my ($server_in, $user, $password, $domain) = @_;
1105 if (!($server = resolv_server
($server_in))) {
1106 die "unable to resolve address for server '${server_in}'\n";
1109 # we support only Windows grater than 2012 cifsscan so use smb3
1110 my $cmd = ['/usr/bin/smbclient', '-m', 'smb3', '-d', '0', '-L', $server];
1111 if (defined($user)) {
1112 die "password is required" if !defined($password);
1113 push @$cmd, '-U', "$user\%$password";
1114 push @$cmd, '-W', $domain if defined($domain);
1123 if ($line =~ m/(\S+)\s*Disk\s*(\S*)/) {
1125 } elsif ($line =~ m/(NT_STATUS_(\S*))/) {
1138 my $cmd = ['zfs', 'list', '-t', 'filesystem', '-H', '-o', 'name,avail,used'];
1141 run_command
($cmd, outfunc
=> sub {
1144 if ($line =~m/^(\S+)\s+(\S+)\s+(\S+)$/) {
1145 my ($pool, $size_str, $used_str) = ($1, $2, $3);
1146 my $size = PVE
::Storage
::ZFSPoolPlugin
::zfs_parse_size
($size_str);
1147 my $used = PVE
::Storage
::ZFSPoolPlugin
::zfs_parse_size
($used_str);
1148 # ignore subvolumes generated by our ZFSPoolPlugin
1149 return if $pool =~ m!/subvol-\d+-[^/]+$!;
1150 return if $pool =~ m!/basevol-\d+-[^/]+$!;
1151 push @$res, { pool
=> $pool, size
=> $size, free
=> $size-$used };
1159 my ($portal, $noerr) = @_;
1161 my ($server, $port) = PVE
::Tools
::parse_host_and_port
($portal);
1163 if (my $ip = resolv_server
($server)) {
1165 $server = "[$server]" if $server =~ /^$IPV6RE$/;
1166 return $port ?
"$server:$port" : $server;
1169 return undef if $noerr;
1171 raise_param_exc
({ portal
=> "unable to resolve portal address '$portal'" });
1176 my ($portal_in) = @_;
1179 if (!($portal = resolv_portal
($portal_in))) {
1180 die "unable to parse/resolve portal address '${portal_in}'\n";
1183 return PVE
::Storage
::ISCSIPlugin
::iscsi_discovery
($portal);
1186 sub storage_default_format
{
1187 my ($cfg, $storeid) = @_;
1189 my $scfg = storage_config
($cfg, $storeid);
1191 return PVE
::Storage
::Plugin
::default_format
($scfg);
1194 sub vgroup_is_used
{
1195 my ($cfg, $vgname) = @_;
1197 foreach my $storeid (keys %{$cfg->{ids
}}) {
1198 my $scfg = storage_config
($cfg, $storeid);
1199 if ($scfg->{type
} eq 'lvm' && $scfg->{vgname
} eq $vgname) {
1207 sub target_is_used
{
1208 my ($cfg, $target) = @_;
1210 foreach my $storeid (keys %{$cfg->{ids
}}) {
1211 my $scfg = storage_config
($cfg, $storeid);
1212 if ($scfg->{type
} eq 'iscsi' && $scfg->{target
} eq $target) {
1220 sub volume_is_used
{
1221 my ($cfg, $volid) = @_;
1223 foreach my $storeid (keys %{$cfg->{ids
}}) {
1224 my $scfg = storage_config
($cfg, $storeid);
1225 if ($scfg->{base
} && $scfg->{base
} eq $volid) {
1233 sub storage_is_used
{
1234 my ($cfg, $storeid) = @_;
1236 foreach my $sid (keys %{$cfg->{ids
}}) {
1237 my $scfg = storage_config
($cfg, $sid);
1238 next if !$scfg->{base
};
1239 my ($st) = parse_volume_id
($scfg->{base
});
1240 return 1 if $st && $st eq $storeid;
1247 my ($list, $func) = @_;
1251 foreach my $sid (keys %$list) {
1252 foreach my $info (@{$list->{$sid}}) {
1253 my $volid = $info->{volid
};
1254 my ($sid1, $volname) = parse_volume_id
($volid, 1);
1255 if ($sid1 && $sid1 eq $sid) {
1256 &$func ($volid, $sid, $info);
1258 warn "detected strange volid '$volid' in volume list for '$sid'\n";
1264 sub extract_vzdump_config_tar
{
1265 my ($archive, $conf_re) = @_;
1267 die "ERROR: file '$archive' does not exist\n" if ! -f
$archive;
1269 my $pid = open(my $fh, '-|', 'tar', 'tf', $archive) ||
1270 die "unable to open file '$archive'\n";
1273 while (defined($file = <$fh>)) {
1274 if ($file =~ $conf_re) {
1275 $file = $1; # untaint
1284 die "ERROR: archive contains no configuration file\n" if !$file;
1290 $raw .= "$output\n";
1293 PVE
::Tools
::run_command
(['tar', '-xpOf', $archive, $file, '--occurrence'], outfunc
=> $out);
1295 return wantarray ?
($raw, $file) : $raw;
1298 sub extract_vzdump_config_vma
{
1299 my ($archive, $comp) = @_;
1305 $raw .= "$output\n";
1311 if ($comp eq 'gz') {
1312 $uncomp = ["zcat", $archive];
1313 } elsif ($comp eq 'lzo') {
1314 $uncomp = ["lzop", "-d", "-c", $archive];
1316 die "unknown compression method '$comp'\n";
1318 $cmd = [$uncomp, ["vma", "config", "-"]];
1320 # in some cases, lzop/zcat exits with 1 when its stdout pipe is
1321 # closed early by vma, detect this and ignore the exit code later
1326 if ($output =~ m/lzop: Broken pipe: <stdout>/ || $output =~ m/gzip: stdout: Broken pipe/) {
1328 } elsif (!defined ($errstring) && $output !~ m/^\s*$/) {
1329 $errstring = "Failed to extract config from VMA archive: $output\n";
1333 # in other cases, the pipeline will exit with exit code 141
1334 # because of the broken pipe, handle / ignore this as well
1337 $rc = PVE
::Tools
::run_command
($cmd, outfunc
=> $out, errfunc
=> $err, noerr
=> 1);
1341 # use exit code if no stderr output and not just broken pipe
1342 if (!$errstring && !$broken_pipe && $rc != 0 && $rc != 141) {
1343 die "$rerr\n" if $rerr;
1344 die "config extraction failed with exit code $rc\n";
1346 die "$errstring\n" if $errstring;
1348 # simple case without compression and weird piping behaviour
1349 PVE
::Tools
::run_command
(["vma", "config", $archive], outfunc
=> $out);
1352 return wantarray ?
($raw, undef) : $raw;
1355 sub extract_vzdump_config
{
1356 my ($cfg, $volid) = @_;
1358 my $archive = abs_filesystem_path
($cfg, $volid);
1360 if ($volid =~ /vzdump-(lxc|openvz)-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?))$/) {
1361 return extract_vzdump_config_tar
($archive, qr!^(\./etc/vzdump/(pct|vps)\.conf)$!);
1362 } elsif ($volid =~ /vzdump-qemu-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(gz|lzo))?))$/) {
1370 $comp = $11 if defined($11);
1373 if ($format eq 'tar') {
1374 return extract_vzdump_config_tar
($archive, qr!\(\./qemu-server\.conf\)!);
1376 return extract_vzdump_config_vma
($archive, $comp);
1379 die "cannot determine backup guest type for backup archive '$volid'\n";
1384 my ($cfg, $fh, $volid, $format, $snapshot, $base_snapshot, $with_snapshots) = @_;
1386 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1387 die "cannot export volume '$volid'\n" if !$storeid;
1388 my $scfg = storage_config
($cfg, $storeid);
1389 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1390 return $plugin->volume_export($scfg, $storeid, $fh, $volname, $format,
1391 $snapshot, $base_snapshot, $with_snapshots);
1395 my ($cfg, $fh, $volid, $format, $base_snapshot, $with_snapshots) = @_;
1397 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1398 die "cannot import into volume '$volid'\n" if !$storeid;
1399 my $scfg = storage_config
($cfg, $storeid);
1400 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1401 return $plugin->volume_import($scfg, $storeid, $fh, $volname, $format,
1402 $base_snapshot, $with_snapshots);
1405 sub volume_export_formats
{
1406 my ($cfg, $volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
1408 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1409 return if !$storeid;
1410 my $scfg = storage_config
($cfg, $storeid);
1411 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1412 return $plugin->volume_export_formats($scfg, $storeid, $volname,
1413 $snapshot, $base_snapshot,
1417 sub volume_import_formats
{
1418 my ($cfg, $volid, $base_snapshot, $with_snapshots) = @_;
1420 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1421 return if !$storeid;
1422 my $scfg = storage_config
($cfg, $storeid);
1423 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1424 return $plugin->volume_import_formats($scfg, $storeid, $volname,
1425 $base_snapshot, $with_snapshots);
1428 sub volume_transfer_formats
{
1429 my ($cfg, $src_volid, $dst_volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
1430 my @export_formats = volume_export_formats
($cfg, $src_volid, $snapshot, $base_snapshot, $with_snapshots);
1431 my @import_formats = volume_import_formats
($cfg, $dst_volid, $base_snapshot, $with_snapshots);
1432 my %import_hash = map { $_ => 1 } @import_formats;
1433 my @common = grep { $import_hash{$_} } @export_formats;
1437 # bash completion helper
1439 sub complete_storage
{
1440 my ($cmdname, $pname, $cvalue) = @_;
1442 my $cfg = PVE
::Storage
::config
();
1444 return $cmdname eq 'add' ?
[] : [ PVE
::Storage
::storage_ids
($cfg) ];
1447 sub complete_storage_enabled
{
1448 my ($cmdname, $pname, $cvalue) = @_;
1452 my $cfg = PVE
::Storage
::config
();
1453 foreach my $sid (keys %{$cfg->{ids
}}) {
1454 next if !storage_check_enabled
($cfg, $sid, undef, 1);
1460 sub complete_content_type
{
1461 my ($cmdname, $pname, $cvalue) = @_;
1463 return [qw(rootdir images vztmpl iso backup snippets)];
1466 sub complete_volume
{
1467 my ($cmdname, $pname, $cvalue) = @_;
1471 my $storage_list = complete_storage_enabled
();
1473 if ($cvalue =~ m/^([^:]+):/) {
1474 $storage_list = [ $1 ];
1476 if (scalar(@$storage_list) > 1) {
1477 # only list storage IDs to avoid large listings
1479 foreach my $storeid (@$storage_list) {
1480 # Hack: simply return 2 artificial values, so that
1481 # completions does not finish
1482 push @$res, "$storeid:volname", "$storeid:...";
1489 foreach my $storeid (@$storage_list) {
1490 my $vollist = PVE
::Storage
::volume_list
($cfg, $storeid);
1492 foreach my $item (@$vollist) {
1493 push @$res, $item->{volid
};
1500 # Various io-heavy operations require io/bandwidth limits which can be
1501 # configured on multiple levels: The global defaults in datacenter.cfg, and
1502 # per-storage overrides. When we want to do a restore from storage A to storage
1503 # B, we should take the smaller limit defined for storages A and B, and if no
1504 # such limit was specified, use the one from datacenter.cfg.
1505 sub get_bandwidth_limit
{
1506 my ($operation, $storage_list, $override) = @_;
1508 # called for each limit (global, per-storage) with the 'default' and the
1509 # $operation limit and should udpate $override for every limit affecting
1511 my $use_global_limits = 0;
1512 my $apply_limit = sub {
1514 if (defined($bwlimit)) {
1515 my $limits = PVE
::JSONSchema
::parse_property_string
('bwlimit', $bwlimit);
1516 my $limit = $limits->{$operation} // $limits->{default};
1517 if (defined($limit)) {
1518 if (!$override || $limit < $override) {
1524 # If there was no applicable limit, try to apply the global ones.
1525 $use_global_limits = 1;
1528 my ($rpcenv, $authuser);
1529 if (defined($override)) {
1530 $rpcenv = PVE
::RPCEnvironment-
>get();
1531 $authuser = $rpcenv->get_user();
1534 # Apply per-storage limits - if there are storages involved.
1535 if (defined($storage_list) && @$storage_list) {
1536 my $config = config
();
1538 # The Datastore.Allocate permission allows us to modify the per-storage
1539 # limits, therefore it also allows us to override them.
1540 # Since we have most likely multiple storages to check, do a quick check on
1541 # the general '/storage' path to see if we can skip the checks entirely:
1542 return $override if $rpcenv && $rpcenv->check($authuser, '/storage', ['Datastore.Allocate'], 1);
1545 foreach my $storage (@$storage_list) {
1546 next if !defined($storage);
1547 # Avoid duplicate checks:
1548 next if $done{$storage};
1549 $done{$storage} = 1;
1551 # Otherwise we may still have individual /storage/$ID permissions:
1552 if (!$rpcenv || !$rpcenv->check($authuser, "/storage/$storage", ['Datastore.Allocate'], 1)) {
1553 # And if not: apply the limits.
1554 my $storecfg = storage_config
($config, $storage);
1555 $apply_limit->($storecfg->{bwlimit
});
1559 # Storage limits take precedence over the datacenter defaults, so if
1560 # a limit was applied:
1561 return $override if !$use_global_limits;
1564 # Sys.Modify on '/' means we can change datacenter.cfg which contains the
1565 # global default limits.
1566 if (!$rpcenv || !$rpcenv->check($authuser, '/', ['Sys.Modify'], 1)) {
1567 # So if we cannot modify global limits, apply them to our currently
1568 # requested override.
1569 my $dc = cfs_read_file
('datacenter.cfg');
1570 $apply_limit->($dc->{bwlimit
});
1576 # checks if the storage id is available and dies if not
1577 sub assert_sid_unused
{
1581 if (my $scfg = storage_config
($cfg, $sid, 1)) {
1582 die "storage ID '$sid' already defined\n";