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
;
39 use PVE
::Storage
::PBSPlugin
;
41 # Storage API version. Icrement it on changes in storage API interface.
42 use constant APIVER
=> 3;
43 # Age is the number of versions we're backward compatible with.
44 # This is like having 'current=APIVER' and age='APIAGE' in libtool,
45 # see https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
46 use constant APIAGE
=> 2;
48 # load standard plugins
49 PVE
::Storage
::DirPlugin-
>register();
50 PVE
::Storage
::LVMPlugin-
>register();
51 PVE
::Storage
::LvmThinPlugin-
>register();
52 PVE
::Storage
::NFSPlugin-
>register();
53 PVE
::Storage
::CIFSPlugin-
>register();
54 PVE
::Storage
::ISCSIPlugin-
>register();
55 PVE
::Storage
::RBDPlugin-
>register();
56 PVE
::Storage
::CephFSPlugin-
>register();
57 PVE
::Storage
::ISCSIDirectPlugin-
>register();
58 PVE
::Storage
::GlusterfsPlugin-
>register();
59 PVE
::Storage
::ZFSPoolPlugin-
>register();
60 PVE
::Storage
::ZFSPlugin-
>register();
61 PVE
::Storage
::DRBDPlugin-
>register();
62 PVE
::Storage
::PBSPlugin-
>register();
64 # load third-party plugins
65 if ( -d
'/usr/share/perl5/PVE/Storage/Custom' ) {
66 dir_glob_foreach
('/usr/share/perl5/PVE/Storage/Custom', '.*\.pm$', sub {
68 my $modname = 'PVE::Storage::Custom::' . $file;
69 $modname =~ s!\.pm$!!;
70 $file = 'PVE/Storage/Custom/' . $file;
75 # Check perl interface:
76 die "not derived from PVE::Storage::Plugin\n"
77 if !$modname->isa('PVE::Storage::Plugin');
78 die "does not provide an api() method\n"
79 if !$modname->can('api');
80 # Check storage API version and that file is really storage plugin.
81 my $version = $modname->api();
82 die "implements an API version newer than current ($version > " . APIVER
. ")\n"
84 my $min_version = (APIVER
- APIAGE
);
85 die "API version too old, please update the plugin ($version < $min_version)\n"
86 if $version < $min_version;
90 # If we got this far and the API version is not the same, make some
92 warn "Plugin \"$modname\" is implementing an older storage API
, an upgrade
is recommended
\n"
93 if $version != APIVER;
96 warn "Error loading storage plugin
\"$modname\": $@";
101 # initialize all plugins
102 PVE
::Storage
::Plugin-
>init();
104 my $UDEVADM = '/sbin/udevadm';
106 our $iso_extension_re = qr/\.(?:iso|img)/i;
108 # PVE::Storage utility functions
111 return cfs_read_file
("storage.cfg");
117 cfs_write_file
('storage.cfg', $cfg);
120 sub lock_storage_config
{
121 my ($code, $errmsg) = @_;
123 cfs_lock_file
("storage.cfg", undef, $code);
126 $errmsg ?
die "$errmsg: $err" : die $err;
131 my ($cfg, $storeid, $noerr) = @_;
133 die "no storage ID specified\n" if !$storeid;
135 my $scfg = $cfg->{ids
}->{$storeid};
137 die "storage '$storeid' does not exist\n" if (!$noerr && !$scfg);
142 sub storage_check_node
{
143 my ($cfg, $storeid, $node, $noerr) = @_;
145 my $scfg = storage_config
($cfg, $storeid);
147 if ($scfg->{nodes
}) {
148 $node = PVE
::INotify
::nodename
() if !$node || ($node eq 'localhost');
149 if (!$scfg->{nodes
}->{$node}) {
150 die "storage '$storeid' is not available on node '$node'\n" if !$noerr;
158 sub storage_check_enabled
{
159 my ($cfg, $storeid, $node, $noerr) = @_;
161 my $scfg = storage_config
($cfg, $storeid);
163 if ($scfg->{disable
}) {
164 die "storage '$storeid' is disabled\n" if !$noerr;
168 return storage_check_node
($cfg, $storeid, $node, $noerr);
171 # storage_can_replicate:
172 # return true if storage supports replication
173 # (volumes alocated with vdisk_alloc() has replication feature)
174 sub storage_can_replicate
{
175 my ($cfg, $storeid, $format) = @_;
177 my $scfg = storage_config
($cfg, $storeid);
178 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
179 return $plugin->storage_can_replicate($scfg, $storeid, $format);
185 return keys %{$cfg->{ids
}};
189 my ($filename, $timeout) = @_;
191 return PVE
::Storage
::Plugin
::file_size_info
($filename, $timeout);
194 sub volume_size_info
{
195 my ($cfg, $volid, $timeout) = @_;
197 my ($storeid, $volname) = parse_volume_id
($volid, 1);
199 my $scfg = storage_config
($cfg, $storeid);
200 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
201 return $plugin->volume_size_info($scfg, $storeid, $volname, $timeout);
202 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
203 return file_size_info
($volid, $timeout);
210 my ($cfg, $volid, $size, $running) = @_;
212 my ($storeid, $volname) = parse_volume_id
($volid, 1);
214 my $scfg = storage_config
($cfg, $storeid);
215 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
216 return $plugin->volume_resize($scfg, $storeid, $volname, $size, $running);
217 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
218 die "resize file/device '$volid' is not possible\n";
220 die "unable to parse volume ID '$volid'\n";
224 sub volume_rollback_is_possible
{
225 my ($cfg, $volid, $snap) = @_;
227 my ($storeid, $volname) = parse_volume_id
($volid, 1);
229 my $scfg = storage_config
($cfg, $storeid);
230 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
231 return $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
232 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
233 die "snapshot rollback file/device '$volid' is not possible\n";
235 die "unable to parse volume ID '$volid'\n";
239 sub volume_snapshot
{
240 my ($cfg, $volid, $snap) = @_;
242 my ($storeid, $volname) = parse_volume_id
($volid, 1);
244 my $scfg = storage_config
($cfg, $storeid);
245 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
246 return $plugin->volume_snapshot($scfg, $storeid, $volname, $snap);
247 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
248 die "snapshot file/device '$volid' is not possible\n";
250 die "unable to parse volume ID '$volid'\n";
254 sub volume_snapshot_rollback
{
255 my ($cfg, $volid, $snap) = @_;
257 my ($storeid, $volname) = parse_volume_id
($volid, 1);
259 my $scfg = storage_config
($cfg, $storeid);
260 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
261 $plugin->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
262 return $plugin->volume_snapshot_rollback($scfg, $storeid, $volname, $snap);
263 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
264 die "snapshot rollback file/device '$volid' is not possible\n";
266 die "unable to parse volume ID '$volid'\n";
270 sub volume_snapshot_delete
{
271 my ($cfg, $volid, $snap, $running) = @_;
273 my ($storeid, $volname) = parse_volume_id
($volid, 1);
275 my $scfg = storage_config
($cfg, $storeid);
276 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
277 return $plugin->volume_snapshot_delete($scfg, $storeid, $volname, $snap, $running);
278 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
279 die "snapshot delete file/device '$volid' is not possible\n";
281 die "unable to parse volume ID '$volid'\n";
285 sub volume_has_feature
{
286 my ($cfg, $feature, $volid, $snap, $running) = @_;
288 my ($storeid, $volname) = parse_volume_id
($volid, 1);
290 my $scfg = storage_config
($cfg, $storeid);
291 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
292 return $plugin->volume_has_feature($scfg, $feature, $storeid, $volname, $snap, $running);
293 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
300 sub volume_snapshot_list
{
301 my ($cfg, $volid) = @_;
303 my ($storeid, $volname) = parse_volume_id
($volid, 1);
305 my $scfg = storage_config
($cfg, $storeid);
306 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
307 return $plugin->volume_snapshot_list($scfg, $storeid, $volname);
308 } elsif ($volid =~ m
|^(/.+)$| && -e
$volid) {
309 die "send file/device '$volid' is not possible\n";
311 die "unable to parse volume ID '$volid'\n";
313 # return an empty array if dataset does not exist.
317 my ($cfg, $storeid, $vmid) = @_;
319 my $scfg = storage_config
($cfg, $storeid);
320 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
322 my $path = $plugin->get_subdir($scfg, 'images');
324 return $vmid ?
"$path/$vmid" : $path;
327 sub get_private_dir
{
328 my ($cfg, $storeid, $vmid) = @_;
330 my $scfg = storage_config
($cfg, $storeid);
331 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
333 my $path = $plugin->get_subdir($scfg, 'rootdir');
335 return $vmid ?
"$path/$vmid" : $path;
339 my ($cfg, $storeid) = @_;
341 my $scfg = storage_config
($cfg, $storeid);
342 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
344 return $plugin->get_subdir($scfg, 'iso');
348 my ($cfg, $storeid) = @_;
350 my $scfg = storage_config
($cfg, $storeid);
351 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
353 return $plugin->get_subdir($scfg, 'vztmpl');
357 my ($cfg, $storeid) = @_;
359 my $scfg = storage_config
($cfg, $storeid);
360 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
362 return $plugin->get_subdir($scfg, 'backup');
365 # library implementation
370 die "VMID '$vmid' contains illegal characters\n" if $vmid !~ m/^\d+$/;
375 # NOTE: basename and basevmid are always undef for LVM-thin, where the
376 # clone -> base reference is not encoded in the volume ID.
377 # see note in PVE::Storage::LvmThinPlugin for details.
379 my ($cfg, $volid) = @_;
381 my ($storeid, $volname) = parse_volume_id
($volid);
383 my $scfg = storage_config
($cfg, $storeid);
385 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
387 # returns ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format)
389 return $plugin->parse_volname($volname);
392 sub parse_volume_id
{
393 my ($volid, $noerr) = @_;
395 return PVE
::Storage
::Plugin
::parse_volume_id
($volid, $noerr);
398 # test if we have read access to volid
399 sub check_volume_access
{
400 my ($rpcenv, $user, $cfg, $vmid, $volid) = @_;
402 my ($sid, $volname) = parse_volume_id
($volid, 1);
404 my ($vtype, undef, $ownervm) = parse_volname
($cfg, $volid);
405 if ($vtype eq 'iso' || $vtype eq 'vztmpl') {
406 # require at least read access to storage, (custom) templates/ISOs could be sensitive
407 $rpcenv->check_any($user, "/storage/$sid", ['Datastore.AllocateSpace', 'Datastore.Audit']);
408 } elsif (defined($ownervm) && defined($vmid) && ($ownervm == $vmid)) {
409 # we are owner - allow access
410 } elsif ($vtype eq 'backup' && $ownervm) {
411 $rpcenv->check($user, "/storage/$sid", ['Datastore.AllocateSpace']);
412 $rpcenv->check($user, "/vms/$ownervm", ['VM.Backup']);
414 # allow if we are Datastore administrator
415 $rpcenv->check($user, "/storage/$sid", ['Datastore.Allocate']);
418 die "Only root can pass arbitrary filesystem paths."
419 if $user ne 'root@pam';
425 my $volume_is_base_and_used__no_lock = sub {
426 my ($scfg, $storeid, $plugin, $volname) = @_;
428 my ($vtype, $name, $vmid, undef, undef, $isBase, undef) =
429 $plugin->parse_volname($volname);
432 my $vollist = $plugin->list_images($storeid, $scfg);
433 foreach my $info (@$vollist) {
434 my (undef, $tmpvolname) = parse_volume_id
($info->{volid
});
435 my $basename = undef;
436 my $basevmid = undef;
439 (undef, undef, undef, $basename, $basevmid) =
440 $plugin->parse_volname($tmpvolname);
443 if ($basename && defined($basevmid) && $basevmid == $vmid && $basename eq $name) {
451 # NOTE: this check does not work for LVM-thin, where the clone -> base
452 # reference is not encoded in the volume ID.
453 # see note in PVE::Storage::LvmThinPlugin for details.
454 sub volume_is_base_and_used
{
455 my ($cfg, $volid) = @_;
457 my ($storeid, $volname) = parse_volume_id
($volid);
458 my $scfg = storage_config
($cfg, $storeid);
459 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
461 $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
462 return &$volume_is_base_and_used__no_lock($scfg, $storeid, $plugin, $volname);
466 # try to map a filesystem path to a volume identifier
467 sub path_to_volume_id
{
468 my ($cfg, $path) = @_;
470 my $ids = $cfg->{ids
};
472 my ($sid, $volname) = parse_volume_id
($path, 1);
474 if (my $scfg = $ids->{$sid}) {
476 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
477 my ($vtype, $name, $vmid) = $plugin->parse_volname($volname);
478 return ($vtype, $path);
484 # Note: abs_path() return undef if $path doesn not exist
485 # for example when nfs storage is not mounted
486 $path = abs_path
($path) || $path;
488 foreach my $sid (keys %$ids) {
489 my $scfg = $ids->{$sid};
490 next if !$scfg->{path
};
491 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
492 my $imagedir = $plugin->get_subdir($scfg, 'images');
493 my $isodir = $plugin->get_subdir($scfg, 'iso');
494 my $tmpldir = $plugin->get_subdir($scfg, 'vztmpl');
495 my $backupdir = $plugin->get_subdir($scfg, 'backup');
496 my $privatedir = $plugin->get_subdir($scfg, 'rootdir');
498 if ($path =~ m!^$imagedir/(\d+)/([^/\s]+)$!) {
502 my $vollist = $plugin->list_images($sid, $scfg, $vmid);
503 foreach my $info (@$vollist) {
504 my ($storeid, $volname) = parse_volume_id
($info->{volid
});
505 my $volpath = $plugin->path($scfg, $volname, $storeid);
506 if ($volpath eq $path) {
507 return ('images', $info->{volid
});
510 } elsif ($path =~ m!^$isodir/([^/]+$iso_extension_re)$!) {
512 return ('iso', "$sid:iso/$name");
513 } elsif ($path =~ m!^$tmpldir/([^/]+\.tar\.gz)$!) {
515 return ('vztmpl', "$sid:vztmpl/$name");
516 } elsif ($path =~ m!^$privatedir/(\d+)$!) {
518 return ('rootdir', "$sid:rootdir/$vmid");
519 } elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!) {
521 return ('iso', "$sid:backup/$name");
525 # can't map path to volume id
530 my ($cfg, $volid, $snapname) = @_;
532 my ($storeid, $volname) = parse_volume_id
($volid);
534 my $scfg = storage_config
($cfg, $storeid);
536 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
537 my ($path, $owner, $vtype) = $plugin->path($scfg, $volname, $storeid, $snapname);
538 return wantarray ?
($path, $owner, $vtype) : $path;
541 sub abs_filesystem_path
{
542 my ($cfg, $volid) = @_;
545 if (parse_volume_id
($volid, 1)) {
546 activate_volumes
($cfg, [ $volid ]);
547 $path = PVE
::Storage
::path
($cfg, $volid);
550 my $abspath = abs_path
($volid);
551 if ($abspath && $abspath =~ m
|^(/.+)$|) {
552 $path = $1; # untaint any path
557 die "can't find file '$volid'\n" if !($path && -f
$path);
562 sub storage_migrate
{
563 my ($cfg, $volid, $target_sshinfo, $target_storeid, $target_volname, $base_snapshot, $snapshot, $ratelimit_bps, $insecure, $with_snapshots, $logfunc) = @_;
565 my ($storeid, $volname) = parse_volume_id
($volid);
566 $target_volname = $volname if !$target_volname;
568 my $scfg = storage_config
($cfg, $storeid);
570 # no need to migrate shared content
571 return if $storeid eq $target_storeid && $scfg->{shared
};
573 my $tcfg = storage_config
($cfg, $target_storeid);
575 my $target_volid = "${target_storeid}:${target_volname}";
577 my $target_ip = $target_sshinfo->{ip
};
579 my $ssh = PVE
::SSHInfo
::ssh_info_to_command
($target_sshinfo);
580 my $ssh_base = PVE
::SSHInfo
::ssh_info_to_command_base
($target_sshinfo);
581 local $ENV{RSYNC_RSH
} = PVE
::Tools
::cmd2string
($ssh_base);
583 my @cstream = ([ '/usr/bin/cstream', '-t', $ratelimit_bps ])
584 if defined($ratelimit_bps);
586 my $migration_snapshot;
587 if (!defined($snapshot)) {
588 if ($scfg->{type
} eq 'zfspool') {
589 $migration_snapshot = 1;
590 $snapshot = '__migration__';
594 my @formats = volume_transfer_formats
($cfg, $volid, $target_volid, $snapshot, $base_snapshot, $with_snapshots);
595 die "cannot migrate from storage type '$scfg->{type}' to '$tcfg->{type}'\n" if !@formats;
596 my $format = $formats[0];
598 my $import_fn = '-'; # let pvesm import read from stdin per default
600 my $net = $target_sshinfo->{network
} // $target_sshinfo->{ip
};
601 $import_fn = "tcp://$net";
604 $with_snapshots = $with_snapshots ?
1 : 0; # sanitize for passing as cli parameter
605 my $send = ['pvesm', 'export', $volid, $format, '-', '-with-snapshots', $with_snapshots];
606 my $recv = [@$ssh, '--', 'pvesm', 'import', $target_volid, $format, $import_fn, '-with-snapshots', $with_snapshots];
607 if (defined($snapshot)) {
608 push @$send, '-snapshot', $snapshot
610 if ($migration_snapshot) {
611 push @$recv, '-delete-snapshot', $snapshot;
614 if (defined($base_snapshot)) {
615 # Check if the snapshot exists on the remote side:
616 push @$send, '-base', $base_snapshot;
617 push @$recv, '-base', $base_snapshot;
620 volume_snapshot
($cfg, $volid, $snapshot) if $migration_snapshot;
623 open(my $info, '-|', @$recv)
624 or die "receive command failed: $!\n";
625 my ($ip) = <$info> =~ /^($PVE::Tools::IPRE)$/ or die "no tunnel IP received\n";
626 my ($port) = <$info> =~ /^(\d+)$/ or die "no tunnel port received\n";
627 my $socket = IO
::Socket
::IP-
>new(PeerHost
=> $ip, PeerPort
=> $port, Type
=> SOCK_STREAM
)
628 or die "failed to connect to tunnel at $ip:$port\n";
629 # we won't be reading from the socket
630 shutdown($socket, 0);
631 run_command
([$send, @cstream], output
=> '>&'.fileno($socket), errfunc
=> $logfunc);
632 # don't close the connection entirely otherwise the receiving end
633 # might not get all buffered data (and fails with 'connection reset by peer')
634 shutdown($socket, 1);
636 # wait for the remote process to finish
638 while (my $line = <$info>) {
640 $logfunc->("[$target_sshinfo->{name}] $line");
646 # now close the socket
648 if (!close($info)) { # does waitpid()
649 die "import failed: $!\n" if $!;
650 die "import failed: exit code ".($?>>8)."\n";
653 run_command
([$send, @cstream, $recv], logfunc
=> $logfunc);
657 warn "send/receive failed, cleaning up snapshot(s)..\n" if $err;
658 if ($migration_snapshot) {
659 eval { volume_snapshot_delete
($cfg, $volid, $snapshot, 0) };
660 warn "could not remove source snapshot: $@\n" if $@;
666 my ($cfg, $volid, $vmid, $snap) = @_;
668 my ($storeid, $volname) = parse_volume_id
($volid);
670 my $scfg = storage_config
($cfg, $storeid);
672 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
674 activate_storage
($cfg, $storeid);
676 # lock shared storage
677 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
678 my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid, $snap);
679 return "$storeid:$volname";
683 sub vdisk_create_base
{
684 my ($cfg, $volid) = @_;
686 my ($storeid, $volname) = parse_volume_id
($volid);
688 my $scfg = storage_config
($cfg, $storeid);
690 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
692 activate_storage
($cfg, $storeid);
694 # lock shared storage
695 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
696 my $volname = $plugin->create_base($storeid, $scfg, $volname);
697 return "$storeid:$volname";
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->map_volume($storeid, $scfg, $volname, $snapname);
714 my ($cfg, $volid, $snapname) = @_;
716 my ($storeid, $volname) = parse_volume_id
($volid);
718 my $scfg = storage_config
($cfg, $storeid);
720 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
722 return $plugin->unmap_volume($storeid, $scfg, $volname, $snapname);
726 my ($cfg, $storeid, $vmid, $fmt, $name, $size) = @_;
728 die "no storage ID specified\n" if !$storeid;
730 PVE
::JSONSchema
::parse_storage_id
($storeid);
732 my $scfg = storage_config
($cfg, $storeid);
734 die "no VMID specified\n" if !$vmid;
736 $vmid = parse_vmid
($vmid);
738 my $defformat = PVE
::Storage
::Plugin
::default_format
($scfg);
740 $fmt = $defformat if !$fmt;
742 activate_storage
($cfg, $storeid);
744 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
746 # lock shared storage
747 return $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
748 my $old_umask = umask(umask|0037);
749 my $volname = eval { $plugin->alloc_image($storeid, $scfg, $vmid, $fmt, $name, $size) };
753 return "$storeid:$volname";
758 my ($cfg, $volid) = @_;
760 my ($storeid, $volname) = parse_volume_id
($volid);
761 my $scfg = storage_config
($cfg, $storeid);
762 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
764 activate_storage
($cfg, $storeid);
768 # lock shared storage
769 $plugin->cluster_lock_storage($storeid, $scfg->{shared
}, undef, sub {
770 # LVM-thin allows deletion of still referenced base volumes!
771 die "base volume '$volname' is still in use by linked clones\n"
772 if &$volume_is_base_and_used__no_lock($scfg, $storeid, $plugin, $volname);
774 my (undef, undef, undef, undef, undef, $isBase, $format) =
775 $plugin->parse_volname($volname);
776 $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname, $isBase, $format);
779 return if !$cleanup_worker;
781 my $rpcenv = PVE
::RPCEnvironment
::get
();
782 my $authuser = $rpcenv->get_user();
784 $rpcenv->fork_worker('imgdel', undef, $authuser, $cleanup_worker);
788 my ($cfg, $storeid, $vmid, $vollist) = @_;
790 my $ids = $cfg->{ids
};
792 storage_check_enabled
($cfg, $storeid) if ($storeid);
796 # prepare/activate/refresh all storages
798 my $storage_list = [];
800 foreach my $volid (@$vollist) {
801 my ($sid, undef) = parse_volume_id
($volid);
802 next if !defined($ids->{$sid});
803 next if !storage_check_enabled
($cfg, $sid, undef, 1);
804 push @$storage_list, $sid;
807 foreach my $sid (keys %$ids) {
808 next if $storeid && $storeid ne $sid;
809 next if !storage_check_enabled
($cfg, $sid, undef, 1);
810 push @$storage_list, $sid;
816 activate_storage_list
($cfg, $storage_list, $cache);
818 foreach my $sid (keys %$ids) {
819 next if $storeid && $storeid ne $sid;
820 next if !storage_check_enabled
($cfg, $sid, undef, 1);
822 my $scfg = $ids->{$sid};
823 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
824 $res->{$sid} = $plugin->list_images($sid, $scfg, $vmid, $vollist, $cache);
825 @{$res->{$sid}} = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @{$res->{$sid}} if $res->{$sid};
832 my ($cfg, $storeid, $tt) = @_;
834 die "unknown template type '$tt'\n"
835 if !($tt eq 'iso' || $tt eq 'vztmpl' || $tt eq 'backup' || $tt eq 'snippets');
837 my $ids = $cfg->{ids
};
839 storage_check_enabled
($cfg, $storeid) if ($storeid);
844 foreach my $sid (keys %$ids) {
845 next if $storeid && $storeid ne $sid;
847 my $scfg = $ids->{$sid};
848 my $type = $scfg->{type
};
850 next if !$scfg->{content
}->{$tt};
852 next if !storage_check_enabled
($cfg, $sid, undef, 1);
854 $res->{$sid} = volume_list
($cfg, $sid, undef, $tt);
861 my ($cfg, $storeid, $vmid, $content) = @_;
863 my @ctypes = qw(rootdir images vztmpl iso backup snippets);
865 my $cts = $content ?
[ $content ] : [ @ctypes ];
867 my $scfg = PVE
::Storage
::storage_config
($cfg, $storeid);
869 $cts = [ grep { defined($scfg->{content
}->{$_}) } @$cts ];
871 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
873 activate_storage
($cfg, $storeid);
875 my $res = $plugin->list_volumes($storeid, $scfg, $vmid, $cts);
877 @$res = sort {lc($a->{volid
}) cmp lc ($b->{volid
}) } @$res;
884 my $filename = "/sys/kernel/uevent_seqnum";
887 if (my $fh = IO
::File-
>new($filename, "r")) {
889 if ($line =~ m/^(\d+)$/) {
897 sub activate_storage
{
898 my ($cfg, $storeid, $cache) = @_;
900 $cache = {} if !$cache;
902 my $scfg = storage_check_enabled
($cfg, $storeid);
904 return if $cache->{activated
}->{$storeid};
906 $cache->{uevent_seqnum
} = uevent_seqnum
() if !$cache->{uevent_seqnum
};
908 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
911 my ($baseid, undef) = parse_volume_id
($scfg->{base
});
912 activate_storage
($cfg, $baseid, $cache);
915 if (!$plugin->check_connection($storeid, $scfg)) {
916 die "storage '$storeid' is not online\n";
919 $plugin->activate_storage($storeid, $scfg, $cache);
921 my $newseq = uevent_seqnum
();
923 # only call udevsettle if there are events
924 if ($newseq > $cache->{uevent_seqnum
}) {
926 system ("$UDEVADM settle --timeout=$timeout"); # ignore errors
927 $cache->{uevent_seqnum
} = $newseq;
930 $cache->{activated
}->{$storeid} = 1;
933 sub activate_storage_list
{
934 my ($cfg, $storeid_list, $cache) = @_;
936 $cache = {} if !$cache;
938 foreach my $storeid (@$storeid_list) {
939 activate_storage
($cfg, $storeid, $cache);
943 sub deactivate_storage
{
944 my ($cfg, $storeid) = @_;
946 my $scfg = storage_config
($cfg, $storeid);
947 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
950 $plugin->deactivate_storage($storeid, $scfg, $cache);
953 sub activate_volumes
{
954 my ($cfg, $vollist, $snapname) = @_;
956 return if !($vollist && scalar(@$vollist));
958 my $storagehash = {};
959 foreach my $volid (@$vollist) {
960 my ($storeid, undef) = parse_volume_id
($volid);
961 $storagehash->{$storeid} = 1;
966 activate_storage_list
($cfg, [keys %$storagehash], $cache);
968 foreach my $volid (@$vollist) {
969 my ($storeid, $volname) = parse_volume_id
($volid);
970 my $scfg = storage_config
($cfg, $storeid);
971 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
972 $plugin->activate_volume($storeid, $scfg, $volname, $snapname, $cache);
976 sub deactivate_volumes
{
977 my ($cfg, $vollist, $snapname) = @_;
979 return if !($vollist && scalar(@$vollist));
984 foreach my $volid (@$vollist) {
985 my ($storeid, $volname) = parse_volume_id
($volid);
987 my $scfg = storage_config
($cfg, $storeid);
988 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
991 $plugin->deactivate_volume($storeid, $scfg, $volname, $snapname, $cache);
995 push @errlist, $volid;
999 die "volume deactivation failed: " . join(' ', @errlist)
1000 if scalar(@errlist);
1004 my ($cfg, $content, $includeformat) = @_;
1006 my $ids = $cfg->{ids
};
1010 my @ctypes = PVE
::Tools
::split_list
($content);
1013 foreach my $storeid (keys %$ids) {
1014 my $storage_enabled = defined(storage_check_enabled
($cfg, $storeid, undef, 1));
1016 if (defined($content)) {
1018 foreach my $ctype (@ctypes) {
1019 if ($ids->{$storeid}->{content
}->{$ctype}) {
1024 next if !$want_ctype || !$storage_enabled;
1027 my $type = $ids->{$storeid}->{type
};
1029 $info->{$storeid} = {
1034 shared
=> $ids->{$storeid}->{shared
} ?
1 : 0,
1035 content
=> PVE
::Storage
::Plugin
::content_hash_to_string
($ids->{$storeid}->{content
}),
1037 enabled
=> $storage_enabled ?
1 : 0,
1040 push @$slist, $storeid;
1045 foreach my $storeid (keys %$ids) {
1046 my $scfg = $ids->{$storeid};
1048 next if !$info->{$storeid};
1049 next if !$info->{$storeid}->{enabled
};
1051 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1052 if ($includeformat) {
1053 my $pd = $plugin->plugindata();
1054 $info->{$storeid}->{format
} = $pd->{format
}
1056 $info->{$storeid}->{select_existing
} = $pd->{select_existing
}
1057 if $pd->{select_existing
};
1060 eval { activate_storage
($cfg, $storeid, $cache); };
1066 my ($total, $avail, $used, $active) = eval { $plugin->status($storeid, $scfg, $cache); };
1069 $info->{$storeid}->{total
} = int($total);
1070 $info->{$storeid}->{avail
} = int($avail);
1071 $info->{$storeid}->{used
} = int($used);
1072 $info->{$storeid}->{active
} = $active;
1081 my ($packed_ip, $family);
1083 my @res = PVE
::Tools
::getaddrinfo_all
($server);
1084 $family = $res[0]->{family
};
1085 $packed_ip = (PVE
::Tools
::unpack_sockaddr_in46
($res[0]->{addr
}))[2];
1087 if (defined $packed_ip) {
1088 return Socket
::inet_ntop
($family, $packed_ip);
1094 my ($server_in) = @_;
1097 if (!($server = resolv_server
($server_in))) {
1098 die "unable to resolve address for server '${server_in}'\n";
1101 my $cmd = ['/sbin/showmount', '--no-headers', '--exports', $server];
1104 run_command
($cmd, outfunc
=> sub {
1107 # note: howto handle white spaces in export path??
1108 if ($line =~ m!^(/\S+)\s+(.+)$!) {
1117 my ($server_in, $user, $password, $domain) = @_;
1120 if (!($server = resolv_server
($server_in))) {
1121 die "unable to resolve address for server '${server_in}'\n";
1124 # we support only Windows grater than 2012 cifsscan so use smb3
1125 my $cmd = ['/usr/bin/smbclient', '-m', 'smb3', '-d', '0', '-L', $server];
1126 if (defined($user)) {
1127 die "password is required" if !defined($password);
1128 push @$cmd, '-U', "$user\%$password";
1129 push @$cmd, '-W', $domain if defined($domain);
1138 if ($line =~ m/(\S+)\s*Disk\s*(\S*)/) {
1140 } elsif ($line =~ m/(NT_STATUS_(\S*))/) {
1153 my $cmd = ['zfs', 'list', '-t', 'filesystem', '-H', '-o', 'name,avail,used'];
1156 run_command
($cmd, outfunc
=> sub {
1159 if ($line =~m/^(\S+)\s+(\S+)\s+(\S+)$/) {
1160 my ($pool, $size_str, $used_str) = ($1, $2, $3);
1161 my $size = PVE
::Storage
::ZFSPoolPlugin
::zfs_parse_size
($size_str);
1162 my $used = PVE
::Storage
::ZFSPoolPlugin
::zfs_parse_size
($used_str);
1163 # ignore subvolumes generated by our ZFSPoolPlugin
1164 return if $pool =~ m!/subvol-\d+-[^/]+$!;
1165 return if $pool =~ m!/basevol-\d+-[^/]+$!;
1166 push @$res, { pool
=> $pool, size
=> $size, free
=> $size-$used };
1174 my ($portal, $noerr) = @_;
1176 my ($server, $port) = PVE
::Tools
::parse_host_and_port
($portal);
1178 if (my $ip = resolv_server
($server)) {
1180 $server = "[$server]" if $server =~ /^$IPV6RE$/;
1181 return $port ?
"$server:$port" : $server;
1184 return undef if $noerr;
1186 raise_param_exc
({ portal
=> "unable to resolve portal address '$portal'" });
1191 my ($portal_in) = @_;
1194 if (!($portal = resolv_portal
($portal_in))) {
1195 die "unable to parse/resolve portal address '${portal_in}'\n";
1198 return PVE
::Storage
::ISCSIPlugin
::iscsi_discovery
($portal);
1201 sub storage_default_format
{
1202 my ($cfg, $storeid) = @_;
1204 my $scfg = storage_config
($cfg, $storeid);
1206 return PVE
::Storage
::Plugin
::default_format
($scfg);
1209 sub vgroup_is_used
{
1210 my ($cfg, $vgname) = @_;
1212 foreach my $storeid (keys %{$cfg->{ids
}}) {
1213 my $scfg = storage_config
($cfg, $storeid);
1214 if ($scfg->{type
} eq 'lvm' && $scfg->{vgname
} eq $vgname) {
1222 sub target_is_used
{
1223 my ($cfg, $target) = @_;
1225 foreach my $storeid (keys %{$cfg->{ids
}}) {
1226 my $scfg = storage_config
($cfg, $storeid);
1227 if ($scfg->{type
} eq 'iscsi' && $scfg->{target
} eq $target) {
1235 sub volume_is_used
{
1236 my ($cfg, $volid) = @_;
1238 foreach my $storeid (keys %{$cfg->{ids
}}) {
1239 my $scfg = storage_config
($cfg, $storeid);
1240 if ($scfg->{base
} && $scfg->{base
} eq $volid) {
1248 sub storage_is_used
{
1249 my ($cfg, $storeid) = @_;
1251 foreach my $sid (keys %{$cfg->{ids
}}) {
1252 my $scfg = storage_config
($cfg, $sid);
1253 next if !$scfg->{base
};
1254 my ($st) = parse_volume_id
($scfg->{base
});
1255 return 1 if $st && $st eq $storeid;
1262 my ($list, $func) = @_;
1266 foreach my $sid (keys %$list) {
1267 foreach my $info (@{$list->{$sid}}) {
1268 my $volid = $info->{volid
};
1269 my ($sid1, $volname) = parse_volume_id
($volid, 1);
1270 if ($sid1 && $sid1 eq $sid) {
1271 &$func ($volid, $sid, $info);
1273 warn "detected strange volid '$volid' in volume list for '$sid'\n";
1279 sub extract_vzdump_config_tar
{
1280 my ($archive, $conf_re) = @_;
1282 die "ERROR: file '$archive' does not exist\n" if ! -f
$archive;
1284 my $pid = open(my $fh, '-|', 'tar', 'tf', $archive) ||
1285 die "unable to open file '$archive'\n";
1288 while (defined($file = <$fh>)) {
1289 if ($file =~ $conf_re) {
1290 $file = $1; # untaint
1299 die "ERROR: archive contains no configuration file\n" if !$file;
1305 $raw .= "$output\n";
1308 PVE
::Tools
::run_command
(['tar', '-xpOf', $archive, $file, '--occurrence'], outfunc
=> $out);
1310 return wantarray ?
($raw, $file) : $raw;
1313 sub extract_vzdump_config_vma
{
1314 my ($archive, $comp) = @_;
1320 $raw .= "$output\n";
1326 if ($comp eq 'gz') {
1327 $uncomp = ["zcat", $archive];
1328 } elsif ($comp eq 'lzo') {
1329 $uncomp = ["lzop", "-d", "-c", $archive];
1331 die "unknown compression method '$comp'\n";
1333 $cmd = [$uncomp, ["vma", "config", "-"]];
1335 # in some cases, lzop/zcat exits with 1 when its stdout pipe is
1336 # closed early by vma, detect this and ignore the exit code later
1341 if ($output =~ m/lzop: Broken pipe: <stdout>/ || $output =~ m/gzip: stdout: Broken pipe/) {
1343 } elsif (!defined ($errstring) && $output !~ m/^\s*$/) {
1344 $errstring = "Failed to extract config from VMA archive: $output\n";
1348 # in other cases, the pipeline will exit with exit code 141
1349 # because of the broken pipe, handle / ignore this as well
1352 $rc = PVE
::Tools
::run_command
($cmd, outfunc
=> $out, errfunc
=> $err, noerr
=> 1);
1356 # use exit code if no stderr output and not just broken pipe
1357 if (!$errstring && !$broken_pipe && $rc != 0 && $rc != 141) {
1358 die "$rerr\n" if $rerr;
1359 die "config extraction failed with exit code $rc\n";
1361 die "$errstring\n" if $errstring;
1363 # simple case without compression and weird piping behaviour
1364 PVE
::Tools
::run_command
(["vma", "config", $archive], outfunc
=> $out);
1367 return wantarray ?
($raw, undef) : $raw;
1370 sub extract_vzdump_config
{
1371 my ($cfg, $volid) = @_;
1373 my ($storeid, $volname) = parse_volume_id
($volid);
1374 if (defined($storeid)) {
1375 my $scfg = storage_config
($cfg, $storeid);
1376 if ($scfg->{type
} eq 'pbs') {
1377 storage_check_enabled
($cfg, $storeid);
1378 return PVE
::Storage
::PBSPlugin-
>extract_vzdump_config($scfg, $volname, $storeid);
1382 my $archive = abs_filesystem_path
($cfg, $volid);
1384 if ($volid =~ /vzdump-(lxc|openvz)-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?))$/) {
1385 return extract_vzdump_config_tar
($archive, qr!^(\./etc/vzdump/(pct|vps)\.conf)$!);
1386 } elsif ($volid =~ /vzdump-qemu-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(gz|lzo))?))$/) {
1394 $comp = $11 if defined($11);
1397 if ($format eq 'tar') {
1398 return extract_vzdump_config_tar
($archive, qr!\(\./qemu-server\.conf\)!);
1400 return extract_vzdump_config_vma
($archive, $comp);
1403 die "cannot determine backup guest type for backup archive '$volid'\n";
1408 my ($cfg, $fh, $volid, $format, $snapshot, $base_snapshot, $with_snapshots) = @_;
1410 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1411 die "cannot export 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_export($scfg, $storeid, $fh, $volname, $format,
1415 $snapshot, $base_snapshot, $with_snapshots);
1419 my ($cfg, $fh, $volid, $format, $base_snapshot, $with_snapshots) = @_;
1421 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1422 die "cannot import into volume '$volid'\n" if !$storeid;
1423 my $scfg = storage_config
($cfg, $storeid);
1424 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1425 return $plugin->volume_import($scfg, $storeid, $fh, $volname, $format,
1426 $base_snapshot, $with_snapshots);
1429 sub volume_export_formats
{
1430 my ($cfg, $volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
1432 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1433 return if !$storeid;
1434 my $scfg = storage_config
($cfg, $storeid);
1435 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1436 return $plugin->volume_export_formats($scfg, $storeid, $volname,
1437 $snapshot, $base_snapshot,
1441 sub volume_import_formats
{
1442 my ($cfg, $volid, $base_snapshot, $with_snapshots) = @_;
1444 my ($storeid, $volname) = parse_volume_id
($volid, 1);
1445 return if !$storeid;
1446 my $scfg = storage_config
($cfg, $storeid);
1447 my $plugin = PVE
::Storage
::Plugin-
>lookup($scfg->{type
});
1448 return $plugin->volume_import_formats($scfg, $storeid, $volname,
1449 $base_snapshot, $with_snapshots);
1452 sub volume_transfer_formats
{
1453 my ($cfg, $src_volid, $dst_volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
1454 my @export_formats = volume_export_formats
($cfg, $src_volid, $snapshot, $base_snapshot, $with_snapshots);
1455 my @import_formats = volume_import_formats
($cfg, $dst_volid, $base_snapshot, $with_snapshots);
1456 my %import_hash = map { $_ => 1 } @import_formats;
1457 my @common = grep { $import_hash{$_} } @export_formats;
1461 # bash completion helper
1463 sub complete_storage
{
1464 my ($cmdname, $pname, $cvalue) = @_;
1466 my $cfg = PVE
::Storage
::config
();
1468 return $cmdname eq 'add' ?
[] : [ PVE
::Storage
::storage_ids
($cfg) ];
1471 sub complete_storage_enabled
{
1472 my ($cmdname, $pname, $cvalue) = @_;
1476 my $cfg = PVE
::Storage
::config
();
1477 foreach my $sid (keys %{$cfg->{ids
}}) {
1478 next if !storage_check_enabled
($cfg, $sid, undef, 1);
1484 sub complete_content_type
{
1485 my ($cmdname, $pname, $cvalue) = @_;
1487 return [qw(rootdir images vztmpl iso backup snippets)];
1490 sub complete_volume
{
1491 my ($cmdname, $pname, $cvalue) = @_;
1495 my $storage_list = complete_storage_enabled
();
1497 if ($cvalue =~ m/^([^:]+):/) {
1498 $storage_list = [ $1 ];
1500 if (scalar(@$storage_list) > 1) {
1501 # only list storage IDs to avoid large listings
1503 foreach my $storeid (@$storage_list) {
1504 # Hack: simply return 2 artificial values, so that
1505 # completions does not finish
1506 push @$res, "$storeid:volname", "$storeid:...";
1513 foreach my $storeid (@$storage_list) {
1514 my $vollist = PVE
::Storage
::volume_list
($cfg, $storeid);
1516 foreach my $item (@$vollist) {
1517 push @$res, $item->{volid
};
1524 # Various io-heavy operations require io/bandwidth limits which can be
1525 # configured on multiple levels: The global defaults in datacenter.cfg, and
1526 # per-storage overrides. When we want to do a restore from storage A to storage
1527 # B, we should take the smaller limit defined for storages A and B, and if no
1528 # such limit was specified, use the one from datacenter.cfg.
1529 sub get_bandwidth_limit
{
1530 my ($operation, $storage_list, $override) = @_;
1532 # called for each limit (global, per-storage) with the 'default' and the
1533 # $operation limit and should udpate $override for every limit affecting
1535 my $use_global_limits = 0;
1536 my $apply_limit = sub {
1538 if (defined($bwlimit)) {
1539 my $limits = PVE
::JSONSchema
::parse_property_string
('bwlimit', $bwlimit);
1540 my $limit = $limits->{$operation} // $limits->{default};
1541 if (defined($limit)) {
1542 if (!$override || $limit < $override) {
1548 # If there was no applicable limit, try to apply the global ones.
1549 $use_global_limits = 1;
1552 my ($rpcenv, $authuser);
1553 if (defined($override)) {
1554 $rpcenv = PVE
::RPCEnvironment-
>get();
1555 $authuser = $rpcenv->get_user();
1558 # Apply per-storage limits - if there are storages involved.
1559 if (defined($storage_list) && @$storage_list) {
1560 my $config = config
();
1562 # The Datastore.Allocate permission allows us to modify the per-storage
1563 # limits, therefore it also allows us to override them.
1564 # Since we have most likely multiple storages to check, do a quick check on
1565 # the general '/storage' path to see if we can skip the checks entirely:
1566 return $override if $rpcenv && $rpcenv->check($authuser, '/storage', ['Datastore.Allocate'], 1);
1569 foreach my $storage (@$storage_list) {
1570 next if !defined($storage);
1571 # Avoid duplicate checks:
1572 next if $done{$storage};
1573 $done{$storage} = 1;
1575 # Otherwise we may still have individual /storage/$ID permissions:
1576 if (!$rpcenv || !$rpcenv->check($authuser, "/storage/$storage", ['Datastore.Allocate'], 1)) {
1577 # And if not: apply the limits.
1578 my $storecfg = storage_config
($config, $storage);
1579 $apply_limit->($storecfg->{bwlimit
});
1583 # Storage limits take precedence over the datacenter defaults, so if
1584 # a limit was applied:
1585 return $override if !$use_global_limits;
1588 # Sys.Modify on '/' means we can change datacenter.cfg which contains the
1589 # global default limits.
1590 if (!$rpcenv || !$rpcenv->check($authuser, '/', ['Sys.Modify'], 1)) {
1591 # So if we cannot modify global limits, apply them to our currently
1592 # requested override.
1593 my $dc = cfs_read_file
('datacenter.cfg');
1594 $apply_limit->($dc->{bwlimit
});
1600 # checks if the storage id is available and dies if not
1601 sub assert_sid_unused
{
1605 if (my $scfg = storage_config
($cfg, $sid, 1)) {
1606 die "storage ID '$sid' already defined\n";