1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
10 # define offsetof(typ,memb) ((int)((char *)&(((typ *)0)->memb)))
13 #define LOWEST_BIT_SET(x) ((x) & ~((x) - 1))
18 extern unsigned int portal_subsystem_debug;
19 extern unsigned int portal_stack;
20 extern unsigned int portal_debug;
21 extern unsigned int portal_printk;
22 extern unsigned int portal_cerror;
23 /* Debugging subsystems (32 bits, non-overlapping) */
24 #define S_UNDEFINED (1 << 0)
25 #define S_MDC (1 << 1)
26 #define S_MDS (1 << 2)
27 #define S_OSC (1 << 3)
28 #define S_OST (1 << 4)
29 #define S_CLASS (1 << 5)
30 #define S_LOG (1 << 6)
31 #define S_LLITE (1 << 7)
32 #define S_RPC (1 << 8)
33 #define S_MGMT (1 << 9)
34 #define S_PORTALS (1 << 10)
35 #define S_SOCKNAL (1 << 11)
36 #define S_QSWNAL (1 << 12)
37 #define S_PINGER (1 << 13)
38 #define S_FILTER (1 << 14)
39 #define S_PTLBD (1 << 15)
40 #define S_ECHO (1 << 16)
41 #define S_LDLM (1 << 17)
42 #define S_LOV (1 << 18)
43 #define S_GMNAL (1 << 19)
44 #define S_PTLROUTER (1 << 20)
45 #define S_COBD (1 << 21)
46 #define S_IBNAL (1 << 22)
48 /* If you change these values, please keep portals/utils/debug.c
51 /* Debugging masks (32 bits, non-overlapping) */
52 #define D_TRACE (1 << 0) /* ENTRY/EXIT markers */
53 #define D_INODE (1 << 1)
54 #define D_SUPER (1 << 2)
55 #define D_EXT2 (1 << 3) /* anything from ext2_debug */
56 #define D_MALLOC (1 << 4) /* print malloc, free information */
57 #define D_CACHE (1 << 5) /* cache-related items */
58 #define D_INFO (1 << 6) /* general information */
59 #define D_IOCTL (1 << 7) /* ioctl related information */
60 #define D_BLOCKS (1 << 8) /* ext2 block allocation */
61 #define D_NET (1 << 9) /* network communications */
62 #define D_WARNING (1 << 10) /* CWARN(...) == CDEBUG (D_WARNING, ...) */
63 #define D_BUFFS (1 << 11)
64 #define D_OTHER (1 << 12)
65 #define D_DENTRY (1 << 13)
66 #define D_PORTALS (1 << 14) /* ENTRY/EXIT markers */
67 #define D_PAGE (1 << 15) /* bulk page handling */
68 #define D_DLMTRACE (1 << 16)
69 #define D_ERROR (1 << 17) /* CERROR(...) == CDEBUG (D_ERROR, ...) */
70 #define D_EMERG (1 << 18) /* CEMERG(...) == CDEBUG (D_EMERG, ...) */
71 #define D_HA (1 << 19) /* recovery and failover */
72 #define D_RPCTRACE (1 << 20) /* for distributed debugging */
73 #define D_VFSTRACE (1 << 21)
76 # include <linux/sched.h> /* THREAD_SIZE */
78 # ifndef THREAD_SIZE /* x86_64 has THREAD_SIZE in userspace */
79 # define THREAD_SIZE 8192
83 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
87 # define CDEBUG_STACK (THREAD_SIZE - \
88 ((unsigned long)__builtin_dwarf_cfa() & \
91 # define CDEBUG_STACK (THREAD_SIZE - \
92 ((unsigned long)__builtin_frame_address(0) & \
96 #define CHECK_STACK(stack) \
98 if ((stack) > 3*THREAD_SIZE/4 && (stack) > portal_stack) { \
99 portals_debug_msg(DEBUG_SUBSYSTEM, D_ERROR, \
100 __FILE__, __FUNCTION__, __LINE__, \
102 "maximum lustre stack %u\n", \
103 portal_stack = (stack)); \
107 #else /* __KERNEL__ */
108 #define CHECK_STACK(stack) do { } while(0)
109 #define CDEBUG_STACK (0L)
110 #endif /* __KERNEL__ */
113 #define CDEBUG(mask, format, a...) \
115 if (portal_cerror == 0) \
117 CHECK_STACK(CDEBUG_STACK); \
118 if (!(mask) || ((mask) & (D_ERROR | D_EMERG)) || \
119 (portal_debug & (mask) && \
120 portal_subsystem_debug & DEBUG_SUBSYSTEM)) \
121 portals_debug_msg(DEBUG_SUBSYSTEM, mask, \
122 __FILE__, __FUNCTION__, __LINE__, \
123 CDEBUG_STACK, format, ## a); \
126 #define CWARN(format, a...) CDEBUG(D_WARNING, format, ## a)
127 #define CERROR(format, a...) CDEBUG(D_ERROR, format, ## a)
128 #define CEMERG(format, a...) CDEBUG(D_EMERG, format, ## a)
130 #define GOTO(label, rc) \
132 long GOTO__ret = (long)(rc); \
133 CDEBUG(D_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n", \
134 #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret,\
135 (signed long)GOTO__ret); \
141 typeof(rc) RETURN__ret = (rc); \
142 CDEBUG(D_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n", \
143 (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret);\
144 return RETURN__ret; \
149 CDEBUG(D_TRACE, "Process entered\n"); \
154 CDEBUG(D_TRACE, "Process leaving\n"); \
157 #define CDEBUG(mask, format, a...) do { } while (0)
158 #define CWARN(format, a...) do { } while (0)
159 #define CERROR(format, a...) printk("<3>" format, ## a)
160 #define CEMERG(format, a...) printk("<0>" format, ## a)
161 #define GOTO(label, rc) do { (void)(rc); goto label; } while (0)
162 #define RETURN(rc) return (rc)
163 #define ENTRY do { } while (0)
164 #define EXIT do { } while (0)
168 # include <linux/vmalloc.h>
169 # include <linux/time.h>
170 # include <linux/slab.h>
171 # include <linux/interrupt.h>
172 # include <linux/highmem.h>
173 # include <linux/module.h>
174 # include <linux/version.h>
175 # include <portals/lib-nal.h>
176 # include <linux/smp_lock.h>
177 # include <asm/atomic.h>
179 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
180 #define schedule_work schedule_task
181 #define prepare_work(wq,cb,cbdata) \
183 INIT_TQUEUE((wq), 0, 0); \
184 PREPARE_TQUEUE((wq), (cb), (cbdata)); \
187 #define ll_invalidate_inode_pages invalidate_inode_pages
188 #define PageUptodate Page_Uptodate
189 #define our_recalc_sigpending(current) recalc_sigpending(current)
190 #define num_online_cpus() smp_num_cpus
191 static inline void our_cond_resched(void)
193 if (current->need_resched)
196 #define work_struct_t struct tq_struct
200 #define prepare_work(wq,cb,cbdata) \
202 INIT_WORK((wq), (void *)(cb), (void *)(cbdata)); \
204 #define ll_invalidate_inode_pages(inode) invalidate_inode_pages((inode)->i_mapping)
205 #define wait_on_page wait_on_page_locked
206 #define our_recalc_sigpending(current) recalc_sigpending()
207 #define strtok(a,b) strpbrk(a, b)
208 static inline void our_cond_resched(void)
212 #define work_struct_t struct work_struct
214 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
217 extern void kportal_assertion_failed(char *expr, char *file, const char *func,
219 #define LASSERT(e) ((e) ? 0 : kportal_assertion_failed( #e , __FILE__, \
220 __FUNCTION__, __LINE__))
221 /* it would be great to dump_stack() here, but some kernels
222 * export it as show_stack() and I can't be bothered to
223 * proprely engage in that dance right now */
224 #define LASSERTF(cond, fmt...) \
226 if (unlikely(!(cond))) { \
227 portals_debug_msg(0, D_EMERG, __FILE__, __FUNCTION__,\
228 __LINE__, CDEBUG_STACK, \
229 "ASSERTION(" #cond ") failed:" fmt);\
236 #define LASSERTF(cond, fmt...) do { } while (0)
240 #define LBUG_WITH_LOC(file, func, line) \
242 CEMERG("LBUG - trying to dump log to /tmp/lustre-log\n"); \
243 portals_debug_dumplog(); \
244 portals_run_lbug_upcall(file, func, line); \
248 #define LBUG_WITH_LOC(file, func, line) \
251 portals_debug_dumplog(); \
252 portals_run_lbug_upcall(file, func, line); \
253 set_task_state(current, TASK_UNINTERRUPTIBLE); \
256 #endif /* __arch_um__ */
258 #define LBUG() LBUG_WITH_LOC(__FILE__, __FUNCTION__, __LINE__)
264 extern atomic_t portal_kmemory;
266 # define portal_kmem_inc(ptr, size) \
268 atomic_add(size, &portal_kmemory); \
271 # define portal_kmem_dec(ptr, size) do { \
272 atomic_sub(size, &portal_kmemory); \
276 # define portal_kmem_inc(ptr, size) do {} while (0)
277 # define portal_kmem_dec(ptr, size) do {} while (0)
278 #endif /* PORTAL_DEBUG */
280 #define PORTAL_VMALLOC_SIZE 16384
283 #define GFP_MEMALLOC 0
286 #define PORTAL_ALLOC(ptr, size) \
288 LASSERT (!in_interrupt()); \
289 if ((size) > PORTAL_VMALLOC_SIZE) \
290 (ptr) = vmalloc(size); \
292 (ptr) = kmalloc((size), (GFP_KERNEL | GFP_MEMALLOC)); \
294 CERROR("PORTALS: out of memory at %s:%d (tried to alloc '"\
295 #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size));\
297 portal_kmem_inc((ptr), (size)); \
298 memset((ptr), 0, (size)); \
300 CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %d at %p (tot %d).\n", \
301 (int)(size), (ptr), atomic_read (&portal_kmemory)); \
304 #define PORTAL_FREE(ptr, size) \
307 if ((ptr) == NULL) { \
308 CERROR("PORTALS: free NULL '" #ptr "' (%d bytes) at " \
309 "%s:%d\n", s, __FILE__, __LINE__); \
312 if (s > PORTAL_VMALLOC_SIZE) \
316 portal_kmem_dec((ptr), s); \
317 CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n", \
318 s, (ptr), atomic_read(&portal_kmemory)); \
321 #ifndef SLAB_MEMALLOC
322 #define SLAB_MEMALLOC 0
325 #define PORTAL_SLAB_ALLOC(ptr, slab, size) \
327 LASSERT(!in_interrupt()); \
328 (ptr) = kmem_cache_alloc((slab), (SLAB_KERNEL | SLAB_MEMALLOC)); \
329 if ((ptr) == NULL) { \
330 CERROR("PORTALS: out of memory at %s:%d (tried to alloc" \
331 " '" #ptr "' from slab '" #slab "')\n", __FILE__, \
334 portal_kmem_inc((ptr), (size)); \
335 memset((ptr), 0, (size)); \
337 CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %ld at %p (tot %d).\n", \
338 (int)(size), (ptr), atomic_read(&portal_kmemory)); \
341 #define PORTAL_SLAB_FREE(ptr, slab, size) \
344 if ((ptr) == NULL) { \
345 CERROR("PORTALS: free NULL '" #ptr "' (%d bytes) at " \
346 "%s:%d\n", s, __FILE__, __LINE__); \
349 memset((ptr), 0x5a, s); \
350 kmem_cache_free((slab), ptr); \
351 portal_kmem_dec((ptr), s); \
352 CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n", \
353 s, (ptr), atomic_read (&portal_kmemory)); \
356 /* ------------------------------------------------------------------- */
358 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
360 #define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
361 #define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
363 #define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
364 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
366 #define PORTAL_MODULE_USE MOD_INC_USE_COUNT
367 #define PORTAL_MODULE_UNUSE MOD_DEC_USE_COUNT
370 #define PORTAL_SYMBOL_REGISTER(x)
371 #define PORTAL_SYMBOL_UNREGISTER(x)
373 #define PORTAL_SYMBOL_GET(x) symbol_get(x)
374 #define PORTAL_SYMBOL_PUT(x) symbol_put(x)
376 #define PORTAL_MODULE_USE try_module_get(THIS_MODULE)
377 #define PORTAL_MODULE_UNUSE module_put(THIS_MODULE)
381 /******************************************************************************/
382 /* Kernel Portals Router interface */
384 typedef void (*kpr_fwd_callback_t)(void *arg, int error); // completion callback
386 /* space for routing targets to stash "stuff" in a forwarded packet */
388 long long _alignment;
389 void *_space[16]; /* scale with CPU arch */
392 /* Kernel Portals Routing Forwarded message Descriptor */
394 struct list_head kprfd_list; /* stash in queues (routing target can use) */
395 ptl_nid_t kprfd_target_nid; /* final destination NID */
396 ptl_nid_t kprfd_gateway_nid; /* gateway NID */
397 int kprfd_nob; /* # message bytes (including header) */
398 int kprfd_niov; /* # message frags (including header) */
399 struct iovec *kprfd_iov; /* message fragments */
400 void *kprfd_router_arg; // originating NAL's router arg
401 kpr_fwd_callback_t kprfd_callback; /* completion callback */
402 void *kprfd_callback_arg; /* completion callback arg */
403 kprfd_scratch_t kprfd_scratch; // scratchpad for routing targets
406 typedef void (*kpr_fwd_t)(void *arg, kpr_fwd_desc_t *fwd);
407 typedef void (*kpr_notify_t)(void *arg, ptl_nid_t peer, int alive);
409 /* NAL's routing interface (Kernel Portals Routing Nal Interface) */
410 typedef const struct {
411 int kprni_nalid; /* NAL's id */
412 void *kprni_arg; /* Arg to pass when calling into NAL */
413 kpr_fwd_t kprni_fwd; /* NAL's forwarding entrypoint */
414 kpr_notify_t kprni_notify; /* NAL's notification entrypoint */
415 } kpr_nal_interface_t;
417 /* Router's routing interface (Kernel Portals Routing Router Interface) */
418 typedef const struct {
419 /* register the calling NAL with the router and get back the handle for
420 * subsequent calls */
421 int (*kprri_register) (kpr_nal_interface_t *nal_interface,
424 /* ask the router to find a gateway that forwards to 'nid' and is a
425 * peer of the calling NAL; assume caller will send 'nob' bytes of
427 int (*kprri_lookup) (void *router_arg, ptl_nid_t nid, int nob,
428 ptl_nid_t *gateway_nid);
430 /* hand a packet over to the router for forwarding */
431 kpr_fwd_t kprri_fwd_start;
433 /* hand a packet back to the router for completion */
434 void (*kprri_fwd_done) (void *router_arg, kpr_fwd_desc_t *fwd,
437 /* notify the router about peer state */
438 void (*kprri_notify) (void *router_arg, ptl_nid_t peer,
439 int alive, time_t when);
441 /* the calling NAL is shutting down */
442 void (*kprri_shutdown) (void *router_arg);
444 /* deregister the calling NAL with the router */
445 void (*kprri_deregister) (void *router_arg);
447 } kpr_router_interface_t;
449 /* Convenient struct for NAL to stash router interface/args */
451 kpr_router_interface_t *kpr_interface;
455 /* Router's control interface (Kernel Portals Routing Control Interface) */
456 typedef const struct {
457 int (*kprci_add_route)(int gateway_nal, ptl_nid_t gateway_nid,
458 ptl_nid_t lo_nid, ptl_nid_t hi_nid);
459 int (*kprci_del_route)(int gateway_nal, ptl_nid_t gateway_nid,
460 ptl_nid_t lo_nid, ptl_nid_t hi_nid);
461 int (*kprci_get_route)(int index, int *gateway_nal,
463 ptl_nid_t *lo_nid, ptl_nid_t *hi_nid,
465 int (*kprci_notify)(int gateway_nal, ptl_nid_t gateway_nid,
466 int alive, time_t when);
467 } kpr_control_interface_t;
469 extern kpr_control_interface_t kpr_control_interface;
470 extern kpr_router_interface_t kpr_router_interface;
473 kpr_register (kpr_router_t *router, kpr_nal_interface_t *nalif)
477 router->kpr_interface = PORTAL_SYMBOL_GET (kpr_router_interface);
478 if (router->kpr_interface == NULL)
481 rc = (router->kpr_interface)->kprri_register (nalif, &router->kpr_arg);
483 router->kpr_interface = NULL;
485 PORTAL_SYMBOL_PUT (kpr_router_interface);
490 kpr_routing (kpr_router_t *router)
492 return (router->kpr_interface != NULL);
496 kpr_lookup (kpr_router_t *router, ptl_nid_t nid, int nob, ptl_nid_t *gateway_nid)
498 if (!kpr_routing (router))
499 return (-ENETUNREACH);
501 return (router->kpr_interface->kprri_lookup(router->kpr_arg, nid, nob,
506 kpr_fwd_init (kpr_fwd_desc_t *fwd, ptl_nid_t nid,
507 int nob, int niov, struct iovec *iov,
508 kpr_fwd_callback_t callback, void *callback_arg)
510 fwd->kprfd_target_nid = nid;
511 fwd->kprfd_gateway_nid = nid;
512 fwd->kprfd_nob = nob;
513 fwd->kprfd_niov = niov;
514 fwd->kprfd_iov = iov;
515 fwd->kprfd_callback = callback;
516 fwd->kprfd_callback_arg = callback_arg;
520 kpr_fwd_start (kpr_router_t *router, kpr_fwd_desc_t *fwd)
522 if (!kpr_routing (router))
523 fwd->kprfd_callback (fwd->kprfd_callback_arg, -ENETUNREACH);
525 router->kpr_interface->kprri_fwd_start (router->kpr_arg, fwd);
529 kpr_fwd_done (kpr_router_t *router, kpr_fwd_desc_t *fwd, int error)
531 LASSERT (kpr_routing (router));
532 router->kpr_interface->kprri_fwd_done (router->kpr_arg, fwd, error);
536 kpr_notify (kpr_router_t *router,
537 ptl_nid_t peer, int alive, time_t when)
539 if (!kpr_routing (router))
542 router->kpr_interface->kprri_notify(router->kpr_arg, peer, alive, when);
546 kpr_shutdown (kpr_router_t *router)
548 if (kpr_routing (router))
549 router->kpr_interface->kprri_shutdown (router->kpr_arg);
553 kpr_deregister (kpr_router_t *router)
555 if (!kpr_routing (router))
557 router->kpr_interface->kprri_deregister (router->kpr_arg);
558 router->kpr_interface = NULL;
561 /******************************************************************************/
563 #ifdef PORTALS_PROFILING
564 #define prof_enum(FOO) PROF__##FOO
566 prof_enum(our_recvmsg),
567 prof_enum(our_sendmsg),
568 prof_enum(socknal_recv),
569 prof_enum(lib_parse),
570 prof_enum(conn_list_walk),
572 prof_enum(lib_finalize),
573 prof_enum(pingcli_time),
574 prof_enum(gmnal_send),
575 prof_enum(gmnal_recv),
581 /* hrmph. wrap-tastic. */
584 cycles_t total_cycles;
589 extern struct prof_ent prof_ents[MAX_PROFS];
591 #define PROF_START(FOO) \
593 struct prof_ent *pe = &prof_ents[PROF__##FOO]; \
595 pe->start = get_cycles(); \
598 #define PROF_FINISH(FOO) \
600 struct prof_ent *pe = &prof_ents[PROF__##FOO]; \
602 pe->end = get_cycles(); \
603 pe->total_cycles += (pe->end - pe->start); \
605 #else /* !PORTALS_PROFILING */
606 #define PROF_START(FOO) do {} while(0)
607 #define PROF_FINISH(FOO) do {} while(0)
608 #endif /* PORTALS_PROFILING */
611 extern spinlock_t stack_backtrace_lock;
613 char *portals_debug_dumpstack(void);
614 void portals_run_upcall(char **argv);
615 void portals_run_lbug_upcall(char * file, const char *fn, const int line);
616 void portals_debug_dumplog(void);
617 int portals_debug_init(unsigned long bufsize);
618 int portals_debug_cleanup(void);
619 int portals_debug_clear_buffer(void);
620 int portals_debug_mark_buffer(char *text);
621 int portals_debug_set_daemon(unsigned int cmd, unsigned int length,
622 char *file, unsigned int size);
623 __s32 portals_debug_copy_to_user(char *buf, unsigned long len);
625 /* Use the special GNU C __attribute__ hack to have the compiler check the
626 * printf style argument string against the actual argument count and
630 # warning printf has been defined as a macro...
633 void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
634 const int line, unsigned long stack,
636 __attribute__ ((format (printf, 7, 8)));
638 void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
639 const int line, unsigned long stack,
640 const char *format, ...);
641 #endif /* __GNUC__ */
642 void portals_debug_set_level(unsigned int debug_level);
644 # define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
645 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
646 # define time(a) CURRENT_TIME
648 extern void kportal_daemonize (char *name);
649 extern void kportal_blockallsigs (void);
651 #else /* !__KERNEL__ */
657 # include <cygwin-ioctl.h>
661 # include <asm/types.h>
662 # ifndef DEBUG_SUBSYSTEM
663 # define DEBUG_SUBSYSTEM S_UNDEFINED
668 # define LASSERT(e) assert(e)
669 # define LASSERTF(cond, args...) assert(cond)
672 # define LASSERTF(cond, args...) do { } while (0)
674 # define printk(format, args...) printf (format, ## args)
675 # define PORTAL_ALLOC(ptr, size) do { (ptr) = malloc(size); } while (0);
676 # define PORTAL_FREE(a, b) do { free(a); } while (0);
677 # define portals_debug_msg(subsys, mask, file, fn, line, stack, format, a...) \
678 printf("%02x:%06x (@%lu %s:%s,l. %d %d %lu): " format, \
679 (subsys), (mask), (long)time(0), file, fn, line, \
680 getpid() , stack, ## a);
683 /* support decl needed both by kernel and liblustre */
684 char *portals_nid2str(int nal, ptl_nid_t nid, char *str);
687 # define CURRENT_TIME time(0)
690 /******************************************************************************/
691 /* Light-weight trace
692 * Support for temporary event tracing with minimal Heisenberg effect. */
693 #define LWT_SUPPORT 1
703 #if BITS_PER_LONG > 32
710 #define LWT_EVENTS_PER_PAGE (PAGE_SIZE / sizeof (lwt_event_t))
712 typedef struct _lwt_page {
713 struct list_head lwtp_list;
714 struct page *lwtp_page;
715 lwt_event_t *lwtp_events;
719 int lwtc_current_index;
720 lwt_page_t *lwtc_current_page;
723 extern int lwt_enabled;
724 extern lwt_cpu_t lwt_cpus[];
726 extern int lwt_init (void);
727 extern void lwt_fini (void);
728 extern int lwt_lookup_string (int *size, char *knlptr,
729 char *usrptr, int usrsize);
730 extern int lwt_control (int enable, int clear);
731 extern int lwt_snapshot (int *ncpu, int *total_size,
732 void *user_ptr, int user_size);
734 /* Note that we _don't_ define LWT_EVENT at all if LWT_SUPPORT isn't set.
735 * This stuff is meant for finding specific problems; it never stays in
736 * production code... */
739 #define LWTWHERE(f,l) f ":" LWTSTR(l)
741 #define LWT_EVENT(p1, p2, p3, p4) \
743 unsigned long flags; \
748 local_irq_save (flags); \
751 cpu = &lwt_cpus[smp_processor_id()]; \
752 p = cpu->lwtc_current_page; \
753 e = &p->lwtp_events[cpu->lwtc_current_index++]; \
755 if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) { \
756 cpu->lwtc_current_page = \
757 list_entry (p->lwtp_list.next, \
758 lwt_page_t, lwtp_list); \
759 cpu->lwtc_current_index = 0; \
762 e->lwte_when = get_cycles(); \
763 e->lwte_where = LWTWHERE(__FILE__,__LINE__); \
764 e->lwte_task = current; \
765 e->lwte_p1 = (long)(p1); \
766 e->lwte_p2 = (long)(p2); \
767 e->lwte_p3 = (long)(p3); \
768 e->lwte_p4 = (long)(p4); \
771 local_irq_restore (flags); \
773 #else /* __KERNEL__ */
774 #define LWT_EVENT(p1,p2,p3,p4) /* no userland implementation yet */
775 #endif /* __KERNEL__ */
776 #endif /* LWT_SUPPORT */
779 #include <linux/portals_lib.h>
782 * USER LEVEL STUFF BELOW
785 #define PORTALS_CFG_VERSION 0x00010001;
805 __u32 pcfg_plen1; /* buffers in userspace */
807 __u32 pcfg_plen2; /* buffers in userspace */
811 #define PCFG_INIT(pcfg, cmd) \
813 memset(&pcfg, 0, sizeof(pcfg)); \
814 pcfg.pcfg_version = PORTALS_CFG_VERSION; \
815 pcfg.pcfg_command = (cmd); \
819 #define PORTAL_IOCTL_VERSION 0x00010007
823 struct portal_ioctl_data {
847 __u32 ioc_plen1; /* buffers in userspace */
849 __u32 ioc_plen2; /* buffers in userspace */
855 struct portal_ioctl_hdr {
860 struct portals_debug_ioctl_data
862 struct portal_ioctl_hdr hdr;
867 #define PORTAL_IOC_INIT(data) \
869 memset(&data, 0, sizeof(data)); \
870 data.ioc_version = PORTAL_IOCTL_VERSION; \
871 data.ioc_len = sizeof(data); \
874 /* FIXME check conflict with lustre_lib.h */
875 #define PTL_IOC_DEBUG_MASK _IOWR('f', 250, long)
877 static inline int portal_ioctl_packlen(struct portal_ioctl_data *data)
879 int len = sizeof(*data);
880 len += size_round(data->ioc_inllen1);
881 len += size_round(data->ioc_inllen2);
885 static inline int portal_ioctl_is_invalid(struct portal_ioctl_data *data)
887 if (data->ioc_len > (1<<30)) {
888 CERROR ("PORTALS ioctl: ioc_len larger than 1<<30\n");
891 if (data->ioc_inllen1 > (1<<30)) {
892 CERROR ("PORTALS ioctl: ioc_inllen1 larger than 1<<30\n");
895 if (data->ioc_inllen2 > (1<<30)) {
896 CERROR ("PORTALS ioctl: ioc_inllen2 larger than 1<<30\n");
899 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
900 CERROR ("PORTALS ioctl: inlbuf1 pointer but 0 length\n");
903 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
904 CERROR ("PORTALS ioctl: inlbuf2 pointer but 0 length\n");
907 if (data->ioc_pbuf1 && !data->ioc_plen1) {
908 CERROR ("PORTALS ioctl: pbuf1 pointer but 0 length\n");
911 if (data->ioc_pbuf2 && !data->ioc_plen2) {
912 CERROR ("PORTALS ioctl: pbuf2 pointer but 0 length\n");
915 if (data->ioc_plen1 && !data->ioc_pbuf1) {
916 CERROR ("PORTALS ioctl: plen1 nonzero but no pbuf1 pointer\n");
919 if (data->ioc_plen2 && !data->ioc_pbuf2) {
920 CERROR ("PORTALS ioctl: plen2 nonzero but no pbuf2 pointer\n");
923 if (portal_ioctl_packlen(data) != data->ioc_len ) {
924 CERROR ("PORTALS ioctl: packlen != ioc_len\n");
927 if (data->ioc_inllen1 &&
928 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
929 CERROR ("PORTALS ioctl: inlbuf1 not 0 terminated\n");
932 if (data->ioc_inllen2 &&
933 data->ioc_bulk[size_round(data->ioc_inllen1) +
934 data->ioc_inllen2 - 1] != '\0') {
935 CERROR ("PORTALS ioctl: inlbuf2 not 0 terminated\n");
942 static inline int portal_ioctl_pack(struct portal_ioctl_data *data, char **pbuf,
946 struct portal_ioctl_data *overlay;
947 data->ioc_len = portal_ioctl_packlen(data);
948 data->ioc_version = PORTAL_IOCTL_VERSION;
950 if (*pbuf && portal_ioctl_packlen(data) > max)
953 *pbuf = malloc(data->ioc_len);
957 overlay = (struct portal_ioctl_data *)*pbuf;
958 memcpy(*pbuf, data, sizeof(*data));
960 ptr = overlay->ioc_bulk;
961 if (data->ioc_inlbuf1)
962 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
963 if (data->ioc_inlbuf2)
964 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
965 if (portal_ioctl_is_invalid(overlay))
971 #include <asm/uaccess.h>
973 /* buffer MUST be at least the size of portal_ioctl_hdr */
974 static inline int portal_ioctl_getdata(char *buf, char *end, void *arg)
976 struct portal_ioctl_hdr *hdr;
977 struct portal_ioctl_data *data;
981 hdr = (struct portal_ioctl_hdr *)buf;
982 data = (struct portal_ioctl_data *)buf;
984 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
990 if (hdr->ioc_version != PORTAL_IOCTL_VERSION) {
991 CERROR ("PORTALS: version mismatch kernel vs application\n");
995 if (hdr->ioc_len + buf >= end) {
996 CERROR ("PORTALS: user buffer exceeds kernel buffer\n");
1001 if (hdr->ioc_len < sizeof(struct portal_ioctl_data)) {
1002 CERROR ("PORTALS: user buffer too small for ioctl\n");
1006 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
1012 if (portal_ioctl_is_invalid(data)) {
1013 CERROR ("PORTALS: ioctl not correctly formatted\n");
1017 if (data->ioc_inllen1) {
1018 data->ioc_inlbuf1 = &data->ioc_bulk[0];
1021 if (data->ioc_inllen2) {
1022 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
1023 size_round(data->ioc_inllen1);
1031 /* ioctls for manipulating snapshots 30- */
1032 #define IOC_PORTAL_TYPE 'e'
1033 #define IOC_PORTAL_MIN_NR 30
1035 #define IOC_PORTAL_PING _IOWR('e', 30, long)
1036 #define IOC_PORTAL_GET_DEBUG _IOWR('e', 31, long)
1037 #define IOC_PORTAL_CLEAR_DEBUG _IOWR('e', 32, long)
1038 #define IOC_PORTAL_MARK_DEBUG _IOWR('e', 33, long)
1039 #define IOC_PORTAL_PANIC _IOWR('e', 34, long)
1040 #define IOC_PORTAL_NAL_CMD _IOWR('e', 35, long)
1041 #define IOC_PORTAL_GET_NID _IOWR('e', 36, long)
1042 #define IOC_PORTAL_FAIL_NID _IOWR('e', 37, long)
1043 #define IOC_PORTAL_SET_DAEMON _IOWR('e', 38, long)
1044 #define IOC_PORTAL_LWT_CONTROL _IOWR('e', 39, long)
1045 #define IOC_PORTAL_LWT_SNAPSHOT _IOWR('e', 40, long)
1046 #define IOC_PORTAL_LWT_LOOKUP_STRING _IOWR('e', 41, long)
1047 #define IOC_PORTAL_MAX_NR 41
1062 extern ptl_handle_ni_t kqswnal_ni;
1063 extern ptl_handle_ni_t ksocknal_ni;
1064 extern ptl_handle_ni_t ktoenal_ni;
1065 extern ptl_handle_ni_t kgmnal_ni;
1066 extern ptl_handle_ni_t kibnal_ni;
1067 extern ptl_handle_ni_t kscimacnal_ni;
1070 #define PTL_NALFMT_SIZE 16
1072 #define NAL_MAX_NR (NAL_ENUM_END_MARKER - 1)
1074 #define NAL_CMD_REGISTER_PEER_FD 100
1075 #define NAL_CMD_CLOSE_CONNECTION 101
1076 #define NAL_CMD_REGISTER_MYNID 102
1077 #define NAL_CMD_PUSH_CONNECTION 103
1078 #define NAL_CMD_GET_CONN 104
1079 #define NAL_CMD_DEL_AUTOCONN 105
1080 #define NAL_CMD_ADD_AUTOCONN 106
1081 #define NAL_CMD_GET_AUTOCONN 107
1082 #define NAL_CMD_GET_TXDESC 108
1083 #define NAL_CMD_ADD_ROUTE 109
1084 #define NAL_CMD_DEL_ROUTE 110
1085 #define NAL_CMD_GET_ROUTE 111
1086 #define NAL_CMD_NOTIFY_ROUTER 112
1089 DEBUG_DAEMON_START = 1,
1090 DEBUG_DAEMON_STOP = 2,
1091 DEBUG_DAEMON_PAUSE = 3,
1092 DEBUG_DAEMON_CONTINUE = 4,
1095 /* XXX remove to lustre ASAP */
1096 struct lustre_peer {
1098 ptl_handle_ni_t peer_ni;
1103 typedef int (*nal_cmd_handler_t)(struct portals_cfg *, void * private);
1104 int kportal_nal_register(int nal, nal_cmd_handler_t handler, void * private);
1105 int kportal_nal_unregister(int nal);
1107 enum cfg_record_type {
1108 PORTALS_CFG_TYPE = 1,
1109 LUSTRE_CFG_TYPE = 123,
1112 typedef int (*cfg_record_cb_t)(enum cfg_record_type, int len, void *data);
1113 int kportal_nal_cmd(struct portals_cfg *);
1115 ptl_handle_ni_t *kportal_get_ni (int nal);
1116 void kportal_put_ni (int nal);
1119 # ifndef BITS_PER_LONG
1120 # if (~0UL) == 0xffffffffUL
1121 # define BITS_PER_LONG 32
1123 # define BITS_PER_LONG 64
1128 #if defined(__x86_64__)
1129 # define LPU64 "%Lu"
1130 # define LPD64 "%Ld"
1131 # define LPX64 "%#Lx"
1133 # define LPSSZ "%ld"
1134 #elif (BITS_PER_LONG == 32 || __WORDSIZE == 32)
1135 # define LPU64 "%Lu"
1136 # define LPD64 "%Ld"
1137 # define LPX64 "%#Lx"
1140 #elif (BITS_PER_LONG == 64 || __WORDSIZE == 64)
1141 # define LPU64 "%lu"
1142 # define LPD64 "%ld"
1143 # define LPX64 "%#lx"
1145 # define LPSSZ "%ld"
1148 # error "No word size defined"