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 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
106 #define MAX_COMMIT_CB_STR_LEN 32
108 struct dt_txn_commit_cb {
109 cfs_list_t dcb_linkage;
112 char dcb_name[MAX_COMMIT_CB_STR_LEN];
116 * Operations on dt device.
118 struct dt_device_operations {
120 * Return device-wide statistics.
122 int (*dt_statfs)(const struct lu_env *env,
123 struct dt_device *dev, struct obd_statfs *osfs);
125 * Create transaction, described by \a param.
127 struct thandle *(*dt_trans_create)(const struct lu_env *env,
128 struct dt_device *dev);
130 * Start transaction, described by \a param.
132 int (*dt_trans_start)(const struct lu_env *env,
133 struct dt_device *dev, struct thandle *th);
135 * Finish previously started transaction.
137 int (*dt_trans_stop)(const struct lu_env *env,
140 * Add commit callback to the transaction.
142 int (*dt_trans_cb_add)(struct thandle *th,
143 struct dt_txn_commit_cb *dcb);
145 * Return fid of root index object.
147 int (*dt_root_get)(const struct lu_env *env,
148 struct dt_device *dev, struct lu_fid *f);
150 * Return device configuration data.
152 void (*dt_conf_get)(const struct lu_env *env,
153 const struct dt_device *dev,
154 struct dt_device_param *param);
156 * handling device state, mostly for tests
158 int (*dt_sync)(const struct lu_env *env, struct dt_device *dev);
159 int (*dt_ro)(const struct lu_env *env, struct dt_device *dev);
161 * Start a transaction commit asynchronously
163 * \param env environment
164 * \param dev dt_device to start commit on
166 * \return 0 success, negative value if error
168 int (*dt_commit_async)(const struct lu_env *env,
169 struct dt_device *dev);
171 * Initialize capability context.
173 int (*dt_init_capa_ctxt)(const struct lu_env *env,
174 struct dt_device *dev,
175 int mode, unsigned long timeout,
176 __u32 alg, struct lustre_capa_key *keys);
178 * Initialize quota context.
180 void (*dt_init_quota_ctxt)(const struct lu_env *env,
181 struct dt_device *dev,
182 struct dt_quota_ctxt *ctxt, void *data);
185 struct dt_index_features {
186 /** required feature flags from enum dt_index_flags */
188 /** minimal required key size */
189 size_t dif_keysize_min;
190 /** maximal required key size, 0 if no limit */
191 size_t dif_keysize_max;
192 /** minimal required record size */
193 size_t dif_recsize_min;
194 /** maximal required record size, 0 if no limit */
195 size_t dif_recsize_max;
196 /** pointer size for record */
200 enum dt_index_flags {
201 /** index supports variable sized keys */
202 DT_IND_VARKEY = 1 << 0,
203 /** index supports variable sized records */
204 DT_IND_VARREC = 1 << 1,
205 /** index can be modified */
206 DT_IND_UPDATE = 1 << 2,
207 /** index supports records with non-unique (duplicate) keys */
208 DT_IND_NONUNQ = 1 << 3,
210 * index support fixed-size keys sorted with natural numerical way
211 * and is able to return left-side value if no exact value found
213 DT_IND_RANGE = 1 << 4,
217 * Features, required from index to support file system directories (mapping
220 extern const struct dt_index_features dt_directory_features;
221 extern const struct dt_index_features dt_otable_features;
223 /* index features supported by the accounting objects */
224 extern const struct dt_index_features dt_acct_features;
227 * This is a general purpose dt allocation hint.
228 * It now contains the parent object.
229 * It can contain any allocation hint in the future.
231 struct dt_allocation_hint {
232 struct dt_object *dah_parent;
237 * object type specifier.
240 enum dt_format_type {
245 /** for special index */
247 /** for symbolic link */
252 * object format specifier.
254 struct dt_object_format {
255 /** type for dt object */
256 enum dt_format_type dof_type;
265 * special index need feature as parameter to create
269 const struct dt_index_features *di_feat;
274 enum dt_format_type dt_mode_to_dft(__u32 mode);
276 typedef __u64 dt_obj_version_t;
279 * Per-dt-object operations.
281 struct dt_object_operations {
282 void (*do_read_lock)(const struct lu_env *env,
283 struct dt_object *dt, unsigned role);
284 void (*do_write_lock)(const struct lu_env *env,
285 struct dt_object *dt, unsigned role);
286 void (*do_read_unlock)(const struct lu_env *env,
287 struct dt_object *dt);
288 void (*do_write_unlock)(const struct lu_env *env,
289 struct dt_object *dt);
290 int (*do_write_locked)(const struct lu_env *env,
291 struct dt_object *dt);
293 * Note: following ->do_{x,}attr_{set,get}() operations are very
294 * similar to ->moo_{x,}attr_{set,get}() operations in struct
295 * md_object_operations (see md_object.h). These operations are not in
296 * lu_object_operations, because ->do_{x,}attr_set() versions take
297 * transaction handle as an argument (this transaction is started by
298 * caller). We might factor ->do_{x,}attr_get() into
299 * lu_object_operations, but that would break existing symmetry.
303 * Return standard attributes.
305 * precondition: lu_object_exists(&dt->do_lu);
307 int (*do_attr_get)(const struct lu_env *env,
308 struct dt_object *dt, struct lu_attr *attr,
309 struct lustre_capa *capa);
311 * Set standard attributes.
313 * precondition: dt_object_exists(dt);
315 int (*do_declare_attr_set)(const struct lu_env *env,
316 struct dt_object *dt,
317 const struct lu_attr *attr,
318 struct thandle *handle);
319 int (*do_attr_set)(const struct lu_env *env,
320 struct dt_object *dt,
321 const struct lu_attr *attr,
322 struct thandle *handle,
323 struct lustre_capa *capa);
325 * Return a value of an extended attribute.
327 * precondition: dt_object_exists(dt);
329 int (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
330 struct lu_buf *buf, const char *name,
331 struct lustre_capa *capa);
333 * Set value of an extended attribute.
335 * \a fl - flags from enum lu_xattr_flags
337 * precondition: dt_object_exists(dt);
339 int (*do_declare_xattr_set)(const struct lu_env *env,
340 struct dt_object *dt,
341 const struct lu_buf *buf,
342 const char *name, int fl,
343 struct thandle *handle);
344 int (*do_xattr_set)(const struct lu_env *env,
345 struct dt_object *dt, const struct lu_buf *buf,
346 const char *name, int fl, struct thandle *handle,
347 struct lustre_capa *capa);
349 * Delete existing extended attribute.
351 * precondition: dt_object_exists(dt);
353 int (*do_declare_xattr_del)(const struct lu_env *env,
354 struct dt_object *dt,
355 const char *name, struct thandle *handle);
356 int (*do_xattr_del)(const struct lu_env *env,
357 struct dt_object *dt,
358 const char *name, struct thandle *handle,
359 struct lustre_capa *capa);
361 * Place list of existing extended attributes into \a buf (which has
364 * precondition: dt_object_exists(dt);
366 int (*do_xattr_list)(const struct lu_env *env,
367 struct dt_object *dt, struct lu_buf *buf,
368 struct lustre_capa *capa);
370 * Init allocation hint using parent object and child mode.
371 * (1) The \a parent might be NULL if this is a partial creation for
373 * (2) The type of child is in \a child_mode.
374 * (3) The result hint is stored in \a ah;
376 void (*do_ah_init)(const struct lu_env *env,
377 struct dt_allocation_hint *ah,
378 struct dt_object *parent,
379 cfs_umode_t child_mode);
381 * Create new object on this device.
383 * precondition: !dt_object_exists(dt);
384 * postcondition: ergo(result == 0, dt_object_exists(dt));
386 int (*do_declare_create)(const struct lu_env *env,
387 struct dt_object *dt,
388 struct lu_attr *attr,
389 struct dt_allocation_hint *hint,
390 struct dt_object_format *dof,
392 int (*do_create)(const struct lu_env *env, struct dt_object *dt,
393 struct lu_attr *attr,
394 struct dt_allocation_hint *hint,
395 struct dt_object_format *dof,
399 Destroy object on this device
400 * precondition: !dt_object_exists(dt);
401 * postcondition: ergo(result == 0, dt_object_exists(dt));
403 int (*do_declare_destroy)(const struct lu_env *env,
404 struct dt_object *dt,
406 int (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
410 * Announce that this object is going to be used as an index. This
411 * operation check that object supports indexing operations and
412 * installs appropriate dt_index_operations vector on success.
414 * Also probes for features. Operation is successful if all required
415 * features are supported.
417 int (*do_index_try)(const struct lu_env *env,
418 struct dt_object *dt,
419 const struct dt_index_features *feat);
421 * Add nlink of the object
422 * precondition: dt_object_exists(dt);
424 int (*do_declare_ref_add)(const struct lu_env *env,
425 struct dt_object *dt, struct thandle *th);
426 int (*do_ref_add)(const struct lu_env *env,
427 struct dt_object *dt, struct thandle *th);
429 * Del nlink of the object
430 * precondition: dt_object_exists(dt);
432 int (*do_declare_ref_del)(const struct lu_env *env,
433 struct dt_object *dt, struct thandle *th);
434 int (*do_ref_del)(const struct lu_env *env,
435 struct dt_object *dt, struct thandle *th);
437 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
438 struct dt_object *dt,
439 struct lustre_capa *old,
441 int (*do_object_sync)(const struct lu_env *, struct dt_object *);
443 * Get object info of next level. Currently, only get inode from osd.
444 * This is only used by quota b=16542
445 * precondition: dt_object_exists(dt);
447 int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
452 * Per-dt-object operations on "file body".
454 struct dt_body_operations {
456 * precondition: dt_object_exists(dt);
458 ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
459 struct lu_buf *buf, loff_t *pos,
460 struct lustre_capa *capa);
462 * precondition: dt_object_exists(dt);
464 ssize_t (*dbo_declare_write)(const struct lu_env *env,
465 struct dt_object *dt,
466 const loff_t size, loff_t pos,
467 struct thandle *handle);
468 ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
469 const struct lu_buf *buf, loff_t *pos,
470 struct thandle *handle, struct lustre_capa *capa,
473 * methods for zero-copy IO
477 * precondition: dt_object_exists(dt);
481 * > 0 - number of local buffers prepared
483 int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
484 loff_t pos, ssize_t len, struct niobuf_local *lb,
485 int rw, struct lustre_capa *capa);
487 * precondition: dt_object_exists(dt);
489 int (*dbo_bufs_put)(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_write_prep)(const struct lu_env *env, struct dt_object *dt,
495 struct niobuf_local *lb, int nr);
497 * precondition: dt_object_exists(dt);
499 int (*dbo_declare_write_commit)(const struct lu_env *env,
500 struct dt_object *dt,
501 struct niobuf_local *,
502 int, struct thandle *);
504 * precondition: dt_object_exists(dt);
506 int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
507 struct niobuf_local *, int, struct thandle *);
509 * precondition: dt_object_exists(dt);
511 int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
512 struct niobuf_local *lnb, int nr);
513 int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
514 struct ll_user_fiemap *fm);
516 * Punch object's content
517 * precondition: regular object, not index
519 int (*do_declare_punch)(const struct lu_env *, struct dt_object *,
520 __u64, __u64, struct thandle *th);
521 int (*do_punch)(const struct lu_env *env, struct dt_object *dt,
522 __u64 start, __u64 end, struct thandle *th,
523 struct lustre_capa *capa);
527 * Incomplete type of index record.
532 * Incomplete type of index key.
537 * Incomplete type of dt iterator.
542 * Per-dt-object operations on object as index.
544 struct dt_index_operations {
546 * precondition: dt_object_exists(dt);
548 int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
549 struct dt_rec *rec, const struct dt_key *key,
550 struct lustre_capa *capa);
552 * precondition: dt_object_exists(dt);
554 int (*dio_declare_insert)(const struct lu_env *env,
555 struct dt_object *dt,
556 const struct dt_rec *rec,
557 const struct dt_key *key,
558 struct thandle *handle);
559 int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
560 const struct dt_rec *rec, const struct dt_key *key,
561 struct thandle *handle, struct lustre_capa *capa,
564 * precondition: dt_object_exists(dt);
566 int (*dio_declare_delete)(const struct lu_env *env,
567 struct dt_object *dt,
568 const struct dt_key *key,
569 struct thandle *handle);
570 int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
571 const struct dt_key *key, struct thandle *handle,
572 struct lustre_capa *capa);
578 * Allocate and initialize new iterator.
580 * precondition: dt_object_exists(dt);
582 struct dt_it *(*init)(const struct lu_env *env,
583 struct dt_object *dt,
585 struct lustre_capa *capa);
586 void (*fini)(const struct lu_env *env,
588 int (*get)(const struct lu_env *env,
590 const struct dt_key *key);
591 void (*put)(const struct lu_env *env,
593 int (*next)(const struct lu_env *env,
595 struct dt_key *(*key)(const struct lu_env *env,
596 const struct dt_it *di);
597 int (*key_size)(const struct lu_env *env,
598 const struct dt_it *di);
599 int (*rec)(const struct lu_env *env,
600 const struct dt_it *di,
603 __u64 (*store)(const struct lu_env *env,
604 const struct dt_it *di);
605 int (*load)(const struct lu_env *env,
606 const struct dt_it *di, __u64 hash);
607 int (*key_rec)(const struct lu_env *env,
608 const struct dt_it *di, void* key_rec);
612 enum dt_otable_it_valid {
613 DOIV_ERROR_HANDLE = 0x0001,
616 enum dt_otable_it_flags {
617 /* Exit when fail. */
618 DOIF_FAILOUT = 0x0001,
620 /* Reset iteration position to the device beginning. */
623 /* There is up layer component uses the iteration. */
624 DOIF_OUTUSED = 0x0004,
627 /* otable based iteration needs to use the common DT interation APIs.
628 * To initialize the iteration, it needs call dio_it::init() firstly.
629 * Here is how the otable based iteration should prepare arguments to
630 * call dt_it_ops::init().
632 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
633 * is composed of two parts:
634 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
635 #define DT_OTABLE_IT_FLAGS_SHIFT 16
636 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
639 struct lu_device dd_lu_dev;
640 const struct dt_device_operations *dd_ops;
643 * List of dt_txn_callback (see below). This is not protected in any
644 * way, because callbacks are supposed to be added/deleted only during
645 * single-threaded start-up shut-down procedures.
647 cfs_list_t dd_txn_callbacks;
650 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
651 void dt_device_fini(struct dt_device *dev);
653 static inline int lu_device_is_dt(const struct lu_device *d)
655 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
658 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
660 LASSERT(lu_device_is_dt(l));
661 return container_of0(l, struct dt_device, dd_lu_dev);
665 struct lu_object do_lu;
666 const struct dt_object_operations *do_ops;
667 const struct dt_body_operations *do_body_ops;
668 const struct dt_index_operations *do_index_ops;
671 static inline struct dt_object *lu2dt(struct lu_object *l)
673 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
674 return container_of0(l, struct dt_object, do_lu);
677 int dt_object_init(struct dt_object *obj,
678 struct lu_object_header *h, struct lu_device *d);
680 void dt_object_fini(struct dt_object *obj);
682 static inline int dt_object_exists(const struct dt_object *dt)
684 return lu_object_exists(&dt->do_lu);
688 * This is the general purpose transaction handle.
689 * 1. Transaction Life Cycle
690 * This transaction handle is allocated upon starting a new transaction,
691 * and deallocated after this transaction is committed.
692 * 2. Transaction Nesting
693 * We do _NOT_ support nested transaction. So, every thread should only
694 * have one active transaction, and a transaction only belongs to one
695 * thread. Due to this, transaction handle need no reference count.
696 * 3. Transaction & dt_object locking
697 * dt_object locks should be taken inside transaction.
698 * 4. Transaction & RPC
699 * No RPC request should be issued inside transaction.
702 /** the dt device on which the transactions are executed */
703 struct dt_device *th_dev;
705 /** additional tags (layers can add in declare) */
708 /** context for this transaction, tag is LCT_TX_HANDLE */
709 struct lu_context th_ctx;
711 /** the last operation result in this transaction.
712 * this value is used in recovery */
715 /** whether we need sync commit */
718 /* local transation, no need to inform other layers */
723 * Transaction call-backs.
725 * These are invoked by osd (or underlying transaction engine) when
726 * transaction changes state.
728 * Call-backs are used by upper layers to modify transaction parameters and to
729 * perform some actions on for each transaction state transition. Typical
730 * example is mdt registering call-back to write into last-received file
731 * before each transaction commit.
733 struct dt_txn_callback {
734 int (*dtc_txn_start)(const struct lu_env *env,
735 struct thandle *txn, void *cookie);
736 int (*dtc_txn_stop)(const struct lu_env *env,
737 struct thandle *txn, void *cookie);
738 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
741 cfs_list_t dtc_linkage;
744 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
745 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
747 int dt_txn_hook_start(const struct lu_env *env,
748 struct dt_device *dev, struct thandle *txn);
749 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
750 void dt_txn_hook_commit(struct thandle *txn);
752 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
755 * Callback function used for parsing path.
756 * \see llo_store_resolve
758 typedef int (*dt_entry_func_t)(const struct lu_env *env,
762 #define DT_MAX_PATH 1024
764 int dt_path_parser(const struct lu_env *env,
765 char *local, dt_entry_func_t entry_func,
768 struct dt_object *dt_store_open(const struct lu_env *env,
769 struct dt_device *dt,
771 const char *filename,
774 struct dt_object *dt_find_or_create(const struct lu_env *env,
775 struct dt_device *dt,
776 const struct lu_fid *fid,
777 struct dt_object_format *dof,
778 struct lu_attr *attr);
780 struct dt_object *dt_locate(const struct lu_env *env,
781 struct dt_device *dev,
782 const struct lu_fid *fid);
784 static inline int dt_object_sync(const struct lu_env *env,
789 LASSERT(o->do_ops->do_object_sync);
790 return o->do_ops->do_object_sync(env, o);
793 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
795 void dt_version_set(const struct lu_env *env, struct dt_object *o,
796 dt_obj_version_t version, struct thandle *th);
797 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
800 int dt_read(const struct lu_env *env, struct dt_object *dt,
801 struct lu_buf *buf, loff_t *pos);
802 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
803 struct lu_buf *buf, loff_t *pos);
804 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
805 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
807 static inline struct thandle *dt_trans_create(const struct lu_env *env,
810 LASSERT(d->dd_ops->dt_trans_create);
811 return d->dd_ops->dt_trans_create(env, d);
814 static inline int dt_trans_start(const struct lu_env *env,
815 struct dt_device *d, struct thandle *th)
817 LASSERT(d->dd_ops->dt_trans_start);
818 return d->dd_ops->dt_trans_start(env, d, th);
821 /* for this transaction hooks shouldn't be called */
822 static inline int dt_trans_start_local(const struct lu_env *env,
823 struct dt_device *d, struct thandle *th)
825 LASSERT(d->dd_ops->dt_trans_start);
827 return d->dd_ops->dt_trans_start(env, d, th);
830 static inline int dt_trans_stop(const struct lu_env *env,
831 struct dt_device *d, struct thandle *th)
833 LASSERT(d->dd_ops->dt_trans_stop);
834 return d->dd_ops->dt_trans_stop(env, th);
837 static inline int dt_trans_cb_add(struct thandle *th,
838 struct dt_txn_commit_cb *dcb)
840 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
841 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
842 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
847 static inline int dt_declare_record_write(const struct lu_env *env,
848 struct dt_object *dt,
849 int size, loff_t pos,
854 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
856 LASSERT(dt->do_body_ops);
857 LASSERT(dt->do_body_ops->dbo_declare_write);
858 rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
862 static inline int dt_declare_create(const struct lu_env *env,
863 struct dt_object *dt,
864 struct lu_attr *attr,
865 struct dt_allocation_hint *hint,
866 struct dt_object_format *dof,
871 LASSERT(dt->do_ops->do_declare_create);
872 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
875 static inline int dt_create(const struct lu_env *env,
876 struct dt_object *dt,
877 struct lu_attr *attr,
878 struct dt_allocation_hint *hint,
879 struct dt_object_format *dof,
884 LASSERT(dt->do_ops->do_create);
885 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
888 static inline int dt_declare_destroy(const struct lu_env *env,
889 struct dt_object *dt,
894 LASSERT(dt->do_ops->do_declare_destroy);
895 return dt->do_ops->do_declare_destroy(env, dt, th);
898 static inline int dt_destroy(const struct lu_env *env,
899 struct dt_object *dt,
904 LASSERT(dt->do_ops->do_destroy);
905 return dt->do_ops->do_destroy(env, dt, th);
908 static inline void dt_read_lock(const struct lu_env *env,
909 struct dt_object *dt,
914 LASSERT(dt->do_ops->do_read_lock);
915 dt->do_ops->do_read_lock(env, dt, role);
918 static inline void dt_write_lock(const struct lu_env *env,
919 struct dt_object *dt,
924 LASSERT(dt->do_ops->do_write_lock);
925 dt->do_ops->do_write_lock(env, dt, role);
928 static inline void dt_read_unlock(const struct lu_env *env,
929 struct dt_object *dt)
933 LASSERT(dt->do_ops->do_read_unlock);
934 dt->do_ops->do_read_unlock(env, dt);
937 static inline void dt_write_unlock(const struct lu_env *env,
938 struct dt_object *dt)
942 LASSERT(dt->do_ops->do_write_unlock);
943 dt->do_ops->do_write_unlock(env, dt);
946 static inline int dt_write_locked(const struct lu_env *env,
947 struct dt_object *dt)
951 LASSERT(dt->do_ops->do_write_locked);
952 return dt->do_ops->do_write_locked(env, dt);
955 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
956 struct lu_attr *la, void *arg)
960 LASSERT(dt->do_ops->do_attr_get);
961 return dt->do_ops->do_attr_get(env, dt, la, arg);
964 static inline int dt_declare_attr_set(const struct lu_env *env,
965 struct dt_object *dt,
966 const struct lu_attr *la,
971 LASSERT(dt->do_ops->do_declare_attr_set);
972 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
975 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
976 const struct lu_attr *la, struct thandle *th,
977 struct lustre_capa *capa)
981 LASSERT(dt->do_ops->do_attr_set);
982 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
985 static inline int dt_declare_ref_add(const struct lu_env *env,
986 struct dt_object *dt, struct thandle *th)
990 LASSERT(dt->do_ops->do_declare_ref_add);
991 return dt->do_ops->do_declare_ref_add(env, dt, th);
994 static inline int dt_ref_add(const struct lu_env *env,
995 struct dt_object *dt, struct thandle *th)
999 LASSERT(dt->do_ops->do_ref_add);
1000 return dt->do_ops->do_ref_add(env, dt, th);
1003 static inline int dt_declare_ref_del(const struct lu_env *env,
1004 struct dt_object *dt, struct thandle *th)
1007 LASSERT(dt->do_ops);
1008 LASSERT(dt->do_ops->do_declare_ref_del);
1009 return dt->do_ops->do_declare_ref_del(env, dt, th);
1012 static inline int dt_ref_del(const struct lu_env *env,
1013 struct dt_object *dt, struct thandle *th)
1016 LASSERT(dt->do_ops);
1017 LASSERT(dt->do_ops->do_ref_del);
1018 return dt->do_ops->do_ref_del(env, dt, th);
1021 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1022 struct dt_object *dt,
1023 struct lustre_capa *old, __u64 opc)
1026 LASSERT(dt->do_ops);
1027 LASSERT(dt->do_ops->do_ref_del);
1028 return dt->do_ops->do_capa_get(env, dt, old, opc);
1031 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1032 struct niobuf_remote *rnb,
1033 struct niobuf_local *lnb, int rw,
1034 struct lustre_capa *capa)
1037 LASSERT(d->do_body_ops);
1038 LASSERT(d->do_body_ops->dbo_bufs_get);
1039 return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1040 rnb->len, lnb, rw, capa);
1043 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1044 struct niobuf_local *lnb, int n)
1047 LASSERT(d->do_body_ops);
1048 LASSERT(d->do_body_ops->dbo_bufs_put);
1049 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1052 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1053 struct niobuf_local *lnb, int n)
1056 LASSERT(d->do_body_ops);
1057 LASSERT(d->do_body_ops->dbo_write_prep);
1058 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1061 static inline int dt_declare_write_commit(const struct lu_env *env,
1062 struct dt_object *d,
1063 struct niobuf_local *lnb,
1064 int n, struct thandle *th)
1066 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1067 LASSERT(th != NULL);
1068 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1072 static inline int dt_write_commit(const struct lu_env *env,
1073 struct dt_object *d, struct niobuf_local *lnb,
1074 int n, struct thandle *th)
1077 LASSERT(d->do_body_ops);
1078 LASSERT(d->do_body_ops->dbo_write_commit);
1079 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1082 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1083 struct niobuf_local *lnb, int n)
1086 LASSERT(d->do_body_ops);
1087 LASSERT(d->do_body_ops->dbo_read_prep);
1088 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1091 static inline int dt_declare_punch(const struct lu_env *env,
1092 struct dt_object *dt, __u64 start,
1093 __u64 end, struct thandle *th)
1096 LASSERT(dt->do_body_ops);
1097 LASSERT(dt->do_body_ops->do_declare_punch);
1098 return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1101 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1102 __u64 start, __u64 end, struct thandle *th,
1103 struct lustre_capa *capa)
1106 LASSERT(dt->do_body_ops);
1107 LASSERT(dt->do_body_ops->do_punch);
1108 return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1111 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1112 struct ll_user_fiemap *fm)
1115 if (d->do_body_ops == NULL)
1117 if (d->do_body_ops->dbo_fiemap_get == NULL)
1119 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1122 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1123 struct obd_statfs *osfs)
1126 LASSERT(dev->dd_ops);
1127 LASSERT(dev->dd_ops->dt_statfs);
1128 return dev->dd_ops->dt_statfs(env, dev, osfs);
1131 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1135 LASSERT(dev->dd_ops);
1136 LASSERT(dev->dd_ops->dt_root_get);
1137 return dev->dd_ops->dt_root_get(env, dev, f);
1140 static inline void dt_conf_get(const struct lu_env *env,
1141 const struct dt_device *dev,
1142 struct dt_device_param *param)
1145 LASSERT(dev->dd_ops);
1146 LASSERT(dev->dd_ops->dt_conf_get);
1147 return dev->dd_ops->dt_conf_get(env, dev, param);
1150 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1153 LASSERT(dev->dd_ops);
1154 LASSERT(dev->dd_ops->dt_sync);
1155 return dev->dd_ops->dt_sync(env, dev);
1158 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1161 LASSERT(dev->dd_ops);
1162 LASSERT(dev->dd_ops->dt_ro);
1163 return dev->dd_ops->dt_ro(env, dev);
1166 static inline int dt_declare_insert(const struct lu_env *env,
1167 struct dt_object *dt,
1168 const struct dt_rec *rec,
1169 const struct dt_key *key,
1173 LASSERT(dt->do_index_ops);
1174 LASSERT(dt->do_index_ops->dio_declare_insert);
1175 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1178 static inline int dt_insert(const struct lu_env *env,
1179 struct dt_object *dt,
1180 const struct dt_rec *rec,
1181 const struct dt_key *key,
1183 struct lustre_capa *capa,
1187 LASSERT(dt->do_index_ops);
1188 LASSERT(dt->do_index_ops->dio_insert);
1189 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1193 static inline int dt_declare_xattr_del(const struct lu_env *env,
1194 struct dt_object *dt,
1199 LASSERT(dt->do_ops);
1200 LASSERT(dt->do_ops->do_declare_xattr_del);
1201 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1204 static inline int dt_xattr_del(const struct lu_env *env,
1205 struct dt_object *dt, const char *name,
1207 struct lustre_capa *capa)
1210 LASSERT(dt->do_ops);
1211 LASSERT(dt->do_ops->do_xattr_del);
1212 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1215 static inline int dt_declare_xattr_set(const struct lu_env *env,
1216 struct dt_object *dt,
1217 const struct lu_buf *buf,
1218 const char *name, int fl,
1222 LASSERT(dt->do_ops);
1223 LASSERT(dt->do_ops->do_declare_xattr_set);
1224 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1227 static inline int dt_xattr_set(const struct lu_env *env,
1228 struct dt_object *dt, const struct lu_buf *buf,
1229 const char *name, int fl, struct thandle *th,
1230 struct lustre_capa *capa)
1233 LASSERT(dt->do_ops);
1234 LASSERT(dt->do_ops->do_xattr_set);
1235 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1238 static inline int dt_xattr_get(const struct lu_env *env,
1239 struct dt_object *dt, struct lu_buf *buf,
1240 const char *name, struct lustre_capa *capa)
1243 LASSERT(dt->do_ops);
1244 LASSERT(dt->do_ops->do_xattr_get);
1245 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1248 static inline int dt_xattr_list(const struct lu_env *env,
1249 struct dt_object *dt, struct lu_buf *buf,
1250 struct lustre_capa *capa)
1253 LASSERT(dt->do_ops);
1254 LASSERT(dt->do_ops->do_xattr_list);
1255 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1258 static inline int dt_declare_delete(const struct lu_env *env,
1259 struct dt_object *dt,
1260 const struct dt_key *key,
1264 LASSERT(dt->do_index_ops);
1265 LASSERT(dt->do_index_ops->dio_declare_delete);
1266 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1269 static inline int dt_delete(const struct lu_env *env,
1270 struct dt_object *dt,
1271 const struct dt_key *key,
1273 struct lustre_capa *capa)
1276 LASSERT(dt->do_index_ops);
1277 LASSERT(dt->do_index_ops->dio_delete);
1278 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1281 static inline int dt_commit_async(const struct lu_env *env,
1282 struct dt_device *dev)
1285 LASSERT(dev->dd_ops);
1286 LASSERT(dev->dd_ops->dt_commit_async);
1287 return dev->dd_ops->dt_commit_async(env, dev);
1290 static inline int dt_lookup(const struct lu_env *env,
1291 struct dt_object *dt,
1293 const struct dt_key *key,
1294 struct lustre_capa *capa)
1299 LASSERT(dt->do_index_ops);
1300 LASSERT(dt->do_index_ops->dio_lookup);
1302 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1310 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1312 #endif /* __LUSTRE_DT_OBJECT_H */