1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-10 01:17:40 +03:00

M #-: Check qemu-nbd support for --fork

This commit is contained in:
Ruben S. Montero 2020-05-04 12:41:36 +02:00
parent b8e00d6cd9
commit c320ce032e
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87

View File

@ -23,6 +23,9 @@ require 'mapper'
# Block device mapping for qcow2 disks, backed by nbd kernel module
class Qcow2Mapper < Mapper
# Version --fork option was introduced in qemu-nbd command
QEMU_NBD_FORK_VERSION = "2.8.0"
def do_map(one_vm, disk, _directory)
device = nbd_device
@ -31,7 +34,10 @@ class Qcow2Mapper < Mapper
dsrc = one_vm.disk_source(disk)
File.chmod(0o664, dsrc) if File.symlink?(one_vm.sysds_path)
map = "#{COMMANDS[:nbd]} --fork -c #{device} #{dsrc}"
map = "#{COMMANDS[:nbd]}"
map.concat(" --fork") if fork_supported
map.concat(" -c #{device} #{dsrc}")
rc, _out, err = Command.execute(map, true)
unless rc.zero?
@ -64,6 +70,28 @@ class Qcow2Mapper < Mapper
private
def fork_supported
tgt_ver = nbd_version
return false if tgt_ver == "0.0.0"
Gem::Version.new(tgt_ver) >= Gem::Version.new(QEMU_NBD_FORK_VERSION)
end
def nbd_version
cmd = "#{COMMANDS[:nbd]} -V"
rc, out, _err = Command.execute(cmd, false)
return "0.0.0" unless rc.zero?
match_v = out.match(/qemu-nbd version (.*)$/)
return "0.0.0" if match_v.nil?
match_v[1]
end
# Detects Max number of block devices
def nbds_max
File.read('/sys/module/nbd/parameters/nbds_max').chomp.to_i