Skip to content

Commit

Permalink
#3103 Update map method
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 committed Mar 21, 2019
1 parent 14ee18f commit 6883f6a
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/vmm_mad/remotes/lib/lxd/mapper/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 6883f6a

Please sign in to comment.