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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LMV
34 #include <linux/slab.h>
35 #include <linux/module.h>
36 #include <linux/pagemap.h>
37 #include <asm/div64.h>
38 #include <linux/seq_file.h>
39 #include <linux/namei.h>
40 #include "../include/lustre_intent.h"
41 #include "../include/obd_support.h"
42 #include "../include/lustre/lustre_idl.h"
43 #include "../include/lustre_lib.h"
44 #include "../include/lustre_net.h"
45 #include "../include/lustre_dlm.h"
46 #include "../include/obd_class.h"
47 #include "../include/lprocfs_status.h"
48 #include "lmv_internal.h"
50 static int lmv_intent_remote(struct obd_export *exp, void *lmm,
51 int lmmsize, struct lookup_intent *it,
52 const struct lu_fid *parent_fid, int flags,
53 struct ptlrpc_request **reqp,
54 ldlm_blocking_callback cb_blocking,
55 __u64 extra_lock_flags)
57 struct obd_device *obd = exp->exp_obd;
58 struct lmv_obd *lmv = &obd->u.lmv;
59 struct ptlrpc_request *req = NULL;
60 struct lustre_handle plock;
61 struct md_op_data *op_data;
62 struct lmv_tgt_desc *tgt;
63 struct mdt_body *body;
67 body = req_capsule_server_get(&(*reqp)->rq_pill, &RMF_MDT_BODY);
71 LASSERT((body->valid & OBD_MD_MDS));
74 * Unfortunately, we have to lie to MDC/MDS to retrieve
75 * attributes llite needs and provideproper locking.
77 if (it->it_op & IT_LOOKUP)
78 it->it_op = IT_GETATTR;
81 * We got LOOKUP lock, but we really need attrs.
83 pmode = it->it_lock_mode;
85 plock.cookie = it->it_lock_handle;
87 it->it_request = NULL;
90 LASSERT(fid_is_sane(&body->fid1));
92 tgt = lmv_find_target(lmv, &body->fid1);
98 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
104 op_data->op_fid1 = body->fid1;
105 /* Sent the parent FID to the remote MDT */
107 /* The parent fid is only for remote open to
108 * check whether the open is from OBF,
111 LASSERT(it->it_op & IT_OPEN);
112 op_data->op_fid2 = *parent_fid;
113 /* Add object FID to op_fid3, in case it needs to check stale
114 * (M_CHECK_STALE), see mdc_finish_intent_lock
116 op_data->op_fid3 = body->fid1;
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);
123 rc = md_intent_lock(tgt->ltd_exp, op_data, lmm, lmmsize, it,
124 flags, &req, cb_blocking, extra_lock_flags);
126 goto out_free_op_data;
129 * LLite needs LOOKUP lock to track dentry revocation in order to
130 * maintain dcache consistency. Thus drop UPDATE|PERM lock here
131 * and put LOOKUP in request.
133 if (it->it_lock_mode != 0) {
134 it->it_remote_lock_handle =
136 it->it_remote_lock_mode = it->it_lock_mode;
139 it->it_lock_handle = plock.cookie;
140 it->it_lock_mode = pmode;
146 ldlm_lock_decref(&plock, pmode);
148 ptlrpc_req_finished(*reqp);
154 * IT_OPEN is intended to open (and create, possible) an object. Parent (pid)
157 static int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
158 void *lmm, int lmmsize, struct lookup_intent *it,
159 int flags, struct ptlrpc_request **reqp,
160 ldlm_blocking_callback cb_blocking,
161 __u64 extra_lock_flags)
163 struct obd_device *obd = exp->exp_obd;
164 struct lmv_obd *lmv = &obd->u.lmv;
165 struct lmv_tgt_desc *tgt;
166 struct mdt_body *body;
169 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
173 /* If it is ready to open the file by FID, do not need
174 * allocate FID at all, otherwise it will confuse MDT
176 if ((it->it_op & IT_CREAT) &&
177 !(it->it_flags & MDS_OPEN_BY_FID)) {
179 * For open with IT_CREATE and for IT_CREATE cases allocate new
180 * fid and setup FLD for it.
182 op_data->op_fid3 = op_data->op_fid2;
183 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
188 CDEBUG(D_INODE, "OPEN_INTENT with fid1=" DFID ", fid2=" DFID ", name='%s' -> mds #%d\n",
189 PFID(&op_data->op_fid1),
190 PFID(&op_data->op_fid2), op_data->op_name, tgt->ltd_idx);
192 rc = md_intent_lock(tgt->ltd_exp, op_data, lmm, lmmsize, it, flags,
193 reqp, cb_blocking, extra_lock_flags);
197 * Nothing is found, do not access body->fid1 as it is zero and thus
200 if ((it->it_disposition & DISP_LOOKUP_NEG) &&
201 !(it->it_disposition & DISP_OPEN_CREATE) &&
202 !(it->it_disposition & DISP_OPEN_OPEN))
205 body = req_capsule_server_get(&(*reqp)->rq_pill, &RMF_MDT_BODY);
209 * Not cross-ref case, just get out of here.
211 if (likely(!(body->valid & OBD_MD_MDS)))
215 * Okay, MDS has returned success. Probably name has been resolved in
218 rc = lmv_intent_remote(exp, lmm, lmmsize, it, &op_data->op_fid1, flags,
219 reqp, cb_blocking, extra_lock_flags);
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,
228 CDEBUG(D_INODE, "Can't handle remote %s: dir " DFID "(" DFID "):%*s: %d\n",
229 LL_IT2STR(it), PFID(&op_data->op_fid2),
230 PFID(&op_data->op_fid1), op_data->op_namelen,
231 op_data->op_name, rc);
239 * Handler for: getattr, lookup and revalidate cases.
241 static int lmv_intent_lookup(struct obd_export *exp,
242 struct md_op_data *op_data,
243 void *lmm, int lmmsize, struct lookup_intent *it,
244 int flags, struct ptlrpc_request **reqp,
245 ldlm_blocking_callback cb_blocking,
246 __u64 extra_lock_flags)
248 struct obd_device *obd = exp->exp_obd;
249 struct lmv_obd *lmv = &obd->u.lmv;
250 struct lmv_tgt_desc *tgt = NULL;
251 struct mdt_body *body;
254 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
258 if (!fid_is_sane(&op_data->op_fid2))
259 fid_zero(&op_data->op_fid2);
261 CDEBUG(D_INODE, "LOOKUP_INTENT with fid1="DFID", fid2="DFID
262 ", name='%s' -> mds #%d\n", PFID(&op_data->op_fid1),
263 PFID(&op_data->op_fid2),
264 op_data->op_name ? op_data->op_name : "<NULL>",
267 op_data->op_bias &= ~MDS_CROSS_REF;
269 rc = md_intent_lock(tgt->ltd_exp, op_data, lmm, lmmsize, it,
270 flags, reqp, cb_blocking, extra_lock_flags);
272 if (rc < 0 || !*reqp)
276 * MDS has returned success. Probably name has been resolved in
277 * remote inode. Let's check this.
279 body = req_capsule_server_get(&(*reqp)->rq_pill, &RMF_MDT_BODY);
282 /* Not cross-ref case, just get out of here. */
283 if (likely(!(body->valid & OBD_MD_MDS)))
286 rc = lmv_intent_remote(exp, lmm, lmmsize, it, NULL, flags, reqp,
287 cb_blocking, extra_lock_flags);
292 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
293 void *lmm, int lmmsize, struct lookup_intent *it,
294 int flags, struct ptlrpc_request **reqp,
295 ldlm_blocking_callback cb_blocking,
296 __u64 extra_lock_flags)
298 struct obd_device *obd = exp->exp_obd;
301 LASSERT(fid_is_sane(&op_data->op_fid1));
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));
307 rc = lmv_check_connect(obd);
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,
315 else if (it->it_op & IT_OPEN)
316 rc = lmv_intent_open(exp, op_data, lmm, lmmsize, it,
317 flags, reqp, cb_blocking,