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