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