Commit b01b11113c32425e888139d8e99e699f90da3a8d

Authored by aliguori
1 parent 7697079b

qemu: drive removal support (Marcelo Tosatti)

To be used by hot-remove.

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@6596 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 24 additions and 0 deletions
sysemu.h
... ... @@ -135,6 +135,7 @@ typedef struct DriveInfo {
135 135 int bus;
136 136 int unit;
137 137 int used;
  138 + int drive_opt_idx;
138 139 BlockInterfaceErrorAction onerror;
139 140 char serial[21];
140 141 } DriveInfo;
... ... @@ -148,6 +149,8 @@ extern DriveInfo drives_table[MAX_DRIVES+1];
148 149  
149 150 extern int drive_get_index(BlockInterfaceType type, int bus, int unit);
150 151 extern int drive_get_max_bus(BlockInterfaceType type);
  152 +extern void drive_uninit(BlockDriverState *bdrv);
  153 +extern void drive_remove(int index);
151 154 extern const char *drive_get_serial(BlockDriverState *bdrv);
152 155 extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
153 156  
... ...
... ... @@ -2182,6 +2182,12 @@ static int drive_add(const char *file, const char *fmt, ...)
2182 2182 return index;
2183 2183 }
2184 2184  
  2185 +void drive_remove(int index)
  2186 +{
  2187 + drives_opt[index].used = 0;
  2188 + nb_drives_opt--;
  2189 +}
  2190 +
2185 2191 int drive_get_index(BlockInterfaceType type, int bus, int unit)
2186 2192 {
2187 2193 int index;
... ... @@ -2239,6 +2245,20 @@ static void bdrv_format_print(void *opaque, const char *name)
2239 2245 fprintf(stderr, " %s", name);
2240 2246 }
2241 2247  
  2248 +void drive_uninit(BlockDriverState *bdrv)
  2249 +{
  2250 + int i;
  2251 +
  2252 + for (i = 0; i < MAX_DRIVES; i++)
  2253 + if (drives_table[i].bdrv == bdrv) {
  2254 + drives_table[i].bdrv = NULL;
  2255 + drives_table[i].used = 0;
  2256 + drive_remove(drives_table[i].drive_opt_idx);
  2257 + nb_drives--;
  2258 + break;
  2259 + }
  2260 +}
  2261 +
2242 2262 static int drive_init(struct drive_opt *arg, int snapshot,
2243 2263 QEMUMachine *machine)
2244 2264 {
... ... @@ -2538,6 +2558,7 @@ static int drive_init(struct drive_opt *arg, int snapshot,
2538 2558 drives_table[drives_table_idx].bus = bus_id;
2539 2559 drives_table[drives_table_idx].unit = unit_id;
2540 2560 drives_table[drives_table_idx].onerror = onerror;
  2561 + drives_table[drives_table_idx].drive_opt_idx = arg - drives_opt;
2541 2562 strncpy(drives_table[nb_drives].serial, serial, sizeof(serial));
2542 2563 nb_drives++;
2543 2564  
... ...