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) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LMV
39 #include <linux/slab.h>
40 #include <linux/module.h>
41 #include <linux/init.h>
42 #include <linux/slab.h>
43 #include <linux/pagemap.h>
44 #include <asm/div64.h>
45 #include <linux/seq_file.h>
46 #include <linux/namei.h>
47 #include <linux/lustre_intent.h>
49 #include <liblustre.h>
52 #include <obd_support.h>
53 #include <lustre/lustre_idl.h>
54 #include <lustre_lib.h>
55 #include <lustre_net.h>
56 #include <lustre_dlm.h>
57 #include <obd_class.h>
58 #include <lprocfs_status.h>
59 #include "lmv_internal.h"
61 int lmv_intent_remote(struct obd_export *exp, void *lmm,
62 int lmmsize, struct lookup_intent *it,
63 int flags, struct ptlrpc_request **reqp,
64 ldlm_blocking_callback cb_blocking,
65 __u64 extra_lock_flags)
67 struct obd_device *obd = exp->exp_obd;
68 struct lmv_obd *lmv = &obd->u.lmv;
69 struct ptlrpc_request *req = NULL;
70 struct lustre_handle plock;
71 struct md_op_data *op_data;
72 struct lmv_tgt_desc *tgt;
73 struct mdt_body *body;
78 body = req_capsule_server_get(&(*reqp)->rq_pill, &RMF_MDT_BODY);
82 LASSERT((body->valid & OBD_MD_MDS));
85 * Unfortunately, we have to lie to MDC/MDS to retrieve
86 * attributes llite needs and provideproper locking.
88 if (it->it_op & IT_LOOKUP)
89 it->it_op = IT_GETATTR;
92 * We got LOOKUP lock, but we really need attrs.
94 pmode = it->d.lustre.it_lock_mode;
96 plock.cookie = it->d.lustre.it_lock_handle;
97 it->d.lustre.it_lock_mode = 0;
98 it->d.lustre.it_data = NULL;
101 LASSERT(fid_is_sane(&body->fid1));
103 tgt = lmv_find_target(lmv, &body->fid1);
105 GOTO(out, rc = PTR_ERR(tgt));
107 OBD_ALLOC_PTR(op_data);
109 GOTO(out, rc = -ENOMEM);
111 op_data->op_fid1 = body->fid1;
112 op_data->op_bias = MDS_CROSS_REF;
114 CDEBUG(D_INODE, "REMOTE_INTENT with fid="DFID" -> mds #%d\n",
115 PFID(&body->fid1), tgt->ltd_idx);
117 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
118 rc = md_intent_lock(tgt->ltd_exp, op_data, lmm, lmmsize, it,
119 flags, &req, cb_blocking, extra_lock_flags);
121 GOTO(out_free_op_data, rc);
124 * LLite needs LOOKUP lock to track dentry revocation in order to
125 * maintain dcache consistency. Thus drop UPDATE lock here and put
128 if (it->d.lustre.it_lock_mode != 0) {
129 ldlm_lock_decref((void *)&it->d.lustre.it_lock_handle,
130 it->d.lustre.it_lock_mode);
131 it->d.lustre.it_lock_mode = 0;
133 it->d.lustre.it_lock_handle = plock.cookie;
134 it->d.lustre.it_lock_mode = pmode;
138 OBD_FREE_PTR(op_data);
141 ldlm_lock_decref(&plock, pmode);
143 ptlrpc_req_finished(*reqp);
149 * IT_OPEN is intended to open (and create, possible) an object. Parent (pid)
152 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
153 void *lmm, int lmmsize, struct lookup_intent *it,
154 int flags, struct ptlrpc_request **reqp,
155 ldlm_blocking_callback cb_blocking,
156 __u64 extra_lock_flags)
158 struct obd_device *obd = exp->exp_obd;
159 struct lmv_obd *lmv = &obd->u.lmv;
160 struct lmv_tgt_desc *tgt;
161 struct mdt_body *body;
165 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
167 RETURN(PTR_ERR(tgt));
169 if (it->it_op & IT_CREAT) {
171 * For open with IT_CREATE and for IT_CREATE cases allocate new
172 * fid and setup FLD for it.
174 op_data->op_fid3 = op_data->op_fid2;
175 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
180 CDEBUG(D_INODE, "OPEN_INTENT with fid1="DFID", fid2="DFID","
181 " name='%s' -> mds #%d\n", PFID(&op_data->op_fid1),
182 PFID(&op_data->op_fid2), op_data->op_name, tgt->ltd_idx);
184 rc = md_intent_lock(tgt->ltd_exp, op_data, lmm, lmmsize, it, flags,
185 reqp, cb_blocking, extra_lock_flags);
189 * Nothing is found, do not access body->fid1 as it is zero and thus
192 if ((it->d.lustre.it_disposition & DISP_LOOKUP_NEG) &&
193 !(it->d.lustre.it_disposition & DISP_OPEN_CREATE) &&
194 !(it->d.lustre.it_disposition & DISP_OPEN_OPEN))
197 body = req_capsule_server_get(&(*reqp)->rq_pill, &RMF_MDT_BODY);
201 * Not cross-ref case, just get out of here.
203 if (likely(!(body->valid & OBD_MD_MDS)))
207 * Okay, MDS has returned success. Probably name has been resolved in
210 rc = lmv_intent_remote(exp, lmm, lmmsize, it, flags, reqp,
211 cb_blocking, extra_lock_flags);
215 * This is possible, that some userspace application will try to
216 * open file as directory and we will have -ENOTDIR here. As
217 * this is normal situation, we should not print error here,
220 CDEBUG(D_INODE, "Can't handle remote %s: dir "DFID"("DFID"):"
221 "%*s: %d\n", LL_IT2STR(it), PFID(&op_data->op_fid2),
222 PFID(&op_data->op_fid1), op_data->op_namelen,
223 op_data->op_name, rc);
231 * Handler for: getattr, lookup and revalidate cases.
233 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
234 void *lmm, int lmmsize, struct lookup_intent *it,
235 int flags, struct ptlrpc_request **reqp,
236 ldlm_blocking_callback cb_blocking,
237 __u64 extra_lock_flags)
239 struct obd_device *obd = exp->exp_obd;
240 struct lmv_obd *lmv = &obd->u.lmv;
241 struct lmv_tgt_desc *tgt = NULL;
242 struct mdt_body *body;
246 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
248 RETURN(PTR_ERR(tgt));
250 if (!fid_is_sane(&op_data->op_fid2))
251 fid_zero(&op_data->op_fid2);
253 CDEBUG(D_INODE, "LOOKUP_INTENT with fid1="DFID", fid2="DFID
254 ", name='%s' -> mds #%d\n", PFID(&op_data->op_fid1),
255 PFID(&op_data->op_fid2),
256 op_data->op_name ? op_data->op_name : "<NULL>",
259 op_data->op_bias &= ~MDS_CROSS_REF;
261 rc = md_intent_lock(tgt->ltd_exp, op_data, lmm, lmmsize, it,
262 flags, reqp, cb_blocking, extra_lock_flags);
264 if (rc < 0 || *reqp == NULL)
268 * MDS has returned success. Probably name has been resolved in
269 * remote inode. Let's check this.
271 body = req_capsule_server_get(&(*reqp)->rq_pill, &RMF_MDT_BODY);
274 /* Not cross-ref case, just get out of here. */
275 if (likely(!(body->valid & OBD_MD_MDS)))
278 rc = lmv_intent_remote(exp, lmm, lmmsize, it, flags, reqp,
279 cb_blocking, extra_lock_flags);
284 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
285 void *lmm, int lmmsize, struct lookup_intent *it,
286 int flags, struct ptlrpc_request **reqp,
287 ldlm_blocking_callback cb_blocking,
288 __u64 extra_lock_flags)
290 struct obd_device *obd = exp->exp_obd;
295 LASSERT(fid_is_sane(&op_data->op_fid1));
297 CDEBUG(D_INODE, "INTENT LOCK '%s' for '%*s' on "DFID"\n",
298 LL_IT2STR(it), op_data->op_namelen, op_data->op_name,
299 PFID(&op_data->op_fid1));
301 rc = lmv_check_connect(obd);
305 if (it->it_op & (IT_LOOKUP | IT_GETATTR | IT_LAYOUT))
306 rc = lmv_intent_lookup(exp, op_data, lmm, lmmsize, it,
307 flags, reqp, cb_blocking,
309 else if (it->it_op & IT_OPEN)
310 rc = lmv_intent_open(exp, op_data, lmm, lmmsize, it,
311 flags, reqp, cb_blocking,