line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::IOLoop::ReadWriteProcess::CGroup::v2; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Refer to https://www.kernel.org/doc/Documentation/cgroup-v2.txt for details |
4
|
|
|
|
|
|
|
|
5
|
15
|
|
|
15
|
|
103
|
use Mojo::Base 'Mojo::IOLoop::ReadWriteProcess::CGroup'; |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
111
|
|
6
|
15
|
|
|
15
|
|
2310
|
use Mojo::File 'path'; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
650
|
|
7
|
15
|
|
|
15
|
|
100
|
use Mojo::Collection 'c'; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
1175
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(cgroup); |
10
|
15
|
|
|
15
|
|
112
|
use Exporter 'import'; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
1152
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use constant { |
13
|
15
|
|
|
|
|
1870
|
PROCS_INTERFACE => 'cgroup.procs', |
14
|
|
|
|
|
|
|
TYPE_INTERFACE => 'cgroup.type', |
15
|
|
|
|
|
|
|
THREADS_INTERFACE => 'cgroup.threads', |
16
|
|
|
|
|
|
|
EVENTS_INTERFACE => 'cgroup.events', |
17
|
|
|
|
|
|
|
CONTROLLERS_INTERFACE => 'cgroup.controllers', |
18
|
|
|
|
|
|
|
SUBTREE_CONTROL_INTERFACE => 'cgroup.subtree_control', |
19
|
|
|
|
|
|
|
MAX_DESCENDANT_INTERFACE => 'cgroup.max.descendants', |
20
|
|
|
|
|
|
|
MAX_DEPTH_INTERFACE => 'cgroup.max.depth', |
21
|
|
|
|
|
|
|
STAT_INTERFACE => 'cgroup.stat', |
22
|
15
|
|
|
15
|
|
103
|
}; |
|
15
|
|
|
|
|
29
|
|
23
|
|
|
|
|
|
|
|
24
|
15
|
|
|
15
|
|
617
|
use Scalar::Util (); |
|
15
|
|
|
|
|
58
|
|
|
15
|
|
|
|
|
340
|
|
25
|
15
|
|
|
15
|
|
6498
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::IO; |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
78
|
|
26
|
15
|
|
|
15
|
|
6762
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::CPU; |
|
15
|
|
|
|
|
33
|
|
|
15
|
|
|
|
|
90
|
|
27
|
15
|
|
|
15
|
|
6434
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::Memory; |
|
15
|
|
|
|
|
65
|
|
|
15
|
|
|
|
|
79
|
|
28
|
15
|
|
|
15
|
|
6583
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::PID; |
|
15
|
|
|
|
|
67
|
|
|
15
|
|
|
|
|
88
|
|
29
|
15
|
|
|
15
|
|
732
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::RDMA; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
147
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has io => sub { |
32
|
|
|
|
|
|
|
my $io = Mojo::IOLoop::ReadWriteProcess::CGroup::v2::IO->new(cgroup => shift); |
33
|
|
|
|
|
|
|
Scalar::Util::weaken $io->{cgroup}; |
34
|
|
|
|
|
|
|
return $io; |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has cpu => sub { |
38
|
|
|
|
|
|
|
my $cpu |
39
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v2::CPU->new(cgroup => shift); |
40
|
|
|
|
|
|
|
Scalar::Util::weaken $cpu->{cgroup}; |
41
|
|
|
|
|
|
|
return $cpu; |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has memory => sub { |
45
|
|
|
|
|
|
|
my $memory |
46
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v2::Memory->new(cgroup => shift); |
47
|
|
|
|
|
|
|
Scalar::Util::weaken $memory->{cgroup}; |
48
|
|
|
|
|
|
|
return $memory; |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has pid => sub { |
52
|
|
|
|
|
|
|
my $pid |
53
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v2::PID->new(cgroup => shift); |
54
|
|
|
|
|
|
|
Scalar::Util::weaken $pid->{cgroup}; |
55
|
|
|
|
|
|
|
return $pid; |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
has rdma => sub { |
59
|
|
|
|
|
|
|
my $rdma |
60
|
|
|
|
|
|
|
= Mojo::IOLoop::ReadWriteProcess::CGroup::v2::RDMA->new(cgroup => shift); |
61
|
|
|
|
|
|
|
Scalar::Util::weaken $rdma->{cgroup}; |
62
|
|
|
|
|
|
|
return $rdma; |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# CGroups process interface |
66
|
4
|
|
|
4
|
0
|
31
|
sub add_process { shift->_appendln(+PROCS_INTERFACE() => pop) } |
67
|
|
|
|
|
|
|
|
68
|
2
|
|
|
2
|
0
|
20
|
sub process_list { shift->_list(PROCS_INTERFACE) } |
69
|
2
|
|
|
2
|
0
|
1696
|
sub processes { c(shift->_listarray(PROCS_INTERFACE)) } |
70
|
|
|
|
|
|
|
|
71
|
8
|
|
|
8
|
0
|
1832
|
sub contains_process { shift->_contains(+PROCS_INTERFACE() => pop) } |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# CGroups thread interface |
74
|
2
|
|
|
2
|
0
|
19
|
sub add_thread { shift->_appendln(+THREADS_INTERFACE() => pop) } |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
1
|
0
|
11
|
sub thread_list { shift->_list(THREADS_INTERFACE) } |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
4
|
0
|
805
|
sub contains_thread { shift->_contains(+THREADS_INTERFACE() => pop) } |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# CGroups event interface |
81
|
1
|
|
|
1
|
0
|
7
|
sub populated { shift->_list(EVENTS_INTERFACE) } |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# CGroups type interface |
84
|
2
|
|
|
2
|
0
|
15
|
sub type { shift->_setget(+TYPE_INTERFACE() => pop) } |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# CGroups controllers Interface |
87
|
2
|
|
|
2
|
0
|
975
|
sub controllers { shift->_setget(+CONTROLLERS_INTERFACE() => pop) } |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# CGroups subtree_control Interface |
90
|
2
|
|
|
2
|
0
|
8
|
sub subtree_control { shift->_setget(+SUBTREE_CONTROL_INTERFACE() => pop) } |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# CGroups max.descendants Interface |
93
|
2
|
|
|
2
|
0
|
1064
|
sub max_descendants { shift->_setget(+MAX_DESCENDANT_INTERFACE() => pop) } |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# CGroups max.depth Interface |
96
|
2
|
|
|
2
|
0
|
1081
|
sub max_depths { shift->_setget(+MAX_DEPTH_INTERFACE() => pop) } |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# CGroups stat Interface |
99
|
1
|
|
|
1
|
0
|
196
|
sub stat { shift->_list(+STAT_INTERFACE()) } |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
*IO = \&io; |
102
|
|
|
|
|
|
|
*CPU = \&cpu; |
103
|
|
|
|
|
|
|
*MEMORY = \&memory; |
104
|
|
|
|
|
|
|
*PID = \&pid; |
105
|
|
|
|
|
|
|
*RDMA = \&rdma; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=encoding utf-8 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 NAME |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Mojo::IOLoop::ReadWriteProcess::CGroup::v2 - CGroups v2 implementation. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 SYNOPSIS |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $cgroup = Mojo::IOLoop::ReadWriteProcess::CGroup::v2->new( name => "test" ); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
$cgroup->create; |
122
|
|
|
|
|
|
|
$cgroup->exists; |
123
|
|
|
|
|
|
|
my $child = $cgroup->child('bar'); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 DESCRIPTION |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This module uses features that are only available on Linux, |
128
|
|
|
|
|
|
|
and requires cgroups and capability for unshare syscalls to achieve pid isolation. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 METHODS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L inherits all methods from L and implements |
133
|
|
|
|
|
|
|
the following new ones. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 LICENSE |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Copyright (C) Ettore Di Giacinto. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
140
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Ettore Di Giacinto Eedigiacinto@suse.comE |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |