« lib/Mojo/IOLoop/ReadWriteProcess/Pool.pm
↑ Summary
lib/Mojo/IOLoop/ReadWriteProcess/CGroup/v1/RDMA.pm »
| 1 | package Mojo::IOLoop::ReadWriteProcess::CGroup; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use Mojo::File 'path'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | 15 | ▶ | use Mojo::IOLoop::ReadWriteProcess::CGroup::v1; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use Mojo::IOLoop::ReadWriteProcess::CGroup::v2; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use File::Spec::Functions 'splitdir'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 15 | our @EXPORT_OK = qw(cgroupv2 cgroupv1); | |||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | 15 | ▶ | use constant CGROUP_FS => $ENV{MOJO_CGROUP_FS} // '/sys/fs/cgroup'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
Condition100%2/2
$ENV{"MOJO_CGROUP_FS"} // "/sys/fs/cgroup"
MC/DC100%1/1
$ENV{"MOJO_CGROUP_FS"} // "/sys/fs/cgroup"
$ENV{"MOJO_CGROUP_FS"}
Truth table100%2/2
A
A= $ENV{"MOJO_CGROUP_FS"}
| |||||||||||||||||||||||||||||||
| 14 | 15 | ▶ | use constant DEBUG => $ENV{MOJO_PROCESS_DEBUG}; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | 176 | ▶ | has '_vfs' => sub { CGROUP_FS() }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | 15 | has [qw(name parent)]; | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | sub cgroupv2 { Mojo::IOLoop::ReadWriteProcess::CGroup::v2->new(@_)->create } | ||||||||||||||||||||||||||||
|
Subroutine
cgroupv2: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 21 | 40 | ▶ | sub cgroupv1 { Mojo::IOLoop::ReadWriteProcess::CGroup::v1->new(@_)->create } | ||||||||||||||||||||||||||||
|
Subroutine
cgroupv1: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | 4 | ▶ | sub from { | ||||||||||||||||||||||||||||
|
Subroutine
from: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 24 | 4 | my ($self, $string) = @_; | |||||||||||||||||||||||||||||
| 25 | 4 | my $g = $self->_vfs; | |||||||||||||||||||||||||||||
| 26 | 4 | $string =~ s/$g//; | |||||||||||||||||||||||||||||
| 27 | 4 | my @p = splitdir($string); | |||||||||||||||||||||||||||||
| 28 | 4 | my $pre = substr $string, 0, 1; | |||||||||||||||||||||||||||||
| 29 | 4 | ▶ | shift @p if $pre eq '/'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 30 | 4 | my $name = shift @p; | |||||||||||||||||||||||||||||
| 31 | 4 | return $_[0]->new(name => $name, parent => path(@p)); | |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | 107 | ▶ | sub _cgroup { | ||||||||||||||||||||||||||||
|
Subroutine
_cgroup: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||
| 35 | 107 | ▶ | path($_[0]->parent | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
$_[0]->name // ""
$_[0]->name // ""
MC/DC0%0/1
$_[0]->name // ""
$_[0]->name
MC/DC100%1/1
$_[0]->name // ""
$_[0]->name
Truth table50%1/2
A
A= $_[0]->name
Truth table100%2/2
A
A= $_[0]->name
| |||||||||||||||||||||||||||||||
| 36 | ? path($_[0]->_vfs, $_[0]->name // '', $_[0]->parent) | ||||||||||||||||||||||||||||||
| 37 | : path($_[0]->_vfs, $_[0]->name // '')); | ||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||
| 40 | 241 | ▶ | sub create { $_[0]->_cgroup->make_path unless -d $_[0]->_cgroup; $_[0] } | ||||||||||||||||||||||||||||
|
Subroutine
create: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | # TODO: Make sure there aren't pid belonging to cgroup before removing | ||||||||||||||||||||||||||||||
| 43 | # This is done in Container class, but we might want to warn in case this is hit | ||||||||||||||||||||||||||||||
| 44 | 87 | ▶ | sub remove { rmdir $_[0]->_cgroup->to_string } #->remove_tree() } | ||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | sub child { | ||||||||||||||||||||||||||||
|
Subroutine
child: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | return $_[0]->new( | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 48 | name => $_[0]->name, | ||||||||||||||||||||||||||||||
| 49 | parent => $_[0]->parent ? path($_[0]->parent, $_[1]) : $_[1])->create; | ||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | 81 | ▶ | sub exists { -d $_[0]->_cgroup } | ||||||||||||||||||||||||||||
|
Subroutine
exists: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 48 | ▶ | sub _append { my $h = $_[0]->_cgroup->child($_[1])->open('>>'); print $h pop() } | ||||||||||||||||||||||||||||
|
Subroutine
_append: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 55 | 4 | ▶ | sub _write { my $h = $_[0]->_cgroup->child($_[1])->open('>'); print $h pop() } | ||||||||||||||||||||||||||||
|
Subroutine
_write: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||
| 57 | 18 | ▶ | sub _flag { | ||||||||||||||||||||||||||||
|
Subroutine
_flag: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 58 | 18 | my $f = pop; | |||||||||||||||||||||||||||||
| 59 | 18 | my $h = $_[0]->_cgroup->child($_[1])->open('>'); | |||||||||||||||||||||||||||||
| 60 | 18 | ▶ | print $h ($f == 0 ? 0 : 1); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | 48 | ▶ | sub _appendln { shift->_append(shift() => pop() . "\n") } | ||||||||||||||||||||||||||||
|
Subroutine
_appendln: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 64 | 352 | ▶ | sub _list { my $c = shift->_cgroup->child(pop); $c->slurp if -e $c } | ||||||||||||||||||||||||||||
|
Subroutine
_list: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 65 | 146 | ▶ | sub _listarray { split(/\n/, shift->_list(@_)) } | ||||||||||||||||||||||||||||
|
Subroutine
_listarray: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | 79 | ▶ | sub _contains { | ||||||||||||||||||||||||||||
|
Subroutine
_contains: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 68 | 79 | my $p = pop; | |||||||||||||||||||||||||||||
| 69 | 79 | my $i = pop; | |||||||||||||||||||||||||||||
| 70 | 79 | grep { $p eq $_ } shift->_listarray($i); | |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | 64 | ▶ | sub _setget { | ||||||||||||||||||||||||||||
|
Subroutine
_setget: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 74 | 64 | ▶ | $_[2] | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 75 | ? shift->_cgroup->child($_[0])->spew($_[1]) | ||||||||||||||||||||||||||||||
| 76 | : shift->_cgroup->child($_[0])->slurp; | ||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | 15 | 1; | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||
| 81 | =encoding utf-8 | ||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | =head1 NAME | ||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||
| 85 | Mojo::IOLoop::ReadWriteProcess::CGroup - Base object for CGroups implementations. | ||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||
| 89 | use Mojo::IOLoop::ReadWriteProcess::CGroup; | ||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | my $cgroup = Mojo::IOLoop::ReadWriteProcess::CGroup->new( name => "test" ); | ||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | $cgroup->create; | ||||||||||||||||||||||||||||||
| 94 | $cgroup->exists; | ||||||||||||||||||||||||||||||
| 95 | my $child = $cgroup->child('bar'); | ||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||
| 97 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||
| 99 | This module uses features that are only available on Linux, | ||||||||||||||||||||||||||||||
| 100 | and requires cgroups and capability for unshare syscalls to achieve pid isolation. | ||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | =head1 METHODS | ||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | L<Mojo::IOLoop::ReadWriteProcess::CGroup> inherits all methods from L<Mojo::Base> and implements | ||||||||||||||||||||||||||||||
| 105 | the following new ones. | ||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||
| 107 | =head1 LICENSE | ||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||
| 109 | Copyright (C) Ettore Di Giacinto. | ||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||
| 112 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||
| 114 | =head1 AUTHOR | ||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||
| 116 | Ettore Di Giacinto E<lt>edigiacinto@suse.comE<gt> | ||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||||