From: Jean Tourrilhes <jt@hpl.hp.com>
To: Greg Kroah-Hartman <gregkh@suse.de>,
"David S. Miller" <davem@davemloft.net>,
Linux kernel mailing list <linux-kernel@vger.kernel.org>,
netdev@vger.kernel.org
Subject: [PATCH 2.6.20] kobject net ifindex + rename
Date: Tue, 27 Feb 2007 17:27:41 -0800 [thread overview]
Message-ID: <20070228012741.GA3988@bougret.hpl.hp.com> (raw)
Hi all,
Various hotplug packages have had trouble dealing with network
interface being renamed. I've decided to tackle this issue from two
angles :
o export ifindex to those apps, as ifindex is persistent.
o expose interface renaming as a hotplug event.
Those two changes are complementary, even an application that
would track interface by ifindex would sometime needs to know about
ifname change. My assumption is that most apps would still use ifname
for a long while to be backward compatible with older kernels.
The kobject framework is well designed, so adding these
features is trivial change and won't run the risk of breaking anything
(famous last words). Obviously, hotplug apps are free to ignore those
additional features.
Patch for 2.6.20 is attached. The patch was tested on a system
running the hotplug scripts, and on another system running udev.
Have fun...
Jean
Signed-off-by: Jean Tourrilhes <jt@hpl.hp.com>
---------------------------------------------------------
diff -u -p linux/include/linux/kobject.j1.h linux/include/linux/kobject.h
--- linux/include/linux/kobject.j1.h 2007-02-26 18:37:55.000000000 -0800
+++ linux/include/linux/kobject.h 2007-02-26 18:38:42.000000000 -0800
@@ -48,6 +48,7 @@ enum kobject_action {
KOBJ_OFFLINE = (__force kobject_action_t) 0x06, /* device offline */
KOBJ_ONLINE = (__force kobject_action_t) 0x07, /* device online */
KOBJ_MOVE = (__force kobject_action_t) 0x08, /* device move */
+ KOBJ_RENAME = (__force kobject_action_t) 0x09, /* device renamed */
};
struct kobject {
diff -u -p linux/net/core/net-sysfs.j1.c linux/net/core/net-sysfs.c
--- linux/net/core/net-sysfs.j1.c 2007-02-27 15:01:08.000000000 -0800
+++ linux/net/core/net-sysfs.c 2007-02-27 15:06:49.000000000 -0800
@@ -412,6 +412,17 @@ static int netdev_uevent(struct class_de
if ((size <= 0) || (i >= num_envp))
return -ENOMEM;
+ /* pass ifindex to uevent.
+ * ifindex is useful as it won't change (interface name may change)
+ * and is what RtNetlink uses natively. */
+ envp[i++] = buf;
+ n = snprintf(buf, size, "IFINDEX=%d", dev->ifindex) + 1;
+ buf += n;
+ size -= n;
+
+ if ((size <= 0) || (i >= num_envp))
+ return -ENOMEM;
+
envp[i] = NULL;
return 0;
}
diff -u -p linux/lib/kobject_uevent.j1.c linux/lib/kobject_uevent.c
--- linux/lib/kobject_uevent.j1.c 2007-02-26 18:38:02.000000000 -0800
+++ linux/lib/kobject_uevent.c 2007-02-26 18:38:42.000000000 -0800
@@ -52,6 +52,8 @@ static char *action_to_string(enum kobje
return "online";
case KOBJ_MOVE:
return "move";
+ case KOBJ_RENAME:
+ return "rename";
default:
return NULL;
}
diff -u -p linux/drivers/base/class.j1.c linux/drivers/base/class.c
--- linux/drivers/base/class.j1.c 2007-02-26 18:38:10.000000000 -0800
+++ linux/drivers/base/class.c 2007-02-27 15:52:37.000000000 -0800
@@ -841,6 +841,8 @@ int class_device_rename(struct class_dev
{
int error = 0;
char *old_class_name = NULL, *new_class_name = NULL;
+ char *devname_string = NULL;
+ char *envp[2];
class_dev = class_device_get(class_dev);
if (!class_dev)
@@ -849,6 +851,15 @@ int class_device_rename(struct class_dev
pr_debug("CLASS: renaming '%s' to '%s'\n", class_dev->class_id,
new_name);
+ devname_string = kmalloc(strlen(class_dev->class_id) + 15, GFP_KERNEL);
+ if (!devname_string) {
+ class_device_put(class_dev);
+ return -ENOMEM;
+ }
+ sprintf(devname_string, "INTERFACE_OLD=%s", class_dev->class_id);
+ envp[0] = devname_string;
+ envp[1] = NULL;
+
#ifdef CONFIG_SYSFS_DEPRECATED
if (class_dev->dev)
old_class_name = make_class_name(class_dev->class->name,
@@ -868,8 +879,16 @@ int class_device_rename(struct class_dev
sysfs_remove_link(&class_dev->dev->kobj, old_class_name);
}
#endif
+
+ /* This function is only used for network interface.
+ * Some hotplug package track interfaces by their name and
+ * therefore want to know when the name is changed by the user. */
+ if(!error)
+ kobject_uevent_env(&class_dev->kobj, KOBJ_RENAME, envp);
+
class_device_put(class_dev);
+ kfree(devname_string);
kfree(old_class_name);
kfree(new_class_name);
next reply other threads:[~2007-02-28 1:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-28 1:27 Jean Tourrilhes [this message]
2007-02-28 9:16 ` Johannes Berg
2007-02-28 18:51 ` Jean Tourrilhes
2007-02-28 19:03 ` Johannes Berg
2007-02-28 9:34 ` Jarek Poplawski
2007-02-28 9:52 ` Jarek Poplawski
2007-02-28 18:45 ` Jean Tourrilhes
2007-03-01 7:42 ` Jarek Poplawski
2007-03-01 19:27 ` Jean Tourrilhes
2007-03-02 9:18 ` Jarek Poplawski
2007-02-28 15:36 ` Greg KH
2007-02-28 18:43 ` Jean Tourrilhes
2007-03-01 0:26 ` Jean Tourrilhes
2007-03-01 0:37 ` Johannes Berg
2007-03-01 0:51 ` Jean Tourrilhes
2007-03-01 0:57 ` Johannes Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070228012741.GA3988@bougret.hpl.hp.com \
--to=jt@hpl.hp.com \
--cc=davem@davemloft.net \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®