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