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
::DataCenterConfig
;
19 use PVE
::Exception
qw(raise_param_exc);
22 use PVE
::RPCEnvironment
;
24 use PVE
::Storage
::Plugin
;
25 use PVE
::Storage
::DirPlugin
;
26 use PVE
::Storage
::LVMPlugin
;
27 use PVE
::Storage
::LvmThinPlugin
;
28 use PVE
::Storage
::NFSPlugin
;
29 use PVE
::Storage
::CIFSPlugin
;
30 use PVE
::Storage
::ISCSIPlugin
;
31 use PVE
::Storage
::RBDPlugin
;
32 use PVE
::Storage
::CephFSPlugin
;
33 use PVE
::Storage
::ISCSIDirectPlugin
;
34 use PVE
::Storage
::GlusterfsPlugin
;
35 use PVE
::Storage
::ZFSPoolPlugin
;
36 use PVE
::Storage
::ZFSPlugin
;
37 use PVE
::Storage
::DRBDPlugin
;
39 # Storage API version. Icrement it on changes in storage API interface.
40 use constant APIVER
=> 3;
41 # Age is the number of versions we're backward compatible with.
42 # This is like having 'current=APIVER' and age='APIAGE' in libtool,
43 # see https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
44 use constant APIAGE
=> 2;
46 # load standard plugins
47 PVE
::Storage
::DirPlugin-
>register();
48 PVE
::Storage
::LVMPlugin-
>register();
49 PVE
::Storage
::LvmThinPlugin-
>register();
50 PVE
::Storage
::NFSPlugin-
>register();
51 PVE
::Storage
::CIFSPlugin-
>register();
52 PVE
::Storage
::ISCSIPlugin-
>register();
53 PVE
::Storage
::RBDPlugin-
>register();
54 PVE
::Storage
::CephFSPlugin-
>register();
55 PVE
::Storage
::ISCSIDirectPlugin-
>register();
56 PVE
::Storage
::GlusterfsPlugin-
>register();
57 PVE
::Storage
::ZFSPoolPlugin-
>register();
58 PVE
::Storage
::ZFSPlugin-
>register();
59 PVE
::Storage
::DRBDPlugin-
>register();
61 # load third-party plugins
62 if ( -d
'/usr/share/perl5/PVE/Storage/Custom' ) {
63 dir_glob_foreach
('/usr/share/perl5/PVE/Storage/Custom', '.*\.pm$', sub {
65 my $modname = 'PVE::Storage::Custom::' . $file;
66 $modname =~ s!\.pm$!!;
67 $file = 'PVE/Storage/Custom/' . $file;
72 # Check perl interface:
73 die "not derived from PVE::Storage::Plugin\n"
74 if !$modname->isa('PVE::Storage::Plugin');
75 die "does not provide an api() method\n"
76 if !$modname->can('api');
77 # Check storage API version and that file is really storage plugin.
78 my $version = $modname->api();
79 die "implements an API version newer than current ($version > " . APIVER
. ")\n"
81 my $min_version = (APIVER
- APIAGE
);
82 die "API version too old, please update the plugin ($version < $min_version)\n"
83 if $version < $min_version;
87 # If we got this far and the API version is not the same, make some
89 warn "Plugin \"$modname\" is implementing an older storage API
, an upgrade
is recommended
\n"
90 if $version != APIVER;
93 warn "Error loading storage plugin
\"$modname\": $@";
98 # initialize all plugins
99 PVE
::Storage
::Plugin-
>init();
101 my $UDEVADM = '/sbin/udevadm';
103 our $iso_extension_re = qr/\.(?:iso|img)/i;
105 # PVE::Storage utility functions
108 return cfs_read_file
("storage.cfg");
114 cfs_write_file
('storage.cfg', $cfg);
117 sub lock_storage_config
{
118 my ($code, $errmsg) = @_;
120 cfs_lock_file
("storage.cfg", undef, $code);
123 $errmsg ?
die "$errmsg: $err" : die $err;
128 my ($cfg, $storeid, $noerr) = @_;
130 die "no storage ID specified\n" if !$storeid;
132 my $scfg = $cfg->{ids
}->{$storeid};
134 die "storage '$storeid' does not exists\n" if (!$noerr && !$scfg);
139 sub storage_check_node
{
140 my ($cfg, $storeid, $node, $noerr) = @_;
142 my $scfg = storage_config
($cfg, $storeid);
144 if ($scfg->{nodes
}) {
145 $node = PVE
::INotify
::nodename
() if !$node || ($node eq 'localhost');
146 if (!$scfg->{nodes
}->{$node}) {
147 die "storage '$storeid' is not available on node '$node'\n" if !$noerr;
155 sub storage_check_enabled
{
156 my ($cfg, $storeid, $node, $noerr) = @_;
158 my $scfg = storage_config
($cfg, $storeid);
160 if ($scfg->{disable
}) {
161 die "storage '$storeid' is disabled\n" if !$noerr;
165 return storage_check_node
($cfg, $storeid, $node, $noerr);
168 # storage_can_replicate:
169 # return true if storage supports replication
170 # (volumes alocated with vdisk_alloc() has replication feature)
171 sub storage_can_replicate
{
172 my ($cfg, $storeid, $format) = @_;
174 my $scfg = storage_config
($cfg, $storeid);
175 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
176 return $plugin->storage_can_replicate($scfg, $storeid, $format);
182 return keys %{$cfg->{ids
}};
186 my ($filename, $timeout) = @_;
188 return PVE
::Storage
::Plugin
::file_size_info
($filename, $timeout);
191 sub volume_size_info
{
192 my ($cfg, $volid, $timeout) = @_;
194 my ($storeid, $volname) = parse_volume_id
($volid, 1);
196 my $scfg = storage_config
($cfg, $storeid);
197 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
198 return $plugin->volume_size_info($scfg, $storeid, $volname, $timeout);
199 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
200 return file_size_info
($volid, $timeout);
207 my ($cfg, $volid, $size, $running) = @_;
209 my ($storeid, $volname) = parse_volume_id
($volid, 1);
211 my $scfg = storage_config
($cfg, $storeid);
212 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
213 return $plugin->volume_resize($scfg, $storeid, $volname, $size, $running);
214 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
215 die "resize file/device '$volid' is not possible\n";
217 die "unable to parse volume ID '$volid'\n";
221 sub volume_rollback_is_possible
{
222 my ($cfg, $volid, $snap) = @_;
224 my ($storeid, $volname) = parse_volume_id
($volid, 1);
226 my $scfg = storage_config
($cfg, $storeid);
227 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
228 return $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
229 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
230 die "snapshot rollback file/device '$volid' is not possible\n";
232 die "unable to parse volume ID '$volid'\n";
236 sub volume_snapshot
{
237 my ($cfg, $volid, $snap) = @_;
239 my ($storeid, $volname) = parse_volume_id
($volid, 1);
241 my $scfg = storage_config
($cfg, $storeid);
242 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
243 return $plugin->volume_snapshot($scfg, $storeid, $volname, $snap);
244 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
245 die "snapshot file/device '$volid' is not possible\n";
247 die "unable to parse volume ID '$volid'\n";
251 sub volume_snapshot_rollback
{
252 my ($cfg, $volid, $snap) = @_;
254 my ($storeid, $volname) = parse_volume_id
($volid, 1);
256 my $scfg = storage_config
($cfg, $storeid);
257 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
258 $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
259 return $plugin->volume_snapshot_rollback($scfg, $storeid, $volname, $snap);
260 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
261 die "snapshot rollback file/device '$volid' is not possible\n";
263 die "unable to parse volume ID '$volid'\n";
267 sub volume_snapshot_delete
{
268 my ($cfg, $volid, $snap, $running) = @_;
270 my ($storeid, $volname) = parse_volume_id
($volid, 1);
272 my $scfg = storage_config
($cfg, $storeid);
273 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
274 return $plugin->volume_snapshot_delete($scfg, $storeid, $volname, $snap, $running);
275 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
276 die "snapshot delete file/device '$volid' is not possible\n";
278 die "unable to parse volume ID '$volid'\n";
282 sub volume_has_feature
{
283 my ($cfg, $feature, $volid, $snap, $running) = @_;
285 my ($storeid, $volname) = parse_volume_id
($volid, 1);
287 my $scfg = storage_config
($cfg, $storeid);
288 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
289 return $plugin->volume_has_feature($scfg, $feature, $storeid, $volname, $snap, $running);
290 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
297 sub volume_snapshot_list
{
298 my ($cfg, $volid) = @_;
300 my ($storeid, $volname) = parse_volume_id
($volid, 1);
302 my $scfg = storage_config
($cfg, $storeid);
303 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
304 return $plugin->volume_snapshot_list($scfg, $storeid, $volname);
305 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
306 die "send file/device '$volid' is not possible\n";
308 die "unable to parse volume ID '$volid'\n";
310 # return an empty array if dataset does not exist.
314 my ($cfg, $storeid, $vmid) = @_;
316 my $scfg = storage_config
($cfg, $storeid);
317 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
319 my $path = $plugin->get_subdir($scfg, 'images');
321 return $vmid ?
"$path/$vmid" : $path;
324 sub get_private_dir
{
325 my ($cfg, $storeid, $vmid) = @_;
327 my $scfg = storage_config
($cfg, $storeid);
328 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
330 my $path = $plugin->get_subdir($scfg, 'rootdir');
332 return $vmid ?
"$path/$vmid" : $path;
336 my ($cfg, $storeid) = @_;
338 my $scfg = storage_config
($cfg, $storeid);
339 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
341 return $plugin->get_subdir($scfg, 'iso');
345 my ($cfg, $storeid) = @_;
347 my $scfg = storage_config
($cfg, $storeid);
348 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
350 return $plugin->get_subdir($scfg, 'vztmpl');
354 my ($cfg, $storeid) = @_;
356 my $scfg = storage_config
($cfg, $storeid);
357 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
359 return $plugin->get_subdir($scfg, 'backup');
362 # library implementation
367 die "VMID '$vmid' contains illegal characters\n" if $vmid !~ m/^\d+$/;
372 # NOTE: basename and basevmid are always undef for LVM-thin, where the
373 # clone -> base reference is not encoded in the volume ID.
374 # see note in PVE::Storage::LvmThinPlugin for details.
376 my ($cfg, $volid) = @_;
378 my ($storeid, $volname) = parse_volume_id
($volid);
380 my $scfg = storage_config
($cfg, $storeid);
382 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
384 # returns ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format)
386 return $plugin->parse_volname($volname);
389 sub parse_volume_id
{
390 my ($volid, $noerr) = @_;
392 return PVE
::Storage
::Plugin
::parse_volume_id
($volid, $noerr);
395 # test if we have read access to volid
396 sub check_volume_access
{
397 my ($rpcenv, $user, $cfg, $vmid, $volid) = @_;
399 my ($sid, $volname) = parse_volume_id
($volid, 1);
401 my ($vtype, undef, $ownervm) = parse_volname
($cfg, $volid);
402 if ($vtype eq 'iso' || $vtype eq 'vztmpl') {
403 # require at least read access to storage, (custom) templates/ISOs could be sensitive
404 $rpcenv->check_any($user, "/storage/$sid", ['Datastore.AllocateSpace', 'Datastore.Audit']);
405 } elsif (defined($ownervm) && defined($vmid) && ($ownervm == $vmid)) {
406 # we are owner - allow access
407 } elsif ($vtype eq 'backup' && $ownervm) {
408 $rpcenv->check($user, "/storage/$sid", ['Datastore.AllocateSpace']);
409 $rpcenv->check($user, "/vms/$ownervm", ['VM.Backup']);
411 # allow if we are Datastore administrator
412 $rpcenv->check($user, "/storage/$sid", ['Datastore.Allocate']);
415 die "Only root can pass arbitrary filesystem paths."
416 if $user ne 'root@pam';
422 my $volume_is_base_and_used__no_lock = sub {
423 my ($scfg, $storeid, $plugin, $volname) = @_;
425 my ($vtype, $name, $vmid, undef, undef, $isBase, undef) =
426 $plugin->parse_volname($volname);
429 my $vollist = $plugin->list_images($storeid, $scfg);
430 foreach my $info (@$vollist) {
431 my (undef, $tmpvolname) = parse_volume_id
($info->{volid
});
432 my $basename = undef;
433 my $basevmid = undef;
436 (undef, undef, undef, $basename, $basevmid) =
437 $plugin->parse_volname($tmpvolname);
440 if ($basename && defined($basevmid) && $basevmid == $vmid && $basename eq $name) {
448 # NOTE: this check does not work for LVM-thin, where the clone -> base
449 # reference is not encoded in the volume ID.
450 # see note in PVE::Storage::LvmThinPlugin for details.
451 sub volume_is_base_and_used
{
452 my ($cfg, $volid) = @_;
454 my ($storeid, $volname) = parse_volume_id
($volid);
455 my $scfg = storage_config
($cfg, $storeid);
456 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
458 $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
459 return &$volume_is_base_and_used__no_lock($scfg, $storeid, $plugin, $volname);
463 # try to map a filesystem path to a volume identifier
464 sub path_to_volume_id
{
465 my ($cfg, $path) = @_;
467 my $ids = $cfg->{ids
};
469 my ($sid, $volname) = parse_volume_id
($path, 1);
471 if (my $scfg = $ids->{$sid}) {
473 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
474 my ($vtype, $name, $vmid) = $plugin->parse_volname($volname);
475 return ($vtype, $path);
481 # Note: abs_path() return undef if $path doesn not exist
482 # for example when nfs storage is not mounted
483 $path = abs_path
($path) || $path;
485 foreach my $sid (keys %$ids) {
486 my $scfg = $ids->{$sid};
487 next if !$scfg->{path
};
488 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
489 my $imagedir = $plugin->get_subdir($scfg, 'images');
490 my $isodir = $plugin->get_subdir($scfg, 'iso');
491 my $tmpldir = $plugin->get_subdir($scfg, 'vztmpl');
492 my $backupdir = $plugin->get_subdir($scfg, 'backup');
493 my $privatedir = $plugin->get_subdir($scfg, 'rootdir');
495 if ($path =~ m!^$imagedir/(\d+)/([^/\s]+)$!) {
499 my $vollist = $plugin->list_images($sid, $scfg, $vmid);
500 foreach my $info (@$vollist) {
501 my ($storeid, $volname) = parse_volume_id
($info->{volid
});
502 my $volpath = $plugin->path($scfg, $volname, $storeid);
503 if ($volpath eq $path) {
504 return ('images', $info->{volid
});
507 } elsif ($path =~ m!^$isodir/([^/]+$iso_extension_re)$!) {
509 return ('iso', "$sid:iso/$name");
510 } elsif ($path =~ m!^$tmpldir/([^/]+\.tar\.gz)$!) {
512 return ('vztmpl', "$sid:vztmpl/$name");
513 } elsif ($path =~ m!^$privatedir/(\d+)$!) {
515 return ('rootdir', "$sid:rootdir/$vmid");
516 } elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!) {
518 return ('iso', "$sid:backup/$name");
522 # can't map path to volume id
527 my ($cfg, $volid, $snapname) = @_;
529 my ($storeid, $volname) = parse_volume_id
($volid);
531 my $scfg = storage_config
($cfg, $storeid);
533 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
534 my ($path, $owner, $vtype) = $plugin->path($scfg, $volname, $storeid, $snapname);
535 return wantarray ?
($path, $owner, $vtype) : $path;
538 sub abs_filesystem_path
{
539 my ($cfg, $volid) = @_;
542 if (parse_volume_id
($volid, 1)) {
543 activate_volumes
($cfg, [ $volid ]);
544 $path = PVE
::Storage
::path
($cfg, $volid);
547 my $abspath = abs_path
($volid);
548 if ($abspath && $abspath =~ m
|^(/.+)$|) {
549 $path = $1; # untaint any path
554 die "can't find file '$volid'\n" if !($path && -f
$path);
559 sub storage_migrate
{
560 my ($cfg, $volid, $target_sshinfo, $target_storeid, $target_volname, $base_snapshot, $snapshot, $ratelimit_bps, $insecure, $with_snapshots, $logfunc) = @_;
562 my ($storeid, $volname) = parse_volume_id
($volid);
563 $target_volname = $volname if !$target_volname;
565 my $scfg = storage_config
($cfg, $storeid);
567 # no need to migrate shared content
568 return if $storeid eq $target_storeid && $scfg->{shared
};
570 my $tcfg = storage_config
($cfg, $target_storeid);
572 my $target_volid = "${target_storeid}:${target_volname}";
574 my $target_ip = $target_sshinfo->{ip
};
575 my $errstr = "unable to migrate '$volid' to '${target_volid}' on host '$target_sshinfo->{name}'";
577 my $ssh = PVE
::Cluster
::ssh_info_to_command
($target_sshinfo);
578 my $ssh_base = PVE
::Cluster
::ssh_info_to_command_base
($target_sshinfo);
579 local $ENV{RSYNC_RSH
} = PVE
::Tools
::cmd2string
($ssh_base);
581 my @cstream = ([ '/usr/bin/cstream', '-t', $ratelimit_bps ])
582 if defined($ratelimit_bps);
584 my $migration_snapshot;
585 if (!defined($snapshot)) {
586 if ($scfg->{type
} eq 'zfspool') {
587 $migration_snapshot = 1;
588 $snapshot = '__migration__';
592 my @formats = volume_transfer_formats
($cfg, $volid, $target_volid, $snapshot, $base_snapshot, $with_snapshots);
593 die "cannot migrate from storage type '$scfg->{type}' to '$tcfg->{type}'\n" if !@formats;
594 my $format = $formats[0];
596 my $import_fn = '-'; # let pvesm import read from stdin per default
598 my $net = $target_sshinfo->{network
} // $target_sshinfo->{ip
};
599 $import_fn = "tcp://$net";
602 $with_snapshots = $with_snapshots ?
1 : 0; # sanitize for passing as cli parameter
603 my $send = ['pvesm', 'export', $volid, $format, '-', '-with-snapshots', $with_snapshots];
604 my $recv = [@$ssh, '--', 'pvesm', 'import', $target_volid, $format, $import_fn, '-with-snapshots', $with_snapshots];
605 if (defined($snapshot)) {
606 push @$send, '-snapshot', $snapshot
608 if ($migration_snapshot) {
609 push @$recv, '-delete-snapshot', $snapshot;
612 if (defined($base_snapshot)) {
613 # Check if the snapshot exists on the remote side:
614 push @$send, '-base', $base_snapshot;
615 push @$recv, '-base', $base_snapshot;
618 volume_snapshot
($cfg, $volid, $snapshot) if $migration_snapshot;
621 open(my $info, '-|', @$recv)
622 or die "receive command failed: $!\n";
623 my ($ip) = <$info> =~ /^($PVE::Tools::IPRE)$/ or die "no tunnel IP received\n";
624 my ($port) = <$info> =~ /^(\d+)$/ or die "no tunnel port received\n";
625 my $socket = IO
::Socket
::IP-
>new(PeerHost
=> $ip, PeerPort
=> $port, Type
=> SOCK_STREAM
)
626 or die "failed to connect to tunnel at $ip:$port\n";
627 # we won't be reading from the socket
628 shutdown($socket, 0);
629 run_command
([$send, @cstream], output
=> '>&'.fileno($socket));
630 # don't close the connection entirely otherwise the receiving end
631 # might not get all buffered data (and fails with 'connection reset by peer')
632 shutdown($socket, 1);
633 1 while <$info>; # wait for the remote process to finish
634 # now close the socket
636 if (!close($info)) { # does waitpid()
637 die "import failed: $!\n" if $!;
638 die "import failed: exit code ".($?>>8)."\n";
641 run_command
([$send, @cstream, $recv], logfunc
=> $logfunc);
645 warn "send/receive failed, cleaning up snapshot(s)..\n" if $err;
646 if ($migration_snapshot) {
647 eval { volume_snapshot_delete
($cfg, $volid, $snapshot, 0) };
648 warn "could not remove source snapshot: $@\n" if $@;
654 my ($cfg, $volid, $vmid, $snap) = @_;
656 my ($storeid, $volname) = parse_volume_id
($volid);
658 my $scfg = storage_config
($cfg, $storeid);
660 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
662 activate_storage
($cfg, $storeid);
664 # lock shared storage
665 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
666 my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid, $snap);
667 return "$storeid:$volname";
671 sub vdisk_create_base
{
672 my ($cfg, $volid) = @_;
674 my ($storeid, $volname) = parse_volume_id
($volid);
676 my $scfg = storage_config
($cfg, $storeid);
678 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
680 activate_storage
($cfg, $storeid);
682 # lock shared storage
683 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
684 my $volname = $plugin->create_base($storeid, $scfg, $volname);
685 return "$storeid:$volname";
690 my ($cfg, $volid, $snapname) = @_;
692 my ($storeid, $volname) = parse_volume_id
($volid);
694 my $scfg = storage_config
($cfg, $storeid);
696 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
698 return $plugin->map_volume($storeid, $scfg, $volname, $snapname);
702 my ($cfg, $volid, $snapname) = @_;
704 my ($storeid, $volname) = parse_volume_id
($volid);
706 my $scfg = storage_config
($cfg, $storeid);
708 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
710 return $plugin->unmap_volume($storeid, $scfg, $volname, $snapname);
714 my ($cfg, $storeid, $vmid, $fmt, $name, $size) = @_;
716 die "no storage ID specified\n" if !$storeid;
718 PVE
::JSONSchema
::parse_storage_id
($storeid);
720 my $scfg = storage_config
($cfg, $storeid);
722 die "no VMID specified\n" if !$vmid;
724 $vmid = parse_vmid
($vmid);
726 my $defformat = PVE
::Storage
::Plugin
::default_format
($scfg);
728 $fmt = $defformat if !$fmt;
730 activate_storage
($cfg, $storeid);
732 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
734 # lock shared storage
735 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
736 my $old_umask = umask(umask|0037);
737 my $volname = eval { $plugin->alloc_image($storeid, $scfg, $vmid, $fmt, $name, $size) };
741 return "$storeid:$volname";
746 my ($cfg, $volid) = @_;
748 my ($storeid, $volname) = parse_volume_id
($volid);
749 my $scfg = storage_config
($cfg, $storeid);
750 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
752 activate_storage
($cfg, $storeid);
756 # lock shared storage
757 $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
758 # LVM-thin allows deletion of still referenced base volumes!
759 die "base volume '$volname' is still in use by linked clones\n"
760 if &$volume_is_base_and_used__no_lock($scfg, $storeid, $plugin, $volname);
762 my (undef, undef, undef, undef, undef, $isBase, $format) =
763 $plugin->parse_volname($volname);
764 $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname, $isBase, $format);
767 return if !$cleanup_worker;
769 my $rpcenv = PVE
::RPCEnvironment
::get
();
770 my $authuser = $rpcenv->get_user();
772 $rpcenv->fork_worker('imgdel', undef, $authuser, $cleanup_worker);
776 my ($cfg, $storeid, $vmid, $vollist) = @_;
778 my $ids = $cfg->{ids
};
780 storage_check_enabled
($cfg, $storeid) if ($storeid);
784 # prepare/activate/refresh all storages
786 my $storage_list = [];
788 foreach my $volid (@$vollist) {
789 my ($sid, undef) = parse_volume_id
($volid);
790 next if !defined($ids->{$sid});
791 next if !storage_check_enabled
($cfg, $sid, undef, 1);
792 push @$storage_list, $sid;
795 foreach my $sid (keys %$ids) {
796 next if $storeid && $storeid ne $sid;
797 next if !storage_check_enabled
($cfg, $sid, undef, 1);
798 push @$storage_list, $sid;
804 activate_storage_list
($cfg, $storage_list, $cache);
806 foreach my $sid (keys %$ids) {
807 next if $storeid && $storeid ne $sid;
808 next if !storage_check_enabled
($cfg, $sid, undef, 1);
810 my $scfg = $ids->{$sid};
811 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
812 $res->{$sid} = $plugin->list_images($sid, $scfg, $vmid, $vollist, $cache);
813 @{$res->{$sid}} = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @{$res->{$sid}} if $res->{$sid};
820 my ($cfg, $storeid, $tt) = @_;
822 die "unknown template type '$tt'\n"
823 if !($tt eq 'iso' || $tt eq 'vztmpl' || $tt eq 'backup' || $tt eq 'snippets');
825 my $ids = $cfg->{ids
};
827 storage_check_enabled
($cfg, $storeid) if ($storeid);
832 foreach my $sid (keys %$ids) {
833 next if $storeid && $storeid ne $sid;
835 my $scfg = $ids->{$sid};
836 my $type = $scfg->{type
};
838 next if !$scfg->{content
}->{$tt};
840 next if !storage_check_enabled
($cfg, $sid, undef, 1);
842 $res->{$sid} = volume_list
($cfg, $sid, undef, $tt);
849 my ($cfg, $storeid, $vmid, $content) = @_;
851 my @ctypes = qw(rootdir images vztmpl iso backup snippets);
853 my $cts = $content ?
[ $content ] : [ @ctypes ];
855 my $scfg = PVE
::Storage
::storage_config
($cfg, $storeid);
857 $cts = [ grep { defined($scfg->{content
}->{$_}) } @$cts ];
859 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
861 activate_storage
($cfg, $storeid);
863 my $res = $plugin->list_volumes($storeid, $scfg, $vmid, $cts);
865 @$res = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @$res;
872 my $filename = "/sys/kernel/uevent_seqnum";
875 if (my $fh = IO
::File-
>new($filename, "r")) {
877 if ($line =~ m/^(\d+)$/) {
885 sub activate_storage
{
886 my ($cfg, $storeid, $cache) = @_;
888 $cache = {} if !$cache;
890 my $scfg = storage_check_enabled
($cfg, $storeid);
892 return if $cache->{activated
}->{$storeid};
894 $cache->{uevent_seqnum
} = uevent_seqnum
() if !$cache->{uevent_seqnum
};
896 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
899 my ($baseid, undef) = parse_volume_id
($scfg->{base
});
900 activate_storage
($cfg, $baseid, $cache);
903 if (!$plugin->check_connection($storeid, $scfg)) {
904 die "storage '$storeid' is not online\n";
907 $plugin->activate_storage($storeid, $scfg, $cache);
909 my $newseq = uevent_seqnum
();
911 # only call udevsettle if there are events
912 if ($newseq > $cache->{uevent_seqnum
}) {
914 system ("$UDEVADM settle --timeout=$timeout"); # ignore errors
915 $cache->{uevent_seqnum
} = $newseq;
918 $cache->{activated
}->{$storeid} = 1;
921 sub activate_storage_list
{
922 my ($cfg, $storeid_list, $cache) = @_;
924 $cache = {} if !$cache;
926 foreach my $storeid (@$storeid_list) {
927 activate_storage
($cfg, $storeid, $cache);
931 sub deactivate_storage
{
932 my ($cfg, $storeid) = @_;
934 my $scfg = storage_config
($cfg, $storeid);
935 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
938 $plugin->deactivate_storage($storeid, $scfg, $cache);
941 sub activate_volumes
{
942 my ($cfg, $vollist, $snapname) = @_;
944 return if !($vollist && scalar(@$vollist));
946 my $storagehash = {};
947 foreach my $volid (@$vollist) {
948 my ($storeid, undef) = parse_volume_id
($volid);
949 $storagehash->{$storeid} = 1;
954 activate_storage_list
($cfg, [keys %$storagehash], $cache);
956 foreach my $volid (@$vollist) {
957 my ($storeid, $volname) = parse_volume_id
($volid);
958 my $scfg = storage_config
($cfg, $storeid);
959 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
960 $plugin->activate_volume($storeid, $scfg, $volname, $snapname, $cache);
964 sub deactivate_volumes
{
965 my ($cfg, $vollist, $snapname) = @_;
967 return if !($vollist && scalar(@$vollist));
972 foreach my $volid (@$vollist) {
973 my ($storeid, $volname) = parse_volume_id
($volid);
975 my $scfg = storage_config
($cfg, $storeid);
976 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
979 $plugin->deactivate_volume($storeid, $scfg, $volname, $snapname, $cache);
983 push @errlist, $volid;
987 die "volume deactivation failed: " . join(' ', @errlist)
992 my ($cfg, $content, $includeformat) = @_;
994 my $ids = $cfg->{ids
};
998 my @ctypes = PVE
::Tools
::split_list
($content);
1001 foreach my $storeid (keys %$ids) {
1002 my $storage_enabled = defined(storage_check_enabled
($cfg, $storeid, undef, 1));
1004 if (defined($content)) {
1006 foreach my $ctype (@ctypes) {
1007 if ($ids->{$storeid}->{content
}->{$ctype}) {
1012 next if !$want_ctype || !$storage_enabled;
1015 my $type = $ids->{$storeid}->{type
};
1017 $info->{$storeid} = {
1022 shared
=> $ids->{$storeid}->{shared
} ?
1 : 0,
1023 content
=> PVE
::Storage
::Plugin
::content_hash_to_string
($ids->{$storeid}->{content
}),
1025 enabled
=> $storage_enabled ?
1 : 0,
1028 push @$slist, $storeid;
1033 foreach my $storeid (keys %$ids) {
1034 my $scfg = $ids->{$storeid};
1036 next if !$info->{$storeid};
1037 next if !$info->{$storeid}->{enabled
};
1039 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1040 if ($includeformat) {
1041 my $pd = $plugin->plugindata();
1042 $info->{$storeid}->{format
} = $pd->{format
}
1044 $info->{$storeid}->{select_existing
} = $pd->{select_existing
}
1045 if $pd->{select_existing
};
1048 eval { activate_storage
($cfg, $storeid, $cache); };
1054 my ($total, $avail, $used, $active) = eval { $plugin->status($storeid, $scfg, $cache); };
1057 $info->{$storeid}->{total
} = int($total);
1058 $info->{$storeid}->{avail
} = int($avail);
1059 $info->{$storeid}->{used
} = int($used);
1060 $info->{$storeid}->{active
} = $active;
1069 my ($packed_ip, $family);
1071 my @res = PVE
::Tools
::getaddrinfo_all
($server);
1072 $family = $res[0]->{family
};
1073 $packed_ip = (PVE
::Tools
::unpack_sockaddr_in46
($res[0]->{addr
}))[2];
1075 if (defined $packed_ip) {
1076 return Socket
::inet_ntop
($family, $packed_ip);
1082 my ($server_in) = @_;
1085 if (!($server = resolv_server
($server_in))) {
1086 die "unable to resolve address for server '${server_in}'\n";
1089 my $cmd = ['/sbin/showmount', '--no-headers', '--exports', $server];
1092 run_command
($cmd, outfunc
=> sub {
1095 # note: howto handle white spaces in export path??
1096 if ($line =~ m!^(/\S+)\s+(.+)$!) {
1105 my ($server_in, $user, $password, $domain) = @_;
1108 if (!($server = resolv_server
($server_in))) {
1109 die "unable to resolve address for server '${server_in}'\n";
1112 # we support only Windows grater than 2012 cifsscan so use smb3
1113 my $cmd = ['/usr/bin/smbclient', '-m', 'smb3', '-d', '0', '-L', $server];
1114 if (defined($user)) {
1115 die "password is required" if !defined($password);
1116 push @$cmd, '-U', "$user\%$password";
1117 push @$cmd, '-W', $domain if defined($domain);
1126 if ($line =~ m/(\S+)\s*Disk\s*(\S*)/) {
1128 } elsif ($line =~ m/(NT_STATUS_(\S*))/) {
1141 my $cmd = ['zfs', 'list', '-t', 'filesystem', '-H', '-o', 'name,avail,used'];
1144 run_command
($cmd, outfunc
=> sub {
1147 if ($line =~m/^(\S+)\s+(\S+)\s+(\S+)$/) {
1148 my ($pool, $size_str, $used_str) = ($1, $2, $3);
1149 my $size = PVE
::Storage
::ZFSPoolPlugin
::zfs_parse_size
($size_str);
1150 my $used = PVE
::Storage
::ZFSPoolPlugin
::zfs_parse_size
($used_str);
1151 # ignore subvolumes generated by our ZFSPoolPlugin
1152 return if $pool =~ m!/subvol-\d+-[^/]+$!;
1153 return if $pool =~ m!/basevol-\d+-[^/]+$!;
1154 push @$res, { pool
=> $pool, size
=> $size, free
=> $size-$used };
1162 my ($portal, $noerr) = @_;
1164 my ($server, $port) = PVE
::Tools
::parse_host_and_port
($portal);
1166 if (my $ip = resolv_server
($server)) {
1168 $server = "[$server]" if $server =~ /^$IPV6RE$/;
1169 return $port ?
"$server:$port" : $server;
1172 return undef if $noerr;
1174 raise_param_exc
({ portal
=> "unable to resolve portal address '$portal'" });
1179 my ($portal_in) = @_;
1182 if (!($portal = resolv_portal
($portal_in))) {
1183 die "unable to parse/resolve portal address '${portal_in}'\n";
1186 return PVE
::Storage
::ISCSIPlugin
::iscsi_discovery
($portal);
1189 sub storage_default_format
{
1190 my ($cfg, $storeid) = @_;
1192 my $scfg = storage_config
($cfg, $storeid);
1194 return PVE
::Storage
::Plugin
::default_format
($scfg);
1197 sub vgroup_is_used
{
1198 my ($cfg, $vgname) = @_;
1200 foreach my $storeid (keys %{$cfg->{ids
}}) {
1201 my $scfg = storage_config
($cfg, $storeid);
1202 if ($scfg->{type
} eq 'lvm' && $scfg->{vgname
} eq $vgname) {
1210 sub target_is_used
{
1211 my ($cfg, $target) = @_;
1213 foreach my $storeid (keys %{$cfg->{ids
}}) {
1214 my $scfg = storage_config
($cfg, $storeid);
1215 if ($scfg->{type
} eq 'iscsi' && $scfg->{target
} eq $target) {
1223 sub volume_is_used
{
1224 my ($cfg, $volid) = @_;
1226 foreach my $storeid (keys %{$cfg->{ids
}}) {
1227 my $scfg = storage_config
($cfg, $storeid);
1228 if ($scfg->{base
} && $scfg->{base
} eq $volid) {
1236 sub storage_is_used
{
1237 my ($cfg, $storeid) = @_;
1239 foreach my $sid (keys %{$cfg->{ids
}}) {
1240 my $scfg = storage_config
($cfg, $sid);
1241 next if !$scfg->{base
};
1242 my ($st) = parse_volume_id
($scfg->{base
});
1243 return 1 if $st && $st eq $storeid;
1250 my ($list, $func) = @_;
1254 foreach my $sid (keys %$list) {
1255 foreach my $info (@{$list->{$sid}}) {
1256 my $volid = $info->{volid
};
1257 my ($sid1, $volname) = parse_volume_id
($volid, 1);
1258 if ($sid1 && $sid1 eq $sid) {
1259 &$func ($volid, $sid, $info);
1261 warn "detected strange volid '$volid' in volume list for '$sid'\n";
1267 sub extract_vzdump_config_tar
{
1268 my ($archive, $conf_re) = @_;
1270 die "ERROR: file '$archive' does not exist\n" if ! -f
$archive;
1272 my $pid = open(my $fh, '-|', 'tar', 'tf', $archive) ||
1273 die "unable to open file '$archive'\n";
1276 while (defined($file = <$fh>)) {
1277 if ($file =~ $conf_re) {
1278 $file = $1; # untaint
1287 die "ERROR: archive contains no configuration file\n" if !$file;
1293 $raw .= "$output\n";
1296 PVE
::Tools
::run_command
(['tar', '-xpOf', $archive, $file, '--occurrence'], outfunc
=> $out);
1298 return wantarray ?
($raw, $file) : $raw;
1301 sub extract_vzdump_config_vma
{
1302 my ($archive, $comp) = @_;
1308 $raw .= "$output\n";
1314 if ($comp eq 'gz') {
1315 $uncomp = ["zcat", $archive];
1316 } elsif ($comp eq 'lzo') {
1317 $uncomp = ["lzop", "-d", "-c", $archive];
1319 die "unknown compression method '$comp'\n";
1321 $cmd = [$uncomp, ["vma", "config", "-"]];
1323 # in some cases, lzop/zcat exits with 1 when its stdout pipe is
1324 # closed early by vma, detect this and ignore the exit code later
1329 if ($output =~ m/lzop: Broken pipe: <stdout>/ || $output =~ m/gzip: stdout: Broken pipe/) {
1331 } elsif (!defined ($errstring) && $output !~ m/^\s*$/) {
1332 $errstring = "Failed to extract config from VMA archive: $output\n";
1336 # in other cases, the pipeline will exit with exit code 141
1337 # because of the broken pipe, handle / ignore this as well
1340 $rc = PVE
::Tools
::run_command
($cmd, outfunc
=> $out, errfunc
=> $err, noerr
=> 1);
1344 # use exit code if no stderr output and not just broken pipe
1345 if (!$errstring && !$broken_pipe && $rc != 0 && $rc != 141) {
1346 die "$rerr\n" if $rerr;
1347 die "config extraction failed with exit code $rc\n";
1349 die "$errstring\n" if $errstring;
1351 # simple case without compression and weird piping behaviour
1352 PVE
::Tools
::run_command
(["vma", "config", $archive], outfunc
=> $out);
1355 return wantarray ?
($raw, undef) : $raw;
1358 sub extract_vzdump_config
{
1359 my ($cfg, $volid) = @_;
1361 my $archive = abs_filesystem_path
($cfg, $volid);
1363 if ($volid =~ /vzdump-(lxc|openvz)-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?))$/) {
1364 return extract_vzdump_config_tar
($archive, qr!^(\./etc/vzdump/(pct|vps)\.conf)$!);
1365 } elsif ($volid =~ /vzdump-qemu-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(gz|lzo))?))$/) {
1373 $comp = $11 if defined($11);
1376 if ($format eq 'tar') {
1377 return extract_vzdump_config_tar
($archive, qr!\(\./qemu-server\.conf\)!);
1379 return extract_vzdump_config_vma
($archive, $comp);
1382 die "cannot determine backup guest type for backup archive '$volid'\n";
1387 my ($cfg, $fh, $volid, $format, $snapshot, $base_snapshot, $with_snapshots) = @_;
1389 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1390 die "cannot export volume '$volid'\n" if !$storeid;
1391 my $scfg = storage_config
($cfg, $storeid);
1392 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1393 return $plugin->volume_export($scfg, $storeid, $fh, $volname, $format,
1394 $snapshot, $base_snapshot, $with_snapshots);
1398 my ($cfg, $fh, $volid, $format, $base_snapshot, $with_snapshots) = @_;
1400 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1401 die "cannot import into volume '$volid'\n" if !$storeid;
1402 my $scfg = storage_config
($cfg, $storeid);
1403 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1404 return $plugin->volume_import($scfg, $storeid, $fh, $volname, $format,
1405 $base_snapshot, $with_snapshots);
1408 sub volume_export_formats
{
1409 my ($cfg, $volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
1411 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1412 return if !$storeid;
1413 my $scfg = storage_config
($cfg, $storeid);
1414 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1415 return $plugin->volume_export_formats($scfg, $storeid, $volname,
1416 $snapshot, $base_snapshot,
1420 sub volume_import_formats
{
1421 my ($cfg, $volid, $base_snapshot, $with_snapshots) = @_;
1423 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1424 return if !$storeid;
1425 my $scfg = storage_config
($cfg, $storeid);
1426 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1427 return $plugin->volume_import_formats($scfg, $storeid, $volname,
1428 $base_snapshot, $with_snapshots);
1431 sub volume_transfer_formats
{
1432 my ($cfg, $src_volid, $dst_volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
1433 my @export_formats = volume_export_formats
($cfg, $src_volid, $snapshot, $base_snapshot, $with_snapshots);
1434 my @import_formats = volume_import_formats
($cfg, $dst_volid, $base_snapshot, $with_snapshots);
1435 my %import_hash = map { $_ => 1 } @import_formats;
1436 my @common = grep { $import_hash{$_} } @export_formats;
1440 # bash completion helper
1442 sub complete_storage
{
1443 my ($cmdname, $pname, $cvalue) = @_;
1445 my $cfg = PVE
::Storage
::config
();
1447 return $cmdname eq 'add' ?
[] : [ PVE
::Storage
::storage_ids
($cfg) ];
1450 sub complete_storage_enabled
{
1451 my ($cmdname, $pname, $cvalue) = @_;
1455 my $cfg = PVE
::Storage
::config
();
1456 foreach my $sid (keys %{$cfg->{ids
}}) {
1457 next if !storage_check_enabled
($cfg, $sid, undef, 1);
1463 sub complete_content_type
{
1464 my ($cmdname, $pname, $cvalue) = @_;
1466 return [qw(rootdir images vztmpl iso backup snippets)];
1469 sub complete_volume
{
1470 my ($cmdname, $pname, $cvalue) = @_;
1474 my $storage_list = complete_storage_enabled
();
1476 if ($cvalue =~ m/^([^:]+):/) {
1477 $storage_list = [ $1 ];
1479 if (scalar(@$storage_list) > 1) {
1480 # only list storage IDs to avoid large listings
1482 foreach my $storeid (@$storage_list) {
1483 # Hack: simply return 2 artificial values, so that
1484 # completions does not finish
1485 push @$res, "$storeid:volname", "$storeid:...";
1492 foreach my $storeid (@$storage_list) {
1493 my $vollist = PVE
::Storage
::volume_list
($cfg, $storeid);
1495 foreach my $item (@$vollist) {
1496 push @$res, $item->{volid
};
1503 # Various io-heavy operations require io/bandwidth limits which can be
1504 # configured on multiple levels: The global defaults in datacenter.cfg, and
1505 # per-storage overrides. When we want to do a restore from storage A to storage
1506 # B, we should take the smaller limit defined for storages A and B, and if no
1507 # such limit was specified, use the one from datacenter.cfg.
1508 sub get_bandwidth_limit
{
1509 my ($operation, $storage_list, $override) = @_;
1511 # called for each limit (global, per-storage) with the 'default' and the
1512 # $operation limit and should udpate $override for every limit affecting
1514 my $use_global_limits = 0;
1515 my $apply_limit = sub {
1517 if (defined($bwlimit)) {
1518 my $limits = PVE
::JSONSchema
::parse_property_string
('bwlimit', $bwlimit);
1519 my $limit = $limits->{$operation} // $limits->{default};
1520 if (defined($limit)) {
1521 if (!$override || $limit < $override) {
1527 # If there was no applicable limit, try to apply the global ones.
1528 $use_global_limits = 1;
1531 my ($rpcenv, $authuser);
1532 if (defined($override)) {
1533 $rpcenv = PVE
::RPCEnvironment-
>get();
1534 $authuser = $rpcenv->get_user();
1537 # Apply per-storage limits - if there are storages involved.
1538 if (defined($storage_list) && @$storage_list) {
1539 my $config = config
();
1541 # The Datastore.Allocate permission allows us to modify the per-storage
1542 # limits, therefore it also allows us to override them.
1543 # Since we have most likely multiple storages to check, do a quick check on
1544 # the general '/storage' path to see if we can skip the checks entirely:
1545 return $override if $rpcenv && $rpcenv->check($authuser, '/storage', ['Datastore.Allocate'], 1);
1548 foreach my $storage (@$storage_list) {
1549 next if !defined($storage);
1550 # Avoid duplicate checks:
1551 next if $done{$storage};
1552 $done{$storage} = 1;
1554 # Otherwise we may still have individual /storage/$ID permissions:
1555 if (!$rpcenv || !$rpcenv->check($authuser, "/storage/$storage", ['Datastore.Allocate'], 1)) {
1556 # And if not: apply the limits.
1557 my $storecfg = storage_config
($config, $storage);
1558 $apply_limit->($storecfg->{bwlimit
});
1562 # Storage limits take precedence over the datacenter defaults, so if
1563 # a limit was applied:
1564 return $override if !$use_global_limits;
1567 # Sys.Modify on '/' means we can change datacenter.cfg which contains the
1568 # global default limits.
1569 if (!$rpcenv || !$rpcenv->check($authuser, '/', ['Sys.Modify'], 1)) {
1570 # So if we cannot modify global limits, apply them to our currently
1571 # requested override.
1572 my $dc = cfs_read_file
('datacenter.cfg');
1573 $apply_limit->($dc->{bwlimit
});
1579 # checks if the storage id is available and dies if not
1580 sub assert_sid_unused
{
1584 if (my $scfg = storage_config
($cfg, $sid, 1)) {
1585 die "storage ID '$sid' already defined\n";