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