]> git.proxmox.com Git - pve-storage.git/commitdiff
implement map_volume and unmap_volume
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 8 Nov 2018 13:05:17 +0000 (14:05 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 9 Nov 2018 16:25:51 +0000 (17:25 +0100)
This allows to request a mapped device/path explicitly, regardles of
the storage option, eg. krbd option in the RBDplugin.

Bump of the storage ABI => 2

Co-authored-by: Alwin Antreich <a.antreich@proxmox.com>
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
PVE/Storage.pm
PVE/Storage/Plugin.pm
PVE/Storage/RBDPlugin.pm

index 3b92ee3104ab671c5a5134b92adaa342d9fb15d6..a5f7fdb6a4f106cb03b25987e82f222e848b9ed8 100755 (executable)
@@ -37,7 +37,7 @@ use PVE::Storage::ZFSPlugin;
 use PVE::Storage::DRBDPlugin;
 
 # Storage API version. Icrement it on changes in storage API interface.
-use constant APIVER => 1;
+use constant APIVER => 2;
 
 # load standard plugins
 PVE::Storage::DirPlugin->register();
@@ -671,6 +671,30 @@ sub vdisk_create_base {
     });
 }
 
+sub map_volume {
+    my ($cfg, $volid, $snapname) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid);
+
+    my $scfg = storage_config($cfg, $storeid);
+
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+
+    return $plugin->map_volume($storeid, $scfg, $volname, $snapname);
+}
+
+sub unmap_volume {
+    my ($cfg, $volid, $snapname) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid);
+
+    my $scfg = storage_config($cfg, $storeid);
+
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+
+    return $plugin->unmap_volume($storeid, $scfg, $volname, $snapname);
+}
+
 sub vdisk_alloc {
     my ($cfg, $storeid, $vmid, $fmt, $name, $size) = @_;
 
index 8ae78e9e9fb09a6cda32edbf538be3ae9eef048b..e0c2a4ec95484f386783544b8ceab9cc6826aeba 100644 (file)
@@ -949,6 +949,18 @@ sub deactivate_storage {
     # do nothing by default
 }
 
+sub map_volume {
+    my ($class, $storeid, $scfg, $volname, $snapname) = @_;
+
+    return undef;
+}
+
+sub unmap_volume {
+    my ($class, $storeid, $scfg, $volname, $snapname) = @_;
+
+    return 1;
+}
+
 sub activate_volume {
     my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
 
index 41d89b5bc32197594bc064d06e3906408d4c24a2..c93071cf31512c60e199b0e39ec12570c657be2d 100644 (file)
@@ -74,8 +74,6 @@ my $librados_connect = sub {
 my $krbd_feature_disable = sub {
     my ($scfg, $storeid, $name) = @_;
 
-    return 1 if !$scfg->{krbd};
-
     my ($major, undef, undef, undef) = ceph_version();
     return 1 if $major < 10;
 
@@ -259,7 +257,7 @@ sub properties {
            type => 'string',
        },
        krbd => {
-           description => "Access rbd through krbd kernel module.",
+           description => "Always access rbd through krbd kernel module.",
            type => 'boolean',
        },
     };
@@ -428,8 +426,6 @@ sub clone_image {
 
     run_rbd_command($cmd, errmsg => "rbd clone '$basename' error");
 
-    &$krbd_feature_disable($scfg, $storeid, $name);
-
     return $newvol;
 }
 
@@ -445,8 +441,6 @@ sub alloc_image {
     my $cmd = &$rbd_cmd($scfg, $storeid, 'create', '--image-format' , 2, '--size', int(($size+1023)/1024), $name);
     run_rbd_command($cmd, errmsg => "rbd create $name' error");
 
-    &$krbd_feature_disable($scfg, $storeid, $name);
-
     return $name;
 }
 
@@ -544,39 +538,62 @@ sub deactivate_storage {
     return 1;
 }
 
-sub activate_volume {
-    my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
+my $get_kernel_device_name = sub {
+    my ($pool, $name) = @_;
+
+    return "/dev/rbd/$pool/$name";
+};
 
-    return 1 if !$scfg->{krbd};
+sub map_volume {
+    my ($class, $storeid, $scfg, $volname, $snapname) = @_;
 
     my ($vtype, $name, $vmid) = $class->parse_volname($volname);
+    $name .= '@'.$snapname if $snapname;
+
     my $pool =  $scfg->{pool} ? $scfg->{pool} : 'rbd';
 
-    my $path = "/dev/rbd/$pool/$name";
-    $path .= '@'.$snapname if $snapname;
-    return if -b $path;
+    my $kerneldev = $get_kernel_device_name->($pool, $name);
+
+    return $kerneldev if -b $kerneldev; # already mapped
+
+    &$krbd_feature_disable($scfg, $storeid, $name);
 
-    $name .= '@'.$snapname if $snapname;
     my $cmd = &$rbd_cmd($scfg, $storeid, 'map', $name);
-    run_rbd_command($cmd, errmsg => "can't mount rbd volume $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 $pool =  $scfg->{pool} ? $scfg->{pool} : 'rbd';
+
+    my $kerneldev = $get_kernel_device_name->($pool, $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;
 }
 
-sub deactivate_volume {
+sub activate_volume {
     my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
 
-    return 1 if !$scfg->{krbd};
+    $class->map_volume($storeid, $scfg, $volname, $snapname) if $scfg->{krbd};
 
-    my ($vtype, $name, $vmid) = $class->parse_volname($volname);
-    my $pool =  $scfg->{pool} ? $scfg->{pool} : 'rbd';
+    return 1;
+}
 
-    my $path = "/dev/rbd/$pool/$name";
-    $path .= '@'.$snapname if $snapname;
-    return if ! -b $path;
+sub deactivate_volume {
+    my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
 
-    my $cmd = &$rbd_cmd($scfg, $storeid, 'unmap', $path);
-    run_rbd_command($cmd, errmsg => "can't unmap rbd volume $name");
+    $class->unmap_volume($storeid, $scfg, $volname, $snapname);
 
     return 1;
 }
@@ -592,7 +609,7 @@ sub volume_size_info {
 sub volume_resize {
     my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
 
-    return 1 if $running && !$scfg->{krbd};
+    return 1 if $running && !$scfg->{krbd}; # FIXME???
 
     my ($vtype, $name, $vmid) = $class->parse_volname($volname);
 
@@ -623,7 +640,7 @@ sub volume_snapshot_rollback {
 sub volume_snapshot_delete {
     my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
 
-    return 1 if $running && !$scfg->{krbd};
+    return 1 if $running && !$scfg->{krbd}; # FIXME: ????
 
     $class->deactivate_volume($storeid, $scfg, $volname, $snap, {});