diff --git a/src/vmm_mad/remotes/lib/lxd/mapper/qcow2.rb b/src/vmm_mad/remotes/lib/lxd/mapper/qcow2.rb index eba1a74b159..d95efa4d76e 100644 --- a/src/vmm_mad/remotes/lib/lxd/mapper/qcow2.rb +++ b/src/vmm_mad/remotes/lib/lxd/mapper/qcow2.rb @@ -65,6 +65,21 @@ def do_unmap(device, _one_vm, _disk, _directory) private + # Detects Max number of block devices + def load_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 + end + + param = mods_conf[/(nbds_max=)(\d+)/] + param.split('=').last.to_i + end + + # Returns the first non-used nbd device def nbd_device sys_parts = lsblk('') nbds = [] @@ -76,7 +91,7 @@ def nbd_device nbds << m[1].to_i end - NBDS_MAX.times do |i| + load_nbds_max.times do |i| return "/dev/nbd#{i}" unless nbds.include?(i) end