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