]> git.karo-electronics.de Git - linux-beck.git/blobdiff - fs/ocfs2/dlm/dlmmaster.c
ocfs2/dlm: do not insert a new mle when another process is already migrating
[linux-beck.git] / fs / ocfs2 / dlm / dlmmaster.c
index 84f2f8079466a7fc07c8a4fda50d3513a02b68f9..9477d6e1de372427c36849b6eb3dc5a041089f64 100644 (file)
@@ -2388,8 +2388,8 @@ static void dlm_deref_lockres_worker(struct dlm_work_item *item, void *data)
 
        spin_lock(&res->spinlock);
        BUG_ON(res->state & DLM_LOCK_RES_DROPPING_REF);
+       __dlm_wait_on_lockres_flags(res, DLM_LOCK_RES_SETREF_INPROG);
        if (test_bit(node, res->refmap)) {
-               __dlm_wait_on_lockres_flags(res, DLM_LOCK_RES_SETREF_INPROG);
                dlm_lockres_clear_refmap_bit(dlm, res, node);
                cleared = 1;
        }
@@ -2519,6 +2519,11 @@ static int dlm_migrate_lockres(struct dlm_ctxt *dlm,
        spin_lock(&dlm->master_lock);
        ret = dlm_add_migration_mle(dlm, res, mle, &oldmle, name,
                                    namelen, target, dlm->node_num);
+       /* get an extra reference on the mle.
+        * otherwise the assert_master from the new
+        * master will destroy this.
+        */
+       dlm_get_mle_inuse(mle);
        spin_unlock(&dlm->master_lock);
        spin_unlock(&dlm->spinlock);
 
@@ -2544,7 +2549,7 @@ static int dlm_migrate_lockres(struct dlm_ctxt *dlm,
        }
 
 fail:
-       if (oldmle) {
+       if (ret != -EEXIST && oldmle) {
                /* master is known, detach if not already detached */
                dlm_mle_detach_hb_events(dlm, oldmle);
                dlm_put_mle(oldmle);
@@ -2554,6 +2559,7 @@ fail:
                if (mle_added) {
                        dlm_mle_detach_hb_events(dlm, mle);
                        dlm_put_mle(mle);
+                       dlm_put_mle_inuse(mle);
                } else if (mle) {
                        kmem_cache_free(dlm_mle_cache, mle);
                        mle = NULL;
@@ -2571,17 +2577,6 @@ fail:
         * ensure that all assert_master work is flushed. */
        flush_workqueue(dlm->dlm_worker);
 
-       /* get an extra reference on the mle.
-        * otherwise the assert_master from the new
-        * master will destroy this.
-        * also, make sure that all callers of dlm_get_mle
-        * take both dlm->spinlock and dlm->master_lock */
-       spin_lock(&dlm->spinlock);
-       spin_lock(&dlm->master_lock);
-       dlm_get_mle_inuse(mle);
-       spin_unlock(&dlm->master_lock);
-       spin_unlock(&dlm->spinlock);
-
        /* notify new node and send all lock state */
        /* call send_one_lockres with migration flag.
         * this serves as notice to the target node that a
@@ -3050,7 +3045,7 @@ int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data,
        int ret = 0;
 
        if (!dlm_grab(dlm))
-               return -EINVAL;
+               return 0;
 
        name = migrate->name;
        namelen = migrate->namelen;
@@ -3141,7 +3136,8 @@ static int dlm_add_migration_mle(struct dlm_ctxt *dlm,
                                mlog(0, "tried to migrate %.*s, but some "
                                     "process beat me to it\n",
                                     namelen, name);
-                               ret = -EEXIST;
+                               spin_unlock(&tmp->spinlock);
+                               return -EEXIST;
                        } else {
                                /* bad.  2 NODES are trying to migrate! */
                                mlog(ML_ERROR, "migration error  mle: "
@@ -3312,6 +3308,15 @@ top:
                            mle->new_master != dead_node)
                                continue;
 
+                       if (mle->new_master == dead_node && mle->inuse) {
+                               mlog(ML_NOTICE, "%s: target %u died during "
+                                               "migration from %u, the MLE is "
+                                               "still keep used, ignore it!\n",
+                                               dlm->name, dead_node,
+                                               mle->master);
+                               continue;
+                       }
+
                        /* If we have reached this point, this mle needs to be
                         * removed from the list and freed. */
                        dlm_clean_migration_mle(dlm, mle);