Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp962713imp; Wed, 20 Feb 2019 12:21:23 -0800 (PST) X-Google-Smtp-Source: AHgI3Iajmil5v0cXKhzPG6rSECZ8IrghQmwDEcFSZv4q/L2Gp42lBJmd0Z3XfgCN3VtWvFswVJXs X-Received: by 2002:a63:5b43:: with SMTP id l3mr21281153pgm.298.1550694083813; Wed, 20 Feb 2019 12:21:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550694083; cv=none; d=google.com; s=arc-20160816; b=IqLCqzrSYvEpOXbMqZoBaroDnOWIEWkUsKjDDk9g0MdRFh5S2OairjCfhDkR9LMD/d MiKYL7PfaOo465+xVdolJgB0psGiYW9A+qPA2VzYqq6twxxAIOFgU64FsB9C2jRkX+1p g3AvZ93pF3kFjOzqo/aTwdg3LAXg/S4PC2V7FcgFviumTv2b4C3DuFud3X/HmIEri5iA 1L+XUz68USD8TmMj7bsZ0k1/rv2S4iGTddbxeQu79AGdw9D6e4rYVeGVVZQbTAuixS7a 3rcQLxUdgEbDAJmi9ahm9JkR5TABnpeexbwtFov6jiF3k+TOp5gHDezTGRW8OBhuX30U hKjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=77QyT0phQkeZUA6ZmD10vXuqjVPqFaqksd3QgbzVgcE=; b=L4oz5aX76PtE3yYDPl7ExhVkP9OXER4Huf4hhYH7cIA8GYvkeqrlcT2wRBHspVbrYn b17XGayB610LNTjHJn1wh7HaypSdCEWDQZOnqALoqrRfzpkaqQaV8t0VIKSj5IFM3WXG IRqyqUijE03zJXUAh/GcaV9cEExiGxrTxefaH1VbXFk8x/goRbGU8uE4YGdwAOAZIyZt q8KKPl2jVY/Ec4VOv8PSYvPDYVlXvD5FoBoRAW6U9NlrwfdjqtNlnKncQ+5Z5zpwobGu 6G6x/P23mmlvD+3/VYeeKbns+33JOpvrBzp4hZ1X7q9XlpnVMLR5mIThVTnCdxNaSaqI uDQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=VpdkMv1b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q15si18718162pgm.420.2019.02.20.12.21.08; Wed, 20 Feb 2019 12:21:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=VpdkMv1b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728167AbfBTUTG (ORCPT + 99 others); Wed, 20 Feb 2019 15:19:06 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:36708 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727119AbfBTUTE (ORCPT ); Wed, 20 Feb 2019 15:19:04 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1KK8c9Z087605; Wed, 20 Feb 2019 20:17:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=77QyT0phQkeZUA6ZmD10vXuqjVPqFaqksd3QgbzVgcE=; b=VpdkMv1bV3DD6gUFdqPFCR+s/5qiMvSTU6egNXo5eskWdCjlpH7Pc3p1u9v9BTn4Dvyj GS3WMCVZfIa/AgRBQWC/eBtNEbZEQsbwEY60yBa+KGQNpxBFKfyIBRdNqZA5jjtL0nOK +zo5l0AEagcNHPQ/Y5JCWMJpoal74XhAZTmo3MggSrSMajzZiwKmTBBhcltMWkWtn6/U Yfpojqn8WBblNy/veaQq/QflH0sVXLDoKD+rST7fLIXTTsJwPpjvGb78CQ3ZFi1qSlBk iubArrqmcyp4l55QLarPbme+MgDFypFru3cnoBO7mMwa454c6EEJXDuTx3VBSsOoWiDk kw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2qpb5rktsd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Feb 2019 20:17:59 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x1KKHwrh022956 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Feb 2019 20:17:58 GMT Received: from abhmp0022.oracle.com (abhmp0022.oracle.com [141.146.116.28]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x1KKHvwI012065; Wed, 20 Feb 2019 20:17:57 GMT Received: from paddy.lan (/94.61.137.133) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 20 Feb 2019 12:17:57 -0800 From: Joao Martins To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: Ankur Arora , Boris Ostrovsky , Joao Martins , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Konrad Rzeszutek Wilk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH RFC 20/39] xen-blkback: module_exit support Date: Wed, 20 Feb 2019 20:15:50 +0000 Message-Id: <20190220201609.28290-21-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190220201609.28290-1-joao.m.martins@oracle.com> References: <20190220201609.28290-1-joao.m.martins@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9173 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902200138 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement module_exit to allow users to do module unload of blkback. We prevent users from module unload whenever there are still interfaces allocated, in other words, do module_get on xen_blkif_alloc() and module_put on xen_blkif_free(). Signed-off-by: Joao Martins --- drivers/block/xen-blkback/blkback.c | 8 ++++++++ drivers/block/xen-blkback/common.h | 2 ++ drivers/block/xen-blkback/xenbus.c | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index fd1e19f1a49f..d51d88be88e1 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c @@ -1504,5 +1504,13 @@ static int __init xen_blkif_init(void) module_init(xen_blkif_init); +static void __exit xen_blkif_exit(void) +{ + xen_blkif_interface_exit(); + xen_blkif_xenbus_exit(); +} + +module_exit(xen_blkif_exit); + MODULE_LICENSE("Dual BSD/GPL"); MODULE_ALIAS("xen-backend:vbd"); diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h index 1d3002d773f7..3415c558e115 100644 --- a/drivers/block/xen-blkback/common.h +++ b/drivers/block/xen-blkback/common.h @@ -376,8 +376,10 @@ struct phys_req { blkif_sector_t sector_number; }; int xen_blkif_interface_init(void); +void xen_blkif_interface_exit(void); int xen_blkif_xenbus_init(void); +void xen_blkif_xenbus_exit(void); irqreturn_t xen_blkif_be_int(int irq, void *dev_id); int xen_blkif_schedule(void *arg); diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index a4bc74e72c39..424e2efebe85 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -181,6 +181,8 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid) init_completion(&blkif->drain_complete); INIT_WORK(&blkif->free_work, xen_blkif_deferred_free); + __module_get(THIS_MODULE); + return blkif; } @@ -328,6 +330,8 @@ static void xen_blkif_free(struct xen_blkif *blkif) /* Make sure everything is drained before shutting down */ kmem_cache_free(xen_blkif_cachep, blkif); + + module_put(THIS_MODULE); } int __init xen_blkif_interface_init(void) @@ -341,6 +345,11 @@ int __init xen_blkif_interface_init(void) return 0; } +void xen_blkif_interface_exit(void) +{ + kmem_cache_destroy(xen_blkif_cachep); +} + /* * sysfs interface for VBD I/O requests */ @@ -1115,3 +1124,8 @@ int xen_blkif_xenbus_init(void) { return xenbus_register_backend(&xen_blkbk_driver); } + +void xen_blkif_xenbus_exit(void) +{ + xenbus_unregister_driver(&xen_blkbk_driver); +} -- 2.11.0