Class: OsCtld::Devices::V1::GroupConfigurator

Inherits:
Configurator
  • Object
show all
Defined in:
lib/osctld/devices/v1/group_configurator.rb

Direct Known Subclasses

ContainerConfigurator

Instance Attribute Summary

Attributes inherited from Configurator

#owner

Instance Method Summary collapse

Methods inherited from Configurator

#dup, #initialize

Constructor Details

This class inherits a constructor from OsCtld::Devices::Configurator

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

#clearObject (protected)



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 (protected)



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 (protected)



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

#do_configure(devices, path) ⇒ Object (protected)



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 (protected)



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 (protected)



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

#reconfigure(devices) ⇒ Object



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