]> 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 35ad72fbb21737d61f70b40cfa159f88a86236c2..69faf8d01f8e063b7f8e9075434542426b056907 100755 (executable)
@@ -7,6 +7,7 @@ use POSIX;
 use Fcntl;
 use File::Copy 'copy';
 
+use PVE::GuestHelpers;
 use PVE::SafeSyslog;
 use PVE::Tools qw(extract_param);
 use PVE::CpuSet;
@@ -19,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);
 
@@ -209,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()],
            },
        },
     },
@@ -231,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};
 
@@ -246,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)) {
@@ -258,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);
@@ -376,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};
 
@@ -699,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;
@@ -712,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 = ': ';
@@ -762,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' },
@@ -777,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);
            });
@@ -799,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'], 
@@ -821,23 +833,33 @@ our $cmddef = {
                        }
                    }
                }],
+
+    pending => [ "PVE::API2::LXC", "vm_pending", ['vmid'], { node => $nodename }, \&PVE::GuestHelpers::format_pending ],
     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']],
@@ -852,34 +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 },
-                     sub {
-                         my $res = shift;
-                         foreach my $e (@$res) {
-                             my $headline = $e->{description} || 'no-description';
-                             $headline =~ s/\n.*//sg;
-                             my $parent = $e->{parent} // 'no-parent';
-                             printf("%-20s %-20s %s\n", $e->{name}, $parent, $headline);
-                         }
-                     }],
-
-    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']],
-
 };