Merge "DPM: fix bug. wrong dbus return value." into tizen submit/tizen/20180115.045329
authorJung <pr.jung@samsung.com>
Fri, 12 Jan 2018 04:35:06 +0000 (04:35 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Fri, 12 Jan 2018 04:35:06 +0000 (04:35 +0000)
packaging/storaged.spec
src/block/block.c

index 4c64e6c..41f7b93 100644 (file)
@@ -85,12 +85,6 @@ App to setup sdcard
        %define ARCH_BIT 64
 %endif
 
-%if 0%{?tizen_build_devel_mode} == 1
-%define engineer_mode on
-%else
-%define engineer_mode off
-%endif
-
 %define APP_PREFIX    "/usr/apps/org.tizen.extended-sd"
 
 %cmake . \
@@ -101,7 +95,6 @@ App to setup sdcard
        -DAPP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}" \
        -DARCH=%{ARCH} \
        -DARCH_BIT=%{ARCH_BIT} \
-       -DENGINEER_MODE=%{engineer_mode} \
        -DPROFILE=mobile \
        -DBLOCK_MODULE=on \
        -DBLOCK_TMPFS=on \
index 3df0de5..bef93ad 100644 (file)
@@ -96,6 +96,7 @@
 
 #define EXTENDEDSD_MOUNT_PATH  "/opt/extendedsd"
 
+#define VFAT_NAME              "vfat"
 #define EXT4_NAME              "ext4"
 #define LUKS_NAME              "crypto_LUKS"
 #define EXTENDEDSD_NAME                "extendedsd"
@@ -979,6 +980,9 @@ static bool pipe_cb(int fd, void *data)
                        get_operation_char(pdata.op),
                        pdata.bdev, pdata.result);
 
+       if (pdata.op == BLOCK_LUKS_CLOSE)
+               goto out;
+
        if (pdata.op == BLOCK_DEV_MOUNT && pdata.result < 0) {
                if (pdata.bdev->data->state == BLOCK_UNMOUNT) {
                        ret = change_mount_point(pdata.bdev, "");
@@ -1096,6 +1100,8 @@ static int retrieve_udev_device(struct block_data *data, bool mount_point_update
 {
        struct udev *udev;
        struct udev_device *dev;
+       const char *fs_type;
+       const char *fs_usage;
        int r;
        int wait;
 
@@ -1116,7 +1122,12 @@ static int retrieve_udev_device(struct block_data *data, bool mount_point_update
                        return -EPERM;
                }
 
-               if (!udev_device_get_property_value(dev, "ID_FS_TYPE"))
+               fs_type = udev_device_get_property_value(dev, "ID_FS_TYPE");
+               fs_usage = udev_device_get_property_value(dev, "ID_FS_USAGE");
+               /* fs_usage for crpto_LUKS is crypto */
+               if (!fs_type || (strncmp(fs_type, VFAT_NAME, strlen(VFAT_NAME)) && strncmp(fs_type, EXT4_NAME, strlen(EXT4_NAME))))
+                       sleep(1);
+               else if (!fs_usage || strncmp(FILESYSTEM_NAME, fs_usage, strlen(FILESYSTEM_NAME)))
                        sleep(1);
                else
                        break;
@@ -1604,7 +1615,7 @@ static int block_format_device(struct block_device *bdev, void *data)
 
        ret = format_block_device(bdev, fdata->fs_type, fdata->option);
        if (ret < 0)
-               _E("fail to mount block device for %s", bdev->data->devnode);
+               _E("fail to format block device for %s", bdev->data->devnode);
 
 out:
        release_format_data(fdata);
@@ -1858,7 +1869,7 @@ static void trigger_operation(struct block_device *bdev, dd_list *queue, struct
                pthread_mutex_unlock(&(th_manager[thread_id].mutex));
                /* UNLOCK */
 
-               if (operation == BLOCK_DEV_INSERT || operation == BLOCK_DEV_REMOVE) {
+               if (operation == BLOCK_DEV_INSERT || operation == BLOCK_DEV_REMOVE || operation == BLOCK_LUKS_CLOSE) {
                        if (pipe_trigger(operation, bdev, 0) < 0)
                                _E("fail to trigger pipe");
                }
@@ -2179,6 +2190,15 @@ static int add_block_device(struct udev_device *dev, const char *devnode, bool m
                return -EPERM;
        }
 
+       if (!block_control) {
+               if (!mapper && strncmp(data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) {
+                       _D("Block module is disabled");
+                       free_block_data(data);
+                       return -EPERM;
+               }
+
+       }
+
        bdev = make_block_device(data);
        if (!bdev) {
                _E("fail to make block device for %s", devnode);
@@ -2316,15 +2336,15 @@ static int remove_block_device(struct udev_device *dev, const char *devnode)
                                return ret;
                        }
 
-                       ret = add_operation(bdev_extended, BLOCK_DEV_REMOVE, NULL, NULL);
+                       ret = add_operation(bdev_extended, BLOCK_LUKS_CLOSE, NULL, NULL);
                        if (ret < 0) {
-                               _E("Failed to add operation (remove %s)", devnode);
+                               _E("Failed to add operation (luks_close %s)", devnode);
                                return ret;
                        }
 
-                       ret = add_operation(bdev_extended, BLOCK_LUKS_CLOSE, NULL, NULL);
+                       ret = add_operation(bdev_extended, BLOCK_DEV_REMOVE, NULL, NULL);
                        if (ret < 0) {
-                               _E("Failed to add operation (luks_close %s)", devnode);
+                               _E("Failed to add operation (remove %s)", devnode);
                                return ret;
                        }
                } else
@@ -2608,6 +2628,9 @@ static void remove_whole_block_device(void)
                do {
                        pthread_mutex_lock(&(th_manager[i].mutex));
                        DD_LIST_FOREACH_SAFE(th_manager[i].block_dev_list, elem, next, bdev) {
+                               if (bdev->data->block_type == BLOCK_EXTENDEDSD_DEV ||
+                                   !strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME)))
+                                       continue;
                                if (bdev->removed == false)
                                        break;
                        }
@@ -2646,10 +2669,10 @@ static void booting_done(const char *sender_name,
        if (ret < 0)
                _E("fail to register block uevent : %d", ret);
 
+       block_control = true;
        /* if there is the attached device, try to mount */
        block_init_from_udev_enumerate();
 
-       block_control = true;
        block_boot = true;
 }
 
@@ -2740,6 +2763,8 @@ static void uevent_block_handler(struct udev_device *dev)
                        _E("fail to update block data for %s", bdev->data->devnode);
                if (!strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME)))
                        _I("filesystem type is updated: crypto_LUKS");
+               if (bdev->data->fs_usage)
+                       _I("fs_usage: %s", bdev->data->fs_usage);
        }
 }
 
@@ -2751,6 +2776,12 @@ static DBusMessage *request_mount_block(dbus_method_reply_handle_h reply_handle,
        int id;
        int ret = -EBADMSG;
 
+       if (!block_control) {
+               _D("Block module is disabled");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (!reply_handle || !msg)
                goto out;
 
@@ -2767,6 +2798,14 @@ static DBusMessage *request_mount_block(dbus_method_reply_handle_h reply_handle,
                ret = -ENOENT;
                goto out;
        }
+
+       if (bdev->data->block_type == BLOCK_EXTENDEDSD_DEV ||
+           !strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) {
+               _D("Mount dbus request for extended internal storage is blocked");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (bdev->on_private_op != REQ_NORMAL) {
                ret = -EPERM;
                goto out;
@@ -2838,6 +2877,12 @@ static DBusMessage *request_unmount_block(dbus_method_reply_handle_h reply_handl
        int id;
        int ret = -EBADMSG;
 
+       if (!block_control) {
+               _D("Block module is disabled");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (!reply_handle || !msg)
                goto out;
 
@@ -2855,6 +2900,13 @@ static DBusMessage *request_unmount_block(dbus_method_reply_handle_h reply_handl
                goto out;
        }
 
+       /* Unmount dbus call is needed when app proceeds extended internal -> portable storage */
+       if (!strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) {
+               _D("Unmount dbus request for extended internal storage is blocked");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (onprivate) {
                pid = get_dbus_method_sender_pid(reply_handle);
                if (bdev->on_private_op == REQ_NORMAL || (bdev->on_private_op != REQ_NORMAL && pid != bdev->private_pid)) {
@@ -2911,6 +2963,12 @@ static DBusMessage *request_format_block(dbus_method_reply_handle_h reply_handle
        int ret = -EBADMSG;
        int prev_state;
 
+       if (!block_control) {
+               _D("Block module is disabled");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (!reply_handle || !msg)
                goto out;
 
@@ -2927,6 +2985,13 @@ static DBusMessage *request_format_block(dbus_method_reply_handle_h reply_handle
                goto out;
        }
 
+       if (bdev->data->block_type == BLOCK_EXTENDEDSD_DEV ||
+           !strncmp(bdev->data->fs_type, LUKS_NAME, strlen(LUKS_NAME))) {
+               _D("Format dbus request for extended internal storage is blocked");
+               ret = -EPERM;
+               goto out;
+       }
+
        pid = get_dbus_method_sender_pid(reply_handle);
        if (bdev->on_private_op != REQ_NORMAL && pid != bdev->private_pid) {
                _E("Failed to format on private state");
@@ -2986,6 +3051,12 @@ static DBusMessage *request_format_block_type(dbus_method_reply_handle_h reply_h
        int ret = -EBADMSG;
        int prev_state;
 
+       if (!block_control) {
+               _D("Block module is disabled");
+               ret = -EPERM;
+               goto out;
+       }
+
        if (!reply_handle || !msg)
                goto out;
 
@@ -3003,6 +3074,13 @@ static DBusMessage *request_format_block_type(dbus_method_reply_handle_h reply_h
                goto out;
        }
 
+       /* FormatwithType dbus call is needed when app proceeds extended internal -> portable storage */
+       if (bdev->data->block_type == BLOCK_EXTENDEDSD_DEV) {
+               _D("FormatwithType dbus request for extended internal storage is blocked");
+               ret = -EPERM;
+               goto out;
+       }
+
        pid = get_dbus_method_sender_pid(reply_handle);
        if (bdev->on_private_op != REQ_NORMAL && pid != bdev->private_pid) {
                _E("Failed to format on private state");
@@ -3747,8 +3825,6 @@ static void block_exit(void *data)
 
 static int block_start(void *data)
 {
-       int ret;
-
        if (!block_boot) {
                _E("Cannot be started. Booting is not ready");
                return -ENODEV;
@@ -3759,15 +3835,10 @@ static int block_start(void *data)
                return 0;
        }
 
-       /* register mmc uevent control routine */
-       ret = register_udev_uevent_control(&uh);
-       if (ret < 0)
-               _E("fail to register block uevent : %d", ret);
+       block_control = true;
 
        block_init_from_udev_enumerate();
 
-       block_control = true;
-
        _I("start");
        return 0;
 }
@@ -3784,9 +3855,6 @@ static int block_stop(void *data)
                return 0;
        }
 
-       /* unregister mmc uevent control routine */
-       unregister_udev_uevent_control(&uh);
-
        /* remove the existing blocks */
        remove_whole_block_device();