hds: enable the multi hds feature
authorSooyoung Ha <yoosah.ha@samsung.com>
Wed, 3 Jun 2015 07:44:22 +0000 (16:44 +0900)
committerSooyoung Ha <yoosah.ha@samsung.com>
Wed, 3 Jun 2015 07:44:22 +0000 (16:44 +0900)
Change-Id: If7a36f186918f09601d9f8b5264ec1972a44fe62
Signed-off-by: Sooyoung Ha <yoosah.ha@samsung.com>
hw/9pfs/virtio-9p-device.c
tizen/src/ecs/ecs_msg_device.c
tizen/src/ecs/ecs_msg_injector.c
tizen/src/emul_state.c
tizen/src/emul_state.h
tizen/src/util/Makefile.objs
tizen/src/util/hds.c [new file with mode: 0644]
tizen/src/util/hds.h [new file with mode: 0644]
tizen/src/util/maru_device_hotplug.c
tizen/src/util/maru_device_hotplug.h

index 0ff4812..99cddf1 100644 (file)
@@ -23,7 +23,6 @@
 
 #ifdef CONFIG_MARU
 #include "tizen/src/util/maru_err_table.h"
-#include "tizen/src/emul_state.h"
 #endif
 
 static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features)
@@ -160,11 +159,6 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
         goto out;
     }
 
-#ifdef CONFIG_MARU
-    set_emul_hds_attached(true);
-    set_emul_hds_path(fse->path);
-#endif
-
     v9fs_path_free(&path);
 
     return;
index 1bb46ed..1311c82 100644 (file)
@@ -41,6 +41,7 @@
 #include "skin/maruskin_server.h"
 
 #include "util/maru_device_hotplug.h"
+#include "util/hds.h"
 #include "emul_state.h"
 #include "ecs.h"
 #include "debug_ch.h"
@@ -321,6 +322,7 @@ static void msgproc_device_req_nfc(ECS_Client* ccli, ECS__DeviceReq* msg)
 
 static void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char * cmd)
 {
+    int len = 0;
     char* data = NULL;
     char token[] = "\n";
     type_group group = (type_group) (msg->group & 0xff);
@@ -334,20 +336,10 @@ static void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char *
 
     LOG_INFO("hds group: %d, action : %d\n", group, action);
     if (group == MSG_GROUP_STATUS) {
-        char hds_data_send[PATH_MAX + 3];
-        if (is_hds_attached()) {
-            char* guest_path = get_emul_hds_guest_path();
-            if (strlen(guest_path) == 0) {
-                set_emul_hds_guest_path("/mnt/host");
-                guest_path = get_emul_hds_guest_path();
-            }
-            sprintf(hds_data_send, "1, %s, %s", get_emul_hds_path(), guest_path);
-        } else {
-            sprintf(hds_data_send, "0, ");
-        }
-        make_send_device_ntf(cmd, group, 99, hds_data_send);
+        data = get_hds_lists();
+        LOG_INFO("hds status: %s\n", data);
+        make_send_device_ntf(cmd, group, 99, data);
     } else if (group == MSG_GROUP_HDS && action == HDS_ACTION_MOUNT) {
-        LOG_INFO("try attach with is_hds_attached : %d\n", is_hds_attached());
         char *host = strtok(data, token);
         if (host == NULL) {
             make_send_device_ntf(cmd, group, 2, NULL);
@@ -359,25 +351,25 @@ static void msgproc_device_req_hds(ECS_Client* ccli, ECS__DeviceReq* msg, char *
             goto hds_free;
         }
 
-        if (!is_hds_attached()) {
-            LOG_INFO("do attach host: %s\n", host);
-            do_hotplug(ATTACH_HDS, host, strlen(host) + 1);
-            LOG_INFO("send emuld to mount: %s, %d.\n", guest, strlen(guest));
-            set_emul_hds_guest_path(guest);
-            send_msg_to_guest(cmd, group, action, guest, strlen(guest) + 1);
+        char* hds_id = new_hds_list(host, guest);
+        if (hds_id != NULL) {
+            LOG_INFO("do attach tag: %s, host: %s, guest: %s\n", hds_id, host, guest);
+            do_hotplug(ATTACH_HDS, hds_id, strlen(hds_id) + 1);
         } else {
             make_send_device_ntf(cmd, group, 2, NULL);
         }
     } else if (group == MSG_GROUP_HDS && action == HDS_ACTION_UMOUNT) {
-        LOG_INFO("try detach with is_hds_attached : %d\n", is_hds_attached());
-        if (is_hds_attached()) {
-            char* guest_path = get_emul_hds_guest_path();
+        LOG_INFO("try detach with is_hds_attached : %s, %d\n", data, is_hds_attached(data));
+        if (is_hds_attached(data)) {
+            char emuld_data [OUT_BUF_SIZE];
+            char* guest_path = get_guest_path_by_id(data);
             if (strlen(guest_path) == 0) {
-                set_emul_hds_guest_path("/mnt/host");
-                guest_path = get_emul_hds_guest_path();
+                LOG_SEVERE("hds guest path is empty.\n");
+                return;
             }
-            LOG_INFO("send emuld to umount.%s\n", guest_path);
-            send_msg_to_guest(cmd, group, action, guest_path, strlen(guest_path) + 1);
+            len = snprintf(emuld_data, sizeof(emuld_data), "%s\n%s\n", data, guest_path);
+            LOG_INFO("send emuld to umount.%s\n", emuld_data);
+            send_msg_to_guest(cmd, group, action, emuld_data, len + 1);
         } else {
             LOG_INFO("hds is not attached. do not try detach it.\n");
             make_send_device_ntf(cmd, group, 4, NULL);
index 16d5fd2..422ade3 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 
 #include "qemu-common.h"
+#include "fsdev/qemu-fsdev.h"
 
 #include "hw/virtio/maru_virtio_vmodem.h"
 #include "hw/virtio/maru_virtio_evdi.h"
@@ -38,6 +39,7 @@
 #include "hw/virtio/maru_virtio_power.h"
 
 #include "util/maru_device_hotplug.h"
+#include "util/hds.h"
 #include "emul_state.h"
 #include "ecs.h"
 #include "debug_ch.h"
@@ -53,6 +55,7 @@ MULTI_DEBUG_CHANNEL(qemu, ecs);
 #define SLEEP_CONNECT_SDB   1000 // ms
 
 static QemuThread sdb_thread_id;
+static QemuThread hds_thread_id;
 
 extern QemuMutex mutex_location_data;
 static char location_data[MAX_INJECTOR_REQ_DATA];
@@ -567,24 +570,137 @@ void ecs_suspend_lock_state(int state)
     msgproc_injector_req(NULL, &msg);
 }
 
+static void send_hds_mount_request(char* list)
+{
+    int len = 0;
+    char token[] = ",";
+    char emuld_data [OUT_BUF_SIZE];
+    char* id;
+    char* host;
+    char* guest;
+
+    LOG_INFO("handling mount request: %s\n", list);
+
+    id = strtok(list, token);
+    if (id == NULL) {
+        LOG_SEVERE("cannot send mount request because of id\n");
+        return;
+    }
+
+    host = strtok(NULL, token);
+    if (host == NULL) {
+        LOG_SEVERE("cannot send mount request because of host\n");
+        return;
+    }
+
+    guest = strtok(NULL, token);
+    if (guest == NULL) {
+        LOG_SEVERE("cannot send mount request because of guest\n");
+        return;
+    }
+
+    len = snprintf(emuld_data, sizeof(emuld_data), "%s\n%s\n", id, guest);
+    send_msg_to_guest(MSG_TYPE_HDS, MSG_GROUP_HDS, HDS_ACTION_MOUNT, emuld_data, len + 1);
+}
+
+static void* hds_mount_request_thread(void* args)
+{
+    char* list = (char*)args;
+    char token[] = "\n";
+    char* hds_list;
+
+    hds_list = strtok(list, token);
+    if (hds_list == NULL) {
+        LOG_INFO("no hds mount request\n");
+        free(list);
+        return NULL;
+    }
+
+    send_hds_mount_request(hds_list);
+
+    while((hds_list = strtok(NULL, token)) != NULL) {
+        send_hds_mount_request(hds_list);
+    }
+
+    free(list);
+    return NULL;
+}
+
 #define MSG_GROUP_HDS   100
-static void do_hds(char* cat, type_action action)
+#define DEFAULT_STATIC_HDS_ID   "fsdef0"
+static void do_hds(char* cat, type_action action, const char* data)
 {
-    INFO("hds status is %d\n", action);
+    FsDriverEntry *entry;
+    char msg [OUT_BUF_SIZE];
+    char *host;
+    char *guest;
+    char* list;
+
+    INFO("hds status is %d, %s\n", action, data);
     switch (action) {
-        case 1:
-            make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
+        case 0: // get list from devices
+            list = get_hds_lists();
+            if (strlen(list) == 0) {
+                LOG_INFO("none of mount candidates available.\n");
+                break;
+            }
+            qemu_thread_create(&hds_thread_id, "hds_mount", hds_mount_request_thread, (void*)list, QEMU_THREAD_DETACHED);
+            break;
+        case 99: // add list for default hds
+            entry = get_fsdev_fsentry((char*)DEFAULT_STATIC_HDS_ID);
+            if (entry == NULL) {
+                LOG_SEVERE("cannot find fsdev entry.\n");
+                break;
+            }
+
+            if (!add_hds_list(DEFAULT_STATIC_HDS_ID, entry->path, DEFAULT_HDS_GUEST_PATH)) {
+                LOG_SEVERE("cannot add into hds list.\n");
+                break;
+            }
+
+            set_hds_attached(DEFAULT_STATIC_HDS_ID, true);
+            data = DEFAULT_STATIC_HDS_ID;
+
+            // pass-through
+        case 1: // mount success
+            if (data == NULL) {
+                LOG_SEVERE("error: hds data is null.\n");
+                break;
+            }
+            host = get_host_path_by_id((char*)data);
+            if (host == NULL)
+                LOG_SEVERE("get_host_path_by_id failed with %s, %s\n", data, host);
+            guest = get_guest_path_by_id((char*)data);
+            if (guest == NULL)
+                LOG_SEVERE("get_guest_path_by_id failed with %s, %s\n", data, guest);
+            snprintf(msg, sizeof(msg), "%s,%s,%s", data, host, guest);
+            make_send_device_ntf(cat, MSG_GROUP_HDS, action, msg);
             break;
-        case 2:
-            do_hotplug(DETACH_HDS, NULL, 0);
-            make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
+        case 2: // mount failed.
+        case 11: // not exist on the possible path
+        case 12: // not a vaild path
+            if (data == NULL) {
+                LOG_SEVERE("error: hds data is null.\n");
+                break;
+            }
+            remove_hds_list((char*)data);
+            do_hotplug(DETACH_HDS, (char*)data, strlen(data) + 1);
+            make_send_device_ntf(cat, MSG_GROUP_HDS, action, (char*)data);
             break;
-        case 3:
-            do_hotplug(DETACH_HDS, NULL, 0);
-            make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
+        case 3: // unmount success
+            if (data == NULL) {
+                LOG_SEVERE("error: hds data is null.\n");
+                break;
+            }
+            do_hotplug(DETACH_HDS, (char*)data, strlen(data) + 1);
+            make_send_device_ntf(cat, MSG_GROUP_HDS, action, (char*)data);
             break;
-        case 4:
-            make_send_device_ntf(cat, MSG_GROUP_HDS, action, NULL);
+        case 4: // unmount failed.
+            if (data == NULL) {
+                LOG_SEVERE("error: hds data is null.\n");
+                break;
+            }
+            make_send_device_ntf(cat, MSG_GROUP_HDS, action, (char*)data);
             break;
         default:
             ERR("unknown action: %s.\n", action);
@@ -597,13 +713,13 @@ static bool do_push_package(char* cmd)
     char buf[MAX_PKGS_LIST];
     FILE* fp = popen(cmd, "r");
     if (fp == NULL) {
-        LOG_SEVERE("Failed to popen push packages");
+        LOG_SEVERE("Failed to popen push packages\n");
         return false;
     }
 
     memset(buf, 0, sizeof(buf));
     while(fgets(buf, sizeof(buf), fp) != NULL) {
-        LOG_INFO("[pkgs]%s", buf);
+        LOG_INFO("[pkgs]%s\n", buf);
         if (!strncmp(buf, "error", 5)){
             pclose(fp);
             return false;
@@ -763,7 +879,7 @@ static bool injector_req_handle(char* cat, type_action action, const char* data)
         INFO("emuld connection is %d\n", action);
         set_emuld_connection(action);
     } else if (!strcmp(cat, "hds")) {
-        do_hds(cat, action);
+        do_hds(cat, action, data);
         return true;
     } else if (!strcmp(cat, MSG_TYPE_PACKAGE)) {
         do_package(cat, action, data);
index 7e7c6ee..740cd70 100644 (file)
@@ -500,46 +500,6 @@ const char* get_http_proxy_addr(void)
     return NULL;
 }
 
-void set_emul_hds_attached(bool attached)
-{
-    _emul_state.hds_attached = attached;
-}
-
-bool get_emul_hds_attached(void)
-{
-    return _emul_state.hds_attached;
-}
-
-void set_emul_hds_path(const char *path)
-{
-    if (path == NULL) {
-        memset(_emul_state.hds_path, 0, sizeof(_emul_state.hds_path));
-    } else {
-        strncpy(_emul_state.hds_path, path, sizeof(_emul_state.hds_path));
-        _emul_state.hds_path[sizeof(_emul_state.hds_path) -1] = 0;
-    }
-}
-
-char* get_emul_hds_path(void)
-{
-    return _emul_state.hds_path;
-}
-
-void set_emul_hds_guest_path(const char *path)
-{
-    if (path == NULL) {
-        memset(_emul_state.hds_guest_path, 0, sizeof(_emul_state.hds_guest_path));
-    } else {
-        strncpy(_emul_state.hds_guest_path, path, sizeof(_emul_state.hds_guest_path));
-        _emul_state.hds_guest_path[sizeof(_emul_state.hds_guest_path) -1] = 0;
-    }
-}
-
-char* get_emul_hds_guest_path(void)
-{
-    return _emul_state.hds_guest_path;
-}
-
 void set_emul_profile(const char *profile)
 {
     LOG_INFO("EMULATOR_PROFILE: %s\n", profile);
index 2b89272..02175c4 100644 (file)
@@ -124,9 +124,6 @@ typedef struct EmulatorConfigState {
     int qemu_caps_lock;
     int qemu_num_lock;
     /* add here */
-    bool hds_attached;
-    char hds_path[MAX_HDS_PATH];
-    char hds_guest_path[MAX_HDS_PATH];
     char emulator_profile[MAX_PROFILE];
     bool emuld_connection;
     bool sdb_connection;
@@ -161,9 +158,9 @@ void set_emulator_condition(int state);
 void set_emul_rotation(short rotation_type);
 void set_emul_caps_lock_state(int state);
 void set_emul_num_lock_state(int state);
-void set_emul_hds_attached(bool attached);
-void set_emul_hds_path(const char *path);
-void set_emul_hds_guest_path(const char *path);
+void set_emul_tap_enable(bool enable);
+void set_emul_http_proxy_addr(char *addr);
+void set_emul_http_proxy_port(char *port);
 void set_emul_profile(const char *profile);
 void set_emuld_connection(bool connected);
 void set_sdb_connection(bool connected);
@@ -199,9 +196,6 @@ int get_emul_num_lock_state(void);
 char* get_emul_guest_ip(void);
 char* get_emul_host_ip(void);
 
-bool get_emul_hds_attached(void);
-char* get_emul_hds_path(void);
-char* get_emul_hds_guest_path(void);
 char* get_emul_profile(void);
 
 bool get_emuld_connection(void);
index 286a422..bb898e2 100644 (file)
@@ -34,4 +34,7 @@ obj-y += new_debug_ch.o
 # extra packages installation
 obj-y += extra_pkgs_install.o
 
+# multi host directory sharing support utility
+obj-y += hds.o
+
 $(obj)/osutil.o: QEMU_CFLAGS += $(CURL_CFLAGS)
diff --git a/tizen/src/util/hds.c b/tizen/src/util/hds.c
new file mode 100644 (file)
index 0000000..2efc855
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+ * Emulator Host Directory Sharing Utility
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ *  Jinhyung choi   <jinhyung2.choi@samsung.com>
+ *  Sangho Park     <sangho1206.park@samsung.com>
+ *  YeongKyoon Lee  <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#include "hds.h"
+#include "debug_ch.h"
+
+MULTI_DEBUG_CHANNEL(qemu, hds);
+
+// TODO: currently it is used as a single operation.
+// But, it is needed to add mutex for future
+typedef struct hds_list {
+    bool attached;
+    char *id;
+    char *host;
+    char *guest;
+
+    QTAILQ_ENTRY(hds_list) next;
+} hds_list;
+
+static QTAILQ_HEAD(hds_listHead, hds_list)
+lists = QTAILQ_HEAD_INITIALIZER(lists);
+
+static hds_list* find_list(const char* id)
+{
+    hds_list *list, *next;
+
+    if (id == NULL)
+        return NULL;
+
+    QTAILQ_FOREACH_SAFE(list, &lists, next, next)
+    {
+        if (!strcmp(list->id, id)) {
+            LOG_TRACE("found id. request: %s\n", id);
+            return list;
+        }
+    }
+
+    return NULL;
+}
+
+static char* find_new_id(void)
+{
+    int i = 0;
+    hds_list *list;
+    char id_candidate [MAX_HDS_ID_LEN];
+
+    for (i = 0; i < LIMIT_HDS_COUNT ; i++) {
+        snprintf(id_candidate, sizeof(id_candidate), "%s%d", DEFAULT_HDS_TAG_ID, i);
+        LOG_TRACE("new id. check: %s\n", id_candidate);
+        list = find_list(id_candidate);
+        if (list == NULL) {
+            LOG_INFO("new id found: %s\n", id_candidate);
+            return strdup(id_candidate);
+        }
+    }
+
+    LOG_INFO("new id not found: out of resources.\n");
+    return NULL;
+}
+
+bool add_hds_list(const char* id, const char* host, const char* guest)
+{
+    hds_list* list;
+
+    if (id == NULL || host == NULL || guest == NULL) {
+        LOG_SEVERE("wrong param id:%s, host:%s, guest:%s\n", host, guest);
+        return false;
+    }
+
+    list = find_list(id);
+    if (list != NULL) {
+        LOG_SEVERE("%s cannot be added. it exists already.\n", id);
+        return false;
+    }
+
+    list = g_malloc0(sizeof(hds_list));
+    if (list == NULL) {
+        LOG_SEVERE("out of resource to add hds list.\n");
+        return false;
+    }
+
+    list->id = strdup(id);
+    list->host = strdup(host);
+    list->guest = strdup(guest);
+
+    QTAILQ_INSERT_TAIL(&lists, list, next);
+
+    return true;
+}
+
+char* new_hds_list(const char* host, const char* guest)
+{
+    char* id = find_new_id();
+    if (id == NULL) {
+        LOG_SEVERE("over the max number of hds count to add hds list.\n");
+        return NULL;
+    }
+
+    if (!add_hds_list(id, host, guest)) {
+        LOG_SEVERE("failed to add list.\n");
+        free(id);
+        return NULL;
+    }
+
+    return id;
+}
+
+void remove_hds_list(const char* id)
+{
+    LOG_INFO("remove hds list request: %s\n", id);
+    hds_list *list = find_list(id);
+    if (list == NULL) {
+        return;
+    }
+
+    if (list->id) {
+        free(list->id);
+    }
+    if (list->host) {
+        free(list->host);
+    }
+    if (list->guest) {
+        free(list->guest);
+    }
+
+    QTAILQ_REMOVE(&lists, list, next);
+
+    g_free(list);
+}
+
+char* get_host_path_by_id(const char* id)
+{
+    LOG_TRACE("get_host_path_by_id request: %s\n", id);
+    hds_list *list = find_list(id);
+    if (list != NULL) {
+        return list->host;
+    }
+    return NULL;
+}
+
+char* get_guest_path_by_id(const char* id)
+{
+    LOG_TRACE("get_guest_path_by_id request: %s\n", id);
+    hds_list *list = find_list(id);
+    if (list != NULL) {
+        return list->guest;
+    }
+    return NULL;
+}
+
+bool is_hds_attached(const char* id)
+{
+    hds_list *list = find_list(id);
+    if (list == NULL) {
+        return false;
+    }
+
+    return list->attached;
+}
+
+void set_hds_attached(const char* id, bool attached)
+{
+    hds_list *list = find_list(id);
+    if (list == NULL) {
+        LOG_SEVERE("set hds attached failed because id does not exist: %s\n", id);
+        return;
+    }
+
+    list->attached = attached;
+}
+
+char* get_hds_lists(void)
+{
+    hds_list *list, *next;
+    char hds [MAX_HDS_LIST_LEN];
+    int hds_size = 0;
+    int list_len = MAX_HDS_LIST_LEN;
+    char *list_hds = g_malloc0(list_len);
+
+    QTAILQ_FOREACH_SAFE(list, &lists, next, next)
+    {
+        LOG_INFO("list id: %s\n", list->id);
+        if (list->attached) {
+            hds_size = sprintf(hds, "%s,%s,%s,\n", list->id, list->host, list->guest);
+            if (strlen(list_hds) + hds_size > list_len) {
+                list_len *= 2;
+                list_hds = g_realloc(list_hds, list_len);
+            }
+            strncat(list_hds, hds, hds_size);
+        }
+    }
+
+    LOG_INFO("get_hds_list: %s\n", list_hds);
+
+    return list_hds;
+}
diff --git a/tizen/src/util/hds.h b/tizen/src/util/hds.h
new file mode 100644 (file)
index 0000000..78af2ec
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Emulator Host Directory Sharing Utility
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact:
+ *  Jinhyung choi   <jinhyung2.choi@samsung.com>
+ *  Sangho Park     <sangho1206.park@samsung.com>
+ *  YeongKyoon Lee  <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+
+#ifndef _HDS_
+#define _HDS_
+
+#define DEFAULT_HDS_GUEST_PATH      "/mnt/host"
+#define DEFAULT_HDS_TAG_ID          "fileshare"
+#define LIMIT_HDS_COUNT             1000
+#define MAX_HDS_ID_LEN              32
+#define MAX_HDS_LIST_LEN            4096
+
+#include "qemu-common.h"
+
+bool add_hds_list(const char* id, const char* host, const char* guest);
+char* new_hds_list(const char* host, const char* guest);
+void remove_hds_list(const char* id);
+
+char* get_host_path_by_id(const char* id);
+char* get_guest_path_by_id(const char* id);
+
+bool is_hds_attached(const char* id);
+void set_hds_attached(const char* id, bool attached);
+
+char* get_hds_lists(void);
+
+#endif // _HDS_
index da4c204..94dd67e 100644 (file)
@@ -38,6 +38,8 @@
 #include "emulator.h"
 #include "emul_state.h"
 #include "maru_device_hotplug.h"
+#include "ecs/ecs.h"
+#include "hds.h"
 
 #define HOST_KEYBOARD_DRIVER        "virtio-keyboard-pci"
 #define HOST_KEYBOARD_DEFAULT_ID    "HOSTKBD0"
@@ -156,22 +158,32 @@ static bool do_sdcard_detach(void) {
     return true;
 }
 
-static bool do_hds_attach(const char * const file)
+static bool do_hds_attach(const char * const id)
 {
     QemuOpts *fsdev;
     int ret;
     QDict *qdict;
+    char* host;
+    int len = 0;
+    char* guest = NULL;
+    char emuld_data [OUT_BUF_SIZE];
 
     fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
-                             FS_MOUNT_TAG, 0, NULL);
+                             id, 0, NULL);
     if (!fsdev) {
         return false;
     }
 
-    LOG_INFO("do_hds_attach - data: %s\n", file);
+    LOG_INFO("do_hds_attach - id: %s\n", id);
+
+    host = get_host_path_by_id((char*)id);
+    if (host == NULL) {
+        LOG_SEVERE("host path is null\n");
+        return false;
+    }
 
     qemu_opt_set(fsdev, "fsdriver", "local");
-    qemu_opt_set(fsdev, "path", file);
+    qemu_opt_set(fsdev, "path", host);
     qemu_opt_set(fsdev, "security_model", "none");
 
     ret = qemu_fsdev_add(fsdev);
@@ -181,26 +193,40 @@ static bool do_hds_attach(const char * const file)
 
     qdict = qdict_new();
     qdict_put(qdict, "driver", qstring_from_str("virtio-9p-pci"));
-    qdict_put(qdict, "fsdev", qstring_from_str(FS_MOUNT_TAG));
-    qdict_put(qdict, "mount_tag", qstring_from_str(FS_MOUNT_TAG));
-    qdict_put(qdict, "id", qstring_from_str(FS_MOUNT_TAG));
+    qdict_put(qdict, "fsdev", qstring_from_str(id));
+    qdict_put(qdict, "mount_tag", qstring_from_str(id));
+    qdict_put(qdict, "id", qstring_from_str(id));
 
     if (do_device_add(default_mon, qdict, NULL)) {
         QDECREF(qdict);
         return false;
     }
 
+    set_hds_attached(id, true);
+
     QDECREF(qdict);
 
+    // send mount message to emuld
+
+    guest = get_guest_path_by_id((char*)id);
+    if (guest == NULL) {
+        LOG_SEVERE("guest path is null\n");
+        return false;
+    }
+
+    len = snprintf(emuld_data, sizeof(emuld_data), "%s\n%s\n", id, guest);
+    LOG_INFO("send emuld to mount: %s", emuld_data);
+    send_msg_to_guest(MSG_TYPE_HDS, MSG_GROUP_HDS, HDS_ACTION_MOUNT, emuld_data, len + 1);
+
     return true;
 }
 
-static bool do_hds_detach(void)
+static bool do_hds_detach(const char * const id)
 {
     QDict *qdict = qdict_new();
-    qemu_fsdev_remove(FS_MOUNT_TAG);
+    qemu_fsdev_remove(id);
 
-    qdict_put(qdict, "id", qstring_from_str(FS_MOUNT_TAG));
+    qdict_put(qdict, "id", qstring_from_str(id));
 
     if (qmp_marshal_input_device_del(cur_mon, qdict, NULL)) {
         QDECREF(qdict);
@@ -209,9 +235,7 @@ static bool do_hds_detach(void)
 
     QDECREF(qdict);
 
-    set_emul_hds_attached(false);
-    set_emul_hds_path(NULL);
-    set_emul_hds_guest_path(NULL);
+    remove_hds_list(id);
 
     return true;
 }
@@ -248,7 +272,7 @@ static void device_hotplug_handler(EventNotifier *e)
         do_hds_attach(state->opaque);
         break;
     case DETACH_HDS:
-        do_hds_detach();
+        do_hds_detach(state->opaque);
         break;
     default:
         break;
@@ -289,8 +313,3 @@ bool is_sdcard_attached(void)
     return state->sdcard_attached;
 }
 
-bool is_hds_attached(void)
-{
-    return get_emul_hds_attached();
-}
-
index 69c8a97..4db1bdc 100644 (file)
@@ -44,6 +44,5 @@ void do_hotplug(int command, void *opaque, size_t size);
 
 bool is_host_keyboard_attached(void);
 bool is_sdcard_attached(void);
-bool is_hds_attached(void);
 
 #endif // _MARU_DEVICE_HOTPLUG_H_