fix invalid ExtDiskMount.blocksize when "-b [BLOCKSIZE]" extoption is passed
authorDohyung Kim <dohyung2.kim@samsung.com>
Mon, 6 Jul 2015 12:34:30 +0000 (21:34 +0900)
committerXiao Jin <jin.xiao@samsung.com>
Thu, 29 Mar 2018 14:29:24 +0000 (22:29 +0800)
To set blocksize by parsing "-b [BLOCKSIZE]" from extoptions in ks file

Change-Id: I0328cdae59a3466bde4d9a3bccb22026118544a1
Signed-off-by: Dohyung Kim <dohyung2.kim@samsung.com>
mic/utils/fs_related.py

index 9be1a10..ce3d214 100755 (executable)
@@ -18,6 +18,7 @@
 
 from __future__ import with_statement
 import os
+import re
 import sys
 import errno
 import stat
@@ -362,7 +363,7 @@ class SparseLoopbackDisk(LoopbackDisk):
         self.expand(create = True)
         LoopbackDisk.create(self)
 
-class Mount:
+class Mount(object):
     """A generic base class to deal with mounting things."""
     def __init__(self, mountdir):
         self.mountdir = mountdir
@@ -454,10 +455,25 @@ class ExtDiskMount(DiskMount):
         self.uuid = fsuuid or str(uuid.uuid4())
         self.skipformat = skipformat
         self.fsopts = fsopts
-        self.extopts = None
+        self.__extopts = None
         self.dumpe2fs = find_binary_path("dumpe2fs")
         self.tune2fs = find_binary_path("tune2fs")
 
+    def __get_extopts(self):
+        return self.__extopts
+
+    def __set_extopts(self, val):
+        if val is None:
+            self.__extopts = None
+        else:
+            m = re.search(r'-b\s*(?P<blocksize>\d+)', val)
+            if m:
+                self.blocksize = int(m.group('blocksize'))
+                val = val.replace(m.group(), '')
+            self.__extopts = val
+
+    extopts = property(__get_extopts, __set_extopts)
+
     def __parse_field(self, output, field):
         for line in output.split("\n"):
             if line.startswith(field + ":"):
@@ -473,8 +489,8 @@ class ExtDiskMount(DiskMount):
         msger.verbose("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
         cmdlist = [self.mkfscmd, "-F", "-L", self.fslabel, "-m", "1", "-b",
                    str(self.blocksize), "-U", self.uuid]
-        if self.extopts:
-            cmdlist.extend(self.extopts.split())
+        if self.__extopts:
+            cmdlist.extend(self.__extopts.split())
         cmdlist.extend([self.disk.device])
 
         rc, errout = runner.runtool(cmdlist, catch=2)
@@ -482,7 +498,7 @@ class ExtDiskMount(DiskMount):
             raise MountError("Error creating %s filesystem on disk %s:\n%s" %
                              (self.fstype, self.disk.device, errout))
 
-        if not self.extopts:
+        if not self.__extopts:
             msger.debug("Tuning filesystem on %s" % self.disk.device)
             runner.show([self.tune2fs, "-c0", "-i0", "-Odir_index", "-ouser_xattr,acl", self.disk.device])