4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * Copyright (c) 2011, 2012, Intel Corporation.
34 * This file is part of Lustre, http://www.lustre.org/
35 * Lustre is a trademark of Sun Microsystems, Inc.
37 * lustre/include/lustre_mdc.h
39 * MDS data structures.
40 * See also lustre_idl.h for wire formats of requests.
52 # include <linux/fs.h>
53 # include <linux/dcache.h>
54 # ifdef CONFIG_FS_POSIX_ACL
55 # include <linux/posix_acl_xattr.h>
56 # endif /* CONFIG_FS_POSIX_ACL */
57 # include <linux/lustre_intent.h>
58 #endif /* __KERNEL__ */
59 #include <lustre_handles.h>
60 #include <libcfs/libcfs.h>
61 #include <obd_class.h>
62 #include <lustre/lustre_idl.h>
63 #include <lustre_lib.h>
64 #include <lustre_dlm.h>
65 #include <lustre_export.h>
69 struct ptlrpc_request;
73 struct mutex rpcl_mutex;
74 struct lookup_intent *rpcl_it;
78 #define MDC_FAKE_RPCL_IT ((void *)0x2c0012bfUL)
80 static inline void mdc_init_rpc_lock(struct mdc_rpc_lock *lck)
82 mutex_init(&lck->rpcl_mutex);
86 static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck,
87 struct lookup_intent *it)
91 if (it != NULL && (it->it_op == IT_GETATTR || it->it_op == IT_LOOKUP ||
92 it->it_op == IT_LAYOUT))
95 /* This would normally block until the existing request finishes.
96 * If fail_loc is set it will block until the regular request is
97 * done, then set rpcl_it to MDC_FAKE_RPCL_IT. Once that is set
98 * it will only be cleared when all fake requests are finished.
99 * Only when all fake requests are finished can normal requests
100 * be sent, to ensure they are recoverable again. */
102 mutex_lock(&lck->rpcl_mutex);
104 if (CFS_FAIL_CHECK_QUIET(OBD_FAIL_MDC_RPCS_SEM)) {
105 lck->rpcl_it = MDC_FAKE_RPCL_IT;
107 mutex_unlock(&lck->rpcl_mutex);
111 /* This will only happen when the CFS_FAIL_CHECK() was
112 * just turned off but there are still requests in progress.
113 * Wait until they finish. It doesn't need to be efficient
114 * in this extremely rare case, just have low overhead in
115 * the common case when it isn't true. */
116 while (unlikely(lck->rpcl_it == MDC_FAKE_RPCL_IT)) {
117 mutex_unlock(&lck->rpcl_mutex);
118 cfs_schedule_timeout(cfs_time_seconds(1) / 4);
122 LASSERT(lck->rpcl_it == NULL);
126 static inline void mdc_put_rpc_lock(struct mdc_rpc_lock *lck,
127 struct lookup_intent *it)
129 if (it != NULL && (it->it_op == IT_GETATTR || it->it_op == IT_LOOKUP ||
130 it->it_op == IT_LAYOUT))
133 if (lck->rpcl_it == MDC_FAKE_RPCL_IT) { /* OBD_FAIL_MDC_RPCS_SEM */
134 mutex_lock(&lck->rpcl_mutex);
136 LASSERTF(lck->rpcl_fakes > 0, "%d\n", lck->rpcl_fakes);
139 if (lck->rpcl_fakes == 0)
143 LASSERTF(it == lck->rpcl_it, "%p != %p\n", it, lck->rpcl_it);
147 mutex_unlock(&lck->rpcl_mutex);
152 static inline void mdc_update_max_ea_from_body(struct obd_export *exp,
153 struct mdt_body *body)
155 if (body->valid & OBD_MD_FLMODEASIZE) {
156 if (exp->exp_obd->u.cli.cl_max_mds_easize < body->max_mdsize)
157 exp->exp_obd->u.cli.cl_max_mds_easize =
159 if (exp->exp_obd->u.cli.cl_max_mds_cookiesize <
160 body->max_cookiesize)
161 exp->exp_obd->u.cli.cl_max_mds_cookiesize =
162 body->max_cookiesize;
167 struct mdc_cache_waiter {
168 cfs_list_t mcw_entry;
169 cfs_waitq_t mcw_waitq;
172 /* mdc/mdc_locks.c */
173 int it_disposition(struct lookup_intent *it, int flag);
174 void it_clear_disposition(struct lookup_intent *it, int flag);
175 void it_set_disposition(struct lookup_intent *it, int flag);
176 int it_open_error(int phase, struct lookup_intent *it);
177 #ifdef HAVE_SPLIT_SUPPORT
178 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
179 const struct page *page, int offset);