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