From: Stanislav Kinsbursky <skinsbursky@parallels.com>
To: tglx@linutronix.de, mingo@redhat.com, davem@davemloft.net, hpa@zytor.com
Cc: thierry.reding@avionic-design.de, bfields@redhat.com,
eric.dumazet@gmail.com, xemul@parallels.com, neilb@suse.de,
netdev@vger.kernel.org, x86@kernel.org,
linux-kernel@vger.kernel.org, paul.gortmaker@windriver.com,
viro@zeniv.linux.org.uk, gorcunov@openvz.org,
akpm@linux-foundation.org, tim.c.chen@linux.intel.com,
devel@openvz.org, ebiederm@xmission.com
Subject: [RFC PATCH 2/5] net: split unix_bind()
Date: Wed, 15 Aug 2012 20:22:09 +0400 [thread overview]
Message-ID: <20120815162209.7598.68428.stgit@localhost.localdomain> (raw)
In-Reply-To: <20120815161141.7598.16682.stgit@localhost.localdomain>
This patch moves UNIX socket insert into separated function, because this code
will be used for unix_fbind() too.
Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com>
---
net/unix/af_unix.c | 52 +++++++++++++++++++++++++++++-----------------------
1 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index bc90ddb..b26200d 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -814,11 +814,38 @@ fail:
return NULL;
}
+static int __unix_add_sock(struct path *path, struct sock *sk,
+ struct unix_address *addr, int hash)
+{
+ struct net *net = sock_net(sk);
+ struct unix_sock *u = unix_sk(sk);
+ struct sockaddr_un *sunaddr = addr->name;
+ char *sun_path = sunaddr->sun_path;
+ struct hlist_head *list;
+
+ if (!sun_path[0]) {
+ if (__unix_find_socket_byname(net, sunaddr, addr->len,
+ sk->sk_type, hash)) {
+ unix_release_addr(addr);
+ return -EADDRINUSE;
+ }
+
+ list = &unix_socket_table[addr->hash];
+ } else {
+ list = &unix_socket_table[path->dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
+ u->path = *path;
+ }
+
+ __unix_remove_socket(sk);
+ u->addr = addr;
+ __unix_insert_socket(list, sk);
+ return 0;
+
+}
static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
{
struct sock *sk = sock->sk;
- struct net *net = sock_net(sk);
struct unix_sock *u = unix_sk(sk);
struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
char *sun_path = sunaddr->sun_path;
@@ -827,7 +854,6 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
int err;
unsigned int hash;
struct unix_address *addr;
- struct hlist_head *list;
err = -EINVAL;
if (sunaddr->sun_family != AF_UNIX)
@@ -893,27 +919,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
}
spin_lock(&unix_table_lock);
-
- err = -EADDRINUSE;
- if (!sun_path[0]) {
- if (__unix_find_socket_byname(net, sunaddr, addr->len,
- sk->sk_type, hash)) {
- unix_release_addr(addr);
- goto out_unlock;
- }
-
- list = &unix_socket_table[addr->hash];
- } else {
- list = &unix_socket_table[path.dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
- u->path = path;
- }
-
- err = 0;
- __unix_remove_socket(sk);
- u->addr = addr;
- __unix_insert_socket(list, sk);
-
-out_unlock:
+ err = __unix_add_sock(&path, sk, addr, hash);
spin_unlock(&unix_table_lock);
out_up:
mutex_unlock(&u->readlock);
next prev parent reply other threads:[~2012-08-15 16:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-15 16:21 [RFC PATCH 0/5] net: socket bind to file descriptor introduced Stanislav Kinsbursky
2012-08-15 16:22 ` [RFC PATCH 1/5] net: cleanup unix_bind() a little Stanislav Kinsbursky
2012-08-15 16:22 ` Stanislav Kinsbursky [this message]
2012-08-15 16:22 ` [RFC PATCH 3/5] net: new protocol operation fbind() introduced Stanislav Kinsbursky
2012-08-15 16:22 ` [RFC PATCH 4/5] net: fbind() for unix sockets protocol operations introduced Stanislav Kinsbursky
2012-08-15 16:22 ` [RFC PATCH 5/5] syscall: sys_fbind() introduced Stanislav Kinsbursky
2012-08-15 16:30 ` H. Peter Anvin
2012-08-15 16:43 ` Stanislav Kinsbursky
2012-08-15 16:52 ` [RFC PATCH 0/5] net: socket bind to file descriptor introduced Ben Pfaff
2012-08-15 17:54 ` H. Peter Anvin
2012-08-15 19:49 ` Eric W. Biederman
2012-08-15 20:58 ` H. Peter Anvin
2012-08-15 21:25 ` Eric W. Biederman
2012-08-16 3:03 ` Eric W. Biederman
2012-08-16 13:54 ` J. Bruce Fields
2012-08-20 10:18 ` Stanislav Kinsbursky
2012-09-04 19:00 ` J. Bruce Fields
2012-10-05 20:00 ` J. Bruce Fields
2012-10-08 8:37 ` Stanislav Kinsbursky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120815162209.7598.68428.stgit@localhost.localdomain \
--to=skinsbursky@parallels.com \
--cc=akpm@linux-foundation.org \
--cc=bfields@redhat.com \
--cc=davem@davemloft.net \
--cc=devel@openvz.org \
--cc=ebiederm@xmission.com \
--cc=eric.dumazet@gmail.com \
--cc=gorcunov@openvz.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=neilb@suse.de \
--cc=netdev@vger.kernel.org \
--cc=paul.gortmaker@windriver.com \
--cc=tglx@linutronix.de \
--cc=thierry.reding@avionic-design.de \
--cc=tim.c.chen@linux.intel.com \
--cc=viro@zeniv.linux.org.uk \
--cc=x86@kernel.org \
--cc=xemul@parallels.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).