Whamcloud - gitweb
LU-2675 cleanup: make bitfield (un)signedness explicit
[fs/lustre-release.git] / lustre / include / dt_object.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, 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 /**
455  * Per-dt-object operations on "file body".
456  */
457 struct dt_body_operations {
458         /**
459          * precondition: dt_object_exists(dt);
460          */
461         ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
462                             struct lu_buf *buf, loff_t *pos,
463                             struct lustre_capa *capa);
464         /**
465          * precondition: dt_object_exists(dt);
466          */
467         ssize_t (*dbo_declare_write)(const struct lu_env *env,
468                                      struct dt_object *dt,
469                                      const loff_t size, loff_t pos,
470                                      struct thandle *handle);
471         ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
472                              const struct lu_buf *buf, loff_t *pos,
473                              struct thandle *handle, struct lustre_capa *capa,
474                              int ignore_quota);
475         /*
476          * methods for zero-copy IO
477          */
478
479         /*
480          * precondition: dt_object_exists(dt);
481          * returns:
482          * < 0 - error code
483          * = 0 - illegal
484          * > 0 - number of local buffers prepared
485          */
486         int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
487                             loff_t pos, ssize_t len, struct niobuf_local *lb,
488                             int rw, struct lustre_capa *capa);
489         /*
490          * precondition: dt_object_exists(dt);
491          */
492         int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
493                             struct niobuf_local *lb, int nr);
494         /*
495          * precondition: dt_object_exists(dt);
496          */
497         int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
498                               struct niobuf_local *lb, int nr);
499         /*
500          * precondition: dt_object_exists(dt);
501          */
502         int (*dbo_declare_write_commit)(const struct lu_env *env,
503                                         struct dt_object *dt,
504                                         struct niobuf_local *,
505                                         int, struct thandle *);
506         /*
507          * precondition: dt_object_exists(dt);
508          */
509         int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
510                                 struct niobuf_local *, int, struct thandle *);
511         /*
512          * precondition: dt_object_exists(dt);
513          */
514         int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
515                              struct niobuf_local *lnb, int nr);
516         int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
517                               struct ll_user_fiemap *fm);
518         /**
519          * Punch object's content
520          * precondition: regular object, not index
521          */
522         int   (*do_declare_punch)(const struct lu_env *, struct dt_object *,
523                                   __u64, __u64, struct thandle *th);
524         int   (*do_punch)(const struct lu_env *env, struct dt_object *dt,
525                           __u64 start, __u64 end, struct thandle *th,
526                           struct lustre_capa *capa);
527 };
528
529 struct dt_lock_operations {
530         int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
531                               struct lustre_handle *lh,
532                               struct ldlm_enqueue_info *einfo,
533                               void *policy);
534 };
535 /**
536  * Incomplete type of index record.
537  */
538 struct dt_rec;
539
540 /**
541  * Incomplete type of index key.
542  */
543 struct dt_key;
544
545 /**
546  * Incomplete type of dt iterator.
547  */
548 struct dt_it;
549
550 /**
551  * Per-dt-object operations on object as index.
552  */
553 struct dt_index_operations {
554         /**
555          * precondition: dt_object_exists(dt);
556          */
557         int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
558                           struct dt_rec *rec, const struct dt_key *key,
559                           struct lustre_capa *capa);
560         /**
561          * precondition: dt_object_exists(dt);
562          */
563         int (*dio_declare_insert)(const struct lu_env *env,
564                                   struct dt_object *dt,
565                                   const struct dt_rec *rec,
566                                   const struct dt_key *key,
567                                   struct thandle *handle);
568         int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
569                           const struct dt_rec *rec, const struct dt_key *key,
570                           struct thandle *handle, struct lustre_capa *capa,
571                           int ignore_quota);
572         /**
573          * precondition: dt_object_exists(dt);
574          */
575         int (*dio_declare_delete)(const struct lu_env *env,
576                                   struct dt_object *dt,
577                                   const struct dt_key *key,
578                                   struct thandle *handle);
579         int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
580                           const struct dt_key *key, struct thandle *handle,
581                           struct lustre_capa *capa);
582         /**
583          * Iterator interface
584          */
585         struct dt_it_ops {
586                 /**
587                  * Allocate and initialize new iterator.
588                  *
589                  * precondition: dt_object_exists(dt);
590                  */
591                 struct dt_it *(*init)(const struct lu_env *env,
592                                       struct dt_object *dt,
593                                       __u32 attr,
594                                       struct lustre_capa *capa);
595                 void          (*fini)(const struct lu_env *env,
596                                       struct dt_it *di);
597                 int            (*get)(const struct lu_env *env,
598                                       struct dt_it *di,
599                                       const struct dt_key *key);
600                 void           (*put)(const struct lu_env *env,
601                                       struct dt_it *di);
602                 int           (*next)(const struct lu_env *env,
603                                       struct dt_it *di);
604                 struct dt_key *(*key)(const struct lu_env *env,
605                                       const struct dt_it *di);
606                 int       (*key_size)(const struct lu_env *env,
607                                       const struct dt_it *di);
608                 int            (*rec)(const struct lu_env *env,
609                                       const struct dt_it *di,
610                                       struct dt_rec *rec,
611                                       __u32 attr);
612                 __u64        (*store)(const struct lu_env *env,
613                                       const struct dt_it *di);
614                 int           (*load)(const struct lu_env *env,
615                                       const struct dt_it *di, __u64 hash);
616                 int        (*key_rec)(const struct lu_env *env,
617                                       const struct dt_it *di, void* key_rec);
618         } dio_it;
619 };
620
621 enum dt_otable_it_valid {
622         DOIV_ERROR_HANDLE       = 0x0001,
623 };
624
625 enum dt_otable_it_flags {
626         /* Exit when fail. */
627         DOIF_FAILOUT    = 0x0001,
628
629         /* Reset iteration position to the device beginning. */
630         DOIF_RESET      = 0x0002,
631
632         /* There is up layer component uses the iteration. */
633         DOIF_OUTUSED    = 0x0004,
634 };
635
636 /* otable based iteration needs to use the common DT interation APIs.
637  * To initialize the iteration, it needs call dio_it::init() firstly.
638  * Here is how the otable based iteration should prepare arguments to
639  * call dt_it_ops::init().
640  *
641  * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
642  * is composed of two parts:
643  * low 16-bits is for valid bits, high 16-bits is for flags bits. */
644 #define DT_OTABLE_IT_FLAGS_SHIFT        16
645 #define DT_OTABLE_IT_FLAGS_MASK         0xffff0000
646
647 struct dt_device {
648         struct lu_device                   dd_lu_dev;
649         const struct dt_device_operations *dd_ops;
650
651         /**
652          * List of dt_txn_callback (see below). This is not protected in any
653          * way, because callbacks are supposed to be added/deleted only during
654          * single-threaded start-up shut-down procedures.
655          */
656         cfs_list_t                         dd_txn_callbacks;
657 };
658
659 int  dt_device_init(struct dt_device *dev, struct lu_device_type *t);
660 void dt_device_fini(struct dt_device *dev);
661
662 static inline int lu_device_is_dt(const struct lu_device *d)
663 {
664         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
665 }
666
667 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
668 {
669         LASSERT(lu_device_is_dt(l));
670         return container_of0(l, struct dt_device, dd_lu_dev);
671 }
672
673 struct dt_object {
674         struct lu_object                   do_lu;
675         const struct dt_object_operations *do_ops;
676         const struct dt_body_operations   *do_body_ops;
677         const struct dt_index_operations  *do_index_ops;
678         const struct dt_lock_operations   *do_lock_ops;
679 };
680
681 /*
682  * In-core representation of per-device local object OID storage
683  */
684 struct local_oid_storage {
685         /* all initialized llog systems on this node linked by this */
686         cfs_list_t        los_list;
687
688         /* how many handle's reference this los has */
689         cfs_atomic_t      los_refcount;
690         struct dt_device *los_dev;
691         struct dt_object *los_obj;
692
693         /* data used to generate new fids */
694         struct mutex     los_id_lock;
695         __u64             los_seq;
696         __u32             los_last_oid;
697 };
698
699 static inline struct dt_object *lu2dt(struct lu_object *l)
700 {
701         LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
702         return container_of0(l, struct dt_object, do_lu);
703 }
704
705 int  dt_object_init(struct dt_object *obj,
706                     struct lu_object_header *h, struct lu_device *d);
707
708 void dt_object_fini(struct dt_object *obj);
709
710 static inline int dt_object_exists(const struct dt_object *dt)
711 {
712         return lu_object_exists(&dt->do_lu);
713 }
714
715 static inline int dt_object_remote(const struct dt_object *dt)
716 {
717         return lu_object_remote(&dt->do_lu);
718 }
719
720 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
721 {
722         LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
723         return container_of0(o, struct dt_object, do_lu);
724 }
725
726 /**
727  * This is the general purpose transaction handle.
728  * 1. Transaction Life Cycle
729  *      This transaction handle is allocated upon starting a new transaction,
730  *      and deallocated after this transaction is committed.
731  * 2. Transaction Nesting
732  *      We do _NOT_ support nested transaction. So, every thread should only
733  *      have one active transaction, and a transaction only belongs to one
734  *      thread. Due to this, transaction handle need no reference count.
735  * 3. Transaction & dt_object locking
736  *      dt_object locks should be taken inside transaction.
737  * 4. Transaction & RPC
738  *      No RPC request should be issued inside transaction.
739  */
740 struct thandle {
741         /** the dt device on which the transactions are executed */
742         struct dt_device *th_dev;
743
744         /** context for this transaction, tag is LCT_TX_HANDLE */
745         struct lu_context th_ctx;
746
747         /** additional tags (layers can add in declare) */
748         __u32             th_tags;
749
750         /** the last operation result in this transaction.
751          * this value is used in recovery */
752         __s32             th_result;
753
754         /** whether we need sync commit */
755         unsigned int            th_sync:1;
756
757         /* local transation, no need to inform other layers */
758         unsigned int            th_local:1;
759
760         /* In DNE, one transaction can be disassemblied into
761          * updates on several different MDTs, and these updates
762          * will be attached to th_remote_update_list per target.
763          * Only single thread will access the list, no need lock
764          */
765         cfs_list_t              th_remote_update_list;
766         struct update_request   *th_current_request;
767 };
768
769 /**
770  * Transaction call-backs.
771  *
772  * These are invoked by osd (or underlying transaction engine) when
773  * transaction changes state.
774  *
775  * Call-backs are used by upper layers to modify transaction parameters and to
776  * perform some actions on for each transaction state transition. Typical
777  * example is mdt registering call-back to write into last-received file
778  * before each transaction commit.
779  */
780 struct dt_txn_callback {
781         int (*dtc_txn_start)(const struct lu_env *env,
782                              struct thandle *txn, void *cookie);
783         int (*dtc_txn_stop)(const struct lu_env *env,
784                             struct thandle *txn, void *cookie);
785         void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
786         void                *dtc_cookie;
787         __u32                dtc_tag;
788         cfs_list_t           dtc_linkage;
789 };
790
791 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
792 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
793
794 int dt_txn_hook_start(const struct lu_env *env,
795                       struct dt_device *dev, struct thandle *txn);
796 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
797 void dt_txn_hook_commit(struct thandle *txn);
798
799 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
800
801 /**
802  * Callback function used for parsing path.
803  * \see llo_store_resolve
804  */
805 typedef int (*dt_entry_func_t)(const struct lu_env *env,
806                             const char *name,
807                             void *pvt);
808
809 #define DT_MAX_PATH 1024
810
811 int dt_path_parser(const struct lu_env *env,
812                    char *local, dt_entry_func_t entry_func,
813                    void *data);
814
815 struct dt_object *
816 dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
817                  const char *path, struct lu_fid *fid);
818
819 struct dt_object *dt_store_open(const struct lu_env *env,
820                                 struct dt_device *dt,
821                                 const char *dirname,
822                                 const char *filename,
823                                 struct lu_fid *fid);
824
825 struct dt_object *dt_find_or_create(const struct lu_env *env,
826                                     struct dt_device *dt,
827                                     const struct lu_fid *fid,
828                                     struct dt_object_format *dof,
829                                     struct lu_attr *attr);
830
831 struct dt_object *dt_locate_at(const struct lu_env *env,
832                                struct dt_device *dev,
833                                const struct lu_fid *fid,
834                                struct lu_device *top_dev);
835 static inline struct dt_object *
836 dt_locate(const struct lu_env *env, struct dt_device *dev,
837           const struct lu_fid *fid)
838 {
839         return dt_locate_at(env, dev, fid, dev->dd_lu_dev.ld_site->ls_top_dev);
840 }
841
842
843 int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
844                            const struct lu_fid *first_fid,
845                            struct local_oid_storage **los);
846 void local_oid_storage_fini(const struct lu_env *env,
847                             struct local_oid_storage *los);
848 int local_object_fid_generate(const struct lu_env *env,
849                               struct local_oid_storage *los,
850                               struct lu_fid *fid);
851 int local_object_declare_create(const struct lu_env *env,
852                                 struct local_oid_storage *los,
853                                 struct dt_object *o,
854                                 struct lu_attr *attr,
855                                 struct dt_object_format *dof,
856                                 struct thandle *th);
857 int local_object_create(const struct lu_env *env,
858                         struct local_oid_storage *los,
859                         struct dt_object *o,
860                         struct lu_attr *attr, struct dt_object_format *dof,
861                         struct thandle *th);
862 struct dt_object *local_file_find_or_create(const struct lu_env *env,
863                                             struct local_oid_storage *los,
864                                             struct dt_object *parent,
865                                             const char *name, __u32 mode);
866 struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
867                                                      struct dt_device *dt,
868                                                      const struct lu_fid *fid,
869                                                      struct dt_object *parent,
870                                                      const char *name,
871                                                      __u32 mode);
872 struct dt_object *
873 local_index_find_or_create(const struct lu_env *env,
874                            struct local_oid_storage *los,
875                            struct dt_object *parent,
876                            const char *name, __u32 mode,
877                            const struct dt_index_features *ft);
878 struct dt_object *
879 local_index_find_or_create_with_fid(const struct lu_env *env,
880                                     struct dt_device *dt,
881                                     const struct lu_fid *fid,
882                                     struct dt_object *parent,
883                                     const char *name, __u32 mode,
884                                     const struct dt_index_features *ft);
885
886 static inline int dt_object_lock(const struct lu_env *env,
887                                  struct dt_object *o, struct lustre_handle *lh,
888                                  struct ldlm_enqueue_info *einfo,
889                                  void *policy)
890 {
891         LASSERT(o);
892         LASSERT(o->do_lock_ops);
893         LASSERT(o->do_lock_ops->do_object_lock);
894         return o->do_lock_ops->do_object_lock(env, o, lh, einfo, policy);
895 }
896
897 int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
898                   const char *name, struct lu_fid *fid);
899
900 static inline int dt_object_sync(const struct lu_env *env,
901                                  struct dt_object *o)
902 {
903         LASSERT(o);
904         LASSERT(o->do_ops);
905         LASSERT(o->do_ops->do_object_sync);
906         return o->do_ops->do_object_sync(env, o);
907 }
908
909 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
910                            struct thandle *th);
911 void dt_version_set(const struct lu_env *env, struct dt_object *o,
912                     dt_obj_version_t version, struct thandle *th);
913 dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
914
915
916 int dt_read(const struct lu_env *env, struct dt_object *dt,
917             struct lu_buf *buf, loff_t *pos);
918 int dt_record_read(const struct lu_env *env, struct dt_object *dt,
919                    struct lu_buf *buf, loff_t *pos);
920 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
921                     const struct lu_buf *buf, loff_t *pos, struct thandle *th);
922 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
923                                      union lu_page *lp, int nob,
924                                      const struct dt_it_ops *iops,
925                                      struct dt_it *it, __u32 attr, void *arg);
926 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
927                   const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
928                   void *arg);
929 int dt_index_read(const struct lu_env *env, struct dt_device *dev,
930                   struct idx_info *ii, const struct lu_rdpg *rdpg);
931
932 static inline struct thandle *dt_trans_create(const struct lu_env *env,
933                                               struct dt_device *d)
934 {
935         LASSERT(d->dd_ops->dt_trans_create);
936         return d->dd_ops->dt_trans_create(env, d);
937 }
938
939 static inline int dt_trans_start(const struct lu_env *env,
940                                  struct dt_device *d, struct thandle *th)
941 {
942         LASSERT(d->dd_ops->dt_trans_start);
943         return d->dd_ops->dt_trans_start(env, d, th);
944 }
945
946 /* for this transaction hooks shouldn't be called */
947 static inline int dt_trans_start_local(const struct lu_env *env,
948                                        struct dt_device *d, struct thandle *th)
949 {
950         LASSERT(d->dd_ops->dt_trans_start);
951         th->th_local = 1;
952         return d->dd_ops->dt_trans_start(env, d, th);
953 }
954
955 static inline int dt_trans_stop(const struct lu_env *env,
956                                 struct dt_device *d, struct thandle *th)
957 {
958         LASSERT(d->dd_ops->dt_trans_stop);
959         return d->dd_ops->dt_trans_stop(env, th);
960 }
961
962 static inline int dt_trans_cb_add(struct thandle *th,
963                                   struct dt_txn_commit_cb *dcb)
964 {
965         LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
966         dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
967         return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
968 }
969 /** @} dt */
970
971
972 static inline int dt_declare_record_write(const struct lu_env *env,
973                                           struct dt_object *dt,
974                                           int size, loff_t pos,
975                                           struct thandle *th)
976 {
977         int rc;
978
979         LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
980         LASSERT(th != NULL);
981         LASSERT(dt->do_body_ops);
982         LASSERT(dt->do_body_ops->dbo_declare_write);
983         rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
984         return rc;
985 }
986
987 static inline int dt_declare_create(const struct lu_env *env,
988                                     struct dt_object *dt,
989                                     struct lu_attr *attr,
990                                     struct dt_allocation_hint *hint,
991                                     struct dt_object_format *dof,
992                                     struct thandle *th)
993 {
994         LASSERT(dt);
995         LASSERT(dt->do_ops);
996         LASSERT(dt->do_ops->do_declare_create);
997         return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
998 }
999
1000 static inline int dt_create(const struct lu_env *env,
1001                                     struct dt_object *dt,
1002                                     struct lu_attr *attr,
1003                                     struct dt_allocation_hint *hint,
1004                                     struct dt_object_format *dof,
1005                                     struct thandle *th)
1006 {
1007         LASSERT(dt);
1008         LASSERT(dt->do_ops);
1009         LASSERT(dt->do_ops->do_create);
1010         return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
1011 }
1012
1013 static inline int dt_declare_destroy(const struct lu_env *env,
1014                                      struct dt_object *dt,
1015                                      struct thandle *th)
1016 {
1017         LASSERT(dt);
1018         LASSERT(dt->do_ops);
1019         LASSERT(dt->do_ops->do_declare_destroy);
1020         return dt->do_ops->do_declare_destroy(env, dt, th);
1021 }
1022
1023 static inline int dt_destroy(const struct lu_env *env,
1024                              struct dt_object *dt,
1025                              struct thandle *th)
1026 {
1027         LASSERT(dt);
1028         LASSERT(dt->do_ops);
1029         LASSERT(dt->do_ops->do_destroy);
1030         return dt->do_ops->do_destroy(env, dt, th);
1031 }
1032
1033 static inline void dt_read_lock(const struct lu_env *env,
1034                                 struct dt_object *dt,
1035                                 unsigned role)
1036 {
1037         LASSERT(dt);
1038         LASSERT(dt->do_ops);
1039         LASSERT(dt->do_ops->do_read_lock);
1040         dt->do_ops->do_read_lock(env, dt, role);
1041 }
1042
1043 static inline void dt_write_lock(const struct lu_env *env,
1044                                 struct dt_object *dt,
1045                                 unsigned role)
1046 {
1047         LASSERT(dt);
1048         LASSERT(dt->do_ops);
1049         LASSERT(dt->do_ops->do_write_lock);
1050         dt->do_ops->do_write_lock(env, dt, role);
1051 }
1052
1053 static inline void dt_read_unlock(const struct lu_env *env,
1054                                 struct dt_object *dt)
1055 {
1056         LASSERT(dt);
1057         LASSERT(dt->do_ops);
1058         LASSERT(dt->do_ops->do_read_unlock);
1059         dt->do_ops->do_read_unlock(env, dt);
1060 }
1061
1062 static inline void dt_write_unlock(const struct lu_env *env,
1063                                 struct dt_object *dt)
1064 {
1065         LASSERT(dt);
1066         LASSERT(dt->do_ops);
1067         LASSERT(dt->do_ops->do_write_unlock);
1068         dt->do_ops->do_write_unlock(env, dt);
1069 }
1070
1071 static inline int dt_write_locked(const struct lu_env *env,
1072                                   struct dt_object *dt)
1073 {
1074         LASSERT(dt);
1075         LASSERT(dt->do_ops);
1076         LASSERT(dt->do_ops->do_write_locked);
1077         return dt->do_ops->do_write_locked(env, dt);
1078 }
1079
1080 static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
1081                               struct lu_attr *la, void *arg)
1082 {
1083         LASSERT(dt);
1084         LASSERT(dt->do_ops);
1085         LASSERT(dt->do_ops->do_attr_get);
1086         return dt->do_ops->do_attr_get(env, dt, la, arg);
1087 }
1088
1089 static inline int dt_declare_attr_set(const struct lu_env *env,
1090                                       struct dt_object *dt,
1091                                       const struct lu_attr *la,
1092                                       struct thandle *th)
1093 {
1094         LASSERT(dt);
1095         LASSERT(dt->do_ops);
1096         LASSERT(dt->do_ops->do_declare_attr_set);
1097         return dt->do_ops->do_declare_attr_set(env, dt, la, th);
1098 }
1099
1100 static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
1101                               const struct lu_attr *la, struct thandle *th,
1102                               struct lustre_capa *capa)
1103 {
1104         LASSERT(dt);
1105         LASSERT(dt->do_ops);
1106         LASSERT(dt->do_ops->do_attr_set);
1107         return dt->do_ops->do_attr_set(env, dt, la, th, capa);
1108 }
1109
1110 static inline int dt_declare_ref_add(const struct lu_env *env,
1111                                      struct dt_object *dt, struct thandle *th)
1112 {
1113         LASSERT(dt);
1114         LASSERT(dt->do_ops);
1115         LASSERT(dt->do_ops->do_declare_ref_add);
1116         return dt->do_ops->do_declare_ref_add(env, dt, th);
1117 }
1118
1119 static inline int dt_ref_add(const struct lu_env *env,
1120                              struct dt_object *dt, struct thandle *th)
1121 {
1122         LASSERT(dt);
1123         LASSERT(dt->do_ops);
1124         LASSERT(dt->do_ops->do_ref_add);
1125         return dt->do_ops->do_ref_add(env, dt, th);
1126 }
1127
1128 static inline int dt_declare_ref_del(const struct lu_env *env,
1129                                      struct dt_object *dt, struct thandle *th)
1130 {
1131         LASSERT(dt);
1132         LASSERT(dt->do_ops);
1133         LASSERT(dt->do_ops->do_declare_ref_del);
1134         return dt->do_ops->do_declare_ref_del(env, dt, th);
1135 }
1136
1137 static inline int dt_ref_del(const struct lu_env *env,
1138                              struct dt_object *dt, struct thandle *th)
1139 {
1140         LASSERT(dt);
1141         LASSERT(dt->do_ops);
1142         LASSERT(dt->do_ops->do_ref_del);
1143         return dt->do_ops->do_ref_del(env, dt, th);
1144 }
1145
1146 static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
1147                                            struct dt_object *dt,
1148                                            struct lustre_capa *old, __u64 opc)
1149 {
1150         LASSERT(dt);
1151         LASSERT(dt->do_ops);
1152         LASSERT(dt->do_ops->do_ref_del);
1153         return dt->do_ops->do_capa_get(env, dt, old, opc);
1154 }
1155
1156 static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
1157                               struct niobuf_remote *rnb,
1158                               struct niobuf_local *lnb, int rw,
1159                               struct lustre_capa *capa)
1160 {
1161         LASSERT(d);
1162         LASSERT(d->do_body_ops);
1163         LASSERT(d->do_body_ops->dbo_bufs_get);
1164         return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
1165                                             rnb->len, lnb, rw, capa);
1166 }
1167
1168 static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
1169                               struct niobuf_local *lnb, int n)
1170 {
1171         LASSERT(d);
1172         LASSERT(d->do_body_ops);
1173         LASSERT(d->do_body_ops->dbo_bufs_put);
1174         return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
1175 }
1176
1177 static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
1178                                 struct niobuf_local *lnb, int n)
1179 {
1180         LASSERT(d);
1181         LASSERT(d->do_body_ops);
1182         LASSERT(d->do_body_ops->dbo_write_prep);
1183         return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
1184 }
1185
1186 static inline int dt_declare_write_commit(const struct lu_env *env,
1187                                           struct dt_object *d,
1188                                           struct niobuf_local *lnb,
1189                                           int n, struct thandle *th)
1190 {
1191         LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
1192         LASSERT(th != NULL);
1193         return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
1194 }
1195
1196
1197 static inline int dt_write_commit(const struct lu_env *env,
1198                                   struct dt_object *d, struct niobuf_local *lnb,
1199                                   int n, struct thandle *th)
1200 {
1201         LASSERT(d);
1202         LASSERT(d->do_body_ops);
1203         LASSERT(d->do_body_ops->dbo_write_commit);
1204         return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
1205 }
1206
1207 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
1208                                struct niobuf_local *lnb, int n)
1209 {
1210         LASSERT(d);
1211         LASSERT(d->do_body_ops);
1212         LASSERT(d->do_body_ops->dbo_read_prep);
1213         return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
1214 }
1215
1216 static inline int dt_declare_punch(const struct lu_env *env,
1217                                    struct dt_object *dt, __u64 start,
1218                                    __u64 end, struct thandle *th)
1219 {
1220         LASSERT(dt);
1221         LASSERT(dt->do_body_ops);
1222         LASSERT(dt->do_body_ops->do_declare_punch);
1223         return dt->do_body_ops->do_declare_punch(env, dt, start, end, th);
1224 }
1225
1226 static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
1227                            __u64 start, __u64 end, struct thandle *th,
1228                            struct lustre_capa *capa)
1229 {
1230         LASSERT(dt);
1231         LASSERT(dt->do_body_ops);
1232         LASSERT(dt->do_body_ops->do_punch);
1233         return dt->do_body_ops->do_punch(env, dt, start, end, th, capa);
1234 }
1235
1236 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
1237                                 struct ll_user_fiemap *fm)
1238 {
1239         LASSERT(d);
1240         if (d->do_body_ops == NULL)
1241                 return -EPROTO;
1242         if (d->do_body_ops->dbo_fiemap_get == NULL)
1243                 return -EOPNOTSUPP;
1244         return d->do_body_ops->dbo_fiemap_get(env, d, fm);
1245 }
1246
1247 static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
1248                             struct obd_statfs *osfs)
1249 {
1250         LASSERT(dev);
1251         LASSERT(dev->dd_ops);
1252         LASSERT(dev->dd_ops->dt_statfs);
1253         return dev->dd_ops->dt_statfs(env, dev, osfs);
1254 }
1255
1256 static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
1257                               struct lu_fid *f)
1258 {
1259         LASSERT(dev);
1260         LASSERT(dev->dd_ops);
1261         LASSERT(dev->dd_ops->dt_root_get);
1262         return dev->dd_ops->dt_root_get(env, dev, f);
1263 }
1264
1265 static inline void dt_conf_get(const struct lu_env *env,
1266                                const struct dt_device *dev,
1267                                struct dt_device_param *param)
1268 {
1269         LASSERT(dev);
1270         LASSERT(dev->dd_ops);
1271         LASSERT(dev->dd_ops->dt_conf_get);
1272         return dev->dd_ops->dt_conf_get(env, dev, param);
1273 }
1274
1275 static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
1276 {
1277         LASSERT(dev);
1278         LASSERT(dev->dd_ops);
1279         LASSERT(dev->dd_ops->dt_sync);
1280         return dev->dd_ops->dt_sync(env, dev);
1281 }
1282
1283 static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
1284 {
1285         LASSERT(dev);
1286         LASSERT(dev->dd_ops);
1287         LASSERT(dev->dd_ops->dt_ro);
1288         return dev->dd_ops->dt_ro(env, dev);
1289 }
1290
1291 static inline int dt_declare_insert(const struct lu_env *env,
1292                                     struct dt_object *dt,
1293                                     const struct dt_rec *rec,
1294                                     const struct dt_key *key,
1295                                     struct thandle *th)
1296 {
1297         LASSERT(dt);
1298         LASSERT(dt->do_index_ops);
1299         LASSERT(dt->do_index_ops->dio_declare_insert);
1300         return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
1301 }
1302
1303 static inline int dt_insert(const struct lu_env *env,
1304                                     struct dt_object *dt,
1305                                     const struct dt_rec *rec,
1306                                     const struct dt_key *key,
1307                                     struct thandle *th,
1308                                     struct lustre_capa *capa,
1309                                     int noquota)
1310 {
1311         LASSERT(dt);
1312         LASSERT(dt->do_index_ops);
1313         LASSERT(dt->do_index_ops->dio_insert);
1314         return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
1315                                             capa, noquota);
1316 }
1317
1318 static inline int dt_declare_xattr_del(const struct lu_env *env,
1319                                        struct dt_object *dt,
1320                                        const char *name,
1321                                        struct thandle *th)
1322 {
1323         LASSERT(dt);
1324         LASSERT(dt->do_ops);
1325         LASSERT(dt->do_ops->do_declare_xattr_del);
1326         return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
1327 }
1328
1329 static inline int dt_xattr_del(const struct lu_env *env,
1330                                struct dt_object *dt, const char *name,
1331                                struct thandle *th,
1332                                struct lustre_capa *capa)
1333 {
1334         LASSERT(dt);
1335         LASSERT(dt->do_ops);
1336         LASSERT(dt->do_ops->do_xattr_del);
1337         return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
1338 }
1339
1340 static inline int dt_declare_xattr_set(const struct lu_env *env,
1341                                       struct dt_object *dt,
1342                                       const struct lu_buf *buf,
1343                                       const char *name, int fl,
1344                                       struct thandle *th)
1345 {
1346         LASSERT(dt);
1347         LASSERT(dt->do_ops);
1348         LASSERT(dt->do_ops->do_declare_xattr_set);
1349         return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
1350 }
1351
1352 static inline int dt_xattr_set(const struct lu_env *env,
1353                               struct dt_object *dt, const struct lu_buf *buf,
1354                               const char *name, int fl, struct thandle *th,
1355                               struct lustre_capa *capa)
1356 {
1357         LASSERT(dt);
1358         LASSERT(dt->do_ops);
1359         LASSERT(dt->do_ops->do_xattr_set);
1360         return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
1361 }
1362
1363 static inline int dt_xattr_get(const struct lu_env *env,
1364                               struct dt_object *dt, struct lu_buf *buf,
1365                               const char *name, struct lustre_capa *capa)
1366 {
1367         LASSERT(dt);
1368         LASSERT(dt->do_ops);
1369         LASSERT(dt->do_ops->do_xattr_get);
1370         return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
1371 }
1372
1373 static inline int dt_xattr_list(const struct lu_env *env,
1374                                struct dt_object *dt, struct lu_buf *buf,
1375                                struct lustre_capa *capa)
1376 {
1377         LASSERT(dt);
1378         LASSERT(dt->do_ops);
1379         LASSERT(dt->do_ops->do_xattr_list);
1380         return dt->do_ops->do_xattr_list(env, dt, buf, capa);
1381 }
1382
1383 static inline int dt_declare_delete(const struct lu_env *env,
1384                                     struct dt_object *dt,
1385                                     const struct dt_key *key,
1386                                     struct thandle *th)
1387 {
1388         LASSERT(dt);
1389         LASSERT(dt->do_index_ops);
1390         LASSERT(dt->do_index_ops->dio_declare_delete);
1391         return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
1392 }
1393
1394 static inline int dt_delete(const struct lu_env *env,
1395                             struct dt_object *dt,
1396                             const struct dt_key *key,
1397                             struct thandle *th,
1398                             struct lustre_capa *capa)
1399 {
1400         LASSERT(dt);
1401         LASSERT(dt->do_index_ops);
1402         LASSERT(dt->do_index_ops->dio_delete);
1403         return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
1404 }
1405
1406 static inline int dt_commit_async(const struct lu_env *env,
1407                                   struct dt_device *dev)
1408 {
1409         LASSERT(dev);
1410         LASSERT(dev->dd_ops);
1411         LASSERT(dev->dd_ops->dt_commit_async);
1412         return dev->dd_ops->dt_commit_async(env, dev);
1413 }
1414
1415 static inline int dt_init_capa_ctxt(const struct lu_env *env,
1416                                     struct dt_device *dev,
1417                                     int mode, unsigned long timeout,
1418                                     __u32 alg, struct lustre_capa_key *keys)
1419 {
1420         LASSERT(dev);
1421         LASSERT(dev->dd_ops);
1422         LASSERT(dev->dd_ops->dt_init_capa_ctxt);
1423         return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
1424                                               timeout, alg, keys);
1425 }
1426
1427 static inline int dt_lookup(const struct lu_env *env,
1428                             struct dt_object *dt,
1429                             struct dt_rec *rec,
1430                             const struct dt_key *key,
1431                             struct lustre_capa *capa)
1432 {
1433         int ret;
1434
1435         LASSERT(dt);
1436         LASSERT(dt->do_index_ops);
1437         LASSERT(dt->do_index_ops->dio_lookup);
1438
1439         ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
1440         if (ret > 0)
1441                 ret = 0;
1442         else if (ret == 0)
1443                 ret = -ENOENT;
1444         return ret;
1445 }
1446
1447 #define LU221_BAD_TIME (0x80000000U + 24 * 3600)
1448
1449 struct dt_find_hint {
1450         struct lu_fid        *dfh_fid;
1451         struct dt_device     *dfh_dt;
1452         struct dt_object     *dfh_o;
1453 };
1454
1455 struct dt_thread_info {
1456         char                     dti_buf[DT_MAX_PATH];
1457         struct dt_find_hint      dti_dfh;
1458         struct lu_attr           dti_attr;
1459         struct lu_fid            dti_fid;
1460         struct dt_object_format  dti_dof;
1461         struct lustre_mdt_attrs  dti_lma;
1462         struct lu_buf            dti_lb;
1463         loff_t                   dti_off;
1464 };
1465
1466 extern struct lu_context_key dt_key;
1467
1468 static inline struct dt_thread_info *dt_info(const struct lu_env *env)
1469 {
1470         struct dt_thread_info *dti;
1471
1472         dti = lu_context_key_get(&env->le_ctx, &dt_key);
1473         LASSERT(dti);
1474         return dti;
1475 }
1476
1477 #endif /* __LUSTRE_DT_OBJECT_H */