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) \
266 LASSERT (!in_interrupt()); \
267 if (s > PORTAL_VMALLOC_SIZE) \
268 (ptr) = vmalloc(s); \
270 (ptr) = kmalloc(s, GFP_NOFS); \
272 CERROR("PORTALS: out of memory at %s:%d (tried to alloc" \
273 " '" #ptr "' = %ld)\n", __FILE__, __LINE__, s); \
275 portal_kmem_inc((ptr), s); \
276 memset((ptr), 0, s); \
278 CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %ld at %p (tot %d).\n", \
279 s, (ptr), atomic_read (&portal_kmemory)); \
282 #define PORTAL_FREE(ptr, size) \
285 if ((ptr) == NULL) { \
286 CERROR("PORTALS: free NULL '" #ptr "' (%ld bytes) at " \
287 "%s:%d\n", s, __FILE__, __LINE__); \
290 if (s > PORTAL_VMALLOC_SIZE) \
294 portal_kmem_dec((ptr), s); \
295 CDEBUG(D_MALLOC, "kfreed '" #ptr "': %ld at %p (tot %d).\n", \
296 s, (ptr), atomic_read (&portal_kmemory)); \
299 #define PORTAL_SLAB_ALLOC(ptr, slab, size) \
302 LASSERT (!in_interrupt()); \
303 (ptr) = kmem_cache_alloc((slab), SLAB_KERNEL); \
304 if ((ptr) == NULL) { \
305 CERROR("PORTALS: out of memory at %s:%d (tried to alloc" \
306 " '" #ptr "' from slab '" #slab "')\n", __FILE__, \
309 portal_kmem_inc((ptr), s); \
310 memset((ptr), 0, s); \
312 CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %ld at %p (tot %d).\n", \
313 s, (ptr), atomic_read (&portal_kmemory)); \
316 #define PORTAL_SLAB_FREE(ptr, slab, size) \
319 if ((ptr) == NULL) { \
320 CERROR("PORTALS: free NULL '" #ptr "' (%ld bytes) at " \
321 "%s:%d\n", s, __FILE__, __LINE__); \
324 memset((ptr), 0x5a, s); \
325 kmem_cache_free((slab), ptr); \
326 portal_kmem_dec((ptr), s); \
327 CDEBUG(D_MALLOC, "kfreed '" #ptr "': %ld at %p (tot %d).\n", \
328 s, (ptr), atomic_read (&portal_kmemory)); \
331 /* ------------------------------------------------------------------- */
333 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
335 #define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
336 #define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
338 #define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
339 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
341 #define PORTAL_MODULE_USE MOD_INC_USE_COUNT
342 #define PORTAL_MODULE_UNUSE MOD_DEC_USE_COUNT
345 #define PORTAL_SYMBOL_REGISTER(x)
346 #define PORTAL_SYMBOL_UNREGISTER(x)
348 #define PORTAL_SYMBOL_GET(x) symbol_get(x)
349 #define PORTAL_SYMBOL_PUT(x) symbol_put(x)
351 #define PORTAL_MODULE_USE try_module_get(THIS_MODULE)
352 #define PORTAL_MODULE_UNUSE module_put(THIS_MODULE)
356 /******************************************************************************/
357 /* Kernel Portals Router interface */
359 typedef void (*kpr_fwd_callback_t)(void *arg, int error); // completion callback
361 /* space for routing targets to stash "stuff" in a forwarded packet */
363 long long _alignment;
364 void *_space[16]; /* scale with CPU arch */
367 /* Kernel Portals Routing Forwarded message Descriptor */
369 struct list_head kprfd_list; /* stash in queues (routing target can use) */
370 ptl_nid_t kprfd_target_nid; /* final destination NID */
371 ptl_nid_t kprfd_gateway_nid; /* gateway NID */
372 int kprfd_nob; /* # message bytes (including header) */
373 int kprfd_niov; /* # message frags (including header) */
374 struct iovec *kprfd_iov; /* message fragments */
375 void *kprfd_router_arg; // originating NAL's router arg
376 kpr_fwd_callback_t kprfd_callback; /* completion callback */
377 void *kprfd_callback_arg; /* completion callback arg */
378 kprfd_scratch_t kprfd_scratch; // scratchpad for routing targets
381 typedef void (*kpr_fwd_t)(void *arg, kpr_fwd_desc_t *fwd);
383 /* NAL's routing interface (Kernel Portals Routing Nal Interface) */
384 typedef const struct {
385 int kprni_nalid; /* NAL's id */
386 void *kprni_arg; /* Arg to pass when calling into NAL */
387 kpr_fwd_t kprni_fwd; /* NAL's forwarding entrypoint */
388 } kpr_nal_interface_t;
390 /* Router's routing interface (Kernel Portals Routing Router Interface) */
391 typedef const struct {
392 /* register the calling NAL with the router and get back the handle for
393 * subsequent calls */
394 int (*kprri_register) (kpr_nal_interface_t *nal_interface,
397 /* ask the router to find a gateway that forwards to 'nid' and is a peer
398 * of the calling NAL */
399 int (*kprri_lookup) (void *router_arg, ptl_nid_t nid,
400 ptl_nid_t *gateway_nid);
402 /* hand a packet over to the router for forwarding */
403 kpr_fwd_t kprri_fwd_start;
405 /* hand a packet back to the router for completion */
406 void (*kprri_fwd_done) (void *router_arg, kpr_fwd_desc_t *fwd,
409 /* the calling NAL is shutting down */
410 void (*kprri_shutdown) (void *router_arg);
412 /* deregister the calling NAL with the router */
413 void (*kprri_deregister) (void *router_arg);
415 } kpr_router_interface_t;
417 /* Convenient struct for NAL to stash router interface/args */
419 kpr_router_interface_t *kpr_interface;
423 /* Router's control interface (Kernel Portals Routing Control Interface) */
424 typedef const struct {
425 int (*kprci_add_route)(int gateway_nal, ptl_nid_t gateway_nid,
426 ptl_nid_t lo_nid, ptl_nid_t hi_nid);
427 int (*kprci_del_route)(ptl_nid_t nid);
428 int (*kprci_get_route)(int index, int *gateway_nal,
429 ptl_nid_t *gateway, ptl_nid_t *lo_nid,
431 } kpr_control_interface_t;
433 extern kpr_control_interface_t kpr_control_interface;
434 extern kpr_router_interface_t kpr_router_interface;
437 kpr_register (kpr_router_t *router, kpr_nal_interface_t *nalif)
441 router->kpr_interface = PORTAL_SYMBOL_GET (kpr_router_interface);
442 if (router->kpr_interface == NULL)
445 rc = (router->kpr_interface)->kprri_register (nalif, &router->kpr_arg);
447 router->kpr_interface = NULL;
449 PORTAL_SYMBOL_PUT (kpr_router_interface);
454 kpr_routing (kpr_router_t *router)
456 return (router->kpr_interface != NULL);
460 kpr_lookup (kpr_router_t *router, ptl_nid_t nid, ptl_nid_t *gateway_nid)
462 if (!kpr_routing (router))
463 return (-EHOSTUNREACH);
465 return (router->kpr_interface->kprri_lookup(router->kpr_arg, nid,
470 kpr_fwd_init (kpr_fwd_desc_t *fwd, ptl_nid_t nid,
471 int nob, int niov, struct iovec *iov,
472 kpr_fwd_callback_t callback, void *callback_arg)
474 fwd->kprfd_target_nid = nid;
475 fwd->kprfd_gateway_nid = nid;
476 fwd->kprfd_nob = nob;
477 fwd->kprfd_niov = niov;
478 fwd->kprfd_iov = iov;
479 fwd->kprfd_callback = callback;
480 fwd->kprfd_callback_arg = callback_arg;
484 kpr_fwd_start (kpr_router_t *router, kpr_fwd_desc_t *fwd)
486 if (!kpr_routing (router))
487 fwd->kprfd_callback (fwd->kprfd_callback_arg, -EHOSTUNREACH);
489 router->kpr_interface->kprri_fwd_start (router->kpr_arg, fwd);
493 kpr_fwd_done (kpr_router_t *router, kpr_fwd_desc_t *fwd, int error)
495 LASSERT (kpr_routing (router));
496 router->kpr_interface->kprri_fwd_done (router->kpr_arg, fwd, error);
500 kpr_shutdown (kpr_router_t *router)
502 if (kpr_routing (router))
503 router->kpr_interface->kprri_shutdown (router->kpr_arg);
507 kpr_deregister (kpr_router_t *router)
509 if (!kpr_routing (router))
511 router->kpr_interface->kprri_deregister (router->kpr_arg);
512 router->kpr_interface = NULL;
515 /******************************************************************************/
517 #ifdef PORTALS_PROFILING
518 #define prof_enum(FOO) PROF__##FOO
520 prof_enum(our_recvmsg),
521 prof_enum(our_sendmsg),
522 prof_enum(socknal_recv),
523 prof_enum(lib_parse),
524 prof_enum(conn_list_walk),
526 prof_enum(lib_finalize),
527 prof_enum(pingcli_time),
528 prof_enum(gmnal_send),
529 prof_enum(gmnal_recv),
535 /* hrmph. wrap-tastic. */
538 cycles_t total_cycles;
543 extern struct prof_ent prof_ents[MAX_PROFS];
545 #define PROF_START(FOO) \
547 struct prof_ent *pe = &prof_ents[PROF__##FOO]; \
549 pe->start = get_cycles(); \
552 #define PROF_FINISH(FOO) \
554 struct prof_ent *pe = &prof_ents[PROF__##FOO]; \
556 pe->end = get_cycles(); \
557 pe->total_cycles += (pe->end - pe->start); \
559 #else /* !PORTALS_PROFILING */
560 #define PROF_START(FOO) do {} while(0)
561 #define PROF_FINISH(FOO) do {} while(0)
562 #endif /* PORTALS_PROFILING */
565 void portals_run_lbug_upcall(char * file, char *fn, int line);
566 void portals_debug_dumplog(void);
567 int portals_debug_init(unsigned long bufsize);
568 int portals_debug_cleanup(void);
569 int portals_debug_clear_buffer(void);
570 int portals_debug_mark_buffer(char *text);
571 int portals_debug_set_daemon(unsigned int cmd, unsigned int length,
572 char *file, unsigned int size);
573 __s32 portals_debug_copy_to_user(char *buf, unsigned long len);
575 /* Use the special GNU C __attribute__ hack to have the compiler check the
576 * printf style argument string against the actual argument count and
580 # warning printf has been defined as a macro...
583 void portals_debug_msg (int subsys, int mask, char *file, char *fn, int line,
584 unsigned long stack, const char *format, ...)
585 __attribute__ ((format (printf, 7, 8)));
587 void portals_debug_msg (int subsys, int mask, char *file, char *fn,
588 int line, unsigned long stack,
589 const char *format, ...);
590 #endif /* __GNUC__ */
591 void portals_debug_set_level(unsigned int debug_level);
593 # define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
594 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
595 # define time(a) CURRENT_TIME
597 extern void kportal_daemonize (char *name);
598 extern void kportal_blockallsigs (void);
600 #else /* !__KERNEL__ */
608 # include <asm/types.h>
609 # ifndef DEBUG_SUBSYSTEM
610 # define DEBUG_SUBSYSTEM S_UNDEFINED
615 # define LASSERT(e) assert(e)
619 # define printk(format, args...) printf (format, ## args)
620 # define PORTAL_ALLOC(ptr, size) do { (ptr) = malloc(size); } while (0);
621 # define PORTAL_FREE(a, b) do { free(a); } while (0);
622 # define portals_debug_msg(subsys, mask, file, fn, line, stack, format, a...) \
623 printf ("%02x:%06x (@%lu %s:%s,l. %d %d %lu): " format, \
624 (subsys) >> 24, (mask), (long)time(0), file, fn, line, \
625 getpid() , stack, ## a);
629 # define CURRENT_TIME time(0)
632 #include <linux/portals_lib.h>
635 * USER LEVEL STUFF BELOW
638 #define PORTAL_IOCTL_VERSION 0x00010007
642 struct portal_ioctl_data {
666 __u32 ioc_plen1; /* buffers in userspace */
668 __u32 ioc_plen2; /* buffers in userspace */
674 struct portal_ioctl_hdr {
679 struct portals_debug_ioctl_data
681 struct portal_ioctl_hdr hdr;
686 #define PORTAL_IOC_INIT(data) \
688 memset(&data, 0, sizeof(data)); \
689 data.ioc_version = PORTAL_IOCTL_VERSION; \
690 data.ioc_len = sizeof(data); \
693 /* FIXME check conflict with lustre_lib.h */
694 #define PTL_IOC_DEBUG_MASK _IOWR('f', 250, long)
696 static inline int portal_ioctl_packlen(struct portal_ioctl_data *data)
698 int len = sizeof(*data);
699 len += size_round(data->ioc_inllen1);
700 len += size_round(data->ioc_inllen2);
704 static inline int portal_ioctl_is_invalid(struct portal_ioctl_data *data)
706 if (data->ioc_len > (1<<30)) {
707 CERROR ("PORTALS ioctl: ioc_len larger than 1<<30\n");
710 if (data->ioc_inllen1 > (1<<30)) {
711 CERROR ("PORTALS ioctl: ioc_inllen1 larger than 1<<30\n");
714 if (data->ioc_inllen2 > (1<<30)) {
715 CERROR ("PORTALS ioctl: ioc_inllen2 larger than 1<<30\n");
718 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
719 CERROR ("PORTALS ioctl: inlbuf1 pointer but 0 length\n");
722 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
723 CERROR ("PORTALS ioctl: inlbuf2 pointer but 0 length\n");
726 if (data->ioc_pbuf1 && !data->ioc_plen1) {
727 CERROR ("PORTALS ioctl: pbuf1 pointer but 0 length\n");
730 if (data->ioc_pbuf2 && !data->ioc_plen2) {
731 CERROR ("PORTALS ioctl: pbuf2 pointer but 0 length\n");
734 if (data->ioc_plen1 && !data->ioc_pbuf1) {
735 CERROR ("PORTALS ioctl: plen1 nonzero but no pbuf1 pointer\n");
738 if (data->ioc_plen2 && !data->ioc_pbuf2) {
739 CERROR ("PORTALS ioctl: plen2 nonzero but no pbuf2 pointer\n");
742 if (portal_ioctl_packlen(data) != data->ioc_len ) {
743 CERROR ("PORTALS ioctl: packlen != ioc_len\n");
746 if (data->ioc_inllen1 &&
747 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
748 CERROR ("PORTALS ioctl: inlbuf1 not 0 terminated\n");
751 if (data->ioc_inllen2 &&
752 data->ioc_bulk[size_round(data->ioc_inllen1) +
753 data->ioc_inllen2 - 1] != '\0') {
754 CERROR ("PORTALS ioctl: inlbuf2 not 0 terminated\n");
761 static inline int portal_ioctl_pack(struct portal_ioctl_data *data, char **pbuf,
765 struct portal_ioctl_data *overlay;
766 data->ioc_len = portal_ioctl_packlen(data);
767 data->ioc_version = PORTAL_IOCTL_VERSION;
769 if (*pbuf && portal_ioctl_packlen(data) > max)
772 *pbuf = malloc(data->ioc_len);
776 overlay = (struct portal_ioctl_data *)*pbuf;
777 memcpy(*pbuf, data, sizeof(*data));
779 ptr = overlay->ioc_bulk;
780 if (data->ioc_inlbuf1)
781 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
782 if (data->ioc_inlbuf2)
783 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
784 if (portal_ioctl_is_invalid(overlay))
790 #include <asm/uaccess.h>
792 /* buffer MUST be at least the size of portal_ioctl_hdr */
793 static inline int portal_ioctl_getdata(char *buf, char *end, void *arg)
795 struct portal_ioctl_hdr *hdr;
796 struct portal_ioctl_data *data;
800 hdr = (struct portal_ioctl_hdr *)buf;
801 data = (struct portal_ioctl_data *)buf;
803 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
809 if (hdr->ioc_version != PORTAL_IOCTL_VERSION) {
810 CERROR ("PORTALS: version mismatch kernel vs application\n");
814 if (hdr->ioc_len + buf >= end) {
815 CERROR ("PORTALS: user buffer exceeds kernel buffer\n");
820 if (hdr->ioc_len < sizeof(struct portal_ioctl_data)) {
821 CERROR ("PORTALS: user buffer too small for ioctl\n");
825 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
831 if (portal_ioctl_is_invalid(data)) {
832 CERROR ("PORTALS: ioctl not correctly formatted\n");
836 if (data->ioc_inllen1) {
837 data->ioc_inlbuf1 = &data->ioc_bulk[0];
840 if (data->ioc_inllen2) {
841 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
842 size_round(data->ioc_inllen1);
850 /* ioctls for manipulating snapshots 30- */
851 #define IOC_PORTAL_TYPE 'e'
852 #define IOC_PORTAL_MIN_NR 30
854 #define IOC_PORTAL_PING _IOWR('e', 30, long)
855 #define IOC_PORTAL_GET_DEBUG _IOWR('e', 31, long)
856 #define IOC_PORTAL_CLEAR_DEBUG _IOWR('e', 32, long)
857 #define IOC_PORTAL_MARK_DEBUG _IOWR('e', 33, long)
858 #define IOC_PORTAL_PANIC _IOWR('e', 34, long)
859 #define IOC_PORTAL_ADD_ROUTE _IOWR('e', 35, long)
860 #define IOC_PORTAL_DEL_ROUTE _IOWR('e', 36, long)
861 #define IOC_PORTAL_GET_ROUTE _IOWR('e', 37, long)
862 #define IOC_PORTAL_NAL_CMD _IOWR('e', 38, long)
863 #define IOC_PORTAL_GET_NID _IOWR('e', 39, long)
864 #define IOC_PORTAL_FAIL_NID _IOWR('e', 40, long)
865 #define IOC_PORTAL_SET_DAEMON _IOWR('e', 41, long)
867 #define IOC_PORTAL_MAX_NR 41
880 extern ptl_handle_ni_t kqswnal_ni;
881 extern ptl_handle_ni_t ksocknal_ni;
882 extern ptl_handle_ni_t ktoenal_ni;
883 extern ptl_handle_ni_t kgmnal_ni;
884 extern ptl_handle_ni_t kscimacnal_ni;
887 #define NAL_MAX_NR (NAL_ENUM_END_MARKER - 1)
889 #define NAL_CMD_REGISTER_PEER_FD 100
890 #define NAL_CMD_CLOSE_CONNECTION 101
891 #define NAL_CMD_REGISTER_MYNID 102
892 #define NAL_CMD_PUSH_CONNECTION 103
895 DEBUG_DAEMON_START = 1,
896 DEBUG_DAEMON_STOP = 2,
897 DEBUG_DAEMON_PAUSE = 3,
898 DEBUG_DAEMON_CONTINUE = 4,
901 /* XXX remove to lustre ASAP */
904 ptl_handle_ni_t peer_ni;
908 typedef int (*nal_cmd_handler_t)(struct portal_ioctl_data *, void * private);
909 int kportal_nal_register(int nal, nal_cmd_handler_t handler, void * private);
910 int kportal_nal_unregister(int nal);
912 ptl_handle_ni_t *kportal_get_ni (int nal);
913 void kportal_put_ni (int nal);
916 #ifndef BITS_PER_LONG
917 #if (~0UL) == 0xffffffffUL
918 #define BITS_PER_LONG 32
920 #define BITS_PER_LONG 64
925 #if (BITS_PER_LONG == 32 || __WORDSIZE == 32)
928 # define LPX64 "%#Lx"
932 #if (BITS_PER_LONG == 64 || __WORDSIZE == 64)
935 # define LPX64 "%#lx"
940 # error "No word size defined"