Whamcloud - gitweb
LU-12961 mdd: avoid double call to mdd_changelog_fini()
[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          * Declare intention to instaintiate extended layout component.
1067          *
1068          * \param[in] env       execution environment
1069          * \param[in] dt        DT object
1070          * \param[in] layout    data structure to describe the changes to
1071          *                      the DT object's layout
1072          * \param[in] buf       buffer containing client's lovea or empty
1073          *
1074          * \retval 0            success
1075          * \retval -ne          error code
1076          */
1077         int (*do_declare_layout_change)(const struct lu_env *env,
1078                                         struct dt_object *dt,
1079                                         struct md_layout_change *mlc,
1080                                         struct thandle *th);
1081
1082         /**
1083          * Client is trying to write to un-instantiated layout component.
1084          *
1085          * \param[in] env       execution environment
1086          * \param[in] dt        DT object
1087          * \param[in] layout    data structure to describe the changes to
1088          *                      the DT object's layout
1089          * \param[in] buf       buffer containing client's lovea or empty
1090          *
1091          * \retval 0            success
1092          * \retval -ne          error code
1093          */
1094         int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1095                                 struct md_layout_change *mlc,
1096                                 struct thandle *th);
1097 };
1098
1099 enum dt_bufs_type {
1100         DT_BUFS_TYPE_READ       = 0x0000,
1101         DT_BUFS_TYPE_WRITE      = 0x0001,
1102         DT_BUFS_TYPE_READAHEAD  = 0x0002,
1103         DT_BUFS_TYPE_LOCAL      = 0x0004,
1104 };
1105
1106 /**
1107  * Per-dt-object operations on "file body" - unstructure raw data.
1108  */
1109 struct dt_body_operations {
1110         /**
1111          * Read data.
1112          *
1113          * Read unstructured data from an existing regular object.
1114          * Only data before attr.la_size is returned.
1115          *
1116          * \param[in] env       execution environment for this thread
1117          * \param[in] dt        object
1118          * \param[out] buf      buffer (including size) to copy data in
1119          * \param[in] pos       position in the object to start
1120          * \param[out] pos      original value of \a pos + bytes returned
1121          *
1122          * \retval positive     bytes read on success
1123          * \retval negative     negated errno on error
1124          */
1125         ssize_t (*dbo_read)(const struct lu_env *env,
1126                             struct dt_object *dt,
1127                             struct lu_buf *buf,
1128                             loff_t *pos);
1129
1130         /**
1131          * Declare intention to write data to object.
1132          *
1133          * Notify the underlying filesystem that data may be written in
1134          * this transaction. This enables the layer below to prepare resources
1135          * (e.g. journal credits in ext4).  This method should be called
1136          * between creating the transaction and starting it. The object need
1137          * not exist. If the layer implementing this method is responsible for
1138          * quota, then the method should reserve space for the given credentials
1139          * and return an error if quota is over. If the write later fails
1140          * for some reason, then the reserve should be released properly
1141          * (usually in ->dt_trans_stop()).
1142          *
1143          * \param[in] env       execution environment for this thread
1144          * \param[in] dt        object
1145          * \param[in] buf       buffer (including size) to copy data from
1146          * \param[in] pos       position in the object to start
1147          * \param[in] th        transaction handle
1148          *
1149          * \retval 0            on success
1150          * \retval negative     negated errno on error
1151          */
1152         ssize_t (*dbo_declare_write)(const struct lu_env *env,
1153                                      struct dt_object *dt,
1154                                      const struct lu_buf *buf,
1155                                      loff_t pos,
1156                                      struct thandle *th);
1157
1158         /**
1159          * Write unstructured data to regular existing object.
1160          *
1161          * The method allocates space and puts data in. Also, the method should
1162          * maintain attr.la_size properly. Partial writes are possible.
1163          *
1164          * If the layer implementing this method is responsible for quota,
1165          * then the method should maintain space accounting for the given
1166          * credentials.
1167          *
1168          * \param[in] env       execution environment for this thread
1169          * \param[in] dt        object
1170          * \param[in] buf       buffer (including size) to copy data from
1171          * \param[in] pos       position in the object to start
1172          * \param[out] pos      \a pos + bytes written
1173          * \param[in] th        transaction handle
1174          *
1175          * \retval positive     bytes written on success
1176          * \retval negative     negated errno on error
1177          */
1178         ssize_t (*dbo_write)(const struct lu_env *env,
1179                              struct dt_object *dt,
1180                              const struct lu_buf *buf,
1181                              loff_t *pos,
1182                              struct thandle *th);
1183
1184         /**
1185          * Return buffers for data.
1186          *
1187          * This method is used to access data with no copying. It's so-called
1188          * zero-copy I/O. The method returns the descriptors for the internal
1189          * buffers where data are managed by the disk filesystem. For example,
1190          * pagecache in case of ext4 or ARC with ZFS. Then other components
1191          * (e.g. networking) can transfer data from or to the buffers with no
1192          * additional copying.
1193          *
1194          * The method should fill an array of struct niobuf_local, where
1195          * each element describes a full or partial page for data at specific
1196          * offset. The caller should use page/lnb_page_offset/len to find data
1197          * at object's offset lnb_file_offset.
1198          *
1199          * The memory referenced by the descriptors can't change its purpose
1200          * until the complementary ->dbo_bufs_put() is called. The caller should
1201          * specify if the buffers are used to read or modify data so that OSD
1202          * can decide how to initialize the buffers: bring all the data for
1203          * reads or just bring partial buffers for write. Note: the method does
1204          * not check whether output array is large enough.
1205          *
1206          * \param[in] env       execution environment for this thread
1207          * \param[in] dt        object
1208          * \param[in] pos       position in the object to start
1209          * \param[in] len       size of region in bytes
1210          * \param[out] lb       array of descriptors to fill
1211          * \param[in] maxlnb    max slots in @lnb array
1212          * \param[in] rw        0 if used to read, 1 if used for write
1213          *
1214          * \retval positive     number of descriptors on success
1215          * \retval negative     negated errno on error
1216          */
1217         int (*dbo_bufs_get)(const struct lu_env *env,
1218                             struct dt_object *dt,
1219                             loff_t pos,
1220                             ssize_t len,
1221                             struct niobuf_local *lb,
1222                             int maxlnb,
1223                             enum dt_bufs_type rw);
1224
1225         /**
1226          * Release reference granted by ->dbo_bufs_get().
1227          *
1228          * Release the reference granted by the previous ->dbo_bufs_get().
1229          * Note the references are counted.
1230          *
1231          * \param[in] env       execution environment for this thread
1232          * \param[in] dt        object
1233          * \param[out] lb       array of descriptors to fill
1234          * \param[in] nr        size of the array
1235          *
1236          * \retval 0            on success
1237          * \retval negative     negated errno on error
1238          */
1239         int (*dbo_bufs_put)(const struct lu_env *env,
1240                             struct dt_object *dt,
1241                             struct niobuf_local *lb,
1242                             int nr);
1243
1244         /**
1245          * Prepare buffers for reading.
1246          *
1247          * The method is called on the given buffers to fill them with data
1248          * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1249          * caller should be able to get few buffers for discontiguous regions
1250          * using few calls to ->dbo_bufs_get() and then request them all for
1251          * the preparation with a single call, so that OSD can fire many I/Os
1252          * to run concurrently. It's up to the specific OSD whether to implement
1253          * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1254          * prepare data for every requested region individually.
1255          *
1256          * \param[in] env       execution environment for this thread
1257          * \param[in] dt        object
1258          * \param[in] lnb       array of buffer descriptors
1259          * \param[in] nr        size of the array
1260          *
1261          * \retval 0            on success
1262          * \retval negative     negated errno on error
1263          */
1264         int (*dbo_read_prep)(const struct lu_env *env,
1265                              struct dt_object *dt,
1266                              struct niobuf_local *lnb,
1267                              int nr);
1268
1269         /**
1270          * Prepare buffers for write.
1271          *
1272          * This method is called on the given buffers to ensure the partial
1273          * buffers contain correct data. The underlying idea is the same as
1274          * in ->db_read_prep().
1275          *
1276          * \param[in] env       execution environment for this thread
1277          * \param[in] dt        object
1278          * \param[in] lb        array of buffer descriptors
1279          * \param[in] nr        size of the array
1280          *
1281          * \retval 0            on success
1282          * \retval negative     negated errno on error
1283          */
1284         int (*dbo_write_prep)(const struct lu_env *env,
1285                               struct dt_object *dt,
1286                               struct niobuf_local *lb,
1287                               int nr);
1288
1289         /**
1290          * Declare intention to write data stored in the buffers.
1291          *
1292          * Notify the underlying filesystem that data may be written in
1293          * this transaction. This enables the layer below to prepare resources
1294          * (e.g. journal credits in ext4).  This method should be called
1295          * between creating the transaction and starting it.
1296          *
1297          * If the layer implementing this method is responsible for quota,
1298          * then the method should be reserving a space for the given
1299          * credentials and return an error if quota is exceeded. If the write
1300          * later fails for some reason, then the reserve should be released
1301          * properly (usually in ->dt_trans_stop()).
1302          *
1303          * \param[in] env       execution environment for this thread
1304          * \param[in] dt        object
1305          * \param[in] lb        array of descriptors
1306          * \param[in] nr        size of the array
1307          * \param[in] th        transaction handle
1308          *
1309          * \retval 0            on success
1310          * \retval negative     negated errno on error
1311          */
1312         int (*dbo_declare_write_commit)(const struct lu_env *env,
1313                                         struct dt_object *dt,
1314                                         struct niobuf_local *lb,
1315                                         int nr,
1316                                         struct thandle *th);
1317
1318         /**
1319          * Write to existing object.
1320          *
1321          * This method is used to write data to a persistent storage using
1322          * the buffers returned by ->dbo_bufs_get(). The caller puts new
1323          * data into the buffers using own mechanisms (e.g. direct transfer
1324          * from a NIC). The method should maintain attr.la_size. Also,
1325          * attr.la_blocks should be maintained but this can be done in lazy
1326          * manner, when actual allocation happens.
1327          *
1328          * If the layer implementing this method is responsible for quota,
1329          * then the method should maintain space accounting for the given
1330          * credentials.
1331          *
1332          * user_size parameter is the apparent size of the file, ie the size
1333          * of the clear text version of the file. It can differ from the actual
1334          * amount of valuable data received when a file is encrypted,
1335          * because encrypted pages always contain PAGE_SIZE bytes of data,
1336          * even if clear text data is only a few bytes.
1337          * In case of encrypted file, apparent size will be stored as the inode
1338          * size, so that servers return to clients an object size they can use
1339          * to determine clear text size.
1340          *
1341          * \param[in] env       execution environment for this thread
1342          * \param[in] dt        object
1343          * \param[in] lb        array of descriptors for the buffers
1344          * \param[in] nr        size of the array
1345          * \param[in] th        transaction handle
1346          * \param[in] user_size apparent size
1347          *
1348          * \retval 0            on success
1349          * \retval negative     negated errno on error
1350          */
1351         int (*dbo_write_commit)(const struct lu_env *env,
1352                                 struct dt_object *dt,
1353                                 struct niobuf_local *lb,
1354                                 int nr,
1355                                 struct thandle *th,
1356                                 __u64 user_size);
1357
1358         /**
1359          * Return logical to physical block mapping for a given extent
1360          *
1361          * \param[in] env       execution environment for this thread
1362          * \param[in] dt        object
1363          * \param[in] fm        describe the region to map and the output buffer
1364          *                      see the details in include/linux/fiemap.h
1365          *
1366          * \retval 0            on success
1367          * \retval negative     negated errno on error
1368          */
1369         int (*dbo_fiemap_get)(const struct lu_env *env,
1370                               struct dt_object *dt,
1371                               struct fiemap *fm);
1372
1373         /**
1374          * Declare intention to deallocate space from an object.
1375          *
1376          * Notify the underlying filesystem that space may be deallocated in
1377          * this transactions. This enables the layer below to prepare resources
1378          * (e.g. journal credits in ext4).  This method should be called between
1379          * creating the transaction and starting it. The object need not exist.
1380          *
1381          * \param[in] env       execution environment for this thread
1382          * \param[in] dt        object
1383          * \param[in] start     the start of the region to deallocate
1384          * \param[in] end       the end of the region to deallocate
1385          * \param[in] th        transaction handle
1386          *
1387          * \retval 0            on success
1388          * \retval negative     negated errno on error
1389          */
1390         int   (*dbo_declare_punch)(const struct lu_env *env,
1391                                    struct dt_object *dt,
1392                                    __u64 start,
1393                                    __u64 end,
1394                                    struct thandle *th);
1395
1396         /**
1397          * Deallocate specified region in an object.
1398          *
1399          * This method is used to deallocate (release) space possibly consumed
1400          * by the given region of the object. If the layer implementing this
1401          * method is responsible for quota, then the method should maintain
1402          * space accounting for the given credentials.
1403          *
1404          * \param[in] env       execution environment for this thread
1405          * \param[in] dt        object
1406          * \param[in] start     the start of the region to deallocate
1407          * \param[in] end       the end of the region to deallocate
1408          * \param[in] th        transaction handle
1409          *
1410          * \retval 0            on success
1411          * \retval negative     negated errno on error
1412          */
1413         int   (*dbo_punch)(const struct lu_env *env,
1414                            struct dt_object *dt,
1415                            __u64 start,
1416                            __u64 end,
1417                            struct thandle *th);
1418         /**
1419          * Give advices on specified region in an object.
1420          *
1421          * This method is used to give advices about access pattern on an
1422          * given region of the object. The disk filesystem understands
1423          * the advices and tunes cache/read-ahead policies.
1424          *
1425          * \param[in] env       execution environment for this thread
1426          * \param[in] dt        object
1427          * \param[in] start     the start of the region affected
1428          * \param[in] end       the end of the region affected
1429          * \param[in] advice    advice type
1430          *
1431          * \retval 0            on success
1432          * \retval negative     negated errno on error
1433          */
1434         int   (*dbo_ladvise)(const struct lu_env *env,
1435                              struct dt_object *dt,
1436                              __u64 start,
1437                              __u64 end,
1438                              enum lu_ladvise_type advice);
1439
1440         /**
1441          * Declare intention to preallocate space for an object
1442          *
1443          * \param[in] env       execution environment for this thread
1444          * \param[in] dt        object
1445          * \param[in] th        transaction handle
1446          *
1447          * \retval 0            on success
1448          * \retval negative     negated errno on error
1449          */
1450         int (*dbo_declare_fallocate)(const struct lu_env *env,
1451                                     struct dt_object *dt, __u64 start,
1452                                     __u64 end, int mode, struct thandle *th);
1453         /**
1454          * Allocate specified region for an object
1455          *
1456          * \param[in] env       execution environment for this thread
1457          * \param[in] dt        object
1458          * \param[in] start     the start of the region to allocate
1459          * \param[in] end       the end of the region to allocate
1460          * \param[in] mode      fallocate mode
1461          * \param[in] th        transaction handle
1462          *
1463          * \retval 0            on success
1464          * \retval negative     negated errno on error
1465          */
1466         int (*dbo_fallocate)(const struct lu_env *env,
1467                             struct dt_object *dt,
1468                             __u64 start,
1469                             __u64 end,
1470                             int mode,
1471                             struct thandle *th);
1472         /**
1473          * Do SEEK_HOLE/SEEK_DATA request on object
1474          *
1475          * \param[in] env       execution environment for this thread
1476          * \param[in] dt        object
1477          * \param[in] offset    the offset to start seek from
1478          * \param[in] whence    seek mode, SEEK_HOLE or SEEK_DATA
1479          *
1480          * \retval hole/data offset     on success
1481          * \retval negative             negated errno on error
1482          */
1483         loff_t (*dbo_lseek)(const struct lu_env *env, struct dt_object *dt,
1484                             loff_t offset, int whence);
1485 };
1486
1487 /**
1488  * Incomplete type of index record.
1489  */
1490 struct dt_rec;
1491
1492 /**
1493  * Incomplete type of index key.
1494  */
1495 struct dt_key;
1496
1497 /**
1498  * Incomplete type of dt iterator.
1499  */
1500 struct dt_it;
1501
1502 /**
1503  * Per-dt-object operations on object as index. Index is a set of key/value
1504  * pairs abstracted from an on-disk representation. An index supports the
1505  * number of operations including lookup by key, insert and delete. Also,
1506  * an index can be iterated to find the pairs one by one, from a beginning
1507  * or specified point.
1508  */
1509 struct dt_index_operations {
1510         /**
1511          * Lookup in an index by key.
1512          *
1513          * The method returns a value for the given key. Key/value format
1514          * and size should have been negotiated with ->do_index_try() before.
1515          * Thus it's the caller's responsibility to provide the method with
1516          * proper key and big enough buffer. No external locking is required,
1517          * all the internal consistency should be implemented by the method
1518          * or lower layers. The object should should have been created with
1519          * type DFT_INDEX or DFT_DIR.
1520          *
1521          * \param[in] env       execution environment for this thread
1522          * \param[in] dt        object
1523          * \param[out] rec      buffer where value will be stored
1524          * \param[in] key       key
1525          *
1526          * \retval 0            on success
1527          * \retval -ENOENT      if key isn't found
1528          * \retval negative     negated errno on error
1529          */
1530         int (*dio_lookup)(const struct lu_env *env,
1531                           struct dt_object *dt,
1532                           struct dt_rec *rec,
1533                           const struct dt_key *key);
1534
1535         /**
1536          * Declare intention to insert a key/value into an index.
1537          *
1538          * Notify the underlying filesystem that new key/value may be inserted
1539          * in this transaction. This enables the layer below to prepare
1540          * resources (e.g. journal credits in ext4). This method should be
1541          * called between creating the transaction and starting it. key/value
1542          * format and size is subject to ->do_index_try().
1543          *
1544          * \param[in] env       execution environment for this thread
1545          * \param[in] dt        object
1546          * \param[in] rec       buffer storing value
1547          * \param[in] key       key
1548          * \param[in] th        transaction handle
1549          *
1550          * \retval 0            on success
1551          * \retval negative     negated errno on error
1552          */
1553         int (*dio_declare_insert)(const struct lu_env *env,
1554                                   struct dt_object *dt,
1555                                   const struct dt_rec *rec,
1556                                   const struct dt_key *key,
1557                                   struct thandle *th);
1558
1559         /**
1560          * Insert a new key/value pair into an index.
1561          *
1562          * The method inserts specified key/value pair into the given index
1563          * object. The internal consistency is maintained by the method or
1564          * the functionality below. The format and size of key/value should
1565          * have been negotiated before using ->do_index_try(), no additional
1566          * information can be specified to the method. The keys are unique
1567          * in a given index.
1568          *
1569          * \param[in] env       execution environment for this thread
1570          * \param[in] dt        object
1571          * \param[in] rec       buffer storing value
1572          * \param[in] key       key
1573          * \param[in] th        transaction handle
1574          *
1575          * \retval 0            on success
1576          * \retval negative     negated errno on error
1577          */
1578         int (*dio_insert)(const struct lu_env *env,
1579                           struct dt_object *dt,
1580                           const struct dt_rec *rec,
1581                           const struct dt_key *key,
1582                           struct thandle *th);
1583
1584         /**
1585          * Declare intention to delete a key/value from an index.
1586          *
1587          * Notify the underlying filesystem that key/value may be deleted in
1588          * this transaction. This enables the layer below to prepare resources
1589          * (e.g. journal credits in ext4).  This method should be called
1590          * between creating the transaction and starting it. Key/value format
1591          * and size is subject to ->do_index_try(). The object need not exist.
1592          *
1593          * \param[in] env       execution environment for this thread
1594          * \param[in] dt        object
1595          * \param[in] key       key
1596          * \param[in] th        transaction handle
1597          *
1598          * \retval 0            on success
1599          * \retval negative     negated errno on error
1600          */
1601         int (*dio_declare_delete)(const struct lu_env *env,
1602                                   struct dt_object *dt,
1603                                   const struct dt_key *key,
1604                                   struct thandle *th);
1605
1606         /**
1607          * Delete key/value pair from an index.
1608          *
1609          * The method deletes specified key and corresponding value from the
1610          * given index object. The internal consistency is maintained by the
1611          * method or the functionality below. The format and size of the key
1612          * should have been negotiated before using ->do_index_try(), no
1613          * additional information can be specified to the method.
1614          *
1615          * \param[in] env       execution environment for this thread
1616          * \param[in] dt        object
1617          * \param[in] key       key
1618          * \param[in] th        transaction handle
1619          *
1620          * \retval 0            on success
1621          * \retval negative     negated errno on error
1622          */
1623         int (*dio_delete)(const struct lu_env *env,
1624                           struct dt_object *dt,
1625                           const struct dt_key *key,
1626                           struct thandle *th);
1627
1628         /**
1629          * Iterator interface.
1630          *
1631          * Methods to iterate over an existing index, list the keys stored and
1632          * associated values, get key/value size, etc.
1633          */
1634         struct dt_it_ops {
1635                 /**
1636                  * Allocate and initialize new iterator.
1637                  *
1638                  * The iterator is a handler to be used in the subsequent
1639                  * methods to access index's content. Note the position is
1640                  * not defined at this point and should be initialized with
1641                  * ->get() or ->load() method.
1642                  *
1643                  * \param[in] env       execution environment for this thread
1644                  * \param[in] dt        object
1645                  * \param[in] attr      ask the iterator to return part of
1646                                         the records, see LUDA_* for details
1647                  *
1648                  * \retval pointer      iterator pointer on success
1649                  * \retval ERR_PTR(errno)       on error
1650                  */
1651                 struct dt_it *(*init)(const struct lu_env *env,
1652                                       struct dt_object *dt,
1653                                       __u32 attr);
1654
1655                 /**
1656                  * Release iterator.
1657                  *
1658                  * Release the specified iterator and all the resources
1659                  * associated (e.g. the object, index cache, etc).
1660                  *
1661                  * \param[in] env       execution environment for this thread
1662                  * \param[in] di        iterator to release
1663                  */
1664                 void          (*fini)(const struct lu_env *env,
1665                                       struct dt_it *di);
1666
1667                 /**
1668                  * Move position of iterator.
1669                  *
1670                  * Move the position of the specified iterator to the specified
1671                  * key.
1672                  *
1673                  * \param[in] env       execution environment for this thread
1674                  * \param[in] di        iterator
1675                  * \param[in] key       key to position to
1676                  *
1677                  * \retval 0            if exact key is found
1678                  * \retval 1            if at the record with least key
1679                  *                      not larger than the key
1680                  * \retval negative     negated errno on error
1681                  */
1682                 int            (*get)(const struct lu_env *env,
1683                                       struct dt_it *di,
1684                                       const struct dt_key *key);
1685
1686                 /**
1687                  * Release position
1688                  *
1689                  * Complimentary method for dt_it_ops::get() above. Some
1690                  * implementation can increase a reference on the iterator in
1691                  * dt_it_ops::get(). So the caller should be able to release
1692                  * with dt_it_ops::put().
1693                  *
1694                  * \param[in] env       execution environment for this thread
1695                  * \param[in] di        iterator
1696                  */
1697                 void           (*put)(const struct lu_env *env,
1698                                       struct dt_it *di);
1699
1700                 /**
1701                  * Move to next record.
1702                  *
1703                  * Moves the position of the iterator to a next record
1704                  *
1705                  * \param[in] env       execution environment for this thread
1706                  * \param[in] di        iterator
1707                  *
1708                  * \retval 1            if no more records
1709                  * \retval 0            on success, the next record is found
1710                  * \retval negative     negated errno on error
1711                  */
1712                 int           (*next)(const struct lu_env *env,
1713                                       struct dt_it *di);
1714
1715                 /**
1716                  * Return key.
1717                  *
1718                  * Returns a pointer to a buffer containing the key of the
1719                  * record at the current position. The pointer is valid and
1720                  * retains data until ->get(), ->load() and ->fini() methods
1721                  * are called.
1722                  *
1723                  * \param[in] env       execution environment for this thread
1724                  * \param[in] di        iterator
1725                  *
1726                  * \retval pointer to key       on success
1727                  * \retval ERR_PTR(errno)       on error
1728                  */
1729                 struct dt_key *(*key)(const struct lu_env *env,
1730                                       const struct dt_it *di);
1731
1732                 /**
1733                  * Return key size.
1734                  *
1735                  * Returns size of the key at the current position.
1736                  *
1737                  * \param[in] env       execution environment for this thread
1738                  * \param[in] di        iterator
1739                  *
1740                  * \retval key's size   on success
1741                  * \retval negative     negated errno on error
1742                  */
1743                 int       (*key_size)(const struct lu_env *env,
1744                                       const struct dt_it *di);
1745
1746                 /**
1747                  * Return record.
1748                  *
1749                  * Stores the value of the record at the current position. The
1750                  * buffer must be big enough (as negotiated with
1751                  * ->do_index_try() or ->rec_size()). The caller can specify
1752                  * she is interested only in part of the record, using attr
1753                  * argument (see LUDA_* definitions for the details).
1754                  *
1755                  * \param[in] env       execution environment for this thread
1756                  * \param[in] di        iterator
1757                  * \param[out] rec      buffer to store value in
1758                  * \param[in] attr      specify part of the value to copy
1759                  *
1760                  * \retval 0            on success
1761                  * \retval negative     negated errno on error
1762                  */
1763                 int            (*rec)(const struct lu_env *env,
1764                                       const struct dt_it *di,
1765                                       struct dt_rec *rec,
1766                                       __u32 attr);
1767
1768                 /**
1769                  * Return record size.
1770                  *
1771                  * Returns size of the record at the current position. The
1772                  * \a attr can be used to specify only the parts of the record
1773                  * needed to be returned. (see LUDA_* definitions for the
1774                  * details).
1775                  *
1776                  * \param[in] env       execution environment for this thread
1777                  * \param[in] di        iterator
1778                  * \param[in] attr      part of the record to return
1779                  *
1780                  * \retval record's size        on success
1781                  * \retval negative             negated errno on error
1782                  */
1783                 int        (*rec_size)(const struct lu_env *env,
1784                                        const struct dt_it *di,
1785                                       __u32 attr);
1786
1787                 /**
1788                  * Return a cookie (hash).
1789                  *
1790                  * Returns the cookie (usually hash) of the key at the current
1791                  * position. This allows the caller to resume iteration at this
1792                  * position later. The exact value is specific to implementation
1793                  * and should not be interpreted by the caller.
1794                  *
1795                  * \param[in] env       execution environment for this thread
1796                  * \param[in] di        iterator
1797                  *
1798                  * \retval cookie/hash of the key
1799                  */
1800                 __u64        (*store)(const struct lu_env *env,
1801                                       const struct dt_it *di);
1802
1803                 /**
1804                  * Initialize position using cookie/hash.
1805                  *
1806                  * Initializes the current position of the iterator to one
1807                  * described by the cookie/hash as returned by ->store()
1808                  * previously.
1809                  *
1810                  * \param[in] env       execution environment for this thread
1811                  * \param[in] di        iterator
1812                  * \param[in] hash      cookie/hash value
1813                  *
1814                  * \retval positive     if current position points to
1815                  *                      record with least cookie not larger
1816                  *                      than cookie
1817                  * \retval 0            if current position matches cookie
1818                  * \retval negative     negated errno on error
1819                  */
1820                 int           (*load)(const struct lu_env *env,
1821                                       const struct dt_it *di,
1822                                       __u64 hash);
1823
1824                 /**
1825                  * Not used
1826                  */
1827                 int        (*key_rec)(const struct lu_env *env,
1828                                       const struct dt_it *di,
1829                                       void *key_rec);
1830         } dio_it;
1831 };
1832
1833 enum dt_otable_it_valid {
1834         DOIV_ERROR_HANDLE       = 0x0001,
1835         DOIV_DRYRUN             = 0x0002,
1836 };
1837
1838 enum dt_otable_it_flags {
1839         /* Exit when fail. */
1840         DOIF_FAILOUT    = 0x0001,
1841
1842         /* Reset iteration position to the device beginning. */
1843         DOIF_RESET      = 0x0002,
1844
1845         /* There is up layer component uses the iteration. */
1846         DOIF_OUTUSED    = 0x0004,
1847
1848         /* Check only without repairing. */
1849         DOIF_DRYRUN     = 0x0008,
1850 };
1851
1852 /* otable based iteration needs to use the common DT iteration APIs.
1853  * To initialize the iteration, it needs call dio_it::init() firstly.
1854  * Here is how the otable based iteration should prepare arguments to
1855  * call dt_it_ops::init().
1856  *
1857  * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1858  * is composed of two parts:
1859  * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1860 #define DT_OTABLE_IT_FLAGS_SHIFT        16
1861 #define DT_OTABLE_IT_FLAGS_MASK         0xffff0000
1862
1863 struct dt_device {
1864         struct lu_device                   dd_lu_dev;
1865         const struct dt_device_operations *dd_ops;
1866
1867         /**
1868          * List of dt_txn_callback (see below). This is not protected in any
1869          * way, because callbacks are supposed to be added/deleted only during
1870          * single-threaded start-up shut-down procedures.
1871          */
1872         struct list_head                   dd_txn_callbacks;
1873         unsigned int                       dd_record_fid_accessed:1,
1874                                            dd_rdonly:1;
1875
1876         /* sysfs and debugfs handling */
1877         struct dentry                     *dd_debugfs_entry;
1878
1879         const struct attribute           **dd_def_attrs;
1880         struct kobject                     dd_kobj;
1881         struct kobj_type                   dd_ktype;
1882         struct completion                  dd_kobj_unregister;
1883 };
1884
1885 int  dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1886 void dt_device_fini(struct dt_device *dev);
1887
1888 static inline int lu_device_is_dt(const struct lu_device *d)
1889 {
1890         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1891 }
1892
1893 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1894 {
1895         LASSERT(lu_device_is_dt(l));
1896         return container_of_safe(l, struct dt_device, dd_lu_dev);
1897 }
1898
1899 struct dt_object {
1900         struct lu_object                   do_lu;
1901         const struct dt_object_operations *do_ops;
1902         const struct dt_body_operations   *do_body_ops;
1903         const struct dt_index_operations  *do_index_ops;
1904 };
1905
1906 /*
1907  * In-core representation of per-device local object OID storage
1908  */
1909 struct local_oid_storage {
1910         /* all initialized llog systems on this node linked by this */
1911         struct list_head  los_list;
1912
1913         /* how many handle's reference this los has */
1914         atomic_t          los_refcount;
1915         struct dt_device *los_dev;
1916         struct dt_object *los_obj;
1917
1918         /* data used to generate new fids */
1919         struct mutex      los_id_lock;
1920         __u64             los_seq;
1921         __u32             los_last_oid;
1922 };
1923
1924 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1925 {
1926         return &d->dd_lu_dev;
1927 }
1928
1929 static inline struct dt_object *lu2dt(struct lu_object *l)
1930 {
1931         LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1932         return container_of_safe(l, struct dt_object, do_lu);
1933 }
1934
1935 int  dt_object_init(struct dt_object *obj,
1936                     struct lu_object_header *h, struct lu_device *d);
1937
1938 void dt_object_fini(struct dt_object *obj);
1939
1940 static inline int dt_object_exists(const struct dt_object *dt)
1941 {
1942         return lu_object_exists(&dt->do_lu);
1943 }
1944
1945 static inline int dt_object_remote(const struct dt_object *dt)
1946 {
1947         return lu_object_remote(&dt->do_lu);
1948 }
1949
1950 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1951 {
1952         LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1953         return container_of_safe(o, struct dt_object, do_lu);
1954 }
1955
1956 static inline struct dt_object *dt_object_child(struct dt_object *o)
1957 {
1958         return container_of(lu_object_next(&(o)->do_lu),
1959                             struct dt_object, do_lu);
1960 }
1961
1962 /**
1963  * This is the general purpose transaction handle.
1964  * 1. Transaction Life Cycle
1965  *      This transaction handle is allocated upon starting a new transaction,
1966  *      and deallocated after this transaction is committed.
1967  * 2. Transaction Nesting
1968  *      We do _NOT_ support nested transaction. So, every thread should only
1969  *      have one active transaction, and a transaction only belongs to one
1970  *      thread. Due to this, transaction handle need no reference count.
1971  * 3. Transaction & dt_object locking
1972  *      dt_object locks should be taken inside transaction.
1973  * 4. Transaction & RPC
1974  *      No RPC request should be issued inside transaction.
1975  */
1976 struct thandle {
1977         /** the dt device on which the transactions are executed */
1978         struct dt_device *th_dev;
1979
1980         /* point to the top thandle, XXX this is a bit hacky right now,
1981          * but normal device trans callback triggered by the bottom
1982          * device (OSP/OSD == sub thandle layer) needs to get the
1983          * top_thandle (see dt_txn_hook_start/stop()), so we put the
1984          * top thandle here for now, will fix it when we have better
1985          * callback mechanism */
1986         struct thandle  *th_top;
1987
1988         /** the last operation result in this transaction.
1989          * this value is used in recovery */
1990         __s32             th_result;
1991
1992         /** whether we need sync commit */
1993         unsigned int            th_sync:1,
1994         /* local transation, no need to inform other layers */
1995                                 th_local:1,
1996         /* Whether we need wait the transaction to be submitted
1997          * (send to remote target) */
1998                                 th_wait_submit:1,
1999         /* complex transaction which will track updates on all targets,
2000          * including OSTs */
2001                                 th_complex:1,
2002         /* whether ignore quota */
2003                                 th_ignore_quota:1,
2004         /* whether restart transaction */
2005                                 th_restart_tran:1;
2006 };
2007
2008 /**
2009  * Transaction call-backs.
2010  *
2011  * These are invoked by osd (or underlying transaction engine) when
2012  * transaction changes state.
2013  *
2014  * Call-backs are used by upper layers to modify transaction parameters and to
2015  * perform some actions on for each transaction state transition. Typical
2016  * example is mdt registering call-back to write into last-received file
2017  * before each transaction commit.
2018  */
2019 struct dt_txn_callback {
2020         int (*dtc_txn_start)(const struct lu_env *env,
2021                              struct thandle *txn, void *cookie);
2022         int (*dtc_txn_stop)(const struct lu_env *env,
2023                             struct thandle *txn, void *cookie);
2024         void                    *dtc_cookie;
2025         __u32                   dtc_tag;
2026         struct list_head        dtc_linkage;
2027 };
2028
2029 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
2030 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
2031
2032 int dt_txn_hook_start(const struct lu_env *env,
2033                       struct dt_device *dev, struct thandle *txn);
2034 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
2035
2036 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
2037
2038 /**
2039  * Callback function used for parsing path.
2040  * \see llo_store_resolve
2041  */
2042 typedef int (*dt_entry_func_t)(const struct lu_env *env,
2043                             const char *name,
2044                             void *pvt);
2045
2046 #define DT_MAX_PATH 1024
2047
2048 int dt_path_parser(const struct lu_env *env,
2049                    char *local, dt_entry_func_t entry_func,
2050                    void *data);
2051
2052 struct dt_object *
2053 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
2054                  const char *path, struct lu_fid *fid);
2055
2056 struct dt_object *dt_store_open(const struct lu_env *env,
2057                                 struct dt_device *dt,
2058                                 const char *dirname,
2059                                 const char *filename,
2060                                 struct lu_fid *fid);
2061
2062 struct dt_object *dt_find_or_create(const struct lu_env *env,
2063                                     struct dt_device *dt,
2064                                     const struct lu_fid *fid,
2065                                     struct dt_object_format *dof,
2066                                     struct lu_attr *attr);
2067
2068 struct dt_object *dt_locate_at(const struct lu_env *env,
2069                                struct dt_device *dev,
2070                                const struct lu_fid *fid,
2071                                struct lu_device *top_dev,
2072                                const struct lu_object_conf *conf);
2073
2074 static inline struct dt_object *
2075 dt_locate(const struct lu_env *env, struct dt_device *dev,
2076           const struct lu_fid *fid)
2077 {
2078         return dt_locate_at(env, dev, fid,
2079                             dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2080 }
2081
2082 static inline struct dt_object *
2083 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2084 {
2085         struct lu_object *lo;
2086
2087         list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2088                 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2089                         return container_of(lo, struct dt_object, do_lu);
2090         }
2091         return NULL;
2092 }
2093
2094 static inline void dt_object_put(const struct lu_env *env,
2095                                  struct dt_object *dto)
2096 {
2097         lu_object_put(env, &dto->do_lu);
2098 }
2099
2100 static inline void dt_object_put_nocache(const struct lu_env *env,
2101                                          struct dt_object *dto)
2102 {
2103         lu_object_put_nocache(env, &dto->do_lu);
2104 }
2105
2106 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2107                            const struct lu_fid *first_fid,
2108                            struct local_oid_storage **los);
2109 void local_oid_storage_fini(const struct lu_env *env,
2110                             struct local_oid_storage *los);
2111 int local_object_fid_generate(const struct lu_env *env,
2112                               struct local_oid_storage *los,
2113                               struct lu_fid *fid);
2114 int local_object_declare_create(const struct lu_env *env,
2115                                 struct local_oid_storage *los,
2116                                 struct dt_object *o,
2117                                 struct lu_attr *attr,
2118                                 struct dt_object_format *dof,
2119                                 struct thandle *th);
2120 int local_object_create(const struct lu_env *env,
2121                         struct local_oid_storage *los,
2122                         struct dt_object *o,
2123                         struct lu_attr *attr, struct dt_object_format *dof,
2124                         struct thandle *th);
2125 struct dt_object *local_file_find(const struct lu_env *env,
2126                                   struct local_oid_storage *los,
2127                                   struct dt_object *parent,
2128                                   const char *name);
2129 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2130                                             struct local_oid_storage *los,
2131                                             struct dt_object *parent,
2132                                             const char *name, __u32 mode);
2133 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2134                                                      struct dt_device *dt,
2135                                                      const struct lu_fid *fid,
2136                                                      struct dt_object *parent,
2137                                                      const char *name,
2138                                                      __u32 mode);
2139 struct dt_object *
2140 local_index_find_or_create(const struct lu_env *env,
2141                            struct local_oid_storage *los,
2142                            struct dt_object *parent,
2143                            const char *name, __u32 mode,
2144                            const struct dt_index_features *ft);
2145 struct dt_object *
2146 local_index_find_or_create_with_fid(const struct lu_env *env,
2147                                     struct dt_device *dt,
2148                                     const struct lu_fid *fid,
2149                                     struct dt_object *parent,
2150                                     const char *name, __u32 mode,
2151                                     const struct dt_index_features *ft);
2152 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2153                         struct dt_object *parent, const char *name);
2154
2155 static inline int dt_object_lock(const struct lu_env *env,
2156                                  struct dt_object *o, struct lustre_handle *lh,
2157                                  struct ldlm_enqueue_info *einfo,
2158                                  union ldlm_policy_data *policy)
2159 {
2160         LASSERT(o != NULL);
2161         LASSERT(o->do_ops != NULL);
2162         LASSERT(o->do_ops->do_object_lock != NULL);
2163         return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2164 }
2165
2166 static inline int dt_object_unlock(const struct lu_env *env,
2167                                    struct dt_object *o,
2168                                    struct ldlm_enqueue_info *einfo,
2169                                    union ldlm_policy_data *policy)
2170 {
2171         LASSERT(o != NULL);
2172         LASSERT(o->do_ops != NULL);
2173         LASSERT(o->do_ops->do_object_unlock != NULL);
2174         return o->do_ops->do_object_unlock(env, o, einfo, policy);
2175 }
2176
2177 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2178                   const char *name, struct lu_fid *fid);
2179
2180 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2181                                  __u64 start, __u64 end)
2182 {
2183         LASSERT(o);
2184         LASSERT(o->do_ops);
2185         LASSERT(o->do_ops->do_object_sync);
2186         return o->do_ops->do_object_sync(env, o, start, end);
2187 }
2188
2189 static inline int dt_fid_alloc(const struct lu_env *env,
2190                                struct dt_device *d,
2191                                struct lu_fid *fid,
2192                                struct lu_object *parent,
2193                                const struct lu_name *name)
2194 {
2195         struct lu_device *l = dt2lu_dev(d);
2196
2197         return l->ld_ops->ldo_fid_alloc(env, l, fid, parent, name);
2198 }
2199
2200 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2201                            struct thandle *th);
2202 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2203                     dt_obj_version_t version, struct thandle *th);
2204 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2205
2206
2207 int dt_read(const struct lu_env *env, struct dt_object *dt,
2208             struct lu_buf *buf, loff_t *pos);
2209 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2210                    struct lu_buf *buf, loff_t *pos);
2211 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2212                     const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2213 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2214                                      union lu_page *lp, size_t nob,
2215                                      const struct dt_it_ops *iops,
2216                                      struct dt_it *it, __u32 attr, void *arg);
2217 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2218                   const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2219                   void *arg);
2220 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2221                   struct idx_info *ii, const struct lu_rdpg *rdpg);
2222
2223 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2224                                               struct dt_device *d)
2225 {
2226         LASSERT(d->dd_ops->dt_trans_create);
2227         return d->dd_ops->dt_trans_create(env, d);
2228 }
2229
2230 static inline int dt_trans_start(const struct lu_env *env,
2231                                  struct dt_device *d, struct thandle *th)
2232 {
2233         LASSERT(d->dd_ops->dt_trans_start);
2234         return d->dd_ops->dt_trans_start(env, d, th);
2235 }
2236
2237 /* for this transaction hooks shouldn't be called */
2238 static inline int dt_trans_start_local(const struct lu_env *env,
2239                                        struct dt_device *d, struct thandle *th)
2240 {
2241         LASSERT(d->dd_ops->dt_trans_start);
2242         th->th_local = 1;
2243         return d->dd_ops->dt_trans_start(env, d, th);
2244 }
2245
2246 static inline int dt_trans_stop(const struct lu_env *env,
2247                                 struct dt_device *d, struct thandle *th)
2248 {
2249         LASSERT(d->dd_ops->dt_trans_stop);
2250         return d->dd_ops->dt_trans_stop(env, d, th);
2251 }
2252
2253 static inline int dt_trans_cb_add(struct thandle *th,
2254                                   struct dt_txn_commit_cb *dcb)
2255 {
2256         LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2257         dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2258         return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2259 }
2260 /** @} dt */
2261
2262
2263 static inline int dt_declare_record_write(const struct lu_env *env,
2264                                           struct dt_object *dt,
2265                                           const struct lu_buf *buf,
2266                                           loff_t pos,
2267                                           struct thandle *th)
2268 {
2269         int rc;
2270
2271         LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2272         LASSERT(th != NULL);
2273         LASSERTF(dt->do_body_ops, DFID" doesn't exit\n",
2274                  PFID(lu_object_fid(&dt->do_lu)));
2275         LASSERT(dt->do_body_ops->dbo_declare_write);
2276         rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2277         return rc;
2278 }
2279
2280 static inline int dt_declare_create(const struct lu_env *env,
2281                                     struct dt_object *dt,
2282                                     struct lu_attr *attr,
2283                                     struct dt_allocation_hint *hint,
2284                                     struct dt_object_format *dof,
2285                                     struct thandle *th)
2286 {
2287         LASSERT(dt);
2288         LASSERT(dt->do_ops);
2289         LASSERT(dt->do_ops->do_declare_create);
2290
2291         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2292                 return cfs_fail_err;
2293
2294         return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2295 }
2296
2297 static inline int dt_create(const struct lu_env *env,
2298                                     struct dt_object *dt,
2299                                     struct lu_attr *attr,
2300                                     struct dt_allocation_hint *hint,
2301                                     struct dt_object_format *dof,
2302                                     struct thandle *th)
2303 {
2304         LASSERT(dt);
2305         LASSERT(dt->do_ops);
2306         LASSERT(dt->do_ops->do_create);
2307
2308         if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2309                 return cfs_fail_err;
2310
2311         return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2312 }
2313
2314 static inline int dt_declare_destroy(const struct lu_env *env,
2315                                      struct dt_object *dt,
2316                                      struct thandle *th)
2317 {
2318         LASSERT(dt);
2319         LASSERT(dt->do_ops);
2320         LASSERT(dt->do_ops->do_declare_destroy);
2321
2322         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2323                 return cfs_fail_err;
2324
2325         return dt->do_ops->do_declare_destroy(env, dt, th);
2326 }
2327
2328 static inline int dt_destroy(const struct lu_env *env,
2329                              struct dt_object *dt,
2330                              struct thandle *th)
2331 {
2332         LASSERT(dt);
2333         LASSERT(dt->do_ops);
2334         LASSERT(dt->do_ops->do_destroy);
2335
2336         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2337                 return cfs_fail_err;
2338
2339         return dt->do_ops->do_destroy(env, dt, th);
2340 }
2341
2342 static inline void dt_read_lock(const struct lu_env *env,
2343                                 struct dt_object *dt,
2344                                 unsigned role)
2345 {
2346         LASSERT(dt);
2347         LASSERT(dt->do_ops);
2348         LASSERT(dt->do_ops->do_read_lock);
2349         dt->do_ops->do_read_lock(env, dt, role);
2350 }
2351
2352 static inline void dt_write_lock(const struct lu_env *env,
2353                                 struct dt_object *dt,
2354                                 unsigned role)
2355 {
2356         LASSERT(dt);
2357         LASSERT(dt->do_ops);
2358         LASSERT(dt->do_ops->do_write_lock);
2359         dt->do_ops->do_write_lock(env, dt, role);
2360 }
2361
2362 static inline void dt_read_unlock(const struct lu_env *env,
2363                                 struct dt_object *dt)
2364 {
2365         LASSERT(dt);
2366         LASSERT(dt->do_ops);
2367         LASSERT(dt->do_ops->do_read_unlock);
2368         dt->do_ops->do_read_unlock(env, dt);
2369 }
2370
2371 static inline void dt_write_unlock(const struct lu_env *env,
2372                                 struct dt_object *dt)
2373 {
2374         LASSERT(dt);
2375         LASSERT(dt->do_ops);
2376         LASSERT(dt->do_ops->do_write_unlock);
2377         dt->do_ops->do_write_unlock(env, dt);
2378 }
2379
2380 static inline int dt_write_locked(const struct lu_env *env,
2381                                   struct dt_object *dt)
2382 {
2383         LASSERT(dt);
2384         LASSERT(dt->do_ops);
2385         LASSERT(dt->do_ops->do_write_locked);
2386         return dt->do_ops->do_write_locked(env, dt);
2387 }
2388
2389 static inline int dt_declare_attr_get(const struct lu_env *env,
2390                                       struct dt_object *dt)
2391 {
2392         LASSERT(dt);
2393         LASSERT(dt->do_ops);
2394         LASSERT(dt->do_ops->do_declare_attr_get);
2395
2396         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2397                 return cfs_fail_err;
2398
2399         return dt->do_ops->do_declare_attr_get(env, dt);
2400 }
2401
2402 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2403                               struct lu_attr *la)
2404 {
2405         LASSERT(dt);
2406         LASSERT(dt->do_ops);
2407         LASSERT(dt->do_ops->do_attr_get);
2408
2409         if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2410                 return cfs_fail_err;
2411
2412         return dt->do_ops->do_attr_get(env, dt, la);
2413 }
2414
2415 static inline int dt_declare_attr_set(const struct lu_env *env,
2416                                       struct dt_object *dt,
2417                                       const struct lu_attr *la,
2418                                       struct thandle *th)
2419 {
2420         LASSERT(dt);
2421         LASSERT(dt->do_ops);
2422         LASSERT(dt->do_ops->do_declare_attr_set);
2423
2424         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2425                 return cfs_fail_err;
2426
2427         return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2428 }
2429
2430 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2431                               const struct lu_attr *la, struct thandle *th)
2432 {
2433         LASSERT(dt);
2434         LASSERT(dt->do_ops);
2435         LASSERT(dt->do_ops->do_attr_set);
2436
2437         if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2438                 return cfs_fail_err;
2439
2440         return dt->do_ops->do_attr_set(env, dt, la, th);
2441 }
2442
2443 static inline int dt_declare_ref_add(const struct lu_env *env,
2444                                      struct dt_object *dt, struct thandle *th)
2445 {
2446         LASSERT(dt);
2447         LASSERT(dt->do_ops);
2448         LASSERT(dt->do_ops->do_declare_ref_add);
2449
2450         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2451                 return cfs_fail_err;
2452
2453         return dt->do_ops->do_declare_ref_add(env, dt, th);
2454 }
2455
2456 static inline int dt_ref_add(const struct lu_env *env,
2457                              struct dt_object *dt, struct thandle *th)
2458 {
2459         LASSERT(dt);
2460         LASSERT(dt->do_ops);
2461         LASSERT(dt->do_ops->do_ref_add);
2462
2463         if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2464                 return cfs_fail_err;
2465
2466         return dt->do_ops->do_ref_add(env, dt, th);
2467 }
2468
2469 static inline int dt_declare_ref_del(const struct lu_env *env,
2470                                      struct dt_object *dt, struct thandle *th)
2471 {
2472         LASSERT(dt);
2473         LASSERT(dt->do_ops);
2474         LASSERT(dt->do_ops->do_declare_ref_del);
2475
2476         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2477                 return cfs_fail_err;
2478
2479         return dt->do_ops->do_declare_ref_del(env, dt, th);
2480 }
2481
2482 static inline int dt_ref_del(const struct lu_env *env,
2483                              struct dt_object *dt, struct thandle *th)
2484 {
2485         LASSERT(dt);
2486         LASSERT(dt->do_ops);
2487         LASSERT(dt->do_ops->do_ref_del);
2488
2489         if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2490                 return cfs_fail_err;
2491
2492         return dt->do_ops->do_ref_del(env, dt, th);
2493 }
2494
2495 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2496                               struct niobuf_remote *rnb,
2497                               struct niobuf_local *lnb, int maxlnb,
2498                               enum dt_bufs_type rw)
2499 {
2500         LASSERT(d);
2501         LASSERT(d->do_body_ops);
2502         LASSERT(d->do_body_ops->dbo_bufs_get);
2503         return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2504                                             rnb->rnb_len, lnb, maxlnb, rw);
2505 }
2506
2507 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2508                               struct niobuf_local *lnb, int n)
2509 {
2510         LASSERT(d);
2511         LASSERT(d->do_body_ops);
2512         LASSERT(d->do_body_ops->dbo_bufs_put);
2513         return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2514 }
2515
2516 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2517                                 struct niobuf_local *lnb, int n)
2518 {
2519         LASSERT(d);
2520         LASSERT(d->do_body_ops);
2521         LASSERT(d->do_body_ops->dbo_write_prep);
2522         return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2523 }
2524
2525 static inline int dt_declare_write_commit(const struct lu_env *env,
2526                                           struct dt_object *d,
2527                                           struct niobuf_local *lnb,
2528                                           int n, struct thandle *th)
2529 {
2530         LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2531         LASSERT(th != NULL);
2532         return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2533 }
2534
2535
2536 static inline int dt_write_commit(const struct lu_env *env,
2537                                   struct dt_object *d, struct niobuf_local *lnb,
2538                                   int n, struct thandle *th, __u64 size)
2539 {
2540         LASSERT(d);
2541         LASSERT(d->do_body_ops);
2542         LASSERT(d->do_body_ops->dbo_write_commit);
2543         return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th, size);
2544 }
2545
2546 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2547                                struct niobuf_local *lnb, int n)
2548 {
2549         LASSERT(d);
2550         LASSERT(d->do_body_ops);
2551         LASSERT(d->do_body_ops->dbo_read_prep);
2552         return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2553 }
2554
2555 static inline int dt_declare_write(const struct lu_env *env,
2556                                    struct dt_object *dt,
2557                                    const struct lu_buf *buf, loff_t pos,
2558                                    struct thandle *th)
2559 {
2560         LASSERT(dt);
2561         LASSERT(dt->do_body_ops);
2562         LASSERT(dt->do_body_ops->dbo_declare_write);
2563         return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2564 }
2565
2566 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2567                                const struct lu_buf *buf, loff_t *pos,
2568                                struct thandle *th)
2569 {
2570         LASSERT(dt);
2571         LASSERT(dt->do_body_ops);
2572         LASSERT(dt->do_body_ops->dbo_write);
2573         return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2574 }
2575
2576 static inline int dt_declare_punch(const struct lu_env *env,
2577                                    struct dt_object *dt, __u64 start,
2578                                    __u64 end, struct thandle *th)
2579 {
2580         LASSERT(dt);
2581         LASSERT(dt->do_body_ops);
2582         LASSERT(dt->do_body_ops->dbo_declare_punch);
2583         return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2584 }
2585
2586 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2587                            __u64 start, __u64 end, struct thandle *th)
2588 {
2589         LASSERT(dt);
2590         LASSERT(dt->do_body_ops);
2591         LASSERT(dt->do_body_ops->dbo_punch);
2592         return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2593 }
2594
2595 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2596                              __u64 start, __u64 end, int advice)
2597 {
2598         LASSERT(dt);
2599         LASSERT(dt->do_body_ops);
2600         LASSERT(dt->do_body_ops->dbo_ladvise);
2601         return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2602 }
2603
2604 static inline int dt_declare_fallocate(const struct lu_env *env,
2605                                        struct dt_object *dt, __u64 start,
2606                                        __u64 end, int mode, struct thandle *th)
2607 {
2608         LASSERT(dt);
2609         if (!dt->do_body_ops)
2610                 return -EOPNOTSUPP;
2611         LASSERT(dt->do_body_ops);
2612         LASSERT(dt->do_body_ops->dbo_declare_fallocate);
2613         return dt->do_body_ops->dbo_declare_fallocate(env, dt, start, end,
2614                                                       mode, th);
2615 }
2616
2617 static inline int dt_falloc(const struct lu_env *env, struct dt_object *dt,
2618                               __u64 start, __u64 end, int mode,
2619                               struct thandle *th)
2620 {
2621         LASSERT(dt);
2622         if (!dt->do_body_ops)
2623                 return -EOPNOTSUPP;
2624         LASSERT(dt->do_body_ops);
2625         LASSERT(dt->do_body_ops->dbo_fallocate);
2626         return dt->do_body_ops->dbo_fallocate(env, dt, start, end, mode, th);
2627 }
2628
2629 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2630                                 struct fiemap *fm)
2631 {
2632         LASSERT(d);
2633         if (d->do_body_ops == NULL)
2634                 return -EPROTO;
2635         if (d->do_body_ops->dbo_fiemap_get == NULL)
2636                 return -EOPNOTSUPP;
2637         return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2638 }
2639
2640 static inline loff_t dt_lseek(const struct lu_env *env, struct dt_object *d,
2641                               loff_t offset, int whence)
2642 {
2643         LASSERT(d);
2644         if (d->do_body_ops == NULL)
2645                 return -EPROTO;
2646         if (d->do_body_ops->dbo_lseek == NULL)
2647                 return -EOPNOTSUPP;
2648         return d->do_body_ops->dbo_lseek(env, d, offset, whence);
2649 }
2650
2651 static inline int dt_statfs_info(const struct lu_env *env,
2652                                  struct dt_device *dev,
2653                                 struct obd_statfs *osfs,
2654                                 struct obd_statfs_info *info)
2655 {
2656         LASSERT(dev);
2657         LASSERT(dev->dd_ops);
2658         LASSERT(dev->dd_ops->dt_statfs);
2659         return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2660 }
2661
2662 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2663                             struct obd_statfs *osfs)
2664 {
2665         return dt_statfs_info(env, dev, osfs, NULL);
2666 }
2667
2668 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2669                               struct lu_fid *f)
2670 {
2671         LASSERT(dev);
2672         LASSERT(dev->dd_ops);
2673         LASSERT(dev->dd_ops->dt_root_get);
2674         return dev->dd_ops->dt_root_get(env, dev, f);
2675 }
2676
2677 static inline void dt_conf_get(const struct lu_env *env,
2678                                const struct dt_device *dev,
2679                                struct dt_device_param *param)
2680 {
2681         LASSERT(dev);
2682         LASSERT(dev->dd_ops);
2683         LASSERT(dev->dd_ops->dt_conf_get);
2684         return dev->dd_ops->dt_conf_get(env, dev, param);
2685 }
2686
2687 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2688 {
2689         LASSERT(dev);
2690         LASSERT(dev->dd_ops);
2691         if (dev->dd_ops->dt_mnt_sb_get)
2692                 return dev->dd_ops->dt_mnt_sb_get(dev);
2693
2694         return ERR_PTR(-EOPNOTSUPP);
2695 }
2696
2697 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2698 {
2699         LASSERT(dev);
2700         LASSERT(dev->dd_ops);
2701         LASSERT(dev->dd_ops->dt_sync);
2702         return dev->dd_ops->dt_sync(env, dev);
2703 }
2704
2705 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2706 {
2707         LASSERT(dev);
2708         LASSERT(dev->dd_ops);
2709         LASSERT(dev->dd_ops->dt_ro);
2710         return dev->dd_ops->dt_ro(env, dev);
2711 }
2712
2713 static inline void dt_wait_quota_pending(struct dt_device *dev)
2714 {
2715         LASSERT(dev);
2716         LASSERT(dev->dd_ops);
2717         if (dev->dd_ops->dt_wait_quota_pending)
2718                 dev->dd_ops->dt_wait_quota_pending(dev);
2719 }
2720
2721 static inline int dt_declare_insert(const struct lu_env *env,
2722                                     struct dt_object *dt,
2723                                     const struct dt_rec *rec,
2724                                     const struct dt_key *key,
2725                                     struct thandle *th)
2726 {
2727         LASSERT(dt);
2728         LASSERT(dt->do_index_ops);
2729         LASSERT(dt->do_index_ops->dio_declare_insert);
2730
2731         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2732                 return cfs_fail_err;
2733
2734         return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2735 }
2736
2737 static inline int dt_insert(const struct lu_env *env,
2738                             struct dt_object *dt,
2739                             const struct dt_rec *rec,
2740                             const struct dt_key *key,
2741                             struct thandle *th)
2742 {
2743         LASSERT(dt);
2744         LASSERT(dt->do_index_ops);
2745         LASSERT(dt->do_index_ops->dio_insert);
2746
2747         if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2748                 return cfs_fail_err;
2749
2750         return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2751 }
2752
2753 static inline int dt_declare_xattr_del(const struct lu_env *env,
2754                                        struct dt_object *dt,
2755                                        const char *name,
2756                                        struct thandle *th)
2757 {
2758         LASSERT(dt);
2759         LASSERT(dt->do_ops);
2760         LASSERT(dt->do_ops->do_declare_xattr_del);
2761
2762         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2763                 return cfs_fail_err;
2764
2765         return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2766 }
2767
2768 static inline int dt_xattr_del(const struct lu_env *env,
2769                                struct dt_object *dt, const char *name,
2770                                struct thandle *th)
2771 {
2772         LASSERT(dt);
2773         LASSERT(dt->do_ops);
2774         LASSERT(dt->do_ops->do_xattr_del);
2775
2776         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2777                 return cfs_fail_err;
2778
2779         return dt->do_ops->do_xattr_del(env, dt, name, th);
2780 }
2781
2782 static inline int dt_declare_xattr_set(const struct lu_env *env,
2783                                       struct dt_object *dt,
2784                                       const struct lu_buf *buf,
2785                                       const char *name, int fl,
2786                                       struct thandle *th)
2787 {
2788         LASSERT(dt);
2789         LASSERT(dt->do_ops);
2790         LASSERT(dt->do_ops->do_declare_xattr_set);
2791
2792         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2793                 return cfs_fail_err;
2794
2795         return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2796 }
2797
2798 static inline int dt_xattr_set(const struct lu_env *env,
2799                                struct dt_object *dt, const struct lu_buf *buf,
2800                                const char *name, int fl, struct thandle *th)
2801 {
2802         LASSERT(dt);
2803         LASSERT(dt->do_ops);
2804         LASSERT(dt->do_ops->do_xattr_set);
2805
2806         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2807                 return cfs_fail_err;
2808
2809         return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2810 }
2811
2812 static inline int dt_declare_xattr_get(const struct lu_env *env,
2813                                        struct dt_object *dt,
2814                                        struct lu_buf *buf,
2815                                        const char *name)
2816 {
2817         LASSERT(dt);
2818         LASSERT(dt->do_ops);
2819         LASSERT(dt->do_ops->do_declare_xattr_get);
2820
2821         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2822                 return cfs_fail_err;
2823
2824         return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2825 }
2826
2827 static inline int dt_xattr_get(const struct lu_env *env,
2828                                struct dt_object *dt, struct lu_buf *buf,
2829                                const char *name)
2830 {
2831         LASSERT(dt);
2832         LASSERT(dt->do_ops);
2833         LASSERT(dt->do_ops->do_xattr_get);
2834
2835         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2836                 return cfs_fail_err;
2837
2838         return dt->do_ops->do_xattr_get(env, dt, buf, name);
2839 }
2840
2841 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2842                                 const struct lu_buf *buf)
2843 {
2844         LASSERT(dt);
2845         LASSERT(dt->do_ops);
2846         LASSERT(dt->do_ops->do_xattr_list);
2847
2848         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2849                 return cfs_fail_err;
2850
2851         return dt->do_ops->do_xattr_list(env, dt, buf);
2852 }
2853
2854 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2855 {
2856         LASSERT(dt);
2857         LASSERT(dt->do_ops);
2858         LASSERT(dt->do_ops->do_invalidate);
2859
2860         return dt->do_ops->do_invalidate(env, dt);
2861 }
2862
2863 static inline int dt_declare_delete(const struct lu_env *env,
2864                                     struct dt_object *dt,
2865                                     const struct dt_key *key,
2866                                     struct thandle *th)
2867 {
2868         LASSERT(dt);
2869         LASSERT(dt->do_index_ops);
2870         LASSERT(dt->do_index_ops->dio_declare_delete);
2871
2872         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2873                 return cfs_fail_err;
2874
2875         return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2876 }
2877
2878 static inline int dt_delete(const struct lu_env *env,
2879                             struct dt_object *dt,
2880                             const struct dt_key *key,
2881                             struct thandle *th)
2882 {
2883         LASSERT(dt);
2884         LASSERT(dt->do_index_ops);
2885         LASSERT(dt->do_index_ops->dio_delete);
2886
2887         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2888                 return cfs_fail_err;
2889
2890         return dt->do_index_ops->dio_delete(env, dt, key, th);
2891 }
2892
2893 static inline int dt_commit_async(const struct lu_env *env,
2894                                   struct dt_device *dev)
2895 {
2896         LASSERT(dev);
2897         LASSERT(dev->dd_ops);
2898         LASSERT(dev->dd_ops->dt_commit_async);
2899         return dev->dd_ops->dt_commit_async(env, dev);
2900 }
2901
2902 static inline int dt_lookup(const struct lu_env *env,
2903                             struct dt_object *dt,
2904                             struct dt_rec *rec,
2905                             const struct dt_key *key)
2906 {
2907         int ret;
2908
2909         LASSERT(dt);
2910         LASSERT(dt->do_index_ops);
2911         LASSERT(dt->do_index_ops->dio_lookup);
2912
2913         if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2914                 return cfs_fail_err;
2915
2916         ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2917         if (ret > 0)
2918                 ret = 0;
2919         else if (ret == 0)
2920                 ret = -ENOENT;
2921         return ret;
2922 }
2923
2924 static inline int dt_declare_layout_change(const struct lu_env *env,
2925                                            struct dt_object *o,
2926                                            struct md_layout_change *mlc,
2927                                            struct thandle *th)
2928 {
2929         LASSERT(o);
2930         LASSERT(o->do_ops);
2931         LASSERT(o->do_ops->do_declare_layout_change);
2932         return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2933 }
2934
2935 static inline int dt_layout_change(const struct lu_env *env,
2936                                    struct dt_object *o,
2937                                    struct md_layout_change *mlc,
2938                                    struct thandle *th)
2939 {
2940         LASSERT(o);
2941         LASSERT(o->do_ops);
2942         LASSERT(o->do_ops->do_layout_change);
2943         return o->do_ops->do_layout_change(env, o, mlc, th);
2944 }
2945
2946 struct dt_find_hint {
2947         struct lu_fid        *dfh_fid;
2948         struct dt_device     *dfh_dt;
2949         struct dt_object     *dfh_o;
2950 };
2951
2952 struct dt_insert_rec {
2953         union {
2954                 const struct lu_fid     *rec_fid;
2955                 void                    *rec_data;
2956         };
2957         union {
2958                 struct {
2959                         __u32            rec_type;
2960                         __u32            rec_padding;
2961                 };
2962                 __u64                    rec_misc;
2963         };
2964 };
2965
2966 struct dt_thread_info {
2967         char                     dti_buf[DT_MAX_PATH];
2968         struct dt_find_hint      dti_dfh;
2969         struct lu_attr           dti_attr;
2970         struct lu_fid            dti_fid;
2971         struct dt_object_format  dti_dof;
2972         struct lustre_mdt_attrs  dti_lma;
2973         struct lu_buf            dti_lb;
2974         struct lu_object_conf    dti_conf;
2975         loff_t                   dti_off;
2976         struct dt_insert_rec     dti_dt_rec;
2977 };
2978
2979 extern struct lu_context_key dt_key;
2980
2981 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2982 {
2983         struct dt_thread_info *dti;
2984
2985         dti = lu_context_key_get(&env->le_ctx, &dt_key);
2986         LASSERT(dti);
2987         return dti;
2988 }
2989
2990 int dt_global_init(void);
2991 void dt_global_fini(void);
2992 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2993                      const char *name, struct ldebugfs_vars *list);
2994 int dt_tunables_fini(struct dt_device *dt);
2995
2996 # ifdef CONFIG_PROC_FS
2997 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2998 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2999 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
3000 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
3001 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
3002 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
3003 # endif /* CONFIG_PROC_FS */
3004
3005 #endif /* __LUSTRE_DT_OBJECT_H */