Whamcloud - gitweb
land b1_5 onto HEAD
[fs/lustre-release.git] / lustre / liblustre / namei.c
index 2a7c5e0..f01f448 100644 (file)
 #include <time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/fcntl.h>
+#include <fcntl.h>
 #include <sys/queue.h>
 
+#ifdef HAVE_XTIO_H
+#include <xtio.h>
+#endif
 #include <sysio.h>
 #include <fs.h>
 #include <mount.h>
 #include <inode.h>
+#ifdef HAVE_FILE_H
 #include <file.h>
+#endif
 
 #undef LIST_HEAD
 
 #include "llite_lib.h"
 
-static void ll_intent_drop_lock(struct lookup_intent *it)
+void ll_intent_drop_lock(struct lookup_intent *it)
 {
         struct lustre_handle *handle;
 
@@ -58,7 +63,7 @@ static void ll_intent_drop_lock(struct lookup_intent *it)
         }
 }
 
-static void ll_intent_release(struct lookup_intent *it)
+void ll_intent_release(struct lookup_intent *it)
 {
         ENTRY;
 
@@ -99,15 +104,16 @@ void unhook_stale_inode(struct pnode *pno)
 
 void llu_lookup_finish_locks(struct lookup_intent *it, struct pnode *pnode)
 {
+        struct inode *inode;
         LASSERT(it);
         LASSERT(pnode);
 
-        if (it && pnode->p_base->pb_ino != NULL) {
-                struct inode *inode = pnode->p_base->pb_ino;
-                CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%lu/%lu)\n",
-                       inode, llu_i2info(inode)->lli_st_ino,
+        inode = pnode->p_base->pb_ino;
+        if (it->d.lustre.it_lock_mode && inode != NULL) {
+                CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%llu/%lu)\n",
+                       inode, (long long)llu_i2stat(inode)->st_ino,
                        llu_i2info(inode)->lli_st_generation);
-                mdc_set_lock_data(NULL, &it->d.lustre.it_lock_handle, inode);
+                mdc_set_lock_data(&it->d.lustre.it_lock_handle, inode);
         }
 
         /* drop lookup/getattr locks */
@@ -142,6 +148,7 @@ int llu_mdc_blocking_ast(struct ldlm_lock *lock,
         case LDLM_CB_CANCELING: {
                 struct inode *inode = llu_inode_from_lock(lock);
                 struct llu_inode_info *lli;
+                struct intnl_stat *st;
                 __u64 bits = lock->l_policy_data.l_inodebits.bits;
 
                 /* Invalidate all dentries associated with this inode */
@@ -149,19 +156,20 @@ int llu_mdc_blocking_ast(struct ldlm_lock *lock,
                         break;
 
                 lli =  llu_i2info(inode);
+                st = llu_i2stat(inode);
 
                 if (bits & MDS_INODELOCK_UPDATE)
                         clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
 
-                if (lock->l_resource->lr_name.name[0] != lli->lli_st_ino ||
-                    lock->l_resource->lr_name.name[1] != lli->lli_st_generation) {
-                        LDLM_ERROR(lock, "data mismatch with ino %lu/%lu",
-                                   lli->lli_st_ino, lli->lli_st_generation);
+                if (lock->l_resource->lr_name.name[0] != st->st_ino ||
+                    lock->l_resource->lr_name.name[1] !=lli->lli_st_generation){
+                        LDLM_ERROR(lock, "data mismatch with ino %llu/%lu",
+                                  (long long)st->st_ino,lli->lli_st_generation);
                 }
-                if (S_ISDIR(lli->lli_st_mode) &&
+                if (S_ISDIR(st->st_mode) &&
                     (bits & MDS_INODELOCK_UPDATE)) {
-                        CDEBUG(D_INODE, "invalidating inode %lu\n",
-                               lli->lli_st_ino);
+                        CDEBUG(D_INODE, "invalidating inode %llu\n",
+                               (long long)st->st_ino);
 
                         llu_invalidate_inode_pages(inode);
                 }
@@ -199,8 +207,7 @@ static int pnode_revalidate_finish(struct ptlrpc_request *req,
         if (it_disposition(it, DISP_LOOKUP_NEG))
                 RETURN(-ENOENT);
 
-        rc = mdc_req2lustre_md(llu_i2sbi(inode)->ll_mdc_exp, req, offset, 
-                               llu_i2sbi(inode)->ll_osc_exp, &md);
+        rc = mdc_req2lustre_md(req, offset, llu_i2sbi(inode)->ll_osc_exp, &md);
         if (rc)
                 RETURN(rc);
 
@@ -209,20 +216,20 @@ static int pnode_revalidate_finish(struct ptlrpc_request *req,
         RETURN(rc);
 }
 
-int llu_pb_revalidate(struct pnode *pnode, int flags, struct lookup_intent *it)
+static int llu_pb_revalidate(struct pnode *pnode, int flags,
+                             struct lookup_intent *it)
 {
         struct pnode_base *pb = pnode->p_base;
-        struct ll_fid pfid, cfid;
         struct it_cb_data icbd;
-        struct ll_uctxt ctxt;
+        struct mdc_op_data op_data;
         struct ptlrpc_request *req = NULL;
         struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
         struct obd_export *exp;
         int rc;
         ENTRY;
 
-        CDEBUG(D_VFSTRACE, "VFS Op:name=%s,intent=%x\n",
-               pb->pb_name.name, it ? it->it_op : 0);
+        CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,intent=%x\n",
+               (int)pb->pb_name.len, pb->pb_name.name, it ? it->it_op : 0);
 
         /* We don't want to cache negative dentries, so return 0 immediately.
          * We believe that this is safe, that negative dentries cannot be
@@ -237,10 +244,11 @@ int llu_pb_revalidate(struct pnode *pnode, int flags, struct lookup_intent *it)
          */
         {
                 struct llu_inode_info *lli = llu_i2info(pb->pb_ino);
+                struct intnl_stat *st = llu_i2stat(pb->pb_ino);
                 if (lli->lli_it) {
-                        CDEBUG(D_INODE, "inode %lu still have intent "
+                        CDEBUG(D_INODE, "inode %llu still have intent "
                                         "%p(opc 0x%x), release it\n",
-                                        lli->lli_st_ino, lli->lli_it,
+                                        (long long) st->st_ino, lli->lli_it,
                                         lli->lli_it->it_op);
                         ll_intent_release(lli->lli_it);
                         OBD_FREE(lli->lli_it, sizeof(*lli->lli_it));
@@ -249,8 +257,6 @@ int llu_pb_revalidate(struct pnode *pnode, int flags, struct lookup_intent *it)
         }
 
         exp = llu_i2mdcexp(pb->pb_ino);
-        ll_inode2fid(&pfid, pnode->p_parent->p_base->pb_ino);
-        ll_inode2fid(&cfid, pb->pb_ino);
         icbd.icbd_parent = pnode->p_parent->p_base->pb_ino;
         icbd.icbd_child = pnode;
 
@@ -259,12 +265,12 @@ int llu_pb_revalidate(struct pnode *pnode, int flags, struct lookup_intent *it)
                 it->it_op_release = ll_intent_release;
         }
 
-        ll_i2uctxt(&ctxt, pnode->p_parent->p_base->pb_ino, pb->pb_ino);
+        llu_prepare_mdc_op_data(&op_data, pnode->p_parent->p_base->pb_ino,
+                                pb->pb_ino, pb->pb_name.name,pb->pb_name.len,0);
 
-        rc = mdc_intent_lock(exp, &ctxt, &pfid,
-                             pb->pb_name.name, pb->pb_name.len,
-                             NULL, 0, &cfid, it, flags, &req,
-                             llu_mdc_blocking_ast);
+        rc = mdc_intent_lock(exp, &op_data, NULL, 0, it, flags,
+                             &req, llu_mdc_blocking_ast,
+                             LDLM_FL_CANCEL_ON_BLOCK);
         /* If req is NULL, then mdc_intent_lock only tried to do a lock match;
          * if all was well, it will return 1 if it found locks, 0 otherwise. */
         if (req == NULL && rc >= 0)
@@ -273,7 +279,7 @@ int llu_pb_revalidate(struct pnode *pnode, int flags, struct lookup_intent *it)
         if (rc < 0)
                 GOTO(out, rc = 0);
 
-        rc = pnode_revalidate_finish(req, 1, it, pnode);
+        rc = pnode_revalidate_finish(req, DLM_REPLY_REC_OFF, it, pnode);
         if (rc != 0) {
                 ll_intent_release(it);
                 GOTO(out, rc = 0);
@@ -334,14 +340,16 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset,
         /* NB 1 request reference will be taken away by ll_intent_lock()
          * when I return
          */
-        if (!it_disposition(it, DISP_LOOKUP_NEG) ||
-            (it->it_op & IT_CREAT)) {
+        if (!it_disposition(it, DISP_LOOKUP_NEG) || (it->it_op & IT_CREAT)) {
                 struct lustre_md md;
                 struct llu_inode_info *lli;
+                struct intnl_stat *st;
                 ENTRY;
 
-                rc = mdc_req2lustre_md(sbi->ll_mdc_exp, request, offset, 
-                                       sbi->ll_osc_exp, &md);
+                if (it_disposition(it, DISP_OPEN_CREATE))
+                        ptlrpc_req_finished(request);
+
+                rc = mdc_req2lustre_md(request, offset, sbi->ll_osc_exp, &md);
                 if (rc)
                         RETURN(rc);
 
@@ -357,9 +365,10 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset,
                 }
 
                 lli = llu_i2info(inode);
+                st = llu_i2stat(inode);
 
                 /* If this is a stat, get the authoritative file size */
-                if (it->it_op == IT_GETATTR && S_ISREG(lli->lli_st_mode) &&
+                if (it->it_op == IT_GETATTR && S_ISREG(st->st_mode) &&
                     lli->lli_smd != NULL) {
                         struct lov_stripe_md *lsm = lli->lli_smd;
                         ldlm_error_t rc;
@@ -391,7 +400,7 @@ static int lookup_it_finish(struct ptlrpc_request *request, int offset,
 struct inode *llu_inode_from_lock(struct ldlm_lock *lock)
 {
         struct inode *inode;
-        l_lock(&lock->l_resource->lr_namespace->ns_lock);
+        lock_res_and_lock(lock);
 
         if (lock->l_ast_data) {
                 inode = (struct inode *)lock->l_ast_data;
@@ -399,15 +408,14 @@ struct inode *llu_inode_from_lock(struct ldlm_lock *lock)
         } else
                 inode = NULL;
 
-        l_unlock(&lock->l_resource->lr_namespace->ns_lock);
+        unlock_res_and_lock(lock);
         return inode;
 }
 
 static int llu_lookup_it(struct inode *parent, struct pnode *pnode,
                          struct lookup_intent *it, int flags)
 {
-        struct ll_fid pfid;
-        struct ll_uctxt ctxt;
+        struct mdc_op_data op_data;
         struct it_cb_data icbd;
         struct ptlrpc_request *req = NULL;
         struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
@@ -424,19 +432,18 @@ static int llu_lookup_it(struct inode *parent, struct pnode *pnode,
 
         icbd.icbd_child = pnode;
         icbd.icbd_parent = parent;
-        icbd.icbd_child = pnode;
-        ll_inode2fid(&pfid, parent);
-        ll_i2uctxt(&ctxt, parent, NULL);
-
-        rc = mdc_intent_lock(llu_i2mdcexp(parent), &ctxt, &pfid,
-                             pnode->p_base->pb_name.name,
-                             pnode->p_base->pb_name.len,
-                             NULL, 0, NULL, it, flags, &req,
-                             llu_mdc_blocking_ast);
+
+        llu_prepare_mdc_op_data(&op_data, parent, NULL,
+                                pnode->p_base->pb_name.name,
+                                pnode->p_base->pb_name.len, flags);
+
+        rc = mdc_intent_lock(llu_i2mdcexp(parent), &op_data, NULL, 0, it,
+                             flags, &req, llu_mdc_blocking_ast,
+                             LDLM_FL_CANCEL_ON_BLOCK);
         if (rc < 0)
                 GOTO(out, rc);
-        
-        rc = lookup_it_finish(req, 1, it, &icbd);
+
+        rc = lookup_it_finish(req, DLM_REPLY_REC_OFF, it, &icbd);
         if (rc != 0) {
                 ll_intent_release(it);
                 GOTO(out, rc);
@@ -503,6 +510,12 @@ translate_lookup_intent(struct intent *intent, const char *path)
         if (it->it_flags & O_CREAT) {
                 it->it_op |= IT_CREAT;
                 it->it_create_mode = *((int*)intent->int_arg1);
+                /* bug 7278: libsysio hack. For O_EXCL, libsysio depends on
+                   this lookup to return negative result, but then there is no
+                   way to find out original intent in ll_iop_open(). So we just
+                   clear O_EXCL from libsysio flags here to avoid checking
+                   for negative result. O_EXCL will be enforced by MDS. */
+                *((int*)intent->int_arg2) &= ~O_EXCL;
         }
 
         if (intent->int_opmask & INT_GETATTR)
@@ -547,7 +560,7 @@ int llu_iop_lookup(struct pnode *pnode,
         if (pnode->p_mount->mnt_root == pnode) {
                 struct inode *i = pnode->p_base->pb_ino;
                 *inop = i;
-                return 0;
+                RETURN(0);
         }
 
         if (!pnode->p_base->pb_name.len)
@@ -559,7 +572,7 @@ int llu_iop_lookup(struct pnode *pnode,
         if (llu_pb_revalidate(pnode, 0, it)) {
                 LASSERT(pnode->p_base->pb_ino);
                 *inop = pnode->p_base->pb_ino;
-                RETURN(0);
+                GOTO(out, rc = 0);
         }
 
         rc = llu_lookup_it(pnode->p_parent->p_base->pb_ino, pnode, it, 0);
@@ -570,5 +583,7 @@ int llu_iop_lookup(struct pnode *pnode,
                         *inop = pnode->p_base->pb_ino;
         }
 
+out:
+        liblustre_wait_event(0);
         RETURN(rc);
 }