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;
395 * object type specifier.
398 enum dt_format_type {
403 /** for special index */
405 /** for symbolic link */
410 * object format specifier.
412 struct dt_object_format {
413 /** type for dt object */
414 enum dt_format_type dof_type;
424 * special index need feature as parameter to create
428 const struct dt_index_features *di_feat;
433 enum dt_format_type dt_mode_to_dft(__u32 mode);
435 typedef __u64 dt_obj_version_t;
437 union ldlm_policy_data;
439 struct md_layout_change;
442 * A dt_object provides common operations to create and destroy
443 * objects and to manage regular and extended attributes.
445 struct dt_object_operations {
447 * Get read lock on object.
449 * Read lock is compatible with other read locks, so it's shared.
450 * Read lock is not compatible with write lock which is exclusive.
451 * The lock is blocking and can't be used from an interrupt context.
453 * \param[in] env execution environment for this thread
454 * \param[in] dt object to lock for reading
455 * \param[in] role a hint to debug locks (see kernel's mutexes)
457 void (*do_read_lock)(const struct lu_env *env,
458 struct dt_object *dt,
462 * Get write lock on object.
464 * Write lock is exclusive and cannot be shared. The lock is blocking
465 * and can't be used from an interrupt context.
467 * \param[in] env execution environment for this thread
468 * \param[in] dt object to lock for writing
469 * \param[in] role a hint to debug locks (see kernel's mutexes)
472 void (*do_write_lock)(const struct lu_env *env,
473 struct dt_object *dt,
479 * \param[in] env execution environment for this thread
480 * \param[in] dt object
482 void (*do_read_unlock)(const struct lu_env *env,
483 struct dt_object *dt);
486 * Release write lock.
488 * \param[in] env execution environment for this thread
489 * \param[in] dt object
491 void (*do_write_unlock)(const struct lu_env *env,
492 struct dt_object *dt);
495 * Check whether write lock is held.
497 * The caller can learn whether write lock is held on the object
499 * \param[in] env execution environment for this thread
500 * \param[in] dt object
502 * \retval 0 no write lock
503 * \retval 1 write lock is held
505 int (*do_write_locked)(const struct lu_env *env,
506 struct dt_object *dt);
509 * Declare intention to request reqular attributes.
511 * Notity the underlying filesystem that the caller may request regular
512 * attributes with ->do_attr_get() soon. This allows OSD to implement
513 * prefetching logic in an object-oriented manner. The implementation
514 * can be noop. This method should avoid expensive delays such as
515 * waiting on disk I/O, otherwise the goal of enabling a performance
516 * optimization would be defeated.
518 * \param[in] env execution environment for this thread
519 * \param[in] dt object
521 * \retval 0 on success
522 * \retval negative negated errno on error
524 int (*do_declare_attr_get)(const struct lu_env *env,
525 struct dt_object *dt);
528 * Return regular attributes.
530 * The object must exist. Currently all the attributes should be
531 * returned, but in the future this can be improved so that only
532 * a selected set is returned. This can improve performance as in
533 * some cases attributes are stored in different places and
534 * getting them all can be an iterative and expensive process.
536 * \param[in] env execution environment for this thread
537 * \param[in] dt object
538 * \param[out] attr attributes to fill
540 * \retval 0 on success
541 * \retval negative negated errno on error
543 int (*do_attr_get)(const struct lu_env *env,
544 struct dt_object *dt,
545 struct lu_attr *attr);
548 * Declare intention to change regular object's attributes.
550 * Notify the underlying filesystem that the regular attributes may
551 * change in this transaction. This enables the layer below to prepare
552 * resources (e.g. journal credits in ext4). This method should be
553 * called between creating the transaction and starting it. Note that
554 * the la_valid field of \a attr specifies which attributes will change.
555 * The object need not exist.
557 * \param[in] env execution environment for this thread
558 * \param[in] dt object
559 * \param[in] attr attributes to change specified in attr.la_valid
560 * \param[in] th transaction handle
562 * \retval 0 on success
563 * \retval negative negated errno on error
565 int (*do_declare_attr_set)(const struct lu_env *env,
566 struct dt_object *dt,
567 const struct lu_attr *attr,
571 * Change regular attributes.
573 * Change regular attributes in the given transaction. Note only
574 * attributes flagged by attr.la_valid change. The object must
575 * exist. If the layer implementing this method is responsible for
576 * quota, then the method should maintain object accounting for the
577 * given credentials when la_uid/la_gid changes.
579 * \param[in] env execution environment for this thread
580 * \param[in] dt object
581 * \param[in] attr new attributes to apply
582 * \param[in] th transaction handle
584 * \retval 0 on success
585 * \retval negative negated errno on error
587 int (*do_attr_set)(const struct lu_env *env,
588 struct dt_object *dt,
589 const struct lu_attr *attr,
593 * Declare intention to request extented attribute.
595 * Notify the underlying filesystem that the caller may request extended
596 * attribute with ->do_xattr_get() soon. This allows OSD to implement
597 * prefetching logic in an object-oriented manner. The implementation
598 * can be noop. This method should avoid expensive delays such as
599 * waiting on disk I/O, otherwise the goal of enabling a performance
600 * optimization would be defeated.
602 * \param[in] env execution environment for this thread
603 * \param[in] dt object
604 * \param[in] buf unused, may be removed in the future
605 * \param[in] name name of the extended attribute
607 * \retval 0 on success
608 * \retval negative negated errno on error
610 int (*do_declare_xattr_get)(const struct lu_env *env,
611 struct dt_object *dt,
616 * Return a value of an extended attribute.
618 * The object must exist. If the buffer is NULL, then the method
619 * must return the size of the value.
621 * \param[in] env execution environment for this thread
622 * \param[in] dt object
623 * \param[out] buf buffer in which to store the value
624 * \param[in] name name of the extended attribute
626 * \retval 0 on success
627 * \retval -ERANGE if \a buf is too small
628 * \retval negative negated errno on error
629 * \retval positive value's size if \a buf is NULL or has zero size
631 int (*do_xattr_get)(const struct lu_env *env,
632 struct dt_object *dt,
637 * Declare intention to change an extended attribute.
639 * Notify the underlying filesystem that the extended attribute may
640 * change in this transaction. This enables the layer below to prepare
641 * resources (e.g. journal credits in ext4). This method should be
642 * called between creating the transaction and starting it. The object
645 * \param[in] env execution environment for this thread
646 * \param[in] dt object
647 * \param[in] buf buffer storing new value of the attribute
648 * \param[in] name name of the attribute
649 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
650 * LU_XATTR_REPLACE - fail if EA doesn't exist
651 * \param[in] th transaction handle
653 * \retval 0 on success
654 * \retval negative negated errno on error
656 int (*do_declare_xattr_set)(const struct lu_env *env,
657 struct dt_object *dt,
658 const struct lu_buf *buf,
664 * Set an extended attribute.
666 * Change or replace the specified extended attribute (EA).
667 * The flags passed in \a fl dictate whether the EA is to be
668 * created or replaced, as follows.
669 * LU_XATTR_CREATE - fail if EA exists
670 * LU_XATTR_REPLACE - fail if EA doesn't exist
671 * The object must exist.
673 * \param[in] env execution environment for this thread
674 * \param[in] dt object
675 * \param[in] buf buffer storing new value of the attribute
676 * \param[in] name name of the attribute
677 * \param[in] fl flags indicating EA creation or replacement
678 * \param[in] th transaction handle
680 * \retval 0 on success
681 * \retval negative negated errno on error
683 int (*do_xattr_set)(const struct lu_env *env,
684 struct dt_object *dt,
685 const struct lu_buf *buf,
691 * Declare intention to delete an extended attribute.
693 * Notify the underlying filesystem that the extended attribute may
694 * be deleted in this transaction. This enables the layer below to
695 * prepare resources (e.g. journal credits in ext4). This method
696 * should be called between creating the transaction and starting it.
697 * The object need not exist.
699 * \param[in] env execution environment for this thread
700 * \param[in] dt object
701 * \param[in] name name of the attribute
702 * \param[in] th transaction handle
704 * \retval 0 on success
705 * \retval negative negated errno on error
707 int (*do_declare_xattr_del)(const struct lu_env *env,
708 struct dt_object *dt,
713 * Delete an extended attribute.
715 * This method deletes the specified extended attribute. The object
718 * \param[in] env execution environment for this thread
719 * \param[in] dt object
720 * \param[in] name name of the attribute
721 * \param[in] th transaction handle
723 * \retval 0 on success
724 * \retval negative negated errno on error
726 int (*do_xattr_del)(const struct lu_env *env,
727 struct dt_object *dt,
732 * Return a list of the extended attributes.
734 * Fills the passed buffer with a list of the extended attributes
735 * found in the object. The names are separated with '\0'.
736 * The object must exist.
738 * \param[in] env execution environment for this thread
739 * \param[in] dt object
740 * \param[out] buf buffer to put the list in
742 * \retval positive bytes used/required in the buffer
743 * \retval negative negated errno on error
745 int (*do_xattr_list)(const struct lu_env *env,
746 struct dt_object *dt,
747 const struct lu_buf *buf);
750 * Prepare allocation hint for a new object.
752 * This method is used by the caller to inform OSD of the parent-child
753 * relationship between two objects and enable efficient object
754 * allocation. Filled allocation hint will be passed to ->do_create()
757 * \param[in] env execution environment for this thread
758 * \param[out] ah allocation hint
759 * \param[in] parent parent object (can be NULL)
760 * \param[in] child child object
761 * \param[in] _mode type of the child object
763 void (*do_ah_init)(const struct lu_env *env,
764 struct dt_allocation_hint *ah,
765 struct dt_object *parent,
766 struct dt_object *child,
770 * Declare intention to create a new object.
772 * Notify the underlying filesystem that the object may be created
773 * in this transaction. This enables the layer below to prepare
774 * resources (e.g. journal credits in ext4). This method should be
775 * called between creating the transaction and starting it.
777 * If the layer implementing this method is responsible for quota,
778 * then the method should reserve an object for the given credentials
779 * and return an error if quota is over. If object creation later
780 * fails for some reason, then the reservation should be released
781 * properly (usually in ->dt_trans_stop()).
783 * \param[in] env execution environment for this thread
784 * \param[in] dt object
785 * \param[in] attr attributes of the new object
786 * \param[in] hint allocation hint
787 * \param[in] dof object format
788 * \param[in] th transaction handle
790 * \retval 0 on success
791 * \retval negative negated errno on error
793 int (*do_declare_create)(const struct lu_env *env,
794 struct dt_object *dt,
795 struct lu_attr *attr,
796 struct dt_allocation_hint *hint,
797 struct dt_object_format *dof,
803 * The method creates the object passed with the specified attributes
804 * and object format. Object allocation procedure can use information
805 * stored in the allocation hint. Different object formats are supported
806 * (see enum dt_format_type and struct dt_object_format) depending on
807 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
808 * in the LU-object header attributes.
810 * If the layer implementing this method is responsible for quota,
811 * then the method should maintain object accounting for the given
814 * \param[in] env execution environment for this thread
815 * \param[in] dt object
816 * \param[in] attr attributes of the new object
817 * \param[in] hint allocation hint
818 * \param[in] dof object format
819 * \param[in] th transaction handle
821 * \retval 0 on success
822 * \retval negative negated errno on error
824 int (*do_create)(const struct lu_env *env,
825 struct dt_object *dt,
826 struct lu_attr *attr,
827 struct dt_allocation_hint *hint,
828 struct dt_object_format *dof,
832 * Declare intention to destroy an object.
834 * Notify the underlying filesystem that the object may be destroyed
835 * in this transaction. This enables the layer below to prepare
836 * resources (e.g. journal credits in ext4). This method should be
837 * called between creating the transaction and starting it. The object
840 * \param[in] env execution environment for this thread
841 * \param[in] dt object
842 * \param[in] th transaction handle
844 * \retval 0 on success
845 * \retval negative negated errno on error
847 int (*do_declare_destroy)(const struct lu_env *env,
848 struct dt_object *dt,
854 * This method destroys the object and all the resources associated
855 * with the object (data, key/value pairs, extended attributes, etc).
856 * The object must exist. If destroy is successful, then flag
857 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
858 * instance of in-core object. Any subsequent access to the same FID
859 * should get another instance with no LOHA_EXIST flag set.
861 * If the layer implementing this method is responsible for quota,
862 * then the method should maintain object accounting for the given
865 * \param[in] env execution environment for this thread
866 * \param[in] dt object
867 * \param[in] th transaction handle
869 * \retval 0 on success
870 * \retval negative negated errno on error
872 int (*do_destroy)(const struct lu_env *env,
873 struct dt_object *dt,
877 * Try object as an index.
879 * Announce that this object is going to be used as an index. This
880 * operation checks that object supports indexing operations and
881 * installs appropriate dt_index_operations vector on success.
882 * Also probes for features. Operation is successful if all required
883 * features are supported. It's not possible to access the object
884 * with index methods before ->do_index_try() returns success.
886 * \param[in] env execution environment for this thread
887 * \param[in] dt object
888 * \param[in] feat index features
890 * \retval 0 on success
891 * \retval negative negated errno on error
893 int (*do_index_try)(const struct lu_env *env,
894 struct dt_object *dt,
895 const struct dt_index_features *feat);
898 * Declare intention to increment nlink count.
900 * Notify the underlying filesystem that the nlink regular attribute
901 * be changed in this transaction. This enables the layer below to
902 * prepare resources (e.g. journal credits in ext4). This method
903 * should be called between creating the transaction and starting it.
904 * The object need not exist.
906 * \param[in] env execution environment for this thread
907 * \param[in] dt object
908 * \param[in] th transaction handle
910 * \retval 0 on success
911 * \retval negative negated errno on error
913 int (*do_declare_ref_add)(const struct lu_env *env,
914 struct dt_object *dt,
920 * Increment nlink (from the regular attributes set) in the given
921 * transaction. Note the absolute limit for nlink should be learnt
922 * from struct dt_device_param::ddp_max_nlink. The object must exist.
924 * \param[in] env execution environment for this thread
925 * \param[in] dt object
926 * \param[in] th transaction handle
928 * \retval 0 on success
929 * \retval negative negated errno on error
931 int (*do_ref_add)(const struct lu_env *env,
932 struct dt_object *dt, struct thandle *th);
935 * Declare intention to decrement nlink count.
937 * Notify the underlying filesystem that the nlink regular attribute
938 * be changed in this transaction. This enables the layer below to
939 * prepare resources (e.g. journal credits in ext4). This method
940 * should be called between creating the transaction and starting it.
941 * The object need not exist.
943 * \param[in] env execution environment for this thread
944 * \param[in] dt object
945 * \param[in] th transaction handle
947 * \retval 0 on success
948 * \retval negative negated errno on error
950 int (*do_declare_ref_del)(const struct lu_env *env,
951 struct dt_object *dt,
957 * Decrement nlink (from the regular attributes set) in the given
958 * transaction. The object must exist.
960 * \param[in] env execution environment for this thread
961 * \param[in] dt object
962 * \param[in] th transaction handle
964 * \retval 0 on success
965 * \retval negative negated errno on error
967 int (*do_ref_del)(const struct lu_env *env,
968 struct dt_object *dt,
974 * The method is called to sync specified range of the object to a
975 * persistent storage. The control is returned once the operation is
976 * complete. The difference from ->do_sync() is that the object can
977 * be in-sync with the persistent storage (nothing to flush), then
978 * the method returns quickly with no I/O overhead. So, this method
979 * should be preferred over ->do_sync() where possible. Also note that
980 * if the object isn't clean, then some disk filesystems will call
981 * ->do_sync() to maintain overall consistency, in which case it's
982 * still very expensive.
984 * \param[in] env execution environment for this thread
985 * \param[in] dt object
986 * \param[in] start start of the range to sync
987 * \param[in] end end of the range to sync
989 * \retval 0 on success
990 * \retval negative negated errno on error
992 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
993 __u64 start, __u64 end);
998 * Lock object(s) using Distributed Lock Manager (LDLM).
1000 * Get LDLM locks for the object. Currently used to lock "remote"
1001 * objects in DNE configuration - a service running on MDTx needs
1002 * to lock an object on MDTy.
1004 * \param[in] env execution environment for this thread
1005 * \param[in] dt object
1006 * \param[out] lh lock handle, sometimes used, sometimes not
1007 * \param[in] einfo ldlm callbacks, locking type and mode
1008 * \param[out] einfo private data to be passed to unlock later
1009 * \param[in] policy inodebits data
1011 * \retval 0 on success
1012 * \retval negative negated errno on error
1014 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1015 struct lustre_handle *lh,
1016 struct ldlm_enqueue_info *einfo,
1017 union ldlm_policy_data *policy);
1022 * Release LDLM lock(s) granted with ->do_object_lock().
1024 * \param[in] env execution environment for this thread
1025 * \param[in] dt object
1026 * \param[in] einfo lock handles, from ->do_object_lock()
1027 * \param[in] policy inodebits data
1029 * \retval 0 on success
1030 * \retval negative negated errno on error
1032 int (*do_object_unlock)(const struct lu_env *env,
1033 struct dt_object *dt,
1034 struct ldlm_enqueue_info *einfo,
1035 union ldlm_policy_data *policy);
1038 * Invalidate attribute cache.
1040 * This method invalidate attribute cache of the object, which is on OSP
1043 * \param[in] env execution envionment for this thread
1044 * \param[in] dt object
1046 * \retval 0 on success
1047 * \retval negative negated errno on error
1049 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1052 * Declare intention to instaintiate extended layout component.
1054 * \param[in] env execution environment
1055 * \param[in] dt DT object
1056 * \param[in] layout data structure to describe the changes to
1057 * the DT object's layout
1058 * \param[in] buf buffer containing client's lovea or empty
1061 * \retval -ne error code
1063 int (*do_declare_layout_change)(const struct lu_env *env,
1064 struct dt_object *dt,
1065 struct md_layout_change *mlc,
1066 struct thandle *th);
1069 * Client is trying to write to un-instantiated layout component.
1071 * \param[in] env execution environment
1072 * \param[in] dt DT object
1073 * \param[in] layout data structure to describe the changes to
1074 * the DT object's layout
1075 * \param[in] buf buffer containing client's lovea or empty
1078 * \retval -ne error code
1080 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1081 struct md_layout_change *mlc,
1082 struct thandle *th);
1086 DT_BUFS_TYPE_READ = 0x0000,
1087 DT_BUFS_TYPE_WRITE = 0x0001,
1088 DT_BUFS_TYPE_READAHEAD = 0x0002,
1089 DT_BUFS_TYPE_LOCAL = 0x0004,
1093 * Per-dt-object operations on "file body" - unstructure raw data.
1095 struct dt_body_operations {
1099 * Read unstructured data from an existing regular object.
1100 * Only data before attr.la_size is returned.
1102 * \param[in] env execution environment for this thread
1103 * \param[in] dt object
1104 * \param[out] buf buffer (including size) to copy data in
1105 * \param[in] pos position in the object to start
1106 * \param[out] pos original value of \a pos + bytes returned
1108 * \retval positive bytes read on success
1109 * \retval negative negated errno on error
1111 ssize_t (*dbo_read)(const struct lu_env *env,
1112 struct dt_object *dt,
1117 * Declare intention to write data to object.
1119 * Notify the underlying filesystem that data may be written in
1120 * this transaction. This enables the layer below to prepare resources
1121 * (e.g. journal credits in ext4). This method should be called
1122 * between creating the transaction and starting it. The object need
1123 * not exist. If the layer implementing this method is responsible for
1124 * quota, then the method should reserve space for the given credentials
1125 * and return an error if quota is over. If the write later fails
1126 * for some reason, then the reserve should be released properly
1127 * (usually in ->dt_trans_stop()).
1129 * \param[in] env execution environment for this thread
1130 * \param[in] dt object
1131 * \param[in] buf buffer (including size) to copy data from
1132 * \param[in] pos position in the object to start
1133 * \param[in] th transaction handle
1135 * \retval 0 on success
1136 * \retval negative negated errno on error
1138 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1139 struct dt_object *dt,
1140 const struct lu_buf *buf,
1142 struct thandle *th);
1145 * Write unstructured data to regular existing object.
1147 * The method allocates space and puts data in. Also, the method should
1148 * maintain attr.la_size properly. Partial writes are possible.
1150 * If the layer implementing this method is responsible for quota,
1151 * then the method should maintain space accounting for the given
1154 * \param[in] env execution environment for this thread
1155 * \param[in] dt object
1156 * \param[in] buf buffer (including size) to copy data from
1157 * \param[in] pos position in the object to start
1158 * \param[out] pos \a pos + bytes written
1159 * \param[in] th transaction handle
1161 * \retval positive bytes written on success
1162 * \retval negative negated errno on error
1164 ssize_t (*dbo_write)(const struct lu_env *env,
1165 struct dt_object *dt,
1166 const struct lu_buf *buf,
1168 struct thandle *th);
1171 * Return buffers for data.
1173 * This method is used to access data with no copying. It's so-called
1174 * zero-copy I/O. The method returns the descriptors for the internal
1175 * buffers where data are managed by the disk filesystem. For example,
1176 * pagecache in case of ext4 or ARC with ZFS. Then other components
1177 * (e.g. networking) can transfer data from or to the buffers with no
1178 * additional copying.
1180 * The method should fill an array of struct niobuf_local, where
1181 * each element describes a full or partial page for data at specific
1182 * offset. The caller should use page/lnb_page_offset/len to find data
1183 * at object's offset lnb_file_offset.
1185 * The memory referenced by the descriptors can't change its purpose
1186 * until the complementary ->dbo_bufs_put() is called. The caller should
1187 * specify if the buffers are used to read or modify data so that OSD
1188 * can decide how to initialize the buffers: bring all the data for
1189 * reads or just bring partial buffers for write. Note: the method does
1190 * not check whether output array is large enough.
1192 * \param[in] env execution environment for this thread
1193 * \param[in] dt object
1194 * \param[in] pos position in the object to start
1195 * \param[in] len size of region in bytes
1196 * \param[out] lb array of descriptors to fill
1197 * \param[in] rw 0 if used to read, 1 if used for write
1199 * \retval positive number of descriptors on success
1200 * \retval negative negated errno on error
1202 int (*dbo_bufs_get)(const struct lu_env *env,
1203 struct dt_object *dt,
1206 struct niobuf_local *lb,
1207 enum dt_bufs_type rw);
1210 * Release reference granted by ->dbo_bufs_get().
1212 * Release the reference granted by the previous ->dbo_bufs_get().
1213 * Note the references are counted.
1215 * \param[in] env execution environment for this thread
1216 * \param[in] dt object
1217 * \param[out] lb array of descriptors to fill
1218 * \param[in] nr size of the array
1220 * \retval 0 on success
1221 * \retval negative negated errno on error
1223 int (*dbo_bufs_put)(const struct lu_env *env,
1224 struct dt_object *dt,
1225 struct niobuf_local *lb,
1229 * Prepare buffers for reading.
1231 * The method is called on the given buffers to fill them with data
1232 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1233 * caller should be able to get few buffers for discontiguous regions
1234 * using few calls to ->dbo_bufs_get() and then request them all for
1235 * the preparation with a single call, so that OSD can fire many I/Os
1236 * to run concurrently. It's up to the specific OSD whether to implement
1237 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1238 * prepare data for every requested region individually.
1240 * \param[in] env execution environment for this thread
1241 * \param[in] dt object
1242 * \param[in] lnb array of buffer descriptors
1243 * \param[in] nr size of the array
1245 * \retval 0 on success
1246 * \retval negative negated errno on error
1248 int (*dbo_read_prep)(const struct lu_env *env,
1249 struct dt_object *dt,
1250 struct niobuf_local *lnb,
1254 * Prepare buffers for write.
1256 * This method is called on the given buffers to ensure the partial
1257 * buffers contain correct data. The underlying idea is the same as
1258 * in ->db_read_prep().
1260 * \param[in] env execution environment for this thread
1261 * \param[in] dt object
1262 * \param[in] lb array of buffer descriptors
1263 * \param[in] nr size of the array
1265 * \retval 0 on success
1266 * \retval negative negated errno on error
1268 int (*dbo_write_prep)(const struct lu_env *env,
1269 struct dt_object *dt,
1270 struct niobuf_local *lb,
1274 * Declare intention to write data stored in the buffers.
1276 * Notify the underlying filesystem that data may be written in
1277 * this transaction. This enables the layer below to prepare resources
1278 * (e.g. journal credits in ext4). This method should be called
1279 * between creating the transaction and starting it.
1281 * If the layer implementing this method is responsible for quota,
1282 * then the method should be reserving a space for the given
1283 * credentials and return an error if quota is exceeded. If the write
1284 * later fails for some reason, then the reserve should be released
1285 * properly (usually in ->dt_trans_stop()).
1287 * \param[in] env execution environment for this thread
1288 * \param[in] dt object
1289 * \param[in] lb array of descriptors
1290 * \param[in] nr size of the array
1291 * \param[in] th transaction handle
1293 * \retval 0 on success
1294 * \retval negative negated errno on error
1296 int (*dbo_declare_write_commit)(const struct lu_env *env,
1297 struct dt_object *dt,
1298 struct niobuf_local *lb,
1300 struct thandle *th);
1303 * Write to existing object.
1305 * This method is used to write data to a persistent storage using
1306 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1307 * data into the buffers using own mechanisms (e.g. direct transfer
1308 * from a NIC). The method should maintain attr.la_size. Also,
1309 * attr.la_blocks should be maintained but this can be done in lazy
1310 * manner, when actual allocation happens.
1312 * If the layer implementing this method is responsible for quota,
1313 * then the method should maintain space accounting for the given
1316 * \param[in] env execution environment for this thread
1317 * \param[in] dt object
1318 * \param[in] lb array of descriptors for the buffers
1319 * \param[in] nr size of the array
1320 * \param[in] th transaction handle
1322 * \retval 0 on success
1323 * \retval negative negated errno on error
1325 int (*dbo_write_commit)(const struct lu_env *env,
1326 struct dt_object *dt,
1327 struct niobuf_local *lb,
1329 struct thandle *th);
1332 * Return logical to physical block mapping for a given extent
1334 * \param[in] env execution environment for this thread
1335 * \param[in] dt object
1336 * \param[in] fm describe the region to map and the output buffer
1337 * see the details in include/linux/fiemap.h
1339 * \retval 0 on success
1340 * \retval negative negated errno on error
1342 int (*dbo_fiemap_get)(const struct lu_env *env,
1343 struct dt_object *dt,
1347 * Declare intention to deallocate space from an object.
1349 * Notify the underlying filesystem that space may be deallocated in
1350 * this transactions. This enables the layer below to prepare resources
1351 * (e.g. journal credits in ext4). This method should be called between
1352 * creating the transaction and starting it. The object need not exist.
1354 * \param[in] env execution environment for this thread
1355 * \param[in] dt object
1356 * \param[in] start the start of the region to deallocate
1357 * \param[in] end the end of the region to deallocate
1358 * \param[in] th transaction handle
1360 * \retval 0 on success
1361 * \retval negative negated errno on error
1363 int (*dbo_declare_punch)(const struct lu_env *env,
1364 struct dt_object *dt,
1367 struct thandle *th);
1370 * Deallocate specified region in an object.
1372 * This method is used to deallocate (release) space possibly consumed
1373 * by the given region of the object. If the layer implementing this
1374 * method is responsible for quota, then the method should maintain
1375 * space accounting for the given credentials.
1377 * \param[in] env execution environment for this thread
1378 * \param[in] dt object
1379 * \param[in] start the start of the region to deallocate
1380 * \param[in] end the end of the region to deallocate
1381 * \param[in] th transaction handle
1383 * \retval 0 on success
1384 * \retval negative negated errno on error
1386 int (*dbo_punch)(const struct lu_env *env,
1387 struct dt_object *dt,
1390 struct thandle *th);
1392 * Give advices on specified region in an object.
1394 * This method is used to give advices about access pattern on an
1395 * given region of the object. The disk filesystem understands
1396 * the advices and tunes cache/read-ahead policies.
1398 * \param[in] env execution environment for this thread
1399 * \param[in] dt object
1400 * \param[in] start the start of the region affected
1401 * \param[in] end the end of the region affected
1402 * \param[in] advice advice type
1404 * \retval 0 on success
1405 * \retval negative negated errno on error
1407 int (*dbo_ladvise)(const struct lu_env *env,
1408 struct dt_object *dt,
1411 enum lu_ladvise_type advice);
1415 * Incomplete type of index record.
1420 * Incomplete type of index key.
1425 * Incomplete type of dt iterator.
1430 * Per-dt-object operations on object as index. Index is a set of key/value
1431 * pairs abstracted from an on-disk representation. An index supports the
1432 * number of operations including lookup by key, insert and delete. Also,
1433 * an index can be iterated to find the pairs one by one, from a beginning
1434 * or specified point.
1436 struct dt_index_operations {
1438 * Lookup in an index by key.
1440 * The method returns a value for the given key. Key/value format
1441 * and size should have been negotiated with ->do_index_try() before.
1442 * Thus it's the caller's responsibility to provide the method with
1443 * proper key and big enough buffer. No external locking is required,
1444 * all the internal consistency should be implemented by the method
1445 * or lower layers. The object should should have been created with
1446 * type DFT_INDEX or DFT_DIR.
1448 * \param[in] env execution environment for this thread
1449 * \param[in] dt object
1450 * \param[out] rec buffer where value will be stored
1451 * \param[in] key key
1453 * \retval 0 on success
1454 * \retval -ENOENT if key isn't found
1455 * \retval negative negated errno on error
1457 int (*dio_lookup)(const struct lu_env *env,
1458 struct dt_object *dt,
1460 const struct dt_key *key);
1463 * Declare intention to insert a key/value into an index.
1465 * Notify the underlying filesystem that new key/value may be inserted
1466 * in this transaction. This enables the layer below to prepare
1467 * resources (e.g. journal credits in ext4). This method should be
1468 * called between creating the transaction and starting it. key/value
1469 * format and size is subject to ->do_index_try().
1471 * \param[in] env execution environment for this thread
1472 * \param[in] dt object
1473 * \param[in] rec buffer storing value
1474 * \param[in] key key
1475 * \param[in] th transaction handle
1477 * \retval 0 on success
1478 * \retval negative negated errno on error
1480 int (*dio_declare_insert)(const struct lu_env *env,
1481 struct dt_object *dt,
1482 const struct dt_rec *rec,
1483 const struct dt_key *key,
1484 struct thandle *th);
1487 * Insert a new key/value pair into an index.
1489 * The method inserts specified key/value pair into the given index
1490 * object. The internal consistency is maintained by the method or
1491 * the functionality below. The format and size of key/value should
1492 * have been negotiated before using ->do_index_try(), no additional
1493 * information can be specified to the method. The keys are unique
1496 * \param[in] env execution environment for this thread
1497 * \param[in] dt object
1498 * \param[in] rec buffer storing value
1499 * \param[in] key key
1500 * \param[in] th transaction handle
1502 * \retval 0 on success
1503 * \retval negative negated errno on error
1505 int (*dio_insert)(const struct lu_env *env,
1506 struct dt_object *dt,
1507 const struct dt_rec *rec,
1508 const struct dt_key *key,
1509 struct thandle *th);
1512 * Declare intention to delete a key/value from an index.
1514 * Notify the underlying filesystem that key/value may be deleted in
1515 * this transaction. This enables the layer below to prepare resources
1516 * (e.g. journal credits in ext4). This method should be called
1517 * between creating the transaction and starting it. Key/value format
1518 * and size is subject to ->do_index_try(). The object need not exist.
1520 * \param[in] env execution environment for this thread
1521 * \param[in] dt object
1522 * \param[in] key key
1523 * \param[in] th transaction handle
1525 * \retval 0 on success
1526 * \retval negative negated errno on error
1528 int (*dio_declare_delete)(const struct lu_env *env,
1529 struct dt_object *dt,
1530 const struct dt_key *key,
1531 struct thandle *th);
1534 * Delete key/value pair from an index.
1536 * The method deletes specified key and corresponding value from the
1537 * given index object. The internal consistency is maintained by the
1538 * method or the functionality below. The format and size of the key
1539 * should have been negotiated before using ->do_index_try(), no
1540 * additional information can be specified to the method.
1542 * \param[in] env execution environment for this thread
1543 * \param[in] dt object
1544 * \param[in] key key
1545 * \param[in] th transaction handle
1547 * \retval 0 on success
1548 * \retval negative negated errno on error
1550 int (*dio_delete)(const struct lu_env *env,
1551 struct dt_object *dt,
1552 const struct dt_key *key,
1553 struct thandle *th);
1556 * Iterator interface.
1558 * Methods to iterate over an existing index, list the keys stored and
1559 * associated values, get key/value size, etc.
1563 * Allocate and initialize new iterator.
1565 * The iterator is a handler to be used in the subsequent
1566 * methods to access index's content. Note the position is
1567 * not defined at this point and should be initialized with
1568 * ->get() or ->load() method.
1570 * \param[in] env execution environment for this thread
1571 * \param[in] dt object
1572 * \param[in] attr ask the iterator to return part of
1573 the records, see LUDA_* for details
1575 * \retval pointer iterator pointer on success
1576 * \retval ERR_PTR(errno) on error
1578 struct dt_it *(*init)(const struct lu_env *env,
1579 struct dt_object *dt,
1585 * Release the specified iterator and all the resources
1586 * associated (e.g. the object, index cache, etc).
1588 * \param[in] env execution environment for this thread
1589 * \param[in] di iterator to release
1591 void (*fini)(const struct lu_env *env,
1595 * Move position of iterator.
1597 * Move the position of the specified iterator to the specified
1600 * \param[in] env execution environment for this thread
1601 * \param[in] di iterator
1602 * \param[in] key key to position to
1604 * \retval 0 if exact key is found
1605 * \retval 1 if at the record with least key
1606 * not larger than the key
1607 * \retval negative negated errno on error
1609 int (*get)(const struct lu_env *env,
1611 const struct dt_key *key);
1616 * Complimentary method for dt_it_ops::get() above. Some
1617 * implementation can increase a reference on the iterator in
1618 * dt_it_ops::get(). So the caller should be able to release
1619 * with dt_it_ops::put().
1621 * \param[in] env execution environment for this thread
1622 * \param[in] di iterator
1624 void (*put)(const struct lu_env *env,
1628 * Move to next record.
1630 * Moves the position of the iterator to a next record
1632 * \param[in] env execution environment for this thread
1633 * \param[in] di iterator
1635 * \retval 1 if no more records
1636 * \retval 0 on success, the next record is found
1637 * \retval negative negated errno on error
1639 int (*next)(const struct lu_env *env,
1645 * Returns a pointer to a buffer containing the key of the
1646 * record at the current position. The pointer is valid and
1647 * retains data until ->get(), ->load() and ->fini() methods
1650 * \param[in] env execution environment for this thread
1651 * \param[in] di iterator
1653 * \retval pointer to key on success
1654 * \retval ERR_PTR(errno) on error
1656 struct dt_key *(*key)(const struct lu_env *env,
1657 const struct dt_it *di);
1662 * Returns size of the key at the current position.
1664 * \param[in] env execution environment for this thread
1665 * \param[in] di iterator
1667 * \retval key's size on success
1668 * \retval negative negated errno on error
1670 int (*key_size)(const struct lu_env *env,
1671 const struct dt_it *di);
1676 * Stores the value of the record at the current position. The
1677 * buffer must be big enough (as negotiated with
1678 * ->do_index_try() or ->rec_size()). The caller can specify
1679 * she is interested only in part of the record, using attr
1680 * argument (see LUDA_* definitions for the details).
1682 * \param[in] env execution environment for this thread
1683 * \param[in] di iterator
1684 * \param[out] rec buffer to store value in
1685 * \param[in] attr specify part of the value to copy
1687 * \retval 0 on success
1688 * \retval negative negated errno on error
1690 int (*rec)(const struct lu_env *env,
1691 const struct dt_it *di,
1696 * Return record size.
1698 * Returns size of the record at the current position. The
1699 * \a attr can be used to specify only the parts of the record
1700 * needed to be returned. (see LUDA_* definitions for the
1703 * \param[in] env execution environment for this thread
1704 * \param[in] di iterator
1705 * \param[in] attr part of the record to return
1707 * \retval record's size on success
1708 * \retval negative negated errno on error
1710 int (*rec_size)(const struct lu_env *env,
1711 const struct dt_it *di,
1715 * Return a cookie (hash).
1717 * Returns the cookie (usually hash) of the key at the current
1718 * position. This allows the caller to resume iteration at this
1719 * position later. The exact value is specific to implementation
1720 * and should not be interpreted by the caller.
1722 * \param[in] env execution environment for this thread
1723 * \param[in] di iterator
1725 * \retval cookie/hash of the key
1727 __u64 (*store)(const struct lu_env *env,
1728 const struct dt_it *di);
1731 * Initialize position using cookie/hash.
1733 * Initializes the current position of the iterator to one
1734 * described by the cookie/hash as returned by ->store()
1737 * \param[in] env execution environment for this thread
1738 * \param[in] di iterator
1739 * \param[in] hash cookie/hash value
1741 * \retval positive if current position points to
1742 * record with least cookie not larger
1744 * \retval 0 if current position matches cookie
1745 * \retval negative negated errno on error
1747 int (*load)(const struct lu_env *env,
1748 const struct dt_it *di,
1754 int (*key_rec)(const struct lu_env *env,
1755 const struct dt_it *di,
1760 enum dt_otable_it_valid {
1761 DOIV_ERROR_HANDLE = 0x0001,
1762 DOIV_DRYRUN = 0x0002,
1765 enum dt_otable_it_flags {
1766 /* Exit when fail. */
1767 DOIF_FAILOUT = 0x0001,
1769 /* Reset iteration position to the device beginning. */
1770 DOIF_RESET = 0x0002,
1772 /* There is up layer component uses the iteration. */
1773 DOIF_OUTUSED = 0x0004,
1775 /* Check only without repairing. */
1776 DOIF_DRYRUN = 0x0008,
1779 /* otable based iteration needs to use the common DT iteration APIs.
1780 * To initialize the iteration, it needs call dio_it::init() firstly.
1781 * Here is how the otable based iteration should prepare arguments to
1782 * call dt_it_ops::init().
1784 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1785 * is composed of two parts:
1786 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1787 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1788 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1791 struct lu_device dd_lu_dev;
1792 const struct dt_device_operations *dd_ops;
1795 * List of dt_txn_callback (see below). This is not protected in any
1796 * way, because callbacks are supposed to be added/deleted only during
1797 * single-threaded start-up shut-down procedures.
1799 struct list_head dd_txn_callbacks;
1800 unsigned int dd_record_fid_accessed:1,
1803 /* sysfs and debugfs handling */
1804 struct dentry *dd_debugfs_entry;
1806 const struct attribute **dd_def_attrs;
1807 struct kobject dd_kobj;
1808 struct kobj_type dd_ktype;
1809 struct completion dd_kobj_unregister;
1812 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1813 void dt_device_fini(struct dt_device *dev);
1815 static inline int lu_device_is_dt(const struct lu_device *d)
1817 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1820 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1822 LASSERT(lu_device_is_dt(l));
1823 return container_of0(l, struct dt_device, dd_lu_dev);
1827 struct lu_object do_lu;
1828 const struct dt_object_operations *do_ops;
1829 const struct dt_body_operations *do_body_ops;
1830 const struct dt_index_operations *do_index_ops;
1834 * In-core representation of per-device local object OID storage
1836 struct local_oid_storage {
1837 /* all initialized llog systems on this node linked by this */
1838 struct list_head los_list;
1840 /* how many handle's reference this los has */
1841 atomic_t los_refcount;
1842 struct dt_device *los_dev;
1843 struct dt_object *los_obj;
1845 /* data used to generate new fids */
1846 struct mutex los_id_lock;
1851 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1853 return &d->dd_lu_dev;
1856 static inline struct dt_object *lu2dt(struct lu_object *l)
1858 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1859 return container_of0(l, struct dt_object, do_lu);
1862 int dt_object_init(struct dt_object *obj,
1863 struct lu_object_header *h, struct lu_device *d);
1865 void dt_object_fini(struct dt_object *obj);
1867 static inline int dt_object_exists(const struct dt_object *dt)
1869 return lu_object_exists(&dt->do_lu);
1872 static inline int dt_object_remote(const struct dt_object *dt)
1874 return lu_object_remote(&dt->do_lu);
1877 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1879 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1880 return container_of0(o, struct dt_object, do_lu);
1883 static inline struct dt_object *dt_object_child(struct dt_object *o)
1885 return container_of0(lu_object_next(&(o)->do_lu),
1886 struct dt_object, do_lu);
1890 * This is the general purpose transaction handle.
1891 * 1. Transaction Life Cycle
1892 * This transaction handle is allocated upon starting a new transaction,
1893 * and deallocated after this transaction is committed.
1894 * 2. Transaction Nesting
1895 * We do _NOT_ support nested transaction. So, every thread should only
1896 * have one active transaction, and a transaction only belongs to one
1897 * thread. Due to this, transaction handle need no reference count.
1898 * 3. Transaction & dt_object locking
1899 * dt_object locks should be taken inside transaction.
1900 * 4. Transaction & RPC
1901 * No RPC request should be issued inside transaction.
1904 /** the dt device on which the transactions are executed */
1905 struct dt_device *th_dev;
1907 /* point to the top thandle, XXX this is a bit hacky right now,
1908 * but normal device trans callback triggered by the bottom
1909 * device (OSP/OSD == sub thandle layer) needs to get the
1910 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1911 * top thandle here for now, will fix it when we have better
1912 * callback mechanism */
1913 struct thandle *th_top;
1915 /** the last operation result in this transaction.
1916 * this value is used in recovery */
1919 /** whether we need sync commit */
1920 unsigned int th_sync:1,
1921 /* local transation, no need to inform other layers */
1923 /* Whether we need wait the transaction to be submitted
1924 * (send to remote target) */
1926 /* complex transaction which will track updates on all targets,
1929 /* whether ignore quota */
1934 * Transaction call-backs.
1936 * These are invoked by osd (or underlying transaction engine) when
1937 * transaction changes state.
1939 * Call-backs are used by upper layers to modify transaction parameters and to
1940 * perform some actions on for each transaction state transition. Typical
1941 * example is mdt registering call-back to write into last-received file
1942 * before each transaction commit.
1944 struct dt_txn_callback {
1945 int (*dtc_txn_start)(const struct lu_env *env,
1946 struct thandle *txn, void *cookie);
1947 int (*dtc_txn_stop)(const struct lu_env *env,
1948 struct thandle *txn, void *cookie);
1951 struct list_head dtc_linkage;
1954 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1955 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1957 int dt_txn_hook_start(const struct lu_env *env,
1958 struct dt_device *dev, struct thandle *txn);
1959 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1961 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1964 * Callback function used for parsing path.
1965 * \see llo_store_resolve
1967 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1971 #define DT_MAX_PATH 1024
1973 int dt_path_parser(const struct lu_env *env,
1974 char *local, dt_entry_func_t entry_func,
1978 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1979 const char *path, struct lu_fid *fid);
1981 struct dt_object *dt_store_open(const struct lu_env *env,
1982 struct dt_device *dt,
1983 const char *dirname,
1984 const char *filename,
1985 struct lu_fid *fid);
1987 struct dt_object *dt_find_or_create(const struct lu_env *env,
1988 struct dt_device *dt,
1989 const struct lu_fid *fid,
1990 struct dt_object_format *dof,
1991 struct lu_attr *attr);
1993 struct dt_object *dt_locate_at(const struct lu_env *env,
1994 struct dt_device *dev,
1995 const struct lu_fid *fid,
1996 struct lu_device *top_dev,
1997 const struct lu_object_conf *conf);
1999 static inline struct dt_object *
2000 dt_locate(const struct lu_env *env, struct dt_device *dev,
2001 const struct lu_fid *fid)
2003 return dt_locate_at(env, dev, fid,
2004 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2007 static inline struct dt_object *
2008 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2010 struct lu_object *lo;
2012 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2013 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2014 return container_of(lo, struct dt_object, do_lu);
2019 static inline void dt_object_put(const struct lu_env *env,
2020 struct dt_object *dto)
2022 lu_object_put(env, &dto->do_lu);
2025 static inline void dt_object_put_nocache(const struct lu_env *env,
2026 struct dt_object *dto)
2028 lu_object_put_nocache(env, &dto->do_lu);
2031 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2032 const struct lu_fid *first_fid,
2033 struct local_oid_storage **los);
2034 void local_oid_storage_fini(const struct lu_env *env,
2035 struct local_oid_storage *los);
2036 int local_object_fid_generate(const struct lu_env *env,
2037 struct local_oid_storage *los,
2038 struct lu_fid *fid);
2039 int local_object_declare_create(const struct lu_env *env,
2040 struct local_oid_storage *los,
2041 struct dt_object *o,
2042 struct lu_attr *attr,
2043 struct dt_object_format *dof,
2044 struct thandle *th);
2045 int local_object_create(const struct lu_env *env,
2046 struct local_oid_storage *los,
2047 struct dt_object *o,
2048 struct lu_attr *attr, struct dt_object_format *dof,
2049 struct thandle *th);
2050 struct dt_object *local_file_find(const struct lu_env *env,
2051 struct local_oid_storage *los,
2052 struct dt_object *parent,
2054 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2055 struct local_oid_storage *los,
2056 struct dt_object *parent,
2057 const char *name, __u32 mode);
2058 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2059 struct dt_device *dt,
2060 const struct lu_fid *fid,
2061 struct dt_object *parent,
2065 local_index_find_or_create(const struct lu_env *env,
2066 struct local_oid_storage *los,
2067 struct dt_object *parent,
2068 const char *name, __u32 mode,
2069 const struct dt_index_features *ft);
2071 local_index_find_or_create_with_fid(const struct lu_env *env,
2072 struct dt_device *dt,
2073 const struct lu_fid *fid,
2074 struct dt_object *parent,
2075 const char *name, __u32 mode,
2076 const struct dt_index_features *ft);
2077 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2078 struct dt_object *parent, const char *name);
2080 static inline int dt_object_lock(const struct lu_env *env,
2081 struct dt_object *o, struct lustre_handle *lh,
2082 struct ldlm_enqueue_info *einfo,
2083 union ldlm_policy_data *policy)
2086 LASSERT(o->do_ops != NULL);
2087 LASSERT(o->do_ops->do_object_lock != NULL);
2088 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2091 static inline int dt_object_unlock(const struct lu_env *env,
2092 struct dt_object *o,
2093 struct ldlm_enqueue_info *einfo,
2094 union ldlm_policy_data *policy)
2097 LASSERT(o->do_ops != NULL);
2098 LASSERT(o->do_ops->do_object_unlock != NULL);
2099 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2102 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2103 const char *name, struct lu_fid *fid);
2105 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2106 __u64 start, __u64 end)
2110 LASSERT(o->do_ops->do_object_sync);
2111 return o->do_ops->do_object_sync(env, o, start, end);
2114 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2115 struct thandle *th);
2116 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2117 dt_obj_version_t version, struct thandle *th);
2118 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2121 int dt_read(const struct lu_env *env, struct dt_object *dt,
2122 struct lu_buf *buf, loff_t *pos);
2123 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2124 struct lu_buf *buf, loff_t *pos);
2125 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2126 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2127 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2128 union lu_page *lp, size_t nob,
2129 const struct dt_it_ops *iops,
2130 struct dt_it *it, __u32 attr, void *arg);
2131 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2132 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2134 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2135 struct idx_info *ii, const struct lu_rdpg *rdpg);
2137 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2138 struct dt_device *d)
2140 LASSERT(d->dd_ops->dt_trans_create);
2141 return d->dd_ops->dt_trans_create(env, d);
2144 static inline int dt_trans_start(const struct lu_env *env,
2145 struct dt_device *d, struct thandle *th)
2147 LASSERT(d->dd_ops->dt_trans_start);
2148 return d->dd_ops->dt_trans_start(env, d, th);
2151 /* for this transaction hooks shouldn't be called */
2152 static inline int dt_trans_start_local(const struct lu_env *env,
2153 struct dt_device *d, struct thandle *th)
2155 LASSERT(d->dd_ops->dt_trans_start);
2157 return d->dd_ops->dt_trans_start(env, d, th);
2160 static inline int dt_trans_stop(const struct lu_env *env,
2161 struct dt_device *d, struct thandle *th)
2163 LASSERT(d->dd_ops->dt_trans_stop);
2164 return d->dd_ops->dt_trans_stop(env, d, th);
2167 static inline int dt_trans_cb_add(struct thandle *th,
2168 struct dt_txn_commit_cb *dcb)
2170 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2171 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2172 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2177 static inline int dt_declare_record_write(const struct lu_env *env,
2178 struct dt_object *dt,
2179 const struct lu_buf *buf,
2185 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2186 LASSERT(th != NULL);
2187 LASSERT(dt->do_body_ops);
2188 LASSERT(dt->do_body_ops->dbo_declare_write);
2189 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2193 static inline int dt_declare_create(const struct lu_env *env,
2194 struct dt_object *dt,
2195 struct lu_attr *attr,
2196 struct dt_allocation_hint *hint,
2197 struct dt_object_format *dof,
2201 LASSERT(dt->do_ops);
2202 LASSERT(dt->do_ops->do_declare_create);
2204 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2205 return cfs_fail_err;
2207 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2210 static inline int dt_create(const struct lu_env *env,
2211 struct dt_object *dt,
2212 struct lu_attr *attr,
2213 struct dt_allocation_hint *hint,
2214 struct dt_object_format *dof,
2218 LASSERT(dt->do_ops);
2219 LASSERT(dt->do_ops->do_create);
2221 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2222 return cfs_fail_err;
2224 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2227 static inline int dt_declare_destroy(const struct lu_env *env,
2228 struct dt_object *dt,
2232 LASSERT(dt->do_ops);
2233 LASSERT(dt->do_ops->do_declare_destroy);
2235 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2236 return cfs_fail_err;
2238 return dt->do_ops->do_declare_destroy(env, dt, th);
2241 static inline int dt_destroy(const struct lu_env *env,
2242 struct dt_object *dt,
2246 LASSERT(dt->do_ops);
2247 LASSERT(dt->do_ops->do_destroy);
2249 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2250 return cfs_fail_err;
2252 return dt->do_ops->do_destroy(env, dt, th);
2255 static inline void dt_read_lock(const struct lu_env *env,
2256 struct dt_object *dt,
2260 LASSERT(dt->do_ops);
2261 LASSERT(dt->do_ops->do_read_lock);
2262 dt->do_ops->do_read_lock(env, dt, role);
2265 static inline void dt_write_lock(const struct lu_env *env,
2266 struct dt_object *dt,
2270 LASSERT(dt->do_ops);
2271 LASSERT(dt->do_ops->do_write_lock);
2272 dt->do_ops->do_write_lock(env, dt, role);
2275 static inline void dt_read_unlock(const struct lu_env *env,
2276 struct dt_object *dt)
2279 LASSERT(dt->do_ops);
2280 LASSERT(dt->do_ops->do_read_unlock);
2281 dt->do_ops->do_read_unlock(env, dt);
2284 static inline void dt_write_unlock(const struct lu_env *env,
2285 struct dt_object *dt)
2288 LASSERT(dt->do_ops);
2289 LASSERT(dt->do_ops->do_write_unlock);
2290 dt->do_ops->do_write_unlock(env, dt);
2293 static inline int dt_write_locked(const struct lu_env *env,
2294 struct dt_object *dt)
2297 LASSERT(dt->do_ops);
2298 LASSERT(dt->do_ops->do_write_locked);
2299 return dt->do_ops->do_write_locked(env, dt);
2302 static inline int dt_declare_attr_get(const struct lu_env *env,
2303 struct dt_object *dt)
2306 LASSERT(dt->do_ops);
2307 LASSERT(dt->do_ops->do_declare_attr_get);
2309 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2310 return cfs_fail_err;
2312 return dt->do_ops->do_declare_attr_get(env, dt);
2315 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2319 LASSERT(dt->do_ops);
2320 LASSERT(dt->do_ops->do_attr_get);
2322 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2323 return cfs_fail_err;
2325 return dt->do_ops->do_attr_get(env, dt, la);
2328 static inline int dt_declare_attr_set(const struct lu_env *env,
2329 struct dt_object *dt,
2330 const struct lu_attr *la,
2334 LASSERT(dt->do_ops);
2335 LASSERT(dt->do_ops->do_declare_attr_set);
2337 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2338 return cfs_fail_err;
2340 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2343 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2344 const struct lu_attr *la, struct thandle *th)
2347 LASSERT(dt->do_ops);
2348 LASSERT(dt->do_ops->do_attr_set);
2350 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2351 return cfs_fail_err;
2353 return dt->do_ops->do_attr_set(env, dt, la, th);
2356 static inline int dt_declare_ref_add(const struct lu_env *env,
2357 struct dt_object *dt, struct thandle *th)
2360 LASSERT(dt->do_ops);
2361 LASSERT(dt->do_ops->do_declare_ref_add);
2363 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2364 return cfs_fail_err;
2366 return dt->do_ops->do_declare_ref_add(env, dt, th);
2369 static inline int dt_ref_add(const struct lu_env *env,
2370 struct dt_object *dt, struct thandle *th)
2373 LASSERT(dt->do_ops);
2374 LASSERT(dt->do_ops->do_ref_add);
2376 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2377 return cfs_fail_err;
2379 return dt->do_ops->do_ref_add(env, dt, th);
2382 static inline int dt_declare_ref_del(const struct lu_env *env,
2383 struct dt_object *dt, struct thandle *th)
2386 LASSERT(dt->do_ops);
2387 LASSERT(dt->do_ops->do_declare_ref_del);
2389 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2390 return cfs_fail_err;
2392 return dt->do_ops->do_declare_ref_del(env, dt, th);
2395 static inline int dt_ref_del(const struct lu_env *env,
2396 struct dt_object *dt, struct thandle *th)
2399 LASSERT(dt->do_ops);
2400 LASSERT(dt->do_ops->do_ref_del);
2402 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2403 return cfs_fail_err;
2405 return dt->do_ops->do_ref_del(env, dt, th);
2408 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2409 struct niobuf_remote *rnb,
2410 struct niobuf_local *lnb, enum dt_bufs_type rw)
2413 LASSERT(d->do_body_ops);
2414 LASSERT(d->do_body_ops->dbo_bufs_get);
2415 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2416 rnb->rnb_len, lnb, rw);
2419 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2420 struct niobuf_local *lnb, int n)
2423 LASSERT(d->do_body_ops);
2424 LASSERT(d->do_body_ops->dbo_bufs_put);
2425 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2428 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2429 struct niobuf_local *lnb, int n)
2432 LASSERT(d->do_body_ops);
2433 LASSERT(d->do_body_ops->dbo_write_prep);
2434 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2437 static inline int dt_declare_write_commit(const struct lu_env *env,
2438 struct dt_object *d,
2439 struct niobuf_local *lnb,
2440 int n, struct thandle *th)
2442 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2443 LASSERT(th != NULL);
2444 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2448 static inline int dt_write_commit(const struct lu_env *env,
2449 struct dt_object *d, struct niobuf_local *lnb,
2450 int n, struct thandle *th)
2453 LASSERT(d->do_body_ops);
2454 LASSERT(d->do_body_ops->dbo_write_commit);
2455 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2458 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2459 struct niobuf_local *lnb, int n)
2462 LASSERT(d->do_body_ops);
2463 LASSERT(d->do_body_ops->dbo_read_prep);
2464 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2467 static inline int dt_declare_write(const struct lu_env *env,
2468 struct dt_object *dt,
2469 const struct lu_buf *buf, loff_t pos,
2473 LASSERT(dt->do_body_ops);
2474 LASSERT(dt->do_body_ops->dbo_declare_write);
2475 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2478 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2479 const struct lu_buf *buf, loff_t *pos,
2483 LASSERT(dt->do_body_ops);
2484 LASSERT(dt->do_body_ops->dbo_write);
2485 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2488 static inline int dt_declare_punch(const struct lu_env *env,
2489 struct dt_object *dt, __u64 start,
2490 __u64 end, struct thandle *th)
2493 LASSERT(dt->do_body_ops);
2494 LASSERT(dt->do_body_ops->dbo_declare_punch);
2495 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2498 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2499 __u64 start, __u64 end, struct thandle *th)
2502 LASSERT(dt->do_body_ops);
2503 LASSERT(dt->do_body_ops->dbo_punch);
2504 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2507 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2508 __u64 start, __u64 end, int advice)
2511 LASSERT(dt->do_body_ops);
2512 LASSERT(dt->do_body_ops->dbo_ladvise);
2513 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2516 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2520 if (d->do_body_ops == NULL)
2522 if (d->do_body_ops->dbo_fiemap_get == NULL)
2524 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2527 static inline int dt_statfs_info(const struct lu_env *env,
2528 struct dt_device *dev,
2529 struct obd_statfs *osfs,
2530 struct obd_statfs_info *info)
2533 LASSERT(dev->dd_ops);
2534 LASSERT(dev->dd_ops->dt_statfs);
2535 return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2538 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2539 struct obd_statfs *osfs)
2541 return dt_statfs_info(env, dev, osfs, NULL);
2544 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2548 LASSERT(dev->dd_ops);
2549 LASSERT(dev->dd_ops->dt_root_get);
2550 return dev->dd_ops->dt_root_get(env, dev, f);
2553 static inline void dt_conf_get(const struct lu_env *env,
2554 const struct dt_device *dev,
2555 struct dt_device_param *param)
2558 LASSERT(dev->dd_ops);
2559 LASSERT(dev->dd_ops->dt_conf_get);
2560 return dev->dd_ops->dt_conf_get(env, dev, param);
2563 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2566 LASSERT(dev->dd_ops);
2567 if (dev->dd_ops->dt_mnt_sb_get)
2568 return dev->dd_ops->dt_mnt_sb_get(dev);
2570 return ERR_PTR(-EOPNOTSUPP);
2573 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2576 LASSERT(dev->dd_ops);
2577 LASSERT(dev->dd_ops->dt_sync);
2578 return dev->dd_ops->dt_sync(env, dev);
2581 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2584 LASSERT(dev->dd_ops);
2585 LASSERT(dev->dd_ops->dt_ro);
2586 return dev->dd_ops->dt_ro(env, dev);
2589 static inline int dt_declare_insert(const struct lu_env *env,
2590 struct dt_object *dt,
2591 const struct dt_rec *rec,
2592 const struct dt_key *key,
2596 LASSERT(dt->do_index_ops);
2597 LASSERT(dt->do_index_ops->dio_declare_insert);
2599 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2600 return cfs_fail_err;
2602 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2605 static inline int dt_insert(const struct lu_env *env,
2606 struct dt_object *dt,
2607 const struct dt_rec *rec,
2608 const struct dt_key *key,
2612 LASSERT(dt->do_index_ops);
2613 LASSERT(dt->do_index_ops->dio_insert);
2615 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2616 return cfs_fail_err;
2618 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2621 static inline int dt_declare_xattr_del(const struct lu_env *env,
2622 struct dt_object *dt,
2627 LASSERT(dt->do_ops);
2628 LASSERT(dt->do_ops->do_declare_xattr_del);
2630 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2631 return cfs_fail_err;
2633 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2636 static inline int dt_xattr_del(const struct lu_env *env,
2637 struct dt_object *dt, const char *name,
2641 LASSERT(dt->do_ops);
2642 LASSERT(dt->do_ops->do_xattr_del);
2644 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2645 return cfs_fail_err;
2647 return dt->do_ops->do_xattr_del(env, dt, name, th);
2650 static inline int dt_declare_xattr_set(const struct lu_env *env,
2651 struct dt_object *dt,
2652 const struct lu_buf *buf,
2653 const char *name, int fl,
2657 LASSERT(dt->do_ops);
2658 LASSERT(dt->do_ops->do_declare_xattr_set);
2660 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2661 return cfs_fail_err;
2663 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2666 static inline int dt_xattr_set(const struct lu_env *env,
2667 struct dt_object *dt, const struct lu_buf *buf,
2668 const char *name, int fl, struct thandle *th)
2671 LASSERT(dt->do_ops);
2672 LASSERT(dt->do_ops->do_xattr_set);
2674 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2675 return cfs_fail_err;
2677 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2680 static inline int dt_declare_xattr_get(const struct lu_env *env,
2681 struct dt_object *dt,
2686 LASSERT(dt->do_ops);
2687 LASSERT(dt->do_ops->do_declare_xattr_get);
2689 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2690 return cfs_fail_err;
2692 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2695 static inline int dt_xattr_get(const struct lu_env *env,
2696 struct dt_object *dt, struct lu_buf *buf,
2700 LASSERT(dt->do_ops);
2701 LASSERT(dt->do_ops->do_xattr_get);
2703 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2704 return cfs_fail_err;
2706 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2709 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2710 const struct lu_buf *buf)
2713 LASSERT(dt->do_ops);
2714 LASSERT(dt->do_ops->do_xattr_list);
2716 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2717 return cfs_fail_err;
2719 return dt->do_ops->do_xattr_list(env, dt, buf);
2722 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2725 LASSERT(dt->do_ops);
2726 LASSERT(dt->do_ops->do_invalidate);
2728 return dt->do_ops->do_invalidate(env, dt);
2731 static inline int dt_declare_delete(const struct lu_env *env,
2732 struct dt_object *dt,
2733 const struct dt_key *key,
2737 LASSERT(dt->do_index_ops);
2738 LASSERT(dt->do_index_ops->dio_declare_delete);
2740 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2741 return cfs_fail_err;
2743 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2746 static inline int dt_delete(const struct lu_env *env,
2747 struct dt_object *dt,
2748 const struct dt_key *key,
2752 LASSERT(dt->do_index_ops);
2753 LASSERT(dt->do_index_ops->dio_delete);
2755 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2756 return cfs_fail_err;
2758 return dt->do_index_ops->dio_delete(env, dt, key, th);
2761 static inline int dt_commit_async(const struct lu_env *env,
2762 struct dt_device *dev)
2765 LASSERT(dev->dd_ops);
2766 LASSERT(dev->dd_ops->dt_commit_async);
2767 return dev->dd_ops->dt_commit_async(env, dev);
2770 static inline int dt_lookup(const struct lu_env *env,
2771 struct dt_object *dt,
2773 const struct dt_key *key)
2778 LASSERT(dt->do_index_ops);
2779 LASSERT(dt->do_index_ops->dio_lookup);
2781 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2782 return cfs_fail_err;
2784 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2792 static inline int dt_declare_layout_change(const struct lu_env *env,
2793 struct dt_object *o,
2794 struct md_layout_change *mlc,
2799 LASSERT(o->do_ops->do_declare_layout_change);
2800 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2803 static inline int dt_layout_change(const struct lu_env *env,
2804 struct dt_object *o,
2805 struct md_layout_change *mlc,
2810 LASSERT(o->do_ops->do_layout_change);
2811 return o->do_ops->do_layout_change(env, o, mlc, th);
2814 struct dt_find_hint {
2815 struct lu_fid *dfh_fid;
2816 struct dt_device *dfh_dt;
2817 struct dt_object *dfh_o;
2820 struct dt_insert_rec {
2822 const struct lu_fid *rec_fid;
2834 struct dt_thread_info {
2835 char dti_buf[DT_MAX_PATH];
2836 struct dt_find_hint dti_dfh;
2837 struct lu_attr dti_attr;
2838 struct lu_fid dti_fid;
2839 struct dt_object_format dti_dof;
2840 struct lustre_mdt_attrs dti_lma;
2841 struct lu_buf dti_lb;
2842 struct lu_object_conf dti_conf;
2844 struct dt_insert_rec dti_dt_rec;
2847 extern struct lu_context_key dt_key;
2849 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2851 struct dt_thread_info *dti;
2853 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2858 int dt_global_init(void);
2859 void dt_global_fini(void);
2860 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2861 const char *name, struct lprocfs_vars *list);
2862 int dt_tunables_fini(struct dt_device *dt);
2864 # ifdef CONFIG_PROC_FS
2865 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2866 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2867 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2868 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2869 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2870 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2871 # endif /* CONFIG_PROC_FS */
2873 #endif /* __LUSTRE_DT_OBJECT_H */