From f3764b873b1b95f4cd028c8fbbdd0f801fdcfe6a Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Mon, 15 Mar 2021 10:50:05 -0700 Subject: [PATCH] Save previous connected client address Our connection state spans sockets that can disconnect and reconnect. While sockets are connected we store the socket's remote address in the connection's peername and we clear it as sockets disconnect. Fencing wants to know the last connected address of the mount. It's a bit of metadata we know about the mount that can be used to find it and fence it. As we store the peer address we also stash it away as the last known peer address for the socket. Fencing can then use that instead of the current socket peer address which is guaranteed to be uninitialized because there's no socket connected. Signed-off-by: Zach Brown --- kmod/src/net.c | 7 +++++-- kmod/src/net.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/kmod/src/net.c b/kmod/src/net.c index 0199b8e9..593a62e7 100644 --- a/kmod/src/net.c +++ b/kmod/src/net.c @@ -941,6 +941,8 @@ static int sock_opts_and_names(struct scoutfs_net_connection *conn, ret = -EAFNOSUPPORT; if (ret) goto out; + + conn->last_peername = conn->peername; out: return ret; } @@ -1237,9 +1239,9 @@ restart: spin_unlock(&conn->lock); if (!test_conn_fl(conn, shutting_down)) { scoutfs_info(sb, "client "SIN_FMT" reconnect timed out, fencing", - SIN_ARG(&acc->peername)); + SIN_ARG(&acc->last_peername)); ret = scoutfs_fence_start(sb, acc->rid, - acc->peername.sin_addr.s_addr, + acc->last_peername.sin_addr.s_addr, SCOUTFS_FENCE_CLIENT_RECONNECT); if (ret) { scoutfs_err(sb, "client fence returned err %d, shutting down server", @@ -1317,6 +1319,7 @@ scoutfs_net_alloc_conn(struct super_block *sb, init_waitqueue_head(&conn->waitq); conn->sockname.sin_family = AF_INET; conn->peername.sin_family = AF_INET; + conn->last_peername.sin_family = AF_INET; INIT_LIST_HEAD(&conn->accepted_head); INIT_LIST_HEAD(&conn->accepted_list); conn->next_send_seq = 1; diff --git a/kmod/src/net.h b/kmod/src/net.h index 0b18b6ff..e16ec524 100644 --- a/kmod/src/net.h +++ b/kmod/src/net.h @@ -49,6 +49,7 @@ struct scoutfs_net_connection { u64 greeting_id; struct sockaddr_in sockname; struct sockaddr_in peername; + struct sockaddr_in last_peername; struct list_head accepted_head; struct scoutfs_net_connection *listening_conn;