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