From 60a5fa3ec17be8caf9b5d22f5801d76e26c6bc55 Mon Sep 17 00:00:00 2001
From: Philipp Reisner <philipp.reisner@linbit.com>
Date: Thu, 11 Oct 2018 12:53:22 +0200
Subject: [PATCH] drbd: Eliminate the dedicated ping_wait wait queue

There is no reason why not to use the resource->state_wait for the
same purpose
---
 drbd/drbd_int.h      |  3 +--
 drbd/drbd_main.c     |  1 -
 drbd/drbd_receiver.c | 15 +++++++++------
 drbd/drbd_sender.c   |  2 +-
 drbd/drbd_state.c    |  1 -
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drbd/drbd_int.h b/drbd/drbd_int.h
index 4475a7f9..2e6c1a7a 100644
--- a/drbd/drbd_int.h
+++ b/drbd/drbd_int.h
@@ -743,7 +743,7 @@ extern struct fifo_buffer *fifo_alloc(int fifo_size);
 /* flag bits per connection */
 enum {
 	SEND_PING,
-	GOT_PING_ACK,		/* set when we receive a ping_ack packet, ping_wait gets woken */
+	GOT_PING_ACK,		/* set when we receive a ping_ack packet, state_wait gets woken */
 	TWOPC_PREPARED,
 	TWOPC_YES,
 	TWOPC_NO,
@@ -939,7 +939,6 @@ struct drbd_connection {
 
 	unsigned long flags;
 	enum drbd_fencing_policy fencing_policy;
-	wait_queue_head_t ping_wait;	/* Woken upon reception of a ping, and a state change */
 
 	struct drbd_send_buffer send_buffer[2];
 	struct mutex mutex[2]; /* Protect assembling of new packet until sending it (in send_buffer) */
diff --git a/drbd/drbd_main.c b/drbd/drbd_main.c
index ce034797..88d4ef5e 100644
--- a/drbd/drbd_main.c
+++ b/drbd/drbd_main.c
@@ -3495,7 +3495,6 @@ struct drbd_connection *drbd_create_connection(struct drbd_resource *resource,
 
 	connection->cstate[NOW] = C_STANDALONE;
 	connection->peer_role[NOW] = R_UNKNOWN;
-	init_waitqueue_head(&connection->ping_wait);
 	idr_init(&connection->peer_devices);
 
 	drbd_init_workqueue(&connection->sender_work);
diff --git a/drbd/drbd_receiver.c b/drbd/drbd_receiver.c
index 027be58c..9a8ad43f 100644
--- a/drbd/drbd_receiver.c
+++ b/drbd/drbd_receiver.c
@@ -519,7 +519,8 @@ static int drbd_recv(struct drbd_connection *connection, void **buf, size_t size
 			t = rcu_dereference(connection->transport.net_conf)->ping_timeo * HZ/10;
 			rcu_read_unlock();
 
-			t = wait_event_timeout(connection->ping_wait, connection->cstate[NOW] < C_CONNECTED, t);
+			t = wait_event_timeout(connection->resource->state_wait,
+					       connection->cstate[NOW] < C_CONNECTED, t);
 
 			if (t)
 				goto out;
@@ -8223,7 +8224,6 @@ static int got_RqSReply(struct drbd_connection *connection, struct packet_info *
 	}
 
 	wake_up(&connection->resource->state_wait);
-	wake_up(&connection->ping_wait);
 
 	return 0;
 }
@@ -8334,8 +8334,10 @@ static int got_Ping(struct drbd_connection *connection, struct packet_info *pi)
 
 static int got_PingAck(struct drbd_connection *connection, struct packet_info *pi)
 {
-	if (!test_and_set_bit(GOT_PING_ACK, &connection->flags))
-		wake_up(&connection->ping_wait);
+	if (!test_bit(GOT_PING_ACK, &connection->flags)) {
+		set_bit(GOT_PING_ACK, &connection->flags);
+		wake_up(&connection->resource->state_wait);
+	}
 
 	return 0;
 }
@@ -8893,7 +8895,8 @@ int drbd_ack_receiver(struct drbd_thread *thi)
 
 		drbd_reclaim_net_peer_reqs(connection);
 
-		if (test_and_clear_bit(SEND_PING, &connection->flags)) {
+		if (test_bit(SEND_PING, &connection->flags)) {
+			clear_bit(SEND_PING, &connection->flags);
 			if (drbd_send_ping(connection)) {
 				drbd_err(connection, "drbd_send_ping has failed\n");
 				goto reconnect;
@@ -8928,7 +8931,7 @@ int drbd_ack_receiver(struct drbd_thread *thi)
 				t = rcu_dereference(connection->transport.net_conf)->ping_timeo * HZ/10;
 				rcu_read_unlock();
 
-				t = wait_event_timeout(connection->ping_wait,
+				t = wait_event_timeout(connection->resource->state_wait,
 						       connection->cstate[NOW] < C_CONNECTED,
 						       t);
 				if (t)
diff --git a/drbd/drbd_sender.c b/drbd/drbd_sender.c
index c925a535..2bdb59c6 100644
--- a/drbd/drbd_sender.c
+++ b/drbd/drbd_sender.c
@@ -896,7 +896,7 @@ void drbd_ping_peer(struct drbd_connection *connection)
 {
 	clear_bit(GOT_PING_ACK, &connection->flags);
 	request_ping(connection);
-	wait_event(connection->ping_wait,
+	wait_event(connection->resource->state_wait,
 		   test_bit(GOT_PING_ACK, &connection->flags) ||
 		   connection->cstate[NOW] < C_CONNECTED);
 }
diff --git a/drbd/drbd_state.c b/drbd/drbd_state.c
index 4b8c461d..517435f5 100644
--- a/drbd/drbd_state.c
+++ b/drbd/drbd_state.c
@@ -725,7 +725,6 @@ static enum drbd_state_rv ___end_state_change(struct drbd_resource *resource, st
 		pro_ver = min_t(unsigned int, pro_ver,
 			connection->agreed_pro_version);
 
-		wake_up(&connection->ping_wait);
 		wake_up(&connection->ee_wait);
 	}
 	resource->cached_min_aggreed_protocol_version = pro_ver;
-- 
2.34.1

