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