Skip to content

Commit

Permalink
B OpenNebula#3175 Updated new nbds_max method
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 committed Apr 5, 2019
1 parent 6a4d9d0 commit 11ae494
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/vmm_mad/remotes/lib/lxd/mapper/qcow2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# 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 @@ -66,17 +68,17 @@ def do_unmap(device, _one_vm, _disk, _directory)
private

# Detects Max number of block devices
def load_nbds_max
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}")
return 0
OpenNebula.log_error("Cannot load max number of nbd devices\n#{e}"\
"Falling back to default #{NBDS_MAX}")
return NBDS_MAX
end

param = mods_conf[/(nbds_max=)(\d+)/]
param.split('=').last.to_i
mods_conf.match(/(nbds_max=)(\d+)/)[-1].to_i
end

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

load_nbds_max.times do |i|
nbds_max.times do |i|
return "/dev/nbd#{i}" unless nbds.include?(i)
end

Expand Down

0 comments on commit 11ae494

Please sign in to comment.