Whamcloud - gitweb
b=3995
[fs/lustre-release.git] / lustre / mdc / mdc_locks.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #ifndef EXPORT_SYMTAB
23 # define EXPORT_SYMTAB
24 #endif
25 #define DEBUG_SUBSYSTEM S_MDC
26
27 #ifdef __KERNEL__
28 # include <linux/module.h>
29 # include <linux/pagemap.h>
30 # include <linux/miscdevice.h>
31 # include <linux/init.h>
32 #else
33 # include <liblustre.h>
34 #endif
35
36 #include <linux/obd_class.h>
37 #include <linux/lustre_mds.h>
38 #include <linux/lustre_dlm.h>
39 #include <linux/lustre_snap.h>
40 #include <linux/lprocfs_status.h>
41 #include "mdc_internal.h"
42
43 int it_disposition(struct lookup_intent *it, int flag)
44 {
45         return it->d.lustre.it_disposition & flag;
46 }
47 EXPORT_SYMBOL(it_disposition);
48
49 void it_set_disposition(struct lookup_intent *it, int flag)
50 {
51         it->d.lustre.it_disposition |= flag;
52 }
53 EXPORT_SYMBOL(it_set_disposition);
54
55 static void mdc_fid2mdc_op_data(struct mdc_op_data *data, struct ll_uctxt *ctxt,
56                                 struct ll_fid *f1, struct ll_fid *f2,
57                                 const char *name, int namelen, int mode)
58 {
59         LASSERT(data);
60         LASSERT(ctxt);
61         LASSERT(f1);
62
63         data->ctxt = *ctxt;
64         data->fid1 = *f1;
65         if (f2)
66                 data->fid2 = *f2;
67         else
68                 memset(&data->fid2, 0, sizeof(data->fid2));
69         data->name = name;
70         data->namelen = namelen;
71         data->create_mode = mode;
72         data->mod_time = LTIME_S(CURRENT_TIME);
73 }
74
75 static int it_to_lock_mode(struct lookup_intent *it)
76 {
77         /* CREAT needs to be tested before open (both could be set) */
78         if (it->it_op & IT_CREAT)
79                 return LCK_PW;
80         else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP |
81                               IT_CHDIR))
82                 return LCK_PR;
83
84         LBUG();
85         RETURN(-EINVAL);
86 }
87
88 int it_open_error(int phase, struct lookup_intent *it)
89 {
90         if (it_disposition(it, DISP_OPEN_OPEN)) {
91                 if (phase == DISP_OPEN_OPEN)
92                         return it->d.lustre.it_status;
93                 else
94                         return 0;
95         }
96
97         if (it_disposition(it, DISP_OPEN_CREATE)) {
98                 if (phase == DISP_OPEN_CREATE)
99                         return it->d.lustre.it_status;
100                 else
101                         return 0;
102         }
103
104         if (it_disposition(it, DISP_LOOKUP_EXECD)) {
105                 if (phase == DISP_LOOKUP_EXECD)
106                         return it->d.lustre.it_status;
107                 else
108                         return 0;
109         }
110
111         if (it_disposition(it, DISP_IT_EXECD)) {
112                 if (phase == DISP_IT_EXECD)
113                         return it->d.lustre.it_status;
114                 else
115                         return 0;
116         }
117         CERROR("it disp: %X, status: %d\n", it->d.lustre.it_disposition,
118                it->d.lustre.it_status);
119         LBUG();
120         return 0;
121 }
122 EXPORT_SYMBOL(it_open_error);
123
124 /* this must be called on a lockh that is known to have a referenced lock */
125 int mdc_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
126 {
127         struct ldlm_lock *lock;
128         struct lustre_handle *lockh = (struct lustre_handle *)l;
129         ENTRY;
130
131         if (!*l) {
132                 EXIT;
133                 return 0;
134         }
135
136         lock = ldlm_handle2lock(lockh);
137
138         LASSERT(lock != NULL);
139         l_lock(&lock->l_resource->lr_namespace->ns_lock);
140 #ifdef __KERNEL__
141         if (lock->l_ast_data && lock->l_ast_data != data) {
142                 struct inode *new_inode = data;
143                 struct inode *old_inode = lock->l_ast_data;
144                 LASSERTF(old_inode->i_state & I_FREEING,
145                          "Found existing inode %p/%lu/%u state %lu in lock: "
146                          "setting data to %p/%lu/%u\n", old_inode,
147                          old_inode->i_ino, old_inode->i_generation,
148                          old_inode->i_state,
149                          new_inode, new_inode->i_ino, new_inode->i_generation);
150         }
151 #endif
152         lock->l_ast_data = data;
153         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
154         LDLM_LOCK_PUT(lock);
155
156         EXIT;
157         return 0;
158 }
159 EXPORT_SYMBOL(mdc_set_lock_data);
160
161 int mdc_change_cbdata(struct obd_export *exp, struct ll_fid *fid, 
162                       ldlm_iterator_t it, void *data)
163 {
164         struct ldlm_res_id res_id = { .name = {0} };
165         ENTRY;
166
167         res_id.name[0] = fid->id;
168         res_id.name[1] = fid->generation;
169
170         ldlm_change_cbdata(class_exp2obd(exp)->obd_namespace, &res_id, it, 
171                            data);
172
173         EXIT;
174         return 0;
175 }
176
177 #if CONFIG_SNAPFS
178 int mdc_set_clone_info(struct obd_export *exp, struct lustre_msg *msg, 
179                        int offset)
180 {
181         struct client_obd *cli_obd = &exp->exp_obd->u.cli;
182         struct clonefs_info *cl_info;
183         ENTRY;
184         
185         if (cli_obd->cl_clone_info) { 
186                 cl_info = (struct clonefs_info *)lustre_msg_buf(msg, offset, 
187                                                                  sizeof (*cl_info));
188                 memcpy(cl_info, cli_obd->cl_clone_info, sizeof(*cl_info));
189         }
190         RETURN(0);        
191
192 #endif
193
194 /* We always reserve enough space in the reply packet for a stripe MD, because
195  * we don't know in advance the file type. */
196 int mdc_enqueue(struct obd_export *exp,
197                 int lock_type,
198                 struct lookup_intent *it,
199                 int lock_mode,
200                 struct mdc_op_data *data,
201                 struct lustre_handle *lockh,
202                 void *lmm,
203                 int lmmsize,
204                 ldlm_completion_callback cb_completion,
205                 ldlm_blocking_callback cb_blocking,
206                 void *cb_data)
207 {
208         struct ptlrpc_request *req;
209         struct obd_device *obddev = class_exp2obd(exp);
210         struct ldlm_res_id res_id =
211                 { .name = {data->fid1.id, data->fid1.generation} };
212         ldlm_policy_data_t policy = { .l_inodebits = { MDS_INODELOCK_LOOKUP } };
213         int size[6] = {sizeof(struct ldlm_request), sizeof(struct ldlm_intent)};
214         int rc, flags = LDLM_FL_HAS_INTENT;
215         int repsize[4] = {sizeof(struct ldlm_reply),
216                           sizeof(struct mds_body),
217                           obddev->u.cli.cl_max_mds_easize,
218                           obddev->u.cli.cl_max_mds_cookiesize};
219         struct ldlm_reply *dlm_rep;
220         struct ldlm_intent *lit;
221         struct ldlm_request *lockreq;
222         void *eadata;
223         unsigned long irqflags;
224         int   reply_buffers = 0;
225         ENTRY;
226
227 //        LDLM_DEBUG_NOLOCK("mdsintent=%s,name=%s,dir=%lu",
228 //                          ldlm_it2str(it->it_op), it_name, it_inode->i_ino);
229
230         if (it->it_op & IT_OPEN) {
231                 it->it_create_mode |= S_IFREG;
232                 it->it_create_mode &= ~current->fs->umask;
233
234                 size[2] = sizeof(struct mds_rec_create);
235                 size[3] = data->namelen + 1;
236                 size[4] = obddev->u.cli.cl_max_mds_easize;
237                 req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 
238                                       5, size, NULL);
239                 if (!req)
240                         RETURN(-ENOMEM);
241
242                 spin_lock_irqsave (&req->rq_lock, irqflags);
243                 req->rq_replay = 1;
244                 spin_unlock_irqrestore (&req->rq_lock, irqflags);
245
246                 /* pack the intent */
247                 lit = lustre_msg_buf(req->rq_reqmsg, 1, sizeof (*lit));
248                 lit->opc = (__u64)it->it_op;
249
250                 /* pack the intended request */
251                 mdc_open_pack(req->rq_reqmsg, 2, data, it->it_create_mode, 0,
252                               it->it_flags, lmm, lmmsize);
253                 /* get ready for the reply */
254                 reply_buffers = 3;
255                 req->rq_replen = lustre_msg_size(3, repsize);
256         } else if (it->it_op & (IT_GETATTR | IT_LOOKUP | IT_CHDIR)) {
257                 int valid = OBD_MD_FLNOTOBD | OBD_MD_FLEASIZE;
258                 size[2] = sizeof(struct mds_body);
259                 size[3] = data->namelen + 1;
260
261                 if (it->it_op & IT_GETATTR)
262                         policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
263 #if CONFIG_SNAPFS                
264                 size[4] = sizeof(struct clonefs_info); 
265                 req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 5,
266                                       size, NULL);
267 #else
268                 req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 4,
269                                       size, NULL);
270
271 #endif
272                 if (!req)
273                         RETURN(-ENOMEM);
274
275                 /* pack the intent */
276                 lit = lustre_msg_buf(req->rq_reqmsg, 1, sizeof (*lit));
277                 lit->opc = (__u64)it->it_op;
278
279                 /* pack the intended request */
280                 mdc_getattr_pack(req->rq_reqmsg, valid, 2, it->it_flags, data);
281 #if CONFIG_SNAPFS               
282                 mdc_set_clone_info(exp, req->rq_reqmsg, 4); 
283 #endif                 
284                 /* get ready for the reply */
285                 reply_buffers = 3;
286                 req->rq_replen = lustre_msg_size(3, repsize);
287         } else if (it->it_op == IT_READDIR) {
288                 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
289                 req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 1,
290                                       size, NULL);
291                 
292                 if (!req)
293                         RETURN(-ENOMEM);
294                 /* get ready for the reply */
295                 reply_buffers = 1;
296                 req->rq_replen = lustre_msg_size(1, repsize);
297         } else if (it->it_op == IT_UNLINK) {
298                 size[2] = sizeof(struct mds_body);
299                 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
300                 req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 3,
301                                       size, NULL);
302                 if (!req)
303                         RETURN(-ENOMEM);
304
305                 /* pack the intended request */
306                 mdc_getattr_pack(req->rq_reqmsg, 0,  2, 0, data);
307
308                 /* pack the intent */
309                 lit = lustre_msg_buf(req->rq_reqmsg, 1, sizeof (*lit));
310                 lit->opc = (__u64)it->it_op;
311
312                 /* get ready for the reply */
313                 reply_buffers = 3;
314                 req->rq_replen = lustre_msg_size(3, repsize);
315         } else {
316                 LBUG();
317                 RETURN(-EINVAL);
318         }
319         mdc_get_rpc_lock(obddev->u.cli.cl_rpc_lock, it);
320         rc = ldlm_cli_enqueue(exp, req, obddev->obd_namespace, res_id,
321                               lock_type, &policy, lock_mode, &flags,cb_blocking,
322                               cb_completion, NULL, cb_data, NULL, 0, NULL,
323                               lockh);
324         mdc_put_rpc_lock(obddev->u.cli.cl_rpc_lock, it);
325
326         /* Similarly, if we're going to replay this request, we don't want to
327          * actually get a lock, just perform the intent. */
328         if (req->rq_transno || req->rq_replay) {
329                 lockreq = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*lockreq));
330                 lockreq->lock_flags |= LDLM_FL_INTENT_ONLY;
331         }
332
333         /* This can go when we're sure that this can never happen */
334         LASSERT(rc != -ENOENT);
335         if (rc == ELDLM_LOCK_ABORTED) {
336                 lock_mode = 0;
337                 memset(lockh, 0, sizeof(*lockh));
338                 rc = 0;
339         } else if (rc != 0) {
340                 CERROR("ldlm_cli_enqueue: %d\n", rc);
341                 LASSERT (rc < 0);
342                 ptlrpc_req_finished(req);
343                 RETURN(rc);
344         } else { /* rc = 0 */
345                 struct ldlm_lock *lock = ldlm_handle2lock(lockh);
346                 LASSERT(lock);
347
348                 /* If the server gave us back a different lock mode, we should
349                  * fix up our variables. */
350                 if (lock->l_req_mode != lock_mode) {
351                         ldlm_lock_addref(lockh, lock->l_req_mode);
352                         ldlm_lock_decref(lockh, lock_mode);
353                         lock_mode = lock->l_req_mode;
354                 }
355
356                 ldlm_lock_allow_match(lock);
357                 LDLM_LOCK_PUT(lock);
358         }
359
360         dlm_rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*dlm_rep));
361         LASSERT(dlm_rep != NULL);           /* checked by ldlm_cli_enqueue() */
362         LASSERT_REPSWABBED(req, 0);         /* swabbed by ldlm_cli_enqueue() */
363
364         it->d.lustre.it_disposition = (int) dlm_rep->lock_policy_res1;
365         it->d.lustre.it_status = (int) dlm_rep->lock_policy_res2;
366         it->d.lustre.it_lock_mode = lock_mode;
367         it->d.lustre.it_data = req;
368
369         if (it->d.lustre.it_status < 0 && req->rq_replay) {
370                 LASSERT(req->rq_transno == 0);
371                 /* Don't hold error requests for replay. */
372                 spin_lock(&req->rq_lock);
373                 req->rq_replay = 0;
374                 spin_unlock(&req->rq_lock);
375         }
376
377         DEBUG_REQ(D_RPCTRACE, req, "disposition: %x, status: %d",
378                   it->d.lustre.it_disposition, it->d.lustre.it_status);
379
380         /* We know what to expect, so we do any byte flipping required here */
381         LASSERT(reply_buffers == 4 || reply_buffers == 3 || reply_buffers == 1);
382         if (reply_buffers >= 3) {
383                 struct mds_body *body;
384
385                 body = lustre_swab_repbuf(req, 1, sizeof (*body),
386                                            lustre_swab_mds_body);
387                 if (body == NULL) {
388                         CERROR ("Can't swab mds_body\n");
389                         RETURN (-EPROTO);
390                 }
391
392                 if ((body->valid & OBD_MD_FLEASIZE) != 0) {
393                         /* The eadata is opaque; just check that it is there.
394                          * Eventually, obd_unpackmd() will check the contents */
395                         eadata = lustre_swab_repbuf(req, 2, body->eadatasize,
396                                                     NULL);
397                         if (eadata == NULL) {
398                                 CERROR ("Missing/short eadata\n");
399                                 RETURN (-EPROTO);
400                         }
401                         if (it->it_op & IT_OPEN) {
402                                 void *replayea;
403
404                                 replayea = lustre_msg_buf(req->rq_reqmsg, 4,
405                                                           body->eadatasize);
406                                 LASSERT(replayea);
407                                 memcpy(replayea, eadata, body->eadatasize);
408
409                                 LASSERT(req->rq_reqmsg->bufcount == 5);
410                                 req->rq_reqmsg->buflens[4] = body->eadatasize;
411                                 /* If this isn't the last buffer, we might
412                                  * have to shift other data around. */
413                         }
414                 }
415         }
416
417         RETURN(rc);
418 }
419 EXPORT_SYMBOL(mdc_enqueue);
420
421 /* 
422  * This long block is all about fixing up the lock and request state
423  * so that it is correct as of the moment _before_ the operation was
424  * applied; that way, the VFS will think that everything is normal and
425  * call Lustre's regular VFS methods.
426  *
427  * If we're performing a creation, that means that unless the creation
428  * failed with EEXIST, we should fake up a negative dentry.
429  *
430  * For everything else, we want to lookup to succeed.
431  *
432  * One additional note: if CREATE or OPEN succeeded, we add an extra
433  * reference to the request because we need to keep it around until
434  * ll_create/ll_open gets called.
435  *
436  * The server will return to us, in it_disposition, an indication of
437  * exactly what d.lustre.it_status refers to.
438  *
439  * If DISP_OPEN_OPEN is set, then d.lustre.it_status refers to the open() call,
440  * otherwise if DISP_OPEN_CREATE is set, then it status is the
441  * creation failure mode.  In either case, one of DISP_LOOKUP_NEG or
442  * DISP_LOOKUP_POS will be set, indicating whether the child lookup
443  * was successful.
444  *
445  * Else, if DISP_LOOKUP_EXECD then d.lustre.it_status is the rc of the
446  * child lookup.
447  */
448 int mdc_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
449                     struct ll_fid *pfid, const char *name, int len,
450                     void *lmm, int lmmsize, struct ll_fid *cfid,
451                     struct lookup_intent *it, int lookup_flags,
452                     struct ptlrpc_request **reqp,
453                     ldlm_blocking_callback cb_blocking)
454 {
455         struct lustre_handle lockh;
456         struct ptlrpc_request *request;
457         int rc = 0;
458         struct mds_body *mds_body;
459         struct lustre_handle old_lock;
460         struct ldlm_lock *lock;
461         ENTRY;
462         LASSERT(it);
463
464         CDEBUG(D_DLMTRACE, "name: %*s in %ld, intent: %s\n", len, name,
465                pfid ? (unsigned long) pfid->id : 0 , ldlm_it2str(it->it_op));
466
467         if (cfid && (it->it_op == IT_LOOKUP || it->it_op == IT_GETATTR ||
468                      it->it_op == IT_CHDIR)) {
469                 /* We could just return 1 immediately, but since we should only
470                  * be called in revalidate_it if we already have a lock, let's
471                  * verify that. */
472                 struct ldlm_res_id res_id ={.name = {cfid->id,
473                                                      cfid->generation}};
474                 struct lustre_handle lockh;
475                 ldlm_policy_data_t policy;
476                 int mode = LCK_PR;
477
478                 /* For the GETATTR case, ll_revalidate_it issues two separate
479                    queries - for LOOKUP and for UPDATE lock because if cannot
480                    check them together - we might have those two bits to be
481                    present in two separate granted locks */
482                 policy.l_inodebits.bits = 
483                                  (it->it_op == IT_GETATTR)?MDS_INODELOCK_UPDATE:
484                                                            MDS_INODELOCK_LOOKUP;
485                 mode = LCK_PR;
486                 rc = ldlm_lock_match(exp->exp_obd->obd_namespace,
487                                      LDLM_FL_BLOCK_GRANTED, &res_id,
488                                      LDLM_IBITS, &policy, LCK_PR, &lockh);
489                 if (!rc) {
490                         mode = LCK_PW;
491                         rc = ldlm_lock_match(exp->exp_obd->obd_namespace,
492                                              LDLM_FL_BLOCK_GRANTED, &res_id,
493                                              LDLM_IBITS, &policy, LCK_PW,
494                                              &lockh);
495                 }
496                 if (rc) {
497                         memcpy(&it->d.lustre.it_lock_handle, &lockh,
498                                sizeof(lockh));
499                         it->d.lustre.it_lock_mode = mode;
500                 }
501                 RETURN(rc);
502         }
503
504         /* lookup_it may be called only after revalidate_it has run, because
505          * revalidate_it cannot return errors, only zero.  Returning zero causes
506          * this call to lookup, which *can* return an error.
507          *
508          * We only want to execute the request associated with the intent one
509          * time, however, so don't send the request again.  Instead, skip past
510          * this and use the request from revalidate.  In this case, revalidate
511          * never dropped its reference, so the refcounts are all OK */
512         if (!it_disposition(it, DISP_ENQ_COMPLETE)) {
513                 struct mdc_op_data op_data;
514                 mdc_fid2mdc_op_data(&op_data, uctxt, pfid, cfid, name, len, 0);
515
516                 rc = mdc_enqueue(exp, LDLM_IBITS, it, it_to_lock_mode(it),
517                                  &op_data, &lockh, lmm, lmmsize,
518                                  ldlm_completion_ast, cb_blocking, NULL);
519                 if (rc < 0)
520                         RETURN(rc);
521                 memcpy(&it->d.lustre.it_lock_handle, &lockh, sizeof(lockh));
522         }
523         request = *reqp = it->d.lustre.it_data;
524         LASSERT(request != NULL);
525
526         if (!it_disposition(it, DISP_IT_EXECD)) {
527                 /* The server failed before it even started executing the
528                  * intent, i.e. because it couldn't unpack the request. */
529                 LASSERT(it->d.lustre.it_status != 0);
530                 RETURN(it->d.lustre.it_status);
531         }
532         rc = it_open_error(DISP_IT_EXECD, it);
533         if (rc)
534                 RETURN(rc);
535
536         mds_body = lustre_msg_buf(request->rq_repmsg, 1, sizeof(*mds_body));
537         LASSERT(mds_body != NULL);           /* mdc_enqueue checked */
538         LASSERT_REPSWABBED(request, 1); /* mdc_enqueue swabbed */
539
540         /* If we were revalidating a fid/name pair, mark the intent in
541          * case we fail and get called again from lookup */
542         if (cfid != NULL) {
543                 it_set_disposition(it, DISP_ENQ_COMPLETE);
544                 /* Also: did we find the same inode? */
545                 /* we have to compare all the fields but type, because
546                  * MDS can return mds/ino/generation triple if inode
547                  * lives on another MDS -bzzz */
548                 if (cfid->generation != mds_body->fid1.generation ||
549                                 cfid->id != mds_body->fid1.id ||
550                                 cfid->mds != mds_body->fid1.mds)
551                         RETURN(-ESTALE);
552         }
553
554         /* If we're doing an IT_OPEN which did not result in an actual
555          * successful open, then we need to remove the bit which saves
556          * this request for unconditional replay. */
557         if (it->it_op & IT_OPEN) {
558                 if (!it_disposition(it, DISP_OPEN_OPEN) ||
559                     it->d.lustre.it_status != 0) {
560                         unsigned long irqflags;
561
562                         spin_lock_irqsave(&request->rq_lock, irqflags);
563                         request->rq_replay = 0;
564                         spin_unlock_irqrestore(&request->rq_lock, irqflags);
565                 }
566         }
567
568         rc = it_open_error(DISP_LOOKUP_EXECD, it);
569         if (rc)
570                 RETURN(rc);
571
572         /* keep requests around for the multiple phases of the call
573          * this shows the DISP_XX must guarantee we make it into the call
574          */
575         if (it_disposition(it, DISP_OPEN_CREATE) &&
576             !it_open_error(DISP_OPEN_CREATE, it))
577                 ptlrpc_request_addref(request);
578         if (it_disposition(it, DISP_OPEN_OPEN) &&
579             !it_open_error(DISP_OPEN_OPEN, it))
580                 ptlrpc_request_addref(request);
581
582         if (it->it_op & IT_CREAT) {
583                 /* XXX this belongs in ll_create_iit */
584         } else if (it->it_op == IT_OPEN) {
585                 LASSERT(!it_disposition(it, DISP_OPEN_CREATE));
586         } else {
587                 LASSERT(it->it_op & (IT_GETATTR | IT_LOOKUP | IT_CHDIR));
588         }
589
590         /* If we already have a matching lock, then cancel the new
591          * one.  We have to set the data here instead of in
592          * mdc_enqueue, because we need to use the child's inode as
593          * the l_ast_data to match, and that's not available until
594          * intent_finish has performed the iget().) */
595         lock = ldlm_handle2lock(&lockh);
596         if (lock) {
597                 ldlm_policy_data_t policy = lock->l_policy_data;
598                 LDLM_DEBUG(lock, "matching against this");
599                 LDLM_LOCK_PUT(lock);
600                 memcpy(&old_lock, &lockh, sizeof(lockh));
601                 if (ldlm_lock_match(NULL, LDLM_FL_BLOCK_GRANTED, NULL,
602                                     LDLM_IBITS, &policy, LCK_NL, &old_lock)) {
603                         ldlm_lock_decref_and_cancel(&lockh,
604                                                     it->d.lustre.it_lock_mode);
605                         memcpy(&lockh, &old_lock, sizeof(old_lock));
606                         memcpy(&it->d.lustre.it_lock_handle, &lockh,
607                                sizeof(lockh));
608                 }
609         }
610         CDEBUG(D_DENTRY, "D_IT dentry %*s intent: %s status %d disp %x rc %d\n",
611                len, name, ldlm_it2str(it->it_op), it->d.lustre.it_status,
612                it->d.lustre.it_disposition, rc);
613
614         RETURN(rc);
615 }
616 EXPORT_SYMBOL(mdc_intent_lock);