Whamcloud - gitweb
- fixes and cleanups in error messages and in code.
[fs/lustre-release.git] / lustre / mdc / mdc_locks.c
index c3bafd1..182d5bc 100644 (file)
@@ -36,7 +36,6 @@
 #include <linux/obd_class.h>
 #include <linux/lustre_mds.h>
 #include <linux/lustre_dlm.h>
-#include <linux/lustre_snap.h>
 #include <linux/lprocfs_status.h>
 #include "mdc_internal.h"
 
@@ -52,20 +51,20 @@ void it_set_disposition(struct lookup_intent *it, int flag)
 }
 EXPORT_SYMBOL(it_set_disposition);
 
-static void mdc_fid2mdc_op_data(struct mdc_op_data *data, struct ll_uctxt *ctxt,
-                                struct ll_fid *f1, struct ll_fid *f2,
-                                const char *name, int namelen, int mode)
+static void mdc_id2mdc_data(struct mdc_op_data *data,
+                            struct lustre_id *f1, 
+                            struct lustre_id *f2,
+                            const char *name, 
+                            int namelen, int mode)
 {
         LASSERT(data);
-        LASSERT(ctxt);
         LASSERT(f1);
 
-        data->ctxt = *ctxt;
-        data->fid1 = *f1;
+        data->id1 = *f1;
         if (f2)
-                data->fid2 = *f2;
-        else
-                memset(&data->fid2, 0, sizeof(data->fid2));
+                data->id2 = *f2;
+
+        data->valid = 0;
         data->name = name;
         data->namelen = namelen;
         data->create_mode = mode;
@@ -145,8 +144,8 @@ int mdc_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
                          "Found existing inode %p/%lu/%u state %lu in lock: "
                          "setting data to %p/%lu/%u\n", old_inode,
                          old_inode->i_ino, old_inode->i_generation,
-                         old_inode->i_state,
-                         new_inode, new_inode->i_ino, new_inode->i_generation);
+                         old_inode->i_state, new_inode, new_inode->i_ino,
+                         new_inode->i_generation);
         }
 #endif
         lock->l_ast_data = data;
@@ -158,37 +157,22 @@ int mdc_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
 }
 EXPORT_SYMBOL(mdc_set_lock_data);
 
-int mdc_change_cbdata(struct obd_export *exp, struct ll_fid *fid, 
+int mdc_change_cbdata(struct obd_export *exp, struct lustre_id *id, 
                       ldlm_iterator_t it, void *data)
 {
         struct ldlm_res_id res_id = { .name = {0} };
         ENTRY;
 
-        res_id.name[0] = fid->id;
-        res_id.name[1] = fid->generation;
+        res_id.name[0] = id_fid(id);
+        res_id.name[1] = id_group(id);
 
-        ldlm_change_cbdata(class_exp2obd(exp)->obd_namespace, &res_id, it, 
-                           data);
+        ldlm_change_cbdata(class_exp2obd(exp)->obd_namespace,
+                           &res_id, it, data);
 
         EXIT;
         return 0;
 }
 
-#if CONFIG_SNAPFS
-int mdc_set_clone_info(struct obd_import *climp, struct lustre_msg *msg, 
-                       int offset)
-{
-        struct client_obd *cli_obd = &climp->imp_obd->u.cli;
-        struct clonefs_info *cl_info;
-        ENTRY;
-         
-        cl_info = (struct clonefs_info *)lustre_msg_buf(msg, offset, 
-                                                         sizeof (*cl_info));
-        memcpy(cl_info, cli_obd->cl_clone_info, sizeof(*cl_info));
-        RETURN(0);        
-} 
-#endif
-
 /* We always reserve enough space in the reply packet for a stripe MD, because
  * we don't know in advance the file type. */
 int mdc_enqueue(struct obd_export *exp,
@@ -204,36 +188,41 @@ int mdc_enqueue(struct obd_export *exp,
                 void *cb_data)
 {
         struct ptlrpc_request *req;
+        struct ldlm_res_id res_id = {
+                .name = {id_fid(&data->id1), id_group(&data->id1)}
+        };
         struct obd_device *obddev = class_exp2obd(exp);
-        struct ldlm_res_id res_id =
-                { .name = {data->fid1.id, data->fid1.generation} };
         ldlm_policy_data_t policy = { .l_inodebits = { MDS_INODELOCK_LOOKUP } };
-        int size[6] = {sizeof(struct ldlm_request), sizeof(struct ldlm_intent)};
-        int rc, flags = LDLM_FL_HAS_INTENT;
+        struct ldlm_intent *lit;
+        struct ldlm_request *lockreq;
+        struct ldlm_reply *dlm_rep;
+        int reqsize[6] = {[MDS_REQ_SECDESC_OFF] = 0,
+                          [MDS_REQ_INTENT_LOCKREQ_OFF] = sizeof(*lockreq),
+                          [MDS_REQ_INTENT_IT_OFF] = sizeof(*lit)};
         int repsize[4] = {sizeof(struct ldlm_reply),
                           sizeof(struct mds_body),
                           obddev->u.cli.cl_max_mds_easize,
                           obddev->u.cli.cl_max_mds_cookiesize};
-        struct ldlm_reply *dlm_rep;
-        struct ldlm_intent *lit;
-        struct ldlm_request *lockreq;
+        int req_buffers = 3, reply_buffers = 0;
+        int rc, flags = LDLM_FL_HAS_INTENT;
         void *eadata;
         unsigned long irqflags;
-        int   reply_buffers = 0;
         ENTRY;
 
 //        LDLM_DEBUG_NOLOCK("mdsintent=%s,name=%s,dir=%lu",
 //                          ldlm_it2str(it->it_op), it_name, it_inode->i_ino);
 
+        reqsize[0] = mdc_get_secdesc_size();
+
         if (it->it_op & IT_OPEN) {
                 it->it_create_mode |= S_IFREG;
                 it->it_create_mode &= ~current->fs->umask;
 
-                size[2] = sizeof(struct mds_rec_create);
-                size[3] = data->namelen + 1;
-                size[4] = obddev->u.cli.cl_max_mds_easize;
-                req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 
-                                      5, size, NULL);
+                reqsize[req_buffers++] = sizeof(struct mds_rec_create);
+                reqsize[req_buffers++] = data->namelen + 1;
+                reqsize[req_buffers++] = obddev->u.cli.cl_max_mds_easize;
+                req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION,
+                                      LDLM_ENQUEUE, req_buffers, reqsize, NULL);
                 if (!req)
                         RETURN(-ENOMEM);
 
@@ -242,78 +231,69 @@ int mdc_enqueue(struct obd_export *exp,
                 spin_unlock_irqrestore (&req->rq_lock, irqflags);
 
                 /* pack the intent */
-                lit = lustre_msg_buf(req->rq_reqmsg, 1, sizeof (*lit));
+                lit = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_INTENT_IT_OFF,
+                                     sizeof (*lit));
                 lit->opc = (__u64)it->it_op;
 
                 /* pack the intended request */
-                mdc_open_pack(req->rq_reqmsg, 2, data, it->it_create_mode, 0,
-                              it->it_flags, lmm, lmmsize);
+                mdc_open_pack(req->rq_reqmsg, MDS_REQ_INTENT_REC_OFF, data,
+                              it->it_create_mode, 0, it->it_flags,
+                              lmm, lmmsize);
                 /* get ready for the reply */
                 reply_buffers = 3;
                 req->rq_replen = lustre_msg_size(3, repsize);
         } else if (it->it_op & (IT_GETATTR | IT_LOOKUP | IT_CHDIR)) {
-                int valid = OBD_MD_FLNOTOBD | OBD_MD_FLEASIZE;
-                size[2] = sizeof(struct mds_body);
-                size[3] = data->namelen + 1;
+                __u64 valid = data->valid | OBD_MD_FLNOTOBD | OBD_MD_FLEASIZE;
+
+                reqsize[req_buffers++] = sizeof(struct mds_body);
+                reqsize[req_buffers++] = data->namelen + 1;
 
                 if (it->it_op & IT_GETATTR)
                         policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
-#if CONFIG_SNAPFS                
-                size[4] = sizeof(struct clonefs_info); 
-                req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 5,
-                                      size, NULL);
-#else
-                req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 4,
-                                      size, NULL);
 
-#endif
+                req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION,
+                                      LDLM_ENQUEUE, req_buffers, reqsize, NULL);
+
                 if (!req)
                         RETURN(-ENOMEM);
 
                 /* pack the intent */
-                lit = lustre_msg_buf(req->rq_reqmsg, 1, sizeof (*lit));
+                lit = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_INTENT_IT_OFF,
+                                     sizeof (*lit));
                 lit->opc = (__u64)it->it_op;
 
                 /* pack the intended request */
-                mdc_getattr_pack(req->rq_reqmsg, valid, 2, it->it_flags, data);
-#if CONFIG_SNAPFS               
-                mdc_set_clone_info(class_exp2cliimp(exp), req->rq_reqmsg, 4); 
-#endif                 
+                mdc_getattr_pack(req->rq_reqmsg, MDS_REQ_INTENT_REC_OFF,
+                                 valid, it->it_flags, data);
+                
                 /* get ready for the reply */
                 reply_buffers = 3;
                 req->rq_replen = lustre_msg_size(3, repsize);
         } else if (it->it_op == IT_READDIR) {
                 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
-#if CONFIG_SNAPFS                
-                size[1] = sizeof(struct clonefs_info); 
-                req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 2,
-                                      size, NULL);
-#else
-                req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 1,
-                                      size, NULL);
+                req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION,
+                                      LDLM_ENQUEUE, 2, reqsize, NULL);
                 
-#endif                
                 if (!req)
                         RETURN(-ENOMEM);
-#if CONFIG_SNAPFS               
-                mdc_set_clone_info(class_exp2cliimp(exp), req->rq_reqmsg, 1); 
-#endif                 
                 /* get ready for the reply */
                 reply_buffers = 1;
                 req->rq_replen = lustre_msg_size(1, repsize);
         } else if (it->it_op == IT_UNLINK) {
-                size[2] = sizeof(struct mds_body);
+                reqsize[req_buffers++] = sizeof(struct mds_body);
                 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
-                req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 3,
-                                      size, NULL);
+                req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION,
+                                      LDLM_ENQUEUE, req_buffers, reqsize, NULL);
                 if (!req)
                         RETURN(-ENOMEM);
 
                 /* pack the intended request */
-                mdc_getattr_pack(req->rq_reqmsg, 0,  2, 0, data);
+                mdc_getattr_pack(req->rq_reqmsg, MDS_REQ_INTENT_REC_OFF,
+                                 0, 0, data);
 
                 /* pack the intent */
-                lit = lustre_msg_buf(req->rq_reqmsg, 1, sizeof (*lit));
+                lit = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_INTENT_IT_OFF,
+                                     sizeof (*lit));
                 lit->opc = (__u64)it->it_op;
 
                 /* get ready for the reply */
@@ -323,6 +303,9 @@ int mdc_enqueue(struct obd_export *exp,
                 LBUG();
                 RETURN(-EINVAL);
         }
+
+        mdc_pack_secdesc(req, reqsize[0]);
+
         mdc_get_rpc_lock(obddev->u.cli.cl_rpc_lock, it);
         rc = ldlm_cli_enqueue(exp, req, obddev->obd_namespace, res_id,
                               lock_type, &policy, lock_mode, &flags,cb_blocking,
@@ -333,7 +316,9 @@ int mdc_enqueue(struct obd_export *exp,
         /* Similarly, if we're going to replay this request, we don't want to
          * actually get a lock, just perform the intent. */
         if (req->rq_transno || req->rq_replay) {
-                lockreq = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*lockreq));
+                lockreq = lustre_msg_buf(req->rq_reqmsg,
+                                         MDS_REQ_INTENT_LOCKREQ_OFF,
+                                         sizeof (*lockreq));
                 lockreq->lock_flags |= LDLM_FL_INTENT_ONLY;
         }
 
@@ -390,17 +375,15 @@ int mdc_enqueue(struct obd_export *exp,
                 struct mds_body *body;
 
                 body = lustre_swab_repbuf(req, 1, sizeof (*body),
-                                           lustre_swab_mds_body);
+                                          lustre_swab_mds_body);
                 if (body == NULL) {
                         CERROR ("Can't swab mds_body\n");
                         RETURN (-EPROTO);
                 }
 
                 if ((body->valid & OBD_MD_FLEASIZE) != 0) {
-                        void *replayea;
-                        /* The eadata is opaque; just check that it is
-                         * there.  Eventually, obd_unpackmd() will check
-                         * the contents */
+                        /* The eadata is opaque; just check that it is there.
+                         * Eventually, obd_unpackmd() will check the contents */
                         eadata = lustre_swab_repbuf(req, 2, body->eadatasize,
                                                     NULL);
                         if (eadata == NULL) {
@@ -408,10 +391,18 @@ int mdc_enqueue(struct obd_export *exp,
                                 RETURN (-EPROTO);
                         }
                         if (it->it_op & IT_OPEN) {
-                                replayea = lustre_msg_buf(req->rq_reqmsg, 4, 
-                                                          obddev->u.cli.cl_max_mds_easize);
+                                void *replayea;
+
+                                replayea = lustre_msg_buf(req->rq_reqmsg,
+                                                          MDS_REQ_INTENT_REC_OFF + 2,
+                                                          body->eadatasize);
                                 LASSERT(replayea);
                                 memcpy(replayea, eadata, body->eadatasize);
+
+                                LASSERT(req->rq_reqmsg->bufcount == 6);
+                                req->rq_reqmsg->buflens[5] = body->eadatasize;
+                                /* If this isn't the last buffer, we might
+                                 * have to shift other data around. */
                         }
                 }
         }
@@ -447,43 +438,42 @@ EXPORT_SYMBOL(mdc_enqueue);
  * Else, if DISP_LOOKUP_EXECD then d.lustre.it_status is the rc of the
  * child lookup.
  */
-int mdc_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
-                    struct ll_fid *pfid, const char *name, int len,
-                    void *lmm, int lmmsize, struct ll_fid *cfid,
-                    struct lookup_intent *it, int lookup_flags,
-                    struct ptlrpc_request **reqp,
+int mdc_intent_lock(struct obd_export *exp, struct lustre_id *pid, 
+                    const char *name, int len, void *lmm, int lmmsize, 
+                    struct lustre_id *cid, struct lookup_intent *it, 
+                    int lookup_flags, struct ptlrpc_request **reqp,
                     ldlm_blocking_callback cb_blocking)
 {
         struct lustre_handle lockh;
         struct ptlrpc_request *request;
-        int rc = 0;
         struct mds_body *mds_body;
         struct lustre_handle old_lock;
         struct ldlm_lock *lock;
+        int rc = 0;
         ENTRY;
         LASSERT(it);
 
-        CDEBUG(D_DLMTRACE, "name: %*s in %ld, intent: %s\n", len, name,
-               pfid ? (unsigned long) pfid->id : 0 , ldlm_it2str(it->it_op));
+        CDEBUG(D_DLMTRACE, "name: %*s in obj "DLID4", intent: %s flags %#o\n",
+               len, name, OLID4(pid), ldlm_it2str(it->it_op), it->it_flags);
 
-        if (cfid && (it->it_op == IT_LOOKUP || it->it_op == IT_GETATTR ||
-                     it->it_op == IT_CHDIR)) {
+        if (cid && (it->it_op == IT_LOOKUP || it->it_op == IT_GETATTR ||
+                    it->it_op == IT_CHDIR)) {
                 /* We could just return 1 immediately, but since we should only
                  * be called in revalidate_it if we already have a lock, let's
                  * verify that. */
-                struct ldlm_res_id res_id ={.name = {cfid->id,
-                                                     cfid->generation}};
+                struct ldlm_res_id res_id = {.name = {id_fid(cid),
+                                                      id_group(cid)}};
                 struct lustre_handle lockh;
                 ldlm_policy_data_t policy;
                 int mode = LCK_PR;
 
                 /* For the GETATTR case, ll_revalidate_it issues two separate
-                   queries - for LOOKUP and for UPDATE lock because if cannot
+                   queries - for LOOKUP and for UPDATE lock because it cannot
                    check them together - we might have those two bits to be
                    present in two separate granted locks */
-                policy.l_inodebits.bits = 
-                                 (it->it_op == IT_GETATTR)?MDS_INODELOCK_UPDATE:
-                                                           MDS_INODELOCK_LOOKUP;
+                policy.l_inodebits.bits = (it->it_op == IT_GETATTR) ?
+                        MDS_INODELOCK_UPDATE: MDS_INODELOCK_LOOKUP;
+                
                 mode = LCK_PR;
                 rc = ldlm_lock_match(exp->exp_obd->obd_namespace,
                                      LDLM_FL_BLOCK_GRANTED, &res_id,
@@ -500,7 +490,11 @@ int mdc_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
                                sizeof(lockh));
                         it->d.lustre.it_lock_mode = mode;
                 }
-                RETURN(rc);
+
+                /* Only return failure if it was not GETATTR by cid (from
+                   inode_revalidate) */
+                if (rc || name)
+                        RETURN(rc);
         }
 
         /* lookup_it may be called only after revalidate_it has run, because
@@ -513,18 +507,58 @@ int mdc_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
          * never dropped its reference, so the refcounts are all OK */
         if (!it_disposition(it, DISP_ENQ_COMPLETE)) {
                 struct mdc_op_data op_data;
-                mdc_fid2mdc_op_data(&op_data, uctxt, pfid, cfid, name, len, 0);
+
+                mdc_id2mdc_data(&op_data, pid, cid, name, len, 0);
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+                /* 
+                 * This is optimization. Now fid will not be obtained from
+                 * server if client inode already exists. This flag is set in
+                 * ll_revalidate_it() if it finds that passed dentry contains
+                 * inode.
+                 */
+                if (!(it->d.lustre.it_int_flags && LL_IT_EXIST)) {
+#endif
+                        /* 
+                         * if we get inode by name (ll_lookup_it() case), we
+                         * always should ask for fid, as we will not be able to
+                         * take locks, revalidate dentry, etc. later with
+                         * invalid fid in inode.
+                         */
+                        if (cid == NULL && name != NULL)
+                                op_data.valid |= OBD_MD_FID;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+                }
+#endif
 
                 rc = mdc_enqueue(exp, LDLM_IBITS, it, it_to_lock_mode(it),
                                  &op_data, &lockh, lmm, lmmsize,
                                  ldlm_completion_ast, cb_blocking, NULL);
                 if (rc < 0)
                         RETURN(rc);
+                
                 memcpy(&it->d.lustre.it_lock_handle, &lockh, sizeof(lockh));
         }
         request = *reqp = it->d.lustre.it_data;
         LASSERT(request != NULL);
+        
+        /* If we're doing an IT_OPEN which did not result in an actual
+         * successful open, then we need to remove the bit which saves this
+         * request for unconditional replay.
+         *
+         * It's important that we do this first!  Otherwise we might exit the
+         * function without doing so, and try to replay a failed create (bug
+         * 3440) */
+        if (it->it_op & IT_OPEN) {
+                if (!it_disposition(it, DISP_OPEN_OPEN) ||
+                    it->d.lustre.it_status != 0) {
+                        unsigned long irqflags;
 
+                        spin_lock_irqsave(&request->rq_lock, irqflags);
+                        request->rq_replay = 0;
+                        spin_unlock_irqrestore(&request->rq_lock, irqflags);
+                }
+        }
         if (!it_disposition(it, DISP_IT_EXECD)) {
                 /* The server failed before it even started executing the
                  * intent, i.e. because it couldn't unpack the request. */
@@ -536,69 +570,65 @@ int mdc_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
                 RETURN(rc);
 
         mds_body = lustre_msg_buf(request->rq_repmsg, 1, sizeof(*mds_body));
-        LASSERT(mds_body != NULL);           /* mdc_enqueue checked */
+        LASSERT(mds_body != NULL);      /* mdc_enqueue checked */
         LASSERT_REPSWABBED(request, 1); /* mdc_enqueue swabbed */
 
-        /* If we were revalidating a fid/name pair, mark the intent in
-         * case we fail and get called again from lookup */
-        if (cfid != NULL) {
+        /* If we were revalidating a fid/name pair, mark the intent in case we
+         * fail and get called again from lookup */
+        if (cid != NULL) {
                 it_set_disposition(it, DISP_ENQ_COMPLETE);
                 /* Also: did we find the same inode? */
-                /* we have to compare all the fields but type, because
-                 * MDS can return mds/ino/generation triple if inode
-                 * lives on another MDS -bzzz */
-                if (cfid->generation != mds_body->fid1.generation ||
-                                cfid->id != mds_body->fid1.id ||
-                                cfid->mds != mds_body->fid1.mds)
+                
+                /* we have to compare all the fields but type, because MDS can
+                 * return fid/mds/ino/gen if inode lives on another MDS -bzzz */
+                if (!id_equal(cid, &mds_body->id1))
                         RETURN(-ESTALE);
         }
 
-        /* If we're doing an IT_OPEN which did not result in an actual
-         * successful open, then we need to remove the bit which saves
-         * this request for unconditional replay. */
-        if (it->it_op & IT_OPEN) {
-                if (!it_disposition(it, DISP_OPEN_OPEN) ||
-                    it->d.lustre.it_status != 0) {
-                        unsigned long irqflags;
-
-                        spin_lock_irqsave(&request->rq_lock, irqflags);
-                        request->rq_replay = 0;
-                        spin_unlock_irqrestore(&request->rq_lock, irqflags);
-                }
-        }
-
         rc = it_open_error(DISP_LOOKUP_EXECD, it);
         if (rc)
                 RETURN(rc);
 
-        /* keep requests around for the multiple phases of the call
-         * this shows the DISP_XX must guarantee we make it into the call
+        /*
+         * keep requests around for the multiple phases of the call this shows
+         * the DISP_XX must guarantee we make it into the call.
          */
         if (it_disposition(it, DISP_OPEN_CREATE) &&
             !it_open_error(DISP_OPEN_CREATE, it))
-                ptlrpc_request_addref(request);
+                ptlrpc_request_addref(request); /* balanced in ll_create_node */
         if (it_disposition(it, DISP_OPEN_OPEN) &&
             !it_open_error(DISP_OPEN_OPEN, it))
-                ptlrpc_request_addref(request);
+                ptlrpc_request_addref(request); /* balanced in ll_file_open */
 
         if (it->it_op & IT_CREAT) {
-                /* XXX this belongs in ll_create_iit */
+                /* XXX this belongs in ll_create_it */
         } else if (it->it_op == IT_OPEN) {
                 LASSERT(!it_disposition(it, DISP_OPEN_CREATE));
         } else {
                 LASSERT(it->it_op & (IT_GETATTR | IT_LOOKUP | IT_CHDIR));
         }
 
-        /* If we already have a matching lock, then cancel the new
-         * one.  We have to set the data here instead of in
-         * mdc_enqueue, because we need to use the child's inode as
-         * the l_ast_data to match, and that's not available until
-         * intent_finish has performed the iget().) */
+        /*
+         * if we already have a matching lock, then cancel the new one. We have
+         * to set the data here instead of in mdc_enqueue, because we need to
+         * use the child's inode as the l_ast_data to match, and that's not
+         * available until intent_finish has performed the iget().)
+         */
         lock = ldlm_handle2lock(&lockh);
         if (lock) {
                 ldlm_policy_data_t policy = lock->l_policy_data;
                 LDLM_DEBUG(lock, "matching against this");
                 LDLM_LOCK_PUT(lock);
+                
+                LASSERTF(id_fid(&mds_body->id1) == lock->l_resource->lr_name.name[0] &&
+                         id_group(&mds_body->id1) == lock->l_resource->lr_name.name[1],
+                         "Invalid lock is returned to client. Lock res_is: %lu/%lu, "
+                         "response res_id: %lu/%lu.\n",
+                         (unsigned long)lock->l_resource->lr_name.name[0],
+                         (unsigned long)lock->l_resource->lr_name.name[1],
+                         (unsigned long)id_fid(&mds_body->id1),
+                         (unsigned long)id_group(&mds_body->id1));
+                
                 memcpy(&old_lock, &lockh, sizeof(lockh));
                 if (ldlm_lock_match(NULL, LDLM_FL_BLOCK_GRANTED, NULL,
                                     LDLM_IBITS, &policy, LCK_NL, &old_lock)) {