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, 2016, 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 */
92 * Per-transaction commit callback function
94 struct dt_txn_commit_cb;
95 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
96 struct dt_txn_commit_cb *cb, int err);
98 * Special per-transaction callback for cases when just commit callback
99 * is needed and per-device callback are not convenient to use
101 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
102 #define MAX_COMMIT_CB_STR_LEN 32
104 #define DCB_TRANS_STOP 0x1
105 struct dt_txn_commit_cb {
106 struct list_head dcb_linkage;
111 char dcb_name[MAX_COMMIT_CB_STR_LEN];
115 * Operations on dt device.
117 struct dt_device_operations {
119 * Return device-wide statistics.
121 * Return device-wide stats including block size, total and
122 * free blocks, total and free objects, etc. See struct obd_statfs
125 * \param[in] env execution environment for this thread
126 * \param[in] dev dt device
127 * \param[out] osfs stats information
129 * \retval 0 on success
130 * \retval negative negated errno on error
132 int (*dt_statfs)(const struct lu_env *env,
133 struct dt_device *dev,
134 struct obd_statfs *osfs);
137 * Create transaction.
139 * Create in-memory structure representing the transaction for the
140 * caller. The structure returned will be used by the calling thread
141 * to specify the transaction the updates belong to. Once created
142 * successfully ->dt_trans_stop() must be called in any case (with
143 * ->dt_trans_start() and updates or not) so that the transaction
144 * handle and other resources can be released by the layers below.
146 * \param[in] env execution environment for this thread
147 * \param[in] dev dt device
149 * \retval pointer to handle if creation succeeds
150 * \retval ERR_PTR(errno) if creation fails
152 struct thandle *(*dt_trans_create)(const struct lu_env *env,
153 struct dt_device *dev);
158 * Start the transaction. The transaction described by \a th can be
159 * started only once. Another start is considered as an error.
160 * A thread is not supposed to start a transaction while another
161 * transaction isn't closed by the thread (though multiple handles
162 * can be created). The caller should start the transaction once
163 * all possible updates are declared (see the ->do_declare_* methods
164 * below) and all the needed resources are reserved.
166 * \param[in] env execution environment for this thread
167 * \param[in] dev dt device
168 * \param[in] th transaction handle
170 * \retval 0 on success
171 * \retval negative negated errno on error
173 int (*dt_trans_start)(const struct lu_env *env,
174 struct dt_device *dev,
180 * Once stopped the transaction described by \a th is complete (all
181 * the needed updates are applied) and further processing such as
182 * flushing to disk, sending to another target, etc, is handled by
183 * lower layers. The caller can't access this transaction by the
184 * handle anymore (except from the commit callbacks, see below).
186 * \param[in] env execution environment for this thread
187 * \param[in] dev dt device
188 * \param[in] th transaction handle
190 * \retval 0 on success
191 * \retval negative negated errno on error
193 int (*dt_trans_stop)(const struct lu_env *env,
194 struct dt_device *dev,
198 * Add commit callback to the transaction.
200 * Add a commit callback to the given transaction handle. The callback
201 * will be called when the associated transaction is stored. I.e. the
202 * transaction will survive an event like power off if the callback did
203 * run. The number of callbacks isn't limited, but you should note that
204 * some disk filesystems do handle the commit callbacks in the thread
205 * handling commit/flush of all the transactions, meaning that new
206 * transactions are blocked from commit and flush until all the
207 * callbacks are done. Also, note multiple callbacks can be running
208 * concurrently using multiple CPU cores. The callbacks will be running
209 * in a special environment which can not be used to pass data around.
211 * \param[in] th transaction handle
212 * \param[in] dcb commit callback description
214 * \retval 0 on success
215 * \retval negative negated errno on error
217 int (*dt_trans_cb_add)(struct thandle *th,
218 struct dt_txn_commit_cb *dcb);
221 * Return FID of root index object.
223 * Return the FID of the root object in the filesystem. This object
224 * is usually provided as a bootstrap point by a disk filesystem.
225 * This is up to the implementation which FID to use, though
226 * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
228 * \param[in] env execution environment for this thread
229 * \param[in] dev dt device
230 * \param[out] fid FID of the root object
232 * \retval 0 on success
233 * \retval negative negated errno on error
235 int (*dt_root_get)(const struct lu_env *env,
236 struct dt_device *dev,
240 * Return device configuration data.
242 * Return device (disk fs, actually) specific configuration.
243 * The configuration isn't subject to change at runtime.
244 * See struct dt_device_param for the details.
246 * \param[in] env execution environment for this thread
247 * \param[in] dev dt device
248 * \param[out] param configuration parameters
250 void (*dt_conf_get)(const struct lu_env *env,
251 const struct dt_device *dev,
252 struct dt_device_param *param);
257 * Sync all the cached state (dirty buffers, pages, etc) to the
258 * persistent storage. The method returns control once the sync is
259 * complete. This operation may incur significant I/O to disk and
260 * should be reserved for cases where a global sync is strictly
263 * \param[in] env execution environment for this thread
264 * \param[in] dev dt device
266 * \retval 0 on success
267 * \retval negative negated errno on error
269 int (*dt_sync)(const struct lu_env *env,
270 struct dt_device *dev);
273 * Make device read-only.
275 * Prevent new modifications to the device. This is a very specific
276 * state where all the changes are accepted successfully and the
277 * commit callbacks are called, but persistent state never changes.
278 * Used only in the tests to simulate power-off scenario.
280 * \param[in] env execution environment for this thread
281 * \param[in] dev dt device
283 * \retval 0 on success
284 * \retval negative negated errno on error
286 int (*dt_ro)(const struct lu_env *env,
287 struct dt_device *dev);
290 * Start transaction commit asynchronously.
293 * Provide a hint to the underlying filesystem that it should start
294 * committing soon. The control returns immediately. It's up to the
295 * layer implementing the method how soon to start committing. Usually
296 * this should be throttled to some extent, otherwise the number of
297 * aggregated transaction goes too high causing performance drop.
299 * \param[in] env execution environment for this thread
300 * \param[in] dev dt device
302 * \retval 0 on success
303 * \retval negative negated errno on error
305 int (*dt_commit_async)(const struct lu_env *env,
306 struct dt_device *dev);
309 struct dt_index_features {
310 /** required feature flags from enum dt_index_flags */
312 /** minimal required key size */
313 size_t dif_keysize_min;
314 /** maximal required key size, 0 if no limit */
315 size_t dif_keysize_max;
316 /** minimal required record size */
317 size_t dif_recsize_min;
318 /** maximal required record size, 0 if no limit */
319 size_t dif_recsize_max;
320 /** pointer size for record */
324 enum dt_index_flags {
325 /** index supports variable sized keys */
326 DT_IND_VARKEY = 1 << 0,
327 /** index supports variable sized records */
328 DT_IND_VARREC = 1 << 1,
329 /** index can be modified */
330 DT_IND_UPDATE = 1 << 2,
331 /** index supports records with non-unique (duplicate) keys */
332 DT_IND_NONUNQ = 1 << 3,
334 * index support fixed-size keys sorted with natural numerical way
335 * and is able to return left-side value if no exact value found
337 DT_IND_RANGE = 1 << 4,
341 * Features, required from index to support file system directories (mapping
344 extern const struct dt_index_features dt_directory_features;
345 extern const struct dt_index_features dt_otable_features;
346 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
347 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
348 extern const struct dt_index_features dt_lfsck_namespace_features;
350 /* index features supported by the accounting objects */
351 extern const struct dt_index_features dt_acct_features;
353 /* index features supported by the quota global indexes */
354 extern const struct dt_index_features dt_quota_glb_features;
356 /* index features supported by the quota slave indexes */
357 extern const struct dt_index_features dt_quota_slv_features;
359 /* index features supported by the nodemap index */
360 extern const struct dt_index_features dt_nodemap_features;
363 * This is a general purpose dt allocation hint.
364 * It now contains the parent object.
365 * It can contain any allocation hint in the future.
367 struct dt_allocation_hint {
368 struct dt_object *dah_parent;
369 const void *dah_eadata;
375 * object type specifier.
378 enum dt_format_type {
383 /** for special index */
385 /** for symbolic link */
390 * object format specifier.
392 struct dt_object_format {
393 /** type for dt object */
394 enum dt_format_type dof_type;
404 * special index need feature as parameter to create
408 const struct dt_index_features *di_feat;
413 enum dt_format_type dt_mode_to_dft(__u32 mode);
415 typedef __u64 dt_obj_version_t;
417 union ldlm_policy_data;
420 * A dt_object provides common operations to create and destroy
421 * objects and to manage regular and extended attributes.
423 struct dt_object_operations {
425 * Get read lock on object.
427 * Read lock is compatible with other read locks, so it's shared.
428 * Read lock is not compatible with write lock which is exclusive.
429 * The lock is blocking and can't be used from an interrupt context.
431 * \param[in] env execution environment for this thread
432 * \param[in] dt object to lock for reading
433 * \param[in] role a hint to debug locks (see kernel's mutexes)
435 void (*do_read_lock)(const struct lu_env *env,
436 struct dt_object *dt,
440 * Get write lock on object.
442 * Write lock is exclusive and cannot be shared. The lock is blocking
443 * and can't be used from an interrupt context.
445 * \param[in] env execution environment for this thread
446 * \param[in] dt object to lock for writing
447 * \param[in] role a hint to debug locks (see kernel's mutexes)
450 void (*do_write_lock)(const struct lu_env *env,
451 struct dt_object *dt,
457 * \param[in] env execution environment for this thread
458 * \param[in] dt object
460 void (*do_read_unlock)(const struct lu_env *env,
461 struct dt_object *dt);
464 * Release write lock.
466 * \param[in] env execution environment for this thread
467 * \param[in] dt object
469 void (*do_write_unlock)(const struct lu_env *env,
470 struct dt_object *dt);
473 * Check whether write lock is held.
475 * The caller can learn whether write lock is held on the object
477 * \param[in] env execution environment for this thread
478 * \param[in] dt object
480 * \retval 0 no write lock
481 * \retval 1 write lock is held
483 int (*do_write_locked)(const struct lu_env *env,
484 struct dt_object *dt);
487 * Declare intention to request reqular attributes.
489 * Notity the underlying filesystem that the caller may request regular
490 * attributes with ->do_attr_get() soon. This allows OSD to implement
491 * prefetching logic in an object-oriented manner. The implementation
492 * can be noop. This method should avoid expensive delays such as
493 * waiting on disk I/O, otherwise the goal of enabling a performance
494 * optimization would be defeated.
496 * \param[in] env execution environment for this thread
497 * \param[in] dt object
499 * \retval 0 on success
500 * \retval negative negated errno on error
502 int (*do_declare_attr_get)(const struct lu_env *env,
503 struct dt_object *dt);
506 * Return regular attributes.
508 * The object must exist. Currently all the attributes should be
509 * returned, but in the future this can be improved so that only
510 * a selected set is returned. This can improve performance as in
511 * some cases attributes are stored in different places and
512 * getting them all can be an iterative and expensive process.
514 * \param[in] env execution environment for this thread
515 * \param[in] dt object
516 * \param[out] attr attributes to fill
518 * \retval 0 on success
519 * \retval negative negated errno on error
521 int (*do_attr_get)(const struct lu_env *env,
522 struct dt_object *dt,
523 struct lu_attr *attr);
526 * Declare intention to change regular object's attributes.
528 * Notify the underlying filesystem that the regular attributes may
529 * change in this transaction. This enables the layer below to prepare
530 * resources (e.g. journal credits in ext4). This method should be
531 * called between creating the transaction and starting it. Note that
532 * the la_valid field of \a attr specifies which attributes will change.
533 * The object need not exist.
535 * \param[in] env execution environment for this thread
536 * \param[in] dt object
537 * \param[in] attr attributes to change specified in attr.la_valid
538 * \param[in] th transaction handle
540 * \retval 0 on success
541 * \retval negative negated errno on error
543 int (*do_declare_attr_set)(const struct lu_env *env,
544 struct dt_object *dt,
545 const struct lu_attr *attr,
549 * Change regular attributes.
551 * Change regular attributes in the given transaction. Note only
552 * attributes flagged by attr.la_valid change. The object must
553 * exist. If the layer implementing this method is responsible for
554 * quota, then the method should maintain object accounting for the
555 * given credentials when la_uid/la_gid changes.
557 * \param[in] env execution environment for this thread
558 * \param[in] dt object
559 * \param[in] attr new attributes to apply
560 * \param[in] th transaction handle
562 * \retval 0 on success
563 * \retval negative negated errno on error
565 int (*do_attr_set)(const struct lu_env *env,
566 struct dt_object *dt,
567 const struct lu_attr *attr,
571 * Declare intention to request extented attribute.
573 * Notify the underlying filesystem that the caller may request extended
574 * attribute with ->do_xattr_get() soon. This allows OSD to implement
575 * prefetching logic in an object-oriented manner. The implementation
576 * can be noop. This method should avoid expensive delays such as
577 * waiting on disk I/O, otherwise the goal of enabling a performance
578 * optimization would be defeated.
580 * \param[in] env execution environment for this thread
581 * \param[in] dt object
582 * \param[in] buf unused, may be removed in the future
583 * \param[in] name name of the extended attribute
585 * \retval 0 on success
586 * \retval negative negated errno on error
588 int (*do_declare_xattr_get)(const struct lu_env *env,
589 struct dt_object *dt,
594 * Return a value of an extended attribute.
596 * The object must exist. If the buffer is NULL, then the method
597 * must return the size of the value.
599 * \param[in] env execution environment for this thread
600 * \param[in] dt object
601 * \param[out] buf buffer in which to store the value
602 * \param[in] name name of the extended attribute
604 * \retval 0 on success
605 * \retval -ERANGE if \a buf is too small
606 * \retval negative negated errno on error
607 * \retval positive value's size if \a buf is NULL or has zero size
609 int (*do_xattr_get)(const struct lu_env *env,
610 struct dt_object *dt,
615 * Declare intention to change an extended attribute.
617 * Notify the underlying filesystem that the extended attribute may
618 * change in this transaction. This enables the layer below to prepare
619 * resources (e.g. journal credits in ext4). This method should be
620 * called between creating the transaction and starting it. The object
623 * \param[in] env execution environment for this thread
624 * \param[in] dt object
625 * \param[in] buf buffer storing new value of the attribute
626 * \param[in] name name of the attribute
627 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
628 * LU_XATTR_REPLACE - fail if EA doesn't exist
629 * \param[in] th transaction handle
631 * \retval 0 on success
632 * \retval negative negated errno on error
634 int (*do_declare_xattr_set)(const struct lu_env *env,
635 struct dt_object *dt,
636 const struct lu_buf *buf,
642 * Set an extended attribute.
644 * Change or replace the specified extended attribute (EA).
645 * The flags passed in \a fl dictate whether the EA is to be
646 * created or replaced, as follows.
647 * LU_XATTR_CREATE - fail if EA exists
648 * LU_XATTR_REPLACE - fail if EA doesn't exist
649 * The object must exist.
651 * \param[in] env execution environment for this thread
652 * \param[in] dt object
653 * \param[in] buf buffer storing new value of the attribute
654 * \param[in] name name of the attribute
655 * \param[in] fl flags indicating EA creation or replacement
656 * \param[in] th transaction handle
658 * \retval 0 on success
659 * \retval negative negated errno on error
661 int (*do_xattr_set)(const struct lu_env *env,
662 struct dt_object *dt,
663 const struct lu_buf *buf,
669 * Declare intention to delete an extended attribute.
671 * Notify the underlying filesystem that the extended attribute may
672 * be deleted in this transaction. This enables the layer below to
673 * prepare resources (e.g. journal credits in ext4). This method
674 * should be called between creating the transaction and starting it.
675 * The object need not exist.
677 * \param[in] env execution environment for this thread
678 * \param[in] dt object
679 * \param[in] name name of the attribute
680 * \param[in] th transaction handle
682 * \retval 0 on success
683 * \retval negative negated errno on error
685 int (*do_declare_xattr_del)(const struct lu_env *env,
686 struct dt_object *dt,
691 * Delete an extended attribute.
693 * This method deletes the specified extended attribute. The object
696 * \param[in] env execution environment for this thread
697 * \param[in] dt object
698 * \param[in] name name of the attribute
699 * \param[in] th transaction handle
701 * \retval 0 on success
702 * \retval negative negated errno on error
704 int (*do_xattr_del)(const struct lu_env *env,
705 struct dt_object *dt,
710 * Return a list of the extended attributes.
712 * Fills the passed buffer with a list of the extended attributes
713 * found in the object. The names are separated with '\0'.
714 * The object must exist.
716 * \param[in] env execution environment for this thread
717 * \param[in] dt object
718 * \param[out] buf buffer to put the list in
720 * \retval positive bytes used/required in the buffer
721 * \retval negative negated errno on error
723 int (*do_xattr_list)(const struct lu_env *env,
724 struct dt_object *dt,
725 const struct lu_buf *buf);
728 * Prepare allocation hint for a new object.
730 * This method is used by the caller to inform OSD of the parent-child
731 * relationship between two objects and enable efficient object
732 * allocation. Filled allocation hint will be passed to ->do_create()
735 * \param[in] env execution environment for this thread
736 * \param[out] ah allocation hint
737 * \param[in] parent parent object (can be NULL)
738 * \param[in] child child object
739 * \param[in] _mode type of the child object
741 void (*do_ah_init)(const struct lu_env *env,
742 struct dt_allocation_hint *ah,
743 struct dt_object *parent,
744 struct dt_object *child,
748 * Declare intention to create a new object.
750 * Notify the underlying filesystem that the object may be created
751 * in this transaction. This enables the layer below to prepare
752 * resources (e.g. journal credits in ext4). This method should be
753 * called between creating the transaction and starting it.
755 * If the layer implementing this method is responsible for quota,
756 * then the method should reserve an object for the given credentials
757 * and return an error if quota is over. If object creation later
758 * fails for some reason, then the reservation should be released
759 * properly (usually in ->dt_trans_stop()).
761 * \param[in] env execution environment for this thread
762 * \param[in] dt object
763 * \param[in] attr attributes of the new object
764 * \param[in] hint allocation hint
765 * \param[in] dof object format
766 * \param[in] th transaction handle
768 * \retval 0 on success
769 * \retval negative negated errno on error
771 int (*do_declare_create)(const struct lu_env *env,
772 struct dt_object *dt,
773 struct lu_attr *attr,
774 struct dt_allocation_hint *hint,
775 struct dt_object_format *dof,
781 * The method creates the object passed with the specified attributes
782 * and object format. Object allocation procedure can use information
783 * stored in the allocation hint. Different object formats are supported
784 * (see enum dt_format_type and struct dt_object_format) depending on
785 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
786 * in the LU-object header attributes.
788 * If the layer implementing this method is responsible for quota,
789 * then the method should maintain object accounting for the given
792 * \param[in] env execution environment for this thread
793 * \param[in] dt object
794 * \param[in] attr attributes of the new object
795 * \param[in] hint allocation hint
796 * \param[in] dof object format
797 * \param[in] th transaction handle
799 * \retval 0 on success
800 * \retval negative negated errno on error
802 int (*do_create)(const struct lu_env *env,
803 struct dt_object *dt,
804 struct lu_attr *attr,
805 struct dt_allocation_hint *hint,
806 struct dt_object_format *dof,
810 * Declare intention to destroy an object.
812 * Notify the underlying filesystem that the object may be destroyed
813 * in this transaction. This enables the layer below to prepare
814 * resources (e.g. journal credits in ext4). This method should be
815 * called between creating the transaction and starting it. The object
818 * \param[in] env execution environment for this thread
819 * \param[in] dt object
820 * \param[in] th transaction handle
822 * \retval 0 on success
823 * \retval negative negated errno on error
825 int (*do_declare_destroy)(const struct lu_env *env,
826 struct dt_object *dt,
832 * This method destroys the object and all the resources associated
833 * with the object (data, key/value pairs, extended attributes, etc).
834 * The object must exist. If destroy is successful, then flag
835 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
836 * instance of in-core object. Any subsequent access to the same FID
837 * should get another instance with no LOHA_EXIST flag set.
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] th transaction handle
847 * \retval 0 on success
848 * \retval negative negated errno on error
850 int (*do_destroy)(const struct lu_env *env,
851 struct dt_object *dt,
855 * Try object as an index.
857 * Announce that this object is going to be used as an index. This
858 * operation checks that object supports indexing operations and
859 * installs appropriate dt_index_operations vector on success.
860 * Also probes for features. Operation is successful if all required
861 * features are supported. It's not possible to access the object
862 * with index methods before ->do_index_try() returns success.
864 * \param[in] env execution environment for this thread
865 * \param[in] dt object
866 * \param[in] feat index features
868 * \retval 0 on success
869 * \retval negative negated errno on error
871 int (*do_index_try)(const struct lu_env *env,
872 struct dt_object *dt,
873 const struct dt_index_features *feat);
876 * Declare intention to increment nlink count.
878 * Notify the underlying filesystem that the nlink regular attribute
879 * be changed in this transaction. This enables the layer below to
880 * prepare resources (e.g. journal credits in ext4). This method
881 * should be called between creating the transaction and starting it.
882 * The object need not exist.
884 * \param[in] env execution environment for this thread
885 * \param[in] dt object
886 * \param[in] th transaction handle
888 * \retval 0 on success
889 * \retval negative negated errno on error
891 int (*do_declare_ref_add)(const struct lu_env *env,
892 struct dt_object *dt,
898 * Increment nlink (from the regular attributes set) in the given
899 * transaction. Note the absolute limit for nlink should be learnt
900 * from struct dt_device_param::ddp_max_nlink. The object must exist.
902 * \param[in] env execution environment for this thread
903 * \param[in] dt object
904 * \param[in] th transaction handle
906 * \retval 0 on success
907 * \retval negative negated errno on error
909 int (*do_ref_add)(const struct lu_env *env,
910 struct dt_object *dt, struct thandle *th);
913 * Declare intention to decrement nlink count.
915 * Notify the underlying filesystem that the nlink regular attribute
916 * be changed in this transaction. This enables the layer below to
917 * prepare resources (e.g. journal credits in ext4). This method
918 * should be called between creating the transaction and starting it.
919 * The object need not exist.
921 * \param[in] env execution environment for this thread
922 * \param[in] dt object
923 * \param[in] th transaction handle
925 * \retval 0 on success
926 * \retval negative negated errno on error
928 int (*do_declare_ref_del)(const struct lu_env *env,
929 struct dt_object *dt,
935 * Decrement nlink (from the regular attributes set) in the given
936 * transaction. The object must exist.
938 * \param[in] env execution environment for this thread
939 * \param[in] dt object
940 * \param[in] th transaction handle
942 * \retval 0 on success
943 * \retval negative negated errno on error
945 int (*do_ref_del)(const struct lu_env *env,
946 struct dt_object *dt,
952 * The method is called to sync specified range of the object to a
953 * persistent storage. The control is returned once the operation is
954 * complete. The difference from ->do_sync() is that the object can
955 * be in-sync with the persistent storage (nothing to flush), then
956 * the method returns quickly with no I/O overhead. So, this method
957 * should be preferred over ->do_sync() where possible. Also note that
958 * if the object isn't clean, then some disk filesystems will call
959 * ->do_sync() to maintain overall consistency, in which case it's
960 * still very expensive.
962 * \param[in] env execution environment for this thread
963 * \param[in] dt object
964 * \param[in] start start of the range to sync
965 * \param[in] end end of the range to sync
967 * \retval 0 on success
968 * \retval negative negated errno on error
970 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
971 __u64 start, __u64 end);
976 * Lock object(s) using Distributed Lock Manager (LDLM).
978 * Get LDLM locks for the object. Currently used to lock "remote"
979 * objects in DNE configuration - a service running on MDTx needs
980 * to lock an object on MDTy.
982 * \param[in] env execution environment for this thread
983 * \param[in] dt object
984 * \param[out] lh lock handle, sometimes used, sometimes not
985 * \param[in] einfo ldlm callbacks, locking type and mode
986 * \param[out] einfo private data to be passed to unlock later
987 * \param[in] policy inodebits data
989 * \retval 0 on success
990 * \retval negative negated errno on error
992 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
993 struct lustre_handle *lh,
994 struct ldlm_enqueue_info *einfo,
995 union ldlm_policy_data *policy);
1000 * Release LDLM lock(s) granted with ->do_object_lock().
1002 * \param[in] env execution environment for this thread
1003 * \param[in] dt object
1004 * \param[in] einfo lock handles, from ->do_object_lock()
1005 * \param[in] policy inodebits data
1007 * \retval 0 on success
1008 * \retval negative negated errno on error
1010 int (*do_object_unlock)(const struct lu_env *env,
1011 struct dt_object *dt,
1012 struct ldlm_enqueue_info *einfo,
1013 union ldlm_policy_data *policy);
1016 * Invalidate attribute cache.
1018 * This method invalidate attribute cache of the object, which is on OSP
1021 * \param[in] env execution envionment for this thread
1022 * \param[in] dt object
1024 * \retval 0 on success
1025 * \retval negative negated errno on error
1027 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1030 * Declare intention to instaintiate extended layout component.
1032 * \param[in] env execution environment
1033 * \param[in] dt DT object
1034 * \param[in] layout data structure to describe the changes to
1035 * the DT object's layout
1036 * \param[in] buf buffer containing client's lovea or empty
1039 * \retval -ne error code
1041 int (*do_declare_layout_change)(const struct lu_env *env,
1042 struct dt_object *dt,
1043 struct layout_intent *layout,
1044 const struct lu_buf *buf,
1045 struct thandle *th);
1048 * Client is trying to write to un-instantiated layout component.
1050 * \param[in] env execution environment
1051 * \param[in] dt DT object
1052 * \param[in] layout data structure to describe the changes to
1053 * the DT object's layout
1054 * \param[in] buf buffer containing client's lovea or empty
1057 * \retval -ne error code
1059 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1060 struct layout_intent *layout,
1061 const struct lu_buf *buf, struct thandle *th);
1065 DT_BUFS_TYPE_READ = 0x0000,
1066 DT_BUFS_TYPE_WRITE = 0x0001,
1067 DT_BUFS_TYPE_READAHEAD = 0x0002,
1068 DT_BUFS_TYPE_LOCAL = 0x0004,
1072 * Per-dt-object operations on "file body" - unstructure raw data.
1074 struct dt_body_operations {
1078 * Read unstructured data from an existing regular object.
1079 * Only data before attr.la_size is returned.
1081 * \param[in] env execution environment for this thread
1082 * \param[in] dt object
1083 * \param[out] buf buffer (including size) to copy data in
1084 * \param[in] pos position in the object to start
1085 * \param[out] pos original value of \a pos + bytes returned
1087 * \retval positive bytes read on success
1088 * \retval negative negated errno on error
1090 ssize_t (*dbo_read)(const struct lu_env *env,
1091 struct dt_object *dt,
1096 * Declare intention to write data to object.
1098 * Notify the underlying filesystem that data may be written in
1099 * this transaction. This enables the layer below to prepare resources
1100 * (e.g. journal credits in ext4). This method should be called
1101 * between creating the transaction and starting it. The object need
1102 * not exist. If the layer implementing this method is responsible for
1103 * quota, then the method should reserve space for the given credentials
1104 * and return an error if quota is over. If the write later fails
1105 * for some reason, then the reserve should be released properly
1106 * (usually in ->dt_trans_stop()).
1108 * \param[in] env execution environment for this thread
1109 * \param[in] dt object
1110 * \param[in] buf buffer (including size) to copy data from
1111 * \param[in] pos position in the object to start
1112 * \param[in] th transaction handle
1114 * \retval 0 on success
1115 * \retval negative negated errno on error
1117 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1118 struct dt_object *dt,
1119 const struct lu_buf *buf,
1121 struct thandle *th);
1124 * Write unstructured data to regular existing object.
1126 * The method allocates space and puts data in. Also, the method should
1127 * maintain attr.la_size properly. Partial writes are possible.
1129 * If the layer implementing this method is responsible for quota,
1130 * then the method should maintain space accounting for the given
1133 * \param[in] env execution environment for this thread
1134 * \param[in] dt object
1135 * \param[in] buf buffer (including size) to copy data from
1136 * \param[in] pos position in the object to start
1137 * \param[out] pos \a pos + bytes written
1138 * \param[in] th transaction handle
1139 * \param[in] ignore unused (was used to request quota ignorance)
1141 * \retval positive bytes written on success
1142 * \retval negative negated errno on error
1144 ssize_t (*dbo_write)(const struct lu_env *env,
1145 struct dt_object *dt,
1146 const struct lu_buf *buf,
1152 * Return buffers for data.
1154 * This method is used to access data with no copying. It's so-called
1155 * zero-copy I/O. The method returns the descriptors for the internal
1156 * buffers where data are managed by the disk filesystem. For example,
1157 * pagecache in case of ext4 or ARC with ZFS. Then other components
1158 * (e.g. networking) can transfer data from or to the buffers with no
1159 * additional copying.
1161 * The method should fill an array of struct niobuf_local, where
1162 * each element describes a full or partial page for data at specific
1163 * offset. The caller should use page/lnb_page_offset/len to find data
1164 * at object's offset lnb_file_offset.
1166 * The memory referenced by the descriptors can't change its purpose
1167 * until the complementary ->dbo_bufs_put() is called. The caller should
1168 * specify if the buffers are used to read or modify data so that OSD
1169 * can decide how to initialize the buffers: bring all the data for
1170 * reads or just bring partial buffers for write. Note: the method does
1171 * not check whether output array is large enough.
1173 * \param[in] env execution environment for this thread
1174 * \param[in] dt object
1175 * \param[in] pos position in the object to start
1176 * \param[in] len size of region in bytes
1177 * \param[out] lb array of descriptors to fill
1178 * \param[in] rw 0 if used to read, 1 if used for write
1180 * \retval positive number of descriptors on success
1181 * \retval negative negated errno on error
1183 int (*dbo_bufs_get)(const struct lu_env *env,
1184 struct dt_object *dt,
1187 struct niobuf_local *lb,
1188 enum dt_bufs_type rw);
1191 * Release reference granted by ->dbo_bufs_get().
1193 * Release the reference granted by the previous ->dbo_bufs_get().
1194 * Note the references are counted.
1196 * \param[in] env execution environment for this thread
1197 * \param[in] dt object
1198 * \param[out] lb array of descriptors to fill
1199 * \param[in] nr size of the array
1201 * \retval 0 on success
1202 * \retval negative negated errno on error
1204 int (*dbo_bufs_put)(const struct lu_env *env,
1205 struct dt_object *dt,
1206 struct niobuf_local *lb,
1210 * Prepare buffers for reading.
1212 * The method is called on the given buffers to fill them with data
1213 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1214 * caller should be able to get few buffers for discontiguous regions
1215 * using few calls to ->dbo_bufs_get() and then request them all for
1216 * the preparation with a single call, so that OSD can fire many I/Os
1217 * to run concurrently. It's up to the specific OSD whether to implement
1218 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1219 * prepare data for every requested region individually.
1221 * \param[in] env execution environment for this thread
1222 * \param[in] dt object
1223 * \param[in] lnb array of buffer descriptors
1224 * \param[in] nr size of the array
1226 * \retval 0 on success
1227 * \retval negative negated errno on error
1229 int (*dbo_read_prep)(const struct lu_env *env,
1230 struct dt_object *dt,
1231 struct niobuf_local *lnb,
1235 * Prepare buffers for write.
1237 * This method is called on the given buffers to ensure the partial
1238 * buffers contain correct data. The underlying idea is the same as
1239 * in ->db_read_prep().
1241 * \param[in] env execution environment for this thread
1242 * \param[in] dt object
1243 * \param[in] lb array of buffer descriptors
1244 * \param[in] nr size of the array
1246 * \retval 0 on success
1247 * \retval negative negated errno on error
1249 int (*dbo_write_prep)(const struct lu_env *env,
1250 struct dt_object *dt,
1251 struct niobuf_local *lb,
1255 * Declare intention to write data stored in the buffers.
1257 * Notify the underlying filesystem that data may be written in
1258 * this transaction. This enables the layer below to prepare resources
1259 * (e.g. journal credits in ext4). This method should be called
1260 * between creating the transaction and starting it.
1262 * If the layer implementing this method is responsible for quota,
1263 * then the method should be reserving a space for the given
1264 * credentials and return an error if quota is exceeded. If the write
1265 * later fails for some reason, then the reserve should be released
1266 * properly (usually in ->dt_trans_stop()).
1268 * \param[in] env execution environment for this thread
1269 * \param[in] dt object
1270 * \param[in] lb array of descriptors
1271 * \param[in] nr size of the array
1272 * \param[in] th transaction handle
1274 * \retval 0 on success
1275 * \retval negative negated errno on error
1277 int (*dbo_declare_write_commit)(const struct lu_env *env,
1278 struct dt_object *dt,
1279 struct niobuf_local *lb,
1281 struct thandle *th);
1284 * Write to existing object.
1286 * This method is used to write data to a persistent storage using
1287 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1288 * data into the buffers using own mechanisms (e.g. direct transfer
1289 * from a NIC). The method should maintain attr.la_size. Also,
1290 * attr.la_blocks should be maintained but this can be done in lazy
1291 * manner, when actual allocation happens.
1293 * If the layer implementing this method is responsible for quota,
1294 * then the method should maintain space accounting for the given
1297 * \param[in] env execution environment for this thread
1298 * \param[in] dt object
1299 * \param[in] lb array of descriptors for the buffers
1300 * \param[in] nr size of the array
1301 * \param[in] th transaction handle
1303 * \retval 0 on success
1304 * \retval negative negated errno on error
1306 int (*dbo_write_commit)(const struct lu_env *env,
1307 struct dt_object *dt,
1308 struct niobuf_local *lb,
1310 struct thandle *th);
1313 * Return logical to physical block mapping for a given extent
1315 * \param[in] env execution environment for this thread
1316 * \param[in] dt object
1317 * \param[in] fm describe the region to map and the output buffer
1318 * see the details in include/linux/fiemap.h
1320 * \retval 0 on success
1321 * \retval negative negated errno on error
1323 int (*dbo_fiemap_get)(const struct lu_env *env,
1324 struct dt_object *dt,
1328 * Declare intention to deallocate space from an object.
1330 * Notify the underlying filesystem that space may be deallocated in
1331 * this transactions. This enables the layer below to prepare resources
1332 * (e.g. journal credits in ext4). This method should be called between
1333 * creating the transaction and starting it. The object need not exist.
1335 * \param[in] env execution environment for this thread
1336 * \param[in] dt object
1337 * \param[in] start the start of the region to deallocate
1338 * \param[in] end the end of the region to deallocate
1339 * \param[in] th transaction handle
1341 * \retval 0 on success
1342 * \retval negative negated errno on error
1344 int (*dbo_declare_punch)(const struct lu_env *env,
1345 struct dt_object *dt,
1348 struct thandle *th);
1351 * Deallocate specified region in an object.
1353 * This method is used to deallocate (release) space possibly consumed
1354 * by the given region of the object. If the layer implementing this
1355 * method is responsible for quota, then the method should maintain
1356 * space accounting for the given credentials.
1358 * \param[in] env execution environment for this thread
1359 * \param[in] dt object
1360 * \param[in] start the start of the region to deallocate
1361 * \param[in] end the end of the region to deallocate
1362 * \param[in] th transaction handle
1364 * \retval 0 on success
1365 * \retval negative negated errno on error
1367 int (*dbo_punch)(const struct lu_env *env,
1368 struct dt_object *dt,
1371 struct thandle *th);
1373 * Give advices on specified region in an object.
1375 * This method is used to give advices about access pattern on an
1376 * given region of the object. The disk filesystem understands
1377 * the advices and tunes cache/read-ahead policies.
1379 * \param[in] env execution environment for this thread
1380 * \param[in] dt object
1381 * \param[in] start the start of the region affected
1382 * \param[in] end the end of the region affected
1383 * \param[in] advice advice type
1385 * \retval 0 on success
1386 * \retval negative negated errno on error
1388 int (*dbo_ladvise)(const struct lu_env *env,
1389 struct dt_object *dt,
1392 enum lu_ladvise_type advice);
1396 * Incomplete type of index record.
1401 * Incomplete type of index key.
1406 * Incomplete type of dt iterator.
1411 * Per-dt-object operations on object as index. Index is a set of key/value
1412 * pairs abstracted from an on-disk representation. An index supports the
1413 * number of operations including lookup by key, insert and delete. Also,
1414 * an index can be iterated to find the pairs one by one, from a beginning
1415 * or specified point.
1417 struct dt_index_operations {
1419 * Lookup in an index by key.
1421 * The method returns a value for the given key. Key/value format
1422 * and size should have been negotiated with ->do_index_try() before.
1423 * Thus it's the caller's responsibility to provide the method with
1424 * proper key and big enough buffer. No external locking is required,
1425 * all the internal consistency should be implemented by the method
1426 * or lower layers. The object should should have been created with
1427 * type DFT_INDEX or DFT_DIR.
1429 * \param[in] env execution environment for this thread
1430 * \param[in] dt object
1431 * \param[out] rec buffer where value will be stored
1432 * \param[in] key key
1434 * \retval 0 on success
1435 * \retval -ENOENT if key isn't found
1436 * \retval negative negated errno on error
1438 int (*dio_lookup)(const struct lu_env *env,
1439 struct dt_object *dt,
1441 const struct dt_key *key);
1444 * Declare intention to insert a key/value into an index.
1446 * Notify the underlying filesystem that new key/value may be inserted
1447 * in this transaction. This enables the layer below to prepare
1448 * resources (e.g. journal credits in ext4). This method should be
1449 * called between creating the transaction and starting it. key/value
1450 * format and size is subject to ->do_index_try().
1452 * \param[in] env execution environment for this thread
1453 * \param[in] dt object
1454 * \param[in] rec buffer storing value
1455 * \param[in] key key
1456 * \param[in] th transaction handle
1458 * \retval 0 on success
1459 * \retval negative negated errno on error
1461 int (*dio_declare_insert)(const struct lu_env *env,
1462 struct dt_object *dt,
1463 const struct dt_rec *rec,
1464 const struct dt_key *key,
1465 struct thandle *th);
1468 * Insert a new key/value pair into an index.
1470 * The method inserts specified key/value pair into the given index
1471 * object. The internal consistency is maintained by the method or
1472 * the functionality below. The format and size of key/value should
1473 * have been negotiated before using ->do_index_try(), no additional
1474 * information can be specified to the method. The keys are unique
1477 * \param[in] env execution environment for this thread
1478 * \param[in] dt object
1479 * \param[in] rec buffer storing value
1480 * \param[in] key key
1481 * \param[in] th transaction handle
1482 * \param[in] ignore unused (was used to request quota ignorance)
1484 * \retval 0 on success
1485 * \retval negative negated errno on error
1487 int (*dio_insert)(const struct lu_env *env,
1488 struct dt_object *dt,
1489 const struct dt_rec *rec,
1490 const struct dt_key *key,
1495 * Declare intention to delete a key/value from an index.
1497 * Notify the underlying filesystem that key/value may be deleted in
1498 * this transaction. This enables the layer below to prepare resources
1499 * (e.g. journal credits in ext4). This method should be called
1500 * between creating the transaction and starting it. Key/value format
1501 * and size is subject to ->do_index_try(). The object need not exist.
1503 * \param[in] env execution environment for this thread
1504 * \param[in] dt object
1505 * \param[in] key key
1506 * \param[in] th transaction handle
1508 * \retval 0 on success
1509 * \retval negative negated errno on error
1511 int (*dio_declare_delete)(const struct lu_env *env,
1512 struct dt_object *dt,
1513 const struct dt_key *key,
1514 struct thandle *th);
1517 * Delete key/value pair from an index.
1519 * The method deletes specified key and corresponding value from the
1520 * given index object. The internal consistency is maintained by the
1521 * method or the functionality below. The format and size of the key
1522 * should have been negotiated before using ->do_index_try(), no
1523 * additional information can be specified to the method.
1525 * \param[in] env execution environment for this thread
1526 * \param[in] dt object
1527 * \param[in] key key
1528 * \param[in] th transaction handle
1530 * \retval 0 on success
1531 * \retval negative negated errno on error
1533 int (*dio_delete)(const struct lu_env *env,
1534 struct dt_object *dt,
1535 const struct dt_key *key,
1536 struct thandle *th);
1539 * Iterator interface.
1541 * Methods to iterate over an existing index, list the keys stored and
1542 * associated values, get key/value size, etc.
1546 * Allocate and initialize new iterator.
1548 * The iterator is a handler to be used in the subsequent
1549 * methods to access index's content. Note the position is
1550 * not defined at this point and should be initialized with
1551 * ->get() or ->load() method.
1553 * \param[in] env execution environment for this thread
1554 * \param[in] dt object
1555 * \param[in] attr ask the iterator to return part of
1556 the records, see LUDA_* for details
1558 * \retval pointer iterator pointer on success
1559 * \retval ERR_PTR(errno) on error
1561 struct dt_it *(*init)(const struct lu_env *env,
1562 struct dt_object *dt,
1568 * Release the specified iterator and all the resources
1569 * associated (e.g. the object, index cache, etc).
1571 * \param[in] env execution environment for this thread
1572 * \param[in] di iterator to release
1574 void (*fini)(const struct lu_env *env,
1578 * Move position of iterator.
1580 * Move the position of the specified iterator to the specified
1583 * \param[in] env execution environment for this thread
1584 * \param[in] di iterator
1585 * \param[in] key key to position to
1587 * \retval 0 if exact key is found
1588 * \retval 1 if at the record with least key
1589 * not larger than the key
1590 * \retval negative negated errno on error
1592 int (*get)(const struct lu_env *env,
1594 const struct dt_key *key);
1599 * Complimentary method for dt_it_ops::get() above. Some
1600 * implementation can increase a reference on the iterator in
1601 * dt_it_ops::get(). So the caller should be able to release
1602 * with dt_it_ops::put().
1604 * \param[in] env execution environment for this thread
1605 * \param[in] di iterator
1607 void (*put)(const struct lu_env *env,
1611 * Move to next record.
1613 * Moves the position of the iterator to a next record
1615 * \param[in] env execution environment for this thread
1616 * \param[in] di iterator
1618 * \retval 1 if no more records
1619 * \retval 0 on success, the next record is found
1620 * \retval negative negated errno on error
1622 int (*next)(const struct lu_env *env,
1628 * Returns a pointer to a buffer containing the key of the
1629 * record at the current position. The pointer is valid and
1630 * retains data until ->get(), ->load() and ->fini() methods
1633 * \param[in] env execution environment for this thread
1634 * \param[in] di iterator
1636 * \retval pointer to key on success
1637 * \retval ERR_PTR(errno) on error
1639 struct dt_key *(*key)(const struct lu_env *env,
1640 const struct dt_it *di);
1645 * Returns size of the key at the current position.
1647 * \param[in] env execution environment for this thread
1648 * \param[in] di iterator
1650 * \retval key's size on success
1651 * \retval negative negated errno on error
1653 int (*key_size)(const struct lu_env *env,
1654 const struct dt_it *di);
1659 * Stores the value of the record at the current position. The
1660 * buffer must be big enough (as negotiated with
1661 * ->do_index_try() or ->rec_size()). The caller can specify
1662 * she is interested only in part of the record, using attr
1663 * argument (see LUDA_* definitions for the details).
1665 * \param[in] env execution environment for this thread
1666 * \param[in] di iterator
1667 * \param[out] rec buffer to store value in
1668 * \param[in] attr specify part of the value to copy
1670 * \retval 0 on success
1671 * \retval negative negated errno on error
1673 int (*rec)(const struct lu_env *env,
1674 const struct dt_it *di,
1679 * Return record size.
1681 * Returns size of the record at the current position. The
1682 * \a attr can be used to specify only the parts of the record
1683 * needed to be returned. (see LUDA_* definitions for the
1686 * \param[in] env execution environment for this thread
1687 * \param[in] di iterator
1688 * \param[in] attr part of the record to return
1690 * \retval record's size on success
1691 * \retval negative negated errno on error
1693 int (*rec_size)(const struct lu_env *env,
1694 const struct dt_it *di,
1698 * Return a cookie (hash).
1700 * Returns the cookie (usually hash) of the key at the current
1701 * position. This allows the caller to resume iteration at this
1702 * position later. The exact value is specific to implementation
1703 * and should not be interpreted by the caller.
1705 * \param[in] env execution environment for this thread
1706 * \param[in] di iterator
1708 * \retval cookie/hash of the key
1710 __u64 (*store)(const struct lu_env *env,
1711 const struct dt_it *di);
1714 * Initialize position using cookie/hash.
1716 * Initializes the current position of the iterator to one
1717 * described by the cookie/hash as returned by ->store()
1720 * \param[in] env execution environment for this thread
1721 * \param[in] di iterator
1722 * \param[in] hash cookie/hash value
1724 * \retval positive if current position points to
1725 * record with least cookie not larger
1727 * \retval 0 if current position matches cookie
1728 * \retval negative negated errno on error
1730 int (*load)(const struct lu_env *env,
1731 const struct dt_it *di,
1737 int (*key_rec)(const struct lu_env *env,
1738 const struct dt_it *di,
1743 enum dt_otable_it_valid {
1744 DOIV_ERROR_HANDLE = 0x0001,
1745 DOIV_DRYRUN = 0x0002,
1748 enum dt_otable_it_flags {
1749 /* Exit when fail. */
1750 DOIF_FAILOUT = 0x0001,
1752 /* Reset iteration position to the device beginning. */
1753 DOIF_RESET = 0x0002,
1755 /* There is up layer component uses the iteration. */
1756 DOIF_OUTUSED = 0x0004,
1758 /* Check only without repairing. */
1759 DOIF_DRYRUN = 0x0008,
1762 /* otable based iteration needs to use the common DT iteration APIs.
1763 * To initialize the iteration, it needs call dio_it::init() firstly.
1764 * Here is how the otable based iteration should prepare arguments to
1765 * call dt_it_ops::init().
1767 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1768 * is composed of two parts:
1769 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1770 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1771 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1774 struct lu_device dd_lu_dev;
1775 const struct dt_device_operations *dd_ops;
1778 * List of dt_txn_callback (see below). This is not protected in any
1779 * way, because callbacks are supposed to be added/deleted only during
1780 * single-threaded start-up shut-down procedures.
1782 struct list_head dd_txn_callbacks;
1783 unsigned int dd_record_fid_accessed:1,
1787 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1788 void dt_device_fini(struct dt_device *dev);
1790 static inline int lu_device_is_dt(const struct lu_device *d)
1792 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1795 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1797 LASSERT(lu_device_is_dt(l));
1798 return container_of0(l, struct dt_device, dd_lu_dev);
1802 struct lu_object do_lu;
1803 const struct dt_object_operations *do_ops;
1804 const struct dt_body_operations *do_body_ops;
1805 const struct dt_index_operations *do_index_ops;
1809 * In-core representation of per-device local object OID storage
1811 struct local_oid_storage {
1812 /* all initialized llog systems on this node linked by this */
1813 struct list_head los_list;
1815 /* how many handle's reference this los has */
1816 atomic_t los_refcount;
1817 struct dt_device *los_dev;
1818 struct dt_object *los_obj;
1820 /* data used to generate new fids */
1821 struct mutex los_id_lock;
1826 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1828 return &d->dd_lu_dev;
1831 static inline struct dt_object *lu2dt(struct lu_object *l)
1833 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1834 return container_of0(l, struct dt_object, do_lu);
1837 int dt_object_init(struct dt_object *obj,
1838 struct lu_object_header *h, struct lu_device *d);
1840 void dt_object_fini(struct dt_object *obj);
1842 static inline int dt_object_exists(const struct dt_object *dt)
1844 return lu_object_exists(&dt->do_lu);
1847 static inline int dt_object_remote(const struct dt_object *dt)
1849 return lu_object_remote(&dt->do_lu);
1852 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1854 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1855 return container_of0(o, struct dt_object, do_lu);
1858 static inline struct dt_object *dt_object_child(struct dt_object *o)
1860 return container_of0(lu_object_next(&(o)->do_lu),
1861 struct dt_object, do_lu);
1865 * This is the general purpose transaction handle.
1866 * 1. Transaction Life Cycle
1867 * This transaction handle is allocated upon starting a new transaction,
1868 * and deallocated after this transaction is committed.
1869 * 2. Transaction Nesting
1870 * We do _NOT_ support nested transaction. So, every thread should only
1871 * have one active transaction, and a transaction only belongs to one
1872 * thread. Due to this, transaction handle need no reference count.
1873 * 3. Transaction & dt_object locking
1874 * dt_object locks should be taken inside transaction.
1875 * 4. Transaction & RPC
1876 * No RPC request should be issued inside transaction.
1879 /** the dt device on which the transactions are executed */
1880 struct dt_device *th_dev;
1882 /* point to the top thandle, XXX this is a bit hacky right now,
1883 * but normal device trans callback triggered by the bottom
1884 * device (OSP/OSD == sub thandle layer) needs to get the
1885 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1886 * top thandle here for now, will fix it when we have better
1887 * callback mechanism */
1888 struct thandle *th_top;
1889 /** context for this transaction, tag is LCT_TX_HANDLE */
1890 struct lu_context th_ctx;
1892 /** additional tags (layers can add in declare) */
1895 /** the last operation result in this transaction.
1896 * this value is used in recovery */
1899 /** whether we need sync commit */
1900 unsigned int th_sync:1,
1901 /* local transation, no need to inform other layers */
1903 /* Whether we need wait the transaction to be submitted
1904 * (send to remote target) */
1906 /* complex transaction which will track updates on all targets,
1912 * Transaction call-backs.
1914 * These are invoked by osd (or underlying transaction engine) when
1915 * transaction changes state.
1917 * Call-backs are used by upper layers to modify transaction parameters and to
1918 * perform some actions on for each transaction state transition. Typical
1919 * example is mdt registering call-back to write into last-received file
1920 * before each transaction commit.
1922 struct dt_txn_callback {
1923 int (*dtc_txn_start)(const struct lu_env *env,
1924 struct thandle *txn, void *cookie);
1925 int (*dtc_txn_stop)(const struct lu_env *env,
1926 struct thandle *txn, void *cookie);
1927 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1930 struct list_head dtc_linkage;
1933 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1934 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1936 int dt_txn_hook_start(const struct lu_env *env,
1937 struct dt_device *dev, struct thandle *txn);
1938 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1939 void dt_txn_hook_commit(struct thandle *txn);
1941 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1944 * Callback function used for parsing path.
1945 * \see llo_store_resolve
1947 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1951 #define DT_MAX_PATH 1024
1953 int dt_path_parser(const struct lu_env *env,
1954 char *local, dt_entry_func_t entry_func,
1958 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1959 const char *path, struct lu_fid *fid);
1961 struct dt_object *dt_store_open(const struct lu_env *env,
1962 struct dt_device *dt,
1963 const char *dirname,
1964 const char *filename,
1965 struct lu_fid *fid);
1967 struct dt_object *dt_find_or_create(const struct lu_env *env,
1968 struct dt_device *dt,
1969 const struct lu_fid *fid,
1970 struct dt_object_format *dof,
1971 struct lu_attr *attr);
1973 struct dt_object *dt_locate_at(const struct lu_env *env,
1974 struct dt_device *dev,
1975 const struct lu_fid *fid,
1976 struct lu_device *top_dev,
1977 const struct lu_object_conf *conf);
1979 static inline struct dt_object *
1980 dt_locate(const struct lu_env *env, struct dt_device *dev,
1981 const struct lu_fid *fid)
1983 return dt_locate_at(env, dev, fid,
1984 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1987 static inline struct dt_object *
1988 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1990 struct lu_object *lo;
1992 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
1993 if (lo->lo_dev == &dt_dev->dd_lu_dev)
1994 return container_of(lo, struct dt_object, do_lu);
1999 static inline void dt_object_put(const struct lu_env *env,
2000 struct dt_object *dto)
2002 lu_object_put(env, &dto->do_lu);
2005 static inline void dt_object_put_nocache(const struct lu_env *env,
2006 struct dt_object *dto)
2008 lu_object_put_nocache(env, &dto->do_lu);
2011 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2012 const struct lu_fid *first_fid,
2013 struct local_oid_storage **los);
2014 void local_oid_storage_fini(const struct lu_env *env,
2015 struct local_oid_storage *los);
2016 int local_object_fid_generate(const struct lu_env *env,
2017 struct local_oid_storage *los,
2018 struct lu_fid *fid);
2019 int local_object_declare_create(const struct lu_env *env,
2020 struct local_oid_storage *los,
2021 struct dt_object *o,
2022 struct lu_attr *attr,
2023 struct dt_object_format *dof,
2024 struct thandle *th);
2025 int local_object_create(const struct lu_env *env,
2026 struct local_oid_storage *los,
2027 struct dt_object *o,
2028 struct lu_attr *attr, struct dt_object_format *dof,
2029 struct thandle *th);
2030 struct dt_object *local_file_find(const struct lu_env *env,
2031 struct local_oid_storage *los,
2032 struct dt_object *parent,
2034 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2035 struct local_oid_storage *los,
2036 struct dt_object *parent,
2037 const char *name, __u32 mode);
2038 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2039 struct dt_device *dt,
2040 const struct lu_fid *fid,
2041 struct dt_object *parent,
2045 local_index_find_or_create(const struct lu_env *env,
2046 struct local_oid_storage *los,
2047 struct dt_object *parent,
2048 const char *name, __u32 mode,
2049 const struct dt_index_features *ft);
2051 local_index_find_or_create_with_fid(const struct lu_env *env,
2052 struct dt_device *dt,
2053 const struct lu_fid *fid,
2054 struct dt_object *parent,
2055 const char *name, __u32 mode,
2056 const struct dt_index_features *ft);
2057 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2058 struct dt_object *parent, const char *name);
2060 static inline int dt_object_lock(const struct lu_env *env,
2061 struct dt_object *o, struct lustre_handle *lh,
2062 struct ldlm_enqueue_info *einfo,
2063 union ldlm_policy_data *policy)
2066 LASSERT(o->do_ops != NULL);
2067 LASSERT(o->do_ops->do_object_lock != NULL);
2068 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2071 static inline int dt_object_unlock(const struct lu_env *env,
2072 struct dt_object *o,
2073 struct ldlm_enqueue_info *einfo,
2074 union ldlm_policy_data *policy)
2077 LASSERT(o->do_ops != NULL);
2078 LASSERT(o->do_ops->do_object_unlock != NULL);
2079 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2082 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2083 const char *name, struct lu_fid *fid);
2085 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2086 __u64 start, __u64 end)
2090 LASSERT(o->do_ops->do_object_sync);
2091 return o->do_ops->do_object_sync(env, o, start, end);
2094 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2095 struct thandle *th);
2096 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2097 dt_obj_version_t version, struct thandle *th);
2098 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2101 int dt_read(const struct lu_env *env, struct dt_object *dt,
2102 struct lu_buf *buf, loff_t *pos);
2103 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2104 struct lu_buf *buf, loff_t *pos);
2105 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2106 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2107 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2108 union lu_page *lp, size_t nob,
2109 const struct dt_it_ops *iops,
2110 struct dt_it *it, __u32 attr, void *arg);
2111 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2112 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2114 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2115 struct idx_info *ii, const struct lu_rdpg *rdpg);
2117 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2118 struct dt_device *d)
2120 LASSERT(d->dd_ops->dt_trans_create);
2121 return d->dd_ops->dt_trans_create(env, d);
2124 static inline int dt_trans_start(const struct lu_env *env,
2125 struct dt_device *d, struct thandle *th)
2127 LASSERT(d->dd_ops->dt_trans_start);
2128 return d->dd_ops->dt_trans_start(env, d, th);
2131 /* for this transaction hooks shouldn't be called */
2132 static inline int dt_trans_start_local(const struct lu_env *env,
2133 struct dt_device *d, struct thandle *th)
2135 LASSERT(d->dd_ops->dt_trans_start);
2137 return d->dd_ops->dt_trans_start(env, d, th);
2140 static inline int dt_trans_stop(const struct lu_env *env,
2141 struct dt_device *d, struct thandle *th)
2143 LASSERT(d->dd_ops->dt_trans_stop);
2144 return d->dd_ops->dt_trans_stop(env, d, th);
2147 static inline int dt_trans_cb_add(struct thandle *th,
2148 struct dt_txn_commit_cb *dcb)
2150 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2151 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2152 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2157 static inline int dt_declare_record_write(const struct lu_env *env,
2158 struct dt_object *dt,
2159 const struct lu_buf *buf,
2165 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2166 LASSERT(th != NULL);
2167 LASSERT(dt->do_body_ops);
2168 LASSERT(dt->do_body_ops->dbo_declare_write);
2169 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2173 static inline int dt_declare_create(const struct lu_env *env,
2174 struct dt_object *dt,
2175 struct lu_attr *attr,
2176 struct dt_allocation_hint *hint,
2177 struct dt_object_format *dof,
2181 LASSERT(dt->do_ops);
2182 LASSERT(dt->do_ops->do_declare_create);
2184 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2185 return cfs_fail_err;
2187 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2190 static inline int dt_create(const struct lu_env *env,
2191 struct dt_object *dt,
2192 struct lu_attr *attr,
2193 struct dt_allocation_hint *hint,
2194 struct dt_object_format *dof,
2198 LASSERT(dt->do_ops);
2199 LASSERT(dt->do_ops->do_create);
2201 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2202 return cfs_fail_err;
2204 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2207 static inline int dt_declare_destroy(const struct lu_env *env,
2208 struct dt_object *dt,
2212 LASSERT(dt->do_ops);
2213 LASSERT(dt->do_ops->do_declare_destroy);
2215 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2216 return cfs_fail_err;
2218 return dt->do_ops->do_declare_destroy(env, dt, th);
2221 static inline int dt_destroy(const struct lu_env *env,
2222 struct dt_object *dt,
2226 LASSERT(dt->do_ops);
2227 LASSERT(dt->do_ops->do_destroy);
2229 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2230 return cfs_fail_err;
2232 return dt->do_ops->do_destroy(env, dt, th);
2235 static inline void dt_read_lock(const struct lu_env *env,
2236 struct dt_object *dt,
2240 LASSERT(dt->do_ops);
2241 LASSERT(dt->do_ops->do_read_lock);
2242 dt->do_ops->do_read_lock(env, dt, role);
2245 static inline void dt_write_lock(const struct lu_env *env,
2246 struct dt_object *dt,
2250 LASSERT(dt->do_ops);
2251 LASSERT(dt->do_ops->do_write_lock);
2252 dt->do_ops->do_write_lock(env, dt, role);
2255 static inline void dt_read_unlock(const struct lu_env *env,
2256 struct dt_object *dt)
2259 LASSERT(dt->do_ops);
2260 LASSERT(dt->do_ops->do_read_unlock);
2261 dt->do_ops->do_read_unlock(env, dt);
2264 static inline void dt_write_unlock(const struct lu_env *env,
2265 struct dt_object *dt)
2268 LASSERT(dt->do_ops);
2269 LASSERT(dt->do_ops->do_write_unlock);
2270 dt->do_ops->do_write_unlock(env, dt);
2273 static inline int dt_write_locked(const struct lu_env *env,
2274 struct dt_object *dt)
2277 LASSERT(dt->do_ops);
2278 LASSERT(dt->do_ops->do_write_locked);
2279 return dt->do_ops->do_write_locked(env, dt);
2282 static inline int dt_declare_attr_get(const struct lu_env *env,
2283 struct dt_object *dt)
2286 LASSERT(dt->do_ops);
2287 LASSERT(dt->do_ops->do_declare_attr_get);
2289 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2290 return cfs_fail_err;
2292 return dt->do_ops->do_declare_attr_get(env, dt);
2295 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2299 LASSERT(dt->do_ops);
2300 LASSERT(dt->do_ops->do_attr_get);
2302 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2303 return cfs_fail_err;
2305 return dt->do_ops->do_attr_get(env, dt, la);
2308 static inline int dt_declare_attr_set(const struct lu_env *env,
2309 struct dt_object *dt,
2310 const struct lu_attr *la,
2314 LASSERT(dt->do_ops);
2315 LASSERT(dt->do_ops->do_declare_attr_set);
2317 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2318 return cfs_fail_err;
2320 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2323 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2324 const struct lu_attr *la, struct thandle *th)
2327 LASSERT(dt->do_ops);
2328 LASSERT(dt->do_ops->do_attr_set);
2330 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2331 return cfs_fail_err;
2333 return dt->do_ops->do_attr_set(env, dt, la, th);
2336 static inline int dt_declare_ref_add(const struct lu_env *env,
2337 struct dt_object *dt, struct thandle *th)
2340 LASSERT(dt->do_ops);
2341 LASSERT(dt->do_ops->do_declare_ref_add);
2343 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2344 return cfs_fail_err;
2346 return dt->do_ops->do_declare_ref_add(env, dt, th);
2349 static inline int dt_ref_add(const struct lu_env *env,
2350 struct dt_object *dt, struct thandle *th)
2353 LASSERT(dt->do_ops);
2354 LASSERT(dt->do_ops->do_ref_add);
2356 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2357 return cfs_fail_err;
2359 return dt->do_ops->do_ref_add(env, dt, th);
2362 static inline int dt_declare_ref_del(const struct lu_env *env,
2363 struct dt_object *dt, struct thandle *th)
2366 LASSERT(dt->do_ops);
2367 LASSERT(dt->do_ops->do_declare_ref_del);
2369 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2370 return cfs_fail_err;
2372 return dt->do_ops->do_declare_ref_del(env, dt, th);
2375 static inline int dt_ref_del(const struct lu_env *env,
2376 struct dt_object *dt, struct thandle *th)
2379 LASSERT(dt->do_ops);
2380 LASSERT(dt->do_ops->do_ref_del);
2382 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2383 return cfs_fail_err;
2385 return dt->do_ops->do_ref_del(env, dt, th);
2388 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2389 struct niobuf_remote *rnb,
2390 struct niobuf_local *lnb, enum dt_bufs_type rw)
2393 LASSERT(d->do_body_ops);
2394 LASSERT(d->do_body_ops->dbo_bufs_get);
2395 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2396 rnb->rnb_len, lnb, rw);
2399 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2400 struct niobuf_local *lnb, int n)
2403 LASSERT(d->do_body_ops);
2404 LASSERT(d->do_body_ops->dbo_bufs_put);
2405 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2408 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2409 struct niobuf_local *lnb, int n)
2412 LASSERT(d->do_body_ops);
2413 LASSERT(d->do_body_ops->dbo_write_prep);
2414 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2417 static inline int dt_declare_write_commit(const struct lu_env *env,
2418 struct dt_object *d,
2419 struct niobuf_local *lnb,
2420 int n, struct thandle *th)
2422 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2423 LASSERT(th != NULL);
2424 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2428 static inline int dt_write_commit(const struct lu_env *env,
2429 struct dt_object *d, struct niobuf_local *lnb,
2430 int n, struct thandle *th)
2433 LASSERT(d->do_body_ops);
2434 LASSERT(d->do_body_ops->dbo_write_commit);
2435 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2438 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2439 struct niobuf_local *lnb, int n)
2442 LASSERT(d->do_body_ops);
2443 LASSERT(d->do_body_ops->dbo_read_prep);
2444 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2447 static inline int dt_declare_write(const struct lu_env *env,
2448 struct dt_object *dt,
2449 const struct lu_buf *buf, loff_t pos,
2453 LASSERT(dt->do_body_ops);
2454 LASSERT(dt->do_body_ops->dbo_declare_write);
2455 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2458 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2459 const struct lu_buf *buf, loff_t *pos,
2460 struct thandle *th, int rq)
2463 LASSERT(dt->do_body_ops);
2464 LASSERT(dt->do_body_ops->dbo_write);
2465 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th, rq);
2468 static inline int dt_declare_punch(const struct lu_env *env,
2469 struct dt_object *dt, __u64 start,
2470 __u64 end, struct thandle *th)
2473 LASSERT(dt->do_body_ops);
2474 LASSERT(dt->do_body_ops->dbo_declare_punch);
2475 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2478 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2479 __u64 start, __u64 end, struct thandle *th)
2482 LASSERT(dt->do_body_ops);
2483 LASSERT(dt->do_body_ops->dbo_punch);
2484 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2487 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2488 __u64 start, __u64 end, int advice)
2491 LASSERT(dt->do_body_ops);
2492 LASSERT(dt->do_body_ops->dbo_ladvise);
2493 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2496 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2500 if (d->do_body_ops == NULL)
2502 if (d->do_body_ops->dbo_fiemap_get == NULL)
2504 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2507 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2508 struct obd_statfs *osfs)
2511 LASSERT(dev->dd_ops);
2512 LASSERT(dev->dd_ops->dt_statfs);
2513 return dev->dd_ops->dt_statfs(env, dev, osfs);
2516 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2520 LASSERT(dev->dd_ops);
2521 LASSERT(dev->dd_ops->dt_root_get);
2522 return dev->dd_ops->dt_root_get(env, dev, f);
2525 static inline void dt_conf_get(const struct lu_env *env,
2526 const struct dt_device *dev,
2527 struct dt_device_param *param)
2530 LASSERT(dev->dd_ops);
2531 LASSERT(dev->dd_ops->dt_conf_get);
2532 return dev->dd_ops->dt_conf_get(env, dev, param);
2535 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2538 LASSERT(dev->dd_ops);
2539 LASSERT(dev->dd_ops->dt_sync);
2540 return dev->dd_ops->dt_sync(env, dev);
2543 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2546 LASSERT(dev->dd_ops);
2547 LASSERT(dev->dd_ops->dt_ro);
2548 return dev->dd_ops->dt_ro(env, dev);
2551 static inline int dt_declare_insert(const struct lu_env *env,
2552 struct dt_object *dt,
2553 const struct dt_rec *rec,
2554 const struct dt_key *key,
2558 LASSERT(dt->do_index_ops);
2559 LASSERT(dt->do_index_ops->dio_declare_insert);
2561 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2562 return cfs_fail_err;
2564 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2567 static inline int dt_insert(const struct lu_env *env,
2568 struct dt_object *dt,
2569 const struct dt_rec *rec,
2570 const struct dt_key *key,
2575 LASSERT(dt->do_index_ops);
2576 LASSERT(dt->do_index_ops->dio_insert);
2578 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2579 return cfs_fail_err;
2581 return dt->do_index_ops->dio_insert(env, dt, rec, key, th, noquota);
2584 static inline int dt_declare_xattr_del(const struct lu_env *env,
2585 struct dt_object *dt,
2590 LASSERT(dt->do_ops);
2591 LASSERT(dt->do_ops->do_declare_xattr_del);
2593 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2594 return cfs_fail_err;
2596 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2599 static inline int dt_xattr_del(const struct lu_env *env,
2600 struct dt_object *dt, const char *name,
2604 LASSERT(dt->do_ops);
2605 LASSERT(dt->do_ops->do_xattr_del);
2607 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2608 return cfs_fail_err;
2610 return dt->do_ops->do_xattr_del(env, dt, name, th);
2613 static inline int dt_declare_xattr_set(const struct lu_env *env,
2614 struct dt_object *dt,
2615 const struct lu_buf *buf,
2616 const char *name, int fl,
2620 LASSERT(dt->do_ops);
2621 LASSERT(dt->do_ops->do_declare_xattr_set);
2623 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2624 return cfs_fail_err;
2626 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2629 static inline int dt_xattr_set(const struct lu_env *env,
2630 struct dt_object *dt, const struct lu_buf *buf,
2631 const char *name, int fl, struct thandle *th)
2634 LASSERT(dt->do_ops);
2635 LASSERT(dt->do_ops->do_xattr_set);
2637 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2638 return cfs_fail_err;
2640 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2643 static inline int dt_declare_xattr_get(const struct lu_env *env,
2644 struct dt_object *dt,
2649 LASSERT(dt->do_ops);
2650 LASSERT(dt->do_ops->do_declare_xattr_get);
2652 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2653 return cfs_fail_err;
2655 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2658 static inline int dt_xattr_get(const struct lu_env *env,
2659 struct dt_object *dt, struct lu_buf *buf,
2663 LASSERT(dt->do_ops);
2664 LASSERT(dt->do_ops->do_xattr_get);
2666 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2667 return cfs_fail_err;
2669 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2672 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2673 const struct lu_buf *buf)
2676 LASSERT(dt->do_ops);
2677 LASSERT(dt->do_ops->do_xattr_list);
2679 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2680 return cfs_fail_err;
2682 return dt->do_ops->do_xattr_list(env, dt, buf);
2685 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2688 LASSERT(dt->do_ops);
2689 LASSERT(dt->do_ops->do_invalidate);
2691 return dt->do_ops->do_invalidate(env, dt);
2694 static inline int dt_declare_delete(const struct lu_env *env,
2695 struct dt_object *dt,
2696 const struct dt_key *key,
2700 LASSERT(dt->do_index_ops);
2701 LASSERT(dt->do_index_ops->dio_declare_delete);
2703 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2704 return cfs_fail_err;
2706 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2709 static inline int dt_delete(const struct lu_env *env,
2710 struct dt_object *dt,
2711 const struct dt_key *key,
2715 LASSERT(dt->do_index_ops);
2716 LASSERT(dt->do_index_ops->dio_delete);
2718 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2719 return cfs_fail_err;
2721 return dt->do_index_ops->dio_delete(env, dt, key, th);
2724 static inline int dt_commit_async(const struct lu_env *env,
2725 struct dt_device *dev)
2728 LASSERT(dev->dd_ops);
2729 LASSERT(dev->dd_ops->dt_commit_async);
2730 return dev->dd_ops->dt_commit_async(env, dev);
2733 static inline int dt_lookup(const struct lu_env *env,
2734 struct dt_object *dt,
2736 const struct dt_key *key)
2741 LASSERT(dt->do_index_ops);
2742 LASSERT(dt->do_index_ops->dio_lookup);
2744 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2745 return cfs_fail_err;
2747 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2755 static inline int dt_declare_layout_change(const struct lu_env *env,
2756 struct dt_object *o,
2757 struct layout_intent *layout,
2758 const struct lu_buf *buf,
2763 LASSERT(o->do_ops->do_declare_layout_change);
2764 return o->do_ops->do_declare_layout_change(env, o, layout, buf, th);
2767 static inline int dt_layout_change(const struct lu_env *env,
2768 struct dt_object *o,
2769 struct layout_intent *layout,
2770 const struct lu_buf *buf,
2775 LASSERT(o->do_ops->do_layout_change);
2776 return o->do_ops->do_layout_change(env, o, layout, buf, th);
2779 struct dt_find_hint {
2780 struct lu_fid *dfh_fid;
2781 struct dt_device *dfh_dt;
2782 struct dt_object *dfh_o;
2785 struct dt_insert_rec {
2787 const struct lu_fid *rec_fid;
2799 struct dt_thread_info {
2800 char dti_buf[DT_MAX_PATH];
2801 struct dt_find_hint dti_dfh;
2802 struct lu_attr dti_attr;
2803 struct lu_fid dti_fid;
2804 struct dt_object_format dti_dof;
2805 struct lustre_mdt_attrs dti_lma;
2806 struct lu_buf dti_lb;
2807 struct lu_object_conf dti_conf;
2809 struct dt_insert_rec dti_dt_rec;
2812 extern struct lu_context_key dt_key;
2814 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2816 struct dt_thread_info *dti;
2818 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2823 int dt_global_init(void);
2824 void dt_global_fini(void);
2826 # ifdef CONFIG_PROC_FS
2827 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2828 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2829 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2830 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2831 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2832 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2833 # endif /* CONFIG_PROC_FS */
2835 #endif /* __LUSTRE_DT_OBJECT_H */