[PATCH v1 12/13] xen/pvcalls: implement frontend disconnect

From: Stefano Stabellini
Date: Fri Jul 21 2017 - 20:13:01 EST


Implement pvcalls frontend removal function. Go through the list of
active and passive sockets and free them all, one at a time.

Signed-off-by: Stefano Stabellini <stefano@xxxxxxxxxxx>
CC: boris.ostrovsky@xxxxxxxxxx
CC: jgross@xxxxxxxx
---
drivers/xen/pvcalls-front.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index bd3dfac..fcc15fb 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -898,6 +898,34 @@ int pvcalls_front_release(struct socket *sock)

static int pvcalls_front_remove(struct xenbus_device *dev)
{
+ struct pvcalls_bedata *bedata;
+ struct sock_mapping *map = NULL, *n;
+
+ bedata = dev_get_drvdata(&pvcalls_front_dev->dev);
+
+ list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) {
+ mutex_lock(&map->active.in_mutex);
+ mutex_lock(&map->active.out_mutex);
+ pvcalls_front_free_map(bedata, map);
+ mutex_unlock(&map->active.out_mutex);
+ mutex_unlock(&map->active.in_mutex);
+ kfree(map);
+ }
+ list_for_each_entry_safe(map, n, &bedata->socketpass_mappings, list) {
+ spin_lock(&bedata->pvcallss_lock);
+ list_del_init(&map->list);
+ spin_unlock(&bedata->pvcallss_lock);
+ kfree(map);
+ }
+ if (bedata->irq > 0)
+ unbind_from_irqhandler(bedata->irq, dev);
+ if (bedata->ref >= 0)
+ gnttab_end_foreign_access(bedata->ref, 0, 0);
+ kfree(bedata->ring.sring);
+ kfree(bedata);
+ dev_set_drvdata(&dev->dev, NULL);
+ xenbus_switch_state(dev, XenbusStateClosed);
+ pvcalls_front_dev = NULL;
return 0;
}

--
1.9.1