+my sub get_kernel_device_path {
+ my ($scfg, $name) = @_;
+ return "/dev/rbd/" . get_rbd_path($scfg, $name);
+};
+
+sub map_volume {
+ my ($class, $storeid, $scfg, $volname, $snapname) = @_;
+
+ my ($vtype, $img_name, $vmid) = $class->parse_volname($volname);
+
+ my $name = $img_name;
+ $name .= '@'.$snapname if $snapname;
+
+ my $kerneldev = get_kernel_device_path($scfg, $name);
+
+ return $kerneldev if -b $kerneldev; # already mapped
+
+ # features can only be enabled/disabled for image, not for snapshot!
+ $krbd_feature_update->($scfg, $storeid, $img_name);
+
+ my $cmd = $rbd_cmd->($scfg, $storeid, 'map', $name);
+ run_rbd_command($cmd, errmsg => "can't map rbd volume $name");
+
+ return $kerneldev;
+}
+
+sub unmap_volume {
+ my ($class, $storeid, $scfg, $volname, $snapname) = @_;
+
+ my ($vtype, $name, $vmid) = $class->parse_volname($volname);
+ $name .= '@'.$snapname if $snapname;
+
+ my $kerneldev = get_kernel_device_path($scfg, $name);
+
+ if (-b $kerneldev) {
+ my $cmd = $rbd_cmd->($scfg, $storeid, 'unmap', $kerneldev);
+ run_rbd_command($cmd, errmsg => "can't unmap rbd device $kerneldev");
+ }
+
+ return 1;
+}
+