# include <unistd.h>
# include <time.h>
# include <limits.h>
+# include <errno.h>
+# include <sys/ioctl.h> /* for _IOWR */
+
+# define CFS_MODULE_PARM(name, t, type, perm, desc)
#endif /* End of !__KERNEL__ */
void spin_lock_bh(spinlock_t *lock);
void spin_unlock_bh(spinlock_t *lock);
-#define spin_lock_irqsave(l, flags) ({ spin_lock(l); (void)flags; })
-#define spin_unlock_irqrestore(l, flags) ({ spin_unlock(l); (void)flags; })
+static inline void
+spin_lock_irqsave(spinlock_t *l, unsigned long f) { spin_lock(l); }
+static inline void
+spin_unlock_irqrestore(spinlock_t *l, unsigned long f) { spin_unlock(l); }
/*
* Semaphore
#define write_lock(l) down_write(l)
#define write_unlock(l) up_write(l)
-#define write_lock_irqsave(l, f) write_lock(l)
-#define write_unlock_irqrestore(l, f) write_unlock(l)
+static inline void
+write_lock_irqsave(rwlock_t *l, unsigned long f) { write_lock(l); }
+static inline void
+write_unlock_irqrestore(rwlock_t *l, unsigned long f) { write_unlock(l); }
-#define read_lock_irqsave(l, f) read_lock(l)
-#define read_unlock_irqrestore(l, f) read_unlock(l)
+static inline void
+read_lock_irqsave(rwlock_t *l, unsigned long f) { read_lock(l); }
+static inline void
+read_unlock_irqrestore(rwlock_t *l, unsigned long f) { read_unlock(l); }
/* !__KERNEL__ */
#endif
cfs_time_t cfs_timer_deadline(struct cfs_timer *t);
#endif
+#define in_interrupt() (0)
+
+static inline void cfs_pause(cfs_duration_t d)
+{
+ struct timespec s;
+
+ cfs_duration_nsec(d, &s);
+ nanosleep(&s, NULL);
+}
+
typedef void cfs_psdev_t;
static inline int cfs_psdev_register(cfs_psdev_t *foo)
return seconds;
}
+static inline time_t cfs_time_current_sec(void)
+{
+ return cfs_time_seconds(cfs_time_current());
+}
+
static inline int cfs_time_before(cfs_time_t t1, cfs_time_t t2)
{
return t1 < t2;
+++ /dev/null
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- */
-#ifndef __PORTALS_KPR_H__
-#define __PORTALS_KPR_H__
-
-# include <portals/lib-types.h> /* for ptl_hdr_t */
-
-
-#endif /* _KPR_H */
#define PTL_UNLOCK(flags) \
pthread_mutex_unlock(&ptl_apini.apini_mutex)
#define PTL_MUTEX_DOWN(m) pthread_mutex_lock(m)
-#define PTL_MUTEX_UP(m) pthread_mutex_up(m)
+#define PTL_MUTEX_UP(m) pthread_mutex_unlock(m)
#endif
#ifdef PTL_USE_LIB_FREELIST
/******************************************************************************/
static inline void
+ptl_ni_addref_locked(ptl_ni_t *ni)
+{
+ LASSERT (ni->ni_refcount > 0);
+ ni->ni_refcount++;
+}
+
+static inline void
ptl_ni_addref(ptl_ni_t *ni)
{
- LASSERT (atomic_read(&ni->ni_refcount) > 0);
- atomic_inc(&ni->ni_refcount);
+ unsigned long flags;
+
+ PTL_LOCK(flags);
+ ptl_ni_addref_locked(ni);
+ PTL_UNLOCK(flags);
}
-extern void ptl_queue_zombie_ni (ptl_ni_t *ni);
+static inline void
+ptl_ni_decref_locked(ptl_ni_t *ni)
+{
+ LASSERT (ni->ni_refcount > 0);
+ ni->ni_refcount--;
+ if (ni->ni_refcount == 0)
+ list_add_tail(&ni->ni_list, &ptl_apini.apini_zombie_nis);
+}
static inline void
ptl_ni_decref(ptl_ni_t *ni)
{
- /* CAVEAT EMPTOR! must NOT be holding PTL_LOCK() (deadlock) */
- LASSERT (atomic_read(&ni->ni_refcount) > 0);
- if (atomic_dec_and_test(&ni->ni_refcount))
- ptl_queue_zombie_ni(ni);
+ unsigned long flags;
+
+ PTL_LOCK(flags);
+ ptl_ni_decref_locked(ni);
+ PTL_UNLOCK(flags);
}
extern ptl_nal_t ptl_lonal;
extern void ptl_unregister_nal(ptl_nal_t *nal);
extern ptl_err_t ptl_set_ip_niaddr (ptl_ni_t *ni);
+#ifdef __KERNEL__
extern ptl_err_t ptl_connect(struct socket **sockp, ptl_nid_t peer_nid,
__u32 local_ip, __u32 peer_ip, int peer_port);
extern void ptl_connect_console_error(int rc, ptl_nid_t peer_nid,
extern ptl_err_t ptl_accept(struct socket *sock, __u32 magic, int choose_ni);
extern int ptl_acceptor_timeout(void);
extern int ptl_acceptor_port(void);
+#endif
extern ptl_err_t ptl_acceptor_start(void);
extern void ptl_acceptor_stop(void);
#define PTL_UNLOCK(flags) \
pthread_mutex_unlock(&ptl_apini.apini_mutex)
#define PTL_MUTEX_DOWN(m) pthread_mutex_lock(m)
-#define PTL_MUTEX_UP(m) pthread_mutex_up(m)
+#define PTL_MUTEX_UP(m) pthread_mutex_unlock(m)
#endif
#ifdef PTL_USE_LIB_FREELIST
/******************************************************************************/
static inline void
+ptl_ni_addref_locked(ptl_ni_t *ni)
+{
+ LASSERT (ni->ni_refcount > 0);
+ ni->ni_refcount++;
+}
+
+static inline void
ptl_ni_addref(ptl_ni_t *ni)
{
- LASSERT (atomic_read(&ni->ni_refcount) > 0);
- atomic_inc(&ni->ni_refcount);
+ unsigned long flags;
+
+ PTL_LOCK(flags);
+ ptl_ni_addref_locked(ni);
+ PTL_UNLOCK(flags);
}
-extern void ptl_queue_zombie_ni (ptl_ni_t *ni);
+static inline void
+ptl_ni_decref_locked(ptl_ni_t *ni)
+{
+ LASSERT (ni->ni_refcount > 0);
+ ni->ni_refcount--;
+ if (ni->ni_refcount == 0)
+ list_add_tail(&ni->ni_list, &ptl_apini.apini_zombie_nis);
+}
static inline void
ptl_ni_decref(ptl_ni_t *ni)
{
- /* CAVEAT EMPTOR! must NOT be holding PTL_LOCK() (deadlock) */
- LASSERT (atomic_read(&ni->ni_refcount) > 0);
- if (atomic_dec_and_test(&ni->ni_refcount))
- ptl_queue_zombie_ni(ni);
+ unsigned long flags;
+
+ PTL_LOCK(flags);
+ ptl_ni_decref_locked(ni);
+ PTL_UNLOCK(flags);
}
extern ptl_nal_t ptl_lonal;
extern void ptl_unregister_nal(ptl_nal_t *nal);
extern ptl_err_t ptl_set_ip_niaddr (ptl_ni_t *ni);
+#ifdef __KERNEL__
extern ptl_err_t ptl_connect(struct socket **sockp, ptl_nid_t peer_nid,
__u32 local_ip, __u32 peer_ip, int peer_port);
extern void ptl_connect_console_error(int rc, ptl_nid_t peer_nid,
extern ptl_err_t ptl_accept(struct socket *sock, __u32 magic, int choose_ni);
extern int ptl_acceptor_timeout(void);
extern int ptl_acceptor_port(void);
+#endif
extern ptl_err_t ptl_acceptor_start(void);
extern void ptl_acceptor_stop(void);
{
/* fields managed by portals */
struct list_head nal_list; /* stash in the NAL table */
- atomic_t nal_refcount; /* # active instances */
+ int nal_refcount; /* # active instances */
/* fields initialised by the NAL */
unsigned int nal_type;
void *ni_data; /* instance-specific data */
ptl_nal_t *ni_nal; /* procedural interface */
int ni_shutdown; /* shutting down? */
- atomic_t ni_refcount; /* reference count */
+ int ni_refcount; /* reference count */
char *ni_interfaces[PTL_MAX_INTERFACES]; /* equivalent interfaces to use */
} ptl_ni_t;
/* lose extra ref from ptl_net2ni NB we wait for all the peers
* to be deleted before ni teardown can complete; i.e. ni can't
* disappear until all its peer table entries has gone so
- * there's no to account the peer's refs on ni. */
+ * there's no need to account the peer's refs on ni. */
ptl_ni_decref(ni);
if (rc != 0)
LASSERT (ptl_find_nal_by_type(nal->nal_type) == NULL);
list_add (&nal->nal_list, &ptl_apini.apini_nals);
- atomic_set(&nal->nal_refcount, 0);
+ nal->nal_refcount = 0;
+
if (nal->nal_type != LONAL)
LCONSOLE(0, "%s NAL registered\n",
libcfs_nal2str(nal->nal_type));
LASSERT (ptl_apini.apini_init);
LASSERT (ptl_find_nal_by_type(nal->nal_type) == nal);
- LASSERT (atomic_read(&nal->nal_refcount) == 0);
+ LASSERT (nal->nal_refcount == 0);
list_del (&nal->nal_list);
if (nal->nal_type != LONAL)
ni = list_entry(tmp, ptl_ni_t, ni_list);
if (PTL_NIDNET(ni->ni_nid) == net) {
- ptl_ni_addref(ni);
+ ptl_ni_addref_locked(ni);
PTL_UNLOCK(flags);
return ni;
}
* *first_ni so the acceptor can pass it connections "blind" to retain
* binary compatibility. */
int count = 0;
+#ifdef __KERNEL__
unsigned long flags;
struct list_head *tmp;
ptl_ni_t *ni;
if (ni->ni_nal->nal_accept != NULL) {
/* This NAL uses the acceptor */
if (count == 0 && first_ni != NULL) {
- ptl_ni_addref(ni);
+ ptl_ni_addref_locked(ni);
*first_ni = ni;
}
count++;
}
PTL_UNLOCK(flags);
-
+#endif
return count;
}
}
void
-ptl_queue_zombie_ni (ptl_ni_t *ni)
-{
- unsigned long flags;
-
- LASSERT (atomic_read(&ni->ni_refcount) == 0);
- LASSERT (ptl_apini.apini_init);
-
- PTL_LOCK(flags);
- list_add_tail(&ni->ni_list, &ptl_apini.apini_zombie_nis);
- PTL_UNLOCK(flags);
-}
-
-void
ptl_shutdown_nalnis (void)
{
int i;
ni->ni_shutdown = 1;
ptl_apini.apini_nzombie_nis++;
- PTL_UNLOCK(flags);
- ptl_ni_decref(ni); /* drop apini's ref (shutdown on last ref) */
-
- PTL_LOCK(flags);
+ ptl_ni_decref_locked(ni); /* drop apini's ref (shutdown on last ref) */
}
/* Now wait for the NI's I just nuked to show up on apini_zombie_nis
if ((i & (-i)) == i)
CDEBUG(D_WARNING,"Waiting for %d zombie NIs\n",
ptl_apini.apini_nzombie_nis);
- set_current_state(TASK_UNINTERRUPTIBLE);
- schedule_timeout(cfs_time_seconds(1));
+ cfs_pause(cfs_time_seconds(1));
PTL_LOCK(flags);
}
ni = list_entry(ptl_apini.apini_zombie_nis.next,
ptl_ni_t, ni_list);
list_del(&ni->ni_list);
+ ni->ni_nal->nal_refcount--;
PTL_UNLOCK(flags);
LASSERT (!in_interrupt());
- atomic_dec(&ni->ni_nal->nal_refcount);
(ni->ni_nal->nal_shutdown)(ni);
/* can't deref nal anymore now; it might have unregistered
nal = ptl_find_nal_by_type(nal_type);
if (nal != NULL)
break;
-
- PTL_MUTEX_UP(&ptl_apini.apini_nal_mutex);
+ PTL_MUTEX_UP(&ptl_apini.apini_nal_mutex);
+#ifdef __KERNEL
if (retry) {
CERROR("Can't load NAL %s, module %s\n",
libcfs_nal2str(nal_type),
}
request_module(libcfs_nal2modname(nal_type));
-
+#else
+ CERROR("NAL %s not supported\n",
+ libcfs_nal2str(nal_type));
+ goto failed;
+#endif
PTL_MUTEX_DOWN(&ptl_apini.apini_nal_mutex);
}
- atomic_set(&ni->ni_refcount, 1);
- atomic_inc(&nal->nal_refcount);
+ ni->ni_refcount = 1;
+
+ PTL_LOCK(flags);
+ nal->nal_refcount++;
+ PTL_UNLOCK(flags);
+
ni->ni_nal = nal;
rc = (nal->nal_startup)(ni);
if (rc != PTL_OK) {
CERROR("Error %d starting up NI %s\n",
rc, libcfs_nal2str(nal->nal_type));
- atomic_dec(&nal->nal_refcount);
+ PTL_LOCK(flags);
+ nal->nal_refcount--;
+ PTL_UNLOCK(flags);
goto failed;
}
#else
pthread_mutex_init(&ptl_apini.apini_mutex, NULL);
pthread_cond_init(&ptl_apini.apini_cond, NULL);
- pthread_mutex_init(&ptl_apini.apini_nal_mutex);
- pthread_mutex_init(&ptl_apini.apini_api_mutex);
+ pthread_mutex_init(&ptl_apini.apini_nal_mutex, NULL);
+ pthread_mutex_init(&ptl_apini.apini_api_mutex, NULL);
#endif
ptl_apini.apini_init = 1;
static int ptl_tbnob = 0; /* track text buf allocation */
#define PTL_MAX_TEXTBUF_NOB (64<<10) /* bound allocation */
+#define PTL_SINGLE_TEXTBUF_NOB (4<<10)
void
ptl_syntax(char *name, char *str, int offset, int width)
ptl_ni_t *ni = NULL;
__u32 net;
- if (strlen(networks) > PAGE_SIZE) {
+ if (strlen(networks) > PTL_SINGLE_TEXTBUF_NOB) {
/* _WAY_ conservative */
CERROR("Can't parse networks; string too long\n");
return PTL_FAIL;
int nob;
nob = offsetof(ptl_text_buf_t, ptb_text[str_len + 1]);
- if (nob > PAGE_SIZE) {
+ if (nob > PTL_SINGLE_TEXTBUF_NOB) {
/* _way_ conservative for "route net gateway..." */
CERROR("text buffer too big\n");
return NULL;
ptl_parse_route (char *str)
{
/* static scratch buffer OK (single threaded) */
- static char cmd[PAGE_SIZE];
+ static char cmd[PTL_SINGLE_TEXTBUF_NOB];
struct list_head nets;
struct list_head gateways;
EXPORT_SYMBOL(ptl_parse);
EXPORT_SYMBOL(ptl_create_reply_msg);
EXPORT_SYMBOL(ptl_net2ni);
-EXPORT_SYMBOL(ptl_queue_zombie_ni);
MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
MODULE_DESCRIPTION("Portals v3.1");
#include "router.h"
+#ifdef __KERNEL__
+
kpr_state_t kpr_state;
static int forwarding = 0;
void
kpr_finalise (void)
{
-#ifdef __KERNEL__
kpr_proc_fini();
-#endif
+
while (!list_empty (&kpr_state.kpr_nets)) {
kpr_net_entry_t *ne = list_entry(kpr_state.kpr_nets.next,
kpr_net_entry_t, kpne_list);
if (rc != PTL_OK)
kpr_finalise();
-#ifdef __KERNEL__
if (rc == PTL_OK)
kpr_proc_init();
-#endif
return (rc == PTL_OK) ? 0 : -EINVAL;
}
EXPORT_SYMBOL(kpr_fwd_start);
EXPORT_SYMBOL(kpr_fwd_done);
EXPORT_SYMBOL(kpr_notify);
+
+#else
+
+ptl_nid_t
+kpr_lookup (ptl_ni_t **nip, ptl_nid_t target_nid, int nob)
+{
+ ptl_ni_t *ni = *nip;
+ ptl_ni_t *gwni;
+ __u32 target_net = PTL_NIDNET(target_nid);
+
+ if (ni == NULL) { /* ni not determined yet */
+ gwni = ptl_net2ni(target_net); /* is it a local network? */
+ if (gwni != NULL) {
+ *nip = gwni;
+ return target_nid;
+ }
+ } else { /* ni already determined */
+ if (target_net == PTL_NIDNET(ni->ni_nid)) {
+ ptl_ni_addref(ni); /* extra ref so caller can drop blindly */
+ return target_nid;
+ }
+ }
+
+ CERROR("Nid %s is not on a local network\n",
+ libcfs_nid2str(target_nid));
+
+ return PTL_NID_ANY;
+}
+
+int
+kpr_add_route (__u32 net, ptl_nid_t gateway_nid)
+{
+ return -EOPNOTSUPP;
+}
+
+int
+kpr_ctl(unsigned int cmd, void *arg)
+{
+ return -EINVAL;
+}
+
+void
+kpr_finalise (void)
+{
+}
+
+int
+kpr_initialise (void)
+{
+ return 0;
+}
+
+#endif
# define EXPORT_SYMTAB
#endif
-#include <linux/config.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
-#include <linux/string.h>
-#include <linux/errno.h>
-#include <linux/proc_fs.h>
-#include <linux/init.h>
-
#define DEBUG_SUBSYSTEM S_PTLROUTER
-#include <libcfs/kp30.h>
-#include <portals/kpr.h>
-#include <portals/p30.h>
#include <portals/lib-p30.h>
+#ifdef __KERNEL__
+
typedef struct
{
struct list_head kpge_list;
extern void kpr_proc_init (void);
extern void kpr_proc_fini (void);
+#endif /* __KERNEL__ */
#endif /* _KPLROUTER_H */
syscall(SYS_write, p->notifier[0], buf, sizeof(buf));
}
-/* forward decl */
-extern ptl_err_t procbridge_startup (ptl_ni_t *, char **);
-extern void procbridge_shutdown (ptl_ni_t *);
-extern ptl_err_t tcpnal_send(ptl_ni_t *ni, void *private, ptl_msg_t *cookie,
- ptl_hdr_t *hdr, int type, ptl_nid_t nid, ptl_pid_t pid,
- unsigned int niov, struct iovec *iov,
- size_t offset, size_t len);
-extern ptl_err_t tcpnal_recv(ptl_ni_t *ni, void *private, ptl_msg_t *cookie,
- unsigned int niov, struct iovec *iov,
- size_t offset, size_t mlen, size_t rlen);
-
ptl_nal_t tcpnal_nal = {
.nal_type = SOCKNAL,
.nal_startup = procbridge_startup,
extern void set_address(bridge t,ptl_pid_t pidrequest);
extern void procbridge_wakeup_nal(procbridge p);
+extern ptl_err_t procbridge_startup (ptl_ni_t *);
+extern void procbridge_shutdown (ptl_ni_t *);
+
+extern ptl_err_t tcpnal_send(ptl_ni_t *ni, void *private, ptl_msg_t *cookie,
+ ptl_hdr_t *hdr, int type, ptl_process_id_t target,
+ int routing, unsigned int niov, struct iovec *iov,
+ size_t offset, size_t len);
+ptl_err_t tcpnal_recv(ptl_ni_t *ni, void *private, ptl_msg_t *cookie,
+ unsigned int niov, struct iovec *iov,
+ size_t offset, size_t mlen, size_t rlen);
+
+
+
+
#endif
syscall(SYS_write, p->notifier[0], buf, sizeof(buf));
}
-/* forward decl */
-extern ptl_err_t procbridge_startup (ptl_ni_t *, char **);
-extern void procbridge_shutdown (ptl_ni_t *);
-extern ptl_err_t tcpnal_send(ptl_ni_t *ni, void *private, ptl_msg_t *cookie,
- ptl_hdr_t *hdr, int type, ptl_nid_t nid, ptl_pid_t pid,
- unsigned int niov, struct iovec *iov,
- size_t offset, size_t len);
-extern ptl_err_t tcpnal_recv(ptl_ni_t *ni, void *private, ptl_msg_t *cookie,
- unsigned int niov, struct iovec *iov,
- size_t offset, size_t mlen, size_t rlen);
-
ptl_nal_t tcpnal_nal = {
.nal_type = SOCKNAL,
.nal_startup = procbridge_startup,
extern void set_address(bridge t,ptl_pid_t pidrequest);
extern void procbridge_wakeup_nal(procbridge p);
+extern ptl_err_t procbridge_startup (ptl_ni_t *);
+extern void procbridge_shutdown (ptl_ni_t *);
+
+extern ptl_err_t tcpnal_send(ptl_ni_t *ni, void *private, ptl_msg_t *cookie,
+ ptl_hdr_t *hdr, int type, ptl_process_id_t target,
+ int routing, unsigned int niov, struct iovec *iov,
+ size_t offset, size_t len);
+ptl_err_t tcpnal_recv(ptl_ni_t *ni, void *private, ptl_msg_t *cookie,
+ unsigned int niov, struct iovec *iov,
+ size_t offset, size_t mlen, size_t rlen);
+
+
+
+
#endif
#include <netinet/in.h>
#include <pqtimer.h>
#include <dispatch.h>
-#include <bridge.h>
-#include <ipmap.h>
+#include <procbridge.h>
#include <connection.h>
-#include <pthread.h>
#include <errno.h>
#ifndef __CYGWIN__
#include <syscall.h>
#include <netinet/in.h>
#include <pqtimer.h>
#include <dispatch.h>
-#include <bridge.h>
-#include <ipmap.h>
+#include <procbridge.h>
#include <connection.h>
-#include <pthread.h>
#include <errno.h>
#ifndef __CYGWIN__
#include <syscall.h>
"%s, %s, state %d\n",
data.ioc_u32[0],
data.ioc_count,
- data.ioc_nid,
- data.ioc_u64[0],
+ libcfs_nid2str(data.ioc_nid),
+ libcfs_nid2str(data.ioc_u64[0]),
data.ioc_u32[1],
(data.ioc_flags & 1) ? "delayed" : "immediate",
(data.ioc_flags & 2) ? "nblk" : "normal",
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <portals/api-support.h>
-
-/* This ghastly hack to allows me to include lib-types.h It doesn't affect any
- * assertions generated here (but fails-safe if it ever does) */
-typedef struct {
- int counter;
-} atomic_t;
-
-#include <portals/lib-types.h>
+#include <portals/lib-p30.h>
#include <string.h>