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;
218 /* index features supported by the accounting objects */
219 extern const struct dt_index_features dt_acct_features;
222 * This is a general purpose dt allocation hint.
223 * It now contains the parent object.
224 * It can contain any allocation hint in the future.
226 struct dt_allocation_hint {
227 struct dt_object *dah_parent;
232 * object type specifier.
235 enum dt_format_type {
240 /** for special index */
242 /** for symbolic link */
247 * object format specifier.
249 struct dt_object_format {
250 /** type for dt object */
251 enum dt_format_type dof_type;
260 * special index need feature as parameter to create
264 const struct dt_index_features *di_feat;
269 enum dt_format_type dt_mode_to_dft(__u32 mode);
271 typedef __u64 dt_obj_version_t;
274 * Per-dt-object operations.
276 struct dt_object_operations {
277 void (*do_read_lock)(const struct lu_env *env,
278 struct dt_object *dt, unsigned role);
279 void (*do_write_lock)(const struct lu_env *env,
280 struct dt_object *dt, unsigned role);
281 void (*do_read_unlock)(const struct lu_env *env,
282 struct dt_object *dt);
283 void (*do_write_unlock)(const struct lu_env *env,
284 struct dt_object *dt);
285 int (*do_write_locked)(const struct lu_env *env,
286 struct dt_object *dt);
288 * Note: following ->do_{x,}attr_{set,get}() operations are very
289 * similar to ->moo_{x,}attr_{set,get}() operations in struct
290 * md_object_operations (see md_object.h). These operations are not in
291 * lu_object_operations, because ->do_{x,}attr_set() versions take
292 * transaction handle as an argument (this transaction is started by
293 * caller). We might factor ->do_{x,}attr_get() into
294 * lu_object_operations, but that would break existing symmetry.
298 * Return standard attributes.
300 * precondition: lu_object_exists(&dt->do_lu);
302 int (*do_attr_get)(const struct lu_env *env,
303 struct dt_object *dt, struct lu_attr *attr,
304 struct lustre_capa *capa);
306 * Set standard attributes.
308 * precondition: dt_object_exists(dt);
310 int (*do_declare_attr_set)(const struct lu_env *env,
311 struct dt_object *dt,
312 const struct lu_attr *attr,
313 struct thandle *handle);
314 int (*do_attr_set)(const struct lu_env *env,
315 struct dt_object *dt,
316 const struct lu_attr *attr,
317 struct thandle *handle,
318 struct lustre_capa *capa);
320 * Return a value of an extended attribute.
322 * precondition: dt_object_exists(dt);
324 int (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
325 struct lu_buf *buf, const char *name,
326 struct lustre_capa *capa);
328 * Set value of an extended attribute.
330 * \a fl - flags from enum lu_xattr_flags
332 * precondition: dt_object_exists(dt);
334 int (*do_declare_xattr_set)(const struct lu_env *env,
335 struct dt_object *dt,
336 const struct lu_buf *buf,
337 const char *name, int fl,
338 struct thandle *handle);
339 int (*do_xattr_set)(const struct lu_env *env,
340 struct dt_object *dt, const struct lu_buf *buf,
341 const char *name, int fl, struct thandle *handle,
342 struct lustre_capa *capa);
344 * Delete existing extended attribute.
346 * precondition: dt_object_exists(dt);
348 int (*do_declare_xattr_del)(const struct lu_env *env,
349 struct dt_object *dt,
350 const char *name, struct thandle *handle);
351 int (*do_xattr_del)(const struct lu_env *env,
352 struct dt_object *dt,
353 const char *name, struct thandle *handle,
354 struct lustre_capa *capa);
356 * Place list of existing extended attributes into \a buf (which has
359 * precondition: dt_object_exists(dt);
361 int (*do_xattr_list)(const struct lu_env *env,
362 struct dt_object *dt, struct lu_buf *buf,
363 struct lustre_capa *capa);
365 * Init allocation hint using parent object and child mode.
366 * (1) The \a parent might be NULL if this is a partial creation for
368 * (2) The type of child is in \a child_mode.
369 * (3) The result hint is stored in \a ah;
371 void (*do_ah_init)(const struct lu_env *env,
372 struct dt_allocation_hint *ah,
373 struct dt_object *parent,
374 cfs_umode_t child_mode);
376 * Create new object on this device.
378 * precondition: !dt_object_exists(dt);
379 * postcondition: ergo(result == 0, dt_object_exists(dt));
381 int (*do_declare_create)(const struct lu_env *env,
382 struct dt_object *dt,
383 struct lu_attr *attr,
384 struct dt_allocation_hint *hint,
385 struct dt_object_format *dof,
387 int (*do_create)(const struct lu_env *env, struct dt_object *dt,
388 struct lu_attr *attr,
389 struct dt_allocation_hint *hint,
390 struct dt_object_format *dof,
394 Destroy object on this device
395 * precondition: !dt_object_exists(dt);
396 * postcondition: ergo(result == 0, dt_object_exists(dt));
398 int (*do_declare_destroy)(const struct lu_env *env,
399 struct dt_object *dt,
401 int (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
405 * Announce that this object is going to be used as an index. This
406 * operation check that object supports indexing operations and
407 * installs appropriate dt_index_operations vector on success.
409 * Also probes for features. Operation is successful if all required
410 * features are supported.
412 int (*do_index_try)(const struct lu_env *env,
413 struct dt_object *dt,
414 const struct dt_index_features *feat);
416 * Add nlink of the object
417 * precondition: dt_object_exists(dt);
419 int (*do_declare_ref_add)(const struct lu_env *env,
420 struct dt_object *dt, struct thandle *th);
421 int (*do_ref_add)(const struct lu_env *env,
422 struct dt_object *dt, struct thandle *th);
424 * Del nlink of the object
425 * precondition: dt_object_exists(dt);
427 int (*do_declare_ref_del)(const struct lu_env *env,
428 struct dt_object *dt, struct thandle *th);
429 int (*do_ref_del)(const struct lu_env *env,
430 struct dt_object *dt, struct thandle *th);
432 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
433 struct dt_object *dt,
434 struct lustre_capa *old,
436 int (*do_object_sync)(const struct lu_env *, struct dt_object *);
438 * Get object info of next level. Currently, only get inode from osd.
439 * This is only used by quota b=16542
440 * precondition: dt_object_exists(dt);
442 int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
447 * Per-dt-object operations on "file body".
449 struct dt_body_operations {
451 * precondition: dt_object_exists(dt);
453 ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
454 struct lu_buf *buf, loff_t *pos,
455 struct lustre_capa *capa);
457 * precondition: dt_object_exists(dt);
459 ssize_t (*dbo_declare_write)(const struct lu_env *env,
460 struct dt_object *dt,
461 const loff_t size, loff_t pos,
462 struct thandle *handle);
463 ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
464 const struct lu_buf *buf, loff_t *pos,
465 struct thandle *handle, struct lustre_capa *capa,
468 * methods for zero-copy IO
472 * precondition: dt_object_exists(dt);
476 * > 0 - number of local buffers prepared
478 int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
479 loff_t pos, ssize_t len, struct niobuf_local *lb,
480 int rw, struct lustre_capa *capa);
482 * precondition: dt_object_exists(dt);
484 int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
485 struct niobuf_local *lb, int nr);
487 * precondition: dt_object_exists(dt);
489 int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
490 struct niobuf_local *lb, int nr);
492 * precondition: dt_object_exists(dt);
494 int (*dbo_declare_write_commit)(const struct lu_env *env,
495 struct dt_object *dt,
496 struct niobuf_local *,
497 int, struct thandle *);
499 * precondition: dt_object_exists(dt);
501 int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
502 struct niobuf_local *, int, struct thandle *);
504 * precondition: dt_object_exists(dt);
506 int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
507 struct niobuf_local *lnb, int nr);
508 int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
509 struct ll_user_fiemap *fm);
511 * Punch object's content
512 * precondition: regular object, not index
514 int (*do_declare_punch)(const struct lu_env *, struct dt_object *,
515 __u64, __u64, struct thandle *th);
516 int (*do_punch)(const struct lu_env *env, struct dt_object *dt,
517 __u64 start, __u64 end, struct thandle *th,
518 struct lustre_capa *capa);
522 * Incomplete type of index record.
527 * Incomplete type of index key.
532 * Incomplete type of dt iterator.
537 * Per-dt-object operations on object as index.
539 struct dt_index_operations {
541 * precondition: dt_object_exists(dt);
543 int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
544 struct dt_rec *rec, const struct dt_key *key,
545 struct lustre_capa *capa);
547 * precondition: dt_object_exists(dt);
549 int (*dio_declare_insert)(const struct lu_env *env,
550 struct dt_object *dt,
551 const struct dt_rec *rec,
552 const struct dt_key *key,
553 struct thandle *handle);
554 int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
555 const struct dt_rec *rec, const struct dt_key *key,
556 struct thandle *handle, struct lustre_capa *capa,
559 * precondition: dt_object_exists(dt);
561 int (*dio_declare_delete)(const struct lu_env *env,
562 struct dt_object *dt,
563 const struct dt_key *key,
564 struct thandle *handle);
565 int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
566 const struct dt_key *key, struct thandle *handle,
567 struct lustre_capa *capa);
573 * Allocate and initialize new iterator.
575 * precondition: dt_object_exists(dt);
577 struct dt_it *(*init)(const struct lu_env *env,
578 struct dt_object *dt,
580 struct lustre_capa *capa);
581 void (*fini)(const struct lu_env *env,
583 int (*get)(const struct lu_env *env,
585 const struct dt_key *key);
586 void (*put)(const struct lu_env *env,
588 int (*next)(const struct lu_env *env,
590 struct dt_key *(*key)(const struct lu_env *env,
591 const struct dt_it *di);
592 int (*key_size)(const struct lu_env *env,
593 const struct dt_it *di);
594 int (*rec)(const struct lu_env *env,
595 const struct dt_it *di,
598 __u64 (*store)(const struct lu_env *env,
599 const struct dt_it *di);
600 int (*load)(const struct lu_env *env,
601 const struct dt_it *di, __u64 hash);
602 int (*key_rec)(const struct lu_env *env,
603 const struct dt_it *di, void* key_rec);
607 enum dt_otable_it_valid {
608 DOIV_ERROR_HANDLE = 0x0001,
611 enum dt_otable_it_flags {
612 /* Exit when fail. */
613 DOIF_FAILOUT = 0x0001,
615 /* Reset iteration position to the device beginning. */
618 /* There is up layer component uses the iteration. */
619 DOIF_OUTUSED = 0x0004,
622 /* otable based iteration needs to use the common DT interation APIs.
623 * To initialize the iteration, it needs call dio_it::init() firstly.
624 * Here is how the otable based iteration should prepare arguments to
625 * call dt_it_ops::init().
627 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
628 * is composed of two parts:
629 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
630 #define DT_OTABLE_IT_FLAGS_SHIFT 16
631 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
634 struct lu_device dd_lu_dev;
635 const struct dt_device_operations *dd_ops;
638 * List of dt_txn_callback (see below). This is not protected in any
639 * way, because callbacks are supposed to be added/deleted only during
640 * single-threaded start-up shut-down procedures.
642 cfs_list_t dd_txn_callbacks;
645 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
646 void dt_device_fini(struct dt_device *dev);
648 static inline int lu_device_is_dt(const struct lu_device *d)
650 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
653 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
655 LASSERT(lu_device_is_dt(l));
656 return container_of0(l, struct dt_device, dd_lu_dev);
660 struct lu_object do_lu;
661 const struct dt_object_operations *do_ops;
662 const struct dt_body_operations *do_body_ops;
663 const struct dt_index_operations *do_index_ops;
666 static inline struct dt_object *lu2dt(struct lu_object *l)
668 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
669 return container_of0(l, struct dt_object, do_lu);
672 int dt_object_init(struct dt_object *obj,
673 struct lu_object_header *h, struct lu_device *d);
675 void dt_object_fini(struct dt_object *obj);
677 static inline int dt_object_exists(const struct dt_object *dt)
679 return lu_object_exists(&dt->do_lu);
683 * This is the general purpose transaction handle.
684 * 1. Transaction Life Cycle
685 * This transaction handle is allocated upon starting a new transaction,
686 * and deallocated after this transaction is committed.
687 * 2. Transaction Nesting
688 * We do _NOT_ support nested transaction. So, every thread should only
689 * have one active transaction, and a transaction only belongs to one
690 * thread. Due to this, transaction handle need no reference count.
691 * 3. Transaction & dt_object locking
692 * dt_object locks should be taken inside transaction.
693 * 4. Transaction & RPC
694 * No RPC request should be issued inside transaction.
697 /** the dt device on which the transactions are executed */
698 struct dt_device *th_dev;
700 /** additional tags (layers can add in declare) */
703 /** context for this transaction, tag is LCT_TX_HANDLE */
704 struct lu_context th_ctx;
706 /** the last operation result in this transaction.
707 * this value is used in recovery */
710 /** whether we need sync commit */
713 /* local transation, no need to inform other layers */
718 * Transaction call-backs.
720 * These are invoked by osd (or underlying transaction engine) when
721 * transaction changes state.
723 * Call-backs are used by upper layers to modify transaction parameters and to
724 * perform some actions on for each transaction state transition. Typical
725 * example is mdt registering call-back to write into last-received file
726 * before each transaction commit.
728 struct dt_txn_callback {
729 int (*dtc_txn_start)(const struct lu_env *env,
730 struct thandle *txn, void *cookie);
731 int (*dtc_txn_stop)(const struct lu_env *env,
732 struct thandle *txn, void *cookie);
733 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
736 cfs_list_t dtc_linkage;
739 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
740 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
742 int dt_txn_hook_start(const struct lu_env *env,
743 struct dt_device *dev, struct thandle *txn);
744 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
745 void dt_txn_hook_commit(struct thandle *txn);
747 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
750 * Callback function used for parsing path.
751 * \see llo_store_resolve
753 typedef int (*dt_entry_func_t)(const struct lu_env *env,
757 #define DT_MAX_PATH 1024
759 int dt_path_parser(const struct lu_env *env,
760 char *local, dt_entry_func_t entry_func,
763 struct dt_object *dt_store_open(const struct lu_env *env,
764 struct dt_device *dt,
766 const char *filename,
769 struct dt_object *dt_find_or_create(const struct lu_env *env,
770 struct dt_device *dt,
771 const struct lu_fid *fid,
772 struct dt_object_format *dof,
773 struct lu_attr *attr);
775 struct dt_object *dt_locate(const struct lu_env *env,
776 struct dt_device *dev,
777 const struct lu_fid *fid);
779 static inline int dt_object_sync(const struct lu_env *env,
784 LASSERT(o->do_ops->do_object_sync);
785 return o->do_ops->do_object_sync(env, o);
788 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
790 void dt_version_set(const struct lu_env *env, struct dt_object *o,
791 dt_obj_version_t version, struct thandle *th);
792 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
795 int dt_read(const struct lu_env *env, struct dt_object *dt,
796 struct lu_buf *buf, loff_t *pos);
797 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
798 struct lu_buf *buf, loff_t *pos);
799 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
800 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
802 static inline struct thandle *dt_trans_create(const struct lu_env *env,
805 LASSERT(d->dd_ops->dt_trans_create);
806 return d->dd_ops->dt_trans_create(env, d);
809 static inline int dt_trans_start(const struct lu_env *env,
810 struct dt_device *d, struct thandle *th)
812 LASSERT(d->dd_ops->dt_trans_start);
813 return d->dd_ops->dt_trans_start(env, d, th);
816 /* for this transaction hooks shouldn't be called */
817 static inline int dt_trans_start_local(const struct lu_env *env,
818 struct dt_device *d, struct thandle *th)
820 LASSERT(d->dd_ops->dt_trans_start);
822 return d->dd_ops->dt_trans_start(env, d, th);
825 static inline int dt_trans_stop(const struct lu_env *env,
826 struct dt_device *d, struct thandle *th)
828 LASSERT(d->dd_ops->dt_trans_stop);
829 return d->dd_ops->dt_trans_stop(env, th);
832 static inline int dt_trans_cb_add(struct thandle *th,
833 struct dt_txn_commit_cb *dcb)
835 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
836 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
841 static inline int dt_declare_record_write(const struct lu_env *env,
842 struct dt_object *dt,
843 int size, loff_t pos,
848 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
850 LASSERT(dt->do_body_ops);
851 LASSERT(dt->do_body_ops->dbo_declare_write);
852 rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
856 static inline int dt_declare_create(const struct lu_env *env,
857 struct dt_object *dt,
858 struct lu_attr *attr,
859 struct dt_allocation_hint *hint,
860 struct dt_object_format *dof,
865 LASSERT(dt->do_ops->do_declare_create);
866 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
869 static inline int dt_create(const struct lu_env *env,
870 struct dt_object *dt,
871 struct lu_attr *attr,
872 struct dt_allocation_hint *hint,
873 struct dt_object_format *dof,
878 LASSERT(dt->do_ops->do_create);
879 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
882 static inline int dt_declare_destroy(const struct lu_env *env,
883 struct dt_object *dt,
888 LASSERT(dt->do_ops->do_declare_destroy);
889 return dt->do_ops->do_declare_destroy(env, dt, th);
892 static inline int dt_destroy(const struct lu_env *env,
893 struct dt_object *dt,
898 LASSERT(dt->do_ops->do_destroy);
899 return dt->do_ops->do_destroy(env, dt, th);
902 static inline void dt_read_lock(const struct lu_env *env,
903 struct dt_object *dt,
908 LASSERT(dt->do_ops->do_read_lock);
909 dt->do_ops->do_read_lock(env, dt, role);
912 static inline void dt_write_lock(const struct lu_env *env,
913 struct dt_object *dt,
918 LASSERT(dt->do_ops->do_write_lock);
919 dt->do_ops->do_write_lock(env, dt, role);
922 static inline void dt_read_unlock(const struct lu_env *env,
923 struct dt_object *dt)
927 LASSERT(dt->do_ops->do_read_unlock);
928 dt->do_ops->do_read_unlock(env, dt);
931 static inline void dt_write_unlock(const struct lu_env *env,
932 struct dt_object *dt)
936 LASSERT(dt->do_ops->do_write_unlock);
937 dt->do_ops->do_write_unlock(env, dt);
940 static inline int dt_write_locked(const struct lu_env *env,
941 struct dt_object *dt)
945 LASSERT(dt->do_ops->do_write_locked);
946 return dt->do_ops->do_write_locked(env, dt);
949 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
950 struct lu_attr *la, void *arg)
954 LASSERT(dt->do_ops->do_attr_get);
955 return dt->do_ops->do_attr_get(env, dt, la, arg);
958 static inline int dt_declare_attr_set(const struct lu_env *env,
959 struct dt_object *dt,
960 const struct lu_attr *la,
965 LASSERT(dt->do_ops->do_declare_attr_set);
966 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
969 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
970 const struct lu_attr *la, struct thandle *th,
971 struct lustre_capa *capa)
975 LASSERT(dt->do_ops->do_attr_set);
976 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
979 static inline int dt_declare_ref_add(const struct lu_env *env,
980 struct dt_object *dt, struct thandle *th)
984 LASSERT(dt->do_ops->do_declare_ref_add);
985 return dt->do_ops->do_declare_ref_add(env, dt, th);
988 static inline int dt_ref_add(const struct lu_env *env,
989 struct dt_object *dt, struct thandle *th)
993 LASSERT(dt->do_ops->do_ref_add);
994 return dt->do_ops->do_ref_add(env, dt, th);
997 static inline int dt_declare_ref_del(const struct lu_env *env,
998 struct dt_object *dt, struct thandle *th)
1001 LASSERT(dt->do_ops);
1002 LASSERT(dt->do_ops->do_declare_ref_del);
1003 return dt->do_ops->do_declare_ref_del(env, dt, th);
1006 static inline int dt_ref_del(const struct lu_env *env,
1007 struct dt_object *dt, struct thandle *th)
1010 LASSERT(dt->do_ops);
1011 LASSERT(dt->do_ops->do_ref_del);
1012 return dt->do_ops->do_ref_del(env, dt, th);
1015 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1016 struct dt_object *dt,
1017 struct lustre_capa *old, __u64 opc)
1020 LASSERT(dt->do_ops);
1021 LASSERT(dt->do_ops->do_ref_del);
1022 return dt->do_ops->do_capa_get(env, dt, old, opc);
1025 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1026 struct niobuf_remote *rnb,
1027 struct niobuf_local *lnb, int rw,
1028 struct lustre_capa *capa)
1031 LASSERT(d->do_body_ops);
1032 LASSERT(d->do_body_ops->dbo_bufs_get);
1033 return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1034 rnb->len, lnb, rw, capa);
1037 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1038 struct niobuf_local *lnb, int n)
1041 LASSERT(d->do_body_ops);
1042 LASSERT(d->do_body_ops->dbo_bufs_put);
1043 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1046 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1047 struct niobuf_local *lnb, int n)
1050 LASSERT(d->do_body_ops);
1051 LASSERT(d->do_body_ops->dbo_write_prep);
1052 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1055 static inline int dt_declare_write_commit(const struct lu_env *env,
1056 struct dt_object *d,
1057 struct niobuf_local *lnb,
1058 int n, struct thandle *th)
1060 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1061 LASSERT(th != NULL);
1062 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1066 static inline int dt_write_commit(const struct lu_env *env,
1067 struct dt_object *d, struct niobuf_local *lnb,
1068 int n, struct thandle *th)
1071 LASSERT(d->do_body_ops);
1072 LASSERT(d->do_body_ops->dbo_write_commit);
1073 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1076 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1077 struct niobuf_local *lnb, int n)
1080 LASSERT(d->do_body_ops);
1081 LASSERT(d->do_body_ops->dbo_read_prep);
1082 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1085 static inline int dt_declare_punch(const struct lu_env *env,
1086 struct dt_object *dt, __u64 start,
1087 __u64 end, struct thandle *th)
1090 LASSERT(dt->do_body_ops);
1091 LASSERT(dt->do_body_ops->do_declare_punch);
1092 return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1095 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1096 __u64 start, __u64 end, struct thandle *th,
1097 struct lustre_capa *capa)
1100 LASSERT(dt->do_body_ops);
1101 LASSERT(dt->do_body_ops->do_punch);
1102 return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1105 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1106 struct ll_user_fiemap *fm)
1109 if (d->do_body_ops == NULL)
1111 LASSERT(d->do_body_ops->dbo_fiemap_get);
1112 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1115 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1116 struct obd_statfs *osfs)
1119 LASSERT(dev->dd_ops);
1120 LASSERT(dev->dd_ops->dt_statfs);
1121 return dev->dd_ops->dt_statfs(env, dev, osfs);
1124 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1128 LASSERT(dev->dd_ops);
1129 LASSERT(dev->dd_ops->dt_root_get);
1130 return dev->dd_ops->dt_root_get(env, dev, f);
1133 static inline void dt_conf_get(const struct lu_env *env,
1134 const struct dt_device *dev,
1135 struct dt_device_param *param)
1138 LASSERT(dev->dd_ops);
1139 LASSERT(dev->dd_ops->dt_conf_get);
1140 return dev->dd_ops->dt_conf_get(env, dev, param);
1143 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1146 LASSERT(dev->dd_ops);
1147 LASSERT(dev->dd_ops->dt_sync);
1148 return dev->dd_ops->dt_sync(env, dev);
1151 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1154 LASSERT(dev->dd_ops);
1155 LASSERT(dev->dd_ops->dt_ro);
1156 return dev->dd_ops->dt_ro(env, dev);
1159 static inline int dt_declare_insert(const struct lu_env *env,
1160 struct dt_object *dt,
1161 const struct dt_rec *rec,
1162 const struct dt_key *key,
1166 LASSERT(dt->do_index_ops);
1167 LASSERT(dt->do_index_ops->dio_declare_insert);
1168 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1171 static inline int dt_insert(const struct lu_env *env,
1172 struct dt_object *dt,
1173 const struct dt_rec *rec,
1174 const struct dt_key *key,
1176 struct lustre_capa *capa,
1180 LASSERT(dt->do_index_ops);
1181 LASSERT(dt->do_index_ops->dio_insert);
1182 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1186 static inline int dt_declare_xattr_del(const struct lu_env *env,
1187 struct dt_object *dt,
1192 LASSERT(dt->do_ops);
1193 LASSERT(dt->do_ops->do_declare_xattr_del);
1194 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1197 static inline int dt_xattr_del(const struct lu_env *env,
1198 struct dt_object *dt, const char *name,
1200 struct lustre_capa *capa)
1203 LASSERT(dt->do_ops);
1204 LASSERT(dt->do_ops->do_xattr_del);
1205 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1208 static inline int dt_declare_xattr_set(const struct lu_env *env,
1209 struct dt_object *dt,
1210 const struct lu_buf *buf,
1211 const char *name, int fl,
1215 LASSERT(dt->do_ops);
1216 LASSERT(dt->do_ops->do_declare_xattr_set);
1217 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1220 static inline int dt_xattr_set(const struct lu_env *env,
1221 struct dt_object *dt, const struct lu_buf *buf,
1222 const char *name, int fl, struct thandle *th,
1223 struct lustre_capa *capa)
1226 LASSERT(dt->do_ops);
1227 LASSERT(dt->do_ops->do_xattr_set);
1228 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1231 static inline int dt_xattr_get(const struct lu_env *env,
1232 struct dt_object *dt, struct lu_buf *buf,
1233 const char *name, struct lustre_capa *capa)
1236 LASSERT(dt->do_ops);
1237 LASSERT(dt->do_ops->do_xattr_get);
1238 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1241 static inline int dt_xattr_list(const struct lu_env *env,
1242 struct dt_object *dt, struct lu_buf *buf,
1243 struct lustre_capa *capa)
1246 LASSERT(dt->do_ops);
1247 LASSERT(dt->do_ops->do_xattr_list);
1248 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1251 static inline int dt_declare_delete(const struct lu_env *env,
1252 struct dt_object *dt,
1253 const struct dt_key *key,
1257 LASSERT(dt->do_index_ops);
1258 LASSERT(dt->do_index_ops->dio_declare_delete);
1259 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1262 static inline int dt_delete(const struct lu_env *env,
1263 struct dt_object *dt,
1264 const struct dt_key *key,
1266 struct lustre_capa *capa)
1269 LASSERT(dt->do_index_ops);
1270 LASSERT(dt->do_index_ops->dio_delete);
1271 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1274 static inline int dt_commit_async(const struct lu_env *env,
1275 struct dt_device *dev)
1278 LASSERT(dev->dd_ops);
1279 LASSERT(dev->dd_ops->dt_commit_async);
1280 return dev->dd_ops->dt_commit_async(env, dev);
1283 static inline int dt_lookup(const struct lu_env *env,
1284 struct dt_object *dt,
1286 const struct dt_key *key,
1287 struct lustre_capa *capa)
1292 LASSERT(dt->do_index_ops);
1293 LASSERT(dt->do_index_ops->dio_lookup);
1295 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1303 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1305 #endif /* __LUSTRE_DT_OBJECT_H */