From 70b0f233bbe5af32a530662e7ab81b5485b8377f Mon Sep 17 00:00:00 2001 From: Jiankang Fan Date: Mon, 19 Dec 2016 20:59:12 +0800 Subject: [PATCH] support vdfs and squashfs image creation Change-Id: Ife64b311bfece1e2f3b2a231062a9a2b9e69d897 Signed-off-by: Jiankang Fan --- mic/imager/loop.py | 56 ++++++++++++++++++++++++++++-- mic/kickstart/custom_commands/partition.py | 10 ++++++ mic/utils/errors.py | 4 +++ mic/utils/fs_related.py | 15 ++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) diff --git a/mic/imager/loop.py b/mic/imager/loop.py index 0943ec7..c0620a4 100644 --- a/mic/imager/loop.py +++ b/mic/imager/loop.py @@ -28,7 +28,8 @@ from mic.archive import packing, compressing # The maximum string length supported for LoopImageCreator.fslabel FSLABEL_MAXLEN = 32 - +# Support for Read-only file system list +AFTER_MNT_FS = {"squashfs":".sqsh", "vdfs":".vdfs"} def save_mountpoints(fpath, loops, arch = None): """Save mount points mapping to file @@ -126,12 +127,18 @@ class LoopImageCreator(BaseImageCreator): "ext3") self.__fsopts = kickstart.get_image_fsopts(self.ks, "defaults,noatime") + if self.__fstype in AFTER_MNT_FS.keys(): + self.__fstype = "ext4" allloops = [] for part in sorted(kickstart.get_partitions(self.ks), key=lambda p: p.mountpoint): + aft_fstype = None if part.fstype == "swap": continue + elif part.fstype in AFTER_MNT_FS.keys(): + aft_fstype = part.fstype + part.fstype = "ext4" label = part.label mp = part.mountpoint @@ -153,7 +160,10 @@ class LoopImageCreator(BaseImageCreator): 'name': imgname, 'size': part.size or 4096L * 1024 * 1024, 'fstype': part.fstype or 'ext3', + 'aft_fstype': aft_fstype or None, 'extopts': part.extopts or None, + 'vdfsopts': part.vdfsopts or None, + 'squashfsopts': part.squashfsopts or None, 'loop': None, # to be created in _mount_instroot 'uuid': part.uuid or None, 'kspart' : part, @@ -180,7 +190,12 @@ class LoopImageCreator(BaseImageCreator): if not self._instloops: return None - return [lo['name'] for lo in self._instloops] + names = [] + for lo in self._instloops : + names.append(lo['name']) + for ro in AFTER_MNT_FS.values(): + names.append(lo['name'].replace('.img',ro)) + return list(set(names)) def _set_fstype(self, fstype): self.__fstype = fstype @@ -391,6 +406,43 @@ class LoopImageCreator(BaseImageCreator): for item in self._instloops: imgfile = os.path.join(self._imgdir, item['name']) + + if item['aft_fstype'] in AFTER_MNT_FS.keys(): + mountpoint = misc.mkdtemp() + ext4img = os.path.join(self._imgdir, item['name']) + runner.show('mount -t ext4 %s %s' % (ext4img, mountpoint)) + runner.show('ls -al %s' % (mountpoint)) +# item['loop'].mount(None, 'not_create') +# point_mnt = os.path.join(self._instroot, item['mountpoint'].lstrip('/')) + + fs_suffix = AFTER_MNT_FS[item['aft_fstype']] + if item['aft_fstype'] == "squashfs": +# fs.mksquashfs(mountpoint, self._outdir+"/"+item['label']+fs_suffix) + args = "mksquashfs " + mountpoint + " " + self._imgdir+"/"+item['label']+fs_suffix + if item['squashfsopts']: + squashfsopts=item['squashfsopts'].replace(',', ' ') + runner.show("mksquashfs --help") + runner.show("%s %s" % (args, squashfsopts)) + else: + runner.show("%s " % args) + + if item['aft_fstype'] == "vdfs": + ##FIXME temporary code - replace this with fs.mkvdfs() + if item['vdfsopts']: + vdfsopts=item['vdfsopts'].replace(',', ' ') + else: + vdfsopts="-i -z 1024M" + + fullpathmkvdfs = "mkfs.vdfs" #find_binary_path("mkfs.vdfs") + runner.show("%s --help" % fullpathmkvdfs) +# fs.mkvdfs(mountpoint, self._outdir+"/"+item['label']+fs_suffix, vdfsopts) + runner.show('%s %s -r %s %s' % (fullpathmkvdfs, vdfsopts, mountpoint, self._imgdir+"/"+item['label']+fs_suffix)) + + runner.show('umount %s' % mountpoint) +# os.unlink(mountpoint) + runner.show('mv %s %s' % (self._imgdir+"/"+item['label']+fs_suffix, self._imgdir+"/"+item['label']+".img") ) + runner.show('ls -al %s' % self._imgdir) + if item['fstype'] == "ext4": runner.show('/sbin/tune2fs -O ^huge_file,extents,uninit_bg %s ' % imgfile) diff --git a/mic/kickstart/custom_commands/partition.py b/mic/kickstart/custom_commands/partition.py index 89dad58..1d31c11 100644 --- a/mic/kickstart/custom_commands/partition.py +++ b/mic/kickstart/custom_commands/partition.py @@ -29,6 +29,8 @@ class Mic_PartData(FC4_PartData): self.part_type = kwargs.get("part_type", None) self.uuid = kwargs.get("uuid", None) self.exclude_image = kwargs.get("exclude_from_image", False) + self.vdfsopts = kwargs.get("vdfsopts", None) + self.squashfsopts = kwargs.get("squashfsopts", None) def _getArgsAsStr(self): retval = FC4_PartData._getArgsAsStr(self) @@ -43,6 +45,10 @@ class Mic_PartData(FC4_PartData): retval += " --uuid=%s" % self.uuid if self.exclude_image: retval += " --exclude-from-image" + if self.vdfsopts: + retval += " --vdfsoptions=%s" % self.vdfsopts + if self.squashfsopts: + retval += " --squashfsoptions=%s" % self.squashfsopts return retval @@ -63,4 +69,8 @@ class Mic_Partition(FC4_Partition): op.add_option("--uuid", dest="uuid", action="store", type="string") op.add_option("--exclude-from-image", action="store_true", dest="exclude_image", default=False) + op.add_option("--vdfsoptions", type="string", action="store", dest="vdfsopts", + default=None) + op.add_option("--squashfsoptions", type="string", action="store", dest="squashfsopts", + default=None) return op diff --git a/mic/utils/errors.py b/mic/utils/errors.py index f64b452..12ddde6 100644 --- a/mic/utils/errors.py +++ b/mic/utils/errors.py @@ -72,6 +72,10 @@ class SquashfsError(CreatorError): """ Error class for Squashfs related """ keyword = 'Squashfs' +class VdfsError(CreatorError): + """ Error class for Vdfs related """ + keyword = 'vdfs' + class BootstrapError(CreatorError): """ Error class for Bootstrap related """ keyword = 'Bootstrap' diff --git a/mic/utils/fs_related.py b/mic/utils/fs_related.py index a6c2c0b..54f68da 100644 --- a/mic/utils/fs_related.py +++ b/mic/utils/fs_related.py @@ -69,6 +69,21 @@ def makedirs(dirname): if err.errno != errno.EEXIST: raise +def mkvdfs(in_img, out_img, fsoptions): + """ This function is incomplete. """ + fullpathmkvdfs = find_binary_path("mkfs.vdfs") +# args = fullpathmkvdfs + " -i -r "+ in_img + " -z 1024M -s " + out_img + args = fullpathmkvdfs + " " + fsoptions + " -r " + in_img + " " + out_img + msger.verbose("vdfs args: %s" % args) + runner.show("%s --help" % fullpathmkvdfs) +# if not sys.stdout.isatty(): +# args.append("-no-progress") +# runner.show("%s --help" % fullpathmkvdfs) + ret = runner.show(args) + if ret != 0: + runner.show ("vdfs error") + raise VdfsError("' %s' exited with error (%d)" % (args, ret)) + def mksquashfs(in_img, out_img): fullpathmksquashfs = find_binary_path("mksquashfs") args = [fullpathmksquashfs, in_img, out_img] -- 2.7.4