summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDohyung Kim <dohyung2.kim@samsung.com>2017-12-26 18:36:57 +0900
committeryuhuan.yang <yuhuan.yang@samsung.com>2018-01-30 11:04:48 +0800
commit2af451af4f5b4cacbc47a36fee8ebda99ef28b73 (patch)
tree038b4fe1a9aedc7e346378cbd1334c0042b07d8f
parent701778b56a56edaefa7b508d6bb3f31ee8ece83a (diff)
downloadmic-2af451af4f5b4cacbc47a36fee8ebda99ef28b73.tar.gz
mic-2af451af4f5b4cacbc47a36fee8ebda99ef28b73.tar.bz2
mic-2af451af4f5b4cacbc47a36fee8ebda99ef28b73.zip
Add init_expand option to partition
- if init_expand is enabled, expand partition size(* 1.5) before mount - check partition size after running resize2fs to verify partition size Change-Id: I60e889f04368877b9d74a581279c9ea4f5d33217 Signed-off-by: Dohyung Kim <dohyung2.kim@samsung.com>
-rwxr-xr-xmic/imager/loop.py3
-rwxr-xr-xmic/kickstart/custom_commands/partition.py4
-rw-r--r--mic/utils/fs_related.py38
3 files changed, 41 insertions, 4 deletions
diff --git a/mic/imager/loop.py b/mic/imager/loop.py
index 7fb5024..1e44343 100755
--- a/mic/imager/loop.py
+++ b/mic/imager/loop.py
@@ -170,6 +170,7 @@ class LoopImageCreator(BaseImageCreator):
'kspart' : part,
'exclude_image' : part.exclude_image or None,
'no_shrink': part.no_shrink or False,
+ 'init_expand': part.init_expand or False,
})
self._instloops = allloops
@@ -387,7 +388,7 @@ class LoopImageCreator(BaseImageCreator):
try:
msger.verbose('Mounting image "%s" on "%s"' % (imgname, mp))
fs.makedirs(mp)
- loop['loop'].mount()
+ loop['loop'].mount(init_expand=loop['init_expand'])
# Make an autogenerated uuid avaialble in _get_post_scripts_env()
if loop['kspart'] and loop['kspart'].uuid is None and \
loop['loop'].uuid:
diff --git a/mic/kickstart/custom_commands/partition.py b/mic/kickstart/custom_commands/partition.py
index d0385b7..341e8dc 100755
--- a/mic/kickstart/custom_commands/partition.py
+++ b/mic/kickstart/custom_commands/partition.py
@@ -33,6 +33,7 @@ class Mic_PartData(FC4_PartData):
self.squashfsopts = kwargs.get("squashfsopts", None)
self.cpioopts = kwargs.get("cpioopts", None)
self.no_shrink = kwargs.get("no_shrink", False)
+ self.init_expand = kwargs.get("init_expand", False)
def _getArgsAsStr(self):
retval = FC4_PartData._getArgsAsStr(self)
@@ -55,6 +56,8 @@ class Mic_PartData(FC4_PartData):
retval += " --cpiooptions=%s" % self.cpioopts
if self.no_shrink:
retval += " --no-shrink"
+ if self.init_expand:
+ retval += " --init-expand"
return retval
class Mic_Partition(FC4_Partition):
@@ -81,4 +84,5 @@ class Mic_Partition(FC4_Partition):
op.add_option("--cpiooptions", type="string", action="store", dest="cpioopts",
default=None)
op.add_option("--no-shrink", action="store_true", dest="no_shrink", default=False)
+ op.add_option("--init-expand", action="store_true", dest="init_expand", default=False)
return op
diff --git a/mic/utils/fs_related.py b/mic/utils/fs_related.py
index cee4c8a..0040fa2 100644
--- a/mic/utils/fs_related.py
+++ b/mic/utils/fs_related.py
@@ -304,6 +304,17 @@ class LoopbackDisk(Disk):
rc = runner.show([self.losetupcmd, "-d", self.device])
self.device = None
+ def reread_size(self):
+ if self.device is None:
+ return
+ msger.debug("Reread size %s" % self.device)
+ rc = runner.show([self.losetupcmd, "-c", self.device])
+ # XXX: (WORKAROUND) re-setup loop device when losetup isn't support '-c' option.
+ if rc != 0:
+ msger.debug("Fail to reread size, Try to re-setup loop device to reread the size of the file associated")
+ runner.show([self.losetupcmd, "-d", self.device])
+ runner.show([self.losetupcmd, self.device, self.lofile])
+
class SparseLoopbackDisk(LoopbackDisk):
"""A Disk backed by a sparse file via the loop module."""
def __init__(self, lofile, size):
@@ -345,6 +356,9 @@ class SparseLoopbackDisk(LoopbackDisk):
os.close(fd)
def create(self):
+ if self.device is not None:
+ return
+
self.expand(create = True)
LoopbackDisk.create(self)
@@ -488,6 +502,9 @@ class ExtDiskMount(DiskMount):
self.__fsck()
resize2fs(self.disk.lofile, size)
+ if size and size != os.stat(self.disk.lofile)[stat.ST_SIZE]:
+ raise MountError("Failed to resize filesystem %s to " % (self.disk.lofile, size))
+
return size
def __create(self):
@@ -502,8 +519,13 @@ class ExtDiskMount(DiskMount):
else:
self.__format_filesystem()
- def mount(self, options = None):
+ def mount(self, options = None, init_expand = False):
self.__create()
+ if init_expand:
+ expand_size = long(self.disk.size * 1.5)
+ msger.info("Initial partition size expanded : %ld -> %ld" % (self.disk.size, expand_size))
+ self.__resize_filesystem(expand_size)
+ self.disk.reread_size()
DiskMount.mount(self, options)
def __fsck(self):
@@ -599,8 +621,13 @@ class VfatDiskMount(DiskMount):
else:
self.__format_filesystem()
- def mount(self, options = None):
+ def mount(self, options = None, init_expand = False):
self.__create()
+ if init_expand:
+ expand_size = long(self.disk.size * 1.5)
+ msger.info("Initial partition size expanded : %ld -> %ld" % (self.disk.size, expand_size))
+ self.__resize_filesystem(expand_size)
+ self.disk.reread_size()
DiskMount.mount(self, options)
def __fsck(self):
@@ -702,8 +729,13 @@ class BtrfsDiskMount(DiskMount):
else:
self.__format_filesystem()
- def mount(self, options = None):
+ def mount(self, options = None, init_expand = False):
self.__create()
+ if init_expand:
+ expand_size = long(self.disk.size * 1.5)
+ msger.info("Initial partition size expanded : %ld -> %ld" % (self.disk.size, expand_size))
+ self.__resize_filesystem(expand_size)
+ self.disk.reread_size()
DiskMount.mount(self, options)
def __fsck(self):