Whamcloud - gitweb
88efa86c10fa163bf952cdd542f204100dcddeb1
[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          * \param[in] ignore    unused (was used to request quota ignorance)
1143          *
1144          * \retval positive     bytes written on success
1145          * \retval negative     negated errno on error
1146          */
1147         ssize_t (*dbo_write)(const struct lu_env *env,
1148                              struct dt_object *dt,
1149                              const struct lu_buf *buf,
1150                              loff_t *pos,
1151                              struct thandle *th,
1152                              int ignore);
1153
1154         /**
1155          * Return buffers for data.
1156          *
1157          * This method is used to access data with no copying. It's so-called
1158          * zero-copy I/O. The method returns the descriptors for the internal
1159          * buffers where data are managed by the disk filesystem. For example,
1160          * pagecache in case of ext4 or ARC with ZFS. Then other components
1161          * (e.g. networking) can transfer data from or to the buffers with no
1162          * additional copying.
1163          *
1164          * The method should fill an array of struct niobuf_local, where
1165          * each element describes a full or partial page for data at specific
1166          * offset. The caller should use page/lnb_page_offset/len to find data
1167          * at object's offset lnb_file_offset.
1168          *
1169          * The memory referenced by the descriptors can't change its purpose
1170          * until the complementary ->dbo_bufs_put() is called. The caller should
1171          * specify if the buffers are used to read or modify data so that OSD
1172          * can decide how to initialize the buffers: bring all the data for
1173          * reads or just bring partial buffers for write. Note: the method does
1174          * not check whether output array is large enough.
1175          *
1176          * \param[in] env       execution environment for this thread
1177          * \param[in] dt        object
1178          * \param[in] pos       position in the object to start
1179          * \param[in] len       size of region in bytes
1180          * \param[out] lb       array of descriptors to fill
1181          * \param[in] rw        0 if used to read, 1 if used for write
1182          *
1183          * \retval positive     number of descriptors on success
1184          * \retval negative     negated errno on error
1185          */
1186         int (*dbo_bufs_get)(const struct lu_env *env,
1187                             struct dt_object *dt,
1188                             loff_t pos,
1189                             ssize_t len,
1190                             struct niobuf_local *lb,
1191                             enum dt_bufs_type rw);
1192
1193         /**
1194          * Release reference granted by ->dbo_bufs_get().
1195          *
1196          * Release the reference granted by the previous ->dbo_bufs_get().
1197          * Note the references are counted.
1198          *
1199          * \param[in] env       execution environment for this thread
1200          * \param[in] dt        object
1201          * \param[out] lb       array of descriptors to fill
1202          * \param[in] nr        size of the array
1203          *
1204          * \retval 0            on success
1205          * \retval negative     negated errno on error
1206          */
1207         int (*dbo_bufs_put)(const struct lu_env *env,
1208                             struct dt_object *dt,
1209                             struct niobuf_local *lb,
1210                             int nr);
1211
1212         /**
1213          * Prepare buffers for reading.
1214          *
1215          * The method is called on the given buffers to fill them with data
1216          * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1217          * caller should be able to get few buffers for discontiguous regions
1218          * using few calls to ->dbo_bufs_get() and then request them all for
1219          * the preparation with a single call, so that OSD can fire many I/Os
1220          * to run concurrently. It's up to the specific OSD whether to implement
1221          * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1222          * prepare data for every requested region individually.
1223          *
1224          * \param[in] env       execution environment for this thread
1225          * \param[in] dt        object
1226          * \param[in] lnb       array of buffer descriptors
1227          * \param[in] nr        size of the array
1228          *
1229          * \retval 0            on success
1230          * \retval negative     negated errno on error
1231          */
1232         int (*dbo_read_prep)(const struct lu_env *env,
1233                              struct dt_object *dt,
1234                              struct niobuf_local *lnb,
1235                              int nr);
1236
1237         /**
1238          * Prepare buffers for write.
1239          *
1240          * This method is called on the given buffers to ensure the partial
1241          * buffers contain correct data. The underlying idea is the same as
1242          * in ->db_read_prep().
1243          *
1244          * \param[in] env       execution environment for this thread
1245          * \param[in] dt        object
1246          * \param[in] lb        array of buffer descriptors
1247          * \param[in] nr        size of the array
1248          *
1249          * \retval 0            on success
1250          * \retval negative     negated errno on error
1251          */
1252         int (*dbo_write_prep)(const struct lu_env *env,
1253                               struct dt_object *dt,
1254                               struct niobuf_local *lb,
1255                               int nr);
1256
1257         /**
1258          * Declare intention to write data stored in the buffers.
1259          *
1260          * Notify the underlying filesystem that data may be written in
1261          * this transaction. This enables the layer below to prepare resources
1262          * (e.g. journal credits in ext4).  This method should be called
1263          * between creating the transaction and starting it.
1264          *
1265          * If the layer implementing this method is responsible for quota,
1266          * then the method should be reserving a space for the given
1267          * credentials and return an error if quota is exceeded. If the write
1268          * later fails for some reason, then the reserve should be released
1269          * properly (usually in ->dt_trans_stop()).
1270          *
1271          * \param[in] env       execution environment for this thread
1272          * \param[in] dt        object
1273          * \param[in] lb        array of descriptors
1274          * \param[in] nr        size of the array
1275          * \param[in] th        transaction handle
1276          *
1277          * \retval 0            on success
1278          * \retval negative     negated errno on error
1279          */
1280         int (*dbo_declare_write_commit)(const struct lu_env *env,
1281                                         struct dt_object *dt,
1282                                         struct niobuf_local *lb,
1283                                         int nr,
1284                                         struct thandle *th);
1285
1286         /**
1287          * Write to existing object.
1288          *
1289          * This method is used to write data to a persistent storage using
1290          * the buffers returned by ->dbo_bufs_get(). The caller puts new
1291          * data into the buffers using own mechanisms (e.g. direct transfer
1292          * from a NIC). The method should maintain attr.la_size. Also,
1293          * attr.la_blocks should be maintained but this can be done in lazy
1294          * manner, when actual allocation happens.
1295          *
1296          * If the layer implementing this method is responsible for quota,
1297          * then the method should maintain space accounting for the given
1298          * credentials.
1299          *
1300          * \param[in] env       execution environment for this thread
1301          * \param[in] dt        object
1302          * \param[in] lb        array of descriptors for the buffers
1303          * \param[in] nr        size of the array
1304          * \param[in] th        transaction handle
1305          *
1306          * \retval 0            on success
1307          * \retval negative     negated errno on error
1308          */
1309         int (*dbo_write_commit)(const struct lu_env *env,
1310                                 struct dt_object *dt,
1311                                 struct niobuf_local *lb,
1312                                 int nr,
1313                                 struct thandle *th);
1314
1315         /**
1316          * Return logical to physical block mapping for a given extent
1317          *
1318          * \param[in] env       execution environment for this thread
1319          * \param[in] dt        object
1320          * \param[in] fm        describe the region to map and the output buffer
1321          *                      see the details in include/linux/fiemap.h
1322          *
1323          * \retval 0            on success
1324          * \retval negative     negated errno on error
1325          */
1326         int (*dbo_fiemap_get)(const struct lu_env *env,
1327                               struct dt_object *dt,
1328                               struct fiemap *fm);
1329
1330         /**
1331          * Declare intention to deallocate space from an object.
1332          *
1333          * Notify the underlying filesystem that space may be deallocated in
1334          * this transactions. This enables the layer below to prepare resources
1335          * (e.g. journal credits in ext4).  This method should be called between
1336          * creating the transaction and starting it. The object need not exist.
1337          *
1338          * \param[in] env       execution environment for this thread
1339          * \param[in] dt        object
1340          * \param[in] start     the start of the region to deallocate
1341          * \param[in] end       the end of the region to deallocate
1342          * \param[in] th        transaction handle
1343          *
1344          * \retval 0            on success
1345          * \retval negative     negated errno on error
1346          */
1347         int   (*dbo_declare_punch)(const struct lu_env *env,
1348                                    struct dt_object *dt,
1349                                    __u64 start,
1350                                    __u64 end,
1351                                    struct thandle *th);
1352
1353         /**
1354          * Deallocate specified region in an object.
1355          *
1356          * This method is used to deallocate (release) space possibly consumed
1357          * by the given region of the object. If the layer implementing this
1358          * method is responsible for quota, then the method should maintain
1359          * space accounting for the given credentials.
1360          *
1361          * \param[in] env       execution environment for this thread
1362          * \param[in] dt        object
1363          * \param[in] start     the start of the region to deallocate
1364          * \param[in] end       the end of the region to deallocate
1365          * \param[in] th        transaction handle
1366          *
1367          * \retval 0            on success
1368          * \retval negative     negated errno on error
1369          */
1370         int   (*dbo_punch)(const struct lu_env *env,
1371                            struct dt_object *dt,
1372                            __u64 start,
1373                            __u64 end,
1374                            struct thandle *th);
1375         /**
1376          * Give advices on specified region in an object.
1377          *
1378          * This method is used to give advices about access pattern on an
1379          * given region of the object. The disk filesystem understands
1380          * the advices and tunes cache/read-ahead policies.
1381          *
1382          * \param[in] env       execution environment for this thread
1383          * \param[in] dt        object
1384          * \param[in] start     the start of the region affected
1385          * \param[in] end       the end of the region affected
1386          * \param[in] advice    advice type
1387          *
1388          * \retval 0            on success
1389          * \retval negative     negated errno on error
1390          */
1391         int   (*dbo_ladvise)(const struct lu_env *env,
1392                              struct dt_object *dt,
1393                              __u64 start,
1394                              __u64 end,
1395                              enum lu_ladvise_type advice);
1396 };
1397
1398 /**
1399  * Incomplete type of index record.
1400  */
1401 struct dt_rec;
1402
1403 /**
1404  * Incomplete type of index key.
1405  */
1406 struct dt_key;
1407
1408 /**
1409  * Incomplete type of dt iterator.
1410  */
1411 struct dt_it;
1412
1413 /**
1414  * Per-dt-object operations on object as index. Index is a set of key/value
1415  * pairs abstracted from an on-disk representation. An index supports the
1416  * number of operations including lookup by key, insert and delete. Also,
1417  * an index can be iterated to find the pairs one by one, from a beginning
1418  * or specified point.
1419  */
1420 struct dt_index_operations {
1421         /**
1422          * Lookup in an index by key.
1423          *
1424          * The method returns a value for the given key. Key/value format
1425          * and size should have been negotiated with ->do_index_try() before.
1426          * Thus it's the caller's responsibility to provide the method with
1427          * proper key and big enough buffer. No external locking is required,
1428          * all the internal consistency should be implemented by the method
1429          * or lower layers. The object should should have been created with
1430          * type DFT_INDEX or DFT_DIR.
1431          *
1432          * \param[in] env       execution environment for this thread
1433          * \param[in] dt        object
1434          * \param[out] rec      buffer where value will be stored
1435          * \param[in] key       key
1436          *
1437          * \retval 0            on success
1438          * \retval -ENOENT      if key isn't found
1439          * \retval negative     negated errno on error
1440          */
1441         int (*dio_lookup)(const struct lu_env *env,
1442                           struct dt_object *dt,
1443                           struct dt_rec *rec,
1444                           const struct dt_key *key);
1445
1446         /**
1447          * Declare intention to insert a key/value into an index.
1448          *
1449          * Notify the underlying filesystem that new key/value may be inserted
1450          * in this transaction. This enables the layer below to prepare
1451          * resources (e.g. journal credits in ext4). This method should be
1452          * called between creating the transaction and starting it. key/value
1453          * format and size is subject to ->do_index_try().
1454          *
1455          * \param[in] env       execution environment for this thread
1456          * \param[in] dt        object
1457          * \param[in] rec       buffer storing value
1458          * \param[in] key       key
1459          * \param[in] th        transaction handle
1460          *
1461          * \retval 0            on success
1462          * \retval negative     negated errno on error
1463          */
1464         int (*dio_declare_insert)(const struct lu_env *env,
1465                                   struct dt_object *dt,
1466                                   const struct dt_rec *rec,
1467                                   const struct dt_key *key,
1468                                   struct thandle *th);
1469
1470         /**
1471          * Insert a new key/value pair into an index.
1472          *
1473          * The method inserts specified key/value pair into the given index
1474          * object. The internal consistency is maintained by the method or
1475          * the functionality below. The format and size of key/value should
1476          * have been negotiated before using ->do_index_try(), no additional
1477          * information can be specified to the method. The keys are unique
1478          * in a given index.
1479          *
1480          * \param[in] env       execution environment for this thread
1481          * \param[in] dt        object
1482          * \param[in] rec       buffer storing value
1483          * \param[in] key       key
1484          * \param[in] th        transaction handle
1485          * \param[in] ignore    unused (was used to request quota ignorance)
1486          *
1487          * \retval 0            on success
1488          * \retval negative     negated errno on error
1489          */
1490         int (*dio_insert)(const struct lu_env *env,
1491                           struct dt_object *dt,
1492                           const struct dt_rec *rec,
1493                           const struct dt_key *key,
1494                           struct thandle *th,
1495                           int ignore);
1496
1497         /**
1498          * Declare intention to delete a key/value from an index.
1499          *
1500          * Notify the underlying filesystem that key/value may be deleted in
1501          * this transaction. This enables the layer below to prepare resources
1502          * (e.g. journal credits in ext4).  This method should be called
1503          * between creating the transaction and starting it. Key/value format
1504          * and size is subject to ->do_index_try(). The object need not exist.
1505          *
1506          * \param[in] env       execution environment for this thread
1507          * \param[in] dt        object
1508          * \param[in] key       key
1509          * \param[in] th        transaction handle
1510          *
1511          * \retval 0            on success
1512          * \retval negative     negated errno on error
1513          */
1514         int (*dio_declare_delete)(const struct lu_env *env,
1515                                   struct dt_object *dt,
1516                                   const struct dt_key *key,
1517                                   struct thandle *th);
1518
1519         /**
1520          * Delete key/value pair from an index.
1521          *
1522          * The method deletes specified key and corresponding value from the
1523          * given index object. The internal consistency is maintained by the
1524          * method or the functionality below. The format and size of the key
1525          * should have been negotiated before using ->do_index_try(), no
1526          * additional information can be specified to the method.
1527          *
1528          * \param[in] env       execution environment for this thread
1529          * \param[in] dt        object
1530          * \param[in] key       key
1531          * \param[in] th        transaction handle
1532          *
1533          * \retval 0            on success
1534          * \retval negative     negated errno on error
1535          */
1536         int (*dio_delete)(const struct lu_env *env,
1537                           struct dt_object *dt,
1538                           const struct dt_key *key,
1539                           struct thandle *th);
1540
1541         /**
1542          * Iterator interface.
1543          *
1544          * Methods to iterate over an existing index, list the keys stored and
1545          * associated values, get key/value size, etc.
1546          */
1547         struct dt_it_ops {
1548                 /**
1549                  * Allocate and initialize new iterator.
1550                  *
1551                  * The iterator is a handler to be used in the subsequent
1552                  * methods to access index's content. Note the position is
1553                  * not defined at this point and should be initialized with
1554                  * ->get() or ->load() method.
1555                  *
1556                  * \param[in] env       execution environment for this thread
1557                  * \param[in] dt        object
1558                  * \param[in] attr      ask the iterator to return part of
1559                                         the records, see LUDA_* for details
1560                  *
1561                  * \retval pointer      iterator pointer on success
1562                  * \retval ERR_PTR(errno)       on error
1563                  */
1564                 struct dt_it *(*init)(const struct lu_env *env,
1565                                       struct dt_object *dt,
1566                                       __u32 attr);
1567
1568                 /**
1569                  * Release iterator.
1570                  *
1571                  * Release the specified iterator and all the resources
1572                  * associated (e.g. the object, index cache, etc).
1573                  *
1574                  * \param[in] env       execution environment for this thread
1575                  * \param[in] di        iterator to release
1576                  */
1577                 void          (*fini)(const struct lu_env *env,
1578                                       struct dt_it *di);
1579
1580                 /**
1581                  * Move position of iterator.
1582                  *
1583                  * Move the position of the specified iterator to the specified
1584                  * key.
1585                  *
1586                  * \param[in] env       execution environment for this thread
1587                  * \param[in] di        iterator
1588                  * \param[in] key       key to position to
1589                  *
1590                  * \retval 0            if exact key is found
1591                  * \retval 1            if at the record with least key
1592                  *                      not larger than the key
1593                  * \retval negative     negated errno on error
1594                  */
1595                 int            (*get)(const struct lu_env *env,
1596                                       struct dt_it *di,
1597                                       const struct dt_key *key);
1598
1599                 /**
1600                  * Release position
1601                  *
1602                  * Complimentary method for dt_it_ops::get() above. Some
1603                  * implementation can increase a reference on the iterator in
1604                  * dt_it_ops::get(). So the caller should be able to release
1605                  * with dt_it_ops::put().
1606                  *
1607                  * \param[in] env       execution environment for this thread
1608                  * \param[in] di        iterator
1609                  */
1610                 void           (*put)(const struct lu_env *env,
1611                                       struct dt_it *di);
1612
1613                 /**
1614                  * Move to next record.
1615                  *
1616                  * Moves the position of the iterator to a next record
1617                  *
1618                  * \param[in] env       execution environment for this thread
1619                  * \param[in] di        iterator
1620                  *
1621                  * \retval 1            if no more records
1622                  * \retval 0            on success, the next record is found
1623                  * \retval negative     negated errno on error
1624                  */
1625                 int           (*next)(const struct lu_env *env,
1626                                       struct dt_it *di);
1627
1628                 /**
1629                  * Return key.
1630                  *
1631                  * Returns a pointer to a buffer containing the key of the
1632                  * record at the current position. The pointer is valid and
1633                  * retains data until ->get(), ->load() and ->fini() methods
1634                  * are called.
1635                  *
1636                  * \param[in] env       execution environment for this thread
1637                  * \param[in] di        iterator
1638                  *
1639                  * \retval pointer to key       on success
1640                  * \retval ERR_PTR(errno)       on error
1641                  */
1642                 struct dt_key *(*key)(const struct lu_env *env,
1643                                       const struct dt_it *di);
1644
1645                 /**
1646                  * Return key size.
1647                  *
1648                  * Returns size of the key at the current position.
1649                  *
1650                  * \param[in] env       execution environment for this thread
1651                  * \param[in] di        iterator
1652                  *
1653                  * \retval key's size   on success
1654                  * \retval negative     negated errno on error
1655                  */
1656                 int       (*key_size)(const struct lu_env *env,
1657                                       const struct dt_it *di);
1658
1659                 /**
1660                  * Return record.
1661                  *
1662                  * Stores the value of the record at the current position. The
1663                  * buffer must be big enough (as negotiated with
1664                  * ->do_index_try() or ->rec_size()). The caller can specify
1665                  * she is interested only in part of the record, using attr
1666                  * argument (see LUDA_* definitions for the details).
1667                  *
1668                  * \param[in] env       execution environment for this thread
1669                  * \param[in] di        iterator
1670                  * \param[out] rec      buffer to store value in
1671                  * \param[in] attr      specify part of the value to copy
1672                  *
1673                  * \retval 0            on success
1674                  * \retval negative     negated errno on error
1675                  */
1676                 int            (*rec)(const struct lu_env *env,
1677                                       const struct dt_it *di,
1678                                       struct dt_rec *rec,
1679                                       __u32 attr);
1680
1681                 /**
1682                  * Return record size.
1683                  *
1684                  * Returns size of the record at the current position. The
1685                  * \a attr can be used to specify only the parts of the record
1686                  * needed to be returned. (see LUDA_* definitions for the
1687                  * details).
1688                  *
1689                  * \param[in] env       execution environment for this thread
1690                  * \param[in] di        iterator
1691                  * \param[in] attr      part of the record to return
1692                  *
1693                  * \retval record's size        on success
1694                  * \retval negative             negated errno on error
1695                  */
1696                 int        (*rec_size)(const struct lu_env *env,
1697                                        const struct dt_it *di,
1698                                       __u32 attr);
1699
1700                 /**
1701                  * Return a cookie (hash).
1702                  *
1703                  * Returns the cookie (usually hash) of the key at the current
1704                  * position. This allows the caller to resume iteration at this
1705                  * position later. The exact value is specific to implementation
1706                  * and should not be interpreted by the caller.
1707                  *
1708                  * \param[in] env       execution environment for this thread
1709                  * \param[in] di        iterator
1710                  *
1711                  * \retval cookie/hash of the key
1712                  */
1713                 __u64        (*store)(const struct lu_env *env,
1714                                       const struct dt_it *di);
1715
1716                 /**
1717                  * Initialize position using cookie/hash.
1718                  *
1719                  * Initializes the current position of the iterator to one
1720                  * described by the cookie/hash as returned by ->store()
1721                  * previously.
1722                  *
1723                  * \param[in] env       execution environment for this thread
1724                  * \param[in] di        iterator
1725                  * \param[in] hash      cookie/hash value
1726                  *
1727                  * \retval positive     if current position points to
1728                  *                      record with least cookie not larger
1729                  *                      than cookie
1730                  * \retval 0            if current position matches cookie
1731                  * \retval negative     negated errno on error
1732                  */
1733                 int           (*load)(const struct lu_env *env,
1734                                       const struct dt_it *di,
1735                                       __u64 hash);
1736
1737                 /**
1738                  * Not used
1739                  */
1740                 int        (*key_rec)(const struct lu_env *env,
1741                                       const struct dt_it *di,
1742                                       void *key_rec);
1743         } dio_it;
1744 };
1745
1746 enum dt_otable_it_valid {
1747         DOIV_ERROR_HANDLE       = 0x0001,
1748         DOIV_DRYRUN             = 0x0002,
1749 };
1750
1751 enum dt_otable_it_flags {
1752         /* Exit when fail. */
1753         DOIF_FAILOUT    = 0x0001,
1754
1755         /* Reset iteration position to the device beginning. */
1756         DOIF_RESET      = 0x0002,
1757
1758         /* There is up layer component uses the iteration. */
1759         DOIF_OUTUSED    = 0x0004,
1760
1761         /* Check only without repairing. */
1762         DOIF_DRYRUN     = 0x0008,
1763 };
1764
1765 /* otable based iteration needs to use the common DT iteration APIs.
1766  * To initialize the iteration, it needs call dio_it::init() firstly.
1767  * Here is how the otable based iteration should prepare arguments to
1768  * call dt_it_ops::init().
1769  *
1770  * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1771  * is composed of two parts:
1772  * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1773 #define DT_OTABLE_IT_FLAGS_SHIFT        16
1774 #define DT_OTABLE_IT_FLAGS_MASK         0xffff0000
1775
1776 struct dt_device {
1777         struct lu_device                   dd_lu_dev;
1778         const struct dt_device_operations *dd_ops;
1779
1780         /**
1781          * List of dt_txn_callback (see below). This is not protected in any
1782          * way, because callbacks are supposed to be added/deleted only during
1783          * single-threaded start-up shut-down procedures.
1784          */
1785         struct list_head                   dd_txn_callbacks;
1786         unsigned int                       dd_record_fid_accessed:1,
1787                                            dd_rdonly:1;
1788
1789         /* sysfs and debugfs handling */
1790         struct dentry                     *dd_debugfs_entry;
1791
1792         const struct attribute           **dd_def_attrs;
1793         struct kobject                     dd_kobj;
1794         struct kobj_type                   dd_ktype;
1795         struct completion                  dd_kobj_unregister;
1796 };
1797
1798 int  dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1799 void dt_device_fini(struct dt_device *dev);
1800
1801 static inline int lu_device_is_dt(const struct lu_device *d)
1802 {
1803         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1804 }
1805
1806 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1807 {
1808         LASSERT(lu_device_is_dt(l));
1809         return container_of0(l, struct dt_device, dd_lu_dev);
1810 }
1811
1812 struct dt_object {
1813         struct lu_object                   do_lu;
1814         const struct dt_object_operations *do_ops;
1815         const struct dt_body_operations   *do_body_ops;
1816         const struct dt_index_operations  *do_index_ops;
1817 };
1818
1819 /*
1820  * In-core representation of per-device local object OID storage
1821  */
1822 struct local_oid_storage {
1823         /* all initialized llog systems on this node linked by this */
1824         struct list_head  los_list;
1825
1826         /* how many handle's reference this los has */
1827         atomic_t          los_refcount;
1828         struct dt_device *los_dev;
1829         struct dt_object *los_obj;
1830
1831         /* data used to generate new fids */
1832         struct mutex      los_id_lock;
1833         __u64             los_seq;
1834         __u32             los_last_oid;
1835 };
1836
1837 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1838 {
1839         return &d->dd_lu_dev;
1840 }
1841
1842 static inline struct dt_object *lu2dt(struct lu_object *l)
1843 {
1844         LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1845         return container_of0(l, struct dt_object, do_lu);
1846 }
1847
1848 int  dt_object_init(struct dt_object *obj,
1849                     struct lu_object_header *h, struct lu_device *d);
1850
1851 void dt_object_fini(struct dt_object *obj);
1852
1853 static inline int dt_object_exists(const struct dt_object *dt)
1854 {
1855         return lu_object_exists(&dt->do_lu);
1856 }
1857
1858 static inline int dt_object_remote(const struct dt_object *dt)
1859 {
1860         return lu_object_remote(&dt->do_lu);
1861 }
1862
1863 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1864 {
1865         LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1866         return container_of0(o, struct dt_object, do_lu);
1867 }
1868
1869 static inline struct dt_object *dt_object_child(struct dt_object *o)
1870 {
1871         return container_of0(lu_object_next(&(o)->do_lu),
1872                              struct dt_object, do_lu);
1873 }
1874
1875 /**
1876  * This is the general purpose transaction handle.
1877  * 1. Transaction Life Cycle
1878  *      This transaction handle is allocated upon starting a new transaction,
1879  *      and deallocated after this transaction is committed.
1880  * 2. Transaction Nesting
1881  *      We do _NOT_ support nested transaction. So, every thread should only
1882  *      have one active transaction, and a transaction only belongs to one
1883  *      thread. Due to this, transaction handle need no reference count.
1884  * 3. Transaction & dt_object locking
1885  *      dt_object locks should be taken inside transaction.
1886  * 4. Transaction & RPC
1887  *      No RPC request should be issued inside transaction.
1888  */
1889 struct thandle {
1890         /** the dt device on which the transactions are executed */
1891         struct dt_device *th_dev;
1892
1893         /* point to the top thandle, XXX this is a bit hacky right now,
1894          * but normal device trans callback triggered by the bottom
1895          * device (OSP/OSD == sub thandle layer) needs to get the
1896          * top_thandle (see dt_txn_hook_start/stop()), so we put the
1897          * top thandle here for now, will fix it when we have better
1898          * callback mechanism */
1899         struct thandle  *th_top;
1900
1901         /** the last operation result in this transaction.
1902          * this value is used in recovery */
1903         __s32             th_result;
1904
1905         /** whether we need sync commit */
1906         unsigned int            th_sync:1,
1907         /* local transation, no need to inform other layers */
1908                                 th_local:1,
1909         /* Whether we need wait the transaction to be submitted
1910          * (send to remote target) */
1911                                 th_wait_submit:1,
1912         /* complex transaction which will track updates on all targets,
1913          * including OSTs */
1914                                 th_complex:1,
1915         /* whether ignore quota */
1916                                 th_ignore_quota:1;
1917 };
1918
1919 /**
1920  * Transaction call-backs.
1921  *
1922  * These are invoked by osd (or underlying transaction engine) when
1923  * transaction changes state.
1924  *
1925  * Call-backs are used by upper layers to modify transaction parameters and to
1926  * perform some actions on for each transaction state transition. Typical
1927  * example is mdt registering call-back to write into last-received file
1928  * before each transaction commit.
1929  */
1930 struct dt_txn_callback {
1931         int (*dtc_txn_start)(const struct lu_env *env,
1932                              struct thandle *txn, void *cookie);
1933         int (*dtc_txn_stop)(const struct lu_env *env,
1934                             struct thandle *txn, void *cookie);
1935         void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1936         void                    *dtc_cookie;
1937         __u32                   dtc_tag;
1938         struct list_head        dtc_linkage;
1939 };
1940
1941 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1942 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1943
1944 int dt_txn_hook_start(const struct lu_env *env,
1945                       struct dt_device *dev, struct thandle *txn);
1946 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1947 void dt_txn_hook_commit(struct thandle *txn);
1948
1949 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1950
1951 /**
1952  * Callback function used for parsing path.
1953  * \see llo_store_resolve
1954  */
1955 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1956                             const char *name,
1957                             void *pvt);
1958
1959 #define DT_MAX_PATH 1024
1960
1961 int dt_path_parser(const struct lu_env *env,
1962                    char *local, dt_entry_func_t entry_func,
1963                    void *data);
1964
1965 struct dt_object *
1966 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1967                  const char *path, struct lu_fid *fid);
1968
1969 struct dt_object *dt_store_open(const struct lu_env *env,
1970                                 struct dt_device *dt,
1971                                 const char *dirname,
1972                                 const char *filename,
1973                                 struct lu_fid *fid);
1974
1975 struct dt_object *dt_find_or_create(const struct lu_env *env,
1976                                     struct dt_device *dt,
1977                                     const struct lu_fid *fid,
1978                                     struct dt_object_format *dof,
1979                                     struct lu_attr *attr);
1980
1981 struct dt_object *dt_locate_at(const struct lu_env *env,
1982                                struct dt_device *dev,
1983                                const struct lu_fid *fid,
1984                                struct lu_device *top_dev,
1985                                const struct lu_object_conf *conf);
1986
1987 static inline struct dt_object *
1988 dt_locate(const struct lu_env *env, struct dt_device *dev,
1989           const struct lu_fid *fid)
1990 {
1991         return dt_locate_at(env, dev, fid,
1992                             dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1993 }
1994
1995 static inline struct dt_object *
1996 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1997 {
1998         struct lu_object *lo;
1999
2000         list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2001                 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2002                         return container_of(lo, struct dt_object, do_lu);
2003         }
2004         return NULL;
2005 }
2006
2007 static inline void dt_object_put(const struct lu_env *env,
2008                                  struct dt_object *dto)
2009 {
2010         lu_object_put(env, &dto->do_lu);
2011 }
2012
2013 static inline void dt_object_put_nocache(const struct lu_env *env,
2014                                          struct dt_object *dto)
2015 {
2016         lu_object_put_nocache(env, &dto->do_lu);
2017 }
2018
2019 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2020                            const struct lu_fid *first_fid,
2021                            struct local_oid_storage **los);
2022 void local_oid_storage_fini(const struct lu_env *env,
2023                             struct local_oid_storage *los);
2024 int local_object_fid_generate(const struct lu_env *env,
2025                               struct local_oid_storage *los,
2026                               struct lu_fid *fid);
2027 int local_object_declare_create(const struct lu_env *env,
2028                                 struct local_oid_storage *los,
2029                                 struct dt_object *o,
2030                                 struct lu_attr *attr,
2031                                 struct dt_object_format *dof,
2032                                 struct thandle *th);
2033 int local_object_create(const struct lu_env *env,
2034                         struct local_oid_storage *los,
2035                         struct dt_object *o,
2036                         struct lu_attr *attr, struct dt_object_format *dof,
2037                         struct thandle *th);
2038 struct dt_object *local_file_find(const struct lu_env *env,
2039                                   struct local_oid_storage *los,
2040                                   struct dt_object *parent,
2041                                   const char *name);
2042 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2043                                             struct local_oid_storage *los,
2044                                             struct dt_object *parent,
2045                                             const char *name, __u32 mode);
2046 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2047                                                      struct dt_device *dt,
2048                                                      const struct lu_fid *fid,
2049                                                      struct dt_object *parent,
2050                                                      const char *name,
2051                                                      __u32 mode);
2052 struct dt_object *
2053 local_index_find_or_create(const struct lu_env *env,
2054                            struct local_oid_storage *los,
2055                            struct dt_object *parent,
2056                            const char *name, __u32 mode,
2057                            const struct dt_index_features *ft);
2058 struct dt_object *
2059 local_index_find_or_create_with_fid(const struct lu_env *env,
2060                                     struct dt_device *dt,
2061                                     const struct lu_fid *fid,
2062                                     struct dt_object *parent,
2063                                     const char *name, __u32 mode,
2064                                     const struct dt_index_features *ft);
2065 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2066                         struct dt_object *parent, const char *name);
2067
2068 static inline int dt_object_lock(const struct lu_env *env,
2069                                  struct dt_object *o, struct lustre_handle *lh,
2070                                  struct ldlm_enqueue_info *einfo,
2071                                  union ldlm_policy_data *policy)
2072 {
2073         LASSERT(o != NULL);
2074         LASSERT(o->do_ops != NULL);
2075         LASSERT(o->do_ops->do_object_lock != NULL);
2076         return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2077 }
2078
2079 static inline int dt_object_unlock(const struct lu_env *env,
2080                                    struct dt_object *o,
2081                                    struct ldlm_enqueue_info *einfo,
2082                                    union ldlm_policy_data *policy)
2083 {
2084         LASSERT(o != NULL);
2085         LASSERT(o->do_ops != NULL);
2086         LASSERT(o->do_ops->do_object_unlock != NULL);
2087         return o->do_ops->do_object_unlock(env, o, einfo, policy);
2088 }
2089
2090 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2091                   const char *name, struct lu_fid *fid);
2092
2093 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2094                                  __u64 start, __u64 end)
2095 {
2096         LASSERT(o);
2097         LASSERT(o->do_ops);
2098         LASSERT(o->do_ops->do_object_sync);
2099         return o->do_ops->do_object_sync(env, o, start, end);
2100 }
2101
2102 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2103                            struct thandle *th);
2104 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2105                     dt_obj_version_t version, struct thandle *th);
2106 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2107
2108
2109 int dt_read(const struct lu_env *env, struct dt_object *dt,
2110             struct lu_buf *buf, loff_t *pos);
2111 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2112                    struct lu_buf *buf, loff_t *pos);
2113 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2114                     const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2115 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2116                                      union lu_page *lp, size_t nob,
2117                                      const struct dt_it_ops *iops,
2118                                      struct dt_it *it, __u32 attr, void *arg);
2119 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2120                   const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2121                   void *arg);
2122 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2123                   struct idx_info *ii, const struct lu_rdpg *rdpg);
2124
2125 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2126                                               struct dt_device *d)
2127 {
2128         LASSERT(d->dd_ops->dt_trans_create);
2129         return d->dd_ops->dt_trans_create(env, d);
2130 }
2131
2132 static inline int dt_trans_start(const struct lu_env *env,
2133                                  struct dt_device *d, struct thandle *th)
2134 {
2135         LASSERT(d->dd_ops->dt_trans_start);
2136         return d->dd_ops->dt_trans_start(env, d, th);
2137 }
2138
2139 /* for this transaction hooks shouldn't be called */
2140 static inline int dt_trans_start_local(const struct lu_env *env,
2141                                        struct dt_device *d, struct thandle *th)
2142 {
2143         LASSERT(d->dd_ops->dt_trans_start);
2144         th->th_local = 1;
2145         return d->dd_ops->dt_trans_start(env, d, th);
2146 }
2147
2148 static inline int dt_trans_stop(const struct lu_env *env,
2149                                 struct dt_device *d, struct thandle *th)
2150 {
2151         LASSERT(d->dd_ops->dt_trans_stop);
2152         return d->dd_ops->dt_trans_stop(env, d, th);
2153 }
2154
2155 static inline int dt_trans_cb_add(struct thandle *th,
2156                                   struct dt_txn_commit_cb *dcb)
2157 {
2158         LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2159         dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2160         return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2161 }
2162 /** @} dt */
2163
2164
2165 static inline int dt_declare_record_write(const struct lu_env *env,
2166                                           struct dt_object *dt,
2167                                           const struct lu_buf *buf,
2168                                           loff_t pos,
2169                                           struct thandle *th)
2170 {
2171         int rc;
2172
2173         LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2174         LASSERT(th != NULL);
2175         LASSERT(dt->do_body_ops);
2176         LASSERT(dt->do_body_ops->dbo_declare_write);
2177         rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2178         return rc;
2179 }
2180
2181 static inline int dt_declare_create(const struct lu_env *env,
2182                                     struct dt_object *dt,
2183                                     struct lu_attr *attr,
2184                                     struct dt_allocation_hint *hint,
2185                                     struct dt_object_format *dof,
2186                                     struct thandle *th)
2187 {
2188         LASSERT(dt);
2189         LASSERT(dt->do_ops);
2190         LASSERT(dt->do_ops->do_declare_create);
2191
2192         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2193                 return cfs_fail_err;
2194
2195         return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2196 }
2197
2198 static inline int dt_create(const struct lu_env *env,
2199                                     struct dt_object *dt,
2200                                     struct lu_attr *attr,
2201                                     struct dt_allocation_hint *hint,
2202                                     struct dt_object_format *dof,
2203                                     struct thandle *th)
2204 {
2205         LASSERT(dt);
2206         LASSERT(dt->do_ops);
2207         LASSERT(dt->do_ops->do_create);
2208
2209         if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2210                 return cfs_fail_err;
2211
2212         return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2213 }
2214
2215 static inline int dt_declare_destroy(const struct lu_env *env,
2216                                      struct dt_object *dt,
2217                                      struct thandle *th)
2218 {
2219         LASSERT(dt);
2220         LASSERT(dt->do_ops);
2221         LASSERT(dt->do_ops->do_declare_destroy);
2222
2223         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2224                 return cfs_fail_err;
2225
2226         return dt->do_ops->do_declare_destroy(env, dt, th);
2227 }
2228
2229 static inline int dt_destroy(const struct lu_env *env,
2230                              struct dt_object *dt,
2231                              struct thandle *th)
2232 {
2233         LASSERT(dt);
2234         LASSERT(dt->do_ops);
2235         LASSERT(dt->do_ops->do_destroy);
2236
2237         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2238                 return cfs_fail_err;
2239
2240         return dt->do_ops->do_destroy(env, dt, th);
2241 }
2242
2243 static inline void dt_read_lock(const struct lu_env *env,
2244                                 struct dt_object *dt,
2245                                 unsigned role)
2246 {
2247         LASSERT(dt);
2248         LASSERT(dt->do_ops);
2249         LASSERT(dt->do_ops->do_read_lock);
2250         dt->do_ops->do_read_lock(env, dt, role);
2251 }
2252
2253 static inline void dt_write_lock(const struct lu_env *env,
2254                                 struct dt_object *dt,
2255                                 unsigned role)
2256 {
2257         LASSERT(dt);
2258         LASSERT(dt->do_ops);
2259         LASSERT(dt->do_ops->do_write_lock);
2260         dt->do_ops->do_write_lock(env, dt, role);
2261 }
2262
2263 static inline void dt_read_unlock(const struct lu_env *env,
2264                                 struct dt_object *dt)
2265 {
2266         LASSERT(dt);
2267         LASSERT(dt->do_ops);
2268         LASSERT(dt->do_ops->do_read_unlock);
2269         dt->do_ops->do_read_unlock(env, dt);
2270 }
2271
2272 static inline void dt_write_unlock(const struct lu_env *env,
2273                                 struct dt_object *dt)
2274 {
2275         LASSERT(dt);
2276         LASSERT(dt->do_ops);
2277         LASSERT(dt->do_ops->do_write_unlock);
2278         dt->do_ops->do_write_unlock(env, dt);
2279 }
2280
2281 static inline int dt_write_locked(const struct lu_env *env,
2282                                   struct dt_object *dt)
2283 {
2284         LASSERT(dt);
2285         LASSERT(dt->do_ops);
2286         LASSERT(dt->do_ops->do_write_locked);
2287         return dt->do_ops->do_write_locked(env, dt);
2288 }
2289
2290 static inline int dt_declare_attr_get(const struct lu_env *env,
2291                                       struct dt_object *dt)
2292 {
2293         LASSERT(dt);
2294         LASSERT(dt->do_ops);
2295         LASSERT(dt->do_ops->do_declare_attr_get);
2296
2297         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2298                 return cfs_fail_err;
2299
2300         return dt->do_ops->do_declare_attr_get(env, dt);
2301 }
2302
2303 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2304                               struct lu_attr *la)
2305 {
2306         LASSERT(dt);
2307         LASSERT(dt->do_ops);
2308         LASSERT(dt->do_ops->do_attr_get);
2309
2310         if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2311                 return cfs_fail_err;
2312
2313         return dt->do_ops->do_attr_get(env, dt, la);
2314 }
2315
2316 static inline int dt_declare_attr_set(const struct lu_env *env,
2317                                       struct dt_object *dt,
2318                                       const struct lu_attr *la,
2319                                       struct thandle *th)
2320 {
2321         LASSERT(dt);
2322         LASSERT(dt->do_ops);
2323         LASSERT(dt->do_ops->do_declare_attr_set);
2324
2325         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2326                 return cfs_fail_err;
2327
2328         return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2329 }
2330
2331 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2332                               const struct lu_attr *la, struct thandle *th)
2333 {
2334         LASSERT(dt);
2335         LASSERT(dt->do_ops);
2336         LASSERT(dt->do_ops->do_attr_set);
2337
2338         if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2339                 return cfs_fail_err;
2340
2341         return dt->do_ops->do_attr_set(env, dt, la, th);
2342 }
2343
2344 static inline int dt_declare_ref_add(const struct lu_env *env,
2345                                      struct dt_object *dt, struct thandle *th)
2346 {
2347         LASSERT(dt);
2348         LASSERT(dt->do_ops);
2349         LASSERT(dt->do_ops->do_declare_ref_add);
2350
2351         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2352                 return cfs_fail_err;
2353
2354         return dt->do_ops->do_declare_ref_add(env, dt, th);
2355 }
2356
2357 static inline int dt_ref_add(const struct lu_env *env,
2358                              struct dt_object *dt, struct thandle *th)
2359 {
2360         LASSERT(dt);
2361         LASSERT(dt->do_ops);
2362         LASSERT(dt->do_ops->do_ref_add);
2363
2364         if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2365                 return cfs_fail_err;
2366
2367         return dt->do_ops->do_ref_add(env, dt, th);
2368 }
2369
2370 static inline int dt_declare_ref_del(const struct lu_env *env,
2371                                      struct dt_object *dt, struct thandle *th)
2372 {
2373         LASSERT(dt);
2374         LASSERT(dt->do_ops);
2375         LASSERT(dt->do_ops->do_declare_ref_del);
2376
2377         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2378                 return cfs_fail_err;
2379
2380         return dt->do_ops->do_declare_ref_del(env, dt, th);
2381 }
2382
2383 static inline int dt_ref_del(const struct lu_env *env,
2384                              struct dt_object *dt, struct thandle *th)
2385 {
2386         LASSERT(dt);
2387         LASSERT(dt->do_ops);
2388         LASSERT(dt->do_ops->do_ref_del);
2389
2390         if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2391                 return cfs_fail_err;
2392
2393         return dt->do_ops->do_ref_del(env, dt, th);
2394 }
2395
2396 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2397                               struct niobuf_remote *rnb,
2398                               struct niobuf_local *lnb, enum dt_bufs_type rw)
2399 {
2400         LASSERT(d);
2401         LASSERT(d->do_body_ops);
2402         LASSERT(d->do_body_ops->dbo_bufs_get);
2403         return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2404                                             rnb->rnb_len, lnb, rw);
2405 }
2406
2407 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2408                               struct niobuf_local *lnb, int n)
2409 {
2410         LASSERT(d);
2411         LASSERT(d->do_body_ops);
2412         LASSERT(d->do_body_ops->dbo_bufs_put);
2413         return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2414 }
2415
2416 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2417                                 struct niobuf_local *lnb, int n)
2418 {
2419         LASSERT(d);
2420         LASSERT(d->do_body_ops);
2421         LASSERT(d->do_body_ops->dbo_write_prep);
2422         return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2423 }
2424
2425 static inline int dt_declare_write_commit(const struct lu_env *env,
2426                                           struct dt_object *d,
2427                                           struct niobuf_local *lnb,
2428                                           int n, struct thandle *th)
2429 {
2430         LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2431         LASSERT(th != NULL);
2432         return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2433 }
2434
2435
2436 static inline int dt_write_commit(const struct lu_env *env,
2437                                   struct dt_object *d, struct niobuf_local *lnb,
2438                                   int n, struct thandle *th)
2439 {
2440         LASSERT(d);
2441         LASSERT(d->do_body_ops);
2442         LASSERT(d->do_body_ops->dbo_write_commit);
2443         return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2444 }
2445
2446 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2447                                struct niobuf_local *lnb, int n)
2448 {
2449         LASSERT(d);
2450         LASSERT(d->do_body_ops);
2451         LASSERT(d->do_body_ops->dbo_read_prep);
2452         return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2453 }
2454
2455 static inline int dt_declare_write(const struct lu_env *env,
2456                                    struct dt_object *dt,
2457                                    const struct lu_buf *buf, loff_t pos,
2458                                    struct thandle *th)
2459 {
2460         LASSERT(dt);
2461         LASSERT(dt->do_body_ops);
2462         LASSERT(dt->do_body_ops->dbo_declare_write);
2463         return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2464 }
2465
2466 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2467                                const struct lu_buf *buf, loff_t *pos,
2468                                struct thandle *th, int rq)
2469 {
2470         LASSERT(dt);
2471         LASSERT(dt->do_body_ops);
2472         LASSERT(dt->do_body_ops->dbo_write);
2473         return dt->do_body_ops->dbo_write(env, dt, buf, pos, th, rq);
2474 }
2475
2476 static inline int dt_declare_punch(const struct lu_env *env,
2477                                    struct dt_object *dt, __u64 start,
2478                                    __u64 end, struct thandle *th)
2479 {
2480         LASSERT(dt);
2481         LASSERT(dt->do_body_ops);
2482         LASSERT(dt->do_body_ops->dbo_declare_punch);
2483         return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2484 }
2485
2486 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2487                            __u64 start, __u64 end, struct thandle *th)
2488 {
2489         LASSERT(dt);
2490         LASSERT(dt->do_body_ops);
2491         LASSERT(dt->do_body_ops->dbo_punch);
2492         return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2493 }
2494
2495 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2496                              __u64 start, __u64 end, int advice)
2497 {
2498         LASSERT(dt);
2499         LASSERT(dt->do_body_ops);
2500         LASSERT(dt->do_body_ops->dbo_ladvise);
2501         return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2502 }
2503
2504 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2505                                 struct fiemap *fm)
2506 {
2507         LASSERT(d);
2508         if (d->do_body_ops == NULL)
2509                 return -EPROTO;
2510         if (d->do_body_ops->dbo_fiemap_get == NULL)
2511                 return -EOPNOTSUPP;
2512         return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2513 }
2514
2515 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2516                             struct obd_statfs *osfs)
2517 {
2518         LASSERT(dev);
2519         LASSERT(dev->dd_ops);
2520         LASSERT(dev->dd_ops->dt_statfs);
2521         return dev->dd_ops->dt_statfs(env, dev, osfs);
2522 }
2523
2524 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2525                               struct lu_fid *f)
2526 {
2527         LASSERT(dev);
2528         LASSERT(dev->dd_ops);
2529         LASSERT(dev->dd_ops->dt_root_get);
2530         return dev->dd_ops->dt_root_get(env, dev, f);
2531 }
2532
2533 static inline void dt_conf_get(const struct lu_env *env,
2534                                const struct dt_device *dev,
2535                                struct dt_device_param *param)
2536 {
2537         LASSERT(dev);
2538         LASSERT(dev->dd_ops);
2539         LASSERT(dev->dd_ops->dt_conf_get);
2540         return dev->dd_ops->dt_conf_get(env, dev, param);
2541 }
2542
2543 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2544 {
2545         LASSERT(dev);
2546         LASSERT(dev->dd_ops);
2547         LASSERT(dev->dd_ops->dt_sync);
2548         return dev->dd_ops->dt_sync(env, dev);
2549 }
2550
2551 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2552 {
2553         LASSERT(dev);
2554         LASSERT(dev->dd_ops);
2555         LASSERT(dev->dd_ops->dt_ro);
2556         return dev->dd_ops->dt_ro(env, dev);
2557 }
2558
2559 static inline int dt_declare_insert(const struct lu_env *env,
2560                                     struct dt_object *dt,
2561                                     const struct dt_rec *rec,
2562                                     const struct dt_key *key,
2563                                     struct thandle *th)
2564 {
2565         LASSERT(dt);
2566         LASSERT(dt->do_index_ops);
2567         LASSERT(dt->do_index_ops->dio_declare_insert);
2568
2569         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2570                 return cfs_fail_err;
2571
2572         return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2573 }
2574
2575 static inline int dt_insert(const struct lu_env *env,
2576                                     struct dt_object *dt,
2577                                     const struct dt_rec *rec,
2578                                     const struct dt_key *key,
2579                                     struct thandle *th,
2580                                     int noquota)
2581 {
2582         LASSERT(dt);
2583         LASSERT(dt->do_index_ops);
2584         LASSERT(dt->do_index_ops->dio_insert);
2585
2586         if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2587                 return cfs_fail_err;
2588
2589         return dt->do_index_ops->dio_insert(env, dt, rec, key, th, noquota);
2590 }
2591
2592 static inline int dt_declare_xattr_del(const struct lu_env *env,
2593                                        struct dt_object *dt,
2594                                        const char *name,
2595                                        struct thandle *th)
2596 {
2597         LASSERT(dt);
2598         LASSERT(dt->do_ops);
2599         LASSERT(dt->do_ops->do_declare_xattr_del);
2600
2601         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2602                 return cfs_fail_err;
2603
2604         return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2605 }
2606
2607 static inline int dt_xattr_del(const struct lu_env *env,
2608                                struct dt_object *dt, const char *name,
2609                                struct thandle *th)
2610 {
2611         LASSERT(dt);
2612         LASSERT(dt->do_ops);
2613         LASSERT(dt->do_ops->do_xattr_del);
2614
2615         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2616                 return cfs_fail_err;
2617
2618         return dt->do_ops->do_xattr_del(env, dt, name, th);
2619 }
2620
2621 static inline int dt_declare_xattr_set(const struct lu_env *env,
2622                                       struct dt_object *dt,
2623                                       const struct lu_buf *buf,
2624                                       const char *name, int fl,
2625                                       struct thandle *th)
2626 {
2627         LASSERT(dt);
2628         LASSERT(dt->do_ops);
2629         LASSERT(dt->do_ops->do_declare_xattr_set);
2630
2631         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2632                 return cfs_fail_err;
2633
2634         return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2635 }
2636
2637 static inline int dt_xattr_set(const struct lu_env *env,
2638                                struct dt_object *dt, const struct lu_buf *buf,
2639                                const char *name, int fl, struct thandle *th)
2640 {
2641         LASSERT(dt);
2642         LASSERT(dt->do_ops);
2643         LASSERT(dt->do_ops->do_xattr_set);
2644
2645         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2646                 return cfs_fail_err;
2647
2648         return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2649 }
2650
2651 static inline int dt_declare_xattr_get(const struct lu_env *env,
2652                                        struct dt_object *dt,
2653                                        struct lu_buf *buf,
2654                                        const char *name)
2655 {
2656         LASSERT(dt);
2657         LASSERT(dt->do_ops);
2658         LASSERT(dt->do_ops->do_declare_xattr_get);
2659
2660         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2661                 return cfs_fail_err;
2662
2663         return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2664 }
2665
2666 static inline int dt_xattr_get(const struct lu_env *env,
2667                                struct dt_object *dt, struct lu_buf *buf,
2668                                const char *name)
2669 {
2670         LASSERT(dt);
2671         LASSERT(dt->do_ops);
2672         LASSERT(dt->do_ops->do_xattr_get);
2673
2674         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2675                 return cfs_fail_err;
2676
2677         return dt->do_ops->do_xattr_get(env, dt, buf, name);
2678 }
2679
2680 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2681                                 const struct lu_buf *buf)
2682 {
2683         LASSERT(dt);
2684         LASSERT(dt->do_ops);
2685         LASSERT(dt->do_ops->do_xattr_list);
2686
2687         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2688                 return cfs_fail_err;
2689
2690         return dt->do_ops->do_xattr_list(env, dt, buf);
2691 }
2692
2693 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2694 {
2695         LASSERT(dt);
2696         LASSERT(dt->do_ops);
2697         LASSERT(dt->do_ops->do_invalidate);
2698
2699         return dt->do_ops->do_invalidate(env, dt);
2700 }
2701
2702 static inline int dt_declare_delete(const struct lu_env *env,
2703                                     struct dt_object *dt,
2704                                     const struct dt_key *key,
2705                                     struct thandle *th)
2706 {
2707         LASSERT(dt);
2708         LASSERT(dt->do_index_ops);
2709         LASSERT(dt->do_index_ops->dio_declare_delete);
2710
2711         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2712                 return cfs_fail_err;
2713
2714         return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2715 }
2716
2717 static inline int dt_delete(const struct lu_env *env,
2718                             struct dt_object *dt,
2719                             const struct dt_key *key,
2720                             struct thandle *th)
2721 {
2722         LASSERT(dt);
2723         LASSERT(dt->do_index_ops);
2724         LASSERT(dt->do_index_ops->dio_delete);
2725
2726         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2727                 return cfs_fail_err;
2728
2729         return dt->do_index_ops->dio_delete(env, dt, key, th);
2730 }
2731
2732 static inline int dt_commit_async(const struct lu_env *env,
2733                                   struct dt_device *dev)
2734 {
2735         LASSERT(dev);
2736         LASSERT(dev->dd_ops);
2737         LASSERT(dev->dd_ops->dt_commit_async);
2738         return dev->dd_ops->dt_commit_async(env, dev);
2739 }
2740
2741 static inline int dt_lookup(const struct lu_env *env,
2742                             struct dt_object *dt,
2743                             struct dt_rec *rec,
2744                             const struct dt_key *key)
2745 {
2746         int ret;
2747
2748         LASSERT(dt);
2749         LASSERT(dt->do_index_ops);
2750         LASSERT(dt->do_index_ops->dio_lookup);
2751
2752         if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2753                 return cfs_fail_err;
2754
2755         ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2756         if (ret > 0)
2757                 ret = 0;
2758         else if (ret == 0)
2759                 ret = -ENOENT;
2760         return ret;
2761 }
2762
2763 static inline int dt_declare_layout_change(const struct lu_env *env,
2764                                            struct dt_object *o,
2765                                            struct md_layout_change *mlc,
2766                                            struct thandle *th)
2767 {
2768         LASSERT(o);
2769         LASSERT(o->do_ops);
2770         LASSERT(o->do_ops->do_declare_layout_change);
2771         return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2772 }
2773
2774 static inline int dt_layout_change(const struct lu_env *env,
2775                                    struct dt_object *o,
2776                                    struct md_layout_change *mlc,
2777                                    struct thandle *th)
2778 {
2779         LASSERT(o);
2780         LASSERT(o->do_ops);
2781         LASSERT(o->do_ops->do_layout_change);
2782         return o->do_ops->do_layout_change(env, o, mlc, th);
2783 }
2784
2785 struct dt_find_hint {
2786         struct lu_fid        *dfh_fid;
2787         struct dt_device     *dfh_dt;
2788         struct dt_object     *dfh_o;
2789 };
2790
2791 struct dt_insert_rec {
2792         union {
2793                 const struct lu_fid     *rec_fid;
2794                 void                    *rec_data;
2795         };
2796         union {
2797                 struct {
2798                         __u32            rec_type;
2799                         __u32            rec_padding;
2800                 };
2801                 __u64                    rec_misc;
2802         };
2803 };
2804
2805 struct dt_thread_info {
2806         char                     dti_buf[DT_MAX_PATH];
2807         struct dt_find_hint      dti_dfh;
2808         struct lu_attr           dti_attr;
2809         struct lu_fid            dti_fid;
2810         struct dt_object_format  dti_dof;
2811         struct lustre_mdt_attrs  dti_lma;
2812         struct lu_buf            dti_lb;
2813         struct lu_object_conf    dti_conf;
2814         loff_t                   dti_off;
2815         struct dt_insert_rec     dti_dt_rec;
2816 };
2817
2818 extern struct lu_context_key dt_key;
2819
2820 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2821 {
2822         struct dt_thread_info *dti;
2823
2824         dti = lu_context_key_get(&env->le_ctx, &dt_key);
2825         LASSERT(dti);
2826         return dti;
2827 }
2828
2829 int dt_global_init(void);
2830 void dt_global_fini(void);
2831 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2832                      const char *name, struct lprocfs_vars *list);
2833 int dt_tunables_fini(struct dt_device *dt);
2834
2835 # ifdef CONFIG_PROC_FS
2836 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2837 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2838 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2839 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2840 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2841 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2842 # endif /* CONFIG_PROC_FS */
2843
2844 #endif /* __LUSTRE_DT_OBJECT_H */