Commit 78886468 authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Pavel Emelyanov

inet: Use task_st futex for notification instead of per-port

The step to make file opening use the only futex.

travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent baa912bb
...@@ -35,7 +35,7 @@ struct inet_port { ...@@ -35,7 +35,7 @@ struct inet_port {
int port; int port;
int type; int type;
struct list_head type_list; struct list_head type_list;
futex_t users; atomic_t users;
mutex_t reuseaddr_lock; mutex_t reuseaddr_lock;
struct list_head list; struct list_head list;
}; };
...@@ -47,7 +47,7 @@ static struct inet_port *port_add(struct inet_sk_info *ii, int port) ...@@ -47,7 +47,7 @@ static struct inet_port *port_add(struct inet_sk_info *ii, int port)
list_for_each_entry(e, &inet_ports, list) list_for_each_entry(e, &inet_ports, list)
if (e->type == type && e->port == port) { if (e->type == type && e->port == port) {
futex_inc(&e->users); atomic_inc(&e->users);
goto out_link; goto out_link;
} }
...@@ -59,8 +59,7 @@ static struct inet_port *port_add(struct inet_sk_info *ii, int port) ...@@ -59,8 +59,7 @@ static struct inet_port *port_add(struct inet_sk_info *ii, int port)
e->port = port; e->port = port;
e->type = type; e->type = type;
futex_init(&e->users); atomic_set(&e->users, 1);
futex_inc(&e->users);
mutex_init(&e->reuseaddr_lock); mutex_init(&e->reuseaddr_lock);
INIT_LIST_HEAD(&e->type_list); INIT_LIST_HEAD(&e->type_list);
...@@ -551,6 +550,19 @@ static int inet_validate_address(InetSkEntry *ie) ...@@ -551,6 +550,19 @@ static int inet_validate_address(InetSkEntry *ie)
return -1; return -1;
} }
static void dec_users_and_wake(struct inet_port *port)
{
struct fdinfo_list_entry *fle;
struct inet_sk_info *ii;
if (atomic_dec_return(&port->users))
return;
list_for_each_entry(ii, &port->type_list, port_list) {
fle = file_master(&ii->d);
set_fds_event(fle->pid);
}
}
static int post_open_inet_sk(struct file_desc *d, int sk) static int post_open_inet_sk(struct file_desc *d, int sk)
{ {
struct inet_sk_info *ii; struct inet_sk_info *ii;
...@@ -573,7 +585,8 @@ static int post_open_inet_sk(struct file_desc *d, int sk) ...@@ -573,7 +585,8 @@ static int post_open_inet_sk(struct file_desc *d, int sk)
if (ii->ie->opts->reuseaddr) if (ii->ie->opts->reuseaddr)
return 0; return 0;
futex_wait_until(&ii->port->users, 0); while (atomic_read(&ii->port->users))
wait_fds_event();
val = ii->ie->opts->reuseaddr; val = ii->ie->opts->reuseaddr;
if (restore_opt(sk, SOL_SOCKET, SO_REUSEADDR, &val)) if (restore_opt(sk, SOL_SOCKET, SO_REUSEADDR, &val))
...@@ -677,7 +690,7 @@ static int open_inet_sk(struct file_desc *d) ...@@ -677,7 +690,7 @@ static int open_inet_sk(struct file_desc *d)
inet_connect(sk, ii)) inet_connect(sk, ii))
goto err; goto err;
done: done:
futex_dec_and_wake(&ii->port->users); dec_users_and_wake(ii->port);
if (rst_file_params(sk, ie->fown, ie->flags)) if (rst_file_params(sk, ie->fown, ie->flags))
goto err; goto err;
......
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