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