1 package PVE
::Storage
::RBDPlugin
;
12 use PVE
::Cluster
qw(cfs_read_file);;
13 use PVE
::JSONSchema
qw(get_standard_option);
16 use PVE
::RPCEnvironment
;
17 use PVE
::Storage
::Plugin
;
18 use PVE
::Tools
qw(run_command trim file_read_firstline);
20 use base
qw(PVE::Storage::Plugin);
22 my $get_parent_image_name = sub {
24 return undef if !$parent;
25 return $parent->{image
} . "@" . $parent->{snapshot
};
28 my $librados_connect = sub {
29 my ($scfg, $storeid, $options) = @_;
31 $options->{timeout
} = 60
32 if !defined($options->{timeout
}) && PVE
::RPCEnvironment-
>is_worker();
34 my $librados_config = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid, $options->%*);
36 my $rados = PVE
::RADOS-
>new(%$librados_config);
42 my ($scfg, $volume) = @_;
43 my $path = $scfg->{pool
} ?
$scfg->{pool
} : 'rbd';
44 $path .= "/$scfg->{namespace}" if defined($scfg->{namespace
});
45 $path .= "/$volume" if defined($volume);
49 my sub get_rbd_dev_path
{
50 my ($scfg, $storeid, $volume) = @_;
54 # NOTE: the config doesn't support this currently (but it could!), hack for qemu-server tests
55 $cluster_id = $scfg->{fsid
};
56 } elsif ($scfg->{monhost
}) {
57 my $rados = $librados_connect->($scfg, $storeid);
58 $cluster_id = $rados->mon_command({ prefix
=> 'fsid', format
=> 'json' })->{fsid
};
60 $cluster_id = cfs_read_file
('ceph.conf')->{global
}->{fsid
};
63 my $uuid_pattern = "([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})";
64 if ($cluster_id =~ qr/^${uuid_pattern}$/is) {
65 $cluster_id = $1; # use untained value
67 die "cluster fsid has invalid format\n";
70 my $rbd_path = get_rbd_path
($scfg, $volume);
71 my $pve_path = "/dev/rbd-pve/${cluster_id}/${rbd_path}";
72 my $path = "/dev/rbd/${rbd_path}";
74 if (!-e
$pve_path && -e
$path) {
75 # possibly mapped before rbd-pve rule existed
76 my $real_dev = abs_path
($path);
77 my ($rbd_id) = ($real_dev =~ m
|/dev/rbd
([0-9]+)$|);
78 my $dev_cluster_id = file_read_firstline
("/sys/devices/rbd/${rbd_id}/cluster_fsid");
79 return $path if $cluster_id eq $dev_cluster_id;
85 my ($binary, $scfg, $storeid, $op, @options) = @_;
87 my $cmd_option = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid);
88 my $pool = $scfg->{pool
} ?
$scfg->{pool
} : 'rbd';
90 my $cmd = [$binary, '-p', $pool];
92 if (defined(my $namespace = $scfg->{namespace
})) {
93 # some subcommands will fail if the --namespace parameter is present
94 my $no_namespace_parameter = {
97 push @$cmd, '--namespace', "$namespace" if !$no_namespace_parameter->{$op};
99 push @$cmd, '-c', $cmd_option->{ceph_conf
} if ($cmd_option->{ceph_conf
});
100 push @$cmd, '-m', $cmd_option->{mon_host
} if ($cmd_option->{mon_host
});
101 push @$cmd, '--auth_supported', $cmd_option->{auth_supported
} if ($cmd_option->{auth_supported
});
102 push @$cmd, '-n', "client.$cmd_option->{userid}" if ($cmd_option->{userid
});
103 push @$cmd, '--keyring', $cmd_option->{keyring
} if ($cmd_option->{keyring
});
107 push @$cmd, @options if scalar(@options);
113 my ($scfg, $storeid, $op, @options) = @_;
115 return $build_cmd->('/usr/bin/rbd', $scfg, $storeid, $op, @options);
118 my $rados_cmd = sub {
119 my ($scfg, $storeid, $op, @options) = @_;
121 return $build_cmd->('/usr/bin/rados', $scfg, $storeid, $op, @options);
124 # needed for volumes created using ceph jewel (or higher)
125 my $krbd_feature_update = sub {
126 my ($scfg, $storeid, $name) = @_;
128 my (@disable, @enable);
129 my ($kmajor, $kminor) = PVE
::ProcFSTools
::kernel_version
();
131 if ($kmajor > 5 || $kmajor == 5 && $kminor >= 3) {
132 # 'deep-flatten' can only be disabled, not enabled after image creation
133 push @enable, 'fast-diff', 'object-map';
135 push @disable, 'fast-diff', 'object-map', 'deep-flatten';
139 push @enable, 'exclusive-lock';
141 push @disable, 'exclusive-lock';
144 my $active_features_list = (rbd_volume_info
($scfg, $storeid, $name))[4];
145 my $active_features = { map { $_ => 1 } @$active_features_list };
147 my $to_disable = join(',', grep { $active_features->{$_} } @disable);
148 my $to_enable = join(',', grep { !$active_features->{$_} } @enable );
151 print "disable RBD image features this kernel RBD drivers is not compatible with: $to_disable\n";
152 my $cmd = $rbd_cmd->($scfg, $storeid, 'feature', 'disable', $name, $to_disable);
155 errmsg
=> "could not disable krbd-incompatible image features '$to_disable' for rbd image: $name",
159 print "enable RBD image features this kernel RBD drivers supports: $to_enable\n";
161 my $cmd = $rbd_cmd->($scfg, $storeid, 'feature', 'enable', $name, $to_enable);
164 errmsg
=> "could not enable krbd-compatible image features '$to_enable' for rbd image: $name",
171 sub run_rbd_command
{
172 my ($cmd, %args) = @_;
175 my $errmsg = $args{errmsg
} . ": " || "";
176 if (!exists($args{errfunc
})) {
177 # ' error: 2014-02-06 11:51:59.839135 7f09f94d0760 -1 librbd: snap_unprotect: can't unprotect;
178 # at least 1 child(ren) in pool cephstor1
179 $args{errfunc
} = sub {
181 if ($line =~ m/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ [0-9a-f]+ [\-\d]+ librbd: (.*)$/) {
186 print STDERR
$lasterr;
191 eval { run_command
($cmd, %args); };
193 die $errmsg . $lasterr if length($lasterr);
201 my ($scfg, $storeid) = @_;
203 my $pool = $scfg->{pool
} ?
$scfg->{pool
} : 'rbd';
204 $pool .= "/$scfg->{namespace}" if defined($scfg->{namespace
});
207 my $parser = sub { $raw .= shift };
209 my $cmd = $rbd_cmd->($scfg, $storeid, 'ls', '-l', '--format', 'json');
211 run_rbd_command
($cmd, errmsg
=> "rbd error", errfunc
=> sub {}, outfunc
=> $parser);
215 die $err if $err && $err !~ m/doesn't contain rbd images/ ;
220 } elsif ($raw =~ m/^(\[.*\])$/s) { # untaint
221 $result = JSON
::decode_json
($1);
223 die "got unexpected data from rbd ls: '$raw'\n";
228 foreach my $el (@$result) {
229 next if defined($el->{snapshot
});
231 my $image = $el->{image
};
233 my ($owner) = $image =~ m/^(?:vm|base)-(\d+)-/;
234 next if !defined($owner);
236 $list->{$pool}->{$image} = {
239 parent
=> $get_parent_image_name->($el->{parent
}),
248 my ($scfg, $storeid, $name) = @_;
250 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'ls', $name, '--format', 'json');
253 run_rbd_command
($cmd, errmsg
=> "rbd error", errfunc
=> sub {}, outfunc
=> sub { $raw .= shift; });
256 if ($raw =~ m/^(\[.*\])$/s) { # untaint
257 $list = eval { JSON
::decode_json
($1) };
258 die "invalid JSON output from 'rbd snap ls $name': $@\n" if $@;
260 die "got unexpected data from 'rbd snap ls $name': '$raw'\n";
263 $list = [] if !defined($list);
266 foreach my $el (@$list) {
267 my $snap = $el->{name
};
268 my $protected = defined($el->{protected
}) && $el->{protected
} eq "true" ?
1 : undef;
271 id
=> $el->{id
} // undef,
272 size
=> $el->{size
} // 0,
273 protected
=> $protected,
279 sub rbd_volume_info
{
280 my ($scfg, $storeid, $volname, $snap) = @_;
284 my @options = ('info', $volname, '--format', 'json');
286 push @options, '--snap', $snap;
289 $cmd = $rbd_cmd->($scfg, $storeid, @options);
292 my $parser = sub { $raw .= shift };
294 run_rbd_command
($cmd, errmsg
=> "rbd error", errfunc
=> sub {}, outfunc
=> $parser);
299 } elsif ($raw =~ m/^(\{.*\})$/s) { # untaint
300 $volume = JSON
::decode_json
($1);
302 die "got unexpected data from rbd info: '$raw'\n";
305 $volume->{parent
} = $get_parent_image_name->($volume->{parent
});
306 $volume->{protected
} = defined($volume->{protected
}) && $volume->{protected
} eq "true" ?
1 : undef;
308 return $volume->@{qw(size parent format protected features)};
312 my ($scfg, $storeid, $volname) = @_;
314 my @options = ('du', $volname, '--format', 'json');
315 my $cmd = $rbd_cmd->($scfg, $storeid, @options);
318 my $parser = sub { $raw .= shift };
320 run_rbd_command
($cmd, errmsg
=> "rbd error", errfunc
=> sub {}, outfunc
=> $parser);
325 } elsif ($raw =~ m/^(\{.*\})$/s) { # untaint
326 $volume = JSON
::decode_json
($1);
328 die "got unexpected data from rbd du: '$raw'\n";
331 if (!defined($volume->{images
})) {
332 die "got no images from rbd du\n";
335 # `rbd du` returns array of images for name matching `volname`,
336 # including snapshots.
337 my $images = $volume->{images
};
338 foreach my $image (@$images) {
339 next if defined($image->{snapshot
});
340 next if !defined($image->{used_size
}) || !defined($image->{name
});
342 # Return `used_size` of first volume with matching name which
344 return $image->{used_size
} if $image->{name
} eq $volname;
347 die "got no matching image from rbd du\n";
358 content
=> [ {images
=> 1, rootdir
=> 1}, { images
=> 1 }],
365 description
=> "IP addresses of monitors (for external clusters).",
366 type
=> 'string', format
=> 'pve-storage-portal-dns-list',
369 description
=> "Pool.",
373 description
=> "Data Pool (for erasure coding only)",
377 description
=> "Namespace.",
381 description
=> "RBD Id.",
385 description
=> "Authsupported.",
389 description
=> "Always access rbd through krbd kernel module.",
393 description
=> "Client keyring contents (for external clusters).",
401 nodes
=> { optional
=> 1 },
402 disable
=> { optional
=> 1 },
403 monhost
=> { optional
=> 1},
404 pool
=> { optional
=> 1 },
405 'data-pool' => { optional
=> 1 },
406 namespace
=> { optional
=> 1 },
407 username
=> { optional
=> 1 },
408 content
=> { optional
=> 1 },
409 krbd
=> { optional
=> 1 },
410 keyring
=> { optional
=> 1 },
411 bwlimit
=> { optional
=> 1 },
415 # Storage implementation
418 my ($class, $storeid, $scfg, %param) = @_;
420 PVE
::CephConfig
::ceph_create_keyfile
($scfg->{type
}, $storeid, $param{keyring
});
426 my ($class, $storeid, $scfg, %param) = @_;
428 if (exists($param{keyring
})) {
429 if (defined($param{keyring
})) {
430 PVE
::CephConfig
::ceph_create_keyfile
($scfg->{type
}, $storeid, $param{keyring
});
432 PVE
::CephConfig
::ceph_remove_keyfile
($scfg->{type
}, $storeid);
440 my ($class, $storeid, $scfg) = @_;
441 PVE
::CephConfig
::ceph_remove_keyfile
($scfg->{type
}, $storeid);
446 my ($class, $volname) = @_;
448 if ($volname =~ m/^((base-(\d+)-\S+)\/)?
((base
)?
(vm
)?
-(\d
+)-\S
+)$/) {
449 return ('images', $4, $7, $2, $3, $5, 'raw');
452 die "unable to parse rbd volume name '$volname'\n";
456 my ($class, $scfg, $volname, $storeid, $snapname) = @_;
458 my $cmd_option = PVE
::CephConfig
::ceph_connect_option
($scfg, $storeid);
459 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
460 $name .= '@'.$snapname if $snapname;
463 my $rbd_dev_path = get_rbd_dev_path
($scfg, $storeid, $name);
464 return ($rbd_dev_path, $vmid, $vtype);
467 my $rbd_path = get_rbd_path
($scfg, $name);
468 my $path = "rbd:${rbd_path}";
470 $path .= ":conf=$cmd_option->{ceph_conf}" if $cmd_option->{ceph_conf
};
471 if (defined($scfg->{monhost
})) {
472 my $monhost = PVE
::CephConfig
::hostlist
($scfg->{monhost
}, ';');
473 $monhost =~ s/:/\\:/g;
474 $path .= ":mon_host=$monhost";
475 $path .= ":auth_supported=$cmd_option->{auth_supported}";
478 $path .= ":id=$cmd_option->{userid}:keyring=$cmd_option->{keyring}" if ($cmd_option->{keyring
});
480 return ($path, $vmid, $vtype);
483 sub find_free_diskname
{
484 my ($class, $storeid, $scfg, $vmid, $fmt, $add_fmt_suffix) = @_;
486 my $cmd = $rbd_cmd->($scfg, $storeid, 'ls');
492 if ($line =~ m/^(.*)$/) { # untaint
493 push @$disk_list, $1;
498 run_rbd_command
($cmd, errmsg
=> "rbd error", errfunc
=> sub {}, outfunc
=> $parser);
502 die $err if $err && $err !~ m/doesn't contain rbd images/;
504 return PVE
::Storage
::Plugin
::get_next_vm_diskname
($disk_list, $storeid, $vmid, undef, $scfg);
508 my ($class, $storeid, $scfg, $volname) = @_;
510 my $snap = '__base__';
512 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
513 $class->parse_volname($volname);
515 die "create_base not possible with base image\n" if $isBase;
517 my ($size, $parent, $format, undef) = rbd_volume_info
($scfg, $storeid, $name);
518 die "rbd volume info on '$name' failed\n" if !($size);
520 die "rbd image must be at format V2" if $format ne "2";
522 die "volname '$volname' contains wrong information about parent $parent $basename\n"
523 if $basename && (!$parent || $parent ne $basename."@".$snap);
526 $newname =~ s/^vm-/base-/;
528 my $newvolname = $basename ?
"$basename/$newname" : "$newname";
530 my $cmd = $rbd_cmd->(
534 get_rbd_path
($scfg, $name),
535 get_rbd_path
($scfg, $newname),
537 run_rbd_command
($cmd, errmsg
=> "rbd rename '$name' error");
539 eval { $class->unmap_volume($storeid, $scfg, $volname); };
542 my $running = undef; #fixme : is create_base always offline ?
544 $class->volume_snapshot($scfg, $storeid, $newname, $snap, $running);
546 my (undef, undef, undef, $protected) = rbd_volume_info
($scfg, $storeid, $newname, $snap);
549 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'protect', $newname, '--snap', $snap);
550 run_rbd_command
($cmd, errmsg
=> "rbd protect $newname snap '$snap' error");
558 my ($class, $scfg, $storeid, $volname, $vmid, $snapname) = @_;
560 my $snap = '__base__';
561 $snap = $snapname if length $snapname;
563 my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
564 $class->parse_volname($volname);
566 die "$volname is not a base image and snapname is not provided\n"
567 if !$isBase && !length($snapname);
569 my $name = $class->find_free_diskname($storeid, $scfg, $vmid);
571 warn "clone $volname: $basename snapname $snap to $name\n";
573 if (length($snapname)) {
574 my (undef, undef, undef, $protected) = rbd_volume_info
($scfg, $storeid, $volname, $snapname);
577 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'protect', $volname, '--snap', $snapname);
578 run_rbd_command
($cmd, errmsg
=> "rbd protect $volname snap $snapname error");
582 my $newvol = "$basename/$name";
583 $newvol = $name if length($snapname);
586 get_rbd_path
($scfg, $basename),
589 push @options, ('--data-pool', $scfg->{'data-pool'}) if $scfg->{'data-pool'};
591 my $cmd = $rbd_cmd->($scfg, $storeid, 'clone', @options, get_rbd_path
($scfg, $name));
592 run_rbd_command
($cmd, errmsg
=> "rbd clone '$basename' error");
598 my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
601 die "illegal name '$name' - should be 'vm-$vmid-*'\n"
602 if $name && $name !~ m/^vm-$vmid-/;
604 $name = $class->find_free_diskname($storeid, $scfg, $vmid) if !$name;
607 '--image-format' , 2,
608 '--size', int(($size + 1023) / 1024),
610 push @options, ('--data-pool', $scfg->{'data-pool'}) if $scfg->{'data-pool'};
612 my $cmd = $rbd_cmd->($scfg, $storeid, 'create', @options, $name);
613 run_rbd_command
($cmd, errmsg
=> "rbd create '$name' error");
619 my ($class, $storeid, $scfg, $volname, $isBase) = @_;
621 my ($vtype, $name, $vmid, undef, undef, undef) =
622 $class->parse_volname($volname);
625 my $snaps = rbd_ls_snap
($scfg, $storeid, $name);
626 foreach my $snap (keys %$snaps) {
627 if ($snaps->{$snap}->{protected
}) {
628 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
629 run_rbd_command
($cmd, errmsg
=> "rbd unprotect $name snap '$snap' error");
633 $class->deactivate_volume($storeid, $scfg, $volname);
635 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'purge', $name);
636 run_rbd_command
($cmd, errmsg
=> "rbd snap purge '$name' error");
638 $cmd = $rbd_cmd->($scfg, $storeid, 'rm', $name);
639 run_rbd_command
($cmd, errmsg
=> "rbd rm '$name' error");
645 my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
647 $cache->{rbd
} = rbd_ls
($scfg, $storeid) if !$cache->{rbd
};
649 my $dat = $cache->{rbd
}->{get_rbd_path
($scfg)};
650 return [] if !$dat; # nothing found
653 for my $image (sort keys %$dat) {
654 my $info = $dat->{$image};
655 my ($volname, $parent, $owner) = $info->@{'name', 'parent', 'vmid'};
657 if ($parent && $parent =~ m/^(base-\d+-\S+)\@__base__$/) {
658 $info->{volid
} = "$storeid:$1/$volname";
660 $info->{volid
} = "$storeid:$volname";
664 my $found = grep { $_ eq $info->{volid
} } @$vollist;
667 next if defined ($vmid) && ($owner ne $vmid);
670 $info->{format
} = 'raw';
679 my ($class, $storeid, $scfg, $cache) = @_;
681 my $rados = $librados_connect->($scfg, $storeid);
682 my $df = $rados->mon_command({ prefix
=> 'df', format
=> 'json' });
684 my $pool = $scfg->{'data-pool'} // $scfg->{pool
} // 'rbd';
686 my ($d) = grep { $_->{name
} eq $pool } @{$df->{pools
}};
689 warn "could not get usage stats for pool '$pool'\n";
693 # max_avail -> max available space for data w/o replication in the pool
694 # bytes_used -> data w/o replication in the pool
695 my $free = $d->{stats
}->{max_avail
};
696 my $used = $d->{stats
}->{stored
} // $d->{stats
}->{bytes_used
};
697 my $total = $used + $free;
700 return ($total, $free, $used, $active);
703 sub activate_storage
{
704 my ($class, $storeid, $scfg, $cache) = @_;
708 sub deactivate_storage
{
709 my ($class, $storeid, $scfg, $cache) = @_;
714 my ($class, $storeid, $scfg, $volname, $snapname) = @_;
716 my ($vtype, $img_name, $vmid) = $class->parse_volname($volname);
718 my $name = $img_name;
719 $name .= '@'.$snapname if $snapname;
721 my $kerneldev = get_rbd_dev_path
($scfg, $storeid, $name);
723 return $kerneldev if -b
$kerneldev; # already mapped
725 # features can only be enabled/disabled for image, not for snapshot!
726 $krbd_feature_update->($scfg, $storeid, $img_name);
728 my $cmd = $rbd_cmd->($scfg, $storeid, 'map', $name);
729 run_rbd_command
($cmd, errmsg
=> "can't map rbd volume $name");
735 my ($class, $storeid, $scfg, $volname, $snapname) = @_;
737 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
738 $name .= '@'.$snapname if $snapname;
740 my $kerneldev = get_rbd_dev_path
($scfg, $storeid, $name);
743 my $cmd = $rbd_cmd->($scfg, $storeid, 'unmap', $kerneldev);
744 run_rbd_command
($cmd, errmsg
=> "can't unmap rbd device $kerneldev");
750 sub activate_volume
{
751 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
753 $class->map_volume($storeid, $scfg, $volname, $snapname) if $scfg->{krbd
};
758 sub deactivate_volume
{
759 my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
761 $class->unmap_volume($storeid, $scfg, $volname, $snapname);
766 sub volume_size_info
{
767 my ($class, $scfg, $storeid, $volname, $timeout) = @_;
769 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
770 my ($size, $parent) = rbd_volume_info
($scfg, $storeid, $name);
771 my $used = wantarray ? rbd_volume_du
($scfg, $storeid, $name) : 0;
772 return wantarray ?
($size, 'raw', $used, $parent) : $size;
776 my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
778 return 1 if $running && !$scfg->{krbd
}; # FIXME???
780 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
782 my $cmd = $rbd_cmd->($scfg, $storeid, 'resize', '--size', ($size/1024/1024), $name);
783 run_rbd_command
($cmd, errmsg
=> "rbd resize '$volname' error");
787 sub volume_snapshot
{
788 my ($class, $scfg, $storeid, $volname, $snap) = @_;
790 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
792 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'create', '--snap', $snap, $name);
793 run_rbd_command
($cmd, errmsg
=> "rbd snapshot '$volname' error");
797 sub volume_snapshot_rollback
{
798 my ($class, $scfg, $storeid, $volname, $snap) = @_;
800 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
802 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'rollback', '--snap', $snap, $name);
803 run_rbd_command
($cmd, errmsg
=> "rbd snapshot $volname to '$snap' error");
806 sub volume_snapshot_delete
{
807 my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
809 $class->deactivate_volume($storeid, $scfg, $volname, $snap, {});
811 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
813 my (undef, undef, undef, $protected) = rbd_volume_info
($scfg, $storeid, $name, $snap);
815 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
816 run_rbd_command
($cmd, errmsg
=> "rbd unprotect $name snap '$snap' error");
819 my $cmd = $rbd_cmd->($scfg, $storeid, 'snap', 'rm', '--snap', $snap, $name);
821 run_rbd_command
($cmd, errmsg
=> "rbd snapshot '$volname' error");
826 sub volume_snapshot_needs_fsfreeze
{
830 sub volume_has_feature
{
831 my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
834 snapshot
=> { current
=> 1, snap
=> 1},
835 clone
=> { base
=> 1, snap
=> 1},
836 template
=> { current
=> 1},
837 copy
=> { base
=> 1, current
=> 1, snap
=> 1},
838 sparseinit
=> { base
=> 1, current
=> 1},
839 rename => {current
=> 1},
842 my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) = $class->parse_volname($volname);
848 $key = $isBase ?
'base' : 'current';
850 return 1 if $features->{$feature}->{$key};
856 my ($class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname) = @_;
866 ) = $class->parse_volname($source_volname);
867 $target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format)
871 my $cmd = $rbd_cmd->($scfg, $storeid, 'info', $target_volname);
872 run_rbd_command
($cmd, errmsg
=> "exist check", quiet
=> 1);
874 die "target volume '${target_volname}' already exists\n" if !$@;
876 my $cmd = $rbd_cmd->($scfg, $storeid, 'rename', $source_image, $target_volname);
880 errmsg
=> "could not rename image '${source_image}' to '${target_volname}'",
883 eval { $class->unmap_volume($storeid, $scfg, $source_volname); };
886 $base_name = $base_name ?
"${base_name}/" : '';
888 return "${storeid}:${base_name}${target_volname}";