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);
375 /* NAL's routing interface (Kernel Portals Routing Nal Interface) */
376 typedef const struct {
377 int kprni_nalid; /* NAL's id */
378 void *kprni_arg; /* Arg to pass when calling into NAL */
379 kpr_fwd_t kprni_fwd; /* NAL's forwarding entrypoint */
380 } kpr_nal_interface_t;
382 /* Router's routing interface (Kernel Portals Routing Router Interface) */
383 typedef const struct {
384 /* register the calling NAL with the router and get back the handle for
385 * subsequent calls */
386 int (*kprri_register) (kpr_nal_interface_t *nal_interface,
389 /* ask the router to find a gateway that forwards to 'nid' and is a peer
390 * of the calling NAL */
391 int (*kprri_lookup) (void *router_arg, ptl_nid_t nid,
392 ptl_nid_t *gateway_nid);
394 /* hand a packet over to the router for forwarding */
395 kpr_fwd_t kprri_fwd_start;
397 /* hand a packet back to the router for completion */
398 void (*kprri_fwd_done) (void *router_arg, kpr_fwd_desc_t *fwd,
401 /* the calling NAL is shutting down */
402 void (*kprri_shutdown) (void *router_arg);
404 /* deregister the calling NAL with the router */
405 void (*kprri_deregister) (void *router_arg);
407 } kpr_router_interface_t;
409 /* Convenient struct for NAL to stash router interface/args */
411 kpr_router_interface_t *kpr_interface;
415 /* Router's control interface (Kernel Portals Routing Control Interface) */
416 typedef const struct {
417 int (*kprci_add_route)(int gateway_nal, ptl_nid_t gateway_nid,
418 ptl_nid_t lo_nid, ptl_nid_t hi_nid);
419 int (*kprci_del_route)(ptl_nid_t nid);
420 int (*kprci_get_route)(int index, int *gateway_nal,
421 ptl_nid_t *gateway, ptl_nid_t *lo_nid,
423 } kpr_control_interface_t;
425 extern kpr_control_interface_t kpr_control_interface;
426 extern kpr_router_interface_t kpr_router_interface;
429 kpr_register (kpr_router_t *router, kpr_nal_interface_t *nalif)
433 router->kpr_interface = PORTAL_SYMBOL_GET (kpr_router_interface);
434 if (router->kpr_interface == NULL)
437 rc = (router->kpr_interface)->kprri_register (nalif, &router->kpr_arg);
439 router->kpr_interface = NULL;
441 PORTAL_SYMBOL_PUT (kpr_router_interface);
446 kpr_routing (kpr_router_t *router)
448 return (router->kpr_interface != NULL);
452 kpr_lookup (kpr_router_t *router, ptl_nid_t nid, ptl_nid_t *gateway_nid)
454 if (!kpr_routing (router))
455 return (-EHOSTUNREACH);
457 return (router->kpr_interface->kprri_lookup(router->kpr_arg, nid,
462 kpr_fwd_init (kpr_fwd_desc_t *fwd, ptl_nid_t nid,
463 int nob, int niov, struct iovec *iov,
464 kpr_fwd_callback_t callback, void *callback_arg)
466 fwd->kprfd_target_nid = nid;
467 fwd->kprfd_gateway_nid = nid;
468 fwd->kprfd_nob = nob;
469 fwd->kprfd_niov = niov;
470 fwd->kprfd_iov = iov;
471 fwd->kprfd_callback = callback;
472 fwd->kprfd_callback_arg = callback_arg;
476 kpr_fwd_start (kpr_router_t *router, kpr_fwd_desc_t *fwd)
478 if (!kpr_routing (router))
479 fwd->kprfd_callback (fwd->kprfd_callback_arg, -EHOSTUNREACH);
481 router->kpr_interface->kprri_fwd_start (router->kpr_arg, fwd);
485 kpr_fwd_done (kpr_router_t *router, kpr_fwd_desc_t *fwd, int error)
487 LASSERT (kpr_routing (router));
488 router->kpr_interface->kprri_fwd_done (router->kpr_arg, fwd, error);
492 kpr_shutdown (kpr_router_t *router)
494 if (kpr_routing (router))
495 router->kpr_interface->kprri_shutdown (router->kpr_arg);
499 kpr_deregister (kpr_router_t *router)
501 if (!kpr_routing (router))
503 router->kpr_interface->kprri_deregister (router->kpr_arg);
504 router->kpr_interface = NULL;
507 /******************************************************************************/
509 #ifdef PORTALS_PROFILING
510 #define prof_enum(FOO) PROF__##FOO
512 prof_enum(our_recvmsg),
513 prof_enum(our_sendmsg),
514 prof_enum(socknal_recv),
515 prof_enum(lib_parse),
516 prof_enum(conn_list_walk),
518 prof_enum(lib_finalize),
519 prof_enum(pingcli_time),
520 prof_enum(gmnal_send),
521 prof_enum(gmnal_recv),
527 /* hrmph. wrap-tastic. */
530 cycles_t total_cycles;
535 extern struct prof_ent prof_ents[MAX_PROFS];
537 #define PROF_START(FOO) \
539 struct prof_ent *pe = &prof_ents[PROF__##FOO]; \
541 pe->start = get_cycles(); \
544 #define PROF_FINISH(FOO) \
546 struct prof_ent *pe = &prof_ents[PROF__##FOO]; \
548 pe->end = get_cycles(); \
549 pe->total_cycles += (pe->end - pe->start); \
551 #else /* !PORTALS_PROFILING */
552 #define PROF_START(FOO) do {} while(0)
553 #define PROF_FINISH(FOO) do {} while(0)
554 #endif /* PORTALS_PROFILING */
557 void portals_run_lbug_upcall(char * file, const char *fn, const int line);
558 void portals_debug_dumplog(void);
559 int portals_debug_init(unsigned long bufsize);
560 int portals_debug_cleanup(void);
561 int portals_debug_clear_buffer(void);
562 int portals_debug_mark_buffer(char *text);
563 int portals_debug_set_daemon(unsigned int cmd, unsigned int length,
564 char *file, unsigned int size);
565 __s32 portals_debug_copy_to_user(char *buf, unsigned long len);
567 /* Use the special GNU C __attribute__ hack to have the compiler check the
568 * printf style argument string against the actual argument count and
572 # warning printf has been defined as a macro...
575 void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
576 const int line, unsigned long stack,
577 const char *format, ...)
578 __attribute__ ((format (printf, 7, 8)));
580 void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
581 const int line, unsigned long stack,
582 const char *format, ...);
583 #endif /* __GNUC__ */
584 void portals_debug_set_level(unsigned int debug_level);
586 # define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
587 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
588 # define time(a) CURRENT_TIME
590 extern void kportal_daemonize (char *name);
591 extern void kportal_blockallsigs (void);
593 #else /* !__KERNEL__ */
601 # include <asm/types.h>
602 # ifndef DEBUG_SUBSYSTEM
603 # define DEBUG_SUBSYSTEM S_UNDEFINED
608 # define LASSERT(e) assert(e)
612 # define printk(format, args...) printf (format, ## args)
613 # define PORTAL_ALLOC(ptr, size) do { (ptr) = malloc(size); } while (0);
614 # define PORTAL_FREE(a, b) do { free(a); } while (0);
615 # define portals_debug_msg(subsys, mask, file, fn, line, stack, format, a...) \
616 printf("%02x:%06x (@%lu %s:%s,l. %d %d %lu): " format, \
617 (subsys), (mask), (long)time(0), file, fn, line, \
618 getpid() , stack, ## a);
622 # define CURRENT_TIME time(0)
625 #include <linux/portals_lib.h>
628 * USER LEVEL STUFF BELOW
631 #define PORTAL_IOCTL_VERSION 0x00010007
635 struct portal_ioctl_data {
659 __u32 ioc_plen1; /* buffers in userspace */
661 __u32 ioc_plen2; /* buffers in userspace */
667 struct portal_ioctl_hdr {
672 struct portals_debug_ioctl_data
674 struct portal_ioctl_hdr hdr;
679 #define PORTAL_IOC_INIT(data) \
681 memset(&data, 0, sizeof(data)); \
682 data.ioc_version = PORTAL_IOCTL_VERSION; \
683 data.ioc_len = sizeof(data); \
686 /* FIXME check conflict with lustre_lib.h */
687 #define PTL_IOC_DEBUG_MASK _IOWR('f', 250, long)
689 static inline int portal_ioctl_packlen(struct portal_ioctl_data *data)
691 int len = sizeof(*data);
692 len += size_round(data->ioc_inllen1);
693 len += size_round(data->ioc_inllen2);
697 static inline int portal_ioctl_is_invalid(struct portal_ioctl_data *data)
699 if (data->ioc_len > (1<<30)) {
700 CERROR ("PORTALS ioctl: ioc_len larger than 1<<30\n");
703 if (data->ioc_inllen1 > (1<<30)) {
704 CERROR ("PORTALS ioctl: ioc_inllen1 larger than 1<<30\n");
707 if (data->ioc_inllen2 > (1<<30)) {
708 CERROR ("PORTALS ioctl: ioc_inllen2 larger than 1<<30\n");
711 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
712 CERROR ("PORTALS ioctl: inlbuf1 pointer but 0 length\n");
715 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
716 CERROR ("PORTALS ioctl: inlbuf2 pointer but 0 length\n");
719 if (data->ioc_pbuf1 && !data->ioc_plen1) {
720 CERROR ("PORTALS ioctl: pbuf1 pointer but 0 length\n");
723 if (data->ioc_pbuf2 && !data->ioc_plen2) {
724 CERROR ("PORTALS ioctl: pbuf2 pointer but 0 length\n");
727 if (data->ioc_plen1 && !data->ioc_pbuf1) {
728 CERROR ("PORTALS ioctl: plen1 nonzero but no pbuf1 pointer\n");
731 if (data->ioc_plen2 && !data->ioc_pbuf2) {
732 CERROR ("PORTALS ioctl: plen2 nonzero but no pbuf2 pointer\n");
735 if (portal_ioctl_packlen(data) != data->ioc_len ) {
736 CERROR ("PORTALS ioctl: packlen != ioc_len\n");
739 if (data->ioc_inllen1 &&
740 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
741 CERROR ("PORTALS ioctl: inlbuf1 not 0 terminated\n");
744 if (data->ioc_inllen2 &&
745 data->ioc_bulk[size_round(data->ioc_inllen1) +
746 data->ioc_inllen2 - 1] != '\0') {
747 CERROR ("PORTALS ioctl: inlbuf2 not 0 terminated\n");
754 static inline int portal_ioctl_pack(struct portal_ioctl_data *data, char **pbuf,
758 struct portal_ioctl_data *overlay;
759 data->ioc_len = portal_ioctl_packlen(data);
760 data->ioc_version = PORTAL_IOCTL_VERSION;
762 if (*pbuf && portal_ioctl_packlen(data) > max)
765 *pbuf = malloc(data->ioc_len);
769 overlay = (struct portal_ioctl_data *)*pbuf;
770 memcpy(*pbuf, data, sizeof(*data));
772 ptr = overlay->ioc_bulk;
773 if (data->ioc_inlbuf1)
774 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
775 if (data->ioc_inlbuf2)
776 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
777 if (portal_ioctl_is_invalid(overlay))
783 #include <asm/uaccess.h>
785 /* buffer MUST be at least the size of portal_ioctl_hdr */
786 static inline int portal_ioctl_getdata(char *buf, char *end, void *arg)
788 struct portal_ioctl_hdr *hdr;
789 struct portal_ioctl_data *data;
793 hdr = (struct portal_ioctl_hdr *)buf;
794 data = (struct portal_ioctl_data *)buf;
796 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
802 if (hdr->ioc_version != PORTAL_IOCTL_VERSION) {
803 CERROR ("PORTALS: version mismatch kernel vs application\n");
807 if (hdr->ioc_len + buf >= end) {
808 CERROR ("PORTALS: user buffer exceeds kernel buffer\n");
813 if (hdr->ioc_len < sizeof(struct portal_ioctl_data)) {
814 CERROR ("PORTALS: user buffer too small for ioctl\n");
818 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
824 if (portal_ioctl_is_invalid(data)) {
825 CERROR ("PORTALS: ioctl not correctly formatted\n");
829 if (data->ioc_inllen1) {
830 data->ioc_inlbuf1 = &data->ioc_bulk[0];
833 if (data->ioc_inllen2) {
834 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
835 size_round(data->ioc_inllen1);
843 /* ioctls for manipulating snapshots 30- */
844 #define IOC_PORTAL_TYPE 'e'
845 #define IOC_PORTAL_MIN_NR 30
847 #define IOC_PORTAL_PING _IOWR('e', 30, long)
848 #define IOC_PORTAL_GET_DEBUG _IOWR('e', 31, long)
849 #define IOC_PORTAL_CLEAR_DEBUG _IOWR('e', 32, long)
850 #define IOC_PORTAL_MARK_DEBUG _IOWR('e', 33, long)
851 #define IOC_PORTAL_PANIC _IOWR('e', 34, long)
852 #define IOC_PORTAL_ADD_ROUTE _IOWR('e', 35, long)
853 #define IOC_PORTAL_DEL_ROUTE _IOWR('e', 36, long)
854 #define IOC_PORTAL_GET_ROUTE _IOWR('e', 37, long)
855 #define IOC_PORTAL_NAL_CMD _IOWR('e', 38, long)
856 #define IOC_PORTAL_GET_NID _IOWR('e', 39, long)
857 #define IOC_PORTAL_FAIL_NID _IOWR('e', 40, long)
858 #define IOC_PORTAL_SET_DAEMON _IOWR('e', 41, long)
860 #define IOC_PORTAL_MAX_NR 41
873 extern ptl_handle_ni_t kqswnal_ni;
874 extern ptl_handle_ni_t ksocknal_ni;
875 extern ptl_handle_ni_t ktoenal_ni;
876 extern ptl_handle_ni_t kgmnal_ni;
877 extern ptl_handle_ni_t kscimacnal_ni;
880 #define NAL_MAX_NR (NAL_ENUM_END_MARKER - 1)
882 #define NAL_CMD_REGISTER_PEER_FD 100
883 #define NAL_CMD_CLOSE_CONNECTION 101
884 #define NAL_CMD_REGISTER_MYNID 102
885 #define NAL_CMD_PUSH_CONNECTION 103
888 DEBUG_DAEMON_START = 1,
889 DEBUG_DAEMON_STOP = 2,
890 DEBUG_DAEMON_PAUSE = 3,
891 DEBUG_DAEMON_CONTINUE = 4,
894 /* XXX remove to lustre ASAP */
897 ptl_handle_ni_t peer_ni;
901 typedef int (*nal_cmd_handler_t)(struct portal_ioctl_data *, void * private);
902 int kportal_nal_register(int nal, nal_cmd_handler_t handler, void * private);
903 int kportal_nal_unregister(int nal);
905 ptl_handle_ni_t *kportal_get_ni (int nal);
906 void kportal_put_ni (int nal);
909 # ifndef BITS_PER_LONG
910 # if (~0UL) == 0xffffffffUL
911 # define BITS_PER_LONG 32
913 # define BITS_PER_LONG 64
918 #if (BITS_PER_LONG == 32 || __WORDSIZE == 32)
921 # define LPX64 "%#Lx"
925 #if (BITS_PER_LONG == 64 || __WORDSIZE == 64)
928 # define LPX64 "%#lx"
933 # error "No word size defined"