staging: lustre: remove RETURN macro
[deliverable/linux.git] / drivers / staging / lustre / lustre / lmv / lmv_intent.c
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) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2011, 2012, Intel Corporation.
31 */
32 /*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 */
36
37 #define DEBUG_SUBSYSTEM S_LMV
38 #include <linux/slab.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/pagemap.h>
42 #include <asm/div64.h>
43 #include <linux/seq_file.h>
44 #include <linux/namei.h>
45 #include <linux/lustre_intent.h>
46
47 #include <obd_support.h>
48 #include <lustre/lustre_idl.h>
49 #include <lustre_lib.h>
50 #include <lustre_net.h>
51 #include <lustre_dlm.h>
52 #include <obd_class.h>
53 #include <lprocfs_status.h>
54 #include "lmv_internal.h"
55
56 static int lmv_intent_remote(struct obd_export *exp, void *lmm,
57 int lmmsize, struct lookup_intent *it,
58 const struct lu_fid *parent_fid, int flags,
59 struct ptlrpc_request **reqp,
60 ldlm_blocking_callback cb_blocking,
61 __u64 extra_lock_flags)
62 {
63 struct obd_device *obd = exp->exp_obd;
64 struct lmv_obd *lmv = &obd->u.lmv;
65 struct ptlrpc_request *req = NULL;
66 struct lustre_handle plock;
67 struct md_op_data *op_data;
68 struct lmv_tgt_desc *tgt;
69 struct mdt_body *body;
70 int pmode;
71 int rc = 0;
72
73 body = req_capsule_server_get(&(*reqp)->rq_pill, &RMF_MDT_BODY);
74 if (body == NULL)
75 return -EPROTO;
76
77 LASSERT((body->valid & OBD_MD_MDS));
78
79 /*
80 * Unfortunately, we have to lie to MDC/MDS to retrieve
81 * attributes llite needs and provideproper locking.
82 */
83 if (it->it_op & IT_LOOKUP)
84 it->it_op = IT_GETATTR;
85
86 /*
87 * We got LOOKUP lock, but we really need attrs.
88 */
89 pmode = it->d.lustre.it_lock_mode;
90 if (pmode) {
91 plock.cookie = it->d.lustre.it_lock_handle;
92 it->d.lustre.it_lock_mode = 0;
93 it->d.lustre.it_data = NULL;
94 }
95
96 LASSERT(fid_is_sane(&body->fid1));
97
98 tgt = lmv_find_target(lmv, &body->fid1);
99 if (IS_ERR(tgt))
100 GOTO(out, rc = PTR_ERR(tgt));
101
102 OBD_ALLOC_PTR(op_data);
103 if (op_data == NULL)
104 GOTO(out, rc = -ENOMEM);
105
106 op_data->op_fid1 = body->fid1;
107 /* Sent the parent FID to the remote MDT */
108 if (parent_fid != NULL) {
109 /* The parent fid is only for remote open to
110 * check whether the open is from OBF,
111 * see mdt_cross_open */
112 LASSERT(it->it_op & IT_OPEN);
113 op_data->op_fid2 = *parent_fid;
114 /* Add object FID to op_fid3, in case it needs to check stale
115 * (M_CHECK_STALE), see mdc_finish_intent_lock */
116 op_data->op_fid3 = body->fid1;
117 }
118
119 op_data->op_bias = MDS_CROSS_REF;
120 CDEBUG(D_INODE, "REMOTE_INTENT with fid="DFID" -> mds #%d\n",
121 PFID(&body->fid1), tgt->ltd_idx);
122
123 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
124 rc = md_intent_lock(tgt->ltd_exp, op_data, lmm, lmmsize, it,
125 flags, &req, cb_blocking, extra_lock_flags);
126 if (rc)
127 GOTO(out_free_op_data, rc);
128
129 /*
130 * LLite needs LOOKUP lock to track dentry revocation in order to
131 * maintain dcache consistency. Thus drop UPDATE|PERM lock here
132 * and put LOOKUP in request.
133 */
134 if (it->d.lustre.it_lock_mode != 0) {
135 it->d.lustre.it_remote_lock_handle =
136 it->d.lustre.it_lock_handle;
137 it->d.lustre.it_remote_lock_mode = it->d.lustre.it_lock_mode;
138 }
139
140 it->d.lustre.it_lock_handle = plock.cookie;
141 it->d.lustre.it_lock_mode = pmode;
142
143 out_free_op_data:
144 OBD_FREE_PTR(op_data);
145 out:
146 if (rc && pmode)
147 ldlm_lock_decref(&plock, pmode);
148
149 ptlrpc_req_finished(*reqp);
150 *reqp = req;
151 return rc;
152 }
153
154 /*
155 * IT_OPEN is intended to open (and create, possible) an object. Parent (pid)
156 * may be split dir.
157 */
158 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
159 void *lmm, int lmmsize, struct lookup_intent *it,
160 int flags, struct ptlrpc_request **reqp,
161 ldlm_blocking_callback cb_blocking,
162 __u64 extra_lock_flags)
163 {
164 struct obd_device *obd = exp->exp_obd;
165 struct lmv_obd *lmv = &obd->u.lmv;
166 struct lmv_tgt_desc *tgt;
167 struct mdt_body *body;
168 int rc;
169
170 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
171 if (IS_ERR(tgt))
172 return PTR_ERR(tgt);
173
174 /* If it is ready to open the file by FID, do not need
175 * allocate FID at all, otherwise it will confuse MDT */
176 if ((it->it_op & IT_CREAT) &&
177 !(it->it_flags & MDS_OPEN_BY_FID)) {
178 /*
179 * For open with IT_CREATE and for IT_CREATE cases allocate new
180 * fid and setup FLD for it.
181 */
182 op_data->op_fid3 = op_data->op_fid2;
183 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
184 if (rc != 0)
185 return rc;
186 }
187
188 CDEBUG(D_INODE, "OPEN_INTENT with fid1="DFID", fid2="DFID","
189 " name='%s' -> mds #%d\n", PFID(&op_data->op_fid1),
190 PFID(&op_data->op_fid2), op_data->op_name, tgt->ltd_idx);
191
192 rc = md_intent_lock(tgt->ltd_exp, op_data, lmm, lmmsize, it, flags,
193 reqp, cb_blocking, extra_lock_flags);
194 if (rc != 0)
195 return rc;
196 /*
197 * Nothing is found, do not access body->fid1 as it is zero and thus
198 * pointless.
199 */
200 if ((it->d.lustre.it_disposition & DISP_LOOKUP_NEG) &&
201 !(it->d.lustre.it_disposition & DISP_OPEN_CREATE) &&
202 !(it->d.lustre.it_disposition & DISP_OPEN_OPEN))
203 return rc;
204
205 body = req_capsule_server_get(&(*reqp)->rq_pill, &RMF_MDT_BODY);
206 if (body == NULL)
207 return -EPROTO;
208 /*
209 * Not cross-ref case, just get out of here.
210 */
211 if (likely(!(body->valid & OBD_MD_MDS)))
212 return 0;
213
214 /*
215 * Okay, MDS has returned success. Probably name has been resolved in
216 * remote inode.
217 */
218 rc = lmv_intent_remote(exp, lmm, lmmsize, it, &op_data->op_fid1, flags,
219 reqp, cb_blocking, extra_lock_flags);
220 if (rc != 0) {
221 LASSERT(rc < 0);
222 /*
223 * This is possible, that some userspace application will try to
224 * open file as directory and we will have -ENOTDIR here. As
225 * this is normal situation, we should not print error here,
226 * only debug info.
227 */
228 CDEBUG(D_INODE, "Can't handle remote %s: dir "DFID"("DFID"):"
229 "%*s: %d\n", LL_IT2STR(it), PFID(&op_data->op_fid2),
230 PFID(&op_data->op_fid1), op_data->op_namelen,
231 op_data->op_name, rc);
232 return rc;
233 }
234
235 return rc;
236 }
237
238 /*
239 * Handler for: getattr, lookup and revalidate cases.
240 */
241 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
242 void *lmm, int lmmsize, struct lookup_intent *it,
243 int flags, struct ptlrpc_request **reqp,
244 ldlm_blocking_callback cb_blocking,
245 __u64 extra_lock_flags)
246 {
247 struct obd_device *obd = exp->exp_obd;
248 struct lmv_obd *lmv = &obd->u.lmv;
249 struct lmv_tgt_desc *tgt = NULL;
250 struct mdt_body *body;
251 int rc = 0;
252
253 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
254 if (IS_ERR(tgt))
255 return PTR_ERR(tgt);
256
257 if (!fid_is_sane(&op_data->op_fid2))
258 fid_zero(&op_data->op_fid2);
259
260 CDEBUG(D_INODE, "LOOKUP_INTENT with fid1="DFID", fid2="DFID
261 ", name='%s' -> mds #%d\n", PFID(&op_data->op_fid1),
262 PFID(&op_data->op_fid2),
263 op_data->op_name ? op_data->op_name : "<NULL>",
264 tgt->ltd_idx);
265
266 op_data->op_bias &= ~MDS_CROSS_REF;
267
268 rc = md_intent_lock(tgt->ltd_exp, op_data, lmm, lmmsize, it,
269 flags, reqp, cb_blocking, extra_lock_flags);
270
271 if (rc < 0 || *reqp == NULL)
272 return rc;
273
274 /*
275 * MDS has returned success. Probably name has been resolved in
276 * remote inode. Let's check this.
277 */
278 body = req_capsule_server_get(&(*reqp)->rq_pill, &RMF_MDT_BODY);
279 if (body == NULL)
280 return -EPROTO;
281 /* Not cross-ref case, just get out of here. */
282 if (likely(!(body->valid & OBD_MD_MDS)))
283 return 0;
284
285 rc = lmv_intent_remote(exp, lmm, lmmsize, it, NULL, flags, reqp,
286 cb_blocking, extra_lock_flags);
287
288 return rc;
289 }
290
291 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
292 void *lmm, int lmmsize, struct lookup_intent *it,
293 int flags, struct ptlrpc_request **reqp,
294 ldlm_blocking_callback cb_blocking,
295 __u64 extra_lock_flags)
296 {
297 struct obd_device *obd = exp->exp_obd;
298 int rc;
299
300 LASSERT(it != NULL);
301 LASSERT(fid_is_sane(&op_data->op_fid1));
302
303 CDEBUG(D_INODE, "INTENT LOCK '%s' for '%*s' on "DFID"\n",
304 LL_IT2STR(it), op_data->op_namelen, op_data->op_name,
305 PFID(&op_data->op_fid1));
306
307 rc = lmv_check_connect(obd);
308 if (rc)
309 return rc;
310
311 if (it->it_op & (IT_LOOKUP | IT_GETATTR | IT_LAYOUT))
312 rc = lmv_intent_lookup(exp, op_data, lmm, lmmsize, it,
313 flags, reqp, cb_blocking,
314 extra_lock_flags);
315 else if (it->it_op & IT_OPEN)
316 rc = lmv_intent_open(exp, op_data, lmm, lmmsize, it,
317 flags, reqp, cb_blocking,
318 extra_lock_flags);
319 else
320 LBUG();
321 return rc;
322 }
This page took 0.051262 seconds and 5 git commands to generate.