Support /dev/mapper/rootfs root device 46/258146/8
authorINSUN PYO <insun.pyo@samsung.com>
Tue, 11 May 2021 07:50:27 +0000 (16:50 +0900)
committerINSUN PYO <insun.pyo@samsung.com>
Wed, 12 May 2021 05:59:38 +0000 (14:59 +0900)
Root device is /dev/mapper/rootfs on RPI4 with dm-verity.

So, the actual root device is not correctly found,
and /dev/mmcblk0 is not recognized as an internal device.

Storaged recognizes the partitions of /dev/mmcblk0p* as external devices,
and storaged mounts them to /opt/media/SDCard@*.

///////////////////////////////////////////////////////////////////
/dev/mmcblk0p1     65390  20830   44560  32% /opt/media/SDCard@1
/dev/mmcblk0p10    59365   1299   53480   3% /opt/media/SDCard@10
/dev/mmcblk0p11   120355   1555  109805   2% /opt/media/SDCard@11
///////////////////////////////////////////////////////////////////

Change-Id: I42f211684e519371a23ee0b403bd3d941d243bb0

packaging/storaged.spec
src/block/CMakeLists.txt
src/block/block.c

index c32783d..2d3ad40 100644 (file)
@@ -29,6 +29,7 @@ BuildRequires:  pkgconfig(blkid)
 BuildRequires:  pkgconfig(mount)
 BuildRequires:  pkgconfig(libsyscommon)
 BuildRequires:  pkgconfig(json-c)
+BuildRequires:  pkgconfig(devmapper)
 
 BuildRequires:  pkgconfig(capi-ui-efl-util)
 BuildRequires:  pkgconfig(capi-appfw-application)
index 8346018..f72f5e3 100644 (file)
@@ -17,6 +17,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST}
                vconf
                capi-system-device
                libsyscommon
+               devmapper
    )
 
 IF(EXTENDED_STORAGE)
index c796b1b..878729f 100644 (file)
@@ -49,6 +49,8 @@
 #ifdef EXTENDED_STORAGE
 #include <ode/luks.h>
 #endif
+#include <linux/kdev_t.h>
+#include <libdevmapper.h>
 
 #include "log.h"
 #include "module-intf.h"
 #include "apps.h"
 #include "storaged_common.h"
 
-/**
- * TODO  Assume root device is always mmcblk0*.
- */
 #define MMC_PATH                     "*/mmcblk[0-9]*"
 #define MMC_PARTITION_PATH           "mmcblk[0-9]p[0-9]"
 /* Emulator send devlink for sdcard as \*\/sdcard\/\* */
 #define MMC_LINK_PATH                "*/sdcard/*"
+#define MMC_LINK_PARTITION_PATH     "vd[a-z][0-9]"
 #define SCSI_PATH                    "*/sd[a-z]*"
 #define SCSI_PARTITION_PATH          "sd[a-z][0-9]"
 #define SCSI_PARTITION_LENGTH        9
 #define EXTENDEDSD_NODE_PATH         "/dev/mapper/extendedsd"
+#define DEVICE_MAPPER_ROOT_NODE_PATH "/dev/mapper/rootfs"
 
 #define FILESYSTEM_NAME              "filesystem"
 
@@ -2395,6 +2396,58 @@ static int remove_block_device(struct udev_device *dev, const char *devnode)
        return 0;
 }
 
+static void get_internal_storage_number_from_device_mapper(char *root_name)
+{
+       int major, minor;
+       char dev_name[PATH_MAX];
+       struct dm_task *dmt;
+       struct dm_info info;
+       struct dm_deps *deps;
+
+       _D("Searching device mapper root device: %s", DEVICE_MAPPER_ROOT_NODE_PATH);
+
+       if (!root_name)
+               return;
+
+       dmt = dm_task_create(DM_DEVICE_DEPS);
+       if (!dmt)
+               return;
+
+       if (!dm_task_set_name(dmt, root_name))
+               goto out;
+
+       if (!dm_task_run(dmt))
+               goto out;
+
+       if (!dm_task_get_info(dmt, &info) || !info.exists)
+               goto out;
+
+       deps = dm_task_get_deps(dmt);
+       if (!deps || deps->count != 1)
+               goto out;
+
+       major = (int) MAJOR(deps->device[0]);
+       minor = (int) MINOR(deps->device[0]);
+
+       if (!dm_device_get_name(major, minor, 1, dev_name, PATH_MAX))
+               goto out;
+
+       /* Ex: dev_name is mmcblk0p2 */
+       _D("Found actual device associated with root device of device mapper: %s", dev_name);
+
+       if (!is_emulator()) {
+               if (!fnmatch(MMC_PARTITION_PATH, dev_name, 0))
+                       sscanf(dev_name, "mmcblk%d", &dev_internal);
+               else if (!fnmatch(SCSI_PARTITION_PATH, dev_name, 0))
+                       sscanf(dev_name, "sd%c", &dev_internal_scsi);
+       } else
+               if (!fnmatch(MMC_LINK_PARTITION_PATH, dev_name, 0))
+                       sscanf(dev_name, "vd%c", &dev_internal_emul);
+
+out:
+       dm_task_destroy(dmt);
+}
+
 static int get_internal_storage_number(void)
 {
        struct libmnt_table *t = NULL;
@@ -2437,7 +2490,9 @@ static int get_internal_storage_number(void)
        name++;
 
        /* Boot from USB is not handled */
-       if (!is_emulator()) {
+       if (!strcmp(temp, DEVICE_MAPPER_ROOT_NODE_PATH))
+               get_internal_storage_number_from_device_mapper(name);
+       else if (!is_emulator()) {
                if (!fnmatch(MMC_PATH, temp, 0))
                        sscanf(name, "mmcblk%d", &dev_internal);
                else if (!fnmatch(SCSI_PATH, temp, 0))
@@ -2492,6 +2547,8 @@ static int check_external_storage(const char* devnode)
                }
        }
 
+       _D("%s is external storage.", devnode);
+
        return 1;
 }