From patchwork Tue Nov 3 12:31:12 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 57300 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nA3CZ5rk014896 for ; Tue, 3 Nov 2009 12:35:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752407AbZKCMeO (ORCPT ); Tue, 3 Nov 2009 07:34:14 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751800AbZKCMeN (ORCPT ); Tue, 3 Nov 2009 07:34:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44563 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750845AbZKCMeM (ORCPT ); Tue, 3 Nov 2009 07:34:12 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nA3CXhAt010182; Tue, 3 Nov 2009 07:33:44 -0500 Received: from redhat.com (dhcp-0-94.tlv.redhat.com [10.35.0.94]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id nA3CXbDx022923; Tue, 3 Nov 2009 07:33:38 -0500 Date: Tue, 3 Nov 2009 14:31:12 +0200 From: "Michael S. Tsirkin" To: Arnd Bergmann Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, mingo@elte.hu, linux-mm@kvack.org, akpm@linux-foundation.org, hpa@zytor.com, gregory.haskins@gmail.com, Rusty Russell , s.hetze@linux-ag.com Subject: Re: [PATCHv6 1/3] tun: export underlying socket Message-ID: <20091103123112.GA4961@redhat.com> References: <20091102222612.GB15184@redhat.com> <200911031312.33580.arnd@arndb.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <200911031312.33580.arnd@arndb.de> User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/drivers/net/tun.c b/drivers/net/tun.c index b58095a..53e1806 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1405,7 +1405,8 @@ static const struct file_operations tun_fops = { .unlocked_ioctl = tun_chr_ioctl, .open = tun_chr_open, .release = tun_chr_close, - .fasync = tun_chr_fasync + .fasync = tun_chr_fasync, + .get_socket = tun_get_socket, }; static struct miscdevice tun_miscdev = { diff --git a/include/linux/fs.h b/include/linux/fs.h index 2620a8c..f2b381f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1506,6 +1506,9 @@ struct file_operations { ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); int (*setlease)(struct file *, long, struct file_lock **); +#ifdef CONFIG_NET + struct socket *(*get_socket)(struct file *file); +#endif }; struct inode_operations { diff --git a/net/socket.c b/net/socket.c index 9dff31c..700efcb 100644 --- a/net/socket.c +++ b/net/socket.c @@ -119,6 +119,11 @@ static ssize_t sock_splice_read(struct file *file, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags); +static struct socket *sock_get_socket(struct file *file) +{ + return file->private_data; /* set in sock_map_fd */ +} + /* * Socket files have a set of 'special' operations as well as the generic file ones. These don't appear * in the operation structures but are done directly via the socketcall() multiplexor. @@ -141,6 +146,7 @@ static const struct file_operations socket_file_ops = { .sendpage = sock_sendpage, .splice_write = generic_splice_sendpage, .splice_read = sock_splice_read, + .get_socket = sock_get_socket, }; /* @@ -416,8 +422,8 @@ int sock_map_fd(struct socket *sock, int flags) static struct socket *sock_from_file(struct file *file, int *err) { - if (file->f_op == &socket_file_ops) - return file->private_data; /* set in sock_map_fd */ + if (file->f_op->get_socket) + return file->f_op->get_socket(file); *err = -ENOTSOCK; return NULL;