1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

F #1684: Force kernel to update parition tables of nbd's. Ubuntu 16.04

This commit is contained in:
Ruben S. Montero 2019-02-06 17:04:59 +01:00
parent 6cb05dadb2
commit afc5a362bd
3 changed files with 54 additions and 37 deletions

View File

@ -446,4 +446,31 @@ class Mapper
end
end
# Returns true if device has mapped partitions
def parts_on?(device)
partitions = lsblk(device)
return true if partitions[0]['type'] == 'part'
false
end
def show_parts(device)
action_parts(device, '-s -av')
end
def hide_parts(device)
action_parts(device, '-d')
end
# Runs kpartx vs a device with required flags as arguments
def action_parts(device, action)
cmd = "#{COMMANDS[:kpartx]} #{action} #{device}"
rc, _out, err = Command.execute(cmd, false)
return true if rc.zero?
OpenNebula.log_error("#{__method__}: #{err}")
false
end
end

View File

@ -24,7 +24,7 @@ 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
NBDS_MAX = 256 # TODO: Read system config file
def do_map(one_vm, disk, _directory)
device = nbd_device
@ -35,7 +35,7 @@ class Qcow2Mapper < Mapper
File.chmod(0o664, dsrc) if File.symlink?(one_vm.sysds_path)
map = "#{COMMANDS[:nbd]} -c #{device} #{dsrc}"
rc, _out, err = Command.execute(map, false)
rc, _out, err = Command.execute(map, true)
unless rc.zero?
OpenNebula.log_error("#{__method__}: #{err}")
@ -43,7 +43,7 @@ class Qcow2Mapper < Mapper
end
# TODO: improve wait condition
sleep 5 # wait for parts to come out
sleep 1 # wait for parts to come out
show_parts(device) unless parts_on?(device)
@ -69,36 +69,8 @@ class Qcow2Mapper < Mapper
private
# Returns true if device has mapped partitions
def parts_on?(device)
partitions = lsblk(device)
return true if partitions[0]['type'] == 'part'
false
end
def show_parts(device)
action_parts(device, '-s -av')
end
def hide_parts(device)
action_parts(device, '-d')
end
# Runs kpartx vs a device with required flags as arguments
def action_parts(device, action)
cmd = "#{COMMANDS[:kpartx]} #{action} #{device}"
rc, _out, err = Command.execute(cmd, false)
return true if rc.zero?
OpenNebula.log_error("#{__method__}: #{err}")
false
end
def nbd_device
sys_parts = lsblk('')
device_id = -1
nbds = []
sys_parts.each do |p|

View File

@ -19,6 +19,7 @@
$LOAD_PATH.unshift File.dirname(__FILE__)
require 'mapper'
require 'tmpdir'
# Ceph RBD mapper
class RBDMapper < Mapper
@ -32,15 +33,20 @@ class RBDMapper < Mapper
cmd = "#{COMMANDS[:rbd]} #{@ceph_user} map #{dsrc}"
rc, out, err = Command.execute(cmd, false)
rc, out, err = Command.execute(cmd, true)
unless rc.zero?
OpenNebula.log_error("#{__method__}: #{err}")
return
end
# TODO: improve wait condition
sleep 5 # wait for partition table
sleep 1 # wait for partition table
return out.chomp if rc.zero?
OpenNebula.log_error("#{__method__}: #{err}")
nil
# TODO: deprecate workaround for ubuntu 16.04 not
# updating partition tables
try_mount(out.chomp)
end
def do_unmap(device, _one_vm, _disk, _directory)
@ -54,4 +60,16 @@ class RBDMapper < Mapper
nil
end
private
# This function tries to mount mapped devices to force update of partition
# tables
def try_mount(device)
dev = device
dev += "p1" if parts_on?(device)
cmd = "#{COMMANDS[:mount]} --fake #{dev} /mnt"
device
end
end