Class: OsCtld::Devices::V1::GroupConfigurator
Instance Attribute Summary
Attributes inherited from Configurator
#owner
Instance Method Summary
collapse
#dup, #initialize
Instance Method Details
#add_device(device) ⇒ Object
18
19
20
|
# File 'lib/osctld/devices/v1/group_configurator.rb', line 18
def add_device(device)
do_allow_device(device, owner.abs_cgroup_path('devices'))
end
|
#apply_changes(changes) ⇒ Object
26
27
28
|
# File 'lib/osctld/devices/v1/group_configurator.rb', line 26
def apply_changes(changes)
do_apply_changes(changes, owner.abs_cgroup_path('devices'))
end
|
#clear ⇒ Object
32
33
34
35
36
37
|
# File 'lib/osctld/devices/v1/group_configurator.rb', line 32
def clear
return if @cleared
do_deny_all(owner.abs_cgroup_path('devices'))
@cleared = true
end
|
#do_allow_device(device, path) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/osctld/devices/v1/group_configurator.rb', line 46
def do_allow_device(device, path)
CGroup.set_param(
File.join(path, 'devices.allow'),
[device.to_s]
)
end
|
#do_apply_changes(changes, path) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/osctld/devices/v1/group_configurator.rb', line 64
def do_apply_changes(changes, path)
changes.each do |action, value|
case action
when :allow
CGroup.set_param(
File.join(path, 'devices.allow'),
[value]
)
when :deny
CGroup.set_param(
File.join(path, 'devices.deny'),
[value]
)
end
end
end
|
60
61
62
|
# File 'lib/osctld/devices/v1/group_configurator.rb', line 60
def do_configure(devices, path)
devices.each { |dev| do_allow_device(dev, path) }
end
|
#do_deny_all(path) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/osctld/devices/v1/group_configurator.rb', line 39
def do_deny_all(path)
CGroup.set_param(
File.join(path, 'devices.deny'),
['a']
)
end
|
#do_deny_device(device, path) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/osctld/devices/v1/group_configurator.rb', line 53
def do_deny_device(device, path)
CGroup.set_param(
File.join(path, 'devices.deny'),
[device.to_s]
)
end
|
#init(devices) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/osctld/devices/v1/group_configurator.rb', line 5
def init(devices)
log(:info, owner, "Configuring cgroup #{owner.cgroup_path} for devices")
return unless CGroup.mkpath('devices', owner.cgroup_path.split('/'))
reconfigure(devices)
end
|
13
14
15
16
|
# File 'lib/osctld/devices/v1/group_configurator.rb', line 13
def reconfigure(devices)
clear
do_configure(devices, owner.abs_cgroup_path('devices'))
end
|
#remove_device(device) ⇒ Object
22
23
24
|
# File 'lib/osctld/devices/v1/group_configurator.rb', line 22
def remove_device(device)
do_deny_device(device, owner.abs_cgroup_path('devices'))
end
|