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