Whamcloud - gitweb
LU-11017 quota: ignore quota for CAP_SYS_RESOURCE properly
[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         /* whether ignore quota */
1906                                 th_ignore_quota:1;
1907 };
1908
1909 /**
1910  * Transaction call-backs.
1911  *
1912  * These are invoked by osd (or underlying transaction engine) when
1913  * transaction changes state.
1914  *
1915  * Call-backs are used by upper layers to modify transaction parameters and to
1916  * perform some actions on for each transaction state transition. Typical
1917  * example is mdt registering call-back to write into last-received file
1918  * before each transaction commit.
1919  */
1920 struct dt_txn_callback {
1921         int (*dtc_txn_start)(const struct lu_env *env,
1922                              struct thandle *txn, void *cookie);
1923         int (*dtc_txn_stop)(const struct lu_env *env,
1924                             struct thandle *txn, void *cookie);
1925         void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1926         void                    *dtc_cookie;
1927         __u32                   dtc_tag;
1928         struct list_head        dtc_linkage;
1929 };
1930
1931 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1932 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1933
1934 int dt_txn_hook_start(const struct lu_env *env,
1935                       struct dt_device *dev, struct thandle *txn);
1936 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1937 void dt_txn_hook_commit(struct thandle *txn);
1938
1939 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1940
1941 /**
1942  * Callback function used for parsing path.
1943  * \see llo_store_resolve
1944  */
1945 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1946                             const char *name,
1947                             void *pvt);
1948
1949 #define DT_MAX_PATH 1024
1950
1951 int dt_path_parser(const struct lu_env *env,
1952                    char *local, dt_entry_func_t entry_func,
1953                    void *data);
1954
1955 struct dt_object *
1956 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1957                  const char *path, struct lu_fid *fid);
1958
1959 struct dt_object *dt_store_open(const struct lu_env *env,
1960                                 struct dt_device *dt,
1961                                 const char *dirname,
1962                                 const char *filename,
1963                                 struct lu_fid *fid);
1964
1965 struct dt_object *dt_find_or_create(const struct lu_env *env,
1966                                     struct dt_device *dt,
1967                                     const struct lu_fid *fid,
1968                                     struct dt_object_format *dof,
1969                                     struct lu_attr *attr);
1970
1971 struct dt_object *dt_locate_at(const struct lu_env *env,
1972                                struct dt_device *dev,
1973                                const struct lu_fid *fid,
1974                                struct lu_device *top_dev,
1975                                const struct lu_object_conf *conf);
1976
1977 static inline struct dt_object *
1978 dt_locate(const struct lu_env *env, struct dt_device *dev,
1979           const struct lu_fid *fid)
1980 {
1981         return dt_locate_at(env, dev, fid,
1982                             dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1983 }
1984
1985 static inline struct dt_object *
1986 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1987 {
1988         struct lu_object *lo;
1989
1990         list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
1991                 if (lo->lo_dev == &dt_dev->dd_lu_dev)
1992                         return container_of(lo, struct dt_object, do_lu);
1993         }
1994         return NULL;
1995 }
1996
1997 static inline void dt_object_put(const struct lu_env *env,
1998                                  struct dt_object *dto)
1999 {
2000         lu_object_put(env, &dto->do_lu);
2001 }
2002
2003 static inline void dt_object_put_nocache(const struct lu_env *env,
2004                                          struct dt_object *dto)
2005 {
2006         lu_object_put_nocache(env, &dto->do_lu);
2007 }
2008
2009 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2010                            const struct lu_fid *first_fid,
2011                            struct local_oid_storage **los);
2012 void local_oid_storage_fini(const struct lu_env *env,
2013                             struct local_oid_storage *los);
2014 int local_object_fid_generate(const struct lu_env *env,
2015                               struct local_oid_storage *los,
2016                               struct lu_fid *fid);
2017 int local_object_declare_create(const struct lu_env *env,
2018                                 struct local_oid_storage *los,
2019                                 struct dt_object *o,
2020                                 struct lu_attr *attr,
2021                                 struct dt_object_format *dof,
2022                                 struct thandle *th);
2023 int local_object_create(const struct lu_env *env,
2024                         struct local_oid_storage *los,
2025                         struct dt_object *o,
2026                         struct lu_attr *attr, struct dt_object_format *dof,
2027                         struct thandle *th);
2028 struct dt_object *local_file_find(const struct lu_env *env,
2029                                   struct local_oid_storage *los,
2030                                   struct dt_object *parent,
2031                                   const char *name);
2032 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2033                                             struct local_oid_storage *los,
2034                                             struct dt_object *parent,
2035                                             const char *name, __u32 mode);
2036 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2037                                                      struct dt_device *dt,
2038                                                      const struct lu_fid *fid,
2039                                                      struct dt_object *parent,
2040                                                      const char *name,
2041                                                      __u32 mode);
2042 struct dt_object *
2043 local_index_find_or_create(const struct lu_env *env,
2044                            struct local_oid_storage *los,
2045                            struct dt_object *parent,
2046                            const char *name, __u32 mode,
2047                            const struct dt_index_features *ft);
2048 struct dt_object *
2049 local_index_find_or_create_with_fid(const struct lu_env *env,
2050                                     struct dt_device *dt,
2051                                     const struct lu_fid *fid,
2052                                     struct dt_object *parent,
2053                                     const char *name, __u32 mode,
2054                                     const struct dt_index_features *ft);
2055 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2056                         struct dt_object *parent, const char *name);
2057
2058 static inline int dt_object_lock(const struct lu_env *env,
2059                                  struct dt_object *o, struct lustre_handle *lh,
2060                                  struct ldlm_enqueue_info *einfo,
2061                                  union ldlm_policy_data *policy)
2062 {
2063         LASSERT(o != NULL);
2064         LASSERT(o->do_ops != NULL);
2065         LASSERT(o->do_ops->do_object_lock != NULL);
2066         return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2067 }
2068
2069 static inline int dt_object_unlock(const struct lu_env *env,
2070                                    struct dt_object *o,
2071                                    struct ldlm_enqueue_info *einfo,
2072                                    union ldlm_policy_data *policy)
2073 {
2074         LASSERT(o != NULL);
2075         LASSERT(o->do_ops != NULL);
2076         LASSERT(o->do_ops->do_object_unlock != NULL);
2077         return o->do_ops->do_object_unlock(env, o, einfo, policy);
2078 }
2079
2080 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2081                   const char *name, struct lu_fid *fid);
2082
2083 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2084                                  __u64 start, __u64 end)
2085 {
2086         LASSERT(o);
2087         LASSERT(o->do_ops);
2088         LASSERT(o->do_ops->do_object_sync);
2089         return o->do_ops->do_object_sync(env, o, start, end);
2090 }
2091
2092 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2093                            struct thandle *th);
2094 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2095                     dt_obj_version_t version, struct thandle *th);
2096 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2097
2098
2099 int dt_read(const struct lu_env *env, struct dt_object *dt,
2100             struct lu_buf *buf, loff_t *pos);
2101 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2102                    struct lu_buf *buf, loff_t *pos);
2103 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2104                     const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2105 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2106                                      union lu_page *lp, size_t nob,
2107                                      const struct dt_it_ops *iops,
2108                                      struct dt_it *it, __u32 attr, void *arg);
2109 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2110                   const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2111                   void *arg);
2112 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2113                   struct idx_info *ii, const struct lu_rdpg *rdpg);
2114
2115 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2116                                               struct dt_device *d)
2117 {
2118         LASSERT(d->dd_ops->dt_trans_create);
2119         return d->dd_ops->dt_trans_create(env, d);
2120 }
2121
2122 static inline int dt_trans_start(const struct lu_env *env,
2123                                  struct dt_device *d, struct thandle *th)
2124 {
2125         LASSERT(d->dd_ops->dt_trans_start);
2126         return d->dd_ops->dt_trans_start(env, d, th);
2127 }
2128
2129 /* for this transaction hooks shouldn't be called */
2130 static inline int dt_trans_start_local(const struct lu_env *env,
2131                                        struct dt_device *d, struct thandle *th)
2132 {
2133         LASSERT(d->dd_ops->dt_trans_start);
2134         th->th_local = 1;
2135         return d->dd_ops->dt_trans_start(env, d, th);
2136 }
2137
2138 static inline int dt_trans_stop(const struct lu_env *env,
2139                                 struct dt_device *d, struct thandle *th)
2140 {
2141         LASSERT(d->dd_ops->dt_trans_stop);
2142         return d->dd_ops->dt_trans_stop(env, d, th);
2143 }
2144
2145 static inline int dt_trans_cb_add(struct thandle *th,
2146                                   struct dt_txn_commit_cb *dcb)
2147 {
2148         LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2149         dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2150         return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2151 }
2152 /** @} dt */
2153
2154
2155 static inline int dt_declare_record_write(const struct lu_env *env,
2156                                           struct dt_object *dt,
2157                                           const struct lu_buf *buf,
2158                                           loff_t pos,
2159                                           struct thandle *th)
2160 {
2161         int rc;
2162
2163         LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2164         LASSERT(th != NULL);
2165         LASSERT(dt->do_body_ops);
2166         LASSERT(dt->do_body_ops->dbo_declare_write);
2167         rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2168         return rc;
2169 }
2170
2171 static inline int dt_declare_create(const struct lu_env *env,
2172                                     struct dt_object *dt,
2173                                     struct lu_attr *attr,
2174                                     struct dt_allocation_hint *hint,
2175                                     struct dt_object_format *dof,
2176                                     struct thandle *th)
2177 {
2178         LASSERT(dt);
2179         LASSERT(dt->do_ops);
2180         LASSERT(dt->do_ops->do_declare_create);
2181
2182         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2183                 return cfs_fail_err;
2184
2185         return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2186 }
2187
2188 static inline int dt_create(const struct lu_env *env,
2189                                     struct dt_object *dt,
2190                                     struct lu_attr *attr,
2191                                     struct dt_allocation_hint *hint,
2192                                     struct dt_object_format *dof,
2193                                     struct thandle *th)
2194 {
2195         LASSERT(dt);
2196         LASSERT(dt->do_ops);
2197         LASSERT(dt->do_ops->do_create);
2198
2199         if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2200                 return cfs_fail_err;
2201
2202         return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2203 }
2204
2205 static inline int dt_declare_destroy(const struct lu_env *env,
2206                                      struct dt_object *dt,
2207                                      struct thandle *th)
2208 {
2209         LASSERT(dt);
2210         LASSERT(dt->do_ops);
2211         LASSERT(dt->do_ops->do_declare_destroy);
2212
2213         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2214                 return cfs_fail_err;
2215
2216         return dt->do_ops->do_declare_destroy(env, dt, th);
2217 }
2218
2219 static inline int dt_destroy(const struct lu_env *env,
2220                              struct dt_object *dt,
2221                              struct thandle *th)
2222 {
2223         LASSERT(dt);
2224         LASSERT(dt->do_ops);
2225         LASSERT(dt->do_ops->do_destroy);
2226
2227         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2228                 return cfs_fail_err;
2229
2230         return dt->do_ops->do_destroy(env, dt, th);
2231 }
2232
2233 static inline void dt_read_lock(const struct lu_env *env,
2234                                 struct dt_object *dt,
2235                                 unsigned role)
2236 {
2237         LASSERT(dt);
2238         LASSERT(dt->do_ops);
2239         LASSERT(dt->do_ops->do_read_lock);
2240         dt->do_ops->do_read_lock(env, dt, role);
2241 }
2242
2243 static inline void dt_write_lock(const struct lu_env *env,
2244                                 struct dt_object *dt,
2245                                 unsigned role)
2246 {
2247         LASSERT(dt);
2248         LASSERT(dt->do_ops);
2249         LASSERT(dt->do_ops->do_write_lock);
2250         dt->do_ops->do_write_lock(env, dt, role);
2251 }
2252
2253 static inline void dt_read_unlock(const struct lu_env *env,
2254                                 struct dt_object *dt)
2255 {
2256         LASSERT(dt);
2257         LASSERT(dt->do_ops);
2258         LASSERT(dt->do_ops->do_read_unlock);
2259         dt->do_ops->do_read_unlock(env, dt);
2260 }
2261
2262 static inline void dt_write_unlock(const struct lu_env *env,
2263                                 struct dt_object *dt)
2264 {
2265         LASSERT(dt);
2266         LASSERT(dt->do_ops);
2267         LASSERT(dt->do_ops->do_write_unlock);
2268         dt->do_ops->do_write_unlock(env, dt);
2269 }
2270
2271 static inline int dt_write_locked(const struct lu_env *env,
2272                                   struct dt_object *dt)
2273 {
2274         LASSERT(dt);
2275         LASSERT(dt->do_ops);
2276         LASSERT(dt->do_ops->do_write_locked);
2277         return dt->do_ops->do_write_locked(env, dt);
2278 }
2279
2280 static inline int dt_declare_attr_get(const struct lu_env *env,
2281                                       struct dt_object *dt)
2282 {
2283         LASSERT(dt);
2284         LASSERT(dt->do_ops);
2285         LASSERT(dt->do_ops->do_declare_attr_get);
2286
2287         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2288                 return cfs_fail_err;
2289
2290         return dt->do_ops->do_declare_attr_get(env, dt);
2291 }
2292
2293 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2294                               struct lu_attr *la)
2295 {
2296         LASSERT(dt);
2297         LASSERT(dt->do_ops);
2298         LASSERT(dt->do_ops->do_attr_get);
2299
2300         if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2301                 return cfs_fail_err;
2302
2303         return dt->do_ops->do_attr_get(env, dt, la);
2304 }
2305
2306 static inline int dt_declare_attr_set(const struct lu_env *env,
2307                                       struct dt_object *dt,
2308                                       const struct lu_attr *la,
2309                                       struct thandle *th)
2310 {
2311         LASSERT(dt);
2312         LASSERT(dt->do_ops);
2313         LASSERT(dt->do_ops->do_declare_attr_set);
2314
2315         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2316                 return cfs_fail_err;
2317
2318         return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2319 }
2320
2321 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2322                               const struct lu_attr *la, struct thandle *th)
2323 {
2324         LASSERT(dt);
2325         LASSERT(dt->do_ops);
2326         LASSERT(dt->do_ops->do_attr_set);
2327
2328         if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2329                 return cfs_fail_err;
2330
2331         return dt->do_ops->do_attr_set(env, dt, la, th);
2332 }
2333
2334 static inline int dt_declare_ref_add(const struct lu_env *env,
2335                                      struct dt_object *dt, struct thandle *th)
2336 {
2337         LASSERT(dt);
2338         LASSERT(dt->do_ops);
2339         LASSERT(dt->do_ops->do_declare_ref_add);
2340
2341         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2342                 return cfs_fail_err;
2343
2344         return dt->do_ops->do_declare_ref_add(env, dt, th);
2345 }
2346
2347 static inline int dt_ref_add(const struct lu_env *env,
2348                              struct dt_object *dt, struct thandle *th)
2349 {
2350         LASSERT(dt);
2351         LASSERT(dt->do_ops);
2352         LASSERT(dt->do_ops->do_ref_add);
2353
2354         if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2355                 return cfs_fail_err;
2356
2357         return dt->do_ops->do_ref_add(env, dt, th);
2358 }
2359
2360 static inline int dt_declare_ref_del(const struct lu_env *env,
2361                                      struct dt_object *dt, struct thandle *th)
2362 {
2363         LASSERT(dt);
2364         LASSERT(dt->do_ops);
2365         LASSERT(dt->do_ops->do_declare_ref_del);
2366
2367         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2368                 return cfs_fail_err;
2369
2370         return dt->do_ops->do_declare_ref_del(env, dt, th);
2371 }
2372
2373 static inline int dt_ref_del(const struct lu_env *env,
2374                              struct dt_object *dt, struct thandle *th)
2375 {
2376         LASSERT(dt);
2377         LASSERT(dt->do_ops);
2378         LASSERT(dt->do_ops->do_ref_del);
2379
2380         if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2381                 return cfs_fail_err;
2382
2383         return dt->do_ops->do_ref_del(env, dt, th);
2384 }
2385
2386 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2387                               struct niobuf_remote *rnb,
2388                               struct niobuf_local *lnb, enum dt_bufs_type rw)
2389 {
2390         LASSERT(d);
2391         LASSERT(d->do_body_ops);
2392         LASSERT(d->do_body_ops->dbo_bufs_get);
2393         return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2394                                             rnb->rnb_len, lnb, rw);
2395 }
2396
2397 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2398                               struct niobuf_local *lnb, int n)
2399 {
2400         LASSERT(d);
2401         LASSERT(d->do_body_ops);
2402         LASSERT(d->do_body_ops->dbo_bufs_put);
2403         return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2404 }
2405
2406 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2407                                 struct niobuf_local *lnb, int n)
2408 {
2409         LASSERT(d);
2410         LASSERT(d->do_body_ops);
2411         LASSERT(d->do_body_ops->dbo_write_prep);
2412         return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2413 }
2414
2415 static inline int dt_declare_write_commit(const struct lu_env *env,
2416                                           struct dt_object *d,
2417                                           struct niobuf_local *lnb,
2418                                           int n, struct thandle *th)
2419 {
2420         LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2421         LASSERT(th != NULL);
2422         return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2423 }
2424
2425
2426 static inline int dt_write_commit(const struct lu_env *env,
2427                                   struct dt_object *d, struct niobuf_local *lnb,
2428                                   int n, struct thandle *th)
2429 {
2430         LASSERT(d);
2431         LASSERT(d->do_body_ops);
2432         LASSERT(d->do_body_ops->dbo_write_commit);
2433         return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2434 }
2435
2436 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2437                                struct niobuf_local *lnb, int n)
2438 {
2439         LASSERT(d);
2440         LASSERT(d->do_body_ops);
2441         LASSERT(d->do_body_ops->dbo_read_prep);
2442         return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2443 }
2444
2445 static inline int dt_declare_write(const struct lu_env *env,
2446                                    struct dt_object *dt,
2447                                    const struct lu_buf *buf, loff_t pos,
2448                                    struct thandle *th)
2449 {
2450         LASSERT(dt);
2451         LASSERT(dt->do_body_ops);
2452         LASSERT(dt->do_body_ops->dbo_declare_write);
2453         return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2454 }
2455
2456 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2457                                const struct lu_buf *buf, loff_t *pos,
2458                                struct thandle *th, int rq)
2459 {
2460         LASSERT(dt);
2461         LASSERT(dt->do_body_ops);
2462         LASSERT(dt->do_body_ops->dbo_write);
2463         return dt->do_body_ops->dbo_write(env, dt, buf, pos, th, rq);
2464 }
2465
2466 static inline int dt_declare_punch(const struct lu_env *env,
2467                                    struct dt_object *dt, __u64 start,
2468                                    __u64 end, struct thandle *th)
2469 {
2470         LASSERT(dt);
2471         LASSERT(dt->do_body_ops);
2472         LASSERT(dt->do_body_ops->dbo_declare_punch);
2473         return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2474 }
2475
2476 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2477                            __u64 start, __u64 end, struct thandle *th)
2478 {
2479         LASSERT(dt);
2480         LASSERT(dt->do_body_ops);
2481         LASSERT(dt->do_body_ops->dbo_punch);
2482         return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2483 }
2484
2485 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2486                              __u64 start, __u64 end, int advice)
2487 {
2488         LASSERT(dt);
2489         LASSERT(dt->do_body_ops);
2490         LASSERT(dt->do_body_ops->dbo_ladvise);
2491         return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2492 }
2493
2494 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2495                                 struct fiemap *fm)
2496 {
2497         LASSERT(d);
2498         if (d->do_body_ops == NULL)
2499                 return -EPROTO;
2500         if (d->do_body_ops->dbo_fiemap_get == NULL)
2501                 return -EOPNOTSUPP;
2502         return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2503 }
2504
2505 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2506                             struct obd_statfs *osfs)
2507 {
2508         LASSERT(dev);
2509         LASSERT(dev->dd_ops);
2510         LASSERT(dev->dd_ops->dt_statfs);
2511         return dev->dd_ops->dt_statfs(env, dev, osfs);
2512 }
2513
2514 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2515                               struct lu_fid *f)
2516 {
2517         LASSERT(dev);
2518         LASSERT(dev->dd_ops);
2519         LASSERT(dev->dd_ops->dt_root_get);
2520         return dev->dd_ops->dt_root_get(env, dev, f);
2521 }
2522
2523 static inline void dt_conf_get(const struct lu_env *env,
2524                                const struct dt_device *dev,
2525                                struct dt_device_param *param)
2526 {
2527         LASSERT(dev);
2528         LASSERT(dev->dd_ops);
2529         LASSERT(dev->dd_ops->dt_conf_get);
2530         return dev->dd_ops->dt_conf_get(env, dev, param);
2531 }
2532
2533 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2534 {
2535         LASSERT(dev);
2536         LASSERT(dev->dd_ops);
2537         LASSERT(dev->dd_ops->dt_sync);
2538         return dev->dd_ops->dt_sync(env, dev);
2539 }
2540
2541 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2542 {
2543         LASSERT(dev);
2544         LASSERT(dev->dd_ops);
2545         LASSERT(dev->dd_ops->dt_ro);
2546         return dev->dd_ops->dt_ro(env, dev);
2547 }
2548
2549 static inline int dt_declare_insert(const struct lu_env *env,
2550                                     struct dt_object *dt,
2551                                     const struct dt_rec *rec,
2552                                     const struct dt_key *key,
2553                                     struct thandle *th)
2554 {
2555         LASSERT(dt);
2556         LASSERT(dt->do_index_ops);
2557         LASSERT(dt->do_index_ops->dio_declare_insert);
2558
2559         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2560                 return cfs_fail_err;
2561
2562         return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2563 }
2564
2565 static inline int dt_insert(const struct lu_env *env,
2566                                     struct dt_object *dt,
2567                                     const struct dt_rec *rec,
2568                                     const struct dt_key *key,
2569                                     struct thandle *th,
2570                                     int noquota)
2571 {
2572         LASSERT(dt);
2573         LASSERT(dt->do_index_ops);
2574         LASSERT(dt->do_index_ops->dio_insert);
2575
2576         if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2577                 return cfs_fail_err;
2578
2579         return dt->do_index_ops->dio_insert(env, dt, rec, key, th, noquota);
2580 }
2581
2582 static inline int dt_declare_xattr_del(const struct lu_env *env,
2583                                        struct dt_object *dt,
2584                                        const char *name,
2585                                        struct thandle *th)
2586 {
2587         LASSERT(dt);
2588         LASSERT(dt->do_ops);
2589         LASSERT(dt->do_ops->do_declare_xattr_del);
2590
2591         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2592                 return cfs_fail_err;
2593
2594         return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2595 }
2596
2597 static inline int dt_xattr_del(const struct lu_env *env,
2598                                struct dt_object *dt, const char *name,
2599                                struct thandle *th)
2600 {
2601         LASSERT(dt);
2602         LASSERT(dt->do_ops);
2603         LASSERT(dt->do_ops->do_xattr_del);
2604
2605         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2606                 return cfs_fail_err;
2607
2608         return dt->do_ops->do_xattr_del(env, dt, name, th);
2609 }
2610
2611 static inline int dt_declare_xattr_set(const struct lu_env *env,
2612                                       struct dt_object *dt,
2613                                       const struct lu_buf *buf,
2614                                       const char *name, int fl,
2615                                       struct thandle *th)
2616 {
2617         LASSERT(dt);
2618         LASSERT(dt->do_ops);
2619         LASSERT(dt->do_ops->do_declare_xattr_set);
2620
2621         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2622                 return cfs_fail_err;
2623
2624         return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2625 }
2626
2627 static inline int dt_xattr_set(const struct lu_env *env,
2628                                struct dt_object *dt, const struct lu_buf *buf,
2629                                const char *name, int fl, struct thandle *th)
2630 {
2631         LASSERT(dt);
2632         LASSERT(dt->do_ops);
2633         LASSERT(dt->do_ops->do_xattr_set);
2634
2635         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2636                 return cfs_fail_err;
2637
2638         return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2639 }
2640
2641 static inline int dt_declare_xattr_get(const struct lu_env *env,
2642                                        struct dt_object *dt,
2643                                        struct lu_buf *buf,
2644                                        const char *name)
2645 {
2646         LASSERT(dt);
2647         LASSERT(dt->do_ops);
2648         LASSERT(dt->do_ops->do_declare_xattr_get);
2649
2650         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2651                 return cfs_fail_err;
2652
2653         return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2654 }
2655
2656 static inline int dt_xattr_get(const struct lu_env *env,
2657                                struct dt_object *dt, struct lu_buf *buf,
2658                                const char *name)
2659 {
2660         LASSERT(dt);
2661         LASSERT(dt->do_ops);
2662         LASSERT(dt->do_ops->do_xattr_get);
2663
2664         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2665                 return cfs_fail_err;
2666
2667         return dt->do_ops->do_xattr_get(env, dt, buf, name);
2668 }
2669
2670 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2671                                 const struct lu_buf *buf)
2672 {
2673         LASSERT(dt);
2674         LASSERT(dt->do_ops);
2675         LASSERT(dt->do_ops->do_xattr_list);
2676
2677         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2678                 return cfs_fail_err;
2679
2680         return dt->do_ops->do_xattr_list(env, dt, buf);
2681 }
2682
2683 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2684 {
2685         LASSERT(dt);
2686         LASSERT(dt->do_ops);
2687         LASSERT(dt->do_ops->do_invalidate);
2688
2689         return dt->do_ops->do_invalidate(env, dt);
2690 }
2691
2692 static inline int dt_declare_delete(const struct lu_env *env,
2693                                     struct dt_object *dt,
2694                                     const struct dt_key *key,
2695                                     struct thandle *th)
2696 {
2697         LASSERT(dt);
2698         LASSERT(dt->do_index_ops);
2699         LASSERT(dt->do_index_ops->dio_declare_delete);
2700
2701         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2702                 return cfs_fail_err;
2703
2704         return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2705 }
2706
2707 static inline int dt_delete(const struct lu_env *env,
2708                             struct dt_object *dt,
2709                             const struct dt_key *key,
2710                             struct thandle *th)
2711 {
2712         LASSERT(dt);
2713         LASSERT(dt->do_index_ops);
2714         LASSERT(dt->do_index_ops->dio_delete);
2715
2716         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2717                 return cfs_fail_err;
2718
2719         return dt->do_index_ops->dio_delete(env, dt, key, th);
2720 }
2721
2722 static inline int dt_commit_async(const struct lu_env *env,
2723                                   struct dt_device *dev)
2724 {
2725         LASSERT(dev);
2726         LASSERT(dev->dd_ops);
2727         LASSERT(dev->dd_ops->dt_commit_async);
2728         return dev->dd_ops->dt_commit_async(env, dev);
2729 }
2730
2731 static inline int dt_lookup(const struct lu_env *env,
2732                             struct dt_object *dt,
2733                             struct dt_rec *rec,
2734                             const struct dt_key *key)
2735 {
2736         int ret;
2737
2738         LASSERT(dt);
2739         LASSERT(dt->do_index_ops);
2740         LASSERT(dt->do_index_ops->dio_lookup);
2741
2742         if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2743                 return cfs_fail_err;
2744
2745         ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2746         if (ret > 0)
2747                 ret = 0;
2748         else if (ret == 0)
2749                 ret = -ENOENT;
2750         return ret;
2751 }
2752
2753 static inline int dt_declare_layout_change(const struct lu_env *env,
2754                                            struct dt_object *o,
2755                                            struct md_layout_change *mlc,
2756                                            struct thandle *th)
2757 {
2758         LASSERT(o);
2759         LASSERT(o->do_ops);
2760         LASSERT(o->do_ops->do_declare_layout_change);
2761         return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2762 }
2763
2764 static inline int dt_layout_change(const struct lu_env *env,
2765                                    struct dt_object *o,
2766                                    struct md_layout_change *mlc,
2767                                    struct thandle *th)
2768 {
2769         LASSERT(o);
2770         LASSERT(o->do_ops);
2771         LASSERT(o->do_ops->do_layout_change);
2772         return o->do_ops->do_layout_change(env, o, mlc, th);
2773 }
2774
2775 struct dt_find_hint {
2776         struct lu_fid        *dfh_fid;
2777         struct dt_device     *dfh_dt;
2778         struct dt_object     *dfh_o;
2779 };
2780
2781 struct dt_insert_rec {
2782         union {
2783                 const struct lu_fid     *rec_fid;
2784                 void                    *rec_data;
2785         };
2786         union {
2787                 struct {
2788                         __u32            rec_type;
2789                         __u32            rec_padding;
2790                 };
2791                 __u64                    rec_misc;
2792         };
2793 };
2794
2795 struct dt_thread_info {
2796         char                     dti_buf[DT_MAX_PATH];
2797         struct dt_find_hint      dti_dfh;
2798         struct lu_attr           dti_attr;
2799         struct lu_fid            dti_fid;
2800         struct dt_object_format  dti_dof;
2801         struct lustre_mdt_attrs  dti_lma;
2802         struct lu_buf            dti_lb;
2803         struct lu_object_conf    dti_conf;
2804         loff_t                   dti_off;
2805         struct dt_insert_rec     dti_dt_rec;
2806 };
2807
2808 extern struct lu_context_key dt_key;
2809
2810 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2811 {
2812         struct dt_thread_info *dti;
2813
2814         dti = lu_context_key_get(&env->le_ctx, &dt_key);
2815         LASSERT(dti);
2816         return dti;
2817 }
2818
2819 int dt_global_init(void);
2820 void dt_global_fini(void);
2821
2822 # ifdef CONFIG_PROC_FS
2823 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2824 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2825 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2826 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2827 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2828 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2829 # endif /* CONFIG_PROC_FS */
2830
2831 #endif /* __LUSTRE_DT_OBJECT_H */