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