Whamcloud - gitweb
b=20433 decrease the usage of memory on clients.
[fs/lustre-release.git] / lustre / include / lustre_mds.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  * lustre/include/lustre_mds.h
37  *
38  * MDS data structures.
39  * See also lustre_idl.h for wire formats of requests.
40  */
41
42 #ifndef _LUSTRE_MDS_H
43 #define _LUSTRE_MDS_H
44
45 #include <lustre_handles.h>
46 #include <libcfs/kp30.h>
47 #include <lustre/lustre_idl.h>
48 #include <lustre_lib.h>
49 #include <lustre_dlm.h>
50 #include <lustre_log.h>
51 #include <lustre_export.h>
52
53 #if defined(__linux__)
54 #include <linux/lustre_mds.h>
55 #elif defined(__APPLE__)
56 #include <darwin/lustre_mds.h>
57 #elif defined(__WINNT__)
58 #include <winnt/lustre_mds.h>
59 #else
60 #error Unsupported operating system.
61 #endif
62
63 struct ldlm_lock_desc;
64 struct mds_obd;
65 struct ptlrpc_connection;
66 struct ptlrpc_client;
67 struct obd_export;
68 struct ptlrpc_request;
69 struct obd_device;
70 struct ll_file_data;
71
72 struct lustre_md {
73         struct mds_body         *body;
74         struct lov_stripe_md    *lsm;
75 #ifdef CONFIG_FS_POSIX_ACL
76         struct posix_acl        *posix_acl;
77 #endif
78 };
79
80 struct mdc_op_data {
81         struct ll_fid    fid1;
82         struct ll_fid    fid2;
83         struct ll_fid    fid3;
84         struct ll_fid    fid4;
85         __u64            mod_time;
86         const char      *name;
87         int              namelen;
88         __u32            create_mode;
89         __u32            suppgids[2];
90         void            *data;
91 };
92
93 struct mds_update_record {
94         __u32 ur_opcode;
95         struct ll_fid *ur_fid1;
96         struct ll_fid *ur_fid2;
97         int ur_namelen;
98         char *ur_name;
99         int ur_tgtlen;
100         char *ur_tgt;
101         int ur_eadatalen;
102         void *ur_eadata;
103         int ur_cookielen;
104         struct llog_cookie *ur_logcookies;
105         struct iattr ur_iattr;
106         struct lvfs_ucred ur_uc;
107         __u64 ur_rdev;
108         __u64 ur_time;
109         __u32 ur_mode;
110         __u32 ur_flags;
111         struct lvfs_grp_hash_entry *ur_grp_entry;
112         struct ldlm_request *ur_dlm;
113 };
114
115 /* file data for open files on MDS */
116 struct mds_file_data {
117         struct portals_handle mfd_handle; /* must be first */
118         atomic_t              mfd_refcount;
119         struct list_head      mfd_list; /* protected by med_open_lock */
120         __u64                 mfd_xid;
121         int                   mfd_mode;
122         struct dentry        *mfd_dentry;
123 };
124
125 /* ACL */
126 #ifdef CONFIG_FS_POSIX_ACL
127 # ifdef HAVE_XATTR_ACL
128 #  define MDS_XATTR_NAME_ACL_ACCESS XATTR_NAME_ACL_ACCESS
129 #  define mds_xattr_acl_size(entry) xattr_acl_size(entry)
130 # else /* HAVE_XATTR_ACL */
131 #  define MDS_XATTR_NAME_ACL_ACCESS POSIX_ACL_XATTR_ACCESS
132 #  define mds_xattr_acl_size(entry) posix_acl_xattr_size(entry)
133 # endif /* HAVE_XATTR_ACL */
134
135 # define LUSTRE_POSIX_ACL_MAX_ENTRIES   (32)
136 #  define LUSTRE_POSIX_ACL_MAX_SIZE      \
137                 (mds_xattr_acl_size(LUSTRE_POSIX_ACL_MAX_ENTRIES))
138 #else /* CONFIG_FS_POSIX_ACL */
139 # define LUSTRE_POSIX_ACL_MAX_SIZE      0
140 #endif /* CONFIG_FS_POSIX_ACL */
141
142 /* mds/mds_reint.c */
143 int mds_reint_rec(struct mds_update_record *r, int offset,
144                   struct ptlrpc_request *req, struct lustre_handle *);
145
146 /* mds/handler.c */
147 static int inline ldlm_reply_disposition(struct ldlm_reply *rep, int flag)
148 {
149         return (rep ? rep->lock_policy_res1 & flag : 0);
150 }
151
152 static void inline ldlm_reply_set_disposition(struct ldlm_reply *rep, int flag)
153 {
154         if (rep)
155                 rep->lock_policy_res1 |= flag;
156 }
157
158 static void inline ldlm_reply_clear_disposition(struct ldlm_reply *rep,
159                                                 int flag)
160 {
161         if (rep)
162                 rep->lock_policy_res1 &= ~flag;
163 }
164
165 /* mdc/mdc_locks.c */
166 struct md_enqueue_info;
167
168 static int inline it_disposition(struct lookup_intent *it, int flag)
169 {
170         return it->d.lustre.it_disposition & flag;
171 }
172
173 static void inline it_set_disposition(struct lookup_intent *it, int flag)
174 {
175         it->d.lustre.it_disposition |= flag;
176 }
177
178 static inline void it_clear_disposition(struct lookup_intent *it, int flag)
179 {
180         it->d.lustre.it_disposition &= ~flag;
181 }
182
183 int it_open_error(int phase, struct lookup_intent *it);
184 void mdc_set_lock_data(__u64 *lockh, void *data, __u32 *lockbits);
185 int mdc_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
186                       ldlm_iterator_t it, void *data);
187 int mdc_find_cbdata(struct obd_export *exp, struct ll_fid *fid,
188                     ldlm_iterator_t it, void *data);
189 int mdc_revalidate_lock(struct obd_export *exp,
190                         struct lookup_intent *it,
191                         struct ll_fid *fid);
192 int mdc_intent_lock(struct obd_export *exp,
193                     struct mdc_op_data *,
194                     void *lmm, int lmmsize,
195                     struct lookup_intent *, int,
196                     struct ptlrpc_request **reqp,
197                     ldlm_blocking_callback cb_blocking, int extra_lock_flags);
198 int mdc_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
199                 struct lookup_intent *it, struct mdc_op_data *data,
200                 struct lustre_handle *lockh, void *lmm, int lmmlen,
201                 int extra_lock_flags);
202 int mdc_intent_getattr_async(struct obd_export *exp,
203                              struct md_enqueue_info *minfo,
204                              struct ldlm_enqueue_info *einfo);
205
206 /* mdc/mdc_request.c */
207 int mdc_init_ea_size(struct obd_export *mdc_exp, struct obd_export *lov_exp);
208 int mdc_req2lustre_md(struct ptlrpc_request *req, int offset,
209                       struct obd_export *exp, struct lustre_md *md);
210 void mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md);
211 int mdc_getstatus(struct obd_export *exp, struct ll_fid *rootfid);
212 int mdc_getattr(struct obd_export *exp, struct ll_fid *fid,
213                 obd_valid valid, unsigned int ea_size,
214                 struct ptlrpc_request **request);
215 int mdc_getattr_name(struct obd_export *exp, struct ll_fid *fid,
216                      const char *filename, int namelen, unsigned long valid,
217                      unsigned int ea_size, struct ptlrpc_request **request);
218 int mdc_setattr(struct obd_export *exp, struct mdc_op_data *data,
219                 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
220                 struct ptlrpc_request **request);
221 int mdc_setxattr(struct obd_export *exp, struct ll_fid *fid,
222                  obd_valid valid, const char *xattr_name,
223                  const char *input, int input_size,
224                  int output_size, int flags,
225                  struct ptlrpc_request **request);
226 int mdc_getxattr(struct obd_export *exp, struct ll_fid *fid,
227                  obd_valid valid, const char *xattr_name,
228                  const char *input, int input_size,
229                  int output_size, struct ptlrpc_request **request);
230 int mdc_open(struct obd_export *exp, obd_id ino, int type, int flags,
231              struct lov_mds_md *lmm, int lmm_size, struct lustre_handle *fh,
232              struct ptlrpc_request **);
233 struct obd_client_handle;
234 void mdc_set_open_replay_data(struct obd_client_handle *och,
235                               struct ptlrpc_request *open_req);
236 void mdc_clear_open_replay_data(struct obd_client_handle *och);
237 int mdc_close(struct obd_export *, struct mdc_op_data *, struct obdo *,
238               struct obd_client_handle *, struct ptlrpc_request **);
239 int mdc_readpage(struct obd_export *exp, struct ll_fid *mdc_fid, __u64 offset,
240                  struct page *, struct ptlrpc_request **);
241 int mdc_create(struct obd_export *exp, struct mdc_op_data *op_data,
242                const void *data, int datalen, int mode, __u32 uid, __u32 gid,
243                cfs_cap_t cap_effective, __u64 rdev,
244                struct ptlrpc_request **request);
245 int mdc_unlink(struct obd_export *exp, struct mdc_op_data *data,
246                struct ptlrpc_request **request);
247 int mdc_link(struct obd_export *exp, struct mdc_op_data *data,
248              struct ptlrpc_request **);
249 int mdc_rename(struct obd_export *exp, struct mdc_op_data *data,
250                const char *old, int oldlen, const char *new, int newlen,
251                struct ptlrpc_request **request);
252 int mdc_sync(struct obd_export *exp, struct ll_fid *fid,
253              struct ptlrpc_request **);
254 int mdc_create_client(struct obd_uuid uuid, struct ptlrpc_client *cl);
255 int mdc_resource_get_unused(struct obd_export *exp, struct ll_fid *fid,
256                             struct list_head *cancels, ldlm_mode_t mode,
257                             __u64 bits);
258
259 /* Store the generation of a newly-created inode in |req| for replay. */
260 void mdc_store_inode_generation(struct ptlrpc_request *req, int reqoff,
261                                 int repoff);
262 int mdc_llog_process(struct obd_export *, char *logname, llog_cb_t, void *data);
263 int mdc_done_writing(struct obd_export *, struct mdc_op_data *, struct obdo *);
264
265 static inline void ll_pack_fid(struct ll_fid *fid, obd_id ino, __u32 gen,
266                                int type)
267 {
268         fid->id = ino;
269         fid->generation = gen;
270         fid->f_type = type;
271 }
272
273 static inline int it_to_lock_mode(struct lookup_intent *it)
274 {
275         /* CREAT needs to be tested before open (both could be set) */
276         if (it->it_op & IT_CREAT)
277                 return LCK_CW;
278         else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP))
279                 return LCK_CR;
280
281         LBUG();
282         return -EINVAL;
283 }
284
285 /* ioctls for trying requests */
286 #define IOC_REQUEST_TYPE                   'f'
287 #define IOC_REQUEST_MIN_NR                 30
288
289 #define IOC_REQUEST_GETATTR             _IOWR('f', 30, long)
290 #define IOC_REQUEST_READPAGE            _IOWR('f', 31, long)
291 #define IOC_REQUEST_SETATTR             _IOWR('f', 32, long)
292 #define IOC_REQUEST_CREATE              _IOWR('f', 33, long)
293 #define IOC_REQUEST_OPEN                _IOWR('f', 34, long)
294 #define IOC_REQUEST_CLOSE               _IOWR('f', 35, long)
295 #define IOC_REQUEST_MAX_NR               35
296
297 /* metadata stat-ahead */
298 typedef int (* md_enqueue_cb_t)(struct obd_export *exp,
299                                 struct ptlrpc_request *req,
300                                 struct md_enqueue_info *minfo,
301                                 int rc);
302
303 struct md_enqueue_info {
304         struct mdc_op_data      mi_data;
305         struct lookup_intent    mi_it;
306         struct lustre_handle    mi_lockh;
307         struct dentry          *mi_dentry;
308         struct inode           *mi_dir;
309         md_enqueue_cb_t         mi_cb;
310         unsigned int            mi_generation;
311         void                   *mi_cbdata;
312 };
313
314 /* these are local flags, used only on the client, private */
315 #define M_CHECK_STALE           0200000000 
316 #define M_JOIN_FILE             0400000000 /* its counterpart is
317                                             * MDS_OPEN_JOIN_FILE */
318
319 #endif