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