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/
32 #ifndef __LUSTRE_DT_OBJECT_H
33 #define __LUSTRE_DT_OBJECT_H
36 * Sub-class of lu_object with methods common for "data" objects in OST stack.
38 * Data objects behave like regular files: you can read/write them, get and
39 * set their attributes. Implementation of dt interface is supposed to
40 * implement some form of garbage collection, normally reference counting
43 * Examples: osd (lustre/osd) is an implementation of dt interface.
47 #include <obd_support.h>
49 * super-class definitions.
51 #include <lu_object.h>
53 #include <libcfs/libcfs.h>
56 struct proc_dir_entry;
62 struct dt_index_features;
65 struct ldlm_enqueue_info;
68 MNTOPT_USERXATTR = 0x00000001,
69 MNTOPT_ACL = 0x00000002,
72 struct dt_device_param {
73 unsigned ddp_max_name_len;
74 unsigned ddp_max_nlink;
75 unsigned ddp_symlink_max;
77 unsigned ddp_max_ea_size;
78 unsigned ddp_mount_type;
79 unsigned long long ddp_maxbytes;
80 /* per-inode space consumption */
82 /* maximum number of blocks in an extent */
83 unsigned ddp_max_extent_blks;
84 /* per-extent insertion overhead to be used by client for grant
86 unsigned int ddp_extent_tax;
87 unsigned int ddp_brw_size; /* optimal RPC size */
88 /* T10PI checksum type, zero if not supported */
89 enum cksum_types ddp_t10_cksum_type;
90 bool ddp_has_lseek_data_hole;
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 * The unit of \a count is byte for block or inodes for metadata.
321 * If \a count > 0, reserve quota in advance of an operation that
322 * changes the quota assignment, such as chgrp() or rename() into
323 * a directory with a different group ID.
325 * If \a count < 0, free the reserved quota previously.
327 * \param[in] env execution environment for this thread
328 * \param[in] dev the bottom OSD device to reserve quota
329 * \param[in] type quota type (LQUOTA_RES_DT or LQUOTA_RES_MD)
330 * \param[in] uid quota uid
331 * \param[in] gid quota gid
332 * \param[in] count space (bytes or inodes) to reserve or free
333 * \param[in] md true for inode, false for block
335 * \retval 0 on success
336 * \retval negative negated errno on error
338 int (*dt_reserve_or_free_quota)(const struct lu_env *env,
339 struct dt_device *dev,
340 enum quota_type type, __u64 uid,
341 __u64 gid, __s64 count, bool md);
344 struct dt_index_features {
345 /** required feature flags from enum dt_index_flags */
347 /** minimal required key size */
348 size_t dif_keysize_min;
349 /** maximal required key size, 0 if no limit */
350 size_t dif_keysize_max;
351 /** minimal required record size */
352 size_t dif_recsize_min;
353 /** maximal required record size, 0 if no limit */
354 size_t dif_recsize_max;
355 /** pointer size for record */
359 enum dt_index_flags {
360 /** index supports variable sized keys */
361 DT_IND_VARKEY = BIT(0),
362 /** index supports variable sized records */
363 DT_IND_VARREC = BIT(1),
364 /** index can be modified */
365 DT_IND_UPDATE = BIT(2),
366 /** index supports records with non-unique (duplicate) keys */
367 DT_IND_NONUNQ = BIT(3),
369 * index support fixed-size keys sorted with natural numerical way
370 * and is able to return left-side value if no exact value found
372 DT_IND_RANGE = BIT(4),
375 /* for dt_read_lock() and dt_write_lock() object lock rule */
376 enum dt_object_role {
386 * Features, required from index to support file system directories (mapping
389 extern const struct dt_index_features dt_directory_features;
390 extern const struct dt_index_features dt_otable_features;
391 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
392 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
393 extern const struct dt_index_features dt_lfsck_namespace_features;
395 /* index features supported by the accounting objects */
396 extern const struct dt_index_features dt_acct_features;
398 /* index features supported by the quota global indexes */
399 extern const struct dt_index_features dt_quota_glb_features;
401 /* index features supported by the quota slave indexes */
402 extern const struct dt_index_features dt_quota_slv_features;
404 /* index features supported by the nodemap index */
405 extern const struct dt_index_features dt_nodemap_features;
408 * This is a general purpose dt allocation hint.
409 * It now contains the parent object.
410 * It can contain any allocation hint in the future.
412 struct dt_allocation_hint {
413 struct dt_object *dah_parent;
414 const void *dah_eadata;
418 int dah_append_stripes;
420 char *dah_append_pool;
424 * object type specifier.
427 enum dt_format_type {
432 /** for special index */
434 /** for symbolic link */
439 * object format specifier.
441 struct dt_object_format {
442 /** type for dt object */
443 enum dt_format_type dof_type;
453 * special index need feature as parameter to create
457 const struct dt_index_features *di_feat;
462 enum dt_format_type dt_mode_to_dft(__u32 mode);
464 typedef __u64 dt_obj_version_t;
466 union ldlm_policy_data;
468 struct md_layout_change;
471 * A dt_object provides common operations to create and destroy
472 * objects and to manage regular and extended attributes.
474 struct dt_object_operations {
476 * Get read lock on object.
478 * Read lock is compatible with other read locks, so it's shared.
479 * Read lock is not compatible with write lock which is exclusive.
480 * The lock is blocking and can't be used from an interrupt context.
482 * \param[in] env execution environment for this thread
483 * \param[in] dt object to lock for reading
484 * \param[in] role a hint to debug locks (see kernel's mutexes)
486 void (*do_read_lock)(const struct lu_env *env,
487 struct dt_object *dt,
491 * Get write lock on object.
493 * Write lock is exclusive and cannot be shared. The lock is blocking
494 * and can't be used from an interrupt context.
496 * \param[in] env execution environment for this thread
497 * \param[in] dt object to lock for writing
498 * \param[in] role a hint to debug locks (see kernel's mutexes)
501 void (*do_write_lock)(const struct lu_env *env,
502 struct dt_object *dt,
508 * \param[in] env execution environment for this thread
509 * \param[in] dt object
511 void (*do_read_unlock)(const struct lu_env *env,
512 struct dt_object *dt);
515 * Release write lock.
517 * \param[in] env execution environment for this thread
518 * \param[in] dt object
520 void (*do_write_unlock)(const struct lu_env *env,
521 struct dt_object *dt);
524 * Check whether write lock is held.
526 * The caller can learn whether write lock is held on the object
528 * \param[in] env execution environment for this thread
529 * \param[in] dt object
531 * \retval 0 no write lock
532 * \retval 1 write lock is held
534 int (*do_write_locked)(const struct lu_env *env,
535 struct dt_object *dt);
538 * Declare intention to request reqular attributes.
540 * Notity the underlying filesystem that the caller may request regular
541 * attributes with ->do_attr_get() soon. This allows OSD to implement
542 * prefetching logic in an object-oriented manner. The implementation
543 * can be noop. This method should avoid expensive delays such as
544 * waiting on disk I/O, otherwise the goal of enabling a performance
545 * optimization would be defeated.
547 * \param[in] env execution environment for this thread
548 * \param[in] dt object
550 * \retval 0 on success
551 * \retval negative negated errno on error
553 int (*do_declare_attr_get)(const struct lu_env *env,
554 struct dt_object *dt);
557 * Return regular attributes.
559 * The object must exist. Currently all the attributes should be
560 * returned, but in the future this can be improved so that only
561 * a selected set is returned. This can improve performance as in
562 * some cases attributes are stored in different places and
563 * getting them all can be an iterative and expensive process.
565 * \param[in] env execution environment for this thread
566 * \param[in] dt object
567 * \param[out] attr attributes to fill
569 * \retval 0 on success
570 * \retval negative negated errno on error
572 int (*do_attr_get)(const struct lu_env *env,
573 struct dt_object *dt,
574 struct lu_attr *attr);
577 * Declare intention to change regular object's attributes.
579 * Notify the underlying filesystem that the regular attributes may
580 * change in this transaction. This enables the layer below to prepare
581 * resources (e.g. journal credits in ext4). This method should be
582 * called between creating the transaction and starting it. Note that
583 * the la_valid field of \a attr specifies which attributes will change.
584 * The object need not exist.
586 * \param[in] env execution environment for this thread
587 * \param[in] dt object
588 * \param[in] attr attributes to change specified in attr.la_valid
589 * \param[in] th transaction handle
591 * \retval 0 on success
592 * \retval negative negated errno on error
594 int (*do_declare_attr_set)(const struct lu_env *env,
595 struct dt_object *dt,
596 const struct lu_attr *attr,
600 * Change regular attributes.
602 * Change regular attributes in the given transaction. Note only
603 * attributes flagged by attr.la_valid change. The object must
604 * exist. If the layer implementing this method is responsible for
605 * quota, then the method should maintain object accounting for the
606 * given credentials when la_uid/la_gid changes.
608 * \param[in] env execution environment for this thread
609 * \param[in] dt object
610 * \param[in] attr new attributes to apply
611 * \param[in] th transaction handle
613 * \retval 0 on success
614 * \retval negative negated errno on error
616 int (*do_attr_set)(const struct lu_env *env,
617 struct dt_object *dt,
618 const struct lu_attr *attr,
622 * Declare intention to request extented attribute.
624 * Notify the underlying filesystem that the caller may request extended
625 * attribute with ->do_xattr_get() soon. This allows OSD to implement
626 * prefetching logic in an object-oriented manner. The implementation
627 * can be noop. This method should avoid expensive delays such as
628 * waiting on disk I/O, otherwise the goal of enabling a performance
629 * optimization would be defeated.
631 * \param[in] env execution environment for this thread
632 * \param[in] dt object
633 * \param[in] buf unused, may be removed in the future
634 * \param[in] name name of the extended attribute
636 * \retval 0 on success
637 * \retval negative negated errno on error
639 int (*do_declare_xattr_get)(const struct lu_env *env,
640 struct dt_object *dt,
645 * Return a value of an extended attribute.
647 * The object must exist. If the buffer is NULL, then the method
648 * must return the size of the value.
650 * \param[in] env execution environment for this thread
651 * \param[in] dt object
652 * \param[out] buf buffer in which to store the value
653 * \param[in] name name of the extended attribute
655 * \retval 0 on success
656 * \retval -ERANGE if \a buf is too small
657 * \retval negative negated errno on error
658 * \retval positive value's size if \a buf is NULL or has zero size
660 int (*do_xattr_get)(const struct lu_env *env,
661 struct dt_object *dt,
666 * Declare intention to change an extended attribute.
668 * Notify the underlying filesystem that the extended attribute may
669 * change in this transaction. This enables the layer below to prepare
670 * resources (e.g. journal credits in ext4). This method should be
671 * called between creating the transaction and starting it. The object
674 * \param[in] env execution environment for this thread
675 * \param[in] dt object
676 * \param[in] buf buffer storing new value of the attribute
677 * \param[in] name name of the attribute
678 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
679 * LU_XATTR_REPLACE - fail if EA doesn't exist
680 * \param[in] th transaction handle
682 * \retval 0 on success
683 * \retval negative negated errno on error
685 int (*do_declare_xattr_set)(const struct lu_env *env,
686 struct dt_object *dt,
687 const struct lu_buf *buf,
693 * Set an extended attribute.
695 * Change or replace the specified extended attribute (EA).
696 * The flags passed in \a fl dictate whether the EA is to be
697 * created or replaced, as follows.
698 * LU_XATTR_CREATE - fail if EA exists
699 * LU_XATTR_REPLACE - fail if EA doesn't exist
700 * The object must exist.
702 * \param[in] env execution environment for this thread
703 * \param[in] dt object
704 * \param[in] buf buffer storing new value of the attribute
705 * \param[in] name name of the attribute
706 * \param[in] fl flags indicating EA creation or replacement
707 * \param[in] th transaction handle
709 * \retval 0 on success
710 * \retval negative negated errno on error
712 int (*do_xattr_set)(const struct lu_env *env,
713 struct dt_object *dt,
714 const struct lu_buf *buf,
720 * Declare intention to delete an extended attribute.
722 * Notify the underlying filesystem that the extended attribute may
723 * be deleted in this transaction. This enables the layer below to
724 * prepare resources (e.g. journal credits in ext4). This method
725 * should be called between creating the transaction and starting it.
726 * The object need not exist.
728 * \param[in] env execution environment for this thread
729 * \param[in] dt object
730 * \param[in] name name of the attribute
731 * \param[in] th transaction handle
733 * \retval 0 on success
734 * \retval negative negated errno on error
736 int (*do_declare_xattr_del)(const struct lu_env *env,
737 struct dt_object *dt,
742 * Delete an extended attribute.
744 * This method deletes the specified extended attribute. The object
747 * \param[in] env execution environment for this thread
748 * \param[in] dt object
749 * \param[in] name name of the attribute
750 * \param[in] th transaction handle
752 * \retval 0 on success
753 * \retval negative negated errno on error
755 int (*do_xattr_del)(const struct lu_env *env,
756 struct dt_object *dt,
761 * Return a list of the extended attributes.
763 * Fills the passed buffer with a list of the extended attributes
764 * found in the object. The names are separated with '\0'.
765 * The object must exist.
767 * \param[in] env execution environment for this thread
768 * \param[in] dt object
769 * \param[out] buf buffer to put the list in
771 * \retval positive bytes used/required in the buffer
772 * \retval negative negated errno on error
774 int (*do_xattr_list)(const struct lu_env *env,
775 struct dt_object *dt,
776 const struct lu_buf *buf);
779 * Prepare allocation hint for a new object.
781 * This method is used by the caller to inform OSD of the parent-child
782 * relationship between two objects and enable efficient object
783 * allocation. Filled allocation hint will be passed to ->do_create()
786 * \param[in] env execution environment for this thread
787 * \param[out] ah allocation hint
788 * \param[in] parent parent object (can be NULL)
789 * \param[in] child child object
790 * \param[in] _mode type of the child object
792 void (*do_ah_init)(const struct lu_env *env,
793 struct dt_allocation_hint *ah,
794 struct dt_object *parent,
795 struct dt_object *child,
799 * Declare intention to create a new object.
801 * Notify the underlying filesystem that the object may be created
802 * in this transaction. This enables the layer below to prepare
803 * resources (e.g. journal credits in ext4). This method should be
804 * called between creating the transaction and starting it.
806 * If the layer implementing this method is responsible for quota,
807 * then the method should reserve an object for the given credentials
808 * and return an error if quota is over. If object creation later
809 * fails for some reason, then the reservation should be released
810 * properly (usually in ->dt_trans_stop()).
812 * \param[in] env execution environment for this thread
813 * \param[in] dt object
814 * \param[in] attr attributes of the new object
815 * \param[in] hint allocation hint
816 * \param[in] dof object format
817 * \param[in] th transaction handle
819 * \retval 0 on success
820 * \retval negative negated errno on error
822 int (*do_declare_create)(const struct lu_env *env,
823 struct dt_object *dt,
824 struct lu_attr *attr,
825 struct dt_allocation_hint *hint,
826 struct dt_object_format *dof,
832 * The method creates the object passed with the specified attributes
833 * and object format. Object allocation procedure can use information
834 * stored in the allocation hint. Different object formats are supported
835 * (see enum dt_format_type and struct dt_object_format) depending on
836 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
837 * in the LU-object header attributes.
839 * If the layer implementing this method is responsible for quota,
840 * then the method should maintain object accounting for the given
843 * \param[in] env execution environment for this thread
844 * \param[in] dt object
845 * \param[in] attr attributes of the new object
846 * \param[in] hint allocation hint
847 * \param[in] dof object format
848 * \param[in] th transaction handle
850 * \retval 0 on success
851 * \retval negative negated errno on error
853 int (*do_create)(const struct lu_env *env,
854 struct dt_object *dt,
855 struct lu_attr *attr,
856 struct dt_allocation_hint *hint,
857 struct dt_object_format *dof,
861 * Declare intention to destroy an object.
863 * Notify the underlying filesystem that the object may be destroyed
864 * in this transaction. This enables the layer below to prepare
865 * resources (e.g. journal credits in ext4). This method should be
866 * called between creating the transaction and starting it. The object
869 * \param[in] env execution environment for this thread
870 * \param[in] dt object
871 * \param[in] th transaction handle
873 * \retval 0 on success
874 * \retval negative negated errno on error
876 int (*do_declare_destroy)(const struct lu_env *env,
877 struct dt_object *dt,
883 * This method destroys the object and all the resources associated
884 * with the object (data, key/value pairs, extended attributes, etc).
885 * The object must exist. If destroy is successful, then flag
886 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
887 * instance of in-core object. Any subsequent access to the same FID
888 * should get another instance with no LOHA_EXIST flag set.
890 * If the layer implementing this method is responsible for quota,
891 * then the method should maintain object accounting for the given
894 * \param[in] env execution environment for this thread
895 * \param[in] dt object
896 * \param[in] th transaction handle
898 * \retval 0 on success
899 * \retval negative negated errno on error
901 int (*do_destroy)(const struct lu_env *env,
902 struct dt_object *dt,
906 * Try object as an index.
908 * Announce that this object is going to be used as an index. This
909 * operation checks that object supports indexing operations and
910 * installs appropriate dt_index_operations vector on success.
911 * Also probes for features. Operation is successful if all required
912 * features are supported. It's not possible to access the object
913 * with index methods before ->do_index_try() returns success.
915 * \param[in] env execution environment for this thread
916 * \param[in] dt object
917 * \param[in] feat index features
919 * \retval 0 on success
920 * \retval negative negated errno on error
922 int (*do_index_try)(const struct lu_env *env,
923 struct dt_object *dt,
924 const struct dt_index_features *feat);
927 * Declare intention to increment nlink count.
929 * Notify the underlying filesystem that the nlink regular attribute
930 * be changed in this transaction. This enables the layer below to
931 * prepare resources (e.g. journal credits in ext4). This method
932 * should be called between creating the transaction and starting it.
933 * The object need not exist.
935 * \param[in] env execution environment for this thread
936 * \param[in] dt object
937 * \param[in] th transaction handle
939 * \retval 0 on success
940 * \retval negative negated errno on error
942 int (*do_declare_ref_add)(const struct lu_env *env,
943 struct dt_object *dt,
949 * Increment nlink (from the regular attributes set) in the given
950 * transaction. Note the absolute limit for nlink should be learnt
951 * from struct dt_device_param::ddp_max_nlink. The object must exist.
953 * \param[in] env execution environment for this thread
954 * \param[in] dt object
955 * \param[in] th transaction handle
957 * \retval 0 on success
958 * \retval negative negated errno on error
960 int (*do_ref_add)(const struct lu_env *env,
961 struct dt_object *dt, struct thandle *th);
964 * Declare intention to decrement nlink count.
966 * Notify the underlying filesystem that the nlink regular attribute
967 * be changed in this transaction. This enables the layer below to
968 * prepare resources (e.g. journal credits in ext4). This method
969 * should be called between creating the transaction and starting it.
970 * The object need not exist.
972 * \param[in] env execution environment for this thread
973 * \param[in] dt object
974 * \param[in] th transaction handle
976 * \retval 0 on success
977 * \retval negative negated errno on error
979 int (*do_declare_ref_del)(const struct lu_env *env,
980 struct dt_object *dt,
986 * Decrement nlink (from the regular attributes set) in the given
987 * transaction. The object must exist.
989 * \param[in] env execution environment for this thread
990 * \param[in] dt object
991 * \param[in] th transaction handle
993 * \retval 0 on success
994 * \retval negative negated errno on error
996 int (*do_ref_del)(const struct lu_env *env,
997 struct dt_object *dt,
1003 * The method is called to sync specified range of the object to a
1004 * persistent storage. The control is returned once the operation is
1005 * complete. The difference from ->do_sync() is that the object can
1006 * be in-sync with the persistent storage (nothing to flush), then
1007 * the method returns quickly with no I/O overhead. So, this method
1008 * should be preferred over ->do_sync() where possible. Also note that
1009 * if the object isn't clean, then some disk filesystems will call
1010 * ->do_sync() to maintain overall consistency, in which case it's
1011 * still very expensive.
1013 * \param[in] env execution environment for this thread
1014 * \param[in] dt object
1015 * \param[in] start start of the range to sync
1016 * \param[in] end end of the range to sync
1018 * \retval 0 on success
1019 * \retval negative negated errno on error
1021 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
1022 __u64 start, __u64 end);
1027 * Lock object(s) using Distributed Lock Manager (LDLM).
1029 * Get LDLM locks for the object. Currently used to lock "remote"
1030 * objects in DNE configuration - a service running on MDTx needs
1031 * to lock an object on MDTy.
1033 * \param[in] env execution environment for this thread
1034 * \param[in] dt object
1035 * \param[out] lh lock handle, sometimes used, sometimes not
1036 * \param[in] einfo ldlm callbacks, locking type and mode
1037 * \param[out] einfo private data to be passed to unlock later
1038 * \param[in] policy inodebits data
1040 * \retval 0 on success
1041 * \retval negative negated errno on error
1043 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1044 struct lustre_handle *lh,
1045 struct ldlm_enqueue_info *einfo,
1046 union ldlm_policy_data *policy);
1051 * Release LDLM lock(s) granted with ->do_object_lock().
1053 * \param[in] env execution environment for this thread
1054 * \param[in] dt object
1055 * \param[in] einfo lock handles, from ->do_object_lock()
1056 * \param[in] policy inodebits data
1058 * \retval 0 on success
1059 * \retval negative negated errno on error
1061 int (*do_object_unlock)(const struct lu_env *env,
1062 struct dt_object *dt,
1063 struct ldlm_enqueue_info *einfo,
1064 union ldlm_policy_data *policy);
1067 * Invalidate attribute cache.
1069 * This method invalidate attribute cache of the object, which is on OSP
1072 * \param[in] env execution envionment for this thread
1073 * \param[in] dt object
1075 * \retval 0 on success
1076 * \retval negative negated errno on error
1078 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1081 * Check object stale state.
1085 * \param[in] dt object
1087 * \retval true for stale object
1088 * \retval false for not stale object
1090 bool (*do_check_stale)(struct dt_object *dt);
1093 * Declare intention to instaintiate extended layout component.
1095 * \param[in] env execution environment
1096 * \param[in] dt DT object
1097 * \param[in] layout data structure to describe the changes to
1098 * the DT object's layout
1099 * \param[in] buf buffer containing client's lovea or empty
1102 * \retval -ne error code
1104 int (*do_declare_layout_change)(const struct lu_env *env,
1105 struct dt_object *dt,
1106 struct md_layout_change *mlc,
1107 struct thandle *th);
1110 * Client is trying to write to un-instantiated layout component.
1112 * \param[in] env execution environment
1113 * \param[in] dt DT object
1114 * \param[in] layout data structure to describe the changes to
1115 * the DT object's layout
1116 * \param[in] buf buffer containing client's lovea or empty
1119 * \retval -ne error code
1121 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1122 struct md_layout_change *mlc,
1123 struct thandle *th);
1127 DT_BUFS_TYPE_READ = 0x0000,
1128 DT_BUFS_TYPE_WRITE = 0x0001,
1129 DT_BUFS_TYPE_READAHEAD = 0x0002,
1130 DT_BUFS_TYPE_LOCAL = 0x0004,
1134 * Per-dt-object operations on "file body" - unstructure raw data.
1136 struct dt_body_operations {
1140 * Read unstructured data from an existing regular object.
1141 * Only data before attr.la_size is returned.
1143 * \param[in] env execution environment for this thread
1144 * \param[in] dt object
1145 * \param[out] buf buffer (including size) to copy data in
1146 * \param[in] pos position in the object to start
1147 * \param[out] pos original value of \a pos + bytes returned
1149 * \retval positive bytes read on success
1150 * \retval negative negated errno on error
1152 ssize_t (*dbo_read)(const struct lu_env *env,
1153 struct dt_object *dt,
1158 * Declare intention to write data to object.
1160 * Notify the underlying filesystem that data may be written in
1161 * this transaction. This enables the layer below to prepare resources
1162 * (e.g. journal credits in ext4). This method should be called
1163 * between creating the transaction and starting it. The object need
1164 * not exist. If the layer implementing this method is responsible for
1165 * quota, then the method should reserve space for the given credentials
1166 * and return an error if quota is over. If the write later fails
1167 * for some reason, then the reserve should be released properly
1168 * (usually in ->dt_trans_stop()).
1170 * \param[in] env execution environment for this thread
1171 * \param[in] dt object
1172 * \param[in] buf buffer (including size) to copy data from
1173 * \param[in] pos position in the object to start
1174 * \param[in] th transaction handle
1176 * \retval 0 on success
1177 * \retval negative negated errno on error
1179 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1180 struct dt_object *dt,
1181 const struct lu_buf *buf,
1183 struct thandle *th);
1186 * Write unstructured data to regular existing object.
1188 * The method allocates space and puts data in. Also, the method should
1189 * maintain attr.la_size properly. Partial writes are possible.
1191 * If the layer implementing this method is responsible for quota,
1192 * then the method should maintain space accounting for the given
1195 * \param[in] env execution environment for this thread
1196 * \param[in] dt object
1197 * \param[in] buf buffer (including size) to copy data from
1198 * \param[in] pos position in the object to start
1199 * \param[out] pos \a pos + bytes written
1200 * \param[in] th transaction handle
1202 * \retval positive bytes written on success
1203 * \retval negative negated errno on error
1205 ssize_t (*dbo_write)(const struct lu_env *env,
1206 struct dt_object *dt,
1207 const struct lu_buf *buf,
1209 struct thandle *th);
1212 * Return buffers for data.
1214 * This method is used to access data with no copying. It's so-called
1215 * zero-copy I/O. The method returns the descriptors for the internal
1216 * buffers where data are managed by the disk filesystem. For example,
1217 * pagecache in case of ext4 or ARC with ZFS. Then other components
1218 * (e.g. networking) can transfer data from or to the buffers with no
1219 * additional copying.
1221 * The method should fill an array of struct niobuf_local, where
1222 * each element describes a full or partial page for data at specific
1223 * offset. The caller should use page/lnb_page_offset/len to find data
1224 * at object's offset lnb_file_offset.
1226 * The memory referenced by the descriptors can't change its purpose
1227 * until the complementary ->dbo_bufs_put() is called. The caller should
1228 * specify if the buffers are used to read or modify data so that OSD
1229 * can decide how to initialize the buffers: bring all the data for
1230 * reads or just bring partial buffers for write. Note: the method does
1231 * not check whether output array is large enough.
1233 * \param[in] env execution environment for this thread
1234 * \param[in] dt object
1235 * \param[in] pos position in the object to start
1236 * \param[in] len size of region in bytes
1237 * \param[out] lb array of descriptors to fill
1238 * \param[in] maxlnb max slots in @lnb array
1239 * \param[in] rw 0 if used to read, 1 if used for write
1241 * \retval positive number of descriptors on success
1242 * \retval negative negated errno on error
1244 int (*dbo_bufs_get)(const struct lu_env *env,
1245 struct dt_object *dt,
1248 struct niobuf_local *lb,
1250 enum dt_bufs_type rw);
1253 * Release reference granted by ->dbo_bufs_get().
1255 * Release the reference granted by the previous ->dbo_bufs_get().
1256 * Note the references are counted.
1258 * \param[in] env execution environment for this thread
1259 * \param[in] dt object
1260 * \param[out] lb array of descriptors to fill
1261 * \param[in] nr size of the array
1263 * \retval 0 on success
1264 * \retval negative negated errno on error
1266 int (*dbo_bufs_put)(const struct lu_env *env,
1267 struct dt_object *dt,
1268 struct niobuf_local *lb,
1272 * Prepare buffers for reading.
1274 * The method is called on the given buffers to fill them with data
1275 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1276 * caller should be able to get few buffers for discontiguous regions
1277 * using few calls to ->dbo_bufs_get() and then request them all for
1278 * the preparation with a single call, so that OSD can fire many I/Os
1279 * to run concurrently. It's up to the specific OSD whether to implement
1280 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1281 * prepare data for every requested region individually.
1283 * \param[in] env execution environment for this thread
1284 * \param[in] dt object
1285 * \param[in] lnb array of buffer descriptors
1286 * \param[in] nr size of the array
1288 * \retval 0 on success
1289 * \retval negative negated errno on error
1291 int (*dbo_read_prep)(const struct lu_env *env,
1292 struct dt_object *dt,
1293 struct niobuf_local *lnb,
1297 * Prepare buffers for write.
1299 * This method is called on the given buffers to ensure the partial
1300 * buffers contain correct data. The underlying idea is the same as
1301 * in ->db_read_prep().
1303 * \param[in] env execution environment for this thread
1304 * \param[in] dt object
1305 * \param[in] lb array of buffer descriptors
1306 * \param[in] nr size of the array
1308 * \retval 0 on success
1309 * \retval negative negated errno on error
1311 int (*dbo_write_prep)(const struct lu_env *env,
1312 struct dt_object *dt,
1313 struct niobuf_local *lb,
1317 * Declare intention to write data stored in the buffers.
1319 * Notify the underlying filesystem that data may be written in
1320 * this transaction. This enables the layer below to prepare resources
1321 * (e.g. journal credits in ext4). This method should be called
1322 * between creating the transaction and starting it.
1324 * If the layer implementing this method is responsible for quota,
1325 * then the method should be reserving a space for the given
1326 * credentials and return an error if quota is exceeded. If the write
1327 * later fails for some reason, then the reserve should be released
1328 * properly (usually in ->dt_trans_stop()).
1330 * \param[in] env execution environment for this thread
1331 * \param[in] dt object
1332 * \param[in] lb array of descriptors
1333 * \param[in] nr size of the array
1334 * \param[in] th transaction handle
1336 * \retval 0 on success
1337 * \retval negative negated errno on error
1339 int (*dbo_declare_write_commit)(const struct lu_env *env,
1340 struct dt_object *dt,
1341 struct niobuf_local *lb,
1343 struct thandle *th);
1346 * Write to existing object.
1348 * This method is used to write data to a persistent storage using
1349 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1350 * data into the buffers using own mechanisms (e.g. direct transfer
1351 * from a NIC). The method should maintain attr.la_size. Also,
1352 * attr.la_blocks should be maintained but this can be done in lazy
1353 * manner, when actual allocation happens.
1355 * If the layer implementing this method is responsible for quota,
1356 * then the method should maintain space accounting for the given
1359 * user_size parameter is the apparent size of the file, ie the size
1360 * of the clear text version of the file. It can differ from the actual
1361 * amount of valuable data received when a file is encrypted,
1362 * because encrypted pages always contain PAGE_SIZE bytes of data,
1363 * even if clear text data is only a few bytes.
1364 * In case of encrypted file, apparent size will be stored as the inode
1365 * size, so that servers return to clients an object size they can use
1366 * to determine clear text size.
1368 * \param[in] env execution environment for this thread
1369 * \param[in] dt object
1370 * \param[in] lb array of descriptors for the buffers
1371 * \param[in] nr size of the array
1372 * \param[in] th transaction handle
1373 * \param[in] user_size apparent size
1375 * \retval 0 on success
1376 * \retval negative negated errno on error
1378 int (*dbo_write_commit)(const struct lu_env *env,
1379 struct dt_object *dt,
1380 struct niobuf_local *lb,
1386 * Return logical to physical block mapping for a given extent
1388 * \param[in] env execution environment for this thread
1389 * \param[in] dt object
1390 * \param[in] fm describe the region to map and the output buffer
1391 * see the details in include/linux/fiemap.h
1393 * \retval 0 on success
1394 * \retval negative negated errno on error
1396 int (*dbo_fiemap_get)(const struct lu_env *env,
1397 struct dt_object *dt,
1401 * Declare intention to deallocate space from an object.
1403 * Notify the underlying filesystem that space may be deallocated in
1404 * this transactions. This enables the layer below to prepare resources
1405 * (e.g. journal credits in ext4). This method should be called between
1406 * creating the transaction and starting it. The object need not exist.
1408 * \param[in] env execution environment for this thread
1409 * \param[in] dt object
1410 * \param[in] start the start of the region to deallocate
1411 * \param[in] end the end of the region to deallocate
1412 * \param[in] th transaction handle
1414 * \retval 0 on success
1415 * \retval negative negated errno on error
1417 int (*dbo_declare_punch)(const struct lu_env *env,
1418 struct dt_object *dt,
1421 struct thandle *th);
1424 * Deallocate specified region in an object.
1426 * This method is used to deallocate (release) space possibly consumed
1427 * by the given region of the object. If the layer implementing this
1428 * method is responsible for quota, then the method should maintain
1429 * space accounting for the given credentials.
1431 * \param[in] env execution environment for this thread
1432 * \param[in] dt object
1433 * \param[in] start the start of the region to deallocate
1434 * \param[in] end the end of the region to deallocate
1435 * \param[in] th transaction handle
1437 * \retval 0 on success
1438 * \retval negative negated errno on error
1440 int (*dbo_punch)(const struct lu_env *env,
1441 struct dt_object *dt,
1444 struct thandle *th);
1446 * Give advices on specified region in an object.
1448 * This method is used to give advices about access pattern on an
1449 * given region of the object. The disk filesystem understands
1450 * the advices and tunes cache/read-ahead policies.
1452 * \param[in] env execution environment for this thread
1453 * \param[in] dt object
1454 * \param[in] start the start of the region affected
1455 * \param[in] end the end of the region affected
1456 * \param[in] advice advice type
1458 * \retval 0 on success
1459 * \retval negative negated errno on error
1461 int (*dbo_ladvise)(const struct lu_env *env,
1462 struct dt_object *dt,
1465 enum lu_ladvise_type advice);
1468 * Declare intention to preallocate space for an object
1470 * \param[in] env execution environment for this thread
1471 * \param[in] dt object
1472 * \param[in] th transaction handle
1474 * \retval 0 on success
1475 * \retval negative negated errno on error
1477 int (*dbo_declare_fallocate)(const struct lu_env *env,
1478 struct dt_object *dt, __u64 start,
1479 __u64 end, int mode, struct thandle *th);
1481 * Allocate specified region for an object
1483 * \param[in] env execution environment for this thread
1484 * \param[in] dt object
1485 * \param[in] start the start of the region to allocate
1486 * \param[in] end the end of the region to allocate
1487 * \param[in] mode fallocate mode
1488 * \param[in] th transaction handle
1490 * \retval 0 on success
1491 * \retval negative negated errno on error
1493 int (*dbo_fallocate)(const struct lu_env *env,
1494 struct dt_object *dt,
1498 struct thandle *th);
1500 * Do SEEK_HOLE/SEEK_DATA request on object
1502 * \param[in] env execution environment for this thread
1503 * \param[in] dt object
1504 * \param[in] offset the offset to start seek from
1505 * \param[in] whence seek mode, SEEK_HOLE or SEEK_DATA
1507 * \retval hole/data offset on success
1508 * \retval negative negated errno on error
1510 loff_t (*dbo_lseek)(const struct lu_env *env, struct dt_object *dt,
1511 loff_t offset, int whence);
1515 * Incomplete type of index record.
1520 * Incomplete type of index key.
1525 * Incomplete type of dt iterator.
1530 * Per-dt-object operations on object as index. Index is a set of key/value
1531 * pairs abstracted from an on-disk representation. An index supports the
1532 * number of operations including lookup by key, insert and delete. Also,
1533 * an index can be iterated to find the pairs one by one, from a beginning
1534 * or specified point.
1536 struct dt_index_operations {
1538 * Lookup in an index by key.
1540 * The method returns a value for the given key. Key/value format
1541 * and size should have been negotiated with ->do_index_try() before.
1542 * Thus it's the caller's responsibility to provide the method with
1543 * proper key and big enough buffer. No external locking is required,
1544 * all the internal consistency should be implemented by the method
1545 * or lower layers. The object should should have been created with
1546 * type DFT_INDEX or DFT_DIR.
1548 * \param[in] env execution environment for this thread
1549 * \param[in] dt object
1550 * \param[out] rec buffer where value will be stored
1551 * \param[in] key key
1553 * \retval 0 on success
1554 * \retval -ENOENT if key isn't found
1555 * \retval negative negated errno on error
1557 int (*dio_lookup)(const struct lu_env *env,
1558 struct dt_object *dt,
1560 const struct dt_key *key);
1563 * Declare intention to insert a key/value into an index.
1565 * Notify the underlying filesystem that new key/value may be inserted
1566 * in this transaction. This enables the layer below to prepare
1567 * resources (e.g. journal credits in ext4). This method should be
1568 * called between creating the transaction and starting it. key/value
1569 * format and size is subject to ->do_index_try().
1571 * \param[in] env execution environment for this thread
1572 * \param[in] dt object
1573 * \param[in] rec buffer storing value
1574 * \param[in] key key
1575 * \param[in] th transaction handle
1577 * \retval 0 on success
1578 * \retval negative negated errno on error
1580 int (*dio_declare_insert)(const struct lu_env *env,
1581 struct dt_object *dt,
1582 const struct dt_rec *rec,
1583 const struct dt_key *key,
1584 struct thandle *th);
1587 * Insert a new key/value pair into an index.
1589 * The method inserts specified key/value pair into the given index
1590 * object. The internal consistency is maintained by the method or
1591 * the functionality below. The format and size of key/value should
1592 * have been negotiated before using ->do_index_try(), no additional
1593 * information can be specified to the method. The keys are unique
1596 * \param[in] env execution environment for this thread
1597 * \param[in] dt object
1598 * \param[in] rec buffer storing value
1599 * \param[in] key key
1600 * \param[in] th transaction handle
1602 * \retval 0 on success
1603 * \retval negative negated errno on error
1605 int (*dio_insert)(const struct lu_env *env,
1606 struct dt_object *dt,
1607 const struct dt_rec *rec,
1608 const struct dt_key *key,
1609 struct thandle *th);
1612 * Declare intention to delete a key/value from an index.
1614 * Notify the underlying filesystem that key/value may be deleted in
1615 * this transaction. This enables the layer below to prepare resources
1616 * (e.g. journal credits in ext4). This method should be called
1617 * between creating the transaction and starting it. Key/value format
1618 * and size is subject to ->do_index_try(). The object need not exist.
1620 * \param[in] env execution environment for this thread
1621 * \param[in] dt object
1622 * \param[in] key key
1623 * \param[in] th transaction handle
1625 * \retval 0 on success
1626 * \retval negative negated errno on error
1628 int (*dio_declare_delete)(const struct lu_env *env,
1629 struct dt_object *dt,
1630 const struct dt_key *key,
1631 struct thandle *th);
1634 * Delete key/value pair from an index.
1636 * The method deletes specified key and corresponding value from the
1637 * given index object. The internal consistency is maintained by the
1638 * method or the functionality below. The format and size of the key
1639 * should have been negotiated before using ->do_index_try(), no
1640 * additional information can be specified to the method.
1642 * \param[in] env execution environment for this thread
1643 * \param[in] dt object
1644 * \param[in] key key
1645 * \param[in] th transaction handle
1647 * \retval 0 on success
1648 * \retval negative negated errno on error
1650 int (*dio_delete)(const struct lu_env *env,
1651 struct dt_object *dt,
1652 const struct dt_key *key,
1653 struct thandle *th);
1656 * Iterator interface.
1658 * Methods to iterate over an existing index, list the keys stored and
1659 * associated values, get key/value size, etc.
1663 * Allocate and initialize new iterator.
1665 * The iterator is a handler to be used in the subsequent
1666 * methods to access index's content. Note the position is
1667 * not defined at this point and should be initialized with
1668 * ->get() or ->load() method.
1670 * \param[in] env execution environment for this thread
1671 * \param[in] dt object
1672 * \param[in] attr ask the iterator to return part of
1673 the records, see LUDA_* for details
1675 * \retval pointer iterator pointer on success
1676 * \retval ERR_PTR(errno) on error
1678 struct dt_it *(*init)(const struct lu_env *env,
1679 struct dt_object *dt,
1685 * Release the specified iterator and all the resources
1686 * associated (e.g. the object, index cache, etc).
1688 * \param[in] env execution environment for this thread
1689 * \param[in] di iterator to release
1691 void (*fini)(const struct lu_env *env,
1695 * Move position of iterator.
1697 * Move the position of the specified iterator to the specified
1700 * \param[in] env execution environment for this thread
1701 * \param[in] di iterator
1702 * \param[in] key key to position to
1704 * \retval 0 if exact key is found
1705 * \retval 1 if at the record with least key
1706 * not larger than the key
1707 * \retval negative negated errno on error
1709 int (*get)(const struct lu_env *env,
1711 const struct dt_key *key);
1716 * Complimentary method for dt_it_ops::get() above. Some
1717 * implementation can increase a reference on the iterator in
1718 * dt_it_ops::get(). So the caller should be able to release
1719 * with dt_it_ops::put().
1721 * \param[in] env execution environment for this thread
1722 * \param[in] di iterator
1724 void (*put)(const struct lu_env *env,
1728 * Move to next record.
1730 * Moves the position of the iterator to a next record
1732 * \param[in] env execution environment for this thread
1733 * \param[in] di iterator
1735 * \retval 1 if no more records
1736 * \retval 0 on success, the next record is found
1737 * \retval negative negated errno on error
1739 int (*next)(const struct lu_env *env,
1745 * Returns a pointer to a buffer containing the key of the
1746 * record at the current position. The pointer is valid and
1747 * retains data until ->get(), ->load() and ->fini() methods
1750 * \param[in] env execution environment for this thread
1751 * \param[in] di iterator
1753 * \retval pointer to key on success
1754 * \retval ERR_PTR(errno) on error
1756 struct dt_key *(*key)(const struct lu_env *env,
1757 const struct dt_it *di);
1762 * Returns size of the key at the current position.
1764 * \param[in] env execution environment for this thread
1765 * \param[in] di iterator
1767 * \retval key's size on success
1768 * \retval negative negated errno on error
1770 int (*key_size)(const struct lu_env *env,
1771 const struct dt_it *di);
1776 * Stores the value of the record at the current position. The
1777 * buffer must be big enough (as negotiated with
1778 * ->do_index_try() or ->rec_size()). The caller can specify
1779 * she is interested only in part of the record, using attr
1780 * argument (see LUDA_* definitions for the details).
1782 * \param[in] env execution environment for this thread
1783 * \param[in] di iterator
1784 * \param[out] rec buffer to store value in
1785 * \param[in] attr specify part of the value to copy
1787 * \retval 0 on success
1788 * \retval negative negated errno on error
1790 int (*rec)(const struct lu_env *env,
1791 const struct dt_it *di,
1796 * Return record size.
1798 * Returns size of the record at the current position. The
1799 * \a attr can be used to specify only the parts of the record
1800 * needed to be returned. (see LUDA_* definitions for the
1803 * \param[in] env execution environment for this thread
1804 * \param[in] di iterator
1805 * \param[in] attr part of the record to return
1807 * \retval record's size on success
1808 * \retval negative negated errno on error
1810 int (*rec_size)(const struct lu_env *env,
1811 const struct dt_it *di,
1815 * Return a cookie (hash).
1817 * Returns the cookie (usually hash) of the key at the current
1818 * position. This allows the caller to resume iteration at this
1819 * position later. The exact value is specific to implementation
1820 * and should not be interpreted by the caller.
1822 * \param[in] env execution environment for this thread
1823 * \param[in] di iterator
1825 * \retval cookie/hash of the key
1827 __u64 (*store)(const struct lu_env *env,
1828 const struct dt_it *di);
1831 * Initialize position using cookie/hash.
1833 * Initializes the current position of the iterator to one
1834 * described by the cookie/hash as returned by ->store()
1837 * \param[in] env execution environment for this thread
1838 * \param[in] di iterator
1839 * \param[in] hash cookie/hash value
1841 * \retval positive if current position points to
1842 * record with least cookie not larger
1844 * \retval 0 if current position matches cookie
1845 * \retval negative negated errno on error
1847 int (*load)(const struct lu_env *env,
1848 const struct dt_it *di,
1854 int (*key_rec)(const struct lu_env *env,
1855 const struct dt_it *di,
1860 enum dt_otable_it_valid {
1861 DOIV_ERROR_HANDLE = 0x0001,
1862 DOIV_DRYRUN = 0x0002,
1865 enum dt_otable_it_flags {
1866 /* Exit when fail. */
1867 DOIF_FAILOUT = 0x0001,
1869 /* Reset iteration position to the device beginning. */
1870 DOIF_RESET = 0x0002,
1872 /* There is up layer component uses the iteration. */
1873 DOIF_OUTUSED = 0x0004,
1875 /* Check only without repairing. */
1876 DOIF_DRYRUN = 0x0008,
1879 /* otable based iteration needs to use the common DT iteration APIs.
1880 * To initialize the iteration, it needs call dio_it::init() firstly.
1881 * Here is how the otable based iteration should prepare arguments to
1882 * call dt_it_ops::init().
1884 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1885 * is composed of two parts:
1886 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1887 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1888 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1891 struct lu_device dd_lu_dev;
1892 const struct dt_device_operations *dd_ops;
1895 * List of dt_txn_callback (see below). This is not protected in any
1896 * way, because callbacks are supposed to be added/deleted only during
1897 * single-threaded start-up shut-down procedures.
1899 struct list_head dd_txn_callbacks;
1900 unsigned int dd_record_fid_accessed:1,
1903 /* sysfs and debugfs handling */
1904 struct dentry *dd_debugfs_entry;
1906 const struct attribute **dd_def_attrs;
1907 struct kobject dd_kobj;
1908 struct kobj_type dd_ktype;
1909 struct completion dd_kobj_unregister;
1912 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1913 void dt_device_fini(struct dt_device *dev);
1915 static inline int lu_device_is_dt(const struct lu_device *d)
1917 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1920 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1922 LASSERT(lu_device_is_dt(l));
1923 return container_of_safe(l, struct dt_device, dd_lu_dev);
1927 struct lu_object do_lu;
1928 const struct dt_object_operations *do_ops;
1929 const struct dt_body_operations *do_body_ops;
1930 const struct dt_index_operations *do_index_ops;
1934 * In-core representation of per-device local object OID storage
1936 struct local_oid_storage {
1937 /* all initialized llog systems on this node linked by this */
1938 struct list_head los_list;
1940 /* how many handle's reference this los has */
1941 atomic_t los_refcount;
1942 struct dt_device *los_dev;
1943 struct dt_object *los_obj;
1945 /* data used to generate new fids */
1946 struct mutex los_id_lock;
1951 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1953 return &d->dd_lu_dev;
1956 static inline struct dt_object *lu2dt(struct lu_object *l)
1958 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1959 return container_of_safe(l, struct dt_object, do_lu);
1962 int dt_object_init(struct dt_object *obj,
1963 struct lu_object_header *h, struct lu_device *d);
1965 void dt_object_fini(struct dt_object *obj);
1967 static inline int dt_object_exists(const struct dt_object *dt)
1969 return lu_object_exists(&dt->do_lu);
1972 static inline int dt_object_remote(const struct dt_object *dt)
1974 return lu_object_remote(&dt->do_lu);
1977 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1979 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1980 return container_of_safe(o, struct dt_object, do_lu);
1983 static inline struct dt_object *dt_object_child(struct dt_object *o)
1985 return container_of(lu_object_next(&(o)->do_lu),
1986 struct dt_object, do_lu);
1989 struct dt_quota_reserve_rec {
1990 enum quota_type qrr_type;
1991 union lquota_id qrr_id;
1996 * This is the general purpose transaction handle.
1997 * 1. Transaction Life Cycle
1998 * This transaction handle is allocated upon starting a new transaction,
1999 * and deallocated after this transaction is committed.
2000 * 2. Transaction Nesting
2001 * We do _NOT_ support nested transaction. So, every thread should only
2002 * have one active transaction, and a transaction only belongs to one
2003 * thread. Due to this, transaction handle need no reference count.
2004 * 3. Transaction & dt_object locking
2005 * dt_object locks should be taken inside transaction.
2006 * 4. Transaction & RPC
2007 * No RPC request should be issued inside transaction.
2010 /** the dt device on which the transactions are executed */
2011 struct dt_device *th_dev;
2013 /* point to the top thandle, XXX this is a bit hacky right now,
2014 * but normal device trans callback triggered by the bottom
2015 * device (OSP/OSD == sub thandle layer) needs to get the
2016 * top_thandle (see dt_txn_hook_start/stop()), so we put the
2017 * top thandle here for now, will fix it when we have better
2018 * callback mechanism */
2019 struct thandle *th_top;
2021 /* reserved quota for this handle */
2022 struct dt_quota_reserve_rec th_reserved_quota;
2024 /** the last operation result in this transaction.
2025 * this value is used in recovery */
2028 /** whether we need sync commit */
2029 unsigned int th_sync:1,
2030 /* local transation, no need to inform other layers */
2032 /* Whether we need wait the transaction to be submitted
2033 * (send to remote target) */
2035 /* complex transaction which will track updates on all targets,
2038 /* whether ignore quota */
2040 /* whether restart transaction */
2045 * Transaction call-backs.
2047 * These are invoked by osd (or underlying transaction engine) when
2048 * transaction changes state.
2050 * Call-backs are used by upper layers to modify transaction parameters and to
2051 * perform some actions on for each transaction state transition. Typical
2052 * example is mdt registering call-back to write into last-received file
2053 * before each transaction commit.
2055 struct dt_txn_callback {
2056 int (*dtc_txn_start)(const struct lu_env *env,
2057 struct thandle *txn, void *cookie);
2058 int (*dtc_txn_stop)(const struct lu_env *env,
2059 struct thandle *txn, void *cookie);
2062 struct list_head dtc_linkage;
2065 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
2066 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
2068 int dt_txn_hook_start(const struct lu_env *env,
2069 struct dt_device *dev, struct thandle *txn);
2070 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
2072 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
2075 * Callback function used for parsing path.
2076 * \see llo_store_resolve
2078 typedef int (*dt_entry_func_t)(const struct lu_env *env,
2082 #define DT_MAX_PATH 1024
2084 int dt_path_parser(const struct lu_env *env,
2085 char *local, dt_entry_func_t entry_func,
2089 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
2090 const char *path, struct lu_fid *fid);
2092 struct dt_object *dt_store_open(const struct lu_env *env,
2093 struct dt_device *dt,
2094 const char *dirname,
2095 const char *filename,
2096 struct lu_fid *fid);
2098 struct dt_object *dt_find_or_create(const struct lu_env *env,
2099 struct dt_device *dt,
2100 const struct lu_fid *fid,
2101 struct dt_object_format *dof,
2102 struct lu_attr *attr);
2104 struct dt_object *dt_locate_at(const struct lu_env *env,
2105 struct dt_device *dev,
2106 const struct lu_fid *fid,
2107 struct lu_device *top_dev,
2108 const struct lu_object_conf *conf);
2110 static inline struct dt_object *
2111 dt_locate(const struct lu_env *env, struct dt_device *dev,
2112 const struct lu_fid *fid)
2114 return dt_locate_at(env, dev, fid,
2115 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2118 static inline struct dt_object *
2119 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2121 struct lu_object *lo;
2123 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2124 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2125 return container_of(lo, struct dt_object, do_lu);
2130 static inline void dt_object_put(const struct lu_env *env,
2131 struct dt_object *dto)
2133 lu_object_put(env, &dto->do_lu);
2136 static inline void dt_object_put_nocache(const struct lu_env *env,
2137 struct dt_object *dto)
2139 lu_object_put_nocache(env, &dto->do_lu);
2142 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2143 const struct lu_fid *first_fid,
2144 struct local_oid_storage **los);
2145 void local_oid_storage_fini(const struct lu_env *env,
2146 struct local_oid_storage *los);
2147 int local_object_fid_generate(const struct lu_env *env,
2148 struct local_oid_storage *los,
2149 struct lu_fid *fid);
2150 int local_object_declare_create(const struct lu_env *env,
2151 struct local_oid_storage *los,
2152 struct dt_object *o,
2153 struct lu_attr *attr,
2154 struct dt_object_format *dof,
2155 struct thandle *th);
2156 int local_object_create(const struct lu_env *env,
2157 struct local_oid_storage *los,
2158 struct dt_object *o,
2159 struct lu_attr *attr, struct dt_object_format *dof,
2160 struct thandle *th);
2161 struct dt_object *local_file_find(const struct lu_env *env,
2162 struct local_oid_storage *los,
2163 struct dt_object *parent,
2165 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2166 struct local_oid_storage *los,
2167 struct dt_object *parent,
2168 const char *name, __u32 mode);
2169 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2170 struct dt_device *dt,
2171 const struct lu_fid *fid,
2172 struct dt_object *parent,
2176 local_index_find_or_create(const struct lu_env *env,
2177 struct local_oid_storage *los,
2178 struct dt_object *parent,
2179 const char *name, __u32 mode,
2180 const struct dt_index_features *ft);
2182 local_index_find_or_create_with_fid(const struct lu_env *env,
2183 struct dt_device *dt,
2184 const struct lu_fid *fid,
2185 struct dt_object *parent,
2186 const char *name, __u32 mode,
2187 const struct dt_index_features *ft);
2188 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2189 struct dt_object *parent, const char *name);
2191 static inline int dt_object_lock(const struct lu_env *env,
2192 struct dt_object *o, struct lustre_handle *lh,
2193 struct ldlm_enqueue_info *einfo,
2194 union ldlm_policy_data *policy)
2197 LASSERT(o->do_ops != NULL);
2198 LASSERT(o->do_ops->do_object_lock != NULL);
2199 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2202 static inline int dt_object_unlock(const struct lu_env *env,
2203 struct dt_object *o,
2204 struct ldlm_enqueue_info *einfo,
2205 union ldlm_policy_data *policy)
2208 LASSERT(o->do_ops != NULL);
2209 LASSERT(o->do_ops->do_object_unlock != NULL);
2210 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2213 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2214 const char *name, struct lu_fid *fid);
2216 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2217 __u64 start, __u64 end)
2221 LASSERT(o->do_ops->do_object_sync);
2222 return o->do_ops->do_object_sync(env, o, start, end);
2225 static inline int dt_fid_alloc(const struct lu_env *env,
2226 struct dt_device *d,
2228 struct lu_object *parent,
2229 const struct lu_name *name)
2231 struct lu_device *l = dt2lu_dev(d);
2233 return l->ld_ops->ldo_fid_alloc(env, l, fid, parent, name);
2236 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2237 struct thandle *th);
2238 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2239 dt_obj_version_t version, struct thandle *th);
2240 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2243 int dt_read(const struct lu_env *env, struct dt_object *dt,
2244 struct lu_buf *buf, loff_t *pos);
2245 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2246 struct lu_buf *buf, loff_t *pos);
2247 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2248 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2249 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2250 union lu_page *lp, size_t nob,
2251 const struct dt_it_ops *iops,
2252 struct dt_it *it, __u32 attr, void *arg);
2253 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2254 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2256 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2257 struct idx_info *ii, const struct lu_rdpg *rdpg);
2259 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2260 struct dt_device *d)
2262 LASSERT(d->dd_ops->dt_trans_create);
2263 return d->dd_ops->dt_trans_create(env, d);
2266 static inline int dt_trans_start(const struct lu_env *env,
2267 struct dt_device *d, struct thandle *th)
2269 LASSERT(d->dd_ops->dt_trans_start);
2270 return d->dd_ops->dt_trans_start(env, d, th);
2273 /* for this transaction hooks shouldn't be called */
2274 static inline int dt_trans_start_local(const struct lu_env *env,
2275 struct dt_device *d, struct thandle *th)
2277 LASSERT(d->dd_ops->dt_trans_start);
2279 return d->dd_ops->dt_trans_start(env, d, th);
2282 static inline int dt_trans_stop(const struct lu_env *env,
2283 struct dt_device *d, struct thandle *th)
2285 LASSERT(d->dd_ops->dt_trans_stop);
2286 return d->dd_ops->dt_trans_stop(env, d, th);
2289 static inline int dt_trans_cb_add(struct thandle *th,
2290 struct dt_txn_commit_cb *dcb)
2292 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2293 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2294 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2299 static inline int dt_declare_record_write(const struct lu_env *env,
2300 struct dt_object *dt,
2301 const struct lu_buf *buf,
2307 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2308 LASSERT(th != NULL);
2309 LASSERTF(dt->do_body_ops, DFID" doesn't exit\n",
2310 PFID(lu_object_fid(&dt->do_lu)));
2311 LASSERT(dt->do_body_ops->dbo_declare_write);
2312 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2316 static inline int dt_declare_create(const struct lu_env *env,
2317 struct dt_object *dt,
2318 struct lu_attr *attr,
2319 struct dt_allocation_hint *hint,
2320 struct dt_object_format *dof,
2324 LASSERT(dt->do_ops);
2325 LASSERT(dt->do_ops->do_declare_create);
2327 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2328 return cfs_fail_err;
2330 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2333 static inline int dt_create(const struct lu_env *env,
2334 struct dt_object *dt,
2335 struct lu_attr *attr,
2336 struct dt_allocation_hint *hint,
2337 struct dt_object_format *dof,
2341 LASSERT(dt->do_ops);
2342 LASSERT(dt->do_ops->do_create);
2344 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2345 return cfs_fail_err;
2347 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2350 static inline int dt_declare_destroy(const struct lu_env *env,
2351 struct dt_object *dt,
2355 LASSERT(dt->do_ops);
2356 LASSERT(dt->do_ops->do_declare_destroy);
2358 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2359 return cfs_fail_err;
2361 return dt->do_ops->do_declare_destroy(env, dt, th);
2364 static inline int dt_destroy(const struct lu_env *env,
2365 struct dt_object *dt,
2369 LASSERT(dt->do_ops);
2370 LASSERT(dt->do_ops->do_destroy);
2372 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2373 return cfs_fail_err;
2375 return dt->do_ops->do_destroy(env, dt, th);
2378 static inline void dt_read_lock(const struct lu_env *env,
2379 struct dt_object *dt,
2383 LASSERT(dt->do_ops);
2384 LASSERT(dt->do_ops->do_read_lock);
2385 dt->do_ops->do_read_lock(env, dt, role);
2388 static inline void dt_write_lock(const struct lu_env *env,
2389 struct dt_object *dt,
2393 LASSERT(dt->do_ops);
2394 LASSERT(dt->do_ops->do_write_lock);
2395 dt->do_ops->do_write_lock(env, dt, role);
2398 static inline void dt_read_unlock(const struct lu_env *env,
2399 struct dt_object *dt)
2402 LASSERT(dt->do_ops);
2403 LASSERT(dt->do_ops->do_read_unlock);
2404 dt->do_ops->do_read_unlock(env, dt);
2407 static inline void dt_write_unlock(const struct lu_env *env,
2408 struct dt_object *dt)
2411 LASSERT(dt->do_ops);
2412 LASSERT(dt->do_ops->do_write_unlock);
2413 dt->do_ops->do_write_unlock(env, dt);
2416 static inline int dt_write_locked(const struct lu_env *env,
2417 struct dt_object *dt)
2420 LASSERT(dt->do_ops);
2421 LASSERT(dt->do_ops->do_write_locked);
2422 return dt->do_ops->do_write_locked(env, dt);
2425 static inline bool dt_object_stale(struct dt_object *dt)
2428 LASSERT(dt->do_ops);
2429 LASSERT(dt->do_ops->do_check_stale);
2431 return dt->do_ops->do_check_stale(dt);
2434 static inline int dt_declare_attr_get(const struct lu_env *env,
2435 struct dt_object *dt)
2438 LASSERT(dt->do_ops);
2439 LASSERT(dt->do_ops->do_declare_attr_get);
2441 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2442 return cfs_fail_err;
2444 return dt->do_ops->do_declare_attr_get(env, dt);
2447 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2451 LASSERT(dt->do_ops);
2452 LASSERT(dt->do_ops->do_attr_get);
2454 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2455 return cfs_fail_err;
2457 return dt->do_ops->do_attr_get(env, dt, la);
2460 static inline int dt_declare_attr_set(const struct lu_env *env,
2461 struct dt_object *dt,
2462 const struct lu_attr *la,
2466 LASSERT(dt->do_ops);
2467 LASSERT(dt->do_ops->do_declare_attr_set);
2469 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2470 return cfs_fail_err;
2472 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2475 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2476 const struct lu_attr *la, struct thandle *th)
2479 LASSERT(dt->do_ops);
2480 LASSERT(dt->do_ops->do_attr_set);
2482 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2483 return cfs_fail_err;
2485 return dt->do_ops->do_attr_set(env, dt, la, th);
2488 static inline int dt_declare_ref_add(const struct lu_env *env,
2489 struct dt_object *dt, struct thandle *th)
2492 LASSERT(dt->do_ops);
2493 LASSERT(dt->do_ops->do_declare_ref_add);
2495 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2496 return cfs_fail_err;
2498 return dt->do_ops->do_declare_ref_add(env, dt, th);
2501 static inline int dt_ref_add(const struct lu_env *env,
2502 struct dt_object *dt, struct thandle *th)
2505 LASSERT(dt->do_ops);
2506 LASSERT(dt->do_ops->do_ref_add);
2508 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2509 return cfs_fail_err;
2511 return dt->do_ops->do_ref_add(env, dt, th);
2514 static inline int dt_declare_ref_del(const struct lu_env *env,
2515 struct dt_object *dt, struct thandle *th)
2518 LASSERT(dt->do_ops);
2519 LASSERT(dt->do_ops->do_declare_ref_del);
2521 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2522 return cfs_fail_err;
2524 return dt->do_ops->do_declare_ref_del(env, dt, th);
2527 static inline int dt_ref_del(const struct lu_env *env,
2528 struct dt_object *dt, struct thandle *th)
2531 LASSERT(dt->do_ops);
2532 LASSERT(dt->do_ops->do_ref_del);
2534 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2535 return cfs_fail_err;
2537 return dt->do_ops->do_ref_del(env, dt, th);
2540 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2541 struct niobuf_remote *rnb,
2542 struct niobuf_local *lnb, int maxlnb,
2543 enum dt_bufs_type rw)
2546 LASSERT(d->do_body_ops);
2547 LASSERT(d->do_body_ops->dbo_bufs_get);
2548 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2549 rnb->rnb_len, lnb, maxlnb, rw);
2552 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2553 struct niobuf_local *lnb, int n)
2556 LASSERT(d->do_body_ops);
2557 LASSERT(d->do_body_ops->dbo_bufs_put);
2558 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2561 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2562 struct niobuf_local *lnb, int n)
2565 LASSERT(d->do_body_ops);
2566 LASSERT(d->do_body_ops->dbo_write_prep);
2567 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2570 static inline int dt_declare_write_commit(const struct lu_env *env,
2571 struct dt_object *d,
2572 struct niobuf_local *lnb,
2573 int n, struct thandle *th)
2575 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2576 LASSERT(th != NULL);
2577 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2581 static inline int dt_write_commit(const struct lu_env *env,
2582 struct dt_object *d, struct niobuf_local *lnb,
2583 int n, struct thandle *th, __u64 size)
2586 LASSERT(d->do_body_ops);
2587 LASSERT(d->do_body_ops->dbo_write_commit);
2588 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th, size);
2591 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2592 struct niobuf_local *lnb, int n)
2595 LASSERT(d->do_body_ops);
2596 LASSERT(d->do_body_ops->dbo_read_prep);
2597 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2600 static inline int dt_declare_write(const struct lu_env *env,
2601 struct dt_object *dt,
2602 const struct lu_buf *buf, loff_t pos,
2606 LASSERT(dt->do_body_ops);
2607 LASSERT(dt->do_body_ops->dbo_declare_write);
2608 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2611 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2612 const struct lu_buf *buf, loff_t *pos,
2616 LASSERT(dt->do_body_ops);
2617 LASSERT(dt->do_body_ops->dbo_write);
2618 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2621 static inline int dt_declare_punch(const struct lu_env *env,
2622 struct dt_object *dt, __u64 start,
2623 __u64 end, struct thandle *th)
2626 LASSERT(dt->do_body_ops);
2627 LASSERT(dt->do_body_ops->dbo_declare_punch);
2628 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2631 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2632 __u64 start, __u64 end, struct thandle *th)
2635 LASSERT(dt->do_body_ops);
2636 LASSERT(dt->do_body_ops->dbo_punch);
2637 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2640 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2641 __u64 start, __u64 end, int advice)
2644 LASSERT(dt->do_body_ops);
2645 LASSERT(dt->do_body_ops->dbo_ladvise);
2646 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2649 static inline int dt_declare_fallocate(const struct lu_env *env,
2650 struct dt_object *dt, __u64 start,
2651 __u64 end, int mode, struct thandle *th)
2654 if (!dt->do_body_ops)
2656 LASSERT(dt->do_body_ops);
2657 LASSERT(dt->do_body_ops->dbo_declare_fallocate);
2658 return dt->do_body_ops->dbo_declare_fallocate(env, dt, start, end,
2662 static inline int dt_falloc(const struct lu_env *env, struct dt_object *dt,
2663 __u64 start, __u64 end, int mode,
2667 if (!dt->do_body_ops)
2669 LASSERT(dt->do_body_ops);
2670 LASSERT(dt->do_body_ops->dbo_fallocate);
2671 return dt->do_body_ops->dbo_fallocate(env, dt, start, end, mode, th);
2674 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2678 if (d->do_body_ops == NULL)
2680 if (d->do_body_ops->dbo_fiemap_get == NULL)
2682 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2685 static inline loff_t dt_lseek(const struct lu_env *env, struct dt_object *d,
2686 loff_t offset, int whence)
2689 if (d->do_body_ops == NULL)
2691 if (d->do_body_ops->dbo_lseek == NULL)
2693 return d->do_body_ops->dbo_lseek(env, d, offset, whence);
2696 static inline int dt_statfs_info(const struct lu_env *env,
2697 struct dt_device *dev,
2698 struct obd_statfs *osfs,
2699 struct obd_statfs_info *info)
2702 LASSERT(dev->dd_ops);
2703 LASSERT(dev->dd_ops->dt_statfs);
2704 return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2707 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2708 struct obd_statfs *osfs)
2710 return dt_statfs_info(env, dev, osfs, NULL);
2713 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2717 LASSERT(dev->dd_ops);
2718 LASSERT(dev->dd_ops->dt_root_get);
2719 return dev->dd_ops->dt_root_get(env, dev, f);
2722 static inline void dt_conf_get(const struct lu_env *env,
2723 const struct dt_device *dev,
2724 struct dt_device_param *param)
2727 LASSERT(dev->dd_ops);
2728 LASSERT(dev->dd_ops->dt_conf_get);
2729 return dev->dd_ops->dt_conf_get(env, dev, param);
2732 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2735 LASSERT(dev->dd_ops);
2736 if (dev->dd_ops->dt_mnt_sb_get)
2737 return dev->dd_ops->dt_mnt_sb_get(dev);
2739 return ERR_PTR(-EOPNOTSUPP);
2742 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2745 LASSERT(dev->dd_ops);
2746 LASSERT(dev->dd_ops->dt_sync);
2747 return dev->dd_ops->dt_sync(env, dev);
2750 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2753 LASSERT(dev->dd_ops);
2754 LASSERT(dev->dd_ops->dt_ro);
2755 return dev->dd_ops->dt_ro(env, dev);
2758 static inline int dt_declare_insert(const struct lu_env *env,
2759 struct dt_object *dt,
2760 const struct dt_rec *rec,
2761 const struct dt_key *key,
2765 LASSERT(dt->do_index_ops);
2766 LASSERT(dt->do_index_ops->dio_declare_insert);
2768 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2769 return cfs_fail_err;
2771 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2774 static inline int dt_insert(const struct lu_env *env,
2775 struct dt_object *dt,
2776 const struct dt_rec *rec,
2777 const struct dt_key *key,
2781 LASSERT(dt->do_index_ops);
2782 LASSERT(dt->do_index_ops->dio_insert);
2784 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2785 return cfs_fail_err;
2787 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2790 static inline int dt_declare_xattr_del(const struct lu_env *env,
2791 struct dt_object *dt,
2796 LASSERT(dt->do_ops);
2797 LASSERT(dt->do_ops->do_declare_xattr_del);
2799 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2800 return cfs_fail_err;
2802 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2805 static inline int dt_xattr_del(const struct lu_env *env,
2806 struct dt_object *dt, const char *name,
2810 LASSERT(dt->do_ops);
2811 LASSERT(dt->do_ops->do_xattr_del);
2813 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2814 return cfs_fail_err;
2816 return dt->do_ops->do_xattr_del(env, dt, name, th);
2819 static inline int dt_declare_xattr_set(const struct lu_env *env,
2820 struct dt_object *dt,
2821 const struct lu_buf *buf,
2822 const char *name, int fl,
2826 LASSERT(dt->do_ops);
2827 LASSERT(dt->do_ops->do_declare_xattr_set);
2829 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2830 return cfs_fail_err;
2832 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2835 static inline int dt_xattr_set(const struct lu_env *env,
2836 struct dt_object *dt, const struct lu_buf *buf,
2837 const char *name, int fl, struct thandle *th)
2840 LASSERT(dt->do_ops);
2841 LASSERT(dt->do_ops->do_xattr_set);
2843 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2844 return cfs_fail_err;
2846 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2849 static inline int dt_declare_xattr_get(const struct lu_env *env,
2850 struct dt_object *dt,
2855 LASSERT(dt->do_ops);
2856 LASSERT(dt->do_ops->do_declare_xattr_get);
2858 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2859 return cfs_fail_err;
2861 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2864 static inline int dt_xattr_get(const struct lu_env *env,
2865 struct dt_object *dt, struct lu_buf *buf,
2869 LASSERT(dt->do_ops);
2870 LASSERT(dt->do_ops->do_xattr_get);
2872 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2873 return cfs_fail_err;
2875 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2878 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2879 const struct lu_buf *buf)
2882 LASSERT(dt->do_ops);
2883 LASSERT(dt->do_ops->do_xattr_list);
2885 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2886 return cfs_fail_err;
2888 return dt->do_ops->do_xattr_list(env, dt, buf);
2891 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2894 LASSERT(dt->do_ops);
2895 LASSERT(dt->do_ops->do_invalidate);
2897 return dt->do_ops->do_invalidate(env, dt);
2900 static inline int dt_declare_delete(const struct lu_env *env,
2901 struct dt_object *dt,
2902 const struct dt_key *key,
2906 LASSERT(dt->do_index_ops);
2907 LASSERT(dt->do_index_ops->dio_declare_delete);
2909 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2910 return cfs_fail_err;
2912 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2915 static inline int dt_delete(const struct lu_env *env,
2916 struct dt_object *dt,
2917 const struct dt_key *key,
2921 LASSERT(dt->do_index_ops);
2922 LASSERT(dt->do_index_ops->dio_delete);
2924 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2925 return cfs_fail_err;
2927 return dt->do_index_ops->dio_delete(env, dt, key, th);
2930 static inline int dt_commit_async(const struct lu_env *env,
2931 struct dt_device *dev)
2934 LASSERT(dev->dd_ops);
2935 LASSERT(dev->dd_ops->dt_commit_async);
2936 return dev->dd_ops->dt_commit_async(env, dev);
2939 static inline int dt_reserve_or_free_quota(const struct lu_env *env,
2940 struct dt_device *dev,
2941 enum quota_type type, __u64 uid,
2942 __u64 gid, int count, bool is_md)
2945 LASSERT(dev->dd_ops);
2946 LASSERT(dev->dd_ops->dt_reserve_or_free_quota);
2947 return dev->dd_ops->dt_reserve_or_free_quota(env, dev, type, uid, gid,
2951 static inline int dt_lookup(const struct lu_env *env,
2952 struct dt_object *dt,
2954 const struct dt_key *key)
2959 LASSERT(dt->do_index_ops);
2960 LASSERT(dt->do_index_ops->dio_lookup);
2962 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2963 return cfs_fail_err;
2965 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2973 static inline int dt_declare_layout_change(const struct lu_env *env,
2974 struct dt_object *o,
2975 struct md_layout_change *mlc,
2980 LASSERT(o->do_ops->do_declare_layout_change);
2981 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2984 static inline int dt_layout_change(const struct lu_env *env,
2985 struct dt_object *o,
2986 struct md_layout_change *mlc,
2991 LASSERT(o->do_ops->do_layout_change);
2992 return o->do_ops->do_layout_change(env, o, mlc, th);
2995 struct dt_find_hint {
2996 struct lu_fid *dfh_fid;
2997 struct dt_device *dfh_dt;
2998 struct dt_object *dfh_o;
3001 struct dt_insert_rec {
3003 const struct lu_fid *rec_fid;
3015 struct dt_thread_info {
3016 char dti_buf[DT_MAX_PATH];
3017 struct dt_find_hint dti_dfh;
3018 struct lu_attr dti_attr;
3019 struct lu_fid dti_fid;
3020 struct dt_object_format dti_dof;
3021 struct lustre_mdt_attrs dti_lma;
3022 struct lu_buf dti_lb;
3023 struct lu_object_conf dti_conf;
3025 struct dt_insert_rec dti_dt_rec;
3028 extern struct lu_context_key dt_key;
3030 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
3032 struct dt_thread_info *dti;
3034 dti = lu_context_key_get(&env->le_ctx, &dt_key);
3039 int dt_global_init(void);
3040 void dt_global_fini(void);
3041 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
3042 const char *name, struct ldebugfs_vars *list);
3043 int dt_tunables_fini(struct dt_device *dt);
3045 # ifdef CONFIG_PROC_FS
3046 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
3047 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
3048 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
3049 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
3050 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
3051 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
3052 # endif /* CONFIG_PROC_FS */
3054 #endif /* __LUSTRE_DT_OBJECT_H */