1 package PVE
::Storage
::RBDPlugin
;
13 use PVE
::Cluster
qw(cfs_read_file);;
14 use PVE
::JSONSchema
qw(get_standard_option);
17 use PVE
::RPCEnvironment
;
18 use PVE
::Storage
::Plugin
;
19 use PVE
::Tools
qw(run_command trim file_read_firstline);
21 use base
qw(PVE::Storage::Plugin);
23 my $get_parent_image_name = sub {
25 return undef if !$parent;
26 return $parent->{image
} . "@" . $parent->{snapshot
};
29 my $librados_connect = sub {
30 my ($scfg, $storeid, $options) = @_;
32 $options->{timeout
} = 60
33 if !defined($options->{timeout
}) && PVE
::RPCEnvironment-
>is_worker();
35 my $librados_config = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid, $options->%*);
37 my $rados = PVE
::RADOS-
>new(%$librados_config);
43 my ($scfg, $volume) = @_;
44 my $path = $scfg->{pool
} ?
$scfg->{pool
} : 'rbd';
45 $path .= "/$scfg->{namespace}" if defined($scfg->{namespace
});
46 $path .= "/$volume" if defined($volume);
50 my sub get_rbd_dev_path
{
51 my ($scfg, $storeid, $volume) = @_;
55 # NOTE: the config doesn't support this currently (but it could!), hack for qemu-server tests
56 $cluster_id = $scfg->{fsid
};
57 } elsif ($scfg->{monhost
}) {
58 my $rados = $librados_connect->($scfg, $storeid);
59 $cluster_id = $rados->mon_command({ prefix
=> 'fsid', format
=> 'json' })->{fsid
};
61 $cluster_id = cfs_read_file
('ceph.conf')->{global
}->{fsid
};
64 my $uuid_pattern = "([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})";
65 if ($cluster_id =~ qr/^${uuid_pattern}$/is) {
66 $cluster_id = $1; # use untained value
68 die "cluster fsid has invalid format\n";
71 my $rbd_path = get_rbd_path
($scfg, $volume);
72 my $pve_path = "/dev/rbd-pve/${cluster_id}/${rbd_path}";
73 my $path = "/dev/rbd/${rbd_path}";
75 if (!-e
$pve_path && -e
$path) {
76 # possibly mapped before rbd-pve rule existed
77 my $real_dev = abs_path
($path);
78 my ($rbd_id) = ($real_dev =~ m
|/dev/rbd
([0-9]+)$|);
79 my $dev_cluster_id = file_read_firstline
("/sys/devices/rbd/${rbd_id}/cluster_fsid");
80 return $path if $cluster_id eq $dev_cluster_id;
86 my ($binary, $scfg, $storeid, $op, @options) = @_;
88 my $cmd_option = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid);
89 my $pool = $scfg->{pool
} ?
$scfg->{pool
} : 'rbd';
91 my $cmd = [$binary, '-p', $pool];
93 if (defined(my $namespace = $scfg->{namespace
})) {
94 # some subcommands will fail if the --namespace parameter is present
95 my $no_namespace_parameter = {
98 push @$cmd, '--namespace', "$namespace" if !$no_namespace_parameter->{$op};
100 push @$cmd, '-c', $cmd_option->{ceph_conf
} if ($cmd_option->{ceph_conf
});
101 push @$cmd, '-m', $cmd_option->{mon_host
} if ($cmd_option->{mon_host
});
102 push @$cmd, '--auth_supported', $cmd_option->{auth_supported
} if ($cmd_option->{auth_supported
});
103 push @$cmd, '-n', "client.$cmd_option->{userid}" if ($cmd_option->{userid
});
104 push @$cmd, '--keyring', $cmd_option->{keyring
} if ($cmd_option->{keyring
});
108 push @$cmd, @options if scalar(@options);
114 my ($scfg, $storeid, $op, @options) = @_;
116 return $build_cmd->('/usr/bin/rbd', $scfg, $storeid, $op, @options);
119 my $rados_cmd = sub {
120 my ($scfg, $storeid, $op, @options) = @_;
122 return $build_cmd->('/usr/bin/rados', $scfg, $storeid, $op, @options);
125 # needed for volumes created using ceph jewel (or higher)
126 my $krbd_feature_update = sub {
127 my ($scfg, $storeid, $name) = @_;
129 my (@disable, @enable);
130 my ($kmajor, $kminor) = PVE
::ProcFSTools
::kernel_version
();
132 if ($kmajor > 5 || $kmajor == 5 && $kminor >= 3) {
133 # 'deep-flatten' can only be disabled, not enabled after image creation
134 push @enable, 'fast-diff', 'object-map';
136 push @disable, 'fast-diff', 'object-map', 'deep-flatten';
140 push @enable, 'exclusive-lock';
142 push @disable, 'exclusive-lock';
145 my $active_features_list = (rbd_volume_info
($scfg, $storeid, $name))[4];
146 my $active_features = { map { $_ => 1 } @$active_features_list };
148 my $to_disable = join(',', grep { $active_features->{$_} } @disable);
149 my $to_enable = join(',', grep { !$active_features->{$_} } @enable );
152 print "disable RBD image features this kernel RBD drivers is not compatible with: $to_disable\n";
153 my $cmd = $rbd_cmd->($scfg, $storeid, 'feature', 'disable', $name, $to_disable);
156 errmsg
=> "could not disable krbd-incompatible image features '$to_disable' for rbd image: $name",
160 print "enable RBD image features this kernel RBD drivers supports: $to_enable\n";
162 my $cmd = $rbd_cmd->($scfg, $storeid, 'feature', 'enable', $name, $to_enable);
165 errmsg
=> "could not enable krbd-compatible image features '$to_enable' for rbd image: $name",
172 sub run_rbd_command
{
173 my ($cmd, %args) = @_;
176 my $errmsg = $args{errmsg
} . ": " || "";
177 if (!exists($args{errfunc
})) {
178 # ' error: 2014-02-06 11:51:59.839135 7f09f94d0760 -1 librbd: snap_unprotect: can't unprotect;
179 # at least 1 child(ren) in pool cephstor1
180 $args{errfunc
} = sub {
182 if ($line =~ m/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [0-9a-f]+ [\-\d]+ librbd: (.*)$/) {
187 print STDERR
$lasterr;
192 eval { run_command
($cmd, %args); };
194 die $errmsg . $lasterr if length($lasterr);
202 my ($scfg, $storeid) = @_;
204 my $pool = $scfg->{pool
} ?
$scfg->{pool
} : 'rbd';
205 $pool .= "/$scfg->{namespace}" if defined($scfg->{namespace
});
208 my $parser = sub { $raw .= shift };
210 my $cmd = $rbd_cmd->($scfg, $storeid, 'ls', '-l', '--format', 'json');
212 run_rbd_command
($cmd, errmsg
=> "rbd error", errfunc
=> sub {}, outfunc
=> $parser);
216 die $err if $err && $err !~ m/doesn't contain rbd images/ ;
221 } elsif ($raw =~ m/^(\[.*\])$/s) { # untaint
222 $result = JSON
::decode_json
($1);
224 die "got unexpected data from rbd ls: '$raw'\n";
229 foreach my $el (@$result) {
230 next if defined($el->{snapshot
});
232 my $image = $el->{image
};
234 my ($owner) = $image =~ m/^(?:vm|base)-(\d+)-/;
235 next if !defined($owner);
237 $list->{$pool}->{$image} = {
240 parent
=> $get_parent_image_name->($el->{parent
}),
249 my ($scfg, $storeid, $name) = @_;
251 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'ls', $name, '--format', 'json');
254 run_rbd_command
($cmd, errmsg
=> "rbd error", errfunc
=> sub {}, outfunc
=> sub { $raw .= shift; });
257 if ($raw =~ m/^(\[.*\])$/s) { # untaint
258 $list = eval { JSON
::decode_json
($1) };
259 die "invalid JSON output from 'rbd snap ls $name': $@\n" if $@;
261 die "got unexpected data from 'rbd snap ls $name': '$raw'\n";
264 $list = [] if !defined($list);
267 foreach my $el (@$list) {
268 my $snap = $el->{name
};
269 my $protected = defined($el->{protected
}) && $el->{protected
} eq "true" ?
1 : undef;
272 id
=> $el->{id
} // undef,
273 size
=> $el->{size
} // 0,
274 protected
=> $protected,
280 sub rbd_volume_info
{
281 my ($scfg, $storeid, $volname, $snap) = @_;
285 my @options = ('info', $volname, '--format', 'json');
287 push @options, '--snap', $snap;
290 $cmd = $rbd_cmd->($scfg, $storeid, @options);
293 my $parser = sub { $raw .= shift };
295 run_rbd_command
($cmd, errmsg
=> "rbd error", errfunc
=> sub {}, outfunc
=> $parser);
300 } elsif ($raw =~ m/^(\{.*\})$/s) { # untaint
301 $volume = JSON
::decode_json
($1);
303 die "got unexpected data from rbd info: '$raw'\n";
306 $volume->{parent
} = $get_parent_image_name->($volume->{parent
});
307 $volume->{protected
} = defined($volume->{protected
}) && $volume->{protected
} eq "true" ?
1 : undef;
309 return $volume->@{qw(size parent format protected features)};
313 my ($scfg, $storeid, $volname) = @_;
315 my @options = ('du', $volname, '--format', 'json');
316 my $cmd = $rbd_cmd->($scfg, $storeid, @options);
319 my $parser = sub { $raw .= shift };
321 run_rbd_command
($cmd, errmsg
=> "rbd error", errfunc
=> sub {}, outfunc
=> $parser);
326 } elsif ($raw =~ m/^(\{.*\})$/s) { # untaint
327 $volume = JSON
::decode_json
($1);
329 die "got unexpected data from rbd du: '$raw'\n";
332 if (!defined($volume->{images
})) {
333 die "got no images from rbd du\n";
336 # `rbd du` returns array of images for name matching `volname`,
337 # including snapshots.
338 my $images = $volume->{images
};
339 foreach my $image (@$images) {
340 next if defined($image->{snapshot
});
341 next if !defined($image->{used_size
}) || !defined($image->{name
});
343 # Return `used_size` of first volume with matching name which
345 return $image->{used_size
} if $image->{name
} eq $volname;
348 die "got no matching image from rbd du\n";
359 content
=> [ {images
=> 1, rootdir
=> 1}, { images
=> 1 }],
366 description
=> "IP addresses of monitors (for external clusters).",
367 type
=> 'string', format
=> 'pve-storage-portal-dns-list',
370 description
=> "Pool.",
374 description
=> "Data Pool (for erasure coding only)",
378 description
=> "Namespace.",
382 description
=> "RBD Id.",
386 description
=> "Authsupported.",
390 description
=> "Always access rbd through krbd kernel module.",
394 description
=> "Client keyring contents (for external clusters).",
402 nodes
=> { optional
=> 1 },
403 disable
=> { optional
=> 1 },
404 monhost
=> { optional
=> 1},
405 pool
=> { optional
=> 1 },
406 'data-pool' => { optional
=> 1 },
407 namespace
=> { optional
=> 1 },
408 username
=> { optional
=> 1 },
409 content
=> { optional
=> 1 },
410 krbd
=> { optional
=> 1 },
411 keyring
=> { optional
=> 1 },
412 bwlimit
=> { optional
=> 1 },
416 # Storage implementation
419 my ($class, $storeid, $scfg, %param) = @_;
421 PVE
::CephConfig
::ceph_create_keyfile
($scfg->{type
}, $storeid, $param{keyring
});
427 my ($class, $storeid, $scfg, %param) = @_;
429 if (exists($param{keyring
})) {
430 if (defined($param{keyring
})) {
431 PVE
::CephConfig
::ceph_create_keyfile
($scfg->{type
}, $storeid, $param{keyring
});
433 PVE
::CephConfig
::ceph_remove_keyfile
($scfg->{type
}, $storeid);
441 my ($class, $storeid, $scfg) = @_;
442 PVE
::CephConfig
::ceph_remove_keyfile
($scfg->{type
}, $storeid);
447 my ($class, $volname) = @_;
449 if ($volname =~ m/^((base-(\d+)-\S+)\/)?
((base
)?
(vm
)?
-(\d
+)-\S
+)$/) {
450 return ('images', $4, $7, $2, $3, $5, 'raw');
453 die "unable to parse rbd volume name '$volname'\n";
457 my ($class, $scfg, $volname, $storeid, $snapname) = @_;
459 my $cmd_option = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid);
460 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
461 $name .= '@'.$snapname if $snapname;
464 my $rbd_dev_path = get_rbd_dev_path
($scfg, $storeid, $name);
465 return ($rbd_dev_path, $vmid, $vtype);
468 my $rbd_path = get_rbd_path
($scfg, $name);
469 my $path = "rbd:${rbd_path}";
471 $path .= ":conf=$cmd_option->{ceph_conf}" if $cmd_option->{ceph_conf
};
472 if (defined($scfg->{monhost
})) {
473 my $monhost = PVE
::CephConfig
::hostlist
($scfg->{monhost
}, ';');
474 $monhost =~ s/:/\\:/g;
475 $path .= ":mon_host=$monhost";
476 $path .= ":auth_supported=$cmd_option->{auth_supported}";
479 $path .= ":id=$cmd_option->{userid}:keyring=$cmd_option->{keyring}" if ($cmd_option->{keyring
});
481 return ($path, $vmid, $vtype);
484 sub find_free_diskname
{
485 my ($class, $storeid, $scfg, $vmid, $fmt, $add_fmt_suffix) = @_;
487 my $cmd = $rbd_cmd->($scfg, $storeid, 'ls');
493 if ($line =~ m/^(.*)$/) { # untaint
494 push @$disk_list, $1;
499 run_rbd_command
($cmd, errmsg
=> "rbd error", errfunc
=> sub {}, outfunc
=> $parser);
503 die $err if $err && $err !~ m/doesn't contain rbd images/;
505 return PVE
::Storage
::Plugin
::get_next_vm_diskname
($disk_list, $storeid, $vmid, undef, $scfg);
509 my ($class, $storeid, $scfg, $volname) = @_;
511 my $snap = '__base__';
513 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
514 $class->parse_volname($volname);
516 die "create_base not possible with base image\n" if $isBase;
518 my ($size, $parent, $format, undef) = rbd_volume_info
($scfg, $storeid, $name);
519 die "rbd volume info on '$name' failed\n" if !($size);
521 die "rbd image must be at format V2" if $format ne "2";
523 die "volname '$volname' contains wrong information about parent $parent $basename\n"
524 if $basename && (!$parent || $parent ne $basename."@".$snap);
527 $newname =~ s/^vm-/base-/;
529 my $newvolname = $basename ?
"$basename/$newname" : "$newname";
531 my $cmd = $rbd_cmd->(
535 get_rbd_path
($scfg, $name),
536 get_rbd_path
($scfg, $newname),
538 run_rbd_command
($cmd, errmsg
=> "rbd rename '$name' error");
540 eval { $class->unmap_volume($storeid, $scfg, $volname); };
543 my $running = undef; #fixme : is create_base always offline ?
545 $class->volume_snapshot($scfg, $storeid, $newname, $snap, $running);
547 my (undef, undef, undef, $protected) = rbd_volume_info
($scfg, $storeid, $newname, $snap);
550 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'protect', $newname, '--snap', $snap);
551 run_rbd_command
($cmd, errmsg
=> "rbd protect $newname snap '$snap' error");
559 my ($class, $scfg, $storeid, $volname, $vmid, $snapname) = @_;
561 my $snap = '__base__';
562 $snap = $snapname if length $snapname;
564 my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
565 $class->parse_volname($volname);
567 die "$volname is not a base image and snapname is not provided\n"
568 if !$isBase && !length($snapname);
570 my $name = $class->find_free_diskname($storeid, $scfg, $vmid);
572 warn "clone $volname: $basename snapname $snap to $name\n";
574 if (length($snapname)) {
575 my (undef, undef, undef, $protected) = rbd_volume_info
($scfg, $storeid, $volname, $snapname);
578 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'protect', $volname, '--snap', $snapname);
579 run_rbd_command
($cmd, errmsg
=> "rbd protect $volname snap $snapname error");
583 my $newvol = "$basename/$name";
584 $newvol = $name if length($snapname);
587 get_rbd_path
($scfg, $basename),
590 push @options, ('--data-pool', $scfg->{'data-pool'}) if $scfg->{'data-pool'};
592 my $cmd = $rbd_cmd->($scfg, $storeid, 'clone', @options, get_rbd_path
($scfg, $name));
593 run_rbd_command
($cmd, errmsg
=> "rbd clone '$basename' error");
599 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
602 die "illegal name '$name' - should be 'vm-$vmid-*'\n"
603 if $name && $name !~ m/^vm-$vmid-/;
605 $name = $class->find_free_diskname($storeid, $scfg, $vmid) if !$name;
608 '--image-format' , 2,
609 '--size', int(($size + 1023) / 1024),
611 push @options, ('--data-pool', $scfg->{'data-pool'}) if $scfg->{'data-pool'};
613 my $cmd = $rbd_cmd->($scfg, $storeid, 'create', @options, $name);
614 run_rbd_command
($cmd, errmsg
=> "rbd create '$name' error");
620 my ($class, $storeid, $scfg, $volname, $isBase) = @_;
622 my ($vtype, $name, $vmid, undef, undef, undef) =
623 $class->parse_volname($volname);
626 my $snaps = rbd_ls_snap
($scfg, $storeid, $name);
627 foreach my $snap (keys %$snaps) {
628 if ($snaps->{$snap}->{protected
}) {
629 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
630 run_rbd_command
($cmd, errmsg
=> "rbd unprotect $name snap '$snap' error");
634 $class->deactivate_volume($storeid, $scfg, $volname);
636 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'purge', $name);
637 run_rbd_command
($cmd, errmsg
=> "rbd snap purge '$name' error");
639 $cmd = $rbd_cmd->($scfg, $storeid, 'rm', $name);
640 run_rbd_command
($cmd, errmsg
=> "rbd rm '$name' error");
646 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
648 $cache->{rbd
} = rbd_ls
($scfg, $storeid) if !$cache->{rbd
};
650 my $dat = $cache->{rbd
}->{get_rbd_path
($scfg)};
651 return [] if !$dat; # nothing found
654 for my $image (sort keys %$dat) {
655 my $info = $dat->{$image};
656 my ($volname, $parent, $owner) = $info->@{'name', 'parent', 'vmid'};
658 if ($parent && $parent =~ m/^(base-\d+-\S+)\@__base__$/) {
659 $info->{volid
} = "$storeid:$1/$volname";
661 $info->{volid
} = "$storeid:$volname";
665 my $found = grep { $_ eq $info->{volid
} } @$vollist;
668 next if defined ($vmid) && ($owner ne $vmid);
671 $info->{format
} = 'raw';
680 my ($class, $storeid, $scfg, $cache) = @_;
682 my $rados = $librados_connect->($scfg, $storeid);
683 my $df = $rados->mon_command({ prefix
=> 'df', format
=> 'json' });
685 my $pool = $scfg->{'data-pool'} // $scfg->{pool
} // 'rbd';
687 my ($d) = grep { $_->{name
} eq $pool } @{$df->{pools
}};
690 warn "could not get usage stats for pool '$pool'\n";
694 # max_avail -> max available space for data w/o replication in the pool
695 # bytes_used -> data w/o replication in the pool
696 my $free = $d->{stats
}->{max_avail
};
697 my $used = $d->{stats
}->{stored
} // $d->{stats
}->{bytes_used
};
698 my $total = $used + $free;
701 return ($total, $free, $used, $active);
704 sub activate_storage
{
705 my ($class, $storeid, $scfg, $cache) = @_;
709 sub deactivate_storage
{
710 my ($class, $storeid, $scfg, $cache) = @_;
715 my ($class, $storeid, $scfg, $volname, $snapname) = @_;
717 my ($vtype, $img_name, $vmid) = $class->parse_volname($volname);
719 my $name = $img_name;
720 $name .= '@'.$snapname if $snapname;
722 my $kerneldev = get_rbd_dev_path
($scfg, $storeid, $name);
724 return $kerneldev if -b
$kerneldev; # already mapped
726 # features can only be enabled/disabled for image, not for snapshot!
727 $krbd_feature_update->($scfg, $storeid, $img_name);
729 my $cmd = $rbd_cmd->($scfg, $storeid, 'map', $name);
730 run_rbd_command
($cmd, errmsg
=> "can't map rbd volume $name");
736 my ($class, $storeid, $scfg, $volname, $snapname) = @_;
738 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
739 $name .= '@'.$snapname if $snapname;
741 my $kerneldev = get_rbd_dev_path
($scfg, $storeid, $name);
744 my $cmd = $rbd_cmd->($scfg, $storeid, 'unmap', $kerneldev);
745 run_rbd_command
($cmd, errmsg
=> "can't unmap rbd device $kerneldev");
751 sub activate_volume
{
752 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
754 $class->map_volume($storeid, $scfg, $volname, $snapname) if $scfg->{krbd
};
759 sub deactivate_volume
{
760 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
762 $class->unmap_volume($storeid, $scfg, $volname, $snapname);
767 sub volume_size_info
{
768 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
770 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
771 my ($size, $parent) = rbd_volume_info
($scfg, $storeid, $name);
772 my $used = wantarray ? rbd_volume_du
($scfg, $storeid, $name) : 0;
773 return wantarray ?
($size, 'raw', $used, $parent) : $size;
777 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
779 return 1 if $running && !$scfg->{krbd
}; # FIXME???
781 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
783 my $cmd = $rbd_cmd->($scfg, $storeid, 'resize', '--size', int(ceil
($size/1024/1024)), $name);
784 run_rbd_command
($cmd, errmsg
=> "rbd resize '$volname' error");
788 sub volume_snapshot
{
789 my ($class, $scfg, $storeid, $volname, $snap) = @_;
791 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
793 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'create', '--snap', $snap, $name);
794 run_rbd_command
($cmd, errmsg
=> "rbd snapshot '$volname' error");
798 sub volume_snapshot_rollback
{
799 my ($class, $scfg, $storeid, $volname, $snap) = @_;
801 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
803 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'rollback', '--snap', $snap, $name);
804 run_rbd_command
($cmd, errmsg
=> "rbd snapshot $volname to '$snap' error");
807 sub volume_snapshot_delete
{
808 my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
810 $class->deactivate_volume($storeid, $scfg, $volname, $snap, {});
812 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
814 my (undef, undef, undef, $protected) = rbd_volume_info
($scfg, $storeid, $name, $snap);
816 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
817 run_rbd_command
($cmd, errmsg
=> "rbd unprotect $name snap '$snap' error");
820 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'rm', '--snap', $snap, $name);
822 run_rbd_command
($cmd, errmsg
=> "rbd snapshot '$volname' error");
827 sub volume_snapshot_needs_fsfreeze
{
831 sub volume_has_feature
{
832 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
835 snapshot
=> { current
=> 1, snap
=> 1},
836 clone
=> { base
=> 1, snap
=> 1},
837 template
=> { current
=> 1},
838 copy
=> { base
=> 1, current
=> 1, snap
=> 1},
839 sparseinit
=> { base
=> 1, current
=> 1},
840 rename => {current
=> 1},
843 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) = $class->parse_volname($volname);
849 $key = $isBase ?
'base' : 'current';
851 return 1 if $features->{$feature}->{$key};
857 my ($class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname) = @_;
867 ) = $class->parse_volname($source_volname);
868 $target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format)
872 my $cmd = $rbd_cmd->($scfg, $storeid, 'info', $target_volname);
873 run_rbd_command
($cmd, errmsg
=> "exist check", quiet
=> 1);
875 die "target volume '${target_volname}' already exists\n" if !$@;
877 my $cmd = $rbd_cmd->($scfg, $storeid, 'rename', $source_image, $target_volname);
881 errmsg
=> "could not rename image '${source_image}' to '${target_volname}'",
884 eval { $class->unmap_volume($storeid, $scfg, $source_volname); };
887 $base_name = $base_name ?
"${base_name}/" : '';
889 return "${storeid}:${base_name}${target_volname}";