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 * Declare intention to instaintiate extended layout component.
1068 * \param[in] env execution environment
1069 * \param[in] dt DT object
1070 * \param[in] layout data structure to describe the changes to
1071 * the DT object's layout
1072 * \param[in] buf buffer containing client's lovea or empty
1075 * \retval -ne error code
1077 int (*do_declare_layout_change)(const struct lu_env *env,
1078 struct dt_object *dt,
1079 struct md_layout_change *mlc,
1080 struct thandle *th);
1083 * Client is trying to write to un-instantiated layout component.
1085 * \param[in] env execution environment
1086 * \param[in] dt DT object
1087 * \param[in] layout data structure to describe the changes to
1088 * the DT object's layout
1089 * \param[in] buf buffer containing client's lovea or empty
1092 * \retval -ne error code
1094 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1095 struct md_layout_change *mlc,
1096 struct thandle *th);
1100 DT_BUFS_TYPE_READ = 0x0000,
1101 DT_BUFS_TYPE_WRITE = 0x0001,
1102 DT_BUFS_TYPE_READAHEAD = 0x0002,
1103 DT_BUFS_TYPE_LOCAL = 0x0004,
1107 * Per-dt-object operations on "file body" - unstructure raw data.
1109 struct dt_body_operations {
1113 * Read unstructured data from an existing regular object.
1114 * Only data before attr.la_size is returned.
1116 * \param[in] env execution environment for this thread
1117 * \param[in] dt object
1118 * \param[out] buf buffer (including size) to copy data in
1119 * \param[in] pos position in the object to start
1120 * \param[out] pos original value of \a pos + bytes returned
1122 * \retval positive bytes read on success
1123 * \retval negative negated errno on error
1125 ssize_t (*dbo_read)(const struct lu_env *env,
1126 struct dt_object *dt,
1131 * Declare intention to write data to object.
1133 * Notify the underlying filesystem that data may be written in
1134 * this transaction. This enables the layer below to prepare resources
1135 * (e.g. journal credits in ext4). This method should be called
1136 * between creating the transaction and starting it. The object need
1137 * not exist. If the layer implementing this method is responsible for
1138 * quota, then the method should reserve space for the given credentials
1139 * and return an error if quota is over. If the write later fails
1140 * for some reason, then the reserve should be released properly
1141 * (usually in ->dt_trans_stop()).
1143 * \param[in] env execution environment for this thread
1144 * \param[in] dt object
1145 * \param[in] buf buffer (including size) to copy data from
1146 * \param[in] pos position in the object to start
1147 * \param[in] th transaction handle
1149 * \retval 0 on success
1150 * \retval negative negated errno on error
1152 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1153 struct dt_object *dt,
1154 const struct lu_buf *buf,
1156 struct thandle *th);
1159 * Write unstructured data to regular existing object.
1161 * The method allocates space and puts data in. Also, the method should
1162 * maintain attr.la_size properly. Partial writes are possible.
1164 * If the layer implementing this method is responsible for quota,
1165 * then the method should maintain space accounting for the given
1168 * \param[in] env execution environment for this thread
1169 * \param[in] dt object
1170 * \param[in] buf buffer (including size) to copy data from
1171 * \param[in] pos position in the object to start
1172 * \param[out] pos \a pos + bytes written
1173 * \param[in] th transaction handle
1175 * \retval positive bytes written on success
1176 * \retval negative negated errno on error
1178 ssize_t (*dbo_write)(const struct lu_env *env,
1179 struct dt_object *dt,
1180 const struct lu_buf *buf,
1182 struct thandle *th);
1185 * Return buffers for data.
1187 * This method is used to access data with no copying. It's so-called
1188 * zero-copy I/O. The method returns the descriptors for the internal
1189 * buffers where data are managed by the disk filesystem. For example,
1190 * pagecache in case of ext4 or ARC with ZFS. Then other components
1191 * (e.g. networking) can transfer data from or to the buffers with no
1192 * additional copying.
1194 * The method should fill an array of struct niobuf_local, where
1195 * each element describes a full or partial page for data at specific
1196 * offset. The caller should use page/lnb_page_offset/len to find data
1197 * at object's offset lnb_file_offset.
1199 * The memory referenced by the descriptors can't change its purpose
1200 * until the complementary ->dbo_bufs_put() is called. The caller should
1201 * specify if the buffers are used to read or modify data so that OSD
1202 * can decide how to initialize the buffers: bring all the data for
1203 * reads or just bring partial buffers for write. Note: the method does
1204 * not check whether output array is large enough.
1206 * \param[in] env execution environment for this thread
1207 * \param[in] dt object
1208 * \param[in] pos position in the object to start
1209 * \param[in] len size of region in bytes
1210 * \param[out] lb array of descriptors to fill
1211 * \param[in] maxlnb max slots in @lnb array
1212 * \param[in] rw 0 if used to read, 1 if used for write
1214 * \retval positive number of descriptors on success
1215 * \retval negative negated errno on error
1217 int (*dbo_bufs_get)(const struct lu_env *env,
1218 struct dt_object *dt,
1221 struct niobuf_local *lb,
1223 enum dt_bufs_type rw);
1226 * Release reference granted by ->dbo_bufs_get().
1228 * Release the reference granted by the previous ->dbo_bufs_get().
1229 * Note the references are counted.
1231 * \param[in] env execution environment for this thread
1232 * \param[in] dt object
1233 * \param[out] lb array of descriptors to fill
1234 * \param[in] nr size of the array
1236 * \retval 0 on success
1237 * \retval negative negated errno on error
1239 int (*dbo_bufs_put)(const struct lu_env *env,
1240 struct dt_object *dt,
1241 struct niobuf_local *lb,
1245 * Prepare buffers for reading.
1247 * The method is called on the given buffers to fill them with data
1248 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1249 * caller should be able to get few buffers for discontiguous regions
1250 * using few calls to ->dbo_bufs_get() and then request them all for
1251 * the preparation with a single call, so that OSD can fire many I/Os
1252 * to run concurrently. It's up to the specific OSD whether to implement
1253 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1254 * prepare data for every requested region individually.
1256 * \param[in] env execution environment for this thread
1257 * \param[in] dt object
1258 * \param[in] lnb array of buffer descriptors
1259 * \param[in] nr size of the array
1261 * \retval 0 on success
1262 * \retval negative negated errno on error
1264 int (*dbo_read_prep)(const struct lu_env *env,
1265 struct dt_object *dt,
1266 struct niobuf_local *lnb,
1270 * Prepare buffers for write.
1272 * This method is called on the given buffers to ensure the partial
1273 * buffers contain correct data. The underlying idea is the same as
1274 * in ->db_read_prep().
1276 * \param[in] env execution environment for this thread
1277 * \param[in] dt object
1278 * \param[in] lb array of buffer descriptors
1279 * \param[in] nr size of the array
1281 * \retval 0 on success
1282 * \retval negative negated errno on error
1284 int (*dbo_write_prep)(const struct lu_env *env,
1285 struct dt_object *dt,
1286 struct niobuf_local *lb,
1290 * Declare intention to write data stored in the buffers.
1292 * Notify the underlying filesystem that data may be written in
1293 * this transaction. This enables the layer below to prepare resources
1294 * (e.g. journal credits in ext4). This method should be called
1295 * between creating the transaction and starting it.
1297 * If the layer implementing this method is responsible for quota,
1298 * then the method should be reserving a space for the given
1299 * credentials and return an error if quota is exceeded. If the write
1300 * later fails for some reason, then the reserve should be released
1301 * properly (usually in ->dt_trans_stop()).
1303 * \param[in] env execution environment for this thread
1304 * \param[in] dt object
1305 * \param[in] lb array of descriptors
1306 * \param[in] nr size of the array
1307 * \param[in] th transaction handle
1309 * \retval 0 on success
1310 * \retval negative negated errno on error
1312 int (*dbo_declare_write_commit)(const struct lu_env *env,
1313 struct dt_object *dt,
1314 struct niobuf_local *lb,
1316 struct thandle *th);
1319 * Write to existing object.
1321 * This method is used to write data to a persistent storage using
1322 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1323 * data into the buffers using own mechanisms (e.g. direct transfer
1324 * from a NIC). The method should maintain attr.la_size. Also,
1325 * attr.la_blocks should be maintained but this can be done in lazy
1326 * manner, when actual allocation happens.
1328 * If the layer implementing this method is responsible for quota,
1329 * then the method should maintain space accounting for the given
1332 * user_size parameter is the apparent size of the file, ie the size
1333 * of the clear text version of the file. It can differ from the actual
1334 * amount of valuable data received when a file is encrypted,
1335 * because encrypted pages always contain PAGE_SIZE bytes of data,
1336 * even if clear text data is only a few bytes.
1337 * In case of encrypted file, apparent size will be stored as the inode
1338 * size, so that servers return to clients an object size they can use
1339 * to determine clear text size.
1341 * \param[in] env execution environment for this thread
1342 * \param[in] dt object
1343 * \param[in] lb array of descriptors for the buffers
1344 * \param[in] nr size of the array
1345 * \param[in] th transaction handle
1346 * \param[in] user_size apparent size
1348 * \retval 0 on success
1349 * \retval negative negated errno on error
1351 int (*dbo_write_commit)(const struct lu_env *env,
1352 struct dt_object *dt,
1353 struct niobuf_local *lb,
1359 * Return logical to physical block mapping for a given extent
1361 * \param[in] env execution environment for this thread
1362 * \param[in] dt object
1363 * \param[in] fm describe the region to map and the output buffer
1364 * see the details in include/linux/fiemap.h
1366 * \retval 0 on success
1367 * \retval negative negated errno on error
1369 int (*dbo_fiemap_get)(const struct lu_env *env,
1370 struct dt_object *dt,
1374 * Declare intention to deallocate space from an object.
1376 * Notify the underlying filesystem that space may be deallocated in
1377 * this transactions. This enables the layer below to prepare resources
1378 * (e.g. journal credits in ext4). This method should be called between
1379 * creating the transaction and starting it. The object need not exist.
1381 * \param[in] env execution environment for this thread
1382 * \param[in] dt object
1383 * \param[in] start the start of the region to deallocate
1384 * \param[in] end the end of the region to deallocate
1385 * \param[in] th transaction handle
1387 * \retval 0 on success
1388 * \retval negative negated errno on error
1390 int (*dbo_declare_punch)(const struct lu_env *env,
1391 struct dt_object *dt,
1394 struct thandle *th);
1397 * Deallocate specified region in an object.
1399 * This method is used to deallocate (release) space possibly consumed
1400 * by the given region of the object. If the layer implementing this
1401 * method is responsible for quota, then the method should maintain
1402 * space accounting for the given credentials.
1404 * \param[in] env execution environment for this thread
1405 * \param[in] dt object
1406 * \param[in] start the start of the region to deallocate
1407 * \param[in] end the end of the region to deallocate
1408 * \param[in] th transaction handle
1410 * \retval 0 on success
1411 * \retval negative negated errno on error
1413 int (*dbo_punch)(const struct lu_env *env,
1414 struct dt_object *dt,
1417 struct thandle *th);
1419 * Give advices on specified region in an object.
1421 * This method is used to give advices about access pattern on an
1422 * given region of the object. The disk filesystem understands
1423 * the advices and tunes cache/read-ahead policies.
1425 * \param[in] env execution environment for this thread
1426 * \param[in] dt object
1427 * \param[in] start the start of the region affected
1428 * \param[in] end the end of the region affected
1429 * \param[in] advice advice type
1431 * \retval 0 on success
1432 * \retval negative negated errno on error
1434 int (*dbo_ladvise)(const struct lu_env *env,
1435 struct dt_object *dt,
1438 enum lu_ladvise_type advice);
1441 * Declare intention to preallocate space for an object
1443 * \param[in] env execution environment for this thread
1444 * \param[in] dt object
1445 * \param[in] th transaction handle
1447 * \retval 0 on success
1448 * \retval negative negated errno on error
1450 int (*dbo_declare_fallocate)(const struct lu_env *env,
1451 struct dt_object *dt, __u64 start,
1452 __u64 end, int mode, struct thandle *th);
1454 * Allocate specified region for an object
1456 * \param[in] env execution environment for this thread
1457 * \param[in] dt object
1458 * \param[in] start the start of the region to allocate
1459 * \param[in] end the end of the region to allocate
1460 * \param[in] mode fallocate mode
1461 * \param[in] th transaction handle
1463 * \retval 0 on success
1464 * \retval negative negated errno on error
1466 int (*dbo_fallocate)(const struct lu_env *env,
1467 struct dt_object *dt,
1471 struct thandle *th);
1473 * Do SEEK_HOLE/SEEK_DATA request on object
1475 * \param[in] env execution environment for this thread
1476 * \param[in] dt object
1477 * \param[in] offset the offset to start seek from
1478 * \param[in] whence seek mode, SEEK_HOLE or SEEK_DATA
1480 * \retval hole/data offset on success
1481 * \retval negative negated errno on error
1483 loff_t (*dbo_lseek)(const struct lu_env *env, struct dt_object *dt,
1484 loff_t offset, int whence);
1488 * Incomplete type of index record.
1493 * Incomplete type of index key.
1498 * Incomplete type of dt iterator.
1503 * Per-dt-object operations on object as index. Index is a set of key/value
1504 * pairs abstracted from an on-disk representation. An index supports the
1505 * number of operations including lookup by key, insert and delete. Also,
1506 * an index can be iterated to find the pairs one by one, from a beginning
1507 * or specified point.
1509 struct dt_index_operations {
1511 * Lookup in an index by key.
1513 * The method returns a value for the given key. Key/value format
1514 * and size should have been negotiated with ->do_index_try() before.
1515 * Thus it's the caller's responsibility to provide the method with
1516 * proper key and big enough buffer. No external locking is required,
1517 * all the internal consistency should be implemented by the method
1518 * or lower layers. The object should should have been created with
1519 * type DFT_INDEX or DFT_DIR.
1521 * \param[in] env execution environment for this thread
1522 * \param[in] dt object
1523 * \param[out] rec buffer where value will be stored
1524 * \param[in] key key
1526 * \retval 0 on success
1527 * \retval -ENOENT if key isn't found
1528 * \retval negative negated errno on error
1530 int (*dio_lookup)(const struct lu_env *env,
1531 struct dt_object *dt,
1533 const struct dt_key *key);
1536 * Declare intention to insert a key/value into an index.
1538 * Notify the underlying filesystem that new key/value may be inserted
1539 * in this transaction. This enables the layer below to prepare
1540 * resources (e.g. journal credits in ext4). This method should be
1541 * called between creating the transaction and starting it. key/value
1542 * format and size is subject to ->do_index_try().
1544 * \param[in] env execution environment for this thread
1545 * \param[in] dt object
1546 * \param[in] rec buffer storing value
1547 * \param[in] key key
1548 * \param[in] th transaction handle
1550 * \retval 0 on success
1551 * \retval negative negated errno on error
1553 int (*dio_declare_insert)(const struct lu_env *env,
1554 struct dt_object *dt,
1555 const struct dt_rec *rec,
1556 const struct dt_key *key,
1557 struct thandle *th);
1560 * Insert a new key/value pair into an index.
1562 * The method inserts specified key/value pair into the given index
1563 * object. The internal consistency is maintained by the method or
1564 * the functionality below. The format and size of key/value should
1565 * have been negotiated before using ->do_index_try(), no additional
1566 * information can be specified to the method. The keys are unique
1569 * \param[in] env execution environment for this thread
1570 * \param[in] dt object
1571 * \param[in] rec buffer storing value
1572 * \param[in] key key
1573 * \param[in] th transaction handle
1575 * \retval 0 on success
1576 * \retval negative negated errno on error
1578 int (*dio_insert)(const struct lu_env *env,
1579 struct dt_object *dt,
1580 const struct dt_rec *rec,
1581 const struct dt_key *key,
1582 struct thandle *th);
1585 * Declare intention to delete a key/value from an index.
1587 * Notify the underlying filesystem that key/value may be deleted in
1588 * this transaction. This enables the layer below to prepare resources
1589 * (e.g. journal credits in ext4). This method should be called
1590 * between creating the transaction and starting it. Key/value format
1591 * and size is subject to ->do_index_try(). The object need not exist.
1593 * \param[in] env execution environment for this thread
1594 * \param[in] dt object
1595 * \param[in] key key
1596 * \param[in] th transaction handle
1598 * \retval 0 on success
1599 * \retval negative negated errno on error
1601 int (*dio_declare_delete)(const struct lu_env *env,
1602 struct dt_object *dt,
1603 const struct dt_key *key,
1604 struct thandle *th);
1607 * Delete key/value pair from an index.
1609 * The method deletes specified key and corresponding value from the
1610 * given index object. The internal consistency is maintained by the
1611 * method or the functionality below. The format and size of the key
1612 * should have been negotiated before using ->do_index_try(), no
1613 * additional information can be specified to the method.
1615 * \param[in] env execution environment for this thread
1616 * \param[in] dt object
1617 * \param[in] key key
1618 * \param[in] th transaction handle
1620 * \retval 0 on success
1621 * \retval negative negated errno on error
1623 int (*dio_delete)(const struct lu_env *env,
1624 struct dt_object *dt,
1625 const struct dt_key *key,
1626 struct thandle *th);
1629 * Iterator interface.
1631 * Methods to iterate over an existing index, list the keys stored and
1632 * associated values, get key/value size, etc.
1636 * Allocate and initialize new iterator.
1638 * The iterator is a handler to be used in the subsequent
1639 * methods to access index's content. Note the position is
1640 * not defined at this point and should be initialized with
1641 * ->get() or ->load() method.
1643 * \param[in] env execution environment for this thread
1644 * \param[in] dt object
1645 * \param[in] attr ask the iterator to return part of
1646 the records, see LUDA_* for details
1648 * \retval pointer iterator pointer on success
1649 * \retval ERR_PTR(errno) on error
1651 struct dt_it *(*init)(const struct lu_env *env,
1652 struct dt_object *dt,
1658 * Release the specified iterator and all the resources
1659 * associated (e.g. the object, index cache, etc).
1661 * \param[in] env execution environment for this thread
1662 * \param[in] di iterator to release
1664 void (*fini)(const struct lu_env *env,
1668 * Move position of iterator.
1670 * Move the position of the specified iterator to the specified
1673 * \param[in] env execution environment for this thread
1674 * \param[in] di iterator
1675 * \param[in] key key to position to
1677 * \retval 0 if exact key is found
1678 * \retval 1 if at the record with least key
1679 * not larger than the key
1680 * \retval negative negated errno on error
1682 int (*get)(const struct lu_env *env,
1684 const struct dt_key *key);
1689 * Complimentary method for dt_it_ops::get() above. Some
1690 * implementation can increase a reference on the iterator in
1691 * dt_it_ops::get(). So the caller should be able to release
1692 * with dt_it_ops::put().
1694 * \param[in] env execution environment for this thread
1695 * \param[in] di iterator
1697 void (*put)(const struct lu_env *env,
1701 * Move to next record.
1703 * Moves the position of the iterator to a next record
1705 * \param[in] env execution environment for this thread
1706 * \param[in] di iterator
1708 * \retval 1 if no more records
1709 * \retval 0 on success, the next record is found
1710 * \retval negative negated errno on error
1712 int (*next)(const struct lu_env *env,
1718 * Returns a pointer to a buffer containing the key of the
1719 * record at the current position. The pointer is valid and
1720 * retains data until ->get(), ->load() and ->fini() methods
1723 * \param[in] env execution environment for this thread
1724 * \param[in] di iterator
1726 * \retval pointer to key on success
1727 * \retval ERR_PTR(errno) on error
1729 struct dt_key *(*key)(const struct lu_env *env,
1730 const struct dt_it *di);
1735 * Returns size of the key at the current position.
1737 * \param[in] env execution environment for this thread
1738 * \param[in] di iterator
1740 * \retval key's size on success
1741 * \retval negative negated errno on error
1743 int (*key_size)(const struct lu_env *env,
1744 const struct dt_it *di);
1749 * Stores the value of the record at the current position. The
1750 * buffer must be big enough (as negotiated with
1751 * ->do_index_try() or ->rec_size()). The caller can specify
1752 * she is interested only in part of the record, using attr
1753 * argument (see LUDA_* definitions for the details).
1755 * \param[in] env execution environment for this thread
1756 * \param[in] di iterator
1757 * \param[out] rec buffer to store value in
1758 * \param[in] attr specify part of the value to copy
1760 * \retval 0 on success
1761 * \retval negative negated errno on error
1763 int (*rec)(const struct lu_env *env,
1764 const struct dt_it *di,
1769 * Return record size.
1771 * Returns size of the record at the current position. The
1772 * \a attr can be used to specify only the parts of the record
1773 * needed to be returned. (see LUDA_* definitions for the
1776 * \param[in] env execution environment for this thread
1777 * \param[in] di iterator
1778 * \param[in] attr part of the record to return
1780 * \retval record's size on success
1781 * \retval negative negated errno on error
1783 int (*rec_size)(const struct lu_env *env,
1784 const struct dt_it *di,
1788 * Return a cookie (hash).
1790 * Returns the cookie (usually hash) of the key at the current
1791 * position. This allows the caller to resume iteration at this
1792 * position later. The exact value is specific to implementation
1793 * and should not be interpreted by the caller.
1795 * \param[in] env execution environment for this thread
1796 * \param[in] di iterator
1798 * \retval cookie/hash of the key
1800 __u64 (*store)(const struct lu_env *env,
1801 const struct dt_it *di);
1804 * Initialize position using cookie/hash.
1806 * Initializes the current position of the iterator to one
1807 * described by the cookie/hash as returned by ->store()
1810 * \param[in] env execution environment for this thread
1811 * \param[in] di iterator
1812 * \param[in] hash cookie/hash value
1814 * \retval positive if current position points to
1815 * record with least cookie not larger
1817 * \retval 0 if current position matches cookie
1818 * \retval negative negated errno on error
1820 int (*load)(const struct lu_env *env,
1821 const struct dt_it *di,
1827 int (*key_rec)(const struct lu_env *env,
1828 const struct dt_it *di,
1833 enum dt_otable_it_valid {
1834 DOIV_ERROR_HANDLE = 0x0001,
1835 DOIV_DRYRUN = 0x0002,
1838 enum dt_otable_it_flags {
1839 /* Exit when fail. */
1840 DOIF_FAILOUT = 0x0001,
1842 /* Reset iteration position to the device beginning. */
1843 DOIF_RESET = 0x0002,
1845 /* There is up layer component uses the iteration. */
1846 DOIF_OUTUSED = 0x0004,
1848 /* Check only without repairing. */
1849 DOIF_DRYRUN = 0x0008,
1852 /* otable based iteration needs to use the common DT iteration APIs.
1853 * To initialize the iteration, it needs call dio_it::init() firstly.
1854 * Here is how the otable based iteration should prepare arguments to
1855 * call dt_it_ops::init().
1857 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1858 * is composed of two parts:
1859 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1860 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1861 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1864 struct lu_device dd_lu_dev;
1865 const struct dt_device_operations *dd_ops;
1868 * List of dt_txn_callback (see below). This is not protected in any
1869 * way, because callbacks are supposed to be added/deleted only during
1870 * single-threaded start-up shut-down procedures.
1872 struct list_head dd_txn_callbacks;
1873 unsigned int dd_record_fid_accessed:1,
1876 /* sysfs and debugfs handling */
1877 struct dentry *dd_debugfs_entry;
1879 const struct attribute **dd_def_attrs;
1880 struct kobject dd_kobj;
1881 struct kobj_type dd_ktype;
1882 struct completion dd_kobj_unregister;
1885 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1886 void dt_device_fini(struct dt_device *dev);
1888 static inline int lu_device_is_dt(const struct lu_device *d)
1890 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1893 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1895 LASSERT(lu_device_is_dt(l));
1896 return container_of_safe(l, struct dt_device, dd_lu_dev);
1900 struct lu_object do_lu;
1901 const struct dt_object_operations *do_ops;
1902 const struct dt_body_operations *do_body_ops;
1903 const struct dt_index_operations *do_index_ops;
1907 * In-core representation of per-device local object OID storage
1909 struct local_oid_storage {
1910 /* all initialized llog systems on this node linked by this */
1911 struct list_head los_list;
1913 /* how many handle's reference this los has */
1914 atomic_t los_refcount;
1915 struct dt_device *los_dev;
1916 struct dt_object *los_obj;
1918 /* data used to generate new fids */
1919 struct mutex los_id_lock;
1924 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1926 return &d->dd_lu_dev;
1929 static inline struct dt_object *lu2dt(struct lu_object *l)
1931 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1932 return container_of_safe(l, struct dt_object, do_lu);
1935 int dt_object_init(struct dt_object *obj,
1936 struct lu_object_header *h, struct lu_device *d);
1938 void dt_object_fini(struct dt_object *obj);
1940 static inline int dt_object_exists(const struct dt_object *dt)
1942 return lu_object_exists(&dt->do_lu);
1945 static inline int dt_object_remote(const struct dt_object *dt)
1947 return lu_object_remote(&dt->do_lu);
1950 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1952 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1953 return container_of_safe(o, struct dt_object, do_lu);
1956 static inline struct dt_object *dt_object_child(struct dt_object *o)
1958 return container_of(lu_object_next(&(o)->do_lu),
1959 struct dt_object, do_lu);
1963 * This is the general purpose transaction handle.
1964 * 1. Transaction Life Cycle
1965 * This transaction handle is allocated upon starting a new transaction,
1966 * and deallocated after this transaction is committed.
1967 * 2. Transaction Nesting
1968 * We do _NOT_ support nested transaction. So, every thread should only
1969 * have one active transaction, and a transaction only belongs to one
1970 * thread. Due to this, transaction handle need no reference count.
1971 * 3. Transaction & dt_object locking
1972 * dt_object locks should be taken inside transaction.
1973 * 4. Transaction & RPC
1974 * No RPC request should be issued inside transaction.
1977 /** the dt device on which the transactions are executed */
1978 struct dt_device *th_dev;
1980 /* point to the top thandle, XXX this is a bit hacky right now,
1981 * but normal device trans callback triggered by the bottom
1982 * device (OSP/OSD == sub thandle layer) needs to get the
1983 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1984 * top thandle here for now, will fix it when we have better
1985 * callback mechanism */
1986 struct thandle *th_top;
1988 /** the last operation result in this transaction.
1989 * this value is used in recovery */
1992 /** whether we need sync commit */
1993 unsigned int th_sync:1,
1994 /* local transation, no need to inform other layers */
1996 /* Whether we need wait the transaction to be submitted
1997 * (send to remote target) */
1999 /* complex transaction which will track updates on all targets,
2002 /* whether ignore quota */
2004 /* whether restart transaction */
2009 * Transaction call-backs.
2011 * These are invoked by osd (or underlying transaction engine) when
2012 * transaction changes state.
2014 * Call-backs are used by upper layers to modify transaction parameters and to
2015 * perform some actions on for each transaction state transition. Typical
2016 * example is mdt registering call-back to write into last-received file
2017 * before each transaction commit.
2019 struct dt_txn_callback {
2020 int (*dtc_txn_start)(const struct lu_env *env,
2021 struct thandle *txn, void *cookie);
2022 int (*dtc_txn_stop)(const struct lu_env *env,
2023 struct thandle *txn, void *cookie);
2026 struct list_head dtc_linkage;
2029 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
2030 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
2032 int dt_txn_hook_start(const struct lu_env *env,
2033 struct dt_device *dev, struct thandle *txn);
2034 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
2036 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
2039 * Callback function used for parsing path.
2040 * \see llo_store_resolve
2042 typedef int (*dt_entry_func_t)(const struct lu_env *env,
2046 #define DT_MAX_PATH 1024
2048 int dt_path_parser(const struct lu_env *env,
2049 char *local, dt_entry_func_t entry_func,
2053 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
2054 const char *path, struct lu_fid *fid);
2056 struct dt_object *dt_store_open(const struct lu_env *env,
2057 struct dt_device *dt,
2058 const char *dirname,
2059 const char *filename,
2060 struct lu_fid *fid);
2062 struct dt_object *dt_find_or_create(const struct lu_env *env,
2063 struct dt_device *dt,
2064 const struct lu_fid *fid,
2065 struct dt_object_format *dof,
2066 struct lu_attr *attr);
2068 struct dt_object *dt_locate_at(const struct lu_env *env,
2069 struct dt_device *dev,
2070 const struct lu_fid *fid,
2071 struct lu_device *top_dev,
2072 const struct lu_object_conf *conf);
2074 static inline struct dt_object *
2075 dt_locate(const struct lu_env *env, struct dt_device *dev,
2076 const struct lu_fid *fid)
2078 return dt_locate_at(env, dev, fid,
2079 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
2082 static inline struct dt_object *
2083 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
2085 struct lu_object *lo;
2087 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
2088 if (lo->lo_dev == &dt_dev->dd_lu_dev)
2089 return container_of(lo, struct dt_object, do_lu);
2094 static inline void dt_object_put(const struct lu_env *env,
2095 struct dt_object *dto)
2097 lu_object_put(env, &dto->do_lu);
2100 static inline void dt_object_put_nocache(const struct lu_env *env,
2101 struct dt_object *dto)
2103 lu_object_put_nocache(env, &dto->do_lu);
2106 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2107 const struct lu_fid *first_fid,
2108 struct local_oid_storage **los);
2109 void local_oid_storage_fini(const struct lu_env *env,
2110 struct local_oid_storage *los);
2111 int local_object_fid_generate(const struct lu_env *env,
2112 struct local_oid_storage *los,
2113 struct lu_fid *fid);
2114 int local_object_declare_create(const struct lu_env *env,
2115 struct local_oid_storage *los,
2116 struct dt_object *o,
2117 struct lu_attr *attr,
2118 struct dt_object_format *dof,
2119 struct thandle *th);
2120 int local_object_create(const struct lu_env *env,
2121 struct local_oid_storage *los,
2122 struct dt_object *o,
2123 struct lu_attr *attr, struct dt_object_format *dof,
2124 struct thandle *th);
2125 struct dt_object *local_file_find(const struct lu_env *env,
2126 struct local_oid_storage *los,
2127 struct dt_object *parent,
2129 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2130 struct local_oid_storage *los,
2131 struct dt_object *parent,
2132 const char *name, __u32 mode);
2133 struct dt_object *local_file_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,
2140 local_index_find_or_create(const struct lu_env *env,
2141 struct local_oid_storage *los,
2142 struct dt_object *parent,
2143 const char *name, __u32 mode,
2144 const struct dt_index_features *ft);
2146 local_index_find_or_create_with_fid(const struct lu_env *env,
2147 struct dt_device *dt,
2148 const struct lu_fid *fid,
2149 struct dt_object *parent,
2150 const char *name, __u32 mode,
2151 const struct dt_index_features *ft);
2152 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2153 struct dt_object *parent, const char *name);
2155 static inline int dt_object_lock(const struct lu_env *env,
2156 struct dt_object *o, struct lustre_handle *lh,
2157 struct ldlm_enqueue_info *einfo,
2158 union ldlm_policy_data *policy)
2161 LASSERT(o->do_ops != NULL);
2162 LASSERT(o->do_ops->do_object_lock != NULL);
2163 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2166 static inline int dt_object_unlock(const struct lu_env *env,
2167 struct dt_object *o,
2168 struct ldlm_enqueue_info *einfo,
2169 union ldlm_policy_data *policy)
2172 LASSERT(o->do_ops != NULL);
2173 LASSERT(o->do_ops->do_object_unlock != NULL);
2174 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2177 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2178 const char *name, struct lu_fid *fid);
2180 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2181 __u64 start, __u64 end)
2185 LASSERT(o->do_ops->do_object_sync);
2186 return o->do_ops->do_object_sync(env, o, start, end);
2189 static inline int dt_fid_alloc(const struct lu_env *env,
2190 struct dt_device *d,
2192 struct lu_object *parent,
2193 const struct lu_name *name)
2195 struct lu_device *l = dt2lu_dev(d);
2197 return l->ld_ops->ldo_fid_alloc(env, l, fid, parent, name);
2200 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2201 struct thandle *th);
2202 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2203 dt_obj_version_t version, struct thandle *th);
2204 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2207 int dt_read(const struct lu_env *env, struct dt_object *dt,
2208 struct lu_buf *buf, loff_t *pos);
2209 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2210 struct lu_buf *buf, loff_t *pos);
2211 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2212 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2213 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2214 union lu_page *lp, size_t nob,
2215 const struct dt_it_ops *iops,
2216 struct dt_it *it, __u32 attr, void *arg);
2217 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2218 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2220 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2221 struct idx_info *ii, const struct lu_rdpg *rdpg);
2223 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2224 struct dt_device *d)
2226 LASSERT(d->dd_ops->dt_trans_create);
2227 return d->dd_ops->dt_trans_create(env, d);
2230 static inline int dt_trans_start(const struct lu_env *env,
2231 struct dt_device *d, struct thandle *th)
2233 LASSERT(d->dd_ops->dt_trans_start);
2234 return d->dd_ops->dt_trans_start(env, d, th);
2237 /* for this transaction hooks shouldn't be called */
2238 static inline int dt_trans_start_local(const struct lu_env *env,
2239 struct dt_device *d, struct thandle *th)
2241 LASSERT(d->dd_ops->dt_trans_start);
2243 return d->dd_ops->dt_trans_start(env, d, th);
2246 static inline int dt_trans_stop(const struct lu_env *env,
2247 struct dt_device *d, struct thandle *th)
2249 LASSERT(d->dd_ops->dt_trans_stop);
2250 return d->dd_ops->dt_trans_stop(env, d, th);
2253 static inline int dt_trans_cb_add(struct thandle *th,
2254 struct dt_txn_commit_cb *dcb)
2256 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2257 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2258 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2263 static inline int dt_declare_record_write(const struct lu_env *env,
2264 struct dt_object *dt,
2265 const struct lu_buf *buf,
2271 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2272 LASSERT(th != NULL);
2273 LASSERTF(dt->do_body_ops, DFID" doesn't exit\n",
2274 PFID(lu_object_fid(&dt->do_lu)));
2275 LASSERT(dt->do_body_ops->dbo_declare_write);
2276 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2280 static inline int dt_declare_create(const struct lu_env *env,
2281 struct dt_object *dt,
2282 struct lu_attr *attr,
2283 struct dt_allocation_hint *hint,
2284 struct dt_object_format *dof,
2288 LASSERT(dt->do_ops);
2289 LASSERT(dt->do_ops->do_declare_create);
2291 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2292 return cfs_fail_err;
2294 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2297 static inline int dt_create(const struct lu_env *env,
2298 struct dt_object *dt,
2299 struct lu_attr *attr,
2300 struct dt_allocation_hint *hint,
2301 struct dt_object_format *dof,
2305 LASSERT(dt->do_ops);
2306 LASSERT(dt->do_ops->do_create);
2308 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2309 return cfs_fail_err;
2311 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2314 static inline int dt_declare_destroy(const struct lu_env *env,
2315 struct dt_object *dt,
2319 LASSERT(dt->do_ops);
2320 LASSERT(dt->do_ops->do_declare_destroy);
2322 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2323 return cfs_fail_err;
2325 return dt->do_ops->do_declare_destroy(env, dt, th);
2328 static inline int dt_destroy(const struct lu_env *env,
2329 struct dt_object *dt,
2333 LASSERT(dt->do_ops);
2334 LASSERT(dt->do_ops->do_destroy);
2336 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2337 return cfs_fail_err;
2339 return dt->do_ops->do_destroy(env, dt, th);
2342 static inline void dt_read_lock(const struct lu_env *env,
2343 struct dt_object *dt,
2347 LASSERT(dt->do_ops);
2348 LASSERT(dt->do_ops->do_read_lock);
2349 dt->do_ops->do_read_lock(env, dt, role);
2352 static inline void dt_write_lock(const struct lu_env *env,
2353 struct dt_object *dt,
2357 LASSERT(dt->do_ops);
2358 LASSERT(dt->do_ops->do_write_lock);
2359 dt->do_ops->do_write_lock(env, dt, role);
2362 static inline void dt_read_unlock(const struct lu_env *env,
2363 struct dt_object *dt)
2366 LASSERT(dt->do_ops);
2367 LASSERT(dt->do_ops->do_read_unlock);
2368 dt->do_ops->do_read_unlock(env, dt);
2371 static inline void dt_write_unlock(const struct lu_env *env,
2372 struct dt_object *dt)
2375 LASSERT(dt->do_ops);
2376 LASSERT(dt->do_ops->do_write_unlock);
2377 dt->do_ops->do_write_unlock(env, dt);
2380 static inline int dt_write_locked(const struct lu_env *env,
2381 struct dt_object *dt)
2384 LASSERT(dt->do_ops);
2385 LASSERT(dt->do_ops->do_write_locked);
2386 return dt->do_ops->do_write_locked(env, dt);
2389 static inline int dt_declare_attr_get(const struct lu_env *env,
2390 struct dt_object *dt)
2393 LASSERT(dt->do_ops);
2394 LASSERT(dt->do_ops->do_declare_attr_get);
2396 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2397 return cfs_fail_err;
2399 return dt->do_ops->do_declare_attr_get(env, dt);
2402 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2406 LASSERT(dt->do_ops);
2407 LASSERT(dt->do_ops->do_attr_get);
2409 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2410 return cfs_fail_err;
2412 return dt->do_ops->do_attr_get(env, dt, la);
2415 static inline int dt_declare_attr_set(const struct lu_env *env,
2416 struct dt_object *dt,
2417 const struct lu_attr *la,
2421 LASSERT(dt->do_ops);
2422 LASSERT(dt->do_ops->do_declare_attr_set);
2424 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2425 return cfs_fail_err;
2427 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2430 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2431 const struct lu_attr *la, struct thandle *th)
2434 LASSERT(dt->do_ops);
2435 LASSERT(dt->do_ops->do_attr_set);
2437 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2438 return cfs_fail_err;
2440 return dt->do_ops->do_attr_set(env, dt, la, th);
2443 static inline int dt_declare_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_declare_ref_add);
2450 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2451 return cfs_fail_err;
2453 return dt->do_ops->do_declare_ref_add(env, dt, th);
2456 static inline int dt_ref_add(const struct lu_env *env,
2457 struct dt_object *dt, struct thandle *th)
2460 LASSERT(dt->do_ops);
2461 LASSERT(dt->do_ops->do_ref_add);
2463 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2464 return cfs_fail_err;
2466 return dt->do_ops->do_ref_add(env, dt, th);
2469 static inline int dt_declare_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_declare_ref_del);
2476 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2477 return cfs_fail_err;
2479 return dt->do_ops->do_declare_ref_del(env, dt, th);
2482 static inline int dt_ref_del(const struct lu_env *env,
2483 struct dt_object *dt, struct thandle *th)
2486 LASSERT(dt->do_ops);
2487 LASSERT(dt->do_ops->do_ref_del);
2489 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2490 return cfs_fail_err;
2492 return dt->do_ops->do_ref_del(env, dt, th);
2495 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2496 struct niobuf_remote *rnb,
2497 struct niobuf_local *lnb, int maxlnb,
2498 enum dt_bufs_type rw)
2501 LASSERT(d->do_body_ops);
2502 LASSERT(d->do_body_ops->dbo_bufs_get);
2503 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2504 rnb->rnb_len, lnb, maxlnb, rw);
2507 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2508 struct niobuf_local *lnb, int n)
2511 LASSERT(d->do_body_ops);
2512 LASSERT(d->do_body_ops->dbo_bufs_put);
2513 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2516 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2517 struct niobuf_local *lnb, int n)
2520 LASSERT(d->do_body_ops);
2521 LASSERT(d->do_body_ops->dbo_write_prep);
2522 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2525 static inline int dt_declare_write_commit(const struct lu_env *env,
2526 struct dt_object *d,
2527 struct niobuf_local *lnb,
2528 int n, struct thandle *th)
2530 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2531 LASSERT(th != NULL);
2532 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2536 static inline int dt_write_commit(const struct lu_env *env,
2537 struct dt_object *d, struct niobuf_local *lnb,
2538 int n, struct thandle *th, __u64 size)
2541 LASSERT(d->do_body_ops);
2542 LASSERT(d->do_body_ops->dbo_write_commit);
2543 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th, size);
2546 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2547 struct niobuf_local *lnb, int n)
2550 LASSERT(d->do_body_ops);
2551 LASSERT(d->do_body_ops->dbo_read_prep);
2552 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2555 static inline int dt_declare_write(const struct lu_env *env,
2556 struct dt_object *dt,
2557 const struct lu_buf *buf, loff_t pos,
2561 LASSERT(dt->do_body_ops);
2562 LASSERT(dt->do_body_ops->dbo_declare_write);
2563 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2566 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2567 const struct lu_buf *buf, loff_t *pos,
2571 LASSERT(dt->do_body_ops);
2572 LASSERT(dt->do_body_ops->dbo_write);
2573 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th);
2576 static inline int dt_declare_punch(const struct lu_env *env,
2577 struct dt_object *dt, __u64 start,
2578 __u64 end, struct thandle *th)
2581 LASSERT(dt->do_body_ops);
2582 LASSERT(dt->do_body_ops->dbo_declare_punch);
2583 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2586 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2587 __u64 start, __u64 end, struct thandle *th)
2590 LASSERT(dt->do_body_ops);
2591 LASSERT(dt->do_body_ops->dbo_punch);
2592 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2595 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2596 __u64 start, __u64 end, int advice)
2599 LASSERT(dt->do_body_ops);
2600 LASSERT(dt->do_body_ops->dbo_ladvise);
2601 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2604 static inline int dt_declare_fallocate(const struct lu_env *env,
2605 struct dt_object *dt, __u64 start,
2606 __u64 end, int mode, struct thandle *th)
2609 if (!dt->do_body_ops)
2611 LASSERT(dt->do_body_ops);
2612 LASSERT(dt->do_body_ops->dbo_declare_fallocate);
2613 return dt->do_body_ops->dbo_declare_fallocate(env, dt, start, end,
2617 static inline int dt_falloc(const struct lu_env *env, struct dt_object *dt,
2618 __u64 start, __u64 end, int mode,
2622 if (!dt->do_body_ops)
2624 LASSERT(dt->do_body_ops);
2625 LASSERT(dt->do_body_ops->dbo_fallocate);
2626 return dt->do_body_ops->dbo_fallocate(env, dt, start, end, mode, th);
2629 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2633 if (d->do_body_ops == NULL)
2635 if (d->do_body_ops->dbo_fiemap_get == NULL)
2637 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2640 static inline loff_t dt_lseek(const struct lu_env *env, struct dt_object *d,
2641 loff_t offset, int whence)
2644 if (d->do_body_ops == NULL)
2646 if (d->do_body_ops->dbo_lseek == NULL)
2648 return d->do_body_ops->dbo_lseek(env, d, offset, whence);
2651 static inline int dt_statfs_info(const struct lu_env *env,
2652 struct dt_device *dev,
2653 struct obd_statfs *osfs,
2654 struct obd_statfs_info *info)
2657 LASSERT(dev->dd_ops);
2658 LASSERT(dev->dd_ops->dt_statfs);
2659 return dev->dd_ops->dt_statfs(env, dev, osfs, info);
2662 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2663 struct obd_statfs *osfs)
2665 return dt_statfs_info(env, dev, osfs, NULL);
2668 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2672 LASSERT(dev->dd_ops);
2673 LASSERT(dev->dd_ops->dt_root_get);
2674 return dev->dd_ops->dt_root_get(env, dev, f);
2677 static inline void dt_conf_get(const struct lu_env *env,
2678 const struct dt_device *dev,
2679 struct dt_device_param *param)
2682 LASSERT(dev->dd_ops);
2683 LASSERT(dev->dd_ops->dt_conf_get);
2684 return dev->dd_ops->dt_conf_get(env, dev, param);
2687 static inline struct super_block *dt_mnt_sb_get(const struct dt_device *dev)
2690 LASSERT(dev->dd_ops);
2691 if (dev->dd_ops->dt_mnt_sb_get)
2692 return dev->dd_ops->dt_mnt_sb_get(dev);
2694 return ERR_PTR(-EOPNOTSUPP);
2697 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2700 LASSERT(dev->dd_ops);
2701 LASSERT(dev->dd_ops->dt_sync);
2702 return dev->dd_ops->dt_sync(env, dev);
2705 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2708 LASSERT(dev->dd_ops);
2709 LASSERT(dev->dd_ops->dt_ro);
2710 return dev->dd_ops->dt_ro(env, dev);
2713 static inline void dt_wait_quota_pending(struct dt_device *dev)
2716 LASSERT(dev->dd_ops);
2717 if (dev->dd_ops->dt_wait_quota_pending)
2718 dev->dd_ops->dt_wait_quota_pending(dev);
2721 static inline int dt_declare_insert(const struct lu_env *env,
2722 struct dt_object *dt,
2723 const struct dt_rec *rec,
2724 const struct dt_key *key,
2728 LASSERT(dt->do_index_ops);
2729 LASSERT(dt->do_index_ops->dio_declare_insert);
2731 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2732 return cfs_fail_err;
2734 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2737 static inline int dt_insert(const struct lu_env *env,
2738 struct dt_object *dt,
2739 const struct dt_rec *rec,
2740 const struct dt_key *key,
2744 LASSERT(dt->do_index_ops);
2745 LASSERT(dt->do_index_ops->dio_insert);
2747 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2748 return cfs_fail_err;
2750 return dt->do_index_ops->dio_insert(env, dt, rec, key, th);
2753 static inline int dt_declare_xattr_del(const struct lu_env *env,
2754 struct dt_object *dt,
2759 LASSERT(dt->do_ops);
2760 LASSERT(dt->do_ops->do_declare_xattr_del);
2762 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2763 return cfs_fail_err;
2765 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2768 static inline int dt_xattr_del(const struct lu_env *env,
2769 struct dt_object *dt, const char *name,
2773 LASSERT(dt->do_ops);
2774 LASSERT(dt->do_ops->do_xattr_del);
2776 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2777 return cfs_fail_err;
2779 return dt->do_ops->do_xattr_del(env, dt, name, th);
2782 static inline int dt_declare_xattr_set(const struct lu_env *env,
2783 struct dt_object *dt,
2784 const struct lu_buf *buf,
2785 const char *name, int fl,
2789 LASSERT(dt->do_ops);
2790 LASSERT(dt->do_ops->do_declare_xattr_set);
2792 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2793 return cfs_fail_err;
2795 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2798 static inline int dt_xattr_set(const struct lu_env *env,
2799 struct dt_object *dt, const struct lu_buf *buf,
2800 const char *name, int fl, struct thandle *th)
2803 LASSERT(dt->do_ops);
2804 LASSERT(dt->do_ops->do_xattr_set);
2806 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2807 return cfs_fail_err;
2809 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2812 static inline int dt_declare_xattr_get(const struct lu_env *env,
2813 struct dt_object *dt,
2818 LASSERT(dt->do_ops);
2819 LASSERT(dt->do_ops->do_declare_xattr_get);
2821 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2822 return cfs_fail_err;
2824 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2827 static inline int dt_xattr_get(const struct lu_env *env,
2828 struct dt_object *dt, struct lu_buf *buf,
2832 LASSERT(dt->do_ops);
2833 LASSERT(dt->do_ops->do_xattr_get);
2835 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2836 return cfs_fail_err;
2838 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2841 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2842 const struct lu_buf *buf)
2845 LASSERT(dt->do_ops);
2846 LASSERT(dt->do_ops->do_xattr_list);
2848 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2849 return cfs_fail_err;
2851 return dt->do_ops->do_xattr_list(env, dt, buf);
2854 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2857 LASSERT(dt->do_ops);
2858 LASSERT(dt->do_ops->do_invalidate);
2860 return dt->do_ops->do_invalidate(env, dt);
2863 static inline int dt_declare_delete(const struct lu_env *env,
2864 struct dt_object *dt,
2865 const struct dt_key *key,
2869 LASSERT(dt->do_index_ops);
2870 LASSERT(dt->do_index_ops->dio_declare_delete);
2872 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2873 return cfs_fail_err;
2875 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2878 static inline int dt_delete(const struct lu_env *env,
2879 struct dt_object *dt,
2880 const struct dt_key *key,
2884 LASSERT(dt->do_index_ops);
2885 LASSERT(dt->do_index_ops->dio_delete);
2887 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2888 return cfs_fail_err;
2890 return dt->do_index_ops->dio_delete(env, dt, key, th);
2893 static inline int dt_commit_async(const struct lu_env *env,
2894 struct dt_device *dev)
2897 LASSERT(dev->dd_ops);
2898 LASSERT(dev->dd_ops->dt_commit_async);
2899 return dev->dd_ops->dt_commit_async(env, dev);
2902 static inline int dt_lookup(const struct lu_env *env,
2903 struct dt_object *dt,
2905 const struct dt_key *key)
2910 LASSERT(dt->do_index_ops);
2911 LASSERT(dt->do_index_ops->dio_lookup);
2913 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2914 return cfs_fail_err;
2916 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2924 static inline int dt_declare_layout_change(const struct lu_env *env,
2925 struct dt_object *o,
2926 struct md_layout_change *mlc,
2931 LASSERT(o->do_ops->do_declare_layout_change);
2932 return o->do_ops->do_declare_layout_change(env, o, mlc, th);
2935 static inline int dt_layout_change(const struct lu_env *env,
2936 struct dt_object *o,
2937 struct md_layout_change *mlc,
2942 LASSERT(o->do_ops->do_layout_change);
2943 return o->do_ops->do_layout_change(env, o, mlc, th);
2946 struct dt_find_hint {
2947 struct lu_fid *dfh_fid;
2948 struct dt_device *dfh_dt;
2949 struct dt_object *dfh_o;
2952 struct dt_insert_rec {
2954 const struct lu_fid *rec_fid;
2966 struct dt_thread_info {
2967 char dti_buf[DT_MAX_PATH];
2968 struct dt_find_hint dti_dfh;
2969 struct lu_attr dti_attr;
2970 struct lu_fid dti_fid;
2971 struct dt_object_format dti_dof;
2972 struct lustre_mdt_attrs dti_lma;
2973 struct lu_buf dti_lb;
2974 struct lu_object_conf dti_conf;
2976 struct dt_insert_rec dti_dt_rec;
2979 extern struct lu_context_key dt_key;
2981 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2983 struct dt_thread_info *dti;
2985 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2990 int dt_global_init(void);
2991 void dt_global_fini(void);
2992 int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
2993 const char *name, struct ldebugfs_vars *list);
2994 int dt_tunables_fini(struct dt_device *dt);
2996 # ifdef CONFIG_PROC_FS
2997 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2998 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2999 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
3000 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
3001 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
3002 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
3003 # endif /* CONFIG_PROC_FS */
3005 #endif /* __LUSTRE_DT_OBJECT_H */