sdcard: allocate "DriveInfo" to delete the "BlockBackend" automatically
authorChulHo Song <ch81.song@samsung.com>
Wed, 30 Sep 2015 04:28:56 +0000 (13:28 +0900)
committerChulHo Song <ch81.song@samsung.com>
Wed, 30 Sep 2015 04:28:56 +0000 (13:28 +0900)
When the sdcard is detached, "virtio_blk_device_unrealize" marks
auto deletion flag to the "DriveInfo". But "qmp_marshal_input_blockdev_add"
does not create the "DriveInfo". To destroy BlockBackend object automatically
we need to create dummy "DriveInfo".

Change-Id: I8501c5b14daab487e72b4b6b6a0744475c6553a3
Signed-off-by: ChulHo Song <ch81.song@samsung.com>
tizen/src/util/device_hotplug.c

index f6d8994..d32235d 100644 (file)
@@ -30,6 +30,7 @@
 #include "qemu/config-file.h"
 #include "hw/qdev.h"
 #include "qemu/event_notifier.h"
+#include "sysemu/block-backend.h"
 
 #include "emulator.h"
 #include "emul_state.h"
@@ -105,6 +106,7 @@ static bool do_sdcard_attach(const char * const file)
     gchar *sdcard_img = g_path_get_basename(file);
     gchar *sdcard_device_id = g_strdup_printf("device_id_%s", sdcard_img);
     gchar *sdcard_drive_id = g_strdup_printf("drive_id_%s", sdcard_img);
+    DriveInfo* dinfo = NULL;
 
     g_free(sdcard_img);
 
@@ -117,6 +119,10 @@ static bool do_sdcard_attach(const char * const file)
 
     qmp_marshal_input_blockdev_add(default_mon, qdict, NULL);
 
+    dinfo = g_malloc0(sizeof(*dinfo));
+    dinfo->type = IF_VIRTIO;
+    blk_set_legacy_dinfo(blk_by_name(sdcard_device_id), dinfo);
+
     QDECREF(qdict);
 
     qdict = qdict_new();