]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: read-lock the cookie during srv_set_dyncookie()
authorWilly Tarreau <w@1wt.eu>
Tue, 20 Oct 2020 15:30:08 +0000 (17:30 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 22 Oct 2020 15:32:28 +0000 (17:32 +0200)
No need to use an exclusive lock on the proxy anymore when reading its
setting, a read lock is enough. A few other places continue to use a
write-lock when modifying simple flags only in order to let this
function see a consistent value all along. This might be changed in
the future using barriers and local copies.

src/server.c

index cdb5bce6840d1591c44b4cd81890c49dcdb30f91..bcef94f5babcf17741bea19c5c39cefc9fbdfa81 100644 (file)
@@ -103,7 +103,8 @@ int srv_getinter(const struct check *check)
 
 /*
  * Check that we did not get a hash collision.
- * Unlikely, but it can happen.
+ * Unlikely, but it can happen. The server's proxy must be at least
+ * read-locked.
  */
 static inline void srv_check_for_dup_dyncookie(struct server *s)
 {
@@ -127,7 +128,7 @@ static inline void srv_check_for_dup_dyncookie(struct server *s)
 }
 
 /*
- * Must be called with the server lock held, and will grab the proxy lock.
+ * Must be called with the server lock held, and will read-lock the proxy.
  */
 void srv_set_dyncookie(struct server *s)
 {
@@ -139,7 +140,7 @@ void srv_set_dyncookie(struct server *s)
        int addr_len;
        int port;
 
-       HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock);
+       HA_RWLOCK_RDLOCK(PROXY_LOCK, &p->lock);
 
        if ((s->flags & SRV_F_COOKIESET) ||
            !(s->proxy->ck_opts & PR_CK_DYNAMIC) ||
@@ -188,7 +189,7 @@ void srv_set_dyncookie(struct server *s)
        if (!(s->next_admin & SRV_ADMF_FMAINT))
                srv_check_for_dup_dyncookie(s);
  out:
-       HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->lock);
+       HA_RWLOCK_RDUNLOCK(PROXY_LOCK, &p->lock);
 }
 
 /*