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