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.
36 * lustre/include/lustre_mds.h
38 * MDS data structures.
39 * See also lustre_idl.h for wire formats of requests.
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>
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>
60 #error Unsupported operating system.
63 struct ldlm_lock_desc;
65 struct ptlrpc_connection;
68 struct ptlrpc_request;
73 struct mds_body *body;
74 struct lov_stripe_md *lsm;
75 #ifdef CONFIG_FS_POSIX_ACL
76 struct posix_acl *posix_acl;
93 struct mds_update_record {
95 struct ll_fid *ur_fid1;
96 struct ll_fid *ur_fid2;
104 struct llog_cookie *ur_logcookies;
105 struct iattr ur_iattr;
106 struct lvfs_ucred ur_uc;
111 struct lvfs_grp_hash_entry *ur_grp_entry;
112 struct ldlm_request *ur_dlm;
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 */
122 struct dentry *mfd_dentry;
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 */
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 */
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 *);
147 static int inline ldlm_reply_disposition(struct ldlm_reply *rep, int flag)
149 return (rep ? rep->lock_policy_res1 & flag : 0);
152 static void inline ldlm_reply_set_disposition(struct ldlm_reply *rep, int flag)
155 rep->lock_policy_res1 |= flag;
158 static void inline ldlm_reply_clear_disposition(struct ldlm_reply *rep,
162 rep->lock_policy_res1 &= ~flag;
165 /* mdc/mdc_locks.c */
166 struct md_enqueue_info;
168 static int inline it_disposition(struct lookup_intent *it, int flag)
170 return it->d.lustre.it_disposition & flag;
173 static void inline it_set_disposition(struct lookup_intent *it, int flag)
175 it->d.lustre.it_disposition |= flag;
178 static inline void it_clear_disposition(struct lookup_intent *it, int flag)
180 it->d.lustre.it_disposition &= ~flag;
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_revalidate_lock(struct obd_export *exp,
188 struct lookup_intent *it,
190 int mdc_intent_lock(struct obd_export *exp,
191 struct mdc_op_data *,
192 void *lmm, int lmmsize,
193 struct lookup_intent *, int,
194 struct ptlrpc_request **reqp,
195 ldlm_blocking_callback cb_blocking, int extra_lock_flags);
196 int mdc_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
197 struct lookup_intent *it, struct mdc_op_data *data,
198 struct lustre_handle *lockh, void *lmm, int lmmlen,
199 int extra_lock_flags);
200 int mdc_intent_getattr_async(struct obd_export *exp,
201 struct md_enqueue_info *minfo,
202 struct ldlm_enqueue_info *einfo);
204 /* mdc/mdc_request.c */
205 int mdc_init_ea_size(struct obd_export *mdc_exp, struct obd_export *lov_exp);
206 int mdc_req2lustre_md(struct ptlrpc_request *req, int offset,
207 struct obd_export *exp, struct lustre_md *md);
208 void mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md);
209 int mdc_getstatus(struct obd_export *exp, struct ll_fid *rootfid);
210 int mdc_getattr(struct obd_export *exp, struct ll_fid *fid,
211 obd_valid valid, unsigned int ea_size,
212 struct ptlrpc_request **request);
213 int mdc_getattr_name(struct obd_export *exp, struct ll_fid *fid,
214 const char *filename, int namelen, unsigned long valid,
215 unsigned int ea_size, struct ptlrpc_request **request);
216 int mdc_setattr(struct obd_export *exp, struct mdc_op_data *data,
217 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
218 struct ptlrpc_request **request);
219 int mdc_setxattr(struct obd_export *exp, struct ll_fid *fid,
220 obd_valid valid, const char *xattr_name,
221 const char *input, int input_size,
222 int output_size, int flags,
223 struct ptlrpc_request **request);
224 int mdc_getxattr(struct obd_export *exp, struct ll_fid *fid,
225 obd_valid valid, const char *xattr_name,
226 const char *input, int input_size,
227 int output_size, struct ptlrpc_request **request);
228 int mdc_open(struct obd_export *exp, obd_id ino, int type, int flags,
229 struct lov_mds_md *lmm, int lmm_size, struct lustre_handle *fh,
230 struct ptlrpc_request **);
231 struct obd_client_handle;
232 void mdc_set_open_replay_data(struct obd_client_handle *och,
233 struct ptlrpc_request *open_req);
234 void mdc_clear_open_replay_data(struct obd_client_handle *och);
235 int mdc_close(struct obd_export *, struct mdc_op_data *, struct obdo *,
236 struct obd_client_handle *, struct ptlrpc_request **);
237 int mdc_readpage(struct obd_export *exp, struct ll_fid *mdc_fid, __u64 offset,
238 struct page *, struct ptlrpc_request **);
239 int mdc_create(struct obd_export *exp, struct mdc_op_data *op_data,
240 const void *data, int datalen, int mode, __u32 uid, __u32 gid,
241 cfs_cap_t cap_effective, __u64 rdev,
242 struct ptlrpc_request **request);
243 int mdc_unlink(struct obd_export *exp, struct mdc_op_data *data,
244 struct ptlrpc_request **request);
245 int mdc_link(struct obd_export *exp, struct mdc_op_data *data,
246 struct ptlrpc_request **);
247 int mdc_rename(struct obd_export *exp, struct mdc_op_data *data,
248 const char *old, int oldlen, const char *new, int newlen,
249 struct ptlrpc_request **request);
250 int mdc_sync(struct obd_export *exp, struct ll_fid *fid,
251 struct ptlrpc_request **);
252 int mdc_create_client(struct obd_uuid uuid, struct ptlrpc_client *cl);
253 int mdc_resource_get_unused(struct obd_export *exp, struct ll_fid *fid,
254 struct list_head *cancels, ldlm_mode_t mode,
257 /* Store the generation of a newly-created inode in |req| for replay. */
258 void mdc_store_inode_generation(struct ptlrpc_request *req, int reqoff,
260 int mdc_llog_process(struct obd_export *, char *logname, llog_cb_t, void *data);
261 int mdc_done_writing(struct obd_export *, struct mdc_op_data *, struct obdo *);
263 static inline void ll_pack_fid(struct ll_fid *fid, obd_id ino, __u32 gen,
267 fid->generation = gen;
271 static inline int it_to_lock_mode(struct lookup_intent *it)
273 /* CREAT needs to be tested before open (both could be set) */
274 if (it->it_op & IT_CREAT)
276 else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP))
283 /* ioctls for trying requests */
284 #define IOC_REQUEST_TYPE 'f'
285 #define IOC_REQUEST_MIN_NR 30
287 #define IOC_REQUEST_GETATTR _IOWR('f', 30, long)
288 #define IOC_REQUEST_READPAGE _IOWR('f', 31, long)
289 #define IOC_REQUEST_SETATTR _IOWR('f', 32, long)
290 #define IOC_REQUEST_CREATE _IOWR('f', 33, long)
291 #define IOC_REQUEST_OPEN _IOWR('f', 34, long)
292 #define IOC_REQUEST_CLOSE _IOWR('f', 35, long)
293 #define IOC_REQUEST_MAX_NR 35
295 /* metadata stat-ahead */
296 typedef int (* md_enqueue_cb_t)(struct obd_export *exp,
297 struct ptlrpc_request *req,
298 struct md_enqueue_info *minfo,
301 struct md_enqueue_info {
302 struct mdc_op_data mi_data;
303 struct lookup_intent mi_it;
304 struct lustre_handle mi_lockh;
305 struct dentry *mi_dentry;
306 struct inode *mi_dir;
307 md_enqueue_cb_t mi_cb;
308 unsigned int mi_generation;
312 /* these are local flags, used only on the client, private */
313 #define M_CHECK_STALE 0200000000
314 #define M_JOIN_FILE 0400000000 /* its counterpart is
315 * MDS_OPEN_JOIN_FILE */