Commit 2a67d8b9 authored by Philipp Reisner's avatar Philipp Reisner

drbd: Converted drbd_send_ping() and related functions from mdev to tconn

Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent 00d56944
...@@ -790,7 +790,6 @@ enum { ...@@ -790,7 +790,6 @@ enum {
RESIZE_PENDING, /* Size change detected locally, waiting for the response from RESIZE_PENDING, /* Size change detected locally, waiting for the response from
* the peer, if it changed there as well. */ * the peer, if it changed there as well. */
CONN_DRY_RUN, /* Expect disconnect after resync handshake. */ CONN_DRY_RUN, /* Expect disconnect after resync handshake. */
GOT_PING_ACK, /* set when we receive a ping_ack packet, misc wait gets woken */
NEW_CUR_UUID, /* Create new current UUID when thawing IO */ NEW_CUR_UUID, /* Create new current UUID when thawing IO */
AL_SUSPENDED, /* Activity logging is currently suspended. */ AL_SUSPENDED, /* Activity logging is currently suspended. */
AHEAD_TO_SYNC_SOURCE, /* Ahead -> SyncSource queued */ AHEAD_TO_SYNC_SOURCE, /* Ahead -> SyncSource queued */
...@@ -913,6 +912,7 @@ enum { ...@@ -913,6 +912,7 @@ enum {
DISCARD_CONCURRENT, /* Set on one node, cleared on the peer! */ DISCARD_CONCURRENT, /* Set on one node, cleared on the peer! */
SEND_PING, /* whether asender should send a ping asap */ SEND_PING, /* whether asender should send a ping asap */
SIGNAL_ASENDER, /* whether asender wants to be interrupted */ SIGNAL_ASENDER, /* whether asender wants to be interrupted */
GOT_PING_ACK, /* set when we receive a ping_ack packet, ping_wait gets woken */
}; };
struct drbd_tconn { /* is a resource from the config file */ struct drbd_tconn { /* is a resource from the config file */
...@@ -925,6 +925,7 @@ struct drbd_tconn { /* is a resource from the config file */ ...@@ -925,6 +925,7 @@ struct drbd_tconn { /* is a resource from the config file */
struct net_conf *net_conf; /* protected by get_net_conf() and put_net_conf() */ struct net_conf *net_conf; /* protected by get_net_conf() and put_net_conf() */
atomic_t net_cnt; /* Users of net_conf */ atomic_t net_cnt; /* Users of net_conf */
wait_queue_head_t net_cnt_wait; wait_queue_head_t net_cnt_wait;
wait_queue_head_t ping_wait; /* Woken upon reception of a ping, and a state change */
struct drbd_socket data; /* data/barrier/cstate/parameter packets */ struct drbd_socket data; /* data/barrier/cstate/parameter packets */
struct drbd_socket meta; /* ping/ack (metadata) packets */ struct drbd_socket meta; /* ping/ack (metadata) packets */
...@@ -1180,12 +1181,12 @@ extern int drbd_send_state(struct drbd_conf *mdev); ...@@ -1180,12 +1181,12 @@ extern int drbd_send_state(struct drbd_conf *mdev);
extern int _conn_send_cmd(struct drbd_tconn *tconn, int vnr, struct socket *sock, extern int _conn_send_cmd(struct drbd_tconn *tconn, int vnr, struct socket *sock,
enum drbd_packet cmd, struct p_header *h, size_t size, enum drbd_packet cmd, struct p_header *h, size_t size,
unsigned msg_flags); unsigned msg_flags);
extern int conn_send_cmd(struct drbd_tconn *tconn, int vnr, int use_data_socket,
enum drbd_packet cmd, struct p_header *h, size_t size);
extern int conn_send_cmd2(struct drbd_tconn *tconn, enum drbd_packet cmd, extern int conn_send_cmd2(struct drbd_tconn *tconn, enum drbd_packet cmd,
char *data, size_t size); char *data, size_t size);
#define USE_DATA_SOCKET 1 #define USE_DATA_SOCKET 1
#define USE_META_SOCKET 0 #define USE_META_SOCKET 0
extern int drbd_send_cmd(struct drbd_conf *mdev, int use_data_socket,
enum drbd_packet cmd, struct p_header *h, size_t size);
extern int drbd_send_sync_param(struct drbd_conf *mdev, struct syncer_conf *sc); extern int drbd_send_sync_param(struct drbd_conf *mdev, struct syncer_conf *sc);
extern int drbd_send_b_ack(struct drbd_conf *mdev, u32 barrier_nr, extern int drbd_send_b_ack(struct drbd_conf *mdev, u32 barrier_nr,
u32 set_size); u32 set_size);
...@@ -1886,6 +1887,12 @@ static inline int _drbd_send_cmd(struct drbd_conf *mdev, struct socket *sock, ...@@ -1886,6 +1887,12 @@ static inline int _drbd_send_cmd(struct drbd_conf *mdev, struct socket *sock,
return _conn_send_cmd(mdev->tconn, mdev->vnr, sock, cmd, h, size, msg_flags); return _conn_send_cmd(mdev->tconn, mdev->vnr, sock, cmd, h, size, msg_flags);
} }
static inline int drbd_send_cmd(struct drbd_conf *mdev, int use_data_socket,
enum drbd_packet cmd, struct p_header *h, size_t size)
{
return conn_send_cmd(mdev->tconn, mdev->vnr, use_data_socket, cmd, h, size);
}
static inline int drbd_send_short_cmd(struct drbd_conf *mdev, static inline int drbd_send_short_cmd(struct drbd_conf *mdev,
enum drbd_packet cmd) enum drbd_packet cmd)
{ {
...@@ -1893,16 +1900,16 @@ static inline int drbd_send_short_cmd(struct drbd_conf *mdev, ...@@ -1893,16 +1900,16 @@ static inline int drbd_send_short_cmd(struct drbd_conf *mdev,
return drbd_send_cmd(mdev, USE_DATA_SOCKET, cmd, &h, sizeof(h)); return drbd_send_cmd(mdev, USE_DATA_SOCKET, cmd, &h, sizeof(h));
} }
static inline int drbd_send_ping(struct drbd_conf *mdev) static inline int drbd_send_ping(struct drbd_tconn *tconn)
{ {
struct p_header h; struct p_header h;
return drbd_send_cmd(mdev, USE_META_SOCKET, P_PING, &h, sizeof(h)); return conn_send_cmd(tconn, 0, USE_META_SOCKET, P_PING, &h, sizeof(h));
} }
static inline int drbd_send_ping_ack(struct drbd_conf *mdev) static inline int drbd_send_ping_ack(struct drbd_tconn *tconn)
{ {
struct p_header h; struct p_header h;
return drbd_send_cmd(mdev, USE_META_SOCKET, P_PING_ACK, &h, sizeof(h)); return conn_send_cmd(tconn, 0, USE_META_SOCKET, P_PING_ACK, &h, sizeof(h));
} }
static inline void drbd_thread_stop(struct drbd_thread *thi) static inline void drbd_thread_stop(struct drbd_thread *thi)
......
...@@ -707,29 +707,29 @@ int _conn_send_cmd(struct drbd_tconn *tconn, int vnr, struct socket *sock, ...@@ -707,29 +707,29 @@ int _conn_send_cmd(struct drbd_tconn *tconn, int vnr, struct socket *sock,
/* don't pass the socket. we may only look at it /* don't pass the socket. we may only look at it
* when we hold the appropriate socket mutex. * when we hold the appropriate socket mutex.
*/ */
int drbd_send_cmd(struct drbd_conf *mdev, int use_data_socket, int conn_send_cmd(struct drbd_tconn *tconn, int vnr, int use_data_socket,
enum drbd_packet cmd, struct p_header *h, size_t size) enum drbd_packet cmd, struct p_header *h, size_t size)
{ {
int ok = 0; int ok = 0;
struct socket *sock; struct socket *sock;
if (use_data_socket) { if (use_data_socket) {
mutex_lock(&mdev->tconn->data.mutex); mutex_lock(&tconn->data.mutex);
sock = mdev->tconn->data.socket; sock = tconn->data.socket;
} else { } else {
mutex_lock(&mdev->tconn->meta.mutex); mutex_lock(&tconn->meta.mutex);
sock = mdev->tconn->meta.socket; sock = tconn->meta.socket;
} }
/* drbd_disconnect() could have called drbd_free_sock() /* drbd_disconnect() could have called drbd_free_sock()
* while we were waiting in down()... */ * while we were waiting in down()... */
if (likely(sock != NULL)) if (likely(sock != NULL))
ok = _drbd_send_cmd(mdev, sock, cmd, h, size, 0); ok = _conn_send_cmd(tconn, vnr, sock, cmd, h, size, 0);
if (use_data_socket) if (use_data_socket)
mutex_unlock(&mdev->tconn->data.mutex); mutex_unlock(&tconn->data.mutex);
else else
mutex_unlock(&mdev->tconn->meta.mutex); mutex_unlock(&tconn->meta.mutex);
return ok; return ok;
} }
...@@ -2191,6 +2191,7 @@ struct drbd_tconn *drbd_new_tconn(char *name) ...@@ -2191,6 +2191,7 @@ struct drbd_tconn *drbd_new_tconn(char *name)
spin_lock_init(&tconn->req_lock); spin_lock_init(&tconn->req_lock);
atomic_set(&tconn->net_cnt, 0); atomic_set(&tconn->net_cnt, 0);
init_waitqueue_head(&tconn->net_cnt_wait); init_waitqueue_head(&tconn->net_cnt_wait);
init_waitqueue_head(&tconn->ping_wait);
idr_init(&tconn->volumes); idr_init(&tconn->volumes);
drbd_init_workqueue(&tconn->data.work); drbd_init_workqueue(&tconn->data.work);
......
...@@ -4279,16 +4279,17 @@ static int got_RqSReply(struct drbd_conf *mdev, enum drbd_packet cmd) ...@@ -4279,16 +4279,17 @@ static int got_RqSReply(struct drbd_conf *mdev, enum drbd_packet cmd)
static int got_Ping(struct drbd_conf *mdev, enum drbd_packet cmd) static int got_Ping(struct drbd_conf *mdev, enum drbd_packet cmd)
{ {
return drbd_send_ping_ack(mdev); return drbd_send_ping_ack(mdev->tconn);
} }
static int got_PingAck(struct drbd_conf *mdev, enum drbd_packet cmd) static int got_PingAck(struct drbd_conf *mdev, enum drbd_packet cmd)
{ {
struct drbd_tconn *tconn = mdev->tconn;
/* restore idle timeout */ /* restore idle timeout */
mdev->tconn->meta.socket->sk->sk_rcvtimeo = mdev->tconn->net_conf->ping_int*HZ; tconn->meta.socket->sk->sk_rcvtimeo = tconn->net_conf->ping_int*HZ;
if (!test_and_set_bit(GOT_PING_ACK, &mdev->flags)) if (!test_and_set_bit(GOT_PING_ACK, &tconn->flags))
wake_up(&mdev->misc_wait); wake_up(&tconn->ping_wait);
return true; return true;
} }
...@@ -4610,7 +4611,7 @@ int drbd_asender(struct drbd_thread *thi) ...@@ -4610,7 +4611,7 @@ int drbd_asender(struct drbd_thread *thi)
while (get_t_state(thi) == RUNNING) { while (get_t_state(thi) == RUNNING) {
drbd_thread_current_set_cpu(thi); drbd_thread_current_set_cpu(thi);
if (test_and_clear_bit(SEND_PING, &tconn->flags)) { if (test_and_clear_bit(SEND_PING, &tconn->flags)) {
if (!drbd_send_ping(tconn->volume0)) { if (!drbd_send_ping(tconn)) {
conn_err(tconn, "drbd_send_ping has failed\n"); conn_err(tconn, "drbd_send_ping has failed\n");
goto reconnect; goto reconnect;
} }
......
...@@ -737,6 +737,7 @@ __drbd_set_state(struct drbd_conf *mdev, union drbd_state ns, ...@@ -737,6 +737,7 @@ __drbd_set_state(struct drbd_conf *mdev, union drbd_state ns,
wake_up(&mdev->misc_wait); wake_up(&mdev->misc_wait);
wake_up(&mdev->state_wait); wake_up(&mdev->state_wait);
wake_up(&mdev->tconn->ping_wait);
/* aborted verify run. log the last position */ /* aborted verify run. log the last position */
if ((os.conn == C_VERIFY_S || os.conn == C_VERIFY_T) && if ((os.conn == C_VERIFY_S || os.conn == C_VERIFY_T) &&
......
...@@ -730,10 +730,12 @@ static int w_resync_finished(struct drbd_work *w, int cancel) ...@@ -730,10 +730,12 @@ static int w_resync_finished(struct drbd_work *w, int cancel)
static void ping_peer(struct drbd_conf *mdev) static void ping_peer(struct drbd_conf *mdev)
{ {
clear_bit(GOT_PING_ACK, &mdev->flags); struct drbd_tconn *tconn = mdev->tconn;
request_ping(mdev->tconn);
wait_event(mdev->misc_wait, clear_bit(GOT_PING_ACK, &tconn->flags);
test_bit(GOT_PING_ACK, &mdev->flags) || mdev->state.conn < C_CONNECTED); request_ping(tconn);
wait_event(tconn->ping_wait,
test_bit(GOT_PING_ACK, &tconn->flags) || mdev->state.conn < C_CONNECTED);
} }
int drbd_resync_finished(struct drbd_conf *mdev) int drbd_resync_finished(struct drbd_conf *mdev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment