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
1143 * \retval positive bytes written on success
1144 * \retval negative negated errno on error
1146 ssize_t (*dbo_write)(const struct lu_env *env,
1147 struct dt_object *dt,
1148 const struct lu_buf *buf,
1150 struct thandle *th);
1153 * Return buffers for data.
1155 * This method is used to access data with no copying. It's so-called
1156 * zero-copy I/O. The method returns the descriptors for the internal
1157 * buffers where data are managed by the disk filesystem. For example,
1158 * pagecache in case of ext4 or ARC with ZFS. Then other components
1159 * (e.g. networking) can transfer data from or to the buffers with no
1160 * additional copying.
1162 * The method should fill an array of struct niobuf_local, where
1163 * each element describes a full or partial page for data at specific
1164 * offset. The caller should use page/lnb_page_offset/len to find data
1165 * at object's offset lnb_file_offset.
1167 * The memory referenced by the descriptors can't change its purpose
1168 * until the complementary ->dbo_bufs_put() is called. The caller should
1169 * specify if the buffers are used to read or modify data so that OSD
1170 * can decide how to initialize the buffers: bring all the data for
1171 * reads or just bring partial buffers for write. Note: the method does
1172 * not check whether output array is large enough.
1174 * \param[in] env execution environment for this thread
1175 * \param[in] dt object
1176 * \param[in] pos position in the object to start
1177 * \param[in] len size of region in bytes
1178 * \param[out] lb array of descriptors to fill
1179 * \param[in] rw 0 if used to read, 1 if used for write
1181 * \retval positive number of descriptors on success
1182 * \retval negative negated errno on error
1184 int (*dbo_bufs_get)(const struct lu_env *env,
1185 struct dt_object *dt,
1188 struct niobuf_local *lb,
1189 enum dt_bufs_type rw);
1192 * Release reference granted by ->dbo_bufs_get().
1194 * Release the reference granted by the previous ->dbo_bufs_get().
1195 * Note the references are counted.
1197 * \param[in] env execution environment for this thread
1198 * \param[in] dt object
1199 * \param[out] lb array of descriptors to fill
1200 * \param[in] nr size of the array
1202 * \retval 0 on success
1203 * \retval negative negated errno on error
1205 int (*dbo_bufs_put)(const struct lu_env *env,
1206 struct dt_object *dt,
1207 struct niobuf_local *lb,
1211 * Prepare buffers for reading.
1213 * The method is called on the given buffers to fill them with data
1214 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1215 * caller should be able to get few buffers for discontiguous regions
1216 * using few calls to ->dbo_bufs_get() and then request them all for
1217 * the preparation with a single call, so that OSD can fire many I/Os
1218 * to run concurrently. It's up to the specific OSD whether to implement
1219 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1220 * prepare data for every requested region individually.
1222 * \param[in] env execution environment for this thread
1223 * \param[in] dt object
1224 * \param[in] lnb array of buffer descriptors
1225 * \param[in] nr size of the array
1227 * \retval 0 on success
1228 * \retval negative negated errno on error
1230 int (*dbo_read_prep)(const struct lu_env *env,
1231 struct dt_object *dt,
1232 struct niobuf_local *lnb,
1236 * Prepare buffers for write.
1238 * This method is called on the given buffers to ensure the partial
1239 * buffers contain correct data. The underlying idea is the same as
1240 * in ->db_read_prep().
1242 * \param[in] env execution environment for this thread
1243 * \param[in] dt object
1244 * \param[in] lb array of buffer descriptors
1245 * \param[in] nr size of the array
1247 * \retval 0 on success
1248 * \retval negative negated errno on error
1250 int (*dbo_write_prep)(const struct lu_env *env,
1251 struct dt_object *dt,
1252 struct niobuf_local *lb,
1256 * Declare intention to write data stored in the buffers.
1258 * Notify the underlying filesystem that data may be written in
1259 * this transaction. This enables the layer below to prepare resources
1260 * (e.g. journal credits in ext4). This method should be called
1261 * between creating the transaction and starting it.
1263 * If the layer implementing this method is responsible for quota,
1264 * then the method should be reserving a space for the given
1265 * credentials and return an error if quota is exceeded. If the write
1266 * later fails for some reason, then the reserve should be released
1267 * properly (usually in ->dt_trans_stop()).
1269 * \param[in] env execution environment for this thread
1270 * \param[in] dt object
1271 * \param[in] lb array of descriptors
1272 * \param[in] nr size of the array
1273 * \param[in] th transaction handle
1275 * \retval 0 on success
1276 * \retval negative negated errno on error
1278 int (*dbo_declare_write_commit)(const struct lu_env *env,
1279 struct dt_object *dt,
1280 struct niobuf_local *lb,
1282 struct thandle *th);
1285 * Write to existing object.
1287 * This method is used to write data to a persistent storage using
1288 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1289 * data into the buffers using own mechanisms (e.g. direct transfer
1290 * from a NIC). The method should maintain attr.la_size. Also,
1291 * attr.la_blocks should be maintained but this can be done in lazy
1292 * manner, when actual allocation happens.
1294 * If the layer implementing this method is responsible for quota,
1295 * then the method should maintain space accounting for the given
1298 * \param[in] env execution environment for this thread
1299 * \param[in] dt object
1300 * \param[in] lb array of descriptors for the buffers
1301 * \param[in] nr size of the array
1302 * \param[in] th transaction handle
1304 * \retval 0 on success
1305 * \retval negative negated errno on error
1307 int (*dbo_write_commit)(const struct lu_env *env,
1308 struct dt_object *dt,
1309 struct niobuf_local *lb,
1311 struct thandle *th);
1314 * Return logical to physical block mapping for a given extent
1316 * \param[in] env execution environment for this thread
1317 * \param[in] dt object
1318 * \param[in] fm describe the region to map and the output buffer
1319 * see the details in include/linux/fiemap.h
1321 * \retval 0 on success
1322 * \retval negative negated errno on error
1324 int (*dbo_fiemap_get)(const struct lu_env *env,
1325 struct dt_object *dt,
1329 * Declare intention to deallocate space from an object.
1331 * Notify the underlying filesystem that space may be deallocated in
1332 * this transactions. This enables the layer below to prepare resources
1333 * (e.g. journal credits in ext4). This method should be called between
1334 * creating the transaction and starting it. The object need not exist.
1336 * \param[in] env execution environment for this thread
1337 * \param[in] dt object
1338 * \param[in] start the start of the region to deallocate
1339 * \param[in] end the end of the region to deallocate
1340 * \param[in] th transaction handle
1342 * \retval 0 on success
1343 * \retval negative negated errno on error
1345 int (*dbo_declare_punch)(const struct lu_env *env,
1346 struct dt_object *dt,
1349 struct thandle *th);
1352 * Deallocate specified region in an object.
1354 * This method is used to deallocate (release) space possibly consumed
1355 * by the given region of the object. If the layer implementing this
1356 * method is responsible for quota, then the method should maintain
1357 * space accounting for the given credentials.
1359 * \param[in] env execution environment for this thread
1360 * \param[in] dt object
1361 * \param[in] start the start of the region to deallocate
1362 * \param[in] end the end of the region to deallocate
1363 * \param[in] th transaction handle
1365 * \retval 0 on success
1366 * \retval negative negated errno on error
1368 int (*dbo_punch)(const struct lu_env *env,
1369 struct dt_object *dt,
1372 struct thandle *th);
1374 * Give advices on specified region in an object.
1376 * This method is used to give advices about access pattern on an
1377 * given region of the object. The disk filesystem understands
1378 * the advices and tunes cache/read-ahead policies.
1380 * \param[in] env execution environment for this thread
1381 * \param[in] dt object
1382 * \param[in] start the start of the region affected
1383 * \param[in] end the end of the region affected
1384 * \param[in] advice advice type
1386 * \retval 0 on success
1387 * \retval negative negated errno on error
1389 int (*dbo_ladvise)(const struct lu_env *env,
1390 struct dt_object *dt,
1393 enum lu_ladvise_type advice);
1397 * Incomplete type of index record.
1402 * Incomplete type of index key.
1407 * Incomplete type of dt iterator.
1412 * Per-dt-object operations on object as index. Index is a set of key/value
1413 * pairs abstracted from an on-disk representation. An index supports the
1414 * number of operations including lookup by key, insert and delete. Also,
1415 * an index can be iterated to find the pairs one by one, from a beginning
1416 * or specified point.
1418 struct dt_index_operations {
1420 * Lookup in an index by key.
1422 * The method returns a value for the given key. Key/value format
1423 * and size should have been negotiated with ->do_index_try() before.
1424 * Thus it's the caller's responsibility to provide the method with
1425 * proper key and big enough buffer. No external locking is required,
1426 * all the internal consistency should be implemented by the method
1427 * or lower layers. The object should should have been created with
1428 * type DFT_INDEX or DFT_DIR.
1430 * \param[in] env execution environment for this thread
1431 * \param[in] dt object
1432 * \param[out] rec buffer where value will be stored
1433 * \param[in] key key
1435 * \retval 0 on success
1436 * \retval -ENOENT if key isn't found
1437 * \retval negative negated errno on error
1439 int (*dio_lookup)(const struct lu_env *env,
1440 struct dt_object *dt,
1442 const struct dt_key *key);
1445 * Declare intention to insert a key/value into an index.
1447 * Notify the underlying filesystem that new key/value may be inserted
1448 * in this transaction. This enables the layer below to prepare
1449 * resources (e.g. journal credits in ext4). This method should be
1450 * called between creating the transaction and starting it. key/value
1451 * format and size is subject to ->do_index_try().
1453 * \param[in] env execution environment for this thread
1454 * \param[in] dt object
1455 * \param[in] rec buffer storing value
1456 * \param[in] key key
1457 * \param[in] th transaction handle
1459 * \retval 0 on success
1460 * \retval negative negated errno on error
1462 int (*dio_declare_insert)(const struct lu_env *env,
1463 struct dt_object *dt,
1464 const struct dt_rec *rec,
1465 const struct dt_key *key,
1466 struct thandle *th);
1469 * Insert a new key/value pair into an index.
1471 * The method inserts specified key/value pair into the given index
1472 * object. The internal consistency is maintained by the method or
1473 * the functionality below. The format and size of key/value should
1474 * have been negotiated before using ->do_index_try(), no additional
1475 * information can be specified to the method. The keys are unique
1478 * \param[in] env execution environment for this thread
1479 * \param[in] dt object
1480 * \param[in] rec buffer storing value
1481 * \param[in] key key
1482 * \param[in] th transaction handle
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,
1491 struct thandle *th);
1494 * Declare intention to delete a key/value from an index.
1496 * Notify the underlying filesystem that key/value may be deleted in
1497 * this transaction. This enables the layer below to prepare resources
1498 * (e.g. journal credits in ext4). This method should be called
1499 * between creating the transaction and starting it. Key/value format
1500 * and size is subject to ->do_index_try(). The object need not exist.
1502 * \param[in] env execution environment for this thread
1503 * \param[in] dt object
1504 * \param[in] key key
1505 * \param[in] th transaction handle
1507 * \retval 0 on success
1508 * \retval negative negated errno on error
1510 int (*dio_declare_delete)(const struct lu_env *env,
1511 struct dt_object *dt,
1512 const struct dt_key *key,
1513 struct thandle *th);
1516 * Delete key/value pair from an index.
1518 * The method deletes specified key and corresponding value from the
1519 * given index object. The internal consistency is maintained by the
1520 * method or the functionality below. The format and size of the key
1521 * should have been negotiated before using ->do_index_try(), no
1522 * additional information can be specified to the method.
1524 * \param[in] env execution environment for this thread
1525 * \param[in] dt object
1526 * \param[in] key key
1527 * \param[in] th transaction handle
1529 * \retval 0 on success
1530 * \retval negative negated errno on error
1532 int (*dio_delete)(const struct lu_env *env,
1533 struct dt_object *dt,
1534 const struct dt_key *key,
1535 struct thandle *th);
1538 * Iterator interface.
1540 * Methods to iterate over an existing index, list the keys stored and
1541 * associated values, get key/value size, etc.
1545 * Allocate and initialize new iterator.
1547 * The iterator is a handler to be used in the subsequent
1548 * methods to access index's content. Note the position is
1549 * not defined at this point and should be initialized with
1550 * ->get() or ->load() method.
1552 * \param[in] env execution environment for this thread
1553 * \param[in] dt object
1554 * \param[in] attr ask the iterator to return part of
1555 the records, see LUDA_* for details
1557 * \retval pointer iterator pointer on success
1558 * \retval ERR_PTR(errno) on error
1560 struct dt_it *(*init)(const struct lu_env *env,
1561 struct dt_object *dt,
1567 * Release the specified iterator and all the resources
1568 * associated (e.g. the object, index cache, etc).
1570 * \param[in] env execution environment for this thread
1571 * \param[in] di iterator to release
1573 void (*fini)(const struct lu_env *env,
1577 * Move position of iterator.
1579 * Move the position of the specified iterator to the specified
1582 * \param[in] env execution environment for this thread
1583 * \param[in] di iterator
1584 * \param[in] key key to position to
1586 * \retval 0 if exact key is found
1587 * \retval 1 if at the record with least key
1588 * not larger than the key
1589 * \retval negative negated errno on error
1591 int (*get)(const struct lu_env *env,
1593 const struct dt_key *key);
1598 * Complimentary method for dt_it_ops::get() above. Some
1599 * implementation can increase a reference on the iterator in
1600 * dt_it_ops::get(). So the caller should be able to release
1601 * with dt_it_ops::put().
1603 * \param[in] env execution environment for this thread
1604 * \param[in] di iterator
1606 void (*put)(const struct lu_env *env,
1610 * Move to next record.
1612 * Moves the position of the iterator to a next record
1614 * \param[in] env execution environment for this thread
1615 * \param[in] di iterator
1617 * \retval 1 if no more records
1618 * \retval 0 on success, the next record is found
1619 * \retval negative negated errno on error
1621 int (*next)(const struct lu_env *env,
1627 * Returns a pointer to a buffer containing the key of the
1628 * record at the current position. The pointer is valid and
1629 * retains data until ->get(), ->load() and ->fini() methods
1632 * \param[in] env execution environment for this thread
1633 * \param[in] di iterator
1635 * \retval pointer to key on success
1636 * \retval ERR_PTR(errno) on error
1638 struct dt_key *(*key)(const struct lu_env *env,
1639 const struct dt_it *di);
1644 * Returns size of the key at the current position.
1646 * \param[in] env execution environment for this thread
1647 * \param[in] di iterator
1649 * \retval key's size on success
1650 * \retval negative negated errno on error
1652 int (*key_size)(const struct lu_env *env,
1653 const struct dt_it *di);
1658 * Stores the value of the record at the current position. The
1659 * buffer must be big enough (as negotiated with
1660 * ->do_index_try() or ->rec_size()). The caller can specify
1661 * she is interested only in part of the record, using attr
1662 * argument (see LUDA_* definitions for the details).
1664 * \param[in] env execution environment for this thread
1665 * \param[in] di iterator
1666 * \param[out] rec buffer to store value in
1667 * \param[in] attr specify part of the value to copy
1669 * \retval 0 on success
1670 * \retval negative negated errno on error
1672 int (*rec)(const struct lu_env *env,
1673 const struct dt_it *di,
1678 * Return record size.
1680 * Returns size of the record at the current position. The
1681 * \a attr can be used to specify only the parts of the record
1682 * needed to be returned. (see LUDA_* definitions for the
1685 * \param[in] env execution environment for this thread
1686 * \param[in] di iterator
1687 * \param[in] attr part of the record to return
1689 * \retval record's size on success
1690 * \retval negative negated errno on error
1692 int (*rec_size)(const struct lu_env *env,
1693 const struct dt_it *di,
1697 * Return a cookie (hash).
1699 * Returns the cookie (usually hash) of the key at the current
1700 * position. This allows the caller to resume iteration at this
1701 * position later. The exact value is specific to implementation
1702 * and should not be interpreted by the caller.
1704 * \param[in] env execution environment for this thread
1705 * \param[in] di iterator
1707 * \retval cookie/hash of the key
1709 __u64 (*store)(const struct lu_env *env,
1710 const struct dt_it *di);
1713 * Initialize position using cookie/hash.
1715 * Initializes the current position of the iterator to one
1716 * described by the cookie/hash as returned by ->store()
1719 * \param[in] env execution environment for this thread
1720 * \param[in] di iterator
1721 * \param[in] hash cookie/hash value
1723 * \retval positive if current position points to
1724 * record with least cookie not larger
1726 * \retval 0 if current position matches cookie
1727 * \retval negative negated errno on error
1729 int (*load)(const struct lu_env *env,
1730 const struct dt_it *di,
1736 int (*key_rec)(const struct lu_env *env,
1737 const struct dt_it *di,
1742 enum dt_otable_it_valid {
1743 DOIV_ERROR_HANDLE = 0x0001,
1744 DOIV_DRYRUN = 0x0002,
1747 enum dt_otable_it_flags {
1748 /* Exit when fail. */
1749 DOIF_FAILOUT = 0x0001,
1751 /* Reset iteration position to the device beginning. */
1752 DOIF_RESET = 0x0002,
1754 /* There is up layer component uses the iteration. */
1755 DOIF_OUTUSED = 0x0004,
1757 /* Check only without repairing. */
1758 DOIF_DRYRUN = 0x0008,
1761 /* otable based iteration needs to use the common DT iteration APIs.
1762 * To initialize the iteration, it needs call dio_it::init() firstly.
1763 * Here is how the otable based iteration should prepare arguments to
1764 * call dt_it_ops::init().
1766 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1767 * is composed of two parts:
1768 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1769 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1770 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1773 struct lu_device dd_lu_dev;
1774 const struct dt_device_operations *dd_ops;
1777 * List of dt_txn_callback (see below). This is not protected in any
1778 * way, because callbacks are supposed to be added/deleted only during
1779 * single-threaded start-up shut-down procedures.
1781 struct list_head dd_txn_callbacks;
1782 unsigned int dd_record_fid_accessed:1,
1785 /* sysfs and debugfs handling */
1786 struct dentry *dd_debugfs_entry;
1788 const struct attribute **dd_def_attrs;
1789 struct kobject dd_kobj;
1790 struct kobj_type dd_ktype;
1791 struct completion dd_kobj_unregister;
1794 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1795 void dt_device_fini(struct dt_device *dev);
1797 static inline int lu_device_is_dt(const struct lu_device *d)
1799 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1802 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1804 LASSERT(lu_device_is_dt(l));
1805 return container_of0(l, struct dt_device, dd_lu_dev);
1809 struct lu_object do_lu;
1810 const struct dt_object_operations *do_ops;
1811 const struct dt_body_operations *do_body_ops;
1812 const struct dt_index_operations *do_index_ops;
1816 * In-core representation of per-device local object OID storage
1818 struct local_oid_storage {
1819 /* all initialized llog systems on this node linked by this */
1820 struct list_head los_list;
1822 /* how many handle's reference this los has */
1823 atomic_t los_refcount;
1824 struct dt_device *los_dev;
1825 struct dt_object *los_obj;
1827 /* data used to generate new fids */
1828 struct mutex los_id_lock;
1833 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1835 return &d->dd_lu_dev;
1838 static inline struct dt_object *lu2dt(struct lu_object *l)
1840 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1841 return container_of0(l, struct dt_object, do_lu);
1844 int dt_object_init(struct dt_object *obj,
1845 struct lu_object_header *h, struct lu_device *d);
1847 void dt_object_fini(struct dt_object *obj);
1849 static inline int dt_object_exists(const struct dt_object *dt)
1851 return lu_object_exists(&dt->do_lu);
1854 static inline int dt_object_remote(const struct dt_object *dt)
1856 return lu_object_remote(&dt->do_lu);
1859 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1861 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1862 return container_of0(o, struct dt_object, do_lu);
1865 static inline struct dt_object *dt_object_child(struct dt_object *o)
1867 return container_of0(lu_object_next(&(o)->do_lu),
1868 struct dt_object, do_lu);
1872 * This is the general purpose transaction handle.
1873 * 1. Transaction Life Cycle
1874 * This transaction handle is allocated upon starting a new transaction,
1875 * and deallocated after this transaction is committed.
1876 * 2. Transaction Nesting
1877 * We do _NOT_ support nested transaction. So, every thread should only
1878 * have one active transaction, and a transaction only belongs to one
1879 * thread. Due to this, transaction handle need no reference count.
1880 * 3. Transaction & dt_object locking
1881 * dt_object locks should be taken inside transaction.
1882 * 4. Transaction & RPC
1883 * No RPC request should be issued inside transaction.
1886 /** the dt device on which the transactions are executed */
1887 struct dt_device *th_dev;
1889 /* point to the top thandle, XXX this is a bit hacky right now,
1890 * but normal device trans callback triggered by the bottom
1891 * device (OSP/OSD == sub thandle layer) needs to get the
1892 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1893 * top thandle here for now, will fix it when we have better
1894 * callback mechanism */
1895 struct thandle *th_top;
1897 /** the last operation result in this transaction.
1898 * this value is used in recovery */
1901 /** whether we need sync commit */
1902 unsigned int th_sync:1,
1903 /* local transation, no need to inform other layers */
1905 /* Whether we need wait the transaction to be submitted
1906 * (send to remote target) */
1908 /* complex transaction which will track updates on all targets,
1911 /* whether ignore quota */
1916 * Transaction call-backs.
1918 * These are invoked by osd (or underlying transaction engine) when
1919 * transaction changes state.
1921 * Call-backs are used by upper layers to modify transaction parameters and to
1922 * perform some actions on for each transaction state transition. Typical
1923 * example is mdt registering call-back to write into last-received file
1924 * before each transaction commit.
1926 struct dt_txn_callback {
1927 int (*dtc_txn_start)(const struct lu_env *env,
1928 struct thandle *txn, void *cookie);
1929 int (*dtc_txn_stop)(const struct lu_env *env,
1930 struct thandle *txn, void *cookie);
1931 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1934 struct list_head dtc_linkage;
1937 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1938 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1940 int dt_txn_hook_start(const struct lu_env *env,
1941 struct dt_device *dev, struct thandle *txn);
1942 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1943 void dt_txn_hook_commit(struct thandle *txn);
1945 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1948 * Callback function used for parsing path.
1949 * \see llo_store_resolve
1951 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1955 #define DT_MAX_PATH 1024
1957 int dt_path_parser(const struct lu_env *env,
1958 char *local, dt_entry_func_t entry_func,
1962 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1963 const char *path, struct lu_fid *fid);
1965 struct dt_object *dt_store_open(const struct lu_env *env,
1966 struct dt_device *dt,
1967 const char *dirname,
1968 const char *filename,
1969 struct lu_fid *fid);
1971 struct dt_object *dt_find_or_create(const struct lu_env *env,
1972 struct dt_device *dt,
1973 const struct lu_fid *fid,
1974 struct dt_object_format *dof,
1975 struct lu_attr *attr);
1977 struct dt_object *dt_locate_at(const struct lu_env *env,
1978 struct dt_device *dev,
1979 const struct lu_fid *fid,
1980 struct lu_device *top_dev,
1981 const struct lu_object_conf *conf);
1983 static inline struct dt_object *
1984 dt_locate(const struct lu_env *env, struct dt_device *dev,
1985 const struct lu_fid *fid)
1987 return dt_locate_at(env, dev, fid,
1988 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1991 static inline struct dt_object *
1992 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1994 struct lu_object *lo;
1996 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
1997 if (lo->lo_dev == &dt_dev->dd_lu_dev)
1998 return container_of(lo, struct dt_object, do_lu);
2003 static inline void dt_object_put(const struct lu_env *env,
2004 struct dt_object *dto)
2006 lu_object_put(env, &dto->do_lu);
2009 static inline void dt_object_put_nocache(const struct lu_env *env,
2010 struct dt_object *dto)
2012 lu_object_put_nocache(env, &dto->do_lu);
2015 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2016 const struct lu_fid *first_fid,
2017 struct local_oid_storage **los);
2018 void local_oid_storage_fini(const struct lu_env *env,
2019 struct local_oid_storage *los);
2020 int local_object_fid_generate(const struct lu_env *env,
2021 struct local_oid_storage *los,
2022 struct lu_fid *fid);
2023 int local_object_declare_create(const struct lu_env *env,
2024 struct local_oid_storage *los,
2025 struct dt_object *o,
2026 struct lu_attr *attr,
2027 struct dt_object_format *dof,
2028 struct thandle *th);
2029 int local_object_create(const struct lu_env *env,
2030 struct local_oid_storage *los,
2031 struct dt_object *o,
2032 struct lu_attr *attr, struct dt_object_format *dof,
2033 struct thandle *th);
2034 struct dt_object *local_file_find(const struct lu_env *env,
2035 struct local_oid_storage *los,
2036 struct dt_object *parent,
2038 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2039 struct local_oid_storage *los,
2040 struct dt_object *parent,
2041 const char *name, __u32 mode);
2042 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2043 struct dt_device *dt,
2044 const struct lu_fid *fid,
2045 struct dt_object *parent,
2049 local_index_find_or_create(const struct lu_env *env,
2050 struct local_oid_storage *los,
2051 struct dt_object *parent,
2052 const char *name, __u32 mode,
2053 const struct dt_index_features *ft);
2055 local_index_find_or_create_with_fid(const struct lu_env *env,
2056 struct dt_device *dt,
2057 const struct lu_fid *fid,
2058 struct dt_object *parent,
2059 const char *name, __u32 mode,
2060 const struct dt_index_features *ft);
2061 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2062 struct dt_object *parent, const char *name);
2064 static inline int dt_object_lock(const struct lu_env *env,
2065 struct dt_object *o, struct lustre_handle *lh,
2066 struct ldlm_enqueue_info *einfo,
2067 union ldlm_policy_data *policy)
2070 LASSERT(o->do_ops != NULL);
2071 LASSERT(o->do_ops->do_object_lock != NULL);
2072 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2075 static inline int dt_object_unlock(const struct lu_env *env,
2076 struct dt_object *o,
2077 struct ldlm_enqueue_info *einfo,
2078 union ldlm_policy_data *policy)
2081 LASSERT(o->do_ops != NULL);
2082 LASSERT(o->do_ops->do_object_unlock != NULL);
2083 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2086 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2087 const char *name, struct lu_fid *fid);
2089 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2090 __u64 start, __u64 end)
2094 LASSERT(o->do_ops->do_object_sync);
2095 return o->do_ops->do_object_sync(env, o, start, end);
2098 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2099 struct thandle *th);
2100 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2101 dt_obj_version_t version, struct thandle *th);
2102 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2105 int dt_read(const struct lu_env *env, struct dt_object *dt,
2106 struct lu_buf *buf, loff_t *pos);
2107 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2108 struct lu_buf *buf, loff_t *pos);
2109 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2110 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2111 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2112 union lu_page *lp, size_t nob,
2113 const struct dt_it_ops *iops,
2114 struct dt_it *it, __u32 attr, void *arg);
2115 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2116 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2118 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2119 struct idx_info *ii, const struct lu_rdpg *rdpg);
2121 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2122 struct dt_device *d)
2124 LASSERT(d->dd_ops->dt_trans_create);
2125 return d->dd_ops->dt_trans_create(env, d);
2128 static inline int dt_trans_start(const struct lu_env *env,
2129 struct dt_device *d, struct thandle *th)
2131 LASSERT(d->dd_ops->dt_trans_start);
2132 return d->dd_ops->dt_trans_start(env, d, th);
2135 /* for this transaction hooks shouldn't be called */
2136 static inline int dt_trans_start_local(const struct lu_env *env,
2137 struct dt_device *d, struct thandle *th)
2139 LASSERT(d->dd_ops->dt_trans_start);
2141 return d->dd_ops->dt_trans_start(env, d, th);
2144 static inline int dt_trans_stop(const struct lu_env *env,
2145 struct dt_device *d, struct thandle *th)
2147 LASSERT(d->dd_ops->dt_trans_stop);
2148 return d->dd_ops->dt_trans_stop(env, d, th);
2151 static inline int dt_trans_cb_add(struct thandle *th,
2152 struct dt_txn_commit_cb *dcb)
2154 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2155 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2156 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2161 static inline int dt_declare_record_write(const struct lu_env *env,
2162 struct dt_object *dt,
2163 const struct lu_buf *buf,
2169 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2170 LASSERT(th != NULL);
2171 LASSERT(dt->do_body_ops);
2172 LASSERT(dt->do_body_ops->dbo_declare_write);
2173 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2177 static inline int dt_declare_create(const struct lu_env *env,
2178 struct dt_object *dt,
2179 struct lu_attr *attr,
2180 struct dt_allocation_hint *hint,
2181 struct dt_object_format *dof,
2185 LASSERT(dt->do_ops);
2186 LASSERT(dt->do_ops->do_declare_create);
2188 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2189 return cfs_fail_err;
2191 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2194 static inline int dt_create(const struct lu_env *env,
2195 struct dt_object *dt,
2196 struct lu_attr *attr,
2197 struct dt_allocation_hint *hint,
2198 struct dt_object_format *dof,
2202 LASSERT(dt->do_ops);
2203 LASSERT(dt->do_ops->do_create);
2205 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2206 return cfs_fail_err;
2208 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2211 static inline int dt_declare_destroy(const struct lu_env *env,
2212 struct dt_object *dt,
2216 LASSERT(dt->do_ops);
2217 LASSERT(dt->do_ops->do_declare_destroy);
2219 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2220 return cfs_fail_err;
2222 return dt->do_ops->do_declare_destroy(env, dt, th);
2225 static inline int dt_destroy(const struct lu_env *env,
2226 struct dt_object *dt,
2230 LASSERT(dt->do_ops);
2231 LASSERT(dt->do_ops->do_destroy);
2233 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2234 return cfs_fail_err;
2236 return dt->do_ops->do_destroy(env, dt, th);
2239 static inline void dt_read_lock(const struct lu_env *env,
2240 struct dt_object *dt,
2244 LASSERT(dt->do_ops);
2245 LASSERT(dt->do_ops->do_read_lock);
2246 dt->do_ops->do_read_lock(env, dt, role);
2249 static inline void dt_write_lock(const struct lu_env *env,
2250 struct dt_object *dt,
2254 LASSERT(dt->do_ops);
2255 LASSERT(dt->do_ops->do_write_lock);
2256 dt->do_ops->do_write_lock(env, dt, role);
2259 static inline void dt_read_unlock(const struct lu_env *env,
2260 struct dt_object *dt)
2263 LASSERT(dt->do_ops);
2264 LASSERT(dt->do_ops->do_read_unlock);
2265 dt->do_ops->do_read_unlock(env, dt);
2268 static inline void dt_write_unlock(const struct lu_env *env,
2269 struct dt_object *dt)
2272 LASSERT(dt->do_ops);
2273 LASSERT(dt->do_ops->do_write_unlock);
2274 dt->do_ops->do_write_unlock(env, dt);
2277 static inline int dt_write_locked(const struct lu_env *env,
2278 struct dt_object *dt)
2281 LASSERT(dt->do_ops);
2282 LASSERT(dt->do_ops->do_write_locked);
2283 return dt->do_ops->do_write_locked(env, dt);
2286 static inline int dt_declare_attr_get(const struct lu_env *env,
2287 struct dt_object *dt)
2290 LASSERT(dt->do_ops);
2291 LASSERT(dt->do_ops->do_declare_attr_get);
2293 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2294 return cfs_fail_err;
2296 return dt->do_ops->do_declare_attr_get(env, dt);
2299 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2303 LASSERT(dt->do_ops);
2304 LASSERT(dt->do_ops->do_attr_get);
2306 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2307 return cfs_fail_err;
2309 return dt->do_ops->do_attr_get(env, dt, la);
2312 static inline int dt_declare_attr_set(const struct lu_env *env,
2313 struct dt_object *dt,
2314 const struct lu_attr *la,
2318 LASSERT(dt->do_ops);
2319 LASSERT(dt->do_ops->do_declare_attr_set);
2321 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2322 return cfs_fail_err;
2324 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2327 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2328 const struct lu_attr *la, struct thandle *th)
2331 LASSERT(dt->do_ops);
2332 LASSERT(dt->do_ops->do_attr_set);
2334 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2335 return cfs_fail_err;
2337 return dt->do_ops->do_attr_set(env, dt, la, th);
2340 static inline int dt_declare_ref_add(const struct lu_env *env,
2341 struct dt_object *dt, struct thandle *th)
2344 LASSERT(dt->do_ops);
2345 LASSERT(dt->do_ops->do_declare_ref_add);
2347 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2348 return cfs_fail_err;
2350 return dt->do_ops->do_declare_ref_add(env, dt, th);
2353 static inline int dt_ref_add(const struct lu_env *env,
2354 struct dt_object *dt, struct thandle *th)
2357 LASSERT(dt->do_ops);
2358 LASSERT(dt->do_ops->do_ref_add);
2360 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2361 return cfs_fail_err;
2363 return dt->do_ops->do_ref_add(env, dt, th);
2366 static inline int dt_declare_ref_del(const struct lu_env *env,
2367 struct dt_object *dt, struct thandle *th)
2370 LASSERT(dt->do_ops);
2371 LASSERT(dt->do_ops->do_declare_ref_del);
2373 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2374 return cfs_fail_err;
2376 return dt->do_ops->do_declare_ref_del(env, dt, th);
2379 static inline int dt_ref_del(const struct lu_env *env,
2380 struct dt_object *dt, struct thandle *th)
2383 LASSERT(dt->do_ops);
2384 LASSERT(dt->do_ops->do_ref_del);
2386 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2387 return cfs_fail_err;
2389 return dt->do_ops->do_ref_del(env, dt, th);
2392 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2393 struct niobuf_remote *rnb,
2394 struct niobuf_local *lnb, enum dt_bufs_type rw)
2397 LASSERT(d->do_body_ops);
2398 LASSERT(d->do_body_ops->dbo_bufs_get);
2399 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2400 rnb->rnb_len, lnb, rw);
2403 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2404 struct niobuf_local *lnb, int n)
2407 LASSERT(d->do_body_ops);
2408 LASSERT(d->do_body_ops->dbo_bufs_put);
2409 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2412 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2413 struct niobuf_local *lnb, int n)
2416 LASSERT(d->do_body_ops);
2417 LASSERT(d->do_body_ops->dbo_write_prep);
2418 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2421 static inline int dt_declare_write_commit(const struct lu_env *env,
2422 struct dt_object *d,
2423 struct niobuf_local *lnb,
2424 int n, struct thandle *th)
2426 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2427 LASSERT(th != NULL);
2428 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2432 static inline int dt_write_commit(const struct lu_env *env,
2433 struct dt_object *d, struct niobuf_local *lnb,
2434 int n, struct thandle *th)
2437 LASSERT(d->do_body_ops);
2438 LASSERT(d->do_body_ops->dbo_write_commit);
2439 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2442 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2443 struct niobuf_local *lnb, int n)
2446 LASSERT(d->do_body_ops);
2447 LASSERT(d->do_body_ops->dbo_read_prep);
2448 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2451 static inline int dt_declare_write(const struct lu_env *env,
2452 struct dt_object *dt,
2453 const struct lu_buf *buf, loff_t pos,
2457 LASSERT(dt->do_body_ops);
2458 LASSERT(dt->do_body_ops->dbo_declare_write);
2459 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2462 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2463 const struct lu_buf *buf, loff_t *pos,
2467 LASSERT(dt->do_body_ops);
2468 LASSERT(dt->do_body_ops->dbo_write);
2469 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2472 static inline int dt_declare_punch(const struct lu_env *env,
2473 struct dt_object *dt, __u64 start,
2474 __u64 end, struct thandle *th)
2477 LASSERT(dt->do_body_ops);
2478 LASSERT(dt->do_body_ops->dbo_declare_punch);
2479 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2482 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2483 __u64 start, __u64 end, struct thandle *th)
2486 LASSERT(dt->do_body_ops);
2487 LASSERT(dt->do_body_ops->dbo_punch);
2488 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2491 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2492 __u64 start, __u64 end, int advice)
2495 LASSERT(dt->do_body_ops);
2496 LASSERT(dt->do_body_ops->dbo_ladvise);
2497 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2500 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2504 if (d->do_body_ops == NULL)
2506 if (d->do_body_ops->dbo_fiemap_get == NULL)
2508 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2511 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2512 struct obd_statfs *osfs)
2515 LASSERT(dev->dd_ops);
2516 LASSERT(dev->dd_ops->dt_statfs);
2517 return dev->dd_ops->dt_statfs(env, dev, osfs);
2520 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2524 LASSERT(dev->dd_ops);
2525 LASSERT(dev->dd_ops->dt_root_get);
2526 return dev->dd_ops->dt_root_get(env, dev, f);
2529 static inline void dt_conf_get(const struct lu_env *env,
2530 const struct dt_device *dev,
2531 struct dt_device_param *param)
2534 LASSERT(dev->dd_ops);
2535 LASSERT(dev->dd_ops->dt_conf_get);
2536 return dev->dd_ops->dt_conf_get(env, dev, param);
2539 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2542 LASSERT(dev->dd_ops);
2543 LASSERT(dev->dd_ops->dt_sync);
2544 return dev->dd_ops->dt_sync(env, dev);
2547 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2550 LASSERT(dev->dd_ops);
2551 LASSERT(dev->dd_ops->dt_ro);
2552 return dev->dd_ops->dt_ro(env, dev);
2555 static inline int dt_declare_insert(const struct lu_env *env,
2556 struct dt_object *dt,
2557 const struct dt_rec *rec,
2558 const struct dt_key *key,
2562 LASSERT(dt->do_index_ops);
2563 LASSERT(dt->do_index_ops->dio_declare_insert);
2565 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2566 return cfs_fail_err;
2568 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2571 static inline int dt_insert(const struct lu_env *env,
2572 struct dt_object *dt,
2573 const struct dt_rec *rec,
2574 const struct dt_key *key,
2578 LASSERT(dt->do_index_ops);
2579 LASSERT(dt->do_index_ops->dio_insert);
2581 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2582 return cfs_fail_err;
2584 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2587 static inline int dt_declare_xattr_del(const struct lu_env *env,
2588 struct dt_object *dt,
2593 LASSERT(dt->do_ops);
2594 LASSERT(dt->do_ops->do_declare_xattr_del);
2596 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2597 return cfs_fail_err;
2599 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2602 static inline int dt_xattr_del(const struct lu_env *env,
2603 struct dt_object *dt, const char *name,
2607 LASSERT(dt->do_ops);
2608 LASSERT(dt->do_ops->do_xattr_del);
2610 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2611 return cfs_fail_err;
2613 return dt->do_ops->do_xattr_del(env, dt, name, th);
2616 static inline int dt_declare_xattr_set(const struct lu_env *env,
2617 struct dt_object *dt,
2618 const struct lu_buf *buf,
2619 const char *name, int fl,
2623 LASSERT(dt->do_ops);
2624 LASSERT(dt->do_ops->do_declare_xattr_set);
2626 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2627 return cfs_fail_err;
2629 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2632 static inline int dt_xattr_set(const struct lu_env *env,
2633 struct dt_object *dt, const struct lu_buf *buf,
2634 const char *name, int fl, struct thandle *th)
2637 LASSERT(dt->do_ops);
2638 LASSERT(dt->do_ops->do_xattr_set);
2640 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2641 return cfs_fail_err;
2643 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2646 static inline int dt_declare_xattr_get(const struct lu_env *env,
2647 struct dt_object *dt,
2652 LASSERT(dt->do_ops);
2653 LASSERT(dt->do_ops->do_declare_xattr_get);
2655 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2656 return cfs_fail_err;
2658 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2661 static inline int dt_xattr_get(const struct lu_env *env,
2662 struct dt_object *dt, struct lu_buf *buf,
2666 LASSERT(dt->do_ops);
2667 LASSERT(dt->do_ops->do_xattr_get);
2669 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2670 return cfs_fail_err;
2672 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2675 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2676 const struct lu_buf *buf)
2679 LASSERT(dt->do_ops);
2680 LASSERT(dt->do_ops->do_xattr_list);
2682 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2683 return cfs_fail_err;
2685 return dt->do_ops->do_xattr_list(env, dt, buf);
2688 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2691 LASSERT(dt->do_ops);
2692 LASSERT(dt->do_ops->do_invalidate);
2694 return dt->do_ops->do_invalidate(env, dt);
2697 static inline int dt_declare_delete(const struct lu_env *env,
2698 struct dt_object *dt,
2699 const struct dt_key *key,
2703 LASSERT(dt->do_index_ops);
2704 LASSERT(dt->do_index_ops->dio_declare_delete);
2706 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2707 return cfs_fail_err;
2709 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2712 static inline int dt_delete(const struct lu_env *env,
2713 struct dt_object *dt,
2714 const struct dt_key *key,
2718 LASSERT(dt->do_index_ops);
2719 LASSERT(dt->do_index_ops->dio_delete);
2721 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2722 return cfs_fail_err;
2724 return dt->do_index_ops->dio_delete(env, dt, key, th);
2727 static inline int dt_commit_async(const struct lu_env *env,
2728 struct dt_device *dev)
2731 LASSERT(dev->dd_ops);
2732 LASSERT(dev->dd_ops->dt_commit_async);
2733 return dev->dd_ops->dt_commit_async(env, dev);
2736 static inline int dt_lookup(const struct lu_env *env,
2737 struct dt_object *dt,
2739 const struct dt_key *key)
2744 LASSERT(dt->do_index_ops);
2745 LASSERT(dt->do_index_ops->dio_lookup);
2747 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2748 return cfs_fail_err;
2750 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2758 static inline int dt_declare_layout_change(const struct lu_env *env,
2759 struct dt_object *o,
2760 struct md_layout_change *mlc,
2765 LASSERT(o->do_ops->do_declare_layout_change);
2766 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2769 static inline int dt_layout_change(const struct lu_env *env,
2770 struct dt_object *o,
2771 struct md_layout_change *mlc,
2776 LASSERT(o->do_ops->do_layout_change);
2777 return o->do_ops->do_layout_change(env, o, mlc, th);
2780 struct dt_find_hint {
2781 struct lu_fid *dfh_fid;
2782 struct dt_device *dfh_dt;
2783 struct dt_object *dfh_o;
2786 struct dt_insert_rec {
2788 const struct lu_fid *rec_fid;
2800 struct dt_thread_info {
2801 char dti_buf[DT_MAX_PATH];
2802 struct dt_find_hint dti_dfh;
2803 struct lu_attr dti_attr;
2804 struct lu_fid dti_fid;
2805 struct dt_object_format dti_dof;
2806 struct lustre_mdt_attrs dti_lma;
2807 struct lu_buf dti_lb;
2808 struct lu_object_conf dti_conf;
2810 struct dt_insert_rec dti_dt_rec;
2813 extern struct lu_context_key dt_key;
2815 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2817 struct dt_thread_info *dti;
2819 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2824 int dt_global_init(void);
2825 void dt_global_fini(void);
2826 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2827 const char *name, struct lprocfs_vars *list);
2828 int dt_tunables_fini(struct dt_device *dt);
2830 # ifdef CONFIG_PROC_FS
2831 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2832 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2833 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2834 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2835 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2836 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2837 # endif /* CONFIG_PROC_FS */
2839 #endif /* __LUSTRE_DT_OBJECT_H */