@@ -1477,7 +1477,7 @@ typedef struct libxl__ddomain_device {
*/
typedef struct libxl__ddomain_guest {
uint32_t domid;
- int num_vifs, num_vbds, num_qdisks;
+ int num_qdisks;
LIBXL_SLIST_HEAD(, struct libxl__ddomain_device) devices;
LIBXL_SLIST_ENTRY(struct libxl__ddomain_guest) next;
} libxl__ddomain_guest;
@@ -1530,8 +1530,7 @@ static void check_and_maybe_remove_guest(libxl__gc *gc,
{
assert(ddomain);
- if (dguest != NULL &&
- dguest->num_vifs + dguest->num_vbds + dguest->num_qdisks == 0) {
+ if (dguest != NULL && LIBXL_SLIST_FIRST(&dguest->devices) == NULL) {
LIBXL_SLIST_REMOVE(&ddomain->guests, dguest, libxl__ddomain_guest,
next);
LOGD(DEBUG, dguest->domid, "Removed domain from the list of active guests");
@@ -1571,24 +1570,6 @@ static int add_device(libxl__egc *egc, libxl__ao *ao,
libxl__device_backend_path(gc, dev));
switch(dev->backend_kind) {
- case LIBXL__DEVICE_KIND_VBD:
- case LIBXL__DEVICE_KIND_VIF:
- if (dev->backend_kind == LIBXL__DEVICE_KIND_VBD) dguest->num_vbds++;
- if (dev->backend_kind == LIBXL__DEVICE_KIND_VIF) dguest->num_vifs++;
-
- GCNEW(aodev);
- libxl__prepare_ao_device(ao, aodev);
- /*
- * Clone the libxl__device to avoid races if remove_device is called
- * before the device addition has finished.
- */
- GCNEW(aodev->dev);
- *aodev->dev = *dev;
- aodev->action = LIBXL__DEVICE_ACTION_ADD;
- aodev->callback = device_complete;
- libxl__wait_device_connection(egc, aodev);
-
- break;
case LIBXL__DEVICE_KIND_QDISK:
if (dguest->num_qdisks == 0) {
GCNEW(dmss);
@@ -1599,10 +1580,19 @@ static int add_device(libxl__egc *egc, libxl__ao *ao,
libxl__spawn_qdisk_backend(egc, dmss);
}
dguest->num_qdisks++;
-
break;
default:
- rc = 1;
+ GCNEW(aodev);
+ libxl__prepare_ao_device(ao, aodev);
+ /*
+ * Clone the libxl__device to avoid races if remove_device is called
+ * before the device addition has finished.
+ */
+ GCNEW(aodev->dev);
+ *aodev->dev = *dev;
+ aodev->action = LIBXL__DEVICE_ACTION_ADD;
+ aodev->callback = device_complete;
+ libxl__wait_device_connection(egc, aodev);
break;
}
@@ -1619,11 +1609,17 @@ static int remove_device(libxl__egc *egc, libxl__ao *ao,
int rc = 0;
switch(ddev->dev->backend_kind) {
- case LIBXL__DEVICE_KIND_VBD:
- case LIBXL__DEVICE_KIND_VIF:
- if (dev->backend_kind == LIBXL__DEVICE_KIND_VBD) dguest->num_vbds--;
- if (dev->backend_kind == LIBXL__DEVICE_KIND_VIF) dguest->num_vifs--;
-
+ case LIBXL__DEVICE_KIND_QDISK:
+ if (--dguest->num_qdisks == 0) {
+ rc = libxl__destroy_qdisk_backend(gc, dev->domid);
+ if (rc)
+ goto out;
+ }
+ libxl__device_destroy(gc, dev);
+ /* Return > 0, no ao has been dispatched */
+ rc = 1;
+ break;
+ default:
GCNEW(aodev);
libxl__prepare_ao_device(ao, aodev);
/*
@@ -1636,17 +1632,6 @@ static int remove_device(libxl__egc *egc, libxl__ao *ao,
aodev->callback = device_complete;
libxl__initiate_device_generic_remove(egc, aodev);
break;
- case LIBXL__DEVICE_KIND_QDISK:
- if (--dguest->num_qdisks == 0) {
- rc = libxl__destroy_qdisk_backend(gc, dev->domid);
- if (rc)
- goto out;
- }
- libxl__device_destroy(gc, dev);
- /* Fall through to return > 0, no ao has been dispatched */
- default:
- rc = 1;
- break;
}
/*