Whamcloud - gitweb
LU-14431 log: Add ending newline for some messages.
[fs/lustre-release.git] / lnet / klnds / gnilnd / gnilnd_conn.c
index 9090f9e..a4d1a5e 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 #include "gnilnd.h"
+#include <linux/swap.h>
 
 void
 kgnilnd_setup_smsg_attr(gni_smsg_attr_t *smsg_attr)
@@ -101,11 +102,11 @@ kgnilnd_alloc_fmablk(kgn_device_t *device, int use_phys)
         * to memory exhaustion during massive reconnects during a network
         * outage. Limit the amount of fma blocks to use by always keeping
         * a percent of pages free initially set to 25% of total memory. */
-       if (global_page_state(NR_FREE_PAGES) < kgnilnd_data.free_pages_limit) {
+       if (nr_free_pages() < kgnilnd_data.free_pages_limit) {
                LCONSOLE_INFO("Exceeding free page limit of %ld. "
                              "Free pages available %ld\n",
                              kgnilnd_data.free_pages_limit,
-                             global_page_state(NR_FREE_PAGES));
+                             nr_free_pages());
                return -ENOMEM;
        }
 #endif
@@ -190,7 +191,7 @@ kgnilnd_alloc_fmablk(kgn_device_t *device, int use_phys)
        }
 
        /* allocate just enough space for the bits to track the mailboxes */
-       LIBCFS_ALLOC(fma_blk->gnm_bit_array, BITS_TO_LONGS(num_mbox) * sizeof(unsigned long));
+       CFS_ALLOC_PTR_ARRAY(fma_blk->gnm_bit_array, BITS_TO_LONGS(num_mbox));
        if (fma_blk->gnm_bit_array == NULL) {
                CNETERR("could not allocate mailbox bitmask, %lu bytes for %d mbox\n",
                       sizeof(unsigned long) * BITS_TO_LONGS(num_mbox), num_mbox);
@@ -199,8 +200,10 @@ kgnilnd_alloc_fmablk(kgn_device_t *device, int use_phys)
        }
        bitmap_zero(fma_blk->gnm_bit_array, num_mbox);
 
-       /* now that the num_mbox is set based on allocation type, get debug info setup */
-       LIBCFS_ALLOC(fma_blk->gnm_mbox_info, sizeof(kgn_mbox_info_t) * num_mbox);
+       /* now that the num_mbox is set based on allocation type, get debug
+        * info setup
+        * */
+       CFS_ALLOC_PTR_ARRAY(fma_blk->gnm_mbox_info, num_mbox);
        if (fma_blk->gnm_mbox_info == NULL) {
                CNETERR("could not allocate mailbox debug, %lu bytes for %d mbox\n",
                       sizeof(kgn_mbox_info_t) * num_mbox, num_mbox);
@@ -238,9 +241,9 @@ kgnilnd_alloc_fmablk(kgn_device_t *device, int use_phys)
        return 0;
 
 free_info:
-       LIBCFS_FREE(fma_blk->gnm_mbox_info, sizeof(kgn_mbox_info_t)*num_mbox);
+       CFS_FREE_PTR_ARRAY(fma_blk->gnm_mbox_info, num_mbox);
 free_bit:
-       LIBCFS_FREE(fma_blk->gnm_bit_array, BITS_TO_LONGS(num_mbox) * sizeof (unsigned long));
+       CFS_FREE_PTR_ARRAY(fma_blk->gnm_bit_array, BITS_TO_LONGS(num_mbox));
 free_blk:
        if (fma_blk->gnm_state == GNILND_FMABLK_VIRT) {
                kgnilnd_vfree(fma_blk->gnm_block, fma_blk->gnm_blk_size);
@@ -353,8 +356,9 @@ kgnilnd_free_fmablk_locked(kgn_device_t *dev, kgn_fma_memblock_t *fma_blk)
 
        list_del(&fma_blk->gnm_bufflist);
 
-       LIBCFS_FREE(fma_blk->gnm_mbox_info, sizeof(kgn_mbox_info_t)*fma_blk->gnm_num_mboxs);
-       LIBCFS_FREE(fma_blk->gnm_bit_array, BITS_TO_LONGS(fma_blk->gnm_num_mboxs) * sizeof (unsigned long));
+       CFS_FREE_PTR_ARRAY(fma_blk->gnm_mbox_info, fma_blk->gnm_num_mboxs);
+       CFS_FREE_PTR_ARRAY(fma_blk->gnm_bit_array,
+                          BITS_TO_LONGS(fma_blk->gnm_num_mboxs));
        LIBCFS_FREE(fma_blk, sizeof(kgn_fma_memblock_t));
 }
 
@@ -517,8 +521,8 @@ kgnilnd_release_mbox(kgn_conn_t *conn, int purgatory_hold)
                        fma_blk->gnm_hndl.qword1, fma_blk->gnm_hndl.qword2);
 
                fma_blk->gnm_held_mboxs++;
-               fma_blk->gnm_max_timeout = MAX(fma_blk->gnm_max_timeout,
-                                               conn->gnc_timeout);
+               fma_blk->gnm_max_timeout = max_t(long, fma_blk->gnm_max_timeout,
+                                                conn->gnc_timeout);
        } else {
                CDEBUG(D_NET, "conn %p smsg %p fmablk %p release SMSG mbox %d "
                        "hndl %#llx.%#llx\n",
@@ -864,7 +868,7 @@ kgnilnd_unpack_connreq(kgn_dgram_t *dgram)
                rc = kgnilnd_find_net(connreq->gncr_dstnid, &net);
 
                if (rc == -ESHUTDOWN) {
-                       CERROR("Looking up network: device is in shutdown");
+                       CERROR("Looking up network: device is in shutdown\n");
                        return rc;
                } else if (rc == -ENONET) {
                        CERROR("Connection data from %s: she sent "
@@ -960,13 +964,10 @@ kgnilnd_alloc_dgram(kgn_dgram_t **dgramp, kgn_device_t *dev, kgn_dgram_type_t ty
 {
        kgn_dgram_t         *dgram;
 
-       dgram = kmem_cache_alloc(kgnilnd_data.kgn_dgram_cache, GFP_ATOMIC);
+       dgram = kmem_cache_zalloc(kgnilnd_data.kgn_dgram_cache, GFP_ATOMIC);
        if (dgram == NULL)
                return -ENOMEM;
 
-       /* cache alloc'd memory is not zeroed */
-       memset((void *)dgram, 0, sizeof(*dgram)) ;
-
        INIT_LIST_HEAD(&dgram->gndg_list);
        dgram->gndg_state = GNILND_DGRAM_USED;
        dgram->gndg_type = type;
@@ -1546,9 +1547,9 @@ failed:
 int
 kgnilnd_cancel_net_dgrams(kgn_net_t *net)
 {
-       kgn_dgram_t            *dg, *dgN;
-       struct list_head        zombies;
-       int                     i;
+       kgn_dgram_t *dg, *dgN;
+       LIST_HEAD(zombies);
+       int i;
        ENTRY;
 
        /* we want to cancel any outstanding dgrams - we don't want to rely
@@ -1561,8 +1562,6 @@ kgnilnd_cancel_net_dgrams(kgn_net_t *net)
                 "in reset %d\n", net->gnn_shutdown,
                 kgnilnd_data.kgn_in_reset);
 
-       INIT_LIST_HEAD(&zombies);
-
        spin_lock(&net->gnn_dev->gnd_dgram_lock);
 
        for (i = 0; i < *kgnilnd_tunables.kgn_peer_hash_size; i++) {
@@ -1588,7 +1587,7 @@ int
 kgnilnd_cancel_wc_dgrams(kgn_device_t *dev)
 {
        kgn_dgram_t *dg, *dgN;
-       struct list_head zombies;
+       LIST_HEAD(zombies);
        ENTRY;
 
        /* Time to kill the outstanding WC's
@@ -1600,7 +1599,6 @@ kgnilnd_cancel_wc_dgrams(kgn_device_t *dev)
                "in reset %d\n", kgnilnd_data.kgn_wc_kill,
                kgnilnd_data.kgn_in_reset);
 
-       INIT_LIST_HEAD(&zombies);
        spin_lock(&dev->gnd_dgram_lock);
 
        do {
@@ -1614,10 +1612,8 @@ kgnilnd_cancel_wc_dgrams(kgn_device_t *dev)
                        kgnilnd_cancel_dgram_locked(dg);
 
                        /* WC could be DONE already, check and if so add to list to be released */
-                       if (dg->gndg_state == GNILND_DGRAM_DONE) {
-                               list_del_init(&dg->gndg_list);
-                               list_add_tail(&dg->gndg_list, &zombies);
-                       }
+                       if (dg->gndg_state == GNILND_DGRAM_DONE)
+                               list_move_tail(&dg->gndg_list, &zombies);
                }
        } while (dg != NULL);
 
@@ -2277,7 +2273,6 @@ kgnilnd_dgram_waitq(void *arg)
        DEFINE_WAIT(mover_done);
 
        snprintf(name, sizeof(name), "kgnilnd_dgn_%02d", dev->gnd_id);
-       cfs_block_allsigs();
 
        /* all gnilnd threads need to run fairly urgently */
        set_user_nice(current, *kgnilnd_tunables.kgn_nice);
@@ -2434,13 +2429,17 @@ kgnilnd_repost_wc_dgrams(kgn_device_t *dev)
        RETURN(did_something);
 }
 
+struct kgnilnd_dgram_timer {
+       struct timer_list timer;
+       kgn_device_t *dev;
+};
+
 static void
-kgnilnd_dgram_poke_with_stick(unsigned long arg)
+kgnilnd_dgram_poke_with_stick(cfs_timer_cb_arg_t arg)
 {
-       int             dev_id = arg;
-       kgn_device_t    *dev = &kgnilnd_data.kgn_devices[dev_id];
+       struct kgnilnd_dgram_timer *t = cfs_from_timer(t, arg, timer);
 
-       wake_up(&dev->gnd_dgram_waitq);
+       wake_up(&t->dev->gnd_dgram_waitq);
 }
 
 /* use single thread for dgrams - should be sufficient for performance */
@@ -2452,12 +2451,12 @@ kgnilnd_dgram_mover(void *arg)
        int                      rc, did_something;
        unsigned long            next_purge_check = jiffies - 1;
        unsigned long            timeout;
-       struct timer_list        timer;
-       unsigned long            deadline = 0;
+       struct kgnilnd_dgram_timer timer;
+       unsigned long deadline = 0;
        DEFINE_WAIT(wait);
 
        snprintf(name, sizeof(name), "kgnilnd_dg_%02d", dev->gnd_id);
-       cfs_block_allsigs();
+
        /* all gnilnd threads need to run fairly urgently */
        set_user_nice(current, *kgnilnd_tunables.kgn_nice);
 
@@ -2521,8 +2520,11 @@ kgnilnd_dgram_mover(void *arg)
 
                prepare_to_wait(&dev->gnd_dgram_waitq, &wait, TASK_INTERRUPTIBLE);
 
-               setup_timer(&timer, kgnilnd_dgram_poke_with_stick, dev->gnd_id);
-               mod_timer(&timer, (long) jiffies + timeout);
+               cfs_timer_setup(&timer.timer,
+                               kgnilnd_dgram_poke_with_stick,
+                               dev, 0);
+               timer.dev = dev;
+               mod_timer(&timer.timer, (long) jiffies + timeout);
 
                /* last second chance for others to poke us */
                did_something += xchg(&dev->gnd_dgram_ready, GNILND_DGRAM_IDLE);
@@ -2541,7 +2543,7 @@ kgnilnd_dgram_mover(void *arg)
                        deadline = jiffies + cfs_time_seconds(*kgnilnd_tunables.kgn_dgram_timeout);
                }
 
-               del_singleshot_timer_sync(&timer);
+               del_singleshot_timer_sync(&timer.timer);
                finish_wait(&dev->gnd_dgram_waitq, &wait);
        }