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 * The unit of \a count is byte for block or inodes for metadata.
321 * If \a count > 0, reserve quota in advance of an operation that
322 * changes the quota assignment, such as chgrp() or rename() into
323 * a directory with a different group ID.
325 * If \a count < 0, free the reserved quota previously.
327 * \param[in] env execution environment for this thread
328 * \param[in] dev the bottom OSD device to reserve quota
329 * \param[in] type quota type (LQUOTA_RES_DT or LQUOTA_RES_MD)
330 * \param[in] uid quota uid
331 * \param[in] gid quota gid
332 * \param[in] count space (bytes or inodes) to reserve or free
333 * \param[in] md true for inode, false for block
335 * \retval 0 on success
336 * \retval negative negated errno on error
338 int (*dt_reserve_or_free_quota)(const struct lu_env *env,
339 struct dt_device *dev,
340 enum quota_type type, __u64 uid,
341 __u64 gid, __s64 count, bool md);
344 struct dt_index_features {
345 /** required feature flags from enum dt_index_flags */
347 /** minimal required key size */
348 size_t dif_keysize_min;
349 /** maximal required key size, 0 if no limit */
350 size_t dif_keysize_max;
351 /** minimal required record size */
352 size_t dif_recsize_min;
353 /** maximal required record size, 0 if no limit */
354 size_t dif_recsize_max;
355 /** pointer size for record */
359 enum dt_index_flags {
360 /** index supports variable sized keys */
361 DT_IND_VARKEY = BIT(0),
362 /** index supports variable sized records */
363 DT_IND_VARREC = BIT(1),
364 /** index can be modified */
365 DT_IND_UPDATE = BIT(2),
366 /** index supports records with non-unique (duplicate) keys */
367 DT_IND_NONUNQ = BIT(3),
369 * index support fixed-size keys sorted with natural numerical way
370 * and is able to return left-side value if no exact value found
372 DT_IND_RANGE = BIT(4),
375 /* for dt_read_lock() and dt_write_lock() object lock rule */
376 enum dt_object_role {
386 * Features, required from index to support file system directories (mapping
389 extern const struct dt_index_features dt_directory_features;
390 extern const struct dt_index_features dt_otable_features;
391 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
392 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
393 extern const struct dt_index_features dt_lfsck_namespace_features;
395 /* index features supported by the accounting objects */
396 extern const struct dt_index_features dt_acct_features;
398 /* index features supported by the quota global indexes */
399 extern const struct dt_index_features dt_quota_glb_features;
401 /* index features supported by the quota slave indexes */
402 extern const struct dt_index_features dt_quota_slv_features;
404 /* index features supported by the nodemap index */
405 extern const struct dt_index_features dt_nodemap_features;
408 * This is a general purpose dt allocation hint.
409 * It now contains the parent object.
410 * It can contain any allocation hint in the future.
412 struct dt_allocation_hint {
413 struct dt_object *dah_parent;
414 const void *dah_eadata;
415 const char *dah_append_pool;
417 int dah_append_stripe_count;
423 * object type specifier.
426 enum dt_format_type {
431 /** for special index */
433 /** for symbolic link */
438 * object format specifier.
440 struct dt_object_format {
441 /** type for dt object */
442 enum dt_format_type dof_type;
452 * special index need feature as parameter to create
456 const struct dt_index_features *di_feat;
461 enum dt_format_type dt_mode_to_dft(__u32 mode);
463 typedef __u64 dt_obj_version_t;
465 union ldlm_policy_data;
467 struct md_layout_change;
470 * A dt_object provides common operations to create and destroy
471 * objects and to manage regular and extended attributes.
473 struct dt_object_operations {
475 * Get read lock on object.
477 * Read lock is compatible with other read locks, so it's shared.
478 * Read lock is not compatible with write lock which is exclusive.
479 * The lock is blocking and can't be used from an interrupt context.
481 * \param[in] env execution environment for this thread
482 * \param[in] dt object to lock for reading
483 * \param[in] role a hint to debug locks (see kernel's mutexes)
485 void (*do_read_lock)(const struct lu_env *env,
486 struct dt_object *dt,
490 * Get write lock on object.
492 * Write lock is exclusive and cannot be shared. The lock is blocking
493 * and can't be used from an interrupt context.
495 * \param[in] env execution environment for this thread
496 * \param[in] dt object to lock for writing
497 * \param[in] role a hint to debug locks (see kernel's mutexes)
500 void (*do_write_lock)(const struct lu_env *env,
501 struct dt_object *dt,
507 * \param[in] env execution environment for this thread
508 * \param[in] dt object
510 void (*do_read_unlock)(const struct lu_env *env,
511 struct dt_object *dt);
514 * Release write lock.
516 * \param[in] env execution environment for this thread
517 * \param[in] dt object
519 void (*do_write_unlock)(const struct lu_env *env,
520 struct dt_object *dt);
523 * Check whether write lock is held.
525 * The caller can learn whether write lock is held on the object
527 * \param[in] env execution environment for this thread
528 * \param[in] dt object
530 * \retval 0 no write lock
531 * \retval 1 write lock is held
533 int (*do_write_locked)(const struct lu_env *env,
534 struct dt_object *dt);
537 * Declare intention to request reqular attributes.
539 * Notity the underlying filesystem that the caller may request regular
540 * attributes with ->do_attr_get() soon. This allows OSD to implement
541 * prefetching logic in an object-oriented manner. The implementation
542 * can be noop. This method should avoid expensive delays such as
543 * waiting on disk I/O, otherwise the goal of enabling a performance
544 * optimization would be defeated.
546 * \param[in] env execution environment for this thread
547 * \param[in] dt object
549 * \retval 0 on success
550 * \retval negative negated errno on error
552 int (*do_declare_attr_get)(const struct lu_env *env,
553 struct dt_object *dt);
556 * Return regular attributes.
558 * The object must exist. Currently all the attributes should be
559 * returned, but in the future this can be improved so that only
560 * a selected set is returned. This can improve performance as in
561 * some cases attributes are stored in different places and
562 * getting them all can be an iterative and expensive process.
564 * \param[in] env execution environment for this thread
565 * \param[in] dt object
566 * \param[out] attr attributes to fill
568 * \retval 0 on success
569 * \retval negative negated errno on error
571 int (*do_attr_get)(const struct lu_env *env,
572 struct dt_object *dt,
573 struct lu_attr *attr);
576 * Declare intention to change regular object's attributes.
578 * Notify the underlying filesystem that the regular attributes may
579 * change in this transaction. This enables the layer below to prepare
580 * resources (e.g. journal credits in ext4). This method should be
581 * called between creating the transaction and starting it. Note that
582 * the la_valid field of \a attr specifies which attributes will change.
583 * The object need not exist.
585 * \param[in] env execution environment for this thread
586 * \param[in] dt object
587 * \param[in] attr attributes to change specified in attr.la_valid
588 * \param[in] th transaction handle
590 * \retval 0 on success
591 * \retval negative negated errno on error
593 int (*do_declare_attr_set)(const struct lu_env *env,
594 struct dt_object *dt,
595 const struct lu_attr *attr,
599 * Change regular attributes.
601 * Change regular attributes in the given transaction. Note only
602 * attributes flagged by attr.la_valid change. The object must
603 * exist. If the layer implementing this method is responsible for
604 * quota, then the method should maintain object accounting for the
605 * given credentials when la_uid/la_gid changes.
607 * \param[in] env execution environment for this thread
608 * \param[in] dt object
609 * \param[in] attr new attributes to apply
610 * \param[in] th transaction handle
612 * \retval 0 on success
613 * \retval negative negated errno on error
615 int (*do_attr_set)(const struct lu_env *env,
616 struct dt_object *dt,
617 const struct lu_attr *attr,
621 * Declare intention to request extented attribute.
623 * Notify the underlying filesystem that the caller may request extended
624 * attribute with ->do_xattr_get() soon. This allows OSD to implement
625 * prefetching logic in an object-oriented manner. The implementation
626 * can be noop. This method should avoid expensive delays such as
627 * waiting on disk I/O, otherwise the goal of enabling a performance
628 * optimization would be defeated.
630 * \param[in] env execution environment for this thread
631 * \param[in] dt object
632 * \param[in] buf unused, may be removed in the future
633 * \param[in] name name of the extended attribute
635 * \retval 0 on success
636 * \retval negative negated errno on error
638 int (*do_declare_xattr_get)(const struct lu_env *env,
639 struct dt_object *dt,
644 * Return a value of an extended attribute.
646 * The object must exist. If the buffer is NULL, then the method
647 * must return the size of the value.
649 * \param[in] env execution environment for this thread
650 * \param[in] dt object
651 * \param[out] buf buffer in which to store the value
652 * \param[in] name name of the extended attribute
654 * \retval 0 on success
655 * \retval -ERANGE if \a buf is too small
656 * \retval negative negated errno on error
657 * \retval positive value's size if \a buf is NULL or has zero size
659 int (*do_xattr_get)(const struct lu_env *env,
660 struct dt_object *dt,
665 * Declare intention to change an extended attribute.
667 * Notify the underlying filesystem that the extended attribute may
668 * change in this transaction. This enables the layer below to prepare
669 * resources (e.g. journal credits in ext4). This method should be
670 * called between creating the transaction and starting it. The object
673 * \param[in] env execution environment for this thread
674 * \param[in] dt object
675 * \param[in] buf buffer storing new value of the attribute
676 * \param[in] name name of the attribute
677 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
678 * LU_XATTR_REPLACE - fail if EA doesn't exist
679 * \param[in] th transaction handle
681 * \retval 0 on success
682 * \retval negative negated errno on error
684 int (*do_declare_xattr_set)(const struct lu_env *env,
685 struct dt_object *dt,
686 const struct lu_buf *buf,
692 * Set an extended attribute.
694 * Change or replace the specified extended attribute (EA).
695 * The flags passed in \a fl dictate whether the EA is to be
696 * created or replaced, as follows.
697 * LU_XATTR_CREATE - fail if EA exists
698 * LU_XATTR_REPLACE - fail if EA doesn't exist
699 * The object must exist.
701 * \param[in] env execution environment for this thread
702 * \param[in] dt object
703 * \param[in] buf buffer storing new value of the attribute
704 * \param[in] name name of the attribute
705 * \param[in] fl flags indicating EA creation or replacement
706 * \param[in] th transaction handle
708 * \retval 0 on success
709 * \retval negative negated errno on error
711 int (*do_xattr_set)(const struct lu_env *env,
712 struct dt_object *dt,
713 const struct lu_buf *buf,
719 * Declare intention to delete an extended attribute.
721 * Notify the underlying filesystem that the extended attribute may
722 * be deleted in this transaction. This enables the layer below to
723 * prepare resources (e.g. journal credits in ext4). This method
724 * should be called between creating the transaction and starting it.
725 * The object need not exist.
727 * \param[in] env execution environment for this thread
728 * \param[in] dt object
729 * \param[in] name name of the attribute
730 * \param[in] th transaction handle
732 * \retval 0 on success
733 * \retval negative negated errno on error
735 int (*do_declare_xattr_del)(const struct lu_env *env,
736 struct dt_object *dt,
741 * Delete an extended attribute.
743 * This method deletes the specified extended attribute. The object
746 * \param[in] env execution environment for this thread
747 * \param[in] dt object
748 * \param[in] name name of the attribute
749 * \param[in] th transaction handle
751 * \retval 0 on success
752 * \retval negative negated errno on error
754 int (*do_xattr_del)(const struct lu_env *env,
755 struct dt_object *dt,
760 * Return a list of the extended attributes.
762 * Fills the passed buffer with a list of the extended attributes
763 * found in the object. The names are separated with '\0'.
764 * The object must exist.
766 * \param[in] env execution environment for this thread
767 * \param[in] dt object
768 * \param[out] buf buffer to put the list in
770 * \retval positive bytes used/required in the buffer
771 * \retval negative negated errno on error
773 int (*do_xattr_list)(const struct lu_env *env,
774 struct dt_object *dt,
775 const struct lu_buf *buf);
778 * Prepare allocation hint for a new object.
780 * This method is used by the caller to inform OSD of the parent-child
781 * relationship between two objects and enable efficient object
782 * allocation. Filled allocation hint will be passed to ->do_create()
785 * \param[in] env execution environment for this thread
786 * \param[out] ah allocation hint
787 * \param[in] parent parent object (can be NULL)
788 * \param[in] child child object
789 * \param[in] _mode type of the child object
791 void (*do_ah_init)(const struct lu_env *env,
792 struct dt_allocation_hint *ah,
793 struct dt_object *parent,
794 struct dt_object *child,
798 * Declare intention to create a new object.
800 * Notify the underlying filesystem that the object may be created
801 * in this transaction. This enables the layer below to prepare
802 * resources (e.g. journal credits in ext4). This method should be
803 * called between creating the transaction and starting it.
805 * If the layer implementing this method is responsible for quota,
806 * then the method should reserve an object for the given credentials
807 * and return an error if quota is over. If object creation later
808 * fails for some reason, then the reservation should be released
809 * properly (usually in ->dt_trans_stop()).
811 * \param[in] env execution environment for this thread
812 * \param[in] dt object
813 * \param[in] attr attributes of the new object
814 * \param[in] hint allocation hint
815 * \param[in] dof object format
816 * \param[in] th transaction handle
818 * \retval 0 on success
819 * \retval negative negated errno on error
821 int (*do_declare_create)(const struct lu_env *env,
822 struct dt_object *dt,
823 struct lu_attr *attr,
824 struct dt_allocation_hint *hint,
825 struct dt_object_format *dof,
831 * The method creates the object passed with the specified attributes
832 * and object format. Object allocation procedure can use information
833 * stored in the allocation hint. Different object formats are supported
834 * (see enum dt_format_type and struct dt_object_format) depending on
835 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
836 * in the LU-object header attributes.
838 * If the layer implementing this method is responsible for quota,
839 * then the method should maintain object accounting for the given
842 * \param[in] env execution environment for this thread
843 * \param[in] dt object
844 * \param[in] attr attributes of the new object
845 * \param[in] hint allocation hint
846 * \param[in] dof object format
847 * \param[in] th transaction handle
849 * \retval 0 on success
850 * \retval negative negated errno on error
852 int (*do_create)(const struct lu_env *env,
853 struct dt_object *dt,
854 struct lu_attr *attr,
855 struct dt_allocation_hint *hint,
856 struct dt_object_format *dof,
860 * Declare intention to destroy an object.
862 * Notify the underlying filesystem that the object may be destroyed
863 * in this transaction. This enables the layer below to prepare
864 * resources (e.g. journal credits in ext4). This method should be
865 * called between creating the transaction and starting it. The object
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_declare_destroy)(const struct lu_env *env,
876 struct dt_object *dt,
882 * This method destroys the object and all the resources associated
883 * with the object (data, key/value pairs, extended attributes, etc).
884 * The object must exist. If destroy is successful, then flag
885 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
886 * instance of in-core object. Any subsequent access to the same FID
887 * should get another instance with no LOHA_EXIST flag set.
889 * If the layer implementing this method is responsible for quota,
890 * then the method should maintain object accounting for the given
893 * \param[in] env execution environment for this thread
894 * \param[in] dt object
895 * \param[in] th transaction handle
897 * \retval 0 on success
898 * \retval negative negated errno on error
900 int (*do_destroy)(const struct lu_env *env,
901 struct dt_object *dt,
905 * Try object as an index.
907 * Announce that this object is going to be used as an index. This
908 * operation checks that object supports indexing operations and
909 * installs appropriate dt_index_operations vector on success.
910 * Also probes for features. Operation is successful if all required
911 * features are supported. It's not possible to access the object
912 * with index methods before ->do_index_try() returns success.
914 * \param[in] env execution environment for this thread
915 * \param[in] dt object
916 * \param[in] feat index features
918 * \retval 0 on success
919 * \retval negative negated errno on error
921 int (*do_index_try)(const struct lu_env *env,
922 struct dt_object *dt,
923 const struct dt_index_features *feat);
926 * Declare intention to increment nlink count.
928 * Notify the underlying filesystem that the nlink regular attribute
929 * be changed in this transaction. This enables the layer below to
930 * prepare resources (e.g. journal credits in ext4). This method
931 * should be called between creating the transaction and starting it.
932 * The object need not exist.
934 * \param[in] env execution environment for this thread
935 * \param[in] dt object
936 * \param[in] th transaction handle
938 * \retval 0 on success
939 * \retval negative negated errno on error
941 int (*do_declare_ref_add)(const struct lu_env *env,
942 struct dt_object *dt,
948 * Increment nlink (from the regular attributes set) in the given
949 * transaction. Note the absolute limit for nlink should be learnt
950 * from struct dt_device_param::ddp_max_nlink. The object must exist.
952 * \param[in] env execution environment for this thread
953 * \param[in] dt object
954 * \param[in] th transaction handle
956 * \retval 0 on success
957 * \retval negative negated errno on error
959 int (*do_ref_add)(const struct lu_env *env,
960 struct dt_object *dt, struct thandle *th);
963 * Declare intention to decrement nlink count.
965 * Notify the underlying filesystem that the nlink regular attribute
966 * be changed in this transaction. This enables the layer below to
967 * prepare resources (e.g. journal credits in ext4). This method
968 * should be called between creating the transaction and starting it.
969 * The object need not exist.
971 * \param[in] env execution environment for this thread
972 * \param[in] dt object
973 * \param[in] th transaction handle
975 * \retval 0 on success
976 * \retval negative negated errno on error
978 int (*do_declare_ref_del)(const struct lu_env *env,
979 struct dt_object *dt,
985 * Decrement nlink (from the regular attributes set) in the given
986 * transaction. The object must exist.
988 * \param[in] env execution environment for this thread
989 * \param[in] dt object
990 * \param[in] th transaction handle
992 * \retval 0 on success
993 * \retval negative negated errno on error
995 int (*do_ref_del)(const struct lu_env *env,
996 struct dt_object *dt,
1002 * The method is called to sync specified range of the object to a
1003 * persistent storage. The control is returned once the operation is
1004 * complete. The difference from ->do_sync() is that the object can
1005 * be in-sync with the persistent storage (nothing to flush), then
1006 * the method returns quickly with no I/O overhead. So, this method
1007 * should be preferred over ->do_sync() where possible. Also note that
1008 * if the object isn't clean, then some disk filesystems will call
1009 * ->do_sync() to maintain overall consistency, in which case it's
1010 * still very expensive.
1012 * \param[in] env execution environment for this thread
1013 * \param[in] dt object
1014 * \param[in] start start of the range to sync
1015 * \param[in] end end of the range to sync
1017 * \retval 0 on success
1018 * \retval negative negated errno on error
1020 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
1021 __u64 start, __u64 end);
1026 * Lock object(s) using Distributed Lock Manager (LDLM).
1028 * Get LDLM locks for the object. Currently used to lock "remote"
1029 * objects in DNE configuration - a service running on MDTx needs
1030 * to lock an object on MDTy.
1032 * \param[in] env execution environment for this thread
1033 * \param[in] dt object
1034 * \param[out] lh lock handle, sometimes used, sometimes not
1035 * \param[in] einfo ldlm callbacks, locking type and mode
1036 * \param[out] einfo private data to be passed to unlock later
1037 * \param[in] policy inodebits data
1039 * \retval 0 on success
1040 * \retval negative negated errno on error
1042 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1043 struct lustre_handle *lh,
1044 struct ldlm_enqueue_info *einfo,
1045 union ldlm_policy_data *policy);
1050 * Release LDLM lock(s) granted with ->do_object_lock().
1052 * \param[in] env execution environment for this thread
1053 * \param[in] dt object
1054 * \param[in] einfo lock handles, from ->do_object_lock()
1055 * \param[in] policy inodebits data
1057 * \retval 0 on success
1058 * \retval negative negated errno on error
1060 int (*do_object_unlock)(const struct lu_env *env,
1061 struct dt_object *dt,
1062 struct ldlm_enqueue_info *einfo,
1063 union ldlm_policy_data *policy);
1066 * Invalidate attribute cache.
1068 * This method invalidate attribute cache of the object, which is on OSP
1071 * \param[in] env execution envionment for this thread
1072 * \param[in] dt object
1074 * \retval 0 on success
1075 * \retval negative negated errno on error
1077 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1080 * Check object stale state.
1084 * \param[in] dt object
1086 * \retval true for stale object
1087 * \retval false for not stale object
1089 bool (*do_check_stale)(struct dt_object *dt);
1092 * Declare intention to instaintiate extended layout component.
1094 * \param[in] env execution environment
1095 * \param[in] dt DT object
1096 * \param[in] layout data structure to describe the changes to
1097 * the DT object's layout
1098 * \param[in] buf buffer containing client's lovea or empty
1101 * \retval -ne error code
1103 int (*do_declare_layout_change)(const struct lu_env *env,
1104 struct dt_object *dt,
1105 struct md_layout_change *mlc,
1106 struct thandle *th);
1109 * Client is trying to write to un-instantiated layout component.
1111 * \param[in] env execution environment
1112 * \param[in] dt DT object
1113 * \param[in] layout data structure to describe the changes to
1114 * the DT object's layout
1115 * \param[in] buf buffer containing client's lovea or empty
1118 * \retval -ne error code
1120 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1121 struct md_layout_change *mlc,
1122 struct thandle *th);
1126 DT_BUFS_TYPE_READ = 0x0000,
1127 DT_BUFS_TYPE_WRITE = 0x0001,
1128 DT_BUFS_TYPE_READAHEAD = 0x0002,
1129 DT_BUFS_TYPE_LOCAL = 0x0004,
1133 * Per-dt-object operations on "file body" - unstructure raw data.
1135 struct dt_body_operations {
1139 * Read unstructured data from an existing regular object.
1140 * Only data before attr.la_size is returned.
1142 * \param[in] env execution environment for this thread
1143 * \param[in] dt object
1144 * \param[out] buf buffer (including size) to copy data in
1145 * \param[in] pos position in the object to start
1146 * \param[out] pos original value of \a pos + bytes returned
1148 * \retval positive bytes read on success
1149 * \retval negative negated errno on error
1151 ssize_t (*dbo_read)(const struct lu_env *env,
1152 struct dt_object *dt,
1157 * Declare intention to write data to object.
1159 * Notify the underlying filesystem that data may be written in
1160 * this transaction. This enables the layer below to prepare resources
1161 * (e.g. journal credits in ext4). This method should be called
1162 * between creating the transaction and starting it. The object need
1163 * not exist. If the layer implementing this method is responsible for
1164 * quota, then the method should reserve space for the given credentials
1165 * and return an error if quota is over. If the write later fails
1166 * for some reason, then the reserve should be released properly
1167 * (usually in ->dt_trans_stop()).
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[in] th transaction handle
1175 * \retval 0 on success
1176 * \retval negative negated errno on error
1178 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1179 struct dt_object *dt,
1180 const struct lu_buf *buf,
1182 struct thandle *th);
1185 * Write unstructured data to regular existing object.
1187 * The method allocates space and puts data in. Also, the method should
1188 * maintain attr.la_size properly. Partial writes are possible.
1190 * If the layer implementing this method is responsible for quota,
1191 * then the method should maintain space accounting for the given
1194 * \param[in] env execution environment for this thread
1195 * \param[in] dt object
1196 * \param[in] buf buffer (including size) to copy data from
1197 * \param[in] pos position in the object to start
1198 * \param[out] pos \a pos + bytes written
1199 * \param[in] th transaction handle
1201 * \retval positive bytes written on success
1202 * \retval negative negated errno on error
1204 ssize_t (*dbo_write)(const struct lu_env *env,
1205 struct dt_object *dt,
1206 const struct lu_buf *buf,
1208 struct thandle *th);
1211 * Return buffers for data.
1213 * This method is used to access data with no copying. It's so-called
1214 * zero-copy I/O. The method returns the descriptors for the internal
1215 * buffers where data are managed by the disk filesystem. For example,
1216 * pagecache in case of ext4 or ARC with ZFS. Then other components
1217 * (e.g. networking) can transfer data from or to the buffers with no
1218 * additional copying.
1220 * The method should fill an array of struct niobuf_local, where
1221 * each element describes a full or partial page for data at specific
1222 * offset. The caller should use page/lnb_page_offset/len to find data
1223 * at object's offset lnb_file_offset.
1225 * The memory referenced by the descriptors can't change its purpose
1226 * until the complementary ->dbo_bufs_put() is called. The caller should
1227 * specify if the buffers are used to read or modify data so that OSD
1228 * can decide how to initialize the buffers: bring all the data for
1229 * reads or just bring partial buffers for write. Note: the method does
1230 * not check whether output array is large enough.
1232 * \param[in] env execution environment for this thread
1233 * \param[in] dt object
1234 * \param[in] pos position in the object to start
1235 * \param[in] len size of region in bytes
1236 * \param[out] lb array of descriptors to fill
1237 * \param[in] maxlnb max slots in @lnb array
1238 * \param[in] rw 0 if used to read, 1 if used for write
1240 * \retval positive number of descriptors on success
1241 * \retval negative negated errno on error
1243 int (*dbo_bufs_get)(const struct lu_env *env,
1244 struct dt_object *dt,
1247 struct niobuf_local *lb,
1249 enum dt_bufs_type rw);
1252 * Release reference granted by ->dbo_bufs_get().
1254 * Release the reference granted by the previous ->dbo_bufs_get().
1255 * Note the references are counted.
1257 * \param[in] env execution environment for this thread
1258 * \param[in] dt object
1259 * \param[out] lb array of descriptors to fill
1260 * \param[in] nr size of the array
1262 * \retval 0 on success
1263 * \retval negative negated errno on error
1265 int (*dbo_bufs_put)(const struct lu_env *env,
1266 struct dt_object *dt,
1267 struct niobuf_local *lb,
1271 * Prepare buffers for reading.
1273 * The method is called on the given buffers to fill them with data
1274 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1275 * caller should be able to get few buffers for discontiguous regions
1276 * using few calls to ->dbo_bufs_get() and then request them all for
1277 * the preparation with a single call, so that OSD can fire many I/Os
1278 * to run concurrently. It's up to the specific OSD whether to implement
1279 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1280 * prepare data for every requested region individually.
1282 * \param[in] env execution environment for this thread
1283 * \param[in] dt object
1284 * \param[in] lnb array of buffer descriptors
1285 * \param[in] nr size of the array
1287 * \retval 0 on success
1288 * \retval negative negated errno on error
1290 int (*dbo_read_prep)(const struct lu_env *env,
1291 struct dt_object *dt,
1292 struct niobuf_local *lnb,
1296 * Prepare buffers for write.
1298 * This method is called on the given buffers to ensure the partial
1299 * buffers contain correct data. The underlying idea is the same as
1300 * in ->db_read_prep().
1302 * \param[in] env execution environment for this thread
1303 * \param[in] dt object
1304 * \param[in] lb array of buffer descriptors
1305 * \param[in] nr size of the array
1307 * \retval 0 on success
1308 * \retval negative negated errno on error
1310 int (*dbo_write_prep)(const struct lu_env *env,
1311 struct dt_object *dt,
1312 struct niobuf_local *lb,
1316 * Declare intention to write data stored in the buffers.
1318 * Notify the underlying filesystem that data may be written in
1319 * this transaction. This enables the layer below to prepare resources
1320 * (e.g. journal credits in ext4). This method should be called
1321 * between creating the transaction and starting it.
1323 * If the layer implementing this method is responsible for quota,
1324 * then the method should be reserving a space for the given
1325 * credentials and return an error if quota is exceeded. If the write
1326 * later fails for some reason, then the reserve should be released
1327 * properly (usually in ->dt_trans_stop()).
1329 * \param[in] env execution environment for this thread
1330 * \param[in] dt object
1331 * \param[in] lb array of descriptors
1332 * \param[in] nr size of the array
1333 * \param[in] th transaction handle
1335 * \retval 0 on success
1336 * \retval negative negated errno on error
1338 int (*dbo_declare_write_commit)(const struct lu_env *env,
1339 struct dt_object *dt,
1340 struct niobuf_local *lb,
1342 struct thandle *th);
1345 * Write to existing object.
1347 * This method is used to write data to a persistent storage using
1348 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1349 * data into the buffers using own mechanisms (e.g. direct transfer
1350 * from a NIC). The method should maintain attr.la_size. Also,
1351 * attr.la_blocks should be maintained but this can be done in lazy
1352 * manner, when actual allocation happens.
1354 * If the layer implementing this method is responsible for quota,
1355 * then the method should maintain space accounting for the given
1358 * user_size parameter is the apparent size of the file, ie the size
1359 * of the clear text version of the file. It can differ from the actual
1360 * amount of valuable data received when a file is encrypted,
1361 * because encrypted pages always contain PAGE_SIZE bytes of data,
1362 * even if clear text data is only a few bytes.
1363 * In case of encrypted file, apparent size will be stored as the inode
1364 * size, so that servers return to clients an object size they can use
1365 * to determine clear text size.
1367 * \param[in] env execution environment for this thread
1368 * \param[in] dt object
1369 * \param[in] lb array of descriptors for the buffers
1370 * \param[in] nr size of the array
1371 * \param[in] th transaction handle
1372 * \param[in] user_size apparent size
1374 * \retval 0 on success
1375 * \retval negative negated errno on error
1377 int (*dbo_write_commit)(const struct lu_env *env,
1378 struct dt_object *dt,
1379 struct niobuf_local *lb,
1385 * Return logical to physical block mapping for a given extent
1387 * \param[in] env execution environment for this thread
1388 * \param[in] dt object
1389 * \param[in] fm describe the region to map and the output buffer
1390 * see the details in include/linux/fiemap.h
1392 * \retval 0 on success
1393 * \retval negative negated errno on error
1395 int (*dbo_fiemap_get)(const struct lu_env *env,
1396 struct dt_object *dt,
1400 * Declare intention to deallocate space from an object.
1402 * Notify the underlying filesystem that space may be deallocated in
1403 * this transactions. This enables the layer below to prepare resources
1404 * (e.g. journal credits in ext4). This method should be called between
1405 * creating the transaction and starting it. The object need not exist.
1407 * \param[in] env execution environment for this thread
1408 * \param[in] dt object
1409 * \param[in] start the start of the region to deallocate
1410 * \param[in] end the end of the region to deallocate
1411 * \param[in] th transaction handle
1413 * \retval 0 on success
1414 * \retval negative negated errno on error
1416 int (*dbo_declare_punch)(const struct lu_env *env,
1417 struct dt_object *dt,
1420 struct thandle *th);
1423 * Deallocate specified region in an object.
1425 * This method is used to deallocate (release) space possibly consumed
1426 * by the given region of the object. If the layer implementing this
1427 * method is responsible for quota, then the method should maintain
1428 * space accounting for the given credentials.
1430 * \param[in] env execution environment for this thread
1431 * \param[in] dt object
1432 * \param[in] start the start of the region to deallocate
1433 * \param[in] end the end of the region to deallocate
1434 * \param[in] th transaction handle
1436 * \retval 0 on success
1437 * \retval negative negated errno on error
1439 int (*dbo_punch)(const struct lu_env *env,
1440 struct dt_object *dt,
1443 struct thandle *th);
1445 * Give advices on specified region in an object.
1447 * This method is used to give advices about access pattern on an
1448 * given region of the object. The disk filesystem understands
1449 * the advices and tunes cache/read-ahead policies.
1451 * \param[in] env execution environment for this thread
1452 * \param[in] dt object
1453 * \param[in] start the start of the region affected
1454 * \param[in] end the end of the region affected
1455 * \param[in] advice advice type
1457 * \retval 0 on success
1458 * \retval negative negated errno on error
1460 int (*dbo_ladvise)(const struct lu_env *env,
1461 struct dt_object *dt,
1464 enum lu_ladvise_type advice);
1467 * Declare intention to preallocate space for an object
1469 * \param[in] env execution environment for this thread
1470 * \param[in] dt object
1471 * \param[in] th transaction handle
1473 * \retval 0 on success
1474 * \retval negative negated errno on error
1476 int (*dbo_declare_fallocate)(const struct lu_env *env,
1477 struct dt_object *dt, __u64 start,
1478 __u64 end, int mode, struct thandle *th);
1480 * Allocate specified region for an object
1482 * \param[in] env execution environment for this thread
1483 * \param[in] dt object
1484 * \param[in] start the start of the region to allocate
1485 * \param[in] end the end of the region to allocate
1486 * \param[in] mode fallocate mode
1487 * \param[in] th transaction handle
1489 * \retval 0 on success
1490 * \retval negative negated errno on error
1492 int (*dbo_fallocate)(const struct lu_env *env,
1493 struct dt_object *dt,
1497 struct thandle *th);
1499 * Do SEEK_HOLE/SEEK_DATA request on object
1501 * \param[in] env execution environment for this thread
1502 * \param[in] dt object
1503 * \param[in] offset the offset to start seek from
1504 * \param[in] whence seek mode, SEEK_HOLE or SEEK_DATA
1506 * \retval hole/data offset on success
1507 * \retval negative negated errno on error
1509 loff_t (*dbo_lseek)(const struct lu_env *env, struct dt_object *dt,
1510 loff_t offset, int whence);
1514 * Incomplete type of index record.
1519 * Incomplete type of index key.
1524 * Incomplete type of dt iterator.
1529 * Per-dt-object operations on object as index. Index is a set of key/value
1530 * pairs abstracted from an on-disk representation. An index supports the
1531 * number of operations including lookup by key, insert and delete. Also,
1532 * an index can be iterated to find the pairs one by one, from a beginning
1533 * or specified point.
1535 struct dt_index_operations {
1537 * Lookup in an index by key.
1539 * The method returns a value for the given key. Key/value format
1540 * and size should have been negotiated with ->do_index_try() before.
1541 * Thus it's the caller's responsibility to provide the method with
1542 * proper key and big enough buffer. No external locking is required,
1543 * all the internal consistency should be implemented by the method
1544 * or lower layers. The object should should have been created with
1545 * type DFT_INDEX or DFT_DIR.
1547 * \param[in] env execution environment for this thread
1548 * \param[in] dt object
1549 * \param[out] rec buffer where value will be stored
1550 * \param[in] key key
1552 * \retval 0 on success
1553 * \retval -ENOENT if key isn't found
1554 * \retval negative negated errno on error
1556 int (*dio_lookup)(const struct lu_env *env,
1557 struct dt_object *dt,
1559 const struct dt_key *key);
1562 * Declare intention to insert a key/value into an index.
1564 * Notify the underlying filesystem that new key/value may be inserted
1565 * in this transaction. This enables the layer below to prepare
1566 * resources (e.g. journal credits in ext4). This method should be
1567 * called between creating the transaction and starting it. key/value
1568 * format and size is subject to ->do_index_try().
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_declare_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 * Insert a new key/value pair into an index.
1588 * The method inserts specified key/value pair into the given index
1589 * object. The internal consistency is maintained by the method or
1590 * the functionality below. The format and size of key/value should
1591 * have been negotiated before using ->do_index_try(), no additional
1592 * information can be specified to the method. The keys are unique
1595 * \param[in] env execution environment for this thread
1596 * \param[in] dt object
1597 * \param[in] rec buffer storing value
1598 * \param[in] key key
1599 * \param[in] th transaction handle
1601 * \retval 0 on success
1602 * \retval negative negated errno on error
1604 int (*dio_insert)(const struct lu_env *env,
1605 struct dt_object *dt,
1606 const struct dt_rec *rec,
1607 const struct dt_key *key,
1608 struct thandle *th);
1611 * Declare intention to delete a key/value from an index.
1613 * Notify the underlying filesystem that key/value may be deleted in
1614 * this transaction. This enables the layer below to prepare resources
1615 * (e.g. journal credits in ext4). This method should be called
1616 * between creating the transaction and starting it. Key/value format
1617 * and size is subject to ->do_index_try(). The object need not exist.
1619 * \param[in] env execution environment for this thread
1620 * \param[in] dt object
1621 * \param[in] key key
1622 * \param[in] th transaction handle
1624 * \retval 0 on success
1625 * \retval negative negated errno on error
1627 int (*dio_declare_delete)(const struct lu_env *env,
1628 struct dt_object *dt,
1629 const struct dt_key *key,
1630 struct thandle *th);
1633 * Delete key/value pair from an index.
1635 * The method deletes specified key and corresponding value from the
1636 * given index object. The internal consistency is maintained by the
1637 * method or the functionality below. The format and size of the key
1638 * should have been negotiated before using ->do_index_try(), no
1639 * additional information can be specified to the method.
1641 * \param[in] env execution environment for this thread
1642 * \param[in] dt object
1643 * \param[in] key key
1644 * \param[in] th transaction handle
1646 * \retval 0 on success
1647 * \retval negative negated errno on error
1649 int (*dio_delete)(const struct lu_env *env,
1650 struct dt_object *dt,
1651 const struct dt_key *key,
1652 struct thandle *th);
1655 * Iterator interface.
1657 * Methods to iterate over an existing index, list the keys stored and
1658 * associated values, get key/value size, etc.
1662 * Allocate and initialize new iterator.
1664 * The iterator is a handler to be used in the subsequent
1665 * methods to access index's content. Note the position is
1666 * not defined at this point and should be initialized with
1667 * ->get() or ->load() method.
1669 * \param[in] env execution environment for this thread
1670 * \param[in] dt object
1671 * \param[in] attr ask the iterator to return part of
1672 the records, see LUDA_* for details
1674 * \retval pointer iterator pointer on success
1675 * \retval ERR_PTR(errno) on error
1677 struct dt_it *(*init)(const struct lu_env *env,
1678 struct dt_object *dt,
1684 * Release the specified iterator and all the resources
1685 * associated (e.g. the object, index cache, etc).
1687 * \param[in] env execution environment for this thread
1688 * \param[in] di iterator to release
1690 void (*fini)(const struct lu_env *env,
1694 * Move position of iterator.
1696 * Move the position of the specified iterator to the specified
1699 * \param[in] env execution environment for this thread
1700 * \param[in] di iterator
1701 * \param[in] key key to position to
1703 * \retval 0 if exact key is found
1704 * \retval 1 if at the record with least key
1705 * not larger than the key
1706 * \retval negative negated errno on error
1708 int (*get)(const struct lu_env *env,
1710 const struct dt_key *key);
1715 * Complimentary method for dt_it_ops::get() above. Some
1716 * implementation can increase a reference on the iterator in
1717 * dt_it_ops::get(). So the caller should be able to release
1718 * with dt_it_ops::put().
1720 * \param[in] env execution environment for this thread
1721 * \param[in] di iterator
1723 void (*put)(const struct lu_env *env,
1727 * Move to next record.
1729 * Moves the position of the iterator to a next record
1731 * \param[in] env execution environment for this thread
1732 * \param[in] di iterator
1734 * \retval 1 if no more records
1735 * \retval 0 on success, the next record is found
1736 * \retval negative negated errno on error
1738 int (*next)(const struct lu_env *env,
1744 * Returns a pointer to a buffer containing the key of the
1745 * record at the current position. The pointer is valid and
1746 * retains data until ->get(), ->load() and ->fini() methods
1749 * \param[in] env execution environment for this thread
1750 * \param[in] di iterator
1752 * \retval pointer to key on success
1753 * \retval ERR_PTR(errno) on error
1755 struct dt_key *(*key)(const struct lu_env *env,
1756 const struct dt_it *di);
1761 * Returns size of the key at the current position.
1763 * \param[in] env execution environment for this thread
1764 * \param[in] di iterator
1766 * \retval key's size on success
1767 * \retval negative negated errno on error
1769 int (*key_size)(const struct lu_env *env,
1770 const struct dt_it *di);
1775 * Stores the value of the record at the current position. The
1776 * buffer must be big enough (as negotiated with
1777 * ->do_index_try() or ->rec_size()). The caller can specify
1778 * she is interested only in part of the record, using attr
1779 * argument (see LUDA_* definitions for the details).
1781 * \param[in] env execution environment for this thread
1782 * \param[in] di iterator
1783 * \param[out] rec buffer to store value in
1784 * \param[in] attr specify part of the value to copy
1786 * \retval 0 on success
1787 * \retval negative negated errno on error
1789 int (*rec)(const struct lu_env *env,
1790 const struct dt_it *di,
1795 * Return record size.
1797 * Returns size of the record at the current position. The
1798 * \a attr can be used to specify only the parts of the record
1799 * needed to be returned. (see LUDA_* definitions for the
1802 * \param[in] env execution environment for this thread
1803 * \param[in] di iterator
1804 * \param[in] attr part of the record to return
1806 * \retval record's size on success
1807 * \retval negative negated errno on error
1809 int (*rec_size)(const struct lu_env *env,
1810 const struct dt_it *di,
1814 * Return a cookie (hash).
1816 * Returns the cookie (usually hash) of the key at the current
1817 * position. This allows the caller to resume iteration at this
1818 * position later. The exact value is specific to implementation
1819 * and should not be interpreted by the caller.
1821 * \param[in] env execution environment for this thread
1822 * \param[in] di iterator
1824 * \retval cookie/hash of the key
1826 __u64 (*store)(const struct lu_env *env,
1827 const struct dt_it *di);
1830 * Initialize position using cookie/hash.
1832 * Initializes the current position of the iterator to one
1833 * described by the cookie/hash as returned by ->store()
1836 * \param[in] env execution environment for this thread
1837 * \param[in] di iterator
1838 * \param[in] hash cookie/hash value
1840 * \retval positive if current position points to
1841 * record with least cookie not larger
1843 * \retval 0 if current position matches cookie
1844 * \retval negative negated errno on error
1846 int (*load)(const struct lu_env *env,
1847 const struct dt_it *di,
1853 int (*key_rec)(const struct lu_env *env,
1854 const struct dt_it *di,
1859 enum dt_otable_it_valid {
1860 DOIV_ERROR_HANDLE = 0x0001,
1861 DOIV_DRYRUN = 0x0002,
1864 enum dt_otable_it_flags {
1865 /* Exit when fail. */
1866 DOIF_FAILOUT = 0x0001,
1868 /* Reset iteration position to the device beginning. */
1869 DOIF_RESET = 0x0002,
1871 /* There is up layer component uses the iteration. */
1872 DOIF_OUTUSED = 0x0004,
1874 /* Check only without repairing. */
1875 DOIF_DRYRUN = 0x0008,
1878 /* otable based iteration needs to use the common DT iteration APIs.
1879 * To initialize the iteration, it needs call dio_it::init() firstly.
1880 * Here is how the otable based iteration should prepare arguments to
1881 * call dt_it_ops::init().
1883 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1884 * is composed of two parts:
1885 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1886 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1887 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1890 struct lu_device dd_lu_dev;
1891 const struct dt_device_operations *dd_ops;
1894 * List of dt_txn_callback (see below). This is not protected in any
1895 * way, because callbacks are supposed to be added/deleted only during
1896 * single-threaded start-up shut-down procedures.
1898 struct list_head dd_txn_callbacks;
1899 unsigned int dd_record_fid_accessed:1,
1902 /* sysfs and debugfs handling */
1903 struct dentry *dd_debugfs_entry;
1905 const struct attribute **dd_def_attrs;
1906 struct kobject dd_kobj;
1907 struct kobj_type dd_ktype;
1908 struct completion dd_kobj_unregister;
1911 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1912 void dt_device_fini(struct dt_device *dev);
1914 static inline int lu_device_is_dt(const struct lu_device *d)
1916 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1919 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1921 LASSERT(lu_device_is_dt(l));
1922 return container_of_safe(l, struct dt_device, dd_lu_dev);
1926 struct lu_object do_lu;
1927 const struct dt_object_operations *do_ops;
1928 const struct dt_body_operations *do_body_ops;
1929 const struct dt_index_operations *do_index_ops;
1933 * In-core representation of per-device local object OID storage
1935 struct local_oid_storage {
1936 /* all initialized llog systems on this node linked by this */
1937 struct list_head los_list;
1939 /* how many handle's reference this los has */
1940 atomic_t los_refcount;
1941 struct dt_device *los_dev;
1942 struct dt_object *los_obj;
1944 /* data used to generate new fids */
1945 struct mutex los_id_lock;
1950 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1952 return &d->dd_lu_dev;
1955 static inline struct dt_object *lu2dt(struct lu_object *l)
1957 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1958 return container_of_safe(l, struct dt_object, do_lu);
1961 int dt_object_init(struct dt_object *obj,
1962 struct lu_object_header *h, struct lu_device *d);
1964 void dt_object_fini(struct dt_object *obj);
1966 static inline int dt_object_exists(const struct dt_object *dt)
1968 return lu_object_exists(&dt->do_lu);
1971 static inline int dt_object_remote(const struct dt_object *dt)
1973 return lu_object_remote(&dt->do_lu);
1976 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1978 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1979 return container_of_safe(o, struct dt_object, do_lu);
1982 static inline struct dt_object *dt_object_child(struct dt_object *o)
1984 return container_of(lu_object_next(&(o)->do_lu),
1985 struct dt_object, do_lu);
1988 struct dt_quota_reserve_rec {
1989 enum quota_type qrr_type;
1990 union lquota_id qrr_id;
1995 * This is the general purpose transaction handle.
1996 * 1. Transaction Life Cycle
1997 * This transaction handle is allocated upon starting a new transaction,
1998 * and deallocated after this transaction is committed.
1999 * 2. Transaction Nesting
2000 * We do _NOT_ support nested transaction. So, every thread should only
2001 * have one active transaction, and a transaction only belongs to one
2002 * thread. Due to this, transaction handle need no reference count.
2003 * 3. Transaction & dt_object locking
2004 * dt_object locks should be taken inside transaction.
2005 * 4. Transaction & RPC
2006 * No RPC request should be issued inside transaction.
2009 /** the dt device on which the transactions are executed */
2010 struct dt_device *th_dev;
2012 /* point to the top thandle, XXX this is a bit hacky right now,
2013 * but normal device trans callback triggered by the bottom
2014 * device (OSP/OSD == sub thandle layer) needs to get the
2015 * top_thandle (see dt_txn_hook_start/stop()), so we put the
2016 * top thandle here for now, will fix it when we have better
2017 * callback mechanism */
2018 struct thandle *th_top;
2020 /* reserved quota for this handle */
2021 struct dt_quota_reserve_rec th_reserved_quota;
2023 /** the last operation result in this transaction.
2024 * this value is used in recovery */
2027 /** whether we need sync commit */
2028 unsigned int th_sync:1,
2029 /* local transation, no need to inform other layers */
2031 /* Whether we need wait the transaction to be submitted
2032 * (send to remote target) */
2034 /* complex transaction which will track updates on all targets,
2037 /* whether ignore quota */
2039 /* whether restart transaction */
2044 * Transaction call-backs.
2046 * These are invoked by osd (or underlying transaction engine) when
2047 * transaction changes state.
2049 * Call-backs are used by upper layers to modify transaction parameters and to
2050 * perform some actions on for each transaction state transition. Typical
2051 * example is mdt registering call-back to write into last-received file
2052 * before each transaction commit.
2054 struct dt_txn_callback {
2055 int (*dtc_txn_start)(const struct lu_env *env,
2056 struct thandle *txn, void *cookie);
2057 int (*dtc_txn_stop)(const struct lu_env *env,
2058 struct thandle *txn, void *cookie);
2061 struct list_head dtc_linkage;
2064 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
2065 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
2067 int dt_txn_hook_start(const struct lu_env *env,
2068 struct dt_device *dev, struct thandle *txn);
2069 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
2071 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
2074 * Callback function used for parsing path.
2075 * \see llo_store_resolve
2077 typedef int (*dt_entry_func_t)(const struct lu_env *env,
2081 #define DT_MAX_PATH 1024
2083 int dt_path_parser(const struct lu_env *env,
2084 char *local, dt_entry_func_t entry_func,
2088 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
2089 const char *path, struct lu_fid *fid);
2091 struct dt_object *dt_store_open(const struct lu_env *env,
2092 struct dt_device *dt,
2093 const char *dirname,
2094 const char *filename,
2095 struct lu_fid *fid);
2097 struct dt_object *dt_find_or_create(const struct lu_env *env,
2098 struct dt_device *dt,
2099 const struct lu_fid *fid,
2100 struct dt_object_format *dof,
2101 struct lu_attr *attr);
2103 struct dt_object *dt_locate_at(const struct lu_env *env,
2104 struct dt_device *dev,
2105 const struct lu_fid *fid,
2106 struct lu_device *top_dev,
2107 const struct lu_object_conf *conf);
2109 static inline struct dt_object *
2110 dt_locate(const struct lu_env *env, struct dt_device *dev,
2111 const struct lu_fid *fid)
2113 return dt_locate_at(env, dev, fid,
2114 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2117 static inline struct dt_object *
2118 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2120 struct lu_object *lo;
2122 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2123 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2124 return container_of(lo, struct dt_object, do_lu);
2129 static inline void dt_object_put(const struct lu_env *env,
2130 struct dt_object *dto)
2132 lu_object_put(env, &dto->do_lu);
2135 static inline void dt_object_put_nocache(const struct lu_env *env,
2136 struct dt_object *dto)
2138 lu_object_put_nocache(env, &dto->do_lu);
2141 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2142 const struct lu_fid *first_fid,
2143 struct local_oid_storage **los);
2144 void local_oid_storage_fini(const struct lu_env *env,
2145 struct local_oid_storage *los);
2146 int local_object_fid_generate(const struct lu_env *env,
2147 struct local_oid_storage *los,
2148 struct lu_fid *fid);
2149 int local_object_declare_create(const struct lu_env *env,
2150 struct local_oid_storage *los,
2151 struct dt_object *o,
2152 struct lu_attr *attr,
2153 struct dt_object_format *dof,
2154 struct thandle *th);
2155 int local_object_create(const struct lu_env *env,
2156 struct local_oid_storage *los,
2157 struct dt_object *o,
2158 struct lu_attr *attr, struct dt_object_format *dof,
2159 struct thandle *th);
2160 struct dt_object *local_file_find(const struct lu_env *env,
2161 struct local_oid_storage *los,
2162 struct dt_object *parent,
2164 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2165 struct local_oid_storage *los,
2166 struct dt_object *parent,
2167 const char *name, __u32 mode);
2168 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2169 struct dt_device *dt,
2170 const struct lu_fid *fid,
2171 struct dt_object *parent,
2175 local_index_find_or_create(const struct lu_env *env,
2176 struct local_oid_storage *los,
2177 struct dt_object *parent,
2178 const char *name, __u32 mode,
2179 const struct dt_index_features *ft);
2181 local_index_find_or_create_with_fid(const struct lu_env *env,
2182 struct dt_device *dt,
2183 const struct lu_fid *fid,
2184 struct dt_object *parent,
2185 const char *name, __u32 mode,
2186 const struct dt_index_features *ft);
2187 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2188 struct dt_object *parent, const char *name);
2190 static inline int dt_object_lock(const struct lu_env *env,
2191 struct dt_object *o, struct lustre_handle *lh,
2192 struct ldlm_enqueue_info *einfo,
2193 union ldlm_policy_data *policy)
2196 LASSERT(o->do_ops != NULL);
2197 LASSERT(o->do_ops->do_object_lock != NULL);
2198 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2201 static inline int dt_object_unlock(const struct lu_env *env,
2202 struct dt_object *o,
2203 struct ldlm_enqueue_info *einfo,
2204 union ldlm_policy_data *policy)
2207 LASSERT(o->do_ops != NULL);
2208 LASSERT(o->do_ops->do_object_unlock != NULL);
2209 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2212 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2213 const char *name, struct lu_fid *fid);
2215 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2216 __u64 start, __u64 end)
2220 LASSERT(o->do_ops->do_object_sync);
2221 return o->do_ops->do_object_sync(env, o, start, end);
2224 static inline int dt_fid_alloc(const struct lu_env *env,
2225 struct dt_device *d,
2227 struct lu_object *parent,
2228 const struct lu_name *name)
2230 struct lu_device *l = dt2lu_dev(d);
2232 return l->ld_ops->ldo_fid_alloc(env, l, fid, parent, name);
2235 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2236 struct thandle *th);
2237 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2238 dt_obj_version_t version, struct thandle *th);
2239 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2242 int dt_read(const struct lu_env *env, struct dt_object *dt,
2243 struct lu_buf *buf, loff_t *pos);
2244 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2245 struct lu_buf *buf, loff_t *pos);
2246 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2247 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2248 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2249 struct dt_object *obj, union lu_page *lp,
2250 size_t bytes, const struct dt_it_ops *iops,
2251 struct dt_it *it, __u32 attr, void *arg);
2252 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2253 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2255 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2256 struct idx_info *ii, const struct lu_rdpg *rdpg);
2258 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2259 struct dt_device *d)
2261 LASSERT(d->dd_ops->dt_trans_create);
2262 return d->dd_ops->dt_trans_create(env, d);
2265 static inline int dt_trans_start(const struct lu_env *env,
2266 struct dt_device *d, struct thandle *th)
2268 LASSERT(d->dd_ops->dt_trans_start);
2269 return d->dd_ops->dt_trans_start(env, d, th);
2272 /* for this transaction hooks shouldn't be called */
2273 static inline int dt_trans_start_local(const struct lu_env *env,
2274 struct dt_device *d, struct thandle *th)
2276 LASSERT(d->dd_ops->dt_trans_start);
2278 return d->dd_ops->dt_trans_start(env, d, th);
2281 static inline int dt_trans_stop(const struct lu_env *env,
2282 struct dt_device *d, struct thandle *th)
2284 LASSERT(d->dd_ops->dt_trans_stop);
2285 return d->dd_ops->dt_trans_stop(env, d, th);
2288 static inline int dt_trans_cb_add(struct thandle *th,
2289 struct dt_txn_commit_cb *dcb)
2291 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2292 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2293 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2298 static inline int dt_declare_record_write(const struct lu_env *env,
2299 struct dt_object *dt,
2300 const struct lu_buf *buf,
2306 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2307 LASSERT(th != NULL);
2308 LASSERTF(dt->do_body_ops, DFID" doesn't exit\n",
2309 PFID(lu_object_fid(&dt->do_lu)));
2310 LASSERT(dt->do_body_ops->dbo_declare_write);
2311 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2315 static inline int dt_declare_create(const struct lu_env *env,
2316 struct dt_object *dt,
2317 struct lu_attr *attr,
2318 struct dt_allocation_hint *hint,
2319 struct dt_object_format *dof,
2323 LASSERT(dt->do_ops);
2324 LASSERT(dt->do_ops->do_declare_create);
2326 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2327 return cfs_fail_err;
2329 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2332 static inline int dt_create(const struct lu_env *env,
2333 struct dt_object *dt,
2334 struct lu_attr *attr,
2335 struct dt_allocation_hint *hint,
2336 struct dt_object_format *dof,
2340 LASSERT(dt->do_ops);
2341 LASSERT(dt->do_ops->do_create);
2343 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2344 return cfs_fail_err;
2346 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2349 static inline int dt_declare_destroy(const struct lu_env *env,
2350 struct dt_object *dt,
2354 LASSERT(dt->do_ops);
2355 LASSERT(dt->do_ops->do_declare_destroy);
2357 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2358 return cfs_fail_err;
2360 return dt->do_ops->do_declare_destroy(env, dt, th);
2363 static inline int dt_destroy(const struct lu_env *env,
2364 struct dt_object *dt,
2368 LASSERT(dt->do_ops);
2369 LASSERT(dt->do_ops->do_destroy);
2371 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2372 return cfs_fail_err;
2374 return dt->do_ops->do_destroy(env, dt, th);
2377 static inline void dt_read_lock(const struct lu_env *env,
2378 struct dt_object *dt,
2382 LASSERT(dt->do_ops);
2383 LASSERT(dt->do_ops->do_read_lock);
2384 dt->do_ops->do_read_lock(env, dt, role);
2387 static inline void dt_write_lock(const struct lu_env *env,
2388 struct dt_object *dt,
2392 LASSERT(dt->do_ops);
2393 LASSERT(dt->do_ops->do_write_lock);
2394 dt->do_ops->do_write_lock(env, dt, role);
2397 static inline void dt_read_unlock(const struct lu_env *env,
2398 struct dt_object *dt)
2401 LASSERT(dt->do_ops);
2402 LASSERT(dt->do_ops->do_read_unlock);
2403 dt->do_ops->do_read_unlock(env, dt);
2406 static inline void dt_write_unlock(const struct lu_env *env,
2407 struct dt_object *dt)
2410 LASSERT(dt->do_ops);
2411 LASSERT(dt->do_ops->do_write_unlock);
2412 dt->do_ops->do_write_unlock(env, dt);
2415 static inline int dt_write_locked(const struct lu_env *env,
2416 struct dt_object *dt)
2419 LASSERT(dt->do_ops);
2420 LASSERT(dt->do_ops->do_write_locked);
2421 return dt->do_ops->do_write_locked(env, dt);
2424 static inline bool dt_object_stale(struct dt_object *dt)
2427 LASSERT(dt->do_ops);
2428 LASSERT(dt->do_ops->do_check_stale);
2430 return dt->do_ops->do_check_stale(dt);
2433 static inline int dt_declare_attr_get(const struct lu_env *env,
2434 struct dt_object *dt)
2437 LASSERT(dt->do_ops);
2438 LASSERT(dt->do_ops->do_declare_attr_get);
2440 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2441 return cfs_fail_err;
2443 return dt->do_ops->do_declare_attr_get(env, dt);
2446 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2450 LASSERT(dt->do_ops);
2451 LASSERT(dt->do_ops->do_attr_get);
2453 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2454 return cfs_fail_err;
2456 return dt->do_ops->do_attr_get(env, dt, la);
2459 static inline int dt_declare_attr_set(const struct lu_env *env,
2460 struct dt_object *dt,
2461 const struct lu_attr *la,
2465 LASSERT(dt->do_ops);
2466 LASSERT(dt->do_ops->do_declare_attr_set);
2468 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2469 return cfs_fail_err;
2471 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2474 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2475 const struct lu_attr *la, struct thandle *th)
2478 LASSERT(dt->do_ops);
2479 LASSERT(dt->do_ops->do_attr_set);
2481 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2482 return cfs_fail_err;
2484 return dt->do_ops->do_attr_set(env, dt, la, th);
2487 static inline int dt_declare_ref_add(const struct lu_env *env,
2488 struct dt_object *dt, struct thandle *th)
2491 LASSERT(dt->do_ops);
2492 LASSERT(dt->do_ops->do_declare_ref_add);
2494 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2495 return cfs_fail_err;
2497 return dt->do_ops->do_declare_ref_add(env, dt, th);
2500 static inline int dt_ref_add(const struct lu_env *env,
2501 struct dt_object *dt, struct thandle *th)
2504 LASSERT(dt->do_ops);
2505 LASSERT(dt->do_ops->do_ref_add);
2507 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2508 return cfs_fail_err;
2510 return dt->do_ops->do_ref_add(env, dt, th);
2513 static inline int dt_declare_ref_del(const struct lu_env *env,
2514 struct dt_object *dt, struct thandle *th)
2517 LASSERT(dt->do_ops);
2518 LASSERT(dt->do_ops->do_declare_ref_del);
2520 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2521 return cfs_fail_err;
2523 return dt->do_ops->do_declare_ref_del(env, dt, th);
2526 static inline int dt_ref_del(const struct lu_env *env,
2527 struct dt_object *dt, struct thandle *th)
2530 LASSERT(dt->do_ops);
2531 LASSERT(dt->do_ops->do_ref_del);
2533 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2534 return cfs_fail_err;
2536 return dt->do_ops->do_ref_del(env, dt, th);
2539 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2540 struct niobuf_remote *rnb,
2541 struct niobuf_local *lnb, int maxlnb,
2542 enum dt_bufs_type rw)
2545 LASSERT(d->do_body_ops);
2546 LASSERT(d->do_body_ops->dbo_bufs_get);
2547 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2548 rnb->rnb_len, lnb, maxlnb, rw);
2551 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2552 struct niobuf_local *lnb, int n)
2555 LASSERT(d->do_body_ops);
2556 LASSERT(d->do_body_ops->dbo_bufs_put);
2557 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2560 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2561 struct niobuf_local *lnb, int n)
2564 LASSERT(d->do_body_ops);
2565 LASSERT(d->do_body_ops->dbo_write_prep);
2566 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2569 static inline int dt_declare_write_commit(const struct lu_env *env,
2570 struct dt_object *d,
2571 struct niobuf_local *lnb,
2572 int n, struct thandle *th)
2574 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2575 LASSERT(th != NULL);
2576 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2580 static inline int dt_write_commit(const struct lu_env *env,
2581 struct dt_object *d, struct niobuf_local *lnb,
2582 int n, struct thandle *th, __u64 size)
2585 LASSERT(d->do_body_ops);
2586 LASSERT(d->do_body_ops->dbo_write_commit);
2587 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th, size);
2590 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2591 struct niobuf_local *lnb, int n)
2594 LASSERT(d->do_body_ops);
2595 LASSERT(d->do_body_ops->dbo_read_prep);
2596 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2599 static inline int dt_declare_write(const struct lu_env *env,
2600 struct dt_object *dt,
2601 const struct lu_buf *buf, loff_t pos,
2605 LASSERT(dt->do_body_ops);
2606 LASSERT(dt->do_body_ops->dbo_declare_write);
2607 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2610 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2611 const struct lu_buf *buf, loff_t *pos,
2615 LASSERT(dt->do_body_ops);
2616 LASSERT(dt->do_body_ops->dbo_write);
2617 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2620 static inline int dt_declare_punch(const struct lu_env *env,
2621 struct dt_object *dt, __u64 start,
2622 __u64 end, struct thandle *th)
2625 LASSERT(dt->do_body_ops);
2626 LASSERT(dt->do_body_ops->dbo_declare_punch);
2627 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2630 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2631 __u64 start, __u64 end, struct thandle *th)
2634 LASSERT(dt->do_body_ops);
2635 LASSERT(dt->do_body_ops->dbo_punch);
2636 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2639 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2640 __u64 start, __u64 end, int advice)
2643 LASSERT(dt->do_body_ops);
2644 LASSERT(dt->do_body_ops->dbo_ladvise);
2645 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2648 static inline int dt_declare_fallocate(const struct lu_env *env,
2649 struct dt_object *dt, __u64 start,
2650 __u64 end, int mode, struct thandle *th)
2653 if (!dt->do_body_ops)
2655 LASSERT(dt->do_body_ops);
2656 LASSERT(dt->do_body_ops->dbo_declare_fallocate);
2657 return dt->do_body_ops->dbo_declare_fallocate(env, dt, start, end,
2661 static inline int dt_falloc(const struct lu_env *env, struct dt_object *dt,
2662 __u64 start, __u64 end, int mode,
2666 if (!dt->do_body_ops)
2668 LASSERT(dt->do_body_ops);
2669 LASSERT(dt->do_body_ops->dbo_fallocate);
2670 return dt->do_body_ops->dbo_fallocate(env, dt, start, end, mode, th);
2673 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2677 if (d->do_body_ops == NULL)
2679 if (d->do_body_ops->dbo_fiemap_get == NULL)
2681 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2684 static inline loff_t dt_lseek(const struct lu_env *env, struct dt_object *d,
2685 loff_t offset, int whence)
2688 if (d->do_body_ops == NULL)
2690 if (d->do_body_ops->dbo_lseek == NULL)
2692 return d->do_body_ops->dbo_lseek(env, d, offset, whence);
2695 static inline int dt_statfs_info(const struct lu_env *env,
2696 struct dt_device *dev,
2697 struct obd_statfs *osfs,
2698 struct obd_statfs_info *info)
2701 LASSERT(dev->dd_ops);
2702 LASSERT(dev->dd_ops->dt_statfs);
2703 return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2706 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2707 struct obd_statfs *osfs)
2709 return dt_statfs_info(env, dev, osfs, NULL);
2712 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2716 LASSERT(dev->dd_ops);
2717 LASSERT(dev->dd_ops->dt_root_get);
2718 return dev->dd_ops->dt_root_get(env, dev, f);
2721 static inline void dt_conf_get(const struct lu_env *env,
2722 const struct dt_device *dev,
2723 struct dt_device_param *param)
2726 LASSERT(dev->dd_ops);
2727 LASSERT(dev->dd_ops->dt_conf_get);
2728 return dev->dd_ops->dt_conf_get(env, dev, param);
2731 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2734 LASSERT(dev->dd_ops);
2735 if (dev->dd_ops->dt_mnt_sb_get)
2736 return dev->dd_ops->dt_mnt_sb_get(dev);
2738 return ERR_PTR(-EOPNOTSUPP);
2741 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2744 LASSERT(dev->dd_ops);
2745 LASSERT(dev->dd_ops->dt_sync);
2746 return dev->dd_ops->dt_sync(env, dev);
2749 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2752 LASSERT(dev->dd_ops);
2753 LASSERT(dev->dd_ops->dt_ro);
2754 return dev->dd_ops->dt_ro(env, dev);
2757 static inline int dt_declare_insert(const struct lu_env *env,
2758 struct dt_object *dt,
2759 const struct dt_rec *rec,
2760 const struct dt_key *key,
2764 LASSERT(dt->do_index_ops);
2765 LASSERT(dt->do_index_ops->dio_declare_insert);
2767 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2768 return cfs_fail_err;
2770 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2773 static inline int dt_insert(const struct lu_env *env,
2774 struct dt_object *dt,
2775 const struct dt_rec *rec,
2776 const struct dt_key *key,
2780 LASSERT(dt->do_index_ops);
2781 LASSERT(dt->do_index_ops->dio_insert);
2783 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2784 return cfs_fail_err;
2786 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2789 static inline int dt_declare_xattr_del(const struct lu_env *env,
2790 struct dt_object *dt,
2795 LASSERT(dt->do_ops);
2796 LASSERT(dt->do_ops->do_declare_xattr_del);
2798 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2799 return cfs_fail_err;
2801 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2804 static inline int dt_xattr_del(const struct lu_env *env,
2805 struct dt_object *dt, const char *name,
2809 LASSERT(dt->do_ops);
2810 LASSERT(dt->do_ops->do_xattr_del);
2812 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2813 return cfs_fail_err;
2815 return dt->do_ops->do_xattr_del(env, dt, name, th);
2818 static inline int dt_declare_xattr_set(const struct lu_env *env,
2819 struct dt_object *dt,
2820 const struct lu_buf *buf,
2821 const char *name, int fl,
2825 LASSERT(dt->do_ops);
2826 LASSERT(dt->do_ops->do_declare_xattr_set);
2828 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2829 return cfs_fail_err;
2831 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2834 static inline int dt_xattr_set(const struct lu_env *env,
2835 struct dt_object *dt, const struct lu_buf *buf,
2836 const char *name, int fl, struct thandle *th)
2839 LASSERT(dt->do_ops);
2840 LASSERT(dt->do_ops->do_xattr_set);
2842 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2843 return cfs_fail_err;
2845 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2848 static inline int dt_declare_xattr_get(const struct lu_env *env,
2849 struct dt_object *dt,
2854 LASSERT(dt->do_ops);
2855 LASSERT(dt->do_ops->do_declare_xattr_get);
2857 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2858 return cfs_fail_err;
2860 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2863 static inline int dt_xattr_get(const struct lu_env *env,
2864 struct dt_object *dt, struct lu_buf *buf,
2868 LASSERT(dt->do_ops);
2869 LASSERT(dt->do_ops->do_xattr_get);
2871 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2872 return cfs_fail_err;
2874 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2877 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2878 const struct lu_buf *buf)
2881 LASSERT(dt->do_ops);
2882 LASSERT(dt->do_ops->do_xattr_list);
2884 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2885 return cfs_fail_err;
2887 return dt->do_ops->do_xattr_list(env, dt, buf);
2890 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2893 LASSERT(dt->do_ops);
2894 LASSERT(dt->do_ops->do_invalidate);
2896 return dt->do_ops->do_invalidate(env, dt);
2899 static inline int dt_declare_delete(const struct lu_env *env,
2900 struct dt_object *dt,
2901 const struct dt_key *key,
2905 LASSERT(dt->do_index_ops);
2906 LASSERT(dt->do_index_ops->dio_declare_delete);
2908 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2909 return cfs_fail_err;
2911 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2914 static inline int dt_delete(const struct lu_env *env,
2915 struct dt_object *dt,
2916 const struct dt_key *key,
2920 LASSERT(dt->do_index_ops);
2921 LASSERT(dt->do_index_ops->dio_delete);
2923 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2924 return cfs_fail_err;
2926 return dt->do_index_ops->dio_delete(env, dt, key, th);
2929 static inline int dt_commit_async(const struct lu_env *env,
2930 struct dt_device *dev)
2933 LASSERT(dev->dd_ops);
2934 LASSERT(dev->dd_ops->dt_commit_async);
2935 return dev->dd_ops->dt_commit_async(env, dev);
2938 static inline int dt_reserve_or_free_quota(const struct lu_env *env,
2939 struct dt_device *dev,
2940 enum quota_type type, __u64 uid,
2941 __u64 gid, int count, bool is_md)
2944 LASSERT(dev->dd_ops);
2945 LASSERT(dev->dd_ops->dt_reserve_or_free_quota);
2946 return dev->dd_ops->dt_reserve_or_free_quota(env, dev, type, uid, gid,
2950 static inline int dt_lookup(const struct lu_env *env,
2951 struct dt_object *dt,
2953 const struct dt_key *key)
2958 LASSERT(dt->do_index_ops);
2959 LASSERT(dt->do_index_ops->dio_lookup);
2961 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2962 return cfs_fail_err;
2964 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2972 static inline int dt_declare_layout_change(const struct lu_env *env,
2973 struct dt_object *o,
2974 struct md_layout_change *mlc,
2979 LASSERT(o->do_ops->do_declare_layout_change);
2980 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2983 static inline int dt_layout_change(const struct lu_env *env,
2984 struct dt_object *o,
2985 struct md_layout_change *mlc,
2990 LASSERT(o->do_ops->do_layout_change);
2991 return o->do_ops->do_layout_change(env, o, mlc, th);
2994 struct dt_find_hint {
2995 struct lu_fid *dfh_fid;
2996 struct dt_device *dfh_dt;
2997 struct dt_object *dfh_o;
3000 struct dt_insert_rec {
3002 const struct lu_fid *rec_fid;
3014 struct dt_thread_info {
3015 char dti_buf[DT_MAX_PATH];
3016 struct dt_find_hint dti_dfh;
3017 struct lu_attr dti_attr;
3018 struct lu_fid dti_fid;
3019 struct dt_object_format dti_dof;
3020 struct lustre_mdt_attrs dti_lma;
3021 struct lu_buf dti_lb;
3022 struct lu_object_conf dti_conf;
3024 struct dt_insert_rec dti_dt_rec;
3027 extern struct lu_context_key dt_key;
3029 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
3031 struct dt_thread_info *dti;
3033 dti = lu_context_key_get(&env->le_ctx, &dt_key);
3038 int dt_global_init(void);
3039 void dt_global_fini(void);
3040 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
3041 const char *name, struct ldebugfs_vars *list);
3042 int dt_tunables_fini(struct dt_device *dt);
3044 # ifdef CONFIG_PROC_FS
3045 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
3046 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
3047 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
3048 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
3049 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
3050 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
3051 # endif /* CONFIG_PROC_FS */
3053 #endif /* __LUSTRE_DT_OBJECT_H */