Whamcloud - gitweb
LU-2901 ldlm: fix resource/fid check, use DLDLMRES
[fs/lustre-release.git] / lustre / liblustre / namei.c
index dc54a7e..0e72637 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include <fcntl.h>
 #include <sys/queue.h>
 
-#include <sysio.h>
-#ifdef HAVE_XTIO_H
-#include <xtio.h>
-#endif
-#include <fs.h>
-#include <mount.h>
-#include <inode.h>
-#ifdef HAVE_FILE_H
-#include <file.h>
-#endif
-
-#undef LIST_HEAD
-
 #include "llite_lib.h"
+#include <lustre_fid.h>
 
 void ll_intent_drop_lock(struct lookup_intent *it)
 {
@@ -108,7 +96,7 @@ void llu_lookup_finish_locks(struct lookup_intent *it, struct pnode *pnode)
 
                 sbi = llu_i2sbi(inode);
                 md_set_lock_data(sbi->ll_md_exp,
-                                 &it->d.lustre.it_lock_handle, inode);
+                                 &it->d.lustre.it_lock_handle, inode, NULL);
         }
 
         /* drop lookup/getattr locks */
@@ -134,19 +122,23 @@ int llu_md_blocking_ast(struct ldlm_lock *lock,
         switch (flag) {
         case LDLM_CB_BLOCKING:
                 ldlm_lock2handle(lock, &lockh);
-                rc = ldlm_cli_cancel(&lockh);
+               rc = ldlm_cli_cancel(&lockh, 0);
                 if (rc < 0) {
                         CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
                         RETURN(rc);
                 }
                 break;
         case LDLM_CB_CANCELING: {
-                struct inode *inode = llu_inode_from_lock(lock);
+               struct inode *inode = llu_inode_from_resource_lock(lock);
                 struct llu_inode_info *lli;
                 struct intnl_stat *st;
                 __u64 bits = lock->l_policy_data.l_inodebits.bits;
                 struct lu_fid *fid;
 
+               /* Inode is set to lock->l_resource->lr_lvb_inode
+               * for mdc - bug 24555 */
+               LASSERT(lock->l_ast_data == NULL);
+
                 /* Invalidate all dentries associated with this inode */
                 if (inode == NULL)
                         break;
@@ -157,15 +149,10 @@ int llu_md_blocking_ast(struct ldlm_lock *lock,
                 if (bits & MDS_INODELOCK_UPDATE)
                         lli->lli_flags &= ~LLIF_MDS_SIZE_LOCK;
 
-                fid = &lli->lli_fid;
-                if (lock->l_resource->lr_name.name[0] != fid_seq(fid) ||
-                    lock->l_resource->lr_name.name[1] != fid_oid(fid) ||
-                    lock->l_resource->lr_name.name[2] != fid_ver(fid)) {
-                        LDLM_ERROR(lock,"data mismatch with ino %llu/%llu/%llu",
-                                  (long long)fid_seq(fid), 
-                                  (long long)fid_oid(fid),
-                                  (long long)fid_ver(fid));
-                }
+               fid = &lli->lli_fid;
+               if (!fid_res_name_eq(fid, &lock->l_resource->lr_name))
+                       LDLM_ERROR(lock, "data mismatch with object "
+                                  DFID" (%p)", PFID(fid), inode);
                 if (S_ISDIR(st->st_mode) &&
                     (bits & MDS_INODELOCK_UPDATE)) {
                         CDEBUG(D_INODE, "invalidating inode %llu\n",
@@ -212,7 +199,7 @@ static int pnode_revalidate_finish(struct ptlrpc_request *req,
         if (rc)
                 RETURN(rc);
 
-        llu_update_inode(inode, md.body, md.lsm);
+        llu_update_inode(inode, &md);
 
         RETURN(rc);
 }
@@ -221,7 +208,6 @@ static int llu_pb_revalidate(struct pnode *pnode, int flags,
                              struct lookup_intent *it)
 {
         struct pnode_base *pb = pnode->p_base;
-        struct it_cb_data icbd;
         struct md_op_data op_data = {{ 0 }};
         struct ptlrpc_request *req = NULL;
         struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
@@ -258,8 +244,6 @@ static int llu_pb_revalidate(struct pnode *pnode, int flags,
         }
 
         exp = llu_i2mdexp(pb->pb_ino);
-        icbd.icbd_parent = pnode->p_parent->p_base->pb_ino;
-        icbd.icbd_child = pnode;
 
         if (!it) {
                 it = &lookup_it;
@@ -332,7 +316,7 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset,
                 if (it_disposition(it, DISP_OPEN_CREATE) &&
                     !it_open_error(DISP_OPEN_CREATE, it)) {
                         LASSERT(request);
-                        LASSERT(atomic_read(&request->rq_refcount) > 1);
+                        LASSERT(cfs_atomic_read(&request->rq_refcount) > 1);
                         CDEBUG(D_INODE, "dec a ref of req %p\n", request);
                         ptlrpc_req_finished(request);
                 }
@@ -362,8 +346,7 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset,
                         if (md.lsm != NULL)
                                 obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
                         RETURN(inode ? PTR_ERR(inode) : -ENOMEM);
-                } else if (md.lsm != NULL &&
-                           llu_i2info(inode)->lli_smd != md.lsm) {
+               } else if (md.lsm != NULL) {
                         obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
                 }
 
@@ -372,16 +355,13 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset,
 
                 /* If this is a stat, get the authoritative file size */
                 if (it->it_op == IT_GETATTR && S_ISREG(st->st_mode) &&
-                    lli->lli_smd != NULL) {
-                        struct lov_stripe_md *lsm = lli->lli_smd;
+                   lli->lli_has_smd) {
                         ldlm_error_t rc;
 
-                        LASSERT(lsm->lsm_object_id != 0);
-
                         /* bug 2334: drop MDS lock before acquiring OST lock */
                         ll_intent_drop_lock(it);
 
-                        rc = llu_glimpse_size(inode);
+                        rc = cl_glimpse_size(inode);
                         if (rc) {
                                 I_RELE(inode);
                                 RETURN(rc);
@@ -400,6 +380,21 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset,
         RETURN(0);
 }
 
+struct inode *llu_inode_from_resource_lock(struct ldlm_lock *lock)
+{
+       struct inode *inode;
+       lock_res_and_lock(lock);
+
+       if (lock->l_resource->lr_lvb_inode) {
+               inode = (struct inode *)lock->l_resource->lr_lvb_inode;
+               I_REF(inode);
+       } else
+               inode = NULL;
+
+       unlock_res_and_lock(lock);
+       return inode;
+}
+
 struct inode *llu_inode_from_lock(struct ldlm_lock *lock)
 {
         struct inode *inode;
@@ -595,6 +590,8 @@ int llu_iop_lookup(struct pnode *pnode,
         }
 
 out:
+        if (it)
+                OBD_FREE(it, sizeof(*it));
         liblustre_wait_event(0);
         RETURN(rc);
 }