Skip to content

Commit

Permalink
B #3175 Load nbds_max from fs
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 committed Apr 9, 2019
1 parent 11ae494 commit 2740191
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/vmm_mad/remotes/lib/lxd/mapper/qcow2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# Block device mapping for qcow2 disks, backed by nbd kernel module
class Qcow2Mapper < Mapper

NBDS_MAX = 256 # Default nbd module param config provided by opennebula

def do_map(one_vm, disk, _directory)
device = nbd_device

Expand Down Expand Up @@ -69,16 +67,10 @@ def do_unmap(device, _one_vm, _disk, _directory)

# Detects Max number of block devices
def nbds_max
cmd = '/sbin/modprobe -c'
rc, mods_conf, e = Command.execute(cmd, false)

if !rc.zero?
OpenNebula.log_error("Cannot load max number of nbd devices\n#{e}"\
"Falling back to default #{NBDS_MAX}")
return NBDS_MAX
end

mods_conf.match(/(nbds_max=)(\d+)/)[-1].to_i
File.read('/sys/module/nbd/parameters/nbds_max').chomp.to_i
rescue => e
OpenNebula.log_error("Cannot load kernel module parameter\n#{e}")
0
end

# Returns the first non-used nbd device
Expand All @@ -93,7 +85,7 @@ def nbd_device
nbds << m[1].to_i
end

nbds_max.times do |i|
nbds_max.times do |i| # if nbds_max returns 0 block is skipped
return "/dev/nbd#{i}" unless nbds.include?(i)
end

Expand Down

0 comments on commit 2740191

Please sign in to comment.