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