diff options
author | San Mehat <san@google.com> | 2009-12-10 14:37:40 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2009-12-10 14:37:40 -0800 |
commit | e13f113248d151c3d160c80e2d28d04a2e27c7ce (patch) | |
tree | 4d9063567a3eca4af263909c5e10b3da1fc2fe43 | |
parent | 2f561e9f85d2ce571cd43570d3baa78577085ec2 (diff) | |
parent | 76ae1ea0e8ef78573df59d0ff4b990bf564920db (diff) | |
download | external_qemu-e13f113248d151c3d160c80e2d28d04a2e27c7ce.zip external_qemu-e13f113248d151c3d160c80e2d28d04a2e27c7ce.tar.gz external_qemu-e13f113248d151c3d160c80e2d28d04a2e27c7ce.tar.bz2 |
am 76ae1ea0: am 7ab6d35b: qemu: android: Add support for hot-adding disks as well as swapping image files
Merge commit '76ae1ea0e8ef78573df59d0ff4b990bf564920db'
* commit '76ae1ea0e8ef78573df59d0ff4b990bf564920db':
qemu: android: Add support for hot-adding disks as well as swapping image files
-rw-r--r-- | sysemu.h | 3 | ||||
-rw-r--r-- | vl-android.c | 45 |
2 files changed, 47 insertions, 1 deletions
@@ -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; |