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