]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/ISCSIDirectPlugin.pm
pbs: allow setting up a master key
[pve-storage.git] / PVE / Storage / ISCSIDirectPlugin.pm
index 6279aae298b62e3dc606ba3ff01c3af54555a0cf..9777969b39e02ee03c44aca84da332b8bb56a316 100644 (file)
@@ -17,29 +17,26 @@ sub iscsi_ls {
     my $portal = $scfg->{portal};
     my $cmd = ['/usr/bin/iscsi-ls', '-s', 'iscsi://'.$portal ];
     my $list = {};
-    my $test  = "";
-
-     my $errfunc = sub {
-         my $line = shift;
-         $line = trim($line);
-
-         die $line if $line;
-    };
-
+    my %unittobytes = (
+       "k"  => 1024,
+       "M" => 1024*1024,
+       "G" => 1024*1024*1024,
+       "T"   => 1024*1024*1024*1024
+    );
     eval {
 
-           run_command($cmd, errmsg => "iscsi error", errfunc => $errfunc, outfunc => sub {
+           run_command($cmd, errmsg => "iscsi error", errfunc => sub {}, outfunc => sub {
                my $line = shift;
                $line = trim($line);
-               if( $line =~ /Lun:(\d+)\s+([A-Za-z0-9\-\_\.\:]*)\s+\(Size:(\d+)G\)/ ) {
-               $test = $1;
-
-                   my $image = $1;
+               if( $line =~ /Lun:(\d+)\s+([A-Za-z0-9\-\_\.\:]*)\s+\(Size:([0-9\.]*)(k|M|G|T)\)/ ) {
+                   my $image = "lun".$1;
                    my $size = $3;
-
+                   my $unit = $4;
+                               
                    $list->{$storeid}->{$image} = {
                        name => $image,
-                       size => $size,
+                       size => $size * $unittobytes{$unit},
+                       format => 'raw',
                    };
                }
            });
@@ -47,7 +44,9 @@ sub iscsi_ls {
 
     my $err = $@;
     die $err if $err && $err !~ m/TESTUNITREADY failed with SENSE KEY/ ;
+
     return $list;
+
 }
 
 # Configuration
@@ -58,7 +57,8 @@ sub type {
 
 sub plugindata {
     return {
-        content => [ {images => 1, none => 1}, { images => 1 }],
+       content => [ {images => 1, none => 1}, { images => 1 }],
+       select_existing => 1,
     };
 }
 
@@ -69,6 +69,7 @@ sub options {
         nodes => { optional => 1},
         disable => { optional => 1},
         content => { optional => 1},
+        bwlimit => { optional => 1 },
     };
 }
 
@@ -78,8 +79,8 @@ sub parse_volname {
     my ($class, $volname) = @_;
 
 
-    if ($volname =~ m/^(\d+)$/) {
-       return ('images', $1, undef);
+    if ($volname =~ m/^lun(\d+)$/) {
+       return ('images', $1, undef, undef, undef, undef, 'raw');
     }
 
     die "unable to parse iscsi volume name '$volname'\n";
@@ -87,7 +88,10 @@ sub parse_volname {
 }
 
 sub path {
-    my ($class, $scfg, $volname) = @_;
+    my ($class, $scfg, $volname, $storeid, $snapname) = @_;
+
+    die "volume snapshot is not possible on iscsi device"
+       if defined($snapname);
 
     my ($vtype, $lun, $vmid) = $class->parse_volname($volname);
 
@@ -99,6 +103,17 @@ sub path {
     return ($path, $vmid, $vtype);
 }
 
+sub create_base {
+    my ($class, $storeid, $scfg, $volname) = @_;
+
+    die "can't create base images in iscsi storage\n";
+}
+
+sub clone_image {
+    my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
+
+    die "can't clone images in iscsi storage\n";
+}
 
 sub alloc_image {
     my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
@@ -107,7 +122,7 @@ sub alloc_image {
 }
 
 sub free_image {
-    my ($class, $storeid, $scfg, $volname) = @_;
+    my ($class, $storeid, $scfg, $volname, $isBase) = @_;
 
     die "can't free space in iscsi storage\n";
 }
@@ -172,18 +187,68 @@ sub deactivate_storage {
 }
 
 sub activate_volume {
-    my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
+
+    die "volume snapshot is not possible on iscsi device" if $snapname;
+
     return 1;
 }
 
 sub deactivate_volume {
-    my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
+    my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
+
+    die "volume snapshot is not possible on iscsi device" if $snapname;
+
     return 1;
 }
 
 sub volume_size_info {
     my ($class, $scfg, $storeid, $volname, $timeout) = @_;
 
+    my $vollist = iscsi_ls($scfg,$storeid);
+    my $info = $vollist->{$storeid}->{$volname};
+
+    return $info->{size};
+}
+
+sub volume_resize {
+    my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
+    die "volume resize is not possible on iscsi device";
+}
+
+sub volume_snapshot {
+    my ($class, $scfg, $storeid, $volname, $snap) = @_;
+    die "volume snapshot is not possible on iscsi device";
+}
+
+sub volume_snapshot_rollback {
+    my ($class, $scfg, $storeid, $volname, $snap) = @_;
+    die "volume snapshot rollback is not possible on iscsi device";
+}
+
+sub volume_snapshot_delete {
+    my ($class, $scfg, $storeid, $volname, $snap) = @_;
+    die "volume snapshot delete is not possible on iscsi device";
+}
+
+sub volume_has_feature {
+    my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
+    
+    my $features = {
+       copy => { current => 1},
+    };
+
+    my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
+       $class->parse_volname($volname);
+
+    my $key = undef;
+    if($snapname){
+       $key = 'snap';
+    }else{
+       $key =  $isBase ? 'base' : 'current';
+    }
+    return 1 if $features->{$feature}->{$key};
+
     return undef;
 }