4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #ifndef __LUSTRE_DT_OBJECT_H
34 #define __LUSTRE_DT_OBJECT_H
37 * Sub-class of lu_object with methods common for "data" objects in OST stack.
39 * Data objects behave like regular files: you can read/write them, get and
40 * set their attributes. Implementation of dt interface is supposed to
41 * implement some form of garbage collection, normally reference counting
44 * Examples: osd (lustre/osd) is an implementation of dt interface.
48 #include <obd_support.h>
50 * super-class definitions.
52 #include <lu_object.h>
54 #include <libcfs/libcfs.h>
57 struct proc_dir_entry;
63 struct dt_index_features;
66 struct ldlm_enqueue_info;
69 MNTOPT_USERXATTR = 0x00000001,
70 MNTOPT_ACL = 0x00000002,
73 struct dt_device_param {
74 unsigned ddp_max_name_len;
75 unsigned ddp_max_nlink;
76 unsigned ddp_symlink_max;
78 unsigned ddp_max_ea_size;
79 unsigned ddp_mount_type;
80 unsigned long long ddp_maxbytes;
81 /* per-inode space consumption */
83 /* maximum number of blocks in an extent */
84 unsigned ddp_max_extent_blks;
85 /* per-extent insertion overhead to be used by client for grant
87 unsigned int ddp_extent_tax;
88 unsigned int ddp_brw_size; /* optimal RPC size */
89 /* T10PI checksum type, zero if not supported */
90 enum cksum_types ddp_t10_cksum_type;
94 * Per-transaction commit callback function
96 struct dt_txn_commit_cb;
97 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
98 struct dt_txn_commit_cb *cb, int err);
100 * Special per-transaction callback for cases when just commit callback
101 * is needed and per-device callback are not convenient to use
103 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
104 #define MAX_COMMIT_CB_STR_LEN 32
106 #define DCB_TRANS_STOP 0x1
107 struct dt_txn_commit_cb {
108 struct list_head dcb_linkage;
113 char dcb_name[MAX_COMMIT_CB_STR_LEN];
117 * Operations on dt device.
119 struct dt_device_operations {
121 * Return device-wide statistics.
123 * Return device-wide stats including block size, total and
124 * free blocks, total and free objects, etc. See struct obd_statfs
127 * \param[in] env execution environment for this thread
128 * \param[in] dev dt device
129 * \param[out] osfs stats information
131 * \retval 0 on success
132 * \retval negative negated errno on error
134 int (*dt_statfs)(const struct lu_env *env,
135 struct dt_device *dev,
136 struct obd_statfs *osfs,
137 struct obd_statfs_info *info);
140 * Create transaction.
142 * Create in-memory structure representing the transaction for the
143 * caller. The structure returned will be used by the calling thread
144 * to specify the transaction the updates belong to. Once created
145 * successfully ->dt_trans_stop() must be called in any case (with
146 * ->dt_trans_start() and updates or not) so that the transaction
147 * handle and other resources can be released by the layers below.
149 * \param[in] env execution environment for this thread
150 * \param[in] dev dt device
152 * \retval pointer to handle if creation succeeds
153 * \retval ERR_PTR(errno) if creation fails
155 struct thandle *(*dt_trans_create)(const struct lu_env *env,
156 struct dt_device *dev);
161 * Start the transaction. The transaction described by \a th can be
162 * started only once. Another start is considered as an error.
163 * A thread is not supposed to start a transaction while another
164 * transaction isn't closed by the thread (though multiple handles
165 * can be created). The caller should start the transaction once
166 * all possible updates are declared (see the ->do_declare_* methods
167 * below) and all the needed resources are reserved.
169 * \param[in] env execution environment for this thread
170 * \param[in] dev dt device
171 * \param[in] th transaction handle
173 * \retval 0 on success
174 * \retval negative negated errno on error
176 int (*dt_trans_start)(const struct lu_env *env,
177 struct dt_device *dev,
183 * Once stopped the transaction described by \a th is complete (all
184 * the needed updates are applied) and further processing such as
185 * flushing to disk, sending to another target, etc, is handled by
186 * lower layers. The caller can't access this transaction by the
187 * handle anymore (except from the commit callbacks, see below).
189 * \param[in] env execution environment for this thread
190 * \param[in] dev dt device
191 * \param[in] th transaction handle
193 * \retval 0 on success
194 * \retval negative negated errno on error
196 int (*dt_trans_stop)(const struct lu_env *env,
197 struct dt_device *dev,
201 * Add commit callback to the transaction.
203 * Add a commit callback to the given transaction handle. The callback
204 * will be called when the associated transaction is stored. I.e. the
205 * transaction will survive an event like power off if the callback did
206 * run. The number of callbacks isn't limited, but you should note that
207 * some disk filesystems do handle the commit callbacks in the thread
208 * handling commit/flush of all the transactions, meaning that new
209 * transactions are blocked from commit and flush until all the
210 * callbacks are done. Also, note multiple callbacks can be running
211 * concurrently using multiple CPU cores. The callbacks will be running
212 * in a special environment which can not be used to pass data around.
214 * \param[in] th transaction handle
215 * \param[in] dcb commit callback description
217 * \retval 0 on success
218 * \retval negative negated errno on error
220 int (*dt_trans_cb_add)(struct thandle *th,
221 struct dt_txn_commit_cb *dcb);
224 * Return FID of root index object.
226 * Return the FID of the root object in the filesystem. This object
227 * is usually provided as a bootstrap point by a disk filesystem.
228 * This is up to the implementation which FID to use, though
229 * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
231 * \param[in] env execution environment for this thread
232 * \param[in] dev dt device
233 * \param[out] fid FID of the root object
235 * \retval 0 on success
236 * \retval negative negated errno on error
238 int (*dt_root_get)(const struct lu_env *env,
239 struct dt_device *dev,
243 * Return device configuration data.
245 * Return device (disk fs, actually) specific configuration.
246 * The configuration isn't subject to change at runtime.
247 * See struct dt_device_param for the details.
249 * \param[in] env execution environment for this thread
250 * \param[in] dev dt device
251 * \param[out] param configuration parameters
253 void (*dt_conf_get)(const struct lu_env *env,
254 const struct dt_device *dev,
255 struct dt_device_param *param);
258 * Return device's super block.
260 * \param[in] dev dt device
262 struct super_block *(*dt_mnt_sb_get)(const struct dt_device *dev);
267 * Sync all the cached state (dirty buffers, pages, etc) to the
268 * persistent storage. The method returns control once the sync is
269 * complete. This operation may incur significant I/O to disk and
270 * should be reserved for cases where a global sync is strictly
273 * \param[in] env execution environment for this thread
274 * \param[in] dev dt device
276 * \retval 0 on success
277 * \retval negative negated errno on error
279 int (*dt_sync)(const struct lu_env *env,
280 struct dt_device *dev);
283 * Make device read-only.
285 * Prevent new modifications to the device. This is a very specific
286 * state where all the changes are accepted successfully and the
287 * commit callbacks are called, but persistent state never changes.
288 * Used only in the tests to simulate power-off scenario.
290 * \param[in] env execution environment for this thread
291 * \param[in] dev dt device
293 * \retval 0 on success
294 * \retval negative negated errno on error
296 int (*dt_ro)(const struct lu_env *env,
297 struct dt_device *dev);
300 * Start transaction commit asynchronously.
303 * Provide a hint to the underlying filesystem that it should start
304 * committing soon. The control returns immediately. It's up to the
305 * layer implementing the method how soon to start committing. Usually
306 * this should be throttled to some extent, otherwise the number of
307 * aggregated transaction goes too high causing performance drop.
309 * \param[in] env execution environment for this thread
310 * \param[in] dev dt device
312 * \retval 0 on success
313 * \retval negative negated errno on error
315 int (*dt_commit_async)(const struct lu_env *env,
316 struct dt_device *dev);
319 struct dt_index_features {
320 /** required feature flags from enum dt_index_flags */
322 /** minimal required key size */
323 size_t dif_keysize_min;
324 /** maximal required key size, 0 if no limit */
325 size_t dif_keysize_max;
326 /** minimal required record size */
327 size_t dif_recsize_min;
328 /** maximal required record size, 0 if no limit */
329 size_t dif_recsize_max;
330 /** pointer size for record */
334 enum dt_index_flags {
335 /** index supports variable sized keys */
336 DT_IND_VARKEY = 1 << 0,
337 /** index supports variable sized records */
338 DT_IND_VARREC = 1 << 1,
339 /** index can be modified */
340 DT_IND_UPDATE = 1 << 2,
341 /** index supports records with non-unique (duplicate) keys */
342 DT_IND_NONUNQ = 1 << 3,
344 * index support fixed-size keys sorted with natural numerical way
345 * and is able to return left-side value if no exact value found
347 DT_IND_RANGE = 1 << 4,
351 * Features, required from index to support file system directories (mapping
354 extern const struct dt_index_features dt_directory_features;
355 extern const struct dt_index_features dt_otable_features;
356 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
357 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
358 extern const struct dt_index_features dt_lfsck_namespace_features;
360 /* index features supported by the accounting objects */
361 extern const struct dt_index_features dt_acct_features;
363 /* index features supported by the quota global indexes */
364 extern const struct dt_index_features dt_quota_glb_features;
366 /* index features supported by the quota slave indexes */
367 extern const struct dt_index_features dt_quota_slv_features;
369 /* index features supported by the nodemap index */
370 extern const struct dt_index_features dt_nodemap_features;
373 * This is a general purpose dt allocation hint.
374 * It now contains the parent object.
375 * It can contain any allocation hint in the future.
377 struct dt_allocation_hint {
378 struct dt_object *dah_parent;
379 const void *dah_eadata;
385 * object type specifier.
388 enum dt_format_type {
393 /** for special index */
395 /** for symbolic link */
400 * object format specifier.
402 struct dt_object_format {
403 /** type for dt object */
404 enum dt_format_type dof_type;
414 * special index need feature as parameter to create
418 const struct dt_index_features *di_feat;
423 enum dt_format_type dt_mode_to_dft(__u32 mode);
425 typedef __u64 dt_obj_version_t;
427 union ldlm_policy_data;
429 struct md_layout_change;
432 * A dt_object provides common operations to create and destroy
433 * objects and to manage regular and extended attributes.
435 struct dt_object_operations {
437 * Get read lock on object.
439 * Read lock is compatible with other read locks, so it's shared.
440 * Read lock is not compatible with write lock which is exclusive.
441 * The lock is blocking and can't be used from an interrupt context.
443 * \param[in] env execution environment for this thread
444 * \param[in] dt object to lock for reading
445 * \param[in] role a hint to debug locks (see kernel's mutexes)
447 void (*do_read_lock)(const struct lu_env *env,
448 struct dt_object *dt,
452 * Get write lock on object.
454 * Write lock is exclusive and cannot be shared. The lock is blocking
455 * and can't be used from an interrupt context.
457 * \param[in] env execution environment for this thread
458 * \param[in] dt object to lock for writing
459 * \param[in] role a hint to debug locks (see kernel's mutexes)
462 void (*do_write_lock)(const struct lu_env *env,
463 struct dt_object *dt,
469 * \param[in] env execution environment for this thread
470 * \param[in] dt object
472 void (*do_read_unlock)(const struct lu_env *env,
473 struct dt_object *dt);
476 * Release write lock.
478 * \param[in] env execution environment for this thread
479 * \param[in] dt object
481 void (*do_write_unlock)(const struct lu_env *env,
482 struct dt_object *dt);
485 * Check whether write lock is held.
487 * The caller can learn whether write lock is held on the object
489 * \param[in] env execution environment for this thread
490 * \param[in] dt object
492 * \retval 0 no write lock
493 * \retval 1 write lock is held
495 int (*do_write_locked)(const struct lu_env *env,
496 struct dt_object *dt);
499 * Declare intention to request reqular attributes.
501 * Notity the underlying filesystem that the caller may request regular
502 * attributes with ->do_attr_get() soon. This allows OSD to implement
503 * prefetching logic in an object-oriented manner. The implementation
504 * can be noop. This method should avoid expensive delays such as
505 * waiting on disk I/O, otherwise the goal of enabling a performance
506 * optimization would be defeated.
508 * \param[in] env execution environment for this thread
509 * \param[in] dt object
511 * \retval 0 on success
512 * \retval negative negated errno on error
514 int (*do_declare_attr_get)(const struct lu_env *env,
515 struct dt_object *dt);
518 * Return regular attributes.
520 * The object must exist. Currently all the attributes should be
521 * returned, but in the future this can be improved so that only
522 * a selected set is returned. This can improve performance as in
523 * some cases attributes are stored in different places and
524 * getting them all can be an iterative and expensive process.
526 * \param[in] env execution environment for this thread
527 * \param[in] dt object
528 * \param[out] attr attributes to fill
530 * \retval 0 on success
531 * \retval negative negated errno on error
533 int (*do_attr_get)(const struct lu_env *env,
534 struct dt_object *dt,
535 struct lu_attr *attr);
538 * Declare intention to change regular object's attributes.
540 * Notify the underlying filesystem that the regular attributes may
541 * change in this transaction. This enables the layer below to prepare
542 * resources (e.g. journal credits in ext4). This method should be
543 * called between creating the transaction and starting it. Note that
544 * the la_valid field of \a attr specifies which attributes will change.
545 * The object need not exist.
547 * \param[in] env execution environment for this thread
548 * \param[in] dt object
549 * \param[in] attr attributes to change specified in attr.la_valid
550 * \param[in] th transaction handle
552 * \retval 0 on success
553 * \retval negative negated errno on error
555 int (*do_declare_attr_set)(const struct lu_env *env,
556 struct dt_object *dt,
557 const struct lu_attr *attr,
561 * Change regular attributes.
563 * Change regular attributes in the given transaction. Note only
564 * attributes flagged by attr.la_valid change. The object must
565 * exist. If the layer implementing this method is responsible for
566 * quota, then the method should maintain object accounting for the
567 * given credentials when la_uid/la_gid changes.
569 * \param[in] env execution environment for this thread
570 * \param[in] dt object
571 * \param[in] attr new attributes to apply
572 * \param[in] th transaction handle
574 * \retval 0 on success
575 * \retval negative negated errno on error
577 int (*do_attr_set)(const struct lu_env *env,
578 struct dt_object *dt,
579 const struct lu_attr *attr,
583 * Declare intention to request extented attribute.
585 * Notify the underlying filesystem that the caller may request extended
586 * attribute with ->do_xattr_get() soon. This allows OSD to implement
587 * prefetching logic in an object-oriented manner. The implementation
588 * can be noop. This method should avoid expensive delays such as
589 * waiting on disk I/O, otherwise the goal of enabling a performance
590 * optimization would be defeated.
592 * \param[in] env execution environment for this thread
593 * \param[in] dt object
594 * \param[in] buf unused, may be removed in the future
595 * \param[in] name name of the extended attribute
597 * \retval 0 on success
598 * \retval negative negated errno on error
600 int (*do_declare_xattr_get)(const struct lu_env *env,
601 struct dt_object *dt,
606 * Return a value of an extended attribute.
608 * The object must exist. If the buffer is NULL, then the method
609 * must return the size of the value.
611 * \param[in] env execution environment for this thread
612 * \param[in] dt object
613 * \param[out] buf buffer in which to store the value
614 * \param[in] name name of the extended attribute
616 * \retval 0 on success
617 * \retval -ERANGE if \a buf is too small
618 * \retval negative negated errno on error
619 * \retval positive value's size if \a buf is NULL or has zero size
621 int (*do_xattr_get)(const struct lu_env *env,
622 struct dt_object *dt,
627 * Declare intention to change an extended attribute.
629 * Notify the underlying filesystem that the extended attribute may
630 * change in this transaction. This enables the layer below to prepare
631 * resources (e.g. journal credits in ext4). This method should be
632 * called between creating the transaction and starting it. The object
635 * \param[in] env execution environment for this thread
636 * \param[in] dt object
637 * \param[in] buf buffer storing new value of the attribute
638 * \param[in] name name of the attribute
639 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
640 * LU_XATTR_REPLACE - fail if EA doesn't exist
641 * \param[in] th transaction handle
643 * \retval 0 on success
644 * \retval negative negated errno on error
646 int (*do_declare_xattr_set)(const struct lu_env *env,
647 struct dt_object *dt,
648 const struct lu_buf *buf,
654 * Set an extended attribute.
656 * Change or replace the specified extended attribute (EA).
657 * The flags passed in \a fl dictate whether the EA is to be
658 * created or replaced, as follows.
659 * LU_XATTR_CREATE - fail if EA exists
660 * LU_XATTR_REPLACE - fail if EA doesn't exist
661 * The object must exist.
663 * \param[in] env execution environment for this thread
664 * \param[in] dt object
665 * \param[in] buf buffer storing new value of the attribute
666 * \param[in] name name of the attribute
667 * \param[in] fl flags indicating EA creation or replacement
668 * \param[in] th transaction handle
670 * \retval 0 on success
671 * \retval negative negated errno on error
673 int (*do_xattr_set)(const struct lu_env *env,
674 struct dt_object *dt,
675 const struct lu_buf *buf,
681 * Declare intention to delete an extended attribute.
683 * Notify the underlying filesystem that the extended attribute may
684 * be deleted in this transaction. This enables the layer below to
685 * prepare resources (e.g. journal credits in ext4). This method
686 * should be called between creating the transaction and starting it.
687 * The object need not exist.
689 * \param[in] env execution environment for this thread
690 * \param[in] dt object
691 * \param[in] name name of the attribute
692 * \param[in] th transaction handle
694 * \retval 0 on success
695 * \retval negative negated errno on error
697 int (*do_declare_xattr_del)(const struct lu_env *env,
698 struct dt_object *dt,
703 * Delete an extended attribute.
705 * This method deletes the specified extended attribute. The object
708 * \param[in] env execution environment for this thread
709 * \param[in] dt object
710 * \param[in] name name of the attribute
711 * \param[in] th transaction handle
713 * \retval 0 on success
714 * \retval negative negated errno on error
716 int (*do_xattr_del)(const struct lu_env *env,
717 struct dt_object *dt,
722 * Return a list of the extended attributes.
724 * Fills the passed buffer with a list of the extended attributes
725 * found in the object. The names are separated with '\0'.
726 * The object must exist.
728 * \param[in] env execution environment for this thread
729 * \param[in] dt object
730 * \param[out] buf buffer to put the list in
732 * \retval positive bytes used/required in the buffer
733 * \retval negative negated errno on error
735 int (*do_xattr_list)(const struct lu_env *env,
736 struct dt_object *dt,
737 const struct lu_buf *buf);
740 * Prepare allocation hint for a new object.
742 * This method is used by the caller to inform OSD of the parent-child
743 * relationship between two objects and enable efficient object
744 * allocation. Filled allocation hint will be passed to ->do_create()
747 * \param[in] env execution environment for this thread
748 * \param[out] ah allocation hint
749 * \param[in] parent parent object (can be NULL)
750 * \param[in] child child object
751 * \param[in] _mode type of the child object
753 void (*do_ah_init)(const struct lu_env *env,
754 struct dt_allocation_hint *ah,
755 struct dt_object *parent,
756 struct dt_object *child,
760 * Declare intention to create a new object.
762 * Notify the underlying filesystem that the object may be created
763 * in this transaction. This enables the layer below to prepare
764 * resources (e.g. journal credits in ext4). This method should be
765 * called between creating the transaction and starting it.
767 * If the layer implementing this method is responsible for quota,
768 * then the method should reserve an object for the given credentials
769 * and return an error if quota is over. If object creation later
770 * fails for some reason, then the reservation should be released
771 * properly (usually in ->dt_trans_stop()).
773 * \param[in] env execution environment for this thread
774 * \param[in] dt object
775 * \param[in] attr attributes of the new object
776 * \param[in] hint allocation hint
777 * \param[in] dof object format
778 * \param[in] th transaction handle
780 * \retval 0 on success
781 * \retval negative negated errno on error
783 int (*do_declare_create)(const struct lu_env *env,
784 struct dt_object *dt,
785 struct lu_attr *attr,
786 struct dt_allocation_hint *hint,
787 struct dt_object_format *dof,
793 * The method creates the object passed with the specified attributes
794 * and object format. Object allocation procedure can use information
795 * stored in the allocation hint. Different object formats are supported
796 * (see enum dt_format_type and struct dt_object_format) depending on
797 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
798 * in the LU-object header attributes.
800 * If the layer implementing this method is responsible for quota,
801 * then the method should maintain object accounting for the given
804 * \param[in] env execution environment for this thread
805 * \param[in] dt object
806 * \param[in] attr attributes of the new object
807 * \param[in] hint allocation hint
808 * \param[in] dof object format
809 * \param[in] th transaction handle
811 * \retval 0 on success
812 * \retval negative negated errno on error
814 int (*do_create)(const struct lu_env *env,
815 struct dt_object *dt,
816 struct lu_attr *attr,
817 struct dt_allocation_hint *hint,
818 struct dt_object_format *dof,
822 * Declare intention to destroy an object.
824 * Notify the underlying filesystem that the object may be destroyed
825 * in this transaction. This enables the layer below to prepare
826 * resources (e.g. journal credits in ext4). This method should be
827 * called between creating the transaction and starting it. The object
830 * \param[in] env execution environment for this thread
831 * \param[in] dt object
832 * \param[in] th transaction handle
834 * \retval 0 on success
835 * \retval negative negated errno on error
837 int (*do_declare_destroy)(const struct lu_env *env,
838 struct dt_object *dt,
844 * This method destroys the object and all the resources associated
845 * with the object (data, key/value pairs, extended attributes, etc).
846 * The object must exist. If destroy is successful, then flag
847 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
848 * instance of in-core object. Any subsequent access to the same FID
849 * should get another instance with no LOHA_EXIST flag set.
851 * If the layer implementing this method is responsible for quota,
852 * then the method should maintain object accounting for the given
855 * \param[in] env execution environment for this thread
856 * \param[in] dt object
857 * \param[in] th transaction handle
859 * \retval 0 on success
860 * \retval negative negated errno on error
862 int (*do_destroy)(const struct lu_env *env,
863 struct dt_object *dt,
867 * Try object as an index.
869 * Announce that this object is going to be used as an index. This
870 * operation checks that object supports indexing operations and
871 * installs appropriate dt_index_operations vector on success.
872 * Also probes for features. Operation is successful if all required
873 * features are supported. It's not possible to access the object
874 * with index methods before ->do_index_try() returns success.
876 * \param[in] env execution environment for this thread
877 * \param[in] dt object
878 * \param[in] feat index features
880 * \retval 0 on success
881 * \retval negative negated errno on error
883 int (*do_index_try)(const struct lu_env *env,
884 struct dt_object *dt,
885 const struct dt_index_features *feat);
888 * Declare intention to increment nlink count.
890 * Notify the underlying filesystem that the nlink regular attribute
891 * be changed in this transaction. This enables the layer below to
892 * prepare resources (e.g. journal credits in ext4). This method
893 * should be called between creating the transaction and starting it.
894 * The object need not exist.
896 * \param[in] env execution environment for this thread
897 * \param[in] dt object
898 * \param[in] th transaction handle
900 * \retval 0 on success
901 * \retval negative negated errno on error
903 int (*do_declare_ref_add)(const struct lu_env *env,
904 struct dt_object *dt,
910 * Increment nlink (from the regular attributes set) in the given
911 * transaction. Note the absolute limit for nlink should be learnt
912 * from struct dt_device_param::ddp_max_nlink. The object must exist.
914 * \param[in] env execution environment for this thread
915 * \param[in] dt object
916 * \param[in] th transaction handle
918 * \retval 0 on success
919 * \retval negative negated errno on error
921 int (*do_ref_add)(const struct lu_env *env,
922 struct dt_object *dt, struct thandle *th);
925 * Declare intention to decrement nlink count.
927 * Notify the underlying filesystem that the nlink regular attribute
928 * be changed in this transaction. This enables the layer below to
929 * prepare resources (e.g. journal credits in ext4). This method
930 * should be called between creating the transaction and starting it.
931 * The object need not exist.
933 * \param[in] env execution environment for this thread
934 * \param[in] dt object
935 * \param[in] th transaction handle
937 * \retval 0 on success
938 * \retval negative negated errno on error
940 int (*do_declare_ref_del)(const struct lu_env *env,
941 struct dt_object *dt,
947 * Decrement nlink (from the regular attributes set) in the given
948 * transaction. The object must exist.
950 * \param[in] env execution environment for this thread
951 * \param[in] dt object
952 * \param[in] th transaction handle
954 * \retval 0 on success
955 * \retval negative negated errno on error
957 int (*do_ref_del)(const struct lu_env *env,
958 struct dt_object *dt,
964 * The method is called to sync specified range of the object to a
965 * persistent storage. The control is returned once the operation is
966 * complete. The difference from ->do_sync() is that the object can
967 * be in-sync with the persistent storage (nothing to flush), then
968 * the method returns quickly with no I/O overhead. So, this method
969 * should be preferred over ->do_sync() where possible. Also note that
970 * if the object isn't clean, then some disk filesystems will call
971 * ->do_sync() to maintain overall consistency, in which case it's
972 * still very expensive.
974 * \param[in] env execution environment for this thread
975 * \param[in] dt object
976 * \param[in] start start of the range to sync
977 * \param[in] end end of the range to sync
979 * \retval 0 on success
980 * \retval negative negated errno on error
982 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
983 __u64 start, __u64 end);
988 * Lock object(s) using Distributed Lock Manager (LDLM).
990 * Get LDLM locks for the object. Currently used to lock "remote"
991 * objects in DNE configuration - a service running on MDTx needs
992 * to lock an object on MDTy.
994 * \param[in] env execution environment for this thread
995 * \param[in] dt object
996 * \param[out] lh lock handle, sometimes used, sometimes not
997 * \param[in] einfo ldlm callbacks, locking type and mode
998 * \param[out] einfo private data to be passed to unlock later
999 * \param[in] policy inodebits data
1001 * \retval 0 on success
1002 * \retval negative negated errno on error
1004 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1005 struct lustre_handle *lh,
1006 struct ldlm_enqueue_info *einfo,
1007 union ldlm_policy_data *policy);
1012 * Release LDLM lock(s) granted with ->do_object_lock().
1014 * \param[in] env execution environment for this thread
1015 * \param[in] dt object
1016 * \param[in] einfo lock handles, from ->do_object_lock()
1017 * \param[in] policy inodebits data
1019 * \retval 0 on success
1020 * \retval negative negated errno on error
1022 int (*do_object_unlock)(const struct lu_env *env,
1023 struct dt_object *dt,
1024 struct ldlm_enqueue_info *einfo,
1025 union ldlm_policy_data *policy);
1028 * Invalidate attribute cache.
1030 * This method invalidate attribute cache of the object, which is on OSP
1033 * \param[in] env execution envionment for this thread
1034 * \param[in] dt object
1036 * \retval 0 on success
1037 * \retval negative negated errno on error
1039 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1042 * Declare intention to instaintiate extended layout component.
1044 * \param[in] env execution environment
1045 * \param[in] dt DT object
1046 * \param[in] layout data structure to describe the changes to
1047 * the DT object's layout
1048 * \param[in] buf buffer containing client's lovea or empty
1051 * \retval -ne error code
1053 int (*do_declare_layout_change)(const struct lu_env *env,
1054 struct dt_object *dt,
1055 struct md_layout_change *mlc,
1056 struct thandle *th);
1059 * Client is trying to write to un-instantiated layout component.
1061 * \param[in] env execution environment
1062 * \param[in] dt DT object
1063 * \param[in] layout data structure to describe the changes to
1064 * the DT object's layout
1065 * \param[in] buf buffer containing client's lovea or empty
1068 * \retval -ne error code
1070 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1071 struct md_layout_change *mlc,
1072 struct thandle *th);
1076 DT_BUFS_TYPE_READ = 0x0000,
1077 DT_BUFS_TYPE_WRITE = 0x0001,
1078 DT_BUFS_TYPE_READAHEAD = 0x0002,
1079 DT_BUFS_TYPE_LOCAL = 0x0004,
1083 * Per-dt-object operations on "file body" - unstructure raw data.
1085 struct dt_body_operations {
1089 * Read unstructured data from an existing regular object.
1090 * Only data before attr.la_size is returned.
1092 * \param[in] env execution environment for this thread
1093 * \param[in] dt object
1094 * \param[out] buf buffer (including size) to copy data in
1095 * \param[in] pos position in the object to start
1096 * \param[out] pos original value of \a pos + bytes returned
1098 * \retval positive bytes read on success
1099 * \retval negative negated errno on error
1101 ssize_t (*dbo_read)(const struct lu_env *env,
1102 struct dt_object *dt,
1107 * Declare intention to write data to object.
1109 * Notify the underlying filesystem that data may be written in
1110 * this transaction. This enables the layer below to prepare resources
1111 * (e.g. journal credits in ext4). This method should be called
1112 * between creating the transaction and starting it. The object need
1113 * not exist. If the layer implementing this method is responsible for
1114 * quota, then the method should reserve space for the given credentials
1115 * and return an error if quota is over. If the write later fails
1116 * for some reason, then the reserve should be released properly
1117 * (usually in ->dt_trans_stop()).
1119 * \param[in] env execution environment for this thread
1120 * \param[in] dt object
1121 * \param[in] buf buffer (including size) to copy data from
1122 * \param[in] pos position in the object to start
1123 * \param[in] th transaction handle
1125 * \retval 0 on success
1126 * \retval negative negated errno on error
1128 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1129 struct dt_object *dt,
1130 const struct lu_buf *buf,
1132 struct thandle *th);
1135 * Write unstructured data to regular existing object.
1137 * The method allocates space and puts data in. Also, the method should
1138 * maintain attr.la_size properly. Partial writes are possible.
1140 * If the layer implementing this method is responsible for quota,
1141 * then the method should maintain space accounting for the given
1144 * \param[in] env execution environment for this thread
1145 * \param[in] dt object
1146 * \param[in] buf buffer (including size) to copy data from
1147 * \param[in] pos position in the object to start
1148 * \param[out] pos \a pos + bytes written
1149 * \param[in] th transaction handle
1151 * \retval positive bytes written on success
1152 * \retval negative negated errno on error
1154 ssize_t (*dbo_write)(const struct lu_env *env,
1155 struct dt_object *dt,
1156 const struct lu_buf *buf,
1158 struct thandle *th);
1161 * Return buffers for data.
1163 * This method is used to access data with no copying. It's so-called
1164 * zero-copy I/O. The method returns the descriptors for the internal
1165 * buffers where data are managed by the disk filesystem. For example,
1166 * pagecache in case of ext4 or ARC with ZFS. Then other components
1167 * (e.g. networking) can transfer data from or to the buffers with no
1168 * additional copying.
1170 * The method should fill an array of struct niobuf_local, where
1171 * each element describes a full or partial page for data at specific
1172 * offset. The caller should use page/lnb_page_offset/len to find data
1173 * at object's offset lnb_file_offset.
1175 * The memory referenced by the descriptors can't change its purpose
1176 * until the complementary ->dbo_bufs_put() is called. The caller should
1177 * specify if the buffers are used to read or modify data so that OSD
1178 * can decide how to initialize the buffers: bring all the data for
1179 * reads or just bring partial buffers for write. Note: the method does
1180 * not check whether output array is large enough.
1182 * \param[in] env execution environment for this thread
1183 * \param[in] dt object
1184 * \param[in] pos position in the object to start
1185 * \param[in] len size of region in bytes
1186 * \param[out] lb array of descriptors to fill
1187 * \param[in] rw 0 if used to read, 1 if used for write
1189 * \retval positive number of descriptors on success
1190 * \retval negative negated errno on error
1192 int (*dbo_bufs_get)(const struct lu_env *env,
1193 struct dt_object *dt,
1196 struct niobuf_local *lb,
1197 enum dt_bufs_type rw);
1200 * Release reference granted by ->dbo_bufs_get().
1202 * Release the reference granted by the previous ->dbo_bufs_get().
1203 * Note the references are counted.
1205 * \param[in] env execution environment for this thread
1206 * \param[in] dt object
1207 * \param[out] lb array of descriptors to fill
1208 * \param[in] nr size of the array
1210 * \retval 0 on success
1211 * \retval negative negated errno on error
1213 int (*dbo_bufs_put)(const struct lu_env *env,
1214 struct dt_object *dt,
1215 struct niobuf_local *lb,
1219 * Prepare buffers for reading.
1221 * The method is called on the given buffers to fill them with data
1222 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1223 * caller should be able to get few buffers for discontiguous regions
1224 * using few calls to ->dbo_bufs_get() and then request them all for
1225 * the preparation with a single call, so that OSD can fire many I/Os
1226 * to run concurrently. It's up to the specific OSD whether to implement
1227 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1228 * prepare data for every requested region individually.
1230 * \param[in] env execution environment for this thread
1231 * \param[in] dt object
1232 * \param[in] lnb array of buffer descriptors
1233 * \param[in] nr size of the array
1235 * \retval 0 on success
1236 * \retval negative negated errno on error
1238 int (*dbo_read_prep)(const struct lu_env *env,
1239 struct dt_object *dt,
1240 struct niobuf_local *lnb,
1244 * Prepare buffers for write.
1246 * This method is called on the given buffers to ensure the partial
1247 * buffers contain correct data. The underlying idea is the same as
1248 * in ->db_read_prep().
1250 * \param[in] env execution environment for this thread
1251 * \param[in] dt object
1252 * \param[in] lb array of buffer descriptors
1253 * \param[in] nr size of the array
1255 * \retval 0 on success
1256 * \retval negative negated errno on error
1258 int (*dbo_write_prep)(const struct lu_env *env,
1259 struct dt_object *dt,
1260 struct niobuf_local *lb,
1264 * Declare intention to write data stored in the buffers.
1266 * Notify the underlying filesystem that data may be written in
1267 * this transaction. This enables the layer below to prepare resources
1268 * (e.g. journal credits in ext4). This method should be called
1269 * between creating the transaction and starting it.
1271 * If the layer implementing this method is responsible for quota,
1272 * then the method should be reserving a space for the given
1273 * credentials and return an error if quota is exceeded. If the write
1274 * later fails for some reason, then the reserve should be released
1275 * properly (usually in ->dt_trans_stop()).
1277 * \param[in] env execution environment for this thread
1278 * \param[in] dt object
1279 * \param[in] lb array of descriptors
1280 * \param[in] nr size of the array
1281 * \param[in] th transaction handle
1283 * \retval 0 on success
1284 * \retval negative negated errno on error
1286 int (*dbo_declare_write_commit)(const struct lu_env *env,
1287 struct dt_object *dt,
1288 struct niobuf_local *lb,
1290 struct thandle *th);
1293 * Write to existing object.
1295 * This method is used to write data to a persistent storage using
1296 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1297 * data into the buffers using own mechanisms (e.g. direct transfer
1298 * from a NIC). The method should maintain attr.la_size. Also,
1299 * attr.la_blocks should be maintained but this can be done in lazy
1300 * manner, when actual allocation happens.
1302 * If the layer implementing this method is responsible for quota,
1303 * then the method should maintain space accounting for the given
1306 * \param[in] env execution environment for this thread
1307 * \param[in] dt object
1308 * \param[in] lb array of descriptors for the buffers
1309 * \param[in] nr size of the array
1310 * \param[in] th transaction handle
1312 * \retval 0 on success
1313 * \retval negative negated errno on error
1315 int (*dbo_write_commit)(const struct lu_env *env,
1316 struct dt_object *dt,
1317 struct niobuf_local *lb,
1319 struct thandle *th);
1322 * Return logical to physical block mapping for a given extent
1324 * \param[in] env execution environment for this thread
1325 * \param[in] dt object
1326 * \param[in] fm describe the region to map and the output buffer
1327 * see the details in include/linux/fiemap.h
1329 * \retval 0 on success
1330 * \retval negative negated errno on error
1332 int (*dbo_fiemap_get)(const struct lu_env *env,
1333 struct dt_object *dt,
1337 * Declare intention to deallocate space from an object.
1339 * Notify the underlying filesystem that space may be deallocated in
1340 * this transactions. This enables the layer below to prepare resources
1341 * (e.g. journal credits in ext4). This method should be called between
1342 * creating the transaction and starting it. The object need not exist.
1344 * \param[in] env execution environment for this thread
1345 * \param[in] dt object
1346 * \param[in] start the start of the region to deallocate
1347 * \param[in] end the end of the region to deallocate
1348 * \param[in] th transaction handle
1350 * \retval 0 on success
1351 * \retval negative negated errno on error
1353 int (*dbo_declare_punch)(const struct lu_env *env,
1354 struct dt_object *dt,
1357 struct thandle *th);
1360 * Deallocate specified region in an object.
1362 * This method is used to deallocate (release) space possibly consumed
1363 * by the given region of the object. If the layer implementing this
1364 * method is responsible for quota, then the method should maintain
1365 * space accounting for the given credentials.
1367 * \param[in] env execution environment for this thread
1368 * \param[in] dt object
1369 * \param[in] start the start of the region to deallocate
1370 * \param[in] end the end of the region to deallocate
1371 * \param[in] th transaction handle
1373 * \retval 0 on success
1374 * \retval negative negated errno on error
1376 int (*dbo_punch)(const struct lu_env *env,
1377 struct dt_object *dt,
1380 struct thandle *th);
1382 * Give advices on specified region in an object.
1384 * This method is used to give advices about access pattern on an
1385 * given region of the object. The disk filesystem understands
1386 * the advices and tunes cache/read-ahead policies.
1388 * \param[in] env execution environment for this thread
1389 * \param[in] dt object
1390 * \param[in] start the start of the region affected
1391 * \param[in] end the end of the region affected
1392 * \param[in] advice advice type
1394 * \retval 0 on success
1395 * \retval negative negated errno on error
1397 int (*dbo_ladvise)(const struct lu_env *env,
1398 struct dt_object *dt,
1401 enum lu_ladvise_type advice);
1405 * Incomplete type of index record.
1410 * Incomplete type of index key.
1415 * Incomplete type of dt iterator.
1420 * Per-dt-object operations on object as index. Index is a set of key/value
1421 * pairs abstracted from an on-disk representation. An index supports the
1422 * number of operations including lookup by key, insert and delete. Also,
1423 * an index can be iterated to find the pairs one by one, from a beginning
1424 * or specified point.
1426 struct dt_index_operations {
1428 * Lookup in an index by key.
1430 * The method returns a value for the given key. Key/value format
1431 * and size should have been negotiated with ->do_index_try() before.
1432 * Thus it's the caller's responsibility to provide the method with
1433 * proper key and big enough buffer. No external locking is required,
1434 * all the internal consistency should be implemented by the method
1435 * or lower layers. The object should should have been created with
1436 * type DFT_INDEX or DFT_DIR.
1438 * \param[in] env execution environment for this thread
1439 * \param[in] dt object
1440 * \param[out] rec buffer where value will be stored
1441 * \param[in] key key
1443 * \retval 0 on success
1444 * \retval -ENOENT if key isn't found
1445 * \retval negative negated errno on error
1447 int (*dio_lookup)(const struct lu_env *env,
1448 struct dt_object *dt,
1450 const struct dt_key *key);
1453 * Declare intention to insert a key/value into an index.
1455 * Notify the underlying filesystem that new key/value may be inserted
1456 * in this transaction. This enables the layer below to prepare
1457 * resources (e.g. journal credits in ext4). This method should be
1458 * called between creating the transaction and starting it. key/value
1459 * format and size is subject to ->do_index_try().
1461 * \param[in] env execution environment for this thread
1462 * \param[in] dt object
1463 * \param[in] rec buffer storing value
1464 * \param[in] key key
1465 * \param[in] th transaction handle
1467 * \retval 0 on success
1468 * \retval negative negated errno on error
1470 int (*dio_declare_insert)(const struct lu_env *env,
1471 struct dt_object *dt,
1472 const struct dt_rec *rec,
1473 const struct dt_key *key,
1474 struct thandle *th);
1477 * Insert a new key/value pair into an index.
1479 * The method inserts specified key/value pair into the given index
1480 * object. The internal consistency is maintained by the method or
1481 * the functionality below. The format and size of key/value should
1482 * have been negotiated before using ->do_index_try(), no additional
1483 * information can be specified to the method. The keys are unique
1486 * \param[in] env execution environment for this thread
1487 * \param[in] dt object
1488 * \param[in] rec buffer storing value
1489 * \param[in] key key
1490 * \param[in] th transaction handle
1492 * \retval 0 on success
1493 * \retval negative negated errno on error
1495 int (*dio_insert)(const struct lu_env *env,
1496 struct dt_object *dt,
1497 const struct dt_rec *rec,
1498 const struct dt_key *key,
1499 struct thandle *th);
1502 * Declare intention to delete a key/value from an index.
1504 * Notify the underlying filesystem that key/value may be deleted in
1505 * this transaction. This enables the layer below to prepare resources
1506 * (e.g. journal credits in ext4). This method should be called
1507 * between creating the transaction and starting it. Key/value format
1508 * and size is subject to ->do_index_try(). The object need not exist.
1510 * \param[in] env execution environment for this thread
1511 * \param[in] dt object
1512 * \param[in] key key
1513 * \param[in] th transaction handle
1515 * \retval 0 on success
1516 * \retval negative negated errno on error
1518 int (*dio_declare_delete)(const struct lu_env *env,
1519 struct dt_object *dt,
1520 const struct dt_key *key,
1521 struct thandle *th);
1524 * Delete key/value pair from an index.
1526 * The method deletes specified key and corresponding value from the
1527 * given index object. The internal consistency is maintained by the
1528 * method or the functionality below. The format and size of the key
1529 * should have been negotiated before using ->do_index_try(), no
1530 * additional information can be specified to the method.
1532 * \param[in] env execution environment for this thread
1533 * \param[in] dt object
1534 * \param[in] key key
1535 * \param[in] th transaction handle
1537 * \retval 0 on success
1538 * \retval negative negated errno on error
1540 int (*dio_delete)(const struct lu_env *env,
1541 struct dt_object *dt,
1542 const struct dt_key *key,
1543 struct thandle *th);
1546 * Iterator interface.
1548 * Methods to iterate over an existing index, list the keys stored and
1549 * associated values, get key/value size, etc.
1553 * Allocate and initialize new iterator.
1555 * The iterator is a handler to be used in the subsequent
1556 * methods to access index's content. Note the position is
1557 * not defined at this point and should be initialized with
1558 * ->get() or ->load() method.
1560 * \param[in] env execution environment for this thread
1561 * \param[in] dt object
1562 * \param[in] attr ask the iterator to return part of
1563 the records, see LUDA_* for details
1565 * \retval pointer iterator pointer on success
1566 * \retval ERR_PTR(errno) on error
1568 struct dt_it *(*init)(const struct lu_env *env,
1569 struct dt_object *dt,
1575 * Release the specified iterator and all the resources
1576 * associated (e.g. the object, index cache, etc).
1578 * \param[in] env execution environment for this thread
1579 * \param[in] di iterator to release
1581 void (*fini)(const struct lu_env *env,
1585 * Move position of iterator.
1587 * Move the position of the specified iterator to the specified
1590 * \param[in] env execution environment for this thread
1591 * \param[in] di iterator
1592 * \param[in] key key to position to
1594 * \retval 0 if exact key is found
1595 * \retval 1 if at the record with least key
1596 * not larger than the key
1597 * \retval negative negated errno on error
1599 int (*get)(const struct lu_env *env,
1601 const struct dt_key *key);
1606 * Complimentary method for dt_it_ops::get() above. Some
1607 * implementation can increase a reference on the iterator in
1608 * dt_it_ops::get(). So the caller should be able to release
1609 * with dt_it_ops::put().
1611 * \param[in] env execution environment for this thread
1612 * \param[in] di iterator
1614 void (*put)(const struct lu_env *env,
1618 * Move to next record.
1620 * Moves the position of the iterator to a next record
1622 * \param[in] env execution environment for this thread
1623 * \param[in] di iterator
1625 * \retval 1 if no more records
1626 * \retval 0 on success, the next record is found
1627 * \retval negative negated errno on error
1629 int (*next)(const struct lu_env *env,
1635 * Returns a pointer to a buffer containing the key of the
1636 * record at the current position. The pointer is valid and
1637 * retains data until ->get(), ->load() and ->fini() methods
1640 * \param[in] env execution environment for this thread
1641 * \param[in] di iterator
1643 * \retval pointer to key on success
1644 * \retval ERR_PTR(errno) on error
1646 struct dt_key *(*key)(const struct lu_env *env,
1647 const struct dt_it *di);
1652 * Returns size of the key at the current position.
1654 * \param[in] env execution environment for this thread
1655 * \param[in] di iterator
1657 * \retval key's size on success
1658 * \retval negative negated errno on error
1660 int (*key_size)(const struct lu_env *env,
1661 const struct dt_it *di);
1666 * Stores the value of the record at the current position. The
1667 * buffer must be big enough (as negotiated with
1668 * ->do_index_try() or ->rec_size()). The caller can specify
1669 * she is interested only in part of the record, using attr
1670 * argument (see LUDA_* definitions for the details).
1672 * \param[in] env execution environment for this thread
1673 * \param[in] di iterator
1674 * \param[out] rec buffer to store value in
1675 * \param[in] attr specify part of the value to copy
1677 * \retval 0 on success
1678 * \retval negative negated errno on error
1680 int (*rec)(const struct lu_env *env,
1681 const struct dt_it *di,
1686 * Return record size.
1688 * Returns size of the record at the current position. The
1689 * \a attr can be used to specify only the parts of the record
1690 * needed to be returned. (see LUDA_* definitions for the
1693 * \param[in] env execution environment for this thread
1694 * \param[in] di iterator
1695 * \param[in] attr part of the record to return
1697 * \retval record's size on success
1698 * \retval negative negated errno on error
1700 int (*rec_size)(const struct lu_env *env,
1701 const struct dt_it *di,
1705 * Return a cookie (hash).
1707 * Returns the cookie (usually hash) of the key at the current
1708 * position. This allows the caller to resume iteration at this
1709 * position later. The exact value is specific to implementation
1710 * and should not be interpreted by the caller.
1712 * \param[in] env execution environment for this thread
1713 * \param[in] di iterator
1715 * \retval cookie/hash of the key
1717 __u64 (*store)(const struct lu_env *env,
1718 const struct dt_it *di);
1721 * Initialize position using cookie/hash.
1723 * Initializes the current position of the iterator to one
1724 * described by the cookie/hash as returned by ->store()
1727 * \param[in] env execution environment for this thread
1728 * \param[in] di iterator
1729 * \param[in] hash cookie/hash value
1731 * \retval positive if current position points to
1732 * record with least cookie not larger
1734 * \retval 0 if current position matches cookie
1735 * \retval negative negated errno on error
1737 int (*load)(const struct lu_env *env,
1738 const struct dt_it *di,
1744 int (*key_rec)(const struct lu_env *env,
1745 const struct dt_it *di,
1750 enum dt_otable_it_valid {
1751 DOIV_ERROR_HANDLE = 0x0001,
1752 DOIV_DRYRUN = 0x0002,
1755 enum dt_otable_it_flags {
1756 /* Exit when fail. */
1757 DOIF_FAILOUT = 0x0001,
1759 /* Reset iteration position to the device beginning. */
1760 DOIF_RESET = 0x0002,
1762 /* There is up layer component uses the iteration. */
1763 DOIF_OUTUSED = 0x0004,
1765 /* Check only without repairing. */
1766 DOIF_DRYRUN = 0x0008,
1769 /* otable based iteration needs to use the common DT iteration APIs.
1770 * To initialize the iteration, it needs call dio_it::init() firstly.
1771 * Here is how the otable based iteration should prepare arguments to
1772 * call dt_it_ops::init().
1774 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1775 * is composed of two parts:
1776 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1777 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1778 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1781 struct lu_device dd_lu_dev;
1782 const struct dt_device_operations *dd_ops;
1785 * List of dt_txn_callback (see below). This is not protected in any
1786 * way, because callbacks are supposed to be added/deleted only during
1787 * single-threaded start-up shut-down procedures.
1789 struct list_head dd_txn_callbacks;
1790 unsigned int dd_record_fid_accessed:1,
1793 /* sysfs and debugfs handling */
1794 struct dentry *dd_debugfs_entry;
1796 const struct attribute **dd_def_attrs;
1797 struct kobject dd_kobj;
1798 struct kobj_type dd_ktype;
1799 struct completion dd_kobj_unregister;
1802 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1803 void dt_device_fini(struct dt_device *dev);
1805 static inline int lu_device_is_dt(const struct lu_device *d)
1807 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1810 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1812 LASSERT(lu_device_is_dt(l));
1813 return container_of0(l, struct dt_device, dd_lu_dev);
1817 struct lu_object do_lu;
1818 const struct dt_object_operations *do_ops;
1819 const struct dt_body_operations *do_body_ops;
1820 const struct dt_index_operations *do_index_ops;
1824 * In-core representation of per-device local object OID storage
1826 struct local_oid_storage {
1827 /* all initialized llog systems on this node linked by this */
1828 struct list_head los_list;
1830 /* how many handle's reference this los has */
1831 atomic_t los_refcount;
1832 struct dt_device *los_dev;
1833 struct dt_object *los_obj;
1835 /* data used to generate new fids */
1836 struct mutex los_id_lock;
1841 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1843 return &d->dd_lu_dev;
1846 static inline struct dt_object *lu2dt(struct lu_object *l)
1848 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1849 return container_of0(l, struct dt_object, do_lu);
1852 int dt_object_init(struct dt_object *obj,
1853 struct lu_object_header *h, struct lu_device *d);
1855 void dt_object_fini(struct dt_object *obj);
1857 static inline int dt_object_exists(const struct dt_object *dt)
1859 return lu_object_exists(&dt->do_lu);
1862 static inline int dt_object_remote(const struct dt_object *dt)
1864 return lu_object_remote(&dt->do_lu);
1867 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1869 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1870 return container_of0(o, struct dt_object, do_lu);
1873 static inline struct dt_object *dt_object_child(struct dt_object *o)
1875 return container_of0(lu_object_next(&(o)->do_lu),
1876 struct dt_object, do_lu);
1880 * This is the general purpose transaction handle.
1881 * 1. Transaction Life Cycle
1882 * This transaction handle is allocated upon starting a new transaction,
1883 * and deallocated after this transaction is committed.
1884 * 2. Transaction Nesting
1885 * We do _NOT_ support nested transaction. So, every thread should only
1886 * have one active transaction, and a transaction only belongs to one
1887 * thread. Due to this, transaction handle need no reference count.
1888 * 3. Transaction & dt_object locking
1889 * dt_object locks should be taken inside transaction.
1890 * 4. Transaction & RPC
1891 * No RPC request should be issued inside transaction.
1894 /** the dt device on which the transactions are executed */
1895 struct dt_device *th_dev;
1897 /* point to the top thandle, XXX this is a bit hacky right now,
1898 * but normal device trans callback triggered by the bottom
1899 * device (OSP/OSD == sub thandle layer) needs to get the
1900 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1901 * top thandle here for now, will fix it when we have better
1902 * callback mechanism */
1903 struct thandle *th_top;
1905 /** the last operation result in this transaction.
1906 * this value is used in recovery */
1909 /** whether we need sync commit */
1910 unsigned int th_sync:1,
1911 /* local transation, no need to inform other layers */
1913 /* Whether we need wait the transaction to be submitted
1914 * (send to remote target) */
1916 /* complex transaction which will track updates on all targets,
1919 /* whether ignore quota */
1924 * Transaction call-backs.
1926 * These are invoked by osd (or underlying transaction engine) when
1927 * transaction changes state.
1929 * Call-backs are used by upper layers to modify transaction parameters and to
1930 * perform some actions on for each transaction state transition. Typical
1931 * example is mdt registering call-back to write into last-received file
1932 * before each transaction commit.
1934 struct dt_txn_callback {
1935 int (*dtc_txn_start)(const struct lu_env *env,
1936 struct thandle *txn, void *cookie);
1937 int (*dtc_txn_stop)(const struct lu_env *env,
1938 struct thandle *txn, void *cookie);
1941 struct list_head dtc_linkage;
1944 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1945 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1947 int dt_txn_hook_start(const struct lu_env *env,
1948 struct dt_device *dev, struct thandle *txn);
1949 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1951 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1954 * Callback function used for parsing path.
1955 * \see llo_store_resolve
1957 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1961 #define DT_MAX_PATH 1024
1963 int dt_path_parser(const struct lu_env *env,
1964 char *local, dt_entry_func_t entry_func,
1968 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1969 const char *path, struct lu_fid *fid);
1971 struct dt_object *dt_store_open(const struct lu_env *env,
1972 struct dt_device *dt,
1973 const char *dirname,
1974 const char *filename,
1975 struct lu_fid *fid);
1977 struct dt_object *dt_find_or_create(const struct lu_env *env,
1978 struct dt_device *dt,
1979 const struct lu_fid *fid,
1980 struct dt_object_format *dof,
1981 struct lu_attr *attr);
1983 struct dt_object *dt_locate_at(const struct lu_env *env,
1984 struct dt_device *dev,
1985 const struct lu_fid *fid,
1986 struct lu_device *top_dev,
1987 const struct lu_object_conf *conf);
1989 static inline struct dt_object *
1990 dt_locate(const struct lu_env *env, struct dt_device *dev,
1991 const struct lu_fid *fid)
1993 return dt_locate_at(env, dev, fid,
1994 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1997 static inline struct dt_object *
1998 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2000 struct lu_object *lo;
2002 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2003 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2004 return container_of(lo, struct dt_object, do_lu);
2009 static inline void dt_object_put(const struct lu_env *env,
2010 struct dt_object *dto)
2012 lu_object_put(env, &dto->do_lu);
2015 static inline void dt_object_put_nocache(const struct lu_env *env,
2016 struct dt_object *dto)
2018 lu_object_put_nocache(env, &dto->do_lu);
2021 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2022 const struct lu_fid *first_fid,
2023 struct local_oid_storage **los);
2024 void local_oid_storage_fini(const struct lu_env *env,
2025 struct local_oid_storage *los);
2026 int local_object_fid_generate(const struct lu_env *env,
2027 struct local_oid_storage *los,
2028 struct lu_fid *fid);
2029 int local_object_declare_create(const struct lu_env *env,
2030 struct local_oid_storage *los,
2031 struct dt_object *o,
2032 struct lu_attr *attr,
2033 struct dt_object_format *dof,
2034 struct thandle *th);
2035 int local_object_create(const struct lu_env *env,
2036 struct local_oid_storage *los,
2037 struct dt_object *o,
2038 struct lu_attr *attr, struct dt_object_format *dof,
2039 struct thandle *th);
2040 struct dt_object *local_file_find(const struct lu_env *env,
2041 struct local_oid_storage *los,
2042 struct dt_object *parent,
2044 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2045 struct local_oid_storage *los,
2046 struct dt_object *parent,
2047 const char *name, __u32 mode);
2048 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2049 struct dt_device *dt,
2050 const struct lu_fid *fid,
2051 struct dt_object *parent,
2055 local_index_find_or_create(const struct lu_env *env,
2056 struct local_oid_storage *los,
2057 struct dt_object *parent,
2058 const char *name, __u32 mode,
2059 const struct dt_index_features *ft);
2061 local_index_find_or_create_with_fid(const struct lu_env *env,
2062 struct dt_device *dt,
2063 const struct lu_fid *fid,
2064 struct dt_object *parent,
2065 const char *name, __u32 mode,
2066 const struct dt_index_features *ft);
2067 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2068 struct dt_object *parent, const char *name);
2070 static inline int dt_object_lock(const struct lu_env *env,
2071 struct dt_object *o, struct lustre_handle *lh,
2072 struct ldlm_enqueue_info *einfo,
2073 union ldlm_policy_data *policy)
2076 LASSERT(o->do_ops != NULL);
2077 LASSERT(o->do_ops->do_object_lock != NULL);
2078 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2081 static inline int dt_object_unlock(const struct lu_env *env,
2082 struct dt_object *o,
2083 struct ldlm_enqueue_info *einfo,
2084 union ldlm_policy_data *policy)
2087 LASSERT(o->do_ops != NULL);
2088 LASSERT(o->do_ops->do_object_unlock != NULL);
2089 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2092 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2093 const char *name, struct lu_fid *fid);
2095 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2096 __u64 start, __u64 end)
2100 LASSERT(o->do_ops->do_object_sync);
2101 return o->do_ops->do_object_sync(env, o, start, end);
2104 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2105 struct thandle *th);
2106 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2107 dt_obj_version_t version, struct thandle *th);
2108 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2111 int dt_read(const struct lu_env *env, struct dt_object *dt,
2112 struct lu_buf *buf, loff_t *pos);
2113 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2114 struct lu_buf *buf, loff_t *pos);
2115 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2116 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2117 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2118 union lu_page *lp, size_t nob,
2119 const struct dt_it_ops *iops,
2120 struct dt_it *it, __u32 attr, void *arg);
2121 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2122 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2124 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2125 struct idx_info *ii, const struct lu_rdpg *rdpg);
2127 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2128 struct dt_device *d)
2130 LASSERT(d->dd_ops->dt_trans_create);
2131 return d->dd_ops->dt_trans_create(env, d);
2134 static inline int dt_trans_start(const struct lu_env *env,
2135 struct dt_device *d, struct thandle *th)
2137 LASSERT(d->dd_ops->dt_trans_start);
2138 return d->dd_ops->dt_trans_start(env, d, th);
2141 /* for this transaction hooks shouldn't be called */
2142 static inline int dt_trans_start_local(const struct lu_env *env,
2143 struct dt_device *d, struct thandle *th)
2145 LASSERT(d->dd_ops->dt_trans_start);
2147 return d->dd_ops->dt_trans_start(env, d, th);
2150 static inline int dt_trans_stop(const struct lu_env *env,
2151 struct dt_device *d, struct thandle *th)
2153 LASSERT(d->dd_ops->dt_trans_stop);
2154 return d->dd_ops->dt_trans_stop(env, d, th);
2157 static inline int dt_trans_cb_add(struct thandle *th,
2158 struct dt_txn_commit_cb *dcb)
2160 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2161 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2162 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2167 static inline int dt_declare_record_write(const struct lu_env *env,
2168 struct dt_object *dt,
2169 const struct lu_buf *buf,
2175 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2176 LASSERT(th != NULL);
2177 LASSERT(dt->do_body_ops);
2178 LASSERT(dt->do_body_ops->dbo_declare_write);
2179 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2183 static inline int dt_declare_create(const struct lu_env *env,
2184 struct dt_object *dt,
2185 struct lu_attr *attr,
2186 struct dt_allocation_hint *hint,
2187 struct dt_object_format *dof,
2191 LASSERT(dt->do_ops);
2192 LASSERT(dt->do_ops->do_declare_create);
2194 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2195 return cfs_fail_err;
2197 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2200 static inline int dt_create(const struct lu_env *env,
2201 struct dt_object *dt,
2202 struct lu_attr *attr,
2203 struct dt_allocation_hint *hint,
2204 struct dt_object_format *dof,
2208 LASSERT(dt->do_ops);
2209 LASSERT(dt->do_ops->do_create);
2211 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2212 return cfs_fail_err;
2214 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2217 static inline int dt_declare_destroy(const struct lu_env *env,
2218 struct dt_object *dt,
2222 LASSERT(dt->do_ops);
2223 LASSERT(dt->do_ops->do_declare_destroy);
2225 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2226 return cfs_fail_err;
2228 return dt->do_ops->do_declare_destroy(env, dt, th);
2231 static inline int dt_destroy(const struct lu_env *env,
2232 struct dt_object *dt,
2236 LASSERT(dt->do_ops);
2237 LASSERT(dt->do_ops->do_destroy);
2239 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2240 return cfs_fail_err;
2242 return dt->do_ops->do_destroy(env, dt, th);
2245 static inline void dt_read_lock(const struct lu_env *env,
2246 struct dt_object *dt,
2250 LASSERT(dt->do_ops);
2251 LASSERT(dt->do_ops->do_read_lock);
2252 dt->do_ops->do_read_lock(env, dt, role);
2255 static inline void dt_write_lock(const struct lu_env *env,
2256 struct dt_object *dt,
2260 LASSERT(dt->do_ops);
2261 LASSERT(dt->do_ops->do_write_lock);
2262 dt->do_ops->do_write_lock(env, dt, role);
2265 static inline void dt_read_unlock(const struct lu_env *env,
2266 struct dt_object *dt)
2269 LASSERT(dt->do_ops);
2270 LASSERT(dt->do_ops->do_read_unlock);
2271 dt->do_ops->do_read_unlock(env, dt);
2274 static inline void dt_write_unlock(const struct lu_env *env,
2275 struct dt_object *dt)
2278 LASSERT(dt->do_ops);
2279 LASSERT(dt->do_ops->do_write_unlock);
2280 dt->do_ops->do_write_unlock(env, dt);
2283 static inline int dt_write_locked(const struct lu_env *env,
2284 struct dt_object *dt)
2287 LASSERT(dt->do_ops);
2288 LASSERT(dt->do_ops->do_write_locked);
2289 return dt->do_ops->do_write_locked(env, dt);
2292 static inline int dt_declare_attr_get(const struct lu_env *env,
2293 struct dt_object *dt)
2296 LASSERT(dt->do_ops);
2297 LASSERT(dt->do_ops->do_declare_attr_get);
2299 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2300 return cfs_fail_err;
2302 return dt->do_ops->do_declare_attr_get(env, dt);
2305 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2309 LASSERT(dt->do_ops);
2310 LASSERT(dt->do_ops->do_attr_get);
2312 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2313 return cfs_fail_err;
2315 return dt->do_ops->do_attr_get(env, dt, la);
2318 static inline int dt_declare_attr_set(const struct lu_env *env,
2319 struct dt_object *dt,
2320 const struct lu_attr *la,
2324 LASSERT(dt->do_ops);
2325 LASSERT(dt->do_ops->do_declare_attr_set);
2327 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2328 return cfs_fail_err;
2330 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2333 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2334 const struct lu_attr *la, struct thandle *th)
2337 LASSERT(dt->do_ops);
2338 LASSERT(dt->do_ops->do_attr_set);
2340 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2341 return cfs_fail_err;
2343 return dt->do_ops->do_attr_set(env, dt, la, th);
2346 static inline int dt_declare_ref_add(const struct lu_env *env,
2347 struct dt_object *dt, struct thandle *th)
2350 LASSERT(dt->do_ops);
2351 LASSERT(dt->do_ops->do_declare_ref_add);
2353 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2354 return cfs_fail_err;
2356 return dt->do_ops->do_declare_ref_add(env, dt, th);
2359 static inline int dt_ref_add(const struct lu_env *env,
2360 struct dt_object *dt, struct thandle *th)
2363 LASSERT(dt->do_ops);
2364 LASSERT(dt->do_ops->do_ref_add);
2366 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2367 return cfs_fail_err;
2369 return dt->do_ops->do_ref_add(env, dt, th);
2372 static inline int dt_declare_ref_del(const struct lu_env *env,
2373 struct dt_object *dt, struct thandle *th)
2376 LASSERT(dt->do_ops);
2377 LASSERT(dt->do_ops->do_declare_ref_del);
2379 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2380 return cfs_fail_err;
2382 return dt->do_ops->do_declare_ref_del(env, dt, th);
2385 static inline int dt_ref_del(const struct lu_env *env,
2386 struct dt_object *dt, struct thandle *th)
2389 LASSERT(dt->do_ops);
2390 LASSERT(dt->do_ops->do_ref_del);
2392 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2393 return cfs_fail_err;
2395 return dt->do_ops->do_ref_del(env, dt, th);
2398 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2399 struct niobuf_remote *rnb,
2400 struct niobuf_local *lnb, enum dt_bufs_type rw)
2403 LASSERT(d->do_body_ops);
2404 LASSERT(d->do_body_ops->dbo_bufs_get);
2405 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2406 rnb->rnb_len, lnb, rw);
2409 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2410 struct niobuf_local *lnb, int n)
2413 LASSERT(d->do_body_ops);
2414 LASSERT(d->do_body_ops->dbo_bufs_put);
2415 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2418 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2419 struct niobuf_local *lnb, int n)
2422 LASSERT(d->do_body_ops);
2423 LASSERT(d->do_body_ops->dbo_write_prep);
2424 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2427 static inline int dt_declare_write_commit(const struct lu_env *env,
2428 struct dt_object *d,
2429 struct niobuf_local *lnb,
2430 int n, struct thandle *th)
2432 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2433 LASSERT(th != NULL);
2434 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2438 static inline int dt_write_commit(const struct lu_env *env,
2439 struct dt_object *d, struct niobuf_local *lnb,
2440 int n, struct thandle *th)
2443 LASSERT(d->do_body_ops);
2444 LASSERT(d->do_body_ops->dbo_write_commit);
2445 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2448 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2449 struct niobuf_local *lnb, int n)
2452 LASSERT(d->do_body_ops);
2453 LASSERT(d->do_body_ops->dbo_read_prep);
2454 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2457 static inline int dt_declare_write(const struct lu_env *env,
2458 struct dt_object *dt,
2459 const struct lu_buf *buf, loff_t pos,
2463 LASSERT(dt->do_body_ops);
2464 LASSERT(dt->do_body_ops->dbo_declare_write);
2465 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2468 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2469 const struct lu_buf *buf, loff_t *pos,
2473 LASSERT(dt->do_body_ops);
2474 LASSERT(dt->do_body_ops->dbo_write);
2475 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2478 static inline int dt_declare_punch(const struct lu_env *env,
2479 struct dt_object *dt, __u64 start,
2480 __u64 end, struct thandle *th)
2483 LASSERT(dt->do_body_ops);
2484 LASSERT(dt->do_body_ops->dbo_declare_punch);
2485 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2488 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2489 __u64 start, __u64 end, struct thandle *th)
2492 LASSERT(dt->do_body_ops);
2493 LASSERT(dt->do_body_ops->dbo_punch);
2494 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2497 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2498 __u64 start, __u64 end, int advice)
2501 LASSERT(dt->do_body_ops);
2502 LASSERT(dt->do_body_ops->dbo_ladvise);
2503 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2506 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2510 if (d->do_body_ops == NULL)
2512 if (d->do_body_ops->dbo_fiemap_get == NULL)
2514 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2517 static inline int dt_statfs_info(const struct lu_env *env,
2518 struct dt_device *dev,
2519 struct obd_statfs *osfs,
2520 struct obd_statfs_info *info)
2523 LASSERT(dev->dd_ops);
2524 LASSERT(dev->dd_ops->dt_statfs);
2525 return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2528 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2529 struct obd_statfs *osfs)
2531 return dt_statfs_info(env, dev, osfs, NULL);
2534 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2538 LASSERT(dev->dd_ops);
2539 LASSERT(dev->dd_ops->dt_root_get);
2540 return dev->dd_ops->dt_root_get(env, dev, f);
2543 static inline void dt_conf_get(const struct lu_env *env,
2544 const struct dt_device *dev,
2545 struct dt_device_param *param)
2548 LASSERT(dev->dd_ops);
2549 LASSERT(dev->dd_ops->dt_conf_get);
2550 return dev->dd_ops->dt_conf_get(env, dev, param);
2553 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2556 LASSERT(dev->dd_ops);
2557 if (dev->dd_ops->dt_mnt_sb_get)
2558 return dev->dd_ops->dt_mnt_sb_get(dev);
2560 return ERR_PTR(-EOPNOTSUPP);
2563 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2566 LASSERT(dev->dd_ops);
2567 LASSERT(dev->dd_ops->dt_sync);
2568 return dev->dd_ops->dt_sync(env, dev);
2571 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2574 LASSERT(dev->dd_ops);
2575 LASSERT(dev->dd_ops->dt_ro);
2576 return dev->dd_ops->dt_ro(env, dev);
2579 static inline int dt_declare_insert(const struct lu_env *env,
2580 struct dt_object *dt,
2581 const struct dt_rec *rec,
2582 const struct dt_key *key,
2586 LASSERT(dt->do_index_ops);
2587 LASSERT(dt->do_index_ops->dio_declare_insert);
2589 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2590 return cfs_fail_err;
2592 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2595 static inline int dt_insert(const struct lu_env *env,
2596 struct dt_object *dt,
2597 const struct dt_rec *rec,
2598 const struct dt_key *key,
2602 LASSERT(dt->do_index_ops);
2603 LASSERT(dt->do_index_ops->dio_insert);
2605 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2606 return cfs_fail_err;
2608 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2611 static inline int dt_declare_xattr_del(const struct lu_env *env,
2612 struct dt_object *dt,
2617 LASSERT(dt->do_ops);
2618 LASSERT(dt->do_ops->do_declare_xattr_del);
2620 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2621 return cfs_fail_err;
2623 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2626 static inline int dt_xattr_del(const struct lu_env *env,
2627 struct dt_object *dt, const char *name,
2631 LASSERT(dt->do_ops);
2632 LASSERT(dt->do_ops->do_xattr_del);
2634 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2635 return cfs_fail_err;
2637 return dt->do_ops->do_xattr_del(env, dt, name, th);
2640 static inline int dt_declare_xattr_set(const struct lu_env *env,
2641 struct dt_object *dt,
2642 const struct lu_buf *buf,
2643 const char *name, int fl,
2647 LASSERT(dt->do_ops);
2648 LASSERT(dt->do_ops->do_declare_xattr_set);
2650 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2651 return cfs_fail_err;
2653 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2656 static inline int dt_xattr_set(const struct lu_env *env,
2657 struct dt_object *dt, const struct lu_buf *buf,
2658 const char *name, int fl, struct thandle *th)
2661 LASSERT(dt->do_ops);
2662 LASSERT(dt->do_ops->do_xattr_set);
2664 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2665 return cfs_fail_err;
2667 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2670 static inline int dt_declare_xattr_get(const struct lu_env *env,
2671 struct dt_object *dt,
2676 LASSERT(dt->do_ops);
2677 LASSERT(dt->do_ops->do_declare_xattr_get);
2679 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2680 return cfs_fail_err;
2682 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2685 static inline int dt_xattr_get(const struct lu_env *env,
2686 struct dt_object *dt, struct lu_buf *buf,
2690 LASSERT(dt->do_ops);
2691 LASSERT(dt->do_ops->do_xattr_get);
2693 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2694 return cfs_fail_err;
2696 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2699 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2700 const struct lu_buf *buf)
2703 LASSERT(dt->do_ops);
2704 LASSERT(dt->do_ops->do_xattr_list);
2706 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2707 return cfs_fail_err;
2709 return dt->do_ops->do_xattr_list(env, dt, buf);
2712 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2715 LASSERT(dt->do_ops);
2716 LASSERT(dt->do_ops->do_invalidate);
2718 return dt->do_ops->do_invalidate(env, dt);
2721 static inline int dt_declare_delete(const struct lu_env *env,
2722 struct dt_object *dt,
2723 const struct dt_key *key,
2727 LASSERT(dt->do_index_ops);
2728 LASSERT(dt->do_index_ops->dio_declare_delete);
2730 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2731 return cfs_fail_err;
2733 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2736 static inline int dt_delete(const struct lu_env *env,
2737 struct dt_object *dt,
2738 const struct dt_key *key,
2742 LASSERT(dt->do_index_ops);
2743 LASSERT(dt->do_index_ops->dio_delete);
2745 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2746 return cfs_fail_err;
2748 return dt->do_index_ops->dio_delete(env, dt, key, th);
2751 static inline int dt_commit_async(const struct lu_env *env,
2752 struct dt_device *dev)
2755 LASSERT(dev->dd_ops);
2756 LASSERT(dev->dd_ops->dt_commit_async);
2757 return dev->dd_ops->dt_commit_async(env, dev);
2760 static inline int dt_lookup(const struct lu_env *env,
2761 struct dt_object *dt,
2763 const struct dt_key *key)
2768 LASSERT(dt->do_index_ops);
2769 LASSERT(dt->do_index_ops->dio_lookup);
2771 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2772 return cfs_fail_err;
2774 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2782 static inline int dt_declare_layout_change(const struct lu_env *env,
2783 struct dt_object *o,
2784 struct md_layout_change *mlc,
2789 LASSERT(o->do_ops->do_declare_layout_change);
2790 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2793 static inline int dt_layout_change(const struct lu_env *env,
2794 struct dt_object *o,
2795 struct md_layout_change *mlc,
2800 LASSERT(o->do_ops->do_layout_change);
2801 return o->do_ops->do_layout_change(env, o, mlc, th);
2804 struct dt_find_hint {
2805 struct lu_fid *dfh_fid;
2806 struct dt_device *dfh_dt;
2807 struct dt_object *dfh_o;
2810 struct dt_insert_rec {
2812 const struct lu_fid *rec_fid;
2824 struct dt_thread_info {
2825 char dti_buf[DT_MAX_PATH];
2826 struct dt_find_hint dti_dfh;
2827 struct lu_attr dti_attr;
2828 struct lu_fid dti_fid;
2829 struct dt_object_format dti_dof;
2830 struct lustre_mdt_attrs dti_lma;
2831 struct lu_buf dti_lb;
2832 struct lu_object_conf dti_conf;
2834 struct dt_insert_rec dti_dt_rec;
2837 extern struct lu_context_key dt_key;
2839 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2841 struct dt_thread_info *dti;
2843 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2848 int dt_global_init(void);
2849 void dt_global_fini(void);
2850 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2851 const char *name, struct lprocfs_vars *list);
2852 int dt_tunables_fini(struct dt_device *dt);
2854 # ifdef CONFIG_PROC_FS
2855 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2856 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2857 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2858 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2859 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2860 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2861 # endif /* CONFIG_PROC_FS */
2863 #endif /* __LUSTRE_DT_OBJECT_H */