Whamcloud - gitweb
e1d574a832ee50eef1e0df1f221718e9b12b20ae
[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 };
2005
2006 /**
2007  * Transaction call-backs.
2008  *
2009  * These are invoked by osd (or underlying transaction engine) when
2010  * transaction changes state.
2011  *
2012  * Call-backs are used by upper layers to modify transaction parameters and to
2013  * perform some actions on for each transaction state transition. Typical
2014  * example is mdt registering call-back to write into last-received file
2015  * before each transaction commit.
2016  */
2017 struct dt_txn_callback {
2018         int (*dtc_txn_start)(const struct lu_env *env,
2019                              struct thandle *txn, void *cookie);
2020         int (*dtc_txn_stop)(const struct lu_env *env,
2021                             struct thandle *txn, void *cookie);
2022         void                    *dtc_cookie;
2023         __u32                   dtc_tag;
2024         struct list_head        dtc_linkage;
2025 };
2026
2027 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
2028 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
2029
2030 int dt_txn_hook_start(const struct lu_env *env,
2031                       struct dt_device *dev, struct thandle *txn);
2032 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
2033
2034 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
2035
2036 /**
2037  * Callback function used for parsing path.
2038  * \see llo_store_resolve
2039  */
2040 typedef int (*dt_entry_func_t)(const struct lu_env *env,
2041                             const char *name,
2042                             void *pvt);
2043
2044 #define DT_MAX_PATH 1024
2045
2046 int dt_path_parser(const struct lu_env *env,
2047                    char *local, dt_entry_func_t entry_func,
2048                    void *data);
2049
2050 struct dt_object *
2051 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
2052                  const char *path, struct lu_fid *fid);
2053
2054 struct dt_object *dt_store_open(const struct lu_env *env,
2055                                 struct dt_device *dt,
2056                                 const char *dirname,
2057                                 const char *filename,
2058                                 struct lu_fid *fid);
2059
2060 struct dt_object *dt_find_or_create(const struct lu_env *env,
2061                                     struct dt_device *dt,
2062                                     const struct lu_fid *fid,
2063                                     struct dt_object_format *dof,
2064                                     struct lu_attr *attr);
2065
2066 struct dt_object *dt_locate_at(const struct lu_env *env,
2067                                struct dt_device *dev,
2068                                const struct lu_fid *fid,
2069                                struct lu_device *top_dev,
2070                                const struct lu_object_conf *conf);
2071
2072 static inline struct dt_object *
2073 dt_locate(const struct lu_env *env, struct dt_device *dev,
2074           const struct lu_fid *fid)
2075 {
2076         return dt_locate_at(env, dev, fid,
2077                             dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2078 }
2079
2080 static inline struct dt_object *
2081 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2082 {
2083         struct lu_object *lo;
2084
2085         list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2086                 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2087                         return container_of(lo, struct dt_object, do_lu);
2088         }
2089         return NULL;
2090 }
2091
2092 static inline void dt_object_put(const struct lu_env *env,
2093                                  struct dt_object *dto)
2094 {
2095         lu_object_put(env, &dto->do_lu);
2096 }
2097
2098 static inline void dt_object_put_nocache(const struct lu_env *env,
2099                                          struct dt_object *dto)
2100 {
2101         lu_object_put_nocache(env, &dto->do_lu);
2102 }
2103
2104 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2105                            const struct lu_fid *first_fid,
2106                            struct local_oid_storage **los);
2107 void local_oid_storage_fini(const struct lu_env *env,
2108                             struct local_oid_storage *los);
2109 int local_object_fid_generate(const struct lu_env *env,
2110                               struct local_oid_storage *los,
2111                               struct lu_fid *fid);
2112 int local_object_declare_create(const struct lu_env *env,
2113                                 struct local_oid_storage *los,
2114                                 struct dt_object *o,
2115                                 struct lu_attr *attr,
2116                                 struct dt_object_format *dof,
2117                                 struct thandle *th);
2118 int local_object_create(const struct lu_env *env,
2119                         struct local_oid_storage *los,
2120                         struct dt_object *o,
2121                         struct lu_attr *attr, struct dt_object_format *dof,
2122                         struct thandle *th);
2123 struct dt_object *local_file_find(const struct lu_env *env,
2124                                   struct local_oid_storage *los,
2125                                   struct dt_object *parent,
2126                                   const char *name);
2127 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2128                                             struct local_oid_storage *los,
2129                                             struct dt_object *parent,
2130                                             const char *name, __u32 mode);
2131 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2132                                                      struct dt_device *dt,
2133                                                      const struct lu_fid *fid,
2134                                                      struct dt_object *parent,
2135                                                      const char *name,
2136                                                      __u32 mode);
2137 struct dt_object *
2138 local_index_find_or_create(const struct lu_env *env,
2139                            struct local_oid_storage *los,
2140                            struct dt_object *parent,
2141                            const char *name, __u32 mode,
2142                            const struct dt_index_features *ft);
2143 struct dt_object *
2144 local_index_find_or_create_with_fid(const struct lu_env *env,
2145                                     struct dt_device *dt,
2146                                     const struct lu_fid *fid,
2147                                     struct dt_object *parent,
2148                                     const char *name, __u32 mode,
2149                                     const struct dt_index_features *ft);
2150 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2151                         struct dt_object *parent, const char *name);
2152
2153 static inline int dt_object_lock(const struct lu_env *env,
2154                                  struct dt_object *o, struct lustre_handle *lh,
2155                                  struct ldlm_enqueue_info *einfo,
2156                                  union ldlm_policy_data *policy)
2157 {
2158         LASSERT(o != NULL);
2159         LASSERT(o->do_ops != NULL);
2160         LASSERT(o->do_ops->do_object_lock != NULL);
2161         return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2162 }
2163
2164 static inline int dt_object_unlock(const struct lu_env *env,
2165                                    struct dt_object *o,
2166                                    struct ldlm_enqueue_info *einfo,
2167                                    union ldlm_policy_data *policy)
2168 {
2169         LASSERT(o != NULL);
2170         LASSERT(o->do_ops != NULL);
2171         LASSERT(o->do_ops->do_object_unlock != NULL);
2172         return o->do_ops->do_object_unlock(env, o, einfo, policy);
2173 }
2174
2175 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2176                   const char *name, struct lu_fid *fid);
2177
2178 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2179                                  __u64 start, __u64 end)
2180 {
2181         LASSERT(o);
2182         LASSERT(o->do_ops);
2183         LASSERT(o->do_ops->do_object_sync);
2184         return o->do_ops->do_object_sync(env, o, start, end);
2185 }
2186
2187 static inline int dt_fid_alloc(const struct lu_env *env,
2188                                struct dt_device *d,
2189                                struct lu_fid *fid,
2190                                struct lu_object *parent,
2191                                const struct lu_name *name)
2192 {
2193         struct lu_device *l = dt2lu_dev(d);
2194
2195         return l->ld_ops->ldo_fid_alloc(env, l, fid, parent, name);
2196 }
2197
2198 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2199                            struct thandle *th);
2200 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2201                     dt_obj_version_t version, struct thandle *th);
2202 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2203
2204
2205 int dt_read(const struct lu_env *env, struct dt_object *dt,
2206             struct lu_buf *buf, loff_t *pos);
2207 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2208                    struct lu_buf *buf, loff_t *pos);
2209 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2210                     const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2211 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2212                                      union lu_page *lp, size_t nob,
2213                                      const struct dt_it_ops *iops,
2214                                      struct dt_it *it, __u32 attr, void *arg);
2215 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2216                   const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2217                   void *arg);
2218 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2219                   struct idx_info *ii, const struct lu_rdpg *rdpg);
2220
2221 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2222                                               struct dt_device *d)
2223 {
2224         LASSERT(d->dd_ops->dt_trans_create);
2225         return d->dd_ops->dt_trans_create(env, d);
2226 }
2227
2228 static inline int dt_trans_start(const struct lu_env *env,
2229                                  struct dt_device *d, struct thandle *th)
2230 {
2231         LASSERT(d->dd_ops->dt_trans_start);
2232         return d->dd_ops->dt_trans_start(env, d, th);
2233 }
2234
2235 /* for this transaction hooks shouldn't be called */
2236 static inline int dt_trans_start_local(const struct lu_env *env,
2237                                        struct dt_device *d, struct thandle *th)
2238 {
2239         LASSERT(d->dd_ops->dt_trans_start);
2240         th->th_local = 1;
2241         return d->dd_ops->dt_trans_start(env, d, th);
2242 }
2243
2244 static inline int dt_trans_stop(const struct lu_env *env,
2245                                 struct dt_device *d, struct thandle *th)
2246 {
2247         LASSERT(d->dd_ops->dt_trans_stop);
2248         return d->dd_ops->dt_trans_stop(env, d, th);
2249 }
2250
2251 static inline int dt_trans_cb_add(struct thandle *th,
2252                                   struct dt_txn_commit_cb *dcb)
2253 {
2254         LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2255         dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2256         return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2257 }
2258 /** @} dt */
2259
2260
2261 static inline int dt_declare_record_write(const struct lu_env *env,
2262                                           struct dt_object *dt,
2263                                           const struct lu_buf *buf,
2264                                           loff_t pos,
2265                                           struct thandle *th)
2266 {
2267         int rc;
2268
2269         LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2270         LASSERT(th != NULL);
2271         LASSERTF(dt->do_body_ops, DFID" doesn't exit\n",
2272                  PFID(lu_object_fid(&dt->do_lu)));
2273         LASSERT(dt->do_body_ops->dbo_declare_write);
2274         rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2275         return rc;
2276 }
2277
2278 static inline int dt_declare_create(const struct lu_env *env,
2279                                     struct dt_object *dt,
2280                                     struct lu_attr *attr,
2281                                     struct dt_allocation_hint *hint,
2282                                     struct dt_object_format *dof,
2283                                     struct thandle *th)
2284 {
2285         LASSERT(dt);
2286         LASSERT(dt->do_ops);
2287         LASSERT(dt->do_ops->do_declare_create);
2288
2289         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2290                 return cfs_fail_err;
2291
2292         return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2293 }
2294
2295 static inline int dt_create(const struct lu_env *env,
2296                                     struct dt_object *dt,
2297                                     struct lu_attr *attr,
2298                                     struct dt_allocation_hint *hint,
2299                                     struct dt_object_format *dof,
2300                                     struct thandle *th)
2301 {
2302         LASSERT(dt);
2303         LASSERT(dt->do_ops);
2304         LASSERT(dt->do_ops->do_create);
2305
2306         if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2307                 return cfs_fail_err;
2308
2309         return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2310 }
2311
2312 static inline int dt_declare_destroy(const struct lu_env *env,
2313                                      struct dt_object *dt,
2314                                      struct thandle *th)
2315 {
2316         LASSERT(dt);
2317         LASSERT(dt->do_ops);
2318         LASSERT(dt->do_ops->do_declare_destroy);
2319
2320         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2321                 return cfs_fail_err;
2322
2323         return dt->do_ops->do_declare_destroy(env, dt, th);
2324 }
2325
2326 static inline int dt_destroy(const struct lu_env *env,
2327                              struct dt_object *dt,
2328                              struct thandle *th)
2329 {
2330         LASSERT(dt);
2331         LASSERT(dt->do_ops);
2332         LASSERT(dt->do_ops->do_destroy);
2333
2334         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2335                 return cfs_fail_err;
2336
2337         return dt->do_ops->do_destroy(env, dt, th);
2338 }
2339
2340 static inline void dt_read_lock(const struct lu_env *env,
2341                                 struct dt_object *dt,
2342                                 unsigned role)
2343 {
2344         LASSERT(dt);
2345         LASSERT(dt->do_ops);
2346         LASSERT(dt->do_ops->do_read_lock);
2347         dt->do_ops->do_read_lock(env, dt, role);
2348 }
2349
2350 static inline void dt_write_lock(const struct lu_env *env,
2351                                 struct dt_object *dt,
2352                                 unsigned role)
2353 {
2354         LASSERT(dt);
2355         LASSERT(dt->do_ops);
2356         LASSERT(dt->do_ops->do_write_lock);
2357         dt->do_ops->do_write_lock(env, dt, role);
2358 }
2359
2360 static inline void dt_read_unlock(const struct lu_env *env,
2361                                 struct dt_object *dt)
2362 {
2363         LASSERT(dt);
2364         LASSERT(dt->do_ops);
2365         LASSERT(dt->do_ops->do_read_unlock);
2366         dt->do_ops->do_read_unlock(env, dt);
2367 }
2368
2369 static inline void dt_write_unlock(const struct lu_env *env,
2370                                 struct dt_object *dt)
2371 {
2372         LASSERT(dt);
2373         LASSERT(dt->do_ops);
2374         LASSERT(dt->do_ops->do_write_unlock);
2375         dt->do_ops->do_write_unlock(env, dt);
2376 }
2377
2378 static inline int dt_write_locked(const struct lu_env *env,
2379                                   struct dt_object *dt)
2380 {
2381         LASSERT(dt);
2382         LASSERT(dt->do_ops);
2383         LASSERT(dt->do_ops->do_write_locked);
2384         return dt->do_ops->do_write_locked(env, dt);
2385 }
2386
2387 static inline int dt_declare_attr_get(const struct lu_env *env,
2388                                       struct dt_object *dt)
2389 {
2390         LASSERT(dt);
2391         LASSERT(dt->do_ops);
2392         LASSERT(dt->do_ops->do_declare_attr_get);
2393
2394         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2395                 return cfs_fail_err;
2396
2397         return dt->do_ops->do_declare_attr_get(env, dt);
2398 }
2399
2400 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2401                               struct lu_attr *la)
2402 {
2403         LASSERT(dt);
2404         LASSERT(dt->do_ops);
2405         LASSERT(dt->do_ops->do_attr_get);
2406
2407         if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2408                 return cfs_fail_err;
2409
2410         return dt->do_ops->do_attr_get(env, dt, la);
2411 }
2412
2413 static inline int dt_declare_attr_set(const struct lu_env *env,
2414                                       struct dt_object *dt,
2415                                       const struct lu_attr *la,
2416                                       struct thandle *th)
2417 {
2418         LASSERT(dt);
2419         LASSERT(dt->do_ops);
2420         LASSERT(dt->do_ops->do_declare_attr_set);
2421
2422         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2423                 return cfs_fail_err;
2424
2425         return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2426 }
2427
2428 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2429                               const struct lu_attr *la, struct thandle *th)
2430 {
2431         LASSERT(dt);
2432         LASSERT(dt->do_ops);
2433         LASSERT(dt->do_ops->do_attr_set);
2434
2435         if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2436                 return cfs_fail_err;
2437
2438         return dt->do_ops->do_attr_set(env, dt, la, th);
2439 }
2440
2441 static inline int dt_declare_ref_add(const struct lu_env *env,
2442                                      struct dt_object *dt, struct thandle *th)
2443 {
2444         LASSERT(dt);
2445         LASSERT(dt->do_ops);
2446         LASSERT(dt->do_ops->do_declare_ref_add);
2447
2448         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2449                 return cfs_fail_err;
2450
2451         return dt->do_ops->do_declare_ref_add(env, dt, th);
2452 }
2453
2454 static inline int dt_ref_add(const struct lu_env *env,
2455                              struct dt_object *dt, struct thandle *th)
2456 {
2457         LASSERT(dt);
2458         LASSERT(dt->do_ops);
2459         LASSERT(dt->do_ops->do_ref_add);
2460
2461         if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2462                 return cfs_fail_err;
2463
2464         return dt->do_ops->do_ref_add(env, dt, th);
2465 }
2466
2467 static inline int dt_declare_ref_del(const struct lu_env *env,
2468                                      struct dt_object *dt, struct thandle *th)
2469 {
2470         LASSERT(dt);
2471         LASSERT(dt->do_ops);
2472         LASSERT(dt->do_ops->do_declare_ref_del);
2473
2474         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2475                 return cfs_fail_err;
2476
2477         return dt->do_ops->do_declare_ref_del(env, dt, th);
2478 }
2479
2480 static inline int dt_ref_del(const struct lu_env *env,
2481                              struct dt_object *dt, struct thandle *th)
2482 {
2483         LASSERT(dt);
2484         LASSERT(dt->do_ops);
2485         LASSERT(dt->do_ops->do_ref_del);
2486
2487         if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2488                 return cfs_fail_err;
2489
2490         return dt->do_ops->do_ref_del(env, dt, th);
2491 }
2492
2493 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2494                               struct niobuf_remote *rnb,
2495                               struct niobuf_local *lnb, int maxlnb,
2496                               enum dt_bufs_type rw)
2497 {
2498         LASSERT(d);
2499         LASSERT(d->do_body_ops);
2500         LASSERT(d->do_body_ops->dbo_bufs_get);
2501         return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2502                                             rnb->rnb_len, lnb, maxlnb, rw);
2503 }
2504
2505 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2506                               struct niobuf_local *lnb, int n)
2507 {
2508         LASSERT(d);
2509         LASSERT(d->do_body_ops);
2510         LASSERT(d->do_body_ops->dbo_bufs_put);
2511         return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2512 }
2513
2514 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2515                                 struct niobuf_local *lnb, int n)
2516 {
2517         LASSERT(d);
2518         LASSERT(d->do_body_ops);
2519         LASSERT(d->do_body_ops->dbo_write_prep);
2520         return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2521 }
2522
2523 static inline int dt_declare_write_commit(const struct lu_env *env,
2524                                           struct dt_object *d,
2525                                           struct niobuf_local *lnb,
2526                                           int n, struct thandle *th)
2527 {
2528         LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2529         LASSERT(th != NULL);
2530         return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2531 }
2532
2533
2534 static inline int dt_write_commit(const struct lu_env *env,
2535                                   struct dt_object *d, struct niobuf_local *lnb,
2536                                   int n, struct thandle *th, __u64 size)
2537 {
2538         LASSERT(d);
2539         LASSERT(d->do_body_ops);
2540         LASSERT(d->do_body_ops->dbo_write_commit);
2541         return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th, size);
2542 }
2543
2544 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2545                                struct niobuf_local *lnb, int n)
2546 {
2547         LASSERT(d);
2548         LASSERT(d->do_body_ops);
2549         LASSERT(d->do_body_ops->dbo_read_prep);
2550         return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2551 }
2552
2553 static inline int dt_declare_write(const struct lu_env *env,
2554                                    struct dt_object *dt,
2555                                    const struct lu_buf *buf, loff_t pos,
2556                                    struct thandle *th)
2557 {
2558         LASSERT(dt);
2559         LASSERT(dt->do_body_ops);
2560         LASSERT(dt->do_body_ops->dbo_declare_write);
2561         return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2562 }
2563
2564 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2565                                const struct lu_buf *buf, loff_t *pos,
2566                                struct thandle *th)
2567 {
2568         LASSERT(dt);
2569         LASSERT(dt->do_body_ops);
2570         LASSERT(dt->do_body_ops->dbo_write);
2571         return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2572 }
2573
2574 static inline int dt_declare_punch(const struct lu_env *env,
2575                                    struct dt_object *dt, __u64 start,
2576                                    __u64 end, struct thandle *th)
2577 {
2578         LASSERT(dt);
2579         LASSERT(dt->do_body_ops);
2580         LASSERT(dt->do_body_ops->dbo_declare_punch);
2581         return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2582 }
2583
2584 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2585                            __u64 start, __u64 end, struct thandle *th)
2586 {
2587         LASSERT(dt);
2588         LASSERT(dt->do_body_ops);
2589         LASSERT(dt->do_body_ops->dbo_punch);
2590         return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2591 }
2592
2593 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2594                              __u64 start, __u64 end, int advice)
2595 {
2596         LASSERT(dt);
2597         LASSERT(dt->do_body_ops);
2598         LASSERT(dt->do_body_ops->dbo_ladvise);
2599         return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2600 }
2601
2602 static inline int dt_declare_fallocate(const struct lu_env *env,
2603                                        struct dt_object *dt, __u64 start,
2604                                        __u64 end, int mode, struct thandle *th)
2605 {
2606         LASSERT(dt);
2607         if (!dt->do_body_ops)
2608                 return -EOPNOTSUPP;
2609         LASSERT(dt->do_body_ops);
2610         LASSERT(dt->do_body_ops->dbo_declare_fallocate);
2611         return dt->do_body_ops->dbo_declare_fallocate(env, dt, start, end,
2612                                                       mode, th);
2613 }
2614
2615 static inline int dt_falloc(const struct lu_env *env, struct dt_object *dt,
2616                               __u64 start, __u64 end, int mode,
2617                               struct thandle *th)
2618 {
2619         LASSERT(dt);
2620         if (!dt->do_body_ops)
2621                 return -EOPNOTSUPP;
2622         LASSERT(dt->do_body_ops);
2623         LASSERT(dt->do_body_ops->dbo_fallocate);
2624         return dt->do_body_ops->dbo_fallocate(env, dt, start, end, mode, th);
2625 }
2626
2627 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2628                                 struct fiemap *fm)
2629 {
2630         LASSERT(d);
2631         if (d->do_body_ops == NULL)
2632                 return -EPROTO;
2633         if (d->do_body_ops->dbo_fiemap_get == NULL)
2634                 return -EOPNOTSUPP;
2635         return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2636 }
2637
2638 static inline loff_t dt_lseek(const struct lu_env *env, struct dt_object *d,
2639                               loff_t offset, int whence)
2640 {
2641         LASSERT(d);
2642         if (d->do_body_ops == NULL)
2643                 return -EPROTO;
2644         if (d->do_body_ops->dbo_lseek == NULL)
2645                 return -EOPNOTSUPP;
2646         return d->do_body_ops->dbo_lseek(env, d, offset, whence);
2647 }
2648
2649 static inline int dt_statfs_info(const struct lu_env *env,
2650                                  struct dt_device *dev,
2651                                 struct obd_statfs *osfs,
2652                                 struct obd_statfs_info *info)
2653 {
2654         LASSERT(dev);
2655         LASSERT(dev->dd_ops);
2656         LASSERT(dev->dd_ops->dt_statfs);
2657         return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2658 }
2659
2660 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2661                             struct obd_statfs *osfs)
2662 {
2663         return dt_statfs_info(env, dev, osfs, NULL);
2664 }
2665
2666 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2667                               struct lu_fid *f)
2668 {
2669         LASSERT(dev);
2670         LASSERT(dev->dd_ops);
2671         LASSERT(dev->dd_ops->dt_root_get);
2672         return dev->dd_ops->dt_root_get(env, dev, f);
2673 }
2674
2675 static inline void dt_conf_get(const struct lu_env *env,
2676                                const struct dt_device *dev,
2677                                struct dt_device_param *param)
2678 {
2679         LASSERT(dev);
2680         LASSERT(dev->dd_ops);
2681         LASSERT(dev->dd_ops->dt_conf_get);
2682         return dev->dd_ops->dt_conf_get(env, dev, param);
2683 }
2684
2685 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2686 {
2687         LASSERT(dev);
2688         LASSERT(dev->dd_ops);
2689         if (dev->dd_ops->dt_mnt_sb_get)
2690                 return dev->dd_ops->dt_mnt_sb_get(dev);
2691
2692         return ERR_PTR(-EOPNOTSUPP);
2693 }
2694
2695 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2696 {
2697         LASSERT(dev);
2698         LASSERT(dev->dd_ops);
2699         LASSERT(dev->dd_ops->dt_sync);
2700         return dev->dd_ops->dt_sync(env, dev);
2701 }
2702
2703 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2704 {
2705         LASSERT(dev);
2706         LASSERT(dev->dd_ops);
2707         LASSERT(dev->dd_ops->dt_ro);
2708         return dev->dd_ops->dt_ro(env, dev);
2709 }
2710
2711 static inline void dt_wait_quota_pending(struct dt_device *dev)
2712 {
2713         LASSERT(dev);
2714         LASSERT(dev->dd_ops);
2715         if (dev->dd_ops->dt_wait_quota_pending)
2716                 dev->dd_ops->dt_wait_quota_pending(dev);
2717 }
2718
2719 static inline int dt_declare_insert(const struct lu_env *env,
2720                                     struct dt_object *dt,
2721                                     const struct dt_rec *rec,
2722                                     const struct dt_key *key,
2723                                     struct thandle *th)
2724 {
2725         LASSERT(dt);
2726         LASSERT(dt->do_index_ops);
2727         LASSERT(dt->do_index_ops->dio_declare_insert);
2728
2729         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2730                 return cfs_fail_err;
2731
2732         return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2733 }
2734
2735 static inline int dt_insert(const struct lu_env *env,
2736                             struct dt_object *dt,
2737                             const struct dt_rec *rec,
2738                             const struct dt_key *key,
2739                             struct thandle *th)
2740 {
2741         LASSERT(dt);
2742         LASSERT(dt->do_index_ops);
2743         LASSERT(dt->do_index_ops->dio_insert);
2744
2745         if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2746                 return cfs_fail_err;
2747
2748         return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2749 }
2750
2751 static inline int dt_declare_xattr_del(const struct lu_env *env,
2752                                        struct dt_object *dt,
2753                                        const char *name,
2754                                        struct thandle *th)
2755 {
2756         LASSERT(dt);
2757         LASSERT(dt->do_ops);
2758         LASSERT(dt->do_ops->do_declare_xattr_del);
2759
2760         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2761                 return cfs_fail_err;
2762
2763         return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2764 }
2765
2766 static inline int dt_xattr_del(const struct lu_env *env,
2767                                struct dt_object *dt, const char *name,
2768                                struct thandle *th)
2769 {
2770         LASSERT(dt);
2771         LASSERT(dt->do_ops);
2772         LASSERT(dt->do_ops->do_xattr_del);
2773
2774         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2775                 return cfs_fail_err;
2776
2777         return dt->do_ops->do_xattr_del(env, dt, name, th);
2778 }
2779
2780 static inline int dt_declare_xattr_set(const struct lu_env *env,
2781                                       struct dt_object *dt,
2782                                       const struct lu_buf *buf,
2783                                       const char *name, int fl,
2784                                       struct thandle *th)
2785 {
2786         LASSERT(dt);
2787         LASSERT(dt->do_ops);
2788         LASSERT(dt->do_ops->do_declare_xattr_set);
2789
2790         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2791                 return cfs_fail_err;
2792
2793         return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2794 }
2795
2796 static inline int dt_xattr_set(const struct lu_env *env,
2797                                struct dt_object *dt, const struct lu_buf *buf,
2798                                const char *name, int fl, struct thandle *th)
2799 {
2800         LASSERT(dt);
2801         LASSERT(dt->do_ops);
2802         LASSERT(dt->do_ops->do_xattr_set);
2803
2804         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2805                 return cfs_fail_err;
2806
2807         return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2808 }
2809
2810 static inline int dt_declare_xattr_get(const struct lu_env *env,
2811                                        struct dt_object *dt,
2812                                        struct lu_buf *buf,
2813                                        const char *name)
2814 {
2815         LASSERT(dt);
2816         LASSERT(dt->do_ops);
2817         LASSERT(dt->do_ops->do_declare_xattr_get);
2818
2819         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2820                 return cfs_fail_err;
2821
2822         return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2823 }
2824
2825 static inline int dt_xattr_get(const struct lu_env *env,
2826                                struct dt_object *dt, struct lu_buf *buf,
2827                                const char *name)
2828 {
2829         LASSERT(dt);
2830         LASSERT(dt->do_ops);
2831         LASSERT(dt->do_ops->do_xattr_get);
2832
2833         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2834                 return cfs_fail_err;
2835
2836         return dt->do_ops->do_xattr_get(env, dt, buf, name);
2837 }
2838
2839 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2840                                 const struct lu_buf *buf)
2841 {
2842         LASSERT(dt);
2843         LASSERT(dt->do_ops);
2844         LASSERT(dt->do_ops->do_xattr_list);
2845
2846         if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2847                 return cfs_fail_err;
2848
2849         return dt->do_ops->do_xattr_list(env, dt, buf);
2850 }
2851
2852 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2853 {
2854         LASSERT(dt);
2855         LASSERT(dt->do_ops);
2856         LASSERT(dt->do_ops->do_invalidate);
2857
2858         return dt->do_ops->do_invalidate(env, dt);
2859 }
2860
2861 static inline int dt_declare_delete(const struct lu_env *env,
2862                                     struct dt_object *dt,
2863                                     const struct dt_key *key,
2864                                     struct thandle *th)
2865 {
2866         LASSERT(dt);
2867         LASSERT(dt->do_index_ops);
2868         LASSERT(dt->do_index_ops->dio_declare_delete);
2869
2870         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2871                 return cfs_fail_err;
2872
2873         return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2874 }
2875
2876 static inline int dt_delete(const struct lu_env *env,
2877                             struct dt_object *dt,
2878                             const struct dt_key *key,
2879                             struct thandle *th)
2880 {
2881         LASSERT(dt);
2882         LASSERT(dt->do_index_ops);
2883         LASSERT(dt->do_index_ops->dio_delete);
2884
2885         if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2886                 return cfs_fail_err;
2887
2888         return dt->do_index_ops->dio_delete(env, dt, key, th);
2889 }
2890
2891 static inline int dt_commit_async(const struct lu_env *env,
2892                                   struct dt_device *dev)
2893 {
2894         LASSERT(dev);
2895         LASSERT(dev->dd_ops);
2896         LASSERT(dev->dd_ops->dt_commit_async);
2897         return dev->dd_ops->dt_commit_async(env, dev);
2898 }
2899
2900 static inline int dt_lookup(const struct lu_env *env,
2901                             struct dt_object *dt,
2902                             struct dt_rec *rec,
2903                             const struct dt_key *key)
2904 {
2905         int ret;
2906
2907         LASSERT(dt);
2908         LASSERT(dt->do_index_ops);
2909         LASSERT(dt->do_index_ops->dio_lookup);
2910
2911         if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2912                 return cfs_fail_err;
2913
2914         ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2915         if (ret > 0)
2916                 ret = 0;
2917         else if (ret == 0)
2918                 ret = -ENOENT;
2919         return ret;
2920 }
2921
2922 static inline int dt_declare_layout_change(const struct lu_env *env,
2923                                            struct dt_object *o,
2924                                            struct md_layout_change *mlc,
2925                                            struct thandle *th)
2926 {
2927         LASSERT(o);
2928         LASSERT(o->do_ops);
2929         LASSERT(o->do_ops->do_declare_layout_change);
2930         return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2931 }
2932
2933 static inline int dt_layout_change(const struct lu_env *env,
2934                                    struct dt_object *o,
2935                                    struct md_layout_change *mlc,
2936                                    struct thandle *th)
2937 {
2938         LASSERT(o);
2939         LASSERT(o->do_ops);
2940         LASSERT(o->do_ops->do_layout_change);
2941         return o->do_ops->do_layout_change(env, o, mlc, th);
2942 }
2943
2944 struct dt_find_hint {
2945         struct lu_fid        *dfh_fid;
2946         struct dt_device     *dfh_dt;
2947         struct dt_object     *dfh_o;
2948 };
2949
2950 struct dt_insert_rec {
2951         union {
2952                 const struct lu_fid     *rec_fid;
2953                 void                    *rec_data;
2954         };
2955         union {
2956                 struct {
2957                         __u32            rec_type;
2958                         __u32            rec_padding;
2959                 };
2960                 __u64                    rec_misc;
2961         };
2962 };
2963
2964 struct dt_thread_info {
2965         char                     dti_buf[DT_MAX_PATH];
2966         struct dt_find_hint      dti_dfh;
2967         struct lu_attr           dti_attr;
2968         struct lu_fid            dti_fid;
2969         struct dt_object_format  dti_dof;
2970         struct lustre_mdt_attrs  dti_lma;
2971         struct lu_buf            dti_lb;
2972         struct lu_object_conf    dti_conf;
2973         loff_t                   dti_off;
2974         struct dt_insert_rec     dti_dt_rec;
2975 };
2976
2977 extern struct lu_context_key dt_key;
2978
2979 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2980 {
2981         struct dt_thread_info *dti;
2982
2983         dti = lu_context_key_get(&env->le_ctx, &dt_key);
2984         LASSERT(dti);
2985         return dti;
2986 }
2987
2988 int dt_global_init(void);
2989 void dt_global_fini(void);
2990 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2991                      const char *name, struct ldebugfs_vars *list);
2992 int dt_tunables_fini(struct dt_device *dt);
2993
2994 # ifdef CONFIG_PROC_FS
2995 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2996 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2997 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2998 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2999 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
3000 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
3001 # endif /* CONFIG_PROC_FS */
3002
3003 #endif /* __LUSTRE_DT_OBJECT_H */