Whamcloud - gitweb
Fix a handful of unsafe spin_unlock()s
authorpschwan <pschwan>
Sun, 23 Jun 2002 21:21:01 +0000 (21:21 +0000)
committerpschwan <pschwan>
Sun, 23 Jun 2002 21:21:01 +0000 (21:21 +0000)
lustre/ldlm/ldlm_lock.c
lustre/ldlm/ldlm_lockd.c
lustre/ldlm/ldlm_request.c

index d56e034..4c922d9 100644 (file)
@@ -462,8 +462,8 @@ int ldlm_local_lock_match(struct ldlm_namespace *ns, __u64 *res_id, __u32 type,
 
         EXIT;
  out:
-        ldlm_resource_put(res);
-        spin_unlock(&res->lr_lock);
+        if (!ldlm_resource_put(res))
+                spin_unlock(&res->lr_lock);
         return rc;
 }
 
@@ -491,8 +491,8 @@ ldlm_error_t ldlm_local_lock_create(struct ldlm_namespace *ns,
         lock = ldlm_lock_new(parent_lock, res);
         if (lock == NULL) {
                 spin_lock(&res->lr_lock);
-                ldlm_resource_put(res);
-                spin_unlock(&res->lr_lock);
+                if (!ldlm_resource_put(res))
+                        spin_unlock(&res->lr_lock);
                 RETURN(-ENOMEM);
         }
 
@@ -540,16 +540,19 @@ ldlm_error_t ldlm_local_lock_enqueue(struct lustre_handle *lockh,
                 rc = policy(lock, cookie, lock->l_req_mode, NULL);
 
                 spin_lock(&res->lr_lock);
-                ldlm_resource_put(res);
+                if (ldlm_resource_put(res))
+                        res = NULL;
 
                 if (rc == ELDLM_LOCK_CHANGED) {
-                        spin_unlock(&res->lr_lock);
+                        if (res)
+                                spin_unlock(&res->lr_lock);
                         res = lock->l_resource;
                         spin_lock(&res->lr_lock);
                         *flags |= LDLM_FL_LOCK_CHANGED;
                 } else if (rc == ELDLM_LOCK_ABORTED) {
                         /* Abort. */
-                        ldlm_resource_put(lock->l_resource);
+                        if (res && !ldlm_resource_put(res))
+                                spin_unlock(&res->lr_lock);
                         ldlm_lock_free(lock);
                         RETURN(rc);
                 }
@@ -602,12 +605,14 @@ ldlm_error_t ldlm_local_lock_enqueue(struct lustre_handle *lockh,
         /* We're called with a lock that has a referenced resource and is not on
          * any resource list.  When we added it to a list, we incurred an extra
          * reference. */
-        ldlm_resource_put(lock->l_resource);
+        if (ldlm_resource_put(lock->l_resource))
+                res = NULL;
  out_noput:
         /* Don't set 'completion_ast' until here so that if the lock is granted
          * immediately we don't do an unnecessary completion call. */
         lock->l_completion_ast = completion;
-        spin_unlock(&res->lr_lock);
+        if (res)
+                spin_unlock(&res->lr_lock);
         return ELDLM_OK;
 }
 
index e372327..f8cc24a 100644 (file)
@@ -35,6 +35,8 @@ static int _ldlm_enqueue(struct obd_device *obddev, struct ptlrpc_service *svc,
         void *cookie = NULL;
         ENTRY;
 
+        LDLM_DEBUG_NOLOCK("server-side enqueue handler START");
+
         callback = ldlm_cli_callback;
 
         dlm_req = lustre_msg_buf(req->rq_reqmsg, 0);
@@ -68,7 +70,7 @@ static int _ldlm_enqueue(struct obd_device *obddev, struct ptlrpc_service *svc,
         lock = lustre_handle2object(&lockh);
         memcpy(&lock->l_remote_handle, &dlm_req->lock_handle1,
                sizeof(lock->l_remote_handle));
-        LDLM_DEBUG(lock, "server-side enqueue handler START");
+        LDLM_DEBUG(lock, "server-side enqueue handler, new lock created");
 
         flags = dlm_req->lock_flags;
         err = ldlm_local_lock_enqueue(&lockh, cookie, cookielen, &flags,
index 709b428..b079b3b 100644 (file)
@@ -85,8 +85,8 @@ int ldlm_cli_enqueue(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
                 LDLM_DEBUG(lock, "client-side enqueue END (%s)",
                            rc == ELDLM_LOCK_ABORTED ? "ABORTED" : "FAILED");
                 spin_lock(&lock->l_resource->lr_lock);
-                ldlm_resource_put(lock->l_resource);
-                spin_unlock(&lock->l_resource->lr_lock);
+                if (!ldlm_resource_put(lock->l_resource))
+                        spin_unlock(&lock->l_resource->lr_lock);
                 ldlm_lock_free(lock);
                 GOTO(out, rc);
         }