hds: supports multiple hds connection
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Mon, 4 May 2015 05:44:40 +0000 (14:44 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Fri, 8 May 2015 06:59:03 +0000 (15:59 +0900)
- moved the directory(/mnt/host) creation from system-plugin-emulator

Change-Id: I4fe946331f4285647a94041aeac67686a38c0ec6
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
include/emuld.h
packaging/emuld.spec
src/common.cpp
src/emuld.cpp

index 73b2bdd21e4abb0bde0b73cd427652397bcca335..3d7057892b3e7799830c87e15c2352fe3eafc220 100644 (file)
@@ -194,6 +194,10 @@ void* dbus_booting_done_check(void* data);
 void systemcall(const char* param);
 int parse_val(char *buff, unsigned char data, char *parsbuf);
 
+#define HDS_DEFAULT_TAG     "fileshare"
+#define HDS_DEFAULT_PATH    "/mnt/host"
+int try_mount(char* tag, char* path);
+
 #define IJTYPE_SUSPEND      "suspend"
 #define IJTYPE_HDS          "hds"
 #define IJTYPE_SYSTEM       "system"
@@ -202,14 +206,14 @@ int parse_val(char *buff, unsigned char data, char *parsbuf);
 #define IJTYPE_PACKAGE      "package"
 #define IJTYPE_BOOT         "boot"
 #define IJTYPE_VCONF        "vconf"
+#define IJTYPE_LOCATION     "location"
+#define IJTYPE_SDCARD       "sdcard"
 
 void msgproc_suspend(ijcommand* ijcmd);
 void msgproc_system(ijcommand* ijcmd);
 void msgproc_package(ijcommand* ijcmd);
 void msgproc_hds(ijcommand* ijcmd);
-#define IJTYPE_LOCATION     "location"
 void msgproc_location(ijcommand* ijcmd);
-#define IJTYPE_SDCARD       "sdcard"
 void msgproc_sdcard(ijcommand* ijcmd);
 void* exec_cmd_thread(void *args);
 void msgproc_cmd(ijcommand* ijcmd);
index 3d3185c42d3ca4859fcbf6fc52894fafa4adf148..37496580a98dc7cc0d3aeecfe6cbf49d81704342 100644 (file)
@@ -42,6 +42,7 @@ make
 %install
 rm -rf %{buildroot}
 
+# for systemd
 if [ ! -d %{buildroot}/usr/lib/systemd/system/emulator.target.wants ]; then
     mkdir -p %{buildroot}/usr/lib/systemd/system/emulator.target.wants
 fi
@@ -49,6 +50,10 @@ fi
 cp emuld.service %{buildroot}/usr/lib/systemd/system/.
 ln -s ../emuld.service %{buildroot}/usr/lib/systemd/system/emulator.target.wants/emuld.service
 
+# for host file sharing
+mkdir -p %{buildroot}/mnt/host
+
+# for license
 mkdir -p %{buildroot}/usr/share/license
 cp LICENSE %{buildroot}/usr/share/license/%{name}
 
@@ -72,5 +77,6 @@ chmod 770 %{_prefix}/bin/emuld
 /usr/share/license/%{name}
 /usr/lib/systemd/system/emuld.service
 /usr/lib/systemd/system/emulator.target.wants/emuld.service
+%dir /mnt/host
 
 %changelog
index 05bd34d4fa49f23399165e2e3e798509646efb48..4072de4e1a427c5bda5e74928aec1685c4a15b7b 100644 (file)
@@ -56,6 +56,7 @@
 #define SUSPEND_LOCK        1
 
 #define MAX_PKGS_BUF        1024
+#define MAX_DATA_BUF        1024
 
 #define PATH_PACKAGE_INSTALL    "/opt/usr/apps/tmp/sdk_tools/"
 #define RPM_CMD_QUERY       "-q"
@@ -1292,22 +1293,62 @@ static char* make_header_msg(int group, int action)
 
 #define MSG_GROUP_HDS   100
 
-void* mount_hds(void* data)
+int try_mount(char* tag, char* path)
+{
+    int ret = 0;
+
+    ret = mount(tag, path, "9p", 0,
+                "trans=virtio,version=9p2000.L,msize=65536");
+    if (ret == -1)
+        return errno;
+
+    return ret;
+}
+
+static bool get_tag_path(char* data, char** tag, char** path)
+{
+    char token[] = "\n";
+
+    LOGINFO("get_tag_path data : %s", data);
+    *tag = strtok(data, token);
+    if (*tag == NULL) {
+        LOGERR("data does not have a correct tag: %s", data);
+        return false;
+    }
+
+    *path = strtok(NULL, token);
+    if (*path == NULL) {
+        LOGERR("data does not have a correct path: %s", data);
+        return false;
+    }
+
+    return true;
+}
+
+static void* mount_hds(void* args)
 {
     int i, ret = 0;
     char* tmp;
-    int group, action;
+    int action = 2;
+    char* tag;
+    char* path;
+    char* data = (char*)args;
 
     LOGINFO("start hds mount thread");
 
     pthread_detach(pthread_self());
 
-    usleep(500000);
+    if (!get_tag_path(data, &tag, &path)) {
+        free(data);
+        return NULL;
+    }
+
+    LOGINFO("tag : %s, path: %s", tag, path);
+    usleep(50000);
 
     for (i = 0; i < 20; i++)
     {
-        ret = mount("fileshare", "/mnt/host", "9p", 0,
-                    "trans=virtio,version=9p2000.L,msize=65536");
+        ret = try_mount(tag, path);
         if(ret == 0) {
             action = 1;
             break;
@@ -1317,71 +1358,95 @@ void* mount_hds(void* data)
         usleep(500000);
     }
 
-    group = MSG_GROUP_HDS;
-
-    if (i == 20 || ret != 0)
-        action = 2;
-
-    tmp = make_header_msg(group, action);
+    tmp = make_header_msg(MSG_GROUP_HDS, action);
     if (!tmp) {
         LOGERR("failed to alloc: out of resource.");
-        pthread_exit((void *) 0);
+        free(data);
         return NULL;
     }
 
     ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_HDS, (const char*) tmp, HEADER_SIZE);
 
+    free(data);
     free(tmp);
 
-    pthread_exit((void *) 0);
+    return NULL;
 }
 
-int umount_hds(void)
+static void* umount_hds(void* args)
 {
     int ret = 0;
     char* tmp;
-    int group, action;
+    int action = 3;
+    char* tag;
+    char* path;
+    char* data = (char*)args;
 
-    pthread_cancel(tid[TID_HDS]);
+    LOGINFO("unmount hds.");
+    pthread_detach(pthread_self());
 
-    LOGINFO("unmount /mnt/host.");
+    if (!get_tag_path(data, &tag, &path)) {
+        LOGERR("wrong tag or path.");
+        free(data);
+        return NULL;
+    }
 
-    ret = umount("/mnt/host");
+    ret = umount(path);
     if (ret != 0) {
         LOGERR("unmount failed with error num: %d", errno);
         action = 4;
-    } else {
-        action = 3;
     }
 
-    group = MSG_GROUP_HDS;
-
-    tmp = make_header_msg(group, action);
+    tmp = make_header_msg(MSG_GROUP_HDS, action);
     if (!tmp) {
         LOGERR("failed to alloc: out of resource.");
-        return -1;
+        free(data);
+        return NULL;
     }
 
     LOGINFO("send result with action %d to evdi", action);
 
     ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_HDS, (const char*) tmp, HEADER_SIZE);
 
+    free(data);
     free(tmp);
 
-    return 0;
+    return NULL;
 }
 
+#define COMPAT_DEFAULT_DATA     "fileshare\n/mnt/host\n"
 void msgproc_hds(ijcommand* ijcmd)
 {
+    char* data;
     LOGDEBUG("msgproc_hds");
 
+    if (!strncmp(ijcmd->data, HDS_DEFAULT_PATH, 9)) {
+        LOGINFO("hds compatibility mode with %s", ijcmd->data);
+        data = strdup(COMPAT_DEFAULT_DATA);
+    } else {
+        data = strdup(ijcmd->data);
+    }
+
+    if (data == NULL) {
+        LOGERR("data dup is failed. out of memory.");
+        return;
+    }
+
+    LOGINFO("action: %d, data: %s", ijcmd->msg.action, data);
     if (ijcmd->msg.action == 1) {
-        if (pthread_create(&tid[TID_HDS], NULL, mount_hds, NULL) != 0)
+        if (pthread_create(&tid[TID_HDS], NULL, mount_hds, (void*)data) != 0) {
             LOGERR("mount hds pthread create fail!");
+            free(data);
+        }
     } else if (ijcmd->msg.action == 2) {
-        umount_hds();
+        pthread_cancel(tid[TID_HDS]);
+        if (pthread_create(&tid[TID_HDS], NULL, umount_hds, (void*)data) != 0) {
+            LOGERR("umount hds pthread create fail!");
+            free(data);
+        }
     } else {
         LOGERR("unknown action cmd.");
+        free(data);
     }
 }
 
index c7122fd514a28495c9ca72451b2bc0a90d656c64..6905e5770b2a55eb47f5090d26f3e4480642e374 100644 (file)
@@ -341,6 +341,8 @@ static bool server_process(void)
 
 int main( int argc , char *argv[])
 {
+    int ret = 0;
+
     init_fd();
 
     if (!epoll_init())
@@ -370,6 +372,9 @@ int main( int argc , char *argv[])
 
     send_default_suspend_req();
 
+    ret = try_mount((char*)HDS_DEFAULT_TAG, (char*)HDS_DEFAULT_PATH);
+    LOGINFO("try mount /mnt/host for default fileshare: %d", ret);
+
     while(!exit_flag)
     {
         exit_flag = server_process();