Commit be6630bf authored by Pavel Emelyanov's avatar Pavel Emelyanov

sk: Opencode sk_hash_link

For simpler unix socket code move.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 518361dc
...@@ -61,11 +61,6 @@ struct unix_sk_listen_icon { ...@@ -61,11 +61,6 @@ struct unix_sk_listen_icon {
}; };
#define SK_HASH_SIZE 32 #define SK_HASH_SIZE 32
#define SK_HASH_LINK(head, key, elem) \
do { \
(elem)->next = (head)[(key) % SK_HASH_SIZE]; \
(head)[(key) % SK_HASH_SIZE] = (elem); \
} while (0)
#define __gen_static_lookup_func(ret, name, head, _member, _type, _name)\ #define __gen_static_lookup_func(ret, name, head, _member, _type, _name)\
static ret *name(_type _name) { \ static ret *name(_type _name) { \
...@@ -89,10 +84,14 @@ __gen_static_lookup_func(struct unix_sk_listen_icon, ...@@ -89,10 +84,14 @@ __gen_static_lookup_func(struct unix_sk_listen_icon,
int sk_collect_one(int ino, int family, struct socket_desc *d) int sk_collect_one(int ino, int family, struct socket_desc *d)
{ {
struct socket_desc **chain;
d->ino = ino; d->ino = ino;
d->family = family; d->family = family;
SK_HASH_LINK(sockets, ino, d); chain = &sockets[ino % SK_HASH_SIZE];
d->next = *chain;
*chain = d;
return 0; return 0;
} }
...@@ -398,18 +397,21 @@ static int unix_collect_one(const struct unix_diag_msg *m, ...@@ -398,18 +397,21 @@ static int unix_collect_one(const struct unix_diag_msg *m,
* to fix up in-flight sockets peers. * to fix up in-flight sockets peers.
*/ */
for (i = 0; i < d->nr_icons; i++) { for (i = 0; i < d->nr_icons; i++) {
struct unix_sk_listen_icon *e; struct unix_sk_listen_icon *e, **chain;
int n; int n;
e = xzalloc(sizeof(*e)); e = xzalloc(sizeof(*e));
if (!e) if (!e)
goto err; goto err;
SK_HASH_LINK(unix_listen_icons, d->icons[i], e); n = d->icons[i];
chain = &unix_listen_icons[n % SK_HASH_SIZE];
e->next = *chain;
*chain = e;
pr_debug("\t\tCollected icon %d\n", d->icons[i]); pr_debug("\t\tCollected icon %d\n", d->icons[i]);
e->peer_ino = d->icons[i]; e->peer_ino = n;
e->sk_desc = d; e->sk_desc = d;
} }
......
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