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