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