📄 api-ni.c
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * Copyright (c) 2001-2003 Cluster File Systems, Inc. * * This file is part of Lustre, http://www.sf.net/projects/lustre/ * * Lustre is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. * * Lustre is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Lustre; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#define DEBUG_SUBSYSTEM S_LNET#include <lnet/lib-lnet.h>#ifdef __KERNEL__#define D_LNI D_CONSOLE#else#define D_LNI D_CONFIG#endiflnet_t the_lnet; /* THE state of the network */#ifdef __KERNEL__static char *ip2nets = "";CFS_MODULE_PARM(ip2nets, "s", charp, 0444, "LNET network <- IP table");static char *networks = "";CFS_MODULE_PARM(networks, "s", charp, 0444, "local networks");static char *routes = "";CFS_MODULE_PARM(routes, "s", charp, 0444, "routes to non-local networks");static char *portals_compatibility = "none";CFS_MODULE_PARM(portals_compatibility, "s", charp, 0444, "wire protocol compatibility: 'strong'|'weak'|'none'");char *lnet_get_routes(void){ return routes;}char *lnet_get_networks(void){ char *nets; int rc; if (*networks != 0 && *ip2nets != 0) { LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or " "'ip2nets' but not both at once\n"); return NULL; } if (*ip2nets != 0) { rc = lnet_parse_ip2nets(&nets, ip2nets); return (rc == 0) ? nets : NULL; } if (*networks != 0) return networks; return "tcp";}intlnet_get_portals_compatibility(void){ if (!strcmp(portals_compatibility, "none")) { return 0; } if (!strcmp(portals_compatibility, "weak")) { return 1; LCONSOLE_WARN("Starting in weak portals-compatible mode\n"); } if (!strcmp(portals_compatibility, "strong")) { return 2; LCONSOLE_WARN("Starting in strong portals-compatible mode\n"); } LCONSOLE_ERROR_MSG(0x102, "portals_compatibility=\"%s\" not supported\n", portals_compatibility); return -EINVAL;}voidlnet_init_locks(void){ spin_lock_init (&the_lnet.ln_lock); cfs_waitq_init (&the_lnet.ln_waitq); init_mutex(&the_lnet.ln_lnd_mutex); init_mutex(&the_lnet.ln_api_mutex);}voidlnet_fini_locks(void){}#elsechar *lnet_get_routes(void){ char *str = getenv("LNET_ROUTES"); return (str == NULL) ? "" : str;}char *lnet_get_networks (void){ static char default_networks[256]; char *networks = getenv ("LNET_NETWORKS"); char *ip2nets = getenv ("LNET_IP2NETS"); char *str; char *sep; int len; int nob; int rc; struct list_head *tmp;#ifdef NOT_YET if (networks != NULL && ip2nets != NULL) { LCONSOLE_ERROR_MSG(0x103, "Please set EITHER 'LNET_NETWORKS' or" " 'LNET_IP2NETS' but not both at once\n"); return NULL; } if (ip2nets != NULL) { rc = lnet_parse_ip2nets(&networks, ip2nets); return (rc == 0) ? networks : NULL; }#else ip2nets = NULL; rc = 0;#endif if (networks != NULL) return networks; /* In userland, the default 'networks=' is the list of known net types */ len = sizeof(default_networks); str = default_networks; *str = 0; sep = ""; list_for_each (tmp, &the_lnet.ln_lnds) { lnd_t *lnd = list_entry(tmp, lnd_t, lnd_list); nob = snprintf(str, len, "%s%s", sep, libcfs_lnd2str(lnd->lnd_type)); len -= nob; if (len < 0) { /* overflowed the string; leave it where it was */ *str = 0; break; } str += nob; sep = ","; } return default_networks;}intlnet_get_portals_compatibility(void){ return 0;}# ifndef HAVE_LIBPTHREADvoid lnet_init_locks(void){ the_lnet.ln_lock = 0; the_lnet.ln_lnd_mutex = 0; the_lnet.ln_api_mutex = 0;}void lnet_fini_locks(void){ LASSERT (the_lnet.ln_api_mutex == 0); LASSERT (the_lnet.ln_lnd_mutex == 0); LASSERT (the_lnet.ln_lock == 0);}# elsevoid lnet_init_locks(void){ pthread_cond_init(&the_lnet.ln_cond, NULL); pthread_mutex_init(&the_lnet.ln_lock, NULL); pthread_mutex_init(&the_lnet.ln_lnd_mutex, NULL); pthread_mutex_init(&the_lnet.ln_api_mutex, NULL);}void lnet_fini_locks(void){ pthread_mutex_destroy(&the_lnet.ln_api_mutex); pthread_mutex_destroy(&the_lnet.ln_lnd_mutex); pthread_mutex_destroy(&the_lnet.ln_lock); pthread_cond_destroy(&the_lnet.ln_cond);}# endif#endifvoid lnet_assert_wire_constants (void){ /* Wire protocol assertions generated by 'wirecheck' * running on Linux robert.bartonsoftware.com 2.6.8-1.521 * #1 Mon Aug 16 09:01:18 EDT 2004 i686 athlon i386 GNU/Linux * with gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) */ /* Constants... */ CLASSERT (LNET_PROTO_TCP_MAGIC == 0xeebc0ded); CLASSERT (LNET_PROTO_TCP_VERSION_MAJOR == 1); CLASSERT (LNET_PROTO_TCP_VERSION_MINOR == 0); CLASSERT (LNET_MSG_ACK == 0); CLASSERT (LNET_MSG_PUT == 1); CLASSERT (LNET_MSG_GET == 2); CLASSERT (LNET_MSG_REPLY == 3); CLASSERT (LNET_MSG_HELLO == 4); /* Checks for struct ptl_handle_wire_t */ CLASSERT ((int)sizeof(lnet_handle_wire_t) == 16); CLASSERT ((int)offsetof(lnet_handle_wire_t, wh_interface_cookie) == 0); CLASSERT ((int)sizeof(((lnet_handle_wire_t *)0)->wh_interface_cookie) == 8); CLASSERT ((int)offsetof(lnet_handle_wire_t, wh_object_cookie) == 8); CLASSERT ((int)sizeof(((lnet_handle_wire_t *)0)->wh_object_cookie) == 8); /* Checks for struct lnet_magicversion_t */ CLASSERT ((int)sizeof(lnet_magicversion_t) == 8); CLASSERT ((int)offsetof(lnet_magicversion_t, magic) == 0); CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->magic) == 4); CLASSERT ((int)offsetof(lnet_magicversion_t, version_major) == 4); CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->version_major) == 2); CLASSERT ((int)offsetof(lnet_magicversion_t, version_minor) == 6); CLASSERT ((int)sizeof(((lnet_magicversion_t *)0)->version_minor) == 2); /* Checks for struct lnet_hdr_t */ CLASSERT ((int)sizeof(lnet_hdr_t) == 72); CLASSERT ((int)offsetof(lnet_hdr_t, dest_nid) == 0); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->dest_nid) == 8); CLASSERT ((int)offsetof(lnet_hdr_t, src_nid) == 8); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->src_nid) == 8); CLASSERT ((int)offsetof(lnet_hdr_t, dest_pid) == 16); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->dest_pid) == 4); CLASSERT ((int)offsetof(lnet_hdr_t, src_pid) == 20); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->src_pid) == 4); CLASSERT ((int)offsetof(lnet_hdr_t, type) == 24); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->type) == 4); CLASSERT ((int)offsetof(lnet_hdr_t, payload_length) == 28); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->payload_length) == 4); CLASSERT ((int)offsetof(lnet_hdr_t, msg) == 32); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg) == 40); /* Ack */ CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.dst_wmd) == 32); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.dst_wmd) == 16); CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.match_bits) == 48); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.match_bits) == 8); CLASSERT ((int)offsetof(lnet_hdr_t, msg.ack.mlength) == 56); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.ack.mlength) == 4); /* Put */ CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.ack_wmd) == 32); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.ack_wmd) == 16); CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.match_bits) == 48); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.match_bits) == 8); CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.hdr_data) == 56); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.hdr_data) == 8); CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.ptl_index) == 64); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.ptl_index) == 4); CLASSERT ((int)offsetof(lnet_hdr_t, msg.put.offset) == 68); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.put.offset) == 4); /* Get */ CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.return_wmd) == 32); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.return_wmd) == 16); CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.match_bits) == 48); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.match_bits) == 8); CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.ptl_index) == 56); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.ptl_index) == 4); CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.src_offset) == 60); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.src_offset) == 4); CLASSERT ((int)offsetof(lnet_hdr_t, msg.get.sink_length) == 64); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.get.sink_length) == 4); /* Reply */ CLASSERT ((int)offsetof(lnet_hdr_t, msg.reply.dst_wmd) == 32); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.reply.dst_wmd) == 16); /* Hello */ CLASSERT ((int)offsetof(lnet_hdr_t, msg.hello.incarnation) == 32); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.hello.incarnation) == 8); CLASSERT ((int)offsetof(lnet_hdr_t, msg.hello.type) == 40); CLASSERT ((int)sizeof(((lnet_hdr_t *)0)->msg.hello.type) == 4);}lnd_t *lnet_find_lnd_by_type (int type) { lnd_t *lnd; struct list_head *tmp; /* holding lnd mutex */ list_for_each (tmp, &the_lnet.ln_lnds) { lnd = list_entry(tmp, lnd_t, lnd_list); if (lnd->lnd_type == type) return lnd; } return NULL;}voidlnet_register_lnd (lnd_t *lnd){ LNET_MUTEX_DOWN(&the_lnet.ln_lnd_mutex); LASSERT (the_lnet.ln_init); LASSERT (libcfs_isknown_lnd(lnd->lnd_type)); LASSERT (lnet_find_lnd_by_type(lnd->lnd_type) == NULL); list_add_tail (&lnd->lnd_list, &the_lnet.ln_lnds); lnd->lnd_refcount = 0; CDEBUG(D_NET, "%s LND registered\n", libcfs_lnd2str(lnd->lnd_type)); LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);}voidlnet_unregister_lnd (lnd_t *lnd){ LNET_MUTEX_DOWN(&the_lnet.ln_lnd_mutex); LASSERT (the_lnet.ln_init); LASSERT (lnet_find_lnd_by_type(lnd->lnd_type) == lnd); LASSERT (lnd->lnd_refcount == 0); list_del (&lnd->lnd_list); CDEBUG(D_NET, "%s LND unregistered\n", libcfs_lnd2str(lnd->lnd_type)); LNET_MUTEX_UP(&the_lnet.ln_lnd_mutex);}#ifndef LNET_USE_LIB_FREELISTintlnet_descriptor_setup (void){ return 0;}voidlnet_descriptor_cleanup (void){}#elseintlnet_freelist_init (lnet_freelist_t *fl, int n, int size){ char *space; LASSERT (n > 0); size += offsetof (lnet_freeobj_t, fo_contents); LIBCFS_ALLOC(space, n * size); if (space == NULL) return (-ENOMEM); CFS_INIT_LIST_HEAD (&fl->fl_list); fl->fl_objs = space; fl->fl_nobjs = n; fl->fl_objsize = size; do { memset (space, 0, size); list_add ((struct list_head *)space, &fl->fl_list); space += size; } while (--n != 0); return (0);}voidlnet_freelist_fini (lnet_freelist_t *fl){ struct list_head *el; int count; if (fl->fl_nobjs == 0) return; count = 0; for (el = fl->fl_list.next; el != &fl->fl_list; el = el->next) count++; LASSERT (count == fl->fl_nobjs); LIBCFS_FREE(fl->fl_objs, fl->fl_nobjs * fl->fl_objsize); memset (fl, 0, sizeof (fl));}intlnet_descriptor_setup (void){ /* NB on failure caller must still call lnet_descriptor_cleanup */ /* ****** */ int rc; memset (&the_lnet.ln_free_mes, 0, sizeof (the_lnet.ln_free_mes)); memset (&the_lnet.ln_free_msgs, 0, sizeof (the_lnet.ln_free_msgs)); memset (&the_lnet.ln_free_mds, 0, sizeof (the_lnet.ln_free_mds)); memset (&the_lnet.ln_free_eqs, 0, sizeof (the_lnet.ln_free_eqs));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -