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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef __LUSTRE_DT_OBJECT_H
38 #define __LUSTRE_DT_OBJECT_H
41 * Sub-class of lu_object with methods common for "data" objects in OST stack.
43 * Data objects behave like regular files: you can read/write them, get and
44 * set their attributes. Implementation of dt interface is supposed to
45 * implement some form of garbage collection, normally reference counting
48 * Examples: osd (lustre/osd) is an implementation of dt interface.
54 * super-class definitions.
56 #include <lu_object.h>
58 #include <libcfs/libcfs.h>
61 struct proc_dir_entry;
67 struct dt_index_features;
72 MNTOPT_USERXATTR = 0x00000001,
73 MNTOPT_ACL = 0x00000002,
76 struct dt_device_param {
77 unsigned ddp_max_name_len;
78 unsigned ddp_max_nlink;
79 unsigned ddp_block_shift;
81 unsigned ddp_max_ea_size;
82 void *ddp_mnt; /* XXX: old code can retrieve mnt -bzzz */
84 unsigned long long ddp_maxbytes;
85 /* percentage of available space to reserve for grant error margin */
86 int ddp_grant_reserved;
87 /* per-inode space consumption */
89 /* per-fragment grant overhead to be used by client for grant
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 struct dt_txn_commit_cb {
108 cfs_list_t dcb_linkage;
111 char dcb_name[MAX_COMMIT_CB_STR_LEN];
115 * Operations on dt device.
117 struct dt_device_operations {
119 * Return device-wide statistics.
121 int (*dt_statfs)(const struct lu_env *env,
122 struct dt_device *dev, struct obd_statfs *osfs);
124 * Create transaction, described by \a param.
126 struct thandle *(*dt_trans_create)(const struct lu_env *env,
127 struct dt_device *dev);
129 * Start transaction, described by \a param.
131 int (*dt_trans_start)(const struct lu_env *env,
132 struct dt_device *dev, struct thandle *th);
134 * Finish previously started transaction.
136 int (*dt_trans_stop)(const struct lu_env *env,
139 * Add commit callback to the transaction.
141 int (*dt_trans_cb_add)(struct thandle *th,
142 struct dt_txn_commit_cb *dcb);
144 * Return fid of root index object.
146 int (*dt_root_get)(const struct lu_env *env,
147 struct dt_device *dev, struct lu_fid *f);
149 * Return device configuration data.
151 void (*dt_conf_get)(const struct lu_env *env,
152 const struct dt_device *dev,
153 struct dt_device_param *param);
155 * handling device state, mostly for tests
157 int (*dt_sync)(const struct lu_env *env, struct dt_device *dev);
158 int (*dt_ro)(const struct lu_env *env, struct dt_device *dev);
160 * Start a transaction commit asynchronously
162 * \param env environment
163 * \param dev dt_device to start commit on
165 * \return 0 success, negative value if error
167 int (*dt_commit_async)(const struct lu_env *env,
168 struct dt_device *dev);
170 * Initialize capability context.
172 int (*dt_init_capa_ctxt)(const struct lu_env *env,
173 struct dt_device *dev,
174 int mode, unsigned long timeout,
175 __u32 alg, struct lustre_capa_key *keys);
178 struct dt_index_features {
179 /** required feature flags from enum dt_index_flags */
181 /** minimal required key size */
182 size_t dif_keysize_min;
183 /** maximal required key size, 0 if no limit */
184 size_t dif_keysize_max;
185 /** minimal required record size */
186 size_t dif_recsize_min;
187 /** maximal required record size, 0 if no limit */
188 size_t dif_recsize_max;
189 /** pointer size for record */
193 enum dt_index_flags {
194 /** index supports variable sized keys */
195 DT_IND_VARKEY = 1 << 0,
196 /** index supports variable sized records */
197 DT_IND_VARREC = 1 << 1,
198 /** index can be modified */
199 DT_IND_UPDATE = 1 << 2,
200 /** index supports records with non-unique (duplicate) keys */
201 DT_IND_NONUNQ = 1 << 3,
203 * index support fixed-size keys sorted with natural numerical way
204 * and is able to return left-side value if no exact value found
206 DT_IND_RANGE = 1 << 4,
210 * Features, required from index to support file system directories (mapping
213 extern const struct dt_index_features dt_directory_features;
214 extern const struct dt_index_features dt_otable_features;
216 /* index features supported by the accounting objects */
217 extern const struct dt_index_features dt_acct_features;
219 /* index features supported by the quota global indexes */
220 extern const struct dt_index_features dt_quota_glb_features;
222 /* index features supported by the quota slave indexes */
223 extern const struct dt_index_features dt_quota_slv_features;
226 * This is a general purpose dt allocation hint.
227 * It now contains the parent object.
228 * It can contain any allocation hint in the future.
230 struct dt_allocation_hint {
231 struct dt_object *dah_parent;
236 * object type specifier.
239 enum dt_format_type {
244 /** for special index */
246 /** for symbolic link */
251 * object format specifier.
253 struct dt_object_format {
254 /** type for dt object */
255 enum dt_format_type dof_type;
265 * special index need feature as parameter to create
269 const struct dt_index_features *di_feat;
274 enum dt_format_type dt_mode_to_dft(__u32 mode);
276 typedef __u64 dt_obj_version_t;
279 * Per-dt-object operations.
281 struct dt_object_operations {
282 void (*do_read_lock)(const struct lu_env *env,
283 struct dt_object *dt, unsigned role);
284 void (*do_write_lock)(const struct lu_env *env,
285 struct dt_object *dt, unsigned role);
286 void (*do_read_unlock)(const struct lu_env *env,
287 struct dt_object *dt);
288 void (*do_write_unlock)(const struct lu_env *env,
289 struct dt_object *dt);
290 int (*do_write_locked)(const struct lu_env *env,
291 struct dt_object *dt);
293 * Note: following ->do_{x,}attr_{set,get}() operations are very
294 * similar to ->moo_{x,}attr_{set,get}() operations in struct
295 * md_object_operations (see md_object.h). These operations are not in
296 * lu_object_operations, because ->do_{x,}attr_set() versions take
297 * transaction handle as an argument (this transaction is started by
298 * caller). We might factor ->do_{x,}attr_get() into
299 * lu_object_operations, but that would break existing symmetry.
303 * Return standard attributes.
305 * precondition: lu_object_exists(&dt->do_lu);
307 int (*do_attr_get)(const struct lu_env *env,
308 struct dt_object *dt, struct lu_attr *attr,
309 struct lustre_capa *capa);
311 * Set standard attributes.
313 * precondition: dt_object_exists(dt);
315 int (*do_declare_attr_set)(const struct lu_env *env,
316 struct dt_object *dt,
317 const struct lu_attr *attr,
318 struct thandle *handle);
319 int (*do_attr_set)(const struct lu_env *env,
320 struct dt_object *dt,
321 const struct lu_attr *attr,
322 struct thandle *handle,
323 struct lustre_capa *capa);
325 * Return a value of an extended attribute.
327 * precondition: dt_object_exists(dt);
329 int (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
330 struct lu_buf *buf, const char *name,
331 struct lustre_capa *capa);
333 * Set value of an extended attribute.
335 * \a fl - flags from enum lu_xattr_flags
337 * precondition: dt_object_exists(dt);
339 int (*do_declare_xattr_set)(const struct lu_env *env,
340 struct dt_object *dt,
341 const struct lu_buf *buf,
342 const char *name, int fl,
343 struct thandle *handle);
344 int (*do_xattr_set)(const struct lu_env *env,
345 struct dt_object *dt, const struct lu_buf *buf,
346 const char *name, int fl, struct thandle *handle,
347 struct lustre_capa *capa);
349 * Delete existing extended attribute.
351 * precondition: dt_object_exists(dt);
353 int (*do_declare_xattr_del)(const struct lu_env *env,
354 struct dt_object *dt,
355 const char *name, struct thandle *handle);
356 int (*do_xattr_del)(const struct lu_env *env,
357 struct dt_object *dt,
358 const char *name, struct thandle *handle,
359 struct lustre_capa *capa);
361 * Place list of existing extended attributes into \a buf (which has
364 * precondition: dt_object_exists(dt);
366 int (*do_xattr_list)(const struct lu_env *env,
367 struct dt_object *dt, struct lu_buf *buf,
368 struct lustre_capa *capa);
370 * Init allocation hint using parent object and child mode.
371 * (1) The \a parent might be NULL if this is a partial creation for
373 * (2) The type of child is in \a child_mode.
374 * (3) The result hint is stored in \a ah;
376 void (*do_ah_init)(const struct lu_env *env,
377 struct dt_allocation_hint *ah,
378 struct dt_object *parent,
379 struct dt_object *child,
380 cfs_umode_t child_mode);
382 * Create new object on this device.
384 * precondition: !dt_object_exists(dt);
385 * postcondition: ergo(result == 0, dt_object_exists(dt));
387 int (*do_declare_create)(const struct lu_env *env,
388 struct dt_object *dt,
389 struct lu_attr *attr,
390 struct dt_allocation_hint *hint,
391 struct dt_object_format *dof,
393 int (*do_create)(const struct lu_env *env, struct dt_object *dt,
394 struct lu_attr *attr,
395 struct dt_allocation_hint *hint,
396 struct dt_object_format *dof,
400 Destroy object on this device
401 * precondition: !dt_object_exists(dt);
402 * postcondition: ergo(result == 0, dt_object_exists(dt));
404 int (*do_declare_destroy)(const struct lu_env *env,
405 struct dt_object *dt,
407 int (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
411 * Announce that this object is going to be used as an index. This
412 * operation check that object supports indexing operations and
413 * installs appropriate dt_index_operations vector on success.
415 * Also probes for features. Operation is successful if all required
416 * features are supported.
418 int (*do_index_try)(const struct lu_env *env,
419 struct dt_object *dt,
420 const struct dt_index_features *feat);
422 * Add nlink of the object
423 * precondition: dt_object_exists(dt);
425 int (*do_declare_ref_add)(const struct lu_env *env,
426 struct dt_object *dt, struct thandle *th);
427 int (*do_ref_add)(const struct lu_env *env,
428 struct dt_object *dt, struct thandle *th);
430 * Del nlink of the object
431 * precondition: dt_object_exists(dt);
433 int (*do_declare_ref_del)(const struct lu_env *env,
434 struct dt_object *dt, struct thandle *th);
435 int (*do_ref_del)(const struct lu_env *env,
436 struct dt_object *dt, struct thandle *th);
438 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
439 struct dt_object *dt,
440 struct lustre_capa *old,
442 int (*do_object_sync)(const struct lu_env *, struct dt_object *);
444 * Get object info of next level. Currently, only get inode from osd.
445 * This is only used by quota b=16542
446 * precondition: dt_object_exists(dt);
448 int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
453 * Per-dt-object operations on "file body".
455 struct dt_body_operations {
457 * precondition: dt_object_exists(dt);
459 ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
460 struct lu_buf *buf, loff_t *pos,
461 struct lustre_capa *capa);
463 * precondition: dt_object_exists(dt);
465 ssize_t (*dbo_declare_write)(const struct lu_env *env,
466 struct dt_object *dt,
467 const loff_t size, loff_t pos,
468 struct thandle *handle);
469 ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
470 const struct lu_buf *buf, loff_t *pos,
471 struct thandle *handle, struct lustre_capa *capa,
474 * methods for zero-copy IO
478 * precondition: dt_object_exists(dt);
482 * > 0 - number of local buffers prepared
484 int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
485 loff_t pos, ssize_t len, struct niobuf_local *lb,
486 int rw, struct lustre_capa *capa);
488 * precondition: dt_object_exists(dt);
490 int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
491 struct niobuf_local *lb, int nr);
493 * precondition: dt_object_exists(dt);
495 int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
496 struct niobuf_local *lb, int nr);
498 * precondition: dt_object_exists(dt);
500 int (*dbo_declare_write_commit)(const struct lu_env *env,
501 struct dt_object *dt,
502 struct niobuf_local *,
503 int, struct thandle *);
505 * precondition: dt_object_exists(dt);
507 int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
508 struct niobuf_local *, int, struct thandle *);
510 * precondition: dt_object_exists(dt);
512 int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
513 struct niobuf_local *lnb, int nr);
514 int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
515 struct ll_user_fiemap *fm);
517 * Punch object's content
518 * precondition: regular object, not index
520 int (*do_declare_punch)(const struct lu_env *, struct dt_object *,
521 __u64, __u64, struct thandle *th);
522 int (*do_punch)(const struct lu_env *env, struct dt_object *dt,
523 __u64 start, __u64 end, struct thandle *th,
524 struct lustre_capa *capa);
528 * Incomplete type of index record.
533 * Incomplete type of index key.
538 * Incomplete type of dt iterator.
543 * Per-dt-object operations on object as index.
545 struct dt_index_operations {
547 * precondition: dt_object_exists(dt);
549 int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
550 struct dt_rec *rec, const struct dt_key *key,
551 struct lustre_capa *capa);
553 * precondition: dt_object_exists(dt);
555 int (*dio_declare_insert)(const struct lu_env *env,
556 struct dt_object *dt,
557 const struct dt_rec *rec,
558 const struct dt_key *key,
559 struct thandle *handle);
560 int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
561 const struct dt_rec *rec, const struct dt_key *key,
562 struct thandle *handle, struct lustre_capa *capa,
565 * precondition: dt_object_exists(dt);
567 int (*dio_declare_delete)(const struct lu_env *env,
568 struct dt_object *dt,
569 const struct dt_key *key,
570 struct thandle *handle);
571 int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
572 const struct dt_key *key, struct thandle *handle,
573 struct lustre_capa *capa);
579 * Allocate and initialize new iterator.
581 * precondition: dt_object_exists(dt);
583 struct dt_it *(*init)(const struct lu_env *env,
584 struct dt_object *dt,
586 struct lustre_capa *capa);
587 void (*fini)(const struct lu_env *env,
589 int (*get)(const struct lu_env *env,
591 const struct dt_key *key);
592 void (*put)(const struct lu_env *env,
594 int (*next)(const struct lu_env *env,
596 struct dt_key *(*key)(const struct lu_env *env,
597 const struct dt_it *di);
598 int (*key_size)(const struct lu_env *env,
599 const struct dt_it *di);
600 int (*rec)(const struct lu_env *env,
601 const struct dt_it *di,
604 __u64 (*store)(const struct lu_env *env,
605 const struct dt_it *di);
606 int (*load)(const struct lu_env *env,
607 const struct dt_it *di, __u64 hash);
608 int (*key_rec)(const struct lu_env *env,
609 const struct dt_it *di, void* key_rec);
613 enum dt_otable_it_valid {
614 DOIV_ERROR_HANDLE = 0x0001,
617 enum dt_otable_it_flags {
618 /* Exit when fail. */
619 DOIF_FAILOUT = 0x0001,
621 /* Reset iteration position to the device beginning. */
624 /* There is up layer component uses the iteration. */
625 DOIF_OUTUSED = 0x0004,
628 /* otable based iteration needs to use the common DT interation APIs.
629 * To initialize the iteration, it needs call dio_it::init() firstly.
630 * Here is how the otable based iteration should prepare arguments to
631 * call dt_it_ops::init().
633 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
634 * is composed of two parts:
635 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
636 #define DT_OTABLE_IT_FLAGS_SHIFT 16
637 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
640 struct lu_device dd_lu_dev;
641 const struct dt_device_operations *dd_ops;
644 * List of dt_txn_callback (see below). This is not protected in any
645 * way, because callbacks are supposed to be added/deleted only during
646 * single-threaded start-up shut-down procedures.
648 cfs_list_t dd_txn_callbacks;
651 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
652 void dt_device_fini(struct dt_device *dev);
654 static inline int lu_device_is_dt(const struct lu_device *d)
656 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
659 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
661 LASSERT(lu_device_is_dt(l));
662 return container_of0(l, struct dt_device, dd_lu_dev);
666 struct lu_object do_lu;
667 const struct dt_object_operations *do_ops;
668 const struct dt_body_operations *do_body_ops;
669 const struct dt_index_operations *do_index_ops;
673 * In-core representation of per-device local object OID storage
675 struct local_oid_storage {
676 /* all initialized llog systems on this node linked by this */
679 /* how many handle's reference this los has */
680 cfs_atomic_t los_refcount;
681 struct dt_device *los_dev;
682 struct dt_object *los_obj;
684 /* data used to generate new fids */
685 struct mutex los_id_lock;
690 static inline struct dt_object *lu2dt(struct lu_object *l)
692 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
693 return container_of0(l, struct dt_object, do_lu);
696 int dt_object_init(struct dt_object *obj,
697 struct lu_object_header *h, struct lu_device *d);
699 void dt_object_fini(struct dt_object *obj);
701 static inline int dt_object_exists(const struct dt_object *dt)
703 return lu_object_exists(&dt->do_lu);
706 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
708 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
709 return container_of0(o, struct dt_object, do_lu);
713 * This is the general purpose transaction handle.
714 * 1. Transaction Life Cycle
715 * This transaction handle is allocated upon starting a new transaction,
716 * and deallocated after this transaction is committed.
717 * 2. Transaction Nesting
718 * We do _NOT_ support nested transaction. So, every thread should only
719 * have one active transaction, and a transaction only belongs to one
720 * thread. Due to this, transaction handle need no reference count.
721 * 3. Transaction & dt_object locking
722 * dt_object locks should be taken inside transaction.
723 * 4. Transaction & RPC
724 * No RPC request should be issued inside transaction.
727 /** the dt device on which the transactions are executed */
728 struct dt_device *th_dev;
730 /** context for this transaction, tag is LCT_TX_HANDLE */
731 struct lu_context th_ctx;
733 /** additional tags (layers can add in declare) */
736 /** the last operation result in this transaction.
737 * this value is used in recovery */
740 /** whether we need sync commit */
743 /* local transation, no need to inform other layers */
746 /* In DNE, one transaction can be disassemblied into
747 * updates on several different MDTs, and these updates
748 * will be attached to th_remote_update_list per target.
749 * Only single thread will access the list, no need lock
751 cfs_list_t th_remote_update_list;
752 struct update_request *th_current_request;
756 * Transaction call-backs.
758 * These are invoked by osd (or underlying transaction engine) when
759 * transaction changes state.
761 * Call-backs are used by upper layers to modify transaction parameters and to
762 * perform some actions on for each transaction state transition. Typical
763 * example is mdt registering call-back to write into last-received file
764 * before each transaction commit.
766 struct dt_txn_callback {
767 int (*dtc_txn_start)(const struct lu_env *env,
768 struct thandle *txn, void *cookie);
769 int (*dtc_txn_stop)(const struct lu_env *env,
770 struct thandle *txn, void *cookie);
771 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
774 cfs_list_t dtc_linkage;
777 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
778 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
780 int dt_txn_hook_start(const struct lu_env *env,
781 struct dt_device *dev, struct thandle *txn);
782 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
783 void dt_txn_hook_commit(struct thandle *txn);
785 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
788 * Callback function used for parsing path.
789 * \see llo_store_resolve
791 typedef int (*dt_entry_func_t)(const struct lu_env *env,
795 #define DT_MAX_PATH 1024
797 int dt_path_parser(const struct lu_env *env,
798 char *local, dt_entry_func_t entry_func,
801 struct dt_object *dt_store_open(const struct lu_env *env,
802 struct dt_device *dt,
804 const char *filename,
807 struct dt_object *dt_find_or_create(const struct lu_env *env,
808 struct dt_device *dt,
809 const struct lu_fid *fid,
810 struct dt_object_format *dof,
811 struct lu_attr *attr);
813 struct dt_object *dt_locate_at(const struct lu_env *env,
814 struct dt_device *dev,
815 const struct lu_fid *fid,
816 struct lu_device *top_dev);
817 static inline struct dt_object *
818 dt_locate(const struct lu_env *env, struct dt_device *dev,
819 const struct lu_fid *fid)
821 return dt_locate_at(env, dev, fid, dev->dd_lu_dev.ld_site->ls_top_dev);
825 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
826 const struct lu_fid *first_fid,
827 struct local_oid_storage **los);
828 void local_oid_storage_fini(const struct lu_env *env,
829 struct local_oid_storage *los);
830 int local_object_fid_generate(const struct lu_env *env,
831 struct local_oid_storage *los,
833 int local_object_declare_create(const struct lu_env *env,
834 struct local_oid_storage *los,
836 struct lu_attr *attr,
837 struct dt_object_format *dof,
839 int local_object_create(const struct lu_env *env,
840 struct local_oid_storage *los,
842 struct lu_attr *attr, struct dt_object_format *dof,
844 struct dt_object *local_file_find_or_create(const struct lu_env *env,
845 struct local_oid_storage *los,
846 struct dt_object *parent,
847 const char *name, __u32 mode);
848 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
849 struct dt_device *dt,
850 const struct lu_fid *fid,
851 struct dt_object *parent,
855 local_index_find_or_create(const struct lu_env *env,
856 struct local_oid_storage *los,
857 struct dt_object *parent,
858 const char *name, __u32 mode,
859 const struct dt_index_features *ft);
861 local_index_find_or_create_with_fid(const struct lu_env *env,
862 struct dt_device *dt,
863 const struct lu_fid *fid,
864 struct dt_object *parent,
865 const char *name, __u32 mode,
866 const struct dt_index_features *ft);
868 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
869 const char *name, struct lu_fid *fid);
871 static inline int dt_object_sync(const struct lu_env *env,
876 LASSERT(o->do_ops->do_object_sync);
877 return o->do_ops->do_object_sync(env, o);
880 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
882 void dt_version_set(const struct lu_env *env, struct dt_object *o,
883 dt_obj_version_t version, struct thandle *th);
884 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
887 int dt_read(const struct lu_env *env, struct dt_object *dt,
888 struct lu_buf *buf, loff_t *pos);
889 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
890 struct lu_buf *buf, loff_t *pos);
891 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
892 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
893 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
894 union lu_page *lp, int nob,
895 const struct dt_it_ops *iops,
896 struct dt_it *it, __u32 attr, void *arg);
897 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
898 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
900 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
901 struct idx_info *ii, const struct lu_rdpg *rdpg);
903 static inline struct thandle *dt_trans_create(const struct lu_env *env,
906 LASSERT(d->dd_ops->dt_trans_create);
907 return d->dd_ops->dt_trans_create(env, d);
910 static inline int dt_trans_start(const struct lu_env *env,
911 struct dt_device *d, struct thandle *th)
913 LASSERT(d->dd_ops->dt_trans_start);
914 return d->dd_ops->dt_trans_start(env, d, th);
917 /* for this transaction hooks shouldn't be called */
918 static inline int dt_trans_start_local(const struct lu_env *env,
919 struct dt_device *d, struct thandle *th)
921 LASSERT(d->dd_ops->dt_trans_start);
923 return d->dd_ops->dt_trans_start(env, d, th);
926 static inline int dt_trans_stop(const struct lu_env *env,
927 struct dt_device *d, struct thandle *th)
929 LASSERT(d->dd_ops->dt_trans_stop);
930 return d->dd_ops->dt_trans_stop(env, th);
933 static inline int dt_trans_cb_add(struct thandle *th,
934 struct dt_txn_commit_cb *dcb)
936 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
937 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
938 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
943 static inline int dt_declare_record_write(const struct lu_env *env,
944 struct dt_object *dt,
945 int size, loff_t pos,
950 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
952 LASSERT(dt->do_body_ops);
953 LASSERT(dt->do_body_ops->dbo_declare_write);
954 rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
958 static inline int dt_declare_create(const struct lu_env *env,
959 struct dt_object *dt,
960 struct lu_attr *attr,
961 struct dt_allocation_hint *hint,
962 struct dt_object_format *dof,
967 LASSERT(dt->do_ops->do_declare_create);
968 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
971 static inline int dt_create(const struct lu_env *env,
972 struct dt_object *dt,
973 struct lu_attr *attr,
974 struct dt_allocation_hint *hint,
975 struct dt_object_format *dof,
980 LASSERT(dt->do_ops->do_create);
981 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
984 static inline int dt_declare_destroy(const struct lu_env *env,
985 struct dt_object *dt,
990 LASSERT(dt->do_ops->do_declare_destroy);
991 return dt->do_ops->do_declare_destroy(env, dt, th);
994 static inline int dt_destroy(const struct lu_env *env,
995 struct dt_object *dt,
1000 LASSERT(dt->do_ops->do_destroy);
1001 return dt->do_ops->do_destroy(env, dt, th);
1004 static inline void dt_read_lock(const struct lu_env *env,
1005 struct dt_object *dt,
1009 LASSERT(dt->do_ops);
1010 LASSERT(dt->do_ops->do_read_lock);
1011 dt->do_ops->do_read_lock(env, dt, role);
1014 static inline void dt_write_lock(const struct lu_env *env,
1015 struct dt_object *dt,
1019 LASSERT(dt->do_ops);
1020 LASSERT(dt->do_ops->do_write_lock);
1021 dt->do_ops->do_write_lock(env, dt, role);
1024 static inline void dt_read_unlock(const struct lu_env *env,
1025 struct dt_object *dt)
1028 LASSERT(dt->do_ops);
1029 LASSERT(dt->do_ops->do_read_unlock);
1030 dt->do_ops->do_read_unlock(env, dt);
1033 static inline void dt_write_unlock(const struct lu_env *env,
1034 struct dt_object *dt)
1037 LASSERT(dt->do_ops);
1038 LASSERT(dt->do_ops->do_write_unlock);
1039 dt->do_ops->do_write_unlock(env, dt);
1042 static inline int dt_write_locked(const struct lu_env *env,
1043 struct dt_object *dt)
1046 LASSERT(dt->do_ops);
1047 LASSERT(dt->do_ops->do_write_locked);
1048 return dt->do_ops->do_write_locked(env, dt);
1051 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
1052 struct lu_attr *la, void *arg)
1055 LASSERT(dt->do_ops);
1056 LASSERT(dt->do_ops->do_attr_get);
1057 return dt->do_ops->do_attr_get(env, dt, la, arg);
1060 static inline int dt_declare_attr_set(const struct lu_env *env,
1061 struct dt_object *dt,
1062 const struct lu_attr *la,
1066 LASSERT(dt->do_ops);
1067 LASSERT(dt->do_ops->do_declare_attr_set);
1068 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
1071 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
1072 const struct lu_attr *la, struct thandle *th,
1073 struct lustre_capa *capa)
1076 LASSERT(dt->do_ops);
1077 LASSERT(dt->do_ops->do_attr_set);
1078 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
1081 static inline int dt_declare_ref_add(const struct lu_env *env,
1082 struct dt_object *dt, struct thandle *th)
1085 LASSERT(dt->do_ops);
1086 LASSERT(dt->do_ops->do_declare_ref_add);
1087 return dt->do_ops->do_declare_ref_add(env, dt, th);
1090 static inline int dt_ref_add(const struct lu_env *env,
1091 struct dt_object *dt, struct thandle *th)
1094 LASSERT(dt->do_ops);
1095 LASSERT(dt->do_ops->do_ref_add);
1096 return dt->do_ops->do_ref_add(env, dt, th);
1099 static inline int dt_declare_ref_del(const struct lu_env *env,
1100 struct dt_object *dt, struct thandle *th)
1103 LASSERT(dt->do_ops);
1104 LASSERT(dt->do_ops->do_declare_ref_del);
1105 return dt->do_ops->do_declare_ref_del(env, dt, th);
1108 static inline int dt_ref_del(const struct lu_env *env,
1109 struct dt_object *dt, struct thandle *th)
1112 LASSERT(dt->do_ops);
1113 LASSERT(dt->do_ops->do_ref_del);
1114 return dt->do_ops->do_ref_del(env, dt, th);
1117 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1118 struct dt_object *dt,
1119 struct lustre_capa *old, __u64 opc)
1122 LASSERT(dt->do_ops);
1123 LASSERT(dt->do_ops->do_ref_del);
1124 return dt->do_ops->do_capa_get(env, dt, old, opc);
1127 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1128 struct niobuf_remote *rnb,
1129 struct niobuf_local *lnb, int rw,
1130 struct lustre_capa *capa)
1133 LASSERT(d->do_body_ops);
1134 LASSERT(d->do_body_ops->dbo_bufs_get);
1135 return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1136 rnb->len, lnb, rw, capa);
1139 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1140 struct niobuf_local *lnb, int n)
1143 LASSERT(d->do_body_ops);
1144 LASSERT(d->do_body_ops->dbo_bufs_put);
1145 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1148 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1149 struct niobuf_local *lnb, int n)
1152 LASSERT(d->do_body_ops);
1153 LASSERT(d->do_body_ops->dbo_write_prep);
1154 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1157 static inline int dt_declare_write_commit(const struct lu_env *env,
1158 struct dt_object *d,
1159 struct niobuf_local *lnb,
1160 int n, struct thandle *th)
1162 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1163 LASSERT(th != NULL);
1164 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1168 static inline int dt_write_commit(const struct lu_env *env,
1169 struct dt_object *d, struct niobuf_local *lnb,
1170 int n, struct thandle *th)
1173 LASSERT(d->do_body_ops);
1174 LASSERT(d->do_body_ops->dbo_write_commit);
1175 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1178 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1179 struct niobuf_local *lnb, int n)
1182 LASSERT(d->do_body_ops);
1183 LASSERT(d->do_body_ops->dbo_read_prep);
1184 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1187 static inline int dt_declare_punch(const struct lu_env *env,
1188 struct dt_object *dt, __u64 start,
1189 __u64 end, struct thandle *th)
1192 LASSERT(dt->do_body_ops);
1193 LASSERT(dt->do_body_ops->do_declare_punch);
1194 return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1197 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1198 __u64 start, __u64 end, struct thandle *th,
1199 struct lustre_capa *capa)
1202 LASSERT(dt->do_body_ops);
1203 LASSERT(dt->do_body_ops->do_punch);
1204 return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1207 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1208 struct ll_user_fiemap *fm)
1211 if (d->do_body_ops == NULL)
1213 if (d->do_body_ops->dbo_fiemap_get == NULL)
1215 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1218 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1219 struct obd_statfs *osfs)
1222 LASSERT(dev->dd_ops);
1223 LASSERT(dev->dd_ops->dt_statfs);
1224 return dev->dd_ops->dt_statfs(env, dev, osfs);
1227 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1231 LASSERT(dev->dd_ops);
1232 LASSERT(dev->dd_ops->dt_root_get);
1233 return dev->dd_ops->dt_root_get(env, dev, f);
1236 static inline void dt_conf_get(const struct lu_env *env,
1237 const struct dt_device *dev,
1238 struct dt_device_param *param)
1241 LASSERT(dev->dd_ops);
1242 LASSERT(dev->dd_ops->dt_conf_get);
1243 return dev->dd_ops->dt_conf_get(env, dev, param);
1246 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1249 LASSERT(dev->dd_ops);
1250 LASSERT(dev->dd_ops->dt_sync);
1251 return dev->dd_ops->dt_sync(env, dev);
1254 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1257 LASSERT(dev->dd_ops);
1258 LASSERT(dev->dd_ops->dt_ro);
1259 return dev->dd_ops->dt_ro(env, dev);
1262 static inline int dt_declare_insert(const struct lu_env *env,
1263 struct dt_object *dt,
1264 const struct dt_rec *rec,
1265 const struct dt_key *key,
1269 LASSERT(dt->do_index_ops);
1270 LASSERT(dt->do_index_ops->dio_declare_insert);
1271 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1274 static inline int dt_insert(const struct lu_env *env,
1275 struct dt_object *dt,
1276 const struct dt_rec *rec,
1277 const struct dt_key *key,
1279 struct lustre_capa *capa,
1283 LASSERT(dt->do_index_ops);
1284 LASSERT(dt->do_index_ops->dio_insert);
1285 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1289 static inline int dt_declare_xattr_del(const struct lu_env *env,
1290 struct dt_object *dt,
1295 LASSERT(dt->do_ops);
1296 LASSERT(dt->do_ops->do_declare_xattr_del);
1297 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1300 static inline int dt_xattr_del(const struct lu_env *env,
1301 struct dt_object *dt, const char *name,
1303 struct lustre_capa *capa)
1306 LASSERT(dt->do_ops);
1307 LASSERT(dt->do_ops->do_xattr_del);
1308 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1311 static inline int dt_declare_xattr_set(const struct lu_env *env,
1312 struct dt_object *dt,
1313 const struct lu_buf *buf,
1314 const char *name, int fl,
1318 LASSERT(dt->do_ops);
1319 LASSERT(dt->do_ops->do_declare_xattr_set);
1320 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1323 static inline int dt_xattr_set(const struct lu_env *env,
1324 struct dt_object *dt, const struct lu_buf *buf,
1325 const char *name, int fl, struct thandle *th,
1326 struct lustre_capa *capa)
1329 LASSERT(dt->do_ops);
1330 LASSERT(dt->do_ops->do_xattr_set);
1331 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1334 static inline int dt_xattr_get(const struct lu_env *env,
1335 struct dt_object *dt, struct lu_buf *buf,
1336 const char *name, struct lustre_capa *capa)
1339 LASSERT(dt->do_ops);
1340 LASSERT(dt->do_ops->do_xattr_get);
1341 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1344 static inline int dt_xattr_list(const struct lu_env *env,
1345 struct dt_object *dt, struct lu_buf *buf,
1346 struct lustre_capa *capa)
1349 LASSERT(dt->do_ops);
1350 LASSERT(dt->do_ops->do_xattr_list);
1351 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1354 static inline int dt_declare_delete(const struct lu_env *env,
1355 struct dt_object *dt,
1356 const struct dt_key *key,
1360 LASSERT(dt->do_index_ops);
1361 LASSERT(dt->do_index_ops->dio_declare_delete);
1362 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1365 static inline int dt_delete(const struct lu_env *env,
1366 struct dt_object *dt,
1367 const struct dt_key *key,
1369 struct lustre_capa *capa)
1372 LASSERT(dt->do_index_ops);
1373 LASSERT(dt->do_index_ops->dio_delete);
1374 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1377 static inline int dt_commit_async(const struct lu_env *env,
1378 struct dt_device *dev)
1381 LASSERT(dev->dd_ops);
1382 LASSERT(dev->dd_ops->dt_commit_async);
1383 return dev->dd_ops->dt_commit_async(env, dev);
1386 static inline int dt_init_capa_ctxt(const struct lu_env *env,
1387 struct dt_device *dev,
1388 int mode, unsigned long timeout,
1389 __u32 alg, struct lustre_capa_key *keys)
1392 LASSERT(dev->dd_ops);
1393 LASSERT(dev->dd_ops->dt_init_capa_ctxt);
1394 return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
1395 timeout, alg, keys);
1398 static inline int dt_lookup(const struct lu_env *env,
1399 struct dt_object *dt,
1401 const struct dt_key *key,
1402 struct lustre_capa *capa)
1407 LASSERT(dt->do_index_ops);
1408 LASSERT(dt->do_index_ops->dio_lookup);
1410 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1418 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1420 struct dt_find_hint {
1421 struct lu_fid *dfh_fid;
1422 struct dt_device *dfh_dt;
1423 struct dt_object *dfh_o;
1426 struct dt_thread_info {
1427 char dti_buf[DT_MAX_PATH];
1428 struct dt_find_hint dti_dfh;
1429 struct lu_attr dti_attr;
1430 struct lu_fid dti_fid;
1431 struct dt_object_format dti_dof;
1432 struct lustre_mdt_attrs dti_lma;
1433 struct lu_buf dti_lb;
1437 extern struct lu_context_key dt_key;
1439 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
1441 struct dt_thread_info *dti;
1443 dti = lu_context_key_get(&env->le_ctx, &dt_key);
1448 #endif /* __LUSTRE_DT_OBJECT_H */