sdcard: Prepare virtio sdcard
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 15 Apr 2013 15:39:58 +0000 (00:39 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 24 May 2013 04:29:15 +0000 (13:29 +0900)
For higher performance and mount support by Tizen system framework.

Change-Id: I0c7d0538cb062139c48d00d57f80bb027a605452
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
hw/pci-hotplug.c
sysemu.h
tizen/src/guest_server.c
tizen/src/mloop_event.c
tizen/src/mloop_event.h

index 73badc1..33d1bac 100644 (file)
@@ -246,7 +246,11 @@ static PCIDevice *qemu_pci_hot_add_keyboard(Monitor *mon,
 }
 #endif /* CONFIG_MARU */
 
+#ifdef CONFIG_MARU
+PCIDevice *pci_device_hot_add(Monitor *mon, const QDict *qdict)
+#else
 void pci_device_hot_add(Monitor *mon, const QDict *qdict)
+#endif
 {
     PCIDevice *dev = NULL;
     const char *pci_addr = qdict_get_str(qdict, "pci_addr");
@@ -284,6 +288,9 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict)
                        PCI_FUNC(dev->devfn));
     } else
         monitor_printf(mon, "failed to add %s\n", opts);
+#ifdef CONFIG_MARU
+    return dev;
+#endif
 }
 #endif
 
index 9210711..3a23fb9 100644 (file)
--- a/sysemu.h
+++ b/sysemu.h
@@ -161,7 +161,11 @@ extern const char *prom_envs[MAX_PROM_ENVS];
 extern unsigned int nb_prom_envs;
 
 /* pci-hotplug */
+#ifdef CONFIG_MARU
+PCIDevice *pci_device_hot_add(Monitor *mon, const QDict *qdict);
+#else
 void pci_device_hot_add(Monitor *mon, const QDict *qdict);
+#endif
 int pci_drive_hot_add(Monitor *mon, const QDict *qdict,
                       DriveInfo *dinfo, int type);
 void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict);
index 452b048..7c0eb41 100644 (file)
@@ -224,7 +224,8 @@ static void* run_guest_server(void* args)
                 if (atoi(ret) == 0) {
                     /* umount sdcard */
                     mloop_evcmd_usbdisk(NULL);
-
+                    // prepare virtio sdcard...
+                    //mloop_evcmd_sdcard(NULL);
                 } else if (atoi(ret) == 1) {
                     /* mount sdcard */
                     char sdcard_path[256];
@@ -239,6 +240,9 @@ static void* run_guest_server(void* args)
                     INFO("%s\n", sdcard_path);
 
                     mloop_evcmd_usbdisk(sdcard_path);
+                    // prepare virtio sdcard...
+                    //mloop_evcmd_sdcard(sdcard_path);
+
                     free(vms_path);
                 } else {
                     ERR("!!! unknown command : %s\n", ret);
index d4a61eb..fca63fc 100644 (file)
@@ -85,6 +85,8 @@ struct mloop_evpack {
 #define MLOOP_EVTYPE_KBD_ADD    8
 #define MLOOP_EVTYPE_KBD_DEL    9
 #define MLOOP_EVTYPE_RAMDUMP    10
+#define MLOOP_EVTYPE_SDCARD_ATTACH  11
+#define MLOOP_EVTYPE_SDCARD_DETACH  12
 
 
 static struct mloop_evsock mloop = {-1, 0, 0};
@@ -205,6 +207,9 @@ static int mloop_evsock_send(struct mloop_evsock *ev, struct mloop_evpack *p)
 static USBDevice *usbkbd = NULL;
 static USBDevice *usbdisk = NULL;
 static PCIDevice *hostkbd = NULL;
+#ifdef TARGET_I386
+static PCIDevice *virtio_sdcard = NULL;
+#endif
 
 static void mloop_evhandle_usb_add(char *name)
 {
@@ -372,6 +377,71 @@ static void mloop_evhandle_kbd_del(char *name)
         WARN("There is no %s device.\n", name);
     }
 }
+
+static void mloop_evhandle_sdcard_attach(char *name)
+{
+    char opts[PATH_MAX];
+
+    INFO("mloop_evhandle_sdcard_attach\n");
+
+    if (name == NULL) {
+        ERR("Packet data is NULL.\n");
+        return;
+    }
+
+    if (virtio_sdcard) {
+        ERR("sdcard is already attached.\n");
+        return;
+    }
+
+    QDict *qdict = qdict_new();
+
+    qdict_put(qdict, "pci_addr", qstring_from_str("auto"));
+    qdict_put(qdict, "type", qstring_from_str("storage"));
+    snprintf(opts, sizeof(opts), "file=%s,if=virtio", name); 
+    qdict_put(qdict, "opts", qstring_from_str(opts));
+
+    virtio_sdcard = pci_device_hot_add(cur_mon, qdict);
+
+    INFO("hot add virtio storage device with [%s]\n", opts);
+    INFO("virtio-sdcard device: domain %d, bus %d, slot %d, function %d\n",
+            pci_find_domain(virtio_sdcard->bus), pci_bus_num(virtio_sdcard->bus),
+            PCI_SLOT(virtio_sdcard->devfn), PCI_FUNC(virtio_sdcard->devfn));
+
+    QDECREF(qdict);
+}
+
+static void mloop_evhandle_sdcard_detach(char *name)
+{
+    INFO("mloop_evhandle_sdcard_detach\n");
+
+    if (name == NULL) {
+        ERR("packet data is NULL.\n");
+        return;
+    }
+
+    if (!virtio_sdcard) {
+        ERR("sdcard is not attached yet.\n");
+        return;
+    }
+
+    QDict *qdict = qdict_new();
+    int slot = 0;
+    char slotbuf[4] = {0,};
+
+    slot = PCI_SLOT(virtio_sdcard->devfn);
+    snprintf(slotbuf, sizeof(slotbuf), "%x", slot);
+    INFO("virtio-sdcard slot [%d].\n", slotbuf);
+    qdict_put(qdict, "pci_addr", qstring_from_str(slotbuf));
+
+    do_pci_device_hot_remove(cur_mon, qdict);
+
+    virtio_sdcard = NULL;
+
+    INFO("hot remove virtio storage device.\n");
+
+    QDECREF(qdict);
+}
 #endif
 
 
@@ -470,6 +540,14 @@ static void mloop_evcb_recv(struct mloop_evsock *ev)
     case MLOOP_EVTYPE_RAMDUMP:
         mloop_evhandle_ramdump(&pack);
         break;
+#ifdef TARGET_I386
+    case MLOOP_EVTYPE_SDCARD_ATTACH:
+        mloop_evhandle_sdcard_attach(pack.data);
+        break;
+    case MLOOP_EVTYPE_SDCARD_DETACH:
+        mloop_evhandle_sdcard_detach(pack.data);
+        break;
+#endif
     default:
         break;
     }
@@ -550,6 +628,28 @@ void mloop_evcmd_usbdisk(char *img)
     mloop_evsock_send(&mloop, &pack);
 }
 
+void mloop_evcmd_sdcard(char *img)
+{
+    struct mloop_evpack pack;
+
+    if (img) {
+        if (strlen(img) > PACKET_LEN-5) {
+            // Need log
+            ERR("The length of disk image path is greater than "
+                "lenth of maximum packet.\n");
+            return;
+        }
+
+        pack.type = MLOOP_EVTYPE_SDCARD_ATTACH;
+        pack.size = 5 + sprintf(pack.data, "%s", img);
+    } else {
+        pack.type = MLOOP_EVTYPE_SDCARD_DETACH;
+        pack.size = 5;
+    }
+
+    mloop_evsock_send(&mloop, &pack);
+}
+
 int mloop_evcmd_get_usbkbd_status(void)
 {
     return (usbkbd && usbkbd->attached ? 1 : 0);
index ddfbc25..1023f02 100644 (file)
@@ -56,6 +56,8 @@ void mloop_evcmd_touch(void);
 void mloop_evcmd_keyboard(void *data);
 void mloop_evcmd_ramdump(void);
 
+void mloop_evcmd_sdcard(char* img);
+
 #ifdef __cplusplus
 }
 #endif