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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #ifndef __LUSTRE_DT_OBJECT_H
34 #define __LUSTRE_DT_OBJECT_H
37 * Sub-class of lu_object with methods common for "data" objects in OST stack.
39 * Data objects behave like regular files: you can read/write them, get and
40 * set their attributes. Implementation of dt interface is supposed to
41 * implement some form of garbage collection, normally reference counting
44 * Examples: osd (lustre/osd) is an implementation of dt interface.
48 #include <obd_support.h>
50 * super-class definitions.
52 #include <lu_object.h>
54 #include <libcfs/libcfs.h>
57 struct proc_dir_entry;
63 struct dt_index_features;
66 struct ldlm_enqueue_info;
69 MNTOPT_USERXATTR = 0x00000001,
70 MNTOPT_ACL = 0x00000002,
73 struct dt_device_param {
74 unsigned ddp_max_name_len;
75 unsigned ddp_max_nlink;
76 unsigned ddp_symlink_max;
78 unsigned ddp_max_ea_size;
79 unsigned ddp_mount_type;
80 unsigned long long ddp_maxbytes;
81 /* per-inode space consumption */
83 /* maximum number of blocks in an extent */
84 unsigned ddp_max_extent_blks;
85 /* per-extent insertion overhead to be used by client for grant
87 unsigned int ddp_extent_tax;
88 unsigned int ddp_brw_size; /* optimal RPC size */
89 /* T10PI checksum type, zero if not supported */
90 enum cksum_types ddp_t10_cksum_type;
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);
139 * Create transaction.
141 * Create in-memory structure representing the transaction for the
142 * caller. The structure returned will be used by the calling thread
143 * to specify the transaction the updates belong to. Once created
144 * successfully ->dt_trans_stop() must be called in any case (with
145 * ->dt_trans_start() and updates or not) so that the transaction
146 * handle and other resources can be released by the layers below.
148 * \param[in] env execution environment for this thread
149 * \param[in] dev dt device
151 * \retval pointer to handle if creation succeeds
152 * \retval ERR_PTR(errno) if creation fails
154 struct thandle *(*dt_trans_create)(const struct lu_env *env,
155 struct dt_device *dev);
160 * Start the transaction. The transaction described by \a th can be
161 * started only once. Another start is considered as an error.
162 * A thread is not supposed to start a transaction while another
163 * transaction isn't closed by the thread (though multiple handles
164 * can be created). The caller should start the transaction once
165 * all possible updates are declared (see the ->do_declare_* methods
166 * below) and all the needed resources are reserved.
168 * \param[in] env execution environment for this thread
169 * \param[in] dev dt device
170 * \param[in] th transaction handle
172 * \retval 0 on success
173 * \retval negative negated errno on error
175 int (*dt_trans_start)(const struct lu_env *env,
176 struct dt_device *dev,
182 * Once stopped the transaction described by \a th is complete (all
183 * the needed updates are applied) and further processing such as
184 * flushing to disk, sending to another target, etc, is handled by
185 * lower layers. The caller can't access this transaction by the
186 * handle anymore (except from the commit callbacks, see below).
188 * \param[in] env execution environment for this thread
189 * \param[in] dev dt device
190 * \param[in] th transaction handle
192 * \retval 0 on success
193 * \retval negative negated errno on error
195 int (*dt_trans_stop)(const struct lu_env *env,
196 struct dt_device *dev,
200 * Add commit callback to the transaction.
202 * Add a commit callback to the given transaction handle. The callback
203 * will be called when the associated transaction is stored. I.e. the
204 * transaction will survive an event like power off if the callback did
205 * run. The number of callbacks isn't limited, but you should note that
206 * some disk filesystems do handle the commit callbacks in the thread
207 * handling commit/flush of all the transactions, meaning that new
208 * transactions are blocked from commit and flush until all the
209 * callbacks are done. Also, note multiple callbacks can be running
210 * concurrently using multiple CPU cores. The callbacks will be running
211 * in a special environment which can not be used to pass data around.
213 * \param[in] th transaction handle
214 * \param[in] dcb commit callback description
216 * \retval 0 on success
217 * \retval negative negated errno on error
219 int (*dt_trans_cb_add)(struct thandle *th,
220 struct dt_txn_commit_cb *dcb);
223 * Return FID of root index object.
225 * Return the FID of the root object in the filesystem. This object
226 * is usually provided as a bootstrap point by a disk filesystem.
227 * This is up to the implementation which FID to use, though
228 * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
230 * \param[in] env execution environment for this thread
231 * \param[in] dev dt device
232 * \param[out] fid FID of the root object
234 * \retval 0 on success
235 * \retval negative negated errno on error
237 int (*dt_root_get)(const struct lu_env *env,
238 struct dt_device *dev,
242 * Return device configuration data.
244 * Return device (disk fs, actually) specific configuration.
245 * The configuration isn't subject to change at runtime.
246 * See struct dt_device_param for the details.
248 * \param[in] env execution environment for this thread
249 * \param[in] dev dt device
250 * \param[out] param configuration parameters
252 void (*dt_conf_get)(const struct lu_env *env,
253 const struct dt_device *dev,
254 struct dt_device_param *param);
257 * Return device's super block.
259 * \param[in] dev dt device
261 struct super_block *(*dt_mnt_sb_get)(const struct dt_device *dev);
266 * Sync all the cached state (dirty buffers, pages, etc) to the
267 * persistent storage. The method returns control once the sync is
268 * complete. This operation may incur significant I/O to disk and
269 * should be reserved for cases where a global sync is strictly
272 * \param[in] env execution environment for this thread
273 * \param[in] dev dt device
275 * \retval 0 on success
276 * \retval negative negated errno on error
278 int (*dt_sync)(const struct lu_env *env,
279 struct dt_device *dev);
282 * Make device read-only.
284 * Prevent new modifications to the device. This is a very specific
285 * state where all the changes are accepted successfully and the
286 * commit callbacks are called, but persistent state never changes.
287 * Used only in the tests to simulate power-off scenario.
289 * \param[in] env execution environment for this thread
290 * \param[in] dev dt device
292 * \retval 0 on success
293 * \retval negative negated errno on error
295 int (*dt_ro)(const struct lu_env *env,
296 struct dt_device *dev);
299 * Start transaction commit asynchronously.
302 * Provide a hint to the underlying filesystem that it should start
303 * committing soon. The control returns immediately. It's up to the
304 * layer implementing the method how soon to start committing. Usually
305 * this should be throttled to some extent, otherwise the number of
306 * aggregated transaction goes too high causing performance drop.
308 * \param[in] env execution environment for this thread
309 * \param[in] dev dt device
311 * \retval 0 on success
312 * \retval negative negated errno on error
314 int (*dt_commit_async)(const struct lu_env *env,
315 struct dt_device *dev);
318 struct dt_index_features {
319 /** required feature flags from enum dt_index_flags */
321 /** minimal required key size */
322 size_t dif_keysize_min;
323 /** maximal required key size, 0 if no limit */
324 size_t dif_keysize_max;
325 /** minimal required record size */
326 size_t dif_recsize_min;
327 /** maximal required record size, 0 if no limit */
328 size_t dif_recsize_max;
329 /** pointer size for record */
333 enum dt_index_flags {
334 /** index supports variable sized keys */
335 DT_IND_VARKEY = 1 << 0,
336 /** index supports variable sized records */
337 DT_IND_VARREC = 1 << 1,
338 /** index can be modified */
339 DT_IND_UPDATE = 1 << 2,
340 /** index supports records with non-unique (duplicate) keys */
341 DT_IND_NONUNQ = 1 << 3,
343 * index support fixed-size keys sorted with natural numerical way
344 * and is able to return left-side value if no exact value found
346 DT_IND_RANGE = 1 << 4,
350 * Features, required from index to support file system directories (mapping
353 extern const struct dt_index_features dt_directory_features;
354 extern const struct dt_index_features dt_otable_features;
355 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
356 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
357 extern const struct dt_index_features dt_lfsck_namespace_features;
359 /* index features supported by the accounting objects */
360 extern const struct dt_index_features dt_acct_features;
362 /* index features supported by the quota global indexes */
363 extern const struct dt_index_features dt_quota_glb_features;
365 /* index features supported by the quota slave indexes */
366 extern const struct dt_index_features dt_quota_slv_features;
368 /* index features supported by the nodemap index */
369 extern const struct dt_index_features dt_nodemap_features;
372 * This is a general purpose dt allocation hint.
373 * It now contains the parent object.
374 * It can contain any allocation hint in the future.
376 struct dt_allocation_hint {
377 struct dt_object *dah_parent;
378 const void *dah_eadata;
384 * object type specifier.
387 enum dt_format_type {
392 /** for special index */
394 /** for symbolic link */
399 * object format specifier.
401 struct dt_object_format {
402 /** type for dt object */
403 enum dt_format_type dof_type;
413 * special index need feature as parameter to create
417 const struct dt_index_features *di_feat;
422 enum dt_format_type dt_mode_to_dft(__u32 mode);
424 typedef __u64 dt_obj_version_t;
426 union ldlm_policy_data;
428 struct md_layout_change;
431 * A dt_object provides common operations to create and destroy
432 * objects and to manage regular and extended attributes.
434 struct dt_object_operations {
436 * Get read lock on object.
438 * Read lock is compatible with other read locks, so it's shared.
439 * Read lock is not compatible with write lock which is exclusive.
440 * The lock is blocking and can't be used from an interrupt context.
442 * \param[in] env execution environment for this thread
443 * \param[in] dt object to lock for reading
444 * \param[in] role a hint to debug locks (see kernel's mutexes)
446 void (*do_read_lock)(const struct lu_env *env,
447 struct dt_object *dt,
451 * Get write lock on object.
453 * Write lock is exclusive and cannot be shared. The lock is blocking
454 * and can't be used from an interrupt context.
456 * \param[in] env execution environment for this thread
457 * \param[in] dt object to lock for writing
458 * \param[in] role a hint to debug locks (see kernel's mutexes)
461 void (*do_write_lock)(const struct lu_env *env,
462 struct dt_object *dt,
468 * \param[in] env execution environment for this thread
469 * \param[in] dt object
471 void (*do_read_unlock)(const struct lu_env *env,
472 struct dt_object *dt);
475 * Release write lock.
477 * \param[in] env execution environment for this thread
478 * \param[in] dt object
480 void (*do_write_unlock)(const struct lu_env *env,
481 struct dt_object *dt);
484 * Check whether write lock is held.
486 * The caller can learn whether write lock is held on the object
488 * \param[in] env execution environment for this thread
489 * \param[in] dt object
491 * \retval 0 no write lock
492 * \retval 1 write lock is held
494 int (*do_write_locked)(const struct lu_env *env,
495 struct dt_object *dt);
498 * Declare intention to request reqular attributes.
500 * Notity the underlying filesystem that the caller may request regular
501 * attributes with ->do_attr_get() soon. This allows OSD to implement
502 * prefetching logic in an object-oriented manner. The implementation
503 * can be noop. This method should avoid expensive delays such as
504 * waiting on disk I/O, otherwise the goal of enabling a performance
505 * optimization would be defeated.
507 * \param[in] env execution environment for this thread
508 * \param[in] dt object
510 * \retval 0 on success
511 * \retval negative negated errno on error
513 int (*do_declare_attr_get)(const struct lu_env *env,
514 struct dt_object *dt);
517 * Return regular attributes.
519 * The object must exist. Currently all the attributes should be
520 * returned, but in the future this can be improved so that only
521 * a selected set is returned. This can improve performance as in
522 * some cases attributes are stored in different places and
523 * getting them all can be an iterative and expensive process.
525 * \param[in] env execution environment for this thread
526 * \param[in] dt object
527 * \param[out] attr attributes to fill
529 * \retval 0 on success
530 * \retval negative negated errno on error
532 int (*do_attr_get)(const struct lu_env *env,
533 struct dt_object *dt,
534 struct lu_attr *attr);
537 * Declare intention to change regular object's attributes.
539 * Notify the underlying filesystem that the regular attributes may
540 * change in this transaction. This enables the layer below to prepare
541 * resources (e.g. journal credits in ext4). This method should be
542 * called between creating the transaction and starting it. Note that
543 * the la_valid field of \a attr specifies which attributes will change.
544 * The object need not exist.
546 * \param[in] env execution environment for this thread
547 * \param[in] dt object
548 * \param[in] attr attributes to change specified in attr.la_valid
549 * \param[in] th transaction handle
551 * \retval 0 on success
552 * \retval negative negated errno on error
554 int (*do_declare_attr_set)(const struct lu_env *env,
555 struct dt_object *dt,
556 const struct lu_attr *attr,
560 * Change regular attributes.
562 * Change regular attributes in the given transaction. Note only
563 * attributes flagged by attr.la_valid change. The object must
564 * exist. If the layer implementing this method is responsible for
565 * quota, then the method should maintain object accounting for the
566 * given credentials when la_uid/la_gid changes.
568 * \param[in] env execution environment for this thread
569 * \param[in] dt object
570 * \param[in] attr new attributes to apply
571 * \param[in] th transaction handle
573 * \retval 0 on success
574 * \retval negative negated errno on error
576 int (*do_attr_set)(const struct lu_env *env,
577 struct dt_object *dt,
578 const struct lu_attr *attr,
582 * Declare intention to request extented attribute.
584 * Notify the underlying filesystem that the caller may request extended
585 * attribute with ->do_xattr_get() soon. This allows OSD to implement
586 * prefetching logic in an object-oriented manner. The implementation
587 * can be noop. This method should avoid expensive delays such as
588 * waiting on disk I/O, otherwise the goal of enabling a performance
589 * optimization would be defeated.
591 * \param[in] env execution environment for this thread
592 * \param[in] dt object
593 * \param[in] buf unused, may be removed in the future
594 * \param[in] name name of the extended attribute
596 * \retval 0 on success
597 * \retval negative negated errno on error
599 int (*do_declare_xattr_get)(const struct lu_env *env,
600 struct dt_object *dt,
605 * Return a value of an extended attribute.
607 * The object must exist. If the buffer is NULL, then the method
608 * must return the size of the value.
610 * \param[in] env execution environment for this thread
611 * \param[in] dt object
612 * \param[out] buf buffer in which to store the value
613 * \param[in] name name of the extended attribute
615 * \retval 0 on success
616 * \retval -ERANGE if \a buf is too small
617 * \retval negative negated errno on error
618 * \retval positive value's size if \a buf is NULL or has zero size
620 int (*do_xattr_get)(const struct lu_env *env,
621 struct dt_object *dt,
626 * Declare intention to change an extended attribute.
628 * Notify the underlying filesystem that the extended attribute may
629 * change in this transaction. This enables the layer below to prepare
630 * resources (e.g. journal credits in ext4). This method should be
631 * called between creating the transaction and starting it. The object
634 * \param[in] env execution environment for this thread
635 * \param[in] dt object
636 * \param[in] buf buffer storing new value of the attribute
637 * \param[in] name name of the attribute
638 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
639 * LU_XATTR_REPLACE - fail if EA doesn't exist
640 * \param[in] th transaction handle
642 * \retval 0 on success
643 * \retval negative negated errno on error
645 int (*do_declare_xattr_set)(const struct lu_env *env,
646 struct dt_object *dt,
647 const struct lu_buf *buf,
653 * Set an extended attribute.
655 * Change or replace the specified extended attribute (EA).
656 * The flags passed in \a fl dictate whether the EA is to be
657 * created or replaced, as follows.
658 * LU_XATTR_CREATE - fail if EA exists
659 * LU_XATTR_REPLACE - fail if EA doesn't exist
660 * The object must exist.
662 * \param[in] env execution environment for this thread
663 * \param[in] dt object
664 * \param[in] buf buffer storing new value of the attribute
665 * \param[in] name name of the attribute
666 * \param[in] fl flags indicating EA creation or replacement
667 * \param[in] th transaction handle
669 * \retval 0 on success
670 * \retval negative negated errno on error
672 int (*do_xattr_set)(const struct lu_env *env,
673 struct dt_object *dt,
674 const struct lu_buf *buf,
680 * Declare intention to delete an extended attribute.
682 * Notify the underlying filesystem that the extended attribute may
683 * be deleted in this transaction. This enables the layer below to
684 * prepare resources (e.g. journal credits in ext4). This method
685 * should be called between creating the transaction and starting it.
686 * The object need not exist.
688 * \param[in] env execution environment for this thread
689 * \param[in] dt object
690 * \param[in] name name of the attribute
691 * \param[in] th transaction handle
693 * \retval 0 on success
694 * \retval negative negated errno on error
696 int (*do_declare_xattr_del)(const struct lu_env *env,
697 struct dt_object *dt,
702 * Delete an extended attribute.
704 * This method deletes the specified extended attribute. The object
707 * \param[in] env execution environment for this thread
708 * \param[in] dt object
709 * \param[in] name name of the attribute
710 * \param[in] th transaction handle
712 * \retval 0 on success
713 * \retval negative negated errno on error
715 int (*do_xattr_del)(const struct lu_env *env,
716 struct dt_object *dt,
721 * Return a list of the extended attributes.
723 * Fills the passed buffer with a list of the extended attributes
724 * found in the object. The names are separated with '\0'.
725 * The object must exist.
727 * \param[in] env execution environment for this thread
728 * \param[in] dt object
729 * \param[out] buf buffer to put the list in
731 * \retval positive bytes used/required in the buffer
732 * \retval negative negated errno on error
734 int (*do_xattr_list)(const struct lu_env *env,
735 struct dt_object *dt,
736 const struct lu_buf *buf);
739 * Prepare allocation hint for a new object.
741 * This method is used by the caller to inform OSD of the parent-child
742 * relationship between two objects and enable efficient object
743 * allocation. Filled allocation hint will be passed to ->do_create()
746 * \param[in] env execution environment for this thread
747 * \param[out] ah allocation hint
748 * \param[in] parent parent object (can be NULL)
749 * \param[in] child child object
750 * \param[in] _mode type of the child object
752 void (*do_ah_init)(const struct lu_env *env,
753 struct dt_allocation_hint *ah,
754 struct dt_object *parent,
755 struct dt_object *child,
759 * Declare intention to create a new object.
761 * Notify the underlying filesystem that the object may be created
762 * in this transaction. This enables the layer below to prepare
763 * resources (e.g. journal credits in ext4). This method should be
764 * called between creating the transaction and starting it.
766 * If the layer implementing this method is responsible for quota,
767 * then the method should reserve an object for the given credentials
768 * and return an error if quota is over. If object creation later
769 * fails for some reason, then the reservation should be released
770 * properly (usually in ->dt_trans_stop()).
772 * \param[in] env execution environment for this thread
773 * \param[in] dt object
774 * \param[in] attr attributes of the new object
775 * \param[in] hint allocation hint
776 * \param[in] dof object format
777 * \param[in] th transaction handle
779 * \retval 0 on success
780 * \retval negative negated errno on error
782 int (*do_declare_create)(const struct lu_env *env,
783 struct dt_object *dt,
784 struct lu_attr *attr,
785 struct dt_allocation_hint *hint,
786 struct dt_object_format *dof,
792 * The method creates the object passed with the specified attributes
793 * and object format. Object allocation procedure can use information
794 * stored in the allocation hint. Different object formats are supported
795 * (see enum dt_format_type and struct dt_object_format) depending on
796 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
797 * in the LU-object header attributes.
799 * If the layer implementing this method is responsible for quota,
800 * then the method should maintain object accounting for the given
803 * \param[in] env execution environment for this thread
804 * \param[in] dt object
805 * \param[in] attr attributes of the new object
806 * \param[in] hint allocation hint
807 * \param[in] dof object format
808 * \param[in] th transaction handle
810 * \retval 0 on success
811 * \retval negative negated errno on error
813 int (*do_create)(const struct lu_env *env,
814 struct dt_object *dt,
815 struct lu_attr *attr,
816 struct dt_allocation_hint *hint,
817 struct dt_object_format *dof,
821 * Declare intention to destroy an object.
823 * Notify the underlying filesystem that the object may be destroyed
824 * in this transaction. This enables the layer below to prepare
825 * resources (e.g. journal credits in ext4). This method should be
826 * called between creating the transaction and starting it. The object
829 * \param[in] env execution environment for this thread
830 * \param[in] dt object
831 * \param[in] th transaction handle
833 * \retval 0 on success
834 * \retval negative negated errno on error
836 int (*do_declare_destroy)(const struct lu_env *env,
837 struct dt_object *dt,
843 * This method destroys the object and all the resources associated
844 * with the object (data, key/value pairs, extended attributes, etc).
845 * The object must exist. If destroy is successful, then flag
846 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
847 * instance of in-core object. Any subsequent access to the same FID
848 * should get another instance with no LOHA_EXIST flag set.
850 * If the layer implementing this method is responsible for quota,
851 * then the method should maintain object accounting for the given
854 * \param[in] env execution environment for this thread
855 * \param[in] dt object
856 * \param[in] th transaction handle
858 * \retval 0 on success
859 * \retval negative negated errno on error
861 int (*do_destroy)(const struct lu_env *env,
862 struct dt_object *dt,
866 * Try object as an index.
868 * Announce that this object is going to be used as an index. This
869 * operation checks that object supports indexing operations and
870 * installs appropriate dt_index_operations vector on success.
871 * Also probes for features. Operation is successful if all required
872 * features are supported. It's not possible to access the object
873 * with index methods before ->do_index_try() returns success.
875 * \param[in] env execution environment for this thread
876 * \param[in] dt object
877 * \param[in] feat index features
879 * \retval 0 on success
880 * \retval negative negated errno on error
882 int (*do_index_try)(const struct lu_env *env,
883 struct dt_object *dt,
884 const struct dt_index_features *feat);
887 * Declare intention to increment nlink count.
889 * Notify the underlying filesystem that the nlink regular attribute
890 * be changed in this transaction. This enables the layer below to
891 * prepare resources (e.g. journal credits in ext4). This method
892 * should be called between creating the transaction and starting it.
893 * The object need not exist.
895 * \param[in] env execution environment for this thread
896 * \param[in] dt object
897 * \param[in] th transaction handle
899 * \retval 0 on success
900 * \retval negative negated errno on error
902 int (*do_declare_ref_add)(const struct lu_env *env,
903 struct dt_object *dt,
909 * Increment nlink (from the regular attributes set) in the given
910 * transaction. Note the absolute limit for nlink should be learnt
911 * from struct dt_device_param::ddp_max_nlink. The object must exist.
913 * \param[in] env execution environment for this thread
914 * \param[in] dt object
915 * \param[in] th transaction handle
917 * \retval 0 on success
918 * \retval negative negated errno on error
920 int (*do_ref_add)(const struct lu_env *env,
921 struct dt_object *dt, struct thandle *th);
924 * Declare intention to decrement nlink count.
926 * Notify the underlying filesystem that the nlink regular attribute
927 * be changed in this transaction. This enables the layer below to
928 * prepare resources (e.g. journal credits in ext4). This method
929 * should be called between creating the transaction and starting it.
930 * The object need not exist.
932 * \param[in] env execution environment for this thread
933 * \param[in] dt object
934 * \param[in] th transaction handle
936 * \retval 0 on success
937 * \retval negative negated errno on error
939 int (*do_declare_ref_del)(const struct lu_env *env,
940 struct dt_object *dt,
946 * Decrement nlink (from the regular attributes set) in the given
947 * transaction. The object must exist.
949 * \param[in] env execution environment for this thread
950 * \param[in] dt object
951 * \param[in] th transaction handle
953 * \retval 0 on success
954 * \retval negative negated errno on error
956 int (*do_ref_del)(const struct lu_env *env,
957 struct dt_object *dt,
963 * The method is called to sync specified range of the object to a
964 * persistent storage. The control is returned once the operation is
965 * complete. The difference from ->do_sync() is that the object can
966 * be in-sync with the persistent storage (nothing to flush), then
967 * the method returns quickly with no I/O overhead. So, this method
968 * should be preferred over ->do_sync() where possible. Also note that
969 * if the object isn't clean, then some disk filesystems will call
970 * ->do_sync() to maintain overall consistency, in which case it's
971 * still very expensive.
973 * \param[in] env execution environment for this thread
974 * \param[in] dt object
975 * \param[in] start start of the range to sync
976 * \param[in] end end of the range to sync
978 * \retval 0 on success
979 * \retval negative negated errno on error
981 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
982 __u64 start, __u64 end);
987 * Lock object(s) using Distributed Lock Manager (LDLM).
989 * Get LDLM locks for the object. Currently used to lock "remote"
990 * objects in DNE configuration - a service running on MDTx needs
991 * to lock an object on MDTy.
993 * \param[in] env execution environment for this thread
994 * \param[in] dt object
995 * \param[out] lh lock handle, sometimes used, sometimes not
996 * \param[in] einfo ldlm callbacks, locking type and mode
997 * \param[out] einfo private data to be passed to unlock later
998 * \param[in] policy inodebits data
1000 * \retval 0 on success
1001 * \retval negative negated errno on error
1003 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1004 struct lustre_handle *lh,
1005 struct ldlm_enqueue_info *einfo,
1006 union ldlm_policy_data *policy);
1011 * Release LDLM lock(s) granted with ->do_object_lock().
1013 * \param[in] env execution environment for this thread
1014 * \param[in] dt object
1015 * \param[in] einfo lock handles, from ->do_object_lock()
1016 * \param[in] policy inodebits data
1018 * \retval 0 on success
1019 * \retval negative negated errno on error
1021 int (*do_object_unlock)(const struct lu_env *env,
1022 struct dt_object *dt,
1023 struct ldlm_enqueue_info *einfo,
1024 union ldlm_policy_data *policy);
1027 * Invalidate attribute cache.
1029 * This method invalidate attribute cache of the object, which is on OSP
1032 * \param[in] env execution envionment for this thread
1033 * \param[in] dt object
1035 * \retval 0 on success
1036 * \retval negative negated errno on error
1038 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1041 * Declare intention to instaintiate extended layout component.
1043 * \param[in] env execution environment
1044 * \param[in] dt DT object
1045 * \param[in] layout data structure to describe the changes to
1046 * the DT object's layout
1047 * \param[in] buf buffer containing client's lovea or empty
1050 * \retval -ne error code
1052 int (*do_declare_layout_change)(const struct lu_env *env,
1053 struct dt_object *dt,
1054 struct md_layout_change *mlc,
1055 struct thandle *th);
1058 * Client is trying to write to un-instantiated layout component.
1060 * \param[in] env execution environment
1061 * \param[in] dt DT object
1062 * \param[in] layout data structure to describe the changes to
1063 * the DT object's layout
1064 * \param[in] buf buffer containing client's lovea or empty
1067 * \retval -ne error code
1069 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1070 struct md_layout_change *mlc,
1071 struct thandle *th);
1075 DT_BUFS_TYPE_READ = 0x0000,
1076 DT_BUFS_TYPE_WRITE = 0x0001,
1077 DT_BUFS_TYPE_READAHEAD = 0x0002,
1078 DT_BUFS_TYPE_LOCAL = 0x0004,
1082 * Per-dt-object operations on "file body" - unstructure raw data.
1084 struct dt_body_operations {
1088 * Read unstructured data from an existing regular object.
1089 * Only data before attr.la_size is returned.
1091 * \param[in] env execution environment for this thread
1092 * \param[in] dt object
1093 * \param[out] buf buffer (including size) to copy data in
1094 * \param[in] pos position in the object to start
1095 * \param[out] pos original value of \a pos + bytes returned
1097 * \retval positive bytes read on success
1098 * \retval negative negated errno on error
1100 ssize_t (*dbo_read)(const struct lu_env *env,
1101 struct dt_object *dt,
1106 * Declare intention to write data to object.
1108 * Notify the underlying filesystem that data may be written in
1109 * this transaction. This enables the layer below to prepare resources
1110 * (e.g. journal credits in ext4). This method should be called
1111 * between creating the transaction and starting it. The object need
1112 * not exist. If the layer implementing this method is responsible for
1113 * quota, then the method should reserve space for the given credentials
1114 * and return an error if quota is over. If the write later fails
1115 * for some reason, then the reserve should be released properly
1116 * (usually in ->dt_trans_stop()).
1118 * \param[in] env execution environment for this thread
1119 * \param[in] dt object
1120 * \param[in] buf buffer (including size) to copy data from
1121 * \param[in] pos position in the object to start
1122 * \param[in] th transaction handle
1124 * \retval 0 on success
1125 * \retval negative negated errno on error
1127 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1128 struct dt_object *dt,
1129 const struct lu_buf *buf,
1131 struct thandle *th);
1134 * Write unstructured data to regular existing object.
1136 * The method allocates space and puts data in. Also, the method should
1137 * maintain attr.la_size properly. Partial writes are possible.
1139 * If the layer implementing this method is responsible for quota,
1140 * then the method should maintain space accounting for the given
1143 * \param[in] env execution environment for this thread
1144 * \param[in] dt object
1145 * \param[in] buf buffer (including size) to copy data from
1146 * \param[in] pos position in the object to start
1147 * \param[out] pos \a pos + bytes written
1148 * \param[in] th transaction handle
1150 * \retval positive bytes written on success
1151 * \retval negative negated errno on error
1153 ssize_t (*dbo_write)(const struct lu_env *env,
1154 struct dt_object *dt,
1155 const struct lu_buf *buf,
1157 struct thandle *th);
1160 * Return buffers for data.
1162 * This method is used to access data with no copying. It's so-called
1163 * zero-copy I/O. The method returns the descriptors for the internal
1164 * buffers where data are managed by the disk filesystem. For example,
1165 * pagecache in case of ext4 or ARC with ZFS. Then other components
1166 * (e.g. networking) can transfer data from or to the buffers with no
1167 * additional copying.
1169 * The method should fill an array of struct niobuf_local, where
1170 * each element describes a full or partial page for data at specific
1171 * offset. The caller should use page/lnb_page_offset/len to find data
1172 * at object's offset lnb_file_offset.
1174 * The memory referenced by the descriptors can't change its purpose
1175 * until the complementary ->dbo_bufs_put() is called. The caller should
1176 * specify if the buffers are used to read or modify data so that OSD
1177 * can decide how to initialize the buffers: bring all the data for
1178 * reads or just bring partial buffers for write. Note: the method does
1179 * not check whether output array is large enough.
1181 * \param[in] env execution environment for this thread
1182 * \param[in] dt object
1183 * \param[in] pos position in the object to start
1184 * \param[in] len size of region in bytes
1185 * \param[out] lb array of descriptors to fill
1186 * \param[in] rw 0 if used to read, 1 if used for write
1188 * \retval positive number of descriptors on success
1189 * \retval negative negated errno on error
1191 int (*dbo_bufs_get)(const struct lu_env *env,
1192 struct dt_object *dt,
1195 struct niobuf_local *lb,
1196 enum dt_bufs_type rw);
1199 * Release reference granted by ->dbo_bufs_get().
1201 * Release the reference granted by the previous ->dbo_bufs_get().
1202 * Note the references are counted.
1204 * \param[in] env execution environment for this thread
1205 * \param[in] dt object
1206 * \param[out] lb array of descriptors to fill
1207 * \param[in] nr size of the array
1209 * \retval 0 on success
1210 * \retval negative negated errno on error
1212 int (*dbo_bufs_put)(const struct lu_env *env,
1213 struct dt_object *dt,
1214 struct niobuf_local *lb,
1218 * Prepare buffers for reading.
1220 * The method is called on the given buffers to fill them with data
1221 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1222 * caller should be able to get few buffers for discontiguous regions
1223 * using few calls to ->dbo_bufs_get() and then request them all for
1224 * the preparation with a single call, so that OSD can fire many I/Os
1225 * to run concurrently. It's up to the specific OSD whether to implement
1226 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1227 * prepare data for every requested region individually.
1229 * \param[in] env execution environment for this thread
1230 * \param[in] dt object
1231 * \param[in] lnb array of buffer descriptors
1232 * \param[in] nr size of the array
1234 * \retval 0 on success
1235 * \retval negative negated errno on error
1237 int (*dbo_read_prep)(const struct lu_env *env,
1238 struct dt_object *dt,
1239 struct niobuf_local *lnb,
1243 * Prepare buffers for write.
1245 * This method is called on the given buffers to ensure the partial
1246 * buffers contain correct data. The underlying idea is the same as
1247 * in ->db_read_prep().
1249 * \param[in] env execution environment for this thread
1250 * \param[in] dt object
1251 * \param[in] lb array of buffer descriptors
1252 * \param[in] nr size of the array
1254 * \retval 0 on success
1255 * \retval negative negated errno on error
1257 int (*dbo_write_prep)(const struct lu_env *env,
1258 struct dt_object *dt,
1259 struct niobuf_local *lb,
1263 * Declare intention to write data stored in the buffers.
1265 * Notify the underlying filesystem that data may be written in
1266 * this transaction. This enables the layer below to prepare resources
1267 * (e.g. journal credits in ext4). This method should be called
1268 * between creating the transaction and starting it.
1270 * If the layer implementing this method is responsible for quota,
1271 * then the method should be reserving a space for the given
1272 * credentials and return an error if quota is exceeded. If the write
1273 * later fails for some reason, then the reserve should be released
1274 * properly (usually in ->dt_trans_stop()).
1276 * \param[in] env execution environment for this thread
1277 * \param[in] dt object
1278 * \param[in] lb array of descriptors
1279 * \param[in] nr size of the array
1280 * \param[in] th transaction handle
1282 * \retval 0 on success
1283 * \retval negative negated errno on error
1285 int (*dbo_declare_write_commit)(const struct lu_env *env,
1286 struct dt_object *dt,
1287 struct niobuf_local *lb,
1289 struct thandle *th);
1292 * Write to existing object.
1294 * This method is used to write data to a persistent storage using
1295 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1296 * data into the buffers using own mechanisms (e.g. direct transfer
1297 * from a NIC). The method should maintain attr.la_size. Also,
1298 * attr.la_blocks should be maintained but this can be done in lazy
1299 * manner, when actual allocation happens.
1301 * If the layer implementing this method is responsible for quota,
1302 * then the method should maintain space accounting for the given
1305 * \param[in] env execution environment for this thread
1306 * \param[in] dt object
1307 * \param[in] lb array of descriptors for the buffers
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_write_commit)(const struct lu_env *env,
1315 struct dt_object *dt,
1316 struct niobuf_local *lb,
1318 struct thandle *th);
1321 * Return logical to physical block mapping for a given extent
1323 * \param[in] env execution environment for this thread
1324 * \param[in] dt object
1325 * \param[in] fm describe the region to map and the output buffer
1326 * see the details in include/linux/fiemap.h
1328 * \retval 0 on success
1329 * \retval negative negated errno on error
1331 int (*dbo_fiemap_get)(const struct lu_env *env,
1332 struct dt_object *dt,
1336 * Declare intention to deallocate space from an object.
1338 * Notify the underlying filesystem that space may be deallocated in
1339 * this transactions. This enables the layer below to prepare resources
1340 * (e.g. journal credits in ext4). This method should be called between
1341 * creating the transaction and starting it. The object need not exist.
1343 * \param[in] env execution environment for this thread
1344 * \param[in] dt object
1345 * \param[in] start the start of the region to deallocate
1346 * \param[in] end the end of the region to deallocate
1347 * \param[in] th transaction handle
1349 * \retval 0 on success
1350 * \retval negative negated errno on error
1352 int (*dbo_declare_punch)(const struct lu_env *env,
1353 struct dt_object *dt,
1356 struct thandle *th);
1359 * Deallocate specified region in an object.
1361 * This method is used to deallocate (release) space possibly consumed
1362 * by the given region of the object. If the layer implementing this
1363 * method is responsible for quota, then the method should maintain
1364 * space accounting for the given credentials.
1366 * \param[in] env execution environment for this thread
1367 * \param[in] dt object
1368 * \param[in] start the start of the region to deallocate
1369 * \param[in] end the end of the region to deallocate
1370 * \param[in] th transaction handle
1372 * \retval 0 on success
1373 * \retval negative negated errno on error
1375 int (*dbo_punch)(const struct lu_env *env,
1376 struct dt_object *dt,
1379 struct thandle *th);
1381 * Give advices on specified region in an object.
1383 * This method is used to give advices about access pattern on an
1384 * given region of the object. The disk filesystem understands
1385 * the advices and tunes cache/read-ahead policies.
1387 * \param[in] env execution environment for this thread
1388 * \param[in] dt object
1389 * \param[in] start the start of the region affected
1390 * \param[in] end the end of the region affected
1391 * \param[in] advice advice type
1393 * \retval 0 on success
1394 * \retval negative negated errno on error
1396 int (*dbo_ladvise)(const struct lu_env *env,
1397 struct dt_object *dt,
1400 enum lu_ladvise_type advice);
1404 * Incomplete type of index record.
1409 * Incomplete type of index key.
1414 * Incomplete type of dt iterator.
1419 * Per-dt-object operations on object as index. Index is a set of key/value
1420 * pairs abstracted from an on-disk representation. An index supports the
1421 * number of operations including lookup by key, insert and delete. Also,
1422 * an index can be iterated to find the pairs one by one, from a beginning
1423 * or specified point.
1425 struct dt_index_operations {
1427 * Lookup in an index by key.
1429 * The method returns a value for the given key. Key/value format
1430 * and size should have been negotiated with ->do_index_try() before.
1431 * Thus it's the caller's responsibility to provide the method with
1432 * proper key and big enough buffer. No external locking is required,
1433 * all the internal consistency should be implemented by the method
1434 * or lower layers. The object should should have been created with
1435 * type DFT_INDEX or DFT_DIR.
1437 * \param[in] env execution environment for this thread
1438 * \param[in] dt object
1439 * \param[out] rec buffer where value will be stored
1440 * \param[in] key key
1442 * \retval 0 on success
1443 * \retval -ENOENT if key isn't found
1444 * \retval negative negated errno on error
1446 int (*dio_lookup)(const struct lu_env *env,
1447 struct dt_object *dt,
1449 const struct dt_key *key);
1452 * Declare intention to insert a key/value into an index.
1454 * Notify the underlying filesystem that new key/value may be inserted
1455 * in this transaction. This enables the layer below to prepare
1456 * resources (e.g. journal credits in ext4). This method should be
1457 * called between creating the transaction and starting it. key/value
1458 * format and size is subject to ->do_index_try().
1460 * \param[in] env execution environment for this thread
1461 * \param[in] dt object
1462 * \param[in] rec buffer storing value
1463 * \param[in] key key
1464 * \param[in] th transaction handle
1466 * \retval 0 on success
1467 * \retval negative negated errno on error
1469 int (*dio_declare_insert)(const struct lu_env *env,
1470 struct dt_object *dt,
1471 const struct dt_rec *rec,
1472 const struct dt_key *key,
1473 struct thandle *th);
1476 * Insert a new key/value pair into an index.
1478 * The method inserts specified key/value pair into the given index
1479 * object. The internal consistency is maintained by the method or
1480 * the functionality below. The format and size of key/value should
1481 * have been negotiated before using ->do_index_try(), no additional
1482 * information can be specified to the method. The keys are unique
1485 * \param[in] env execution environment for this thread
1486 * \param[in] dt object
1487 * \param[in] rec buffer storing value
1488 * \param[in] key key
1489 * \param[in] th transaction handle
1491 * \retval 0 on success
1492 * \retval negative negated errno on error
1494 int (*dio_insert)(const struct lu_env *env,
1495 struct dt_object *dt,
1496 const struct dt_rec *rec,
1497 const struct dt_key *key,
1498 struct thandle *th);
1501 * Declare intention to delete a key/value from an index.
1503 * Notify the underlying filesystem that key/value may be deleted in
1504 * this transaction. This enables the layer below to prepare resources
1505 * (e.g. journal credits in ext4). This method should be called
1506 * between creating the transaction and starting it. Key/value format
1507 * and size is subject to ->do_index_try(). The object need not exist.
1509 * \param[in] env execution environment for this thread
1510 * \param[in] dt object
1511 * \param[in] key key
1512 * \param[in] th transaction handle
1514 * \retval 0 on success
1515 * \retval negative negated errno on error
1517 int (*dio_declare_delete)(const struct lu_env *env,
1518 struct dt_object *dt,
1519 const struct dt_key *key,
1520 struct thandle *th);
1523 * Delete key/value pair from an index.
1525 * The method deletes specified key and corresponding value from the
1526 * given index object. The internal consistency is maintained by the
1527 * method or the functionality below. The format and size of the key
1528 * should have been negotiated before using ->do_index_try(), no
1529 * additional information can be specified to the method.
1531 * \param[in] env execution environment for this thread
1532 * \param[in] dt object
1533 * \param[in] key key
1534 * \param[in] th transaction handle
1536 * \retval 0 on success
1537 * \retval negative negated errno on error
1539 int (*dio_delete)(const struct lu_env *env,
1540 struct dt_object *dt,
1541 const struct dt_key *key,
1542 struct thandle *th);
1545 * Iterator interface.
1547 * Methods to iterate over an existing index, list the keys stored and
1548 * associated values, get key/value size, etc.
1552 * Allocate and initialize new iterator.
1554 * The iterator is a handler to be used in the subsequent
1555 * methods to access index's content. Note the position is
1556 * not defined at this point and should be initialized with
1557 * ->get() or ->load() method.
1559 * \param[in] env execution environment for this thread
1560 * \param[in] dt object
1561 * \param[in] attr ask the iterator to return part of
1562 the records, see LUDA_* for details
1564 * \retval pointer iterator pointer on success
1565 * \retval ERR_PTR(errno) on error
1567 struct dt_it *(*init)(const struct lu_env *env,
1568 struct dt_object *dt,
1574 * Release the specified iterator and all the resources
1575 * associated (e.g. the object, index cache, etc).
1577 * \param[in] env execution environment for this thread
1578 * \param[in] di iterator to release
1580 void (*fini)(const struct lu_env *env,
1584 * Move position of iterator.
1586 * Move the position of the specified iterator to the specified
1589 * \param[in] env execution environment for this thread
1590 * \param[in] di iterator
1591 * \param[in] key key to position to
1593 * \retval 0 if exact key is found
1594 * \retval 1 if at the record with least key
1595 * not larger than the key
1596 * \retval negative negated errno on error
1598 int (*get)(const struct lu_env *env,
1600 const struct dt_key *key);
1605 * Complimentary method for dt_it_ops::get() above. Some
1606 * implementation can increase a reference on the iterator in
1607 * dt_it_ops::get(). So the caller should be able to release
1608 * with dt_it_ops::put().
1610 * \param[in] env execution environment for this thread
1611 * \param[in] di iterator
1613 void (*put)(const struct lu_env *env,
1617 * Move to next record.
1619 * Moves the position of the iterator to a next record
1621 * \param[in] env execution environment for this thread
1622 * \param[in] di iterator
1624 * \retval 1 if no more records
1625 * \retval 0 on success, the next record is found
1626 * \retval negative negated errno on error
1628 int (*next)(const struct lu_env *env,
1634 * Returns a pointer to a buffer containing the key of the
1635 * record at the current position. The pointer is valid and
1636 * retains data until ->get(), ->load() and ->fini() methods
1639 * \param[in] env execution environment for this thread
1640 * \param[in] di iterator
1642 * \retval pointer to key on success
1643 * \retval ERR_PTR(errno) on error
1645 struct dt_key *(*key)(const struct lu_env *env,
1646 const struct dt_it *di);
1651 * Returns size of the key at the current position.
1653 * \param[in] env execution environment for this thread
1654 * \param[in] di iterator
1656 * \retval key's size on success
1657 * \retval negative negated errno on error
1659 int (*key_size)(const struct lu_env *env,
1660 const struct dt_it *di);
1665 * Stores the value of the record at the current position. The
1666 * buffer must be big enough (as negotiated with
1667 * ->do_index_try() or ->rec_size()). The caller can specify
1668 * she is interested only in part of the record, using attr
1669 * argument (see LUDA_* definitions for the details).
1671 * \param[in] env execution environment for this thread
1672 * \param[in] di iterator
1673 * \param[out] rec buffer to store value in
1674 * \param[in] attr specify part of the value to copy
1676 * \retval 0 on success
1677 * \retval negative negated errno on error
1679 int (*rec)(const struct lu_env *env,
1680 const struct dt_it *di,
1685 * Return record size.
1687 * Returns size of the record at the current position. The
1688 * \a attr can be used to specify only the parts of the record
1689 * needed to be returned. (see LUDA_* definitions for the
1692 * \param[in] env execution environment for this thread
1693 * \param[in] di iterator
1694 * \param[in] attr part of the record to return
1696 * \retval record's size on success
1697 * \retval negative negated errno on error
1699 int (*rec_size)(const struct lu_env *env,
1700 const struct dt_it *di,
1704 * Return a cookie (hash).
1706 * Returns the cookie (usually hash) of the key at the current
1707 * position. This allows the caller to resume iteration at this
1708 * position later. The exact value is specific to implementation
1709 * and should not be interpreted by the caller.
1711 * \param[in] env execution environment for this thread
1712 * \param[in] di iterator
1714 * \retval cookie/hash of the key
1716 __u64 (*store)(const struct lu_env *env,
1717 const struct dt_it *di);
1720 * Initialize position using cookie/hash.
1722 * Initializes the current position of the iterator to one
1723 * described by the cookie/hash as returned by ->store()
1726 * \param[in] env execution environment for this thread
1727 * \param[in] di iterator
1728 * \param[in] hash cookie/hash value
1730 * \retval positive if current position points to
1731 * record with least cookie not larger
1733 * \retval 0 if current position matches cookie
1734 * \retval negative negated errno on error
1736 int (*load)(const struct lu_env *env,
1737 const struct dt_it *di,
1743 int (*key_rec)(const struct lu_env *env,
1744 const struct dt_it *di,
1749 enum dt_otable_it_valid {
1750 DOIV_ERROR_HANDLE = 0x0001,
1751 DOIV_DRYRUN = 0x0002,
1754 enum dt_otable_it_flags {
1755 /* Exit when fail. */
1756 DOIF_FAILOUT = 0x0001,
1758 /* Reset iteration position to the device beginning. */
1759 DOIF_RESET = 0x0002,
1761 /* There is up layer component uses the iteration. */
1762 DOIF_OUTUSED = 0x0004,
1764 /* Check only without repairing. */
1765 DOIF_DRYRUN = 0x0008,
1768 /* otable based iteration needs to use the common DT iteration APIs.
1769 * To initialize the iteration, it needs call dio_it::init() firstly.
1770 * Here is how the otable based iteration should prepare arguments to
1771 * call dt_it_ops::init().
1773 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1774 * is composed of two parts:
1775 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1776 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1777 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1780 struct lu_device dd_lu_dev;
1781 const struct dt_device_operations *dd_ops;
1784 * List of dt_txn_callback (see below). This is not protected in any
1785 * way, because callbacks are supposed to be added/deleted only during
1786 * single-threaded start-up shut-down procedures.
1788 struct list_head dd_txn_callbacks;
1789 unsigned int dd_record_fid_accessed:1,
1792 /* sysfs and debugfs handling */
1793 struct dentry *dd_debugfs_entry;
1795 const struct attribute **dd_def_attrs;
1796 struct kobject dd_kobj;
1797 struct kobj_type dd_ktype;
1798 struct completion dd_kobj_unregister;
1801 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1802 void dt_device_fini(struct dt_device *dev);
1804 static inline int lu_device_is_dt(const struct lu_device *d)
1806 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1809 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1811 LASSERT(lu_device_is_dt(l));
1812 return container_of0(l, struct dt_device, dd_lu_dev);
1816 struct lu_object do_lu;
1817 const struct dt_object_operations *do_ops;
1818 const struct dt_body_operations *do_body_ops;
1819 const struct dt_index_operations *do_index_ops;
1823 * In-core representation of per-device local object OID storage
1825 struct local_oid_storage {
1826 /* all initialized llog systems on this node linked by this */
1827 struct list_head los_list;
1829 /* how many handle's reference this los has */
1830 atomic_t los_refcount;
1831 struct dt_device *los_dev;
1832 struct dt_object *los_obj;
1834 /* data used to generate new fids */
1835 struct mutex los_id_lock;
1840 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1842 return &d->dd_lu_dev;
1845 static inline struct dt_object *lu2dt(struct lu_object *l)
1847 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1848 return container_of0(l, struct dt_object, do_lu);
1851 int dt_object_init(struct dt_object *obj,
1852 struct lu_object_header *h, struct lu_device *d);
1854 void dt_object_fini(struct dt_object *obj);
1856 static inline int dt_object_exists(const struct dt_object *dt)
1858 return lu_object_exists(&dt->do_lu);
1861 static inline int dt_object_remote(const struct dt_object *dt)
1863 return lu_object_remote(&dt->do_lu);
1866 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1868 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1869 return container_of0(o, struct dt_object, do_lu);
1872 static inline struct dt_object *dt_object_child(struct dt_object *o)
1874 return container_of0(lu_object_next(&(o)->do_lu),
1875 struct dt_object, do_lu);
1879 * This is the general purpose transaction handle.
1880 * 1. Transaction Life Cycle
1881 * This transaction handle is allocated upon starting a new transaction,
1882 * and deallocated after this transaction is committed.
1883 * 2. Transaction Nesting
1884 * We do _NOT_ support nested transaction. So, every thread should only
1885 * have one active transaction, and a transaction only belongs to one
1886 * thread. Due to this, transaction handle need no reference count.
1887 * 3. Transaction & dt_object locking
1888 * dt_object locks should be taken inside transaction.
1889 * 4. Transaction & RPC
1890 * No RPC request should be issued inside transaction.
1893 /** the dt device on which the transactions are executed */
1894 struct dt_device *th_dev;
1896 /* point to the top thandle, XXX this is a bit hacky right now,
1897 * but normal device trans callback triggered by the bottom
1898 * device (OSP/OSD == sub thandle layer) needs to get the
1899 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1900 * top thandle here for now, will fix it when we have better
1901 * callback mechanism */
1902 struct thandle *th_top;
1904 /** the last operation result in this transaction.
1905 * this value is used in recovery */
1908 /** whether we need sync commit */
1909 unsigned int th_sync:1,
1910 /* local transation, no need to inform other layers */
1912 /* Whether we need wait the transaction to be submitted
1913 * (send to remote target) */
1915 /* complex transaction which will track updates on all targets,
1918 /* whether ignore quota */
1923 * Transaction call-backs.
1925 * These are invoked by osd (or underlying transaction engine) when
1926 * transaction changes state.
1928 * Call-backs are used by upper layers to modify transaction parameters and to
1929 * perform some actions on for each transaction state transition. Typical
1930 * example is mdt registering call-back to write into last-received file
1931 * before each transaction commit.
1933 struct dt_txn_callback {
1934 int (*dtc_txn_start)(const struct lu_env *env,
1935 struct thandle *txn, void *cookie);
1936 int (*dtc_txn_stop)(const struct lu_env *env,
1937 struct thandle *txn, void *cookie);
1940 struct list_head dtc_linkage;
1943 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1944 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1946 int dt_txn_hook_start(const struct lu_env *env,
1947 struct dt_device *dev, struct thandle *txn);
1948 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1950 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1953 * Callback function used for parsing path.
1954 * \see llo_store_resolve
1956 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1960 #define DT_MAX_PATH 1024
1962 int dt_path_parser(const struct lu_env *env,
1963 char *local, dt_entry_func_t entry_func,
1967 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1968 const char *path, struct lu_fid *fid);
1970 struct dt_object *dt_store_open(const struct lu_env *env,
1971 struct dt_device *dt,
1972 const char *dirname,
1973 const char *filename,
1974 struct lu_fid *fid);
1976 struct dt_object *dt_find_or_create(const struct lu_env *env,
1977 struct dt_device *dt,
1978 const struct lu_fid *fid,
1979 struct dt_object_format *dof,
1980 struct lu_attr *attr);
1982 struct dt_object *dt_locate_at(const struct lu_env *env,
1983 struct dt_device *dev,
1984 const struct lu_fid *fid,
1985 struct lu_device *top_dev,
1986 const struct lu_object_conf *conf);
1988 static inline struct dt_object *
1989 dt_locate(const struct lu_env *env, struct dt_device *dev,
1990 const struct lu_fid *fid)
1992 return dt_locate_at(env, dev, fid,
1993 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1996 static inline struct dt_object *
1997 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1999 struct lu_object *lo;
2001 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2002 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2003 return container_of(lo, struct dt_object, do_lu);
2008 static inline void dt_object_put(const struct lu_env *env,
2009 struct dt_object *dto)
2011 lu_object_put(env, &dto->do_lu);
2014 static inline void dt_object_put_nocache(const struct lu_env *env,
2015 struct dt_object *dto)
2017 lu_object_put_nocache(env, &dto->do_lu);
2020 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2021 const struct lu_fid *first_fid,
2022 struct local_oid_storage **los);
2023 void local_oid_storage_fini(const struct lu_env *env,
2024 struct local_oid_storage *los);
2025 int local_object_fid_generate(const struct lu_env *env,
2026 struct local_oid_storage *los,
2027 struct lu_fid *fid);
2028 int local_object_declare_create(const struct lu_env *env,
2029 struct local_oid_storage *los,
2030 struct dt_object *o,
2031 struct lu_attr *attr,
2032 struct dt_object_format *dof,
2033 struct thandle *th);
2034 int local_object_create(const struct lu_env *env,
2035 struct local_oid_storage *los,
2036 struct dt_object *o,
2037 struct lu_attr *attr, struct dt_object_format *dof,
2038 struct thandle *th);
2039 struct dt_object *local_file_find(const struct lu_env *env,
2040 struct local_oid_storage *los,
2041 struct dt_object *parent,
2043 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2044 struct local_oid_storage *los,
2045 struct dt_object *parent,
2046 const char *name, __u32 mode);
2047 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2048 struct dt_device *dt,
2049 const struct lu_fid *fid,
2050 struct dt_object *parent,
2054 local_index_find_or_create(const struct lu_env *env,
2055 struct local_oid_storage *los,
2056 struct dt_object *parent,
2057 const char *name, __u32 mode,
2058 const struct dt_index_features *ft);
2060 local_index_find_or_create_with_fid(const struct lu_env *env,
2061 struct dt_device *dt,
2062 const struct lu_fid *fid,
2063 struct dt_object *parent,
2064 const char *name, __u32 mode,
2065 const struct dt_index_features *ft);
2066 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2067 struct dt_object *parent, const char *name);
2069 static inline int dt_object_lock(const struct lu_env *env,
2070 struct dt_object *o, struct lustre_handle *lh,
2071 struct ldlm_enqueue_info *einfo,
2072 union ldlm_policy_data *policy)
2075 LASSERT(o->do_ops != NULL);
2076 LASSERT(o->do_ops->do_object_lock != NULL);
2077 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2080 static inline int dt_object_unlock(const struct lu_env *env,
2081 struct dt_object *o,
2082 struct ldlm_enqueue_info *einfo,
2083 union ldlm_policy_data *policy)
2086 LASSERT(o->do_ops != NULL);
2087 LASSERT(o->do_ops->do_object_unlock != NULL);
2088 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2091 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2092 const char *name, struct lu_fid *fid);
2094 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2095 __u64 start, __u64 end)
2099 LASSERT(o->do_ops->do_object_sync);
2100 return o->do_ops->do_object_sync(env, o, start, end);
2103 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2104 struct thandle *th);
2105 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2106 dt_obj_version_t version, struct thandle *th);
2107 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2110 int dt_read(const struct lu_env *env, struct dt_object *dt,
2111 struct lu_buf *buf, loff_t *pos);
2112 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2113 struct lu_buf *buf, loff_t *pos);
2114 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2115 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2116 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2117 union lu_page *lp, size_t nob,
2118 const struct dt_it_ops *iops,
2119 struct dt_it *it, __u32 attr, void *arg);
2120 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2121 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2123 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2124 struct idx_info *ii, const struct lu_rdpg *rdpg);
2126 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2127 struct dt_device *d)
2129 LASSERT(d->dd_ops->dt_trans_create);
2130 return d->dd_ops->dt_trans_create(env, d);
2133 static inline int dt_trans_start(const struct lu_env *env,
2134 struct dt_device *d, struct thandle *th)
2136 LASSERT(d->dd_ops->dt_trans_start);
2137 return d->dd_ops->dt_trans_start(env, d, th);
2140 /* for this transaction hooks shouldn't be called */
2141 static inline int dt_trans_start_local(const struct lu_env *env,
2142 struct dt_device *d, struct thandle *th)
2144 LASSERT(d->dd_ops->dt_trans_start);
2146 return d->dd_ops->dt_trans_start(env, d, th);
2149 static inline int dt_trans_stop(const struct lu_env *env,
2150 struct dt_device *d, struct thandle *th)
2152 LASSERT(d->dd_ops->dt_trans_stop);
2153 return d->dd_ops->dt_trans_stop(env, d, th);
2156 static inline int dt_trans_cb_add(struct thandle *th,
2157 struct dt_txn_commit_cb *dcb)
2159 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2160 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2161 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2166 static inline int dt_declare_record_write(const struct lu_env *env,
2167 struct dt_object *dt,
2168 const struct lu_buf *buf,
2174 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2175 LASSERT(th != NULL);
2176 LASSERT(dt->do_body_ops);
2177 LASSERT(dt->do_body_ops->dbo_declare_write);
2178 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2182 static inline int dt_declare_create(const struct lu_env *env,
2183 struct dt_object *dt,
2184 struct lu_attr *attr,
2185 struct dt_allocation_hint *hint,
2186 struct dt_object_format *dof,
2190 LASSERT(dt->do_ops);
2191 LASSERT(dt->do_ops->do_declare_create);
2193 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2194 return cfs_fail_err;
2196 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2199 static inline int dt_create(const struct lu_env *env,
2200 struct dt_object *dt,
2201 struct lu_attr *attr,
2202 struct dt_allocation_hint *hint,
2203 struct dt_object_format *dof,
2207 LASSERT(dt->do_ops);
2208 LASSERT(dt->do_ops->do_create);
2210 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2211 return cfs_fail_err;
2213 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2216 static inline int dt_declare_destroy(const struct lu_env *env,
2217 struct dt_object *dt,
2221 LASSERT(dt->do_ops);
2222 LASSERT(dt->do_ops->do_declare_destroy);
2224 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2225 return cfs_fail_err;
2227 return dt->do_ops->do_declare_destroy(env, dt, th);
2230 static inline int dt_destroy(const struct lu_env *env,
2231 struct dt_object *dt,
2235 LASSERT(dt->do_ops);
2236 LASSERT(dt->do_ops->do_destroy);
2238 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2239 return cfs_fail_err;
2241 return dt->do_ops->do_destroy(env, dt, th);
2244 static inline void dt_read_lock(const struct lu_env *env,
2245 struct dt_object *dt,
2249 LASSERT(dt->do_ops);
2250 LASSERT(dt->do_ops->do_read_lock);
2251 dt->do_ops->do_read_lock(env, dt, role);
2254 static inline void dt_write_lock(const struct lu_env *env,
2255 struct dt_object *dt,
2259 LASSERT(dt->do_ops);
2260 LASSERT(dt->do_ops->do_write_lock);
2261 dt->do_ops->do_write_lock(env, dt, role);
2264 static inline void dt_read_unlock(const struct lu_env *env,
2265 struct dt_object *dt)
2268 LASSERT(dt->do_ops);
2269 LASSERT(dt->do_ops->do_read_unlock);
2270 dt->do_ops->do_read_unlock(env, dt);
2273 static inline void dt_write_unlock(const struct lu_env *env,
2274 struct dt_object *dt)
2277 LASSERT(dt->do_ops);
2278 LASSERT(dt->do_ops->do_write_unlock);
2279 dt->do_ops->do_write_unlock(env, dt);
2282 static inline int dt_write_locked(const struct lu_env *env,
2283 struct dt_object *dt)
2286 LASSERT(dt->do_ops);
2287 LASSERT(dt->do_ops->do_write_locked);
2288 return dt->do_ops->do_write_locked(env, dt);
2291 static inline int dt_declare_attr_get(const struct lu_env *env,
2292 struct dt_object *dt)
2295 LASSERT(dt->do_ops);
2296 LASSERT(dt->do_ops->do_declare_attr_get);
2298 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2299 return cfs_fail_err;
2301 return dt->do_ops->do_declare_attr_get(env, dt);
2304 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2308 LASSERT(dt->do_ops);
2309 LASSERT(dt->do_ops->do_attr_get);
2311 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2312 return cfs_fail_err;
2314 return dt->do_ops->do_attr_get(env, dt, la);
2317 static inline int dt_declare_attr_set(const struct lu_env *env,
2318 struct dt_object *dt,
2319 const struct lu_attr *la,
2323 LASSERT(dt->do_ops);
2324 LASSERT(dt->do_ops->do_declare_attr_set);
2326 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2327 return cfs_fail_err;
2329 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2332 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2333 const struct lu_attr *la, struct thandle *th)
2336 LASSERT(dt->do_ops);
2337 LASSERT(dt->do_ops->do_attr_set);
2339 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2340 return cfs_fail_err;
2342 return dt->do_ops->do_attr_set(env, dt, la, th);
2345 static inline int dt_declare_ref_add(const struct lu_env *env,
2346 struct dt_object *dt, struct thandle *th)
2349 LASSERT(dt->do_ops);
2350 LASSERT(dt->do_ops->do_declare_ref_add);
2352 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2353 return cfs_fail_err;
2355 return dt->do_ops->do_declare_ref_add(env, dt, th);
2358 static inline int dt_ref_add(const struct lu_env *env,
2359 struct dt_object *dt, struct thandle *th)
2362 LASSERT(dt->do_ops);
2363 LASSERT(dt->do_ops->do_ref_add);
2365 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2366 return cfs_fail_err;
2368 return dt->do_ops->do_ref_add(env, dt, th);
2371 static inline int dt_declare_ref_del(const struct lu_env *env,
2372 struct dt_object *dt, struct thandle *th)
2375 LASSERT(dt->do_ops);
2376 LASSERT(dt->do_ops->do_declare_ref_del);
2378 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2379 return cfs_fail_err;
2381 return dt->do_ops->do_declare_ref_del(env, dt, th);
2384 static inline int dt_ref_del(const struct lu_env *env,
2385 struct dt_object *dt, struct thandle *th)
2388 LASSERT(dt->do_ops);
2389 LASSERT(dt->do_ops->do_ref_del);
2391 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2392 return cfs_fail_err;
2394 return dt->do_ops->do_ref_del(env, dt, th);
2397 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2398 struct niobuf_remote *rnb,
2399 struct niobuf_local *lnb, enum dt_bufs_type rw)
2402 LASSERT(d->do_body_ops);
2403 LASSERT(d->do_body_ops->dbo_bufs_get);
2404 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2405 rnb->rnb_len, lnb, rw);
2408 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2409 struct niobuf_local *lnb, int n)
2412 LASSERT(d->do_body_ops);
2413 LASSERT(d->do_body_ops->dbo_bufs_put);
2414 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2417 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2418 struct niobuf_local *lnb, int n)
2421 LASSERT(d->do_body_ops);
2422 LASSERT(d->do_body_ops->dbo_write_prep);
2423 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2426 static inline int dt_declare_write_commit(const struct lu_env *env,
2427 struct dt_object *d,
2428 struct niobuf_local *lnb,
2429 int n, struct thandle *th)
2431 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2432 LASSERT(th != NULL);
2433 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2437 static inline int dt_write_commit(const struct lu_env *env,
2438 struct dt_object *d, struct niobuf_local *lnb,
2439 int n, struct thandle *th)
2442 LASSERT(d->do_body_ops);
2443 LASSERT(d->do_body_ops->dbo_write_commit);
2444 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2447 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2448 struct niobuf_local *lnb, int n)
2451 LASSERT(d->do_body_ops);
2452 LASSERT(d->do_body_ops->dbo_read_prep);
2453 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2456 static inline int dt_declare_write(const struct lu_env *env,
2457 struct dt_object *dt,
2458 const struct lu_buf *buf, loff_t pos,
2462 LASSERT(dt->do_body_ops);
2463 LASSERT(dt->do_body_ops->dbo_declare_write);
2464 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2467 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2468 const struct lu_buf *buf, loff_t *pos,
2472 LASSERT(dt->do_body_ops);
2473 LASSERT(dt->do_body_ops->dbo_write);
2474 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2477 static inline int dt_declare_punch(const struct lu_env *env,
2478 struct dt_object *dt, __u64 start,
2479 __u64 end, struct thandle *th)
2482 LASSERT(dt->do_body_ops);
2483 LASSERT(dt->do_body_ops->dbo_declare_punch);
2484 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2487 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2488 __u64 start, __u64 end, struct thandle *th)
2491 LASSERT(dt->do_body_ops);
2492 LASSERT(dt->do_body_ops->dbo_punch);
2493 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2496 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2497 __u64 start, __u64 end, int advice)
2500 LASSERT(dt->do_body_ops);
2501 LASSERT(dt->do_body_ops->dbo_ladvise);
2502 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2505 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2509 if (d->do_body_ops == NULL)
2511 if (d->do_body_ops->dbo_fiemap_get == NULL)
2513 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2516 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2517 struct obd_statfs *osfs)
2520 LASSERT(dev->dd_ops);
2521 LASSERT(dev->dd_ops->dt_statfs);
2522 return dev->dd_ops->dt_statfs(env, dev, osfs);
2525 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2529 LASSERT(dev->dd_ops);
2530 LASSERT(dev->dd_ops->dt_root_get);
2531 return dev->dd_ops->dt_root_get(env, dev, f);
2534 static inline void dt_conf_get(const struct lu_env *env,
2535 const struct dt_device *dev,
2536 struct dt_device_param *param)
2539 LASSERT(dev->dd_ops);
2540 LASSERT(dev->dd_ops->dt_conf_get);
2541 return dev->dd_ops->dt_conf_get(env, dev, param);
2544 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2547 LASSERT(dev->dd_ops);
2548 if (dev->dd_ops->dt_mnt_sb_get)
2549 return dev->dd_ops->dt_mnt_sb_get(dev);
2551 return ERR_PTR(-EOPNOTSUPP);
2554 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2557 LASSERT(dev->dd_ops);
2558 LASSERT(dev->dd_ops->dt_sync);
2559 return dev->dd_ops->dt_sync(env, dev);
2562 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2565 LASSERT(dev->dd_ops);
2566 LASSERT(dev->dd_ops->dt_ro);
2567 return dev->dd_ops->dt_ro(env, dev);
2570 static inline int dt_declare_insert(const struct lu_env *env,
2571 struct dt_object *dt,
2572 const struct dt_rec *rec,
2573 const struct dt_key *key,
2577 LASSERT(dt->do_index_ops);
2578 LASSERT(dt->do_index_ops->dio_declare_insert);
2580 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2581 return cfs_fail_err;
2583 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2586 static inline int dt_insert(const struct lu_env *env,
2587 struct dt_object *dt,
2588 const struct dt_rec *rec,
2589 const struct dt_key *key,
2593 LASSERT(dt->do_index_ops);
2594 LASSERT(dt->do_index_ops->dio_insert);
2596 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2597 return cfs_fail_err;
2599 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2602 static inline int dt_declare_xattr_del(const struct lu_env *env,
2603 struct dt_object *dt,
2608 LASSERT(dt->do_ops);
2609 LASSERT(dt->do_ops->do_declare_xattr_del);
2611 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2612 return cfs_fail_err;
2614 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2617 static inline int dt_xattr_del(const struct lu_env *env,
2618 struct dt_object *dt, const char *name,
2622 LASSERT(dt->do_ops);
2623 LASSERT(dt->do_ops->do_xattr_del);
2625 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2626 return cfs_fail_err;
2628 return dt->do_ops->do_xattr_del(env, dt, name, th);
2631 static inline int dt_declare_xattr_set(const struct lu_env *env,
2632 struct dt_object *dt,
2633 const struct lu_buf *buf,
2634 const char *name, int fl,
2638 LASSERT(dt->do_ops);
2639 LASSERT(dt->do_ops->do_declare_xattr_set);
2641 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2642 return cfs_fail_err;
2644 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2647 static inline int dt_xattr_set(const struct lu_env *env,
2648 struct dt_object *dt, const struct lu_buf *buf,
2649 const char *name, int fl, struct thandle *th)
2652 LASSERT(dt->do_ops);
2653 LASSERT(dt->do_ops->do_xattr_set);
2655 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2656 return cfs_fail_err;
2658 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2661 static inline int dt_declare_xattr_get(const struct lu_env *env,
2662 struct dt_object *dt,
2667 LASSERT(dt->do_ops);
2668 LASSERT(dt->do_ops->do_declare_xattr_get);
2670 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2671 return cfs_fail_err;
2673 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2676 static inline int dt_xattr_get(const struct lu_env *env,
2677 struct dt_object *dt, struct lu_buf *buf,
2681 LASSERT(dt->do_ops);
2682 LASSERT(dt->do_ops->do_xattr_get);
2684 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2685 return cfs_fail_err;
2687 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2690 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2691 const struct lu_buf *buf)
2694 LASSERT(dt->do_ops);
2695 LASSERT(dt->do_ops->do_xattr_list);
2697 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2698 return cfs_fail_err;
2700 return dt->do_ops->do_xattr_list(env, dt, buf);
2703 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2706 LASSERT(dt->do_ops);
2707 LASSERT(dt->do_ops->do_invalidate);
2709 return dt->do_ops->do_invalidate(env, dt);
2712 static inline int dt_declare_delete(const struct lu_env *env,
2713 struct dt_object *dt,
2714 const struct dt_key *key,
2718 LASSERT(dt->do_index_ops);
2719 LASSERT(dt->do_index_ops->dio_declare_delete);
2721 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2722 return cfs_fail_err;
2724 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2727 static inline int dt_delete(const struct lu_env *env,
2728 struct dt_object *dt,
2729 const struct dt_key *key,
2733 LASSERT(dt->do_index_ops);
2734 LASSERT(dt->do_index_ops->dio_delete);
2736 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2737 return cfs_fail_err;
2739 return dt->do_index_ops->dio_delete(env, dt, key, th);
2742 static inline int dt_commit_async(const struct lu_env *env,
2743 struct dt_device *dev)
2746 LASSERT(dev->dd_ops);
2747 LASSERT(dev->dd_ops->dt_commit_async);
2748 return dev->dd_ops->dt_commit_async(env, dev);
2751 static inline int dt_lookup(const struct lu_env *env,
2752 struct dt_object *dt,
2754 const struct dt_key *key)
2759 LASSERT(dt->do_index_ops);
2760 LASSERT(dt->do_index_ops->dio_lookup);
2762 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2763 return cfs_fail_err;
2765 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2773 static inline int dt_declare_layout_change(const struct lu_env *env,
2774 struct dt_object *o,
2775 struct md_layout_change *mlc,
2780 LASSERT(o->do_ops->do_declare_layout_change);
2781 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2784 static inline int dt_layout_change(const struct lu_env *env,
2785 struct dt_object *o,
2786 struct md_layout_change *mlc,
2791 LASSERT(o->do_ops->do_layout_change);
2792 return o->do_ops->do_layout_change(env, o, mlc, th);
2795 struct dt_find_hint {
2796 struct lu_fid *dfh_fid;
2797 struct dt_device *dfh_dt;
2798 struct dt_object *dfh_o;
2801 struct dt_insert_rec {
2803 const struct lu_fid *rec_fid;
2815 struct dt_thread_info {
2816 char dti_buf[DT_MAX_PATH];
2817 struct dt_find_hint dti_dfh;
2818 struct lu_attr dti_attr;
2819 struct lu_fid dti_fid;
2820 struct dt_object_format dti_dof;
2821 struct lustre_mdt_attrs dti_lma;
2822 struct lu_buf dti_lb;
2823 struct lu_object_conf dti_conf;
2825 struct dt_insert_rec dti_dt_rec;
2828 extern struct lu_context_key dt_key;
2830 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2832 struct dt_thread_info *dti;
2834 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2839 int dt_global_init(void);
2840 void dt_global_fini(void);
2841 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2842 const char *name, struct lprocfs_vars *list);
2843 int dt_tunables_fini(struct dt_device *dt);
2845 # ifdef CONFIG_PROC_FS
2846 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2847 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2848 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2849 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2850 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2851 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2852 # endif /* CONFIG_PROC_FS */
2854 #endif /* __LUSTRE_DT_OBJECT_H */