Support f2fs option and check if kernel support f2s 80/251580/2
authorbiao716.wang <biao716.wang@samsung.com>
Fri, 15 Jan 2021 08:18:39 +0000 (17:18 +0900)
committerbiao716.wang <biao716.wang@samsung.com>
Fri, 15 Jan 2021 08:30:18 +0000 (17:30 +0900)
Change-Id: I785462a0f4a6a81c4ad45451dd010686e88aeed6
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
mic/imager/loop.py
mic/kickstart/custom_commands/partition.py
mic/utils/fs_related.py

index a46d0ab51c94817b19b4ec6bc3be80f01101d2ec..3d128db9df9b651234e0ed5017df1bb2bddabbde 100644 (file)
@@ -167,6 +167,7 @@ class LoopImageCreator(BaseImageCreator):
                     'fsopts': part.fsopts or None,
                     'aft_fstype': aft_fstype or None,
                     'extopts': part.extopts or None,
+                    'f2fsopts': part.f2fsopts or None,
                     'vdfsopts': part.vdfsopts or None,
                     'squashfsopts': part.squashfsopts or None,
                     'cpioopts': part.cpioopts or None,
@@ -354,6 +355,7 @@ class LoopImageCreator(BaseImageCreator):
                  "name": imgname,
                  "size": self.__image_size or 4096,
                  "fstype": self.__fstype or "ext3",
+                 "f2fsopts": None,
                  "extopts": None,
                  "loop": None,
                  "uuid": None,
@@ -393,6 +395,8 @@ class LoopImageCreator(BaseImageCreator):
 
             if fstype in ("ext2", "ext3", "ext4"):
                 loop['loop'].extopts = loop['extopts']
+            elif fstype == "f2fs":
+                loop['loop'].f2fsopts = loop['f2fsopts']
 
             try:
                 msger.verbose('Mounting image "%s" on "%s"' % (imgname, mp))
index 341e8dc4b4925f8a5d683ba5bd0422600ad52b71..ae271e2f30d710cc9d13be1c38147f980a44b5f5 100755 (executable)
@@ -26,6 +26,7 @@ class Mic_PartData(FC4_PartData):
         self.deleteRemovedAttrs()
         self.align = kwargs.get("align", None)
         self.extopts = kwargs.get("extopts", None)
+        self.f2fsopts = kwargs.get("f2fsopts", None)
         self.part_type = kwargs.get("part_type", None)
         self.uuid = kwargs.get("uuid", None)
         self.exclude_image = kwargs.get("exclude_from_image", False)
@@ -42,6 +43,8 @@ class Mic_PartData(FC4_PartData):
             retval += " --align"
         if self.extopts:
             retval += " --extoptions=%s" % self.extopts
+        if self.f2fsopts:
+            retval += " --f2fsoptions=%s" % self.f2fsopts
         if self.part_type:
             retval += " --part-type=%s" % self.part_type
         if self.uuid:
@@ -72,6 +75,8 @@ class Mic_Partition(FC4_Partition):
                       default=None)
         op.add_option("--extoptions", type="string", action="store", dest="extopts",
                       default=None)
+        op.add_option("--f2fsoptions", type="string", action="store", dest="f2fsopts",
+                      default=None)
         op.add_option("--part-type", type="string", action="store", dest="part_type",
                       default=None)
         op.add_option("--uuid", dest="uuid", action="store", type="string")
index 5ddae6b08b9ca7d919e4bc3dc618d88147598eee..9e2e2c39b3a68993f1421ecef501a1bb63915abc 100755 (executable)
@@ -449,19 +449,46 @@ class DiskMount(Mount):
 class F2fsDiskMount(DiskMount):
     """A DiskMount object that is able to format/resize f2fs filesystems."""
     def __init__(self, disk, mountdir, fstype, blocksize, fslabel, rmmountdir=True, skipformat = False, fsopts = None, fsuuid=None):
+        self.__check_f2fs()
         DiskMount.__init__(self, disk, mountdir, fstype, rmmountdir)
         self.blocksize = blocksize
         self.fslabel = fslabel.replace("/", "")
-        self.uuid = fsuuid or str(uuid.uuid4())
+        self.uuid = fsuuid or None
         self.skipformat = skipformat
         self.fsopts = fsopts
-        self.__extopts = None
+        self.__f2fsopts = None
+        self.blkidcmd = find_binary_path("blkid")
         self.dumpe2fs = find_binary_path("dump." + self.fstype)
         self.fsckcmd = find_binary_path("fsck." + self.fstype)
         self.resizecmd = find_binary_path("resize." + self.fstype)
 
+    def __get_f2fsopts(self):
+        return self.__f2f2opts
+
+    def __set_f2fsopts(self, val):
+        if val is None:
+            self.__f2fsopts = None
+        else:
+            self.__f2fsopts = val
+    f2fsopts = property(__get_f2fsopts, __set_f2fsopts)
+
+    def __check_f2fs(self):
+        found = False
+        """ Need to load f2fs module to mount it """
+        load_module("f2fs")
+        for line in open("/proc/filesystems").xreadlines():
+            if line.find("f2fs") > -1:
+                found = True
+                break
+        if not found:
+            raise MountError("Your system can't mount f2fs filesystem, please make sure your kernel has f2fs support and the module f2fs.ko has been loaded.")
+
     def __parse_field(self, output, field):
-        return
+        for line in output.split(" "):
+            if line.startswith(field + "="):
+                return line[len(field) + 1:].strip().replace("\"", "")
+
+        raise KeyError("Failed to find field '%s' in output" % field)
 
     def __format_filesystem(self):
         if self.skipformat:
@@ -469,9 +496,18 @@ class F2fsDiskMount(DiskMount):
             return
 
         msger.verbose("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
-        rc = runner.show([self.mkfscmd, "-l", self.fslabel, self.disk.device])
+
+        cmdlist = [self.mkfscmd, "-l", self.fslabel]
+        if self.__f2fsopts:
+            cmdlist.extend(self.__f2fsopts.split())
+        cmdlist.extend([self.disk.device])
+
+        rc, errout = runner.runtool(cmdlist, catch=2)
         if rc != 0:
-            raise MountError("Error creating %s filesystem on disk %s" % (self.fstype,self.disk.device))
+            raise MountError("Error creating %s filesystem on disk %s:\n%s" %
+                             (self.fstype, self.disk.device, errout))
+
+        self.uuid = self.__parse_field(runner.outs([self.blkidcmd, self.disk.device]), "UUID")
 
     def __resize_filesystem(self, size = None):
         msger.info("Resizing filesystem ...")