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