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 */
92 * Per-transaction commit callback function
94 struct dt_txn_commit_cb;
95 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
96 struct dt_txn_commit_cb *cb, int err);
98 * Special per-transaction callback for cases when just commit callback
99 * is needed and per-device callback are not convenient to use
101 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
102 #define MAX_COMMIT_CB_STR_LEN 32
104 #define DCB_TRANS_STOP 0x1
105 struct dt_txn_commit_cb {
106 struct list_head dcb_linkage;
111 char dcb_name[MAX_COMMIT_CB_STR_LEN];
115 * Operations on dt device.
117 struct dt_device_operations {
119 * Return device-wide statistics.
121 * Return device-wide stats including block size, total and
122 * free blocks, total and free objects, etc. See struct obd_statfs
125 * \param[in] env execution environment for this thread
126 * \param[in] dev dt device
127 * \param[out] osfs stats information
129 * \retval 0 on success
130 * \retval negative negated errno on error
132 int (*dt_statfs)(const struct lu_env *env,
133 struct dt_device *dev,
134 struct obd_statfs *osfs);
137 * Create transaction.
139 * Create in-memory structure representing the transaction for the
140 * caller. The structure returned will be used by the calling thread
141 * to specify the transaction the updates belong to. Once created
142 * successfully ->dt_trans_stop() must be called in any case (with
143 * ->dt_trans_start() and updates or not) so that the transaction
144 * handle and other resources can be released by the layers below.
146 * \param[in] env execution environment for this thread
147 * \param[in] dev dt device
149 * \retval pointer to handle if creation succeeds
150 * \retval ERR_PTR(errno) if creation fails
152 struct thandle *(*dt_trans_create)(const struct lu_env *env,
153 struct dt_device *dev);
158 * Start the transaction. The transaction described by \a th can be
159 * started only once. Another start is considered as an error.
160 * A thread is not supposed to start a transaction while another
161 * transaction isn't closed by the thread (though multiple handles
162 * can be created). The caller should start the transaction once
163 * all possible updates are declared (see the ->do_declare_* methods
164 * below) and all the needed resources are reserved.
166 * \param[in] env execution environment for this thread
167 * \param[in] dev dt device
168 * \param[in] th transaction handle
170 * \retval 0 on success
171 * \retval negative negated errno on error
173 int (*dt_trans_start)(const struct lu_env *env,
174 struct dt_device *dev,
180 * Once stopped the transaction described by \a th is complete (all
181 * the needed updates are applied) and further processing such as
182 * flushing to disk, sending to another target, etc, is handled by
183 * lower layers. The caller can't access this transaction by the
184 * handle anymore (except from the commit callbacks, see below).
186 * \param[in] env execution environment for this thread
187 * \param[in] dev dt device
188 * \param[in] th transaction handle
190 * \retval 0 on success
191 * \retval negative negated errno on error
193 int (*dt_trans_stop)(const struct lu_env *env,
194 struct dt_device *dev,
198 * Add commit callback to the transaction.
200 * Add a commit callback to the given transaction handle. The callback
201 * will be called when the associated transaction is stored. I.e. the
202 * transaction will survive an event like power off if the callback did
203 * run. The number of callbacks isn't limited, but you should note that
204 * some disk filesystems do handle the commit callbacks in the thread
205 * handling commit/flush of all the transactions, meaning that new
206 * transactions are blocked from commit and flush until all the
207 * callbacks are done. Also, note multiple callbacks can be running
208 * concurrently using multiple CPU cores. The callbacks will be running
209 * in a special environment which can not be used to pass data around.
211 * \param[in] th transaction handle
212 * \param[in] dcb commit callback description
214 * \retval 0 on success
215 * \retval negative negated errno on error
217 int (*dt_trans_cb_add)(struct thandle *th,
218 struct dt_txn_commit_cb *dcb);
221 * Return FID of root index object.
223 * Return the FID of the root object in the filesystem. This object
224 * is usually provided as a bootstrap point by a disk filesystem.
225 * This is up to the implementation which FID to use, though
226 * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
228 * \param[in] env execution environment for this thread
229 * \param[in] dev dt device
230 * \param[out] fid FID of the root object
232 * \retval 0 on success
233 * \retval negative negated errno on error
235 int (*dt_root_get)(const struct lu_env *env,
236 struct dt_device *dev,
240 * Return device configuration data.
242 * Return device (disk fs, actually) specific configuration.
243 * The configuration isn't subject to change at runtime.
244 * See struct dt_device_param for the details.
246 * \param[in] env execution environment for this thread
247 * \param[in] dev dt device
248 * \param[out] param configuration parameters
250 void (*dt_conf_get)(const struct lu_env *env,
251 const struct dt_device *dev,
252 struct dt_device_param *param);
257 * Sync all the cached state (dirty buffers, pages, etc) to the
258 * persistent storage. The method returns control once the sync is
259 * complete. This operation may incur significant I/O to disk and
260 * should be reserved for cases where a global sync is strictly
263 * \param[in] env execution environment for this thread
264 * \param[in] dev dt device
266 * \retval 0 on success
267 * \retval negative negated errno on error
269 int (*dt_sync)(const struct lu_env *env,
270 struct dt_device *dev);
273 * Make device read-only.
275 * Prevent new modifications to the device. This is a very specific
276 * state where all the changes are accepted successfully and the
277 * commit callbacks are called, but persistent state never changes.
278 * Used only in the tests to simulate power-off scenario.
280 * \param[in] env execution environment for this thread
281 * \param[in] dev dt device
283 * \retval 0 on success
284 * \retval negative negated errno on error
286 int (*dt_ro)(const struct lu_env *env,
287 struct dt_device *dev);
290 * Start transaction commit asynchronously.
293 * Provide a hint to the underlying filesystem that it should start
294 * committing soon. The control returns immediately. It's up to the
295 * layer implementing the method how soon to start committing. Usually
296 * this should be throttled to some extent, otherwise the number of
297 * aggregated transaction goes too high causing performance drop.
299 * \param[in] env execution environment for this thread
300 * \param[in] dev dt device
302 * \retval 0 on success
303 * \retval negative negated errno on error
305 int (*dt_commit_async)(const struct lu_env *env,
306 struct dt_device *dev);
309 struct dt_index_features {
310 /** required feature flags from enum dt_index_flags */
312 /** minimal required key size */
313 size_t dif_keysize_min;
314 /** maximal required key size, 0 if no limit */
315 size_t dif_keysize_max;
316 /** minimal required record size */
317 size_t dif_recsize_min;
318 /** maximal required record size, 0 if no limit */
319 size_t dif_recsize_max;
320 /** pointer size for record */
324 enum dt_index_flags {
325 /** index supports variable sized keys */
326 DT_IND_VARKEY = 1 << 0,
327 /** index supports variable sized records */
328 DT_IND_VARREC = 1 << 1,
329 /** index can be modified */
330 DT_IND_UPDATE = 1 << 2,
331 /** index supports records with non-unique (duplicate) keys */
332 DT_IND_NONUNQ = 1 << 3,
334 * index support fixed-size keys sorted with natural numerical way
335 * and is able to return left-side value if no exact value found
337 DT_IND_RANGE = 1 << 4,
341 * Features, required from index to support file system directories (mapping
344 extern const struct dt_index_features dt_directory_features;
345 extern const struct dt_index_features dt_otable_features;
346 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
347 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
348 extern const struct dt_index_features dt_lfsck_namespace_features;
350 /* index features supported by the accounting objects */
351 extern const struct dt_index_features dt_acct_features;
353 /* index features supported by the quota global indexes */
354 extern const struct dt_index_features dt_quota_glb_features;
356 /* index features supported by the quota slave indexes */
357 extern const struct dt_index_features dt_quota_slv_features;
359 /* index features supported by the nodemap index */
360 extern const struct dt_index_features dt_nodemap_features;
363 * This is a general purpose dt allocation hint.
364 * It now contains the parent object.
365 * It can contain any allocation hint in the future.
367 struct dt_allocation_hint {
368 struct dt_object *dah_parent;
369 const void *dah_eadata;
375 * object type specifier.
378 enum dt_format_type {
383 /** for special index */
385 /** for symbolic link */
390 * object format specifier.
392 struct dt_object_format {
393 /** type for dt object */
394 enum dt_format_type dof_type;
404 * special index need feature as parameter to create
408 const struct dt_index_features *di_feat;
413 enum dt_format_type dt_mode_to_dft(__u32 mode);
415 typedef __u64 dt_obj_version_t;
417 union ldlm_policy_data;
419 struct md_layout_change;
422 * A dt_object provides common operations to create and destroy
423 * objects and to manage regular and extended attributes.
425 struct dt_object_operations {
427 * Get read lock on object.
429 * Read lock is compatible with other read locks, so it's shared.
430 * Read lock is not compatible with write lock which is exclusive.
431 * The lock is blocking and can't be used from an interrupt context.
433 * \param[in] env execution environment for this thread
434 * \param[in] dt object to lock for reading
435 * \param[in] role a hint to debug locks (see kernel's mutexes)
437 void (*do_read_lock)(const struct lu_env *env,
438 struct dt_object *dt,
442 * Get write lock on object.
444 * Write lock is exclusive and cannot be shared. The lock is blocking
445 * and can't be used from an interrupt context.
447 * \param[in] env execution environment for this thread
448 * \param[in] dt object to lock for writing
449 * \param[in] role a hint to debug locks (see kernel's mutexes)
452 void (*do_write_lock)(const struct lu_env *env,
453 struct dt_object *dt,
459 * \param[in] env execution environment for this thread
460 * \param[in] dt object
462 void (*do_read_unlock)(const struct lu_env *env,
463 struct dt_object *dt);
466 * Release write lock.
468 * \param[in] env execution environment for this thread
469 * \param[in] dt object
471 void (*do_write_unlock)(const struct lu_env *env,
472 struct dt_object *dt);
475 * Check whether write lock is held.
477 * The caller can learn whether write lock is held on the object
479 * \param[in] env execution environment for this thread
480 * \param[in] dt object
482 * \retval 0 no write lock
483 * \retval 1 write lock is held
485 int (*do_write_locked)(const struct lu_env *env,
486 struct dt_object *dt);
489 * Declare intention to request reqular attributes.
491 * Notity the underlying filesystem that the caller may request regular
492 * attributes with ->do_attr_get() soon. This allows OSD to implement
493 * prefetching logic in an object-oriented manner. The implementation
494 * can be noop. This method should avoid expensive delays such as
495 * waiting on disk I/O, otherwise the goal of enabling a performance
496 * optimization would be defeated.
498 * \param[in] env execution environment for this thread
499 * \param[in] dt object
501 * \retval 0 on success
502 * \retval negative negated errno on error
504 int (*do_declare_attr_get)(const struct lu_env *env,
505 struct dt_object *dt);
508 * Return regular attributes.
510 * The object must exist. Currently all the attributes should be
511 * returned, but in the future this can be improved so that only
512 * a selected set is returned. This can improve performance as in
513 * some cases attributes are stored in different places and
514 * getting them all can be an iterative and expensive process.
516 * \param[in] env execution environment for this thread
517 * \param[in] dt object
518 * \param[out] attr attributes to fill
520 * \retval 0 on success
521 * \retval negative negated errno on error
523 int (*do_attr_get)(const struct lu_env *env,
524 struct dt_object *dt,
525 struct lu_attr *attr);
528 * Declare intention to change regular object's attributes.
530 * Notify the underlying filesystem that the regular attributes may
531 * change in this transaction. This enables the layer below to prepare
532 * resources (e.g. journal credits in ext4). This method should be
533 * called between creating the transaction and starting it. Note that
534 * the la_valid field of \a attr specifies which attributes will change.
535 * The object need not exist.
537 * \param[in] env execution environment for this thread
538 * \param[in] dt object
539 * \param[in] attr attributes to change specified in attr.la_valid
540 * \param[in] th transaction handle
542 * \retval 0 on success
543 * \retval negative negated errno on error
545 int (*do_declare_attr_set)(const struct lu_env *env,
546 struct dt_object *dt,
547 const struct lu_attr *attr,
551 * Change regular attributes.
553 * Change regular attributes in the given transaction. Note only
554 * attributes flagged by attr.la_valid change. The object must
555 * exist. If the layer implementing this method is responsible for
556 * quota, then the method should maintain object accounting for the
557 * given credentials when la_uid/la_gid changes.
559 * \param[in] env execution environment for this thread
560 * \param[in] dt object
561 * \param[in] attr new attributes to apply
562 * \param[in] th transaction handle
564 * \retval 0 on success
565 * \retval negative negated errno on error
567 int (*do_attr_set)(const struct lu_env *env,
568 struct dt_object *dt,
569 const struct lu_attr *attr,
573 * Declare intention to request extented attribute.
575 * Notify the underlying filesystem that the caller may request extended
576 * attribute with ->do_xattr_get() soon. This allows OSD to implement
577 * prefetching logic in an object-oriented manner. The implementation
578 * can be noop. This method should avoid expensive delays such as
579 * waiting on disk I/O, otherwise the goal of enabling a performance
580 * optimization would be defeated.
582 * \param[in] env execution environment for this thread
583 * \param[in] dt object
584 * \param[in] buf unused, may be removed in the future
585 * \param[in] name name of the extended attribute
587 * \retval 0 on success
588 * \retval negative negated errno on error
590 int (*do_declare_xattr_get)(const struct lu_env *env,
591 struct dt_object *dt,
596 * Return a value of an extended attribute.
598 * The object must exist. If the buffer is NULL, then the method
599 * must return the size of the value.
601 * \param[in] env execution environment for this thread
602 * \param[in] dt object
603 * \param[out] buf buffer in which to store the value
604 * \param[in] name name of the extended attribute
606 * \retval 0 on success
607 * \retval -ERANGE if \a buf is too small
608 * \retval negative negated errno on error
609 * \retval positive value's size if \a buf is NULL or has zero size
611 int (*do_xattr_get)(const struct lu_env *env,
612 struct dt_object *dt,
617 * Declare intention to change an extended attribute.
619 * Notify the underlying filesystem that the extended attribute may
620 * change in this transaction. This enables the layer below to prepare
621 * resources (e.g. journal credits in ext4). This method should be
622 * called between creating the transaction and starting it. The object
625 * \param[in] env execution environment for this thread
626 * \param[in] dt object
627 * \param[in] buf buffer storing new value of the attribute
628 * \param[in] name name of the attribute
629 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
630 * LU_XATTR_REPLACE - fail if EA doesn't exist
631 * \param[in] th transaction handle
633 * \retval 0 on success
634 * \retval negative negated errno on error
636 int (*do_declare_xattr_set)(const struct lu_env *env,
637 struct dt_object *dt,
638 const struct lu_buf *buf,
644 * Set an extended attribute.
646 * Change or replace the specified extended attribute (EA).
647 * The flags passed in \a fl dictate whether the EA is to be
648 * created or replaced, as follows.
649 * LU_XATTR_CREATE - fail if EA exists
650 * LU_XATTR_REPLACE - fail if EA doesn't exist
651 * The object must exist.
653 * \param[in] env execution environment for this thread
654 * \param[in] dt object
655 * \param[in] buf buffer storing new value of the attribute
656 * \param[in] name name of the attribute
657 * \param[in] fl flags indicating EA creation or replacement
658 * \param[in] th transaction handle
660 * \retval 0 on success
661 * \retval negative negated errno on error
663 int (*do_xattr_set)(const struct lu_env *env,
664 struct dt_object *dt,
665 const struct lu_buf *buf,
671 * Declare intention to delete an extended attribute.
673 * Notify the underlying filesystem that the extended attribute may
674 * be deleted in this transaction. This enables the layer below to
675 * prepare resources (e.g. journal credits in ext4). This method
676 * should be called between creating the transaction and starting it.
677 * The object need not exist.
679 * \param[in] env execution environment for this thread
680 * \param[in] dt object
681 * \param[in] name name of the attribute
682 * \param[in] th transaction handle
684 * \retval 0 on success
685 * \retval negative negated errno on error
687 int (*do_declare_xattr_del)(const struct lu_env *env,
688 struct dt_object *dt,
693 * Delete an extended attribute.
695 * This method deletes the specified extended attribute. The object
698 * \param[in] env execution environment for this thread
699 * \param[in] dt object
700 * \param[in] name name of the attribute
701 * \param[in] th transaction handle
703 * \retval 0 on success
704 * \retval negative negated errno on error
706 int (*do_xattr_del)(const struct lu_env *env,
707 struct dt_object *dt,
712 * Return a list of the extended attributes.
714 * Fills the passed buffer with a list of the extended attributes
715 * found in the object. The names are separated with '\0'.
716 * The object must exist.
718 * \param[in] env execution environment for this thread
719 * \param[in] dt object
720 * \param[out] buf buffer to put the list in
722 * \retval positive bytes used/required in the buffer
723 * \retval negative negated errno on error
725 int (*do_xattr_list)(const struct lu_env *env,
726 struct dt_object *dt,
727 const struct lu_buf *buf);
730 * Prepare allocation hint for a new object.
732 * This method is used by the caller to inform OSD of the parent-child
733 * relationship between two objects and enable efficient object
734 * allocation. Filled allocation hint will be passed to ->do_create()
737 * \param[in] env execution environment for this thread
738 * \param[out] ah allocation hint
739 * \param[in] parent parent object (can be NULL)
740 * \param[in] child child object
741 * \param[in] _mode type of the child object
743 void (*do_ah_init)(const struct lu_env *env,
744 struct dt_allocation_hint *ah,
745 struct dt_object *parent,
746 struct dt_object *child,
750 * Declare intention to create a new object.
752 * Notify the underlying filesystem that the object may be created
753 * in this transaction. This enables the layer below to prepare
754 * resources (e.g. journal credits in ext4). This method should be
755 * called between creating the transaction and starting it.
757 * If the layer implementing this method is responsible for quota,
758 * then the method should reserve an object for the given credentials
759 * and return an error if quota is over. If object creation later
760 * fails for some reason, then the reservation should be released
761 * properly (usually in ->dt_trans_stop()).
763 * \param[in] env execution environment for this thread
764 * \param[in] dt object
765 * \param[in] attr attributes of the new object
766 * \param[in] hint allocation hint
767 * \param[in] dof object format
768 * \param[in] th transaction handle
770 * \retval 0 on success
771 * \retval negative negated errno on error
773 int (*do_declare_create)(const struct lu_env *env,
774 struct dt_object *dt,
775 struct lu_attr *attr,
776 struct dt_allocation_hint *hint,
777 struct dt_object_format *dof,
783 * The method creates the object passed with the specified attributes
784 * and object format. Object allocation procedure can use information
785 * stored in the allocation hint. Different object formats are supported
786 * (see enum dt_format_type and struct dt_object_format) depending on
787 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
788 * in the LU-object header attributes.
790 * If the layer implementing this method is responsible for quota,
791 * then the method should maintain object accounting for the given
794 * \param[in] env execution environment for this thread
795 * \param[in] dt object
796 * \param[in] attr attributes of the new object
797 * \param[in] hint allocation hint
798 * \param[in] dof object format
799 * \param[in] th transaction handle
801 * \retval 0 on success
802 * \retval negative negated errno on error
804 int (*do_create)(const struct lu_env *env,
805 struct dt_object *dt,
806 struct lu_attr *attr,
807 struct dt_allocation_hint *hint,
808 struct dt_object_format *dof,
812 * Declare intention to destroy an object.
814 * Notify the underlying filesystem that the object may be destroyed
815 * in this transaction. This enables the layer below to prepare
816 * resources (e.g. journal credits in ext4). This method should be
817 * called between creating the transaction and starting it. The object
820 * \param[in] env execution environment for this thread
821 * \param[in] dt object
822 * \param[in] th transaction handle
824 * \retval 0 on success
825 * \retval negative negated errno on error
827 int (*do_declare_destroy)(const struct lu_env *env,
828 struct dt_object *dt,
834 * This method destroys the object and all the resources associated
835 * with the object (data, key/value pairs, extended attributes, etc).
836 * The object must exist. If destroy is successful, then flag
837 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
838 * instance of in-core object. Any subsequent access to the same FID
839 * should get another instance with no LOHA_EXIST flag set.
841 * If the layer implementing this method is responsible for quota,
842 * then the method should maintain object accounting for the given
845 * \param[in] env execution environment for this thread
846 * \param[in] dt object
847 * \param[in] th transaction handle
849 * \retval 0 on success
850 * \retval negative negated errno on error
852 int (*do_destroy)(const struct lu_env *env,
853 struct dt_object *dt,
857 * Try object as an index.
859 * Announce that this object is going to be used as an index. This
860 * operation checks that object supports indexing operations and
861 * installs appropriate dt_index_operations vector on success.
862 * Also probes for features. Operation is successful if all required
863 * features are supported. It's not possible to access the object
864 * with index methods before ->do_index_try() returns success.
866 * \param[in] env execution environment for this thread
867 * \param[in] dt object
868 * \param[in] feat index features
870 * \retval 0 on success
871 * \retval negative negated errno on error
873 int (*do_index_try)(const struct lu_env *env,
874 struct dt_object *dt,
875 const struct dt_index_features *feat);
878 * Declare intention to increment nlink count.
880 * Notify the underlying filesystem that the nlink regular attribute
881 * be changed in this transaction. This enables the layer below to
882 * prepare resources (e.g. journal credits in ext4). This method
883 * should be called between creating the transaction and starting it.
884 * The object need not exist.
886 * \param[in] env execution environment for this thread
887 * \param[in] dt object
888 * \param[in] th transaction handle
890 * \retval 0 on success
891 * \retval negative negated errno on error
893 int (*do_declare_ref_add)(const struct lu_env *env,
894 struct dt_object *dt,
900 * Increment nlink (from the regular attributes set) in the given
901 * transaction. Note the absolute limit for nlink should be learnt
902 * from struct dt_device_param::ddp_max_nlink. The object must exist.
904 * \param[in] env execution environment for this thread
905 * \param[in] dt object
906 * \param[in] th transaction handle
908 * \retval 0 on success
909 * \retval negative negated errno on error
911 int (*do_ref_add)(const struct lu_env *env,
912 struct dt_object *dt, struct thandle *th);
915 * Declare intention to decrement nlink count.
917 * Notify the underlying filesystem that the nlink regular attribute
918 * be changed in this transaction. This enables the layer below to
919 * prepare resources (e.g. journal credits in ext4). This method
920 * should be called between creating the transaction and starting it.
921 * The object need not exist.
923 * \param[in] env execution environment for this thread
924 * \param[in] dt object
925 * \param[in] th transaction handle
927 * \retval 0 on success
928 * \retval negative negated errno on error
930 int (*do_declare_ref_del)(const struct lu_env *env,
931 struct dt_object *dt,
937 * Decrement nlink (from the regular attributes set) in the given
938 * transaction. The object must exist.
940 * \param[in] env execution environment for this thread
941 * \param[in] dt object
942 * \param[in] th transaction handle
944 * \retval 0 on success
945 * \retval negative negated errno on error
947 int (*do_ref_del)(const struct lu_env *env,
948 struct dt_object *dt,
954 * The method is called to sync specified range of the object to a
955 * persistent storage. The control is returned once the operation is
956 * complete. The difference from ->do_sync() is that the object can
957 * be in-sync with the persistent storage (nothing to flush), then
958 * the method returns quickly with no I/O overhead. So, this method
959 * should be preferred over ->do_sync() where possible. Also note that
960 * if the object isn't clean, then some disk filesystems will call
961 * ->do_sync() to maintain overall consistency, in which case it's
962 * still very expensive.
964 * \param[in] env execution environment for this thread
965 * \param[in] dt object
966 * \param[in] start start of the range to sync
967 * \param[in] end end of the range to sync
969 * \retval 0 on success
970 * \retval negative negated errno on error
972 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
973 __u64 start, __u64 end);
978 * Lock object(s) using Distributed Lock Manager (LDLM).
980 * Get LDLM locks for the object. Currently used to lock "remote"
981 * objects in DNE configuration - a service running on MDTx needs
982 * to lock an object on MDTy.
984 * \param[in] env execution environment for this thread
985 * \param[in] dt object
986 * \param[out] lh lock handle, sometimes used, sometimes not
987 * \param[in] einfo ldlm callbacks, locking type and mode
988 * \param[out] einfo private data to be passed to unlock later
989 * \param[in] policy inodebits data
991 * \retval 0 on success
992 * \retval negative negated errno on error
994 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
995 struct lustre_handle *lh,
996 struct ldlm_enqueue_info *einfo,
997 union ldlm_policy_data *policy);
1002 * Release LDLM lock(s) granted with ->do_object_lock().
1004 * \param[in] env execution environment for this thread
1005 * \param[in] dt object
1006 * \param[in] einfo lock handles, from ->do_object_lock()
1007 * \param[in] policy inodebits data
1009 * \retval 0 on success
1010 * \retval negative negated errno on error
1012 int (*do_object_unlock)(const struct lu_env *env,
1013 struct dt_object *dt,
1014 struct ldlm_enqueue_info *einfo,
1015 union ldlm_policy_data *policy);
1018 * Invalidate attribute cache.
1020 * This method invalidate attribute cache of the object, which is on OSP
1023 * \param[in] env execution envionment for this thread
1024 * \param[in] dt object
1026 * \retval 0 on success
1027 * \retval negative negated errno on error
1029 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1032 * Declare intention to instaintiate extended layout component.
1034 * \param[in] env execution environment
1035 * \param[in] dt DT object
1036 * \param[in] layout data structure to describe the changes to
1037 * the DT object's layout
1038 * \param[in] buf buffer containing client's lovea or empty
1041 * \retval -ne error code
1043 int (*do_declare_layout_change)(const struct lu_env *env,
1044 struct dt_object *dt,
1045 struct md_layout_change *mlc,
1046 struct thandle *th);
1049 * Client is trying to write to un-instantiated layout component.
1051 * \param[in] env execution environment
1052 * \param[in] dt DT object
1053 * \param[in] layout data structure to describe the changes to
1054 * the DT object's layout
1055 * \param[in] buf buffer containing client's lovea or empty
1058 * \retval -ne error code
1060 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1061 struct md_layout_change *mlc,
1062 struct thandle *th);
1066 DT_BUFS_TYPE_READ = 0x0000,
1067 DT_BUFS_TYPE_WRITE = 0x0001,
1068 DT_BUFS_TYPE_READAHEAD = 0x0002,
1069 DT_BUFS_TYPE_LOCAL = 0x0004,
1073 * Per-dt-object operations on "file body" - unstructure raw data.
1075 struct dt_body_operations {
1079 * Read unstructured data from an existing regular object.
1080 * Only data before attr.la_size is returned.
1082 * \param[in] env execution environment for this thread
1083 * \param[in] dt object
1084 * \param[out] buf buffer (including size) to copy data in
1085 * \param[in] pos position in the object to start
1086 * \param[out] pos original value of \a pos + bytes returned
1088 * \retval positive bytes read on success
1089 * \retval negative negated errno on error
1091 ssize_t (*dbo_read)(const struct lu_env *env,
1092 struct dt_object *dt,
1097 * Declare intention to write data to object.
1099 * Notify the underlying filesystem that data may be written in
1100 * this transaction. This enables the layer below to prepare resources
1101 * (e.g. journal credits in ext4). This method should be called
1102 * between creating the transaction and starting it. The object need
1103 * not exist. If the layer implementing this method is responsible for
1104 * quota, then the method should reserve space for the given credentials
1105 * and return an error if quota is over. If the write later fails
1106 * for some reason, then the reserve should be released properly
1107 * (usually in ->dt_trans_stop()).
1109 * \param[in] env execution environment for this thread
1110 * \param[in] dt object
1111 * \param[in] buf buffer (including size) to copy data from
1112 * \param[in] pos position in the object to start
1113 * \param[in] th transaction handle
1115 * \retval 0 on success
1116 * \retval negative negated errno on error
1118 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1119 struct dt_object *dt,
1120 const struct lu_buf *buf,
1122 struct thandle *th);
1125 * Write unstructured data to regular existing object.
1127 * The method allocates space and puts data in. Also, the method should
1128 * maintain attr.la_size properly. Partial writes are possible.
1130 * If the layer implementing this method is responsible for quota,
1131 * then the method should maintain space accounting for the given
1134 * \param[in] env execution environment for this thread
1135 * \param[in] dt object
1136 * \param[in] buf buffer (including size) to copy data from
1137 * \param[in] pos position in the object to start
1138 * \param[out] pos \a pos + bytes written
1139 * \param[in] th transaction handle
1140 * \param[in] ignore unused (was used to request quota ignorance)
1142 * \retval positive bytes written on success
1143 * \retval negative negated errno on error
1145 ssize_t (*dbo_write)(const struct lu_env *env,
1146 struct dt_object *dt,
1147 const struct lu_buf *buf,
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
1483 * \param[in] ignore unused (was used to request quota ignorance)
1485 * \retval 0 on success
1486 * \retval negative negated errno on error
1488 int (*dio_insert)(const struct lu_env *env,
1489 struct dt_object *dt,
1490 const struct dt_rec *rec,
1491 const struct dt_key *key,
1496 * Declare intention to delete a key/value from an index.
1498 * Notify the underlying filesystem that key/value may be deleted in
1499 * this transaction. This enables the layer below to prepare resources
1500 * (e.g. journal credits in ext4). This method should be called
1501 * between creating the transaction and starting it. Key/value format
1502 * and size is subject to ->do_index_try(). The object need not exist.
1504 * \param[in] env execution environment for this thread
1505 * \param[in] dt object
1506 * \param[in] key key
1507 * \param[in] th transaction handle
1509 * \retval 0 on success
1510 * \retval negative negated errno on error
1512 int (*dio_declare_delete)(const struct lu_env *env,
1513 struct dt_object *dt,
1514 const struct dt_key *key,
1515 struct thandle *th);
1518 * Delete key/value pair from an index.
1520 * The method deletes specified key and corresponding value from the
1521 * given index object. The internal consistency is maintained by the
1522 * method or the functionality below. The format and size of the key
1523 * should have been negotiated before using ->do_index_try(), no
1524 * additional information can be specified to the method.
1526 * \param[in] env execution environment for this thread
1527 * \param[in] dt object
1528 * \param[in] key key
1529 * \param[in] th transaction handle
1531 * \retval 0 on success
1532 * \retval negative negated errno on error
1534 int (*dio_delete)(const struct lu_env *env,
1535 struct dt_object *dt,
1536 const struct dt_key *key,
1537 struct thandle *th);
1540 * Iterator interface.
1542 * Methods to iterate over an existing index, list the keys stored and
1543 * associated values, get key/value size, etc.
1547 * Allocate and initialize new iterator.
1549 * The iterator is a handler to be used in the subsequent
1550 * methods to access index's content. Note the position is
1551 * not defined at this point and should be initialized with
1552 * ->get() or ->load() method.
1554 * \param[in] env execution environment for this thread
1555 * \param[in] dt object
1556 * \param[in] attr ask the iterator to return part of
1557 the records, see LUDA_* for details
1559 * \retval pointer iterator pointer on success
1560 * \retval ERR_PTR(errno) on error
1562 struct dt_it *(*init)(const struct lu_env *env,
1563 struct dt_object *dt,
1569 * Release the specified iterator and all the resources
1570 * associated (e.g. the object, index cache, etc).
1572 * \param[in] env execution environment for this thread
1573 * \param[in] di iterator to release
1575 void (*fini)(const struct lu_env *env,
1579 * Move position of iterator.
1581 * Move the position of the specified iterator to the specified
1584 * \param[in] env execution environment for this thread
1585 * \param[in] di iterator
1586 * \param[in] key key to position to
1588 * \retval 0 if exact key is found
1589 * \retval 1 if at the record with least key
1590 * not larger than the key
1591 * \retval negative negated errno on error
1593 int (*get)(const struct lu_env *env,
1595 const struct dt_key *key);
1600 * Complimentary method for dt_it_ops::get() above. Some
1601 * implementation can increase a reference on the iterator in
1602 * dt_it_ops::get(). So the caller should be able to release
1603 * with dt_it_ops::put().
1605 * \param[in] env execution environment for this thread
1606 * \param[in] di iterator
1608 void (*put)(const struct lu_env *env,
1612 * Move to next record.
1614 * Moves the position of the iterator to a next record
1616 * \param[in] env execution environment for this thread
1617 * \param[in] di iterator
1619 * \retval 1 if no more records
1620 * \retval 0 on success, the next record is found
1621 * \retval negative negated errno on error
1623 int (*next)(const struct lu_env *env,
1629 * Returns a pointer to a buffer containing the key of the
1630 * record at the current position. The pointer is valid and
1631 * retains data until ->get(), ->load() and ->fini() methods
1634 * \param[in] env execution environment for this thread
1635 * \param[in] di iterator
1637 * \retval pointer to key on success
1638 * \retval ERR_PTR(errno) on error
1640 struct dt_key *(*key)(const struct lu_env *env,
1641 const struct dt_it *di);
1646 * Returns size of the key at the current position.
1648 * \param[in] env execution environment for this thread
1649 * \param[in] di iterator
1651 * \retval key's size on success
1652 * \retval negative negated errno on error
1654 int (*key_size)(const struct lu_env *env,
1655 const struct dt_it *di);
1660 * Stores the value of the record at the current position. The
1661 * buffer must be big enough (as negotiated with
1662 * ->do_index_try() or ->rec_size()). The caller can specify
1663 * she is interested only in part of the record, using attr
1664 * argument (see LUDA_* definitions for the details).
1666 * \param[in] env execution environment for this thread
1667 * \param[in] di iterator
1668 * \param[out] rec buffer to store value in
1669 * \param[in] attr specify part of the value to copy
1671 * \retval 0 on success
1672 * \retval negative negated errno on error
1674 int (*rec)(const struct lu_env *env,
1675 const struct dt_it *di,
1680 * Return record size.
1682 * Returns size of the record at the current position. The
1683 * \a attr can be used to specify only the parts of the record
1684 * needed to be returned. (see LUDA_* definitions for the
1687 * \param[in] env execution environment for this thread
1688 * \param[in] di iterator
1689 * \param[in] attr part of the record to return
1691 * \retval record's size on success
1692 * \retval negative negated errno on error
1694 int (*rec_size)(const struct lu_env *env,
1695 const struct dt_it *di,
1699 * Return a cookie (hash).
1701 * Returns the cookie (usually hash) of the key at the current
1702 * position. This allows the caller to resume iteration at this
1703 * position later. The exact value is specific to implementation
1704 * and should not be interpreted by the caller.
1706 * \param[in] env execution environment for this thread
1707 * \param[in] di iterator
1709 * \retval cookie/hash of the key
1711 __u64 (*store)(const struct lu_env *env,
1712 const struct dt_it *di);
1715 * Initialize position using cookie/hash.
1717 * Initializes the current position of the iterator to one
1718 * described by the cookie/hash as returned by ->store()
1721 * \param[in] env execution environment for this thread
1722 * \param[in] di iterator
1723 * \param[in] hash cookie/hash value
1725 * \retval positive if current position points to
1726 * record with least cookie not larger
1728 * \retval 0 if current position matches cookie
1729 * \retval negative negated errno on error
1731 int (*load)(const struct lu_env *env,
1732 const struct dt_it *di,
1738 int (*key_rec)(const struct lu_env *env,
1739 const struct dt_it *di,
1744 enum dt_otable_it_valid {
1745 DOIV_ERROR_HANDLE = 0x0001,
1746 DOIV_DRYRUN = 0x0002,
1749 enum dt_otable_it_flags {
1750 /* Exit when fail. */
1751 DOIF_FAILOUT = 0x0001,
1753 /* Reset iteration position to the device beginning. */
1754 DOIF_RESET = 0x0002,
1756 /* There is up layer component uses the iteration. */
1757 DOIF_OUTUSED = 0x0004,
1759 /* Check only without repairing. */
1760 DOIF_DRYRUN = 0x0008,
1763 /* otable based iteration needs to use the common DT iteration APIs.
1764 * To initialize the iteration, it needs call dio_it::init() firstly.
1765 * Here is how the otable based iteration should prepare arguments to
1766 * call dt_it_ops::init().
1768 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1769 * is composed of two parts:
1770 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1771 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1772 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1775 struct lu_device dd_lu_dev;
1776 const struct dt_device_operations *dd_ops;
1779 * List of dt_txn_callback (see below). This is not protected in any
1780 * way, because callbacks are supposed to be added/deleted only during
1781 * single-threaded start-up shut-down procedures.
1783 struct list_head dd_txn_callbacks;
1784 unsigned int dd_record_fid_accessed:1,
1788 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1789 void dt_device_fini(struct dt_device *dev);
1791 static inline int lu_device_is_dt(const struct lu_device *d)
1793 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1796 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1798 LASSERT(lu_device_is_dt(l));
1799 return container_of0(l, struct dt_device, dd_lu_dev);
1803 struct lu_object do_lu;
1804 const struct dt_object_operations *do_ops;
1805 const struct dt_body_operations *do_body_ops;
1806 const struct dt_index_operations *do_index_ops;
1810 * In-core representation of per-device local object OID storage
1812 struct local_oid_storage {
1813 /* all initialized llog systems on this node linked by this */
1814 struct list_head los_list;
1816 /* how many handle's reference this los has */
1817 atomic_t los_refcount;
1818 struct dt_device *los_dev;
1819 struct dt_object *los_obj;
1821 /* data used to generate new fids */
1822 struct mutex los_id_lock;
1827 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1829 return &d->dd_lu_dev;
1832 static inline struct dt_object *lu2dt(struct lu_object *l)
1834 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1835 return container_of0(l, struct dt_object, do_lu);
1838 int dt_object_init(struct dt_object *obj,
1839 struct lu_object_header *h, struct lu_device *d);
1841 void dt_object_fini(struct dt_object *obj);
1843 static inline int dt_object_exists(const struct dt_object *dt)
1845 return lu_object_exists(&dt->do_lu);
1848 static inline int dt_object_remote(const struct dt_object *dt)
1850 return lu_object_remote(&dt->do_lu);
1853 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1855 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1856 return container_of0(o, struct dt_object, do_lu);
1859 static inline struct dt_object *dt_object_child(struct dt_object *o)
1861 return container_of0(lu_object_next(&(o)->do_lu),
1862 struct dt_object, do_lu);
1866 * This is the general purpose transaction handle.
1867 * 1. Transaction Life Cycle
1868 * This transaction handle is allocated upon starting a new transaction,
1869 * and deallocated after this transaction is committed.
1870 * 2. Transaction Nesting
1871 * We do _NOT_ support nested transaction. So, every thread should only
1872 * have one active transaction, and a transaction only belongs to one
1873 * thread. Due to this, transaction handle need no reference count.
1874 * 3. Transaction & dt_object locking
1875 * dt_object locks should be taken inside transaction.
1876 * 4. Transaction & RPC
1877 * No RPC request should be issued inside transaction.
1880 /** the dt device on which the transactions are executed */
1881 struct dt_device *th_dev;
1883 /* point to the top thandle, XXX this is a bit hacky right now,
1884 * but normal device trans callback triggered by the bottom
1885 * device (OSP/OSD == sub thandle layer) needs to get the
1886 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1887 * top thandle here for now, will fix it when we have better
1888 * callback mechanism */
1889 struct thandle *th_top;
1891 /** the last operation result in this transaction.
1892 * this value is used in recovery */
1895 /** whether we need sync commit */
1896 unsigned int th_sync:1,
1897 /* local transation, no need to inform other layers */
1899 /* Whether we need wait the transaction to be submitted
1900 * (send to remote target) */
1902 /* complex transaction which will track updates on all targets,
1908 * Transaction call-backs.
1910 * These are invoked by osd (or underlying transaction engine) when
1911 * transaction changes state.
1913 * Call-backs are used by upper layers to modify transaction parameters and to
1914 * perform some actions on for each transaction state transition. Typical
1915 * example is mdt registering call-back to write into last-received file
1916 * before each transaction commit.
1918 struct dt_txn_callback {
1919 int (*dtc_txn_start)(const struct lu_env *env,
1920 struct thandle *txn, void *cookie);
1921 int (*dtc_txn_stop)(const struct lu_env *env,
1922 struct thandle *txn, void *cookie);
1923 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1926 struct list_head dtc_linkage;
1929 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1930 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1932 int dt_txn_hook_start(const struct lu_env *env,
1933 struct dt_device *dev, struct thandle *txn);
1934 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1935 void dt_txn_hook_commit(struct thandle *txn);
1937 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1940 * Callback function used for parsing path.
1941 * \see llo_store_resolve
1943 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1947 #define DT_MAX_PATH 1024
1949 int dt_path_parser(const struct lu_env *env,
1950 char *local, dt_entry_func_t entry_func,
1954 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1955 const char *path, struct lu_fid *fid);
1957 struct dt_object *dt_store_open(const struct lu_env *env,
1958 struct dt_device *dt,
1959 const char *dirname,
1960 const char *filename,
1961 struct lu_fid *fid);
1963 struct dt_object *dt_find_or_create(const struct lu_env *env,
1964 struct dt_device *dt,
1965 const struct lu_fid *fid,
1966 struct dt_object_format *dof,
1967 struct lu_attr *attr);
1969 struct dt_object *dt_locate_at(const struct lu_env *env,
1970 struct dt_device *dev,
1971 const struct lu_fid *fid,
1972 struct lu_device *top_dev,
1973 const struct lu_object_conf *conf);
1975 static inline struct dt_object *
1976 dt_locate(const struct lu_env *env, struct dt_device *dev,
1977 const struct lu_fid *fid)
1979 return dt_locate_at(env, dev, fid,
1980 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1983 static inline struct dt_object *
1984 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1986 struct lu_object *lo;
1988 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
1989 if (lo->lo_dev == &dt_dev->dd_lu_dev)
1990 return container_of(lo, struct dt_object, do_lu);
1995 static inline void dt_object_put(const struct lu_env *env,
1996 struct dt_object *dto)
1998 lu_object_put(env, &dto->do_lu);
2001 static inline void dt_object_put_nocache(const struct lu_env *env,
2002 struct dt_object *dto)
2004 lu_object_put_nocache(env, &dto->do_lu);
2007 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2008 const struct lu_fid *first_fid,
2009 struct local_oid_storage **los);
2010 void local_oid_storage_fini(const struct lu_env *env,
2011 struct local_oid_storage *los);
2012 int local_object_fid_generate(const struct lu_env *env,
2013 struct local_oid_storage *los,
2014 struct lu_fid *fid);
2015 int local_object_declare_create(const struct lu_env *env,
2016 struct local_oid_storage *los,
2017 struct dt_object *o,
2018 struct lu_attr *attr,
2019 struct dt_object_format *dof,
2020 struct thandle *th);
2021 int local_object_create(const struct lu_env *env,
2022 struct local_oid_storage *los,
2023 struct dt_object *o,
2024 struct lu_attr *attr, struct dt_object_format *dof,
2025 struct thandle *th);
2026 struct dt_object *local_file_find(const struct lu_env *env,
2027 struct local_oid_storage *los,
2028 struct dt_object *parent,
2030 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2031 struct local_oid_storage *los,
2032 struct dt_object *parent,
2033 const char *name, __u32 mode);
2034 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2035 struct dt_device *dt,
2036 const struct lu_fid *fid,
2037 struct dt_object *parent,
2041 local_index_find_or_create(const struct lu_env *env,
2042 struct local_oid_storage *los,
2043 struct dt_object *parent,
2044 const char *name, __u32 mode,
2045 const struct dt_index_features *ft);
2047 local_index_find_or_create_with_fid(const struct lu_env *env,
2048 struct dt_device *dt,
2049 const struct lu_fid *fid,
2050 struct dt_object *parent,
2051 const char *name, __u32 mode,
2052 const struct dt_index_features *ft);
2053 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2054 struct dt_object *parent, const char *name);
2056 static inline int dt_object_lock(const struct lu_env *env,
2057 struct dt_object *o, struct lustre_handle *lh,
2058 struct ldlm_enqueue_info *einfo,
2059 union ldlm_policy_data *policy)
2062 LASSERT(o->do_ops != NULL);
2063 LASSERT(o->do_ops->do_object_lock != NULL);
2064 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2067 static inline int dt_object_unlock(const struct lu_env *env,
2068 struct dt_object *o,
2069 struct ldlm_enqueue_info *einfo,
2070 union ldlm_policy_data *policy)
2073 LASSERT(o->do_ops != NULL);
2074 LASSERT(o->do_ops->do_object_unlock != NULL);
2075 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2078 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2079 const char *name, struct lu_fid *fid);
2081 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2082 __u64 start, __u64 end)
2086 LASSERT(o->do_ops->do_object_sync);
2087 return o->do_ops->do_object_sync(env, o, start, end);
2090 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2091 struct thandle *th);
2092 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2093 dt_obj_version_t version, struct thandle *th);
2094 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2097 int dt_read(const struct lu_env *env, struct dt_object *dt,
2098 struct lu_buf *buf, loff_t *pos);
2099 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2100 struct lu_buf *buf, loff_t *pos);
2101 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2102 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2103 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2104 union lu_page *lp, size_t nob,
2105 const struct dt_it_ops *iops,
2106 struct dt_it *it, __u32 attr, void *arg);
2107 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2108 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2110 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2111 struct idx_info *ii, const struct lu_rdpg *rdpg);
2113 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2114 struct dt_device *d)
2116 LASSERT(d->dd_ops->dt_trans_create);
2117 return d->dd_ops->dt_trans_create(env, d);
2120 static inline int dt_trans_start(const struct lu_env *env,
2121 struct dt_device *d, struct thandle *th)
2123 LASSERT(d->dd_ops->dt_trans_start);
2124 return d->dd_ops->dt_trans_start(env, d, th);
2127 /* for this transaction hooks shouldn't be called */
2128 static inline int dt_trans_start_local(const struct lu_env *env,
2129 struct dt_device *d, struct thandle *th)
2131 LASSERT(d->dd_ops->dt_trans_start);
2133 return d->dd_ops->dt_trans_start(env, d, th);
2136 static inline int dt_trans_stop(const struct lu_env *env,
2137 struct dt_device *d, struct thandle *th)
2139 LASSERT(d->dd_ops->dt_trans_stop);
2140 return d->dd_ops->dt_trans_stop(env, d, th);
2143 static inline int dt_trans_cb_add(struct thandle *th,
2144 struct dt_txn_commit_cb *dcb)
2146 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2147 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2148 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2153 static inline int dt_declare_record_write(const struct lu_env *env,
2154 struct dt_object *dt,
2155 const struct lu_buf *buf,
2161 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2162 LASSERT(th != NULL);
2163 LASSERT(dt->do_body_ops);
2164 LASSERT(dt->do_body_ops->dbo_declare_write);
2165 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2169 static inline int dt_declare_create(const struct lu_env *env,
2170 struct dt_object *dt,
2171 struct lu_attr *attr,
2172 struct dt_allocation_hint *hint,
2173 struct dt_object_format *dof,
2177 LASSERT(dt->do_ops);
2178 LASSERT(dt->do_ops->do_declare_create);
2180 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2181 return cfs_fail_err;
2183 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2186 static inline int dt_create(const struct lu_env *env,
2187 struct dt_object *dt,
2188 struct lu_attr *attr,
2189 struct dt_allocation_hint *hint,
2190 struct dt_object_format *dof,
2194 LASSERT(dt->do_ops);
2195 LASSERT(dt->do_ops->do_create);
2197 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2198 return cfs_fail_err;
2200 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2203 static inline int dt_declare_destroy(const struct lu_env *env,
2204 struct dt_object *dt,
2208 LASSERT(dt->do_ops);
2209 LASSERT(dt->do_ops->do_declare_destroy);
2211 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2212 return cfs_fail_err;
2214 return dt->do_ops->do_declare_destroy(env, dt, th);
2217 static inline int dt_destroy(const struct lu_env *env,
2218 struct dt_object *dt,
2222 LASSERT(dt->do_ops);
2223 LASSERT(dt->do_ops->do_destroy);
2225 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2226 return cfs_fail_err;
2228 return dt->do_ops->do_destroy(env, dt, th);
2231 static inline void dt_read_lock(const struct lu_env *env,
2232 struct dt_object *dt,
2236 LASSERT(dt->do_ops);
2237 LASSERT(dt->do_ops->do_read_lock);
2238 dt->do_ops->do_read_lock(env, dt, role);
2241 static inline void dt_write_lock(const struct lu_env *env,
2242 struct dt_object *dt,
2246 LASSERT(dt->do_ops);
2247 LASSERT(dt->do_ops->do_write_lock);
2248 dt->do_ops->do_write_lock(env, dt, role);
2251 static inline void dt_read_unlock(const struct lu_env *env,
2252 struct dt_object *dt)
2255 LASSERT(dt->do_ops);
2256 LASSERT(dt->do_ops->do_read_unlock);
2257 dt->do_ops->do_read_unlock(env, dt);
2260 static inline void dt_write_unlock(const struct lu_env *env,
2261 struct dt_object *dt)
2264 LASSERT(dt->do_ops);
2265 LASSERT(dt->do_ops->do_write_unlock);
2266 dt->do_ops->do_write_unlock(env, dt);
2269 static inline int dt_write_locked(const struct lu_env *env,
2270 struct dt_object *dt)
2273 LASSERT(dt->do_ops);
2274 LASSERT(dt->do_ops->do_write_locked);
2275 return dt->do_ops->do_write_locked(env, dt);
2278 static inline int dt_declare_attr_get(const struct lu_env *env,
2279 struct dt_object *dt)
2282 LASSERT(dt->do_ops);
2283 LASSERT(dt->do_ops->do_declare_attr_get);
2285 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2286 return cfs_fail_err;
2288 return dt->do_ops->do_declare_attr_get(env, dt);
2291 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2295 LASSERT(dt->do_ops);
2296 LASSERT(dt->do_ops->do_attr_get);
2298 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2299 return cfs_fail_err;
2301 return dt->do_ops->do_attr_get(env, dt, la);
2304 static inline int dt_declare_attr_set(const struct lu_env *env,
2305 struct dt_object *dt,
2306 const struct lu_attr *la,
2310 LASSERT(dt->do_ops);
2311 LASSERT(dt->do_ops->do_declare_attr_set);
2313 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2314 return cfs_fail_err;
2316 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2319 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2320 const struct lu_attr *la, struct thandle *th)
2323 LASSERT(dt->do_ops);
2324 LASSERT(dt->do_ops->do_attr_set);
2326 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2327 return cfs_fail_err;
2329 return dt->do_ops->do_attr_set(env, dt, la, th);
2332 static inline int dt_declare_ref_add(const struct lu_env *env,
2333 struct dt_object *dt, struct thandle *th)
2336 LASSERT(dt->do_ops);
2337 LASSERT(dt->do_ops->do_declare_ref_add);
2339 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2340 return cfs_fail_err;
2342 return dt->do_ops->do_declare_ref_add(env, dt, th);
2345 static inline int dt_ref_add(const struct lu_env *env,
2346 struct dt_object *dt, struct thandle *th)
2349 LASSERT(dt->do_ops);
2350 LASSERT(dt->do_ops->do_ref_add);
2352 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2353 return cfs_fail_err;
2355 return dt->do_ops->do_ref_add(env, dt, th);
2358 static inline int dt_declare_ref_del(const struct lu_env *env,
2359 struct dt_object *dt, struct thandle *th)
2362 LASSERT(dt->do_ops);
2363 LASSERT(dt->do_ops->do_declare_ref_del);
2365 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2366 return cfs_fail_err;
2368 return dt->do_ops->do_declare_ref_del(env, dt, th);
2371 static inline int dt_ref_del(const struct lu_env *env,
2372 struct dt_object *dt, struct thandle *th)
2375 LASSERT(dt->do_ops);
2376 LASSERT(dt->do_ops->do_ref_del);
2378 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2379 return cfs_fail_err;
2381 return dt->do_ops->do_ref_del(env, dt, th);
2384 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2385 struct niobuf_remote *rnb,
2386 struct niobuf_local *lnb, enum dt_bufs_type rw)
2389 LASSERT(d->do_body_ops);
2390 LASSERT(d->do_body_ops->dbo_bufs_get);
2391 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2392 rnb->rnb_len, lnb, rw);
2395 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2396 struct niobuf_local *lnb, int n)
2399 LASSERT(d->do_body_ops);
2400 LASSERT(d->do_body_ops->dbo_bufs_put);
2401 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2404 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2405 struct niobuf_local *lnb, int n)
2408 LASSERT(d->do_body_ops);
2409 LASSERT(d->do_body_ops->dbo_write_prep);
2410 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2413 static inline int dt_declare_write_commit(const struct lu_env *env,
2414 struct dt_object *d,
2415 struct niobuf_local *lnb,
2416 int n, struct thandle *th)
2418 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2419 LASSERT(th != NULL);
2420 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2424 static inline int dt_write_commit(const struct lu_env *env,
2425 struct dt_object *d, struct niobuf_local *lnb,
2426 int n, struct thandle *th)
2429 LASSERT(d->do_body_ops);
2430 LASSERT(d->do_body_ops->dbo_write_commit);
2431 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2434 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2435 struct niobuf_local *lnb, int n)
2438 LASSERT(d->do_body_ops);
2439 LASSERT(d->do_body_ops->dbo_read_prep);
2440 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2443 static inline int dt_declare_write(const struct lu_env *env,
2444 struct dt_object *dt,
2445 const struct lu_buf *buf, loff_t pos,
2449 LASSERT(dt->do_body_ops);
2450 LASSERT(dt->do_body_ops->dbo_declare_write);
2451 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2454 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2455 const struct lu_buf *buf, loff_t *pos,
2456 struct thandle *th, int rq)
2459 LASSERT(dt->do_body_ops);
2460 LASSERT(dt->do_body_ops->dbo_write);
2461 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th, rq);
2464 static inline int dt_declare_punch(const struct lu_env *env,
2465 struct dt_object *dt, __u64 start,
2466 __u64 end, struct thandle *th)
2469 LASSERT(dt->do_body_ops);
2470 LASSERT(dt->do_body_ops->dbo_declare_punch);
2471 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2474 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2475 __u64 start, __u64 end, struct thandle *th)
2478 LASSERT(dt->do_body_ops);
2479 LASSERT(dt->do_body_ops->dbo_punch);
2480 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2483 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2484 __u64 start, __u64 end, int advice)
2487 LASSERT(dt->do_body_ops);
2488 LASSERT(dt->do_body_ops->dbo_ladvise);
2489 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2492 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2496 if (d->do_body_ops == NULL)
2498 if (d->do_body_ops->dbo_fiemap_get == NULL)
2500 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2503 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2504 struct obd_statfs *osfs)
2507 LASSERT(dev->dd_ops);
2508 LASSERT(dev->dd_ops->dt_statfs);
2509 return dev->dd_ops->dt_statfs(env, dev, osfs);
2512 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2516 LASSERT(dev->dd_ops);
2517 LASSERT(dev->dd_ops->dt_root_get);
2518 return dev->dd_ops->dt_root_get(env, dev, f);
2521 static inline void dt_conf_get(const struct lu_env *env,
2522 const struct dt_device *dev,
2523 struct dt_device_param *param)
2526 LASSERT(dev->dd_ops);
2527 LASSERT(dev->dd_ops->dt_conf_get);
2528 return dev->dd_ops->dt_conf_get(env, dev, param);
2531 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2534 LASSERT(dev->dd_ops);
2535 LASSERT(dev->dd_ops->dt_sync);
2536 return dev->dd_ops->dt_sync(env, dev);
2539 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2542 LASSERT(dev->dd_ops);
2543 LASSERT(dev->dd_ops->dt_ro);
2544 return dev->dd_ops->dt_ro(env, dev);
2547 static inline int dt_declare_insert(const struct lu_env *env,
2548 struct dt_object *dt,
2549 const struct dt_rec *rec,
2550 const struct dt_key *key,
2554 LASSERT(dt->do_index_ops);
2555 LASSERT(dt->do_index_ops->dio_declare_insert);
2557 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2558 return cfs_fail_err;
2560 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2563 static inline int dt_insert(const struct lu_env *env,
2564 struct dt_object *dt,
2565 const struct dt_rec *rec,
2566 const struct dt_key *key,
2571 LASSERT(dt->do_index_ops);
2572 LASSERT(dt->do_index_ops->dio_insert);
2574 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2575 return cfs_fail_err;
2577 return dt->do_index_ops->dio_insert(env, dt, rec, key, th, noquota);
2580 static inline int dt_declare_xattr_del(const struct lu_env *env,
2581 struct dt_object *dt,
2586 LASSERT(dt->do_ops);
2587 LASSERT(dt->do_ops->do_declare_xattr_del);
2589 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2590 return cfs_fail_err;
2592 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2595 static inline int dt_xattr_del(const struct lu_env *env,
2596 struct dt_object *dt, const char *name,
2600 LASSERT(dt->do_ops);
2601 LASSERT(dt->do_ops->do_xattr_del);
2603 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2604 return cfs_fail_err;
2606 return dt->do_ops->do_xattr_del(env, dt, name, th);
2609 static inline int dt_declare_xattr_set(const struct lu_env *env,
2610 struct dt_object *dt,
2611 const struct lu_buf *buf,
2612 const char *name, int fl,
2616 LASSERT(dt->do_ops);
2617 LASSERT(dt->do_ops->do_declare_xattr_set);
2619 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2620 return cfs_fail_err;
2622 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2625 static inline int dt_xattr_set(const struct lu_env *env,
2626 struct dt_object *dt, const struct lu_buf *buf,
2627 const char *name, int fl, struct thandle *th)
2630 LASSERT(dt->do_ops);
2631 LASSERT(dt->do_ops->do_xattr_set);
2633 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2634 return cfs_fail_err;
2636 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2639 static inline int dt_declare_xattr_get(const struct lu_env *env,
2640 struct dt_object *dt,
2645 LASSERT(dt->do_ops);
2646 LASSERT(dt->do_ops->do_declare_xattr_get);
2648 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2649 return cfs_fail_err;
2651 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2654 static inline int dt_xattr_get(const struct lu_env *env,
2655 struct dt_object *dt, struct lu_buf *buf,
2659 LASSERT(dt->do_ops);
2660 LASSERT(dt->do_ops->do_xattr_get);
2662 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2663 return cfs_fail_err;
2665 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2668 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2669 const struct lu_buf *buf)
2672 LASSERT(dt->do_ops);
2673 LASSERT(dt->do_ops->do_xattr_list);
2675 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2676 return cfs_fail_err;
2678 return dt->do_ops->do_xattr_list(env, dt, buf);
2681 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2684 LASSERT(dt->do_ops);
2685 LASSERT(dt->do_ops->do_invalidate);
2687 return dt->do_ops->do_invalidate(env, dt);
2690 static inline int dt_declare_delete(const struct lu_env *env,
2691 struct dt_object *dt,
2692 const struct dt_key *key,
2696 LASSERT(dt->do_index_ops);
2697 LASSERT(dt->do_index_ops->dio_declare_delete);
2699 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2700 return cfs_fail_err;
2702 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2705 static inline int dt_delete(const struct lu_env *env,
2706 struct dt_object *dt,
2707 const struct dt_key *key,
2711 LASSERT(dt->do_index_ops);
2712 LASSERT(dt->do_index_ops->dio_delete);
2714 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2715 return cfs_fail_err;
2717 return dt->do_index_ops->dio_delete(env, dt, key, th);
2720 static inline int dt_commit_async(const struct lu_env *env,
2721 struct dt_device *dev)
2724 LASSERT(dev->dd_ops);
2725 LASSERT(dev->dd_ops->dt_commit_async);
2726 return dev->dd_ops->dt_commit_async(env, dev);
2729 static inline int dt_lookup(const struct lu_env *env,
2730 struct dt_object *dt,
2732 const struct dt_key *key)
2737 LASSERT(dt->do_index_ops);
2738 LASSERT(dt->do_index_ops->dio_lookup);
2740 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2741 return cfs_fail_err;
2743 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2751 static inline int dt_declare_layout_change(const struct lu_env *env,
2752 struct dt_object *o,
2753 struct md_layout_change *mlc,
2758 LASSERT(o->do_ops->do_declare_layout_change);
2759 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2762 static inline int dt_layout_change(const struct lu_env *env,
2763 struct dt_object *o,
2764 struct md_layout_change *mlc,
2769 LASSERT(o->do_ops->do_layout_change);
2770 return o->do_ops->do_layout_change(env, o, mlc, th);
2773 struct dt_find_hint {
2774 struct lu_fid *dfh_fid;
2775 struct dt_device *dfh_dt;
2776 struct dt_object *dfh_o;
2779 struct dt_insert_rec {
2781 const struct lu_fid *rec_fid;
2793 struct dt_thread_info {
2794 char dti_buf[DT_MAX_PATH];
2795 struct dt_find_hint dti_dfh;
2796 struct lu_attr dti_attr;
2797 struct lu_fid dti_fid;
2798 struct dt_object_format dti_dof;
2799 struct lustre_mdt_attrs dti_lma;
2800 struct lu_buf dti_lb;
2801 struct lu_object_conf dti_conf;
2803 struct dt_insert_rec dti_dt_rec;
2806 extern struct lu_context_key dt_key;
2808 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2810 struct dt_thread_info *dti;
2812 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2817 int dt_global_init(void);
2818 void dt_global_fini(void);
2820 # ifdef CONFIG_PROC_FS
2821 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2822 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2823 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2824 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2825 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2826 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2827 # endif /* CONFIG_PROC_FS */
2829 #endif /* __LUSTRE_DT_OBJECT_H */