Whamcloud - gitweb
Land b1_8_gate onto b1_8 (20081218_1708)
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef _MDS_INTERNAL_H
38 #define _MDS_INTERNAL_H
39
40 #include <lustre_disk.h>
41 #include <lustre_mds.h>
42
43 #define MDT_ROCOMPAT_SUPP       (OBD_ROCOMPAT_LOVOBJID)
44 #define MDT_INCOMPAT_SUPP       (OBD_INCOMPAT_MDT | OBD_INCOMPAT_COMMON_LR | \
45                                  OBD_INCOMPAT_FID)
46
47 #define MDS_SERVICE_WATCHDOG_FACTOR 2000
48
49 #define MAX_ATIME_DIFF 60
50
51 struct mds_filter_data {
52         __u64 io_epoch;
53 };
54
55 #define MDS_FILTERDATA(inode) ((struct mds_filter_data *)(inode)->i_filterdata)
56
57 static inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req)
58 {
59         return &req->rq_export->exp_obd->u.mds;
60 }
61
62 static inline void mds_export_evict(struct obd_export *exp)
63 {
64         class_fail_export(exp);
65         class_export_put(exp);
66 }
67
68 #ifdef __KERNEL__
69 /* Open counts for files.  No longer atomic, must hold inode->i_sem */
70 # define mds_inode_oatomic(inode)    ((inode)->i_cindex)
71
72 #ifdef HAVE_I_ALLOC_SEM
73 #define MDS_UP_READ_ORPHAN_SEM(i)          UP_READ_I_ALLOC_SEM(i)
74 #define MDS_DOWN_READ_ORPHAN_SEM(i)        DOWN_READ_I_ALLOC_SEM(i)
75 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i)  LASSERT_I_ALLOC_SEM_READ_LOCKED(i)
76
77 #define MDS_UP_WRITE_ORPHAN_SEM(i)         UP_WRITE_I_ALLOC_SEM(i)
78 #define MDS_DOWN_WRITE_ORPHAN_SEM(i)       DOWN_WRITE_I_ALLOC_SEM(i)
79 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i)
80 #define MDS_PACK_MD_LOCK 1
81 #else
82 #define MDS_UP_READ_ORPHAN_SEM(i)          do { up(&(i)->i_sem); } while (0)
83 #define MDS_DOWN_READ_ORPHAN_SEM(i)        do { down(&(i)->i_sem); } while (0)
84 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i)  LASSERT(down_trylock(&(i)->i_sem)!=0)
85
86 #define MDS_UP_WRITE_ORPHAN_SEM(i)         do { up(&(i)->i_sem); } while (0)
87 #define MDS_DOWN_WRITE_ORPHAN_SEM(i)       do { down(&(i)->i_sem); } while (0)
88 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT(down_trylock(&(i)->i_sem)!=0)
89 #define MDS_PACK_MD_LOCK 0
90 #endif
91
92 static inline int mds_orphan_open_count(struct inode *inode)
93 {
94         LASSERT_MDS_ORPHAN_READ_LOCKED(inode);
95         return mds_inode_oatomic(inode);
96 }
97
98 static inline int mds_orphan_needed(struct obd_device *obd,
99                                     struct inode * inode)
100 {
101         return (obd->obd_recovering ||
102                 mds_orphan_open_count(inode) > 0);
103 }
104
105 static inline int mds_orphan_open_inc(struct inode *inode)
106 {
107         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
108         return ++mds_inode_oatomic(inode);
109 }
110
111 static inline int mds_orphan_open_dec_test(struct inode *inode)
112 {
113         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
114         return --mds_inode_oatomic(inode) == 0;
115 }
116
117 #define mds_inode_is_orphan(inode)  ((inode)->i_flags & 0x4000000)
118
119 static inline void mds_inode_set_orphan(struct inode *inode)
120 {
121         inode->i_flags |= 0x4000000;
122         CDEBUG(D_VFSTRACE, "setting orphan flag on inode %p\n", inode);
123 }
124
125 static inline void mds_inode_unset_orphan(struct inode *inode)
126 {
127         inode->i_flags &= ~(0x4000000);
128         CDEBUG(D_VFSTRACE, "removing orphan flag from inode %p\n", inode);
129 }
130
131 #endif /* __KERNEL__ */
132
133 #define MDS_CHECK_RESENT(req, reconstruct)                                    \
134 {                                                                             \
135         if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {              \
136                 struct lsd_client_data *lcd =                                 \
137                         req->rq_export->exp_mds_data.med_lcd;                 \
138                 if (le64_to_cpu(lcd->lcd_last_xid) == req->rq_xid) {          \
139                         reconstruct;                                          \
140                         RETURN(le32_to_cpu(lcd->lcd_last_result));            \
141                 }                                                             \
142                 if (le64_to_cpu(lcd->lcd_last_close_xid) == req->rq_xid) {    \
143                         reconstruct;                                          \
144                         RETURN(le32_to_cpu(lcd->lcd_last_close_result));      \
145                 }                                                             \
146                 DEBUG_REQ(D_HA, req, "no reply for RESENT req (have "LPD64")",\
147                           lcd->lcd_last_xid);                                 \
148         }                                                                     \
149 }
150
151 /* mds/mds_reint.c */
152 int res_gt(struct ldlm_res_id *res1, struct ldlm_res_id *res2,
153            ldlm_policy_data_t *p1, ldlm_policy_data_t *p2);
154 int enqueue_ordered_locks(struct obd_device *obd, struct ldlm_res_id *p1_res_id,
155                           struct lustre_handle *p1_lockh, int p1_lock_mode,
156                           ldlm_policy_data_t *p1_policy,
157                           struct ldlm_res_id *p2_res_id,
158                           struct lustre_handle *p2_lockh, int p2_lock_mode,
159                           ldlm_policy_data_t *p2_policy);
160 void mds_commit_cb(struct obd_device *, __u64 last_rcvd, void *data, int error);
161 int mds_finish_transno(struct mds_obd *, struct inode **, void *,
162                        struct ptlrpc_request *, int, __u32, int force_sync);
163 void mds_reconstruct_generic(struct ptlrpc_request *req);
164 void mds_req_from_lcd(struct ptlrpc_request *req, struct lsd_client_data *cd);
165 int mds_get_parent_child_locked(struct obd_device *obd, struct mds_obd *mds,
166                                 struct ll_fid *fid,
167                                 struct lustre_handle *parent_lockh,
168                                 struct dentry **dparentp, int parent_mode,
169                                 __u64 parent_lockpart,
170                                 char *name, int namelen,
171                                 struct lustre_handle *child_lockh,
172                                 struct dentry **dchildp, int child_mode,
173                                 __u64 child_lockpart);
174 int mds_lock_new_child(struct obd_device *obd, struct inode *inode,
175                        struct lustre_handle *child_lockh);
176 int mds_osc_setattr_async(struct obd_device *obd, struct inode *inode,
177                           struct lov_mds_md *lmm, int lmm_size,
178                           struct llog_cookie *logcookies, struct ll_fid *fid);
179
180 int mds_get_parents_children_locked(struct obd_device *obd,
181                                     struct mds_obd *mds,
182                                     struct ll_fid *p1_fid,
183                                     struct dentry **de_srcdirp,
184                                     struct ll_fid *p2_fid,
185                                     struct dentry **de_tgtdirp,
186                                     int parent_mode,
187                                     const char *old_name, int old_len,
188                                     struct dentry **de_oldp,
189                                     const char *new_name, int new_len,
190                                     struct dentry **de_newp,
191                                     struct lustre_handle *dlm_handles,
192                                     int child_mode);
193
194 struct dentry *mds_lookup(struct obd_device *obd,
195                           const char *fid_name,
196                           struct dentry *dparent,
197                           int fid_namelen);
198
199 void mds_shrink_reply(struct obd_device *obd, struct ptlrpc_request *req,
200                       struct mds_body *body, int md_off);
201 int mds_get_cookie_size(struct obd_device *obd, struct lov_mds_md *lmm);
202 int mds_version_get_check(struct ptlrpc_request *, struct inode *, int);
203 /* mds/mds_lib.c */
204 int mds_update_unpack(struct ptlrpc_request *, int offset,
205                       struct mds_update_record *);
206 int mds_init_ucred(struct lvfs_ucred *ucred, struct ptlrpc_request *req,
207                    int offset);
208 void mds_exit_ucred(struct lvfs_ucred *ucred, struct mds_obd *obd);
209 void mds_root_squash(struct mds_obd *mds, lnet_nid_t *peernid,
210                      __u32 *fsuid, __u32 *fsgid, cfs_kernel_cap_t *cap,
211                      __u32 *suppgid, __u32 *suppgid2);
212
213 /* mds/mds_unlink_open.c */
214 int mds_osc_destroy_orphan(struct obd_device *obd, umode_t mode,
215                            struct lov_mds_md *lmm, int lmm_size,
216                            struct llog_cookie *logcookies, int log_unlink);
217 int mds_cleanup_pending(struct obd_device *obd);
218 int mds_check_stale_orphan(struct obd_device *obd, struct ll_fid *fid);
219
220 /* mds/mds_log.c */
221 int mds_log_op_unlink(struct obd_device *obd,
222                       struct lov_mds_md *lmm, int lmm_size,
223                       struct llog_cookie *logcookies, int cookies_size);
224 int mds_log_op_orphan(struct obd_device *, struct lov_stripe_md *, obd_count);
225 int mds_log_op_setattr(struct obd_device *obd, struct inode *inode,
226                       struct lov_mds_md *lmm, int lmm_size,
227                       struct llog_cookie *logcookies, int cookies_size);
228 int mds_llog_init(struct obd_device *obd, struct obd_device *tgt, int count,
229                   struct llog_catid *logid, struct obd_uuid *uuid);
230 int mds_llog_finish(struct obd_device *obd, int count);
231
232 /* mds/mds_lov.c */
233 int mds_lov_connect(struct obd_device *obd, char * lov_name);
234 int mds_lov_disconnect(struct obd_device *obd);
235
236 int mds_lov_write_objids(struct obd_device *obd);
237 int mds_lov_prepare_objids(struct obd_device *obd, struct lov_mds_md *lmm);
238 void mds_lov_update_objids(struct obd_device *obd, struct lov_mds_md *lmm);
239 int mds_lov_clear_orphans(struct mds_obd *mds, struct obd_uuid *ost_uuid);
240
241 int mds_lov_start_synchronize(struct obd_device *obd,
242                               struct obd_device *watched,
243                               void *data, int nonblock);
244 int mds_post_mds_lovconf(struct obd_device *obd);
245 int mds_notify(struct obd_device *obd, struct obd_device *watched,
246                enum obd_notify_event ev, void *data);
247 int mds_get_default_md(struct obd_device *obd, struct lov_mds_md *lmm,
248                        int *lmmsize);
249 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
250                        struct lov_mds_md *lmm, int lmm_size,
251                        __u64 connect_flags);
252 int mds_init_lov_desc(struct obd_device *obd, struct obd_export *osc_exp);
253
254 /* mds/mds_open.c */
255 int mds_query_write_access(struct inode *inode);
256 int mds_open(struct mds_update_record *rec, int offset,
257              struct ptlrpc_request *req, struct lustre_handle *);
258 int mds_pin(struct ptlrpc_request *req, int offset);
259 void mds_mfd_unlink(struct mds_file_data *mfd, int decref);
260 int mds_mfd_close(struct ptlrpc_request *req, int offset,struct obd_device *obd,
261                   struct mds_file_data *mfd, int unlink_orphan,
262                   struct lov_mds_md *lmm, int lmm_size,
263                   struct llog_cookie *logcookies, int cookies_size,
264                   __u64 *valid);
265 int mds_close(struct ptlrpc_request *req, int offset);
266 int mds_done_writing(struct ptlrpc_request *req, int offset);
267
268 /*mds/mds_join.c*/
269 int mds_join_file(struct mds_update_record *rec, struct ptlrpc_request *req,
270                   struct dentry *dchild, struct lustre_handle *lockh);
271
272 /* mds/mds_fs.c */
273 int mds_update_client_epoch(struct obd_export *exp);
274 void mds_update_last_epoch(struct obd_device *obd);
275 int mds_export_stats_init(struct obd_device *obd,
276                           struct obd_export *exp,
277                           void *client_nid);
278 int mds_client_add(struct obd_device *obd, struct obd_export *exp,
279                    int cl_off, void *localdata);
280 int mds_client_free(struct obd_export *exp);
281 int mds_obd_create(struct obd_export *exp, struct obdo *oa,
282                    struct lov_stripe_md **ea, struct obd_trans_info *oti);
283 int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
284                     struct lov_stripe_md *ea, struct obd_trans_info *oti,
285                     struct obd_export *md_exp);
286
287 /* mds/handler.c */
288 extern struct lvfs_callback_ops mds_lvfs_ops;
289 extern int mds_iocontrol(unsigned int cmd, struct obd_export *exp,
290                          int len, void *karg, void *uarg);
291 int mds_postrecov(struct obd_device *obd);
292 int mds_init_export(struct obd_export *exp);
293 #ifdef __KERNEL__
294 int mds_get_md(struct obd_device *, struct inode *, void *md, int *size,
295                int lock, int flags, __u64 connect_flags);
296 int mds_pack_md(struct obd_device *, struct lustre_msg *, int offset,
297                 struct mds_body *, struct inode *, int lock, int flags,
298                 __u64 connect_flags);
299 void mds_pack_inode2body(struct mds_body *body, struct inode *inode);
300 #endif
301 int mds_pack_acl(struct mds_export_data *med, struct inode *inode,
302                  struct lustre_msg *repmsg, struct mds_body *repbody,
303                  int repoff);
304
305 /* quota stuff */
306 extern quota_interface_t *mds_quota_interface_ref;
307
308 /* mds/mds_xattr.c */
309 int mds_setxattr(struct ptlrpc_request *req);
310 int mds_getxattr(struct ptlrpc_request *req);
311
312 /* mds/lproc_mds.c */
313 enum {
314         LPROC_MDS_OPEN = 0,
315         LPROC_MDS_CLOSE,
316         LPROC_MDS_MKNOD,
317         LPROC_MDS_LINK,
318         LPROC_MDS_UNLINK,
319         LPROC_MDS_MKDIR,
320         LPROC_MDS_RMDIR,
321         LPROC_MDS_RENAME,
322         LPROC_MDS_GETXATTR,
323         LPROC_MDS_SETXATTR,
324         LPROC_MDS_LAST,
325 };
326 void mds_counter_incr(struct obd_export *exp, int opcode);
327 void mds_stats_counter_init(struct lprocfs_stats *stats);
328 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars);
329 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars);
330 #endif /* _MDS_INTERNAL_H */