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, 2013, 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 * Not used, subject to removal.
311 int (*dt_init_capa_ctxt)(const struct lu_env *env,
312 struct dt_device *dev,
314 unsigned long timeout,
316 struct lustre_capa_key *keys);
319 struct dt_index_features {
320 /** required feature flags from enum dt_index_flags */
322 /** minimal required key size */
323 size_t dif_keysize_min;
324 /** maximal required key size, 0 if no limit */
325 size_t dif_keysize_max;
326 /** minimal required record size */
327 size_t dif_recsize_min;
328 /** maximal required record size, 0 if no limit */
329 size_t dif_recsize_max;
330 /** pointer size for record */
334 enum dt_index_flags {
335 /** index supports variable sized keys */
336 DT_IND_VARKEY = 1 << 0,
337 /** index supports variable sized records */
338 DT_IND_VARREC = 1 << 1,
339 /** index can be modified */
340 DT_IND_UPDATE = 1 << 2,
341 /** index supports records with non-unique (duplicate) keys */
342 DT_IND_NONUNQ = 1 << 3,
344 * index support fixed-size keys sorted with natural numerical way
345 * and is able to return left-side value if no exact value found
347 DT_IND_RANGE = 1 << 4,
351 * Features, required from index to support file system directories (mapping
354 extern const struct dt_index_features dt_directory_features;
355 extern const struct dt_index_features dt_otable_features;
356 extern const struct dt_index_features dt_lfsck_orphan_features;
357 extern const struct dt_index_features dt_lfsck_features;
359 /* index features supported by the accounting objects */
360 extern const struct dt_index_features dt_acct_features;
362 /* index features supported by the quota global indexes */
363 extern const struct dt_index_features dt_quota_glb_features;
365 /* index features supported by the quota slave indexes */
366 extern const struct dt_index_features dt_quota_slv_features;
369 * This is a general purpose dt allocation hint.
370 * It now contains the parent object.
371 * It can contain any allocation hint in the future.
373 struct dt_allocation_hint {
374 struct dt_object *dah_parent;
375 const void *dah_eadata;
381 * object type specifier.
384 enum dt_format_type {
389 /** for special index */
391 /** for symbolic link */
396 * object format specifier.
398 struct dt_object_format {
399 /** type for dt object */
400 enum dt_format_type dof_type;
410 * special index need feature as parameter to create
414 const struct dt_index_features *di_feat;
419 enum dt_format_type dt_mode_to_dft(__u32 mode);
421 typedef __u64 dt_obj_version_t;
423 union ldlm_policy_data;
426 * A dt_object provides common operations to create and destroy
427 * objects and to manage regular and extended attributes.
429 struct dt_object_operations {
431 * Get read lock on object.
433 * Read lock is compatible with other read locks, so it's shared.
434 * Read lock is not compatible with write lock which is exclusive.
435 * The lock is blocking and can't be used from an interrupt context.
437 * \param[in] env execution environment for this thread
438 * \param[in] dt object to lock for reading
439 * \param[in] role a hint to debug locks (see kernel's mutexes)
441 void (*do_read_lock)(const struct lu_env *env,
442 struct dt_object *dt,
446 * Get write lock on object.
448 * Write lock is exclusive and cannot be shared. The lock is blocking
449 * and can't be used from an interrupt context.
451 * \param[in] env execution environment for this thread
452 * \param[in] dt object to lock for writing
453 * \param[in] role a hint to debug locks (see kernel's mutexes)
456 void (*do_write_lock)(const struct lu_env *env,
457 struct dt_object *dt,
463 * \param[in] env execution environment for this thread
464 * \param[in] dt object
466 void (*do_read_unlock)(const struct lu_env *env,
467 struct dt_object *dt);
470 * Release write lock.
472 * \param[in] env execution environment for this thread
473 * \param[in] dt object
475 void (*do_write_unlock)(const struct lu_env *env,
476 struct dt_object *dt);
479 * Check whether write lock is held.
481 * The caller can learn whether write lock is held on the object
483 * \param[in] env execution environment for this thread
484 * \param[in] dt object
486 * \retval 0 no write lock
487 * \retval 1 write lock is held
489 int (*do_write_locked)(const struct lu_env *env,
490 struct dt_object *dt);
493 * Declare intention to request reqular attributes.
495 * Notity the underlying filesystem that the caller may request regular
496 * attributes with ->do_attr_get() soon. This allows OSD to implement
497 * prefetching logic in an object-oriented manner. The implementation
498 * can be noop. This method should avoid expensive delays such as
499 * waiting on disk I/O, otherwise the goal of enabling a performance
500 * optimization would be defeated.
502 * \param[in] env execution environment for this thread
503 * \param[in] dt object
504 * \param[in] capa unused
506 * \retval 0 on success
507 * \retval negative negated errno on error
509 int (*do_declare_attr_get)(const struct lu_env *env,
510 struct dt_object *dt,
511 struct lustre_capa *capa);
514 * Return regular attributes.
516 * The object must exist. Currently all the attributes should be
517 * returned, but in the future this can be improved so that only
518 * a selected set is returned. This can improve performance as in
519 * some cases attributes are stored in different places and
520 * getting them all can be an iterative and expensive process.
522 * \param[in] env execution environment for this thread
523 * \param[in] dt object
524 * \param[out] attr attributes to fill
525 * \param[in] capa unused
527 * \retval 0 on success
528 * \retval negative negated errno on error
530 int (*do_attr_get)(const struct lu_env *env,
531 struct dt_object *dt,
532 struct lu_attr *attr,
533 struct lustre_capa *capa);
536 * Declare intention to change regular object's attributes.
538 * Notify the underlying filesystem that the regular attributes may
539 * change in this transaction. This enables the layer below to prepare
540 * resources (e.g. journal credits in ext4). This method should be
541 * called between creating the transaction and starting it. Note that
542 * the la_valid field of \a attr specifies which attributes will change.
543 * The object need not exist.
545 * \param[in] env execution environment for this thread
546 * \param[in] dt object
547 * \param[in] attr attributes to change specified in attr.la_valid
548 * \param[in] th transaction handle
550 * \retval 0 on success
551 * \retval negative negated errno on error
553 int (*do_declare_attr_set)(const struct lu_env *env,
554 struct dt_object *dt,
555 const struct lu_attr *attr,
559 * Change regular attributes.
561 * Change regular attributes in the given transaction. Note only
562 * attributes flagged by attr.la_valid change. The object must
563 * exist. If the layer implementing this method is responsible for
564 * quota, then the method should maintain object accounting for the
565 * given credentials when la_uid/la_gid changes.
567 * \param[in] env execution environment for this thread
568 * \param[in] dt object
569 * \param[in] attr new attributes to apply
570 * \param[in] th transaction handle
571 * \param[in] capa unused
573 * \retval 0 on success
574 * \retval negative negated errno on error
576 int (*do_attr_set)(const struct lu_env *env,
577 struct dt_object *dt,
578 const struct lu_attr *attr,
580 struct lustre_capa *capa);
583 * Declare intention to request extented attribute.
585 * Notify the underlying filesystem that the caller may request extended
586 * attribute with ->do_xattr_get() soon. This allows OSD to implement
587 * prefetching logic in an object-oriented manner. The implementation
588 * can be noop. This method should avoid expensive delays such as
589 * waiting on disk I/O, otherwise the goal of enabling a performance
590 * optimization would be defeated.
592 * \param[in] env execution environment for this thread
593 * \param[in] dt object
594 * \param[in] buf unused, may be removed in the future
595 * \param[in] name name of the extended attribute
596 * \param[in] capa unused, may be removed in the future
598 * \retval 0 on success
599 * \retval negative negated errno on error
601 int (*do_declare_xattr_get)(const struct lu_env *env,
602 struct dt_object *dt,
605 struct lustre_capa *capa);
608 * Return a value of an extended attribute.
610 * The object must exist. If the buffer is NULL, then the method
611 * must return the size of the value.
613 * \param[in] env execution environment for this thread
614 * \param[in] dt object
615 * \param[out] buf buffer in which to store the value
616 * \param[in] name name of the extended attribute
617 * \param[in] capa unused
619 * \retval 0 on success
620 * \retval -ERANGE if \a buf is too small
621 * \retval negative negated errno on error
622 * \retval positive value's size if \a buf is NULL or has zero size
624 int (*do_xattr_get)(const struct lu_env *env,
625 struct dt_object *dt,
628 struct lustre_capa *capa);
631 * Declare intention to change an extended attribute.
633 * Notify the underlying filesystem that the extended attribute may
634 * change in this transaction. This enables the layer below to prepare
635 * resources (e.g. journal credits in ext4). This method should be
636 * called between creating the transaction and starting it. The object
639 * \param[in] env execution environment for this thread
640 * \param[in] dt object
641 * \param[in] buf buffer storing new value of the attribute
642 * \param[in] name name of the attribute
643 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
644 * LU_XATTR_REPLACE - fail if EA doesn't exist
645 * \param[in] th transaction handle
647 * \retval 0 on success
648 * \retval negative negated errno on error
650 int (*do_declare_xattr_set)(const struct lu_env *env,
651 struct dt_object *dt,
652 const struct lu_buf *buf,
658 * Set an extended attribute.
660 * Change or replace the specified extended attribute (EA).
661 * The flags passed in \a fl dictate whether the EA is to be
662 * created or replaced, as follows.
663 * LU_XATTR_CREATE - fail if EA exists
664 * LU_XATTR_REPLACE - fail if EA doesn't exist
665 * The object must exist.
667 * \param[in] env execution environment for this thread
668 * \param[in] dt object
669 * \param[in] buf buffer storing new value of the attribute
670 * \param[in] name name of the attribute
671 * \param[in] fl flags indicating EA creation or replacement
672 * \param[in] th transaction handle
673 * \param[in] capa unused
675 * \retval 0 on success
676 * \retval negative negated errno on error
678 int (*do_xattr_set)(const struct lu_env *env,
679 struct dt_object *dt,
680 const struct lu_buf *buf,
684 struct lustre_capa *capa);
687 * Declare intention to delete an extended attribute.
689 * Notify the underlying filesystem that the extended attribute may
690 * be deleted in this transaction. This enables the layer below to
691 * prepare resources (e.g. journal credits in ext4). This method
692 * should be called between creating the transaction and starting it.
693 * The object need not exist.
695 * \param[in] env execution environment for this thread
696 * \param[in] dt object
697 * \param[in] name name of the attribute
698 * \param[in] th transaction handle
700 * \retval 0 on success
701 * \retval negative negated errno on error
703 int (*do_declare_xattr_del)(const struct lu_env *env,
704 struct dt_object *dt,
709 * Delete an extended attribute.
711 * This method deletes the specified extended attribute. The object
714 * \param[in] env execution environment for this thread
715 * \param[in] dt object
716 * \param[in] name name of the attribute
717 * \param[in] th transaction handle
718 * \param[in] capa unused
720 * \retval 0 on success
721 * \retval negative negated errno on error
723 int (*do_xattr_del)(const struct lu_env *env,
724 struct dt_object *dt,
727 struct lustre_capa *capa);
730 * Return a list of the extended attributes.
732 * Fills the passed buffer with a list of the extended attributes
733 * found in the object. The names are separated with '\0'.
734 * The object must exist.
736 * \param[in] env execution environment for this thread
737 * \param[in] dt object
738 * \param[out] buf buffer to put the list in
739 * \param[in] capa unused
741 * \retval positive bytes used/required in the buffer
742 * \retval negative negated errno on error
744 int (*do_xattr_list)(const struct lu_env *env,
745 struct dt_object *dt,
747 struct lustre_capa *capa);
750 * Prepare allocation hint for a new object.
752 * This method is used by the caller to inform OSD of the parent-child
753 * relationship between two objects and enable efficient object
754 * allocation. Filled allocation hint will be passed to ->do_create()
757 * \param[in] env execution environment for this thread
758 * \param[out] ah allocation hint
759 * \param[in] parent parent object (can be NULL)
760 * \param[in] child child object
761 * \param[in] _mode type of the child object
763 void (*do_ah_init)(const struct lu_env *env,
764 struct dt_allocation_hint *ah,
765 struct dt_object *parent,
766 struct dt_object *child,
770 * Declare intention to create a new object.
772 * Notify the underlying filesystem that the object may be created
773 * in this transaction. This enables the layer below to prepare
774 * resources (e.g. journal credits in ext4). This method should be
775 * called between creating the transaction and starting it.
777 * If the layer implementing this method is responsible for quota,
778 * then the method should reserve an object for the given credentials
779 * and return an error if quota is over. If object creation later
780 * fails for some reason, then the reservation should be released
781 * properly (usually in ->dt_trans_stop()).
783 * \param[in] env execution environment for this thread
784 * \param[in] dt object
785 * \param[in] attr attributes of the new object
786 * \param[in] hint allocation hint
787 * \param[in] dof object format
788 * \param[in] th transaction handle
790 * \retval 0 on success
791 * \retval negative negated errno on error
793 int (*do_declare_create)(const struct lu_env *env,
794 struct dt_object *dt,
795 struct lu_attr *attr,
796 struct dt_allocation_hint *hint,
797 struct dt_object_format *dof,
803 * The method creates the object passed with the specified attributes
804 * and object format. Object allocation procedure can use information
805 * stored in the allocation hint. Different object formats are supported
806 * (see enum dt_format_type and struct dt_object_format) depending on
807 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
808 * in the LU-object header attributes.
810 * If the layer implementing this method is responsible for quota,
811 * then the method should maintain object accounting for the given
814 * \param[in] env execution environment for this thread
815 * \param[in] dt object
816 * \param[in] attr attributes of the new object
817 * \param[in] hint allocation hint
818 * \param[in] dof object format
819 * \param[in] th transaction handle
821 * \retval 0 on success
822 * \retval negative negated errno on error
824 int (*do_create)(const struct lu_env *env,
825 struct dt_object *dt,
826 struct lu_attr *attr,
827 struct dt_allocation_hint *hint,
828 struct dt_object_format *dof,
832 * Declare intention to destroy an object.
834 * Notify the underlying filesystem that the object may be destroyed
835 * in this transaction. This enables the layer below to prepare
836 * resources (e.g. journal credits in ext4). This method should be
837 * called between creating the transaction and starting it. The object
840 * \param[in] env execution environment for this thread
841 * \param[in] dt object
842 * \param[in] th transaction handle
844 * \retval 0 on success
845 * \retval negative negated errno on error
847 int (*do_declare_destroy)(const struct lu_env *env,
848 struct dt_object *dt,
854 * This method destroys the object and all the resources associated
855 * with the object (data, key/value pairs, extended attributes, etc).
856 * The object must exist. If destroy is successful, then flag
857 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
858 * instance of in-core object. Any subsequent access to the same FID
859 * should get another instance with no LOHA_EXIST flag set.
861 * If the layer implementing this method is responsible for quota,
862 * then the method should maintain object accounting for the given
865 * \param[in] env execution environment for this thread
866 * \param[in] dt object
867 * \param[in] th transaction handle
869 * \retval 0 on success
870 * \retval negative negated errno on error
872 int (*do_destroy)(const struct lu_env *env,
873 struct dt_object *dt,
877 * Try object as an index.
879 * Announce that this object is going to be used as an index. This
880 * operation checks that object supports indexing operations and
881 * installs appropriate dt_index_operations vector on success.
882 * Also probes for features. Operation is successful if all required
883 * features are supported. It's not possible to access the object
884 * with index methods before ->do_index_try() returns success.
886 * \param[in] env execution environment for this thread
887 * \param[in] dt object
888 * \param[in] feat index features
890 * \retval 0 on success
891 * \retval negative negated errno on error
893 int (*do_index_try)(const struct lu_env *env,
894 struct dt_object *dt,
895 const struct dt_index_features *feat);
898 * Declare intention to increment nlink count.
900 * Notify the underlying filesystem that the nlink regular attribute
901 * be changed in this transaction. This enables the layer below to
902 * prepare resources (e.g. journal credits in ext4). This method
903 * should be called between creating the transaction and starting it.
904 * The object need not exist.
906 * \param[in] env execution environment for this thread
907 * \param[in] dt object
908 * \param[in] th transaction handle
910 * \retval 0 on success
911 * \retval negative negated errno on error
913 int (*do_declare_ref_add)(const struct lu_env *env,
914 struct dt_object *dt,
920 * Increment nlink (from the regular attributes set) in the given
921 * transaction. Note the absolute limit for nlink should be learnt
922 * from struct dt_device_param::ddp_max_nlink. The object must exist.
924 * \param[in] env execution environment for this thread
925 * \param[in] dt object
926 * \param[in] th transaction handle
928 * \retval 0 on success
929 * \retval negative negated errno on error
931 int (*do_ref_add)(const struct lu_env *env,
932 struct dt_object *dt, struct thandle *th);
935 * Declare intention to decrement nlink count.
937 * Notify the underlying filesystem that the nlink regular attribute
938 * be changed in this transaction. This enables the layer below to
939 * prepare resources (e.g. journal credits in ext4). This method
940 * should be called between creating the transaction and starting it.
941 * The object need not exist.
943 * \param[in] env execution environment for this thread
944 * \param[in] dt object
945 * \param[in] th transaction handle
947 * \retval 0 on success
948 * \retval negative negated errno on error
950 int (*do_declare_ref_del)(const struct lu_env *env,
951 struct dt_object *dt,
957 * Decrement nlink (from the regular attributes set) in the given
958 * transaction. The object must exist.
960 * \param[in] env execution environment for this thread
961 * \param[in] dt object
962 * \param[in] th transaction handle
964 * \retval 0 on success
965 * \retval negative negated errno on error
967 int (*do_ref_del)(const struct lu_env *env,
968 struct dt_object *dt,
972 * Not used, subject to removal.
974 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
975 struct dt_object *dt,
976 struct lustre_capa *old,
982 * The method is called to sync specified range of the object to a
983 * persistent storage. The control is returned once the operation is
984 * complete. The difference from ->do_sync() is that the object can
985 * be in-sync with the persistent storage (nothing to flush), then
986 * the method returns quickly with no I/O overhead. So, this method
987 * should be preferred over ->do_sync() where possible. Also note that
988 * if the object isn't clean, then some disk filesystems will call
989 * ->do_sync() to maintain overall consistency, in which case it's
990 * still very expensive.
992 * \param[in] env execution environment for this thread
993 * \param[in] dt object
994 * \param[in] start start of the range to sync
995 * \param[in] end end of the range to sync
997 * \retval 0 on success
998 * \retval negative negated errno on error
1000 int (*do_object_sync)(const struct lu_env *env,
1001 struct dt_object *obj,
1006 * Not used, subject to removal.
1008 int (*do_data_get)(const struct lu_env *env,
1009 struct dt_object *dt,
1015 * Lock object(s) using Distributed Lock Manager (LDLM).
1017 * Get LDLM locks for the object. Currently used to lock "remote"
1018 * objects in DNE configuration - a service running on MDTx needs
1019 * to lock an object on MDTy.
1021 * \param[in] env execution environment for this thread
1022 * \param[in] dt object
1023 * \param[out] lh lock handle, sometimes used, sometimes not
1024 * \param[in] einfo ldlm callbacks, locking type and mode
1025 * \param[out] einfo private data to be passed to unlock later
1026 * \param[in] policy inodebits data
1028 * \retval 0 on success
1029 * \retval negative negated errno on error
1031 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1032 struct lustre_handle *lh,
1033 struct ldlm_enqueue_info *einfo,
1034 union ldlm_policy_data *policy);
1039 * Release LDLM lock(s) granted with ->do_object_lock().
1041 * \param[in] env execution environment for this thread
1042 * \param[in] dt object
1043 * \param[in] einfo lock handles, from ->do_object_lock()
1044 * \param[in] policy inodebits data
1046 * \retval 0 on success
1047 * \retval negative negated errno on error
1049 int (*do_object_unlock)(const struct lu_env *env,
1050 struct dt_object *dt,
1051 struct ldlm_enqueue_info *einfo,
1052 union ldlm_policy_data *policy);
1056 * Per-dt-object operations on "file body" - unstructure raw data.
1058 struct dt_body_operations {
1062 * Read unstructured data from an existing regular object.
1063 * Only data before attr.la_size is returned.
1065 * \param[in] env execution environment for this thread
1066 * \param[in] dt object
1067 * \param[out] buf buffer (including size) to copy data in
1068 * \param[in] pos position in the object to start
1069 * \param[out] pos original value of \a pos + bytes returned
1070 * \param[in] capa unused
1072 * \retval positive bytes read on success
1073 * \retval negative negated errno on error
1075 ssize_t (*dbo_read)(const struct lu_env *env,
1076 struct dt_object *dt,
1079 struct lustre_capa *capa);
1082 * Declare intention to write data to object.
1084 * Notify the underlying filesystem that data may be written in
1085 * this transaction. This enables the layer below to prepare resources
1086 * (e.g. journal credits in ext4). This method should be called
1087 * between creating the transaction and starting it. The object need
1088 * not exist. If the layer implementing this method is responsible for
1089 * quota, then the method should reserve space for the given credentials
1090 * and return an error if quota is over. If the write later fails
1091 * for some reason, then the reserve should be released properly
1092 * (usually in ->dt_trans_stop()).
1094 * \param[in] env execution environment for this thread
1095 * \param[in] dt object
1096 * \param[in] buf buffer (including size) to copy data from
1097 * \param[in] pos position in the object to start
1098 * \param[in] th transaction handle
1100 * \retval 0 on success
1101 * \retval negative negated errno on error
1103 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1104 struct dt_object *dt,
1105 const struct lu_buf *buf,
1107 struct thandle *th);
1110 * Write unstructured data to regular existing object.
1112 * The method allocates space and puts data in. Also, the method should
1113 * maintain attr.la_size properly. Partial writes are possible.
1115 * If the layer implementing this method is responsible for quota,
1116 * then the method should maintain space accounting for the given
1119 * \param[in] env execution environment for this thread
1120 * \param[in] dt object
1121 * \param[in] buf buffer (including size) to copy data from
1122 * \param[in] pos position in the object to start
1123 * \param[out] pos \a pos + bytes written
1124 * \param[in] th transaction handle
1125 * \param[in] capa unused
1126 * \param[in] ignore unused (was used to request quota ignorance)
1128 * \retval positive bytes written on success
1129 * \retval negative negated errno on error
1131 ssize_t (*dbo_write)(const struct lu_env *env,
1132 struct dt_object *dt,
1133 const struct lu_buf *buf,
1136 struct lustre_capa *capa,
1140 * Return buffers for data.
1142 * This method is used to access data with no copying. It's so-called
1143 * zero-copy I/O. The method returns the descriptors for the internal
1144 * buffers where data are managed by the disk filesystem. For example,
1145 * pagecache in case of ext4 or ARC with ZFS. Then other components
1146 * (e.g. networking) can transfer data from or to the buffers with no
1147 * additional copying.
1149 * The method should fill an array of struct niobuf_local, where
1150 * each element describes a full or partial page for data at specific
1151 * offset. The caller should use page/lnb_page_offset/len to find data
1152 * at object's offset lnb_file_offset.
1154 * The memory referenced by the descriptors can't change its purpose
1155 * until the complimentary ->dbo_bufs_put() is called. The caller should
1156 * specify if the buffers are used to read or modify data so that OSD
1157 * can decide how to initialize the buffers: bring all the data for
1158 * reads or just bring partial buffers for write. Note: the method does
1159 * not check whether output array is large enough.
1161 * \param[in] env execution environment for this thread
1162 * \param[in] dt object
1163 * \param[in] pos position in the object to start
1164 * \param[in] len size of region in bytes
1165 * \param[out] lb array of descriptors to fill
1166 * \param[in] rw 0 if used to read, 1 if used for write
1167 * \param[in] capa unused
1169 * \retval positive number of descriptors on success
1170 * \retval negative negated errno on error
1172 int (*dbo_bufs_get)(const struct lu_env *env,
1173 struct dt_object *dt,
1176 struct niobuf_local *lb,
1178 struct lustre_capa *capa);
1181 * Release reference granted by ->dbo_bufs_get().
1183 * Release the reference granted by the previous ->dbo_bufs_get().
1184 * Note the references are counted.
1186 * \param[in] env execution environment for this thread
1187 * \param[in] dt object
1188 * \param[out] lb array of descriptors to fill
1189 * \param[in] nr size of the array
1191 * \retval 0 on success
1192 * \retval negative negated errno on error
1194 int (*dbo_bufs_put)(const struct lu_env *env,
1195 struct dt_object *dt,
1196 struct niobuf_local *lb,
1200 * Prepare buffers for reading.
1202 * The method is called on the given buffers to fill them with data
1203 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1204 * caller should be able to get few buffers for discontiguous regions
1205 * using few calls to ->dbo_bufs_get() and then request them all for
1206 * the preparation with a single call, so that OSD can fire many I/Os
1207 * to run concurrently. It's up to the specific OSD whether to implement
1208 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1209 * prepare data for every requested region individually.
1211 * \param[in] env execution environment for this thread
1212 * \param[in] dt object
1213 * \param[in] lnb array of buffer descriptors
1214 * \param[in] nr size of the array
1216 * \retval 0 on success
1217 * \retval negative negated errno on error
1219 int (*dbo_read_prep)(const struct lu_env *env,
1220 struct dt_object *dt,
1221 struct niobuf_local *lnb,
1225 * Prepare buffers for write.
1227 * This method is called on the given buffers to ensure the partial
1228 * buffers contain correct data. The underlying idea is the same as
1229 * in ->db_read_prep().
1231 * \param[in] env execution environment for this thread
1232 * \param[in] dt object
1233 * \param[in] lb array of buffer descriptors
1234 * \param[in] nr size of the array
1236 * \retval 0 on success
1237 * \retval negative negated errno on error
1239 int (*dbo_write_prep)(const struct lu_env *env,
1240 struct dt_object *dt,
1241 struct niobuf_local *lb,
1245 * Declare intention to write data stored in the buffers.
1247 * Notify the underlying filesystem that data may be written in
1248 * this transaction. This enables the layer below to prepare resources
1249 * (e.g. journal credits in ext4). This method should be called
1250 * between creating the transaction and starting it.
1252 * If the layer implementing this method is responsible for quota,
1253 * then the method should be reserving a space for the given
1254 * credentials and return an error if quota is exceeded. If the write
1255 * later fails for some reason, then the reserve should be released
1256 * properly (usually in ->dt_trans_stop()).
1258 * \param[in] env execution environment for this thread
1259 * \param[in] dt object
1260 * \param[in] lb array of descriptors
1261 * \param[in] nr size of the array
1262 * \param[in] th transaction handle
1264 * \retval 0 on success
1265 * \retval negative negated errno on error
1267 int (*dbo_declare_write_commit)(const struct lu_env *env,
1268 struct dt_object *dt,
1269 struct niobuf_local *lb,
1271 struct thandle *th);
1274 * Write to existing object.
1276 * This method is used to write data to a persistent storage using
1277 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1278 * data into the buffers using own mechanisms (e.g. direct transfer
1279 * from a NIC). The method should maintain attr.la_size. Also,
1280 * attr.la_blocks should be maintained but this can be done in lazy
1281 * manner, when actual allocation happens.
1283 * If the layer implementing this method is responsible for quota,
1284 * then the method should maintain space accounting for the given
1287 * \param[in] env execution environment for this thread
1288 * \param[in] dt object
1289 * \param[in] lb array of descriptors for the buffers
1290 * \param[in] nr size of the array
1291 * \param[in] th transaction handle
1293 * \retval 0 on success
1294 * \retval negative negated errno on error
1296 int (*dbo_write_commit)(const struct lu_env *env,
1297 struct dt_object *dt,
1298 struct niobuf_local *lb,
1300 struct thandle *th);
1303 * Return logical to physical block mapping for a given extent
1305 * \param[in] env execution environment for this thread
1306 * \param[in] dt object
1307 * \param[in] fm describe the region to map and the output buffer
1308 * see the details in include/linux/fiemap.h
1310 * \retval 0 on success
1311 * \retval negative negated errno on error
1313 int (*dbo_fiemap_get)(const struct lu_env *env,
1314 struct dt_object *dt,
1315 struct ll_user_fiemap *fm);
1318 * Declare intention to deallocate space from an object.
1320 * Notify the underlying filesystem that space may be deallocated in
1321 * this transactions. This enables the layer below to prepare resources
1322 * (e.g. journal credits in ext4). This method should be called between
1323 * creating the transaction and starting it. The object need not exist.
1325 * \param[in] env execution environment for this thread
1326 * \param[in] dt object
1327 * \param[in] start the start of the region to deallocate
1328 * \param[in] end the end of the region to deallocate
1329 * \param[in] th transaction handle
1331 * \retval 0 on success
1332 * \retval negative negated errno on error
1334 int (*dbo_declare_punch)(const struct lu_env *env,
1335 struct dt_object *dt,
1338 struct thandle *th);
1341 * Deallocate specified region in an object.
1343 * This method is used to deallocate (release) space possibly consumed
1344 * by the given region of the object. If the layer implementing this
1345 * method is responsible for quota, then the method should maintain
1346 * space accounting for the given credentials.
1348 * \param[in] env execution environment for this thread
1349 * \param[in] dt object
1350 * \param[in] start the start of the region to deallocate
1351 * \param[in] end the end of the region to deallocate
1352 * \param[in] th transaction handle
1353 * \param[in] capa unused
1355 * \retval 0 on success
1356 * \retval negative negated errno on error
1358 int (*dbo_punch)(const struct lu_env *env,
1359 struct dt_object *dt,
1363 struct lustre_capa *capa);
1367 * Incomplete type of index record.
1372 * Incomplete type of index key.
1377 * Incomplete type of dt iterator.
1382 * Per-dt-object operations on object as index. Index is a set of key/value
1383 * pairs abstracted from an on-disk representation. An index supports the
1384 * number of operations including lookup by key, insert and delete. Also,
1385 * an index can be iterated to find the pairs one by one, from a beginning
1386 * or specified point.
1388 struct dt_index_operations {
1390 * Lookup in an index by key.
1392 * The method returns a value for the given key. Key/value format
1393 * and size should have been negotiated with ->do_index_try() before.
1394 * Thus it's the caller's responsibility to provide the method with
1395 * proper key and big enough buffer. No external locking is required,
1396 * all the internal consistency should be implemented by the method
1397 * or lower layers. The object should should have been created with
1398 * type DFT_INDEX or DFT_DIR.
1400 * \param[in] env execution environment for this thread
1401 * \param[in] dt object
1402 * \param[out] rec buffer where value will be stored
1403 * \param[in] key key
1404 * \param[in] capa unused
1406 * \retval 0 on success
1407 * \retval -ENOENT if key isn't found
1408 * \retval negative negated errno on error
1410 int (*dio_lookup)(const struct lu_env *env,
1411 struct dt_object *dt,
1413 const struct dt_key *key,
1414 struct lustre_capa *capa);
1417 * Declare intention to insert a key/value into an index.
1419 * Notify the underlying filesystem that new key/value may be inserted
1420 * in this transaction. This enables the layer below to prepare
1421 * resources (e.g. journal credits in ext4). This method should be
1422 * called between creating the transaction and starting it. key/value
1423 * format and size is subject to ->do_index_try().
1425 * \param[in] env execution environment for this thread
1426 * \param[in] dt object
1427 * \param[in] rec buffer storing value
1428 * \param[in] key key
1429 * \param[in] th transaction handle
1431 * \retval 0 on success
1432 * \retval negative negated errno on error
1434 int (*dio_declare_insert)(const struct lu_env *env,
1435 struct dt_object *dt,
1436 const struct dt_rec *rec,
1437 const struct dt_key *key,
1438 struct thandle *th);
1441 * Insert a new key/value pair into an index.
1443 * The method inserts specified key/value pair into the given index
1444 * object. The internal consistency is maintained by the method or
1445 * the functionality below. The format and size of key/value should
1446 * have been negotiated before using ->do_index_try(), no additional
1447 * information can be specified to the method. The keys are unique
1450 * \param[in] env execution environment for this thread
1451 * \param[in] dt object
1452 * \param[in] rec buffer storing value
1453 * \param[in] key key
1454 * \param[in] th transaction handle
1455 * \param[in] capa unused
1456 * \param[in] ignore unused (was used to request quota ignorance)
1458 * \retval 0 on success
1459 * \retval negative negated errno on error
1461 int (*dio_insert)(const struct lu_env *env,
1462 struct dt_object *dt,
1463 const struct dt_rec *rec,
1464 const struct dt_key *key,
1466 struct lustre_capa *capa,
1470 * Declare intention to delete a key/value from an index.
1472 * Notify the underlying filesystem that key/value may be deleted in
1473 * this transaction. This enables the layer below to prepare resources
1474 * (e.g. journal credits in ext4). This method should be called
1475 * between creating the transaction and starting it. Key/value format
1476 * and size is subject to ->do_index_try(). The object need not exist.
1478 * \param[in] env execution environment for this thread
1479 * \param[in] dt object
1480 * \param[in] key key
1481 * \param[in] th transaction handle
1483 * \retval 0 on success
1484 * \retval negative negated errno on error
1486 int (*dio_declare_delete)(const struct lu_env *env,
1487 struct dt_object *dt,
1488 const struct dt_key *key,
1489 struct thandle *th);
1492 * Delete key/value pair from an index.
1494 * The method deletes specified key and corresponding value from the
1495 * given index object. The internal consistency is maintained by the
1496 * method or the functionality below. The format and size of the key
1497 * should have been negotiated before using ->do_index_try(), no
1498 * additional information can be specified to the method.
1500 * \param[in] env execution environment for this thread
1501 * \param[in] dt object
1502 * \param[in] key key
1503 * \param[in] th transaction handle
1504 * \param[in] capa unused
1506 * \retval 0 on success
1507 * \retval negative negated errno on error
1509 int (*dio_delete)(const struct lu_env *env,
1510 struct dt_object *dt,
1511 const struct dt_key *key,
1513 struct lustre_capa *capa);
1516 * Iterator interface.
1518 * Methods to iterate over an existing index, list the keys stored and
1519 * associated values, get key/value size, etc.
1523 * Allocate and initialize new iterator.
1525 * The iterator is a handler to be used in the subsequent
1526 * methods to access index's content. Note the position is
1527 * not defined at this point and should be initialized with
1528 * ->get() or ->load() method.
1530 * \param[in] env execution environment for this thread
1531 * \param[in] dt object
1532 * \param[in] attr ask the iterator to return part of
1533 the records, see LUDA_* for details
1534 * \param[in] capa unused
1536 * \retval pointer iterator pointer on success
1537 * \retval ERR_PTR(errno) on error
1539 struct dt_it *(*init)(const struct lu_env *env,
1540 struct dt_object *dt,
1542 struct lustre_capa *capa);
1547 * Release the specified iterator and all the resources
1548 * associated (e.g. the object, index cache, etc).
1550 * \param[in] env execution environment for this thread
1551 * \param[in] di iterator to release
1553 void (*fini)(const struct lu_env *env,
1557 * Move position of iterator.
1559 * Move the position of the specified iterator to the specified
1562 * \param[in] env execution environment for this thread
1563 * \param[in] di iterator
1564 * \param[in] key key to position to
1566 * \retval 0 if exact key is found
1567 * \retval 1 if at the record with least key
1568 * not larger than the key
1569 * \retval negative negated errno on error
1571 int (*get)(const struct lu_env *env,
1573 const struct dt_key *key);
1578 * Complimentary method for dt_it_ops::get() above. Some
1579 * implementation can increase a reference on the iterator in
1580 * dt_it_ops::get(). So the caller should be able to release
1581 * with dt_it_ops::put().
1583 * \param[in] env execution environment for this thread
1584 * \param[in] di iterator
1586 void (*put)(const struct lu_env *env,
1590 * Move to next record.
1592 * Moves the position of the iterator to a next record
1594 * \param[in] env execution environment for this thread
1595 * \param[in] di iterator
1597 * \retval 1 if no more records
1598 * \retval 0 on success, the next record is found
1599 * \retval negative negated errno on error
1601 int (*next)(const struct lu_env *env,
1607 * Returns a pointer to a buffer containing the key of the
1608 * record at the current position. The pointer is valid and
1609 * retains data until ->get(), ->load() and ->fini() methods
1612 * \param[in] env execution environment for this thread
1613 * \param[in] di iterator
1615 * \retval pointer to key on success
1616 * \retval ERR_PTR(errno) on error
1618 struct dt_key *(*key)(const struct lu_env *env,
1619 const struct dt_it *di);
1624 * Returns size of the key at the current position.
1626 * \param[in] env execution environment for this thread
1627 * \param[in] di iterator
1629 * \retval key's size on success
1630 * \retval negative negated errno on error
1632 int (*key_size)(const struct lu_env *env,
1633 const struct dt_it *di);
1638 * Stores the value of the record at the current position. The
1639 * buffer must be big enough (as negotiated with
1640 * ->do_index_try() or ->rec_size()). The caller can specify
1641 * she is interested only in part of the record, using attr
1642 * argument (see LUDA_* definitions for the details).
1644 * \param[in] env execution environment for this thread
1645 * \param[in] di iterator
1646 * \param[out] rec buffer to store value in
1647 * \param[in] attr specify part of the value to copy
1649 * \retval 0 on success
1650 * \retval negative negated errno on error
1652 int (*rec)(const struct lu_env *env,
1653 const struct dt_it *di,
1658 * Return record size.
1660 * Returns size of the record at the current position. The
1661 * \a attr can be used to specify only the parts of the record
1662 * needed to be returned. (see LUDA_* definitions for the
1665 * \param[in] env execution environment for this thread
1666 * \param[in] di iterator
1667 * \param[in] attr part of the record to return
1669 * \retval record's size on success
1670 * \retval negative negated errno on error
1672 int (*rec_size)(const struct lu_env *env,
1673 const struct dt_it *di,
1677 * Return a cookie (hash).
1679 * Returns the cookie (usually hash) of the key at the current
1680 * position. This allows the caller to resume iteration at this
1681 * position later. The exact value is specific to implementation
1682 * and should not be interpreted by the caller.
1684 * \param[in] env execution environment for this thread
1685 * \param[in] di iterator
1687 * \retval cookie/hash of the key
1689 __u64 (*store)(const struct lu_env *env,
1690 const struct dt_it *di);
1693 * Initialize position using cookie/hash.
1695 * Initializes the current position of the iterator to one
1696 * described by the cookie/hash as returned by ->store()
1699 * \param[in] env execution environment for this thread
1700 * \param[in] di iterator
1701 * \param[in] hash cookie/hash value
1703 * \retval positive if current position points to
1704 * record with least cookie not larger
1706 * \retval 0 if current position matches cookie
1707 * \retval negative negated errno on error
1709 int (*load)(const struct lu_env *env,
1710 const struct dt_it *di,
1716 int (*key_rec)(const struct lu_env *env,
1717 const struct dt_it *di,
1722 enum dt_otable_it_valid {
1723 DOIV_ERROR_HANDLE = 0x0001,
1724 DOIV_DRYRUN = 0x0002,
1727 enum dt_otable_it_flags {
1728 /* Exit when fail. */
1729 DOIF_FAILOUT = 0x0001,
1731 /* Reset iteration position to the device beginning. */
1732 DOIF_RESET = 0x0002,
1734 /* There is up layer component uses the iteration. */
1735 DOIF_OUTUSED = 0x0004,
1737 /* Check only without repairing. */
1738 DOIF_DRYRUN = 0x0008,
1741 /* otable based iteration needs to use the common DT interation APIs.
1742 * To initialize the iteration, it needs call dio_it::init() firstly.
1743 * Here is how the otable based iteration should prepare arguments to
1744 * call dt_it_ops::init().
1746 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1747 * is composed of two parts:
1748 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1749 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1750 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1753 struct lu_device dd_lu_dev;
1754 const struct dt_device_operations *dd_ops;
1757 * List of dt_txn_callback (see below). This is not protected in any
1758 * way, because callbacks are supposed to be added/deleted only during
1759 * single-threaded start-up shut-down procedures.
1761 struct list_head dd_txn_callbacks;
1762 unsigned int dd_record_fid_accessed:1;
1765 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1766 void dt_device_fini(struct dt_device *dev);
1768 static inline int lu_device_is_dt(const struct lu_device *d)
1770 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1773 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1775 LASSERT(lu_device_is_dt(l));
1776 return container_of0(l, struct dt_device, dd_lu_dev);
1780 struct lu_object do_lu;
1781 const struct dt_object_operations *do_ops;
1782 const struct dt_body_operations *do_body_ops;
1783 const struct dt_index_operations *do_index_ops;
1787 * In-core representation of per-device local object OID storage
1789 struct local_oid_storage {
1790 /* all initialized llog systems on this node linked by this */
1791 struct list_head los_list;
1793 /* how many handle's reference this los has */
1794 atomic_t los_refcount;
1795 struct dt_device *los_dev;
1796 struct dt_object *los_obj;
1798 /* data used to generate new fids */
1799 struct mutex los_id_lock;
1804 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1806 return &d->dd_lu_dev;
1809 static inline struct dt_object *lu2dt(struct lu_object *l)
1811 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1812 return container_of0(l, struct dt_object, do_lu);
1815 int dt_object_init(struct dt_object *obj,
1816 struct lu_object_header *h, struct lu_device *d);
1818 void dt_object_fini(struct dt_object *obj);
1820 static inline int dt_object_exists(const struct dt_object *dt)
1822 return lu_object_exists(&dt->do_lu);
1825 static inline int dt_object_remote(const struct dt_object *dt)
1827 return lu_object_remote(&dt->do_lu);
1830 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1832 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1833 return container_of0(o, struct dt_object, do_lu);
1836 struct thandle_update {
1837 /* In DNE, one transaction can be disassembled into
1838 * updates on several different MDTs, and these updates
1839 * will be attached to tu_remote_update_list per target.
1840 * Only single thread will access the list, no need lock
1842 struct list_head tu_remote_update_list;
1844 /* sent after or before local transaction */
1845 unsigned int tu_sent_after_local_trans:1,
1846 tu_only_remote_trans:1;
1850 * This is the general purpose transaction handle.
1851 * 1. Transaction Life Cycle
1852 * This transaction handle is allocated upon starting a new transaction,
1853 * and deallocated after this transaction is committed.
1854 * 2. Transaction Nesting
1855 * We do _NOT_ support nested transaction. So, every thread should only
1856 * have one active transaction, and a transaction only belongs to one
1857 * thread. Due to this, transaction handle need no reference count.
1858 * 3. Transaction & dt_object locking
1859 * dt_object locks should be taken inside transaction.
1860 * 4. Transaction & RPC
1861 * No RPC request should be issued inside transaction.
1864 /** the dt device on which the transactions are executed */
1865 struct dt_device *th_dev;
1868 /* the size of transaction */
1871 /** context for this transaction, tag is LCT_TX_HANDLE */
1872 struct lu_context th_ctx;
1874 /** additional tags (layers can add in declare) */
1877 /** the last operation result in this transaction.
1878 * this value is used in recovery */
1881 /** whether we need sync commit */
1882 unsigned int th_sync:1;
1884 /* local transation, no need to inform other layers */
1885 unsigned int th_local:1;
1887 struct thandle_update *th_update;
1890 static inline void thandle_get(struct thandle *thandle)
1892 atomic_inc(&thandle->th_refc);
1895 static inline void thandle_put(struct thandle *thandle)
1897 if (atomic_dec_and_test(&thandle->th_refc)) {
1898 if (thandle->th_update != NULL)
1899 OBD_FREE_PTR(thandle->th_update);
1900 OBD_FREE(thandle, thandle->th_alloc_size);
1904 * Transaction call-backs.
1906 * These are invoked by osd (or underlying transaction engine) when
1907 * transaction changes state.
1909 * Call-backs are used by upper layers to modify transaction parameters and to
1910 * perform some actions on for each transaction state transition. Typical
1911 * example is mdt registering call-back to write into last-received file
1912 * before each transaction commit.
1914 struct dt_txn_callback {
1915 int (*dtc_txn_start)(const struct lu_env *env,
1916 struct thandle *txn, void *cookie);
1917 int (*dtc_txn_stop)(const struct lu_env *env,
1918 struct thandle *txn, void *cookie);
1919 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1922 struct list_head dtc_linkage;
1925 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1926 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1928 int dt_txn_hook_start(const struct lu_env *env,
1929 struct dt_device *dev, struct thandle *txn);
1930 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1931 void dt_txn_hook_commit(struct thandle *txn);
1933 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1936 * Callback function used for parsing path.
1937 * \see llo_store_resolve
1939 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1943 #define DT_MAX_PATH 1024
1945 int dt_path_parser(const struct lu_env *env,
1946 char *local, dt_entry_func_t entry_func,
1950 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1951 const char *path, struct lu_fid *fid);
1953 struct dt_object *dt_store_open(const struct lu_env *env,
1954 struct dt_device *dt,
1955 const char *dirname,
1956 const char *filename,
1957 struct lu_fid *fid);
1959 struct dt_object *dt_find_or_create(const struct lu_env *env,
1960 struct dt_device *dt,
1961 const struct lu_fid *fid,
1962 struct dt_object_format *dof,
1963 struct lu_attr *attr);
1965 struct dt_object *dt_locate_at(const struct lu_env *env,
1966 struct dt_device *dev,
1967 const struct lu_fid *fid,
1968 struct lu_device *top_dev,
1969 const struct lu_object_conf *conf);
1971 static inline struct dt_object *
1972 dt_locate(const struct lu_env *env, struct dt_device *dev,
1973 const struct lu_fid *fid)
1975 return dt_locate_at(env, dev, fid,
1976 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1979 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
1980 const struct lu_fid *first_fid,
1981 struct local_oid_storage **los);
1982 void local_oid_storage_fini(const struct lu_env *env,
1983 struct local_oid_storage *los);
1984 int local_object_fid_generate(const struct lu_env *env,
1985 struct local_oid_storage *los,
1986 struct lu_fid *fid);
1987 int local_object_declare_create(const struct lu_env *env,
1988 struct local_oid_storage *los,
1989 struct dt_object *o,
1990 struct lu_attr *attr,
1991 struct dt_object_format *dof,
1992 struct thandle *th);
1993 int local_object_create(const struct lu_env *env,
1994 struct local_oid_storage *los,
1995 struct dt_object *o,
1996 struct lu_attr *attr, struct dt_object_format *dof,
1997 struct thandle *th);
1998 struct dt_object *local_file_find_or_create(const struct lu_env *env,
1999 struct local_oid_storage *los,
2000 struct dt_object *parent,
2001 const char *name, __u32 mode);
2002 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2003 struct dt_device *dt,
2004 const struct lu_fid *fid,
2005 struct dt_object *parent,
2009 local_index_find_or_create(const struct lu_env *env,
2010 struct local_oid_storage *los,
2011 struct dt_object *parent,
2012 const char *name, __u32 mode,
2013 const struct dt_index_features *ft);
2015 local_index_find_or_create_with_fid(const struct lu_env *env,
2016 struct dt_device *dt,
2017 const struct lu_fid *fid,
2018 struct dt_object *parent,
2019 const char *name, __u32 mode,
2020 const struct dt_index_features *ft);
2021 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2022 struct dt_object *parent, const char *name);
2024 static inline int dt_object_lock(const struct lu_env *env,
2025 struct dt_object *o, struct lustre_handle *lh,
2026 struct ldlm_enqueue_info *einfo,
2027 union ldlm_policy_data *policy)
2030 LASSERT(o->do_ops != NULL);
2031 LASSERT(o->do_ops->do_object_lock != NULL);
2032 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2035 static inline int dt_object_unlock(const struct lu_env *env,
2036 struct dt_object *o,
2037 struct ldlm_enqueue_info *einfo,
2038 union ldlm_policy_data *policy)
2041 LASSERT(o->do_ops != NULL);
2042 LASSERT(o->do_ops->do_object_unlock != NULL);
2043 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2046 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2047 const char *name, struct lu_fid *fid);
2049 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2050 __u64 start, __u64 end)
2054 LASSERT(o->do_ops->do_object_sync);
2055 return o->do_ops->do_object_sync(env, o, start, end);
2058 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2059 struct thandle *th);
2060 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2061 dt_obj_version_t version, struct thandle *th);
2062 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2065 int dt_read(const struct lu_env *env, struct dt_object *dt,
2066 struct lu_buf *buf, loff_t *pos);
2067 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2068 struct lu_buf *buf, loff_t *pos);
2069 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2070 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2071 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2072 union lu_page *lp, int nob,
2073 const struct dt_it_ops *iops,
2074 struct dt_it *it, __u32 attr, void *arg);
2075 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2076 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2078 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2079 struct idx_info *ii, const struct lu_rdpg *rdpg);
2081 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2082 struct dt_device *d)
2084 LASSERT(d->dd_ops->dt_trans_create);
2085 return d->dd_ops->dt_trans_create(env, d);
2088 static inline int dt_trans_start(const struct lu_env *env,
2089 struct dt_device *d, struct thandle *th)
2091 LASSERT(d->dd_ops->dt_trans_start);
2092 return d->dd_ops->dt_trans_start(env, d, th);
2095 /* for this transaction hooks shouldn't be called */
2096 static inline int dt_trans_start_local(const struct lu_env *env,
2097 struct dt_device *d, struct thandle *th)
2099 LASSERT(d->dd_ops->dt_trans_start);
2101 return d->dd_ops->dt_trans_start(env, d, th);
2104 static inline int dt_trans_stop(const struct lu_env *env,
2105 struct dt_device *d, struct thandle *th)
2107 LASSERT(d->dd_ops->dt_trans_stop);
2108 return d->dd_ops->dt_trans_stop(env, d, th);
2111 static inline int dt_trans_cb_add(struct thandle *th,
2112 struct dt_txn_commit_cb *dcb)
2114 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2115 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2116 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2121 static inline int dt_declare_record_write(const struct lu_env *env,
2122 struct dt_object *dt,
2123 const struct lu_buf *buf,
2129 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2130 LASSERT(th != NULL);
2131 LASSERT(dt->do_body_ops);
2132 LASSERT(dt->do_body_ops->dbo_declare_write);
2133 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2137 static inline int dt_declare_create(const struct lu_env *env,
2138 struct dt_object *dt,
2139 struct lu_attr *attr,
2140 struct dt_allocation_hint *hint,
2141 struct dt_object_format *dof,
2145 LASSERT(dt->do_ops);
2146 LASSERT(dt->do_ops->do_declare_create);
2148 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2149 return cfs_fail_err;
2151 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2154 static inline int dt_create(const struct lu_env *env,
2155 struct dt_object *dt,
2156 struct lu_attr *attr,
2157 struct dt_allocation_hint *hint,
2158 struct dt_object_format *dof,
2162 LASSERT(dt->do_ops);
2163 LASSERT(dt->do_ops->do_create);
2165 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2166 return cfs_fail_err;
2168 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2171 static inline int dt_declare_destroy(const struct lu_env *env,
2172 struct dt_object *dt,
2176 LASSERT(dt->do_ops);
2177 LASSERT(dt->do_ops->do_declare_destroy);
2179 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2180 return cfs_fail_err;
2182 return dt->do_ops->do_declare_destroy(env, dt, th);
2185 static inline int dt_destroy(const struct lu_env *env,
2186 struct dt_object *dt,
2190 LASSERT(dt->do_ops);
2191 LASSERT(dt->do_ops->do_destroy);
2193 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2194 return cfs_fail_err;
2196 return dt->do_ops->do_destroy(env, dt, th);
2199 static inline void dt_read_lock(const struct lu_env *env,
2200 struct dt_object *dt,
2204 LASSERT(dt->do_ops);
2205 LASSERT(dt->do_ops->do_read_lock);
2206 dt->do_ops->do_read_lock(env, dt, role);
2209 static inline void dt_write_lock(const struct lu_env *env,
2210 struct dt_object *dt,
2214 LASSERT(dt->do_ops);
2215 LASSERT(dt->do_ops->do_write_lock);
2216 dt->do_ops->do_write_lock(env, dt, role);
2219 static inline void dt_read_unlock(const struct lu_env *env,
2220 struct dt_object *dt)
2223 LASSERT(dt->do_ops);
2224 LASSERT(dt->do_ops->do_read_unlock);
2225 dt->do_ops->do_read_unlock(env, dt);
2228 static inline void dt_write_unlock(const struct lu_env *env,
2229 struct dt_object *dt)
2232 LASSERT(dt->do_ops);
2233 LASSERT(dt->do_ops->do_write_unlock);
2234 dt->do_ops->do_write_unlock(env, dt);
2237 static inline int dt_write_locked(const struct lu_env *env,
2238 struct dt_object *dt)
2241 LASSERT(dt->do_ops);
2242 LASSERT(dt->do_ops->do_write_locked);
2243 return dt->do_ops->do_write_locked(env, dt);
2246 static inline int dt_declare_attr_get(const struct lu_env *env,
2247 struct dt_object *dt,
2248 struct lustre_capa *capa)
2251 LASSERT(dt->do_ops);
2252 LASSERT(dt->do_ops->do_declare_attr_get);
2254 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2255 return cfs_fail_err;
2257 return dt->do_ops->do_declare_attr_get(env, dt, capa);
2260 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2261 struct lu_attr *la, void *arg)
2264 LASSERT(dt->do_ops);
2265 LASSERT(dt->do_ops->do_attr_get);
2267 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2268 return cfs_fail_err;
2270 return dt->do_ops->do_attr_get(env, dt, la, arg);
2273 static inline int dt_declare_attr_set(const struct lu_env *env,
2274 struct dt_object *dt,
2275 const struct lu_attr *la,
2279 LASSERT(dt->do_ops);
2280 LASSERT(dt->do_ops->do_declare_attr_set);
2282 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2283 return cfs_fail_err;
2285 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2288 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2289 const struct lu_attr *la, struct thandle *th,
2290 struct lustre_capa *capa)
2293 LASSERT(dt->do_ops);
2294 LASSERT(dt->do_ops->do_attr_set);
2296 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2297 return cfs_fail_err;
2299 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
2302 static inline int dt_declare_ref_add(const struct lu_env *env,
2303 struct dt_object *dt, struct thandle *th)
2306 LASSERT(dt->do_ops);
2307 LASSERT(dt->do_ops->do_declare_ref_add);
2309 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2310 return cfs_fail_err;
2312 return dt->do_ops->do_declare_ref_add(env, dt, th);
2315 static inline int dt_ref_add(const struct lu_env *env,
2316 struct dt_object *dt, struct thandle *th)
2319 LASSERT(dt->do_ops);
2320 LASSERT(dt->do_ops->do_ref_add);
2322 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2323 return cfs_fail_err;
2325 return dt->do_ops->do_ref_add(env, dt, th);
2328 static inline int dt_declare_ref_del(const struct lu_env *env,
2329 struct dt_object *dt, struct thandle *th)
2332 LASSERT(dt->do_ops);
2333 LASSERT(dt->do_ops->do_declare_ref_del);
2335 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2336 return cfs_fail_err;
2338 return dt->do_ops->do_declare_ref_del(env, dt, th);
2341 static inline int dt_ref_del(const struct lu_env *env,
2342 struct dt_object *dt, struct thandle *th)
2345 LASSERT(dt->do_ops);
2346 LASSERT(dt->do_ops->do_ref_del);
2348 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2349 return cfs_fail_err;
2351 return dt->do_ops->do_ref_del(env, dt, th);
2354 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
2355 struct dt_object *dt,
2356 struct lustre_capa *old, __u64 opc)
2359 LASSERT(dt->do_ops);
2360 LASSERT(dt->do_ops->do_capa_get);
2361 return dt->do_ops->do_capa_get(env, dt, old, opc);
2364 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2365 struct niobuf_remote *rnb,
2366 struct niobuf_local *lnb, int rw,
2367 struct lustre_capa *capa)
2370 LASSERT(d->do_body_ops);
2371 LASSERT(d->do_body_ops->dbo_bufs_get);
2372 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2373 rnb->rnb_len, lnb, rw, capa);
2376 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2377 struct niobuf_local *lnb, int n)
2380 LASSERT(d->do_body_ops);
2381 LASSERT(d->do_body_ops->dbo_bufs_put);
2382 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2385 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2386 struct niobuf_local *lnb, int n)
2389 LASSERT(d->do_body_ops);
2390 LASSERT(d->do_body_ops->dbo_write_prep);
2391 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2394 static inline int dt_declare_write_commit(const struct lu_env *env,
2395 struct dt_object *d,
2396 struct niobuf_local *lnb,
2397 int n, struct thandle *th)
2399 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2400 LASSERT(th != NULL);
2401 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2405 static inline int dt_write_commit(const struct lu_env *env,
2406 struct dt_object *d, struct niobuf_local *lnb,
2407 int n, struct thandle *th)
2410 LASSERT(d->do_body_ops);
2411 LASSERT(d->do_body_ops->dbo_write_commit);
2412 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2415 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2416 struct niobuf_local *lnb, int n)
2419 LASSERT(d->do_body_ops);
2420 LASSERT(d->do_body_ops->dbo_read_prep);
2421 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2424 static inline int dt_declare_punch(const struct lu_env *env,
2425 struct dt_object *dt, __u64 start,
2426 __u64 end, struct thandle *th)
2429 LASSERT(dt->do_body_ops);
2430 LASSERT(dt->do_body_ops->dbo_declare_punch);
2431 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2434 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2435 __u64 start, __u64 end, struct thandle *th,
2436 struct lustre_capa *capa)
2439 LASSERT(dt->do_body_ops);
2440 LASSERT(dt->do_body_ops->dbo_punch);
2441 return dt->do_body_ops->dbo_punch(env, dt, start, end, th, capa);
2444 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2445 struct ll_user_fiemap *fm)
2448 if (d->do_body_ops == NULL)
2450 if (d->do_body_ops->dbo_fiemap_get == NULL)
2452 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2455 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2456 struct obd_statfs *osfs)
2459 LASSERT(dev->dd_ops);
2460 LASSERT(dev->dd_ops->dt_statfs);
2461 return dev->dd_ops->dt_statfs(env, dev, osfs);
2464 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2468 LASSERT(dev->dd_ops);
2469 LASSERT(dev->dd_ops->dt_root_get);
2470 return dev->dd_ops->dt_root_get(env, dev, f);
2473 static inline void dt_conf_get(const struct lu_env *env,
2474 const struct dt_device *dev,
2475 struct dt_device_param *param)
2478 LASSERT(dev->dd_ops);
2479 LASSERT(dev->dd_ops->dt_conf_get);
2480 return dev->dd_ops->dt_conf_get(env, dev, param);
2483 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2486 LASSERT(dev->dd_ops);
2487 LASSERT(dev->dd_ops->dt_sync);
2488 return dev->dd_ops->dt_sync(env, dev);
2491 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2494 LASSERT(dev->dd_ops);
2495 LASSERT(dev->dd_ops->dt_ro);
2496 return dev->dd_ops->dt_ro(env, dev);
2499 static inline int dt_declare_insert(const struct lu_env *env,
2500 struct dt_object *dt,
2501 const struct dt_rec *rec,
2502 const struct dt_key *key,
2506 LASSERT(dt->do_index_ops);
2507 LASSERT(dt->do_index_ops->dio_declare_insert);
2509 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2510 return cfs_fail_err;
2512 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2515 static inline int dt_insert(const struct lu_env *env,
2516 struct dt_object *dt,
2517 const struct dt_rec *rec,
2518 const struct dt_key *key,
2520 struct lustre_capa *capa,
2524 LASSERT(dt->do_index_ops);
2525 LASSERT(dt->do_index_ops->dio_insert);
2527 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2528 return cfs_fail_err;
2530 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
2534 static inline int dt_declare_xattr_del(const struct lu_env *env,
2535 struct dt_object *dt,
2540 LASSERT(dt->do_ops);
2541 LASSERT(dt->do_ops->do_declare_xattr_del);
2543 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2544 return cfs_fail_err;
2546 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2549 static inline int dt_xattr_del(const struct lu_env *env,
2550 struct dt_object *dt, const char *name,
2552 struct lustre_capa *capa)
2555 LASSERT(dt->do_ops);
2556 LASSERT(dt->do_ops->do_xattr_del);
2558 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2559 return cfs_fail_err;
2561 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
2564 static inline int dt_declare_xattr_set(const struct lu_env *env,
2565 struct dt_object *dt,
2566 const struct lu_buf *buf,
2567 const char *name, int fl,
2571 LASSERT(dt->do_ops);
2572 LASSERT(dt->do_ops->do_declare_xattr_set);
2574 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2575 return cfs_fail_err;
2577 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2580 static inline int dt_xattr_set(const struct lu_env *env,
2581 struct dt_object *dt, const struct lu_buf *buf,
2582 const char *name, int fl, struct thandle *th,
2583 struct lustre_capa *capa)
2586 LASSERT(dt->do_ops);
2587 LASSERT(dt->do_ops->do_xattr_set);
2589 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2590 return cfs_fail_err;
2592 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
2595 static inline int dt_declare_xattr_get(const struct lu_env *env,
2596 struct dt_object *dt,
2599 struct lustre_capa *capa)
2602 LASSERT(dt->do_ops);
2603 LASSERT(dt->do_ops->do_declare_xattr_get);
2605 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2606 return cfs_fail_err;
2608 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name, capa);
2611 static inline int dt_xattr_get(const struct lu_env *env,
2612 struct dt_object *dt, struct lu_buf *buf,
2613 const char *name, struct lustre_capa *capa)
2616 LASSERT(dt->do_ops);
2617 LASSERT(dt->do_ops->do_xattr_get);
2619 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2620 return cfs_fail_err;
2622 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
2625 static inline int dt_xattr_list(const struct lu_env *env,
2626 struct dt_object *dt, struct lu_buf *buf,
2627 struct lustre_capa *capa)
2630 LASSERT(dt->do_ops);
2631 LASSERT(dt->do_ops->do_xattr_list);
2633 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2634 return cfs_fail_err;
2636 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
2639 static inline int dt_declare_delete(const struct lu_env *env,
2640 struct dt_object *dt,
2641 const struct dt_key *key,
2645 LASSERT(dt->do_index_ops);
2646 LASSERT(dt->do_index_ops->dio_declare_delete);
2648 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2649 return cfs_fail_err;
2651 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2654 static inline int dt_delete(const struct lu_env *env,
2655 struct dt_object *dt,
2656 const struct dt_key *key,
2658 struct lustre_capa *capa)
2661 LASSERT(dt->do_index_ops);
2662 LASSERT(dt->do_index_ops->dio_delete);
2664 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2665 return cfs_fail_err;
2667 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
2670 static inline int dt_commit_async(const struct lu_env *env,
2671 struct dt_device *dev)
2674 LASSERT(dev->dd_ops);
2675 LASSERT(dev->dd_ops->dt_commit_async);
2676 return dev->dd_ops->dt_commit_async(env, dev);
2679 static inline int dt_init_capa_ctxt(const struct lu_env *env,
2680 struct dt_device *dev,
2681 int mode, unsigned long timeout,
2682 __u32 alg, struct lustre_capa_key *keys)
2685 LASSERT(dev->dd_ops);
2686 LASSERT(dev->dd_ops->dt_init_capa_ctxt);
2687 return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
2688 timeout, alg, keys);
2691 static inline int dt_lookup(const struct lu_env *env,
2692 struct dt_object *dt,
2694 const struct dt_key *key,
2695 struct lustre_capa *capa)
2700 LASSERT(dt->do_index_ops);
2701 LASSERT(dt->do_index_ops->dio_lookup);
2703 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2704 return cfs_fail_err;
2706 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
2714 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
2716 struct dt_find_hint {
2717 struct lu_fid *dfh_fid;
2718 struct dt_device *dfh_dt;
2719 struct dt_object *dfh_o;
2722 struct dt_insert_rec {
2724 const struct lu_fid *rec_fid;
2736 struct dt_thread_info {
2737 char dti_buf[DT_MAX_PATH];
2738 struct dt_find_hint dti_dfh;
2739 struct lu_attr dti_attr;
2740 struct lu_fid dti_fid;
2741 struct dt_object_format dti_dof;
2742 struct lustre_mdt_attrs dti_lma;
2743 struct lu_buf dti_lb;
2744 struct lu_object_conf dti_conf;
2746 struct dt_insert_rec dti_dt_rec;
2749 extern struct lu_context_key dt_key;
2751 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2753 struct dt_thread_info *dti;
2755 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2760 int dt_global_init(void);
2761 void dt_global_fini(void);
2764 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2765 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2766 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2767 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2768 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2769 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2770 # endif /* LPROCFS */
2772 #endif /* __LUSTRE_DT_OBJECT_H */