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