we need this for krbd volumes

Signed-off-by: Alexandre Derumier <aderum...@odiso.com>
---
 src/PVE/API2/LXC.pm | 15 +++++++++++++++
 src/PVE/LXC.pm      | 12 ++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 9e82bc4..f41d0df 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -942,6 +942,9 @@ __PACKAGE__->register_method({
                    PVE::Storage::activate_storage($stcfg, $sid);
                }
 
+               my $volid = $conf->{'pve.volid'};
+               PVE::Storage::activate_volumes($stcfg, [$volid]) if $volid;
+
                my $cmd = ['lxc-start', '-n', $vmid];
 
                run_command($cmd);
@@ -984,6 +987,10 @@ __PACKAGE__->register_method({
 
        my $vmid = extract_param($param, 'vmid');
 
+       my $conf = PVE::LXC::load_config($vmid);
+
+       my $storecfg = PVE::Storage::config();
+
        die "CT $vmid not running\n" if !PVE::LXC::check_running($vmid);
 
        if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 
'ha') {
@@ -1015,6 +1022,8 @@ __PACKAGE__->register_method({
 
                run_command($cmd);
 
+               PVE::LXC::vm_stop_cleanup($storecfg, $vmid, $conf);
+
                return;
            };
 
@@ -1068,6 +1077,10 @@ __PACKAGE__->register_method({
 
        my $timeout = extract_param($param, 'timeout');
 
+       my $conf = PVE::LXC::load_config($vmid);
+
+       my $storecfg = PVE::Storage::config();
+
        die "CT $vmid not running\n" if !PVE::LXC::check_running($vmid);
 
        my $realcmd = sub {
@@ -1092,6 +1105,8 @@ __PACKAGE__->register_method({
            push @$cmd, '--kill';
            run_command($cmd);
 
+            PVE::LXC::vm_stop_cleanup($storecfg, $vmid, $conf);
+
            return;
        };
 
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 2517ffd..0843c2e 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1670,4 +1670,16 @@ sub snapshot_rollback {
     lock_container($vmid, 5, $unlockfn);
 }
 
+sub vm_stop_cleanup {
+    my ($storecfg, $vmid, $conf, $keepActive) = @_;
+
+    eval {
+        if (!$keepActive) {
+          my $volid = $conf->{'pve.volid'};
+         PVE::Storage::deactivate_volumes($storecfg, [$volid]) if $volid;
+       }
+    };
+    warn $@ if $@; # avoid errors - just warn
+}
+
 1;
-- 
2.1.4

_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to