1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc. <info@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * MDS data structures.
22 * See also lustre_idl.h for wire formats of requests.
30 # include <linux/fs.h>
31 # include <linux/dcache.h>
33 #include <linux/lustre_handles.h>
34 #include <linux/kp30.h>
35 #include <linux/lustre_idl.h>
36 #include <linux/lustre_lib.h>
37 #include <linux/lustre_dlm.h>
39 struct ldlm_lock_desc;
41 struct ptlrpc_connection;
44 struct ptlrpc_request;
48 #define LUSTRE_MDS_NAME "mds"
49 #define LUSTRE_MDT_NAME "mdt"
50 #define LUSTRE_MDC_NAME "mdc"
53 struct semaphore rpcl_sem;
54 struct lookup_intent *rpcl_it;
56 extern struct mdc_rpc_lock mdc_rpc_lock;
57 extern struct mdc_rpc_lock mdc_setattr_lock;
59 static inline void mdc_init_rpc_lock(struct mdc_rpc_lock *lck)
61 sema_init(&lck->rpcl_sem, 1);
66 /* Compat code for kernel patch v18 users, can be removed when everyone has
67 * upgraded --phik 02 June 2003 */
69 static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck,
70 struct lookup_intent *it)
75 it->it_int_flags |= IT_FL_LOCKED;
79 static inline void mdc_put_rpc_lock(struct mdc_rpc_lock *lck,
80 struct lookup_intent *it)
83 LASSERT(it == lck->rpcl_it);
87 if (it != NULL && (it->it_int_flags & IT_FL_LOCKED)) {
88 it->it_int_flags &= ~IT_FL_LOCKED;
89 LASSERT(it == lck->rpcl_it);
95 static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck,
96 struct lookup_intent *it)
101 it->it_iattr = (void *)1;
105 static inline void mdc_put_rpc_lock(struct mdc_rpc_lock *lck,
106 struct lookup_intent *it)
109 LASSERT(it == lck->rpcl_it);
113 if (it && it->it_iattr) {
115 LASSERT(it == lck->rpcl_it);
137 struct mds_update_record {
139 struct ll_fid *ur_fid1;
140 struct ll_fid *ur_fid2;
147 struct iattr ur_iattr;
148 struct obd_ucred ur_uc;
157 #define ur_fsuid ur_uc.ouc_fsuid
158 #define ur_fsgid ur_uc.ouc_fsgid
159 #define ur_cap ur_uc.ouc_cap
160 #define ur_suppgid1 ur_uc.ouc_suppgid1
161 #define ur_suppgid2 ur_uc.ouc_suppgid2
163 #define MDS_LR_CLIENT 8192
164 #define MDS_LR_SIZE 128
166 #define MDS_CLIENT_SLOTS 17
168 #define MDS_MOUNT_RECOV 2
170 /* Data stored per server at the head of the last_rcvd file. In le32 order. */
171 struct mds_server_data {
172 __u8 msd_uuid[37]; /* server UUID */
173 __u8 uuid_padding[3]; /* unused */
174 __u64 msd_last_transno; /* last completed transaction ID */
175 __u64 msd_mount_count; /* MDS incarnation number */
176 __u8 padding[512 - 56];
179 /* Data stored per client in the last_rcvd file. In le32 order. */
180 struct mds_client_data {
181 __u8 mcd_uuid[37]; /* client UUID */
182 __u8 uuid_padding[3]; /* unused */
183 __u64 mcd_mount_count; /* MDS incarnation number */
184 __u64 mcd_last_transno; /* last completed transaction ID */
185 __u64 mcd_last_xid; /* xid for the last transaction */
186 __u32 mcd_last_result; /* result from last RPC */
187 __u32 mcd_last_data; /* per-op data (disposition for open &c.) */
188 __u8 padding[MDS_LR_SIZE - 74];
191 /* file data for open files on MDS */
192 struct mds_file_data {
193 struct portals_handle mfd_handle; /* must be first */
194 atomic_t mfd_refcount;
195 struct list_head mfd_list;
198 struct dentry *mfd_dentry;
201 /* mds/mds_reint.c */
202 int mds_reint_rec(struct mds_update_record *r, int offset,
203 struct ptlrpc_request *req, struct lustre_handle *);
206 int mds_open(struct mds_update_record *rec, int offset,
207 struct ptlrpc_request *req, struct lustre_handle *);
211 struct dentry *mds_name2locked_dentry(struct obd_device *, struct dentry *dir,
212 struct vfsmount **mnt, char *name,
213 int namelen, int lock_mode,
214 struct lustre_handle *lockh,
216 struct dentry *mds_fid2locked_dentry(struct obd_device *obd, struct ll_fid *fid,
217 struct vfsmount **mnt, int lock_mode,
218 struct lustre_handle *lockh);
219 struct dentry *mds_fid2dentry(struct mds_obd *mds, struct ll_fid *fid,
220 struct vfsmount **mnt);
221 int mds_reint(struct ptlrpc_request *req, int offset, struct lustre_handle *);
222 int mds_pack_md(struct obd_device *mds, struct lustre_msg *msg,
223 int offset, struct mds_body *body, struct inode *inode);
224 void mds_steal_ack_locks(struct obd_export *exp,
225 struct ptlrpc_request *req);
228 int mds_fs_setup(struct obd_device *obddev, struct vfsmount *mnt);
229 int mds_fs_cleanup(struct obd_device *obddev, int failover);
232 /* mdc/mdc_request.c */
233 int mdc_enqueue(struct lustre_handle *conn, int lock_type,
234 struct lookup_intent *it, int lock_mode,
235 struct mdc_op_data *enq_data,
236 struct lustre_handle *lockh, char *tgt, int tgtlen,
237 ldlm_completion_callback cb_completion,
238 ldlm_blocking_callback cb_blocking,
240 int mdc_getlovinfo(struct obd_device *obd, struct lustre_handle *mdc_connh,
241 struct ptlrpc_request **request);
242 int mdc_getstatus(struct lustre_handle *conn, struct ll_fid *rootfid);
243 int mdc_getattr(struct lustre_handle *conn, struct ll_fid *fid,
244 unsigned long valid, unsigned int ea_size,
245 struct ptlrpc_request **request);
246 int mdc_getattr_name(struct lustre_handle *conn, struct ll_fid *fid,
247 char *filename, int namelen, unsigned long valid,
248 unsigned int ea_size, struct ptlrpc_request **request);
249 int mdc_setattr(struct lustre_handle *conn,
250 struct mdc_op_data *data,
251 struct iattr *iattr, void *ea, int ealen,
252 struct ptlrpc_request **request);
253 int mdc_open(struct lustre_handle *conn, obd_id ino, int type, int flags,
254 struct lov_mds_md *lmm, int lmm_size, struct lustre_handle *fh,
255 struct ptlrpc_request **);
256 struct obd_client_handle;
257 void mdc_set_open_replay_data(struct obd_client_handle *och);
258 int mdc_close(struct lustre_handle *conn, obd_id ino, int type,
259 struct lustre_handle *fh, struct ptlrpc_request **req);
260 int mdc_readpage(struct lustre_handle *conn, obd_id ino, int type, __u64 offset,
261 struct page *, struct ptlrpc_request **);
262 int mdc_create(struct lustre_handle *conn, struct mdc_op_data *op_data,
263 const void *data, int datalen, int mode, __u32 uid, __u32 gid,
264 __u64 time, __u64 rdev, struct ptlrpc_request **request);
265 int mdc_unlink(struct lustre_handle *conn, struct mdc_op_data *data,
266 struct ptlrpc_request **request);
267 int mdc_link(struct lustre_handle *conn, struct mdc_op_data *data,
268 struct ptlrpc_request **);
269 int mdc_rename(struct lustre_handle *conn, struct mdc_op_data *data,
270 const char *old, int oldlen, const char *new, int newlen,
271 struct ptlrpc_request **request);
272 int mdc_create_client(struct obd_uuid uuid, struct ptlrpc_client *cl);
274 /* Store the generation of a newly-created inode in |req| for replay. */
275 void mdc_store_inode_generation(struct ptlrpc_request *req, int reqoff,
279 /* ioctls for trying requests */
280 #define IOC_REQUEST_TYPE 'f'
281 #define IOC_REQUEST_MIN_NR 30
283 #define IOC_REQUEST_GETATTR _IOWR('f', 30, long)
284 #define IOC_REQUEST_READPAGE _IOWR('f', 31, long)
285 #define IOC_REQUEST_SETATTR _IOWR('f', 32, long)
286 #define IOC_REQUEST_CREATE _IOWR('f', 33, long)
287 #define IOC_REQUEST_OPEN _IOWR('f', 34, long)
288 #define IOC_REQUEST_CLOSE _IOWR('f', 35, long)
289 #define IOC_REQUEST_MAX_NR 35
291 #define MDS_CHECK_RESENT(req, reconstruct) \
293 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) { \
294 struct mds_client_data *mcd = \
295 req->rq_export->exp_mds_data.med_mcd; \
296 if (mcd->mcd_last_xid == req->rq_xid) { \
300 DEBUG_REQ(D_HA, req, "no reply for RESENT req (have "LPD64")", \
301 mcd->mcd_last_xid); \