From patchwork Fri Aug 12 01:55:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 109737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8DB31B6F8A for ; Fri, 12 Aug 2011 11:58:11 +1000 (EST) Received: from localhost ([::1]:55420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qrh0d-00056J-Hv for incoming@patchwork.ozlabs.org; Thu, 11 Aug 2011 21:58:03 -0400 Received: from eggs.gnu.org ([140.186.70.92]:53828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qrh0M-0004Px-AU for qemu-devel@nongnu.org; Thu, 11 Aug 2011 21:57:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qrh0H-000898-MG for qemu-devel@nongnu.org; Thu, 11 Aug 2011 21:57:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10551) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qrh0H-000893-C1 for qemu-devel@nongnu.org; Thu, 11 Aug 2011 21:57:41 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7C1vaoV005479 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 11 Aug 2011 21:57:36 -0400 Received: from intel-e5620-16-2.englab.nay.redhat.com (intel-e5620-16-2.englab.nay.redhat.com [10.66.72.16]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p7C1vWcQ004617; Thu, 11 Aug 2011 21:57:33 -0400 To: mst@redhat.com, netdev@vger.kernel.org, jasowang@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, davem@davemloft.net From: Jason Wang Date: Fri, 12 Aug 2011 09:55:00 +0800 Message-ID: <20110812015500.31613.29559.stgit@intel-e5620-16-2.englab.nay.redhat.com> In-Reply-To: <20110812015221.31613.95001.stgit@intel-e5620-16-2.englab.nay.redhat.com> References: <20110812015221.31613.95001.stgit@intel-e5620-16-2.englab.nay.redhat.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: krkumar2@in.ibm.com, rusty@rustcorp.com.au, qemu-devel@nongnu.org, kvm@vger.kernel.org, mirq-linux@rere.qmqm.pl Subject: [Qemu-devel] [net-next RFC PATCH 2/7] tuntap: categorize ioctl X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org As we've moved socket related structure to file->private_data, we can separate system calls that only touch tfile from others as they don't need hold rtnl lock. Signed-off-by: Jason Wang --- drivers/net/tun.c | 52 ++++++++++++++++++++++++++++++++++------------------ 1 files changed, 34 insertions(+), 18 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 2739887..4cd292a 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1240,10 +1240,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, struct tun_file *tfile = file->private_data; struct tun_struct *tun; void __user* argp = (void __user*)arg; - struct sock_fprog fprog; struct ifreq ifr; - int sndbuf; - int vnet_hdr_sz; int ret; if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) @@ -1348,14 +1345,6 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ret = set_offload(tun, arg); break; - case TUNSETTXFILTER: - /* Can be set only for TAPs */ - ret = -EINVAL; - if ((tfile->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) - break; - ret = update_filter(&tfile->txflt, (void __user *)arg); - break; - case SIOCGIFHWADDR: /* Get hw address */ memcpy(ifr.ifr_hwaddr.sa_data, tun->dev->dev_addr, ETH_ALEN); @@ -1372,6 +1361,37 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ret = dev_set_mac_address(tun->dev, &ifr.ifr_hwaddr); break; + default: + ret = -EINVAL; + break; + } + +unlock: + rtnl_unlock(); + if (tun) + tun_put(tun); + return ret; +} + +static long __tun_socket_ioctl(struct file *file, unsigned int cmd, + unsigned long arg, int ifreq_len) +{ + struct tun_file *tfile = file->private_data; + void __user* argp = (void __user*)arg; + struct sock_fprog fprog; + int sndbuf; + int vnet_hdr_sz; + int ret = 0; + + switch (cmd) { + case TUNSETTXFILTER: + /* Can be set only for TAPs */ + ret = -EINVAL; + if ((tfile->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) + break; + ret = update_filter(&tfile->txflt, (void __user *)arg); + break; + case TUNGETSNDBUF: sndbuf = tfile->socket.sk->sk_sndbuf; if (copy_to_user(argp, &sndbuf, sizeof(sndbuf))) @@ -1427,21 +1447,17 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, break; default: - ret = -EINVAL; + ret = __tun_chr_ioctl(file, cmd, arg, ifreq_len); break; } -unlock: - rtnl_unlock(); - if (tun) - tun_put(tun); return ret; } static long tun_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - return __tun_chr_ioctl(file, cmd, arg, sizeof (struct ifreq)); + return __tun_socket_ioctl(file, cmd, arg, sizeof (struct ifreq)); } #ifdef CONFIG_COMPAT @@ -1469,7 +1485,7 @@ static long tun_chr_compat_ioctl(struct file *file, * driver are compatible though, we don't need to convert the * contents. */ - return __tun_chr_ioctl(file, cmd, arg, sizeof(struct compat_ifreq)); + return __tun_socket_ioctl(file, cmd, arg, sizeof(struct compat_ifreq)); } #endif /* CONFIG_COMPAT */