Whamcloud - gitweb
Land b1_8_gate onto b1_8 (20081218_1708)
[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/mds_lov.c */
147
148 /* mdc/mdc_locks.c */
149 struct md_enqueue_info;
150
151 int it_disposition(struct lookup_intent *it, int flag);
152 void it_set_disposition(struct lookup_intent *it, int flag);
153 void it_clear_disposition(struct lookup_intent *it, int flag);
154 int it_open_error(int phase, struct lookup_intent *it);
155 void mdc_set_lock_data(__u64 *lockh, void *data);
156 int mdc_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
157                       ldlm_iterator_t it, void *data);
158 int mdc_revalidate_lock(struct obd_export *exp,
159                         struct lookup_intent *it,
160                         struct ll_fid *fid);
161 int mdc_intent_lock(struct obd_export *exp,
162                     struct mdc_op_data *,
163                     void *lmm, int lmmsize,
164                     struct lookup_intent *, int,
165                     struct ptlrpc_request **reqp,
166                     ldlm_blocking_callback cb_blocking, int extra_lock_flags);
167 int mdc_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
168                 struct lookup_intent *it, struct mdc_op_data *data,
169                 struct lustre_handle *lockh, void *lmm, int lmmlen,
170                 int extra_lock_flags);
171 int mdc_intent_getattr_async(struct obd_export *exp,
172                              struct md_enqueue_info *minfo,
173                              struct ldlm_enqueue_info *einfo);
174
175 /* mdc/mdc_request.c */
176 int mdc_init_ea_size(struct obd_export *mdc_exp, struct obd_export *lov_exp);
177 int mdc_req2lustre_md(struct ptlrpc_request *req, int offset,
178                       struct obd_export *exp, struct lustre_md *md);
179 void mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md);
180 int mdc_getstatus(struct obd_export *exp, struct ll_fid *rootfid);
181 int mdc_getattr(struct obd_export *exp, struct ll_fid *fid,
182                 obd_valid valid, unsigned int ea_size,
183                 struct ptlrpc_request **request);
184 int mdc_getattr_name(struct obd_export *exp, struct ll_fid *fid,
185                      const char *filename, int namelen, unsigned long valid,
186                      unsigned int ea_size, struct ptlrpc_request **request);
187 int mdc_setattr(struct obd_export *exp, struct mdc_op_data *data,
188                 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
189                 struct ptlrpc_request **request);
190 int mdc_setxattr(struct obd_export *exp, struct ll_fid *fid,
191                  obd_valid valid, const char *xattr_name,
192                  const char *input, int input_size,
193                  int output_size, int flags,
194                  struct ptlrpc_request **request);
195 int mdc_getxattr(struct obd_export *exp, struct ll_fid *fid,
196                  obd_valid valid, const char *xattr_name,
197                  const char *input, int input_size,
198                  int output_size, struct ptlrpc_request **request);
199 int mdc_open(struct obd_export *exp, obd_id ino, int type, int flags,
200              struct lov_mds_md *lmm, int lmm_size, struct lustre_handle *fh,
201              struct ptlrpc_request **);
202 struct obd_client_handle;
203 void mdc_set_open_replay_data(struct obd_client_handle *och,
204                               struct ptlrpc_request *open_req);
205 void mdc_clear_open_replay_data(struct obd_client_handle *och);
206 int mdc_close(struct obd_export *, struct mdc_op_data *, struct obdo *,
207               struct obd_client_handle *, struct ptlrpc_request **);
208 int mdc_readpage(struct obd_export *exp, struct ll_fid *mdc_fid, __u64 offset,
209                  struct page *, struct ptlrpc_request **);
210 int mdc_create(struct obd_export *exp, struct mdc_op_data *op_data,
211                const void *data, int datalen, int mode, __u32 uid, __u32 gid,
212                cfs_cap_t cap_effective, __u64 rdev,
213                struct ptlrpc_request **request);
214 int mdc_unlink(struct obd_export *exp, struct mdc_op_data *data,
215                struct ptlrpc_request **request);
216 int mdc_link(struct obd_export *exp, struct mdc_op_data *data,
217              struct ptlrpc_request **);
218 int mdc_rename(struct obd_export *exp, struct mdc_op_data *data,
219                const char *old, int oldlen, const char *new, int newlen,
220                struct ptlrpc_request **request);
221 int mdc_sync(struct obd_export *exp, struct ll_fid *fid,
222              struct ptlrpc_request **);
223 int mdc_create_client(struct obd_uuid uuid, struct ptlrpc_client *cl);
224 int mdc_resource_get_unused(struct obd_export *exp, struct ll_fid *fid,
225                             struct list_head *cancels, ldlm_mode_t mode,
226                             __u64 bits);
227
228 /* Store the generation of a newly-created inode in |req| for replay. */
229 void mdc_store_inode_generation(struct ptlrpc_request *req, int reqoff,
230                                 int repoff);
231 int mdc_llog_process(struct obd_export *, char *logname, llog_cb_t, void *data);
232 int mdc_done_writing(struct obd_export *, struct mdc_op_data *, struct obdo *);
233
234 static inline void ll_pack_fid(struct ll_fid *fid, obd_id ino, __u32 gen,
235                                int type)
236 {
237         fid->id = ino;
238         fid->generation = gen;
239         fid->f_type = type;
240 }
241
242 static inline int it_to_lock_mode(struct lookup_intent *it)
243 {
244         /* CREAT needs to be tested before open (both could be set) */
245         if (it->it_op & IT_CREAT)
246                 return LCK_CW;
247         else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP))
248                 return LCK_CR;
249
250         LBUG();
251         return -EINVAL;
252 }
253
254 /* ioctls for trying requests */
255 #define IOC_REQUEST_TYPE                   'f'
256 #define IOC_REQUEST_MIN_NR                 30
257
258 #define IOC_REQUEST_GETATTR             _IOWR('f', 30, long)
259 #define IOC_REQUEST_READPAGE            _IOWR('f', 31, long)
260 #define IOC_REQUEST_SETATTR             _IOWR('f', 32, long)
261 #define IOC_REQUEST_CREATE              _IOWR('f', 33, long)
262 #define IOC_REQUEST_OPEN                _IOWR('f', 34, long)
263 #define IOC_REQUEST_CLOSE               _IOWR('f', 35, long)
264 #define IOC_REQUEST_MAX_NR               35
265
266 /* metadata stat-ahead */
267 typedef int (* md_enqueue_cb_t)(struct obd_export *exp,
268                                 struct ptlrpc_request *req,
269                                 struct md_enqueue_info *minfo,
270                                 int rc);
271
272 struct md_enqueue_info {
273         struct mdc_op_data      mi_data;
274         struct lookup_intent    mi_it;
275         struct lustre_handle    mi_lockh;
276         struct dentry          *mi_dentry;
277         md_enqueue_cb_t         mi_cb;
278         unsigned int            mi_generation;
279         void                   *mi_cbdata;
280 };
281
282 #endif