tcp: Improved helpers to update connections after moving
When we compact the connection tables (both spliced and non-spliced) we need to move entries from one slot to another. That requires some updates in the entries themselves. Add helpers to make all the necessary updates for the spliced and non-spliced cases. This will simplify later cleanups. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
ff27fd63cd
commit
181ce83d9b
2 changed files with 23 additions and 10 deletions
16
tcp.c
16
tcp.c
|
@ -1291,11 +1291,13 @@ static void tcp_hash_remove(const struct tcp_tap_conn *conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tcp_hash_update() - Update pointer for given connection
|
* tcp_tap_conn_update() - Update tcp_tap_conn when being moved in the table
|
||||||
* @old: Old connection pointer
|
* @c: Execution context
|
||||||
* @new: New connection pointer
|
* @old: Old location of tcp_tap_conn
|
||||||
|
* @new: New location of tcp_tap_conn
|
||||||
*/
|
*/
|
||||||
static void tcp_hash_update(struct tcp_tap_conn *old, struct tcp_tap_conn *new)
|
static void tcp_tap_conn_update(struct ctx *c, struct tcp_tap_conn *old,
|
||||||
|
struct tcp_tap_conn *new)
|
||||||
{
|
{
|
||||||
struct tcp_tap_conn *entry, *prev = NULL;
|
struct tcp_tap_conn *entry, *prev = NULL;
|
||||||
int b = old->hash_bucket;
|
int b = old->hash_bucket;
|
||||||
|
@ -1314,6 +1316,8 @@ static void tcp_hash_update(struct tcp_tap_conn *old, struct tcp_tap_conn *new)
|
||||||
debug("TCP: hash table update: old index %li, new index %li, sock %i, "
|
debug("TCP: hash table update: old index %li, new index %li, sock %i, "
|
||||||
"bucket: %i, old: %p, new: %p",
|
"bucket: %i, old: %p, new: %p",
|
||||||
CONN_IDX(old), CONN_IDX(new), new->sock, b, old, new);
|
CONN_IDX(old), CONN_IDX(new), new->sock, b, old, new);
|
||||||
|
|
||||||
|
tcp_epoll_ctl(c, new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1362,9 +1366,7 @@ static void tcp_table_compact(struct ctx *c, struct tcp_tap_conn *hole)
|
||||||
memcpy(hole, from, sizeof(*hole));
|
memcpy(hole, from, sizeof(*hole));
|
||||||
|
|
||||||
to = hole;
|
to = hole;
|
||||||
tcp_hash_update(from, to);
|
tcp_tap_conn_update(c, from, to);
|
||||||
|
|
||||||
tcp_epoll_ctl(c, to);
|
|
||||||
|
|
||||||
debug("TCP: hash table compaction: old index %li, new index %li, "
|
debug("TCP: hash table compaction: old index %li, new index %li, "
|
||||||
"sock %i, from: %p, to: %p",
|
"sock %i, from: %p, to: %p",
|
||||||
|
|
17
tcp_splice.c
17
tcp_splice.c
|
@ -242,6 +242,19 @@ static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn,
|
||||||
conn_event_do(c, conn, event); \
|
conn_event_do(c, conn, event); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tcp_splice_conn_update() - Update tcp_splice_conn when being moved in the table
|
||||||
|
* @c: Execution context
|
||||||
|
* @new: New location of tcp_splice_conn
|
||||||
|
*/
|
||||||
|
static void tcp_splice_conn_update(struct ctx *c, struct tcp_splice_conn *new)
|
||||||
|
{
|
||||||
|
tcp_splice_epoll_ctl(c, new);
|
||||||
|
if (tcp_splice_epoll_ctl(c, new))
|
||||||
|
conn_flag(c, new, CLOSING);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tcp_table_splice_compact - Compact spliced connection table
|
* tcp_table_splice_compact - Compact spliced connection table
|
||||||
* @c: Execution context
|
* @c: Execution context
|
||||||
|
@ -269,9 +282,7 @@ static void tcp_table_splice_compact(struct ctx *c,
|
||||||
|
|
||||||
debug("TCP (spliced): index %li moved to %li",
|
debug("TCP (spliced): index %li moved to %li",
|
||||||
CONN_IDX(move), CONN_IDX(hole));
|
CONN_IDX(move), CONN_IDX(hole));
|
||||||
tcp_splice_epoll_ctl(c, hole);
|
tcp_splice_conn_update(c, hole);
|
||||||
if (tcp_splice_epoll_ctl(c, hole))
|
|
||||||
conn_flag(c, hole, CLOSING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue