Whamcloud - gitweb
Land b1_4_bgl on b1_4.
[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 (obd_timeout * 1000)
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 *)(inode)->i_filterdata)
19
20 static inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req)
21 {
22         return &req->rq_export->exp_obd->u.mds;
23 }
24
25 #ifdef __KERNEL__
26 /* Open counts for files.  No longer atomic, must hold inode->i_sem */
27 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
28 # define mds_inode_oatomic(inode)    ((inode)->i_cindex)
29 #else
30 # define mds_inode_oatomic(inode)    ((inode)->i_attr_flags)
31 #endif
32
33 #ifdef HAVE_I_ALLOC_SEM
34 #define MDS_UP_READ_ORPHAN_SEM(i)          UP_READ_I_ALLOC_SEM(i)
35 #define MDS_DOWN_READ_ORPHAN_SEM(i)        DOWN_READ_I_ALLOC_SEM(i)
36 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i)  LASSERT_I_ALLOC_SEM_READ_LOCKED(i)
37
38 #define MDS_UP_WRITE_ORPHAN_SEM(i)         UP_WRITE_I_ALLOC_SEM(i)
39 #define MDS_DOWN_WRITE_ORPHAN_SEM(i)       DOWN_WRITE_I_ALLOC_SEM(i)
40 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i)
41 #define MDS_PACK_MD_LOCK 1
42 #else
43 #define MDS_UP_READ_ORPHAN_SEM(i)          do { up(&(i)->i_sem); } while (0)
44 #define MDS_DOWN_READ_ORPHAN_SEM(i)        do { down(&(i)->i_sem); } while (0)
45 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i)  LASSERT(down_trylock(&(i)->i_sem)!=0)
46
47 #define MDS_UP_WRITE_ORPHAN_SEM(i)         do { up(&(i)->i_sem); } while (0)
48 #define MDS_DOWN_WRITE_ORPHAN_SEM(i)       do { down(&(i)->i_sem); } while (0)
49 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem)!=0)
50 #define MDS_PACK_MD_LOCK 0
51 #endif
52
53 static inline int mds_orphan_open_count(struct inode *inode)
54 {
55         LASSERT_MDS_ORPHAN_READ_LOCKED(inode);
56         return mds_inode_oatomic(inode);
57 }
58
59 static inline int mds_orphan_open_inc(struct inode *inode)
60 {
61         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
62         return ++mds_inode_oatomic(inode);
63 }
64
65 static inline int mds_orphan_open_dec_test(struct inode *inode)
66 {
67         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
68         return --mds_inode_oatomic(inode) == 0;
69 }
70
71 #define mds_inode_is_orphan(inode)  ((inode)->i_flags & 0x4000000)
72
73 static inline void mds_inode_set_orphan(struct inode *inode)
74 {
75         inode->i_flags |= 0x4000000;
76         CDEBUG(D_VFSTRACE, "setting orphan flag on inode %p\n", inode);
77 }
78
79 static inline void mds_inode_unset_orphan(struct inode *inode)
80 {
81         inode->i_flags &= ~(0x4000000);
82         CDEBUG(D_VFSTRACE, "removing orphan flag from inode %p\n", inode);
83 }
84
85 #endif /* __KERNEL__ */
86
87 #define MDS_CHECK_RESENT(req, reconstruct)                                    \
88 {                                                                             \
89         if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {              \
90                 struct mds_client_data *mcd =                                 \
91                         req->rq_export->exp_mds_data.med_mcd;                 \
92                 if (mcd->mcd_last_xid == req->rq_xid) {                       \
93                         reconstruct;                                          \
94                         RETURN(req->rq_repmsg->status);                       \
95                 }                                                             \
96                 DEBUG_REQ(D_HA, req, "no reply for RESENT req (have "LPD64")",\
97                           mcd->mcd_last_xid);                                 \
98         }                                                                     \
99 }
100
101 /* mds/mds_reint.c */
102 int res_gt(struct ldlm_res_id *res1, struct ldlm_res_id *res2);
103 int enqueue_ordered_locks(struct obd_device *obd, struct ldlm_res_id *p1_res_id,
104                           struct lustre_handle *p1_lockh, int p1_lock_mode,
105                           struct ldlm_res_id *p2_res_id,
106                           struct lustre_handle *p2_lockh, int p2_lock_mode);
107 void mds_commit_cb(struct obd_device *, __u64 last_rcvd, void *data, int error);
108 int mds_finish_transno(struct mds_obd *mds, struct inode *inode, void *handle,
109                        struct ptlrpc_request *req, int rc, __u32 op_data);
110 void mds_reconstruct_generic(struct ptlrpc_request *req);
111 void mds_req_from_mcd(struct ptlrpc_request *req, struct mds_client_data *mcd);
112 int mds_get_parent_child_locked(struct obd_device *obd, struct mds_obd *mds,
113                                 struct ll_fid *fid,
114                                 struct lustre_handle *parent_lockh,
115                                 struct dentry **dparentp, int parent_mode,
116                                 char *name, int namelen,
117                                 struct lustre_handle *child_lockh,
118                                 struct dentry **dchildp, int child_mode);
119 int mds_lock_new_child(struct obd_device *obd, struct inode *inode,
120                        struct lustre_handle *child_lockh);
121
122 /* mds/mds_lib.c */
123 int mds_update_unpack(struct ptlrpc_request *, int offset,
124                       struct mds_update_record *);
125
126 /* mds/mds_unlink_open.c */
127 int mds_cleanup_orphans(struct obd_device *obd);
128
129
130 /* mds/mds_log.c */
131 int mds_log_op_unlink(struct obd_device *obd, struct inode *inode,
132                       struct lov_mds_md *lmm, int lmm_size,
133                       struct llog_cookie *logcookies, int cookies_size);
134 int mds_llog_init(struct obd_device *obd, struct obd_device *tgt, int count,
135                   struct llog_catid *logid);
136 int mds_llog_finish(struct obd_device *obd, int count);
137
138 /* mds/mds_lov.c */
139 int mds_lov_connect(struct obd_device *obd, char * lov_name);
140 int mds_lov_disconnect(struct obd_device *obd);
141 void mds_lov_set_cleanup_flags(struct obd_device *);
142 int mds_lov_write_objids(struct obd_device *obd);
143 void mds_lov_update_objids(struct obd_device *obd, obd_id *ids);
144 int mds_lov_set_growth(struct mds_obd *mds, int count);
145 int mds_lov_set_nextid(struct obd_device *obd);
146 int mds_lov_clearorphans(struct mds_obd *mds, struct obd_uuid *ost_uuid);
147 int mds_post_mds_lovconf(struct obd_device *obd);
148 int mds_notify(struct obd_device *obd, struct obd_device *watched, int active);
149 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
150                        struct lov_mds_md *lmm, int lmm_size);
151 void mds_objids_from_lmm(obd_id *ids, struct lov_mds_md *lmm,
152                          struct lov_desc *desc);
153
154 /* mds/mds_open.c */
155 int mds_query_write_access(struct inode *inode);
156 int mds_open(struct mds_update_record *rec, int offset,
157              struct ptlrpc_request *req, struct lustre_handle *);
158 int mds_pin(struct ptlrpc_request *req);
159 int mds_mfd_close(struct ptlrpc_request *req, struct obd_device *obd,
160                   struct mds_file_data *mfd, int unlink_orphan);
161 int mds_close(struct ptlrpc_request *req);
162 int mds_done_writing(struct ptlrpc_request *req);
163
164
165 /* mds/mds_fs.c */
166 int mds_client_add(struct obd_device *obd, struct mds_obd *mds,
167                    struct mds_export_data *med, int cl_off);
168 int mds_client_free(struct obd_export *exp, int clear_client);
169 int mds_obd_create(struct obd_export *exp, struct obdo *oa,
170                    struct lov_stripe_md **ea, struct obd_trans_info *oti);
171 int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
172                     struct lov_stripe_md *ea, struct obd_trans_info *oti);
173
174 /* mds/handler.c */
175 extern struct lvfs_callback_ops mds_lvfs_ops;
176 int mds_lov_clean(struct obd_device *obd);
177 extern int mds_iocontrol(unsigned int cmd, struct obd_export *exp,
178                          int len, void *karg, void *uarg);
179 int mds_postrecov(struct obd_device *obd);
180 #ifdef __KERNEL__
181 int mds_get_md(struct obd_device *, struct inode *, void *md, int *size,
182                int lock);
183 int mds_pack_md(struct obd_device *, struct lustre_msg *, int offset,
184                 struct mds_body *, struct inode *, int lock);
185 void mds_pack_inode2fid(struct ll_fid *fid, struct inode *inode);
186 void mds_pack_inode2body(struct mds_body *body, struct inode *inode);
187 #endif
188
189 #endif /* _MDS_INTERNAL_H */