sub vmstatus {
my ($opt_vmid) = @_;
- my $list = $opt_vmid ? { $opt_vmid => { type => 'lxc', vmid => $opt_vmid }} : config_list();
+ my $list = $opt_vmid ? { $opt_vmid => { type => 'lxc', vmid => int($opt_vmid) }} : config_list();
my $active_hash = list_active_containers();
foreach my $vmid (keys %$list) {
my $d = $list->{$vmid};
- eval { $d->{pid} = find_lxc_pid($vmid) if defined($active_hash->{$vmid}); };
+ eval { $d->{pid} = int(find_lxc_pid($vmid)) if defined($active_hash->{$vmid}); };
warn $@ if $@; # ignore errors (consider them stopped)
$d->{status} = $active_hash->{$vmid} ? 'running' : 'stopped';
if ($d->{pid}) {
my $res = get_container_disk_usage($vmid, $d->{pid});
- $d->{disk} = $res->{used};
- $d->{maxdisk} = $res->{total};
+ $d->{disk} = int($res->{used});
+ $d->{maxdisk} = int($res->{total});
} else {
$d->{disk} = 0;
# use 4GB by default ??
$d->{diskread} = 0;
$d->{diskwrite} = 0;
- $d->{template} = PVE::LXC::Config->is_template($conf);
+ $d->{template} = 1 if PVE::LXC::Config->is_template($conf);
$d->{lock} = $conf->{lock} if $conf->{lock};
}
my $cgroups = PVE::LXC::CGroup->new($vmid);
if (defined(my $mem = $cgroups->get_memory_stat())) {
- $d->{mem} = $mem->{mem};
- $d->{swap} = $mem->{swap};
+ $d->{mem} = int($mem->{mem});
+ $d->{swap} = int($mem->{swap});
} else {
$d->{mem} = 0;
$d->{swap} = 0;
}
if (defined(my $blkio = $cgroups->get_io_stats())) {
- $d->{diskread} = $blkio->{diskread};
- $d->{diskwrite} = $blkio->{diskwrite};
+ $d->{diskread} = int($blkio->{diskread});
+ $d->{diskwrite} = int($blkio->{diskwrite});
} else {
$d->{diskread} = 0;
$d->{diskwrite} = 0;
die "unable to parse ipv4 address/mask\n";
}
-# Deprecated. Use `PVE::CGroup::get_cgroup_controllers()` instead.
-sub get_cgroup_subsystems {
- PVE::CGroup::get_v1_controllers();
-}
-
# With seccomp trap to userspace we now have the ability to optionally forward
# certain syscalls to the "host" to handle (via our pve-lxc-syscalld daemon).
#
# files while the container is running!
$raw .= "lxc.monitor.unshare = 1\n";
- my $cgv1 = get_cgroup_subsystems();
+ my ($cgv1, $cgv2) = PVE::CGroup::get_cgroup_controllers();
# Should we read them from /etc/subuid?
if ($unprivileged && !$custom_idmap) {
if (!PVE::LXC::Config->has_dev_console($conf)) {
$raw .= "lxc.console.path = none\n";
- $raw .= "lxc.cgroup.devices.deny = c 5:1 rwm\n" if $cgv1->{devices};
+ if ($cgv1->{devices}) {
+ $raw .= "lxc.cgroup.devices.deny = c 5:1 rwm\n";
+ } elsif (defined($cgv2)) {
+ $raw .= "lxc.cgroup2.devices.deny = c 5:1 rwm\n";
+ }
}
my $ttycount = PVE::LXC::Config->get_tty_count($conf);
my $lxcswap = int(($memory + $swap)*1024*1024);
$raw .= "lxc.cgroup.memory.memsw.limit_in_bytes = $lxcswap\n";
+ } elsif ($cgv2->{memory}) {
+ my $memory = $conf->{memory} || 512;
+ my $swap = $conf->{swap} // 0;
+
+ my $lxcmem = int($memory*1024*1024);
+ $raw .= "lxc.cgroup2.memory.max = $lxcmem\n";
+
+ my $lxcswap = int($swap*1024*1024);
+ $raw .= "lxc.cgroup2.memory.swap.max = $lxcswap\n";
}
if ($cgv1->{cpu}) {
my $shares = $conf->{cpuunits} || 1024;
$raw .= "lxc.cgroup.cpu.shares = $shares\n";
+ } elsif ($cgv2->{cpu}) {
+ # See PVE::CGroup
+ if (my $cpulimit = $conf->{cpulimit}) {
+ my $value = int(100000*$cpulimit);
+ $raw .= "lxc.cgroup2.cpu.max = $value 100000\n";
+ }
+
+ if (defined(my $shares = $conf->{cpuunits})) {
+ die "cpu weight (shares) must be in range [1, 10000]\n"
+ if $shares < 1 || $shares > 10000;
+ $raw .= "lxc.cgroup2.cpu.weight = $shares\n";
+ }
}
die "missing 'rootfs' configuration\n"
}
};
my $use_loopdev = 0;
- if ($scfg->{path}) {
- $mounted_dev = run_with_loopdev($domount, $path, $readonly);
- $use_loopdev = 1;
- } elsif ($scfg->{type} eq 'drbd' || $scfg->{type} eq 'lvm' ||
- $scfg->{type} eq 'rbd' || $scfg->{type} eq 'lvmthin') {
- $mounted_dev = $path;
- &$domount($path);
+ if ($scfg->{content}->{rootdir}) {
+ if ($scfg->{path}) {
+ $mounted_dev = run_with_loopdev($domount, $path, $readonly);
+ $use_loopdev = 1;
+ } else {
+ $mounted_dev = $path;
+ &$domount($path);
+ }
} else {
- die "unsupported storage type '$scfg->{type}'\n";
+ die "storage '$storage' does not support containers\n";
}
return wantarray ? ($path, $use_loopdev, $mounted_dev) : $path;
} else {
eval {
my $do_format = 0;
- if ($scfg->{type} eq 'dir' || $scfg->{type} eq 'nfs' || $scfg->{type} eq 'cifs' ) {
+ if ($scfg->{content}->{rootdir} && $scfg->{path}) {
if ($size_kb > 0) {
- $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw',
- undef, $size_kb);
+ $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw', undef, $size_kb);
$do_format = 1;
} else {
- $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'subvol',
- undef, 0);
+ $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'subvol', undef, 0);
$needs_chown = 1;
}
} elsif ($scfg->{type} eq 'zfspool') {
-
- $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'subvol',
- undef, $size_kb);
+ $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'subvol', undef, $size_kb);
$needs_chown = 1;
- } elsif ($scfg->{type} eq 'drbd' || $scfg->{type} eq 'lvm' || $scfg->{type} eq 'lvmthin') {
-
- $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw', undef, $size_kb);
- $do_format = 1;
-
- } elsif ($scfg->{type} eq 'rbd') {
-
+ } elsif ($scfg->{content}->{rootdir}) {
$volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw', undef, $size_kb);
$do_format = 1;
} else {
- die "unable to create containers on storage type '$scfg->{type}'\n";
+ die "content type 'rootdir' is not available or configured on storage '$storage'\n";
}
format_disk($storecfg, $volid, $rootuid, $rootgid) if $do_format;
};