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