Skip to content

Commit

Permalink
osctld: introduce prlimit manager
Browse files Browse the repository at this point in the history
  • Loading branch information
aither64 committed Nov 16, 2018
1 parent e9b2d1c commit a6775b1
Show file tree
Hide file tree
Showing 22 changed files with 153 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .build_id
@@ -1 +1 @@
18.09.0.build20181115124313
18.09.0.build20181116172621
2 changes: 1 addition & 1 deletion os/packages/osctl/Gemfile
@@ -1,2 +1,2 @@
source 'https://rubygems.vpsfree.cz'
gem 'osctl', '18.09.0.build20181115124313'
gem 'osctl', '18.09.0.build20181116172621'
8 changes: 4 additions & 4 deletions os/packages/osctl/Gemfile.lock
Expand Up @@ -6,15 +6,15 @@ GEM
highline (1.7.10)
ipaddress (0.8.3)
json (2.1.0)
libosctl (18.09.0.build20181115124313)
libosctl (18.09.0.build20181116172621)
require_all (~> 2.0.0)
osctl (18.09.0.build20181115124313)
osctl (18.09.0.build20181116172621)
curses
gli (~> 2.17.1)
highline (~> 1.7.10)
ipaddress (~> 0.8.3)
json
libosctl (= 18.09.0.build20181115124313)
libosctl (= 18.09.0.build20181116172621)
rainbow (~> 3.0.0)
require_all (~> 2.0.0)
ruby-progressbar (~> 1.9.0)
Expand All @@ -26,7 +26,7 @@ PLATFORMS
ruby

DEPENDENCIES
osctl (= 18.09.0.build20181115124313)
osctl (= 18.09.0.build20181116172621)

BUNDLED WITH
1.16.3
8 changes: 4 additions & 4 deletions os/packages/osctl/gemset.nix
Expand Up @@ -43,19 +43,19 @@
dependencies = ["require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "0ibqm6hs74gh2dn23ir0aqs3l25rssh5wjqbvbjvsnvcbki2lnkj";
sha256 = "0kk7v1zafjrji9dj6frvph9qgdrqly8y8yw70xkhamdh0dcjv152";
type = "gem";
};
version = "18.09.0.build20181115124313";
version = "18.09.0.build20181116172621";
};
osctl = {
dependencies = ["curses" "gli" "highline" "ipaddress" "json" "libosctl" "rainbow" "require_all" "ruby-progressbar"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "1wb7c70bcqvrvr8x85x6iyx7lkl716sbh0k1b72iy3icyzinzil3";
sha256 = "0384n277r380bkpvvgbkzk6dzg9fvp8syzb5v7fqhlpb8y6cyqdi";
type = "gem";
};
version = "18.09.0.build20181115124313";
version = "18.09.0.build20181116172621";
};
rainbow = {
source = {
Expand Down
2 changes: 1 addition & 1 deletion os/packages/osctld/Gemfile
@@ -1,2 +1,2 @@
source 'https://rubygems.vpsfree.cz'
gem 'osctld', '18.09.0.build20181115124313'
gem 'osctld', '18.09.0.build20181116172621'
20 changes: 10 additions & 10 deletions os/packages/osctld/Gemfile.lock
Expand Up @@ -6,29 +6,29 @@ GEM
gli (2.17.2)
ipaddress (0.8.3)
json (2.1.0)
libosctl (18.09.0.build20181115124313)
libosctl (18.09.0.build20181116172621)
require_all (~> 2.0.0)
netlinkrb (0.18.vpsadminos.0)
osctl-repo (18.09.0.build20181115124313)
osctl-repo (18.09.0.build20181116172621)
filelock
gli (~> 2.17.1)
json
libosctl (= 18.09.0.build20181115124313)
libosctl (= 18.09.0.build20181116172621)
require_all (~> 2.0.0)
osctld (18.09.0.build20181115124313)
osctld (18.09.0.build20181116172621)
concurrent-ruby (~> 1.0.5)
ipaddress (~> 0.8.3)
json
libosctl (= 18.09.0.build20181115124313)
libosctl (= 18.09.0.build20181116172621)
netlinkrb (= 0.18.vpsadminos.0)
osctl-repo (= 18.09.0.build20181115124313)
osup (= 18.09.0.build20181115124313)
osctl-repo (= 18.09.0.build20181116172621)
osup (= 18.09.0.build20181116172621)
require_all (~> 2.0.0)
ruby-lxc (= 1.2.3)
osup (18.09.0.build20181115124313)
osup (18.09.0.build20181116172621)
gli (~> 2.17.1)
json
libosctl (= 18.09.0.build20181115124313)
libosctl (= 18.09.0.build20181116172621)
require_all (~> 2.0.0)
require_all (2.0.0)
ruby-lxc (1.2.3)
Expand All @@ -37,7 +37,7 @@ PLATFORMS
ruby

DEPENDENCIES
osctld (= 18.09.0.build20181115124313)
osctld (= 18.09.0.build20181116172621)

BUNDLED WITH
1.16.3
16 changes: 8 additions & 8 deletions os/packages/osctld/gemset.nix
Expand Up @@ -43,10 +43,10 @@
dependencies = ["require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "0ibqm6hs74gh2dn23ir0aqs3l25rssh5wjqbvbjvsnvcbki2lnkj";
sha256 = "0kk7v1zafjrji9dj6frvph9qgdrqly8y8yw70xkhamdh0dcjv152";
type = "gem";
};
version = "18.09.0.build20181115124313";
version = "18.09.0.build20181116172621";
};
netlinkrb = {
source = {
Expand All @@ -60,28 +60,28 @@
dependencies = ["filelock" "gli" "json" "libosctl" "require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "1j0dz5q7hl1di2rzppfsa0fgin63l4nm3gyib4v726c5403l9dnk";
sha256 = "0mghxd0j6iy5b777hmbq3h0g26j10yvvg2whw3b2hn322bh6l6j1";
type = "gem";
};
version = "18.09.0.build20181115124313";
version = "18.09.0.build20181116172621";
};
osctld = {
dependencies = ["concurrent-ruby" "ipaddress" "json" "libosctl" "netlinkrb" "osctl-repo" "osup" "require_all" "ruby-lxc"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "00w6b0a01ckz7vr2d704j1isx6lnpcrkgn72ddasw392pqli83bi";
sha256 = "02yb1837v7kbxinl51jlxsrjgb5q8lhjig94fpmcwscsdh3rd02b";
type = "gem";
};
version = "18.09.0.build20181115124313";
version = "18.09.0.build20181116172621";
};
osup = {
dependencies = ["gli" "json" "libosctl" "require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "0piqri8m1drpgcp7bqpgk1kh9kbzssfybbkzvp2whfdpmnkndvm5";
sha256 = "0vj90ig2rvrwqhmrc8bkzz7nac429zqnp2fj70dq9s2h6j6mjdyv";
type = "gem";
};
version = "18.09.0.build20181115124313";
version = "18.09.0.build20181116172621";
};
require_all = {
source = {
Expand Down
2 changes: 1 addition & 1 deletion os/packages/osup/Gemfile
@@ -1,2 +1,2 @@
source 'https://rubygems.vpsfree.cz'
gem 'osup', '18.09.0.build20181115124313'
gem 'osup', '18.09.0.build20181116172621'
8 changes: 4 additions & 4 deletions os/packages/osup/Gemfile.lock
Expand Up @@ -3,20 +3,20 @@ GEM
specs:
gli (2.17.2)
json (2.1.0)
libosctl (18.09.0.build20181115124313)
libosctl (18.09.0.build20181116172621)
require_all (~> 2.0.0)
osup (18.09.0.build20181115124313)
osup (18.09.0.build20181116172621)
gli (~> 2.17.1)
json
libosctl (= 18.09.0.build20181115124313)
libosctl (= 18.09.0.build20181116172621)
require_all (~> 2.0.0)
require_all (2.0.0)

PLATFORMS
ruby

DEPENDENCIES
osup (= 18.09.0.build20181115124313)
osup (= 18.09.0.build20181116172621)

BUNDLED WITH
1.16.3
8 changes: 4 additions & 4 deletions os/packages/osup/gemset.nix
Expand Up @@ -19,19 +19,19 @@
dependencies = ["require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "0ibqm6hs74gh2dn23ir0aqs3l25rssh5wjqbvbjvsnvcbki2lnkj";
sha256 = "0kk7v1zafjrji9dj6frvph9qgdrqly8y8yw70xkhamdh0dcjv152";
type = "gem";
};
version = "18.09.0.build20181115124313";
version = "18.09.0.build20181116172621";
};
osup = {
dependencies = ["gli" "json" "libosctl" "require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "0piqri8m1drpgcp7bqpgk1kh9kbzssfybbkzvp2whfdpmnkndvm5";
sha256 = "0vj90ig2rvrwqhmrc8bkzz7nac429zqnp2fj70dq9s2h6j6mjdyv";
type = "gem";
};
version = "18.09.0.build20181115124313";
version = "18.09.0.build20181116172621";
};
require_all = {
source = {
Expand Down
2 changes: 1 addition & 1 deletion os/packages/svctl/Gemfile
@@ -1,2 +1,2 @@
source 'https://rubygems.vpsfree.cz'
gem 'svctl', '18.09.0.build20181115124313'
gem 'svctl', '18.09.0.build20181116172621'
8 changes: 4 additions & 4 deletions os/packages/svctl/Gemfile.lock
Expand Up @@ -2,18 +2,18 @@ GEM
remote: https://rubygems.vpsfree.cz/
specs:
gli (2.17.2)
libosctl (18.09.0.build20181115124313)
libosctl (18.09.0.build20181116172621)
require_all (~> 2.0.0)
require_all (2.0.0)
svctl (18.09.0.build20181115124313)
svctl (18.09.0.build20181116172621)
gli (~> 2.17.1)
libosctl (= 18.09.0.build20181115124313)
libosctl (= 18.09.0.build20181116172621)

PLATFORMS
ruby

DEPENDENCIES
svctl (= 18.09.0.build20181115124313)
svctl (= 18.09.0.build20181116172621)

BUNDLED WITH
1.16.3
8 changes: 4 additions & 4 deletions os/packages/svctl/gemset.nix
Expand Up @@ -11,10 +11,10 @@
dependencies = ["require_all"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "0ibqm6hs74gh2dn23ir0aqs3l25rssh5wjqbvbjvsnvcbki2lnkj";
sha256 = "0kk7v1zafjrji9dj6frvph9qgdrqly8y8yw70xkhamdh0dcjv152";
type = "gem";
};
version = "18.09.0.build20181115124313";
version = "18.09.0.build20181116172621";
};
require_all = {
source = {
Expand All @@ -28,9 +28,9 @@
dependencies = ["gli" "libosctl"];
source = {
remotes = ["https://rubygems.vpsfree.cz"];
sha256 = "1wwsf4z78wl2p9bf297rakyw0539007ky3ipjbvay6d62hdi5k7w";
sha256 = "1kmha18nciayy0gn1j4g884rxypws7kz62fbc06ynclx61v987md";
type = "gem";
};
version = "18.09.0.build20181115124313";
version = "18.09.0.build20181116172621";
};
}
3 changes: 2 additions & 1 deletion osctl/lib/osctl/cli/container.rb
Expand Up @@ -925,7 +925,8 @@ def prlimit_list
cols = PRLIMIT_FIELDS
end

osctld_fmt(:ct_prlimit_list, cmd_opts, cols, fmt_opts)
data = osctld_call(:ct_prlimit_list, cmd_opts)
format_output(data.map { |k, v| v.merge(name: k)}, cols, fmt_opts)
end

def prlimit_set
Expand Down
2 changes: 2 additions & 0 deletions osctld/lib/osctld.rb
Expand Up @@ -19,6 +19,7 @@ module DB ; end
module Devices ; end
module Generic ; end
module Mount ; end
module PrLimits ; end
module Routing ; end
module Utils ; end
module UserControl
Expand Down Expand Up @@ -64,6 +65,7 @@ def self.tpl(name)
require_rel 'osctld/monitor'
require_rel 'osctld/mount'
require_rel 'osctld/net_interface'
require_rel 'osctld/prlimits'
require_rel 'osctld/repository'
require_rel 'osctld/routing'
require_rel 'osctld/switch_user'
Expand Down
13 changes: 7 additions & 6 deletions osctld/lib/osctld/commands/container/prlimit_list.rb
Expand Up @@ -8,14 +8,15 @@ def execute
ct = DB::Containers.find(opts[:id], opts[:pool])
return error('container not found') unless ct

ct.inclusively do
ret = ct.prlimits.select do |limit|
next(false) if opts[:limits] && !opts[:limits].include?(limit.name)
true
end.map(&:export)
ret = {}

ok(ret)
ct.prlimits.each do |name, limit|
next if opts[:limits] && !opts[:limits].include?(name)

ret[name] = limit.export
end

ok(ret)
end
end
end
7 changes: 2 additions & 5 deletions osctld/lib/osctld/commands/container/prlimit_set.rb
Expand Up @@ -32,11 +32,8 @@ def execute(ct)
hard = parse(opts[:hard])

validate(opts[:name], soft, hard)

ct.exclusively do
ct.prlimit_set(opts[:name], soft, hard)
ok
end
ct.prlimits.set(opts[:name], soft, hard)
ok
end

protected
Expand Down
6 changes: 2 additions & 4 deletions osctld/lib/osctld/commands/container/prlimit_unset.rb
Expand Up @@ -10,10 +10,8 @@ def find
end

def execute(ct)
ct.exclusively do
ct.prlimit_unset(opts[:name])
ok
end
ct.prlimit_unset(opts[:name])
ok
end
end
end
8 changes: 5 additions & 3 deletions osctld/lib/osctld/container.rb
Expand Up @@ -49,7 +49,7 @@ def initialize(pool, id, user = nil, group = nil, dataset = nil, opts = {})
@netifs = NetInterface::Manager.new(self)
@cgparams = nil
@devices = nil
@prlimits = []
@prlimits = nil
@mounts = nil
@hostname = nil
@dns_resolvers = nil
Expand Down Expand Up @@ -79,6 +79,7 @@ def configure(distribution, version, arch)
@seccomp_profile = default_seccomp_profile
@cgparams = CGroup::ContainerParams.new(self)
@devices = Devices::ContainerManager.new(self)
@prlimits = PrLimits::Manager.new(self)
@mounts = Mount::Manager.new(self)
devices.init
save_config
Expand Down Expand Up @@ -579,7 +580,7 @@ def load_config(config = nil, init_devices = true)
@seccomp_profile = cfg['seccomp_profile'] || default_seccomp_profile
@migration_log = Migration::Log.load(cfg['migration_log']) if cfg['migration_log']
@cgparams = CGroup::ContainerParams.load(self, cfg['cgparams'])
@prlimits = (cfg['prlimits'] || []).map { |v| PrLimit.load(v) }
@prlimits = PrLimits::Manager.load(self, cfg['prlimits'] || {})
@attrs = Attributes.load(cfg['attrs'] || {})

# It's necessary to load devices _before_ netifs. The device manager needs
Expand Down Expand Up @@ -608,7 +609,7 @@ def dump
'net_interfaces' => netifs.dump,
'cgparams' => cgparams.dump,
'devices' => devices.dump,
'prlimits' => prlimits.map(&:dump),
'prlimits' => prlimits.dump,
'mounts' => mounts.dump,
'autostart' => autostart && autostart.dump,
'hostname' => hostname && hostname.to_s,
Expand Down Expand Up @@ -658,6 +659,7 @@ def clone_from(ct, id, opts = {})
@apparmor = @apparmor.dup(self)
@autostart = @autostart && @autostart.dup(self)
@cgparams = cgparams.dup(self)
@prlimits = prlimits.dup(self)
@mounts = mounts.dup(self)
@lxc_config = lxc_config.dup(self)
@attrs = attrs.dup
Expand Down

0 comments on commit a6775b1

Please sign in to comment.