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, 2013, 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;
216 extern const struct dt_index_features dt_lfsck_features;
218 /* index features supported by the accounting objects */
219 extern const struct dt_index_features dt_acct_features;
221 /* index features supported by the quota global indexes */
222 extern const struct dt_index_features dt_quota_glb_features;
224 /* index features supported by the quota slave indexes */
225 extern const struct dt_index_features dt_quota_slv_features;
228 * This is a general purpose dt allocation hint.
229 * It now contains the parent object.
230 * It can contain any allocation hint in the future.
232 struct dt_allocation_hint {
233 struct dt_object *dah_parent;
238 * object type specifier.
241 enum dt_format_type {
246 /** for special index */
248 /** for symbolic link */
253 * object format specifier.
255 struct dt_object_format {
256 /** type for dt object */
257 enum dt_format_type dof_type;
267 * special index need feature as parameter to create
271 const struct dt_index_features *di_feat;
276 enum dt_format_type dt_mode_to_dft(__u32 mode);
278 typedef __u64 dt_obj_version_t;
281 * Per-dt-object operations.
283 struct dt_object_operations {
284 void (*do_read_lock)(const struct lu_env *env,
285 struct dt_object *dt, unsigned role);
286 void (*do_write_lock)(const struct lu_env *env,
287 struct dt_object *dt, unsigned role);
288 void (*do_read_unlock)(const struct lu_env *env,
289 struct dt_object *dt);
290 void (*do_write_unlock)(const struct lu_env *env,
291 struct dt_object *dt);
292 int (*do_write_locked)(const struct lu_env *env,
293 struct dt_object *dt);
295 * Note: following ->do_{x,}attr_{set,get}() operations are very
296 * similar to ->moo_{x,}attr_{set,get}() operations in struct
297 * md_object_operations (see md_object.h). These operations are not in
298 * lu_object_operations, because ->do_{x,}attr_set() versions take
299 * transaction handle as an argument (this transaction is started by
300 * caller). We might factor ->do_{x,}attr_get() into
301 * lu_object_operations, but that would break existing symmetry.
305 * Return standard attributes.
307 * precondition: lu_object_exists(&dt->do_lu);
309 int (*do_attr_get)(const struct lu_env *env,
310 struct dt_object *dt, struct lu_attr *attr,
311 struct lustre_capa *capa);
313 * Set standard attributes.
315 * precondition: dt_object_exists(dt);
317 int (*do_declare_attr_set)(const struct lu_env *env,
318 struct dt_object *dt,
319 const struct lu_attr *attr,
320 struct thandle *handle);
321 int (*do_attr_set)(const struct lu_env *env,
322 struct dt_object *dt,
323 const struct lu_attr *attr,
324 struct thandle *handle,
325 struct lustre_capa *capa);
327 * Return a value of an extended attribute.
329 * precondition: dt_object_exists(dt);
331 int (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
332 struct lu_buf *buf, const char *name,
333 struct lustre_capa *capa);
335 * Set value of an extended attribute.
337 * \a fl - flags from enum lu_xattr_flags
339 * precondition: dt_object_exists(dt);
341 int (*do_declare_xattr_set)(const struct lu_env *env,
342 struct dt_object *dt,
343 const struct lu_buf *buf,
344 const char *name, int fl,
345 struct thandle *handle);
346 int (*do_xattr_set)(const struct lu_env *env,
347 struct dt_object *dt, const struct lu_buf *buf,
348 const char *name, int fl, struct thandle *handle,
349 struct lustre_capa *capa);
351 * Delete existing extended attribute.
353 * precondition: dt_object_exists(dt);
355 int (*do_declare_xattr_del)(const struct lu_env *env,
356 struct dt_object *dt,
357 const char *name, struct thandle *handle);
358 int (*do_xattr_del)(const struct lu_env *env,
359 struct dt_object *dt,
360 const char *name, struct thandle *handle,
361 struct lustre_capa *capa);
363 * Place list of existing extended attributes into \a buf (which has
366 * precondition: dt_object_exists(dt);
368 int (*do_xattr_list)(const struct lu_env *env,
369 struct dt_object *dt, struct lu_buf *buf,
370 struct lustre_capa *capa);
372 * Init allocation hint using parent object and child mode.
373 * (1) The \a parent might be NULL if this is a partial creation for
375 * (2) The type of child is in \a child_mode.
376 * (3) The result hint is stored in \a ah;
378 void (*do_ah_init)(const struct lu_env *env,
379 struct dt_allocation_hint *ah,
380 struct dt_object *parent,
381 struct dt_object *child,
382 cfs_umode_t child_mode);
384 * Create new object on this device.
386 * precondition: !dt_object_exists(dt);
387 * postcondition: ergo(result == 0, dt_object_exists(dt));
389 int (*do_declare_create)(const struct lu_env *env,
390 struct dt_object *dt,
391 struct lu_attr *attr,
392 struct dt_allocation_hint *hint,
393 struct dt_object_format *dof,
395 int (*do_create)(const struct lu_env *env, struct dt_object *dt,
396 struct lu_attr *attr,
397 struct dt_allocation_hint *hint,
398 struct dt_object_format *dof,
402 Destroy object on this device
403 * precondition: !dt_object_exists(dt);
404 * postcondition: ergo(result == 0, dt_object_exists(dt));
406 int (*do_declare_destroy)(const struct lu_env *env,
407 struct dt_object *dt,
409 int (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
413 * Announce that this object is going to be used as an index. This
414 * operation check that object supports indexing operations and
415 * installs appropriate dt_index_operations vector on success.
417 * Also probes for features. Operation is successful if all required
418 * features are supported.
420 int (*do_index_try)(const struct lu_env *env,
421 struct dt_object *dt,
422 const struct dt_index_features *feat);
424 * Add nlink of the object
425 * precondition: dt_object_exists(dt);
427 int (*do_declare_ref_add)(const struct lu_env *env,
428 struct dt_object *dt, struct thandle *th);
429 int (*do_ref_add)(const struct lu_env *env,
430 struct dt_object *dt, struct thandle *th);
432 * Del nlink of the object
433 * precondition: dt_object_exists(dt);
435 int (*do_declare_ref_del)(const struct lu_env *env,
436 struct dt_object *dt, struct thandle *th);
437 int (*do_ref_del)(const struct lu_env *env,
438 struct dt_object *dt, struct thandle *th);
440 struct obd_capa *(*do_capa_get)(const struct lu_env *env,
441 struct dt_object *dt,
442 struct lustre_capa *old,
444 int (*do_object_sync)(const struct lu_env *, struct dt_object *);
446 * Get object info of next level. Currently, only get inode from osd.
447 * This is only used by quota b=16542
448 * precondition: dt_object_exists(dt);
450 int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
456 int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
457 struct lustre_handle *lh,
458 struct ldlm_enqueue_info *einfo,
463 * Per-dt-object operations on "file body".
465 struct dt_body_operations {
467 * precondition: dt_object_exists(dt);
469 ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
470 struct lu_buf *buf, loff_t *pos,
471 struct lustre_capa *capa);
473 * precondition: dt_object_exists(dt);
475 ssize_t (*dbo_declare_write)(const struct lu_env *env,
476 struct dt_object *dt,
477 const loff_t size, loff_t pos,
478 struct thandle *handle);
479 ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
480 const struct lu_buf *buf, loff_t *pos,
481 struct thandle *handle, struct lustre_capa *capa,
484 * methods for zero-copy IO
488 * precondition: dt_object_exists(dt);
492 * > 0 - number of local buffers prepared
494 int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
495 loff_t pos, ssize_t len, struct niobuf_local *lb,
496 int rw, struct lustre_capa *capa);
498 * precondition: dt_object_exists(dt);
500 int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
501 struct niobuf_local *lb, int nr);
503 * precondition: dt_object_exists(dt);
505 int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
506 struct niobuf_local *lb, int nr);
508 * precondition: dt_object_exists(dt);
510 int (*dbo_declare_write_commit)(const struct lu_env *env,
511 struct dt_object *dt,
512 struct niobuf_local *,
513 int, struct thandle *);
515 * precondition: dt_object_exists(dt);
517 int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
518 struct niobuf_local *, int, struct thandle *);
520 * precondition: dt_object_exists(dt);
522 int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
523 struct niobuf_local *lnb, int nr);
524 int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
525 struct ll_user_fiemap *fm);
527 * Punch object's content
528 * precondition: regular object, not index
530 int (*dbo_declare_punch)(const struct lu_env *, struct dt_object *,
531 __u64, __u64, struct thandle *th);
532 int (*dbo_punch)(const struct lu_env *env, struct dt_object *dt,
533 __u64 start, __u64 end, struct thandle *th,
534 struct lustre_capa *capa);
538 * Incomplete type of index record.
543 * Incomplete type of index key.
548 * Incomplete type of dt iterator.
553 * Per-dt-object operations on object as index.
555 struct dt_index_operations {
557 * precondition: dt_object_exists(dt);
559 int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
560 struct dt_rec *rec, const struct dt_key *key,
561 struct lustre_capa *capa);
563 * precondition: dt_object_exists(dt);
565 int (*dio_declare_insert)(const struct lu_env *env,
566 struct dt_object *dt,
567 const struct dt_rec *rec,
568 const struct dt_key *key,
569 struct thandle *handle);
570 int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
571 const struct dt_rec *rec, const struct dt_key *key,
572 struct thandle *handle, struct lustre_capa *capa,
575 * precondition: dt_object_exists(dt);
577 int (*dio_declare_delete)(const struct lu_env *env,
578 struct dt_object *dt,
579 const struct dt_key *key,
580 struct thandle *handle);
581 int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
582 const struct dt_key *key, struct thandle *handle,
583 struct lustre_capa *capa);
589 * Allocate and initialize new iterator.
591 * precondition: dt_object_exists(dt);
593 struct dt_it *(*init)(const struct lu_env *env,
594 struct dt_object *dt,
596 struct lustre_capa *capa);
597 void (*fini)(const struct lu_env *env,
599 int (*get)(const struct lu_env *env,
601 const struct dt_key *key);
602 void (*put)(const struct lu_env *env,
604 int (*next)(const struct lu_env *env,
606 struct dt_key *(*key)(const struct lu_env *env,
607 const struct dt_it *di);
608 int (*key_size)(const struct lu_env *env,
609 const struct dt_it *di);
610 int (*rec)(const struct lu_env *env,
611 const struct dt_it *di,
614 __u64 (*store)(const struct lu_env *env,
615 const struct dt_it *di);
616 int (*load)(const struct lu_env *env,
617 const struct dt_it *di, __u64 hash);
618 int (*key_rec)(const struct lu_env *env,
619 const struct dt_it *di, void* key_rec);
623 enum dt_otable_it_valid {
624 DOIV_ERROR_HANDLE = 0x0001,
625 DOIV_DRYRUN = 0x0002,
628 enum dt_otable_it_flags {
629 /* Exit when fail. */
630 DOIF_FAILOUT = 0x0001,
632 /* Reset iteration position to the device beginning. */
635 /* There is up layer component uses the iteration. */
636 DOIF_OUTUSED = 0x0004,
638 /* Check only without repairing. */
639 DOIF_DRYRUN = 0x0008,
642 /* otable based iteration needs to use the common DT interation APIs.
643 * To initialize the iteration, it needs call dio_it::init() firstly.
644 * Here is how the otable based iteration should prepare arguments to
645 * call dt_it_ops::init().
647 * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
648 * is composed of two parts:
649 * low 16-bits is for valid bits, high 16-bits is for flags bits. */
650 #define DT_OTABLE_IT_FLAGS_SHIFT 16
651 #define DT_OTABLE_IT_FLAGS_MASK 0xffff0000
654 struct lu_device dd_lu_dev;
655 const struct dt_device_operations *dd_ops;
658 * List of dt_txn_callback (see below). This is not protected in any
659 * way, because callbacks are supposed to be added/deleted only during
660 * single-threaded start-up shut-down procedures.
662 cfs_list_t dd_txn_callbacks;
665 int dt_device_init(struct dt_device *dev, struct lu_device_type *t);
666 void dt_device_fini(struct dt_device *dev);
668 static inline int lu_device_is_dt(const struct lu_device *d)
670 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
673 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
675 LASSERT(lu_device_is_dt(l));
676 return container_of0(l, struct dt_device, dd_lu_dev);
680 struct lu_object do_lu;
681 const struct dt_object_operations *do_ops;
682 const struct dt_body_operations *do_body_ops;
683 const struct dt_index_operations *do_index_ops;
687 * In-core representation of per-device local object OID storage
689 struct local_oid_storage {
690 /* all initialized llog systems on this node linked by this */
693 /* how many handle's reference this los has */
694 cfs_atomic_t los_refcount;
695 struct dt_device *los_dev;
696 struct dt_object *los_obj;
698 /* data used to generate new fids */
699 struct mutex los_id_lock;
704 static inline struct dt_object *lu2dt(struct lu_object *l)
706 LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
707 return container_of0(l, struct dt_object, do_lu);
710 int dt_object_init(struct dt_object *obj,
711 struct lu_object_header *h, struct lu_device *d);
713 void dt_object_fini(struct dt_object *obj);
715 static inline int dt_object_exists(const struct dt_object *dt)
717 return lu_object_exists(&dt->do_lu);
720 static inline int dt_object_remote(const struct dt_object *dt)
722 return lu_object_remote(&dt->do_lu);
725 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
727 LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
728 return container_of0(o, struct dt_object, do_lu);
732 * This is the general purpose transaction handle.
733 * 1. Transaction Life Cycle
734 * This transaction handle is allocated upon starting a new transaction,
735 * and deallocated after this transaction is committed.
736 * 2. Transaction Nesting
737 * We do _NOT_ support nested transaction. So, every thread should only
738 * have one active transaction, and a transaction only belongs to one
739 * thread. Due to this, transaction handle need no reference count.
740 * 3. Transaction & dt_object locking
741 * dt_object locks should be taken inside transaction.
742 * 4. Transaction & RPC
743 * No RPC request should be issued inside transaction.
746 /** the dt device on which the transactions are executed */
747 struct dt_device *th_dev;
749 /** context for this transaction, tag is LCT_TX_HANDLE */
750 struct lu_context th_ctx;
752 /** additional tags (layers can add in declare) */
755 /** the last operation result in this transaction.
756 * this value is used in recovery */
759 /** whether we need sync commit */
760 unsigned int th_sync:1;
762 /* local transation, no need to inform other layers */
763 unsigned int th_local:1;
765 /* In DNE, one transaction can be disassemblied into
766 * updates on several different MDTs, and these updates
767 * will be attached to th_remote_update_list per target.
768 * Only single thread will access the list, no need lock
770 cfs_list_t th_remote_update_list;
771 struct update_request *th_current_request;
775 * Transaction call-backs.
777 * These are invoked by osd (or underlying transaction engine) when
778 * transaction changes state.
780 * Call-backs are used by upper layers to modify transaction parameters and to
781 * perform some actions on for each transaction state transition. Typical
782 * example is mdt registering call-back to write into last-received file
783 * before each transaction commit.
785 struct dt_txn_callback {
786 int (*dtc_txn_start)(const struct lu_env *env,
787 struct thandle *txn, void *cookie);
788 int (*dtc_txn_stop)(const struct lu_env *env,
789 struct thandle *txn, void *cookie);
790 void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
793 cfs_list_t dtc_linkage;
796 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
797 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
799 int dt_txn_hook_start(const struct lu_env *env,
800 struct dt_device *dev, struct thandle *txn);
801 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
802 void dt_txn_hook_commit(struct thandle *txn);
804 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
807 * Callback function used for parsing path.
808 * \see llo_store_resolve
810 typedef int (*dt_entry_func_t)(const struct lu_env *env,
814 #define DT_MAX_PATH 1024
816 int dt_path_parser(const struct lu_env *env,
817 char *local, dt_entry_func_t entry_func,
821 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
822 const char *path, struct lu_fid *fid);
824 struct dt_object *dt_store_open(const struct lu_env *env,
825 struct dt_device *dt,
827 const char *filename,
830 struct dt_object *dt_find_or_create(const struct lu_env *env,
831 struct dt_device *dt,
832 const struct lu_fid *fid,
833 struct dt_object_format *dof,
834 struct lu_attr *attr);
836 struct dt_object *dt_locate_at(const struct lu_env *env,
837 struct dt_device *dev,
838 const struct lu_fid *fid,
839 struct lu_device *top_dev);
840 static inline struct dt_object *
841 dt_locate(const struct lu_env *env, struct dt_device *dev,
842 const struct lu_fid *fid)
844 return dt_locate_at(env, dev, fid, dev->dd_lu_dev.ld_site->ls_top_dev);
848 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
849 const struct lu_fid *first_fid,
850 struct local_oid_storage **los);
851 void local_oid_storage_fini(const struct lu_env *env,
852 struct local_oid_storage *los);
853 int local_object_fid_generate(const struct lu_env *env,
854 struct local_oid_storage *los,
856 int local_object_declare_create(const struct lu_env *env,
857 struct local_oid_storage *los,
859 struct lu_attr *attr,
860 struct dt_object_format *dof,
862 int local_object_create(const struct lu_env *env,
863 struct local_oid_storage *los,
865 struct lu_attr *attr, struct dt_object_format *dof,
867 struct dt_object *local_file_find_or_create(const struct lu_env *env,
868 struct local_oid_storage *los,
869 struct dt_object *parent,
870 const char *name, __u32 mode);
871 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
872 struct dt_device *dt,
873 const struct lu_fid *fid,
874 struct dt_object *parent,
878 local_index_find_or_create(const struct lu_env *env,
879 struct local_oid_storage *los,
880 struct dt_object *parent,
881 const char *name, __u32 mode,
882 const struct dt_index_features *ft);
884 local_index_find_or_create_with_fid(const struct lu_env *env,
885 struct dt_device *dt,
886 const struct lu_fid *fid,
887 struct dt_object *parent,
888 const char *name, __u32 mode,
889 const struct dt_index_features *ft);
890 int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
891 struct dt_object *parent, const char *name);
893 static inline int dt_object_lock(const struct lu_env *env,
894 struct dt_object *o, struct lustre_handle *lh,
895 struct ldlm_enqueue_info *einfo,
900 LASSERT(o->do_ops->do_object_lock);
901 return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
904 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
905 const char *name, struct lu_fid *fid);
907 static inline int dt_object_sync(const struct lu_env *env,
912 LASSERT(o->do_ops->do_object_sync);
913 return o->do_ops->do_object_sync(env, o);
916 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
918 void dt_version_set(const struct lu_env *env, struct dt_object *o,
919 dt_obj_version_t version, struct thandle *th);
920 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
923 int dt_read(const struct lu_env *env, struct dt_object *dt,
924 struct lu_buf *buf, loff_t *pos);
925 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
926 struct lu_buf *buf, loff_t *pos);
927 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
928 const struct lu_buf *buf, loff_t *pos, struct thandle *th);
929 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
930 union lu_page *lp, int nob,
931 const struct dt_it_ops *iops,
932 struct dt_it *it, __u32 attr, void *arg);
933 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
934 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
936 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
937 struct idx_info *ii, const struct lu_rdpg *rdpg);
939 static inline struct thandle *dt_trans_create(const struct lu_env *env,
942 LASSERT(d->dd_ops->dt_trans_create);
943 return d->dd_ops->dt_trans_create(env, d);
946 static inline int dt_trans_start(const struct lu_env *env,
947 struct dt_device *d, struct thandle *th)
949 LASSERT(d->dd_ops->dt_trans_start);
950 return d->dd_ops->dt_trans_start(env, d, th);
953 /* for this transaction hooks shouldn't be called */
954 static inline int dt_trans_start_local(const struct lu_env *env,
955 struct dt_device *d, struct thandle *th)
957 LASSERT(d->dd_ops->dt_trans_start);
959 return d->dd_ops->dt_trans_start(env, d, th);
962 static inline int dt_trans_stop(const struct lu_env *env,
963 struct dt_device *d, struct thandle *th)
965 LASSERT(d->dd_ops->dt_trans_stop);
966 return d->dd_ops->dt_trans_stop(env, th);
969 static inline int dt_trans_cb_add(struct thandle *th,
970 struct dt_txn_commit_cb *dcb)
972 LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
973 dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
974 return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
979 static inline int dt_declare_record_write(const struct lu_env *env,
980 struct dt_object *dt,
981 int size, loff_t pos,
986 LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
988 LASSERT(dt->do_body_ops);
989 LASSERT(dt->do_body_ops->dbo_declare_write);
990 rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
994 static inline int dt_declare_create(const struct lu_env *env,
995 struct dt_object *dt,
996 struct lu_attr *attr,
997 struct dt_allocation_hint *hint,
998 struct dt_object_format *dof,
1002 LASSERT(dt->do_ops);
1003 LASSERT(dt->do_ops->do_declare_create);
1004 return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
1007 static inline int dt_create(const struct lu_env *env,
1008 struct dt_object *dt,
1009 struct lu_attr *attr,
1010 struct dt_allocation_hint *hint,
1011 struct dt_object_format *dof,
1015 LASSERT(dt->do_ops);
1016 LASSERT(dt->do_ops->do_create);
1017 return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
1020 static inline int dt_declare_destroy(const struct lu_env *env,
1021 struct dt_object *dt,
1025 LASSERT(dt->do_ops);
1026 LASSERT(dt->do_ops->do_declare_destroy);
1027 return dt->do_ops->do_declare_destroy(env, dt, th);
1030 static inline int dt_destroy(const struct lu_env *env,
1031 struct dt_object *dt,
1035 LASSERT(dt->do_ops);
1036 LASSERT(dt->do_ops->do_destroy);
1037 return dt->do_ops->do_destroy(env, dt, th);
1040 static inline void dt_read_lock(const struct lu_env *env,
1041 struct dt_object *dt,
1045 LASSERT(dt->do_ops);
1046 LASSERT(dt->do_ops->do_read_lock);
1047 dt->do_ops->do_read_lock(env, dt, role);
1050 static inline void dt_write_lock(const struct lu_env *env,
1051 struct dt_object *dt,
1055 LASSERT(dt->do_ops);
1056 LASSERT(dt->do_ops->do_write_lock);
1057 dt->do_ops->do_write_lock(env, dt, role);
1060 static inline void dt_read_unlock(const struct lu_env *env,
1061 struct dt_object *dt)
1064 LASSERT(dt->do_ops);
1065 LASSERT(dt->do_ops->do_read_unlock);
1066 dt->do_ops->do_read_unlock(env, dt);
1069 static inline void dt_write_unlock(const struct lu_env *env,
1070 struct dt_object *dt)
1073 LASSERT(dt->do_ops);
1074 LASSERT(dt->do_ops->do_write_unlock);
1075 dt->do_ops->do_write_unlock(env, dt);
1078 static inline int dt_write_locked(const struct lu_env *env,
1079 struct dt_object *dt)
1082 LASSERT(dt->do_ops);
1083 LASSERT(dt->do_ops->do_write_locked);
1084 return dt->do_ops->do_write_locked(env, dt);
1087 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
1088 struct lu_attr *la, void *arg)
1091 LASSERT(dt->do_ops);
1092 LASSERT(dt->do_ops->do_attr_get);
1093 return dt->do_ops->do_attr_get(env, dt, la, arg);
1096 static inline int dt_declare_attr_set(const struct lu_env *env,
1097 struct dt_object *dt,
1098 const struct lu_attr *la,
1102 LASSERT(dt->do_ops);
1103 LASSERT(dt->do_ops->do_declare_attr_set);
1104 return dt->do_ops->do_declare_attr_set(env, dt, la, th);
1107 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
1108 const struct lu_attr *la, struct thandle *th,
1109 struct lustre_capa *capa)
1112 LASSERT(dt->do_ops);
1113 LASSERT(dt->do_ops->do_attr_set);
1114 return dt->do_ops->do_attr_set(env, dt, la, th, capa);
1117 static inline int dt_declare_ref_add(const struct lu_env *env,
1118 struct dt_object *dt, struct thandle *th)
1121 LASSERT(dt->do_ops);
1122 LASSERT(dt->do_ops->do_declare_ref_add);
1123 return dt->do_ops->do_declare_ref_add(env, dt, th);
1126 static inline int dt_ref_add(const struct lu_env *env,
1127 struct dt_object *dt, struct thandle *th)
1130 LASSERT(dt->do_ops);
1131 LASSERT(dt->do_ops->do_ref_add);
1132 return dt->do_ops->do_ref_add(env, dt, th);
1135 static inline int dt_declare_ref_del(const struct lu_env *env,
1136 struct dt_object *dt, struct thandle *th)
1139 LASSERT(dt->do_ops);
1140 LASSERT(dt->do_ops->do_declare_ref_del);
1141 return dt->do_ops->do_declare_ref_del(env, dt, th);
1144 static inline int dt_ref_del(const struct lu_env *env,
1145 struct dt_object *dt, struct thandle *th)
1148 LASSERT(dt->do_ops);
1149 LASSERT(dt->do_ops->do_ref_del);
1150 return dt->do_ops->do_ref_del(env, dt, th);
1153 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1154 struct dt_object *dt,
1155 struct lustre_capa *old, __u64 opc)
1158 LASSERT(dt->do_ops);
1159 LASSERT(dt->do_ops->do_ref_del);
1160 return dt->do_ops->do_capa_get(env, dt, old, opc);
1163 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1164 struct niobuf_remote *rnb,
1165 struct niobuf_local *lnb, int rw,
1166 struct lustre_capa *capa)
1169 LASSERT(d->do_body_ops);
1170 LASSERT(d->do_body_ops->dbo_bufs_get);
1171 return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1172 rnb->len, lnb, rw, capa);
1175 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1176 struct niobuf_local *lnb, int n)
1179 LASSERT(d->do_body_ops);
1180 LASSERT(d->do_body_ops->dbo_bufs_put);
1181 return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1184 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1185 struct niobuf_local *lnb, int n)
1188 LASSERT(d->do_body_ops);
1189 LASSERT(d->do_body_ops->dbo_write_prep);
1190 return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1193 static inline int dt_declare_write_commit(const struct lu_env *env,
1194 struct dt_object *d,
1195 struct niobuf_local *lnb,
1196 int n, struct thandle *th)
1198 LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1199 LASSERT(th != NULL);
1200 return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1204 static inline int dt_write_commit(const struct lu_env *env,
1205 struct dt_object *d, struct niobuf_local *lnb,
1206 int n, struct thandle *th)
1209 LASSERT(d->do_body_ops);
1210 LASSERT(d->do_body_ops->dbo_write_commit);
1211 return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1214 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1215 struct niobuf_local *lnb, int n)
1218 LASSERT(d->do_body_ops);
1219 LASSERT(d->do_body_ops->dbo_read_prep);
1220 return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1223 static inline int dt_declare_punch(const struct lu_env *env,
1224 struct dt_object *dt, __u64 start,
1225 __u64 end, struct thandle *th)
1228 LASSERT(dt->do_body_ops);
1229 LASSERT(dt->do_body_ops->dbo_declare_punch);
1230 return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
1233 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1234 __u64 start, __u64 end, struct thandle *th,
1235 struct lustre_capa *capa)
1238 LASSERT(dt->do_body_ops);
1239 LASSERT(dt->do_body_ops->dbo_punch);
1240 return dt->do_body_ops->dbo_punch(env, dt, start, end, th, capa);
1243 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1244 struct ll_user_fiemap *fm)
1247 if (d->do_body_ops == NULL)
1249 if (d->do_body_ops->dbo_fiemap_get == NULL)
1251 return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1254 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1255 struct obd_statfs *osfs)
1258 LASSERT(dev->dd_ops);
1259 LASSERT(dev->dd_ops->dt_statfs);
1260 return dev->dd_ops->dt_statfs(env, dev, osfs);
1263 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1267 LASSERT(dev->dd_ops);
1268 LASSERT(dev->dd_ops->dt_root_get);
1269 return dev->dd_ops->dt_root_get(env, dev, f);
1272 static inline void dt_conf_get(const struct lu_env *env,
1273 const struct dt_device *dev,
1274 struct dt_device_param *param)
1277 LASSERT(dev->dd_ops);
1278 LASSERT(dev->dd_ops->dt_conf_get);
1279 return dev->dd_ops->dt_conf_get(env, dev, param);
1282 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1285 LASSERT(dev->dd_ops);
1286 LASSERT(dev->dd_ops->dt_sync);
1287 return dev->dd_ops->dt_sync(env, dev);
1290 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1293 LASSERT(dev->dd_ops);
1294 LASSERT(dev->dd_ops->dt_ro);
1295 return dev->dd_ops->dt_ro(env, dev);
1298 static inline int dt_declare_insert(const struct lu_env *env,
1299 struct dt_object *dt,
1300 const struct dt_rec *rec,
1301 const struct dt_key *key,
1305 LASSERT(dt->do_index_ops);
1306 LASSERT(dt->do_index_ops->dio_declare_insert);
1307 return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1310 static inline int dt_insert(const struct lu_env *env,
1311 struct dt_object *dt,
1312 const struct dt_rec *rec,
1313 const struct dt_key *key,
1315 struct lustre_capa *capa,
1319 LASSERT(dt->do_index_ops);
1320 LASSERT(dt->do_index_ops->dio_insert);
1321 return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1325 static inline int dt_declare_xattr_del(const struct lu_env *env,
1326 struct dt_object *dt,
1331 LASSERT(dt->do_ops);
1332 LASSERT(dt->do_ops->do_declare_xattr_del);
1333 return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1336 static inline int dt_xattr_del(const struct lu_env *env,
1337 struct dt_object *dt, const char *name,
1339 struct lustre_capa *capa)
1342 LASSERT(dt->do_ops);
1343 LASSERT(dt->do_ops->do_xattr_del);
1344 return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1347 static inline int dt_declare_xattr_set(const struct lu_env *env,
1348 struct dt_object *dt,
1349 const struct lu_buf *buf,
1350 const char *name, int fl,
1354 LASSERT(dt->do_ops);
1355 LASSERT(dt->do_ops->do_declare_xattr_set);
1356 return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1359 static inline int dt_xattr_set(const struct lu_env *env,
1360 struct dt_object *dt, const struct lu_buf *buf,
1361 const char *name, int fl, struct thandle *th,
1362 struct lustre_capa *capa)
1365 LASSERT(dt->do_ops);
1366 LASSERT(dt->do_ops->do_xattr_set);
1367 return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1370 static inline int dt_xattr_get(const struct lu_env *env,
1371 struct dt_object *dt, struct lu_buf *buf,
1372 const char *name, struct lustre_capa *capa)
1375 LASSERT(dt->do_ops);
1376 LASSERT(dt->do_ops->do_xattr_get);
1377 return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1380 static inline int dt_xattr_list(const struct lu_env *env,
1381 struct dt_object *dt, struct lu_buf *buf,
1382 struct lustre_capa *capa)
1385 LASSERT(dt->do_ops);
1386 LASSERT(dt->do_ops->do_xattr_list);
1387 return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1390 static inline int dt_declare_delete(const struct lu_env *env,
1391 struct dt_object *dt,
1392 const struct dt_key *key,
1396 LASSERT(dt->do_index_ops);
1397 LASSERT(dt->do_index_ops->dio_declare_delete);
1398 return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1401 static inline int dt_delete(const struct lu_env *env,
1402 struct dt_object *dt,
1403 const struct dt_key *key,
1405 struct lustre_capa *capa)
1408 LASSERT(dt->do_index_ops);
1409 LASSERT(dt->do_index_ops->dio_delete);
1410 return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1413 static inline int dt_commit_async(const struct lu_env *env,
1414 struct dt_device *dev)
1417 LASSERT(dev->dd_ops);
1418 LASSERT(dev->dd_ops->dt_commit_async);
1419 return dev->dd_ops->dt_commit_async(env, dev);
1422 static inline int dt_init_capa_ctxt(const struct lu_env *env,
1423 struct dt_device *dev,
1424 int mode, unsigned long timeout,
1425 __u32 alg, struct lustre_capa_key *keys)
1428 LASSERT(dev->dd_ops);
1429 LASSERT(dev->dd_ops->dt_init_capa_ctxt);
1430 return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
1431 timeout, alg, keys);
1434 static inline int dt_lookup(const struct lu_env *env,
1435 struct dt_object *dt,
1437 const struct dt_key *key,
1438 struct lustre_capa *capa)
1443 LASSERT(dt->do_index_ops);
1444 LASSERT(dt->do_index_ops->dio_lookup);
1446 ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1454 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1456 struct dt_find_hint {
1457 struct lu_fid *dfh_fid;
1458 struct dt_device *dfh_dt;
1459 struct dt_object *dfh_o;
1462 struct dt_thread_info {
1463 char dti_buf[DT_MAX_PATH];
1464 struct dt_find_hint dti_dfh;
1465 struct lu_attr dti_attr;
1466 struct lu_fid dti_fid;
1467 struct dt_object_format dti_dof;
1468 struct lustre_mdt_attrs dti_lma;
1469 struct lu_buf dti_lb;
1473 extern struct lu_context_key dt_key;
1475 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
1477 struct dt_thread_info *dti;
1479 dti = lu_context_key_get(&env->le_ctx, &dt_key);
1484 int dt_global_init(void);
1485 void dt_global_fini(void);
1488 int lprocfs_dt_rd_blksize(char *page, char **start, off_t off,
1489 int count, int *eof, void *data);
1490 int lprocfs_dt_rd_kbytestotal(char *page, char **start, off_t off,
1491 int count, int *eof, void *data);
1492 int lprocfs_dt_rd_kbytesfree(char *page, char **start, off_t off,
1493 int count, int *eof, void *data);
1494 int lprocfs_dt_rd_kbytesavail(char *page, char **start, off_t off,
1495 int count, int *eof, void *data);
1496 int lprocfs_dt_rd_filestotal(char *page, char **start, off_t off,
1497 int count, int *eof, void *data);
1498 int lprocfs_dt_rd_filesfree(char *page, char **start, off_t off,
1499 int count, int *eof, void *data);
1500 # endif /* LPROCFS */
1502 #endif /* __LUSTRE_DT_OBJECT_H */