Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752465AbdGYVWY (ORCPT ); Tue, 25 Jul 2017 17:22:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:46672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752365AbdGYVWV (ORCPT ); Tue, 25 Jul 2017 17:22:21 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5EDDA22C93 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=sstabellini@kernel.org From: Stefano Stabellini To: xen-devel@lists.xen.org Cc: linux-kernel@vger.kernel.org, sstabellini@kernel.org, jgross@suse.com, boris.ostrovsky@oracle.com, Stefano Stabellini Subject: [PATCH v2 12/13] xen/pvcalls: implement frontend disconnect Date: Tue, 25 Jul 2017 14:22:09 -0700 Message-Id: <1501017730-12797-12-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501017730-12797-1-git-send-email-sstabellini@kernel.org> References: <1501017730-12797-1-git-send-email-sstabellini@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1626 Lines: 52 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 Reviewed-by: Juergen Gross CC: boris.ostrovsky@oracle.com CC: jgross@suse.com --- 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 5a4040e..b3d4675 100644 --- a/drivers/xen/pvcalls-front.c +++ b/drivers/xen/pvcalls-front.c @@ -911,6 +911,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