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>
52 #include <lustre_quota.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 * If \a qi->lqi_space > 0, reserve quota in advance of an operation
320 * that changes the quota assignment, such as chgrp() or rename() into
321 * a directory with a different group ID.
323 * If \a qi->lqi_space < 0, free the reserved quota previously.
325 * \param[in] env execution environment for this thread
326 * \param[in] dev the bottom OSD device to reserve quota
327 * \param[in] qi quota id & space required to reserve
329 * \retval 0 on success
330 * \retval negative negated errno on error
332 int (*dt_reserve_or_free_quota)(const struct lu_env *env,
333 struct dt_device *dev,
334 struct lquota_id_info *qi);
337 struct dt_index_features {
338 /** required feature flags from enum dt_index_flags */
340 /** minimal required key size */
341 size_t dif_keysize_min;
342 /** maximal required key size, 0 if no limit */
343 size_t dif_keysize_max;
344 /** minimal required record size */
345 size_t dif_recsize_min;
346 /** maximal required record size, 0 if no limit */
347 size_t dif_recsize_max;
348 /** pointer size for record */
352 enum dt_index_flags {
353 /** index supports variable sized keys */
354 DT_IND_VARKEY = BIT(0),
355 /** index supports variable sized records */
356 DT_IND_VARREC = BIT(1),
357 /** index can be modified */
358 DT_IND_UPDATE = BIT(2),
359 /** index supports records with non-unique (duplicate) keys */
360 DT_IND_NONUNQ = BIT(3),
362 * index support fixed-size keys sorted with natural numerical way
363 * and is able to return left-side value if no exact value found
365 DT_IND_RANGE = BIT(4),
368 /* for dt_read_lock() and dt_write_lock() object lock rule */
369 enum dt_object_role {
379 * Features, required from index to support file system directories (mapping
382 extern const struct dt_index_features dt_directory_features;
383 extern const struct dt_index_features dt_otable_features;
384 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
385 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
386 extern const struct dt_index_features dt_lfsck_namespace_features;
388 /* index features supported by the accounting objects */
389 extern const struct dt_index_features dt_acct_features;
391 /* index features supported by the quota global indexes */
392 extern const struct dt_index_features dt_quota_glb_features;
394 /* index features supported by the quota slave indexes */
395 extern const struct dt_index_features dt_quota_slv_features;
397 /* index features supported by the nodemap index */
398 extern const struct dt_index_features dt_nodemap_features;
401 * This is a general purpose dt allocation hint.
402 * It now contains the parent object.
403 * It can contain any allocation hint in the future.
405 struct dt_allocation_hint {
406 struct dt_object *dah_parent;
407 const void *dah_eadata;
408 const char *dah_append_pool;
410 int dah_append_stripe_count;
416 * object type specifier.
419 enum dt_format_type {
424 /** for special index */
426 /** for symbolic link */
431 * object format specifier.
433 struct dt_object_format {
434 /** type for dt object */
435 enum dt_format_type dof_type;
445 * special index need feature as parameter to create
449 const struct dt_index_features *di_feat;
454 enum dt_format_type dt_mode_to_dft(__u32 mode);
456 typedef __u64 dt_obj_version_t;
458 union ldlm_policy_data;
460 struct md_layout_change;
463 * A dt_object provides common operations to create and destroy
464 * objects and to manage regular and extended attributes.
466 struct dt_object_operations {
468 * Get read lock on object.
470 * Read lock is compatible with other read locks, so it's shared.
471 * Read lock is not compatible with write lock which is exclusive.
472 * The lock is blocking and can't be used from an interrupt context.
474 * \param[in] env execution environment for this thread
475 * \param[in] dt object to lock for reading
476 * \param[in] role a hint to debug locks (see kernel's mutexes)
478 void (*do_read_lock)(const struct lu_env *env,
479 struct dt_object *dt,
483 * Get write lock on object.
485 * Write lock is exclusive and cannot be shared. The lock is blocking
486 * and can't be used from an interrupt context.
488 * \param[in] env execution environment for this thread
489 * \param[in] dt object to lock for writing
490 * \param[in] role a hint to debug locks (see kernel's mutexes)
493 void (*do_write_lock)(const struct lu_env *env,
494 struct dt_object *dt,
500 * \param[in] env execution environment for this thread
501 * \param[in] dt object
503 void (*do_read_unlock)(const struct lu_env *env,
504 struct dt_object *dt);
507 * Release write lock.
509 * \param[in] env execution environment for this thread
510 * \param[in] dt object
512 void (*do_write_unlock)(const struct lu_env *env,
513 struct dt_object *dt);
516 * Check whether write lock is held.
518 * The caller can learn whether write lock is held on the object
520 * \param[in] env execution environment for this thread
521 * \param[in] dt object
523 * \retval 0 no write lock
524 * \retval 1 write lock is held
526 int (*do_write_locked)(const struct lu_env *env,
527 struct dt_object *dt);
530 * Declare intention to request reqular attributes.
532 * Notity the underlying filesystem that the caller may request regular
533 * attributes with ->do_attr_get() soon. This allows OSD to implement
534 * prefetching logic in an object-oriented manner. The implementation
535 * can be noop. This method should avoid expensive delays such as
536 * waiting on disk I/O, otherwise the goal of enabling a performance
537 * optimization would be defeated.
539 * \param[in] env execution environment for this thread
540 * \param[in] dt object
542 * \retval 0 on success
543 * \retval negative negated errno on error
545 int (*do_declare_attr_get)(const struct lu_env *env,
546 struct dt_object *dt);
549 * Return regular attributes.
551 * The object must exist. Currently all the attributes should be
552 * returned, but in the future this can be improved so that only
553 * a selected set is returned. This can improve performance as in
554 * some cases attributes are stored in different places and
555 * getting them all can be an iterative and expensive process.
557 * \param[in] env execution environment for this thread
558 * \param[in] dt object
559 * \param[out] attr attributes to fill
561 * \retval 0 on success
562 * \retval negative negated errno on error
564 int (*do_attr_get)(const struct lu_env *env,
565 struct dt_object *dt,
566 struct lu_attr *attr);
569 * Declare intention to change regular object's attributes.
571 * Notify the underlying filesystem that the regular attributes may
572 * change in this transaction. This enables the layer below to prepare
573 * resources (e.g. journal credits in ext4). This method should be
574 * called between creating the transaction and starting it. Note that
575 * the la_valid field of \a attr specifies which attributes will change.
576 * The object need not exist.
578 * \param[in] env execution environment for this thread
579 * \param[in] dt object
580 * \param[in] attr attributes to change specified in attr.la_valid
581 * \param[in] th transaction handle
583 * \retval 0 on success
584 * \retval negative negated errno on error
586 int (*do_declare_attr_set)(const struct lu_env *env,
587 struct dt_object *dt,
588 const struct lu_attr *attr,
592 * Change regular attributes.
594 * Change regular attributes in the given transaction. Note only
595 * attributes flagged by attr.la_valid change. The object must
596 * exist. If the layer implementing this method is responsible for
597 * quota, then the method should maintain object accounting for the
598 * given credentials when la_uid/la_gid changes.
600 * \param[in] env execution environment for this thread
601 * \param[in] dt object
602 * \param[in] attr new attributes to apply
603 * \param[in] th transaction handle
605 * \retval 0 on success
606 * \retval negative negated errno on error
608 int (*do_attr_set)(const struct lu_env *env,
609 struct dt_object *dt,
610 const struct lu_attr *attr,
614 * Declare intention to request extented attribute.
616 * Notify the underlying filesystem that the caller may request extended
617 * attribute with ->do_xattr_get() soon. This allows OSD to implement
618 * prefetching logic in an object-oriented manner. The implementation
619 * can be noop. This method should avoid expensive delays such as
620 * waiting on disk I/O, otherwise the goal of enabling a performance
621 * optimization would be defeated.
623 * \param[in] env execution environment for this thread
624 * \param[in] dt object
625 * \param[in] buf unused, may be removed in the future
626 * \param[in] name name of the extended attribute
628 * \retval 0 on success
629 * \retval negative negated errno on error
631 int (*do_declare_xattr_get)(const struct lu_env *env,
632 struct dt_object *dt,
637 * Return a value of an extended attribute.
639 * The object must exist. If the buffer is NULL, then the method
640 * must return the size of the value.
642 * \param[in] env execution environment for this thread
643 * \param[in] dt object
644 * \param[out] buf buffer in which to store the value
645 * \param[in] name name of the extended attribute
647 * \retval 0 on success
648 * \retval -ERANGE if \a buf is too small
649 * \retval negative negated errno on error
650 * \retval positive value's size if \a buf is NULL or has zero size
652 int (*do_xattr_get)(const struct lu_env *env,
653 struct dt_object *dt,
658 * Declare intention to change an extended attribute.
660 * Notify the underlying filesystem that the extended attribute may
661 * change in this transaction. This enables the layer below to prepare
662 * resources (e.g. journal credits in ext4). This method should be
663 * called between creating the transaction and starting it. The object
666 * \param[in] env execution environment for this thread
667 * \param[in] dt object
668 * \param[in] buf buffer storing new value of the attribute
669 * \param[in] name name of the attribute
670 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
671 * LU_XATTR_REPLACE - fail if EA doesn't exist
672 * \param[in] th transaction handle
674 * \retval 0 on success
675 * \retval negative negated errno on error
677 int (*do_declare_xattr_set)(const struct lu_env *env,
678 struct dt_object *dt,
679 const struct lu_buf *buf,
685 * Set an extended attribute.
687 * Change or replace the specified extended attribute (EA).
688 * The flags passed in \a fl dictate whether the EA is to be
689 * created or replaced, as follows.
690 * LU_XATTR_CREATE - fail if EA exists
691 * LU_XATTR_REPLACE - fail if EA doesn't exist
692 * The object must exist.
694 * \param[in] env execution environment for this thread
695 * \param[in] dt object
696 * \param[in] buf buffer storing new value of the attribute
697 * \param[in] name name of the attribute
698 * \param[in] fl flags indicating EA creation or replacement
699 * \param[in] th transaction handle
701 * \retval 0 on success
702 * \retval negative negated errno on error
704 int (*do_xattr_set)(const struct lu_env *env,
705 struct dt_object *dt,
706 const struct lu_buf *buf,
712 * Declare intention to delete an extended attribute.
714 * Notify the underlying filesystem that the extended attribute may
715 * be deleted in this transaction. This enables the layer below to
716 * prepare resources (e.g. journal credits in ext4). This method
717 * should be called between creating the transaction and starting it.
718 * The object need not exist.
720 * \param[in] env execution environment for this thread
721 * \param[in] dt object
722 * \param[in] name name of the attribute
723 * \param[in] th transaction handle
725 * \retval 0 on success
726 * \retval negative negated errno on error
728 int (*do_declare_xattr_del)(const struct lu_env *env,
729 struct dt_object *dt,
734 * Delete an extended attribute.
736 * This method deletes the specified extended attribute. The object
739 * \param[in] env execution environment for this thread
740 * \param[in] dt object
741 * \param[in] name name of the attribute
742 * \param[in] th transaction handle
744 * \retval 0 on success
745 * \retval negative negated errno on error
747 int (*do_xattr_del)(const struct lu_env *env,
748 struct dt_object *dt,
753 * Return a list of the extended attributes.
755 * Fills the passed buffer with a list of the extended attributes
756 * found in the object. The names are separated with '\0'.
757 * The object must exist.
759 * \param[in] env execution environment for this thread
760 * \param[in] dt object
761 * \param[out] buf buffer to put the list in
763 * \retval positive bytes used/required in the buffer
764 * \retval negative negated errno on error
766 int (*do_xattr_list)(const struct lu_env *env,
767 struct dt_object *dt,
768 const struct lu_buf *buf);
771 * Prepare allocation hint for a new object.
773 * This method is used by the caller to inform OSD of the parent-child
774 * relationship between two objects and enable efficient object
775 * allocation. Filled allocation hint will be passed to ->do_create()
778 * \param[in] env execution environment for this thread
779 * \param[out] ah allocation hint
780 * \param[in] parent parent object (can be NULL)
781 * \param[in] child child object
782 * \param[in] _mode type of the child object
784 void (*do_ah_init)(const struct lu_env *env,
785 struct dt_allocation_hint *ah,
786 struct dt_object *parent,
787 struct dt_object *child,
791 * Declare intention to create a new object.
793 * Notify the underlying filesystem that the object may be created
794 * in this transaction. This enables the layer below to prepare
795 * resources (e.g. journal credits in ext4). This method should be
796 * called between creating the transaction and starting it.
798 * If the layer implementing this method is responsible for quota,
799 * then the method should reserve an object for the given credentials
800 * and return an error if quota is over. If object creation later
801 * fails for some reason, then the reservation should be released
802 * properly (usually in ->dt_trans_stop()).
804 * \param[in] env execution environment for this thread
805 * \param[in] dt object
806 * \param[in] attr attributes of the new object
807 * \param[in] hint allocation hint
808 * \param[in] dof object format
809 * \param[in] th transaction handle
811 * \retval 0 on success
812 * \retval negative negated errno on error
814 int (*do_declare_create)(const struct lu_env *env,
815 struct dt_object *dt,
816 struct lu_attr *attr,
817 struct dt_allocation_hint *hint,
818 struct dt_object_format *dof,
824 * The method creates the object passed with the specified attributes
825 * and object format. Object allocation procedure can use information
826 * stored in the allocation hint. Different object formats are supported
827 * (see enum dt_format_type and struct dt_object_format) depending on
828 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
829 * in the LU-object header attributes.
831 * If the layer implementing this method is responsible for quota,
832 * then the method should maintain object accounting for the given
835 * \param[in] env execution environment for this thread
836 * \param[in] dt object
837 * \param[in] attr attributes of the new object
838 * \param[in] hint allocation hint
839 * \param[in] dof object format
840 * \param[in] th transaction handle
842 * \retval 0 on success
843 * \retval negative negated errno on error
845 int (*do_create)(const struct lu_env *env,
846 struct dt_object *dt,
847 struct lu_attr *attr,
848 struct dt_allocation_hint *hint,
849 struct dt_object_format *dof,
853 * Declare intention to destroy an object.
855 * Notify the underlying filesystem that the object may be destroyed
856 * in this transaction. This enables the layer below to prepare
857 * resources (e.g. journal credits in ext4). This method should be
858 * called between creating the transaction and starting it. The object
861 * \param[in] env execution environment for this thread
862 * \param[in] dt object
863 * \param[in] th transaction handle
865 * \retval 0 on success
866 * \retval negative negated errno on error
868 int (*do_declare_destroy)(const struct lu_env *env,
869 struct dt_object *dt,
875 * This method destroys the object and all the resources associated
876 * with the object (data, key/value pairs, extended attributes, etc).
877 * The object must exist. If destroy is successful, then flag
878 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
879 * instance of in-core object. Any subsequent access to the same FID
880 * should get another instance with no LOHA_EXIST flag set.
882 * If the layer implementing this method is responsible for quota,
883 * then the method should maintain object accounting for the given
886 * \param[in] env execution environment for this thread
887 * \param[in] dt object
888 * \param[in] th transaction handle
890 * \retval 0 on success
891 * \retval negative negated errno on error
893 int (*do_destroy)(const struct lu_env *env,
894 struct dt_object *dt,
898 * Try object as an index.
900 * Announce that this object is going to be used as an index. This
901 * operation checks that object supports indexing operations and
902 * installs appropriate dt_index_operations vector on success.
903 * Also probes for features. Operation is successful if all required
904 * features are supported. It's not possible to access the object
905 * with index methods before ->do_index_try() returns success.
907 * \param[in] env execution environment for this thread
908 * \param[in] dt object
909 * \param[in] feat index features
911 * \retval 0 on success
912 * \retval negative negated errno on error
914 int (*do_index_try)(const struct lu_env *env,
915 struct dt_object *dt,
916 const struct dt_index_features *feat);
919 * Declare intention to increment nlink count.
921 * Notify the underlying filesystem that the nlink regular attribute
922 * be changed in this transaction. This enables the layer below to
923 * prepare resources (e.g. journal credits in ext4). This method
924 * should be called between creating the transaction and starting it.
925 * The object need not 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_declare_ref_add)(const struct lu_env *env,
935 struct dt_object *dt,
941 * Increment nlink (from the regular attributes set) in the given
942 * transaction. Note the absolute limit for nlink should be learnt
943 * from struct dt_device_param::ddp_max_nlink. The object must exist.
945 * \param[in] env execution environment for this thread
946 * \param[in] dt object
947 * \param[in] th transaction handle
949 * \retval 0 on success
950 * \retval negative negated errno on error
952 int (*do_ref_add)(const struct lu_env *env,
953 struct dt_object *dt, struct thandle *th);
956 * Declare intention to decrement nlink count.
958 * Notify the underlying filesystem that the nlink regular attribute
959 * be changed in this transaction. This enables the layer below to
960 * prepare resources (e.g. journal credits in ext4). This method
961 * should be called between creating the transaction and starting it.
962 * The object need not exist.
964 * \param[in] env execution environment for this thread
965 * \param[in] dt object
966 * \param[in] th transaction handle
968 * \retval 0 on success
969 * \retval negative negated errno on error
971 int (*do_declare_ref_del)(const struct lu_env *env,
972 struct dt_object *dt,
978 * Decrement nlink (from the regular attributes set) in the given
979 * transaction. The object must exist.
981 * \param[in] env execution environment for this thread
982 * \param[in] dt object
983 * \param[in] th transaction handle
985 * \retval 0 on success
986 * \retval negative negated errno on error
988 int (*do_ref_del)(const struct lu_env *env,
989 struct dt_object *dt,
995 * The method is called to sync specified range of the object to a
996 * persistent storage. The control is returned once the operation is
997 * complete. The difference from ->do_sync() is that the object can
998 * be in-sync with the persistent storage (nothing to flush), then
999 * the method returns quickly with no I/O overhead. So, this method
1000 * should be preferred over ->do_sync() where possible. Also note that
1001 * if the object isn't clean, then some disk filesystems will call
1002 * ->do_sync() to maintain overall consistency, in which case it's
1003 * still very expensive.
1005 * \param[in] env execution environment for this thread
1006 * \param[in] dt object
1007 * \param[in] start start of the range to sync
1008 * \param[in] end end of the range to sync
1010 * \retval 0 on success
1011 * \retval negative negated errno on error
1013 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
1014 __u64 start, __u64 end);
1019 * Lock object(s) using Distributed Lock Manager (LDLM).
1021 * Get LDLM locks for the object. Currently used to lock "remote"
1022 * objects in DNE configuration - a service running on MDTx needs
1023 * to lock an object on MDTy.
1025 * \param[in] env execution environment for this thread
1026 * \param[in] dt object
1027 * \param[out] lh lock handle, sometimes used, sometimes not
1028 * \param[in] einfo ldlm callbacks, locking type and mode
1029 * \param[out] einfo private data to be passed to unlock later
1030 * \param[in] policy inodebits data
1032 * \retval 0 on success
1033 * \retval negative negated errno on error
1035 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1036 struct lustre_handle *lh,
1037 struct ldlm_enqueue_info *einfo,
1038 union ldlm_policy_data *policy);
1043 * Release LDLM lock(s) granted with ->do_object_lock().
1045 * \param[in] env execution environment for this thread
1046 * \param[in] dt object
1047 * \param[in] einfo lock handles, from ->do_object_lock()
1048 * \param[in] policy inodebits data
1050 * \retval 0 on success
1051 * \retval negative negated errno on error
1053 int (*do_object_unlock)(const struct lu_env *env,
1054 struct dt_object *dt,
1055 struct ldlm_enqueue_info *einfo,
1056 union ldlm_policy_data *policy);
1059 * Invalidate attribute cache.
1061 * This method invalidate attribute cache of the object, which is on OSP
1064 * \param[in] env execution envionment for this thread
1065 * \param[in] dt object
1067 * \retval 0 on success
1068 * \retval negative negated errno on error
1070 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1073 * Check object stale state.
1077 * \param[in] dt object
1079 * \retval true for stale object
1080 * \retval false for not stale object
1082 bool (*do_check_stale)(struct dt_object *dt);
1085 * Declare intention to instaintiate extended layout component.
1087 * \param[in] env execution environment
1088 * \param[in] dt DT object
1089 * \param[in] layout data structure to describe the changes to
1090 * the DT object's layout
1091 * \param[in] buf buffer containing client's lovea or empty
1094 * \retval -ne error code
1096 int (*do_declare_layout_change)(const struct lu_env *env,
1097 struct dt_object *dt,
1098 struct md_layout_change *mlc,
1099 struct thandle *th);
1102 * Client is trying to write to un-instantiated layout component.
1104 * \param[in] env execution environment
1105 * \param[in] dt DT object
1106 * \param[in] layout data structure to describe the changes to
1107 * the DT object's layout
1108 * \param[in] buf buffer containing client's lovea or empty
1111 * \retval -ne error code
1113 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1114 struct md_layout_change *mlc,
1115 struct thandle *th);
1119 DT_BUFS_TYPE_READ = 0x0000,
1120 DT_BUFS_TYPE_WRITE = 0x0001,
1121 DT_BUFS_TYPE_READAHEAD = 0x0002,
1122 DT_BUFS_TYPE_LOCAL = 0x0004,
1126 * Per-dt-object operations on "file body" - unstructure raw data.
1128 struct dt_body_operations {
1132 * Read unstructured data from an existing regular object.
1133 * Only data before attr.la_size is returned.
1135 * \param[in] env execution environment for this thread
1136 * \param[in] dt object
1137 * \param[out] buf buffer (including size) to copy data in
1138 * \param[in] pos position in the object to start
1139 * \param[out] pos original value of \a pos + bytes returned
1141 * \retval positive bytes read on success
1142 * \retval negative negated errno on error
1144 ssize_t (*dbo_read)(const struct lu_env *env,
1145 struct dt_object *dt,
1150 * Declare intention to write data to object.
1152 * Notify the underlying filesystem that data may be written in
1153 * this transaction. This enables the layer below to prepare resources
1154 * (e.g. journal credits in ext4). This method should be called
1155 * between creating the transaction and starting it. The object need
1156 * not exist. If the layer implementing this method is responsible for
1157 * quota, then the method should reserve space for the given credentials
1158 * and return an error if quota is over. If the write later fails
1159 * for some reason, then the reserve should be released properly
1160 * (usually in ->dt_trans_stop()).
1162 * \param[in] env execution environment for this thread
1163 * \param[in] dt object
1164 * \param[in] buf buffer (including size) to copy data from
1165 * \param[in] pos position in the object to start
1166 * \param[in] th transaction handle
1168 * \retval 0 on success
1169 * \retval negative negated errno on error
1171 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1172 struct dt_object *dt,
1173 const struct lu_buf *buf,
1175 struct thandle *th);
1178 * Write unstructured data to regular existing object.
1180 * The method allocates space and puts data in. Also, the method should
1181 * maintain attr.la_size properly. Partial writes are possible.
1183 * If the layer implementing this method is responsible for quota,
1184 * then the method should maintain space accounting for the given
1187 * \param[in] env execution environment for this thread
1188 * \param[in] dt object
1189 * \param[in] buf buffer (including size) to copy data from
1190 * \param[in] pos position in the object to start
1191 * \param[out] pos \a pos + bytes written
1192 * \param[in] th transaction handle
1194 * \retval positive bytes written on success
1195 * \retval negative negated errno on error
1197 ssize_t (*dbo_write)(const struct lu_env *env,
1198 struct dt_object *dt,
1199 const struct lu_buf *buf,
1201 struct thandle *th);
1204 * Return buffers for data.
1206 * This method is used to access data with no copying. It's so-called
1207 * zero-copy I/O. The method returns the descriptors for the internal
1208 * buffers where data are managed by the disk filesystem. For example,
1209 * pagecache in case of ext4 or ARC with ZFS. Then other components
1210 * (e.g. networking) can transfer data from or to the buffers with no
1211 * additional copying.
1213 * The method should fill an array of struct niobuf_local, where
1214 * each element describes a full or partial page for data at specific
1215 * offset. The caller should use page/lnb_page_offset/len to find data
1216 * at object's offset lnb_file_offset.
1218 * The memory referenced by the descriptors can't change its purpose
1219 * until the complementary ->dbo_bufs_put() is called. The caller should
1220 * specify if the buffers are used to read or modify data so that OSD
1221 * can decide how to initialize the buffers: bring all the data for
1222 * reads or just bring partial buffers for write. Note: the method does
1223 * not check whether output array is large enough.
1225 * \param[in] env execution environment for this thread
1226 * \param[in] dt object
1227 * \param[in] pos position in the object to start
1228 * \param[in] len size of region in bytes
1229 * \param[out] lb array of descriptors to fill
1230 * \param[in] maxlnb max slots in @lnb array
1231 * \param[in] rw 0 if used to read, 1 if used for write
1233 * \retval positive number of descriptors on success
1234 * \retval negative negated errno on error
1236 int (*dbo_bufs_get)(const struct lu_env *env,
1237 struct dt_object *dt,
1240 struct niobuf_local *lb,
1242 enum dt_bufs_type rw);
1245 * Release reference granted by ->dbo_bufs_get().
1247 * Release the reference granted by the previous ->dbo_bufs_get().
1248 * Note the references are counted.
1250 * \param[in] env execution environment for this thread
1251 * \param[in] dt object
1252 * \param[out] lb array of descriptors to fill
1253 * \param[in] nr size of the array
1255 * \retval 0 on success
1256 * \retval negative negated errno on error
1258 int (*dbo_bufs_put)(const struct lu_env *env,
1259 struct dt_object *dt,
1260 struct niobuf_local *lb,
1264 * Prepare buffers for reading.
1266 * The method is called on the given buffers to fill them with data
1267 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1268 * caller should be able to get few buffers for discontiguous regions
1269 * using few calls to ->dbo_bufs_get() and then request them all for
1270 * the preparation with a single call, so that OSD can fire many I/Os
1271 * to run concurrently. It's up to the specific OSD whether to implement
1272 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1273 * prepare data for every requested region individually.
1275 * \param[in] env execution environment for this thread
1276 * \param[in] dt object
1277 * \param[in] lnb array of buffer descriptors
1278 * \param[in] nr size of the array
1280 * \retval 0 on success
1281 * \retval negative negated errno on error
1283 int (*dbo_read_prep)(const struct lu_env *env,
1284 struct dt_object *dt,
1285 struct niobuf_local *lnb,
1289 * Prepare buffers for write.
1291 * This method is called on the given buffers to ensure the partial
1292 * buffers contain correct data. The underlying idea is the same as
1293 * in ->db_read_prep().
1295 * \param[in] env execution environment for this thread
1296 * \param[in] dt object
1297 * \param[in] lb array of buffer descriptors
1298 * \param[in] nr size of the array
1300 * \retval 0 on success
1301 * \retval negative negated errno on error
1303 int (*dbo_write_prep)(const struct lu_env *env,
1304 struct dt_object *dt,
1305 struct niobuf_local *lb,
1309 * Declare intention to write data stored in the buffers.
1311 * Notify the underlying filesystem that data may be written in
1312 * this transaction. This enables the layer below to prepare resources
1313 * (e.g. journal credits in ext4). This method should be called
1314 * between creating the transaction and starting it.
1316 * If the layer implementing this method is responsible for quota,
1317 * then the method should be reserving a space for the given
1318 * credentials and return an error if quota is exceeded. If the write
1319 * later fails for some reason, then the reserve should be released
1320 * properly (usually in ->dt_trans_stop()).
1322 * \param[in] env execution environment for this thread
1323 * \param[in] dt object
1324 * \param[in] lb array of descriptors
1325 * \param[in] nr size of the array
1326 * \param[in] th transaction handle
1328 * \retval 0 on success
1329 * \retval negative negated errno on error
1331 int (*dbo_declare_write_commit)(const struct lu_env *env,
1332 struct dt_object *dt,
1333 struct niobuf_local *lb,
1335 struct thandle *th);
1338 * Write to existing object.
1340 * This method is used to write data to a persistent storage using
1341 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1342 * data into the buffers using own mechanisms (e.g. direct transfer
1343 * from a NIC). The method should maintain attr.la_size. Also,
1344 * attr.la_blocks should be maintained but this can be done in lazy
1345 * manner, when actual allocation happens.
1347 * If the layer implementing this method is responsible for quota,
1348 * then the method should maintain space accounting for the given
1351 * user_size parameter is the apparent size of the file, ie the size
1352 * of the clear text version of the file. It can differ from the actual
1353 * amount of valuable data received when a file is encrypted,
1354 * because encrypted pages always contain PAGE_SIZE bytes of data,
1355 * even if clear text data is only a few bytes.
1356 * In case of encrypted file, apparent size will be stored as the inode
1357 * size, so that servers return to clients an object size they can use
1358 * to determine clear text size.
1360 * \param[in] env execution environment for this thread
1361 * \param[in] dt object
1362 * \param[in] lb array of descriptors for the buffers
1363 * \param[in] nr size of the array
1364 * \param[in] th transaction handle
1365 * \param[in] user_size apparent size
1367 * \retval 0 on success
1368 * \retval negative negated errno on error
1370 int (*dbo_write_commit)(const struct lu_env *env,
1371 struct dt_object *dt,
1372 struct niobuf_local *lb,
1378 * Return logical to physical block mapping for a given extent
1380 * \param[in] env execution environment for this thread
1381 * \param[in] dt object
1382 * \param[in] fm describe the region to map and the output buffer
1383 * see the details in include/linux/fiemap.h
1385 * \retval 0 on success
1386 * \retval negative negated errno on error
1388 int (*dbo_fiemap_get)(const struct lu_env *env,
1389 struct dt_object *dt,
1393 * Declare intention to deallocate space from an object.
1395 * Notify the underlying filesystem that space may be deallocated in
1396 * this transactions. This enables the layer below to prepare resources
1397 * (e.g. journal credits in ext4). This method should be called between
1398 * creating the transaction and starting it. The object need not exist.
1400 * \param[in] env execution environment for this thread
1401 * \param[in] dt object
1402 * \param[in] start the start of the region to deallocate
1403 * \param[in] end the end of the region to deallocate
1404 * \param[in] th transaction handle
1406 * \retval 0 on success
1407 * \retval negative negated errno on error
1409 int (*dbo_declare_punch)(const struct lu_env *env,
1410 struct dt_object *dt,
1413 struct thandle *th);
1416 * Deallocate specified region in an object.
1418 * This method is used to deallocate (release) space possibly consumed
1419 * by the given region of the object. If the layer implementing this
1420 * method is responsible for quota, then the method should maintain
1421 * space accounting for the given credentials.
1423 * \param[in] env execution environment for this thread
1424 * \param[in] dt object
1425 * \param[in] start the start of the region to deallocate
1426 * \param[in] end the end of the region to deallocate
1427 * \param[in] th transaction handle
1429 * \retval 0 on success
1430 * \retval negative negated errno on error
1432 int (*dbo_punch)(const struct lu_env *env,
1433 struct dt_object *dt,
1436 struct thandle *th);
1438 * Give advices on specified region in an object.
1440 * This method is used to give advices about access pattern on an
1441 * given region of the object. The disk filesystem understands
1442 * the advices and tunes cache/read-ahead policies.
1444 * \param[in] env execution environment for this thread
1445 * \param[in] dt object
1446 * \param[in] start the start of the region affected
1447 * \param[in] end the end of the region affected
1448 * \param[in] advice advice type
1450 * \retval 0 on success
1451 * \retval negative negated errno on error
1453 int (*dbo_ladvise)(const struct lu_env *env,
1454 struct dt_object *dt,
1457 enum lu_ladvise_type advice);
1460 * Declare intention to preallocate space for an object
1462 * \param[in] env execution environment for this thread
1463 * \param[in] dt object
1464 * \param[in] th transaction handle
1466 * \retval 0 on success
1467 * \retval negative negated errno on error
1469 int (*dbo_declare_fallocate)(const struct lu_env *env,
1470 struct dt_object *dt, __u64 start,
1471 __u64 end, int mode, struct thandle *th);
1473 * Allocate specified region for an object
1475 * \param[in] env execution environment for this thread
1476 * \param[in] dt object
1477 * \param[in] start the start of the region to allocate
1478 * \param[in] end the end of the region to allocate
1479 * \param[in] mode fallocate mode
1480 * \param[in] th transaction handle
1482 * \retval 0 on success
1483 * \retval negative negated errno on error
1485 int (*dbo_fallocate)(const struct lu_env *env,
1486 struct dt_object *dt,
1490 struct thandle *th);
1492 * Do SEEK_HOLE/SEEK_DATA request on object
1494 * \param[in] env execution environment for this thread
1495 * \param[in] dt object
1496 * \param[in] offset the offset to start seek from
1497 * \param[in] whence seek mode, SEEK_HOLE or SEEK_DATA
1499 * \retval hole/data offset on success
1500 * \retval negative negated errno on error
1502 loff_t (*dbo_lseek)(const struct lu_env *env, struct dt_object *dt,
1503 loff_t offset, int whence);
1507 * Incomplete type of index record.
1512 * Incomplete type of index key.
1517 * Incomplete type of dt iterator.
1522 * Per-dt-object operations on object as index. Index is a set of key/value
1523 * pairs abstracted from an on-disk representation. An index supports the
1524 * number of operations including lookup by key, insert and delete. Also,
1525 * an index can be iterated to find the pairs one by one, from a beginning
1526 * or specified point.
1528 struct dt_index_operations {
1530 * Lookup in an index by key.
1532 * The method returns a value for the given key. Key/value format
1533 * and size should have been negotiated with ->do_index_try() before.
1534 * Thus it's the caller's responsibility to provide the method with
1535 * proper key and big enough buffer. No external locking is required,
1536 * all the internal consistency should be implemented by the method
1537 * or lower layers. The object should should have been created with
1538 * type DFT_INDEX or DFT_DIR.
1540 * \param[in] env execution environment for this thread
1541 * \param[in] dt object
1542 * \param[out] rec buffer where value will be stored
1543 * \param[in] key key
1545 * \retval 0 on success
1546 * \retval -ENOENT if key isn't found
1547 * \retval negative negated errno on error
1549 int (*dio_lookup)(const struct lu_env *env,
1550 struct dt_object *dt,
1552 const struct dt_key *key);
1555 * Declare intention to insert a key/value into an index.
1557 * Notify the underlying filesystem that new key/value may be inserted
1558 * in this transaction. This enables the layer below to prepare
1559 * resources (e.g. journal credits in ext4). This method should be
1560 * called between creating the transaction and starting it. key/value
1561 * format and size is subject to ->do_index_try().
1563 * \param[in] env execution environment for this thread
1564 * \param[in] dt object
1565 * \param[in] rec buffer storing value
1566 * \param[in] key key
1567 * \param[in] th transaction handle
1569 * \retval 0 on success
1570 * \retval negative negated errno on error
1572 int (*dio_declare_insert)(const struct lu_env *env,
1573 struct dt_object *dt,
1574 const struct dt_rec *rec,
1575 const struct dt_key *key,
1576 struct thandle *th);
1579 * Insert a new key/value pair into an index.
1581 * The method inserts specified key/value pair into the given index
1582 * object. The internal consistency is maintained by the method or
1583 * the functionality below. The format and size of key/value should
1584 * have been negotiated before using ->do_index_try(), no additional
1585 * information can be specified to the method. The keys are unique
1588 * \param[in] env execution environment for this thread
1589 * \param[in] dt object
1590 * \param[in] rec buffer storing value
1591 * \param[in] key key
1592 * \param[in] th transaction handle
1594 * \retval 0 on success
1595 * \retval negative negated errno on error
1597 int (*dio_insert)(const struct lu_env *env,
1598 struct dt_object *dt,
1599 const struct dt_rec *rec,
1600 const struct dt_key *key,
1601 struct thandle *th);
1604 * Declare intention to delete a key/value from an index.
1606 * Notify the underlying filesystem that key/value may be deleted in
1607 * this transaction. This enables the layer below to prepare resources
1608 * (e.g. journal credits in ext4). This method should be called
1609 * between creating the transaction and starting it. Key/value format
1610 * and size is subject to ->do_index_try(). The object need not exist.
1612 * \param[in] env execution environment for this thread
1613 * \param[in] dt object
1614 * \param[in] key key
1615 * \param[in] th transaction handle
1617 * \retval 0 on success
1618 * \retval negative negated errno on error
1620 int (*dio_declare_delete)(const struct lu_env *env,
1621 struct dt_object *dt,
1622 const struct dt_key *key,
1623 struct thandle *th);
1626 * Delete key/value pair from an index.
1628 * The method deletes specified key and corresponding value from the
1629 * given index object. The internal consistency is maintained by the
1630 * method or the functionality below. The format and size of the key
1631 * should have been negotiated before using ->do_index_try(), no
1632 * additional information can be specified to the method.
1634 * \param[in] env execution environment for this thread
1635 * \param[in] dt object
1636 * \param[in] key key
1637 * \param[in] th transaction handle
1639 * \retval 0 on success
1640 * \retval negative negated errno on error
1642 int (*dio_delete)(const struct lu_env *env,
1643 struct dt_object *dt,
1644 const struct dt_key *key,
1645 struct thandle *th);
1648 * Iterator interface.
1650 * Methods to iterate over an existing index, list the keys stored and
1651 * associated values, get key/value size, etc.
1655 * Allocate and initialize new iterator.
1657 * The iterator is a handler to be used in the subsequent
1658 * methods to access index's content. Note the position is
1659 * not defined at this point and should be initialized with
1660 * ->get() or ->load() method.
1662 * \param[in] env execution environment for this thread
1663 * \param[in] dt object
1664 * \param[in] attr ask the iterator to return part of
1665 the records, see LUDA_* for details
1667 * \retval pointer iterator pointer on success
1668 * \retval ERR_PTR(errno) on error
1670 struct dt_it *(*init)(const struct lu_env *env,
1671 struct dt_object *dt,
1677 * Release the specified iterator and all the resources
1678 * associated (e.g. the object, index cache, etc).
1680 * \param[in] env execution environment for this thread
1681 * \param[in] di iterator to release
1683 void (*fini)(const struct lu_env *env,
1687 * Move position of iterator.
1689 * Move the position of the specified iterator to the specified
1692 * \param[in] env execution environment for this thread
1693 * \param[in] di iterator
1694 * \param[in] key key to position to
1696 * \retval 0 if exact key is found
1697 * \retval 1 if at the record with least key
1698 * not larger than the key
1699 * \retval negative negated errno on error
1701 int (*get)(const struct lu_env *env,
1703 const struct dt_key *key);
1708 * Complimentary method for dt_it_ops::get() above. Some
1709 * implementation can increase a reference on the iterator in
1710 * dt_it_ops::get(). So the caller should be able to release
1711 * with dt_it_ops::put().
1713 * \param[in] env execution environment for this thread
1714 * \param[in] di iterator
1716 void (*put)(const struct lu_env *env,
1720 * Move to next record.
1722 * Moves the position of the iterator to a next record
1724 * \param[in] env execution environment for this thread
1725 * \param[in] di iterator
1727 * \retval 1 if no more records
1728 * \retval 0 on success, the next record is found
1729 * \retval negative negated errno on error
1731 int (*next)(const struct lu_env *env,
1737 * Returns a pointer to a buffer containing the key of the
1738 * record at the current position. The pointer is valid and
1739 * retains data until ->get(), ->load() and ->fini() methods
1742 * \param[in] env execution environment for this thread
1743 * \param[in] di iterator
1745 * \retval pointer to key on success
1746 * \retval ERR_PTR(errno) on error
1748 struct dt_key *(*key)(const struct lu_env *env,
1749 const struct dt_it *di);
1754 * Returns size of the key at the current position.
1756 * \param[in] env execution environment for this thread
1757 * \param[in] di iterator
1759 * \retval key's size on success
1760 * \retval negative negated errno on error
1762 int (*key_size)(const struct lu_env *env,
1763 const struct dt_it *di);
1768 * Stores the value of the record at the current position. The
1769 * buffer must be big enough (as negotiated with
1770 * ->do_index_try() or ->rec_size()). The caller can specify
1771 * she is interested only in part of the record, using attr
1772 * argument (see LUDA_* definitions for the details).
1774 * \param[in] env execution environment for this thread
1775 * \param[in] di iterator
1776 * \param[out] rec buffer to store value in
1777 * \param[in] attr specify part of the value to copy
1779 * \retval 0 on success
1780 * \retval negative negated errno on error
1782 int (*rec)(const struct lu_env *env,
1783 const struct dt_it *di,
1788 * Return record size.
1790 * Returns size of the record at the current position. The
1791 * \a attr can be used to specify only the parts of the record
1792 * needed to be returned. (see LUDA_* definitions for the
1795 * \param[in] env execution environment for this thread
1796 * \param[in] di iterator
1797 * \param[in] attr part of the record to return
1799 * \retval record's size on success
1800 * \retval negative negated errno on error
1802 int (*rec_size)(const struct lu_env *env,
1803 const struct dt_it *di,
1807 * Return a cookie (hash).
1809 * Returns the cookie (usually hash) of the key at the current
1810 * position. This allows the caller to resume iteration at this
1811 * position later. The exact value is specific to implementation
1812 * and should not be interpreted by the caller.
1814 * \param[in] env execution environment for this thread
1815 * \param[in] di iterator
1817 * \retval cookie/hash of the key
1819 __u64 (*store)(const struct lu_env *env,
1820 const struct dt_it *di);
1823 * Initialize position using cookie/hash.
1825 * Initializes the current position of the iterator to one
1826 * described by the cookie/hash as returned by ->store()
1829 * \param[in] env execution environment for this thread
1830 * \param[in] di iterator
1831 * \param[in] hash cookie/hash value
1833 * \retval positive if current position points to
1834 * record with least cookie not larger
1836 * \retval 0 if current position matches cookie
1837 * \retval negative negated errno on error
1839 int (*load)(const struct lu_env *env,
1840 const struct dt_it *di,
1846 int (*key_rec)(const struct lu_env *env,
1847 const struct dt_it *di,
1852 enum dt_otable_it_valid {
1853 DOIV_ERROR_HANDLE = 0x0001,
1854 DOIV_DRYRUN = 0x0002,
1857 enum dt_otable_it_flags {
1858 /* Exit when fail. */
1859 DOIF_FAILOUT = 0x0001,
1861 /* Reset iteration position to the device beginning. */
1862 DOIF_RESET = 0x0002,
1864 /* There is up layer component uses the iteration. */
1865 DOIF_OUTUSED = 0x0004,
1867 /* Check only without repairing. */
1868 DOIF_DRYRUN = 0x0008,
1871 /* otable based iteration needs to use the common DT iteration APIs.
1872 * To initialize the iteration, it needs call dio_it::init() firstly.
1873 * Here is how the otable based iteration should prepare arguments to
1874 * call dt_it_ops::init().
1876 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1877 * is composed of two parts:
1878 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1879 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1880 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1883 struct lu_device dd_lu_dev;
1884 const struct dt_device_operations *dd_ops;
1887 * List of dt_txn_callback (see below). This is not protected in any
1888 * way, because callbacks are supposed to be added/deleted only during
1889 * single-threaded start-up shut-down procedures.
1891 struct list_head dd_txn_callbacks;
1892 unsigned int dd_record_fid_accessed:1,
1895 /* sysfs and debugfs handling */
1896 struct dentry *dd_debugfs_entry;
1898 const struct attribute **dd_def_attrs;
1899 struct kobject dd_kobj;
1900 struct kobj_type dd_ktype;
1901 struct completion dd_kobj_unregister;
1904 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1905 void dt_device_fini(struct dt_device *dev);
1907 static inline int lu_device_is_dt(const struct lu_device *d)
1909 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1912 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1914 LASSERT(lu_device_is_dt(l));
1915 return container_of_safe(l, struct dt_device, dd_lu_dev);
1919 struct lu_object do_lu;
1920 const struct dt_object_operations *do_ops;
1921 const struct dt_body_operations *do_body_ops;
1922 const struct dt_index_operations *do_index_ops;
1926 * In-core representation of per-device local object OID storage
1928 struct local_oid_storage {
1929 /* all initialized llog systems on this node linked by this */
1930 struct list_head los_list;
1932 /* how many handle's reference this los has */
1933 atomic_t los_refcount;
1934 struct dt_device *los_dev;
1935 struct dt_object *los_obj;
1937 /* data used to generate new fids */
1938 struct mutex los_id_lock;
1943 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1945 return &d->dd_lu_dev;
1948 static inline struct dt_object *lu2dt(struct lu_object *l)
1950 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1951 return container_of_safe(l, struct dt_object, do_lu);
1954 int dt_object_init(struct dt_object *obj,
1955 struct lu_object_header *h, struct lu_device *d);
1957 void dt_object_fini(struct dt_object *obj);
1959 static inline int dt_object_exists(const struct dt_object *dt)
1961 return lu_object_exists(&dt->do_lu);
1964 static inline int dt_object_remote(const struct dt_object *dt)
1966 return lu_object_remote(&dt->do_lu);
1969 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1971 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1972 return container_of_safe(o, struct dt_object, do_lu);
1975 static inline struct dt_object *dt_object_child(struct dt_object *o)
1977 return container_of(lu_object_next(&(o)->do_lu),
1978 struct dt_object, do_lu);
1982 * This is the general purpose transaction handle.
1983 * 1. Transaction Life Cycle
1984 * This transaction handle is allocated upon starting a new transaction,
1985 * and deallocated after this transaction is committed.
1986 * 2. Transaction Nesting
1987 * We do _NOT_ support nested transaction. So, every thread should only
1988 * have one active transaction, and a transaction only belongs to one
1989 * thread. Due to this, transaction handle need no reference count.
1990 * 3. Transaction & dt_object locking
1991 * dt_object locks should be taken inside transaction.
1992 * 4. Transaction & RPC
1993 * No RPC request should be issued inside transaction.
1996 /** the dt device on which the transactions are executed */
1997 struct dt_device *th_dev;
1999 /* point to the top thandle, XXX this is a bit hacky right now,
2000 * but normal device trans callback triggered by the bottom
2001 * device (OSP/OSD == sub thandle layer) needs to get the
2002 * top_thandle (see dt_txn_hook_start/stop()), so we put the
2003 * top thandle here for now, will fix it when we have better
2004 * callback mechanism */
2005 struct thandle *th_top;
2007 /* reserved quota for this handle */
2008 struct lquota_id_info th_reserved_quota;
2010 /** the last operation result in this transaction.
2011 * this value is used in recovery */
2014 /** whether we need sync commit */
2015 unsigned int th_sync:1,
2016 /* local transation, no need to inform other layers */
2018 /* Whether we need wait the transaction to be submitted
2019 * (send to remote target) */
2021 /* complex transaction which will track updates on all targets,
2024 /* whether ignore quota */
2026 /* whether restart transaction */
2031 * Transaction call-backs.
2033 * These are invoked by osd (or underlying transaction engine) when
2034 * transaction changes state.
2036 * Call-backs are used by upper layers to modify transaction parameters and to
2037 * perform some actions on for each transaction state transition. Typical
2038 * example is mdt registering call-back to write into last-received file
2039 * before each transaction commit.
2041 struct dt_txn_callback {
2042 int (*dtc_txn_start)(const struct lu_env *env,
2043 struct thandle *txn, void *cookie);
2044 int (*dtc_txn_stop)(const struct lu_env *env,
2045 struct thandle *txn, void *cookie);
2048 struct list_head dtc_linkage;
2051 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
2052 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
2054 int dt_txn_hook_start(const struct lu_env *env,
2055 struct dt_device *dev, struct thandle *txn);
2056 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
2058 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj, bool check);
2061 * Callback function used for parsing path.
2062 * \see llo_store_resolve
2064 typedef int (*dt_entry_func_t)(const struct lu_env *env,
2068 #define DT_MAX_PATH 1024
2070 int dt_path_parser(const struct lu_env *env,
2071 char *local, dt_entry_func_t entry_func,
2075 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
2076 const char *path, struct lu_fid *fid);
2078 struct dt_object *dt_store_open(const struct lu_env *env,
2079 struct dt_device *dt,
2080 const char *dirname,
2081 const char *filename,
2082 struct lu_fid *fid);
2084 struct dt_object *dt_find_or_create(const struct lu_env *env,
2085 struct dt_device *dt,
2086 const struct lu_fid *fid,
2087 struct dt_object_format *dof,
2088 struct lu_attr *attr);
2090 struct dt_object *dt_locate_at(const struct lu_env *env,
2091 struct dt_device *dev,
2092 const struct lu_fid *fid,
2093 struct lu_device *top_dev,
2094 const struct lu_object_conf *conf);
2096 static inline struct dt_object *
2097 dt_locate(const struct lu_env *env, struct dt_device *dev,
2098 const struct lu_fid *fid)
2100 return dt_locate_at(env, dev, fid,
2101 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2104 static inline struct dt_object *
2105 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2107 struct lu_object *lo;
2109 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2110 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2111 return container_of(lo, struct dt_object, do_lu);
2116 static inline void dt_object_put(const struct lu_env *env,
2117 struct dt_object *dto)
2119 lu_object_put(env, &dto->do_lu);
2122 static inline void dt_object_put_nocache(const struct lu_env *env,
2123 struct dt_object *dto)
2125 lu_object_put_nocache(env, &dto->do_lu);
2128 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2129 const struct lu_fid *first_fid,
2130 struct local_oid_storage **los);
2131 void local_oid_storage_fini(const struct lu_env *env,
2132 struct local_oid_storage *los);
2133 int local_object_fid_generate(const struct lu_env *env,
2134 struct local_oid_storage *los,
2135 struct lu_fid *fid);
2136 int local_object_declare_create(const struct lu_env *env,
2137 struct local_oid_storage *los,
2138 struct dt_object *o,
2139 struct lu_attr *attr,
2140 struct dt_object_format *dof,
2141 struct thandle *th);
2142 int local_object_create(const struct lu_env *env,
2143 struct local_oid_storage *los,
2144 struct dt_object *o,
2145 struct lu_attr *attr, struct dt_object_format *dof,
2146 struct thandle *th);
2147 struct dt_object *local_file_find(const struct lu_env *env,
2148 struct local_oid_storage *los,
2149 struct dt_object *parent,
2151 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2152 struct local_oid_storage *los,
2153 struct dt_object *parent,
2154 const char *name, __u32 mode);
2155 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2156 struct dt_device *dt,
2157 const struct lu_fid *fid,
2158 struct dt_object *parent,
2162 local_index_find_or_create(const struct lu_env *env,
2163 struct local_oid_storage *los,
2164 struct dt_object *parent,
2165 const char *name, __u32 mode,
2166 const struct dt_index_features *ft);
2168 local_index_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,
2172 const char *name, __u32 mode,
2173 const struct dt_index_features *ft);
2174 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2175 struct dt_object *parent, const char *name);
2177 static inline int dt_object_lock(const struct lu_env *env,
2178 struct dt_object *o, struct lustre_handle *lh,
2179 struct ldlm_enqueue_info *einfo,
2180 union ldlm_policy_data *policy)
2183 LASSERT(o->do_ops != NULL);
2184 LASSERT(o->do_ops->do_object_lock != NULL);
2185 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2188 static inline int dt_object_unlock(const struct lu_env *env,
2189 struct dt_object *o,
2190 struct ldlm_enqueue_info *einfo,
2191 union ldlm_policy_data *policy)
2194 LASSERT(o->do_ops != NULL);
2195 LASSERT(o->do_ops->do_object_unlock != NULL);
2196 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2199 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2200 const char *name, struct lu_fid *fid);
2202 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2203 __u64 start, __u64 end)
2207 LASSERT(o->do_ops->do_object_sync);
2208 return o->do_ops->do_object_sync(env, o, start, end);
2211 static inline int dt_fid_alloc(const struct lu_env *env,
2212 struct dt_device *d,
2214 struct lu_object *parent,
2215 const struct lu_name *name)
2217 struct lu_device *l = dt2lu_dev(d);
2219 return l->ld_ops->ldo_fid_alloc(env, l, fid, parent, name);
2222 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2223 struct thandle *th);
2224 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2225 dt_obj_version_t version, struct thandle *th);
2226 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2229 int dt_read(const struct lu_env *env, struct dt_object *dt,
2230 struct lu_buf *buf, loff_t *pos);
2231 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2232 struct lu_buf *buf, loff_t *pos);
2233 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2234 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2235 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2236 struct dt_object *obj, union lu_page *lp,
2237 size_t bytes, const struct dt_it_ops *iops,
2238 struct dt_it *it, __u32 attr, void *arg);
2239 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2240 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2242 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2243 struct idx_info *ii, const struct lu_rdpg *rdpg);
2245 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2246 struct dt_device *d)
2248 LASSERT(d->dd_ops->dt_trans_create);
2249 return d->dd_ops->dt_trans_create(env, d);
2252 static inline int dt_trans_start(const struct lu_env *env,
2253 struct dt_device *d, struct thandle *th)
2255 LASSERT(d->dd_ops->dt_trans_start);
2256 return d->dd_ops->dt_trans_start(env, d, th);
2259 /* for this transaction hooks shouldn't be called */
2260 static inline int dt_trans_start_local(const struct lu_env *env,
2261 struct dt_device *d, struct thandle *th)
2263 LASSERT(d->dd_ops->dt_trans_start);
2265 return d->dd_ops->dt_trans_start(env, d, th);
2268 static inline int dt_trans_stop(const struct lu_env *env,
2269 struct dt_device *d, struct thandle *th)
2271 LASSERT(d->dd_ops->dt_trans_stop);
2272 return d->dd_ops->dt_trans_stop(env, d, th);
2275 static inline int dt_trans_cb_add(struct thandle *th,
2276 struct dt_txn_commit_cb *dcb)
2278 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2279 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2280 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2285 static inline int dt_declare_record_write(const struct lu_env *env,
2286 struct dt_object *dt,
2287 const struct lu_buf *buf,
2293 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2294 LASSERT(th != NULL);
2295 LASSERTF(dt->do_body_ops, DFID" doesn't exit\n",
2296 PFID(lu_object_fid(&dt->do_lu)));
2297 LASSERT(dt->do_body_ops->dbo_declare_write);
2298 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2302 static inline int dt_declare_create(const struct lu_env *env,
2303 struct dt_object *dt,
2304 struct lu_attr *attr,
2305 struct dt_allocation_hint *hint,
2306 struct dt_object_format *dof,
2310 LASSERT(dt->do_ops);
2311 LASSERT(dt->do_ops->do_declare_create);
2313 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2314 return cfs_fail_err;
2316 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2319 static inline int dt_create(const struct lu_env *env,
2320 struct dt_object *dt,
2321 struct lu_attr *attr,
2322 struct dt_allocation_hint *hint,
2323 struct dt_object_format *dof,
2327 LASSERT(dt->do_ops);
2328 LASSERT(dt->do_ops->do_create);
2330 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2331 return cfs_fail_err;
2333 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2336 static inline int dt_declare_destroy(const struct lu_env *env,
2337 struct dt_object *dt,
2341 LASSERT(dt->do_ops);
2342 LASSERT(dt->do_ops->do_declare_destroy);
2344 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2345 return cfs_fail_err;
2347 return dt->do_ops->do_declare_destroy(env, dt, th);
2350 static inline int dt_destroy(const struct lu_env *env,
2351 struct dt_object *dt,
2355 LASSERT(dt->do_ops);
2356 LASSERT(dt->do_ops->do_destroy);
2358 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2359 return cfs_fail_err;
2361 return dt->do_ops->do_destroy(env, dt, th);
2364 static inline void dt_read_lock(const struct lu_env *env,
2365 struct dt_object *dt,
2369 LASSERT(dt->do_ops);
2370 LASSERT(dt->do_ops->do_read_lock);
2371 dt->do_ops->do_read_lock(env, dt, role);
2374 static inline void dt_write_lock(const struct lu_env *env,
2375 struct dt_object *dt,
2379 LASSERT(dt->do_ops);
2380 LASSERT(dt->do_ops->do_write_lock);
2381 dt->do_ops->do_write_lock(env, dt, role);
2384 static inline void dt_read_unlock(const struct lu_env *env,
2385 struct dt_object *dt)
2388 LASSERT(dt->do_ops);
2389 LASSERT(dt->do_ops->do_read_unlock);
2390 dt->do_ops->do_read_unlock(env, dt);
2393 static inline void dt_write_unlock(const struct lu_env *env,
2394 struct dt_object *dt)
2397 LASSERT(dt->do_ops);
2398 LASSERT(dt->do_ops->do_write_unlock);
2399 dt->do_ops->do_write_unlock(env, dt);
2402 static inline int dt_write_locked(const struct lu_env *env,
2403 struct dt_object *dt)
2406 LASSERT(dt->do_ops);
2407 LASSERT(dt->do_ops->do_write_locked);
2408 return dt->do_ops->do_write_locked(env, dt);
2411 static inline bool dt_object_stale(struct dt_object *dt)
2414 LASSERT(dt->do_ops);
2415 LASSERT(dt->do_ops->do_check_stale);
2417 return dt->do_ops->do_check_stale(dt);
2420 static inline int dt_declare_attr_get(const struct lu_env *env,
2421 struct dt_object *dt)
2424 LASSERT(dt->do_ops);
2425 LASSERT(dt->do_ops->do_declare_attr_get);
2427 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2428 return cfs_fail_err;
2430 return dt->do_ops->do_declare_attr_get(env, dt);
2433 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2437 LASSERT(dt->do_ops);
2438 LASSERT(dt->do_ops->do_attr_get);
2440 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2441 return cfs_fail_err;
2443 return dt->do_ops->do_attr_get(env, dt, la);
2446 static inline int dt_declare_attr_set(const struct lu_env *env,
2447 struct dt_object *dt,
2448 const struct lu_attr *la,
2452 LASSERT(dt->do_ops);
2453 LASSERT(dt->do_ops->do_declare_attr_set);
2455 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2456 return cfs_fail_err;
2458 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2461 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2462 const struct lu_attr *la, struct thandle *th)
2465 LASSERT(dt->do_ops);
2466 LASSERT(dt->do_ops->do_attr_set);
2468 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2469 return cfs_fail_err;
2471 return dt->do_ops->do_attr_set(env, dt, la, th);
2474 static inline int dt_declare_ref_add(const struct lu_env *env,
2475 struct dt_object *dt, struct thandle *th)
2478 LASSERT(dt->do_ops);
2479 LASSERT(dt->do_ops->do_declare_ref_add);
2481 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2482 return cfs_fail_err;
2484 return dt->do_ops->do_declare_ref_add(env, dt, th);
2487 static inline int dt_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_ref_add);
2494 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2495 return cfs_fail_err;
2497 return dt->do_ops->do_ref_add(env, dt, th);
2500 static inline int dt_declare_ref_del(const struct lu_env *env,
2501 struct dt_object *dt, struct thandle *th)
2504 LASSERT(dt->do_ops);
2505 LASSERT(dt->do_ops->do_declare_ref_del);
2507 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2508 return cfs_fail_err;
2510 return dt->do_ops->do_declare_ref_del(env, dt, th);
2513 static inline int dt_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_ref_del);
2520 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2521 return cfs_fail_err;
2523 return dt->do_ops->do_ref_del(env, dt, th);
2526 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2527 struct niobuf_remote *rnb,
2528 struct niobuf_local *lnb, int maxlnb,
2529 enum dt_bufs_type rw)
2532 LASSERT(d->do_body_ops);
2533 LASSERT(d->do_body_ops->dbo_bufs_get);
2534 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2535 rnb->rnb_len, lnb, maxlnb, rw);
2538 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2539 struct niobuf_local *lnb, int n)
2542 LASSERT(d->do_body_ops);
2543 LASSERT(d->do_body_ops->dbo_bufs_put);
2544 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2547 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2548 struct niobuf_local *lnb, int n)
2551 LASSERT(d->do_body_ops);
2552 LASSERT(d->do_body_ops->dbo_write_prep);
2553 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2556 static inline int dt_declare_write_commit(const struct lu_env *env,
2557 struct dt_object *d,
2558 struct niobuf_local *lnb,
2559 int n, struct thandle *th)
2561 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2562 LASSERT(th != NULL);
2563 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2567 static inline int dt_write_commit(const struct lu_env *env,
2568 struct dt_object *d, struct niobuf_local *lnb,
2569 int n, struct thandle *th, __u64 size)
2572 LASSERT(d->do_body_ops);
2573 LASSERT(d->do_body_ops->dbo_write_commit);
2574 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th, size);
2577 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2578 struct niobuf_local *lnb, int n)
2581 LASSERT(d->do_body_ops);
2582 LASSERT(d->do_body_ops->dbo_read_prep);
2583 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2586 static inline int dt_declare_write(const struct lu_env *env,
2587 struct dt_object *dt,
2588 const struct lu_buf *buf, loff_t pos,
2592 LASSERT(dt->do_body_ops);
2593 LASSERT(dt->do_body_ops->dbo_declare_write);
2594 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2597 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2598 const struct lu_buf *buf, loff_t *pos,
2602 LASSERT(dt->do_body_ops);
2603 LASSERT(dt->do_body_ops->dbo_write);
2604 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2607 static inline int dt_declare_punch(const struct lu_env *env,
2608 struct dt_object *dt, __u64 start,
2609 __u64 end, struct thandle *th)
2612 LASSERT(dt->do_body_ops);
2613 LASSERT(dt->do_body_ops->dbo_declare_punch);
2614 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2617 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2618 __u64 start, __u64 end, struct thandle *th)
2621 LASSERT(dt->do_body_ops);
2622 LASSERT(dt->do_body_ops->dbo_punch);
2623 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2626 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2627 __u64 start, __u64 end, int advice)
2630 LASSERT(dt->do_body_ops);
2631 LASSERT(dt->do_body_ops->dbo_ladvise);
2632 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2635 static inline int dt_declare_fallocate(const struct lu_env *env,
2636 struct dt_object *dt, __u64 start,
2637 __u64 end, int mode, struct thandle *th)
2640 if (!dt->do_body_ops)
2642 LASSERT(dt->do_body_ops);
2643 LASSERT(dt->do_body_ops->dbo_declare_fallocate);
2644 return dt->do_body_ops->dbo_declare_fallocate(env, dt, start, end,
2648 static inline int dt_falloc(const struct lu_env *env, struct dt_object *dt,
2649 __u64 start, __u64 end, int mode,
2653 if (!dt->do_body_ops)
2655 LASSERT(dt->do_body_ops);
2656 LASSERT(dt->do_body_ops->dbo_fallocate);
2657 return dt->do_body_ops->dbo_fallocate(env, dt, start, end, mode, th);
2660 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2664 if (d->do_body_ops == NULL)
2666 if (d->do_body_ops->dbo_fiemap_get == NULL)
2668 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2671 static inline loff_t dt_lseek(const struct lu_env *env, struct dt_object *d,
2672 loff_t offset, int whence)
2675 if (d->do_body_ops == NULL)
2677 if (d->do_body_ops->dbo_lseek == NULL)
2679 return d->do_body_ops->dbo_lseek(env, d, offset, whence);
2682 static inline int dt_statfs_info(const struct lu_env *env,
2683 struct dt_device *dev,
2684 struct obd_statfs *osfs,
2685 struct obd_statfs_info *info)
2688 LASSERT(dev->dd_ops);
2689 LASSERT(dev->dd_ops->dt_statfs);
2690 return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2693 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2694 struct obd_statfs *osfs)
2696 return dt_statfs_info(env, dev, osfs, NULL);
2699 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2703 LASSERT(dev->dd_ops);
2704 LASSERT(dev->dd_ops->dt_root_get);
2705 return dev->dd_ops->dt_root_get(env, dev, f);
2708 static inline void dt_conf_get(const struct lu_env *env,
2709 const struct dt_device *dev,
2710 struct dt_device_param *param)
2713 LASSERT(dev->dd_ops);
2714 LASSERT(dev->dd_ops->dt_conf_get);
2715 return dev->dd_ops->dt_conf_get(env, dev, param);
2718 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2721 LASSERT(dev->dd_ops);
2722 if (dev->dd_ops->dt_mnt_sb_get)
2723 return dev->dd_ops->dt_mnt_sb_get(dev);
2725 return ERR_PTR(-EOPNOTSUPP);
2728 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2731 LASSERT(dev->dd_ops);
2732 LASSERT(dev->dd_ops->dt_sync);
2733 return dev->dd_ops->dt_sync(env, dev);
2736 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2739 LASSERT(dev->dd_ops);
2740 LASSERT(dev->dd_ops->dt_ro);
2741 return dev->dd_ops->dt_ro(env, dev);
2744 static inline int dt_declare_insert(const struct lu_env *env,
2745 struct dt_object *dt,
2746 const struct dt_rec *rec,
2747 const struct dt_key *key,
2751 LASSERT(dt->do_index_ops);
2752 LASSERT(dt->do_index_ops->dio_declare_insert);
2754 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2755 return cfs_fail_err;
2757 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2760 static inline int dt_insert(const struct lu_env *env,
2761 struct dt_object *dt,
2762 const struct dt_rec *rec,
2763 const struct dt_key *key,
2767 LASSERT(dt->do_index_ops);
2768 LASSERT(dt->do_index_ops->dio_insert);
2770 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2771 return cfs_fail_err;
2773 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2776 static inline int dt_declare_xattr_del(const struct lu_env *env,
2777 struct dt_object *dt,
2782 LASSERT(dt->do_ops);
2783 LASSERT(dt->do_ops->do_declare_xattr_del);
2785 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2786 return cfs_fail_err;
2788 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2791 static inline int dt_xattr_del(const struct lu_env *env,
2792 struct dt_object *dt, const char *name,
2796 LASSERT(dt->do_ops);
2797 LASSERT(dt->do_ops->do_xattr_del);
2799 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2800 return cfs_fail_err;
2802 return dt->do_ops->do_xattr_del(env, dt, name, th);
2805 static inline int dt_declare_xattr_set(const struct lu_env *env,
2806 struct dt_object *dt,
2807 const struct lu_buf *buf,
2808 const char *name, int fl,
2812 LASSERT(dt->do_ops);
2813 LASSERT(dt->do_ops->do_declare_xattr_set);
2815 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2816 return cfs_fail_err;
2818 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2821 static inline int dt_xattr_set(const struct lu_env *env,
2822 struct dt_object *dt, const struct lu_buf *buf,
2823 const char *name, int fl, struct thandle *th)
2826 LASSERT(dt->do_ops);
2827 LASSERT(dt->do_ops->do_xattr_set);
2829 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2830 return cfs_fail_err;
2832 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2835 static inline int dt_declare_xattr_get(const struct lu_env *env,
2836 struct dt_object *dt,
2841 LASSERT(dt->do_ops);
2842 LASSERT(dt->do_ops->do_declare_xattr_get);
2844 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2845 return cfs_fail_err;
2847 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2850 static inline int dt_xattr_get(const struct lu_env *env,
2851 struct dt_object *dt, struct lu_buf *buf,
2855 LASSERT(dt->do_ops);
2856 LASSERT(dt->do_ops->do_xattr_get);
2858 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2859 return cfs_fail_err;
2861 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2864 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2865 const struct lu_buf *buf)
2868 LASSERT(dt->do_ops);
2869 LASSERT(dt->do_ops->do_xattr_list);
2871 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2872 return cfs_fail_err;
2874 return dt->do_ops->do_xattr_list(env, dt, buf);
2877 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2880 LASSERT(dt->do_ops);
2881 LASSERT(dt->do_ops->do_invalidate);
2883 return dt->do_ops->do_invalidate(env, dt);
2886 static inline int dt_declare_delete(const struct lu_env *env,
2887 struct dt_object *dt,
2888 const struct dt_key *key,
2892 LASSERT(dt->do_index_ops);
2893 LASSERT(dt->do_index_ops->dio_declare_delete);
2895 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2896 return cfs_fail_err;
2898 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2901 static inline int dt_delete(const struct lu_env *env,
2902 struct dt_object *dt,
2903 const struct dt_key *key,
2907 LASSERT(dt->do_index_ops);
2908 LASSERT(dt->do_index_ops->dio_delete);
2910 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2911 return cfs_fail_err;
2913 return dt->do_index_ops->dio_delete(env, dt, key, th);
2916 static inline int dt_commit_async(const struct lu_env *env,
2917 struct dt_device *dev)
2920 LASSERT(dev->dd_ops);
2921 LASSERT(dev->dd_ops->dt_commit_async);
2922 return dev->dd_ops->dt_commit_async(env, dev);
2925 static inline int dt_reserve_or_free_quota(const struct lu_env *env,
2926 struct dt_device *dev,
2927 struct lquota_id_info *qi)
2930 LASSERT(dev->dd_ops);
2931 LASSERT(dev->dd_ops->dt_reserve_or_free_quota);
2932 return dev->dd_ops->dt_reserve_or_free_quota(env, dev, qi);
2935 static inline int dt_lookup(const struct lu_env *env,
2936 struct dt_object *dt,
2938 const struct dt_key *key)
2943 LASSERT(dt->do_index_ops);
2944 LASSERT(dt->do_index_ops->dio_lookup);
2946 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2947 return cfs_fail_err;
2949 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2957 static inline int dt_declare_layout_change(const struct lu_env *env,
2958 struct dt_object *o,
2959 struct md_layout_change *mlc,
2964 LASSERT(o->do_ops->do_declare_layout_change);
2965 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2968 static inline int dt_layout_change(const struct lu_env *env,
2969 struct dt_object *o,
2970 struct md_layout_change *mlc,
2975 LASSERT(o->do_ops->do_layout_change);
2976 return o->do_ops->do_layout_change(env, o, mlc, th);
2979 struct dt_find_hint {
2980 struct lu_fid *dfh_fid;
2981 struct dt_device *dfh_dt;
2982 struct dt_object *dfh_o;
2985 struct dt_insert_rec {
2987 const struct lu_fid *rec_fid;
2999 struct dt_thread_info {
3000 char dti_buf[DT_MAX_PATH];
3001 struct dt_find_hint dti_dfh;
3002 struct lu_attr dti_attr;
3003 struct lu_fid dti_fid;
3004 struct dt_object_format dti_dof;
3005 struct lustre_mdt_attrs dti_lma;
3006 struct lu_buf dti_lb;
3007 struct lu_object_conf dti_conf;
3009 struct dt_insert_rec dti_dt_rec;
3012 extern struct lu_context_key dt_key;
3014 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
3016 struct dt_thread_info *dti;
3018 dti = lu_context_key_get(&env->le_ctx, &dt_key);
3023 int dt_global_init(void);
3024 void dt_global_fini(void);
3025 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
3026 const char *name, struct ldebugfs_vars *list);
3027 int dt_tunables_fini(struct dt_device *dt);
3029 # ifdef CONFIG_PROC_FS
3030 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
3031 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
3032 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
3033 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
3034 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
3035 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
3036 # endif /* CONFIG_PROC_FS */
3038 #endif /* __LUSTRE_DT_OBJECT_H */