From e1ed063f7935ff2087b6b19e3fc45a66a3229f57 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Tue, 7 Feb 2012 15:57:32 +0400 Subject: [PATCH] sockets: Merge dgram and stream listeners They fully coincide now, just need to distinguish them by socket type. Thus, add the type member on the unix_sk_listen and merge two hashes. Signed-off-by: Pavel Emelyanov Signed-off-by: Cyrill Gorcunov --- sockets.c | 69 +++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/sockets.c b/sockets.c index 42ca4a55b..7b283a477 100644 --- a/sockets.c +++ b/sockets.c @@ -65,6 +65,7 @@ struct unix_sk_listen { unsigned int ino; struct sockaddr_un addr; unsigned int addrlen; + int type; struct unix_sk_listen *next; }; @@ -109,14 +110,16 @@ __gen_static_lookup_func(struct unix_sk_listen_icon, \ peer_ino, unsigned int, ino); static struct unix_sk_listen *unix_listen[SK_HASH_SIZE]; -__gen_static_lookup_func(struct unix_sk_listen, \ - lookup_unix_listen, \ - unix_listen, \ - ino, unsigned int, ino); +static struct unix_sk_listen *lookup_unix_listen(unsigned int ino, int type) +{ + struct unix_sk_listen *l; -static struct unix_sk_listen *dgram_bound[SK_HASH_SIZE]; -__gen_static_lookup_func(struct unix_sk_listen, lookup_dgram_bound, dgram_bound, ino, int, ino); + for (l = unix_listen[ino % SK_HASH_SIZE]; l != NULL; l = l->next) + if ((l->ino == ino) && (l->type == type)) + return l; + return NULL; +} static int sk_collect_one(int ino, int family, struct socket_desc *d) { @@ -720,30 +723,24 @@ static int run_connect_jobs(void) /* * Might need to resolve in-flight connection name. */ - if (cj->type == CJ_STREAM_INFLIGHT) { - struct unix_sk_listen *e; - - e = lookup_unix_listen(cj->peer); - if (!e) { - pr_err("Bad in-flight socket peer %d\n", cj->peer); - return -1; - } - - memcpy(&addr, &e->addr, sizeof(addr)); - addrlen = e->addrlen; - } else if (cj->type == CJ_DGRAM) { - struct unix_sk_listen *e; - - e = lookup_dgram_bound(cj->peer); - if (!e) { - pr_err("Bad in-flight socket peer %d\n", cj->peer); - return -1; - } - - memcpy(&addr, &e->addr, sizeof(addr)); - addrlen = e->addrlen; - } else + if (cj->type == CJ_STREAM) prep_conn_addr(cj->peer, &addr, &addrlen); + else { + struct unix_sk_listen *e; + + if (cj->type == CJ_STREAM_INFLIGHT) + e = lookup_unix_listen(cj->peer, SOCK_STREAM); + else /* if (cj->type == CJ_DGRAM) */ + e = lookup_unix_listen(cj->peer, SOCK_DGRAM); + + if (!e) { + pr_err("Bad in-flight socket peer %d\n", cj->peer); + return -1; + } + + memcpy(&addr, &e->addr, sizeof(addr)); + addrlen = e->addrlen; + } unix_show_job("Run conn", cj->fd, -1); try_again: @@ -777,16 +774,6 @@ try_again: } } - for (i = 0; i < SK_HASH_SIZE; i++) { - struct unix_sk_listen *h = dgram_bound[i]; - struct unix_sk_listen *e; - while (h) { - e = h->next; - xfree(h); - h = e; - } - } - return 0; } @@ -864,8 +851,9 @@ static int open_unix_sk_dgram(int sk, struct unix_sk_entry *ue, int img_fd) memcpy(&d->addr, &addr, sizeof(d->addr)); d->addrlen = sizeof(addr.sun_family) + ue->namelen; d->ino = ue->id; + d->type = SOCK_DGRAM; - SK_HASH_LINK(dgram_bound, d->ino, d); + SK_HASH_LINK(unix_listen, d->ino, d); } if (ue->peer) @@ -931,6 +919,7 @@ static int open_unix_sk_stream(int sk, struct unix_sk_entry *ue, int img_fd) memcpy(&e->addr, &addr, sizeof(e->addr)); e->addrlen = sizeof(e->addr.sun_family) + ue->namelen; e->ino = ue->id; + e->type = SOCK_STREAM; dprintk("\tCollected listening socket %d\n", ue->id);