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 #define DCB_TRANS_STOP 0x1
108 struct dt_txn_commit_cb {
109 struct list_head dcb_linkage;
114 char dcb_name[MAX_COMMIT_CB_STR_LEN];
118 * Operations on dt device.
120 struct dt_device_operations {
122 * Return device-wide statistics.
124 * Return device-wide stats including block size, total and
125 * free blocks, total and free objects, etc. See struct obd_statfs
128 * \param[in] env execution environment for this thread
129 * \param[in] dev dt device
130 * \param[out] osfs stats information
132 * \retval 0 on success
133 * \retval negative negated errno on error
135 int (*dt_statfs)(const struct lu_env *env,
136 struct dt_device *dev,
137 struct obd_statfs *osfs);
140 * Create transaction.
142 * Create in-memory structure representing the transaction for the
143 * caller. The structure returned will be used by the calling thread
144 * to specify the transaction the updates belong to. Once created
145 * successfully ->dt_trans_stop() must be called in any case (with
146 * ->dt_trans_start() and updates or not) so that the transaction
147 * handle and other resources can be released by the layers below.
149 * \param[in] env execution environment for this thread
150 * \param[in] dev dt device
152 * \retval pointer to handle if creation succeeds
153 * \retval ERR_PTR(errno) if creation fails
155 struct thandle *(*dt_trans_create)(const struct lu_env *env,
156 struct dt_device *dev);
161 * Start the transaction. The transaction described by \a th can be
162 * started only once. Another start is considered as an error.
163 * A thread is not supposed to start a transaction while another
164 * transaction isn't closed by the thread (though multiple handles
165 * can be created). The caller should start the transaction once
166 * all possible updates are declared (see the ->do_declare_* methods
167 * below) and all the needed resources are reserved.
169 * \param[in] env execution environment for this thread
170 * \param[in] dev dt device
171 * \param[in] th transaction handle
173 * \retval 0 on success
174 * \retval negative negated errno on error
176 int (*dt_trans_start)(const struct lu_env *env,
177 struct dt_device *dev,
183 * Once stopped the transaction described by \a th is complete (all
184 * the needed updates are applied) and further processing such as
185 * flushing to disk, sending to another target, etc, is handled by
186 * lower layers. The caller can't access this transaction by the
187 * handle anymore (except from the commit callbacks, see below).
189 * \param[in] env execution environment for this thread
190 * \param[in] dev dt device
191 * \param[in] th transaction handle
193 * \retval 0 on success
194 * \retval negative negated errno on error
196 int (*dt_trans_stop)(const struct lu_env *env,
197 struct dt_device *dev,
201 * Add commit callback to the transaction.
203 * Add a commit callback to the given transaction handle. The callback
204 * will be called when the associated transaction is stored. I.e. the
205 * transaction will survive an event like power off if the callback did
206 * run. The number of callbacks isn't limited, but you should note that
207 * some disk filesystems do handle the commit callbacks in the thread
208 * handling commit/flush of all the transactions, meaning that new
209 * transactions are blocked from commit and flush until all the
210 * callbacks are done. Also, note multiple callbacks can be running
211 * concurrently using multiple CPU cores. The callbacks will be running
212 * in a special environment which can not be used to pass data around.
214 * \param[in] th transaction handle
215 * \param[in] dcb commit callback description
217 * \retval 0 on success
218 * \retval negative negated errno on error
220 int (*dt_trans_cb_add)(struct thandle *th,
221 struct dt_txn_commit_cb *dcb);
224 * Return FID of root index object.
226 * Return the FID of the root object in the filesystem. This object
227 * is usually provided as a bootstrap point by a disk filesystem.
228 * This is up to the implementation which FID to use, though
229 * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
231 * \param[in] env execution environment for this thread
232 * \param[in] dev dt device
233 * \param[out] fid FID of the root object
235 * \retval 0 on success
236 * \retval negative negated errno on error
238 int (*dt_root_get)(const struct lu_env *env,
239 struct dt_device *dev,
243 * Return device configuration data.
245 * Return device (disk fs, actually) specific configuration.
246 * The configuration isn't subject to change at runtime.
247 * See struct dt_device_param for the details.
249 * \param[in] env execution environment for this thread
250 * \param[in] dev dt device
251 * \param[out] param configuration parameters
253 void (*dt_conf_get)(const struct lu_env *env,
254 const struct dt_device *dev,
255 struct dt_device_param *param);
260 * Sync all the cached state (dirty buffers, pages, etc) to the
261 * persistent storage. The method returns control once the sync is
262 * complete. This operation may incur significant I/O to disk and
263 * should be reserved for cases where a global sync is strictly
266 * \param[in] env execution environment for this thread
267 * \param[in] dev dt device
269 * \retval 0 on success
270 * \retval negative negated errno on error
272 int (*dt_sync)(const struct lu_env *env,
273 struct dt_device *dev);
276 * Make device read-only.
278 * Prevent new modifications to the device. This is a very specific
279 * state where all the changes are accepted successfully and the
280 * commit callbacks are called, but persistent state never changes.
281 * Used only in the tests to simulate power-off scenario.
283 * \param[in] env execution environment for this thread
284 * \param[in] dev dt device
286 * \retval 0 on success
287 * \retval negative negated errno on error
289 int (*dt_ro)(const struct lu_env *env,
290 struct dt_device *dev);
293 * Start transaction commit asynchronously.
296 * Provide a hint to the underlying filesystem that it should start
297 * committing soon. The control returns immediately. It's up to the
298 * layer implementing the method how soon to start committing. Usually
299 * this should be throttled to some extent, otherwise the number of
300 * aggregated transaction goes too high causing performance drop.
302 * \param[in] env execution environment for this thread
303 * \param[in] dev dt device
305 * \retval 0 on success
306 * \retval negative negated errno on error
308 int (*dt_commit_async)(const struct lu_env *env,
309 struct dt_device *dev);
312 struct dt_index_features {
313 /** required feature flags from enum dt_index_flags */
315 /** minimal required key size */
316 size_t dif_keysize_min;
317 /** maximal required key size, 0 if no limit */
318 size_t dif_keysize_max;
319 /** minimal required record size */
320 size_t dif_recsize_min;
321 /** maximal required record size, 0 if no limit */
322 size_t dif_recsize_max;
323 /** pointer size for record */
327 enum dt_index_flags {
328 /** index supports variable sized keys */
329 DT_IND_VARKEY = 1 << 0,
330 /** index supports variable sized records */
331 DT_IND_VARREC = 1 << 1,
332 /** index can be modified */
333 DT_IND_UPDATE = 1 << 2,
334 /** index supports records with non-unique (duplicate) keys */
335 DT_IND_NONUNQ = 1 << 3,
337 * index support fixed-size keys sorted with natural numerical way
338 * and is able to return left-side value if no exact value found
340 DT_IND_RANGE = 1 << 4,
344 * Features, required from index to support file system directories (mapping
347 extern const struct dt_index_features dt_directory_features;
348 extern const struct dt_index_features dt_otable_features;
349 extern const struct dt_index_features dt_lfsck_orphan_features;
350 extern const struct dt_index_features dt_lfsck_features;
352 /* index features supported by the accounting objects */
353 extern const struct dt_index_features dt_acct_features;
355 /* index features supported by the quota global indexes */
356 extern const struct dt_index_features dt_quota_glb_features;
358 /* index features supported by the quota slave indexes */
359 extern const struct dt_index_features dt_quota_slv_features;
362 * This is a general purpose dt allocation hint.
363 * It now contains the parent object.
364 * It can contain any allocation hint in the future.
366 struct dt_allocation_hint {
367 struct dt_object *dah_parent;
368 const void *dah_eadata;
374 * object type specifier.
377 enum dt_format_type {
382 /** for special index */
384 /** for symbolic link */
389 * object format specifier.
391 struct dt_object_format {
392 /** type for dt object */
393 enum dt_format_type dof_type;
403 * special index need feature as parameter to create
407 const struct dt_index_features *di_feat;
412 enum dt_format_type dt_mode_to_dft(__u32 mode);
414 typedef __u64 dt_obj_version_t;
416 union ldlm_policy_data;
419 * A dt_object provides common operations to create and destroy
420 * objects and to manage regular and extended attributes.
422 struct dt_object_operations {
424 * Get read lock on object.
426 * Read lock is compatible with other read locks, so it's shared.
427 * Read lock is not compatible with write lock which is exclusive.
428 * The lock is blocking and can't be used from an interrupt context.
430 * \param[in] env execution environment for this thread
431 * \param[in] dt object to lock for reading
432 * \param[in] role a hint to debug locks (see kernel's mutexes)
434 void (*do_read_lock)(const struct lu_env *env,
435 struct dt_object *dt,
439 * Get write lock on object.
441 * Write lock is exclusive and cannot be shared. The lock is blocking
442 * and can't be used from an interrupt context.
444 * \param[in] env execution environment for this thread
445 * \param[in] dt object to lock for writing
446 * \param[in] role a hint to debug locks (see kernel's mutexes)
449 void (*do_write_lock)(const struct lu_env *env,
450 struct dt_object *dt,
456 * \param[in] env execution environment for this thread
457 * \param[in] dt object
459 void (*do_read_unlock)(const struct lu_env *env,
460 struct dt_object *dt);
463 * Release write lock.
465 * \param[in] env execution environment for this thread
466 * \param[in] dt object
468 void (*do_write_unlock)(const struct lu_env *env,
469 struct dt_object *dt);
472 * Check whether write lock is held.
474 * The caller can learn whether write lock is held on the object
476 * \param[in] env execution environment for this thread
477 * \param[in] dt object
479 * \retval 0 no write lock
480 * \retval 1 write lock is held
482 int (*do_write_locked)(const struct lu_env *env,
483 struct dt_object *dt);
486 * Declare intention to request reqular attributes.
488 * Notity the underlying filesystem that the caller may request regular
489 * attributes with ->do_attr_get() soon. This allows OSD to implement
490 * prefetching logic in an object-oriented manner. The implementation
491 * can be noop. This method should avoid expensive delays such as
492 * waiting on disk I/O, otherwise the goal of enabling a performance
493 * optimization would be defeated.
495 * \param[in] env execution environment for this thread
496 * \param[in] dt object
498 * \retval 0 on success
499 * \retval negative negated errno on error
501 int (*do_declare_attr_get)(const struct lu_env *env,
502 struct dt_object *dt);
505 * Return regular attributes.
507 * The object must exist. Currently all the attributes should be
508 * returned, but in the future this can be improved so that only
509 * a selected set is returned. This can improve performance as in
510 * some cases attributes are stored in different places and
511 * getting them all can be an iterative and expensive process.
513 * \param[in] env execution environment for this thread
514 * \param[in] dt object
515 * \param[out] attr attributes to fill
517 * \retval 0 on success
518 * \retval negative negated errno on error
520 int (*do_attr_get)(const struct lu_env *env,
521 struct dt_object *dt,
522 struct lu_attr *attr);
525 * Declare intention to change regular object's attributes.
527 * Notify the underlying filesystem that the regular attributes may
528 * change in this transaction. This enables the layer below to prepare
529 * resources (e.g. journal credits in ext4). This method should be
530 * called between creating the transaction and starting it. Note that
531 * the la_valid field of \a attr specifies which attributes will change.
532 * The object need not exist.
534 * \param[in] env execution environment for this thread
535 * \param[in] dt object
536 * \param[in] attr attributes to change specified in attr.la_valid
537 * \param[in] th transaction handle
539 * \retval 0 on success
540 * \retval negative negated errno on error
542 int (*do_declare_attr_set)(const struct lu_env *env,
543 struct dt_object *dt,
544 const struct lu_attr *attr,
548 * Change regular attributes.
550 * Change regular attributes in the given transaction. Note only
551 * attributes flagged by attr.la_valid change. The object must
552 * exist. If the layer implementing this method is responsible for
553 * quota, then the method should maintain object accounting for the
554 * given credentials when la_uid/la_gid changes.
556 * \param[in] env execution environment for this thread
557 * \param[in] dt object
558 * \param[in] attr new attributes to apply
559 * \param[in] th transaction handle
561 * \retval 0 on success
562 * \retval negative negated errno on error
564 int (*do_attr_set)(const struct lu_env *env,
565 struct dt_object *dt,
566 const struct lu_attr *attr,
570 * Declare intention to request extented attribute.
572 * Notify the underlying filesystem that the caller may request extended
573 * attribute with ->do_xattr_get() soon. This allows OSD to implement
574 * prefetching logic in an object-oriented manner. The implementation
575 * can be noop. This method should avoid expensive delays such as
576 * waiting on disk I/O, otherwise the goal of enabling a performance
577 * optimization would be defeated.
579 * \param[in] env execution environment for this thread
580 * \param[in] dt object
581 * \param[in] buf unused, may be removed in the future
582 * \param[in] name name of the extended attribute
584 * \retval 0 on success
585 * \retval negative negated errno on error
587 int (*do_declare_xattr_get)(const struct lu_env *env,
588 struct dt_object *dt,
593 * Return a value of an extended attribute.
595 * The object must exist. If the buffer is NULL, then the method
596 * must return the size of the value.
598 * \param[in] env execution environment for this thread
599 * \param[in] dt object
600 * \param[out] buf buffer in which to store the value
601 * \param[in] name name of the extended attribute
603 * \retval 0 on success
604 * \retval -ERANGE if \a buf is too small
605 * \retval negative negated errno on error
606 * \retval positive value's size if \a buf is NULL or has zero size
608 int (*do_xattr_get)(const struct lu_env *env,
609 struct dt_object *dt,
614 * Declare intention to change an extended attribute.
616 * Notify the underlying filesystem that the extended attribute may
617 * change in this transaction. This enables the layer below to prepare
618 * resources (e.g. journal credits in ext4). This method should be
619 * called between creating the transaction and starting it. The object
622 * \param[in] env execution environment for this thread
623 * \param[in] dt object
624 * \param[in] buf buffer storing new value of the attribute
625 * \param[in] name name of the attribute
626 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
627 * LU_XATTR_REPLACE - fail if EA doesn't exist
628 * \param[in] th transaction handle
630 * \retval 0 on success
631 * \retval negative negated errno on error
633 int (*do_declare_xattr_set)(const struct lu_env *env,
634 struct dt_object *dt,
635 const struct lu_buf *buf,
641 * Set an extended attribute.
643 * Change or replace the specified extended attribute (EA).
644 * The flags passed in \a fl dictate whether the EA is to be
645 * created or replaced, as follows.
646 * LU_XATTR_CREATE - fail if EA exists
647 * LU_XATTR_REPLACE - fail if EA doesn't exist
648 * The object must exist.
650 * \param[in] env execution environment for this thread
651 * \param[in] dt object
652 * \param[in] buf buffer storing new value of the attribute
653 * \param[in] name name of the attribute
654 * \param[in] fl flags indicating EA creation or replacement
655 * \param[in] th transaction handle
657 * \retval 0 on success
658 * \retval negative negated errno on error
660 int (*do_xattr_set)(const struct lu_env *env,
661 struct dt_object *dt,
662 const struct lu_buf *buf,
668 * Declare intention to delete an extended attribute.
670 * Notify the underlying filesystem that the extended attribute may
671 * be deleted in this transaction. This enables the layer below to
672 * prepare resources (e.g. journal credits in ext4). This method
673 * should be called between creating the transaction and starting it.
674 * The object need not exist.
676 * \param[in] env execution environment for this thread
677 * \param[in] dt object
678 * \param[in] name name of the attribute
679 * \param[in] th transaction handle
681 * \retval 0 on success
682 * \retval negative negated errno on error
684 int (*do_declare_xattr_del)(const struct lu_env *env,
685 struct dt_object *dt,
690 * Delete an extended attribute.
692 * This method deletes the specified extended attribute. The object
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_xattr_del)(const struct lu_env *env,
704 struct dt_object *dt,
709 * Return a list of the extended attributes.
711 * Fills the passed buffer with a list of the extended attributes
712 * found in the object. The names are separated with '\0'.
713 * The object must exist.
715 * \param[in] env execution environment for this thread
716 * \param[in] dt object
717 * \param[out] buf buffer to put the list in
719 * \retval positive bytes used/required in the buffer
720 * \retval negative negated errno on error
722 int (*do_xattr_list)(const struct lu_env *env,
723 struct dt_object *dt,
724 const struct lu_buf *buf);
727 * Prepare allocation hint for a new object.
729 * This method is used by the caller to inform OSD of the parent-child
730 * relationship between two objects and enable efficient object
731 * allocation. Filled allocation hint will be passed to ->do_create()
734 * \param[in] env execution environment for this thread
735 * \param[out] ah allocation hint
736 * \param[in] parent parent object (can be NULL)
737 * \param[in] child child object
738 * \param[in] _mode type of the child object
740 void (*do_ah_init)(const struct lu_env *env,
741 struct dt_allocation_hint *ah,
742 struct dt_object *parent,
743 struct dt_object *child,
747 * Declare intention to create a new object.
749 * Notify the underlying filesystem that the object may be created
750 * in this transaction. This enables the layer below to prepare
751 * resources (e.g. journal credits in ext4). This method should be
752 * called between creating the transaction and starting it.
754 * If the layer implementing this method is responsible for quota,
755 * then the method should reserve an object for the given credentials
756 * and return an error if quota is over. If object creation later
757 * fails for some reason, then the reservation should be released
758 * properly (usually in ->dt_trans_stop()).
760 * \param[in] env execution environment for this thread
761 * \param[in] dt object
762 * \param[in] attr attributes of the new object
763 * \param[in] hint allocation hint
764 * \param[in] dof object format
765 * \param[in] th transaction handle
767 * \retval 0 on success
768 * \retval negative negated errno on error
770 int (*do_declare_create)(const struct lu_env *env,
771 struct dt_object *dt,
772 struct lu_attr *attr,
773 struct dt_allocation_hint *hint,
774 struct dt_object_format *dof,
780 * The method creates the object passed with the specified attributes
781 * and object format. Object allocation procedure can use information
782 * stored in the allocation hint. Different object formats are supported
783 * (see enum dt_format_type and struct dt_object_format) depending on
784 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
785 * in the LU-object header attributes.
787 * If the layer implementing this method is responsible for quota,
788 * then the method should maintain object accounting for the given
791 * \param[in] env execution environment for this thread
792 * \param[in] dt object
793 * \param[in] attr attributes of the new object
794 * \param[in] hint allocation hint
795 * \param[in] dof object format
796 * \param[in] th transaction handle
798 * \retval 0 on success
799 * \retval negative negated errno on error
801 int (*do_create)(const struct lu_env *env,
802 struct dt_object *dt,
803 struct lu_attr *attr,
804 struct dt_allocation_hint *hint,
805 struct dt_object_format *dof,
809 * Declare intention to destroy an object.
811 * Notify the underlying filesystem that the object may be destroyed
812 * in this transaction. This enables the layer below to prepare
813 * resources (e.g. journal credits in ext4). This method should be
814 * called between creating the transaction and starting it. The object
817 * \param[in] env execution environment for this thread
818 * \param[in] dt object
819 * \param[in] th transaction handle
821 * \retval 0 on success
822 * \retval negative negated errno on error
824 int (*do_declare_destroy)(const struct lu_env *env,
825 struct dt_object *dt,
831 * This method destroys the object and all the resources associated
832 * with the object (data, key/value pairs, extended attributes, etc).
833 * The object must exist. If destroy is successful, then flag
834 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
835 * instance of in-core object. Any subsequent access to the same FID
836 * should get another instance with no LOHA_EXIST flag set.
838 * If the layer implementing this method is responsible for quota,
839 * then the method should maintain object accounting for the given
842 * \param[in] env execution environment for this thread
843 * \param[in] dt object
844 * \param[in] th transaction handle
846 * \retval 0 on success
847 * \retval negative negated errno on error
849 int (*do_destroy)(const struct lu_env *env,
850 struct dt_object *dt,
854 * Try object as an index.
856 * Announce that this object is going to be used as an index. This
857 * operation checks that object supports indexing operations and
858 * installs appropriate dt_index_operations vector on success.
859 * Also probes for features. Operation is successful if all required
860 * features are supported. It's not possible to access the object
861 * with index methods before ->do_index_try() returns success.
863 * \param[in] env execution environment for this thread
864 * \param[in] dt object
865 * \param[in] feat index features
867 * \retval 0 on success
868 * \retval negative negated errno on error
870 int (*do_index_try)(const struct lu_env *env,
871 struct dt_object *dt,
872 const struct dt_index_features *feat);
875 * Declare intention to increment nlink count.
877 * Notify the underlying filesystem that the nlink regular attribute
878 * be changed in this transaction. This enables the layer below to
879 * prepare resources (e.g. journal credits in ext4). This method
880 * should be called between creating the transaction and starting it.
881 * The object need not exist.
883 * \param[in] env execution environment for this thread
884 * \param[in] dt object
885 * \param[in] th transaction handle
887 * \retval 0 on success
888 * \retval negative negated errno on error
890 int (*do_declare_ref_add)(const struct lu_env *env,
891 struct dt_object *dt,
897 * Increment nlink (from the regular attributes set) in the given
898 * transaction. Note the absolute limit for nlink should be learnt
899 * from struct dt_device_param::ddp_max_nlink. The object must exist.
901 * \param[in] env execution environment for this thread
902 * \param[in] dt object
903 * \param[in] th transaction handle
905 * \retval 0 on success
906 * \retval negative negated errno on error
908 int (*do_ref_add)(const struct lu_env *env,
909 struct dt_object *dt, struct thandle *th);
912 * Declare intention to decrement nlink count.
914 * Notify the underlying filesystem that the nlink regular attribute
915 * be changed in this transaction. This enables the layer below to
916 * prepare resources (e.g. journal credits in ext4). This method
917 * should be called between creating the transaction and starting it.
918 * The object need not exist.
920 * \param[in] env execution environment for this thread
921 * \param[in] dt object
922 * \param[in] th transaction handle
924 * \retval 0 on success
925 * \retval negative negated errno on error
927 int (*do_declare_ref_del)(const struct lu_env *env,
928 struct dt_object *dt,
934 * Decrement nlink (from the regular attributes set) in the given
935 * transaction. The object must exist.
937 * \param[in] env execution environment for this thread
938 * \param[in] dt object
939 * \param[in] th transaction handle
941 * \retval 0 on success
942 * \retval negative negated errno on error
944 int (*do_ref_del)(const struct lu_env *env,
945 struct dt_object *dt,
951 * The method is called to sync specified range of the object to a
952 * persistent storage. The control is returned once the operation is
953 * complete. The difference from ->do_sync() is that the object can
954 * be in-sync with the persistent storage (nothing to flush), then
955 * the method returns quickly with no I/O overhead. So, this method
956 * should be preferred over ->do_sync() where possible. Also note that
957 * if the object isn't clean, then some disk filesystems will call
958 * ->do_sync() to maintain overall consistency, in which case it's
959 * still very expensive.
961 * \param[in] env execution environment for this thread
962 * \param[in] dt object
963 * \param[in] start start of the range to sync
964 * \param[in] end end of the range to sync
966 * \retval 0 on success
967 * \retval negative negated errno on error
969 int (*do_object_sync)(const struct lu_env *env,
970 struct dt_object *obj,
977 * Lock object(s) using Distributed Lock Manager (LDLM).
979 * Get LDLM locks for the object. Currently used to lock "remote"
980 * objects in DNE configuration - a service running on MDTx needs
981 * to lock an object on MDTy.
983 * \param[in] env execution environment for this thread
984 * \param[in] dt object
985 * \param[out] lh lock handle, sometimes used, sometimes not
986 * \param[in] einfo ldlm callbacks, locking type and mode
987 * \param[out] einfo private data to be passed to unlock later
988 * \param[in] policy inodebits data
990 * \retval 0 on success
991 * \retval negative negated errno on error
993 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
994 struct lustre_handle *lh,
995 struct ldlm_enqueue_info *einfo,
996 union ldlm_policy_data *policy);
1001 * Release LDLM lock(s) granted with ->do_object_lock().
1003 * \param[in] env execution environment for this thread
1004 * \param[in] dt object
1005 * \param[in] einfo lock handles, from ->do_object_lock()
1006 * \param[in] policy inodebits data
1008 * \retval 0 on success
1009 * \retval negative negated errno on error
1011 int (*do_object_unlock)(const struct lu_env *env,
1012 struct dt_object *dt,
1013 struct ldlm_enqueue_info *einfo,
1014 union ldlm_policy_data *policy);
1018 * Per-dt-object operations on "file body" - unstructure raw data.
1020 struct dt_body_operations {
1024 * Read unstructured data from an existing regular object.
1025 * Only data before attr.la_size is returned.
1027 * \param[in] env execution environment for this thread
1028 * \param[in] dt object
1029 * \param[out] buf buffer (including size) to copy data in
1030 * \param[in] pos position in the object to start
1031 * \param[out] pos original value of \a pos + bytes returned
1033 * \retval positive bytes read on success
1034 * \retval negative negated errno on error
1036 ssize_t (*dbo_read)(const struct lu_env *env,
1037 struct dt_object *dt,
1042 * Declare intention to write data to object.
1044 * Notify the underlying filesystem that data may be written in
1045 * this transaction. This enables the layer below to prepare resources
1046 * (e.g. journal credits in ext4). This method should be called
1047 * between creating the transaction and starting it. The object need
1048 * not exist. If the layer implementing this method is responsible for
1049 * quota, then the method should reserve space for the given credentials
1050 * and return an error if quota is over. If the write later fails
1051 * for some reason, then the reserve should be released properly
1052 * (usually in ->dt_trans_stop()).
1054 * \param[in] env execution environment for this thread
1055 * \param[in] dt object
1056 * \param[in] buf buffer (including size) to copy data from
1057 * \param[in] pos position in the object to start
1058 * \param[in] th transaction handle
1060 * \retval 0 on success
1061 * \retval negative negated errno on error
1063 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1064 struct dt_object *dt,
1065 const struct lu_buf *buf,
1067 struct thandle *th);
1070 * Write unstructured data to regular existing object.
1072 * The method allocates space and puts data in. Also, the method should
1073 * maintain attr.la_size properly. Partial writes are possible.
1075 * If the layer implementing this method is responsible for quota,
1076 * then the method should maintain space accounting for the given
1079 * \param[in] env execution environment for this thread
1080 * \param[in] dt object
1081 * \param[in] buf buffer (including size) to copy data from
1082 * \param[in] pos position in the object to start
1083 * \param[out] pos \a pos + bytes written
1084 * \param[in] th transaction handle
1085 * \param[in] ignore unused (was used to request quota ignorance)
1087 * \retval positive bytes written on success
1088 * \retval negative negated errno on error
1090 ssize_t (*dbo_write)(const struct lu_env *env,
1091 struct dt_object *dt,
1092 const struct lu_buf *buf,
1098 * Return buffers for data.
1100 * This method is used to access data with no copying. It's so-called
1101 * zero-copy I/O. The method returns the descriptors for the internal
1102 * buffers where data are managed by the disk filesystem. For example,
1103 * pagecache in case of ext4 or ARC with ZFS. Then other components
1104 * (e.g. networking) can transfer data from or to the buffers with no
1105 * additional copying.
1107 * The method should fill an array of struct niobuf_local, where
1108 * each element describes a full or partial page for data at specific
1109 * offset. The caller should use page/lnb_page_offset/len to find data
1110 * at object's offset lnb_file_offset.
1112 * The memory referenced by the descriptors can't change its purpose
1113 * until the complementary ->dbo_bufs_put() is called. The caller should
1114 * specify if the buffers are used to read or modify data so that OSD
1115 * can decide how to initialize the buffers: bring all the data for
1116 * reads or just bring partial buffers for write. Note: the method does
1117 * not check whether output array is large enough.
1119 * \param[in] env execution environment for this thread
1120 * \param[in] dt object
1121 * \param[in] pos position in the object to start
1122 * \param[in] len size of region in bytes
1123 * \param[out] lb array of descriptors to fill
1124 * \param[in] rw 0 if used to read, 1 if used for write
1126 * \retval positive number of descriptors on success
1127 * \retval negative negated errno on error
1129 int (*dbo_bufs_get)(const struct lu_env *env,
1130 struct dt_object *dt,
1133 struct niobuf_local *lb,
1137 * Release reference granted by ->dbo_bufs_get().
1139 * Release the reference granted by the previous ->dbo_bufs_get().
1140 * Note the references are counted.
1142 * \param[in] env execution environment for this thread
1143 * \param[in] dt object
1144 * \param[out] lb array of descriptors to fill
1145 * \param[in] nr size of the array
1147 * \retval 0 on success
1148 * \retval negative negated errno on error
1150 int (*dbo_bufs_put)(const struct lu_env *env,
1151 struct dt_object *dt,
1152 struct niobuf_local *lb,
1156 * Prepare buffers for reading.
1158 * The method is called on the given buffers to fill them with data
1159 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1160 * caller should be able to get few buffers for discontiguous regions
1161 * using few calls to ->dbo_bufs_get() and then request them all for
1162 * the preparation with a single call, so that OSD can fire many I/Os
1163 * to run concurrently. It's up to the specific OSD whether to implement
1164 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1165 * prepare data for every requested region individually.
1167 * \param[in] env execution environment for this thread
1168 * \param[in] dt object
1169 * \param[in] lnb array of buffer descriptors
1170 * \param[in] nr size of the array
1172 * \retval 0 on success
1173 * \retval negative negated errno on error
1175 int (*dbo_read_prep)(const struct lu_env *env,
1176 struct dt_object *dt,
1177 struct niobuf_local *lnb,
1181 * Prepare buffers for write.
1183 * This method is called on the given buffers to ensure the partial
1184 * buffers contain correct data. The underlying idea is the same as
1185 * in ->db_read_prep().
1187 * \param[in] env execution environment for this thread
1188 * \param[in] dt object
1189 * \param[in] lb array of buffer descriptors
1190 * \param[in] nr size of the array
1192 * \retval 0 on success
1193 * \retval negative negated errno on error
1195 int (*dbo_write_prep)(const struct lu_env *env,
1196 struct dt_object *dt,
1197 struct niobuf_local *lb,
1201 * Declare intention to write data stored in the buffers.
1203 * Notify the underlying filesystem that data may be written in
1204 * this transaction. This enables the layer below to prepare resources
1205 * (e.g. journal credits in ext4). This method should be called
1206 * between creating the transaction and starting it.
1208 * If the layer implementing this method is responsible for quota,
1209 * then the method should be reserving a space for the given
1210 * credentials and return an error if quota is exceeded. If the write
1211 * later fails for some reason, then the reserve should be released
1212 * properly (usually in ->dt_trans_stop()).
1214 * \param[in] env execution environment for this thread
1215 * \param[in] dt object
1216 * \param[in] lb array of descriptors
1217 * \param[in] nr size of the array
1218 * \param[in] th transaction handle
1220 * \retval 0 on success
1221 * \retval negative negated errno on error
1223 int (*dbo_declare_write_commit)(const struct lu_env *env,
1224 struct dt_object *dt,
1225 struct niobuf_local *lb,
1227 struct thandle *th);
1230 * Write to existing object.
1232 * This method is used to write data to a persistent storage using
1233 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1234 * data into the buffers using own mechanisms (e.g. direct transfer
1235 * from a NIC). The method should maintain attr.la_size. Also,
1236 * attr.la_blocks should be maintained but this can be done in lazy
1237 * manner, when actual allocation happens.
1239 * If the layer implementing this method is responsible for quota,
1240 * then the method should maintain space accounting for the given
1243 * \param[in] env execution environment for this thread
1244 * \param[in] dt object
1245 * \param[in] lb array of descriptors for the buffers
1246 * \param[in] nr size of the array
1247 * \param[in] th transaction handle
1249 * \retval 0 on success
1250 * \retval negative negated errno on error
1252 int (*dbo_write_commit)(const struct lu_env *env,
1253 struct dt_object *dt,
1254 struct niobuf_local *lb,
1256 struct thandle *th);
1259 * Return logical to physical block mapping for a given extent
1261 * \param[in] env execution environment for this thread
1262 * \param[in] dt object
1263 * \param[in] fm describe the region to map and the output buffer
1264 * see the details in include/linux/fiemap.h
1266 * \retval 0 on success
1267 * \retval negative negated errno on error
1269 int (*dbo_fiemap_get)(const struct lu_env *env,
1270 struct dt_object *dt,
1274 * Declare intention to deallocate space from an object.
1276 * Notify the underlying filesystem that space may be deallocated in
1277 * this transactions. This enables the layer below to prepare resources
1278 * (e.g. journal credits in ext4). This method should be called between
1279 * creating the transaction and starting it. The object need not exist.
1281 * \param[in] env execution environment for this thread
1282 * \param[in] dt object
1283 * \param[in] start the start of the region to deallocate
1284 * \param[in] end the end of the region to deallocate
1285 * \param[in] th transaction handle
1287 * \retval 0 on success
1288 * \retval negative negated errno on error
1290 int (*dbo_declare_punch)(const struct lu_env *env,
1291 struct dt_object *dt,
1294 struct thandle *th);
1297 * Deallocate specified region in an object.
1299 * This method is used to deallocate (release) space possibly consumed
1300 * by the given region of the object. If the layer implementing this
1301 * method is responsible for quota, then the method should maintain
1302 * space accounting for the given credentials.
1304 * \param[in] env execution environment for this thread
1305 * \param[in] dt object
1306 * \param[in] start the start of the region to deallocate
1307 * \param[in] end the end of the region to deallocate
1308 * \param[in] th transaction handle
1310 * \retval 0 on success
1311 * \retval negative negated errno on error
1313 int (*dbo_punch)(const struct lu_env *env,
1314 struct dt_object *dt,
1317 struct thandle *th);
1321 * Incomplete type of index record.
1326 * Incomplete type of index key.
1331 * Incomplete type of dt iterator.
1336 * Per-dt-object operations on object as index. Index is a set of key/value
1337 * pairs abstracted from an on-disk representation. An index supports the
1338 * number of operations including lookup by key, insert and delete. Also,
1339 * an index can be iterated to find the pairs one by one, from a beginning
1340 * or specified point.
1342 struct dt_index_operations {
1344 * Lookup in an index by key.
1346 * The method returns a value for the given key. Key/value format
1347 * and size should have been negotiated with ->do_index_try() before.
1348 * Thus it's the caller's responsibility to provide the method with
1349 * proper key and big enough buffer. No external locking is required,
1350 * all the internal consistency should be implemented by the method
1351 * or lower layers. The object should should have been created with
1352 * type DFT_INDEX or DFT_DIR.
1354 * \param[in] env execution environment for this thread
1355 * \param[in] dt object
1356 * \param[out] rec buffer where value will be stored
1357 * \param[in] key key
1359 * \retval 0 on success
1360 * \retval -ENOENT if key isn't found
1361 * \retval negative negated errno on error
1363 int (*dio_lookup)(const struct lu_env *env,
1364 struct dt_object *dt,
1366 const struct dt_key *key);
1369 * Declare intention to insert a key/value into an index.
1371 * Notify the underlying filesystem that new key/value may be inserted
1372 * in this transaction. This enables the layer below to prepare
1373 * resources (e.g. journal credits in ext4). This method should be
1374 * called between creating the transaction and starting it. key/value
1375 * format and size is subject to ->do_index_try().
1377 * \param[in] env execution environment for this thread
1378 * \param[in] dt object
1379 * \param[in] rec buffer storing value
1380 * \param[in] key key
1381 * \param[in] th transaction handle
1383 * \retval 0 on success
1384 * \retval negative negated errno on error
1386 int (*dio_declare_insert)(const struct lu_env *env,
1387 struct dt_object *dt,
1388 const struct dt_rec *rec,
1389 const struct dt_key *key,
1390 struct thandle *th);
1393 * Insert a new key/value pair into an index.
1395 * The method inserts specified key/value pair into the given index
1396 * object. The internal consistency is maintained by the method or
1397 * the functionality below. The format and size of key/value should
1398 * have been negotiated before using ->do_index_try(), no additional
1399 * information can be specified to the method. The keys are unique
1402 * \param[in] env execution environment for this thread
1403 * \param[in] dt object
1404 * \param[in] rec buffer storing value
1405 * \param[in] key key
1406 * \param[in] th transaction handle
1407 * \param[in] ignore unused (was used to request quota ignorance)
1409 * \retval 0 on success
1410 * \retval negative negated errno on error
1412 int (*dio_insert)(const struct lu_env *env,
1413 struct dt_object *dt,
1414 const struct dt_rec *rec,
1415 const struct dt_key *key,
1420 * Declare intention to delete a key/value from an index.
1422 * Notify the underlying filesystem that key/value may be deleted in
1423 * this transaction. This enables the layer below to prepare resources
1424 * (e.g. journal credits in ext4). This method should be called
1425 * between creating the transaction and starting it. Key/value format
1426 * and size is subject to ->do_index_try(). The object need not exist.
1428 * \param[in] env execution environment for this thread
1429 * \param[in] dt object
1430 * \param[in] key key
1431 * \param[in] th transaction handle
1433 * \retval 0 on success
1434 * \retval negative negated errno on error
1436 int (*dio_declare_delete)(const struct lu_env *env,
1437 struct dt_object *dt,
1438 const struct dt_key *key,
1439 struct thandle *th);
1442 * Delete key/value pair from an index.
1444 * The method deletes specified key and corresponding value from the
1445 * given index object. The internal consistency is maintained by the
1446 * method or the functionality below. The format and size of the key
1447 * should have been negotiated before using ->do_index_try(), no
1448 * additional information can be specified to the method.
1450 * \param[in] env execution environment for this thread
1451 * \param[in] dt object
1452 * \param[in] key key
1453 * \param[in] th transaction handle
1455 * \retval 0 on success
1456 * \retval negative negated errno on error
1458 int (*dio_delete)(const struct lu_env *env,
1459 struct dt_object *dt,
1460 const struct dt_key *key,
1461 struct thandle *th);
1464 * Iterator interface.
1466 * Methods to iterate over an existing index, list the keys stored and
1467 * associated values, get key/value size, etc.
1471 * Allocate and initialize new iterator.
1473 * The iterator is a handler to be used in the subsequent
1474 * methods to access index's content. Note the position is
1475 * not defined at this point and should be initialized with
1476 * ->get() or ->load() method.
1478 * \param[in] env execution environment for this thread
1479 * \param[in] dt object
1480 * \param[in] attr ask the iterator to return part of
1481 the records, see LUDA_* for details
1483 * \retval pointer iterator pointer on success
1484 * \retval ERR_PTR(errno) on error
1486 struct dt_it *(*init)(const struct lu_env *env,
1487 struct dt_object *dt,
1493 * Release the specified iterator and all the resources
1494 * associated (e.g. the object, index cache, etc).
1496 * \param[in] env execution environment for this thread
1497 * \param[in] di iterator to release
1499 void (*fini)(const struct lu_env *env,
1503 * Move position of iterator.
1505 * Move the position of the specified iterator to the specified
1508 * \param[in] env execution environment for this thread
1509 * \param[in] di iterator
1510 * \param[in] key key to position to
1512 * \retval 0 if exact key is found
1513 * \retval 1 if at the record with least key
1514 * not larger than the key
1515 * \retval negative negated errno on error
1517 int (*get)(const struct lu_env *env,
1519 const struct dt_key *key);
1524 * Complimentary method for dt_it_ops::get() above. Some
1525 * implementation can increase a reference on the iterator in
1526 * dt_it_ops::get(). So the caller should be able to release
1527 * with dt_it_ops::put().
1529 * \param[in] env execution environment for this thread
1530 * \param[in] di iterator
1532 void (*put)(const struct lu_env *env,
1536 * Move to next record.
1538 * Moves the position of the iterator to a next record
1540 * \param[in] env execution environment for this thread
1541 * \param[in] di iterator
1543 * \retval 1 if no more records
1544 * \retval 0 on success, the next record is found
1545 * \retval negative negated errno on error
1547 int (*next)(const struct lu_env *env,
1553 * Returns a pointer to a buffer containing the key of the
1554 * record at the current position. The pointer is valid and
1555 * retains data until ->get(), ->load() and ->fini() methods
1558 * \param[in] env execution environment for this thread
1559 * \param[in] di iterator
1561 * \retval pointer to key on success
1562 * \retval ERR_PTR(errno) on error
1564 struct dt_key *(*key)(const struct lu_env *env,
1565 const struct dt_it *di);
1570 * Returns size of the key at the current position.
1572 * \param[in] env execution environment for this thread
1573 * \param[in] di iterator
1575 * \retval key's size on success
1576 * \retval negative negated errno on error
1578 int (*key_size)(const struct lu_env *env,
1579 const struct dt_it *di);
1584 * Stores the value of the record at the current position. The
1585 * buffer must be big enough (as negotiated with
1586 * ->do_index_try() or ->rec_size()). The caller can specify
1587 * she is interested only in part of the record, using attr
1588 * argument (see LUDA_* definitions for the details).
1590 * \param[in] env execution environment for this thread
1591 * \param[in] di iterator
1592 * \param[out] rec buffer to store value in
1593 * \param[in] attr specify part of the value to copy
1595 * \retval 0 on success
1596 * \retval negative negated errno on error
1598 int (*rec)(const struct lu_env *env,
1599 const struct dt_it *di,
1604 * Return record size.
1606 * Returns size of the record at the current position. The
1607 * \a attr can be used to specify only the parts of the record
1608 * needed to be returned. (see LUDA_* definitions for the
1611 * \param[in] env execution environment for this thread
1612 * \param[in] di iterator
1613 * \param[in] attr part of the record to return
1615 * \retval record's size on success
1616 * \retval negative negated errno on error
1618 int (*rec_size)(const struct lu_env *env,
1619 const struct dt_it *di,
1623 * Return a cookie (hash).
1625 * Returns the cookie (usually hash) of the key at the current
1626 * position. This allows the caller to resume iteration at this
1627 * position later. The exact value is specific to implementation
1628 * and should not be interpreted by the caller.
1630 * \param[in] env execution environment for this thread
1631 * \param[in] di iterator
1633 * \retval cookie/hash of the key
1635 __u64 (*store)(const struct lu_env *env,
1636 const struct dt_it *di);
1639 * Initialize position using cookie/hash.
1641 * Initializes the current position of the iterator to one
1642 * described by the cookie/hash as returned by ->store()
1645 * \param[in] env execution environment for this thread
1646 * \param[in] di iterator
1647 * \param[in] hash cookie/hash value
1649 * \retval positive if current position points to
1650 * record with least cookie not larger
1652 * \retval 0 if current position matches cookie
1653 * \retval negative negated errno on error
1655 int (*load)(const struct lu_env *env,
1656 const struct dt_it *di,
1662 int (*key_rec)(const struct lu_env *env,
1663 const struct dt_it *di,
1668 enum dt_otable_it_valid {
1669 DOIV_ERROR_HANDLE = 0x0001,
1670 DOIV_DRYRUN = 0x0002,
1673 enum dt_otable_it_flags {
1674 /* Exit when fail. */
1675 DOIF_FAILOUT = 0x0001,
1677 /* Reset iteration position to the device beginning. */
1678 DOIF_RESET = 0x0002,
1680 /* There is up layer component uses the iteration. */
1681 DOIF_OUTUSED = 0x0004,
1683 /* Check only without repairing. */
1684 DOIF_DRYRUN = 0x0008,
1687 /* otable based iteration needs to use the common DT iteration APIs.
1688 * To initialize the iteration, it needs call dio_it::init() firstly.
1689 * Here is how the otable based iteration should prepare arguments to
1690 * call dt_it_ops::init().
1692 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1693 * is composed of two parts:
1694 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1695 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1696 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1699 struct lu_device dd_lu_dev;
1700 const struct dt_device_operations *dd_ops;
1703 * List of dt_txn_callback (see below). This is not protected in any
1704 * way, because callbacks are supposed to be added/deleted only during
1705 * single-threaded start-up shut-down procedures.
1707 struct list_head dd_txn_callbacks;
1708 unsigned int dd_record_fid_accessed:1;
1711 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1712 void dt_device_fini(struct dt_device *dev);
1714 static inline int lu_device_is_dt(const struct lu_device *d)
1716 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1719 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1721 LASSERT(lu_device_is_dt(l));
1722 return container_of0(l, struct dt_device, dd_lu_dev);
1726 struct lu_object do_lu;
1727 const struct dt_object_operations *do_ops;
1728 const struct dt_body_operations *do_body_ops;
1729 const struct dt_index_operations *do_index_ops;
1733 * In-core representation of per-device local object OID storage
1735 struct local_oid_storage {
1736 /* all initialized llog systems on this node linked by this */
1737 struct list_head los_list;
1739 /* how many handle's reference this los has */
1740 atomic_t los_refcount;
1741 struct dt_device *los_dev;
1742 struct dt_object *los_obj;
1744 /* data used to generate new fids */
1745 struct mutex los_id_lock;
1750 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1752 return &d->dd_lu_dev;
1755 static inline struct dt_object *lu2dt(struct lu_object *l)
1757 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1758 return container_of0(l, struct dt_object, do_lu);
1761 int dt_object_init(struct dt_object *obj,
1762 struct lu_object_header *h, struct lu_device *d);
1764 void dt_object_fini(struct dt_object *obj);
1766 static inline int dt_object_exists(const struct dt_object *dt)
1768 return lu_object_exists(&dt->do_lu);
1771 static inline int dt_object_remote(const struct dt_object *dt)
1773 return lu_object_remote(&dt->do_lu);
1776 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1778 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1779 return container_of0(o, struct dt_object, do_lu);
1782 static inline struct dt_object *dt_object_child(struct dt_object *o)
1784 return container_of0(lu_object_next(&(o)->do_lu),
1785 struct dt_object, do_lu);
1789 * This is the general purpose transaction handle.
1790 * 1. Transaction Life Cycle
1791 * This transaction handle is allocated upon starting a new transaction,
1792 * and deallocated after this transaction is committed.
1793 * 2. Transaction Nesting
1794 * We do _NOT_ support nested transaction. So, every thread should only
1795 * have one active transaction, and a transaction only belongs to one
1796 * thread. Due to this, transaction handle need no reference count.
1797 * 3. Transaction & dt_object locking
1798 * dt_object locks should be taken inside transaction.
1799 * 4. Transaction & RPC
1800 * No RPC request should be issued inside transaction.
1803 /** the dt device on which the transactions are executed */
1804 struct dt_device *th_dev;
1806 /* point to the top thandle, XXX this is a bit hacky right now,
1807 * but normal device trans callback triggered by the bottom
1808 * device (OSP/OSD == sub thandle layer) needs to get the
1809 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1810 * top thandle here for now, will fix it when we have better
1811 * callback mechanism */
1812 struct thandle *th_top;
1813 /** context for this transaction, tag is LCT_TX_HANDLE */
1814 struct lu_context th_ctx;
1816 /** additional tags (layers can add in declare) */
1819 /** the last operation result in this transaction.
1820 * this value is used in recovery */
1823 /** whether we need sync commit */
1824 unsigned int th_sync:1,
1825 /* local transation, no need to inform other layers */
1827 /* Whether we need wait the transaction to be submitted */
1829 /* complex transaction which will track updates on all targets */
1834 * Transaction call-backs.
1836 * These are invoked by osd (or underlying transaction engine) when
1837 * transaction changes state.
1839 * Call-backs are used by upper layers to modify transaction parameters and to
1840 * perform some actions on for each transaction state transition. Typical
1841 * example is mdt registering call-back to write into last-received file
1842 * before each transaction commit.
1844 struct dt_txn_callback {
1845 int (*dtc_txn_start)(const struct lu_env *env,
1846 struct thandle *txn, void *cookie);
1847 int (*dtc_txn_stop)(const struct lu_env *env,
1848 struct thandle *txn, void *cookie);
1849 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1852 struct list_head dtc_linkage;
1855 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1856 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1858 int dt_txn_hook_start(const struct lu_env *env,
1859 struct dt_device *dev, struct thandle *txn);
1860 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1861 void dt_txn_hook_commit(struct thandle *txn);
1863 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1866 * Callback function used for parsing path.
1867 * \see llo_store_resolve
1869 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1873 #define DT_MAX_PATH 1024
1875 int dt_path_parser(const struct lu_env *env,
1876 char *local, dt_entry_func_t entry_func,
1880 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1881 const char *path, struct lu_fid *fid);
1883 struct dt_object *dt_store_open(const struct lu_env *env,
1884 struct dt_device *dt,
1885 const char *dirname,
1886 const char *filename,
1887 struct lu_fid *fid);
1889 struct dt_object *dt_find_or_create(const struct lu_env *env,
1890 struct dt_device *dt,
1891 const struct lu_fid *fid,
1892 struct dt_object_format *dof,
1893 struct lu_attr *attr);
1895 struct dt_object *dt_locate_at(const struct lu_env *env,
1896 struct dt_device *dev,
1897 const struct lu_fid *fid,
1898 struct lu_device *top_dev,
1899 const struct lu_object_conf *conf);
1901 static inline struct dt_object *
1902 dt_locate(const struct lu_env *env, struct dt_device *dev,
1903 const struct lu_fid *fid)
1905 return dt_locate_at(env, dev, fid,
1906 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1909 static inline struct dt_object *
1910 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1912 struct lu_object *lo;
1914 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
1915 if (lo->lo_dev == &dt_dev->dd_lu_dev)
1916 return container_of(lo, struct dt_object, do_lu);
1921 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
1922 const struct lu_fid *first_fid,
1923 struct local_oid_storage **los);
1924 void local_oid_storage_fini(const struct lu_env *env,
1925 struct local_oid_storage *los);
1926 int local_object_fid_generate(const struct lu_env *env,
1927 struct local_oid_storage *los,
1928 struct lu_fid *fid);
1929 int local_object_declare_create(const struct lu_env *env,
1930 struct local_oid_storage *los,
1931 struct dt_object *o,
1932 struct lu_attr *attr,
1933 struct dt_object_format *dof,
1934 struct thandle *th);
1935 int local_object_create(const struct lu_env *env,
1936 struct local_oid_storage *los,
1937 struct dt_object *o,
1938 struct lu_attr *attr, struct dt_object_format *dof,
1939 struct thandle *th);
1940 struct dt_object *local_file_find_or_create(const struct lu_env *env,
1941 struct local_oid_storage *los,
1942 struct dt_object *parent,
1943 const char *name, __u32 mode);
1944 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
1945 struct dt_device *dt,
1946 const struct lu_fid *fid,
1947 struct dt_object *parent,
1951 local_index_find_or_create(const struct lu_env *env,
1952 struct local_oid_storage *los,
1953 struct dt_object *parent,
1954 const char *name, __u32 mode,
1955 const struct dt_index_features *ft);
1957 local_index_find_or_create_with_fid(const struct lu_env *env,
1958 struct dt_device *dt,
1959 const struct lu_fid *fid,
1960 struct dt_object *parent,
1961 const char *name, __u32 mode,
1962 const struct dt_index_features *ft);
1963 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
1964 struct dt_object *parent, const char *name);
1966 static inline int dt_object_lock(const struct lu_env *env,
1967 struct dt_object *o, struct lustre_handle *lh,
1968 struct ldlm_enqueue_info *einfo,
1969 union ldlm_policy_data *policy)
1972 LASSERT(o->do_ops != NULL);
1973 LASSERT(o->do_ops->do_object_lock != NULL);
1974 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
1977 static inline int dt_object_unlock(const struct lu_env *env,
1978 struct dt_object *o,
1979 struct ldlm_enqueue_info *einfo,
1980 union ldlm_policy_data *policy)
1983 LASSERT(o->do_ops != NULL);
1984 LASSERT(o->do_ops->do_object_unlock != NULL);
1985 return o->do_ops->do_object_unlock(env, o, einfo, policy);
1988 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
1989 const char *name, struct lu_fid *fid);
1991 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
1992 __u64 start, __u64 end)
1996 LASSERT(o->do_ops->do_object_sync);
1997 return o->do_ops->do_object_sync(env, o, start, end);
2000 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2001 struct thandle *th);
2002 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2003 dt_obj_version_t version, struct thandle *th);
2004 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2007 int dt_read(const struct lu_env *env, struct dt_object *dt,
2008 struct lu_buf *buf, loff_t *pos);
2009 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2010 struct lu_buf *buf, loff_t *pos);
2011 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2012 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2013 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2014 union lu_page *lp, size_t nob,
2015 const struct dt_it_ops *iops,
2016 struct dt_it *it, __u32 attr, void *arg);
2017 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2018 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2020 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2021 struct idx_info *ii, const struct lu_rdpg *rdpg);
2023 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2024 struct dt_device *d)
2026 LASSERT(d->dd_ops->dt_trans_create);
2027 return d->dd_ops->dt_trans_create(env, d);
2030 static inline int dt_trans_start(const struct lu_env *env,
2031 struct dt_device *d, struct thandle *th)
2033 LASSERT(d->dd_ops->dt_trans_start);
2034 return d->dd_ops->dt_trans_start(env, d, th);
2037 /* for this transaction hooks shouldn't be called */
2038 static inline int dt_trans_start_local(const struct lu_env *env,
2039 struct dt_device *d, struct thandle *th)
2041 LASSERT(d->dd_ops->dt_trans_start);
2043 return d->dd_ops->dt_trans_start(env, d, th);
2046 static inline int dt_trans_stop(const struct lu_env *env,
2047 struct dt_device *d, struct thandle *th)
2049 LASSERT(d->dd_ops->dt_trans_stop);
2050 return d->dd_ops->dt_trans_stop(env, d, th);
2053 static inline int dt_trans_cb_add(struct thandle *th,
2054 struct dt_txn_commit_cb *dcb)
2056 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2057 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2058 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2063 static inline int dt_declare_record_write(const struct lu_env *env,
2064 struct dt_object *dt,
2065 const struct lu_buf *buf,
2071 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2072 LASSERT(th != NULL);
2073 LASSERT(dt->do_body_ops);
2074 LASSERT(dt->do_body_ops->dbo_declare_write);
2075 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2079 static inline int dt_declare_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_declare_create);
2090 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2091 return cfs_fail_err;
2093 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2096 static inline int dt_create(const struct lu_env *env,
2097 struct dt_object *dt,
2098 struct lu_attr *attr,
2099 struct dt_allocation_hint *hint,
2100 struct dt_object_format *dof,
2104 LASSERT(dt->do_ops);
2105 LASSERT(dt->do_ops->do_create);
2107 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2108 return cfs_fail_err;
2110 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2113 static inline int dt_declare_destroy(const struct lu_env *env,
2114 struct dt_object *dt,
2118 LASSERT(dt->do_ops);
2119 LASSERT(dt->do_ops->do_declare_destroy);
2121 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2122 return cfs_fail_err;
2124 return dt->do_ops->do_declare_destroy(env, dt, th);
2127 static inline int dt_destroy(const struct lu_env *env,
2128 struct dt_object *dt,
2132 LASSERT(dt->do_ops);
2133 LASSERT(dt->do_ops->do_destroy);
2135 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2136 return cfs_fail_err;
2138 return dt->do_ops->do_destroy(env, dt, th);
2141 static inline void dt_read_lock(const struct lu_env *env,
2142 struct dt_object *dt,
2146 LASSERT(dt->do_ops);
2147 LASSERT(dt->do_ops->do_read_lock);
2148 dt->do_ops->do_read_lock(env, dt, role);
2151 static inline void dt_write_lock(const struct lu_env *env,
2152 struct dt_object *dt,
2156 LASSERT(dt->do_ops);
2157 LASSERT(dt->do_ops->do_write_lock);
2158 dt->do_ops->do_write_lock(env, dt, role);
2161 static inline void dt_read_unlock(const struct lu_env *env,
2162 struct dt_object *dt)
2165 LASSERT(dt->do_ops);
2166 LASSERT(dt->do_ops->do_read_unlock);
2167 dt->do_ops->do_read_unlock(env, dt);
2170 static inline void dt_write_unlock(const struct lu_env *env,
2171 struct dt_object *dt)
2174 LASSERT(dt->do_ops);
2175 LASSERT(dt->do_ops->do_write_unlock);
2176 dt->do_ops->do_write_unlock(env, dt);
2179 static inline int dt_write_locked(const struct lu_env *env,
2180 struct dt_object *dt)
2183 LASSERT(dt->do_ops);
2184 LASSERT(dt->do_ops->do_write_locked);
2185 return dt->do_ops->do_write_locked(env, dt);
2188 static inline int dt_declare_attr_get(const struct lu_env *env,
2189 struct dt_object *dt)
2192 LASSERT(dt->do_ops);
2193 LASSERT(dt->do_ops->do_declare_attr_get);
2195 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2196 return cfs_fail_err;
2198 return dt->do_ops->do_declare_attr_get(env, dt);
2201 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2205 LASSERT(dt->do_ops);
2206 LASSERT(dt->do_ops->do_attr_get);
2208 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2209 return cfs_fail_err;
2211 return dt->do_ops->do_attr_get(env, dt, la);
2214 static inline int dt_declare_attr_set(const struct lu_env *env,
2215 struct dt_object *dt,
2216 const struct lu_attr *la,
2220 LASSERT(dt->do_ops);
2221 LASSERT(dt->do_ops->do_declare_attr_set);
2223 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2224 return cfs_fail_err;
2226 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2229 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2230 const struct lu_attr *la, struct thandle *th)
2233 LASSERT(dt->do_ops);
2234 LASSERT(dt->do_ops->do_attr_set);
2236 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2237 return cfs_fail_err;
2239 return dt->do_ops->do_attr_set(env, dt, la, th);
2242 static inline int dt_declare_ref_add(const struct lu_env *env,
2243 struct dt_object *dt, struct thandle *th)
2246 LASSERT(dt->do_ops);
2247 LASSERT(dt->do_ops->do_declare_ref_add);
2249 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2250 return cfs_fail_err;
2252 return dt->do_ops->do_declare_ref_add(env, dt, th);
2255 static inline int dt_ref_add(const struct lu_env *env,
2256 struct dt_object *dt, struct thandle *th)
2259 LASSERT(dt->do_ops);
2260 LASSERT(dt->do_ops->do_ref_add);
2262 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2263 return cfs_fail_err;
2265 return dt->do_ops->do_ref_add(env, dt, th);
2268 static inline int dt_declare_ref_del(const struct lu_env *env,
2269 struct dt_object *dt, struct thandle *th)
2272 LASSERT(dt->do_ops);
2273 LASSERT(dt->do_ops->do_declare_ref_del);
2275 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2276 return cfs_fail_err;
2278 return dt->do_ops->do_declare_ref_del(env, dt, th);
2281 static inline int dt_ref_del(const struct lu_env *env,
2282 struct dt_object *dt, struct thandle *th)
2285 LASSERT(dt->do_ops);
2286 LASSERT(dt->do_ops->do_ref_del);
2288 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2289 return cfs_fail_err;
2291 return dt->do_ops->do_ref_del(env, dt, th);
2294 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2295 struct niobuf_remote *rnb,
2296 struct niobuf_local *lnb, int rw)
2299 LASSERT(d->do_body_ops);
2300 LASSERT(d->do_body_ops->dbo_bufs_get);
2301 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2302 rnb->rnb_len, lnb, rw);
2305 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2306 struct niobuf_local *lnb, int n)
2309 LASSERT(d->do_body_ops);
2310 LASSERT(d->do_body_ops->dbo_bufs_put);
2311 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2314 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2315 struct niobuf_local *lnb, int n)
2318 LASSERT(d->do_body_ops);
2319 LASSERT(d->do_body_ops->dbo_write_prep);
2320 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2323 static inline int dt_declare_write_commit(const struct lu_env *env,
2324 struct dt_object *d,
2325 struct niobuf_local *lnb,
2326 int n, struct thandle *th)
2328 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2329 LASSERT(th != NULL);
2330 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2334 static inline int dt_write_commit(const struct lu_env *env,
2335 struct dt_object *d, struct niobuf_local *lnb,
2336 int n, struct thandle *th)
2339 LASSERT(d->do_body_ops);
2340 LASSERT(d->do_body_ops->dbo_write_commit);
2341 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2344 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2345 struct niobuf_local *lnb, int n)
2348 LASSERT(d->do_body_ops);
2349 LASSERT(d->do_body_ops->dbo_read_prep);
2350 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2353 static inline int dt_declare_write(const struct lu_env *env,
2354 struct dt_object *dt,
2355 const struct lu_buf *buf, loff_t pos,
2359 LASSERT(dt->do_body_ops);
2360 LASSERT(dt->do_body_ops->dbo_declare_write);
2361 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2364 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2365 const struct lu_buf *buf, loff_t *pos,
2366 struct thandle *th, int rq)
2369 LASSERT(dt->do_body_ops);
2370 LASSERT(dt->do_body_ops->dbo_write);
2371 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th, rq);
2374 static inline int dt_declare_punch(const struct lu_env *env,
2375 struct dt_object *dt, __u64 start,
2376 __u64 end, struct thandle *th)
2379 LASSERT(dt->do_body_ops);
2380 LASSERT(dt->do_body_ops->dbo_declare_punch);
2381 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2384 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2385 __u64 start, __u64 end, struct thandle *th)
2388 LASSERT(dt->do_body_ops);
2389 LASSERT(dt->do_body_ops->dbo_punch);
2390 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2393 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2397 if (d->do_body_ops == NULL)
2399 if (d->do_body_ops->dbo_fiemap_get == NULL)
2401 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2404 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2405 struct obd_statfs *osfs)
2408 LASSERT(dev->dd_ops);
2409 LASSERT(dev->dd_ops->dt_statfs);
2410 return dev->dd_ops->dt_statfs(env, dev, osfs);
2413 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2417 LASSERT(dev->dd_ops);
2418 LASSERT(dev->dd_ops->dt_root_get);
2419 return dev->dd_ops->dt_root_get(env, dev, f);
2422 static inline void dt_conf_get(const struct lu_env *env,
2423 const struct dt_device *dev,
2424 struct dt_device_param *param)
2427 LASSERT(dev->dd_ops);
2428 LASSERT(dev->dd_ops->dt_conf_get);
2429 return dev->dd_ops->dt_conf_get(env, dev, param);
2432 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2435 LASSERT(dev->dd_ops);
2436 LASSERT(dev->dd_ops->dt_sync);
2437 return dev->dd_ops->dt_sync(env, dev);
2440 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2443 LASSERT(dev->dd_ops);
2444 LASSERT(dev->dd_ops->dt_ro);
2445 return dev->dd_ops->dt_ro(env, dev);
2448 static inline int dt_declare_insert(const struct lu_env *env,
2449 struct dt_object *dt,
2450 const struct dt_rec *rec,
2451 const struct dt_key *key,
2455 LASSERT(dt->do_index_ops);
2456 LASSERT(dt->do_index_ops->dio_declare_insert);
2458 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2459 return cfs_fail_err;
2461 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2464 static inline int dt_insert(const struct lu_env *env,
2465 struct dt_object *dt,
2466 const struct dt_rec *rec,
2467 const struct dt_key *key,
2472 LASSERT(dt->do_index_ops);
2473 LASSERT(dt->do_index_ops->dio_insert);
2475 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2476 return cfs_fail_err;
2478 return dt->do_index_ops->dio_insert(env, dt, rec, key, th, noquota);
2481 static inline int dt_declare_xattr_del(const struct lu_env *env,
2482 struct dt_object *dt,
2487 LASSERT(dt->do_ops);
2488 LASSERT(dt->do_ops->do_declare_xattr_del);
2490 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2491 return cfs_fail_err;
2493 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2496 static inline int dt_xattr_del(const struct lu_env *env,
2497 struct dt_object *dt, const char *name,
2501 LASSERT(dt->do_ops);
2502 LASSERT(dt->do_ops->do_xattr_del);
2504 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2505 return cfs_fail_err;
2507 return dt->do_ops->do_xattr_del(env, dt, name, th);
2510 static inline int dt_declare_xattr_set(const struct lu_env *env,
2511 struct dt_object *dt,
2512 const struct lu_buf *buf,
2513 const char *name, int fl,
2517 LASSERT(dt->do_ops);
2518 LASSERT(dt->do_ops->do_declare_xattr_set);
2520 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2521 return cfs_fail_err;
2523 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2526 static inline int dt_xattr_set(const struct lu_env *env,
2527 struct dt_object *dt, const struct lu_buf *buf,
2528 const char *name, int fl, struct thandle *th)
2531 LASSERT(dt->do_ops);
2532 LASSERT(dt->do_ops->do_xattr_set);
2534 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2535 return cfs_fail_err;
2537 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2540 static inline int dt_declare_xattr_get(const struct lu_env *env,
2541 struct dt_object *dt,
2546 LASSERT(dt->do_ops);
2547 LASSERT(dt->do_ops->do_declare_xattr_get);
2549 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2550 return cfs_fail_err;
2552 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2555 static inline int dt_xattr_get(const struct lu_env *env,
2556 struct dt_object *dt, struct lu_buf *buf,
2560 LASSERT(dt->do_ops);
2561 LASSERT(dt->do_ops->do_xattr_get);
2563 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2564 return cfs_fail_err;
2566 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2569 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2570 const struct lu_buf *buf)
2573 LASSERT(dt->do_ops);
2574 LASSERT(dt->do_ops->do_xattr_list);
2576 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2577 return cfs_fail_err;
2579 return dt->do_ops->do_xattr_list(env, dt, buf);
2582 static inline int dt_declare_delete(const struct lu_env *env,
2583 struct dt_object *dt,
2584 const struct dt_key *key,
2588 LASSERT(dt->do_index_ops);
2589 LASSERT(dt->do_index_ops->dio_declare_delete);
2591 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2592 return cfs_fail_err;
2594 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2597 static inline int dt_delete(const struct lu_env *env,
2598 struct dt_object *dt,
2599 const struct dt_key *key,
2603 LASSERT(dt->do_index_ops);
2604 LASSERT(dt->do_index_ops->dio_delete);
2606 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2607 return cfs_fail_err;
2609 return dt->do_index_ops->dio_delete(env, dt, key, th);
2612 static inline int dt_commit_async(const struct lu_env *env,
2613 struct dt_device *dev)
2616 LASSERT(dev->dd_ops);
2617 LASSERT(dev->dd_ops->dt_commit_async);
2618 return dev->dd_ops->dt_commit_async(env, dev);
2621 static inline int dt_lookup(const struct lu_env *env,
2622 struct dt_object *dt,
2624 const struct dt_key *key)
2629 LASSERT(dt->do_index_ops);
2630 LASSERT(dt->do_index_ops->dio_lookup);
2632 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2633 return cfs_fail_err;
2635 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2643 struct dt_find_hint {
2644 struct lu_fid *dfh_fid;
2645 struct dt_device *dfh_dt;
2646 struct dt_object *dfh_o;
2649 struct dt_insert_rec {
2651 const struct lu_fid *rec_fid;
2663 struct dt_thread_info {
2664 char dti_buf[DT_MAX_PATH];
2665 struct dt_find_hint dti_dfh;
2666 struct lu_attr dti_attr;
2667 struct lu_fid dti_fid;
2668 struct dt_object_format dti_dof;
2669 struct lustre_mdt_attrs dti_lma;
2670 struct lu_buf dti_lb;
2671 struct lu_object_conf dti_conf;
2673 struct dt_insert_rec dti_dt_rec;
2676 extern struct lu_context_key dt_key;
2678 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2680 struct dt_thread_info *dti;
2682 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2687 int dt_global_init(void);
2688 void dt_global_fini(void);
2690 # ifdef CONFIG_PROC_FS
2691 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2692 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2693 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2694 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2695 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2696 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2697 # endif /* CONFIG_PROC_FS */
2699 #endif /* __LUSTRE_DT_OBJECT_H */