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