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