1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef _MDS_INTERNAL_H
38 #define _MDS_INTERNAL_H
40 #include <lustre_disk.h>
41 #include <lustre_mds.h>
43 #define MDT_ROCOMPAT_SUPP (OBD_ROCOMPAT_LOVOBJID)
44 #define MDT_INCOMPAT_SUPP (OBD_INCOMPAT_MDT | OBD_INCOMPAT_COMMON_LR | \
47 #define MDS_SERVICE_WATCHDOG_FACTOR 2
49 #define MAX_ATIME_DIFF 60
51 struct mds_filter_data {
55 #define MDS_FILTERDATA(inode) \
56 ((struct mds_filter_data *)INODE_PRIVATE_DATA(inode))
59 static inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req)
61 return &req->rq_export->exp_obd->u.mds;
64 static inline void mds_export_evict(struct obd_export *exp)
66 class_fail_export(exp);
67 class_export_put(exp);
71 /* Open counts for files. No longer atomic, must hold inode->i_sem */
72 # define mds_inode_oatomic(inode) ((inode)->i_cindex)
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)
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
83 static inline int mds_orphan_open_count(struct inode *inode)
85 LASSERT_MDS_ORPHAN_READ_LOCKED(inode);
86 return mds_inode_oatomic(inode);
89 static inline int mds_orphan_needed(struct obd_device *obd,
92 return (obd->obd_recovering ||
93 mds_orphan_open_count(inode) > 0);
96 static inline int mds_orphan_open_inc(struct inode *inode)
98 LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
99 return ++mds_inode_oatomic(inode);
102 static inline int mds_orphan_open_dec_test(struct inode *inode)
104 LASSERT_MDS_ORPHAN_WRITE_LOCKED(inode);
105 return --mds_inode_oatomic(inode) == 0;
108 #define mds_inode_is_orphan(inode) ((inode)->i_flags & 0x4000000)
110 static inline void mds_inode_set_orphan(struct inode *inode)
112 inode->i_flags |= 0x4000000;
113 CDEBUG(D_VFSTRACE, "setting orphan flag on inode %p\n", inode);
116 static inline void mds_inode_unset_orphan(struct inode *inode)
118 inode->i_flags &= ~(0x4000000);
119 CDEBUG(D_VFSTRACE, "removing orphan flag from inode %p\n", inode);
122 #endif /* __KERNEL__ */
124 #define MDS_CHECK_RESENT(req, reconstruct) \
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) { \
131 RETURN(le32_to_cpu(lcd->lcd_last_result)); \
133 if (le64_to_cpu(lcd->lcd_last_close_xid) == req->rq_xid) { \
135 RETURN(le32_to_cpu(lcd->lcd_last_close_result)); \
137 DEBUG_REQ(D_HA, req, "no reply for RESENT req (have "LPD64")",\
138 lcd->lcd_last_xid); \
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,
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);
171 int mds_get_parents_children_locked(struct obd_device *obd,
173 struct ll_fid *p1_fid,
174 struct dentry **de_srcdirp,
175 struct ll_fid *p2_fid,
176 struct dentry **de_tgtdirp,
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,
185 struct dentry *mds_lookup(struct obd_device *obd,
186 const char *fid_name,
187 struct dentry *dparent,
190 void mds_shrink_body_reply(struct ptlrpc_request *req, int req_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);
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,
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);
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);
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,
223 int mds_llog_finish(struct obd_device *obd, int count);
226 int mds_lov_connect(struct obd_device *obd, char * lov_name);
227 int mds_lov_disconnect(struct obd_device *obd);
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);
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_mds_md *lmm,
242 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
243 struct lov_mds_md *lmm, int lmm_size,
244 __u64 connect_flags);
245 int mds_init_lov_desc(struct obd_device *obd, struct obd_export *osc_exp);
248 int mds_query_write_access(struct inode *inode);
249 int mds_open(struct mds_update_record *rec, int offset,
250 struct ptlrpc_request *req, struct lustre_handle *);
251 int mds_pin(struct ptlrpc_request *req, int offset);
252 void mds_mfd_unlink(struct mds_file_data *mfd, int decref);
253 int mds_mfd_close(struct ptlrpc_request *req, int offset,struct obd_device *obd,
254 struct mds_file_data *mfd, int unlink_orphan,
255 struct lov_mds_md *lmm, int lmm_size,
256 struct llog_cookie *logcookies, int cookies_size,
258 int mds_close(struct ptlrpc_request *req, int offset);
259 int mds_done_writing(struct ptlrpc_request *req, int offset);
262 int mds_join_file(struct mds_update_record *rec, struct ptlrpc_request *req,
263 struct dentry *dchild, struct lustre_handle *lockh);
266 int mds_update_client_epoch(struct obd_export *exp);
267 void mds_update_last_epoch(struct obd_device *obd);
268 int mds_export_stats_init(struct obd_device *obd,
269 struct obd_export *exp,
272 int mds_client_add(struct obd_device *obd, struct obd_export *exp,
273 int cl_off, void *localdata);
274 int mds_client_free(struct obd_export *exp);
275 int mds_obd_create(struct obd_export *exp, struct obdo *oa,
276 struct lov_stripe_md **ea, struct obd_trans_info *oti);
277 int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
278 struct lov_stripe_md *ea, struct obd_trans_info *oti,
279 struct obd_export *md_exp);
282 extern struct lvfs_callback_ops mds_lvfs_ops;
283 extern int mds_iocontrol(unsigned int cmd, struct obd_export *exp,
284 int len, void *karg, void *uarg);
285 int mds_postrecov(struct obd_device *obd);
286 int mds_init_export(struct obd_export *exp);
288 int mds_get_md(struct obd_device *, struct inode *, void *md, int *size,
289 int lock, int flags, __u64 connect_flags);
290 int mds_pack_md(struct obd_device *, struct lustre_msg *, int offset,
291 struct mds_body *, struct inode *, int lock, int flags,
292 __u64 connect_flags);
293 void mds_pack_inode2body(struct mds_body *body, struct inode *inode);
295 int mds_pack_acl(struct mds_export_data *med, struct inode *inode,
296 struct lustre_msg *repmsg, struct mds_body *repbody,
300 extern quota_interface_t *mds_quota_interface_ref;
302 /* mds/mds_xattr.c */
303 int mds_setxattr(struct ptlrpc_request *req);
304 int mds_getxattr(struct ptlrpc_request *req);
306 /* mds/lproc_mds.c */
320 void mds_counter_incr(struct obd_export *exp, int opcode);
321 void mds_stats_counter_init(struct lprocfs_stats *stats);
322 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars);
323 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars);
324 #endif /* _MDS_INTERNAL_H */