From: Mike Christie <[EMAIL PROTECTED]>

We need to reserve some exchanges so we can make forward progress
even if normal memory allocations fail.

Signed-off-by: Mike Christie <[EMAIL PROTECTED]>
---
 drivers/scsi/libfc/fc_exch.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index a273a2f..207e849 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -112,6 +112,7 @@ struct fc_exch_mgr {
        u32     total_exches;           /* total allocated exchanges */
        struct list_head        ex_list;        /* allocated exchanges list */
        struct fc_lport *lp;            /* fc device instance */
+       mempool_t       *ep_pool;       /* reserve ep's */
 
        /*
         * currently exchange mgr stats are updated but not used.
@@ -292,7 +293,7 @@ static void fc_exch_release(struct fc_exch *ep)
 
                WARN_ON(!ep->esb_stat & ESB_ST_COMPLETE);
                WARN_ON(timer_pending(&ep->ex_timer));
-               kmem_cache_free(fc_em_cachep, ep);
+               mempool_free(ep, mp->ep_pool);
        }
 }
 
@@ -463,11 +464,12 @@ struct fc_exch *fc_exch_alloc(struct fc_exch_mgr *mp, u16 
xid)
        /*
         * Allocate new exchange
         */
-       ep = kmem_cache_zalloc(fc_em_cachep, GFP_ATOMIC);
+       ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
        if (!ep) {
                atomic_inc(&mp->stats.no_free_exch);
                goto out;
        }
+       memset(ep, 0, sizeof(*ep));
 
        spin_lock_bh(&mp->em_lock);
 
@@ -491,7 +493,7 @@ struct fc_exch *fc_exch_alloc(struct fc_exch_mgr *mp, u16 
xid)
                } else {
                        spin_unlock_bh(&mp->em_lock);
                        atomic_inc(&mp->stats.no_free_exch_xid);
-                       kmem_cache_free(fc_em_cachep, ep);
+                       mempool_free(ep, mp->ep_pool);
                        goto out;
                }
        }
@@ -1763,7 +1765,16 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport 
*lp,
                INIT_LIST_HEAD(&mp->ex_list);
                spin_lock_init(&mp->em_lock);
        }
+
+       mp->ep_pool = mempool_create_slab_pool(2, fc_em_cachep);
+       if (!mp->ep_pool)
+               goto free_mp;
+
        return mp;
+
+free_mp:
+       kfree(mp);
+       return NULL;
 }
 EXPORT_SYMBOL(fc_exch_mgr_alloc);
 
@@ -1775,6 +1786,7 @@ void fc_exch_mgr_free(struct fc_exch_mgr *mp)
         * before freeing exchange manager.
         */
        WARN_ON(mp->total_exches != 0);
+       mempool_destroy(mp->ep_pool);
        kfree(mp);
 }
 EXPORT_SYMBOL(fc_exch_mgr_free);
-- 
1.5.4.1

_______________________________________________
devel mailing list
[email protected]
http://www.open-fcoe.org/mailman/listinfo/devel

Reply via email to