line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::IOLoop::ReadWriteProcess::CGroup::v1; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Refer to https://www.kernel.org/doc/Documentation/cgroup-v1/ for details |
4
|
|
|
|
|
|
|
|
5
|
15
|
|
|
15
|
|
105
|
use Mojo::Base 'Mojo::IOLoop::ReadWriteProcess::CGroup'; |
|
15
|
|
|
|
|
28
|
|
|
15
|
|
|
|
|
112
|
|
6
|
15
|
|
|
15
|
|
2619
|
use Mojo::File 'path'; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
804
|
|
7
|
15
|
|
|
15
|
|
223
|
use Mojo::Collection 'c'; |
|
15
|
|
|
|
|
48
|
|
|
15
|
|
|
|
|
859
|
|
8
|
15
|
|
|
15
|
|
109
|
use Carp 'confess'; |
|
15
|
|
|
|
|
119
|
|
|
15
|
|
|
|
|
1088
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(cgroup); |
10
|
15
|
|
|
15
|
|
95
|
use Exporter 'import'; |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
712
|
|
11
|
|
|
|
|
|
|
|
12
|
15
|
|
|
15
|
|
93
|
use constant {PROCS_INTERFACE => 'cgroup.procs', TASKS_INTERFACE => 'tasks'}; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
1253
|
|
13
|
|
|
|
|
|
|
|
14
|
15
|
|
|
15
|
|
104
|
use Scalar::Util (); |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
305
|
|
15
|
15
|
|
|
15
|
|
6530
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::PID; |
|
15
|
|
|
|
|
44
|
|
|
15
|
|
|
|
|
92
|
|
16
|
15
|
|
|
15
|
|
7531
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::RDMA; |
|
15
|
|
|
|
|
47
|
|
|
15
|
|
|
|
|
506
|
|
17
|
15
|
|
|
15
|
|
7727
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Memory; |
|
15
|
|
|
|
|
44
|
|
|
15
|
|
|
|
|
79
|
|
18
|
15
|
|
|
15
|
|
6999
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Devices; |
|
15
|
|
|
|
|
44
|
|
|
15
|
|
|
|
|
92
|
|
19
|
15
|
|
|
15
|
|
6775
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Cpuacct; |
|
15
|
|
|
|
|
44
|
|
|
15
|
|
|
|
|
104
|
|
20
|
15
|
|
|
15
|
|
6796
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Cpuset; |
|
15
|
|
|
|
|
33
|
|
|
15
|
|
|
|
|
89
|
|
21
|
15
|
|
|
15
|
|
6639
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Netcls; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
117
|
|
22
|
15
|
|
|
15
|
|
7381
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Netprio; |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
399
|
|
23
|
15
|
|
|
15
|
|
6668
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Freezer; |
|
15
|
|
|
|
|
44
|
|
|
15
|
|
|
|
|
90
|
|
24
|
15
|
|
|
15
|
|
582
|
use File::Spec::Functions 'splitdir'; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
20995
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has controller => ''; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _cgroup { |
30
|
987
|
100
|
50
|
987
|
|
125045
|
path( |
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
31
|
|
|
|
|
|
|
$_[0]->parent |
32
|
|
|
|
|
|
|
? path( |
33
|
|
|
|
|
|
|
$_[0]->_vfs, |
34
|
|
|
|
|
|
|
$_[0]->controller // '', |
35
|
|
|
|
|
|
|
$_[0]->name // '', |
36
|
|
|
|
|
|
|
$_[0]->parent |
37
|
|
|
|
|
|
|
) |
38
|
|
|
|
|
|
|
: path($_[0]->_vfs, $_[0]->controller // '', $_[0]->name // '')); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub child { |
42
|
66
|
50
|
|
66
|
0
|
2203
|
return $_[0]->new( |
43
|
|
|
|
|
|
|
name => $_[0]->name, |
44
|
|
|
|
|
|
|
controller => $_[0]->controller, |
45
|
|
|
|
|
|
|
parent => $_[0]->parent ? path($_[0]->parent, $_[1]) : $_[1])->create; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub from { |
49
|
1
|
|
|
1
|
0
|
25
|
my ($self, $string) = @_; |
50
|
1
|
|
|
|
|
6
|
my $g = $self->_vfs; |
51
|
1
|
|
|
|
|
23
|
$string =~ s/$g//; |
52
|
1
|
|
|
|
|
18
|
my @p = splitdir($string); |
53
|
1
|
|
|
|
|
11
|
my $pre = substr $string, 0, 1; |
54
|
1
|
50
|
|
|
|
6
|
shift @p if $pre eq '/'; |
55
|
1
|
|
|
|
|
2
|
my $controller = shift @p; |
56
|
1
|
|
|
|
|
2
|
my $name = shift @p; |
57
|
1
|
|
|
|
|
5
|
return $_[0] |
58
|
|
|
|
|
|
|
->new(name => $name, controller => $controller, parent => path(@p)); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has pid => sub { |
62
|
|
|
|
|
|
|
my $pid |
63
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v1::PID->new(cgroup => shift); |
64
|
|
|
|
|
|
|
Scalar::Util::weaken $pid->{cgroup}; |
65
|
|
|
|
|
|
|
return $pid; |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
has rdma => sub { |
69
|
|
|
|
|
|
|
my $rdma |
70
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v1::RDMA->new(cgroup => shift); |
71
|
|
|
|
|
|
|
Scalar::Util::weaken $rdma->{cgroup}; |
72
|
|
|
|
|
|
|
return $rdma; |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
has memory => sub { |
76
|
|
|
|
|
|
|
my $memory |
77
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Memory->new(cgroup => shift); |
78
|
|
|
|
|
|
|
Scalar::Util::weaken $memory->{cgroup}; |
79
|
|
|
|
|
|
|
return $memory; |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
has devices => sub { |
83
|
|
|
|
|
|
|
my $devices |
84
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Devices->new(cgroup => shift); |
85
|
|
|
|
|
|
|
Scalar::Util::weaken $devices->{cgroup}; |
86
|
|
|
|
|
|
|
return $devices; |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
has cpuacct => sub { |
90
|
|
|
|
|
|
|
my $cpuacct |
91
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Cpuacct->new(cgroup => shift); |
92
|
|
|
|
|
|
|
Scalar::Util::weaken $cpuacct->{cgroup}; |
93
|
|
|
|
|
|
|
return $cpuacct; |
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
has cpuset => sub { |
97
|
|
|
|
|
|
|
my $cpuset |
98
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Cpuset->new(cgroup => shift); |
99
|
|
|
|
|
|
|
Scalar::Util::weaken $cpuset->{cgroup}; |
100
|
|
|
|
|
|
|
return $cpuset; |
101
|
|
|
|
|
|
|
}; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
has netcls => sub { |
104
|
|
|
|
|
|
|
my $netcls |
105
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Netcls->new(cgroup => shift); |
106
|
|
|
|
|
|
|
Scalar::Util::weaken $netcls->{cgroup}; |
107
|
|
|
|
|
|
|
return $netcls; |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
has netprio => sub { |
111
|
|
|
|
|
|
|
my $netprio |
112
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Netprio->new(cgroup => shift); |
113
|
|
|
|
|
|
|
Scalar::Util::weaken $netprio->{cgroup}; |
114
|
|
|
|
|
|
|
return $netprio; |
115
|
|
|
|
|
|
|
}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
has freezer => sub { |
118
|
|
|
|
|
|
|
my $freezer |
119
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Freezer->new(cgroup => shift); |
120
|
|
|
|
|
|
|
Scalar::Util::weaken $freezer->{cgroup}; |
121
|
|
|
|
|
|
|
return $freezer; |
122
|
|
|
|
|
|
|
}; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# CGroups process interface |
125
|
40
|
|
|
40
|
0
|
1904
|
sub add_process { shift->_appendln(+PROCS_INTERFACE() => pop) } |
126
|
|
|
|
|
|
|
|
127
|
173
|
|
|
173
|
0
|
10467
|
sub process_list { shift->_list(PROCS_INTERFACE) } |
128
|
65
|
|
|
65
|
0
|
7203
|
sub processes { c(shift->_listarray(PROCS_INTERFACE)) } |
129
|
|
|
|
|
|
|
|
130
|
63
|
|
|
63
|
0
|
157106
|
sub contains_process { shift->_contains(+PROCS_INTERFACE() => pop) } |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# CGroups thread interface |
133
|
2
|
|
|
2
|
0
|
9
|
sub add_thread { shift->_appendln(+TASKS_INTERFACE() => pop) } |
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
1
|
0
|
6
|
sub thread_list { shift->_list(TASKS_INTERFACE) } |
136
|
|
|
|
|
|
|
|
137
|
4
|
|
|
4
|
0
|
726
|
sub contains_thread { shift->_contains(+TASKS_INTERFACE() => pop) } |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
*CPU = \&cpu; |
141
|
|
|
|
|
|
|
*MEMORY = \&memory; |
142
|
|
|
|
|
|
|
*PID = \&pid; |
143
|
|
|
|
|
|
|
*RDMA = \&rdma; |
144
|
|
|
|
|
|
|
*DEVICES = \&devices; |
145
|
|
|
|
|
|
|
*FREEZER = \&freezer; |
146
|
|
|
|
|
|
|
*NETPRIO = \&netprio; |
147
|
|
|
|
|
|
|
*NETCLS = \&netcls; |
148
|
|
|
|
|
|
|
*CPUSET = \&cpuset; |
149
|
|
|
|
|
|
|
*CPUACCT = \&cpuacct; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=encoding utf-8 |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 NAME |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Mojo::IOLoop::ReadWriteProcess::CGroup::v1 - CGroups v1 implementation. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 SYNOPSIS |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
my $cgroup = Mojo::IOLoop::ReadWriteProcess::CGroup::v1->new( name => "test" ); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$cgroup->create; |
166
|
|
|
|
|
|
|
$cgroup->exists; |
167
|
|
|
|
|
|
|
my $child = $cgroup->child('bar'); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 DESCRIPTION |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This module uses features that are only available on Linux, |
172
|
|
|
|
|
|
|
and requires cgroups and capability for unshare syscalls to achieve pid isolation. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 METHODS |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L inherits all methods from L and implements |
177
|
|
|
|
|
|
|
the following new ones. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 LICENSE |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Copyright (C) Ettore Di Giacinto. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
184
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 AUTHOR |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Ettore Di Giacinto Eedigiacinto@suse.comE |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |