Whamcloud - gitweb
Bug# 329: Approver: Andreas - obd_ioctl_unpack() causes segmentation violation.
[fs/lustre-release.git] / lustre / include / linux / lustre_lib.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Basic Lustre library routines. 
22  *
23  */
24
25 #ifndef _LUSTRE_LIB_H
26 #define _LUSTRE_LIB_H
27
28 #ifndef __KERNEL__
29 # include <string.h>
30 #else
31 # include <asm/semaphore.h>
32 #include <linux/kp30.h> /* XXX just for LASSERT! */
33 #endif
34 #include <linux/portals_lib.h>
35 #include <linux/lustre_idl.h>
36
37 #if BITS_PER_LONG > 32
38 #define LPU64 "%lu"
39 #define LPD64 "%ld"
40 #define LPX64 "%#lx"
41 #else
42 #define LPU64 "%Lu"
43 #define LPD64 "%Ld"
44 #define LPX64 "%#Lx"
45 #endif
46
47 #ifdef __KERNEL__
48 /* l_net.c */
49 struct ptlrpc_request;
50 struct obd_device;
51 struct recovd_data;
52 struct recovd_obd;
53 #include <linux/lustre_ha.h>
54
55 int target_handle_connect(struct ptlrpc_request *req);
56 int target_handle_disconnect(struct ptlrpc_request *req);
57 int client_obd_connect(struct lustre_handle *conn, struct obd_device *obd,
58                        obd_uuid_t cluuid, struct recovd_obd *recovd,
59                        ptlrpc_recovery_cb_t recover);
60 int client_obd_disconnect(struct lustre_handle *conn);
61 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf);
62 int client_obd_cleanup(struct obd_device * obddev);
63 struct client_obd *client_conn2cli(struct lustre_handle *conn); 
64
65 int target_revoke_connection(struct recovd_data *rd, int phase);
66
67 /* l_lock.c */
68 struct lustre_lock { 
69         int l_depth;
70         struct task_struct *l_owner;
71         struct semaphore l_sem;
72         spinlock_t l_spin;
73 };
74
75 void l_lock_init(struct lustre_lock *);
76 void l_lock(struct lustre_lock *);
77 void l_unlock(struct lustre_lock *);
78
79
80 /* page.c */
81 #define CB_PHASE_START   12
82 #define CB_PHASE_FINISH  13
83
84 /*
85  * io_cb_data: io callback data merged into one struct to simplify
86  *   memory managment. This may be turn out to be too simple.
87  */
88 struct io_cb_data;
89 typedef int (*brw_callback_t)(struct io_cb_data *, int err, int phase);
90
91 struct io_cb_data {
92         wait_queue_head_t waitq;
93         atomic_t refcount;
94         int complete;
95         int err;
96         struct ptlrpc_bulk_desc *desc;
97         brw_callback_t cb;
98         void *data;
99 };
100
101 int ll_sync_io_cb(struct io_cb_data *data, int err, int phase);
102 struct  io_cb_data *ll_init_cb(void);
103
104 /* simple.c */
105 struct obd_run_ctxt;
106 struct obd_ucred;
107 void push_ctxt(struct obd_run_ctxt *save, struct obd_run_ctxt *new, 
108                struct obd_ucred *cred);
109 void pop_ctxt(struct obd_run_ctxt *saved);
110 struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode);
111 struct dentry *simple_mknod(struct dentry *dir, char *name, int mode);
112 int lustre_fread(struct file *file, char *str, int len, loff_t *off);
113 int lustre_fwrite(struct file *file, const char *str, int len, loff_t *off);
114 int lustre_fsync(struct file *file);
115
116 static inline void l_dput(struct dentry *de)
117 {
118         if (!de || IS_ERR(de))
119                 return;
120         shrink_dcache_parent(de);
121         LASSERT(atomic_read(&de->d_count) > 0);
122         dput(de);
123 }
124
125 static inline void ll_sleep(int t)
126 {
127         set_current_state(TASK_INTERRUPTIBLE);
128         schedule_timeout(t * HZ);
129         set_current_state(TASK_RUNNING);
130 }
131 #endif
132
133 /* FIXME: This needs to validate pointers and cookies */
134 static inline void *lustre_handle2object(struct lustre_handle *handle)
135 {
136         if (handle) 
137                 return (void *)(unsigned long)(handle->addr);
138         return NULL; 
139 }
140
141 static inline void ldlm_object2handle(void *object, struct lustre_handle *handle)
142 {
143         handle->addr = (__u64)(unsigned long)object;
144 }
145
146 struct obd_statfs;
147 struct statfs;
148 void statfs_pack(struct obd_statfs *osfs, struct statfs *sfs);
149 void statfs_unpack(struct statfs *sfs, struct obd_statfs *osfs);
150 void obd_statfs_pack(struct obd_statfs *tgt, struct obd_statfs *src);
151 static inline void
152 obd_statfs_unpack(struct obd_statfs *tgt, struct obd_statfs *src)
153 {
154         obd_statfs_pack(tgt, src);
155 }
156
157 #include <linux/portals_lib.h>
158
159 /*
160  *   OBD IOCTLS
161  */
162 #define OBD_IOCTL_VERSION 0x00010001
163
164 struct obd_ioctl_data {
165         uint32_t ioc_len;
166         uint32_t ioc_version;
167
168         uint64_t ioc_addr;
169         uint64_t ioc_cookie;
170         uint32_t ioc_conn1;
171         uint32_t ioc_conn2;
172
173         struct obdo ioc_obdo1;
174         struct obdo ioc_obdo2;
175
176         obd_size         ioc_count;
177         obd_off          ioc_offset;
178         uint32_t         ioc_dev;
179         uint32_t         ____padding;
180
181         /* buffers the kernel will treat as user pointers */
182         uint32_t ioc_plen1;
183         char    *ioc_pbuf1;
184         uint32_t ioc_plen2;
185         char    *ioc_pbuf2;
186
187         /* two inline buffers */
188         uint32_t ioc_inllen1;
189         char    *ioc_inlbuf1;
190         uint32_t ioc_inllen2;
191         char    *ioc_inlbuf2;
192         uint32_t ioc_inllen3;
193         char    *ioc_inlbuf3;
194
195         char    ioc_bulk[0];
196 };
197
198 struct obd_ioctl_hdr {
199         uint32_t ioc_len;
200         uint32_t ioc_version;
201 };
202
203 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
204 {
205         int len = size_round(sizeof(struct obd_ioctl_data));
206         len += size_round(data->ioc_inllen1);
207         len += size_round(data->ioc_inllen2);
208         len += size_round(data->ioc_inllen3);
209         return len;
210 }
211
212
213 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
214 {
215         if (data->ioc_len > (1<<30)) {
216                 printk("OBD ioctl: ioc_len larger than 1<<30\n");
217                 return 1;
218         }
219         if (data->ioc_inllen1 > (1<<30)) {
220                 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
221                 return 1;
222         }
223         if (data->ioc_inllen2 > (1<<30)) {
224                 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
225                 return 1;
226         }
227
228         if (data->ioc_inllen3 > (1<<30)) {
229                 printk("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
230                 return 1;
231         }
232         if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
233                 printk("OBD ioctl: inlbuf1 pointer but 0 length\n");
234                 return 1;
235         }
236         if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
237                 printk("OBD ioctl: inlbuf2 pointer but 0 length\n");
238                 return 1;
239         }
240         if (data->ioc_inlbuf3 && !data->ioc_inllen3) {
241                 printk("OBD ioctl: inlbuf3 pointer but 0 length\n");
242                 return 1;
243         }
244         if (data->ioc_pbuf1 && !data->ioc_plen1) {
245                 printk("OBD ioctl: pbuf1 pointer but 0 length\n");
246                 return 1;
247         }
248         if (data->ioc_pbuf2 && !data->ioc_plen2) {
249                 printk("OBD ioctl: pbuf2 pointer but 0 length\n");
250                 return 1;
251         }
252         /*
253         if (data->ioc_inllen1 && !data->ioc_inlbuf1) {
254                 printk("OBD ioctl: inllen1 set but NULL pointer\n");
255                 return 1;
256         }
257         if (data->ioc_inllen2 && !data->ioc_inlbuf2) {
258                 printk("OBD ioctl: inllen2 set but NULL pointer\n");
259                 return 1;
260         }
261         if (data->ioc_inllen3 && !data->ioc_inlbuf3) {
262                 printk("OBD ioctl: inllen3 set but NULL pointer\n");
263                 return 1;
264         }
265         */
266         if (data->ioc_plen1 && !data->ioc_pbuf1) {
267                 printk("OBD ioctl: plen1 set but NULL pointer\n");
268                 return 1;
269         }
270         if (data->ioc_plen2 && !data->ioc_pbuf2) {
271                 printk("OBD ioctl: plen2 set but NULL pointer\n");
272                 return 1;
273         }
274         if (obd_ioctl_packlen(data) != data->ioc_len ) {
275                 printk("OBD ioctl: packlen exceeds ioc_len\n");
276                 return 1;
277         }
278 #if 0
279         if (data->ioc_inllen1 &&
280             data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
281                 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
282                 return 1;
283         }
284         if (data->ioc_inllen2 &&
285             data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
286                 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
287                 return 1;
288         }
289         if (data->ioc_inllen3 &&
290             data->ioc_bulk[size_round(data->ioc_inllen1) + size_round(data->ioc_inllen2)
291                            + data->ioc_inllen3 - 1] != '\0') {
292                 printk("OBD ioctl: inlbuf3 not 0 terminated\n");
293                 return 1;
294         }
295 #endif 
296         return 0;
297 }
298
299 #ifndef __KERNEL__
300 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
301                                  int max)
302 {
303         char *ptr;
304         struct obd_ioctl_data *overlay;
305         data->ioc_len = obd_ioctl_packlen(data);
306         data->ioc_version = OBD_IOCTL_VERSION;
307
308         if (*pbuf && data->ioc_len > max)
309                 return 1;
310         if (*pbuf == NULL) {
311                 *pbuf = malloc(data->ioc_len);
312         }
313         if (!*pbuf)
314                 return 1;
315         overlay = (struct obd_ioctl_data *)*pbuf;
316         memcpy(*pbuf, data, sizeof(*data));
317
318         ptr = overlay->ioc_bulk;
319         if (data->ioc_inlbuf1)
320                 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
321         if (data->ioc_inlbuf2)
322                 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
323         if (data->ioc_inlbuf3)
324                 LOGL(data->ioc_inlbuf3, data->ioc_inllen3, ptr);
325         if (obd_ioctl_is_invalid(overlay))
326                 return 1;
327
328         return 0;
329 }
330
331 static inline int obd_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf,
332                                    int max)
333 {
334         char *ptr;
335         struct obd_ioctl_data *overlay;
336
337         if (!pbuf)
338                 return 1;
339         overlay = (struct obd_ioctl_data *)pbuf;
340
341         /* Preserve the caller's buffer pointers */
342         overlay->ioc_inlbuf1 = data->ioc_inlbuf1;
343         overlay->ioc_inlbuf2 = data->ioc_inlbuf2;
344         overlay->ioc_inlbuf3 = data->ioc_inlbuf3;
345
346         memcpy(data, pbuf, sizeof(*data));
347
348         ptr = overlay->ioc_bulk;
349         if (data->ioc_inlbuf1)
350                 LOGU(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
351         if (data->ioc_inlbuf2)
352                 LOGU(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
353         if (data->ioc_inlbuf3)
354                 LOGU(data->ioc_inlbuf3, data->ioc_inllen3, ptr);
355
356         return 0;
357 }
358 #else
359
360 #include <linux/obd_support.h>
361
362 /* buffer MUST be at least the size of obd_ioctl_hdr */
363 static inline int obd_ioctl_getdata(char **buf, int *len, void *arg)
364 {
365         struct obd_ioctl_hdr hdr;
366         struct obd_ioctl_data *data;
367         int err;
368         ENTRY;
369
370         err = copy_from_user(&hdr, (void *)arg, sizeof(hdr));
371         if ( err ) {
372                 EXIT;
373                 return err;
374         }
375
376         if (hdr.ioc_version != OBD_IOCTL_VERSION) {
377                 printk("OBD: version mismatch kernel vs application\n");
378                 return -EINVAL;
379         }
380
381         if (hdr.ioc_len > 8192) {
382                 printk("OBD: user buffer exceeds 8192 max buffer\n");
383                 return -EINVAL;
384         }
385
386         if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
387                 printk("OBD: user buffer too small for ioctl\n");
388                 return -EINVAL;
389         }
390
391         OBD_ALLOC(*buf, hdr.ioc_len);
392         if (!*buf) {
393                 CERROR("Cannot allocate control buffer of len %d\n",
394                        hdr.ioc_len);
395                 RETURN(-EINVAL);
396         }
397         *len = hdr.ioc_len;
398         data = (struct obd_ioctl_data *)*buf;
399
400         err = copy_from_user(*buf, (void *)arg, hdr.ioc_len);
401         if ( err ) {
402                 EXIT;
403                 return err;
404         }
405
406         if (obd_ioctl_is_invalid(data)) {
407                 printk("OBD: ioctl not correctly formatted\n");
408                 return -EINVAL;
409         }
410
411         if (data->ioc_inllen1) {
412                 data->ioc_inlbuf1 = &data->ioc_bulk[0];
413         }
414
415         if (data->ioc_inllen2) {
416                 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
417         }
418
419         if (data->ioc_inllen3) {
420                 data->ioc_inlbuf3 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1) + 
421                         size_round(data->ioc_inllen2);
422         }
423
424         EXIT;
425         return 0;
426 }
427 #endif
428
429 #define OBD_IOC_CREATE                 _IOR ('f', 101, long)
430 #define OBD_IOC_SETUP                  _IOW ('f', 102, long)
431 #define OBD_IOC_CLEANUP                _IO  ('f', 103      )
432 #define OBD_IOC_DESTROY                _IOW ('f', 104, long)
433 #define OBD_IOC_PREALLOCATE            _IOWR('f', 105, long)
434 #define OBD_IOC_DEC_USE_COUNT          _IO  ('f', 106      )
435 #define OBD_IOC_SETATTR                _IOW ('f', 107, long)
436 #define OBD_IOC_GETATTR                _IOR ('f', 108, long)
437 #define OBD_IOC_READ                   _IOWR('f', 109, long)
438 #define OBD_IOC_WRITE                  _IOWR('f', 110, long)
439 #define OBD_IOC_CONNECT                _IOR ('f', 111, long)
440 #define OBD_IOC_DISCONNECT             _IOW ('f', 112, long)
441 #define OBD_IOC_STATFS                 _IOWR('f', 113, long)
442 #define OBD_IOC_SYNC                   _IOR ('f', 114, long)
443 #define OBD_IOC_READ2                  _IOWR('f', 115, long)
444 #define OBD_IOC_FORMAT                 _IOWR('f', 116, long)
445 #define OBD_IOC_PARTITION              _IOWR('f', 117, long)
446 #define OBD_IOC_ATTACH                 _IOWR('f', 118, long)
447 #define OBD_IOC_DETACH                 _IOWR('f', 119, long)
448 #define OBD_IOC_COPY                   _IOWR('f', 120, long)
449 #define OBD_IOC_MIGR                   _IOWR('f', 121, long)
450 #define OBD_IOC_PUNCH                  _IOWR('f', 122, long)
451 #define OBD_IOC_DEVICE                 _IOWR('f', 123, long)
452 #define OBD_IOC_MODULE_DEBUG           _IOWR('f', 124, long)
453 #define OBD_IOC_BRW_READ               _IOWR('f', 125, long)
454 #define OBD_IOC_BRW_WRITE              _IOWR('f', 126, long)
455 #define OBD_IOC_NAME2DEV               _IOWR('f', 127, long)
456 #define OBD_IOC_NEWDEV                 _IOWR('f', 128, long)
457 #define OBD_IOC_LIST                   _IOWR('f', 129, long)
458 #define OBD_IOC_UUID2DEV               _IOWR('f', 130, long)
459
460 #define OBD_IOC_RECOVD_NEWCONN         _IOWR('f', 131, long)
461 #define OBD_IOC_LOV_SET_CONFIG         _IOWR('f', 132, long)
462 #define OBD_IOC_LOV_GET_CONFIG         _IOWR('f', 133, long)
463 #define OBD_IOC_LOV_CONFIG             OBD_IOC_LOV_SET_CONFIG
464
465 #define OBD_IOC_OPEN                   _IOWR('f', 134, long)
466 #define OBD_IOC_CLOSE                  _IOWR('f', 135, long)
467
468 #define OBD_IOC_RECOVD_FAILCONN        _IOWR('f', 136, long)
469
470 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 139      )
471
472 /*
473  * l_wait_event is a flexible sleeping function, permitting simple caller
474  * configuration of interrupt and timeout sensitivity along with actions to
475  * be performed in the event of either exception.
476  *
477  * Common usage looks like this:
478  * 
479  * struct l_wait_info lwi = LWI_TIMEOUT_INTR(timeout, timeout_handler,
480  *                                           intr_handler, callback_data);
481  * rc = l_wait_event(waitq, condition, &lwi);
482  *
483  * (LWI_TIMEOUT and LWI_INTR macros are available for timeout- and
484  * interrupt-only variants, respectively.)
485  *
486  * If a timeout is specified, the timeout_handler will be invoked in the event
487  * that the timeout expires before the process is awakened.  (Note that any
488  * waking of the process will restart the timeout, even if the condition is
489  * not satisfied and the process immediately returns to sleep.  This might be
490  * considered a bug.)  If the timeout_handler returns non-zero, l_wait_event
491  * will return -ETIMEDOUT and the caller will continue.  If the handler returns
492  * zero instead, the process will go back to sleep until it is awakened by the
493  * waitq or some similar mechanism, or an interrupt occurs (if the caller has
494  * asked for interrupts to be detected).  The timeout will only fire once, so
495  * callers should take care that a timeout_handler which returns zero will take
496  * future steps to awaken the process.  N.B. that these steps must include
497  * making the provided condition become true.
498  *
499  * If the interrupt flag (lwi_signals) is non-zero, then the process will be
500  * interruptible, and will be awakened by any "killable" signal (SIGTERM,
501  * SIGKILL or SIGINT).  If a timeout is also specified, then the process will
502  * only become interruptible _after_ the timeout has expired, though it can be
503  * awakened by a signal that was delivered before the timeout and is still
504  * pending when the timeout expires.  If a timeout is not specified, the process
505  * will be interruptible at all times during l_wait_event.
506  */
507
508 struct l_wait_info {
509         long   lwi_timeout;
510         int  (*lwi_on_timeout)(void *);
511         long   lwi_signals;
512         int  (*lwi_on_signal)(void *); /* XXX return is ignored for now */
513         void  *lwi_cb_data;
514 };
515
516 #define LWI_TIMEOUT(time, cb, data)                                            \
517 ((struct l_wait_info) {                                                        \
518         lwi_timeout:    time,                                                  \
519         lwi_on_timeout: cb,                                                    \
520         lwi_cb_data:    data                                                   \
521 })
522
523 #define LWI_INTR(cb, data)                                                     \
524 ((struct l_wait_info) {                                                        \
525         lwi_signals:   1,                                                      \
526         lwi_on_signal: cb,                                                     \
527         lwi_cb_data:   data                                                    \
528 })
529
530 #define LWI_TIMEOUT_INTR(time, time_cb, sig_cb, data)                          \
531 ((struct l_wait_info) {                                                        \
532         lwi_timeout:    time,                                                  \
533         lwi_on_timeout: time_cb,                                               \
534         lwi_signals:    1,                                                     \
535         lwi_on_signal:  sig_cb,                                                \
536         lwi_cb_data:    data                                                   \
537 })
538
539 /* XXX this should be one mask-check */
540 #define l_killable_pending(task)                                               \
541 (sigismember(&(task->pending.signal), SIGKILL) ||                              \
542  sigismember(&(task->pending.signal), SIGINT) ||                               \
543  sigismember(&(task->pending.signal), SIGTERM))
544
545 #define __l_wait_event(wq, condition, info, ret)                               \
546 do {                                                                           \
547         wait_queue_t __wait;                                                   \
548         long __state;                                                          \
549         int __timed_out = 0;                                                   \
550         init_waitqueue_entry(&__wait, current);                                \
551                                                                                \
552         add_wait_queue(&wq, &__wait);                                          \
553         if (info->lwi_signals && !info->lwi_timeout)                           \
554             __state = TASK_INTERRUPTIBLE;                                      \
555         else                                                                   \
556             __state = TASK_UNINTERRUPTIBLE;                                    \
557         for (;;) {                                                             \
558             set_current_state(__state);                                        \
559             if (condition)                                                     \
560                     break;                                                     \
561             if (__state == TASK_INTERRUPTIBLE && l_killable_pending(current)) {\
562                 CERROR("lwe: interrupt\n");                                    \
563                 if (info->lwi_on_signal)                                       \
564                         info->lwi_on_signal(info->lwi_cb_data);                \
565                 ret = -EINTR;                                                  \
566                 break;                                                         \
567             }                                                                  \
568             if (info->lwi_timeout && !__timed_out) {                           \
569                 if (schedule_timeout(info->lwi_timeout) == 0) {                \
570                     CERROR("lwe: timeout\n");                                  \
571                     __timed_out = 1;                                           \
572                     if (!info->lwi_on_timeout ||                               \
573                         info->lwi_on_timeout(info->lwi_cb_data)) {             \
574                         ret = -ETIMEDOUT;                                      \
575                         break;                                                 \
576                     }                                                          \
577                     /* We'll take signals after a timeout. */                  \
578                     if (info->lwi_signals) {                                   \
579                         __state = TASK_INTERRUPTIBLE;                          \
580                         /* Check for a pending interrupt. */                   \
581                         if (info->lwi_signals && l_killable_pending(current)) {\
582                             CERROR("lwe: pending interrupt\n");                \
583                             if (info->lwi_on_signal)                           \
584                                 info->lwi_on_signal(info->lwi_cb_data);        \
585                             ret = -EINTR;                                      \
586                             break;                                             \
587                         }                                                      \
588                     }                                                          \
589                 }                                                              \
590             } else {                                                           \
591                 schedule();                                                    \
592             }                                                                  \
593         }                                                                      \
594         current->state = TASK_RUNNING;                                         \
595         remove_wait_queue(&wq, &__wait);                                       \
596 } while(0)
597
598 #define l_wait_event(wq, condition, info)                                      \
599 ({                                                                             \
600         int __ret = 0;                                                         \
601         struct l_wait_info *__info = (info);                                   \
602         if (!(condition))                                                      \
603                 __l_wait_event(wq, condition, __info, __ret);                  \
604         __ret;                                                                 \
605 })
606
607 #endif /* _LUSTRE_LIB_H */