Whamcloud - gitweb
LU-3435 util: Improvement to error logging for l_getidentity
[fs/lustre-release.git] / lustre / lmv / lmv_intent.c
index b1f071d..1a7fc0a 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include <lprocfs_status.h>
 #include "lmv_internal.h"
 
-int lmv_intent_remote(struct obd_export *exp, void *lmm,
-                      int lmmsize, struct lookup_intent *it,
-                      int flags, struct ptlrpc_request **reqp,
-                      ldlm_blocking_callback cb_blocking,
-                     __u64 extra_lock_flags)
+static int lmv_intent_remote(struct obd_export *exp, void *lmm,
+                            int lmmsize, struct lookup_intent *it,
+                            const struct lu_fid *parent_fid, int flags,
+                            struct ptlrpc_request **reqp,
+                            ldlm_blocking_callback cb_blocking,
+                            __u64 extra_lock_flags)
 {
        struct obd_device       *obd = exp->exp_obd;
        struct lmv_obd          *lmv = &obd->u.lmv;
@@ -109,8 +110,19 @@ int lmv_intent_remote(struct obd_export *exp, void *lmm,
                GOTO(out, rc = -ENOMEM);
 
        op_data->op_fid1 = body->fid1;
-       op_data->op_bias = MDS_CROSS_REF;
+       /* Sent the parent FID to the remote MDT */
+       if (parent_fid != NULL) {
+               /* The parent fid is only for remote open to
+                * check whether the open is from OBF,
+                * see mdt_cross_open */
+               LASSERT(it->it_op & IT_OPEN);
+               op_data->op_fid2 = *parent_fid;
+               /* Add object FID to op_fid3, in case it needs to check stale
+                * (M_CHECK_STALE), see mdc_finish_intent_lock */
+               op_data->op_fid3 = body->fid1;
+       }
 
+       op_data->op_bias = MDS_CROSS_REF;
        CDEBUG(D_INODE, "REMOTE_INTENT with fid="DFID" -> mds #%d\n",
               PFID(&body->fid1), tgt->ltd_idx);
 
@@ -120,29 +132,30 @@ int lmv_intent_remote(struct obd_export *exp, void *lmm,
         if (rc)
                 GOTO(out_free_op_data, rc);
 
-        /*
-         * LLite needs LOOKUP lock to track dentry revocation in order to
-         * maintain dcache consistency. Thus drop UPDATE lock here and put
-         * LOOKUP in request.
-         */
-        if (it->d.lustre.it_lock_mode != 0) {
-                ldlm_lock_decref((void *)&it->d.lustre.it_lock_handle,
-                                 it->d.lustre.it_lock_mode);
-                it->d.lustre.it_lock_mode = 0;
-        }
-        it->d.lustre.it_lock_handle = plock.cookie;
-        it->d.lustre.it_lock_mode = pmode;
-
-        EXIT;
+       /*
+        * LLite needs LOOKUP lock to track dentry revocation in order to
+        * maintain dcache consistency. Thus drop UPDATE|PERM lock here
+        * and put LOOKUP in request.
+        */
+       if (it->d.lustre.it_lock_mode != 0) {
+               it->d.lustre.it_remote_lock_handle =
+                                       it->d.lustre.it_lock_handle;
+               it->d.lustre.it_remote_lock_mode = it->d.lustre.it_lock_mode;
+       }
+
+       it->d.lustre.it_lock_handle = plock.cookie;
+       it->d.lustre.it_lock_mode = pmode;
+
+       EXIT;
 out_free_op_data:
-        OBD_FREE_PTR(op_data);
+       OBD_FREE_PTR(op_data);
 out:
-        if (rc && pmode)
-                ldlm_lock_decref(&plock, pmode);
+       if (rc && pmode)
+               ldlm_lock_decref(&plock, pmode);
 
-        ptlrpc_req_finished(*reqp);
-        *reqp = req;
-        return rc;
+       ptlrpc_req_finished(*reqp);
+       *reqp = req;
+       return rc;
 }
 
 /*
@@ -166,7 +179,10 @@ int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
        if (IS_ERR(tgt))
                RETURN(PTR_ERR(tgt));
 
-       if (it->it_op & IT_CREAT) {
+       /* If it is ready to open the file by FID, do not need
+        * allocate FID at all, otherwise it will confuse MDT */
+       if ((it->it_op & IT_CREAT) &&
+           !(it->it_flags & MDS_OPEN_BY_FID)) {
                /*
                 * For open with IT_CREATE and for IT_CREATE cases allocate new
                 * fid and setup FLD for it.
@@ -207,8 +223,8 @@ int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
         * Okay, MDS has returned success. Probably name has been resolved in
         * remote inode.
         */
-       rc = lmv_intent_remote(exp, lmm, lmmsize, it, flags, reqp,
-                              cb_blocking, extra_lock_flags);
+       rc = lmv_intent_remote(exp, lmm, lmmsize, it, &op_data->op_fid1, flags,
+                              reqp, cb_blocking, extra_lock_flags);
        if (rc != 0) {
                LASSERT(rc < 0);
                /*
@@ -275,7 +291,7 @@ int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
        if (likely(!(body->valid & OBD_MD_MDS)))
                RETURN(0);
 
-       rc = lmv_intent_remote(exp, lmm, lmmsize, it, flags, reqp,
+       rc = lmv_intent_remote(exp, lmm, lmmsize, it, NULL, flags, reqp,
                               cb_blocking, extra_lock_flags);
 
        RETURN(rc);