]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/CLI/pct.pm
vmstatus: make lock property optional again
[pve-container.git] / src / PVE / CLI / pct.pm
index 3a32de4d7faeeef45c478583725c1b05f98e8a8b..69faf8d01f8e063b7f8e9075434542426b056907 100755 (executable)
@@ -20,6 +20,7 @@ use PVE::API2::LXC;
 use PVE::API2::LXC::Config;
 use PVE::API2::LXC::Status;
 use PVE::API2::LXC::Snapshot;
+use PVE::LXC::CGroup;
 
 use base qw(PVE::CLIHandler);
 
@@ -210,7 +211,7 @@ __PACKAGE__->register_method ({
                optional => 1,
                type => 'string',
                description => "A volume on which to run the filesystem check",
-               enum => [PVE::LXC::Config->mountpoint_names()],
+               enum => [PVE::LXC::Config->valid_volume_keys()],
            },
        },
     },
@@ -232,8 +233,10 @@ __PACKAGE__->register_method ({
 
            defined($conf->{$device}) || die "cannot run command on non-existing mount point $device\n";
 
-           my $mount_point = $device eq 'rootfs' ? PVE::LXC::Config->parse_ct_rootfs($conf->{$device}) :
-               PVE::LXC::Config->parse_ct_mountpoint($conf->{$device});
+           my $mount_point = PVE::LXC::Config->parse_volume($device, $conf->{$device});
+
+           die "cannot run fsck when container is running\n"
+               if PVE::LXC::check_running($vmid);
 
            my $volid = $mount_point->{volume};
 
@@ -247,7 +250,7 @@ __PACKAGE__->register_method ({
                die "unable to run fsck for '$volid' (format == $format)\n"
                    if $format ne 'raw';
 
-               $path = PVE::Storage::path($storage_cfg, $volid);
+               $path = PVE::Storage::map_volume($storage_cfg, $volid);
 
            } else {
                if (($volid =~ m|^/.+|) && (-b $volid)) {
@@ -259,11 +262,9 @@ __PACKAGE__->register_method ({
            }
 
            push(@$command, $path);
-
-           PVE::LXC::check_running($vmid) &&
-               die "cannot run fsck on active container\n";
-
            PVE::Tools::run_command($command);
+
+           PVE::Storage::unmap_volume($storage_cfg, $volid) if $storage_id;
        };
 
        PVE::LXC::Config->lock_config($vmid, $do_fsck);
@@ -377,7 +378,7 @@ __PACKAGE__->register_method({
            my @len = map { length($_) } @{$list[0]};
 
            eval {
-               PVE::LXC::Config->foreach_mountpoint($conf, sub {
+               PVE::LXC::Config->foreach_volume($conf, sub {
                    my ($name, $mp) = @_;
                    my $path = $mp->{mp};
 
@@ -700,12 +701,6 @@ __PACKAGE__->register_method ({
     code => sub {
        my ($param) = @_;
 
-       my $cgv1 = PVE::LXC::get_cgroup_subsystems();
-       if (!$cgv1->{cpuset}) {
-           print "cpuset cgroup not available\n";
-           return undef;
-       }
-
        my $ctlist = PVE::LXC::config_list();
 
        my $len = 0;
@@ -713,13 +708,22 @@ __PACKAGE__->register_method ({
        my $res = {};
 
        foreach my $vmid (sort keys %$ctlist) {
-           next if ! -d "/sys/fs/cgroup/cpuset/lxc/$vmid";
+           my $cgroup = PVE::LXC::CGroup->new($vmid);
 
-           my $cpuset = eval { PVE::CpuSet->new_from_cgroup("lxc/$vmid"); };
+           my ($cpuset, $path);
+           if (defined($path = $cgroup->get_path('cpuset'))) {
+               $cpuset = eval { PVE::CpuSet->new_from_path($path); };
+           } elsif (defined($path = $cgroup->get_path())) {
+               $cpuset = eval { PVE::CpuSet->new_from_path($path); };
+           } else {
+               # Container not running.
+               next;
+           }
            if (my $err = $@) {
                warn $err;
                next;
            }
+
            my @cpuset_members = $cpuset->members();
 
            my $line = ': ';
@@ -763,6 +767,11 @@ __PACKAGE__->register_method ({
        additionalProperties => 0,
        properties => {
            vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
+           'ignore-mountpoints' => {
+               description => 'Skip all mountpoints, only do fstrim on the container root.',
+               optional => 1,
+               type => 'boolean',
+           },
        },
     },
     returns => { type => 'null' },
@@ -778,9 +787,10 @@ __PACKAGE__->register_method ({
        eval {
            my $path = "";
            PVE::LXC::mount_all($vmid, $storecfg, $conf);
-           PVE::LXC::Config->foreach_mountpoint($conf, sub {
+           PVE::LXC::Config->foreach_volume($conf, sub {
                my ($name, $mp) = @_;
                $path = $mp->{mp};
+               return if $param->{'ignore-mountpoints'} && $name =~ /^mp\d+/;
                my $cmd = ["fstrim", "-v", "$rootdir$path"];
                PVE::Tools::run_command($cmd);
            });
@@ -800,7 +810,8 @@ our $cmddef = {
        my $format = "%-10s %-10s %-12s %-20s\n";
        printf($format, 'VMID', 'Status', 'Lock', 'Name');
        foreach my $d (sort {$a->{vmid} <=> $b->{vmid} } @$res) {
-           printf($format, $d->{vmid}, $d->{status}, $d->{lock}, $d->{name});
+           my $lock = $d->{lock} || '';
+           printf($format, $d->{vmid}, $d->{status}, $lock, $d->{name});
        }
     }],
     config => [ "PVE::API2::LXC::Config", 'vm_config', ['vmid'], 
@@ -827,20 +838,28 @@ our $cmddef = {
     set => [ 'PVE::API2::LXC::Config', 'update_vm', ['vmid'], { node => $nodename }],
 
     resize => [ "PVE::API2::LXC", 'resize_vm', ['vmid', 'disk', 'size'], { node => $nodename } ],
-    
+
     create => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename }, $upid_exit ],
     restore => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename, restore => 1 }, $upid_exit ],
+    destroy => [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'], { node => $nodename }, $upid_exit ],
 
     start => [ 'PVE::API2::LXC::Status', 'vm_start', ['vmid'], { node => $nodename }, $upid_exit],
     suspend => [ 'PVE::API2::LXC::Status', 'vm_suspend', ['vmid'], { node => $nodename }, $upid_exit],
     resume => [ 'PVE::API2::LXC::Status', 'vm_resume', ['vmid'], { node => $nodename }, $upid_exit],
     shutdown => [ 'PVE::API2::LXC::Status', 'vm_shutdown', ['vmid'], { node => $nodename }, $upid_exit],
     stop => [ 'PVE::API2::LXC::Status', 'vm_stop', ['vmid'], { node => $nodename }, $upid_exit],
-    
+    reboot => [ 'PVE::API2::LXC::Status', 'vm_reboot', ['vmid'], { node => $nodename }, $upid_exit],
+
     clone => [ "PVE::API2::LXC", 'clone_vm', ['vmid', 'newid'], { node => $nodename }, $upid_exit ],
     migrate => [ "PVE::API2::LXC", 'migrate_vm', ['vmid', 'target'], { node => $nodename }, $upid_exit],
     move_volume => [ "PVE::API2::LXC", 'move_volume', ['vmid', 'volume', 'storage'], { node => $nodename }, $upid_exit ],
-    
+
+    snapshot => [ "PVE::API2::LXC::Snapshot", 'snapshot', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
+    delsnapshot => [ "PVE::API2::LXC::Snapshot", 'delsnapshot', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
+    listsnapshot => [ "PVE::API2::LXC::Snapshot", 'list', ['vmid'], { node => $nodename }, \&PVE::GuestHelpers::print_snapshot_tree ],
+    rollback => [ "PVE::API2::LXC::Snapshot", 'rollback', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
+    template => [ "PVE::API2::LXC", 'template', ['vmid'], { node => $nodename }],
+
     status => [ __PACKAGE__, 'status', ['vmid']],
     console => [ __PACKAGE__, 'console', ['vmid']],
     enter => [ __PACKAGE__, 'enter', ['vmid']],
@@ -855,25 +874,8 @@ our $cmddef = {
 
     df => [ __PACKAGE__, 'df', ['vmid']],
     rescan  => [ __PACKAGE__, 'rescan', []],
-
-    destroy => [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'], 
-                { node => $nodename }, $upid_exit ],
-
-    snapshot => [ "PVE::API2::LXC::Snapshot", 'snapshot', ['vmid', 'snapname'],
-                 { node => $nodename } , $upid_exit ],
-
-    delsnapshot => [ "PVE::API2::LXC::Snapshot", 'delsnapshot', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
-
-    listsnapshot => [ "PVE::API2::LXC::Snapshot", 'list', ['vmid'], { node => $nodename }, \&PVE::GuestHelpers::print_snapshot_tree ],
-
-    rollback => [ "PVE::API2::LXC::Snapshot", 'rollback', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
-
-    template => [ "PVE::API2::LXC", 'template', ['vmid'], { node => $nodename }],
-
     cpusets => [ __PACKAGE__, 'cpusets', []],
-
     fstrim => [ __PACKAGE__, 'fstrim', ['vmid']],
-
 };