Whamcloud - gitweb
LU-2675 mdt: add mbo_ prefix to members of struct mdt_body
[fs/lustre-release.git] / lustre / include / lustre_mdc.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * Copyright (c) 2011, 2012, Intel Corporation.
32  */
33 /*
34  * This file is part of Lustre, http://www.lustre.org/
35  * Lustre is a trademark of Sun Microsystems, Inc.
36  *
37  * lustre/include/lustre_mdc.h
38  *
39  * MDS data structures.
40  * See also lustre_idl.h for wire formats of requests.
41  */
42
43 #ifndef _LUSTRE_MDC_H
44 #define _LUSTRE_MDC_H
45
46 /** \defgroup mdc mdc
47  *
48  * @{
49  */
50
51 #ifdef __KERNEL__
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>
66
67 struct ptlrpc_client;
68 struct obd_export;
69 struct ptlrpc_request;
70 struct obd_device;
71
72 /**
73  * Serializes in-flight MDT-modifying RPC requests to preserve idempotency.
74  *
75  * This mutex is used to implement execute-once semantics on the MDT.
76  * The MDT stores the last transaction ID and result for every client in
77  * its last_rcvd file. If the client doesn't get a reply, it can safely
78  * resend the request and the MDT will reconstruct the reply being aware
79  * that the request has already been executed. Without this lock,
80  * execution status of concurrent in-flight requests would be
81  * overwritten.
82  *
83  * This design limits the extent to which we can keep a full pipeline of
84  * in-flight requests from a single client.  This limitation could be
85  * overcome by allowing multiple slots per client in the last_rcvd file.
86  */
87 struct mdc_rpc_lock {
88         /** Lock protecting in-flight RPC concurrency. */
89         struct mutex            rpcl_mutex;
90         /** Intent associated with currently executing request. */
91         struct lookup_intent    *rpcl_it;
92         /** Used for MDS/RPC load testing purposes. */
93         int                     rpcl_fakes;
94 };
95
96 #define MDC_FAKE_RPCL_IT ((void *)0x2c0012bfUL)
97
98 static inline void mdc_init_rpc_lock(struct mdc_rpc_lock *lck)
99 {
100         mutex_init(&lck->rpcl_mutex);
101         lck->rpcl_it = NULL;
102 }
103
104 static inline void mdc_get_rpc_lock(struct mdc_rpc_lock *lck,
105                                     struct lookup_intent *it)
106 {
107         ENTRY;
108
109         if (it != NULL && (it->it_op == IT_GETATTR || it->it_op == IT_LOOKUP ||
110                            it->it_op == IT_LAYOUT))
111                 return;
112
113         /* This would normally block until the existing request finishes.
114          * If fail_loc is set it will block until the regular request is
115          * done, then set rpcl_it to MDC_FAKE_RPCL_IT.  Once that is set
116          * it will only be cleared when all fake requests are finished.
117          * Only when all fake requests are finished can normal requests
118          * be sent, to ensure they are recoverable again. */
119  again:
120         mutex_lock(&lck->rpcl_mutex);
121
122         if (CFS_FAIL_CHECK_QUIET(OBD_FAIL_MDC_RPCS_SEM)) {
123                 lck->rpcl_it = MDC_FAKE_RPCL_IT;
124                 lck->rpcl_fakes++;
125                 mutex_unlock(&lck->rpcl_mutex);
126                 return;
127         }
128
129         /* This will only happen when the CFS_FAIL_CHECK() was
130          * just turned off but there are still requests in progress.
131          * Wait until they finish.  It doesn't need to be efficient
132          * in this extremely rare case, just have low overhead in
133          * the common case when it isn't true. */
134         while (unlikely(lck->rpcl_it == MDC_FAKE_RPCL_IT)) {
135                 mutex_unlock(&lck->rpcl_mutex);
136                 schedule_timeout(cfs_time_seconds(1) / 4);
137                 goto again;
138         }
139
140         LASSERT(lck->rpcl_it == NULL);
141         lck->rpcl_it = it;
142 }
143
144 static inline void mdc_put_rpc_lock(struct mdc_rpc_lock *lck,
145                                     struct lookup_intent *it)
146 {
147         if (it != NULL && (it->it_op == IT_GETATTR || it->it_op == IT_LOOKUP ||
148                            it->it_op == IT_LAYOUT))
149                 goto out;
150
151         if (lck->rpcl_it == MDC_FAKE_RPCL_IT) { /* OBD_FAIL_MDC_RPCS_SEM */
152                 mutex_lock(&lck->rpcl_mutex);
153
154                 LASSERTF(lck->rpcl_fakes > 0, "%d\n", lck->rpcl_fakes);
155                 lck->rpcl_fakes--;
156
157                 if (lck->rpcl_fakes == 0)
158                         lck->rpcl_it = NULL;
159
160         } else {
161                 LASSERTF(it == lck->rpcl_it, "%p != %p\n", it, lck->rpcl_it);
162                 lck->rpcl_it = NULL;
163         }
164
165         mutex_unlock(&lck->rpcl_mutex);
166  out:
167         EXIT;
168 }
169
170 /* Update the maximum observed easize and cookiesize.  The default easize
171  * and cookiesize is initialized to the minimum value but allowed to grow
172  * up to a single page in size if required to handle the common case.
173  */
174 static inline void mdc_update_max_ea_from_body(struct obd_export *exp,
175                                                struct mdt_body *body)
176 {
177         if (body->mbo_valid & OBD_MD_FLMODEASIZE) {
178                 struct client_obd *cli = &exp->exp_obd->u.cli;
179
180                 if (cli->cl_max_mds_easize < body->mbo_max_mdsize) {
181                         cli->cl_max_mds_easize = body->mbo_max_mdsize;
182                         cli->cl_default_mds_easize =
183                                 min_t(__u32, body->mbo_max_mdsize,
184                                       PAGE_CACHE_SIZE);
185                 }
186                 if (cli->cl_max_mds_cookiesize < body->mbo_max_cookiesize) {
187                         cli->cl_max_mds_cookiesize = body->mbo_max_cookiesize;
188                         cli->cl_default_mds_cookiesize =
189                             min_t(__u32, body->mbo_max_cookiesize,
190                                   PAGE_CACHE_SIZE);
191                 }
192         }
193 }
194
195
196 /* mdc/mdc_locks.c */
197 int it_disposition(const struct lookup_intent *it, int flag);
198 void it_clear_disposition(struct lookup_intent *it, int flag);
199 void it_set_disposition(struct lookup_intent *it, int flag);
200 int it_open_error(int phase, struct lookup_intent *it);
201 #ifdef HAVE_SPLIT_SUPPORT
202 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
203                  const struct page *page, int offset);
204 #endif
205
206 static inline bool cl_is_lov_delay_create(unsigned int flags)
207 {
208         return  (flags & O_LOV_DELAY_CREATE_1_8) != 0 ||
209                 (flags & O_LOV_DELAY_CREATE_MASK) == O_LOV_DELAY_CREATE_MASK;
210 }
211
212 static inline void cl_lov_delay_create_clear(unsigned int *flags)
213 {
214         if ((*flags & O_LOV_DELAY_CREATE_1_8) != 0)
215                 *flags &= ~O_LOV_DELAY_CREATE_1_8;
216         if ((*flags & O_LOV_DELAY_CREATE_MASK) == O_LOV_DELAY_CREATE_MASK)
217                 *flags &= ~O_LOV_DELAY_CREATE_MASK;
218 }
219
220 /** @} mdc */
221
222 #endif