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