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
|
|
106
|
use Mojo::Base 'Mojo::IOLoop::ReadWriteProcess::CGroup'; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
92
|
|
6
|
15
|
|
|
15
|
|
2447
|
use Mojo::File 'path'; |
|
15
|
|
|
|
|
51
|
|
|
15
|
|
|
|
|
711
|
|
7
|
15
|
|
|
15
|
|
80
|
use Mojo::Collection 'c'; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
1277
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(cgroup); |
10
|
15
|
|
|
15
|
|
107
|
use Exporter 'import'; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
953
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use constant { |
13
|
15
|
|
|
|
|
1856
|
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
|
|
104
|
}; |
|
15
|
|
|
|
|
20
|
|
23
|
|
|
|
|
|
|
|
24
|
15
|
|
|
15
|
|
607
|
use Scalar::Util (); |
|
15
|
|
|
|
|
71
|
|
|
15
|
|
|
|
|
367
|
|
25
|
15
|
|
|
15
|
|
6771
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::IO; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
90
|
|
26
|
15
|
|
|
15
|
|
6730
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::CPU; |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
90
|
|
27
|
15
|
|
|
15
|
|
6692
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::Memory; |
|
15
|
|
|
|
|
56
|
|
|
15
|
|
|
|
|
91
|
|
28
|
15
|
|
|
15
|
|
6693
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::PID; |
|
15
|
|
|
|
|
42
|
|
|
15
|
|
|
|
|
91
|
|
29
|
15
|
|
|
15
|
|
566
|
use Mojo::IOLoop::ReadWriteProcess::CGroup::v2::RDMA; |
|
15
|
|
|
|
|
42
|
|
|
15
|
|
|
|
|
113
|
|
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
|
29
|
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
|
1750
|
sub processes { c(shift->_listarray(PROCS_INTERFACE)) } |
70
|
|
|
|
|
|
|
|
71
|
8
|
|
|
8
|
0
|
1852
|
sub contains_process { shift->_contains(+PROCS_INTERFACE() => pop) } |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# CGroups thread interface |
74
|
2
|
|
|
2
|
0
|
20
|
sub add_thread { shift->_appendln(+THREADS_INTERFACE() => pop) } |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
1
|
0
|
10
|
sub thread_list { shift->_list(THREADS_INTERFACE) } |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
4
|
0
|
876
|
sub contains_thread { shift->_contains(+THREADS_INTERFACE() => pop) } |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# CGroups event interface |
81
|
1
|
|
|
1
|
0
|
5
|
sub populated { shift->_list(EVENTS_INTERFACE) } |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# CGroups type interface |
84
|
2
|
|
|
2
|
0
|
16
|
sub type { shift->_setget(+TYPE_INTERFACE() => pop) } |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# CGroups controllers Interface |
87
|
2
|
|
|
2
|
0
|
976
|
sub controllers { shift->_setget(+CONTROLLERS_INTERFACE() => pop) } |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# CGroups subtree_control Interface |
90
|
2
|
|
|
2
|
0
|
11
|
sub subtree_control { shift->_setget(+SUBTREE_CONTROL_INTERFACE() => pop) } |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# CGroups max.descendants Interface |
93
|
2
|
|
|
2
|
0
|
1080
|
sub max_descendants { shift->_setget(+MAX_DESCENDANT_INTERFACE() => pop) } |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# CGroups max.depth Interface |
96
|
2
|
|
|
2
|
0
|
1110
|
sub max_depths { shift->_setget(+MAX_DEPTH_INTERFACE() => pop) } |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# CGroups stat Interface |
99
|
1
|
|
|
1
|
0
|
201
|
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 |