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, Whamcloud, Inc.
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;
73 MNTOPT_USERXATTR = 0x00000001,
74 MNTOPT_ACL = 0x00000002,
77 struct dt_device_param {
78 unsigned ddp_max_name_len;
79 unsigned ddp_max_nlink;
80 unsigned ddp_block_shift;
82 unsigned ddp_max_ea_size;
83 void *ddp_mnt; /* XXX: old code can retrieve mnt -bzzz */
85 unsigned long long ddp_maxbytes;
86 /* percentage of available space to reserve for grant error margin */
87 int ddp_grant_reserved;
88 /* per-inode space consumption */
90 /* per-fragment grant overhead to be used by client for grant
96 * Per-transaction commit callback function
98 struct dt_txn_commit_cb;
99 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
100 struct dt_txn_commit_cb *cb, int err);
102 * Special per-transaction callback for cases when just commit callback
103 * is needed and per-device callback are not convenient to use
105 struct dt_txn_commit_cb {
106 cfs_list_t dcb_linkage;
111 * Operations on dt device.
113 struct dt_device_operations {
115 * Return device-wide statistics.
117 int (*dt_statfs)(const struct lu_env *env,
118 struct dt_device *dev, struct obd_statfs *osfs);
120 * Create transaction, described by \a param.
122 struct thandle *(*dt_trans_create)(const struct lu_env *env,
123 struct dt_device *dev);
125 * Start transaction, described by \a param.
127 int (*dt_trans_start)(const struct lu_env *env,
128 struct dt_device *dev, struct thandle *th);
130 * Finish previously started transaction.
132 int (*dt_trans_stop)(const struct lu_env *env,
135 * Add commit callback to the transaction.
137 int (*dt_trans_cb_add)(struct thandle *th,
138 struct dt_txn_commit_cb *dcb);
140 * Return fid of root index object.
142 int (*dt_root_get)(const struct lu_env *env,
143 struct dt_device *dev, struct lu_fid *f);
145 * Return device configuration data.
147 void (*dt_conf_get)(const struct lu_env *env,
148 const struct dt_device *dev,
149 struct dt_device_param *param);
151 * handling device state, mostly for tests
153 int (*dt_sync)(const struct lu_env *env, struct dt_device *dev);
154 int (*dt_ro)(const struct lu_env *env, struct dt_device *dev);
156 * Start a transaction commit asynchronously
158 * \param env environment
159 * \param dev dt_device to start commit on
161 * \return 0 success, negative value if error
163 int (*dt_commit_async)(const struct lu_env *env,
164 struct dt_device *dev);
166 * Initialize capability context.
168 int (*dt_init_capa_ctxt)(const struct lu_env *env,
169 struct dt_device *dev,
170 int mode, unsigned long timeout,
171 __u32 alg, struct lustre_capa_key *keys);
173 * Initialize quota context.
175 void (*dt_init_quota_ctxt)(const struct lu_env *env,
176 struct dt_device *dev,
177 struct dt_quota_ctxt *ctxt, void *data);
180 struct dt_index_features {
181 /** required feature flags from enum dt_index_flags */
183 /** minimal required key size */
184 size_t dif_keysize_min;
185 /** maximal required key size, 0 if no limit */
186 size_t dif_keysize_max;
187 /** minimal required record size */
188 size_t dif_recsize_min;
189 /** maximal required record size, 0 if no limit */
190 size_t dif_recsize_max;
191 /** pointer size for record */
195 enum dt_index_flags {
196 /** index supports variable sized keys */
197 DT_IND_VARKEY = 1 << 0,
198 /** index supports variable sized records */
199 DT_IND_VARREC = 1 << 1,
200 /** index can be modified */
201 DT_IND_UPDATE = 1 << 2,
202 /** index supports records with non-unique (duplicate) keys */
203 DT_IND_NONUNQ = 1 << 3,
205 * index support fixed-size keys sorted with natural numerical way
206 * and is able to return left-side value if no exact value found
208 DT_IND_RANGE = 1 << 4,
212 * Features, required from index to support file system directories (mapping
215 extern const struct dt_index_features dt_directory_features;
216 extern const struct dt_index_features dt_otable_features;
219 * This is a general purpose dt allocation hint.
220 * It now contains the parent object.
221 * It can contain any allocation hint in the future.
223 struct dt_allocation_hint {
224 struct dt_object *dah_parent;
229 * object type specifier.
232 enum dt_format_type {
237 /** for special index */
239 /** for symbolic link */
244 * object format specifier.
246 struct dt_object_format {
247 /** type for dt object */
248 enum dt_format_type dof_type;
257 * special index need feature as parameter to create
261 const struct dt_index_features *di_feat;
266 enum dt_format_type dt_mode_to_dft(__u32 mode);
268 typedef __u64 dt_obj_version_t;
271 * Per-dt-object operations.
273 struct dt_object_operations {
274 void (*do_read_lock)(const struct lu_env *env,
275 struct dt_object *dt, unsigned role);
276 void (*do_write_lock)(const struct lu_env *env,
277 struct dt_object *dt, unsigned role);
278 void (*do_read_unlock)(const struct lu_env *env,
279 struct dt_object *dt);
280 void (*do_write_unlock)(const struct lu_env *env,
281 struct dt_object *dt);
282 int (*do_write_locked)(const struct lu_env *env,
283 struct dt_object *dt);
285 * Note: following ->do_{x,}attr_{set,get}() operations are very
286 * similar to ->moo_{x,}attr_{set,get}() operations in struct
287 * md_object_operations (see md_object.h). These operations are not in
288 * lu_object_operations, because ->do_{x,}attr_set() versions take
289 * transaction handle as an argument (this transaction is started by
290 * caller). We might factor ->do_{x,}attr_get() into
291 * lu_object_operations, but that would break existing symmetry.
295 * Return standard attributes.
297 * precondition: lu_object_exists(&dt->do_lu);
299 int (*do_attr_get)(const struct lu_env *env,
300 struct dt_object *dt, struct lu_attr *attr,
301 struct lustre_capa *capa);
303 * Set standard attributes.
305 * precondition: dt_object_exists(dt);
307 int (*do_declare_attr_set)(const struct lu_env *env,
308 struct dt_object *dt,
309 const struct lu_attr *attr,
310 struct thandle *handle);
311 int (*do_attr_set)(const struct lu_env *env,
312 struct dt_object *dt,
313 const struct lu_attr *attr,
314 struct thandle *handle,
315 struct lustre_capa *capa);
317 * Return a value of an extended attribute.
319 * precondition: dt_object_exists(dt);
321 int (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
322 struct lu_buf *buf, const char *name,
323 struct lustre_capa *capa);
325 * Set value of an extended attribute.
327 * \a fl - flags from enum lu_xattr_flags
329 * precondition: dt_object_exists(dt);
331 int (*do_declare_xattr_set)(const struct lu_env *env,
332 struct dt_object *dt,
333 const struct lu_buf *buf,
334 const char *name, int fl,
335 struct thandle *handle);
336 int (*do_xattr_set)(const struct lu_env *env,
337 struct dt_object *dt, const struct lu_buf *buf,
338 const char *name, int fl, struct thandle *handle,
339 struct lustre_capa *capa);
341 * Delete existing extended attribute.
343 * precondition: dt_object_exists(dt);
345 int (*do_declare_xattr_del)(const struct lu_env *env,
346 struct dt_object *dt,
347 const char *name, struct thandle *handle);
348 int (*do_xattr_del)(const struct lu_env *env,
349 struct dt_object *dt,
350 const char *name, struct thandle *handle,
351 struct lustre_capa *capa);
353 * Place list of existing extended attributes into \a buf (which has
356 * precondition: dt_object_exists(dt);
358 int (*do_xattr_list)(const struct lu_env *env,
359 struct dt_object *dt, struct lu_buf *buf,
360 struct lustre_capa *capa);
362 * Init allocation hint using parent object and child mode.
363 * (1) The \a parent might be NULL if this is a partial creation for
365 * (2) The type of child is in \a child_mode.
366 * (3) The result hint is stored in \a ah;
368 void (*do_ah_init)(const struct lu_env *env,
369 struct dt_allocation_hint *ah,
370 struct dt_object *parent,
371 cfs_umode_t child_mode);
373 * Create new object on this device.
375 * precondition: !dt_object_exists(dt);
376 * postcondition: ergo(result == 0, dt_object_exists(dt));
378 int (*do_declare_create)(const struct lu_env *env,
379 struct dt_object *dt,
380 struct lu_attr *attr,
381 struct dt_allocation_hint *hint,
382 struct dt_object_format *dof,
384 int (*do_create)(const struct lu_env *env, struct dt_object *dt,
385 struct lu_attr *attr,
386 struct dt_allocation_hint *hint,
387 struct dt_object_format *dof,
391 Destroy object on this device
392 * precondition: !dt_object_exists(dt);
393 * postcondition: ergo(result == 0, dt_object_exists(dt));
395 int (*do_declare_destroy)(const struct lu_env *env,
396 struct dt_object *dt,
398 int (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
402 * Announce that this object is going to be used as an index. This
403 * operation check that object supports indexing operations and
404 * installs appropriate dt_index_operations vector on success.
406 * Also probes for features. Operation is successful if all required
407 * features are supported.
409 int (*do_index_try)(const struct lu_env *env,
410 struct dt_object *dt,
411 const struct dt_index_features *feat);
413 * Add nlink of the object
414 * precondition: dt_object_exists(dt);
416 int (*do_declare_ref_add)(const struct lu_env *env,
417 struct dt_object *dt, struct thandle *th);
418 int (*do_ref_add)(const struct lu_env *env,
419 struct dt_object *dt, struct thandle *th);
421 * Del nlink of the object
422 * precondition: dt_object_exists(dt);
424 int (*do_declare_ref_del)(const struct lu_env *env,
425 struct dt_object *dt, struct thandle *th);
426 int (*do_ref_del)(const struct lu_env *env,
427 struct dt_object *dt, struct thandle *th);
429 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
430 struct dt_object *dt,
431 struct lustre_capa *old,
433 int (*do_object_sync)(const struct lu_env *, struct dt_object *);
435 * Get object info of next level. Currently, only get inode from osd.
436 * This is only used by quota b=16542
437 * precondition: dt_object_exists(dt);
439 int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
444 * Per-dt-object operations on "file body".
446 struct dt_body_operations {
448 * precondition: dt_object_exists(dt);
450 ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
451 struct lu_buf *buf, loff_t *pos,
452 struct lustre_capa *capa);
454 * precondition: dt_object_exists(dt);
456 ssize_t (*dbo_declare_write)(const struct lu_env *env,
457 struct dt_object *dt,
458 const loff_t size, loff_t pos,
459 struct thandle *handle);
460 ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
461 const struct lu_buf *buf, loff_t *pos,
462 struct thandle *handle, struct lustre_capa *capa,
465 * methods for zero-copy IO
469 * precondition: dt_object_exists(dt);
473 * > 0 - number of local buffers prepared
475 int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
476 loff_t pos, ssize_t len, struct niobuf_local *lb,
477 int rw, struct lustre_capa *capa);
479 * precondition: dt_object_exists(dt);
481 int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
482 struct niobuf_local *lb, int nr);
484 * precondition: dt_object_exists(dt);
486 int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
487 struct niobuf_local *lb, int nr);
489 * precondition: dt_object_exists(dt);
491 int (*dbo_declare_write_commit)(const struct lu_env *env,
492 struct dt_object *dt,
493 struct niobuf_local *,
494 int, struct thandle *);
496 * precondition: dt_object_exists(dt);
498 int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
499 struct niobuf_local *, int, struct thandle *);
501 * precondition: dt_object_exists(dt);
503 int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
504 struct niobuf_local *lnb, int nr);
505 int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
506 struct ll_user_fiemap *fm);
508 * Punch object's content
509 * precondition: regular object, not index
511 int (*do_declare_punch)(const struct lu_env *, struct dt_object *,
512 __u64, __u64, struct thandle *th);
513 int (*do_punch)(const struct lu_env *env, struct dt_object *dt,
514 __u64 start, __u64 end, struct thandle *th,
515 struct lustre_capa *capa);
519 * Incomplete type of index record.
524 * Incomplete type of index key.
529 * Incomplete type of dt iterator.
534 * Per-dt-object operations on object as index.
536 struct dt_index_operations {
538 * precondition: dt_object_exists(dt);
540 int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
541 struct dt_rec *rec, const struct dt_key *key,
542 struct lustre_capa *capa);
544 * precondition: dt_object_exists(dt);
546 int (*dio_declare_insert)(const struct lu_env *env,
547 struct dt_object *dt,
548 const struct dt_rec *rec,
549 const struct dt_key *key,
550 struct thandle *handle);
551 int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
552 const struct dt_rec *rec, const struct dt_key *key,
553 struct thandle *handle, struct lustre_capa *capa,
556 * precondition: dt_object_exists(dt);
558 int (*dio_declare_delete)(const struct lu_env *env,
559 struct dt_object *dt,
560 const struct dt_key *key,
561 struct thandle *handle);
562 int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
563 const struct dt_key *key, struct thandle *handle,
564 struct lustre_capa *capa);
570 * Allocate and initialize new iterator.
572 * precondition: dt_object_exists(dt);
574 struct dt_it *(*init)(const struct lu_env *env,
575 struct dt_object *dt,
577 struct lustre_capa *capa);
578 void (*fini)(const struct lu_env *env,
580 int (*get)(const struct lu_env *env,
582 const struct dt_key *key);
583 void (*put)(const struct lu_env *env,
585 int (*next)(const struct lu_env *env,
587 struct dt_key *(*key)(const struct lu_env *env,
588 const struct dt_it *di);
589 int (*key_size)(const struct lu_env *env,
590 const struct dt_it *di);
591 int (*rec)(const struct lu_env *env,
592 const struct dt_it *di,
595 __u64 (*store)(const struct lu_env *env,
596 const struct dt_it *di);
597 int (*load)(const struct lu_env *env,
598 const struct dt_it *di, __u64 hash);
599 int (*key_rec)(const struct lu_env *env,
600 const struct dt_it *di, void* key_rec);
604 enum dt_otable_it_valid {
605 DOIV_ERROR_HANDLE = 0x0001,
608 enum dt_otable_it_flags {
609 /* Exit when fail. */
610 DOIF_FAILOUT = 0x0001,
612 /* Reset iteration position to the device beginning. */
615 /* There is up layer component uses the iteration. */
616 DOIF_OUTUSED = 0x0004,
619 /* otable based iteration needs to use the common DT interation APIs.
620 * To initialize the iteration, it needs call dio_it::init() firstly.
621 * Here is how the otable based iteration should prepare arguments to
622 * call dt_it_ops::init().
624 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
625 * is composed of two parts:
626 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
627 #define DT_OTABLE_IT_FLAGS_SHIFT 16
628 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
631 struct lu_device dd_lu_dev;
632 const struct dt_device_operations *dd_ops;
635 * List of dt_txn_callback (see below). This is not protected in any
636 * way, because callbacks are supposed to be added/deleted only during
637 * single-threaded start-up shut-down procedures.
639 cfs_list_t dd_txn_callbacks;
642 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
643 void dt_device_fini(struct dt_device *dev);
645 static inline int lu_device_is_dt(const struct lu_device *d)
647 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
650 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
652 LASSERT(lu_device_is_dt(l));
653 return container_of0(l, struct dt_device, dd_lu_dev);
657 struct lu_object do_lu;
658 const struct dt_object_operations *do_ops;
659 const struct dt_body_operations *do_body_ops;
660 const struct dt_index_operations *do_index_ops;
663 static inline struct dt_object *lu2dt(struct lu_object *l)
665 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
666 return container_of0(l, struct dt_object, do_lu);
669 int dt_object_init(struct dt_object *obj,
670 struct lu_object_header *h, struct lu_device *d);
672 void dt_object_fini(struct dt_object *obj);
674 static inline int dt_object_exists(const struct dt_object *dt)
676 return lu_object_exists(&dt->do_lu);
680 * This is the general purpose transaction handle.
681 * 1. Transaction Life Cycle
682 * This transaction handle is allocated upon starting a new transaction,
683 * and deallocated after this transaction is committed.
684 * 2. Transaction Nesting
685 * We do _NOT_ support nested transaction. So, every thread should only
686 * have one active transaction, and a transaction only belongs to one
687 * thread. Due to this, transaction handle need no reference count.
688 * 3. Transaction & dt_object locking
689 * dt_object locks should be taken inside transaction.
690 * 4. Transaction & RPC
691 * No RPC request should be issued inside transaction.
694 /** the dt device on which the transactions are executed */
695 struct dt_device *th_dev;
697 /** additional tags (layers can add in declare) */
700 /** context for this transaction, tag is LCT_TX_HANDLE */
701 struct lu_context th_ctx;
703 /** the last operation result in this transaction.
704 * this value is used in recovery */
707 /** whether we need sync commit */
710 /* local transation, no need to inform other layers */
715 * Transaction call-backs.
717 * These are invoked by osd (or underlying transaction engine) when
718 * transaction changes state.
720 * Call-backs are used by upper layers to modify transaction parameters and to
721 * perform some actions on for each transaction state transition. Typical
722 * example is mdt registering call-back to write into last-received file
723 * before each transaction commit.
725 struct dt_txn_callback {
726 int (*dtc_txn_start)(const struct lu_env *env,
727 struct thandle *txn, void *cookie);
728 int (*dtc_txn_stop)(const struct lu_env *env,
729 struct thandle *txn, void *cookie);
730 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
733 cfs_list_t dtc_linkage;
736 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
737 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
739 int dt_txn_hook_start(const struct lu_env *env,
740 struct dt_device *dev, struct thandle *txn);
741 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
742 void dt_txn_hook_commit(struct thandle *txn);
744 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
747 * Callback function used for parsing path.
748 * \see llo_store_resolve
750 typedef int (*dt_entry_func_t)(const struct lu_env *env,
754 #define DT_MAX_PATH 1024
756 int dt_path_parser(const struct lu_env *env,
757 char *local, dt_entry_func_t entry_func,
760 struct dt_object *dt_store_open(const struct lu_env *env,
761 struct dt_device *dt,
763 const char *filename,
766 struct dt_object *dt_find_or_create(const struct lu_env *env,
767 struct dt_device *dt,
768 const struct lu_fid *fid,
769 struct dt_object_format *dof,
770 struct lu_attr *attr);
772 struct dt_object *dt_locate(const struct lu_env *env,
773 struct dt_device *dev,
774 const struct lu_fid *fid);
776 static inline int dt_object_sync(const struct lu_env *env,
781 LASSERT(o->do_ops->do_object_sync);
782 return o->do_ops->do_object_sync(env, o);
785 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
787 void dt_version_set(const struct lu_env *env, struct dt_object *o,
788 dt_obj_version_t version, struct thandle *th);
789 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
792 int dt_read(const struct lu_env *env, struct dt_object *dt,
793 struct lu_buf *buf, loff_t *pos);
794 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
795 struct lu_buf *buf, loff_t *pos);
796 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
797 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
799 static inline struct thandle *dt_trans_create(const struct lu_env *env,
802 LASSERT(d->dd_ops->dt_trans_create);
803 return d->dd_ops->dt_trans_create(env, d);
806 static inline int dt_trans_start(const struct lu_env *env,
807 struct dt_device *d, struct thandle *th)
809 LASSERT(d->dd_ops->dt_trans_start);
810 return d->dd_ops->dt_trans_start(env, d, th);
813 /* for this transaction hooks shouldn't be called */
814 static inline int dt_trans_start_local(const struct lu_env *env,
815 struct dt_device *d, struct thandle *th)
817 LASSERT(d->dd_ops->dt_trans_start);
819 return d->dd_ops->dt_trans_start(env, d, th);
822 static inline int dt_trans_stop(const struct lu_env *env,
823 struct dt_device *d, struct thandle *th)
825 LASSERT(d->dd_ops->dt_trans_stop);
826 return d->dd_ops->dt_trans_stop(env, th);
829 static inline int dt_trans_cb_add(struct thandle *th,
830 struct dt_txn_commit_cb *dcb)
832 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
833 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
838 static inline int dt_declare_record_write(const struct lu_env *env,
839 struct dt_object *dt,
840 int size, loff_t pos,
845 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
847 LASSERT(dt->do_body_ops);
848 LASSERT(dt->do_body_ops->dbo_declare_write);
849 rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
853 static inline int dt_declare_create(const struct lu_env *env,
854 struct dt_object *dt,
855 struct lu_attr *attr,
856 struct dt_allocation_hint *hint,
857 struct dt_object_format *dof,
862 LASSERT(dt->do_ops->do_declare_create);
863 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
866 static inline int dt_create(const struct lu_env *env,
867 struct dt_object *dt,
868 struct lu_attr *attr,
869 struct dt_allocation_hint *hint,
870 struct dt_object_format *dof,
875 LASSERT(dt->do_ops->do_create);
876 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
879 static inline int dt_declare_destroy(const struct lu_env *env,
880 struct dt_object *dt,
885 LASSERT(dt->do_ops->do_declare_destroy);
886 return dt->do_ops->do_declare_destroy(env, dt, th);
889 static inline int dt_destroy(const struct lu_env *env,
890 struct dt_object *dt,
895 LASSERT(dt->do_ops->do_destroy);
896 return dt->do_ops->do_destroy(env, dt, th);
899 static inline void dt_read_lock(const struct lu_env *env,
900 struct dt_object *dt,
905 LASSERT(dt->do_ops->do_read_lock);
906 dt->do_ops->do_read_lock(env, dt, role);
909 static inline void dt_write_lock(const struct lu_env *env,
910 struct dt_object *dt,
915 LASSERT(dt->do_ops->do_write_lock);
916 dt->do_ops->do_write_lock(env, dt, role);
919 static inline void dt_read_unlock(const struct lu_env *env,
920 struct dt_object *dt)
924 LASSERT(dt->do_ops->do_read_unlock);
925 dt->do_ops->do_read_unlock(env, dt);
928 static inline void dt_write_unlock(const struct lu_env *env,
929 struct dt_object *dt)
933 LASSERT(dt->do_ops->do_write_unlock);
934 dt->do_ops->do_write_unlock(env, dt);
937 static inline int dt_write_locked(const struct lu_env *env,
938 struct dt_object *dt)
942 LASSERT(dt->do_ops->do_write_locked);
943 return dt->do_ops->do_write_locked(env, dt);
946 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
947 struct lu_attr *la, void *arg)
951 LASSERT(dt->do_ops->do_attr_get);
952 return dt->do_ops->do_attr_get(env, dt, la, arg);
955 static inline int dt_declare_attr_set(const struct lu_env *env,
956 struct dt_object *dt,
957 const struct lu_attr *la,
962 LASSERT(dt->do_ops->do_declare_attr_set);
963 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
966 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
967 const struct lu_attr *la, struct thandle *th,
968 struct lustre_capa *capa)
972 LASSERT(dt->do_ops->do_attr_set);
973 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
976 static inline int dt_declare_ref_add(const struct lu_env *env,
977 struct dt_object *dt, struct thandle *th)
981 LASSERT(dt->do_ops->do_declare_ref_add);
982 return dt->do_ops->do_declare_ref_add(env, dt, th);
985 static inline int dt_ref_add(const struct lu_env *env,
986 struct dt_object *dt, struct thandle *th)
990 LASSERT(dt->do_ops->do_ref_add);
991 return dt->do_ops->do_ref_add(env, dt, th);
994 static inline int dt_declare_ref_del(const struct lu_env *env,
995 struct dt_object *dt, struct thandle *th)
999 LASSERT(dt->do_ops->do_declare_ref_del);
1000 return dt->do_ops->do_declare_ref_del(env, dt, th);
1003 static inline int dt_ref_del(const struct lu_env *env,
1004 struct dt_object *dt, struct thandle *th)
1007 LASSERT(dt->do_ops);
1008 LASSERT(dt->do_ops->do_ref_del);
1009 return dt->do_ops->do_ref_del(env, dt, th);
1012 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1013 struct dt_object *dt,
1014 struct lustre_capa *old, __u64 opc)
1017 LASSERT(dt->do_ops);
1018 LASSERT(dt->do_ops->do_ref_del);
1019 return dt->do_ops->do_capa_get(env, dt, old, opc);
1022 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1023 struct niobuf_remote *rnb,
1024 struct niobuf_local *lnb, int rw,
1025 struct lustre_capa *capa)
1028 LASSERT(d->do_body_ops);
1029 LASSERT(d->do_body_ops->dbo_bufs_get);
1030 return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1031 rnb->len, lnb, rw, capa);
1034 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1035 struct niobuf_local *lnb, int n)
1038 LASSERT(d->do_body_ops);
1039 LASSERT(d->do_body_ops->dbo_bufs_put);
1040 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1043 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1044 struct niobuf_local *lnb, int n)
1047 LASSERT(d->do_body_ops);
1048 LASSERT(d->do_body_ops->dbo_write_prep);
1049 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1052 static inline int dt_declare_write_commit(const struct lu_env *env,
1053 struct dt_object *d,
1054 struct niobuf_local *lnb,
1055 int n, struct thandle *th)
1057 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1058 LASSERT(th != NULL);
1059 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1063 static inline int dt_write_commit(const struct lu_env *env,
1064 struct dt_object *d, struct niobuf_local *lnb,
1065 int n, struct thandle *th)
1068 LASSERT(d->do_body_ops);
1069 LASSERT(d->do_body_ops->dbo_write_commit);
1070 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1073 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1074 struct niobuf_local *lnb, int n)
1077 LASSERT(d->do_body_ops);
1078 LASSERT(d->do_body_ops->dbo_read_prep);
1079 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1082 static inline int dt_declare_punch(const struct lu_env *env,
1083 struct dt_object *dt, __u64 start,
1084 __u64 end, struct thandle *th)
1087 LASSERT(dt->do_body_ops);
1088 LASSERT(dt->do_body_ops->do_declare_punch);
1089 return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1092 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1093 __u64 start, __u64 end, struct thandle *th,
1094 struct lustre_capa *capa)
1097 LASSERT(dt->do_body_ops);
1098 LASSERT(dt->do_body_ops->do_punch);
1099 return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1102 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1103 struct ll_user_fiemap *fm)
1106 if (d->do_body_ops == NULL)
1108 LASSERT(d->do_body_ops->dbo_fiemap_get);
1109 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1112 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1113 struct obd_statfs *osfs)
1116 LASSERT(dev->dd_ops);
1117 LASSERT(dev->dd_ops->dt_statfs);
1118 return dev->dd_ops->dt_statfs(env, dev, osfs);
1121 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1125 LASSERT(dev->dd_ops);
1126 LASSERT(dev->dd_ops->dt_root_get);
1127 return dev->dd_ops->dt_root_get(env, dev, f);
1130 static inline void dt_conf_get(const struct lu_env *env,
1131 const struct dt_device *dev,
1132 struct dt_device_param *param)
1135 LASSERT(dev->dd_ops);
1136 LASSERT(dev->dd_ops->dt_conf_get);
1137 return dev->dd_ops->dt_conf_get(env, dev, param);
1140 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1143 LASSERT(dev->dd_ops);
1144 LASSERT(dev->dd_ops->dt_sync);
1145 return dev->dd_ops->dt_sync(env, dev);
1148 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1151 LASSERT(dev->dd_ops);
1152 LASSERT(dev->dd_ops->dt_ro);
1153 return dev->dd_ops->dt_ro(env, dev);
1156 static inline int dt_declare_insert(const struct lu_env *env,
1157 struct dt_object *dt,
1158 const struct dt_rec *rec,
1159 const struct dt_key *key,
1163 LASSERT(dt->do_index_ops);
1164 LASSERT(dt->do_index_ops->dio_declare_insert);
1165 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1168 static inline int dt_insert(const struct lu_env *env,
1169 struct dt_object *dt,
1170 const struct dt_rec *rec,
1171 const struct dt_key *key,
1173 struct lustre_capa *capa,
1177 LASSERT(dt->do_index_ops);
1178 LASSERT(dt->do_index_ops->dio_insert);
1179 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1183 static inline int dt_declare_xattr_del(const struct lu_env *env,
1184 struct dt_object *dt,
1189 LASSERT(dt->do_ops);
1190 LASSERT(dt->do_ops->do_declare_xattr_del);
1191 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1194 static inline int dt_xattr_del(const struct lu_env *env,
1195 struct dt_object *dt, const char *name,
1197 struct lustre_capa *capa)
1200 LASSERT(dt->do_ops);
1201 LASSERT(dt->do_ops->do_xattr_del);
1202 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1205 static inline int dt_declare_xattr_set(const struct lu_env *env,
1206 struct dt_object *dt,
1207 const struct lu_buf *buf,
1208 const char *name, int fl,
1212 LASSERT(dt->do_ops);
1213 LASSERT(dt->do_ops->do_declare_xattr_set);
1214 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1217 static inline int dt_xattr_set(const struct lu_env *env,
1218 struct dt_object *dt, const struct lu_buf *buf,
1219 const char *name, int fl, struct thandle *th,
1220 struct lustre_capa *capa)
1223 LASSERT(dt->do_ops);
1224 LASSERT(dt->do_ops->do_xattr_set);
1225 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1228 static inline int dt_xattr_get(const struct lu_env *env,
1229 struct dt_object *dt, struct lu_buf *buf,
1230 const char *name, struct lustre_capa *capa)
1233 LASSERT(dt->do_ops);
1234 LASSERT(dt->do_ops->do_xattr_get);
1235 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1238 static inline int dt_xattr_list(const struct lu_env *env,
1239 struct dt_object *dt, struct lu_buf *buf,
1240 struct lustre_capa *capa)
1243 LASSERT(dt->do_ops);
1244 LASSERT(dt->do_ops->do_xattr_list);
1245 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1248 static inline int dt_declare_delete(const struct lu_env *env,
1249 struct dt_object *dt,
1250 const struct dt_key *key,
1254 LASSERT(dt->do_index_ops);
1255 LASSERT(dt->do_index_ops->dio_declare_delete);
1256 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1259 static inline int dt_delete(const struct lu_env *env,
1260 struct dt_object *dt,
1261 const struct dt_key *key,
1263 struct lustre_capa *capa)
1266 LASSERT(dt->do_index_ops);
1267 LASSERT(dt->do_index_ops->dio_delete);
1268 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1271 static inline int dt_commit_async(const struct lu_env *env,
1272 struct dt_device *dev)
1275 LASSERT(dev->dd_ops);
1276 LASSERT(dev->dd_ops->dt_commit_async);
1277 return dev->dd_ops->dt_commit_async(env, dev);
1280 static inline int dt_lookup(const struct lu_env *env,
1281 struct dt_object *dt,
1283 const struct dt_key *key,
1284 struct lustre_capa *capa)
1289 LASSERT(dt->do_index_ops);
1290 LASSERT(dt->do_index_ops->dio_lookup);
1292 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1300 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1302 #endif /* __LUSTRE_DT_OBJECT_H */