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