Whamcloud - gitweb
436139fa128c30385e3b40c4e5ea818e56f63c31
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32
33 #ifndef __LUSTRE_DT_OBJECT_H
34 #define __LUSTRE_DT_OBJECT_H
35
36 /** \defgroup dt dt
37  * Sub-class of lu_object with methods common for "data" objects in OST stack.
38  *
39  * Data objects behave like regular files: you can read/write them, get and
40  * set their attributes. Implementation of dt interface is supposed to
41  * implement some form of garbage collection, normally reference counting
42  * (nlink) based one.
43  *
44  * Examples: osd (lustre/osd) is an implementation of dt interface.
45  * @{
46  */
47
48 #include <obd_support.h>
49 /*
50  * super-class definitions.
51  */
52 #include <lu_object.h>
53
54 #include <libcfs/libcfs.h>
55
56 struct seq_file;
57 struct proc_dir_entry;
58 struct lustre_cfg;
59
60 struct thandle;
61 struct dt_device;
62 struct dt_object;
63 struct dt_index_features;
64 struct niobuf_local;
65 struct niobuf_remote;
66 struct ldlm_enqueue_info;
67
68 typedef enum {
69         MNTOPT_USERXATTR        = 0x00000001,
70         MNTOPT_ACL              = 0x00000002,
71 } mntopt_t;
72
73 struct dt_device_param {
74         unsigned           ddp_max_name_len;
75         unsigned           ddp_max_nlink;
76         unsigned           ddp_symlink_max;
77         mntopt_t           ddp_mntopts;
78         unsigned           ddp_max_ea_size;
79         unsigned           ddp_mount_type;
80         unsigned long long ddp_maxbytes;
81         /* per-inode space consumption */
82         short              ddp_inodespace;
83         /* maximum number of blocks in an extent */
84         unsigned           ddp_max_extent_blks;
85         /* per-extent insertion overhead to be used by client for grant
86          * calculation */
87         unsigned           ddp_extent_tax;
88 };
89
90 /**
91  * Per-transaction commit callback function
92  */
93 struct dt_txn_commit_cb;
94 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
95                         struct dt_txn_commit_cb *cb, int err);
96 /**
97  * Special per-transaction callback for cases when just commit callback
98  * is needed and per-device callback are not convenient to use
99  */
100 #define TRANS_COMMIT_CB_MAGIC   0xa0a00a0a
101 #define MAX_COMMIT_CB_STR_LEN   32
102
103 #define DCB_TRANS_STOP          0x1
104 struct dt_txn_commit_cb {
105         struct list_head        dcb_linkage;
106         dt_cb_t                 dcb_func;
107         void                    *dcb_data;
108         __u32                   dcb_magic;
109         __u32                   dcb_flags;
110         char                    dcb_name[MAX_COMMIT_CB_STR_LEN];
111 };
112
113 /**
114  * Operations on dt device.
115  */
116 struct dt_device_operations {
117         /**
118          * Return device-wide statistics.
119          *
120          * Return device-wide stats including block size, total and
121          * free blocks, total and free objects, etc. See struct obd_statfs
122          * for the details.
123          *
124          * \param[in] env       execution environment for this thread
125          * \param[in] dev       dt device
126          * \param[out] osfs     stats information
127          *
128          * \retval 0            on success
129          * \retval negative     negated errno on error
130          */
131         int   (*dt_statfs)(const struct lu_env *env,
132                            struct dt_device *dev,
133                            struct obd_statfs *osfs);
134
135         /**
136          * Create transaction.
137          *
138          * Create in-memory structure representing the transaction for the
139          * caller. The structure returned will be used by the calling thread
140          * to specify the transaction the updates belong to. Once created
141          * successfully ->dt_trans_stop() must be called in any case (with
142          * ->dt_trans_start() and updates or not) so that the transaction
143          * handle and other resources can be released by the layers below.
144          *
145          * \param[in] env       execution environment for this thread
146          * \param[in] dev       dt device
147          *
148          * \retval pointer to handle    if creation succeeds
149          * \retval ERR_PTR(errno)       if creation fails
150          */
151         struct thandle *(*dt_trans_create)(const struct lu_env *env,
152                                            struct dt_device *dev);
153
154         /**
155          * Start transaction.
156          *
157          * Start the transaction. The transaction described by \a th can be
158          * started only once. Another start is considered as an error.
159          * A thread is not supposed to start a transaction while another
160          * transaction isn't closed by the thread (though multiple handles
161          * can be created). The caller should start the transaction once
162          * all possible updates are declared (see the ->do_declare_* methods
163          * below) and all the needed resources are reserved.
164          *
165          * \param[in] env       execution environment for this thread
166          * \param[in] dev       dt device
167          * \param[in] th        transaction handle
168          *
169          * \retval 0            on success
170          * \retval negative     negated errno on error
171          */
172         int   (*dt_trans_start)(const struct lu_env *env,
173                                 struct dt_device *dev,
174                                 struct thandle *th);
175
176         /**
177          * Stop transaction.
178          *
179          * Once stopped the transaction described by \a th is complete (all
180          * the needed updates are applied) and further processing such as
181          * flushing to disk, sending to another target, etc, is handled by
182          * lower layers. The caller can't access this transaction by the
183          * handle anymore (except from the commit callbacks, see below).
184          *
185          * \param[in] env       execution environment for this thread
186          * \param[in] dev       dt device
187          * \param[in] th        transaction handle
188          *
189          * \retval 0            on success
190          * \retval negative     negated errno on error
191          */
192         int   (*dt_trans_stop)(const struct lu_env *env,
193                                struct dt_device *dev,
194                                struct thandle *th);
195
196         /**
197          * Add commit callback to the transaction.
198          *
199          * Add a commit callback to the given transaction handle. The callback
200          * will be called when the associated transaction is stored. I.e. the
201          * transaction will survive an event like power off if the callback did
202          * run. The number of callbacks isn't limited, but you should note that
203          * some disk filesystems do handle the commit callbacks in the thread
204          * handling commit/flush of all the transactions, meaning that new
205          * transactions are blocked from commit and flush until all the
206          * callbacks are done. Also, note multiple callbacks can be running
207          * concurrently using multiple CPU cores. The callbacks will be running
208          * in a special environment which can not be used to pass data around.
209          *
210          * \param[in] th        transaction handle
211          * \param[in] dcb       commit callback description
212          *
213          * \retval 0            on success
214          * \retval negative     negated errno on error
215          */
216         int   (*dt_trans_cb_add)(struct thandle *th,
217                                  struct dt_txn_commit_cb *dcb);
218
219         /**
220          * Return FID of root index object.
221          *
222          * Return the FID of the root object in the filesystem. This object
223          * is usually provided as a bootstrap point by a disk filesystem.
224          * This is up to the implementation which FID to use, though
225          * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
226          *
227          * \param[in] env       execution environment for this thread
228          * \param[in] dev       dt device
229          * \param[out] fid      FID of the root object
230          *
231          * \retval 0            on success
232          * \retval negative     negated errno on error
233          */
234         int   (*dt_root_get)(const struct lu_env *env,
235                              struct dt_device *dev,
236                              struct lu_fid *f);
237
238         /**
239          * Return device configuration data.
240          *
241          * Return device (disk fs, actually) specific configuration.
242          * The configuration isn't subject to change at runtime.
243          * See struct dt_device_param for the details.
244          *
245          * \param[in] env       execution environment for this thread
246          * \param[in] dev       dt device
247          * \param[out] param    configuration parameters
248          */
249         void  (*dt_conf_get)(const struct lu_env *env,
250                              const struct dt_device *dev,
251                              struct dt_device_param *param);
252
253         /**
254          * Sync the device.
255          *
256          * Sync all the cached state (dirty buffers, pages, etc) to the
257          * persistent storage. The method returns control once the sync is
258          * complete. This operation may incur significant I/O to disk and
259          * should be reserved for cases where a global sync is strictly
260          * necessary.
261          *
262          * \param[in] env       execution environment for this thread
263          * \param[in] dev       dt device
264          *
265          * \retval 0            on success
266          * \retval negative     negated errno on error
267          */
268         int   (*dt_sync)(const struct lu_env *env,
269                          struct dt_device *dev);
270
271         /**
272          * Make device read-only.
273          *
274          * Prevent new modifications to the device. This is a very specific
275          * state where all the changes are accepted successfully and the
276          * commit callbacks are called, but persistent state never changes.
277          * Used only in the tests to simulate power-off scenario.
278          *
279          * \param[in] env       execution environment for this thread
280          * \param[in] dev       dt device
281          *
282          * \retval 0            on success
283          * \retval negative     negated errno on error
284          */
285         int   (*dt_ro)(const struct lu_env *env,
286                        struct dt_device *dev);
287
288         /**
289          * Start transaction commit asynchronously.
290          *
291
292          * Provide a hint to the underlying filesystem that it should start
293          * committing soon. The control returns immediately. It's up to the
294          * layer implementing the method how soon to start committing. Usually
295          * this should be throttled to some extent, otherwise the number of
296          * aggregated transaction goes too high causing performance drop.
297          *
298          * \param[in] env       execution environment for this thread
299          * \param[in] dev       dt device
300          *
301          * \retval 0            on success
302          * \retval negative     negated errno on error
303          */
304          int   (*dt_commit_async)(const struct lu_env *env,
305                                   struct dt_device *dev);
306 };
307
308 struct dt_index_features {
309         /** required feature flags from enum dt_index_flags */
310         __u32 dif_flags;
311         /** minimal required key size */
312         size_t dif_keysize_min;
313         /** maximal required key size, 0 if no limit */
314         size_t dif_keysize_max;
315         /** minimal required record size */
316         size_t dif_recsize_min;
317         /** maximal required record size, 0 if no limit */
318         size_t dif_recsize_max;
319         /** pointer size for record */
320         size_t dif_ptrsize;
321 };
322
323 enum dt_index_flags {
324         /** index supports variable sized keys */
325         DT_IND_VARKEY = 1 << 0,
326         /** index supports variable sized records */
327         DT_IND_VARREC = 1 << 1,
328         /** index can be modified */
329         DT_IND_UPDATE = 1 << 2,
330         /** index supports records with non-unique (duplicate) keys */
331         DT_IND_NONUNQ = 1 << 3,
332         /**
333          * index support fixed-size keys sorted with natural numerical way
334          * and is able to return left-side value if no exact value found
335          */
336         DT_IND_RANGE = 1 << 4,
337 };
338
339 /**
340  * Features, required from index to support file system directories (mapping
341  * names to fids).
342  */
343 extern const struct dt_index_features dt_directory_features;
344 extern const struct dt_index_features dt_otable_features;
345 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
346 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
347 extern const struct dt_index_features dt_lfsck_namespace_features;
348
349 /* index features supported by the accounting objects */
350 extern const struct dt_index_features dt_acct_features;
351
352 /* index features supported by the quota global indexes */
353 extern const struct dt_index_features dt_quota_glb_features;
354
355 /* index features supported by the quota slave indexes */
356 extern const struct dt_index_features dt_quota_slv_features;
357
358 /* index features supported by the nodemap index */
359 extern const struct dt_index_features dt_nodemap_features;
360
361 /**
362  * This is a general purpose dt allocation hint.
363  * It now contains the parent object.
364  * It can contain any allocation hint in the future.
365  */
366 struct dt_allocation_hint {
367         struct dt_object        *dah_parent;
368         const void              *dah_eadata;
369         int                     dah_eadata_len;
370         __u32                   dah_mode;
371 };
372
373 /**
374  * object type specifier.
375  */
376
377 enum dt_format_type {
378         DFT_REGULAR,
379         DFT_DIR,
380         /** for mknod */
381         DFT_NODE,
382         /** for special index */
383         DFT_INDEX,
384         /** for symbolic link */
385         DFT_SYM,
386 };
387
388 /**
389  * object format specifier.
390  */
391 struct dt_object_format {
392         /** type for dt object */
393         enum dt_format_type dof_type;
394         union {
395                 struct dof_regular {
396                         int striped;
397                 } dof_reg;
398                 struct dof_dir {
399                 } dof_dir;
400                 struct dof_node {
401                 } dof_node;
402                 /**
403                  * special index need feature as parameter to create
404                  * special idx
405                  */
406                 struct dof_index {
407                         const struct dt_index_features *di_feat;
408                 } dof_idx;
409         } u;
410 };
411
412 enum dt_format_type dt_mode_to_dft(__u32 mode);
413
414 typedef __u64 dt_obj_version_t;
415
416 union ldlm_policy_data;
417
418 /**
419  * A dt_object provides common operations to create and destroy
420  * objects and to manage regular and extended attributes.
421  */
422 struct dt_object_operations {
423         /**
424          * Get read lock on object.
425          *
426          * Read lock is compatible with other read locks, so it's shared.
427          * Read lock is not compatible with write lock which is exclusive.
428          * The lock is blocking and can't be used from an interrupt context.
429          *
430          * \param[in] env       execution environment for this thread
431          * \param[in] dt        object to lock for reading
432          * \param[in] role      a hint to debug locks (see kernel's mutexes)
433          */
434         void  (*do_read_lock)(const struct lu_env *env,
435                               struct dt_object *dt,
436                               unsigned role);
437
438         /*
439          * Get write lock on object.
440          *
441          * Write lock is exclusive and cannot be shared. The lock is blocking
442          * and can't be used from an interrupt context.
443          *
444          * \param[in] env       execution environment for this thread
445          * \param[in] dt        object to lock for writing
446          * \param[in] role      a hint to debug locks (see kernel's mutexes)
447          *
448          */
449         void  (*do_write_lock)(const struct lu_env *env,
450                                struct dt_object *dt,
451                                unsigned role);
452
453         /**
454          * Release read lock.
455          *
456          * \param[in] env       execution environment for this thread
457          * \param[in] dt        object
458          */
459         void  (*do_read_unlock)(const struct lu_env *env,
460                                 struct dt_object *dt);
461
462         /**
463          * Release write lock.
464          *
465          * \param[in] env       execution environment for this thread
466          * \param[in] dt        object
467          */
468         void  (*do_write_unlock)(const struct lu_env *env,
469                                  struct dt_object *dt);
470
471         /**
472          * Check whether write lock is held.
473          *
474          * The caller can learn whether write lock is held on the object
475          *
476          * \param[in] env       execution environment for this thread
477          * \param[in] dt        object
478          *
479          * \retval 0            no write lock
480          * \retval 1            write lock is held
481          */
482         int  (*do_write_locked)(const struct lu_env *env,
483                                 struct dt_object *dt);
484
485         /**
486          * Declare intention to request reqular attributes.
487          *
488          * Notity the underlying filesystem that the caller may request regular
489          * attributes with ->do_attr_get() soon. This allows OSD to implement
490          * prefetching logic in an object-oriented manner. The implementation
491          * can be noop. This method should avoid expensive delays such as
492          * waiting on disk I/O, otherwise the goal of enabling a performance
493          * optimization would be defeated.
494          *
495          * \param[in] env       execution environment for this thread
496          * \param[in] dt        object
497          *
498          * \retval 0            on success
499          * \retval negative     negated errno on error
500          */
501         int   (*do_declare_attr_get)(const struct lu_env *env,
502                                      struct dt_object *dt);
503
504         /**
505          * Return regular attributes.
506          *
507          * The object must exist. Currently all the attributes should be
508          * returned, but in the future this can be improved so that only
509          * a selected set is returned. This can improve performance as in
510          * some cases attributes are stored in different places and
511          * getting them all can be an iterative and expensive process.
512          *
513          * \param[in] env       execution environment for this thread
514          * \param[in] dt        object
515          * \param[out] attr     attributes to fill
516          *
517          * \retval 0            on success
518          * \retval negative     negated errno on error
519          */
520         int   (*do_attr_get)(const struct lu_env *env,
521                              struct dt_object *dt,
522                              struct lu_attr *attr);
523
524         /**
525          * Declare intention to change regular object's attributes.
526          *
527          * Notify the underlying filesystem that the regular attributes may
528          * change in this transaction. This enables the layer below to prepare
529          * resources (e.g. journal credits in ext4).  This method should be
530          * called between creating the transaction and starting it. Note that
531          * the la_valid field of \a attr specifies which attributes will change.
532          * The object need not exist.
533          *
534          * \param[in] env       execution environment for this thread
535          * \param[in] dt        object
536          * \param[in] attr      attributes to change specified in attr.la_valid
537          * \param[in] th        transaction handle
538          *
539          * \retval 0            on success
540          * \retval negative     negated errno on error
541          */
542         int   (*do_declare_attr_set)(const struct lu_env *env,
543                                      struct dt_object *dt,
544                                      const struct lu_attr *attr,
545                                      struct thandle *th);
546
547         /**
548          * Change regular attributes.
549          *
550          * Change regular attributes in the given transaction. Note only
551          * attributes flagged by attr.la_valid change. The object must
552          * exist. If the layer implementing this method is responsible for
553          * quota, then the method should maintain object accounting for the
554          * given credentials when la_uid/la_gid changes.
555          *
556          * \param[in] env       execution environment for this thread
557          * \param[in] dt        object
558          * \param[in] attr      new attributes to apply
559          * \param[in] th        transaction handle
560          *
561          * \retval 0            on success
562          * \retval negative     negated errno on error
563          */
564         int   (*do_attr_set)(const struct lu_env *env,
565                              struct dt_object *dt,
566                              const struct lu_attr *attr,
567                              struct thandle *th);
568
569         /**
570          * Declare intention to request extented attribute.
571          *
572          * Notify the underlying filesystem that the caller may request extended
573          * attribute with ->do_xattr_get() soon. This allows OSD to implement
574          * prefetching logic in an object-oriented manner. The implementation
575          * can be noop. This method should avoid expensive delays such as
576          * waiting on disk I/O, otherwise the goal of enabling a performance
577          * optimization would be defeated.
578          *
579          * \param[in] env       execution environment for this thread
580          * \param[in] dt        object
581          * \param[in] buf       unused, may be removed in the future
582          * \param[in] name      name of the extended attribute
583          *
584          * \retval 0            on success
585          * \retval negative     negated errno on error
586          */
587         int   (*do_declare_xattr_get)(const struct lu_env *env,
588                                       struct dt_object *dt,
589                                       struct lu_buf *buf,
590                                       const char *name);
591
592         /**
593          * Return a value of an extended attribute.
594          *
595          * The object must exist. If the buffer is NULL, then the method
596          * must return the size of the value.
597          *
598          * \param[in] env       execution environment for this thread
599          * \param[in] dt        object
600          * \param[out] buf      buffer in which to store the value
601          * \param[in] name      name of the extended attribute
602          *
603          * \retval 0            on success
604          * \retval -ERANGE      if \a buf is too small
605          * \retval negative     negated errno on error
606          * \retval positive     value's size if \a buf is NULL or has zero size
607          */
608         int   (*do_xattr_get)(const struct lu_env *env,
609                               struct dt_object *dt,
610                               struct lu_buf *buf,
611                               const char *name);
612
613         /**
614          * Declare intention to change an extended attribute.
615          *
616          * Notify the underlying filesystem that the extended attribute may
617          * change in this transaction.  This enables the layer below to prepare
618          * resources (e.g. journal credits in ext4).  This method should be
619          * called between creating the transaction and starting it. The object
620          * need not exist.
621          *
622          * \param[in] env       execution environment for this thread
623          * \param[in] dt        object
624          * \param[in] buf       buffer storing new value of the attribute
625          * \param[in] name      name of the attribute
626          * \param[in] fl        LU_XATTR_CREATE - fail if EA exists
627          *                      LU_XATTR_REPLACE - fail if EA doesn't exist
628          * \param[in] th        transaction handle
629          *
630          * \retval 0            on success
631          * \retval negative     negated errno on error
632          */
633         int   (*do_declare_xattr_set)(const struct lu_env *env,
634                                       struct dt_object *dt,
635                                       const struct lu_buf *buf,
636                                       const char *name,
637                                       int fl,
638                                       struct thandle *th);
639
640         /**
641          * Set an extended attribute.
642          *
643          * Change or replace the specified extended attribute (EA).
644          * The flags passed in \a fl dictate whether the EA is to be
645          * created or replaced, as follows.
646          *   LU_XATTR_CREATE - fail if EA exists
647          *   LU_XATTR_REPLACE - fail if EA doesn't exist
648          * The object must exist.
649          *
650          * \param[in] env       execution environment for this thread
651          * \param[in] dt        object
652          * \param[in] buf       buffer storing new value of the attribute
653          * \param[in] name      name of the attribute
654          * \param[in] fl        flags indicating EA creation or replacement
655          * \param[in] th        transaction handle
656          *
657          * \retval 0            on success
658          * \retval negative     negated errno on error
659          */
660         int   (*do_xattr_set)(const struct lu_env *env,
661                               struct dt_object *dt,
662                               const struct lu_buf *buf,
663                               const char *name,
664                               int fl,
665                               struct thandle *th);
666
667         /**
668          * Declare intention to delete an extended attribute.
669          *
670          * Notify the underlying filesystem that the extended attribute may
671          * be deleted in this transaction. This enables the layer below to
672          * prepare resources (e.g. journal credits in ext4).  This method
673          * should be called between creating the transaction and starting it.
674          * The object need not exist.
675          *
676          * \param[in] env       execution environment for this thread
677          * \param[in] dt        object
678          * \param[in] name      name of the attribute
679          * \param[in] th        transaction handle
680          *
681          * \retval 0            on success
682          * \retval negative     negated errno on error
683          */
684         int   (*do_declare_xattr_del)(const struct lu_env *env,
685                                       struct dt_object *dt,
686                                       const char *name,
687                                       struct thandle *th);
688
689         /**
690          * Delete an extended attribute.
691          *
692          * This method deletes the specified extended attribute. The object
693          * must exist.
694          *
695          * \param[in] env       execution environment for this thread
696          * \param[in] dt        object
697          * \param[in] name      name of the attribute
698          * \param[in] th        transaction handle
699          *
700          * \retval 0            on success
701          * \retval negative     negated errno on error
702          */
703         int   (*do_xattr_del)(const struct lu_env *env,
704                               struct dt_object *dt,
705                               const char *name,
706                               struct thandle *th);
707
708         /**
709          * Return a list of the extended attributes.
710          *
711          * Fills the passed buffer with a list of the extended attributes
712          * found in the object. The names are separated with '\0'.
713          * The object must exist.
714          *
715          * \param[in] env       execution environment for this thread
716          * \param[in] dt        object
717          * \param[out] buf      buffer to put the list in
718          *
719          * \retval positive     bytes used/required in the buffer
720          * \retval negative     negated errno on error
721          */
722         int   (*do_xattr_list)(const struct lu_env *env,
723                                struct dt_object *dt,
724                                const struct lu_buf *buf);
725
726         /**
727          * Prepare allocation hint for a new object.
728          *
729          * This method is used by the caller to inform OSD of the parent-child
730          * relationship between two objects and enable efficient object
731          * allocation. Filled allocation hint will be passed to ->do_create()
732          * later.
733          *
734          * \param[in] env       execution environment for this thread
735          * \param[out] ah       allocation hint
736          * \param[in] parent    parent object (can be NULL)
737          * \param[in] child     child object
738          * \param[in] _mode     type of the child object
739          */
740         void  (*do_ah_init)(const struct lu_env *env,
741                             struct dt_allocation_hint *ah,
742                             struct dt_object *parent,
743                             struct dt_object *child,
744                             umode_t mode);
745
746         /**
747          * Declare intention to create a new object.
748          *
749          * Notify the underlying filesystem that the object may be created
750          * in this transaction. This enables the layer below to prepare
751          * resources (e.g. journal credits in ext4).  This method should be
752          * called between creating the transaction and starting it.
753          *
754          * If the layer implementing this method is responsible for quota,
755          * then the method should reserve an object for the given credentials
756          * and return an error if quota is over. If object creation later
757          * fails for some reason, then the reservation should be released
758          * properly (usually in ->dt_trans_stop()).
759          *
760          * \param[in] env       execution environment for this thread
761          * \param[in] dt        object
762          * \param[in] attr      attributes of the new object
763          * \param[in] hint      allocation hint
764          * \param[in] dof       object format
765          * \param[in] th        transaction handle
766          *
767          * \retval 0            on success
768          * \retval negative     negated errno on error
769          */
770         int   (*do_declare_create)(const struct lu_env *env,
771                                    struct dt_object *dt,
772                                    struct lu_attr *attr,
773                                    struct dt_allocation_hint *hint,
774                                    struct dt_object_format *dof,
775                                    struct thandle *th);
776
777         /**
778          * Create new object.
779          *
780          * The method creates the object passed with the specified attributes
781          * and object format. Object allocation procedure can use information
782          * stored in the allocation hint. Different object formats are supported
783          * (see enum dt_format_type and struct dt_object_format) depending on
784          * the device. If creation succeeds, then LOHA_EXISTS flag must be set
785          * in the LU-object header attributes.
786          *
787          * If the layer implementing this method is responsible for quota,
788          * then the method should maintain object accounting for the given
789          * credentials.
790          *
791          * \param[in] env       execution environment for this thread
792          * \param[in] dt        object
793          * \param[in] attr      attributes of the new object
794          * \param[in] hint      allocation hint
795          * \param[in] dof       object format
796          * \param[in] th        transaction handle
797          *
798          * \retval 0            on success
799          * \retval negative     negated errno on error
800          */
801         int   (*do_create)(const struct lu_env *env,
802                            struct dt_object *dt,
803                            struct lu_attr *attr,
804                            struct dt_allocation_hint *hint,
805                            struct dt_object_format *dof,
806                            struct thandle *th);
807
808         /**
809          * Declare intention to destroy an object.
810          *
811          * Notify the underlying filesystem that the object may be destroyed
812          * in this transaction. This enables the layer below to prepare
813          * resources (e.g. journal credits in ext4).  This method should be
814          * called between creating the transaction and starting it. The object
815          * need not exist.
816          *
817          * \param[in] env       execution environment for this thread
818          * \param[in] dt        object
819          * \param[in] th        transaction handle
820          *
821          * \retval 0            on success
822          * \retval negative     negated errno on error
823          */
824         int   (*do_declare_destroy)(const struct lu_env *env,
825                                     struct dt_object *dt,
826                                     struct thandle *th);
827
828         /**
829          * Destroy an object.
830          *
831          * This method destroys the object and all the resources associated
832          * with the object (data, key/value pairs, extended attributes, etc).
833          * The object must exist. If destroy is successful, then flag
834          * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
835          * instance of in-core object. Any subsequent access to the same FID
836          * should get another instance with no LOHA_EXIST flag set.
837          *
838          * If the layer implementing this method is responsible for quota,
839          * then the method should maintain object accounting for the given
840          * credentials.
841          *
842          * \param[in] env       execution environment for this thread
843          * \param[in] dt        object
844          * \param[in] th        transaction handle
845          *
846          * \retval 0            on success
847          * \retval negative     negated errno on error
848          */
849         int   (*do_destroy)(const struct lu_env *env,
850                             struct dt_object *dt,
851                             struct thandle *th);
852
853         /**
854          * Try object as an index.
855          *
856          * Announce that this object is going to be used as an index. This
857          * operation checks that object supports indexing operations and
858          * installs appropriate dt_index_operations vector on success.
859          * Also probes for features. Operation is successful if all required
860          * features are supported. It's not possible to access the object
861          * with index methods before ->do_index_try() returns success.
862          *
863          * \param[in] env       execution environment for this thread
864          * \param[in] dt        object
865          * \param[in] feat      index features
866          *
867          * \retval 0            on success
868          * \retval negative     negated errno on error
869          */
870         int   (*do_index_try)(const struct lu_env *env,
871                               struct dt_object *dt,
872                               const struct dt_index_features *feat);
873
874         /**
875          * Declare intention to increment nlink count.
876          *
877          * Notify the underlying filesystem that the nlink regular attribute
878          * be changed in this transaction. This enables the layer below to
879          * prepare resources (e.g. journal credits in ext4).  This method
880          * should be called between creating the transaction and starting it.
881          * The object need not exist.
882          *
883          * \param[in] env       execution environment for this thread
884          * \param[in] dt        object
885          * \param[in] th        transaction handle
886          *
887          * \retval 0            on success
888          * \retval negative     negated errno on error
889          */
890         int   (*do_declare_ref_add)(const struct lu_env *env,
891                                     struct dt_object *dt,
892                                     struct thandle *th);
893
894         /**
895          * Increment nlink.
896          *
897          * Increment nlink (from the regular attributes set) in the given
898          * transaction. Note the absolute limit for nlink should be learnt
899          * from struct dt_device_param::ddp_max_nlink. The object must exist.
900          *
901          * \param[in] env       execution environment for this thread
902          * \param[in] dt        object
903          * \param[in] th        transaction handle
904          *
905          * \retval 0            on success
906          * \retval negative     negated errno on error
907          */
908         int   (*do_ref_add)(const struct lu_env *env,
909                             struct dt_object *dt, struct thandle *th);
910
911         /**
912          * Declare intention to decrement nlink count.
913          *
914          * Notify the underlying filesystem that the nlink regular attribute
915          * be changed in this transaction. This enables the layer below to
916          * prepare resources (e.g. journal credits in ext4).  This method
917          * should be called between creating the transaction and starting it.
918          * The object need not exist.
919          *
920          * \param[in] env       execution environment for this thread
921          * \param[in] dt        object
922          * \param[in] th        transaction handle
923          *
924          * \retval 0            on success
925          * \retval negative     negated errno on error
926          */
927         int   (*do_declare_ref_del)(const struct lu_env *env,
928                                     struct dt_object *dt,
929                                     struct thandle *th);
930
931         /**
932          * Decrement nlink.
933          *
934          * Decrement nlink (from the regular attributes set) in the given
935          * transaction. The object must exist.
936          *
937          * \param[in] env       execution environment for this thread
938          * \param[in] dt        object
939          * \param[in] th        transaction handle
940          *
941          * \retval 0            on success
942          * \retval negative     negated errno on error
943          */
944         int   (*do_ref_del)(const struct lu_env *env,
945                             struct dt_object *dt,
946                             struct thandle *th);
947
948         /**
949          * Sync obect.
950          *
951          * The method is called to sync specified range of the object to a
952          * persistent storage. The control is returned once the operation is
953          * complete. The difference from ->do_sync() is that the object can
954          * be in-sync with the persistent storage (nothing to flush), then
955          * the method returns quickly with no I/O overhead. So, this method
956          * should be preferred over ->do_sync() where possible. Also note that
957          * if the object isn't clean, then some disk filesystems will call
958          * ->do_sync() to maintain overall consistency, in which case it's
959          * still very expensive.
960          *
961          * \param[in] env       execution environment for this thread
962          * \param[in] dt        object
963          * \param[in] start     start of the range to sync
964          * \param[in] end       end of the range to sync
965          *
966          * \retval 0            on success
967          * \retval negative     negated errno on error
968          */
969         int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
970                               __u64 start, __u64 end);
971
972         /**
973          * Lock object.
974          *
975          * Lock object(s) using Distributed Lock Manager (LDLM).
976          *
977          * Get LDLM locks for the object. Currently used to lock "remote"
978          * objects in DNE configuration - a service running on MDTx needs
979          * to lock an object on MDTy.
980          *
981          * \param[in] env       execution environment for this thread
982          * \param[in] dt        object
983          * \param[out] lh       lock handle, sometimes used, sometimes not
984          * \param[in] einfo     ldlm callbacks, locking type and mode
985          * \param[out] einfo    private data to be passed to unlock later
986          * \param[in] policy    inodebits data
987          *
988          * \retval 0            on success
989          * \retval negative     negated errno on error
990          */
991         int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
992                               struct lustre_handle *lh,
993                               struct ldlm_enqueue_info *einfo,
994                               union ldlm_policy_data *policy);
995
996         /**
997          * Unlock object.
998          *
999          * Release LDLM lock(s) granted with ->do_object_lock().
1000          *
1001          * \param[in] env       execution environment for this thread
1002          * \param[in] dt        object
1003          * \param[in] einfo     lock handles, from ->do_object_lock()
1004          * \param[in] policy    inodebits data
1005          *
1006          * \retval 0            on success
1007          * \retval negative     negated errno on error
1008          */
1009         int (*do_object_unlock)(const struct lu_env *env,
1010                                 struct dt_object *dt,
1011                                 struct ldlm_enqueue_info *einfo,
1012                                 union ldlm_policy_data *policy);
1013
1014         /**
1015          * Invalidate attribute cache.
1016          *
1017          * This method invalidate attribute cache of the object, which is on OSP
1018          * only.
1019          *
1020          * \param[in] env       execution envionment for this thread
1021          * \param[in] dt        object
1022          *
1023          * \retval 0            on success
1024          * \retval negative     negated errno on error
1025          */
1026         int   (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1027
1028         /**
1029          * Declare intention to instaintiate extended layout component.
1030          *
1031          * \param[in] env       execution environment
1032          * \param[in] dt        DT object
1033          * \param[in] layout    data structure to describe the changes to
1034          *                      the DT object's layout
1035          * \param[in] buf       buffer containing client's lovea or empty
1036          *
1037          * \retval 0            success
1038          * \retval -ne          error code
1039          */
1040         int (*do_declare_layout_change)(const struct lu_env *env,
1041                                         struct dt_object *dt,
1042                                         struct layout_intent *layout,
1043                                         const struct lu_buf *buf,
1044                                         struct thandle *th);
1045
1046         /**
1047          * Client is trying to write to un-instantiated layout component.
1048          *
1049          * \param[in] env       execution environment
1050          * \param[in] dt        DT object
1051          * \param[in] layout    data structure to describe the changes to
1052          *                      the DT object's layout
1053          * \param[in] buf       buffer containing client's lovea or empty
1054          *
1055          * \retval 0            success
1056          * \retval -ne          error code
1057          */
1058         int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1059                                 struct layout_intent *layout,
1060                                 const struct lu_buf *buf, struct thandle *th);
1061 };
1062
1063 enum dt_bufs_type {
1064         DT_BUFS_TYPE_READ       = 0x0000,
1065         DT_BUFS_TYPE_WRITE      = 0x0001,
1066         DT_BUFS_TYPE_READAHEAD  = 0x0002,
1067         DT_BUFS_TYPE_LOCAL      = 0x0004,
1068 };
1069
1070 /**
1071  * Per-dt-object operations on "file body" - unstructure raw data.
1072  */
1073 struct dt_body_operations {
1074         /**
1075          * Read data.
1076          *
1077          * Read unstructured data from an existing regular object.
1078          * Only data before attr.la_size is returned.
1079          *
1080          * \param[in] env       execution environment for this thread
1081          * \param[in] dt        object
1082          * \param[out] buf      buffer (including size) to copy data in
1083          * \param[in] pos       position in the object to start
1084          * \param[out] pos      original value of \a pos + bytes returned
1085          *
1086          * \retval positive     bytes read on success
1087          * \retval negative     negated errno on error
1088          */
1089         ssize_t (*dbo_read)(const struct lu_env *env,
1090                             struct dt_object *dt,
1091                             struct lu_buf *buf,
1092                             loff_t *pos);
1093
1094         /**
1095          * Declare intention to write data to object.
1096          *
1097          * Notify the underlying filesystem that data may be written in
1098          * this transaction. This enables the layer below to prepare resources
1099          * (e.g. journal credits in ext4).  This method should be called
1100          * between creating the transaction and starting it. The object need
1101          * not exist. If the layer implementing this method is responsible for
1102          * quota, then the method should reserve space for the given credentials
1103          * and return an error if quota is over. If the write later fails
1104          * for some reason, then the reserve should be released properly
1105          * (usually in ->dt_trans_stop()).
1106          *
1107          * \param[in] env       execution environment for this thread
1108          * \param[in] dt        object
1109          * \param[in] buf       buffer (including size) to copy data from
1110          * \param[in] pos       position in the object to start
1111          * \param[in] th        transaction handle
1112          *
1113          * \retval 0            on success
1114          * \retval negative     negated errno on error
1115          */
1116         ssize_t (*dbo_declare_write)(const struct lu_env *env,
1117                                      struct dt_object *dt,
1118                                      const struct lu_buf *buf,
1119                                      loff_t pos,
1120                                      struct thandle *th);
1121
1122         /**
1123          * Write unstructured data to regular existing object.
1124          *
1125          * The method allocates space and puts data in. Also, the method should
1126          * maintain attr.la_size properly. Partial writes are possible.
1127          *
1128          * If the layer implementing this method is responsible for quota,
1129          * then the method should maintain space accounting for the given
1130          * credentials.
1131          *
1132          * \param[in] env       execution environment for this thread
1133          * \param[in] dt        object
1134          * \param[in] buf       buffer (including size) to copy data from
1135          * \param[in] pos       position in the object to start
1136          * \param[out] pos      \a pos + bytes written
1137          * \param[in] th        transaction handle
1138          * \param[in] ignore    unused (was used to request quota ignorance)
1139          *
1140          * \retval positive     bytes written on success
1141          * \retval negative     negated errno on error
1142          */
1143         ssize_t (*dbo_write)(const struct lu_env *env,
1144                              struct dt_object *dt,
1145                              const struct lu_buf *buf,
1146                              loff_t *pos,
1147                              struct thandle *th,
1148                              int ignore);
1149
1150         /**
1151          * Return buffers for data.
1152          *
1153          * This method is used to access data with no copying. It's so-called
1154          * zero-copy I/O. The method returns the descriptors for the internal
1155          * buffers where data are managed by the disk filesystem. For example,
1156          * pagecache in case of ext4 or ARC with ZFS. Then other components
1157          * (e.g. networking) can transfer data from or to the buffers with no
1158          * additional copying.
1159          *
1160          * The method should fill an array of struct niobuf_local, where
1161          * each element describes a full or partial page for data at specific
1162          * offset. The caller should use page/lnb_page_offset/len to find data
1163          * at object's offset lnb_file_offset.
1164          *
1165          * The memory referenced by the descriptors can't change its purpose
1166          * until the complementary ->dbo_bufs_put() is called. The caller should
1167          * specify if the buffers are used to read or modify data so that OSD
1168          * can decide how to initialize the buffers: bring all the data for
1169          * reads or just bring partial buffers for write. Note: the method does
1170          * not check whether output array is large enough.
1171          *
1172          * \param[in] env       execution environment for this thread
1173          * \param[in] dt        object
1174          * \param[in] pos       position in the object to start
1175          * \param[in] len       size of region in bytes
1176          * \param[out] lb       array of descriptors to fill
1177          * \param[in] rw        0 if used to read, 1 if used for write
1178          *
1179          * \retval positive     number of descriptors on success
1180          * \retval negative     negated errno on error
1181          */
1182         int (*dbo_bufs_get)(const struct lu_env *env,
1183                             struct dt_object *dt,
1184                             loff_t pos,
1185                             ssize_t len,
1186                             struct niobuf_local *lb,
1187                             enum dt_bufs_type rw);
1188
1189         /**
1190          * Release reference granted by ->dbo_bufs_get().
1191          *
1192          * Release the reference granted by the previous ->dbo_bufs_get().
1193          * Note the references are counted.
1194          *
1195          * \param[in] env       execution environment for this thread
1196          * \param[in] dt        object
1197          * \param[out] lb       array of descriptors to fill
1198          * \param[in] nr        size of the array
1199          *
1200          * \retval 0            on success
1201          * \retval negative     negated errno on error
1202          */
1203         int (*dbo_bufs_put)(const struct lu_env *env,
1204                             struct dt_object *dt,
1205                             struct niobuf_local *lb,
1206                             int nr);
1207
1208         /**
1209          * Prepare buffers for reading.
1210          *
1211          * The method is called on the given buffers to fill them with data
1212          * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1213          * caller should be able to get few buffers for discontiguous regions
1214          * using few calls to ->dbo_bufs_get() and then request them all for
1215          * the preparation with a single call, so that OSD can fire many I/Os
1216          * to run concurrently. It's up to the specific OSD whether to implement
1217          * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1218          * prepare data for every requested region individually.
1219          *
1220          * \param[in] env       execution environment for this thread
1221          * \param[in] dt        object
1222          * \param[in] lnb       array of buffer descriptors
1223          * \param[in] nr        size of the array
1224          *
1225          * \retval 0            on success
1226          * \retval negative     negated errno on error
1227          */
1228         int (*dbo_read_prep)(const struct lu_env *env,
1229                              struct dt_object *dt,
1230                              struct niobuf_local *lnb,
1231                              int nr);
1232
1233         /**
1234          * Prepare buffers for write.
1235          *
1236          * This method is called on the given buffers to ensure the partial
1237          * buffers contain correct data. The underlying idea is the same as
1238          * in ->db_read_prep().
1239          *
1240          * \param[in] env       execution environment for this thread
1241          * \param[in] dt        object
1242          * \param[in] lb        array of buffer descriptors
1243          * \param[in] nr        size of the array
1244          *
1245          * \retval 0            on success
1246          * \retval negative     negated errno on error
1247          */
1248         int (*dbo_write_prep)(const struct lu_env *env,
1249                               struct dt_object *dt,
1250                               struct niobuf_local *lb,
1251                               int nr);
1252
1253         /**
1254          * Declare intention to write data stored in the buffers.
1255          *
1256          * Notify the underlying filesystem that data may be written in
1257          * this transaction. This enables the layer below to prepare resources
1258          * (e.g. journal credits in ext4).  This method should be called
1259          * between creating the transaction and starting it.
1260          *
1261          * If the layer implementing this method is responsible for quota,
1262          * then the method should be reserving a space for the given
1263          * credentials and return an error if quota is exceeded. If the write
1264          * later fails for some reason, then the reserve should be released
1265          * properly (usually in ->dt_trans_stop()).
1266          *
1267          * \param[in] env       execution environment for this thread
1268          * \param[in] dt        object
1269          * \param[in] lb        array of descriptors
1270          * \param[in] nr        size of the array
1271          * \param[in] th        transaction handle
1272          *
1273          * \retval 0            on success
1274          * \retval negative     negated errno on error
1275          */
1276         int (*dbo_declare_write_commit)(const struct lu_env *env,
1277                                         struct dt_object *dt,
1278                                         struct niobuf_local *lb,
1279                                         int nr,
1280                                         struct thandle *th);
1281
1282         /**
1283          * Write to existing object.
1284          *
1285          * This method is used to write data to a persistent storage using
1286          * the buffers returned by ->dbo_bufs_get(). The caller puts new
1287          * data into the buffers using own mechanisms (e.g. direct transfer
1288          * from a NIC). The method should maintain attr.la_size. Also,
1289          * attr.la_blocks should be maintained but this can be done in lazy
1290          * manner, when actual allocation happens.
1291          *
1292          * If the layer implementing this method is responsible for quota,
1293          * then the method should maintain space accounting for the given
1294          * credentials.
1295          *
1296          * \param[in] env       execution environment for this thread
1297          * \param[in] dt        object
1298          * \param[in] lb        array of descriptors for the buffers
1299          * \param[in] nr        size of the array
1300          * \param[in] th        transaction handle
1301          *
1302          * \retval 0            on success
1303          * \retval negative     negated errno on error
1304          */
1305         int (*dbo_write_commit)(const struct lu_env *env,
1306                                 struct dt_object *dt,
1307                                 struct niobuf_local *lb,
1308                                 int nr,
1309                                 struct thandle *th);
1310
1311         /**
1312          * Return logical to physical block mapping for a given extent
1313          *
1314          * \param[in] env       execution environment for this thread
1315          * \param[in] dt        object
1316          * \param[in] fm        describe the region to map and the output buffer
1317          *                      see the details in include/linux/fiemap.h
1318          *
1319          * \retval 0            on success
1320          * \retval negative     negated errno on error
1321          */
1322         int (*dbo_fiemap_get)(const struct lu_env *env,
1323                               struct dt_object *dt,
1324                               struct fiemap *fm);
1325
1326         /**
1327          * Declare intention to deallocate space from an object.
1328          *
1329          * Notify the underlying filesystem that space may be deallocated in
1330          * this transactions. This enables the layer below to prepare resources
1331          * (e.g. journal credits in ext4).  This method should be called between
1332          * creating the transaction and starting it. The object need not exist.
1333          *
1334          * \param[in] env       execution environment for this thread
1335          * \param[in] dt        object
1336          * \param[in] start     the start of the region to deallocate
1337          * \param[in] end       the end of the region to deallocate
1338          * \param[in] th        transaction handle
1339          *
1340          * \retval 0            on success
1341          * \retval negative     negated errno on error
1342          */
1343         int   (*dbo_declare_punch)(const struct lu_env *env,
1344                                    struct dt_object *dt,
1345                                    __u64 start,
1346                                    __u64 end,
1347                                    struct thandle *th);
1348
1349         /**
1350          * Deallocate specified region in an object.
1351          *
1352          * This method is used to deallocate (release) space possibly consumed
1353          * by the given region of the object. If the layer implementing this
1354          * method is responsible for quota, then the method should maintain
1355          * space accounting for the given credentials.
1356          *
1357          * \param[in] env       execution environment for this thread
1358          * \param[in] dt        object
1359          * \param[in] start     the start of the region to deallocate
1360          * \param[in] end       the end of the region to deallocate
1361          * \param[in] th        transaction handle
1362          *
1363          * \retval 0            on success
1364          * \retval negative     negated errno on error
1365          */
1366         int   (*dbo_punch)(const struct lu_env *env,
1367                            struct dt_object *dt,
1368                            __u64 start,
1369                            __u64 end,
1370                            struct thandle *th);
1371         /**
1372          * Give advices on specified region in an object.
1373          *
1374          * This method is used to give advices about access pattern on an
1375          * given region of the object. The disk filesystem understands
1376          * the advices and tunes cache/read-ahead policies.
1377          *
1378          * \param[in] env       execution environment for this thread
1379          * \param[in] dt        object
1380          * \param[in] start     the start of the region affected
1381          * \param[in] end       the end of the region affected
1382          * \param[in] advice    advice type
1383          *
1384          * \retval 0            on success
1385          * \retval negative     negated errno on error
1386          */
1387         int   (*dbo_ladvise)(const struct lu_env *env,
1388                              struct dt_object *dt,
1389                              __u64 start,
1390                              __u64 end,
1391                              enum lu_ladvise_type advice);
1392 };
1393
1394 /**
1395  * Incomplete type of index record.
1396  */
1397 struct dt_rec;
1398
1399 /**
1400  * Incomplete type of index key.
1401  */
1402 struct dt_key;
1403
1404 /**
1405  * Incomplete type of dt iterator.
1406  */
1407 struct dt_it;
1408
1409 /**
1410  * Per-dt-object operations on object as index. Index is a set of key/value
1411  * pairs abstracted from an on-disk representation. An index supports the
1412  * number of operations including lookup by key, insert and delete. Also,
1413  * an index can be iterated to find the pairs one by one, from a beginning
1414  * or specified point.
1415  */
1416 struct dt_index_operations {
1417         /**
1418          * Lookup in an index by key.
1419          *
1420          * The method returns a value for the given key. Key/value format
1421          * and size should have been negotiated with ->do_index_try() before.
1422          * Thus it's the caller's responsibility to provide the method with
1423          * proper key and big enough buffer. No external locking is required,
1424          * all the internal consistency should be implemented by the method
1425          * or lower layers. The object should should have been created with
1426          * type DFT_INDEX or DFT_DIR.
1427          *
1428          * \param[in] env       execution environment for this thread
1429          * \param[in] dt        object
1430          * \param[out] rec      buffer where value will be stored
1431          * \param[in] key       key
1432          *
1433          * \retval 0            on success
1434          * \retval -ENOENT      if key isn't found
1435          * \retval negative     negated errno on error
1436          */
1437         int (*dio_lookup)(const struct lu_env *env,
1438                           struct dt_object *dt,
1439                           struct dt_rec *rec,
1440                           const struct dt_key *key);
1441
1442         /**
1443          * Declare intention to insert a key/value into an index.
1444          *
1445          * Notify the underlying filesystem that new key/value may be inserted
1446          * in this transaction. This enables the layer below to prepare
1447          * resources (e.g. journal credits in ext4). This method should be
1448          * called between creating the transaction and starting it. key/value
1449          * format and size is subject to ->do_index_try().
1450          *
1451          * \param[in] env       execution environment for this thread
1452          * \param[in] dt        object
1453          * \param[in] rec       buffer storing value
1454          * \param[in] key       key
1455          * \param[in] th        transaction handle
1456          *
1457          * \retval 0            on success
1458          * \retval negative     negated errno on error
1459          */
1460         int (*dio_declare_insert)(const struct lu_env *env,
1461                                   struct dt_object *dt,
1462                                   const struct dt_rec *rec,
1463                                   const struct dt_key *key,
1464                                   struct thandle *th);
1465
1466         /**
1467          * Insert a new key/value pair into an index.
1468          *
1469          * The method inserts specified key/value pair into the given index
1470          * object. The internal consistency is maintained by the method or
1471          * the functionality below. The format and size of key/value should
1472          * have been negotiated before using ->do_index_try(), no additional
1473          * information can be specified to the method. The keys are unique
1474          * in a given index.
1475          *
1476          * \param[in] env       execution environment for this thread
1477          * \param[in] dt        object
1478          * \param[in] rec       buffer storing value
1479          * \param[in] key       key
1480          * \param[in] th        transaction handle
1481          * \param[in] ignore    unused (was used to request quota ignorance)
1482          *
1483          * \retval 0            on success
1484          * \retval negative     negated errno on error
1485          */
1486         int (*dio_insert)(const struct lu_env *env,
1487                           struct dt_object *dt,
1488                           const struct dt_rec *rec,
1489                           const struct dt_key *key,
1490                           struct thandle *th,
1491                           int ignore);
1492
1493         /**
1494          * Declare intention to delete a key/value from an index.
1495          *
1496          * Notify the underlying filesystem that key/value may be deleted in
1497          * this transaction. This enables the layer below to prepare resources
1498          * (e.g. journal credits in ext4).  This method should be called
1499          * between creating the transaction and starting it. Key/value format
1500          * and size is subject to ->do_index_try(). The object need not exist.
1501          *
1502          * \param[in] env       execution environment for this thread
1503          * \param[in] dt        object
1504          * \param[in] key       key
1505          * \param[in] th        transaction handle
1506          *
1507          * \retval 0            on success
1508          * \retval negative     negated errno on error
1509          */
1510         int (*dio_declare_delete)(const struct lu_env *env,
1511                                   struct dt_object *dt,
1512                                   const struct dt_key *key,
1513                                   struct thandle *th);
1514
1515         /**
1516          * Delete key/value pair from an index.
1517          *
1518          * The method deletes specified key and corresponding value from the
1519          * given index object. The internal consistency is maintained by the
1520          * method or the functionality below. The format and size of the key
1521          * should have been negotiated before using ->do_index_try(), no
1522          * additional information can be specified to the method.
1523          *
1524          * \param[in] env       execution environment for this thread
1525          * \param[in] dt        object
1526          * \param[in] key       key
1527          * \param[in] th        transaction handle
1528          *
1529          * \retval 0            on success
1530          * \retval negative     negated errno on error
1531          */
1532         int (*dio_delete)(const struct lu_env *env,
1533                           struct dt_object *dt,
1534                           const struct dt_key *key,
1535                           struct thandle *th);
1536
1537         /**
1538          * Iterator interface.
1539          *
1540          * Methods to iterate over an existing index, list the keys stored and
1541          * associated values, get key/value size, etc.
1542          */
1543         struct dt_it_ops {
1544                 /**
1545                  * Allocate and initialize new iterator.
1546                  *
1547                  * The iterator is a handler to be used in the subsequent
1548                  * methods to access index's content. Note the position is
1549                  * not defined at this point and should be initialized with
1550                  * ->get() or ->load() method.
1551                  *
1552                  * \param[in] env       execution environment for this thread
1553                  * \param[in] dt        object
1554                  * \param[in] attr      ask the iterator to return part of
1555                                         the records, see LUDA_* for details
1556                  *
1557                  * \retval pointer      iterator pointer on success
1558                  * \retval ERR_PTR(errno)       on error
1559                  */
1560                 struct dt_it *(*init)(const struct lu_env *env,
1561                                       struct dt_object *dt,
1562                                       __u32 attr);
1563
1564                 /**
1565                  * Release iterator.
1566                  *
1567                  * Release the specified iterator and all the resources
1568                  * associated (e.g. the object, index cache, etc).
1569                  *
1570                  * \param[in] env       execution environment for this thread
1571                  * \param[in] di        iterator to release
1572                  */
1573                 void          (*fini)(const struct lu_env *env,
1574                                       struct dt_it *di);
1575
1576                 /**
1577                  * Move position of iterator.
1578                  *
1579                  * Move the position of the specified iterator to the specified
1580                  * key.
1581                  *
1582                  * \param[in] env       execution environment for this thread
1583                  * \param[in] di        iterator
1584                  * \param[in] key       key to position to
1585                  *
1586                  * \retval 0            if exact key is found
1587                  * \retval 1            if at the record with least key
1588                  *                      not larger than the key
1589                  * \retval negative     negated errno on error
1590                  */
1591                 int            (*get)(const struct lu_env *env,
1592                                       struct dt_it *di,
1593                                       const struct dt_key *key);
1594
1595                 /**
1596                  * Release position
1597                  *
1598                  * Complimentary method for dt_it_ops::get() above. Some
1599                  * implementation can increase a reference on the iterator in
1600                  * dt_it_ops::get(). So the caller should be able to release
1601                  * with dt_it_ops::put().
1602                  *
1603                  * \param[in] env       execution environment for this thread
1604                  * \param[in] di        iterator
1605                  */
1606                 void           (*put)(const struct lu_env *env,
1607                                       struct dt_it *di);
1608
1609                 /**
1610                  * Move to next record.
1611                  *
1612                  * Moves the position of the iterator to a next record
1613                  *
1614                  * \param[in] env       execution environment for this thread
1615                  * \param[in] di        iterator
1616                  *
1617                  * \retval 1            if no more records
1618                  * \retval 0            on success, the next record is found
1619                  * \retval negative     negated errno on error
1620                  */
1621                 int           (*next)(const struct lu_env *env,
1622                                       struct dt_it *di);
1623
1624                 /**
1625                  * Return key.
1626                  *
1627                  * Returns a pointer to a buffer containing the key of the
1628                  * record at the current position. The pointer is valid and
1629                  * retains data until ->get(), ->load() and ->fini() methods
1630                  * are called.
1631                  *
1632                  * \param[in] env       execution environment for this thread
1633                  * \param[in] di        iterator
1634                  *
1635                  * \retval pointer to key       on success
1636                  * \retval ERR_PTR(errno)       on error
1637                  */
1638                 struct dt_key *(*key)(const struct lu_env *env,
1639                                       const struct dt_it *di);
1640
1641                 /**
1642                  * Return key size.
1643                  *
1644                  * Returns size of the key at the current position.
1645                  *
1646                  * \param[in] env       execution environment for this thread
1647                  * \param[in] di        iterator
1648                  *
1649                  * \retval key's size   on success
1650                  * \retval negative     negated errno on error
1651                  */
1652                 int       (*key_size)(const struct lu_env *env,
1653                                       const struct dt_it *di);
1654
1655                 /**
1656                  * Return record.
1657                  *
1658                  * Stores the value of the record at the current position. The
1659                  * buffer must be big enough (as negotiated with
1660                  * ->do_index_try() or ->rec_size()). The caller can specify
1661                  * she is interested only in part of the record, using attr
1662                  * argument (see LUDA_* definitions for the details).
1663                  *
1664                  * \param[in] env       execution environment for this thread
1665                  * \param[in] di        iterator
1666                  * \param[out] rec      buffer to store value in
1667                  * \param[in] attr      specify part of the value to copy
1668                  *
1669                  * \retval 0            on success
1670                  * \retval negative     negated errno on error
1671                  */
1672                 int            (*rec)(const struct lu_env *env,
1673                                       const struct dt_it *di,
1674                                       struct dt_rec *rec,
1675                                       __u32 attr);
1676
1677                 /**
1678                  * Return record size.
1679                  *
1680                  * Returns size of the record at the current position. The
1681                  * \a attr can be used to specify only the parts of the record
1682                  * needed to be returned. (see LUDA_* definitions for the
1683                  * details).
1684                  *
1685                  * \param[in] env       execution environment for this thread
1686                  * \param[in] di        iterator
1687                  * \param[in] attr      part of the record to return
1688                  *
1689                  * \retval record's size        on success
1690                  * \retval negative             negated errno on error
1691                  */
1692                 int        (*rec_size)(const struct lu_env *env,
1693                                        const struct dt_it *di,
1694                                       __u32 attr);
1695
1696                 /**
1697                  * Return a cookie (hash).
1698                  *
1699                  * Returns the cookie (usually hash) of the key at the current
1700                  * position. This allows the caller to resume iteration at this
1701                  * position later. The exact value is specific to implementation
1702                  * and should not be interpreted by the caller.
1703                  *
1704                  * \param[in] env       execution environment for this thread
1705                  * \param[in] di        iterator
1706                  *
1707                  * \retval cookie/hash of the key
1708                  */
1709                 __u64        (*store)(const struct lu_env *env,
1710                                       const struct dt_it *di);
1711
1712                 /**
1713                  * Initialize position using cookie/hash.
1714                  *
1715                  * Initializes the current position of the iterator to one
1716                  * described by the cookie/hash as returned by ->store()
1717                  * previously.
1718                  *
1719                  * \param[in] env       execution environment for this thread
1720                  * \param[in] di        iterator
1721                  * \param[in] hash      cookie/hash value
1722                  *
1723                  * \retval positive     if current position points to
1724                  *                      record with least cookie not larger
1725                  *                      than cookie
1726                  * \retval 0            if current position matches cookie
1727                  * \retval negative     negated errno on error
1728                  */
1729                 int           (*load)(const struct lu_env *env,
1730                                       const struct dt_it *di,
1731                                       __u64 hash);
1732
1733                 /**
1734                  * Not used
1735                  */
1736                 int        (*key_rec)(const struct lu_env *env,
1737                                       const struct dt_it *di,
1738                                       void *key_rec);
1739         } dio_it;
1740 };
1741
1742 enum dt_otable_it_valid {
1743         DOIV_ERROR_HANDLE       = 0x0001,
1744         DOIV_DRYRUN             = 0x0002,
1745 };
1746
1747 enum dt_otable_it_flags {
1748         /* Exit when fail. */
1749         DOIF_FAILOUT    = 0x0001,
1750
1751         /* Reset iteration position to the device beginning. */
1752         DOIF_RESET      = 0x0002,
1753
1754         /* There is up layer component uses the iteration. */
1755         DOIF_OUTUSED    = 0x0004,
1756
1757         /* Check only without repairing. */
1758         DOIF_DRYRUN     = 0x0008,
1759 };
1760
1761 /* otable based iteration needs to use the common DT iteration APIs.
1762  * To initialize the iteration, it needs call dio_it::init() firstly.
1763  * Here is how the otable based iteration should prepare arguments to
1764  * call dt_it_ops::init().
1765  *
1766  * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1767  * is composed of two parts:
1768  * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1769 #define DT_OTABLE_IT_FLAGS_SHIFT        16
1770 #define DT_OTABLE_IT_FLAGS_MASK         0xffff0000
1771
1772 struct dt_device {
1773         struct lu_device                   dd_lu_dev;
1774         const struct dt_device_operations *dd_ops;
1775
1776         /**
1777          * List of dt_txn_callback (see below). This is not protected in any
1778          * way, because callbacks are supposed to be added/deleted only during
1779          * single-threaded start-up shut-down procedures.
1780          */
1781         struct list_head                   dd_txn_callbacks;
1782         unsigned int                       dd_record_fid_accessed:1,
1783                                            dd_rdonly:1;
1784 };
1785
1786 int  dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1787 void dt_device_fini(struct dt_device *dev);
1788
1789 static inline int lu_device_is_dt(const struct lu_device *d)
1790 {
1791         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1792 }
1793
1794 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1795 {
1796         LASSERT(lu_device_is_dt(l));
1797         return container_of0(l, struct dt_device, dd_lu_dev);
1798 }
1799
1800 struct dt_object {
1801         struct lu_object                   do_lu;
1802         const struct dt_object_operations *do_ops;
1803         const struct dt_body_operations   *do_body_ops;
1804         const struct dt_index_operations  *do_index_ops;
1805 };
1806
1807 /*
1808  * In-core representation of per-device local object OID storage
1809  */
1810 struct local_oid_storage {
1811         /* all initialized llog systems on this node linked by this */
1812         struct list_head  los_list;
1813
1814         /* how many handle's reference this los has */
1815         atomic_t          los_refcount;
1816         struct dt_device *los_dev;
1817         struct dt_object *los_obj;
1818
1819         /* data used to generate new fids */
1820         struct mutex      los_id_lock;
1821         __u64             los_seq;
1822         __u32             los_last_oid;
1823 };
1824
1825 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1826 {
1827         return &d->dd_lu_dev;
1828 }
1829
1830 static inline struct dt_object *lu2dt(struct lu_object *l)
1831 {
1832         LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1833         return container_of0(l, struct dt_object, do_lu);
1834 }
1835
1836 int  dt_object_init(struct dt_object *obj,
1837                     struct lu_object_header *h, struct lu_device *d);
1838
1839 void dt_object_fini(struct dt_object *obj);
1840
1841 static inline int dt_object_exists(const struct dt_object *dt)
1842 {
1843         return lu_object_exists(&dt->do_lu);
1844 }
1845
1846 static inline int dt_object_remote(const struct dt_object *dt)
1847 {
1848         return lu_object_remote(&dt->do_lu);
1849 }
1850
1851 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1852 {
1853         LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1854         return container_of0(o, struct dt_object, do_lu);
1855 }
1856
1857 static inline struct dt_object *dt_object_child(struct dt_object *o)
1858 {
1859         return container_of0(lu_object_next(&(o)->do_lu),
1860                              struct dt_object, do_lu);
1861 }
1862
1863 /**
1864  * This is the general purpose transaction handle.
1865  * 1. Transaction Life Cycle
1866  *      This transaction handle is allocated upon starting a new transaction,
1867  *      and deallocated after this transaction is committed.
1868  * 2. Transaction Nesting
1869  *      We do _NOT_ support nested transaction. So, every thread should only
1870  *      have one active transaction, and a transaction only belongs to one
1871  *      thread. Due to this, transaction handle need no reference count.
1872  * 3. Transaction & dt_object locking
1873  *      dt_object locks should be taken inside transaction.
1874  * 4. Transaction & RPC
1875  *      No RPC request should be issued inside transaction.
1876  */
1877 struct thandle {
1878         /** the dt device on which the transactions are executed */
1879         struct dt_device *th_dev;
1880
1881         /* point to the top thandle, XXX this is a bit hacky right now,
1882          * but normal device trans callback triggered by the bottom
1883          * device (OSP/OSD == sub thandle layer) needs to get the
1884          * top_thandle (see dt_txn_hook_start/stop()), so we put the
1885          * top thandle here for now, will fix it when we have better
1886          * callback mechanism */
1887         struct thandle  *th_top;
1888         /** context for this transaction, tag is LCT_TX_HANDLE */
1889         struct lu_context th_ctx;
1890
1891         /** additional tags (layers can add in declare) */
1892         __u32             th_tags;
1893
1894         /** the last operation result in this transaction.
1895          * this value is used in recovery */
1896         __s32             th_result;
1897
1898         /** whether we need sync commit */
1899         unsigned int            th_sync:1,
1900         /* local transation, no need to inform other layers */
1901                                 th_local:1,
1902         /* Whether we need wait the transaction to be submitted
1903          * (send to remote target) */
1904                                 th_wait_submit:1,
1905         /* complex transaction which will track updates on all targets,
1906          * including OSTs */
1907                                 th_complex:1;
1908 };
1909
1910 /**
1911  * Transaction call-backs.
1912  *
1913  * These are invoked by osd (or underlying transaction engine) when
1914  * transaction changes state.
1915  *
1916  * Call-backs are used by upper layers to modify transaction parameters and to
1917  * perform some actions on for each transaction state transition. Typical
1918  * example is mdt registering call-back to write into last-received file
1919  * before each transaction commit.
1920  */
1921 struct dt_txn_callback {
1922         int (*dtc_txn_start)(const struct lu_env *env,
1923                              struct thandle *txn, void *cookie);
1924         int (*dtc_txn_stop)(const struct lu_env *env,
1925                             struct thandle *txn, void *cookie);
1926         void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1927         void                    *dtc_cookie;
1928         __u32                   dtc_tag;
1929         struct list_head        dtc_linkage;
1930 };
1931
1932 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1933 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1934
1935 int dt_txn_hook_start(const struct lu_env *env,
1936                       struct dt_device *dev, struct thandle *txn);
1937 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1938 void dt_txn_hook_commit(struct thandle *txn);
1939
1940 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1941
1942 /**
1943  * Callback function used for parsing path.
1944  * \see llo_store_resolve
1945  */
1946 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1947                             const char *name,
1948                             void *pvt);
1949
1950 #define DT_MAX_PATH 1024
1951
1952 int dt_path_parser(const struct lu_env *env,
1953                    char *local, dt_entry_func_t entry_func,
1954                    void *data);
1955
1956 struct dt_object *
1957 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1958                  const char *path, struct lu_fid *fid);
1959
1960 struct dt_object *dt_store_open(const struct lu_env *env,
1961                                 struct dt_device *dt,
1962                                 const char *dirname,
1963                                 const char *filename,
1964                                 struct lu_fid *fid);
1965
1966 struct dt_object *dt_find_or_create(const struct lu_env *env,
1967                                     struct dt_device *dt,
1968                                     const struct lu_fid *fid,
1969                                     struct dt_object_format *dof,
1970                                     struct lu_attr *attr);
1971
1972 struct dt_object *dt_locate_at(const struct lu_env *env,
1973                                struct dt_device *dev,
1974                                const struct lu_fid *fid,
1975                                struct lu_device *top_dev,
1976                                const struct lu_object_conf *conf);
1977
1978 static inline struct dt_object *
1979 dt_locate(const struct lu_env *env, struct dt_device *dev,
1980           const struct lu_fid *fid)
1981 {
1982         return dt_locate_at(env, dev, fid,
1983                             dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1984 }
1985
1986 static inline struct dt_object *
1987 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1988 {
1989         struct lu_object *lo;
1990
1991         list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
1992                 if (lo->lo_dev == &dt_dev->dd_lu_dev)
1993                         return container_of(lo, struct dt_object, do_lu);
1994         }
1995         return NULL;
1996 }
1997
1998 static inline void dt_object_put(const struct lu_env *env,
1999                                  struct dt_object *dto)
2000 {
2001         lu_object_put(env, &dto->do_lu);
2002 }
2003
2004 static inline void dt_object_put_nocache(const struct lu_env *env,
2005                                          struct dt_object *dto)
2006 {
2007         lu_object_put_nocache(env, &dto->do_lu);
2008 }
2009
2010 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2011                            const struct lu_fid *first_fid,
2012                            struct local_oid_storage **los);
2013 void local_oid_storage_fini(const struct lu_env *env,
2014                             struct local_oid_storage *los);
2015 int local_object_fid_generate(const struct lu_env *env,
2016                               struct local_oid_storage *los,
2017                               struct lu_fid *fid);
2018 int local_object_declare_create(const struct lu_env *env,
2019                                 struct local_oid_storage *los,
2020                                 struct dt_object *o,
2021                                 struct lu_attr *attr,
2022                                 struct dt_object_format *dof,
2023                                 struct thandle *th);
2024 int local_object_create(const struct lu_env *env,
2025                         struct local_oid_storage *los,
2026                         struct dt_object *o,
2027                         struct lu_attr *attr, struct dt_object_format *dof,
2028                         struct thandle *th);
2029 struct dt_object *local_file_find(const struct lu_env *env,
2030                                   struct local_oid_storage *los,
2031                                   struct dt_object *parent,
2032                                   const char *name);
2033 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2034                                             struct local_oid_storage *los,
2035                                             struct dt_object *parent,
2036                                             const char *name, __u32 mode);
2037 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2038                                                      struct dt_device *dt,
2039                                                      const struct lu_fid *fid,
2040                                                      struct dt_object *parent,
2041                                                      const char *name,
2042                                                      __u32 mode);
2043 struct dt_object *
2044 local_index_find_or_create(const struct lu_env *env,
2045                            struct local_oid_storage *los,
2046                            struct dt_object *parent,
2047                            const char *name, __u32 mode,
2048                            const struct dt_index_features *ft);
2049 struct dt_object *
2050 local_index_find_or_create_with_fid(const struct lu_env *env,
2051                                     struct dt_device *dt,
2052                                     const struct lu_fid *fid,
2053                                     struct dt_object *parent,
2054                                     const char *name, __u32 mode,
2055                                     const struct dt_index_features *ft);
2056 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2057                         struct dt_object *parent, const char *name);
2058
2059 static inline int dt_object_lock(const struct lu_env *env,
2060                                  struct dt_object *o, struct lustre_handle *lh,
2061                                  struct ldlm_enqueue_info *einfo,
2062                                  union ldlm_policy_data *policy)
2063 {
2064         LASSERT(o != NULL);
2065         LASSERT(o->do_ops != NULL);
2066         LASSERT(o->do_ops->do_object_lock != NULL);
2067         return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2068 }
2069
2070 static inline int dt_object_unlock(const struct lu_env *env,
2071                                    struct dt_object *o,
2072                                    struct ldlm_enqueue_info *einfo,
2073                                    union ldlm_policy_data *policy)
2074 {
2075         LASSERT(o != NULL);
2076         LASSERT(o->do_ops != NULL);
2077         LASSERT(o->do_ops->do_object_unlock != NULL);
2078         return o->do_ops->do_object_unlock(env, o, einfo, policy);
2079 }
2080
2081 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2082                   const char *name, struct lu_fid *fid);
2083
2084 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2085                                  __u64 start, __u64 end)
2086 {
2087         LASSERT(o);
2088         LASSERT(o->do_ops);
2089         LASSERT(o->do_ops->do_object_sync);
2090         return o->do_ops->do_object_sync(env, o, start, end);
2091 }
2092
2093 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2094                            struct thandle *th);
2095 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2096                     dt_obj_version_t version, struct thandle *th);
2097 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2098
2099
2100 int dt_read(const struct lu_env *env, struct dt_object *dt,
2101             struct lu_buf *buf, loff_t *pos);
2102 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2103                    struct lu_buf *buf, loff_t *pos);
2104 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2105                     const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2106 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2107                                      union lu_page *lp, size_t nob,
2108                                      const struct dt_it_ops *iops,
2109                                      struct dt_it *it, __u32 attr, void *arg);
2110 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2111                   const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2112                   void *arg);
2113 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2114                   struct idx_info *ii, const struct lu_rdpg *rdpg);
2115
2116 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2117                                               struct dt_device *d)
2118 {
2119         LASSERT(d->dd_ops->dt_trans_create);
2120         return d->dd_ops->dt_trans_create(env, d);
2121 }
2122
2123 static inline int dt_trans_start(const struct lu_env *env,
2124                                  struct dt_device *d, struct thandle *th)
2125 {
2126         LASSERT(d->dd_ops->dt_trans_start);
2127         return d->dd_ops->dt_trans_start(env, d, th);
2128 }
2129
2130 /* for this transaction hooks shouldn't be called */
2131 static inline int dt_trans_start_local(const struct lu_env *env,
2132                                        struct dt_device *d, struct thandle *th)
2133 {
2134         LASSERT(d->dd_ops->dt_trans_start);
2135         th->th_local = 1;
2136         return d->dd_ops->dt_trans_start(env, d, th);
2137 }
2138
2139 static inline int dt_trans_stop(const struct lu_env *env,
2140                                 struct dt_device *d, struct thandle *th)
2141 {
2142         LASSERT(d->dd_ops->dt_trans_stop);
2143         return d->dd_ops->dt_trans_stop(env, d, th);
2144 }
2145
2146 static inline int dt_trans_cb_add(struct thandle *th,
2147                                   struct dt_txn_commit_cb *dcb)
2148 {
2149         LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2150         dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2151         return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2152 }
2153 /** @} dt */
2154
2155
2156 static inline int dt_declare_record_write(const struct lu_env *env,
2157                                           struct dt_object *dt,
2158                                           const struct lu_buf *buf,
2159                                           loff_t pos,
2160                                           struct thandle *th)
2161 {
2162         int rc;
2163
2164         LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2165         LASSERT(th != NULL);
2166         LASSERT(dt->do_body_ops);
2167         LASSERT(dt->do_body_ops->dbo_declare_write);
2168         rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2169         return rc;
2170 }
2171
2172 static inline int dt_declare_create(const struct lu_env *env,
2173                                     struct dt_object *dt,
2174                                     struct lu_attr *attr,
2175                                     struct dt_allocation_hint *hint,
2176                                     struct dt_object_format *dof,
2177                                     struct thandle *th)
2178 {
2179         LASSERT(dt);
2180         LASSERT(dt->do_ops);
2181         LASSERT(dt->do_ops->do_declare_create);
2182
2183         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2184                 return cfs_fail_err;
2185
2186         return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2187 }
2188
2189 static inline int dt_create(const struct lu_env *env,
2190                                     struct dt_object *dt,
2191                                     struct lu_attr *attr,
2192                                     struct dt_allocation_hint *hint,
2193                                     struct dt_object_format *dof,
2194                                     struct thandle *th)
2195 {
2196         LASSERT(dt);
2197         LASSERT(dt->do_ops);
2198         LASSERT(dt->do_ops->do_create);
2199
2200         if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2201                 return cfs_fail_err;
2202
2203         return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2204 }
2205
2206 static inline int dt_declare_destroy(const struct lu_env *env,
2207                                      struct dt_object *dt,
2208                                      struct thandle *th)
2209 {
2210         LASSERT(dt);
2211         LASSERT(dt->do_ops);
2212         LASSERT(dt->do_ops->do_declare_destroy);
2213
2214         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2215                 return cfs_fail_err;
2216
2217         return dt->do_ops->do_declare_destroy(env, dt, th);
2218 }
2219
2220 static inline int dt_destroy(const struct lu_env *env,
2221                              struct dt_object *dt,
2222                              struct thandle *th)
2223 {
2224         LASSERT(dt);
2225         LASSERT(dt->do_ops);
2226         LASSERT(dt->do_ops->do_destroy);
2227
2228         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2229                 return cfs_fail_err;
2230
2231         return dt->do_ops->do_destroy(env, dt, th);
2232 }
2233
2234 static inline void dt_read_lock(const struct lu_env *env,
2235                                 struct dt_object *dt,
2236                                 unsigned role)
2237 {
2238         LASSERT(dt);
2239         LASSERT(dt->do_ops);
2240         LASSERT(dt->do_ops->do_read_lock);
2241         dt->do_ops->do_read_lock(env, dt, role);
2242 }
2243
2244 static inline void dt_write_lock(const struct lu_env *env,
2245                                 struct dt_object *dt,
2246                                 unsigned role)
2247 {
2248         LASSERT(dt);
2249         LASSERT(dt->do_ops);
2250         LASSERT(dt->do_ops->do_write_lock);
2251         dt->do_ops->do_write_lock(env, dt, role);
2252 }
2253
2254 static inline void dt_read_unlock(const struct lu_env *env,
2255                                 struct dt_object *dt)
2256 {
2257         LASSERT(dt);
2258         LASSERT(dt->do_ops);
2259         LASSERT(dt->do_ops->do_read_unlock);
2260         dt->do_ops->do_read_unlock(env, dt);
2261 }
2262
2263 static inline void dt_write_unlock(const struct lu_env *env,
2264                                 struct dt_object *dt)
2265 {
2266         LASSERT(dt);
2267         LASSERT(dt->do_ops);
2268         LASSERT(dt->do_ops->do_write_unlock);
2269         dt->do_ops->do_write_unlock(env, dt);
2270 }
2271
2272 static inline int dt_write_locked(const struct lu_env *env,
2273                                   struct dt_object *dt)
2274 {
2275         LASSERT(dt);
2276         LASSERT(dt->do_ops);
2277         LASSERT(dt->do_ops->do_write_locked);
2278         return dt->do_ops->do_write_locked(env, dt);
2279 }
2280
2281 static inline int dt_declare_attr_get(const struct lu_env *env,
2282                                       struct dt_object *dt)
2283 {
2284         LASSERT(dt);
2285         LASSERT(dt->do_ops);
2286         LASSERT(dt->do_ops->do_declare_attr_get);
2287
2288         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2289                 return cfs_fail_err;
2290
2291         return dt->do_ops->do_declare_attr_get(env, dt);
2292 }
2293
2294 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2295                               struct lu_attr *la)
2296 {
2297         LASSERT(dt);
2298         LASSERT(dt->do_ops);
2299         LASSERT(dt->do_ops->do_attr_get);
2300
2301         if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2302                 return cfs_fail_err;
2303
2304         return dt->do_ops->do_attr_get(env, dt, la);
2305 }
2306
2307 static inline int dt_declare_attr_set(const struct lu_env *env,
2308                                       struct dt_object *dt,
2309                                       const struct lu_attr *la,
2310                                       struct thandle *th)
2311 {
2312         LASSERT(dt);
2313         LASSERT(dt->do_ops);
2314         LASSERT(dt->do_ops->do_declare_attr_set);
2315
2316         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2317                 return cfs_fail_err;
2318
2319         return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2320 }
2321
2322 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2323                               const struct lu_attr *la, struct thandle *th)
2324 {
2325         LASSERT(dt);
2326         LASSERT(dt->do_ops);
2327         LASSERT(dt->do_ops->do_attr_set);
2328
2329         if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2330                 return cfs_fail_err;
2331
2332         return dt->do_ops->do_attr_set(env, dt, la, th);
2333 }
2334
2335 static inline int dt_declare_ref_add(const struct lu_env *env,
2336                                      struct dt_object *dt, struct thandle *th)
2337 {
2338         LASSERT(dt);
2339         LASSERT(dt->do_ops);
2340         LASSERT(dt->do_ops->do_declare_ref_add);
2341
2342         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2343                 return cfs_fail_err;
2344
2345         return dt->do_ops->do_declare_ref_add(env, dt, th);
2346 }
2347
2348 static inline int dt_ref_add(const struct lu_env *env,
2349                              struct dt_object *dt, struct thandle *th)
2350 {
2351         LASSERT(dt);
2352         LASSERT(dt->do_ops);
2353         LASSERT(dt->do_ops->do_ref_add);
2354
2355         if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2356                 return cfs_fail_err;
2357
2358         return dt->do_ops->do_ref_add(env, dt, th);
2359 }
2360
2361 static inline int dt_declare_ref_del(const struct lu_env *env,
2362                                      struct dt_object *dt, struct thandle *th)
2363 {
2364         LASSERT(dt);
2365         LASSERT(dt->do_ops);
2366         LASSERT(dt->do_ops->do_declare_ref_del);
2367
2368         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2369                 return cfs_fail_err;
2370
2371         return dt->do_ops->do_declare_ref_del(env, dt, th);
2372 }
2373
2374 static inline int dt_ref_del(const struct lu_env *env,
2375                              struct dt_object *dt, struct thandle *th)
2376 {
2377         LASSERT(dt);
2378         LASSERT(dt->do_ops);
2379         LASSERT(dt->do_ops->do_ref_del);
2380
2381         if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2382                 return cfs_fail_err;
2383
2384         return dt->do_ops->do_ref_del(env, dt, th);
2385 }
2386
2387 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2388                               struct niobuf_remote *rnb,
2389                               struct niobuf_local *lnb, enum dt_bufs_type rw)
2390 {
2391         LASSERT(d);
2392         LASSERT(d->do_body_ops);
2393         LASSERT(d->do_body_ops->dbo_bufs_get);
2394         return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2395                                             rnb->rnb_len, lnb, rw);
2396 }
2397
2398 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2399                               struct niobuf_local *lnb, int n)
2400 {
2401         LASSERT(d);
2402         LASSERT(d->do_body_ops);
2403         LASSERT(d->do_body_ops->dbo_bufs_put);
2404         return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2405 }
2406
2407 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2408                                 struct niobuf_local *lnb, int n)
2409 {
2410         LASSERT(d);
2411         LASSERT(d->do_body_ops);
2412         LASSERT(d->do_body_ops->dbo_write_prep);
2413         return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2414 }
2415
2416 static inline int dt_declare_write_commit(const struct lu_env *env,
2417                                           struct dt_object *d,
2418                                           struct niobuf_local *lnb,
2419                                           int n, struct thandle *th)
2420 {
2421         LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2422         LASSERT(th != NULL);
2423         return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2424 }
2425
2426
2427 static inline int dt_write_commit(const struct lu_env *env,
2428                                   struct dt_object *d, struct niobuf_local *lnb,
2429                                   int n, struct thandle *th)
2430 {
2431         LASSERT(d);
2432         LASSERT(d->do_body_ops);
2433         LASSERT(d->do_body_ops->dbo_write_commit);
2434         return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2435 }
2436
2437 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2438                                struct niobuf_local *lnb, int n)
2439 {
2440         LASSERT(d);
2441         LASSERT(d->do_body_ops);
2442         LASSERT(d->do_body_ops->dbo_read_prep);
2443         return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2444 }
2445
2446 static inline int dt_declare_write(const struct lu_env *env,
2447                                    struct dt_object *dt,
2448                                    const struct lu_buf *buf, loff_t pos,
2449                                    struct thandle *th)
2450 {
2451         LASSERT(dt);
2452         LASSERT(dt->do_body_ops);
2453         LASSERT(dt->do_body_ops->dbo_declare_write);
2454         return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2455 }
2456
2457 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2458                                const struct lu_buf *buf, loff_t *pos,
2459                                struct thandle *th, int rq)
2460 {
2461         LASSERT(dt);
2462         LASSERT(dt->do_body_ops);
2463         LASSERT(dt->do_body_ops->dbo_write);
2464         return dt->do_body_ops->dbo_write(env, dt, buf, pos, th, rq);
2465 }
2466
2467 static inline int dt_declare_punch(const struct lu_env *env,
2468                                    struct dt_object *dt, __u64 start,
2469                                    __u64 end, struct thandle *th)
2470 {
2471         LASSERT(dt);
2472         LASSERT(dt->do_body_ops);
2473         LASSERT(dt->do_body_ops->dbo_declare_punch);
2474         return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2475 }
2476
2477 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2478                            __u64 start, __u64 end, struct thandle *th)
2479 {
2480         LASSERT(dt);
2481         LASSERT(dt->do_body_ops);
2482         LASSERT(dt->do_body_ops->dbo_punch);
2483         return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2484 }
2485
2486 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2487                              __u64 start, __u64 end, int advice)
2488 {
2489         LASSERT(dt);
2490         LASSERT(dt->do_body_ops);
2491         LASSERT(dt->do_body_ops->dbo_ladvise);
2492         return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2493 }
2494
2495 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2496                                 struct fiemap *fm)
2497 {
2498         LASSERT(d);
2499         if (d->do_body_ops == NULL)
2500                 return -EPROTO;
2501         if (d->do_body_ops->dbo_fiemap_get == NULL)
2502                 return -EOPNOTSUPP;
2503         return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2504 }
2505
2506 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2507                             struct obd_statfs *osfs)
2508 {
2509         LASSERT(dev);
2510         LASSERT(dev->dd_ops);
2511         LASSERT(dev->dd_ops->dt_statfs);
2512         return dev->dd_ops->dt_statfs(env, dev, osfs);
2513 }
2514
2515 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2516                               struct lu_fid *f)
2517 {
2518         LASSERT(dev);
2519         LASSERT(dev->dd_ops);
2520         LASSERT(dev->dd_ops->dt_root_get);
2521         return dev->dd_ops->dt_root_get(env, dev, f);
2522 }
2523
2524 static inline void dt_conf_get(const struct lu_env *env,
2525                                const struct dt_device *dev,
2526                                struct dt_device_param *param)
2527 {
2528         LASSERT(dev);
2529         LASSERT(dev->dd_ops);
2530         LASSERT(dev->dd_ops->dt_conf_get);
2531         return dev->dd_ops->dt_conf_get(env, dev, param);
2532 }
2533
2534 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2535 {
2536         LASSERT(dev);
2537         LASSERT(dev->dd_ops);
2538         LASSERT(dev->dd_ops->dt_sync);
2539         return dev->dd_ops->dt_sync(env, dev);
2540 }
2541
2542 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2543 {
2544         LASSERT(dev);
2545         LASSERT(dev->dd_ops);
2546         LASSERT(dev->dd_ops->dt_ro);
2547         return dev->dd_ops->dt_ro(env, dev);
2548 }
2549
2550 static inline int dt_declare_insert(const struct lu_env *env,
2551                                     struct dt_object *dt,
2552                                     const struct dt_rec *rec,
2553                                     const struct dt_key *key,
2554                                     struct thandle *th)
2555 {
2556         LASSERT(dt);
2557         LASSERT(dt->do_index_ops);
2558         LASSERT(dt->do_index_ops->dio_declare_insert);
2559
2560         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2561                 return cfs_fail_err;
2562
2563         return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2564 }
2565
2566 static inline int dt_insert(const struct lu_env *env,
2567                                     struct dt_object *dt,
2568                                     const struct dt_rec *rec,
2569                                     const struct dt_key *key,
2570                                     struct thandle *th,
2571                                     int noquota)
2572 {
2573         LASSERT(dt);
2574         LASSERT(dt->do_index_ops);
2575         LASSERT(dt->do_index_ops->dio_insert);
2576
2577         if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2578                 return cfs_fail_err;
2579
2580         return dt->do_index_ops->dio_insert(env, dt, rec, key, th, noquota);
2581 }
2582
2583 static inline int dt_declare_xattr_del(const struct lu_env *env,
2584                                        struct dt_object *dt,
2585                                        const char *name,
2586                                        struct thandle *th)
2587 {
2588         LASSERT(dt);
2589         LASSERT(dt->do_ops);
2590         LASSERT(dt->do_ops->do_declare_xattr_del);
2591
2592         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2593                 return cfs_fail_err;
2594
2595         return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2596 }
2597
2598 static inline int dt_xattr_del(const struct lu_env *env,
2599                                struct dt_object *dt, const char *name,
2600                                struct thandle *th)
2601 {
2602         LASSERT(dt);
2603         LASSERT(dt->do_ops);
2604         LASSERT(dt->do_ops->do_xattr_del);
2605
2606         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2607                 return cfs_fail_err;
2608
2609         return dt->do_ops->do_xattr_del(env, dt, name, th);
2610 }
2611
2612 static inline int dt_declare_xattr_set(const struct lu_env *env,
2613                                       struct dt_object *dt,
2614                                       const struct lu_buf *buf,
2615                                       const char *name, int fl,
2616                                       struct thandle *th)
2617 {
2618         LASSERT(dt);
2619         LASSERT(dt->do_ops);
2620         LASSERT(dt->do_ops->do_declare_xattr_set);
2621
2622         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2623                 return cfs_fail_err;
2624
2625         return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2626 }
2627
2628 static inline int dt_xattr_set(const struct lu_env *env,
2629                                struct dt_object *dt, const struct lu_buf *buf,
2630                                const char *name, int fl, struct thandle *th)
2631 {
2632         LASSERT(dt);
2633         LASSERT(dt->do_ops);
2634         LASSERT(dt->do_ops->do_xattr_set);
2635
2636         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2637                 return cfs_fail_err;
2638
2639         return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2640 }
2641
2642 static inline int dt_declare_xattr_get(const struct lu_env *env,
2643                                        struct dt_object *dt,
2644                                        struct lu_buf *buf,
2645                                        const char *name)
2646 {
2647         LASSERT(dt);
2648         LASSERT(dt->do_ops);
2649         LASSERT(dt->do_ops->do_declare_xattr_get);
2650
2651         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2652                 return cfs_fail_err;
2653
2654         return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2655 }
2656
2657 static inline int dt_xattr_get(const struct lu_env *env,
2658                                struct dt_object *dt, struct lu_buf *buf,
2659                                const char *name)
2660 {
2661         LASSERT(dt);
2662         LASSERT(dt->do_ops);
2663         LASSERT(dt->do_ops->do_xattr_get);
2664
2665         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2666                 return cfs_fail_err;
2667
2668         return dt->do_ops->do_xattr_get(env, dt, buf, name);
2669 }
2670
2671 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2672                                 const struct lu_buf *buf)
2673 {
2674         LASSERT(dt);
2675         LASSERT(dt->do_ops);
2676         LASSERT(dt->do_ops->do_xattr_list);
2677
2678         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2679                 return cfs_fail_err;
2680
2681         return dt->do_ops->do_xattr_list(env, dt, buf);
2682 }
2683
2684 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2685 {
2686         LASSERT(dt);
2687         LASSERT(dt->do_ops);
2688         LASSERT(dt->do_ops->do_invalidate);
2689
2690         return dt->do_ops->do_invalidate(env, dt);
2691 }
2692
2693 static inline int dt_declare_delete(const struct lu_env *env,
2694                                     struct dt_object *dt,
2695                                     const struct dt_key *key,
2696                                     struct thandle *th)
2697 {
2698         LASSERT(dt);
2699         LASSERT(dt->do_index_ops);
2700         LASSERT(dt->do_index_ops->dio_declare_delete);
2701
2702         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2703                 return cfs_fail_err;
2704
2705         return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2706 }
2707
2708 static inline int dt_delete(const struct lu_env *env,
2709                             struct dt_object *dt,
2710                             const struct dt_key *key,
2711                             struct thandle *th)
2712 {
2713         LASSERT(dt);
2714         LASSERT(dt->do_index_ops);
2715         LASSERT(dt->do_index_ops->dio_delete);
2716
2717         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2718                 return cfs_fail_err;
2719
2720         return dt->do_index_ops->dio_delete(env, dt, key, th);
2721 }
2722
2723 static inline int dt_commit_async(const struct lu_env *env,
2724                                   struct dt_device *dev)
2725 {
2726         LASSERT(dev);
2727         LASSERT(dev->dd_ops);
2728         LASSERT(dev->dd_ops->dt_commit_async);
2729         return dev->dd_ops->dt_commit_async(env, dev);
2730 }
2731
2732 static inline int dt_lookup(const struct lu_env *env,
2733                             struct dt_object *dt,
2734                             struct dt_rec *rec,
2735                             const struct dt_key *key)
2736 {
2737         int ret;
2738
2739         LASSERT(dt);
2740         LASSERT(dt->do_index_ops);
2741         LASSERT(dt->do_index_ops->dio_lookup);
2742
2743         if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2744                 return cfs_fail_err;
2745
2746         ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2747         if (ret > 0)
2748                 ret = 0;
2749         else if (ret == 0)
2750                 ret = -ENOENT;
2751         return ret;
2752 }
2753
2754 static inline int dt_declare_layout_change(const struct lu_env *env,
2755                                            struct dt_object *o,
2756                                            struct layout_intent *layout,
2757                                            const struct lu_buf *buf,
2758                                            struct thandle *th)
2759 {
2760         LASSERT(o);
2761         LASSERT(o->do_ops);
2762         LASSERT(o->do_ops->do_declare_layout_change);
2763         return o->do_ops->do_declare_layout_change(env, o, layout, buf, th);
2764 }
2765
2766 static inline int dt_layout_change(const struct lu_env *env,
2767                                    struct dt_object *o,
2768                                    struct layout_intent *layout,
2769                                    const struct lu_buf *buf,
2770                                    struct thandle *th)
2771 {
2772         LASSERT(o);
2773         LASSERT(o->do_ops);
2774         LASSERT(o->do_ops->do_layout_change);
2775         return o->do_ops->do_layout_change(env, o, layout, buf, th);
2776 }
2777
2778 struct dt_find_hint {
2779         struct lu_fid        *dfh_fid;
2780         struct dt_device     *dfh_dt;
2781         struct dt_object     *dfh_o;
2782 };
2783
2784 struct dt_insert_rec {
2785         union {
2786                 const struct lu_fid     *rec_fid;
2787                 void                    *rec_data;
2788         };
2789         union {
2790                 struct {
2791                         __u32            rec_type;
2792                         __u32            rec_padding;
2793                 };
2794                 __u64                    rec_misc;
2795         };
2796 };
2797
2798 struct dt_thread_info {
2799         char                     dti_buf[DT_MAX_PATH];
2800         struct dt_find_hint      dti_dfh;
2801         struct lu_attr           dti_attr;
2802         struct lu_fid            dti_fid;
2803         struct dt_object_format  dti_dof;
2804         struct lustre_mdt_attrs  dti_lma;
2805         struct lu_buf            dti_lb;
2806         struct lu_object_conf    dti_conf;
2807         loff_t                   dti_off;
2808         struct dt_insert_rec     dti_dt_rec;
2809 };
2810
2811 extern struct lu_context_key dt_key;
2812
2813 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2814 {
2815         struct dt_thread_info *dti;
2816
2817         dti = lu_context_key_get(&env->le_ctx, &dt_key);
2818         LASSERT(dti);
2819         return dti;
2820 }
2821
2822 int dt_global_init(void);
2823 void dt_global_fini(void);
2824
2825 # ifdef CONFIG_PROC_FS
2826 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2827 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2828 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2829 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2830 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2831 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2832 # endif /* CONFIG_PROC_FS */
2833
2834 #endif /* __LUSTRE_DT_OBJECT_H */