Whamcloud - gitweb
e93ae43268cc49a27036fadfa095ab4de65a024a
[fs/lustre-release.git] / lustre / include / dt_object.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef __LUSTRE_DT_OBJECT_H
38 #define __LUSTRE_DT_OBJECT_H
39
40 /** \defgroup dt dt
41  * Sub-class of lu_object with methods common for "data" objects in OST stack.
42  *
43  * Data objects behave like regular files: you can read/write them, get and
44  * set their attributes. Implementation of dt interface is supposed to
45  * implement some form of garbage collection, normally reference counting
46  * (nlink) based one.
47  *
48  * Examples: osd (lustre/osd) is an implementation of dt interface.
49  * @{
50  */
51
52
53 /*
54  * super-class definitions.
55  */
56 #include <lu_object.h>
57
58 #include <libcfs/libcfs.h>
59
60 struct seq_file;
61 struct proc_dir_entry;
62 struct lustre_cfg;
63
64 struct thandle;
65 struct dt_device;
66 struct dt_object;
67 struct dt_index_features;
68 struct niobuf_local;
69 struct niobuf_remote;
70 struct ldlm_enqueue_info;
71
72 typedef enum {
73         MNTOPT_USERXATTR        = 0x00000001,
74         MNTOPT_ACL              = 0x00000002,
75 } mntopt_t;
76
77 struct 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         int                ddp_mount_type;
84         unsigned long long ddp_maxbytes;
85         /* percentage of available space to reserve for grant error margin */
86         int                ddp_grant_reserved;
87         /* per-inode space consumption */
88         short              ddp_inodespace;
89         /* per-fragment grant overhead to be used by client for grant
90          * calculation */
91         int                ddp_grant_frag;
92 };
93
94 /**
95  * Per-transaction commit callback function
96  */
97 struct dt_txn_commit_cb;
98 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
99                         struct dt_txn_commit_cb *cb, int err);
100 /**
101  * Special per-transaction callback for cases when just commit callback
102  * is needed and per-device callback are not convenient to use
103  */
104 #define TRANS_COMMIT_CB_MAGIC   0xa0a00a0a
105 #define MAX_COMMIT_CB_STR_LEN   32
106
107 struct dt_txn_commit_cb {
108         cfs_list_t      dcb_linkage;
109         dt_cb_t         dcb_func;
110         __u32           dcb_magic;
111         char            dcb_name[MAX_COMMIT_CB_STR_LEN];
112 };
113
114 /**
115  * Operations on dt device.
116  */
117 struct dt_device_operations {
118         /**
119          * Return device-wide statistics.
120          */
121         int   (*dt_statfs)(const struct lu_env *env,
122                            struct dt_device *dev, struct obd_statfs *osfs);
123         /**
124          * Create transaction, described by \a param.
125          */
126         struct thandle *(*dt_trans_create)(const struct lu_env *env,
127                                            struct dt_device *dev);
128         /**
129          * Start transaction, described by \a param.
130          */
131         int   (*dt_trans_start)(const struct lu_env *env,
132                                 struct dt_device *dev, struct thandle *th);
133         /**
134          * Finish previously started transaction.
135          */
136         int   (*dt_trans_stop)(const struct lu_env *env,
137                                struct thandle *th);
138         /**
139          * Add commit callback to the transaction.
140          */
141         int   (*dt_trans_cb_add)(struct thandle *th,
142                                  struct dt_txn_commit_cb *dcb);
143         /**
144          * Return fid of root index object.
145          */
146         int   (*dt_root_get)(const struct lu_env *env,
147                              struct dt_device *dev, struct lu_fid *f);
148         /**
149          * Return device configuration data.
150          */
151         void  (*dt_conf_get)(const struct lu_env *env,
152                              const struct dt_device *dev,
153                              struct dt_device_param *param);
154         /**
155          *  handling device state, mostly for tests
156          */
157         int   (*dt_sync)(const struct lu_env *env, struct dt_device *dev);
158         int   (*dt_ro)(const struct lu_env *env, struct dt_device *dev);
159         /**
160           * Start a transaction commit asynchronously
161           *
162           * \param env environment
163           * \param dev dt_device to start commit on
164           *
165           * \return 0 success, negative value if error
166           */
167          int   (*dt_commit_async)(const struct lu_env *env,
168                                   struct dt_device *dev);
169         /**
170          * Initialize capability context.
171          */
172         int   (*dt_init_capa_ctxt)(const struct lu_env *env,
173                                    struct dt_device *dev,
174                                    int mode, unsigned long timeout,
175                                    __u32 alg, struct lustre_capa_key *keys);
176 };
177
178 struct dt_index_features {
179         /** required feature flags from enum dt_index_flags */
180         __u32 dif_flags;
181         /** minimal required key size */
182         size_t dif_keysize_min;
183         /** maximal required key size, 0 if no limit */
184         size_t dif_keysize_max;
185         /** minimal required record size */
186         size_t dif_recsize_min;
187         /** maximal required record size, 0 if no limit */
188         size_t dif_recsize_max;
189         /** pointer size for record */
190         size_t dif_ptrsize;
191 };
192
193 enum dt_index_flags {
194         /** index supports variable sized keys */
195         DT_IND_VARKEY = 1 << 0,
196         /** index supports variable sized records */
197         DT_IND_VARREC = 1 << 1,
198         /** index can be modified */
199         DT_IND_UPDATE = 1 << 2,
200         /** index supports records with non-unique (duplicate) keys */
201         DT_IND_NONUNQ = 1 << 3,
202         /**
203          * index support fixed-size keys sorted with natural numerical way
204          * and is able to return left-side value if no exact value found
205          */
206         DT_IND_RANGE = 1 << 4,
207 };
208
209 /**
210  * Features, required from index to support file system directories (mapping
211  * names to fids).
212  */
213 extern const struct dt_index_features dt_directory_features;
214 extern const struct dt_index_features dt_otable_features;
215 extern const struct dt_index_features dt_lfsck_features;
216
217 /* index features supported by the accounting objects */
218 extern const struct dt_index_features dt_acct_features;
219
220 /* index features supported by the quota global indexes */
221 extern const struct dt_index_features dt_quota_glb_features;
222
223 /* index features supported by the quota slave indexes */
224 extern const struct dt_index_features dt_quota_slv_features;
225
226 /**
227  * This is a general purpose dt allocation hint.
228  * It now contains the parent object.
229  * It can contain any allocation hint in the future.
230  */
231 struct dt_allocation_hint {
232         struct dt_object           *dah_parent;
233         __u32                       dah_mode;
234 };
235
236 /**
237  * object type specifier.
238  */
239
240 enum dt_format_type {
241         DFT_REGULAR,
242         DFT_DIR,
243         /** for mknod */
244         DFT_NODE,
245         /** for special index */
246         DFT_INDEX,
247         /** for symbolic link */
248         DFT_SYM,
249 };
250
251 /**
252  * object format specifier.
253  */
254 struct dt_object_format {
255         /** type for dt object */
256         enum dt_format_type dof_type;
257         union {
258                 struct dof_regular {
259                         int striped;
260                 } dof_reg;
261                 struct dof_dir {
262                 } dof_dir;
263                 struct dof_node {
264                 } dof_node;
265                 /**
266                  * special index need feature as parameter to create
267                  * special idx
268                  */
269                 struct dof_index {
270                         const struct dt_index_features *di_feat;
271                 } dof_idx;
272         } u;
273 };
274
275 enum dt_format_type dt_mode_to_dft(__u32 mode);
276
277 typedef __u64 dt_obj_version_t;
278
279 /**
280  * Per-dt-object operations.
281  */
282 struct dt_object_operations {
283         void  (*do_read_lock)(const struct lu_env *env,
284                               struct dt_object *dt, unsigned role);
285         void  (*do_write_lock)(const struct lu_env *env,
286                                struct dt_object *dt, unsigned role);
287         void  (*do_read_unlock)(const struct lu_env *env,
288                                 struct dt_object *dt);
289         void  (*do_write_unlock)(const struct lu_env *env,
290                                  struct dt_object *dt);
291         int  (*do_write_locked)(const struct lu_env *env,
292                                 struct dt_object *dt);
293         /**
294          * Note: following ->do_{x,}attr_{set,get}() operations are very
295          * similar to ->moo_{x,}attr_{set,get}() operations in struct
296          * md_object_operations (see md_object.h). These operations are not in
297          * lu_object_operations, because ->do_{x,}attr_set() versions take
298          * transaction handle as an argument (this transaction is started by
299          * caller). We might factor ->do_{x,}attr_get() into
300          * lu_object_operations, but that would break existing symmetry.
301          */
302
303         /**
304          * Return standard attributes.
305          *
306          * precondition: lu_object_exists(&dt->do_lu);
307          */
308         int   (*do_attr_get)(const struct lu_env *env,
309                              struct dt_object *dt, struct lu_attr *attr,
310                              struct lustre_capa *capa);
311         /**
312          * Set standard attributes.
313          *
314          * precondition: dt_object_exists(dt);
315          */
316         int   (*do_declare_attr_set)(const struct lu_env *env,
317                                      struct dt_object *dt,
318                                      const struct lu_attr *attr,
319                                      struct thandle *handle);
320         int   (*do_attr_set)(const struct lu_env *env,
321                              struct dt_object *dt,
322                              const struct lu_attr *attr,
323                              struct thandle *handle,
324                              struct lustre_capa *capa);
325         /**
326          * Return a value of an extended attribute.
327          *
328          * precondition: dt_object_exists(dt);
329          */
330         int   (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
331                               struct lu_buf *buf, const char *name,
332                               struct lustre_capa *capa);
333         /**
334          * Set value of an extended attribute.
335          *
336          * \a fl - flags from enum lu_xattr_flags
337          *
338          * precondition: dt_object_exists(dt);
339          */
340         int   (*do_declare_xattr_set)(const struct lu_env *env,
341                                       struct dt_object *dt,
342                                       const struct lu_buf *buf,
343                                       const char *name, int fl,
344                                       struct thandle *handle);
345         int   (*do_xattr_set)(const struct lu_env *env,
346                               struct dt_object *dt, const struct lu_buf *buf,
347                               const char *name, int fl, struct thandle *handle,
348                               struct lustre_capa *capa);
349         /**
350          * Delete existing extended attribute.
351          *
352          * precondition: dt_object_exists(dt);
353          */
354         int   (*do_declare_xattr_del)(const struct lu_env *env,
355                                       struct dt_object *dt,
356                                       const char *name, struct thandle *handle);
357         int   (*do_xattr_del)(const struct lu_env *env,
358                               struct dt_object *dt,
359                               const char *name, struct thandle *handle,
360                               struct lustre_capa *capa);
361         /**
362          * Place list of existing extended attributes into \a buf (which has
363          * length len).
364          *
365          * precondition: dt_object_exists(dt);
366          */
367         int   (*do_xattr_list)(const struct lu_env *env,
368                                struct dt_object *dt, struct lu_buf *buf,
369                                struct lustre_capa *capa);
370         /**
371          * Init allocation hint using parent object and child mode.
372          * (1) The \a parent might be NULL if this is a partial creation for
373          *     remote object.
374          * (2) The type of child is in \a child_mode.
375          * (3) The result hint is stored in \a ah;
376          */
377         void  (*do_ah_init)(const struct lu_env *env,
378                             struct dt_allocation_hint *ah,
379                             struct dt_object *parent,
380                             struct dt_object *child,
381                             umode_t child_mode);
382         /**
383          * Create new object on this device.
384          *
385          * precondition: !dt_object_exists(dt);
386          * postcondition: ergo(result == 0, dt_object_exists(dt));
387          */
388         int   (*do_declare_create)(const struct lu_env *env,
389                                    struct dt_object *dt,
390                                    struct lu_attr *attr,
391                                    struct dt_allocation_hint *hint,
392                                    struct dt_object_format *dof,
393                                    struct thandle *th);
394         int   (*do_create)(const struct lu_env *env, struct dt_object *dt,
395                            struct lu_attr *attr,
396                            struct dt_allocation_hint *hint,
397                            struct dt_object_format *dof,
398                            struct thandle *th);
399
400         /**
401           Destroy object on this device
402          * precondition: !dt_object_exists(dt);
403          * postcondition: ergo(result == 0, dt_object_exists(dt));
404          */
405         int   (*do_declare_destroy)(const struct lu_env *env,
406                                     struct dt_object *dt,
407                                     struct thandle *th);
408         int   (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
409                             struct thandle *th);
410
411         /**
412          * Announce that this object is going to be used as an index. This
413          * operation check that object supports indexing operations and
414          * installs appropriate dt_index_operations vector on success.
415          *
416          * Also probes for features. Operation is successful if all required
417          * features are supported.
418          */
419         int   (*do_index_try)(const struct lu_env *env,
420                               struct dt_object *dt,
421                               const struct dt_index_features *feat);
422         /**
423          * Add nlink of the object
424          * precondition: dt_object_exists(dt);
425          */
426         int   (*do_declare_ref_add)(const struct lu_env *env,
427                                     struct dt_object *dt, struct thandle *th);
428         int   (*do_ref_add)(const struct lu_env *env,
429                             struct dt_object *dt, struct thandle *th);
430         /**
431          * Del nlink of the object
432          * precondition: dt_object_exists(dt);
433          */
434         int   (*do_declare_ref_del)(const struct lu_env *env,
435                                     struct dt_object *dt, struct thandle *th);
436         int   (*do_ref_del)(const struct lu_env *env,
437                             struct dt_object *dt, struct thandle *th);
438
439         struct obd_capa *(*do_capa_get)(const struct lu_env *env,
440                                         struct dt_object *dt,
441                                         struct lustre_capa *old,
442                                         __u64 opc);
443         int (*do_object_sync)(const struct lu_env *, struct dt_object *);
444         /**
445          * Get object info of next level. Currently, only get inode from osd.
446          * This is only used by quota b=16542
447          * precondition: dt_object_exists(dt);
448          */
449         int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
450                            void **data);
451
452         /**
453          * Lock object.
454          */
455         int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
456                               struct lustre_handle *lh,
457                               struct ldlm_enqueue_info *einfo,
458                               void *policy);
459 };
460
461 /**
462  * Per-dt-object operations on "file body".
463  */
464 struct dt_body_operations {
465         /**
466          * precondition: dt_object_exists(dt);
467          */
468         ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
469                             struct lu_buf *buf, loff_t *pos,
470                             struct lustre_capa *capa);
471         /**
472          * precondition: dt_object_exists(dt);
473          */
474         ssize_t (*dbo_declare_write)(const struct lu_env *env,
475                                      struct dt_object *dt,
476                                      const loff_t size, loff_t pos,
477                                      struct thandle *handle);
478         ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
479                              const struct lu_buf *buf, loff_t *pos,
480                              struct thandle *handle, struct lustre_capa *capa,
481                              int ignore_quota);
482         /*
483          * methods for zero-copy IO
484          */
485
486         /*
487          * precondition: dt_object_exists(dt);
488          * returns:
489          * < 0 - error code
490          * = 0 - illegal
491          * > 0 - number of local buffers prepared
492          */
493         int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
494                             loff_t pos, ssize_t len, struct niobuf_local *lb,
495                             int rw, struct lustre_capa *capa);
496         /*
497          * precondition: dt_object_exists(dt);
498          */
499         int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
500                             struct niobuf_local *lb, int nr);
501         /*
502          * precondition: dt_object_exists(dt);
503          */
504         int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
505                               struct niobuf_local *lb, int nr);
506         /*
507          * precondition: dt_object_exists(dt);
508          */
509         int (*dbo_declare_write_commit)(const struct lu_env *env,
510                                         struct dt_object *dt,
511                                         struct niobuf_local *,
512                                         int, struct thandle *);
513         /*
514          * precondition: dt_object_exists(dt);
515          */
516         int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
517                                 struct niobuf_local *, int, struct thandle *);
518         /*
519          * precondition: dt_object_exists(dt);
520          */
521         int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
522                              struct niobuf_local *lnb, int nr);
523         int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
524                               struct ll_user_fiemap *fm);
525         /**
526          * Punch object's content
527          * precondition: regular object, not index
528          */
529         int   (*dbo_declare_punch)(const struct lu_env *, struct dt_object *,
530                                   __u64, __u64, struct thandle *th);
531         int   (*dbo_punch)(const struct lu_env *env, struct dt_object *dt,
532                           __u64 start, __u64 end, struct thandle *th,
533                           struct lustre_capa *capa);
534 };
535
536 /**
537  * Incomplete type of index record.
538  */
539 struct dt_rec;
540
541 /**
542  * Incomplete type of index key.
543  */
544 struct dt_key;
545
546 /**
547  * Incomplete type of dt iterator.
548  */
549 struct dt_it;
550
551 /**
552  * Per-dt-object operations on object as index.
553  */
554 struct dt_index_operations {
555         /**
556          * precondition: dt_object_exists(dt);
557          */
558         int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
559                           struct dt_rec *rec, const struct dt_key *key,
560                           struct lustre_capa *capa);
561         /**
562          * precondition: dt_object_exists(dt);
563          */
564         int (*dio_declare_insert)(const struct lu_env *env,
565                                   struct dt_object *dt,
566                                   const struct dt_rec *rec,
567                                   const struct dt_key *key,
568                                   struct thandle *handle);
569         int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
570                           const struct dt_rec *rec, const struct dt_key *key,
571                           struct thandle *handle, struct lustre_capa *capa,
572                           int ignore_quota);
573         /**
574          * precondition: dt_object_exists(dt);
575          */
576         int (*dio_declare_delete)(const struct lu_env *env,
577                                   struct dt_object *dt,
578                                   const struct dt_key *key,
579                                   struct thandle *handle);
580         int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
581                           const struct dt_key *key, struct thandle *handle,
582                           struct lustre_capa *capa);
583         /**
584          * Iterator interface
585          */
586         struct dt_it_ops {
587                 /**
588                  * Allocate and initialize new iterator.
589                  *
590                  * precondition: dt_object_exists(dt);
591                  */
592                 struct dt_it *(*init)(const struct lu_env *env,
593                                       struct dt_object *dt,
594                                       __u32 attr,
595                                       struct lustre_capa *capa);
596                 void          (*fini)(const struct lu_env *env,
597                                       struct dt_it *di);
598                 int            (*get)(const struct lu_env *env,
599                                       struct dt_it *di,
600                                       const struct dt_key *key);
601                 void           (*put)(const struct lu_env *env,
602                                       struct dt_it *di);
603                 int           (*next)(const struct lu_env *env,
604                                       struct dt_it *di);
605                 struct dt_key *(*key)(const struct lu_env *env,
606                                       const struct dt_it *di);
607                 int       (*key_size)(const struct lu_env *env,
608                                       const struct dt_it *di);
609                 int            (*rec)(const struct lu_env *env,
610                                       const struct dt_it *di,
611                                       struct dt_rec *rec,
612                                       __u32 attr);
613                 __u64        (*store)(const struct lu_env *env,
614                                       const struct dt_it *di);
615                 int           (*load)(const struct lu_env *env,
616                                       const struct dt_it *di, __u64 hash);
617                 int        (*key_rec)(const struct lu_env *env,
618                                       const struct dt_it *di, void* key_rec);
619         } dio_it;
620 };
621
622 enum dt_otable_it_valid {
623         DOIV_ERROR_HANDLE       = 0x0001,
624         DOIV_DRYRUN             = 0x0002,
625 };
626
627 enum dt_otable_it_flags {
628         /* Exit when fail. */
629         DOIF_FAILOUT    = 0x0001,
630
631         /* Reset iteration position to the device beginning. */
632         DOIF_RESET      = 0x0002,
633
634         /* There is up layer component uses the iteration. */
635         DOIF_OUTUSED    = 0x0004,
636
637         /* Check only without repairing. */
638         DOIF_DRYRUN     = 0x0008,
639 };
640
641 /* otable based iteration needs to use the common DT interation APIs.
642  * To initialize the iteration, it needs call dio_it::init() firstly.
643  * Here is how the otable based iteration should prepare arguments to
644  * call dt_it_ops::init().
645  *
646  * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
647  * is composed of two parts:
648  * low 16-bits is for valid bits, high 16-bits is for flags bits. */
649 #define DT_OTABLE_IT_FLAGS_SHIFT        16
650 #define DT_OTABLE_IT_FLAGS_MASK         0xffff0000
651
652 struct dt_device {
653         struct lu_device                   dd_lu_dev;
654         const struct dt_device_operations *dd_ops;
655
656         /**
657          * List of dt_txn_callback (see below). This is not protected in any
658          * way, because callbacks are supposed to be added/deleted only during
659          * single-threaded start-up shut-down procedures.
660          */
661         cfs_list_t                         dd_txn_callbacks;
662 };
663
664 int  dt_device_init(struct dt_device *dev, struct lu_device_type *t);
665 void dt_device_fini(struct dt_device *dev);
666
667 static inline int lu_device_is_dt(const struct lu_device *d)
668 {
669         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
670 }
671
672 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
673 {
674         LASSERT(lu_device_is_dt(l));
675         return container_of0(l, struct dt_device, dd_lu_dev);
676 }
677
678 struct dt_object {
679         struct lu_object                   do_lu;
680         const struct dt_object_operations *do_ops;
681         const struct dt_body_operations   *do_body_ops;
682         const struct dt_index_operations  *do_index_ops;
683 };
684
685 /*
686  * In-core representation of per-device local object OID storage
687  */
688 struct local_oid_storage {
689         /* all initialized llog systems on this node linked by this */
690         cfs_list_t        los_list;
691
692         /* how many handle's reference this los has */
693         atomic_t          los_refcount;
694         struct dt_device *los_dev;
695         struct dt_object *los_obj;
696
697         /* data used to generate new fids */
698         struct mutex      los_id_lock;
699         __u64             los_seq;
700         __u32             los_last_oid;
701 };
702
703 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
704 {
705         return &d->dd_lu_dev;
706 }
707
708 static inline struct dt_object *lu2dt(struct lu_object *l)
709 {
710         LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
711         return container_of0(l, struct dt_object, do_lu);
712 }
713
714 int  dt_object_init(struct dt_object *obj,
715                     struct lu_object_header *h, struct lu_device *d);
716
717 void dt_object_fini(struct dt_object *obj);
718
719 static inline int dt_object_exists(const struct dt_object *dt)
720 {
721         return lu_object_exists(&dt->do_lu);
722 }
723
724 static inline int dt_object_remote(const struct dt_object *dt)
725 {
726         return lu_object_remote(&dt->do_lu);
727 }
728
729 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
730 {
731         LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
732         return container_of0(o, struct dt_object, do_lu);
733 }
734
735 /**
736  * This is the general purpose transaction handle.
737  * 1. Transaction Life Cycle
738  *      This transaction handle is allocated upon starting a new transaction,
739  *      and deallocated after this transaction is committed.
740  * 2. Transaction Nesting
741  *      We do _NOT_ support nested transaction. So, every thread should only
742  *      have one active transaction, and a transaction only belongs to one
743  *      thread. Due to this, transaction handle need no reference count.
744  * 3. Transaction & dt_object locking
745  *      dt_object locks should be taken inside transaction.
746  * 4. Transaction & RPC
747  *      No RPC request should be issued inside transaction.
748  */
749 struct thandle {
750         /** the dt device on which the transactions are executed */
751         struct dt_device *th_dev;
752
753         /** context for this transaction, tag is LCT_TX_HANDLE */
754         struct lu_context th_ctx;
755
756         /** additional tags (layers can add in declare) */
757         __u32             th_tags;
758
759         /** the last operation result in this transaction.
760          * this value is used in recovery */
761         __s32             th_result;
762
763         /** whether we need sync commit */
764         unsigned int            th_sync:1;
765
766         /* local transation, no need to inform other layers */
767         unsigned int            th_local:1;
768
769         /* In DNE, one transaction can be disassemblied into
770          * updates on several different MDTs, and these updates
771          * will be attached to th_remote_update_list per target.
772          * Only single thread will access the list, no need lock
773          */
774         cfs_list_t              th_remote_update_list;
775         struct update_request   *th_current_request;
776 };
777
778 /**
779  * Transaction call-backs.
780  *
781  * These are invoked by osd (or underlying transaction engine) when
782  * transaction changes state.
783  *
784  * Call-backs are used by upper layers to modify transaction parameters and to
785  * perform some actions on for each transaction state transition. Typical
786  * example is mdt registering call-back to write into last-received file
787  * before each transaction commit.
788  */
789 struct dt_txn_callback {
790         int (*dtc_txn_start)(const struct lu_env *env,
791                              struct thandle *txn, void *cookie);
792         int (*dtc_txn_stop)(const struct lu_env *env,
793                             struct thandle *txn, void *cookie);
794         void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
795         void                *dtc_cookie;
796         __u32                dtc_tag;
797         cfs_list_t           dtc_linkage;
798 };
799
800 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
801 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
802
803 int dt_txn_hook_start(const struct lu_env *env,
804                       struct dt_device *dev, struct thandle *txn);
805 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
806 void dt_txn_hook_commit(struct thandle *txn);
807
808 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
809
810 /**
811  * Callback function used for parsing path.
812  * \see llo_store_resolve
813  */
814 typedef int (*dt_entry_func_t)(const struct lu_env *env,
815                             const char *name,
816                             void *pvt);
817
818 #define DT_MAX_PATH 1024
819
820 int dt_path_parser(const struct lu_env *env,
821                    char *local, dt_entry_func_t entry_func,
822                    void *data);
823
824 struct dt_object *
825 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
826                  const char *path, struct lu_fid *fid);
827
828 struct dt_object *dt_store_open(const struct lu_env *env,
829                                 struct dt_device *dt,
830                                 const char *dirname,
831                                 const char *filename,
832                                 struct lu_fid *fid);
833
834 struct dt_object *dt_find_or_create(const struct lu_env *env,
835                                     struct dt_device *dt,
836                                     const struct lu_fid *fid,
837                                     struct dt_object_format *dof,
838                                     struct lu_attr *attr);
839
840 struct dt_object *dt_locate_at(const struct lu_env *env,
841                                struct dt_device *dev,
842                                const struct lu_fid *fid,
843                                struct lu_device *top_dev,
844                                const struct lu_object_conf *conf);
845
846 static inline struct dt_object *
847 dt_locate(const struct lu_env *env, struct dt_device *dev,
848           const struct lu_fid *fid)
849 {
850         return dt_locate_at(env, dev, fid,
851                             dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
852 }
853
854 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
855                            const struct lu_fid *first_fid,
856                            struct local_oid_storage **los);
857 void local_oid_storage_fini(const struct lu_env *env,
858                             struct local_oid_storage *los);
859 int local_object_fid_generate(const struct lu_env *env,
860                               struct local_oid_storage *los,
861                               struct lu_fid *fid);
862 int local_object_declare_create(const struct lu_env *env,
863                                 struct local_oid_storage *los,
864                                 struct dt_object *o,
865                                 struct lu_attr *attr,
866                                 struct dt_object_format *dof,
867                                 struct thandle *th);
868 int local_object_create(const struct lu_env *env,
869                         struct local_oid_storage *los,
870                         struct dt_object *o,
871                         struct lu_attr *attr, struct dt_object_format *dof,
872                         struct thandle *th);
873 struct dt_object *local_file_find_or_create(const struct lu_env *env,
874                                             struct local_oid_storage *los,
875                                             struct dt_object *parent,
876                                             const char *name, __u32 mode);
877 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
878                                                      struct dt_device *dt,
879                                                      const struct lu_fid *fid,
880                                                      struct dt_object *parent,
881                                                      const char *name,
882                                                      __u32 mode);
883 struct dt_object *
884 local_index_find_or_create(const struct lu_env *env,
885                            struct local_oid_storage *los,
886                            struct dt_object *parent,
887                            const char *name, __u32 mode,
888                            const struct dt_index_features *ft);
889 struct dt_object *
890 local_index_find_or_create_with_fid(const struct lu_env *env,
891                                     struct dt_device *dt,
892                                     const struct lu_fid *fid,
893                                     struct dt_object *parent,
894                                     const char *name, __u32 mode,
895                                     const struct dt_index_features *ft);
896 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
897                         struct dt_object *parent, const char *name);
898
899 static inline int dt_object_lock(const struct lu_env *env,
900                                  struct dt_object *o, struct lustre_handle *lh,
901                                  struct ldlm_enqueue_info *einfo,
902                                  void *policy)
903 {
904         LASSERT(o);
905         LASSERT(o->do_ops);
906         LASSERT(o->do_ops->do_object_lock);
907         return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
908 }
909
910 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
911                   const char *name, struct lu_fid *fid);
912
913 static inline int dt_object_sync(const struct lu_env *env,
914                                  struct dt_object *o)
915 {
916         LASSERT(o);
917         LASSERT(o->do_ops);
918         LASSERT(o->do_ops->do_object_sync);
919         return o->do_ops->do_object_sync(env, o);
920 }
921
922 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
923                            struct thandle *th);
924 void dt_version_set(const struct lu_env *env, struct dt_object *o,
925                     dt_obj_version_t version, struct thandle *th);
926 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
927
928
929 int dt_read(const struct lu_env *env, struct dt_object *dt,
930             struct lu_buf *buf, loff_t *pos);
931 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
932                    struct lu_buf *buf, loff_t *pos);
933 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
934                     const struct lu_buf *buf, loff_t *pos, struct thandle *th);
935 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
936                                      union lu_page *lp, int nob,
937                                      const struct dt_it_ops *iops,
938                                      struct dt_it *it, __u32 attr, void *arg);
939 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
940                   const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
941                   void *arg);
942 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
943                   struct idx_info *ii, const struct lu_rdpg *rdpg);
944
945 static inline struct thandle *dt_trans_create(const struct lu_env *env,
946                                               struct dt_device *d)
947 {
948         LASSERT(d->dd_ops->dt_trans_create);
949         return d->dd_ops->dt_trans_create(env, d);
950 }
951
952 static inline int dt_trans_start(const struct lu_env *env,
953                                  struct dt_device *d, struct thandle *th)
954 {
955         LASSERT(d->dd_ops->dt_trans_start);
956         return d->dd_ops->dt_trans_start(env, d, th);
957 }
958
959 /* for this transaction hooks shouldn't be called */
960 static inline int dt_trans_start_local(const struct lu_env *env,
961                                        struct dt_device *d, struct thandle *th)
962 {
963         LASSERT(d->dd_ops->dt_trans_start);
964         th->th_local = 1;
965         return d->dd_ops->dt_trans_start(env, d, th);
966 }
967
968 static inline int dt_trans_stop(const struct lu_env *env,
969                                 struct dt_device *d, struct thandle *th)
970 {
971         LASSERT(d->dd_ops->dt_trans_stop);
972         return d->dd_ops->dt_trans_stop(env, th);
973 }
974
975 static inline int dt_trans_cb_add(struct thandle *th,
976                                   struct dt_txn_commit_cb *dcb)
977 {
978         LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
979         dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
980         return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
981 }
982 /** @} dt */
983
984
985 static inline int dt_declare_record_write(const struct lu_env *env,
986                                           struct dt_object *dt,
987                                           int size, loff_t pos,
988                                           struct thandle *th)
989 {
990         int rc;
991
992         LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
993         LASSERT(th != NULL);
994         LASSERT(dt->do_body_ops);
995         LASSERT(dt->do_body_ops->dbo_declare_write);
996         rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
997         return rc;
998 }
999
1000 static inline int dt_declare_create(const struct lu_env *env,
1001                                     struct dt_object *dt,
1002                                     struct lu_attr *attr,
1003                                     struct dt_allocation_hint *hint,
1004                                     struct dt_object_format *dof,
1005                                     struct thandle *th)
1006 {
1007         LASSERT(dt);
1008         LASSERT(dt->do_ops);
1009         LASSERT(dt->do_ops->do_declare_create);
1010         return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
1011 }
1012
1013 static inline int dt_create(const struct lu_env *env,
1014                                     struct dt_object *dt,
1015                                     struct lu_attr *attr,
1016                                     struct dt_allocation_hint *hint,
1017                                     struct dt_object_format *dof,
1018                                     struct thandle *th)
1019 {
1020         LASSERT(dt);
1021         LASSERT(dt->do_ops);
1022         LASSERT(dt->do_ops->do_create);
1023         return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
1024 }
1025
1026 static inline int dt_declare_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_declare_destroy);
1033         return dt->do_ops->do_declare_destroy(env, dt, th);
1034 }
1035
1036 static inline int dt_destroy(const struct lu_env *env,
1037                              struct dt_object *dt,
1038                              struct thandle *th)
1039 {
1040         LASSERT(dt);
1041         LASSERT(dt->do_ops);
1042         LASSERT(dt->do_ops->do_destroy);
1043         return dt->do_ops->do_destroy(env, dt, th);
1044 }
1045
1046 static inline void dt_read_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_read_lock);
1053         dt->do_ops->do_read_lock(env, dt, role);
1054 }
1055
1056 static inline void dt_write_lock(const struct lu_env *env,
1057                                 struct dt_object *dt,
1058                                 unsigned role)
1059 {
1060         LASSERT(dt);
1061         LASSERT(dt->do_ops);
1062         LASSERT(dt->do_ops->do_write_lock);
1063         dt->do_ops->do_write_lock(env, dt, role);
1064 }
1065
1066 static inline void dt_read_unlock(const struct lu_env *env,
1067                                 struct dt_object *dt)
1068 {
1069         LASSERT(dt);
1070         LASSERT(dt->do_ops);
1071         LASSERT(dt->do_ops->do_read_unlock);
1072         dt->do_ops->do_read_unlock(env, dt);
1073 }
1074
1075 static inline void dt_write_unlock(const struct lu_env *env,
1076                                 struct dt_object *dt)
1077 {
1078         LASSERT(dt);
1079         LASSERT(dt->do_ops);
1080         LASSERT(dt->do_ops->do_write_unlock);
1081         dt->do_ops->do_write_unlock(env, dt);
1082 }
1083
1084 static inline int dt_write_locked(const struct lu_env *env,
1085                                   struct dt_object *dt)
1086 {
1087         LASSERT(dt);
1088         LASSERT(dt->do_ops);
1089         LASSERT(dt->do_ops->do_write_locked);
1090         return dt->do_ops->do_write_locked(env, dt);
1091 }
1092
1093 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
1094                               struct lu_attr *la, void *arg)
1095 {
1096         LASSERT(dt);
1097         LASSERT(dt->do_ops);
1098         LASSERT(dt->do_ops->do_attr_get);
1099         return dt->do_ops->do_attr_get(env, dt, la, arg);
1100 }
1101
1102 static inline int dt_declare_attr_set(const struct lu_env *env,
1103                                       struct dt_object *dt,
1104                                       const struct lu_attr *la,
1105                                       struct thandle *th)
1106 {
1107         LASSERT(dt);
1108         LASSERT(dt->do_ops);
1109         LASSERT(dt->do_ops->do_declare_attr_set);
1110         return dt->do_ops->do_declare_attr_set(env, dt, la, th);
1111 }
1112
1113 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
1114                               const struct lu_attr *la, struct thandle *th,
1115                               struct lustre_capa *capa)
1116 {
1117         LASSERT(dt);
1118         LASSERT(dt->do_ops);
1119         LASSERT(dt->do_ops->do_attr_set);
1120         return dt->do_ops->do_attr_set(env, dt, la, th, capa);
1121 }
1122
1123 static inline int dt_declare_ref_add(const struct lu_env *env,
1124                                      struct dt_object *dt, struct thandle *th)
1125 {
1126         LASSERT(dt);
1127         LASSERT(dt->do_ops);
1128         LASSERT(dt->do_ops->do_declare_ref_add);
1129         return dt->do_ops->do_declare_ref_add(env, dt, th);
1130 }
1131
1132 static inline int dt_ref_add(const struct lu_env *env,
1133                              struct dt_object *dt, struct thandle *th)
1134 {
1135         LASSERT(dt);
1136         LASSERT(dt->do_ops);
1137         LASSERT(dt->do_ops->do_ref_add);
1138         return dt->do_ops->do_ref_add(env, dt, th);
1139 }
1140
1141 static inline int dt_declare_ref_del(const struct lu_env *env,
1142                                      struct dt_object *dt, struct thandle *th)
1143 {
1144         LASSERT(dt);
1145         LASSERT(dt->do_ops);
1146         LASSERT(dt->do_ops->do_declare_ref_del);
1147         return dt->do_ops->do_declare_ref_del(env, dt, th);
1148 }
1149
1150 static inline int dt_ref_del(const struct lu_env *env,
1151                              struct dt_object *dt, struct thandle *th)
1152 {
1153         LASSERT(dt);
1154         LASSERT(dt->do_ops);
1155         LASSERT(dt->do_ops->do_ref_del);
1156         return dt->do_ops->do_ref_del(env, dt, th);
1157 }
1158
1159 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1160                                            struct dt_object *dt,
1161                                            struct lustre_capa *old, __u64 opc)
1162 {
1163         LASSERT(dt);
1164         LASSERT(dt->do_ops);
1165         LASSERT(dt->do_ops->do_capa_get);
1166         return dt->do_ops->do_capa_get(env, dt, old, opc);
1167 }
1168
1169 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1170                               struct niobuf_remote *rnb,
1171                               struct niobuf_local *lnb, int rw,
1172                               struct lustre_capa *capa)
1173 {
1174         LASSERT(d);
1175         LASSERT(d->do_body_ops);
1176         LASSERT(d->do_body_ops->dbo_bufs_get);
1177         return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1178                                             rnb->len, lnb, rw, capa);
1179 }
1180
1181 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1182                               struct niobuf_local *lnb, int n)
1183 {
1184         LASSERT(d);
1185         LASSERT(d->do_body_ops);
1186         LASSERT(d->do_body_ops->dbo_bufs_put);
1187         return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1188 }
1189
1190 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1191                                 struct niobuf_local *lnb, int n)
1192 {
1193         LASSERT(d);
1194         LASSERT(d->do_body_ops);
1195         LASSERT(d->do_body_ops->dbo_write_prep);
1196         return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1197 }
1198
1199 static inline int dt_declare_write_commit(const struct lu_env *env,
1200                                           struct dt_object *d,
1201                                           struct niobuf_local *lnb,
1202                                           int n, struct thandle *th)
1203 {
1204         LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1205         LASSERT(th != NULL);
1206         return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1207 }
1208
1209
1210 static inline int dt_write_commit(const struct lu_env *env,
1211                                   struct dt_object *d, struct niobuf_local *lnb,
1212                                   int n, struct thandle *th)
1213 {
1214         LASSERT(d);
1215         LASSERT(d->do_body_ops);
1216         LASSERT(d->do_body_ops->dbo_write_commit);
1217         return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1218 }
1219
1220 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1221                                struct niobuf_local *lnb, int n)
1222 {
1223         LASSERT(d);
1224         LASSERT(d->do_body_ops);
1225         LASSERT(d->do_body_ops->dbo_read_prep);
1226         return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1227 }
1228
1229 static inline int dt_declare_punch(const struct lu_env *env,
1230                                    struct dt_object *dt, __u64 start,
1231                                    __u64 end, struct thandle *th)
1232 {
1233         LASSERT(dt);
1234         LASSERT(dt->do_body_ops);
1235         LASSERT(dt->do_body_ops->dbo_declare_punch);
1236         return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
1237 }
1238
1239 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1240                            __u64 start, __u64 end, struct thandle *th,
1241                            struct lustre_capa *capa)
1242 {
1243         LASSERT(dt);
1244         LASSERT(dt->do_body_ops);
1245         LASSERT(dt->do_body_ops->dbo_punch);
1246         return dt->do_body_ops->dbo_punch(env, dt, start, end, th, capa);
1247 }
1248
1249 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1250                                 struct ll_user_fiemap *fm)
1251 {
1252         LASSERT(d);
1253         if (d->do_body_ops == NULL)
1254                 return -EPROTO;
1255         if (d->do_body_ops->dbo_fiemap_get == NULL)
1256                 return -EOPNOTSUPP;
1257         return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1258 }
1259
1260 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1261                             struct obd_statfs *osfs)
1262 {
1263         LASSERT(dev);
1264         LASSERT(dev->dd_ops);
1265         LASSERT(dev->dd_ops->dt_statfs);
1266         return dev->dd_ops->dt_statfs(env, dev, osfs);
1267 }
1268
1269 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1270                               struct lu_fid *f)
1271 {
1272         LASSERT(dev);
1273         LASSERT(dev->dd_ops);
1274         LASSERT(dev->dd_ops->dt_root_get);
1275         return dev->dd_ops->dt_root_get(env, dev, f);
1276 }
1277
1278 static inline void dt_conf_get(const struct lu_env *env,
1279                                const struct dt_device *dev,
1280                                struct dt_device_param *param)
1281 {
1282         LASSERT(dev);
1283         LASSERT(dev->dd_ops);
1284         LASSERT(dev->dd_ops->dt_conf_get);
1285         return dev->dd_ops->dt_conf_get(env, dev, param);
1286 }
1287
1288 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1289 {
1290         LASSERT(dev);
1291         LASSERT(dev->dd_ops);
1292         LASSERT(dev->dd_ops->dt_sync);
1293         return dev->dd_ops->dt_sync(env, dev);
1294 }
1295
1296 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1297 {
1298         LASSERT(dev);
1299         LASSERT(dev->dd_ops);
1300         LASSERT(dev->dd_ops->dt_ro);
1301         return dev->dd_ops->dt_ro(env, dev);
1302 }
1303
1304 static inline int dt_declare_insert(const struct lu_env *env,
1305                                     struct dt_object *dt,
1306                                     const struct dt_rec *rec,
1307                                     const struct dt_key *key,
1308                                     struct thandle *th)
1309 {
1310         LASSERT(dt);
1311         LASSERT(dt->do_index_ops);
1312         LASSERT(dt->do_index_ops->dio_declare_insert);
1313         return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1314 }
1315
1316 static inline int dt_insert(const struct lu_env *env,
1317                                     struct dt_object *dt,
1318                                     const struct dt_rec *rec,
1319                                     const struct dt_key *key,
1320                                     struct thandle *th,
1321                                     struct lustre_capa *capa,
1322                                     int noquota)
1323 {
1324         LASSERT(dt);
1325         LASSERT(dt->do_index_ops);
1326         LASSERT(dt->do_index_ops->dio_insert);
1327         return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1328                                             capa, noquota);
1329 }
1330
1331 static inline int dt_declare_xattr_del(const struct lu_env *env,
1332                                        struct dt_object *dt,
1333                                        const char *name,
1334                                        struct thandle *th)
1335 {
1336         LASSERT(dt);
1337         LASSERT(dt->do_ops);
1338         LASSERT(dt->do_ops->do_declare_xattr_del);
1339         return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1340 }
1341
1342 static inline int dt_xattr_del(const struct lu_env *env,
1343                                struct dt_object *dt, const char *name,
1344                                struct thandle *th,
1345                                struct lustre_capa *capa)
1346 {
1347         LASSERT(dt);
1348         LASSERT(dt->do_ops);
1349         LASSERT(dt->do_ops->do_xattr_del);
1350         return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1351 }
1352
1353 static inline int dt_declare_xattr_set(const struct lu_env *env,
1354                                       struct dt_object *dt,
1355                                       const struct lu_buf *buf,
1356                                       const char *name, int fl,
1357                                       struct thandle *th)
1358 {
1359         LASSERT(dt);
1360         LASSERT(dt->do_ops);
1361         LASSERT(dt->do_ops->do_declare_xattr_set);
1362         return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1363 }
1364
1365 static inline int dt_xattr_set(const struct lu_env *env,
1366                               struct dt_object *dt, const struct lu_buf *buf,
1367                               const char *name, int fl, struct thandle *th,
1368                               struct lustre_capa *capa)
1369 {
1370         LASSERT(dt);
1371         LASSERT(dt->do_ops);
1372         LASSERT(dt->do_ops->do_xattr_set);
1373         return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1374 }
1375
1376 static inline int dt_xattr_get(const struct lu_env *env,
1377                               struct dt_object *dt, struct lu_buf *buf,
1378                               const char *name, struct lustre_capa *capa)
1379 {
1380         LASSERT(dt);
1381         LASSERT(dt->do_ops);
1382         LASSERT(dt->do_ops->do_xattr_get);
1383         return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1384 }
1385
1386 static inline int dt_xattr_list(const struct lu_env *env,
1387                                struct dt_object *dt, struct lu_buf *buf,
1388                                struct lustre_capa *capa)
1389 {
1390         LASSERT(dt);
1391         LASSERT(dt->do_ops);
1392         LASSERT(dt->do_ops->do_xattr_list);
1393         return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1394 }
1395
1396 static inline int dt_declare_delete(const struct lu_env *env,
1397                                     struct dt_object *dt,
1398                                     const struct dt_key *key,
1399                                     struct thandle *th)
1400 {
1401         LASSERT(dt);
1402         LASSERT(dt->do_index_ops);
1403         LASSERT(dt->do_index_ops->dio_declare_delete);
1404         return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1405 }
1406
1407 static inline int dt_delete(const struct lu_env *env,
1408                             struct dt_object *dt,
1409                             const struct dt_key *key,
1410                             struct thandle *th,
1411                             struct lustre_capa *capa)
1412 {
1413         LASSERT(dt);
1414         LASSERT(dt->do_index_ops);
1415         LASSERT(dt->do_index_ops->dio_delete);
1416         return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1417 }
1418
1419 static inline int dt_commit_async(const struct lu_env *env,
1420                                   struct dt_device *dev)
1421 {
1422         LASSERT(dev);
1423         LASSERT(dev->dd_ops);
1424         LASSERT(dev->dd_ops->dt_commit_async);
1425         return dev->dd_ops->dt_commit_async(env, dev);
1426 }
1427
1428 static inline int dt_init_capa_ctxt(const struct lu_env *env,
1429                                     struct dt_device *dev,
1430                                     int mode, unsigned long timeout,
1431                                     __u32 alg, struct lustre_capa_key *keys)
1432 {
1433         LASSERT(dev);
1434         LASSERT(dev->dd_ops);
1435         LASSERT(dev->dd_ops->dt_init_capa_ctxt);
1436         return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
1437                                               timeout, alg, keys);
1438 }
1439
1440 static inline int dt_lookup(const struct lu_env *env,
1441                             struct dt_object *dt,
1442                             struct dt_rec *rec,
1443                             const struct dt_key *key,
1444                             struct lustre_capa *capa)
1445 {
1446         int ret;
1447
1448         LASSERT(dt);
1449         LASSERT(dt->do_index_ops);
1450         LASSERT(dt->do_index_ops->dio_lookup);
1451
1452         ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1453         if (ret > 0)
1454                 ret = 0;
1455         else if (ret == 0)
1456                 ret = -ENOENT;
1457         return ret;
1458 }
1459
1460 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1461
1462 struct dt_find_hint {
1463         struct lu_fid        *dfh_fid;
1464         struct dt_device     *dfh_dt;
1465         struct dt_object     *dfh_o;
1466 };
1467
1468 struct dt_thread_info {
1469         char                     dti_buf[DT_MAX_PATH];
1470         struct dt_find_hint      dti_dfh;
1471         struct lu_attr           dti_attr;
1472         struct lu_fid            dti_fid;
1473         struct dt_object_format  dti_dof;
1474         struct lustre_mdt_attrs  dti_lma;
1475         struct lu_buf            dti_lb;
1476         struct lu_object_conf    dti_conf;
1477         loff_t                   dti_off;
1478 };
1479
1480 extern struct lu_context_key dt_key;
1481
1482 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
1483 {
1484         struct dt_thread_info *dti;
1485
1486         dti = lu_context_key_get(&env->le_ctx, &dt_key);
1487         LASSERT(dti);
1488         return dti;
1489 }
1490
1491 int dt_global_init(void);
1492 void dt_global_fini(void);
1493
1494 # ifdef LPROCFS
1495 #ifndef HAVE_ONLY_PROCFS_SEQ
1496 int lprocfs_dt_rd_blksize(char *page, char **start, off_t off,
1497                           int count, int *eof, void *data);
1498 int lprocfs_dt_rd_kbytestotal(char *page, char **start, off_t off,
1499                               int count, int *eof, void *data);
1500 int lprocfs_dt_rd_kbytesfree(char *page, char **start, off_t off,
1501                              int count, int *eof, void *data);
1502 int lprocfs_dt_rd_kbytesavail(char *page, char **start, off_t off,
1503                               int count, int *eof, void *data);
1504 int lprocfs_dt_rd_filestotal(char *page, char **start, off_t off,
1505                              int count, int *eof, void *data);
1506 int lprocfs_dt_rd_filesfree(char *page, char **start, off_t off,
1507                             int count, int *eof, void *data);
1508 #endif
1509 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
1510 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
1511 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
1512 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
1513 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
1514 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
1515 # endif /* LPROCFS */
1516
1517 #endif /* __LUSTRE_DT_OBJECT_H */