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
;
25 use PVE
::Storage
::Plugin
;
26 use PVE
::Storage
::DirPlugin
;
27 use PVE
::Storage
::LVMPlugin
;
28 use PVE
::Storage
::LvmThinPlugin
;
29 use PVE
::Storage
::NFSPlugin
;
30 use PVE
::Storage
::CIFSPlugin
;
31 use PVE
::Storage
::ISCSIPlugin
;
32 use PVE
::Storage
::RBDPlugin
;
33 use PVE
::Storage
::CephFSPlugin
;
34 use PVE
::Storage
::ISCSIDirectPlugin
;
35 use PVE
::Storage
::GlusterfsPlugin
;
36 use PVE
::Storage
::ZFSPoolPlugin
;
37 use PVE
::Storage
::ZFSPlugin
;
38 use PVE
::Storage
::DRBDPlugin
;
40 # Storage API version. Icrement it on changes in storage API interface.
41 use constant APIVER
=> 3;
42 # Age is the number of versions we're backward compatible with.
43 # This is like having 'current=APIVER' and age='APIAGE' in libtool,
44 # see https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
45 use constant APIAGE
=> 2;
47 # load standard plugins
48 PVE
::Storage
::DirPlugin-
>register();
49 PVE
::Storage
::LVMPlugin-
>register();
50 PVE
::Storage
::LvmThinPlugin-
>register();
51 PVE
::Storage
::NFSPlugin-
>register();
52 PVE
::Storage
::CIFSPlugin-
>register();
53 PVE
::Storage
::ISCSIPlugin-
>register();
54 PVE
::Storage
::RBDPlugin-
>register();
55 PVE
::Storage
::CephFSPlugin-
>register();
56 PVE
::Storage
::ISCSIDirectPlugin-
>register();
57 PVE
::Storage
::GlusterfsPlugin-
>register();
58 PVE
::Storage
::ZFSPoolPlugin-
>register();
59 PVE
::Storage
::ZFSPlugin-
>register();
60 PVE
::Storage
::DRBDPlugin-
>register();
62 # load third-party plugins
63 if ( -d
'/usr/share/perl5/PVE/Storage/Custom' ) {
64 dir_glob_foreach
('/usr/share/perl5/PVE/Storage/Custom', '.*\.pm$', sub {
66 my $modname = 'PVE::Storage::Custom::' . $file;
67 $modname =~ s!\.pm$!!;
68 $file = 'PVE/Storage/Custom/' . $file;
73 # Check perl interface:
74 die "not derived from PVE::Storage::Plugin\n"
75 if !$modname->isa('PVE::Storage::Plugin');
76 die "does not provide an api() method\n"
77 if !$modname->can('api');
78 # Check storage API version and that file is really storage plugin.
79 my $version = $modname->api();
80 die "implements an API version newer than current ($version > " . APIVER
. ")\n"
82 my $min_version = (APIVER
- APIAGE
);
83 die "API version too old, please update the plugin ($version < $min_version)\n"
84 if $version < $min_version;
88 # If we got this far and the API version is not the same, make some
90 warn "Plugin \"$modname\" is implementing an older storage API
, an upgrade
is recommended
\n"
91 if $version != APIVER;
94 warn "Error loading storage plugin
\"$modname\": $@";
99 # initialize all plugins
100 PVE
::Storage
::Plugin-
>init();
102 my $UDEVADM = '/sbin/udevadm';
104 our $iso_extension_re = qr/\.(?:iso|img)/i;
106 # PVE::Storage utility functions
109 return cfs_read_file
("storage.cfg");
115 cfs_write_file
('storage.cfg', $cfg);
118 sub lock_storage_config
{
119 my ($code, $errmsg) = @_;
121 cfs_lock_file
("storage.cfg", undef, $code);
124 $errmsg ?
die "$errmsg: $err" : die $err;
129 my ($cfg, $storeid, $noerr) = @_;
131 die "no storage ID specified\n" if !$storeid;
133 my $scfg = $cfg->{ids
}->{$storeid};
135 die "storage '$storeid' does not exist\n" if (!$noerr && !$scfg);
140 sub storage_check_node
{
141 my ($cfg, $storeid, $node, $noerr) = @_;
143 my $scfg = storage_config
($cfg, $storeid);
145 if ($scfg->{nodes
}) {
146 $node = PVE
::INotify
::nodename
() if !$node || ($node eq 'localhost');
147 if (!$scfg->{nodes
}->{$node}) {
148 die "storage '$storeid' is not available on node '$node'\n" if !$noerr;
156 sub storage_check_enabled
{
157 my ($cfg, $storeid, $node, $noerr) = @_;
159 my $scfg = storage_config
($cfg, $storeid);
161 if ($scfg->{disable
}) {
162 die "storage '$storeid' is disabled\n" if !$noerr;
166 return storage_check_node
($cfg, $storeid, $node, $noerr);
169 # storage_can_replicate:
170 # return true if storage supports replication
171 # (volumes alocated with vdisk_alloc() has replication feature)
172 sub storage_can_replicate
{
173 my ($cfg, $storeid, $format) = @_;
175 my $scfg = storage_config
($cfg, $storeid);
176 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
177 return $plugin->storage_can_replicate($scfg, $storeid, $format);
183 return keys %{$cfg->{ids
}};
187 my ($filename, $timeout) = @_;
189 return PVE
::Storage
::Plugin
::file_size_info
($filename, $timeout);
192 sub volume_size_info
{
193 my ($cfg, $volid, $timeout) = @_;
195 my ($storeid, $volname) = parse_volume_id
($volid, 1);
197 my $scfg = storage_config
($cfg, $storeid);
198 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
199 return $plugin->volume_size_info($scfg, $storeid, $volname, $timeout);
200 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
201 return file_size_info
($volid, $timeout);
208 my ($cfg, $volid, $size, $running) = @_;
210 my ($storeid, $volname) = parse_volume_id
($volid, 1);
212 my $scfg = storage_config
($cfg, $storeid);
213 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
214 return $plugin->volume_resize($scfg, $storeid, $volname, $size, $running);
215 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
216 die "resize file/device '$volid' is not possible\n";
218 die "unable to parse volume ID '$volid'\n";
222 sub volume_rollback_is_possible
{
223 my ($cfg, $volid, $snap) = @_;
225 my ($storeid, $volname) = parse_volume_id
($volid, 1);
227 my $scfg = storage_config
($cfg, $storeid);
228 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
229 return $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
230 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
231 die "snapshot rollback file/device '$volid' is not possible\n";
233 die "unable to parse volume ID '$volid'\n";
237 sub volume_snapshot
{
238 my ($cfg, $volid, $snap) = @_;
240 my ($storeid, $volname) = parse_volume_id
($volid, 1);
242 my $scfg = storage_config
($cfg, $storeid);
243 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
244 return $plugin->volume_snapshot($scfg, $storeid, $volname, $snap);
245 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
246 die "snapshot file/device '$volid' is not possible\n";
248 die "unable to parse volume ID '$volid'\n";
252 sub volume_snapshot_rollback
{
253 my ($cfg, $volid, $snap) = @_;
255 my ($storeid, $volname) = parse_volume_id
($volid, 1);
257 my $scfg = storage_config
($cfg, $storeid);
258 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
259 $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
260 return $plugin->volume_snapshot_rollback($scfg, $storeid, $volname, $snap);
261 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
262 die "snapshot rollback file/device '$volid' is not possible\n";
264 die "unable to parse volume ID '$volid'\n";
268 sub volume_snapshot_delete
{
269 my ($cfg, $volid, $snap, $running) = @_;
271 my ($storeid, $volname) = parse_volume_id
($volid, 1);
273 my $scfg = storage_config
($cfg, $storeid);
274 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
275 return $plugin->volume_snapshot_delete($scfg, $storeid, $volname, $snap, $running);
276 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
277 die "snapshot delete file/device '$volid' is not possible\n";
279 die "unable to parse volume ID '$volid'\n";
283 sub volume_has_feature
{
284 my ($cfg, $feature, $volid, $snap, $running) = @_;
286 my ($storeid, $volname) = parse_volume_id
($volid, 1);
288 my $scfg = storage_config
($cfg, $storeid);
289 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
290 return $plugin->volume_has_feature($scfg, $feature, $storeid, $volname, $snap, $running);
291 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
298 sub volume_snapshot_list
{
299 my ($cfg, $volid) = @_;
301 my ($storeid, $volname) = parse_volume_id
($volid, 1);
303 my $scfg = storage_config
($cfg, $storeid);
304 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
305 return $plugin->volume_snapshot_list($scfg, $storeid, $volname);
306 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
307 die "send file/device '$volid' is not possible\n";
309 die "unable to parse volume ID '$volid'\n";
311 # return an empty array if dataset does not exist.
315 my ($cfg, $storeid, $vmid) = @_;
317 my $scfg = storage_config
($cfg, $storeid);
318 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
320 my $path = $plugin->get_subdir($scfg, 'images');
322 return $vmid ?
"$path/$vmid" : $path;
325 sub get_private_dir
{
326 my ($cfg, $storeid, $vmid) = @_;
328 my $scfg = storage_config
($cfg, $storeid);
329 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
331 my $path = $plugin->get_subdir($scfg, 'rootdir');
333 return $vmid ?
"$path/$vmid" : $path;
337 my ($cfg, $storeid) = @_;
339 my $scfg = storage_config
($cfg, $storeid);
340 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
342 return $plugin->get_subdir($scfg, 'iso');
346 my ($cfg, $storeid) = @_;
348 my $scfg = storage_config
($cfg, $storeid);
349 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
351 return $plugin->get_subdir($scfg, 'vztmpl');
355 my ($cfg, $storeid) = @_;
357 my $scfg = storage_config
($cfg, $storeid);
358 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
360 return $plugin->get_subdir($scfg, 'backup');
363 # library implementation
368 die "VMID '$vmid' contains illegal characters\n" if $vmid !~ m/^\d+$/;
373 # NOTE: basename and basevmid are always undef for LVM-thin, where the
374 # clone -> base reference is not encoded in the volume ID.
375 # see note in PVE::Storage::LvmThinPlugin for details.
377 my ($cfg, $volid) = @_;
379 my ($storeid, $volname) = parse_volume_id
($volid);
381 my $scfg = storage_config
($cfg, $storeid);
383 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
385 # returns ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format)
387 return $plugin->parse_volname($volname);
390 sub parse_volume_id
{
391 my ($volid, $noerr) = @_;
393 return PVE
::Storage
::Plugin
::parse_volume_id
($volid, $noerr);
396 # test if we have read access to volid
397 sub check_volume_access
{
398 my ($rpcenv, $user, $cfg, $vmid, $volid) = @_;
400 my ($sid, $volname) = parse_volume_id
($volid, 1);
402 my ($vtype, undef, $ownervm) = parse_volname
($cfg, $volid);
403 if ($vtype eq 'iso' || $vtype eq 'vztmpl') {
404 # require at least read access to storage, (custom) templates/ISOs could be sensitive
405 $rpcenv->check_any($user, "/storage/$sid", ['Datastore.AllocateSpace', 'Datastore.Audit']);
406 } elsif (defined($ownervm) && defined($vmid) && ($ownervm == $vmid)) {
407 # we are owner - allow access
408 } elsif ($vtype eq 'backup' && $ownervm) {
409 $rpcenv->check($user, "/storage/$sid", ['Datastore.AllocateSpace']);
410 $rpcenv->check($user, "/vms/$ownervm", ['VM.Backup']);
412 # allow if we are Datastore administrator
413 $rpcenv->check($user, "/storage/$sid", ['Datastore.Allocate']);
416 die "Only root can pass arbitrary filesystem paths."
417 if $user ne 'root@pam';
423 my $volume_is_base_and_used__no_lock = sub {
424 my ($scfg, $storeid, $plugin, $volname) = @_;
426 my ($vtype, $name, $vmid, undef, undef, $isBase, undef) =
427 $plugin->parse_volname($volname);
430 my $vollist = $plugin->list_images($storeid, $scfg);
431 foreach my $info (@$vollist) {
432 my (undef, $tmpvolname) = parse_volume_id
($info->{volid
});
433 my $basename = undef;
434 my $basevmid = undef;
437 (undef, undef, undef, $basename, $basevmid) =
438 $plugin->parse_volname($tmpvolname);
441 if ($basename && defined($basevmid) && $basevmid == $vmid && $basename eq $name) {
449 # NOTE: this check does not work for LVM-thin, where the clone -> base
450 # reference is not encoded in the volume ID.
451 # see note in PVE::Storage::LvmThinPlugin for details.
452 sub volume_is_base_and_used
{
453 my ($cfg, $volid) = @_;
455 my ($storeid, $volname) = parse_volume_id
($volid);
456 my $scfg = storage_config
($cfg, $storeid);
457 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
459 $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
460 return &$volume_is_base_and_used__no_lock($scfg, $storeid, $plugin, $volname);
464 # try to map a filesystem path to a volume identifier
465 sub path_to_volume_id
{
466 my ($cfg, $path) = @_;
468 my $ids = $cfg->{ids
};
470 my ($sid, $volname) = parse_volume_id
($path, 1);
472 if (my $scfg = $ids->{$sid}) {
474 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
475 my ($vtype, $name, $vmid) = $plugin->parse_volname($volname);
476 return ($vtype, $path);
482 # Note: abs_path() return undef if $path doesn not exist
483 # for example when nfs storage is not mounted
484 $path = abs_path
($path) || $path;
486 foreach my $sid (keys %$ids) {
487 my $scfg = $ids->{$sid};
488 next if !$scfg->{path
};
489 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
490 my $imagedir = $plugin->get_subdir($scfg, 'images');
491 my $isodir = $plugin->get_subdir($scfg, 'iso');
492 my $tmpldir = $plugin->get_subdir($scfg, 'vztmpl');
493 my $backupdir = $plugin->get_subdir($scfg, 'backup');
494 my $privatedir = $plugin->get_subdir($scfg, 'rootdir');
496 if ($path =~ m!^$imagedir/(\d+)/([^/\s]+)$!) {
500 my $vollist = $plugin->list_images($sid, $scfg, $vmid);
501 foreach my $info (@$vollist) {
502 my ($storeid, $volname) = parse_volume_id
($info->{volid
});
503 my $volpath = $plugin->path($scfg, $volname, $storeid);
504 if ($volpath eq $path) {
505 return ('images', $info->{volid
});
508 } elsif ($path =~ m!^$isodir/([^/]+$iso_extension_re)$!) {
510 return ('iso', "$sid:iso/$name");
511 } elsif ($path =~ m!^$tmpldir/([^/]+\.tar\.gz)$!) {
513 return ('vztmpl', "$sid:vztmpl/$name");
514 } elsif ($path =~ m!^$privatedir/(\d+)$!) {
516 return ('rootdir', "$sid:rootdir/$vmid");
517 } elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!) {
519 return ('iso', "$sid:backup/$name");
523 # can't map path to volume id
528 my ($cfg, $volid, $snapname) = @_;
530 my ($storeid, $volname) = parse_volume_id
($volid);
532 my $scfg = storage_config
($cfg, $storeid);
534 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
535 my ($path, $owner, $vtype) = $plugin->path($scfg, $volname, $storeid, $snapname);
536 return wantarray ?
($path, $owner, $vtype) : $path;
539 sub abs_filesystem_path
{
540 my ($cfg, $volid) = @_;
543 if (parse_volume_id
($volid, 1)) {
544 activate_volumes
($cfg, [ $volid ]);
545 $path = PVE
::Storage
::path
($cfg, $volid);
548 my $abspath = abs_path
($volid);
549 if ($abspath && $abspath =~ m
|^(/.+)$|) {
550 $path = $1; # untaint any path
555 die "can't find file '$volid'\n" if !($path && -f
$path);
560 sub storage_migrate
{
561 my ($cfg, $volid, $target_sshinfo, $target_storeid, $target_volname, $base_snapshot, $snapshot, $ratelimit_bps, $insecure, $with_snapshots, $logfunc) = @_;
563 my ($storeid, $volname) = parse_volume_id
($volid);
564 $target_volname = $volname if !$target_volname;
566 my $scfg = storage_config
($cfg, $storeid);
568 # no need to migrate shared content
569 return if $storeid eq $target_storeid && $scfg->{shared
};
571 my $tcfg = storage_config
($cfg, $target_storeid);
573 my $target_volid = "${target_storeid}:${target_volname}";
575 my $target_ip = $target_sshinfo->{ip
};
577 my $ssh = PVE
::SSHInfo
::ssh_info_to_command
($target_sshinfo);
578 my $ssh_base = PVE
::SSHInfo
::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), logfunc
=> $logfunc);
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);
634 # wait for the remote process to finish
636 while (my $line = <$info>) {
638 $logfunc->("[$target_sshinfo->{name}] $line");
644 # now close the socket
646 if (!close($info)) { # does waitpid()
647 die "import failed: $!\n" if $!;
648 die "import failed: exit code ".($?>>8)."\n";
651 run_command
([$send, @cstream, $recv], logfunc
=> $logfunc);
655 warn "send/receive failed, cleaning up snapshot(s)..\n" if $err;
656 if ($migration_snapshot) {
657 eval { volume_snapshot_delete
($cfg, $volid, $snapshot, 0) };
658 warn "could not remove source snapshot: $@\n" if $@;
664 my ($cfg, $volid, $vmid, $snap) = @_;
666 my ($storeid, $volname) = parse_volume_id
($volid);
668 my $scfg = storage_config
($cfg, $storeid);
670 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
672 activate_storage
($cfg, $storeid);
674 # lock shared storage
675 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
676 my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid, $snap);
677 return "$storeid:$volname";
681 sub vdisk_create_base
{
682 my ($cfg, $volid) = @_;
684 my ($storeid, $volname) = parse_volume_id
($volid);
686 my $scfg = storage_config
($cfg, $storeid);
688 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
690 activate_storage
($cfg, $storeid);
692 # lock shared storage
693 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
694 my $volname = $plugin->create_base($storeid, $scfg, $volname);
695 return "$storeid:$volname";
700 my ($cfg, $volid, $snapname) = @_;
702 my ($storeid, $volname) = parse_volume_id
($volid);
704 my $scfg = storage_config
($cfg, $storeid);
706 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
708 return $plugin->map_volume($storeid, $scfg, $volname, $snapname);
712 my ($cfg, $volid, $snapname) = @_;
714 my ($storeid, $volname) = parse_volume_id
($volid);
716 my $scfg = storage_config
($cfg, $storeid);
718 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
720 return $plugin->unmap_volume($storeid, $scfg, $volname, $snapname);
724 my ($cfg, $storeid, $vmid, $fmt, $name, $size) = @_;
726 die "no storage ID specified\n" if !$storeid;
728 PVE
::JSONSchema
::parse_storage_id
($storeid);
730 my $scfg = storage_config
($cfg, $storeid);
732 die "no VMID specified\n" if !$vmid;
734 $vmid = parse_vmid
($vmid);
736 my $defformat = PVE
::Storage
::Plugin
::default_format
($scfg);
738 $fmt = $defformat if !$fmt;
740 activate_storage
($cfg, $storeid);
742 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
744 # lock shared storage
745 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
746 my $old_umask = umask(umask|0037);
747 my $volname = eval { $plugin->alloc_image($storeid, $scfg, $vmid, $fmt, $name, $size) };
751 return "$storeid:$volname";
756 my ($cfg, $volid) = @_;
758 my ($storeid, $volname) = parse_volume_id
($volid);
759 my $scfg = storage_config
($cfg, $storeid);
760 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
762 activate_storage
($cfg, $storeid);
766 # lock shared storage
767 $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
768 # LVM-thin allows deletion of still referenced base volumes!
769 die "base volume '$volname' is still in use by linked clones\n"
770 if &$volume_is_base_and_used__no_lock($scfg, $storeid, $plugin, $volname);
772 my (undef, undef, undef, undef, undef, $isBase, $format) =
773 $plugin->parse_volname($volname);
774 $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname, $isBase, $format);
777 return if !$cleanup_worker;
779 my $rpcenv = PVE
::RPCEnvironment
::get
();
780 my $authuser = $rpcenv->get_user();
782 $rpcenv->fork_worker('imgdel', undef, $authuser, $cleanup_worker);
786 my ($cfg, $storeid, $vmid, $vollist) = @_;
788 my $ids = $cfg->{ids
};
790 storage_check_enabled
($cfg, $storeid) if ($storeid);
794 # prepare/activate/refresh all storages
796 my $storage_list = [];
798 foreach my $volid (@$vollist) {
799 my ($sid, undef) = parse_volume_id
($volid);
800 next if !defined($ids->{$sid});
801 next if !storage_check_enabled
($cfg, $sid, undef, 1);
802 push @$storage_list, $sid;
805 foreach my $sid (keys %$ids) {
806 next if $storeid && $storeid ne $sid;
807 next if !storage_check_enabled
($cfg, $sid, undef, 1);
808 push @$storage_list, $sid;
814 activate_storage_list
($cfg, $storage_list, $cache);
816 foreach my $sid (keys %$ids) {
817 next if $storeid && $storeid ne $sid;
818 next if !storage_check_enabled
($cfg, $sid, undef, 1);
820 my $scfg = $ids->{$sid};
821 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
822 $res->{$sid} = $plugin->list_images($sid, $scfg, $vmid, $vollist, $cache);
823 @{$res->{$sid}} = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @{$res->{$sid}} if $res->{$sid};
830 my ($cfg, $storeid, $tt) = @_;
832 die "unknown template type '$tt'\n"
833 if !($tt eq 'iso' || $tt eq 'vztmpl' || $tt eq 'backup' || $tt eq 'snippets');
835 my $ids = $cfg->{ids
};
837 storage_check_enabled
($cfg, $storeid) if ($storeid);
842 foreach my $sid (keys %$ids) {
843 next if $storeid && $storeid ne $sid;
845 my $scfg = $ids->{$sid};
846 my $type = $scfg->{type
};
848 next if !$scfg->{content
}->{$tt};
850 next if !storage_check_enabled
($cfg, $sid, undef, 1);
852 $res->{$sid} = volume_list
($cfg, $sid, undef, $tt);
859 my ($cfg, $storeid, $vmid, $content) = @_;
861 my @ctypes = qw(rootdir images vztmpl iso backup snippets);
863 my $cts = $content ?
[ $content ] : [ @ctypes ];
865 my $scfg = PVE
::Storage
::storage_config
($cfg, $storeid);
867 $cts = [ grep { defined($scfg->{content
}->{$_}) } @$cts ];
869 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
871 activate_storage
($cfg, $storeid);
873 my $res = $plugin->list_volumes($storeid, $scfg, $vmid, $cts);
875 @$res = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @$res;
882 my $filename = "/sys/kernel/uevent_seqnum";
885 if (my $fh = IO
::File-
>new($filename, "r")) {
887 if ($line =~ m/^(\d+)$/) {
895 sub activate_storage
{
896 my ($cfg, $storeid, $cache) = @_;
898 $cache = {} if !$cache;
900 my $scfg = storage_check_enabled
($cfg, $storeid);
902 return if $cache->{activated
}->{$storeid};
904 $cache->{uevent_seqnum
} = uevent_seqnum
() if !$cache->{uevent_seqnum
};
906 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
909 my ($baseid, undef) = parse_volume_id
($scfg->{base
});
910 activate_storage
($cfg, $baseid, $cache);
913 if (!$plugin->check_connection($storeid, $scfg)) {
914 die "storage '$storeid' is not online\n";
917 $plugin->activate_storage($storeid, $scfg, $cache);
919 my $newseq = uevent_seqnum
();
921 # only call udevsettle if there are events
922 if ($newseq > $cache->{uevent_seqnum
}) {
924 system ("$UDEVADM settle --timeout=$timeout"); # ignore errors
925 $cache->{uevent_seqnum
} = $newseq;
928 $cache->{activated
}->{$storeid} = 1;
931 sub activate_storage_list
{
932 my ($cfg, $storeid_list, $cache) = @_;
934 $cache = {} if !$cache;
936 foreach my $storeid (@$storeid_list) {
937 activate_storage
($cfg, $storeid, $cache);
941 sub deactivate_storage
{
942 my ($cfg, $storeid) = @_;
944 my $scfg = storage_config
($cfg, $storeid);
945 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
948 $plugin->deactivate_storage($storeid, $scfg, $cache);
951 sub activate_volumes
{
952 my ($cfg, $vollist, $snapname) = @_;
954 return if !($vollist && scalar(@$vollist));
956 my $storagehash = {};
957 foreach my $volid (@$vollist) {
958 my ($storeid, undef) = parse_volume_id
($volid);
959 $storagehash->{$storeid} = 1;
964 activate_storage_list
($cfg, [keys %$storagehash], $cache);
966 foreach my $volid (@$vollist) {
967 my ($storeid, $volname) = parse_volume_id
($volid);
968 my $scfg = storage_config
($cfg, $storeid);
969 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
970 $plugin->activate_volume($storeid, $scfg, $volname, $snapname, $cache);
974 sub deactivate_volumes
{
975 my ($cfg, $vollist, $snapname) = @_;
977 return if !($vollist && scalar(@$vollist));
982 foreach my $volid (@$vollist) {
983 my ($storeid, $volname) = parse_volume_id
($volid);
985 my $scfg = storage_config
($cfg, $storeid);
986 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
989 $plugin->deactivate_volume($storeid, $scfg, $volname, $snapname, $cache);
993 push @errlist, $volid;
997 die "volume deactivation failed: " . join(' ', @errlist)
1002 my ($cfg, $content, $includeformat) = @_;
1004 my $ids = $cfg->{ids
};
1008 my @ctypes = PVE
::Tools
::split_list
($content);
1011 foreach my $storeid (keys %$ids) {
1012 my $storage_enabled = defined(storage_check_enabled
($cfg, $storeid, undef, 1));
1014 if (defined($content)) {
1016 foreach my $ctype (@ctypes) {
1017 if ($ids->{$storeid}->{content
}->{$ctype}) {
1022 next if !$want_ctype || !$storage_enabled;
1025 my $type = $ids->{$storeid}->{type
};
1027 $info->{$storeid} = {
1032 shared
=> $ids->{$storeid}->{shared
} ?
1 : 0,
1033 content
=> PVE
::Storage
::Plugin
::content_hash_to_string
($ids->{$storeid}->{content
}),
1035 enabled
=> $storage_enabled ?
1 : 0,
1038 push @$slist, $storeid;
1043 foreach my $storeid (keys %$ids) {
1044 my $scfg = $ids->{$storeid};
1046 next if !$info->{$storeid};
1047 next if !$info->{$storeid}->{enabled
};
1049 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1050 if ($includeformat) {
1051 my $pd = $plugin->plugindata();
1052 $info->{$storeid}->{format
} = $pd->{format
}
1054 $info->{$storeid}->{select_existing
} = $pd->{select_existing
}
1055 if $pd->{select_existing
};
1058 eval { activate_storage
($cfg, $storeid, $cache); };
1064 my ($total, $avail, $used, $active) = eval { $plugin->status($storeid, $scfg, $cache); };
1067 $info->{$storeid}->{total
} = int($total);
1068 $info->{$storeid}->{avail
} = int($avail);
1069 $info->{$storeid}->{used
} = int($used);
1070 $info->{$storeid}->{active
} = $active;
1079 my ($packed_ip, $family);
1081 my @res = PVE
::Tools
::getaddrinfo_all
($server);
1082 $family = $res[0]->{family
};
1083 $packed_ip = (PVE
::Tools
::unpack_sockaddr_in46
($res[0]->{addr
}))[2];
1085 if (defined $packed_ip) {
1086 return Socket
::inet_ntop
($family, $packed_ip);
1092 my ($server_in) = @_;
1095 if (!($server = resolv_server
($server_in))) {
1096 die "unable to resolve address for server '${server_in}'\n";
1099 my $cmd = ['/sbin/showmount', '--no-headers', '--exports', $server];
1102 run_command
($cmd, outfunc
=> sub {
1105 # note: howto handle white spaces in export path??
1106 if ($line =~ m!^(/\S+)\s+(.+)$!) {
1115 my ($server_in, $user, $password, $domain) = @_;
1118 if (!($server = resolv_server
($server_in))) {
1119 die "unable to resolve address for server '${server_in}'\n";
1122 # we support only Windows grater than 2012 cifsscan so use smb3
1123 my $cmd = ['/usr/bin/smbclient', '-m', 'smb3', '-d', '0', '-L', $server];
1124 if (defined($user)) {
1125 die "password is required" if !defined($password);
1126 push @$cmd, '-U', "$user\%$password";
1127 push @$cmd, '-W', $domain if defined($domain);
1136 if ($line =~ m/(\S+)\s*Disk\s*(\S*)/) {
1138 } elsif ($line =~ m/(NT_STATUS_(\S*))/) {
1151 my $cmd = ['zfs', 'list', '-t', 'filesystem', '-H', '-o', 'name,avail,used'];
1154 run_command
($cmd, outfunc
=> sub {
1157 if ($line =~m/^(\S+)\s+(\S+)\s+(\S+)$/) {
1158 my ($pool, $size_str, $used_str) = ($1, $2, $3);
1159 my $size = PVE
::Storage
::ZFSPoolPlugin
::zfs_parse_size
($size_str);
1160 my $used = PVE
::Storage
::ZFSPoolPlugin
::zfs_parse_size
($used_str);
1161 # ignore subvolumes generated by our ZFSPoolPlugin
1162 return if $pool =~ m!/subvol-\d+-[^/]+$!;
1163 return if $pool =~ m!/basevol-\d+-[^/]+$!;
1164 push @$res, { pool
=> $pool, size
=> $size, free
=> $size-$used };
1172 my ($portal, $noerr) = @_;
1174 my ($server, $port) = PVE
::Tools
::parse_host_and_port
($portal);
1176 if (my $ip = resolv_server
($server)) {
1178 $server = "[$server]" if $server =~ /^$IPV6RE$/;
1179 return $port ?
"$server:$port" : $server;
1182 return undef if $noerr;
1184 raise_param_exc
({ portal
=> "unable to resolve portal address '$portal'" });
1189 my ($portal_in) = @_;
1192 if (!($portal = resolv_portal
($portal_in))) {
1193 die "unable to parse/resolve portal address '${portal_in}'\n";
1196 return PVE
::Storage
::ISCSIPlugin
::iscsi_discovery
($portal);
1199 sub storage_default_format
{
1200 my ($cfg, $storeid) = @_;
1202 my $scfg = storage_config
($cfg, $storeid);
1204 return PVE
::Storage
::Plugin
::default_format
($scfg);
1207 sub vgroup_is_used
{
1208 my ($cfg, $vgname) = @_;
1210 foreach my $storeid (keys %{$cfg->{ids
}}) {
1211 my $scfg = storage_config
($cfg, $storeid);
1212 if ($scfg->{type
} eq 'lvm' && $scfg->{vgname
} eq $vgname) {
1220 sub target_is_used
{
1221 my ($cfg, $target) = @_;
1223 foreach my $storeid (keys %{$cfg->{ids
}}) {
1224 my $scfg = storage_config
($cfg, $storeid);
1225 if ($scfg->{type
} eq 'iscsi' && $scfg->{target
} eq $target) {
1233 sub volume_is_used
{
1234 my ($cfg, $volid) = @_;
1236 foreach my $storeid (keys %{$cfg->{ids
}}) {
1237 my $scfg = storage_config
($cfg, $storeid);
1238 if ($scfg->{base
} && $scfg->{base
} eq $volid) {
1246 sub storage_is_used
{
1247 my ($cfg, $storeid) = @_;
1249 foreach my $sid (keys %{$cfg->{ids
}}) {
1250 my $scfg = storage_config
($cfg, $sid);
1251 next if !$scfg->{base
};
1252 my ($st) = parse_volume_id
($scfg->{base
});
1253 return 1 if $st && $st eq $storeid;
1260 my ($list, $func) = @_;
1264 foreach my $sid (keys %$list) {
1265 foreach my $info (@{$list->{$sid}}) {
1266 my $volid = $info->{volid
};
1267 my ($sid1, $volname) = parse_volume_id
($volid, 1);
1268 if ($sid1 && $sid1 eq $sid) {
1269 &$func ($volid, $sid, $info);
1271 warn "detected strange volid '$volid' in volume list for '$sid'\n";
1277 sub extract_vzdump_config_tar
{
1278 my ($archive, $conf_re) = @_;
1280 die "ERROR: file '$archive' does not exist\n" if ! -f
$archive;
1282 my $pid = open(my $fh, '-|', 'tar', 'tf', $archive) ||
1283 die "unable to open file '$archive'\n";
1286 while (defined($file = <$fh>)) {
1287 if ($file =~ $conf_re) {
1288 $file = $1; # untaint
1297 die "ERROR: archive contains no configuration file\n" if !$file;
1303 $raw .= "$output\n";
1306 PVE
::Tools
::run_command
(['tar', '-xpOf', $archive, $file, '--occurrence'], outfunc
=> $out);
1308 return wantarray ?
($raw, $file) : $raw;
1311 sub extract_vzdump_config_vma
{
1312 my ($archive, $comp) = @_;
1318 $raw .= "$output\n";
1324 if ($comp eq 'gz') {
1325 $uncomp = ["zcat", $archive];
1326 } elsif ($comp eq 'lzo') {
1327 $uncomp = ["lzop", "-d", "-c", $archive];
1329 die "unknown compression method '$comp'\n";
1331 $cmd = [$uncomp, ["vma", "config", "-"]];
1333 # in some cases, lzop/zcat exits with 1 when its stdout pipe is
1334 # closed early by vma, detect this and ignore the exit code later
1339 if ($output =~ m/lzop: Broken pipe: <stdout>/ || $output =~ m/gzip: stdout: Broken pipe/) {
1341 } elsif (!defined ($errstring) && $output !~ m/^\s*$/) {
1342 $errstring = "Failed to extract config from VMA archive: $output\n";
1346 # in other cases, the pipeline will exit with exit code 141
1347 # because of the broken pipe, handle / ignore this as well
1350 $rc = PVE
::Tools
::run_command
($cmd, outfunc
=> $out, errfunc
=> $err, noerr
=> 1);
1354 # use exit code if no stderr output and not just broken pipe
1355 if (!$errstring && !$broken_pipe && $rc != 0 && $rc != 141) {
1356 die "$rerr\n" if $rerr;
1357 die "config extraction failed with exit code $rc\n";
1359 die "$errstring\n" if $errstring;
1361 # simple case without compression and weird piping behaviour
1362 PVE
::Tools
::run_command
(["vma", "config", $archive], outfunc
=> $out);
1365 return wantarray ?
($raw, undef) : $raw;
1368 sub extract_vzdump_config
{
1369 my ($cfg, $volid) = @_;
1371 my $archive = abs_filesystem_path
($cfg, $volid);
1373 if ($volid =~ /vzdump-(lxc|openvz)-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?))$/) {
1374 return extract_vzdump_config_tar
($archive, qr!^(\./etc/vzdump/(pct|vps)\.conf)$!);
1375 } elsif ($volid =~ /vzdump-qemu-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(gz|lzo))?))$/) {
1383 $comp = $11 if defined($11);
1386 if ($format eq 'tar') {
1387 return extract_vzdump_config_tar
($archive, qr!\(\./qemu-server\.conf\)!);
1389 return extract_vzdump_config_vma
($archive, $comp);
1392 die "cannot determine backup guest type for backup archive '$volid'\n";
1397 my ($cfg, $fh, $volid, $format, $snapshot, $base_snapshot, $with_snapshots) = @_;
1399 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1400 die "cannot export volume '$volid'\n" if !$storeid;
1401 my $scfg = storage_config
($cfg, $storeid);
1402 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1403 return $plugin->volume_export($scfg, $storeid, $fh, $volname, $format,
1404 $snapshot, $base_snapshot, $with_snapshots);
1408 my ($cfg, $fh, $volid, $format, $base_snapshot, $with_snapshots) = @_;
1410 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1411 die "cannot import into volume '$volid'\n" if !$storeid;
1412 my $scfg = storage_config
($cfg, $storeid);
1413 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1414 return $plugin->volume_import($scfg, $storeid, $fh, $volname, $format,
1415 $base_snapshot, $with_snapshots);
1418 sub volume_export_formats
{
1419 my ($cfg, $volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
1421 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1422 return if !$storeid;
1423 my $scfg = storage_config
($cfg, $storeid);
1424 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1425 return $plugin->volume_export_formats($scfg, $storeid, $volname,
1426 $snapshot, $base_snapshot,
1430 sub volume_import_formats
{
1431 my ($cfg, $volid, $base_snapshot, $with_snapshots) = @_;
1433 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1434 return if !$storeid;
1435 my $scfg = storage_config
($cfg, $storeid);
1436 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1437 return $plugin->volume_import_formats($scfg, $storeid, $volname,
1438 $base_snapshot, $with_snapshots);
1441 sub volume_transfer_formats
{
1442 my ($cfg, $src_volid, $dst_volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
1443 my @export_formats = volume_export_formats
($cfg, $src_volid, $snapshot, $base_snapshot, $with_snapshots);
1444 my @import_formats = volume_import_formats
($cfg, $dst_volid, $base_snapshot, $with_snapshots);
1445 my %import_hash = map { $_ => 1 } @import_formats;
1446 my @common = grep { $import_hash{$_} } @export_formats;
1450 # bash completion helper
1452 sub complete_storage
{
1453 my ($cmdname, $pname, $cvalue) = @_;
1455 my $cfg = PVE
::Storage
::config
();
1457 return $cmdname eq 'add' ?
[] : [ PVE
::Storage
::storage_ids
($cfg) ];
1460 sub complete_storage_enabled
{
1461 my ($cmdname, $pname, $cvalue) = @_;
1465 my $cfg = PVE
::Storage
::config
();
1466 foreach my $sid (keys %{$cfg->{ids
}}) {
1467 next if !storage_check_enabled
($cfg, $sid, undef, 1);
1473 sub complete_content_type
{
1474 my ($cmdname, $pname, $cvalue) = @_;
1476 return [qw(rootdir images vztmpl iso backup snippets)];
1479 sub complete_volume
{
1480 my ($cmdname, $pname, $cvalue) = @_;
1484 my $storage_list = complete_storage_enabled
();
1486 if ($cvalue =~ m/^([^:]+):/) {
1487 $storage_list = [ $1 ];
1489 if (scalar(@$storage_list) > 1) {
1490 # only list storage IDs to avoid large listings
1492 foreach my $storeid (@$storage_list) {
1493 # Hack: simply return 2 artificial values, so that
1494 # completions does not finish
1495 push @$res, "$storeid:volname", "$storeid:...";
1502 foreach my $storeid (@$storage_list) {
1503 my $vollist = PVE
::Storage
::volume_list
($cfg, $storeid);
1505 foreach my $item (@$vollist) {
1506 push @$res, $item->{volid
};
1513 # Various io-heavy operations require io/bandwidth limits which can be
1514 # configured on multiple levels: The global defaults in datacenter.cfg, and
1515 # per-storage overrides. When we want to do a restore from storage A to storage
1516 # B, we should take the smaller limit defined for storages A and B, and if no
1517 # such limit was specified, use the one from datacenter.cfg.
1518 sub get_bandwidth_limit
{
1519 my ($operation, $storage_list, $override) = @_;
1521 # called for each limit (global, per-storage) with the 'default' and the
1522 # $operation limit and should udpate $override for every limit affecting
1524 my $use_global_limits = 0;
1525 my $apply_limit = sub {
1527 if (defined($bwlimit)) {
1528 my $limits = PVE
::JSONSchema
::parse_property_string
('bwlimit', $bwlimit);
1529 my $limit = $limits->{$operation} // $limits->{default};
1530 if (defined($limit)) {
1531 if (!$override || $limit < $override) {
1537 # If there was no applicable limit, try to apply the global ones.
1538 $use_global_limits = 1;
1541 my ($rpcenv, $authuser);
1542 if (defined($override)) {
1543 $rpcenv = PVE
::RPCEnvironment-
>get();
1544 $authuser = $rpcenv->get_user();
1547 # Apply per-storage limits - if there are storages involved.
1548 if (defined($storage_list) && @$storage_list) {
1549 my $config = config
();
1551 # The Datastore.Allocate permission allows us to modify the per-storage
1552 # limits, therefore it also allows us to override them.
1553 # Since we have most likely multiple storages to check, do a quick check on
1554 # the general '/storage' path to see if we can skip the checks entirely:
1555 return $override if $rpcenv && $rpcenv->check($authuser, '/storage', ['Datastore.Allocate'], 1);
1558 foreach my $storage (@$storage_list) {
1559 next if !defined($storage);
1560 # Avoid duplicate checks:
1561 next if $done{$storage};
1562 $done{$storage} = 1;
1564 # Otherwise we may still have individual /storage/$ID permissions:
1565 if (!$rpcenv || !$rpcenv->check($authuser, "/storage/$storage", ['Datastore.Allocate'], 1)) {
1566 # And if not: apply the limits.
1567 my $storecfg = storage_config
($config, $storage);
1568 $apply_limit->($storecfg->{bwlimit
});
1572 # Storage limits take precedence over the datacenter defaults, so if
1573 # a limit was applied:
1574 return $override if !$use_global_limits;
1577 # Sys.Modify on '/' means we can change datacenter.cfg which contains the
1578 # global default limits.
1579 if (!$rpcenv || !$rpcenv->check($authuser, '/', ['Sys.Modify'], 1)) {
1580 # So if we cannot modify global limits, apply them to our currently
1581 # requested override.
1582 my $dc = cfs_read_file
('datacenter.cfg');
1583 $apply_limit->($dc->{bwlimit
});
1589 # checks if the storage id is available and dies if not
1590 sub assert_sid_unused
{
1594 if (my $scfg = storage_config
($cfg, $sid, 1)) {
1595 die "storage ID '$sid' already defined\n";