Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=b267b179648e46ea8e2a44f7314a23eb6aee1d6c
Commit:     b267b179648e46ea8e2a44f7314a23eb6aee1d6c
Parent:     881d966b48b035ab3f3aeaae0f3d3f9b584f45b2
Author:     Eric W. Biederman <[EMAIL PROTECTED]>
AuthorDate: Wed Sep 12 13:48:45 2007 +0200
Committer:  David S. Miller <[EMAIL PROTECTED]>
CommitDate: Wed Oct 10 16:49:11 2007 -0700

    [NET]: Factor out __dev_alloc_name from dev_alloc_name
    
    When forcibly changing the network namespace of a device
    I need something that can generate a name for the device
    in the new namespace without overwriting the old name.
    
    __dev_alloc_name provides me that functionality.
    
    Signed-off-by: Eric W. Biederman <[EMAIL PROTECTED]>
    Signed-off-by: David S. Miller <[EMAIL PROTECTED]>
---
 net/core/dev.c |   48 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 3a3d5ee..520ef7b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -739,9 +739,10 @@ int dev_valid_name(const char *name)
 }
 
 /**
- *     dev_alloc_name - allocate a name for a device
- *     @dev: device
+ *     __dev_alloc_name - allocate a name for a device
+ *     @net: network namespace to allocate the device name in
  *     @name: name format string
+ *     @buf:  scratch buffer and result name string
  *
  *     Passed a format string - eg "lt%d" it will try and find a suitable
  *     id. It scans list of devices to build up a free map, then chooses
@@ -752,18 +753,13 @@ int dev_valid_name(const char *name)
  *     Returns the number of the unit assigned or a negative errno code.
  */
 
-int dev_alloc_name(struct net_device *dev, const char *name)
+static int __dev_alloc_name(struct net *net, const char *name, char *buf)
 {
        int i = 0;
-       char buf[IFNAMSIZ];
        const char *p;
        const int max_netdevices = 8*PAGE_SIZE;
        long *inuse;
        struct net_device *d;
-       struct net *net;
-
-       BUG_ON(!dev->nd_net);
-       net = dev->nd_net;
 
        p = strnchr(name, IFNAMSIZ-1, '%');
        if (p) {
@@ -787,7 +783,7 @@ int dev_alloc_name(struct net_device *dev, const char *name)
                                continue;
 
                        /*  avoid cases where sscanf is not exact inverse of 
printf */
-                       snprintf(buf, sizeof(buf), name, i);
+                       snprintf(buf, IFNAMSIZ, name, i);
                        if (!strncmp(buf, d->name, IFNAMSIZ))
                                set_bit(i, inuse);
                }
@@ -796,11 +792,9 @@ int dev_alloc_name(struct net_device *dev, const char 
*name)
                free_page((unsigned long) inuse);
        }
 
-       snprintf(buf, sizeof(buf), name, i);
-       if (!__dev_get_by_name(net, buf)) {
-               strlcpy(dev->name, buf, IFNAMSIZ);
+       snprintf(buf, IFNAMSIZ, name, i);
+       if (!__dev_get_by_name(net, buf))
                return i;
-       }
 
        /* It is possible to run out of possible slots
         * when the name is long and there isn't enough space left
@@ -809,6 +803,34 @@ int dev_alloc_name(struct net_device *dev, const char 
*name)
        return -ENFILE;
 }
 
+/**
+ *     dev_alloc_name - allocate a name for a device
+ *     @dev: device
+ *     @name: name format string
+ *
+ *     Passed a format string - eg "lt%d" it will try and find a suitable
+ *     id. It scans list of devices to build up a free map, then chooses
+ *     the first empty slot. The caller must hold the dev_base or rtnl lock
+ *     while allocating the name and adding the device in order to avoid
+ *     duplicates.
+ *     Limited to bits_per_byte * page size devices (ie 32K on most platforms).
+ *     Returns the number of the unit assigned or a negative errno code.
+ */
+
+int dev_alloc_name(struct net_device *dev, const char *name)
+{
+       char buf[IFNAMSIZ];
+       struct net *net;
+       int ret;
+
+       BUG_ON(!dev->nd_net);
+       net = dev->nd_net;
+       ret = __dev_alloc_name(net, name, buf);
+       if (ret >= 0)
+               strlcpy(dev->name, buf, IFNAMSIZ);
+       return ret;
+}
+
 
 /**
  *     dev_change_name - change name of a device
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to