]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
xen-blkback: module_exit support
authorJoao Martins <joao.m.martins@oracle.com>
Tue, 4 Dec 2018 15:22:47 +0000 (10:22 -0500)
committerJoao Martins <joao.m.martins@oracle.com>
Wed, 20 Feb 2019 17:30:52 +0000 (12:30 -0500)
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 <joao.m.martins@oracle.com>
drivers/block/xen-blkback/blkback.c
drivers/block/xen-blkback/common.h
drivers/block/xen-blkback/xenbus.c

index fd1e19f1a49f5803ca6dd5d939ec41ec592af077..d51d88be88e14e39161a549c720bf3604a4a822a 100644 (file)
@@ -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");
index 1d3002d773f7adb151dcf79adf18f919e461290a..3415c558e1155dd76e52f8d600e706e3a40d2b58 100644 (file)
@@ -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);
index a4bc74e72c394965f31dcbe7b55c8e5cd0fc6cd5..424e2efebe855ade6a07193021599b9895dfadd1 100644 (file)
@@ -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);
+}