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

Fix ext4 issues with uuidgen #3110

Closed
wants to merge 2 commits into from
Closed
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
70 changes: 45 additions & 25 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)
fstype = get_fstype(device)

fs_type = ''
return unless reset_fs_uuid(fstype, device)

o.each_line {|l|
next unless (m = l.match(/TYPE=(.*)/))

fs_type = m[1]
break
}

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 All @@ -484,13 +474,21 @@ def mount_resize_fs(device, directory, fs_type, size, osize)

Command.execute("#{COMMANDS[:xfs_growfs]} -d #{directory}", false)
when /ext/
_rc, o, e = Command.execute("#{COMMANDS[:e2fsck]} -f -y #{device}", false)
err = "#{__method__}: failed to resize #{device}\n"

_rc, o, e = check_ext4(device)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after poweroff they failed to boot again when recreating the fs uuid, it required e2fsck to be run again


if o.empty?
err = "#{__method__}: failed to resize #{device}\n#{e}"
OpenNebula.log_error err
OpenNebula.log_error("#{err}#{e}")
return
else
Command.execute("#{COMMANDS[:resize2fs]} #{device}", false)
cmd = "#{COMMANDS[:resize2fs]} #{device}"
rc, _o, e = Command.execute(cmd, false)

if rc != 0
OpenNebula.log_error("#{err}#{e}")
return
end
end

rc = mount_dev(device, directory)
Expand All @@ -512,15 +510,37 @@ def reset_fs_uuid(fs_type, device)
when /xfs/
cmd = "#{COMMANDS[:xfs_admin]} -U generate #{device}"
when /ext/
cmd = "#{COMMANDS[:tune2fs]} tune2fs -U random #{device}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the main issue, the command was 2 times written

check_ext4(device)
cmd = "#{COMMANDS[:tune2fs]} -U random #{device}"
else
return true
end

rc, _o, e = Command.execute(cmd, false)
rc, o, e = Command.execute(cmd, false)
return true if rc.zero?

OpenNebula.log_error "#{__method__}: failed to change UUID: #{e}\n"
OpenNebula.log_error "#{__method__}: error changing UUID: #{o}\n#{e}\n"
nil
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

def check_ext4(part)
Command.execute("#{COMMANDS[:e2fsck]} -f -y #{part}", false)
end

end