Patchwork [PATCHv2] tun: fix carrier on/off status

login
register
mail settings
Submitter Michael S. Tsirkin
Date Jan. 28, 2013, 10:38 a.m.
Message ID <20130128103801.GA6648@redhat.com>
Download mbox | patch
Permalink /patch/216157/
State Accepted
Delegated to: David Miller
Headers show

Comments

Michael S. Tsirkin - Jan. 28, 2013, 10:38 a.m.
Commit c8d68e6be1c3b242f1c598595830890b65cea64a removed carrier off call
from tun_detach since it's now called on queue disable and not only on
tun close.  This confuses userspace which used this flag to detect a
free tun. To fix, put this back but under if (clean).

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

---

Changes from v1:
	Don't set carrier off unless all queues are closed.

Note: didn't test in MQ mode - Jason, care checking this does the
right thing there?

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jason Wang - Jan. 28, 2013, 11 a.m.
On 01/28/2013 06:38 PM, Michael S. Tsirkin wrote:
> Commit c8d68e6be1c3b242f1c598595830890b65cea64a removed carrier off call
> from tun_detach since it's now called on queue disable and not only on
> tun close.  This confuses userspace which used this flag to detect a
> free tun. To fix, put this back but under if (clean).
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>
> ---
>
> Changes from v1:
> 	Don't set carrier off unless all queues are closed.
>
> Note: didn't test in MQ mode - Jason, care checking this does the
> right thing there?

Tested-by: Jason Wang <jasowang@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index af372d0..06b2723 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -434,10 +434,13 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
>  	}
>  
>  	if (clean) {
> -		if (tun && tun->numqueues == 0 && tun->numdisabled == 0 &&
> -		    !(tun->flags & TUN_PERSIST))
> -			if (tun->dev->reg_state == NETREG_REGISTERED)
> +		if (tun && tun->numqueues == 0 && tun->numdisabled == 0) {
> +			netif_carrier_off(tun->dev);
> +
> +			if (!(tun->flags & TUN_PERSIST) &&
> +			    tun->dev->reg_state == NETREG_REGISTERED)
>  				unregister_netdevice(tun->dev);
> +		}
>  
>  		BUG_ON(!test_bit(SOCK_EXTERNALLY_ALLOCATED,
>  				 &tfile->socket.flags));
> @@ -1644,10 +1647,10 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
>  		    device_create_file(&tun->dev->dev, &dev_attr_owner) ||
>  		    device_create_file(&tun->dev->dev, &dev_attr_group))
>  			pr_err("Failed to create tun sysfs files\n");
> -
> -		netif_carrier_on(tun->dev);
>  	}
>  
> +	netif_carrier_on(tun->dev);
> +
>  	tun_debug(KERN_INFO, tun, "tun_set_iff\n");
>  
>  	if (ifr->ifr_flags & IFF_NO_PI)
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Toralf Förster - Jan. 28, 2013, 7:38 p.m.
Tested-by: Toralf Förster <toralf.foerster@gmx.de>

On 01/28/2013 11:38 AM, Michael S. Tsirkin wrote:
> Commit c8d68e6be1c3b242f1c598595830890b65cea64a removed carrier off call
> from tun_detach since it's now called on queue disable and not only on
> tun close.  This confuses userspace which used this flag to detect a
> free tun. To fix, put this back but under if (clean).
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> 
> ---
> 
> Changes from v1:
> 	Don't set carrier off unless all queues are closed.
> 
> Note: didn't test in MQ mode - Jason, care checking this does the
> right thing there?
> 
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index af372d0..06b2723 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -434,10 +434,13 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
>  	}
>  
>  	if (clean) {
> -		if (tun && tun->numqueues == 0 && tun->numdisabled == 0 &&
> -		    !(tun->flags & TUN_PERSIST))
> -			if (tun->dev->reg_state == NETREG_REGISTERED)
> +		if (tun && tun->numqueues == 0 && tun->numdisabled == 0) {
> +			netif_carrier_off(tun->dev);
> +
> +			if (!(tun->flags & TUN_PERSIST) &&
> +			    tun->dev->reg_state == NETREG_REGISTERED)
>  				unregister_netdevice(tun->dev);
> +		}
>  
>  		BUG_ON(!test_bit(SOCK_EXTERNALLY_ALLOCATED,
>  				 &tfile->socket.flags));
> @@ -1644,10 +1647,10 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
>  		    device_create_file(&tun->dev->dev, &dev_attr_owner) ||
>  		    device_create_file(&tun->dev->dev, &dev_attr_group))
>  			pr_err("Failed to create tun sysfs files\n");
> -
> -		netif_carrier_on(tun->dev);
>  	}
>  
> +	netif_carrier_on(tun->dev);
> +
>  	tun_debug(KERN_INFO, tun, "tun_set_iff\n");
>  
>  	if (ifr->ifr_flags & IFF_NO_PI)
>
David Miller - Jan. 29, 2013, 8:45 p.m.
From: "Michael S. Tsirkin" <mst@redhat.com>
Date: Mon, 28 Jan 2013 12:38:02 +0200

> Commit c8d68e6be1c3b242f1c598595830890b65cea64a removed carrier off call
> from tun_detach since it's now called on queue disable and not only on
> tun close.  This confuses userspace which used this flag to detect a
> free tun. To fix, put this back but under if (clean).
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Applied.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Toralf Förster - Feb. 2, 2013, 10:27 a.m.
Between v3.8.0-rc5+ and v3.8.0-rc6+ the following dmesg are new :

> br0: port 4(tap3) entered forwarding state
> br0: port 4(tap3) entered forwarding state
> br0: port 3(tap2) entered forwarding state
> br0: port 3(tap2) entered forwarding state
> br0: port 2(tap1) entered forwarding state
> br0: port 2(tap1) entered forwarding state
> br0: port 1(tap0) entered forwarding state
> br0: port 1(tap0) entered forwarding state

Is this related to the original mail too ?

Patch

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index af372d0..06b2723 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -434,10 +434,13 @@  static void __tun_detach(struct tun_file *tfile, bool clean)
 	}
 
 	if (clean) {
-		if (tun && tun->numqueues == 0 && tun->numdisabled == 0 &&
-		    !(tun->flags & TUN_PERSIST))
-			if (tun->dev->reg_state == NETREG_REGISTERED)
+		if (tun && tun->numqueues == 0 && tun->numdisabled == 0) {
+			netif_carrier_off(tun->dev);
+
+			if (!(tun->flags & TUN_PERSIST) &&
+			    tun->dev->reg_state == NETREG_REGISTERED)
 				unregister_netdevice(tun->dev);
+		}
 
 		BUG_ON(!test_bit(SOCK_EXTERNALLY_ALLOCATED,
 				 &tfile->socket.flags));
@@ -1644,10 +1647,10 @@  static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
 		    device_create_file(&tun->dev->dev, &dev_attr_owner) ||
 		    device_create_file(&tun->dev->dev, &dev_attr_group))
 			pr_err("Failed to create tun sysfs files\n");
-
-		netif_carrier_on(tun->dev);
 	}
 
+	netif_carrier_on(tun->dev);
+
 	tun_debug(KERN_INFO, tun, "tun_set_iff\n");
 
 	if (ifr->ifr_flags & IFF_NO_PI)