1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
40 #ifndef __LUSTRE_DT_OBJECT_H
41 #define __LUSTRE_DT_OBJECT_H
44 * Sub-class of lu_object with methods common for "data" objects in OST stack.
46 * Data objects behave like regular files: you can read/write them, get and
47 * set their attributes. Implementation of dt interface is supposed to
48 * implement some form of garbage collection, normally reference counting
51 * Examples: osd (lustre/osd) is an implementation of dt interface.
57 * super-class definitions.
59 #include <lu_object.h>
61 #include <libcfs/libcfs.h>
64 struct proc_dir_entry;
70 struct dt_index_features;
76 MNTOPT_USERXATTR = 0x00000001,
77 MNTOPT_ACL = 0x00000002,
80 struct dt_device_param {
81 unsigned ddp_max_name_len;
82 unsigned ddp_max_nlink;
83 unsigned ddp_block_shift;
85 unsigned ddp_max_ea_size;
86 void *ddp_mnt; /* XXX: old code can retrieve mnt -bzzz */
88 unsigned long long ddp_maxbytes;
89 /* percentage of available space to reserve for grant error margin */
90 int ddp_grant_reserved;
91 /* per-inode space consumption */
93 /* per-fragment grant overhead to be used by client for grant
99 * Per-transaction commit callback function
101 struct dt_txn_commit_cb;
102 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
103 struct dt_txn_commit_cb *cb, int err);
105 * Special per-transaction callback for cases when just commit callback
106 * is needed and per-device callback are not convenient to use
108 struct dt_txn_commit_cb {
109 cfs_list_t dcb_linkage;
114 * Operations on dt device.
116 struct dt_device_operations {
118 * Return device-wide statistics.
120 int (*dt_statfs)(const struct lu_env *env,
121 struct dt_device *dev, cfs_kstatfs_t *osfs);
123 * Create transaction, described by \a param.
125 struct thandle *(*dt_trans_create)(const struct lu_env *env,
126 struct dt_device *dev);
128 * Start transaction, described by \a param.
130 int (*dt_trans_start)(const struct lu_env *env,
131 struct dt_device *dev, struct thandle *th);
133 * Finish previously started transaction.
135 int (*dt_trans_stop)(const struct lu_env *env,
138 * Add commit callback to the transaction.
140 int (*dt_trans_cb_add)(struct thandle *th,
141 struct dt_txn_commit_cb *dcb);
143 * Return fid of root index object.
145 int (*dt_root_get)(const struct lu_env *env,
146 struct dt_device *dev, struct lu_fid *f);
148 * Return device configuration data.
150 void (*dt_conf_get)(const struct lu_env *env,
151 const struct dt_device *dev,
152 struct dt_device_param *param);
154 * handling device state, mostly for tests
156 int (*dt_sync)(const struct lu_env *env, struct dt_device *dev);
157 void (*dt_ro)(const struct lu_env *env, struct dt_device *dev);
159 * Start a transaction commit asynchronously
161 * \param env environment
162 * \param dev dt_device to start commit on
164 * \return 0 success, negative value if error
166 int (*dt_commit_async)(const struct lu_env *env,
167 struct dt_device *dev);
169 * Initialize capability context.
171 int (*dt_init_capa_ctxt)(const struct lu_env *env,
172 struct dt_device *dev,
173 int mode, unsigned long timeout,
174 __u32 alg, struct lustre_capa_key *keys);
176 * Initialize quota context.
178 void (*dt_init_quota_ctxt)(const struct lu_env *env,
179 struct dt_device *dev,
180 struct dt_quota_ctxt *ctxt, void *data);
183 struct dt_index_features {
184 /** required feature flags from enum dt_index_flags */
186 /** minimal required key size */
187 size_t dif_keysize_min;
188 /** maximal required key size, 0 if no limit */
189 size_t dif_keysize_max;
190 /** minimal required record size */
191 size_t dif_recsize_min;
192 /** maximal required record size, 0 if no limit */
193 size_t dif_recsize_max;
194 /** pointer size for record */
198 enum dt_index_flags {
199 /** index supports variable sized keys */
200 DT_IND_VARKEY = 1 << 0,
201 /** index supports variable sized records */
202 DT_IND_VARREC = 1 << 1,
203 /** index can be modified */
204 DT_IND_UPDATE = 1 << 2,
205 /** index supports records with non-unique (duplicate) keys */
206 DT_IND_NONUNQ = 1 << 3
210 * Features, required from index to support file system directories (mapping
213 extern const struct dt_index_features dt_directory_features;
216 * This is a general purpose dt allocation hint.
217 * It now contains the parent object.
218 * It can contain any allocation hint in the future.
220 struct dt_allocation_hint {
221 struct dt_object *dah_parent;
226 * object type specifier.
229 enum dt_format_type {
234 /** for special index */
236 /** for symbolic link */
241 * object format specifier.
243 struct dt_object_format {
244 /** type for dt object */
245 enum dt_format_type dof_type;
254 * special index need feature as parameter to create
258 const struct dt_index_features *di_feat;
263 enum dt_format_type dt_mode_to_dft(__u32 mode);
265 typedef __u64 dt_obj_version_t;
268 * Per-dt-object operations.
270 struct dt_object_operations {
271 void (*do_read_lock)(const struct lu_env *env,
272 struct dt_object *dt, unsigned role);
273 void (*do_write_lock)(const struct lu_env *env,
274 struct dt_object *dt, unsigned role);
275 void (*do_read_unlock)(const struct lu_env *env,
276 struct dt_object *dt);
277 void (*do_write_unlock)(const struct lu_env *env,
278 struct dt_object *dt);
279 int (*do_write_locked)(const struct lu_env *env,
280 struct dt_object *dt);
282 * Note: following ->do_{x,}attr_{set,get}() operations are very
283 * similar to ->moo_{x,}attr_{set,get}() operations in struct
284 * md_object_operations (see md_object.h). These operations are not in
285 * lu_object_operations, because ->do_{x,}attr_set() versions take
286 * transaction handle as an argument (this transaction is started by
287 * caller). We might factor ->do_{x,}attr_get() into
288 * lu_object_operations, but that would break existing symmetry.
292 * Return standard attributes.
294 * precondition: lu_object_exists(&dt->do_lu);
296 int (*do_attr_get)(const struct lu_env *env,
297 struct dt_object *dt, struct lu_attr *attr,
298 struct lustre_capa *capa);
300 * Set standard attributes.
302 * precondition: dt_object_exists(dt);
304 int (*do_declare_attr_set)(const struct lu_env *env,
305 struct dt_object *dt,
306 const struct lu_attr *attr,
307 struct thandle *handle);
308 int (*do_attr_set)(const struct lu_env *env,
309 struct dt_object *dt,
310 const struct lu_attr *attr,
311 struct thandle *handle,
312 struct lustre_capa *capa);
314 * Return a value of an extended attribute.
316 * precondition: dt_object_exists(dt);
318 int (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
319 struct lu_buf *buf, const char *name,
320 struct lustre_capa *capa);
322 * Set value of an extended attribute.
324 * \a fl - flags from enum lu_xattr_flags
326 * precondition: dt_object_exists(dt);
328 int (*do_declare_xattr_set)(const struct lu_env *env,
329 struct dt_object *dt,
330 const struct lu_buf *buf,
331 const char *name, int fl,
332 struct thandle *handle);
333 int (*do_xattr_set)(const struct lu_env *env,
334 struct dt_object *dt, const struct lu_buf *buf,
335 const char *name, int fl, struct thandle *handle,
336 struct lustre_capa *capa);
338 * Delete existing extended attribute.
340 * precondition: dt_object_exists(dt);
342 int (*do_declare_xattr_del)(const struct lu_env *env,
343 struct dt_object *dt,
344 const char *name, struct thandle *handle);
345 int (*do_xattr_del)(const struct lu_env *env,
346 struct dt_object *dt,
347 const char *name, struct thandle *handle,
348 struct lustre_capa *capa);
350 * Place list of existing extended attributes into \a buf (which has
353 * precondition: dt_object_exists(dt);
355 int (*do_xattr_list)(const struct lu_env *env,
356 struct dt_object *dt, struct lu_buf *buf,
357 struct lustre_capa *capa);
359 * Init allocation hint using parent object and child mode.
360 * (1) The \a parent might be NULL if this is a partial creation for
362 * (2) The type of child is in \a child_mode.
363 * (3) The result hint is stored in \a ah;
365 void (*do_ah_init)(const struct lu_env *env,
366 struct dt_allocation_hint *ah,
367 struct dt_object *parent,
368 cfs_umode_t child_mode);
370 * Create new object on this device.
372 * precondition: !dt_object_exists(dt);
373 * postcondition: ergo(result == 0, dt_object_exists(dt));
375 int (*do_declare_create)(const struct lu_env *env,
376 struct dt_object *dt,
377 struct lu_attr *attr,
378 struct dt_allocation_hint *hint,
379 struct dt_object_format *dof,
381 int (*do_create)(const struct lu_env *env, struct dt_object *dt,
382 struct lu_attr *attr,
383 struct dt_allocation_hint *hint,
384 struct dt_object_format *dof,
388 Destroy object on this device
389 * precondition: !dt_object_exists(dt);
390 * postcondition: ergo(result == 0, dt_object_exists(dt));
392 int (*do_declare_destroy)(const struct lu_env *env,
393 struct dt_object *dt,
395 int (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
399 * Announce that this object is going to be used as an index. This
400 * operation check that object supports indexing operations and
401 * installs appropriate dt_index_operations vector on success.
403 * Also probes for features. Operation is successful if all required
404 * features are supported.
406 int (*do_index_try)(const struct lu_env *env,
407 struct dt_object *dt,
408 const struct dt_index_features *feat);
410 * Add nlink of the object
411 * precondition: dt_object_exists(dt);
413 int (*do_declare_ref_add)(const struct lu_env *env,
414 struct dt_object *dt, struct thandle *th);
415 int (*do_ref_add)(const struct lu_env *env,
416 struct dt_object *dt, struct thandle *th);
418 * Del nlink of the object
419 * precondition: dt_object_exists(dt);
421 int (*do_declare_ref_del)(const struct lu_env *env,
422 struct dt_object *dt, struct thandle *th);
423 int (*do_ref_del)(const struct lu_env *env,
424 struct dt_object *dt, struct thandle *th);
426 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
427 struct dt_object *dt,
428 struct lustre_capa *old,
430 int (*do_object_sync)(const struct lu_env *, struct dt_object *);
432 * Get object info of next level. Currently, only get inode from osd.
433 * This is only used by quota b=16542
434 * precondition: dt_object_exists(dt);
436 int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
441 * Per-dt-object operations on "file body".
443 struct dt_body_operations {
445 * precondition: dt_object_exists(dt);
447 ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
448 struct lu_buf *buf, loff_t *pos,
449 struct lustre_capa *capa);
451 * precondition: dt_object_exists(dt);
453 ssize_t (*dbo_declare_write)(const struct lu_env *env,
454 struct dt_object *dt,
455 const loff_t size, loff_t pos,
456 struct thandle *handle);
457 ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
458 const struct lu_buf *buf, loff_t *pos,
459 struct thandle *handle, struct lustre_capa *capa,
462 * methods for zero-copy IO
466 * precondition: dt_object_exists(dt);
470 * > 0 - number of local buffers prepared
472 int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
473 loff_t pos, ssize_t len, struct niobuf_local *lb,
474 int rw, struct lustre_capa *capa);
476 * precondition: dt_object_exists(dt);
478 int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
479 struct niobuf_local *lb, int nr);
481 * precondition: dt_object_exists(dt);
483 int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
484 struct niobuf_local *lb, int nr);
486 * precondition: dt_object_exists(dt);
488 int (*dbo_declare_write_commit)(const struct lu_env *env,
489 struct dt_object *dt,
490 struct niobuf_local *,
491 int, struct thandle *);
493 * precondition: dt_object_exists(dt);
495 int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
496 struct niobuf_local *, int, struct thandle *);
498 * precondition: dt_object_exists(dt);
500 int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
501 struct niobuf_local *lnb, int nr);
502 int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
503 struct ll_user_fiemap *fm);
505 * Punch object's content
506 * precondition: regular object, not index
508 int (*do_declare_punch)(const struct lu_env *, struct dt_object *,
509 __u64, __u64, struct thandle *th);
510 int (*do_punch)(const struct lu_env *env, struct dt_object *dt,
511 __u64 start, __u64 end, struct thandle *th,
512 struct lustre_capa *capa);
516 * Incomplete type of index record.
521 * Incomplete type of index key.
526 * Incomplete type of dt iterator.
531 * Per-dt-object operations on object as index.
533 struct dt_index_operations {
535 * precondition: dt_object_exists(dt);
537 int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
538 struct dt_rec *rec, const struct dt_key *key,
539 struct lustre_capa *capa);
541 * precondition: dt_object_exists(dt);
543 int (*dio_declare_insert)(const struct lu_env *env,
544 struct dt_object *dt,
545 const struct dt_rec *rec,
546 const struct dt_key *key,
547 struct thandle *handle);
548 int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
549 const struct dt_rec *rec, const struct dt_key *key,
550 struct thandle *handle, struct lustre_capa *capa,
553 * precondition: dt_object_exists(dt);
555 int (*dio_declare_delete)(const struct lu_env *env,
556 struct dt_object *dt,
557 const struct dt_key *key,
558 struct thandle *handle);
559 int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
560 const struct dt_key *key, struct thandle *handle,
561 struct lustre_capa *capa);
567 * Allocate and initialize new iterator.
569 * precondition: dt_object_exists(dt);
571 struct dt_it *(*init)(const struct lu_env *env,
572 struct dt_object *dt,
574 struct lustre_capa *capa);
575 void (*fini)(const struct lu_env *env,
577 int (*get)(const struct lu_env *env,
579 const struct dt_key *key);
580 void (*put)(const struct lu_env *env,
582 int (*next)(const struct lu_env *env,
584 struct dt_key *(*key)(const struct lu_env *env,
585 const struct dt_it *di);
586 int (*key_size)(const struct lu_env *env,
587 const struct dt_it *di);
588 int (*rec)(const struct lu_env *env,
589 const struct dt_it *di,
592 __u64 (*store)(const struct lu_env *env,
593 const struct dt_it *di);
594 int (*load)(const struct lu_env *env,
595 const struct dt_it *di, __u64 hash);
596 int (*key_rec)(const struct lu_env *env,
597 const struct dt_it *di, void* key_rec);
602 struct lu_device dd_lu_dev;
603 const struct dt_device_operations *dd_ops;
606 * List of dt_txn_callback (see below). This is not protected in any
607 * way, because callbacks are supposed to be added/deleted only during
608 * single-threaded start-up shut-down procedures.
610 cfs_list_t dd_txn_callbacks;
613 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
614 void dt_device_fini(struct dt_device *dev);
616 static inline int lu_device_is_dt(const struct lu_device *d)
618 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
621 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
623 LASSERT(lu_device_is_dt(l));
624 return container_of0(l, struct dt_device, dd_lu_dev);
628 struct lu_object do_lu;
629 const struct dt_object_operations *do_ops;
630 const struct dt_body_operations *do_body_ops;
631 const struct dt_index_operations *do_index_ops;
634 static inline struct dt_object *lu2dt(struct lu_object *l)
636 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
637 return container_of0(l, struct dt_object, do_lu);
640 int dt_object_init(struct dt_object *obj,
641 struct lu_object_header *h, struct lu_device *d);
643 void dt_object_fini(struct dt_object *obj);
645 static inline int dt_object_exists(const struct dt_object *dt)
647 return lu_object_exists(&dt->do_lu);
651 * This is the general purpose transaction handle.
652 * 1. Transaction Life Cycle
653 * This transaction handle is allocated upon starting a new transaction,
654 * and deallocated after this transaction is committed.
655 * 2. Transaction Nesting
656 * We do _NOT_ support nested transaction. So, every thread should only
657 * have one active transaction, and a transaction only belongs to one
658 * thread. Due to this, transaction handle need no reference count.
659 * 3. Transaction & dt_object locking
660 * dt_object locks should be taken inside transaction.
661 * 4. Transaction & RPC
662 * No RPC request should be issued inside transaction.
665 /** the dt device on which the transactions are executed */
666 struct dt_device *th_dev;
668 /** additional tags (layers can add in declare) */
671 /** context for this transaction, tag is LCT_TX_HANDLE */
672 struct lu_context th_ctx;
674 /** the last operation result in this transaction.
675 * this value is used in recovery */
678 /** whether we need sync commit */
681 /* local transation, no need to inform other layers */
686 * Transaction call-backs.
688 * These are invoked by osd (or underlying transaction engine) when
689 * transaction changes state.
691 * Call-backs are used by upper layers to modify transaction parameters and to
692 * perform some actions on for each transaction state transition. Typical
693 * example is mdt registering call-back to write into last-received file
694 * before each transaction commit.
696 struct dt_txn_callback {
697 int (*dtc_txn_start)(const struct lu_env *env,
698 struct thandle *txn, void *cookie);
699 int (*dtc_txn_stop)(const struct lu_env *env,
700 struct thandle *txn, void *cookie);
701 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
704 cfs_list_t dtc_linkage;
707 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
708 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
710 int dt_txn_hook_start(const struct lu_env *env,
711 struct dt_device *dev, struct thandle *txn);
712 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
713 void dt_txn_hook_commit(struct thandle *txn);
715 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
718 * Callback function used for parsing path.
719 * \see llo_store_resolve
721 typedef int (*dt_entry_func_t)(const struct lu_env *env,
725 #define DT_MAX_PATH 1024
727 int dt_path_parser(const struct lu_env *env,
728 char *local, dt_entry_func_t entry_func,
731 struct dt_object *dt_store_open(const struct lu_env *env,
732 struct dt_device *dt,
734 const char *filename,
737 struct dt_object *dt_locate(const struct lu_env *env,
738 struct dt_device *dev,
739 const struct lu_fid *fid);
741 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
743 void dt_version_set(const struct lu_env *env, struct dt_object *o,
744 dt_obj_version_t version, struct thandle *th);
745 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
748 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
749 struct lu_buf *buf, loff_t *pos);
750 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
751 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
754 static inline struct thandle *dt_trans_create(const struct lu_env *env,
757 LASSERT(d->dd_ops->dt_trans_create);
758 return d->dd_ops->dt_trans_create(env, d);
761 static inline int dt_trans_start(const struct lu_env *env,
762 struct dt_device *d, struct thandle *th)
764 LASSERT(d->dd_ops->dt_trans_start);
765 return d->dd_ops->dt_trans_start(env, d, th);
768 /* for this transaction hooks shouldn't be called */
769 static inline int dt_trans_start_local(const struct lu_env *env,
770 struct dt_device *d, struct thandle *th)
772 LASSERT(d->dd_ops->dt_trans_start);
774 return d->dd_ops->dt_trans_start(env, d, th);
777 static inline int dt_trans_stop(const struct lu_env *env,
778 struct dt_device *d, struct thandle *th)
780 LASSERT(d->dd_ops->dt_trans_stop);
781 return d->dd_ops->dt_trans_stop(env, th);
784 static inline int dt_trans_cb_add(struct thandle *th,
785 struct dt_txn_commit_cb *dcb)
787 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
788 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
793 static inline int dt_declare_record_write(const struct lu_env *env,
794 struct dt_object *dt,
795 int size, loff_t pos,
800 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
802 rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
806 static inline int dt_declare_create(const struct lu_env *env,
807 struct dt_object *dt,
808 struct lu_attr *attr,
809 struct dt_allocation_hint *hint,
810 struct dt_object_format *dof,
815 LASSERT(dt->do_ops->do_declare_create);
816 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
819 static inline int dt_create(const struct lu_env *env,
820 struct dt_object *dt,
821 struct lu_attr *attr,
822 struct dt_allocation_hint *hint,
823 struct dt_object_format *dof,
828 LASSERT(dt->do_ops->do_create);
829 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
832 static inline int dt_declare_destroy(const struct lu_env *env,
833 struct dt_object *dt,
838 LASSERT(dt->do_ops->do_declare_destroy);
839 return dt->do_ops->do_declare_destroy(env, dt, th);
842 static inline int dt_destroy(const struct lu_env *env,
843 struct dt_object *dt,
848 LASSERT(dt->do_ops->do_destroy);
849 return dt->do_ops->do_destroy(env, dt, th);
852 static inline void dt_read_lock(const struct lu_env *env,
853 struct dt_object *dt,
858 LASSERT(dt->do_ops->do_read_lock);
859 dt->do_ops->do_read_lock(env, dt, role);
862 static inline void dt_write_lock(const struct lu_env *env,
863 struct dt_object *dt,
868 LASSERT(dt->do_ops->do_write_lock);
869 dt->do_ops->do_write_lock(env, dt, role);
872 static inline void dt_read_unlock(const struct lu_env *env,
873 struct dt_object *dt)
877 LASSERT(dt->do_ops->do_read_unlock);
878 dt->do_ops->do_read_unlock(env, dt);
881 static inline void dt_write_unlock(const struct lu_env *env,
882 struct dt_object *dt)
886 LASSERT(dt->do_ops->do_write_unlock);
887 dt->do_ops->do_write_unlock(env, dt);
890 static inline int dt_write_locked(const struct lu_env *env,
891 struct dt_object *dt)
895 LASSERT(dt->do_ops->do_write_locked);
896 return dt->do_ops->do_write_locked(env, dt);
899 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
900 struct lu_attr *la, void *arg)
904 LASSERT(dt->do_ops->do_attr_get);
905 return dt->do_ops->do_attr_get(env, dt, la, arg);
908 static inline int dt_declare_attr_set(const struct lu_env *env,
909 struct dt_object *dt,
910 const struct lu_attr *la,
915 LASSERT(dt->do_ops->do_declare_attr_set);
916 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
919 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
920 const struct lu_attr *la, struct thandle *th,
921 struct lustre_capa *capa)
925 LASSERT(dt->do_ops->do_attr_set);
926 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
929 static inline int dt_declare_ref_add(const struct lu_env *env,
930 struct dt_object *dt, struct thandle *th)
934 LASSERT(dt->do_ops->do_declare_ref_add);
935 return dt->do_ops->do_declare_ref_add(env, dt, th);
938 static inline int dt_ref_add(const struct lu_env *env,
939 struct dt_object *dt, struct thandle *th)
943 LASSERT(dt->do_ops->do_ref_add);
944 return dt->do_ops->do_ref_add(env, dt, th);
947 static inline int dt_declare_ref_del(const struct lu_env *env,
948 struct dt_object *dt, struct thandle *th)
952 LASSERT(dt->do_ops->do_declare_ref_del);
953 return dt->do_ops->do_declare_ref_del(env, dt, th);
956 static inline int dt_ref_del(const struct lu_env *env,
957 struct dt_object *dt, struct thandle *th)
961 LASSERT(dt->do_ops->do_ref_del);
962 return dt->do_ops->do_ref_del(env, dt, th);
965 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
966 struct dt_object *dt,
967 struct lustre_capa *old, __u64 opc)
971 LASSERT(dt->do_ops->do_ref_del);
972 return dt->do_ops->do_capa_get(env, dt, old, opc);
975 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
976 struct niobuf_remote *rnb,
977 struct niobuf_local *lnb, int rw,
978 struct lustre_capa *capa)
981 LASSERT(d->do_body_ops);
982 LASSERT(d->do_body_ops->dbo_bufs_get);
983 return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
984 rnb->len, lnb, rw, capa);
987 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
988 struct niobuf_local *lnb, int n)
991 LASSERT(d->do_body_ops);
992 LASSERT(d->do_body_ops->dbo_bufs_put);
993 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
996 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
997 struct niobuf_local *lnb, int n)
1000 LASSERT(d->do_body_ops);
1001 LASSERT(d->do_body_ops->dbo_write_prep);
1002 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1005 static inline int dt_declare_write_commit(const struct lu_env *env,
1006 struct dt_object *d,
1007 struct niobuf_local *lnb,
1008 int n, struct thandle *th)
1010 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1011 LASSERT(th != NULL);
1012 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1016 static inline int dt_write_commit(const struct lu_env *env,
1017 struct dt_object *d, struct niobuf_local *lnb,
1018 int n, struct thandle *th)
1021 LASSERT(d->do_body_ops);
1022 LASSERT(d->do_body_ops->dbo_write_commit);
1023 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1026 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1027 struct niobuf_local *lnb, int n)
1030 LASSERT(d->do_body_ops);
1031 LASSERT(d->do_body_ops->dbo_read_prep);
1032 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1035 static inline int dt_declare_punch(const struct lu_env *env,
1036 struct dt_object *dt, __u64 start,
1037 __u64 end, struct thandle *th)
1040 LASSERT(dt->do_body_ops);
1041 LASSERT(dt->do_body_ops->do_declare_punch);
1042 return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1045 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1046 __u64 start, __u64 end, struct thandle *th,
1047 struct lustre_capa *capa)
1050 LASSERT(dt->do_body_ops);
1051 LASSERT(dt->do_body_ops->do_punch);
1052 return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1055 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1056 struct ll_user_fiemap *fm)
1059 if (d->do_body_ops == NULL)
1061 LASSERT(d->do_body_ops->dbo_fiemap_get);
1062 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1065 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1066 cfs_kstatfs_t *osfs)
1069 LASSERT(dev->dd_ops);
1070 LASSERT(dev->dd_ops->dt_statfs);
1071 return dev->dd_ops->dt_statfs(env, dev, osfs);
1074 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1078 LASSERT(dev->dd_ops);
1079 LASSERT(dev->dd_ops->dt_root_get);
1080 return dev->dd_ops->dt_root_get(env, dev, f);
1083 static inline void dt_conf_get(const struct lu_env *env,
1084 const struct dt_device *dev,
1085 struct dt_device_param *param)
1088 LASSERT(dev->dd_ops);
1089 LASSERT(dev->dd_ops->dt_conf_get);
1090 return dev->dd_ops->dt_conf_get(env, dev, param);
1093 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1096 LASSERT(dev->dd_ops);
1097 LASSERT(dev->dd_ops->dt_sync);
1098 return dev->dd_ops->dt_sync(env, dev);
1101 static inline void dt_ro(const struct lu_env *env, struct dt_device *dev)
1104 LASSERT(dev->dd_ops);
1105 LASSERT(dev->dd_ops->dt_ro);
1106 return dev->dd_ops->dt_ro(env, dev);
1109 static inline int dt_declare_insert(const struct lu_env *env,
1110 struct dt_object *dt,
1111 const struct dt_rec *rec,
1112 const struct dt_key *key,
1116 LASSERT(dt->do_index_ops);
1117 LASSERT(dt->do_index_ops->dio_declare_insert);
1118 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1121 static inline int dt_insert(const struct lu_env *env,
1122 struct dt_object *dt,
1123 const struct dt_rec *rec,
1124 const struct dt_key *key,
1126 struct lustre_capa *capa,
1130 LASSERT(dt->do_index_ops);
1131 LASSERT(dt->do_index_ops->dio_insert);
1132 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1136 static inline int dt_declare_xattr_del(const struct lu_env *env,
1137 struct dt_object *dt,
1142 LASSERT(dt->do_ops);
1143 LASSERT(dt->do_ops->do_declare_xattr_del);
1144 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1147 static inline int dt_xattr_del(const struct lu_env *env,
1148 struct dt_object *dt, const char *name,
1150 struct lustre_capa *capa)
1153 LASSERT(dt->do_ops);
1154 LASSERT(dt->do_ops->do_xattr_del);
1155 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1158 static inline int dt_declare_xattr_set(const struct lu_env *env,
1159 struct dt_object *dt,
1160 const struct lu_buf *buf,
1161 const char *name, int fl,
1165 LASSERT(dt->do_ops);
1166 LASSERT(dt->do_ops->do_declare_xattr_set);
1167 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1170 static inline int dt_xattr_set(const struct lu_env *env,
1171 struct dt_object *dt, const struct lu_buf *buf,
1172 const char *name, int fl, struct thandle *th,
1173 struct lustre_capa *capa)
1176 LASSERT(dt->do_ops);
1177 LASSERT(dt->do_ops->do_xattr_set);
1178 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1181 static inline int dt_xattr_get(const struct lu_env *env,
1182 struct dt_object *dt, struct lu_buf *buf,
1183 const char *name, struct lustre_capa *capa)
1186 LASSERT(dt->do_ops);
1187 LASSERT(dt->do_ops->do_xattr_get);
1188 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1191 static inline int dt_xattr_list(const struct lu_env *env,
1192 struct dt_object *dt, struct lu_buf *buf,
1193 struct lustre_capa *capa)
1196 LASSERT(dt->do_ops);
1197 LASSERT(dt->do_ops->do_xattr_list);
1198 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1201 static inline int dt_declare_delete(const struct lu_env *env,
1202 struct dt_object *dt,
1203 const struct dt_key *key,
1207 LASSERT(dt->do_index_ops);
1208 LASSERT(dt->do_index_ops->dio_declare_delete);
1209 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1212 static inline int dt_delete(const struct lu_env *env,
1213 struct dt_object *dt,
1214 const struct dt_key *key,
1216 struct lustre_capa *capa)
1219 LASSERT(dt->do_index_ops);
1220 LASSERT(dt->do_index_ops->dio_delete);
1221 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1224 static inline int dt_commit_async(const struct lu_env *env,
1225 struct dt_device *dev)
1228 LASSERT(dev->dd_ops);
1229 LASSERT(dev->dd_ops->dt_commit_async);
1230 return dev->dd_ops->dt_commit_async(env, dev);
1233 static inline int dt_lookup(const struct lu_env *env,
1234 struct dt_object *dt,
1236 const struct dt_key *key,
1237 struct lustre_capa *capa)
1242 LASSERT(dt->do_index_ops);
1243 LASSERT(dt->do_index_ops->dio_lookup);
1245 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1252 #endif /* __LUSTRE_DT_OBJECT_H */