]> git.proxmox.com Git - pve-container.git/commitdiff
fix #4470: pct fstrim: ignore bind or read-only mountpoints
authorFriedrich Weber <f.weber@proxmox.com>
Mon, 20 Feb 2023 10:04:45 +0000 (11:04 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 20 Feb 2023 10:27:30 +0000 (11:27 +0100)
Currently, `pct fstrim` will run `fstrim` on all mountpoints
of the container, including bind and read-only mountpoints.

However, trimming a bind mountpoint might trim a host
filesystem, which users may not expect. Also, trimming can
be considered a write operation, which users may not expect
to be carried out on a read-only mountpoint.

Hence, exclude bind mointpoints and read-only mountpoints
from trimming.

Signed-off-by: Friedrich Weber <f.weber@proxmox.com>
src/PVE/CLI/pct.pm

index 3ade2bac46aa7571625b2a52ebcaadd2eb4cd330..d559d00f33b75f0918d02a8621fd2e0b076aef1c 100755 (executable)
@@ -763,7 +763,7 @@ __PACKAGE__->register_method ({
     name => 'fstrim',
     path => 'fstrim',
     method => 'POST',
-    description => "Run fstrim on a chosen CT and its mountpoints.",
+    description => "Run fstrim on a chosen CT and its mountpoints, except bind or read-only mountpoints.",
     parameters => {
        additionalProperties => 0,
        properties => {
@@ -791,6 +791,7 @@ __PACKAGE__->register_method ({
            PVE::LXC::Config->foreach_volume($conf, sub {
                my ($name, $mp) = @_;
                $path = $mp->{mp};
+               return if $mp->{type} eq 'bind' || $mp->{ro};
                return if $param->{'ignore-mountpoints'} && $name =~ /^mp\d+/;
                my $cmd = ["fstrim", "-v", "$rootdir$path"];
                PVE::Tools::run_command($cmd, noerr => 1);