Commit 4d73cd3b3f55fcff433ce64b125b7adb8aaece29
1 parent
ec691c80
qemu: net/drive add/remove tweaks (Marcelo Tosatti)
Export net/drive add/remove functions for device hotplug usage. Return the table index on add. Return failure instead of exiting if limit has been reached on drive_add. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6599 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
3 changed files
with
11 additions
and
8 deletions
net.c
... | ... | @@ -1597,7 +1597,7 @@ int net_client_init(const char *device, const char *p) |
1597 | 1597 | name = NULL; |
1598 | 1598 | nb_nics++; |
1599 | 1599 | vlan->nb_guest_devs++; |
1600 | - ret = 0; | |
1600 | + ret = idx; | |
1601 | 1601 | } else |
1602 | 1602 | if (!strcmp(device, "none")) { |
1603 | 1603 | /* does nothing. It is needed to signal that no network cards | ... | ... |
sysemu.h
... | ... | @@ -163,6 +163,9 @@ struct drive_opt { |
163 | 163 | extern struct drive_opt drives_opt[MAX_DRIVES]; |
164 | 164 | extern int nb_drives_opt; |
165 | 165 | |
166 | +extern int drive_add(const char *file, const char *fmt, ...); | |
167 | +extern int drive_init(struct drive_opt *arg, int snapshot, void *machine); | |
168 | + | |
166 | 169 | /* serial ports */ |
167 | 170 | |
168 | 171 | #define MAX_SERIAL_PORTS 4 | ... | ... |
vl.c
... | ... | @@ -2158,14 +2158,14 @@ static int drive_get_free_idx(void) |
2158 | 2158 | return -1; |
2159 | 2159 | } |
2160 | 2160 | |
2161 | -static int drive_add(const char *file, const char *fmt, ...) | |
2161 | +int drive_add(const char *file, const char *fmt, ...) | |
2162 | 2162 | { |
2163 | 2163 | va_list ap; |
2164 | 2164 | int index = drive_opt_get_free_idx(); |
2165 | 2165 | |
2166 | 2166 | if (nb_drives_opt >= MAX_DRIVES || index == -1) { |
2167 | 2167 | fprintf(stderr, "qemu: too many drives\n"); |
2168 | - exit(1); | |
2168 | + return -1; | |
2169 | 2169 | } |
2170 | 2170 | |
2171 | 2171 | drives_opt[index].file = file; |
... | ... | @@ -2255,8 +2255,7 @@ void drive_uninit(BlockDriverState *bdrv) |
2255 | 2255 | } |
2256 | 2256 | } |
2257 | 2257 | |
2258 | -static int drive_init(struct drive_opt *arg, int snapshot, | |
2259 | - QEMUMachine *machine) | |
2258 | +int drive_init(struct drive_opt *arg, int snapshot, void *opaque) | |
2260 | 2259 | { |
2261 | 2260 | char buf[128]; |
2262 | 2261 | char file[1024]; |
... | ... | @@ -2269,6 +2268,7 @@ static int drive_init(struct drive_opt *arg, int snapshot, |
2269 | 2268 | int cyls, heads, secs, translation; |
2270 | 2269 | BlockDriverState *bdrv; |
2271 | 2270 | BlockDriver *drv = NULL; |
2271 | + QEMUMachine *machine = opaque; | |
2272 | 2272 | int max_devs; |
2273 | 2273 | int index; |
2274 | 2274 | int cache; |
... | ... | @@ -2535,7 +2535,7 @@ static int drive_init(struct drive_opt *arg, int snapshot, |
2535 | 2535 | */ |
2536 | 2536 | |
2537 | 2537 | if (drive_get_index(type, bus_id, unit_id) != -1) |
2538 | - return 0; | |
2538 | + return -2; | |
2539 | 2539 | |
2540 | 2540 | /* init */ |
2541 | 2541 | |
... | ... | @@ -2585,7 +2585,7 @@ static int drive_init(struct drive_opt *arg, int snapshot, |
2585 | 2585 | break; |
2586 | 2586 | } |
2587 | 2587 | if (!file[0]) |
2588 | - return 0; | |
2588 | + return -2; | |
2589 | 2589 | bdrv_flags = 0; |
2590 | 2590 | if (snapshot) { |
2591 | 2591 | bdrv_flags |= BDRV_O_SNAPSHOT; |
... | ... | @@ -2602,7 +2602,7 @@ static int drive_init(struct drive_opt *arg, int snapshot, |
2602 | 2602 | file); |
2603 | 2603 | return -1; |
2604 | 2604 | } |
2605 | - return 0; | |
2605 | + return drives_table_idx; | |
2606 | 2606 | } |
2607 | 2607 | |
2608 | 2608 | /***********************************************************/ | ... | ... |