]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/CLI/pct.pm
Implement pct mount/unmount
[pve-container.git] / src / PVE / CLI / pct.pm
index befe1971d32fcb8b667bef7a07798317c33c2f73..e5993534a6dbb18ffd9480f83d78d453d7b07ec1 100755 (executable)
@@ -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']],