Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[fs/lustre-release.git] / lustre / include / linux / lustre_mds.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001-2003 Cluster File Systems, Inc. <info@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  *
21  * MDS data structures.
22  * See also lustre_idl.h for wire formats of requests.
23  *
24  */
25
26 #ifndef _LUSTRE_MDS_H
27 #define _LUSTRE_MDS_H
28
29 #ifdef __KERNEL__
30 # include <linux/fs.h>
31 # include <linux/dcache.h>
32 #endif
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>
38
39 struct ldlm_lock_desc;
40 struct mds_obd;
41 struct ptlrpc_connection;
42 struct ptlrpc_client;
43 struct obd_export;
44 struct ptlrpc_request;
45 struct obd_device;
46 struct ll_file_data;
47
48 #define LUSTRE_MDS_NAME "mds"
49 #define LUSTRE_MDT_NAME "mdt"
50 #define LUSTRE_MDC_NAME "mdc"
51
52 struct mdc_rpc_lock {
53         struct semaphore rpcl_sem;
54         struct lookup_intent *rpcl_it;
55 };
56 extern struct mdc_rpc_lock mdc_rpc_lock;
57 extern struct mdc_rpc_lock mdc_setattr_lock;
58
59 static inline void mdc_init_rpc_lock(struct mdc_rpc_lock *lck)
60 {
61         sema_init(&lck->rpcl_sem, 1);
62         lck->rpcl_it = NULL;
63 }
64
65 #ifdef __KERNEL__
66 /* Compat code for kernel patch v18 users, can be removed when everyone has
67  * upgraded --phik 02 June 2003 */
68 #ifdef IT_FL_LOCKED
69 static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck, 
70                                     struct lookup_intent *it)
71 {
72         down(&lck->rpcl_sem);
73         if (it) { 
74                 lck->rpcl_it = it;
75                 it->it_int_flags |= IT_FL_LOCKED;
76         }
77 }
78
79 static inline void mdc_put_rpc_lock(struct mdc_rpc_lock *lck, 
80                                     struct lookup_intent *it)
81 {
82         if (it == NULL) {
83                 LASSERT(it == lck->rpcl_it);
84                 up(&lck->rpcl_sem);
85                 return;
86         }
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);
90                 lck->rpcl_it = NULL;
91                 up(&lck->rpcl_sem);
92         }
93 }
94 #else
95 static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck, 
96                                     struct lookup_intent *it)
97 {
98         down(&lck->rpcl_sem);
99         if (it) { 
100                 lck->rpcl_it = it;
101                 it->it_iattr = (void *)1;
102         }
103 }
104
105 static inline void mdc_put_rpc_lock(struct mdc_rpc_lock *lck, 
106                                     struct lookup_intent *it)
107 {
108         if (it == NULL) {
109                 LASSERT(it == lck->rpcl_it);
110                 up(&lck->rpcl_sem);
111                 return;
112         }
113         if (it && it->it_iattr) {
114                 it->it_iattr = NULL;
115                 LASSERT(it == lck->rpcl_it);
116                 lck->rpcl_it = NULL;
117                 up(&lck->rpcl_sem);
118         }
119 }
120 #endif
121 #endif
122
123 struct mdc_op_data {
124         __u64   ino1;
125         __u32   gen1;
126         __u32   typ1;
127         __u32   gid1;
128         __u64   ino2;
129         __u32   gen2;
130         __u32   typ2;
131         __u32   gid2;
132         const char *name;
133         int     namelen;
134         int     mode;
135 };
136
137 struct mds_update_record {
138         __u32 ur_opcode;
139         struct ll_fid *ur_fid1;
140         struct ll_fid *ur_fid2;
141         int ur_namelen;
142         char *ur_name;
143         int ur_tgtlen;
144         char *ur_tgt;
145         int ur_eadatalen;
146         void *ur_eadata;
147         struct iattr ur_iattr;
148         struct obd_ucred ur_uc;
149         __u64 ur_rdev;
150         __u32 ur_mode;
151         __u32 ur_uid;
152         __u32 ur_gid;
153         __u64 ur_time;
154         __u32 ur_flags;
155 };
156
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
162
163 #define MDS_LR_CLIENT  8192
164 #define MDS_LR_SIZE     128
165
166 #define MDS_CLIENT_SLOTS 17
167
168 #define MDS_MOUNT_RECOV 2
169
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];
177 };
178
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];
189 };
190
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;
196         __u64                 mfd_xid;
197         int                   mfd_mode;
198         struct dentry        *mfd_dentry;
199 };
200
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 *);
204
205 /* mds/mds_open.c */
206 int mds_open(struct mds_update_record *rec, int offset,
207              struct ptlrpc_request *req, struct lustre_handle *);
208
209 /* mds/handler.c */
210 #ifdef __KERNEL__
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,
215                                       int dir_lock_mode);
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);
226
227 /* mds/mds_fs.c */
228 int mds_fs_setup(struct obd_device *obddev, struct vfsmount *mnt);
229 int mds_fs_cleanup(struct obd_device *obddev, int failover);
230 #endif
231
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,
239                 void *cb_data);
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);
273
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,
276                                 int repoff);
277
278
279 /* ioctls for trying requests */
280 #define IOC_REQUEST_TYPE                   'f'
281 #define IOC_REQUEST_MIN_NR                 30
282
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
290
291 #define MDS_CHECK_RESENT(req, reconstruct)                                     \
292 {                                                                              \
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) {                        \
297                         reconstruct;                                           \
298                         RETURN(0);                                             \
299                 }                                                              \
300                 DEBUG_REQ(D_HA, req, "no reply for RESENT req (have "LPD64")", \
301                           mcd->mcd_last_xid);                                  \
302         }                                                                      \
303 }
304
305 #endif