提交 4d73cd3b 编写于 作者: A aliguori

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: NMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6599 c046a42c-6fe2-441c-8c8c-71466251a162
上级 ec691c80
...@@ -1597,7 +1597,7 @@ int net_client_init(const char *device, const char *p) ...@@ -1597,7 +1597,7 @@ int net_client_init(const char *device, const char *p)
name = NULL; name = NULL;
nb_nics++; nb_nics++;
vlan->nb_guest_devs++; vlan->nb_guest_devs++;
ret = 0; ret = idx;
} else } else
if (!strcmp(device, "none")) { if (!strcmp(device, "none")) {
/* does nothing. It is needed to signal that no network cards /* does nothing. It is needed to signal that no network cards
......
...@@ -163,6 +163,9 @@ struct drive_opt { ...@@ -163,6 +163,9 @@ struct drive_opt {
extern struct drive_opt drives_opt[MAX_DRIVES]; extern struct drive_opt drives_opt[MAX_DRIVES];
extern int nb_drives_opt; 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);
/* serial ports */ /* serial ports */
#define MAX_SERIAL_PORTS 4 #define MAX_SERIAL_PORTS 4
......
...@@ -2158,14 +2158,14 @@ static int drive_get_free_idx(void) ...@@ -2158,14 +2158,14 @@ static int drive_get_free_idx(void)
return -1; return -1;
} }
static int drive_add(const char *file, const char *fmt, ...) int drive_add(const char *file, const char *fmt, ...)
{ {
va_list ap; va_list ap;
int index = drive_opt_get_free_idx(); int index = drive_opt_get_free_idx();
if (nb_drives_opt >= MAX_DRIVES || index == -1) { if (nb_drives_opt >= MAX_DRIVES || index == -1) {
fprintf(stderr, "qemu: too many drives\n"); fprintf(stderr, "qemu: too many drives\n");
exit(1); return -1;
} }
drives_opt[index].file = file; drives_opt[index].file = file;
...@@ -2255,8 +2255,7 @@ void drive_uninit(BlockDriverState *bdrv) ...@@ -2255,8 +2255,7 @@ void drive_uninit(BlockDriverState *bdrv)
} }
} }
static int drive_init(struct drive_opt *arg, int snapshot, int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
QEMUMachine *machine)
{ {
char buf[128]; char buf[128];
char file[1024]; char file[1024];
...@@ -2269,6 +2268,7 @@ static int drive_init(struct drive_opt *arg, int snapshot, ...@@ -2269,6 +2268,7 @@ static int drive_init(struct drive_opt *arg, int snapshot,
int cyls, heads, secs, translation; int cyls, heads, secs, translation;
BlockDriverState *bdrv; BlockDriverState *bdrv;
BlockDriver *drv = NULL; BlockDriver *drv = NULL;
QEMUMachine *machine = opaque;
int max_devs; int max_devs;
int index; int index;
int cache; int cache;
...@@ -2535,7 +2535,7 @@ static int drive_init(struct drive_opt *arg, int snapshot, ...@@ -2535,7 +2535,7 @@ static int drive_init(struct drive_opt *arg, int snapshot,
*/ */
if (drive_get_index(type, bus_id, unit_id) != -1) if (drive_get_index(type, bus_id, unit_id) != -1)
return 0; return -2;
/* init */ /* init */
...@@ -2585,7 +2585,7 @@ static int drive_init(struct drive_opt *arg, int snapshot, ...@@ -2585,7 +2585,7 @@ static int drive_init(struct drive_opt *arg, int snapshot,
break; break;
} }
if (!file[0]) if (!file[0])
return 0; return -2;
bdrv_flags = 0; bdrv_flags = 0;
if (snapshot) { if (snapshot) {
bdrv_flags |= BDRV_O_SNAPSHOT; bdrv_flags |= BDRV_O_SNAPSHOT;
...@@ -2602,7 +2602,7 @@ static int drive_init(struct drive_opt *arg, int snapshot, ...@@ -2602,7 +2602,7 @@ static int drive_init(struct drive_opt *arg, int snapshot,
file); file);
return -1; return -1;
} }
return 0; return drives_table_idx;
} }
/***********************************************************/ /***********************************************************/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册