1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41#ifndef _LUSTRE_LIB_H
42#define _LUSTRE_LIB_H
43
44
45
46
47
48
49#include <linux/libcfs/libcfs.h>
50#include <lustre/lustre_idl.h>
51#include <lustre_ver.h>
52#include <lustre_cfg.h>
53#include <linux/lustre_lib.h>
54
55
56struct ptlrpc_request;
57struct obd_export;
58struct lu_target;
59struct l_wait_info;
60#include <lustre_ha.h>
61#include <lustre_net.h>
62#include <lvfs.h>
63
64
65int target_pack_pool_reply(struct ptlrpc_request *req);
66int do_set_info_async(struct obd_import *imp,
67 int opcode, int version,
68 obd_count keylen, void *key,
69 obd_count vallen, void *val,
70 struct ptlrpc_request_set *set);
71
72#define OBD_RECOVERY_MAX_TIME (obd_timeout * 18)
73#define OBD_MAX_IOCTL_BUFFER CONFIG_LUSTRE_OBD_MAX_IOCTL_BUFFER
74
75void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id);
76
77
78
79int client_sanobd_setup(struct obd_device *obddev, struct lustre_cfg* lcfg);
80struct client_obd *client_conn2cli(struct lustre_handle *conn);
81
82struct md_open_data;
83struct obd_client_handle {
84 struct lustre_handle och_fh;
85 struct lu_fid och_fid;
86 struct md_open_data *och_mod;
87 __u32 och_magic;
88 int och_flags;
89};
90#define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed
91
92
93void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
94void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
95
96
97struct lustre_lock {
98 int l_depth;
99 task_t *l_owner;
100 struct semaphore l_sem;
101 spinlock_t l_spin;
102};
103
104void l_lock_init(struct lustre_lock *);
105void l_lock(struct lustre_lock *);
106void l_unlock(struct lustre_lock *);
107int l_has_lock(struct lustre_lock *);
108
109
110
111
112enum md_echo_cmd {
113 ECHO_MD_CREATE = 1,
114 ECHO_MD_MKDIR = 2,
115 ECHO_MD_DESTROY = 3,
116 ECHO_MD_RMDIR = 4,
117 ECHO_MD_LOOKUP = 5,
118 ECHO_MD_GETATTR = 6,
119 ECHO_MD_SETATTR = 7,
120 ECHO_MD_ALLOC_FID = 8,
121};
122
123
124
125
126#define OBD_IOCTL_VERSION 0x00010004
127
128struct obd_ioctl_data {
129 __u32 ioc_len;
130 __u32 ioc_version;
131
132 union {
133 __u64 ioc_cookie;
134 __u64 ioc_u64_1;
135 };
136 union {
137 __u32 ioc_conn1;
138 __u32 ioc_u32_1;
139 };
140 union {
141 __u32 ioc_conn2;
142 __u32 ioc_u32_2;
143 };
144
145 struct obdo ioc_obdo1;
146 struct obdo ioc_obdo2;
147
148 obd_size ioc_count;
149 obd_off ioc_offset;
150 __u32 ioc_dev;
151 __u32 ioc_command;
152
153 __u64 ioc_nid;
154 __u32 ioc_nal;
155 __u32 ioc_type;
156
157
158 __u32 ioc_plen1;
159 char *ioc_pbuf1;
160 __u32 ioc_plen2;
161 char *ioc_pbuf2;
162
163
164 __u32 ioc_inllen1;
165 char *ioc_inlbuf1;
166 __u32 ioc_inllen2;
167 char *ioc_inlbuf2;
168 __u32 ioc_inllen3;
169 char *ioc_inlbuf3;
170 __u32 ioc_inllen4;
171 char *ioc_inlbuf4;
172
173 char ioc_bulk[0];
174};
175
176struct obd_ioctl_hdr {
177 __u32 ioc_len;
178 __u32 ioc_version;
179};
180
181static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
182{
183 int len = cfs_size_round(sizeof(struct obd_ioctl_data));
184 len += cfs_size_round(data->ioc_inllen1);
185 len += cfs_size_round(data->ioc_inllen2);
186 len += cfs_size_round(data->ioc_inllen3);
187 len += cfs_size_round(data->ioc_inllen4);
188 return len;
189}
190
191
192static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
193{
194 if (data->ioc_len > (1<<30)) {
195 CERROR("OBD ioctl: ioc_len larger than 1<<30\n");
196 return 1;
197 }
198 if (data->ioc_inllen1 > (1<<30)) {
199 CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
200 return 1;
201 }
202 if (data->ioc_inllen2 > (1<<30)) {
203 CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
204 return 1;
205 }
206 if (data->ioc_inllen3 > (1<<30)) {
207 CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
208 return 1;
209 }
210 if (data->ioc_inllen4 > (1<<30)) {
211 CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n");
212 return 1;
213 }
214 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
215 CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n");
216 return 1;
217 }
218 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
219 CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n");
220 return 1;
221 }
222 if (data->ioc_inlbuf3 && !data->ioc_inllen3) {
223 CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n");
224 return 1;
225 }
226 if (data->ioc_inlbuf4 && !data->ioc_inllen4) {
227 CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n");
228 return 1;
229 }
230 if (data->ioc_pbuf1 && !data->ioc_plen1) {
231 CERROR("OBD ioctl: pbuf1 pointer but 0 length\n");
232 return 1;
233 }
234 if (data->ioc_pbuf2 && !data->ioc_plen2) {
235 CERROR("OBD ioctl: pbuf2 pointer but 0 length\n");
236 return 1;
237 }
238 if (data->ioc_plen1 && !data->ioc_pbuf1) {
239 CERROR("OBD ioctl: plen1 set but NULL pointer\n");
240 return 1;
241 }
242 if (data->ioc_plen2 && !data->ioc_pbuf2) {
243 CERROR("OBD ioctl: plen2 set but NULL pointer\n");
244 return 1;
245 }
246 if (obd_ioctl_packlen(data) > data->ioc_len) {
247 CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n",
248 obd_ioctl_packlen(data), data->ioc_len);
249 return 1;
250 }
251 return 0;
252}
253
254
255#include <obd_support.h>
256
257
258int obd_ioctl_getdata(char **buf, int *len, void *arg);
259int obd_ioctl_popdata(void *arg, void *data, int len);
260
261static inline void obd_ioctl_freedata(char *buf, int len)
262{
263 ENTRY;
264
265 OBD_FREE_LARGE(buf, len);
266 EXIT;
267 return;
268}
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286#define OBD_IOC_CREATE _IOWR('f', 101, OBD_IOC_DATA_TYPE)
287#define OBD_IOC_DESTROY _IOW ('f', 104, OBD_IOC_DATA_TYPE)
288#define OBD_IOC_PREALLOCATE _IOWR('f', 105, OBD_IOC_DATA_TYPE)
289
290#define OBD_IOC_SETATTR _IOW ('f', 107, OBD_IOC_DATA_TYPE)
291#define OBD_IOC_GETATTR _IOWR ('f', 108, OBD_IOC_DATA_TYPE)
292#define OBD_IOC_READ _IOWR('f', 109, OBD_IOC_DATA_TYPE)
293#define OBD_IOC_WRITE _IOWR('f', 110, OBD_IOC_DATA_TYPE)
294
295
296#define OBD_IOC_STATFS _IOWR('f', 113, OBD_IOC_DATA_TYPE)
297#define OBD_IOC_SYNC _IOW ('f', 114, OBD_IOC_DATA_TYPE)
298#define OBD_IOC_READ2 _IOWR('f', 115, OBD_IOC_DATA_TYPE)
299#define OBD_IOC_FORMAT _IOWR('f', 116, OBD_IOC_DATA_TYPE)
300#define OBD_IOC_PARTITION _IOWR('f', 117, OBD_IOC_DATA_TYPE)
301#define OBD_IOC_COPY _IOWR('f', 120, OBD_IOC_DATA_TYPE)
302#define OBD_IOC_MIGR _IOWR('f', 121, OBD_IOC_DATA_TYPE)
303#define OBD_IOC_PUNCH _IOWR('f', 122, OBD_IOC_DATA_TYPE)
304
305#define OBD_IOC_MODULE_DEBUG _IOWR('f', 124, OBD_IOC_DATA_TYPE)
306#define OBD_IOC_BRW_READ _IOWR('f', 125, OBD_IOC_DATA_TYPE)
307#define OBD_IOC_BRW_WRITE _IOWR('f', 126, OBD_IOC_DATA_TYPE)
308#define OBD_IOC_NAME2DEV _IOWR('f', 127, OBD_IOC_DATA_TYPE)
309#define OBD_IOC_UUID2DEV _IOWR('f', 130, OBD_IOC_DATA_TYPE)
310
311#define OBD_IOC_GETNAME _IOWR('f', 131, OBD_IOC_DATA_TYPE)
312#define OBD_IOC_GETMDNAME _IOR('f', 131, char[MAX_OBD_NAME])
313#define OBD_IOC_GETDTNAME OBD_IOC_GETNAME
314
315#define OBD_IOC_LOV_GET_CONFIG _IOWR('f', 132, OBD_IOC_DATA_TYPE)
316#define OBD_IOC_CLIENT_RECOVER _IOW ('f', 133, OBD_IOC_DATA_TYPE)
317#define OBD_IOC_PING_TARGET _IOW ('f', 136, OBD_IOC_DATA_TYPE)
318
319#define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 139 )
320#define OBD_IOC_NO_TRANSNO _IOW ('f', 140, OBD_IOC_DATA_TYPE)
321#define OBD_IOC_SET_READONLY _IOW ('f', 141, OBD_IOC_DATA_TYPE)
322#define OBD_IOC_ABORT_RECOVERY _IOR ('f', 142, OBD_IOC_DATA_TYPE)
323
324#define OBD_IOC_ROOT_SQUASH _IOWR('f', 143, OBD_IOC_DATA_TYPE)
325
326#define OBD_GET_VERSION _IOWR ('f', 144, OBD_IOC_DATA_TYPE)
327
328#define OBD_IOC_GSS_SUPPORT _IOWR('f', 145, OBD_IOC_DATA_TYPE)
329
330#define OBD_IOC_CLOSE_UUID _IOWR ('f', 147, OBD_IOC_DATA_TYPE)
331
332#define OBD_IOC_CHANGELOG_SEND _IOW ('f', 148, OBD_IOC_DATA_TYPE)
333#define OBD_IOC_GETDEVICE _IOWR ('f', 149, OBD_IOC_DATA_TYPE)
334#define OBD_IOC_FID2PATH _IOWR ('f', 150, OBD_IOC_DATA_TYPE)
335
336
337#define OBD_IOC_LOV_SETSTRIPE _IOW ('f', 154, OBD_IOC_DATA_TYPE)
338
339#define OBD_IOC_LOV_GETSTRIPE _IOW ('f', 155, OBD_IOC_DATA_TYPE)
340
341#define OBD_IOC_LOV_SETEA _IOW ('f', 156, OBD_IOC_DATA_TYPE)
342
343
344#define OBD_IOC_QUOTACHECK _IOW ('f', 160, int)
345
346#define OBD_IOC_POLL_QUOTACHECK _IOR ('f', 161, struct if_quotacheck *)
347
348#define OBD_IOC_QUOTACTL _IOWR('f', 162, struct if_quotactl)
349
350#define OBD_IOC_CHANGELOG_REG _IOW ('f', 177, struct obd_ioctl_data)
351#define OBD_IOC_CHANGELOG_DEREG _IOW ('f', 178, struct obd_ioctl_data)
352#define OBD_IOC_CHANGELOG_CLEAR _IOW ('f', 179, struct obd_ioctl_data)
353#define OBD_IOC_RECORD _IOWR('f', 180, OBD_IOC_DATA_TYPE)
354#define OBD_IOC_ENDRECORD _IOWR('f', 181, OBD_IOC_DATA_TYPE)
355#define OBD_IOC_PARSE _IOWR('f', 182, OBD_IOC_DATA_TYPE)
356#define OBD_IOC_DORECORD _IOWR('f', 183, OBD_IOC_DATA_TYPE)
357#define OBD_IOC_PROCESS_CFG _IOWR('f', 184, OBD_IOC_DATA_TYPE)
358#define OBD_IOC_DUMP_LOG _IOWR('f', 185, OBD_IOC_DATA_TYPE)
359#define OBD_IOC_CLEAR_LOG _IOWR('f', 186, OBD_IOC_DATA_TYPE)
360#define OBD_IOC_PARAM _IOW ('f', 187, OBD_IOC_DATA_TYPE)
361#define OBD_IOC_POOL _IOWR('f', 188, OBD_IOC_DATA_TYPE)
362#define OBD_IOC_REPLACE_NIDS _IOWR('f', 189, OBD_IOC_DATA_TYPE)
363
364#define OBD_IOC_CATLOGLIST _IOWR('f', 190, OBD_IOC_DATA_TYPE)
365#define OBD_IOC_LLOG_INFO _IOWR('f', 191, OBD_IOC_DATA_TYPE)
366#define OBD_IOC_LLOG_PRINT _IOWR('f', 192, OBD_IOC_DATA_TYPE)
367#define OBD_IOC_LLOG_CANCEL _IOWR('f', 193, OBD_IOC_DATA_TYPE)
368#define OBD_IOC_LLOG_REMOVE _IOWR('f', 194, OBD_IOC_DATA_TYPE)
369#define OBD_IOC_LLOG_CHECK _IOWR('f', 195, OBD_IOC_DATA_TYPE)
370
371#define OBD_IOC_LLOG_CATINFO _IOWR('f', 196, OBD_IOC_DATA_TYPE)
372
373#define ECHO_IOC_GET_STRIPE _IOWR('f', 200, OBD_IOC_DATA_TYPE)
374#define ECHO_IOC_SET_STRIPE _IOWR('f', 201, OBD_IOC_DATA_TYPE)
375#define ECHO_IOC_ENQUEUE _IOWR('f', 202, OBD_IOC_DATA_TYPE)
376#define ECHO_IOC_CANCEL _IOWR('f', 203, OBD_IOC_DATA_TYPE)
377
378#define OBD_IOC_GET_OBJ_VERSION _IOR('f', 210, OBD_IOC_DATA_TYPE)
379
380
381#define OBD_IOC_GET_MNTOPT _IOW('f', 220, mntopt_t)
382
383#define OBD_IOC_ECHO_MD _IOR('f', 221, struct obd_ioctl_data)
384#define OBD_IOC_ECHO_ALLOC_SEQ _IOWR('f', 222, struct obd_ioctl_data)
385
386#define OBD_IOC_START_LFSCK _IOWR('f', 230, OBD_IOC_DATA_TYPE)
387#define OBD_IOC_STOP_LFSCK _IOW('f', 231, OBD_IOC_DATA_TYPE)
388#define OBD_IOC_PAUSE_LFSCK _IOW('f', 232, OBD_IOC_DATA_TYPE)
389
390
391
392
393
394
395
396#define LUSTRE_STRIPE_MAXBYTES 0x1fffffff000ULL
397
398
399#define LOVEA_DELETE_VALUES(size, count, offset) (size == 0 && count == 0 && \
400 offset == (typeof(offset))(-1))
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468static inline int back_to_sleep(void *arg)
469{
470 return 0;
471}
472
473#define LWI_ON_SIGNAL_NOOP ((void (*)(void *))(-1))
474
475struct l_wait_info {
476 cfs_duration_t lwi_timeout;
477 cfs_duration_t lwi_interval;
478 int lwi_allow_intr;
479 int (*lwi_on_timeout)(void *);
480 void (*lwi_on_signal)(void *);
481 void *lwi_cb_data;
482};
483
484
485#define LWI_TIMEOUT(time, cb, data) \
486((struct l_wait_info) { \
487 .lwi_timeout = time, \
488 .lwi_on_timeout = cb, \
489 .lwi_cb_data = data, \
490 .lwi_interval = 0, \
491 .lwi_allow_intr = 0 \
492})
493
494#define LWI_TIMEOUT_INTERVAL(time, interval, cb, data) \
495((struct l_wait_info) { \
496 .lwi_timeout = time, \
497 .lwi_on_timeout = cb, \
498 .lwi_cb_data = data, \
499 .lwi_interval = interval, \
500 .lwi_allow_intr = 0 \
501})
502
503#define LWI_TIMEOUT_INTR(time, time_cb, sig_cb, data) \
504((struct l_wait_info) { \
505 .lwi_timeout = time, \
506 .lwi_on_timeout = time_cb, \
507 .lwi_on_signal = sig_cb, \
508 .lwi_cb_data = data, \
509 .lwi_interval = 0, \
510 .lwi_allow_intr = 0 \
511})
512
513#define LWI_TIMEOUT_INTR_ALL(time, time_cb, sig_cb, data) \
514((struct l_wait_info) { \
515 .lwi_timeout = time, \
516 .lwi_on_timeout = time_cb, \
517 .lwi_on_signal = sig_cb, \
518 .lwi_cb_data = data, \
519 .lwi_interval = 0, \
520 .lwi_allow_intr = 1 \
521})
522
523#define LWI_INTR(cb, data) LWI_TIMEOUT_INTR(0, NULL, cb, data)
524
525
526
527
528
529
530#define __l_wait_event(wq, condition, info, ret, l_add_wait) \
531do { \
532 wait_queue_t __wait; \
533 cfs_duration_t __timeout = info->lwi_timeout; \
534 sigset_t __blocked; \
535 int __allow_intr = info->lwi_allow_intr; \
536 \
537 ret = 0; \
538 if (condition) \
539 break; \
540 \
541 init_waitqueue_entry_current(&__wait); \
542 l_add_wait(&wq, &__wait); \
543 \
544 \
545 if (info->lwi_on_signal != NULL && (__timeout == 0 || __allow_intr)) \
546 __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \
547 else \
548 __blocked = cfs_block_sigsinv(0); \
549 \
550 for (;;) { \
551 unsigned __wstate; \
552 \
553 __wstate = info->lwi_on_signal != NULL && \
554 (__timeout == 0 || __allow_intr) ? \
555 TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE; \
556 \
557 set_current_state(TASK_INTERRUPTIBLE); \
558 \
559 if (condition) \
560 break; \
561 \
562 if (__timeout == 0) { \
563 waitq_wait(&__wait, __wstate); \
564 } else { \
565 cfs_duration_t interval = info->lwi_interval? \
566 min_t(cfs_duration_t, \
567 info->lwi_interval,__timeout):\
568 __timeout; \
569 cfs_duration_t remaining = waitq_timedwait(&__wait,\
570 __wstate, \
571 interval); \
572 __timeout = cfs_time_sub(__timeout, \
573 cfs_time_sub(interval, remaining));\
574 if (__timeout == 0) { \
575 if (info->lwi_on_timeout == NULL || \
576 info->lwi_on_timeout(info->lwi_cb_data)) { \
577 ret = -ETIMEDOUT; \
578 break; \
579 } \
580 \
581 if (info->lwi_on_signal != NULL) \
582 (void)cfs_block_sigsinv(LUSTRE_FATAL_SIGS);\
583 } \
584 } \
585 \
586 if (condition) \
587 break; \
588 if (cfs_signal_pending()) { \
589 if (info->lwi_on_signal != NULL && \
590 (__timeout == 0 || __allow_intr)) { \
591 if (info->lwi_on_signal != LWI_ON_SIGNAL_NOOP) \
592 info->lwi_on_signal(info->lwi_cb_data);\
593 ret = -EINTR; \
594 break; \
595 } \
596 \
597 \
598 \
599 \
600 \
601 \
602 \
603 cfs_clear_sigpending(); \
604 } \
605 } \
606 \
607 cfs_restore_sigs(__blocked); \
608 \
609 set_current_state(TASK_RUNNING); \
610 remove_wait_queue(&wq, &__wait); \
611} while (0)
612
613
614
615#define l_wait_event(wq, condition, info) \
616({ \
617 int __ret; \
618 struct l_wait_info *__info = (info); \
619 \
620 __l_wait_event(wq, condition, __info, \
621 __ret, add_wait_queue); \
622 __ret; \
623})
624
625#define l_wait_event_exclusive(wq, condition, info) \
626({ \
627 int __ret; \
628 struct l_wait_info *__info = (info); \
629 \
630 __l_wait_event(wq, condition, __info, \
631 __ret, add_wait_queue_exclusive); \
632 __ret; \
633})
634
635#define l_wait_event_exclusive_head(wq, condition, info) \
636({ \
637 int __ret; \
638 struct l_wait_info *__info = (info); \
639 \
640 __l_wait_event(wq, condition, __info, \
641 __ret, add_wait_queue_exclusive_head); \
642 __ret; \
643})
644
645#define l_wait_condition(wq, condition) \
646({ \
647 struct l_wait_info lwi = { 0 }; \
648 l_wait_event(wq, condition, &lwi); \
649})
650
651#define l_wait_condition_exclusive(wq, condition) \
652({ \
653 struct l_wait_info lwi = { 0 }; \
654 l_wait_event_exclusive(wq, condition, &lwi); \
655})
656
657#define l_wait_condition_exclusive_head(wq, condition) \
658({ \
659 struct l_wait_info lwi = { 0 }; \
660 l_wait_event_exclusive_head(wq, condition, &lwi); \
661})
662
663#define LIBLUSTRE_CLIENT (0)
664
665
666
667#endif
668