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