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, 2016, 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 ddp_extent_tax;
91 * Per-transaction commit callback function
93 struct dt_txn_commit_cb;
94 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
95 struct dt_txn_commit_cb *cb, int err);
97 * Special per-transaction callback for cases when just commit callback
98 * is needed and per-device callback are not convenient to use
100 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
101 #define MAX_COMMIT_CB_STR_LEN 32
103 #define DCB_TRANS_STOP 0x1
104 struct dt_txn_commit_cb {
105 struct list_head dcb_linkage;
110 char dcb_name[MAX_COMMIT_CB_STR_LEN];
114 * Operations on dt device.
116 struct dt_device_operations {
118 * Return device-wide statistics.
120 * Return device-wide stats including block size, total and
121 * free blocks, total and free objects, etc. See struct obd_statfs
124 * \param[in] env execution environment for this thread
125 * \param[in] dev dt device
126 * \param[out] osfs stats information
128 * \retval 0 on success
129 * \retval negative negated errno on error
131 int (*dt_statfs)(const struct lu_env *env,
132 struct dt_device *dev,
133 struct obd_statfs *osfs);
136 * Create transaction.
138 * Create in-memory structure representing the transaction for the
139 * caller. The structure returned will be used by the calling thread
140 * to specify the transaction the updates belong to. Once created
141 * successfully ->dt_trans_stop() must be called in any case (with
142 * ->dt_trans_start() and updates or not) so that the transaction
143 * handle and other resources can be released by the layers below.
145 * \param[in] env execution environment for this thread
146 * \param[in] dev dt device
148 * \retval pointer to handle if creation succeeds
149 * \retval ERR_PTR(errno) if creation fails
151 struct thandle *(*dt_trans_create)(const struct lu_env *env,
152 struct dt_device *dev);
157 * Start the transaction. The transaction described by \a th can be
158 * started only once. Another start is considered as an error.
159 * A thread is not supposed to start a transaction while another
160 * transaction isn't closed by the thread (though multiple handles
161 * can be created). The caller should start the transaction once
162 * all possible updates are declared (see the ->do_declare_* methods
163 * below) and all the needed resources are reserved.
165 * \param[in] env execution environment for this thread
166 * \param[in] dev dt device
167 * \param[in] th transaction handle
169 * \retval 0 on success
170 * \retval negative negated errno on error
172 int (*dt_trans_start)(const struct lu_env *env,
173 struct dt_device *dev,
179 * Once stopped the transaction described by \a th is complete (all
180 * the needed updates are applied) and further processing such as
181 * flushing to disk, sending to another target, etc, is handled by
182 * lower layers. The caller can't access this transaction by the
183 * handle anymore (except from the commit callbacks, see below).
185 * \param[in] env execution environment for this thread
186 * \param[in] dev dt device
187 * \param[in] th transaction handle
189 * \retval 0 on success
190 * \retval negative negated errno on error
192 int (*dt_trans_stop)(const struct lu_env *env,
193 struct dt_device *dev,
197 * Add commit callback to the transaction.
199 * Add a commit callback to the given transaction handle. The callback
200 * will be called when the associated transaction is stored. I.e. the
201 * transaction will survive an event like power off if the callback did
202 * run. The number of callbacks isn't limited, but you should note that
203 * some disk filesystems do handle the commit callbacks in the thread
204 * handling commit/flush of all the transactions, meaning that new
205 * transactions are blocked from commit and flush until all the
206 * callbacks are done. Also, note multiple callbacks can be running
207 * concurrently using multiple CPU cores. The callbacks will be running
208 * in a special environment which can not be used to pass data around.
210 * \param[in] th transaction handle
211 * \param[in] dcb commit callback description
213 * \retval 0 on success
214 * \retval negative negated errno on error
216 int (*dt_trans_cb_add)(struct thandle *th,
217 struct dt_txn_commit_cb *dcb);
220 * Return FID of root index object.
222 * Return the FID of the root object in the filesystem. This object
223 * is usually provided as a bootstrap point by a disk filesystem.
224 * This is up to the implementation which FID to use, though
225 * [FID_SEQ_ROOT:1:0] is reserved for this purpose.
227 * \param[in] env execution environment for this thread
228 * \param[in] dev dt device
229 * \param[out] fid FID of the root object
231 * \retval 0 on success
232 * \retval negative negated errno on error
234 int (*dt_root_get)(const struct lu_env *env,
235 struct dt_device *dev,
239 * Return device configuration data.
241 * Return device (disk fs, actually) specific configuration.
242 * The configuration isn't subject to change at runtime.
243 * See struct dt_device_param for the details.
245 * \param[in] env execution environment for this thread
246 * \param[in] dev dt device
247 * \param[out] param configuration parameters
249 void (*dt_conf_get)(const struct lu_env *env,
250 const struct dt_device *dev,
251 struct dt_device_param *param);
256 * Sync all the cached state (dirty buffers, pages, etc) to the
257 * persistent storage. The method returns control once the sync is
258 * complete. This operation may incur significant I/O to disk and
259 * should be reserved for cases where a global sync is strictly
262 * \param[in] env execution environment for this thread
263 * \param[in] dev dt device
265 * \retval 0 on success
266 * \retval negative negated errno on error
268 int (*dt_sync)(const struct lu_env *env,
269 struct dt_device *dev);
272 * Make device read-only.
274 * Prevent new modifications to the device. This is a very specific
275 * state where all the changes are accepted successfully and the
276 * commit callbacks are called, but persistent state never changes.
277 * Used only in the tests to simulate power-off scenario.
279 * \param[in] env execution environment for this thread
280 * \param[in] dev dt device
282 * \retval 0 on success
283 * \retval negative negated errno on error
285 int (*dt_ro)(const struct lu_env *env,
286 struct dt_device *dev);
289 * Start transaction commit asynchronously.
292 * Provide a hint to the underlying filesystem that it should start
293 * committing soon. The control returns immediately. It's up to the
294 * layer implementing the method how soon to start committing. Usually
295 * this should be throttled to some extent, otherwise the number of
296 * aggregated transaction goes too high causing performance drop.
298 * \param[in] env execution environment for this thread
299 * \param[in] dev dt device
301 * \retval 0 on success
302 * \retval negative negated errno on error
304 int (*dt_commit_async)(const struct lu_env *env,
305 struct dt_device *dev);
308 struct dt_index_features {
309 /** required feature flags from enum dt_index_flags */
311 /** minimal required key size */
312 size_t dif_keysize_min;
313 /** maximal required key size, 0 if no limit */
314 size_t dif_keysize_max;
315 /** minimal required record size */
316 size_t dif_recsize_min;
317 /** maximal required record size, 0 if no limit */
318 size_t dif_recsize_max;
319 /** pointer size for record */
323 enum dt_index_flags {
324 /** index supports variable sized keys */
325 DT_IND_VARKEY = 1 << 0,
326 /** index supports variable sized records */
327 DT_IND_VARREC = 1 << 1,
328 /** index can be modified */
329 DT_IND_UPDATE = 1 << 2,
330 /** index supports records with non-unique (duplicate) keys */
331 DT_IND_NONUNQ = 1 << 3,
333 * index support fixed-size keys sorted with natural numerical way
334 * and is able to return left-side value if no exact value found
336 DT_IND_RANGE = 1 << 4,
340 * Features, required from index to support file system directories (mapping
343 extern const struct dt_index_features dt_directory_features;
344 extern const struct dt_index_features dt_otable_features;
345 extern const struct dt_index_features dt_lfsck_layout_orphan_features;
346 extern const struct dt_index_features dt_lfsck_layout_dangling_features;
347 extern const struct dt_index_features dt_lfsck_namespace_features;
349 /* index features supported by the accounting objects */
350 extern const struct dt_index_features dt_acct_features;
352 /* index features supported by the quota global indexes */
353 extern const struct dt_index_features dt_quota_glb_features;
355 /* index features supported by the quota slave indexes */
356 extern const struct dt_index_features dt_quota_slv_features;
358 /* index features supported by the nodemap index */
359 extern const struct dt_index_features dt_nodemap_features;
362 * This is a general purpose dt allocation hint.
363 * It now contains the parent object.
364 * It can contain any allocation hint in the future.
366 struct dt_allocation_hint {
367 struct dt_object *dah_parent;
368 const void *dah_eadata;
374 * object type specifier.
377 enum dt_format_type {
382 /** for special index */
384 /** for symbolic link */
389 * object format specifier.
391 struct dt_object_format {
392 /** type for dt object */
393 enum dt_format_type dof_type;
403 * special index need feature as parameter to create
407 const struct dt_index_features *di_feat;
412 enum dt_format_type dt_mode_to_dft(__u32 mode);
414 typedef __u64 dt_obj_version_t;
416 union ldlm_policy_data;
419 * A dt_object provides common operations to create and destroy
420 * objects and to manage regular and extended attributes.
422 struct dt_object_operations {
424 * Get read lock on object.
426 * Read lock is compatible with other read locks, so it's shared.
427 * Read lock is not compatible with write lock which is exclusive.
428 * The lock is blocking and can't be used from an interrupt context.
430 * \param[in] env execution environment for this thread
431 * \param[in] dt object to lock for reading
432 * \param[in] role a hint to debug locks (see kernel's mutexes)
434 void (*do_read_lock)(const struct lu_env *env,
435 struct dt_object *dt,
439 * Get write lock on object.
441 * Write lock is exclusive and cannot be shared. The lock is blocking
442 * and can't be used from an interrupt context.
444 * \param[in] env execution environment for this thread
445 * \param[in] dt object to lock for writing
446 * \param[in] role a hint to debug locks (see kernel's mutexes)
449 void (*do_write_lock)(const struct lu_env *env,
450 struct dt_object *dt,
456 * \param[in] env execution environment for this thread
457 * \param[in] dt object
459 void (*do_read_unlock)(const struct lu_env *env,
460 struct dt_object *dt);
463 * Release write lock.
465 * \param[in] env execution environment for this thread
466 * \param[in] dt object
468 void (*do_write_unlock)(const struct lu_env *env,
469 struct dt_object *dt);
472 * Check whether write lock is held.
474 * The caller can learn whether write lock is held on the object
476 * \param[in] env execution environment for this thread
477 * \param[in] dt object
479 * \retval 0 no write lock
480 * \retval 1 write lock is held
482 int (*do_write_locked)(const struct lu_env *env,
483 struct dt_object *dt);
486 * Declare intention to request reqular attributes.
488 * Notity the underlying filesystem that the caller may request regular
489 * attributes with ->do_attr_get() soon. This allows OSD to implement
490 * prefetching logic in an object-oriented manner. The implementation
491 * can be noop. This method should avoid expensive delays such as
492 * waiting on disk I/O, otherwise the goal of enabling a performance
493 * optimization would be defeated.
495 * \param[in] env execution environment for this thread
496 * \param[in] dt object
498 * \retval 0 on success
499 * \retval negative negated errno on error
501 int (*do_declare_attr_get)(const struct lu_env *env,
502 struct dt_object *dt);
505 * Return regular attributes.
507 * The object must exist. Currently all the attributes should be
508 * returned, but in the future this can be improved so that only
509 * a selected set is returned. This can improve performance as in
510 * some cases attributes are stored in different places and
511 * getting them all can be an iterative and expensive process.
513 * \param[in] env execution environment for this thread
514 * \param[in] dt object
515 * \param[out] attr attributes to fill
517 * \retval 0 on success
518 * \retval negative negated errno on error
520 int (*do_attr_get)(const struct lu_env *env,
521 struct dt_object *dt,
522 struct lu_attr *attr);
525 * Declare intention to change regular object's attributes.
527 * Notify the underlying filesystem that the regular attributes may
528 * change in this transaction. This enables the layer below to prepare
529 * resources (e.g. journal credits in ext4). This method should be
530 * called between creating the transaction and starting it. Note that
531 * the la_valid field of \a attr specifies which attributes will change.
532 * The object need not exist.
534 * \param[in] env execution environment for this thread
535 * \param[in] dt object
536 * \param[in] attr attributes to change specified in attr.la_valid
537 * \param[in] th transaction handle
539 * \retval 0 on success
540 * \retval negative negated errno on error
542 int (*do_declare_attr_set)(const struct lu_env *env,
543 struct dt_object *dt,
544 const struct lu_attr *attr,
548 * Change regular attributes.
550 * Change regular attributes in the given transaction. Note only
551 * attributes flagged by attr.la_valid change. The object must
552 * exist. If the layer implementing this method is responsible for
553 * quota, then the method should maintain object accounting for the
554 * given credentials when la_uid/la_gid changes.
556 * \param[in] env execution environment for this thread
557 * \param[in] dt object
558 * \param[in] attr new attributes to apply
559 * \param[in] th transaction handle
561 * \retval 0 on success
562 * \retval negative negated errno on error
564 int (*do_attr_set)(const struct lu_env *env,
565 struct dt_object *dt,
566 const struct lu_attr *attr,
570 * Declare intention to request extented attribute.
572 * Notify the underlying filesystem that the caller may request extended
573 * attribute with ->do_xattr_get() soon. This allows OSD to implement
574 * prefetching logic in an object-oriented manner. The implementation
575 * can be noop. This method should avoid expensive delays such as
576 * waiting on disk I/O, otherwise the goal of enabling a performance
577 * optimization would be defeated.
579 * \param[in] env execution environment for this thread
580 * \param[in] dt object
581 * \param[in] buf unused, may be removed in the future
582 * \param[in] name name of the extended attribute
584 * \retval 0 on success
585 * \retval negative negated errno on error
587 int (*do_declare_xattr_get)(const struct lu_env *env,
588 struct dt_object *dt,
593 * Return a value of an extended attribute.
595 * The object must exist. If the buffer is NULL, then the method
596 * must return the size of the value.
598 * \param[in] env execution environment for this thread
599 * \param[in] dt object
600 * \param[out] buf buffer in which to store the value
601 * \param[in] name name of the extended attribute
603 * \retval 0 on success
604 * \retval -ERANGE if \a buf is too small
605 * \retval negative negated errno on error
606 * \retval positive value's size if \a buf is NULL or has zero size
608 int (*do_xattr_get)(const struct lu_env *env,
609 struct dt_object *dt,
614 * Declare intention to change an extended attribute.
616 * Notify the underlying filesystem that the extended attribute may
617 * change in this transaction. This enables the layer below to prepare
618 * resources (e.g. journal credits in ext4). This method should be
619 * called between creating the transaction and starting it. The object
622 * \param[in] env execution environment for this thread
623 * \param[in] dt object
624 * \param[in] buf buffer storing new value of the attribute
625 * \param[in] name name of the attribute
626 * \param[in] fl LU_XATTR_CREATE - fail if EA exists
627 * LU_XATTR_REPLACE - fail if EA doesn't exist
628 * \param[in] th transaction handle
630 * \retval 0 on success
631 * \retval negative negated errno on error
633 int (*do_declare_xattr_set)(const struct lu_env *env,
634 struct dt_object *dt,
635 const struct lu_buf *buf,
641 * Set an extended attribute.
643 * Change or replace the specified extended attribute (EA).
644 * The flags passed in \a fl dictate whether the EA is to be
645 * created or replaced, as follows.
646 * LU_XATTR_CREATE - fail if EA exists
647 * LU_XATTR_REPLACE - fail if EA doesn't exist
648 * The object must exist.
650 * \param[in] env execution environment for this thread
651 * \param[in] dt object
652 * \param[in] buf buffer storing new value of the attribute
653 * \param[in] name name of the attribute
654 * \param[in] fl flags indicating EA creation or replacement
655 * \param[in] th transaction handle
657 * \retval 0 on success
658 * \retval negative negated errno on error
660 int (*do_xattr_set)(const struct lu_env *env,
661 struct dt_object *dt,
662 const struct lu_buf *buf,
668 * Declare intention to delete an extended attribute.
670 * Notify the underlying filesystem that the extended attribute may
671 * be deleted in this transaction. This enables the layer below to
672 * prepare resources (e.g. journal credits in ext4). This method
673 * should be called between creating the transaction and starting it.
674 * The object need not exist.
676 * \param[in] env execution environment for this thread
677 * \param[in] dt object
678 * \param[in] name name of the attribute
679 * \param[in] th transaction handle
681 * \retval 0 on success
682 * \retval negative negated errno on error
684 int (*do_declare_xattr_del)(const struct lu_env *env,
685 struct dt_object *dt,
690 * Delete an extended attribute.
692 * This method deletes the specified extended attribute. The object
695 * \param[in] env execution environment for this thread
696 * \param[in] dt object
697 * \param[in] name name of the attribute
698 * \param[in] th transaction handle
700 * \retval 0 on success
701 * \retval negative negated errno on error
703 int (*do_xattr_del)(const struct lu_env *env,
704 struct dt_object *dt,
709 * Return a list of the extended attributes.
711 * Fills the passed buffer with a list of the extended attributes
712 * found in the object. The names are separated with '\0'.
713 * The object must exist.
715 * \param[in] env execution environment for this thread
716 * \param[in] dt object
717 * \param[out] buf buffer to put the list in
719 * \retval positive bytes used/required in the buffer
720 * \retval negative negated errno on error
722 int (*do_xattr_list)(const struct lu_env *env,
723 struct dt_object *dt,
724 const struct lu_buf *buf);
727 * Prepare allocation hint for a new object.
729 * This method is used by the caller to inform OSD of the parent-child
730 * relationship between two objects and enable efficient object
731 * allocation. Filled allocation hint will be passed to ->do_create()
734 * \param[in] env execution environment for this thread
735 * \param[out] ah allocation hint
736 * \param[in] parent parent object (can be NULL)
737 * \param[in] child child object
738 * \param[in] _mode type of the child object
740 void (*do_ah_init)(const struct lu_env *env,
741 struct dt_allocation_hint *ah,
742 struct dt_object *parent,
743 struct dt_object *child,
747 * Declare intention to create a new object.
749 * Notify the underlying filesystem that the object may be created
750 * in this transaction. This enables the layer below to prepare
751 * resources (e.g. journal credits in ext4). This method should be
752 * called between creating the transaction and starting it.
754 * If the layer implementing this method is responsible for quota,
755 * then the method should reserve an object for the given credentials
756 * and return an error if quota is over. If object creation later
757 * fails for some reason, then the reservation should be released
758 * properly (usually in ->dt_trans_stop()).
760 * \param[in] env execution environment for this thread
761 * \param[in] dt object
762 * \param[in] attr attributes of the new object
763 * \param[in] hint allocation hint
764 * \param[in] dof object format
765 * \param[in] th transaction handle
767 * \retval 0 on success
768 * \retval negative negated errno on error
770 int (*do_declare_create)(const struct lu_env *env,
771 struct dt_object *dt,
772 struct lu_attr *attr,
773 struct dt_allocation_hint *hint,
774 struct dt_object_format *dof,
780 * The method creates the object passed with the specified attributes
781 * and object format. Object allocation procedure can use information
782 * stored in the allocation hint. Different object formats are supported
783 * (see enum dt_format_type and struct dt_object_format) depending on
784 * the device. If creation succeeds, then LOHA_EXISTS flag must be set
785 * in the LU-object header attributes.
787 * If the layer implementing this method is responsible for quota,
788 * then the method should maintain object accounting for the given
791 * \param[in] env execution environment for this thread
792 * \param[in] dt object
793 * \param[in] attr attributes of the new object
794 * \param[in] hint allocation hint
795 * \param[in] dof object format
796 * \param[in] th transaction handle
798 * \retval 0 on success
799 * \retval negative negated errno on error
801 int (*do_create)(const struct lu_env *env,
802 struct dt_object *dt,
803 struct lu_attr *attr,
804 struct dt_allocation_hint *hint,
805 struct dt_object_format *dof,
809 * Declare intention to destroy an object.
811 * Notify the underlying filesystem that the object may be destroyed
812 * in this transaction. This enables the layer below to prepare
813 * resources (e.g. journal credits in ext4). This method should be
814 * called between creating the transaction and starting it. The object
817 * \param[in] env execution environment for this thread
818 * \param[in] dt object
819 * \param[in] th transaction handle
821 * \retval 0 on success
822 * \retval negative negated errno on error
824 int (*do_declare_destroy)(const struct lu_env *env,
825 struct dt_object *dt,
831 * This method destroys the object and all the resources associated
832 * with the object (data, key/value pairs, extended attributes, etc).
833 * The object must exist. If destroy is successful, then flag
834 * LU_OBJECT_HEARD_BANSHEE should be set to forbid access to this
835 * instance of in-core object. Any subsequent access to the same FID
836 * should get another instance with no LOHA_EXIST flag set.
838 * If the layer implementing this method is responsible for quota,
839 * then the method should maintain object accounting for the given
842 * \param[in] env execution environment for this thread
843 * \param[in] dt object
844 * \param[in] th transaction handle
846 * \retval 0 on success
847 * \retval negative negated errno on error
849 int (*do_destroy)(const struct lu_env *env,
850 struct dt_object *dt,
854 * Try object as an index.
856 * Announce that this object is going to be used as an index. This
857 * operation checks that object supports indexing operations and
858 * installs appropriate dt_index_operations vector on success.
859 * Also probes for features. Operation is successful if all required
860 * features are supported. It's not possible to access the object
861 * with index methods before ->do_index_try() returns success.
863 * \param[in] env execution environment for this thread
864 * \param[in] dt object
865 * \param[in] feat index features
867 * \retval 0 on success
868 * \retval negative negated errno on error
870 int (*do_index_try)(const struct lu_env *env,
871 struct dt_object *dt,
872 const struct dt_index_features *feat);
875 * Declare intention to increment nlink count.
877 * Notify the underlying filesystem that the nlink regular attribute
878 * be changed in this transaction. This enables the layer below to
879 * prepare resources (e.g. journal credits in ext4). This method
880 * should be called between creating the transaction and starting it.
881 * The object need not exist.
883 * \param[in] env execution environment for this thread
884 * \param[in] dt object
885 * \param[in] th transaction handle
887 * \retval 0 on success
888 * \retval negative negated errno on error
890 int (*do_declare_ref_add)(const struct lu_env *env,
891 struct dt_object *dt,
897 * Increment nlink (from the regular attributes set) in the given
898 * transaction. Note the absolute limit for nlink should be learnt
899 * from struct dt_device_param::ddp_max_nlink. The object must exist.
901 * \param[in] env execution environment for this thread
902 * \param[in] dt object
903 * \param[in] th transaction handle
905 * \retval 0 on success
906 * \retval negative negated errno on error
908 int (*do_ref_add)(const struct lu_env *env,
909 struct dt_object *dt, struct thandle *th);
912 * Declare intention to decrement 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_del)(const struct lu_env *env,
928 struct dt_object *dt,
934 * Decrement nlink (from the regular attributes set) in the given
935 * transaction. The object must exist.
937 * \param[in] env execution environment for this thread
938 * \param[in] dt object
939 * \param[in] th transaction handle
941 * \retval 0 on success
942 * \retval negative negated errno on error
944 int (*do_ref_del)(const struct lu_env *env,
945 struct dt_object *dt,
951 * The method is called to sync specified range of the object to a
952 * persistent storage. The control is returned once the operation is
953 * complete. The difference from ->do_sync() is that the object can
954 * be in-sync with the persistent storage (nothing to flush), then
955 * the method returns quickly with no I/O overhead. So, this method
956 * should be preferred over ->do_sync() where possible. Also note that
957 * if the object isn't clean, then some disk filesystems will call
958 * ->do_sync() to maintain overall consistency, in which case it's
959 * still very expensive.
961 * \param[in] env execution environment for this thread
962 * \param[in] dt object
963 * \param[in] start start of the range to sync
964 * \param[in] end end of the range to sync
966 * \retval 0 on success
967 * \retval negative negated errno on error
969 int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
970 __u64 start, __u64 end);
975 * Lock object(s) using Distributed Lock Manager (LDLM).
977 * Get LDLM locks for the object. Currently used to lock "remote"
978 * objects in DNE configuration - a service running on MDTx needs
979 * to lock an object on MDTy.
981 * \param[in] env execution environment for this thread
982 * \param[in] dt object
983 * \param[out] lh lock handle, sometimes used, sometimes not
984 * \param[in] einfo ldlm callbacks, locking type and mode
985 * \param[out] einfo private data to be passed to unlock later
986 * \param[in] policy inodebits data
988 * \retval 0 on success
989 * \retval negative negated errno on error
991 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
992 struct lustre_handle *lh,
993 struct ldlm_enqueue_info *einfo,
994 union ldlm_policy_data *policy);
999 * Release LDLM lock(s) granted with ->do_object_lock().
1001 * \param[in] env execution environment for this thread
1002 * \param[in] dt object
1003 * \param[in] einfo lock handles, from ->do_object_lock()
1004 * \param[in] policy inodebits data
1006 * \retval 0 on success
1007 * \retval negative negated errno on error
1009 int (*do_object_unlock)(const struct lu_env *env,
1010 struct dt_object *dt,
1011 struct ldlm_enqueue_info *einfo,
1012 union ldlm_policy_data *policy);
1015 * Invalidate attribute cache.
1017 * This method invalidate attribute cache of the object, which is on OSP
1020 * \param[in] env execution envionment for this thread
1021 * \param[in] dt object
1023 * \retval 0 on success
1024 * \retval negative negated errno on error
1026 int (*do_invalidate)(const struct lu_env *env, struct dt_object *dt);
1029 * Declare intention to instaintiate extended layout component.
1031 * \param[in] env execution environment
1032 * \param[in] dt DT object
1033 * \param[in] layout data structure to describe the changes to
1034 * the DT object's layout
1035 * \param[in] buf buffer containing client's lovea or empty
1038 * \retval -ne error code
1040 int (*do_declare_layout_change)(const struct lu_env *env,
1041 struct dt_object *dt,
1042 struct layout_intent *layout,
1043 const struct lu_buf *buf,
1044 struct thandle *th);
1047 * Client is trying to write to un-instantiated layout component.
1049 * \param[in] env execution environment
1050 * \param[in] dt DT object
1051 * \param[in] layout data structure to describe the changes to
1052 * the DT object's layout
1053 * \param[in] buf buffer containing client's lovea or empty
1056 * \retval -ne error code
1058 int (*do_layout_change)(const struct lu_env *env, struct dt_object *dt,
1059 struct layout_intent *layout,
1060 const struct lu_buf *buf, struct thandle *th);
1064 * Per-dt-object operations on "file body" - unstructure raw data.
1066 struct dt_body_operations {
1070 * Read unstructured data from an existing regular object.
1071 * Only data before attr.la_size is returned.
1073 * \param[in] env execution environment for this thread
1074 * \param[in] dt object
1075 * \param[out] buf buffer (including size) to copy data in
1076 * \param[in] pos position in the object to start
1077 * \param[out] pos original value of \a pos + bytes returned
1079 * \retval positive bytes read on success
1080 * \retval negative negated errno on error
1082 ssize_t (*dbo_read)(const struct lu_env *env,
1083 struct dt_object *dt,
1088 * Declare intention to write data to object.
1090 * Notify the underlying filesystem that data may be written in
1091 * this transaction. This enables the layer below to prepare resources
1092 * (e.g. journal credits in ext4). This method should be called
1093 * between creating the transaction and starting it. The object need
1094 * not exist. If the layer implementing this method is responsible for
1095 * quota, then the method should reserve space for the given credentials
1096 * and return an error if quota is over. If the write later fails
1097 * for some reason, then the reserve should be released properly
1098 * (usually in ->dt_trans_stop()).
1100 * \param[in] env execution environment for this thread
1101 * \param[in] dt object
1102 * \param[in] buf buffer (including size) to copy data from
1103 * \param[in] pos position in the object to start
1104 * \param[in] th transaction handle
1106 * \retval 0 on success
1107 * \retval negative negated errno on error
1109 ssize_t (*dbo_declare_write)(const struct lu_env *env,
1110 struct dt_object *dt,
1111 const struct lu_buf *buf,
1113 struct thandle *th);
1116 * Write unstructured data to regular existing object.
1118 * The method allocates space and puts data in. Also, the method should
1119 * maintain attr.la_size properly. Partial writes are possible.
1121 * If the layer implementing this method is responsible for quota,
1122 * then the method should maintain space accounting for the given
1125 * \param[in] env execution environment for this thread
1126 * \param[in] dt object
1127 * \param[in] buf buffer (including size) to copy data from
1128 * \param[in] pos position in the object to start
1129 * \param[out] pos \a pos + bytes written
1130 * \param[in] th transaction handle
1131 * \param[in] ignore unused (was used to request quota ignorance)
1133 * \retval positive bytes written on success
1134 * \retval negative negated errno on error
1136 ssize_t (*dbo_write)(const struct lu_env *env,
1137 struct dt_object *dt,
1138 const struct lu_buf *buf,
1144 * Return buffers for data.
1146 * This method is used to access data with no copying. It's so-called
1147 * zero-copy I/O. The method returns the descriptors for the internal
1148 * buffers where data are managed by the disk filesystem. For example,
1149 * pagecache in case of ext4 or ARC with ZFS. Then other components
1150 * (e.g. networking) can transfer data from or to the buffers with no
1151 * additional copying.
1153 * The method should fill an array of struct niobuf_local, where
1154 * each element describes a full or partial page for data at specific
1155 * offset. The caller should use page/lnb_page_offset/len to find data
1156 * at object's offset lnb_file_offset.
1158 * The memory referenced by the descriptors can't change its purpose
1159 * until the complementary ->dbo_bufs_put() is called. The caller should
1160 * specify if the buffers are used to read or modify data so that OSD
1161 * can decide how to initialize the buffers: bring all the data for
1162 * reads or just bring partial buffers for write. Note: the method does
1163 * not check whether output array is large enough.
1165 * \param[in] env execution environment for this thread
1166 * \param[in] dt object
1167 * \param[in] pos position in the object to start
1168 * \param[in] len size of region in bytes
1169 * \param[out] lb array of descriptors to fill
1170 * \param[in] rw 0 if used to read, 1 if used for write
1172 * \retval positive number of descriptors on success
1173 * \retval negative negated errno on error
1175 int (*dbo_bufs_get)(const struct lu_env *env,
1176 struct dt_object *dt,
1179 struct niobuf_local *lb,
1183 * Release reference granted by ->dbo_bufs_get().
1185 * Release the reference granted by the previous ->dbo_bufs_get().
1186 * Note the references are counted.
1188 * \param[in] env execution environment for this thread
1189 * \param[in] dt object
1190 * \param[out] lb array of descriptors to fill
1191 * \param[in] nr size of the array
1193 * \retval 0 on success
1194 * \retval negative negated errno on error
1196 int (*dbo_bufs_put)(const struct lu_env *env,
1197 struct dt_object *dt,
1198 struct niobuf_local *lb,
1202 * Prepare buffers for reading.
1204 * The method is called on the given buffers to fill them with data
1205 * if that wasn't done in ->dbo_bufs_get(). The idea is that the
1206 * caller should be able to get few buffers for discontiguous regions
1207 * using few calls to ->dbo_bufs_get() and then request them all for
1208 * the preparation with a single call, so that OSD can fire many I/Os
1209 * to run concurrently. It's up to the specific OSD whether to implement
1210 * this logic in ->dbo_read_prep() or just use ->dbo_bufs_get() to
1211 * prepare data for every requested region individually.
1213 * \param[in] env execution environment for this thread
1214 * \param[in] dt object
1215 * \param[in] lnb array of buffer descriptors
1216 * \param[in] nr size of the array
1218 * \retval 0 on success
1219 * \retval negative negated errno on error
1221 int (*dbo_read_prep)(const struct lu_env *env,
1222 struct dt_object *dt,
1223 struct niobuf_local *lnb,
1227 * Prepare buffers for write.
1229 * This method is called on the given buffers to ensure the partial
1230 * buffers contain correct data. The underlying idea is the same as
1231 * in ->db_read_prep().
1233 * \param[in] env execution environment for this thread
1234 * \param[in] dt object
1235 * \param[in] lb array of buffer descriptors
1236 * \param[in] nr size of the array
1238 * \retval 0 on success
1239 * \retval negative negated errno on error
1241 int (*dbo_write_prep)(const struct lu_env *env,
1242 struct dt_object *dt,
1243 struct niobuf_local *lb,
1247 * Declare intention to write data stored in the buffers.
1249 * Notify the underlying filesystem that data may be written in
1250 * this transaction. This enables the layer below to prepare resources
1251 * (e.g. journal credits in ext4). This method should be called
1252 * between creating the transaction and starting it.
1254 * If the layer implementing this method is responsible for quota,
1255 * then the method should be reserving a space for the given
1256 * credentials and return an error if quota is exceeded. If the write
1257 * later fails for some reason, then the reserve should be released
1258 * properly (usually in ->dt_trans_stop()).
1260 * \param[in] env execution environment for this thread
1261 * \param[in] dt object
1262 * \param[in] lb array of descriptors
1263 * \param[in] nr size of the array
1264 * \param[in] th transaction handle
1266 * \retval 0 on success
1267 * \retval negative negated errno on error
1269 int (*dbo_declare_write_commit)(const struct lu_env *env,
1270 struct dt_object *dt,
1271 struct niobuf_local *lb,
1273 struct thandle *th);
1276 * Write to existing object.
1278 * This method is used to write data to a persistent storage using
1279 * the buffers returned by ->dbo_bufs_get(). The caller puts new
1280 * data into the buffers using own mechanisms (e.g. direct transfer
1281 * from a NIC). The method should maintain attr.la_size. Also,
1282 * attr.la_blocks should be maintained but this can be done in lazy
1283 * manner, when actual allocation happens.
1285 * If the layer implementing this method is responsible for quota,
1286 * then the method should maintain space accounting for the given
1289 * \param[in] env execution environment for this thread
1290 * \param[in] dt object
1291 * \param[in] lb array of descriptors for the buffers
1292 * \param[in] nr size of the array
1293 * \param[in] th transaction handle
1295 * \retval 0 on success
1296 * \retval negative negated errno on error
1298 int (*dbo_write_commit)(const struct lu_env *env,
1299 struct dt_object *dt,
1300 struct niobuf_local *lb,
1302 struct thandle *th);
1305 * Return logical to physical block mapping for a given extent
1307 * \param[in] env execution environment for this thread
1308 * \param[in] dt object
1309 * \param[in] fm describe the region to map and the output buffer
1310 * see the details in include/linux/fiemap.h
1312 * \retval 0 on success
1313 * \retval negative negated errno on error
1315 int (*dbo_fiemap_get)(const struct lu_env *env,
1316 struct dt_object *dt,
1320 * Declare intention to deallocate space from an object.
1322 * Notify the underlying filesystem that space may be deallocated in
1323 * this transactions. This enables the layer below to prepare resources
1324 * (e.g. journal credits in ext4). This method should be called between
1325 * creating the transaction and starting it. The object need not exist.
1327 * \param[in] env execution environment for this thread
1328 * \param[in] dt object
1329 * \param[in] start the start of the region to deallocate
1330 * \param[in] end the end of the region to deallocate
1331 * \param[in] th transaction handle
1333 * \retval 0 on success
1334 * \retval negative negated errno on error
1336 int (*dbo_declare_punch)(const struct lu_env *env,
1337 struct dt_object *dt,
1340 struct thandle *th);
1343 * Deallocate specified region in an object.
1345 * This method is used to deallocate (release) space possibly consumed
1346 * by the given region of the object. If the layer implementing this
1347 * method is responsible for quota, then the method should maintain
1348 * space accounting for the given credentials.
1350 * \param[in] env execution environment for this thread
1351 * \param[in] dt object
1352 * \param[in] start the start of the region to deallocate
1353 * \param[in] end the end of the region to deallocate
1354 * \param[in] th transaction handle
1356 * \retval 0 on success
1357 * \retval negative negated errno on error
1359 int (*dbo_punch)(const struct lu_env *env,
1360 struct dt_object *dt,
1363 struct thandle *th);
1365 * Give advices on specified region in an object.
1367 * This method is used to give advices about access pattern on an
1368 * given region of the object. The disk filesystem understands
1369 * the advices and tunes cache/read-ahead policies.
1371 * \param[in] env execution environment for this thread
1372 * \param[in] dt object
1373 * \param[in] start the start of the region affected
1374 * \param[in] end the end of the region affected
1375 * \param[in] advice advice type
1377 * \retval 0 on success
1378 * \retval negative negated errno on error
1380 int (*dbo_ladvise)(const struct lu_env *env,
1381 struct dt_object *dt,
1384 enum lu_ladvise_type advice);
1388 * Incomplete type of index record.
1393 * Incomplete type of index key.
1398 * Incomplete type of dt iterator.
1403 * Per-dt-object operations on object as index. Index is a set of key/value
1404 * pairs abstracted from an on-disk representation. An index supports the
1405 * number of operations including lookup by key, insert and delete. Also,
1406 * an index can be iterated to find the pairs one by one, from a beginning
1407 * or specified point.
1409 struct dt_index_operations {
1411 * Lookup in an index by key.
1413 * The method returns a value for the given key. Key/value format
1414 * and size should have been negotiated with ->do_index_try() before.
1415 * Thus it's the caller's responsibility to provide the method with
1416 * proper key and big enough buffer. No external locking is required,
1417 * all the internal consistency should be implemented by the method
1418 * or lower layers. The object should should have been created with
1419 * type DFT_INDEX or DFT_DIR.
1421 * \param[in] env execution environment for this thread
1422 * \param[in] dt object
1423 * \param[out] rec buffer where value will be stored
1424 * \param[in] key key
1426 * \retval 0 on success
1427 * \retval -ENOENT if key isn't found
1428 * \retval negative negated errno on error
1430 int (*dio_lookup)(const struct lu_env *env,
1431 struct dt_object *dt,
1433 const struct dt_key *key);
1436 * Declare intention to insert a key/value into an index.
1438 * Notify the underlying filesystem that new key/value may be inserted
1439 * in this transaction. This enables the layer below to prepare
1440 * resources (e.g. journal credits in ext4). This method should be
1441 * called between creating the transaction and starting it. key/value
1442 * format and size is subject to ->do_index_try().
1444 * \param[in] env execution environment for this thread
1445 * \param[in] dt object
1446 * \param[in] rec buffer storing value
1447 * \param[in] key key
1448 * \param[in] th transaction handle
1450 * \retval 0 on success
1451 * \retval negative negated errno on error
1453 int (*dio_declare_insert)(const struct lu_env *env,
1454 struct dt_object *dt,
1455 const struct dt_rec *rec,
1456 const struct dt_key *key,
1457 struct thandle *th);
1460 * Insert a new key/value pair into an index.
1462 * The method inserts specified key/value pair into the given index
1463 * object. The internal consistency is maintained by the method or
1464 * the functionality below. The format and size of key/value should
1465 * have been negotiated before using ->do_index_try(), no additional
1466 * information can be specified to the method. The keys are unique
1469 * \param[in] env execution environment for this thread
1470 * \param[in] dt object
1471 * \param[in] rec buffer storing value
1472 * \param[in] key key
1473 * \param[in] th transaction handle
1474 * \param[in] ignore unused (was used to request quota ignorance)
1476 * \retval 0 on success
1477 * \retval negative negated errno on error
1479 int (*dio_insert)(const struct lu_env *env,
1480 struct dt_object *dt,
1481 const struct dt_rec *rec,
1482 const struct dt_key *key,
1487 * Declare intention to delete a key/value from an index.
1489 * Notify the underlying filesystem that key/value may be deleted in
1490 * this transaction. This enables the layer below to prepare resources
1491 * (e.g. journal credits in ext4). This method should be called
1492 * between creating the transaction and starting it. Key/value format
1493 * and size is subject to ->do_index_try(). The object need not exist.
1495 * \param[in] env execution environment for this thread
1496 * \param[in] dt object
1497 * \param[in] key key
1498 * \param[in] th transaction handle
1500 * \retval 0 on success
1501 * \retval negative negated errno on error
1503 int (*dio_declare_delete)(const struct lu_env *env,
1504 struct dt_object *dt,
1505 const struct dt_key *key,
1506 struct thandle *th);
1509 * Delete key/value pair from an index.
1511 * The method deletes specified key and corresponding value from the
1512 * given index object. The internal consistency is maintained by the
1513 * method or the functionality below. The format and size of the key
1514 * should have been negotiated before using ->do_index_try(), no
1515 * additional information can be specified to the method.
1517 * \param[in] env execution environment for this thread
1518 * \param[in] dt object
1519 * \param[in] key key
1520 * \param[in] th transaction handle
1522 * \retval 0 on success
1523 * \retval negative negated errno on error
1525 int (*dio_delete)(const struct lu_env *env,
1526 struct dt_object *dt,
1527 const struct dt_key *key,
1528 struct thandle *th);
1531 * Iterator interface.
1533 * Methods to iterate over an existing index, list the keys stored and
1534 * associated values, get key/value size, etc.
1538 * Allocate and initialize new iterator.
1540 * The iterator is a handler to be used in the subsequent
1541 * methods to access index's content. Note the position is
1542 * not defined at this point and should be initialized with
1543 * ->get() or ->load() method.
1545 * \param[in] env execution environment for this thread
1546 * \param[in] dt object
1547 * \param[in] attr ask the iterator to return part of
1548 the records, see LUDA_* for details
1550 * \retval pointer iterator pointer on success
1551 * \retval ERR_PTR(errno) on error
1553 struct dt_it *(*init)(const struct lu_env *env,
1554 struct dt_object *dt,
1560 * Release the specified iterator and all the resources
1561 * associated (e.g. the object, index cache, etc).
1563 * \param[in] env execution environment for this thread
1564 * \param[in] di iterator to release
1566 void (*fini)(const struct lu_env *env,
1570 * Move position of iterator.
1572 * Move the position of the specified iterator to the specified
1575 * \param[in] env execution environment for this thread
1576 * \param[in] di iterator
1577 * \param[in] key key to position to
1579 * \retval 0 if exact key is found
1580 * \retval 1 if at the record with least key
1581 * not larger than the key
1582 * \retval negative negated errno on error
1584 int (*get)(const struct lu_env *env,
1586 const struct dt_key *key);
1591 * Complimentary method for dt_it_ops::get() above. Some
1592 * implementation can increase a reference on the iterator in
1593 * dt_it_ops::get(). So the caller should be able to release
1594 * with dt_it_ops::put().
1596 * \param[in] env execution environment for this thread
1597 * \param[in] di iterator
1599 void (*put)(const struct lu_env *env,
1603 * Move to next record.
1605 * Moves the position of the iterator to a next record
1607 * \param[in] env execution environment for this thread
1608 * \param[in] di iterator
1610 * \retval 1 if no more records
1611 * \retval 0 on success, the next record is found
1612 * \retval negative negated errno on error
1614 int (*next)(const struct lu_env *env,
1620 * Returns a pointer to a buffer containing the key of the
1621 * record at the current position. The pointer is valid and
1622 * retains data until ->get(), ->load() and ->fini() methods
1625 * \param[in] env execution environment for this thread
1626 * \param[in] di iterator
1628 * \retval pointer to key on success
1629 * \retval ERR_PTR(errno) on error
1631 struct dt_key *(*key)(const struct lu_env *env,
1632 const struct dt_it *di);
1637 * Returns size of the key at the current position.
1639 * \param[in] env execution environment for this thread
1640 * \param[in] di iterator
1642 * \retval key's size on success
1643 * \retval negative negated errno on error
1645 int (*key_size)(const struct lu_env *env,
1646 const struct dt_it *di);
1651 * Stores the value of the record at the current position. The
1652 * buffer must be big enough (as negotiated with
1653 * ->do_index_try() or ->rec_size()). The caller can specify
1654 * she is interested only in part of the record, using attr
1655 * argument (see LUDA_* definitions for the details).
1657 * \param[in] env execution environment for this thread
1658 * \param[in] di iterator
1659 * \param[out] rec buffer to store value in
1660 * \param[in] attr specify part of the value to copy
1662 * \retval 0 on success
1663 * \retval negative negated errno on error
1665 int (*rec)(const struct lu_env *env,
1666 const struct dt_it *di,
1671 * Return record size.
1673 * Returns size of the record at the current position. The
1674 * \a attr can be used to specify only the parts of the record
1675 * needed to be returned. (see LUDA_* definitions for the
1678 * \param[in] env execution environment for this thread
1679 * \param[in] di iterator
1680 * \param[in] attr part of the record to return
1682 * \retval record's size on success
1683 * \retval negative negated errno on error
1685 int (*rec_size)(const struct lu_env *env,
1686 const struct dt_it *di,
1690 * Return a cookie (hash).
1692 * Returns the cookie (usually hash) of the key at the current
1693 * position. This allows the caller to resume iteration at this
1694 * position later. The exact value is specific to implementation
1695 * and should not be interpreted by the caller.
1697 * \param[in] env execution environment for this thread
1698 * \param[in] di iterator
1700 * \retval cookie/hash of the key
1702 __u64 (*store)(const struct lu_env *env,
1703 const struct dt_it *di);
1706 * Initialize position using cookie/hash.
1708 * Initializes the current position of the iterator to one
1709 * described by the cookie/hash as returned by ->store()
1712 * \param[in] env execution environment for this thread
1713 * \param[in] di iterator
1714 * \param[in] hash cookie/hash value
1716 * \retval positive if current position points to
1717 * record with least cookie not larger
1719 * \retval 0 if current position matches cookie
1720 * \retval negative negated errno on error
1722 int (*load)(const struct lu_env *env,
1723 const struct dt_it *di,
1729 int (*key_rec)(const struct lu_env *env,
1730 const struct dt_it *di,
1735 enum dt_otable_it_valid {
1736 DOIV_ERROR_HANDLE = 0x0001,
1737 DOIV_DRYRUN = 0x0002,
1740 enum dt_otable_it_flags {
1741 /* Exit when fail. */
1742 DOIF_FAILOUT = 0x0001,
1744 /* Reset iteration position to the device beginning. */
1745 DOIF_RESET = 0x0002,
1747 /* There is up layer component uses the iteration. */
1748 DOIF_OUTUSED = 0x0004,
1750 /* Check only without repairing. */
1751 DOIF_DRYRUN = 0x0008,
1754 /* otable based iteration needs to use the common DT iteration APIs.
1755 * To initialize the iteration, it needs call dio_it::init() firstly.
1756 * Here is how the otable based iteration should prepare arguments to
1757 * call dt_it_ops::init().
1759 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
1760 * is composed of two parts:
1761 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
1762 #define DT_OTABLE_IT_FLAGS_SHIFT 16
1763 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
1766 struct lu_device dd_lu_dev;
1767 const struct dt_device_operations *dd_ops;
1770 * List of dt_txn_callback (see below). This is not protected in any
1771 * way, because callbacks are supposed to be added/deleted only during
1772 * single-threaded start-up shut-down procedures.
1774 struct list_head dd_txn_callbacks;
1775 unsigned int dd_record_fid_accessed:1,
1779 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
1780 void dt_device_fini(struct dt_device *dev);
1782 static inline int lu_device_is_dt(const struct lu_device *d)
1784 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
1787 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
1789 LASSERT(lu_device_is_dt(l));
1790 return container_of0(l, struct dt_device, dd_lu_dev);
1794 struct lu_object do_lu;
1795 const struct dt_object_operations *do_ops;
1796 const struct dt_body_operations *do_body_ops;
1797 const struct dt_index_operations *do_index_ops;
1801 * In-core representation of per-device local object OID storage
1803 struct local_oid_storage {
1804 /* all initialized llog systems on this node linked by this */
1805 struct list_head los_list;
1807 /* how many handle's reference this los has */
1808 atomic_t los_refcount;
1809 struct dt_device *los_dev;
1810 struct dt_object *los_obj;
1812 /* data used to generate new fids */
1813 struct mutex los_id_lock;
1818 static inline struct lu_device *dt2lu_dev(struct dt_device *d)
1820 return &d->dd_lu_dev;
1823 static inline struct dt_object *lu2dt(struct lu_object *l)
1825 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
1826 return container_of0(l, struct dt_object, do_lu);
1829 int dt_object_init(struct dt_object *obj,
1830 struct lu_object_header *h, struct lu_device *d);
1832 void dt_object_fini(struct dt_object *obj);
1834 static inline int dt_object_exists(const struct dt_object *dt)
1836 return lu_object_exists(&dt->do_lu);
1839 static inline int dt_object_remote(const struct dt_object *dt)
1841 return lu_object_remote(&dt->do_lu);
1844 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
1846 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
1847 return container_of0(o, struct dt_object, do_lu);
1850 static inline struct dt_object *dt_object_child(struct dt_object *o)
1852 return container_of0(lu_object_next(&(o)->do_lu),
1853 struct dt_object, do_lu);
1857 * This is the general purpose transaction handle.
1858 * 1. Transaction Life Cycle
1859 * This transaction handle is allocated upon starting a new transaction,
1860 * and deallocated after this transaction is committed.
1861 * 2. Transaction Nesting
1862 * We do _NOT_ support nested transaction. So, every thread should only
1863 * have one active transaction, and a transaction only belongs to one
1864 * thread. Due to this, transaction handle need no reference count.
1865 * 3. Transaction & dt_object locking
1866 * dt_object locks should be taken inside transaction.
1867 * 4. Transaction & RPC
1868 * No RPC request should be issued inside transaction.
1871 /** the dt device on which the transactions are executed */
1872 struct dt_device *th_dev;
1874 /* point to the top thandle, XXX this is a bit hacky right now,
1875 * but normal device trans callback triggered by the bottom
1876 * device (OSP/OSD == sub thandle layer) needs to get the
1877 * top_thandle (see dt_txn_hook_start/stop()), so we put the
1878 * top thandle here for now, will fix it when we have better
1879 * callback mechanism */
1880 struct thandle *th_top;
1881 /** context for this transaction, tag is LCT_TX_HANDLE */
1882 struct lu_context th_ctx;
1884 /** additional tags (layers can add in declare) */
1887 /** the last operation result in this transaction.
1888 * this value is used in recovery */
1891 /** whether we need sync commit */
1892 unsigned int th_sync:1,
1893 /* local transation, no need to inform other layers */
1895 /* Whether we need wait the transaction to be submitted
1896 * (send to remote target) */
1898 /* complex transaction which will track updates on all targets,
1904 * Transaction call-backs.
1906 * These are invoked by osd (or underlying transaction engine) when
1907 * transaction changes state.
1909 * Call-backs are used by upper layers to modify transaction parameters and to
1910 * perform some actions on for each transaction state transition. Typical
1911 * example is mdt registering call-back to write into last-received file
1912 * before each transaction commit.
1914 struct dt_txn_callback {
1915 int (*dtc_txn_start)(const struct lu_env *env,
1916 struct thandle *txn, void *cookie);
1917 int (*dtc_txn_stop)(const struct lu_env *env,
1918 struct thandle *txn, void *cookie);
1919 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
1922 struct list_head dtc_linkage;
1925 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
1926 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
1928 int dt_txn_hook_start(const struct lu_env *env,
1929 struct dt_device *dev, struct thandle *txn);
1930 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
1931 void dt_txn_hook_commit(struct thandle *txn);
1933 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
1936 * Callback function used for parsing path.
1937 * \see llo_store_resolve
1939 typedef int (*dt_entry_func_t)(const struct lu_env *env,
1943 #define DT_MAX_PATH 1024
1945 int dt_path_parser(const struct lu_env *env,
1946 char *local, dt_entry_func_t entry_func,
1950 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
1951 const char *path, struct lu_fid *fid);
1953 struct dt_object *dt_store_open(const struct lu_env *env,
1954 struct dt_device *dt,
1955 const char *dirname,
1956 const char *filename,
1957 struct lu_fid *fid);
1959 struct dt_object *dt_find_or_create(const struct lu_env *env,
1960 struct dt_device *dt,
1961 const struct lu_fid *fid,
1962 struct dt_object_format *dof,
1963 struct lu_attr *attr);
1965 struct dt_object *dt_locate_at(const struct lu_env *env,
1966 struct dt_device *dev,
1967 const struct lu_fid *fid,
1968 struct lu_device *top_dev,
1969 const struct lu_object_conf *conf);
1971 static inline struct dt_object *
1972 dt_locate(const struct lu_env *env, struct dt_device *dev,
1973 const struct lu_fid *fid)
1975 return dt_locate_at(env, dev, fid,
1976 dev->dd_lu_dev.ld_site->ls_top_dev, NULL);
1979 static inline struct dt_object *
1980 dt_object_locate(struct dt_object *dto, struct dt_device *dt_dev)
1982 struct lu_object *lo;
1984 list_for_each_entry(lo, &dto->do_lu.lo_header->loh_layers, lo_linkage) {
1985 if (lo->lo_dev == &dt_dev->dd_lu_dev)
1986 return container_of(lo, struct dt_object, do_lu);
1991 static inline void dt_object_put(const struct lu_env *env,
1992 struct dt_object *dto)
1994 lu_object_put(env, &dto->do_lu);
1997 static inline void dt_object_put_nocache(const struct lu_env *env,
1998 struct dt_object *dto)
2000 lu_object_put_nocache(env, &dto->do_lu);
2003 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
2004 const struct lu_fid *first_fid,
2005 struct local_oid_storage **los);
2006 void local_oid_storage_fini(const struct lu_env *env,
2007 struct local_oid_storage *los);
2008 int local_object_fid_generate(const struct lu_env *env,
2009 struct local_oid_storage *los,
2010 struct lu_fid *fid);
2011 int local_object_declare_create(const struct lu_env *env,
2012 struct local_oid_storage *los,
2013 struct dt_object *o,
2014 struct lu_attr *attr,
2015 struct dt_object_format *dof,
2016 struct thandle *th);
2017 int local_object_create(const struct lu_env *env,
2018 struct local_oid_storage *los,
2019 struct dt_object *o,
2020 struct lu_attr *attr, struct dt_object_format *dof,
2021 struct thandle *th);
2022 struct dt_object *local_file_find(const struct lu_env *env,
2023 struct local_oid_storage *los,
2024 struct dt_object *parent,
2026 struct dt_object *local_file_find_or_create(const struct lu_env *env,
2027 struct local_oid_storage *los,
2028 struct dt_object *parent,
2029 const char *name, __u32 mode);
2030 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
2031 struct dt_device *dt,
2032 const struct lu_fid *fid,
2033 struct dt_object *parent,
2037 local_index_find_or_create(const struct lu_env *env,
2038 struct local_oid_storage *los,
2039 struct dt_object *parent,
2040 const char *name, __u32 mode,
2041 const struct dt_index_features *ft);
2043 local_index_find_or_create_with_fid(const struct lu_env *env,
2044 struct dt_device *dt,
2045 const struct lu_fid *fid,
2046 struct dt_object *parent,
2047 const char *name, __u32 mode,
2048 const struct dt_index_features *ft);
2049 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
2050 struct dt_object *parent, const char *name);
2052 static inline int dt_object_lock(const struct lu_env *env,
2053 struct dt_object *o, struct lustre_handle *lh,
2054 struct ldlm_enqueue_info *einfo,
2055 union ldlm_policy_data *policy)
2058 LASSERT(o->do_ops != NULL);
2059 LASSERT(o->do_ops->do_object_lock != NULL);
2060 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
2063 static inline int dt_object_unlock(const struct lu_env *env,
2064 struct dt_object *o,
2065 struct ldlm_enqueue_info *einfo,
2066 union ldlm_policy_data *policy)
2069 LASSERT(o->do_ops != NULL);
2070 LASSERT(o->do_ops->do_object_unlock != NULL);
2071 return o->do_ops->do_object_unlock(env, o, einfo, policy);
2074 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
2075 const char *name, struct lu_fid *fid);
2077 static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
2078 __u64 start, __u64 end)
2082 LASSERT(o->do_ops->do_object_sync);
2083 return o->do_ops->do_object_sync(env, o, start, end);
2086 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
2087 struct thandle *th);
2088 void dt_version_set(const struct lu_env *env, struct dt_object *o,
2089 dt_obj_version_t version, struct thandle *th);
2090 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
2093 int dt_read(const struct lu_env *env, struct dt_object *dt,
2094 struct lu_buf *buf, loff_t *pos);
2095 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
2096 struct lu_buf *buf, loff_t *pos);
2097 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
2098 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
2099 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
2100 union lu_page *lp, size_t nob,
2101 const struct dt_it_ops *iops,
2102 struct dt_it *it, __u32 attr, void *arg);
2103 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
2104 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
2106 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
2107 struct idx_info *ii, const struct lu_rdpg *rdpg);
2109 static inline struct thandle *dt_trans_create(const struct lu_env *env,
2110 struct dt_device *d)
2112 LASSERT(d->dd_ops->dt_trans_create);
2113 return d->dd_ops->dt_trans_create(env, d);
2116 static inline int dt_trans_start(const struct lu_env *env,
2117 struct dt_device *d, struct thandle *th)
2119 LASSERT(d->dd_ops->dt_trans_start);
2120 return d->dd_ops->dt_trans_start(env, d, th);
2123 /* for this transaction hooks shouldn't be called */
2124 static inline int dt_trans_start_local(const struct lu_env *env,
2125 struct dt_device *d, struct thandle *th)
2127 LASSERT(d->dd_ops->dt_trans_start);
2129 return d->dd_ops->dt_trans_start(env, d, th);
2132 static inline int dt_trans_stop(const struct lu_env *env,
2133 struct dt_device *d, struct thandle *th)
2135 LASSERT(d->dd_ops->dt_trans_stop);
2136 return d->dd_ops->dt_trans_stop(env, d, th);
2139 static inline int dt_trans_cb_add(struct thandle *th,
2140 struct dt_txn_commit_cb *dcb)
2142 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
2143 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
2144 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
2149 static inline int dt_declare_record_write(const struct lu_env *env,
2150 struct dt_object *dt,
2151 const struct lu_buf *buf,
2157 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
2158 LASSERT(th != NULL);
2159 LASSERT(dt->do_body_ops);
2160 LASSERT(dt->do_body_ops->dbo_declare_write);
2161 rc = dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2165 static inline int dt_declare_create(const struct lu_env *env,
2166 struct dt_object *dt,
2167 struct lu_attr *attr,
2168 struct dt_allocation_hint *hint,
2169 struct dt_object_format *dof,
2173 LASSERT(dt->do_ops);
2174 LASSERT(dt->do_ops->do_declare_create);
2176 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_CREATE))
2177 return cfs_fail_err;
2179 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
2182 static inline int dt_create(const struct lu_env *env,
2183 struct dt_object *dt,
2184 struct lu_attr *attr,
2185 struct dt_allocation_hint *hint,
2186 struct dt_object_format *dof,
2190 LASSERT(dt->do_ops);
2191 LASSERT(dt->do_ops->do_create);
2193 if (CFS_FAULT_CHECK(OBD_FAIL_DT_CREATE))
2194 return cfs_fail_err;
2196 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
2199 static inline int dt_declare_destroy(const struct lu_env *env,
2200 struct dt_object *dt,
2204 LASSERT(dt->do_ops);
2205 LASSERT(dt->do_ops->do_declare_destroy);
2207 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DESTROY))
2208 return cfs_fail_err;
2210 return dt->do_ops->do_declare_destroy(env, dt, th);
2213 static inline int dt_destroy(const struct lu_env *env,
2214 struct dt_object *dt,
2218 LASSERT(dt->do_ops);
2219 LASSERT(dt->do_ops->do_destroy);
2221 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DESTROY))
2222 return cfs_fail_err;
2224 return dt->do_ops->do_destroy(env, dt, th);
2227 static inline void dt_read_lock(const struct lu_env *env,
2228 struct dt_object *dt,
2232 LASSERT(dt->do_ops);
2233 LASSERT(dt->do_ops->do_read_lock);
2234 dt->do_ops->do_read_lock(env, dt, role);
2237 static inline void dt_write_lock(const struct lu_env *env,
2238 struct dt_object *dt,
2242 LASSERT(dt->do_ops);
2243 LASSERT(dt->do_ops->do_write_lock);
2244 dt->do_ops->do_write_lock(env, dt, role);
2247 static inline void dt_read_unlock(const struct lu_env *env,
2248 struct dt_object *dt)
2251 LASSERT(dt->do_ops);
2252 LASSERT(dt->do_ops->do_read_unlock);
2253 dt->do_ops->do_read_unlock(env, dt);
2256 static inline void dt_write_unlock(const struct lu_env *env,
2257 struct dt_object *dt)
2260 LASSERT(dt->do_ops);
2261 LASSERT(dt->do_ops->do_write_unlock);
2262 dt->do_ops->do_write_unlock(env, dt);
2265 static inline int dt_write_locked(const struct lu_env *env,
2266 struct dt_object *dt)
2269 LASSERT(dt->do_ops);
2270 LASSERT(dt->do_ops->do_write_locked);
2271 return dt->do_ops->do_write_locked(env, dt);
2274 static inline int dt_declare_attr_get(const struct lu_env *env,
2275 struct dt_object *dt)
2278 LASSERT(dt->do_ops);
2279 LASSERT(dt->do_ops->do_declare_attr_get);
2281 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_GET))
2282 return cfs_fail_err;
2284 return dt->do_ops->do_declare_attr_get(env, dt);
2287 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
2291 LASSERT(dt->do_ops);
2292 LASSERT(dt->do_ops->do_attr_get);
2294 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_GET))
2295 return cfs_fail_err;
2297 return dt->do_ops->do_attr_get(env, dt, la);
2300 static inline int dt_declare_attr_set(const struct lu_env *env,
2301 struct dt_object *dt,
2302 const struct lu_attr *la,
2306 LASSERT(dt->do_ops);
2307 LASSERT(dt->do_ops->do_declare_attr_set);
2309 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_ATTR_SET))
2310 return cfs_fail_err;
2312 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
2315 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
2316 const struct lu_attr *la, struct thandle *th)
2319 LASSERT(dt->do_ops);
2320 LASSERT(dt->do_ops->do_attr_set);
2322 if (CFS_FAULT_CHECK(OBD_FAIL_DT_ATTR_SET))
2323 return cfs_fail_err;
2325 return dt->do_ops->do_attr_set(env, dt, la, th);
2328 static inline int dt_declare_ref_add(const struct lu_env *env,
2329 struct dt_object *dt, struct thandle *th)
2332 LASSERT(dt->do_ops);
2333 LASSERT(dt->do_ops->do_declare_ref_add);
2335 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_ADD))
2336 return cfs_fail_err;
2338 return dt->do_ops->do_declare_ref_add(env, dt, th);
2341 static inline int dt_ref_add(const struct lu_env *env,
2342 struct dt_object *dt, struct thandle *th)
2345 LASSERT(dt->do_ops);
2346 LASSERT(dt->do_ops->do_ref_add);
2348 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_ADD))
2349 return cfs_fail_err;
2351 return dt->do_ops->do_ref_add(env, dt, th);
2354 static inline int dt_declare_ref_del(const struct lu_env *env,
2355 struct dt_object *dt, struct thandle *th)
2358 LASSERT(dt->do_ops);
2359 LASSERT(dt->do_ops->do_declare_ref_del);
2361 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_REF_DEL))
2362 return cfs_fail_err;
2364 return dt->do_ops->do_declare_ref_del(env, dt, th);
2367 static inline int dt_ref_del(const struct lu_env *env,
2368 struct dt_object *dt, struct thandle *th)
2371 LASSERT(dt->do_ops);
2372 LASSERT(dt->do_ops->do_ref_del);
2374 if (CFS_FAULT_CHECK(OBD_FAIL_DT_REF_DEL))
2375 return cfs_fail_err;
2377 return dt->do_ops->do_ref_del(env, dt, th);
2380 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
2381 struct niobuf_remote *rnb,
2382 struct niobuf_local *lnb, int rw)
2385 LASSERT(d->do_body_ops);
2386 LASSERT(d->do_body_ops->dbo_bufs_get);
2387 return d->do_body_ops->dbo_bufs_get(env, d, rnb->rnb_offset,
2388 rnb->rnb_len, lnb, rw);
2391 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
2392 struct niobuf_local *lnb, int n)
2395 LASSERT(d->do_body_ops);
2396 LASSERT(d->do_body_ops->dbo_bufs_put);
2397 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
2400 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
2401 struct niobuf_local *lnb, int n)
2404 LASSERT(d->do_body_ops);
2405 LASSERT(d->do_body_ops->dbo_write_prep);
2406 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
2409 static inline int dt_declare_write_commit(const struct lu_env *env,
2410 struct dt_object *d,
2411 struct niobuf_local *lnb,
2412 int n, struct thandle *th)
2414 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
2415 LASSERT(th != NULL);
2416 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
2420 static inline int dt_write_commit(const struct lu_env *env,
2421 struct dt_object *d, struct niobuf_local *lnb,
2422 int n, struct thandle *th)
2425 LASSERT(d->do_body_ops);
2426 LASSERT(d->do_body_ops->dbo_write_commit);
2427 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
2430 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
2431 struct niobuf_local *lnb, int n)
2434 LASSERT(d->do_body_ops);
2435 LASSERT(d->do_body_ops->dbo_read_prep);
2436 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
2439 static inline int dt_declare_write(const struct lu_env *env,
2440 struct dt_object *dt,
2441 const struct lu_buf *buf, loff_t pos,
2445 LASSERT(dt->do_body_ops);
2446 LASSERT(dt->do_body_ops->dbo_declare_write);
2447 return dt->do_body_ops->dbo_declare_write(env, dt, buf, pos, th);
2450 static inline ssize_t dt_write(const struct lu_env *env, struct dt_object *dt,
2451 const struct lu_buf *buf, loff_t *pos,
2452 struct thandle *th, int rq)
2455 LASSERT(dt->do_body_ops);
2456 LASSERT(dt->do_body_ops->dbo_write);
2457 return dt->do_body_ops->dbo_write(env, dt, buf, pos, th, rq);
2460 static inline int dt_declare_punch(const struct lu_env *env,
2461 struct dt_object *dt, __u64 start,
2462 __u64 end, struct thandle *th)
2465 LASSERT(dt->do_body_ops);
2466 LASSERT(dt->do_body_ops->dbo_declare_punch);
2467 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
2470 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
2471 __u64 start, __u64 end, struct thandle *th)
2474 LASSERT(dt->do_body_ops);
2475 LASSERT(dt->do_body_ops->dbo_punch);
2476 return dt->do_body_ops->dbo_punch(env, dt, start, end, th);
2479 static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
2480 __u64 start, __u64 end, int advice)
2483 LASSERT(dt->do_body_ops);
2484 LASSERT(dt->do_body_ops->dbo_ladvise);
2485 return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
2488 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
2492 if (d->do_body_ops == NULL)
2494 if (d->do_body_ops->dbo_fiemap_get == NULL)
2496 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
2499 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
2500 struct obd_statfs *osfs)
2503 LASSERT(dev->dd_ops);
2504 LASSERT(dev->dd_ops->dt_statfs);
2505 return dev->dd_ops->dt_statfs(env, dev, osfs);
2508 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
2512 LASSERT(dev->dd_ops);
2513 LASSERT(dev->dd_ops->dt_root_get);
2514 return dev->dd_ops->dt_root_get(env, dev, f);
2517 static inline void dt_conf_get(const struct lu_env *env,
2518 const struct dt_device *dev,
2519 struct dt_device_param *param)
2522 LASSERT(dev->dd_ops);
2523 LASSERT(dev->dd_ops->dt_conf_get);
2524 return dev->dd_ops->dt_conf_get(env, dev, param);
2527 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
2530 LASSERT(dev->dd_ops);
2531 LASSERT(dev->dd_ops->dt_sync);
2532 return dev->dd_ops->dt_sync(env, dev);
2535 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
2538 LASSERT(dev->dd_ops);
2539 LASSERT(dev->dd_ops->dt_ro);
2540 return dev->dd_ops->dt_ro(env, dev);
2543 static inline int dt_declare_insert(const struct lu_env *env,
2544 struct dt_object *dt,
2545 const struct dt_rec *rec,
2546 const struct dt_key *key,
2550 LASSERT(dt->do_index_ops);
2551 LASSERT(dt->do_index_ops->dio_declare_insert);
2553 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_INSERT))
2554 return cfs_fail_err;
2556 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
2559 static inline int dt_insert(const struct lu_env *env,
2560 struct dt_object *dt,
2561 const struct dt_rec *rec,
2562 const struct dt_key *key,
2567 LASSERT(dt->do_index_ops);
2568 LASSERT(dt->do_index_ops->dio_insert);
2570 if (CFS_FAULT_CHECK(OBD_FAIL_DT_INSERT))
2571 return cfs_fail_err;
2573 return dt->do_index_ops->dio_insert(env, dt, rec, key, th, noquota);
2576 static inline int dt_declare_xattr_del(const struct lu_env *env,
2577 struct dt_object *dt,
2582 LASSERT(dt->do_ops);
2583 LASSERT(dt->do_ops->do_declare_xattr_del);
2585 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_DEL))
2586 return cfs_fail_err;
2588 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
2591 static inline int dt_xattr_del(const struct lu_env *env,
2592 struct dt_object *dt, const char *name,
2596 LASSERT(dt->do_ops);
2597 LASSERT(dt->do_ops->do_xattr_del);
2599 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_DEL))
2600 return cfs_fail_err;
2602 return dt->do_ops->do_xattr_del(env, dt, name, th);
2605 static inline int dt_declare_xattr_set(const struct lu_env *env,
2606 struct dt_object *dt,
2607 const struct lu_buf *buf,
2608 const char *name, int fl,
2612 LASSERT(dt->do_ops);
2613 LASSERT(dt->do_ops->do_declare_xattr_set);
2615 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_SET))
2616 return cfs_fail_err;
2618 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
2621 static inline int dt_xattr_set(const struct lu_env *env,
2622 struct dt_object *dt, const struct lu_buf *buf,
2623 const char *name, int fl, struct thandle *th)
2626 LASSERT(dt->do_ops);
2627 LASSERT(dt->do_ops->do_xattr_set);
2629 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_SET))
2630 return cfs_fail_err;
2632 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th);
2635 static inline int dt_declare_xattr_get(const struct lu_env *env,
2636 struct dt_object *dt,
2641 LASSERT(dt->do_ops);
2642 LASSERT(dt->do_ops->do_declare_xattr_get);
2644 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_XATTR_GET))
2645 return cfs_fail_err;
2647 return dt->do_ops->do_declare_xattr_get(env, dt, buf, name);
2650 static inline int dt_xattr_get(const struct lu_env *env,
2651 struct dt_object *dt, struct lu_buf *buf,
2655 LASSERT(dt->do_ops);
2656 LASSERT(dt->do_ops->do_xattr_get);
2658 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_GET))
2659 return cfs_fail_err;
2661 return dt->do_ops->do_xattr_get(env, dt, buf, name);
2664 static inline int dt_xattr_list(const struct lu_env *env, struct dt_object *dt,
2665 const struct lu_buf *buf)
2668 LASSERT(dt->do_ops);
2669 LASSERT(dt->do_ops->do_xattr_list);
2671 if (CFS_FAULT_CHECK(OBD_FAIL_DT_XATTR_LIST))
2672 return cfs_fail_err;
2674 return dt->do_ops->do_xattr_list(env, dt, buf);
2677 static inline int dt_invalidate(const struct lu_env *env, struct dt_object *dt)
2680 LASSERT(dt->do_ops);
2681 LASSERT(dt->do_ops->do_invalidate);
2683 return dt->do_ops->do_invalidate(env, dt);
2686 static inline int dt_declare_delete(const struct lu_env *env,
2687 struct dt_object *dt,
2688 const struct dt_key *key,
2692 LASSERT(dt->do_index_ops);
2693 LASSERT(dt->do_index_ops->dio_declare_delete);
2695 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DECLARE_DELETE))
2696 return cfs_fail_err;
2698 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
2701 static inline int dt_delete(const struct lu_env *env,
2702 struct dt_object *dt,
2703 const struct dt_key *key,
2707 LASSERT(dt->do_index_ops);
2708 LASSERT(dt->do_index_ops->dio_delete);
2710 if (CFS_FAULT_CHECK(OBD_FAIL_DT_DELETE))
2711 return cfs_fail_err;
2713 return dt->do_index_ops->dio_delete(env, dt, key, th);
2716 static inline int dt_commit_async(const struct lu_env *env,
2717 struct dt_device *dev)
2720 LASSERT(dev->dd_ops);
2721 LASSERT(dev->dd_ops->dt_commit_async);
2722 return dev->dd_ops->dt_commit_async(env, dev);
2725 static inline int dt_lookup(const struct lu_env *env,
2726 struct dt_object *dt,
2728 const struct dt_key *key)
2733 LASSERT(dt->do_index_ops);
2734 LASSERT(dt->do_index_ops->dio_lookup);
2736 if (CFS_FAULT_CHECK(OBD_FAIL_DT_LOOKUP))
2737 return cfs_fail_err;
2739 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key);
2747 static inline int dt_declare_layout_change(const struct lu_env *env,
2748 struct dt_object *o,
2749 struct layout_intent *layout,
2750 const struct lu_buf *buf,
2755 LASSERT(o->do_ops->do_declare_layout_change);
2756 return o->do_ops->do_declare_layout_change(env, o, layout, buf, th);
2759 static inline int dt_layout_change(const struct lu_env *env,
2760 struct dt_object *o,
2761 struct layout_intent *layout,
2762 const struct lu_buf *buf,
2767 LASSERT(o->do_ops->do_layout_change);
2768 return o->do_ops->do_layout_change(env, o, layout, buf, th);
2771 struct dt_find_hint {
2772 struct lu_fid *dfh_fid;
2773 struct dt_device *dfh_dt;
2774 struct dt_object *dfh_o;
2777 struct dt_insert_rec {
2779 const struct lu_fid *rec_fid;
2791 struct dt_thread_info {
2792 char dti_buf[DT_MAX_PATH];
2793 struct dt_find_hint dti_dfh;
2794 struct lu_attr dti_attr;
2795 struct lu_fid dti_fid;
2796 struct dt_object_format dti_dof;
2797 struct lustre_mdt_attrs dti_lma;
2798 struct lu_buf dti_lb;
2799 struct lu_object_conf dti_conf;
2801 struct dt_insert_rec dti_dt_rec;
2804 extern struct lu_context_key dt_key;
2806 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
2808 struct dt_thread_info *dti;
2810 dti = lu_context_key_get(&env->le_ctx, &dt_key);
2815 int dt_global_init(void);
2816 void dt_global_fini(void);
2818 # ifdef CONFIG_PROC_FS
2819 int lprocfs_dt_blksize_seq_show(struct seq_file *m, void *v);
2820 int lprocfs_dt_kbytestotal_seq_show(struct seq_file *m, void *v);
2821 int lprocfs_dt_kbytesfree_seq_show(struct seq_file *m, void *v);
2822 int lprocfs_dt_kbytesavail_seq_show(struct seq_file *m, void *v);
2823 int lprocfs_dt_filestotal_seq_show(struct seq_file *m, void *v);
2824 int lprocfs_dt_filesfree_seq_show(struct seq_file *m, void *v);
2825 # endif /* CONFIG_PROC_FS */
2827 #endif /* __LUSTRE_DT_OBJECT_H */