]> git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/Plugin.pm
LIO: drop unused statements
[pve-storage.git] / PVE / Storage / Plugin.pm
1 package PVE::Storage::Plugin;
2
3 use strict;
4 use warnings;
5
6 use Fcntl ':mode';
7 use File::chdir;
8 use File::Path;
9 use File::Basename;
10 use File::stat qw();
11
12 use PVE::Tools qw(run_command);
13 use PVE::JSONSchema qw(get_standard_option register_standard_option);
14 use PVE::Cluster qw(cfs_register_file);
15
16 use JSON;
17
18 use base qw(PVE::SectionConfig);
19
20 use constant COMPRESSOR_RE => 'gz|lzo|zst';
21
22 our @COMMON_TAR_FLAGS = qw(
23 --one-file-system
24 -p --sparse --numeric-owner --acls
25 --xattrs --xattrs-include=user.* --xattrs-include=security.capability
26 --warning=no-file-ignored --warning=no-xattr-write
27 );
28
29 our @SHARED_STORAGE = (
30 'iscsi',
31 'nfs',
32 'cifs',
33 'rbd',
34 'cephfs',
35 'iscsidirect',
36 'glusterfs',
37 'zfs',
38 'drbd');
39
40 our $MAX_VOLUMES_PER_GUEST = 1024;
41
42 cfs_register_file ('storage.cfg',
43 sub { __PACKAGE__->parse_config(@_); },
44 sub { __PACKAGE__->write_config(@_); });
45
46 my %prune_option = (
47 optional => 1,
48 type => 'integer', minimum => '0',
49 format_description => 'N',
50 );
51
52 our $prune_backups_format = {
53 'keep-last' => {
54 %prune_option,
55 description => 'Keep the last <N> backups.',
56 },
57 'keep-hourly' => {
58 %prune_option,
59 description => 'Keep backups for the last <N> different hours. If there is more' .
60 'than one backup for a single hour, only the latest one is kept.'
61 },
62 'keep-daily' => {
63 %prune_option,
64 description => 'Keep backups for the last <N> different days. If there is more' .
65 'than one backup for a single day, only the latest one is kept.'
66 },
67 'keep-weekly' => {
68 %prune_option,
69 description => 'Keep backups for the last <N> different weeks. If there is more' .
70 'than one backup for a single week, only the latest one is kept.'
71 },
72 'keep-monthly' => {
73 %prune_option,
74 description => 'Keep backups for the last <N> different months. If there is more' .
75 'than one backup for a single month, only the latest one is kept.'
76 },
77 'keep-yearly' => {
78 %prune_option,
79 description => 'Keep backups for the last <N> different years. If there is more' .
80 'than one backup for a single year, only the latest one is kept.'
81 },
82 };
83 PVE::JSONSchema::register_format('prune-backups', $prune_backups_format, \&validate_prune_backups);
84 sub validate_prune_backups {
85 my ($keep) = @_;
86
87 die "at least one keep-option must be set and positive\n"
88 if !grep { $_ } values %{$keep};
89
90 return $keep;
91 }
92 register_standard_option('prune-backups', {
93 description => "The retention options with shorter intervals are processed first " .
94 "with --keep-last being the very first one. Each option covers a " .
95 "specific period of time. We say that backups within this period " .
96 "are covered by this option. The next option does not take care " .
97 "of already covered backups and only considers older backups.",
98 optional => 1,
99 type => 'string',
100 format => 'prune-backups',
101 });
102
103 my $defaultData = {
104 propertyList => {
105 type => { description => "Storage type." },
106 storage => get_standard_option('pve-storage-id',
107 { completion => \&PVE::Storage::complete_storage }),
108 nodes => get_standard_option('pve-node-list', { optional => 1 }),
109 content => {
110 description => "Allowed content types.\n\nNOTE: the value " .
111 "'rootdir' is used for Containers, and value 'images' for VMs.\n",
112 type => 'string', format => 'pve-storage-content-list',
113 optional => 1,
114 completion => \&PVE::Storage::complete_content_type,
115 },
116 disable => {
117 description => "Flag to disable the storage.",
118 type => 'boolean',
119 optional => 1,
120 },
121 maxfiles => {
122 description => "Maximal number of backup files per VM. Use '0' for unlimted.",
123 type => 'integer',
124 minimum => 0,
125 optional => 1,
126 },
127 'prune-backups' => get_standard_option('prune-backups'),
128 shared => {
129 description => "Mark storage as shared.",
130 type => 'boolean',
131 optional => 1,
132 },
133 'format' => {
134 description => "Default image format.",
135 type => 'string', format => 'pve-storage-format',
136 optional => 1,
137 },
138 },
139 };
140
141 sub content_hash_to_string {
142 my $hash = shift;
143
144 my @cta;
145 foreach my $ct (keys %$hash) {
146 push @cta, $ct if $hash->{$ct};
147 }
148
149 return join(',', @cta);
150 }
151
152 sub valid_content_types {
153 my ($type) = @_;
154
155 my $def = $defaultData->{plugindata}->{$type};
156
157 return {} if !$def;
158
159 return $def->{content}->[0];
160 }
161
162 sub default_format {
163 my ($scfg) = @_;
164
165 my $type = $scfg->{type};
166 my $def = $defaultData->{plugindata}->{$type};
167
168 my $def_format = 'raw';
169 my $valid_formats = [ $def_format ];
170
171 if (defined($def->{format})) {
172 $def_format = $scfg->{format} || $def->{format}->[1];
173 $valid_formats = [ sort keys %{$def->{format}->[0]} ];
174 }
175
176 return wantarray ? ($def_format, $valid_formats) : $def_format;
177 }
178
179 PVE::JSONSchema::register_format('pve-storage-path', \&verify_path);
180 sub verify_path {
181 my ($path, $noerr) = @_;
182
183 # fixme: exclude more shell meta characters?
184 # we need absolute paths
185 if ($path !~ m|^/[^;\(\)]+|) {
186 return undef if $noerr;
187 die "value does not look like a valid absolute path\n";
188 }
189 return $path;
190 }
191
192 PVE::JSONSchema::register_format('pve-storage-server', \&verify_server);
193 sub verify_server {
194 my ($server, $noerr) = @_;
195
196 if (!(PVE::JSONSchema::pve_verify_ip($server, 1) ||
197 PVE::JSONSchema::pve_verify_dns_name($server, 1)))
198 {
199 return undef if $noerr;
200 die "value does not look like a valid server name or IP address\n";
201 }
202 return $server;
203 }
204
205 PVE::JSONSchema::register_format('pve-storage-vgname', \&parse_lvm_name);
206 sub parse_lvm_name {
207 my ($name, $noerr) = @_;
208
209 if ($name !~ m/^[a-z0-9][a-z0-9\-\_\.]*[a-z0-9]$/i) {
210 return undef if $noerr;
211 die "lvm name '$name' contains illegal characters\n";
212 }
213
214 return $name;
215 }
216
217 # fixme: do we need this
218 #PVE::JSONSchema::register_format('pve-storage-portal', \&verify_portal);
219 #sub verify_portal {
220 # my ($portal, $noerr) = @_;
221 #
222 # # IP with optional port
223 # if ($portal !~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d+)?$/) {
224 # return undef if $noerr;
225 # die "value does not look like a valid portal address\n";
226 # }
227 # return $portal;
228 #}
229
230 PVE::JSONSchema::register_format('pve-storage-portal-dns', \&verify_portal_dns);
231 sub verify_portal_dns {
232 my ($portal, $noerr) = @_;
233
234 # IP or DNS name with optional port
235 if (!PVE::Tools::parse_host_and_port($portal)) {
236 return undef if $noerr;
237 die "value does not look like a valid portal address\n";
238 }
239 return $portal;
240 }
241
242 PVE::JSONSchema::register_format('pve-storage-content', \&verify_content);
243 sub verify_content {
244 my ($ct, $noerr) = @_;
245
246 my $valid_content = valid_content_types('dir'); # dir includes all types
247
248 if (!$valid_content->{$ct}) {
249 return undef if $noerr;
250 die "invalid content type '$ct'\n";
251 }
252
253 return $ct;
254 }
255
256 PVE::JSONSchema::register_format('pve-storage-format', \&verify_format);
257 sub verify_format {
258 my ($fmt, $noerr) = @_;
259
260 if ($fmt !~ m/(raw|qcow2|vmdk|subvol)/) {
261 return undef if $noerr;
262 die "invalid format '$fmt'\n";
263 }
264
265 return $fmt;
266 }
267
268 PVE::JSONSchema::register_format('pve-storage-options', \&verify_options);
269 sub verify_options {
270 my ($value, $noerr) = @_;
271
272 # mount options (see man fstab)
273 if ($value !~ m/^\S+$/) {
274 return undef if $noerr;
275 die "invalid options '$value'\n";
276 }
277
278 return $value;
279 }
280
281 PVE::JSONSchema::register_format('pve-volume-id', \&parse_volume_id);
282 sub parse_volume_id {
283 my ($volid, $noerr) = @_;
284
285 if ($volid =~ m/^([a-z][a-z0-9\-\_\.]*[a-z0-9]):(.+)$/i) {
286 return wantarray ? ($1, $2) : $1;
287 }
288 return undef if $noerr;
289 die "unable to parse volume ID '$volid'\n";
290 }
291
292
293 sub private {
294 return $defaultData;
295 }
296
297 sub parse_section_header {
298 my ($class, $line) = @_;
299
300 if ($line =~ m/^(\S+):\s*(\S+)\s*$/) {
301 my ($type, $storeid) = (lc($1), $2);
302 my $errmsg = undef; # set if you want to skip whole section
303 eval { PVE::JSONSchema::parse_storage_id($storeid); };
304 $errmsg = $@ if $@;
305 my $config = {}; # to return additional attributes
306 return ($type, $storeid, $errmsg, $config);
307 }
308 return undef;
309 }
310
311 sub decode_value {
312 my ($class, $type, $key, $value) = @_;
313
314 my $def = $defaultData->{plugindata}->{$type};
315
316 if ($key eq 'content') {
317 my $valid_content = $def->{content}->[0];
318
319 my $res = {};
320
321 foreach my $c (PVE::Tools::split_list($value)) {
322 if (!$valid_content->{$c}) {
323 warn "storage does not support content type '$c'\n";
324 next;
325 }
326 $res->{$c} = 1;
327 }
328
329 if ($res->{none} && scalar (keys %$res) > 1) {
330 die "unable to combine 'none' with other content types\n";
331 }
332
333 return $res;
334 } elsif ($key eq 'format') {
335 my $valid_formats = $def->{format}->[0];
336
337 if (!$valid_formats->{$value}) {
338 warn "storage does not support format '$value'\n";
339 next;
340 }
341
342 return $value;
343 } elsif ($key eq 'nodes') {
344 my $res = {};
345
346 foreach my $node (PVE::Tools::split_list($value)) {
347 if (PVE::JSONSchema::pve_verify_node_name($node)) {
348 $res->{$node} = 1;
349 }
350 }
351
352 # fixme:
353 # no node restrictions for local storage
354 #if ($storeid && $storeid eq 'local' && scalar(keys(%$res))) {
355 # die "storage '$storeid' does not allow node restrictions\n";
356 #}
357
358 return $res;
359 }
360
361 return $value;
362 }
363
364 sub encode_value {
365 my ($class, $type, $key, $value) = @_;
366
367 if ($key eq 'nodes') {
368 return join(',', keys(%$value));
369 } elsif ($key eq 'content') {
370 my $res = content_hash_to_string($value) || 'none';
371 return $res;
372 }
373
374 return $value;
375 }
376
377 sub parse_config {
378 my ($class, $filename, $raw) = @_;
379
380 my $cfg = $class->SUPER::parse_config($filename, $raw);
381 my $ids = $cfg->{ids};
382
383 # make sure we have a reasonable 'local:' storage
384 # we want 'local' to be always the same 'type' (on all cluster nodes)
385 if (!$ids->{local} || $ids->{local}->{type} ne 'dir' ||
386 ($ids->{local}->{path} && $ids->{local}->{path} ne '/var/lib/vz')) {
387 $ids->{local} = {
388 type => 'dir',
389 priority => 0, # force first entry
390 path => '/var/lib/vz',
391 maxfiles => 0,
392 content => { images => 1, rootdir => 1, vztmpl => 1, iso => 1, snippets => 1},
393 };
394 }
395
396 # make sure we have a path
397 $ids->{local}->{path} = '/var/lib/vz' if !$ids->{local}->{path};
398
399 # remove node restrictions for local storage
400 delete($ids->{local}->{nodes});
401
402 foreach my $storeid (keys %$ids) {
403 my $d = $ids->{$storeid};
404 my $type = $d->{type};
405
406 my $def = $defaultData->{plugindata}->{$type};
407
408 if ($def->{content}) {
409 $d->{content} = $def->{content}->[1] if !$d->{content};
410 }
411 if (grep { $_ eq $type } @SHARED_STORAGE) {
412 $d->{shared} = 1;
413 }
414 }
415
416 return $cfg;
417 }
418
419 # Storage implementation
420
421 # called during addition of storage (before the new storage config got written)
422 # die to abort additon if there are (grave) problems
423 # NOTE: runs in a storage config *locked* context
424 sub on_add_hook {
425 my ($class, $storeid, $scfg, %param) = @_;
426
427 # do nothing by default
428 }
429
430 # called during storage configuration update (before the updated storage config got written)
431 # die to abort the update if there are (grave) problems
432 # NOTE: runs in a storage config *locked* context
433 sub on_update_hook {
434 my ($class, $storeid, $scfg, %param) = @_;
435
436 # do nothing by default
437 }
438
439 # called during deletion of storage (before the new storage config got written)
440 # and if the activate check on addition fails, to cleanup all storage traces
441 # which on_add_hook may have created.
442 # die to abort deletion if there are (very grave) problems
443 # NOTE: runs in a storage config *locked* context
444 sub on_delete_hook {
445 my ($class, $storeid, $scfg) = @_;
446
447 # do nothing by default
448 }
449
450 sub cluster_lock_storage {
451 my ($class, $storeid, $shared, $timeout, $func, @param) = @_;
452
453 my $res;
454 if (!$shared) {
455 my $lockid = "pve-storage-$storeid";
456 my $lockdir = "/var/lock/pve-manager";
457 mkdir $lockdir;
458 $res = PVE::Tools::lock_file("$lockdir/$lockid", $timeout, $func, @param);
459 die $@ if $@;
460 } else {
461 $res = PVE::Cluster::cfs_lock_storage($storeid, $timeout, $func, @param);
462 die $@ if $@;
463 }
464 return $res;
465 }
466
467 sub parse_name_dir {
468 my $name = shift;
469
470 if ($name =~ m!^((base-)?[^/\s]+\.(raw|qcow2|vmdk|subvol))$!) {
471 return ($1, $3, $2); # (name, format, isBase)
472 }
473
474 die "unable to parse volume filename '$name'\n";
475 }
476
477 sub parse_volname {
478 my ($class, $volname) = @_;
479
480 if ($volname =~ m!^(\d+)/(\S+)/(\d+)/(\S+)$!) {
481 my ($basedvmid, $basename) = ($1, $2);
482 parse_name_dir($basename);
483 my ($vmid, $name) = ($3, $4);
484 my (undef, $format, $isBase) = parse_name_dir($name);
485 return ('images', $name, $vmid, $basename, $basedvmid, $isBase, $format);
486 } elsif ($volname =~ m!^(\d+)/(\S+)$!) {
487 my ($vmid, $name) = ($1, $2);
488 my (undef, $format, $isBase) = parse_name_dir($name);
489 return ('images', $name, $vmid, undef, undef, $isBase, $format);
490 } elsif ($volname =~ m!^iso/([^/]+$PVE::Storage::iso_extension_re)$!) {
491 return ('iso', $1);
492 } elsif ($volname =~ m!^vztmpl/([^/]+\.tar\.[gx]z)$!) {
493 return ('vztmpl', $1);
494 } elsif ($volname =~ m!^rootdir/(\d+)$!) {
495 return ('rootdir', $1, $1);
496 } elsif ($volname =~ m!^backup/([^/]+(?:\.(?:tgz|(?:(?:tar|vma)(?:\.(?:${\COMPRESSOR_RE}))?))))$!) {
497 my $fn = $1;
498 if ($fn =~ m/^vzdump-(openvz|lxc|qemu)-(\d+)-.+/) {
499 return ('backup', $fn, $2);
500 }
501 return ('backup', $fn);
502 } elsif ($volname =~ m!^snippets/([^/]+)$!) {
503 return ('snippets', $1);
504 }
505
506 die "unable to parse directory volume name '$volname'\n";
507 }
508
509 my $vtype_subdirs = {
510 images => 'images',
511 rootdir => 'private',
512 iso => 'template/iso',
513 vztmpl => 'template/cache',
514 backup => 'dump',
515 snippets => 'snippets',
516 };
517
518 sub get_vtype_subdirs {
519 return $vtype_subdirs;
520 }
521
522 sub get_subdir {
523 my ($class, $scfg, $vtype) = @_;
524
525 my $path = $scfg->{path};
526
527 die "storage definintion has no path\n" if !$path;
528
529 my $subdir = $vtype_subdirs->{$vtype};
530
531 die "unknown vtype '$vtype'\n" if !defined($subdir);
532
533 return "$path/$subdir";
534 }
535
536 sub filesystem_path {
537 my ($class, $scfg, $volname, $snapname) = @_;
538
539 my ($vtype, $name, $vmid, undef, undef, $isBase, $format) =
540 $class->parse_volname($volname);
541
542 # Note: qcow2/qed has internal snapshot, so path is always
543 # the same (with or without snapshot => same file).
544 die "can't snapshot this image format\n"
545 if defined($snapname) && $format !~ m/^(qcow2|qed)$/;
546
547 my $dir = $class->get_subdir($scfg, $vtype);
548
549 $dir .= "/$vmid" if $vtype eq 'images';
550
551 my $path = "$dir/$name";
552
553 return wantarray ? ($path, $vmid, $vtype) : $path;
554 }
555
556 sub path {
557 my ($class, $scfg, $volname, $storeid, $snapname) = @_;
558
559 return $class->filesystem_path($scfg, $volname, $snapname);
560 }
561
562 sub create_base {
563 my ($class, $storeid, $scfg, $volname) = @_;
564
565 # this only works for file based storage types
566 die "storage definition has no path\n" if !$scfg->{path};
567
568 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) =
569 $class->parse_volname($volname);
570
571 die "create_base on wrong vtype '$vtype'\n" if $vtype ne 'images';
572
573 die "create_base not possible with base image\n" if $isBase;
574
575 my $path = $class->filesystem_path($scfg, $volname);
576
577 my ($size, undef, $used, $parent) = file_size_info($path);
578 die "file_size_info on '$volname' failed\n" if !($format && defined($size));
579
580 die "volname '$volname' contains wrong information about parent\n"
581 if $basename && (!$parent || $parent ne "../$basevmid/$basename");
582
583 my $newname = $name;
584 $newname =~ s/^vm-/base-/;
585
586 my $newvolname = $basename ? "$basevmid/$basename/$vmid/$newname" :
587 "$vmid/$newname";
588
589 my $newpath = $class->filesystem_path($scfg, $newvolname);
590
591 die "file '$newpath' already exists\n" if -f $newpath;
592
593 rename($path, $newpath) ||
594 die "rename '$path' to '$newpath' failed - $!\n";
595
596 # We try to protect base volume
597
598 chmod(0444, $newpath); # nobody should write anything
599
600 # also try to set immutable flag
601 eval { run_command(['/usr/bin/chattr', '+i', $newpath]); };
602 warn $@ if $@;
603
604 return $newvolname;
605 }
606
607 my $get_vm_disk_number = sub {
608 my ($disk_name, $scfg, $vmid, $suffix) = @_;
609
610 my $disk_regex = qr/(vm|base)-$vmid-disk-(\d+)$suffix/;
611
612 my $type = $scfg->{type};
613 my $def = { %{$defaultData->{plugindata}->{$type}} };
614
615 my $valid = $def->{format}[0];
616 if ($valid->{subvol}) {
617 $disk_regex = qr/(vm|base|subvol|basevol)-$vmid-disk-(\d+)/;
618 }
619
620 if ($disk_name =~ m/$disk_regex/) {
621 return $2;
622 }
623
624 return undef;
625 };
626
627 sub get_next_vm_diskname {
628 my ($disk_list, $storeid, $vmid, $fmt, $scfg, $add_fmt_suffix) = @_;
629
630 $fmt //= '';
631 my $prefix = ($fmt eq 'subvol') ? 'subvol' : 'vm';
632 my $suffix = $add_fmt_suffix ? ".$fmt" : '';
633
634 my $disk_ids = {};
635 foreach my $disk (@$disk_list) {
636 my $disknum = $get_vm_disk_number->($disk, $scfg, $vmid, $suffix);
637 $disk_ids->{$disknum} = 1 if defined($disknum);
638 }
639
640 for (my $i = 0; $i < $MAX_VOLUMES_PER_GUEST; $i++) {
641 if (!$disk_ids->{$i}) {
642 return "$prefix-$vmid-disk-$i$suffix";
643 }
644 }
645
646 die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
647 }
648
649 sub find_free_diskname {
650 my ($class, $storeid, $scfg, $vmid, $fmt, $add_fmt_suffix) = @_;
651
652 my $disks = $class->list_images($storeid, $scfg, $vmid);
653
654 my $disk_list = [ map { $_->{volid} } @$disks ];
655
656 return get_next_vm_diskname($disk_list, $storeid, $vmid, $fmt, $scfg, $add_fmt_suffix);
657 }
658
659 sub clone_image {
660 my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
661
662 # this only works for file based storage types
663 die "storage definintion has no path\n" if !$scfg->{path};
664
665 my ($vtype, $basename, $basevmid, undef, undef, $isBase, $format) =
666 $class->parse_volname($volname);
667
668 die "clone_image on wrong vtype '$vtype'\n" if $vtype ne 'images';
669
670 die "this storage type does not support clone_image on snapshot\n" if $snap;
671
672 die "this storage type does not support clone_image on subvolumes\n" if $format eq 'subvol';
673
674 die "clone_image only works on base images\n" if !$isBase;
675
676 my $imagedir = $class->get_subdir($scfg, 'images');
677 $imagedir .= "/$vmid";
678
679 mkpath $imagedir;
680
681 my $name = $class->find_free_diskname($imagedir, $scfg, $vmid, "qcow2", 1);
682
683 warn "clone $volname: $vtype, $name, $vmid to $name (base=../$basevmid/$basename)\n";
684
685 my $newvol = "$basevmid/$basename/$vmid/$name";
686
687 my $path = $class->filesystem_path($scfg, $newvol);
688
689 # Note: we use relative paths, so we need to call chdir before qemu-img
690 eval {
691 local $CWD = $imagedir;
692
693 my $cmd = ['/usr/bin/qemu-img', 'create', '-b', "../$basevmid/$basename",
694 '-f', 'qcow2', $path];
695
696 run_command($cmd);
697 };
698 my $err = $@;
699
700 die $err if $err;
701
702 return $newvol;
703 }
704
705 sub alloc_image {
706 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
707
708 my $imagedir = $class->get_subdir($scfg, 'images');
709 $imagedir .= "/$vmid";
710
711 mkpath $imagedir;
712
713 $name = $class->find_free_diskname($imagedir, $scfg, $vmid, $fmt, 1) if !$name;
714
715 my (undef, $tmpfmt) = parse_name_dir($name);
716
717 die "illegal name '$name' - wrong extension for format ('$tmpfmt != '$fmt')\n"
718 if $tmpfmt ne $fmt;
719
720 my $path = "$imagedir/$name";
721
722 die "disk image '$path' already exists\n" if -e $path;
723
724 if ($fmt eq 'subvol') {
725 # only allow this if size = 0, so that user knows what he is doing
726 die "storage does not support subvol quotas\n" if $size != 0;
727
728 my $old_umask = umask(0022);
729 my $err;
730 mkdir($path) or $err = "unable to create subvol '$path' - $!\n";
731 umask $old_umask;
732 die $err if $err;
733 } else {
734 my $cmd = ['/usr/bin/qemu-img', 'create'];
735
736 push @$cmd, '-o', 'preallocation=metadata' if $fmt eq 'qcow2';
737
738 push @$cmd, '-f', $fmt, $path, "${size}K";
739
740 eval { run_command($cmd, errmsg => "unable to create image"); };
741 if ($@) {
742 unlink $path;
743 rmdir $imagedir;
744 die "$@";
745 }
746 }
747
748 return "$vmid/$name";
749 }
750
751 sub free_image {
752 my ($class, $storeid, $scfg, $volname, $isBase, $format) = @_;
753
754 my $path = $class->filesystem_path($scfg, $volname);
755
756 if ($isBase) {
757 # try to remove immutable flag
758 eval { run_command(['/usr/bin/chattr', '-i', $path]); };
759 warn $@ if $@;
760 }
761
762 if (defined($format) && ($format eq 'subvol')) {
763 File::Path::remove_tree($path);
764 } else {
765 if (!(-f $path || -l $path)) {
766 warn "disk image '$path' does not exist\n";
767 return undef;
768 }
769
770 unlink($path) || die "unlink '$path' failed - $!\n";
771 }
772
773 # try to cleanup directory to not clutter storage with empty $vmid dirs if
774 # all images from a guest got deleted
775 my $dir = dirname($path);
776 rmdir($dir);
777
778 return undef;
779 }
780
781 sub file_size_info {
782 my ($filename, $timeout) = @_;
783
784 my $st = File::stat::stat($filename);
785
786 if (!defined($st)) {
787 my $extramsg = -l $filename ? ' - dangling symlink?' : '';
788 warn "failed to stat '$filename'$extramsg\n";
789 return undef;
790 }
791
792 if (S_ISDIR($st->mode)) {
793 return wantarray ? (0, 'subvol', 0, undef, $st->ctime) : 1;
794 }
795
796 my $json = '';
797 eval {
798 run_command(['/usr/bin/qemu-img', 'info', '--output=json', $filename],
799 timeout => $timeout,
800 outfunc => sub { $json .= shift },
801 errfunc => sub { warn "$_[0]\n" }
802 );
803 };
804 warn $@ if $@;
805
806 my $info = eval { decode_json($json) };
807 warn "could not parse qemu-img info command output for '$filename'\n" if $@;
808
809 my ($size, $format, $used, $parent) = $info->@{qw(virtual-size format actual-size backing-filename)};
810
811 return wantarray ? ($size, $format, $used, $parent, $st->ctime) : $size;
812 }
813
814 sub volume_size_info {
815 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
816 my $path = $class->filesystem_path($scfg, $volname);
817 return file_size_info($path, $timeout);
818
819 }
820
821 sub volume_resize {
822 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
823
824 die "can't resize this image format\n" if $volname !~ m/\.(raw|qcow2)$/;
825
826 return 1 if $running;
827
828 my $path = $class->filesystem_path($scfg, $volname);
829
830 my $format = ($class->parse_volname($volname))[6];
831
832 my $cmd = ['/usr/bin/qemu-img', 'resize', '-f', $format, $path , $size];
833
834 run_command($cmd, timeout => 10);
835
836 return undef;
837 }
838
839 sub volume_snapshot {
840 my ($class, $scfg, $storeid, $volname, $snap) = @_;
841
842 die "can't snapshot this image format\n" if $volname !~ m/\.(qcow2|qed)$/;
843
844 my $path = $class->filesystem_path($scfg, $volname);
845
846 my $cmd = ['/usr/bin/qemu-img', 'snapshot','-c', $snap, $path];
847
848 run_command($cmd);
849
850 return undef;
851 }
852
853 sub volume_rollback_is_possible {
854 my ($class, $scfg, $storeid, $volname, $snap) = @_;
855
856 return 1;
857 }
858
859 sub volume_snapshot_rollback {
860 my ($class, $scfg, $storeid, $volname, $snap) = @_;
861
862 die "can't rollback snapshot this image format\n" if $volname !~ m/\.(qcow2|qed)$/;
863
864 my $path = $class->filesystem_path($scfg, $volname);
865
866 my $cmd = ['/usr/bin/qemu-img', 'snapshot','-a', $snap, $path];
867
868 run_command($cmd);
869
870 return undef;
871 }
872
873 sub volume_snapshot_delete {
874 my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
875
876 die "can't delete snapshot for this image format\n" if $volname !~ m/\.(qcow2|qed)$/;
877
878 return 1 if $running;
879
880 my $path = $class->filesystem_path($scfg, $volname);
881
882 $class->deactivate_volume($storeid, $scfg, $volname, $snap, {});
883
884 my $cmd = ['/usr/bin/qemu-img', 'snapshot','-d', $snap, $path];
885
886 run_command($cmd);
887
888 return undef;
889 }
890
891 sub storage_can_replicate {
892 my ($class, $scfg, $storeid, $format) = @_;
893
894 return 0;
895 }
896
897 sub volume_has_feature {
898 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running, $opts) = @_;
899
900 my $features = {
901 snapshot => { current => { qcow2 => 1}, snap => { qcow2 => 1} },
902 clone => { base => {qcow2 => 1, raw => 1, vmdk => 1} },
903 template => { current => {qcow2 => 1, raw => 1, vmdk => 1, subvol => 1} },
904 copy => { base => {qcow2 => 1, raw => 1, vmdk => 1},
905 current => {qcow2 => 1, raw => 1, vmdk => 1},
906 snap => {qcow2 => 1} },
907 sparseinit => { base => {qcow2 => 1, raw => 1, vmdk => 1},
908 current => {qcow2 => 1, raw => 1, vmdk => 1} },
909 };
910
911 # clone_image creates a qcow2 volume
912 return 0 if $feature eq 'clone' &&
913 defined($opts->{valid_target_formats}) &&
914 !(grep { $_ eq 'qcow2' } @{$opts->{valid_target_formats}});
915
916 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $format) =
917 $class->parse_volname($volname);
918
919 my $key = undef;
920 if($snapname){
921 $key = 'snap';
922 }else{
923 $key = $isBase ? 'base' : 'current';
924 }
925
926 return 1 if defined($features->{$feature}->{$key}->{$format});
927
928 return undef;
929 }
930
931 sub list_images {
932 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
933
934 my $imagedir = $class->get_subdir($scfg, 'images');
935
936 my ($defFmt, $vaidFmts) = default_format($scfg);
937 my $fmts = join ('|', @$vaidFmts);
938
939 my $res = [];
940
941 foreach my $fn (<$imagedir/[0-9][0-9]*/*>) {
942
943 next if $fn !~ m!^(/.+/(\d+)/([^/]+\.($fmts)))$!;
944 $fn = $1; # untaint
945
946 my $owner = $2;
947 my $name = $3;
948
949 next if !$vollist && defined($vmid) && ($owner ne $vmid);
950
951 my ($size, $format, $used, $parent, $ctime) = file_size_info($fn);
952 next if !($format && defined($size));
953
954 my $volid;
955 if ($parent && $parent =~ m!^../(\d+)/([^/]+\.($fmts))$!) {
956 my ($basevmid, $basename) = ($1, $2);
957 $volid = "$storeid:$basevmid/$basename/$owner/$name";
958 } else {
959 $volid = "$storeid:$owner/$name";
960 }
961
962 if ($vollist) {
963 my $found = grep { $_ eq $volid } @$vollist;
964 next if !$found;
965 }
966
967 my $info = {
968 volid => $volid, format => $format,
969 size => $size, vmid => $owner, used => $used, parent => $parent
970 };
971
972 $info->{ctime} = $ctime if $ctime;
973
974 push @$res, $info;
975 }
976
977 return $res;
978 }
979
980 # list templates ($tt = <iso|vztmpl|backup|snippets>)
981 my $get_subdir_files = sub {
982 my ($sid, $path, $tt, $vmid) = @_;
983
984 my $res = [];
985
986 foreach my $fn (<$path/*>) {
987
988 my $st = File::stat::stat($fn);
989
990 next if (!$st || S_ISDIR($st->mode));
991
992 my $info;
993
994 if ($tt eq 'iso') {
995 next if $fn !~ m!/([^/]+$PVE::Storage::iso_extension_re)$!i;
996
997 $info = { volid => "$sid:iso/$1", format => 'iso' };
998
999 } elsif ($tt eq 'vztmpl') {
1000 next if $fn !~ m!/([^/]+\.tar\.([gx]z))$!;
1001
1002 $info = { volid => "$sid:vztmpl/$1", format => "t$2" };
1003
1004 } elsif ($tt eq 'backup') {
1005 next if defined($vmid) && $fn !~ m/\S+-$vmid-\S+/;
1006 next if $fn !~ m!/([^/]+\.(tgz|(?:(?:tar|vma)(?:\.(${\COMPRESSOR_RE}))?)))$!;
1007 my $format = $2;
1008 $fn = $1;
1009 $info = { volid => "$sid:backup/$fn", format => $format };
1010
1011 my $archive_info = eval { PVE::Storage::archive_info($fn) } // {};
1012
1013 $info->{ctime} = $archive_info->{ctime} if defined($archive_info->{ctime});
1014
1015 if (defined($vmid) || $fn =~ m!\-([1-9][0-9]{2,8})\-[^/]+\.${format}$!) {
1016 $info->{vmid} = $vmid // $1;
1017 }
1018
1019 } elsif ($tt eq 'snippets') {
1020
1021 $info = {
1022 volid => "$sid:snippets/". basename($fn),
1023 format => 'snippet',
1024 };
1025 }
1026
1027 $info->{size} = $st->size;
1028 $info->{ctime} //= $st->ctime;
1029
1030 push @$res, $info;
1031 }
1032
1033 return $res;
1034 };
1035
1036 sub list_volumes {
1037 my ($class, $storeid, $scfg, $vmid, $content_types) = @_;
1038
1039 my $res = [];
1040 my $vmlist = PVE::Cluster::get_vmlist();
1041 foreach my $type (@$content_types) {
1042 my $data;
1043
1044 if ($type eq 'images' || $type eq 'rootdir') {
1045 $data = $class->list_images($storeid, $scfg, $vmid);
1046 } elsif ($scfg->{path}) {
1047 my $path = $class->get_subdir($scfg, $type);
1048
1049 if ($type eq 'iso' && !defined($vmid)) {
1050 $data = $get_subdir_files->($storeid, $path, 'iso');
1051 } elsif ($type eq 'vztmpl'&& !defined($vmid)) {
1052 $data = $get_subdir_files->($storeid, $path, 'vztmpl');
1053 } elsif ($type eq 'backup') {
1054 $data = $get_subdir_files->($storeid, $path, 'backup', $vmid);
1055 } elsif ($type eq 'snippets') {
1056 $data = $get_subdir_files->($storeid, $path, 'snippets');
1057 }
1058 }
1059
1060 next if !$data;
1061
1062 foreach my $item (@$data) {
1063 if ($type eq 'images' || $type eq 'rootdir') {
1064 my $vminfo = $vmlist->{ids}->{$item->{vmid}};
1065 my $vmtype;
1066 if (defined($vminfo)) {
1067 $vmtype = $vminfo->{type};
1068 }
1069 if (defined($vmtype) && $vmtype eq 'lxc') {
1070 $item->{content} = 'rootdir';
1071 } else {
1072 $item->{content} = 'images';
1073 }
1074 next if $type ne $item->{content};
1075 } else {
1076 $item->{content} = $type;
1077 }
1078
1079 push @$res, $item;
1080 }
1081 }
1082
1083 return $res;
1084 }
1085
1086 sub status {
1087 my ($class, $storeid, $scfg, $cache) = @_;
1088
1089 my $path = $scfg->{path};
1090
1091 die "storage definintion has no path\n" if !$path;
1092
1093 my $timeout = 2;
1094 my $res = PVE::Tools::df($path, $timeout);
1095
1096 return undef if !$res || !$res->{total};
1097
1098 return ($res->{total}, $res->{avail}, $res->{used}, 1);
1099 }
1100
1101 sub volume_snapshot_list {
1102 my ($class, $scfg, $storeid, $volname) = @_;
1103
1104 # implement in subclass
1105 die "Volume_snapshot_list is not implemented for $class";
1106
1107 # return an empty array if dataset does not exist.
1108 }
1109
1110 sub activate_storage {
1111 my ($class, $storeid, $scfg, $cache) = @_;
1112
1113 my $path = $scfg->{path};
1114
1115 die "storage definintion has no path\n" if !$path;
1116
1117 # this path test may hang indefinitely on unresponsive mounts
1118 my $timeout = 2;
1119 if (! PVE::Tools::run_fork_with_timeout($timeout, sub {-d $path})) {
1120 die "unable to activate storage '$storeid' - " .
1121 "directory '$path' does not exist or is unreachable\n";
1122 }
1123
1124
1125 return if defined($scfg->{mkdir}) && !$scfg->{mkdir};
1126
1127 if (defined($scfg->{content})) {
1128 foreach my $vtype (keys %$vtype_subdirs) {
1129 # OpenVZMigrate uses backup (dump) dir
1130 if (defined($scfg->{content}->{$vtype}) ||
1131 ($vtype eq 'backup' && defined($scfg->{content}->{'rootdir'}))) {
1132 my $subdir = $class->get_subdir($scfg, $vtype);
1133 mkpath $subdir if $subdir ne $path;
1134 }
1135 }
1136 }
1137 }
1138
1139 sub deactivate_storage {
1140 my ($class, $storeid, $scfg, $cache) = @_;
1141
1142 # do nothing by default
1143 }
1144
1145 sub map_volume {
1146 my ($class, $storeid, $scfg, $volname, $snapname) = @_;
1147
1148 my ($path) = $class->path($scfg, $volname, $storeid, $snapname);
1149 return $path;
1150 }
1151
1152 sub unmap_volume {
1153 my ($class, $storeid, $scfg, $volname, $snapname) = @_;
1154
1155 return 1;
1156 }
1157
1158 sub activate_volume {
1159 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
1160
1161 my $path = $class->filesystem_path($scfg, $volname, $snapname);
1162
1163 # check is volume exists
1164 if ($scfg->{path}) {
1165 die "volume '$storeid:$volname' does not exist\n" if ! -e $path;
1166 } else {
1167 die "volume '$storeid:$volname' does not exist\n" if ! -b $path;
1168 }
1169 }
1170
1171 sub deactivate_volume {
1172 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
1173
1174 # do nothing by default
1175 }
1176
1177 sub check_connection {
1178 my ($class, $storeid, $scfg) = @_;
1179 # do nothing by default
1180 return 1;
1181 }
1182
1183 sub prune_backups {
1184 my ($class, $scfg, $storeid, $keep, $vmid, $type, $dryrun, $logfunc) = @_;
1185
1186 $logfunc //= sub { print "$_[1]\n" };
1187
1188 my $backups = $class->list_volumes($storeid, $scfg, $vmid, ['backup']);
1189
1190 my $backup_groups = {};
1191 my $prune_list = [];
1192
1193 foreach my $backup (@{$backups}) {
1194 my $volid = $backup->{volid};
1195 my $backup_vmid = $backup->{vmid};
1196 my $archive_info = eval { PVE::Storage::archive_info($volid) } // {};
1197 my $backup_type = $archive_info->{type} // 'unknown';
1198
1199 next if defined($type) && $type ne $backup_type;
1200
1201 my $prune_entry = {
1202 ctime => $backup->{ctime},
1203 type => $backup_type,
1204 volid => $volid,
1205 };
1206
1207 $prune_entry->{vmid} = $backup_vmid if defined($backup_vmid);
1208
1209 if ($archive_info->{is_std_name}) {
1210 $prune_entry->{ctime} = $archive_info->{ctime};
1211 my $group = "$backup_type/$backup_vmid";
1212 push @{$backup_groups->{$group}}, $prune_entry;
1213 } else {
1214 # ignore backups that don't use the standard naming scheme
1215 $prune_entry->{mark} = 'protected';
1216 }
1217
1218 push @{$prune_list}, $prune_entry;
1219 }
1220
1221 foreach my $backup_group (values %{$backup_groups}) {
1222 PVE::Storage::prune_mark_backup_group($backup_group, $keep);
1223 }
1224
1225 my $failed;
1226 if (!$dryrun) {
1227 foreach my $prune_entry (@{$prune_list}) {
1228 next if $prune_entry->{mark} ne 'remove';
1229
1230 my $volid = $prune_entry->{volid};
1231 $logfunc->('info', "removing backup '$volid'");
1232 eval {
1233 my (undef, $volname) = parse_volume_id($volid);
1234 my $archive_path = $class->filesystem_path($scfg, $volname);
1235 PVE::Storage::archive_remove($archive_path);
1236 };
1237 if (my $err = $@) {
1238 $logfunc->('err', "error when removing backup '$volid' - $err\n");
1239 $failed = 1;
1240 }
1241 }
1242 }
1243 die "error pruning backups - check log\n" if $failed;
1244
1245 return $prune_list;
1246 }
1247
1248 # Import/Export interface:
1249 # Any path based storage is assumed to support 'raw' and 'tar' streams, so
1250 # the default implementations will return this if $scfg->{path} is set,
1251 # mimicking the old PVE::Storage::storage_migrate() function.
1252 #
1253 # Plugins may fall back to PVE::Storage::Plugin::volume_{export,import}...
1254 # functions in case the format doesn't match their specialized
1255 # implementations to reuse the raw/tar code.
1256 #
1257 # Format specification:
1258 # The following formats are all prefixed with image information in the form
1259 # of a 64 bit little endian unsigned integer (pack('Q<')) in order to be able
1260 # to preallocate the image on storages which require it.
1261 #
1262 # raw+size: (image files only)
1263 # A raw binary data stream such as produced via `dd if=TheImageFile`.
1264 # qcow2+size, vmdk: (image files only)
1265 # A raw qcow2/vmdk/... file such as produced via `dd if=some.qcow2` for
1266 # files which are already in qcow2 format, or via `qemu-img convert`.
1267 # Note that these formats are only valid with $with_snapshots being true.
1268 # tar+size: (subvolumes only)
1269 # A GNU tar stream containing just the inner contents of the subvolume.
1270 # This does not distinguish between the contents of a privileged or
1271 # unprivileged container. In other words, this is from the root user
1272 # namespace's point of view with no uid-mapping in effect.
1273 # As produced via `tar -C vm-100-disk-1.subvol -cpf TheOutputFile.dat .`
1274
1275 # Plugins may reuse these helpers. Changes to the header format should be
1276 # reflected by changes to the function prototypes.
1277 sub write_common_header($$) {
1278 my ($fh, $image_size_in_bytes) = @_;
1279 syswrite($fh, pack("Q<", $image_size_in_bytes), 8);
1280 }
1281
1282 sub read_common_header($) {
1283 my ($fh) = @_;
1284 sysread($fh, my $size, 8);
1285 $size = unpack('Q<', $size);
1286 die "import: no size found in export header, aborting.\n" if !defined($size);
1287 die "import: got a bad size (not a multiple of 1K), aborting.\n" if ($size&1023);
1288 # Size is in bytes!
1289 return $size;
1290 }
1291
1292 # Export a volume into a file handle as a stream of desired format.
1293 sub volume_export {
1294 my ($class, $scfg, $storeid, $fh, $volname, $format, $snapshot, $base_snapshot, $with_snapshots) = @_;
1295 if ($scfg->{path} && !defined($snapshot) && !defined($base_snapshot)) {
1296 my $file = $class->path($scfg, $volname, $storeid)
1297 or goto unsupported;
1298 my ($size, $file_format) = file_size_info($file);
1299
1300 if ($format eq 'raw+size') {
1301 goto unsupported if $with_snapshots || $file_format eq 'subvol';
1302 write_common_header($fh, $size);
1303 if ($file_format eq 'raw') {
1304 run_command(['dd', "if=$file", "bs=4k"], output => '>&'.fileno($fh));
1305 } else {
1306 run_command(['qemu-img', 'convert', '-f', $file_format, '-O', 'raw', $file, '/dev/stdout'],
1307 output => '>&'.fileno($fh));
1308 }
1309 return;
1310 } elsif ($format =~ /^(qcow2|vmdk)\+size$/) {
1311 my $data_format = $1;
1312 goto unsupported if !$with_snapshots || $file_format ne $data_format;
1313 write_common_header($fh, $size);
1314 run_command(['dd', "if=$file", "bs=4k"], output => '>&'.fileno($fh));
1315 return;
1316 } elsif ($format eq 'tar+size') {
1317 goto unsupported if $file_format ne 'subvol';
1318 write_common_header($fh, $size);
1319 run_command(['tar', @COMMON_TAR_FLAGS, '-cf', '-', '-C', $file, '.'],
1320 output => '>&'.fileno($fh));
1321 return;
1322 }
1323 }
1324 unsupported:
1325 die "volume export format $format not available for $class";
1326 }
1327
1328 sub volume_export_formats {
1329 my ($class, $scfg, $storeid, $volname, $snapshot, $base_snapshot, $with_snapshots) = @_;
1330 if ($scfg->{path} && !defined($snapshot) && !defined($base_snapshot)) {
1331 my $file = $class->path($scfg, $volname, $storeid)
1332 or return;
1333 my ($size, $format) = file_size_info($file);
1334
1335 if ($with_snapshots) {
1336 return ($format.'+size') if ($format eq 'qcow2' || $format eq 'vmdk');
1337 return ();
1338 }
1339 return ('tar+size') if $format eq 'subvol';
1340 return ('raw+size');
1341 }
1342 return ();
1343 }
1344
1345 # Import data from a stream, creating a new or replacing or adding to an existing volume.
1346 sub volume_import {
1347 my ($class, $scfg, $storeid, $fh, $volname, $format, $base_snapshot, $with_snapshots, $allow_rename) = @_;
1348
1349 die "volume import format '$format' not available for $class\n"
1350 if $format !~ /^(raw|tar|qcow2|vmdk)\+size$/;
1351 my $data_format = $1;
1352
1353 die "format $format cannot be imported without snapshots\n"
1354 if !$with_snapshots && ($data_format eq 'qcow2' || $data_format eq 'vmdk');
1355 die "format $format cannot be imported with snapshots\n"
1356 if $with_snapshots && ($data_format eq 'raw' || $data_format eq 'tar');
1357
1358 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $file_format) =
1359 $class->parse_volname($volname);
1360
1361 # XXX: Should we bother with conversion routines at this level? This won't
1362 # happen without manual CLI usage, so for now we just error out...
1363 die "cannot import format $format into a file of format $file_format\n"
1364 if $data_format ne $file_format && !($data_format eq 'tar' && $file_format eq 'subvol');
1365
1366 # Check for an existing file first since interrupting alloc_image doesn't
1367 # free it.
1368 my $file = $class->path($scfg, $volname, $storeid);
1369 if (-e $file) {
1370 die "file '$file' already exists\n" if !$allow_rename;
1371 warn "file '$file' already exists - importing with a different name\n";
1372 $name = undef;
1373 }
1374
1375 my ($size) = read_common_header($fh);
1376 $size = int($size/1024);
1377
1378 eval {
1379 my $allocname = $class->alloc_image($storeid, $scfg, $vmid, $file_format, $name, $size);
1380 my $oldname = $volname;
1381 $volname = $allocname;
1382 if (defined($name) && $allocname ne $oldname) {
1383 die "internal error: unexpected allocated name: '$allocname' != '$oldname'\n";
1384 }
1385 my $file = $class->path($scfg, $volname, $storeid)
1386 or die "internal error: failed to get path to newly allocated volume $volname\n";
1387 if ($data_format eq 'raw' || $data_format eq 'qcow2' || $data_format eq 'vmdk') {
1388 run_command(['dd', "of=$file", 'conv=sparse', 'bs=64k'],
1389 input => '<&'.fileno($fh));
1390 } elsif ($data_format eq 'tar') {
1391 run_command(['tar', @COMMON_TAR_FLAGS, '-C', $file, '-xf', '-'],
1392 input => '<&'.fileno($fh));
1393 } else {
1394 die "volume import format '$format' not available for $class";
1395 }
1396 };
1397 if (my $err = $@) {
1398 eval { $class->free_image($storeid, $scfg, $volname, 0, $file_format) };
1399 warn $@ if $@;
1400 die $err;
1401 }
1402
1403 return "$storeid:$volname";
1404 }
1405
1406 sub volume_import_formats {
1407 my ($class, $scfg, $storeid, $volname, $base_snapshot, $with_snapshots) = @_;
1408 if ($scfg->{path} && !defined($base_snapshot)) {
1409 my $format = ($class->parse_volname($volname))[6];
1410 if ($with_snapshots) {
1411 return ($format.'+size') if ($format eq 'qcow2' || $format eq 'vmdk');
1412 return ();
1413 }
1414 return ('tar+size') if $format eq 'subvol';
1415 return ('raw+size');
1416 }
1417 return ();
1418 }
1419
1420 1;