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 * Wait pending quota update finish
303 * There might be a window that quota usage has been updated,
304 * but commit callback to reduce pending write have not been
305 * finished, this is used to wait all pending update done.
307 * \param[in] dev dt device
309 void (*dt_wait_quota_pending)(struct dt_device *dev);
312 * Start transaction commit asynchronously.
315 * Provide a hint to the underlying filesystem that it should start
316 * committing soon. The control returns immediately. It's up to the
317 * layer implementing the method how soon to start committing. Usually
318 * this should be throttled to some extent, otherwise the number of
319 * aggregated transaction goes too high causing performance drop.
321 * \param[in] env execution environment for this thread
322 * \param[in] dev dt device
324 * \retval 0 on success
325 * \retval negative negated errno on error
327 int (*dt_commit_async)(const struct lu_env *env,
328 struct dt_device *dev);
331 struct dt_index_features {
332 /** required feature flags from enum dt_index_flags */
334 /** minimal required key size */
335 size_t dif_keysize_min;
336 /** maximal required key size, 0 if no limit */
337 size_t dif_keysize_max;
338 /** minimal required record size */
339 size_t dif_recsize_min;
340 /** maximal required record size, 0 if no limit */
341 size_t dif_recsize_max;
342 /** pointer size for record */
346 enum dt_index_flags {
347 /** index supports variable sized keys */
348 DT_IND_VARKEY = BIT(0),
349 /** index supports variable sized records */
350 DT_IND_VARREC = BIT(1),
351 /** index can be modified */
352 DT_IND_UPDATE = BIT(2),
353 /** index supports records with non-unique (duplicate) keys */
354 DT_IND_NONUNQ = BIT(3),
356 * index support fixed-size keys sorted with natural numerical way
357 * and is able to return left-side value if no exact value found
359 DT_IND_RANGE = BIT(4),
362 /* for dt_read_lock() and dt_write_lock() object lock rule */
363 enum dt_object_role {
373 * Features, required from index to support file system directories (mapping
376 extern const struct dt_index_features dt_directory_features;
377 extern const struct dt_index_features dt_otable_features;
378 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
379 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
380 extern const struct dt_index_features dt_lfsck_namespace_features;
382 /* index features supported by the accounting objects */
383 extern const struct dt_index_features dt_acct_features;
385 /* index features supported by the quota global indexes */
386 extern const struct dt_index_features dt_quota_glb_features;
388 /* index features supported by the quota slave indexes */
389 extern const struct dt_index_features dt_quota_slv_features;
391 /* index features supported by the nodemap index */
392 extern const struct dt_index_features dt_nodemap_features;
395 * This is a general purpose dt allocation hint.
396 * It now contains the parent object.
397 * It can contain any allocation hint in the future.
399 struct dt_allocation_hint {
400 struct dt_object *dah_parent;
401 const void *dah_eadata;
404 int dah_append_stripes;
405 char *dah_append_pool;
409 * object type specifier.
412 enum dt_format_type {
417 /** for special index */
419 /** for symbolic link */
424 * object format specifier.
426 struct dt_object_format {
427 /** type for dt object */
428 enum dt_format_type dof_type;
438 * special index need feature as parameter to create
442 const struct dt_index_features *di_feat;
447 enum dt_format_type dt_mode_to_dft(__u32 mode);
449 typedef __u64 dt_obj_version_t;
451 union ldlm_policy_data;
453 struct md_layout_change;
456 * A dt_object provides common operations to create and destroy
457 * objects and to manage regular and extended attributes.
459 struct dt_object_operations {
461 * Get read lock on object.
463 * Read lock is compatible with other read locks, so it's shared.
464 * Read lock is not compatible with write lock which is exclusive.
465 * The lock is blocking and can't be used from an interrupt context.
467 * \param[in] env execution environment for this thread
468 * \param[in] dt object to lock for reading
469 * \param[in] role a hint to debug locks (see kernel's mutexes)
471 void (*do_read_lock)(const struct lu_env *env,
472 struct dt_object *dt,
476 * Get write lock on object.
478 * Write lock is exclusive and cannot be shared. The lock is blocking
479 * and can't be used from an interrupt context.
481 * \param[in] env execution environment for this thread
482 * \param[in] dt object to lock for writing
483 * \param[in] role a hint to debug locks (see kernel's mutexes)
486 void (*do_write_lock)(const struct lu_env *env,
487 struct dt_object *dt,
493 * \param[in] env execution environment for this thread
494 * \param[in] dt object
496 void (*do_read_unlock)(const struct lu_env *env,
497 struct dt_object *dt);
500 * Release write lock.
502 * \param[in] env execution environment for this thread
503 * \param[in] dt object
505 void (*do_write_unlock)(const struct lu_env *env,
506 struct dt_object *dt);
509 * Check whether write lock is held.
511 * The caller can learn whether write lock is held on the object
513 * \param[in] env execution environment for this thread
514 * \param[in] dt object
516 * \retval 0 no write lock
517 * \retval 1 write lock is held
519 int (*do_write_locked)(const struct lu_env *env,
520 struct dt_object *dt);
523 * Declare intention to request reqular attributes.
525 * Notity the underlying filesystem that the caller may request regular
526 * attributes with ->do_attr_get() soon. This allows OSD to implement
527 * prefetching logic in an object-oriented manner. The implementation
528 * can be noop. This method should avoid expensive delays such as
529 * waiting on disk I/O, otherwise the goal of enabling a performance
530 * optimization would be defeated.
532 * \param[in] env execution environment for this thread
533 * \param[in] dt object
535 * \retval 0 on success
536 * \retval negative negated errno on error
538 int (*do_declare_attr_get)(const struct lu_env *env,
539 struct dt_object *dt);
542 * Return regular attributes.
544 * The object must exist. Currently all the attributes should be
545 * returned, but in the future this can be improved so that only
546 * a selected set is returned. This can improve performance as in
547 * some cases attributes are stored in different places and
548 * getting them all can be an iterative and expensive process.
550 * \param[in] env execution environment for this thread
551 * \param[in] dt object
552 * \param[out] attr attributes to fill
554 * \retval 0 on success
555 * \retval negative negated errno on error
557 int (*do_attr_get)(const struct lu_env *env,
558 struct dt_object *dt,
559 struct lu_attr *attr);
562 * Declare intention to change regular object's attributes.
564 * Notify the underlying filesystem that the regular attributes may
565 * change in this transaction. This enables the layer below to prepare
566 * resources (e.g. journal credits in ext4). This method should be
567 * called between creating the transaction and starting it. Note that
568 * the la_valid field of \a attr specifies which attributes will change.
569 * The object need not exist.
571 * \param[in] env execution environment for this thread
572 * \param[in] dt object
573 * \param[in] attr attributes to change specified in attr.la_valid
574 * \param[in] th transaction handle
576 * \retval 0 on success
577 * \retval negative negated errno on error
579 int (*do_declare_attr_set)(const struct lu_env *env,
580 struct dt_object *dt,
581 const struct lu_attr *attr,
585 * Change regular attributes.
587 * Change regular attributes in the given transaction. Note only
588 * attributes flagged by attr.la_valid change. The object must
589 * exist. If the layer implementing this method is responsible for
590 * quota, then the method should maintain object accounting for the
591 * given credentials when la_uid/la_gid changes.
593 * \param[in] env execution environment for this thread
594 * \param[in] dt object
595 * \param[in] attr new attributes to apply
596 * \param[in] th transaction handle
598 * \retval 0 on success
599 * \retval negative negated errno on error
601 int (*do_attr_set)(const struct lu_env *env,
602 struct dt_object *dt,
603 const struct lu_attr *attr,
607 * Declare intention to request extented attribute.
609 * Notify the underlying filesystem that the caller may request extended
610 * attribute with ->do_xattr_get() soon. This allows OSD to implement
611 * prefetching logic in an object-oriented manner. The implementation
612 * can be noop. This method should avoid expensive delays such as
613 * waiting on disk I/O, otherwise the goal of enabling a performance
614 * optimization would be defeated.
616 * \param[in] env execution environment for this thread
617 * \param[in] dt object
618 * \param[in] buf unused, may be removed in the future
619 * \param[in] name name of the extended attribute
621 * \retval 0 on success
622 * \retval negative negated errno on error
624 int (*do_declare_xattr_get)(const struct lu_env *env,
625 struct dt_object *dt,
630 * Return a value of an extended attribute.
632 * The object must exist. If the buffer is NULL, then the method
633 * must return the size of the value.
635 * \param[in] env execution environment for this thread
636 * \param[in] dt object
637 * \param[out] buf buffer in which to store the value
638 * \param[in] name name of the extended attribute
640 * \retval 0 on success
641 * \retval -ERANGE if \a buf is too small
642 * \retval negative negated errno on error
643 * \retval positive value's size if \a buf is NULL or has zero size
645 int (*do_xattr_get)(const struct lu_env *env,
646 struct dt_object *dt,
651 * Declare intention to change an extended attribute.
653 * Notify the underlying filesystem that the extended attribute may
654 * change in this transaction. This enables the layer below to prepare
655 * resources (e.g. journal credits in ext4). This method should be
656 * called between creating the transaction and starting it. The object
659 * \param[in] env execution environment for this thread
660 * \param[in] dt object
661 * \param[in] buf buffer storing new value of the attribute
662 * \param[in] name name of the attribute
663 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
664 * LU_XATTR_REPLACE - fail if EA doesn't exist
665 * \param[in] th transaction handle
667 * \retval 0 on success
668 * \retval negative negated errno on error
670 int (*do_declare_xattr_set)(const struct lu_env *env,
671 struct dt_object *dt,
672 const struct lu_buf *buf,
678 * Set an extended attribute.
680 * Change or replace the specified extended attribute (EA).
681 * The flags passed in \a fl dictate whether the EA is to be
682 * created or replaced, as follows.
683 * LU_XATTR_CREATE - fail if EA exists
684 * LU_XATTR_REPLACE - fail if EA doesn't exist
685 * The object must exist.
687 * \param[in] env execution environment for this thread
688 * \param[in] dt object
689 * \param[in] buf buffer storing new value of the attribute
690 * \param[in] name name of the attribute
691 * \param[in] fl flags indicating EA creation or replacement
692 * \param[in] th transaction handle
694 * \retval 0 on success
695 * \retval negative negated errno on error
697 int (*do_xattr_set)(const struct lu_env *env,
698 struct dt_object *dt,
699 const struct lu_buf *buf,
705 * Declare intention to delete an extended attribute.
707 * Notify the underlying filesystem that the extended attribute may
708 * be deleted in this transaction. This enables the layer below to
709 * prepare resources (e.g. journal credits in ext4). This method
710 * should be called between creating the transaction and starting it.
711 * The object need not exist.
713 * \param[in] env execution environment for this thread
714 * \param[in] dt object
715 * \param[in] name name of the attribute
716 * \param[in] th transaction handle
718 * \retval 0 on success
719 * \retval negative negated errno on error
721 int (*do_declare_xattr_del)(const struct lu_env *env,
722 struct dt_object *dt,
727 * Delete an extended attribute.
729 * This method deletes the specified extended attribute. The object
732 * \param[in] env execution environment for this thread
733 * \param[in] dt object
734 * \param[in] name name of the attribute
735 * \param[in] th transaction handle
737 * \retval 0 on success
738 * \retval negative negated errno on error
740 int (*do_xattr_del)(const struct lu_env *env,
741 struct dt_object *dt,
746 * Return a list of the extended attributes.
748 * Fills the passed buffer with a list of the extended attributes
749 * found in the object. The names are separated with '\0'.
750 * The object must exist.
752 * \param[in] env execution environment for this thread
753 * \param[in] dt object
754 * \param[out] buf buffer to put the list in
756 * \retval positive bytes used/required in the buffer
757 * \retval negative negated errno on error
759 int (*do_xattr_list)(const struct lu_env *env,
760 struct dt_object *dt,
761 const struct lu_buf *buf);
764 * Prepare allocation hint for a new object.
766 * This method is used by the caller to inform OSD of the parent-child
767 * relationship between two objects and enable efficient object
768 * allocation. Filled allocation hint will be passed to ->do_create()
771 * \param[in] env execution environment for this thread
772 * \param[out] ah allocation hint
773 * \param[in] parent parent object (can be NULL)
774 * \param[in] child child object
775 * \param[in] _mode type of the child object
777 void (*do_ah_init)(const struct lu_env *env,
778 struct dt_allocation_hint *ah,
779 struct dt_object *parent,
780 struct dt_object *child,
784 * Declare intention to create a new object.
786 * Notify the underlying filesystem that the object may be created
787 * in this transaction. This enables the layer below to prepare
788 * resources (e.g. journal credits in ext4). This method should be
789 * called between creating the transaction and starting it.
791 * If the layer implementing this method is responsible for quota,
792 * then the method should reserve an object for the given credentials
793 * and return an error if quota is over. If object creation later
794 * fails for some reason, then the reservation should be released
795 * properly (usually in ->dt_trans_stop()).
797 * \param[in] env execution environment for this thread
798 * \param[in] dt object
799 * \param[in] attr attributes of the new object
800 * \param[in] hint allocation hint
801 * \param[in] dof object format
802 * \param[in] th transaction handle
804 * \retval 0 on success
805 * \retval negative negated errno on error
807 int (*do_declare_create)(const struct lu_env *env,
808 struct dt_object *dt,
809 struct lu_attr *attr,
810 struct dt_allocation_hint *hint,
811 struct dt_object_format *dof,
817 * The method creates the object passed with the specified attributes
818 * and object format. Object allocation procedure can use information
819 * stored in the allocation hint. Different object formats are supported
820 * (see enum dt_format_type and struct dt_object_format) depending on
821 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
822 * in the LU-object header attributes.
824 * If the layer implementing this method is responsible for quota,
825 * then the method should maintain object accounting for the given
828 * \param[in] env execution environment for this thread
829 * \param[in] dt object
830 * \param[in] attr attributes of the new object
831 * \param[in] hint allocation hint
832 * \param[in] dof object format
833 * \param[in] th transaction handle
835 * \retval 0 on success
836 * \retval negative negated errno on error
838 int (*do_create)(const struct lu_env *env,
839 struct dt_object *dt,
840 struct lu_attr *attr,
841 struct dt_allocation_hint *hint,
842 struct dt_object_format *dof,
846 * Declare intention to destroy an object.
848 * Notify the underlying filesystem that the object may be destroyed
849 * in this transaction. This enables the layer below to prepare
850 * resources (e.g. journal credits in ext4). This method should be
851 * called between creating the transaction and starting it. The object
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_declare_destroy)(const struct lu_env *env,
862 struct dt_object *dt,
868 * This method destroys the object and all the resources associated
869 * with the object (data, key/value pairs, extended attributes, etc).
870 * The object must exist. If destroy is successful, then flag
871 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
872 * instance of in-core object. Any subsequent access to the same FID
873 * should get another instance with no LOHA_EXIST flag set.
875 * If the layer implementing this method is responsible for quota,
876 * then the method should maintain object accounting for the given
879 * \param[in] env execution environment for this thread
880 * \param[in] dt object
881 * \param[in] th transaction handle
883 * \retval 0 on success
884 * \retval negative negated errno on error
886 int (*do_destroy)(const struct lu_env *env,
887 struct dt_object *dt,
891 * Try object as an index.
893 * Announce that this object is going to be used as an index. This
894 * operation checks that object supports indexing operations and
895 * installs appropriate dt_index_operations vector on success.
896 * Also probes for features. Operation is successful if all required
897 * features are supported. It's not possible to access the object
898 * with index methods before ->do_index_try() returns success.
900 * \param[in] env execution environment for this thread
901 * \param[in] dt object
902 * \param[in] feat index features
904 * \retval 0 on success
905 * \retval negative negated errno on error
907 int (*do_index_try)(const struct lu_env *env,
908 struct dt_object *dt,
909 const struct dt_index_features *feat);
912 * Declare intention to increment nlink count.
914 * Notify the underlying filesystem that the nlink regular attribute
915 * be changed in this transaction. This enables the layer below to
916 * prepare resources (e.g. journal credits in ext4). This method
917 * should be called between creating the transaction and starting it.
918 * The object need not exist.
920 * \param[in] env execution environment for this thread
921 * \param[in] dt object
922 * \param[in] th transaction handle
924 * \retval 0 on success
925 * \retval negative negated errno on error
927 int (*do_declare_ref_add)(const struct lu_env *env,
928 struct dt_object *dt,
934 * Increment nlink (from the regular attributes set) in the given
935 * transaction. Note the absolute limit for nlink should be learnt
936 * from struct dt_device_param::ddp_max_nlink. The object must exist.
938 * \param[in] env execution environment for this thread
939 * \param[in] dt object
940 * \param[in] th transaction handle
942 * \retval 0 on success
943 * \retval negative negated errno on error
945 int (*do_ref_add)(const struct lu_env *env,
946 struct dt_object *dt, struct thandle *th);
949 * Declare intention to decrement nlink count.
951 * Notify the underlying filesystem that the nlink regular attribute
952 * be changed in this transaction. This enables the layer below to
953 * prepare resources (e.g. journal credits in ext4). This method
954 * should be called between creating the transaction and starting it.
955 * The object need not exist.
957 * \param[in] env execution environment for this thread
958 * \param[in] dt object
959 * \param[in] th transaction handle
961 * \retval 0 on success
962 * \retval negative negated errno on error
964 int (*do_declare_ref_del)(const struct lu_env *env,
965 struct dt_object *dt,
971 * Decrement nlink (from the regular attributes set) in the given
972 * transaction. The object must exist.
974 * \param[in] env execution environment for this thread
975 * \param[in] dt object
976 * \param[in] th transaction handle
978 * \retval 0 on success
979 * \retval negative negated errno on error
981 int (*do_ref_del)(const struct lu_env *env,
982 struct dt_object *dt,
988 * The method is called to sync specified range of the object to a
989 * persistent storage. The control is returned once the operation is
990 * complete. The difference from ->do_sync() is that the object can
991 * be in-sync with the persistent storage (nothing to flush), then
992 * the method returns quickly with no I/O overhead. So, this method
993 * should be preferred over ->do_sync() where possible. Also note that
994 * if the object isn't clean, then some disk filesystems will call
995 * ->do_sync() to maintain overall consistency, in which case it's
996 * still very expensive.
998 * \param[in] env execution environment for this thread
999 * \param[in] dt object
1000 * \param[in] start start of the range to sync
1001 * \param[in] end end of the range to sync
1003 * \retval 0 on success
1004 * \retval negative negated errno on error
1006 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
1007 __u64 start, __u64 end);
1012 * Lock object(s) using Distributed Lock Manager (LDLM).
1014 * Get LDLM locks for the object. Currently used to lock "remote"
1015 * objects in DNE configuration - a service running on MDTx needs
1016 * to lock an object on MDTy.
1018 * \param[in] env execution environment for this thread
1019 * \param[in] dt object
1020 * \param[out] lh lock handle, sometimes used, sometimes not
1021 * \param[in] einfo ldlm callbacks, locking type and mode
1022 * \param[out] einfo private data to be passed to unlock later
1023 * \param[in] policy inodebits data
1025 * \retval 0 on success
1026 * \retval negative negated errno on error
1028 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
1029 struct lustre_handle *lh,
1030 struct ldlm_enqueue_info *einfo,
1031 union ldlm_policy_data *policy);
1036 * Release LDLM lock(s) granted with ->do_object_lock().
1038 * \param[in] env execution environment for this thread
1039 * \param[in] dt object
1040 * \param[in] einfo lock handles, from ->do_object_lock()
1041 * \param[in] policy inodebits data
1043 * \retval 0 on success
1044 * \retval negative negated errno on error
1046 int (*do_object_unlock)(const struct lu_env *env,
1047 struct dt_object *dt,
1048 struct ldlm_enqueue_info *einfo,
1049 union ldlm_policy_data *policy);
1052 * Invalidate attribute cache.
1054 * This method invalidate attribute cache of the object, which is on OSP
1057 * \param[in] env execution envionment for this thread
1058 * \param[in] dt object
1060 * \retval 0 on success
1061 * \retval negative negated errno on error
1063 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1066 * Check object stale state.
1070 * \param[in] dt object
1072 * \retval true for stale object
1073 * \retval false for not stale object
1075 bool (*do_check_stale)(struct dt_object *dt);
1078 * Declare intention to instaintiate extended layout component.
1080 * \param[in] env execution environment
1081 * \param[in] dt DT object
1082 * \param[in] layout data structure to describe the changes to
1083 * the DT object's layout
1084 * \param[in] buf buffer containing client's lovea or empty
1087 * \retval -ne error code
1089 int (*do_declare_layout_change)(const struct lu_env *env,
1090 struct dt_object *dt,
1091 struct md_layout_change *mlc,
1092 struct thandle *th);
1095 * Client is trying to write to un-instantiated layout component.
1097 * \param[in] env execution environment
1098 * \param[in] dt DT object
1099 * \param[in] layout data structure to describe the changes to
1100 * the DT object's layout
1101 * \param[in] buf buffer containing client's lovea or empty
1104 * \retval -ne error code
1106 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1107 struct md_layout_change *mlc,
1108 struct thandle *th);
1112 DT_BUFS_TYPE_READ = 0x0000,
1113 DT_BUFS_TYPE_WRITE = 0x0001,
1114 DT_BUFS_TYPE_READAHEAD = 0x0002,
1115 DT_BUFS_TYPE_LOCAL = 0x0004,
1119 * Per-dt-object operations on "file body" - unstructure raw data.
1121 struct dt_body_operations {
1125 * Read unstructured data from an existing regular object.
1126 * Only data before attr.la_size is returned.
1128 * \param[in] env execution environment for this thread
1129 * \param[in] dt object
1130 * \param[out] buf buffer (including size) to copy data in
1131 * \param[in] pos position in the object to start
1132 * \param[out] pos original value of \a pos + bytes returned
1134 * \retval positive bytes read on success
1135 * \retval negative negated errno on error
1137 ssize_t (*dbo_read)(const struct lu_env *env,
1138 struct dt_object *dt,
1143 * Declare intention to write data to object.
1145 * Notify the underlying filesystem that data may be written in
1146 * this transaction. This enables the layer below to prepare resources
1147 * (e.g. journal credits in ext4). This method should be called
1148 * between creating the transaction and starting it. The object need
1149 * not exist. If the layer implementing this method is responsible for
1150 * quota, then the method should reserve space for the given credentials
1151 * and return an error if quota is over. If the write later fails
1152 * for some reason, then the reserve should be released properly
1153 * (usually in ->dt_trans_stop()).
1155 * \param[in] env execution environment for this thread
1156 * \param[in] dt object
1157 * \param[in] buf buffer (including size) to copy data from
1158 * \param[in] pos position in the object to start
1159 * \param[in] th transaction handle
1161 * \retval 0 on success
1162 * \retval negative negated errno on error
1164 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1165 struct dt_object *dt,
1166 const struct lu_buf *buf,
1168 struct thandle *th);
1171 * Write unstructured data to regular existing object.
1173 * The method allocates space and puts data in. Also, the method should
1174 * maintain attr.la_size properly. Partial writes are possible.
1176 * If the layer implementing this method is responsible for quota,
1177 * then the method should maintain space accounting for the given
1180 * \param[in] env execution environment for this thread
1181 * \param[in] dt object
1182 * \param[in] buf buffer (including size) to copy data from
1183 * \param[in] pos position in the object to start
1184 * \param[out] pos \a pos + bytes written
1185 * \param[in] th transaction handle
1187 * \retval positive bytes written on success
1188 * \retval negative negated errno on error
1190 ssize_t (*dbo_write)(const struct lu_env *env,
1191 struct dt_object *dt,
1192 const struct lu_buf *buf,
1194 struct thandle *th);
1197 * Return buffers for data.
1199 * This method is used to access data with no copying. It's so-called
1200 * zero-copy I/O. The method returns the descriptors for the internal
1201 * buffers where data are managed by the disk filesystem. For example,
1202 * pagecache in case of ext4 or ARC with ZFS. Then other components
1203 * (e.g. networking) can transfer data from or to the buffers with no
1204 * additional copying.
1206 * The method should fill an array of struct niobuf_local, where
1207 * each element describes a full or partial page for data at specific
1208 * offset. The caller should use page/lnb_page_offset/len to find data
1209 * at object's offset lnb_file_offset.
1211 * The memory referenced by the descriptors can't change its purpose
1212 * until the complementary ->dbo_bufs_put() is called. The caller should
1213 * specify if the buffers are used to read or modify data so that OSD
1214 * can decide how to initialize the buffers: bring all the data for
1215 * reads or just bring partial buffers for write. Note: the method does
1216 * not check whether output array is large enough.
1218 * \param[in] env execution environment for this thread
1219 * \param[in] dt object
1220 * \param[in] pos position in the object to start
1221 * \param[in] len size of region in bytes
1222 * \param[out] lb array of descriptors to fill
1223 * \param[in] maxlnb max slots in @lnb array
1224 * \param[in] rw 0 if used to read, 1 if used for write
1226 * \retval positive number of descriptors on success
1227 * \retval negative negated errno on error
1229 int (*dbo_bufs_get)(const struct lu_env *env,
1230 struct dt_object *dt,
1233 struct niobuf_local *lb,
1235 enum dt_bufs_type rw);
1238 * Release reference granted by ->dbo_bufs_get().
1240 * Release the reference granted by the previous ->dbo_bufs_get().
1241 * Note the references are counted.
1243 * \param[in] env execution environment for this thread
1244 * \param[in] dt object
1245 * \param[out] lb array of descriptors to fill
1246 * \param[in] nr size of the array
1248 * \retval 0 on success
1249 * \retval negative negated errno on error
1251 int (*dbo_bufs_put)(const struct lu_env *env,
1252 struct dt_object *dt,
1253 struct niobuf_local *lb,
1257 * Prepare buffers for reading.
1259 * The method is called on the given buffers to fill them with data
1260 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1261 * caller should be able to get few buffers for discontiguous regions
1262 * using few calls to ->dbo_bufs_get() and then request them all for
1263 * the preparation with a single call, so that OSD can fire many I/Os
1264 * to run concurrently. It's up to the specific OSD whether to implement
1265 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1266 * prepare data for every requested region individually.
1268 * \param[in] env execution environment for this thread
1269 * \param[in] dt object
1270 * \param[in] lnb array of buffer descriptors
1271 * \param[in] nr size of the array
1273 * \retval 0 on success
1274 * \retval negative negated errno on error
1276 int (*dbo_read_prep)(const struct lu_env *env,
1277 struct dt_object *dt,
1278 struct niobuf_local *lnb,
1282 * Prepare buffers for write.
1284 * This method is called on the given buffers to ensure the partial
1285 * buffers contain correct data. The underlying idea is the same as
1286 * in ->db_read_prep().
1288 * \param[in] env execution environment for this thread
1289 * \param[in] dt object
1290 * \param[in] lb array of buffer descriptors
1291 * \param[in] nr size of the array
1293 * \retval 0 on success
1294 * \retval negative negated errno on error
1296 int (*dbo_write_prep)(const struct lu_env *env,
1297 struct dt_object *dt,
1298 struct niobuf_local *lb,
1302 * Declare intention to write data stored in the buffers.
1304 * Notify the underlying filesystem that data may be written in
1305 * this transaction. This enables the layer below to prepare resources
1306 * (e.g. journal credits in ext4). This method should be called
1307 * between creating the transaction and starting it.
1309 * If the layer implementing this method is responsible for quota,
1310 * then the method should be reserving a space for the given
1311 * credentials and return an error if quota is exceeded. If the write
1312 * later fails for some reason, then the reserve should be released
1313 * properly (usually in ->dt_trans_stop()).
1315 * \param[in] env execution environment for this thread
1316 * \param[in] dt object
1317 * \param[in] lb array of descriptors
1318 * \param[in] nr size of the array
1319 * \param[in] th transaction handle
1321 * \retval 0 on success
1322 * \retval negative negated errno on error
1324 int (*dbo_declare_write_commit)(const struct lu_env *env,
1325 struct dt_object *dt,
1326 struct niobuf_local *lb,
1328 struct thandle *th);
1331 * Write to existing object.
1333 * This method is used to write data to a persistent storage using
1334 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1335 * data into the buffers using own mechanisms (e.g. direct transfer
1336 * from a NIC). The method should maintain attr.la_size. Also,
1337 * attr.la_blocks should be maintained but this can be done in lazy
1338 * manner, when actual allocation happens.
1340 * If the layer implementing this method is responsible for quota,
1341 * then the method should maintain space accounting for the given
1344 * user_size parameter is the apparent size of the file, ie the size
1345 * of the clear text version of the file. It can differ from the actual
1346 * amount of valuable data received when a file is encrypted,
1347 * because encrypted pages always contain PAGE_SIZE bytes of data,
1348 * even if clear text data is only a few bytes.
1349 * In case of encrypted file, apparent size will be stored as the inode
1350 * size, so that servers return to clients an object size they can use
1351 * to determine clear text size.
1353 * \param[in] env execution environment for this thread
1354 * \param[in] dt object
1355 * \param[in] lb array of descriptors for the buffers
1356 * \param[in] nr size of the array
1357 * \param[in] th transaction handle
1358 * \param[in] user_size apparent size
1360 * \retval 0 on success
1361 * \retval negative negated errno on error
1363 int (*dbo_write_commit)(const struct lu_env *env,
1364 struct dt_object *dt,
1365 struct niobuf_local *lb,
1371 * Return logical to physical block mapping for a given extent
1373 * \param[in] env execution environment for this thread
1374 * \param[in] dt object
1375 * \param[in] fm describe the region to map and the output buffer
1376 * see the details in include/linux/fiemap.h
1378 * \retval 0 on success
1379 * \retval negative negated errno on error
1381 int (*dbo_fiemap_get)(const struct lu_env *env,
1382 struct dt_object *dt,
1386 * Declare intention to deallocate space from an object.
1388 * Notify the underlying filesystem that space may be deallocated in
1389 * this transactions. This enables the layer below to prepare resources
1390 * (e.g. journal credits in ext4). This method should be called between
1391 * creating the transaction and starting it. The object need not exist.
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_declare_punch)(const struct lu_env *env,
1403 struct dt_object *dt,
1406 struct thandle *th);
1409 * Deallocate specified region in an object.
1411 * This method is used to deallocate (release) space possibly consumed
1412 * by the given region of the object. If the layer implementing this
1413 * method is responsible for quota, then the method should maintain
1414 * space accounting for the given credentials.
1416 * \param[in] env execution environment for this thread
1417 * \param[in] dt object
1418 * \param[in] start the start of the region to deallocate
1419 * \param[in] end the end of the region to deallocate
1420 * \param[in] th transaction handle
1422 * \retval 0 on success
1423 * \retval negative negated errno on error
1425 int (*dbo_punch)(const struct lu_env *env,
1426 struct dt_object *dt,
1429 struct thandle *th);
1431 * Give advices on specified region in an object.
1433 * This method is used to give advices about access pattern on an
1434 * given region of the object. The disk filesystem understands
1435 * the advices and tunes cache/read-ahead policies.
1437 * \param[in] env execution environment for this thread
1438 * \param[in] dt object
1439 * \param[in] start the start of the region affected
1440 * \param[in] end the end of the region affected
1441 * \param[in] advice advice type
1443 * \retval 0 on success
1444 * \retval negative negated errno on error
1446 int (*dbo_ladvise)(const struct lu_env *env,
1447 struct dt_object *dt,
1450 enum lu_ladvise_type advice);
1453 * Declare intention to preallocate space for an object
1455 * \param[in] env execution environment for this thread
1456 * \param[in] dt object
1457 * \param[in] th transaction handle
1459 * \retval 0 on success
1460 * \retval negative negated errno on error
1462 int (*dbo_declare_fallocate)(const struct lu_env *env,
1463 struct dt_object *dt, __u64 start,
1464 __u64 end, int mode, struct thandle *th);
1466 * Allocate specified region for an object
1468 * \param[in] env execution environment for this thread
1469 * \param[in] dt object
1470 * \param[in] start the start of the region to allocate
1471 * \param[in] end the end of the region to allocate
1472 * \param[in] mode fallocate mode
1473 * \param[in] th transaction handle
1475 * \retval 0 on success
1476 * \retval negative negated errno on error
1478 int (*dbo_fallocate)(const struct lu_env *env,
1479 struct dt_object *dt,
1483 struct thandle *th);
1485 * Do SEEK_HOLE/SEEK_DATA request on object
1487 * \param[in] env execution environment for this thread
1488 * \param[in] dt object
1489 * \param[in] offset the offset to start seek from
1490 * \param[in] whence seek mode, SEEK_HOLE or SEEK_DATA
1492 * \retval hole/data offset on success
1493 * \retval negative negated errno on error
1495 loff_t (*dbo_lseek)(const struct lu_env *env, struct dt_object *dt,
1496 loff_t offset, int whence);
1500 * Incomplete type of index record.
1505 * Incomplete type of index key.
1510 * Incomplete type of dt iterator.
1515 * Per-dt-object operations on object as index. Index is a set of key/value
1516 * pairs abstracted from an on-disk representation. An index supports the
1517 * number of operations including lookup by key, insert and delete. Also,
1518 * an index can be iterated to find the pairs one by one, from a beginning
1519 * or specified point.
1521 struct dt_index_operations {
1523 * Lookup in an index by key.
1525 * The method returns a value for the given key. Key/value format
1526 * and size should have been negotiated with ->do_index_try() before.
1527 * Thus it's the caller's responsibility to provide the method with
1528 * proper key and big enough buffer. No external locking is required,
1529 * all the internal consistency should be implemented by the method
1530 * or lower layers. The object should should have been created with
1531 * type DFT_INDEX or DFT_DIR.
1533 * \param[in] env execution environment for this thread
1534 * \param[in] dt object
1535 * \param[out] rec buffer where value will be stored
1536 * \param[in] key key
1538 * \retval 0 on success
1539 * \retval -ENOENT if key isn't found
1540 * \retval negative negated errno on error
1542 int (*dio_lookup)(const struct lu_env *env,
1543 struct dt_object *dt,
1545 const struct dt_key *key);
1548 * Declare intention to insert a key/value into an index.
1550 * Notify the underlying filesystem that new key/value may be inserted
1551 * in this transaction. This enables the layer below to prepare
1552 * resources (e.g. journal credits in ext4). This method should be
1553 * called between creating the transaction and starting it. key/value
1554 * format and size is subject to ->do_index_try().
1556 * \param[in] env execution environment for this thread
1557 * \param[in] dt object
1558 * \param[in] rec buffer storing value
1559 * \param[in] key key
1560 * \param[in] th transaction handle
1562 * \retval 0 on success
1563 * \retval negative negated errno on error
1565 int (*dio_declare_insert)(const struct lu_env *env,
1566 struct dt_object *dt,
1567 const struct dt_rec *rec,
1568 const struct dt_key *key,
1569 struct thandle *th);
1572 * Insert a new key/value pair into an index.
1574 * The method inserts specified key/value pair into the given index
1575 * object. The internal consistency is maintained by the method or
1576 * the functionality below. The format and size of key/value should
1577 * have been negotiated before using ->do_index_try(), no additional
1578 * information can be specified to the method. The keys are unique
1581 * \param[in] env execution environment for this thread
1582 * \param[in] dt object
1583 * \param[in] rec buffer storing value
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_insert)(const struct lu_env *env,
1591 struct dt_object *dt,
1592 const struct dt_rec *rec,
1593 const struct dt_key *key,
1594 struct thandle *th);
1597 * Declare intention to delete a key/value from an index.
1599 * Notify the underlying filesystem that key/value may be deleted in
1600 * this transaction. This enables the layer below to prepare resources
1601 * (e.g. journal credits in ext4). This method should be called
1602 * between creating the transaction and starting it. Key/value format
1603 * and size is subject to ->do_index_try(). The object need not exist.
1605 * \param[in] env execution environment for this thread
1606 * \param[in] dt object
1607 * \param[in] key key
1608 * \param[in] th transaction handle
1610 * \retval 0 on success
1611 * \retval negative negated errno on error
1613 int (*dio_declare_delete)(const struct lu_env *env,
1614 struct dt_object *dt,
1615 const struct dt_key *key,
1616 struct thandle *th);
1619 * Delete key/value pair from an index.
1621 * The method deletes specified key and corresponding value from the
1622 * given index object. The internal consistency is maintained by the
1623 * method or the functionality below. The format and size of the key
1624 * should have been negotiated before using ->do_index_try(), no
1625 * additional information can be specified to the method.
1627 * \param[in] env execution environment for this thread
1628 * \param[in] dt object
1629 * \param[in] key key
1630 * \param[in] th transaction handle
1632 * \retval 0 on success
1633 * \retval negative negated errno on error
1635 int (*dio_delete)(const struct lu_env *env,
1636 struct dt_object *dt,
1637 const struct dt_key *key,
1638 struct thandle *th);
1641 * Iterator interface.
1643 * Methods to iterate over an existing index, list the keys stored and
1644 * associated values, get key/value size, etc.
1648 * Allocate and initialize new iterator.
1650 * The iterator is a handler to be used in the subsequent
1651 * methods to access index's content. Note the position is
1652 * not defined at this point and should be initialized with
1653 * ->get() or ->load() method.
1655 * \param[in] env execution environment for this thread
1656 * \param[in] dt object
1657 * \param[in] attr ask the iterator to return part of
1658 the records, see LUDA_* for details
1660 * \retval pointer iterator pointer on success
1661 * \retval ERR_PTR(errno) on error
1663 struct dt_it *(*init)(const struct lu_env *env,
1664 struct dt_object *dt,
1670 * Release the specified iterator and all the resources
1671 * associated (e.g. the object, index cache, etc).
1673 * \param[in] env execution environment for this thread
1674 * \param[in] di iterator to release
1676 void (*fini)(const struct lu_env *env,
1680 * Move position of iterator.
1682 * Move the position of the specified iterator to the specified
1685 * \param[in] env execution environment for this thread
1686 * \param[in] di iterator
1687 * \param[in] key key to position to
1689 * \retval 0 if exact key is found
1690 * \retval 1 if at the record with least key
1691 * not larger than the key
1692 * \retval negative negated errno on error
1694 int (*get)(const struct lu_env *env,
1696 const struct dt_key *key);
1701 * Complimentary method for dt_it_ops::get() above. Some
1702 * implementation can increase a reference on the iterator in
1703 * dt_it_ops::get(). So the caller should be able to release
1704 * with dt_it_ops::put().
1706 * \param[in] env execution environment for this thread
1707 * \param[in] di iterator
1709 void (*put)(const struct lu_env *env,
1713 * Move to next record.
1715 * Moves the position of the iterator to a next record
1717 * \param[in] env execution environment for this thread
1718 * \param[in] di iterator
1720 * \retval 1 if no more records
1721 * \retval 0 on success, the next record is found
1722 * \retval negative negated errno on error
1724 int (*next)(const struct lu_env *env,
1730 * Returns a pointer to a buffer containing the key of the
1731 * record at the current position. The pointer is valid and
1732 * retains data until ->get(), ->load() and ->fini() methods
1735 * \param[in] env execution environment for this thread
1736 * \param[in] di iterator
1738 * \retval pointer to key on success
1739 * \retval ERR_PTR(errno) on error
1741 struct dt_key *(*key)(const struct lu_env *env,
1742 const struct dt_it *di);
1747 * Returns size of the key at the current position.
1749 * \param[in] env execution environment for this thread
1750 * \param[in] di iterator
1752 * \retval key's size on success
1753 * \retval negative negated errno on error
1755 int (*key_size)(const struct lu_env *env,
1756 const struct dt_it *di);
1761 * Stores the value of the record at the current position. The
1762 * buffer must be big enough (as negotiated with
1763 * ->do_index_try() or ->rec_size()). The caller can specify
1764 * she is interested only in part of the record, using attr
1765 * argument (see LUDA_* definitions for the details).
1767 * \param[in] env execution environment for this thread
1768 * \param[in] di iterator
1769 * \param[out] rec buffer to store value in
1770 * \param[in] attr specify part of the value to copy
1772 * \retval 0 on success
1773 * \retval negative negated errno on error
1775 int (*rec)(const struct lu_env *env,
1776 const struct dt_it *di,
1781 * Return record size.
1783 * Returns size of the record at the current position. The
1784 * \a attr can be used to specify only the parts of the record
1785 * needed to be returned. (see LUDA_* definitions for the
1788 * \param[in] env execution environment for this thread
1789 * \param[in] di iterator
1790 * \param[in] attr part of the record to return
1792 * \retval record's size on success
1793 * \retval negative negated errno on error
1795 int (*rec_size)(const struct lu_env *env,
1796 const struct dt_it *di,
1800 * Return a cookie (hash).
1802 * Returns the cookie (usually hash) of the key at the current
1803 * position. This allows the caller to resume iteration at this
1804 * position later. The exact value is specific to implementation
1805 * and should not be interpreted by the caller.
1807 * \param[in] env execution environment for this thread
1808 * \param[in] di iterator
1810 * \retval cookie/hash of the key
1812 __u64 (*store)(const struct lu_env *env,
1813 const struct dt_it *di);
1816 * Initialize position using cookie/hash.
1818 * Initializes the current position of the iterator to one
1819 * described by the cookie/hash as returned by ->store()
1822 * \param[in] env execution environment for this thread
1823 * \param[in] di iterator
1824 * \param[in] hash cookie/hash value
1826 * \retval positive if current position points to
1827 * record with least cookie not larger
1829 * \retval 0 if current position matches cookie
1830 * \retval negative negated errno on error
1832 int (*load)(const struct lu_env *env,
1833 const struct dt_it *di,
1839 int (*key_rec)(const struct lu_env *env,
1840 const struct dt_it *di,
1845 enum dt_otable_it_valid {
1846 DOIV_ERROR_HANDLE = 0x0001,
1847 DOIV_DRYRUN = 0x0002,
1850 enum dt_otable_it_flags {
1851 /* Exit when fail. */
1852 DOIF_FAILOUT = 0x0001,
1854 /* Reset iteration position to the device beginning. */
1855 DOIF_RESET = 0x0002,
1857 /* There is up layer component uses the iteration. */
1858 DOIF_OUTUSED = 0x0004,
1860 /* Check only without repairing. */
1861 DOIF_DRYRUN = 0x0008,
1864 /* otable based iteration needs to use the common DT iteration APIs.
1865 * To initialize the iteration, it needs call dio_it::init() firstly.
1866 * Here is how the otable based iteration should prepare arguments to
1867 * call dt_it_ops::init().
1869 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1870 * is composed of two parts:
1871 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1872 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1873 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1876 struct lu_device dd_lu_dev;
1877 const struct dt_device_operations *dd_ops;
1880 * List of dt_txn_callback (see below). This is not protected in any
1881 * way, because callbacks are supposed to be added/deleted only during
1882 * single-threaded start-up shut-down procedures.
1884 struct list_head dd_txn_callbacks;
1885 unsigned int dd_record_fid_accessed:1,
1888 /* sysfs and debugfs handling */
1889 struct dentry *dd_debugfs_entry;
1891 const struct attribute **dd_def_attrs;
1892 struct kobject dd_kobj;
1893 struct kobj_type dd_ktype;
1894 struct completion dd_kobj_unregister;
1897 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1898 void dt_device_fini(struct dt_device *dev);
1900 static inline int lu_device_is_dt(const struct lu_device *d)
1902 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1905 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1907 LASSERT(lu_device_is_dt(l));
1908 return container_of_safe(l, struct dt_device, dd_lu_dev);
1912 struct lu_object do_lu;
1913 const struct dt_object_operations *do_ops;
1914 const struct dt_body_operations *do_body_ops;
1915 const struct dt_index_operations *do_index_ops;
1919 * In-core representation of per-device local object OID storage
1921 struct local_oid_storage {
1922 /* all initialized llog systems on this node linked by this */
1923 struct list_head los_list;
1925 /* how many handle's reference this los has */
1926 atomic_t los_refcount;
1927 struct dt_device *los_dev;
1928 struct dt_object *los_obj;
1930 /* data used to generate new fids */
1931 struct mutex los_id_lock;
1936 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1938 return &d->dd_lu_dev;
1941 static inline struct dt_object *lu2dt(struct lu_object *l)
1943 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1944 return container_of_safe(l, struct dt_object, do_lu);
1947 int dt_object_init(struct dt_object *obj,
1948 struct lu_object_header *h, struct lu_device *d);
1950 void dt_object_fini(struct dt_object *obj);
1952 static inline int dt_object_exists(const struct dt_object *dt)
1954 return lu_object_exists(&dt->do_lu);
1957 static inline int dt_object_remote(const struct dt_object *dt)
1959 return lu_object_remote(&dt->do_lu);
1962 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1964 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1965 return container_of_safe(o, struct dt_object, do_lu);
1968 static inline struct dt_object *dt_object_child(struct dt_object *o)
1970 return container_of(lu_object_next(&(o)->do_lu),
1971 struct dt_object, do_lu);
1975 * This is the general purpose transaction handle.
1976 * 1. Transaction Life Cycle
1977 * This transaction handle is allocated upon starting a new transaction,
1978 * and deallocated after this transaction is committed.
1979 * 2. Transaction Nesting
1980 * We do _NOT_ support nested transaction. So, every thread should only
1981 * have one active transaction, and a transaction only belongs to one
1982 * thread. Due to this, transaction handle need no reference count.
1983 * 3. Transaction & dt_object locking
1984 * dt_object locks should be taken inside transaction.
1985 * 4. Transaction & RPC
1986 * No RPC request should be issued inside transaction.
1989 /** the dt device on which the transactions are executed */
1990 struct dt_device *th_dev;
1992 /* point to the top thandle, XXX this is a bit hacky right now,
1993 * but normal device trans callback triggered by the bottom
1994 * device (OSP/OSD == sub thandle layer) needs to get the
1995 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1996 * top thandle here for now, will fix it when we have better
1997 * callback mechanism */
1998 struct thandle *th_top;
2000 /** the last operation result in this transaction.
2001 * this value is used in recovery */
2004 /** whether we need sync commit */
2005 unsigned int th_sync:1,
2006 /* local transation, no need to inform other layers */
2008 /* Whether we need wait the transaction to be submitted
2009 * (send to remote target) */
2011 /* complex transaction which will track updates on all targets,
2014 /* whether ignore quota */
2016 /* whether restart transaction */
2021 * Transaction call-backs.
2023 * These are invoked by osd (or underlying transaction engine) when
2024 * transaction changes state.
2026 * Call-backs are used by upper layers to modify transaction parameters and to
2027 * perform some actions on for each transaction state transition. Typical
2028 * example is mdt registering call-back to write into last-received file
2029 * before each transaction commit.
2031 struct dt_txn_callback {
2032 int (*dtc_txn_start)(const struct lu_env *env,
2033 struct thandle *txn, void *cookie);
2034 int (*dtc_txn_stop)(const struct lu_env *env,
2035 struct thandle *txn, void *cookie);
2038 struct list_head dtc_linkage;
2041 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
2042 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
2044 int dt_txn_hook_start(const struct lu_env *env,
2045 struct dt_device *dev, struct thandle *txn);
2046 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
2048 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
2051 * Callback function used for parsing path.
2052 * \see llo_store_resolve
2054 typedef int (*dt_entry_func_t)(const struct lu_env *env,
2058 #define DT_MAX_PATH 1024
2060 int dt_path_parser(const struct lu_env *env,
2061 char *local, dt_entry_func_t entry_func,
2065 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
2066 const char *path, struct lu_fid *fid);
2068 struct dt_object *dt_store_open(const struct lu_env *env,
2069 struct dt_device *dt,
2070 const char *dirname,
2071 const char *filename,
2072 struct lu_fid *fid);
2074 struct dt_object *dt_find_or_create(const struct lu_env *env,
2075 struct dt_device *dt,
2076 const struct lu_fid *fid,
2077 struct dt_object_format *dof,
2078 struct lu_attr *attr);
2080 struct dt_object *dt_locate_at(const struct lu_env *env,
2081 struct dt_device *dev,
2082 const struct lu_fid *fid,
2083 struct lu_device *top_dev,
2084 const struct lu_object_conf *conf);
2086 static inline struct dt_object *
2087 dt_locate(const struct lu_env *env, struct dt_device *dev,
2088 const struct lu_fid *fid)
2090 return dt_locate_at(env, dev, fid,
2091 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2094 static inline struct dt_object *
2095 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2097 struct lu_object *lo;
2099 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2100 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2101 return container_of(lo, struct dt_object, do_lu);
2106 static inline void dt_object_put(const struct lu_env *env,
2107 struct dt_object *dto)
2109 lu_object_put(env, &dto->do_lu);
2112 static inline void dt_object_put_nocache(const struct lu_env *env,
2113 struct dt_object *dto)
2115 lu_object_put_nocache(env, &dto->do_lu);
2118 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2119 const struct lu_fid *first_fid,
2120 struct local_oid_storage **los);
2121 void local_oid_storage_fini(const struct lu_env *env,
2122 struct local_oid_storage *los);
2123 int local_object_fid_generate(const struct lu_env *env,
2124 struct local_oid_storage *los,
2125 struct lu_fid *fid);
2126 int local_object_declare_create(const struct lu_env *env,
2127 struct local_oid_storage *los,
2128 struct dt_object *o,
2129 struct lu_attr *attr,
2130 struct dt_object_format *dof,
2131 struct thandle *th);
2132 int local_object_create(const struct lu_env *env,
2133 struct local_oid_storage *los,
2134 struct dt_object *o,
2135 struct lu_attr *attr, struct dt_object_format *dof,
2136 struct thandle *th);
2137 struct dt_object *local_file_find(const struct lu_env *env,
2138 struct local_oid_storage *los,
2139 struct dt_object *parent,
2141 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2142 struct local_oid_storage *los,
2143 struct dt_object *parent,
2144 const char *name, __u32 mode);
2145 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2146 struct dt_device *dt,
2147 const struct lu_fid *fid,
2148 struct dt_object *parent,
2152 local_index_find_or_create(const struct lu_env *env,
2153 struct local_oid_storage *los,
2154 struct dt_object *parent,
2155 const char *name, __u32 mode,
2156 const struct dt_index_features *ft);
2158 local_index_find_or_create_with_fid(const struct lu_env *env,
2159 struct dt_device *dt,
2160 const struct lu_fid *fid,
2161 struct dt_object *parent,
2162 const char *name, __u32 mode,
2163 const struct dt_index_features *ft);
2164 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2165 struct dt_object *parent, const char *name);
2167 static inline int dt_object_lock(const struct lu_env *env,
2168 struct dt_object *o, struct lustre_handle *lh,
2169 struct ldlm_enqueue_info *einfo,
2170 union ldlm_policy_data *policy)
2173 LASSERT(o->do_ops != NULL);
2174 LASSERT(o->do_ops->do_object_lock != NULL);
2175 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2178 static inline int dt_object_unlock(const struct lu_env *env,
2179 struct dt_object *o,
2180 struct ldlm_enqueue_info *einfo,
2181 union ldlm_policy_data *policy)
2184 LASSERT(o->do_ops != NULL);
2185 LASSERT(o->do_ops->do_object_unlock != NULL);
2186 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2189 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2190 const char *name, struct lu_fid *fid);
2192 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2193 __u64 start, __u64 end)
2197 LASSERT(o->do_ops->do_object_sync);
2198 return o->do_ops->do_object_sync(env, o, start, end);
2201 static inline int dt_fid_alloc(const struct lu_env *env,
2202 struct dt_device *d,
2204 struct lu_object *parent,
2205 const struct lu_name *name)
2207 struct lu_device *l = dt2lu_dev(d);
2209 return l->ld_ops->ldo_fid_alloc(env, l, fid, parent, name);
2212 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2213 struct thandle *th);
2214 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2215 dt_obj_version_t version, struct thandle *th);
2216 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2219 int dt_read(const struct lu_env *env, struct dt_object *dt,
2220 struct lu_buf *buf, loff_t *pos);
2221 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2222 struct lu_buf *buf, loff_t *pos);
2223 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2224 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2225 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2226 union lu_page *lp, size_t nob,
2227 const struct dt_it_ops *iops,
2228 struct dt_it *it, __u32 attr, void *arg);
2229 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2230 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2232 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2233 struct idx_info *ii, const struct lu_rdpg *rdpg);
2235 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2236 struct dt_device *d)
2238 LASSERT(d->dd_ops->dt_trans_create);
2239 return d->dd_ops->dt_trans_create(env, d);
2242 static inline int dt_trans_start(const struct lu_env *env,
2243 struct dt_device *d, struct thandle *th)
2245 LASSERT(d->dd_ops->dt_trans_start);
2246 return d->dd_ops->dt_trans_start(env, d, th);
2249 /* for this transaction hooks shouldn't be called */
2250 static inline int dt_trans_start_local(const struct lu_env *env,
2251 struct dt_device *d, struct thandle *th)
2253 LASSERT(d->dd_ops->dt_trans_start);
2255 return d->dd_ops->dt_trans_start(env, d, th);
2258 static inline int dt_trans_stop(const struct lu_env *env,
2259 struct dt_device *d, struct thandle *th)
2261 LASSERT(d->dd_ops->dt_trans_stop);
2262 return d->dd_ops->dt_trans_stop(env, d, th);
2265 static inline int dt_trans_cb_add(struct thandle *th,
2266 struct dt_txn_commit_cb *dcb)
2268 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2269 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2270 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2275 static inline int dt_declare_record_write(const struct lu_env *env,
2276 struct dt_object *dt,
2277 const struct lu_buf *buf,
2283 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2284 LASSERT(th != NULL);
2285 LASSERTF(dt->do_body_ops, DFID" doesn't exit\n",
2286 PFID(lu_object_fid(&dt->do_lu)));
2287 LASSERT(dt->do_body_ops->dbo_declare_write);
2288 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2292 static inline int dt_declare_create(const struct lu_env *env,
2293 struct dt_object *dt,
2294 struct lu_attr *attr,
2295 struct dt_allocation_hint *hint,
2296 struct dt_object_format *dof,
2300 LASSERT(dt->do_ops);
2301 LASSERT(dt->do_ops->do_declare_create);
2303 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2304 return cfs_fail_err;
2306 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2309 static inline int dt_create(const struct lu_env *env,
2310 struct dt_object *dt,
2311 struct lu_attr *attr,
2312 struct dt_allocation_hint *hint,
2313 struct dt_object_format *dof,
2317 LASSERT(dt->do_ops);
2318 LASSERT(dt->do_ops->do_create);
2320 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2321 return cfs_fail_err;
2323 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2326 static inline int dt_declare_destroy(const struct lu_env *env,
2327 struct dt_object *dt,
2331 LASSERT(dt->do_ops);
2332 LASSERT(dt->do_ops->do_declare_destroy);
2334 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2335 return cfs_fail_err;
2337 return dt->do_ops->do_declare_destroy(env, dt, th);
2340 static inline int dt_destroy(const struct lu_env *env,
2341 struct dt_object *dt,
2345 LASSERT(dt->do_ops);
2346 LASSERT(dt->do_ops->do_destroy);
2348 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2349 return cfs_fail_err;
2351 return dt->do_ops->do_destroy(env, dt, th);
2354 static inline void dt_read_lock(const struct lu_env *env,
2355 struct dt_object *dt,
2359 LASSERT(dt->do_ops);
2360 LASSERT(dt->do_ops->do_read_lock);
2361 dt->do_ops->do_read_lock(env, dt, role);
2364 static inline void dt_write_lock(const struct lu_env *env,
2365 struct dt_object *dt,
2369 LASSERT(dt->do_ops);
2370 LASSERT(dt->do_ops->do_write_lock);
2371 dt->do_ops->do_write_lock(env, dt, role);
2374 static inline void dt_read_unlock(const struct lu_env *env,
2375 struct dt_object *dt)
2378 LASSERT(dt->do_ops);
2379 LASSERT(dt->do_ops->do_read_unlock);
2380 dt->do_ops->do_read_unlock(env, dt);
2383 static inline void dt_write_unlock(const struct lu_env *env,
2384 struct dt_object *dt)
2387 LASSERT(dt->do_ops);
2388 LASSERT(dt->do_ops->do_write_unlock);
2389 dt->do_ops->do_write_unlock(env, dt);
2392 static inline int dt_write_locked(const struct lu_env *env,
2393 struct dt_object *dt)
2396 LASSERT(dt->do_ops);
2397 LASSERT(dt->do_ops->do_write_locked);
2398 return dt->do_ops->do_write_locked(env, dt);
2401 static inline bool dt_object_stale(struct dt_object *dt)
2404 LASSERT(dt->do_ops);
2405 LASSERT(dt->do_ops->do_check_stale);
2407 return dt->do_ops->do_check_stale(dt);
2410 static inline int dt_declare_attr_get(const struct lu_env *env,
2411 struct dt_object *dt)
2414 LASSERT(dt->do_ops);
2415 LASSERT(dt->do_ops->do_declare_attr_get);
2417 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2418 return cfs_fail_err;
2420 return dt->do_ops->do_declare_attr_get(env, dt);
2423 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2427 LASSERT(dt->do_ops);
2428 LASSERT(dt->do_ops->do_attr_get);
2430 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2431 return cfs_fail_err;
2433 return dt->do_ops->do_attr_get(env, dt, la);
2436 static inline int dt_declare_attr_set(const struct lu_env *env,
2437 struct dt_object *dt,
2438 const struct lu_attr *la,
2442 LASSERT(dt->do_ops);
2443 LASSERT(dt->do_ops->do_declare_attr_set);
2445 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2446 return cfs_fail_err;
2448 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2451 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2452 const struct lu_attr *la, struct thandle *th)
2455 LASSERT(dt->do_ops);
2456 LASSERT(dt->do_ops->do_attr_set);
2458 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2459 return cfs_fail_err;
2461 return dt->do_ops->do_attr_set(env, dt, la, th);
2464 static inline int dt_declare_ref_add(const struct lu_env *env,
2465 struct dt_object *dt, struct thandle *th)
2468 LASSERT(dt->do_ops);
2469 LASSERT(dt->do_ops->do_declare_ref_add);
2471 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2472 return cfs_fail_err;
2474 return dt->do_ops->do_declare_ref_add(env, dt, th);
2477 static inline int dt_ref_add(const struct lu_env *env,
2478 struct dt_object *dt, struct thandle *th)
2481 LASSERT(dt->do_ops);
2482 LASSERT(dt->do_ops->do_ref_add);
2484 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2485 return cfs_fail_err;
2487 return dt->do_ops->do_ref_add(env, dt, th);
2490 static inline int dt_declare_ref_del(const struct lu_env *env,
2491 struct dt_object *dt, struct thandle *th)
2494 LASSERT(dt->do_ops);
2495 LASSERT(dt->do_ops->do_declare_ref_del);
2497 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2498 return cfs_fail_err;
2500 return dt->do_ops->do_declare_ref_del(env, dt, th);
2503 static inline int dt_ref_del(const struct lu_env *env,
2504 struct dt_object *dt, struct thandle *th)
2507 LASSERT(dt->do_ops);
2508 LASSERT(dt->do_ops->do_ref_del);
2510 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2511 return cfs_fail_err;
2513 return dt->do_ops->do_ref_del(env, dt, th);
2516 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2517 struct niobuf_remote *rnb,
2518 struct niobuf_local *lnb, int maxlnb,
2519 enum dt_bufs_type rw)
2522 LASSERT(d->do_body_ops);
2523 LASSERT(d->do_body_ops->dbo_bufs_get);
2524 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2525 rnb->rnb_len, lnb, maxlnb, rw);
2528 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2529 struct niobuf_local *lnb, int n)
2532 LASSERT(d->do_body_ops);
2533 LASSERT(d->do_body_ops->dbo_bufs_put);
2534 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2537 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2538 struct niobuf_local *lnb, int n)
2541 LASSERT(d->do_body_ops);
2542 LASSERT(d->do_body_ops->dbo_write_prep);
2543 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2546 static inline int dt_declare_write_commit(const struct lu_env *env,
2547 struct dt_object *d,
2548 struct niobuf_local *lnb,
2549 int n, struct thandle *th)
2551 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2552 LASSERT(th != NULL);
2553 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2557 static inline int dt_write_commit(const struct lu_env *env,
2558 struct dt_object *d, struct niobuf_local *lnb,
2559 int n, struct thandle *th, __u64 size)
2562 LASSERT(d->do_body_ops);
2563 LASSERT(d->do_body_ops->dbo_write_commit);
2564 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th, size);
2567 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2568 struct niobuf_local *lnb, int n)
2571 LASSERT(d->do_body_ops);
2572 LASSERT(d->do_body_ops->dbo_read_prep);
2573 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2576 static inline int dt_declare_write(const struct lu_env *env,
2577 struct dt_object *dt,
2578 const struct lu_buf *buf, loff_t pos,
2582 LASSERT(dt->do_body_ops);
2583 LASSERT(dt->do_body_ops->dbo_declare_write);
2584 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2587 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2588 const struct lu_buf *buf, loff_t *pos,
2592 LASSERT(dt->do_body_ops);
2593 LASSERT(dt->do_body_ops->dbo_write);
2594 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2597 static inline int dt_declare_punch(const struct lu_env *env,
2598 struct dt_object *dt, __u64 start,
2599 __u64 end, struct thandle *th)
2602 LASSERT(dt->do_body_ops);
2603 LASSERT(dt->do_body_ops->dbo_declare_punch);
2604 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2607 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2608 __u64 start, __u64 end, struct thandle *th)
2611 LASSERT(dt->do_body_ops);
2612 LASSERT(dt->do_body_ops->dbo_punch);
2613 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2616 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2617 __u64 start, __u64 end, int advice)
2620 LASSERT(dt->do_body_ops);
2621 LASSERT(dt->do_body_ops->dbo_ladvise);
2622 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2625 static inline int dt_declare_fallocate(const struct lu_env *env,
2626 struct dt_object *dt, __u64 start,
2627 __u64 end, int mode, struct thandle *th)
2630 if (!dt->do_body_ops)
2632 LASSERT(dt->do_body_ops);
2633 LASSERT(dt->do_body_ops->dbo_declare_fallocate);
2634 return dt->do_body_ops->dbo_declare_fallocate(env, dt, start, end,
2638 static inline int dt_falloc(const struct lu_env *env, struct dt_object *dt,
2639 __u64 start, __u64 end, int mode,
2643 if (!dt->do_body_ops)
2645 LASSERT(dt->do_body_ops);
2646 LASSERT(dt->do_body_ops->dbo_fallocate);
2647 return dt->do_body_ops->dbo_fallocate(env, dt, start, end, mode, th);
2650 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2654 if (d->do_body_ops == NULL)
2656 if (d->do_body_ops->dbo_fiemap_get == NULL)
2658 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2661 static inline loff_t dt_lseek(const struct lu_env *env, struct dt_object *d,
2662 loff_t offset, int whence)
2665 if (d->do_body_ops == NULL)
2667 if (d->do_body_ops->dbo_lseek == NULL)
2669 return d->do_body_ops->dbo_lseek(env, d, offset, whence);
2672 static inline int dt_statfs_info(const struct lu_env *env,
2673 struct dt_device *dev,
2674 struct obd_statfs *osfs,
2675 struct obd_statfs_info *info)
2678 LASSERT(dev->dd_ops);
2679 LASSERT(dev->dd_ops->dt_statfs);
2680 return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2683 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2684 struct obd_statfs *osfs)
2686 return dt_statfs_info(env, dev, osfs, NULL);
2689 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2693 LASSERT(dev->dd_ops);
2694 LASSERT(dev->dd_ops->dt_root_get);
2695 return dev->dd_ops->dt_root_get(env, dev, f);
2698 static inline void dt_conf_get(const struct lu_env *env,
2699 const struct dt_device *dev,
2700 struct dt_device_param *param)
2703 LASSERT(dev->dd_ops);
2704 LASSERT(dev->dd_ops->dt_conf_get);
2705 return dev->dd_ops->dt_conf_get(env, dev, param);
2708 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2711 LASSERT(dev->dd_ops);
2712 if (dev->dd_ops->dt_mnt_sb_get)
2713 return dev->dd_ops->dt_mnt_sb_get(dev);
2715 return ERR_PTR(-EOPNOTSUPP);
2718 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2721 LASSERT(dev->dd_ops);
2722 LASSERT(dev->dd_ops->dt_sync);
2723 return dev->dd_ops->dt_sync(env, dev);
2726 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2729 LASSERT(dev->dd_ops);
2730 LASSERT(dev->dd_ops->dt_ro);
2731 return dev->dd_ops->dt_ro(env, dev);
2734 static inline void dt_wait_quota_pending(struct dt_device *dev)
2737 LASSERT(dev->dd_ops);
2738 if (dev->dd_ops->dt_wait_quota_pending)
2739 dev->dd_ops->dt_wait_quota_pending(dev);
2742 static inline int dt_declare_insert(const struct lu_env *env,
2743 struct dt_object *dt,
2744 const struct dt_rec *rec,
2745 const struct dt_key *key,
2749 LASSERT(dt->do_index_ops);
2750 LASSERT(dt->do_index_ops->dio_declare_insert);
2752 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2753 return cfs_fail_err;
2755 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2758 static inline int dt_insert(const struct lu_env *env,
2759 struct dt_object *dt,
2760 const struct dt_rec *rec,
2761 const struct dt_key *key,
2765 LASSERT(dt->do_index_ops);
2766 LASSERT(dt->do_index_ops->dio_insert);
2768 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2769 return cfs_fail_err;
2771 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2774 static inline int dt_declare_xattr_del(const struct lu_env *env,
2775 struct dt_object *dt,
2780 LASSERT(dt->do_ops);
2781 LASSERT(dt->do_ops->do_declare_xattr_del);
2783 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2784 return cfs_fail_err;
2786 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2789 static inline int dt_xattr_del(const struct lu_env *env,
2790 struct dt_object *dt, const char *name,
2794 LASSERT(dt->do_ops);
2795 LASSERT(dt->do_ops->do_xattr_del);
2797 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2798 return cfs_fail_err;
2800 return dt->do_ops->do_xattr_del(env, dt, name, th);
2803 static inline int dt_declare_xattr_set(const struct lu_env *env,
2804 struct dt_object *dt,
2805 const struct lu_buf *buf,
2806 const char *name, int fl,
2810 LASSERT(dt->do_ops);
2811 LASSERT(dt->do_ops->do_declare_xattr_set);
2813 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2814 return cfs_fail_err;
2816 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2819 static inline int dt_xattr_set(const struct lu_env *env,
2820 struct dt_object *dt, const struct lu_buf *buf,
2821 const char *name, int fl, struct thandle *th)
2824 LASSERT(dt->do_ops);
2825 LASSERT(dt->do_ops->do_xattr_set);
2827 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2828 return cfs_fail_err;
2830 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2833 static inline int dt_declare_xattr_get(const struct lu_env *env,
2834 struct dt_object *dt,
2839 LASSERT(dt->do_ops);
2840 LASSERT(dt->do_ops->do_declare_xattr_get);
2842 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2843 return cfs_fail_err;
2845 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2848 static inline int dt_xattr_get(const struct lu_env *env,
2849 struct dt_object *dt, struct lu_buf *buf,
2853 LASSERT(dt->do_ops);
2854 LASSERT(dt->do_ops->do_xattr_get);
2856 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2857 return cfs_fail_err;
2859 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2862 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2863 const struct lu_buf *buf)
2866 LASSERT(dt->do_ops);
2867 LASSERT(dt->do_ops->do_xattr_list);
2869 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2870 return cfs_fail_err;
2872 return dt->do_ops->do_xattr_list(env, dt, buf);
2875 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2878 LASSERT(dt->do_ops);
2879 LASSERT(dt->do_ops->do_invalidate);
2881 return dt->do_ops->do_invalidate(env, dt);
2884 static inline int dt_declare_delete(const struct lu_env *env,
2885 struct dt_object *dt,
2886 const struct dt_key *key,
2890 LASSERT(dt->do_index_ops);
2891 LASSERT(dt->do_index_ops->dio_declare_delete);
2893 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2894 return cfs_fail_err;
2896 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2899 static inline int dt_delete(const struct lu_env *env,
2900 struct dt_object *dt,
2901 const struct dt_key *key,
2905 LASSERT(dt->do_index_ops);
2906 LASSERT(dt->do_index_ops->dio_delete);
2908 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2909 return cfs_fail_err;
2911 return dt->do_index_ops->dio_delete(env, dt, key, th);
2914 static inline int dt_commit_async(const struct lu_env *env,
2915 struct dt_device *dev)
2918 LASSERT(dev->dd_ops);
2919 LASSERT(dev->dd_ops->dt_commit_async);
2920 return dev->dd_ops->dt_commit_async(env, dev);
2923 static inline int dt_lookup(const struct lu_env *env,
2924 struct dt_object *dt,
2926 const struct dt_key *key)
2931 LASSERT(dt->do_index_ops);
2932 LASSERT(dt->do_index_ops->dio_lookup);
2934 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2935 return cfs_fail_err;
2937 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2945 static inline int dt_declare_layout_change(const struct lu_env *env,
2946 struct dt_object *o,
2947 struct md_layout_change *mlc,
2952 LASSERT(o->do_ops->do_declare_layout_change);
2953 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2956 static inline int dt_layout_change(const struct lu_env *env,
2957 struct dt_object *o,
2958 struct md_layout_change *mlc,
2963 LASSERT(o->do_ops->do_layout_change);
2964 return o->do_ops->do_layout_change(env, o, mlc, th);
2967 struct dt_find_hint {
2968 struct lu_fid *dfh_fid;
2969 struct dt_device *dfh_dt;
2970 struct dt_object *dfh_o;
2973 struct dt_insert_rec {
2975 const struct lu_fid *rec_fid;
2987 struct dt_thread_info {
2988 char dti_buf[DT_MAX_PATH];
2989 struct dt_find_hint dti_dfh;
2990 struct lu_attr dti_attr;
2991 struct lu_fid dti_fid;
2992 struct dt_object_format dti_dof;
2993 struct lustre_mdt_attrs dti_lma;
2994 struct lu_buf dti_lb;
2995 struct lu_object_conf dti_conf;
2997 struct dt_insert_rec dti_dt_rec;
3000 extern struct lu_context_key dt_key;
3002 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
3004 struct dt_thread_info *dti;
3006 dti = lu_context_key_get(&env->le_ctx, &dt_key);
3011 int dt_global_init(void);
3012 void dt_global_fini(void);
3013 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
3014 const char *name, struct ldebugfs_vars *list);
3015 int dt_tunables_fini(struct dt_device *dt);
3017 # ifdef CONFIG_PROC_FS
3018 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
3019 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
3020 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
3021 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
3022 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
3023 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
3024 # endif /* CONFIG_PROC_FS */
3026 #endif /* __LUSTRE_DT_OBJECT_H */