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