[pve-devel] [PATCH v7 pve-storage 06/10] Implement support for volume resize

mir at datanom.net mir at datanom.net
Tue Jun 20 22:39:58 CEST 2017


From: Michael Rasmussen <mir at datanom.net>

Signed-off-by: Michael Rasmussen <mir at datanom.net>
---
 PVE/Storage/FreeNASPlugin.pm | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/PVE/Storage/FreeNASPlugin.pm b/PVE/Storage/FreeNASPlugin.pm
index 91a1b0c..943eeab 100644
--- a/PVE/Storage/FreeNASPlugin.pm
+++ b/PVE/Storage/FreeNASPlugin.pm
@@ -842,6 +842,8 @@ my $rescan_session = sub {
     my $sid = $get_sid->($scfg, $volname);
     die "Missing session\n" if $sid < 0;
     $os_request->(['iscsiadm', '-m', 'session', '-r', $sid, '-R'], 0, 60);
+    $os_request->(['udevadm', 'trigger', '--subsystem-match=scsi_disk'], 0, 60);
+    $os_request->(['udevadm', 'settle', '-t', $api_timeout], 0, 60);
     $deactivate_luns->($scfg, $volname, $luns_to_keep);
     $delete_session->($scfg, $sid) unless %$luns_to_keep;
 };
@@ -1044,6 +1046,35 @@ sub volume_resize {
 
     my ($vtype, $name, $vmid) = $class->parse_volname($volname);
 
+    my $data = {
+        volsize => $size,
+    };
+    my $vol = $freenas_request->(
+        $scfg, 'PUT', "storage/volume/$scfg->{pool}/zvols/$name", encode_json($data));
+
+    my $sid = $get_sid->($scfg, $name);
+    if ($sid >= 0) {
+        eval {
+#### Required because of a bug in FreeNAS: https://bugs.freenas.org/issues/24432
+            my $targetname = $freenas_get_target_name->($scfg, $name);
+            die "volume_resize-> Missing target name\n" unless $targetname;
+            my $target = $freenas_get_target->($scfg, $vmid);
+            die "volume_resize-> Missing target\n" unless $target;
+            my $extent = $freenas_get_extent->($scfg, $name);
+            die "volume_resize-> Missing extent\n" unless $extent;
+            my $tg2exent = $freenas_get_target_to_exent->($scfg, $extent, $target);
+            die "volume_resize-> Missing target to extent\n" unless $tg2exent;
+            my $lunid = $freenas_get_lun_number->($scfg, $name);
+            die "volume_resize-> Missing LUN\n" unless defined $lunid;
+            $freenas_delete_target_to_exent->($scfg, $tg2exent);
+            $freenas_create_target_to_exent->($scfg, $target, $extent, $lunid);
+#### Required because of a bug in FreeNAS: https://bugs.freenas.org/issues/24432
+            $rescan_session->($class, $storeid, $scfg, $name);
+        };
+        die "$name: Resize with $size failed or could not export new size. ($@)\n" if $@;
+    }
+
+    return int($vol->{volsize}/1024);
 }
 
 sub volume_snapshot {
-- 
2.11.0


----

This mail was virus scanned and spam checked before delivery.
This mail is also DKIM signed. See header dkim-signature.




More information about the pve-devel mailing list