[pve-devel] [PATCH container 3/5] Implement pct mount/unmount

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Feb 26 11:42:10 CET 2016


These are for emergency maintenance and put the container
into a locked state ('mounted' lock).
---
 src/PVE/CLI/pct.pm | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index befe197..e599353 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -211,6 +211,61 @@ __PACKAGE__->register_method ({
 	return undef;
     }});
 
+__PACKAGE__->register_method({
+    name => 'mount',
+    path => 'mount',
+    method => 'POST',
+    description => "Mount the container's filesystem on the host. " .
+		   "This will hold a lock on the container and is meant for emergency maintenance only " .
+		   "as it will prevent further operations on the container other than start and stop.",
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
+	},
+    },
+    returns => { type => 'null' },
+    code => sub {
+	my ($param) = @_;
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+
+	my $vmid = extract_param($param, 'vmid');
+	my $storecfg = PVE::Storage::config();
+	PVE::LXC::lock_config($vmid, sub {
+	    my $conf = PVE::LXC::set_lock($vmid, 'mounted');
+	    PVE::LXC::mount_all($vmid, $storecfg, $conf);
+	});
+	return undef;
+    }});
+
+__PACKAGE__->register_method({
+    name => 'unmount',
+    path => 'unmount',
+    method => 'POST',
+    description => "Unmount the container's filesystem.",
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
+	},
+    },
+    returns => { type => 'null' },
+    code => sub {
+	my ($param) = @_;
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+
+	my $vmid = extract_param($param, 'vmid');
+	my $storecfg = PVE::Storage::config();
+	PVE::LXC::lock_config($vmid, sub {
+	    my $conf = PVE::LXC::load_config($vmid);
+	    PVE::LXC::umount_all($vmid, $storecfg, $conf, 0);
+	    PVE::LXC::remove_lock($vmid, 'mounted');
+	});
+	return undef;
+    }});
+
 # File creation with specified ownership and permissions.
 # User and group can be names or decimal numbers.
 # Permissions are explicit (not affected by umask) and can be numeric with the
@@ -495,6 +550,8 @@ our $cmddef = {
     exec => [ __PACKAGE__, 'exec', ['vmid', 'extra-args']],
     fsck => [ __PACKAGE__, 'fsck', ['vmid']],
 
+    mount => [ __PACKAGE__, 'mount', ['vmid']],
+    unmount => [ __PACKAGE__, 'unmount', ['vmid']],
     push => [ __PACKAGE__, 'push', ['vmid', 'file', 'destination']],
     pull => [ __PACKAGE__, 'pull', ['vmid', 'path', 'destination']],
     
-- 
2.1.4





More information about the pve-devel mailing list