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