Whamcloud - gitweb
file lc_modprobe.sh.in was added on branch b_new_cmd on 2006-08-19 03:08:14 +0000
[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         __u8 mcd_padding[LR_CLIENT_SIZE - 64];
22 };
23
24 #define MDS_SERVICE_WATCHDOG_TIMEOUT (obd_timeout * 1000)
25
26 #define MAX_ATIME_DIFF 60
27
28 struct mds_filter_data {
29         __u64 io_epoch;
30 };
31
32 #define MDS_FILTERDATA(inode) ((struct mds_filter_data *)(inode)->i_filterdata)
33
34 static inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req)
35 {
36         return &req->rq_export->exp_obd->u.mds;
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 #ifdef HAVE_I_ALLOC_SEM
48 #define MDS_UP_READ_ORPHAN_SEM(i)          UP_READ_I_ALLOC_SEM(i)
49 #define MDS_DOWN_READ_ORPHAN_SEM(i)        DOWN_READ_I_ALLOC_SEM(i)
50 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i)  LASSERT_I_ALLOC_SEM_READ_LOCKED(i)
51
52 #define MDS_UP_WRITE_ORPHAN_SEM(i)         UP_WRITE_I_ALLOC_SEM(i)
53 #define MDS_DOWN_WRITE_ORPHAN_SEM(i)       DOWN_WRITE_I_ALLOC_SEM(i)
54 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i)
55 #define MDS_PACK_MD_LOCK 1
56 #else
57 #define MDS_UP_READ_ORPHAN_SEM(i)          do { up(&(i)->i_sem); } while (0)
58 #define MDS_DOWN_READ_ORPHAN_SEM(i)        do { down(&(i)->i_sem); } while (0)
59 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i)  LASSERT(down_trylock(&(i)->i_sem)!=0)
60
61 #define MDS_UP_WRITE_ORPHAN_SEM(i)         do { up(&(i)->i_sem); } while (0)
62 #define MDS_DOWN_WRITE_ORPHAN_SEM(i)       do { down(&(i)->i_sem); } while (0)
63 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem)!=0)
64 #define MDS_PACK_MD_LOCK 0
65 #endif
66
67 static inline int mds_orphan_open_count(struct inode *inode)
68 {
69         LASSERT_MDS_ORPHAN_READ_LOCKED(inode);
70         return mds_inode_oatomic(inode);
71 }
72
73 static inline int mds_orphan_open_inc(struct inode *inode)
74 {
75         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
76         return ++mds_inode_oatomic(inode);
77 }
78
79 static inline int mds_orphan_open_dec_test(struct inode *inode)
80 {
81         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
82         return --mds_inode_oatomic(inode) == 0;
83 }
84
85 #define mds_inode_is_orphan(inode)  ((inode)->i_flags & 0x4000000)
86
87 static inline void mds_inode_set_orphan(struct inode *inode)
88 {
89         inode->i_flags |= 0x4000000;
90         CDEBUG(D_VFSTRACE, "setting orphan flag on inode %p\n", inode);
91 }
92
93 static inline void mds_inode_unset_orphan(struct inode *inode)
94 {
95         inode->i_flags &= ~(0x4000000);
96         CDEBUG(D_VFSTRACE, "removing orphan flag from inode %p\n", inode);
97 }
98
99 #endif /* __KERNEL__ */
100
101 #define MDS_CHECK_RESENT(req, reconstruct)                                    \
102 {                                                                             \
103         if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {              \
104                 struct mds_client_data *mcd =                                 \
105                         req->rq_export->exp_mds_data.med_mcd;                 \
106                 if (mcd->mcd_last_xid == req->rq_xid) {                       \
107                         reconstruct;                                          \
108                         RETURN(req->rq_repmsg->status);                       \
109                 }                                                             \
110                 DEBUG_REQ(D_HA, req, "no reply for RESENT req (have "LPD64")",\
111                           mcd->mcd_last_xid);                                 \
112         }                                                                     \
113 }
114
115 /* mds/mds_reint.c */
116 int res_gt(struct ldlm_res_id *res1, struct ldlm_res_id *res2,
117            ldlm_policy_data_t *p1, ldlm_policy_data_t *p2);
118 int enqueue_ordered_locks(struct obd_device *obd, struct ldlm_res_id *p1_res_id,
119                           struct lustre_handle *p1_lockh, int p1_lock_mode,
120                           ldlm_policy_data_t *p1_policy,
121                           struct ldlm_res_id *p2_res_id,
122                           struct lustre_handle *p2_lockh, int p2_lock_mode,
123                           ldlm_policy_data_t *p2_policy);
124 void mds_commit_cb(struct obd_device *, __u64 last_rcvd, void *data, int error);
125 int mds_finish_transno(struct mds_obd *mds, struct inode *inode, void *handle,
126                        struct ptlrpc_request *req, int rc, __u32 op_data);
127 void mds_reconstruct_generic(struct ptlrpc_request *req);
128 void mds_req_from_mcd(struct ptlrpc_request *req, struct mds_client_data *mcd);
129 int mds_get_parent_child_locked(struct obd_device *obd, struct mds_obd *mds,
130                                 struct ll_fid *fid,
131                                 struct lustre_handle *parent_lockh,
132                                 struct dentry **dparentp, int parent_mode,
133                                 __u64 parent_lockpart,
134                                 char *name, int namelen,
135                                 struct lustre_handle *child_lockh,
136                                 struct dentry **dchildp, int child_mode,
137                                 __u64 child_lockpart);
138 int mds_lock_new_child(struct obd_device *obd, struct inode *inode,
139                        struct lustre_handle *child_lockh);
140 int mds_osc_setattr_async(struct obd_device *obd, struct inode *inode,
141                           struct lov_mds_md *lmm, int lmm_size,
142                           struct llog_cookie *logcookies, struct ll_fid *fid);
143
144 int mds_get_parents_children_locked(struct obd_device *obd,
145                                     struct mds_obd *mds,
146                                     struct ll_fid *p1_fid,
147                                     struct dentry **de_srcdirp,
148                                     struct ll_fid *p2_fid,
149                                     struct dentry **de_tgtdirp,
150                                     int parent_mode,
151                                     const char *old_name, int old_len,
152                                     struct dentry **de_oldp,
153                                     const char *new_name, int new_len,
154                                     struct dentry **de_newp,
155                                     struct lustre_handle *dlm_handles,
156                                     int child_mode);
157
158 void mds_shrink_reply(struct obd_device *obd, struct ptlrpc_request *req,
159                       struct mds_body *body);
160 int mds_get_cookie_size(struct obd_device *obd, struct lov_mds_md *lmm);
161 /* mds/mds_lib.c */
162 int mds_update_unpack(struct ptlrpc_request *, int offset,
163                       struct mds_update_record *);
164 int mds_init_ucred(struct lvfs_ucred *ucred, struct ptlrpc_request *req,
165                    int offset);
166 void mds_exit_ucred(struct lvfs_ucred *ucred, struct mds_obd *obd);
167
168 /* mds/mds_unlink_open.c */
169 int mds_cleanup_pending(struct obd_device *obd);
170
171
172 /* mds/mds_log.c */
173 int mds_log_op_unlink(struct obd_device *obd, struct inode *inode,
174                       struct lov_mds_md *lmm, int lmm_size,
175                       struct llog_cookie *logcookies, int cookies_size);
176 int mds_log_op_setattr(struct obd_device *obd, struct inode *inode,
177                       struct lov_mds_md *lmm, int lmm_size,
178                       struct llog_cookie *logcookies, int cookies_size);
179 int mds_llog_init(struct obd_device *obd, struct obd_device *tgt, int count,
180                   struct llog_catid *logid);
181 int mds_llog_finish(struct obd_device *obd, int count);
182
183 /* mds/mds_lov.c */
184 int mds_lov_connect(struct obd_device *obd, char * lov_name);
185 int mds_lov_disconnect(struct obd_device *obd);
186 int mds_lov_write_objids(struct obd_device *obd);
187 void mds_lov_update_objids(struct obd_device *obd, obd_id *ids);
188 int mds_lov_clear_orphans(struct mds_obd *mds, struct obd_uuid *ost_uuid);
189 int mds_lov_set_nextid(struct obd_device *obd);
190 int mds_lov_start_synchronize(struct obd_device *obd, 
191                               struct obd_device *watched,
192                               void *data, int nonblock);
193 int mds_post_mds_lovconf(struct obd_device *obd);
194 int mds_notify(struct obd_device *obd, struct obd_device *watched,
195                enum obd_notify_event ev, void *data);
196 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
197                        struct lov_mds_md *lmm, int lmm_size);
198 void mds_objids_from_lmm(obd_id *ids, struct lov_mds_md *lmm,
199                          struct lov_desc *desc);
200 int mds_init_lov_desc(struct obd_device *obd, struct obd_export *osc_exp);
201
202 /* mds/mds_open.c */
203 int mds_query_write_access(struct inode *inode);
204 int mds_open(struct mds_update_record *rec, int offset,
205              struct ptlrpc_request *req, struct lustre_handle *);
206 int mds_pin(struct ptlrpc_request *req, int offset);
207 void mds_mfd_unlink(struct mds_file_data *mfd, int decref);
208 int mds_mfd_close(struct ptlrpc_request *req, int offset, struct obd_device *obd,
209                   struct mds_file_data *mfd, int unlink_orphan);
210 int mds_close(struct ptlrpc_request *req, int offset);
211 int mds_done_writing(struct ptlrpc_request *req, int offset);
212
213 /*mds/mds_join.c*/
214 int mds_join_file(struct mds_update_record *rec, struct ptlrpc_request *req, 
215                   struct dentry *dchild, struct lustre_handle *lockh);
216
217 /* mds/mds_fs.c */
218 int mds_client_add(struct obd_device *obd, struct mds_obd *mds,
219                    struct mds_export_data *med, int cl_off);
220 int mds_client_free(struct obd_export *exp);
221 int mds_obd_create(struct obd_export *exp, struct obdo *oa,
222                    struct lov_stripe_md **ea, struct obd_trans_info *oti);
223 int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
224                     struct lov_stripe_md *ea, struct obd_trans_info *oti,
225                     struct obd_export *md_exp);
226
227 /* mds/handler.c */
228 extern struct lvfs_callback_ops mds_lvfs_ops;
229 extern int mds_iocontrol(unsigned int cmd, struct obd_export *exp,
230                          int len, void *karg, void *uarg);
231 int mds_postrecov(struct obd_device *obd);
232 int mds_init_export(struct obd_export *exp);
233 #ifdef __KERNEL__
234 int mds_get_md(struct obd_device *, struct inode *, void *md, int *size,
235                int lock);
236 int mds_pack_md(struct obd_device *, struct lustre_msg *, int offset,
237                 struct mds_body *, struct inode *, int lock);
238 void mds_pack_inode2fid(struct ll_fid *fid, struct inode *inode);
239 void mds_pack_inode2body(struct mds_body *body, struct inode *inode);
240 #endif
241 int mds_pack_acl(struct mds_export_data *med, struct inode *inode,
242                  struct lustre_msg *repmsg, struct mds_body *repbody,
243                  int repoff);
244
245 /* quota stuff */
246 extern quota_interface_t mds_quota_interface;
247 extern quota_interface_t *quota_interface;
248
249 /* mds/mds_xattr.c */
250 int mds_setxattr(struct ptlrpc_request *req);
251 int mds_getxattr(struct ptlrpc_request *req);
252
253 static inline int mds_fid2str(char *str, __u64 id, __u32 generation)
254 {
255         return sprintf(str, "%llx:%08x", (unsigned long long)id, generation);
256 }
257
258 #endif /* _MDS_INTERNAL_H */