Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B #3177 Load max_nbds from running module #3188

Merged
merged 4 commits into from
Apr 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/vmm_mad/remotes/lib/lxd/mapper/qcow2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@

require 'mapper'

# Block device mapping for qcow2 disks, backed by nbd kernel module
class Qcow2Mapper < Mapper

# Max number of block devices. This should be set to the parameter used
# to load the nbd kernel module (default in kernel is 16)
NBDS_MAX = 256 # TODO: Read system config file

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

Expand All @@ -49,10 +46,11 @@ def do_map(one_vm, disk, _directory)
end

def do_unmap(device, _one_vm, _disk, _directory)
#After mapping and unmapping a qcow2 disk the next mapped qcow2 may collide with the previous one.
#The use of kpartx before unmapping seems to prevent this behavior on the nbd module used with
#the kernel versions in ubuntu 16.04
#
# After mapping and unmapping a qcow2 disk the next mapped qcow2
# may collide with the previous one. The use of kpartx
# before unmapping seems to prevent this behavior on the nbd module
# used with the kernel versions in ubuntu 16.04

# TODO: avoid using if kpartx was not used
hide_parts(device)
cmd = "#{COMMANDS[:nbd]} -d #{device}"
Expand All @@ -67,6 +65,15 @@ def do_unmap(device, _one_vm, _disk, _directory)

private

# Detects Max number of block devices
def nbds_max
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
def nbd_device
sys_parts = lsblk('')
nbds = []
Expand All @@ -78,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