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.
32 * Copyright (c) 2011, 2012, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
39 #ifndef __LUSTRE_DT_OBJECT_H
40 #define __LUSTRE_DT_OBJECT_H
43 * Sub-class of lu_object with methods common for "data" objects in OST stack.
45 * Data objects behave like regular files: you can read/write them, get and
46 * set their attributes. Implementation of dt interface is supposed to
47 * implement some form of garbage collection, normally reference counting
50 * Examples: osd (lustre/osd) is an implementation of dt interface.
56 * super-class definitions.
58 #include <lu_object.h>
60 #include <libcfs/libcfs.h>
63 struct proc_dir_entry;
69 struct dt_index_features;
75 MNTOPT_USERXATTR = 0x00000001,
76 MNTOPT_ACL = 0x00000002,
79 struct dt_device_param {
80 unsigned ddp_max_name_len;
81 unsigned ddp_max_nlink;
82 unsigned ddp_block_shift;
84 unsigned ddp_max_ea_size;
85 void *ddp_mnt; /* XXX: old code can retrieve mnt -bzzz */
87 unsigned long long ddp_maxbytes;
88 /* percentage of available space to reserve for grant error margin */
89 int ddp_grant_reserved;
90 /* per-inode space consumption */
92 /* per-fragment grant overhead to be used by client for grant
98 * Per-transaction commit callback function
100 struct dt_txn_commit_cb;
101 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
102 struct dt_txn_commit_cb *cb, int err);
104 * Special per-transaction callback for cases when just commit callback
105 * is needed and per-device callback are not convenient to use
107 struct dt_txn_commit_cb {
108 cfs_list_t dcb_linkage;
113 * Operations on dt device.
115 struct dt_device_operations {
117 * Return device-wide statistics.
119 int (*dt_statfs)(const struct lu_env *env,
120 struct dt_device *dev, struct obd_statfs *osfs);
122 * Create transaction, described by \a param.
124 struct thandle *(*dt_trans_create)(const struct lu_env *env,
125 struct dt_device *dev);
127 * Start transaction, described by \a param.
129 int (*dt_trans_start)(const struct lu_env *env,
130 struct dt_device *dev, struct thandle *th);
132 * Finish previously started transaction.
134 int (*dt_trans_stop)(const struct lu_env *env,
137 * Add commit callback to the transaction.
139 int (*dt_trans_cb_add)(struct thandle *th,
140 struct dt_txn_commit_cb *dcb);
142 * Return fid of root index object.
144 int (*dt_root_get)(const struct lu_env *env,
145 struct dt_device *dev, struct lu_fid *f);
147 * Return device configuration data.
149 void (*dt_conf_get)(const struct lu_env *env,
150 const struct dt_device *dev,
151 struct dt_device_param *param);
153 * handling device state, mostly for tests
155 int (*dt_sync)(const struct lu_env *env, struct dt_device *dev);
156 int (*dt_ro)(const struct lu_env *env, struct dt_device *dev);
158 * Start a transaction commit asynchronously
160 * \param env environment
161 * \param dev dt_device to start commit on
163 * \return 0 success, negative value if error
165 int (*dt_commit_async)(const struct lu_env *env,
166 struct dt_device *dev);
168 * Initialize capability context.
170 int (*dt_init_capa_ctxt)(const struct lu_env *env,
171 struct dt_device *dev,
172 int mode, unsigned long timeout,
173 __u32 alg, struct lustre_capa_key *keys);
175 * Initialize quota context.
177 void (*dt_init_quota_ctxt)(const struct lu_env *env,
178 struct dt_device *dev,
179 struct dt_quota_ctxt *ctxt, void *data);
182 struct dt_index_features {
183 /** required feature flags from enum dt_index_flags */
185 /** minimal required key size */
186 size_t dif_keysize_min;
187 /** maximal required key size, 0 if no limit */
188 size_t dif_keysize_max;
189 /** minimal required record size */
190 size_t dif_recsize_min;
191 /** maximal required record size, 0 if no limit */
192 size_t dif_recsize_max;
193 /** pointer size for record */
197 enum dt_index_flags {
198 /** index supports variable sized keys */
199 DT_IND_VARKEY = 1 << 0,
200 /** index supports variable sized records */
201 DT_IND_VARREC = 1 << 1,
202 /** index can be modified */
203 DT_IND_UPDATE = 1 << 2,
204 /** index supports records with non-unique (duplicate) keys */
205 DT_IND_NONUNQ = 1 << 3
209 * Features, required from index to support file system directories (mapping
212 extern const struct dt_index_features dt_directory_features;
215 * This is a general purpose dt allocation hint.
216 * It now contains the parent object.
217 * It can contain any allocation hint in the future.
219 struct dt_allocation_hint {
220 struct dt_object *dah_parent;
225 * object type specifier.
228 enum dt_format_type {
233 /** for special index */
235 /** for symbolic link */
240 * object format specifier.
242 struct dt_object_format {
243 /** type for dt object */
244 enum dt_format_type dof_type;
253 * special index need feature as parameter to create
257 const struct dt_index_features *di_feat;
262 enum dt_format_type dt_mode_to_dft(__u32 mode);
264 typedef __u64 dt_obj_version_t;
267 * Per-dt-object operations.
269 struct dt_object_operations {
270 void (*do_read_lock)(const struct lu_env *env,
271 struct dt_object *dt, unsigned role);
272 void (*do_write_lock)(const struct lu_env *env,
273 struct dt_object *dt, unsigned role);
274 void (*do_read_unlock)(const struct lu_env *env,
275 struct dt_object *dt);
276 void (*do_write_unlock)(const struct lu_env *env,
277 struct dt_object *dt);
278 int (*do_write_locked)(const struct lu_env *env,
279 struct dt_object *dt);
281 * Note: following ->do_{x,}attr_{set,get}() operations are very
282 * similar to ->moo_{x,}attr_{set,get}() operations in struct
283 * md_object_operations (see md_object.h). These operations are not in
284 * lu_object_operations, because ->do_{x,}attr_set() versions take
285 * transaction handle as an argument (this transaction is started by
286 * caller). We might factor ->do_{x,}attr_get() into
287 * lu_object_operations, but that would break existing symmetry.
291 * Return standard attributes.
293 * precondition: lu_object_exists(&dt->do_lu);
295 int (*do_attr_get)(const struct lu_env *env,
296 struct dt_object *dt, struct lu_attr *attr,
297 struct lustre_capa *capa);
299 * Set standard attributes.
301 * precondition: dt_object_exists(dt);
303 int (*do_declare_attr_set)(const struct lu_env *env,
304 struct dt_object *dt,
305 const struct lu_attr *attr,
306 struct thandle *handle);
307 int (*do_attr_set)(const struct lu_env *env,
308 struct dt_object *dt,
309 const struct lu_attr *attr,
310 struct thandle *handle,
311 struct lustre_capa *capa);
313 * Return a value of an extended attribute.
315 * precondition: dt_object_exists(dt);
317 int (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
318 struct lu_buf *buf, const char *name,
319 struct lustre_capa *capa);
321 * Set value of an extended attribute.
323 * \a fl - flags from enum lu_xattr_flags
325 * precondition: dt_object_exists(dt);
327 int (*do_declare_xattr_set)(const struct lu_env *env,
328 struct dt_object *dt,
329 const struct lu_buf *buf,
330 const char *name, int fl,
331 struct thandle *handle);
332 int (*do_xattr_set)(const struct lu_env *env,
333 struct dt_object *dt, const struct lu_buf *buf,
334 const char *name, int fl, struct thandle *handle,
335 struct lustre_capa *capa);
337 * Delete existing extended attribute.
339 * precondition: dt_object_exists(dt);
341 int (*do_declare_xattr_del)(const struct lu_env *env,
342 struct dt_object *dt,
343 const char *name, struct thandle *handle);
344 int (*do_xattr_del)(const struct lu_env *env,
345 struct dt_object *dt,
346 const char *name, struct thandle *handle,
347 struct lustre_capa *capa);
349 * Place list of existing extended attributes into \a buf (which has
352 * precondition: dt_object_exists(dt);
354 int (*do_xattr_list)(const struct lu_env *env,
355 struct dt_object *dt, struct lu_buf *buf,
356 struct lustre_capa *capa);
358 * Init allocation hint using parent object and child mode.
359 * (1) The \a parent might be NULL if this is a partial creation for
361 * (2) The type of child is in \a child_mode.
362 * (3) The result hint is stored in \a ah;
364 void (*do_ah_init)(const struct lu_env *env,
365 struct dt_allocation_hint *ah,
366 struct dt_object *parent,
367 cfs_umode_t child_mode);
369 * Create new object on this device.
371 * precondition: !dt_object_exists(dt);
372 * postcondition: ergo(result == 0, dt_object_exists(dt));
374 int (*do_declare_create)(const struct lu_env *env,
375 struct dt_object *dt,
376 struct lu_attr *attr,
377 struct dt_allocation_hint *hint,
378 struct dt_object_format *dof,
380 int (*do_create)(const struct lu_env *env, struct dt_object *dt,
381 struct lu_attr *attr,
382 struct dt_allocation_hint *hint,
383 struct dt_object_format *dof,
387 Destroy object on this device
388 * precondition: !dt_object_exists(dt);
389 * postcondition: ergo(result == 0, dt_object_exists(dt));
391 int (*do_declare_destroy)(const struct lu_env *env,
392 struct dt_object *dt,
394 int (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
398 * Announce that this object is going to be used as an index. This
399 * operation check that object supports indexing operations and
400 * installs appropriate dt_index_operations vector on success.
402 * Also probes for features. Operation is successful if all required
403 * features are supported.
405 int (*do_index_try)(const struct lu_env *env,
406 struct dt_object *dt,
407 const struct dt_index_features *feat);
409 * Add nlink of the object
410 * precondition: dt_object_exists(dt);
412 int (*do_declare_ref_add)(const struct lu_env *env,
413 struct dt_object *dt, struct thandle *th);
414 int (*do_ref_add)(const struct lu_env *env,
415 struct dt_object *dt, struct thandle *th);
417 * Del nlink of the object
418 * precondition: dt_object_exists(dt);
420 int (*do_declare_ref_del)(const struct lu_env *env,
421 struct dt_object *dt, struct thandle *th);
422 int (*do_ref_del)(const struct lu_env *env,
423 struct dt_object *dt, struct thandle *th);
425 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
426 struct dt_object *dt,
427 struct lustre_capa *old,
429 int (*do_object_sync)(const struct lu_env *, struct dt_object *);
431 * Get object info of next level. Currently, only get inode from osd.
432 * This is only used by quota b=16542
433 * precondition: dt_object_exists(dt);
435 int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
440 * Per-dt-object operations on "file body".
442 struct dt_body_operations {
444 * precondition: dt_object_exists(dt);
446 ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
447 struct lu_buf *buf, loff_t *pos,
448 struct lustre_capa *capa);
450 * precondition: dt_object_exists(dt);
452 ssize_t (*dbo_declare_write)(const struct lu_env *env,
453 struct dt_object *dt,
454 const loff_t size, loff_t pos,
455 struct thandle *handle);
456 ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
457 const struct lu_buf *buf, loff_t *pos,
458 struct thandle *handle, struct lustre_capa *capa,
461 * methods for zero-copy IO
465 * precondition: dt_object_exists(dt);
469 * > 0 - number of local buffers prepared
471 int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
472 loff_t pos, ssize_t len, struct niobuf_local *lb,
473 int rw, struct lustre_capa *capa);
475 * precondition: dt_object_exists(dt);
477 int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
478 struct niobuf_local *lb, int nr);
480 * precondition: dt_object_exists(dt);
482 int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
483 struct niobuf_local *lb, int nr);
485 * precondition: dt_object_exists(dt);
487 int (*dbo_declare_write_commit)(const struct lu_env *env,
488 struct dt_object *dt,
489 struct niobuf_local *,
490 int, struct thandle *);
492 * precondition: dt_object_exists(dt);
494 int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
495 struct niobuf_local *, int, struct thandle *);
497 * precondition: dt_object_exists(dt);
499 int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
500 struct niobuf_local *lnb, int nr);
501 int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
502 struct ll_user_fiemap *fm);
504 * Punch object's content
505 * precondition: regular object, not index
507 int (*do_declare_punch)(const struct lu_env *, struct dt_object *,
508 __u64, __u64, struct thandle *th);
509 int (*do_punch)(const struct lu_env *env, struct dt_object *dt,
510 __u64 start, __u64 end, struct thandle *th,
511 struct lustre_capa *capa);
515 * Incomplete type of index record.
520 * Incomplete type of index key.
525 * Incomplete type of dt iterator.
530 * Per-dt-object operations on object as index.
532 struct dt_index_operations {
534 * precondition: dt_object_exists(dt);
536 int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
537 struct dt_rec *rec, const struct dt_key *key,
538 struct lustre_capa *capa);
540 * precondition: dt_object_exists(dt);
542 int (*dio_declare_insert)(const struct lu_env *env,
543 struct dt_object *dt,
544 const struct dt_rec *rec,
545 const struct dt_key *key,
546 struct thandle *handle);
547 int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
548 const struct dt_rec *rec, const struct dt_key *key,
549 struct thandle *handle, struct lustre_capa *capa,
552 * precondition: dt_object_exists(dt);
554 int (*dio_declare_delete)(const struct lu_env *env,
555 struct dt_object *dt,
556 const struct dt_key *key,
557 struct thandle *handle);
558 int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
559 const struct dt_key *key, struct thandle *handle,
560 struct lustre_capa *capa);
566 * Allocate and initialize new iterator.
568 * precondition: dt_object_exists(dt);
570 struct dt_it *(*init)(const struct lu_env *env,
571 struct dt_object *dt,
573 struct lustre_capa *capa);
574 void (*fini)(const struct lu_env *env,
576 int (*get)(const struct lu_env *env,
578 const struct dt_key *key);
579 void (*put)(const struct lu_env *env,
581 int (*next)(const struct lu_env *env,
583 struct dt_key *(*key)(const struct lu_env *env,
584 const struct dt_it *di);
585 int (*key_size)(const struct lu_env *env,
586 const struct dt_it *di);
587 int (*rec)(const struct lu_env *env,
588 const struct dt_it *di,
591 __u64 (*store)(const struct lu_env *env,
592 const struct dt_it *di);
593 int (*load)(const struct lu_env *env,
594 const struct dt_it *di, __u64 hash);
595 int (*key_rec)(const struct lu_env *env,
596 const struct dt_it *di, void* key_rec);
601 struct lu_device dd_lu_dev;
602 const struct dt_device_operations *dd_ops;
605 * List of dt_txn_callback (see below). This is not protected in any
606 * way, because callbacks are supposed to be added/deleted only during
607 * single-threaded start-up shut-down procedures.
609 cfs_list_t dd_txn_callbacks;
612 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
613 void dt_device_fini(struct dt_device *dev);
615 static inline int lu_device_is_dt(const struct lu_device *d)
617 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
620 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
622 LASSERT(lu_device_is_dt(l));
623 return container_of0(l, struct dt_device, dd_lu_dev);
627 struct lu_object do_lu;
628 const struct dt_object_operations *do_ops;
629 const struct dt_body_operations *do_body_ops;
630 const struct dt_index_operations *do_index_ops;
633 static inline struct dt_object *lu2dt(struct lu_object *l)
635 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
636 return container_of0(l, struct dt_object, do_lu);
639 int dt_object_init(struct dt_object *obj,
640 struct lu_object_header *h, struct lu_device *d);
642 void dt_object_fini(struct dt_object *obj);
644 static inline int dt_object_exists(const struct dt_object *dt)
646 return lu_object_exists(&dt->do_lu);
650 * This is the general purpose transaction handle.
651 * 1. Transaction Life Cycle
652 * This transaction handle is allocated upon starting a new transaction,
653 * and deallocated after this transaction is committed.
654 * 2. Transaction Nesting
655 * We do _NOT_ support nested transaction. So, every thread should only
656 * have one active transaction, and a transaction only belongs to one
657 * thread. Due to this, transaction handle need no reference count.
658 * 3. Transaction & dt_object locking
659 * dt_object locks should be taken inside transaction.
660 * 4. Transaction & RPC
661 * No RPC request should be issued inside transaction.
664 /** the dt device on which the transactions are executed */
665 struct dt_device *th_dev;
667 /** additional tags (layers can add in declare) */
670 /** context for this transaction, tag is LCT_TX_HANDLE */
671 struct lu_context th_ctx;
673 /** the last operation result in this transaction.
674 * this value is used in recovery */
677 /** whether we need sync commit */
680 /* local transation, no need to inform other layers */
685 * Transaction call-backs.
687 * These are invoked by osd (or underlying transaction engine) when
688 * transaction changes state.
690 * Call-backs are used by upper layers to modify transaction parameters and to
691 * perform some actions on for each transaction state transition. Typical
692 * example is mdt registering call-back to write into last-received file
693 * before each transaction commit.
695 struct dt_txn_callback {
696 int (*dtc_txn_start)(const struct lu_env *env,
697 struct thandle *txn, void *cookie);
698 int (*dtc_txn_stop)(const struct lu_env *env,
699 struct thandle *txn, void *cookie);
700 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
703 cfs_list_t dtc_linkage;
706 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
707 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
709 int dt_txn_hook_start(const struct lu_env *env,
710 struct dt_device *dev, struct thandle *txn);
711 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
712 void dt_txn_hook_commit(struct thandle *txn);
714 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
717 * Callback function used for parsing path.
718 * \see llo_store_resolve
720 typedef int (*dt_entry_func_t)(const struct lu_env *env,
724 #define DT_MAX_PATH 1024
726 int dt_path_parser(const struct lu_env *env,
727 char *local, dt_entry_func_t entry_func,
730 struct dt_object *dt_store_open(const struct lu_env *env,
731 struct dt_device *dt,
733 const char *filename,
736 struct dt_object *dt_locate(const struct lu_env *env,
737 struct dt_device *dev,
738 const struct lu_fid *fid);
740 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
742 void dt_version_set(const struct lu_env *env, struct dt_object *o,
743 dt_obj_version_t version, struct thandle *th);
744 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
747 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
748 struct lu_buf *buf, loff_t *pos);
749 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
750 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
753 static inline struct thandle *dt_trans_create(const struct lu_env *env,
756 LASSERT(d->dd_ops->dt_trans_create);
757 return d->dd_ops->dt_trans_create(env, d);
760 static inline int dt_trans_start(const struct lu_env *env,
761 struct dt_device *d, struct thandle *th)
763 LASSERT(d->dd_ops->dt_trans_start);
764 return d->dd_ops->dt_trans_start(env, d, th);
767 /* for this transaction hooks shouldn't be called */
768 static inline int dt_trans_start_local(const struct lu_env *env,
769 struct dt_device *d, struct thandle *th)
771 LASSERT(d->dd_ops->dt_trans_start);
773 return d->dd_ops->dt_trans_start(env, d, th);
776 static inline int dt_trans_stop(const struct lu_env *env,
777 struct dt_device *d, struct thandle *th)
779 LASSERT(d->dd_ops->dt_trans_stop);
780 return d->dd_ops->dt_trans_stop(env, th);
783 static inline int dt_trans_cb_add(struct thandle *th,
784 struct dt_txn_commit_cb *dcb)
786 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
787 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
792 static inline int dt_declare_record_write(const struct lu_env *env,
793 struct dt_object *dt,
794 int size, loff_t pos,
799 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
801 rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
805 static inline int dt_declare_create(const struct lu_env *env,
806 struct dt_object *dt,
807 struct lu_attr *attr,
808 struct dt_allocation_hint *hint,
809 struct dt_object_format *dof,
814 LASSERT(dt->do_ops->do_declare_create);
815 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
818 static inline int dt_create(const struct lu_env *env,
819 struct dt_object *dt,
820 struct lu_attr *attr,
821 struct dt_allocation_hint *hint,
822 struct dt_object_format *dof,
827 LASSERT(dt->do_ops->do_create);
828 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
831 static inline int dt_declare_destroy(const struct lu_env *env,
832 struct dt_object *dt,
837 LASSERT(dt->do_ops->do_declare_destroy);
838 return dt->do_ops->do_declare_destroy(env, dt, th);
841 static inline int dt_destroy(const struct lu_env *env,
842 struct dt_object *dt,
847 LASSERT(dt->do_ops->do_destroy);
848 return dt->do_ops->do_destroy(env, dt, th);
851 static inline void dt_read_lock(const struct lu_env *env,
852 struct dt_object *dt,
857 LASSERT(dt->do_ops->do_read_lock);
858 dt->do_ops->do_read_lock(env, dt, role);
861 static inline void dt_write_lock(const struct lu_env *env,
862 struct dt_object *dt,
867 LASSERT(dt->do_ops->do_write_lock);
868 dt->do_ops->do_write_lock(env, dt, role);
871 static inline void dt_read_unlock(const struct lu_env *env,
872 struct dt_object *dt)
876 LASSERT(dt->do_ops->do_read_unlock);
877 dt->do_ops->do_read_unlock(env, dt);
880 static inline void dt_write_unlock(const struct lu_env *env,
881 struct dt_object *dt)
885 LASSERT(dt->do_ops->do_write_unlock);
886 dt->do_ops->do_write_unlock(env, dt);
889 static inline int dt_write_locked(const struct lu_env *env,
890 struct dt_object *dt)
894 LASSERT(dt->do_ops->do_write_locked);
895 return dt->do_ops->do_write_locked(env, dt);
898 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
899 struct lu_attr *la, void *arg)
903 LASSERT(dt->do_ops->do_attr_get);
904 return dt->do_ops->do_attr_get(env, dt, la, arg);
907 static inline int dt_declare_attr_set(const struct lu_env *env,
908 struct dt_object *dt,
909 const struct lu_attr *la,
914 LASSERT(dt->do_ops->do_declare_attr_set);
915 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
918 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
919 const struct lu_attr *la, struct thandle *th,
920 struct lustre_capa *capa)
924 LASSERT(dt->do_ops->do_attr_set);
925 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
928 static inline int dt_declare_ref_add(const struct lu_env *env,
929 struct dt_object *dt, struct thandle *th)
933 LASSERT(dt->do_ops->do_declare_ref_add);
934 return dt->do_ops->do_declare_ref_add(env, dt, th);
937 static inline int dt_ref_add(const struct lu_env *env,
938 struct dt_object *dt, struct thandle *th)
942 LASSERT(dt->do_ops->do_ref_add);
943 return dt->do_ops->do_ref_add(env, dt, th);
946 static inline int dt_declare_ref_del(const struct lu_env *env,
947 struct dt_object *dt, struct thandle *th)
951 LASSERT(dt->do_ops->do_declare_ref_del);
952 return dt->do_ops->do_declare_ref_del(env, dt, th);
955 static inline int dt_ref_del(const struct lu_env *env,
956 struct dt_object *dt, struct thandle *th)
960 LASSERT(dt->do_ops->do_ref_del);
961 return dt->do_ops->do_ref_del(env, dt, th);
964 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
965 struct dt_object *dt,
966 struct lustre_capa *old, __u64 opc)
970 LASSERT(dt->do_ops->do_ref_del);
971 return dt->do_ops->do_capa_get(env, dt, old, opc);
974 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
975 struct niobuf_remote *rnb,
976 struct niobuf_local *lnb, int rw,
977 struct lustre_capa *capa)
980 LASSERT(d->do_body_ops);
981 LASSERT(d->do_body_ops->dbo_bufs_get);
982 return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
983 rnb->len, lnb, rw, capa);
986 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
987 struct niobuf_local *lnb, int n)
990 LASSERT(d->do_body_ops);
991 LASSERT(d->do_body_ops->dbo_bufs_put);
992 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
995 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
996 struct niobuf_local *lnb, int n)
999 LASSERT(d->do_body_ops);
1000 LASSERT(d->do_body_ops->dbo_write_prep);
1001 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1004 static inline int dt_declare_write_commit(const struct lu_env *env,
1005 struct dt_object *d,
1006 struct niobuf_local *lnb,
1007 int n, struct thandle *th)
1009 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1010 LASSERT(th != NULL);
1011 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1015 static inline int dt_write_commit(const struct lu_env *env,
1016 struct dt_object *d, struct niobuf_local *lnb,
1017 int n, struct thandle *th)
1020 LASSERT(d->do_body_ops);
1021 LASSERT(d->do_body_ops->dbo_write_commit);
1022 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1025 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1026 struct niobuf_local *lnb, int n)
1029 LASSERT(d->do_body_ops);
1030 LASSERT(d->do_body_ops->dbo_read_prep);
1031 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1034 static inline int dt_declare_punch(const struct lu_env *env,
1035 struct dt_object *dt, __u64 start,
1036 __u64 end, struct thandle *th)
1039 LASSERT(dt->do_body_ops);
1040 LASSERT(dt->do_body_ops->do_declare_punch);
1041 return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1044 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1045 __u64 start, __u64 end, struct thandle *th,
1046 struct lustre_capa *capa)
1049 LASSERT(dt->do_body_ops);
1050 LASSERT(dt->do_body_ops->do_punch);
1051 return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1054 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1055 struct ll_user_fiemap *fm)
1058 if (d->do_body_ops == NULL)
1060 LASSERT(d->do_body_ops->dbo_fiemap_get);
1061 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1064 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1065 struct obd_statfs *osfs)
1068 LASSERT(dev->dd_ops);
1069 LASSERT(dev->dd_ops->dt_statfs);
1070 return dev->dd_ops->dt_statfs(env, dev, osfs);
1073 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1077 LASSERT(dev->dd_ops);
1078 LASSERT(dev->dd_ops->dt_root_get);
1079 return dev->dd_ops->dt_root_get(env, dev, f);
1082 static inline void dt_conf_get(const struct lu_env *env,
1083 const struct dt_device *dev,
1084 struct dt_device_param *param)
1087 LASSERT(dev->dd_ops);
1088 LASSERT(dev->dd_ops->dt_conf_get);
1089 return dev->dd_ops->dt_conf_get(env, dev, param);
1092 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1095 LASSERT(dev->dd_ops);
1096 LASSERT(dev->dd_ops->dt_sync);
1097 return dev->dd_ops->dt_sync(env, dev);
1100 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1103 LASSERT(dev->dd_ops);
1104 LASSERT(dev->dd_ops->dt_ro);
1105 return dev->dd_ops->dt_ro(env, dev);
1108 static inline int dt_declare_insert(const struct lu_env *env,
1109 struct dt_object *dt,
1110 const struct dt_rec *rec,
1111 const struct dt_key *key,
1115 LASSERT(dt->do_index_ops);
1116 LASSERT(dt->do_index_ops->dio_declare_insert);
1117 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1120 static inline int dt_insert(const struct lu_env *env,
1121 struct dt_object *dt,
1122 const struct dt_rec *rec,
1123 const struct dt_key *key,
1125 struct lustre_capa *capa,
1129 LASSERT(dt->do_index_ops);
1130 LASSERT(dt->do_index_ops->dio_insert);
1131 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1135 static inline int dt_declare_xattr_del(const struct lu_env *env,
1136 struct dt_object *dt,
1141 LASSERT(dt->do_ops);
1142 LASSERT(dt->do_ops->do_declare_xattr_del);
1143 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1146 static inline int dt_xattr_del(const struct lu_env *env,
1147 struct dt_object *dt, const char *name,
1149 struct lustre_capa *capa)
1152 LASSERT(dt->do_ops);
1153 LASSERT(dt->do_ops->do_xattr_del);
1154 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1157 static inline int dt_declare_xattr_set(const struct lu_env *env,
1158 struct dt_object *dt,
1159 const struct lu_buf *buf,
1160 const char *name, int fl,
1164 LASSERT(dt->do_ops);
1165 LASSERT(dt->do_ops->do_declare_xattr_set);
1166 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1169 static inline int dt_xattr_set(const struct lu_env *env,
1170 struct dt_object *dt, const struct lu_buf *buf,
1171 const char *name, int fl, struct thandle *th,
1172 struct lustre_capa *capa)
1175 LASSERT(dt->do_ops);
1176 LASSERT(dt->do_ops->do_xattr_set);
1177 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1180 static inline int dt_xattr_get(const struct lu_env *env,
1181 struct dt_object *dt, struct lu_buf *buf,
1182 const char *name, struct lustre_capa *capa)
1185 LASSERT(dt->do_ops);
1186 LASSERT(dt->do_ops->do_xattr_get);
1187 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1190 static inline int dt_xattr_list(const struct lu_env *env,
1191 struct dt_object *dt, struct lu_buf *buf,
1192 struct lustre_capa *capa)
1195 LASSERT(dt->do_ops);
1196 LASSERT(dt->do_ops->do_xattr_list);
1197 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1200 static inline int dt_declare_delete(const struct lu_env *env,
1201 struct dt_object *dt,
1202 const struct dt_key *key,
1206 LASSERT(dt->do_index_ops);
1207 LASSERT(dt->do_index_ops->dio_declare_delete);
1208 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1211 static inline int dt_delete(const struct lu_env *env,
1212 struct dt_object *dt,
1213 const struct dt_key *key,
1215 struct lustre_capa *capa)
1218 LASSERT(dt->do_index_ops);
1219 LASSERT(dt->do_index_ops->dio_delete);
1220 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1223 static inline int dt_commit_async(const struct lu_env *env,
1224 struct dt_device *dev)
1227 LASSERT(dev->dd_ops);
1228 LASSERT(dev->dd_ops->dt_commit_async);
1229 return dev->dd_ops->dt_commit_async(env, dev);
1232 static inline int dt_lookup(const struct lu_env *env,
1233 struct dt_object *dt,
1235 const struct dt_key *key,
1236 struct lustre_capa *capa)
1241 LASSERT(dt->do_index_ops);
1242 LASSERT(dt->do_index_ops->dio_lookup);
1244 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1251 #endif /* __LUSTRE_DT_OBJECT_H */