Class: OsCtld::BpfFs
- Inherits:
-
Object
- Object
- OsCtld::BpfFs
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/osctld/bpf_fs.rb
Constant Summary collapse
- FS =
'/sys/fs/bpf'.freeze
- ROOT_DIR =
File.join(FS, 'osctl')
- PROG_DIR =
File.join(ROOT_DIR, 'progs')
- POOL_DIR =
File.join(ROOT_DIR, 'pools')
Instance Method Summary collapse
- #add_pool(pool_name) ⇒ Object
- #link_pin_path(pool_name, link_name) ⇒ Object
- #link_pinned?(pool_name, link_name) ⇒ Boolean
- #list_links(pool_name) ⇒ Object
- #list_progs ⇒ Object
- #pool_dir(pool_name) ⇒ Object protected
- #prog_pin_path(prog_name) ⇒ Object
- #prog_pinned?(prog_name) ⇒ Boolean
- #remove_pool(pool_name) ⇒ Object
- #setup ⇒ Object
Instance Method Details
#add_pool(pool_name) ⇒ Object
28 29 30 |
# File 'lib/osctld/bpf_fs.rb', line 28 def add_pool(pool_name) FileUtils.mkdir_p(File.join(pool_dir(pool_name), 'links')) end |
#link_pin_path(pool_name, link_name) ⇒ Object
54 55 56 |
# File 'lib/osctld/bpf_fs.rb', line 54 def link_pin_path(pool_name, link_name) File.join(pool_dir(pool_name), 'links', link_name) end |
#link_pinned?(pool_name, link_name) ⇒ Boolean
58 59 60 |
# File 'lib/osctld/bpf_fs.rb', line 58 def link_pinned?(pool_name, link_name) File.exist?(link_pin_path(pool_name, link_name)) end |
#list_links(pool_name) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/osctld/bpf_fs.rb', line 62 def list_links(pool_name) dir = File.join(pool_dir(pool_name), 'links') Dir.entries(dir).select do |f| !%w[. ..].include?(f) && File.file?(File.join(dir, f)) end rescue Errno::ENOENT [] end |
#list_progs ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/osctld/bpf_fs.rb', line 44 def list_progs dir = PROG_DIR Dir.entries(dir).select do |f| !%w[. ..].include?(f) && File.file?(File.join(dir, f)) end rescue Errno::ENOENT [] end |
#pool_dir(pool_name) ⇒ Object (protected)
74 75 76 |
# File 'lib/osctld/bpf_fs.rb', line 74 def pool_dir(pool_name) File.join(POOL_DIR, pool_name) end |
#prog_pin_path(prog_name) ⇒ Object
36 37 38 |
# File 'lib/osctld/bpf_fs.rb', line 36 def prog_pin_path(prog_name) File.join(PROG_DIR, prog_name) end |
#prog_pinned?(prog_name) ⇒ Boolean
40 41 42 |
# File 'lib/osctld/bpf_fs.rb', line 40 def prog_pinned?(prog_name) File.exist?(prog_pin_path(prog_name)) end |
#remove_pool(pool_name) ⇒ Object
32 33 34 |
# File 'lib/osctld/bpf_fs.rb', line 32 def remove_pool(pool_name) FileUtils.rm_rf(pool_dir(pool_name), secure: true) end |
#setup ⇒ Object
24 25 26 |
# File 'lib/osctld/bpf_fs.rb', line 24 def setup FileUtils.mkdir_p(PROG_DIR) end |