4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
32 #ifndef __LUSTRE_DT_OBJECT_H
33 #define __LUSTRE_DT_OBJECT_H
36 * Sub-class of lu_object with methods common for "data" objects in OST stack.
38 * Data objects behave like regular files: you can read/write them, get and
39 * set their attributes. Implementation of dt interface is supposed to
40 * implement some form of garbage collection, normally reference counting
43 * Examples: osd (lustre/osd) is an implementation of dt interface.
47 #include <obd_support.h>
49 * super-class definitions.
51 #include <lu_object.h>
53 #include <libcfs/libcfs.h>
56 struct proc_dir_entry;
62 struct dt_index_features;
65 struct ldlm_enqueue_info;
68 MNTOPT_USERXATTR = 0x00000001,
69 MNTOPT_ACL = 0x00000002,
72 struct dt_device_param {
73 unsigned ddp_max_name_len;
74 unsigned ddp_max_nlink;
75 unsigned ddp_symlink_max;
77 unsigned ddp_max_ea_size;
78 unsigned ddp_mount_type;
79 unsigned long long ddp_maxbytes;
80 /* per-inode space consumption */
82 /* maximum number of blocks in an extent */
83 unsigned ddp_max_extent_blks;
84 /* per-extent insertion overhead to be used by client for grant
86 unsigned int ddp_extent_tax;
87 unsigned int ddp_brw_size; /* optimal RPC size */
88 /* T10PI checksum type, zero if not supported */
89 enum cksum_types ddp_t10_cksum_type;
90 bool ddp_has_lseek_data_hole;
94 * Per-transaction commit callback function
96 struct dt_txn_commit_cb;
97 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
98 struct dt_txn_commit_cb *cb, int err);
100 * Special per-transaction callback for cases when just commit callback
101 * is needed and per-device callback are not convenient to use
103 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
104 #define MAX_COMMIT_CB_STR_LEN 32
106 #define DCB_TRANS_STOP 0x1
107 struct dt_txn_commit_cb {
108 struct list_head dcb_linkage;
113 char dcb_name[MAX_COMMIT_CB_STR_LEN];
117 * Operations on dt device.
119 struct dt_device_operations {
121 * Return device-wide statistics.
123 * Return device-wide stats including block size, total and
124 * free blocks, total and free objects, etc. See struct obd_statfs
127 * \param[in] env execution environment for this thread
128 * \param[in] dev dt device
129 * \param[out] osfs stats information
131 * \retval 0 on success
132 * \retval negative negated errno on error
134 int (*dt_statfs)(const struct lu_env *env,
135 struct dt_device *dev,
136 struct obd_statfs *osfs,
137 struct obd_statfs_info *info);
140 * Create transaction.
142 * Create in-memory structure representing the transaction for the
143 * caller. The structure returned will be used by the calling thread
144 * to specify the transaction the updates belong to. Once created
145 * successfully ->dt_trans_stop() must be called in any case (with
146 * ->dt_trans_start() and updates or not) so that the transaction
147 * handle and other resources can be released by the layers below.
149 * \param[in] env execution environment for this thread
150 * \param[in] dev dt device
152 * \retval pointer to handle if creation succeeds
153 * \retval ERR_PTR(errno) if creation fails
155 struct thandle *(*dt_trans_create)(const struct lu_env *env,
156 struct dt_device *dev);
161 * Start the transaction. The transaction described by \a th can be
162 * started only once. Another start is considered as an error.
163 * A thread is not supposed to start a transaction while another
164 * transaction isn't closed by the thread (though multiple handles
165 * can be created). The caller should start the transaction once
166 * all possible updates are declared (see the ->do_declare_* methods
167 * below) and all the needed resources are reserved.
169 * \param[in] env execution environment for this thread
170 * \param[in] dev dt device
171 * \param[in] th transaction handle
173 * \retval 0 on success
174 * \retval negative negated errno on error
176 int (*dt_trans_start)(const struct lu_env *env,
177 struct dt_device *dev,
183 * Once stopped the transaction described by \a th is complete (all
184 * the needed updates are applied) and further processing such as
185 * flushing to disk, sending to another target, etc, is handled by
186 * lower layers. The caller can't access this transaction by the
187 * handle anymore (except from the commit callbacks, see below).
189 * \param[in] env execution environment for this thread
190 * \param[in] dev dt device
191 * \param[in] th transaction handle
193 * \retval 0 on success
194 * \retval negative negated errno on error
196 int (*dt_trans_stop)(const struct lu_env *env,
197 struct dt_device *dev,
201 * Add commit callback to the transaction.
203 * Add a commit callback to the given transaction handle. The callback
204 * will be called when the associated transaction is stored. I.e. the
205 * transaction will survive an event like power off if the callback did
206 * run. The number of callbacks isn't limited, but you should note that
207 * some disk filesystems do handle the commit callbacks in the thread
208 * handling commit/flush of all the transactions, meaning that new
209 * transactions are blocked from commit and flush until all the
210 * callbacks are done. Also, note multiple callbacks can be running
211 * concurrently using multiple CPU cores. The callbacks will be running
212 * in a special environment which can not be used to pass data around.
214 * \param[in] th transaction handle
215 * \param[in] dcb commit callback description
217 * \retval 0 on success
218 * \retval negative negated errno on error
220 int (*dt_trans_cb_add)(struct thandle *th,
221 struct dt_txn_commit_cb *dcb);
224 * Return FID of root index object.
226 * Return the FID of the root object in the filesystem. This object
227 * is usually provided as a bootstrap point by a disk filesystem.
228 * This is up to the implementation which FID to use, though
229 * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
231 * \param[in] env execution environment for this thread
232 * \param[in] dev dt device
233 * \param[out] fid FID of the root object
235 * \retval 0 on success
236 * \retval negative negated errno on error
238 int (*dt_root_get)(const struct lu_env *env,
239 struct dt_device *dev,
243 * Return device configuration data.
245 * Return device (disk fs, actually) specific configuration.
246 * The configuration isn't subject to change at runtime.
247 * See struct dt_device_param for the details.
249 * \param[in] env execution environment for this thread
250 * \param[in] dev dt device
251 * \param[out] param configuration parameters
253 void (*dt_conf_get)(const struct lu_env *env,
254 const struct dt_device *dev,
255 struct dt_device_param *param);
258 * Return device's super block.
260 * \param[in] dev dt device
262 struct super_block *(*dt_mnt_sb_get)(const struct dt_device *dev);
267 * Sync all the cached state (dirty buffers, pages, etc) to the
268 * persistent storage. The method returns control once the sync is
269 * complete. This operation may incur significant I/O to disk and
270 * should be reserved for cases where a global sync is strictly
273 * \param[in] env execution environment for this thread
274 * \param[in] dev dt device
276 * \retval 0 on success
277 * \retval negative negated errno on error
279 int (*dt_sync)(const struct lu_env *env,
280 struct dt_device *dev);
283 * Make device read-only.
285 * Prevent new modifications to the device. This is a very specific
286 * state where all the changes are accepted successfully and the
287 * commit callbacks are called, but persistent state never changes.
288 * Used only in the tests to simulate power-off scenario.
290 * \param[in] env execution environment for this thread
291 * \param[in] dev dt device
293 * \retval 0 on success
294 * \retval negative negated errno on error
296 int (*dt_ro)(const struct lu_env *env,
297 struct dt_device *dev);
300 * Start transaction commit asynchronously.
303 * Provide a hint to the underlying filesystem that it should start
304 * committing soon. The control returns immediately. It's up to the
305 * layer implementing the method how soon to start committing. Usually
306 * this should be throttled to some extent, otherwise the number of
307 * aggregated transaction goes too high causing performance drop.
309 * \param[in] env execution environment for this thread
310 * \param[in] dev dt device
312 * \retval 0 on success
313 * \retval negative negated errno on error
315 int (*dt_commit_async)(const struct lu_env *env,
316 struct dt_device *dev);
319 struct dt_index_features {
320 /** required feature flags from enum dt_index_flags */
322 /** minimal required key size */
323 size_t dif_keysize_min;
324 /** maximal required key size, 0 if no limit */
325 size_t dif_keysize_max;
326 /** minimal required record size */
327 size_t dif_recsize_min;
328 /** maximal required record size, 0 if no limit */
329 size_t dif_recsize_max;
330 /** pointer size for record */
334 enum dt_index_flags {
335 /** index supports variable sized keys */
336 DT_IND_VARKEY = BIT(0),
337 /** index supports variable sized records */
338 DT_IND_VARREC = BIT(1),
339 /** index can be modified */
340 DT_IND_UPDATE = BIT(2),
341 /** index supports records with non-unique (duplicate) keys */
342 DT_IND_NONUNQ = BIT(3),
344 * index support fixed-size keys sorted with natural numerical way
345 * and is able to return left-side value if no exact value found
347 DT_IND_RANGE = BIT(4),
350 /* for dt_read_lock() and dt_write_lock() object lock rule */
351 enum dt_object_role {
361 * Features, required from index to support file system directories (mapping
364 extern const struct dt_index_features dt_directory_features;
365 extern const struct dt_index_features dt_otable_features;
366 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
367 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
368 extern const struct dt_index_features dt_lfsck_namespace_features;
370 /* index features supported by the accounting objects */
371 extern const struct dt_index_features dt_acct_features;
373 /* index features supported by the quota global indexes */
374 extern const struct dt_index_features dt_quota_glb_features;
376 /* index features supported by the quota slave indexes */
377 extern const struct dt_index_features dt_quota_slv_features;
379 /* index features supported by the nodemap index */
380 extern const struct dt_index_features dt_nodemap_features;
383 * This is a general purpose dt allocation hint.
384 * It now contains the parent object.
385 * It can contain any allocation hint in the future.
387 struct dt_allocation_hint {
388 struct dt_object *dah_parent;
389 const void *dah_eadata;
393 int dah_append_stripes;
395 char *dah_append_pool;
399 * object type specifier.
402 enum dt_format_type {
407 /** for special index */
409 /** for symbolic link */
414 * object format specifier.
416 struct dt_object_format {
417 /** type for dt object */
418 enum dt_format_type dof_type;
428 * special index need feature as parameter to create
432 const struct dt_index_features *di_feat;
437 enum dt_format_type dt_mode_to_dft(__u32 mode);
439 typedef __u64 dt_obj_version_t;
441 union ldlm_policy_data;
443 struct md_layout_change;
446 * A dt_object provides common operations to create and destroy
447 * objects and to manage regular and extended attributes.
449 struct dt_object_operations {
451 * Get read lock on object.
453 * Read lock is compatible with other read locks, so it's shared.
454 * Read lock is not compatible with write lock which is exclusive.
455 * The lock is blocking and can't be used from an interrupt context.
457 * \param[in] env execution environment for this thread
458 * \param[in] dt object to lock for reading
459 * \param[in] role a hint to debug locks (see kernel's mutexes)
461 void (*do_read_lock)(const struct lu_env *env,
462 struct dt_object *dt,
466 * Get write lock on object.
468 * Write lock is exclusive and cannot be shared. The lock is blocking
469 * and can't be used from an interrupt context.
471 * \param[in] env execution environment for this thread
472 * \param[in] dt object to lock for writing
473 * \param[in] role a hint to debug locks (see kernel's mutexes)
476 void (*do_write_lock)(const struct lu_env *env,
477 struct dt_object *dt,
483 * \param[in] env execution environment for this thread
484 * \param[in] dt object
486 void (*do_read_unlock)(const struct lu_env *env,
487 struct dt_object *dt);
490 * Release write lock.
492 * \param[in] env execution environment for this thread
493 * \param[in] dt object
495 void (*do_write_unlock)(const struct lu_env *env,
496 struct dt_object *dt);
499 * Check whether write lock is held.
501 * The caller can learn whether write lock is held on the object
503 * \param[in] env execution environment for this thread
504 * \param[in] dt object
506 * \retval 0 no write lock
507 * \retval 1 write lock is held
509 int (*do_write_locked)(const struct lu_env *env,
510 struct dt_object *dt);
513 * Declare intention to request reqular attributes.
515 * Notity the underlying filesystem that the caller may request regular
516 * attributes with ->do_attr_get() soon. This allows OSD to implement
517 * prefetching logic in an object-oriented manner. The implementation
518 * can be noop. This method should avoid expensive delays such as
519 * waiting on disk I/O, otherwise the goal of enabling a performance
520 * optimization would be defeated.
522 * \param[in] env execution environment for this thread
523 * \param[in] dt object
525 * \retval 0 on success
526 * \retval negative negated errno on error
528 int (*do_declare_attr_get)(const struct lu_env *env,
529 struct dt_object *dt);
532 * Return regular attributes.
534 * The object must exist. Currently all the attributes should be
535 * returned, but in the future this can be improved so that only
536 * a selected set is returned. This can improve performance as in
537 * some cases attributes are stored in different places and
538 * getting them all can be an iterative and expensive process.
540 * \param[in] env execution environment for this thread
541 * \param[in] dt object
542 * \param[out] attr attributes to fill
544 * \retval 0 on success
545 * \retval negative negated errno on error
547 int (*do_attr_get)(const struct lu_env *env,
548 struct dt_object *dt,
549 struct lu_attr *attr);
552 * Declare intention to change regular object's attributes.
554 * Notify the underlying filesystem that the regular attributes may
555 * change in this transaction. This enables the layer below to prepare
556 * resources (e.g. journal credits in ext4). This method should be
557 * called between creating the transaction and starting it. Note that
558 * the la_valid field of \a attr specifies which attributes will change.
559 * The object need not exist.
561 * \param[in] env execution environment for this thread
562 * \param[in] dt object
563 * \param[in] attr attributes to change specified in attr.la_valid
564 * \param[in] th transaction handle
566 * \retval 0 on success
567 * \retval negative negated errno on error
569 int (*do_declare_attr_set)(const struct lu_env *env,
570 struct dt_object *dt,
571 const struct lu_attr *attr,
575 * Change regular attributes.
577 * Change regular attributes in the given transaction. Note only
578 * attributes flagged by attr.la_valid change. The object must
579 * exist. If the layer implementing this method is responsible for
580 * quota, then the method should maintain object accounting for the
581 * given credentials when la_uid/la_gid changes.
583 * \param[in] env execution environment for this thread
584 * \param[in] dt object
585 * \param[in] attr new attributes to apply
586 * \param[in] th transaction handle
588 * \retval 0 on success
589 * \retval negative negated errno on error
591 int (*do_attr_set)(const struct lu_env *env,
592 struct dt_object *dt,
593 const struct lu_attr *attr,
597 * Declare intention to request extented attribute.
599 * Notify the underlying filesystem that the caller may request extended
600 * attribute with ->do_xattr_get() soon. This allows OSD to implement
601 * prefetching logic in an object-oriented manner. The implementation
602 * can be noop. This method should avoid expensive delays such as
603 * waiting on disk I/O, otherwise the goal of enabling a performance
604 * optimization would be defeated.
606 * \param[in] env execution environment for this thread
607 * \param[in] dt object
608 * \param[in] buf unused, may be removed in the future
609 * \param[in] name name of the extended attribute
611 * \retval 0 on success
612 * \retval negative negated errno on error
614 int (*do_declare_xattr_get)(const struct lu_env *env,
615 struct dt_object *dt,
620 * Return a value of an extended attribute.
622 * The object must exist. If the buffer is NULL, then the method
623 * must return the size of the value.
625 * \param[in] env execution environment for this thread
626 * \param[in] dt object
627 * \param[out] buf buffer in which to store the value
628 * \param[in] name name of the extended attribute
630 * \retval 0 on success
631 * \retval -ERANGE if \a buf is too small
632 * \retval negative negated errno on error
633 * \retval positive value's size if \a buf is NULL or has zero size
635 int (*do_xattr_get)(const struct lu_env *env,
636 struct dt_object *dt,
641 * Declare intention to change an extended attribute.
643 * Notify the underlying filesystem that the extended attribute may
644 * change in this transaction. This enables the layer below to prepare
645 * resources (e.g. journal credits in ext4). This method should be
646 * called between creating the transaction and starting it. The object
649 * \param[in] env execution environment for this thread
650 * \param[in] dt object
651 * \param[in] buf buffer storing new value of the attribute
652 * \param[in] name name of the attribute
653 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
654 * LU_XATTR_REPLACE - fail if EA doesn't exist
655 * \param[in] th transaction handle
657 * \retval 0 on success
658 * \retval negative negated errno on error
660 int (*do_declare_xattr_set)(const struct lu_env *env,
661 struct dt_object *dt,
662 const struct lu_buf *buf,
668 * Set an extended attribute.
670 * Change or replace the specified extended attribute (EA).
671 * The flags passed in \a fl dictate whether the EA is to be
672 * created or replaced, as follows.
673 * LU_XATTR_CREATE - fail if EA exists
674 * LU_XATTR_REPLACE - fail if EA doesn't exist
675 * The object must exist.
677 * \param[in] env execution environment for this thread
678 * \param[in] dt object
679 * \param[in] buf buffer storing new value of the attribute
680 * \param[in] name name of the attribute
681 * \param[in] fl flags indicating EA creation or replacement
682 * \param[in] th transaction handle
684 * \retval 0 on success
685 * \retval negative negated errno on error
687 int (*do_xattr_set)(const struct lu_env *env,
688 struct dt_object *dt,
689 const struct lu_buf *buf,
695 * Declare intention to delete an extended attribute.
697 * Notify the underlying filesystem that the extended attribute may
698 * be deleted in this transaction. This enables the layer below to
699 * prepare resources (e.g. journal credits in ext4). This method
700 * should be called between creating the transaction and starting it.
701 * The object need not exist.
703 * \param[in] env execution environment for this thread
704 * \param[in] dt object
705 * \param[in] name name of the attribute
706 * \param[in] th transaction handle
708 * \retval 0 on success
709 * \retval negative negated errno on error
711 int (*do_declare_xattr_del)(const struct lu_env *env,
712 struct dt_object *dt,
717 * Delete an extended attribute.
719 * This method deletes the specified extended attribute. The object
722 * \param[in] env execution environment for this thread
723 * \param[in] dt object
724 * \param[in] name name of the attribute
725 * \param[in] th transaction handle
727 * \retval 0 on success
728 * \retval negative negated errno on error
730 int (*do_xattr_del)(const struct lu_env *env,
731 struct dt_object *dt,
736 * Return a list of the extended attributes.
738 * Fills the passed buffer with a list of the extended attributes
739 * found in the object. The names are separated with '\0'.
740 * The object must exist.
742 * \param[in] env execution environment for this thread
743 * \param[in] dt object
744 * \param[out] buf buffer to put the list in
746 * \retval positive bytes used/required in the buffer
747 * \retval negative negated errno on error
749 int (*do_xattr_list)(const struct lu_env *env,
750 struct dt_object *dt,
751 const struct lu_buf *buf);
754 * Prepare allocation hint for a new object.
756 * This method is used by the caller to inform OSD of the parent-child
757 * relationship between two objects and enable efficient object
758 * allocation. Filled allocation hint will be passed to ->do_create()
761 * \param[in] env execution environment for this thread
762 * \param[out] ah allocation hint
763 * \param[in] parent parent object (can be NULL)
764 * \param[in] child child object
765 * \param[in] _mode type of the child object
767 void (*do_ah_init)(const struct lu_env *env,
768 struct dt_allocation_hint *ah,
769 struct dt_object *parent,
770 struct dt_object *child,
774 * Declare intention to create a new object.
776 * Notify the underlying filesystem that the object may be created
777 * in this transaction. This enables the layer below to prepare
778 * resources (e.g. journal credits in ext4). This method should be
779 * called between creating the transaction and starting it.
781 * If the layer implementing this method is responsible for quota,
782 * then the method should reserve an object for the given credentials
783 * and return an error if quota is over. If object creation later
784 * fails for some reason, then the reservation should be released
785 * properly (usually in ->dt_trans_stop()).
787 * \param[in] env execution environment for this thread
788 * \param[in] dt object
789 * \param[in] attr attributes of the new object
790 * \param[in] hint allocation hint
791 * \param[in] dof object format
792 * \param[in] th transaction handle
794 * \retval 0 on success
795 * \retval negative negated errno on error
797 int (*do_declare_create)(const struct lu_env *env,
798 struct dt_object *dt,
799 struct lu_attr *attr,
800 struct dt_allocation_hint *hint,
801 struct dt_object_format *dof,
807 * The method creates the object passed with the specified attributes
808 * and object format. Object allocation procedure can use information
809 * stored in the allocation hint. Different object formats are supported
810 * (see enum dt_format_type and struct dt_object_format) depending on
811 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
812 * in the LU-object header attributes.
814 * If the layer implementing this method is responsible for quota,
815 * then the method should maintain object accounting for the given
818 * \param[in] env execution environment for this thread
819 * \param[in] dt object
820 * \param[in] attr attributes of the new object
821 * \param[in] hint allocation hint
822 * \param[in] dof object format
823 * \param[in] th transaction handle
825 * \retval 0 on success
826 * \retval negative negated errno on error
828 int (*do_create)(const struct lu_env *env,
829 struct dt_object *dt,
830 struct lu_attr *attr,
831 struct dt_allocation_hint *hint,
832 struct dt_object_format *dof,
836 * Declare intention to destroy an object.
838 * Notify the underlying filesystem that the object may be destroyed
839 * in this transaction. This enables the layer below to prepare
840 * resources (e.g. journal credits in ext4). This method should be
841 * called between creating the transaction and starting it. The object
844 * \param[in] env execution environment for this thread
845 * \param[in] dt object
846 * \param[in] th transaction handle
848 * \retval 0 on success
849 * \retval negative negated errno on error
851 int (*do_declare_destroy)(const struct lu_env *env,
852 struct dt_object *dt,
858 * This method destroys the object and all the resources associated
859 * with the object (data, key/value pairs, extended attributes, etc).
860 * The object must exist. If destroy is successful, then flag
861 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
862 * instance of in-core object. Any subsequent access to the same FID
863 * should get another instance with no LOHA_EXIST flag set.
865 * If the layer implementing this method is responsible for quota,
866 * then the method should maintain object accounting for the given
869 * \param[in] env execution environment for this thread
870 * \param[in] dt object
871 * \param[in] th transaction handle
873 * \retval 0 on success
874 * \retval negative negated errno on error
876 int (*do_destroy)(const struct lu_env *env,
877 struct dt_object *dt,
881 * Try object as an index.
883 * Announce that this object is going to be used as an index. This
884 * operation checks that object supports indexing operations and
885 * installs appropriate dt_index_operations vector on success.
886 * Also probes for features. Operation is successful if all required
887 * features are supported. It's not possible to access the object
888 * with index methods before ->do_index_try() returns success.
890 * \param[in] env execution environment for this thread
891 * \param[in] dt object
892 * \param[in] feat index features
894 * \retval 0 on success
895 * \retval negative negated errno on error
897 int (*do_index_try)(const struct lu_env *env,
898 struct dt_object *dt,
899 const struct dt_index_features *feat);
902 * Declare intention to increment nlink count.
904 * Notify the underlying filesystem that the nlink regular attribute
905 * be changed in this transaction. This enables the layer below to
906 * prepare resources (e.g. journal credits in ext4). This method
907 * should be called between creating the transaction and starting it.
908 * The object need not exist.
910 * \param[in] env execution environment for this thread
911 * \param[in] dt object
912 * \param[in] th transaction handle
914 * \retval 0 on success
915 * \retval negative negated errno on error
917 int (*do_declare_ref_add)(const struct lu_env *env,
918 struct dt_object *dt,
924 * Increment nlink (from the regular attributes set) in the given
925 * transaction. Note the absolute limit for nlink should be learnt
926 * from struct dt_device_param::ddp_max_nlink. The object must exist.
928 * \param[in] env execution environment for this thread
929 * \param[in] dt object
930 * \param[in] th transaction handle
932 * \retval 0 on success
933 * \retval negative negated errno on error
935 int (*do_ref_add)(const struct lu_env *env,
936 struct dt_object *dt, struct thandle *th);
939 * Declare intention to decrement nlink count.
941 * Notify the underlying filesystem that the nlink regular attribute
942 * be changed in this transaction. This enables the layer below to
943 * prepare resources (e.g. journal credits in ext4). This method
944 * should be called between creating the transaction and starting it.
945 * The object need not exist.
947 * \param[in] env execution environment for this thread
948 * \param[in] dt object
949 * \param[in] th transaction handle
951 * \retval 0 on success
952 * \retval negative negated errno on error
954 int (*do_declare_ref_del)(const struct lu_env *env,
955 struct dt_object *dt,
961 * Decrement nlink (from the regular attributes set) in the given
962 * transaction. The object must 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_ref_del)(const struct lu_env *env,
972 struct dt_object *dt,
978 * The method is called to sync specified range of the object to a
979 * persistent storage. The control is returned once the operation is
980 * complete. The difference from ->do_sync() is that the object can
981 * be in-sync with the persistent storage (nothing to flush), then
982 * the method returns quickly with no I/O overhead. So, this method
983 * should be preferred over ->do_sync() where possible. Also note that
984 * if the object isn't clean, then some disk filesystems will call
985 * ->do_sync() to maintain overall consistency, in which case it's
986 * still very expensive.
988 * \param[in] env execution environment for this thread
989 * \param[in] dt object
990 * \param[in] start start of the range to sync
991 * \param[in] end end of the range to sync
993 * \retval 0 on success
994 * \retval negative negated errno on error
996 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
997 __u64 start, __u64 end);
1002 * Lock object(s) using Distributed Lock Manager (LDLM).
1004 * Get LDLM locks for the object. Currently used to lock "remote"
1005 * objects in DNE configuration - a service running on MDTx needs
1006 * to lock an object on MDTy.
1008 * \param[in] env execution environment for this thread
1009 * \param[in] dt object
1010 * \param[out] lh lock handle, sometimes used, sometimes not
1011 * \param[in] einfo ldlm callbacks, locking type and mode
1012 * \param[out] einfo private data to be passed to unlock later
1013 * \param[in] policy inodebits data
1015 * \retval 0 on success
1016 * \retval negative negated errno on error
1018 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1019 struct lustre_handle *lh,
1020 struct ldlm_enqueue_info *einfo,
1021 union ldlm_policy_data *policy);
1026 * Release LDLM lock(s) granted with ->do_object_lock().
1028 * \param[in] env execution environment for this thread
1029 * \param[in] dt object
1030 * \param[in] einfo lock handles, from ->do_object_lock()
1031 * \param[in] policy inodebits data
1033 * \retval 0 on success
1034 * \retval negative negated errno on error
1036 int (*do_object_unlock)(const struct lu_env *env,
1037 struct dt_object *dt,
1038 struct ldlm_enqueue_info *einfo,
1039 union ldlm_policy_data *policy);
1042 * Invalidate attribute cache.
1044 * This method invalidate attribute cache of the object, which is on OSP
1047 * \param[in] env execution envionment for this thread
1048 * \param[in] dt object
1050 * \retval 0 on success
1051 * \retval negative negated errno on error
1053 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1056 * Check object stale state.
1060 * \param[in] dt object
1062 * \retval true for stale object
1063 * \retval false for not stale object
1065 bool (*do_check_stale)(struct dt_object *dt);
1068 * Declare intention to instaintiate extended layout component.
1070 * \param[in] env execution environment
1071 * \param[in] dt DT object
1072 * \param[in] layout data structure to describe the changes to
1073 * the DT object's layout
1074 * \param[in] buf buffer containing client's lovea or empty
1077 * \retval -ne error code
1079 int (*do_declare_layout_change)(const struct lu_env *env,
1080 struct dt_object *dt,
1081 struct md_layout_change *mlc,
1082 struct thandle *th);
1085 * Client is trying to write to un-instantiated 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_layout_change)(const struct lu_env *env, struct dt_object *dt,
1097 struct md_layout_change *mlc,
1098 struct thandle *th);
1102 DT_BUFS_TYPE_READ = 0x0000,
1103 DT_BUFS_TYPE_WRITE = 0x0001,
1104 DT_BUFS_TYPE_READAHEAD = 0x0002,
1105 DT_BUFS_TYPE_LOCAL = 0x0004,
1109 * Per-dt-object operations on "file body" - unstructure raw data.
1111 struct dt_body_operations {
1115 * Read unstructured data from an existing regular object.
1116 * Only data before attr.la_size is returned.
1118 * \param[in] env execution environment for this thread
1119 * \param[in] dt object
1120 * \param[out] buf buffer (including size) to copy data in
1121 * \param[in] pos position in the object to start
1122 * \param[out] pos original value of \a pos + bytes returned
1124 * \retval positive bytes read on success
1125 * \retval negative negated errno on error
1127 ssize_t (*dbo_read)(const struct lu_env *env,
1128 struct dt_object *dt,
1133 * Declare intention to write data to object.
1135 * Notify the underlying filesystem that data may be written in
1136 * this transaction. This enables the layer below to prepare resources
1137 * (e.g. journal credits in ext4). This method should be called
1138 * between creating the transaction and starting it. The object need
1139 * not exist. If the layer implementing this method is responsible for
1140 * quota, then the method should reserve space for the given credentials
1141 * and return an error if quota is over. If the write later fails
1142 * for some reason, then the reserve should be released properly
1143 * (usually in ->dt_trans_stop()).
1145 * \param[in] env execution environment for this thread
1146 * \param[in] dt object
1147 * \param[in] buf buffer (including size) to copy data from
1148 * \param[in] pos position in the object to start
1149 * \param[in] th transaction handle
1151 * \retval 0 on success
1152 * \retval negative negated errno on error
1154 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1155 struct dt_object *dt,
1156 const struct lu_buf *buf,
1158 struct thandle *th);
1161 * Write unstructured data to regular existing object.
1163 * The method allocates space and puts data in. Also, the method should
1164 * maintain attr.la_size properly. Partial writes are possible.
1166 * If the layer implementing this method is responsible for quota,
1167 * then the method should maintain space accounting for the given
1170 * \param[in] env execution environment for this thread
1171 * \param[in] dt object
1172 * \param[in] buf buffer (including size) to copy data from
1173 * \param[in] pos position in the object to start
1174 * \param[out] pos \a pos + bytes written
1175 * \param[in] th transaction handle
1177 * \retval positive bytes written on success
1178 * \retval negative negated errno on error
1180 ssize_t (*dbo_write)(const struct lu_env *env,
1181 struct dt_object *dt,
1182 const struct lu_buf *buf,
1184 struct thandle *th);
1187 * Return buffers for data.
1189 * This method is used to access data with no copying. It's so-called
1190 * zero-copy I/O. The method returns the descriptors for the internal
1191 * buffers where data are managed by the disk filesystem. For example,
1192 * pagecache in case of ext4 or ARC with ZFS. Then other components
1193 * (e.g. networking) can transfer data from or to the buffers with no
1194 * additional copying.
1196 * The method should fill an array of struct niobuf_local, where
1197 * each element describes a full or partial page for data at specific
1198 * offset. The caller should use page/lnb_page_offset/len to find data
1199 * at object's offset lnb_file_offset.
1201 * The memory referenced by the descriptors can't change its purpose
1202 * until the complementary ->dbo_bufs_put() is called. The caller should
1203 * specify if the buffers are used to read or modify data so that OSD
1204 * can decide how to initialize the buffers: bring all the data for
1205 * reads or just bring partial buffers for write. Note: the method does
1206 * not check whether output array is large enough.
1208 * \param[in] env execution environment for this thread
1209 * \param[in] dt object
1210 * \param[in] pos position in the object to start
1211 * \param[in] len size of region in bytes
1212 * \param[out] lb array of descriptors to fill
1213 * \param[in] maxlnb max slots in @lnb array
1214 * \param[in] rw 0 if used to read, 1 if used for write
1216 * \retval positive number of descriptors on success
1217 * \retval negative negated errno on error
1219 int (*dbo_bufs_get)(const struct lu_env *env,
1220 struct dt_object *dt,
1223 struct niobuf_local *lb,
1225 enum dt_bufs_type rw);
1228 * Release reference granted by ->dbo_bufs_get().
1230 * Release the reference granted by the previous ->dbo_bufs_get().
1231 * Note the references are counted.
1233 * \param[in] env execution environment for this thread
1234 * \param[in] dt object
1235 * \param[out] lb array of descriptors to fill
1236 * \param[in] nr size of the array
1238 * \retval 0 on success
1239 * \retval negative negated errno on error
1241 int (*dbo_bufs_put)(const struct lu_env *env,
1242 struct dt_object *dt,
1243 struct niobuf_local *lb,
1247 * Prepare buffers for reading.
1249 * The method is called on the given buffers to fill them with data
1250 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1251 * caller should be able to get few buffers for discontiguous regions
1252 * using few calls to ->dbo_bufs_get() and then request them all for
1253 * the preparation with a single call, so that OSD can fire many I/Os
1254 * to run concurrently. It's up to the specific OSD whether to implement
1255 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1256 * prepare data for every requested region individually.
1258 * \param[in] env execution environment for this thread
1259 * \param[in] dt object
1260 * \param[in] lnb array of buffer descriptors
1261 * \param[in] nr size of the array
1263 * \retval 0 on success
1264 * \retval negative negated errno on error
1266 int (*dbo_read_prep)(const struct lu_env *env,
1267 struct dt_object *dt,
1268 struct niobuf_local *lnb,
1272 * Prepare buffers for write.
1274 * This method is called on the given buffers to ensure the partial
1275 * buffers contain correct data. The underlying idea is the same as
1276 * in ->db_read_prep().
1278 * \param[in] env execution environment for this thread
1279 * \param[in] dt object
1280 * \param[in] lb array of buffer descriptors
1281 * \param[in] nr size of the array
1283 * \retval 0 on success
1284 * \retval negative negated errno on error
1286 int (*dbo_write_prep)(const struct lu_env *env,
1287 struct dt_object *dt,
1288 struct niobuf_local *lb,
1292 * Declare intention to write data stored in the buffers.
1294 * Notify the underlying filesystem that data may be written in
1295 * this transaction. This enables the layer below to prepare resources
1296 * (e.g. journal credits in ext4). This method should be called
1297 * between creating the transaction and starting it.
1299 * If the layer implementing this method is responsible for quota,
1300 * then the method should be reserving a space for the given
1301 * credentials and return an error if quota is exceeded. If the write
1302 * later fails for some reason, then the reserve should be released
1303 * properly (usually in ->dt_trans_stop()).
1305 * \param[in] env execution environment for this thread
1306 * \param[in] dt object
1307 * \param[in] lb array of descriptors
1308 * \param[in] nr size of the array
1309 * \param[in] th transaction handle
1311 * \retval 0 on success
1312 * \retval negative negated errno on error
1314 int (*dbo_declare_write_commit)(const struct lu_env *env,
1315 struct dt_object *dt,
1316 struct niobuf_local *lb,
1318 struct thandle *th);
1321 * Write to existing object.
1323 * This method is used to write data to a persistent storage using
1324 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1325 * data into the buffers using own mechanisms (e.g. direct transfer
1326 * from a NIC). The method should maintain attr.la_size. Also,
1327 * attr.la_blocks should be maintained but this can be done in lazy
1328 * manner, when actual allocation happens.
1330 * If the layer implementing this method is responsible for quota,
1331 * then the method should maintain space accounting for the given
1334 * user_size parameter is the apparent size of the file, ie the size
1335 * of the clear text version of the file. It can differ from the actual
1336 * amount of valuable data received when a file is encrypted,
1337 * because encrypted pages always contain PAGE_SIZE bytes of data,
1338 * even if clear text data is only a few bytes.
1339 * In case of encrypted file, apparent size will be stored as the inode
1340 * size, so that servers return to clients an object size they can use
1341 * to determine clear text size.
1343 * \param[in] env execution environment for this thread
1344 * \param[in] dt object
1345 * \param[in] lb array of descriptors for the buffers
1346 * \param[in] nr size of the array
1347 * \param[in] th transaction handle
1348 * \param[in] user_size apparent size
1350 * \retval 0 on success
1351 * \retval negative negated errno on error
1353 int (*dbo_write_commit)(const struct lu_env *env,
1354 struct dt_object *dt,
1355 struct niobuf_local *lb,
1361 * Return logical to physical block mapping for a given extent
1363 * \param[in] env execution environment for this thread
1364 * \param[in] dt object
1365 * \param[in] fm describe the region to map and the output buffer
1366 * see the details in include/linux/fiemap.h
1368 * \retval 0 on success
1369 * \retval negative negated errno on error
1371 int (*dbo_fiemap_get)(const struct lu_env *env,
1372 struct dt_object *dt,
1376 * Declare intention to deallocate space from an object.
1378 * Notify the underlying filesystem that space may be deallocated in
1379 * this transactions. This enables the layer below to prepare resources
1380 * (e.g. journal credits in ext4). This method should be called between
1381 * creating the transaction and starting it. The object need not exist.
1383 * \param[in] env execution environment for this thread
1384 * \param[in] dt object
1385 * \param[in] start the start of the region to deallocate
1386 * \param[in] end the end of the region to deallocate
1387 * \param[in] th transaction handle
1389 * \retval 0 on success
1390 * \retval negative negated errno on error
1392 int (*dbo_declare_punch)(const struct lu_env *env,
1393 struct dt_object *dt,
1396 struct thandle *th);
1399 * Deallocate specified region in an object.
1401 * This method is used to deallocate (release) space possibly consumed
1402 * by the given region of the object. If the layer implementing this
1403 * method is responsible for quota, then the method should maintain
1404 * space accounting for the given credentials.
1406 * \param[in] env execution environment for this thread
1407 * \param[in] dt object
1408 * \param[in] start the start of the region to deallocate
1409 * \param[in] end the end of the region to deallocate
1410 * \param[in] th transaction handle
1412 * \retval 0 on success
1413 * \retval negative negated errno on error
1415 int (*dbo_punch)(const struct lu_env *env,
1416 struct dt_object *dt,
1419 struct thandle *th);
1421 * Give advices on specified region in an object.
1423 * This method is used to give advices about access pattern on an
1424 * given region of the object. The disk filesystem understands
1425 * the advices and tunes cache/read-ahead policies.
1427 * \param[in] env execution environment for this thread
1428 * \param[in] dt object
1429 * \param[in] start the start of the region affected
1430 * \param[in] end the end of the region affected
1431 * \param[in] advice advice type
1433 * \retval 0 on success
1434 * \retval negative negated errno on error
1436 int (*dbo_ladvise)(const struct lu_env *env,
1437 struct dt_object *dt,
1440 enum lu_ladvise_type advice);
1443 * Declare intention to preallocate space for an object
1445 * \param[in] env execution environment for this thread
1446 * \param[in] dt object
1447 * \param[in] th transaction handle
1449 * \retval 0 on success
1450 * \retval negative negated errno on error
1452 int (*dbo_declare_fallocate)(const struct lu_env *env,
1453 struct dt_object *dt, __u64 start,
1454 __u64 end, int mode, struct thandle *th);
1456 * Allocate specified region for an object
1458 * \param[in] env execution environment for this thread
1459 * \param[in] dt object
1460 * \param[in] start the start of the region to allocate
1461 * \param[in] end the end of the region to allocate
1462 * \param[in] mode fallocate mode
1463 * \param[in] th transaction handle
1465 * \retval 0 on success
1466 * \retval negative negated errno on error
1468 int (*dbo_fallocate)(const struct lu_env *env,
1469 struct dt_object *dt,
1473 struct thandle *th);
1475 * Do SEEK_HOLE/SEEK_DATA request on object
1477 * \param[in] env execution environment for this thread
1478 * \param[in] dt object
1479 * \param[in] offset the offset to start seek from
1480 * \param[in] whence seek mode, SEEK_HOLE or SEEK_DATA
1482 * \retval hole/data offset on success
1483 * \retval negative negated errno on error
1485 loff_t (*dbo_lseek)(const struct lu_env *env, struct dt_object *dt,
1486 loff_t offset, int whence);
1490 * Incomplete type of index record.
1495 * Incomplete type of index key.
1500 * Incomplete type of dt iterator.
1505 * Per-dt-object operations on object as index. Index is a set of key/value
1506 * pairs abstracted from an on-disk representation. An index supports the
1507 * number of operations including lookup by key, insert and delete. Also,
1508 * an index can be iterated to find the pairs one by one, from a beginning
1509 * or specified point.
1511 struct dt_index_operations {
1513 * Lookup in an index by key.
1515 * The method returns a value for the given key. Key/value format
1516 * and size should have been negotiated with ->do_index_try() before.
1517 * Thus it's the caller's responsibility to provide the method with
1518 * proper key and big enough buffer. No external locking is required,
1519 * all the internal consistency should be implemented by the method
1520 * or lower layers. The object should should have been created with
1521 * type DFT_INDEX or DFT_DIR.
1523 * \param[in] env execution environment for this thread
1524 * \param[in] dt object
1525 * \param[out] rec buffer where value will be stored
1526 * \param[in] key key
1528 * \retval 0 on success
1529 * \retval -ENOENT if key isn't found
1530 * \retval negative negated errno on error
1532 int (*dio_lookup)(const struct lu_env *env,
1533 struct dt_object *dt,
1535 const struct dt_key *key);
1538 * Declare intention to insert a key/value into an index.
1540 * Notify the underlying filesystem that new key/value may be inserted
1541 * in this transaction. This enables the layer below to prepare
1542 * resources (e.g. journal credits in ext4). This method should be
1543 * called between creating the transaction and starting it. key/value
1544 * format and size is subject to ->do_index_try().
1546 * \param[in] env execution environment for this thread
1547 * \param[in] dt object
1548 * \param[in] rec buffer storing value
1549 * \param[in] key key
1550 * \param[in] th transaction handle
1552 * \retval 0 on success
1553 * \retval negative negated errno on error
1555 int (*dio_declare_insert)(const struct lu_env *env,
1556 struct dt_object *dt,
1557 const struct dt_rec *rec,
1558 const struct dt_key *key,
1559 struct thandle *th);
1562 * Insert a new key/value pair into an index.
1564 * The method inserts specified key/value pair into the given index
1565 * object. The internal consistency is maintained by the method or
1566 * the functionality below. The format and size of key/value should
1567 * have been negotiated before using ->do_index_try(), no additional
1568 * information can be specified to the method. The keys are unique
1571 * \param[in] env execution environment for this thread
1572 * \param[in] dt object
1573 * \param[in] rec buffer storing value
1574 * \param[in] key key
1575 * \param[in] th transaction handle
1577 * \retval 0 on success
1578 * \retval negative negated errno on error
1580 int (*dio_insert)(const struct lu_env *env,
1581 struct dt_object *dt,
1582 const struct dt_rec *rec,
1583 const struct dt_key *key,
1584 struct thandle *th);
1587 * Declare intention to delete a key/value from an index.
1589 * Notify the underlying filesystem that key/value may be deleted in
1590 * this transaction. This enables the layer below to prepare resources
1591 * (e.g. journal credits in ext4). This method should be called
1592 * between creating the transaction and starting it. Key/value format
1593 * and size is subject to ->do_index_try(). The object need not exist.
1595 * \param[in] env execution environment for this thread
1596 * \param[in] dt object
1597 * \param[in] key key
1598 * \param[in] th transaction handle
1600 * \retval 0 on success
1601 * \retval negative negated errno on error
1603 int (*dio_declare_delete)(const struct lu_env *env,
1604 struct dt_object *dt,
1605 const struct dt_key *key,
1606 struct thandle *th);
1609 * Delete key/value pair from an index.
1611 * The method deletes specified key and corresponding value from the
1612 * given index object. The internal consistency is maintained by the
1613 * method or the functionality below. The format and size of the key
1614 * should have been negotiated before using ->do_index_try(), no
1615 * additional information can be specified to the method.
1617 * \param[in] env execution environment for this thread
1618 * \param[in] dt object
1619 * \param[in] key key
1620 * \param[in] th transaction handle
1622 * \retval 0 on success
1623 * \retval negative negated errno on error
1625 int (*dio_delete)(const struct lu_env *env,
1626 struct dt_object *dt,
1627 const struct dt_key *key,
1628 struct thandle *th);
1631 * Iterator interface.
1633 * Methods to iterate over an existing index, list the keys stored and
1634 * associated values, get key/value size, etc.
1638 * Allocate and initialize new iterator.
1640 * The iterator is a handler to be used in the subsequent
1641 * methods to access index's content. Note the position is
1642 * not defined at this point and should be initialized with
1643 * ->get() or ->load() method.
1645 * \param[in] env execution environment for this thread
1646 * \param[in] dt object
1647 * \param[in] attr ask the iterator to return part of
1648 the records, see LUDA_* for details
1650 * \retval pointer iterator pointer on success
1651 * \retval ERR_PTR(errno) on error
1653 struct dt_it *(*init)(const struct lu_env *env,
1654 struct dt_object *dt,
1660 * Release the specified iterator and all the resources
1661 * associated (e.g. the object, index cache, etc).
1663 * \param[in] env execution environment for this thread
1664 * \param[in] di iterator to release
1666 void (*fini)(const struct lu_env *env,
1670 * Move position of iterator.
1672 * Move the position of the specified iterator to the specified
1675 * \param[in] env execution environment for this thread
1676 * \param[in] di iterator
1677 * \param[in] key key to position to
1679 * \retval 0 if exact key is found
1680 * \retval 1 if at the record with least key
1681 * not larger than the key
1682 * \retval negative negated errno on error
1684 int (*get)(const struct lu_env *env,
1686 const struct dt_key *key);
1691 * Complimentary method for dt_it_ops::get() above. Some
1692 * implementation can increase a reference on the iterator in
1693 * dt_it_ops::get(). So the caller should be able to release
1694 * with dt_it_ops::put().
1696 * \param[in] env execution environment for this thread
1697 * \param[in] di iterator
1699 void (*put)(const struct lu_env *env,
1703 * Move to next record.
1705 * Moves the position of the iterator to a next record
1707 * \param[in] env execution environment for this thread
1708 * \param[in] di iterator
1710 * \retval 1 if no more records
1711 * \retval 0 on success, the next record is found
1712 * \retval negative negated errno on error
1714 int (*next)(const struct lu_env *env,
1720 * Returns a pointer to a buffer containing the key of the
1721 * record at the current position. The pointer is valid and
1722 * retains data until ->get(), ->load() and ->fini() methods
1725 * \param[in] env execution environment for this thread
1726 * \param[in] di iterator
1728 * \retval pointer to key on success
1729 * \retval ERR_PTR(errno) on error
1731 struct dt_key *(*key)(const struct lu_env *env,
1732 const struct dt_it *di);
1737 * Returns size of the key at the current position.
1739 * \param[in] env execution environment for this thread
1740 * \param[in] di iterator
1742 * \retval key's size on success
1743 * \retval negative negated errno on error
1745 int (*key_size)(const struct lu_env *env,
1746 const struct dt_it *di);
1751 * Stores the value of the record at the current position. The
1752 * buffer must be big enough (as negotiated with
1753 * ->do_index_try() or ->rec_size()). The caller can specify
1754 * she is interested only in part of the record, using attr
1755 * argument (see LUDA_* definitions for the details).
1757 * \param[in] env execution environment for this thread
1758 * \param[in] di iterator
1759 * \param[out] rec buffer to store value in
1760 * \param[in] attr specify part of the value to copy
1762 * \retval 0 on success
1763 * \retval negative negated errno on error
1765 int (*rec)(const struct lu_env *env,
1766 const struct dt_it *di,
1771 * Return record size.
1773 * Returns size of the record at the current position. The
1774 * \a attr can be used to specify only the parts of the record
1775 * needed to be returned. (see LUDA_* definitions for the
1778 * \param[in] env execution environment for this thread
1779 * \param[in] di iterator
1780 * \param[in] attr part of the record to return
1782 * \retval record's size on success
1783 * \retval negative negated errno on error
1785 int (*rec_size)(const struct lu_env *env,
1786 const struct dt_it *di,
1790 * Return a cookie (hash).
1792 * Returns the cookie (usually hash) of the key at the current
1793 * position. This allows the caller to resume iteration at this
1794 * position later. The exact value is specific to implementation
1795 * and should not be interpreted by the caller.
1797 * \param[in] env execution environment for this thread
1798 * \param[in] di iterator
1800 * \retval cookie/hash of the key
1802 __u64 (*store)(const struct lu_env *env,
1803 const struct dt_it *di);
1806 * Initialize position using cookie/hash.
1808 * Initializes the current position of the iterator to one
1809 * described by the cookie/hash as returned by ->store()
1812 * \param[in] env execution environment for this thread
1813 * \param[in] di iterator
1814 * \param[in] hash cookie/hash value
1816 * \retval positive if current position points to
1817 * record with least cookie not larger
1819 * \retval 0 if current position matches cookie
1820 * \retval negative negated errno on error
1822 int (*load)(const struct lu_env *env,
1823 const struct dt_it *di,
1829 int (*key_rec)(const struct lu_env *env,
1830 const struct dt_it *di,
1835 enum dt_otable_it_valid {
1836 DOIV_ERROR_HANDLE = 0x0001,
1837 DOIV_DRYRUN = 0x0002,
1840 enum dt_otable_it_flags {
1841 /* Exit when fail. */
1842 DOIF_FAILOUT = 0x0001,
1844 /* Reset iteration position to the device beginning. */
1845 DOIF_RESET = 0x0002,
1847 /* There is up layer component uses the iteration. */
1848 DOIF_OUTUSED = 0x0004,
1850 /* Check only without repairing. */
1851 DOIF_DRYRUN = 0x0008,
1854 /* otable based iteration needs to use the common DT iteration APIs.
1855 * To initialize the iteration, it needs call dio_it::init() firstly.
1856 * Here is how the otable based iteration should prepare arguments to
1857 * call dt_it_ops::init().
1859 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1860 * is composed of two parts:
1861 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1862 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1863 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1866 struct lu_device dd_lu_dev;
1867 const struct dt_device_operations *dd_ops;
1870 * List of dt_txn_callback (see below). This is not protected in any
1871 * way, because callbacks are supposed to be added/deleted only during
1872 * single-threaded start-up shut-down procedures.
1874 struct list_head dd_txn_callbacks;
1875 unsigned int dd_record_fid_accessed:1,
1878 /* sysfs and debugfs handling */
1879 struct dentry *dd_debugfs_entry;
1881 const struct attribute **dd_def_attrs;
1882 struct kobject dd_kobj;
1883 struct kobj_type dd_ktype;
1884 struct completion dd_kobj_unregister;
1887 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1888 void dt_device_fini(struct dt_device *dev);
1890 static inline int lu_device_is_dt(const struct lu_device *d)
1892 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1895 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1897 LASSERT(lu_device_is_dt(l));
1898 return container_of_safe(l, struct dt_device, dd_lu_dev);
1902 struct lu_object do_lu;
1903 const struct dt_object_operations *do_ops;
1904 const struct dt_body_operations *do_body_ops;
1905 const struct dt_index_operations *do_index_ops;
1909 * In-core representation of per-device local object OID storage
1911 struct local_oid_storage {
1912 /* all initialized llog systems on this node linked by this */
1913 struct list_head los_list;
1915 /* how many handle's reference this los has */
1916 atomic_t los_refcount;
1917 struct dt_device *los_dev;
1918 struct dt_object *los_obj;
1920 /* data used to generate new fids */
1921 struct mutex los_id_lock;
1926 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1928 return &d->dd_lu_dev;
1931 static inline struct dt_object *lu2dt(struct lu_object *l)
1933 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1934 return container_of_safe(l, struct dt_object, do_lu);
1937 int dt_object_init(struct dt_object *obj,
1938 struct lu_object_header *h, struct lu_device *d);
1940 void dt_object_fini(struct dt_object *obj);
1942 static inline int dt_object_exists(const struct dt_object *dt)
1944 return lu_object_exists(&dt->do_lu);
1947 static inline int dt_object_remote(const struct dt_object *dt)
1949 return lu_object_remote(&dt->do_lu);
1952 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1954 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1955 return container_of_safe(o, struct dt_object, do_lu);
1958 static inline struct dt_object *dt_object_child(struct dt_object *o)
1960 return container_of(lu_object_next(&(o)->do_lu),
1961 struct dt_object, do_lu);
1965 * This is the general purpose transaction handle.
1966 * 1. Transaction Life Cycle
1967 * This transaction handle is allocated upon starting a new transaction,
1968 * and deallocated after this transaction is committed.
1969 * 2. Transaction Nesting
1970 * We do _NOT_ support nested transaction. So, every thread should only
1971 * have one active transaction, and a transaction only belongs to one
1972 * thread. Due to this, transaction handle need no reference count.
1973 * 3. Transaction & dt_object locking
1974 * dt_object locks should be taken inside transaction.
1975 * 4. Transaction & RPC
1976 * No RPC request should be issued inside transaction.
1979 /** the dt device on which the transactions are executed */
1980 struct dt_device *th_dev;
1982 /* point to the top thandle, XXX this is a bit hacky right now,
1983 * but normal device trans callback triggered by the bottom
1984 * device (OSP/OSD == sub thandle layer) needs to get the
1985 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1986 * top thandle here for now, will fix it when we have better
1987 * callback mechanism */
1988 struct thandle *th_top;
1990 /** the last operation result in this transaction.
1991 * this value is used in recovery */
1994 /** whether we need sync commit */
1995 unsigned int th_sync:1,
1996 /* local transation, no need to inform other layers */
1998 /* Whether we need wait the transaction to be submitted
1999 * (send to remote target) */
2001 /* complex transaction which will track updates on all targets,
2004 /* whether ignore quota */
2006 /* whether restart transaction */
2011 * Transaction call-backs.
2013 * These are invoked by osd (or underlying transaction engine) when
2014 * transaction changes state.
2016 * Call-backs are used by upper layers to modify transaction parameters and to
2017 * perform some actions on for each transaction state transition. Typical
2018 * example is mdt registering call-back to write into last-received file
2019 * before each transaction commit.
2021 struct dt_txn_callback {
2022 int (*dtc_txn_start)(const struct lu_env *env,
2023 struct thandle *txn, void *cookie);
2024 int (*dtc_txn_stop)(const struct lu_env *env,
2025 struct thandle *txn, void *cookie);
2028 struct list_head dtc_linkage;
2031 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
2032 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
2034 int dt_txn_hook_start(const struct lu_env *env,
2035 struct dt_device *dev, struct thandle *txn);
2036 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
2038 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
2041 * Callback function used for parsing path.
2042 * \see llo_store_resolve
2044 typedef int (*dt_entry_func_t)(const struct lu_env *env,
2048 #define DT_MAX_PATH 1024
2050 int dt_path_parser(const struct lu_env *env,
2051 char *local, dt_entry_func_t entry_func,
2055 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
2056 const char *path, struct lu_fid *fid);
2058 struct dt_object *dt_store_open(const struct lu_env *env,
2059 struct dt_device *dt,
2060 const char *dirname,
2061 const char *filename,
2062 struct lu_fid *fid);
2064 struct dt_object *dt_find_or_create(const struct lu_env *env,
2065 struct dt_device *dt,
2066 const struct lu_fid *fid,
2067 struct dt_object_format *dof,
2068 struct lu_attr *attr);
2070 struct dt_object *dt_locate_at(const struct lu_env *env,
2071 struct dt_device *dev,
2072 const struct lu_fid *fid,
2073 struct lu_device *top_dev,
2074 const struct lu_object_conf *conf);
2076 static inline struct dt_object *
2077 dt_locate(const struct lu_env *env, struct dt_device *dev,
2078 const struct lu_fid *fid)
2080 return dt_locate_at(env, dev, fid,
2081 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2084 static inline struct dt_object *
2085 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2087 struct lu_object *lo;
2089 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2090 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2091 return container_of(lo, struct dt_object, do_lu);
2096 static inline void dt_object_put(const struct lu_env *env,
2097 struct dt_object *dto)
2099 lu_object_put(env, &dto->do_lu);
2102 static inline void dt_object_put_nocache(const struct lu_env *env,
2103 struct dt_object *dto)
2105 lu_object_put_nocache(env, &dto->do_lu);
2108 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2109 const struct lu_fid *first_fid,
2110 struct local_oid_storage **los);
2111 void local_oid_storage_fini(const struct lu_env *env,
2112 struct local_oid_storage *los);
2113 int local_object_fid_generate(const struct lu_env *env,
2114 struct local_oid_storage *los,
2115 struct lu_fid *fid);
2116 int local_object_declare_create(const struct lu_env *env,
2117 struct local_oid_storage *los,
2118 struct dt_object *o,
2119 struct lu_attr *attr,
2120 struct dt_object_format *dof,
2121 struct thandle *th);
2122 int local_object_create(const struct lu_env *env,
2123 struct local_oid_storage *los,
2124 struct dt_object *o,
2125 struct lu_attr *attr, struct dt_object_format *dof,
2126 struct thandle *th);
2127 struct dt_object *local_file_find(const struct lu_env *env,
2128 struct local_oid_storage *los,
2129 struct dt_object *parent,
2131 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2132 struct local_oid_storage *los,
2133 struct dt_object *parent,
2134 const char *name, __u32 mode);
2135 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2136 struct dt_device *dt,
2137 const struct lu_fid *fid,
2138 struct dt_object *parent,
2142 local_index_find_or_create(const struct lu_env *env,
2143 struct local_oid_storage *los,
2144 struct dt_object *parent,
2145 const char *name, __u32 mode,
2146 const struct dt_index_features *ft);
2148 local_index_find_or_create_with_fid(const struct lu_env *env,
2149 struct dt_device *dt,
2150 const struct lu_fid *fid,
2151 struct dt_object *parent,
2152 const char *name, __u32 mode,
2153 const struct dt_index_features *ft);
2154 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2155 struct dt_object *parent, const char *name);
2157 static inline int dt_object_lock(const struct lu_env *env,
2158 struct dt_object *o, struct lustre_handle *lh,
2159 struct ldlm_enqueue_info *einfo,
2160 union ldlm_policy_data *policy)
2163 LASSERT(o->do_ops != NULL);
2164 LASSERT(o->do_ops->do_object_lock != NULL);
2165 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2168 static inline int dt_object_unlock(const struct lu_env *env,
2169 struct dt_object *o,
2170 struct ldlm_enqueue_info *einfo,
2171 union ldlm_policy_data *policy)
2174 LASSERT(o->do_ops != NULL);
2175 LASSERT(o->do_ops->do_object_unlock != NULL);
2176 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2179 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2180 const char *name, struct lu_fid *fid);
2182 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2183 __u64 start, __u64 end)
2187 LASSERT(o->do_ops->do_object_sync);
2188 return o->do_ops->do_object_sync(env, o, start, end);
2191 static inline int dt_fid_alloc(const struct lu_env *env,
2192 struct dt_device *d,
2194 struct lu_object *parent,
2195 const struct lu_name *name)
2197 struct lu_device *l = dt2lu_dev(d);
2199 return l->ld_ops->ldo_fid_alloc(env, l, fid, parent, name);
2202 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2203 struct thandle *th);
2204 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2205 dt_obj_version_t version, struct thandle *th);
2206 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2209 int dt_read(const struct lu_env *env, struct dt_object *dt,
2210 struct lu_buf *buf, loff_t *pos);
2211 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2212 struct lu_buf *buf, loff_t *pos);
2213 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2214 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2215 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2216 union lu_page *lp, size_t nob,
2217 const struct dt_it_ops *iops,
2218 struct dt_it *it, __u32 attr, void *arg);
2219 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2220 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2222 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2223 struct idx_info *ii, const struct lu_rdpg *rdpg);
2225 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2226 struct dt_device *d)
2228 LASSERT(d->dd_ops->dt_trans_create);
2229 return d->dd_ops->dt_trans_create(env, d);
2232 static inline int dt_trans_start(const struct lu_env *env,
2233 struct dt_device *d, struct thandle *th)
2235 LASSERT(d->dd_ops->dt_trans_start);
2236 return d->dd_ops->dt_trans_start(env, d, th);
2239 /* for this transaction hooks shouldn't be called */
2240 static inline int dt_trans_start_local(const struct lu_env *env,
2241 struct dt_device *d, struct thandle *th)
2243 LASSERT(d->dd_ops->dt_trans_start);
2245 return d->dd_ops->dt_trans_start(env, d, th);
2248 static inline int dt_trans_stop(const struct lu_env *env,
2249 struct dt_device *d, struct thandle *th)
2251 LASSERT(d->dd_ops->dt_trans_stop);
2252 return d->dd_ops->dt_trans_stop(env, d, th);
2255 static inline int dt_trans_cb_add(struct thandle *th,
2256 struct dt_txn_commit_cb *dcb)
2258 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2259 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2260 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2265 static inline int dt_declare_record_write(const struct lu_env *env,
2266 struct dt_object *dt,
2267 const struct lu_buf *buf,
2273 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2274 LASSERT(th != NULL);
2275 LASSERTF(dt->do_body_ops, DFID" doesn't exit\n",
2276 PFID(lu_object_fid(&dt->do_lu)));
2277 LASSERT(dt->do_body_ops->dbo_declare_write);
2278 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2282 static inline int dt_declare_create(const struct lu_env *env,
2283 struct dt_object *dt,
2284 struct lu_attr *attr,
2285 struct dt_allocation_hint *hint,
2286 struct dt_object_format *dof,
2290 LASSERT(dt->do_ops);
2291 LASSERT(dt->do_ops->do_declare_create);
2293 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2294 return cfs_fail_err;
2296 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2299 static inline int dt_create(const struct lu_env *env,
2300 struct dt_object *dt,
2301 struct lu_attr *attr,
2302 struct dt_allocation_hint *hint,
2303 struct dt_object_format *dof,
2307 LASSERT(dt->do_ops);
2308 LASSERT(dt->do_ops->do_create);
2310 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2311 return cfs_fail_err;
2313 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2316 static inline int dt_declare_destroy(const struct lu_env *env,
2317 struct dt_object *dt,
2321 LASSERT(dt->do_ops);
2322 LASSERT(dt->do_ops->do_declare_destroy);
2324 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2325 return cfs_fail_err;
2327 return dt->do_ops->do_declare_destroy(env, dt, th);
2330 static inline int dt_destroy(const struct lu_env *env,
2331 struct dt_object *dt,
2335 LASSERT(dt->do_ops);
2336 LASSERT(dt->do_ops->do_destroy);
2338 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2339 return cfs_fail_err;
2341 return dt->do_ops->do_destroy(env, dt, th);
2344 static inline void dt_read_lock(const struct lu_env *env,
2345 struct dt_object *dt,
2349 LASSERT(dt->do_ops);
2350 LASSERT(dt->do_ops->do_read_lock);
2351 dt->do_ops->do_read_lock(env, dt, role);
2354 static inline void dt_write_lock(const struct lu_env *env,
2355 struct dt_object *dt,
2359 LASSERT(dt->do_ops);
2360 LASSERT(dt->do_ops->do_write_lock);
2361 dt->do_ops->do_write_lock(env, dt, role);
2364 static inline void dt_read_unlock(const struct lu_env *env,
2365 struct dt_object *dt)
2368 LASSERT(dt->do_ops);
2369 LASSERT(dt->do_ops->do_read_unlock);
2370 dt->do_ops->do_read_unlock(env, dt);
2373 static inline void dt_write_unlock(const struct lu_env *env,
2374 struct dt_object *dt)
2377 LASSERT(dt->do_ops);
2378 LASSERT(dt->do_ops->do_write_unlock);
2379 dt->do_ops->do_write_unlock(env, dt);
2382 static inline int dt_write_locked(const struct lu_env *env,
2383 struct dt_object *dt)
2386 LASSERT(dt->do_ops);
2387 LASSERT(dt->do_ops->do_write_locked);
2388 return dt->do_ops->do_write_locked(env, dt);
2391 static inline bool dt_object_stale(struct dt_object *dt)
2394 LASSERT(dt->do_ops);
2395 LASSERT(dt->do_ops->do_check_stale);
2397 return dt->do_ops->do_check_stale(dt);
2400 static inline int dt_declare_attr_get(const struct lu_env *env,
2401 struct dt_object *dt)
2404 LASSERT(dt->do_ops);
2405 LASSERT(dt->do_ops->do_declare_attr_get);
2407 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2408 return cfs_fail_err;
2410 return dt->do_ops->do_declare_attr_get(env, dt);
2413 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2417 LASSERT(dt->do_ops);
2418 LASSERT(dt->do_ops->do_attr_get);
2420 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2421 return cfs_fail_err;
2423 return dt->do_ops->do_attr_get(env, dt, la);
2426 static inline int dt_declare_attr_set(const struct lu_env *env,
2427 struct dt_object *dt,
2428 const struct lu_attr *la,
2432 LASSERT(dt->do_ops);
2433 LASSERT(dt->do_ops->do_declare_attr_set);
2435 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2436 return cfs_fail_err;
2438 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2441 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2442 const struct lu_attr *la, struct thandle *th)
2445 LASSERT(dt->do_ops);
2446 LASSERT(dt->do_ops->do_attr_set);
2448 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2449 return cfs_fail_err;
2451 return dt->do_ops->do_attr_set(env, dt, la, th);
2454 static inline int dt_declare_ref_add(const struct lu_env *env,
2455 struct dt_object *dt, struct thandle *th)
2458 LASSERT(dt->do_ops);
2459 LASSERT(dt->do_ops->do_declare_ref_add);
2461 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2462 return cfs_fail_err;
2464 return dt->do_ops->do_declare_ref_add(env, dt, th);
2467 static inline int dt_ref_add(const struct lu_env *env,
2468 struct dt_object *dt, struct thandle *th)
2471 LASSERT(dt->do_ops);
2472 LASSERT(dt->do_ops->do_ref_add);
2474 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2475 return cfs_fail_err;
2477 return dt->do_ops->do_ref_add(env, dt, th);
2480 static inline int dt_declare_ref_del(const struct lu_env *env,
2481 struct dt_object *dt, struct thandle *th)
2484 LASSERT(dt->do_ops);
2485 LASSERT(dt->do_ops->do_declare_ref_del);
2487 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2488 return cfs_fail_err;
2490 return dt->do_ops->do_declare_ref_del(env, dt, th);
2493 static inline int dt_ref_del(const struct lu_env *env,
2494 struct dt_object *dt, struct thandle *th)
2497 LASSERT(dt->do_ops);
2498 LASSERT(dt->do_ops->do_ref_del);
2500 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2501 return cfs_fail_err;
2503 return dt->do_ops->do_ref_del(env, dt, th);
2506 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2507 struct niobuf_remote *rnb,
2508 struct niobuf_local *lnb, int maxlnb,
2509 enum dt_bufs_type rw)
2512 LASSERT(d->do_body_ops);
2513 LASSERT(d->do_body_ops->dbo_bufs_get);
2514 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2515 rnb->rnb_len, lnb, maxlnb, rw);
2518 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2519 struct niobuf_local *lnb, int n)
2522 LASSERT(d->do_body_ops);
2523 LASSERT(d->do_body_ops->dbo_bufs_put);
2524 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2527 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2528 struct niobuf_local *lnb, int n)
2531 LASSERT(d->do_body_ops);
2532 LASSERT(d->do_body_ops->dbo_write_prep);
2533 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2536 static inline int dt_declare_write_commit(const struct lu_env *env,
2537 struct dt_object *d,
2538 struct niobuf_local *lnb,
2539 int n, struct thandle *th)
2541 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2542 LASSERT(th != NULL);
2543 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2547 static inline int dt_write_commit(const struct lu_env *env,
2548 struct dt_object *d, struct niobuf_local *lnb,
2549 int n, struct thandle *th, __u64 size)
2552 LASSERT(d->do_body_ops);
2553 LASSERT(d->do_body_ops->dbo_write_commit);
2554 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th, size);
2557 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2558 struct niobuf_local *lnb, int n)
2561 LASSERT(d->do_body_ops);
2562 LASSERT(d->do_body_ops->dbo_read_prep);
2563 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2566 static inline int dt_declare_write(const struct lu_env *env,
2567 struct dt_object *dt,
2568 const struct lu_buf *buf, loff_t pos,
2572 LASSERT(dt->do_body_ops);
2573 LASSERT(dt->do_body_ops->dbo_declare_write);
2574 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2577 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2578 const struct lu_buf *buf, loff_t *pos,
2582 LASSERT(dt->do_body_ops);
2583 LASSERT(dt->do_body_ops->dbo_write);
2584 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2587 static inline int dt_declare_punch(const struct lu_env *env,
2588 struct dt_object *dt, __u64 start,
2589 __u64 end, struct thandle *th)
2592 LASSERT(dt->do_body_ops);
2593 LASSERT(dt->do_body_ops->dbo_declare_punch);
2594 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2597 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2598 __u64 start, __u64 end, struct thandle *th)
2601 LASSERT(dt->do_body_ops);
2602 LASSERT(dt->do_body_ops->dbo_punch);
2603 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2606 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2607 __u64 start, __u64 end, int advice)
2610 LASSERT(dt->do_body_ops);
2611 LASSERT(dt->do_body_ops->dbo_ladvise);
2612 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2615 static inline int dt_declare_fallocate(const struct lu_env *env,
2616 struct dt_object *dt, __u64 start,
2617 __u64 end, int mode, struct thandle *th)
2620 if (!dt->do_body_ops)
2622 LASSERT(dt->do_body_ops);
2623 LASSERT(dt->do_body_ops->dbo_declare_fallocate);
2624 return dt->do_body_ops->dbo_declare_fallocate(env, dt, start, end,
2628 static inline int dt_falloc(const struct lu_env *env, struct dt_object *dt,
2629 __u64 start, __u64 end, int mode,
2633 if (!dt->do_body_ops)
2635 LASSERT(dt->do_body_ops);
2636 LASSERT(dt->do_body_ops->dbo_fallocate);
2637 return dt->do_body_ops->dbo_fallocate(env, dt, start, end, mode, th);
2640 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2644 if (d->do_body_ops == NULL)
2646 if (d->do_body_ops->dbo_fiemap_get == NULL)
2648 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2651 static inline loff_t dt_lseek(const struct lu_env *env, struct dt_object *d,
2652 loff_t offset, int whence)
2655 if (d->do_body_ops == NULL)
2657 if (d->do_body_ops->dbo_lseek == NULL)
2659 return d->do_body_ops->dbo_lseek(env, d, offset, whence);
2662 static inline int dt_statfs_info(const struct lu_env *env,
2663 struct dt_device *dev,
2664 struct obd_statfs *osfs,
2665 struct obd_statfs_info *info)
2668 LASSERT(dev->dd_ops);
2669 LASSERT(dev->dd_ops->dt_statfs);
2670 return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2673 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2674 struct obd_statfs *osfs)
2676 return dt_statfs_info(env, dev, osfs, NULL);
2679 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2683 LASSERT(dev->dd_ops);
2684 LASSERT(dev->dd_ops->dt_root_get);
2685 return dev->dd_ops->dt_root_get(env, dev, f);
2688 static inline void dt_conf_get(const struct lu_env *env,
2689 const struct dt_device *dev,
2690 struct dt_device_param *param)
2693 LASSERT(dev->dd_ops);
2694 LASSERT(dev->dd_ops->dt_conf_get);
2695 return dev->dd_ops->dt_conf_get(env, dev, param);
2698 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2701 LASSERT(dev->dd_ops);
2702 if (dev->dd_ops->dt_mnt_sb_get)
2703 return dev->dd_ops->dt_mnt_sb_get(dev);
2705 return ERR_PTR(-EOPNOTSUPP);
2708 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2711 LASSERT(dev->dd_ops);
2712 LASSERT(dev->dd_ops->dt_sync);
2713 return dev->dd_ops->dt_sync(env, dev);
2716 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2719 LASSERT(dev->dd_ops);
2720 LASSERT(dev->dd_ops->dt_ro);
2721 return dev->dd_ops->dt_ro(env, dev);
2724 static inline int dt_declare_insert(const struct lu_env *env,
2725 struct dt_object *dt,
2726 const struct dt_rec *rec,
2727 const struct dt_key *key,
2731 LASSERT(dt->do_index_ops);
2732 LASSERT(dt->do_index_ops->dio_declare_insert);
2734 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2735 return cfs_fail_err;
2737 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2740 static inline int dt_insert(const struct lu_env *env,
2741 struct dt_object *dt,
2742 const struct dt_rec *rec,
2743 const struct dt_key *key,
2747 LASSERT(dt->do_index_ops);
2748 LASSERT(dt->do_index_ops->dio_insert);
2750 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2751 return cfs_fail_err;
2753 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2756 static inline int dt_declare_xattr_del(const struct lu_env *env,
2757 struct dt_object *dt,
2762 LASSERT(dt->do_ops);
2763 LASSERT(dt->do_ops->do_declare_xattr_del);
2765 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2766 return cfs_fail_err;
2768 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2771 static inline int dt_xattr_del(const struct lu_env *env,
2772 struct dt_object *dt, const char *name,
2776 LASSERT(dt->do_ops);
2777 LASSERT(dt->do_ops->do_xattr_del);
2779 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2780 return cfs_fail_err;
2782 return dt->do_ops->do_xattr_del(env, dt, name, th);
2785 static inline int dt_declare_xattr_set(const struct lu_env *env,
2786 struct dt_object *dt,
2787 const struct lu_buf *buf,
2788 const char *name, int fl,
2792 LASSERT(dt->do_ops);
2793 LASSERT(dt->do_ops->do_declare_xattr_set);
2795 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2796 return cfs_fail_err;
2798 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2801 static inline int dt_xattr_set(const struct lu_env *env,
2802 struct dt_object *dt, const struct lu_buf *buf,
2803 const char *name, int fl, struct thandle *th)
2806 LASSERT(dt->do_ops);
2807 LASSERT(dt->do_ops->do_xattr_set);
2809 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2810 return cfs_fail_err;
2812 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2815 static inline int dt_declare_xattr_get(const struct lu_env *env,
2816 struct dt_object *dt,
2821 LASSERT(dt->do_ops);
2822 LASSERT(dt->do_ops->do_declare_xattr_get);
2824 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2825 return cfs_fail_err;
2827 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2830 static inline int dt_xattr_get(const struct lu_env *env,
2831 struct dt_object *dt, struct lu_buf *buf,
2835 LASSERT(dt->do_ops);
2836 LASSERT(dt->do_ops->do_xattr_get);
2838 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2839 return cfs_fail_err;
2841 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2844 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2845 const struct lu_buf *buf)
2848 LASSERT(dt->do_ops);
2849 LASSERT(dt->do_ops->do_xattr_list);
2851 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2852 return cfs_fail_err;
2854 return dt->do_ops->do_xattr_list(env, dt, buf);
2857 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2860 LASSERT(dt->do_ops);
2861 LASSERT(dt->do_ops->do_invalidate);
2863 return dt->do_ops->do_invalidate(env, dt);
2866 static inline int dt_declare_delete(const struct lu_env *env,
2867 struct dt_object *dt,
2868 const struct dt_key *key,
2872 LASSERT(dt->do_index_ops);
2873 LASSERT(dt->do_index_ops->dio_declare_delete);
2875 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2876 return cfs_fail_err;
2878 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2881 static inline int dt_delete(const struct lu_env *env,
2882 struct dt_object *dt,
2883 const struct dt_key *key,
2887 LASSERT(dt->do_index_ops);
2888 LASSERT(dt->do_index_ops->dio_delete);
2890 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2891 return cfs_fail_err;
2893 return dt->do_index_ops->dio_delete(env, dt, key, th);
2896 static inline int dt_commit_async(const struct lu_env *env,
2897 struct dt_device *dev)
2900 LASSERT(dev->dd_ops);
2901 LASSERT(dev->dd_ops->dt_commit_async);
2902 return dev->dd_ops->dt_commit_async(env, dev);
2905 static inline int dt_lookup(const struct lu_env *env,
2906 struct dt_object *dt,
2908 const struct dt_key *key)
2913 LASSERT(dt->do_index_ops);
2914 LASSERT(dt->do_index_ops->dio_lookup);
2916 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2917 return cfs_fail_err;
2919 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2927 static inline int dt_declare_layout_change(const struct lu_env *env,
2928 struct dt_object *o,
2929 struct md_layout_change *mlc,
2934 LASSERT(o->do_ops->do_declare_layout_change);
2935 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2938 static inline int dt_layout_change(const struct lu_env *env,
2939 struct dt_object *o,
2940 struct md_layout_change *mlc,
2945 LASSERT(o->do_ops->do_layout_change);
2946 return o->do_ops->do_layout_change(env, o, mlc, th);
2949 struct dt_find_hint {
2950 struct lu_fid *dfh_fid;
2951 struct dt_device *dfh_dt;
2952 struct dt_object *dfh_o;
2955 struct dt_insert_rec {
2957 const struct lu_fid *rec_fid;
2969 struct dt_thread_info {
2970 char dti_buf[DT_MAX_PATH];
2971 struct dt_find_hint dti_dfh;
2972 struct lu_attr dti_attr;
2973 struct lu_fid dti_fid;
2974 struct dt_object_format dti_dof;
2975 struct lustre_mdt_attrs dti_lma;
2976 struct lu_buf dti_lb;
2977 struct lu_object_conf dti_conf;
2979 struct dt_insert_rec dti_dt_rec;
2982 extern struct lu_context_key dt_key;
2984 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2986 struct dt_thread_info *dti;
2988 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2993 int dt_global_init(void);
2994 void dt_global_fini(void);
2995 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2996 const char *name, struct ldebugfs_vars *list);
2997 int dt_tunables_fini(struct dt_device *dt);
2999 # ifdef CONFIG_PROC_FS
3000 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
3001 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
3002 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
3003 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
3004 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
3005 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
3006 # endif /* CONFIG_PROC_FS */
3008 #endif /* __LUSTRE_DT_OBJECT_H */