4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #ifndef __LUSTRE_DT_OBJECT_H
34 #define __LUSTRE_DT_OBJECT_H
37 * Sub-class of lu_object with methods common for "data" objects in OST stack.
39 * Data objects behave like regular files: you can read/write them, get and
40 * set their attributes. Implementation of dt interface is supposed to
41 * implement some form of garbage collection, normally reference counting
44 * Examples: osd (lustre/osd) is an implementation of dt interface.
48 #include <obd_support.h>
50 * super-class definitions.
52 #include <lu_object.h>
54 #include <libcfs/libcfs.h>
57 struct proc_dir_entry;
63 struct dt_index_features;
66 struct ldlm_enqueue_info;
69 MNTOPT_USERXATTR = 0x00000001,
70 MNTOPT_ACL = 0x00000002,
73 struct dt_device_param {
74 unsigned ddp_max_name_len;
75 unsigned ddp_max_nlink;
76 unsigned ddp_symlink_max;
78 unsigned ddp_max_ea_size;
79 unsigned ddp_mount_type;
80 unsigned long long ddp_maxbytes;
81 /* per-inode space consumption */
83 /* maximum number of blocks in an extent */
84 unsigned ddp_max_extent_blks;
85 /* per-extent insertion overhead to be used by client for grant
87 unsigned ddp_extent_tax;
91 * Per-transaction commit callback function
93 struct dt_txn_commit_cb;
94 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
95 struct dt_txn_commit_cb *cb, int err);
97 * Special per-transaction callback for cases when just commit callback
98 * is needed and per-device callback are not convenient to use
100 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
101 #define MAX_COMMIT_CB_STR_LEN 32
103 #define DCB_TRANS_STOP 0x1
104 struct dt_txn_commit_cb {
105 struct list_head dcb_linkage;
110 char dcb_name[MAX_COMMIT_CB_STR_LEN];
114 * Operations on dt device.
116 struct dt_device_operations {
118 * Return device-wide statistics.
120 * Return device-wide stats including block size, total and
121 * free blocks, total and free objects, etc. See struct obd_statfs
124 * \param[in] env execution environment for this thread
125 * \param[in] dev dt device
126 * \param[out] osfs stats information
128 * \retval 0 on success
129 * \retval negative negated errno on error
131 int (*dt_statfs)(const struct lu_env *env,
132 struct dt_device *dev,
133 struct obd_statfs *osfs);
136 * Create transaction.
138 * Create in-memory structure representing the transaction for the
139 * caller. The structure returned will be used by the calling thread
140 * to specify the transaction the updates belong to. Once created
141 * successfully ->dt_trans_stop() must be called in any case (with
142 * ->dt_trans_start() and updates or not) so that the transaction
143 * handle and other resources can be released by the layers below.
145 * \param[in] env execution environment for this thread
146 * \param[in] dev dt device
148 * \retval pointer to handle if creation succeeds
149 * \retval ERR_PTR(errno) if creation fails
151 struct thandle *(*dt_trans_create)(const struct lu_env *env,
152 struct dt_device *dev);
157 * Start the transaction. The transaction described by \a th can be
158 * started only once. Another start is considered as an error.
159 * A thread is not supposed to start a transaction while another
160 * transaction isn't closed by the thread (though multiple handles
161 * can be created). The caller should start the transaction once
162 * all possible updates are declared (see the ->do_declare_* methods
163 * below) and all the needed resources are reserved.
165 * \param[in] env execution environment for this thread
166 * \param[in] dev dt device
167 * \param[in] th transaction handle
169 * \retval 0 on success
170 * \retval negative negated errno on error
172 int (*dt_trans_start)(const struct lu_env *env,
173 struct dt_device *dev,
179 * Once stopped the transaction described by \a th is complete (all
180 * the needed updates are applied) and further processing such as
181 * flushing to disk, sending to another target, etc, is handled by
182 * lower layers. The caller can't access this transaction by the
183 * handle anymore (except from the commit callbacks, see below).
185 * \param[in] env execution environment for this thread
186 * \param[in] dev dt device
187 * \param[in] th transaction handle
189 * \retval 0 on success
190 * \retval negative negated errno on error
192 int (*dt_trans_stop)(const struct lu_env *env,
193 struct dt_device *dev,
197 * Add commit callback to the transaction.
199 * Add a commit callback to the given transaction handle. The callback
200 * will be called when the associated transaction is stored. I.e. the
201 * transaction will survive an event like power off if the callback did
202 * run. The number of callbacks isn't limited, but you should note that
203 * some disk filesystems do handle the commit callbacks in the thread
204 * handling commit/flush of all the transactions, meaning that new
205 * transactions are blocked from commit and flush until all the
206 * callbacks are done. Also, note multiple callbacks can be running
207 * concurrently using multiple CPU cores. The callbacks will be running
208 * in a special environment which can not be used to pass data around.
210 * \param[in] th transaction handle
211 * \param[in] dcb commit callback description
213 * \retval 0 on success
214 * \retval negative negated errno on error
216 int (*dt_trans_cb_add)(struct thandle *th,
217 struct dt_txn_commit_cb *dcb);
220 * Return FID of root index object.
222 * Return the FID of the root object in the filesystem. This object
223 * is usually provided as a bootstrap point by a disk filesystem.
224 * This is up to the implementation which FID to use, though
225 * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
227 * \param[in] env execution environment for this thread
228 * \param[in] dev dt device
229 * \param[out] fid FID of the root object
231 * \retval 0 on success
232 * \retval negative negated errno on error
234 int (*dt_root_get)(const struct lu_env *env,
235 struct dt_device *dev,
239 * Return device configuration data.
241 * Return device (disk fs, actually) specific configuration.
242 * The configuration isn't subject to change at runtime.
243 * See struct dt_device_param for the details.
245 * \param[in] env execution environment for this thread
246 * \param[in] dev dt device
247 * \param[out] param configuration parameters
249 void (*dt_conf_get)(const struct lu_env *env,
250 const struct dt_device *dev,
251 struct dt_device_param *param);
256 * Sync all the cached state (dirty buffers, pages, etc) to the
257 * persistent storage. The method returns control once the sync is
258 * complete. This operation may incur significant I/O to disk and
259 * should be reserved for cases where a global sync is strictly
262 * \param[in] env execution environment for this thread
263 * \param[in] dev dt device
265 * \retval 0 on success
266 * \retval negative negated errno on error
268 int (*dt_sync)(const struct lu_env *env,
269 struct dt_device *dev);
272 * Make device read-only.
274 * Prevent new modifications to the device. This is a very specific
275 * state where all the changes are accepted successfully and the
276 * commit callbacks are called, but persistent state never changes.
277 * Used only in the tests to simulate power-off scenario.
279 * \param[in] env execution environment for this thread
280 * \param[in] dev dt device
282 * \retval 0 on success
283 * \retval negative negated errno on error
285 int (*dt_ro)(const struct lu_env *env,
286 struct dt_device *dev);
289 * Start transaction commit asynchronously.
292 * Provide a hint to the underlying filesystem that it should start
293 * committing soon. The control returns immediately. It's up to the
294 * layer implementing the method how soon to start committing. Usually
295 * this should be throttled to some extent, otherwise the number of
296 * aggregated transaction goes too high causing performance drop.
298 * \param[in] env execution environment for this thread
299 * \param[in] dev dt device
301 * \retval 0 on success
302 * \retval negative negated errno on error
304 int (*dt_commit_async)(const struct lu_env *env,
305 struct dt_device *dev);
308 struct dt_index_features {
309 /** required feature flags from enum dt_index_flags */
311 /** minimal required key size */
312 size_t dif_keysize_min;
313 /** maximal required key size, 0 if no limit */
314 size_t dif_keysize_max;
315 /** minimal required record size */
316 size_t dif_recsize_min;
317 /** maximal required record size, 0 if no limit */
318 size_t dif_recsize_max;
319 /** pointer size for record */
323 enum dt_index_flags {
324 /** index supports variable sized keys */
325 DT_IND_VARKEY = 1 << 0,
326 /** index supports variable sized records */
327 DT_IND_VARREC = 1 << 1,
328 /** index can be modified */
329 DT_IND_UPDATE = 1 << 2,
330 /** index supports records with non-unique (duplicate) keys */
331 DT_IND_NONUNQ = 1 << 3,
333 * index support fixed-size keys sorted with natural numerical way
334 * and is able to return left-side value if no exact value found
336 DT_IND_RANGE = 1 << 4,
340 * Features, required from index to support file system directories (mapping
343 extern const struct dt_index_features dt_directory_features;
344 extern const struct dt_index_features dt_otable_features;
345 extern const struct dt_index_features dt_lfsck_orphan_features;
346 extern const struct dt_index_features dt_lfsck_features;
348 /* index features supported by the accounting objects */
349 extern const struct dt_index_features dt_acct_features;
351 /* index features supported by the quota global indexes */
352 extern const struct dt_index_features dt_quota_glb_features;
354 /* index features supported by the quota slave indexes */
355 extern const struct dt_index_features dt_quota_slv_features;
357 /* index features supported by the nodemap index */
358 extern const struct dt_index_features dt_nodemap_features;
361 * This is a general purpose dt allocation hint.
362 * It now contains the parent object.
363 * It can contain any allocation hint in the future.
365 struct dt_allocation_hint {
366 struct dt_object *dah_parent;
367 const void *dah_eadata;
373 * object type specifier.
376 enum dt_format_type {
381 /** for special index */
383 /** for symbolic link */
388 * object format specifier.
390 struct dt_object_format {
391 /** type for dt object */
392 enum dt_format_type dof_type;
402 * special index need feature as parameter to create
406 const struct dt_index_features *di_feat;
411 enum dt_format_type dt_mode_to_dft(__u32 mode);
413 typedef __u64 dt_obj_version_t;
415 union ldlm_policy_data;
418 * A dt_object provides common operations to create and destroy
419 * objects and to manage regular and extended attributes.
421 struct dt_object_operations {
423 * Get read lock on object.
425 * Read lock is compatible with other read locks, so it's shared.
426 * Read lock is not compatible with write lock which is exclusive.
427 * The lock is blocking and can't be used from an interrupt context.
429 * \param[in] env execution environment for this thread
430 * \param[in] dt object to lock for reading
431 * \param[in] role a hint to debug locks (see kernel's mutexes)
433 void (*do_read_lock)(const struct lu_env *env,
434 struct dt_object *dt,
438 * Get write lock on object.
440 * Write lock is exclusive and cannot be shared. The lock is blocking
441 * and can't be used from an interrupt context.
443 * \param[in] env execution environment for this thread
444 * \param[in] dt object to lock for writing
445 * \param[in] role a hint to debug locks (see kernel's mutexes)
448 void (*do_write_lock)(const struct lu_env *env,
449 struct dt_object *dt,
455 * \param[in] env execution environment for this thread
456 * \param[in] dt object
458 void (*do_read_unlock)(const struct lu_env *env,
459 struct dt_object *dt);
462 * Release write lock.
464 * \param[in] env execution environment for this thread
465 * \param[in] dt object
467 void (*do_write_unlock)(const struct lu_env *env,
468 struct dt_object *dt);
471 * Check whether write lock is held.
473 * The caller can learn whether write lock is held on the object
475 * \param[in] env execution environment for this thread
476 * \param[in] dt object
478 * \retval 0 no write lock
479 * \retval 1 write lock is held
481 int (*do_write_locked)(const struct lu_env *env,
482 struct dt_object *dt);
485 * Declare intention to request reqular attributes.
487 * Notity the underlying filesystem that the caller may request regular
488 * attributes with ->do_attr_get() soon. This allows OSD to implement
489 * prefetching logic in an object-oriented manner. The implementation
490 * can be noop. This method should avoid expensive delays such as
491 * waiting on disk I/O, otherwise the goal of enabling a performance
492 * optimization would be defeated.
494 * \param[in] env execution environment for this thread
495 * \param[in] dt object
497 * \retval 0 on success
498 * \retval negative negated errno on error
500 int (*do_declare_attr_get)(const struct lu_env *env,
501 struct dt_object *dt);
504 * Return regular attributes.
506 * The object must exist. Currently all the attributes should be
507 * returned, but in the future this can be improved so that only
508 * a selected set is returned. This can improve performance as in
509 * some cases attributes are stored in different places and
510 * getting them all can be an iterative and expensive process.
512 * \param[in] env execution environment for this thread
513 * \param[in] dt object
514 * \param[out] attr attributes to fill
516 * \retval 0 on success
517 * \retval negative negated errno on error
519 int (*do_attr_get)(const struct lu_env *env,
520 struct dt_object *dt,
521 struct lu_attr *attr);
524 * Declare intention to change regular object's attributes.
526 * Notify the underlying filesystem that the regular attributes may
527 * change in this transaction. This enables the layer below to prepare
528 * resources (e.g. journal credits in ext4). This method should be
529 * called between creating the transaction and starting it. Note that
530 * the la_valid field of \a attr specifies which attributes will change.
531 * The object need not exist.
533 * \param[in] env execution environment for this thread
534 * \param[in] dt object
535 * \param[in] attr attributes to change specified in attr.la_valid
536 * \param[in] th transaction handle
538 * \retval 0 on success
539 * \retval negative negated errno on error
541 int (*do_declare_attr_set)(const struct lu_env *env,
542 struct dt_object *dt,
543 const struct lu_attr *attr,
547 * Change regular attributes.
549 * Change regular attributes in the given transaction. Note only
550 * attributes flagged by attr.la_valid change. The object must
551 * exist. If the layer implementing this method is responsible for
552 * quota, then the method should maintain object accounting for the
553 * given credentials when la_uid/la_gid changes.
555 * \param[in] env execution environment for this thread
556 * \param[in] dt object
557 * \param[in] attr new attributes to apply
558 * \param[in] th transaction handle
560 * \retval 0 on success
561 * \retval negative negated errno on error
563 int (*do_attr_set)(const struct lu_env *env,
564 struct dt_object *dt,
565 const struct lu_attr *attr,
569 * Declare intention to request extented attribute.
571 * Notify the underlying filesystem that the caller may request extended
572 * attribute with ->do_xattr_get() soon. This allows OSD to implement
573 * prefetching logic in an object-oriented manner. The implementation
574 * can be noop. This method should avoid expensive delays such as
575 * waiting on disk I/O, otherwise the goal of enabling a performance
576 * optimization would be defeated.
578 * \param[in] env execution environment for this thread
579 * \param[in] dt object
580 * \param[in] buf unused, may be removed in the future
581 * \param[in] name name of the extended attribute
583 * \retval 0 on success
584 * \retval negative negated errno on error
586 int (*do_declare_xattr_get)(const struct lu_env *env,
587 struct dt_object *dt,
592 * Return a value of an extended attribute.
594 * The object must exist. If the buffer is NULL, then the method
595 * must return the size of the value.
597 * \param[in] env execution environment for this thread
598 * \param[in] dt object
599 * \param[out] buf buffer in which to store the value
600 * \param[in] name name of the extended attribute
602 * \retval 0 on success
603 * \retval -ERANGE if \a buf is too small
604 * \retval negative negated errno on error
605 * \retval positive value's size if \a buf is NULL or has zero size
607 int (*do_xattr_get)(const struct lu_env *env,
608 struct dt_object *dt,
613 * Declare intention to change an extended attribute.
615 * Notify the underlying filesystem that the extended attribute may
616 * change in this transaction. This enables the layer below to prepare
617 * resources (e.g. journal credits in ext4). This method should be
618 * called between creating the transaction and starting it. The object
621 * \param[in] env execution environment for this thread
622 * \param[in] dt object
623 * \param[in] buf buffer storing new value of the attribute
624 * \param[in] name name of the attribute
625 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
626 * LU_XATTR_REPLACE - fail if EA doesn't exist
627 * \param[in] th transaction handle
629 * \retval 0 on success
630 * \retval negative negated errno on error
632 int (*do_declare_xattr_set)(const struct lu_env *env,
633 struct dt_object *dt,
634 const struct lu_buf *buf,
640 * Set an extended attribute.
642 * Change or replace the specified extended attribute (EA).
643 * The flags passed in \a fl dictate whether the EA is to be
644 * created or replaced, as follows.
645 * LU_XATTR_CREATE - fail if EA exists
646 * LU_XATTR_REPLACE - fail if EA doesn't exist
647 * The object must exist.
649 * \param[in] env execution environment for this thread
650 * \param[in] dt object
651 * \param[in] buf buffer storing new value of the attribute
652 * \param[in] name name of the attribute
653 * \param[in] fl flags indicating EA creation or replacement
654 * \param[in] th transaction handle
656 * \retval 0 on success
657 * \retval negative negated errno on error
659 int (*do_xattr_set)(const struct lu_env *env,
660 struct dt_object *dt,
661 const struct lu_buf *buf,
667 * Declare intention to delete an extended attribute.
669 * Notify the underlying filesystem that the extended attribute may
670 * be deleted in this transaction. This enables the layer below to
671 * prepare resources (e.g. journal credits in ext4). This method
672 * should be called between creating the transaction and starting it.
673 * The object need not exist.
675 * \param[in] env execution environment for this thread
676 * \param[in] dt object
677 * \param[in] name name of the attribute
678 * \param[in] th transaction handle
680 * \retval 0 on success
681 * \retval negative negated errno on error
683 int (*do_declare_xattr_del)(const struct lu_env *env,
684 struct dt_object *dt,
689 * Delete an extended attribute.
691 * This method deletes the specified extended attribute. The object
694 * \param[in] env execution environment for this thread
695 * \param[in] dt object
696 * \param[in] name name of the attribute
697 * \param[in] th transaction handle
699 * \retval 0 on success
700 * \retval negative negated errno on error
702 int (*do_xattr_del)(const struct lu_env *env,
703 struct dt_object *dt,
708 * Return a list of the extended attributes.
710 * Fills the passed buffer with a list of the extended attributes
711 * found in the object. The names are separated with '\0'.
712 * The object must exist.
714 * \param[in] env execution environment for this thread
715 * \param[in] dt object
716 * \param[out] buf buffer to put the list in
718 * \retval positive bytes used/required in the buffer
719 * \retval negative negated errno on error
721 int (*do_xattr_list)(const struct lu_env *env,
722 struct dt_object *dt,
723 const struct lu_buf *buf);
726 * Prepare allocation hint for a new object.
728 * This method is used by the caller to inform OSD of the parent-child
729 * relationship between two objects and enable efficient object
730 * allocation. Filled allocation hint will be passed to ->do_create()
733 * \param[in] env execution environment for this thread
734 * \param[out] ah allocation hint
735 * \param[in] parent parent object (can be NULL)
736 * \param[in] child child object
737 * \param[in] _mode type of the child object
739 void (*do_ah_init)(const struct lu_env *env,
740 struct dt_allocation_hint *ah,
741 struct dt_object *parent,
742 struct dt_object *child,
746 * Declare intention to create a new object.
748 * Notify the underlying filesystem that the object may be created
749 * in this transaction. This enables the layer below to prepare
750 * resources (e.g. journal credits in ext4). This method should be
751 * called between creating the transaction and starting it.
753 * If the layer implementing this method is responsible for quota,
754 * then the method should reserve an object for the given credentials
755 * and return an error if quota is over. If object creation later
756 * fails for some reason, then the reservation should be released
757 * properly (usually in ->dt_trans_stop()).
759 * \param[in] env execution environment for this thread
760 * \param[in] dt object
761 * \param[in] attr attributes of the new object
762 * \param[in] hint allocation hint
763 * \param[in] dof object format
764 * \param[in] th transaction handle
766 * \retval 0 on success
767 * \retval negative negated errno on error
769 int (*do_declare_create)(const struct lu_env *env,
770 struct dt_object *dt,
771 struct lu_attr *attr,
772 struct dt_allocation_hint *hint,
773 struct dt_object_format *dof,
779 * The method creates the object passed with the specified attributes
780 * and object format. Object allocation procedure can use information
781 * stored in the allocation hint. Different object formats are supported
782 * (see enum dt_format_type and struct dt_object_format) depending on
783 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
784 * in the LU-object header attributes.
786 * If the layer implementing this method is responsible for quota,
787 * then the method should maintain object accounting for the given
790 * \param[in] env execution environment for this thread
791 * \param[in] dt object
792 * \param[in] attr attributes of the new object
793 * \param[in] hint allocation hint
794 * \param[in] dof object format
795 * \param[in] th transaction handle
797 * \retval 0 on success
798 * \retval negative negated errno on error
800 int (*do_create)(const struct lu_env *env,
801 struct dt_object *dt,
802 struct lu_attr *attr,
803 struct dt_allocation_hint *hint,
804 struct dt_object_format *dof,
808 * Declare intention to destroy an object.
810 * Notify the underlying filesystem that the object may be destroyed
811 * in this transaction. This enables the layer below to prepare
812 * resources (e.g. journal credits in ext4). This method should be
813 * called between creating the transaction and starting it. The object
816 * \param[in] env execution environment for this thread
817 * \param[in] dt object
818 * \param[in] th transaction handle
820 * \retval 0 on success
821 * \retval negative negated errno on error
823 int (*do_declare_destroy)(const struct lu_env *env,
824 struct dt_object *dt,
830 * This method destroys the object and all the resources associated
831 * with the object (data, key/value pairs, extended attributes, etc).
832 * The object must exist. If destroy is successful, then flag
833 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
834 * instance of in-core object. Any subsequent access to the same FID
835 * should get another instance with no LOHA_EXIST flag set.
837 * If the layer implementing this method is responsible for quota,
838 * then the method should maintain object accounting for the given
841 * \param[in] env execution environment for this thread
842 * \param[in] dt object
843 * \param[in] th transaction handle
845 * \retval 0 on success
846 * \retval negative negated errno on error
848 int (*do_destroy)(const struct lu_env *env,
849 struct dt_object *dt,
853 * Try object as an index.
855 * Announce that this object is going to be used as an index. This
856 * operation checks that object supports indexing operations and
857 * installs appropriate dt_index_operations vector on success.
858 * Also probes for features. Operation is successful if all required
859 * features are supported. It's not possible to access the object
860 * with index methods before ->do_index_try() returns success.
862 * \param[in] env execution environment for this thread
863 * \param[in] dt object
864 * \param[in] feat index features
866 * \retval 0 on success
867 * \retval negative negated errno on error
869 int (*do_index_try)(const struct lu_env *env,
870 struct dt_object *dt,
871 const struct dt_index_features *feat);
874 * Declare intention to increment nlink count.
876 * Notify the underlying filesystem that the nlink regular attribute
877 * be changed in this transaction. This enables the layer below to
878 * prepare resources (e.g. journal credits in ext4). This method
879 * should be called between creating the transaction and starting it.
880 * The object need not exist.
882 * \param[in] env execution environment for this thread
883 * \param[in] dt object
884 * \param[in] th transaction handle
886 * \retval 0 on success
887 * \retval negative negated errno on error
889 int (*do_declare_ref_add)(const struct lu_env *env,
890 struct dt_object *dt,
896 * Increment nlink (from the regular attributes set) in the given
897 * transaction. Note the absolute limit for nlink should be learnt
898 * from struct dt_device_param::ddp_max_nlink. The object must exist.
900 * \param[in] env execution environment for this thread
901 * \param[in] dt object
902 * \param[in] th transaction handle
904 * \retval 0 on success
905 * \retval negative negated errno on error
907 int (*do_ref_add)(const struct lu_env *env,
908 struct dt_object *dt, struct thandle *th);
911 * Declare intention to decrement nlink count.
913 * Notify the underlying filesystem that the nlink regular attribute
914 * be changed in this transaction. This enables the layer below to
915 * prepare resources (e.g. journal credits in ext4). This method
916 * should be called between creating the transaction and starting it.
917 * The object need not exist.
919 * \param[in] env execution environment for this thread
920 * \param[in] dt object
921 * \param[in] th transaction handle
923 * \retval 0 on success
924 * \retval negative negated errno on error
926 int (*do_declare_ref_del)(const struct lu_env *env,
927 struct dt_object *dt,
933 * Decrement nlink (from the regular attributes set) in the given
934 * transaction. The object must exist.
936 * \param[in] env execution environment for this thread
937 * \param[in] dt object
938 * \param[in] th transaction handle
940 * \retval 0 on success
941 * \retval negative negated errno on error
943 int (*do_ref_del)(const struct lu_env *env,
944 struct dt_object *dt,
950 * The method is called to sync specified range of the object to a
951 * persistent storage. The control is returned once the operation is
952 * complete. The difference from ->do_sync() is that the object can
953 * be in-sync with the persistent storage (nothing to flush), then
954 * the method returns quickly with no I/O overhead. So, this method
955 * should be preferred over ->do_sync() where possible. Also note that
956 * if the object isn't clean, then some disk filesystems will call
957 * ->do_sync() to maintain overall consistency, in which case it's
958 * still very expensive.
960 * \param[in] env execution environment for this thread
961 * \param[in] dt object
962 * \param[in] start start of the range to sync
963 * \param[in] end end of the range to sync
965 * \retval 0 on success
966 * \retval negative negated errno on error
968 int (*do_object_sync)(const struct lu_env *env,
969 struct dt_object *obj,
976 * Lock object(s) using Distributed Lock Manager (LDLM).
978 * Get LDLM locks for the object. Currently used to lock "remote"
979 * objects in DNE configuration - a service running on MDTx needs
980 * to lock an object on MDTy.
982 * \param[in] env execution environment for this thread
983 * \param[in] dt object
984 * \param[out] lh lock handle, sometimes used, sometimes not
985 * \param[in] einfo ldlm callbacks, locking type and mode
986 * \param[out] einfo private data to be passed to unlock later
987 * \param[in] policy inodebits data
989 * \retval 0 on success
990 * \retval negative negated errno on error
992 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
993 struct lustre_handle *lh,
994 struct ldlm_enqueue_info *einfo,
995 union ldlm_policy_data *policy);
1000 * Release LDLM lock(s) granted with ->do_object_lock().
1002 * \param[in] env execution environment for this thread
1003 * \param[in] dt object
1004 * \param[in] einfo lock handles, from ->do_object_lock()
1005 * \param[in] policy inodebits data
1007 * \retval 0 on success
1008 * \retval negative negated errno on error
1010 int (*do_object_unlock)(const struct lu_env *env,
1011 struct dt_object *dt,
1012 struct ldlm_enqueue_info *einfo,
1013 union ldlm_policy_data *policy);
1016 * Invalidate attribute cache.
1018 * This method invalidate attribute cache of the object, which is on OSP
1021 * \param[in] env execution envionment for this thread
1022 * \param[in] dt object
1024 * \retval 0 on success
1025 * \retval negative negated errno on error
1027 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1031 * Per-dt-object operations on "file body" - unstructure raw data.
1033 struct dt_body_operations {
1037 * Read unstructured data from an existing regular object.
1038 * Only data before attr.la_size is returned.
1040 * \param[in] env execution environment for this thread
1041 * \param[in] dt object
1042 * \param[out] buf buffer (including size) to copy data in
1043 * \param[in] pos position in the object to start
1044 * \param[out] pos original value of \a pos + bytes returned
1046 * \retval positive bytes read on success
1047 * \retval negative negated errno on error
1049 ssize_t (*dbo_read)(const struct lu_env *env,
1050 struct dt_object *dt,
1055 * Declare intention to write data to object.
1057 * Notify the underlying filesystem that data may be written in
1058 * this transaction. This enables the layer below to prepare resources
1059 * (e.g. journal credits in ext4). This method should be called
1060 * between creating the transaction and starting it. The object need
1061 * not exist. If the layer implementing this method is responsible for
1062 * quota, then the method should reserve space for the given credentials
1063 * and return an error if quota is over. If the write later fails
1064 * for some reason, then the reserve should be released properly
1065 * (usually in ->dt_trans_stop()).
1067 * \param[in] env execution environment for this thread
1068 * \param[in] dt object
1069 * \param[in] buf buffer (including size) to copy data from
1070 * \param[in] pos position in the object to start
1071 * \param[in] th transaction handle
1073 * \retval 0 on success
1074 * \retval negative negated errno on error
1076 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1077 struct dt_object *dt,
1078 const struct lu_buf *buf,
1080 struct thandle *th);
1083 * Write unstructured data to regular existing object.
1085 * The method allocates space and puts data in. Also, the method should
1086 * maintain attr.la_size properly. Partial writes are possible.
1088 * If the layer implementing this method is responsible for quota,
1089 * then the method should maintain space accounting for the given
1092 * \param[in] env execution environment for this thread
1093 * \param[in] dt object
1094 * \param[in] buf buffer (including size) to copy data from
1095 * \param[in] pos position in the object to start
1096 * \param[out] pos \a pos + bytes written
1097 * \param[in] th transaction handle
1098 * \param[in] ignore unused (was used to request quota ignorance)
1100 * \retval positive bytes written on success
1101 * \retval negative negated errno on error
1103 ssize_t (*dbo_write)(const struct lu_env *env,
1104 struct dt_object *dt,
1105 const struct lu_buf *buf,
1111 * Return buffers for data.
1113 * This method is used to access data with no copying. It's so-called
1114 * zero-copy I/O. The method returns the descriptors for the internal
1115 * buffers where data are managed by the disk filesystem. For example,
1116 * pagecache in case of ext4 or ARC with ZFS. Then other components
1117 * (e.g. networking) can transfer data from or to the buffers with no
1118 * additional copying.
1120 * The method should fill an array of struct niobuf_local, where
1121 * each element describes a full or partial page for data at specific
1122 * offset. The caller should use page/lnb_page_offset/len to find data
1123 * at object's offset lnb_file_offset.
1125 * The memory referenced by the descriptors can't change its purpose
1126 * until the complementary ->dbo_bufs_put() is called. The caller should
1127 * specify if the buffers are used to read or modify data so that OSD
1128 * can decide how to initialize the buffers: bring all the data for
1129 * reads or just bring partial buffers for write. Note: the method does
1130 * not check whether output array is large enough.
1132 * \param[in] env execution environment for this thread
1133 * \param[in] dt object
1134 * \param[in] pos position in the object to start
1135 * \param[in] len size of region in bytes
1136 * \param[out] lb array of descriptors to fill
1137 * \param[in] rw 0 if used to read, 1 if used for write
1139 * \retval positive number of descriptors on success
1140 * \retval negative negated errno on error
1142 int (*dbo_bufs_get)(const struct lu_env *env,
1143 struct dt_object *dt,
1146 struct niobuf_local *lb,
1150 * Release reference granted by ->dbo_bufs_get().
1152 * Release the reference granted by the previous ->dbo_bufs_get().
1153 * Note the references are counted.
1155 * \param[in] env execution environment for this thread
1156 * \param[in] dt object
1157 * \param[out] lb array of descriptors to fill
1158 * \param[in] nr size of the array
1160 * \retval 0 on success
1161 * \retval negative negated errno on error
1163 int (*dbo_bufs_put)(const struct lu_env *env,
1164 struct dt_object *dt,
1165 struct niobuf_local *lb,
1169 * Prepare buffers for reading.
1171 * The method is called on the given buffers to fill them with data
1172 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1173 * caller should be able to get few buffers for discontiguous regions
1174 * using few calls to ->dbo_bufs_get() and then request them all for
1175 * the preparation with a single call, so that OSD can fire many I/Os
1176 * to run concurrently. It's up to the specific OSD whether to implement
1177 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1178 * prepare data for every requested region individually.
1180 * \param[in] env execution environment for this thread
1181 * \param[in] dt object
1182 * \param[in] lnb array of buffer descriptors
1183 * \param[in] nr size of the array
1185 * \retval 0 on success
1186 * \retval negative negated errno on error
1188 int (*dbo_read_prep)(const struct lu_env *env,
1189 struct dt_object *dt,
1190 struct niobuf_local *lnb,
1194 * Prepare buffers for write.
1196 * This method is called on the given buffers to ensure the partial
1197 * buffers contain correct data. The underlying idea is the same as
1198 * in ->db_read_prep().
1200 * \param[in] env execution environment for this thread
1201 * \param[in] dt object
1202 * \param[in] lb array of buffer descriptors
1203 * \param[in] nr size of the array
1205 * \retval 0 on success
1206 * \retval negative negated errno on error
1208 int (*dbo_write_prep)(const struct lu_env *env,
1209 struct dt_object *dt,
1210 struct niobuf_local *lb,
1214 * Declare intention to write data stored in the buffers.
1216 * Notify the underlying filesystem that data may be written in
1217 * this transaction. This enables the layer below to prepare resources
1218 * (e.g. journal credits in ext4). This method should be called
1219 * between creating the transaction and starting it.
1221 * If the layer implementing this method is responsible for quota,
1222 * then the method should be reserving a space for the given
1223 * credentials and return an error if quota is exceeded. If the write
1224 * later fails for some reason, then the reserve should be released
1225 * properly (usually in ->dt_trans_stop()).
1227 * \param[in] env execution environment for this thread
1228 * \param[in] dt object
1229 * \param[in] lb array of descriptors
1230 * \param[in] nr size of the array
1231 * \param[in] th transaction handle
1233 * \retval 0 on success
1234 * \retval negative negated errno on error
1236 int (*dbo_declare_write_commit)(const struct lu_env *env,
1237 struct dt_object *dt,
1238 struct niobuf_local *lb,
1240 struct thandle *th);
1243 * Write to existing object.
1245 * This method is used to write data to a persistent storage using
1246 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1247 * data into the buffers using own mechanisms (e.g. direct transfer
1248 * from a NIC). The method should maintain attr.la_size. Also,
1249 * attr.la_blocks should be maintained but this can be done in lazy
1250 * manner, when actual allocation happens.
1252 * If the layer implementing this method is responsible for quota,
1253 * then the method should maintain space accounting for the given
1256 * \param[in] env execution environment for this thread
1257 * \param[in] dt object
1258 * \param[in] lb array of descriptors for the buffers
1259 * \param[in] nr size of the array
1260 * \param[in] th transaction handle
1262 * \retval 0 on success
1263 * \retval negative negated errno on error
1265 int (*dbo_write_commit)(const struct lu_env *env,
1266 struct dt_object *dt,
1267 struct niobuf_local *lb,
1269 struct thandle *th);
1272 * Return logical to physical block mapping for a given extent
1274 * \param[in] env execution environment for this thread
1275 * \param[in] dt object
1276 * \param[in] fm describe the region to map and the output buffer
1277 * see the details in include/linux/fiemap.h
1279 * \retval 0 on success
1280 * \retval negative negated errno on error
1282 int (*dbo_fiemap_get)(const struct lu_env *env,
1283 struct dt_object *dt,
1287 * Declare intention to deallocate space from an object.
1289 * Notify the underlying filesystem that space may be deallocated in
1290 * this transactions. This enables the layer below to prepare resources
1291 * (e.g. journal credits in ext4). This method should be called between
1292 * creating the transaction and starting it. The object need not exist.
1294 * \param[in] env execution environment for this thread
1295 * \param[in] dt object
1296 * \param[in] start the start of the region to deallocate
1297 * \param[in] end the end of the region to deallocate
1298 * \param[in] th transaction handle
1300 * \retval 0 on success
1301 * \retval negative negated errno on error
1303 int (*dbo_declare_punch)(const struct lu_env *env,
1304 struct dt_object *dt,
1307 struct thandle *th);
1310 * Deallocate specified region in an object.
1312 * This method is used to deallocate (release) space possibly consumed
1313 * by the given region of the object. If the layer implementing this
1314 * method is responsible for quota, then the method should maintain
1315 * space accounting for the given credentials.
1317 * \param[in] env execution environment for this thread
1318 * \param[in] dt object
1319 * \param[in] start the start of the region to deallocate
1320 * \param[in] end the end of the region to deallocate
1321 * \param[in] th transaction handle
1323 * \retval 0 on success
1324 * \retval negative negated errno on error
1326 int (*dbo_punch)(const struct lu_env *env,
1327 struct dt_object *dt,
1330 struct thandle *th);
1332 * Give advices on specified region in an object.
1334 * This method is used to give advices about access pattern on an
1335 * given region of the object. The disk filesystem understands
1336 * the advices and tunes cache/read-ahead policies.
1338 * \param[in] env execution environment for this thread
1339 * \param[in] dt object
1340 * \param[in] start the start of the region affected
1341 * \param[in] end the end of the region affected
1342 * \param[in] advice advice type
1344 * \retval 0 on success
1345 * \retval negative negated errno on error
1347 int (*dbo_ladvise)(const struct lu_env *env,
1348 struct dt_object *dt,
1351 enum lu_ladvise_type advice);
1355 * Incomplete type of index record.
1360 * Incomplete type of index key.
1365 * Incomplete type of dt iterator.
1370 * Per-dt-object operations on object as index. Index is a set of key/value
1371 * pairs abstracted from an on-disk representation. An index supports the
1372 * number of operations including lookup by key, insert and delete. Also,
1373 * an index can be iterated to find the pairs one by one, from a beginning
1374 * or specified point.
1376 struct dt_index_operations {
1378 * Lookup in an index by key.
1380 * The method returns a value for the given key. Key/value format
1381 * and size should have been negotiated with ->do_index_try() before.
1382 * Thus it's the caller's responsibility to provide the method with
1383 * proper key and big enough buffer. No external locking is required,
1384 * all the internal consistency should be implemented by the method
1385 * or lower layers. The object should should have been created with
1386 * type DFT_INDEX or DFT_DIR.
1388 * \param[in] env execution environment for this thread
1389 * \param[in] dt object
1390 * \param[out] rec buffer where value will be stored
1391 * \param[in] key key
1393 * \retval 0 on success
1394 * \retval -ENOENT if key isn't found
1395 * \retval negative negated errno on error
1397 int (*dio_lookup)(const struct lu_env *env,
1398 struct dt_object *dt,
1400 const struct dt_key *key);
1403 * Declare intention to insert a key/value into an index.
1405 * Notify the underlying filesystem that new key/value may be inserted
1406 * in this transaction. This enables the layer below to prepare
1407 * resources (e.g. journal credits in ext4). This method should be
1408 * called between creating the transaction and starting it. key/value
1409 * format and size is subject to ->do_index_try().
1411 * \param[in] env execution environment for this thread
1412 * \param[in] dt object
1413 * \param[in] rec buffer storing value
1414 * \param[in] key key
1415 * \param[in] th transaction handle
1417 * \retval 0 on success
1418 * \retval negative negated errno on error
1420 int (*dio_declare_insert)(const struct lu_env *env,
1421 struct dt_object *dt,
1422 const struct dt_rec *rec,
1423 const struct dt_key *key,
1424 struct thandle *th);
1427 * Insert a new key/value pair into an index.
1429 * The method inserts specified key/value pair into the given index
1430 * object. The internal consistency is maintained by the method or
1431 * the functionality below. The format and size of key/value should
1432 * have been negotiated before using ->do_index_try(), no additional
1433 * information can be specified to the method. The keys are unique
1436 * \param[in] env execution environment for this thread
1437 * \param[in] dt object
1438 * \param[in] rec buffer storing value
1439 * \param[in] key key
1440 * \param[in] th transaction handle
1441 * \param[in] ignore unused (was used to request quota ignorance)
1443 * \retval 0 on success
1444 * \retval negative negated errno on error
1446 int (*dio_insert)(const struct lu_env *env,
1447 struct dt_object *dt,
1448 const struct dt_rec *rec,
1449 const struct dt_key *key,
1454 * Declare intention to delete a key/value from an index.
1456 * Notify the underlying filesystem that key/value may be deleted in
1457 * this transaction. This enables the layer below to prepare resources
1458 * (e.g. journal credits in ext4). This method should be called
1459 * between creating the transaction and starting it. Key/value format
1460 * and size is subject to ->do_index_try(). The object need not exist.
1462 * \param[in] env execution environment for this thread
1463 * \param[in] dt object
1464 * \param[in] key key
1465 * \param[in] th transaction handle
1467 * \retval 0 on success
1468 * \retval negative negated errno on error
1470 int (*dio_declare_delete)(const struct lu_env *env,
1471 struct dt_object *dt,
1472 const struct dt_key *key,
1473 struct thandle *th);
1476 * Delete key/value pair from an index.
1478 * The method deletes specified key and corresponding value from the
1479 * given index object. The internal consistency is maintained by the
1480 * method or the functionality below. The format and size of the key
1481 * should have been negotiated before using ->do_index_try(), no
1482 * additional information can be specified to the method.
1484 * \param[in] env execution environment for this thread
1485 * \param[in] dt object
1486 * \param[in] key key
1487 * \param[in] th transaction handle
1489 * \retval 0 on success
1490 * \retval negative negated errno on error
1492 int (*dio_delete)(const struct lu_env *env,
1493 struct dt_object *dt,
1494 const struct dt_key *key,
1495 struct thandle *th);
1498 * Iterator interface.
1500 * Methods to iterate over an existing index, list the keys stored and
1501 * associated values, get key/value size, etc.
1505 * Allocate and initialize new iterator.
1507 * The iterator is a handler to be used in the subsequent
1508 * methods to access index's content. Note the position is
1509 * not defined at this point and should be initialized with
1510 * ->get() or ->load() method.
1512 * \param[in] env execution environment for this thread
1513 * \param[in] dt object
1514 * \param[in] attr ask the iterator to return part of
1515 the records, see LUDA_* for details
1517 * \retval pointer iterator pointer on success
1518 * \retval ERR_PTR(errno) on error
1520 struct dt_it *(*init)(const struct lu_env *env,
1521 struct dt_object *dt,
1527 * Release the specified iterator and all the resources
1528 * associated (e.g. the object, index cache, etc).
1530 * \param[in] env execution environment for this thread
1531 * \param[in] di iterator to release
1533 void (*fini)(const struct lu_env *env,
1537 * Move position of iterator.
1539 * Move the position of the specified iterator to the specified
1542 * \param[in] env execution environment for this thread
1543 * \param[in] di iterator
1544 * \param[in] key key to position to
1546 * \retval 0 if exact key is found
1547 * \retval 1 if at the record with least key
1548 * not larger than the key
1549 * \retval negative negated errno on error
1551 int (*get)(const struct lu_env *env,
1553 const struct dt_key *key);
1558 * Complimentary method for dt_it_ops::get() above. Some
1559 * implementation can increase a reference on the iterator in
1560 * dt_it_ops::get(). So the caller should be able to release
1561 * with dt_it_ops::put().
1563 * \param[in] env execution environment for this thread
1564 * \param[in] di iterator
1566 void (*put)(const struct lu_env *env,
1570 * Move to next record.
1572 * Moves the position of the iterator to a next record
1574 * \param[in] env execution environment for this thread
1575 * \param[in] di iterator
1577 * \retval 1 if no more records
1578 * \retval 0 on success, the next record is found
1579 * \retval negative negated errno on error
1581 int (*next)(const struct lu_env *env,
1587 * Returns a pointer to a buffer containing the key of the
1588 * record at the current position. The pointer is valid and
1589 * retains data until ->get(), ->load() and ->fini() methods
1592 * \param[in] env execution environment for this thread
1593 * \param[in] di iterator
1595 * \retval pointer to key on success
1596 * \retval ERR_PTR(errno) on error
1598 struct dt_key *(*key)(const struct lu_env *env,
1599 const struct dt_it *di);
1604 * Returns size of the key at the current position.
1606 * \param[in] env execution environment for this thread
1607 * \param[in] di iterator
1609 * \retval key's size on success
1610 * \retval negative negated errno on error
1612 int (*key_size)(const struct lu_env *env,
1613 const struct dt_it *di);
1618 * Stores the value of the record at the current position. The
1619 * buffer must be big enough (as negotiated with
1620 * ->do_index_try() or ->rec_size()). The caller can specify
1621 * she is interested only in part of the record, using attr
1622 * argument (see LUDA_* definitions for the details).
1624 * \param[in] env execution environment for this thread
1625 * \param[in] di iterator
1626 * \param[out] rec buffer to store value in
1627 * \param[in] attr specify part of the value to copy
1629 * \retval 0 on success
1630 * \retval negative negated errno on error
1632 int (*rec)(const struct lu_env *env,
1633 const struct dt_it *di,
1638 * Return record size.
1640 * Returns size of the record at the current position. The
1641 * \a attr can be used to specify only the parts of the record
1642 * needed to be returned. (see LUDA_* definitions for the
1645 * \param[in] env execution environment for this thread
1646 * \param[in] di iterator
1647 * \param[in] attr part of the record to return
1649 * \retval record's size on success
1650 * \retval negative negated errno on error
1652 int (*rec_size)(const struct lu_env *env,
1653 const struct dt_it *di,
1657 * Return a cookie (hash).
1659 * Returns the cookie (usually hash) of the key at the current
1660 * position. This allows the caller to resume iteration at this
1661 * position later. The exact value is specific to implementation
1662 * and should not be interpreted by the caller.
1664 * \param[in] env execution environment for this thread
1665 * \param[in] di iterator
1667 * \retval cookie/hash of the key
1669 __u64 (*store)(const struct lu_env *env,
1670 const struct dt_it *di);
1673 * Initialize position using cookie/hash.
1675 * Initializes the current position of the iterator to one
1676 * described by the cookie/hash as returned by ->store()
1679 * \param[in] env execution environment for this thread
1680 * \param[in] di iterator
1681 * \param[in] hash cookie/hash value
1683 * \retval positive if current position points to
1684 * record with least cookie not larger
1686 * \retval 0 if current position matches cookie
1687 * \retval negative negated errno on error
1689 int (*load)(const struct lu_env *env,
1690 const struct dt_it *di,
1696 int (*key_rec)(const struct lu_env *env,
1697 const struct dt_it *di,
1702 enum dt_otable_it_valid {
1703 DOIV_ERROR_HANDLE = 0x0001,
1704 DOIV_DRYRUN = 0x0002,
1707 enum dt_otable_it_flags {
1708 /* Exit when fail. */
1709 DOIF_FAILOUT = 0x0001,
1711 /* Reset iteration position to the device beginning. */
1712 DOIF_RESET = 0x0002,
1714 /* There is up layer component uses the iteration. */
1715 DOIF_OUTUSED = 0x0004,
1717 /* Check only without repairing. */
1718 DOIF_DRYRUN = 0x0008,
1721 /* otable based iteration needs to use the common DT iteration APIs.
1722 * To initialize the iteration, it needs call dio_it::init() firstly.
1723 * Here is how the otable based iteration should prepare arguments to
1724 * call dt_it_ops::init().
1726 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1727 * is composed of two parts:
1728 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1729 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1730 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1733 struct lu_device dd_lu_dev;
1734 const struct dt_device_operations *dd_ops;
1737 * List of dt_txn_callback (see below). This is not protected in any
1738 * way, because callbacks are supposed to be added/deleted only during
1739 * single-threaded start-up shut-down procedures.
1741 struct list_head dd_txn_callbacks;
1742 unsigned int dd_record_fid_accessed:1;
1745 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1746 void dt_device_fini(struct dt_device *dev);
1748 static inline int lu_device_is_dt(const struct lu_device *d)
1750 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1753 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1755 LASSERT(lu_device_is_dt(l));
1756 return container_of0(l, struct dt_device, dd_lu_dev);
1760 struct lu_object do_lu;
1761 const struct dt_object_operations *do_ops;
1762 const struct dt_body_operations *do_body_ops;
1763 const struct dt_index_operations *do_index_ops;
1767 * In-core representation of per-device local object OID storage
1769 struct local_oid_storage {
1770 /* all initialized llog systems on this node linked by this */
1771 struct list_head los_list;
1773 /* how many handle's reference this los has */
1774 atomic_t los_refcount;
1775 struct dt_device *los_dev;
1776 struct dt_object *los_obj;
1778 /* data used to generate new fids */
1779 struct mutex los_id_lock;
1784 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1786 return &d->dd_lu_dev;
1789 static inline struct dt_object *lu2dt(struct lu_object *l)
1791 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1792 return container_of0(l, struct dt_object, do_lu);
1795 int dt_object_init(struct dt_object *obj,
1796 struct lu_object_header *h, struct lu_device *d);
1798 void dt_object_fini(struct dt_object *obj);
1800 static inline int dt_object_exists(const struct dt_object *dt)
1802 return lu_object_exists(&dt->do_lu);
1805 static inline int dt_object_remote(const struct dt_object *dt)
1807 return lu_object_remote(&dt->do_lu);
1810 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1812 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1813 return container_of0(o, struct dt_object, do_lu);
1816 static inline struct dt_object *dt_object_child(struct dt_object *o)
1818 return container_of0(lu_object_next(&(o)->do_lu),
1819 struct dt_object, do_lu);
1823 * This is the general purpose transaction handle.
1824 * 1. Transaction Life Cycle
1825 * This transaction handle is allocated upon starting a new transaction,
1826 * and deallocated after this transaction is committed.
1827 * 2. Transaction Nesting
1828 * We do _NOT_ support nested transaction. So, every thread should only
1829 * have one active transaction, and a transaction only belongs to one
1830 * thread. Due to this, transaction handle need no reference count.
1831 * 3. Transaction & dt_object locking
1832 * dt_object locks should be taken inside transaction.
1833 * 4. Transaction & RPC
1834 * No RPC request should be issued inside transaction.
1837 /** the dt device on which the transactions are executed */
1838 struct dt_device *th_dev;
1840 /* point to the top thandle, XXX this is a bit hacky right now,
1841 * but normal device trans callback triggered by the bottom
1842 * device (OSP/OSD == sub thandle layer) needs to get the
1843 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1844 * top thandle here for now, will fix it when we have better
1845 * callback mechanism */
1846 struct thandle *th_top;
1847 /** context for this transaction, tag is LCT_TX_HANDLE */
1848 struct lu_context th_ctx;
1850 /** additional tags (layers can add in declare) */
1853 /** the last operation result in this transaction.
1854 * this value is used in recovery */
1857 /** whether we need sync commit */
1858 unsigned int th_sync:1,
1859 /* local transation, no need to inform other layers */
1861 /* Whether we need wait the transaction to be submitted */
1863 /* complex transaction which will track updates on all targets */
1868 * Transaction call-backs.
1870 * These are invoked by osd (or underlying transaction engine) when
1871 * transaction changes state.
1873 * Call-backs are used by upper layers to modify transaction parameters and to
1874 * perform some actions on for each transaction state transition. Typical
1875 * example is mdt registering call-back to write into last-received file
1876 * before each transaction commit.
1878 struct dt_txn_callback {
1879 int (*dtc_txn_start)(const struct lu_env *env,
1880 struct thandle *txn, void *cookie);
1881 int (*dtc_txn_stop)(const struct lu_env *env,
1882 struct thandle *txn, void *cookie);
1883 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1886 struct list_head dtc_linkage;
1889 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1890 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1892 int dt_txn_hook_start(const struct lu_env *env,
1893 struct dt_device *dev, struct thandle *txn);
1894 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1895 void dt_txn_hook_commit(struct thandle *txn);
1897 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1900 * Callback function used for parsing path.
1901 * \see llo_store_resolve
1903 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1907 #define DT_MAX_PATH 1024
1909 int dt_path_parser(const struct lu_env *env,
1910 char *local, dt_entry_func_t entry_func,
1914 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1915 const char *path, struct lu_fid *fid);
1917 struct dt_object *dt_store_open(const struct lu_env *env,
1918 struct dt_device *dt,
1919 const char *dirname,
1920 const char *filename,
1921 struct lu_fid *fid);
1923 struct dt_object *dt_find_or_create(const struct lu_env *env,
1924 struct dt_device *dt,
1925 const struct lu_fid *fid,
1926 struct dt_object_format *dof,
1927 struct lu_attr *attr);
1929 struct dt_object *dt_locate_at(const struct lu_env *env,
1930 struct dt_device *dev,
1931 const struct lu_fid *fid,
1932 struct lu_device *top_dev,
1933 const struct lu_object_conf *conf);
1935 static inline struct dt_object *
1936 dt_locate(const struct lu_env *env, struct dt_device *dev,
1937 const struct lu_fid *fid)
1939 return dt_locate_at(env, dev, fid,
1940 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1943 static inline struct dt_object *
1944 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1946 struct lu_object *lo;
1948 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
1949 if (lo->lo_dev == &dt_dev->dd_lu_dev)
1950 return container_of(lo, struct dt_object, do_lu);
1955 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
1956 const struct lu_fid *first_fid,
1957 struct local_oid_storage **los);
1958 void local_oid_storage_fini(const struct lu_env *env,
1959 struct local_oid_storage *los);
1960 int local_object_fid_generate(const struct lu_env *env,
1961 struct local_oid_storage *los,
1962 struct lu_fid *fid);
1963 int local_object_declare_create(const struct lu_env *env,
1964 struct local_oid_storage *los,
1965 struct dt_object *o,
1966 struct lu_attr *attr,
1967 struct dt_object_format *dof,
1968 struct thandle *th);
1969 int local_object_create(const struct lu_env *env,
1970 struct local_oid_storage *los,
1971 struct dt_object *o,
1972 struct lu_attr *attr, struct dt_object_format *dof,
1973 struct thandle *th);
1974 struct dt_object *local_file_find_or_create(const struct lu_env *env,
1975 struct local_oid_storage *los,
1976 struct dt_object *parent,
1977 const char *name, __u32 mode);
1978 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
1979 struct dt_device *dt,
1980 const struct lu_fid *fid,
1981 struct dt_object *parent,
1985 local_index_find_or_create(const struct lu_env *env,
1986 struct local_oid_storage *los,
1987 struct dt_object *parent,
1988 const char *name, __u32 mode,
1989 const struct dt_index_features *ft);
1991 local_index_find_or_create_with_fid(const struct lu_env *env,
1992 struct dt_device *dt,
1993 const struct lu_fid *fid,
1994 struct dt_object *parent,
1995 const char *name, __u32 mode,
1996 const struct dt_index_features *ft);
1997 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
1998 struct dt_object *parent, const char *name);
2000 static inline int dt_object_lock(const struct lu_env *env,
2001 struct dt_object *o, struct lustre_handle *lh,
2002 struct ldlm_enqueue_info *einfo,
2003 union ldlm_policy_data *policy)
2006 LASSERT(o->do_ops != NULL);
2007 LASSERT(o->do_ops->do_object_lock != NULL);
2008 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2011 static inline int dt_object_unlock(const struct lu_env *env,
2012 struct dt_object *o,
2013 struct ldlm_enqueue_info *einfo,
2014 union ldlm_policy_data *policy)
2017 LASSERT(o->do_ops != NULL);
2018 LASSERT(o->do_ops->do_object_unlock != NULL);
2019 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2022 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2023 const char *name, struct lu_fid *fid);
2025 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2026 __u64 start, __u64 end)
2030 LASSERT(o->do_ops->do_object_sync);
2031 return o->do_ops->do_object_sync(env, o, start, end);
2034 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2035 struct thandle *th);
2036 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2037 dt_obj_version_t version, struct thandle *th);
2038 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2041 int dt_read(const struct lu_env *env, struct dt_object *dt,
2042 struct lu_buf *buf, loff_t *pos);
2043 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2044 struct lu_buf *buf, loff_t *pos);
2045 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2046 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2047 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2048 union lu_page *lp, size_t nob,
2049 const struct dt_it_ops *iops,
2050 struct dt_it *it, __u32 attr, void *arg);
2051 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2052 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2054 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2055 struct idx_info *ii, const struct lu_rdpg *rdpg);
2057 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2058 struct dt_device *d)
2060 LASSERT(d->dd_ops->dt_trans_create);
2061 return d->dd_ops->dt_trans_create(env, d);
2064 static inline int dt_trans_start(const struct lu_env *env,
2065 struct dt_device *d, struct thandle *th)
2067 LASSERT(d->dd_ops->dt_trans_start);
2068 return d->dd_ops->dt_trans_start(env, d, th);
2071 /* for this transaction hooks shouldn't be called */
2072 static inline int dt_trans_start_local(const struct lu_env *env,
2073 struct dt_device *d, struct thandle *th)
2075 LASSERT(d->dd_ops->dt_trans_start);
2077 return d->dd_ops->dt_trans_start(env, d, th);
2080 static inline int dt_trans_stop(const struct lu_env *env,
2081 struct dt_device *d, struct thandle *th)
2083 LASSERT(d->dd_ops->dt_trans_stop);
2084 return d->dd_ops->dt_trans_stop(env, d, th);
2087 static inline int dt_trans_cb_add(struct thandle *th,
2088 struct dt_txn_commit_cb *dcb)
2090 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2091 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2092 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2097 static inline int dt_declare_record_write(const struct lu_env *env,
2098 struct dt_object *dt,
2099 const struct lu_buf *buf,
2105 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2106 LASSERT(th != NULL);
2107 LASSERT(dt->do_body_ops);
2108 LASSERT(dt->do_body_ops->dbo_declare_write);
2109 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2113 static inline int dt_declare_create(const struct lu_env *env,
2114 struct dt_object *dt,
2115 struct lu_attr *attr,
2116 struct dt_allocation_hint *hint,
2117 struct dt_object_format *dof,
2121 LASSERT(dt->do_ops);
2122 LASSERT(dt->do_ops->do_declare_create);
2124 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2125 return cfs_fail_err;
2127 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2130 static inline int dt_create(const struct lu_env *env,
2131 struct dt_object *dt,
2132 struct lu_attr *attr,
2133 struct dt_allocation_hint *hint,
2134 struct dt_object_format *dof,
2138 LASSERT(dt->do_ops);
2139 LASSERT(dt->do_ops->do_create);
2141 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2142 return cfs_fail_err;
2144 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2147 static inline int dt_declare_destroy(const struct lu_env *env,
2148 struct dt_object *dt,
2152 LASSERT(dt->do_ops);
2153 LASSERT(dt->do_ops->do_declare_destroy);
2155 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2156 return cfs_fail_err;
2158 return dt->do_ops->do_declare_destroy(env, dt, th);
2161 static inline int dt_destroy(const struct lu_env *env,
2162 struct dt_object *dt,
2166 LASSERT(dt->do_ops);
2167 LASSERT(dt->do_ops->do_destroy);
2169 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2170 return cfs_fail_err;
2172 return dt->do_ops->do_destroy(env, dt, th);
2175 static inline void dt_read_lock(const struct lu_env *env,
2176 struct dt_object *dt,
2180 LASSERT(dt->do_ops);
2181 LASSERT(dt->do_ops->do_read_lock);
2182 dt->do_ops->do_read_lock(env, dt, role);
2185 static inline void dt_write_lock(const struct lu_env *env,
2186 struct dt_object *dt,
2190 LASSERT(dt->do_ops);
2191 LASSERT(dt->do_ops->do_write_lock);
2192 dt->do_ops->do_write_lock(env, dt, role);
2195 static inline void dt_read_unlock(const struct lu_env *env,
2196 struct dt_object *dt)
2199 LASSERT(dt->do_ops);
2200 LASSERT(dt->do_ops->do_read_unlock);
2201 dt->do_ops->do_read_unlock(env, dt);
2204 static inline void dt_write_unlock(const struct lu_env *env,
2205 struct dt_object *dt)
2208 LASSERT(dt->do_ops);
2209 LASSERT(dt->do_ops->do_write_unlock);
2210 dt->do_ops->do_write_unlock(env, dt);
2213 static inline int dt_write_locked(const struct lu_env *env,
2214 struct dt_object *dt)
2217 LASSERT(dt->do_ops);
2218 LASSERT(dt->do_ops->do_write_locked);
2219 return dt->do_ops->do_write_locked(env, dt);
2222 static inline int dt_declare_attr_get(const struct lu_env *env,
2223 struct dt_object *dt)
2226 LASSERT(dt->do_ops);
2227 LASSERT(dt->do_ops->do_declare_attr_get);
2229 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2230 return cfs_fail_err;
2232 return dt->do_ops->do_declare_attr_get(env, dt);
2235 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2239 LASSERT(dt->do_ops);
2240 LASSERT(dt->do_ops->do_attr_get);
2242 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2243 return cfs_fail_err;
2245 return dt->do_ops->do_attr_get(env, dt, la);
2248 static inline int dt_declare_attr_set(const struct lu_env *env,
2249 struct dt_object *dt,
2250 const struct lu_attr *la,
2254 LASSERT(dt->do_ops);
2255 LASSERT(dt->do_ops->do_declare_attr_set);
2257 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2258 return cfs_fail_err;
2260 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2263 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2264 const struct lu_attr *la, struct thandle *th)
2267 LASSERT(dt->do_ops);
2268 LASSERT(dt->do_ops->do_attr_set);
2270 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2271 return cfs_fail_err;
2273 return dt->do_ops->do_attr_set(env, dt, la, th);
2276 static inline int dt_declare_ref_add(const struct lu_env *env,
2277 struct dt_object *dt, struct thandle *th)
2280 LASSERT(dt->do_ops);
2281 LASSERT(dt->do_ops->do_declare_ref_add);
2283 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2284 return cfs_fail_err;
2286 return dt->do_ops->do_declare_ref_add(env, dt, th);
2289 static inline int dt_ref_add(const struct lu_env *env,
2290 struct dt_object *dt, struct thandle *th)
2293 LASSERT(dt->do_ops);
2294 LASSERT(dt->do_ops->do_ref_add);
2296 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2297 return cfs_fail_err;
2299 return dt->do_ops->do_ref_add(env, dt, th);
2302 static inline int dt_declare_ref_del(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_del);
2309 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2310 return cfs_fail_err;
2312 return dt->do_ops->do_declare_ref_del(env, dt, th);
2315 static inline int dt_ref_del(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_del);
2322 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2323 return cfs_fail_err;
2325 return dt->do_ops->do_ref_del(env, dt, th);
2328 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2329 struct niobuf_remote *rnb,
2330 struct niobuf_local *lnb, int rw)
2333 LASSERT(d->do_body_ops);
2334 LASSERT(d->do_body_ops->dbo_bufs_get);
2335 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2336 rnb->rnb_len, lnb, rw);
2339 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2340 struct niobuf_local *lnb, int n)
2343 LASSERT(d->do_body_ops);
2344 LASSERT(d->do_body_ops->dbo_bufs_put);
2345 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2348 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2349 struct niobuf_local *lnb, int n)
2352 LASSERT(d->do_body_ops);
2353 LASSERT(d->do_body_ops->dbo_write_prep);
2354 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2357 static inline int dt_declare_write_commit(const struct lu_env *env,
2358 struct dt_object *d,
2359 struct niobuf_local *lnb,
2360 int n, struct thandle *th)
2362 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2363 LASSERT(th != NULL);
2364 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2368 static inline int dt_write_commit(const struct lu_env *env,
2369 struct dt_object *d, struct niobuf_local *lnb,
2370 int n, struct thandle *th)
2373 LASSERT(d->do_body_ops);
2374 LASSERT(d->do_body_ops->dbo_write_commit);
2375 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2378 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2379 struct niobuf_local *lnb, int n)
2382 LASSERT(d->do_body_ops);
2383 LASSERT(d->do_body_ops->dbo_read_prep);
2384 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2387 static inline int dt_declare_write(const struct lu_env *env,
2388 struct dt_object *dt,
2389 const struct lu_buf *buf, loff_t pos,
2393 LASSERT(dt->do_body_ops);
2394 LASSERT(dt->do_body_ops->dbo_declare_write);
2395 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2398 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2399 const struct lu_buf *buf, loff_t *pos,
2400 struct thandle *th, int rq)
2403 LASSERT(dt->do_body_ops);
2404 LASSERT(dt->do_body_ops->dbo_write);
2405 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th, rq);
2408 static inline int dt_declare_punch(const struct lu_env *env,
2409 struct dt_object *dt, __u64 start,
2410 __u64 end, struct thandle *th)
2413 LASSERT(dt->do_body_ops);
2414 LASSERT(dt->do_body_ops->dbo_declare_punch);
2415 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2418 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2419 __u64 start, __u64 end, struct thandle *th)
2422 LASSERT(dt->do_body_ops);
2423 LASSERT(dt->do_body_ops->dbo_punch);
2424 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2427 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2428 __u64 start, __u64 end, int advice)
2431 LASSERT(dt->do_body_ops);
2432 LASSERT(dt->do_body_ops->dbo_ladvise);
2433 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2436 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2440 if (d->do_body_ops == NULL)
2442 if (d->do_body_ops->dbo_fiemap_get == NULL)
2444 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2447 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2448 struct obd_statfs *osfs)
2451 LASSERT(dev->dd_ops);
2452 LASSERT(dev->dd_ops->dt_statfs);
2453 return dev->dd_ops->dt_statfs(env, dev, osfs);
2456 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2460 LASSERT(dev->dd_ops);
2461 LASSERT(dev->dd_ops->dt_root_get);
2462 return dev->dd_ops->dt_root_get(env, dev, f);
2465 static inline void dt_conf_get(const struct lu_env *env,
2466 const struct dt_device *dev,
2467 struct dt_device_param *param)
2470 LASSERT(dev->dd_ops);
2471 LASSERT(dev->dd_ops->dt_conf_get);
2472 return dev->dd_ops->dt_conf_get(env, dev, param);
2475 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2478 LASSERT(dev->dd_ops);
2479 LASSERT(dev->dd_ops->dt_sync);
2480 return dev->dd_ops->dt_sync(env, dev);
2483 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2486 LASSERT(dev->dd_ops);
2487 LASSERT(dev->dd_ops->dt_ro);
2488 return dev->dd_ops->dt_ro(env, dev);
2491 static inline int dt_declare_insert(const struct lu_env *env,
2492 struct dt_object *dt,
2493 const struct dt_rec *rec,
2494 const struct dt_key *key,
2498 LASSERT(dt->do_index_ops);
2499 LASSERT(dt->do_index_ops->dio_declare_insert);
2501 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2502 return cfs_fail_err;
2504 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2507 static inline int dt_insert(const struct lu_env *env,
2508 struct dt_object *dt,
2509 const struct dt_rec *rec,
2510 const struct dt_key *key,
2515 LASSERT(dt->do_index_ops);
2516 LASSERT(dt->do_index_ops->dio_insert);
2518 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2519 return cfs_fail_err;
2521 return dt->do_index_ops->dio_insert(env, dt, rec, key, th, noquota);
2524 static inline int dt_declare_xattr_del(const struct lu_env *env,
2525 struct dt_object *dt,
2530 LASSERT(dt->do_ops);
2531 LASSERT(dt->do_ops->do_declare_xattr_del);
2533 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2534 return cfs_fail_err;
2536 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2539 static inline int dt_xattr_del(const struct lu_env *env,
2540 struct dt_object *dt, const char *name,
2544 LASSERT(dt->do_ops);
2545 LASSERT(dt->do_ops->do_xattr_del);
2547 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2548 return cfs_fail_err;
2550 return dt->do_ops->do_xattr_del(env, dt, name, th);
2553 static inline int dt_declare_xattr_set(const struct lu_env *env,
2554 struct dt_object *dt,
2555 const struct lu_buf *buf,
2556 const char *name, int fl,
2560 LASSERT(dt->do_ops);
2561 LASSERT(dt->do_ops->do_declare_xattr_set);
2563 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2564 return cfs_fail_err;
2566 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2569 static inline int dt_xattr_set(const struct lu_env *env,
2570 struct dt_object *dt, const struct lu_buf *buf,
2571 const char *name, int fl, struct thandle *th)
2574 LASSERT(dt->do_ops);
2575 LASSERT(dt->do_ops->do_xattr_set);
2577 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2578 return cfs_fail_err;
2580 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2583 static inline int dt_declare_xattr_get(const struct lu_env *env,
2584 struct dt_object *dt,
2589 LASSERT(dt->do_ops);
2590 LASSERT(dt->do_ops->do_declare_xattr_get);
2592 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2593 return cfs_fail_err;
2595 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2598 static inline int dt_xattr_get(const struct lu_env *env,
2599 struct dt_object *dt, struct lu_buf *buf,
2603 LASSERT(dt->do_ops);
2604 LASSERT(dt->do_ops->do_xattr_get);
2606 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2607 return cfs_fail_err;
2609 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2612 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2613 const struct lu_buf *buf)
2616 LASSERT(dt->do_ops);
2617 LASSERT(dt->do_ops->do_xattr_list);
2619 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2620 return cfs_fail_err;
2622 return dt->do_ops->do_xattr_list(env, dt, buf);
2625 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2628 LASSERT(dt->do_ops);
2629 LASSERT(dt->do_ops->do_invalidate);
2631 return dt->do_ops->do_invalidate(env, dt);
2634 static inline int dt_declare_delete(const struct lu_env *env,
2635 struct dt_object *dt,
2636 const struct dt_key *key,
2640 LASSERT(dt->do_index_ops);
2641 LASSERT(dt->do_index_ops->dio_declare_delete);
2643 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2644 return cfs_fail_err;
2646 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2649 static inline int dt_delete(const struct lu_env *env,
2650 struct dt_object *dt,
2651 const struct dt_key *key,
2655 LASSERT(dt->do_index_ops);
2656 LASSERT(dt->do_index_ops->dio_delete);
2658 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2659 return cfs_fail_err;
2661 return dt->do_index_ops->dio_delete(env, dt, key, th);
2664 static inline int dt_commit_async(const struct lu_env *env,
2665 struct dt_device *dev)
2668 LASSERT(dev->dd_ops);
2669 LASSERT(dev->dd_ops->dt_commit_async);
2670 return dev->dd_ops->dt_commit_async(env, dev);
2673 static inline int dt_lookup(const struct lu_env *env,
2674 struct dt_object *dt,
2676 const struct dt_key *key)
2681 LASSERT(dt->do_index_ops);
2682 LASSERT(dt->do_index_ops->dio_lookup);
2684 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2685 return cfs_fail_err;
2687 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2695 struct dt_find_hint {
2696 struct lu_fid *dfh_fid;
2697 struct dt_device *dfh_dt;
2698 struct dt_object *dfh_o;
2701 struct dt_insert_rec {
2703 const struct lu_fid *rec_fid;
2715 struct dt_thread_info {
2716 char dti_buf[DT_MAX_PATH];
2717 struct dt_find_hint dti_dfh;
2718 struct lu_attr dti_attr;
2719 struct lu_fid dti_fid;
2720 struct dt_object_format dti_dof;
2721 struct lustre_mdt_attrs dti_lma;
2722 struct lu_buf dti_lb;
2723 struct lu_object_conf dti_conf;
2725 struct dt_insert_rec dti_dt_rec;
2728 extern struct lu_context_key dt_key;
2730 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2732 struct dt_thread_info *dti;
2734 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2739 int dt_global_init(void);
2740 void dt_global_fini(void);
2742 # ifdef CONFIG_PROC_FS
2743 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2744 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2745 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2746 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2747 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2748 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2749 # endif /* CONFIG_PROC_FS */
2751 #endif /* __LUSTRE_DT_OBJECT_H */