1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
11 # define offsetof(typ,memb) ((int)((char *)&(((typ *)0)->memb)))
14 #define LOWEST_BIT_SET(x) ((x) & ~((x) - 1))
17 # define smp_processor_id() 0
23 extern unsigned int portal_subsystem_debug;
24 extern unsigned int portal_stack;
25 extern unsigned int portal_debug;
26 extern unsigned int portal_printk;
27 /* Debugging subsystems (8 bit ID)
29 * If you add debug subsystem #32, you need to send email to phil, because
30 * you're going to break kernel subsystem debug filtering. */
31 #define S_UNDEFINED (0 << 24)
32 #define S_MDC (1 << 24)
33 #define S_MDS (2 << 24)
34 #define S_OSC (3 << 24)
35 #define S_OST (4 << 24)
36 #define S_CLASS (5 << 24)
37 #define S_OBDFS (6 << 24) /* obsolete */
38 #define S_LLITE (7 << 24)
39 #define S_RPC (8 << 24)
40 #define S_EXT2OBD (9 << 24) /* obsolete */
41 #define S_PORTALS (10 << 24)
42 #define S_SOCKNAL (11 << 24)
43 #define S_QSWNAL (12 << 24)
44 #define S_PINGER (13 << 24)
45 #define S_FILTER (14 << 24)
46 #define S_TRACE (15 << 24) /* obsolete */
47 #define S_ECHO (16 << 24)
48 #define S_LDLM (17 << 24)
49 #define S_LOV (18 << 24)
50 #define S_GMNAL (19 << 24)
51 #define S_PTLROUTER (20 << 24)
52 #define S_COBD (21 << 24)
53 #define S_PTLBD (22 << 24)
54 #define S_LOG (23 << 24)
56 /* If you change these values, please keep portals/linux/utils/debug.c
59 /* Debugging masks (24 bits, non-overlapping) */
60 #define D_TRACE (1 << 0) /* ENTRY/EXIT markers */
61 #define D_INODE (1 << 1)
62 #define D_SUPER (1 << 2)
63 #define D_EXT2 (1 << 3) /* anything from ext2_debug */
64 #define D_MALLOC (1 << 4) /* print malloc, free information */
65 #define D_CACHE (1 << 5) /* cache-related items */
66 #define D_INFO (1 << 6) /* general information */
67 #define D_IOCTL (1 << 7) /* ioctl related information */
68 #define D_BLOCKS (1 << 8) /* ext2 block allocation */
69 #define D_NET (1 << 9) /* network communications */
70 #define D_WARNING (1 << 10)
71 #define D_BUFFS (1 << 11)
72 #define D_OTHER (1 << 12)
73 #define D_DENTRY (1 << 13)
74 #define D_PORTALS (1 << 14) /* ENTRY/EXIT markers */
75 #define D_PAGE (1 << 15) /* bulk page handling */
76 #define D_DLMTRACE (1 << 16)
77 #define D_ERROR (1 << 17) /* CERROR(...) == CDEBUG (D_ERROR, ...) */
78 #define D_EMERG (1 << 18) /* CEMERG(...) == CDEBUG (D_EMERG, ...) */
79 #define D_HA (1 << 19) /* recovery and failover */
80 #define D_RPCTRACE (1 << 20) /* for distributed debugging */
81 #define D_VFSTRACE (1 << 21)
84 #define THREAD_SIZE 8192
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) & \
97 #define CHECK_STACK(stack) \
99 if ((stack) > 3*THREAD_SIZE/4 && (stack) > portal_stack) { \
100 portals_debug_msg(DEBUG_SUBSYSTEM, D_ERROR, \
101 __FILE__, __FUNCTION__, __LINE__, \
103 "maximum lustre stack %u\n", \
104 portal_stack = (stack)); \
109 #define CHECK_STACK(stack) do { } while(0)
113 #define CDEBUG(mask, format, a...) \
115 CHECK_STACK(CDEBUG_STACK()); \
116 if (!(mask) || ((mask) & (D_ERROR | D_EMERG)) || \
117 (portal_debug & (mask) && \
118 portal_subsystem_debug & (1 << (DEBUG_SUBSYSTEM >> 24)))) \
119 portals_debug_msg(DEBUG_SUBSYSTEM, mask, \
120 __FILE__, __FUNCTION__, __LINE__, \
121 CDEBUG_STACK(), format , ## a); \
124 #define CWARN(format, a...) CDEBUG(D_WARNING, format, ## a)
125 #define CERROR(format, a...) CDEBUG(D_ERROR, format, ## a)
126 #define CEMERG(format, a...) CDEBUG(D_EMERG, format, ## a)
128 #define GOTO(label, rc) \
130 long GOTO__ret = (long)(rc); \
131 CDEBUG(D_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n", \
132 #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret,\
133 (signed long)GOTO__ret); \
139 typeof(rc) RETURN__ret = (rc); \
140 CDEBUG(D_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n", \
141 (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret);\
142 return RETURN__ret; \
147 CDEBUG(D_TRACE, "Process entered\n"); \
152 CDEBUG(D_TRACE, "Process leaving\n"); \
155 #define CDEBUG(mask, format, a...) do { } while (0)
156 #define CWARN(format, a...) do { } while (0)
157 #define CERROR(format, a...) printk("<3>" format, ## a)
158 #define CEMERG(format, a...) printk("<0>" format, ## a)
159 #define GOTO(label, rc) do { (void)(rc); goto label; } while (0)
160 #define RETURN(rc) return (rc)
161 #define ENTRY do { } while (0)
162 #define EXIT do { } while (0)
167 # include <linux/vmalloc.h>
168 # include <linux/time.h>
169 # include <linux/slab.h>
170 # include <linux/interrupt.h>
171 # include <linux/highmem.h>
172 # include <linux/module.h>
173 # include <linux/version.h>
174 # include <portals/lib-nal.h>
175 # include <linux/smp_lock.h>
176 # include <asm/atomic.h>
178 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
179 #define schedule_work schedule_task
180 #define prepare_work(wq,cb,cbdata) \
182 INIT_TQUEUE((wq), 0, 0); \
183 PREPARE_TQUEUE((wq), (cb), (cbdata)); \
186 #define ll_invalidate_inode_pages invalidate_inode_pages
187 #define PageUptodate Page_Uptodate
188 #define our_recalc_sigpending(current) recalc_sigpending(current)
189 #define num_online_cpus() smp_num_cpus
190 static inline void our_cond_resched(void)
192 if (current->need_resched)
198 #define prepare_work(wq,cb,cbdata) \
200 INIT_WORK((wq), (void *)(cb), (void *)(cbdata)); \
202 #define ll_invalidate_inode_pages(inode) invalidate_inode_pages((inode)->i_mapping)
203 #define wait_on_page wait_on_page_locked
204 #define our_recalc_sigpending(current) recalc_sigpending()
205 #define strtok(a,b) strpbrk(a, b)
206 static inline void our_cond_resched(void)
210 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
213 extern void kportal_assertion_failed(char *expr,char *file,char *func,int line);
214 #define LASSERT(e) ((e) ? 0 : kportal_assertion_failed( #e , __FILE__, \
215 __FUNCTION__, __LINE__))
221 #define LBUG_WITH_LOC(file, func, line) \
223 CEMERG("LBUG - trying to dump log to /tmp/lustre-log\n"); \
224 portals_debug_dumplog(); \
225 portals_run_lbug_upcall(file, func, line); \
229 #define LBUG_WITH_LOC(file, func, line) \
232 portals_debug_dumplog(); \
233 portals_run_lbug_upcall(file, func, line); \
234 set_task_state(current, TASK_UNINTERRUPTIBLE); \
237 #endif /* __arch_um__ */
239 #define LBUG() LBUG_WITH_LOC(__FILE__, __FUNCTION__, __LINE__)
245 extern atomic_t portal_kmemory;
247 # define portal_kmem_inc(ptr, size) \
249 atomic_add(size, &portal_kmemory); \
252 # define portal_kmem_dec(ptr, size) do { \
253 atomic_sub(size, &portal_kmemory); \
257 # define portal_kmem_inc(ptr, size) do {} while (0)
258 # define portal_kmem_dec(ptr, size) do {} while (0)
259 #endif /* PORTAL_DEBUG */
261 #define PORTAL_VMALLOC_SIZE 16384
263 #define PORTAL_ALLOC(ptr, size) \
265 LASSERT (!in_interrupt()); \
266 if ((size) > PORTAL_VMALLOC_SIZE) \
267 (ptr) = vmalloc(size); \
269 (ptr) = kmalloc((size), GFP_NOFS); \
271 CERROR("PORTALS: out of memory at %s:%d (tried to alloc '"\
272 #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size));\
274 portal_kmem_inc((ptr), (size)); \
275 memset((ptr), 0, (size)); \
277 CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %d at %p (tot %d).\n", \
278 (int)(size), (ptr), atomic_read (&portal_kmemory)); \
281 #define PORTAL_FREE(ptr, size) \
284 if ((ptr) == NULL) { \
285 CERROR("PORTALS: free NULL '" #ptr "' (%d bytes) at " \
286 "%s:%d\n", s, __FILE__, __LINE__); \
289 if (s > PORTAL_VMALLOC_SIZE) \
293 portal_kmem_dec((ptr), s); \
294 CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n", \
295 s, (ptr), atomic_read(&portal_kmemory)); \
298 #define PORTAL_SLAB_ALLOC(ptr, slab, size) \
300 LASSERT(!in_interrupt()); \
301 (ptr) = kmem_cache_alloc((slab), SLAB_KERNEL); \
302 if ((ptr) == NULL) { \
303 CERROR("PORTALS: out of memory at %s:%d (tried to alloc" \
304 " '" #ptr "' from slab '" #slab "')\n", __FILE__, \
307 portal_kmem_inc((ptr), (size)); \
308 memset((ptr), 0, (size)); \
310 CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %ld at %p (tot %d).\n", \
311 (int)(size), (ptr), atomic_read(&portal_kmemory)); \
314 #define PORTAL_SLAB_FREE(ptr, slab, size) \
317 if ((ptr) == NULL) { \
318 CERROR("PORTALS: free NULL '" #ptr "' (%d bytes) at " \
319 "%s:%d\n", s, __FILE__, __LINE__); \
322 memset((ptr), 0x5a, s); \
323 kmem_cache_free((slab), ptr); \
324 portal_kmem_dec((ptr), s); \
325 CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n", \
326 s, (ptr), atomic_read (&portal_kmemory)); \
329 /* ------------------------------------------------------------------- */
331 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
333 #define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
334 #define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
336 #define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
337 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
339 #define PORTAL_MODULE_USE MOD_INC_USE_COUNT
340 #define PORTAL_MODULE_UNUSE MOD_DEC_USE_COUNT
343 #define PORTAL_SYMBOL_REGISTER(x)
344 #define PORTAL_SYMBOL_UNREGISTER(x)
346 #define PORTAL_SYMBOL_GET(x) symbol_get(x)
347 #define PORTAL_SYMBOL_PUT(x) symbol_put(x)
349 #define PORTAL_MODULE_USE try_module_get(THIS_MODULE)
350 #define PORTAL_MODULE_UNUSE module_put(THIS_MODULE)
354 /******************************************************************************/
355 /* Kernel Portals Router interface */
357 typedef void (*kpr_fwd_callback_t)(void *arg, int error); // completion callback
359 /* space for routing targets to stash "stuff" in a forwarded packet */
361 long long _alignment;
362 void *_space[16]; /* scale with CPU arch */
365 /* Kernel Portals Routing Forwarded message Descriptor */
367 struct list_head kprfd_list; /* stash in queues (routing target can use) */
368 ptl_nid_t kprfd_target_nid; /* final destination NID */
369 ptl_nid_t kprfd_gateway_nid; /* gateway NID */
370 int kprfd_nob; /* # message bytes (including header) */
371 int kprfd_niov; /* # message frags (including header) */
372 struct iovec *kprfd_iov; /* message fragments */
373 void *kprfd_router_arg; // originating NAL's router arg
374 kpr_fwd_callback_t kprfd_callback; /* completion callback */
375 void *kprfd_callback_arg; /* completion callback arg */
376 kprfd_scratch_t kprfd_scratch; // scratchpad for routing targets
379 typedef void (*kpr_fwd_t)(void *arg, kpr_fwd_desc_t *fwd);
381 /* NAL's routing interface (Kernel Portals Routing Nal Interface) */
382 typedef const struct {
383 int kprni_nalid; /* NAL's id */
384 void *kprni_arg; /* Arg to pass when calling into NAL */
385 kpr_fwd_t kprni_fwd; /* NAL's forwarding entrypoint */
386 } kpr_nal_interface_t;
388 /* Router's routing interface (Kernel Portals Routing Router Interface) */
389 typedef const struct {
390 /* register the calling NAL with the router and get back the handle for
391 * subsequent calls */
392 int (*kprri_register) (kpr_nal_interface_t *nal_interface,
395 /* ask the router to find a gateway that forwards to 'nid' and is a peer
396 * of the calling NAL */
397 int (*kprri_lookup) (void *router_arg, ptl_nid_t nid,
398 ptl_nid_t *gateway_nid);
400 /* hand a packet over to the router for forwarding */
401 kpr_fwd_t kprri_fwd_start;
403 /* hand a packet back to the router for completion */
404 void (*kprri_fwd_done) (void *router_arg, kpr_fwd_desc_t *fwd,
407 /* the calling NAL is shutting down */
408 void (*kprri_shutdown) (void *router_arg);
410 /* deregister the calling NAL with the router */
411 void (*kprri_deregister) (void *router_arg);
413 } kpr_router_interface_t;
415 /* Convenient struct for NAL to stash router interface/args */
417 kpr_router_interface_t *kpr_interface;
421 /* Router's control interface (Kernel Portals Routing Control Interface) */
422 typedef const struct {
423 int (*kprci_add_route)(int gateway_nal, ptl_nid_t gateway_nid,
424 ptl_nid_t lo_nid, ptl_nid_t hi_nid);
425 int (*kprci_del_route)(ptl_nid_t nid);
426 int (*kprci_get_route)(int index, int *gateway_nal,
427 ptl_nid_t *gateway, ptl_nid_t *lo_nid,
429 } kpr_control_interface_t;
431 extern kpr_control_interface_t kpr_control_interface;
432 extern kpr_router_interface_t kpr_router_interface;
435 kpr_register (kpr_router_t *router, kpr_nal_interface_t *nalif)
439 router->kpr_interface = PORTAL_SYMBOL_GET (kpr_router_interface);
440 if (router->kpr_interface == NULL)
443 rc = (router->kpr_interface)->kprri_register (nalif, &router->kpr_arg);
445 router->kpr_interface = NULL;
447 PORTAL_SYMBOL_PUT (kpr_router_interface);
452 kpr_routing (kpr_router_t *router)
454 return (router->kpr_interface != NULL);
458 kpr_lookup (kpr_router_t *router, ptl_nid_t nid, ptl_nid_t *gateway_nid)
460 if (!kpr_routing (router))
461 return (-EHOSTUNREACH);
463 return (router->kpr_interface->kprri_lookup(router->kpr_arg, nid,
468 kpr_fwd_init (kpr_fwd_desc_t *fwd, ptl_nid_t nid,
469 int nob, int niov, struct iovec *iov,
470 kpr_fwd_callback_t callback, void *callback_arg)
472 fwd->kprfd_target_nid = nid;
473 fwd->kprfd_gateway_nid = nid;
474 fwd->kprfd_nob = nob;
475 fwd->kprfd_niov = niov;
476 fwd->kprfd_iov = iov;
477 fwd->kprfd_callback = callback;
478 fwd->kprfd_callback_arg = callback_arg;
482 kpr_fwd_start (kpr_router_t *router, kpr_fwd_desc_t *fwd)
484 if (!kpr_routing (router))
485 fwd->kprfd_callback (fwd->kprfd_callback_arg, -EHOSTUNREACH);
487 router->kpr_interface->kprri_fwd_start (router->kpr_arg, fwd);
491 kpr_fwd_done (kpr_router_t *router, kpr_fwd_desc_t *fwd, int error)
493 LASSERT (kpr_routing (router));
494 router->kpr_interface->kprri_fwd_done (router->kpr_arg, fwd, error);
498 kpr_shutdown (kpr_router_t *router)
500 if (kpr_routing (router))
501 router->kpr_interface->kprri_shutdown (router->kpr_arg);
505 kpr_deregister (kpr_router_t *router)
507 if (!kpr_routing (router))
509 router->kpr_interface->kprri_deregister (router->kpr_arg);
510 router->kpr_interface = NULL;
513 /******************************************************************************/
515 #ifdef PORTALS_PROFILING
516 #define prof_enum(FOO) PROF__##FOO
518 prof_enum(our_recvmsg),
519 prof_enum(our_sendmsg),
520 prof_enum(socknal_recv),
521 prof_enum(lib_parse),
522 prof_enum(conn_list_walk),
524 prof_enum(lib_finalize),
525 prof_enum(pingcli_time),
526 prof_enum(gmnal_send),
527 prof_enum(gmnal_recv),
533 /* hrmph. wrap-tastic. */
536 cycles_t total_cycles;
541 extern struct prof_ent prof_ents[MAX_PROFS];
543 #define PROF_START(FOO) \
545 struct prof_ent *pe = &prof_ents[PROF__##FOO]; \
547 pe->start = get_cycles(); \
550 #define PROF_FINISH(FOO) \
552 struct prof_ent *pe = &prof_ents[PROF__##FOO]; \
554 pe->end = get_cycles(); \
555 pe->total_cycles += (pe->end - pe->start); \
557 #else /* !PORTALS_PROFILING */
558 #define PROF_START(FOO) do {} while(0)
559 #define PROF_FINISH(FOO) do {} while(0)
560 #endif /* PORTALS_PROFILING */
563 void portals_run_lbug_upcall(char * file, char *fn, int line);
564 void portals_debug_dumplog(void);
565 int portals_debug_init(unsigned long bufsize);
566 int portals_debug_cleanup(void);
567 int portals_debug_clear_buffer(void);
568 int portals_debug_mark_buffer(char *text);
569 int portals_debug_set_daemon(unsigned int cmd, unsigned int length,
570 char *file, unsigned int size);
571 __s32 portals_debug_copy_to_user(char *buf, unsigned long len);
573 /* Use the special GNU C __attribute__ hack to have the compiler check the
574 * printf style argument string against the actual argument count and
578 # warning printf has been defined as a macro...
581 void portals_debug_msg (int subsys, int mask, char *file, char *fn, int line,
582 unsigned long stack, const char *format, ...)
583 __attribute__ ((format (printf, 7, 8)));
585 void portals_debug_msg (int subsys, int mask, char *file, char *fn,
586 int line, unsigned long stack,
587 const char *format, ...);
588 #endif /* __GNUC__ */
589 void portals_debug_set_level(unsigned int debug_level);
591 # define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
592 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
593 # define time(a) CURRENT_TIME
595 extern void kportal_daemonize (char *name);
596 extern void kportal_blockallsigs (void);
598 #else /* !__KERNEL__ */
606 # include <asm/types.h>
607 # ifndef DEBUG_SUBSYSTEM
608 # define DEBUG_SUBSYSTEM S_UNDEFINED
613 # define LASSERT(e) assert(e)
617 # define printk(format, args...) printf (format, ## args)
618 # define PORTAL_ALLOC(ptr, size) do { (ptr) = malloc(size); } while (0);
619 # define PORTAL_FREE(a, b) do { free(a); } while (0);
620 # define portals_debug_msg(subsys, mask, file, fn, line, stack, format, a...) \
621 printf ("%02x:%06x (@%lu %s:%s,l. %d %d %lu): " format, \
622 (subsys) >> 24, (mask), (long)time(0), file, fn, line, \
623 getpid() , stack, ## a);
627 # define CURRENT_TIME time(0)
630 #include <linux/portals_lib.h>
633 * USER LEVEL STUFF BELOW
636 #define PORTAL_IOCTL_VERSION 0x00010007
640 struct portal_ioctl_data {
664 __u32 ioc_plen1; /* buffers in userspace */
666 __u32 ioc_plen2; /* buffers in userspace */
672 struct portal_ioctl_hdr {
677 struct portals_debug_ioctl_data
679 struct portal_ioctl_hdr hdr;
684 #define PORTAL_IOC_INIT(data) \
686 memset(&data, 0, sizeof(data)); \
687 data.ioc_version = PORTAL_IOCTL_VERSION; \
688 data.ioc_len = sizeof(data); \
691 /* FIXME check conflict with lustre_lib.h */
692 #define PTL_IOC_DEBUG_MASK _IOWR('f', 250, long)
694 static inline int portal_ioctl_packlen(struct portal_ioctl_data *data)
696 int len = sizeof(*data);
697 len += size_round(data->ioc_inllen1);
698 len += size_round(data->ioc_inllen2);
702 static inline int portal_ioctl_is_invalid(struct portal_ioctl_data *data)
704 if (data->ioc_len > (1<<30)) {
705 CERROR ("PORTALS ioctl: ioc_len larger than 1<<30\n");
708 if (data->ioc_inllen1 > (1<<30)) {
709 CERROR ("PORTALS ioctl: ioc_inllen1 larger than 1<<30\n");
712 if (data->ioc_inllen2 > (1<<30)) {
713 CERROR ("PORTALS ioctl: ioc_inllen2 larger than 1<<30\n");
716 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
717 CERROR ("PORTALS ioctl: inlbuf1 pointer but 0 length\n");
720 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
721 CERROR ("PORTALS ioctl: inlbuf2 pointer but 0 length\n");
724 if (data->ioc_pbuf1 && !data->ioc_plen1) {
725 CERROR ("PORTALS ioctl: pbuf1 pointer but 0 length\n");
728 if (data->ioc_pbuf2 && !data->ioc_plen2) {
729 CERROR ("PORTALS ioctl: pbuf2 pointer but 0 length\n");
732 if (data->ioc_plen1 && !data->ioc_pbuf1) {
733 CERROR ("PORTALS ioctl: plen1 nonzero but no pbuf1 pointer\n");
736 if (data->ioc_plen2 && !data->ioc_pbuf2) {
737 CERROR ("PORTALS ioctl: plen2 nonzero but no pbuf2 pointer\n");
740 if (portal_ioctl_packlen(data) != data->ioc_len ) {
741 CERROR ("PORTALS ioctl: packlen != ioc_len\n");
744 if (data->ioc_inllen1 &&
745 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
746 CERROR ("PORTALS ioctl: inlbuf1 not 0 terminated\n");
749 if (data->ioc_inllen2 &&
750 data->ioc_bulk[size_round(data->ioc_inllen1) +
751 data->ioc_inllen2 - 1] != '\0') {
752 CERROR ("PORTALS ioctl: inlbuf2 not 0 terminated\n");
759 static inline int portal_ioctl_pack(struct portal_ioctl_data *data, char **pbuf,
763 struct portal_ioctl_data *overlay;
764 data->ioc_len = portal_ioctl_packlen(data);
765 data->ioc_version = PORTAL_IOCTL_VERSION;
767 if (*pbuf && portal_ioctl_packlen(data) > max)
770 *pbuf = malloc(data->ioc_len);
774 overlay = (struct portal_ioctl_data *)*pbuf;
775 memcpy(*pbuf, data, sizeof(*data));
777 ptr = overlay->ioc_bulk;
778 if (data->ioc_inlbuf1)
779 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
780 if (data->ioc_inlbuf2)
781 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
782 if (portal_ioctl_is_invalid(overlay))
788 #include <asm/uaccess.h>
790 /* buffer MUST be at least the size of portal_ioctl_hdr */
791 static inline int portal_ioctl_getdata(char *buf, char *end, void *arg)
793 struct portal_ioctl_hdr *hdr;
794 struct portal_ioctl_data *data;
798 hdr = (struct portal_ioctl_hdr *)buf;
799 data = (struct portal_ioctl_data *)buf;
801 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
807 if (hdr->ioc_version != PORTAL_IOCTL_VERSION) {
808 CERROR ("PORTALS: version mismatch kernel vs application\n");
812 if (hdr->ioc_len + buf >= end) {
813 CERROR ("PORTALS: user buffer exceeds kernel buffer\n");
818 if (hdr->ioc_len < sizeof(struct portal_ioctl_data)) {
819 CERROR ("PORTALS: user buffer too small for ioctl\n");
823 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
829 if (portal_ioctl_is_invalid(data)) {
830 CERROR ("PORTALS: ioctl not correctly formatted\n");
834 if (data->ioc_inllen1) {
835 data->ioc_inlbuf1 = &data->ioc_bulk[0];
838 if (data->ioc_inllen2) {
839 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
840 size_round(data->ioc_inllen1);
848 /* ioctls for manipulating snapshots 30- */
849 #define IOC_PORTAL_TYPE 'e'
850 #define IOC_PORTAL_MIN_NR 30
852 #define IOC_PORTAL_PING _IOWR('e', 30, long)
853 #define IOC_PORTAL_GET_DEBUG _IOWR('e', 31, long)
854 #define IOC_PORTAL_CLEAR_DEBUG _IOWR('e', 32, long)
855 #define IOC_PORTAL_MARK_DEBUG _IOWR('e', 33, long)
856 #define IOC_PORTAL_PANIC _IOWR('e', 34, long)
857 #define IOC_PORTAL_ADD_ROUTE _IOWR('e', 35, long)
858 #define IOC_PORTAL_DEL_ROUTE _IOWR('e', 36, long)
859 #define IOC_PORTAL_GET_ROUTE _IOWR('e', 37, long)
860 #define IOC_PORTAL_NAL_CMD _IOWR('e', 38, long)
861 #define IOC_PORTAL_GET_NID _IOWR('e', 39, long)
862 #define IOC_PORTAL_FAIL_NID _IOWR('e', 40, long)
863 #define IOC_PORTAL_SET_DAEMON _IOWR('e', 41, long)
865 #define IOC_PORTAL_MAX_NR 41
878 extern ptl_handle_ni_t kqswnal_ni;
879 extern ptl_handle_ni_t ksocknal_ni;
880 extern ptl_handle_ni_t ktoenal_ni;
881 extern ptl_handle_ni_t kgmnal_ni;
882 extern ptl_handle_ni_t kscimacnal_ni;
885 #define NAL_MAX_NR (NAL_ENUM_END_MARKER - 1)
887 #define NAL_CMD_REGISTER_PEER_FD 100
888 #define NAL_CMD_CLOSE_CONNECTION 101
889 #define NAL_CMD_REGISTER_MYNID 102
890 #define NAL_CMD_PUSH_CONNECTION 103
893 DEBUG_DAEMON_START = 1,
894 DEBUG_DAEMON_STOP = 2,
895 DEBUG_DAEMON_PAUSE = 3,
896 DEBUG_DAEMON_CONTINUE = 4,
899 /* XXX remove to lustre ASAP */
902 ptl_handle_ni_t peer_ni;
906 typedef int (*nal_cmd_handler_t)(struct portal_ioctl_data *, void * private);
907 int kportal_nal_register(int nal, nal_cmd_handler_t handler, void * private);
908 int kportal_nal_unregister(int nal);
910 ptl_handle_ni_t *kportal_get_ni (int nal);
911 void kportal_put_ni (int nal);
914 #ifndef BITS_PER_LONG
915 #if (~0UL) == 0xffffffffUL
916 #define BITS_PER_LONG 32
918 #define BITS_PER_LONG 64
923 #if (BITS_PER_LONG == 32 || __WORDSIZE == 32)
926 # define LPX64 "%#Lx"
930 #if (BITS_PER_LONG == 64 || __WORDSIZE == 64)
933 # define LPX64 "%#lx"
938 # error "No word size defined"