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
|
|
|
|
|
42
|
|
|
15
|
|
|
|
|
86
|
|
6
|
15
|
|
|
15
|
|
2561
|
use Mojo::File 'path'; |
|
15
|
|
|
|
|
37
|
|
|
15
|
|
|
|
|
656
|
|
7
|
15
|
|
|
15
|
|
199
|
use Mojo::Collection 'c'; |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
766
|
|
8
|
15
|
|
|
15
|
|
103
|
use Carp 'confess'; |
|
15
|
|
|
|
|
29
|
|
|
15
|
|
|
|
|
1162
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(cgroup); |
10
|
15
|
|
|
15
|
|
105
|
use Exporter 'import'; |
|
15
|
|
|
|
|
20
|
|
|
15
|
|
|
|
|
623
|
|
11
|
|
|
|
|
|
|
|
12
|
15
|
|
|
15
|
|
88
|
use constant {PROCS_INTERFACE => 'cgroup.procs', TASKS_INTERFACE => 'tasks'}; |
|
15
|
|
|
|
|
29
|
|
|
15
|
|
|
|
|
1222
|
|
13
|
|
|
|
|
|
|
|
14
|
15
|
|
|
15
|
|
103
|
use Scalar::Util (); |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
317
|
|
15
|
15
|
|
|
15
|
|
6085
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::PID; |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
103
|
|
16
|
15
|
|
|
15
|
|
6357
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::RDMA; |
|
15
|
|
|
|
|
44
|
|
|
15
|
|
|
|
|
127
|
|
17
|
15
|
|
|
15
|
|
6593
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Memory; |
|
15
|
|
|
|
|
47
|
|
|
15
|
|
|
|
|
78
|
|
18
|
15
|
|
|
15
|
|
6392
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Devices; |
|
15
|
|
|
|
|
42
|
|
|
15
|
|
|
|
|
80
|
|
19
|
15
|
|
|
15
|
|
7091
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Cpuacct; |
|
15
|
|
|
|
|
47
|
|
|
15
|
|
|
|
|
103
|
|
20
|
15
|
|
|
15
|
|
6434
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Cpuset; |
|
15
|
|
|
|
|
38
|
|
|
15
|
|
|
|
|
91
|
|
21
|
15
|
|
|
15
|
|
6249
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Netcls; |
|
15
|
|
|
|
|
42
|
|
|
15
|
|
|
|
|
130
|
|
22
|
15
|
|
|
15
|
|
6434
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Netprio; |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
90
|
|
23
|
15
|
|
|
15
|
|
6739
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Freezer; |
|
15
|
|
|
|
|
36
|
|
|
15
|
|
|
|
|
103
|
|
24
|
15
|
|
|
15
|
|
553
|
use File::Spec::Functions 'splitdir'; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
20767
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has controller => ''; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _cgroup { |
30
|
987
|
100
|
50
|
987
|
|
118492
|
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
|
2143
|
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
|
29
|
my ($self, $string) = @_; |
50
|
1
|
|
|
|
|
5
|
my $g = $self->_vfs; |
51
|
1
|
|
|
|
|
22
|
$string =~ s/$g//; |
52
|
1
|
|
|
|
|
21
|
my @p = splitdir($string); |
53
|
1
|
|
|
|
|
15
|
my $pre = substr $string, 0, 1; |
54
|
1
|
50
|
|
|
|
5
|
shift @p if $pre eq '/'; |
55
|
1
|
|
|
|
|
3
|
my $controller = shift @p; |
56
|
1
|
|
|
|
|
3
|
my $name = shift @p; |
57
|
1
|
|
|
|
|
4
|
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
|
1726
|
sub add_process { shift->_appendln(+PROCS_INTERFACE() => pop) } |
126
|
|
|
|
|
|
|
|
127
|
173
|
|
|
173
|
0
|
9983
|
sub process_list { shift->_list(PROCS_INTERFACE) } |
128
|
65
|
|
|
65
|
0
|
6416
|
sub processes { c(shift->_listarray(PROCS_INTERFACE)) } |
129
|
|
|
|
|
|
|
|
130
|
63
|
|
|
63
|
0
|
135802
|
sub contains_process { shift->_contains(+PROCS_INTERFACE() => pop) } |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# CGroups thread interface |
133
|
2
|
|
|
2
|
0
|
7
|
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
|
814
|
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 |