Whamcloud - gitweb
35d4ab30e42890d065248e4f95981b8b7f61cfb9
[fs/lustre-release.git] / lustre / lmv / lmv_internal.h
1 #ifndef _LMV_INTERNAL_H_
2 #define _LMV_INTERNAL_H_
3
4 #define LL_IT2STR(it)                                   \
5         ((it) ? ldlm_it2str((it)->it_op) : "0")
6
7 #define MEA_SIZE_LMV(lmv)                               \
8         ((lmv)->desc.ld_tgt_count *                     \
9          sizeof(struct ll_fid) + sizeof(struct mea))
10         
11 struct lmv_inode {
12         struct ll_fid      fid;            /* fid of dirobj */
13         unsigned long      size;
14         int                flags;
15 };
16
17 struct lmv_obj {
18         struct list_head   list;
19         struct semaphore   guard;
20         int                freeing;        /* object is freeing. */
21         atomic_t           count;
22         struct ll_fid      fid;            /* master fid of dir */
23         void               *update;        /* bitmap of status (uptodate) */
24         int                objcount;
25         struct lmv_inode   *objs;          /* array of dirobjs */
26         struct obd_device  *obd;           /* pointer to LMV itself */
27 };
28
29 static inline void
30 lmv_lock_obj(struct lmv_obj *obj)
31 {
32         LASSERT(obj);
33         down(&obj->guard);
34 }
35
36 static inline void
37 lmv_unlock_obj(struct lmv_obj *obj)
38 {
39         LASSERT(obj);
40         up(&obj->guard);
41 }
42
43 void lmv_add_obj(struct lmv_obj *obj);
44 void lmv_del_obj(struct lmv_obj *obj);
45
46 void lmv_put_obj(struct lmv_obj *obj);
47 void lmv_free_obj(struct lmv_obj *obj);
48
49 int lmv_setup_mgr(struct obd_device *obd);
50 void lmv_cleanup_mgr(struct obd_device *obd);
51 int lmv_check_connect(struct obd_device *obd);
52
53 struct lmv_obj *lmv_get_obj(struct lmv_obj *obj);
54
55 struct lmv_obj *lmv_grab_obj(struct obd_device *obd,
56                              struct ll_fid *fid);
57
58 struct lmv_obj *lmv_alloc_obj(struct obd_device *obd,
59                               struct ll_fid *fid,
60                               struct mea *mea);
61
62 struct lmv_obj *lmv_create_obj(struct obd_export *exp,
63                                struct ll_fid *fid,
64                                struct mea *mea);
65
66 int lmv_delete_obj(struct obd_export *exp, struct ll_fid *fid);
67
68 int lmv_intent_lock(struct obd_export *, struct ll_uctxt *,
69                     struct ll_fid *, const char *, int, void *, int,
70                     struct ll_fid *, struct lookup_intent *, int,
71                     struct ptlrpc_request **, ldlm_blocking_callback);
72
73 int lmv_intent_lookup(struct obd_export *, struct ll_uctxt *,
74                       struct ll_fid *, const char *, int, void *, int,
75                       struct ll_fid *, struct lookup_intent *, int,
76                       struct ptlrpc_request **, ldlm_blocking_callback);
77
78 int lmv_intent_getattr(struct obd_export *, struct ll_uctxt *,
79                        struct ll_fid *, const char *, int, void *, int,
80                        struct ll_fid *, struct lookup_intent *, int,
81                        struct ptlrpc_request **, ldlm_blocking_callback);
82
83 int lmv_intent_open(struct obd_export *, struct ll_uctxt *,
84                     struct ll_fid *, const char *, int, void *, int,
85                     struct ll_fid *, struct lookup_intent *, int,
86                     struct ptlrpc_request **, ldlm_blocking_callback);
87
88 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
89                           struct ll_fid *, struct lookup_intent *, int,
90                           ldlm_blocking_callback cb_blocking);
91
92 int lmv_get_mea_and_update_object(struct obd_export *, struct ll_fid *);
93 int lmv_dirobj_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
94                             void *, int);
95
96 static inline struct mea * 
97 body_of_splitted_dir(struct ptlrpc_request *req, int offset)
98 {
99         struct mds_body *body;
100         struct mea *mea;
101
102         LASSERT(req);
103
104         body = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*body));
105
106         if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
107                 return NULL;
108
109         mea = lustre_msg_buf(req->rq_repmsg,
110                              offset + 1, body->eadatasize);
111         LASSERT(mea);
112
113         if (mea->mea_count == 0)
114                 return NULL;
115         
116         return mea;
117 }
118
119 static inline int
120 fid_equal(struct ll_fid *fid1, struct ll_fid *fid2)
121 {
122         if (fid1->mds != fid2->mds)
123                 return 0;
124         if (fid1->id != fid2->id)
125                 return 0;
126         if (fid1->generation != fid2->generation)
127                 return 0;
128         return 1;
129 }
130
131 #endif
132