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;
72 MNTOPT_USERXATTR = 0x00000001,
73 MNTOPT_ACL = 0x00000002,
76 struct dt_device_param {
77 unsigned ddp_max_name_len;
78 unsigned ddp_max_nlink;
79 unsigned ddp_block_shift;
81 unsigned ddp_max_ea_size;
82 void *ddp_mnt; /* XXX: old code can retrieve mnt -bzzz */
84 unsigned long long ddp_maxbytes;
85 /* percentage of available space to reserve for grant error margin */
86 int ddp_grant_reserved;
87 /* per-inode space consumption */
89 /* per-fragment grant overhead to be used by client for grant
95 * Per-transaction commit callback function
97 struct dt_txn_commit_cb;
98 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
99 struct dt_txn_commit_cb *cb, int err);
101 * Special per-transaction callback for cases when just commit callback
102 * is needed and per-device callback are not convenient to use
104 #define TRANS_COMMIT_CB_MAGIC 0xa0a00a0a
105 #define MAX_COMMIT_CB_STR_LEN 32
107 struct dt_txn_commit_cb {
108 cfs_list_t dcb_linkage;
111 char dcb_name[MAX_COMMIT_CB_STR_LEN];
115 * Operations on dt device.
117 struct dt_device_operations {
119 * Return device-wide statistics.
121 int (*dt_statfs)(const struct lu_env *env,
122 struct dt_device *dev, struct obd_statfs *osfs);
124 * Create transaction, described by \a param.
126 struct thandle *(*dt_trans_create)(const struct lu_env *env,
127 struct dt_device *dev);
129 * Start transaction, described by \a param.
131 int (*dt_trans_start)(const struct lu_env *env,
132 struct dt_device *dev, struct thandle *th);
134 * Finish previously started transaction.
136 int (*dt_trans_stop)(const struct lu_env *env,
139 * Add commit callback to the transaction.
141 int (*dt_trans_cb_add)(struct thandle *th,
142 struct dt_txn_commit_cb *dcb);
144 * Return fid of root index object.
146 int (*dt_root_get)(const struct lu_env *env,
147 struct dt_device *dev, struct lu_fid *f);
149 * Return device configuration data.
151 void (*dt_conf_get)(const struct lu_env *env,
152 const struct dt_device *dev,
153 struct dt_device_param *param);
155 * handling device state, mostly for tests
157 int (*dt_sync)(const struct lu_env *env, struct dt_device *dev);
158 int (*dt_ro)(const struct lu_env *env, struct dt_device *dev);
160 * Start a transaction commit asynchronously
162 * \param env environment
163 * \param dev dt_device to start commit on
165 * \return 0 success, negative value if error
167 int (*dt_commit_async)(const struct lu_env *env,
168 struct dt_device *dev);
170 * Initialize capability context.
172 int (*dt_init_capa_ctxt)(const struct lu_env *env,
173 struct dt_device *dev,
174 int mode, unsigned long timeout,
175 __u32 alg, struct lustre_capa_key *keys);
178 struct dt_index_features {
179 /** required feature flags from enum dt_index_flags */
181 /** minimal required key size */
182 size_t dif_keysize_min;
183 /** maximal required key size, 0 if no limit */
184 size_t dif_keysize_max;
185 /** minimal required record size */
186 size_t dif_recsize_min;
187 /** maximal required record size, 0 if no limit */
188 size_t dif_recsize_max;
189 /** pointer size for record */
193 enum dt_index_flags {
194 /** index supports variable sized keys */
195 DT_IND_VARKEY = 1 << 0,
196 /** index supports variable sized records */
197 DT_IND_VARREC = 1 << 1,
198 /** index can be modified */
199 DT_IND_UPDATE = 1 << 2,
200 /** index supports records with non-unique (duplicate) keys */
201 DT_IND_NONUNQ = 1 << 3,
203 * index support fixed-size keys sorted with natural numerical way
204 * and is able to return left-side value if no exact value found
206 DT_IND_RANGE = 1 << 4,
210 * Features, required from index to support file system directories (mapping
213 extern const struct dt_index_features dt_directory_features;
214 extern const struct dt_index_features dt_otable_features;
216 /* index features supported by the accounting objects */
217 extern const struct dt_index_features dt_acct_features;
219 /* index features supported by the quota global indexes */
220 extern const struct dt_index_features dt_quota_glb_features;
222 /* index features supported by the quota slave indexes */
223 extern const struct dt_index_features dt_quota_slv_features;
226 * This is a general purpose dt allocation hint.
227 * It now contains the parent object.
228 * It can contain any allocation hint in the future.
230 struct dt_allocation_hint {
231 struct dt_object *dah_parent;
236 * object type specifier.
239 enum dt_format_type {
244 /** for special index */
246 /** for symbolic link */
251 * object format specifier.
253 struct dt_object_format {
254 /** type for dt object */
255 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 struct dt_object *child,
380 cfs_umode_t child_mode);
382 * Create new object on this device.
384 * precondition: !dt_object_exists(dt);
385 * postcondition: ergo(result == 0, dt_object_exists(dt));
387 int (*do_declare_create)(const struct lu_env *env,
388 struct dt_object *dt,
389 struct lu_attr *attr,
390 struct dt_allocation_hint *hint,
391 struct dt_object_format *dof,
393 int (*do_create)(const struct lu_env *env, struct dt_object *dt,
394 struct lu_attr *attr,
395 struct dt_allocation_hint *hint,
396 struct dt_object_format *dof,
400 Destroy object on this device
401 * precondition: !dt_object_exists(dt);
402 * postcondition: ergo(result == 0, dt_object_exists(dt));
404 int (*do_declare_destroy)(const struct lu_env *env,
405 struct dt_object *dt,
407 int (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
411 * Announce that this object is going to be used as an index. This
412 * operation check that object supports indexing operations and
413 * installs appropriate dt_index_operations vector on success.
415 * Also probes for features. Operation is successful if all required
416 * features are supported.
418 int (*do_index_try)(const struct lu_env *env,
419 struct dt_object *dt,
420 const struct dt_index_features *feat);
422 * Add nlink of the object
423 * precondition: dt_object_exists(dt);
425 int (*do_declare_ref_add)(const struct lu_env *env,
426 struct dt_object *dt, struct thandle *th);
427 int (*do_ref_add)(const struct lu_env *env,
428 struct dt_object *dt, struct thandle *th);
430 * Del nlink of the object
431 * precondition: dt_object_exists(dt);
433 int (*do_declare_ref_del)(const struct lu_env *env,
434 struct dt_object *dt, struct thandle *th);
435 int (*do_ref_del)(const struct lu_env *env,
436 struct dt_object *dt, struct thandle *th);
438 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
439 struct dt_object *dt,
440 struct lustre_capa *old,
442 int (*do_object_sync)(const struct lu_env *, struct dt_object *);
444 * Get object info of next level. Currently, only get inode from osd.
445 * This is only used by quota b=16542
446 * precondition: dt_object_exists(dt);
448 int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
453 * Per-dt-object operations on "file body".
455 struct dt_body_operations {
457 * precondition: dt_object_exists(dt);
459 ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
460 struct lu_buf *buf, loff_t *pos,
461 struct lustre_capa *capa);
463 * precondition: dt_object_exists(dt);
465 ssize_t (*dbo_declare_write)(const struct lu_env *env,
466 struct dt_object *dt,
467 const loff_t size, loff_t pos,
468 struct thandle *handle);
469 ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
470 const struct lu_buf *buf, loff_t *pos,
471 struct thandle *handle, struct lustre_capa *capa,
474 * methods for zero-copy IO
478 * precondition: dt_object_exists(dt);
482 * > 0 - number of local buffers prepared
484 int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
485 loff_t pos, ssize_t len, struct niobuf_local *lb,
486 int rw, struct lustre_capa *capa);
488 * precondition: dt_object_exists(dt);
490 int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
491 struct niobuf_local *lb, int nr);
493 * precondition: dt_object_exists(dt);
495 int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
496 struct niobuf_local *lb, int nr);
498 * precondition: dt_object_exists(dt);
500 int (*dbo_declare_write_commit)(const struct lu_env *env,
501 struct dt_object *dt,
502 struct niobuf_local *,
503 int, struct thandle *);
505 * precondition: dt_object_exists(dt);
507 int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
508 struct niobuf_local *, int, struct thandle *);
510 * precondition: dt_object_exists(dt);
512 int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
513 struct niobuf_local *lnb, int nr);
514 int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
515 struct ll_user_fiemap *fm);
517 * Punch object's content
518 * precondition: regular object, not index
520 int (*do_declare_punch)(const struct lu_env *, struct dt_object *,
521 __u64, __u64, struct thandle *th);
522 int (*do_punch)(const struct lu_env *env, struct dt_object *dt,
523 __u64 start, __u64 end, struct thandle *th,
524 struct lustre_capa *capa);
528 * Incomplete type of index record.
533 * Incomplete type of index key.
538 * Incomplete type of dt iterator.
543 * Per-dt-object operations on object as index.
545 struct dt_index_operations {
547 * precondition: dt_object_exists(dt);
549 int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
550 struct dt_rec *rec, const struct dt_key *key,
551 struct lustre_capa *capa);
553 * precondition: dt_object_exists(dt);
555 int (*dio_declare_insert)(const struct lu_env *env,
556 struct dt_object *dt,
557 const struct dt_rec *rec,
558 const struct dt_key *key,
559 struct thandle *handle);
560 int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
561 const struct dt_rec *rec, const struct dt_key *key,
562 struct thandle *handle, struct lustre_capa *capa,
565 * precondition: dt_object_exists(dt);
567 int (*dio_declare_delete)(const struct lu_env *env,
568 struct dt_object *dt,
569 const struct dt_key *key,
570 struct thandle *handle);
571 int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
572 const struct dt_key *key, struct thandle *handle,
573 struct lustre_capa *capa);
579 * Allocate and initialize new iterator.
581 * precondition: dt_object_exists(dt);
583 struct dt_it *(*init)(const struct lu_env *env,
584 struct dt_object *dt,
586 struct lustre_capa *capa);
587 void (*fini)(const struct lu_env *env,
589 int (*get)(const struct lu_env *env,
591 const struct dt_key *key);
592 void (*put)(const struct lu_env *env,
594 int (*next)(const struct lu_env *env,
596 struct dt_key *(*key)(const struct lu_env *env,
597 const struct dt_it *di);
598 int (*key_size)(const struct lu_env *env,
599 const struct dt_it *di);
600 int (*rec)(const struct lu_env *env,
601 const struct dt_it *di,
604 __u64 (*store)(const struct lu_env *env,
605 const struct dt_it *di);
606 int (*load)(const struct lu_env *env,
607 const struct dt_it *di, __u64 hash);
608 int (*key_rec)(const struct lu_env *env,
609 const struct dt_it *di, void* key_rec);
613 enum dt_otable_it_valid {
614 DOIV_ERROR_HANDLE = 0x0001,
617 enum dt_otable_it_flags {
618 /* Exit when fail. */
619 DOIF_FAILOUT = 0x0001,
621 /* Reset iteration position to the device beginning. */
624 /* There is up layer component uses the iteration. */
625 DOIF_OUTUSED = 0x0004,
628 /* otable based iteration needs to use the common DT interation APIs.
629 * To initialize the iteration, it needs call dio_it::init() firstly.
630 * Here is how the otable based iteration should prepare arguments to
631 * call dt_it_ops::init().
633 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
634 * is composed of two parts:
635 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
636 #define DT_OTABLE_IT_FLAGS_SHIFT 16
637 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
640 struct lu_device dd_lu_dev;
641 const struct dt_device_operations *dd_ops;
644 * List of dt_txn_callback (see below). This is not protected in any
645 * way, because callbacks are supposed to be added/deleted only during
646 * single-threaded start-up shut-down procedures.
648 cfs_list_t dd_txn_callbacks;
651 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
652 void dt_device_fini(struct dt_device *dev);
654 static inline int lu_device_is_dt(const struct lu_device *d)
656 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
659 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
661 LASSERT(lu_device_is_dt(l));
662 return container_of0(l, struct dt_device, dd_lu_dev);
666 struct lu_object do_lu;
667 const struct dt_object_operations *do_ops;
668 const struct dt_body_operations *do_body_ops;
669 const struct dt_index_operations *do_index_ops;
673 * In-core representation of per-device local object OID storage
675 struct local_oid_storage {
676 /* all initialized llog systems on this node linked by this */
679 /* how many handle's reference this los has */
680 cfs_atomic_t los_refcount;
681 struct dt_device *los_dev;
682 struct dt_object *los_obj;
684 /* data used to generate new fids */
685 struct mutex los_id_lock;
690 static inline struct dt_object *lu2dt(struct lu_object *l)
692 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
693 return container_of0(l, struct dt_object, do_lu);
696 int dt_object_init(struct dt_object *obj,
697 struct lu_object_header *h, struct lu_device *d);
699 void dt_object_fini(struct dt_object *obj);
701 static inline int dt_object_exists(const struct dt_object *dt)
703 return lu_object_exists(&dt->do_lu);
707 * This is the general purpose transaction handle.
708 * 1. Transaction Life Cycle
709 * This transaction handle is allocated upon starting a new transaction,
710 * and deallocated after this transaction is committed.
711 * 2. Transaction Nesting
712 * We do _NOT_ support nested transaction. So, every thread should only
713 * have one active transaction, and a transaction only belongs to one
714 * thread. Due to this, transaction handle need no reference count.
715 * 3. Transaction & dt_object locking
716 * dt_object locks should be taken inside transaction.
717 * 4. Transaction & RPC
718 * No RPC request should be issued inside transaction.
721 /** the dt device on which the transactions are executed */
722 struct dt_device *th_dev;
724 /** additional tags (layers can add in declare) */
727 /** context for this transaction, tag is LCT_TX_HANDLE */
728 struct lu_context th_ctx;
730 /** the last operation result in this transaction.
731 * this value is used in recovery */
734 /** whether we need sync commit */
737 /* local transation, no need to inform other layers */
742 * Transaction call-backs.
744 * These are invoked by osd (or underlying transaction engine) when
745 * transaction changes state.
747 * Call-backs are used by upper layers to modify transaction parameters and to
748 * perform some actions on for each transaction state transition. Typical
749 * example is mdt registering call-back to write into last-received file
750 * before each transaction commit.
752 struct dt_txn_callback {
753 int (*dtc_txn_start)(const struct lu_env *env,
754 struct thandle *txn, void *cookie);
755 int (*dtc_txn_stop)(const struct lu_env *env,
756 struct thandle *txn, void *cookie);
757 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
760 cfs_list_t dtc_linkage;
763 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
764 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
766 int dt_txn_hook_start(const struct lu_env *env,
767 struct dt_device *dev, struct thandle *txn);
768 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
769 void dt_txn_hook_commit(struct thandle *txn);
771 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
774 * Callback function used for parsing path.
775 * \see llo_store_resolve
777 typedef int (*dt_entry_func_t)(const struct lu_env *env,
781 #define DT_MAX_PATH 1024
783 int dt_path_parser(const struct lu_env *env,
784 char *local, dt_entry_func_t entry_func,
787 struct dt_object *dt_store_open(const struct lu_env *env,
788 struct dt_device *dt,
790 const char *filename,
793 struct dt_object *dt_find_or_create(const struct lu_env *env,
794 struct dt_device *dt,
795 const struct lu_fid *fid,
796 struct dt_object_format *dof,
797 struct lu_attr *attr);
799 struct dt_object *dt_locate_at(const struct lu_env *env,
800 struct dt_device *dev,
801 const struct lu_fid *fid,
802 struct lu_device *top_dev);
803 static inline struct dt_object *
804 dt_locate(const struct lu_env *env, struct dt_device *dev,
805 const struct lu_fid *fid)
807 return dt_locate_at(env, dev, fid, dev->dd_lu_dev.ld_site->ls_top_dev);
811 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
812 const struct lu_fid *first_fid,
813 struct local_oid_storage **los);
814 void local_oid_storage_fini(const struct lu_env *env,
815 struct local_oid_storage *los);
816 int local_object_fid_generate(const struct lu_env *env,
817 struct local_oid_storage *los,
819 int local_object_declare_create(const struct lu_env *env,
820 struct local_oid_storage *los,
822 struct lu_attr *attr,
823 struct dt_object_format *dof,
825 int local_object_create(const struct lu_env *env,
826 struct local_oid_storage *los,
828 struct lu_attr *attr, struct dt_object_format *dof,
830 struct dt_object *local_file_find_or_create(const struct lu_env *env,
831 struct local_oid_storage *los,
832 struct dt_object *parent,
833 const char *name, __u32 mode);
834 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
835 struct dt_device *dt,
836 const struct lu_fid *fid,
837 struct dt_object *parent,
841 local_index_find_or_create(const struct lu_env *env,
842 struct local_oid_storage *los,
843 struct dt_object *parent,
844 const char *name, __u32 mode,
845 const struct dt_index_features *ft);
847 local_index_find_or_create_with_fid(const struct lu_env *env,
848 struct dt_device *dt,
849 const struct lu_fid *fid,
850 struct dt_object *parent,
851 const char *name, __u32 mode,
852 const struct dt_index_features *ft);
854 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
855 const char *name, struct lu_fid *fid);
857 static inline int dt_object_sync(const struct lu_env *env,
862 LASSERT(o->do_ops->do_object_sync);
863 return o->do_ops->do_object_sync(env, o);
866 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
868 void dt_version_set(const struct lu_env *env, struct dt_object *o,
869 dt_obj_version_t version, struct thandle *th);
870 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
873 int dt_read(const struct lu_env *env, struct dt_object *dt,
874 struct lu_buf *buf, loff_t *pos);
875 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
876 struct lu_buf *buf, loff_t *pos);
877 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
878 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
879 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
880 union lu_page *lp, int nob,
881 const struct dt_it_ops *iops,
882 struct dt_it *it, __u32 attr, void *arg);
883 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
884 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
886 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
887 struct idx_info *ii, const struct lu_rdpg *rdpg);
889 static inline struct thandle *dt_trans_create(const struct lu_env *env,
892 LASSERT(d->dd_ops->dt_trans_create);
893 return d->dd_ops->dt_trans_create(env, d);
896 static inline int dt_trans_start(const struct lu_env *env,
897 struct dt_device *d, struct thandle *th)
899 LASSERT(d->dd_ops->dt_trans_start);
900 return d->dd_ops->dt_trans_start(env, d, th);
903 /* for this transaction hooks shouldn't be called */
904 static inline int dt_trans_start_local(const struct lu_env *env,
905 struct dt_device *d, struct thandle *th)
907 LASSERT(d->dd_ops->dt_trans_start);
909 return d->dd_ops->dt_trans_start(env, d, th);
912 static inline int dt_trans_stop(const struct lu_env *env,
913 struct dt_device *d, struct thandle *th)
915 LASSERT(d->dd_ops->dt_trans_stop);
916 return d->dd_ops->dt_trans_stop(env, th);
919 static inline int dt_trans_cb_add(struct thandle *th,
920 struct dt_txn_commit_cb *dcb)
922 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
923 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
924 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
929 static inline int dt_declare_record_write(const struct lu_env *env,
930 struct dt_object *dt,
931 int size, loff_t pos,
936 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
938 LASSERT(dt->do_body_ops);
939 LASSERT(dt->do_body_ops->dbo_declare_write);
940 rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
944 static inline int dt_declare_create(const struct lu_env *env,
945 struct dt_object *dt,
946 struct lu_attr *attr,
947 struct dt_allocation_hint *hint,
948 struct dt_object_format *dof,
953 LASSERT(dt->do_ops->do_declare_create);
954 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
957 static inline int dt_create(const struct lu_env *env,
958 struct dt_object *dt,
959 struct lu_attr *attr,
960 struct dt_allocation_hint *hint,
961 struct dt_object_format *dof,
966 LASSERT(dt->do_ops->do_create);
967 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
970 static inline int dt_declare_destroy(const struct lu_env *env,
971 struct dt_object *dt,
976 LASSERT(dt->do_ops->do_declare_destroy);
977 return dt->do_ops->do_declare_destroy(env, dt, th);
980 static inline int dt_destroy(const struct lu_env *env,
981 struct dt_object *dt,
986 LASSERT(dt->do_ops->do_destroy);
987 return dt->do_ops->do_destroy(env, dt, th);
990 static inline void dt_read_lock(const struct lu_env *env,
991 struct dt_object *dt,
996 LASSERT(dt->do_ops->do_read_lock);
997 dt->do_ops->do_read_lock(env, dt, role);
1000 static inline void dt_write_lock(const struct lu_env *env,
1001 struct dt_object *dt,
1005 LASSERT(dt->do_ops);
1006 LASSERT(dt->do_ops->do_write_lock);
1007 dt->do_ops->do_write_lock(env, dt, role);
1010 static inline void dt_read_unlock(const struct lu_env *env,
1011 struct dt_object *dt)
1014 LASSERT(dt->do_ops);
1015 LASSERT(dt->do_ops->do_read_unlock);
1016 dt->do_ops->do_read_unlock(env, dt);
1019 static inline void dt_write_unlock(const struct lu_env *env,
1020 struct dt_object *dt)
1023 LASSERT(dt->do_ops);
1024 LASSERT(dt->do_ops->do_write_unlock);
1025 dt->do_ops->do_write_unlock(env, dt);
1028 static inline int dt_write_locked(const struct lu_env *env,
1029 struct dt_object *dt)
1032 LASSERT(dt->do_ops);
1033 LASSERT(dt->do_ops->do_write_locked);
1034 return dt->do_ops->do_write_locked(env, dt);
1037 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
1038 struct lu_attr *la, void *arg)
1041 LASSERT(dt->do_ops);
1042 LASSERT(dt->do_ops->do_attr_get);
1043 return dt->do_ops->do_attr_get(env, dt, la, arg);
1046 static inline int dt_declare_attr_set(const struct lu_env *env,
1047 struct dt_object *dt,
1048 const struct lu_attr *la,
1052 LASSERT(dt->do_ops);
1053 LASSERT(dt->do_ops->do_declare_attr_set);
1054 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
1057 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
1058 const struct lu_attr *la, struct thandle *th,
1059 struct lustre_capa *capa)
1062 LASSERT(dt->do_ops);
1063 LASSERT(dt->do_ops->do_attr_set);
1064 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
1067 static inline int dt_declare_ref_add(const struct lu_env *env,
1068 struct dt_object *dt, struct thandle *th)
1071 LASSERT(dt->do_ops);
1072 LASSERT(dt->do_ops->do_declare_ref_add);
1073 return dt->do_ops->do_declare_ref_add(env, dt, th);
1076 static inline int dt_ref_add(const struct lu_env *env,
1077 struct dt_object *dt, struct thandle *th)
1080 LASSERT(dt->do_ops);
1081 LASSERT(dt->do_ops->do_ref_add);
1082 return dt->do_ops->do_ref_add(env, dt, th);
1085 static inline int dt_declare_ref_del(const struct lu_env *env,
1086 struct dt_object *dt, struct thandle *th)
1089 LASSERT(dt->do_ops);
1090 LASSERT(dt->do_ops->do_declare_ref_del);
1091 return dt->do_ops->do_declare_ref_del(env, dt, th);
1094 static inline int dt_ref_del(const struct lu_env *env,
1095 struct dt_object *dt, struct thandle *th)
1098 LASSERT(dt->do_ops);
1099 LASSERT(dt->do_ops->do_ref_del);
1100 return dt->do_ops->do_ref_del(env, dt, th);
1103 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1104 struct dt_object *dt,
1105 struct lustre_capa *old, __u64 opc)
1108 LASSERT(dt->do_ops);
1109 LASSERT(dt->do_ops->do_ref_del);
1110 return dt->do_ops->do_capa_get(env, dt, old, opc);
1113 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1114 struct niobuf_remote *rnb,
1115 struct niobuf_local *lnb, int rw,
1116 struct lustre_capa *capa)
1119 LASSERT(d->do_body_ops);
1120 LASSERT(d->do_body_ops->dbo_bufs_get);
1121 return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1122 rnb->len, lnb, rw, capa);
1125 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1126 struct niobuf_local *lnb, int n)
1129 LASSERT(d->do_body_ops);
1130 LASSERT(d->do_body_ops->dbo_bufs_put);
1131 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1134 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1135 struct niobuf_local *lnb, int n)
1138 LASSERT(d->do_body_ops);
1139 LASSERT(d->do_body_ops->dbo_write_prep);
1140 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1143 static inline int dt_declare_write_commit(const struct lu_env *env,
1144 struct dt_object *d,
1145 struct niobuf_local *lnb,
1146 int n, struct thandle *th)
1148 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1149 LASSERT(th != NULL);
1150 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1154 static inline int dt_write_commit(const struct lu_env *env,
1155 struct dt_object *d, struct niobuf_local *lnb,
1156 int n, struct thandle *th)
1159 LASSERT(d->do_body_ops);
1160 LASSERT(d->do_body_ops->dbo_write_commit);
1161 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1164 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1165 struct niobuf_local *lnb, int n)
1168 LASSERT(d->do_body_ops);
1169 LASSERT(d->do_body_ops->dbo_read_prep);
1170 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1173 static inline int dt_declare_punch(const struct lu_env *env,
1174 struct dt_object *dt, __u64 start,
1175 __u64 end, struct thandle *th)
1178 LASSERT(dt->do_body_ops);
1179 LASSERT(dt->do_body_ops->do_declare_punch);
1180 return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1183 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1184 __u64 start, __u64 end, struct thandle *th,
1185 struct lustre_capa *capa)
1188 LASSERT(dt->do_body_ops);
1189 LASSERT(dt->do_body_ops->do_punch);
1190 return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1193 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1194 struct ll_user_fiemap *fm)
1197 if (d->do_body_ops == NULL)
1199 if (d->do_body_ops->dbo_fiemap_get == NULL)
1201 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1204 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1205 struct obd_statfs *osfs)
1208 LASSERT(dev->dd_ops);
1209 LASSERT(dev->dd_ops->dt_statfs);
1210 return dev->dd_ops->dt_statfs(env, dev, osfs);
1213 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1217 LASSERT(dev->dd_ops);
1218 LASSERT(dev->dd_ops->dt_root_get);
1219 return dev->dd_ops->dt_root_get(env, dev, f);
1222 static inline void dt_conf_get(const struct lu_env *env,
1223 const struct dt_device *dev,
1224 struct dt_device_param *param)
1227 LASSERT(dev->dd_ops);
1228 LASSERT(dev->dd_ops->dt_conf_get);
1229 return dev->dd_ops->dt_conf_get(env, dev, param);
1232 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1235 LASSERT(dev->dd_ops);
1236 LASSERT(dev->dd_ops->dt_sync);
1237 return dev->dd_ops->dt_sync(env, dev);
1240 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1243 LASSERT(dev->dd_ops);
1244 LASSERT(dev->dd_ops->dt_ro);
1245 return dev->dd_ops->dt_ro(env, dev);
1248 static inline int dt_declare_insert(const struct lu_env *env,
1249 struct dt_object *dt,
1250 const struct dt_rec *rec,
1251 const struct dt_key *key,
1255 LASSERT(dt->do_index_ops);
1256 LASSERT(dt->do_index_ops->dio_declare_insert);
1257 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1260 static inline int dt_insert(const struct lu_env *env,
1261 struct dt_object *dt,
1262 const struct dt_rec *rec,
1263 const struct dt_key *key,
1265 struct lustre_capa *capa,
1269 LASSERT(dt->do_index_ops);
1270 LASSERT(dt->do_index_ops->dio_insert);
1271 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1275 static inline int dt_declare_xattr_del(const struct lu_env *env,
1276 struct dt_object *dt,
1281 LASSERT(dt->do_ops);
1282 LASSERT(dt->do_ops->do_declare_xattr_del);
1283 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1286 static inline int dt_xattr_del(const struct lu_env *env,
1287 struct dt_object *dt, const char *name,
1289 struct lustre_capa *capa)
1292 LASSERT(dt->do_ops);
1293 LASSERT(dt->do_ops->do_xattr_del);
1294 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1297 static inline int dt_declare_xattr_set(const struct lu_env *env,
1298 struct dt_object *dt,
1299 const struct lu_buf *buf,
1300 const char *name, int fl,
1304 LASSERT(dt->do_ops);
1305 LASSERT(dt->do_ops->do_declare_xattr_set);
1306 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1309 static inline int dt_xattr_set(const struct lu_env *env,
1310 struct dt_object *dt, const struct lu_buf *buf,
1311 const char *name, int fl, struct thandle *th,
1312 struct lustre_capa *capa)
1315 LASSERT(dt->do_ops);
1316 LASSERT(dt->do_ops->do_xattr_set);
1317 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1320 static inline int dt_xattr_get(const struct lu_env *env,
1321 struct dt_object *dt, struct lu_buf *buf,
1322 const char *name, struct lustre_capa *capa)
1325 LASSERT(dt->do_ops);
1326 LASSERT(dt->do_ops->do_xattr_get);
1327 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1330 static inline int dt_xattr_list(const struct lu_env *env,
1331 struct dt_object *dt, struct lu_buf *buf,
1332 struct lustre_capa *capa)
1335 LASSERT(dt->do_ops);
1336 LASSERT(dt->do_ops->do_xattr_list);
1337 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1340 static inline int dt_declare_delete(const struct lu_env *env,
1341 struct dt_object *dt,
1342 const struct dt_key *key,
1346 LASSERT(dt->do_index_ops);
1347 LASSERT(dt->do_index_ops->dio_declare_delete);
1348 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1351 static inline int dt_delete(const struct lu_env *env,
1352 struct dt_object *dt,
1353 const struct dt_key *key,
1355 struct lustre_capa *capa)
1358 LASSERT(dt->do_index_ops);
1359 LASSERT(dt->do_index_ops->dio_delete);
1360 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1363 static inline int dt_commit_async(const struct lu_env *env,
1364 struct dt_device *dev)
1367 LASSERT(dev->dd_ops);
1368 LASSERT(dev->dd_ops->dt_commit_async);
1369 return dev->dd_ops->dt_commit_async(env, dev);
1372 static inline int dt_init_capa_ctxt(const struct lu_env *env,
1373 struct dt_device *dev,
1374 int mode, unsigned long timeout,
1375 __u32 alg, struct lustre_capa_key *keys)
1378 LASSERT(dev->dd_ops);
1379 LASSERT(dev->dd_ops->dt_init_capa_ctxt);
1380 return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
1381 timeout, alg, keys);
1384 static inline int dt_lookup(const struct lu_env *env,
1385 struct dt_object *dt,
1387 const struct dt_key *key,
1388 struct lustre_capa *capa)
1393 LASSERT(dt->do_index_ops);
1394 LASSERT(dt->do_index_ops->dio_lookup);
1396 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1404 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1406 struct dt_find_hint {
1407 struct lu_fid *dfh_fid;
1408 struct dt_device *dfh_dt;
1409 struct dt_object *dfh_o;
1412 struct dt_thread_info {
1413 char dti_buf[DT_MAX_PATH];
1414 struct dt_find_hint dti_dfh;
1415 struct lu_attr dti_attr;
1416 struct lu_fid dti_fid;
1417 struct dt_object_format dti_dof;
1418 struct lustre_mdt_attrs dti_lma;
1419 struct lu_buf dti_lb;
1423 extern struct lu_context_key dt_key;
1425 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
1427 struct dt_thread_info *dti;
1429 dti = lu_context_key_get(&env->le_ctx, &dt_key);
1434 #endif /* __LUSTRE_DT_OBJECT_H */