4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
32 #ifndef __LUSTRE_DT_OBJECT_H
33 #define __LUSTRE_DT_OBJECT_H
36 * Sub-class of lu_object with methods common for "data" objects in OST stack.
38 * Data objects behave like regular files: you can read/write them, get and
39 * set their attributes. Implementation of dt interface is supposed to
40 * implement some form of garbage collection, normally reference counting
43 * Examples: osd (lustre/osd) is an implementation of dt interface.
47 #include <obd_support.h>
49 * super-class definitions.
51 #include <lu_object.h>
53 #include <libcfs/libcfs.h>
56 struct proc_dir_entry;
62 struct dt_index_features;
65 struct ldlm_enqueue_info;
68 MNTOPT_USERXATTR = 0x00000001,
69 MNTOPT_ACL = 0x00000002,
72 struct dt_device_param {
73 unsigned ddp_max_name_len;
74 unsigned ddp_max_nlink;
75 unsigned ddp_symlink_max;
77 unsigned ddp_max_ea_size;
78 unsigned ddp_mount_type;
79 unsigned long long ddp_maxbytes;
80 /* per-inode space consumption */
82 /* maximum number of blocks in an extent */
83 unsigned ddp_max_extent_blks;
84 /* per-extent insertion overhead to be used by client for grant
86 unsigned int ddp_extent_tax;
87 unsigned int ddp_brw_size; /* optimal RPC size */
88 /* T10PI checksum type, zero if not supported */
89 enum cksum_types ddp_t10_cksum_type;
90 bool ddp_has_lseek_data_hole;
94 * Per-transaction commit callback function
96 struct dt_txn_commit_cb;
97 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
98 struct dt_txn_commit_cb *cb, int err);
100 * Special per-transaction callback for cases when just commit callback
101 * is needed and per-device callback are not convenient to use
103 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
104 #define MAX_COMMIT_CB_STR_LEN 32
106 #define DCB_TRANS_STOP 0x1
107 struct dt_txn_commit_cb {
108 struct list_head dcb_linkage;
113 char dcb_name[MAX_COMMIT_CB_STR_LEN];
117 * Operations on dt device.
119 struct dt_device_operations {
121 * Return device-wide statistics.
123 * Return device-wide stats including block size, total and
124 * free blocks, total and free objects, etc. See struct obd_statfs
127 * \param[in] env execution environment for this thread
128 * \param[in] dev dt device
129 * \param[out] osfs stats information
131 * \retval 0 on success
132 * \retval negative negated errno on error
134 int (*dt_statfs)(const struct lu_env *env,
135 struct dt_device *dev,
136 struct obd_statfs *osfs,
137 struct obd_statfs_info *info);
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);
258 * Return device's super block.
260 * \param[in] dev dt device
262 struct super_block *(*dt_mnt_sb_get)(const struct dt_device *dev);
267 * Sync all the cached state (dirty buffers, pages, etc) to the
268 * persistent storage. The method returns control once the sync is
269 * complete. This operation may incur significant I/O to disk and
270 * should be reserved for cases where a global sync is strictly
273 * \param[in] env execution environment for this thread
274 * \param[in] dev dt device
276 * \retval 0 on success
277 * \retval negative negated errno on error
279 int (*dt_sync)(const struct lu_env *env,
280 struct dt_device *dev);
283 * Make device read-only.
285 * Prevent new modifications to the device. This is a very specific
286 * state where all the changes are accepted successfully and the
287 * commit callbacks are called, but persistent state never changes.
288 * Used only in the tests to simulate power-off scenario.
290 * \param[in] env execution environment for this thread
291 * \param[in] dev dt device
293 * \retval 0 on success
294 * \retval negative negated errno on error
296 int (*dt_ro)(const struct lu_env *env,
297 struct dt_device *dev);
300 * Start transaction commit asynchronously.
303 * Provide a hint to the underlying filesystem that it should start
304 * committing soon. The control returns immediately. It's up to the
305 * layer implementing the method how soon to start committing. Usually
306 * this should be throttled to some extent, otherwise the number of
307 * aggregated transaction goes too high causing performance drop.
309 * \param[in] env execution environment for this thread
310 * \param[in] dev dt device
312 * \retval 0 on success
313 * \retval negative negated errno on error
315 int (*dt_commit_async)(const struct lu_env *env,
316 struct dt_device *dev);
319 struct dt_index_features {
320 /** required feature flags from enum dt_index_flags */
322 /** minimal required key size */
323 size_t dif_keysize_min;
324 /** maximal required key size, 0 if no limit */
325 size_t dif_keysize_max;
326 /** minimal required record size */
327 size_t dif_recsize_min;
328 /** maximal required record size, 0 if no limit */
329 size_t dif_recsize_max;
330 /** pointer size for record */
334 enum dt_index_flags {
335 /** index supports variable sized keys */
336 DT_IND_VARKEY = BIT(0),
337 /** index supports variable sized records */
338 DT_IND_VARREC = BIT(1),
339 /** index can be modified */
340 DT_IND_UPDATE = BIT(2),
341 /** index supports records with non-unique (duplicate) keys */
342 DT_IND_NONUNQ = BIT(3),
344 * index support fixed-size keys sorted with natural numerical way
345 * and is able to return left-side value if no exact value found
347 DT_IND_RANGE = BIT(4),
350 /* for dt_read_lock() and dt_write_lock() object lock rule */
351 enum dt_object_role {
361 * Features, required from index to support file system directories (mapping
364 extern const struct dt_index_features dt_directory_features;
365 extern const struct dt_index_features dt_otable_features;
366 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
367 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
368 extern const struct dt_index_features dt_lfsck_namespace_features;
370 /* index features supported by the accounting objects */
371 extern const struct dt_index_features dt_acct_features;
373 /* index features supported by the quota global indexes */
374 extern const struct dt_index_features dt_quota_glb_features;
376 /* index features supported by the quota slave indexes */
377 extern const struct dt_index_features dt_quota_slv_features;
379 /* index features supported by the nodemap index */
380 extern const struct dt_index_features dt_nodemap_features;
383 * This is a general purpose dt allocation hint.
384 * It now contains the parent object.
385 * It can contain any allocation hint in the future.
387 struct dt_allocation_hint {
388 struct dt_object *dah_parent;
389 const void *dah_eadata;
392 int dah_append_stripes;
394 char *dah_append_pool;
398 * object type specifier.
401 enum dt_format_type {
406 /** for special index */
408 /** for symbolic link */
413 * object format specifier.
415 struct dt_object_format {
416 /** type for dt object */
417 enum dt_format_type dof_type;
427 * special index need feature as parameter to create
431 const struct dt_index_features *di_feat;
436 enum dt_format_type dt_mode_to_dft(__u32 mode);
438 typedef __u64 dt_obj_version_t;
440 union ldlm_policy_data;
442 struct md_layout_change;
445 * A dt_object provides common operations to create and destroy
446 * objects and to manage regular and extended attributes.
448 struct dt_object_operations {
450 * Get read lock on object.
452 * Read lock is compatible with other read locks, so it's shared.
453 * Read lock is not compatible with write lock which is exclusive.
454 * The lock is blocking and can't be used from an interrupt context.
456 * \param[in] env execution environment for this thread
457 * \param[in] dt object to lock for reading
458 * \param[in] role a hint to debug locks (see kernel's mutexes)
460 void (*do_read_lock)(const struct lu_env *env,
461 struct dt_object *dt,
465 * Get write lock on object.
467 * Write lock is exclusive and cannot be shared. The lock is blocking
468 * and can't be used from an interrupt context.
470 * \param[in] env execution environment for this thread
471 * \param[in] dt object to lock for writing
472 * \param[in] role a hint to debug locks (see kernel's mutexes)
475 void (*do_write_lock)(const struct lu_env *env,
476 struct dt_object *dt,
482 * \param[in] env execution environment for this thread
483 * \param[in] dt object
485 void (*do_read_unlock)(const struct lu_env *env,
486 struct dt_object *dt);
489 * Release write lock.
491 * \param[in] env execution environment for this thread
492 * \param[in] dt object
494 void (*do_write_unlock)(const struct lu_env *env,
495 struct dt_object *dt);
498 * Check whether write lock is held.
500 * The caller can learn whether write lock is held on the object
502 * \param[in] env execution environment for this thread
503 * \param[in] dt object
505 * \retval 0 no write lock
506 * \retval 1 write lock is held
508 int (*do_write_locked)(const struct lu_env *env,
509 struct dt_object *dt);
512 * Declare intention to request reqular attributes.
514 * Notity the underlying filesystem that the caller may request regular
515 * attributes with ->do_attr_get() soon. This allows OSD to implement
516 * prefetching logic in an object-oriented manner. The implementation
517 * can be noop. This method should avoid expensive delays such as
518 * waiting on disk I/O, otherwise the goal of enabling a performance
519 * optimization would be defeated.
521 * \param[in] env execution environment for this thread
522 * \param[in] dt object
524 * \retval 0 on success
525 * \retval negative negated errno on error
527 int (*do_declare_attr_get)(const struct lu_env *env,
528 struct dt_object *dt);
531 * Return regular attributes.
533 * The object must exist. Currently all the attributes should be
534 * returned, but in the future this can be improved so that only
535 * a selected set is returned. This can improve performance as in
536 * some cases attributes are stored in different places and
537 * getting them all can be an iterative and expensive process.
539 * \param[in] env execution environment for this thread
540 * \param[in] dt object
541 * \param[out] attr attributes to fill
543 * \retval 0 on success
544 * \retval negative negated errno on error
546 int (*do_attr_get)(const struct lu_env *env,
547 struct dt_object *dt,
548 struct lu_attr *attr);
551 * Declare intention to change regular object's attributes.
553 * Notify the underlying filesystem that the regular attributes may
554 * change in this transaction. This enables the layer below to prepare
555 * resources (e.g. journal credits in ext4). This method should be
556 * called between creating the transaction and starting it. Note that
557 * the la_valid field of \a attr specifies which attributes will change.
558 * The object need not exist.
560 * \param[in] env execution environment for this thread
561 * \param[in] dt object
562 * \param[in] attr attributes to change specified in attr.la_valid
563 * \param[in] th transaction handle
565 * \retval 0 on success
566 * \retval negative negated errno on error
568 int (*do_declare_attr_set)(const struct lu_env *env,
569 struct dt_object *dt,
570 const struct lu_attr *attr,
574 * Change regular attributes.
576 * Change regular attributes in the given transaction. Note only
577 * attributes flagged by attr.la_valid change. The object must
578 * exist. If the layer implementing this method is responsible for
579 * quota, then the method should maintain object accounting for the
580 * given credentials when la_uid/la_gid changes.
582 * \param[in] env execution environment for this thread
583 * \param[in] dt object
584 * \param[in] attr new attributes to apply
585 * \param[in] th transaction handle
587 * \retval 0 on success
588 * \retval negative negated errno on error
590 int (*do_attr_set)(const struct lu_env *env,
591 struct dt_object *dt,
592 const struct lu_attr *attr,
596 * Declare intention to request extented attribute.
598 * Notify the underlying filesystem that the caller may request extended
599 * attribute with ->do_xattr_get() soon. This allows OSD to implement
600 * prefetching logic in an object-oriented manner. The implementation
601 * can be noop. This method should avoid expensive delays such as
602 * waiting on disk I/O, otherwise the goal of enabling a performance
603 * optimization would be defeated.
605 * \param[in] env execution environment for this thread
606 * \param[in] dt object
607 * \param[in] buf unused, may be removed in the future
608 * \param[in] name name of the extended attribute
610 * \retval 0 on success
611 * \retval negative negated errno on error
613 int (*do_declare_xattr_get)(const struct lu_env *env,
614 struct dt_object *dt,
619 * Return a value of an extended attribute.
621 * The object must exist. If the buffer is NULL, then the method
622 * must return the size of the value.
624 * \param[in] env execution environment for this thread
625 * \param[in] dt object
626 * \param[out] buf buffer in which to store the value
627 * \param[in] name name of the extended attribute
629 * \retval 0 on success
630 * \retval -ERANGE if \a buf is too small
631 * \retval negative negated errno on error
632 * \retval positive value's size if \a buf is NULL or has zero size
634 int (*do_xattr_get)(const struct lu_env *env,
635 struct dt_object *dt,
640 * Declare intention to change an extended attribute.
642 * Notify the underlying filesystem that the extended attribute may
643 * change in this transaction. This enables the layer below to prepare
644 * resources (e.g. journal credits in ext4). This method should be
645 * called between creating the transaction and starting it. The object
648 * \param[in] env execution environment for this thread
649 * \param[in] dt object
650 * \param[in] buf buffer storing new value of the attribute
651 * \param[in] name name of the attribute
652 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
653 * LU_XATTR_REPLACE - fail if EA doesn't exist
654 * \param[in] th transaction handle
656 * \retval 0 on success
657 * \retval negative negated errno on error
659 int (*do_declare_xattr_set)(const struct lu_env *env,
660 struct dt_object *dt,
661 const struct lu_buf *buf,
667 * Set an extended attribute.
669 * Change or replace the specified extended attribute (EA).
670 * The flags passed in \a fl dictate whether the EA is to be
671 * created or replaced, as follows.
672 * LU_XATTR_CREATE - fail if EA exists
673 * LU_XATTR_REPLACE - fail if EA doesn't exist
674 * The object must exist.
676 * \param[in] env execution environment for this thread
677 * \param[in] dt object
678 * \param[in] buf buffer storing new value of the attribute
679 * \param[in] name name of the attribute
680 * \param[in] fl flags indicating EA creation or replacement
681 * \param[in] th transaction handle
683 * \retval 0 on success
684 * \retval negative negated errno on error
686 int (*do_xattr_set)(const struct lu_env *env,
687 struct dt_object *dt,
688 const struct lu_buf *buf,
694 * Declare intention to delete an extended attribute.
696 * Notify the underlying filesystem that the extended attribute may
697 * be deleted in this transaction. This enables the layer below to
698 * prepare resources (e.g. journal credits in ext4). This method
699 * should be called between creating the transaction and starting it.
700 * The object need not exist.
702 * \param[in] env execution environment for this thread
703 * \param[in] dt object
704 * \param[in] name name of the attribute
705 * \param[in] th transaction handle
707 * \retval 0 on success
708 * \retval negative negated errno on error
710 int (*do_declare_xattr_del)(const struct lu_env *env,
711 struct dt_object *dt,
716 * Delete an extended attribute.
718 * This method deletes the specified extended attribute. The object
721 * \param[in] env execution environment for this thread
722 * \param[in] dt object
723 * \param[in] name name of the attribute
724 * \param[in] th transaction handle
726 * \retval 0 on success
727 * \retval negative negated errno on error
729 int (*do_xattr_del)(const struct lu_env *env,
730 struct dt_object *dt,
735 * Return a list of the extended attributes.
737 * Fills the passed buffer with a list of the extended attributes
738 * found in the object. The names are separated with '\0'.
739 * The object must exist.
741 * \param[in] env execution environment for this thread
742 * \param[in] dt object
743 * \param[out] buf buffer to put the list in
745 * \retval positive bytes used/required in the buffer
746 * \retval negative negated errno on error
748 int (*do_xattr_list)(const struct lu_env *env,
749 struct dt_object *dt,
750 const struct lu_buf *buf);
753 * Prepare allocation hint for a new object.
755 * This method is used by the caller to inform OSD of the parent-child
756 * relationship between two objects and enable efficient object
757 * allocation. Filled allocation hint will be passed to ->do_create()
760 * \param[in] env execution environment for this thread
761 * \param[out] ah allocation hint
762 * \param[in] parent parent object (can be NULL)
763 * \param[in] child child object
764 * \param[in] _mode type of the child object
766 void (*do_ah_init)(const struct lu_env *env,
767 struct dt_allocation_hint *ah,
768 struct dt_object *parent,
769 struct dt_object *child,
773 * Declare intention to create a new object.
775 * Notify the underlying filesystem that the object may be created
776 * in this transaction. This enables the layer below to prepare
777 * resources (e.g. journal credits in ext4). This method should be
778 * called between creating the transaction and starting it.
780 * If the layer implementing this method is responsible for quota,
781 * then the method should reserve an object for the given credentials
782 * and return an error if quota is over. If object creation later
783 * fails for some reason, then the reservation should be released
784 * properly (usually in ->dt_trans_stop()).
786 * \param[in] env execution environment for this thread
787 * \param[in] dt object
788 * \param[in] attr attributes of the new object
789 * \param[in] hint allocation hint
790 * \param[in] dof object format
791 * \param[in] th transaction handle
793 * \retval 0 on success
794 * \retval negative negated errno on error
796 int (*do_declare_create)(const struct lu_env *env,
797 struct dt_object *dt,
798 struct lu_attr *attr,
799 struct dt_allocation_hint *hint,
800 struct dt_object_format *dof,
806 * The method creates the object passed with the specified attributes
807 * and object format. Object allocation procedure can use information
808 * stored in the allocation hint. Different object formats are supported
809 * (see enum dt_format_type and struct dt_object_format) depending on
810 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
811 * in the LU-object header attributes.
813 * If the layer implementing this method is responsible for quota,
814 * then the method should maintain object accounting for the given
817 * \param[in] env execution environment for this thread
818 * \param[in] dt object
819 * \param[in] attr attributes of the new object
820 * \param[in] hint allocation hint
821 * \param[in] dof object format
822 * \param[in] th transaction handle
824 * \retval 0 on success
825 * \retval negative negated errno on error
827 int (*do_create)(const struct lu_env *env,
828 struct dt_object *dt,
829 struct lu_attr *attr,
830 struct dt_allocation_hint *hint,
831 struct dt_object_format *dof,
835 * Declare intention to destroy an object.
837 * Notify the underlying filesystem that the object may be destroyed
838 * in this transaction. This enables the layer below to prepare
839 * resources (e.g. journal credits in ext4). This method should be
840 * called between creating the transaction and starting it. The object
843 * \param[in] env execution environment for this thread
844 * \param[in] dt object
845 * \param[in] th transaction handle
847 * \retval 0 on success
848 * \retval negative negated errno on error
850 int (*do_declare_destroy)(const struct lu_env *env,
851 struct dt_object *dt,
857 * This method destroys the object and all the resources associated
858 * with the object (data, key/value pairs, extended attributes, etc).
859 * The object must exist. If destroy is successful, then flag
860 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
861 * instance of in-core object. Any subsequent access to the same FID
862 * should get another instance with no LOHA_EXIST flag set.
864 * If the layer implementing this method is responsible for quota,
865 * then the method should maintain object accounting for the given
868 * \param[in] env execution environment for this thread
869 * \param[in] dt object
870 * \param[in] th transaction handle
872 * \retval 0 on success
873 * \retval negative negated errno on error
875 int (*do_destroy)(const struct lu_env *env,
876 struct dt_object *dt,
880 * Try object as an index.
882 * Announce that this object is going to be used as an index. This
883 * operation checks that object supports indexing operations and
884 * installs appropriate dt_index_operations vector on success.
885 * Also probes for features. Operation is successful if all required
886 * features are supported. It's not possible to access the object
887 * with index methods before ->do_index_try() returns success.
889 * \param[in] env execution environment for this thread
890 * \param[in] dt object
891 * \param[in] feat index features
893 * \retval 0 on success
894 * \retval negative negated errno on error
896 int (*do_index_try)(const struct lu_env *env,
897 struct dt_object *dt,
898 const struct dt_index_features *feat);
901 * Declare intention to increment nlink count.
903 * Notify the underlying filesystem that the nlink regular attribute
904 * be changed in this transaction. This enables the layer below to
905 * prepare resources (e.g. journal credits in ext4). This method
906 * should be called between creating the transaction and starting it.
907 * The object need not exist.
909 * \param[in] env execution environment for this thread
910 * \param[in] dt object
911 * \param[in] th transaction handle
913 * \retval 0 on success
914 * \retval negative negated errno on error
916 int (*do_declare_ref_add)(const struct lu_env *env,
917 struct dt_object *dt,
923 * Increment nlink (from the regular attributes set) in the given
924 * transaction. Note the absolute limit for nlink should be learnt
925 * from struct dt_device_param::ddp_max_nlink. The object must exist.
927 * \param[in] env execution environment for this thread
928 * \param[in] dt object
929 * \param[in] th transaction handle
931 * \retval 0 on success
932 * \retval negative negated errno on error
934 int (*do_ref_add)(const struct lu_env *env,
935 struct dt_object *dt, struct thandle *th);
938 * Declare intention to decrement nlink count.
940 * Notify the underlying filesystem that the nlink regular attribute
941 * be changed in this transaction. This enables the layer below to
942 * prepare resources (e.g. journal credits in ext4). This method
943 * should be called between creating the transaction and starting it.
944 * The object need not exist.
946 * \param[in] env execution environment for this thread
947 * \param[in] dt object
948 * \param[in] th transaction handle
950 * \retval 0 on success
951 * \retval negative negated errno on error
953 int (*do_declare_ref_del)(const struct lu_env *env,
954 struct dt_object *dt,
960 * Decrement nlink (from the regular attributes set) in the given
961 * transaction. The object must exist.
963 * \param[in] env execution environment for this thread
964 * \param[in] dt object
965 * \param[in] th transaction handle
967 * \retval 0 on success
968 * \retval negative negated errno on error
970 int (*do_ref_del)(const struct lu_env *env,
971 struct dt_object *dt,
977 * The method is called to sync specified range of the object to a
978 * persistent storage. The control is returned once the operation is
979 * complete. The difference from ->do_sync() is that the object can
980 * be in-sync with the persistent storage (nothing to flush), then
981 * the method returns quickly with no I/O overhead. So, this method
982 * should be preferred over ->do_sync() where possible. Also note that
983 * if the object isn't clean, then some disk filesystems will call
984 * ->do_sync() to maintain overall consistency, in which case it's
985 * still very expensive.
987 * \param[in] env execution environment for this thread
988 * \param[in] dt object
989 * \param[in] start start of the range to sync
990 * \param[in] end end of the range to sync
992 * \retval 0 on success
993 * \retval negative negated errno on error
995 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
996 __u64 start, __u64 end);
1001 * Lock object(s) using Distributed Lock Manager (LDLM).
1003 * Get LDLM locks for the object. Currently used to lock "remote"
1004 * objects in DNE configuration - a service running on MDTx needs
1005 * to lock an object on MDTy.
1007 * \param[in] env execution environment for this thread
1008 * \param[in] dt object
1009 * \param[out] lh lock handle, sometimes used, sometimes not
1010 * \param[in] einfo ldlm callbacks, locking type and mode
1011 * \param[out] einfo private data to be passed to unlock later
1012 * \param[in] policy inodebits data
1014 * \retval 0 on success
1015 * \retval negative negated errno on error
1017 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1018 struct lustre_handle *lh,
1019 struct ldlm_enqueue_info *einfo,
1020 union ldlm_policy_data *policy);
1025 * Release LDLM lock(s) granted with ->do_object_lock().
1027 * \param[in] env execution environment for this thread
1028 * \param[in] dt object
1029 * \param[in] einfo lock handles, from ->do_object_lock()
1030 * \param[in] policy inodebits data
1032 * \retval 0 on success
1033 * \retval negative negated errno on error
1035 int (*do_object_unlock)(const struct lu_env *env,
1036 struct dt_object *dt,
1037 struct ldlm_enqueue_info *einfo,
1038 union ldlm_policy_data *policy);
1041 * Invalidate attribute cache.
1043 * This method invalidate attribute cache of the object, which is on OSP
1046 * \param[in] env execution envionment for this thread
1047 * \param[in] dt object
1049 * \retval 0 on success
1050 * \retval negative negated errno on error
1052 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1055 * Check object stale state.
1059 * \param[in] dt object
1061 * \retval true for stale object
1062 * \retval false for not stale object
1064 bool (*do_check_stale)(struct dt_object *dt);
1067 * Declare intention to instaintiate extended layout component.
1069 * \param[in] env execution environment
1070 * \param[in] dt DT object
1071 * \param[in] layout data structure to describe the changes to
1072 * the DT object's layout
1073 * \param[in] buf buffer containing client's lovea or empty
1076 * \retval -ne error code
1078 int (*do_declare_layout_change)(const struct lu_env *env,
1079 struct dt_object *dt,
1080 struct md_layout_change *mlc,
1081 struct thandle *th);
1084 * Client is trying to write to un-instantiated layout component.
1086 * \param[in] env execution environment
1087 * \param[in] dt DT object
1088 * \param[in] layout data structure to describe the changes to
1089 * the DT object's layout
1090 * \param[in] buf buffer containing client's lovea or empty
1093 * \retval -ne error code
1095 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1096 struct md_layout_change *mlc,
1097 struct thandle *th);
1101 DT_BUFS_TYPE_READ = 0x0000,
1102 DT_BUFS_TYPE_WRITE = 0x0001,
1103 DT_BUFS_TYPE_READAHEAD = 0x0002,
1104 DT_BUFS_TYPE_LOCAL = 0x0004,
1108 * Per-dt-object operations on "file body" - unstructure raw data.
1110 struct dt_body_operations {
1114 * Read unstructured data from an existing regular object.
1115 * Only data before attr.la_size is returned.
1117 * \param[in] env execution environment for this thread
1118 * \param[in] dt object
1119 * \param[out] buf buffer (including size) to copy data in
1120 * \param[in] pos position in the object to start
1121 * \param[out] pos original value of \a pos + bytes returned
1123 * \retval positive bytes read on success
1124 * \retval negative negated errno on error
1126 ssize_t (*dbo_read)(const struct lu_env *env,
1127 struct dt_object *dt,
1132 * Declare intention to write data to object.
1134 * Notify the underlying filesystem that data may be written in
1135 * this transaction. This enables the layer below to prepare resources
1136 * (e.g. journal credits in ext4). This method should be called
1137 * between creating the transaction and starting it. The object need
1138 * not exist. If the layer implementing this method is responsible for
1139 * quota, then the method should reserve space for the given credentials
1140 * and return an error if quota is over. If the write later fails
1141 * for some reason, then the reserve should be released properly
1142 * (usually in ->dt_trans_stop()).
1144 * \param[in] env execution environment for this thread
1145 * \param[in] dt object
1146 * \param[in] buf buffer (including size) to copy data from
1147 * \param[in] pos position in the object to start
1148 * \param[in] th transaction handle
1150 * \retval 0 on success
1151 * \retval negative negated errno on error
1153 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1154 struct dt_object *dt,
1155 const struct lu_buf *buf,
1157 struct thandle *th);
1160 * Write unstructured data to regular existing object.
1162 * The method allocates space and puts data in. Also, the method should
1163 * maintain attr.la_size properly. Partial writes are possible.
1165 * If the layer implementing this method is responsible for quota,
1166 * then the method should maintain space accounting for the given
1169 * \param[in] env execution environment for this thread
1170 * \param[in] dt object
1171 * \param[in] buf buffer (including size) to copy data from
1172 * \param[in] pos position in the object to start
1173 * \param[out] pos \a pos + bytes written
1174 * \param[in] th transaction handle
1176 * \retval positive bytes written on success
1177 * \retval negative negated errno on error
1179 ssize_t (*dbo_write)(const struct lu_env *env,
1180 struct dt_object *dt,
1181 const struct lu_buf *buf,
1183 struct thandle *th);
1186 * Return buffers for data.
1188 * This method is used to access data with no copying. It's so-called
1189 * zero-copy I/O. The method returns the descriptors for the internal
1190 * buffers where data are managed by the disk filesystem. For example,
1191 * pagecache in case of ext4 or ARC with ZFS. Then other components
1192 * (e.g. networking) can transfer data from or to the buffers with no
1193 * additional copying.
1195 * The method should fill an array of struct niobuf_local, where
1196 * each element describes a full or partial page for data at specific
1197 * offset. The caller should use page/lnb_page_offset/len to find data
1198 * at object's offset lnb_file_offset.
1200 * The memory referenced by the descriptors can't change its purpose
1201 * until the complementary ->dbo_bufs_put() is called. The caller should
1202 * specify if the buffers are used to read or modify data so that OSD
1203 * can decide how to initialize the buffers: bring all the data for
1204 * reads or just bring partial buffers for write. Note: the method does
1205 * not check whether output array is large enough.
1207 * \param[in] env execution environment for this thread
1208 * \param[in] dt object
1209 * \param[in] pos position in the object to start
1210 * \param[in] len size of region in bytes
1211 * \param[out] lb array of descriptors to fill
1212 * \param[in] maxlnb max slots in @lnb array
1213 * \param[in] rw 0 if used to read, 1 if used for write
1215 * \retval positive number of descriptors on success
1216 * \retval negative negated errno on error
1218 int (*dbo_bufs_get)(const struct lu_env *env,
1219 struct dt_object *dt,
1222 struct niobuf_local *lb,
1224 enum dt_bufs_type rw);
1227 * Release reference granted by ->dbo_bufs_get().
1229 * Release the reference granted by the previous ->dbo_bufs_get().
1230 * Note the references are counted.
1232 * \param[in] env execution environment for this thread
1233 * \param[in] dt object
1234 * \param[out] lb array of descriptors to fill
1235 * \param[in] nr size of the array
1237 * \retval 0 on success
1238 * \retval negative negated errno on error
1240 int (*dbo_bufs_put)(const struct lu_env *env,
1241 struct dt_object *dt,
1242 struct niobuf_local *lb,
1246 * Prepare buffers for reading.
1248 * The method is called on the given buffers to fill them with data
1249 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1250 * caller should be able to get few buffers for discontiguous regions
1251 * using few calls to ->dbo_bufs_get() and then request them all for
1252 * the preparation with a single call, so that OSD can fire many I/Os
1253 * to run concurrently. It's up to the specific OSD whether to implement
1254 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1255 * prepare data for every requested region individually.
1257 * \param[in] env execution environment for this thread
1258 * \param[in] dt object
1259 * \param[in] lnb array of buffer descriptors
1260 * \param[in] nr size of the array
1262 * \retval 0 on success
1263 * \retval negative negated errno on error
1265 int (*dbo_read_prep)(const struct lu_env *env,
1266 struct dt_object *dt,
1267 struct niobuf_local *lnb,
1271 * Prepare buffers for write.
1273 * This method is called on the given buffers to ensure the partial
1274 * buffers contain correct data. The underlying idea is the same as
1275 * in ->db_read_prep().
1277 * \param[in] env execution environment for this thread
1278 * \param[in] dt object
1279 * \param[in] lb array of buffer descriptors
1280 * \param[in] nr size of the array
1282 * \retval 0 on success
1283 * \retval negative negated errno on error
1285 int (*dbo_write_prep)(const struct lu_env *env,
1286 struct dt_object *dt,
1287 struct niobuf_local *lb,
1291 * Declare intention to write data stored in the buffers.
1293 * Notify the underlying filesystem that data may be written in
1294 * this transaction. This enables the layer below to prepare resources
1295 * (e.g. journal credits in ext4). This method should be called
1296 * between creating the transaction and starting it.
1298 * If the layer implementing this method is responsible for quota,
1299 * then the method should be reserving a space for the given
1300 * credentials and return an error if quota is exceeded. If the write
1301 * later fails for some reason, then the reserve should be released
1302 * properly (usually in ->dt_trans_stop()).
1304 * \param[in] env execution environment for this thread
1305 * \param[in] dt object
1306 * \param[in] lb array of descriptors
1307 * \param[in] nr size of the array
1308 * \param[in] th transaction handle
1310 * \retval 0 on success
1311 * \retval negative negated errno on error
1313 int (*dbo_declare_write_commit)(const struct lu_env *env,
1314 struct dt_object *dt,
1315 struct niobuf_local *lb,
1317 struct thandle *th);
1320 * Write to existing object.
1322 * This method is used to write data to a persistent storage using
1323 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1324 * data into the buffers using own mechanisms (e.g. direct transfer
1325 * from a NIC). The method should maintain attr.la_size. Also,
1326 * attr.la_blocks should be maintained but this can be done in lazy
1327 * manner, when actual allocation happens.
1329 * If the layer implementing this method is responsible for quota,
1330 * then the method should maintain space accounting for the given
1333 * user_size parameter is the apparent size of the file, ie the size
1334 * of the clear text version of the file. It can differ from the actual
1335 * amount of valuable data received when a file is encrypted,
1336 * because encrypted pages always contain PAGE_SIZE bytes of data,
1337 * even if clear text data is only a few bytes.
1338 * In case of encrypted file, apparent size will be stored as the inode
1339 * size, so that servers return to clients an object size they can use
1340 * to determine clear text size.
1342 * \param[in] env execution environment for this thread
1343 * \param[in] dt object
1344 * \param[in] lb array of descriptors for the buffers
1345 * \param[in] nr size of the array
1346 * \param[in] th transaction handle
1347 * \param[in] user_size apparent size
1349 * \retval 0 on success
1350 * \retval negative negated errno on error
1352 int (*dbo_write_commit)(const struct lu_env *env,
1353 struct dt_object *dt,
1354 struct niobuf_local *lb,
1360 * Return logical to physical block mapping for a given extent
1362 * \param[in] env execution environment for this thread
1363 * \param[in] dt object
1364 * \param[in] fm describe the region to map and the output buffer
1365 * see the details in include/linux/fiemap.h
1367 * \retval 0 on success
1368 * \retval negative negated errno on error
1370 int (*dbo_fiemap_get)(const struct lu_env *env,
1371 struct dt_object *dt,
1375 * Declare intention to deallocate space from an object.
1377 * Notify the underlying filesystem that space may be deallocated in
1378 * this transactions. This enables the layer below to prepare resources
1379 * (e.g. journal credits in ext4). This method should be called between
1380 * creating the transaction and starting it. The object need not exist.
1382 * \param[in] env execution environment for this thread
1383 * \param[in] dt object
1384 * \param[in] start the start of the region to deallocate
1385 * \param[in] end the end of the region to deallocate
1386 * \param[in] th transaction handle
1388 * \retval 0 on success
1389 * \retval negative negated errno on error
1391 int (*dbo_declare_punch)(const struct lu_env *env,
1392 struct dt_object *dt,
1395 struct thandle *th);
1398 * Deallocate specified region in an object.
1400 * This method is used to deallocate (release) space possibly consumed
1401 * by the given region of the object. If the layer implementing this
1402 * method is responsible for quota, then the method should maintain
1403 * space accounting for the given credentials.
1405 * \param[in] env execution environment for this thread
1406 * \param[in] dt object
1407 * \param[in] start the start of the region to deallocate
1408 * \param[in] end the end of the region to deallocate
1409 * \param[in] th transaction handle
1411 * \retval 0 on success
1412 * \retval negative negated errno on error
1414 int (*dbo_punch)(const struct lu_env *env,
1415 struct dt_object *dt,
1418 struct thandle *th);
1420 * Give advices on specified region in an object.
1422 * This method is used to give advices about access pattern on an
1423 * given region of the object. The disk filesystem understands
1424 * the advices and tunes cache/read-ahead policies.
1426 * \param[in] env execution environment for this thread
1427 * \param[in] dt object
1428 * \param[in] start the start of the region affected
1429 * \param[in] end the end of the region affected
1430 * \param[in] advice advice type
1432 * \retval 0 on success
1433 * \retval negative negated errno on error
1435 int (*dbo_ladvise)(const struct lu_env *env,
1436 struct dt_object *dt,
1439 enum lu_ladvise_type advice);
1442 * Declare intention to preallocate space for an object
1444 * \param[in] env execution environment for this thread
1445 * \param[in] dt object
1446 * \param[in] th transaction handle
1448 * \retval 0 on success
1449 * \retval negative negated errno on error
1451 int (*dbo_declare_fallocate)(const struct lu_env *env,
1452 struct dt_object *dt, __u64 start,
1453 __u64 end, int mode, struct thandle *th);
1455 * Allocate specified region for an object
1457 * \param[in] env execution environment for this thread
1458 * \param[in] dt object
1459 * \param[in] start the start of the region to allocate
1460 * \param[in] end the end of the region to allocate
1461 * \param[in] mode fallocate mode
1462 * \param[in] th transaction handle
1464 * \retval 0 on success
1465 * \retval negative negated errno on error
1467 int (*dbo_fallocate)(const struct lu_env *env,
1468 struct dt_object *dt,
1472 struct thandle *th);
1474 * Do SEEK_HOLE/SEEK_DATA request on object
1476 * \param[in] env execution environment for this thread
1477 * \param[in] dt object
1478 * \param[in] offset the offset to start seek from
1479 * \param[in] whence seek mode, SEEK_HOLE or SEEK_DATA
1481 * \retval hole/data offset on success
1482 * \retval negative negated errno on error
1484 loff_t (*dbo_lseek)(const struct lu_env *env, struct dt_object *dt,
1485 loff_t offset, int whence);
1489 * Incomplete type of index record.
1494 * Incomplete type of index key.
1499 * Incomplete type of dt iterator.
1504 * Per-dt-object operations on object as index. Index is a set of key/value
1505 * pairs abstracted from an on-disk representation. An index supports the
1506 * number of operations including lookup by key, insert and delete. Also,
1507 * an index can be iterated to find the pairs one by one, from a beginning
1508 * or specified point.
1510 struct dt_index_operations {
1512 * Lookup in an index by key.
1514 * The method returns a value for the given key. Key/value format
1515 * and size should have been negotiated with ->do_index_try() before.
1516 * Thus it's the caller's responsibility to provide the method with
1517 * proper key and big enough buffer. No external locking is required,
1518 * all the internal consistency should be implemented by the method
1519 * or lower layers. The object should should have been created with
1520 * type DFT_INDEX or DFT_DIR.
1522 * \param[in] env execution environment for this thread
1523 * \param[in] dt object
1524 * \param[out] rec buffer where value will be stored
1525 * \param[in] key key
1527 * \retval 0 on success
1528 * \retval -ENOENT if key isn't found
1529 * \retval negative negated errno on error
1531 int (*dio_lookup)(const struct lu_env *env,
1532 struct dt_object *dt,
1534 const struct dt_key *key);
1537 * Declare intention to insert a key/value into an index.
1539 * Notify the underlying filesystem that new key/value may be inserted
1540 * in this transaction. This enables the layer below to prepare
1541 * resources (e.g. journal credits in ext4). This method should be
1542 * called between creating the transaction and starting it. key/value
1543 * format and size is subject to ->do_index_try().
1545 * \param[in] env execution environment for this thread
1546 * \param[in] dt object
1547 * \param[in] rec buffer storing value
1548 * \param[in] key key
1549 * \param[in] th transaction handle
1551 * \retval 0 on success
1552 * \retval negative negated errno on error
1554 int (*dio_declare_insert)(const struct lu_env *env,
1555 struct dt_object *dt,
1556 const struct dt_rec *rec,
1557 const struct dt_key *key,
1558 struct thandle *th);
1561 * Insert a new key/value pair into an index.
1563 * The method inserts specified key/value pair into the given index
1564 * object. The internal consistency is maintained by the method or
1565 * the functionality below. The format and size of key/value should
1566 * have been negotiated before using ->do_index_try(), no additional
1567 * information can be specified to the method. The keys are unique
1570 * \param[in] env execution environment for this thread
1571 * \param[in] dt object
1572 * \param[in] rec buffer storing value
1573 * \param[in] key key
1574 * \param[in] th transaction handle
1576 * \retval 0 on success
1577 * \retval negative negated errno on error
1579 int (*dio_insert)(const struct lu_env *env,
1580 struct dt_object *dt,
1581 const struct dt_rec *rec,
1582 const struct dt_key *key,
1583 struct thandle *th);
1586 * Declare intention to delete a key/value from an index.
1588 * Notify the underlying filesystem that key/value may be deleted in
1589 * this transaction. This enables the layer below to prepare resources
1590 * (e.g. journal credits in ext4). This method should be called
1591 * between creating the transaction and starting it. Key/value format
1592 * and size is subject to ->do_index_try(). The object need not exist.
1594 * \param[in] env execution environment for this thread
1595 * \param[in] dt object
1596 * \param[in] key key
1597 * \param[in] th transaction handle
1599 * \retval 0 on success
1600 * \retval negative negated errno on error
1602 int (*dio_declare_delete)(const struct lu_env *env,
1603 struct dt_object *dt,
1604 const struct dt_key *key,
1605 struct thandle *th);
1608 * Delete key/value pair from an index.
1610 * The method deletes specified key and corresponding value from the
1611 * given index object. The internal consistency is maintained by the
1612 * method or the functionality below. The format and size of the key
1613 * should have been negotiated before using ->do_index_try(), no
1614 * additional information can be specified to the method.
1616 * \param[in] env execution environment for this thread
1617 * \param[in] dt object
1618 * \param[in] key key
1619 * \param[in] th transaction handle
1621 * \retval 0 on success
1622 * \retval negative negated errno on error
1624 int (*dio_delete)(const struct lu_env *env,
1625 struct dt_object *dt,
1626 const struct dt_key *key,
1627 struct thandle *th);
1630 * Iterator interface.
1632 * Methods to iterate over an existing index, list the keys stored and
1633 * associated values, get key/value size, etc.
1637 * Allocate and initialize new iterator.
1639 * The iterator is a handler to be used in the subsequent
1640 * methods to access index's content. Note the position is
1641 * not defined at this point and should be initialized with
1642 * ->get() or ->load() method.
1644 * \param[in] env execution environment for this thread
1645 * \param[in] dt object
1646 * \param[in] attr ask the iterator to return part of
1647 the records, see LUDA_* for details
1649 * \retval pointer iterator pointer on success
1650 * \retval ERR_PTR(errno) on error
1652 struct dt_it *(*init)(const struct lu_env *env,
1653 struct dt_object *dt,
1659 * Release the specified iterator and all the resources
1660 * associated (e.g. the object, index cache, etc).
1662 * \param[in] env execution environment for this thread
1663 * \param[in] di iterator to release
1665 void (*fini)(const struct lu_env *env,
1669 * Move position of iterator.
1671 * Move the position of the specified iterator to the specified
1674 * \param[in] env execution environment for this thread
1675 * \param[in] di iterator
1676 * \param[in] key key to position to
1678 * \retval 0 if exact key is found
1679 * \retval 1 if at the record with least key
1680 * not larger than the key
1681 * \retval negative negated errno on error
1683 int (*get)(const struct lu_env *env,
1685 const struct dt_key *key);
1690 * Complimentary method for dt_it_ops::get() above. Some
1691 * implementation can increase a reference on the iterator in
1692 * dt_it_ops::get(). So the caller should be able to release
1693 * with dt_it_ops::put().
1695 * \param[in] env execution environment for this thread
1696 * \param[in] di iterator
1698 void (*put)(const struct lu_env *env,
1702 * Move to next record.
1704 * Moves the position of the iterator to a next record
1706 * \param[in] env execution environment for this thread
1707 * \param[in] di iterator
1709 * \retval 1 if no more records
1710 * \retval 0 on success, the next record is found
1711 * \retval negative negated errno on error
1713 int (*next)(const struct lu_env *env,
1719 * Returns a pointer to a buffer containing the key of the
1720 * record at the current position. The pointer is valid and
1721 * retains data until ->get(), ->load() and ->fini() methods
1724 * \param[in] env execution environment for this thread
1725 * \param[in] di iterator
1727 * \retval pointer to key on success
1728 * \retval ERR_PTR(errno) on error
1730 struct dt_key *(*key)(const struct lu_env *env,
1731 const struct dt_it *di);
1736 * Returns size of the key at the current position.
1738 * \param[in] env execution environment for this thread
1739 * \param[in] di iterator
1741 * \retval key's size on success
1742 * \retval negative negated errno on error
1744 int (*key_size)(const struct lu_env *env,
1745 const struct dt_it *di);
1750 * Stores the value of the record at the current position. The
1751 * buffer must be big enough (as negotiated with
1752 * ->do_index_try() or ->rec_size()). The caller can specify
1753 * she is interested only in part of the record, using attr
1754 * argument (see LUDA_* definitions for the details).
1756 * \param[in] env execution environment for this thread
1757 * \param[in] di iterator
1758 * \param[out] rec buffer to store value in
1759 * \param[in] attr specify part of the value to copy
1761 * \retval 0 on success
1762 * \retval negative negated errno on error
1764 int (*rec)(const struct lu_env *env,
1765 const struct dt_it *di,
1770 * Return record size.
1772 * Returns size of the record at the current position. The
1773 * \a attr can be used to specify only the parts of the record
1774 * needed to be returned. (see LUDA_* definitions for the
1777 * \param[in] env execution environment for this thread
1778 * \param[in] di iterator
1779 * \param[in] attr part of the record to return
1781 * \retval record's size on success
1782 * \retval negative negated errno on error
1784 int (*rec_size)(const struct lu_env *env,
1785 const struct dt_it *di,
1789 * Return a cookie (hash).
1791 * Returns the cookie (usually hash) of the key at the current
1792 * position. This allows the caller to resume iteration at this
1793 * position later. The exact value is specific to implementation
1794 * and should not be interpreted by the caller.
1796 * \param[in] env execution environment for this thread
1797 * \param[in] di iterator
1799 * \retval cookie/hash of the key
1801 __u64 (*store)(const struct lu_env *env,
1802 const struct dt_it *di);
1805 * Initialize position using cookie/hash.
1807 * Initializes the current position of the iterator to one
1808 * described by the cookie/hash as returned by ->store()
1811 * \param[in] env execution environment for this thread
1812 * \param[in] di iterator
1813 * \param[in] hash cookie/hash value
1815 * \retval positive if current position points to
1816 * record with least cookie not larger
1818 * \retval 0 if current position matches cookie
1819 * \retval negative negated errno on error
1821 int (*load)(const struct lu_env *env,
1822 const struct dt_it *di,
1828 int (*key_rec)(const struct lu_env *env,
1829 const struct dt_it *di,
1834 enum dt_otable_it_valid {
1835 DOIV_ERROR_HANDLE = 0x0001,
1836 DOIV_DRYRUN = 0x0002,
1839 enum dt_otable_it_flags {
1840 /* Exit when fail. */
1841 DOIF_FAILOUT = 0x0001,
1843 /* Reset iteration position to the device beginning. */
1844 DOIF_RESET = 0x0002,
1846 /* There is up layer component uses the iteration. */
1847 DOIF_OUTUSED = 0x0004,
1849 /* Check only without repairing. */
1850 DOIF_DRYRUN = 0x0008,
1853 /* otable based iteration needs to use the common DT iteration APIs.
1854 * To initialize the iteration, it needs call dio_it::init() firstly.
1855 * Here is how the otable based iteration should prepare arguments to
1856 * call dt_it_ops::init().
1858 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1859 * is composed of two parts:
1860 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1861 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1862 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1865 struct lu_device dd_lu_dev;
1866 const struct dt_device_operations *dd_ops;
1869 * List of dt_txn_callback (see below). This is not protected in any
1870 * way, because callbacks are supposed to be added/deleted only during
1871 * single-threaded start-up shut-down procedures.
1873 struct list_head dd_txn_callbacks;
1874 unsigned int dd_record_fid_accessed:1,
1877 /* sysfs and debugfs handling */
1878 struct dentry *dd_debugfs_entry;
1880 const struct attribute **dd_def_attrs;
1881 struct kobject dd_kobj;
1882 struct kobj_type dd_ktype;
1883 struct completion dd_kobj_unregister;
1886 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1887 void dt_device_fini(struct dt_device *dev);
1889 static inline int lu_device_is_dt(const struct lu_device *d)
1891 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1894 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1896 LASSERT(lu_device_is_dt(l));
1897 return container_of_safe(l, struct dt_device, dd_lu_dev);
1901 struct lu_object do_lu;
1902 const struct dt_object_operations *do_ops;
1903 const struct dt_body_operations *do_body_ops;
1904 const struct dt_index_operations *do_index_ops;
1908 * In-core representation of per-device local object OID storage
1910 struct local_oid_storage {
1911 /* all initialized llog systems on this node linked by this */
1912 struct list_head los_list;
1914 /* how many handle's reference this los has */
1915 atomic_t los_refcount;
1916 struct dt_device *los_dev;
1917 struct dt_object *los_obj;
1919 /* data used to generate new fids */
1920 struct mutex los_id_lock;
1925 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1927 return &d->dd_lu_dev;
1930 static inline struct dt_object *lu2dt(struct lu_object *l)
1932 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1933 return container_of_safe(l, struct dt_object, do_lu);
1936 int dt_object_init(struct dt_object *obj,
1937 struct lu_object_header *h, struct lu_device *d);
1939 void dt_object_fini(struct dt_object *obj);
1941 static inline int dt_object_exists(const struct dt_object *dt)
1943 return lu_object_exists(&dt->do_lu);
1946 static inline int dt_object_remote(const struct dt_object *dt)
1948 return lu_object_remote(&dt->do_lu);
1951 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1953 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1954 return container_of_safe(o, struct dt_object, do_lu);
1957 static inline struct dt_object *dt_object_child(struct dt_object *o)
1959 return container_of(lu_object_next(&(o)->do_lu),
1960 struct dt_object, do_lu);
1964 * This is the general purpose transaction handle.
1965 * 1. Transaction Life Cycle
1966 * This transaction handle is allocated upon starting a new transaction,
1967 * and deallocated after this transaction is committed.
1968 * 2. Transaction Nesting
1969 * We do _NOT_ support nested transaction. So, every thread should only
1970 * have one active transaction, and a transaction only belongs to one
1971 * thread. Due to this, transaction handle need no reference count.
1972 * 3. Transaction & dt_object locking
1973 * dt_object locks should be taken inside transaction.
1974 * 4. Transaction & RPC
1975 * No RPC request should be issued inside transaction.
1978 /** the dt device on which the transactions are executed */
1979 struct dt_device *th_dev;
1981 /* point to the top thandle, XXX this is a bit hacky right now,
1982 * but normal device trans callback triggered by the bottom
1983 * device (OSP/OSD == sub thandle layer) needs to get the
1984 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1985 * top thandle here for now, will fix it when we have better
1986 * callback mechanism */
1987 struct thandle *th_top;
1989 /** the last operation result in this transaction.
1990 * this value is used in recovery */
1993 /** whether we need sync commit */
1994 unsigned int th_sync:1,
1995 /* local transation, no need to inform other layers */
1997 /* Whether we need wait the transaction to be submitted
1998 * (send to remote target) */
2000 /* complex transaction which will track updates on all targets,
2003 /* whether ignore quota */
2005 /* whether restart transaction */
2010 * Transaction call-backs.
2012 * These are invoked by osd (or underlying transaction engine) when
2013 * transaction changes state.
2015 * Call-backs are used by upper layers to modify transaction parameters and to
2016 * perform some actions on for each transaction state transition. Typical
2017 * example is mdt registering call-back to write into last-received file
2018 * before each transaction commit.
2020 struct dt_txn_callback {
2021 int (*dtc_txn_start)(const struct lu_env *env,
2022 struct thandle *txn, void *cookie);
2023 int (*dtc_txn_stop)(const struct lu_env *env,
2024 struct thandle *txn, void *cookie);
2027 struct list_head dtc_linkage;
2030 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
2031 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
2033 int dt_txn_hook_start(const struct lu_env *env,
2034 struct dt_device *dev, struct thandle *txn);
2035 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
2037 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
2040 * Callback function used for parsing path.
2041 * \see llo_store_resolve
2043 typedef int (*dt_entry_func_t)(const struct lu_env *env,
2047 #define DT_MAX_PATH 1024
2049 int dt_path_parser(const struct lu_env *env,
2050 char *local, dt_entry_func_t entry_func,
2054 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
2055 const char *path, struct lu_fid *fid);
2057 struct dt_object *dt_store_open(const struct lu_env *env,
2058 struct dt_device *dt,
2059 const char *dirname,
2060 const char *filename,
2061 struct lu_fid *fid);
2063 struct dt_object *dt_find_or_create(const struct lu_env *env,
2064 struct dt_device *dt,
2065 const struct lu_fid *fid,
2066 struct dt_object_format *dof,
2067 struct lu_attr *attr);
2069 struct dt_object *dt_locate_at(const struct lu_env *env,
2070 struct dt_device *dev,
2071 const struct lu_fid *fid,
2072 struct lu_device *top_dev,
2073 const struct lu_object_conf *conf);
2075 static inline struct dt_object *
2076 dt_locate(const struct lu_env *env, struct dt_device *dev,
2077 const struct lu_fid *fid)
2079 return dt_locate_at(env, dev, fid,
2080 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2083 static inline struct dt_object *
2084 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2086 struct lu_object *lo;
2088 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2089 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2090 return container_of(lo, struct dt_object, do_lu);
2095 static inline void dt_object_put(const struct lu_env *env,
2096 struct dt_object *dto)
2098 lu_object_put(env, &dto->do_lu);
2101 static inline void dt_object_put_nocache(const struct lu_env *env,
2102 struct dt_object *dto)
2104 lu_object_put_nocache(env, &dto->do_lu);
2107 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2108 const struct lu_fid *first_fid,
2109 struct local_oid_storage **los);
2110 void local_oid_storage_fini(const struct lu_env *env,
2111 struct local_oid_storage *los);
2112 int local_object_fid_generate(const struct lu_env *env,
2113 struct local_oid_storage *los,
2114 struct lu_fid *fid);
2115 int local_object_declare_create(const struct lu_env *env,
2116 struct local_oid_storage *los,
2117 struct dt_object *o,
2118 struct lu_attr *attr,
2119 struct dt_object_format *dof,
2120 struct thandle *th);
2121 int local_object_create(const struct lu_env *env,
2122 struct local_oid_storage *los,
2123 struct dt_object *o,
2124 struct lu_attr *attr, struct dt_object_format *dof,
2125 struct thandle *th);
2126 struct dt_object *local_file_find(const struct lu_env *env,
2127 struct local_oid_storage *los,
2128 struct dt_object *parent,
2130 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2131 struct local_oid_storage *los,
2132 struct dt_object *parent,
2133 const char *name, __u32 mode);
2134 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2135 struct dt_device *dt,
2136 const struct lu_fid *fid,
2137 struct dt_object *parent,
2141 local_index_find_or_create(const struct lu_env *env,
2142 struct local_oid_storage *los,
2143 struct dt_object *parent,
2144 const char *name, __u32 mode,
2145 const struct dt_index_features *ft);
2147 local_index_find_or_create_with_fid(const struct lu_env *env,
2148 struct dt_device *dt,
2149 const struct lu_fid *fid,
2150 struct dt_object *parent,
2151 const char *name, __u32 mode,
2152 const struct dt_index_features *ft);
2153 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2154 struct dt_object *parent, const char *name);
2156 static inline int dt_object_lock(const struct lu_env *env,
2157 struct dt_object *o, struct lustre_handle *lh,
2158 struct ldlm_enqueue_info *einfo,
2159 union ldlm_policy_data *policy)
2162 LASSERT(o->do_ops != NULL);
2163 LASSERT(o->do_ops->do_object_lock != NULL);
2164 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2167 static inline int dt_object_unlock(const struct lu_env *env,
2168 struct dt_object *o,
2169 struct ldlm_enqueue_info *einfo,
2170 union ldlm_policy_data *policy)
2173 LASSERT(o->do_ops != NULL);
2174 LASSERT(o->do_ops->do_object_unlock != NULL);
2175 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2178 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2179 const char *name, struct lu_fid *fid);
2181 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2182 __u64 start, __u64 end)
2186 LASSERT(o->do_ops->do_object_sync);
2187 return o->do_ops->do_object_sync(env, o, start, end);
2190 static inline int dt_fid_alloc(const struct lu_env *env,
2191 struct dt_device *d,
2193 struct lu_object *parent,
2194 const struct lu_name *name)
2196 struct lu_device *l = dt2lu_dev(d);
2198 return l->ld_ops->ldo_fid_alloc(env, l, fid, parent, name);
2201 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2202 struct thandle *th);
2203 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2204 dt_obj_version_t version, struct thandle *th);
2205 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2208 int dt_read(const struct lu_env *env, struct dt_object *dt,
2209 struct lu_buf *buf, loff_t *pos);
2210 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2211 struct lu_buf *buf, loff_t *pos);
2212 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2213 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2214 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2215 union lu_page *lp, size_t nob,
2216 const struct dt_it_ops *iops,
2217 struct dt_it *it, __u32 attr, void *arg);
2218 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2219 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2221 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2222 struct idx_info *ii, const struct lu_rdpg *rdpg);
2224 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2225 struct dt_device *d)
2227 LASSERT(d->dd_ops->dt_trans_create);
2228 return d->dd_ops->dt_trans_create(env, d);
2231 static inline int dt_trans_start(const struct lu_env *env,
2232 struct dt_device *d, struct thandle *th)
2234 LASSERT(d->dd_ops->dt_trans_start);
2235 return d->dd_ops->dt_trans_start(env, d, th);
2238 /* for this transaction hooks shouldn't be called */
2239 static inline int dt_trans_start_local(const struct lu_env *env,
2240 struct dt_device *d, struct thandle *th)
2242 LASSERT(d->dd_ops->dt_trans_start);
2244 return d->dd_ops->dt_trans_start(env, d, th);
2247 static inline int dt_trans_stop(const struct lu_env *env,
2248 struct dt_device *d, struct thandle *th)
2250 LASSERT(d->dd_ops->dt_trans_stop);
2251 return d->dd_ops->dt_trans_stop(env, d, th);
2254 static inline int dt_trans_cb_add(struct thandle *th,
2255 struct dt_txn_commit_cb *dcb)
2257 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2258 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2259 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2264 static inline int dt_declare_record_write(const struct lu_env *env,
2265 struct dt_object *dt,
2266 const struct lu_buf *buf,
2272 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2273 LASSERT(th != NULL);
2274 LASSERTF(dt->do_body_ops, DFID" doesn't exit\n",
2275 PFID(lu_object_fid(&dt->do_lu)));
2276 LASSERT(dt->do_body_ops->dbo_declare_write);
2277 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2281 static inline int dt_declare_create(const struct lu_env *env,
2282 struct dt_object *dt,
2283 struct lu_attr *attr,
2284 struct dt_allocation_hint *hint,
2285 struct dt_object_format *dof,
2289 LASSERT(dt->do_ops);
2290 LASSERT(dt->do_ops->do_declare_create);
2292 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2293 return cfs_fail_err;
2295 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2298 static inline int dt_create(const struct lu_env *env,
2299 struct dt_object *dt,
2300 struct lu_attr *attr,
2301 struct dt_allocation_hint *hint,
2302 struct dt_object_format *dof,
2306 LASSERT(dt->do_ops);
2307 LASSERT(dt->do_ops->do_create);
2309 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2310 return cfs_fail_err;
2312 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2315 static inline int dt_declare_destroy(const struct lu_env *env,
2316 struct dt_object *dt,
2320 LASSERT(dt->do_ops);
2321 LASSERT(dt->do_ops->do_declare_destroy);
2323 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2324 return cfs_fail_err;
2326 return dt->do_ops->do_declare_destroy(env, dt, th);
2329 static inline int dt_destroy(const struct lu_env *env,
2330 struct dt_object *dt,
2334 LASSERT(dt->do_ops);
2335 LASSERT(dt->do_ops->do_destroy);
2337 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2338 return cfs_fail_err;
2340 return dt->do_ops->do_destroy(env, dt, th);
2343 static inline void dt_read_lock(const struct lu_env *env,
2344 struct dt_object *dt,
2348 LASSERT(dt->do_ops);
2349 LASSERT(dt->do_ops->do_read_lock);
2350 dt->do_ops->do_read_lock(env, dt, role);
2353 static inline void dt_write_lock(const struct lu_env *env,
2354 struct dt_object *dt,
2358 LASSERT(dt->do_ops);
2359 LASSERT(dt->do_ops->do_write_lock);
2360 dt->do_ops->do_write_lock(env, dt, role);
2363 static inline void dt_read_unlock(const struct lu_env *env,
2364 struct dt_object *dt)
2367 LASSERT(dt->do_ops);
2368 LASSERT(dt->do_ops->do_read_unlock);
2369 dt->do_ops->do_read_unlock(env, dt);
2372 static inline void dt_write_unlock(const struct lu_env *env,
2373 struct dt_object *dt)
2376 LASSERT(dt->do_ops);
2377 LASSERT(dt->do_ops->do_write_unlock);
2378 dt->do_ops->do_write_unlock(env, dt);
2381 static inline int dt_write_locked(const struct lu_env *env,
2382 struct dt_object *dt)
2385 LASSERT(dt->do_ops);
2386 LASSERT(dt->do_ops->do_write_locked);
2387 return dt->do_ops->do_write_locked(env, dt);
2390 static inline bool dt_object_stale(struct dt_object *dt)
2393 LASSERT(dt->do_ops);
2394 LASSERT(dt->do_ops->do_check_stale);
2396 return dt->do_ops->do_check_stale(dt);
2399 static inline int dt_declare_attr_get(const struct lu_env *env,
2400 struct dt_object *dt)
2403 LASSERT(dt->do_ops);
2404 LASSERT(dt->do_ops->do_declare_attr_get);
2406 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2407 return cfs_fail_err;
2409 return dt->do_ops->do_declare_attr_get(env, dt);
2412 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2416 LASSERT(dt->do_ops);
2417 LASSERT(dt->do_ops->do_attr_get);
2419 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2420 return cfs_fail_err;
2422 return dt->do_ops->do_attr_get(env, dt, la);
2425 static inline int dt_declare_attr_set(const struct lu_env *env,
2426 struct dt_object *dt,
2427 const struct lu_attr *la,
2431 LASSERT(dt->do_ops);
2432 LASSERT(dt->do_ops->do_declare_attr_set);
2434 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2435 return cfs_fail_err;
2437 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2440 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2441 const struct lu_attr *la, struct thandle *th)
2444 LASSERT(dt->do_ops);
2445 LASSERT(dt->do_ops->do_attr_set);
2447 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2448 return cfs_fail_err;
2450 return dt->do_ops->do_attr_set(env, dt, la, th);
2453 static inline int dt_declare_ref_add(const struct lu_env *env,
2454 struct dt_object *dt, struct thandle *th)
2457 LASSERT(dt->do_ops);
2458 LASSERT(dt->do_ops->do_declare_ref_add);
2460 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2461 return cfs_fail_err;
2463 return dt->do_ops->do_declare_ref_add(env, dt, th);
2466 static inline int dt_ref_add(const struct lu_env *env,
2467 struct dt_object *dt, struct thandle *th)
2470 LASSERT(dt->do_ops);
2471 LASSERT(dt->do_ops->do_ref_add);
2473 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2474 return cfs_fail_err;
2476 return dt->do_ops->do_ref_add(env, dt, th);
2479 static inline int dt_declare_ref_del(const struct lu_env *env,
2480 struct dt_object *dt, struct thandle *th)
2483 LASSERT(dt->do_ops);
2484 LASSERT(dt->do_ops->do_declare_ref_del);
2486 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2487 return cfs_fail_err;
2489 return dt->do_ops->do_declare_ref_del(env, dt, th);
2492 static inline int dt_ref_del(const struct lu_env *env,
2493 struct dt_object *dt, struct thandle *th)
2496 LASSERT(dt->do_ops);
2497 LASSERT(dt->do_ops->do_ref_del);
2499 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2500 return cfs_fail_err;
2502 return dt->do_ops->do_ref_del(env, dt, th);
2505 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2506 struct niobuf_remote *rnb,
2507 struct niobuf_local *lnb, int maxlnb,
2508 enum dt_bufs_type rw)
2511 LASSERT(d->do_body_ops);
2512 LASSERT(d->do_body_ops->dbo_bufs_get);
2513 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2514 rnb->rnb_len, lnb, maxlnb, rw);
2517 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2518 struct niobuf_local *lnb, int n)
2521 LASSERT(d->do_body_ops);
2522 LASSERT(d->do_body_ops->dbo_bufs_put);
2523 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2526 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2527 struct niobuf_local *lnb, int n)
2530 LASSERT(d->do_body_ops);
2531 LASSERT(d->do_body_ops->dbo_write_prep);
2532 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2535 static inline int dt_declare_write_commit(const struct lu_env *env,
2536 struct dt_object *d,
2537 struct niobuf_local *lnb,
2538 int n, struct thandle *th)
2540 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2541 LASSERT(th != NULL);
2542 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2546 static inline int dt_write_commit(const struct lu_env *env,
2547 struct dt_object *d, struct niobuf_local *lnb,
2548 int n, struct thandle *th, __u64 size)
2551 LASSERT(d->do_body_ops);
2552 LASSERT(d->do_body_ops->dbo_write_commit);
2553 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th, size);
2556 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2557 struct niobuf_local *lnb, int n)
2560 LASSERT(d->do_body_ops);
2561 LASSERT(d->do_body_ops->dbo_read_prep);
2562 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2565 static inline int dt_declare_write(const struct lu_env *env,
2566 struct dt_object *dt,
2567 const struct lu_buf *buf, loff_t pos,
2571 LASSERT(dt->do_body_ops);
2572 LASSERT(dt->do_body_ops->dbo_declare_write);
2573 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2576 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2577 const struct lu_buf *buf, loff_t *pos,
2581 LASSERT(dt->do_body_ops);
2582 LASSERT(dt->do_body_ops->dbo_write);
2583 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2586 static inline int dt_declare_punch(const struct lu_env *env,
2587 struct dt_object *dt, __u64 start,
2588 __u64 end, struct thandle *th)
2591 LASSERT(dt->do_body_ops);
2592 LASSERT(dt->do_body_ops->dbo_declare_punch);
2593 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2596 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2597 __u64 start, __u64 end, struct thandle *th)
2600 LASSERT(dt->do_body_ops);
2601 LASSERT(dt->do_body_ops->dbo_punch);
2602 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2605 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2606 __u64 start, __u64 end, int advice)
2609 LASSERT(dt->do_body_ops);
2610 LASSERT(dt->do_body_ops->dbo_ladvise);
2611 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2614 static inline int dt_declare_fallocate(const struct lu_env *env,
2615 struct dt_object *dt, __u64 start,
2616 __u64 end, int mode, struct thandle *th)
2619 if (!dt->do_body_ops)
2621 LASSERT(dt->do_body_ops);
2622 LASSERT(dt->do_body_ops->dbo_declare_fallocate);
2623 return dt->do_body_ops->dbo_declare_fallocate(env, dt, start, end,
2627 static inline int dt_falloc(const struct lu_env *env, struct dt_object *dt,
2628 __u64 start, __u64 end, int mode,
2632 if (!dt->do_body_ops)
2634 LASSERT(dt->do_body_ops);
2635 LASSERT(dt->do_body_ops->dbo_fallocate);
2636 return dt->do_body_ops->dbo_fallocate(env, dt, start, end, mode, th);
2639 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2643 if (d->do_body_ops == NULL)
2645 if (d->do_body_ops->dbo_fiemap_get == NULL)
2647 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2650 static inline loff_t dt_lseek(const struct lu_env *env, struct dt_object *d,
2651 loff_t offset, int whence)
2654 if (d->do_body_ops == NULL)
2656 if (d->do_body_ops->dbo_lseek == NULL)
2658 return d->do_body_ops->dbo_lseek(env, d, offset, whence);
2661 static inline int dt_statfs_info(const struct lu_env *env,
2662 struct dt_device *dev,
2663 struct obd_statfs *osfs,
2664 struct obd_statfs_info *info)
2667 LASSERT(dev->dd_ops);
2668 LASSERT(dev->dd_ops->dt_statfs);
2669 return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2672 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2673 struct obd_statfs *osfs)
2675 return dt_statfs_info(env, dev, osfs, NULL);
2678 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2682 LASSERT(dev->dd_ops);
2683 LASSERT(dev->dd_ops->dt_root_get);
2684 return dev->dd_ops->dt_root_get(env, dev, f);
2687 static inline void dt_conf_get(const struct lu_env *env,
2688 const struct dt_device *dev,
2689 struct dt_device_param *param)
2692 LASSERT(dev->dd_ops);
2693 LASSERT(dev->dd_ops->dt_conf_get);
2694 return dev->dd_ops->dt_conf_get(env, dev, param);
2697 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2700 LASSERT(dev->dd_ops);
2701 if (dev->dd_ops->dt_mnt_sb_get)
2702 return dev->dd_ops->dt_mnt_sb_get(dev);
2704 return ERR_PTR(-EOPNOTSUPP);
2707 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2710 LASSERT(dev->dd_ops);
2711 LASSERT(dev->dd_ops->dt_sync);
2712 return dev->dd_ops->dt_sync(env, dev);
2715 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2718 LASSERT(dev->dd_ops);
2719 LASSERT(dev->dd_ops->dt_ro);
2720 return dev->dd_ops->dt_ro(env, dev);
2723 static inline int dt_declare_insert(const struct lu_env *env,
2724 struct dt_object *dt,
2725 const struct dt_rec *rec,
2726 const struct dt_key *key,
2730 LASSERT(dt->do_index_ops);
2731 LASSERT(dt->do_index_ops->dio_declare_insert);
2733 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2734 return cfs_fail_err;
2736 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2739 static inline int dt_insert(const struct lu_env *env,
2740 struct dt_object *dt,
2741 const struct dt_rec *rec,
2742 const struct dt_key *key,
2746 LASSERT(dt->do_index_ops);
2747 LASSERT(dt->do_index_ops->dio_insert);
2749 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2750 return cfs_fail_err;
2752 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2755 static inline int dt_declare_xattr_del(const struct lu_env *env,
2756 struct dt_object *dt,
2761 LASSERT(dt->do_ops);
2762 LASSERT(dt->do_ops->do_declare_xattr_del);
2764 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2765 return cfs_fail_err;
2767 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2770 static inline int dt_xattr_del(const struct lu_env *env,
2771 struct dt_object *dt, const char *name,
2775 LASSERT(dt->do_ops);
2776 LASSERT(dt->do_ops->do_xattr_del);
2778 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2779 return cfs_fail_err;
2781 return dt->do_ops->do_xattr_del(env, dt, name, th);
2784 static inline int dt_declare_xattr_set(const struct lu_env *env,
2785 struct dt_object *dt,
2786 const struct lu_buf *buf,
2787 const char *name, int fl,
2791 LASSERT(dt->do_ops);
2792 LASSERT(dt->do_ops->do_declare_xattr_set);
2794 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2795 return cfs_fail_err;
2797 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2800 static inline int dt_xattr_set(const struct lu_env *env,
2801 struct dt_object *dt, const struct lu_buf *buf,
2802 const char *name, int fl, struct thandle *th)
2805 LASSERT(dt->do_ops);
2806 LASSERT(dt->do_ops->do_xattr_set);
2808 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2809 return cfs_fail_err;
2811 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2814 static inline int dt_declare_xattr_get(const struct lu_env *env,
2815 struct dt_object *dt,
2820 LASSERT(dt->do_ops);
2821 LASSERT(dt->do_ops->do_declare_xattr_get);
2823 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2824 return cfs_fail_err;
2826 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2829 static inline int dt_xattr_get(const struct lu_env *env,
2830 struct dt_object *dt, struct lu_buf *buf,
2834 LASSERT(dt->do_ops);
2835 LASSERT(dt->do_ops->do_xattr_get);
2837 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2838 return cfs_fail_err;
2840 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2843 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2844 const struct lu_buf *buf)
2847 LASSERT(dt->do_ops);
2848 LASSERT(dt->do_ops->do_xattr_list);
2850 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2851 return cfs_fail_err;
2853 return dt->do_ops->do_xattr_list(env, dt, buf);
2856 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2859 LASSERT(dt->do_ops);
2860 LASSERT(dt->do_ops->do_invalidate);
2862 return dt->do_ops->do_invalidate(env, dt);
2865 static inline int dt_declare_delete(const struct lu_env *env,
2866 struct dt_object *dt,
2867 const struct dt_key *key,
2871 LASSERT(dt->do_index_ops);
2872 LASSERT(dt->do_index_ops->dio_declare_delete);
2874 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2875 return cfs_fail_err;
2877 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2880 static inline int dt_delete(const struct lu_env *env,
2881 struct dt_object *dt,
2882 const struct dt_key *key,
2886 LASSERT(dt->do_index_ops);
2887 LASSERT(dt->do_index_ops->dio_delete);
2889 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2890 return cfs_fail_err;
2892 return dt->do_index_ops->dio_delete(env, dt, key, th);
2895 static inline int dt_commit_async(const struct lu_env *env,
2896 struct dt_device *dev)
2899 LASSERT(dev->dd_ops);
2900 LASSERT(dev->dd_ops->dt_commit_async);
2901 return dev->dd_ops->dt_commit_async(env, dev);
2904 static inline int dt_lookup(const struct lu_env *env,
2905 struct dt_object *dt,
2907 const struct dt_key *key)
2912 LASSERT(dt->do_index_ops);
2913 LASSERT(dt->do_index_ops->dio_lookup);
2915 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2916 return cfs_fail_err;
2918 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2926 static inline int dt_declare_layout_change(const struct lu_env *env,
2927 struct dt_object *o,
2928 struct md_layout_change *mlc,
2933 LASSERT(o->do_ops->do_declare_layout_change);
2934 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2937 static inline int dt_layout_change(const struct lu_env *env,
2938 struct dt_object *o,
2939 struct md_layout_change *mlc,
2944 LASSERT(o->do_ops->do_layout_change);
2945 return o->do_ops->do_layout_change(env, o, mlc, th);
2948 struct dt_find_hint {
2949 struct lu_fid *dfh_fid;
2950 struct dt_device *dfh_dt;
2951 struct dt_object *dfh_o;
2954 struct dt_insert_rec {
2956 const struct lu_fid *rec_fid;
2968 struct dt_thread_info {
2969 char dti_buf[DT_MAX_PATH];
2970 struct dt_find_hint dti_dfh;
2971 struct lu_attr dti_attr;
2972 struct lu_fid dti_fid;
2973 struct dt_object_format dti_dof;
2974 struct lustre_mdt_attrs dti_lma;
2975 struct lu_buf dti_lb;
2976 struct lu_object_conf dti_conf;
2978 struct dt_insert_rec dti_dt_rec;
2981 extern struct lu_context_key dt_key;
2983 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2985 struct dt_thread_info *dti;
2987 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2992 int dt_global_init(void);
2993 void dt_global_fini(void);
2994 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2995 const char *name, struct ldebugfs_vars *list);
2996 int dt_tunables_fini(struct dt_device *dt);
2998 # ifdef CONFIG_PROC_FS
2999 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
3000 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
3001 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
3002 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
3003 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
3004 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
3005 # endif /* CONFIG_PROC_FS */
3007 #endif /* __LUSTRE_DT_OBJECT_H */