]> git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/RBDPlugin.pm
Fix #1750: set monhost split to old behavior
[pve-storage.git] / PVE / Storage / RBDPlugin.pm
1 package PVE::Storage::RBDPlugin;
2
3 use strict;
4 use warnings;
5 use IO::File;
6 use Net::IP;
7 use PVE::Tools qw(run_command trim);
8 use PVE::Storage::Plugin;
9 use PVE::JSONSchema qw(get_standard_option);
10 use PVE::RADOS;
11
12 use base qw(PVE::Storage::Plugin);
13
14 my $rbd_unittobytes = {
15 "k" => 1024,
16 "M" => 1024*1024,
17 "G" => 1024*1024*1024,
18 "T" => 1024*1024*1024*1024,
19 };
20
21 my $add_pool_to_disk = sub {
22 my ($scfg, $disk) = @_;
23
24 my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
25
26 return "$pool/$disk";
27 };
28
29 my $hostlist = sub {
30 my ($list_text, $separator) = @_;
31
32 my @monhostlist = PVE::Tools::split_list($list_text);
33 return join($separator, map {
34 my ($host, $port) = PVE::Tools::parse_host_and_port($_);
35 $port = defined($port) ? ":$port" : '';
36 $host = "[$host]" if Net::IP::ip_is_ipv6($host);
37 "${host}${port}"
38 } @monhostlist);
39 };
40
41 my $ceph_connect_option = sub {
42 my ($scfg, $storeid, %options) = @_;
43
44 my $cmd_option = {};
45 my $ceph_storeid_conf = "/etc/pve/priv/ceph/${storeid}.conf";
46 my $pveceph_config = '/etc/pve/ceph.conf';
47 my $keyring = "/etc/pve/priv/ceph/${storeid}.keyring";
48 my $pveceph_managed = !defined($scfg->{monhost});
49
50 $cmd_option->{ceph_conf} = $pveceph_config if (-e $pveceph_config);
51
52 if (-e $ceph_storeid_conf) {
53 if ($pveceph_managed) {
54 warn "ignoring custom ceph config for storage '$storeid', 'monhost' is not set (assuming pveceph managed cluster)!\n";
55 } else {
56 $cmd_option->{ceph_conf} = $ceph_storeid_conf;
57 }
58 }
59
60 $cmd_option->{keyring} = $keyring if (-e $keyring);
61 $cmd_option->{auth_supported} = (defined $cmd_option->{keyring}) ? 'cephx' : 'none';
62 $cmd_option->{userid} = $scfg->{username} ? $scfg->{username} : 'admin';
63 $cmd_option->{mon_host} = $hostlist->($scfg->{monhost}, ',') if (defined($scfg->{monhost}));
64
65 if (%options) {
66 foreach my $k (keys %options) {
67 $cmd_option->{$k} = $options{$k};
68 }
69 }
70
71 return $cmd_option;
72
73 };
74
75 my $build_cmd = sub {
76 my ($binary, $scfg, $storeid, $op, @options) = @_;
77
78 my $cmd_option = $ceph_connect_option->($scfg, $storeid);
79 my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
80
81 my $cmd = [$binary, '-p', $pool];
82
83 push @$cmd, '-c', $cmd_option->{ceph_conf} if ($cmd_option->{ceph_conf});
84 push @$cmd, '-m', $cmd_option->{mon_host} if ($cmd_option->{mon_host});
85 push @$cmd, '--auth_supported', $cmd_option->{auth_supported} if ($cmd_option->{auth_supported});
86 push @$cmd, '-n', "client.$cmd_option->{userid}" if ($cmd_option->{userid});
87 push @$cmd, '--keyring', $cmd_option->{keyring} if ($cmd_option->{keyring});
88
89 push @$cmd, $op;
90
91 push @$cmd, @options if scalar(@options);
92
93 return $cmd;
94 };
95
96 my $rbd_cmd = sub {
97 my ($scfg, $storeid, $op, @options) = @_;
98
99 return $build_cmd->('/usr/bin/rbd', $scfg, $storeid, $op, @options);
100 };
101
102 my $rados_cmd = sub {
103 my ($scfg, $storeid, $op, @options) = @_;
104
105 return $build_cmd->('/usr/bin/rados', $scfg, $storeid, $op, @options);
106 };
107
108 my $librados_connect = sub {
109 my ($scfg, $storeid, $options) = @_;
110
111 my $librados_config = $ceph_connect_option->($scfg, $storeid);
112
113 my $rados = PVE::RADOS->new(%$librados_config);
114
115 return $rados;
116 };
117
118 # needed for volumes created using ceph jewel (or higher)
119 my $krbd_feature_disable = sub {
120 my ($scfg, $storeid, $name) = @_;
121
122 return 1 if !$scfg->{krbd};
123
124 my ($major, undef, undef, undef) = ceph_version();
125 return 1 if $major < 10;
126
127 my $krbd_feature_blacklist = ['deep-flatten', 'fast-diff', 'object-map', 'exclusive-lock'];
128 my (undef, undef, undef, undef, $features) = rbd_volume_info($scfg, $storeid, $name);
129
130 my $active_features = { map { $_ => 1 } PVE::Tools::split_list($features)};
131 my $incompatible_features = join(',', grep { %$active_features{$_} } @$krbd_feature_blacklist);
132
133 if ($incompatible_features) {
134 my $feature_cmd = &$rbd_cmd($scfg, $storeid, 'feature', 'disable', $name, $incompatible_features);
135 run_rbd_command($feature_cmd, errmsg => "could not disable krbd-incompatible image features of rbd volume $name");
136 }
137 };
138
139 my $ceph_version_parser = sub {
140 my $line = shift;
141 if ($line =~ m/^ceph version ((\d+)\.(\d+)\.(\d+))(?: \([a-fA-F0-9]+\))/) {
142 return ($2, $3, $4, $1);
143 } else {
144 warn "Could not parse Ceph version: '$line'\n";
145 }
146 };
147
148 sub ceph_version {
149 my ($cache) = @_;
150
151 my $version_string = $cache;
152
153 my $major;
154 my $minor;
155 my $bugfix;
156
157 if (defined($version_string)) {
158 ($major, $minor, $bugfix, $version_string) = &$ceph_version_parser($version_string);
159 } else {
160 run_command('ceph --version', outfunc => sub {
161 my $line = shift;
162 ($major, $minor, $bugfix, $version_string) = &$ceph_version_parser($line);
163 });
164 }
165 return undef if !defined($version_string);
166 return wantarray ? ($major, $minor, $bugfix, $version_string) : $version_string;
167 }
168
169 sub run_rbd_command {
170 my ($cmd, %args) = @_;
171
172 my $lasterr;
173 my $errmsg = $args{errmsg} . ": " || "";
174 if (!exists($args{errfunc})) {
175 # ' error: 2014-02-06 11:51:59.839135 7f09f94d0760 -1 librbd: snap_unprotect: can't unprotect;
176 # at least 1 child(ren) in pool cephstor1
177 $args{errfunc} = sub {
178 my $line = shift;
179 if ($line =~ m/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [0-9a-f]+ [\-\d]+ librbd: (.*)$/) {
180 $lasterr = "$1\n";
181 } else {
182 $lasterr = $line;
183 }
184 print STDERR $lasterr;
185 *STDERR->flush();
186 };
187 }
188
189 eval { run_command($cmd, %args); };
190 if (my $err = $@) {
191 die $errmsg . $lasterr if length($lasterr);
192 die $err;
193 }
194
195 return undef;
196 }
197
198 sub rbd_ls {
199 my ($scfg, $storeid) = @_;
200
201 my $cmd = &$rbd_cmd($scfg, $storeid, 'ls', '-l');
202 my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
203
204 my $list = {};
205
206 my $parser = sub {
207 my $line = shift;
208
209 if ($line =~ m/^((vm|base)-(\d+)-\S+)\s+(\d+)(k|M|G|T)\s((\S+)\/((vm|base)-\d+-\S+@\S+))?/) {
210 my ($image, $owner, $size, $unit, $parent) = ($1, $3, $4, $5, $8);
211 return if $image =~ /@/; #skip snapshots
212
213 $list->{$pool}->{$image} = {
214 name => $image,
215 size => $size*$rbd_unittobytes->{$unit},
216 parent => $parent,
217 vmid => $owner
218 };
219 }
220 };
221
222 eval {
223 run_rbd_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
224 };
225 my $err = $@;
226
227 die $err if $err && $err !~ m/doesn't contain rbd images/ ;
228
229 return $list;
230 }
231
232 sub rbd_volume_info {
233 my ($scfg, $storeid, $volname, $snap) = @_;
234
235 my $cmd = undef;
236
237 if($snap){
238 $cmd = &$rbd_cmd($scfg, $storeid, 'info', $volname, '--snap', $snap);
239 }else{
240 $cmd = &$rbd_cmd($scfg, $storeid, 'info', $volname);
241 }
242
243 my $size = undef;
244 my $parent = undef;
245 my $format = undef;
246 my $protected = undef;
247 my $features = undef;
248
249 my $parser = sub {
250 my $line = shift;
251
252 if ($line =~ m/size (\d+) (k|M|G|T)B in (\d+) objects/) {
253 $size = $1 * $rbd_unittobytes->{$2} if ($1);
254 } elsif ($line =~ m/parent:\s(\S+)\/(\S+)/) {
255 $parent = $2;
256 } elsif ($line =~ m/format:\s(\d+)/) {
257 $format = $1;
258 } elsif ($line =~ m/protected:\s(\S+)/) {
259 $protected = 1 if $1 eq "True";
260 } elsif ($line =~ m/features:\s(.+)/) {
261 $features = $1;
262 }
263
264 };
265
266 run_rbd_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
267
268 return ($size, $parent, $format, $protected, $features);
269 }
270
271 # Configuration
272
273 sub type {
274 return 'rbd';
275 }
276
277 sub plugindata {
278 return {
279 content => [ {images => 1, rootdir => 1}, { images => 1 }],
280 };
281 }
282
283 sub properties {
284 return {
285 monhost => {
286 description => "IP addresses of monitors (for external clusters).",
287 type => 'string', format => 'pve-storage-portal-dns-list',
288 },
289 pool => {
290 description => "Pool.",
291 type => 'string',
292 },
293 username => {
294 description => "RBD Id.",
295 type => 'string',
296 },
297 authsupported => {
298 description => "Authsupported.",
299 type => 'string',
300 },
301 krbd => {
302 description => "Access rbd through krbd kernel module.",
303 type => 'boolean',
304 },
305 };
306 }
307
308 sub options {
309 return {
310 nodes => { optional => 1 },
311 disable => { optional => 1 },
312 monhost => { optional => 1},
313 pool => { optional => 1 },
314 username => { optional => 1 },
315 content => { optional => 1 },
316 krbd => { optional => 1 },
317 bwlimit => { optional => 1 },
318 };
319 }
320
321 # Storage implementation
322
323 sub parse_volname {
324 my ($class, $volname) = @_;
325
326 if ($volname =~ m/^((base-(\d+)-\S+)\/)?((base)?(vm)?-(\d+)-\S+)$/) {
327 return ('images', $4, $7, $2, $3, $5, 'raw');
328 }
329
330 die "unable to parse rbd volume name '$volname'\n";
331 }
332
333 sub path {
334 my ($class, $scfg, $volname, $storeid, $snapname) = @_;
335
336 my $cmd_option = $ceph_connect_option->($scfg, $storeid);
337 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
338 $name .= '@'.$snapname if $snapname;
339
340 my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
341 return ("/dev/rbd/$pool/$name", $vmid, $vtype) if $scfg->{krbd};
342
343 my $path = "rbd:$pool/$name";
344
345 if ($cmd_option->{ceph_conf}) {
346 $path .= ":conf=$cmd_option->{ceph_conf}";
347 } else {
348 my $monhost = $hostlist->($scfg->{monhost}, ';');
349 $monhost =~ s/:/\\:/g;
350 $path .= ":mon_host=$monhost";
351 $path .= ":auth_supported=$cmd_option->{auth_supported}";
352 }
353
354 $path .= ":id=$cmd_option->{userid}:keyring=$cmd_option->{keyring}" if ($cmd_option->{keyring});
355
356 return ($path, $vmid, $vtype);
357 }
358
359 my $find_free_diskname = sub {
360 my ($storeid, $scfg, $vmid) = @_;
361
362 my $cmd = &$rbd_cmd($scfg, $storeid, 'ls');
363 my $disk_ids = {};
364
365 my $parser = sub {
366 my $line = shift;
367
368 if ($line =~ m/^(vm|base)-\Q$vmid\E+-disk-(\d+)$/) {
369 $disk_ids->{$2} = 1;
370 }
371 };
372
373 eval {
374 run_rbd_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
375 };
376 my $err = $@;
377
378 die $err if $err && $err !~ m/doesn't contain rbd images/;
379
380 #fix: can we search in $rbd hash key with a regex to find (vm|base) ?
381 for (my $i = 1; $i < 100; $i++) {
382 if (!$disk_ids->{$i}) {
383 return "vm-$vmid-disk-$i";
384 }
385 }
386
387 die "unable to allocate an image name for VM $vmid in storage '$storeid'\n";
388 };
389
390 sub create_base {
391 my ($class, $storeid, $scfg, $volname) = @_;
392
393 my $snap = '__base__';
394
395 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
396 $class->parse_volname($volname);
397
398 die "create_base not possible with base image\n" if $isBase;
399
400 my ($size, $parent, $format, undef) = rbd_volume_info($scfg, $storeid, $name);
401 die "rbd volume info on '$name' failed\n" if !($size);
402
403 die "rbd image must be at format V2" if $format ne "2";
404
405 die "volname '$volname' contains wrong information about parent $parent $basename\n"
406 if $basename && (!$parent || $parent ne $basename."@".$snap);
407
408 my $newname = $name;
409 $newname =~ s/^vm-/base-/;
410
411 my $newvolname = $basename ? "$basename/$newname" : "$newname";
412
413 my $cmd = &$rbd_cmd($scfg, $storeid, 'rename', &$add_pool_to_disk($scfg, $name), &$add_pool_to_disk($scfg, $newname));
414 run_rbd_command($cmd, errmsg => "rbd rename '$name' error");
415
416 my $running = undef; #fixme : is create_base always offline ?
417
418 $class->volume_snapshot($scfg, $storeid, $newname, $snap, $running);
419
420 my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $newname, $snap);
421
422 if (!$protected){
423 my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'protect', $newname, '--snap', $snap);
424 run_rbd_command($cmd, errmsg => "rbd protect $newname snap '$snap' error");
425 }
426
427 return $newvolname;
428
429 }
430
431 sub clone_image {
432 my ($class, $scfg, $storeid, $volname, $vmid, $snapname) = @_;
433
434 my $snap = '__base__';
435 $snap = $snapname if length $snapname;
436
437 my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
438 $class->parse_volname($volname);
439
440 die "$volname is not a base image and snapname is not provided\n"
441 if !$isBase && !length($snapname);
442
443 my $name = &$find_free_diskname($storeid, $scfg, $vmid);
444
445 warn "clone $volname: $basename snapname $snap to $name\n";
446
447 if (length($snapname)) {
448 my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $volname, $snapname);
449
450 if (!$protected) {
451 my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'protect', $volname, '--snap', $snapname);
452 run_rbd_command($cmd, errmsg => "rbd protect $volname snap $snapname error");
453 }
454 }
455
456 my $newvol = "$basename/$name";
457 $newvol = $name if length($snapname);
458
459 my $cmd = &$rbd_cmd($scfg, $storeid, 'clone', &$add_pool_to_disk($scfg, $basename),
460 '--snap', $snap, &$add_pool_to_disk($scfg, $name));
461
462 run_rbd_command($cmd, errmsg => "rbd clone '$basename' error");
463
464 &$krbd_feature_disable($scfg, $storeid, $name);
465
466 return $newvol;
467 }
468
469 sub alloc_image {
470 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
471
472
473 die "illegal name '$name' - should be 'vm-$vmid-*'\n"
474 if $name && $name !~ m/^vm-$vmid-/;
475
476 $name = &$find_free_diskname($storeid, $scfg, $vmid) if !$name;
477
478 my $cmd = &$rbd_cmd($scfg, $storeid, 'create', '--image-format' , 2, '--size', int(($size+1023)/1024), $name);
479 run_rbd_command($cmd, errmsg => "rbd create $name' error");
480
481 &$krbd_feature_disable($scfg, $storeid, $name);
482
483 return $name;
484 }
485
486 sub free_image {
487 my ($class, $storeid, $scfg, $volname, $isBase) = @_;
488
489 my ($vtype, $name, $vmid, undef, undef, undef) =
490 $class->parse_volname($volname);
491
492 if ($isBase) {
493 my $snap = '__base__';
494 my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $name, $snap);
495 if ($protected){
496 my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
497 run_rbd_command($cmd, errmsg => "rbd unprotect $name snap '$snap' error");
498 }
499 }
500
501 $class->deactivate_volume($storeid, $scfg, $volname);
502
503 my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'purge', $name);
504 run_rbd_command($cmd, errmsg => "rbd snap purge '$volname' error");
505
506 $cmd = &$rbd_cmd($scfg, $storeid, 'rm', $name);
507 run_rbd_command($cmd, errmsg => "rbd rm '$volname' error");
508
509 return undef;
510 }
511
512 sub list_images {
513 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
514
515 $cache->{rbd} = rbd_ls($scfg, $storeid) if !$cache->{rbd};
516 my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
517
518 my $res = [];
519
520 if (my $dat = $cache->{rbd}->{$pool}) {
521 foreach my $image (keys %$dat) {
522
523 my $info = $dat->{$image};
524
525 my $volname = $info->{name};
526 my $parent = $info->{parent};
527 my $owner = $info->{vmid};
528
529 if ($parent && $parent =~ m/^(base-\d+-\S+)\@__base__$/) {
530 $info->{volid} = "$storeid:$1/$volname";
531 } else {
532 $info->{volid} = "$storeid:$volname";
533 }
534
535 if ($vollist) {
536 my $found = grep { $_ eq $info->{volid} } @$vollist;
537 next if !$found;
538 } else {
539 next if defined ($vmid) && ($owner ne $vmid);
540 }
541
542 $info->{format} = 'raw';
543
544 push @$res, $info;
545 }
546 }
547
548 return $res;
549 }
550
551 sub status {
552 my ($class, $storeid, $scfg, $cache) = @_;
553
554
555 my $rados = &$librados_connect($scfg, $storeid);
556 my $df = $rados->mon_command({ prefix => 'df', format => 'json' });
557
558 my ($d) = grep { $_->{name} eq $scfg->{pool} } @{$df->{pools}};
559
560 # max_avail -> max available space for data w/o replication in the pool
561 # bytes_used -> data w/o replication in the pool
562 my $free = $d->{stats}->{max_avail};
563 my $used = $d->{stats}->{bytes_used};
564 my $total = $used + $free;
565 my $active = 1;
566
567 return ($total, $free, $used, $active);
568 }
569
570 sub activate_storage {
571 my ($class, $storeid, $scfg, $cache) = @_;
572 return 1;
573 }
574
575 sub deactivate_storage {
576 my ($class, $storeid, $scfg, $cache) = @_;
577 return 1;
578 }
579
580 sub activate_volume {
581 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
582
583 return 1 if !$scfg->{krbd};
584
585 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
586 my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
587
588 my $path = "/dev/rbd/$pool/$name";
589 $path .= '@'.$snapname if $snapname;
590 return if -b $path;
591
592 $name .= '@'.$snapname if $snapname;
593 my $cmd = &$rbd_cmd($scfg, $storeid, 'map', $name);
594 run_rbd_command($cmd, errmsg => "can't mount rbd volume $name");
595
596 return 1;
597 }
598
599 sub deactivate_volume {
600 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
601
602 return 1 if !$scfg->{krbd};
603
604 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
605 my $pool = $scfg->{pool} ? $scfg->{pool} : 'rbd';
606
607 my $path = "/dev/rbd/$pool/$name";
608 $path .= '@'.$snapname if $snapname;
609 return if ! -b $path;
610
611 my $cmd = &$rbd_cmd($scfg, $storeid, 'unmap', $path);
612 run_rbd_command($cmd, errmsg => "can't unmap rbd volume $name");
613
614 return 1;
615 }
616
617 sub volume_size_info {
618 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
619
620 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
621 my ($size, undef) = rbd_volume_info($scfg, $storeid, $name);
622 return $size;
623 }
624
625 sub volume_resize {
626 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
627
628 return 1 if $running && !$scfg->{krbd};
629
630 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
631
632 my $cmd = &$rbd_cmd($scfg, $storeid, 'resize', '--allow-shrink', '--size', ($size/1024/1024), $name);
633 run_rbd_command($cmd, errmsg => "rbd resize '$volname' error");
634 return undef;
635 }
636
637 sub volume_snapshot {
638 my ($class, $scfg, $storeid, $volname, $snap) = @_;
639
640 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
641
642 my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'create', '--snap', $snap, $name);
643 run_rbd_command($cmd, errmsg => "rbd snapshot '$volname' error");
644 return undef;
645 }
646
647 sub volume_snapshot_rollback {
648 my ($class, $scfg, $storeid, $volname, $snap) = @_;
649
650 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
651
652 my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'rollback', '--snap', $snap, $name);
653 run_rbd_command($cmd, errmsg => "rbd snapshot $volname to '$snap' error");
654 }
655
656 sub volume_snapshot_delete {
657 my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
658
659 return 1 if $running && !$scfg->{krbd};
660
661 $class->deactivate_volume($storeid, $scfg, $volname, $snap, {});
662
663 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
664
665 my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $name, $snap);
666 if ($protected){
667 my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
668 run_rbd_command($cmd, errmsg => "rbd unprotect $name snap '$snap' error");
669 }
670
671 my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'rm', '--snap', $snap, $name);
672
673 run_rbd_command($cmd, errmsg => "rbd snapshot '$volname' error");
674
675 return undef;
676 }
677
678 sub volume_has_feature {
679 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
680
681 my $features = {
682 snapshot => { current => 1, snap => 1},
683 clone => { base => 1, snap => 1},
684 template => { current => 1},
685 copy => { base => 1, current => 1, snap => 1},
686 sparseinit => { base => 1, current => 1},
687 };
688
689 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
690 $class->parse_volname($volname);
691
692 my $key = undef;
693 if($snapname){
694 $key = 'snap';
695 }else{
696 $key = $isBase ? 'base' : 'current';
697 }
698 return 1 if $features->{$feature}->{$key};
699
700 return undef;
701 }
702
703 1;