def _before_link_dm_node(self, e): """Links the volume using the device mapper This allows us to create a 'window' into the volume that acts like a volum in itself. Mainly it is used to fool grub into thinking that it is working with a real volume, rather than a loopback device or a network block device. Args: e (_e_obj): Event object containing arguments to create() Arguments are: logical_start_sector (int): The sector the volume should start at in the new volume start_sector (int): The offset at which the volume should begin to be mapped in the new volume sectors (int): The number of sectors that should be mapped Read more at: http://manpages.debian.org/cgi-bin/man.cgi?query=dmsetup&apropos=0&sektion=0&manpath=Debian+7.0+wheezy&format=html&locale=en Raises: VolumeError """ import os.path from common.fs import get_partitions # Fetch information from /proc/partitions proc_partitions = get_partitions() device_name = os.path.basename(self.device_path) device_partition = proc_partitions[device_name] # The sector the volume should start at in the new volume logical_start_sector = getattr(e, 'logical_start_sector', 0) # The offset at which the volume should begin to be mapped in the new volume start_sector = getattr(e, 'start_sector', 0) # The number of sectors that should be mapped sectors = getattr(e, 'sectors', int(self.size / 512) - start_sector) # This is the table we send to dmsetup, so that it may create a decie mapping for us. table = ('{log_start_sec} {sectors} linear {major}:{minor} {start_sec}' .format(log_start_sec=logical_start_sector, sectors=sectors, major=device_partition['major'], minor=device_partition['minor'], start_sec=start_sector)) import string import os.path # Figure out the device letter and path for letter in string.ascii_lowercase: dev_name = 'vd' + letter dev_path = os.path.join('/dev/mapper', dev_name) if not os.path.exists(dev_path): self.dm_node_name = dev_name self.dm_node_path = dev_path break if not hasattr(self, 'dm_node_name'): raise VolumeError('Unable to find a free block device path for mounting the bootstrap volume') # Create the device mapping log_check_call(['dmsetup', 'create', self.dm_node_name], table) # Update the device_path but remember the old one for when we unlink the volume again self.unlinked_device_path = self.device_path self.device_path = self.dm_node_path
def _before_link_dm_node(self, e): import os.path from common.fs import get_partitions proc_partitions = get_partitions() device_name = os.path.basename(self.device_path) device_partition = proc_partitions[device_name] # The sector the volume should start at in the new volume logical_start_sector = getattr(e, 'logical_start_sector', 0) # The offset at which the volume should begin to be mapped in the new volume start_sector = getattr(e, 'start_sector', 0) sectors = getattr(e, 'sectors', int(self.size / 512) - start_sector) table = ('{log_start_sec} {sectors} linear {major}:{minor} {start_sec}' .format(log_start_sec=logical_start_sector, sectors=sectors, major=device_partition['major'], minor=device_partition['minor'], start_sec=start_sector)) import string import os.path for letter in string.ascii_lowercase: dev_name = 'vd' + letter dev_path = os.path.join('/dev/mapper', dev_name) if not os.path.exists(dev_path): self.dm_node_name = dev_name self.dm_node_path = dev_path break if not hasattr(self, 'dm_node_name'): raise VolumeError('Unable to find a free block device path for mounting the bootstrap volume') log_check_call(['/sbin/dmsetup', 'create', self.dm_node_name], table) self.unlinked_device_path = self.device_path self.device_path = self.dm_node_path
def _before_link_dm_node(self, e): """Links the volume using the device mapper This allows us to create a 'window' into the volume that acts like a volum in itself. Mainly it is used to fool grub into thinking that it is working with a real volume, rather than a loopback device or a network block device. Args: e (_e_obj): Event object containing arguments to create() Arguments are: logical_start_sector (int): The sector the volume should start at in the new volume start_sector (int): The offset at which the volume should begin to be mapped in the new volume sectors (int): The number of sectors that should be mapped Read more at: http://manpages.debian.org/cgi-bin/man.cgi?query=dmsetup&apropos=0&sektion=0&manpath=Debian+7.0+wheezy&format=html&locale=en Raises: VolumeError """ import os.path from common.fs import get_partitions # Fetch information from /proc/partitions proc_partitions = get_partitions() device_name = os.path.basename(self.device_path) device_partition = proc_partitions[device_name] # The sector the volume should start at in the new volume logical_start_sector = getattr(e, 'logical_start_sector', 0) # The offset at which the volume should begin to be mapped in the new volume start_sector = getattr(e, 'start_sector', 0) # The number of sectors that should be mapped sectors = getattr(e, 'sectors', int(self.size / 512) - start_sector) # This is the table we send to dmsetup, so that it may create a decie mapping for us. table = ('{log_start_sec} {sectors} linear {major}:{minor} {start_sec}' .format(log_start_sec=logical_start_sector, sectors=sectors, major=device_partition['major'], minor=device_partition['minor'], start_sec=start_sector)) import string import os.path # Figure out the device letter and path for letter in string.ascii_lowercase: dev_name = 'vd' + letter dev_path = os.path.join('/dev/mapper', dev_name) if not os.path.exists(dev_path): self.dm_node_name = dev_name self.dm_node_path = dev_path break if not hasattr(self, 'dm_node_name'): raise VolumeError( 'Unable to find a free block device path for mounting the bootstrap volume' ) # Create the device mapping log_check_call(['dmsetup', 'create', self.dm_node_name], table) # Update the device_path but remember the old one for when we unlink the volume again self.unlinked_device_path = self.device_path self.device_path = self.dm_node_path
def _is_nbd_used(self, device_name): return device_name in get_partitions()