mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
F #1684: Fix mount/umount for symlinks in the system datastore
This commit is contained in:
parent
e5d3f46da1
commit
5fcb9910bc
@ -66,7 +66,8 @@ class Mapper
|
||||
:e2fsck => 'sudo e2fsck',
|
||||
:resize2fs => 'sudo resize2fs',
|
||||
:xfs_growfs => 'sudo xfs_growfs',
|
||||
:chmod_nfs => 'chmod o+w'
|
||||
:chmod_nfs => 'chmod o+w',
|
||||
:rbd => 'sudo rbd --id'
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
@ -182,28 +183,35 @@ class Mapper
|
||||
OpenNebula.log_info "Unmapping disk at #{directory}"
|
||||
|
||||
sys_parts = lsblk('')
|
||||
partitions = []
|
||||
device = ''
|
||||
|
||||
return false if !sys_parts
|
||||
|
||||
partitions = []
|
||||
device = ''
|
||||
|
||||
ds = one_vm.lxdrc[:datastore_location] + "/#{one_vm.sysds_id}"
|
||||
real_ds = File.readlink(ds) if File.symlink?(ds)
|
||||
|
||||
real_path = directory
|
||||
real_path = real_ds + directory.split(ds)[-1] if directory.include?(ds)
|
||||
|
||||
sys_parts.each { |d|
|
||||
if d['mountpoint'] == directory
|
||||
if d['mountpoint'] == real_path
|
||||
partitions = [d]
|
||||
device = d['path']
|
||||
break
|
||||
end
|
||||
|
||||
d['children'].each { |c|
|
||||
if c['mountpoint'] == directory
|
||||
if c['mountpoint'] == real_path
|
||||
partitions = d['children']
|
||||
device = d['path']
|
||||
break
|
||||
end
|
||||
} if d['children']
|
||||
|
||||
break if !partitions.empty?
|
||||
}
|
||||
} if d['children']
|
||||
|
||||
break if !partitions.empty?
|
||||
}
|
||||
|
||||
partitions.delete_if { |p| !p['mountpoint'] }
|
||||
|
||||
@ -213,7 +221,7 @@ class Mapper
|
||||
|
||||
umount(partitions)
|
||||
|
||||
do_unmap(device, one_vm, disk, directory)
|
||||
do_unmap(device, one_vm, disk, real_path)
|
||||
|
||||
return true
|
||||
end
|
||||
@ -368,7 +376,7 @@ class Mapper
|
||||
partitions = [partitions]
|
||||
end
|
||||
|
||||
partitions.delete_if { |p|
|
||||
partitions.delete_if { |p|
|
||||
p['fstype'].casecmp?('swap') if p['fstype']
|
||||
}
|
||||
end
|
||||
@ -391,11 +399,10 @@ class Mapper
|
||||
def disk_source(one_vm, disk)
|
||||
ds_path = one_vm.ds_path
|
||||
ds_id = one_vm.sysds_id
|
||||
|
||||
vm_id = one_vm.vm_id
|
||||
disk_id = disk['DISK_ID']
|
||||
|
||||
"#{ds_path}/#{ds_id}/#{vm_id}/disk.#{disk_id}"
|
||||
"#{ds_path}/#{ds_id}/#{vm_id}/disk.#{disk_id}"
|
||||
end
|
||||
|
||||
# Adds path to the partition Hash. This is needed for lsblk version < 2.33
|
||||
|
@ -28,25 +28,19 @@ class Qcow2Mapper < Mapper
|
||||
def do_map(one_vm, disk, directory)
|
||||
device = nbd_device
|
||||
|
||||
return nil if device.empty?
|
||||
return if device.empty?
|
||||
|
||||
dsrc = disk_source(one_vm, disk)
|
||||
cmd = "#{COMMANDS[:nbd]} -c #{device} #{dsrc}"
|
||||
|
||||
rc, out, err = Command.execute(cmd, true)
|
||||
|
||||
loop do
|
||||
sleep 0.5
|
||||
|
||||
nbd_parts = lsblk(device)
|
||||
|
||||
break if nbd_parts && nbd_parts[0] && nbd_parts[0]['fstype']
|
||||
end
|
||||
|
||||
rc, _out, err = Command.execute(cmd, true)
|
||||
|
||||
if rc != 0
|
||||
OpenNebula.log_error("do_map: #{err}")
|
||||
return nil
|
||||
return
|
||||
end
|
||||
|
||||
sleep 0.5 # TODO: improve settledown, lsblk -f fails
|
||||
|
||||
device
|
||||
end
|
||||
|
22
src/vmm_mad/remotes/lib/lxd/opennebula-lxd
Normal file
22
src/vmm_mad/remotes/lib/lxd/opennebula-lxd
Normal file
@ -0,0 +1,22 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
#
|
||||
# This file is meant for allow oneadmin to run the following commands as root
|
||||
#
|
||||
|
||||
Cmnd_Alias ONE_MAPPER = /bin/lsblk, /sbin/losetup, /bin/mount, /bin/umount, /sbin/kpartx, /usr/bin/qemu-nbd, /bin/mkdir, /usr/bin/catfstab, /sbin/e2fsck, /sbin/resize2fs, /usr/sbin/xfs_growfs, /usr/bin/rbd
|
||||
oneadmin ALL=(ALL) NOPASSWD: ONE_MAPPER
|
Loading…
x
Reference in New Issue
Block a user