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#ifndef __LUSTRE_DT_OBJECT_H
38#define __LUSTRE_DT_OBJECT_H
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56#include <lu_object.h>
57
58#include <linux/libcfs/libcfs.h>
59
60struct seq_file;
61struct proc_dir_entry;
62struct lustre_cfg;
63
64struct thandle;
65struct dt_device;
66struct dt_object;
67struct dt_index_features;
68struct niobuf_local;
69struct niobuf_remote;
70struct ldlm_enqueue_info;
71
72typedef enum {
73 MNTOPT_USERXATTR = 0x00000001,
74 MNTOPT_ACL = 0x00000002,
75} mntopt_t;
76
77struct dt_device_param {
78 unsigned ddp_max_name_len;
79 unsigned ddp_max_nlink;
80 unsigned ddp_block_shift;
81 mntopt_t ddp_mntopts;
82 unsigned ddp_max_ea_size;
83 void *ddp_mnt;
84 int ddp_mount_type;
85 unsigned long long ddp_maxbytes;
86
87 int ddp_grant_reserved;
88
89 short ddp_inodespace;
90
91
92 int ddp_grant_frag;
93};
94
95
96
97
98struct dt_txn_commit_cb;
99typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
100 struct dt_txn_commit_cb *cb, int err);
101
102
103
104
105#define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
106#define MAX_COMMIT_CB_STR_LEN 32
107
108struct dt_txn_commit_cb {
109 struct list_head dcb_linkage;
110 dt_cb_t dcb_func;
111 __u32 dcb_magic;
112 char dcb_name[MAX_COMMIT_CB_STR_LEN];
113};
114
115
116
117
118struct dt_device_operations {
119
120
121
122 int (*dt_statfs)(const struct lu_env *env,
123 struct dt_device *dev, struct obd_statfs *osfs);
124
125
126
127 struct thandle *(*dt_trans_create)(const struct lu_env *env,
128 struct dt_device *dev);
129
130
131
132 int (*dt_trans_start)(const struct lu_env *env,
133 struct dt_device *dev, struct thandle *th);
134
135
136
137 int (*dt_trans_stop)(const struct lu_env *env,
138 struct thandle *th);
139
140
141
142 int (*dt_trans_cb_add)(struct thandle *th,
143 struct dt_txn_commit_cb *dcb);
144
145
146
147 int (*dt_root_get)(const struct lu_env *env,
148 struct dt_device *dev, struct lu_fid *f);
149
150
151
152 void (*dt_conf_get)(const struct lu_env *env,
153 const struct dt_device *dev,
154 struct dt_device_param *param);
155
156
157
158 int (*dt_sync)(const struct lu_env *env, struct dt_device *dev);
159 int (*dt_ro)(const struct lu_env *env, struct dt_device *dev);
160
161
162
163
164
165
166
167
168 int (*dt_commit_async)(const struct lu_env *env,
169 struct dt_device *dev);
170
171
172
173 int (*dt_init_capa_ctxt)(const struct lu_env *env,
174 struct dt_device *dev,
175 int mode, unsigned long timeout,
176 __u32 alg, struct lustre_capa_key *keys);
177};
178
179struct dt_index_features {
180
181 __u32 dif_flags;
182
183 size_t dif_keysize_min;
184
185 size_t dif_keysize_max;
186
187 size_t dif_recsize_min;
188
189 size_t dif_recsize_max;
190
191 size_t dif_ptrsize;
192};
193
194enum dt_index_flags {
195
196 DT_IND_VARKEY = 1 << 0,
197
198 DT_IND_VARREC = 1 << 1,
199
200 DT_IND_UPDATE = 1 << 2,
201
202 DT_IND_NONUNQ = 1 << 3,
203
204
205
206
207 DT_IND_RANGE = 1 << 4,
208};
209
210
211
212
213
214extern const struct dt_index_features dt_directory_features;
215extern const struct dt_index_features dt_otable_features;
216extern const struct dt_index_features dt_lfsck_features;
217
218
219extern const struct dt_index_features dt_acct_features;
220
221
222extern const struct dt_index_features dt_quota_glb_features;
223
224
225extern const struct dt_index_features dt_quota_slv_features;
226
227
228
229
230
231
232struct dt_allocation_hint {
233 struct dt_object *dah_parent;
234 __u32 dah_mode;
235};
236
237
238
239
240
241enum dt_format_type {
242 DFT_REGULAR,
243 DFT_DIR,
244
245 DFT_NODE,
246
247 DFT_INDEX,
248
249 DFT_SYM,
250};
251
252
253
254
255struct dt_object_format {
256
257 enum dt_format_type dof_type;
258 union {
259 struct dof_regular {
260 int striped;
261 } dof_reg;
262 struct dof_dir {
263 } dof_dir;
264 struct dof_node {
265 } dof_node;
266
267
268
269
270 struct dof_index {
271 const struct dt_index_features *di_feat;
272 } dof_idx;
273 } u;
274};
275
276enum dt_format_type dt_mode_to_dft(__u32 mode);
277
278typedef __u64 dt_obj_version_t;
279
280
281
282
283struct dt_object_operations {
284 void (*do_read_lock)(const struct lu_env *env,
285 struct dt_object *dt, unsigned role);
286 void (*do_write_lock)(const struct lu_env *env,
287 struct dt_object *dt, unsigned role);
288 void (*do_read_unlock)(const struct lu_env *env,
289 struct dt_object *dt);
290 void (*do_write_unlock)(const struct lu_env *env,
291 struct dt_object *dt);
292 int (*do_write_locked)(const struct lu_env *env,
293 struct dt_object *dt);
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309 int (*do_attr_get)(const struct lu_env *env,
310 struct dt_object *dt, struct lu_attr *attr,
311 struct lustre_capa *capa);
312
313
314
315
316
317 int (*do_declare_attr_set)(const struct lu_env *env,
318 struct dt_object *dt,
319 const struct lu_attr *attr,
320 struct thandle *handle);
321 int (*do_attr_set)(const struct lu_env *env,
322 struct dt_object *dt,
323 const struct lu_attr *attr,
324 struct thandle *handle,
325 struct lustre_capa *capa);
326
327
328
329
330
331 int (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
332 struct lu_buf *buf, const char *name,
333 struct lustre_capa *capa);
334
335
336
337
338
339
340
341 int (*do_declare_xattr_set)(const struct lu_env *env,
342 struct dt_object *dt,
343 const struct lu_buf *buf,
344 const char *name, int fl,
345 struct thandle *handle);
346 int (*do_xattr_set)(const struct lu_env *env,
347 struct dt_object *dt, const struct lu_buf *buf,
348 const char *name, int fl, struct thandle *handle,
349 struct lustre_capa *capa);
350
351
352
353
354
355 int (*do_declare_xattr_del)(const struct lu_env *env,
356 struct dt_object *dt,
357 const char *name, struct thandle *handle);
358 int (*do_xattr_del)(const struct lu_env *env,
359 struct dt_object *dt,
360 const char *name, struct thandle *handle,
361 struct lustre_capa *capa);
362
363
364
365
366
367
368 int (*do_xattr_list)(const struct lu_env *env,
369 struct dt_object *dt, struct lu_buf *buf,
370 struct lustre_capa *capa);
371
372
373
374
375
376
377
378 void (*do_ah_init)(const struct lu_env *env,
379 struct dt_allocation_hint *ah,
380 struct dt_object *parent,
381 struct dt_object *child,
382 umode_t child_mode);
383
384
385
386
387
388
389 int (*do_declare_create)(const struct lu_env *env,
390 struct dt_object *dt,
391 struct lu_attr *attr,
392 struct dt_allocation_hint *hint,
393 struct dt_object_format *dof,
394 struct thandle *th);
395 int (*do_create)(const struct lu_env *env, struct dt_object *dt,
396 struct lu_attr *attr,
397 struct dt_allocation_hint *hint,
398 struct dt_object_format *dof,
399 struct thandle *th);
400
401
402
403
404
405
406 int (*do_declare_destroy)(const struct lu_env *env,
407 struct dt_object *dt,
408 struct thandle *th);
409 int (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
410 struct thandle *th);
411
412
413
414
415
416
417
418
419
420 int (*do_index_try)(const struct lu_env *env,
421 struct dt_object *dt,
422 const struct dt_index_features *feat);
423
424
425
426
427 int (*do_declare_ref_add)(const struct lu_env *env,
428 struct dt_object *dt, struct thandle *th);
429 int (*do_ref_add)(const struct lu_env *env,
430 struct dt_object *dt, struct thandle *th);
431
432
433
434
435 int (*do_declare_ref_del)(const struct lu_env *env,
436 struct dt_object *dt, struct thandle *th);
437 int (*do_ref_del)(const struct lu_env *env,
438 struct dt_object *dt, struct thandle *th);
439
440 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
441 struct dt_object *dt,
442 struct lustre_capa *old,
443 __u64 opc);
444 int (*do_object_sync)(const struct lu_env *, struct dt_object *);
445
446
447
448
449
450 int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
451 void **data);
452
453
454
455
456 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
457 struct lustre_handle *lh,
458 struct ldlm_enqueue_info *einfo,
459 void *policy);
460};
461
462
463
464
465struct dt_body_operations {
466
467
468
469 ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
470 struct lu_buf *buf, loff_t *pos,
471 struct lustre_capa *capa);
472
473
474
475 ssize_t (*dbo_declare_write)(const struct lu_env *env,
476 struct dt_object *dt,
477 const loff_t size, loff_t pos,
478 struct thandle *handle);
479 ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
480 const struct lu_buf *buf, loff_t *pos,
481 struct thandle *handle, struct lustre_capa *capa,
482 int ignore_quota);
483
484
485
486
487
488
489
490
491
492
493
494 int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
495 loff_t pos, ssize_t len, struct niobuf_local *lb,
496 int rw, struct lustre_capa *capa);
497
498
499
500 int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
501 struct niobuf_local *lb, int nr);
502
503
504
505 int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
506 struct niobuf_local *lb, int nr);
507
508
509
510 int (*dbo_declare_write_commit)(const struct lu_env *env,
511 struct dt_object *dt,
512 struct niobuf_local *,
513 int, struct thandle *);
514
515
516
517 int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
518 struct niobuf_local *, int, struct thandle *);
519
520
521
522 int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
523 struct niobuf_local *lnb, int nr);
524 int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
525 struct ll_user_fiemap *fm);
526
527
528
529
530 int (*dbo_declare_punch)(const struct lu_env *, struct dt_object *,
531 __u64, __u64, struct thandle *th);
532 int (*dbo_punch)(const struct lu_env *env, struct dt_object *dt,
533 __u64 start, __u64 end, struct thandle *th,
534 struct lustre_capa *capa);
535};
536
537
538
539
540struct dt_rec;
541
542
543
544
545struct dt_key;
546
547
548
549
550struct dt_it;
551
552
553
554
555struct dt_index_operations {
556
557
558
559 int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
560 struct dt_rec *rec, const struct dt_key *key,
561 struct lustre_capa *capa);
562
563
564
565 int (*dio_declare_insert)(const struct lu_env *env,
566 struct dt_object *dt,
567 const struct dt_rec *rec,
568 const struct dt_key *key,
569 struct thandle *handle);
570 int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
571 const struct dt_rec *rec, const struct dt_key *key,
572 struct thandle *handle, struct lustre_capa *capa,
573 int ignore_quota);
574
575
576
577 int (*dio_declare_delete)(const struct lu_env *env,
578 struct dt_object *dt,
579 const struct dt_key *key,
580 struct thandle *handle);
581 int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
582 const struct dt_key *key, struct thandle *handle,
583 struct lustre_capa *capa);
584
585
586
587 struct dt_it_ops {
588
589
590
591
592
593 struct dt_it *(*init)(const struct lu_env *env,
594 struct dt_object *dt,
595 __u32 attr,
596 struct lustre_capa *capa);
597 void (*fini)(const struct lu_env *env,
598 struct dt_it *di);
599 int (*get)(const struct lu_env *env,
600 struct dt_it *di,
601 const struct dt_key *key);
602 void (*put)(const struct lu_env *env,
603 struct dt_it *di);
604 int (*next)(const struct lu_env *env,
605 struct dt_it *di);
606 struct dt_key *(*key)(const struct lu_env *env,
607 const struct dt_it *di);
608 int (*key_size)(const struct lu_env *env,
609 const struct dt_it *di);
610 int (*rec)(const struct lu_env *env,
611 const struct dt_it *di,
612 struct dt_rec *rec,
613 __u32 attr);
614 __u64 (*store)(const struct lu_env *env,
615 const struct dt_it *di);
616 int (*load)(const struct lu_env *env,
617 const struct dt_it *di, __u64 hash);
618 int (*key_rec)(const struct lu_env *env,
619 const struct dt_it *di, void* key_rec);
620 } dio_it;
621};
622
623enum dt_otable_it_valid {
624 DOIV_ERROR_HANDLE = 0x0001,
625};
626
627enum dt_otable_it_flags {
628
629 DOIF_FAILOUT = 0x0001,
630
631
632 DOIF_RESET = 0x0002,
633
634
635 DOIF_OUTUSED = 0x0004,
636};
637
638
639
640
641
642
643
644
645
646#define DT_OTABLE_IT_FLAGS_SHIFT 16
647#define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
648
649struct dt_device {
650 struct lu_device dd_lu_dev;
651 const struct dt_device_operations *dd_ops;
652
653
654
655
656
657
658 struct list_head dd_txn_callbacks;
659};
660
661int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
662void dt_device_fini(struct dt_device *dev);
663
664static inline int lu_device_is_dt(const struct lu_device *d)
665{
666 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
667}
668
669static inline struct dt_device * lu2dt_dev(struct lu_device *l)
670{
671 LASSERT(lu_device_is_dt(l));
672 return container_of0(l, struct dt_device, dd_lu_dev);
673}
674
675struct dt_object {
676 struct lu_object do_lu;
677 const struct dt_object_operations *do_ops;
678 const struct dt_body_operations *do_body_ops;
679 const struct dt_index_operations *do_index_ops;
680};
681
682
683
684
685struct local_oid_storage {
686
687 struct list_head los_list;
688
689
690 atomic_t los_refcount;
691 struct dt_device *los_dev;
692 struct dt_object *los_obj;
693
694
695 struct mutex los_id_lock;
696 __u64 los_seq;
697 __u32 los_last_oid;
698};
699
700static inline struct dt_object *lu2dt(struct lu_object *l)
701{
702 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
703 return container_of0(l, struct dt_object, do_lu);
704}
705
706int dt_object_init(struct dt_object *obj,
707 struct lu_object_header *h, struct lu_device *d);
708
709void dt_object_fini(struct dt_object *obj);
710
711static inline int dt_object_exists(const struct dt_object *dt)
712{
713 return lu_object_exists(&dt->do_lu);
714}
715
716static inline int dt_object_remote(const struct dt_object *dt)
717{
718 return lu_object_remote(&dt->do_lu);
719}
720
721static inline struct dt_object *lu2dt_obj(struct lu_object *o)
722{
723 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
724 return container_of0(o, struct dt_object, do_lu);
725}
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741struct thandle {
742
743 struct dt_device *th_dev;
744
745
746 struct lu_context th_ctx;
747
748
749 __u32 th_tags;
750
751
752
753 __s32 th_result;
754
755
756 unsigned int th_sync:1;
757
758
759 unsigned int th_local:1;
760
761
762
763
764
765
766 struct list_head th_remote_update_list;
767 struct update_request *th_current_request;
768};
769
770
771
772
773
774
775
776
777
778
779
780
781struct dt_txn_callback {
782 int (*dtc_txn_start)(const struct lu_env *env,
783 struct thandle *txn, void *cookie);
784 int (*dtc_txn_stop)(const struct lu_env *env,
785 struct thandle *txn, void *cookie);
786 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
787 void *dtc_cookie;
788 __u32 dtc_tag;
789 struct list_head dtc_linkage;
790};
791
792void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
793void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
794
795int dt_txn_hook_start(const struct lu_env *env,
796 struct dt_device *dev, struct thandle *txn);
797int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
798void dt_txn_hook_commit(struct thandle *txn);
799
800int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
801
802
803
804
805
806typedef int (*dt_entry_func_t)(const struct lu_env *env,
807 const char *name,
808 void *pvt);
809
810#define DT_MAX_PATH 1024
811
812int dt_path_parser(const struct lu_env *env,
813 char *local, dt_entry_func_t entry_func,
814 void *data);
815
816struct dt_object *
817dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
818 const char *path, struct lu_fid *fid);
819
820struct dt_object *dt_store_open(const struct lu_env *env,
821 struct dt_device *dt,
822 const char *dirname,
823 const char *filename,
824 struct lu_fid *fid);
825
826struct dt_object *dt_find_or_create(const struct lu_env *env,
827 struct dt_device *dt,
828 const struct lu_fid *fid,
829 struct dt_object_format *dof,
830 struct lu_attr *attr);
831
832struct dt_object *dt_locate_at(const struct lu_env *env,
833 struct dt_device *dev,
834 const struct lu_fid *fid,
835 struct lu_device *top_dev);
836static inline struct dt_object *
837dt_locate(const struct lu_env *env, struct dt_device *dev,
838 const struct lu_fid *fid)
839{
840 return dt_locate_at(env, dev, fid, dev->dd_lu_dev.ld_site->ls_top_dev);
841}
842
843
844int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
845 const struct lu_fid *first_fid,
846 struct local_oid_storage **los);
847void local_oid_storage_fini(const struct lu_env *env,
848 struct local_oid_storage *los);
849int local_object_fid_generate(const struct lu_env *env,
850 struct local_oid_storage *los,
851 struct lu_fid *fid);
852int local_object_declare_create(const struct lu_env *env,
853 struct local_oid_storage *los,
854 struct dt_object *o,
855 struct lu_attr *attr,
856 struct dt_object_format *dof,
857 struct thandle *th);
858int local_object_create(const struct lu_env *env,
859 struct local_oid_storage *los,
860 struct dt_object *o,
861 struct lu_attr *attr, struct dt_object_format *dof,
862 struct thandle *th);
863struct dt_object *local_file_find_or_create(const struct lu_env *env,
864 struct local_oid_storage *los,
865 struct dt_object *parent,
866 const char *name, __u32 mode);
867struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
868 struct dt_device *dt,
869 const struct lu_fid *fid,
870 struct dt_object *parent,
871 const char *name,
872 __u32 mode);
873struct dt_object *
874local_index_find_or_create(const struct lu_env *env,
875 struct local_oid_storage *los,
876 struct dt_object *parent,
877 const char *name, __u32 mode,
878 const struct dt_index_features *ft);
879struct dt_object *
880local_index_find_or_create_with_fid(const struct lu_env *env,
881 struct dt_device *dt,
882 const struct lu_fid *fid,
883 struct dt_object *parent,
884 const char *name, __u32 mode,
885 const struct dt_index_features *ft);
886int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
887 struct dt_object *parent, const char *name);
888
889static inline int dt_object_lock(const struct lu_env *env,
890 struct dt_object *o, struct lustre_handle *lh,
891 struct ldlm_enqueue_info *einfo,
892 void *policy)
893{
894 LASSERT(o);
895 LASSERT(o->do_ops);
896 LASSERT(o->do_ops->do_object_lock);
897 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
898}
899
900int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
901 const char *name, struct lu_fid *fid);
902
903static inline int dt_object_sync(const struct lu_env *env,
904 struct dt_object *o)
905{
906 LASSERT(o);
907 LASSERT(o->do_ops);
908 LASSERT(o->do_ops->do_object_sync);
909 return o->do_ops->do_object_sync(env, o);
910}
911
912int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
913 struct thandle *th);
914void dt_version_set(const struct lu_env *env, struct dt_object *o,
915 dt_obj_version_t version, struct thandle *th);
916dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
917
918
919int dt_read(const struct lu_env *env, struct dt_object *dt,
920 struct lu_buf *buf, loff_t *pos);
921int dt_record_read(const struct lu_env *env, struct dt_object *dt,
922 struct lu_buf *buf, loff_t *pos);
923int dt_record_write(const struct lu_env *env, struct dt_object *dt,
924 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
925typedef int (*dt_index_page_build_t)(const struct lu_env *env,
926 union lu_page *lp, int nob,
927 const struct dt_it_ops *iops,
928 struct dt_it *it, __u32 attr, void *arg);
929int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
930 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
931 void *arg);
932int dt_index_read(const struct lu_env *env, struct dt_device *dev,
933 struct idx_info *ii, const struct lu_rdpg *rdpg);
934
935static inline struct thandle *dt_trans_create(const struct lu_env *env,
936 struct dt_device *d)
937{
938 LASSERT(d->dd_ops->dt_trans_create);
939 return d->dd_ops->dt_trans_create(env, d);
940}
941
942static inline int dt_trans_start(const struct lu_env *env,
943 struct dt_device *d, struct thandle *th)
944{
945 LASSERT(d->dd_ops->dt_trans_start);
946 return d->dd_ops->dt_trans_start(env, d, th);
947}
948
949
950static inline int dt_trans_start_local(const struct lu_env *env,
951 struct dt_device *d, struct thandle *th)
952{
953 LASSERT(d->dd_ops->dt_trans_start);
954 th->th_local = 1;
955 return d->dd_ops->dt_trans_start(env, d, th);
956}
957
958static inline int dt_trans_stop(const struct lu_env *env,
959 struct dt_device *d, struct thandle *th)
960{
961 LASSERT(d->dd_ops->dt_trans_stop);
962 return d->dd_ops->dt_trans_stop(env, th);
963}
964
965static inline int dt_trans_cb_add(struct thandle *th,
966 struct dt_txn_commit_cb *dcb)
967{
968 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
969 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
970 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
971}
972
973
974
975static inline int dt_declare_record_write(const struct lu_env *env,
976 struct dt_object *dt,
977 int size, loff_t pos,
978 struct thandle *th)
979{
980 int rc;
981
982 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
983 LASSERT(th != NULL);
984 LASSERT(dt->do_body_ops);
985 LASSERT(dt->do_body_ops->dbo_declare_write);
986 rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
987 return rc;
988}
989
990static inline int dt_declare_create(const struct lu_env *env,
991 struct dt_object *dt,
992 struct lu_attr *attr,
993 struct dt_allocation_hint *hint,
994 struct dt_object_format *dof,
995 struct thandle *th)
996{
997 LASSERT(dt);
998 LASSERT(dt->do_ops);
999 LASSERT(dt->do_ops->do_declare_create);
1000 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
1001}
1002
1003static inline int dt_create(const struct lu_env *env,
1004 struct dt_object *dt,
1005 struct lu_attr *attr,
1006 struct dt_allocation_hint *hint,
1007 struct dt_object_format *dof,
1008 struct thandle *th)
1009{
1010 LASSERT(dt);
1011 LASSERT(dt->do_ops);
1012 LASSERT(dt->do_ops->do_create);
1013 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
1014}
1015
1016static inline int dt_declare_destroy(const struct lu_env *env,
1017 struct dt_object *dt,
1018 struct thandle *th)
1019{
1020 LASSERT(dt);
1021 LASSERT(dt->do_ops);
1022 LASSERT(dt->do_ops->do_declare_destroy);
1023 return dt->do_ops->do_declare_destroy(env, dt, th);
1024}
1025
1026static inline int dt_destroy(const struct lu_env *env,
1027 struct dt_object *dt,
1028 struct thandle *th)
1029{
1030 LASSERT(dt);
1031 LASSERT(dt->do_ops);
1032 LASSERT(dt->do_ops->do_destroy);
1033 return dt->do_ops->do_destroy(env, dt, th);
1034}
1035
1036static inline void dt_read_lock(const struct lu_env *env,
1037 struct dt_object *dt,
1038 unsigned role)
1039{
1040 LASSERT(dt);
1041 LASSERT(dt->do_ops);
1042 LASSERT(dt->do_ops->do_read_lock);
1043 dt->do_ops->do_read_lock(env, dt, role);
1044}
1045
1046static inline void dt_write_lock(const struct lu_env *env,
1047 struct dt_object *dt,
1048 unsigned role)
1049{
1050 LASSERT(dt);
1051 LASSERT(dt->do_ops);
1052 LASSERT(dt->do_ops->do_write_lock);
1053 dt->do_ops->do_write_lock(env, dt, role);
1054}
1055
1056static inline void dt_read_unlock(const struct lu_env *env,
1057 struct dt_object *dt)
1058{
1059 LASSERT(dt);
1060 LASSERT(dt->do_ops);
1061 LASSERT(dt->do_ops->do_read_unlock);
1062 dt->do_ops->do_read_unlock(env, dt);
1063}
1064
1065static inline void dt_write_unlock(const struct lu_env *env,
1066 struct dt_object *dt)
1067{
1068 LASSERT(dt);
1069 LASSERT(dt->do_ops);
1070 LASSERT(dt->do_ops->do_write_unlock);
1071 dt->do_ops->do_write_unlock(env, dt);
1072}
1073
1074static inline int dt_write_locked(const struct lu_env *env,
1075 struct dt_object *dt)
1076{
1077 LASSERT(dt);
1078 LASSERT(dt->do_ops);
1079 LASSERT(dt->do_ops->do_write_locked);
1080 return dt->do_ops->do_write_locked(env, dt);
1081}
1082
1083static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
1084 struct lu_attr *la, void *arg)
1085{
1086 LASSERT(dt);
1087 LASSERT(dt->do_ops);
1088 LASSERT(dt->do_ops->do_attr_get);
1089 return dt->do_ops->do_attr_get(env, dt, la, arg);
1090}
1091
1092static inline int dt_declare_attr_set(const struct lu_env *env,
1093 struct dt_object *dt,
1094 const struct lu_attr *la,
1095 struct thandle *th)
1096{
1097 LASSERT(dt);
1098 LASSERT(dt->do_ops);
1099 LASSERT(dt->do_ops->do_declare_attr_set);
1100 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
1101}
1102
1103static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
1104 const struct lu_attr *la, struct thandle *th,
1105 struct lustre_capa *capa)
1106{
1107 LASSERT(dt);
1108 LASSERT(dt->do_ops);
1109 LASSERT(dt->do_ops->do_attr_set);
1110 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
1111}
1112
1113static inline int dt_declare_ref_add(const struct lu_env *env,
1114 struct dt_object *dt, struct thandle *th)
1115{
1116 LASSERT(dt);
1117 LASSERT(dt->do_ops);
1118 LASSERT(dt->do_ops->do_declare_ref_add);
1119 return dt->do_ops->do_declare_ref_add(env, dt, th);
1120}
1121
1122static inline int dt_ref_add(const struct lu_env *env,
1123 struct dt_object *dt, struct thandle *th)
1124{
1125 LASSERT(dt);
1126 LASSERT(dt->do_ops);
1127 LASSERT(dt->do_ops->do_ref_add);
1128 return dt->do_ops->do_ref_add(env, dt, th);
1129}
1130
1131static inline int dt_declare_ref_del(const struct lu_env *env,
1132 struct dt_object *dt, struct thandle *th)
1133{
1134 LASSERT(dt);
1135 LASSERT(dt->do_ops);
1136 LASSERT(dt->do_ops->do_declare_ref_del);
1137 return dt->do_ops->do_declare_ref_del(env, dt, th);
1138}
1139
1140static inline int dt_ref_del(const struct lu_env *env,
1141 struct dt_object *dt, struct thandle *th)
1142{
1143 LASSERT(dt);
1144 LASSERT(dt->do_ops);
1145 LASSERT(dt->do_ops->do_ref_del);
1146 return dt->do_ops->do_ref_del(env, dt, th);
1147}
1148
1149static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1150 struct dt_object *dt,
1151 struct lustre_capa *old, __u64 opc)
1152{
1153 LASSERT(dt);
1154 LASSERT(dt->do_ops);
1155 LASSERT(dt->do_ops->do_ref_del);
1156 return dt->do_ops->do_capa_get(env, dt, old, opc);
1157}
1158
1159static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1160 struct niobuf_remote *rnb,
1161 struct niobuf_local *lnb, int rw,
1162 struct lustre_capa *capa)
1163{
1164 LASSERT(d);
1165 LASSERT(d->do_body_ops);
1166 LASSERT(d->do_body_ops->dbo_bufs_get);
1167 return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1168 rnb->len, lnb, rw, capa);
1169}
1170
1171static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1172 struct niobuf_local *lnb, int n)
1173{
1174 LASSERT(d);
1175 LASSERT(d->do_body_ops);
1176 LASSERT(d->do_body_ops->dbo_bufs_put);
1177 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1178}
1179
1180static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1181 struct niobuf_local *lnb, int n)
1182{
1183 LASSERT(d);
1184 LASSERT(d->do_body_ops);
1185 LASSERT(d->do_body_ops->dbo_write_prep);
1186 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1187}
1188
1189static inline int dt_declare_write_commit(const struct lu_env *env,
1190 struct dt_object *d,
1191 struct niobuf_local *lnb,
1192 int n, struct thandle *th)
1193{
1194 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1195 LASSERT(th != NULL);
1196 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1197}
1198
1199
1200static inline int dt_write_commit(const struct lu_env *env,
1201 struct dt_object *d, struct niobuf_local *lnb,
1202 int n, struct thandle *th)
1203{
1204 LASSERT(d);
1205 LASSERT(d->do_body_ops);
1206 LASSERT(d->do_body_ops->dbo_write_commit);
1207 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1208}
1209
1210static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1211 struct niobuf_local *lnb, int n)
1212{
1213 LASSERT(d);
1214 LASSERT(d->do_body_ops);
1215 LASSERT(d->do_body_ops->dbo_read_prep);
1216 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1217}
1218
1219static inline int dt_declare_punch(const struct lu_env *env,
1220 struct dt_object *dt, __u64 start,
1221 __u64 end, struct thandle *th)
1222{
1223 LASSERT(dt);
1224 LASSERT(dt->do_body_ops);
1225 LASSERT(dt->do_body_ops->dbo_declare_punch);
1226 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
1227}
1228
1229static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1230 __u64 start, __u64 end, struct thandle *th,
1231 struct lustre_capa *capa)
1232{
1233 LASSERT(dt);
1234 LASSERT(dt->do_body_ops);
1235 LASSERT(dt->do_body_ops->dbo_punch);
1236 return dt->do_body_ops->dbo_punch(env, dt, start, end, th, capa);
1237}
1238
1239static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1240 struct ll_user_fiemap *fm)
1241{
1242 LASSERT(d);
1243 if (d->do_body_ops == NULL)
1244 return -EPROTO;
1245 if (d->do_body_ops->dbo_fiemap_get == NULL)
1246 return -EOPNOTSUPP;
1247 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1248}
1249
1250static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1251 struct obd_statfs *osfs)
1252{
1253 LASSERT(dev);
1254 LASSERT(dev->dd_ops);
1255 LASSERT(dev->dd_ops->dt_statfs);
1256 return dev->dd_ops->dt_statfs(env, dev, osfs);
1257}
1258
1259static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1260 struct lu_fid *f)
1261{
1262 LASSERT(dev);
1263 LASSERT(dev->dd_ops);
1264 LASSERT(dev->dd_ops->dt_root_get);
1265 return dev->dd_ops->dt_root_get(env, dev, f);
1266}
1267
1268static inline void dt_conf_get(const struct lu_env *env,
1269 const struct dt_device *dev,
1270 struct dt_device_param *param)
1271{
1272 LASSERT(dev);
1273 LASSERT(dev->dd_ops);
1274 LASSERT(dev->dd_ops->dt_conf_get);
1275 return dev->dd_ops->dt_conf_get(env, dev, param);
1276}
1277
1278static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1279{
1280 LASSERT(dev);
1281 LASSERT(dev->dd_ops);
1282 LASSERT(dev->dd_ops->dt_sync);
1283 return dev->dd_ops->dt_sync(env, dev);
1284}
1285
1286static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1287{
1288 LASSERT(dev);
1289 LASSERT(dev->dd_ops);
1290 LASSERT(dev->dd_ops->dt_ro);
1291 return dev->dd_ops->dt_ro(env, dev);
1292}
1293
1294static inline int dt_declare_insert(const struct lu_env *env,
1295 struct dt_object *dt,
1296 const struct dt_rec *rec,
1297 const struct dt_key *key,
1298 struct thandle *th)
1299{
1300 LASSERT(dt);
1301 LASSERT(dt->do_index_ops);
1302 LASSERT(dt->do_index_ops->dio_declare_insert);
1303 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1304}
1305
1306static inline int dt_insert(const struct lu_env *env,
1307 struct dt_object *dt,
1308 const struct dt_rec *rec,
1309 const struct dt_key *key,
1310 struct thandle *th,
1311 struct lustre_capa *capa,
1312 int noquota)
1313{
1314 LASSERT(dt);
1315 LASSERT(dt->do_index_ops);
1316 LASSERT(dt->do_index_ops->dio_insert);
1317 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1318 capa, noquota);
1319}
1320
1321static inline int dt_declare_xattr_del(const struct lu_env *env,
1322 struct dt_object *dt,
1323 const char *name,
1324 struct thandle *th)
1325{
1326 LASSERT(dt);
1327 LASSERT(dt->do_ops);
1328 LASSERT(dt->do_ops->do_declare_xattr_del);
1329 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1330}
1331
1332static inline int dt_xattr_del(const struct lu_env *env,
1333 struct dt_object *dt, const char *name,
1334 struct thandle *th,
1335 struct lustre_capa *capa)
1336{
1337 LASSERT(dt);
1338 LASSERT(dt->do_ops);
1339 LASSERT(dt->do_ops->do_xattr_del);
1340 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1341}
1342
1343static inline int dt_declare_xattr_set(const struct lu_env *env,
1344 struct dt_object *dt,
1345 const struct lu_buf *buf,
1346 const char *name, int fl,
1347 struct thandle *th)
1348{
1349 LASSERT(dt);
1350 LASSERT(dt->do_ops);
1351 LASSERT(dt->do_ops->do_declare_xattr_set);
1352 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1353}
1354
1355static inline int dt_xattr_set(const struct lu_env *env,
1356 struct dt_object *dt, const struct lu_buf *buf,
1357 const char *name, int fl, struct thandle *th,
1358 struct lustre_capa *capa)
1359{
1360 LASSERT(dt);
1361 LASSERT(dt->do_ops);
1362 LASSERT(dt->do_ops->do_xattr_set);
1363 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1364}
1365
1366static inline int dt_xattr_get(const struct lu_env *env,
1367 struct dt_object *dt, struct lu_buf *buf,
1368 const char *name, struct lustre_capa *capa)
1369{
1370 LASSERT(dt);
1371 LASSERT(dt->do_ops);
1372 LASSERT(dt->do_ops->do_xattr_get);
1373 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1374}
1375
1376static inline int dt_xattr_list(const struct lu_env *env,
1377 struct dt_object *dt, struct lu_buf *buf,
1378 struct lustre_capa *capa)
1379{
1380 LASSERT(dt);
1381 LASSERT(dt->do_ops);
1382 LASSERT(dt->do_ops->do_xattr_list);
1383 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1384}
1385
1386static inline int dt_declare_delete(const struct lu_env *env,
1387 struct dt_object *dt,
1388 const struct dt_key *key,
1389 struct thandle *th)
1390{
1391 LASSERT(dt);
1392 LASSERT(dt->do_index_ops);
1393 LASSERT(dt->do_index_ops->dio_declare_delete);
1394 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1395}
1396
1397static inline int dt_delete(const struct lu_env *env,
1398 struct dt_object *dt,
1399 const struct dt_key *key,
1400 struct thandle *th,
1401 struct lustre_capa *capa)
1402{
1403 LASSERT(dt);
1404 LASSERT(dt->do_index_ops);
1405 LASSERT(dt->do_index_ops->dio_delete);
1406 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1407}
1408
1409static inline int dt_commit_async(const struct lu_env *env,
1410 struct dt_device *dev)
1411{
1412 LASSERT(dev);
1413 LASSERT(dev->dd_ops);
1414 LASSERT(dev->dd_ops->dt_commit_async);
1415 return dev->dd_ops->dt_commit_async(env, dev);
1416}
1417
1418static inline int dt_init_capa_ctxt(const struct lu_env *env,
1419 struct dt_device *dev,
1420 int mode, unsigned long timeout,
1421 __u32 alg, struct lustre_capa_key *keys)
1422{
1423 LASSERT(dev);
1424 LASSERT(dev->dd_ops);
1425 LASSERT(dev->dd_ops->dt_init_capa_ctxt);
1426 return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
1427 timeout, alg, keys);
1428}
1429
1430static inline int dt_lookup(const struct lu_env *env,
1431 struct dt_object *dt,
1432 struct dt_rec *rec,
1433 const struct dt_key *key,
1434 struct lustre_capa *capa)
1435{
1436 int ret;
1437
1438 LASSERT(dt);
1439 LASSERT(dt->do_index_ops);
1440 LASSERT(dt->do_index_ops->dio_lookup);
1441
1442 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1443 if (ret > 0)
1444 ret = 0;
1445 else if (ret == 0)
1446 ret = -ENOENT;
1447 return ret;
1448}
1449
1450#define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1451
1452struct dt_find_hint {
1453 struct lu_fid *dfh_fid;
1454 struct dt_device *dfh_dt;
1455 struct dt_object *dfh_o;
1456};
1457
1458struct dt_thread_info {
1459 char dti_buf[DT_MAX_PATH];
1460 struct dt_find_hint dti_dfh;
1461 struct lu_attr dti_attr;
1462 struct lu_fid dti_fid;
1463 struct dt_object_format dti_dof;
1464 struct lustre_mdt_attrs dti_lma;
1465 struct lu_buf dti_lb;
1466 loff_t dti_off;
1467};
1468
1469extern struct lu_context_key dt_key;
1470
1471static inline struct dt_thread_info *dt_info(const struct lu_env *env)
1472{
1473 struct dt_thread_info *dti;
1474
1475 dti = lu_context_key_get(&env->le_ctx, &dt_key);
1476 LASSERT(dti);
1477 return dti;
1478}
1479
1480int dt_global_init(void);
1481void dt_global_fini(void);
1482
1483# ifdef LPROCFS
1484int lprocfs_dt_rd_blksize(char *page, char **start, off_t off,
1485 int count, int *eof, void *data);
1486int lprocfs_dt_rd_kbytestotal(char *page, char **start, off_t off,
1487 int count, int *eof, void *data);
1488int lprocfs_dt_rd_kbytesfree(char *page, char **start, off_t off,
1489 int count, int *eof, void *data);
1490int lprocfs_dt_rd_kbytesavail(char *page, char **start, off_t off,
1491 int count, int *eof, void *data);
1492int lprocfs_dt_rd_filestotal(char *page, char **start, off_t off,
1493 int count, int *eof, void *data);
1494int lprocfs_dt_rd_filesfree(char *page, char **start, off_t off,
1495 int count, int *eof, void *data);
1496# endif
1497
1498#endif
1499