Class: OsCtld::UserControl::Commands::CtOnStart
- Inherits:
-
Base
show all
- Includes:
- OsCtl::Lib::Utils::Log
- Defined in:
- lib/osctld/user_control/commands/ct_on_start.rb
Constant Summary
collapse
- CGROUP_DELEGATE_BUSY_RETRIES =
100
- CGROUP_DELEGATE_BUSY_RETRY_DELAY =
0.1
- CGROUP_DELEGATE_RETRYABLE_ERRORS =
[
Errno::EBUSY,
Errno::EOPNOTSUPP,
Errno::EINVAL
].freeze
Instance Attribute Summary
Attributes inherited from Base
#user
#client, #client_handler, #id, #opts
Instance Method Summary
collapse
Methods inherited from Base
handle, #initialize, #owns_ct?, run
#base_execute, #call_cmd, #call_cmd!, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!
Instance Method Details
#delegate_start_cgroup_ancestors(ct, root_cgroup) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/osctld/user_control/commands/ct_on_start.rb', line 75
def delegate_start_cgroup_ancestors(ct, root_cgroup)
cgroup_fs = File.expand_path(CGroup.fs)
path = File.dirname(File.expand_path(root_cgroup))
ancestors = []
loop do
break if path == cgroup_fs || path == '/'
break unless path.start_with?("#{cgroup_fs}/")
ancestors << path
path = File.dirname(path)
end
ancestors.reverse_each do |ancestor|
delegate_start_cgroup_controllers(ct, ancestor)
end
end
|
#delegate_start_cgroup_controllers(ct, root_cgroup) ⇒ Object
#delegate_start_cgroups(ct) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/osctld/user_control/commands/ct_on_start.rb', line 36
def delegate_start_cgroups(ct)
return unless CGroup.v2?
uid = ct.user.ugid
gid = ct.root_host_gid
root_cgroup = CGroup.abs_cgroup_path(nil, ct.cgroup_path)
delegate_start_cgroup_ancestors(ct, root_cgroup)
CGroup.chown_delegated(
root_cgroup,
uid:,
gid:
)
delegate_start_cgroup_controllers(ct, root_cgroup) do
ensure_start_cgroup_empty!(ct)
end
begin
CGroup.chown_delegated(
CGroup.abs_cgroup_path(nil, ct.payload_cgroup_path),
uid:,
gid:
)
rescue Errno::ENOENT
nil
end
end
|
#ensure_start_cgroup_empty!(ct) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/osctld/user_control/commands/ct_on_start.rb', line 118
def ensure_start_cgroup_empty!(ct)
pids = CGroup.get_cgroup_pids(nil, ct.cgroup_path)
return if pids.empty?
raise Errno::EBUSY,
"unexpected processes remain in the container cgroup: #{pids.join(', ')}"
end
|
#execute ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/osctld/user_control/commands/ct_on_start.rb', line 18
def execute
ct = DB::Containers.find(opts[:id], opts[:pool])
return error('container not found') unless ct
return error('access denied') unless owns_ct?(ct)
delegate_start_cgroups(ct)
DistConfig.run(ct.run_conf, :start)
Hook.run(ct, :on_start)
ok
rescue HookFailed => e
error(e.message)
end
|