1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/include/lustre_lib.h
38 * Basic Lustre library routines.
44 #include <libcfs/kp30.h>
45 #include <lustre/lustre_idl.h>
46 #include <lustre_ver.h>
47 #include <lustre_cfg.h>
48 #if defined(__linux__)
49 #include <linux/lustre_lib.h>
50 #elif defined(__APPLE__)
51 #include <darwin/lustre_lib.h>
52 #elif defined(__WINNT__)
53 #include <winnt/lustre_lib.h>
55 #error Unsupported operating system.
59 unsigned int ll_rand(void); /* returns a random 32-bit integer */
60 void ll_srand(unsigned int, unsigned int); /* seed the generator */
61 void ll_get_random_bytes(void *buf, int size);
64 struct ptlrpc_request;
68 #include <lustre_ha.h>
69 #include <lustre_net.h>
72 void target_client_add_cb(struct obd_device *obd, __u64 transno, void *cb_data,
74 void target_trans_table_init(struct obd_device *obd);
75 __u32 target_trans_table_last_time(struct obd_export *exp);
76 void target_trans_table_recalc(struct obd_device *obd, __u32 new_age);
77 void target_trans_table_update(struct obd_export *exp, __u64 transno);
79 int target_fs_version_capable(struct obd_device *obd);
81 static inline int target_fs_version_capable(struct obd_device *obd)
86 int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler);
87 int target_handle_disconnect(struct ptlrpc_request *req);
88 void target_destroy_export(struct obd_export *exp);
89 int target_handle_reconnect(struct lustre_handle *conn, struct obd_export *exp,
90 struct obd_uuid *cluuid);
91 int target_handle_ping(struct ptlrpc_request *req);
92 int target_pack_pool_reply(struct ptlrpc_request *req);
93 void target_committed_to_req(struct ptlrpc_request *req);
95 /* quotacheck callback, dqacq/dqrel callback handler */
96 int target_handle_qc_callback(struct ptlrpc_request *req);
97 #ifdef HAVE_QUOTA_SUPPORT
98 int target_handle_dqacq_callback(struct ptlrpc_request *req);
100 #define target_handle_dqacq_callback(req) ldlm_callback_reply(req, -ENOTSUPP)
103 void target_cancel_recovery_timer(struct obd_device *obd);
104 void target_abort_recovery(void *data);
105 int target_recovery_check_and_stop(struct obd_device *obd);
106 void target_cleanup_recovery(struct obd_device *obd);
107 int target_queue_recovery_request(struct ptlrpc_request *req,
108 struct obd_device *obd);
109 int target_handle_reply(struct ptlrpc_request *req, int rc, int fail);
110 void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id);
114 int client_sanobd_setup(struct obd_device *obddev, obd_count len, void *buf);
115 struct client_obd *client_conn2cli(struct lustre_handle *conn);
117 struct mdc_open_data;
118 struct obd_client_handle {
119 struct lustre_handle och_fh;
120 struct llog_cookie och_cookie;
121 struct mdc_open_data *och_mod;
124 #define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed
127 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
128 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
134 struct semaphore l_sem;
138 void l_lock_init(struct lustre_lock *);
139 void l_lock(struct lustre_lock *);
140 void l_unlock(struct lustre_lock *);
141 int l_has_lock(struct lustre_lock *);
147 #define OBD_IOCTL_VERSION 0x00010004
149 struct obd_ioctl_data {
157 struct obdo ioc_obdo1;
158 struct obdo ioc_obdo2;
169 /* buffers the kernel will treat as user pointers */
175 /* inline buffers for various arguments */
188 struct obd_ioctl_hdr {
193 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
195 int len = size_round(sizeof(struct obd_ioctl_data));
196 len += size_round(data->ioc_inllen1);
197 len += size_round(data->ioc_inllen2);
198 len += size_round(data->ioc_inllen3);
199 len += size_round(data->ioc_inllen4);
204 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
206 if (data->ioc_len > (1<<30)) {
207 CERROR("OBD ioctl: ioc_len larger than 1<<30\n");
210 if (data->ioc_inllen1 > (1<<30)) {
211 CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
214 if (data->ioc_inllen2 > (1<<30)) {
215 CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
218 if (data->ioc_inllen3 > (1<<30)) {
219 CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
222 if (data->ioc_inllen4 > (1<<30)) {
223 CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n");
226 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
227 CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n");
230 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
231 CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n");
234 if (data->ioc_inlbuf3 && !data->ioc_inllen3) {
235 CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n");
238 if (data->ioc_inlbuf4 && !data->ioc_inllen4) {
239 CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n");
242 if (data->ioc_pbuf1 && !data->ioc_plen1) {
243 CERROR("OBD ioctl: pbuf1 pointer but 0 length\n");
246 if (data->ioc_pbuf2 && !data->ioc_plen2) {
247 CERROR("OBD ioctl: pbuf2 pointer but 0 length\n");
250 if (data->ioc_plen1 && !data->ioc_pbuf1) {
251 CERROR("OBD ioctl: plen1 set but NULL pointer\n");
254 if (data->ioc_plen2 && !data->ioc_pbuf2) {
255 CERROR("OBD ioctl: plen2 set but NULL pointer\n");
258 if (obd_ioctl_packlen(data) > data->ioc_len) {
259 CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n",
260 obd_ioctl_packlen(data), data->ioc_len);
267 static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
271 struct obd_ioctl_data *overlay;
272 data->ioc_len = obd_ioctl_packlen(data);
273 data->ioc_version = OBD_IOCTL_VERSION;
275 if (*pbuf && data->ioc_len > max)
278 *pbuf = malloc(data->ioc_len);
282 overlay = (struct obd_ioctl_data *)*pbuf;
283 memcpy(*pbuf, data, sizeof(*data));
285 ptr = overlay->ioc_bulk;
286 if (data->ioc_inlbuf1)
287 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
288 if (data->ioc_inlbuf2)
289 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
290 if (data->ioc_inlbuf3)
291 LOGL(data->ioc_inlbuf3, data->ioc_inllen3, ptr);
292 if (data->ioc_inlbuf4)
293 LOGL(data->ioc_inlbuf4, data->ioc_inllen4, ptr);
294 if (obd_ioctl_is_invalid(overlay))
300 static inline int obd_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf,
304 struct obd_ioctl_data *overlay;
308 overlay = (struct obd_ioctl_data *)pbuf;
310 /* Preserve the caller's buffer pointers */
311 overlay->ioc_inlbuf1 = data->ioc_inlbuf1;
312 overlay->ioc_inlbuf2 = data->ioc_inlbuf2;
313 overlay->ioc_inlbuf3 = data->ioc_inlbuf3;
314 overlay->ioc_inlbuf4 = data->ioc_inlbuf4;
316 memcpy(data, pbuf, sizeof(*data));
318 ptr = overlay->ioc_bulk;
319 if (data->ioc_inlbuf1)
320 LOGU(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
321 if (data->ioc_inlbuf2)
322 LOGU(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
323 if (data->ioc_inlbuf3)
324 LOGU(data->ioc_inlbuf3, data->ioc_inllen3, ptr);
325 if (data->ioc_inlbuf4)
326 LOGU(data->ioc_inlbuf4, data->ioc_inllen4, ptr);
332 #include <obd_support.h>
335 /* function defined in lustre/obdclass/<platform>/<platform>-module.c */
336 int obd_ioctl_getdata(char **buf, int *len, void *arg);
337 int obd_ioctl_popdata(void *arg, void *data, int len);
339 /* buffer MUST be at least the size of obd_ioctl_hdr */
340 static inline int obd_ioctl_getdata(char **buf, int *len, void *arg)
342 struct obd_ioctl_hdr hdr;
343 struct obd_ioctl_data *data;
348 err = copy_from_user(&hdr, (void *)arg, sizeof(hdr));
352 if (hdr.ioc_version != OBD_IOCTL_VERSION) {
353 CERROR("Version mismatch kernel vs application\n");
357 if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) {
358 CERROR("User buffer len %d exceeds %d max buffer\n",
359 hdr.ioc_len, OBD_MAX_IOCTL_BUFFER);
363 if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
364 CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len);
368 /* XXX allocate this more intelligently, using kmalloc when
370 OBD_VMALLOC(*buf, hdr.ioc_len);
372 CERROR("Cannot allocate control buffer of len %d\n",
377 data = (struct obd_ioctl_data *)*buf;
379 err = copy_from_user(*buf, (void *)arg, hdr.ioc_len);
381 OBD_VFREE(*buf, hdr.ioc_len);
385 if (obd_ioctl_is_invalid(data)) {
386 CERROR("ioctl not correctly formatted\n");
387 OBD_VFREE(*buf, hdr.ioc_len);
391 if (data->ioc_inllen1) {
392 data->ioc_inlbuf1 = &data->ioc_bulk[0];
393 offset += size_round(data->ioc_inllen1);
396 if (data->ioc_inllen2) {
397 data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset;
398 offset += size_round(data->ioc_inllen2);
401 if (data->ioc_inllen3) {
402 data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset;
403 offset += size_round(data->ioc_inllen3);
406 if (data->ioc_inllen4) {
407 data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
413 static inline int obd_ioctl_popdata(void *arg, void *data, int len)
415 int err = copy_to_user(arg, data, len);
422 static inline void obd_ioctl_freedata(char *buf, int len)
432 * BSD ioctl description:
433 * #define IOC_V1 _IOR(g, n1, long)
434 * #define IOC_V2 _IOW(g, n2, long)
436 * ioctl(f, IOC_V1, arg);
437 * arg will be treated as a long value,
439 * ioctl(f, IOC_V2, arg)
440 * arg will be treated as a pointer, bsd will call
441 * copyin(buf, arg, sizeof(long))
443 * To make BSD ioctl handles argument correctly and simplely,
444 * we change _IOR to _IOWR so BSD will copyin obd_ioctl_data
445 * for us. Does this change affect Linux? (XXX Liang)
447 #define OBD_IOC_CREATE _IOWR('f', 101, OBD_IOC_DATA_TYPE)
448 #define OBD_IOC_DESTROY _IOW ('f', 104, OBD_IOC_DATA_TYPE)
449 #define OBD_IOC_PREALLOCATE _IOWR('f', 105, OBD_IOC_DATA_TYPE)
451 #define OBD_IOC_SETATTR _IOW ('f', 107, OBD_IOC_DATA_TYPE)
452 #define OBD_IOC_GETATTR _IOWR ('f', 108, OBD_IOC_DATA_TYPE)
453 #define OBD_IOC_READ _IOWR('f', 109, OBD_IOC_DATA_TYPE)
454 #define OBD_IOC_WRITE _IOWR('f', 110, OBD_IOC_DATA_TYPE)
457 #define OBD_IOC_STATFS _IOWR('f', 113, OBD_IOC_DATA_TYPE)
458 #define OBD_IOC_SYNC _IOW ('f', 114, OBD_IOC_DATA_TYPE)
459 #define OBD_IOC_READ2 _IOWR('f', 115, OBD_IOC_DATA_TYPE)
460 #define OBD_IOC_FORMAT _IOWR('f', 116, OBD_IOC_DATA_TYPE)
461 #define OBD_IOC_PARTITION _IOWR('f', 117, OBD_IOC_DATA_TYPE)
462 #define OBD_IOC_COPY _IOWR('f', 120, OBD_IOC_DATA_TYPE)
463 #define OBD_IOC_MIGR _IOWR('f', 121, OBD_IOC_DATA_TYPE)
464 #define OBD_IOC_PUNCH _IOWR('f', 122, OBD_IOC_DATA_TYPE)
466 #define OBD_IOC_MODULE_DEBUG _IOWR('f', 124, OBD_IOC_DATA_TYPE)
467 #define OBD_IOC_BRW_READ _IOWR('f', 125, OBD_IOC_DATA_TYPE)
468 #define OBD_IOC_BRW_WRITE _IOWR('f', 126, OBD_IOC_DATA_TYPE)
469 #define OBD_IOC_NAME2DEV _IOWR('f', 127, OBD_IOC_DATA_TYPE)
470 #define OBD_IOC_UUID2DEV _IOWR('f', 130, OBD_IOC_DATA_TYPE)
471 /* OBD_IOC_GETNAME_OLD is for compatibility with 1.4.x */
472 #define OBD_IOC_GETNAME_OLD _IOR ('f', 131, OBD_IOC_DATA_TYPE)
473 #define OBD_IOC_GETNAME _IOWR('f', 131, OBD_IOC_DATA_TYPE)
475 #define OBD_IOC_LOV_GET_CONFIG _IOWR('f', 132, OBD_IOC_DATA_TYPE)
476 #define OBD_IOC_CLIENT_RECOVER _IOW ('f', 133, OBD_IOC_DATA_TYPE)
477 #define OBD_IOC_PING_TARGET _IOW ('f', 136, OBD_IOC_DATA_TYPE)
479 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 139 )
480 #define OBD_IOC_NO_TRANSNO _IOW ('f', 140, OBD_IOC_DATA_TYPE)
481 #define OBD_IOC_SET_READONLY _IOW ('f', 141, OBD_IOC_DATA_TYPE)
482 #define OBD_IOC_ABORT_RECOVERY _IOR ('f', 142, OBD_IOC_DATA_TYPE)
484 #define OBD_GET_VERSION _IOWR ('f', 144, OBD_IOC_DATA_TYPE)
486 #define OBD_IOC_CLOSE_UUID _IOWR ('f', 147, OBD_IOC_DATA_TYPE)
488 #define OBD_IOC_GETDEVICE _IOWR ('f', 149, OBD_IOC_DATA_TYPE)
490 #define OBD_IOC_LOV_SETSTRIPE _IOW ('f', 154, OBD_IOC_DATA_TYPE)
491 #define OBD_IOC_LOV_GETSTRIPE _IOW ('f', 155, OBD_IOC_DATA_TYPE)
492 #define OBD_IOC_LOV_SETEA _IOW ('f', 156, OBD_IOC_DATA_TYPE)
494 #define OBD_IOC_QUOTACHECK _IOW ('f', 160, int)
495 #define OBD_IOC_POLL_QUOTACHECK _IOR ('f', 161, struct if_quotacheck *)
496 #define OBD_IOC_QUOTACTL _IOWR('f', 162, struct if_quotactl *)
498 #define OBD_IOC_MOUNTOPT _IOWR('f', 170, OBD_IOC_DATA_TYPE)
500 #define OBD_IOC_RECORD _IOWR('f', 180, OBD_IOC_DATA_TYPE)
501 #define OBD_IOC_ENDRECORD _IOWR('f', 181, OBD_IOC_DATA_TYPE)
502 #define OBD_IOC_PARSE _IOWR('f', 182, OBD_IOC_DATA_TYPE)
503 #define OBD_IOC_DORECORD _IOWR('f', 183, OBD_IOC_DATA_TYPE)
504 #define OBD_IOC_PROCESS_CFG _IOWR('f', 184, OBD_IOC_DATA_TYPE)
505 #define OBD_IOC_DUMP_LOG _IOWR('f', 185, OBD_IOC_DATA_TYPE)
506 #define OBD_IOC_CLEAR_LOG _IOWR('f', 186, OBD_IOC_DATA_TYPE)
507 #define OBD_IOC_PARAM _IOW ('f', 187, OBD_IOC_DATA_TYPE)
508 #define OBD_IOC_POOL _IOWR('f', 188, OBD_IOC_DATA_TYPE)
510 #define OBD_IOC_CATLOGLIST _IOWR('f', 190, OBD_IOC_DATA_TYPE)
511 #define OBD_IOC_LLOG_INFO _IOWR('f', 191, OBD_IOC_DATA_TYPE)
512 #define OBD_IOC_LLOG_PRINT _IOWR('f', 192, OBD_IOC_DATA_TYPE)
513 #define OBD_IOC_LLOG_CANCEL _IOWR('f', 193, OBD_IOC_DATA_TYPE)
514 #define OBD_IOC_LLOG_REMOVE _IOWR('f', 194, OBD_IOC_DATA_TYPE)
515 #define OBD_IOC_LLOG_CHECK _IOWR('f', 195, OBD_IOC_DATA_TYPE)
516 #define OBD_IOC_LLOG_CATINFO _IOWR('f', 196, OBD_IOC_DATA_TYPE)
518 #define ECHO_IOC_GET_STRIPE _IOWR('f', 200, OBD_IOC_DATA_TYPE)
519 #define ECHO_IOC_SET_STRIPE _IOWR('f', 201, OBD_IOC_DATA_TYPE)
520 #define ECHO_IOC_ENQUEUE _IOWR('f', 202, OBD_IOC_DATA_TYPE)
521 #define ECHO_IOC_CANCEL _IOWR('f', 203, OBD_IOC_DATA_TYPE)
523 /* XXX _IOWR('f', 250, long) has been defined in
524 * lnet/include/libcfs/kp30.h for debug, don't use it
527 /* Until such time as we get_info the per-stripe maximum from the OST,
528 * we define this to be 2T - 4k, which is the ext3 maxbytes. */
529 #define LUSTRE_STRIPE_MAXBYTES 0x1fffffff000ULL
531 /* #define POISON_BULK 0 */
534 * l_wait_event is a flexible sleeping function, permitting simple caller
535 * configuration of interrupt and timeout sensitivity along with actions to
536 * be performed in the event of either exception.
538 * The first form of usage looks like this:
540 * struct l_wait_info lwi = LWI_TIMEOUT_INTR(timeout, timeout_handler,
541 * intr_handler, callback_data);
542 * rc = l_wait_event(waitq, condition, &lwi);
544 * l_wait_event() makes the current process wait on 'waitq' until 'condition'
545 * is TRUE or a "killable" signal (SIGTERM, SIKGILL, SIGINT) is pending. It
546 * returns 0 to signify 'condition' is TRUE, but if a signal wakes it before
547 * 'condition' becomes true, it optionally calls the specified 'intr_handler'
548 * if not NULL, and returns -EINTR.
550 * If a non-zero timeout is specified, signals are ignored until the timeout
551 * has expired. At this time, if 'timeout_handler' is not NULL it is called.
552 * If it returns FALSE l_wait_event() continues to wait as described above with
553 * signals enabled. Otherwise it returns -ETIMEDOUT.
555 * LWI_INTR(intr_handler, callback_data) is shorthand for
556 * LWI_TIMEOUT_INTR(0, NULL, intr_handler, callback_data)
558 * The second form of usage looks like this:
560 * struct l_wait_info lwi = LWI_TIMEOUT(timeout, timeout_handler);
561 * rc = l_wait_event(waitq, condition, &lwi);
563 * This form is the same as the first except that it COMPLETELY IGNORES
564 * SIGNALS. The caller must therefore beware that if 'timeout' is zero, or if
565 * 'timeout_handler' is not NULL and returns FALSE, then the ONLY thing that
566 * can unblock the current process is 'condition' becoming TRUE.
568 * Another form of usage is:
569 * struct l_wait_info lwi = LWI_TIMEOUT_INTERVAL(timeout, interval,
571 * rc = l_wait_event(waitq, condition, &lwi);
572 * This is the same as previous case, but condition is checked once every
573 * 'interval' jiffies (if non-zero).
575 * Subtle synchronization point: this macro does *not* necessary takes
576 * wait-queue spin-lock before returning, and, hence, following idiom is safe
577 * ONLY when caller provides some external locking:
581 * l_wait_event(&obj->wq, ....); (1)
583 * wake_up(&obj->wq): (2)
584 * spin_lock(&q->lock); (2.1)
585 * __wake_up_common(q, ...); (2.2)
586 * spin_unlock(&q->lock, flags); (2.3)
588 * OBD_FREE_PTR(obj); (3)
590 * As l_wait_event() may "short-cut" execution and return without taking
591 * wait-queue spin-lock, some additional synchronization is necessary to
592 * guarantee that step (3) can begin only after (2.3) finishes.
594 * XXX nikita: some ptlrpc daemon threads have races of that sort.
598 #define LWI_ON_SIGNAL_NOOP ((void (*)(void *))(-1))
601 cfs_duration_t lwi_timeout;
602 cfs_duration_t lwi_interval;
603 int (*lwi_on_timeout)(void *);
604 void (*lwi_on_signal)(void *);
608 /* NB: LWI_TIMEOUT ignores signals completely */
609 #define LWI_TIMEOUT(time, cb, data) \
610 ((struct l_wait_info) { \
611 .lwi_timeout = time, \
612 .lwi_on_timeout = cb, \
613 .lwi_cb_data = data, \
617 #define LWI_TIMEOUT_INTERVAL(time, interval, cb, data) \
618 ((struct l_wait_info) { \
619 .lwi_timeout = time, \
620 .lwi_on_timeout = cb, \
621 .lwi_cb_data = data, \
622 .lwi_interval = interval \
625 #define LWI_TIMEOUT_INTR(time, time_cb, sig_cb, data) \
626 ((struct l_wait_info) { \
627 .lwi_timeout = time, \
628 .lwi_on_timeout = time_cb, \
629 .lwi_on_signal = sig_cb, \
630 .lwi_cb_data = data, \
634 #define LWI_INTR(cb, data) LWI_TIMEOUT_INTR(0, NULL, cb, data)
639 * wait for @condition to become true, but no longer than timeout, specified
642 #define __l_wait_event(wq, condition, info, ret, excl) \
644 cfs_waitlink_t __wait; \
645 cfs_duration_t __timeout = info->lwi_timeout; \
646 cfs_sigset_t __blocked; \
652 cfs_waitlink_init(&__wait); \
654 cfs_waitq_add_exclusive(&wq, &__wait); \
656 cfs_waitq_add(&wq, &__wait); \
658 /* Block all signals (just the non-fatal ones if no timeout). */ \
659 if (info->lwi_on_signal != NULL && __timeout == 0) \
660 __blocked = l_w_e_set_sigs(LUSTRE_FATAL_SIGS); \
662 __blocked = l_w_e_set_sigs(0); \
665 set_current_state(TASK_INTERRUPTIBLE); \
670 if (__timeout == 0) { \
671 cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE); \
673 cfs_duration_t interval = info->lwi_interval? \
674 min_t(cfs_duration_t, \
675 info->lwi_interval,__timeout):\
677 cfs_duration_t remaining = cfs_waitq_timedwait(&__wait,\
678 CFS_TASK_INTERRUPTIBLE, \
680 __timeout = cfs_time_sub(__timeout, \
681 cfs_time_sub(interval, remaining));\
682 if (__timeout == 0) { \
683 if (info->lwi_on_timeout == NULL || \
684 info->lwi_on_timeout(info->lwi_cb_data)) { \
688 /* Take signals after the timeout expires. */ \
689 if (info->lwi_on_signal != NULL) \
690 (void)l_w_e_set_sigs(LUSTRE_FATAL_SIGS); \
696 if (cfs_signal_pending()) { \
697 if (info->lwi_on_signal != NULL && __timeout == 0) { \
698 if (info->lwi_on_signal != LWI_ON_SIGNAL_NOOP) \
699 info->lwi_on_signal(info->lwi_cb_data);\
703 /* We have to do this here because some signals */ \
704 /* are not blockable - ie from strace(1). */ \
705 /* In these cases we want to schedule_timeout() */ \
706 /* again, because we don't want that to return */ \
707 /* -EINTR when the RPC actually succeeded. */ \
708 /* the RECALC_SIGPENDING below will deliver the */ \
709 /* signal properly. */ \
710 cfs_clear_sigpending(); \
714 cfs_block_sigs(__blocked); \
716 set_current_state(TASK_RUNNING); \
717 cfs_waitq_del(&wq, &__wait); \
720 #else /* !__KERNEL__ */
721 #define __l_wait_event(wq, condition, info, ret, excl) \
723 long __timeout = info->lwi_timeout; \
726 int __timed_out = 0; \
727 int __interval = obd_timeout; \
733 if (__timeout != 0) \
734 __then = time(NULL); \
736 if (__timeout && __timeout < __interval) \
737 __interval = __timeout; \
738 if (info->lwi_interval && info->lwi_interval < __interval) \
739 __interval = info->lwi_interval; \
741 while (!(condition)) { \
742 liblustre_wait_event(__interval); \
746 if (!__timed_out && info->lwi_timeout != 0) { \
747 __now = time(NULL); \
748 __timeout -= __now - __then; \
756 if (info->lwi_on_timeout == NULL || \
757 info->lwi_on_timeout(info->lwi_cb_data)) { \
765 #endif /* __KERNEL__ */
767 #define l_wait_event(wq, condition, info) \
770 struct l_wait_info *__info = (info); \
772 __l_wait_event(wq, condition, __info, __ret, 0); \
776 #define l_wait_event_exclusive(wq, condition, info) \
779 struct l_wait_info *__info = (info); \
781 __l_wait_event(wq, condition, __info, __ret, 1); \
786 #define LIBLUSTRE_CLIENT (0)
788 #define LIBLUSTRE_CLIENT (1)
791 #endif /* _LUSTRE_LIB_H */