Whamcloud - gitweb
37601a41c110351147231e915c899d04e3269859
[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 <lustre_disk.h>
9 #include <lustre_mds.h>
10
11 #define MDT_ROCOMPAT_SUPP       (OBD_ROCOMPAT_LOVOBJID)
12 #define MDT_INCOMPAT_SUPP       (OBD_INCOMPAT_MDT | OBD_INCOMPAT_COMMON_LR)
13
14 /* Data stored per client in the last_rcvd file.  In le32 order. */
15 struct mds_client_data {
16         __u8 mcd_uuid[40];      /* client UUID */
17         __u64 mcd_last_transno; /* last completed transaction ID */
18         __u64 mcd_last_xid;     /* xid for the last transaction */
19         __u32 mcd_last_result;  /* result from last RPC */
20         __u32 mcd_last_data;    /* per-op data (disposition for open &c.) */
21         /* for MDS_CLOSE requests */
22         __u64 mcd_last_close_transno; /* last completed transaction ID */
23         __u64 mcd_last_close_xid;     /* xid for the last transaction */
24         __u32 mcd_last_close_result;  /* result from last RPC */
25         __u32 mcd_last_close_data;  /* per-op data (disposition for open &c.) */
26         __u8 mcd_padding[LR_CLIENT_SIZE - 88];
27 };
28
29 #define MDS_SERVICE_WATCHDOG_TIMEOUT (obd_timeout * 1000)
30
31 #define MAX_ATIME_DIFF 60
32
33 struct mds_filter_data {
34         __u64 io_epoch;
35 };
36
37 #define MDS_FILTERDATA(inode) ((struct mds_filter_data *)(inode)->i_filterdata)
38
39 static inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req)
40 {
41         return &req->rq_export->exp_obd->u.mds;
42 }
43
44 #ifdef __KERNEL__
45 /* Open counts for files.  No longer atomic, must hold inode->i_sem */
46 # define mds_inode_oatomic(inode)    ((inode)->i_cindex)
47
48 #ifdef HAVE_I_ALLOC_SEM
49 #define MDS_UP_READ_ORPHAN_SEM(i)          UP_READ_I_ALLOC_SEM(i)
50 #define MDS_DOWN_READ_ORPHAN_SEM(i)        DOWN_READ_I_ALLOC_SEM(i)
51 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i)  LASSERT_I_ALLOC_SEM_READ_LOCKED(i)
52
53 #define MDS_UP_WRITE_ORPHAN_SEM(i)         UP_WRITE_I_ALLOC_SEM(i)
54 #define MDS_DOWN_WRITE_ORPHAN_SEM(i)       DOWN_WRITE_I_ALLOC_SEM(i)
55 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i)
56 #define MDS_PACK_MD_LOCK 1
57 #else
58 #define MDS_UP_READ_ORPHAN_SEM(i)          do { up(&(i)->i_sem); } while (0)
59 #define MDS_DOWN_READ_ORPHAN_SEM(i)        do { down(&(i)->i_sem); } while (0)
60 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i)  LASSERT(down_trylock(&(i)->i_sem)!=0)
61
62 #define MDS_UP_WRITE_ORPHAN_SEM(i)         do { up(&(i)->i_sem); } while (0)
63 #define MDS_DOWN_WRITE_ORPHAN_SEM(i)       do { down(&(i)->i_sem); } while (0)
64 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem)!=0)
65 #define MDS_PACK_MD_LOCK 0
66 #endif
67
68 static inline int mds_orphan_open_count(struct inode *inode)
69 {
70         LASSERT_MDS_ORPHAN_READ_LOCKED(inode);
71         return mds_inode_oatomic(inode);
72 }
73
74 static inline int mds_orphan_open_inc(struct inode *inode)
75 {
76         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
77         return ++mds_inode_oatomic(inode);
78 }
79
80 static inline int mds_orphan_open_dec_test(struct inode *inode)
81 {
82         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
83         return --mds_inode_oatomic(inode) == 0;
84 }
85
86 #define mds_inode_is_orphan(inode)  ((inode)->i_flags & 0x4000000)
87
88 static inline void mds_inode_set_orphan(struct inode *inode)
89 {
90         inode->i_flags |= 0x4000000;
91         CDEBUG(D_VFSTRACE, "setting orphan flag on inode %p\n", inode);
92 }
93
94 static inline void mds_inode_unset_orphan(struct inode *inode)
95 {
96         inode->i_flags &= ~(0x4000000);
97         CDEBUG(D_VFSTRACE, "removing orphan flag from inode %p\n", inode);
98 }
99
100 #endif /* __KERNEL__ */
101
102 #define MDS_CHECK_RESENT(req, reconstruct)                                    \
103 {                                                                             \
104         if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {              \
105                 struct mds_client_data *mcd =                                 \
106                         req->rq_export->exp_mds_data.med_mcd;                 \
107                 if (le64_to_cpu(mcd->mcd_last_xid) == req->rq_xid) {          \
108                         reconstruct;                                          \
109                         RETURN(le32_to_cpu(mcd->mcd_last_result));            \
110                 }                                                             \
111                 if (le64_to_cpu(mcd->mcd_last_close_xid) == req->rq_xid) {    \
112                         reconstruct;                                          \
113                         RETURN(le32_to_cpu(mcd->mcd_last_close_result));      \
114                 }                                                             \
115                 DEBUG_REQ(D_HA, req, "no reply for RESENT req (have "LPD64")",\
116                           mcd->mcd_last_xid);                                 \
117         }                                                                     \
118 }
119
120 /* mds/mds_reint.c */
121 int res_gt(const struct ldlm_res_id *res1, const struct ldlm_res_id *res2,
122            ldlm_policy_data_t *p1, ldlm_policy_data_t *p2);
123 int enqueue_ordered_locks(struct obd_device *obd,
124                           const struct ldlm_res_id *p1_res_id,
125                           struct lustre_handle *p1_lockh, int p1_lock_mode,
126                           ldlm_policy_data_t *p1_policy,
127                           const struct ldlm_res_id *p2_res_id,
128                           struct lustre_handle *p2_lockh, int p2_lock_mode,
129                           ldlm_policy_data_t *p2_policy);
130 void mds_commit_cb(struct obd_device *, __u64 last_rcvd, void *data, int error);
131 int mds_finish_transno(struct mds_obd *mds, struct inode *inode, void *handle,
132                        struct ptlrpc_request *req, int rc, __u32 op_data,
133                        int force_sync);
134 void mds_reconstruct_generic(struct ptlrpc_request *req);
135 void mds_req_from_mcd(struct ptlrpc_request *req, struct mds_client_data *mcd);
136 int mds_get_parent_child_locked(struct obd_device *obd, struct mds_obd *mds,
137                                 struct ll_fid *fid,
138                                 struct lustre_handle *parent_lockh,
139                                 struct dentry **dparentp, int parent_mode,
140                                 __u64 parent_lockpart,
141                                 char *name, int namelen,
142                                 struct lustre_handle *child_lockh,
143                                 struct dentry **dchildp, int child_mode,
144                                 __u64 child_lockpart);
145 int mds_lock_new_child(struct obd_device *obd, struct inode *inode,
146                        struct lustre_handle *child_lockh);
147
148 int mds_get_parents_children_locked(struct obd_device *obd,
149                                     struct mds_obd *mds,
150                                     struct ll_fid *p1_fid,
151                                     struct dentry **de_srcdirp,
152                                     struct ll_fid *p2_fid,
153                                     struct dentry **de_tgtdirp,
154                                     int parent_mode,
155                                     const char *old_name, int old_len,
156                                     struct dentry **de_oldp,
157                                     const char *new_name, int new_len,
158                                     struct dentry **de_newp,
159                                     struct lustre_handle *dlm_handles,
160                                     int child_mode);
161
162 void mds_shrink_reply(struct obd_device *obd, struct ptlrpc_request *req,
163                       struct mds_body *body, int md_off);
164 int mds_get_cookie_size(struct obd_device *obd, struct lov_mds_md *lmm);
165 /* mds/mds_lib.c */
166 int mds_update_unpack(struct ptlrpc_request *, int offset,
167                       struct mds_update_record *);
168 int mds_init_ucred(struct lvfs_ucred *ucred, struct ptlrpc_request *req,
169                    int offset);
170 void mds_exit_ucred(struct lvfs_ucred *ucred, struct mds_obd *obd);
171
172 /* mds/mds_unlink_open.c */
173 int mds_osc_destroy_orphan(struct obd_device *obd, umode_t mode,
174                            struct lov_mds_md *lmm, int lmm_size,
175                            struct llog_cookie *logcookies, int log_unlink);
176 int mds_cleanup_pending(struct obd_device *obd);
177
178
179 /* mds/mds_log.c */
180 int mds_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
181                   struct obd_device *tgt, int count,
182                   struct llog_catid *logid, struct obd_uuid *uuid);
183 int mds_llog_finish(struct obd_device *obd, int count);
184
185 /* mds/mds_lov.c */
186 int mds_lov_connect(struct obd_device *obd, char * lov_name);
187 int mds_lov_disconnect(struct obd_device *obd);
188 int mds_lov_write_objids(struct obd_device *obd);
189
190 int mds_lov_clear_orphans(struct mds_obd *mds, struct obd_uuid *ost_uuid);
191 void mds_lov_update_objids(struct obd_device *obd, struct lov_mds_md *lmm);
192 int mds_lov_set_nextid(struct obd_device *obd);
193
194 int mds_lov_start_synchronize(struct obd_device *obd,
195                               struct obd_device *watched,
196                               void *data, int nonblock);
197 int mds_post_mds_lovconf(struct obd_device *obd);
198 int mds_notify(struct obd_device *obd, struct obd_device *watched,
199                enum obd_notify_event ev, void *data);
200 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
201                        struct lov_mds_md *lmm, int lmm_size);
202 int mds_init_lov_desc(struct obd_device *obd, struct obd_export *osc_exp);
203
204 /* mds/mds_open.c */
205 int mds_query_write_access(struct inode *inode);
206 int mds_open(struct mds_update_record *rec, int offset,
207              struct ptlrpc_request *req, struct lustre_handle *);
208 int mds_pin(struct ptlrpc_request *req, int offset);
209 void mds_mfd_unlink(struct mds_file_data *mfd, int decref);
210 int mds_mfd_close(struct ptlrpc_request *req, int offset,struct obd_device *obd,
211                   struct mds_file_data *mfd, int unlink_orphan,
212                   struct lov_mds_md *lmm, int lmm_size,
213                   struct llog_cookie *logcookies, int cookies_size,
214                   __u64 *valid);
215 int mds_close(struct ptlrpc_request *req, int offset);
216 int mds_done_writing(struct ptlrpc_request *req, int offset);
217
218 /*mds/mds_join.c*/
219 int mds_join_file(struct mds_update_record *rec, struct ptlrpc_request *req,
220                   struct dentry *dchild, struct lustre_handle *lockh);
221
222 /* mds/mds_fs.c */
223 int mds_client_add(struct obd_device *obd, struct obd_export *exp, int cl_off);
224 int mds_client_free(struct obd_export *exp);
225 int mds_obd_create(struct obd_export *exp, struct obdo *oa,
226                    struct lov_stripe_md **ea, struct obd_trans_info *oti);
227 int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
228                     struct lov_stripe_md *ea, struct obd_trans_info *oti,
229                     struct obd_export *md_exp);
230 void mds_init_ctxt(struct obd_device *obd, struct vfsmount *mnt);
231
232 /* mds/handler.c */
233 extern struct lvfs_callback_ops mds_lvfs_ops;
234 extern int mds_iocontrol(unsigned int cmd, struct obd_export *exp,
235                          int len, void *karg, void *uarg);
236 int mds_postrecov(struct obd_device *obd);
237 int mds_init_export(struct obd_export *exp);
238 #ifdef __KERNEL__
239 int mds_get_md(struct obd_device *, struct inode *, void *md, int *size,
240                int lock);
241 int mds_pack_md(struct obd_device *, struct lustre_msg *, int offset,
242                 struct mds_body *, struct inode *, int lock);
243 void mds_pack_inode2fid(struct ll_fid *fid, struct inode *inode);
244 void mds_pack_inode2body(struct mds_body *body, struct inode *inode);
245 #endif
246 int mds_pack_acl(struct mds_export_data *med, struct inode *inode,
247                  struct lustre_msg *repmsg, struct mds_body *repbody,
248                  int repoff);
249
250 /* quota stuff */
251 extern quota_interface_t *mds_quota_interface_ref;
252
253 /* mds/mds_xattr.c */
254 int mds_setxattr(struct ptlrpc_request *req);
255 int mds_getxattr(struct ptlrpc_request *req);
256
257 /* mds/lproc_mds.c */
258 enum {
259         LPROC_MDS_OPEN = 0,
260         LPROC_MDS_CLOSE,
261         LPROC_MDS_MKNOD,
262         LPROC_MDS_LINK,
263         LPROC_MDS_UNLINK,
264         LPROC_MDS_MKDIR,
265         LPROC_MDS_RMDIR,
266         LPROC_MDS_RENAME,
267         LPROC_MDS_GETXATTR,
268         LPROC_MDS_SETXATTR,
269         LPROC_MDS_LAST,
270 };
271 void mds_counter_incr(struct obd_export *exp, int opcode);
272 void mds_stats_counter_init(struct lprocfs_stats *stats);
273 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars);
274 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars);
275 #endif /* _MDS_INTERNAL_H */