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, Intel Corporation.
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;
70 struct ldlm_enqueue_info;
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);
179 struct dt_index_features {
180 /** required feature flags from enum dt_index_flags */
182 /** minimal required key size */
183 size_t dif_keysize_min;
184 /** maximal required key size, 0 if no limit */
185 size_t dif_keysize_max;
186 /** minimal required record size */
187 size_t dif_recsize_min;
188 /** maximal required record size, 0 if no limit */
189 size_t dif_recsize_max;
190 /** pointer size for record */
194 enum dt_index_flags {
195 /** index supports variable sized keys */
196 DT_IND_VARKEY = 1 << 0,
197 /** index supports variable sized records */
198 DT_IND_VARREC = 1 << 1,
199 /** index can be modified */
200 DT_IND_UPDATE = 1 << 2,
201 /** index supports records with non-unique (duplicate) keys */
202 DT_IND_NONUNQ = 1 << 3,
204 * index support fixed-size keys sorted with natural numerical way
205 * and is able to return left-side value if no exact value found
207 DT_IND_RANGE = 1 << 4,
211 * Features, required from index to support file system directories (mapping
214 extern const struct dt_index_features dt_directory_features;
215 extern const struct dt_index_features dt_otable_features;
217 /* index features supported by the accounting objects */
218 extern const struct dt_index_features dt_acct_features;
220 /* index features supported by the quota global indexes */
221 extern const struct dt_index_features dt_quota_glb_features;
223 /* index features supported by the quota slave indexes */
224 extern const struct dt_index_features dt_quota_slv_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;
266 * special index need feature as parameter to create
270 const struct dt_index_features *di_feat;
275 enum dt_format_type dt_mode_to_dft(__u32 mode);
277 typedef __u64 dt_obj_version_t;
280 * Per-dt-object operations.
282 struct dt_object_operations {
283 void (*do_read_lock)(const struct lu_env *env,
284 struct dt_object *dt, unsigned role);
285 void (*do_write_lock)(const struct lu_env *env,
286 struct dt_object *dt, unsigned role);
287 void (*do_read_unlock)(const struct lu_env *env,
288 struct dt_object *dt);
289 void (*do_write_unlock)(const struct lu_env *env,
290 struct dt_object *dt);
291 int (*do_write_locked)(const struct lu_env *env,
292 struct dt_object *dt);
294 * Note: following ->do_{x,}attr_{set,get}() operations are very
295 * similar to ->moo_{x,}attr_{set,get}() operations in struct
296 * md_object_operations (see md_object.h). These operations are not in
297 * lu_object_operations, because ->do_{x,}attr_set() versions take
298 * transaction handle as an argument (this transaction is started by
299 * caller). We might factor ->do_{x,}attr_get() into
300 * lu_object_operations, but that would break existing symmetry.
304 * Return standard attributes.
306 * precondition: lu_object_exists(&dt->do_lu);
308 int (*do_attr_get)(const struct lu_env *env,
309 struct dt_object *dt, struct lu_attr *attr,
310 struct lustre_capa *capa);
312 * Set standard attributes.
314 * precondition: dt_object_exists(dt);
316 int (*do_declare_attr_set)(const struct lu_env *env,
317 struct dt_object *dt,
318 const struct lu_attr *attr,
319 struct thandle *handle);
320 int (*do_attr_set)(const struct lu_env *env,
321 struct dt_object *dt,
322 const struct lu_attr *attr,
323 struct thandle *handle,
324 struct lustre_capa *capa);
326 * Return a value of an extended attribute.
328 * precondition: dt_object_exists(dt);
330 int (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
331 struct lu_buf *buf, const char *name,
332 struct lustre_capa *capa);
334 * Set value of an extended attribute.
336 * \a fl - flags from enum lu_xattr_flags
338 * precondition: dt_object_exists(dt);
340 int (*do_declare_xattr_set)(const struct lu_env *env,
341 struct dt_object *dt,
342 const struct lu_buf *buf,
343 const char *name, int fl,
344 struct thandle *handle);
345 int (*do_xattr_set)(const struct lu_env *env,
346 struct dt_object *dt, const struct lu_buf *buf,
347 const char *name, int fl, struct thandle *handle,
348 struct lustre_capa *capa);
350 * Delete existing extended attribute.
352 * precondition: dt_object_exists(dt);
354 int (*do_declare_xattr_del)(const struct lu_env *env,
355 struct dt_object *dt,
356 const char *name, struct thandle *handle);
357 int (*do_xattr_del)(const struct lu_env *env,
358 struct dt_object *dt,
359 const char *name, struct thandle *handle,
360 struct lustre_capa *capa);
362 * Place list of existing extended attributes into \a buf (which has
365 * precondition: dt_object_exists(dt);
367 int (*do_xattr_list)(const struct lu_env *env,
368 struct dt_object *dt, struct lu_buf *buf,
369 struct lustre_capa *capa);
371 * Init allocation hint using parent object and child mode.
372 * (1) The \a parent might be NULL if this is a partial creation for
374 * (2) The type of child is in \a child_mode.
375 * (3) The result hint is stored in \a ah;
377 void (*do_ah_init)(const struct lu_env *env,
378 struct dt_allocation_hint *ah,
379 struct dt_object *parent,
380 struct dt_object *child,
381 cfs_umode_t child_mode);
383 * Create new object on this device.
385 * precondition: !dt_object_exists(dt);
386 * postcondition: ergo(result == 0, dt_object_exists(dt));
388 int (*do_declare_create)(const struct lu_env *env,
389 struct dt_object *dt,
390 struct lu_attr *attr,
391 struct dt_allocation_hint *hint,
392 struct dt_object_format *dof,
394 int (*do_create)(const struct lu_env *env, struct dt_object *dt,
395 struct lu_attr *attr,
396 struct dt_allocation_hint *hint,
397 struct dt_object_format *dof,
401 Destroy object on this device
402 * precondition: !dt_object_exists(dt);
403 * postcondition: ergo(result == 0, dt_object_exists(dt));
405 int (*do_declare_destroy)(const struct lu_env *env,
406 struct dt_object *dt,
408 int (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
412 * Announce that this object is going to be used as an index. This
413 * operation check that object supports indexing operations and
414 * installs appropriate dt_index_operations vector on success.
416 * Also probes for features. Operation is successful if all required
417 * features are supported.
419 int (*do_index_try)(const struct lu_env *env,
420 struct dt_object *dt,
421 const struct dt_index_features *feat);
423 * Add nlink of the object
424 * precondition: dt_object_exists(dt);
426 int (*do_declare_ref_add)(const struct lu_env *env,
427 struct dt_object *dt, struct thandle *th);
428 int (*do_ref_add)(const struct lu_env *env,
429 struct dt_object *dt, struct thandle *th);
431 * Del nlink of the object
432 * precondition: dt_object_exists(dt);
434 int (*do_declare_ref_del)(const struct lu_env *env,
435 struct dt_object *dt, struct thandle *th);
436 int (*do_ref_del)(const struct lu_env *env,
437 struct dt_object *dt, struct thandle *th);
439 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
440 struct dt_object *dt,
441 struct lustre_capa *old,
443 int (*do_object_sync)(const struct lu_env *, struct dt_object *);
445 * Get object info of next level. Currently, only get inode from osd.
446 * This is only used by quota b=16542
447 * precondition: dt_object_exists(dt);
449 int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
454 * Per-dt-object operations on "file body".
456 struct dt_body_operations {
458 * precondition: dt_object_exists(dt);
460 ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
461 struct lu_buf *buf, loff_t *pos,
462 struct lustre_capa *capa);
464 * precondition: dt_object_exists(dt);
466 ssize_t (*dbo_declare_write)(const struct lu_env *env,
467 struct dt_object *dt,
468 const loff_t size, loff_t pos,
469 struct thandle *handle);
470 ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
471 const struct lu_buf *buf, loff_t *pos,
472 struct thandle *handle, struct lustre_capa *capa,
475 * methods for zero-copy IO
479 * precondition: dt_object_exists(dt);
483 * > 0 - number of local buffers prepared
485 int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
486 loff_t pos, ssize_t len, struct niobuf_local *lb,
487 int rw, struct lustre_capa *capa);
489 * precondition: dt_object_exists(dt);
491 int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
492 struct niobuf_local *lb, int nr);
494 * precondition: dt_object_exists(dt);
496 int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
497 struct niobuf_local *lb, int nr);
499 * precondition: dt_object_exists(dt);
501 int (*dbo_declare_write_commit)(const struct lu_env *env,
502 struct dt_object *dt,
503 struct niobuf_local *,
504 int, struct thandle *);
506 * precondition: dt_object_exists(dt);
508 int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
509 struct niobuf_local *, int, struct thandle *);
511 * precondition: dt_object_exists(dt);
513 int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
514 struct niobuf_local *lnb, int nr);
515 int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
516 struct ll_user_fiemap *fm);
518 * Punch object's content
519 * precondition: regular object, not index
521 int (*do_declare_punch)(const struct lu_env *, struct dt_object *,
522 __u64, __u64, struct thandle *th);
523 int (*do_punch)(const struct lu_env *env, struct dt_object *dt,
524 __u64 start, __u64 end, struct thandle *th,
525 struct lustre_capa *capa);
528 struct dt_lock_operations {
529 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
530 struct lustre_handle *lh,
531 struct ldlm_enqueue_info *einfo,
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;
677 const struct dt_lock_operations *do_lock_ops;
681 * In-core representation of per-device local object OID storage
683 struct local_oid_storage {
684 /* all initialized llog systems on this node linked by this */
687 /* how many handle's reference this los has */
688 cfs_atomic_t los_refcount;
689 struct dt_device *los_dev;
690 struct dt_object *los_obj;
692 /* data used to generate new fids */
693 struct mutex los_id_lock;
698 static inline struct dt_object *lu2dt(struct lu_object *l)
700 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
701 return container_of0(l, struct dt_object, do_lu);
704 int dt_object_init(struct dt_object *obj,
705 struct lu_object_header *h, struct lu_device *d);
707 void dt_object_fini(struct dt_object *obj);
709 static inline int dt_object_exists(const struct dt_object *dt)
711 return lu_object_exists(&dt->do_lu);
714 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
716 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
717 return container_of0(o, struct dt_object, do_lu);
721 * This is the general purpose transaction handle.
722 * 1. Transaction Life Cycle
723 * This transaction handle is allocated upon starting a new transaction,
724 * and deallocated after this transaction is committed.
725 * 2. Transaction Nesting
726 * We do _NOT_ support nested transaction. So, every thread should only
727 * have one active transaction, and a transaction only belongs to one
728 * thread. Due to this, transaction handle need no reference count.
729 * 3. Transaction & dt_object locking
730 * dt_object locks should be taken inside transaction.
731 * 4. Transaction & RPC
732 * No RPC request should be issued inside transaction.
735 /** the dt device on which the transactions are executed */
736 struct dt_device *th_dev;
738 /** context for this transaction, tag is LCT_TX_HANDLE */
739 struct lu_context th_ctx;
741 /** additional tags (layers can add in declare) */
744 /** the last operation result in this transaction.
745 * this value is used in recovery */
748 /** whether we need sync commit */
751 /* local transation, no need to inform other layers */
754 /* In DNE, one transaction can be disassemblied into
755 * updates on several different MDTs, and these updates
756 * will be attached to th_remote_update_list per target.
757 * Only single thread will access the list, no need lock
759 cfs_list_t th_remote_update_list;
760 struct update_request *th_current_request;
764 * Transaction call-backs.
766 * These are invoked by osd (or underlying transaction engine) when
767 * transaction changes state.
769 * Call-backs are used by upper layers to modify transaction parameters and to
770 * perform some actions on for each transaction state transition. Typical
771 * example is mdt registering call-back to write into last-received file
772 * before each transaction commit.
774 struct dt_txn_callback {
775 int (*dtc_txn_start)(const struct lu_env *env,
776 struct thandle *txn, void *cookie);
777 int (*dtc_txn_stop)(const struct lu_env *env,
778 struct thandle *txn, void *cookie);
779 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
782 cfs_list_t dtc_linkage;
785 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
786 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
788 int dt_txn_hook_start(const struct lu_env *env,
789 struct dt_device *dev, struct thandle *txn);
790 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
791 void dt_txn_hook_commit(struct thandle *txn);
793 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
796 * Callback function used for parsing path.
797 * \see llo_store_resolve
799 typedef int (*dt_entry_func_t)(const struct lu_env *env,
803 #define DT_MAX_PATH 1024
805 int dt_path_parser(const struct lu_env *env,
806 char *local, dt_entry_func_t entry_func,
809 struct dt_object *dt_store_open(const struct lu_env *env,
810 struct dt_device *dt,
812 const char *filename,
815 struct dt_object *dt_find_or_create(const struct lu_env *env,
816 struct dt_device *dt,
817 const struct lu_fid *fid,
818 struct dt_object_format *dof,
819 struct lu_attr *attr);
821 struct dt_object *dt_locate_at(const struct lu_env *env,
822 struct dt_device *dev,
823 const struct lu_fid *fid,
824 struct lu_device *top_dev);
825 static inline struct dt_object *
826 dt_locate(const struct lu_env *env, struct dt_device *dev,
827 const struct lu_fid *fid)
829 return dt_locate_at(env, dev, fid, dev->dd_lu_dev.ld_site->ls_top_dev);
833 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
834 const struct lu_fid *first_fid,
835 struct local_oid_storage **los);
836 void local_oid_storage_fini(const struct lu_env *env,
837 struct local_oid_storage *los);
838 int local_object_fid_generate(const struct lu_env *env,
839 struct local_oid_storage *los,
841 int local_object_declare_create(const struct lu_env *env,
842 struct local_oid_storage *los,
844 struct lu_attr *attr,
845 struct dt_object_format *dof,
847 int local_object_create(const struct lu_env *env,
848 struct local_oid_storage *los,
850 struct lu_attr *attr, struct dt_object_format *dof,
852 struct dt_object *local_file_find_or_create(const struct lu_env *env,
853 struct local_oid_storage *los,
854 struct dt_object *parent,
855 const char *name, __u32 mode);
856 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
857 struct dt_device *dt,
858 const struct lu_fid *fid,
859 struct dt_object *parent,
863 local_index_find_or_create(const struct lu_env *env,
864 struct local_oid_storage *los,
865 struct dt_object *parent,
866 const char *name, __u32 mode,
867 const struct dt_index_features *ft);
869 local_index_find_or_create_with_fid(const struct lu_env *env,
870 struct dt_device *dt,
871 const struct lu_fid *fid,
872 struct dt_object *parent,
873 const char *name, __u32 mode,
874 const struct dt_index_features *ft);
876 static inline int dt_object_lock(const struct lu_env *env,
877 struct dt_object *o, struct lustre_handle *lh,
878 struct ldlm_enqueue_info *einfo,
882 LASSERT(o->do_lock_ops);
883 LASSERT(o->do_lock_ops->do_object_lock);
884 return o->do_lock_ops->do_object_lock(env, o, lh, einfo, policy);
887 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
888 const char *name, struct lu_fid *fid);
890 static inline int dt_object_sync(const struct lu_env *env,
895 LASSERT(o->do_ops->do_object_sync);
896 return o->do_ops->do_object_sync(env, o);
899 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
901 void dt_version_set(const struct lu_env *env, struct dt_object *o,
902 dt_obj_version_t version, struct thandle *th);
903 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
906 int dt_read(const struct lu_env *env, struct dt_object *dt,
907 struct lu_buf *buf, loff_t *pos);
908 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
909 struct lu_buf *buf, loff_t *pos);
910 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
911 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
912 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
913 union lu_page *lp, int nob,
914 const struct dt_it_ops *iops,
915 struct dt_it *it, __u32 attr, void *arg);
916 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
917 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
919 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
920 struct idx_info *ii, const struct lu_rdpg *rdpg);
922 static inline struct thandle *dt_trans_create(const struct lu_env *env,
925 LASSERT(d->dd_ops->dt_trans_create);
926 return d->dd_ops->dt_trans_create(env, d);
929 static inline int dt_trans_start(const struct lu_env *env,
930 struct dt_device *d, struct thandle *th)
932 LASSERT(d->dd_ops->dt_trans_start);
933 return d->dd_ops->dt_trans_start(env, d, th);
936 /* for this transaction hooks shouldn't be called */
937 static inline int dt_trans_start_local(const struct lu_env *env,
938 struct dt_device *d, struct thandle *th)
940 LASSERT(d->dd_ops->dt_trans_start);
942 return d->dd_ops->dt_trans_start(env, d, th);
945 static inline int dt_trans_stop(const struct lu_env *env,
946 struct dt_device *d, struct thandle *th)
948 LASSERT(d->dd_ops->dt_trans_stop);
949 return d->dd_ops->dt_trans_stop(env, th);
952 static inline int dt_trans_cb_add(struct thandle *th,
953 struct dt_txn_commit_cb *dcb)
955 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
956 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
957 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
962 static inline int dt_declare_record_write(const struct lu_env *env,
963 struct dt_object *dt,
964 int size, loff_t pos,
969 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
971 LASSERT(dt->do_body_ops);
972 LASSERT(dt->do_body_ops->dbo_declare_write);
973 rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
977 static inline int dt_declare_create(const struct lu_env *env,
978 struct dt_object *dt,
979 struct lu_attr *attr,
980 struct dt_allocation_hint *hint,
981 struct dt_object_format *dof,
986 LASSERT(dt->do_ops->do_declare_create);
987 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
990 static inline int dt_create(const struct lu_env *env,
991 struct dt_object *dt,
992 struct lu_attr *attr,
993 struct dt_allocation_hint *hint,
994 struct dt_object_format *dof,
999 LASSERT(dt->do_ops->do_create);
1000 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
1003 static inline int dt_declare_destroy(const struct lu_env *env,
1004 struct dt_object *dt,
1008 LASSERT(dt->do_ops);
1009 LASSERT(dt->do_ops->do_declare_destroy);
1010 return dt->do_ops->do_declare_destroy(env, dt, th);
1013 static inline int dt_destroy(const struct lu_env *env,
1014 struct dt_object *dt,
1018 LASSERT(dt->do_ops);
1019 LASSERT(dt->do_ops->do_destroy);
1020 return dt->do_ops->do_destroy(env, dt, th);
1023 static inline void dt_read_lock(const struct lu_env *env,
1024 struct dt_object *dt,
1028 LASSERT(dt->do_ops);
1029 LASSERT(dt->do_ops->do_read_lock);
1030 dt->do_ops->do_read_lock(env, dt, role);
1033 static inline void dt_write_lock(const struct lu_env *env,
1034 struct dt_object *dt,
1038 LASSERT(dt->do_ops);
1039 LASSERT(dt->do_ops->do_write_lock);
1040 dt->do_ops->do_write_lock(env, dt, role);
1043 static inline void dt_read_unlock(const struct lu_env *env,
1044 struct dt_object *dt)
1047 LASSERT(dt->do_ops);
1048 LASSERT(dt->do_ops->do_read_unlock);
1049 dt->do_ops->do_read_unlock(env, dt);
1052 static inline void dt_write_unlock(const struct lu_env *env,
1053 struct dt_object *dt)
1056 LASSERT(dt->do_ops);
1057 LASSERT(dt->do_ops->do_write_unlock);
1058 dt->do_ops->do_write_unlock(env, dt);
1061 static inline int dt_write_locked(const struct lu_env *env,
1062 struct dt_object *dt)
1065 LASSERT(dt->do_ops);
1066 LASSERT(dt->do_ops->do_write_locked);
1067 return dt->do_ops->do_write_locked(env, dt);
1070 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
1071 struct lu_attr *la, void *arg)
1074 LASSERT(dt->do_ops);
1075 LASSERT(dt->do_ops->do_attr_get);
1076 return dt->do_ops->do_attr_get(env, dt, la, arg);
1079 static inline int dt_declare_attr_set(const struct lu_env *env,
1080 struct dt_object *dt,
1081 const struct lu_attr *la,
1085 LASSERT(dt->do_ops);
1086 LASSERT(dt->do_ops->do_declare_attr_set);
1087 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
1090 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
1091 const struct lu_attr *la, struct thandle *th,
1092 struct lustre_capa *capa)
1095 LASSERT(dt->do_ops);
1096 LASSERT(dt->do_ops->do_attr_set);
1097 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
1100 static inline int dt_declare_ref_add(const struct lu_env *env,
1101 struct dt_object *dt, struct thandle *th)
1104 LASSERT(dt->do_ops);
1105 LASSERT(dt->do_ops->do_declare_ref_add);
1106 return dt->do_ops->do_declare_ref_add(env, dt, th);
1109 static inline int dt_ref_add(const struct lu_env *env,
1110 struct dt_object *dt, struct thandle *th)
1113 LASSERT(dt->do_ops);
1114 LASSERT(dt->do_ops->do_ref_add);
1115 return dt->do_ops->do_ref_add(env, dt, th);
1118 static inline int dt_declare_ref_del(const struct lu_env *env,
1119 struct dt_object *dt, struct thandle *th)
1122 LASSERT(dt->do_ops);
1123 LASSERT(dt->do_ops->do_declare_ref_del);
1124 return dt->do_ops->do_declare_ref_del(env, dt, th);
1127 static inline int dt_ref_del(const struct lu_env *env,
1128 struct dt_object *dt, struct thandle *th)
1131 LASSERT(dt->do_ops);
1132 LASSERT(dt->do_ops->do_ref_del);
1133 return dt->do_ops->do_ref_del(env, dt, th);
1136 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1137 struct dt_object *dt,
1138 struct lustre_capa *old, __u64 opc)
1141 LASSERT(dt->do_ops);
1142 LASSERT(dt->do_ops->do_ref_del);
1143 return dt->do_ops->do_capa_get(env, dt, old, opc);
1146 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1147 struct niobuf_remote *rnb,
1148 struct niobuf_local *lnb, int rw,
1149 struct lustre_capa *capa)
1152 LASSERT(d->do_body_ops);
1153 LASSERT(d->do_body_ops->dbo_bufs_get);
1154 return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1155 rnb->len, lnb, rw, capa);
1158 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1159 struct niobuf_local *lnb, int n)
1162 LASSERT(d->do_body_ops);
1163 LASSERT(d->do_body_ops->dbo_bufs_put);
1164 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1167 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1168 struct niobuf_local *lnb, int n)
1171 LASSERT(d->do_body_ops);
1172 LASSERT(d->do_body_ops->dbo_write_prep);
1173 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1176 static inline int dt_declare_write_commit(const struct lu_env *env,
1177 struct dt_object *d,
1178 struct niobuf_local *lnb,
1179 int n, struct thandle *th)
1181 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1182 LASSERT(th != NULL);
1183 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1187 static inline int dt_write_commit(const struct lu_env *env,
1188 struct dt_object *d, struct niobuf_local *lnb,
1189 int n, struct thandle *th)
1192 LASSERT(d->do_body_ops);
1193 LASSERT(d->do_body_ops->dbo_write_commit);
1194 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1197 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1198 struct niobuf_local *lnb, int n)
1201 LASSERT(d->do_body_ops);
1202 LASSERT(d->do_body_ops->dbo_read_prep);
1203 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1206 static inline int dt_declare_punch(const struct lu_env *env,
1207 struct dt_object *dt, __u64 start,
1208 __u64 end, struct thandle *th)
1211 LASSERT(dt->do_body_ops);
1212 LASSERT(dt->do_body_ops->do_declare_punch);
1213 return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1216 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1217 __u64 start, __u64 end, struct thandle *th,
1218 struct lustre_capa *capa)
1221 LASSERT(dt->do_body_ops);
1222 LASSERT(dt->do_body_ops->do_punch);
1223 return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1226 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1227 struct ll_user_fiemap *fm)
1230 if (d->do_body_ops == NULL)
1232 if (d->do_body_ops->dbo_fiemap_get == NULL)
1234 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1237 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1238 struct obd_statfs *osfs)
1241 LASSERT(dev->dd_ops);
1242 LASSERT(dev->dd_ops->dt_statfs);
1243 return dev->dd_ops->dt_statfs(env, dev, osfs);
1246 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1250 LASSERT(dev->dd_ops);
1251 LASSERT(dev->dd_ops->dt_root_get);
1252 return dev->dd_ops->dt_root_get(env, dev, f);
1255 static inline void dt_conf_get(const struct lu_env *env,
1256 const struct dt_device *dev,
1257 struct dt_device_param *param)
1260 LASSERT(dev->dd_ops);
1261 LASSERT(dev->dd_ops->dt_conf_get);
1262 return dev->dd_ops->dt_conf_get(env, dev, param);
1265 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1268 LASSERT(dev->dd_ops);
1269 LASSERT(dev->dd_ops->dt_sync);
1270 return dev->dd_ops->dt_sync(env, dev);
1273 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1276 LASSERT(dev->dd_ops);
1277 LASSERT(dev->dd_ops->dt_ro);
1278 return dev->dd_ops->dt_ro(env, dev);
1281 static inline int dt_declare_insert(const struct lu_env *env,
1282 struct dt_object *dt,
1283 const struct dt_rec *rec,
1284 const struct dt_key *key,
1288 LASSERT(dt->do_index_ops);
1289 LASSERT(dt->do_index_ops->dio_declare_insert);
1290 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1293 static inline int dt_insert(const struct lu_env *env,
1294 struct dt_object *dt,
1295 const struct dt_rec *rec,
1296 const struct dt_key *key,
1298 struct lustre_capa *capa,
1302 LASSERT(dt->do_index_ops);
1303 LASSERT(dt->do_index_ops->dio_insert);
1304 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1308 static inline int dt_declare_xattr_del(const struct lu_env *env,
1309 struct dt_object *dt,
1314 LASSERT(dt->do_ops);
1315 LASSERT(dt->do_ops->do_declare_xattr_del);
1316 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1319 static inline int dt_xattr_del(const struct lu_env *env,
1320 struct dt_object *dt, const char *name,
1322 struct lustre_capa *capa)
1325 LASSERT(dt->do_ops);
1326 LASSERT(dt->do_ops->do_xattr_del);
1327 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1330 static inline int dt_declare_xattr_set(const struct lu_env *env,
1331 struct dt_object *dt,
1332 const struct lu_buf *buf,
1333 const char *name, int fl,
1337 LASSERT(dt->do_ops);
1338 LASSERT(dt->do_ops->do_declare_xattr_set);
1339 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1342 static inline int dt_xattr_set(const struct lu_env *env,
1343 struct dt_object *dt, const struct lu_buf *buf,
1344 const char *name, int fl, struct thandle *th,
1345 struct lustre_capa *capa)
1348 LASSERT(dt->do_ops);
1349 LASSERT(dt->do_ops->do_xattr_set);
1350 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1353 static inline int dt_xattr_get(const struct lu_env *env,
1354 struct dt_object *dt, struct lu_buf *buf,
1355 const char *name, struct lustre_capa *capa)
1358 LASSERT(dt->do_ops);
1359 LASSERT(dt->do_ops->do_xattr_get);
1360 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1363 static inline int dt_xattr_list(const struct lu_env *env,
1364 struct dt_object *dt, struct lu_buf *buf,
1365 struct lustre_capa *capa)
1368 LASSERT(dt->do_ops);
1369 LASSERT(dt->do_ops->do_xattr_list);
1370 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1373 static inline int dt_declare_delete(const struct lu_env *env,
1374 struct dt_object *dt,
1375 const struct dt_key *key,
1379 LASSERT(dt->do_index_ops);
1380 LASSERT(dt->do_index_ops->dio_declare_delete);
1381 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1384 static inline int dt_delete(const struct lu_env *env,
1385 struct dt_object *dt,
1386 const struct dt_key *key,
1388 struct lustre_capa *capa)
1391 LASSERT(dt->do_index_ops);
1392 LASSERT(dt->do_index_ops->dio_delete);
1393 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1396 static inline int dt_commit_async(const struct lu_env *env,
1397 struct dt_device *dev)
1400 LASSERT(dev->dd_ops);
1401 LASSERT(dev->dd_ops->dt_commit_async);
1402 return dev->dd_ops->dt_commit_async(env, dev);
1405 static inline int dt_init_capa_ctxt(const struct lu_env *env,
1406 struct dt_device *dev,
1407 int mode, unsigned long timeout,
1408 __u32 alg, struct lustre_capa_key *keys)
1411 LASSERT(dev->dd_ops);
1412 LASSERT(dev->dd_ops->dt_init_capa_ctxt);
1413 return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
1414 timeout, alg, keys);
1417 static inline int dt_lookup(const struct lu_env *env,
1418 struct dt_object *dt,
1420 const struct dt_key *key,
1421 struct lustre_capa *capa)
1426 LASSERT(dt->do_index_ops);
1427 LASSERT(dt->do_index_ops->dio_lookup);
1429 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1437 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1439 struct dt_find_hint {
1440 struct lu_fid *dfh_fid;
1441 struct dt_device *dfh_dt;
1442 struct dt_object *dfh_o;
1445 struct dt_thread_info {
1446 char dti_buf[DT_MAX_PATH];
1447 struct dt_find_hint dti_dfh;
1448 struct lu_attr dti_attr;
1449 struct lu_fid dti_fid;
1450 struct dt_object_format dti_dof;
1451 struct lustre_mdt_attrs dti_lma;
1452 struct lu_buf dti_lb;
1456 extern struct lu_context_key dt_key;
1458 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
1460 struct dt_thread_info *dti;
1462 dti = lu_context_key_get(&env->le_ctx, &dt_key);
1467 #endif /* __LUSTRE_DT_OBJECT_H */