1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-30 00:20:08 +00:00

wic: Update/rename/delete mount-related code

The wic code inherited a basic image-creation flow based on mounting
loop devices, but wic doesn't actually mount anything, so rename parts
of the code dealing with mounting to something more appropriate, and
remove related unused code.

(From OE-Core rev: 94e15c18c011b0d7d71276cd4566be2417c2c6be)

Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Tom Zanussi
2014-08-08 10:09:12 -05:00
committed by Richard Purdie
parent bd0dd4489e
commit 4d1f5ee6d1
4 changed files with 22 additions and 106 deletions
+9 -38
View File
@@ -96,42 +96,16 @@ class BaseImageCreator(object):
os.makedirs(self.tmpdir) os.makedirs(self.tmpdir)
#
# Properties
#
def __get_instroot(self):
if self.__builddir is None:
raise CreatorError("_instroot is not valid before calling mount()")
return self.__builddir + "/install_root"
_instroot = property(__get_instroot)
"""The location of the install root directory.
This is the directory into which the system is installed. Subclasses may
mount a filesystem image here or copy files to/from here.
Note, this directory does not exist before ImageCreator.mount() is called.
Note also, this is a read-only attribute.
"""
# #
# Hooks for subclasses # Hooks for subclasses
# #
def _mount_instroot(self, base_on = None): def _create(self):
"""Mount or prepare the install root directory. """Create partitions for the disk image(s)
This is the hook where subclasses may prepare the install root by e.g. This is the hook where subclasses may create the partitions
mounting creating and loopback mounting a filesystem image to that will be assembled into disk image(s).
_instroot.
There is no default implementation. There is no default implementation.
base_on -- this is the value passed to mount() and can be interpreted
as the subclass wishes; it might e.g. be the location of
a previously created ISO containing a system image.
""" """
pass pass
@@ -176,19 +150,16 @@ class BaseImageCreator(object):
runner.show('umount -l %s' % self.workdir) runner.show('umount -l %s' % self.workdir)
def mount(self): def create(self):
"""Setup the target filesystem in preparation for an install. """Create partitions for the disk image(s)
This function sets up the filesystem which the ImageCreator will Create the partitions that will be assembled into disk
install into and configure. The ImageCreator class merely creates an image(s).
install root directory, bind mounts some system directories (e.g. /dev)
and writes out /etc/fstab. Other subclasses may also e.g. create a
sparse file, format it and loopback mount it to the install root.
""" """
self.__setup_tmpdir() self.__setup_tmpdir()
self.__ensure_builddir() self.__ensure_builddir()
self._mount_instroot() self._create()
def unmount(self): def unmount(self):
"""Unmounts the target filesystem. """Unmounts the target filesystem.
+10 -32
View File
@@ -79,9 +79,10 @@ class DirectImageCreator(BaseImageCreator):
self.staging_data_dir = staging_data_dir self.staging_data_dir = staging_data_dir
def __write_fstab(self, image_rootfs): def __write_fstab(self, image_rootfs):
"""overriden to generate fstab (temporarily) in rootfs. This """overriden to generate fstab (temporarily) in rootfs. This is called
is called from mount_instroot, make sure it doesn't get called from _create, make sure it doesn't get called from
from BaseImage.mount()""" BaseImage.create()
"""
if image_rootfs is None: if image_rootfs is None:
return None return None
@@ -217,29 +218,15 @@ class DirectImageCreator(BaseImageCreator):
# #
# Actual implemention # Actual implemention
# #
def _mount_instroot(self): def _create(self):
""" """
For 'wic', we already have our build artifacts and don't want For 'wic', we already have our build artifacts - we just create
to loop mount anything to install into, we just create
filesystems from the artifacts directly and combine them into filesystems from the artifacts directly and combine them into
a partitioned image. a partitioned image.
We still want to reuse as much of the basic mic machinery
though; despite the fact that we don't actually do loop or any
other kind of mounting we still want to do many of the same
things to prepare images, so we basically just adapt to the
basic framework and reinterpret what 'mounting' means in our
context.
_instroot would normally be something like
/var/tmp/wic/build/imgcreate-s_9AKQ/install_root, for
installing packages, etc. We don't currently need to do that,
so we simplify life by just using /var/tmp/wic/build as our
workdir.
""" """
parts = self._get_parts() parts = self._get_parts()
self.__instimage = PartitionedMount(self._instroot) self.__instimage = PartitionedMount()
for p in parts: for p in parts:
# as a convenience, set source to the boot partition source # as a convenience, set source to the boot partition source
@@ -250,20 +237,11 @@ class DirectImageCreator(BaseImageCreator):
for p in parts: for p in parts:
# need to create the filesystems in order to get their # need to create the filesystems in order to get their
# sizes before we can add them and do the layout. # sizes before we can add them and do the layout.
# PartitionedMount.mount() actually calls __format_disks() # PartitionedMount.create() actually calls __format_disks()
# to create the disk images and carve out the partitions, # to create the disk images and carve out the partitions,
# then self.install() calls PartitionedMount.install() # then self.install() calls PartitionedMount.install()
# which calls __install_partitition() for each partition # which calls __install_partitition() for each partition
# to dd the fs into the partitions. It would be nice to # to dd the fs into the partitions.
# be able to use e.g. ExtDiskMount etc to create the
# filesystems, since that's where existing e.g. mkfs code
# is, but those are only created after __format_disks()
# which needs the partition sizes so needs them created
# before its called. Well, the existing setup is geared
# to installing packages into mounted filesystems - maybe
# when/if we need to actually do package selection we
# should modify things to use those objects, but for now
# we can avoid that.
fstab = self.__write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) fstab = self.__write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
@@ -294,7 +272,7 @@ class DirectImageCreator(BaseImageCreator):
self.__disks[disk_name] = disk_obj self.__disks[disk_name] = disk_obj
self.__instimage.add_disk(disk_name, disk_obj) self.__instimage.add_disk(disk_name, disk_obj)
self.__instimage.mount() self.__instimage.create()
def install(self): def install(self):
""" """
@@ -91,7 +91,7 @@ class DirectPlugin(ImagerPlugin):
creatoropts) creatoropts)
try: try:
creator.mount() creator.create()
creator.install() creator.install()
creator.configure() creator.configure()
creator.print_outimage_info() creator.print_outimage_info()
+2 -35
View File
@@ -33,11 +33,9 @@ MBR_OVERHEAD = 1
SECTOR_SIZE = 512 SECTOR_SIZE = 512
class PartitionedMount: class PartitionedMount:
def __init__(self, mountdir): def __init__(self):
self.disks = {} self.disks = {}
self.partitions = [] self.partitions = []
self.mountOrder = []
self.unmountOrder = []
self.parted = find_binary_path("parted") self.parted = find_binary_path("parted")
# Size of a sector used in calculations # Size of a sector used in calculations
self.sector_size = SECTOR_SIZE self.sector_size = SECTOR_SIZE
@@ -102,7 +100,6 @@ class PartitionedMount:
'label': label, # Partition label 'label': label, # Partition label
'disk_name': disk_name, # physical disk name holding partition 'disk_name': disk_name, # physical disk name holding partition
'device': None, # kpartx device node for partition 'device': None, # kpartx device node for partition
'mount': None, # Mount object
'num': None, # Partition number 'num': None, # Partition number
'boot': boot, # Bootable flag 'boot': boot, # Bootable flag
'align': align, # Partition alignment 'align': align, # Partition alignment
@@ -303,17 +300,6 @@ class PartitionedMount:
self.__run_parted(["-s", d['disk'].device, "set", self.__run_parted(["-s", d['disk'].device, "set",
"%d" % p['num'], "lba", "off"]) "%d" % p['num'], "lba", "off"])
def __calculate_mountorder(self):
msger.debug("Calculating mount order")
for p in self.partitions:
if p['mountpoint']:
self.mountOrder.append(p['mountpoint'])
self.unmountOrder.append(p['mountpoint'])
self.mountOrder.sort()
self.unmountOrder.sort()
self.unmountOrder.reverse()
def cleanup(self): def cleanup(self):
if self.disks: if self.disks:
for dev in self.disks.keys(): for dev in self.disks.keys():
@@ -323,23 +309,6 @@ class PartitionedMount:
except: except:
pass pass
def unmount(self):
for mp in self.unmountOrder:
if mp == 'swap':
continue
p = None
for p1 in self.partitions:
if p1['mountpoint'] == mp:
p = p1
break
if p['mount'] != None:
try:
p['mount'].cleanup()
except:
pass
p['mount'] = None
def __install_partition(self, num, source_file, start, size): def __install_partition(self, num, source_file, start, size):
""" """
Install source_file contents into a partition. Install source_file contents into a partition.
@@ -375,13 +344,11 @@ class PartitionedMount:
self.__install_partition(p['num'], p['source_file'], self.__install_partition(p['num'], p['source_file'],
p['start'], p['size']) p['start'], p['size'])
def mount(self): def create(self):
for dev in self.disks.keys(): for dev in self.disks.keys():
d = self.disks[dev] d = self.disks[dev]
d['disk'].create() d['disk'].create()
self.__format_disks() self.__format_disks()
self.__calculate_mountorder()
return return