macvlan: resolve ENOENT errors on creation
authorJohn Fastabend <john.fastabend@gmail.com>
Mon, 21 Oct 2013 21:28:02 +0000 (14:28 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 22 Oct 2013 23:22:09 +0000 (19:22 -0400)
After the commit below attempting to create macvlan devices was
resulting in ENOENT errors,

# ip link add link p3p2 type macvlan
RTNETLINK answers: Invalid argument

This happens because netdev_upper_dev_link() is called before
register_netdevice() in the macvlan code. Through a call chain
this results in a call to __netdev_adjacent_dev_insert() and
finally a sysfs_create_link(). This requires the kobject of
the macvlan to be registered which is done in register_netdevice().
If there is no kobject which is the case here the ENOENT error
is seen on the command line.

To resolve this move the netdev_upper_dev_link() call below
the register_netdevice() call. This aligns with vlan driver
flow.

Regression introduced here,

commit 5831d66e8097aedfa3bc35941cf265ada2352317
Author: Veaceslav Falico <vfalico@redhat.com>
Date:   Wed Sep 25 09:20:32 2013 +0200

    net: create sysfs symlinks for neighbour devices

CC: Veaceslav Falico <vfalico@redhat.com>
CC: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
Acked-by: Veaceslav Falico <vfalico@redhat.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/macvlan.c

index 9bf46bd19b87bf947fd79e547bdde626c8a12097..cc9845ec91c1b1be56cc960a0768ee71b8db69c9 100644 (file)
@@ -828,22 +828,21 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
                eth_hw_addr_inherit(dev, lowerdev);
        }
 
+       port->count += 1;
+       err = register_netdevice(dev);
+       if (err < 0)
+               goto destroy_port;
+
        err = netdev_upper_dev_link(lowerdev, dev);
        if (err)
                goto destroy_port;
 
-       port->count += 1;
-       err = register_netdevice(dev);
-       if (err < 0)
-               goto upper_dev_unlink;
 
        list_add_tail_rcu(&vlan->list, &port->vlans);
        netif_stacked_transfer_operstate(lowerdev, dev);
 
        return 0;
 
-upper_dev_unlink:
-       netdev_upper_dev_unlink(lowerdev, dev);
 destroy_port:
        port->count -= 1;
        if (!port->count)