1 package PVE
::Storage
::Plugin
;
14 use PVE
::Tools
qw(run_command);
15 use PVE
::JSONSchema
qw(get_standard_option register_standard_option);
16 use PVE
::Cluster
qw(cfs_register_file);
20 use base
qw(PVE::SectionConfig);
22 use constant COMPRESSOR_RE
=> 'gz|lzo|zst';
24 use constant LOG_EXT
=> ".log";
25 use constant NOTES_EXT
=> ".notes";
27 our @COMMON_TAR_FLAGS = qw(
29 -p --sparse --numeric-owner --acls
30 --xattrs --xattrs-include=user.* --xattrs-include=security.capability
31 --warning=no-file-ignored --warning=no-xattr-write
34 our @SHARED_STORAGE = (
47 our $QCOW2_PREALLOCATION = {
54 our $RAW_PREALLOCATION = {
60 our $MAX_VOLUMES_PER_GUEST = 1024;
62 cfs_register_file
('storage.cfg',
63 sub { __PACKAGE__-
>parse_config(@_); },
64 sub { __PACKAGE__-
>write_config(@_); });
68 type
=> 'integer', minimum
=> '0',
69 format_description
=> 'N',
72 our $prune_backups_format = {
75 description
=> 'Keep all backups. Conflicts with the other options when true.',
80 description
=> 'Keep the last <N> backups.',
84 description
=> 'Keep backups for the last <N> different hours. If there is more' .
85 'than one backup for a single hour, only the latest one is kept.'
89 description
=> 'Keep backups for the last <N> different days. If there is more' .
90 'than one backup for a single day, only the latest one is kept.'
94 description
=> 'Keep backups for the last <N> different weeks. If there is more' .
95 'than one backup for a single week, only the latest one is kept.'
99 description
=> 'Keep backups for the last <N> different months. If there is more' .
100 'than one backup for a single month, only the latest one is kept.'
104 description
=> 'Keep backups for the last <N> different years. If there is more' .
105 'than one backup for a single year, only the latest one is kept.'
108 PVE
::JSONSchema
::register_format
('prune-backups', $prune_backups_format, \
&validate_prune_backups
);
109 sub validate_prune_backups
{
110 my ($prune_backups) = @_;
112 my $res = { $prune_backups->%* };
114 my $keep_all = delete $res->{'keep-all'};
116 if (scalar(grep { $_ > 0 } values %{$res}) == 0) {
117 $res = { 'keep-all' => 1 };
118 } elsif ($keep_all) {
119 die "keep-all cannot be set together with other options.\n";
124 register_standard_option
('prune-backups', {
125 description
=> "The retention options with shorter intervals are processed first " .
126 "with --keep-last being the very first one. Each option covers a " .
127 "specific period of time. We say that backups within this period " .
128 "are covered by this option. The next option does not take care " .
129 "of already covered backups and only considers older backups.",
132 format
=> 'prune-backups',
137 type
=> { description
=> "Storage type." },
138 storage
=> get_standard_option
('pve-storage-id',
139 { completion
=> \
&PVE
::Storage
::complete_storage
}),
140 nodes
=> get_standard_option
('pve-node-list', { optional
=> 1 }),
142 description
=> "Allowed content types.\n\nNOTE: the value " .
143 "'rootdir' is used for Containers, and value 'images' for VMs.\n",
144 type
=> 'string', format
=> 'pve-storage-content-list',
146 completion
=> \
&PVE
::Storage
::complete_content_type
,
149 description
=> "Flag to disable the storage.",
154 description
=> "Deprecated: use 'prune-backups' instead. " .
155 "Maximal number of backup files per VM. Use '0' for unlimited.",
160 'prune-backups' => get_standard_option
('prune-backups'),
161 'max-protected-backups' => {
162 description
=> "Maximal number of protected backups per guest. Use '-1' for unlimited.",
166 default => "Unlimited for users with Datastore.Allocate privilege, 5 for other users",
169 description
=> "Mark storage as shared.",
174 description
=> "Subdir to mount.",
175 type
=> 'string', format
=> 'pve-storage-path',
179 description
=> "Default image format.",
180 type
=> 'string', format
=> 'pve-storage-format',
184 description
=> "Preallocation mode for raw and qcow2 images. " .
185 "Using 'metadata' on raw images results in preallocation=off.",
186 type
=> 'string', enum
=> ['off', 'metadata', 'falloc', 'full'],
187 default => 'metadata',
191 description
=> "Overrides for default content type directories.",
192 type
=> "string", format
=> "pve-dir-override-list",
196 description
=> "NFS/CIFS mount options (see 'man nfs' or 'man mount.cifs')",
198 format
=> 'pve-storage-options',
204 sub content_hash_to_string
{
208 foreach my $ct (keys %$hash) {
209 push @cta, $ct if $hash->{$ct};
212 return join(',', @cta);
215 sub valid_content_types
{
218 my $def = $defaultData->{plugindata
}->{$type};
222 return $def->{content
}->[0];
225 sub dirs_hash_to_string
{
228 return join(',', map { "$_=$hash->{$_}" } sort keys %$hash);
234 my $type = $scfg->{type
};
235 my $def = $defaultData->{plugindata
}->{$type};
237 my $def_format = 'raw';
238 my $valid_formats = [ $def_format ];
240 if (defined($def->{format
})) {
241 $def_format = $scfg->{format
} || $def->{format
}->[1];
242 $valid_formats = [ sort keys %{$def->{format
}->[0]} ];
245 return wantarray ?
($def_format, $valid_formats) : $def_format;
248 PVE
::JSONSchema
::register_format
('pve-storage-path', \
&verify_path
);
250 my ($path, $noerr) = @_;
252 # fixme: exclude more shell meta characters?
253 # we need absolute paths
254 if ($path !~ m
|^/[^;\
(\
)]+|) {
255 return undef if $noerr;
256 die "value does not look like a valid absolute path\n";
261 PVE
::JSONSchema
::register_format
('pve-storage-server', \
&verify_server
);
263 my ($server, $noerr) = @_;
265 if (!(PVE
::JSONSchema
::pve_verify_ip
($server, 1) ||
266 PVE
::JSONSchema
::pve_verify_dns_name
($server, 1)))
268 return undef if $noerr;
269 die "value does not look like a valid server name or IP address\n";
274 PVE
::JSONSchema
::register_format
('pve-storage-vgname', \
&parse_lvm_name
);
276 my ($name, $noerr) = @_;
278 if ($name !~ m/^[a-z0-9][a-z0-9\-\_\.]*[a-z0-9]$/i) {
279 return undef if $noerr;
280 die "lvm name '$name' contains illegal characters\n";
286 # fixme: do we need this
287 #PVE::JSONSchema::register_format('pve-storage-portal', \&verify_portal);
289 # my ($portal, $noerr) = @_;
291 # # IP with optional port
292 # if ($portal !~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d+)?$/) {
293 # return undef if $noerr;
294 # die "value does not look like a valid portal address\n";
299 PVE
::JSONSchema
::register_format
('pve-storage-portal-dns', \
&verify_portal_dns
);
300 sub verify_portal_dns
{
301 my ($portal, $noerr) = @_;
303 # IP or DNS name with optional port
304 if (!PVE
::Tools
::parse_host_and_port
($portal)) {
305 return undef if $noerr;
306 die "value does not look like a valid portal address\n";
311 PVE
::JSONSchema
::register_format
('pve-storage-content', \
&verify_content
);
313 my ($ct, $noerr) = @_;
315 my $valid_content = valid_content_types
('dir'); # dir includes all types
317 if (!$valid_content->{$ct}) {
318 return undef if $noerr;
319 die "invalid content type '$ct'\n";
325 PVE
::JSONSchema
::register_format
('pve-storage-format', \
&verify_format
);
327 my ($fmt, $noerr) = @_;
329 if ($fmt !~ m/(raw|qcow2|vmdk|subvol)/) {
330 return undef if $noerr;
331 die "invalid format '$fmt'\n";
337 PVE
::JSONSchema
::register_format
('pve-storage-options', \
&verify_options
);
339 my ($value, $noerr) = @_;
341 # mount options (see man fstab)
342 if ($value !~ m/^\S+$/) {
343 return undef if $noerr;
344 die "invalid options '$value'\n";
350 PVE
::JSONSchema
::register_format
('pve-volume-id', \
&parse_volume_id
);
351 sub parse_volume_id
{
352 my ($volid, $noerr) = @_;
354 if ($volid =~ m/^([a-z][a-z0-9\-\_\.]*[a-z0-9]):(.+)$/i) {
355 return wantarray ?
($1, $2) : $1;
357 return undef if $noerr;
358 die "unable to parse volume ID '$volid'\n";
361 PVE
::JSONSchema
::register_format
('pve-dir-override', \
&verify_dir_override
);
362 sub verify_dir_override
{
363 my ($value, $noerr) = @_;
365 if ($value =~ m/^([a-z]+)=([^.]*(?:\.?[^.]+)+)$/) {
366 my ($content_type, $relative_path) = ($1, $2);
367 if (verify_content
($content_type, $noerr)) {
368 # linux has 4k max-path, but limit total length to lower as its concat'd for full path
369 if (length($relative_path) < 1023 && !(grep { length($_) >= 255 } split('/', $relative_path))) {
375 return undef if $noerr;
376 die "invalid override '$value'\n";
383 sub parse_section_header
{
384 my ($class, $line) = @_;
386 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
387 my ($type, $storeid) = (lc($1), $2);
388 my $errmsg = undef; # set if you want to skip whole section
389 eval { PVE
::JSONSchema
::parse_storage_id
($storeid); };
391 my $config = {}; # to return additional attributes
392 return ($type, $storeid, $errmsg, $config);
398 my ($class, $type, $key, $value) = @_;
400 my $def = $defaultData->{plugindata
}->{$type};
402 if ($key eq 'content') {
403 my $valid_content = $def->{content
}->[0];
407 foreach my $c (PVE
::Tools
::split_list
($value)) {
408 if (!$valid_content->{$c}) {
409 warn "storage does not support content type '$c'\n";
415 if ($res->{none
} && scalar (keys %$res) > 1) {
416 die "unable to combine 'none' with other content types\n";
419 if (scalar(keys $res->%*) == 0 && !$valid_content->{none
}) {
420 die "storage does not support content type 'none'\n";
424 } elsif ($key eq 'format') {
425 my $valid_formats = $def->{format
}->[0];
427 if (!$valid_formats->{$value}) {
428 warn "storage does not support format '$value'\n";
433 } elsif ($key eq 'nodes') {
436 foreach my $node (PVE
::Tools
::split_list
($value)) {
437 if (PVE
::JSONSchema
::pve_verify_node_name
($node)) {
443 # no node restrictions for local storage
444 #if ($storeid && $storeid eq 'local' && scalar(keys(%$res))) {
445 # die "storage '$storeid' does not allow node restrictions\n";
449 } elsif ($key eq 'content-dirs') {
450 my $valid_content = $def->{content
}->[0];
453 foreach my $dir (PVE
::Tools
::split_list
($value)) {
454 my ($content, $path) = split(/=/, $dir, 2);
456 if (!$valid_content->{$content}) {
457 warn "storage does not support content type '$content'\n";
461 $res->{$content} = $path;
471 my ($class, $type, $key, $value) = @_;
473 if ($key eq 'nodes') {
474 return join(',', keys(%$value));
475 } elsif ($key eq 'content') {
476 my $res = content_hash_to_string
($value) || 'none';
478 } elsif ($key eq 'content-dirs') {
479 my $res = dirs_hash_to_string
($value);
487 my ($class, $filename, $raw) = @_;
489 my $cfg = $class->SUPER::parse_config
($filename, $raw);
490 my $ids = $cfg->{ids
};
492 # make sure we have a reasonable 'local:' storage
493 # we want 'local' to be always the same 'type' (on all cluster nodes)
494 if (!$ids->{local} || $ids->{local}->{type
} ne 'dir' ||
495 ($ids->{local}->{path
} && $ids->{local}->{path
} ne '/var/lib/vz')) {
498 priority
=> 0, # force first entry
499 path
=> '/var/lib/vz',
500 'prune-backups' => 'keep-all=1',
512 # make sure we have a path
513 $ids->{local}->{path
} = '/var/lib/vz' if !$ids->{local}->{path
};
515 # remove node restrictions for local storage
516 delete($ids->{local}->{nodes
});
518 foreach my $storeid (keys %$ids) {
519 my $d = $ids->{$storeid};
520 my $type = $d->{type
};
522 my $def = $defaultData->{plugindata
}->{$type};
524 if ($def->{content
}) {
525 $d->{content
} = $def->{content
}->[1] if !$d->{content
};
527 if (grep { $_ eq $type } @SHARED_STORAGE) {
535 sub preallocation_cmd_option
{
536 my ($scfg, $fmt) = @_;
538 my $prealloc = $scfg->{preallocation
};
540 if ($fmt eq 'qcow2') {
541 $prealloc = $prealloc // 'metadata';
543 die "preallocation mode '$prealloc' not supported by format '$fmt'\n"
544 if !$QCOW2_PREALLOCATION->{$prealloc};
546 return "preallocation=$prealloc";
547 } elsif ($fmt eq 'raw') {
548 $prealloc = $prealloc // 'off';
549 $prealloc = 'off' if $prealloc eq 'metadata';
551 die "preallocation mode '$prealloc' not supported by format '$fmt'\n"
552 if !$RAW_PREALLOCATION->{$prealloc};
554 return "preallocation=$prealloc";
560 # Storage implementation
562 # called during addition of storage (before the new storage config got written)
563 # die to abort addition if there are (grave) problems
564 # NOTE: runs in a storage config *locked* context
566 my ($class, $storeid, $scfg, %param) = @_;
568 # do nothing by default
572 # called during storage configuration update (before the updated storage config got written)
573 # die to abort the update if there are (grave) problems
574 # NOTE: runs in a storage config *locked* context
576 my ($class, $storeid, $scfg, %param) = @_;
578 # do nothing by default
582 # called during deletion of storage (before the new storage config got written)
583 # and if the activate check on addition fails, to cleanup all storage traces
584 # which on_add_hook may have created.
585 # die to abort deletion if there are (very grave) problems
586 # NOTE: runs in a storage config *locked* context
588 my ($class, $storeid, $scfg) = @_;
590 # do nothing by default
594 sub cluster_lock_storage
{
595 my ($class, $storeid, $shared, $timeout, $func, @param) = @_;
599 my $lockid = "pve-storage-$storeid";
600 my $lockdir = "/var/lock/pve-manager";
602 $res = PVE
::Tools
::lock_file
("$lockdir/$lockid", $timeout, $func, @param);
605 $res = PVE
::Cluster
::cfs_lock_storage
($storeid, $timeout, $func, @param);
614 if ($name =~ m!^((base-)?[^/\s]+\.(raw|qcow2|vmdk|subvol))$!) {
615 return ($1, $3, $2); # (name, format, isBase)
618 die "unable to parse volume filename '$name'\n";
622 my ($class, $volname) = @_;
624 if ($volname =~ m!^(\d+)/(\S+)/(\d+)/(\S+)$!) {
625 my ($basedvmid, $basename) = ($1, $2);
626 parse_name_dir
($basename);
627 my ($vmid, $name) = ($3, $4);
628 my (undef, $format, $isBase) = parse_name_dir
($name);
629 return ('images', $name, $vmid, $basename, $basedvmid, $isBase, $format);
630 } elsif ($volname =~ m!^(\d+)/(\S+)$!) {
631 my ($vmid, $name) = ($1, $2);
632 my (undef, $format, $isBase) = parse_name_dir
($name);
633 return ('images', $name, $vmid, undef, undef, $isBase, $format);
634 } elsif ($volname =~ m!^iso/([^/]+$PVE::Storage::ISO_EXT_RE_0)$!) {
636 } elsif ($volname =~ m!^vztmpl/([^/]+$PVE::Storage::VZTMPL_EXT_RE_1)$!) {
637 return ('vztmpl', $1);
638 } elsif ($volname =~ m!^rootdir/(\d+)$!) {
639 return ('rootdir', $1, $1);
640 } elsif ($volname =~ m!^backup/([^/]+$PVE::Storage::BACKUP_EXT_RE_2)$!) {
642 if ($fn =~ m/^vzdump-(openvz|lxc|qemu)-(\d+)-.+/) {
643 return ('backup', $fn, $2);
645 return ('backup', $fn);
646 } elsif ($volname =~ m!^snippets/([^/]+)$!) {
647 return ('snippets', $1);
650 die "unable to parse directory volume name '$volname'\n";
653 my $vtype_subdirs = {
655 rootdir
=> 'private',
656 iso
=> 'template/iso',
657 vztmpl
=> 'template/cache',
659 snippets
=> 'snippets',
662 sub get_vtype_subdirs
{
663 return $vtype_subdirs;
667 my ($class, $scfg, $vtype) = @_;
669 my $path = $scfg->{path
};
671 die "storage definition has no path\n" if !$path;
672 die "unknown vtype '$vtype'\n" if !exists($vtype_subdirs->{$vtype});
674 my $subdir = $scfg->{"content-dirs"}->{$vtype} // $vtype_subdirs->{$vtype};
676 return "$path/$subdir";
679 sub filesystem_path
{
680 my ($class, $scfg, $volname, $snapname) = @_;
682 my ($vtype, $name, $vmid, undef, undef, $isBase, $format) =
683 $class->parse_volname($volname);
685 # Note: qcow2/qed has internal snapshot, so path is always
686 # the same (with or without snapshot => same file).
687 die "can't snapshot this image format\n"
688 if defined($snapname) && $format !~ m/^(qcow2|qed)$/;
690 my $dir = $class->get_subdir($scfg, $vtype);
692 $dir .= "/$vmid" if $vtype eq 'images';
694 my $path = "$dir/$name";
696 return wantarray ?
($path, $vmid, $vtype) : $path;
700 my ($class, $scfg, $volname, $storeid, $snapname) = @_;
702 return $class->filesystem_path($scfg, $volname, $snapname);
706 my ($class, $storeid, $scfg, $volname) = @_;
708 # this only works for file based storage types
709 die "storage definition has no path\n" if !$scfg->{path
};
711 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) =
712 $class->parse_volname($volname);
714 die "create_base on wrong vtype '$vtype'\n" if $vtype ne 'images';
716 die "create_base not possible with base image\n" if $isBase;
718 my $path = $class->filesystem_path($scfg, $volname);
720 my ($size, undef, $used, $parent) = file_size_info
($path);
721 die "file_size_info on '$volname' failed\n" if !($format && defined($size));
723 die "volname '$volname' contains wrong information about parent\n"
724 if $basename && (!$parent || $parent ne "../$basevmid/$basename");
727 $newname =~ s/^vm-/base-/;
729 my $newvolname = $basename ?
"$basevmid/$basename/$vmid/$newname" :
732 my $newpath = $class->filesystem_path($scfg, $newvolname);
734 die "file '$newpath' already exists\n" if -f
$newpath;
736 rename($path, $newpath) ||
737 die "rename '$path' to '$newpath' failed - $!\n";
739 # We try to protect base volume
741 chmod(0444, $newpath); # nobody should write anything
743 # also try to set immutable flag
744 eval { run_command
(['/usr/bin/chattr', '+i', $newpath]); };
750 my $get_vm_disk_number = sub {
751 my ($disk_name, $scfg, $vmid, $suffix) = @_;
753 my $disk_regex = qr/(vm|base)-$vmid-disk-(\d+)$suffix/;
755 my $type = $scfg->{type
};
756 my $def = { %{$defaultData->{plugindata
}->{$type}} };
758 my $valid = $def->{format
}[0];
759 if ($valid->{subvol
}) {
760 $disk_regex = qr/(vm|base|subvol|basevol)-$vmid-disk-(\d+)/;
763 if ($disk_name =~ m/$disk_regex/) {
770 sub get_next_vm_diskname
{
771 my ($disk_list, $storeid, $vmid, $fmt, $scfg, $add_fmt_suffix) = @_;
774 my $prefix = ($fmt eq 'subvol') ?
'subvol' : 'vm';
775 my $suffix = $add_fmt_suffix ?
".$fmt" : '';
778 foreach my $disk (@$disk_list) {
779 my $disknum = $get_vm_disk_number->($disk, $scfg, $vmid, $suffix);
780 $disk_ids->{$disknum} = 1 if defined($disknum);
783 for (my $i = 0; $i < $MAX_VOLUMES_PER_GUEST; $i++) {
784 if (!$disk_ids->{$i}) {
785 return "$prefix-$vmid-disk-$i$suffix";
789 die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
792 sub find_free_diskname
{
793 my ($class, $storeid, $scfg, $vmid, $fmt, $add_fmt_suffix) = @_;
795 my $disks = $class->list_images($storeid, $scfg, $vmid);
797 my $disk_list = [ map { $_->{volid
} } @$disks ];
799 return get_next_vm_diskname
($disk_list, $storeid, $vmid, $fmt, $scfg, $add_fmt_suffix);
803 my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
805 # this only works for file based storage types
806 die "storage definition has no path\n" if !$scfg->{path
};
808 my ($vtype, $basename, $basevmid, undef, undef, $isBase, $format) =
809 $class->parse_volname($volname);
811 die "clone_image on wrong vtype '$vtype'\n" if $vtype ne 'images';
813 die "this storage type does not support clone_image on snapshot\n" if $snap;
815 die "this storage type does not support clone_image on subvolumes\n" if $format eq 'subvol';
817 die "clone_image only works on base images\n" if !$isBase;
819 my $imagedir = $class->get_subdir($scfg, 'images');
820 $imagedir .= "/$vmid";
824 my $name = $class->find_free_diskname($storeid, $scfg, $vmid, "qcow2", 1);
826 warn "clone $volname: $vtype, $name, $vmid to $name (base=../$basevmid/$basename)\n";
828 my $newvol = "$basevmid/$basename/$vmid/$name";
830 my $path = $class->filesystem_path($scfg, $newvol);
832 # Note: we use relative paths, so we need to call chdir before qemu-img
834 local $CWD = $imagedir;
836 my $cmd = ['/usr/bin/qemu-img', 'create', '-b', "../$basevmid/$basename",
837 '-F', $format, '-f', 'qcow2', $path];
849 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
851 my $imagedir = $class->get_subdir($scfg, 'images');
852 $imagedir .= "/$vmid";
856 $name = $class->find_free_diskname($storeid, $scfg, $vmid, $fmt, 1) if !$name;
858 my (undef, $tmpfmt) = parse_name_dir
($name);
860 die "illegal name '$name' - wrong extension for format ('$tmpfmt != '$fmt')\n"
863 my $path = "$imagedir/$name";
865 die "disk image '$path' already exists\n" if -e
$path;
867 if ($fmt eq 'subvol') {
868 # only allow this if size = 0, so that user knows what he is doing
869 die "storage does not support subvol quotas\n" if $size != 0;
871 my $old_umask = umask(0022);
873 mkdir($path) or $err = "unable to create subvol '$path' - $!\n";
877 my $cmd = ['/usr/bin/qemu-img', 'create'];
879 my $prealloc_opt = preallocation_cmd_option
($scfg, $fmt);
880 push @$cmd, '-o', $prealloc_opt if defined($prealloc_opt);
882 push @$cmd, '-f', $fmt, $path, "${size}K";
884 eval { run_command
($cmd, errmsg
=> "unable to create image"); };
892 return "$vmid/$name";
896 my ($class, $storeid, $scfg, $volname, $isBase, $format) = @_;
898 die "cannot remove protected volume '$volname' on '$storeid'\n"
899 if $class->get_volume_attribute($scfg, $storeid, $volname, 'protected');
901 my $path = $class->filesystem_path($scfg, $volname);
904 # try to remove immutable flag
905 eval { run_command
(['/usr/bin/chattr', '-i', $path]); };
909 if (defined($format) && ($format eq 'subvol')) {
910 File
::Path
::remove_tree
($path);
912 if (!(-f
$path || -l
$path)) {
913 warn "disk image '$path' does not exist\n";
917 unlink($path) || die "unlink '$path' failed - $!\n";
920 # try to cleanup directory to not clutter storage with empty $vmid dirs if
921 # all images from a guest got deleted
922 my $dir = dirname
($path);
929 my ($filename, $timeout) = @_;
931 my $st = File
::stat::stat($filename);
934 my $extramsg = -l
$filename ?
' - dangling symlink?' : '';
935 warn "failed to stat '$filename'$extramsg\n";
939 if (S_ISDIR
($st->mode)) {
940 return wantarray ?
(0, 'subvol', 0, undef, $st->ctime) : 1;
945 run_command
(['/usr/bin/qemu-img', 'info', '--output=json', $filename],
947 outfunc
=> sub { $json .= shift },
948 errfunc
=> sub { warn "$_[0]\n" }
953 my $info = eval { decode_json
($json) };
955 warn "could not parse qemu-img info command output for '$filename' - $err\n";
956 return wantarray ?
(undef, undef, undef, undef, $st->ctime) : undef;
959 my ($size, $format, $used, $parent) = $info->@{qw(virtual-size format actual-size backing-filename)};
961 ($size) = ($size =~ /^(\d+)$/) or die "size '$size' not an integer\n"; # untaint
962 # coerce back from string
964 ($used) = ($used =~ /^(\d+)$/) or die "used '$used' not an integer\n"; # untaint
965 # coerce back from string
967 ($format) = ($format =~ /^(\S+)$/) or die "format '$format' includes whitespace\n"; # untaint
968 if (defined($parent)) {
969 ($parent) = ($parent =~ /^(\S+)$/) or die "parent '$parent' includes whitespace\n"; # untaint
971 return wantarray ?
($size, $format, $used, $parent, $st->ctime) : $size;
974 # FIXME remove on the next APIAGE reset.
975 # Deprecated, use get_volume_attribute instead.
976 sub get_volume_notes
{
977 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
979 die "volume notes are not supported for $class";
982 # FIXME remove on the next APIAGE reset.
983 # Deprecated, use update_volume_attribute instead.
984 sub update_volume_notes
{
985 my ($class, $scfg, $storeid, $volname, $notes, $timeout) = @_;
987 die "volume notes are not supported for $class";
990 # Returns undef if the attribute is not supported for the volume.
991 # Should die if there is an error fetching the attribute.
992 # Possible attributes:
993 # notes - user-provided comments/notes.
994 # protected - not to be removed by free_image, and for backups, ignored when pruning.
995 sub get_volume_attribute
{
996 my ($class, $scfg, $storeid, $volname, $attribute) = @_;
998 if ($attribute eq 'notes') {
999 my $notes = eval { $class->get_volume_notes($scfg, $storeid, $volname); };
1001 return if $err =~ m/^volume notes are not supported/;
1010 # Dies if the attribute is not supported for the volume.
1011 sub update_volume_attribute
{
1012 my ($class, $scfg, $storeid, $volname, $attribute, $value) = @_;
1014 if ($attribute eq 'notes') {
1015 $class->update_volume_notes($scfg, $storeid, $volname, $value);
1018 die "attribute '$attribute' is not supported for storage type '$scfg->{type}'\n";
1021 sub volume_size_info
{
1022 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
1023 my $path = $class->filesystem_path($scfg, $volname);
1024 return file_size_info
($path, $timeout);
1029 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
1031 die "can't resize this image format\n" if $volname !~ m/\.(raw|qcow2)$/;
1033 return 1 if $running;
1035 my $path = $class->filesystem_path($scfg, $volname);
1037 my $format = ($class->parse_volname($volname))[6];
1039 my $cmd = ['/usr/bin/qemu-img', 'resize', '-f', $format, $path , $size];
1041 run_command
($cmd, timeout
=> 10);
1046 sub volume_snapshot
{
1047 my ($class, $scfg, $storeid, $volname, $snap) = @_;
1049 die "can't snapshot this image format\n" if $volname !~ m/\.(qcow2|qed)$/;
1051 my $path = $class->filesystem_path($scfg, $volname);
1053 my $cmd = ['/usr/bin/qemu-img', 'snapshot','-c', $snap, $path];
1060 # Asserts that a rollback to $snap on $volname is possible.
1061 # If certain snapshots are preventing the rollback and $blockers is an array
1062 # reference, the snapshot names can be pushed onto $blockers prior to dying.
1063 sub volume_rollback_is_possible
{
1064 my ($class, $scfg, $storeid, $volname, $snap, $blockers) = @_;
1069 sub volume_snapshot_rollback
{
1070 my ($class, $scfg, $storeid, $volname, $snap) = @_;
1072 die "can't rollback snapshot this image format\n" if $volname !~ m/\.(qcow2|qed)$/;
1074 my $path = $class->filesystem_path($scfg, $volname);
1076 my $cmd = ['/usr/bin/qemu-img', 'snapshot','-a', $snap, $path];
1083 sub volume_snapshot_delete
{
1084 my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
1086 die "can't delete snapshot for this image format\n" if $volname !~ m/\.(qcow2|qed)$/;
1088 return 1 if $running;
1090 my $path = $class->filesystem_path($scfg, $volname);
1092 $class->deactivate_volume($storeid, $scfg, $volname, $snap, {});
1094 my $cmd = ['/usr/bin/qemu-img', 'snapshot','-d', $snap, $path];
1101 sub volume_snapshot_needs_fsfreeze
{
1105 sub storage_can_replicate
{
1106 my ($class, $scfg, $storeid, $format) = @_;
1111 sub volume_has_feature
{
1112 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running, $opts) = @_;
1116 current
=> { qcow2
=> 1 },
1117 snap
=> { qcow2
=> 1 },
1120 base
=> { qcow2
=> 1, raw
=> 1, vmdk
=> 1 },
1123 current
=> { qcow2
=> 1, raw
=> 1, vmdk
=> 1, subvol
=> 1 },
1126 base
=> { qcow2
=> 1, raw
=> 1, vmdk
=> 1 },
1127 current
=> { qcow2
=> 1, raw
=> 1, vmdk
=> 1 },
1128 snap
=> { qcow2
=> 1 },
1131 base
=> { qcow2
=> 1, raw
=> 1, vmdk
=> 1 },
1132 current
=> { qcow2
=> 1, raw
=> 1, vmdk
=> 1 },
1135 current
=> {qcow2
=> 1, raw
=> 1, vmdk
=> 1},
1139 if ($feature eq 'clone') {
1141 defined($opts->{valid_target_formats
})
1142 && !(grep { $_ eq 'qcow2' } @{$opts->{valid_target_formats
}})
1144 return 0; # clone_image creates a qcow2 volume
1146 } elsif ($feature eq 'rename') {
1147 return 0 if $class->can('api') && $class->api() < 10;
1151 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) = $class->parse_volname($volname);
1157 $key = $isBase ?
'base' : 'current';
1160 return 1 if defined($features->{$feature}->{$key}->{$format});
1166 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
1168 my $imagedir = $class->get_subdir($scfg, 'images');
1170 my ($defFmt, $vaidFmts) = default_format
($scfg);
1171 my $fmts = join ('|', @$vaidFmts);
1175 foreach my $fn (<$imagedir/[0-9][0-9]*/*>) {
1177 next if $fn !~ m!^(/.+/(\d+)/([^/]+\.($fmts)))$!;
1183 next if !$vollist && defined($vmid) && ($owner ne $vmid);
1185 my ($size, $format, $used, $parent, $ctime) = file_size_info
($fn);
1186 next if !($format && defined($size));
1189 if ($parent && $parent =~ m!^../(\d+)/([^/]+\.($fmts))$!) {
1190 my ($basevmid, $basename) = ($1, $2);
1191 $volid = "$storeid:$basevmid/$basename/$owner/$name";
1193 $volid = "$storeid:$owner/$name";
1197 my $found = grep { $_ eq $volid } @$vollist;
1202 volid
=> $volid, format
=> $format,
1203 size
=> $size, vmid
=> $owner, used
=> $used, parent
=> $parent
1206 $info->{ctime
} = $ctime if $ctime;
1214 # list templates ($tt = <iso|vztmpl|backup|snippets>)
1215 my $get_subdir_files = sub {
1216 my ($sid, $path, $tt, $vmid) = @_;
1220 foreach my $fn (<$path/*>) {
1221 my $st = File
::stat::stat($fn);
1223 next if (!$st || S_ISDIR
($st->mode));
1228 next if $fn !~ m!/([^/]+$PVE::Storage::ISO_EXT_RE_0)$!i;
1230 $info = { volid
=> "$sid:iso/$1", format
=> 'iso' };
1232 } elsif ($tt eq 'vztmpl') {
1233 next if $fn !~ m!/([^/]+$PVE::Storage::VZTMPL_EXT_RE_1)$!;
1235 $info = { volid
=> "$sid:vztmpl/$1", format
=> "t$2" };
1237 } elsif ($tt eq 'backup') {
1238 next if $fn !~ m!/([^/]+$PVE::Storage::BACKUP_EXT_RE_2)$!;
1243 # only match for VMID now, to avoid false positives (VMID in parent directory name)
1244 next if defined($vmid) && $fn !~ m/\S+-$vmid-\S+/;
1246 $info = { volid
=> "$sid:backup/$fn", format
=> $format };
1248 my $archive_info = eval { PVE
::Storage
::archive_info
($fn) } // {};
1250 $info->{ctime
} = $archive_info->{ctime
} if defined($archive_info->{ctime
});
1251 $info->{subtype
} = $archive_info->{type
} // 'unknown';
1253 if (defined($vmid) || $fn =~ m!\-([1-9][0-9]{2,8})\-[^/]+\.${format}$!) {
1254 $info->{vmid
} = $vmid // $1;
1257 my $notes_fn = $original.NOTES_EXT
;
1259 my $notes = PVE
::Tools
::file_read_firstline
($notes_fn);
1260 $info->{notes
} = eval { decode
('UTF-8', $notes, 1) } // $notes if defined($notes);
1263 $info->{protected
} = 1 if -e PVE
::Storage
::protection_file_path
($original);
1264 } elsif ($tt eq 'snippets') {
1267 volid
=> "$sid:snippets/". basename
($fn),
1268 format
=> 'snippet',
1272 $info->{size
} = $st->size;
1273 $info->{ctime
} //= $st->ctime;
1281 # If attributes are set on a volume, they should be included in the result.
1282 # See get_volume_attribute for a list of possible attributes.
1284 my ($class, $storeid, $scfg, $vmid, $content_types) = @_;
1287 my $vmlist = PVE
::Cluster
::get_vmlist
();
1288 foreach my $type (@$content_types) {
1291 if ($type eq 'images' || $type eq 'rootdir') {
1292 $data = $class->list_images($storeid, $scfg, $vmid);
1293 } elsif ($scfg->{path
}) {
1294 my $path = $class->get_subdir($scfg, $type);
1296 if ($type eq 'iso' && !defined($vmid)) {
1297 $data = $get_subdir_files->($storeid, $path, 'iso');
1298 } elsif ($type eq 'vztmpl'&& !defined($vmid)) {
1299 $data = $get_subdir_files->($storeid, $path, 'vztmpl');
1300 } elsif ($type eq 'backup') {
1301 $data = $get_subdir_files->($storeid, $path, 'backup', $vmid);
1302 } elsif ($type eq 'snippets') {
1303 $data = $get_subdir_files->($storeid, $path, 'snippets');
1309 foreach my $item (@$data) {
1310 if ($type eq 'images' || $type eq 'rootdir') {
1311 my $vminfo = $vmlist->{ids
}->{$item->{vmid
}};
1313 if (defined($vminfo)) {
1314 $vmtype = $vminfo->{type
};
1316 if (defined($vmtype) && $vmtype eq 'lxc') {
1317 $item->{content
} = 'rootdir';
1319 $item->{content
} = 'images';
1321 next if $type ne $item->{content
};
1323 $item->{content
} = $type;
1334 my ($class, $storeid, $scfg, $cache) = @_;
1336 my $path = $scfg->{path
};
1338 die "storage definition has no path\n" if !$path;
1341 my $res = PVE
::Tools
::df
($path, $timeout);
1343 return undef if !$res || !$res->{total
};
1345 return ($res->{total
}, $res->{avail
}, $res->{used
}, 1);
1348 # Returns a hash with the snapshot names as keys and the following data:
1349 # id - Unique id to distinguish different snapshots even if the have the same name.
1350 # timestamp - Creation time of the snapshot (seconds since epoch).
1351 # Returns an empty hash if the volume does not exist.
1352 sub volume_snapshot_info
{
1353 my ($class, $scfg, $storeid, $volname) = @_;
1355 die "volume_snapshot_info is not implemented for $class";
1358 sub activate_storage
{
1359 my ($class, $storeid, $scfg, $cache) = @_;
1361 my $path = $scfg->{path
};
1363 die "storage definition has no path\n" if !$path;
1365 # this path test may hang indefinitely on unresponsive mounts
1367 if (! PVE
::Tools
::run_fork_with_timeout
($timeout, sub {-d
$path})) {
1368 die "unable to activate storage '$storeid' - " .
1369 "directory '$path' does not exist or is unreachable\n";
1372 warn "${storeid}: 'mkdir' option is deprecated. Use 'create-base-path' or 'create-subdirs' instead.\n"
1373 if defined($scfg->{mkdir});
1375 # check that content dirs are pairwise inequal
1376 my $resolved_subdirs = {};
1377 if (defined($scfg->{content
})) {
1378 foreach my $vtype (keys $scfg->{content
}->%*) {
1379 my $abs_subdir = abs_path
($class->get_subdir($scfg, $vtype));
1380 die "storage '$storeid' uses directory $abs_subdir for multiple content types\n"
1381 if defined($resolved_subdirs->{$abs_subdir});
1382 $resolved_subdirs->{$abs_subdir} = 1;
1386 return if defined($scfg->{'create-subdirs'}) && !$scfg->{'create-subdirs'};
1388 # FIXME The mkdir option is deprecated. Remove with PVE 9?
1389 return if defined($scfg->{mkdir}) && !$scfg->{mkdir};
1391 if (defined($scfg->{content
})) {
1392 foreach my $vtype (keys %$vtype_subdirs) {
1393 # OpenVZMigrate uses backup (dump) dir
1394 if (defined($scfg->{content
}->{$vtype}) ||
1395 ($vtype eq 'backup' && defined($scfg->{content
}->{'rootdir'}))) {
1396 my $subdir = $class->get_subdir($scfg, $vtype);
1397 mkpath
$subdir if $subdir ne $path;
1403 sub deactivate_storage
{
1404 my ($class, $storeid, $scfg, $cache) = @_;
1406 # do nothing by default
1410 my ($class, $storeid, $scfg, $volname, $snapname) = @_;
1412 my ($path) = $class->path($scfg, $volname, $storeid, $snapname);
1417 my ($class, $storeid, $scfg, $volname, $snapname) = @_;
1422 sub activate_volume
{
1423 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
1425 my $path = $class->filesystem_path($scfg, $volname, $snapname);
1427 # check is volume exists
1428 if ($scfg->{path
}) {
1429 die "volume '$storeid:$volname' does not exist\n" if ! -e
$path;
1431 die "volume '$storeid:$volname' does not exist\n" if ! -b
$path;
1435 sub deactivate_volume
{
1436 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
1438 # do nothing by default
1441 sub check_connection
{
1442 my ($class, $storeid, $scfg) = @_;
1443 # do nothing by default
1448 my ($class, $scfg, $storeid, $keep, $vmid, $type, $dryrun, $logfunc) = @_;
1450 $logfunc //= sub { print "$_[1]\n" };
1452 my $backups = $class->list_volumes($storeid, $scfg, $vmid, ['backup']);
1454 my $backup_groups = {};
1455 my $prune_list = [];
1457 foreach my $backup (@{$backups}) {
1458 my $volid = $backup->{volid
};
1459 my $archive_info = eval { PVE
::Storage
::archive_info
($volid) } // {};
1460 my $backup_type = $archive_info->{type
} // 'unknown';
1461 my $backup_vmid = $archive_info->{vmid
} // $backup->{vmid
};
1463 next if defined($type) && $type ne $backup_type;
1466 ctime
=> $backup->{ctime
},
1467 type
=> $backup_type,
1471 $prune_entry->{vmid
} = $backup_vmid if defined($backup_vmid);
1473 if ($archive_info->{is_std_name
}) {
1474 die "internal error - got no VMID\n" if !defined($backup_vmid);
1475 die "internal error - got wrong VMID '$backup_vmid' != '$vmid'\n"
1476 if defined($vmid) && $backup_vmid ne $vmid;
1478 $prune_entry->{ctime
} = $archive_info->{ctime
};
1479 my $group = "$backup_type/$backup_vmid";
1480 push @{$backup_groups->{$group}}, $prune_entry;
1482 # ignore backups that don't use the standard naming scheme
1483 $prune_entry->{mark
} = 'renamed';
1486 $prune_entry->{mark
} = 'protected' if $backup->{protected
};
1488 push @{$prune_list}, $prune_entry;
1491 foreach my $backup_group (values %{$backup_groups}) {
1492 PVE
::Storage
::prune_mark_backup_group
($backup_group, $keep);
1497 foreach my $prune_entry (@{$prune_list}) {
1498 next if $prune_entry->{mark
} ne 'remove';
1500 my $volid = $prune_entry->{volid
};
1501 $logfunc->('info', "removing backup '$volid'");
1503 my (undef, $volname) = parse_volume_id
($volid);
1504 my $archive_path = $class->filesystem_path($scfg, $volname);
1505 PVE
::Storage
::archive_remove
($archive_path);
1508 $logfunc->('err', "error when removing backup '$volid' - $err\n");
1513 die "error pruning backups - check log\n" if $failed;
1518 # Import/Export interface:
1519 # Any path based storage is assumed to support 'raw' and 'tar' streams, so
1520 # the default implementations will return this if $scfg->{path} is set,
1521 # mimicking the old PVE::Storage::storage_migrate() function.
1523 # Plugins may fall back to PVE::Storage::Plugin::volume_{export,import}...
1524 # functions in case the format doesn't match their specialized
1525 # implementations to reuse the raw/tar code.
1527 # Format specification:
1528 # The following formats are all prefixed with image information in the form
1529 # of a 64 bit little endian unsigned integer (pack('Q<')) in order to be able
1530 # to preallocate the image on storages which require it.
1532 # raw+size: (image files only)
1533 # A raw binary data stream such as produced via `dd if=TheImageFile`.
1534 # qcow2+size, vmdk: (image files only)
1535 # A raw qcow2/vmdk/... file such as produced via `dd if=some.qcow2` for
1536 # files which are already in qcow2 format, or via `qemu-img convert`.
1537 # Note that these formats are only valid with $with_snapshots being true.
1538 # tar+size: (subvolumes only)
1539 # A GNU tar stream containing just the inner contents of the subvolume.
1540 # This does not distinguish between the contents of a privileged or
1541 # unprivileged container. In other words, this is from the root user
1542 # namespace's point of view with no uid-mapping in effect.
1543 # As produced via `tar -C vm-100-disk-1.subvol -cpf TheOutputFile.dat .`
1545 # Plugins may reuse these helpers. Changes to the header format should be
1546 # reflected by changes to the function prototypes.
1547 sub write_common_header
($$) {
1548 my ($fh, $image_size_in_bytes) = @_;
1549 syswrite($fh, pack("Q<", $image_size_in_bytes), 8);
1552 sub read_common_header
($) {
1554 sysread($fh, my $size, 8);
1555 $size = unpack('Q<', $size);
1556 die "import: no size found in export header, aborting.\n" if !defined($size);
1561 # Export a volume into a file handle as a stream of desired format.
1563 my ($class, $scfg, $storeid, $fh, $volname, $format, $snapshot, $base_snapshot, $with_snapshots) = @_;
1564 if ($scfg->{path
} && !defined($snapshot) && !defined($base_snapshot)) {
1565 my $file = $class->path($scfg, $volname, $storeid)
1566 or goto unsupported
;
1567 my ($size, $file_format) = file_size_info
($file);
1569 if ($format eq 'raw+size') {
1570 goto unsupported
if $with_snapshots || $file_format eq 'subvol';
1571 write_common_header
($fh, $size);
1572 if ($file_format eq 'raw') {
1573 run_command
(['dd', "if=$file", "bs=4k"], output
=> '>&'.fileno($fh));
1575 run_command
(['qemu-img', 'convert', '-f', $file_format, '-O', 'raw', $file, '/dev/stdout'],
1576 output
=> '>&'.fileno($fh));
1579 } elsif ($format =~ /^(qcow2|vmdk)\+size$/) {
1580 my $data_format = $1;
1581 goto unsupported
if !$with_snapshots || $file_format ne $data_format;
1582 write_common_header
($fh, $size);
1583 run_command
(['dd', "if=$file", "bs=4k"], output
=> '>&'.fileno($fh));
1585 } elsif ($format eq 'tar+size') {
1586 goto unsupported
if $file_format ne 'subvol';
1587 write_common_header
($fh, $size);
1588 run_command
(['tar', @COMMON_TAR_FLAGS, '-cf', '-', '-C', $file, '.'],
1589 output
=> '>&'.fileno($fh));
1594 die "volume export format $format not available for $class";
1597 sub volume_export_formats
{
1598 my ($class, $scfg, $storeid, $volname, $snapshot, $base_snapshot, $with_snapshots) = @_;
1599 if ($scfg->{path
} && !defined($snapshot) && !defined($base_snapshot)) {
1600 my $file = $class->path($scfg, $volname, $storeid)
1602 my ($size, $format) = file_size_info
($file);
1604 if ($with_snapshots) {
1605 return ($format.'+size') if ($format eq 'qcow2' || $format eq 'vmdk');
1608 return ('tar+size') if $format eq 'subvol';
1609 return ('raw+size');
1614 # Import data from a stream, creating a new or replacing or adding to an existing volume.
1616 my ($class, $scfg, $storeid, $fh, $volname, $format, $snapshot, $base_snapshot, $with_snapshots, $allow_rename) = @_;
1618 die "volume import format '$format' not available for $class\n"
1619 if $format !~ /^(raw|tar|qcow2|vmdk)\+size$/;
1620 my $data_format = $1;
1622 die "format $format cannot be imported without snapshots\n"
1623 if !$with_snapshots && ($data_format eq 'qcow2' || $data_format eq 'vmdk');
1624 die "format $format cannot be imported with snapshots\n"
1625 if $with_snapshots && ($data_format eq 'raw' || $data_format eq 'tar');
1627 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $file_format) =
1628 $class->parse_volname($volname);
1630 # XXX: Should we bother with conversion routines at this level? This won't
1631 # happen without manual CLI usage, so for now we just error out...
1632 die "cannot import format $format into a file of format $file_format\n"
1633 if $data_format ne $file_format && !($data_format eq 'tar' && $file_format eq 'subvol');
1635 # Check for an existing file first since interrupting alloc_image doesn't
1637 my $file = $class->path($scfg, $volname, $storeid);
1639 die "file '$file' already exists\n" if !$allow_rename;
1640 warn "file '$file' already exists - importing with a different name\n";
1644 my ($size) = read_common_header
($fh);
1645 $size = int($size/1024);
1648 my $allocname = $class->alloc_image($storeid, $scfg, $vmid, $file_format, $name, $size);
1649 my $oldname = $volname;
1650 $volname = $allocname;
1651 if (defined($name) && $allocname ne $oldname) {
1652 die "internal error: unexpected allocated name: '$allocname' != '$oldname'\n";
1654 my $file = $class->path($scfg, $volname, $storeid)
1655 or die "internal error: failed to get path to newly allocated volume $volname\n";
1656 if ($data_format eq 'raw' || $data_format eq 'qcow2' || $data_format eq 'vmdk') {
1657 run_command
(['dd', "of=$file", 'conv=sparse', 'bs=64k'],
1658 input
=> '<&'.fileno($fh));
1659 } elsif ($data_format eq 'tar') {
1660 run_command
(['tar', @COMMON_TAR_FLAGS, '-C', $file, '-xf', '-'],
1661 input
=> '<&'.fileno($fh));
1663 die "volume import format '$format' not available for $class";
1667 eval { $class->free_image($storeid, $scfg, $volname, 0, $file_format) };
1672 return "$storeid:$volname";
1675 sub volume_import_formats
{
1676 my ($class, $scfg, $storeid, $volname, $snapshot, $base_snapshot, $with_snapshots) = @_;
1677 if ($scfg->{path
} && !defined($base_snapshot)) {
1678 my $format = ($class->parse_volname($volname))[6];
1679 if ($with_snapshots) {
1680 return ($format.'+size') if ($format eq 'qcow2' || $format eq 'vmdk');
1683 return ('tar+size') if $format eq 'subvol';
1684 return ('raw+size');
1690 my ($class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname) = @_;
1691 die "not implemented in storage plugin '$class'\n" if $class->can('api') && $class->api() < 10;
1692 die "no path found\n" if !$scfg->{path
};
1702 ) = $class->parse_volname($source_volname);
1704 $target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format, 1)
1705 if !$target_volname;
1707 my $basedir = $class->get_subdir($scfg, 'images');
1709 mkpath
"${basedir}/${target_vmid}";
1711 my $old_path = "${basedir}/${source_vmid}/${source_image}";
1712 my $new_path = "${basedir}/${target_vmid}/${target_volname}";
1714 die "target volume '${target_volname}' already exists\n" if -e
$new_path;
1716 my $base = $base_name ?
"${base_vmid}/${base_name}/" : '';
1718 rename($old_path, $new_path) ||
1719 die "rename '$old_path' to '$new_path' failed - $!\n";
1721 return "${storeid}:${base}${target_vmid}/${target_volname}";
1724 sub config_aware_base_mkdir
{
1725 my ($class, $scfg, $path) = @_;
1727 # FIXME the mkdir parameter is deprecated and create-base-path should be used
1728 if ($scfg->{'create-base-path'} // $scfg->{mkdir} // 1) {