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;
91 bool ddp_has_lseek_data_hole;
95 * Per-transaction commit callback function
97 struct dt_txn_commit_cb;
98 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
99 struct dt_txn_commit_cb *cb, int err);
101 * Special per-transaction callback for cases when just commit callback
102 * is needed and per-device callback are not convenient to use
104 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
105 #define MAX_COMMIT_CB_STR_LEN 32
107 #define DCB_TRANS_STOP 0x1
108 struct dt_txn_commit_cb {
109 struct list_head dcb_linkage;
114 char dcb_name[MAX_COMMIT_CB_STR_LEN];
118 * Operations on dt device.
120 struct dt_device_operations {
122 * Return device-wide statistics.
124 * Return device-wide stats including block size, total and
125 * free blocks, total and free objects, etc. See struct obd_statfs
128 * \param[in] env execution environment for this thread
129 * \param[in] dev dt device
130 * \param[out] osfs stats information
132 * \retval 0 on success
133 * \retval negative negated errno on error
135 int (*dt_statfs)(const struct lu_env *env,
136 struct dt_device *dev,
137 struct obd_statfs *osfs,
138 struct obd_statfs_info *info);
141 * Create transaction.
143 * Create in-memory structure representing the transaction for the
144 * caller. The structure returned will be used by the calling thread
145 * to specify the transaction the updates belong to. Once created
146 * successfully ->dt_trans_stop() must be called in any case (with
147 * ->dt_trans_start() and updates or not) so that the transaction
148 * handle and other resources can be released by the layers below.
150 * \param[in] env execution environment for this thread
151 * \param[in] dev dt device
153 * \retval pointer to handle if creation succeeds
154 * \retval ERR_PTR(errno) if creation fails
156 struct thandle *(*dt_trans_create)(const struct lu_env *env,
157 struct dt_device *dev);
162 * Start the transaction. The transaction described by \a th can be
163 * started only once. Another start is considered as an error.
164 * A thread is not supposed to start a transaction while another
165 * transaction isn't closed by the thread (though multiple handles
166 * can be created). The caller should start the transaction once
167 * all possible updates are declared (see the ->do_declare_* methods
168 * below) and all the needed resources are reserved.
170 * \param[in] env execution environment for this thread
171 * \param[in] dev dt device
172 * \param[in] th transaction handle
174 * \retval 0 on success
175 * \retval negative negated errno on error
177 int (*dt_trans_start)(const struct lu_env *env,
178 struct dt_device *dev,
184 * Once stopped the transaction described by \a th is complete (all
185 * the needed updates are applied) and further processing such as
186 * flushing to disk, sending to another target, etc, is handled by
187 * lower layers. The caller can't access this transaction by the
188 * handle anymore (except from the commit callbacks, see below).
190 * \param[in] env execution environment for this thread
191 * \param[in] dev dt device
192 * \param[in] th transaction handle
194 * \retval 0 on success
195 * \retval negative negated errno on error
197 int (*dt_trans_stop)(const struct lu_env *env,
198 struct dt_device *dev,
202 * Add commit callback to the transaction.
204 * Add a commit callback to the given transaction handle. The callback
205 * will be called when the associated transaction is stored. I.e. the
206 * transaction will survive an event like power off if the callback did
207 * run. The number of callbacks isn't limited, but you should note that
208 * some disk filesystems do handle the commit callbacks in the thread
209 * handling commit/flush of all the transactions, meaning that new
210 * transactions are blocked from commit and flush until all the
211 * callbacks are done. Also, note multiple callbacks can be running
212 * concurrently using multiple CPU cores. The callbacks will be running
213 * in a special environment which can not be used to pass data around.
215 * \param[in] th transaction handle
216 * \param[in] dcb commit callback description
218 * \retval 0 on success
219 * \retval negative negated errno on error
221 int (*dt_trans_cb_add)(struct thandle *th,
222 struct dt_txn_commit_cb *dcb);
225 * Return FID of root index object.
227 * Return the FID of the root object in the filesystem. This object
228 * is usually provided as a bootstrap point by a disk filesystem.
229 * This is up to the implementation which FID to use, though
230 * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
232 * \param[in] env execution environment for this thread
233 * \param[in] dev dt device
234 * \param[out] fid FID of the root object
236 * \retval 0 on success
237 * \retval negative negated errno on error
239 int (*dt_root_get)(const struct lu_env *env,
240 struct dt_device *dev,
244 * Return device configuration data.
246 * Return device (disk fs, actually) specific configuration.
247 * The configuration isn't subject to change at runtime.
248 * See struct dt_device_param for the details.
250 * \param[in] env execution environment for this thread
251 * \param[in] dev dt device
252 * \param[out] param configuration parameters
254 void (*dt_conf_get)(const struct lu_env *env,
255 const struct dt_device *dev,
256 struct dt_device_param *param);
259 * Return device's super block.
261 * \param[in] dev dt device
263 struct super_block *(*dt_mnt_sb_get)(const struct dt_device *dev);
268 * Sync all the cached state (dirty buffers, pages, etc) to the
269 * persistent storage. The method returns control once the sync is
270 * complete. This operation may incur significant I/O to disk and
271 * should be reserved for cases where a global sync is strictly
274 * \param[in] env execution environment for this thread
275 * \param[in] dev dt device
277 * \retval 0 on success
278 * \retval negative negated errno on error
280 int (*dt_sync)(const struct lu_env *env,
281 struct dt_device *dev);
284 * Make device read-only.
286 * Prevent new modifications to the device. This is a very specific
287 * state where all the changes are accepted successfully and the
288 * commit callbacks are called, but persistent state never changes.
289 * Used only in the tests to simulate power-off scenario.
291 * \param[in] env execution environment for this thread
292 * \param[in] dev dt device
294 * \retval 0 on success
295 * \retval negative negated errno on error
297 int (*dt_ro)(const struct lu_env *env,
298 struct dt_device *dev);
301 * Start transaction commit asynchronously.
304 * Provide a hint to the underlying filesystem that it should start
305 * committing soon. The control returns immediately. It's up to the
306 * layer implementing the method how soon to start committing. Usually
307 * this should be throttled to some extent, otherwise the number of
308 * aggregated transaction goes too high causing performance drop.
310 * \param[in] env execution environment for this thread
311 * \param[in] dev dt device
313 * \retval 0 on success
314 * \retval negative negated errno on error
316 int (*dt_commit_async)(const struct lu_env *env,
317 struct dt_device *dev);
320 struct dt_index_features {
321 /** required feature flags from enum dt_index_flags */
323 /** minimal required key size */
324 size_t dif_keysize_min;
325 /** maximal required key size, 0 if no limit */
326 size_t dif_keysize_max;
327 /** minimal required record size */
328 size_t dif_recsize_min;
329 /** maximal required record size, 0 if no limit */
330 size_t dif_recsize_max;
331 /** pointer size for record */
335 enum dt_index_flags {
336 /** index supports variable sized keys */
337 DT_IND_VARKEY = BIT(0),
338 /** index supports variable sized records */
339 DT_IND_VARREC = BIT(1),
340 /** index can be modified */
341 DT_IND_UPDATE = BIT(2),
342 /** index supports records with non-unique (duplicate) keys */
343 DT_IND_NONUNQ = BIT(3),
345 * index support fixed-size keys sorted with natural numerical way
346 * and is able to return left-side value if no exact value found
348 DT_IND_RANGE = BIT(4),
351 /* for dt_read_lock() and dt_write_lock() object lock rule */
352 enum dt_object_role {
362 * Features, required from index to support file system directories (mapping
365 extern const struct dt_index_features dt_directory_features;
366 extern const struct dt_index_features dt_otable_features;
367 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
368 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
369 extern const struct dt_index_features dt_lfsck_namespace_features;
371 /* index features supported by the accounting objects */
372 extern const struct dt_index_features dt_acct_features;
374 /* index features supported by the quota global indexes */
375 extern const struct dt_index_features dt_quota_glb_features;
377 /* index features supported by the quota slave indexes */
378 extern const struct dt_index_features dt_quota_slv_features;
380 /* index features supported by the nodemap index */
381 extern const struct dt_index_features dt_nodemap_features;
384 * This is a general purpose dt allocation hint.
385 * It now contains the parent object.
386 * It can contain any allocation hint in the future.
388 struct dt_allocation_hint {
389 struct dt_object *dah_parent;
390 const void *dah_eadata;
393 int dah_append_stripes;
394 char *dah_append_pool;
398 * object type specifier.
401 enum dt_format_type {
406 /** for special index */
408 /** for symbolic link */
413 * object format specifier.
415 struct dt_object_format {
416 /** type for dt object */
417 enum dt_format_type dof_type;
427 * special index need feature as parameter to create
431 const struct dt_index_features *di_feat;
436 enum dt_format_type dt_mode_to_dft(__u32 mode);
438 typedef __u64 dt_obj_version_t;
440 union ldlm_policy_data;
442 struct md_layout_change;
445 * A dt_object provides common operations to create and destroy
446 * objects and to manage regular and extended attributes.
448 struct dt_object_operations {
450 * Get read lock on object.
452 * Read lock is compatible with other read locks, so it's shared.
453 * Read lock is not compatible with write lock which is exclusive.
454 * The lock is blocking and can't be used from an interrupt context.
456 * \param[in] env execution environment for this thread
457 * \param[in] dt object to lock for reading
458 * \param[in] role a hint to debug locks (see kernel's mutexes)
460 void (*do_read_lock)(const struct lu_env *env,
461 struct dt_object *dt,
465 * Get write lock on object.
467 * Write lock is exclusive and cannot be shared. The lock is blocking
468 * and can't be used from an interrupt context.
470 * \param[in] env execution environment for this thread
471 * \param[in] dt object to lock for writing
472 * \param[in] role a hint to debug locks (see kernel's mutexes)
475 void (*do_write_lock)(const struct lu_env *env,
476 struct dt_object *dt,
482 * \param[in] env execution environment for this thread
483 * \param[in] dt object
485 void (*do_read_unlock)(const struct lu_env *env,
486 struct dt_object *dt);
489 * Release write lock.
491 * \param[in] env execution environment for this thread
492 * \param[in] dt object
494 void (*do_write_unlock)(const struct lu_env *env,
495 struct dt_object *dt);
498 * Check whether write lock is held.
500 * The caller can learn whether write lock is held on the object
502 * \param[in] env execution environment for this thread
503 * \param[in] dt object
505 * \retval 0 no write lock
506 * \retval 1 write lock is held
508 int (*do_write_locked)(const struct lu_env *env,
509 struct dt_object *dt);
512 * Declare intention to request reqular attributes.
514 * Notity the underlying filesystem that the caller may request regular
515 * attributes with ->do_attr_get() soon. This allows OSD to implement
516 * prefetching logic in an object-oriented manner. The implementation
517 * can be noop. This method should avoid expensive delays such as
518 * waiting on disk I/O, otherwise the goal of enabling a performance
519 * optimization would be defeated.
521 * \param[in] env execution environment for this thread
522 * \param[in] dt object
524 * \retval 0 on success
525 * \retval negative negated errno on error
527 int (*do_declare_attr_get)(const struct lu_env *env,
528 struct dt_object *dt);
531 * Return regular attributes.
533 * The object must exist. Currently all the attributes should be
534 * returned, but in the future this can be improved so that only
535 * a selected set is returned. This can improve performance as in
536 * some cases attributes are stored in different places and
537 * getting them all can be an iterative and expensive process.
539 * \param[in] env execution environment for this thread
540 * \param[in] dt object
541 * \param[out] attr attributes to fill
543 * \retval 0 on success
544 * \retval negative negated errno on error
546 int (*do_attr_get)(const struct lu_env *env,
547 struct dt_object *dt,
548 struct lu_attr *attr);
551 * Declare intention to change regular object's attributes.
553 * Notify the underlying filesystem that the regular attributes may
554 * change in this transaction. This enables the layer below to prepare
555 * resources (e.g. journal credits in ext4). This method should be
556 * called between creating the transaction and starting it. Note that
557 * the la_valid field of \a attr specifies which attributes will change.
558 * The object need not exist.
560 * \param[in] env execution environment for this thread
561 * \param[in] dt object
562 * \param[in] attr attributes to change specified in attr.la_valid
563 * \param[in] th transaction handle
565 * \retval 0 on success
566 * \retval negative negated errno on error
568 int (*do_declare_attr_set)(const struct lu_env *env,
569 struct dt_object *dt,
570 const struct lu_attr *attr,
574 * Change regular attributes.
576 * Change regular attributes in the given transaction. Note only
577 * attributes flagged by attr.la_valid change. The object must
578 * exist. If the layer implementing this method is responsible for
579 * quota, then the method should maintain object accounting for the
580 * given credentials when la_uid/la_gid changes.
582 * \param[in] env execution environment for this thread
583 * \param[in] dt object
584 * \param[in] attr new attributes to apply
585 * \param[in] th transaction handle
587 * \retval 0 on success
588 * \retval negative negated errno on error
590 int (*do_attr_set)(const struct lu_env *env,
591 struct dt_object *dt,
592 const struct lu_attr *attr,
596 * Declare intention to request extented attribute.
598 * Notify the underlying filesystem that the caller may request extended
599 * attribute with ->do_xattr_get() soon. This allows OSD to implement
600 * prefetching logic in an object-oriented manner. The implementation
601 * can be noop. This method should avoid expensive delays such as
602 * waiting on disk I/O, otherwise the goal of enabling a performance
603 * optimization would be defeated.
605 * \param[in] env execution environment for this thread
606 * \param[in] dt object
607 * \param[in] buf unused, may be removed in the future
608 * \param[in] name name of the extended attribute
610 * \retval 0 on success
611 * \retval negative negated errno on error
613 int (*do_declare_xattr_get)(const struct lu_env *env,
614 struct dt_object *dt,
619 * Return a value of an extended attribute.
621 * The object must exist. If the buffer is NULL, then the method
622 * must return the size of the value.
624 * \param[in] env execution environment for this thread
625 * \param[in] dt object
626 * \param[out] buf buffer in which to store the value
627 * \param[in] name name of the extended attribute
629 * \retval 0 on success
630 * \retval -ERANGE if \a buf is too small
631 * \retval negative negated errno on error
632 * \retval positive value's size if \a buf is NULL or has zero size
634 int (*do_xattr_get)(const struct lu_env *env,
635 struct dt_object *dt,
640 * Declare intention to change an extended attribute.
642 * Notify the underlying filesystem that the extended attribute may
643 * change in this transaction. This enables the layer below to prepare
644 * resources (e.g. journal credits in ext4). This method should be
645 * called between creating the transaction and starting it. The object
648 * \param[in] env execution environment for this thread
649 * \param[in] dt object
650 * \param[in] buf buffer storing new value of the attribute
651 * \param[in] name name of the attribute
652 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
653 * LU_XATTR_REPLACE - fail if EA doesn't exist
654 * \param[in] th transaction handle
656 * \retval 0 on success
657 * \retval negative negated errno on error
659 int (*do_declare_xattr_set)(const struct lu_env *env,
660 struct dt_object *dt,
661 const struct lu_buf *buf,
667 * Set an extended attribute.
669 * Change or replace the specified extended attribute (EA).
670 * The flags passed in \a fl dictate whether the EA is to be
671 * created or replaced, as follows.
672 * LU_XATTR_CREATE - fail if EA exists
673 * LU_XATTR_REPLACE - fail if EA doesn't exist
674 * The object must exist.
676 * \param[in] env execution environment for this thread
677 * \param[in] dt object
678 * \param[in] buf buffer storing new value of the attribute
679 * \param[in] name name of the attribute
680 * \param[in] fl flags indicating EA creation or replacement
681 * \param[in] th transaction handle
683 * \retval 0 on success
684 * \retval negative negated errno on error
686 int (*do_xattr_set)(const struct lu_env *env,
687 struct dt_object *dt,
688 const struct lu_buf *buf,
694 * Declare intention to delete an extended attribute.
696 * Notify the underlying filesystem that the extended attribute may
697 * be deleted in this transaction. This enables the layer below to
698 * prepare resources (e.g. journal credits in ext4). This method
699 * should be called between creating the transaction and starting it.
700 * The object need not exist.
702 * \param[in] env execution environment for this thread
703 * \param[in] dt object
704 * \param[in] name name of the attribute
705 * \param[in] th transaction handle
707 * \retval 0 on success
708 * \retval negative negated errno on error
710 int (*do_declare_xattr_del)(const struct lu_env *env,
711 struct dt_object *dt,
716 * Delete an extended attribute.
718 * This method deletes the specified extended attribute. The object
721 * \param[in] env execution environment for this thread
722 * \param[in] dt object
723 * \param[in] name name of the attribute
724 * \param[in] th transaction handle
726 * \retval 0 on success
727 * \retval negative negated errno on error
729 int (*do_xattr_del)(const struct lu_env *env,
730 struct dt_object *dt,
735 * Return a list of the extended attributes.
737 * Fills the passed buffer with a list of the extended attributes
738 * found in the object. The names are separated with '\0'.
739 * The object must exist.
741 * \param[in] env execution environment for this thread
742 * \param[in] dt object
743 * \param[out] buf buffer to put the list in
745 * \retval positive bytes used/required in the buffer
746 * \retval negative negated errno on error
748 int (*do_xattr_list)(const struct lu_env *env,
749 struct dt_object *dt,
750 const struct lu_buf *buf);
753 * Prepare allocation hint for a new object.
755 * This method is used by the caller to inform OSD of the parent-child
756 * relationship between two objects and enable efficient object
757 * allocation. Filled allocation hint will be passed to ->do_create()
760 * \param[in] env execution environment for this thread
761 * \param[out] ah allocation hint
762 * \param[in] parent parent object (can be NULL)
763 * \param[in] child child object
764 * \param[in] _mode type of the child object
766 void (*do_ah_init)(const struct lu_env *env,
767 struct dt_allocation_hint *ah,
768 struct dt_object *parent,
769 struct dt_object *child,
773 * Declare intention to create a new object.
775 * Notify the underlying filesystem that the object may be created
776 * in this transaction. This enables the layer below to prepare
777 * resources (e.g. journal credits in ext4). This method should be
778 * called between creating the transaction and starting it.
780 * If the layer implementing this method is responsible for quota,
781 * then the method should reserve an object for the given credentials
782 * and return an error if quota is over. If object creation later
783 * fails for some reason, then the reservation should be released
784 * properly (usually in ->dt_trans_stop()).
786 * \param[in] env execution environment for this thread
787 * \param[in] dt object
788 * \param[in] attr attributes of the new object
789 * \param[in] hint allocation hint
790 * \param[in] dof object format
791 * \param[in] th transaction handle
793 * \retval 0 on success
794 * \retval negative negated errno on error
796 int (*do_declare_create)(const struct lu_env *env,
797 struct dt_object *dt,
798 struct lu_attr *attr,
799 struct dt_allocation_hint *hint,
800 struct dt_object_format *dof,
806 * The method creates the object passed with the specified attributes
807 * and object format. Object allocation procedure can use information
808 * stored in the allocation hint. Different object formats are supported
809 * (see enum dt_format_type and struct dt_object_format) depending on
810 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
811 * in the LU-object header attributes.
813 * If the layer implementing this method is responsible for quota,
814 * then the method should maintain object accounting for the given
817 * \param[in] env execution environment for this thread
818 * \param[in] dt object
819 * \param[in] attr attributes of the new object
820 * \param[in] hint allocation hint
821 * \param[in] dof object format
822 * \param[in] th transaction handle
824 * \retval 0 on success
825 * \retval negative negated errno on error
827 int (*do_create)(const struct lu_env *env,
828 struct dt_object *dt,
829 struct lu_attr *attr,
830 struct dt_allocation_hint *hint,
831 struct dt_object_format *dof,
835 * Declare intention to destroy an object.
837 * Notify the underlying filesystem that the object may be destroyed
838 * in this transaction. This enables the layer below to prepare
839 * resources (e.g. journal credits in ext4). This method should be
840 * called between creating the transaction and starting it. The object
843 * \param[in] env execution environment for this thread
844 * \param[in] dt object
845 * \param[in] th transaction handle
847 * \retval 0 on success
848 * \retval negative negated errno on error
850 int (*do_declare_destroy)(const struct lu_env *env,
851 struct dt_object *dt,
857 * This method destroys the object and all the resources associated
858 * with the object (data, key/value pairs, extended attributes, etc).
859 * The object must exist. If destroy is successful, then flag
860 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
861 * instance of in-core object. Any subsequent access to the same FID
862 * should get another instance with no LOHA_EXIST flag set.
864 * If the layer implementing this method is responsible for quota,
865 * then the method should maintain object accounting for the given
868 * \param[in] env execution environment for this thread
869 * \param[in] dt object
870 * \param[in] th transaction handle
872 * \retval 0 on success
873 * \retval negative negated errno on error
875 int (*do_destroy)(const struct lu_env *env,
876 struct dt_object *dt,
880 * Try object as an index.
882 * Announce that this object is going to be used as an index. This
883 * operation checks that object supports indexing operations and
884 * installs appropriate dt_index_operations vector on success.
885 * Also probes for features. Operation is successful if all required
886 * features are supported. It's not possible to access the object
887 * with index methods before ->do_index_try() returns success.
889 * \param[in] env execution environment for this thread
890 * \param[in] dt object
891 * \param[in] feat index features
893 * \retval 0 on success
894 * \retval negative negated errno on error
896 int (*do_index_try)(const struct lu_env *env,
897 struct dt_object *dt,
898 const struct dt_index_features *feat);
901 * Declare intention to increment nlink count.
903 * Notify the underlying filesystem that the nlink regular attribute
904 * be changed in this transaction. This enables the layer below to
905 * prepare resources (e.g. journal credits in ext4). This method
906 * should be called between creating the transaction and starting it.
907 * The object need not exist.
909 * \param[in] env execution environment for this thread
910 * \param[in] dt object
911 * \param[in] th transaction handle
913 * \retval 0 on success
914 * \retval negative negated errno on error
916 int (*do_declare_ref_add)(const struct lu_env *env,
917 struct dt_object *dt,
923 * Increment nlink (from the regular attributes set) in the given
924 * transaction. Note the absolute limit for nlink should be learnt
925 * from struct dt_device_param::ddp_max_nlink. The object must exist.
927 * \param[in] env execution environment for this thread
928 * \param[in] dt object
929 * \param[in] th transaction handle
931 * \retval 0 on success
932 * \retval negative negated errno on error
934 int (*do_ref_add)(const struct lu_env *env,
935 struct dt_object *dt, struct thandle *th);
938 * Declare intention to decrement nlink count.
940 * Notify the underlying filesystem that the nlink regular attribute
941 * be changed in this transaction. This enables the layer below to
942 * prepare resources (e.g. journal credits in ext4). This method
943 * should be called between creating the transaction and starting it.
944 * The object need not exist.
946 * \param[in] env execution environment for this thread
947 * \param[in] dt object
948 * \param[in] th transaction handle
950 * \retval 0 on success
951 * \retval negative negated errno on error
953 int (*do_declare_ref_del)(const struct lu_env *env,
954 struct dt_object *dt,
960 * Decrement nlink (from the regular attributes set) in the given
961 * transaction. The object must exist.
963 * \param[in] env execution environment for this thread
964 * \param[in] dt object
965 * \param[in] th transaction handle
967 * \retval 0 on success
968 * \retval negative negated errno on error
970 int (*do_ref_del)(const struct lu_env *env,
971 struct dt_object *dt,
977 * The method is called to sync specified range of the object to a
978 * persistent storage. The control is returned once the operation is
979 * complete. The difference from ->do_sync() is that the object can
980 * be in-sync with the persistent storage (nothing to flush), then
981 * the method returns quickly with no I/O overhead. So, this method
982 * should be preferred over ->do_sync() where possible. Also note that
983 * if the object isn't clean, then some disk filesystems will call
984 * ->do_sync() to maintain overall consistency, in which case it's
985 * still very expensive.
987 * \param[in] env execution environment for this thread
988 * \param[in] dt object
989 * \param[in] start start of the range to sync
990 * \param[in] end end of the range to sync
992 * \retval 0 on success
993 * \retval negative negated errno on error
995 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
996 __u64 start, __u64 end);
1001 * Lock object(s) using Distributed Lock Manager (LDLM).
1003 * Get LDLM locks for the object. Currently used to lock "remote"
1004 * objects in DNE configuration - a service running on MDTx needs
1005 * to lock an object on MDTy.
1007 * \param[in] env execution environment for this thread
1008 * \param[in] dt object
1009 * \param[out] lh lock handle, sometimes used, sometimes not
1010 * \param[in] einfo ldlm callbacks, locking type and mode
1011 * \param[out] einfo private data to be passed to unlock later
1012 * \param[in] policy inodebits data
1014 * \retval 0 on success
1015 * \retval negative negated errno on error
1017 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1018 struct lustre_handle *lh,
1019 struct ldlm_enqueue_info *einfo,
1020 union ldlm_policy_data *policy);
1025 * Release LDLM lock(s) granted with ->do_object_lock().
1027 * \param[in] env execution environment for this thread
1028 * \param[in] dt object
1029 * \param[in] einfo lock handles, from ->do_object_lock()
1030 * \param[in] policy inodebits data
1032 * \retval 0 on success
1033 * \retval negative negated errno on error
1035 int (*do_object_unlock)(const struct lu_env *env,
1036 struct dt_object *dt,
1037 struct ldlm_enqueue_info *einfo,
1038 union ldlm_policy_data *policy);
1041 * Invalidate attribute cache.
1043 * This method invalidate attribute cache of the object, which is on OSP
1046 * \param[in] env execution envionment for this thread
1047 * \param[in] dt object
1049 * \retval 0 on success
1050 * \retval negative negated errno on error
1052 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1055 * Declare intention to instaintiate extended layout component.
1057 * \param[in] env execution environment
1058 * \param[in] dt DT object
1059 * \param[in] layout data structure to describe the changes to
1060 * the DT object's layout
1061 * \param[in] buf buffer containing client's lovea or empty
1064 * \retval -ne error code
1066 int (*do_declare_layout_change)(const struct lu_env *env,
1067 struct dt_object *dt,
1068 struct md_layout_change *mlc,
1069 struct thandle *th);
1072 * Client is trying to write to un-instantiated layout component.
1074 * \param[in] env execution environment
1075 * \param[in] dt DT object
1076 * \param[in] layout data structure to describe the changes to
1077 * the DT object's layout
1078 * \param[in] buf buffer containing client's lovea or empty
1081 * \retval -ne error code
1083 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1084 struct md_layout_change *mlc,
1085 struct thandle *th);
1089 DT_BUFS_TYPE_READ = 0x0000,
1090 DT_BUFS_TYPE_WRITE = 0x0001,
1091 DT_BUFS_TYPE_READAHEAD = 0x0002,
1092 DT_BUFS_TYPE_LOCAL = 0x0004,
1096 * Per-dt-object operations on "file body" - unstructure raw data.
1098 struct dt_body_operations {
1102 * Read unstructured data from an existing regular object.
1103 * Only data before attr.la_size is returned.
1105 * \param[in] env execution environment for this thread
1106 * \param[in] dt object
1107 * \param[out] buf buffer (including size) to copy data in
1108 * \param[in] pos position in the object to start
1109 * \param[out] pos original value of \a pos + bytes returned
1111 * \retval positive bytes read on success
1112 * \retval negative negated errno on error
1114 ssize_t (*dbo_read)(const struct lu_env *env,
1115 struct dt_object *dt,
1120 * Declare intention to write data to object.
1122 * Notify the underlying filesystem that data may be written in
1123 * this transaction. This enables the layer below to prepare resources
1124 * (e.g. journal credits in ext4). This method should be called
1125 * between creating the transaction and starting it. The object need
1126 * not exist. If the layer implementing this method is responsible for
1127 * quota, then the method should reserve space for the given credentials
1128 * and return an error if quota is over. If the write later fails
1129 * for some reason, then the reserve should be released properly
1130 * (usually in ->dt_trans_stop()).
1132 * \param[in] env execution environment for this thread
1133 * \param[in] dt object
1134 * \param[in] buf buffer (including size) to copy data from
1135 * \param[in] pos position in the object to start
1136 * \param[in] th transaction handle
1138 * \retval 0 on success
1139 * \retval negative negated errno on error
1141 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1142 struct dt_object *dt,
1143 const struct lu_buf *buf,
1145 struct thandle *th);
1148 * Write unstructured data to regular existing object.
1150 * The method allocates space and puts data in. Also, the method should
1151 * maintain attr.la_size properly. Partial writes are possible.
1153 * If the layer implementing this method is responsible for quota,
1154 * then the method should maintain space accounting for the given
1157 * \param[in] env execution environment for this thread
1158 * \param[in] dt object
1159 * \param[in] buf buffer (including size) to copy data from
1160 * \param[in] pos position in the object to start
1161 * \param[out] pos \a pos + bytes written
1162 * \param[in] th transaction handle
1164 * \retval positive bytes written on success
1165 * \retval negative negated errno on error
1167 ssize_t (*dbo_write)(const struct lu_env *env,
1168 struct dt_object *dt,
1169 const struct lu_buf *buf,
1171 struct thandle *th);
1174 * Return buffers for data.
1176 * This method is used to access data with no copying. It's so-called
1177 * zero-copy I/O. The method returns the descriptors for the internal
1178 * buffers where data are managed by the disk filesystem. For example,
1179 * pagecache in case of ext4 or ARC with ZFS. Then other components
1180 * (e.g. networking) can transfer data from or to the buffers with no
1181 * additional copying.
1183 * The method should fill an array of struct niobuf_local, where
1184 * each element describes a full or partial page for data at specific
1185 * offset. The caller should use page/lnb_page_offset/len to find data
1186 * at object's offset lnb_file_offset.
1188 * The memory referenced by the descriptors can't change its purpose
1189 * until the complementary ->dbo_bufs_put() is called. The caller should
1190 * specify if the buffers are used to read or modify data so that OSD
1191 * can decide how to initialize the buffers: bring all the data for
1192 * reads or just bring partial buffers for write. Note: the method does
1193 * not check whether output array is large enough.
1195 * \param[in] env execution environment for this thread
1196 * \param[in] dt object
1197 * \param[in] pos position in the object to start
1198 * \param[in] len size of region in bytes
1199 * \param[out] lb array of descriptors to fill
1200 * \param[in] maxlnb max slots in @lnb array
1201 * \param[in] rw 0 if used to read, 1 if used for write
1203 * \retval positive number of descriptors on success
1204 * \retval negative negated errno on error
1206 int (*dbo_bufs_get)(const struct lu_env *env,
1207 struct dt_object *dt,
1210 struct niobuf_local *lb,
1212 enum dt_bufs_type rw);
1215 * Release reference granted by ->dbo_bufs_get().
1217 * Release the reference granted by the previous ->dbo_bufs_get().
1218 * Note the references are counted.
1220 * \param[in] env execution environment for this thread
1221 * \param[in] dt object
1222 * \param[out] lb array of descriptors to fill
1223 * \param[in] nr size of the array
1225 * \retval 0 on success
1226 * \retval negative negated errno on error
1228 int (*dbo_bufs_put)(const struct lu_env *env,
1229 struct dt_object *dt,
1230 struct niobuf_local *lb,
1234 * Prepare buffers for reading.
1236 * The method is called on the given buffers to fill them with data
1237 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1238 * caller should be able to get few buffers for discontiguous regions
1239 * using few calls to ->dbo_bufs_get() and then request them all for
1240 * the preparation with a single call, so that OSD can fire many I/Os
1241 * to run concurrently. It's up to the specific OSD whether to implement
1242 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1243 * prepare data for every requested region individually.
1245 * \param[in] env execution environment for this thread
1246 * \param[in] dt object
1247 * \param[in] lnb array of buffer descriptors
1248 * \param[in] nr size of the array
1250 * \retval 0 on success
1251 * \retval negative negated errno on error
1253 int (*dbo_read_prep)(const struct lu_env *env,
1254 struct dt_object *dt,
1255 struct niobuf_local *lnb,
1259 * Prepare buffers for write.
1261 * This method is called on the given buffers to ensure the partial
1262 * buffers contain correct data. The underlying idea is the same as
1263 * in ->db_read_prep().
1265 * \param[in] env execution environment for this thread
1266 * \param[in] dt object
1267 * \param[in] lb array of buffer descriptors
1268 * \param[in] nr size of the array
1270 * \retval 0 on success
1271 * \retval negative negated errno on error
1273 int (*dbo_write_prep)(const struct lu_env *env,
1274 struct dt_object *dt,
1275 struct niobuf_local *lb,
1279 * Declare intention to write data stored in the buffers.
1281 * Notify the underlying filesystem that data may be written in
1282 * this transaction. This enables the layer below to prepare resources
1283 * (e.g. journal credits in ext4). This method should be called
1284 * between creating the transaction and starting it.
1286 * If the layer implementing this method is responsible for quota,
1287 * then the method should be reserving a space for the given
1288 * credentials and return an error if quota is exceeded. If the write
1289 * later fails for some reason, then the reserve should be released
1290 * properly (usually in ->dt_trans_stop()).
1292 * \param[in] env execution environment for this thread
1293 * \param[in] dt object
1294 * \param[in] lb array of descriptors
1295 * \param[in] nr size of the array
1296 * \param[in] th transaction handle
1298 * \retval 0 on success
1299 * \retval negative negated errno on error
1301 int (*dbo_declare_write_commit)(const struct lu_env *env,
1302 struct dt_object *dt,
1303 struct niobuf_local *lb,
1305 struct thandle *th);
1308 * Write to existing object.
1310 * This method is used to write data to a persistent storage using
1311 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1312 * data into the buffers using own mechanisms (e.g. direct transfer
1313 * from a NIC). The method should maintain attr.la_size. Also,
1314 * attr.la_blocks should be maintained but this can be done in lazy
1315 * manner, when actual allocation happens.
1317 * If the layer implementing this method is responsible for quota,
1318 * then the method should maintain space accounting for the given
1321 * user_size parameter is the apparent size of the file, ie the size
1322 * of the clear text version of the file. It can differ from the actual
1323 * amount of valuable data received when a file is encrypted,
1324 * because encrypted pages always contain PAGE_SIZE bytes of data,
1325 * even if clear text data is only a few bytes.
1326 * In case of encrypted file, apparent size will be stored as the inode
1327 * size, so that servers return to clients an object size they can use
1328 * to determine clear text size.
1330 * \param[in] env execution environment for this thread
1331 * \param[in] dt object
1332 * \param[in] lb array of descriptors for the buffers
1333 * \param[in] nr size of the array
1334 * \param[in] th transaction handle
1335 * \param[in] user_size apparent size
1337 * \retval 0 on success
1338 * \retval negative negated errno on error
1340 int (*dbo_write_commit)(const struct lu_env *env,
1341 struct dt_object *dt,
1342 struct niobuf_local *lb,
1348 * Return logical to physical block mapping for a given extent
1350 * \param[in] env execution environment for this thread
1351 * \param[in] dt object
1352 * \param[in] fm describe the region to map and the output buffer
1353 * see the details in include/linux/fiemap.h
1355 * \retval 0 on success
1356 * \retval negative negated errno on error
1358 int (*dbo_fiemap_get)(const struct lu_env *env,
1359 struct dt_object *dt,
1363 * Declare intention to deallocate space from an object.
1365 * Notify the underlying filesystem that space may be deallocated in
1366 * this transactions. This enables the layer below to prepare resources
1367 * (e.g. journal credits in ext4). This method should be called between
1368 * creating the transaction and starting it. The object need not exist.
1370 * \param[in] env execution environment for this thread
1371 * \param[in] dt object
1372 * \param[in] start the start of the region to deallocate
1373 * \param[in] end the end of the region to deallocate
1374 * \param[in] th transaction handle
1376 * \retval 0 on success
1377 * \retval negative negated errno on error
1379 int (*dbo_declare_punch)(const struct lu_env *env,
1380 struct dt_object *dt,
1383 struct thandle *th);
1386 * Deallocate specified region in an object.
1388 * This method is used to deallocate (release) space possibly consumed
1389 * by the given region of the object. If the layer implementing this
1390 * method is responsible for quota, then the method should maintain
1391 * space accounting for the given credentials.
1393 * \param[in] env execution environment for this thread
1394 * \param[in] dt object
1395 * \param[in] start the start of the region to deallocate
1396 * \param[in] end the end of the region to deallocate
1397 * \param[in] th transaction handle
1399 * \retval 0 on success
1400 * \retval negative negated errno on error
1402 int (*dbo_punch)(const struct lu_env *env,
1403 struct dt_object *dt,
1406 struct thandle *th);
1408 * Give advices on specified region in an object.
1410 * This method is used to give advices about access pattern on an
1411 * given region of the object. The disk filesystem understands
1412 * the advices and tunes cache/read-ahead policies.
1414 * \param[in] env execution environment for this thread
1415 * \param[in] dt object
1416 * \param[in] start the start of the region affected
1417 * \param[in] end the end of the region affected
1418 * \param[in] advice advice type
1420 * \retval 0 on success
1421 * \retval negative negated errno on error
1423 int (*dbo_ladvise)(const struct lu_env *env,
1424 struct dt_object *dt,
1427 enum lu_ladvise_type advice);
1430 * Declare intention to preallocate space for an object
1432 * \param[in] env execution environment for this thread
1433 * \param[in] dt object
1434 * \param[in] th transaction handle
1436 * \retval 0 on success
1437 * \retval negative negated errno on error
1439 int (*dbo_declare_fallocate)(const struct lu_env *env,
1440 struct dt_object *dt, __u64 start,
1441 __u64 end, int mode, struct thandle *th);
1443 * Allocate specified region for an object
1445 * \param[in] env execution environment for this thread
1446 * \param[in] dt object
1447 * \param[in] start the start of the region to allocate
1448 * \param[in] end the end of the region to allocate
1449 * \param[in] mode fallocate mode
1450 * \param[in] th transaction handle
1452 * \retval 0 on success
1453 * \retval negative negated errno on error
1455 int (*dbo_fallocate)(const struct lu_env *env,
1456 struct dt_object *dt,
1460 struct thandle *th);
1462 * Do SEEK_HOLE/SEEK_DATA request on object
1464 * \param[in] env execution environment for this thread
1465 * \param[in] dt object
1466 * \param[in] offset the offset to start seek from
1467 * \param[in] whence seek mode, SEEK_HOLE or SEEK_DATA
1469 * \retval hole/data offset on success
1470 * \retval negative negated errno on error
1472 loff_t (*dbo_lseek)(const struct lu_env *env, struct dt_object *dt,
1473 loff_t offset, int whence);
1477 * Incomplete type of index record.
1482 * Incomplete type of index key.
1487 * Incomplete type of dt iterator.
1492 * Per-dt-object operations on object as index. Index is a set of key/value
1493 * pairs abstracted from an on-disk representation. An index supports the
1494 * number of operations including lookup by key, insert and delete. Also,
1495 * an index can be iterated to find the pairs one by one, from a beginning
1496 * or specified point.
1498 struct dt_index_operations {
1500 * Lookup in an index by key.
1502 * The method returns a value for the given key. Key/value format
1503 * and size should have been negotiated with ->do_index_try() before.
1504 * Thus it's the caller's responsibility to provide the method with
1505 * proper key and big enough buffer. No external locking is required,
1506 * all the internal consistency should be implemented by the method
1507 * or lower layers. The object should should have been created with
1508 * type DFT_INDEX or DFT_DIR.
1510 * \param[in] env execution environment for this thread
1511 * \param[in] dt object
1512 * \param[out] rec buffer where value will be stored
1513 * \param[in] key key
1515 * \retval 0 on success
1516 * \retval -ENOENT if key isn't found
1517 * \retval negative negated errno on error
1519 int (*dio_lookup)(const struct lu_env *env,
1520 struct dt_object *dt,
1522 const struct dt_key *key);
1525 * Declare intention to insert a key/value into an index.
1527 * Notify the underlying filesystem that new key/value may be inserted
1528 * in this transaction. This enables the layer below to prepare
1529 * resources (e.g. journal credits in ext4). This method should be
1530 * called between creating the transaction and starting it. key/value
1531 * format and size is subject to ->do_index_try().
1533 * \param[in] env execution environment for this thread
1534 * \param[in] dt object
1535 * \param[in] rec buffer storing value
1536 * \param[in] key key
1537 * \param[in] th transaction handle
1539 * \retval 0 on success
1540 * \retval negative negated errno on error
1542 int (*dio_declare_insert)(const struct lu_env *env,
1543 struct dt_object *dt,
1544 const struct dt_rec *rec,
1545 const struct dt_key *key,
1546 struct thandle *th);
1549 * Insert a new key/value pair into an index.
1551 * The method inserts specified key/value pair into the given index
1552 * object. The internal consistency is maintained by the method or
1553 * the functionality below. The format and size of key/value should
1554 * have been negotiated before using ->do_index_try(), no additional
1555 * information can be specified to the method. The keys are unique
1558 * \param[in] env execution environment for this thread
1559 * \param[in] dt object
1560 * \param[in] rec buffer storing value
1561 * \param[in] key key
1562 * \param[in] th transaction handle
1564 * \retval 0 on success
1565 * \retval negative negated errno on error
1567 int (*dio_insert)(const struct lu_env *env,
1568 struct dt_object *dt,
1569 const struct dt_rec *rec,
1570 const struct dt_key *key,
1571 struct thandle *th);
1574 * Declare intention to delete a key/value from an index.
1576 * Notify the underlying filesystem that key/value may be deleted in
1577 * this transaction. This enables the layer below to prepare resources
1578 * (e.g. journal credits in ext4). This method should be called
1579 * between creating the transaction and starting it. Key/value format
1580 * and size is subject to ->do_index_try(). The object need not exist.
1582 * \param[in] env execution environment for this thread
1583 * \param[in] dt object
1584 * \param[in] key key
1585 * \param[in] th transaction handle
1587 * \retval 0 on success
1588 * \retval negative negated errno on error
1590 int (*dio_declare_delete)(const struct lu_env *env,
1591 struct dt_object *dt,
1592 const struct dt_key *key,
1593 struct thandle *th);
1596 * Delete key/value pair from an index.
1598 * The method deletes specified key and corresponding value from the
1599 * given index object. The internal consistency is maintained by the
1600 * method or the functionality below. The format and size of the key
1601 * should have been negotiated before using ->do_index_try(), no
1602 * additional information can be specified to the method.
1604 * \param[in] env execution environment for this thread
1605 * \param[in] dt object
1606 * \param[in] key key
1607 * \param[in] th transaction handle
1609 * \retval 0 on success
1610 * \retval negative negated errno on error
1612 int (*dio_delete)(const struct lu_env *env,
1613 struct dt_object *dt,
1614 const struct dt_key *key,
1615 struct thandle *th);
1618 * Iterator interface.
1620 * Methods to iterate over an existing index, list the keys stored and
1621 * associated values, get key/value size, etc.
1625 * Allocate and initialize new iterator.
1627 * The iterator is a handler to be used in the subsequent
1628 * methods to access index's content. Note the position is
1629 * not defined at this point and should be initialized with
1630 * ->get() or ->load() method.
1632 * \param[in] env execution environment for this thread
1633 * \param[in] dt object
1634 * \param[in] attr ask the iterator to return part of
1635 the records, see LUDA_* for details
1637 * \retval pointer iterator pointer on success
1638 * \retval ERR_PTR(errno) on error
1640 struct dt_it *(*init)(const struct lu_env *env,
1641 struct dt_object *dt,
1647 * Release the specified iterator and all the resources
1648 * associated (e.g. the object, index cache, etc).
1650 * \param[in] env execution environment for this thread
1651 * \param[in] di iterator to release
1653 void (*fini)(const struct lu_env *env,
1657 * Move position of iterator.
1659 * Move the position of the specified iterator to the specified
1662 * \param[in] env execution environment for this thread
1663 * \param[in] di iterator
1664 * \param[in] key key to position to
1666 * \retval 0 if exact key is found
1667 * \retval 1 if at the record with least key
1668 * not larger than the key
1669 * \retval negative negated errno on error
1671 int (*get)(const struct lu_env *env,
1673 const struct dt_key *key);
1678 * Complimentary method for dt_it_ops::get() above. Some
1679 * implementation can increase a reference on the iterator in
1680 * dt_it_ops::get(). So the caller should be able to release
1681 * with dt_it_ops::put().
1683 * \param[in] env execution environment for this thread
1684 * \param[in] di iterator
1686 void (*put)(const struct lu_env *env,
1690 * Move to next record.
1692 * Moves the position of the iterator to a next record
1694 * \param[in] env execution environment for this thread
1695 * \param[in] di iterator
1697 * \retval 1 if no more records
1698 * \retval 0 on success, the next record is found
1699 * \retval negative negated errno on error
1701 int (*next)(const struct lu_env *env,
1707 * Returns a pointer to a buffer containing the key of the
1708 * record at the current position. The pointer is valid and
1709 * retains data until ->get(), ->load() and ->fini() methods
1712 * \param[in] env execution environment for this thread
1713 * \param[in] di iterator
1715 * \retval pointer to key on success
1716 * \retval ERR_PTR(errno) on error
1718 struct dt_key *(*key)(const struct lu_env *env,
1719 const struct dt_it *di);
1724 * Returns size of the key at the current position.
1726 * \param[in] env execution environment for this thread
1727 * \param[in] di iterator
1729 * \retval key's size on success
1730 * \retval negative negated errno on error
1732 int (*key_size)(const struct lu_env *env,
1733 const struct dt_it *di);
1738 * Stores the value of the record at the current position. The
1739 * buffer must be big enough (as negotiated with
1740 * ->do_index_try() or ->rec_size()). The caller can specify
1741 * she is interested only in part of the record, using attr
1742 * argument (see LUDA_* definitions for the details).
1744 * \param[in] env execution environment for this thread
1745 * \param[in] di iterator
1746 * \param[out] rec buffer to store value in
1747 * \param[in] attr specify part of the value to copy
1749 * \retval 0 on success
1750 * \retval negative negated errno on error
1752 int (*rec)(const struct lu_env *env,
1753 const struct dt_it *di,
1758 * Return record size.
1760 * Returns size of the record at the current position. The
1761 * \a attr can be used to specify only the parts of the record
1762 * needed to be returned. (see LUDA_* definitions for the
1765 * \param[in] env execution environment for this thread
1766 * \param[in] di iterator
1767 * \param[in] attr part of the record to return
1769 * \retval record's size on success
1770 * \retval negative negated errno on error
1772 int (*rec_size)(const struct lu_env *env,
1773 const struct dt_it *di,
1777 * Return a cookie (hash).
1779 * Returns the cookie (usually hash) of the key at the current
1780 * position. This allows the caller to resume iteration at this
1781 * position later. The exact value is specific to implementation
1782 * and should not be interpreted by the caller.
1784 * \param[in] env execution environment for this thread
1785 * \param[in] di iterator
1787 * \retval cookie/hash of the key
1789 __u64 (*store)(const struct lu_env *env,
1790 const struct dt_it *di);
1793 * Initialize position using cookie/hash.
1795 * Initializes the current position of the iterator to one
1796 * described by the cookie/hash as returned by ->store()
1799 * \param[in] env execution environment for this thread
1800 * \param[in] di iterator
1801 * \param[in] hash cookie/hash value
1803 * \retval positive if current position points to
1804 * record with least cookie not larger
1806 * \retval 0 if current position matches cookie
1807 * \retval negative negated errno on error
1809 int (*load)(const struct lu_env *env,
1810 const struct dt_it *di,
1816 int (*key_rec)(const struct lu_env *env,
1817 const struct dt_it *di,
1822 enum dt_otable_it_valid {
1823 DOIV_ERROR_HANDLE = 0x0001,
1824 DOIV_DRYRUN = 0x0002,
1827 enum dt_otable_it_flags {
1828 /* Exit when fail. */
1829 DOIF_FAILOUT = 0x0001,
1831 /* Reset iteration position to the device beginning. */
1832 DOIF_RESET = 0x0002,
1834 /* There is up layer component uses the iteration. */
1835 DOIF_OUTUSED = 0x0004,
1837 /* Check only without repairing. */
1838 DOIF_DRYRUN = 0x0008,
1841 /* otable based iteration needs to use the common DT iteration APIs.
1842 * To initialize the iteration, it needs call dio_it::init() firstly.
1843 * Here is how the otable based iteration should prepare arguments to
1844 * call dt_it_ops::init().
1846 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1847 * is composed of two parts:
1848 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1849 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1850 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1853 struct lu_device dd_lu_dev;
1854 const struct dt_device_operations *dd_ops;
1857 * List of dt_txn_callback (see below). This is not protected in any
1858 * way, because callbacks are supposed to be added/deleted only during
1859 * single-threaded start-up shut-down procedures.
1861 struct list_head dd_txn_callbacks;
1862 unsigned int dd_record_fid_accessed:1,
1865 /* sysfs and debugfs handling */
1866 struct dentry *dd_debugfs_entry;
1868 const struct attribute **dd_def_attrs;
1869 struct kobject dd_kobj;
1870 struct kobj_type dd_ktype;
1871 struct completion dd_kobj_unregister;
1874 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1875 void dt_device_fini(struct dt_device *dev);
1877 static inline int lu_device_is_dt(const struct lu_device *d)
1879 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1882 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1884 LASSERT(lu_device_is_dt(l));
1885 return container_of_safe(l, struct dt_device, dd_lu_dev);
1889 struct lu_object do_lu;
1890 const struct dt_object_operations *do_ops;
1891 const struct dt_body_operations *do_body_ops;
1892 const struct dt_index_operations *do_index_ops;
1896 * In-core representation of per-device local object OID storage
1898 struct local_oid_storage {
1899 /* all initialized llog systems on this node linked by this */
1900 struct list_head los_list;
1902 /* how many handle's reference this los has */
1903 atomic_t los_refcount;
1904 struct dt_device *los_dev;
1905 struct dt_object *los_obj;
1907 /* data used to generate new fids */
1908 struct mutex los_id_lock;
1913 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1915 return &d->dd_lu_dev;
1918 static inline struct dt_object *lu2dt(struct lu_object *l)
1920 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1921 return container_of_safe(l, struct dt_object, do_lu);
1924 int dt_object_init(struct dt_object *obj,
1925 struct lu_object_header *h, struct lu_device *d);
1927 void dt_object_fini(struct dt_object *obj);
1929 static inline int dt_object_exists(const struct dt_object *dt)
1931 return lu_object_exists(&dt->do_lu);
1934 static inline int dt_object_remote(const struct dt_object *dt)
1936 return lu_object_remote(&dt->do_lu);
1939 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1941 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1942 return container_of_safe(o, struct dt_object, do_lu);
1945 static inline struct dt_object *dt_object_child(struct dt_object *o)
1947 return container_of(lu_object_next(&(o)->do_lu),
1948 struct dt_object, do_lu);
1952 * This is the general purpose transaction handle.
1953 * 1. Transaction Life Cycle
1954 * This transaction handle is allocated upon starting a new transaction,
1955 * and deallocated after this transaction is committed.
1956 * 2. Transaction Nesting
1957 * We do _NOT_ support nested transaction. So, every thread should only
1958 * have one active transaction, and a transaction only belongs to one
1959 * thread. Due to this, transaction handle need no reference count.
1960 * 3. Transaction & dt_object locking
1961 * dt_object locks should be taken inside transaction.
1962 * 4. Transaction & RPC
1963 * No RPC request should be issued inside transaction.
1966 /** the dt device on which the transactions are executed */
1967 struct dt_device *th_dev;
1969 /* point to the top thandle, XXX this is a bit hacky right now,
1970 * but normal device trans callback triggered by the bottom
1971 * device (OSP/OSD == sub thandle layer) needs to get the
1972 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1973 * top thandle here for now, will fix it when we have better
1974 * callback mechanism */
1975 struct thandle *th_top;
1977 /** the last operation result in this transaction.
1978 * this value is used in recovery */
1981 /** whether we need sync commit */
1982 unsigned int th_sync:1,
1983 /* local transation, no need to inform other layers */
1985 /* Whether we need wait the transaction to be submitted
1986 * (send to remote target) */
1988 /* complex transaction which will track updates on all targets,
1991 /* whether ignore quota */
1996 * Transaction call-backs.
1998 * These are invoked by osd (or underlying transaction engine) when
1999 * transaction changes state.
2001 * Call-backs are used by upper layers to modify transaction parameters and to
2002 * perform some actions on for each transaction state transition. Typical
2003 * example is mdt registering call-back to write into last-received file
2004 * before each transaction commit.
2006 struct dt_txn_callback {
2007 int (*dtc_txn_start)(const struct lu_env *env,
2008 struct thandle *txn, void *cookie);
2009 int (*dtc_txn_stop)(const struct lu_env *env,
2010 struct thandle *txn, void *cookie);
2013 struct list_head dtc_linkage;
2016 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
2017 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
2019 int dt_txn_hook_start(const struct lu_env *env,
2020 struct dt_device *dev, struct thandle *txn);
2021 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
2023 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
2026 * Callback function used for parsing path.
2027 * \see llo_store_resolve
2029 typedef int (*dt_entry_func_t)(const struct lu_env *env,
2033 #define DT_MAX_PATH 1024
2035 int dt_path_parser(const struct lu_env *env,
2036 char *local, dt_entry_func_t entry_func,
2040 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
2041 const char *path, struct lu_fid *fid);
2043 struct dt_object *dt_store_open(const struct lu_env *env,
2044 struct dt_device *dt,
2045 const char *dirname,
2046 const char *filename,
2047 struct lu_fid *fid);
2049 struct dt_object *dt_find_or_create(const struct lu_env *env,
2050 struct dt_device *dt,
2051 const struct lu_fid *fid,
2052 struct dt_object_format *dof,
2053 struct lu_attr *attr);
2055 struct dt_object *dt_locate_at(const struct lu_env *env,
2056 struct dt_device *dev,
2057 const struct lu_fid *fid,
2058 struct lu_device *top_dev,
2059 const struct lu_object_conf *conf);
2061 static inline struct dt_object *
2062 dt_locate(const struct lu_env *env, struct dt_device *dev,
2063 const struct lu_fid *fid)
2065 return dt_locate_at(env, dev, fid,
2066 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2069 static inline struct dt_object *
2070 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2072 struct lu_object *lo;
2074 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2075 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2076 return container_of(lo, struct dt_object, do_lu);
2081 static inline void dt_object_put(const struct lu_env *env,
2082 struct dt_object *dto)
2084 lu_object_put(env, &dto->do_lu);
2087 static inline void dt_object_put_nocache(const struct lu_env *env,
2088 struct dt_object *dto)
2090 lu_object_put_nocache(env, &dto->do_lu);
2093 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2094 const struct lu_fid *first_fid,
2095 struct local_oid_storage **los);
2096 void local_oid_storage_fini(const struct lu_env *env,
2097 struct local_oid_storage *los);
2098 int local_object_fid_generate(const struct lu_env *env,
2099 struct local_oid_storage *los,
2100 struct lu_fid *fid);
2101 int local_object_declare_create(const struct lu_env *env,
2102 struct local_oid_storage *los,
2103 struct dt_object *o,
2104 struct lu_attr *attr,
2105 struct dt_object_format *dof,
2106 struct thandle *th);
2107 int local_object_create(const struct lu_env *env,
2108 struct local_oid_storage *los,
2109 struct dt_object *o,
2110 struct lu_attr *attr, struct dt_object_format *dof,
2111 struct thandle *th);
2112 struct dt_object *local_file_find(const struct lu_env *env,
2113 struct local_oid_storage *los,
2114 struct dt_object *parent,
2116 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2117 struct local_oid_storage *los,
2118 struct dt_object *parent,
2119 const char *name, __u32 mode);
2120 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2121 struct dt_device *dt,
2122 const struct lu_fid *fid,
2123 struct dt_object *parent,
2127 local_index_find_or_create(const struct lu_env *env,
2128 struct local_oid_storage *los,
2129 struct dt_object *parent,
2130 const char *name, __u32 mode,
2131 const struct dt_index_features *ft);
2133 local_index_find_or_create_with_fid(const struct lu_env *env,
2134 struct dt_device *dt,
2135 const struct lu_fid *fid,
2136 struct dt_object *parent,
2137 const char *name, __u32 mode,
2138 const struct dt_index_features *ft);
2139 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2140 struct dt_object *parent, const char *name);
2142 static inline int dt_object_lock(const struct lu_env *env,
2143 struct dt_object *o, struct lustre_handle *lh,
2144 struct ldlm_enqueue_info *einfo,
2145 union ldlm_policy_data *policy)
2148 LASSERT(o->do_ops != NULL);
2149 LASSERT(o->do_ops->do_object_lock != NULL);
2150 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2153 static inline int dt_object_unlock(const struct lu_env *env,
2154 struct dt_object *o,
2155 struct ldlm_enqueue_info *einfo,
2156 union ldlm_policy_data *policy)
2159 LASSERT(o->do_ops != NULL);
2160 LASSERT(o->do_ops->do_object_unlock != NULL);
2161 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2164 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2165 const char *name, struct lu_fid *fid);
2167 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2168 __u64 start, __u64 end)
2172 LASSERT(o->do_ops->do_object_sync);
2173 return o->do_ops->do_object_sync(env, o, start, end);
2176 static inline int dt_fid_alloc(const struct lu_env *env,
2177 struct dt_device *d,
2179 struct lu_object *parent,
2180 const struct lu_name *name)
2182 struct lu_device *l = dt2lu_dev(d);
2184 return l->ld_ops->ldo_fid_alloc(env, l, fid, parent, name);
2187 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2188 struct thandle *th);
2189 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2190 dt_obj_version_t version, struct thandle *th);
2191 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2194 int dt_read(const struct lu_env *env, struct dt_object *dt,
2195 struct lu_buf *buf, loff_t *pos);
2196 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2197 struct lu_buf *buf, loff_t *pos);
2198 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2199 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2200 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2201 union lu_page *lp, size_t nob,
2202 const struct dt_it_ops *iops,
2203 struct dt_it *it, __u32 attr, void *arg);
2204 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2205 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2207 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2208 struct idx_info *ii, const struct lu_rdpg *rdpg);
2210 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2211 struct dt_device *d)
2213 LASSERT(d->dd_ops->dt_trans_create);
2214 return d->dd_ops->dt_trans_create(env, d);
2217 static inline int dt_trans_start(const struct lu_env *env,
2218 struct dt_device *d, struct thandle *th)
2220 LASSERT(d->dd_ops->dt_trans_start);
2221 return d->dd_ops->dt_trans_start(env, d, th);
2224 /* for this transaction hooks shouldn't be called */
2225 static inline int dt_trans_start_local(const struct lu_env *env,
2226 struct dt_device *d, struct thandle *th)
2228 LASSERT(d->dd_ops->dt_trans_start);
2230 return d->dd_ops->dt_trans_start(env, d, th);
2233 static inline int dt_trans_stop(const struct lu_env *env,
2234 struct dt_device *d, struct thandle *th)
2236 LASSERT(d->dd_ops->dt_trans_stop);
2237 return d->dd_ops->dt_trans_stop(env, d, th);
2240 static inline int dt_trans_cb_add(struct thandle *th,
2241 struct dt_txn_commit_cb *dcb)
2243 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2244 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2245 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2250 static inline int dt_declare_record_write(const struct lu_env *env,
2251 struct dt_object *dt,
2252 const struct lu_buf *buf,
2258 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2259 LASSERT(th != NULL);
2260 LASSERTF(dt->do_body_ops, DFID" doesn't exit\n",
2261 PFID(lu_object_fid(&dt->do_lu)));
2262 LASSERT(dt->do_body_ops->dbo_declare_write);
2263 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2267 static inline int dt_declare_create(const struct lu_env *env,
2268 struct dt_object *dt,
2269 struct lu_attr *attr,
2270 struct dt_allocation_hint *hint,
2271 struct dt_object_format *dof,
2275 LASSERT(dt->do_ops);
2276 LASSERT(dt->do_ops->do_declare_create);
2278 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2279 return cfs_fail_err;
2281 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2284 static inline int dt_create(const struct lu_env *env,
2285 struct dt_object *dt,
2286 struct lu_attr *attr,
2287 struct dt_allocation_hint *hint,
2288 struct dt_object_format *dof,
2292 LASSERT(dt->do_ops);
2293 LASSERT(dt->do_ops->do_create);
2295 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2296 return cfs_fail_err;
2298 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2301 static inline int dt_declare_destroy(const struct lu_env *env,
2302 struct dt_object *dt,
2306 LASSERT(dt->do_ops);
2307 LASSERT(dt->do_ops->do_declare_destroy);
2309 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2310 return cfs_fail_err;
2312 return dt->do_ops->do_declare_destroy(env, dt, th);
2315 static inline int dt_destroy(const struct lu_env *env,
2316 struct dt_object *dt,
2320 LASSERT(dt->do_ops);
2321 LASSERT(dt->do_ops->do_destroy);
2323 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2324 return cfs_fail_err;
2326 return dt->do_ops->do_destroy(env, dt, th);
2329 static inline void dt_read_lock(const struct lu_env *env,
2330 struct dt_object *dt,
2334 LASSERT(dt->do_ops);
2335 LASSERT(dt->do_ops->do_read_lock);
2336 dt->do_ops->do_read_lock(env, dt, role);
2339 static inline void dt_write_lock(const struct lu_env *env,
2340 struct dt_object *dt,
2344 LASSERT(dt->do_ops);
2345 LASSERT(dt->do_ops->do_write_lock);
2346 dt->do_ops->do_write_lock(env, dt, role);
2349 static inline void dt_read_unlock(const struct lu_env *env,
2350 struct dt_object *dt)
2353 LASSERT(dt->do_ops);
2354 LASSERT(dt->do_ops->do_read_unlock);
2355 dt->do_ops->do_read_unlock(env, dt);
2358 static inline void dt_write_unlock(const struct lu_env *env,
2359 struct dt_object *dt)
2362 LASSERT(dt->do_ops);
2363 LASSERT(dt->do_ops->do_write_unlock);
2364 dt->do_ops->do_write_unlock(env, dt);
2367 static inline int dt_write_locked(const struct lu_env *env,
2368 struct dt_object *dt)
2371 LASSERT(dt->do_ops);
2372 LASSERT(dt->do_ops->do_write_locked);
2373 return dt->do_ops->do_write_locked(env, dt);
2376 static inline int dt_declare_attr_get(const struct lu_env *env,
2377 struct dt_object *dt)
2380 LASSERT(dt->do_ops);
2381 LASSERT(dt->do_ops->do_declare_attr_get);
2383 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2384 return cfs_fail_err;
2386 return dt->do_ops->do_declare_attr_get(env, dt);
2389 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2393 LASSERT(dt->do_ops);
2394 LASSERT(dt->do_ops->do_attr_get);
2396 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2397 return cfs_fail_err;
2399 return dt->do_ops->do_attr_get(env, dt, la);
2402 static inline int dt_declare_attr_set(const struct lu_env *env,
2403 struct dt_object *dt,
2404 const struct lu_attr *la,
2408 LASSERT(dt->do_ops);
2409 LASSERT(dt->do_ops->do_declare_attr_set);
2411 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2412 return cfs_fail_err;
2414 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2417 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2418 const struct lu_attr *la, struct thandle *th)
2421 LASSERT(dt->do_ops);
2422 LASSERT(dt->do_ops->do_attr_set);
2424 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2425 return cfs_fail_err;
2427 return dt->do_ops->do_attr_set(env, dt, la, th);
2430 static inline int dt_declare_ref_add(const struct lu_env *env,
2431 struct dt_object *dt, struct thandle *th)
2434 LASSERT(dt->do_ops);
2435 LASSERT(dt->do_ops->do_declare_ref_add);
2437 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2438 return cfs_fail_err;
2440 return dt->do_ops->do_declare_ref_add(env, dt, th);
2443 static inline int dt_ref_add(const struct lu_env *env,
2444 struct dt_object *dt, struct thandle *th)
2447 LASSERT(dt->do_ops);
2448 LASSERT(dt->do_ops->do_ref_add);
2450 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2451 return cfs_fail_err;
2453 return dt->do_ops->do_ref_add(env, dt, th);
2456 static inline int dt_declare_ref_del(const struct lu_env *env,
2457 struct dt_object *dt, struct thandle *th)
2460 LASSERT(dt->do_ops);
2461 LASSERT(dt->do_ops->do_declare_ref_del);
2463 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2464 return cfs_fail_err;
2466 return dt->do_ops->do_declare_ref_del(env, dt, th);
2469 static inline int dt_ref_del(const struct lu_env *env,
2470 struct dt_object *dt, struct thandle *th)
2473 LASSERT(dt->do_ops);
2474 LASSERT(dt->do_ops->do_ref_del);
2476 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2477 return cfs_fail_err;
2479 return dt->do_ops->do_ref_del(env, dt, th);
2482 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2483 struct niobuf_remote *rnb,
2484 struct niobuf_local *lnb, int maxlnb,
2485 enum dt_bufs_type rw)
2488 LASSERT(d->do_body_ops);
2489 LASSERT(d->do_body_ops->dbo_bufs_get);
2490 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2491 rnb->rnb_len, lnb, maxlnb, rw);
2494 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2495 struct niobuf_local *lnb, int n)
2498 LASSERT(d->do_body_ops);
2499 LASSERT(d->do_body_ops->dbo_bufs_put);
2500 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2503 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2504 struct niobuf_local *lnb, int n)
2507 LASSERT(d->do_body_ops);
2508 LASSERT(d->do_body_ops->dbo_write_prep);
2509 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2512 static inline int dt_declare_write_commit(const struct lu_env *env,
2513 struct dt_object *d,
2514 struct niobuf_local *lnb,
2515 int n, struct thandle *th)
2517 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2518 LASSERT(th != NULL);
2519 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2523 static inline int dt_write_commit(const struct lu_env *env,
2524 struct dt_object *d, struct niobuf_local *lnb,
2525 int n, struct thandle *th, __u64 size)
2528 LASSERT(d->do_body_ops);
2529 LASSERT(d->do_body_ops->dbo_write_commit);
2530 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th, size);
2533 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2534 struct niobuf_local *lnb, int n)
2537 LASSERT(d->do_body_ops);
2538 LASSERT(d->do_body_ops->dbo_read_prep);
2539 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2542 static inline int dt_declare_write(const struct lu_env *env,
2543 struct dt_object *dt,
2544 const struct lu_buf *buf, loff_t pos,
2548 LASSERT(dt->do_body_ops);
2549 LASSERT(dt->do_body_ops->dbo_declare_write);
2550 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2553 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2554 const struct lu_buf *buf, loff_t *pos,
2558 LASSERT(dt->do_body_ops);
2559 LASSERT(dt->do_body_ops->dbo_write);
2560 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2563 static inline int dt_declare_punch(const struct lu_env *env,
2564 struct dt_object *dt, __u64 start,
2565 __u64 end, struct thandle *th)
2568 LASSERT(dt->do_body_ops);
2569 LASSERT(dt->do_body_ops->dbo_declare_punch);
2570 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2573 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2574 __u64 start, __u64 end, struct thandle *th)
2577 LASSERT(dt->do_body_ops);
2578 LASSERT(dt->do_body_ops->dbo_punch);
2579 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2582 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2583 __u64 start, __u64 end, int advice)
2586 LASSERT(dt->do_body_ops);
2587 LASSERT(dt->do_body_ops->dbo_ladvise);
2588 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2591 static inline int dt_declare_fallocate(const struct lu_env *env,
2592 struct dt_object *dt, __u64 start,
2593 __u64 end, int mode, struct thandle *th)
2596 if (!dt->do_body_ops)
2598 LASSERT(dt->do_body_ops);
2599 LASSERT(dt->do_body_ops->dbo_declare_fallocate);
2600 return dt->do_body_ops->dbo_declare_fallocate(env, dt, start, end,
2604 static inline int dt_falloc(const struct lu_env *env, struct dt_object *dt,
2605 __u64 start, __u64 end, int mode,
2609 if (!dt->do_body_ops)
2611 LASSERT(dt->do_body_ops);
2612 LASSERT(dt->do_body_ops->dbo_fallocate);
2613 return dt->do_body_ops->dbo_fallocate(env, dt, start, end, mode, th);
2616 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2620 if (d->do_body_ops == NULL)
2622 if (d->do_body_ops->dbo_fiemap_get == NULL)
2624 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2627 static inline loff_t dt_lseek(const struct lu_env *env, struct dt_object *d,
2628 loff_t offset, int whence)
2631 if (d->do_body_ops == NULL)
2633 if (d->do_body_ops->dbo_lseek == NULL)
2635 return d->do_body_ops->dbo_lseek(env, d, offset, whence);
2638 static inline int dt_statfs_info(const struct lu_env *env,
2639 struct dt_device *dev,
2640 struct obd_statfs *osfs,
2641 struct obd_statfs_info *info)
2644 LASSERT(dev->dd_ops);
2645 LASSERT(dev->dd_ops->dt_statfs);
2646 return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2649 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2650 struct obd_statfs *osfs)
2652 return dt_statfs_info(env, dev, osfs, NULL);
2655 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2659 LASSERT(dev->dd_ops);
2660 LASSERT(dev->dd_ops->dt_root_get);
2661 return dev->dd_ops->dt_root_get(env, dev, f);
2664 static inline void dt_conf_get(const struct lu_env *env,
2665 const struct dt_device *dev,
2666 struct dt_device_param *param)
2669 LASSERT(dev->dd_ops);
2670 LASSERT(dev->dd_ops->dt_conf_get);
2671 return dev->dd_ops->dt_conf_get(env, dev, param);
2674 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2677 LASSERT(dev->dd_ops);
2678 if (dev->dd_ops->dt_mnt_sb_get)
2679 return dev->dd_ops->dt_mnt_sb_get(dev);
2681 return ERR_PTR(-EOPNOTSUPP);
2684 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2687 LASSERT(dev->dd_ops);
2688 LASSERT(dev->dd_ops->dt_sync);
2689 return dev->dd_ops->dt_sync(env, dev);
2692 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2695 LASSERT(dev->dd_ops);
2696 LASSERT(dev->dd_ops->dt_ro);
2697 return dev->dd_ops->dt_ro(env, dev);
2700 static inline int dt_declare_insert(const struct lu_env *env,
2701 struct dt_object *dt,
2702 const struct dt_rec *rec,
2703 const struct dt_key *key,
2707 LASSERT(dt->do_index_ops);
2708 LASSERT(dt->do_index_ops->dio_declare_insert);
2710 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2711 return cfs_fail_err;
2713 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2716 static inline int dt_insert(const struct lu_env *env,
2717 struct dt_object *dt,
2718 const struct dt_rec *rec,
2719 const struct dt_key *key,
2723 LASSERT(dt->do_index_ops);
2724 LASSERT(dt->do_index_ops->dio_insert);
2726 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2727 return cfs_fail_err;
2729 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2732 static inline int dt_declare_xattr_del(const struct lu_env *env,
2733 struct dt_object *dt,
2738 LASSERT(dt->do_ops);
2739 LASSERT(dt->do_ops->do_declare_xattr_del);
2741 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2742 return cfs_fail_err;
2744 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2747 static inline int dt_xattr_del(const struct lu_env *env,
2748 struct dt_object *dt, const char *name,
2752 LASSERT(dt->do_ops);
2753 LASSERT(dt->do_ops->do_xattr_del);
2755 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2756 return cfs_fail_err;
2758 return dt->do_ops->do_xattr_del(env, dt, name, th);
2761 static inline int dt_declare_xattr_set(const struct lu_env *env,
2762 struct dt_object *dt,
2763 const struct lu_buf *buf,
2764 const char *name, int fl,
2768 LASSERT(dt->do_ops);
2769 LASSERT(dt->do_ops->do_declare_xattr_set);
2771 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2772 return cfs_fail_err;
2774 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2777 static inline int dt_xattr_set(const struct lu_env *env,
2778 struct dt_object *dt, const struct lu_buf *buf,
2779 const char *name, int fl, struct thandle *th)
2782 LASSERT(dt->do_ops);
2783 LASSERT(dt->do_ops->do_xattr_set);
2785 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2786 return cfs_fail_err;
2788 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2791 static inline int dt_declare_xattr_get(const struct lu_env *env,
2792 struct dt_object *dt,
2797 LASSERT(dt->do_ops);
2798 LASSERT(dt->do_ops->do_declare_xattr_get);
2800 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2801 return cfs_fail_err;
2803 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2806 static inline int dt_xattr_get(const struct lu_env *env,
2807 struct dt_object *dt, struct lu_buf *buf,
2811 LASSERT(dt->do_ops);
2812 LASSERT(dt->do_ops->do_xattr_get);
2814 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2815 return cfs_fail_err;
2817 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2820 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2821 const struct lu_buf *buf)
2824 LASSERT(dt->do_ops);
2825 LASSERT(dt->do_ops->do_xattr_list);
2827 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2828 return cfs_fail_err;
2830 return dt->do_ops->do_xattr_list(env, dt, buf);
2833 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2836 LASSERT(dt->do_ops);
2837 LASSERT(dt->do_ops->do_invalidate);
2839 return dt->do_ops->do_invalidate(env, dt);
2842 static inline int dt_declare_delete(const struct lu_env *env,
2843 struct dt_object *dt,
2844 const struct dt_key *key,
2848 LASSERT(dt->do_index_ops);
2849 LASSERT(dt->do_index_ops->dio_declare_delete);
2851 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2852 return cfs_fail_err;
2854 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2857 static inline int dt_delete(const struct lu_env *env,
2858 struct dt_object *dt,
2859 const struct dt_key *key,
2863 LASSERT(dt->do_index_ops);
2864 LASSERT(dt->do_index_ops->dio_delete);
2866 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2867 return cfs_fail_err;
2869 return dt->do_index_ops->dio_delete(env, dt, key, th);
2872 static inline int dt_commit_async(const struct lu_env *env,
2873 struct dt_device *dev)
2876 LASSERT(dev->dd_ops);
2877 LASSERT(dev->dd_ops->dt_commit_async);
2878 return dev->dd_ops->dt_commit_async(env, dev);
2881 static inline int dt_lookup(const struct lu_env *env,
2882 struct dt_object *dt,
2884 const struct dt_key *key)
2889 LASSERT(dt->do_index_ops);
2890 LASSERT(dt->do_index_ops->dio_lookup);
2892 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2893 return cfs_fail_err;
2895 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2903 static inline int dt_declare_layout_change(const struct lu_env *env,
2904 struct dt_object *o,
2905 struct md_layout_change *mlc,
2910 LASSERT(o->do_ops->do_declare_layout_change);
2911 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2914 static inline int dt_layout_change(const struct lu_env *env,
2915 struct dt_object *o,
2916 struct md_layout_change *mlc,
2921 LASSERT(o->do_ops->do_layout_change);
2922 return o->do_ops->do_layout_change(env, o, mlc, th);
2925 struct dt_find_hint {
2926 struct lu_fid *dfh_fid;
2927 struct dt_device *dfh_dt;
2928 struct dt_object *dfh_o;
2931 struct dt_insert_rec {
2933 const struct lu_fid *rec_fid;
2945 struct dt_thread_info {
2946 char dti_buf[DT_MAX_PATH];
2947 struct dt_find_hint dti_dfh;
2948 struct lu_attr dti_attr;
2949 struct lu_fid dti_fid;
2950 struct dt_object_format dti_dof;
2951 struct lustre_mdt_attrs dti_lma;
2952 struct lu_buf dti_lb;
2953 struct lu_object_conf dti_conf;
2955 struct dt_insert_rec dti_dt_rec;
2958 extern struct lu_context_key dt_key;
2960 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2962 struct dt_thread_info *dti;
2964 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2969 int dt_global_init(void);
2970 void dt_global_fini(void);
2971 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2972 const char *name, struct ldebugfs_vars *list);
2973 int dt_tunables_fini(struct dt_device *dt);
2975 # ifdef CONFIG_PROC_FS
2976 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2977 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2978 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2979 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2980 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2981 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2982 # endif /* CONFIG_PROC_FS */
2984 #endif /* __LUSTRE_DT_OBJECT_H */