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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef __LUSTRE_DT_OBJECT_H
38 #define __LUSTRE_DT_OBJECT_H
41 * Sub-class of lu_object with methods common for "data" objects in OST stack.
43 * Data objects behave like regular files: you can read/write them, get and
44 * set their attributes. Implementation of dt interface is supposed to
45 * implement some form of garbage collection, normally reference counting
48 * Examples: osd (lustre/osd) is an implementation of dt interface.
52 #include <obd_support.h>
54 * super-class definitions.
56 #include <lu_object.h>
58 #include <libcfs/libcfs.h>
61 struct proc_dir_entry;
67 struct dt_index_features;
70 struct ldlm_enqueue_info;
73 MNTOPT_USERXATTR = 0x00000001,
74 MNTOPT_ACL = 0x00000002,
77 struct dt_device_param {
78 unsigned ddp_max_name_len;
79 unsigned ddp_max_nlink;
80 unsigned ddp_block_shift;
82 unsigned ddp_max_ea_size;
84 unsigned long long ddp_maxbytes;
85 /* percentage of available space to reserve for grant error margin */
86 int ddp_grant_reserved;
87 /* per-inode space consumption */
89 /* per-fragment grant overhead to be used by client for grant
95 * Per-transaction commit callback function
97 struct dt_txn_commit_cb;
98 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
99 struct dt_txn_commit_cb *cb, int err);
101 * Special per-transaction callback for cases when just commit callback
102 * is needed and per-device callback are not convenient to use
104 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
105 #define MAX_COMMIT_CB_STR_LEN 32
107 struct dt_txn_commit_cb {
108 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_orphan_features;
347 extern const struct dt_index_features dt_lfsck_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;
359 * This is a general purpose dt allocation hint.
360 * It now contains the parent object.
361 * It can contain any allocation hint in the future.
363 struct dt_allocation_hint {
364 struct dt_object *dah_parent;
365 const void *dah_eadata;
371 * object type specifier.
374 enum dt_format_type {
379 /** for special index */
381 /** for symbolic link */
386 * object format specifier.
388 struct dt_object_format {
389 /** type for dt object */
390 enum dt_format_type dof_type;
400 * special index need feature as parameter to create
404 const struct dt_index_features *di_feat;
409 enum dt_format_type dt_mode_to_dft(__u32 mode);
411 typedef __u64 dt_obj_version_t;
413 union ldlm_policy_data;
416 * A dt_object provides common operations to create and destroy
417 * objects and to manage regular and extended attributes.
419 struct dt_object_operations {
421 * Get read lock on object.
423 * Read lock is compatible with other read locks, so it's shared.
424 * Read lock is not compatible with write lock which is exclusive.
425 * The lock is blocking and can't be used from an interrupt context.
427 * \param[in] env execution environment for this thread
428 * \param[in] dt object to lock for reading
429 * \param[in] role a hint to debug locks (see kernel's mutexes)
431 void (*do_read_lock)(const struct lu_env *env,
432 struct dt_object *dt,
436 * Get write lock on object.
438 * Write lock is exclusive and cannot be shared. The lock is blocking
439 * and can't be used from an interrupt context.
441 * \param[in] env execution environment for this thread
442 * \param[in] dt object to lock for writing
443 * \param[in] role a hint to debug locks (see kernel's mutexes)
446 void (*do_write_lock)(const struct lu_env *env,
447 struct dt_object *dt,
453 * \param[in] env execution environment for this thread
454 * \param[in] dt object
456 void (*do_read_unlock)(const struct lu_env *env,
457 struct dt_object *dt);
460 * Release write lock.
462 * \param[in] env execution environment for this thread
463 * \param[in] dt object
465 void (*do_write_unlock)(const struct lu_env *env,
466 struct dt_object *dt);
469 * Check whether write lock is held.
471 * The caller can learn whether write lock is held on the object
473 * \param[in] env execution environment for this thread
474 * \param[in] dt object
476 * \retval 0 no write lock
477 * \retval 1 write lock is held
479 int (*do_write_locked)(const struct lu_env *env,
480 struct dt_object *dt);
483 * Declare intention to request reqular attributes.
485 * Notity the underlying filesystem that the caller may request regular
486 * attributes with ->do_attr_get() soon. This allows OSD to implement
487 * prefetching logic in an object-oriented manner. The implementation
488 * can be noop. This method should avoid expensive delays such as
489 * waiting on disk I/O, otherwise the goal of enabling a performance
490 * optimization would be defeated.
492 * \param[in] env execution environment for this thread
493 * \param[in] dt object
495 * \retval 0 on success
496 * \retval negative negated errno on error
498 int (*do_declare_attr_get)(const struct lu_env *env,
499 struct dt_object *dt);
502 * Return regular attributes.
504 * The object must exist. Currently all the attributes should be
505 * returned, but in the future this can be improved so that only
506 * a selected set is returned. This can improve performance as in
507 * some cases attributes are stored in different places and
508 * getting them all can be an iterative and expensive process.
510 * \param[in] env execution environment for this thread
511 * \param[in] dt object
512 * \param[out] attr attributes to fill
514 * \retval 0 on success
515 * \retval negative negated errno on error
517 int (*do_attr_get)(const struct lu_env *env,
518 struct dt_object *dt,
519 struct lu_attr *attr);
522 * Declare intention to change regular object's attributes.
524 * Notify the underlying filesystem that the regular attributes may
525 * change in this transaction. This enables the layer below to prepare
526 * resources (e.g. journal credits in ext4). This method should be
527 * called between creating the transaction and starting it. Note that
528 * the la_valid field of \a attr specifies which attributes will change.
529 * The object need not exist.
531 * \param[in] env execution environment for this thread
532 * \param[in] dt object
533 * \param[in] attr attributes to change specified in attr.la_valid
534 * \param[in] th transaction handle
536 * \retval 0 on success
537 * \retval negative negated errno on error
539 int (*do_declare_attr_set)(const struct lu_env *env,
540 struct dt_object *dt,
541 const struct lu_attr *attr,
545 * Change regular attributes.
547 * Change regular attributes in the given transaction. Note only
548 * attributes flagged by attr.la_valid change. The object must
549 * exist. If the layer implementing this method is responsible for
550 * quota, then the method should maintain object accounting for the
551 * given credentials when la_uid/la_gid changes.
553 * \param[in] env execution environment for this thread
554 * \param[in] dt object
555 * \param[in] attr new attributes to apply
556 * \param[in] th transaction handle
558 * \retval 0 on success
559 * \retval negative negated errno on error
561 int (*do_attr_set)(const struct lu_env *env,
562 struct dt_object *dt,
563 const struct lu_attr *attr,
567 * Declare intention to request extented attribute.
569 * Notify the underlying filesystem that the caller may request extended
570 * attribute with ->do_xattr_get() soon. This allows OSD to implement
571 * prefetching logic in an object-oriented manner. The implementation
572 * can be noop. This method should avoid expensive delays such as
573 * waiting on disk I/O, otherwise the goal of enabling a performance
574 * optimization would be defeated.
576 * \param[in] env execution environment for this thread
577 * \param[in] dt object
578 * \param[in] buf unused, may be removed in the future
579 * \param[in] name name of the extended attribute
581 * \retval 0 on success
582 * \retval negative negated errno on error
584 int (*do_declare_xattr_get)(const struct lu_env *env,
585 struct dt_object *dt,
590 * Return a value of an extended attribute.
592 * The object must exist. If the buffer is NULL, then the method
593 * must return the size of the value.
595 * \param[in] env execution environment for this thread
596 * \param[in] dt object
597 * \param[out] buf buffer in which to store the value
598 * \param[in] name name of the extended attribute
600 * \retval 0 on success
601 * \retval -ERANGE if \a buf is too small
602 * \retval negative negated errno on error
603 * \retval positive value's size if \a buf is NULL or has zero size
605 int (*do_xattr_get)(const struct lu_env *env,
606 struct dt_object *dt,
611 * Declare intention to change an extended attribute.
613 * Notify the underlying filesystem that the extended attribute may
614 * change in this transaction. This enables the layer below to prepare
615 * resources (e.g. journal credits in ext4). This method should be
616 * called between creating the transaction and starting it. The object
619 * \param[in] env execution environment for this thread
620 * \param[in] dt object
621 * \param[in] buf buffer storing new value of the attribute
622 * \param[in] name name of the attribute
623 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
624 * LU_XATTR_REPLACE - fail if EA doesn't exist
625 * \param[in] th transaction handle
627 * \retval 0 on success
628 * \retval negative negated errno on error
630 int (*do_declare_xattr_set)(const struct lu_env *env,
631 struct dt_object *dt,
632 const struct lu_buf *buf,
638 * Set an extended attribute.
640 * Change or replace the specified extended attribute (EA).
641 * The flags passed in \a fl dictate whether the EA is to be
642 * created or replaced, as follows.
643 * LU_XATTR_CREATE - fail if EA exists
644 * LU_XATTR_REPLACE - fail if EA doesn't exist
645 * The object must exist.
647 * \param[in] env execution environment for this thread
648 * \param[in] dt object
649 * \param[in] buf buffer storing new value of the attribute
650 * \param[in] name name of the attribute
651 * \param[in] fl flags indicating EA creation or replacement
652 * \param[in] th transaction handle
654 * \retval 0 on success
655 * \retval negative negated errno on error
657 int (*do_xattr_set)(const struct lu_env *env,
658 struct dt_object *dt,
659 const struct lu_buf *buf,
665 * Declare intention to delete an extended attribute.
667 * Notify the underlying filesystem that the extended attribute may
668 * be deleted in this transaction. This enables the layer below to
669 * prepare resources (e.g. journal credits in ext4). This method
670 * should be called between creating the transaction and starting it.
671 * The object need not exist.
673 * \param[in] env execution environment for this thread
674 * \param[in] dt object
675 * \param[in] name name of the attribute
676 * \param[in] th transaction handle
678 * \retval 0 on success
679 * \retval negative negated errno on error
681 int (*do_declare_xattr_del)(const struct lu_env *env,
682 struct dt_object *dt,
687 * Delete an extended attribute.
689 * This method deletes the specified extended attribute. The object
692 * \param[in] env execution environment for this thread
693 * \param[in] dt object
694 * \param[in] name name of the attribute
695 * \param[in] th transaction handle
697 * \retval 0 on success
698 * \retval negative negated errno on error
700 int (*do_xattr_del)(const struct lu_env *env,
701 struct dt_object *dt,
706 * Return a list of the extended attributes.
708 * Fills the passed buffer with a list of the extended attributes
709 * found in the object. The names are separated with '\0'.
710 * The object must exist.
712 * \param[in] env execution environment for this thread
713 * \param[in] dt object
714 * \param[out] buf buffer to put the list in
716 * \retval positive bytes used/required in the buffer
717 * \retval negative negated errno on error
719 int (*do_xattr_list)(const struct lu_env *env,
720 struct dt_object *dt,
721 const struct lu_buf *buf);
724 * Prepare allocation hint for a new object.
726 * This method is used by the caller to inform OSD of the parent-child
727 * relationship between two objects and enable efficient object
728 * allocation. Filled allocation hint will be passed to ->do_create()
731 * \param[in] env execution environment for this thread
732 * \param[out] ah allocation hint
733 * \param[in] parent parent object (can be NULL)
734 * \param[in] child child object
735 * \param[in] _mode type of the child object
737 void (*do_ah_init)(const struct lu_env *env,
738 struct dt_allocation_hint *ah,
739 struct dt_object *parent,
740 struct dt_object *child,
744 * Declare intention to create a new object.
746 * Notify the underlying filesystem that the object may be created
747 * in this transaction. This enables the layer below to prepare
748 * resources (e.g. journal credits in ext4). This method should be
749 * called between creating the transaction and starting it.
751 * If the layer implementing this method is responsible for quota,
752 * then the method should reserve an object for the given credentials
753 * and return an error if quota is over. If object creation later
754 * fails for some reason, then the reservation should be released
755 * properly (usually in ->dt_trans_stop()).
757 * \param[in] env execution environment for this thread
758 * \param[in] dt object
759 * \param[in] attr attributes of the new object
760 * \param[in] hint allocation hint
761 * \param[in] dof object format
762 * \param[in] th transaction handle
764 * \retval 0 on success
765 * \retval negative negated errno on error
767 int (*do_declare_create)(const struct lu_env *env,
768 struct dt_object *dt,
769 struct lu_attr *attr,
770 struct dt_allocation_hint *hint,
771 struct dt_object_format *dof,
777 * The method creates the object passed with the specified attributes
778 * and object format. Object allocation procedure can use information
779 * stored in the allocation hint. Different object formats are supported
780 * (see enum dt_format_type and struct dt_object_format) depending on
781 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
782 * in the LU-object header attributes.
784 * If the layer implementing this method is responsible for quota,
785 * then the method should maintain object accounting for the given
788 * \param[in] env execution environment for this thread
789 * \param[in] dt object
790 * \param[in] attr attributes of the new object
791 * \param[in] hint allocation hint
792 * \param[in] dof object format
793 * \param[in] th transaction handle
795 * \retval 0 on success
796 * \retval negative negated errno on error
798 int (*do_create)(const struct lu_env *env,
799 struct dt_object *dt,
800 struct lu_attr *attr,
801 struct dt_allocation_hint *hint,
802 struct dt_object_format *dof,
806 * Declare intention to destroy an object.
808 * Notify the underlying filesystem that the object may be destroyed
809 * in this transaction. This enables the layer below to prepare
810 * resources (e.g. journal credits in ext4). This method should be
811 * called between creating the transaction and starting it. The object
814 * \param[in] env execution environment for this thread
815 * \param[in] dt object
816 * \param[in] th transaction handle
818 * \retval 0 on success
819 * \retval negative negated errno on error
821 int (*do_declare_destroy)(const struct lu_env *env,
822 struct dt_object *dt,
828 * This method destroys the object and all the resources associated
829 * with the object (data, key/value pairs, extended attributes, etc).
830 * The object must exist. If destroy is successful, then flag
831 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
832 * instance of in-core object. Any subsequent access to the same FID
833 * should get another instance with no LOHA_EXIST flag set.
835 * If the layer implementing this method is responsible for quota,
836 * then the method should maintain object accounting for the given
839 * \param[in] env execution environment for this thread
840 * \param[in] dt object
841 * \param[in] th transaction handle
843 * \retval 0 on success
844 * \retval negative negated errno on error
846 int (*do_destroy)(const struct lu_env *env,
847 struct dt_object *dt,
851 * Try object as an index.
853 * Announce that this object is going to be used as an index. This
854 * operation checks that object supports indexing operations and
855 * installs appropriate dt_index_operations vector on success.
856 * Also probes for features. Operation is successful if all required
857 * features are supported. It's not possible to access the object
858 * with index methods before ->do_index_try() returns success.
860 * \param[in] env execution environment for this thread
861 * \param[in] dt object
862 * \param[in] feat index features
864 * \retval 0 on success
865 * \retval negative negated errno on error
867 int (*do_index_try)(const struct lu_env *env,
868 struct dt_object *dt,
869 const struct dt_index_features *feat);
872 * Declare intention to increment nlink count.
874 * Notify the underlying filesystem that the nlink regular attribute
875 * be changed in this transaction. This enables the layer below to
876 * prepare resources (e.g. journal credits in ext4). This method
877 * should be called between creating the transaction and starting it.
878 * The object need not exist.
880 * \param[in] env execution environment for this thread
881 * \param[in] dt object
882 * \param[in] th transaction handle
884 * \retval 0 on success
885 * \retval negative negated errno on error
887 int (*do_declare_ref_add)(const struct lu_env *env,
888 struct dt_object *dt,
894 * Increment nlink (from the regular attributes set) in the given
895 * transaction. Note the absolute limit for nlink should be learnt
896 * from struct dt_device_param::ddp_max_nlink. The object must exist.
898 * \param[in] env execution environment for this thread
899 * \param[in] dt object
900 * \param[in] th transaction handle
902 * \retval 0 on success
903 * \retval negative negated errno on error
905 int (*do_ref_add)(const struct lu_env *env,
906 struct dt_object *dt, struct thandle *th);
909 * Declare intention to decrement nlink count.
911 * Notify the underlying filesystem that the nlink regular attribute
912 * be changed in this transaction. This enables the layer below to
913 * prepare resources (e.g. journal credits in ext4). This method
914 * should be called between creating the transaction and starting it.
915 * The object need not exist.
917 * \param[in] env execution environment for this thread
918 * \param[in] dt object
919 * \param[in] th transaction handle
921 * \retval 0 on success
922 * \retval negative negated errno on error
924 int (*do_declare_ref_del)(const struct lu_env *env,
925 struct dt_object *dt,
931 * Decrement nlink (from the regular attributes set) in the given
932 * transaction. The object must exist.
934 * \param[in] env execution environment for this thread
935 * \param[in] dt object
936 * \param[in] th transaction handle
938 * \retval 0 on success
939 * \retval negative negated errno on error
941 int (*do_ref_del)(const struct lu_env *env,
942 struct dt_object *dt,
948 * The method is called to sync specified range of the object to a
949 * persistent storage. The control is returned once the operation is
950 * complete. The difference from ->do_sync() is that the object can
951 * be in-sync with the persistent storage (nothing to flush), then
952 * the method returns quickly with no I/O overhead. So, this method
953 * should be preferred over ->do_sync() where possible. Also note that
954 * if the object isn't clean, then some disk filesystems will call
955 * ->do_sync() to maintain overall consistency, in which case it's
956 * still very expensive.
958 * \param[in] env execution environment for this thread
959 * \param[in] dt object
960 * \param[in] start start of the range to sync
961 * \param[in] end end of the range to sync
963 * \retval 0 on success
964 * \retval negative negated errno on error
966 int (*do_object_sync)(const struct lu_env *env,
967 struct dt_object *obj,
974 * Lock object(s) using Distributed Lock Manager (LDLM).
976 * Get LDLM locks for the object. Currently used to lock "remote"
977 * objects in DNE configuration - a service running on MDTx needs
978 * to lock an object on MDTy.
980 * \param[in] env execution environment for this thread
981 * \param[in] dt object
982 * \param[out] lh lock handle, sometimes used, sometimes not
983 * \param[in] einfo ldlm callbacks, locking type and mode
984 * \param[out] einfo private data to be passed to unlock later
985 * \param[in] policy inodebits data
987 * \retval 0 on success
988 * \retval negative negated errno on error
990 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
991 struct lustre_handle *lh,
992 struct ldlm_enqueue_info *einfo,
993 union ldlm_policy_data *policy);
998 * Release LDLM lock(s) granted with ->do_object_lock().
1000 * \param[in] env execution environment for this thread
1001 * \param[in] dt object
1002 * \param[in] einfo lock handles, from ->do_object_lock()
1003 * \param[in] policy inodebits data
1005 * \retval 0 on success
1006 * \retval negative negated errno on error
1008 int (*do_object_unlock)(const struct lu_env *env,
1009 struct dt_object *dt,
1010 struct ldlm_enqueue_info *einfo,
1011 union ldlm_policy_data *policy);
1015 * Per-dt-object operations on "file body" - unstructure raw data.
1017 struct dt_body_operations {
1021 * Read unstructured data from an existing regular object.
1022 * Only data before attr.la_size is returned.
1024 * \param[in] env execution environment for this thread
1025 * \param[in] dt object
1026 * \param[out] buf buffer (including size) to copy data in
1027 * \param[in] pos position in the object to start
1028 * \param[out] pos original value of \a pos + bytes returned
1030 * \retval positive bytes read on success
1031 * \retval negative negated errno on error
1033 ssize_t (*dbo_read)(const struct lu_env *env,
1034 struct dt_object *dt,
1039 * Declare intention to write data to object.
1041 * Notify the underlying filesystem that data may be written in
1042 * this transaction. This enables the layer below to prepare resources
1043 * (e.g. journal credits in ext4). This method should be called
1044 * between creating the transaction and starting it. The object need
1045 * not exist. If the layer implementing this method is responsible for
1046 * quota, then the method should reserve space for the given credentials
1047 * and return an error if quota is over. If the write later fails
1048 * for some reason, then the reserve should be released properly
1049 * (usually in ->dt_trans_stop()).
1051 * \param[in] env execution environment for this thread
1052 * \param[in] dt object
1053 * \param[in] buf buffer (including size) to copy data from
1054 * \param[in] pos position in the object to start
1055 * \param[in] th transaction handle
1057 * \retval 0 on success
1058 * \retval negative negated errno on error
1060 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1061 struct dt_object *dt,
1062 const struct lu_buf *buf,
1064 struct thandle *th);
1067 * Write unstructured data to regular existing object.
1069 * The method allocates space and puts data in. Also, the method should
1070 * maintain attr.la_size properly. Partial writes are possible.
1072 * If the layer implementing this method is responsible for quota,
1073 * then the method should maintain space accounting for the given
1076 * \param[in] env execution environment for this thread
1077 * \param[in] dt object
1078 * \param[in] buf buffer (including size) to copy data from
1079 * \param[in] pos position in the object to start
1080 * \param[out] pos \a pos + bytes written
1081 * \param[in] th transaction handle
1082 * \param[in] ignore unused (was used to request quota ignorance)
1084 * \retval positive bytes written on success
1085 * \retval negative negated errno on error
1087 ssize_t (*dbo_write)(const struct lu_env *env,
1088 struct dt_object *dt,
1089 const struct lu_buf *buf,
1095 * Return buffers for data.
1097 * This method is used to access data with no copying. It's so-called
1098 * zero-copy I/O. The method returns the descriptors for the internal
1099 * buffers where data are managed by the disk filesystem. For example,
1100 * pagecache in case of ext4 or ARC with ZFS. Then other components
1101 * (e.g. networking) can transfer data from or to the buffers with no
1102 * additional copying.
1104 * The method should fill an array of struct niobuf_local, where
1105 * each element describes a full or partial page for data at specific
1106 * offset. The caller should use page/lnb_page_offset/len to find data
1107 * at object's offset lnb_file_offset.
1109 * The memory referenced by the descriptors can't change its purpose
1110 * until the complementary ->dbo_bufs_put() is called. The caller should
1111 * specify if the buffers are used to read or modify data so that OSD
1112 * can decide how to initialize the buffers: bring all the data for
1113 * reads or just bring partial buffers for write. Note: the method does
1114 * not check whether output array is large enough.
1116 * \param[in] env execution environment for this thread
1117 * \param[in] dt object
1118 * \param[in] pos position in the object to start
1119 * \param[in] len size of region in bytes
1120 * \param[out] lb array of descriptors to fill
1121 * \param[in] rw 0 if used to read, 1 if used for write
1123 * \retval positive number of descriptors on success
1124 * \retval negative negated errno on error
1126 int (*dbo_bufs_get)(const struct lu_env *env,
1127 struct dt_object *dt,
1130 struct niobuf_local *lb,
1134 * Release reference granted by ->dbo_bufs_get().
1136 * Release the reference granted by the previous ->dbo_bufs_get().
1137 * Note the references are counted.
1139 * \param[in] env execution environment for this thread
1140 * \param[in] dt object
1141 * \param[out] lb array of descriptors to fill
1142 * \param[in] nr size of the array
1144 * \retval 0 on success
1145 * \retval negative negated errno on error
1147 int (*dbo_bufs_put)(const struct lu_env *env,
1148 struct dt_object *dt,
1149 struct niobuf_local *lb,
1153 * Prepare buffers for reading.
1155 * The method is called on the given buffers to fill them with data
1156 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1157 * caller should be able to get few buffers for discontiguous regions
1158 * using few calls to ->dbo_bufs_get() and then request them all for
1159 * the preparation with a single call, so that OSD can fire many I/Os
1160 * to run concurrently. It's up to the specific OSD whether to implement
1161 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1162 * prepare data for every requested region individually.
1164 * \param[in] env execution environment for this thread
1165 * \param[in] dt object
1166 * \param[in] lnb array of buffer descriptors
1167 * \param[in] nr size of the array
1169 * \retval 0 on success
1170 * \retval negative negated errno on error
1172 int (*dbo_read_prep)(const struct lu_env *env,
1173 struct dt_object *dt,
1174 struct niobuf_local *lnb,
1178 * Prepare buffers for write.
1180 * This method is called on the given buffers to ensure the partial
1181 * buffers contain correct data. The underlying idea is the same as
1182 * in ->db_read_prep().
1184 * \param[in] env execution environment for this thread
1185 * \param[in] dt object
1186 * \param[in] lb array of buffer descriptors
1187 * \param[in] nr size of the array
1189 * \retval 0 on success
1190 * \retval negative negated errno on error
1192 int (*dbo_write_prep)(const struct lu_env *env,
1193 struct dt_object *dt,
1194 struct niobuf_local *lb,
1198 * Declare intention to write data stored in the buffers.
1200 * Notify the underlying filesystem that data may be written in
1201 * this transaction. This enables the layer below to prepare resources
1202 * (e.g. journal credits in ext4). This method should be called
1203 * between creating the transaction and starting it.
1205 * If the layer implementing this method is responsible for quota,
1206 * then the method should be reserving a space for the given
1207 * credentials and return an error if quota is exceeded. If the write
1208 * later fails for some reason, then the reserve should be released
1209 * properly (usually in ->dt_trans_stop()).
1211 * \param[in] env execution environment for this thread
1212 * \param[in] dt object
1213 * \param[in] lb array of descriptors
1214 * \param[in] nr size of the array
1215 * \param[in] th transaction handle
1217 * \retval 0 on success
1218 * \retval negative negated errno on error
1220 int (*dbo_declare_write_commit)(const struct lu_env *env,
1221 struct dt_object *dt,
1222 struct niobuf_local *lb,
1224 struct thandle *th);
1227 * Write to existing object.
1229 * This method is used to write data to a persistent storage using
1230 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1231 * data into the buffers using own mechanisms (e.g. direct transfer
1232 * from a NIC). The method should maintain attr.la_size. Also,
1233 * attr.la_blocks should be maintained but this can be done in lazy
1234 * manner, when actual allocation happens.
1236 * If the layer implementing this method is responsible for quota,
1237 * then the method should maintain space accounting for the given
1240 * \param[in] env execution environment for this thread
1241 * \param[in] dt object
1242 * \param[in] lb array of descriptors for the buffers
1243 * \param[in] nr size of the array
1244 * \param[in] th transaction handle
1246 * \retval 0 on success
1247 * \retval negative negated errno on error
1249 int (*dbo_write_commit)(const struct lu_env *env,
1250 struct dt_object *dt,
1251 struct niobuf_local *lb,
1253 struct thandle *th);
1256 * Return logical to physical block mapping for a given extent
1258 * \param[in] env execution environment for this thread
1259 * \param[in] dt object
1260 * \param[in] fm describe the region to map and the output buffer
1261 * see the details in include/linux/fiemap.h
1263 * \retval 0 on success
1264 * \retval negative negated errno on error
1266 int (*dbo_fiemap_get)(const struct lu_env *env,
1267 struct dt_object *dt,
1268 struct ll_user_fiemap *fm);
1271 * Declare intention to deallocate space from an object.
1273 * Notify the underlying filesystem that space may be deallocated in
1274 * this transactions. This enables the layer below to prepare resources
1275 * (e.g. journal credits in ext4). This method should be called between
1276 * creating the transaction and starting it. The object need not exist.
1278 * \param[in] env execution environment for this thread
1279 * \param[in] dt object
1280 * \param[in] start the start of the region to deallocate
1281 * \param[in] end the end of the region to deallocate
1282 * \param[in] th transaction handle
1284 * \retval 0 on success
1285 * \retval negative negated errno on error
1287 int (*dbo_declare_punch)(const struct lu_env *env,
1288 struct dt_object *dt,
1291 struct thandle *th);
1294 * Deallocate specified region in an object.
1296 * This method is used to deallocate (release) space possibly consumed
1297 * by the given region of the object. If the layer implementing this
1298 * method is responsible for quota, then the method should maintain
1299 * space accounting for the given credentials.
1301 * \param[in] env execution environment for this thread
1302 * \param[in] dt object
1303 * \param[in] start the start of the region to deallocate
1304 * \param[in] end the end of the region to deallocate
1305 * \param[in] th transaction handle
1307 * \retval 0 on success
1308 * \retval negative negated errno on error
1310 int (*dbo_punch)(const struct lu_env *env,
1311 struct dt_object *dt,
1314 struct thandle *th);
1318 * Incomplete type of index record.
1323 * Incomplete type of index key.
1328 * Incomplete type of dt iterator.
1333 * Per-dt-object operations on object as index. Index is a set of key/value
1334 * pairs abstracted from an on-disk representation. An index supports the
1335 * number of operations including lookup by key, insert and delete. Also,
1336 * an index can be iterated to find the pairs one by one, from a beginning
1337 * or specified point.
1339 struct dt_index_operations {
1341 * Lookup in an index by key.
1343 * The method returns a value for the given key. Key/value format
1344 * and size should have been negotiated with ->do_index_try() before.
1345 * Thus it's the caller's responsibility to provide the method with
1346 * proper key and big enough buffer. No external locking is required,
1347 * all the internal consistency should be implemented by the method
1348 * or lower layers. The object should should have been created with
1349 * type DFT_INDEX or DFT_DIR.
1351 * \param[in] env execution environment for this thread
1352 * \param[in] dt object
1353 * \param[out] rec buffer where value will be stored
1354 * \param[in] key key
1356 * \retval 0 on success
1357 * \retval -ENOENT if key isn't found
1358 * \retval negative negated errno on error
1360 int (*dio_lookup)(const struct lu_env *env,
1361 struct dt_object *dt,
1363 const struct dt_key *key);
1366 * Declare intention to insert a key/value into an index.
1368 * Notify the underlying filesystem that new key/value may be inserted
1369 * in this transaction. This enables the layer below to prepare
1370 * resources (e.g. journal credits in ext4). This method should be
1371 * called between creating the transaction and starting it. key/value
1372 * format and size is subject to ->do_index_try().
1374 * \param[in] env execution environment for this thread
1375 * \param[in] dt object
1376 * \param[in] rec buffer storing value
1377 * \param[in] key key
1378 * \param[in] th transaction handle
1380 * \retval 0 on success
1381 * \retval negative negated errno on error
1383 int (*dio_declare_insert)(const struct lu_env *env,
1384 struct dt_object *dt,
1385 const struct dt_rec *rec,
1386 const struct dt_key *key,
1387 struct thandle *th);
1390 * Insert a new key/value pair into an index.
1392 * The method inserts specified key/value pair into the given index
1393 * object. The internal consistency is maintained by the method or
1394 * the functionality below. The format and size of key/value should
1395 * have been negotiated before using ->do_index_try(), no additional
1396 * information can be specified to the method. The keys are unique
1399 * \param[in] env execution environment for this thread
1400 * \param[in] dt object
1401 * \param[in] rec buffer storing value
1402 * \param[in] key key
1403 * \param[in] th transaction handle
1404 * \param[in] ignore unused (was used to request quota ignorance)
1406 * \retval 0 on success
1407 * \retval negative negated errno on error
1409 int (*dio_insert)(const struct lu_env *env,
1410 struct dt_object *dt,
1411 const struct dt_rec *rec,
1412 const struct dt_key *key,
1417 * Declare intention to delete a key/value from an index.
1419 * Notify the underlying filesystem that key/value may be deleted in
1420 * this transaction. This enables the layer below to prepare resources
1421 * (e.g. journal credits in ext4). This method should be called
1422 * between creating the transaction and starting it. Key/value format
1423 * and size is subject to ->do_index_try(). The object need not exist.
1425 * \param[in] env execution environment for this thread
1426 * \param[in] dt object
1427 * \param[in] key key
1428 * \param[in] th transaction handle
1430 * \retval 0 on success
1431 * \retval negative negated errno on error
1433 int (*dio_declare_delete)(const struct lu_env *env,
1434 struct dt_object *dt,
1435 const struct dt_key *key,
1436 struct thandle *th);
1439 * Delete key/value pair from an index.
1441 * The method deletes specified key and corresponding value from the
1442 * given index object. The internal consistency is maintained by the
1443 * method or the functionality below. The format and size of the key
1444 * should have been negotiated before using ->do_index_try(), no
1445 * additional information can be specified to the method.
1447 * \param[in] env execution environment for this thread
1448 * \param[in] dt object
1449 * \param[in] key key
1450 * \param[in] th transaction handle
1452 * \retval 0 on success
1453 * \retval negative negated errno on error
1455 int (*dio_delete)(const struct lu_env *env,
1456 struct dt_object *dt,
1457 const struct dt_key *key,
1458 struct thandle *th);
1461 * Iterator interface.
1463 * Methods to iterate over an existing index, list the keys stored and
1464 * associated values, get key/value size, etc.
1468 * Allocate and initialize new iterator.
1470 * The iterator is a handler to be used in the subsequent
1471 * methods to access index's content. Note the position is
1472 * not defined at this point and should be initialized with
1473 * ->get() or ->load() method.
1475 * \param[in] env execution environment for this thread
1476 * \param[in] dt object
1477 * \param[in] attr ask the iterator to return part of
1478 the records, see LUDA_* for details
1480 * \retval pointer iterator pointer on success
1481 * \retval ERR_PTR(errno) on error
1483 struct dt_it *(*init)(const struct lu_env *env,
1484 struct dt_object *dt,
1490 * Release the specified iterator and all the resources
1491 * associated (e.g. the object, index cache, etc).
1493 * \param[in] env execution environment for this thread
1494 * \param[in] di iterator to release
1496 void (*fini)(const struct lu_env *env,
1500 * Move position of iterator.
1502 * Move the position of the specified iterator to the specified
1505 * \param[in] env execution environment for this thread
1506 * \param[in] di iterator
1507 * \param[in] key key to position to
1509 * \retval 0 if exact key is found
1510 * \retval 1 if at the record with least key
1511 * not larger than the key
1512 * \retval negative negated errno on error
1514 int (*get)(const struct lu_env *env,
1516 const struct dt_key *key);
1521 * Complimentary method for dt_it_ops::get() above. Some
1522 * implementation can increase a reference on the iterator in
1523 * dt_it_ops::get(). So the caller should be able to release
1524 * with dt_it_ops::put().
1526 * \param[in] env execution environment for this thread
1527 * \param[in] di iterator
1529 void (*put)(const struct lu_env *env,
1533 * Move to next record.
1535 * Moves the position of the iterator to a next record
1537 * \param[in] env execution environment for this thread
1538 * \param[in] di iterator
1540 * \retval 1 if no more records
1541 * \retval 0 on success, the next record is found
1542 * \retval negative negated errno on error
1544 int (*next)(const struct lu_env *env,
1550 * Returns a pointer to a buffer containing the key of the
1551 * record at the current position. The pointer is valid and
1552 * retains data until ->get(), ->load() and ->fini() methods
1555 * \param[in] env execution environment for this thread
1556 * \param[in] di iterator
1558 * \retval pointer to key on success
1559 * \retval ERR_PTR(errno) on error
1561 struct dt_key *(*key)(const struct lu_env *env,
1562 const struct dt_it *di);
1567 * Returns size of the key at the current position.
1569 * \param[in] env execution environment for this thread
1570 * \param[in] di iterator
1572 * \retval key's size on success
1573 * \retval negative negated errno on error
1575 int (*key_size)(const struct lu_env *env,
1576 const struct dt_it *di);
1581 * Stores the value of the record at the current position. The
1582 * buffer must be big enough (as negotiated with
1583 * ->do_index_try() or ->rec_size()). The caller can specify
1584 * she is interested only in part of the record, using attr
1585 * argument (see LUDA_* definitions for the details).
1587 * \param[in] env execution environment for this thread
1588 * \param[in] di iterator
1589 * \param[out] rec buffer to store value in
1590 * \param[in] attr specify part of the value to copy
1592 * \retval 0 on success
1593 * \retval negative negated errno on error
1595 int (*rec)(const struct lu_env *env,
1596 const struct dt_it *di,
1601 * Return record size.
1603 * Returns size of the record at the current position. The
1604 * \a attr can be used to specify only the parts of the record
1605 * needed to be returned. (see LUDA_* definitions for the
1608 * \param[in] env execution environment for this thread
1609 * \param[in] di iterator
1610 * \param[in] attr part of the record to return
1612 * \retval record's size on success
1613 * \retval negative negated errno on error
1615 int (*rec_size)(const struct lu_env *env,
1616 const struct dt_it *di,
1620 * Return a cookie (hash).
1622 * Returns the cookie (usually hash) of the key at the current
1623 * position. This allows the caller to resume iteration at this
1624 * position later. The exact value is specific to implementation
1625 * and should not be interpreted by the caller.
1627 * \param[in] env execution environment for this thread
1628 * \param[in] di iterator
1630 * \retval cookie/hash of the key
1632 __u64 (*store)(const struct lu_env *env,
1633 const struct dt_it *di);
1636 * Initialize position using cookie/hash.
1638 * Initializes the current position of the iterator to one
1639 * described by the cookie/hash as returned by ->store()
1642 * \param[in] env execution environment for this thread
1643 * \param[in] di iterator
1644 * \param[in] hash cookie/hash value
1646 * \retval positive if current position points to
1647 * record with least cookie not larger
1649 * \retval 0 if current position matches cookie
1650 * \retval negative negated errno on error
1652 int (*load)(const struct lu_env *env,
1653 const struct dt_it *di,
1659 int (*key_rec)(const struct lu_env *env,
1660 const struct dt_it *di,
1665 enum dt_otable_it_valid {
1666 DOIV_ERROR_HANDLE = 0x0001,
1667 DOIV_DRYRUN = 0x0002,
1670 enum dt_otable_it_flags {
1671 /* Exit when fail. */
1672 DOIF_FAILOUT = 0x0001,
1674 /* Reset iteration position to the device beginning. */
1675 DOIF_RESET = 0x0002,
1677 /* There is up layer component uses the iteration. */
1678 DOIF_OUTUSED = 0x0004,
1680 /* Check only without repairing. */
1681 DOIF_DRYRUN = 0x0008,
1684 /* otable based iteration needs to use the common DT iteration APIs.
1685 * To initialize the iteration, it needs call dio_it::init() firstly.
1686 * Here is how the otable based iteration should prepare arguments to
1687 * call dt_it_ops::init().
1689 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1690 * is composed of two parts:
1691 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1692 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1693 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1696 struct lu_device dd_lu_dev;
1697 const struct dt_device_operations *dd_ops;
1700 * List of dt_txn_callback (see below). This is not protected in any
1701 * way, because callbacks are supposed to be added/deleted only during
1702 * single-threaded start-up shut-down procedures.
1704 struct list_head dd_txn_callbacks;
1705 unsigned int dd_record_fid_accessed:1;
1708 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1709 void dt_device_fini(struct dt_device *dev);
1711 static inline int lu_device_is_dt(const struct lu_device *d)
1713 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1716 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1718 LASSERT(lu_device_is_dt(l));
1719 return container_of0(l, struct dt_device, dd_lu_dev);
1723 struct lu_object do_lu;
1724 const struct dt_object_operations *do_ops;
1725 const struct dt_body_operations *do_body_ops;
1726 const struct dt_index_operations *do_index_ops;
1730 * In-core representation of per-device local object OID storage
1732 struct local_oid_storage {
1733 /* all initialized llog systems on this node linked by this */
1734 struct list_head los_list;
1736 /* how many handle's reference this los has */
1737 atomic_t los_refcount;
1738 struct dt_device *los_dev;
1739 struct dt_object *los_obj;
1741 /* data used to generate new fids */
1742 struct mutex los_id_lock;
1747 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1749 return &d->dd_lu_dev;
1752 static inline struct dt_object *lu2dt(struct lu_object *l)
1754 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1755 return container_of0(l, struct dt_object, do_lu);
1758 int dt_object_init(struct dt_object *obj,
1759 struct lu_object_header *h, struct lu_device *d);
1761 void dt_object_fini(struct dt_object *obj);
1763 static inline int dt_object_exists(const struct dt_object *dt)
1765 return lu_object_exists(&dt->do_lu);
1768 static inline int dt_object_remote(const struct dt_object *dt)
1770 return lu_object_remote(&dt->do_lu);
1773 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1775 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1776 return container_of0(o, struct dt_object, do_lu);
1780 * This is the general purpose transaction handle.
1781 * 1. Transaction Life Cycle
1782 * This transaction handle is allocated upon starting a new transaction,
1783 * and deallocated after this transaction is committed.
1784 * 2. Transaction Nesting
1785 * We do _NOT_ support nested transaction. So, every thread should only
1786 * have one active transaction, and a transaction only belongs to one
1787 * thread. Due to this, transaction handle need no reference count.
1788 * 3. Transaction & dt_object locking
1789 * dt_object locks should be taken inside transaction.
1790 * 4. Transaction & RPC
1791 * No RPC request should be issued inside transaction.
1794 /** the dt device on which the transactions are executed */
1795 struct dt_device *th_dev;
1797 /* In some callback function, it needs to access the top_th directly */
1798 struct thandle *th_top;
1800 /** context for this transaction, tag is LCT_TX_HANDLE */
1801 struct lu_context th_ctx;
1803 /** additional tags (layers can add in declare) */
1806 /** the last operation result in this transaction.
1807 * this value is used in recovery */
1810 /** whether we need sync commit */
1811 unsigned int th_sync:1,
1812 /* local transation, no need to inform other layers */
1817 * Transaction call-backs.
1819 * These are invoked by osd (or underlying transaction engine) when
1820 * transaction changes state.
1822 * Call-backs are used by upper layers to modify transaction parameters and to
1823 * perform some actions on for each transaction state transition. Typical
1824 * example is mdt registering call-back to write into last-received file
1825 * before each transaction commit.
1827 struct dt_txn_callback {
1828 int (*dtc_txn_start)(const struct lu_env *env,
1829 struct thandle *txn, void *cookie);
1830 int (*dtc_txn_stop)(const struct lu_env *env,
1831 struct thandle *txn, void *cookie);
1832 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1835 struct list_head dtc_linkage;
1838 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1839 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1841 int dt_txn_hook_start(const struct lu_env *env,
1842 struct dt_device *dev, struct thandle *txn);
1843 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1844 void dt_txn_hook_commit(struct thandle *txn);
1846 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1849 * Callback function used for parsing path.
1850 * \see llo_store_resolve
1852 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1856 #define DT_MAX_PATH 1024
1858 int dt_path_parser(const struct lu_env *env,
1859 char *local, dt_entry_func_t entry_func,
1863 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1864 const char *path, struct lu_fid *fid);
1866 struct dt_object *dt_store_open(const struct lu_env *env,
1867 struct dt_device *dt,
1868 const char *dirname,
1869 const char *filename,
1870 struct lu_fid *fid);
1872 struct dt_object *dt_find_or_create(const struct lu_env *env,
1873 struct dt_device *dt,
1874 const struct lu_fid *fid,
1875 struct dt_object_format *dof,
1876 struct lu_attr *attr);
1878 struct dt_object *dt_locate_at(const struct lu_env *env,
1879 struct dt_device *dev,
1880 const struct lu_fid *fid,
1881 struct lu_device *top_dev,
1882 const struct lu_object_conf *conf);
1884 static inline struct dt_object *
1885 dt_locate(const struct lu_env *env, struct dt_device *dev,
1886 const struct lu_fid *fid)
1888 return dt_locate_at(env, dev, fid,
1889 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1892 static inline struct dt_object *
1893 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1895 struct lu_object *lo;
1897 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
1898 if (lo->lo_dev == &dt_dev->dd_lu_dev)
1899 return container_of(lo, struct dt_object, do_lu);
1904 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
1905 const struct lu_fid *first_fid,
1906 struct local_oid_storage **los);
1907 void local_oid_storage_fini(const struct lu_env *env,
1908 struct local_oid_storage *los);
1909 int local_object_fid_generate(const struct lu_env *env,
1910 struct local_oid_storage *los,
1911 struct lu_fid *fid);
1912 int local_object_declare_create(const struct lu_env *env,
1913 struct local_oid_storage *los,
1914 struct dt_object *o,
1915 struct lu_attr *attr,
1916 struct dt_object_format *dof,
1917 struct thandle *th);
1918 int local_object_create(const struct lu_env *env,
1919 struct local_oid_storage *los,
1920 struct dt_object *o,
1921 struct lu_attr *attr, struct dt_object_format *dof,
1922 struct thandle *th);
1923 struct dt_object *local_file_find_or_create(const struct lu_env *env,
1924 struct local_oid_storage *los,
1925 struct dt_object *parent,
1926 const char *name, __u32 mode);
1927 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
1928 struct dt_device *dt,
1929 const struct lu_fid *fid,
1930 struct dt_object *parent,
1934 local_index_find_or_create(const struct lu_env *env,
1935 struct local_oid_storage *los,
1936 struct dt_object *parent,
1937 const char *name, __u32 mode,
1938 const struct dt_index_features *ft);
1940 local_index_find_or_create_with_fid(const struct lu_env *env,
1941 struct dt_device *dt,
1942 const struct lu_fid *fid,
1943 struct dt_object *parent,
1944 const char *name, __u32 mode,
1945 const struct dt_index_features *ft);
1946 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
1947 struct dt_object *parent, const char *name);
1949 static inline int dt_object_lock(const struct lu_env *env,
1950 struct dt_object *o, struct lustre_handle *lh,
1951 struct ldlm_enqueue_info *einfo,
1952 union ldlm_policy_data *policy)
1955 LASSERT(o->do_ops != NULL);
1956 LASSERT(o->do_ops->do_object_lock != NULL);
1957 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
1960 static inline int dt_object_unlock(const struct lu_env *env,
1961 struct dt_object *o,
1962 struct ldlm_enqueue_info *einfo,
1963 union ldlm_policy_data *policy)
1966 LASSERT(o->do_ops != NULL);
1967 LASSERT(o->do_ops->do_object_unlock != NULL);
1968 return o->do_ops->do_object_unlock(env, o, einfo, policy);
1971 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
1972 const char *name, struct lu_fid *fid);
1974 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
1975 __u64 start, __u64 end)
1979 LASSERT(o->do_ops->do_object_sync);
1980 return o->do_ops->do_object_sync(env, o, start, end);
1983 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
1984 struct thandle *th);
1985 void dt_version_set(const struct lu_env *env, struct dt_object *o,
1986 dt_obj_version_t version, struct thandle *th);
1987 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
1990 int dt_read(const struct lu_env *env, struct dt_object *dt,
1991 struct lu_buf *buf, loff_t *pos);
1992 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
1993 struct lu_buf *buf, loff_t *pos);
1994 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
1995 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
1996 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
1997 union lu_page *lp, size_t nob,
1998 const struct dt_it_ops *iops,
1999 struct dt_it *it, __u32 attr, void *arg);
2000 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2001 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2003 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2004 struct idx_info *ii, const struct lu_rdpg *rdpg);
2006 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2007 struct dt_device *d)
2009 LASSERT(d->dd_ops->dt_trans_create);
2010 return d->dd_ops->dt_trans_create(env, d);
2013 static inline int dt_trans_start(const struct lu_env *env,
2014 struct dt_device *d, struct thandle *th)
2016 LASSERT(d->dd_ops->dt_trans_start);
2017 return d->dd_ops->dt_trans_start(env, d, th);
2020 /* for this transaction hooks shouldn't be called */
2021 static inline int dt_trans_start_local(const struct lu_env *env,
2022 struct dt_device *d, struct thandle *th)
2024 LASSERT(d->dd_ops->dt_trans_start);
2026 return d->dd_ops->dt_trans_start(env, d, th);
2029 static inline int dt_trans_stop(const struct lu_env *env,
2030 struct dt_device *d, struct thandle *th)
2032 LASSERT(d->dd_ops->dt_trans_stop);
2033 return d->dd_ops->dt_trans_stop(env, d, th);
2036 static inline int dt_trans_cb_add(struct thandle *th,
2037 struct dt_txn_commit_cb *dcb)
2039 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2040 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2041 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2046 static inline int dt_declare_record_write(const struct lu_env *env,
2047 struct dt_object *dt,
2048 const struct lu_buf *buf,
2054 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2055 LASSERT(th != NULL);
2056 LASSERT(dt->do_body_ops);
2057 LASSERT(dt->do_body_ops->dbo_declare_write);
2058 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2062 static inline int dt_declare_create(const struct lu_env *env,
2063 struct dt_object *dt,
2064 struct lu_attr *attr,
2065 struct dt_allocation_hint *hint,
2066 struct dt_object_format *dof,
2070 LASSERT(dt->do_ops);
2071 LASSERT(dt->do_ops->do_declare_create);
2073 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2074 return cfs_fail_err;
2076 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2079 static inline int dt_create(const struct lu_env *env,
2080 struct dt_object *dt,
2081 struct lu_attr *attr,
2082 struct dt_allocation_hint *hint,
2083 struct dt_object_format *dof,
2087 LASSERT(dt->do_ops);
2088 LASSERT(dt->do_ops->do_create);
2090 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2091 return cfs_fail_err;
2093 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2096 static inline int dt_declare_destroy(const struct lu_env *env,
2097 struct dt_object *dt,
2101 LASSERT(dt->do_ops);
2102 LASSERT(dt->do_ops->do_declare_destroy);
2104 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2105 return cfs_fail_err;
2107 return dt->do_ops->do_declare_destroy(env, dt, th);
2110 static inline int dt_destroy(const struct lu_env *env,
2111 struct dt_object *dt,
2115 LASSERT(dt->do_ops);
2116 LASSERT(dt->do_ops->do_destroy);
2118 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2119 return cfs_fail_err;
2121 return dt->do_ops->do_destroy(env, dt, th);
2124 static inline void dt_read_lock(const struct lu_env *env,
2125 struct dt_object *dt,
2129 LASSERT(dt->do_ops);
2130 LASSERT(dt->do_ops->do_read_lock);
2131 dt->do_ops->do_read_lock(env, dt, role);
2134 static inline void dt_write_lock(const struct lu_env *env,
2135 struct dt_object *dt,
2139 LASSERT(dt->do_ops);
2140 LASSERT(dt->do_ops->do_write_lock);
2141 dt->do_ops->do_write_lock(env, dt, role);
2144 static inline void dt_read_unlock(const struct lu_env *env,
2145 struct dt_object *dt)
2148 LASSERT(dt->do_ops);
2149 LASSERT(dt->do_ops->do_read_unlock);
2150 dt->do_ops->do_read_unlock(env, dt);
2153 static inline void dt_write_unlock(const struct lu_env *env,
2154 struct dt_object *dt)
2157 LASSERT(dt->do_ops);
2158 LASSERT(dt->do_ops->do_write_unlock);
2159 dt->do_ops->do_write_unlock(env, dt);
2162 static inline int dt_write_locked(const struct lu_env *env,
2163 struct dt_object *dt)
2166 LASSERT(dt->do_ops);
2167 LASSERT(dt->do_ops->do_write_locked);
2168 return dt->do_ops->do_write_locked(env, dt);
2171 static inline int dt_declare_attr_get(const struct lu_env *env,
2172 struct dt_object *dt)
2175 LASSERT(dt->do_ops);
2176 LASSERT(dt->do_ops->do_declare_attr_get);
2178 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2179 return cfs_fail_err;
2181 return dt->do_ops->do_declare_attr_get(env, dt);
2184 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2188 LASSERT(dt->do_ops);
2189 LASSERT(dt->do_ops->do_attr_get);
2191 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2192 return cfs_fail_err;
2194 return dt->do_ops->do_attr_get(env, dt, la);
2197 static inline int dt_declare_attr_set(const struct lu_env *env,
2198 struct dt_object *dt,
2199 const struct lu_attr *la,
2203 LASSERT(dt->do_ops);
2204 LASSERT(dt->do_ops->do_declare_attr_set);
2206 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2207 return cfs_fail_err;
2209 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2212 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2213 const struct lu_attr *la, struct thandle *th)
2216 LASSERT(dt->do_ops);
2217 LASSERT(dt->do_ops->do_attr_set);
2219 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2220 return cfs_fail_err;
2222 return dt->do_ops->do_attr_set(env, dt, la, th);
2225 static inline int dt_declare_ref_add(const struct lu_env *env,
2226 struct dt_object *dt, struct thandle *th)
2229 LASSERT(dt->do_ops);
2230 LASSERT(dt->do_ops->do_declare_ref_add);
2232 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2233 return cfs_fail_err;
2235 return dt->do_ops->do_declare_ref_add(env, dt, th);
2238 static inline int dt_ref_add(const struct lu_env *env,
2239 struct dt_object *dt, struct thandle *th)
2242 LASSERT(dt->do_ops);
2243 LASSERT(dt->do_ops->do_ref_add);
2245 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2246 return cfs_fail_err;
2248 return dt->do_ops->do_ref_add(env, dt, th);
2251 static inline int dt_declare_ref_del(const struct lu_env *env,
2252 struct dt_object *dt, struct thandle *th)
2255 LASSERT(dt->do_ops);
2256 LASSERT(dt->do_ops->do_declare_ref_del);
2258 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2259 return cfs_fail_err;
2261 return dt->do_ops->do_declare_ref_del(env, dt, th);
2264 static inline int dt_ref_del(const struct lu_env *env,
2265 struct dt_object *dt, struct thandle *th)
2268 LASSERT(dt->do_ops);
2269 LASSERT(dt->do_ops->do_ref_del);
2271 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2272 return cfs_fail_err;
2274 return dt->do_ops->do_ref_del(env, dt, th);
2277 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2278 struct niobuf_remote *rnb,
2279 struct niobuf_local *lnb, int rw)
2282 LASSERT(d->do_body_ops);
2283 LASSERT(d->do_body_ops->dbo_bufs_get);
2284 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2285 rnb->rnb_len, lnb, rw);
2288 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2289 struct niobuf_local *lnb, int n)
2292 LASSERT(d->do_body_ops);
2293 LASSERT(d->do_body_ops->dbo_bufs_put);
2294 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2297 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2298 struct niobuf_local *lnb, int n)
2301 LASSERT(d->do_body_ops);
2302 LASSERT(d->do_body_ops->dbo_write_prep);
2303 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2306 static inline int dt_declare_write_commit(const struct lu_env *env,
2307 struct dt_object *d,
2308 struct niobuf_local *lnb,
2309 int n, struct thandle *th)
2311 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2312 LASSERT(th != NULL);
2313 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2317 static inline int dt_write_commit(const struct lu_env *env,
2318 struct dt_object *d, struct niobuf_local *lnb,
2319 int n, struct thandle *th)
2322 LASSERT(d->do_body_ops);
2323 LASSERT(d->do_body_ops->dbo_write_commit);
2324 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2327 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2328 struct niobuf_local *lnb, int n)
2331 LASSERT(d->do_body_ops);
2332 LASSERT(d->do_body_ops->dbo_read_prep);
2333 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2336 static inline int dt_declare_write(const struct lu_env *env,
2337 struct dt_object *dt,
2338 const struct lu_buf *buf, loff_t pos,
2342 LASSERT(dt->do_body_ops);
2343 LASSERT(dt->do_body_ops->dbo_declare_write);
2344 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2347 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2348 const struct lu_buf *buf, loff_t *pos,
2349 struct thandle *th, int rq)
2352 LASSERT(dt->do_body_ops);
2353 LASSERT(dt->do_body_ops->dbo_write);
2354 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th, rq);
2357 static inline int dt_declare_punch(const struct lu_env *env,
2358 struct dt_object *dt, __u64 start,
2359 __u64 end, struct thandle *th)
2362 LASSERT(dt->do_body_ops);
2363 LASSERT(dt->do_body_ops->dbo_declare_punch);
2364 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2367 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2368 __u64 start, __u64 end, struct thandle *th)
2371 LASSERT(dt->do_body_ops);
2372 LASSERT(dt->do_body_ops->dbo_punch);
2373 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2376 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2377 struct ll_user_fiemap *fm)
2380 if (d->do_body_ops == NULL)
2382 if (d->do_body_ops->dbo_fiemap_get == NULL)
2384 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2387 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2388 struct obd_statfs *osfs)
2391 LASSERT(dev->dd_ops);
2392 LASSERT(dev->dd_ops->dt_statfs);
2393 return dev->dd_ops->dt_statfs(env, dev, osfs);
2396 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2400 LASSERT(dev->dd_ops);
2401 LASSERT(dev->dd_ops->dt_root_get);
2402 return dev->dd_ops->dt_root_get(env, dev, f);
2405 static inline void dt_conf_get(const struct lu_env *env,
2406 const struct dt_device *dev,
2407 struct dt_device_param *param)
2410 LASSERT(dev->dd_ops);
2411 LASSERT(dev->dd_ops->dt_conf_get);
2412 return dev->dd_ops->dt_conf_get(env, dev, param);
2415 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2418 LASSERT(dev->dd_ops);
2419 LASSERT(dev->dd_ops->dt_sync);
2420 return dev->dd_ops->dt_sync(env, dev);
2423 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2426 LASSERT(dev->dd_ops);
2427 LASSERT(dev->dd_ops->dt_ro);
2428 return dev->dd_ops->dt_ro(env, dev);
2431 static inline int dt_declare_insert(const struct lu_env *env,
2432 struct dt_object *dt,
2433 const struct dt_rec *rec,
2434 const struct dt_key *key,
2438 LASSERT(dt->do_index_ops);
2439 LASSERT(dt->do_index_ops->dio_declare_insert);
2441 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2442 return cfs_fail_err;
2444 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2447 static inline int dt_insert(const struct lu_env *env,
2448 struct dt_object *dt,
2449 const struct dt_rec *rec,
2450 const struct dt_key *key,
2455 LASSERT(dt->do_index_ops);
2456 LASSERT(dt->do_index_ops->dio_insert);
2458 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2459 return cfs_fail_err;
2461 return dt->do_index_ops->dio_insert(env, dt, rec, key, th, noquota);
2464 static inline int dt_declare_xattr_del(const struct lu_env *env,
2465 struct dt_object *dt,
2470 LASSERT(dt->do_ops);
2471 LASSERT(dt->do_ops->do_declare_xattr_del);
2473 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2474 return cfs_fail_err;
2476 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2479 static inline int dt_xattr_del(const struct lu_env *env,
2480 struct dt_object *dt, const char *name,
2484 LASSERT(dt->do_ops);
2485 LASSERT(dt->do_ops->do_xattr_del);
2487 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2488 return cfs_fail_err;
2490 return dt->do_ops->do_xattr_del(env, dt, name, th);
2493 static inline int dt_declare_xattr_set(const struct lu_env *env,
2494 struct dt_object *dt,
2495 const struct lu_buf *buf,
2496 const char *name, int fl,
2500 LASSERT(dt->do_ops);
2501 LASSERT(dt->do_ops->do_declare_xattr_set);
2503 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2504 return cfs_fail_err;
2506 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2509 static inline int dt_xattr_set(const struct lu_env *env,
2510 struct dt_object *dt, const struct lu_buf *buf,
2511 const char *name, int fl, struct thandle *th)
2514 LASSERT(dt->do_ops);
2515 LASSERT(dt->do_ops->do_xattr_set);
2517 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2518 return cfs_fail_err;
2520 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2523 static inline int dt_declare_xattr_get(const struct lu_env *env,
2524 struct dt_object *dt,
2529 LASSERT(dt->do_ops);
2530 LASSERT(dt->do_ops->do_declare_xattr_get);
2532 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2533 return cfs_fail_err;
2535 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2538 static inline int dt_xattr_get(const struct lu_env *env,
2539 struct dt_object *dt, struct lu_buf *buf,
2543 LASSERT(dt->do_ops);
2544 LASSERT(dt->do_ops->do_xattr_get);
2546 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2547 return cfs_fail_err;
2549 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2552 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2553 const struct lu_buf *buf)
2556 LASSERT(dt->do_ops);
2557 LASSERT(dt->do_ops->do_xattr_list);
2559 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2560 return cfs_fail_err;
2562 return dt->do_ops->do_xattr_list(env, dt, buf);
2565 static inline int dt_declare_delete(const struct lu_env *env,
2566 struct dt_object *dt,
2567 const struct dt_key *key,
2571 LASSERT(dt->do_index_ops);
2572 LASSERT(dt->do_index_ops->dio_declare_delete);
2574 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2575 return cfs_fail_err;
2577 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2580 static inline int dt_delete(const struct lu_env *env,
2581 struct dt_object *dt,
2582 const struct dt_key *key,
2586 LASSERT(dt->do_index_ops);
2587 LASSERT(dt->do_index_ops->dio_delete);
2589 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2590 return cfs_fail_err;
2592 return dt->do_index_ops->dio_delete(env, dt, key, th);
2595 static inline int dt_commit_async(const struct lu_env *env,
2596 struct dt_device *dev)
2599 LASSERT(dev->dd_ops);
2600 LASSERT(dev->dd_ops->dt_commit_async);
2601 return dev->dd_ops->dt_commit_async(env, dev);
2604 static inline int dt_lookup(const struct lu_env *env,
2605 struct dt_object *dt,
2607 const struct dt_key *key)
2612 LASSERT(dt->do_index_ops);
2613 LASSERT(dt->do_index_ops->dio_lookup);
2615 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2616 return cfs_fail_err;
2618 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2626 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
2628 struct dt_find_hint {
2629 struct lu_fid *dfh_fid;
2630 struct dt_device *dfh_dt;
2631 struct dt_object *dfh_o;
2634 struct dt_insert_rec {
2636 const struct lu_fid *rec_fid;
2648 struct dt_thread_info {
2649 char dti_buf[DT_MAX_PATH];
2650 struct dt_find_hint dti_dfh;
2651 struct lu_attr dti_attr;
2652 struct lu_fid dti_fid;
2653 struct dt_object_format dti_dof;
2654 struct lustre_mdt_attrs dti_lma;
2655 struct lu_buf dti_lb;
2656 struct lu_object_conf dti_conf;
2658 struct dt_insert_rec dti_dt_rec;
2661 extern struct lu_context_key dt_key;
2663 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2665 struct dt_thread_info *dti;
2667 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2672 int dt_global_init(void);
2673 void dt_global_fini(void);
2675 # ifdef CONFIG_PROC_FS
2676 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2677 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2678 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2679 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2680 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2681 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2682 # endif /* CONFIG_PROC_FS */
2684 #endif /* __LUSTRE_DT_OBJECT_H */