Whamcloud - gitweb
LU-1303 lod: object create to create underlying objects
[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, Whamcloud, Inc.
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 dt_quota_ctxt;
69 struct niobuf_local;
70 struct niobuf_remote;
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          * Initialize quota context.
179          */
180         void (*dt_init_quota_ctxt)(const struct lu_env *env,
181                                    struct dt_device *dev,
182                                    struct dt_quota_ctxt *ctxt, void *data);
183 };
184
185 struct dt_index_features {
186         /** required feature flags from enum dt_index_flags */
187         __u32 dif_flags;
188         /** minimal required key size */
189         size_t dif_keysize_min;
190         /** maximal required key size, 0 if no limit */
191         size_t dif_keysize_max;
192         /** minimal required record size */
193         size_t dif_recsize_min;
194         /** maximal required record size, 0 if no limit */
195         size_t dif_recsize_max;
196         /** pointer size for record */
197         size_t dif_ptrsize;
198 };
199
200 enum dt_index_flags {
201         /** index supports variable sized keys */
202         DT_IND_VARKEY = 1 << 0,
203         /** index supports variable sized records */
204         DT_IND_VARREC = 1 << 1,
205         /** index can be modified */
206         DT_IND_UPDATE = 1 << 2,
207         /** index supports records with non-unique (duplicate) keys */
208         DT_IND_NONUNQ = 1 << 3,
209         /**
210          * index support fixed-size keys sorted with natural numerical way
211          * and is able to return left-side value if no exact value found
212          */
213         DT_IND_RANGE = 1 << 4,
214 };
215
216 /**
217  * Features, required from index to support file system directories (mapping
218  * names to fids).
219  */
220 extern const struct dt_index_features dt_directory_features;
221 extern const struct dt_index_features dt_otable_features;
222
223 /* index features supported by the accounting objects */
224 extern const struct dt_index_features dt_acct_features;
225
226 /* index features supported by the quota global indexes */
227 extern const struct dt_index_features dt_quota_glb_features;
228
229 /* index features supported by the quota slave indexes */
230 extern const struct dt_index_features dt_quota_slv_features;
231
232 /**
233  * This is a general purpose dt allocation hint.
234  * It now contains the parent object.
235  * It can contain any allocation hint in the future.
236  */
237 struct dt_allocation_hint {
238         struct dt_object           *dah_parent;
239         __u32                       dah_mode;
240 };
241
242 /**
243  * object type specifier.
244  */
245
246 enum dt_format_type {
247         DFT_REGULAR,
248         DFT_DIR,
249         /** for mknod */
250         DFT_NODE,
251         /** for special index */
252         DFT_INDEX,
253         /** for symbolic link */
254         DFT_SYM,
255 };
256
257 /**
258  * object format specifier.
259  */
260 struct dt_object_format {
261         /** type for dt object */
262         enum dt_format_type dof_type;
263         union {
264                 struct dof_regular {
265                         int striped;
266                 } dof_reg;
267                 struct dof_dir {
268                 } dof_dir;
269                 struct dof_node {
270                 } dof_node;
271                 /**
272                  * special index need feature as parameter to create
273                  * special idx
274                  */
275                 struct dof_index {
276                         const struct dt_index_features *di_feat;
277                 } dof_idx;
278         } u;
279 };
280
281 enum dt_format_type dt_mode_to_dft(__u32 mode);
282
283 typedef __u64 dt_obj_version_t;
284
285 /**
286  * Per-dt-object operations.
287  */
288 struct dt_object_operations {
289         void  (*do_read_lock)(const struct lu_env *env,
290                               struct dt_object *dt, unsigned role);
291         void  (*do_write_lock)(const struct lu_env *env,
292                                struct dt_object *dt, unsigned role);
293         void  (*do_read_unlock)(const struct lu_env *env,
294                                 struct dt_object *dt);
295         void  (*do_write_unlock)(const struct lu_env *env,
296                                  struct dt_object *dt);
297         int  (*do_write_locked)(const struct lu_env *env,
298                                 struct dt_object *dt);
299         /**
300          * Note: following ->do_{x,}attr_{set,get}() operations are very
301          * similar to ->moo_{x,}attr_{set,get}() operations in struct
302          * md_object_operations (see md_object.h). These operations are not in
303          * lu_object_operations, because ->do_{x,}attr_set() versions take
304          * transaction handle as an argument (this transaction is started by
305          * caller). We might factor ->do_{x,}attr_get() into
306          * lu_object_operations, but that would break existing symmetry.
307          */
308
309         /**
310          * Return standard attributes.
311          *
312          * precondition: lu_object_exists(&dt->do_lu);
313          */
314         int   (*do_attr_get)(const struct lu_env *env,
315                              struct dt_object *dt, struct lu_attr *attr,
316                              struct lustre_capa *capa);
317         /**
318          * Set standard attributes.
319          *
320          * precondition: dt_object_exists(dt);
321          */
322         int   (*do_declare_attr_set)(const struct lu_env *env,
323                                      struct dt_object *dt,
324                                      const struct lu_attr *attr,
325                                      struct thandle *handle);
326         int   (*do_attr_set)(const struct lu_env *env,
327                              struct dt_object *dt,
328                              const struct lu_attr *attr,
329                              struct thandle *handle,
330                              struct lustre_capa *capa);
331         /**
332          * Return a value of an extended attribute.
333          *
334          * precondition: dt_object_exists(dt);
335          */
336         int   (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
337                               struct lu_buf *buf, const char *name,
338                               struct lustre_capa *capa);
339         /**
340          * Set value of an extended attribute.
341          *
342          * \a fl - flags from enum lu_xattr_flags
343          *
344          * precondition: dt_object_exists(dt);
345          */
346         int   (*do_declare_xattr_set)(const struct lu_env *env,
347                                       struct dt_object *dt,
348                                       const struct lu_buf *buf,
349                                       const char *name, int fl,
350                                       struct thandle *handle);
351         int   (*do_xattr_set)(const struct lu_env *env,
352                               struct dt_object *dt, const struct lu_buf *buf,
353                               const char *name, int fl, struct thandle *handle,
354                               struct lustre_capa *capa);
355         /**
356          * Delete existing extended attribute.
357          *
358          * precondition: dt_object_exists(dt);
359          */
360         int   (*do_declare_xattr_del)(const struct lu_env *env,
361                                       struct dt_object *dt,
362                                       const char *name, struct thandle *handle);
363         int   (*do_xattr_del)(const struct lu_env *env,
364                               struct dt_object *dt,
365                               const char *name, struct thandle *handle,
366                               struct lustre_capa *capa);
367         /**
368          * Place list of existing extended attributes into \a buf (which has
369          * length len).
370          *
371          * precondition: dt_object_exists(dt);
372          */
373         int   (*do_xattr_list)(const struct lu_env *env,
374                                struct dt_object *dt, struct lu_buf *buf,
375                                struct lustre_capa *capa);
376         /**
377          * Init allocation hint using parent object and child mode.
378          * (1) The \a parent might be NULL if this is a partial creation for
379          *     remote object.
380          * (2) The type of child is in \a child_mode.
381          * (3) The result hint is stored in \a ah;
382          */
383         void  (*do_ah_init)(const struct lu_env *env,
384                             struct dt_allocation_hint *ah,
385                             struct dt_object *parent,
386                             struct dt_object *child,
387                             cfs_umode_t child_mode);
388         /**
389          * Create new object on this device.
390          *
391          * precondition: !dt_object_exists(dt);
392          * postcondition: ergo(result == 0, dt_object_exists(dt));
393          */
394         int   (*do_declare_create)(const struct lu_env *env,
395                                    struct dt_object *dt,
396                                    struct lu_attr *attr,
397                                    struct dt_allocation_hint *hint,
398                                    struct dt_object_format *dof,
399                                    struct thandle *th);
400         int   (*do_create)(const struct lu_env *env, struct dt_object *dt,
401                            struct lu_attr *attr,
402                            struct dt_allocation_hint *hint,
403                            struct dt_object_format *dof,
404                            struct thandle *th);
405
406         /**
407           Destroy object on this device
408          * precondition: !dt_object_exists(dt);
409          * postcondition: ergo(result == 0, dt_object_exists(dt));
410          */
411         int   (*do_declare_destroy)(const struct lu_env *env,
412                                     struct dt_object *dt,
413                                     struct thandle *th);
414         int   (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
415                             struct thandle *th);
416
417         /**
418          * Announce that this object is going to be used as an index. This
419          * operation check that object supports indexing operations and
420          * installs appropriate dt_index_operations vector on success.
421          *
422          * Also probes for features. Operation is successful if all required
423          * features are supported.
424          */
425         int   (*do_index_try)(const struct lu_env *env,
426                               struct dt_object *dt,
427                               const struct dt_index_features *feat);
428         /**
429          * Add nlink of the object
430          * precondition: dt_object_exists(dt);
431          */
432         int   (*do_declare_ref_add)(const struct lu_env *env,
433                                     struct dt_object *dt, struct thandle *th);
434         int   (*do_ref_add)(const struct lu_env *env,
435                             struct dt_object *dt, struct thandle *th);
436         /**
437          * Del nlink of the object
438          * precondition: dt_object_exists(dt);
439          */
440         int   (*do_declare_ref_del)(const struct lu_env *env,
441                                     struct dt_object *dt, struct thandle *th);
442         int   (*do_ref_del)(const struct lu_env *env,
443                             struct dt_object *dt, struct thandle *th);
444
445         struct obd_capa *(*do_capa_get)(const struct lu_env *env,
446                                         struct dt_object *dt,
447                                         struct lustre_capa *old,
448                                         __u64 opc);
449         int (*do_object_sync)(const struct lu_env *, struct dt_object *);
450         /**
451          * Get object info of next level. Currently, only get inode from osd.
452          * This is only used by quota b=16542
453          * precondition: dt_object_exists(dt);
454          */
455         int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
456                            void **data);
457 };
458
459 /**
460  * Per-dt-object operations on "file body".
461  */
462 struct dt_body_operations {
463         /**
464          * precondition: dt_object_exists(dt);
465          */
466         ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
467                             struct lu_buf *buf, loff_t *pos,
468                             struct lustre_capa *capa);
469         /**
470          * precondition: dt_object_exists(dt);
471          */
472         ssize_t (*dbo_declare_write)(const struct lu_env *env,
473                                      struct dt_object *dt,
474                                      const loff_t size, loff_t pos,
475                                      struct thandle *handle);
476         ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
477                              const struct lu_buf *buf, loff_t *pos,
478                              struct thandle *handle, struct lustre_capa *capa,
479                              int ignore_quota);
480         /*
481          * methods for zero-copy IO
482          */
483
484         /*
485          * precondition: dt_object_exists(dt);
486          * returns:
487          * < 0 - error code
488          * = 0 - illegal
489          * > 0 - number of local buffers prepared
490          */
491         int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
492                             loff_t pos, ssize_t len, struct niobuf_local *lb,
493                             int rw, struct lustre_capa *capa);
494         /*
495          * precondition: dt_object_exists(dt);
496          */
497         int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
498                             struct niobuf_local *lb, int nr);
499         /*
500          * precondition: dt_object_exists(dt);
501          */
502         int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
503                               struct niobuf_local *lb, int nr);
504         /*
505          * precondition: dt_object_exists(dt);
506          */
507         int (*dbo_declare_write_commit)(const struct lu_env *env,
508                                         struct dt_object *dt,
509                                         struct niobuf_local *,
510                                         int, struct thandle *);
511         /*
512          * precondition: dt_object_exists(dt);
513          */
514         int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
515                                 struct niobuf_local *, int, struct thandle *);
516         /*
517          * precondition: dt_object_exists(dt);
518          */
519         int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
520                              struct niobuf_local *lnb, int nr);
521         int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
522                               struct ll_user_fiemap *fm);
523         /**
524          * Punch object's content
525          * precondition: regular object, not index
526          */
527         int   (*do_declare_punch)(const struct lu_env *, struct dt_object *,
528                                   __u64, __u64, struct thandle *th);
529         int   (*do_punch)(const struct lu_env *env, struct dt_object *dt,
530                           __u64 start, __u64 end, struct thandle *th,
531                           struct lustre_capa *capa);
532 };
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 };
678
679 /*
680  * In-core representation of per-device local object OID storage
681  */
682 struct local_oid_storage {
683         /* all initialized llog systems on this node linked by this */
684         cfs_list_t        los_list;
685
686         /* how many handle's reference this los has */
687         cfs_atomic_t      los_refcount;
688         struct dt_device *los_dev;
689         struct dt_object *los_obj;
690
691         /* data used to generate new fids */
692         cfs_mutex_t       los_id_lock;
693         __u64             los_seq;
694         __u32             los_last_oid;
695 };
696
697 static inline struct dt_object *lu2dt(struct lu_object *l)
698 {
699         LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
700         return container_of0(l, struct dt_object, do_lu);
701 }
702
703 int  dt_object_init(struct dt_object *obj,
704                     struct lu_object_header *h, struct lu_device *d);
705
706 void dt_object_fini(struct dt_object *obj);
707
708 static inline int dt_object_exists(const struct dt_object *dt)
709 {
710         return lu_object_exists(&dt->do_lu);
711 }
712
713 /**
714  * This is the general purpose transaction handle.
715  * 1. Transaction Life Cycle
716  *      This transaction handle is allocated upon starting a new transaction,
717  *      and deallocated after this transaction is committed.
718  * 2. Transaction Nesting
719  *      We do _NOT_ support nested transaction. So, every thread should only
720  *      have one active transaction, and a transaction only belongs to one
721  *      thread. Due to this, transaction handle need no reference count.
722  * 3. Transaction & dt_object locking
723  *      dt_object locks should be taken inside transaction.
724  * 4. Transaction & RPC
725  *      No RPC request should be issued inside transaction.
726  */
727 struct thandle {
728         /** the dt device on which the transactions are executed */
729         struct dt_device *th_dev;
730
731         /** additional tags (layers can add in declare) */
732         __u32             th_tags;
733
734         /** context for this transaction, tag is LCT_TX_HANDLE */
735         struct lu_context th_ctx;
736
737         /** the last operation result in this transaction.
738          * this value is used in recovery */
739         __s32             th_result;
740
741         /** whether we need sync commit */
742         int               th_sync:1;
743
744         /* local transation, no need to inform other layers */
745         int               th_local:1;
746 };
747
748 /**
749  * Transaction call-backs.
750  *
751  * These are invoked by osd (or underlying transaction engine) when
752  * transaction changes state.
753  *
754  * Call-backs are used by upper layers to modify transaction parameters and to
755  * perform some actions on for each transaction state transition. Typical
756  * example is mdt registering call-back to write into last-received file
757  * before each transaction commit.
758  */
759 struct dt_txn_callback {
760         int (*dtc_txn_start)(const struct lu_env *env,
761                              struct thandle *txn, void *cookie);
762         int (*dtc_txn_stop)(const struct lu_env *env,
763                             struct thandle *txn, void *cookie);
764         void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
765         void                *dtc_cookie;
766         __u32                dtc_tag;
767         cfs_list_t           dtc_linkage;
768 };
769
770 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
771 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
772
773 int dt_txn_hook_start(const struct lu_env *env,
774                       struct dt_device *dev, struct thandle *txn);
775 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
776 void dt_txn_hook_commit(struct thandle *txn);
777
778 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
779
780 /**
781  * Callback function used for parsing path.
782  * \see llo_store_resolve
783  */
784 typedef int (*dt_entry_func_t)(const struct lu_env *env,
785                             const char *name,
786                             void *pvt);
787
788 #define DT_MAX_PATH 1024
789
790 int dt_path_parser(const struct lu_env *env,
791                    char *local, dt_entry_func_t entry_func,
792                    void *data);
793
794 struct dt_object *dt_store_open(const struct lu_env *env,
795                                 struct dt_device *dt,
796                                 const char *dirname,
797                                 const char *filename,
798                                 struct lu_fid *fid);
799
800 struct dt_object *dt_find_or_create(const struct lu_env *env,
801                                     struct dt_device *dt,
802                                     const struct lu_fid *fid,
803                                     struct dt_object_format *dof,
804                                     struct lu_attr *attr);
805
806 struct dt_object *dt_locate_at(const struct lu_env *env,
807                                struct dt_device *dev,
808                                const struct lu_fid *fid,
809                                struct lu_device *top_dev);
810 static inline struct dt_object *
811 dt_locate(const struct lu_env *env, struct dt_device *dev,
812           const struct lu_fid *fid)
813 {
814         return dt_locate_at(env, dev, fid, dev->dd_lu_dev.ld_site->ls_top_dev);
815 }
816
817
818 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
819                            const struct lu_fid *first_fid,
820                            struct local_oid_storage **los);
821 void local_oid_storage_fini(const struct lu_env *env,
822                             struct local_oid_storage *los);
823 int local_object_fid_generate(const struct lu_env *env,
824                               struct local_oid_storage *los,
825                               struct lu_fid *fid);
826 int local_object_declare_create(const struct lu_env *env,
827                                 struct local_oid_storage *los,
828                                 struct dt_object *o,
829                                 struct lu_attr *attr,
830                                 struct dt_object_format *dof,
831                                 struct thandle *th);
832 int local_object_create(const struct lu_env *env,
833                         struct local_oid_storage *los,
834                         struct dt_object *o,
835                         struct lu_attr *attr, struct dt_object_format *dof,
836                         struct thandle *th);
837 struct dt_object *local_file_find_or_create(const struct lu_env *env,
838                                             struct local_oid_storage *los,
839                                             struct dt_object *parent,
840                                             const char *name, __u32 mode);
841 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
842                                                      struct dt_device *dt,
843                                                      const struct lu_fid *fid,
844                                                      struct dt_object *parent,
845                                                      const char *name,
846                                                      __u32 mode);
847 struct dt_object *
848 local_index_find_or_create(const struct lu_env *env,
849                            struct local_oid_storage *los,
850                            struct dt_object *parent,
851                            const char *name, __u32 mode,
852                            const struct dt_index_features *ft);
853 struct dt_object *
854 local_index_find_or_create_with_fid(const struct lu_env *env,
855                                     struct dt_device *dt,
856                                     const struct lu_fid *fid,
857                                     struct dt_object *parent,
858                                     const char *name, __u32 mode,
859                                     const struct dt_index_features *ft);
860
861 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
862                   const char *name, struct lu_fid *fid);
863
864 static inline int dt_object_sync(const struct lu_env *env,
865                                  struct dt_object *o)
866 {
867         LASSERT(o);
868         LASSERT(o->do_ops);
869         LASSERT(o->do_ops->do_object_sync);
870         return o->do_ops->do_object_sync(env, o);
871 }
872
873 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
874                            struct thandle *th);
875 void dt_version_set(const struct lu_env *env, struct dt_object *o,
876                     dt_obj_version_t version, struct thandle *th);
877 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
878
879
880 int dt_read(const struct lu_env *env, struct dt_object *dt,
881             struct lu_buf *buf, loff_t *pos);
882 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
883                    struct lu_buf *buf, loff_t *pos);
884 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
885                     const struct lu_buf *buf, loff_t *pos, struct thandle *th);
886 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
887                                      union lu_page *lp, int nob,
888                                      const struct dt_it_ops *iops,
889                                      struct dt_it *it, __u32 attr, void *arg);
890 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
891                   const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
892                   void *arg);
893 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
894                   struct idx_info *ii, const struct lu_rdpg *rdpg);
895
896 static inline struct thandle *dt_trans_create(const struct lu_env *env,
897                                               struct dt_device *d)
898 {
899         LASSERT(d->dd_ops->dt_trans_create);
900         return d->dd_ops->dt_trans_create(env, d);
901 }
902
903 static inline int dt_trans_start(const struct lu_env *env,
904                                  struct dt_device *d, struct thandle *th)
905 {
906         LASSERT(d->dd_ops->dt_trans_start);
907         return d->dd_ops->dt_trans_start(env, d, th);
908 }
909
910 /* for this transaction hooks shouldn't be called */
911 static inline int dt_trans_start_local(const struct lu_env *env,
912                                        struct dt_device *d, struct thandle *th)
913 {
914         LASSERT(d->dd_ops->dt_trans_start);
915         th->th_local = 1;
916         return d->dd_ops->dt_trans_start(env, d, th);
917 }
918
919 static inline int dt_trans_stop(const struct lu_env *env,
920                                 struct dt_device *d, struct thandle *th)
921 {
922         LASSERT(d->dd_ops->dt_trans_stop);
923         return d->dd_ops->dt_trans_stop(env, th);
924 }
925
926 static inline int dt_trans_cb_add(struct thandle *th,
927                                   struct dt_txn_commit_cb *dcb)
928 {
929         LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
930         dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
931         return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
932 }
933 /** @} dt */
934
935
936 static inline int dt_declare_record_write(const struct lu_env *env,
937                                           struct dt_object *dt,
938                                           int size, loff_t pos,
939                                           struct thandle *th)
940 {
941         int rc;
942
943         LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
944         LASSERT(th != NULL);
945         LASSERT(dt->do_body_ops);
946         LASSERT(dt->do_body_ops->dbo_declare_write);
947         rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
948         return rc;
949 }
950
951 static inline int dt_declare_create(const struct lu_env *env,
952                                     struct dt_object *dt,
953                                     struct lu_attr *attr,
954                                     struct dt_allocation_hint *hint,
955                                     struct dt_object_format *dof,
956                                     struct thandle *th)
957 {
958         LASSERT(dt);
959         LASSERT(dt->do_ops);
960         LASSERT(dt->do_ops->do_declare_create);
961         return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
962 }
963
964 static inline int dt_create(const struct lu_env *env,
965                                     struct dt_object *dt,
966                                     struct lu_attr *attr,
967                                     struct dt_allocation_hint *hint,
968                                     struct dt_object_format *dof,
969                                     struct thandle *th)
970 {
971         LASSERT(dt);
972         LASSERT(dt->do_ops);
973         LASSERT(dt->do_ops->do_create);
974         return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
975 }
976
977 static inline int dt_declare_destroy(const struct lu_env *env,
978                                      struct dt_object *dt,
979                                      struct thandle *th)
980 {
981         LASSERT(dt);
982         LASSERT(dt->do_ops);
983         LASSERT(dt->do_ops->do_declare_destroy);
984         return dt->do_ops->do_declare_destroy(env, dt, th);
985 }
986
987 static inline int dt_destroy(const struct lu_env *env,
988                              struct dt_object *dt,
989                              struct thandle *th)
990 {
991         LASSERT(dt);
992         LASSERT(dt->do_ops);
993         LASSERT(dt->do_ops->do_destroy);
994         return dt->do_ops->do_destroy(env, dt, th);
995 }
996
997 static inline void dt_read_lock(const struct lu_env *env,
998                                 struct dt_object *dt,
999                                 unsigned role)
1000 {
1001         LASSERT(dt);
1002         LASSERT(dt->do_ops);
1003         LASSERT(dt->do_ops->do_read_lock);
1004         dt->do_ops->do_read_lock(env, dt, role);
1005 }
1006
1007 static inline void dt_write_lock(const struct lu_env *env,
1008                                 struct dt_object *dt,
1009                                 unsigned role)
1010 {
1011         LASSERT(dt);
1012         LASSERT(dt->do_ops);
1013         LASSERT(dt->do_ops->do_write_lock);
1014         dt->do_ops->do_write_lock(env, dt, role);
1015 }
1016
1017 static inline void dt_read_unlock(const struct lu_env *env,
1018                                 struct dt_object *dt)
1019 {
1020         LASSERT(dt);
1021         LASSERT(dt->do_ops);
1022         LASSERT(dt->do_ops->do_read_unlock);
1023         dt->do_ops->do_read_unlock(env, dt);
1024 }
1025
1026 static inline void dt_write_unlock(const struct lu_env *env,
1027                                 struct dt_object *dt)
1028 {
1029         LASSERT(dt);
1030         LASSERT(dt->do_ops);
1031         LASSERT(dt->do_ops->do_write_unlock);
1032         dt->do_ops->do_write_unlock(env, dt);
1033 }
1034
1035 static inline int dt_write_locked(const struct lu_env *env,
1036                                   struct dt_object *dt)
1037 {
1038         LASSERT(dt);
1039         LASSERT(dt->do_ops);
1040         LASSERT(dt->do_ops->do_write_locked);
1041         return dt->do_ops->do_write_locked(env, dt);
1042 }
1043
1044 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
1045                               struct lu_attr *la, void *arg)
1046 {
1047         LASSERT(dt);
1048         LASSERT(dt->do_ops);
1049         LASSERT(dt->do_ops->do_attr_get);
1050         return dt->do_ops->do_attr_get(env, dt, la, arg);
1051 }
1052
1053 static inline int dt_declare_attr_set(const struct lu_env *env,
1054                                       struct dt_object *dt,
1055                                       const struct lu_attr *la,
1056                                       struct thandle *th)
1057 {
1058         LASSERT(dt);
1059         LASSERT(dt->do_ops);
1060         LASSERT(dt->do_ops->do_declare_attr_set);
1061         return dt->do_ops->do_declare_attr_set(env, dt, la, th);
1062 }
1063
1064 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
1065                               const struct lu_attr *la, struct thandle *th,
1066                               struct lustre_capa *capa)
1067 {
1068         LASSERT(dt);
1069         LASSERT(dt->do_ops);
1070         LASSERT(dt->do_ops->do_attr_set);
1071         return dt->do_ops->do_attr_set(env, dt, la, th, capa);
1072 }
1073
1074 static inline int dt_declare_ref_add(const struct lu_env *env,
1075                                      struct dt_object *dt, struct thandle *th)
1076 {
1077         LASSERT(dt);
1078         LASSERT(dt->do_ops);
1079         LASSERT(dt->do_ops->do_declare_ref_add);
1080         return dt->do_ops->do_declare_ref_add(env, dt, th);
1081 }
1082
1083 static inline int dt_ref_add(const struct lu_env *env,
1084                              struct dt_object *dt, struct thandle *th)
1085 {
1086         LASSERT(dt);
1087         LASSERT(dt->do_ops);
1088         LASSERT(dt->do_ops->do_ref_add);
1089         return dt->do_ops->do_ref_add(env, dt, th);
1090 }
1091
1092 static inline int dt_declare_ref_del(const struct lu_env *env,
1093                                      struct dt_object *dt, struct thandle *th)
1094 {
1095         LASSERT(dt);
1096         LASSERT(dt->do_ops);
1097         LASSERT(dt->do_ops->do_declare_ref_del);
1098         return dt->do_ops->do_declare_ref_del(env, dt, th);
1099 }
1100
1101 static inline int dt_ref_del(const struct lu_env *env,
1102                              struct dt_object *dt, struct thandle *th)
1103 {
1104         LASSERT(dt);
1105         LASSERT(dt->do_ops);
1106         LASSERT(dt->do_ops->do_ref_del);
1107         return dt->do_ops->do_ref_del(env, dt, th);
1108 }
1109
1110 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1111                                            struct dt_object *dt,
1112                                            struct lustre_capa *old, __u64 opc)
1113 {
1114         LASSERT(dt);
1115         LASSERT(dt->do_ops);
1116         LASSERT(dt->do_ops->do_ref_del);
1117         return dt->do_ops->do_capa_get(env, dt, old, opc);
1118 }
1119
1120 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1121                               struct niobuf_remote *rnb,
1122                               struct niobuf_local *lnb, int rw,
1123                               struct lustre_capa *capa)
1124 {
1125         LASSERT(d);
1126         LASSERT(d->do_body_ops);
1127         LASSERT(d->do_body_ops->dbo_bufs_get);
1128         return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1129                                             rnb->len, lnb, rw, capa);
1130 }
1131
1132 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1133                               struct niobuf_local *lnb, int n)
1134 {
1135         LASSERT(d);
1136         LASSERT(d->do_body_ops);
1137         LASSERT(d->do_body_ops->dbo_bufs_put);
1138         return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1139 }
1140
1141 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1142                                 struct niobuf_local *lnb, int n)
1143 {
1144         LASSERT(d);
1145         LASSERT(d->do_body_ops);
1146         LASSERT(d->do_body_ops->dbo_write_prep);
1147         return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1148 }
1149
1150 static inline int dt_declare_write_commit(const struct lu_env *env,
1151                                           struct dt_object *d,
1152                                           struct niobuf_local *lnb,
1153                                           int n, struct thandle *th)
1154 {
1155         LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1156         LASSERT(th != NULL);
1157         return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1158 }
1159
1160
1161 static inline int dt_write_commit(const struct lu_env *env,
1162                                   struct dt_object *d, struct niobuf_local *lnb,
1163                                   int n, struct thandle *th)
1164 {
1165         LASSERT(d);
1166         LASSERT(d->do_body_ops);
1167         LASSERT(d->do_body_ops->dbo_write_commit);
1168         return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1169 }
1170
1171 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1172                                struct niobuf_local *lnb, int n)
1173 {
1174         LASSERT(d);
1175         LASSERT(d->do_body_ops);
1176         LASSERT(d->do_body_ops->dbo_read_prep);
1177         return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1178 }
1179
1180 static inline int dt_declare_punch(const struct lu_env *env,
1181                                    struct dt_object *dt, __u64 start,
1182                                    __u64 end, struct thandle *th)
1183 {
1184         LASSERT(dt);
1185         LASSERT(dt->do_body_ops);
1186         LASSERT(dt->do_body_ops->do_declare_punch);
1187         return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1188 }
1189
1190 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1191                            __u64 start, __u64 end, struct thandle *th,
1192                            struct lustre_capa *capa)
1193 {
1194         LASSERT(dt);
1195         LASSERT(dt->do_body_ops);
1196         LASSERT(dt->do_body_ops->do_punch);
1197         return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1198 }
1199
1200 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1201                                 struct ll_user_fiemap *fm)
1202 {
1203         LASSERT(d);
1204         if (d->do_body_ops == NULL)
1205                 return -EPROTO;
1206         if (d->do_body_ops->dbo_fiemap_get == NULL)
1207                 return -EOPNOTSUPP;
1208         return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1209 }
1210
1211 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1212                             struct obd_statfs *osfs)
1213 {
1214         LASSERT(dev);
1215         LASSERT(dev->dd_ops);
1216         LASSERT(dev->dd_ops->dt_statfs);
1217         return dev->dd_ops->dt_statfs(env, dev, osfs);
1218 }
1219
1220 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1221                               struct lu_fid *f)
1222 {
1223         LASSERT(dev);
1224         LASSERT(dev->dd_ops);
1225         LASSERT(dev->dd_ops->dt_root_get);
1226         return dev->dd_ops->dt_root_get(env, dev, f);
1227 }
1228
1229 static inline void dt_conf_get(const struct lu_env *env,
1230                                const struct dt_device *dev,
1231                                struct dt_device_param *param)
1232 {
1233         LASSERT(dev);
1234         LASSERT(dev->dd_ops);
1235         LASSERT(dev->dd_ops->dt_conf_get);
1236         return dev->dd_ops->dt_conf_get(env, dev, param);
1237 }
1238
1239 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1240 {
1241         LASSERT(dev);
1242         LASSERT(dev->dd_ops);
1243         LASSERT(dev->dd_ops->dt_sync);
1244         return dev->dd_ops->dt_sync(env, dev);
1245 }
1246
1247 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1248 {
1249         LASSERT(dev);
1250         LASSERT(dev->dd_ops);
1251         LASSERT(dev->dd_ops->dt_ro);
1252         return dev->dd_ops->dt_ro(env, dev);
1253 }
1254
1255 static inline int dt_declare_insert(const struct lu_env *env,
1256                                     struct dt_object *dt,
1257                                     const struct dt_rec *rec,
1258                                     const struct dt_key *key,
1259                                     struct thandle *th)
1260 {
1261         LASSERT(dt);
1262         LASSERT(dt->do_index_ops);
1263         LASSERT(dt->do_index_ops->dio_declare_insert);
1264         return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1265 }
1266
1267 static inline int dt_insert(const struct lu_env *env,
1268                                     struct dt_object *dt,
1269                                     const struct dt_rec *rec,
1270                                     const struct dt_key *key,
1271                                     struct thandle *th,
1272                                     struct lustre_capa *capa,
1273                                     int noquota)
1274 {
1275         LASSERT(dt);
1276         LASSERT(dt->do_index_ops);
1277         LASSERT(dt->do_index_ops->dio_insert);
1278         return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1279                                             capa, noquota);
1280 }
1281
1282 static inline int dt_declare_xattr_del(const struct lu_env *env,
1283                                        struct dt_object *dt,
1284                                        const char *name,
1285                                        struct thandle *th)
1286 {
1287         LASSERT(dt);
1288         LASSERT(dt->do_ops);
1289         LASSERT(dt->do_ops->do_declare_xattr_del);
1290         return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1291 }
1292
1293 static inline int dt_xattr_del(const struct lu_env *env,
1294                                struct dt_object *dt, const char *name,
1295                                struct thandle *th,
1296                                struct lustre_capa *capa)
1297 {
1298         LASSERT(dt);
1299         LASSERT(dt->do_ops);
1300         LASSERT(dt->do_ops->do_xattr_del);
1301         return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1302 }
1303
1304 static inline int dt_declare_xattr_set(const struct lu_env *env,
1305                                       struct dt_object *dt,
1306                                       const struct lu_buf *buf,
1307                                       const char *name, int fl,
1308                                       struct thandle *th)
1309 {
1310         LASSERT(dt);
1311         LASSERT(dt->do_ops);
1312         LASSERT(dt->do_ops->do_declare_xattr_set);
1313         return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1314 }
1315
1316 static inline int dt_xattr_set(const struct lu_env *env,
1317                               struct dt_object *dt, const struct lu_buf *buf,
1318                               const char *name, int fl, struct thandle *th,
1319                               struct lustre_capa *capa)
1320 {
1321         LASSERT(dt);
1322         LASSERT(dt->do_ops);
1323         LASSERT(dt->do_ops->do_xattr_set);
1324         return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1325 }
1326
1327 static inline int dt_xattr_get(const struct lu_env *env,
1328                               struct dt_object *dt, struct lu_buf *buf,
1329                               const char *name, struct lustre_capa *capa)
1330 {
1331         LASSERT(dt);
1332         LASSERT(dt->do_ops);
1333         LASSERT(dt->do_ops->do_xattr_get);
1334         return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1335 }
1336
1337 static inline int dt_xattr_list(const struct lu_env *env,
1338                                struct dt_object *dt, struct lu_buf *buf,
1339                                struct lustre_capa *capa)
1340 {
1341         LASSERT(dt);
1342         LASSERT(dt->do_ops);
1343         LASSERT(dt->do_ops->do_xattr_list);
1344         return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1345 }
1346
1347 static inline int dt_declare_delete(const struct lu_env *env,
1348                                     struct dt_object *dt,
1349                                     const struct dt_key *key,
1350                                     struct thandle *th)
1351 {
1352         LASSERT(dt);
1353         LASSERT(dt->do_index_ops);
1354         LASSERT(dt->do_index_ops->dio_declare_delete);
1355         return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1356 }
1357
1358 static inline int dt_delete(const struct lu_env *env,
1359                             struct dt_object *dt,
1360                             const struct dt_key *key,
1361                             struct thandle *th,
1362                             struct lustre_capa *capa)
1363 {
1364         LASSERT(dt);
1365         LASSERT(dt->do_index_ops);
1366         LASSERT(dt->do_index_ops->dio_delete);
1367         return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1368 }
1369
1370 static inline int dt_commit_async(const struct lu_env *env,
1371                                   struct dt_device *dev)
1372 {
1373         LASSERT(dev);
1374         LASSERT(dev->dd_ops);
1375         LASSERT(dev->dd_ops->dt_commit_async);
1376         return dev->dd_ops->dt_commit_async(env, dev);
1377 }
1378
1379 static inline int dt_init_capa_ctxt(const struct lu_env *env,
1380                                     struct dt_device *dev,
1381                                     int mode, unsigned long timeout,
1382                                     __u32 alg, struct lustre_capa_key *keys)
1383 {
1384         LASSERT(dev);
1385         LASSERT(dev->dd_ops);
1386         LASSERT(dev->dd_ops->dt_init_capa_ctxt);
1387         return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
1388                                               timeout, alg, keys);
1389 }
1390
1391 static inline int dt_lookup(const struct lu_env *env,
1392                             struct dt_object *dt,
1393                             struct dt_rec *rec,
1394                             const struct dt_key *key,
1395                             struct lustre_capa *capa)
1396 {
1397         int ret;
1398
1399         LASSERT(dt);
1400         LASSERT(dt->do_index_ops);
1401         LASSERT(dt->do_index_ops->dio_lookup);
1402
1403         ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1404         if (ret > 0)
1405                 ret = 0;
1406         else if (ret == 0)
1407                 ret = -ENOENT;
1408         return ret;
1409 }
1410
1411 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1412
1413 struct dt_find_hint {
1414         struct lu_fid        *dfh_fid;
1415         struct dt_device     *dfh_dt;
1416         struct dt_object     *dfh_o;
1417 };
1418
1419 struct dt_thread_info {
1420         char                     dti_buf[DT_MAX_PATH];
1421         struct dt_find_hint      dti_dfh;
1422         struct lu_attr           dti_attr;
1423         struct lu_fid            dti_fid;
1424         struct dt_object_format  dti_dof;
1425         struct lustre_mdt_attrs  dti_lma;
1426         struct lu_buf            dti_lb;
1427         loff_t                   dti_off;
1428 };
1429
1430 extern struct lu_context_key dt_key;
1431
1432 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
1433 {
1434         struct dt_thread_info *dti;
1435
1436         dti = lu_context_key_get(&env->le_ctx, &dt_key);
1437         LASSERT(dti);
1438         return dti;
1439 }
1440
1441 #endif /* __LUSTRE_DT_OBJECT_H */