4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #ifndef __LUSTRE_DT_OBJECT_H
34 #define __LUSTRE_DT_OBJECT_H
37 * Sub-class of lu_object with methods common for "data" objects in OST stack.
39 * Data objects behave like regular files: you can read/write them, get and
40 * set their attributes. Implementation of dt interface is supposed to
41 * implement some form of garbage collection, normally reference counting
44 * Examples: osd (lustre/osd) is an implementation of dt interface.
48 #include <obd_support.h>
50 * super-class definitions.
52 #include <lu_object.h>
54 #include <libcfs/libcfs.h>
57 struct proc_dir_entry;
63 struct dt_index_features;
66 struct ldlm_enqueue_info;
69 MNTOPT_USERXATTR = 0x00000001,
70 MNTOPT_ACL = 0x00000002,
73 struct dt_device_param {
74 unsigned ddp_max_name_len;
75 unsigned ddp_max_nlink;
76 unsigned ddp_symlink_max;
78 unsigned ddp_max_ea_size;
79 unsigned ddp_mount_type;
80 unsigned long long ddp_maxbytes;
81 /* per-inode space consumption */
83 /* maximum number of blocks in an extent */
84 unsigned ddp_max_extent_blks;
85 /* per-extent insertion overhead to be used by client for grant
87 unsigned int ddp_extent_tax;
88 unsigned int ddp_brw_size; /* optimal RPC size */
89 /* T10PI checksum type, zero if not supported */
90 enum cksum_types ddp_t10_cksum_type;
94 * Per-transaction commit callback function
96 struct dt_txn_commit_cb;
97 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
98 struct dt_txn_commit_cb *cb, int err);
100 * Special per-transaction callback for cases when just commit callback
101 * is needed and per-device callback are not convenient to use
103 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
104 #define MAX_COMMIT_CB_STR_LEN 32
106 #define DCB_TRANS_STOP 0x1
107 struct dt_txn_commit_cb {
108 struct list_head dcb_linkage;
113 char dcb_name[MAX_COMMIT_CB_STR_LEN];
117 * Operations on dt device.
119 struct dt_device_operations {
121 * Return device-wide statistics.
123 * Return device-wide stats including block size, total and
124 * free blocks, total and free objects, etc. See struct obd_statfs
127 * \param[in] env execution environment for this thread
128 * \param[in] dev dt device
129 * \param[out] osfs stats information
131 * \retval 0 on success
132 * \retval negative negated errno on error
134 int (*dt_statfs)(const struct lu_env *env,
135 struct dt_device *dev,
136 struct obd_statfs *osfs);
139 * Create transaction.
141 * Create in-memory structure representing the transaction for the
142 * caller. The structure returned will be used by the calling thread
143 * to specify the transaction the updates belong to. Once created
144 * successfully ->dt_trans_stop() must be called in any case (with
145 * ->dt_trans_start() and updates or not) so that the transaction
146 * handle and other resources can be released by the layers below.
148 * \param[in] env execution environment for this thread
149 * \param[in] dev dt device
151 * \retval pointer to handle if creation succeeds
152 * \retval ERR_PTR(errno) if creation fails
154 struct thandle *(*dt_trans_create)(const struct lu_env *env,
155 struct dt_device *dev);
160 * Start the transaction. The transaction described by \a th can be
161 * started only once. Another start is considered as an error.
162 * A thread is not supposed to start a transaction while another
163 * transaction isn't closed by the thread (though multiple handles
164 * can be created). The caller should start the transaction once
165 * all possible updates are declared (see the ->do_declare_* methods
166 * below) and all the needed resources are reserved.
168 * \param[in] env execution environment for this thread
169 * \param[in] dev dt device
170 * \param[in] th transaction handle
172 * \retval 0 on success
173 * \retval negative negated errno on error
175 int (*dt_trans_start)(const struct lu_env *env,
176 struct dt_device *dev,
182 * Once stopped the transaction described by \a th is complete (all
183 * the needed updates are applied) and further processing such as
184 * flushing to disk, sending to another target, etc, is handled by
185 * lower layers. The caller can't access this transaction by the
186 * handle anymore (except from the commit callbacks, see below).
188 * \param[in] env execution environment for this thread
189 * \param[in] dev dt device
190 * \param[in] th transaction handle
192 * \retval 0 on success
193 * \retval negative negated errno on error
195 int (*dt_trans_stop)(const struct lu_env *env,
196 struct dt_device *dev,
200 * Add commit callback to the transaction.
202 * Add a commit callback to the given transaction handle. The callback
203 * will be called when the associated transaction is stored. I.e. the
204 * transaction will survive an event like power off if the callback did
205 * run. The number of callbacks isn't limited, but you should note that
206 * some disk filesystems do handle the commit callbacks in the thread
207 * handling commit/flush of all the transactions, meaning that new
208 * transactions are blocked from commit and flush until all the
209 * callbacks are done. Also, note multiple callbacks can be running
210 * concurrently using multiple CPU cores. The callbacks will be running
211 * in a special environment which can not be used to pass data around.
213 * \param[in] th transaction handle
214 * \param[in] dcb commit callback description
216 * \retval 0 on success
217 * \retval negative negated errno on error
219 int (*dt_trans_cb_add)(struct thandle *th,
220 struct dt_txn_commit_cb *dcb);
223 * Return FID of root index object.
225 * Return the FID of the root object in the filesystem. This object
226 * is usually provided as a bootstrap point by a disk filesystem.
227 * This is up to the implementation which FID to use, though
228 * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
230 * \param[in] env execution environment for this thread
231 * \param[in] dev dt device
232 * \param[out] fid FID of the root object
234 * \retval 0 on success
235 * \retval negative negated errno on error
237 int (*dt_root_get)(const struct lu_env *env,
238 struct dt_device *dev,
242 * Return device configuration data.
244 * Return device (disk fs, actually) specific configuration.
245 * The configuration isn't subject to change at runtime.
246 * See struct dt_device_param for the details.
248 * \param[in] env execution environment for this thread
249 * \param[in] dev dt device
250 * \param[out] param configuration parameters
252 void (*dt_conf_get)(const struct lu_env *env,
253 const struct dt_device *dev,
254 struct dt_device_param *param);
259 * Sync all the cached state (dirty buffers, pages, etc) to the
260 * persistent storage. The method returns control once the sync is
261 * complete. This operation may incur significant I/O to disk and
262 * should be reserved for cases where a global sync is strictly
265 * \param[in] env execution environment for this thread
266 * \param[in] dev dt device
268 * \retval 0 on success
269 * \retval negative negated errno on error
271 int (*dt_sync)(const struct lu_env *env,
272 struct dt_device *dev);
275 * Make device read-only.
277 * Prevent new modifications to the device. This is a very specific
278 * state where all the changes are accepted successfully and the
279 * commit callbacks are called, but persistent state never changes.
280 * Used only in the tests to simulate power-off scenario.
282 * \param[in] env execution environment for this thread
283 * \param[in] dev dt device
285 * \retval 0 on success
286 * \retval negative negated errno on error
288 int (*dt_ro)(const struct lu_env *env,
289 struct dt_device *dev);
292 * Start transaction commit asynchronously.
295 * Provide a hint to the underlying filesystem that it should start
296 * committing soon. The control returns immediately. It's up to the
297 * layer implementing the method how soon to start committing. Usually
298 * this should be throttled to some extent, otherwise the number of
299 * aggregated transaction goes too high causing performance drop.
301 * \param[in] env execution environment for this thread
302 * \param[in] dev dt device
304 * \retval 0 on success
305 * \retval negative negated errno on error
307 int (*dt_commit_async)(const struct lu_env *env,
308 struct dt_device *dev);
311 struct dt_index_features {
312 /** required feature flags from enum dt_index_flags */
314 /** minimal required key size */
315 size_t dif_keysize_min;
316 /** maximal required key size, 0 if no limit */
317 size_t dif_keysize_max;
318 /** minimal required record size */
319 size_t dif_recsize_min;
320 /** maximal required record size, 0 if no limit */
321 size_t dif_recsize_max;
322 /** pointer size for record */
326 enum dt_index_flags {
327 /** index supports variable sized keys */
328 DT_IND_VARKEY = 1 << 0,
329 /** index supports variable sized records */
330 DT_IND_VARREC = 1 << 1,
331 /** index can be modified */
332 DT_IND_UPDATE = 1 << 2,
333 /** index supports records with non-unique (duplicate) keys */
334 DT_IND_NONUNQ = 1 << 3,
336 * index support fixed-size keys sorted with natural numerical way
337 * and is able to return left-side value if no exact value found
339 DT_IND_RANGE = 1 << 4,
343 * Features, required from index to support file system directories (mapping
346 extern const struct dt_index_features dt_directory_features;
347 extern const struct dt_index_features dt_otable_features;
348 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
349 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
350 extern const struct dt_index_features dt_lfsck_namespace_features;
352 /* index features supported by the accounting objects */
353 extern const struct dt_index_features dt_acct_features;
355 /* index features supported by the quota global indexes */
356 extern const struct dt_index_features dt_quota_glb_features;
358 /* index features supported by the quota slave indexes */
359 extern const struct dt_index_features dt_quota_slv_features;
361 /* index features supported by the nodemap index */
362 extern const struct dt_index_features dt_nodemap_features;
365 * This is a general purpose dt allocation hint.
366 * It now contains the parent object.
367 * It can contain any allocation hint in the future.
369 struct dt_allocation_hint {
370 struct dt_object *dah_parent;
371 const void *dah_eadata;
377 * object type specifier.
380 enum dt_format_type {
385 /** for special index */
387 /** for symbolic link */
392 * object format specifier.
394 struct dt_object_format {
395 /** type for dt object */
396 enum dt_format_type dof_type;
406 * special index need feature as parameter to create
410 const struct dt_index_features *di_feat;
415 enum dt_format_type dt_mode_to_dft(__u32 mode);
417 typedef __u64 dt_obj_version_t;
419 union ldlm_policy_data;
421 struct md_layout_change;
424 * A dt_object provides common operations to create and destroy
425 * objects and to manage regular and extended attributes.
427 struct dt_object_operations {
429 * Get read lock on object.
431 * Read lock is compatible with other read locks, so it's shared.
432 * Read lock is not compatible with write lock which is exclusive.
433 * The lock is blocking and can't be used from an interrupt context.
435 * \param[in] env execution environment for this thread
436 * \param[in] dt object to lock for reading
437 * \param[in] role a hint to debug locks (see kernel's mutexes)
439 void (*do_read_lock)(const struct lu_env *env,
440 struct dt_object *dt,
444 * Get write lock on object.
446 * Write lock is exclusive and cannot be shared. The lock is blocking
447 * and can't be used from an interrupt context.
449 * \param[in] env execution environment for this thread
450 * \param[in] dt object to lock for writing
451 * \param[in] role a hint to debug locks (see kernel's mutexes)
454 void (*do_write_lock)(const struct lu_env *env,
455 struct dt_object *dt,
461 * \param[in] env execution environment for this thread
462 * \param[in] dt object
464 void (*do_read_unlock)(const struct lu_env *env,
465 struct dt_object *dt);
468 * Release write lock.
470 * \param[in] env execution environment for this thread
471 * \param[in] dt object
473 void (*do_write_unlock)(const struct lu_env *env,
474 struct dt_object *dt);
477 * Check whether write lock is held.
479 * The caller can learn whether write lock is held on the object
481 * \param[in] env execution environment for this thread
482 * \param[in] dt object
484 * \retval 0 no write lock
485 * \retval 1 write lock is held
487 int (*do_write_locked)(const struct lu_env *env,
488 struct dt_object *dt);
491 * Declare intention to request reqular attributes.
493 * Notity the underlying filesystem that the caller may request regular
494 * attributes with ->do_attr_get() soon. This allows OSD to implement
495 * prefetching logic in an object-oriented manner. The implementation
496 * can be noop. This method should avoid expensive delays such as
497 * waiting on disk I/O, otherwise the goal of enabling a performance
498 * optimization would be defeated.
500 * \param[in] env execution environment for this thread
501 * \param[in] dt object
503 * \retval 0 on success
504 * \retval negative negated errno on error
506 int (*do_declare_attr_get)(const struct lu_env *env,
507 struct dt_object *dt);
510 * Return regular attributes.
512 * The object must exist. Currently all the attributes should be
513 * returned, but in the future this can be improved so that only
514 * a selected set is returned. This can improve performance as in
515 * some cases attributes are stored in different places and
516 * getting them all can be an iterative and expensive process.
518 * \param[in] env execution environment for this thread
519 * \param[in] dt object
520 * \param[out] attr attributes to fill
522 * \retval 0 on success
523 * \retval negative negated errno on error
525 int (*do_attr_get)(const struct lu_env *env,
526 struct dt_object *dt,
527 struct lu_attr *attr);
530 * Declare intention to change regular object's attributes.
532 * Notify the underlying filesystem that the regular attributes may
533 * change in this transaction. This enables the layer below to prepare
534 * resources (e.g. journal credits in ext4). This method should be
535 * called between creating the transaction and starting it. Note that
536 * the la_valid field of \a attr specifies which attributes will change.
537 * The object need not exist.
539 * \param[in] env execution environment for this thread
540 * \param[in] dt object
541 * \param[in] attr attributes to change specified in attr.la_valid
542 * \param[in] th transaction handle
544 * \retval 0 on success
545 * \retval negative negated errno on error
547 int (*do_declare_attr_set)(const struct lu_env *env,
548 struct dt_object *dt,
549 const struct lu_attr *attr,
553 * Change regular attributes.
555 * Change regular attributes in the given transaction. Note only
556 * attributes flagged by attr.la_valid change. The object must
557 * exist. If the layer implementing this method is responsible for
558 * quota, then the method should maintain object accounting for the
559 * given credentials when la_uid/la_gid changes.
561 * \param[in] env execution environment for this thread
562 * \param[in] dt object
563 * \param[in] attr new attributes to apply
564 * \param[in] th transaction handle
566 * \retval 0 on success
567 * \retval negative negated errno on error
569 int (*do_attr_set)(const struct lu_env *env,
570 struct dt_object *dt,
571 const struct lu_attr *attr,
575 * Declare intention to request extented attribute.
577 * Notify the underlying filesystem that the caller may request extended
578 * attribute with ->do_xattr_get() soon. This allows OSD to implement
579 * prefetching logic in an object-oriented manner. The implementation
580 * can be noop. This method should avoid expensive delays such as
581 * waiting on disk I/O, otherwise the goal of enabling a performance
582 * optimization would be defeated.
584 * \param[in] env execution environment for this thread
585 * \param[in] dt object
586 * \param[in] buf unused, may be removed in the future
587 * \param[in] name name of the extended attribute
589 * \retval 0 on success
590 * \retval negative negated errno on error
592 int (*do_declare_xattr_get)(const struct lu_env *env,
593 struct dt_object *dt,
598 * Return a value of an extended attribute.
600 * The object must exist. If the buffer is NULL, then the method
601 * must return the size of the value.
603 * \param[in] env execution environment for this thread
604 * \param[in] dt object
605 * \param[out] buf buffer in which to store the value
606 * \param[in] name name of the extended attribute
608 * \retval 0 on success
609 * \retval -ERANGE if \a buf is too small
610 * \retval negative negated errno on error
611 * \retval positive value's size if \a buf is NULL or has zero size
613 int (*do_xattr_get)(const struct lu_env *env,
614 struct dt_object *dt,
619 * Declare intention to change an extended attribute.
621 * Notify the underlying filesystem that the extended attribute may
622 * change in this transaction. This enables the layer below to prepare
623 * resources (e.g. journal credits in ext4). This method should be
624 * called between creating the transaction and starting it. The object
627 * \param[in] env execution environment for this thread
628 * \param[in] dt object
629 * \param[in] buf buffer storing new value of the attribute
630 * \param[in] name name of the attribute
631 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
632 * LU_XATTR_REPLACE - fail if EA doesn't exist
633 * \param[in] th transaction handle
635 * \retval 0 on success
636 * \retval negative negated errno on error
638 int (*do_declare_xattr_set)(const struct lu_env *env,
639 struct dt_object *dt,
640 const struct lu_buf *buf,
646 * Set an extended attribute.
648 * Change or replace the specified extended attribute (EA).
649 * The flags passed in \a fl dictate whether the EA is to be
650 * created or replaced, as follows.
651 * LU_XATTR_CREATE - fail if EA exists
652 * LU_XATTR_REPLACE - fail if EA doesn't exist
653 * The object must exist.
655 * \param[in] env execution environment for this thread
656 * \param[in] dt object
657 * \param[in] buf buffer storing new value of the attribute
658 * \param[in] name name of the attribute
659 * \param[in] fl flags indicating EA creation or replacement
660 * \param[in] th transaction handle
662 * \retval 0 on success
663 * \retval negative negated errno on error
665 int (*do_xattr_set)(const struct lu_env *env,
666 struct dt_object *dt,
667 const struct lu_buf *buf,
673 * Declare intention to delete an extended attribute.
675 * Notify the underlying filesystem that the extended attribute may
676 * be deleted in this transaction. This enables the layer below to
677 * prepare resources (e.g. journal credits in ext4). This method
678 * should be called between creating the transaction and starting it.
679 * The object need not exist.
681 * \param[in] env execution environment for this thread
682 * \param[in] dt object
683 * \param[in] name name of the attribute
684 * \param[in] th transaction handle
686 * \retval 0 on success
687 * \retval negative negated errno on error
689 int (*do_declare_xattr_del)(const struct lu_env *env,
690 struct dt_object *dt,
695 * Delete an extended attribute.
697 * This method deletes the specified extended attribute. The object
700 * \param[in] env execution environment for this thread
701 * \param[in] dt object
702 * \param[in] name name of the attribute
703 * \param[in] th transaction handle
705 * \retval 0 on success
706 * \retval negative negated errno on error
708 int (*do_xattr_del)(const struct lu_env *env,
709 struct dt_object *dt,
714 * Return a list of the extended attributes.
716 * Fills the passed buffer with a list of the extended attributes
717 * found in the object. The names are separated with '\0'.
718 * The object must exist.
720 * \param[in] env execution environment for this thread
721 * \param[in] dt object
722 * \param[out] buf buffer to put the list in
724 * \retval positive bytes used/required in the buffer
725 * \retval negative negated errno on error
727 int (*do_xattr_list)(const struct lu_env *env,
728 struct dt_object *dt,
729 const struct lu_buf *buf);
732 * Prepare allocation hint for a new object.
734 * This method is used by the caller to inform OSD of the parent-child
735 * relationship between two objects and enable efficient object
736 * allocation. Filled allocation hint will be passed to ->do_create()
739 * \param[in] env execution environment for this thread
740 * \param[out] ah allocation hint
741 * \param[in] parent parent object (can be NULL)
742 * \param[in] child child object
743 * \param[in] _mode type of the child object
745 void (*do_ah_init)(const struct lu_env *env,
746 struct dt_allocation_hint *ah,
747 struct dt_object *parent,
748 struct dt_object *child,
752 * Declare intention to create a new object.
754 * Notify the underlying filesystem that the object may be created
755 * in this transaction. This enables the layer below to prepare
756 * resources (e.g. journal credits in ext4). This method should be
757 * called between creating the transaction and starting it.
759 * If the layer implementing this method is responsible for quota,
760 * then the method should reserve an object for the given credentials
761 * and return an error if quota is over. If object creation later
762 * fails for some reason, then the reservation should be released
763 * properly (usually in ->dt_trans_stop()).
765 * \param[in] env execution environment for this thread
766 * \param[in] dt object
767 * \param[in] attr attributes of the new object
768 * \param[in] hint allocation hint
769 * \param[in] dof object format
770 * \param[in] th transaction handle
772 * \retval 0 on success
773 * \retval negative negated errno on error
775 int (*do_declare_create)(const struct lu_env *env,
776 struct dt_object *dt,
777 struct lu_attr *attr,
778 struct dt_allocation_hint *hint,
779 struct dt_object_format *dof,
785 * The method creates the object passed with the specified attributes
786 * and object format. Object allocation procedure can use information
787 * stored in the allocation hint. Different object formats are supported
788 * (see enum dt_format_type and struct dt_object_format) depending on
789 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
790 * in the LU-object header attributes.
792 * If the layer implementing this method is responsible for quota,
793 * then the method should maintain object accounting for the given
796 * \param[in] env execution environment for this thread
797 * \param[in] dt object
798 * \param[in] attr attributes of the new object
799 * \param[in] hint allocation hint
800 * \param[in] dof object format
801 * \param[in] th transaction handle
803 * \retval 0 on success
804 * \retval negative negated errno on error
806 int (*do_create)(const struct lu_env *env,
807 struct dt_object *dt,
808 struct lu_attr *attr,
809 struct dt_allocation_hint *hint,
810 struct dt_object_format *dof,
814 * Declare intention to destroy an object.
816 * Notify the underlying filesystem that the object may be destroyed
817 * in this transaction. This enables the layer below to prepare
818 * resources (e.g. journal credits in ext4). This method should be
819 * called between creating the transaction and starting it. The object
822 * \param[in] env execution environment for this thread
823 * \param[in] dt object
824 * \param[in] th transaction handle
826 * \retval 0 on success
827 * \retval negative negated errno on error
829 int (*do_declare_destroy)(const struct lu_env *env,
830 struct dt_object *dt,
836 * This method destroys the object and all the resources associated
837 * with the object (data, key/value pairs, extended attributes, etc).
838 * The object must exist. If destroy is successful, then flag
839 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
840 * instance of in-core object. Any subsequent access to the same FID
841 * should get another instance with no LOHA_EXIST flag set.
843 * If the layer implementing this method is responsible for quota,
844 * then the method should maintain object accounting for the given
847 * \param[in] env execution environment for this thread
848 * \param[in] dt object
849 * \param[in] th transaction handle
851 * \retval 0 on success
852 * \retval negative negated errno on error
854 int (*do_destroy)(const struct lu_env *env,
855 struct dt_object *dt,
859 * Try object as an index.
861 * Announce that this object is going to be used as an index. This
862 * operation checks that object supports indexing operations and
863 * installs appropriate dt_index_operations vector on success.
864 * Also probes for features. Operation is successful if all required
865 * features are supported. It's not possible to access the object
866 * with index methods before ->do_index_try() returns success.
868 * \param[in] env execution environment for this thread
869 * \param[in] dt object
870 * \param[in] feat index features
872 * \retval 0 on success
873 * \retval negative negated errno on error
875 int (*do_index_try)(const struct lu_env *env,
876 struct dt_object *dt,
877 const struct dt_index_features *feat);
880 * Declare intention to increment nlink count.
882 * Notify the underlying filesystem that the nlink regular attribute
883 * be changed in this transaction. This enables the layer below to
884 * prepare resources (e.g. journal credits in ext4). This method
885 * should be called between creating the transaction and starting it.
886 * The object need not exist.
888 * \param[in] env execution environment for this thread
889 * \param[in] dt object
890 * \param[in] th transaction handle
892 * \retval 0 on success
893 * \retval negative negated errno on error
895 int (*do_declare_ref_add)(const struct lu_env *env,
896 struct dt_object *dt,
902 * Increment nlink (from the regular attributes set) in the given
903 * transaction. Note the absolute limit for nlink should be learnt
904 * from struct dt_device_param::ddp_max_nlink. The object must exist.
906 * \param[in] env execution environment for this thread
907 * \param[in] dt object
908 * \param[in] th transaction handle
910 * \retval 0 on success
911 * \retval negative negated errno on error
913 int (*do_ref_add)(const struct lu_env *env,
914 struct dt_object *dt, struct thandle *th);
917 * Declare intention to decrement nlink count.
919 * Notify the underlying filesystem that the nlink regular attribute
920 * be changed in this transaction. This enables the layer below to
921 * prepare resources (e.g. journal credits in ext4). This method
922 * should be called between creating the transaction and starting it.
923 * The object need not exist.
925 * \param[in] env execution environment for this thread
926 * \param[in] dt object
927 * \param[in] th transaction handle
929 * \retval 0 on success
930 * \retval negative negated errno on error
932 int (*do_declare_ref_del)(const struct lu_env *env,
933 struct dt_object *dt,
939 * Decrement nlink (from the regular attributes set) in the given
940 * transaction. The object must exist.
942 * \param[in] env execution environment for this thread
943 * \param[in] dt object
944 * \param[in] th transaction handle
946 * \retval 0 on success
947 * \retval negative negated errno on error
949 int (*do_ref_del)(const struct lu_env *env,
950 struct dt_object *dt,
956 * The method is called to sync specified range of the object to a
957 * persistent storage. The control is returned once the operation is
958 * complete. The difference from ->do_sync() is that the object can
959 * be in-sync with the persistent storage (nothing to flush), then
960 * the method returns quickly with no I/O overhead. So, this method
961 * should be preferred over ->do_sync() where possible. Also note that
962 * if the object isn't clean, then some disk filesystems will call
963 * ->do_sync() to maintain overall consistency, in which case it's
964 * still very expensive.
966 * \param[in] env execution environment for this thread
967 * \param[in] dt object
968 * \param[in] start start of the range to sync
969 * \param[in] end end of the range to sync
971 * \retval 0 on success
972 * \retval negative negated errno on error
974 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
975 __u64 start, __u64 end);
980 * Lock object(s) using Distributed Lock Manager (LDLM).
982 * Get LDLM locks for the object. Currently used to lock "remote"
983 * objects in DNE configuration - a service running on MDTx needs
984 * to lock an object on MDTy.
986 * \param[in] env execution environment for this thread
987 * \param[in] dt object
988 * \param[out] lh lock handle, sometimes used, sometimes not
989 * \param[in] einfo ldlm callbacks, locking type and mode
990 * \param[out] einfo private data to be passed to unlock later
991 * \param[in] policy inodebits data
993 * \retval 0 on success
994 * \retval negative negated errno on error
996 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
997 struct lustre_handle *lh,
998 struct ldlm_enqueue_info *einfo,
999 union ldlm_policy_data *policy);
1004 * Release LDLM lock(s) granted with ->do_object_lock().
1006 * \param[in] env execution environment for this thread
1007 * \param[in] dt object
1008 * \param[in] einfo lock handles, from ->do_object_lock()
1009 * \param[in] policy inodebits data
1011 * \retval 0 on success
1012 * \retval negative negated errno on error
1014 int (*do_object_unlock)(const struct lu_env *env,
1015 struct dt_object *dt,
1016 struct ldlm_enqueue_info *einfo,
1017 union ldlm_policy_data *policy);
1020 * Invalidate attribute cache.
1022 * This method invalidate attribute cache of the object, which is on OSP
1025 * \param[in] env execution envionment for this thread
1026 * \param[in] dt object
1028 * \retval 0 on success
1029 * \retval negative negated errno on error
1031 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1034 * Declare intention to instaintiate extended layout component.
1036 * \param[in] env execution environment
1037 * \param[in] dt DT object
1038 * \param[in] layout data structure to describe the changes to
1039 * the DT object's layout
1040 * \param[in] buf buffer containing client's lovea or empty
1043 * \retval -ne error code
1045 int (*do_declare_layout_change)(const struct lu_env *env,
1046 struct dt_object *dt,
1047 struct md_layout_change *mlc,
1048 struct thandle *th);
1051 * Client is trying to write to un-instantiated layout component.
1053 * \param[in] env execution environment
1054 * \param[in] dt DT object
1055 * \param[in] layout data structure to describe the changes to
1056 * the DT object's layout
1057 * \param[in] buf buffer containing client's lovea or empty
1060 * \retval -ne error code
1062 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1063 struct md_layout_change *mlc,
1064 struct thandle *th);
1068 DT_BUFS_TYPE_READ = 0x0000,
1069 DT_BUFS_TYPE_WRITE = 0x0001,
1070 DT_BUFS_TYPE_READAHEAD = 0x0002,
1071 DT_BUFS_TYPE_LOCAL = 0x0004,
1075 * Per-dt-object operations on "file body" - unstructure raw data.
1077 struct dt_body_operations {
1081 * Read unstructured data from an existing regular object.
1082 * Only data before attr.la_size is returned.
1084 * \param[in] env execution environment for this thread
1085 * \param[in] dt object
1086 * \param[out] buf buffer (including size) to copy data in
1087 * \param[in] pos position in the object to start
1088 * \param[out] pos original value of \a pos + bytes returned
1090 * \retval positive bytes read on success
1091 * \retval negative negated errno on error
1093 ssize_t (*dbo_read)(const struct lu_env *env,
1094 struct dt_object *dt,
1099 * Declare intention to write data to object.
1101 * Notify the underlying filesystem that data may be written in
1102 * this transaction. This enables the layer below to prepare resources
1103 * (e.g. journal credits in ext4). This method should be called
1104 * between creating the transaction and starting it. The object need
1105 * not exist. If the layer implementing this method is responsible for
1106 * quota, then the method should reserve space for the given credentials
1107 * and return an error if quota is over. If the write later fails
1108 * for some reason, then the reserve should be released properly
1109 * (usually in ->dt_trans_stop()).
1111 * \param[in] env execution environment for this thread
1112 * \param[in] dt object
1113 * \param[in] buf buffer (including size) to copy data from
1114 * \param[in] pos position in the object to start
1115 * \param[in] th transaction handle
1117 * \retval 0 on success
1118 * \retval negative negated errno on error
1120 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1121 struct dt_object *dt,
1122 const struct lu_buf *buf,
1124 struct thandle *th);
1127 * Write unstructured data to regular existing object.
1129 * The method allocates space and puts data in. Also, the method should
1130 * maintain attr.la_size properly. Partial writes are possible.
1132 * If the layer implementing this method is responsible for quota,
1133 * then the method should maintain space accounting for the given
1136 * \param[in] env execution environment for this thread
1137 * \param[in] dt object
1138 * \param[in] buf buffer (including size) to copy data from
1139 * \param[in] pos position in the object to start
1140 * \param[out] pos \a pos + bytes written
1141 * \param[in] th transaction handle
1142 * \param[in] ignore unused (was used to request quota ignorance)
1144 * \retval positive bytes written on success
1145 * \retval negative negated errno on error
1147 ssize_t (*dbo_write)(const struct lu_env *env,
1148 struct dt_object *dt,
1149 const struct lu_buf *buf,
1155 * Return buffers for data.
1157 * This method is used to access data with no copying. It's so-called
1158 * zero-copy I/O. The method returns the descriptors for the internal
1159 * buffers where data are managed by the disk filesystem. For example,
1160 * pagecache in case of ext4 or ARC with ZFS. Then other components
1161 * (e.g. networking) can transfer data from or to the buffers with no
1162 * additional copying.
1164 * The method should fill an array of struct niobuf_local, where
1165 * each element describes a full or partial page for data at specific
1166 * offset. The caller should use page/lnb_page_offset/len to find data
1167 * at object's offset lnb_file_offset.
1169 * The memory referenced by the descriptors can't change its purpose
1170 * until the complementary ->dbo_bufs_put() is called. The caller should
1171 * specify if the buffers are used to read or modify data so that OSD
1172 * can decide how to initialize the buffers: bring all the data for
1173 * reads or just bring partial buffers for write. Note: the method does
1174 * not check whether output array is large enough.
1176 * \param[in] env execution environment for this thread
1177 * \param[in] dt object
1178 * \param[in] pos position in the object to start
1179 * \param[in] len size of region in bytes
1180 * \param[out] lb array of descriptors to fill
1181 * \param[in] rw 0 if used to read, 1 if used for write
1183 * \retval positive number of descriptors on success
1184 * \retval negative negated errno on error
1186 int (*dbo_bufs_get)(const struct lu_env *env,
1187 struct dt_object *dt,
1190 struct niobuf_local *lb,
1191 enum dt_bufs_type rw);
1194 * Release reference granted by ->dbo_bufs_get().
1196 * Release the reference granted by the previous ->dbo_bufs_get().
1197 * Note the references are counted.
1199 * \param[in] env execution environment for this thread
1200 * \param[in] dt object
1201 * \param[out] lb array of descriptors to fill
1202 * \param[in] nr size of the array
1204 * \retval 0 on success
1205 * \retval negative negated errno on error
1207 int (*dbo_bufs_put)(const struct lu_env *env,
1208 struct dt_object *dt,
1209 struct niobuf_local *lb,
1213 * Prepare buffers for reading.
1215 * The method is called on the given buffers to fill them with data
1216 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1217 * caller should be able to get few buffers for discontiguous regions
1218 * using few calls to ->dbo_bufs_get() and then request them all for
1219 * the preparation with a single call, so that OSD can fire many I/Os
1220 * to run concurrently. It's up to the specific OSD whether to implement
1221 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1222 * prepare data for every requested region individually.
1224 * \param[in] env execution environment for this thread
1225 * \param[in] dt object
1226 * \param[in] lnb array of buffer descriptors
1227 * \param[in] nr size of the array
1229 * \retval 0 on success
1230 * \retval negative negated errno on error
1232 int (*dbo_read_prep)(const struct lu_env *env,
1233 struct dt_object *dt,
1234 struct niobuf_local *lnb,
1238 * Prepare buffers for write.
1240 * This method is called on the given buffers to ensure the partial
1241 * buffers contain correct data. The underlying idea is the same as
1242 * in ->db_read_prep().
1244 * \param[in] env execution environment for this thread
1245 * \param[in] dt object
1246 * \param[in] lb array of buffer descriptors
1247 * \param[in] nr size of the array
1249 * \retval 0 on success
1250 * \retval negative negated errno on error
1252 int (*dbo_write_prep)(const struct lu_env *env,
1253 struct dt_object *dt,
1254 struct niobuf_local *lb,
1258 * Declare intention to write data stored in the buffers.
1260 * Notify the underlying filesystem that data may be written in
1261 * this transaction. This enables the layer below to prepare resources
1262 * (e.g. journal credits in ext4). This method should be called
1263 * between creating the transaction and starting it.
1265 * If the layer implementing this method is responsible for quota,
1266 * then the method should be reserving a space for the given
1267 * credentials and return an error if quota is exceeded. If the write
1268 * later fails for some reason, then the reserve should be released
1269 * properly (usually in ->dt_trans_stop()).
1271 * \param[in] env execution environment for this thread
1272 * \param[in] dt object
1273 * \param[in] lb array of descriptors
1274 * \param[in] nr size of the array
1275 * \param[in] th transaction handle
1277 * \retval 0 on success
1278 * \retval negative negated errno on error
1280 int (*dbo_declare_write_commit)(const struct lu_env *env,
1281 struct dt_object *dt,
1282 struct niobuf_local *lb,
1284 struct thandle *th);
1287 * Write to existing object.
1289 * This method is used to write data to a persistent storage using
1290 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1291 * data into the buffers using own mechanisms (e.g. direct transfer
1292 * from a NIC). The method should maintain attr.la_size. Also,
1293 * attr.la_blocks should be maintained but this can be done in lazy
1294 * manner, when actual allocation happens.
1296 * If the layer implementing this method is responsible for quota,
1297 * then the method should maintain space accounting for the given
1300 * \param[in] env execution environment for this thread
1301 * \param[in] dt object
1302 * \param[in] lb array of descriptors for the buffers
1303 * \param[in] nr size of the array
1304 * \param[in] th transaction handle
1306 * \retval 0 on success
1307 * \retval negative negated errno on error
1309 int (*dbo_write_commit)(const struct lu_env *env,
1310 struct dt_object *dt,
1311 struct niobuf_local *lb,
1313 struct thandle *th);
1316 * Return logical to physical block mapping for a given extent
1318 * \param[in] env execution environment for this thread
1319 * \param[in] dt object
1320 * \param[in] fm describe the region to map and the output buffer
1321 * see the details in include/linux/fiemap.h
1323 * \retval 0 on success
1324 * \retval negative negated errno on error
1326 int (*dbo_fiemap_get)(const struct lu_env *env,
1327 struct dt_object *dt,
1331 * Declare intention to deallocate space from an object.
1333 * Notify the underlying filesystem that space may be deallocated in
1334 * this transactions. This enables the layer below to prepare resources
1335 * (e.g. journal credits in ext4). This method should be called between
1336 * creating the transaction and starting it. The object need not exist.
1338 * \param[in] env execution environment for this thread
1339 * \param[in] dt object
1340 * \param[in] start the start of the region to deallocate
1341 * \param[in] end the end of the region to deallocate
1342 * \param[in] th transaction handle
1344 * \retval 0 on success
1345 * \retval negative negated errno on error
1347 int (*dbo_declare_punch)(const struct lu_env *env,
1348 struct dt_object *dt,
1351 struct thandle *th);
1354 * Deallocate specified region in an object.
1356 * This method is used to deallocate (release) space possibly consumed
1357 * by the given region of the object. If the layer implementing this
1358 * method is responsible for quota, then the method should maintain
1359 * space accounting for the given credentials.
1361 * \param[in] env execution environment for this thread
1362 * \param[in] dt object
1363 * \param[in] start the start of the region to deallocate
1364 * \param[in] end the end of the region to deallocate
1365 * \param[in] th transaction handle
1367 * \retval 0 on success
1368 * \retval negative negated errno on error
1370 int (*dbo_punch)(const struct lu_env *env,
1371 struct dt_object *dt,
1374 struct thandle *th);
1376 * Give advices on specified region in an object.
1378 * This method is used to give advices about access pattern on an
1379 * given region of the object. The disk filesystem understands
1380 * the advices and tunes cache/read-ahead policies.
1382 * \param[in] env execution environment for this thread
1383 * \param[in] dt object
1384 * \param[in] start the start of the region affected
1385 * \param[in] end the end of the region affected
1386 * \param[in] advice advice type
1388 * \retval 0 on success
1389 * \retval negative negated errno on error
1391 int (*dbo_ladvise)(const struct lu_env *env,
1392 struct dt_object *dt,
1395 enum lu_ladvise_type advice);
1399 * Incomplete type of index record.
1404 * Incomplete type of index key.
1409 * Incomplete type of dt iterator.
1414 * Per-dt-object operations on object as index. Index is a set of key/value
1415 * pairs abstracted from an on-disk representation. An index supports the
1416 * number of operations including lookup by key, insert and delete. Also,
1417 * an index can be iterated to find the pairs one by one, from a beginning
1418 * or specified point.
1420 struct dt_index_operations {
1422 * Lookup in an index by key.
1424 * The method returns a value for the given key. Key/value format
1425 * and size should have been negotiated with ->do_index_try() before.
1426 * Thus it's the caller's responsibility to provide the method with
1427 * proper key and big enough buffer. No external locking is required,
1428 * all the internal consistency should be implemented by the method
1429 * or lower layers. The object should should have been created with
1430 * type DFT_INDEX or DFT_DIR.
1432 * \param[in] env execution environment for this thread
1433 * \param[in] dt object
1434 * \param[out] rec buffer where value will be stored
1435 * \param[in] key key
1437 * \retval 0 on success
1438 * \retval -ENOENT if key isn't found
1439 * \retval negative negated errno on error
1441 int (*dio_lookup)(const struct lu_env *env,
1442 struct dt_object *dt,
1444 const struct dt_key *key);
1447 * Declare intention to insert a key/value into an index.
1449 * Notify the underlying filesystem that new key/value may be inserted
1450 * in this transaction. This enables the layer below to prepare
1451 * resources (e.g. journal credits in ext4). This method should be
1452 * called between creating the transaction and starting it. key/value
1453 * format and size is subject to ->do_index_try().
1455 * \param[in] env execution environment for this thread
1456 * \param[in] dt object
1457 * \param[in] rec buffer storing value
1458 * \param[in] key key
1459 * \param[in] th transaction handle
1461 * \retval 0 on success
1462 * \retval negative negated errno on error
1464 int (*dio_declare_insert)(const struct lu_env *env,
1465 struct dt_object *dt,
1466 const struct dt_rec *rec,
1467 const struct dt_key *key,
1468 struct thandle *th);
1471 * Insert a new key/value pair into an index.
1473 * The method inserts specified key/value pair into the given index
1474 * object. The internal consistency is maintained by the method or
1475 * the functionality below. The format and size of key/value should
1476 * have been negotiated before using ->do_index_try(), no additional
1477 * information can be specified to the method. The keys are unique
1480 * \param[in] env execution environment for this thread
1481 * \param[in] dt object
1482 * \param[in] rec buffer storing value
1483 * \param[in] key key
1484 * \param[in] th transaction handle
1485 * \param[in] ignore unused (was used to request quota ignorance)
1487 * \retval 0 on success
1488 * \retval negative negated errno on error
1490 int (*dio_insert)(const struct lu_env *env,
1491 struct dt_object *dt,
1492 const struct dt_rec *rec,
1493 const struct dt_key *key,
1498 * Declare intention to delete a key/value from an index.
1500 * Notify the underlying filesystem that key/value may be deleted in
1501 * this transaction. This enables the layer below to prepare resources
1502 * (e.g. journal credits in ext4). This method should be called
1503 * between creating the transaction and starting it. Key/value format
1504 * and size is subject to ->do_index_try(). The object need not exist.
1506 * \param[in] env execution environment for this thread
1507 * \param[in] dt object
1508 * \param[in] key key
1509 * \param[in] th transaction handle
1511 * \retval 0 on success
1512 * \retval negative negated errno on error
1514 int (*dio_declare_delete)(const struct lu_env *env,
1515 struct dt_object *dt,
1516 const struct dt_key *key,
1517 struct thandle *th);
1520 * Delete key/value pair from an index.
1522 * The method deletes specified key and corresponding value from the
1523 * given index object. The internal consistency is maintained by the
1524 * method or the functionality below. The format and size of the key
1525 * should have been negotiated before using ->do_index_try(), no
1526 * additional information can be specified to the method.
1528 * \param[in] env execution environment for this thread
1529 * \param[in] dt object
1530 * \param[in] key key
1531 * \param[in] th transaction handle
1533 * \retval 0 on success
1534 * \retval negative negated errno on error
1536 int (*dio_delete)(const struct lu_env *env,
1537 struct dt_object *dt,
1538 const struct dt_key *key,
1539 struct thandle *th);
1542 * Iterator interface.
1544 * Methods to iterate over an existing index, list the keys stored and
1545 * associated values, get key/value size, etc.
1549 * Allocate and initialize new iterator.
1551 * The iterator is a handler to be used in the subsequent
1552 * methods to access index's content. Note the position is
1553 * not defined at this point and should be initialized with
1554 * ->get() or ->load() method.
1556 * \param[in] env execution environment for this thread
1557 * \param[in] dt object
1558 * \param[in] attr ask the iterator to return part of
1559 the records, see LUDA_* for details
1561 * \retval pointer iterator pointer on success
1562 * \retval ERR_PTR(errno) on error
1564 struct dt_it *(*init)(const struct lu_env *env,
1565 struct dt_object *dt,
1571 * Release the specified iterator and all the resources
1572 * associated (e.g. the object, index cache, etc).
1574 * \param[in] env execution environment for this thread
1575 * \param[in] di iterator to release
1577 void (*fini)(const struct lu_env *env,
1581 * Move position of iterator.
1583 * Move the position of the specified iterator to the specified
1586 * \param[in] env execution environment for this thread
1587 * \param[in] di iterator
1588 * \param[in] key key to position to
1590 * \retval 0 if exact key is found
1591 * \retval 1 if at the record with least key
1592 * not larger than the key
1593 * \retval negative negated errno on error
1595 int (*get)(const struct lu_env *env,
1597 const struct dt_key *key);
1602 * Complimentary method for dt_it_ops::get() above. Some
1603 * implementation can increase a reference on the iterator in
1604 * dt_it_ops::get(). So the caller should be able to release
1605 * with dt_it_ops::put().
1607 * \param[in] env execution environment for this thread
1608 * \param[in] di iterator
1610 void (*put)(const struct lu_env *env,
1614 * Move to next record.
1616 * Moves the position of the iterator to a next record
1618 * \param[in] env execution environment for this thread
1619 * \param[in] di iterator
1621 * \retval 1 if no more records
1622 * \retval 0 on success, the next record is found
1623 * \retval negative negated errno on error
1625 int (*next)(const struct lu_env *env,
1631 * Returns a pointer to a buffer containing the key of the
1632 * record at the current position. The pointer is valid and
1633 * retains data until ->get(), ->load() and ->fini() methods
1636 * \param[in] env execution environment for this thread
1637 * \param[in] di iterator
1639 * \retval pointer to key on success
1640 * \retval ERR_PTR(errno) on error
1642 struct dt_key *(*key)(const struct lu_env *env,
1643 const struct dt_it *di);
1648 * Returns size of the key at the current position.
1650 * \param[in] env execution environment for this thread
1651 * \param[in] di iterator
1653 * \retval key's size on success
1654 * \retval negative negated errno on error
1656 int (*key_size)(const struct lu_env *env,
1657 const struct dt_it *di);
1662 * Stores the value of the record at the current position. The
1663 * buffer must be big enough (as negotiated with
1664 * ->do_index_try() or ->rec_size()). The caller can specify
1665 * she is interested only in part of the record, using attr
1666 * argument (see LUDA_* definitions for the details).
1668 * \param[in] env execution environment for this thread
1669 * \param[in] di iterator
1670 * \param[out] rec buffer to store value in
1671 * \param[in] attr specify part of the value to copy
1673 * \retval 0 on success
1674 * \retval negative negated errno on error
1676 int (*rec)(const struct lu_env *env,
1677 const struct dt_it *di,
1682 * Return record size.
1684 * Returns size of the record at the current position. The
1685 * \a attr can be used to specify only the parts of the record
1686 * needed to be returned. (see LUDA_* definitions for the
1689 * \param[in] env execution environment for this thread
1690 * \param[in] di iterator
1691 * \param[in] attr part of the record to return
1693 * \retval record's size on success
1694 * \retval negative negated errno on error
1696 int (*rec_size)(const struct lu_env *env,
1697 const struct dt_it *di,
1701 * Return a cookie (hash).
1703 * Returns the cookie (usually hash) of the key at the current
1704 * position. This allows the caller to resume iteration at this
1705 * position later. The exact value is specific to implementation
1706 * and should not be interpreted by the caller.
1708 * \param[in] env execution environment for this thread
1709 * \param[in] di iterator
1711 * \retval cookie/hash of the key
1713 __u64 (*store)(const struct lu_env *env,
1714 const struct dt_it *di);
1717 * Initialize position using cookie/hash.
1719 * Initializes the current position of the iterator to one
1720 * described by the cookie/hash as returned by ->store()
1723 * \param[in] env execution environment for this thread
1724 * \param[in] di iterator
1725 * \param[in] hash cookie/hash value
1727 * \retval positive if current position points to
1728 * record with least cookie not larger
1730 * \retval 0 if current position matches cookie
1731 * \retval negative negated errno on error
1733 int (*load)(const struct lu_env *env,
1734 const struct dt_it *di,
1740 int (*key_rec)(const struct lu_env *env,
1741 const struct dt_it *di,
1746 enum dt_otable_it_valid {
1747 DOIV_ERROR_HANDLE = 0x0001,
1748 DOIV_DRYRUN = 0x0002,
1751 enum dt_otable_it_flags {
1752 /* Exit when fail. */
1753 DOIF_FAILOUT = 0x0001,
1755 /* Reset iteration position to the device beginning. */
1756 DOIF_RESET = 0x0002,
1758 /* There is up layer component uses the iteration. */
1759 DOIF_OUTUSED = 0x0004,
1761 /* Check only without repairing. */
1762 DOIF_DRYRUN = 0x0008,
1765 /* otable based iteration needs to use the common DT iteration APIs.
1766 * To initialize the iteration, it needs call dio_it::init() firstly.
1767 * Here is how the otable based iteration should prepare arguments to
1768 * call dt_it_ops::init().
1770 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1771 * is composed of two parts:
1772 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1773 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1774 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1777 struct lu_device dd_lu_dev;
1778 const struct dt_device_operations *dd_ops;
1781 * List of dt_txn_callback (see below). This is not protected in any
1782 * way, because callbacks are supposed to be added/deleted only during
1783 * single-threaded start-up shut-down procedures.
1785 struct list_head dd_txn_callbacks;
1786 unsigned int dd_record_fid_accessed:1,
1789 /* sysfs and debugfs handling */
1790 struct dentry *dd_debugfs_entry;
1792 const struct attribute **dd_def_attrs;
1793 struct kobject dd_kobj;
1794 struct kobj_type dd_ktype;
1795 struct completion dd_kobj_unregister;
1798 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1799 void dt_device_fini(struct dt_device *dev);
1801 static inline int lu_device_is_dt(const struct lu_device *d)
1803 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1806 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1808 LASSERT(lu_device_is_dt(l));
1809 return container_of0(l, struct dt_device, dd_lu_dev);
1813 struct lu_object do_lu;
1814 const struct dt_object_operations *do_ops;
1815 const struct dt_body_operations *do_body_ops;
1816 const struct dt_index_operations *do_index_ops;
1820 * In-core representation of per-device local object OID storage
1822 struct local_oid_storage {
1823 /* all initialized llog systems on this node linked by this */
1824 struct list_head los_list;
1826 /* how many handle's reference this los has */
1827 atomic_t los_refcount;
1828 struct dt_device *los_dev;
1829 struct dt_object *los_obj;
1831 /* data used to generate new fids */
1832 struct mutex los_id_lock;
1837 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1839 return &d->dd_lu_dev;
1842 static inline struct dt_object *lu2dt(struct lu_object *l)
1844 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1845 return container_of0(l, struct dt_object, do_lu);
1848 int dt_object_init(struct dt_object *obj,
1849 struct lu_object_header *h, struct lu_device *d);
1851 void dt_object_fini(struct dt_object *obj);
1853 static inline int dt_object_exists(const struct dt_object *dt)
1855 return lu_object_exists(&dt->do_lu);
1858 static inline int dt_object_remote(const struct dt_object *dt)
1860 return lu_object_remote(&dt->do_lu);
1863 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1865 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1866 return container_of0(o, struct dt_object, do_lu);
1869 static inline struct dt_object *dt_object_child(struct dt_object *o)
1871 return container_of0(lu_object_next(&(o)->do_lu),
1872 struct dt_object, do_lu);
1876 * This is the general purpose transaction handle.
1877 * 1. Transaction Life Cycle
1878 * This transaction handle is allocated upon starting a new transaction,
1879 * and deallocated after this transaction is committed.
1880 * 2. Transaction Nesting
1881 * We do _NOT_ support nested transaction. So, every thread should only
1882 * have one active transaction, and a transaction only belongs to one
1883 * thread. Due to this, transaction handle need no reference count.
1884 * 3. Transaction & dt_object locking
1885 * dt_object locks should be taken inside transaction.
1886 * 4. Transaction & RPC
1887 * No RPC request should be issued inside transaction.
1890 /** the dt device on which the transactions are executed */
1891 struct dt_device *th_dev;
1893 /* point to the top thandle, XXX this is a bit hacky right now,
1894 * but normal device trans callback triggered by the bottom
1895 * device (OSP/OSD == sub thandle layer) needs to get the
1896 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1897 * top thandle here for now, will fix it when we have better
1898 * callback mechanism */
1899 struct thandle *th_top;
1901 /** the last operation result in this transaction.
1902 * this value is used in recovery */
1905 /** whether we need sync commit */
1906 unsigned int th_sync:1,
1907 /* local transation, no need to inform other layers */
1909 /* Whether we need wait the transaction to be submitted
1910 * (send to remote target) */
1912 /* complex transaction which will track updates on all targets,
1915 /* whether ignore quota */
1920 * Transaction call-backs.
1922 * These are invoked by osd (or underlying transaction engine) when
1923 * transaction changes state.
1925 * Call-backs are used by upper layers to modify transaction parameters and to
1926 * perform some actions on for each transaction state transition. Typical
1927 * example is mdt registering call-back to write into last-received file
1928 * before each transaction commit.
1930 struct dt_txn_callback {
1931 int (*dtc_txn_start)(const struct lu_env *env,
1932 struct thandle *txn, void *cookie);
1933 int (*dtc_txn_stop)(const struct lu_env *env,
1934 struct thandle *txn, void *cookie);
1935 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1938 struct list_head dtc_linkage;
1941 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1942 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1944 int dt_txn_hook_start(const struct lu_env *env,
1945 struct dt_device *dev, struct thandle *txn);
1946 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1947 void dt_txn_hook_commit(struct thandle *txn);
1949 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1952 * Callback function used for parsing path.
1953 * \see llo_store_resolve
1955 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1959 #define DT_MAX_PATH 1024
1961 int dt_path_parser(const struct lu_env *env,
1962 char *local, dt_entry_func_t entry_func,
1966 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1967 const char *path, struct lu_fid *fid);
1969 struct dt_object *dt_store_open(const struct lu_env *env,
1970 struct dt_device *dt,
1971 const char *dirname,
1972 const char *filename,
1973 struct lu_fid *fid);
1975 struct dt_object *dt_find_or_create(const struct lu_env *env,
1976 struct dt_device *dt,
1977 const struct lu_fid *fid,
1978 struct dt_object_format *dof,
1979 struct lu_attr *attr);
1981 struct dt_object *dt_locate_at(const struct lu_env *env,
1982 struct dt_device *dev,
1983 const struct lu_fid *fid,
1984 struct lu_device *top_dev,
1985 const struct lu_object_conf *conf);
1987 static inline struct dt_object *
1988 dt_locate(const struct lu_env *env, struct dt_device *dev,
1989 const struct lu_fid *fid)
1991 return dt_locate_at(env, dev, fid,
1992 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1995 static inline struct dt_object *
1996 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1998 struct lu_object *lo;
2000 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2001 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2002 return container_of(lo, struct dt_object, do_lu);
2007 static inline void dt_object_put(const struct lu_env *env,
2008 struct dt_object *dto)
2010 lu_object_put(env, &dto->do_lu);
2013 static inline void dt_object_put_nocache(const struct lu_env *env,
2014 struct dt_object *dto)
2016 lu_object_put_nocache(env, &dto->do_lu);
2019 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2020 const struct lu_fid *first_fid,
2021 struct local_oid_storage **los);
2022 void local_oid_storage_fini(const struct lu_env *env,
2023 struct local_oid_storage *los);
2024 int local_object_fid_generate(const struct lu_env *env,
2025 struct local_oid_storage *los,
2026 struct lu_fid *fid);
2027 int local_object_declare_create(const struct lu_env *env,
2028 struct local_oid_storage *los,
2029 struct dt_object *o,
2030 struct lu_attr *attr,
2031 struct dt_object_format *dof,
2032 struct thandle *th);
2033 int local_object_create(const struct lu_env *env,
2034 struct local_oid_storage *los,
2035 struct dt_object *o,
2036 struct lu_attr *attr, struct dt_object_format *dof,
2037 struct thandle *th);
2038 struct dt_object *local_file_find(const struct lu_env *env,
2039 struct local_oid_storage *los,
2040 struct dt_object *parent,
2042 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2043 struct local_oid_storage *los,
2044 struct dt_object *parent,
2045 const char *name, __u32 mode);
2046 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2047 struct dt_device *dt,
2048 const struct lu_fid *fid,
2049 struct dt_object *parent,
2053 local_index_find_or_create(const struct lu_env *env,
2054 struct local_oid_storage *los,
2055 struct dt_object *parent,
2056 const char *name, __u32 mode,
2057 const struct dt_index_features *ft);
2059 local_index_find_or_create_with_fid(const struct lu_env *env,
2060 struct dt_device *dt,
2061 const struct lu_fid *fid,
2062 struct dt_object *parent,
2063 const char *name, __u32 mode,
2064 const struct dt_index_features *ft);
2065 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2066 struct dt_object *parent, const char *name);
2068 static inline int dt_object_lock(const struct lu_env *env,
2069 struct dt_object *o, struct lustre_handle *lh,
2070 struct ldlm_enqueue_info *einfo,
2071 union ldlm_policy_data *policy)
2074 LASSERT(o->do_ops != NULL);
2075 LASSERT(o->do_ops->do_object_lock != NULL);
2076 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2079 static inline int dt_object_unlock(const struct lu_env *env,
2080 struct dt_object *o,
2081 struct ldlm_enqueue_info *einfo,
2082 union ldlm_policy_data *policy)
2085 LASSERT(o->do_ops != NULL);
2086 LASSERT(o->do_ops->do_object_unlock != NULL);
2087 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2090 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2091 const char *name, struct lu_fid *fid);
2093 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2094 __u64 start, __u64 end)
2098 LASSERT(o->do_ops->do_object_sync);
2099 return o->do_ops->do_object_sync(env, o, start, end);
2102 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2103 struct thandle *th);
2104 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2105 dt_obj_version_t version, struct thandle *th);
2106 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2109 int dt_read(const struct lu_env *env, struct dt_object *dt,
2110 struct lu_buf *buf, loff_t *pos);
2111 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2112 struct lu_buf *buf, loff_t *pos);
2113 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2114 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2115 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2116 union lu_page *lp, size_t nob,
2117 const struct dt_it_ops *iops,
2118 struct dt_it *it, __u32 attr, void *arg);
2119 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2120 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2122 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2123 struct idx_info *ii, const struct lu_rdpg *rdpg);
2125 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2126 struct dt_device *d)
2128 LASSERT(d->dd_ops->dt_trans_create);
2129 return d->dd_ops->dt_trans_create(env, d);
2132 static inline int dt_trans_start(const struct lu_env *env,
2133 struct dt_device *d, struct thandle *th)
2135 LASSERT(d->dd_ops->dt_trans_start);
2136 return d->dd_ops->dt_trans_start(env, d, th);
2139 /* for this transaction hooks shouldn't be called */
2140 static inline int dt_trans_start_local(const struct lu_env *env,
2141 struct dt_device *d, struct thandle *th)
2143 LASSERT(d->dd_ops->dt_trans_start);
2145 return d->dd_ops->dt_trans_start(env, d, th);
2148 static inline int dt_trans_stop(const struct lu_env *env,
2149 struct dt_device *d, struct thandle *th)
2151 LASSERT(d->dd_ops->dt_trans_stop);
2152 return d->dd_ops->dt_trans_stop(env, d, th);
2155 static inline int dt_trans_cb_add(struct thandle *th,
2156 struct dt_txn_commit_cb *dcb)
2158 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2159 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2160 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2165 static inline int dt_declare_record_write(const struct lu_env *env,
2166 struct dt_object *dt,
2167 const struct lu_buf *buf,
2173 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2174 LASSERT(th != NULL);
2175 LASSERT(dt->do_body_ops);
2176 LASSERT(dt->do_body_ops->dbo_declare_write);
2177 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2181 static inline int dt_declare_create(const struct lu_env *env,
2182 struct dt_object *dt,
2183 struct lu_attr *attr,
2184 struct dt_allocation_hint *hint,
2185 struct dt_object_format *dof,
2189 LASSERT(dt->do_ops);
2190 LASSERT(dt->do_ops->do_declare_create);
2192 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2193 return cfs_fail_err;
2195 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2198 static inline int dt_create(const struct lu_env *env,
2199 struct dt_object *dt,
2200 struct lu_attr *attr,
2201 struct dt_allocation_hint *hint,
2202 struct dt_object_format *dof,
2206 LASSERT(dt->do_ops);
2207 LASSERT(dt->do_ops->do_create);
2209 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2210 return cfs_fail_err;
2212 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2215 static inline int dt_declare_destroy(const struct lu_env *env,
2216 struct dt_object *dt,
2220 LASSERT(dt->do_ops);
2221 LASSERT(dt->do_ops->do_declare_destroy);
2223 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2224 return cfs_fail_err;
2226 return dt->do_ops->do_declare_destroy(env, dt, th);
2229 static inline int dt_destroy(const struct lu_env *env,
2230 struct dt_object *dt,
2234 LASSERT(dt->do_ops);
2235 LASSERT(dt->do_ops->do_destroy);
2237 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2238 return cfs_fail_err;
2240 return dt->do_ops->do_destroy(env, dt, th);
2243 static inline void dt_read_lock(const struct lu_env *env,
2244 struct dt_object *dt,
2248 LASSERT(dt->do_ops);
2249 LASSERT(dt->do_ops->do_read_lock);
2250 dt->do_ops->do_read_lock(env, dt, role);
2253 static inline void dt_write_lock(const struct lu_env *env,
2254 struct dt_object *dt,
2258 LASSERT(dt->do_ops);
2259 LASSERT(dt->do_ops->do_write_lock);
2260 dt->do_ops->do_write_lock(env, dt, role);
2263 static inline void dt_read_unlock(const struct lu_env *env,
2264 struct dt_object *dt)
2267 LASSERT(dt->do_ops);
2268 LASSERT(dt->do_ops->do_read_unlock);
2269 dt->do_ops->do_read_unlock(env, dt);
2272 static inline void dt_write_unlock(const struct lu_env *env,
2273 struct dt_object *dt)
2276 LASSERT(dt->do_ops);
2277 LASSERT(dt->do_ops->do_write_unlock);
2278 dt->do_ops->do_write_unlock(env, dt);
2281 static inline int dt_write_locked(const struct lu_env *env,
2282 struct dt_object *dt)
2285 LASSERT(dt->do_ops);
2286 LASSERT(dt->do_ops->do_write_locked);
2287 return dt->do_ops->do_write_locked(env, dt);
2290 static inline int dt_declare_attr_get(const struct lu_env *env,
2291 struct dt_object *dt)
2294 LASSERT(dt->do_ops);
2295 LASSERT(dt->do_ops->do_declare_attr_get);
2297 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2298 return cfs_fail_err;
2300 return dt->do_ops->do_declare_attr_get(env, dt);
2303 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2307 LASSERT(dt->do_ops);
2308 LASSERT(dt->do_ops->do_attr_get);
2310 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2311 return cfs_fail_err;
2313 return dt->do_ops->do_attr_get(env, dt, la);
2316 static inline int dt_declare_attr_set(const struct lu_env *env,
2317 struct dt_object *dt,
2318 const struct lu_attr *la,
2322 LASSERT(dt->do_ops);
2323 LASSERT(dt->do_ops->do_declare_attr_set);
2325 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2326 return cfs_fail_err;
2328 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2331 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2332 const struct lu_attr *la, struct thandle *th)
2335 LASSERT(dt->do_ops);
2336 LASSERT(dt->do_ops->do_attr_set);
2338 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2339 return cfs_fail_err;
2341 return dt->do_ops->do_attr_set(env, dt, la, th);
2344 static inline int dt_declare_ref_add(const struct lu_env *env,
2345 struct dt_object *dt, struct thandle *th)
2348 LASSERT(dt->do_ops);
2349 LASSERT(dt->do_ops->do_declare_ref_add);
2351 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2352 return cfs_fail_err;
2354 return dt->do_ops->do_declare_ref_add(env, dt, th);
2357 static inline int dt_ref_add(const struct lu_env *env,
2358 struct dt_object *dt, struct thandle *th)
2361 LASSERT(dt->do_ops);
2362 LASSERT(dt->do_ops->do_ref_add);
2364 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2365 return cfs_fail_err;
2367 return dt->do_ops->do_ref_add(env, dt, th);
2370 static inline int dt_declare_ref_del(const struct lu_env *env,
2371 struct dt_object *dt, struct thandle *th)
2374 LASSERT(dt->do_ops);
2375 LASSERT(dt->do_ops->do_declare_ref_del);
2377 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2378 return cfs_fail_err;
2380 return dt->do_ops->do_declare_ref_del(env, dt, th);
2383 static inline int dt_ref_del(const struct lu_env *env,
2384 struct dt_object *dt, struct thandle *th)
2387 LASSERT(dt->do_ops);
2388 LASSERT(dt->do_ops->do_ref_del);
2390 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2391 return cfs_fail_err;
2393 return dt->do_ops->do_ref_del(env, dt, th);
2396 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2397 struct niobuf_remote *rnb,
2398 struct niobuf_local *lnb, enum dt_bufs_type rw)
2401 LASSERT(d->do_body_ops);
2402 LASSERT(d->do_body_ops->dbo_bufs_get);
2403 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2404 rnb->rnb_len, lnb, rw);
2407 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2408 struct niobuf_local *lnb, int n)
2411 LASSERT(d->do_body_ops);
2412 LASSERT(d->do_body_ops->dbo_bufs_put);
2413 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2416 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2417 struct niobuf_local *lnb, int n)
2420 LASSERT(d->do_body_ops);
2421 LASSERT(d->do_body_ops->dbo_write_prep);
2422 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2425 static inline int dt_declare_write_commit(const struct lu_env *env,
2426 struct dt_object *d,
2427 struct niobuf_local *lnb,
2428 int n, struct thandle *th)
2430 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2431 LASSERT(th != NULL);
2432 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2436 static inline int dt_write_commit(const struct lu_env *env,
2437 struct dt_object *d, struct niobuf_local *lnb,
2438 int n, struct thandle *th)
2441 LASSERT(d->do_body_ops);
2442 LASSERT(d->do_body_ops->dbo_write_commit);
2443 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2446 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2447 struct niobuf_local *lnb, int n)
2450 LASSERT(d->do_body_ops);
2451 LASSERT(d->do_body_ops->dbo_read_prep);
2452 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2455 static inline int dt_declare_write(const struct lu_env *env,
2456 struct dt_object *dt,
2457 const struct lu_buf *buf, loff_t pos,
2461 LASSERT(dt->do_body_ops);
2462 LASSERT(dt->do_body_ops->dbo_declare_write);
2463 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2466 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2467 const struct lu_buf *buf, loff_t *pos,
2468 struct thandle *th, int rq)
2471 LASSERT(dt->do_body_ops);
2472 LASSERT(dt->do_body_ops->dbo_write);
2473 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th, rq);
2476 static inline int dt_declare_punch(const struct lu_env *env,
2477 struct dt_object *dt, __u64 start,
2478 __u64 end, struct thandle *th)
2481 LASSERT(dt->do_body_ops);
2482 LASSERT(dt->do_body_ops->dbo_declare_punch);
2483 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2486 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2487 __u64 start, __u64 end, struct thandle *th)
2490 LASSERT(dt->do_body_ops);
2491 LASSERT(dt->do_body_ops->dbo_punch);
2492 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2495 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2496 __u64 start, __u64 end, int advice)
2499 LASSERT(dt->do_body_ops);
2500 LASSERT(dt->do_body_ops->dbo_ladvise);
2501 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2504 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2508 if (d->do_body_ops == NULL)
2510 if (d->do_body_ops->dbo_fiemap_get == NULL)
2512 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2515 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2516 struct obd_statfs *osfs)
2519 LASSERT(dev->dd_ops);
2520 LASSERT(dev->dd_ops->dt_statfs);
2521 return dev->dd_ops->dt_statfs(env, dev, osfs);
2524 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2528 LASSERT(dev->dd_ops);
2529 LASSERT(dev->dd_ops->dt_root_get);
2530 return dev->dd_ops->dt_root_get(env, dev, f);
2533 static inline void dt_conf_get(const struct lu_env *env,
2534 const struct dt_device *dev,
2535 struct dt_device_param *param)
2538 LASSERT(dev->dd_ops);
2539 LASSERT(dev->dd_ops->dt_conf_get);
2540 return dev->dd_ops->dt_conf_get(env, dev, param);
2543 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2546 LASSERT(dev->dd_ops);
2547 LASSERT(dev->dd_ops->dt_sync);
2548 return dev->dd_ops->dt_sync(env, dev);
2551 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2554 LASSERT(dev->dd_ops);
2555 LASSERT(dev->dd_ops->dt_ro);
2556 return dev->dd_ops->dt_ro(env, dev);
2559 static inline int dt_declare_insert(const struct lu_env *env,
2560 struct dt_object *dt,
2561 const struct dt_rec *rec,
2562 const struct dt_key *key,
2566 LASSERT(dt->do_index_ops);
2567 LASSERT(dt->do_index_ops->dio_declare_insert);
2569 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2570 return cfs_fail_err;
2572 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2575 static inline int dt_insert(const struct lu_env *env,
2576 struct dt_object *dt,
2577 const struct dt_rec *rec,
2578 const struct dt_key *key,
2583 LASSERT(dt->do_index_ops);
2584 LASSERT(dt->do_index_ops->dio_insert);
2586 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2587 return cfs_fail_err;
2589 return dt->do_index_ops->dio_insert(env, dt, rec, key, th, noquota);
2592 static inline int dt_declare_xattr_del(const struct lu_env *env,
2593 struct dt_object *dt,
2598 LASSERT(dt->do_ops);
2599 LASSERT(dt->do_ops->do_declare_xattr_del);
2601 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2602 return cfs_fail_err;
2604 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2607 static inline int dt_xattr_del(const struct lu_env *env,
2608 struct dt_object *dt, const char *name,
2612 LASSERT(dt->do_ops);
2613 LASSERT(dt->do_ops->do_xattr_del);
2615 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2616 return cfs_fail_err;
2618 return dt->do_ops->do_xattr_del(env, dt, name, th);
2621 static inline int dt_declare_xattr_set(const struct lu_env *env,
2622 struct dt_object *dt,
2623 const struct lu_buf *buf,
2624 const char *name, int fl,
2628 LASSERT(dt->do_ops);
2629 LASSERT(dt->do_ops->do_declare_xattr_set);
2631 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2632 return cfs_fail_err;
2634 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2637 static inline int dt_xattr_set(const struct lu_env *env,
2638 struct dt_object *dt, const struct lu_buf *buf,
2639 const char *name, int fl, struct thandle *th)
2642 LASSERT(dt->do_ops);
2643 LASSERT(dt->do_ops->do_xattr_set);
2645 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2646 return cfs_fail_err;
2648 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2651 static inline int dt_declare_xattr_get(const struct lu_env *env,
2652 struct dt_object *dt,
2657 LASSERT(dt->do_ops);
2658 LASSERT(dt->do_ops->do_declare_xattr_get);
2660 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2661 return cfs_fail_err;
2663 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2666 static inline int dt_xattr_get(const struct lu_env *env,
2667 struct dt_object *dt, struct lu_buf *buf,
2671 LASSERT(dt->do_ops);
2672 LASSERT(dt->do_ops->do_xattr_get);
2674 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2675 return cfs_fail_err;
2677 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2680 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2681 const struct lu_buf *buf)
2684 LASSERT(dt->do_ops);
2685 LASSERT(dt->do_ops->do_xattr_list);
2687 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2688 return cfs_fail_err;
2690 return dt->do_ops->do_xattr_list(env, dt, buf);
2693 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2696 LASSERT(dt->do_ops);
2697 LASSERT(dt->do_ops->do_invalidate);
2699 return dt->do_ops->do_invalidate(env, dt);
2702 static inline int dt_declare_delete(const struct lu_env *env,
2703 struct dt_object *dt,
2704 const struct dt_key *key,
2708 LASSERT(dt->do_index_ops);
2709 LASSERT(dt->do_index_ops->dio_declare_delete);
2711 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2712 return cfs_fail_err;
2714 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2717 static inline int dt_delete(const struct lu_env *env,
2718 struct dt_object *dt,
2719 const struct dt_key *key,
2723 LASSERT(dt->do_index_ops);
2724 LASSERT(dt->do_index_ops->dio_delete);
2726 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2727 return cfs_fail_err;
2729 return dt->do_index_ops->dio_delete(env, dt, key, th);
2732 static inline int dt_commit_async(const struct lu_env *env,
2733 struct dt_device *dev)
2736 LASSERT(dev->dd_ops);
2737 LASSERT(dev->dd_ops->dt_commit_async);
2738 return dev->dd_ops->dt_commit_async(env, dev);
2741 static inline int dt_lookup(const struct lu_env *env,
2742 struct dt_object *dt,
2744 const struct dt_key *key)
2749 LASSERT(dt->do_index_ops);
2750 LASSERT(dt->do_index_ops->dio_lookup);
2752 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2753 return cfs_fail_err;
2755 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2763 static inline int dt_declare_layout_change(const struct lu_env *env,
2764 struct dt_object *o,
2765 struct md_layout_change *mlc,
2770 LASSERT(o->do_ops->do_declare_layout_change);
2771 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2774 static inline int dt_layout_change(const struct lu_env *env,
2775 struct dt_object *o,
2776 struct md_layout_change *mlc,
2781 LASSERT(o->do_ops->do_layout_change);
2782 return o->do_ops->do_layout_change(env, o, mlc, th);
2785 struct dt_find_hint {
2786 struct lu_fid *dfh_fid;
2787 struct dt_device *dfh_dt;
2788 struct dt_object *dfh_o;
2791 struct dt_insert_rec {
2793 const struct lu_fid *rec_fid;
2805 struct dt_thread_info {
2806 char dti_buf[DT_MAX_PATH];
2807 struct dt_find_hint dti_dfh;
2808 struct lu_attr dti_attr;
2809 struct lu_fid dti_fid;
2810 struct dt_object_format dti_dof;
2811 struct lustre_mdt_attrs dti_lma;
2812 struct lu_buf dti_lb;
2813 struct lu_object_conf dti_conf;
2815 struct dt_insert_rec dti_dt_rec;
2818 extern struct lu_context_key dt_key;
2820 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2822 struct dt_thread_info *dti;
2824 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2829 int dt_global_init(void);
2830 void dt_global_fini(void);
2831 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2832 const char *name, struct lprocfs_vars *list);
2833 int dt_tunables_fini(struct dt_device *dt);
2835 # ifdef CONFIG_PROC_FS
2836 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2837 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2838 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2839 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2840 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2841 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2842 # endif /* CONFIG_PROC_FS */
2844 #endif /* __LUSTRE_DT_OBJECT_H */