diff --git a/src/vmm_mad/remotes/lib/lxd/mapper/mapper.rb b/src/vmm_mad/remotes/lib/lxd/mapper/mapper.rb index 0a5a04f006f..3c4a0b9c435 100644 --- a/src/vmm_mad/remotes/lib/lxd/mapper/mapper.rb +++ b/src/vmm_mad/remotes/lib/lxd/mapper/mapper.rb @@ -137,24 +137,11 @@ def map(one_vm, disk, directory) return mount_dev(device, directory) unless %w[loop disk].include?(type) - size = disk['SIZE'].to_i if disk['SIZE'] - osize = disk['ORIGINAL_SIZE'].to_i if disk['ORIGINAL_SIZE'] - - cmd = "#{COMMANDS[:blkid]} -o export #{device}" - _rc, o, _e = Command.execute(cmd, false) - - fs_type = '' - - o.each_line {|l| - next unless (m = l.match(/TYPE=(.*)/)) + fstype = get_fstype(device) - fs_type = m[1] - break - } + return unless reset_fs_uuid(fstype, device) - reset_fs_uuid(fs_type, device) - - mount_resize_fs(device, directory, fs_type, size, osize) + mount_resize_fs(device, directory, fstype, disk) end # Unmaps a disk from a given directory @@ -455,7 +442,7 @@ def parse_fstab(partitions, path, fstab) next if %w[/ swap].include?(mount_point) - partitions.each { |p| + partitions.each {|p| next if p[key] != value return false unless mount_dev(p['path'], path + mount_point) @@ -471,7 +458,10 @@ def parse_fstab(partitions, path, fstab) # @param fs_type [String] # @param size, osize [Integer] disk size and original size # @return true if success - def mount_resize_fs(device, directory, fs_type, size, osize) + def mount_resize_fs(device, directory, fs_type, disk) + size = disk['SIZE'].to_i if disk['SIZE'] + osize = disk['ORIGINAL_SIZE'].to_i if disk['ORIGINAL_SIZE'] + # TODO: osize is always < size after 1st resize during deployment return mount_dev(device, directory) unless size > osize @@ -523,4 +513,20 @@ def reset_fs_uuid(fs_type, device) OpenNebula.log_error "#{__method__}: failed to change UUID: #{e}\n" end + def get_fstype(device) + cmd = "#{COMMANDS[:blkid]} -o export #{device}" + _rc, o, _e = Command.execute(cmd, false) + + fstype = '' + + o.each_line {|l| + next unless (m = l.match(/TYPE=(.*)/)) + + fstype = m[1] + break + } + + fstype + end + end