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;
226 /* index features supported by the quota global indexes */
227 extern const struct dt_index_features dt_quota_glb_features;
229 /* index features supported by the quota slave indexes */
230 extern const struct dt_index_features dt_quota_slv_features;
233 * This is a general purpose dt allocation hint.
234 * It now contains the parent object.
235 * It can contain any allocation hint in the future.
237 struct dt_allocation_hint {
238 struct dt_object *dah_parent;
243 * object type specifier.
246 enum dt_format_type {
251 /** for special index */
253 /** for symbolic link */
258 * object format specifier.
260 struct dt_object_format {
261 /** type for dt object */
262 enum dt_format_type dof_type;
272 * special index need feature as parameter to create
276 const struct dt_index_features *di_feat;
281 enum dt_format_type dt_mode_to_dft(__u32 mode);
283 typedef __u64 dt_obj_version_t;
286 * Per-dt-object operations.
288 struct dt_object_operations {
289 void (*do_read_lock)(const struct lu_env *env,
290 struct dt_object *dt, unsigned role);
291 void (*do_write_lock)(const struct lu_env *env,
292 struct dt_object *dt, unsigned role);
293 void (*do_read_unlock)(const struct lu_env *env,
294 struct dt_object *dt);
295 void (*do_write_unlock)(const struct lu_env *env,
296 struct dt_object *dt);
297 int (*do_write_locked)(const struct lu_env *env,
298 struct dt_object *dt);
300 * Note: following ->do_{x,}attr_{set,get}() operations are very
301 * similar to ->moo_{x,}attr_{set,get}() operations in struct
302 * md_object_operations (see md_object.h). These operations are not in
303 * lu_object_operations, because ->do_{x,}attr_set() versions take
304 * transaction handle as an argument (this transaction is started by
305 * caller). We might factor ->do_{x,}attr_get() into
306 * lu_object_operations, but that would break existing symmetry.
310 * Return standard attributes.
312 * precondition: lu_object_exists(&dt->do_lu);
314 int (*do_attr_get)(const struct lu_env *env,
315 struct dt_object *dt, struct lu_attr *attr,
316 struct lustre_capa *capa);
318 * Set standard attributes.
320 * precondition: dt_object_exists(dt);
322 int (*do_declare_attr_set)(const struct lu_env *env,
323 struct dt_object *dt,
324 const struct lu_attr *attr,
325 struct thandle *handle);
326 int (*do_attr_set)(const struct lu_env *env,
327 struct dt_object *dt,
328 const struct lu_attr *attr,
329 struct thandle *handle,
330 struct lustre_capa *capa);
332 * Return a value of an extended attribute.
334 * precondition: dt_object_exists(dt);
336 int (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
337 struct lu_buf *buf, const char *name,
338 struct lustre_capa *capa);
340 * Set value of an extended attribute.
342 * \a fl - flags from enum lu_xattr_flags
344 * precondition: dt_object_exists(dt);
346 int (*do_declare_xattr_set)(const struct lu_env *env,
347 struct dt_object *dt,
348 const struct lu_buf *buf,
349 const char *name, int fl,
350 struct thandle *handle);
351 int (*do_xattr_set)(const struct lu_env *env,
352 struct dt_object *dt, const struct lu_buf *buf,
353 const char *name, int fl, struct thandle *handle,
354 struct lustre_capa *capa);
356 * Delete existing extended attribute.
358 * precondition: dt_object_exists(dt);
360 int (*do_declare_xattr_del)(const struct lu_env *env,
361 struct dt_object *dt,
362 const char *name, struct thandle *handle);
363 int (*do_xattr_del)(const struct lu_env *env,
364 struct dt_object *dt,
365 const char *name, struct thandle *handle,
366 struct lustre_capa *capa);
368 * Place list of existing extended attributes into \a buf (which has
371 * precondition: dt_object_exists(dt);
373 int (*do_xattr_list)(const struct lu_env *env,
374 struct dt_object *dt, struct lu_buf *buf,
375 struct lustre_capa *capa);
377 * Init allocation hint using parent object and child mode.
378 * (1) The \a parent might be NULL if this is a partial creation for
380 * (2) The type of child is in \a child_mode.
381 * (3) The result hint is stored in \a ah;
383 void (*do_ah_init)(const struct lu_env *env,
384 struct dt_allocation_hint *ah,
385 struct dt_object *parent,
386 struct dt_object *child,
387 cfs_umode_t child_mode);
389 * Create new object on this device.
391 * precondition: !dt_object_exists(dt);
392 * postcondition: ergo(result == 0, dt_object_exists(dt));
394 int (*do_declare_create)(const struct lu_env *env,
395 struct dt_object *dt,
396 struct lu_attr *attr,
397 struct dt_allocation_hint *hint,
398 struct dt_object_format *dof,
400 int (*do_create)(const struct lu_env *env, struct dt_object *dt,
401 struct lu_attr *attr,
402 struct dt_allocation_hint *hint,
403 struct dt_object_format *dof,
407 Destroy object on this device
408 * precondition: !dt_object_exists(dt);
409 * postcondition: ergo(result == 0, dt_object_exists(dt));
411 int (*do_declare_destroy)(const struct lu_env *env,
412 struct dt_object *dt,
414 int (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
418 * Announce that this object is going to be used as an index. This
419 * operation check that object supports indexing operations and
420 * installs appropriate dt_index_operations vector on success.
422 * Also probes for features. Operation is successful if all required
423 * features are supported.
425 int (*do_index_try)(const struct lu_env *env,
426 struct dt_object *dt,
427 const struct dt_index_features *feat);
429 * Add nlink of the object
430 * precondition: dt_object_exists(dt);
432 int (*do_declare_ref_add)(const struct lu_env *env,
433 struct dt_object *dt, struct thandle *th);
434 int (*do_ref_add)(const struct lu_env *env,
435 struct dt_object *dt, struct thandle *th);
437 * Del nlink of the object
438 * precondition: dt_object_exists(dt);
440 int (*do_declare_ref_del)(const struct lu_env *env,
441 struct dt_object *dt, struct thandle *th);
442 int (*do_ref_del)(const struct lu_env *env,
443 struct dt_object *dt, struct thandle *th);
445 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
446 struct dt_object *dt,
447 struct lustre_capa *old,
449 int (*do_object_sync)(const struct lu_env *, struct dt_object *);
451 * Get object info of next level. Currently, only get inode from osd.
452 * This is only used by quota b=16542
453 * precondition: dt_object_exists(dt);
455 int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
460 * Per-dt-object operations on "file body".
462 struct dt_body_operations {
464 * precondition: dt_object_exists(dt);
466 ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
467 struct lu_buf *buf, loff_t *pos,
468 struct lustre_capa *capa);
470 * precondition: dt_object_exists(dt);
472 ssize_t (*dbo_declare_write)(const struct lu_env *env,
473 struct dt_object *dt,
474 const loff_t size, loff_t pos,
475 struct thandle *handle);
476 ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
477 const struct lu_buf *buf, loff_t *pos,
478 struct thandle *handle, struct lustre_capa *capa,
481 * methods for zero-copy IO
485 * precondition: dt_object_exists(dt);
489 * > 0 - number of local buffers prepared
491 int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
492 loff_t pos, ssize_t len, struct niobuf_local *lb,
493 int rw, struct lustre_capa *capa);
495 * precondition: dt_object_exists(dt);
497 int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
498 struct niobuf_local *lb, int nr);
500 * precondition: dt_object_exists(dt);
502 int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
503 struct niobuf_local *lb, int nr);
505 * precondition: dt_object_exists(dt);
507 int (*dbo_declare_write_commit)(const struct lu_env *env,
508 struct dt_object *dt,
509 struct niobuf_local *,
510 int, struct thandle *);
512 * precondition: dt_object_exists(dt);
514 int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
515 struct niobuf_local *, int, struct thandle *);
517 * precondition: dt_object_exists(dt);
519 int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
520 struct niobuf_local *lnb, int nr);
521 int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
522 struct ll_user_fiemap *fm);
524 * Punch object's content
525 * precondition: regular object, not index
527 int (*do_declare_punch)(const struct lu_env *, struct dt_object *,
528 __u64, __u64, struct thandle *th);
529 int (*do_punch)(const struct lu_env *env, struct dt_object *dt,
530 __u64 start, __u64 end, struct thandle *th,
531 struct lustre_capa *capa);
535 * Incomplete type of index record.
540 * Incomplete type of index key.
545 * Incomplete type of dt iterator.
550 * Per-dt-object operations on object as index.
552 struct dt_index_operations {
554 * precondition: dt_object_exists(dt);
556 int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
557 struct dt_rec *rec, const struct dt_key *key,
558 struct lustre_capa *capa);
560 * precondition: dt_object_exists(dt);
562 int (*dio_declare_insert)(const struct lu_env *env,
563 struct dt_object *dt,
564 const struct dt_rec *rec,
565 const struct dt_key *key,
566 struct thandle *handle);
567 int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
568 const struct dt_rec *rec, const struct dt_key *key,
569 struct thandle *handle, struct lustre_capa *capa,
572 * precondition: dt_object_exists(dt);
574 int (*dio_declare_delete)(const struct lu_env *env,
575 struct dt_object *dt,
576 const struct dt_key *key,
577 struct thandle *handle);
578 int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
579 const struct dt_key *key, struct thandle *handle,
580 struct lustre_capa *capa);
586 * Allocate and initialize new iterator.
588 * precondition: dt_object_exists(dt);
590 struct dt_it *(*init)(const struct lu_env *env,
591 struct dt_object *dt,
593 struct lustre_capa *capa);
594 void (*fini)(const struct lu_env *env,
596 int (*get)(const struct lu_env *env,
598 const struct dt_key *key);
599 void (*put)(const struct lu_env *env,
601 int (*next)(const struct lu_env *env,
603 struct dt_key *(*key)(const struct lu_env *env,
604 const struct dt_it *di);
605 int (*key_size)(const struct lu_env *env,
606 const struct dt_it *di);
607 int (*rec)(const struct lu_env *env,
608 const struct dt_it *di,
611 __u64 (*store)(const struct lu_env *env,
612 const struct dt_it *di);
613 int (*load)(const struct lu_env *env,
614 const struct dt_it *di, __u64 hash);
615 int (*key_rec)(const struct lu_env *env,
616 const struct dt_it *di, void* key_rec);
620 enum dt_otable_it_valid {
621 DOIV_ERROR_HANDLE = 0x0001,
624 enum dt_otable_it_flags {
625 /* Exit when fail. */
626 DOIF_FAILOUT = 0x0001,
628 /* Reset iteration position to the device beginning. */
631 /* There is up layer component uses the iteration. */
632 DOIF_OUTUSED = 0x0004,
635 /* otable based iteration needs to use the common DT interation APIs.
636 * To initialize the iteration, it needs call dio_it::init() firstly.
637 * Here is how the otable based iteration should prepare arguments to
638 * call dt_it_ops::init().
640 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
641 * is composed of two parts:
642 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
643 #define DT_OTABLE_IT_FLAGS_SHIFT 16
644 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
647 struct lu_device dd_lu_dev;
648 const struct dt_device_operations *dd_ops;
651 * List of dt_txn_callback (see below). This is not protected in any
652 * way, because callbacks are supposed to be added/deleted only during
653 * single-threaded start-up shut-down procedures.
655 cfs_list_t dd_txn_callbacks;
658 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
659 void dt_device_fini(struct dt_device *dev);
661 static inline int lu_device_is_dt(const struct lu_device *d)
663 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
666 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
668 LASSERT(lu_device_is_dt(l));
669 return container_of0(l, struct dt_device, dd_lu_dev);
673 struct lu_object do_lu;
674 const struct dt_object_operations *do_ops;
675 const struct dt_body_operations *do_body_ops;
676 const struct dt_index_operations *do_index_ops;
680 * In-core representation of per-device local object OID storage
682 struct local_oid_storage {
683 /* all initialized llog systems on this node linked by this */
686 /* how many handle's reference this los has */
687 cfs_atomic_t los_refcount;
688 struct dt_device *los_dev;
689 struct dt_object *los_obj;
691 /* data used to generate new fids */
692 cfs_mutex_t los_id_lock;
697 static inline struct dt_object *lu2dt(struct lu_object *l)
699 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
700 return container_of0(l, struct dt_object, do_lu);
703 int dt_object_init(struct dt_object *obj,
704 struct lu_object_header *h, struct lu_device *d);
706 void dt_object_fini(struct dt_object *obj);
708 static inline int dt_object_exists(const struct dt_object *dt)
710 return lu_object_exists(&dt->do_lu);
714 * This is the general purpose transaction handle.
715 * 1. Transaction Life Cycle
716 * This transaction handle is allocated upon starting a new transaction,
717 * and deallocated after this transaction is committed.
718 * 2. Transaction Nesting
719 * We do _NOT_ support nested transaction. So, every thread should only
720 * have one active transaction, and a transaction only belongs to one
721 * thread. Due to this, transaction handle need no reference count.
722 * 3. Transaction & dt_object locking
723 * dt_object locks should be taken inside transaction.
724 * 4. Transaction & RPC
725 * No RPC request should be issued inside transaction.
728 /** the dt device on which the transactions are executed */
729 struct dt_device *th_dev;
731 /** additional tags (layers can add in declare) */
734 /** context for this transaction, tag is LCT_TX_HANDLE */
735 struct lu_context th_ctx;
737 /** the last operation result in this transaction.
738 * this value is used in recovery */
741 /** whether we need sync commit */
744 /* local transation, no need to inform other layers */
749 * Transaction call-backs.
751 * These are invoked by osd (or underlying transaction engine) when
752 * transaction changes state.
754 * Call-backs are used by upper layers to modify transaction parameters and to
755 * perform some actions on for each transaction state transition. Typical
756 * example is mdt registering call-back to write into last-received file
757 * before each transaction commit.
759 struct dt_txn_callback {
760 int (*dtc_txn_start)(const struct lu_env *env,
761 struct thandle *txn, void *cookie);
762 int (*dtc_txn_stop)(const struct lu_env *env,
763 struct thandle *txn, void *cookie);
764 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
767 cfs_list_t dtc_linkage;
770 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
771 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
773 int dt_txn_hook_start(const struct lu_env *env,
774 struct dt_device *dev, struct thandle *txn);
775 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
776 void dt_txn_hook_commit(struct thandle *txn);
778 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
781 * Callback function used for parsing path.
782 * \see llo_store_resolve
784 typedef int (*dt_entry_func_t)(const struct lu_env *env,
788 #define DT_MAX_PATH 1024
790 int dt_path_parser(const struct lu_env *env,
791 char *local, dt_entry_func_t entry_func,
794 struct dt_object *dt_store_open(const struct lu_env *env,
795 struct dt_device *dt,
797 const char *filename,
800 struct dt_object *dt_find_or_create(const struct lu_env *env,
801 struct dt_device *dt,
802 const struct lu_fid *fid,
803 struct dt_object_format *dof,
804 struct lu_attr *attr);
806 struct dt_object *dt_locate_at(const struct lu_env *env,
807 struct dt_device *dev,
808 const struct lu_fid *fid,
809 struct lu_device *top_dev);
810 static inline struct dt_object *
811 dt_locate(const struct lu_env *env, struct dt_device *dev,
812 const struct lu_fid *fid)
814 return dt_locate_at(env, dev, fid, dev->dd_lu_dev.ld_site->ls_top_dev);
818 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
819 const struct lu_fid *first_fid,
820 struct local_oid_storage **los);
821 void local_oid_storage_fini(const struct lu_env *env,
822 struct local_oid_storage *los);
823 int local_object_fid_generate(const struct lu_env *env,
824 struct local_oid_storage *los,
826 int local_object_declare_create(const struct lu_env *env,
827 struct local_oid_storage *los,
829 struct lu_attr *attr,
830 struct dt_object_format *dof,
832 int local_object_create(const struct lu_env *env,
833 struct local_oid_storage *los,
835 struct lu_attr *attr, struct dt_object_format *dof,
837 struct dt_object *local_file_find_or_create(const struct lu_env *env,
838 struct local_oid_storage *los,
839 struct dt_object *parent,
840 const char *name, __u32 mode);
841 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
842 struct dt_device *dt,
843 const struct lu_fid *fid,
844 struct dt_object *parent,
848 local_index_find_or_create(const struct lu_env *env,
849 struct local_oid_storage *los,
850 struct dt_object *parent,
851 const char *name, __u32 mode,
852 const struct dt_index_features *ft);
854 local_index_find_or_create_with_fid(const struct lu_env *env,
855 struct dt_device *dt,
856 const struct lu_fid *fid,
857 struct dt_object *parent,
858 const char *name, __u32 mode,
859 const struct dt_index_features *ft);
861 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
862 const char *name, struct lu_fid *fid);
864 static inline int dt_object_sync(const struct lu_env *env,
869 LASSERT(o->do_ops->do_object_sync);
870 return o->do_ops->do_object_sync(env, o);
873 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
875 void dt_version_set(const struct lu_env *env, struct dt_object *o,
876 dt_obj_version_t version, struct thandle *th);
877 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
880 int dt_read(const struct lu_env *env, struct dt_object *dt,
881 struct lu_buf *buf, loff_t *pos);
882 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
883 struct lu_buf *buf, loff_t *pos);
884 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
885 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
886 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
887 union lu_page *lp, int nob,
888 const struct dt_it_ops *iops,
889 struct dt_it *it, __u32 attr, void *arg);
890 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
891 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
893 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
894 struct idx_info *ii, const struct lu_rdpg *rdpg);
896 static inline struct thandle *dt_trans_create(const struct lu_env *env,
899 LASSERT(d->dd_ops->dt_trans_create);
900 return d->dd_ops->dt_trans_create(env, d);
903 static inline int dt_trans_start(const struct lu_env *env,
904 struct dt_device *d, struct thandle *th)
906 LASSERT(d->dd_ops->dt_trans_start);
907 return d->dd_ops->dt_trans_start(env, d, th);
910 /* for this transaction hooks shouldn't be called */
911 static inline int dt_trans_start_local(const struct lu_env *env,
912 struct dt_device *d, struct thandle *th)
914 LASSERT(d->dd_ops->dt_trans_start);
916 return d->dd_ops->dt_trans_start(env, d, th);
919 static inline int dt_trans_stop(const struct lu_env *env,
920 struct dt_device *d, struct thandle *th)
922 LASSERT(d->dd_ops->dt_trans_stop);
923 return d->dd_ops->dt_trans_stop(env, th);
926 static inline int dt_trans_cb_add(struct thandle *th,
927 struct dt_txn_commit_cb *dcb)
929 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
930 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
931 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
936 static inline int dt_declare_record_write(const struct lu_env *env,
937 struct dt_object *dt,
938 int size, loff_t pos,
943 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
945 LASSERT(dt->do_body_ops);
946 LASSERT(dt->do_body_ops->dbo_declare_write);
947 rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
951 static inline int dt_declare_create(const struct lu_env *env,
952 struct dt_object *dt,
953 struct lu_attr *attr,
954 struct dt_allocation_hint *hint,
955 struct dt_object_format *dof,
960 LASSERT(dt->do_ops->do_declare_create);
961 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
964 static inline int dt_create(const struct lu_env *env,
965 struct dt_object *dt,
966 struct lu_attr *attr,
967 struct dt_allocation_hint *hint,
968 struct dt_object_format *dof,
973 LASSERT(dt->do_ops->do_create);
974 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
977 static inline int dt_declare_destroy(const struct lu_env *env,
978 struct dt_object *dt,
983 LASSERT(dt->do_ops->do_declare_destroy);
984 return dt->do_ops->do_declare_destroy(env, dt, th);
987 static inline int dt_destroy(const struct lu_env *env,
988 struct dt_object *dt,
993 LASSERT(dt->do_ops->do_destroy);
994 return dt->do_ops->do_destroy(env, dt, th);
997 static inline void dt_read_lock(const struct lu_env *env,
998 struct dt_object *dt,
1002 LASSERT(dt->do_ops);
1003 LASSERT(dt->do_ops->do_read_lock);
1004 dt->do_ops->do_read_lock(env, dt, role);
1007 static inline void dt_write_lock(const struct lu_env *env,
1008 struct dt_object *dt,
1012 LASSERT(dt->do_ops);
1013 LASSERT(dt->do_ops->do_write_lock);
1014 dt->do_ops->do_write_lock(env, dt, role);
1017 static inline void dt_read_unlock(const struct lu_env *env,
1018 struct dt_object *dt)
1021 LASSERT(dt->do_ops);
1022 LASSERT(dt->do_ops->do_read_unlock);
1023 dt->do_ops->do_read_unlock(env, dt);
1026 static inline void dt_write_unlock(const struct lu_env *env,
1027 struct dt_object *dt)
1030 LASSERT(dt->do_ops);
1031 LASSERT(dt->do_ops->do_write_unlock);
1032 dt->do_ops->do_write_unlock(env, dt);
1035 static inline int dt_write_locked(const struct lu_env *env,
1036 struct dt_object *dt)
1039 LASSERT(dt->do_ops);
1040 LASSERT(dt->do_ops->do_write_locked);
1041 return dt->do_ops->do_write_locked(env, dt);
1044 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
1045 struct lu_attr *la, void *arg)
1048 LASSERT(dt->do_ops);
1049 LASSERT(dt->do_ops->do_attr_get);
1050 return dt->do_ops->do_attr_get(env, dt, la, arg);
1053 static inline int dt_declare_attr_set(const struct lu_env *env,
1054 struct dt_object *dt,
1055 const struct lu_attr *la,
1059 LASSERT(dt->do_ops);
1060 LASSERT(dt->do_ops->do_declare_attr_set);
1061 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
1064 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
1065 const struct lu_attr *la, struct thandle *th,
1066 struct lustre_capa *capa)
1069 LASSERT(dt->do_ops);
1070 LASSERT(dt->do_ops->do_attr_set);
1071 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
1074 static inline int dt_declare_ref_add(const struct lu_env *env,
1075 struct dt_object *dt, struct thandle *th)
1078 LASSERT(dt->do_ops);
1079 LASSERT(dt->do_ops->do_declare_ref_add);
1080 return dt->do_ops->do_declare_ref_add(env, dt, th);
1083 static inline int dt_ref_add(const struct lu_env *env,
1084 struct dt_object *dt, struct thandle *th)
1087 LASSERT(dt->do_ops);
1088 LASSERT(dt->do_ops->do_ref_add);
1089 return dt->do_ops->do_ref_add(env, dt, th);
1092 static inline int dt_declare_ref_del(const struct lu_env *env,
1093 struct dt_object *dt, struct thandle *th)
1096 LASSERT(dt->do_ops);
1097 LASSERT(dt->do_ops->do_declare_ref_del);
1098 return dt->do_ops->do_declare_ref_del(env, dt, th);
1101 static inline int dt_ref_del(const struct lu_env *env,
1102 struct dt_object *dt, struct thandle *th)
1105 LASSERT(dt->do_ops);
1106 LASSERT(dt->do_ops->do_ref_del);
1107 return dt->do_ops->do_ref_del(env, dt, th);
1110 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1111 struct dt_object *dt,
1112 struct lustre_capa *old, __u64 opc)
1115 LASSERT(dt->do_ops);
1116 LASSERT(dt->do_ops->do_ref_del);
1117 return dt->do_ops->do_capa_get(env, dt, old, opc);
1120 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1121 struct niobuf_remote *rnb,
1122 struct niobuf_local *lnb, int rw,
1123 struct lustre_capa *capa)
1126 LASSERT(d->do_body_ops);
1127 LASSERT(d->do_body_ops->dbo_bufs_get);
1128 return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1129 rnb->len, lnb, rw, capa);
1132 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1133 struct niobuf_local *lnb, int n)
1136 LASSERT(d->do_body_ops);
1137 LASSERT(d->do_body_ops->dbo_bufs_put);
1138 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1141 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1142 struct niobuf_local *lnb, int n)
1145 LASSERT(d->do_body_ops);
1146 LASSERT(d->do_body_ops->dbo_write_prep);
1147 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1150 static inline int dt_declare_write_commit(const struct lu_env *env,
1151 struct dt_object *d,
1152 struct niobuf_local *lnb,
1153 int n, struct thandle *th)
1155 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1156 LASSERT(th != NULL);
1157 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1161 static inline int dt_write_commit(const struct lu_env *env,
1162 struct dt_object *d, struct niobuf_local *lnb,
1163 int n, struct thandle *th)
1166 LASSERT(d->do_body_ops);
1167 LASSERT(d->do_body_ops->dbo_write_commit);
1168 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1171 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1172 struct niobuf_local *lnb, int n)
1175 LASSERT(d->do_body_ops);
1176 LASSERT(d->do_body_ops->dbo_read_prep);
1177 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1180 static inline int dt_declare_punch(const struct lu_env *env,
1181 struct dt_object *dt, __u64 start,
1182 __u64 end, struct thandle *th)
1185 LASSERT(dt->do_body_ops);
1186 LASSERT(dt->do_body_ops->do_declare_punch);
1187 return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1190 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1191 __u64 start, __u64 end, struct thandle *th,
1192 struct lustre_capa *capa)
1195 LASSERT(dt->do_body_ops);
1196 LASSERT(dt->do_body_ops->do_punch);
1197 return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1200 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1201 struct ll_user_fiemap *fm)
1204 if (d->do_body_ops == NULL)
1206 if (d->do_body_ops->dbo_fiemap_get == NULL)
1208 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1211 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1212 struct obd_statfs *osfs)
1215 LASSERT(dev->dd_ops);
1216 LASSERT(dev->dd_ops->dt_statfs);
1217 return dev->dd_ops->dt_statfs(env, dev, osfs);
1220 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1224 LASSERT(dev->dd_ops);
1225 LASSERT(dev->dd_ops->dt_root_get);
1226 return dev->dd_ops->dt_root_get(env, dev, f);
1229 static inline void dt_conf_get(const struct lu_env *env,
1230 const struct dt_device *dev,
1231 struct dt_device_param *param)
1234 LASSERT(dev->dd_ops);
1235 LASSERT(dev->dd_ops->dt_conf_get);
1236 return dev->dd_ops->dt_conf_get(env, dev, param);
1239 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1242 LASSERT(dev->dd_ops);
1243 LASSERT(dev->dd_ops->dt_sync);
1244 return dev->dd_ops->dt_sync(env, dev);
1247 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1250 LASSERT(dev->dd_ops);
1251 LASSERT(dev->dd_ops->dt_ro);
1252 return dev->dd_ops->dt_ro(env, dev);
1255 static inline int dt_declare_insert(const struct lu_env *env,
1256 struct dt_object *dt,
1257 const struct dt_rec *rec,
1258 const struct dt_key *key,
1262 LASSERT(dt->do_index_ops);
1263 LASSERT(dt->do_index_ops->dio_declare_insert);
1264 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1267 static inline int dt_insert(const struct lu_env *env,
1268 struct dt_object *dt,
1269 const struct dt_rec *rec,
1270 const struct dt_key *key,
1272 struct lustre_capa *capa,
1276 LASSERT(dt->do_index_ops);
1277 LASSERT(dt->do_index_ops->dio_insert);
1278 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1282 static inline int dt_declare_xattr_del(const struct lu_env *env,
1283 struct dt_object *dt,
1288 LASSERT(dt->do_ops);
1289 LASSERT(dt->do_ops->do_declare_xattr_del);
1290 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1293 static inline int dt_xattr_del(const struct lu_env *env,
1294 struct dt_object *dt, const char *name,
1296 struct lustre_capa *capa)
1299 LASSERT(dt->do_ops);
1300 LASSERT(dt->do_ops->do_xattr_del);
1301 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1304 static inline int dt_declare_xattr_set(const struct lu_env *env,
1305 struct dt_object *dt,
1306 const struct lu_buf *buf,
1307 const char *name, int fl,
1311 LASSERT(dt->do_ops);
1312 LASSERT(dt->do_ops->do_declare_xattr_set);
1313 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1316 static inline int dt_xattr_set(const struct lu_env *env,
1317 struct dt_object *dt, const struct lu_buf *buf,
1318 const char *name, int fl, struct thandle *th,
1319 struct lustre_capa *capa)
1322 LASSERT(dt->do_ops);
1323 LASSERT(dt->do_ops->do_xattr_set);
1324 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1327 static inline int dt_xattr_get(const struct lu_env *env,
1328 struct dt_object *dt, struct lu_buf *buf,
1329 const char *name, struct lustre_capa *capa)
1332 LASSERT(dt->do_ops);
1333 LASSERT(dt->do_ops->do_xattr_get);
1334 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1337 static inline int dt_xattr_list(const struct lu_env *env,
1338 struct dt_object *dt, struct lu_buf *buf,
1339 struct lustre_capa *capa)
1342 LASSERT(dt->do_ops);
1343 LASSERT(dt->do_ops->do_xattr_list);
1344 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1347 static inline int dt_declare_delete(const struct lu_env *env,
1348 struct dt_object *dt,
1349 const struct dt_key *key,
1353 LASSERT(dt->do_index_ops);
1354 LASSERT(dt->do_index_ops->dio_declare_delete);
1355 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1358 static inline int dt_delete(const struct lu_env *env,
1359 struct dt_object *dt,
1360 const struct dt_key *key,
1362 struct lustre_capa *capa)
1365 LASSERT(dt->do_index_ops);
1366 LASSERT(dt->do_index_ops->dio_delete);
1367 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1370 static inline int dt_commit_async(const struct lu_env *env,
1371 struct dt_device *dev)
1374 LASSERT(dev->dd_ops);
1375 LASSERT(dev->dd_ops->dt_commit_async);
1376 return dev->dd_ops->dt_commit_async(env, dev);
1379 static inline int dt_init_capa_ctxt(const struct lu_env *env,
1380 struct dt_device *dev,
1381 int mode, unsigned long timeout,
1382 __u32 alg, struct lustre_capa_key *keys)
1385 LASSERT(dev->dd_ops);
1386 LASSERT(dev->dd_ops->dt_init_capa_ctxt);
1387 return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
1388 timeout, alg, keys);
1391 static inline int dt_lookup(const struct lu_env *env,
1392 struct dt_object *dt,
1394 const struct dt_key *key,
1395 struct lustre_capa *capa)
1400 LASSERT(dt->do_index_ops);
1401 LASSERT(dt->do_index_ops->dio_lookup);
1403 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1411 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1413 struct dt_find_hint {
1414 struct lu_fid *dfh_fid;
1415 struct dt_device *dfh_dt;
1416 struct dt_object *dfh_o;
1419 struct dt_thread_info {
1420 char dti_buf[DT_MAX_PATH];
1421 struct dt_find_hint dti_dfh;
1422 struct lu_attr dti_attr;
1423 struct lu_fid dti_fid;
1424 struct dt_object_format dti_dof;
1425 struct lustre_mdt_attrs dti_lma;
1426 struct lu_buf dti_lb;
1430 extern struct lu_context_key dt_key;
1432 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
1434 struct dt_thread_info *dti;
1436 dti = lu_context_key_get(&env->le_ctx, &dt_key);
1441 #endif /* __LUSTRE_DT_OBJECT_H */