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