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 /* Debugging subsystems (32 bits, non-overlapping) */
23 #define S_UNDEFINED (1 << 0)
24 #define S_MDC (1 << 1)
25 #define S_MDS (1 << 2)
26 #define S_OSC (1 << 3)
27 #define S_OST (1 << 4)
28 #define S_CLASS (1 << 5)
29 #define S_LOG (1 << 6)
30 #define S_LLITE (1 << 7)
31 #define S_RPC (1 << 8)
32 #define S_MGMT (1 << 9)
33 #define S_PORTALS (1 << 10)
34 #define S_SOCKNAL (1 << 11)
35 #define S_QSWNAL (1 << 12)
36 #define S_PINGER (1 << 13)
37 #define S_FILTER (1 << 14)
38 #define S_PTLBD (1 << 15)
39 #define S_ECHO (1 << 16)
40 #define S_LDLM (1 << 17)
41 #define S_LOV (1 << 18)
42 #define S_GMNAL (1 << 19)
43 #define S_PTLROUTER (1 << 20)
44 #define S_COBD (1 << 21)
46 /* If you change these values, please keep portals/utils/debug.c
49 /* Debugging masks (32 bits, non-overlapping) */
50 #define D_TRACE (1 << 0) /* ENTRY/EXIT markers */
51 #define D_INODE (1 << 1)
52 #define D_SUPER (1 << 2)
53 #define D_EXT2 (1 << 3) /* anything from ext2_debug */
54 #define D_MALLOC (1 << 4) /* print malloc, free information */
55 #define D_CACHE (1 << 5) /* cache-related items */
56 #define D_INFO (1 << 6) /* general information */
57 #define D_IOCTL (1 << 7) /* ioctl related information */
58 #define D_BLOCKS (1 << 8) /* ext2 block allocation */
59 #define D_NET (1 << 9) /* network communications */
60 #define D_WARNING (1 << 10)
61 #define D_BUFFS (1 << 11)
62 #define D_OTHER (1 << 12)
63 #define D_DENTRY (1 << 13)
64 #define D_PORTALS (1 << 14) /* ENTRY/EXIT markers */
65 #define D_PAGE (1 << 15) /* bulk page handling */
66 #define D_DLMTRACE (1 << 16)
67 #define D_ERROR (1 << 17) /* CERROR(...) == CDEBUG (D_ERROR, ...) */
68 #define D_EMERG (1 << 18) /* CEMERG(...) == CDEBUG (D_EMERG, ...) */
69 #define D_HA (1 << 19) /* recovery and failover */
70 #define D_RPCTRACE (1 << 20) /* for distributed debugging */
71 #define D_VFSTRACE (1 << 21)
74 # include <linux/sched.h> /* THREAD_SIZE */
76 # define THREAD_SIZE 8192
81 # define CDEBUG_STACK (THREAD_SIZE - \
82 ((unsigned long)__builtin_dwarf_cfa() & \
85 # define CDEBUG_STACK (THREAD_SIZE - \
86 ((unsigned long)__builtin_frame_address(0) & \
90 #define CHECK_STACK(stack) \
92 if ((stack) > 3*THREAD_SIZE/4 && (stack) > portal_stack) { \
93 portals_debug_msg(DEBUG_SUBSYSTEM, D_ERROR, \
94 __FILE__, __FUNCTION__, __LINE__, \
96 "maximum lustre stack %u\n", \
97 portal_stack = (stack)); \
101 #else /* __KERNEL__ */
102 #define CHECK_STACK(stack) do { } while(0)
103 #define CDEBUG_STACK (0L)
104 #endif /* __KERNEL__ */
107 #define CDEBUG(mask, format, a...) \
109 CHECK_STACK(CDEBUG_STACK); \
110 if (!(mask) || ((mask) & (D_ERROR | D_EMERG)) || \
111 (portal_debug & (mask) && \
112 portal_subsystem_debug & DEBUG_SUBSYSTEM)) \
113 portals_debug_msg(DEBUG_SUBSYSTEM, mask, \
114 __FILE__, __FUNCTION__, __LINE__, \
115 CDEBUG_STACK, format, ## a); \
118 #define CWARN(format, a...) CDEBUG(D_WARNING, format, ## a)
119 #define CERROR(format, a...) CDEBUG(D_ERROR, format, ## a)
120 #define CEMERG(format, a...) CDEBUG(D_EMERG, format, ## a)
122 #define GOTO(label, rc) \
124 long GOTO__ret = (long)(rc); \
125 CDEBUG(D_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n", \
126 #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret,\
127 (signed long)GOTO__ret); \
133 typeof(rc) RETURN__ret = (rc); \
134 CDEBUG(D_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n", \
135 (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret);\
136 return RETURN__ret; \
141 CDEBUG(D_TRACE, "Process entered\n"); \
146 CDEBUG(D_TRACE, "Process leaving\n"); \
149 #define CDEBUG(mask, format, a...) do { } while (0)
150 #define CWARN(format, a...) do { } while (0)
151 #define CERROR(format, a...) printk("<3>" format, ## a)
152 #define CEMERG(format, a...) printk("<0>" format, ## a)
153 #define GOTO(label, rc) do { (void)(rc); goto label; } while (0)
154 #define RETURN(rc) return (rc)
155 #define ENTRY do { } while (0)
156 #define EXIT do { } while (0)
160 # include <linux/vmalloc.h>
161 # include <linux/time.h>
162 # include <linux/slab.h>
163 # include <linux/interrupt.h>
164 # include <linux/highmem.h>
165 # include <linux/module.h>
166 # include <linux/version.h>
167 # include <portals/lib-nal.h>
168 # include <linux/smp_lock.h>
169 # include <asm/atomic.h>
171 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
172 #define schedule_work schedule_task
173 #define prepare_work(wq,cb,cbdata) \
175 INIT_TQUEUE((wq), 0, 0); \
176 PREPARE_TQUEUE((wq), (cb), (cbdata)); \
179 #define ll_invalidate_inode_pages invalidate_inode_pages
180 #define PageUptodate Page_Uptodate
181 #define our_recalc_sigpending(current) recalc_sigpending(current)
182 #define num_online_cpus() smp_num_cpus
183 static inline void our_cond_resched(void)
185 if (current->need_resched)
191 #define prepare_work(wq,cb,cbdata) \
193 INIT_WORK((wq), (void *)(cb), (void *)(cbdata)); \
195 #define ll_invalidate_inode_pages(inode) invalidate_inode_pages((inode)->i_mapping)
196 #define wait_on_page wait_on_page_locked
197 #define our_recalc_sigpending(current) recalc_sigpending()
198 #define strtok(a,b) strpbrk(a, b)
199 static inline void our_cond_resched(void)
203 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
206 extern void kportal_assertion_failed(char *expr, char *file, const char *func,
208 #define LASSERT(e) ((e) ? 0 : kportal_assertion_failed( #e , __FILE__, \
209 __FUNCTION__, __LINE__))
215 #define LBUG_WITH_LOC(file, func, line) \
217 CEMERG("LBUG - trying to dump log to /tmp/lustre-log\n"); \
218 portals_debug_dumplog(); \
219 portals_run_lbug_upcall(file, func, line); \
223 #define LBUG_WITH_LOC(file, func, line) \
226 portals_debug_dumplog(); \
227 portals_run_lbug_upcall(file, func, line); \
228 set_task_state(current, TASK_UNINTERRUPTIBLE); \
231 #endif /* __arch_um__ */
233 #define LBUG() LBUG_WITH_LOC(__FILE__, __FUNCTION__, __LINE__)
239 extern atomic_t portal_kmemory;
241 # define portal_kmem_inc(ptr, size) \
243 atomic_add(size, &portal_kmemory); \
246 # define portal_kmem_dec(ptr, size) do { \
247 atomic_sub(size, &portal_kmemory); \
251 # define portal_kmem_inc(ptr, size) do {} while (0)
252 # define portal_kmem_dec(ptr, size) do {} while (0)
253 #endif /* PORTAL_DEBUG */
255 #define PORTAL_VMALLOC_SIZE 16384
257 #define PORTAL_ALLOC(ptr, size) \
259 LASSERT (!in_interrupt()); \
260 if ((size) > PORTAL_VMALLOC_SIZE) \
261 (ptr) = vmalloc(size); \
263 (ptr) = kmalloc((size), GFP_NOFS); \
265 CERROR("PORTALS: out of memory at %s:%d (tried to alloc '"\
266 #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size));\
268 portal_kmem_inc((ptr), (size)); \
269 memset((ptr), 0, (size)); \
271 CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %d at %p (tot %d).\n", \
272 (int)(size), (ptr), atomic_read (&portal_kmemory)); \
275 #define PORTAL_FREE(ptr, size) \
278 if ((ptr) == NULL) { \
279 CERROR("PORTALS: free NULL '" #ptr "' (%d bytes) at " \
280 "%s:%d\n", s, __FILE__, __LINE__); \
283 if (s > PORTAL_VMALLOC_SIZE) \
287 portal_kmem_dec((ptr), s); \
288 CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n", \
289 s, (ptr), atomic_read(&portal_kmemory)); \
292 #define PORTAL_SLAB_ALLOC(ptr, slab, size) \
294 LASSERT(!in_interrupt()); \
295 (ptr) = kmem_cache_alloc((slab), SLAB_KERNEL); \
296 if ((ptr) == NULL) { \
297 CERROR("PORTALS: out of memory at %s:%d (tried to alloc" \
298 " '" #ptr "' from slab '" #slab "')\n", __FILE__, \
301 portal_kmem_inc((ptr), (size)); \
302 memset((ptr), 0, (size)); \
304 CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %ld at %p (tot %d).\n", \
305 (int)(size), (ptr), atomic_read(&portal_kmemory)); \
308 #define PORTAL_SLAB_FREE(ptr, slab, size) \
311 if ((ptr) == NULL) { \
312 CERROR("PORTALS: free NULL '" #ptr "' (%d bytes) at " \
313 "%s:%d\n", s, __FILE__, __LINE__); \
316 memset((ptr), 0x5a, s); \
317 kmem_cache_free((slab), ptr); \
318 portal_kmem_dec((ptr), s); \
319 CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n", \
320 s, (ptr), atomic_read (&portal_kmemory)); \
323 /* ------------------------------------------------------------------- */
325 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
327 #define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
328 #define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
330 #define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
331 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
333 #define PORTAL_MODULE_USE MOD_INC_USE_COUNT
334 #define PORTAL_MODULE_UNUSE MOD_DEC_USE_COUNT
337 #define PORTAL_SYMBOL_REGISTER(x)
338 #define PORTAL_SYMBOL_UNREGISTER(x)
340 #define PORTAL_SYMBOL_GET(x) symbol_get(x)
341 #define PORTAL_SYMBOL_PUT(x) symbol_put(x)
343 #define PORTAL_MODULE_USE try_module_get(THIS_MODULE)
344 #define PORTAL_MODULE_UNUSE module_put(THIS_MODULE)
348 /******************************************************************************/
349 /* Kernel Portals Router interface */
351 typedef void (*kpr_fwd_callback_t)(void *arg, int error); // completion callback
353 /* space for routing targets to stash "stuff" in a forwarded packet */
355 long long _alignment;
356 void *_space[16]; /* scale with CPU arch */
359 /* Kernel Portals Routing Forwarded message Descriptor */
361 struct list_head kprfd_list; /* stash in queues (routing target can use) */
362 ptl_nid_t kprfd_target_nid; /* final destination NID */
363 ptl_nid_t kprfd_gateway_nid; /* gateway NID */
364 int kprfd_nob; /* # message bytes (including header) */
365 int kprfd_niov; /* # message frags (including header) */
366 struct iovec *kprfd_iov; /* message fragments */
367 void *kprfd_router_arg; // originating NAL's router arg
368 kpr_fwd_callback_t kprfd_callback; /* completion callback */
369 void *kprfd_callback_arg; /* completion callback arg */
370 kprfd_scratch_t kprfd_scratch; // scratchpad for routing targets
373 typedef void (*kpr_fwd_t)(void *arg, kpr_fwd_desc_t *fwd);
374 typedef void (*kpr_notify_t)(void *arg, ptl_nid_t peer, int alive);
376 /* NAL's routing interface (Kernel Portals Routing Nal Interface) */
377 typedef const struct {
378 int kprni_nalid; /* NAL's id */
379 void *kprni_arg; /* Arg to pass when calling into NAL */
380 kpr_fwd_t kprni_fwd; /* NAL's forwarding entrypoint */
381 kpr_notify_t kprni_notify; /* NAL's notification entrypoint */
382 } kpr_nal_interface_t;
384 /* Router's routing interface (Kernel Portals Routing Router Interface) */
385 typedef const struct {
386 /* register the calling NAL with the router and get back the handle for
387 * subsequent calls */
388 int (*kprri_register) (kpr_nal_interface_t *nal_interface,
391 /* ask the router to find a gateway that forwards to 'nid' and is a
392 * peer of the calling NAL; assume caller will send 'nob' bytes of
394 int (*kprri_lookup) (void *router_arg, ptl_nid_t nid, int nob,
395 ptl_nid_t *gateway_nid);
397 /* hand a packet over to the router for forwarding */
398 kpr_fwd_t kprri_fwd_start;
400 /* hand a packet back to the router for completion */
401 void (*kprri_fwd_done) (void *router_arg, kpr_fwd_desc_t *fwd,
404 /* notify the router about peer state */
405 void (*kprri_notify) (void *router_arg, ptl_nid_t peer,
406 int alive, time_t when);
408 /* the calling NAL is shutting down */
409 void (*kprri_shutdown) (void *router_arg);
411 /* deregister the calling NAL with the router */
412 void (*kprri_deregister) (void *router_arg);
414 } kpr_router_interface_t;
416 /* Convenient struct for NAL to stash router interface/args */
418 kpr_router_interface_t *kpr_interface;
422 /* Router's control interface (Kernel Portals Routing Control Interface) */
423 typedef const struct {
424 int (*kprci_add_route)(int gateway_nal, ptl_nid_t gateway_nid,
425 ptl_nid_t lo_nid, ptl_nid_t hi_nid);
426 int (*kprci_del_route)(int gateway_nal, ptl_nid_t gateway_nid,
427 ptl_nid_t lo_nid, ptl_nid_t hi_nid);
428 int (*kprci_get_route)(int index, int *gateway_nal,
430 ptl_nid_t *lo_nid, ptl_nid_t *hi_nid,
432 int (*kprci_notify)(int gateway_nal, ptl_nid_t gateway_nid,
433 int alive, time_t when);
434 } kpr_control_interface_t;
436 extern kpr_control_interface_t kpr_control_interface;
437 extern kpr_router_interface_t kpr_router_interface;
440 kpr_register (kpr_router_t *router, kpr_nal_interface_t *nalif)
444 router->kpr_interface = PORTAL_SYMBOL_GET (kpr_router_interface);
445 if (router->kpr_interface == NULL)
448 rc = (router->kpr_interface)->kprri_register (nalif, &router->kpr_arg);
450 router->kpr_interface = NULL;
452 PORTAL_SYMBOL_PUT (kpr_router_interface);
457 kpr_routing (kpr_router_t *router)
459 return (router->kpr_interface != NULL);
463 kpr_lookup (kpr_router_t *router, ptl_nid_t nid, int nob, ptl_nid_t *gateway_nid)
465 if (!kpr_routing (router))
466 return (-ENETUNREACH);
468 return (router->kpr_interface->kprri_lookup(router->kpr_arg, nid, nob,
473 kpr_fwd_init (kpr_fwd_desc_t *fwd, ptl_nid_t nid,
474 int nob, int niov, struct iovec *iov,
475 kpr_fwd_callback_t callback, void *callback_arg)
477 fwd->kprfd_target_nid = nid;
478 fwd->kprfd_gateway_nid = nid;
479 fwd->kprfd_nob = nob;
480 fwd->kprfd_niov = niov;
481 fwd->kprfd_iov = iov;
482 fwd->kprfd_callback = callback;
483 fwd->kprfd_callback_arg = callback_arg;
487 kpr_fwd_start (kpr_router_t *router, kpr_fwd_desc_t *fwd)
489 if (!kpr_routing (router))
490 fwd->kprfd_callback (fwd->kprfd_callback_arg, -ENETUNREACH);
492 router->kpr_interface->kprri_fwd_start (router->kpr_arg, fwd);
496 kpr_fwd_done (kpr_router_t *router, kpr_fwd_desc_t *fwd, int error)
498 LASSERT (kpr_routing (router));
499 router->kpr_interface->kprri_fwd_done (router->kpr_arg, fwd, error);
503 kpr_notify (kpr_router_t *router,
504 ptl_nid_t peer, int alive, time_t when)
506 if (!kpr_routing (router))
509 router->kpr_interface->kprri_notify(router->kpr_arg, peer, alive, when);
513 kpr_shutdown (kpr_router_t *router)
515 if (kpr_routing (router))
516 router->kpr_interface->kprri_shutdown (router->kpr_arg);
520 kpr_deregister (kpr_router_t *router)
522 if (!kpr_routing (router))
524 router->kpr_interface->kprri_deregister (router->kpr_arg);
525 router->kpr_interface = NULL;
528 /******************************************************************************/
530 #ifdef PORTALS_PROFILING
531 #define prof_enum(FOO) PROF__##FOO
533 prof_enum(our_recvmsg),
534 prof_enum(our_sendmsg),
535 prof_enum(socknal_recv),
536 prof_enum(lib_parse),
537 prof_enum(conn_list_walk),
539 prof_enum(lib_finalize),
540 prof_enum(pingcli_time),
541 prof_enum(gmnal_send),
542 prof_enum(gmnal_recv),
548 /* hrmph. wrap-tastic. */
551 cycles_t total_cycles;
556 extern struct prof_ent prof_ents[MAX_PROFS];
558 #define PROF_START(FOO) \
560 struct prof_ent *pe = &prof_ents[PROF__##FOO]; \
562 pe->start = get_cycles(); \
565 #define PROF_FINISH(FOO) \
567 struct prof_ent *pe = &prof_ents[PROF__##FOO]; \
569 pe->end = get_cycles(); \
570 pe->total_cycles += (pe->end - pe->start); \
572 #else /* !PORTALS_PROFILING */
573 #define PROF_START(FOO) do {} while(0)
574 #define PROF_FINISH(FOO) do {} while(0)
575 #endif /* PORTALS_PROFILING */
578 void portals_run_upcall(char **argv);
579 void portals_run_lbug_upcall(char * file, const char *fn, const int line);
580 void portals_debug_dumplog(void);
581 int portals_debug_init(unsigned long bufsize);
582 int portals_debug_cleanup(void);
583 int portals_debug_clear_buffer(void);
584 int portals_debug_mark_buffer(char *text);
585 int portals_debug_set_daemon(unsigned int cmd, unsigned int length,
586 char *file, unsigned int size);
587 __s32 portals_debug_copy_to_user(char *buf, unsigned long len);
589 /* Use the special GNU C __attribute__ hack to have the compiler check the
590 * printf style argument string against the actual argument count and
594 # warning printf has been defined as a macro...
597 void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
598 const int line, unsigned long stack,
599 const char *format, ...)
600 __attribute__ ((format (printf, 7, 8)));
602 void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
603 const int line, unsigned long stack,
604 const char *format, ...);
605 #endif /* __GNUC__ */
606 void portals_debug_set_level(unsigned int debug_level);
608 # define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
609 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
610 # define time(a) CURRENT_TIME
612 extern void kportal_daemonize (char *name);
613 extern void kportal_blockallsigs (void);
615 #else /* !__KERNEL__ */
623 # include <asm/types.h>
624 # ifndef DEBUG_SUBSYSTEM
625 # define DEBUG_SUBSYSTEM S_UNDEFINED
630 # define LASSERT(e) assert(e)
634 # define printk(format, args...) printf (format, ## args)
635 # define PORTAL_ALLOC(ptr, size) do { (ptr) = malloc(size); } while (0);
636 # define PORTAL_FREE(a, b) do { free(a); } while (0);
637 # define portals_debug_msg(subsys, mask, file, fn, line, stack, format, a...) \
638 printf("%02x:%06x (@%lu %s:%s,l. %d %d %lu): " format, \
639 (subsys), (mask), (long)time(0), file, fn, line, \
640 getpid() , stack, ## a);
644 # define CURRENT_TIME time(0)
647 /******************************************************************************/
648 /* Light-weight trace
649 * Support for temporary event tracing with minimal Heisenberg effect. */
650 #define LWT_SUPPORT 1
664 #define LWT_EVENTS_PER_PAGE (PAGE_SIZE / sizeof (lwt_event_t))
666 typedef struct _lwt_page {
667 struct list_head lwtp_list;
668 struct page *lwtp_page;
669 lwt_event_t *lwtp_events;
673 int lwtc_current_index;
674 lwt_page_t *lwtc_current_page;
677 extern int lwt_enabled;
678 extern lwt_cpu_t lwt_cpus[];
680 extern int lwt_init (void);
681 extern void lwt_fini (void);
682 extern int lwt_lookup_string (int *size, char *knlptr,
683 char *usrptr, int usrsize);
684 extern int lwt_control (int enable, int clear);
685 extern int lwt_snapshot (int *ncpu, int *total_size,
686 void *user_ptr, int user_size);
688 /* Note that we _don't_ define LWT_EVENT at all if LWT_SUPPORT isn't set.
689 * This stuff is meant for finding specific problems; it never stays in
690 * production code... */
693 #define LWTWHERE(f,l) f ":" LWTSTR(l)
695 #define LWT_EVENT(p1, p2, p3, p4) \
697 unsigned long flags; \
702 local_irq_save (flags); \
705 cpu = &lwt_cpus[smp_processor_id()]; \
706 p = cpu->lwtc_current_page; \
707 e = &p->lwtp_events[cpu->lwtc_current_index++]; \
709 if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) { \
710 cpu->lwtc_current_page = \
711 list_entry (p->lwtp_list.next, \
712 lwt_page_t, lwtp_list); \
713 cpu->lwtc_current_index = 0; \
716 e->lwte_when = get_cycles(); \
717 e->lwte_where = LWTWHERE(__FILE__,__LINE__); \
718 e->lwte_task = current; \
719 e->lwte_p1 = (long)(p1); \
720 e->lwte_p2 = (long)(p2); \
721 e->lwte_p3 = (long)(p3); \
722 e->lwte_p4 = (long)(p4); \
725 local_irq_restore (flags); \
727 #else /* __KERNEL__ */
728 #define LWT_EVENT(p1,p2,p3,p4) /* no userland implementation yet */
729 #endif /* __KERNEL__ */
730 #endif /* LWT_SUPPORT */
733 #include <linux/portals_lib.h>
736 * USER LEVEL STUFF BELOW
739 #define PORTAL_IOCTL_VERSION 0x00010007
743 struct portal_ioctl_data {
767 __u32 ioc_plen1; /* buffers in userspace */
769 __u32 ioc_plen2; /* buffers in userspace */
775 struct portal_ioctl_hdr {
780 struct portals_debug_ioctl_data
782 struct portal_ioctl_hdr hdr;
787 #define PORTAL_IOC_INIT(data) \
789 memset(&data, 0, sizeof(data)); \
790 data.ioc_version = PORTAL_IOCTL_VERSION; \
791 data.ioc_len = sizeof(data); \
794 /* FIXME check conflict with lustre_lib.h */
795 #define PTL_IOC_DEBUG_MASK _IOWR('f', 250, long)
797 static inline int portal_ioctl_packlen(struct portal_ioctl_data *data)
799 int len = sizeof(*data);
800 len += size_round(data->ioc_inllen1);
801 len += size_round(data->ioc_inllen2);
805 static inline int portal_ioctl_is_invalid(struct portal_ioctl_data *data)
807 if (data->ioc_len > (1<<30)) {
808 CERROR ("PORTALS ioctl: ioc_len larger than 1<<30\n");
811 if (data->ioc_inllen1 > (1<<30)) {
812 CERROR ("PORTALS ioctl: ioc_inllen1 larger than 1<<30\n");
815 if (data->ioc_inllen2 > (1<<30)) {
816 CERROR ("PORTALS ioctl: ioc_inllen2 larger than 1<<30\n");
819 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
820 CERROR ("PORTALS ioctl: inlbuf1 pointer but 0 length\n");
823 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
824 CERROR ("PORTALS ioctl: inlbuf2 pointer but 0 length\n");
827 if (data->ioc_pbuf1 && !data->ioc_plen1) {
828 CERROR ("PORTALS ioctl: pbuf1 pointer but 0 length\n");
831 if (data->ioc_pbuf2 && !data->ioc_plen2) {
832 CERROR ("PORTALS ioctl: pbuf2 pointer but 0 length\n");
835 if (data->ioc_plen1 && !data->ioc_pbuf1) {
836 CERROR ("PORTALS ioctl: plen1 nonzero but no pbuf1 pointer\n");
839 if (data->ioc_plen2 && !data->ioc_pbuf2) {
840 CERROR ("PORTALS ioctl: plen2 nonzero but no pbuf2 pointer\n");
843 if (portal_ioctl_packlen(data) != data->ioc_len ) {
844 CERROR ("PORTALS ioctl: packlen != ioc_len\n");
847 if (data->ioc_inllen1 &&
848 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
849 CERROR ("PORTALS ioctl: inlbuf1 not 0 terminated\n");
852 if (data->ioc_inllen2 &&
853 data->ioc_bulk[size_round(data->ioc_inllen1) +
854 data->ioc_inllen2 - 1] != '\0') {
855 CERROR ("PORTALS ioctl: inlbuf2 not 0 terminated\n");
862 static inline int portal_ioctl_pack(struct portal_ioctl_data *data, char **pbuf,
866 struct portal_ioctl_data *overlay;
867 data->ioc_len = portal_ioctl_packlen(data);
868 data->ioc_version = PORTAL_IOCTL_VERSION;
870 if (*pbuf && portal_ioctl_packlen(data) > max)
873 *pbuf = malloc(data->ioc_len);
877 overlay = (struct portal_ioctl_data *)*pbuf;
878 memcpy(*pbuf, data, sizeof(*data));
880 ptr = overlay->ioc_bulk;
881 if (data->ioc_inlbuf1)
882 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
883 if (data->ioc_inlbuf2)
884 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
885 if (portal_ioctl_is_invalid(overlay))
891 #include <asm/uaccess.h>
893 /* buffer MUST be at least the size of portal_ioctl_hdr */
894 static inline int portal_ioctl_getdata(char *buf, char *end, void *arg)
896 struct portal_ioctl_hdr *hdr;
897 struct portal_ioctl_data *data;
901 hdr = (struct portal_ioctl_hdr *)buf;
902 data = (struct portal_ioctl_data *)buf;
904 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
910 if (hdr->ioc_version != PORTAL_IOCTL_VERSION) {
911 CERROR ("PORTALS: version mismatch kernel vs application\n");
915 if (hdr->ioc_len + buf >= end) {
916 CERROR ("PORTALS: user buffer exceeds kernel buffer\n");
921 if (hdr->ioc_len < sizeof(struct portal_ioctl_data)) {
922 CERROR ("PORTALS: user buffer too small for ioctl\n");
926 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
932 if (portal_ioctl_is_invalid(data)) {
933 CERROR ("PORTALS: ioctl not correctly formatted\n");
937 if (data->ioc_inllen1) {
938 data->ioc_inlbuf1 = &data->ioc_bulk[0];
941 if (data->ioc_inllen2) {
942 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
943 size_round(data->ioc_inllen1);
951 /* ioctls for manipulating snapshots 30- */
952 #define IOC_PORTAL_TYPE 'e'
953 #define IOC_PORTAL_MIN_NR 30
955 #define IOC_PORTAL_PING _IOWR('e', 30, long)
956 #define IOC_PORTAL_GET_DEBUG _IOWR('e', 31, long)
957 #define IOC_PORTAL_CLEAR_DEBUG _IOWR('e', 32, long)
958 #define IOC_PORTAL_MARK_DEBUG _IOWR('e', 33, long)
959 #define IOC_PORTAL_PANIC _IOWR('e', 34, long)
960 #define IOC_PORTAL_ADD_ROUTE _IOWR('e', 35, long)
961 #define IOC_PORTAL_DEL_ROUTE _IOWR('e', 36, long)
962 #define IOC_PORTAL_GET_ROUTE _IOWR('e', 37, long)
963 #define IOC_PORTAL_NAL_CMD _IOWR('e', 38, long)
964 #define IOC_PORTAL_GET_NID _IOWR('e', 39, long)
965 #define IOC_PORTAL_FAIL_NID _IOWR('e', 40, long)
966 #define IOC_PORTAL_SET_DAEMON _IOWR('e', 41, long)
967 #define IOC_PORTAL_NOTIFY_ROUTER _IOWR('e', 42, long)
968 #define IOC_PORTAL_LWT_CONTROL _IOWR('e', 43, long)
969 #define IOC_PORTAL_LWT_SNAPSHOT _IOWR('e', 44, long)
970 #define IOC_PORTAL_LWT_LOOKUP_STRING _IOWR('e', 45, long)
971 #define IOC_PORTAL_MAX_NR 45
984 extern ptl_handle_ni_t kqswnal_ni;
985 extern ptl_handle_ni_t ksocknal_ni;
986 extern ptl_handle_ni_t ktoenal_ni;
987 extern ptl_handle_ni_t kgmnal_ni;
988 extern ptl_handle_ni_t kscimacnal_ni;
991 #define NAL_MAX_NR (NAL_ENUM_END_MARKER - 1)
993 #define NAL_CMD_REGISTER_PEER_FD 100
994 #define NAL_CMD_CLOSE_CONNECTION 101
995 #define NAL_CMD_REGISTER_MYNID 102
996 #define NAL_CMD_PUSH_CONNECTION 103
997 #define NAL_CMD_GET_CONN 104
998 #define NAL_CMD_DEL_AUTOCONN 105
999 #define NAL_CMD_ADD_AUTOCONN 106
1000 #define NAL_CMD_GET_AUTOCONN 107
1001 #define NAL_CMD_GET_TXDESC 108
1004 DEBUG_DAEMON_START = 1,
1005 DEBUG_DAEMON_STOP = 2,
1006 DEBUG_DAEMON_PAUSE = 3,
1007 DEBUG_DAEMON_CONTINUE = 4,
1010 /* XXX remove to lustre ASAP */
1011 struct lustre_peer {
1013 ptl_handle_ni_t peer_ni;
1017 typedef int (*nal_cmd_handler_t)(struct portal_ioctl_data *, void * private);
1018 int kportal_nal_register(int nal, nal_cmd_handler_t handler, void * private);
1019 int kportal_nal_unregister(int nal);
1021 ptl_handle_ni_t *kportal_get_ni (int nal);
1022 void kportal_put_ni (int nal);
1025 # ifndef BITS_PER_LONG
1026 # if (~0UL) == 0xffffffffUL
1027 # define BITS_PER_LONG 32
1029 # define BITS_PER_LONG 64
1034 #if (BITS_PER_LONG == 32 || __WORDSIZE == 32)
1035 # define LPU64 "%Lu"
1036 # define LPD64 "%Ld"
1037 # define LPX64 "%#Lx"
1041 #if (BITS_PER_LONG == 64 || __WORDSIZE == 64)
1042 # define LPU64 "%lu"
1043 # define LPD64 "%ld"
1044 # define LPX64 "%#lx"
1046 # define LPSSZ "%ld"
1049 # error "No word size defined"