Whamcloud - gitweb
79c01d796bb3102bfad866c8f676d66c7ab267ce
[fs/lustre-release.git] / lustre / mds / mds_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4
5 #ifndef _MDS_INTERNAL_H
6 #define _MDS_INTERNAL_H
7
8 #include <linux/lustre_mds.h>
9
10 #define MDS_SERVICE_WATCHDOG_TIMEOUT 30000
11
12 #define MAX_ATIME_DIFF 60
13
14 struct mds_filter_data {
15         __u64 io_epoch;
16 };
17
18 #define MDS_FILTERDATA(inode) ((struct mds_filter_data *)LUSTRE_FILTERDATA(inode))
19 #define DENTRY_VALID(dentry)    \
20         ((dentry)->d_inode || ((dentry)->d_flags & DCACHE_CROSS_REF))
21
22 #define MDS_NO_SPLIT_EXPECTED   0
23 #define MDS_EXPECT_SPLIT        1
24 #define MDS_NO_SPLITTABLE       2
25
26 static inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req)
27 {
28         return &req->rq_export->exp_obd->u.mds;
29 }
30 static inline struct obd_device *req2obd(struct ptlrpc_request *req)
31 {
32         return req->rq_export->exp_obd;
33 }
34
35 #ifdef __KERNEL__
36 /* Open counts for files.  No longer atomic, must hold inode->i_sem */
37 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
38 # define mds_inode_oatomic(inode)    ((inode)->i_cindex)
39 #else
40 # define mds_inode_oatomic(inode)    ((inode)->i_attr_flags)
41 #endif
42
43 static inline int mds_orphan_open_count(struct inode *inode)
44 {
45         LASSERT_MDS_ORPHAN_READ_LOCKED(inode);
46         return mds_inode_oatomic(inode);
47 }
48
49 static inline int mds_orphan_open_inc(struct inode *inode)
50 {
51         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
52         return ++mds_inode_oatomic(inode);
53 }
54
55 static inline int mds_orphan_open_dec_test(struct inode *inode)
56 {
57         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
58         return --mds_inode_oatomic(inode) == 0;
59 }
60
61 #define mds_inode_is_orphan(inode)  ((inode)->i_flags & 0x4000000)
62 #define mds_inode_set_orphan(inode)                                     \
63 do {                                                                    \
64         (inode)->i_flags |= 0x4000000;                                  \
65         CDEBUG(D_VFSTRACE, "setting orphan flag on inode %p\n", inode); \
66 } while (0)
67 #define mds_inode_unset_orphan(inode)                                      \
68 do {                                                                       \
69         (inode)->i_flags &= ~(0x4000000);                                  \
70         CDEBUG(D_VFSTRACE, "removing orphan flag from inode %p\n", inode); \
71 } while (0)
72
73
74 /* inode flags managed by mds directly */
75 #define MDS_IF_ATTRS_OLD        0x8000000       /* inode needs attrs. refreshing */
76
77 #define mds_inode_has_old_attrs(inode)  ((inode)->i_flags & MDS_IF_ATTRS_OLD)
78 #define mds_inode_set_attrs_old(inode)                                   \
79 do {                                                                     \
80         (inode)->i_flags |= MDS_IF_ATTRS_OLD;                            \
81         CDEBUG(D_VFSTRACE, "setting attr.old flag on inode %p\n", inode);\
82 } while (0)
83 #define mds_inode_unset_attrs_old(inode)                                     \
84 do {                                                                         \
85         (inode)->i_flags &= ~(MDS_IF_ATTRS_OLD);                             \
86         CDEBUG(D_VFSTRACE, "removing attrs.old flag from inode %p\n", inode);\
87 } while (0)
88
89
90 #endif /* __KERNEL__ */
91
92 /* mds/mds_reint.c */
93 int enqueue_ordered_locks(struct obd_device *obd, struct ldlm_res_id *p1_res_id,
94                           struct lustre_handle *p1_lockh, int p1_lock_mode,
95                           ldlm_policy_data_t *p1_policy,
96                           struct ldlm_res_id *p2_res_id,
97                           struct lustre_handle *p2_lockh, int p2_lock_mode,
98                           ldlm_policy_data_t *p2_policy);
99
100 int mds_finish_transno(struct mds_obd *mds, struct inode *inode, void *handle,
101                        struct ptlrpc_request *req, int rc, __u32 op_data);
102 void mds_reconstruct_generic(struct ptlrpc_request *req);
103 void mds_req_from_mcd(struct ptlrpc_request *req, struct mds_client_data *mcd);
104 int mds_get_parent_child_locked(struct obd_device *obd, struct mds_obd *mds,
105                                 struct lustre_id *id,
106                                 struct lustre_handle *parent_lockh,
107                                 struct dentry **dparentp, int parent_mode,
108                                 __u64 parent_lockpart, int *update_mode,
109                                 char *name, int namelen,
110                                 struct lustre_handle *child_lockh,
111                                 struct dentry **dchildp, int child_mode,
112                                 __u64 child_lockpart);
113 int mds_lock_new_child(struct obd_device *obd, struct inode *inode,
114                        struct lustre_handle *child_lockh);
115
116 /* mds/mds_lib.c */
117 void groups_from_buffer(struct group_info *ginfo, __u32 *gids);
118 int mds_update_unpack(struct ptlrpc_request *, int offset,
119                       struct mds_update_record *);
120 int mds_idmap_add(struct mds_idmap_table *tbl,
121                   uid_t rmt_uid, uid_t lcl_uid,
122                   gid_t rmt_gid, gid_t lcl_gid);
123 int mds_idmap_del(struct mds_idmap_table *tbl,
124                   uid_t rmt_uid, uid_t lcl_uid,
125                   gid_t rmt_gid, gid_t lcl_gid);
126 int mds_idmap_lookup_uid(struct mds_idmap_table *tbl, int reverse, uid_t uid);
127 int mds_idmap_lookup_gid(struct mds_idmap_table *tbl, int reverse, gid_t gid);
128 struct mds_idmap_table *mds_idmap_alloc(void);
129 void mds_idmap_free(struct mds_idmap_table *tbl);
130 void mds_body_do_reverse_map(struct mds_export_data *med,
131                              struct mds_body *body);
132 int mds_init_ucred(struct lvfs_ucred *ucred, struct ptlrpc_request *req,
133                    struct mds_req_sec_desc *rsd);
134 void mds_exit_ucred(struct lvfs_ucred *ucred);
135
136 int mds_set_gskey(struct obd_device *obd, void *handle, 
137                   struct inode *inode, void *key, int key_len, int valid); 
138 int mds_set_crypto_type(struct obd_device *obd, void *val, __u32 vallen);
139
140 int mds_pack_gskey(struct obd_device *obd, struct lustre_msg *repmsg, 
141                    int *offset, struct mds_body *body, struct inode *inode);
142 /* mds/mds_unlink_open.c */
143 int mds_cleanup_orphans(struct obd_device *obd);
144
145 int mds_unlink_object(struct mds_obd *mds, struct inode *inode,
146                       struct lov_mds_md *lmm, int lmm_size,
147                       struct llog_cookie *logcookies,
148                       int log_unlink, int async);
149         
150
151 /* mds/mds_log.c */
152 int mds_log_op_unlink(struct obd_device *obd, struct inode *inode,
153                       struct lov_mds_md *lmm, int lmm_size,
154                       struct llog_cookie *logcookies, int cookies_size,
155                       struct llog_create_locks **res);
156 int mds_llog_init(struct obd_device *obd, struct obd_llogs *,
157                   struct obd_device *tgt, int count, struct llog_catid *logid);
158 int mds_llog_finish(struct obd_device *obd, struct obd_llogs *, int count);
159
160 /* mds/mds_lov.c */
161 int mds_dt_connect(struct obd_device *obd, char * lov_name);
162 int mds_dt_disconnect(struct obd_device *obd, int flags);
163 int mds_dt_set_info(struct obd_export *exp, obd_count keylen,
164                      void *key, obd_count vallen, void *val);
165 int mds_get_lovtgts(struct obd_device *, int tgt_count, struct obd_uuid *);
166 int mds_dt_write_objids(struct obd_device *obd);
167 int mds_dt_set_growth(struct mds_obd *mds, int count);
168 int mds_dt_clear_orphans(struct mds_obd *mds, struct obd_uuid *ost_uuid);
169 int mds_post_mds_lovconf(struct obd_device *obd);
170 int mds_notify(struct obd_device *obd, struct obd_device *watched,
171                int active, void *data);
172 int mds_dt_update_config(struct obd_device *obd, int transno);
173 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
174                        struct lov_mds_md *lmm, int lmm_size);
175 int mds_revalidate_lov_ea(struct obd_device *obd, struct inode *inode,
176                           struct lustre_msg *msg, int offset);
177 void mds_dt_update_objids(struct obd_device *obd, obd_id *ids);
178 void mds_dt_save_objids(struct obd_device *obd, obd_id *ids);
179
180 /* mds/mds_open.c */
181 int
182 mds_create_object(struct obd_device *obd, struct ptlrpc_request *req,
183                   int offset, struct mds_update_record *rec,
184                   struct dentry *dchild, void **handle,
185                   obd_id *ids);
186 int mds_destroy_object(struct obd_device *obd,
187                        struct inode *inode, int async);
188 int mds_query_write_access(struct inode *inode);
189 int mds_open(struct mds_update_record *rec, int offset,
190              struct ptlrpc_request *req, struct lustre_handle *);
191 int mds_pin(struct ptlrpc_request *req, int offset);
192 int mds_mfd_close(struct ptlrpc_request *req, int offset,
193                   struct obd_device *obd, struct mds_file_data *mfd,
194                   int unlink_orphan);
195 int mds_close(struct ptlrpc_request *req, int offset);
196 int mds_done_writing(struct ptlrpc_request *req, int offset);
197 int mds_validate_size(struct obd_device *obd, struct inode *inode,
198                       struct mds_body *body, struct iattr *iattr);
199
200 /* mds/mds_fs.c */
201 int mds_client_add(struct obd_device *obd, struct mds_obd *mds,
202                    struct mds_export_data *med, int cl_off);
203 int mds_client_free(struct obd_export *exp, int clear_client);
204 int mds_obd_create(struct obd_export *exp, struct obdo *oa,
205                    void *acl, int acl_size,
206                    struct lov_stripe_md **ea, struct obd_trans_info *oti);
207 int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
208                     struct lov_stripe_md *ea, struct obd_trans_info *oti);
209
210 /* mds/handler.c */
211 int mds_getattr_size(struct obd_device *obd, struct dentry *dentry,
212                      struct ptlrpc_request *req, struct mds_body *body);
213 int mds_handle(struct ptlrpc_request *req);
214 extern struct lvfs_callback_ops mds_lvfs_ops;
215 int mds_dt_clean(struct obd_device *obd);
216 int mds_postrecov(struct obd_device *obd);
217 int mds_postrecov_common(struct obd_device *obd);
218 extern struct lvfs_callback_ops mds_lvfs_ops;
219
220 extern int mds_iocontrol(unsigned int cmd,
221                          struct obd_export *exp,
222                          int len, void *karg,
223                          void *uarg);
224
225 extern int mds_lock_mode_for_dir(struct obd_device *,
226                                  struct dentry *, int);
227
228 int mds_fs_setup_rootid(struct obd_device *obd);
229 int mds_fs_setup_virtid(struct obd_device *obd);
230
231 __u64 mds_alloc_fid(struct obd_device *obd);
232
233 int mds_set_inode_sid(struct obd_device *, struct inode *,
234                       void *, struct lustre_id *, __u64 fid);
235
236 int mds_update_inode_sid(struct obd_device *, struct inode *,
237                          void *, struct lustre_id *);
238
239 int mds_read_inode_sid(struct obd_device *, struct inode *,
240                        struct lustre_id *);
241
242 int mds_update_inode_mid(struct obd_device *, struct inode *,
243                          void *, struct lustre_id *);
244
245 int mds_read_inode_mid(struct obd_device *, struct inode *,
246                        struct lustre_id *);
247
248 void mds_commit_last_fid_cb(struct obd_device *, __u64 fid,
249                             void *data, int error);
250
251 void mds_commit_last_transno_cb(struct obd_device *, __u64 transno,
252                                 void *data, int error);
253
254 void mds_set_last_fid(struct obd_device *obd, __u64 fid);
255
256 #ifdef __KERNEL__
257 int mds_get_md(struct obd_device *, struct inode *, void *md,
258                int *size, int lock, int mea);
259
260 int mds_pack_md(struct obd_device *, struct lustre_msg *, int offset,
261                 struct mds_body *, struct inode *, int lock, int mea);
262 int mds_pack_link(struct dentry *dentry, struct ptlrpc_request *req,
263                   struct mds_body *repbody, int reply_off);
264 int mds_pack_xattr(struct dentry *dentry, struct ptlrpc_request *req,
265                    struct mds_body *repbody, int req_off, int reply_off);
266 int mds_pack_xattr_list(struct dentry *dentry, struct ptlrpc_request *req,
267                         struct mds_body *repbody, int reply_off);
268 int mds_pack_acl(struct ptlrpc_request *req, int *reply_off,
269                  struct mds_body *body, struct inode *inode);
270
271 int mds_pack_inode2id(struct obd_device *, struct lustre_id *,
272                       struct inode *, int);
273
274 void mds_pack_inode2body(struct obd_device *, struct mds_body *,
275                          struct inode *, int);
276
277 void mds_pack_dentry2id(struct obd_device *, struct lustre_id *,
278                         struct dentry *, int);
279
280 void mds_pack_dentry2body(struct obd_device *, struct mds_body *b,
281                           struct dentry *, int);
282
283 #endif
284
285 /* mds/mds_lmv.c */
286 int mds_md_postsetup(struct obd_device *obd);
287 int mds_md_connect(struct obd_device *obd, char * lov_name);
288 int mds_md_disconnect(struct obd_device *obd, int flags);
289 int mds_try_to_split_dir(struct obd_device *, struct dentry *, struct mea **,
290                          int, int);
291 int mds_md_get_attr(struct obd_device *, struct inode *, struct mea **, int *);
292 int mds_choose_mdsnum(struct obd_device *, const char *, int, int, struct ptlrpc_peer *, struct inode *);
293 int mds_md_postsetup(struct obd_device *);
294 int mds_splitting_expected(struct obd_device *, struct dentry *);
295 int mds_lock_slave_objs(struct obd_device *, struct dentry *,
296                         struct lustre_handle **);
297 int mds_unlink_slave_objs(struct obd_device *, struct dentry *);
298 void mds_unlock_slave_objs(struct obd_device *, struct dentry *,
299                            struct lustre_handle *);
300 int mds_lock_and_check_slave(int, struct ptlrpc_request *, struct lustre_handle *);
301 int mds_convert_mea_ea(struct obd_device *, struct inode *, struct lov_mds_md *, int);
302 int mds_is_dir_empty(struct obd_device *, struct dentry *);
303 int mds_md_reconnect(struct obd_device *obd);
304
305 /* mds_lsd.c */
306 struct upcall_cache *__mds_get_global_lsd_cache(void);
307 int mds_init_lsd_cache(void);
308 void mds_cleanup_lsd_cache(void);
309 struct lustre_sec_desc * mds_get_lsd(__u32 uid);
310 void mds_put_lsd(struct lustre_sec_desc *lsd);
311 void mds_flush_lsd(__u32 id);
312
313 /* mds_acl.c */
314 struct upcall_cache *__mds_get_global_rmtacl_upcall_cache(void);
315 int mds_init_rmtacl_upcall_cache(void);
316 void mds_cleanup_rmtacl_upcall_cache(void);
317 void mds_do_remote_acl_upcall(struct rmtacl_upcall_desc *desc);
318
319 #endif /* _MDS_INTERNAL_H */