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