Whamcloud - gitweb
b=22990 update copyright messages for Oracle
[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 (c) 2003, 2010, Oracle and/or its affiliates. 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 2
48
49 #define MAX_ATIME_DIFF 60
50
51 struct mds_filter_data {
52         __u64 io_epoch;
53 };
54
55 #define MDS_FILTERDATA(inode) \
56                 ((struct mds_filter_data *)INODE_PRIVATE_DATA(inode))
57
58
59 static inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req)
60 {
61         return &req->rq_export->exp_obd->u.mds;
62 }
63
64 static inline void mds_export_evict(struct obd_export *exp)
65 {
66         class_fail_export(exp);
67         class_export_put(exp);
68 }
69
70 #ifdef __KERNEL__
71 /* Open counts for files.  No longer atomic, must hold inode->i_sem */
72 # define mds_inode_oatomic(inode)    ((inode)->i_cindex)
73
74 #define MDS_UP_READ_ORPHAN_SEM(i)          UP_READ_I_ALLOC_SEM(i)
75 #define MDS_DOWN_READ_ORPHAN_SEM(i)        DOWN_READ_I_ALLOC_SEM(i)
76 #define LASSERT_MDS_ORPHAN_READ_LOCKED(i)  LASSERT_I_ALLOC_SEM_READ_LOCKED(i)
77
78 #define MDS_UP_WRITE_ORPHAN_SEM(i)         UP_WRITE_I_ALLOC_SEM(i)
79 #define MDS_DOWN_WRITE_ORPHAN_SEM(i)       DOWN_WRITE_I_ALLOC_SEM(i)
80 #define LASSERT_MDS_ORPHAN_WRITE_LOCKED(i) LASSERT_I_ALLOC_SEM_WRITE_LOCKED(i)
81 #define MDS_PACK_MD_LOCK 1
82
83 static inline int mds_orphan_open_count(struct inode *inode)
84 {
85         LASSERT_MDS_ORPHAN_READ_LOCKED(inode);
86         return mds_inode_oatomic(inode);
87 }
88
89 static inline int mds_orphan_needed(struct obd_device *obd,
90                                     struct inode * inode)
91 {
92         return (obd->obd_recovering ||
93                 mds_orphan_open_count(inode) > 0);
94 }
95
96 static inline int mds_orphan_open_inc(struct inode *inode)
97 {
98         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
99         return ++mds_inode_oatomic(inode);
100 }
101
102 static inline int mds_orphan_open_dec_test(struct inode *inode)
103 {
104         LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
105         return --mds_inode_oatomic(inode) == 0;
106 }
107
108 #define mds_inode_is_orphan(inode)  ((inode)->i_flags & 0x4000000)
109
110 static inline void mds_inode_set_orphan(struct inode *inode)
111 {
112         inode->i_flags |= 0x4000000;
113         CDEBUG(D_VFSTRACE, "setting orphan flag on inode %p\n", inode);
114 }
115
116 static inline void mds_inode_unset_orphan(struct inode *inode)
117 {
118         inode->i_flags &= ~(0x4000000);
119         CDEBUG(D_VFSTRACE, "removing orphan flag from inode %p\n", inode);
120 }
121
122 #endif /* __KERNEL__ */
123
124 #define MDS_CHECK_RESENT(req, reconstruct)                                    \
125 {                                                                             \
126         if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {              \
127                 struct lsd_client_data *lcd =                                 \
128                         req->rq_export->exp_mds_data.med_lcd;                 \
129                 if (le64_to_cpu(lcd->lcd_last_xid) == req->rq_xid) {          \
130                         reconstruct;                                          \
131                         RETURN(le32_to_cpu(lcd->lcd_last_result));            \
132                 }                                                             \
133                 if (le64_to_cpu(lcd->lcd_last_close_xid) == req->rq_xid) {    \
134                         reconstruct;                                          \
135                         RETURN(le32_to_cpu(lcd->lcd_last_close_result));      \
136                 }                                                             \
137                 DEBUG_REQ(D_HA, req, "no reply for RESENT req (have "LPD64")",\
138                           lcd->lcd_last_xid);                                 \
139         }                                                                     \
140 }
141
142 /* mds/mds_reint.c */
143 int res_gt(struct ldlm_res_id *res1, struct ldlm_res_id *res2,
144            ldlm_policy_data_t *p1, ldlm_policy_data_t *p2);
145 int enqueue_ordered_locks(struct obd_device *obd, struct ldlm_res_id *p1_res_id,
146                           struct lustre_handle *p1_lockh, int p1_lock_mode,
147                           ldlm_policy_data_t *p1_policy,
148                           struct ldlm_res_id *p2_res_id,
149                           struct lustre_handle *p2_lockh, int p2_lock_mode,
150                           ldlm_policy_data_t *p2_policy);
151 void mds_commit_cb(struct obd_device *, __u64 last_rcvd, void *data, int error);
152 int mds_finish_transno(struct mds_obd *, struct inode **, void *,
153                        struct ptlrpc_request *, int, __u32, int force_sync);
154 void mds_reconstruct_generic(struct ptlrpc_request *req);
155 void mds_req_from_lcd(struct ptlrpc_request *req, struct lsd_client_data *cd);
156 int mds_get_parent_child_locked(struct obd_device *obd, struct mds_obd *mds,
157                                 struct ll_fid *fid,
158                                 struct lustre_handle *parent_lockh,
159                                 struct dentry **dparentp, int parent_mode,
160                                 __u64 parent_lockpart,
161                                 char *name, int namelen,
162                                 struct lustre_handle *child_lockh,
163                                 struct dentry **dchildp, int child_mode,
164                                 __u64 child_lockpart);
165 int mds_lock_new_child(struct obd_device *obd, struct inode *inode,
166                        struct lustre_handle *child_lockh);
167 int mds_osc_setattr_async(struct obd_device *obd, struct inode *inode,
168                           struct lov_mds_md *lmm, int lmm_size,
169                           struct llog_cookie *logcookies, struct ll_fid *fid);
170
171 int mds_get_parents_children_locked(struct obd_device *obd,
172                                     struct mds_obd *mds,
173                                     struct ll_fid *p1_fid,
174                                     struct dentry **de_srcdirp,
175                                     struct ll_fid *p2_fid,
176                                     struct dentry **de_tgtdirp,
177                                     int parent_mode,
178                                     const char *old_name, int old_len,
179                                     struct dentry **de_oldp,
180                                     const char *new_name, int new_len,
181                                     struct dentry **de_newp,
182                                     struct lustre_handle *dlm_handles,
183                                     int child_mode);
184
185 struct dentry *mds_lookup(struct obd_device *obd,
186                           const char *fid_name,
187                           struct dentry *dparent,
188                           int fid_namelen);
189
190 void mds_shrink_body_reply(struct ptlrpc_request *req, int req_mdoff,
191                            int reply_mdoff);
192 void mds_shrink_intent_reply(struct ptlrpc_request *req,
193                              int opc, int reply_mdoff);
194 int mds_get_cookie_size(struct obd_device *obd, struct lov_mds_md *lmm);
195 int mds_version_get_check(struct ptlrpc_request *, struct inode *, int);
196 /* mds/mds_lib.c */
197 int mds_update_unpack(struct ptlrpc_request *, int offset,
198                       struct mds_update_record *);
199 int mds_init_ucred(struct lvfs_ucred *ucred, struct ptlrpc_request *req,
200                    int offset);
201 void mds_exit_ucred(struct lvfs_ucred *ucred, struct mds_obd *obd);
202 void mds_root_squash(struct mds_obd *mds, lnet_nid_t *peernid,
203                      __u32 *fsuid, __u32 *fsgid, cfs_kernel_cap_t *cap,
204                      __u32 *suppgid, __u32 *suppgid2);
205
206 /* mds/mds_unlink_open.c */
207 int mds_osc_destroy_orphan(struct obd_device *obd, umode_t mode,
208                            struct lov_mds_md *lmm, int lmm_size,
209                            struct llog_cookie *logcookies, int log_unlink);
210 int mds_cleanup_pending(struct obd_device *obd);
211 int mds_check_stale_orphan(struct obd_device *obd, struct ll_fid *fid);
212
213 /* mds/mds_log.c */
214 int mds_log_op_unlink(struct obd_device *obd,
215                       struct lov_mds_md *lmm, int lmm_size,
216                       struct llog_cookie *logcookies, int cookies_size);
217 int mds_log_op_orphan(struct obd_device *, struct lov_stripe_md *, obd_count);
218 int mds_log_op_setattr(struct obd_device *obd, struct inode *inode,
219                       struct lov_mds_md *lmm, int lmm_size,
220                       struct llog_cookie *logcookies, int cookies_size);
221 int mds_llog_init(struct obd_device *obd, struct obd_device *disk_obd,
222                   int *index);
223 int mds_llog_finish(struct obd_device *obd, int count);
224
225 /* mds/mds_lov.c */
226 int mds_lov_connect(struct obd_device *obd, char * lov_name);
227 int mds_lov_disconnect(struct obd_device *obd);
228
229 int mds_lov_write_objids(struct obd_device *obd);
230 int mds_lov_prepare_objids(struct obd_device *obd, struct lov_mds_md *lmm);
231 void mds_lov_update_objids(struct obd_device *obd, struct lov_mds_md *lmm);
232 int mds_lov_clear_orphans(struct mds_obd *mds, struct obd_uuid *ost_uuid);
233
234 int mds_lov_start_synchronize(struct obd_device *obd,
235                               struct obd_device *watched,
236                               void *data, int nonblock);
237 int mds_post_mds_lovconf(struct obd_device *obd);
238 int mds_notify(struct obd_device *obd, struct obd_device *watched,
239                enum obd_notify_event ev, void *data);
240 int mds_get_default_md(struct obd_device *obd, struct lov_user_md *lmm);
241 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
242                        struct lov_mds_md *lmm, int lmm_size,
243                        __u64 connect_flags);
244 int mds_init_lov_desc(struct obd_device *obd, struct obd_export *osc_exp);
245
246 /* mds/mds_open.c */
247 int mds_query_write_access(struct inode *inode);
248 int mds_open(struct mds_update_record *rec, int offset,
249              struct ptlrpc_request *req, struct lustre_handle *);
250 int mds_pin(struct ptlrpc_request *req, int offset);
251 void mds_mfd_unlink(struct mds_file_data *mfd, int decref);
252 int mds_mfd_close(struct ptlrpc_request *req, int offset,struct obd_device *obd,
253                   struct mds_file_data *mfd, int unlink_orphan,
254                   struct lov_mds_md *lmm, int lmm_size,
255                   struct llog_cookie *logcookies, int cookies_size,
256                   __u64 *valid);
257 int mds_close(struct ptlrpc_request *req, int offset);
258 int mds_done_writing(struct ptlrpc_request *req, int offset);
259
260 /*mds/mds_join.c*/
261 int mds_join_file(struct mds_update_record *rec, struct ptlrpc_request *req,
262                   struct dentry *dchild, struct lustre_handle *lockh);
263
264 /* mds/mds_fs.c */
265 int mds_update_client_epoch(struct obd_export *exp);
266 void mds_update_last_epoch(struct obd_device *obd);
267 int mds_export_stats_init(struct obd_device *obd,
268                           struct obd_export *exp,
269                           int reconnect,
270                           void *client_nid);
271 int mds_client_add(struct obd_device *obd, struct obd_export *exp,
272                    int cl_off, void *localdata);
273 int mds_client_free(struct obd_export *exp);
274 int mds_obd_create(struct obd_export *exp, struct obdo *oa,
275                    struct lov_stripe_md **ea, struct obd_trans_info *oti);
276 int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
277                     struct lov_stripe_md *ea, struct obd_trans_info *oti,
278                     struct obd_export *md_exp);
279
280 /* mds/handler.c */
281 extern struct lvfs_callback_ops mds_lvfs_ops;
282 extern int mds_iocontrol(unsigned int cmd, struct obd_export *exp,
283                          int len, void *karg, void *uarg);
284 int mds_postrecov(struct obd_device *obd);
285 int mds_init_export(struct obd_export *exp);
286 #ifdef __KERNEL__
287 int mds_get_md(struct obd_device *, struct inode *, void *md, int *size,
288                int lock, int flags, __u64 connect_flags);
289 int mds_pack_md(struct obd_device *, struct lustre_msg *, int offset,
290                 struct mds_body *, struct inode *, int lock, int flags,
291                 __u64 connect_flags);
292 void mds_pack_inode2body(struct mds_body *body, struct inode *inode);
293 #endif
294 int mds_pack_acl(struct mds_export_data *med, struct inode *inode,
295                  struct lustre_msg *repmsg, struct mds_body *repbody,
296                  int repoff);
297
298 /* quota stuff */
299 extern quota_interface_t *mds_quota_interface_ref;
300
301 /* mds/mds_xattr.c */
302 int mds_setxattr(struct ptlrpc_request *req);
303 int mds_getxattr(struct ptlrpc_request *req);
304
305 /* mds/lproc_mds.c */
306 enum {
307         LPROC_MDS_OPEN = 0,
308         LPROC_MDS_CLOSE,
309         LPROC_MDS_MKNOD,
310         LPROC_MDS_LINK,
311         LPROC_MDS_UNLINK,
312         LPROC_MDS_MKDIR,
313         LPROC_MDS_RMDIR,
314         LPROC_MDS_RENAME,
315         LPROC_MDS_GETXATTR,
316         LPROC_MDS_SETXATTR,
317         LPROC_MDS_LAST,
318 };
319 void mds_counter_incr(struct obd_export *exp, int opcode);
320 void mds_stats_counter_init(struct lprocfs_stats *stats);
321 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars);
322 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars);
323 #endif /* _MDS_INTERNAL_H */