4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #ifndef __LUSTRE_DT_OBJECT_H
34 #define __LUSTRE_DT_OBJECT_H
37 * Sub-class of lu_object with methods common for "data" objects in OST stack.
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
44 * Examples: osd (lustre/osd) is an implementation of dt interface.
48 #include <obd_support.h>
50 * super-class definitions.
52 #include <lu_object.h>
54 #include <libcfs/libcfs.h>
57 struct proc_dir_entry;
63 struct dt_index_features;
66 struct ldlm_enqueue_info;
69 MNTOPT_USERXATTR = 0x00000001,
70 MNTOPT_ACL = 0x00000002,
73 struct dt_device_param {
74 unsigned ddp_max_name_len;
75 unsigned ddp_max_nlink;
76 unsigned ddp_symlink_max;
78 unsigned ddp_max_ea_size;
79 unsigned ddp_mount_type;
80 unsigned long long ddp_maxbytes;
81 /* per-inode space consumption */
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
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;
94 * Per-transaction commit callback function
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);
100 * Special per-transaction callback for cases when just commit callback
101 * is needed and per-device callback are not convenient to use
103 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
104 #define MAX_COMMIT_CB_STR_LEN 32
106 #define DCB_TRANS_STOP 0x1
107 struct dt_txn_commit_cb {
108 struct list_head dcb_linkage;
113 char dcb_name[MAX_COMMIT_CB_STR_LEN];
117 * Operations on dt device.
119 struct dt_device_operations {
121 * Return device-wide statistics.
123 * Return device-wide stats including block size, total and
124 * free blocks, total and free objects, etc. See struct obd_statfs
127 * \param[in] env execution environment for this thread
128 * \param[in] dev dt device
129 * \param[out] osfs stats information
131 * \retval 0 on success
132 * \retval negative negated errno on error
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);
140 * Create transaction.
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.
149 * \param[in] env execution environment for this thread
150 * \param[in] dev dt device
152 * \retval pointer to handle if creation succeeds
153 * \retval ERR_PTR(errno) if creation fails
155 struct thandle *(*dt_trans_create)(const struct lu_env *env,
156 struct dt_device *dev);
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.
169 * \param[in] env execution environment for this thread
170 * \param[in] dev dt device
171 * \param[in] th transaction handle
173 * \retval 0 on success
174 * \retval negative negated errno on error
176 int (*dt_trans_start)(const struct lu_env *env,
177 struct dt_device *dev,
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).
189 * \param[in] env execution environment for this thread
190 * \param[in] dev dt device
191 * \param[in] th transaction handle
193 * \retval 0 on success
194 * \retval negative negated errno on error
196 int (*dt_trans_stop)(const struct lu_env *env,
197 struct dt_device *dev,
201 * Add commit callback to the transaction.
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.
214 * \param[in] th transaction handle
215 * \param[in] dcb commit callback description
217 * \retval 0 on success
218 * \retval negative negated errno on error
220 int (*dt_trans_cb_add)(struct thandle *th,
221 struct dt_txn_commit_cb *dcb);
224 * Return FID of root index object.
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.
231 * \param[in] env execution environment for this thread
232 * \param[in] dev dt device
233 * \param[out] fid FID of the root object
235 * \retval 0 on success
236 * \retval negative negated errno on error
238 int (*dt_root_get)(const struct lu_env *env,
239 struct dt_device *dev,
243 * Return device configuration data.
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.
249 * \param[in] env execution environment for this thread
250 * \param[in] dev dt device
251 * \param[out] param configuration parameters
253 void (*dt_conf_get)(const struct lu_env *env,
254 const struct dt_device *dev,
255 struct dt_device_param *param);
258 * Return device's super block.
260 * \param[in] dev dt device
262 struct super_block *(*dt_mnt_sb_get)(const struct dt_device *dev);
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
273 * \param[in] env execution environment for this thread
274 * \param[in] dev dt device
276 * \retval 0 on success
277 * \retval negative negated errno on error
279 int (*dt_sync)(const struct lu_env *env,
280 struct dt_device *dev);
283 * Make device read-only.
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.
290 * \param[in] env execution environment for this thread
291 * \param[in] dev dt device
293 * \retval 0 on success
294 * \retval negative negated errno on error
296 int (*dt_ro)(const struct lu_env *env,
297 struct dt_device *dev);
300 * Start transaction commit asynchronously.
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.
309 * \param[in] env execution environment for this thread
310 * \param[in] dev dt device
312 * \retval 0 on success
313 * \retval negative negated errno on error
315 int (*dt_commit_async)(const struct lu_env *env,
316 struct dt_device *dev);
319 struct dt_index_features {
320 /** required feature flags from enum dt_index_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 */
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,
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
347 DT_IND_RANGE = 1 << 4,
350 /* for dt_read_lock() and dt_write_lock() object lock rule */
351 enum dt_object_role {
361 * Features, required from index to support file system directories (mapping
364 extern const struct dt_index_features dt_directory_features;
365 extern const struct dt_index_features dt_otable_features;
366 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
367 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
368 extern const struct dt_index_features dt_lfsck_namespace_features;
370 /* index features supported by the accounting objects */
371 extern const struct dt_index_features dt_acct_features;
373 /* index features supported by the quota global indexes */
374 extern const struct dt_index_features dt_quota_glb_features;
376 /* index features supported by the quota slave indexes */
377 extern const struct dt_index_features dt_quota_slv_features;
379 /* index features supported by the nodemap index */
380 extern const struct dt_index_features dt_nodemap_features;
383 * This is a general purpose dt allocation hint.
384 * It now contains the parent object.
385 * It can contain any allocation hint in the future.
387 struct dt_allocation_hint {
388 struct dt_object *dah_parent;
389 const void *dah_eadata;
392 int dah_append_stripes;
393 char *dah_append_pool;
397 * object type specifier.
400 enum dt_format_type {
405 /** for special index */
407 /** for symbolic link */
412 * object format specifier.
414 struct dt_object_format {
415 /** type for dt object */
416 enum dt_format_type dof_type;
426 * special index need feature as parameter to create
430 const struct dt_index_features *di_feat;
435 enum dt_format_type dt_mode_to_dft(__u32 mode);
437 typedef __u64 dt_obj_version_t;
439 union ldlm_policy_data;
441 struct md_layout_change;
444 * A dt_object provides common operations to create and destroy
445 * objects and to manage regular and extended attributes.
447 struct dt_object_operations {
449 * Get read lock on object.
451 * Read lock is compatible with other read locks, so it's shared.
452 * Read lock is not compatible with write lock which is exclusive.
453 * The lock is blocking and can't be used from an interrupt context.
455 * \param[in] env execution environment for this thread
456 * \param[in] dt object to lock for reading
457 * \param[in] role a hint to debug locks (see kernel's mutexes)
459 void (*do_read_lock)(const struct lu_env *env,
460 struct dt_object *dt,
464 * Get write lock on object.
466 * Write lock is exclusive and cannot be shared. The lock is blocking
467 * and can't be used from an interrupt context.
469 * \param[in] env execution environment for this thread
470 * \param[in] dt object to lock for writing
471 * \param[in] role a hint to debug locks (see kernel's mutexes)
474 void (*do_write_lock)(const struct lu_env *env,
475 struct dt_object *dt,
481 * \param[in] env execution environment for this thread
482 * \param[in] dt object
484 void (*do_read_unlock)(const struct lu_env *env,
485 struct dt_object *dt);
488 * Release write lock.
490 * \param[in] env execution environment for this thread
491 * \param[in] dt object
493 void (*do_write_unlock)(const struct lu_env *env,
494 struct dt_object *dt);
497 * Check whether write lock is held.
499 * The caller can learn whether write lock is held on the object
501 * \param[in] env execution environment for this thread
502 * \param[in] dt object
504 * \retval 0 no write lock
505 * \retval 1 write lock is held
507 int (*do_write_locked)(const struct lu_env *env,
508 struct dt_object *dt);
511 * Declare intention to request reqular attributes.
513 * Notity the underlying filesystem that the caller may request regular
514 * attributes with ->do_attr_get() soon. This allows OSD to implement
515 * prefetching logic in an object-oriented manner. The implementation
516 * can be noop. This method should avoid expensive delays such as
517 * waiting on disk I/O, otherwise the goal of enabling a performance
518 * optimization would be defeated.
520 * \param[in] env execution environment for this thread
521 * \param[in] dt object
523 * \retval 0 on success
524 * \retval negative negated errno on error
526 int (*do_declare_attr_get)(const struct lu_env *env,
527 struct dt_object *dt);
530 * Return regular attributes.
532 * The object must exist. Currently all the attributes should be
533 * returned, but in the future this can be improved so that only
534 * a selected set is returned. This can improve performance as in
535 * some cases attributes are stored in different places and
536 * getting them all can be an iterative and expensive process.
538 * \param[in] env execution environment for this thread
539 * \param[in] dt object
540 * \param[out] attr attributes to fill
542 * \retval 0 on success
543 * \retval negative negated errno on error
545 int (*do_attr_get)(const struct lu_env *env,
546 struct dt_object *dt,
547 struct lu_attr *attr);
550 * Declare intention to change regular object's attributes.
552 * Notify the underlying filesystem that the regular attributes may
553 * change in this transaction. This enables the layer below to prepare
554 * resources (e.g. journal credits in ext4). This method should be
555 * called between creating the transaction and starting it. Note that
556 * the la_valid field of \a attr specifies which attributes will change.
557 * The object need not exist.
559 * \param[in] env execution environment for this thread
560 * \param[in] dt object
561 * \param[in] attr attributes to change specified in attr.la_valid
562 * \param[in] th transaction handle
564 * \retval 0 on success
565 * \retval negative negated errno on error
567 int (*do_declare_attr_set)(const struct lu_env *env,
568 struct dt_object *dt,
569 const struct lu_attr *attr,
573 * Change regular attributes.
575 * Change regular attributes in the given transaction. Note only
576 * attributes flagged by attr.la_valid change. The object must
577 * exist. If the layer implementing this method is responsible for
578 * quota, then the method should maintain object accounting for the
579 * given credentials when la_uid/la_gid changes.
581 * \param[in] env execution environment for this thread
582 * \param[in] dt object
583 * \param[in] attr new attributes to apply
584 * \param[in] th transaction handle
586 * \retval 0 on success
587 * \retval negative negated errno on error
589 int (*do_attr_set)(const struct lu_env *env,
590 struct dt_object *dt,
591 const struct lu_attr *attr,
595 * Declare intention to request extented attribute.
597 * Notify the underlying filesystem that the caller may request extended
598 * attribute with ->do_xattr_get() soon. This allows OSD to implement
599 * prefetching logic in an object-oriented manner. The implementation
600 * can be noop. This method should avoid expensive delays such as
601 * waiting on disk I/O, otherwise the goal of enabling a performance
602 * optimization would be defeated.
604 * \param[in] env execution environment for this thread
605 * \param[in] dt object
606 * \param[in] buf unused, may be removed in the future
607 * \param[in] name name of the extended attribute
609 * \retval 0 on success
610 * \retval negative negated errno on error
612 int (*do_declare_xattr_get)(const struct lu_env *env,
613 struct dt_object *dt,
618 * Return a value of an extended attribute.
620 * The object must exist. If the buffer is NULL, then the method
621 * must return the size of the value.
623 * \param[in] env execution environment for this thread
624 * \param[in] dt object
625 * \param[out] buf buffer in which to store the value
626 * \param[in] name name of the extended attribute
628 * \retval 0 on success
629 * \retval -ERANGE if \a buf is too small
630 * \retval negative negated errno on error
631 * \retval positive value's size if \a buf is NULL or has zero size
633 int (*do_xattr_get)(const struct lu_env *env,
634 struct dt_object *dt,
639 * Declare intention to change an extended attribute.
641 * Notify the underlying filesystem that the extended attribute may
642 * change in this transaction. This enables the layer below to prepare
643 * resources (e.g. journal credits in ext4). This method should be
644 * called between creating the transaction and starting it. The object
647 * \param[in] env execution environment for this thread
648 * \param[in] dt object
649 * \param[in] buf buffer storing new value of the attribute
650 * \param[in] name name of the attribute
651 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
652 * LU_XATTR_REPLACE - fail if EA doesn't exist
653 * \param[in] th transaction handle
655 * \retval 0 on success
656 * \retval negative negated errno on error
658 int (*do_declare_xattr_set)(const struct lu_env *env,
659 struct dt_object *dt,
660 const struct lu_buf *buf,
666 * Set an extended attribute.
668 * Change or replace the specified extended attribute (EA).
669 * The flags passed in \a fl dictate whether the EA is to be
670 * created or replaced, as follows.
671 * LU_XATTR_CREATE - fail if EA exists
672 * LU_XATTR_REPLACE - fail if EA doesn't exist
673 * The object must exist.
675 * \param[in] env execution environment for this thread
676 * \param[in] dt object
677 * \param[in] buf buffer storing new value of the attribute
678 * \param[in] name name of the attribute
679 * \param[in] fl flags indicating EA creation or replacement
680 * \param[in] th transaction handle
682 * \retval 0 on success
683 * \retval negative negated errno on error
685 int (*do_xattr_set)(const struct lu_env *env,
686 struct dt_object *dt,
687 const struct lu_buf *buf,
693 * Declare intention to delete an extended attribute.
695 * Notify the underlying filesystem that the extended attribute may
696 * be deleted in this transaction. This enables the layer below to
697 * prepare resources (e.g. journal credits in ext4). This method
698 * should be called between creating the transaction and starting it.
699 * The object need not exist.
701 * \param[in] env execution environment for this thread
702 * \param[in] dt object
703 * \param[in] name name of the attribute
704 * \param[in] th transaction handle
706 * \retval 0 on success
707 * \retval negative negated errno on error
709 int (*do_declare_xattr_del)(const struct lu_env *env,
710 struct dt_object *dt,
715 * Delete an extended attribute.
717 * This method deletes the specified extended attribute. The object
720 * \param[in] env execution environment for this thread
721 * \param[in] dt object
722 * \param[in] name name of the attribute
723 * \param[in] th transaction handle
725 * \retval 0 on success
726 * \retval negative negated errno on error
728 int (*do_xattr_del)(const struct lu_env *env,
729 struct dt_object *dt,
734 * Return a list of the extended attributes.
736 * Fills the passed buffer with a list of the extended attributes
737 * found in the object. The names are separated with '\0'.
738 * The object must exist.
740 * \param[in] env execution environment for this thread
741 * \param[in] dt object
742 * \param[out] buf buffer to put the list in
744 * \retval positive bytes used/required in the buffer
745 * \retval negative negated errno on error
747 int (*do_xattr_list)(const struct lu_env *env,
748 struct dt_object *dt,
749 const struct lu_buf *buf);
752 * Prepare allocation hint for a new object.
754 * This method is used by the caller to inform OSD of the parent-child
755 * relationship between two objects and enable efficient object
756 * allocation. Filled allocation hint will be passed to ->do_create()
759 * \param[in] env execution environment for this thread
760 * \param[out] ah allocation hint
761 * \param[in] parent parent object (can be NULL)
762 * \param[in] child child object
763 * \param[in] _mode type of the child object
765 void (*do_ah_init)(const struct lu_env *env,
766 struct dt_allocation_hint *ah,
767 struct dt_object *parent,
768 struct dt_object *child,
772 * Declare intention to create a new object.
774 * Notify the underlying filesystem that the object may be created
775 * in this transaction. This enables the layer below to prepare
776 * resources (e.g. journal credits in ext4). This method should be
777 * called between creating the transaction and starting it.
779 * If the layer implementing this method is responsible for quota,
780 * then the method should reserve an object for the given credentials
781 * and return an error if quota is over. If object creation later
782 * fails for some reason, then the reservation should be released
783 * properly (usually in ->dt_trans_stop()).
785 * \param[in] env execution environment for this thread
786 * \param[in] dt object
787 * \param[in] attr attributes of the new object
788 * \param[in] hint allocation hint
789 * \param[in] dof object format
790 * \param[in] th transaction handle
792 * \retval 0 on success
793 * \retval negative negated errno on error
795 int (*do_declare_create)(const struct lu_env *env,
796 struct dt_object *dt,
797 struct lu_attr *attr,
798 struct dt_allocation_hint *hint,
799 struct dt_object_format *dof,
805 * The method creates the object passed with the specified attributes
806 * and object format. Object allocation procedure can use information
807 * stored in the allocation hint. Different object formats are supported
808 * (see enum dt_format_type and struct dt_object_format) depending on
809 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
810 * in the LU-object header attributes.
812 * If the layer implementing this method is responsible for quota,
813 * then the method should maintain object accounting for the given
816 * \param[in] env execution environment for this thread
817 * \param[in] dt object
818 * \param[in] attr attributes of the new object
819 * \param[in] hint allocation hint
820 * \param[in] dof object format
821 * \param[in] th transaction handle
823 * \retval 0 on success
824 * \retval negative negated errno on error
826 int (*do_create)(const struct lu_env *env,
827 struct dt_object *dt,
828 struct lu_attr *attr,
829 struct dt_allocation_hint *hint,
830 struct dt_object_format *dof,
834 * Declare intention to destroy an object.
836 * Notify the underlying filesystem that the object may be destroyed
837 * in this transaction. This enables the layer below to prepare
838 * resources (e.g. journal credits in ext4). This method should be
839 * called between creating the transaction and starting it. The object
842 * \param[in] env execution environment for this thread
843 * \param[in] dt object
844 * \param[in] th transaction handle
846 * \retval 0 on success
847 * \retval negative negated errno on error
849 int (*do_declare_destroy)(const struct lu_env *env,
850 struct dt_object *dt,
856 * This method destroys the object and all the resources associated
857 * with the object (data, key/value pairs, extended attributes, etc).
858 * The object must exist. If destroy is successful, then flag
859 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
860 * instance of in-core object. Any subsequent access to the same FID
861 * should get another instance with no LOHA_EXIST flag set.
863 * If the layer implementing this method is responsible for quota,
864 * then the method should maintain object accounting for the given
867 * \param[in] env execution environment for this thread
868 * \param[in] dt object
869 * \param[in] th transaction handle
871 * \retval 0 on success
872 * \retval negative negated errno on error
874 int (*do_destroy)(const struct lu_env *env,
875 struct dt_object *dt,
879 * Try object as an index.
881 * Announce that this object is going to be used as an index. This
882 * operation checks that object supports indexing operations and
883 * installs appropriate dt_index_operations vector on success.
884 * Also probes for features. Operation is successful if all required
885 * features are supported. It's not possible to access the object
886 * with index methods before ->do_index_try() returns success.
888 * \param[in] env execution environment for this thread
889 * \param[in] dt object
890 * \param[in] feat index features
892 * \retval 0 on success
893 * \retval negative negated errno on error
895 int (*do_index_try)(const struct lu_env *env,
896 struct dt_object *dt,
897 const struct dt_index_features *feat);
900 * Declare intention to increment nlink count.
902 * Notify the underlying filesystem that the nlink regular attribute
903 * be changed in this transaction. This enables the layer below to
904 * prepare resources (e.g. journal credits in ext4). This method
905 * should be called between creating the transaction and starting it.
906 * The object need not exist.
908 * \param[in] env execution environment for this thread
909 * \param[in] dt object
910 * \param[in] th transaction handle
912 * \retval 0 on success
913 * \retval negative negated errno on error
915 int (*do_declare_ref_add)(const struct lu_env *env,
916 struct dt_object *dt,
922 * Increment nlink (from the regular attributes set) in the given
923 * transaction. Note the absolute limit for nlink should be learnt
924 * from struct dt_device_param::ddp_max_nlink. The object must exist.
926 * \param[in] env execution environment for this thread
927 * \param[in] dt object
928 * \param[in] th transaction handle
930 * \retval 0 on success
931 * \retval negative negated errno on error
933 int (*do_ref_add)(const struct lu_env *env,
934 struct dt_object *dt, struct thandle *th);
937 * Declare intention to decrement nlink count.
939 * Notify the underlying filesystem that the nlink regular attribute
940 * be changed in this transaction. This enables the layer below to
941 * prepare resources (e.g. journal credits in ext4). This method
942 * should be called between creating the transaction and starting it.
943 * The object need not exist.
945 * \param[in] env execution environment for this thread
946 * \param[in] dt object
947 * \param[in] th transaction handle
949 * \retval 0 on success
950 * \retval negative negated errno on error
952 int (*do_declare_ref_del)(const struct lu_env *env,
953 struct dt_object *dt,
959 * Decrement nlink (from the regular attributes set) in the given
960 * transaction. The object must exist.
962 * \param[in] env execution environment for this thread
963 * \param[in] dt object
964 * \param[in] th transaction handle
966 * \retval 0 on success
967 * \retval negative negated errno on error
969 int (*do_ref_del)(const struct lu_env *env,
970 struct dt_object *dt,
976 * The method is called to sync specified range of the object to a
977 * persistent storage. The control is returned once the operation is
978 * complete. The difference from ->do_sync() is that the object can
979 * be in-sync with the persistent storage (nothing to flush), then
980 * the method returns quickly with no I/O overhead. So, this method
981 * should be preferred over ->do_sync() where possible. Also note that
982 * if the object isn't clean, then some disk filesystems will call
983 * ->do_sync() to maintain overall consistency, in which case it's
984 * still very expensive.
986 * \param[in] env execution environment for this thread
987 * \param[in] dt object
988 * \param[in] start start of the range to sync
989 * \param[in] end end of the range to sync
991 * \retval 0 on success
992 * \retval negative negated errno on error
994 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
995 __u64 start, __u64 end);
1000 * Lock object(s) using Distributed Lock Manager (LDLM).
1002 * Get LDLM locks for the object. Currently used to lock "remote"
1003 * objects in DNE configuration - a service running on MDTx needs
1004 * to lock an object on MDTy.
1006 * \param[in] env execution environment for this thread
1007 * \param[in] dt object
1008 * \param[out] lh lock handle, sometimes used, sometimes not
1009 * \param[in] einfo ldlm callbacks, locking type and mode
1010 * \param[out] einfo private data to be passed to unlock later
1011 * \param[in] policy inodebits data
1013 * \retval 0 on success
1014 * \retval negative negated errno on error
1016 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1017 struct lustre_handle *lh,
1018 struct ldlm_enqueue_info *einfo,
1019 union ldlm_policy_data *policy);
1024 * Release LDLM lock(s) granted with ->do_object_lock().
1026 * \param[in] env execution environment for this thread
1027 * \param[in] dt object
1028 * \param[in] einfo lock handles, from ->do_object_lock()
1029 * \param[in] policy inodebits data
1031 * \retval 0 on success
1032 * \retval negative negated errno on error
1034 int (*do_object_unlock)(const struct lu_env *env,
1035 struct dt_object *dt,
1036 struct ldlm_enqueue_info *einfo,
1037 union ldlm_policy_data *policy);
1040 * Invalidate attribute cache.
1042 * This method invalidate attribute cache of the object, which is on OSP
1045 * \param[in] env execution envionment for this thread
1046 * \param[in] dt object
1048 * \retval 0 on success
1049 * \retval negative negated errno on error
1051 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1054 * Declare intention to instaintiate extended layout component.
1056 * \param[in] env execution environment
1057 * \param[in] dt DT object
1058 * \param[in] layout data structure to describe the changes to
1059 * the DT object's layout
1060 * \param[in] buf buffer containing client's lovea or empty
1063 * \retval -ne error code
1065 int (*do_declare_layout_change)(const struct lu_env *env,
1066 struct dt_object *dt,
1067 struct md_layout_change *mlc,
1068 struct thandle *th);
1071 * Client is trying to write to un-instantiated layout component.
1073 * \param[in] env execution environment
1074 * \param[in] dt DT object
1075 * \param[in] layout data structure to describe the changes to
1076 * the DT object's layout
1077 * \param[in] buf buffer containing client's lovea or empty
1080 * \retval -ne error code
1082 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1083 struct md_layout_change *mlc,
1084 struct thandle *th);
1088 DT_BUFS_TYPE_READ = 0x0000,
1089 DT_BUFS_TYPE_WRITE = 0x0001,
1090 DT_BUFS_TYPE_READAHEAD = 0x0002,
1091 DT_BUFS_TYPE_LOCAL = 0x0004,
1095 * Per-dt-object operations on "file body" - unstructure raw data.
1097 struct dt_body_operations {
1101 * Read unstructured data from an existing regular object.
1102 * Only data before attr.la_size is returned.
1104 * \param[in] env execution environment for this thread
1105 * \param[in] dt object
1106 * \param[out] buf buffer (including size) to copy data in
1107 * \param[in] pos position in the object to start
1108 * \param[out] pos original value of \a pos + bytes returned
1110 * \retval positive bytes read on success
1111 * \retval negative negated errno on error
1113 ssize_t (*dbo_read)(const struct lu_env *env,
1114 struct dt_object *dt,
1119 * Declare intention to write data to object.
1121 * Notify the underlying filesystem that data may be written in
1122 * this transaction. This enables the layer below to prepare resources
1123 * (e.g. journal credits in ext4). This method should be called
1124 * between creating the transaction and starting it. The object need
1125 * not exist. If the layer implementing this method is responsible for
1126 * quota, then the method should reserve space for the given credentials
1127 * and return an error if quota is over. If the write later fails
1128 * for some reason, then the reserve should be released properly
1129 * (usually in ->dt_trans_stop()).
1131 * \param[in] env execution environment for this thread
1132 * \param[in] dt object
1133 * \param[in] buf buffer (including size) to copy data from
1134 * \param[in] pos position in the object to start
1135 * \param[in] th transaction handle
1137 * \retval 0 on success
1138 * \retval negative negated errno on error
1140 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1141 struct dt_object *dt,
1142 const struct lu_buf *buf,
1144 struct thandle *th);
1147 * Write unstructured data to regular existing object.
1149 * The method allocates space and puts data in. Also, the method should
1150 * maintain attr.la_size properly. Partial writes are possible.
1152 * If the layer implementing this method is responsible for quota,
1153 * then the method should maintain space accounting for the given
1156 * \param[in] env execution environment for this thread
1157 * \param[in] dt object
1158 * \param[in] buf buffer (including size) to copy data from
1159 * \param[in] pos position in the object to start
1160 * \param[out] pos \a pos + bytes written
1161 * \param[in] th transaction handle
1163 * \retval positive bytes written on success
1164 * \retval negative negated errno on error
1166 ssize_t (*dbo_write)(const struct lu_env *env,
1167 struct dt_object *dt,
1168 const struct lu_buf *buf,
1170 struct thandle *th);
1173 * Return buffers for data.
1175 * This method is used to access data with no copying. It's so-called
1176 * zero-copy I/O. The method returns the descriptors for the internal
1177 * buffers where data are managed by the disk filesystem. For example,
1178 * pagecache in case of ext4 or ARC with ZFS. Then other components
1179 * (e.g. networking) can transfer data from or to the buffers with no
1180 * additional copying.
1182 * The method should fill an array of struct niobuf_local, where
1183 * each element describes a full or partial page for data at specific
1184 * offset. The caller should use page/lnb_page_offset/len to find data
1185 * at object's offset lnb_file_offset.
1187 * The memory referenced by the descriptors can't change its purpose
1188 * until the complementary ->dbo_bufs_put() is called. The caller should
1189 * specify if the buffers are used to read or modify data so that OSD
1190 * can decide how to initialize the buffers: bring all the data for
1191 * reads or just bring partial buffers for write. Note: the method does
1192 * not check whether output array is large enough.
1194 * \param[in] env execution environment for this thread
1195 * \param[in] dt object
1196 * \param[in] pos position in the object to start
1197 * \param[in] len size of region in bytes
1198 * \param[out] lb array of descriptors to fill
1199 * \param[in] maxlnb max slots in @lnb array
1200 * \param[in] rw 0 if used to read, 1 if used for write
1202 * \retval positive number of descriptors on success
1203 * \retval negative negated errno on error
1205 int (*dbo_bufs_get)(const struct lu_env *env,
1206 struct dt_object *dt,
1209 struct niobuf_local *lb,
1211 enum dt_bufs_type rw);
1214 * Release reference granted by ->dbo_bufs_get().
1216 * Release the reference granted by the previous ->dbo_bufs_get().
1217 * Note the references are counted.
1219 * \param[in] env execution environment for this thread
1220 * \param[in] dt object
1221 * \param[out] lb array of descriptors to fill
1222 * \param[in] nr size of the array
1224 * \retval 0 on success
1225 * \retval negative negated errno on error
1227 int (*dbo_bufs_put)(const struct lu_env *env,
1228 struct dt_object *dt,
1229 struct niobuf_local *lb,
1233 * Prepare buffers for reading.
1235 * The method is called on the given buffers to fill them with data
1236 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1237 * caller should be able to get few buffers for discontiguous regions
1238 * using few calls to ->dbo_bufs_get() and then request them all for
1239 * the preparation with a single call, so that OSD can fire many I/Os
1240 * to run concurrently. It's up to the specific OSD whether to implement
1241 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1242 * prepare data for every requested region individually.
1244 * \param[in] env execution environment for this thread
1245 * \param[in] dt object
1246 * \param[in] lnb array of buffer descriptors
1247 * \param[in] nr size of the array
1249 * \retval 0 on success
1250 * \retval negative negated errno on error
1252 int (*dbo_read_prep)(const struct lu_env *env,
1253 struct dt_object *dt,
1254 struct niobuf_local *lnb,
1258 * Prepare buffers for write.
1260 * This method is called on the given buffers to ensure the partial
1261 * buffers contain correct data. The underlying idea is the same as
1262 * in ->db_read_prep().
1264 * \param[in] env execution environment for this thread
1265 * \param[in] dt object
1266 * \param[in] lb array of buffer descriptors
1267 * \param[in] nr size of the array
1269 * \retval 0 on success
1270 * \retval negative negated errno on error
1272 int (*dbo_write_prep)(const struct lu_env *env,
1273 struct dt_object *dt,
1274 struct niobuf_local *lb,
1278 * Declare intention to write data stored in the buffers.
1280 * Notify the underlying filesystem that data may be written in
1281 * this transaction. This enables the layer below to prepare resources
1282 * (e.g. journal credits in ext4). This method should be called
1283 * between creating the transaction and starting it.
1285 * If the layer implementing this method is responsible for quota,
1286 * then the method should be reserving a space for the given
1287 * credentials and return an error if quota is exceeded. If the write
1288 * later fails for some reason, then the reserve should be released
1289 * properly (usually in ->dt_trans_stop()).
1291 * \param[in] env execution environment for this thread
1292 * \param[in] dt object
1293 * \param[in] lb array of descriptors
1294 * \param[in] nr size of the array
1295 * \param[in] th transaction handle
1297 * \retval 0 on success
1298 * \retval negative negated errno on error
1300 int (*dbo_declare_write_commit)(const struct lu_env *env,
1301 struct dt_object *dt,
1302 struct niobuf_local *lb,
1304 struct thandle *th);
1307 * Write to existing object.
1309 * This method is used to write data to a persistent storage using
1310 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1311 * data into the buffers using own mechanisms (e.g. direct transfer
1312 * from a NIC). The method should maintain attr.la_size. Also,
1313 * attr.la_blocks should be maintained but this can be done in lazy
1314 * manner, when actual allocation happens.
1316 * If the layer implementing this method is responsible for quota,
1317 * then the method should maintain space accounting for the given
1320 * \param[in] env execution environment for this thread
1321 * \param[in] dt object
1322 * \param[in] lb array of descriptors for the buffers
1323 * \param[in] nr size of the array
1324 * \param[in] th transaction handle
1326 * \retval 0 on success
1327 * \retval negative negated errno on error
1329 int (*dbo_write_commit)(const struct lu_env *env,
1330 struct dt_object *dt,
1331 struct niobuf_local *lb,
1333 struct thandle *th);
1336 * Return logical to physical block mapping for a given extent
1338 * \param[in] env execution environment for this thread
1339 * \param[in] dt object
1340 * \param[in] fm describe the region to map and the output buffer
1341 * see the details in include/linux/fiemap.h
1343 * \retval 0 on success
1344 * \retval negative negated errno on error
1346 int (*dbo_fiemap_get)(const struct lu_env *env,
1347 struct dt_object *dt,
1351 * Declare intention to deallocate space from an object.
1353 * Notify the underlying filesystem that space may be deallocated in
1354 * this transactions. This enables the layer below to prepare resources
1355 * (e.g. journal credits in ext4). This method should be called between
1356 * creating the transaction and starting it. The object need not exist.
1358 * \param[in] env execution environment for this thread
1359 * \param[in] dt object
1360 * \param[in] start the start of the region to deallocate
1361 * \param[in] end the end of the region to deallocate
1362 * \param[in] th transaction handle
1364 * \retval 0 on success
1365 * \retval negative negated errno on error
1367 int (*dbo_declare_punch)(const struct lu_env *env,
1368 struct dt_object *dt,
1371 struct thandle *th);
1374 * Deallocate specified region in an object.
1376 * This method is used to deallocate (release) space possibly consumed
1377 * by the given region of the object. If the layer implementing this
1378 * method is responsible for quota, then the method should maintain
1379 * space accounting for the given credentials.
1381 * \param[in] env execution environment for this thread
1382 * \param[in] dt object
1383 * \param[in] start the start of the region to deallocate
1384 * \param[in] end the end of the region to deallocate
1385 * \param[in] th transaction handle
1387 * \retval 0 on success
1388 * \retval negative negated errno on error
1390 int (*dbo_punch)(const struct lu_env *env,
1391 struct dt_object *dt,
1394 struct thandle *th);
1396 * Give advices on specified region in an object.
1398 * This method is used to give advices about access pattern on an
1399 * given region of the object. The disk filesystem understands
1400 * the advices and tunes cache/read-ahead policies.
1402 * \param[in] env execution environment for this thread
1403 * \param[in] dt object
1404 * \param[in] start the start of the region affected
1405 * \param[in] end the end of the region affected
1406 * \param[in] advice advice type
1408 * \retval 0 on success
1409 * \retval negative negated errno on error
1411 int (*dbo_ladvise)(const struct lu_env *env,
1412 struct dt_object *dt,
1415 enum lu_ladvise_type advice);
1419 * Incomplete type of index record.
1424 * Incomplete type of index key.
1429 * Incomplete type of dt iterator.
1434 * Per-dt-object operations on object as index. Index is a set of key/value
1435 * pairs abstracted from an on-disk representation. An index supports the
1436 * number of operations including lookup by key, insert and delete. Also,
1437 * an index can be iterated to find the pairs one by one, from a beginning
1438 * or specified point.
1440 struct dt_index_operations {
1442 * Lookup in an index by key.
1444 * The method returns a value for the given key. Key/value format
1445 * and size should have been negotiated with ->do_index_try() before.
1446 * Thus it's the caller's responsibility to provide the method with
1447 * proper key and big enough buffer. No external locking is required,
1448 * all the internal consistency should be implemented by the method
1449 * or lower layers. The object should should have been created with
1450 * type DFT_INDEX or DFT_DIR.
1452 * \param[in] env execution environment for this thread
1453 * \param[in] dt object
1454 * \param[out] rec buffer where value will be stored
1455 * \param[in] key key
1457 * \retval 0 on success
1458 * \retval -ENOENT if key isn't found
1459 * \retval negative negated errno on error
1461 int (*dio_lookup)(const struct lu_env *env,
1462 struct dt_object *dt,
1464 const struct dt_key *key);
1467 * Declare intention to insert a key/value into an index.
1469 * Notify the underlying filesystem that new key/value may be inserted
1470 * in this transaction. This enables the layer below to prepare
1471 * resources (e.g. journal credits in ext4). This method should be
1472 * called between creating the transaction and starting it. key/value
1473 * format and size is subject to ->do_index_try().
1475 * \param[in] env execution environment for this thread
1476 * \param[in] dt object
1477 * \param[in] rec buffer storing value
1478 * \param[in] key key
1479 * \param[in] th transaction handle
1481 * \retval 0 on success
1482 * \retval negative negated errno on error
1484 int (*dio_declare_insert)(const struct lu_env *env,
1485 struct dt_object *dt,
1486 const struct dt_rec *rec,
1487 const struct dt_key *key,
1488 struct thandle *th);
1491 * Insert a new key/value pair into an index.
1493 * The method inserts specified key/value pair into the given index
1494 * object. The internal consistency is maintained by the method or
1495 * the functionality below. The format and size of key/value should
1496 * have been negotiated before using ->do_index_try(), no additional
1497 * information can be specified to the method. The keys are unique
1500 * \param[in] env execution environment for this thread
1501 * \param[in] dt object
1502 * \param[in] rec buffer storing value
1503 * \param[in] key key
1504 * \param[in] th transaction handle
1506 * \retval 0 on success
1507 * \retval negative negated errno on error
1509 int (*dio_insert)(const struct lu_env *env,
1510 struct dt_object *dt,
1511 const struct dt_rec *rec,
1512 const struct dt_key *key,
1513 struct thandle *th);
1516 * Declare intention to delete a key/value from an index.
1518 * Notify the underlying filesystem that key/value may be deleted in
1519 * this transaction. This enables the layer below to prepare resources
1520 * (e.g. journal credits in ext4). This method should be called
1521 * between creating the transaction and starting it. Key/value format
1522 * and size is subject to ->do_index_try(). The object need not exist.
1524 * \param[in] env execution environment for this thread
1525 * \param[in] dt object
1526 * \param[in] key key
1527 * \param[in] th transaction handle
1529 * \retval 0 on success
1530 * \retval negative negated errno on error
1532 int (*dio_declare_delete)(const struct lu_env *env,
1533 struct dt_object *dt,
1534 const struct dt_key *key,
1535 struct thandle *th);
1538 * Delete key/value pair from an index.
1540 * The method deletes specified key and corresponding value from the
1541 * given index object. The internal consistency is maintained by the
1542 * method or the functionality below. The format and size of the key
1543 * should have been negotiated before using ->do_index_try(), no
1544 * additional information can be specified to the method.
1546 * \param[in] env execution environment for this thread
1547 * \param[in] dt object
1548 * \param[in] key key
1549 * \param[in] th transaction handle
1551 * \retval 0 on success
1552 * \retval negative negated errno on error
1554 int (*dio_delete)(const struct lu_env *env,
1555 struct dt_object *dt,
1556 const struct dt_key *key,
1557 struct thandle *th);
1560 * Iterator interface.
1562 * Methods to iterate over an existing index, list the keys stored and
1563 * associated values, get key/value size, etc.
1567 * Allocate and initialize new iterator.
1569 * The iterator is a handler to be used in the subsequent
1570 * methods to access index's content. Note the position is
1571 * not defined at this point and should be initialized with
1572 * ->get() or ->load() method.
1574 * \param[in] env execution environment for this thread
1575 * \param[in] dt object
1576 * \param[in] attr ask the iterator to return part of
1577 the records, see LUDA_* for details
1579 * \retval pointer iterator pointer on success
1580 * \retval ERR_PTR(errno) on error
1582 struct dt_it *(*init)(const struct lu_env *env,
1583 struct dt_object *dt,
1589 * Release the specified iterator and all the resources
1590 * associated (e.g. the object, index cache, etc).
1592 * \param[in] env execution environment for this thread
1593 * \param[in] di iterator to release
1595 void (*fini)(const struct lu_env *env,
1599 * Move position of iterator.
1601 * Move the position of the specified iterator to the specified
1604 * \param[in] env execution environment for this thread
1605 * \param[in] di iterator
1606 * \param[in] key key to position to
1608 * \retval 0 if exact key is found
1609 * \retval 1 if at the record with least key
1610 * not larger than the key
1611 * \retval negative negated errno on error
1613 int (*get)(const struct lu_env *env,
1615 const struct dt_key *key);
1620 * Complimentary method for dt_it_ops::get() above. Some
1621 * implementation can increase a reference on the iterator in
1622 * dt_it_ops::get(). So the caller should be able to release
1623 * with dt_it_ops::put().
1625 * \param[in] env execution environment for this thread
1626 * \param[in] di iterator
1628 void (*put)(const struct lu_env *env,
1632 * Move to next record.
1634 * Moves the position of the iterator to a next record
1636 * \param[in] env execution environment for this thread
1637 * \param[in] di iterator
1639 * \retval 1 if no more records
1640 * \retval 0 on success, the next record is found
1641 * \retval negative negated errno on error
1643 int (*next)(const struct lu_env *env,
1649 * Returns a pointer to a buffer containing the key of the
1650 * record at the current position. The pointer is valid and
1651 * retains data until ->get(), ->load() and ->fini() methods
1654 * \param[in] env execution environment for this thread
1655 * \param[in] di iterator
1657 * \retval pointer to key on success
1658 * \retval ERR_PTR(errno) on error
1660 struct dt_key *(*key)(const struct lu_env *env,
1661 const struct dt_it *di);
1666 * Returns size of the key at the current position.
1668 * \param[in] env execution environment for this thread
1669 * \param[in] di iterator
1671 * \retval key's size on success
1672 * \retval negative negated errno on error
1674 int (*key_size)(const struct lu_env *env,
1675 const struct dt_it *di);
1680 * Stores the value of the record at the current position. The
1681 * buffer must be big enough (as negotiated with
1682 * ->do_index_try() or ->rec_size()). The caller can specify
1683 * she is interested only in part of the record, using attr
1684 * argument (see LUDA_* definitions for the details).
1686 * \param[in] env execution environment for this thread
1687 * \param[in] di iterator
1688 * \param[out] rec buffer to store value in
1689 * \param[in] attr specify part of the value to copy
1691 * \retval 0 on success
1692 * \retval negative negated errno on error
1694 int (*rec)(const struct lu_env *env,
1695 const struct dt_it *di,
1700 * Return record size.
1702 * Returns size of the record at the current position. The
1703 * \a attr can be used to specify only the parts of the record
1704 * needed to be returned. (see LUDA_* definitions for the
1707 * \param[in] env execution environment for this thread
1708 * \param[in] di iterator
1709 * \param[in] attr part of the record to return
1711 * \retval record's size on success
1712 * \retval negative negated errno on error
1714 int (*rec_size)(const struct lu_env *env,
1715 const struct dt_it *di,
1719 * Return a cookie (hash).
1721 * Returns the cookie (usually hash) of the key at the current
1722 * position. This allows the caller to resume iteration at this
1723 * position later. The exact value is specific to implementation
1724 * and should not be interpreted by the caller.
1726 * \param[in] env execution environment for this thread
1727 * \param[in] di iterator
1729 * \retval cookie/hash of the key
1731 __u64 (*store)(const struct lu_env *env,
1732 const struct dt_it *di);
1735 * Initialize position using cookie/hash.
1737 * Initializes the current position of the iterator to one
1738 * described by the cookie/hash as returned by ->store()
1741 * \param[in] env execution environment for this thread
1742 * \param[in] di iterator
1743 * \param[in] hash cookie/hash value
1745 * \retval positive if current position points to
1746 * record with least cookie not larger
1748 * \retval 0 if current position matches cookie
1749 * \retval negative negated errno on error
1751 int (*load)(const struct lu_env *env,
1752 const struct dt_it *di,
1758 int (*key_rec)(const struct lu_env *env,
1759 const struct dt_it *di,
1764 enum dt_otable_it_valid {
1765 DOIV_ERROR_HANDLE = 0x0001,
1766 DOIV_DRYRUN = 0x0002,
1769 enum dt_otable_it_flags {
1770 /* Exit when fail. */
1771 DOIF_FAILOUT = 0x0001,
1773 /* Reset iteration position to the device beginning. */
1774 DOIF_RESET = 0x0002,
1776 /* There is up layer component uses the iteration. */
1777 DOIF_OUTUSED = 0x0004,
1779 /* Check only without repairing. */
1780 DOIF_DRYRUN = 0x0008,
1783 /* otable based iteration needs to use the common DT iteration APIs.
1784 * To initialize the iteration, it needs call dio_it::init() firstly.
1785 * Here is how the otable based iteration should prepare arguments to
1786 * call dt_it_ops::init().
1788 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1789 * is composed of two parts:
1790 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1791 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1792 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1795 struct lu_device dd_lu_dev;
1796 const struct dt_device_operations *dd_ops;
1799 * List of dt_txn_callback (see below). This is not protected in any
1800 * way, because callbacks are supposed to be added/deleted only during
1801 * single-threaded start-up shut-down procedures.
1803 struct list_head dd_txn_callbacks;
1804 unsigned int dd_record_fid_accessed:1,
1807 /* sysfs and debugfs handling */
1808 struct dentry *dd_debugfs_entry;
1810 const struct attribute **dd_def_attrs;
1811 struct kobject dd_kobj;
1812 struct kobj_type dd_ktype;
1813 struct completion dd_kobj_unregister;
1816 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1817 void dt_device_fini(struct dt_device *dev);
1819 static inline int lu_device_is_dt(const struct lu_device *d)
1821 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1824 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1826 LASSERT(lu_device_is_dt(l));
1827 return container_of0(l, struct dt_device, dd_lu_dev);
1831 struct lu_object do_lu;
1832 const struct dt_object_operations *do_ops;
1833 const struct dt_body_operations *do_body_ops;
1834 const struct dt_index_operations *do_index_ops;
1838 * In-core representation of per-device local object OID storage
1840 struct local_oid_storage {
1841 /* all initialized llog systems on this node linked by this */
1842 struct list_head los_list;
1844 /* how many handle's reference this los has */
1845 atomic_t los_refcount;
1846 struct dt_device *los_dev;
1847 struct dt_object *los_obj;
1849 /* data used to generate new fids */
1850 struct mutex los_id_lock;
1855 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1857 return &d->dd_lu_dev;
1860 static inline struct dt_object *lu2dt(struct lu_object *l)
1862 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1863 return container_of0(l, struct dt_object, do_lu);
1866 int dt_object_init(struct dt_object *obj,
1867 struct lu_object_header *h, struct lu_device *d);
1869 void dt_object_fini(struct dt_object *obj);
1871 static inline int dt_object_exists(const struct dt_object *dt)
1873 return lu_object_exists(&dt->do_lu);
1876 static inline int dt_object_remote(const struct dt_object *dt)
1878 return lu_object_remote(&dt->do_lu);
1881 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1883 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1884 return container_of0(o, struct dt_object, do_lu);
1887 static inline struct dt_object *dt_object_child(struct dt_object *o)
1889 return container_of0(lu_object_next(&(o)->do_lu),
1890 struct dt_object, do_lu);
1894 * This is the general purpose transaction handle.
1895 * 1. Transaction Life Cycle
1896 * This transaction handle is allocated upon starting a new transaction,
1897 * and deallocated after this transaction is committed.
1898 * 2. Transaction Nesting
1899 * We do _NOT_ support nested transaction. So, every thread should only
1900 * have one active transaction, and a transaction only belongs to one
1901 * thread. Due to this, transaction handle need no reference count.
1902 * 3. Transaction & dt_object locking
1903 * dt_object locks should be taken inside transaction.
1904 * 4. Transaction & RPC
1905 * No RPC request should be issued inside transaction.
1908 /** the dt device on which the transactions are executed */
1909 struct dt_device *th_dev;
1911 /* point to the top thandle, XXX this is a bit hacky right now,
1912 * but normal device trans callback triggered by the bottom
1913 * device (OSP/OSD == sub thandle layer) needs to get the
1914 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1915 * top thandle here for now, will fix it when we have better
1916 * callback mechanism */
1917 struct thandle *th_top;
1919 /** the last operation result in this transaction.
1920 * this value is used in recovery */
1923 /** whether we need sync commit */
1924 unsigned int th_sync:1,
1925 /* local transation, no need to inform other layers */
1927 /* Whether we need wait the transaction to be submitted
1928 * (send to remote target) */
1930 /* complex transaction which will track updates on all targets,
1933 /* whether ignore quota */
1938 * Transaction call-backs.
1940 * These are invoked by osd (or underlying transaction engine) when
1941 * transaction changes state.
1943 * Call-backs are used by upper layers to modify transaction parameters and to
1944 * perform some actions on for each transaction state transition. Typical
1945 * example is mdt registering call-back to write into last-received file
1946 * before each transaction commit.
1948 struct dt_txn_callback {
1949 int (*dtc_txn_start)(const struct lu_env *env,
1950 struct thandle *txn, void *cookie);
1951 int (*dtc_txn_stop)(const struct lu_env *env,
1952 struct thandle *txn, void *cookie);
1955 struct list_head dtc_linkage;
1958 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1959 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1961 int dt_txn_hook_start(const struct lu_env *env,
1962 struct dt_device *dev, struct thandle *txn);
1963 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1965 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1968 * Callback function used for parsing path.
1969 * \see llo_store_resolve
1971 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1975 #define DT_MAX_PATH 1024
1977 int dt_path_parser(const struct lu_env *env,
1978 char *local, dt_entry_func_t entry_func,
1982 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1983 const char *path, struct lu_fid *fid);
1985 struct dt_object *dt_store_open(const struct lu_env *env,
1986 struct dt_device *dt,
1987 const char *dirname,
1988 const char *filename,
1989 struct lu_fid *fid);
1991 struct dt_object *dt_find_or_create(const struct lu_env *env,
1992 struct dt_device *dt,
1993 const struct lu_fid *fid,
1994 struct dt_object_format *dof,
1995 struct lu_attr *attr);
1997 struct dt_object *dt_locate_at(const struct lu_env *env,
1998 struct dt_device *dev,
1999 const struct lu_fid *fid,
2000 struct lu_device *top_dev,
2001 const struct lu_object_conf *conf);
2003 static inline struct dt_object *
2004 dt_locate(const struct lu_env *env, struct dt_device *dev,
2005 const struct lu_fid *fid)
2007 return dt_locate_at(env, dev, fid,
2008 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2011 static inline struct dt_object *
2012 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2014 struct lu_object *lo;
2016 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2017 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2018 return container_of(lo, struct dt_object, do_lu);
2023 static inline void dt_object_put(const struct lu_env *env,
2024 struct dt_object *dto)
2026 lu_object_put(env, &dto->do_lu);
2029 static inline void dt_object_put_nocache(const struct lu_env *env,
2030 struct dt_object *dto)
2032 lu_object_put_nocache(env, &dto->do_lu);
2035 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2036 const struct lu_fid *first_fid,
2037 struct local_oid_storage **los);
2038 void local_oid_storage_fini(const struct lu_env *env,
2039 struct local_oid_storage *los);
2040 int local_object_fid_generate(const struct lu_env *env,
2041 struct local_oid_storage *los,
2042 struct lu_fid *fid);
2043 int local_object_declare_create(const struct lu_env *env,
2044 struct local_oid_storage *los,
2045 struct dt_object *o,
2046 struct lu_attr *attr,
2047 struct dt_object_format *dof,
2048 struct thandle *th);
2049 int local_object_create(const struct lu_env *env,
2050 struct local_oid_storage *los,
2051 struct dt_object *o,
2052 struct lu_attr *attr, struct dt_object_format *dof,
2053 struct thandle *th);
2054 struct dt_object *local_file_find(const struct lu_env *env,
2055 struct local_oid_storage *los,
2056 struct dt_object *parent,
2058 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2059 struct local_oid_storage *los,
2060 struct dt_object *parent,
2061 const char *name, __u32 mode);
2062 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2063 struct dt_device *dt,
2064 const struct lu_fid *fid,
2065 struct dt_object *parent,
2069 local_index_find_or_create(const struct lu_env *env,
2070 struct local_oid_storage *los,
2071 struct dt_object *parent,
2072 const char *name, __u32 mode,
2073 const struct dt_index_features *ft);
2075 local_index_find_or_create_with_fid(const struct lu_env *env,
2076 struct dt_device *dt,
2077 const struct lu_fid *fid,
2078 struct dt_object *parent,
2079 const char *name, __u32 mode,
2080 const struct dt_index_features *ft);
2081 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2082 struct dt_object *parent, const char *name);
2084 static inline int dt_object_lock(const struct lu_env *env,
2085 struct dt_object *o, struct lustre_handle *lh,
2086 struct ldlm_enqueue_info *einfo,
2087 union ldlm_policy_data *policy)
2090 LASSERT(o->do_ops != NULL);
2091 LASSERT(o->do_ops->do_object_lock != NULL);
2092 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2095 static inline int dt_object_unlock(const struct lu_env *env,
2096 struct dt_object *o,
2097 struct ldlm_enqueue_info *einfo,
2098 union ldlm_policy_data *policy)
2101 LASSERT(o->do_ops != NULL);
2102 LASSERT(o->do_ops->do_object_unlock != NULL);
2103 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2106 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2107 const char *name, struct lu_fid *fid);
2109 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2110 __u64 start, __u64 end)
2114 LASSERT(o->do_ops->do_object_sync);
2115 return o->do_ops->do_object_sync(env, o, start, end);
2118 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2119 struct thandle *th);
2120 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2121 dt_obj_version_t version, struct thandle *th);
2122 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2125 int dt_read(const struct lu_env *env, struct dt_object *dt,
2126 struct lu_buf *buf, loff_t *pos);
2127 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2128 struct lu_buf *buf, loff_t *pos);
2129 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2130 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2131 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2132 union lu_page *lp, size_t nob,
2133 const struct dt_it_ops *iops,
2134 struct dt_it *it, __u32 attr, void *arg);
2135 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2136 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2138 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2139 struct idx_info *ii, const struct lu_rdpg *rdpg);
2141 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2142 struct dt_device *d)
2144 LASSERT(d->dd_ops->dt_trans_create);
2145 return d->dd_ops->dt_trans_create(env, d);
2148 static inline int dt_trans_start(const struct lu_env *env,
2149 struct dt_device *d, struct thandle *th)
2151 LASSERT(d->dd_ops->dt_trans_start);
2152 return d->dd_ops->dt_trans_start(env, d, th);
2155 /* for this transaction hooks shouldn't be called */
2156 static inline int dt_trans_start_local(const struct lu_env *env,
2157 struct dt_device *d, struct thandle *th)
2159 LASSERT(d->dd_ops->dt_trans_start);
2161 return d->dd_ops->dt_trans_start(env, d, th);
2164 static inline int dt_trans_stop(const struct lu_env *env,
2165 struct dt_device *d, struct thandle *th)
2167 LASSERT(d->dd_ops->dt_trans_stop);
2168 return d->dd_ops->dt_trans_stop(env, d, th);
2171 static inline int dt_trans_cb_add(struct thandle *th,
2172 struct dt_txn_commit_cb *dcb)
2174 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2175 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2176 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2181 static inline int dt_declare_record_write(const struct lu_env *env,
2182 struct dt_object *dt,
2183 const struct lu_buf *buf,
2189 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2190 LASSERT(th != NULL);
2191 LASSERT(dt->do_body_ops);
2192 LASSERT(dt->do_body_ops->dbo_declare_write);
2193 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2197 static inline int dt_declare_create(const struct lu_env *env,
2198 struct dt_object *dt,
2199 struct lu_attr *attr,
2200 struct dt_allocation_hint *hint,
2201 struct dt_object_format *dof,
2205 LASSERT(dt->do_ops);
2206 LASSERT(dt->do_ops->do_declare_create);
2208 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2209 return cfs_fail_err;
2211 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2214 static inline int dt_create(const struct lu_env *env,
2215 struct dt_object *dt,
2216 struct lu_attr *attr,
2217 struct dt_allocation_hint *hint,
2218 struct dt_object_format *dof,
2222 LASSERT(dt->do_ops);
2223 LASSERT(dt->do_ops->do_create);
2225 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2226 return cfs_fail_err;
2228 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2231 static inline int dt_declare_destroy(const struct lu_env *env,
2232 struct dt_object *dt,
2236 LASSERT(dt->do_ops);
2237 LASSERT(dt->do_ops->do_declare_destroy);
2239 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2240 return cfs_fail_err;
2242 return dt->do_ops->do_declare_destroy(env, dt, th);
2245 static inline int dt_destroy(const struct lu_env *env,
2246 struct dt_object *dt,
2250 LASSERT(dt->do_ops);
2251 LASSERT(dt->do_ops->do_destroy);
2253 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2254 return cfs_fail_err;
2256 return dt->do_ops->do_destroy(env, dt, th);
2259 static inline void dt_read_lock(const struct lu_env *env,
2260 struct dt_object *dt,
2264 LASSERT(dt->do_ops);
2265 LASSERT(dt->do_ops->do_read_lock);
2266 dt->do_ops->do_read_lock(env, dt, role);
2269 static inline void dt_write_lock(const struct lu_env *env,
2270 struct dt_object *dt,
2274 LASSERT(dt->do_ops);
2275 LASSERT(dt->do_ops->do_write_lock);
2276 dt->do_ops->do_write_lock(env, dt, role);
2279 static inline void dt_read_unlock(const struct lu_env *env,
2280 struct dt_object *dt)
2283 LASSERT(dt->do_ops);
2284 LASSERT(dt->do_ops->do_read_unlock);
2285 dt->do_ops->do_read_unlock(env, dt);
2288 static inline void dt_write_unlock(const struct lu_env *env,
2289 struct dt_object *dt)
2292 LASSERT(dt->do_ops);
2293 LASSERT(dt->do_ops->do_write_unlock);
2294 dt->do_ops->do_write_unlock(env, dt);
2297 static inline int dt_write_locked(const struct lu_env *env,
2298 struct dt_object *dt)
2301 LASSERT(dt->do_ops);
2302 LASSERT(dt->do_ops->do_write_locked);
2303 return dt->do_ops->do_write_locked(env, dt);
2306 static inline int dt_declare_attr_get(const struct lu_env *env,
2307 struct dt_object *dt)
2310 LASSERT(dt->do_ops);
2311 LASSERT(dt->do_ops->do_declare_attr_get);
2313 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2314 return cfs_fail_err;
2316 return dt->do_ops->do_declare_attr_get(env, dt);
2319 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2323 LASSERT(dt->do_ops);
2324 LASSERT(dt->do_ops->do_attr_get);
2326 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2327 return cfs_fail_err;
2329 return dt->do_ops->do_attr_get(env, dt, la);
2332 static inline int dt_declare_attr_set(const struct lu_env *env,
2333 struct dt_object *dt,
2334 const struct lu_attr *la,
2338 LASSERT(dt->do_ops);
2339 LASSERT(dt->do_ops->do_declare_attr_set);
2341 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2342 return cfs_fail_err;
2344 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2347 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2348 const struct lu_attr *la, struct thandle *th)
2351 LASSERT(dt->do_ops);
2352 LASSERT(dt->do_ops->do_attr_set);
2354 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2355 return cfs_fail_err;
2357 return dt->do_ops->do_attr_set(env, dt, la, th);
2360 static inline int dt_declare_ref_add(const struct lu_env *env,
2361 struct dt_object *dt, struct thandle *th)
2364 LASSERT(dt->do_ops);
2365 LASSERT(dt->do_ops->do_declare_ref_add);
2367 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2368 return cfs_fail_err;
2370 return dt->do_ops->do_declare_ref_add(env, dt, th);
2373 static inline int dt_ref_add(const struct lu_env *env,
2374 struct dt_object *dt, struct thandle *th)
2377 LASSERT(dt->do_ops);
2378 LASSERT(dt->do_ops->do_ref_add);
2380 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2381 return cfs_fail_err;
2383 return dt->do_ops->do_ref_add(env, dt, th);
2386 static inline int dt_declare_ref_del(const struct lu_env *env,
2387 struct dt_object *dt, struct thandle *th)
2390 LASSERT(dt->do_ops);
2391 LASSERT(dt->do_ops->do_declare_ref_del);
2393 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2394 return cfs_fail_err;
2396 return dt->do_ops->do_declare_ref_del(env, dt, th);
2399 static inline int dt_ref_del(const struct lu_env *env,
2400 struct dt_object *dt, struct thandle *th)
2403 LASSERT(dt->do_ops);
2404 LASSERT(dt->do_ops->do_ref_del);
2406 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2407 return cfs_fail_err;
2409 return dt->do_ops->do_ref_del(env, dt, th);
2412 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2413 struct niobuf_remote *rnb,
2414 struct niobuf_local *lnb, int maxlnb,
2415 enum dt_bufs_type rw)
2418 LASSERT(d->do_body_ops);
2419 LASSERT(d->do_body_ops->dbo_bufs_get);
2420 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2421 rnb->rnb_len, lnb, maxlnb, rw);
2424 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2425 struct niobuf_local *lnb, int n)
2428 LASSERT(d->do_body_ops);
2429 LASSERT(d->do_body_ops->dbo_bufs_put);
2430 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2433 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2434 struct niobuf_local *lnb, int n)
2437 LASSERT(d->do_body_ops);
2438 LASSERT(d->do_body_ops->dbo_write_prep);
2439 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2442 static inline int dt_declare_write_commit(const struct lu_env *env,
2443 struct dt_object *d,
2444 struct niobuf_local *lnb,
2445 int n, struct thandle *th)
2447 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2448 LASSERT(th != NULL);
2449 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2453 static inline int dt_write_commit(const struct lu_env *env,
2454 struct dt_object *d, struct niobuf_local *lnb,
2455 int n, struct thandle *th)
2458 LASSERT(d->do_body_ops);
2459 LASSERT(d->do_body_ops->dbo_write_commit);
2460 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2463 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2464 struct niobuf_local *lnb, int n)
2467 LASSERT(d->do_body_ops);
2468 LASSERT(d->do_body_ops->dbo_read_prep);
2469 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2472 static inline int dt_declare_write(const struct lu_env *env,
2473 struct dt_object *dt,
2474 const struct lu_buf *buf, loff_t pos,
2478 LASSERT(dt->do_body_ops);
2479 LASSERT(dt->do_body_ops->dbo_declare_write);
2480 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2483 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2484 const struct lu_buf *buf, loff_t *pos,
2488 LASSERT(dt->do_body_ops);
2489 LASSERT(dt->do_body_ops->dbo_write);
2490 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2493 static inline int dt_declare_punch(const struct lu_env *env,
2494 struct dt_object *dt, __u64 start,
2495 __u64 end, struct thandle *th)
2498 LASSERT(dt->do_body_ops);
2499 LASSERT(dt->do_body_ops->dbo_declare_punch);
2500 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2503 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2504 __u64 start, __u64 end, struct thandle *th)
2507 LASSERT(dt->do_body_ops);
2508 LASSERT(dt->do_body_ops->dbo_punch);
2509 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2512 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2513 __u64 start, __u64 end, int advice)
2516 LASSERT(dt->do_body_ops);
2517 LASSERT(dt->do_body_ops->dbo_ladvise);
2518 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2521 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2525 if (d->do_body_ops == NULL)
2527 if (d->do_body_ops->dbo_fiemap_get == NULL)
2529 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2532 static inline int dt_statfs_info(const struct lu_env *env,
2533 struct dt_device *dev,
2534 struct obd_statfs *osfs,
2535 struct obd_statfs_info *info)
2538 LASSERT(dev->dd_ops);
2539 LASSERT(dev->dd_ops->dt_statfs);
2540 return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2543 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2544 struct obd_statfs *osfs)
2546 return dt_statfs_info(env, dev, osfs, NULL);
2549 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2553 LASSERT(dev->dd_ops);
2554 LASSERT(dev->dd_ops->dt_root_get);
2555 return dev->dd_ops->dt_root_get(env, dev, f);
2558 static inline void dt_conf_get(const struct lu_env *env,
2559 const struct dt_device *dev,
2560 struct dt_device_param *param)
2563 LASSERT(dev->dd_ops);
2564 LASSERT(dev->dd_ops->dt_conf_get);
2565 return dev->dd_ops->dt_conf_get(env, dev, param);
2568 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2571 LASSERT(dev->dd_ops);
2572 if (dev->dd_ops->dt_mnt_sb_get)
2573 return dev->dd_ops->dt_mnt_sb_get(dev);
2575 return ERR_PTR(-EOPNOTSUPP);
2578 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2581 LASSERT(dev->dd_ops);
2582 LASSERT(dev->dd_ops->dt_sync);
2583 return dev->dd_ops->dt_sync(env, dev);
2586 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2589 LASSERT(dev->dd_ops);
2590 LASSERT(dev->dd_ops->dt_ro);
2591 return dev->dd_ops->dt_ro(env, dev);
2594 static inline int dt_declare_insert(const struct lu_env *env,
2595 struct dt_object *dt,
2596 const struct dt_rec *rec,
2597 const struct dt_key *key,
2601 LASSERT(dt->do_index_ops);
2602 LASSERT(dt->do_index_ops->dio_declare_insert);
2604 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2605 return cfs_fail_err;
2607 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2610 static inline int dt_insert(const struct lu_env *env,
2611 struct dt_object *dt,
2612 const struct dt_rec *rec,
2613 const struct dt_key *key,
2617 LASSERT(dt->do_index_ops);
2618 LASSERT(dt->do_index_ops->dio_insert);
2620 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2621 return cfs_fail_err;
2623 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2626 static inline int dt_declare_xattr_del(const struct lu_env *env,
2627 struct dt_object *dt,
2632 LASSERT(dt->do_ops);
2633 LASSERT(dt->do_ops->do_declare_xattr_del);
2635 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2636 return cfs_fail_err;
2638 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2641 static inline int dt_xattr_del(const struct lu_env *env,
2642 struct dt_object *dt, const char *name,
2646 LASSERT(dt->do_ops);
2647 LASSERT(dt->do_ops->do_xattr_del);
2649 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2650 return cfs_fail_err;
2652 return dt->do_ops->do_xattr_del(env, dt, name, th);
2655 static inline int dt_declare_xattr_set(const struct lu_env *env,
2656 struct dt_object *dt,
2657 const struct lu_buf *buf,
2658 const char *name, int fl,
2662 LASSERT(dt->do_ops);
2663 LASSERT(dt->do_ops->do_declare_xattr_set);
2665 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2666 return cfs_fail_err;
2668 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2671 static inline int dt_xattr_set(const struct lu_env *env,
2672 struct dt_object *dt, const struct lu_buf *buf,
2673 const char *name, int fl, struct thandle *th)
2676 LASSERT(dt->do_ops);
2677 LASSERT(dt->do_ops->do_xattr_set);
2679 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2680 return cfs_fail_err;
2682 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2685 static inline int dt_declare_xattr_get(const struct lu_env *env,
2686 struct dt_object *dt,
2691 LASSERT(dt->do_ops);
2692 LASSERT(dt->do_ops->do_declare_xattr_get);
2694 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2695 return cfs_fail_err;
2697 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2700 static inline int dt_xattr_get(const struct lu_env *env,
2701 struct dt_object *dt, struct lu_buf *buf,
2705 LASSERT(dt->do_ops);
2706 LASSERT(dt->do_ops->do_xattr_get);
2708 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2709 return cfs_fail_err;
2711 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2714 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2715 const struct lu_buf *buf)
2718 LASSERT(dt->do_ops);
2719 LASSERT(dt->do_ops->do_xattr_list);
2721 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2722 return cfs_fail_err;
2724 return dt->do_ops->do_xattr_list(env, dt, buf);
2727 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2730 LASSERT(dt->do_ops);
2731 LASSERT(dt->do_ops->do_invalidate);
2733 return dt->do_ops->do_invalidate(env, dt);
2736 static inline int dt_declare_delete(const struct lu_env *env,
2737 struct dt_object *dt,
2738 const struct dt_key *key,
2742 LASSERT(dt->do_index_ops);
2743 LASSERT(dt->do_index_ops->dio_declare_delete);
2745 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2746 return cfs_fail_err;
2748 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2751 static inline int dt_delete(const struct lu_env *env,
2752 struct dt_object *dt,
2753 const struct dt_key *key,
2757 LASSERT(dt->do_index_ops);
2758 LASSERT(dt->do_index_ops->dio_delete);
2760 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2761 return cfs_fail_err;
2763 return dt->do_index_ops->dio_delete(env, dt, key, th);
2766 static inline int dt_commit_async(const struct lu_env *env,
2767 struct dt_device *dev)
2770 LASSERT(dev->dd_ops);
2771 LASSERT(dev->dd_ops->dt_commit_async);
2772 return dev->dd_ops->dt_commit_async(env, dev);
2775 static inline int dt_lookup(const struct lu_env *env,
2776 struct dt_object *dt,
2778 const struct dt_key *key)
2783 LASSERT(dt->do_index_ops);
2784 LASSERT(dt->do_index_ops->dio_lookup);
2786 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2787 return cfs_fail_err;
2789 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2797 static inline int dt_declare_layout_change(const struct lu_env *env,
2798 struct dt_object *o,
2799 struct md_layout_change *mlc,
2804 LASSERT(o->do_ops->do_declare_layout_change);
2805 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2808 static inline int dt_layout_change(const struct lu_env *env,
2809 struct dt_object *o,
2810 struct md_layout_change *mlc,
2815 LASSERT(o->do_ops->do_layout_change);
2816 return o->do_ops->do_layout_change(env, o, mlc, th);
2819 struct dt_find_hint {
2820 struct lu_fid *dfh_fid;
2821 struct dt_device *dfh_dt;
2822 struct dt_object *dfh_o;
2825 struct dt_insert_rec {
2827 const struct lu_fid *rec_fid;
2839 struct dt_thread_info {
2840 char dti_buf[DT_MAX_PATH];
2841 struct dt_find_hint dti_dfh;
2842 struct lu_attr dti_attr;
2843 struct lu_fid dti_fid;
2844 struct dt_object_format dti_dof;
2845 struct lustre_mdt_attrs dti_lma;
2846 struct lu_buf dti_lb;
2847 struct lu_object_conf dti_conf;
2849 struct dt_insert_rec dti_dt_rec;
2852 extern struct lu_context_key dt_key;
2854 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2856 struct dt_thread_info *dti;
2858 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2863 int dt_global_init(void);
2864 void dt_global_fini(void);
2865 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2866 const char *name, struct lprocfs_vars *list);
2867 int dt_tunables_fini(struct dt_device *dt);
2869 # ifdef CONFIG_PROC_FS
2870 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2871 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2872 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2873 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2874 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2875 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2876 # endif /* CONFIG_PROC_FS */
2878 #endif /* __LUSTRE_DT_OBJECT_H */