]> xenbits.xensource.com Git - legacy/linux-2.6.18-xen.git/commitdiff
Use module use count on accel plugin to prevent premature unload.
authorKeir Fraser <keir@xensource.com>
Wed, 3 Oct 2007 14:02:07 +0000 (15:02 +0100)
committerKeir Fraser <keir@xensource.com>
Wed, 3 Oct 2007 14:02:07 +0000 (15:02 +0100)
Signed-off-by: Kieran Mansley <kmansley@solarflare.com>
drivers/xen/netback/accel.c
drivers/xen/netback/common.h

index d34f362ca76f75e4cfce2060a436f97567cbf515..33f254b800ac42fec8a4bdddcaa262abfa5f14b8 100644 (file)
@@ -187,8 +187,8 @@ static int netback_accelerator_cleanup_backend(struct device *dev, void *arg)
  *
  * This should only be allowed when there are no remaining users -
  * i.e. it is not necessary to go through and clear all the hooks, as
- * they should have already been removed.  This is enforced through a
- * usage count and BUG_ON(use!=0), but should be made more user-friendly
+ * they should have already been removed.  This is enforced by taking
+ * a module reference to the plugin while the interfaces are in use
  */
 void netback_disconnect_accelerator(int id, const char *eth_name)
 {
@@ -227,7 +227,8 @@ void netback_probe_accelerators(struct backend_info *be,
         */
        spin_lock_irqsave(&accelerators_lock, flags);
        list_for_each_entry(accelerator, &accelerators_list, link) { 
-               if (match_accelerator(dev, be, accelerator)) {
+               if (match_accelerator(dev, be, accelerator) &&
+                   try_module_get(accelerator->hooks->owner)) {
                        be->accelerator = accelerator;
                        atomic_inc(&be->accelerator->use_count);
                        be->accelerator->hooks->probe(dev);
@@ -242,9 +243,10 @@ void netback_remove_accelerators(struct backend_info *be,
                                 struct xenbus_device *dev)
 {
        /* Notify the accelerator (if any) of this device's removal */
-       if ( be->accelerator ) {
+       if (be->accelerator) {
                be->accelerator->hooks->remove(dev);
                atomic_dec(&be->accelerator->use_count);
+               module_put(be->accelerator->hooks->owner);
        }
        be->accelerator = NULL;
 }
index 6346dba654b7f73bf6fe6e230ff0ebd8d51f2f6f..784b62878bac9fcb0e566eb4a20e89e7aa3fc954 100644 (file)
@@ -125,6 +125,7 @@ extern int netbk_copy_skb_mode;
 
 /* Function pointers into netback accelerator plugin modules */
 struct netback_accel_hooks {
+       struct module *owner;
        int  (*probe)(struct xenbus_device *dev);
        int (*remove)(struct xenbus_device *dev);
 };