Whamcloud - gitweb
LU-15146 mdt: mdt_lvb2reply crash fix
[fs/lustre-release.git] / lustre / mdt / mdt_lvb.c
index f37fa6c..729cb8e 100644 (file)
@@ -155,13 +155,10 @@ int mdt_dom_lvbo_update(struct ldlm_resource *res, struct ldlm_lock *lock,
        ENTRY;
 
        /* Before going further let's check that OBD and export are healthy.
+        * The condition matches one in ptlrpc_send_reply()
         */
-       if (exp != NULL &&
-           (exp->exp_disconnected || exp->exp_failed ||
-            exp->exp_obd->obd_stopping)) {
-               CDEBUG(D_INFO, "Skip LVB update, export is %s, obd is %s\n",
-                      exp->exp_failed ? "failed" : "disconnected",
-                      exp->exp_obd->obd_stopping ? "stopping" : "OK");
+       if (exp && exp->exp_obd && exp->exp_obd->obd_fail) {
+               CDEBUG(D_INFO, "Skip LVB update, obd is failing over\n");
                RETURN(0);
        }
 
@@ -292,6 +289,11 @@ static int mdt_lvbo_size(struct ldlm_lock *lock)
                return qmt_hdls.qmth_lvbo_size(mdt->mdt_qmt_dev, lock);
        }
 
+       /* Always prefer DoM LVB data because layout is never returned in
+        * LVB when lock bits are combined with DoM, this is either GETATTR
+        * or OPEN enqueue. Meanwhile GL AST can be issued on such combined
+        * lock bits and it uses LVB for DoM data.
+        */
        if (ldlm_has_dom(lock))
                return sizeof(struct ost_lvb);
 
@@ -355,22 +357,23 @@ static int mdt_lvbo_fill(struct ldlm_lock *lock,
                        GOTO(out, rc = -ENOMEM);
        }
 
-       /* LVB for DoM lock is needed only for glimpse,
-        * don't fill DoM data if there is layout lock */
+       /* DOM LVB is used by glimpse and IO completion when
+        * DoM bits is always alone.
+        * If DoM bit is combined with any other bit then it is
+        * intent OPEN or GETATTR lock which is not filling
+        * LVB buffer in reply neither for DoM nor for LAYOUT.
+        */
        if (ldlm_has_dom(lock)) {
                struct ldlm_resource *res = lock->l_resource;
                int lvb_len = sizeof(struct ost_lvb);
 
                if (!mdt_dom_lvb_is_valid(res))
-                       mdt_dom_lvbo_update(lock->l_resource, lock, NULL, 0);
-
-               if (lvb_len > *lvblen)
-                       lvb_len = *lvblen;
+                       mdt_dom_lvbo_update(res, lock, NULL, 0);
 
+               LASSERT(*lvblen >= lvb_len);
                lock_res(res);
                memcpy(lvb, res->lr_lvb_data, lvb_len);
                unlock_res(res);
-
                GOTO(out, rc = lvb_len);
        }
 
@@ -408,7 +411,12 @@ static int mdt_lvbo_fill(struct ldlm_lock *lock,
                                mdt->mdt_max_mdsize = rc;
                                level = D_INFO;
                        } else {
-                               level = D_ERROR;
+                               /* The PFL layout EA could be enlarged when
+                                * the corresponding layout of some IO range
+                                * is started to be written, which can cause
+                                * other thread to get incorrect layout size
+                                * at mdt_intent_layout, see LU-13261. */
+                               level = D_LAYOUT;
                        }
                        CDEBUG_LIMIT(level, "%s: small buffer size %d for EA "
                                     "%d (max_mdsize %d): rc = %d\n",