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