aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sysemu.h3
-rw-r--r--vl-android.c45
2 files changed, 47 insertions, 1 deletions
diff --git a/sysemu.h b/sysemu.h
index fe24415..7959197 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -173,6 +173,7 @@ extern int nb_drives;
extern DriveInfo drives_table[MAX_DRIVES+1];
extern int drive_get_index(BlockInterfaceType type, int bus, int unit);
+extern int drive_get_index_by_bdrv(BlockDriverState *bdrv);
extern int drive_get_max_bus(BlockInterfaceType type);
extern void drive_uninit(BlockDriverState *bdrv);
extern void drive_remove(int index);
@@ -192,6 +193,8 @@ extern int nb_drives_opt;
extern int drive_add(const char *file, const char *fmt, ...);
extern int drive_init(struct drive_opt *arg, int snapshot, void *machine);
+extern int drive_swap(struct BlockDriverState *bdrv, const char *file);
+extern int drive_hotadd(const char *file, const char *fmt, ...);
/* acpi */
void qemu_system_hot_add_init(void);
diff --git a/vl-android.c b/vl-android.c
index d6feced..5d234a2 100644
--- a/vl-android.c
+++ b/vl-android.c
@@ -2223,7 +2223,21 @@ static int drive_get_free_idx(void)
return -1;
}
-int drive_add(const char *file, const char *fmt, ...)
+int drive_swap(BlockDriverState *bdrv, const char *file)
+{
+ int index = drive_get_index_by_bdrv(bdrv);
+ int unit = drives_table[index].unit;
+ int opt_idx;
+
+ bdrv_close(bdrv);
+ drive_uninit(bdrv);
+ bdrv_delete(bdrv);
+
+ opt_idx = drive_add(file, HD_ALIAS, unit);
+ return drive_init(&drives_opt[opt_idx], 0, current_machine);
+}
+
+int drive_hotadd(const char *file, const char *fmt, ...)
{
va_list ap;
int index = drive_opt_get_free_idx();
@@ -2238,7 +2252,27 @@ int drive_add(const char *file, const char *fmt, ...)
vsnprintf(drives_opt[index].opt,
sizeof(drives_opt[0].opt), fmt, ap);
va_end(ap);
+ nb_drives_opt++;
+ if (drive_init(&drives_opt[index], 0, current_machine) < 0)
+ return -1;
+ return index;
+}
+
+int drive_add(const char *file, const char *fmt, ...)
+{
+ va_list ap;
+ int index = drive_opt_get_free_idx();
+ if (nb_drives_opt >= MAX_DRIVES || index == -1) {
+ fprintf(stderr, "qemu: too many drives\n");
+ return -1;
+ }
+
+ drives_opt[index].file = file;
+ va_start(ap, fmt);
+ vsnprintf(drives_opt[index].opt,
+ sizeof(drives_opt[0].opt), fmt, ap);
+ va_end(ap);
nb_drives_opt++;
return index;
}
@@ -2249,6 +2283,15 @@ void drive_remove(int index)
nb_drives_opt--;
}
+int drive_get_index_by_bdrv(BlockDriverState *bdrv)
+{
+ int index;
+
+ for (index = 0; index < MAX_DRIVES; index++)
+ if (drives_table[index].bdrv == bdrv)
+ return index;
+ return -1;
+}
int drive_get_index(BlockInterfaceType type, int bus, int unit)
{
int index;