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