From patchwork Fri Aug 10 12:57:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsbursky X-Patchwork-Id: 1305321 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id DBF283FC33 for ; Fri, 10 Aug 2012 13:00:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755046Ab2HJNAE (ORCPT ); Fri, 10 Aug 2012 09:00:04 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:11938 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751502Ab2HJNAD (ORCPT ); Fri, 10 Aug 2012 09:00:03 -0400 Received: from localhost.localdomain ([10.30.21.131]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id q7ACxSw0029192; Fri, 10 Aug 2012 16:59:28 +0400 (MSK) Subject: [RFC PATCH 1/2] unix sockets: add ability for search for peer from passed root To: Trond.Myklebust@netapp.com, davem@davemloft.net From: Stanislav Kinsbursky Cc: linux-nfs@vger.kernel.org, eric.dumazet@gmail.com, xemul@parallels.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bfields@fieldses.org, viro@zeniv.linux.org.uk, tim.c.chen@linux.intel.com, devel@openvz.org Date: Fri, 10 Aug 2012 16:57:30 +0400 Message-ID: <20120810125730.7115.96005.stgit@localhost.localdomain> In-Reply-To: <20120810125701.7115.71612.stgit@localhost.localdomain> References: <20120810125701.7115.71612.stgit@localhost.localdomain> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This helper is used stream sockets yet. All is simple: if non-NULL struct path was passed to unix_find_other(), then vfs_path_lookup() is called instead of kern_path(). Signed-off-by: Stanislav Kinsbursky --- include/net/af_unix.h | 2 ++ net/unix/af_unix.c | 25 ++++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/net/af_unix.h b/include/net/af_unix.h index 2ee33da..559467e 100644 --- a/include/net/af_unix.h +++ b/include/net/af_unix.h @@ -67,6 +67,8 @@ struct unix_sock { long unix_inq_len(struct sock *sk); long unix_outq_len(struct sock *sk); +int unix_stream_connect_root(struct path *root, struct socket *sock, + struct sockaddr *uaddr, int addr_len, int flags); #ifdef CONFIG_SYSCTL extern int unix_sysctl_register(struct net *net); diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 641f2e4..a790ebc 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -759,7 +759,7 @@ out: mutex_unlock(&u->readlock); return err; } -static struct sock *unix_find_other(struct net *net, +static struct sock *unix_find_other(struct net *net, struct path *root, struct sockaddr_un *sunname, int len, int type, unsigned int hash, int *error) { @@ -769,7 +769,11 @@ static struct sock *unix_find_other(struct net *net, if (sunname->sun_path[0]) { struct inode *inode; - err = kern_path(sunname->sun_path, LOOKUP_FOLLOW, &path); + + if (root) + err = vfs_path_lookup(root->dentry, root->mnt, sunname->sun_path, LOOKUP_FOLLOW, &path); + else + err = kern_path(sunname->sun_path, LOOKUP_FOLLOW, &path); if (err) goto fail; inode = path.dentry->d_inode; @@ -979,7 +983,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr, goto out; restart: - other = unix_find_other(net, sunaddr, alen, sock->type, hash, &err); + other = unix_find_other(net, NULL, sunaddr, alen, sock->type, hash, &err); if (!other) goto out; @@ -1053,8 +1057,8 @@ static long unix_wait_for_peer(struct sock *other, long timeo) return timeo; } -static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, - int addr_len, int flags) +int unix_stream_connect_root(struct path *root, struct socket *sock, + struct sockaddr *uaddr, int addr_len, int flags) { struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr; struct sock *sk = sock->sk; @@ -1098,7 +1102,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, restart: /* Find listening sock. */ - other = unix_find_other(net, sunaddr, addr_len, sk->sk_type, hash, &err); + other = unix_find_other(net, root, sunaddr, addr_len, sk->sk_type, hash, &err); if (!other) goto out; @@ -1227,6 +1231,13 @@ out: sock_put(other); return err; } +EXPORT_SYMBOL_GPL(unix_stream_connect_root); + +static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, + int addr_len, int flags) +{ + return unix_stream_connect_root(NULL, sock, uaddr, addr_len, flags); +} static int unix_socketpair(struct socket *socka, struct socket *sockb) { @@ -1508,7 +1519,7 @@ restart: if (sunaddr == NULL) goto out_free; - other = unix_find_other(net, sunaddr, namelen, sk->sk_type, + other = unix_find_other(net, NULL, sunaddr, namelen, sk->sk_type, hash, &err); if (other == NULL) goto out_free;