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 ddp_extent_tax;
91 * Per-transaction commit callback function
93 struct dt_txn_commit_cb;
94 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
95 struct dt_txn_commit_cb *cb, int err);
97 * Special per-transaction callback for cases when just commit callback
98 * is needed and per-device callback are not convenient to use
100 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
101 #define MAX_COMMIT_CB_STR_LEN 32
103 #define DCB_TRANS_STOP 0x1
104 struct dt_txn_commit_cb {
105 struct list_head dcb_linkage;
110 char dcb_name[MAX_COMMIT_CB_STR_LEN];
114 * Operations on dt device.
116 struct dt_device_operations {
118 * Return device-wide statistics.
120 * Return device-wide stats including block size, total and
121 * free blocks, total and free objects, etc. See struct obd_statfs
124 * \param[in] env execution environment for this thread
125 * \param[in] dev dt device
126 * \param[out] osfs stats information
128 * \retval 0 on success
129 * \retval negative negated errno on error
131 int (*dt_statfs)(const struct lu_env *env,
132 struct dt_device *dev,
133 struct obd_statfs *osfs);
136 * Create transaction.
138 * Create in-memory structure representing the transaction for the
139 * caller. The structure returned will be used by the calling thread
140 * to specify the transaction the updates belong to. Once created
141 * successfully ->dt_trans_stop() must be called in any case (with
142 * ->dt_trans_start() and updates or not) so that the transaction
143 * handle and other resources can be released by the layers below.
145 * \param[in] env execution environment for this thread
146 * \param[in] dev dt device
148 * \retval pointer to handle if creation succeeds
149 * \retval ERR_PTR(errno) if creation fails
151 struct thandle *(*dt_trans_create)(const struct lu_env *env,
152 struct dt_device *dev);
157 * Start the transaction. The transaction described by \a th can be
158 * started only once. Another start is considered as an error.
159 * A thread is not supposed to start a transaction while another
160 * transaction isn't closed by the thread (though multiple handles
161 * can be created). The caller should start the transaction once
162 * all possible updates are declared (see the ->do_declare_* methods
163 * below) and all the needed resources are reserved.
165 * \param[in] env execution environment for this thread
166 * \param[in] dev dt device
167 * \param[in] th transaction handle
169 * \retval 0 on success
170 * \retval negative negated errno on error
172 int (*dt_trans_start)(const struct lu_env *env,
173 struct dt_device *dev,
179 * Once stopped the transaction described by \a th is complete (all
180 * the needed updates are applied) and further processing such as
181 * flushing to disk, sending to another target, etc, is handled by
182 * lower layers. The caller can't access this transaction by the
183 * handle anymore (except from the commit callbacks, see below).
185 * \param[in] env execution environment for this thread
186 * \param[in] dev dt device
187 * \param[in] th transaction handle
189 * \retval 0 on success
190 * \retval negative negated errno on error
192 int (*dt_trans_stop)(const struct lu_env *env,
193 struct dt_device *dev,
197 * Add commit callback to the transaction.
199 * Add a commit callback to the given transaction handle. The callback
200 * will be called when the associated transaction is stored. I.e. the
201 * transaction will survive an event like power off if the callback did
202 * run. The number of callbacks isn't limited, but you should note that
203 * some disk filesystems do handle the commit callbacks in the thread
204 * handling commit/flush of all the transactions, meaning that new
205 * transactions are blocked from commit and flush until all the
206 * callbacks are done. Also, note multiple callbacks can be running
207 * concurrently using multiple CPU cores. The callbacks will be running
208 * in a special environment which can not be used to pass data around.
210 * \param[in] th transaction handle
211 * \param[in] dcb commit callback description
213 * \retval 0 on success
214 * \retval negative negated errno on error
216 int (*dt_trans_cb_add)(struct thandle *th,
217 struct dt_txn_commit_cb *dcb);
220 * Return FID of root index object.
222 * Return the FID of the root object in the filesystem. This object
223 * is usually provided as a bootstrap point by a disk filesystem.
224 * This is up to the implementation which FID to use, though
225 * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
227 * \param[in] env execution environment for this thread
228 * \param[in] dev dt device
229 * \param[out] fid FID of the root object
231 * \retval 0 on success
232 * \retval negative negated errno on error
234 int (*dt_root_get)(const struct lu_env *env,
235 struct dt_device *dev,
239 * Return device configuration data.
241 * Return device (disk fs, actually) specific configuration.
242 * The configuration isn't subject to change at runtime.
243 * See struct dt_device_param for the details.
245 * \param[in] env execution environment for this thread
246 * \param[in] dev dt device
247 * \param[out] param configuration parameters
249 void (*dt_conf_get)(const struct lu_env *env,
250 const struct dt_device *dev,
251 struct dt_device_param *param);
256 * Sync all the cached state (dirty buffers, pages, etc) to the
257 * persistent storage. The method returns control once the sync is
258 * complete. This operation may incur significant I/O to disk and
259 * should be reserved for cases where a global sync is strictly
262 * \param[in] env execution environment for this thread
263 * \param[in] dev dt device
265 * \retval 0 on success
266 * \retval negative negated errno on error
268 int (*dt_sync)(const struct lu_env *env,
269 struct dt_device *dev);
272 * Make device read-only.
274 * Prevent new modifications to the device. This is a very specific
275 * state where all the changes are accepted successfully and the
276 * commit callbacks are called, but persistent state never changes.
277 * Used only in the tests to simulate power-off scenario.
279 * \param[in] env execution environment for this thread
280 * \param[in] dev dt device
282 * \retval 0 on success
283 * \retval negative negated errno on error
285 int (*dt_ro)(const struct lu_env *env,
286 struct dt_device *dev);
289 * Start transaction commit asynchronously.
292 * Provide a hint to the underlying filesystem that it should start
293 * committing soon. The control returns immediately. It's up to the
294 * layer implementing the method how soon to start committing. Usually
295 * this should be throttled to some extent, otherwise the number of
296 * aggregated transaction goes too high causing performance drop.
298 * \param[in] env execution environment for this thread
299 * \param[in] dev dt device
301 * \retval 0 on success
302 * \retval negative negated errno on error
304 int (*dt_commit_async)(const struct lu_env *env,
305 struct dt_device *dev);
308 struct dt_index_features {
309 /** required feature flags from enum dt_index_flags */
311 /** minimal required key size */
312 size_t dif_keysize_min;
313 /** maximal required key size, 0 if no limit */
314 size_t dif_keysize_max;
315 /** minimal required record size */
316 size_t dif_recsize_min;
317 /** maximal required record size, 0 if no limit */
318 size_t dif_recsize_max;
319 /** pointer size for record */
323 enum dt_index_flags {
324 /** index supports variable sized keys */
325 DT_IND_VARKEY = 1 << 0,
326 /** index supports variable sized records */
327 DT_IND_VARREC = 1 << 1,
328 /** index can be modified */
329 DT_IND_UPDATE = 1 << 2,
330 /** index supports records with non-unique (duplicate) keys */
331 DT_IND_NONUNQ = 1 << 3,
333 * index support fixed-size keys sorted with natural numerical way
334 * and is able to return left-side value if no exact value found
336 DT_IND_RANGE = 1 << 4,
340 * Features, required from index to support file system directories (mapping
343 extern const struct dt_index_features dt_directory_features;
344 extern const struct dt_index_features dt_otable_features;
345 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
346 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
347 extern const struct dt_index_features dt_lfsck_namespace_features;
349 /* index features supported by the accounting objects */
350 extern const struct dt_index_features dt_acct_features;
352 /* index features supported by the quota global indexes */
353 extern const struct dt_index_features dt_quota_glb_features;
355 /* index features supported by the quota slave indexes */
356 extern const struct dt_index_features dt_quota_slv_features;
358 /* index features supported by the nodemap index */
359 extern const struct dt_index_features dt_nodemap_features;
362 * This is a general purpose dt allocation hint.
363 * It now contains the parent object.
364 * It can contain any allocation hint in the future.
366 struct dt_allocation_hint {
367 struct dt_object *dah_parent;
368 const void *dah_eadata;
374 * object type specifier.
377 enum dt_format_type {
382 /** for special index */
384 /** for symbolic link */
389 * object format specifier.
391 struct dt_object_format {
392 /** type for dt object */
393 enum dt_format_type dof_type;
403 * special index need feature as parameter to create
407 const struct dt_index_features *di_feat;
412 enum dt_format_type dt_mode_to_dft(__u32 mode);
414 typedef __u64 dt_obj_version_t;
416 union ldlm_policy_data;
418 struct md_layout_change;
421 * A dt_object provides common operations to create and destroy
422 * objects and to manage regular and extended attributes.
424 struct dt_object_operations {
426 * Get read lock on object.
428 * Read lock is compatible with other read locks, so it's shared.
429 * Read lock is not compatible with write lock which is exclusive.
430 * The lock is blocking and can't be used from an interrupt context.
432 * \param[in] env execution environment for this thread
433 * \param[in] dt object to lock for reading
434 * \param[in] role a hint to debug locks (see kernel's mutexes)
436 void (*do_read_lock)(const struct lu_env *env,
437 struct dt_object *dt,
441 * Get write lock on object.
443 * Write lock is exclusive and cannot be shared. The lock is blocking
444 * and can't be used from an interrupt context.
446 * \param[in] env execution environment for this thread
447 * \param[in] dt object to lock for writing
448 * \param[in] role a hint to debug locks (see kernel's mutexes)
451 void (*do_write_lock)(const struct lu_env *env,
452 struct dt_object *dt,
458 * \param[in] env execution environment for this thread
459 * \param[in] dt object
461 void (*do_read_unlock)(const struct lu_env *env,
462 struct dt_object *dt);
465 * Release write lock.
467 * \param[in] env execution environment for this thread
468 * \param[in] dt object
470 void (*do_write_unlock)(const struct lu_env *env,
471 struct dt_object *dt);
474 * Check whether write lock is held.
476 * The caller can learn whether write lock is held on the object
478 * \param[in] env execution environment for this thread
479 * \param[in] dt object
481 * \retval 0 no write lock
482 * \retval 1 write lock is held
484 int (*do_write_locked)(const struct lu_env *env,
485 struct dt_object *dt);
488 * Declare intention to request reqular attributes.
490 * Notity the underlying filesystem that the caller may request regular
491 * attributes with ->do_attr_get() soon. This allows OSD to implement
492 * prefetching logic in an object-oriented manner. The implementation
493 * can be noop. This method should avoid expensive delays such as
494 * waiting on disk I/O, otherwise the goal of enabling a performance
495 * optimization would be defeated.
497 * \param[in] env execution environment for this thread
498 * \param[in] dt object
500 * \retval 0 on success
501 * \retval negative negated errno on error
503 int (*do_declare_attr_get)(const struct lu_env *env,
504 struct dt_object *dt);
507 * Return regular attributes.
509 * The object must exist. Currently all the attributes should be
510 * returned, but in the future this can be improved so that only
511 * a selected set is returned. This can improve performance as in
512 * some cases attributes are stored in different places and
513 * getting them all can be an iterative and expensive process.
515 * \param[in] env execution environment for this thread
516 * \param[in] dt object
517 * \param[out] attr attributes to fill
519 * \retval 0 on success
520 * \retval negative negated errno on error
522 int (*do_attr_get)(const struct lu_env *env,
523 struct dt_object *dt,
524 struct lu_attr *attr);
527 * Declare intention to change regular object's attributes.
529 * Notify the underlying filesystem that the regular attributes may
530 * change in this transaction. This enables the layer below to prepare
531 * resources (e.g. journal credits in ext4). This method should be
532 * called between creating the transaction and starting it. Note that
533 * the la_valid field of \a attr specifies which attributes will change.
534 * The object need not exist.
536 * \param[in] env execution environment for this thread
537 * \param[in] dt object
538 * \param[in] attr attributes to change specified in attr.la_valid
539 * \param[in] th transaction handle
541 * \retval 0 on success
542 * \retval negative negated errno on error
544 int (*do_declare_attr_set)(const struct lu_env *env,
545 struct dt_object *dt,
546 const struct lu_attr *attr,
550 * Change regular attributes.
552 * Change regular attributes in the given transaction. Note only
553 * attributes flagged by attr.la_valid change. The object must
554 * exist. If the layer implementing this method is responsible for
555 * quota, then the method should maintain object accounting for the
556 * given credentials when la_uid/la_gid changes.
558 * \param[in] env execution environment for this thread
559 * \param[in] dt object
560 * \param[in] attr new attributes to apply
561 * \param[in] th transaction handle
563 * \retval 0 on success
564 * \retval negative negated errno on error
566 int (*do_attr_set)(const struct lu_env *env,
567 struct dt_object *dt,
568 const struct lu_attr *attr,
572 * Declare intention to request extented attribute.
574 * Notify the underlying filesystem that the caller may request extended
575 * attribute with ->do_xattr_get() soon. This allows OSD to implement
576 * prefetching logic in an object-oriented manner. The implementation
577 * can be noop. This method should avoid expensive delays such as
578 * waiting on disk I/O, otherwise the goal of enabling a performance
579 * optimization would be defeated.
581 * \param[in] env execution environment for this thread
582 * \param[in] dt object
583 * \param[in] buf unused, may be removed in the future
584 * \param[in] name name of the extended attribute
586 * \retval 0 on success
587 * \retval negative negated errno on error
589 int (*do_declare_xattr_get)(const struct lu_env *env,
590 struct dt_object *dt,
595 * Return a value of an extended attribute.
597 * The object must exist. If the buffer is NULL, then the method
598 * must return the size of the value.
600 * \param[in] env execution environment for this thread
601 * \param[in] dt object
602 * \param[out] buf buffer in which to store the value
603 * \param[in] name name of the extended attribute
605 * \retval 0 on success
606 * \retval -ERANGE if \a buf is too small
607 * \retval negative negated errno on error
608 * \retval positive value's size if \a buf is NULL or has zero size
610 int (*do_xattr_get)(const struct lu_env *env,
611 struct dt_object *dt,
616 * Declare intention to change an extended attribute.
618 * Notify the underlying filesystem that the extended attribute may
619 * change in this transaction. This enables the layer below to prepare
620 * resources (e.g. journal credits in ext4). This method should be
621 * called between creating the transaction and starting it. The object
624 * \param[in] env execution environment for this thread
625 * \param[in] dt object
626 * \param[in] buf buffer storing new value of the attribute
627 * \param[in] name name of the attribute
628 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
629 * LU_XATTR_REPLACE - fail if EA doesn't exist
630 * \param[in] th transaction handle
632 * \retval 0 on success
633 * \retval negative negated errno on error
635 int (*do_declare_xattr_set)(const struct lu_env *env,
636 struct dt_object *dt,
637 const struct lu_buf *buf,
643 * Set an extended attribute.
645 * Change or replace the specified extended attribute (EA).
646 * The flags passed in \a fl dictate whether the EA is to be
647 * created or replaced, as follows.
648 * LU_XATTR_CREATE - fail if EA exists
649 * LU_XATTR_REPLACE - fail if EA doesn't exist
650 * The object must exist.
652 * \param[in] env execution environment for this thread
653 * \param[in] dt object
654 * \param[in] buf buffer storing new value of the attribute
655 * \param[in] name name of the attribute
656 * \param[in] fl flags indicating EA creation or replacement
657 * \param[in] th transaction handle
659 * \retval 0 on success
660 * \retval negative negated errno on error
662 int (*do_xattr_set)(const struct lu_env *env,
663 struct dt_object *dt,
664 const struct lu_buf *buf,
670 * Declare intention to delete an extended attribute.
672 * Notify the underlying filesystem that the extended attribute may
673 * be deleted in this transaction. This enables the layer below to
674 * prepare resources (e.g. journal credits in ext4). This method
675 * should be called between creating the transaction and starting it.
676 * The object need not exist.
678 * \param[in] env execution environment for this thread
679 * \param[in] dt object
680 * \param[in] name name of the attribute
681 * \param[in] th transaction handle
683 * \retval 0 on success
684 * \retval negative negated errno on error
686 int (*do_declare_xattr_del)(const struct lu_env *env,
687 struct dt_object *dt,
692 * Delete an extended attribute.
694 * This method deletes the specified extended attribute. The object
697 * \param[in] env execution environment for this thread
698 * \param[in] dt object
699 * \param[in] name name of the attribute
700 * \param[in] th transaction handle
702 * \retval 0 on success
703 * \retval negative negated errno on error
705 int (*do_xattr_del)(const struct lu_env *env,
706 struct dt_object *dt,
711 * Return a list of the extended attributes.
713 * Fills the passed buffer with a list of the extended attributes
714 * found in the object. The names are separated with '\0'.
715 * The object must exist.
717 * \param[in] env execution environment for this thread
718 * \param[in] dt object
719 * \param[out] buf buffer to put the list in
721 * \retval positive bytes used/required in the buffer
722 * \retval negative negated errno on error
724 int (*do_xattr_list)(const struct lu_env *env,
725 struct dt_object *dt,
726 const struct lu_buf *buf);
729 * Prepare allocation hint for a new object.
731 * This method is used by the caller to inform OSD of the parent-child
732 * relationship between two objects and enable efficient object
733 * allocation. Filled allocation hint will be passed to ->do_create()
736 * \param[in] env execution environment for this thread
737 * \param[out] ah allocation hint
738 * \param[in] parent parent object (can be NULL)
739 * \param[in] child child object
740 * \param[in] _mode type of the child object
742 void (*do_ah_init)(const struct lu_env *env,
743 struct dt_allocation_hint *ah,
744 struct dt_object *parent,
745 struct dt_object *child,
749 * Declare intention to create a new object.
751 * Notify the underlying filesystem that the object may be created
752 * in this transaction. This enables the layer below to prepare
753 * resources (e.g. journal credits in ext4). This method should be
754 * called between creating the transaction and starting it.
756 * If the layer implementing this method is responsible for quota,
757 * then the method should reserve an object for the given credentials
758 * and return an error if quota is over. If object creation later
759 * fails for some reason, then the reservation should be released
760 * properly (usually in ->dt_trans_stop()).
762 * \param[in] env execution environment for this thread
763 * \param[in] dt object
764 * \param[in] attr attributes of the new object
765 * \param[in] hint allocation hint
766 * \param[in] dof object format
767 * \param[in] th transaction handle
769 * \retval 0 on success
770 * \retval negative negated errno on error
772 int (*do_declare_create)(const struct lu_env *env,
773 struct dt_object *dt,
774 struct lu_attr *attr,
775 struct dt_allocation_hint *hint,
776 struct dt_object_format *dof,
782 * The method creates the object passed with the specified attributes
783 * and object format. Object allocation procedure can use information
784 * stored in the allocation hint. Different object formats are supported
785 * (see enum dt_format_type and struct dt_object_format) depending on
786 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
787 * in the LU-object header attributes.
789 * If the layer implementing this method is responsible for quota,
790 * then the method should maintain object accounting for the given
793 * \param[in] env execution environment for this thread
794 * \param[in] dt object
795 * \param[in] attr attributes of the new object
796 * \param[in] hint allocation hint
797 * \param[in] dof object format
798 * \param[in] th transaction handle
800 * \retval 0 on success
801 * \retval negative negated errno on error
803 int (*do_create)(const struct lu_env *env,
804 struct dt_object *dt,
805 struct lu_attr *attr,
806 struct dt_allocation_hint *hint,
807 struct dt_object_format *dof,
811 * Declare intention to destroy an object.
813 * Notify the underlying filesystem that the object may be destroyed
814 * in this transaction. This enables the layer below to prepare
815 * resources (e.g. journal credits in ext4). This method should be
816 * called between creating the transaction and starting it. The object
819 * \param[in] env execution environment for this thread
820 * \param[in] dt object
821 * \param[in] th transaction handle
823 * \retval 0 on success
824 * \retval negative negated errno on error
826 int (*do_declare_destroy)(const struct lu_env *env,
827 struct dt_object *dt,
833 * This method destroys the object and all the resources associated
834 * with the object (data, key/value pairs, extended attributes, etc).
835 * The object must exist. If destroy is successful, then flag
836 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
837 * instance of in-core object. Any subsequent access to the same FID
838 * should get another instance with no LOHA_EXIST flag set.
840 * If the layer implementing this method is responsible for quota,
841 * then the method should maintain object accounting for the given
844 * \param[in] env execution environment for this thread
845 * \param[in] dt object
846 * \param[in] th transaction handle
848 * \retval 0 on success
849 * \retval negative negated errno on error
851 int (*do_destroy)(const struct lu_env *env,
852 struct dt_object *dt,
856 * Try object as an index.
858 * Announce that this object is going to be used as an index. This
859 * operation checks that object supports indexing operations and
860 * installs appropriate dt_index_operations vector on success.
861 * Also probes for features. Operation is successful if all required
862 * features are supported. It's not possible to access the object
863 * with index methods before ->do_index_try() returns success.
865 * \param[in] env execution environment for this thread
866 * \param[in] dt object
867 * \param[in] feat index features
869 * \retval 0 on success
870 * \retval negative negated errno on error
872 int (*do_index_try)(const struct lu_env *env,
873 struct dt_object *dt,
874 const struct dt_index_features *feat);
877 * Declare intention to increment nlink count.
879 * Notify the underlying filesystem that the nlink regular attribute
880 * be changed in this transaction. This enables the layer below to
881 * prepare resources (e.g. journal credits in ext4). This method
882 * should be called between creating the transaction and starting it.
883 * The object need not exist.
885 * \param[in] env execution environment for this thread
886 * \param[in] dt object
887 * \param[in] th transaction handle
889 * \retval 0 on success
890 * \retval negative negated errno on error
892 int (*do_declare_ref_add)(const struct lu_env *env,
893 struct dt_object *dt,
899 * Increment nlink (from the regular attributes set) in the given
900 * transaction. Note the absolute limit for nlink should be learnt
901 * from struct dt_device_param::ddp_max_nlink. The object must exist.
903 * \param[in] env execution environment for this thread
904 * \param[in] dt object
905 * \param[in] th transaction handle
907 * \retval 0 on success
908 * \retval negative negated errno on error
910 int (*do_ref_add)(const struct lu_env *env,
911 struct dt_object *dt, struct thandle *th);
914 * Declare intention to decrement nlink count.
916 * Notify the underlying filesystem that the nlink regular attribute
917 * be changed in this transaction. This enables the layer below to
918 * prepare resources (e.g. journal credits in ext4). This method
919 * should be called between creating the transaction and starting it.
920 * The object need not exist.
922 * \param[in] env execution environment for this thread
923 * \param[in] dt object
924 * \param[in] th transaction handle
926 * \retval 0 on success
927 * \retval negative negated errno on error
929 int (*do_declare_ref_del)(const struct lu_env *env,
930 struct dt_object *dt,
936 * Decrement nlink (from the regular attributes set) in the given
937 * transaction. The object must exist.
939 * \param[in] env execution environment for this thread
940 * \param[in] dt object
941 * \param[in] th transaction handle
943 * \retval 0 on success
944 * \retval negative negated errno on error
946 int (*do_ref_del)(const struct lu_env *env,
947 struct dt_object *dt,
953 * The method is called to sync specified range of the object to a
954 * persistent storage. The control is returned once the operation is
955 * complete. The difference from ->do_sync() is that the object can
956 * be in-sync with the persistent storage (nothing to flush), then
957 * the method returns quickly with no I/O overhead. So, this method
958 * should be preferred over ->do_sync() where possible. Also note that
959 * if the object isn't clean, then some disk filesystems will call
960 * ->do_sync() to maintain overall consistency, in which case it's
961 * still very expensive.
963 * \param[in] env execution environment for this thread
964 * \param[in] dt object
965 * \param[in] start start of the range to sync
966 * \param[in] end end of the range to sync
968 * \retval 0 on success
969 * \retval negative negated errno on error
971 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
972 __u64 start, __u64 end);
977 * Lock object(s) using Distributed Lock Manager (LDLM).
979 * Get LDLM locks for the object. Currently used to lock "remote"
980 * objects in DNE configuration - a service running on MDTx needs
981 * to lock an object on MDTy.
983 * \param[in] env execution environment for this thread
984 * \param[in] dt object
985 * \param[out] lh lock handle, sometimes used, sometimes not
986 * \param[in] einfo ldlm callbacks, locking type and mode
987 * \param[out] einfo private data to be passed to unlock later
988 * \param[in] policy inodebits data
990 * \retval 0 on success
991 * \retval negative negated errno on error
993 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
994 struct lustre_handle *lh,
995 struct ldlm_enqueue_info *einfo,
996 union ldlm_policy_data *policy);
1001 * Release LDLM lock(s) granted with ->do_object_lock().
1003 * \param[in] env execution environment for this thread
1004 * \param[in] dt object
1005 * \param[in] einfo lock handles, from ->do_object_lock()
1006 * \param[in] policy inodebits data
1008 * \retval 0 on success
1009 * \retval negative negated errno on error
1011 int (*do_object_unlock)(const struct lu_env *env,
1012 struct dt_object *dt,
1013 struct ldlm_enqueue_info *einfo,
1014 union ldlm_policy_data *policy);
1017 * Invalidate attribute cache.
1019 * This method invalidate attribute cache of the object, which is on OSP
1022 * \param[in] env execution envionment for this thread
1023 * \param[in] dt object
1025 * \retval 0 on success
1026 * \retval negative negated errno on error
1028 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1031 * Declare intention to instaintiate extended layout component.
1033 * \param[in] env execution environment
1034 * \param[in] dt DT object
1035 * \param[in] layout data structure to describe the changes to
1036 * the DT object's layout
1037 * \param[in] buf buffer containing client's lovea or empty
1040 * \retval -ne error code
1042 int (*do_declare_layout_change)(const struct lu_env *env,
1043 struct dt_object *dt,
1044 struct md_layout_change *mlc,
1045 struct thandle *th);
1048 * Client is trying to write to un-instantiated layout component.
1050 * \param[in] env execution environment
1051 * \param[in] dt DT object
1052 * \param[in] layout data structure to describe the changes to
1053 * the DT object's layout
1054 * \param[in] buf buffer containing client's lovea or empty
1057 * \retval -ne error code
1059 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1060 struct md_layout_change *mlc,
1061 struct thandle *th);
1065 DT_BUFS_TYPE_READ = 0x0000,
1066 DT_BUFS_TYPE_WRITE = 0x0001,
1067 DT_BUFS_TYPE_READAHEAD = 0x0002,
1068 DT_BUFS_TYPE_LOCAL = 0x0004,
1072 * Per-dt-object operations on "file body" - unstructure raw data.
1074 struct dt_body_operations {
1078 * Read unstructured data from an existing regular object.
1079 * Only data before attr.la_size is returned.
1081 * \param[in] env execution environment for this thread
1082 * \param[in] dt object
1083 * \param[out] buf buffer (including size) to copy data in
1084 * \param[in] pos position in the object to start
1085 * \param[out] pos original value of \a pos + bytes returned
1087 * \retval positive bytes read on success
1088 * \retval negative negated errno on error
1090 ssize_t (*dbo_read)(const struct lu_env *env,
1091 struct dt_object *dt,
1096 * Declare intention to write data to object.
1098 * Notify the underlying filesystem that data may be written in
1099 * this transaction. This enables the layer below to prepare resources
1100 * (e.g. journal credits in ext4). This method should be called
1101 * between creating the transaction and starting it. The object need
1102 * not exist. If the layer implementing this method is responsible for
1103 * quota, then the method should reserve space for the given credentials
1104 * and return an error if quota is over. If the write later fails
1105 * for some reason, then the reserve should be released properly
1106 * (usually in ->dt_trans_stop()).
1108 * \param[in] env execution environment for this thread
1109 * \param[in] dt object
1110 * \param[in] buf buffer (including size) to copy data from
1111 * \param[in] pos position in the object to start
1112 * \param[in] th transaction handle
1114 * \retval 0 on success
1115 * \retval negative negated errno on error
1117 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1118 struct dt_object *dt,
1119 const struct lu_buf *buf,
1121 struct thandle *th);
1124 * Write unstructured data to regular existing object.
1126 * The method allocates space and puts data in. Also, the method should
1127 * maintain attr.la_size properly. Partial writes are possible.
1129 * If the layer implementing this method is responsible for quota,
1130 * then the method should maintain space accounting for the given
1133 * \param[in] env execution environment for this thread
1134 * \param[in] dt object
1135 * \param[in] buf buffer (including size) to copy data from
1136 * \param[in] pos position in the object to start
1137 * \param[out] pos \a pos + bytes written
1138 * \param[in] th transaction handle
1139 * \param[in] ignore unused (was used to request quota ignorance)
1141 * \retval positive bytes written on success
1142 * \retval negative negated errno on error
1144 ssize_t (*dbo_write)(const struct lu_env *env,
1145 struct dt_object *dt,
1146 const struct lu_buf *buf,
1152 * Return buffers for data.
1154 * This method is used to access data with no copying. It's so-called
1155 * zero-copy I/O. The method returns the descriptors for the internal
1156 * buffers where data are managed by the disk filesystem. For example,
1157 * pagecache in case of ext4 or ARC with ZFS. Then other components
1158 * (e.g. networking) can transfer data from or to the buffers with no
1159 * additional copying.
1161 * The method should fill an array of struct niobuf_local, where
1162 * each element describes a full or partial page for data at specific
1163 * offset. The caller should use page/lnb_page_offset/len to find data
1164 * at object's offset lnb_file_offset.
1166 * The memory referenced by the descriptors can't change its purpose
1167 * until the complementary ->dbo_bufs_put() is called. The caller should
1168 * specify if the buffers are used to read or modify data so that OSD
1169 * can decide how to initialize the buffers: bring all the data for
1170 * reads or just bring partial buffers for write. Note: the method does
1171 * not check whether output array is large enough.
1173 * \param[in] env execution environment for this thread
1174 * \param[in] dt object
1175 * \param[in] pos position in the object to start
1176 * \param[in] len size of region in bytes
1177 * \param[out] lb array of descriptors to fill
1178 * \param[in] rw 0 if used to read, 1 if used for write
1180 * \retval positive number of descriptors on success
1181 * \retval negative negated errno on error
1183 int (*dbo_bufs_get)(const struct lu_env *env,
1184 struct dt_object *dt,
1187 struct niobuf_local *lb,
1188 enum dt_bufs_type rw);
1191 * Release reference granted by ->dbo_bufs_get().
1193 * Release the reference granted by the previous ->dbo_bufs_get().
1194 * Note the references are counted.
1196 * \param[in] env execution environment for this thread
1197 * \param[in] dt object
1198 * \param[out] lb array of descriptors to fill
1199 * \param[in] nr size of the array
1201 * \retval 0 on success
1202 * \retval negative negated errno on error
1204 int (*dbo_bufs_put)(const struct lu_env *env,
1205 struct dt_object *dt,
1206 struct niobuf_local *lb,
1210 * Prepare buffers for reading.
1212 * The method is called on the given buffers to fill them with data
1213 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1214 * caller should be able to get few buffers for discontiguous regions
1215 * using few calls to ->dbo_bufs_get() and then request them all for
1216 * the preparation with a single call, so that OSD can fire many I/Os
1217 * to run concurrently. It's up to the specific OSD whether to implement
1218 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1219 * prepare data for every requested region individually.
1221 * \param[in] env execution environment for this thread
1222 * \param[in] dt object
1223 * \param[in] lnb array of buffer descriptors
1224 * \param[in] nr size of the array
1226 * \retval 0 on success
1227 * \retval negative negated errno on error
1229 int (*dbo_read_prep)(const struct lu_env *env,
1230 struct dt_object *dt,
1231 struct niobuf_local *lnb,
1235 * Prepare buffers for write.
1237 * This method is called on the given buffers to ensure the partial
1238 * buffers contain correct data. The underlying idea is the same as
1239 * in ->db_read_prep().
1241 * \param[in] env execution environment for this thread
1242 * \param[in] dt object
1243 * \param[in] lb array of buffer descriptors
1244 * \param[in] nr size of the array
1246 * \retval 0 on success
1247 * \retval negative negated errno on error
1249 int (*dbo_write_prep)(const struct lu_env *env,
1250 struct dt_object *dt,
1251 struct niobuf_local *lb,
1255 * Declare intention to write data stored in the buffers.
1257 * Notify the underlying filesystem that data may be written in
1258 * this transaction. This enables the layer below to prepare resources
1259 * (e.g. journal credits in ext4). This method should be called
1260 * between creating the transaction and starting it.
1262 * If the layer implementing this method is responsible for quota,
1263 * then the method should be reserving a space for the given
1264 * credentials and return an error if quota is exceeded. If the write
1265 * later fails for some reason, then the reserve should be released
1266 * properly (usually in ->dt_trans_stop()).
1268 * \param[in] env execution environment for this thread
1269 * \param[in] dt object
1270 * \param[in] lb array of descriptors
1271 * \param[in] nr size of the array
1272 * \param[in] th transaction handle
1274 * \retval 0 on success
1275 * \retval negative negated errno on error
1277 int (*dbo_declare_write_commit)(const struct lu_env *env,
1278 struct dt_object *dt,
1279 struct niobuf_local *lb,
1281 struct thandle *th);
1284 * Write to existing object.
1286 * This method is used to write data to a persistent storage using
1287 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1288 * data into the buffers using own mechanisms (e.g. direct transfer
1289 * from a NIC). The method should maintain attr.la_size. Also,
1290 * attr.la_blocks should be maintained but this can be done in lazy
1291 * manner, when actual allocation happens.
1293 * If the layer implementing this method is responsible for quota,
1294 * then the method should maintain space accounting for the given
1297 * \param[in] env execution environment for this thread
1298 * \param[in] dt object
1299 * \param[in] lb array of descriptors for the buffers
1300 * \param[in] nr size of the array
1301 * \param[in] th transaction handle
1303 * \retval 0 on success
1304 * \retval negative negated errno on error
1306 int (*dbo_write_commit)(const struct lu_env *env,
1307 struct dt_object *dt,
1308 struct niobuf_local *lb,
1310 struct thandle *th);
1313 * Return logical to physical block mapping for a given extent
1315 * \param[in] env execution environment for this thread
1316 * \param[in] dt object
1317 * \param[in] fm describe the region to map and the output buffer
1318 * see the details in include/linux/fiemap.h
1320 * \retval 0 on success
1321 * \retval negative negated errno on error
1323 int (*dbo_fiemap_get)(const struct lu_env *env,
1324 struct dt_object *dt,
1328 * Declare intention to deallocate space from an object.
1330 * Notify the underlying filesystem that space may be deallocated in
1331 * this transactions. This enables the layer below to prepare resources
1332 * (e.g. journal credits in ext4). This method should be called between
1333 * creating the transaction and starting it. The object need not exist.
1335 * \param[in] env execution environment for this thread
1336 * \param[in] dt object
1337 * \param[in] start the start of the region to deallocate
1338 * \param[in] end the end of the region to deallocate
1339 * \param[in] th transaction handle
1341 * \retval 0 on success
1342 * \retval negative negated errno on error
1344 int (*dbo_declare_punch)(const struct lu_env *env,
1345 struct dt_object *dt,
1348 struct thandle *th);
1351 * Deallocate specified region in an object.
1353 * This method is used to deallocate (release) space possibly consumed
1354 * by the given region of the object. If the layer implementing this
1355 * method is responsible for quota, then the method should maintain
1356 * space accounting for the given credentials.
1358 * \param[in] env execution environment for this thread
1359 * \param[in] dt object
1360 * \param[in] start the start of the region to deallocate
1361 * \param[in] end the end of the region to deallocate
1362 * \param[in] th transaction handle
1364 * \retval 0 on success
1365 * \retval negative negated errno on error
1367 int (*dbo_punch)(const struct lu_env *env,
1368 struct dt_object *dt,
1371 struct thandle *th);
1373 * Give advices on specified region in an object.
1375 * This method is used to give advices about access pattern on an
1376 * given region of the object. The disk filesystem understands
1377 * the advices and tunes cache/read-ahead policies.
1379 * \param[in] env execution environment for this thread
1380 * \param[in] dt object
1381 * \param[in] start the start of the region affected
1382 * \param[in] end the end of the region affected
1383 * \param[in] advice advice type
1385 * \retval 0 on success
1386 * \retval negative negated errno on error
1388 int (*dbo_ladvise)(const struct lu_env *env,
1389 struct dt_object *dt,
1392 enum lu_ladvise_type advice);
1396 * Incomplete type of index record.
1401 * Incomplete type of index key.
1406 * Incomplete type of dt iterator.
1411 * Per-dt-object operations on object as index. Index is a set of key/value
1412 * pairs abstracted from an on-disk representation. An index supports the
1413 * number of operations including lookup by key, insert and delete. Also,
1414 * an index can be iterated to find the pairs one by one, from a beginning
1415 * or specified point.
1417 struct dt_index_operations {
1419 * Lookup in an index by key.
1421 * The method returns a value for the given key. Key/value format
1422 * and size should have been negotiated with ->do_index_try() before.
1423 * Thus it's the caller's responsibility to provide the method with
1424 * proper key and big enough buffer. No external locking is required,
1425 * all the internal consistency should be implemented by the method
1426 * or lower layers. The object should should have been created with
1427 * type DFT_INDEX or DFT_DIR.
1429 * \param[in] env execution environment for this thread
1430 * \param[in] dt object
1431 * \param[out] rec buffer where value will be stored
1432 * \param[in] key key
1434 * \retval 0 on success
1435 * \retval -ENOENT if key isn't found
1436 * \retval negative negated errno on error
1438 int (*dio_lookup)(const struct lu_env *env,
1439 struct dt_object *dt,
1441 const struct dt_key *key);
1444 * Declare intention to insert a key/value into an index.
1446 * Notify the underlying filesystem that new key/value may be inserted
1447 * in this transaction. This enables the layer below to prepare
1448 * resources (e.g. journal credits in ext4). This method should be
1449 * called between creating the transaction and starting it. key/value
1450 * format and size is subject to ->do_index_try().
1452 * \param[in] env execution environment for this thread
1453 * \param[in] dt object
1454 * \param[in] rec buffer storing value
1455 * \param[in] key key
1456 * \param[in] th transaction handle
1458 * \retval 0 on success
1459 * \retval negative negated errno on error
1461 int (*dio_declare_insert)(const struct lu_env *env,
1462 struct dt_object *dt,
1463 const struct dt_rec *rec,
1464 const struct dt_key *key,
1465 struct thandle *th);
1468 * Insert a new key/value pair into an index.
1470 * The method inserts specified key/value pair into the given index
1471 * object. The internal consistency is maintained by the method or
1472 * the functionality below. The format and size of key/value should
1473 * have been negotiated before using ->do_index_try(), no additional
1474 * information can be specified to the method. The keys are unique
1477 * \param[in] env execution environment for this thread
1478 * \param[in] dt object
1479 * \param[in] rec buffer storing value
1480 * \param[in] key key
1481 * \param[in] th transaction handle
1482 * \param[in] ignore unused (was used to request quota ignorance)
1484 * \retval 0 on success
1485 * \retval negative negated errno on error
1487 int (*dio_insert)(const struct lu_env *env,
1488 struct dt_object *dt,
1489 const struct dt_rec *rec,
1490 const struct dt_key *key,
1495 * Declare intention to delete a key/value from an index.
1497 * Notify the underlying filesystem that key/value may be deleted in
1498 * this transaction. This enables the layer below to prepare resources
1499 * (e.g. journal credits in ext4). This method should be called
1500 * between creating the transaction and starting it. Key/value format
1501 * and size is subject to ->do_index_try(). The object need not exist.
1503 * \param[in] env execution environment for this thread
1504 * \param[in] dt object
1505 * \param[in] key key
1506 * \param[in] th transaction handle
1508 * \retval 0 on success
1509 * \retval negative negated errno on error
1511 int (*dio_declare_delete)(const struct lu_env *env,
1512 struct dt_object *dt,
1513 const struct dt_key *key,
1514 struct thandle *th);
1517 * Delete key/value pair from an index.
1519 * The method deletes specified key and corresponding value from the
1520 * given index object. The internal consistency is maintained by the
1521 * method or the functionality below. The format and size of the key
1522 * should have been negotiated before using ->do_index_try(), no
1523 * additional information can be specified to the method.
1525 * \param[in] env execution environment for this thread
1526 * \param[in] dt object
1527 * \param[in] key key
1528 * \param[in] th transaction handle
1530 * \retval 0 on success
1531 * \retval negative negated errno on error
1533 int (*dio_delete)(const struct lu_env *env,
1534 struct dt_object *dt,
1535 const struct dt_key *key,
1536 struct thandle *th);
1539 * Iterator interface.
1541 * Methods to iterate over an existing index, list the keys stored and
1542 * associated values, get key/value size, etc.
1546 * Allocate and initialize new iterator.
1548 * The iterator is a handler to be used in the subsequent
1549 * methods to access index's content. Note the position is
1550 * not defined at this point and should be initialized with
1551 * ->get() or ->load() method.
1553 * \param[in] env execution environment for this thread
1554 * \param[in] dt object
1555 * \param[in] attr ask the iterator to return part of
1556 the records, see LUDA_* for details
1558 * \retval pointer iterator pointer on success
1559 * \retval ERR_PTR(errno) on error
1561 struct dt_it *(*init)(const struct lu_env *env,
1562 struct dt_object *dt,
1568 * Release the specified iterator and all the resources
1569 * associated (e.g. the object, index cache, etc).
1571 * \param[in] env execution environment for this thread
1572 * \param[in] di iterator to release
1574 void (*fini)(const struct lu_env *env,
1578 * Move position of iterator.
1580 * Move the position of the specified iterator to the specified
1583 * \param[in] env execution environment for this thread
1584 * \param[in] di iterator
1585 * \param[in] key key to position to
1587 * \retval 0 if exact key is found
1588 * \retval 1 if at the record with least key
1589 * not larger than the key
1590 * \retval negative negated errno on error
1592 int (*get)(const struct lu_env *env,
1594 const struct dt_key *key);
1599 * Complimentary method for dt_it_ops::get() above. Some
1600 * implementation can increase a reference on the iterator in
1601 * dt_it_ops::get(). So the caller should be able to release
1602 * with dt_it_ops::put().
1604 * \param[in] env execution environment for this thread
1605 * \param[in] di iterator
1607 void (*put)(const struct lu_env *env,
1611 * Move to next record.
1613 * Moves the position of the iterator to a next record
1615 * \param[in] env execution environment for this thread
1616 * \param[in] di iterator
1618 * \retval 1 if no more records
1619 * \retval 0 on success, the next record is found
1620 * \retval negative negated errno on error
1622 int (*next)(const struct lu_env *env,
1628 * Returns a pointer to a buffer containing the key of the
1629 * record at the current position. The pointer is valid and
1630 * retains data until ->get(), ->load() and ->fini() methods
1633 * \param[in] env execution environment for this thread
1634 * \param[in] di iterator
1636 * \retval pointer to key on success
1637 * \retval ERR_PTR(errno) on error
1639 struct dt_key *(*key)(const struct lu_env *env,
1640 const struct dt_it *di);
1645 * Returns size of the key at the current position.
1647 * \param[in] env execution environment for this thread
1648 * \param[in] di iterator
1650 * \retval key's size on success
1651 * \retval negative negated errno on error
1653 int (*key_size)(const struct lu_env *env,
1654 const struct dt_it *di);
1659 * Stores the value of the record at the current position. The
1660 * buffer must be big enough (as negotiated with
1661 * ->do_index_try() or ->rec_size()). The caller can specify
1662 * she is interested only in part of the record, using attr
1663 * argument (see LUDA_* definitions for the details).
1665 * \param[in] env execution environment for this thread
1666 * \param[in] di iterator
1667 * \param[out] rec buffer to store value in
1668 * \param[in] attr specify part of the value to copy
1670 * \retval 0 on success
1671 * \retval negative negated errno on error
1673 int (*rec)(const struct lu_env *env,
1674 const struct dt_it *di,
1679 * Return record size.
1681 * Returns size of the record at the current position. The
1682 * \a attr can be used to specify only the parts of the record
1683 * needed to be returned. (see LUDA_* definitions for the
1686 * \param[in] env execution environment for this thread
1687 * \param[in] di iterator
1688 * \param[in] attr part of the record to return
1690 * \retval record's size on success
1691 * \retval negative negated errno on error
1693 int (*rec_size)(const struct lu_env *env,
1694 const struct dt_it *di,
1698 * Return a cookie (hash).
1700 * Returns the cookie (usually hash) of the key at the current
1701 * position. This allows the caller to resume iteration at this
1702 * position later. The exact value is specific to implementation
1703 * and should not be interpreted by the caller.
1705 * \param[in] env execution environment for this thread
1706 * \param[in] di iterator
1708 * \retval cookie/hash of the key
1710 __u64 (*store)(const struct lu_env *env,
1711 const struct dt_it *di);
1714 * Initialize position using cookie/hash.
1716 * Initializes the current position of the iterator to one
1717 * described by the cookie/hash as returned by ->store()
1720 * \param[in] env execution environment for this thread
1721 * \param[in] di iterator
1722 * \param[in] hash cookie/hash value
1724 * \retval positive if current position points to
1725 * record with least cookie not larger
1727 * \retval 0 if current position matches cookie
1728 * \retval negative negated errno on error
1730 int (*load)(const struct lu_env *env,
1731 const struct dt_it *di,
1737 int (*key_rec)(const struct lu_env *env,
1738 const struct dt_it *di,
1743 enum dt_otable_it_valid {
1744 DOIV_ERROR_HANDLE = 0x0001,
1745 DOIV_DRYRUN = 0x0002,
1748 enum dt_otable_it_flags {
1749 /* Exit when fail. */
1750 DOIF_FAILOUT = 0x0001,
1752 /* Reset iteration position to the device beginning. */
1753 DOIF_RESET = 0x0002,
1755 /* There is up layer component uses the iteration. */
1756 DOIF_OUTUSED = 0x0004,
1758 /* Check only without repairing. */
1759 DOIF_DRYRUN = 0x0008,
1762 /* otable based iteration needs to use the common DT iteration APIs.
1763 * To initialize the iteration, it needs call dio_it::init() firstly.
1764 * Here is how the otable based iteration should prepare arguments to
1765 * call dt_it_ops::init().
1767 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1768 * is composed of two parts:
1769 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1770 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1771 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1774 struct lu_device dd_lu_dev;
1775 const struct dt_device_operations *dd_ops;
1778 * List of dt_txn_callback (see below). This is not protected in any
1779 * way, because callbacks are supposed to be added/deleted only during
1780 * single-threaded start-up shut-down procedures.
1782 struct list_head dd_txn_callbacks;
1783 unsigned int dd_record_fid_accessed:1,
1787 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1788 void dt_device_fini(struct dt_device *dev);
1790 static inline int lu_device_is_dt(const struct lu_device *d)
1792 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1795 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1797 LASSERT(lu_device_is_dt(l));
1798 return container_of0(l, struct dt_device, dd_lu_dev);
1802 struct lu_object do_lu;
1803 const struct dt_object_operations *do_ops;
1804 const struct dt_body_operations *do_body_ops;
1805 const struct dt_index_operations *do_index_ops;
1809 * In-core representation of per-device local object OID storage
1811 struct local_oid_storage {
1812 /* all initialized llog systems on this node linked by this */
1813 struct list_head los_list;
1815 /* how many handle's reference this los has */
1816 atomic_t los_refcount;
1817 struct dt_device *los_dev;
1818 struct dt_object *los_obj;
1820 /* data used to generate new fids */
1821 struct mutex los_id_lock;
1826 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1828 return &d->dd_lu_dev;
1831 static inline struct dt_object *lu2dt(struct lu_object *l)
1833 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1834 return container_of0(l, struct dt_object, do_lu);
1837 int dt_object_init(struct dt_object *obj,
1838 struct lu_object_header *h, struct lu_device *d);
1840 void dt_object_fini(struct dt_object *obj);
1842 static inline int dt_object_exists(const struct dt_object *dt)
1844 return lu_object_exists(&dt->do_lu);
1847 static inline int dt_object_remote(const struct dt_object *dt)
1849 return lu_object_remote(&dt->do_lu);
1852 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1854 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1855 return container_of0(o, struct dt_object, do_lu);
1858 static inline struct dt_object *dt_object_child(struct dt_object *o)
1860 return container_of0(lu_object_next(&(o)->do_lu),
1861 struct dt_object, do_lu);
1865 * This is the general purpose transaction handle.
1866 * 1. Transaction Life Cycle
1867 * This transaction handle is allocated upon starting a new transaction,
1868 * and deallocated after this transaction is committed.
1869 * 2. Transaction Nesting
1870 * We do _NOT_ support nested transaction. So, every thread should only
1871 * have one active transaction, and a transaction only belongs to one
1872 * thread. Due to this, transaction handle need no reference count.
1873 * 3. Transaction & dt_object locking
1874 * dt_object locks should be taken inside transaction.
1875 * 4. Transaction & RPC
1876 * No RPC request should be issued inside transaction.
1879 /** the dt device on which the transactions are executed */
1880 struct dt_device *th_dev;
1882 /* point to the top thandle, XXX this is a bit hacky right now,
1883 * but normal device trans callback triggered by the bottom
1884 * device (OSP/OSD == sub thandle layer) needs to get the
1885 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1886 * top thandle here for now, will fix it when we have better
1887 * callback mechanism */
1888 struct thandle *th_top;
1890 /** the last operation result in this transaction.
1891 * this value is used in recovery */
1894 /** whether we need sync commit */
1895 unsigned int th_sync:1,
1896 /* local transation, no need to inform other layers */
1898 /* Whether we need wait the transaction to be submitted
1899 * (send to remote target) */
1901 /* complex transaction which will track updates on all targets,
1907 * Transaction call-backs.
1909 * These are invoked by osd (or underlying transaction engine) when
1910 * transaction changes state.
1912 * Call-backs are used by upper layers to modify transaction parameters and to
1913 * perform some actions on for each transaction state transition. Typical
1914 * example is mdt registering call-back to write into last-received file
1915 * before each transaction commit.
1917 struct dt_txn_callback {
1918 int (*dtc_txn_start)(const struct lu_env *env,
1919 struct thandle *txn, void *cookie);
1920 int (*dtc_txn_stop)(const struct lu_env *env,
1921 struct thandle *txn, void *cookie);
1922 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1925 struct list_head dtc_linkage;
1928 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1929 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1931 int dt_txn_hook_start(const struct lu_env *env,
1932 struct dt_device *dev, struct thandle *txn);
1933 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1934 void dt_txn_hook_commit(struct thandle *txn);
1936 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1939 * Callback function used for parsing path.
1940 * \see llo_store_resolve
1942 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1946 #define DT_MAX_PATH 1024
1948 int dt_path_parser(const struct lu_env *env,
1949 char *local, dt_entry_func_t entry_func,
1953 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1954 const char *path, struct lu_fid *fid);
1956 struct dt_object *dt_store_open(const struct lu_env *env,
1957 struct dt_device *dt,
1958 const char *dirname,
1959 const char *filename,
1960 struct lu_fid *fid);
1962 struct dt_object *dt_find_or_create(const struct lu_env *env,
1963 struct dt_device *dt,
1964 const struct lu_fid *fid,
1965 struct dt_object_format *dof,
1966 struct lu_attr *attr);
1968 struct dt_object *dt_locate_at(const struct lu_env *env,
1969 struct dt_device *dev,
1970 const struct lu_fid *fid,
1971 struct lu_device *top_dev,
1972 const struct lu_object_conf *conf);
1974 static inline struct dt_object *
1975 dt_locate(const struct lu_env *env, struct dt_device *dev,
1976 const struct lu_fid *fid)
1978 return dt_locate_at(env, dev, fid,
1979 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1982 static inline struct dt_object *
1983 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1985 struct lu_object *lo;
1987 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
1988 if (lo->lo_dev == &dt_dev->dd_lu_dev)
1989 return container_of(lo, struct dt_object, do_lu);
1994 static inline void dt_object_put(const struct lu_env *env,
1995 struct dt_object *dto)
1997 lu_object_put(env, &dto->do_lu);
2000 static inline void dt_object_put_nocache(const struct lu_env *env,
2001 struct dt_object *dto)
2003 lu_object_put_nocache(env, &dto->do_lu);
2006 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2007 const struct lu_fid *first_fid,
2008 struct local_oid_storage **los);
2009 void local_oid_storage_fini(const struct lu_env *env,
2010 struct local_oid_storage *los);
2011 int local_object_fid_generate(const struct lu_env *env,
2012 struct local_oid_storage *los,
2013 struct lu_fid *fid);
2014 int local_object_declare_create(const struct lu_env *env,
2015 struct local_oid_storage *los,
2016 struct dt_object *o,
2017 struct lu_attr *attr,
2018 struct dt_object_format *dof,
2019 struct thandle *th);
2020 int local_object_create(const struct lu_env *env,
2021 struct local_oid_storage *los,
2022 struct dt_object *o,
2023 struct lu_attr *attr, struct dt_object_format *dof,
2024 struct thandle *th);
2025 struct dt_object *local_file_find(const struct lu_env *env,
2026 struct local_oid_storage *los,
2027 struct dt_object *parent,
2029 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2030 struct local_oid_storage *los,
2031 struct dt_object *parent,
2032 const char *name, __u32 mode);
2033 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2034 struct dt_device *dt,
2035 const struct lu_fid *fid,
2036 struct dt_object *parent,
2040 local_index_find_or_create(const struct lu_env *env,
2041 struct local_oid_storage *los,
2042 struct dt_object *parent,
2043 const char *name, __u32 mode,
2044 const struct dt_index_features *ft);
2046 local_index_find_or_create_with_fid(const struct lu_env *env,
2047 struct dt_device *dt,
2048 const struct lu_fid *fid,
2049 struct dt_object *parent,
2050 const char *name, __u32 mode,
2051 const struct dt_index_features *ft);
2052 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2053 struct dt_object *parent, const char *name);
2055 static inline int dt_object_lock(const struct lu_env *env,
2056 struct dt_object *o, struct lustre_handle *lh,
2057 struct ldlm_enqueue_info *einfo,
2058 union ldlm_policy_data *policy)
2061 LASSERT(o->do_ops != NULL);
2062 LASSERT(o->do_ops->do_object_lock != NULL);
2063 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2066 static inline int dt_object_unlock(const struct lu_env *env,
2067 struct dt_object *o,
2068 struct ldlm_enqueue_info *einfo,
2069 union ldlm_policy_data *policy)
2072 LASSERT(o->do_ops != NULL);
2073 LASSERT(o->do_ops->do_object_unlock != NULL);
2074 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2077 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2078 const char *name, struct lu_fid *fid);
2080 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2081 __u64 start, __u64 end)
2085 LASSERT(o->do_ops->do_object_sync);
2086 return o->do_ops->do_object_sync(env, o, start, end);
2089 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2090 struct thandle *th);
2091 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2092 dt_obj_version_t version, struct thandle *th);
2093 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2096 int dt_read(const struct lu_env *env, struct dt_object *dt,
2097 struct lu_buf *buf, loff_t *pos);
2098 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2099 struct lu_buf *buf, loff_t *pos);
2100 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2101 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2102 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2103 union lu_page *lp, size_t nob,
2104 const struct dt_it_ops *iops,
2105 struct dt_it *it, __u32 attr, void *arg);
2106 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2107 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2109 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2110 struct idx_info *ii, const struct lu_rdpg *rdpg);
2112 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2113 struct dt_device *d)
2115 LASSERT(d->dd_ops->dt_trans_create);
2116 return d->dd_ops->dt_trans_create(env, d);
2119 static inline int dt_trans_start(const struct lu_env *env,
2120 struct dt_device *d, struct thandle *th)
2122 LASSERT(d->dd_ops->dt_trans_start);
2123 return d->dd_ops->dt_trans_start(env, d, th);
2126 /* for this transaction hooks shouldn't be called */
2127 static inline int dt_trans_start_local(const struct lu_env *env,
2128 struct dt_device *d, struct thandle *th)
2130 LASSERT(d->dd_ops->dt_trans_start);
2132 return d->dd_ops->dt_trans_start(env, d, th);
2135 static inline int dt_trans_stop(const struct lu_env *env,
2136 struct dt_device *d, struct thandle *th)
2138 LASSERT(d->dd_ops->dt_trans_stop);
2139 return d->dd_ops->dt_trans_stop(env, d, th);
2142 static inline int dt_trans_cb_add(struct thandle *th,
2143 struct dt_txn_commit_cb *dcb)
2145 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2146 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2147 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2152 static inline int dt_declare_record_write(const struct lu_env *env,
2153 struct dt_object *dt,
2154 const struct lu_buf *buf,
2160 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2161 LASSERT(th != NULL);
2162 LASSERT(dt->do_body_ops);
2163 LASSERT(dt->do_body_ops->dbo_declare_write);
2164 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2168 static inline int dt_declare_create(const struct lu_env *env,
2169 struct dt_object *dt,
2170 struct lu_attr *attr,
2171 struct dt_allocation_hint *hint,
2172 struct dt_object_format *dof,
2176 LASSERT(dt->do_ops);
2177 LASSERT(dt->do_ops->do_declare_create);
2179 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2180 return cfs_fail_err;
2182 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2185 static inline int dt_create(const struct lu_env *env,
2186 struct dt_object *dt,
2187 struct lu_attr *attr,
2188 struct dt_allocation_hint *hint,
2189 struct dt_object_format *dof,
2193 LASSERT(dt->do_ops);
2194 LASSERT(dt->do_ops->do_create);
2196 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2197 return cfs_fail_err;
2199 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2202 static inline int dt_declare_destroy(const struct lu_env *env,
2203 struct dt_object *dt,
2207 LASSERT(dt->do_ops);
2208 LASSERT(dt->do_ops->do_declare_destroy);
2210 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2211 return cfs_fail_err;
2213 return dt->do_ops->do_declare_destroy(env, dt, th);
2216 static inline int dt_destroy(const struct lu_env *env,
2217 struct dt_object *dt,
2221 LASSERT(dt->do_ops);
2222 LASSERT(dt->do_ops->do_destroy);
2224 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2225 return cfs_fail_err;
2227 return dt->do_ops->do_destroy(env, dt, th);
2230 static inline void dt_read_lock(const struct lu_env *env,
2231 struct dt_object *dt,
2235 LASSERT(dt->do_ops);
2236 LASSERT(dt->do_ops->do_read_lock);
2237 dt->do_ops->do_read_lock(env, dt, role);
2240 static inline void dt_write_lock(const struct lu_env *env,
2241 struct dt_object *dt,
2245 LASSERT(dt->do_ops);
2246 LASSERT(dt->do_ops->do_write_lock);
2247 dt->do_ops->do_write_lock(env, dt, role);
2250 static inline void dt_read_unlock(const struct lu_env *env,
2251 struct dt_object *dt)
2254 LASSERT(dt->do_ops);
2255 LASSERT(dt->do_ops->do_read_unlock);
2256 dt->do_ops->do_read_unlock(env, dt);
2259 static inline void dt_write_unlock(const struct lu_env *env,
2260 struct dt_object *dt)
2263 LASSERT(dt->do_ops);
2264 LASSERT(dt->do_ops->do_write_unlock);
2265 dt->do_ops->do_write_unlock(env, dt);
2268 static inline int dt_write_locked(const struct lu_env *env,
2269 struct dt_object *dt)
2272 LASSERT(dt->do_ops);
2273 LASSERT(dt->do_ops->do_write_locked);
2274 return dt->do_ops->do_write_locked(env, dt);
2277 static inline int dt_declare_attr_get(const struct lu_env *env,
2278 struct dt_object *dt)
2281 LASSERT(dt->do_ops);
2282 LASSERT(dt->do_ops->do_declare_attr_get);
2284 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2285 return cfs_fail_err;
2287 return dt->do_ops->do_declare_attr_get(env, dt);
2290 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2294 LASSERT(dt->do_ops);
2295 LASSERT(dt->do_ops->do_attr_get);
2297 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2298 return cfs_fail_err;
2300 return dt->do_ops->do_attr_get(env, dt, la);
2303 static inline int dt_declare_attr_set(const struct lu_env *env,
2304 struct dt_object *dt,
2305 const struct lu_attr *la,
2309 LASSERT(dt->do_ops);
2310 LASSERT(dt->do_ops->do_declare_attr_set);
2312 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2313 return cfs_fail_err;
2315 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2318 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2319 const struct lu_attr *la, struct thandle *th)
2322 LASSERT(dt->do_ops);
2323 LASSERT(dt->do_ops->do_attr_set);
2325 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2326 return cfs_fail_err;
2328 return dt->do_ops->do_attr_set(env, dt, la, th);
2331 static inline int dt_declare_ref_add(const struct lu_env *env,
2332 struct dt_object *dt, struct thandle *th)
2335 LASSERT(dt->do_ops);
2336 LASSERT(dt->do_ops->do_declare_ref_add);
2338 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2339 return cfs_fail_err;
2341 return dt->do_ops->do_declare_ref_add(env, dt, th);
2344 static inline int dt_ref_add(const struct lu_env *env,
2345 struct dt_object *dt, struct thandle *th)
2348 LASSERT(dt->do_ops);
2349 LASSERT(dt->do_ops->do_ref_add);
2351 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2352 return cfs_fail_err;
2354 return dt->do_ops->do_ref_add(env, dt, th);
2357 static inline int dt_declare_ref_del(const struct lu_env *env,
2358 struct dt_object *dt, struct thandle *th)
2361 LASSERT(dt->do_ops);
2362 LASSERT(dt->do_ops->do_declare_ref_del);
2364 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2365 return cfs_fail_err;
2367 return dt->do_ops->do_declare_ref_del(env, dt, th);
2370 static inline int dt_ref_del(const struct lu_env *env,
2371 struct dt_object *dt, struct thandle *th)
2374 LASSERT(dt->do_ops);
2375 LASSERT(dt->do_ops->do_ref_del);
2377 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2378 return cfs_fail_err;
2380 return dt->do_ops->do_ref_del(env, dt, th);
2383 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2384 struct niobuf_remote *rnb,
2385 struct niobuf_local *lnb, enum dt_bufs_type rw)
2388 LASSERT(d->do_body_ops);
2389 LASSERT(d->do_body_ops->dbo_bufs_get);
2390 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2391 rnb->rnb_len, lnb, rw);
2394 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2395 struct niobuf_local *lnb, int n)
2398 LASSERT(d->do_body_ops);
2399 LASSERT(d->do_body_ops->dbo_bufs_put);
2400 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2403 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2404 struct niobuf_local *lnb, int n)
2407 LASSERT(d->do_body_ops);
2408 LASSERT(d->do_body_ops->dbo_write_prep);
2409 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2412 static inline int dt_declare_write_commit(const struct lu_env *env,
2413 struct dt_object *d,
2414 struct niobuf_local *lnb,
2415 int n, struct thandle *th)
2417 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2418 LASSERT(th != NULL);
2419 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2423 static inline int dt_write_commit(const struct lu_env *env,
2424 struct dt_object *d, struct niobuf_local *lnb,
2425 int n, struct thandle *th)
2428 LASSERT(d->do_body_ops);
2429 LASSERT(d->do_body_ops->dbo_write_commit);
2430 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2433 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2434 struct niobuf_local *lnb, int n)
2437 LASSERT(d->do_body_ops);
2438 LASSERT(d->do_body_ops->dbo_read_prep);
2439 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2442 static inline int dt_declare_write(const struct lu_env *env,
2443 struct dt_object *dt,
2444 const struct lu_buf *buf, loff_t pos,
2448 LASSERT(dt->do_body_ops);
2449 LASSERT(dt->do_body_ops->dbo_declare_write);
2450 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2453 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2454 const struct lu_buf *buf, loff_t *pos,
2455 struct thandle *th, int rq)
2458 LASSERT(dt->do_body_ops);
2459 LASSERT(dt->do_body_ops->dbo_write);
2460 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th, rq);
2463 static inline int dt_declare_punch(const struct lu_env *env,
2464 struct dt_object *dt, __u64 start,
2465 __u64 end, struct thandle *th)
2468 LASSERT(dt->do_body_ops);
2469 LASSERT(dt->do_body_ops->dbo_declare_punch);
2470 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2473 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2474 __u64 start, __u64 end, struct thandle *th)
2477 LASSERT(dt->do_body_ops);
2478 LASSERT(dt->do_body_ops->dbo_punch);
2479 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2482 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2483 __u64 start, __u64 end, int advice)
2486 LASSERT(dt->do_body_ops);
2487 LASSERT(dt->do_body_ops->dbo_ladvise);
2488 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2491 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2495 if (d->do_body_ops == NULL)
2497 if (d->do_body_ops->dbo_fiemap_get == NULL)
2499 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2502 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2503 struct obd_statfs *osfs)
2506 LASSERT(dev->dd_ops);
2507 LASSERT(dev->dd_ops->dt_statfs);
2508 return dev->dd_ops->dt_statfs(env, dev, osfs);
2511 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2515 LASSERT(dev->dd_ops);
2516 LASSERT(dev->dd_ops->dt_root_get);
2517 return dev->dd_ops->dt_root_get(env, dev, f);
2520 static inline void dt_conf_get(const struct lu_env *env,
2521 const struct dt_device *dev,
2522 struct dt_device_param *param)
2525 LASSERT(dev->dd_ops);
2526 LASSERT(dev->dd_ops->dt_conf_get);
2527 return dev->dd_ops->dt_conf_get(env, dev, param);
2530 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2533 LASSERT(dev->dd_ops);
2534 LASSERT(dev->dd_ops->dt_sync);
2535 return dev->dd_ops->dt_sync(env, dev);
2538 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2541 LASSERT(dev->dd_ops);
2542 LASSERT(dev->dd_ops->dt_ro);
2543 return dev->dd_ops->dt_ro(env, dev);
2546 static inline int dt_declare_insert(const struct lu_env *env,
2547 struct dt_object *dt,
2548 const struct dt_rec *rec,
2549 const struct dt_key *key,
2553 LASSERT(dt->do_index_ops);
2554 LASSERT(dt->do_index_ops->dio_declare_insert);
2556 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2557 return cfs_fail_err;
2559 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2562 static inline int dt_insert(const struct lu_env *env,
2563 struct dt_object *dt,
2564 const struct dt_rec *rec,
2565 const struct dt_key *key,
2570 LASSERT(dt->do_index_ops);
2571 LASSERT(dt->do_index_ops->dio_insert);
2573 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2574 return cfs_fail_err;
2576 return dt->do_index_ops->dio_insert(env, dt, rec, key, th, noquota);
2579 static inline int dt_declare_xattr_del(const struct lu_env *env,
2580 struct dt_object *dt,
2585 LASSERT(dt->do_ops);
2586 LASSERT(dt->do_ops->do_declare_xattr_del);
2588 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2589 return cfs_fail_err;
2591 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2594 static inline int dt_xattr_del(const struct lu_env *env,
2595 struct dt_object *dt, const char *name,
2599 LASSERT(dt->do_ops);
2600 LASSERT(dt->do_ops->do_xattr_del);
2602 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2603 return cfs_fail_err;
2605 return dt->do_ops->do_xattr_del(env, dt, name, th);
2608 static inline int dt_declare_xattr_set(const struct lu_env *env,
2609 struct dt_object *dt,
2610 const struct lu_buf *buf,
2611 const char *name, int fl,
2615 LASSERT(dt->do_ops);
2616 LASSERT(dt->do_ops->do_declare_xattr_set);
2618 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2619 return cfs_fail_err;
2621 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2624 static inline int dt_xattr_set(const struct lu_env *env,
2625 struct dt_object *dt, const struct lu_buf *buf,
2626 const char *name, int fl, struct thandle *th)
2629 LASSERT(dt->do_ops);
2630 LASSERT(dt->do_ops->do_xattr_set);
2632 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2633 return cfs_fail_err;
2635 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2638 static inline int dt_declare_xattr_get(const struct lu_env *env,
2639 struct dt_object *dt,
2644 LASSERT(dt->do_ops);
2645 LASSERT(dt->do_ops->do_declare_xattr_get);
2647 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2648 return cfs_fail_err;
2650 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2653 static inline int dt_xattr_get(const struct lu_env *env,
2654 struct dt_object *dt, struct lu_buf *buf,
2658 LASSERT(dt->do_ops);
2659 LASSERT(dt->do_ops->do_xattr_get);
2661 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2662 return cfs_fail_err;
2664 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2667 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2668 const struct lu_buf *buf)
2671 LASSERT(dt->do_ops);
2672 LASSERT(dt->do_ops->do_xattr_list);
2674 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2675 return cfs_fail_err;
2677 return dt->do_ops->do_xattr_list(env, dt, buf);
2680 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2683 LASSERT(dt->do_ops);
2684 LASSERT(dt->do_ops->do_invalidate);
2686 return dt->do_ops->do_invalidate(env, dt);
2689 static inline int dt_declare_delete(const struct lu_env *env,
2690 struct dt_object *dt,
2691 const struct dt_key *key,
2695 LASSERT(dt->do_index_ops);
2696 LASSERT(dt->do_index_ops->dio_declare_delete);
2698 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2699 return cfs_fail_err;
2701 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2704 static inline int dt_delete(const struct lu_env *env,
2705 struct dt_object *dt,
2706 const struct dt_key *key,
2710 LASSERT(dt->do_index_ops);
2711 LASSERT(dt->do_index_ops->dio_delete);
2713 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2714 return cfs_fail_err;
2716 return dt->do_index_ops->dio_delete(env, dt, key, th);
2719 static inline int dt_commit_async(const struct lu_env *env,
2720 struct dt_device *dev)
2723 LASSERT(dev->dd_ops);
2724 LASSERT(dev->dd_ops->dt_commit_async);
2725 return dev->dd_ops->dt_commit_async(env, dev);
2728 static inline int dt_lookup(const struct lu_env *env,
2729 struct dt_object *dt,
2731 const struct dt_key *key)
2736 LASSERT(dt->do_index_ops);
2737 LASSERT(dt->do_index_ops->dio_lookup);
2739 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2740 return cfs_fail_err;
2742 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2750 static inline int dt_declare_layout_change(const struct lu_env *env,
2751 struct dt_object *o,
2752 struct md_layout_change *mlc,
2757 LASSERT(o->do_ops->do_declare_layout_change);
2758 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2761 static inline int dt_layout_change(const struct lu_env *env,
2762 struct dt_object *o,
2763 struct md_layout_change *mlc,
2768 LASSERT(o->do_ops->do_layout_change);
2769 return o->do_ops->do_layout_change(env, o, mlc, th);
2772 struct dt_find_hint {
2773 struct lu_fid *dfh_fid;
2774 struct dt_device *dfh_dt;
2775 struct dt_object *dfh_o;
2778 struct dt_insert_rec {
2780 const struct lu_fid *rec_fid;
2792 struct dt_thread_info {
2793 char dti_buf[DT_MAX_PATH];
2794 struct dt_find_hint dti_dfh;
2795 struct lu_attr dti_attr;
2796 struct lu_fid dti_fid;
2797 struct dt_object_format dti_dof;
2798 struct lustre_mdt_attrs dti_lma;
2799 struct lu_buf dti_lb;
2800 struct lu_object_conf dti_conf;
2802 struct dt_insert_rec dti_dt_rec;
2805 extern struct lu_context_key dt_key;
2807 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2809 struct dt_thread_info *dti;
2811 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2816 int dt_global_init(void);
2817 void dt_global_fini(void);
2819 # ifdef CONFIG_PROC_FS
2820 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2821 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2822 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2823 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2824 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2825 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2826 # endif /* CONFIG_PROC_FS */
2828 #endif /* __LUSTRE_DT_OBJECT_H */