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
|
|
108
|
use Mojo::Base 'Mojo::IOLoop::ReadWriteProcess::CGroup'; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
90
|
|
6
|
15
|
|
|
15
|
|
2409
|
use Mojo::File 'path'; |
|
15
|
|
|
|
|
19
|
|
|
15
|
|
|
|
|
671
|
|
7
|
15
|
|
|
15
|
|
95
|
use Mojo::Collection 'c'; |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
660
|
|
8
|
15
|
|
|
15
|
|
92
|
use Carp 'confess'; |
|
15
|
|
|
|
|
38
|
|
|
15
|
|
|
|
|
1133
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(cgroup); |
10
|
15
|
|
|
15
|
|
104
|
use Exporter 'import'; |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
655
|
|
11
|
|
|
|
|
|
|
|
12
|
15
|
|
|
15
|
|
131
|
use constant {PROCS_INTERFACE => 'cgroup.procs', TASKS_INTERFACE => 'tasks'}; |
|
15
|
|
|
|
|
21
|
|
|
15
|
|
|
|
|
1298
|
|
13
|
|
|
|
|
|
|
|
14
|
15
|
|
|
15
|
|
107
|
use Scalar::Util (); |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
390
|
|
15
|
15
|
|
|
15
|
|
6150
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::PID; |
|
15
|
|
|
|
|
45
|
|
|
15
|
|
|
|
|
80
|
|
16
|
15
|
|
|
15
|
|
6302
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::RDMA; |
|
15
|
|
|
|
|
45
|
|
|
15
|
|
|
|
|
145
|
|
17
|
15
|
|
|
15
|
|
6550
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Memory; |
|
15
|
|
|
|
|
44
|
|
|
15
|
|
|
|
|
90
|
|
18
|
15
|
|
|
15
|
|
6458
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Devices; |
|
15
|
|
|
|
|
34
|
|
|
15
|
|
|
|
|
113
|
|
19
|
15
|
|
|
15
|
|
6478
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Cpuacct; |
|
15
|
|
|
|
|
35
|
|
|
15
|
|
|
|
|
115
|
|
20
|
15
|
|
|
15
|
|
6602
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Cpuset; |
|
15
|
|
|
|
|
45
|
|
|
15
|
|
|
|
|
78
|
|
21
|
15
|
|
|
15
|
|
6361
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Netcls; |
|
15
|
|
|
|
|
46
|
|
|
15
|
|
|
|
|
107
|
|
22
|
15
|
|
|
15
|
|
6447
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Netprio; |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
105
|
|
23
|
15
|
|
|
15
|
|
6520
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Freezer; |
|
15
|
|
|
|
|
45
|
|
|
15
|
|
|
|
|
89
|
|
24
|
15
|
|
|
15
|
|
542
|
use File::Spec::Functions 'splitdir'; |
|
15
|
|
|
|
|
40
|
|
|
15
|
|
|
|
|
20570
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has controller => ''; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _cgroup { |
30
|
987
|
100
|
50
|
987
|
|
110468
|
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
|
1652
|
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
|
23
|
my ($self, $string) = @_; |
50
|
1
|
|
|
|
|
4
|
my $g = $self->_vfs; |
51
|
1
|
|
|
|
|
20
|
$string =~ s/$g//; |
52
|
1
|
|
|
|
|
17
|
my @p = splitdir($string); |
53
|
1
|
|
|
|
|
11
|
my $pre = substr $string, 0, 1; |
54
|
1
|
50
|
|
|
|
4
|
shift @p if $pre eq '/'; |
55
|
1
|
|
|
|
|
3
|
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
|
1478
|
sub add_process { shift->_appendln(+PROCS_INTERFACE() => pop) } |
126
|
|
|
|
|
|
|
|
127
|
173
|
|
|
173
|
0
|
50034704
|
sub process_list { shift->_list(PROCS_INTERFACE) } |
128
|
65
|
|
|
65
|
0
|
6085
|
sub processes { c(shift->_listarray(PROCS_INTERFACE)) } |
129
|
|
|
|
|
|
|
|
130
|
63
|
|
|
63
|
0
|
130183
|
sub contains_process { shift->_contains(+PROCS_INTERFACE() => pop) } |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# CGroups thread interface |
133
|
2
|
|
|
2
|
0
|
8
|
sub add_thread { shift->_appendln(+TASKS_INTERFACE() => pop) } |
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
1
|
0
|
5
|
sub thread_list { shift->_list(TASKS_INTERFACE) } |
136
|
|
|
|
|
|
|
|
137
|
4
|
|
|
4
|
0
|
722
|
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 |