⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib-lnet.h

📁 lustre 1.6.5 source code
💻 H
📖 第 1 页 / 共 2 页
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * lib-lnet.h * * Top level include for library side routines */#ifndef __LNET_LIB_LNET_H__#define __LNET_LIB_LNET_H__#if defined(__linux__)#include <lnet/linux/lib-lnet.h>#elif defined(__APPLE__)#include <lnet/darwin/lib-lnet.h>#elif defined(__WINNT__)#include <lnet/winnt/lib-lnet.h>#else#error Unsupported Operating System#endif#include <lnet/types.h>#include <libcfs/kp30.h>#include <lnet/lnet.h>#include <lnet/lib-types.h>extern lnet_t  the_lnet;                        /* THE network */static inline int lnet_is_wire_handle_none (lnet_handle_wire_t *wh){        return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_NONE.wh_interface_cookie &&                wh->wh_object_cookie == LNET_WIRE_HANDLE_NONE.wh_object_cookie);}static inline int lnet_md_exhausted (lnet_libmd_t *md) {        return (md->md_threshold == 0 ||                ((md->md_options & LNET_MD_MAX_SIZE) != 0 &&                 md->md_offset + md->md_max_size > md->md_length));}static inline int lnet_md_unlinkable (lnet_libmd_t *md){        /* Should unlink md when its refcount is 0 and either:         *  - md has been flagged for deletion (by auto unlink or LNetM[DE]Unlink,         *    in the latter case md may not be exhausted).         *  - auto unlink is on and md is exhausted.         */        if (md->md_refcount != 0)                return 0;        if ((md->md_flags & LNET_MD_FLAG_ZOMBIE) != 0)                return 1;        return ((md->md_flags & LNET_MD_FLAG_AUTO_UNLINK) != 0 &&                lnet_md_exhausted(md));}#ifdef __KERNEL__#define LNET_LOCK()        spin_lock(&the_lnet.ln_lock)                 #define LNET_UNLOCK()      spin_unlock(&the_lnet.ln_lock)               #define LNET_MUTEX_DOWN(m) mutex_down(m)#define LNET_MUTEX_UP(m)   mutex_up(m)#else# ifndef HAVE_LIBPTHREAD#define LNET_SINGLE_THREADED_LOCK(l)            \do {                                            \        LASSERT ((l) == 0);                     \        (l) = 1;                                \} while (0)#define LNET_SINGLE_THREADED_UNLOCK(l)          \do {                                            \        LASSERT ((l) == 1);                     \        (l) = 0;                                \} while (0)#define LNET_LOCK()        LNET_SINGLE_THREADED_LOCK(the_lnet.ln_lock)#define LNET_UNLOCK()      LNET_SINGLE_THREADED_UNLOCK(the_lnet.ln_lock)#define LNET_MUTEX_DOWN(m) LNET_SINGLE_THREADED_LOCK(*(m))#define LNET_MUTEX_UP(m)   LNET_SINGLE_THREADED_UNLOCK(*(m))# else#define LNET_LOCK()        pthread_mutex_lock(&the_lnet.ln_lock)#define LNET_UNLOCK()      pthread_mutex_unlock(&the_lnet.ln_lock)#define LNET_MUTEX_DOWN(m) pthread_mutex_lock(m)#define LNET_MUTEX_UP(m)   pthread_mutex_unlock(m)# endif#endif#define MAX_PORTALS     64#ifdef LNET_USE_LIB_FREELIST#define MAX_MES         2048#define MAX_MDS         2048#define MAX_MSGS        2048    /* Outstanding messages */#define MAX_EQS         512static inline void *lnet_freelist_alloc (lnet_freelist_t *fl){        /* ALWAYS called with liblock held */        lnet_freeobj_t *o;        if (list_empty (&fl->fl_list))                return (NULL);                o = list_entry (fl->fl_list.next, lnet_freeobj_t, fo_list);        list_del (&o->fo_list);        return ((void *)&o->fo_contents);}static inline voidlnet_freelist_free (lnet_freelist_t *fl, void *obj){        /* ALWAYS called with liblock held */        lnet_freeobj_t *o = list_entry (obj, lnet_freeobj_t, fo_contents);                list_add (&o->fo_list, &fl->fl_list);}static inline lnet_eq_t *lnet_eq_alloc (void){        /* NEVER called with liblock held */        lnet_eq_t     *eq;                LNET_LOCK();        eq = (lnet_eq_t *)lnet_freelist_alloc(&the_lnet.ln_free_eqs);        LNET_UNLOCK();        return (eq);}static inline voidlnet_eq_free (lnet_eq_t *eq){        /* ALWAYS called with liblock held */        lnet_freelist_free(&the_lnet.ln_free_eqs, eq);}static inline lnet_libmd_t *lnet_md_alloc (lnet_md_t *umd){        /* NEVER called with liblock held */        lnet_libmd_t  *md;                LNET_LOCK();        md = (lnet_libmd_t *)lnet_freelist_alloc(&the_lnet.ln_free_mds);        LNET_UNLOCK();        return (md);}static inline voidlnet_md_free (lnet_libmd_t *md){        /* ALWAYS called with liblock held */        lnet_freelist_free (&the_lnet.ln_free_mds, md);}static inline lnet_me_t *lnet_me_alloc (void){        /* NEVER called with liblock held */        lnet_me_t     *me;                LNET_LOCK();        me = (lnet_me_t *)lnet_freelist_alloc(&the_lnet.ln_free_mes);        LNET_UNLOCK();                return (me);}static inline voidlnet_me_free (lnet_me_t *me){        /* ALWAYS called with liblock held */        lnet_freelist_free (&the_lnet.ln_free_mes, me);}static inline lnet_msg_t *lnet_msg_alloc (void){        /* NEVER called with liblock held */        lnet_msg_t    *msg;                LNET_LOCK();        msg = (lnet_msg_t *)lnet_freelist_alloc(&the_lnet.ln_free_msgs);        LNET_UNLOCK();        if (msg != NULL) {                /* NULL pointers, clear flags etc */                memset (msg, 0, sizeof (*msg));#ifdef CRAY_XT3                msg->msg_ev.uid = LNET_UID_ANY;#endif        }        return(msg);}static inline voidlnet_msg_free (lnet_msg_t *msg){        /* ALWAYS called with liblock held */        LASSERT (!msg->msg_onactivelist);        lnet_freelist_free(&the_lnet.ln_free_msgs, msg);}#elsestatic inline lnet_eq_t *lnet_eq_alloc (void){        /* NEVER called with liblock held */        lnet_eq_t *eq;        LIBCFS_ALLOC(eq, sizeof(*eq));        return (eq);}static inline voidlnet_eq_free (lnet_eq_t *eq){        /* ALWAYS called with liblock held */        LIBCFS_FREE(eq, sizeof(*eq));}static inline lnet_libmd_t *lnet_md_alloc (lnet_md_t *umd){        /* NEVER called with liblock held */        lnet_libmd_t *md;        int           size;        unsigned int  niov;        if ((umd->options & LNET_MD_KIOV) != 0) {                niov = umd->length;                size = offsetof(lnet_libmd_t, md_iov.kiov[niov]);        } else {                niov = ((umd->options & LNET_MD_IOVEC) != 0) ?                       umd->length : 1;                size = offsetof(lnet_libmd_t, md_iov.iov[niov]);        }        LIBCFS_ALLOC(md, size);        if (md != NULL) {                /* Set here in case of early free */                md->md_options = umd->options;                md->md_niov = niov;        }                return (md);}static inline void lnet_md_free (lnet_libmd_t *md){        /* ALWAYS called with liblock held */        int       size;        if ((md->md_options & LNET_MD_KIOV) != 0)                size = offsetof(lnet_libmd_t, md_iov.kiov[md->md_niov]);        else                size = offsetof(lnet_libmd_t, md_iov.iov[md->md_niov]);        LIBCFS_FREE(md, size);}static inline lnet_me_t *lnet_me_alloc (void){        /* NEVER called with liblock held */        lnet_me_t *me;        LIBCFS_ALLOC(me, sizeof(*me));        return (me);}static inline void lnet_me_free(lnet_me_t *me){        /* ALWAYS called with liblock held */        LIBCFS_FREE(me, sizeof(*me));}static inline lnet_msg_t *lnet_msg_alloc(void){        /* NEVER called with liblock held */        lnet_msg_t *msg;        LIBCFS_ALLOC(msg, sizeof(*msg));        if (msg != NULL) {                /* NULL pointers, clear flags etc */                memset (msg, 0, sizeof (*msg));#ifdef CRAY_XT3                msg->msg_ev.uid = LNET_UID_ANY;#endif        }        return (msg);}static inline void lnet_msg_free(lnet_msg_t *msg){        /* ALWAYS called with liblock held */        LASSERT (!msg->msg_onactivelist);        LIBCFS_FREE(msg, sizeof(*msg));}#endifextern lnet_libhandle_t *lnet_lookup_cookie (__u64 cookie, int type);extern void lnet_initialise_handle (lnet_libhandle_t *lh, int type);extern void lnet_invalidate_handle (lnet_libhandle_t *lh);static inline voidlnet_eq2handle (lnet_handle_eq_t *handle, lnet_eq_t *eq){        if (eq == NULL) {                *handle = LNET_EQ_NONE;                return;        }        handle->cookie = eq->eq_lh.lh_cookie;}static inline lnet_eq_t *lnet_handle2eq (lnet_handle_eq_t *handle){        /* ALWAYS called with liblock held */        lnet_libhandle_t *lh = lnet_lookup_cookie(handle->cookie,                                                   LNET_COOKIE_TYPE_EQ);        if (lh == NULL)                return (NULL);        return (lh_entry (lh, lnet_eq_t, eq_lh));}static inline void

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -