Whamcloud - gitweb
07f9a4b2aad8d729118b193f7c45b48b63eb2728
[fs/lustre-release.git] / lustre / include / dt_object.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef __LUSTRE_DT_OBJECT_H
38 #define __LUSTRE_DT_OBJECT_H
39
40 /** \defgroup dt dt
41  * Sub-class of lu_object with methods common for "data" objects in OST stack.
42  *
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
46  * (nlink) based one.
47  *
48  * Examples: osd (lustre/osd) is an implementation of dt interface.
49  * @{
50  */
51
52
53 /*
54  * super-class definitions.
55  */
56 #include <lu_object.h>
57
58 #include <libcfs/libcfs.h>
59
60 struct seq_file;
61 struct proc_dir_entry;
62 struct lustre_cfg;
63
64 struct thandle;
65 struct dt_device;
66 struct dt_object;
67 struct dt_index_features;
68 struct niobuf_local;
69 struct niobuf_remote;
70
71 typedef enum {
72         MNTOPT_USERXATTR        = 0x00000001,
73         MNTOPT_ACL              = 0x00000002,
74 } mntopt_t;
75
76 struct dt_device_param {
77         unsigned           ddp_max_name_len;
78         unsigned           ddp_max_nlink;
79         unsigned           ddp_block_shift;
80         mntopt_t           ddp_mntopts;
81         unsigned           ddp_max_ea_size;
82         void              *ddp_mnt; /* XXX: old code can retrieve mnt -bzzz */
83         int                ddp_mount_type;
84         unsigned long long ddp_maxbytes;
85         /* percentage of available space to reserve for grant error margin */
86         int                ddp_grant_reserved;
87         /* per-inode space consumption */
88         short              ddp_inodespace;
89         /* per-fragment grant overhead to be used by client for grant
90          * calculation */
91         int                ddp_grant_frag;
92 };
93
94 /**
95  * Per-transaction commit callback function
96  */
97 struct dt_txn_commit_cb;
98 typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
99                         struct dt_txn_commit_cb *cb, int err);
100 /**
101  * Special per-transaction callback for cases when just commit callback
102  * is needed and per-device callback are not convenient to use
103  */
104 #define TRANS_COMMIT_CB_MAGIC   0xa0a00a0a
105 #define MAX_COMMIT_CB_STR_LEN   32
106
107 struct dt_txn_commit_cb {
108         cfs_list_t      dcb_linkage;
109         dt_cb_t         dcb_func;
110         __u32           dcb_magic;
111         char            dcb_name[MAX_COMMIT_CB_STR_LEN];
112 };
113
114 /**
115  * Operations on dt device.
116  */
117 struct dt_device_operations {
118         /**
119          * Return device-wide statistics.
120          */
121         int   (*dt_statfs)(const struct lu_env *env,
122                            struct dt_device *dev, struct obd_statfs *osfs);
123         /**
124          * Create transaction, described by \a param.
125          */
126         struct thandle *(*dt_trans_create)(const struct lu_env *env,
127                                            struct dt_device *dev);
128         /**
129          * Start transaction, described by \a param.
130          */
131         int   (*dt_trans_start)(const struct lu_env *env,
132                                 struct dt_device *dev, struct thandle *th);
133         /**
134          * Finish previously started transaction.
135          */
136         int   (*dt_trans_stop)(const struct lu_env *env,
137                                struct thandle *th);
138         /**
139          * Add commit callback to the transaction.
140          */
141         int   (*dt_trans_cb_add)(struct thandle *th,
142                                  struct dt_txn_commit_cb *dcb);
143         /**
144          * Return fid of root index object.
145          */
146         int   (*dt_root_get)(const struct lu_env *env,
147                              struct dt_device *dev, struct lu_fid *f);
148         /**
149          * Return device configuration data.
150          */
151         void  (*dt_conf_get)(const struct lu_env *env,
152                              const struct dt_device *dev,
153                              struct dt_device_param *param);
154         /**
155          *  handling device state, mostly for tests
156          */
157         int   (*dt_sync)(const struct lu_env *env, struct dt_device *dev);
158         int   (*dt_ro)(const struct lu_env *env, struct dt_device *dev);
159         /**
160           * Start a transaction commit asynchronously
161           *
162           * \param env environment
163           * \param dev dt_device to start commit on
164           *
165           * \return 0 success, negative value if error
166           */
167          int   (*dt_commit_async)(const struct lu_env *env,
168                                   struct dt_device *dev);
169         /**
170          * Initialize capability context.
171          */
172         int   (*dt_init_capa_ctxt)(const struct lu_env *env,
173                                    struct dt_device *dev,
174                                    int mode, unsigned long timeout,
175                                    __u32 alg, struct lustre_capa_key *keys);
176 };
177
178 struct dt_index_features {
179         /** required feature flags from enum dt_index_flags */
180         __u32 dif_flags;
181         /** minimal required key size */
182         size_t dif_keysize_min;
183         /** maximal required key size, 0 if no limit */
184         size_t dif_keysize_max;
185         /** minimal required record size */
186         size_t dif_recsize_min;
187         /** maximal required record size, 0 if no limit */
188         size_t dif_recsize_max;
189         /** pointer size for record */
190         size_t dif_ptrsize;
191 };
192
193 enum dt_index_flags {
194         /** index supports variable sized keys */
195         DT_IND_VARKEY = 1 << 0,
196         /** index supports variable sized records */
197         DT_IND_VARREC = 1 << 1,
198         /** index can be modified */
199         DT_IND_UPDATE = 1 << 2,
200         /** index supports records with non-unique (duplicate) keys */
201         DT_IND_NONUNQ = 1 << 3,
202         /**
203          * index support fixed-size keys sorted with natural numerical way
204          * and is able to return left-side value if no exact value found
205          */
206         DT_IND_RANGE = 1 << 4,
207 };
208
209 /**
210  * Features, required from index to support file system directories (mapping
211  * names to fids).
212  */
213 extern const struct dt_index_features dt_directory_features;
214 extern const struct dt_index_features dt_otable_features;
215
216 /* index features supported by the accounting objects */
217 extern const struct dt_index_features dt_acct_features;
218
219 /* index features supported by the quota global indexes */
220 extern const struct dt_index_features dt_quota_glb_features;
221
222 /* index features supported by the quota slave indexes */
223 extern const struct dt_index_features dt_quota_slv_features;
224
225 /**
226  * This is a general purpose dt allocation hint.
227  * It now contains the parent object.
228  * It can contain any allocation hint in the future.
229  */
230 struct dt_allocation_hint {
231         struct dt_object           *dah_parent;
232         __u32                       dah_mode;
233 };
234
235 /**
236  * object type specifier.
237  */
238
239 enum dt_format_type {
240         DFT_REGULAR,
241         DFT_DIR,
242         /** for mknod */
243         DFT_NODE,
244         /** for special index */
245         DFT_INDEX,
246         /** for symbolic link */
247         DFT_SYM,
248 };
249
250 /**
251  * object format specifier.
252  */
253 struct dt_object_format {
254         /** type for dt object */
255         enum dt_format_type dof_type;
256         union {
257                 struct dof_regular {
258                         int striped;
259                 } dof_reg;
260                 struct dof_dir {
261                 } dof_dir;
262                 struct dof_node {
263                 } dof_node;
264                 /**
265                  * special index need feature as parameter to create
266                  * special idx
267                  */
268                 struct dof_index {
269                         const struct dt_index_features *di_feat;
270                 } dof_idx;
271         } u;
272 };
273
274 enum dt_format_type dt_mode_to_dft(__u32 mode);
275
276 typedef __u64 dt_obj_version_t;
277
278 /**
279  * Per-dt-object operations.
280  */
281 struct dt_object_operations {
282         void  (*do_read_lock)(const struct lu_env *env,
283                               struct dt_object *dt, unsigned role);
284         void  (*do_write_lock)(const struct lu_env *env,
285                                struct dt_object *dt, unsigned role);
286         void  (*do_read_unlock)(const struct lu_env *env,
287                                 struct dt_object *dt);
288         void  (*do_write_unlock)(const struct lu_env *env,
289                                  struct dt_object *dt);
290         int  (*do_write_locked)(const struct lu_env *env,
291                                 struct dt_object *dt);
292         /**
293          * Note: following ->do_{x,}attr_{set,get}() operations are very
294          * similar to ->moo_{x,}attr_{set,get}() operations in struct
295          * md_object_operations (see md_object.h). These operations are not in
296          * lu_object_operations, because ->do_{x,}attr_set() versions take
297          * transaction handle as an argument (this transaction is started by
298          * caller). We might factor ->do_{x,}attr_get() into
299          * lu_object_operations, but that would break existing symmetry.
300          */
301
302         /**
303          * Return standard attributes.
304          *
305          * precondition: lu_object_exists(&dt->do_lu);
306          */
307         int   (*do_attr_get)(const struct lu_env *env,
308                              struct dt_object *dt, struct lu_attr *attr,
309                              struct lustre_capa *capa);
310         /**
311          * Set standard attributes.
312          *
313          * precondition: dt_object_exists(dt);
314          */
315         int   (*do_declare_attr_set)(const struct lu_env *env,
316                                      struct dt_object *dt,
317                                      const struct lu_attr *attr,
318                                      struct thandle *handle);
319         int   (*do_attr_set)(const struct lu_env *env,
320                              struct dt_object *dt,
321                              const struct lu_attr *attr,
322                              struct thandle *handle,
323                              struct lustre_capa *capa);
324         /**
325          * Return a value of an extended attribute.
326          *
327          * precondition: dt_object_exists(dt);
328          */
329         int   (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
330                               struct lu_buf *buf, const char *name,
331                               struct lustre_capa *capa);
332         /**
333          * Set value of an extended attribute.
334          *
335          * \a fl - flags from enum lu_xattr_flags
336          *
337          * precondition: dt_object_exists(dt);
338          */
339         int   (*do_declare_xattr_set)(const struct lu_env *env,
340                                       struct dt_object *dt,
341                                       const struct lu_buf *buf,
342                                       const char *name, int fl,
343                                       struct thandle *handle);
344         int   (*do_xattr_set)(const struct lu_env *env,
345                               struct dt_object *dt, const struct lu_buf *buf,
346                               const char *name, int fl, struct thandle *handle,
347                               struct lustre_capa *capa);
348         /**
349          * Delete existing extended attribute.
350          *
351          * precondition: dt_object_exists(dt);
352          */
353         int   (*do_declare_xattr_del)(const struct lu_env *env,
354                                       struct dt_object *dt,
355                                       const char *name, struct thandle *handle);
356         int   (*do_xattr_del)(const struct lu_env *env,
357                               struct dt_object *dt,
358                               const char *name, struct thandle *handle,
359                               struct lustre_capa *capa);
360         /**
361          * Place list of existing extended attributes into \a buf (which has
362          * length len).
363          *
364          * precondition: dt_object_exists(dt);
365          */
366         int   (*do_xattr_list)(const struct lu_env *env,
367                                struct dt_object *dt, struct lu_buf *buf,
368                                struct lustre_capa *capa);
369         /**
370          * Init allocation hint using parent object and child mode.
371          * (1) The \a parent might be NULL if this is a partial creation for
372          *     remote object.
373          * (2) The type of child is in \a child_mode.
374          * (3) The result hint is stored in \a ah;
375          */
376         void  (*do_ah_init)(const struct lu_env *env,
377                             struct dt_allocation_hint *ah,
378                             struct dt_object *parent,
379                             struct dt_object *child,
380                             cfs_umode_t child_mode);
381         /**
382          * Create new object on this device.
383          *
384          * precondition: !dt_object_exists(dt);
385          * postcondition: ergo(result == 0, dt_object_exists(dt));
386          */
387         int   (*do_declare_create)(const struct lu_env *env,
388                                    struct dt_object *dt,
389                                    struct lu_attr *attr,
390                                    struct dt_allocation_hint *hint,
391                                    struct dt_object_format *dof,
392                                    struct thandle *th);
393         int   (*do_create)(const struct lu_env *env, struct dt_object *dt,
394                            struct lu_attr *attr,
395                            struct dt_allocation_hint *hint,
396                            struct dt_object_format *dof,
397                            struct thandle *th);
398
399         /**
400           Destroy object on this device
401          * precondition: !dt_object_exists(dt);
402          * postcondition: ergo(result == 0, dt_object_exists(dt));
403          */
404         int   (*do_declare_destroy)(const struct lu_env *env,
405                                     struct dt_object *dt,
406                                     struct thandle *th);
407         int   (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
408                             struct thandle *th);
409
410         /**
411          * Announce that this object is going to be used as an index. This
412          * operation check that object supports indexing operations and
413          * installs appropriate dt_index_operations vector on success.
414          *
415          * Also probes for features. Operation is successful if all required
416          * features are supported.
417          */
418         int   (*do_index_try)(const struct lu_env *env,
419                               struct dt_object *dt,
420                               const struct dt_index_features *feat);
421         /**
422          * Add nlink of the object
423          * precondition: dt_object_exists(dt);
424          */
425         int   (*do_declare_ref_add)(const struct lu_env *env,
426                                     struct dt_object *dt, struct thandle *th);
427         int   (*do_ref_add)(const struct lu_env *env,
428                             struct dt_object *dt, struct thandle *th);
429         /**
430          * Del nlink of the object
431          * precondition: dt_object_exists(dt);
432          */
433         int   (*do_declare_ref_del)(const struct lu_env *env,
434                                     struct dt_object *dt, struct thandle *th);
435         int   (*do_ref_del)(const struct lu_env *env,
436                             struct dt_object *dt, struct thandle *th);
437
438         struct obd_capa *(*do_capa_get)(const struct lu_env *env,
439                                         struct dt_object *dt,
440                                         struct lustre_capa *old,
441                                         __u64 opc);
442         int (*do_object_sync)(const struct lu_env *, struct dt_object *);
443         /**
444          * Get object info of next level. Currently, only get inode from osd.
445          * This is only used by quota b=16542
446          * precondition: dt_object_exists(dt);
447          */
448         int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
449                            void **data);
450 };
451
452 /**
453  * Per-dt-object operations on "file body".
454  */
455 struct dt_body_operations {
456         /**
457          * precondition: dt_object_exists(dt);
458          */
459         ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
460                             struct lu_buf *buf, loff_t *pos,
461                             struct lustre_capa *capa);
462         /**
463          * precondition: dt_object_exists(dt);
464          */
465         ssize_t (*dbo_declare_write)(const struct lu_env *env,
466                                      struct dt_object *dt,
467                                      const loff_t size, loff_t pos,
468                                      struct thandle *handle);
469         ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
470                              const struct lu_buf *buf, loff_t *pos,
471                              struct thandle *handle, struct lustre_capa *capa,
472                              int ignore_quota);
473         /*
474          * methods for zero-copy IO
475          */
476
477         /*
478          * precondition: dt_object_exists(dt);
479          * returns:
480          * < 0 - error code
481          * = 0 - illegal
482          * > 0 - number of local buffers prepared
483          */
484         int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
485                             loff_t pos, ssize_t len, struct niobuf_local *lb,
486                             int rw, struct lustre_capa *capa);
487         /*
488          * precondition: dt_object_exists(dt);
489          */
490         int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
491                             struct niobuf_local *lb, int nr);
492         /*
493          * precondition: dt_object_exists(dt);
494          */
495         int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
496                               struct niobuf_local *lb, int nr);
497         /*
498          * precondition: dt_object_exists(dt);
499          */
500         int (*dbo_declare_write_commit)(const struct lu_env *env,
501                                         struct dt_object *dt,
502                                         struct niobuf_local *,
503                                         int, struct thandle *);
504         /*
505          * precondition: dt_object_exists(dt);
506          */
507         int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
508                                 struct niobuf_local *, int, struct thandle *);
509         /*
510          * precondition: dt_object_exists(dt);
511          */
512         int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
513                              struct niobuf_local *lnb, int nr);
514         int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
515                               struct ll_user_fiemap *fm);
516         /**
517          * Punch object's content
518          * precondition: regular object, not index
519          */
520         int   (*do_declare_punch)(const struct lu_env *, struct dt_object *,
521                                   __u64, __u64, struct thandle *th);
522         int   (*do_punch)(const struct lu_env *env, struct dt_object *dt,
523                           __u64 start, __u64 end, struct thandle *th,
524                           struct lustre_capa *capa);
525 };
526
527 /**
528  * Incomplete type of index record.
529  */
530 struct dt_rec;
531
532 /**
533  * Incomplete type of index key.
534  */
535 struct dt_key;
536
537 /**
538  * Incomplete type of dt iterator.
539  */
540 struct dt_it;
541
542 /**
543  * Per-dt-object operations on object as index.
544  */
545 struct dt_index_operations {
546         /**
547          * precondition: dt_object_exists(dt);
548          */
549         int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
550                           struct dt_rec *rec, const struct dt_key *key,
551                           struct lustre_capa *capa);
552         /**
553          * precondition: dt_object_exists(dt);
554          */
555         int (*dio_declare_insert)(const struct lu_env *env,
556                                   struct dt_object *dt,
557                                   const struct dt_rec *rec,
558                                   const struct dt_key *key,
559                                   struct thandle *handle);
560         int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
561                           const struct dt_rec *rec, const struct dt_key *key,
562                           struct thandle *handle, struct lustre_capa *capa,
563                           int ignore_quota);
564         /**
565          * precondition: dt_object_exists(dt);
566          */
567         int (*dio_declare_delete)(const struct lu_env *env,
568                                   struct dt_object *dt,
569                                   const struct dt_key *key,
570                                   struct thandle *handle);
571         int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
572                           const struct dt_key *key, struct thandle *handle,
573                           struct lustre_capa *capa);
574         /**
575          * Iterator interface
576          */
577         struct dt_it_ops {
578                 /**
579                  * Allocate and initialize new iterator.
580                  *
581                  * precondition: dt_object_exists(dt);
582                  */
583                 struct dt_it *(*init)(const struct lu_env *env,
584                                       struct dt_object *dt,
585                                       __u32 attr,
586                                       struct lustre_capa *capa);
587                 void          (*fini)(const struct lu_env *env,
588                                       struct dt_it *di);
589                 int            (*get)(const struct lu_env *env,
590                                       struct dt_it *di,
591                                       const struct dt_key *key);
592                 void           (*put)(const struct lu_env *env,
593                                       struct dt_it *di);
594                 int           (*next)(const struct lu_env *env,
595                                       struct dt_it *di);
596                 struct dt_key *(*key)(const struct lu_env *env,
597                                       const struct dt_it *di);
598                 int       (*key_size)(const struct lu_env *env,
599                                       const struct dt_it *di);
600                 int            (*rec)(const struct lu_env *env,
601                                       const struct dt_it *di,
602                                       struct dt_rec *rec,
603                                       __u32 attr);
604                 __u64        (*store)(const struct lu_env *env,
605                                       const struct dt_it *di);
606                 int           (*load)(const struct lu_env *env,
607                                       const struct dt_it *di, __u64 hash);
608                 int        (*key_rec)(const struct lu_env *env,
609                                       const struct dt_it *di, void* key_rec);
610         } dio_it;
611 };
612
613 enum dt_otable_it_valid {
614         DOIV_ERROR_HANDLE       = 0x0001,
615 };
616
617 enum dt_otable_it_flags {
618         /* Exit when fail. */
619         DOIF_FAILOUT    = 0x0001,
620
621         /* Reset iteration position to the device beginning. */
622         DOIF_RESET      = 0x0002,
623
624         /* There is up layer component uses the iteration. */
625         DOIF_OUTUSED    = 0x0004,
626 };
627
628 /* otable based iteration needs to use the common DT interation APIs.
629  * To initialize the iteration, it needs call dio_it::init() firstly.
630  * Here is how the otable based iteration should prepare arguments to
631  * call dt_it_ops::init().
632  *
633  * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
634  * is composed of two parts:
635  * low 16-bits is for valid bits, high 16-bits is for flags bits. */
636 #define DT_OTABLE_IT_FLAGS_SHIFT        16
637 #define DT_OTABLE_IT_FLAGS_MASK         0xffff0000
638
639 struct dt_device {
640         struct lu_device                   dd_lu_dev;
641         const struct dt_device_operations *dd_ops;
642
643         /**
644          * List of dt_txn_callback (see below). This is not protected in any
645          * way, because callbacks are supposed to be added/deleted only during
646          * single-threaded start-up shut-down procedures.
647          */
648         cfs_list_t                         dd_txn_callbacks;
649 };
650
651 int  dt_device_init(struct dt_device *dev, struct lu_device_type *t);
652 void dt_device_fini(struct dt_device *dev);
653
654 static inline int lu_device_is_dt(const struct lu_device *d)
655 {
656         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
657 }
658
659 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
660 {
661         LASSERT(lu_device_is_dt(l));
662         return container_of0(l, struct dt_device, dd_lu_dev);
663 }
664
665 struct dt_object {
666         struct lu_object                   do_lu;
667         const struct dt_object_operations *do_ops;
668         const struct dt_body_operations   *do_body_ops;
669         const struct dt_index_operations  *do_index_ops;
670 };
671
672 /*
673  * In-core representation of per-device local object OID storage
674  */
675 struct local_oid_storage {
676         /* all initialized llog systems on this node linked by this */
677         cfs_list_t        los_list;
678
679         /* how many handle's reference this los has */
680         cfs_atomic_t      los_refcount;
681         struct dt_device *los_dev;
682         struct dt_object *los_obj;
683
684         /* data used to generate new fids */
685         struct mutex     los_id_lock;
686         __u64             los_seq;
687         __u32             los_last_oid;
688 };
689
690 static inline struct dt_object *lu2dt(struct lu_object *l)
691 {
692         LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
693         return container_of0(l, struct dt_object, do_lu);
694 }
695
696 int  dt_object_init(struct dt_object *obj,
697                     struct lu_object_header *h, struct lu_device *d);
698
699 void dt_object_fini(struct dt_object *obj);
700
701 static inline int dt_object_exists(const struct dt_object *dt)
702 {
703         return lu_object_exists(&dt->do_lu);
704 }
705
706 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
707 {
708         LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
709         return container_of0(o, struct dt_object, do_lu);
710 }
711
712 /**
713  * This is the general purpose transaction handle.
714  * 1. Transaction Life Cycle
715  *      This transaction handle is allocated upon starting a new transaction,
716  *      and deallocated after this transaction is committed.
717  * 2. Transaction Nesting
718  *      We do _NOT_ support nested transaction. So, every thread should only
719  *      have one active transaction, and a transaction only belongs to one
720  *      thread. Due to this, transaction handle need no reference count.
721  * 3. Transaction & dt_object locking
722  *      dt_object locks should be taken inside transaction.
723  * 4. Transaction & RPC
724  *      No RPC request should be issued inside transaction.
725  */
726 struct thandle {
727         /** the dt device on which the transactions are executed */
728         struct dt_device *th_dev;
729
730         /** context for this transaction, tag is LCT_TX_HANDLE */
731         struct lu_context th_ctx;
732
733         /** additional tags (layers can add in declare) */
734         __u32             th_tags;
735
736         /** the last operation result in this transaction.
737          * this value is used in recovery */
738         __s32             th_result;
739
740         /** whether we need sync commit */
741         int               th_sync:1;
742
743         /* local transation, no need to inform other layers */
744         int               th_local:1;
745
746         /* In DNE, one transaction can be disassemblied into
747          * updates on several different MDTs, and these updates
748          * will be attached to th_remote_update_list per target.
749          * Only single thread will access the list, no need lock
750          */
751         cfs_list_t              th_remote_update_list;
752         struct update_request   *th_current_request;
753 };
754
755 /**
756  * Transaction call-backs.
757  *
758  * These are invoked by osd (or underlying transaction engine) when
759  * transaction changes state.
760  *
761  * Call-backs are used by upper layers to modify transaction parameters and to
762  * perform some actions on for each transaction state transition. Typical
763  * example is mdt registering call-back to write into last-received file
764  * before each transaction commit.
765  */
766 struct dt_txn_callback {
767         int (*dtc_txn_start)(const struct lu_env *env,
768                              struct thandle *txn, void *cookie);
769         int (*dtc_txn_stop)(const struct lu_env *env,
770                             struct thandle *txn, void *cookie);
771         void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
772         void                *dtc_cookie;
773         __u32                dtc_tag;
774         cfs_list_t           dtc_linkage;
775 };
776
777 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
778 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
779
780 int dt_txn_hook_start(const struct lu_env *env,
781                       struct dt_device *dev, struct thandle *txn);
782 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
783 void dt_txn_hook_commit(struct thandle *txn);
784
785 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
786
787 /**
788  * Callback function used for parsing path.
789  * \see llo_store_resolve
790  */
791 typedef int (*dt_entry_func_t)(const struct lu_env *env,
792                             const char *name,
793                             void *pvt);
794
795 #define DT_MAX_PATH 1024
796
797 int dt_path_parser(const struct lu_env *env,
798                    char *local, dt_entry_func_t entry_func,
799                    void *data);
800
801 struct dt_object *dt_store_open(const struct lu_env *env,
802                                 struct dt_device *dt,
803                                 const char *dirname,
804                                 const char *filename,
805                                 struct lu_fid *fid);
806
807 struct dt_object *dt_find_or_create(const struct lu_env *env,
808                                     struct dt_device *dt,
809                                     const struct lu_fid *fid,
810                                     struct dt_object_format *dof,
811                                     struct lu_attr *attr);
812
813 struct dt_object *dt_locate_at(const struct lu_env *env,
814                                struct dt_device *dev,
815                                const struct lu_fid *fid,
816                                struct lu_device *top_dev);
817 static inline struct dt_object *
818 dt_locate(const struct lu_env *env, struct dt_device *dev,
819           const struct lu_fid *fid)
820 {
821         return dt_locate_at(env, dev, fid, dev->dd_lu_dev.ld_site->ls_top_dev);
822 }
823
824
825 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
826                            const struct lu_fid *first_fid,
827                            struct local_oid_storage **los);
828 void local_oid_storage_fini(const struct lu_env *env,
829                             struct local_oid_storage *los);
830 int local_object_fid_generate(const struct lu_env *env,
831                               struct local_oid_storage *los,
832                               struct lu_fid *fid);
833 int local_object_declare_create(const struct lu_env *env,
834                                 struct local_oid_storage *los,
835                                 struct dt_object *o,
836                                 struct lu_attr *attr,
837                                 struct dt_object_format *dof,
838                                 struct thandle *th);
839 int local_object_create(const struct lu_env *env,
840                         struct local_oid_storage *los,
841                         struct dt_object *o,
842                         struct lu_attr *attr, struct dt_object_format *dof,
843                         struct thandle *th);
844 struct dt_object *local_file_find_or_create(const struct lu_env *env,
845                                             struct local_oid_storage *los,
846                                             struct dt_object *parent,
847                                             const char *name, __u32 mode);
848 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
849                                                      struct dt_device *dt,
850                                                      const struct lu_fid *fid,
851                                                      struct dt_object *parent,
852                                                      const char *name,
853                                                      __u32 mode);
854 struct dt_object *
855 local_index_find_or_create(const struct lu_env *env,
856                            struct local_oid_storage *los,
857                            struct dt_object *parent,
858                            const char *name, __u32 mode,
859                            const struct dt_index_features *ft);
860 struct dt_object *
861 local_index_find_or_create_with_fid(const struct lu_env *env,
862                                     struct dt_device *dt,
863                                     const struct lu_fid *fid,
864                                     struct dt_object *parent,
865                                     const char *name, __u32 mode,
866                                     const struct dt_index_features *ft);
867
868 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
869                   const char *name, struct lu_fid *fid);
870
871 static inline int dt_object_sync(const struct lu_env *env,
872                                  struct dt_object *o)
873 {
874         LASSERT(o);
875         LASSERT(o->do_ops);
876         LASSERT(o->do_ops->do_object_sync);
877         return o->do_ops->do_object_sync(env, o);
878 }
879
880 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
881                            struct thandle *th);
882 void dt_version_set(const struct lu_env *env, struct dt_object *o,
883                     dt_obj_version_t version, struct thandle *th);
884 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
885
886
887 int dt_read(const struct lu_env *env, struct dt_object *dt,
888             struct lu_buf *buf, loff_t *pos);
889 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
890                    struct lu_buf *buf, loff_t *pos);
891 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
892                     const struct lu_buf *buf, loff_t *pos, struct thandle *th);
893 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
894                                      union lu_page *lp, int nob,
895                                      const struct dt_it_ops *iops,
896                                      struct dt_it *it, __u32 attr, void *arg);
897 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
898                   const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
899                   void *arg);
900 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
901                   struct idx_info *ii, const struct lu_rdpg *rdpg);
902
903 static inline struct thandle *dt_trans_create(const struct lu_env *env,
904                                               struct dt_device *d)
905 {
906         LASSERT(d->dd_ops->dt_trans_create);
907         return d->dd_ops->dt_trans_create(env, d);
908 }
909
910 static inline int dt_trans_start(const struct lu_env *env,
911                                  struct dt_device *d, struct thandle *th)
912 {
913         LASSERT(d->dd_ops->dt_trans_start);
914         return d->dd_ops->dt_trans_start(env, d, th);
915 }
916
917 /* for this transaction hooks shouldn't be called */
918 static inline int dt_trans_start_local(const struct lu_env *env,
919                                        struct dt_device *d, struct thandle *th)
920 {
921         LASSERT(d->dd_ops->dt_trans_start);
922         th->th_local = 1;
923         return d->dd_ops->dt_trans_start(env, d, th);
924 }
925
926 static inline int dt_trans_stop(const struct lu_env *env,
927                                 struct dt_device *d, struct thandle *th)
928 {
929         LASSERT(d->dd_ops->dt_trans_stop);
930         return d->dd_ops->dt_trans_stop(env, th);
931 }
932
933 static inline int dt_trans_cb_add(struct thandle *th,
934                                   struct dt_txn_commit_cb *dcb)
935 {
936         LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
937         dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
938         return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
939 }
940 /** @} dt */
941
942
943 static inline int dt_declare_record_write(const struct lu_env *env,
944                                           struct dt_object *dt,
945                                           int size, loff_t pos,
946                                           struct thandle *th)
947 {
948         int rc;
949
950         LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
951         LASSERT(th != NULL);
952         LASSERT(dt->do_body_ops);
953         LASSERT(dt->do_body_ops->dbo_declare_write);
954         rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
955         return rc;
956 }
957
958 static inline int dt_declare_create(const struct lu_env *env,
959                                     struct dt_object *dt,
960                                     struct lu_attr *attr,
961                                     struct dt_allocation_hint *hint,
962                                     struct dt_object_format *dof,
963                                     struct thandle *th)
964 {
965         LASSERT(dt);
966         LASSERT(dt->do_ops);
967         LASSERT(dt->do_ops->do_declare_create);
968         return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
969 }
970
971 static inline int dt_create(const struct lu_env *env,
972                                     struct dt_object *dt,
973                                     struct lu_attr *attr,
974                                     struct dt_allocation_hint *hint,
975                                     struct dt_object_format *dof,
976                                     struct thandle *th)
977 {
978         LASSERT(dt);
979         LASSERT(dt->do_ops);
980         LASSERT(dt->do_ops->do_create);
981         return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
982 }
983
984 static inline int dt_declare_destroy(const struct lu_env *env,
985                                      struct dt_object *dt,
986                                      struct thandle *th)
987 {
988         LASSERT(dt);
989         LASSERT(dt->do_ops);
990         LASSERT(dt->do_ops->do_declare_destroy);
991         return dt->do_ops->do_declare_destroy(env, dt, th);
992 }
993
994 static inline int dt_destroy(const struct lu_env *env,
995                              struct dt_object *dt,
996                              struct thandle *th)
997 {
998         LASSERT(dt);
999         LASSERT(dt->do_ops);
1000         LASSERT(dt->do_ops->do_destroy);
1001         return dt->do_ops->do_destroy(env, dt, th);
1002 }
1003
1004 static inline void dt_read_lock(const struct lu_env *env,
1005                                 struct dt_object *dt,
1006                                 unsigned role)
1007 {
1008         LASSERT(dt);
1009         LASSERT(dt->do_ops);
1010         LASSERT(dt->do_ops->do_read_lock);
1011         dt->do_ops->do_read_lock(env, dt, role);
1012 }
1013
1014 static inline void dt_write_lock(const struct lu_env *env,
1015                                 struct dt_object *dt,
1016                                 unsigned role)
1017 {
1018         LASSERT(dt);
1019         LASSERT(dt->do_ops);
1020         LASSERT(dt->do_ops->do_write_lock);
1021         dt->do_ops->do_write_lock(env, dt, role);
1022 }
1023
1024 static inline void dt_read_unlock(const struct lu_env *env,
1025                                 struct dt_object *dt)
1026 {
1027         LASSERT(dt);
1028         LASSERT(dt->do_ops);
1029         LASSERT(dt->do_ops->do_read_unlock);
1030         dt->do_ops->do_read_unlock(env, dt);
1031 }
1032
1033 static inline void dt_write_unlock(const struct lu_env *env,
1034                                 struct dt_object *dt)
1035 {
1036         LASSERT(dt);
1037         LASSERT(dt->do_ops);
1038         LASSERT(dt->do_ops->do_write_unlock);
1039         dt->do_ops->do_write_unlock(env, dt);
1040 }
1041
1042 static inline int dt_write_locked(const struct lu_env *env,
1043                                   struct dt_object *dt)
1044 {
1045         LASSERT(dt);
1046         LASSERT(dt->do_ops);
1047         LASSERT(dt->do_ops->do_write_locked);
1048         return dt->do_ops->do_write_locked(env, dt);
1049 }
1050
1051 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
1052                               struct lu_attr *la, void *arg)
1053 {
1054         LASSERT(dt);
1055         LASSERT(dt->do_ops);
1056         LASSERT(dt->do_ops->do_attr_get);
1057         return dt->do_ops->do_attr_get(env, dt, la, arg);
1058 }
1059
1060 static inline int dt_declare_attr_set(const struct lu_env *env,
1061                                       struct dt_object *dt,
1062                                       const struct lu_attr *la,
1063                                       struct thandle *th)
1064 {
1065         LASSERT(dt);
1066         LASSERT(dt->do_ops);
1067         LASSERT(dt->do_ops->do_declare_attr_set);
1068         return dt->do_ops->do_declare_attr_set(env, dt, la, th);
1069 }
1070
1071 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
1072                               const struct lu_attr *la, struct thandle *th,
1073                               struct lustre_capa *capa)
1074 {
1075         LASSERT(dt);
1076         LASSERT(dt->do_ops);
1077         LASSERT(dt->do_ops->do_attr_set);
1078         return dt->do_ops->do_attr_set(env, dt, la, th, capa);
1079 }
1080
1081 static inline int dt_declare_ref_add(const struct lu_env *env,
1082                                      struct dt_object *dt, struct thandle *th)
1083 {
1084         LASSERT(dt);
1085         LASSERT(dt->do_ops);
1086         LASSERT(dt->do_ops->do_declare_ref_add);
1087         return dt->do_ops->do_declare_ref_add(env, dt, th);
1088 }
1089
1090 static inline int dt_ref_add(const struct lu_env *env,
1091                              struct dt_object *dt, struct thandle *th)
1092 {
1093         LASSERT(dt);
1094         LASSERT(dt->do_ops);
1095         LASSERT(dt->do_ops->do_ref_add);
1096         return dt->do_ops->do_ref_add(env, dt, th);
1097 }
1098
1099 static inline int dt_declare_ref_del(const struct lu_env *env,
1100                                      struct dt_object *dt, struct thandle *th)
1101 {
1102         LASSERT(dt);
1103         LASSERT(dt->do_ops);
1104         LASSERT(dt->do_ops->do_declare_ref_del);
1105         return dt->do_ops->do_declare_ref_del(env, dt, th);
1106 }
1107
1108 static inline int dt_ref_del(const struct lu_env *env,
1109                              struct dt_object *dt, struct thandle *th)
1110 {
1111         LASSERT(dt);
1112         LASSERT(dt->do_ops);
1113         LASSERT(dt->do_ops->do_ref_del);
1114         return dt->do_ops->do_ref_del(env, dt, th);
1115 }
1116
1117 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1118                                            struct dt_object *dt,
1119                                            struct lustre_capa *old, __u64 opc)
1120 {
1121         LASSERT(dt);
1122         LASSERT(dt->do_ops);
1123         LASSERT(dt->do_ops->do_ref_del);
1124         return dt->do_ops->do_capa_get(env, dt, old, opc);
1125 }
1126
1127 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1128                               struct niobuf_remote *rnb,
1129                               struct niobuf_local *lnb, int rw,
1130                               struct lustre_capa *capa)
1131 {
1132         LASSERT(d);
1133         LASSERT(d->do_body_ops);
1134         LASSERT(d->do_body_ops->dbo_bufs_get);
1135         return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1136                                             rnb->len, lnb, rw, capa);
1137 }
1138
1139 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1140                               struct niobuf_local *lnb, int n)
1141 {
1142         LASSERT(d);
1143         LASSERT(d->do_body_ops);
1144         LASSERT(d->do_body_ops->dbo_bufs_put);
1145         return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1146 }
1147
1148 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1149                                 struct niobuf_local *lnb, int n)
1150 {
1151         LASSERT(d);
1152         LASSERT(d->do_body_ops);
1153         LASSERT(d->do_body_ops->dbo_write_prep);
1154         return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1155 }
1156
1157 static inline int dt_declare_write_commit(const struct lu_env *env,
1158                                           struct dt_object *d,
1159                                           struct niobuf_local *lnb,
1160                                           int n, struct thandle *th)
1161 {
1162         LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1163         LASSERT(th != NULL);
1164         return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1165 }
1166
1167
1168 static inline int dt_write_commit(const struct lu_env *env,
1169                                   struct dt_object *d, struct niobuf_local *lnb,
1170                                   int n, struct thandle *th)
1171 {
1172         LASSERT(d);
1173         LASSERT(d->do_body_ops);
1174         LASSERT(d->do_body_ops->dbo_write_commit);
1175         return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1176 }
1177
1178 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1179                                struct niobuf_local *lnb, int n)
1180 {
1181         LASSERT(d);
1182         LASSERT(d->do_body_ops);
1183         LASSERT(d->do_body_ops->dbo_read_prep);
1184         return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1185 }
1186
1187 static inline int dt_declare_punch(const struct lu_env *env,
1188                                    struct dt_object *dt, __u64 start,
1189                                    __u64 end, struct thandle *th)
1190 {
1191         LASSERT(dt);
1192         LASSERT(dt->do_body_ops);
1193         LASSERT(dt->do_body_ops->do_declare_punch);
1194         return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1195 }
1196
1197 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1198                            __u64 start, __u64 end, struct thandle *th,
1199                            struct lustre_capa *capa)
1200 {
1201         LASSERT(dt);
1202         LASSERT(dt->do_body_ops);
1203         LASSERT(dt->do_body_ops->do_punch);
1204         return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1205 }
1206
1207 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1208                                 struct ll_user_fiemap *fm)
1209 {
1210         LASSERT(d);
1211         if (d->do_body_ops == NULL)
1212                 return -EPROTO;
1213         if (d->do_body_ops->dbo_fiemap_get == NULL)
1214                 return -EOPNOTSUPP;
1215         return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1216 }
1217
1218 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1219                             struct obd_statfs *osfs)
1220 {
1221         LASSERT(dev);
1222         LASSERT(dev->dd_ops);
1223         LASSERT(dev->dd_ops->dt_statfs);
1224         return dev->dd_ops->dt_statfs(env, dev, osfs);
1225 }
1226
1227 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1228                               struct lu_fid *f)
1229 {
1230         LASSERT(dev);
1231         LASSERT(dev->dd_ops);
1232         LASSERT(dev->dd_ops->dt_root_get);
1233         return dev->dd_ops->dt_root_get(env, dev, f);
1234 }
1235
1236 static inline void dt_conf_get(const struct lu_env *env,
1237                                const struct dt_device *dev,
1238                                struct dt_device_param *param)
1239 {
1240         LASSERT(dev);
1241         LASSERT(dev->dd_ops);
1242         LASSERT(dev->dd_ops->dt_conf_get);
1243         return dev->dd_ops->dt_conf_get(env, dev, param);
1244 }
1245
1246 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1247 {
1248         LASSERT(dev);
1249         LASSERT(dev->dd_ops);
1250         LASSERT(dev->dd_ops->dt_sync);
1251         return dev->dd_ops->dt_sync(env, dev);
1252 }
1253
1254 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1255 {
1256         LASSERT(dev);
1257         LASSERT(dev->dd_ops);
1258         LASSERT(dev->dd_ops->dt_ro);
1259         return dev->dd_ops->dt_ro(env, dev);
1260 }
1261
1262 static inline int dt_declare_insert(const struct lu_env *env,
1263                                     struct dt_object *dt,
1264                                     const struct dt_rec *rec,
1265                                     const struct dt_key *key,
1266                                     struct thandle *th)
1267 {
1268         LASSERT(dt);
1269         LASSERT(dt->do_index_ops);
1270         LASSERT(dt->do_index_ops->dio_declare_insert);
1271         return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1272 }
1273
1274 static inline int dt_insert(const struct lu_env *env,
1275                                     struct dt_object *dt,
1276                                     const struct dt_rec *rec,
1277                                     const struct dt_key *key,
1278                                     struct thandle *th,
1279                                     struct lustre_capa *capa,
1280                                     int noquota)
1281 {
1282         LASSERT(dt);
1283         LASSERT(dt->do_index_ops);
1284         LASSERT(dt->do_index_ops->dio_insert);
1285         return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1286                                             capa, noquota);
1287 }
1288
1289 static inline int dt_declare_xattr_del(const struct lu_env *env,
1290                                        struct dt_object *dt,
1291                                        const char *name,
1292                                        struct thandle *th)
1293 {
1294         LASSERT(dt);
1295         LASSERT(dt->do_ops);
1296         LASSERT(dt->do_ops->do_declare_xattr_del);
1297         return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1298 }
1299
1300 static inline int dt_xattr_del(const struct lu_env *env,
1301                                struct dt_object *dt, const char *name,
1302                                struct thandle *th,
1303                                struct lustre_capa *capa)
1304 {
1305         LASSERT(dt);
1306         LASSERT(dt->do_ops);
1307         LASSERT(dt->do_ops->do_xattr_del);
1308         return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1309 }
1310
1311 static inline int dt_declare_xattr_set(const struct lu_env *env,
1312                                       struct dt_object *dt,
1313                                       const struct lu_buf *buf,
1314                                       const char *name, int fl,
1315                                       struct thandle *th)
1316 {
1317         LASSERT(dt);
1318         LASSERT(dt->do_ops);
1319         LASSERT(dt->do_ops->do_declare_xattr_set);
1320         return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1321 }
1322
1323 static inline int dt_xattr_set(const struct lu_env *env,
1324                               struct dt_object *dt, const struct lu_buf *buf,
1325                               const char *name, int fl, struct thandle *th,
1326                               struct lustre_capa *capa)
1327 {
1328         LASSERT(dt);
1329         LASSERT(dt->do_ops);
1330         LASSERT(dt->do_ops->do_xattr_set);
1331         return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1332 }
1333
1334 static inline int dt_xattr_get(const struct lu_env *env,
1335                               struct dt_object *dt, struct lu_buf *buf,
1336                               const char *name, struct lustre_capa *capa)
1337 {
1338         LASSERT(dt);
1339         LASSERT(dt->do_ops);
1340         LASSERT(dt->do_ops->do_xattr_get);
1341         return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1342 }
1343
1344 static inline int dt_xattr_list(const struct lu_env *env,
1345                                struct dt_object *dt, struct lu_buf *buf,
1346                                struct lustre_capa *capa)
1347 {
1348         LASSERT(dt);
1349         LASSERT(dt->do_ops);
1350         LASSERT(dt->do_ops->do_xattr_list);
1351         return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1352 }
1353
1354 static inline int dt_declare_delete(const struct lu_env *env,
1355                                     struct dt_object *dt,
1356                                     const struct dt_key *key,
1357                                     struct thandle *th)
1358 {
1359         LASSERT(dt);
1360         LASSERT(dt->do_index_ops);
1361         LASSERT(dt->do_index_ops->dio_declare_delete);
1362         return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1363 }
1364
1365 static inline int dt_delete(const struct lu_env *env,
1366                             struct dt_object *dt,
1367                             const struct dt_key *key,
1368                             struct thandle *th,
1369                             struct lustre_capa *capa)
1370 {
1371         LASSERT(dt);
1372         LASSERT(dt->do_index_ops);
1373         LASSERT(dt->do_index_ops->dio_delete);
1374         return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1375 }
1376
1377 static inline int dt_commit_async(const struct lu_env *env,
1378                                   struct dt_device *dev)
1379 {
1380         LASSERT(dev);
1381         LASSERT(dev->dd_ops);
1382         LASSERT(dev->dd_ops->dt_commit_async);
1383         return dev->dd_ops->dt_commit_async(env, dev);
1384 }
1385
1386 static inline int dt_init_capa_ctxt(const struct lu_env *env,
1387                                     struct dt_device *dev,
1388                                     int mode, unsigned long timeout,
1389                                     __u32 alg, struct lustre_capa_key *keys)
1390 {
1391         LASSERT(dev);
1392         LASSERT(dev->dd_ops);
1393         LASSERT(dev->dd_ops->dt_init_capa_ctxt);
1394         return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
1395                                               timeout, alg, keys);
1396 }
1397
1398 static inline int dt_lookup(const struct lu_env *env,
1399                             struct dt_object *dt,
1400                             struct dt_rec *rec,
1401                             const struct dt_key *key,
1402                             struct lustre_capa *capa)
1403 {
1404         int ret;
1405
1406         LASSERT(dt);
1407         LASSERT(dt->do_index_ops);
1408         LASSERT(dt->do_index_ops->dio_lookup);
1409
1410         ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1411         if (ret > 0)
1412                 ret = 0;
1413         else if (ret == 0)
1414                 ret = -ENOENT;
1415         return ret;
1416 }
1417
1418 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1419
1420 struct dt_find_hint {
1421         struct lu_fid        *dfh_fid;
1422         struct dt_device     *dfh_dt;
1423         struct dt_object     *dfh_o;
1424 };
1425
1426 struct dt_thread_info {
1427         char                     dti_buf[DT_MAX_PATH];
1428         struct dt_find_hint      dti_dfh;
1429         struct lu_attr           dti_attr;
1430         struct lu_fid            dti_fid;
1431         struct dt_object_format  dti_dof;
1432         struct lustre_mdt_attrs  dti_lma;
1433         struct lu_buf            dti_lb;
1434         loff_t                   dti_off;
1435 };
1436
1437 extern struct lu_context_key dt_key;
1438
1439 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
1440 {
1441         struct dt_thread_info *dti;
1442
1443         dti = lu_context_key_get(&env->le_ctx, &dt_key);
1444         LASSERT(dti);
1445         return dti;
1446 }
1447
1448 #endif /* __LUSTRE_DT_OBJECT_H */