[PATCH 13/46] Driver core: notify userspace of network device renames

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>
Cc: Jean Tourrilhes <jt@...>, Kay Sievers <kay.sievers@...>, Greg Kroah-Hartman <gregkh@...>
Date: Friday, April 27, 2007 - 2:53 pm

From: Jean Tourrilhes <jt@hpl.hp.com>

Provide rename event for when we rename network devices.

Signed-off-by: Jean Tourrilhes <jt@hpl.hp.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 lib/kobject.c        |   30 ++++++++++++++++++++++++++++++
 net/core/net-sysfs.c |   11 +++++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index bbbfab4..db1d237 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -311,13 +311,43 @@ EXPORT_SYMBOL(kobject_set_name);
 int kobject_rename(struct kobject * kobj, const char *new_name)
 {
 	int error = 0;
+	const char *devpath = NULL;
+	char *devpath_string = NULL;
+	char *envp[2];
 
 	kobj = kobject_get(kobj);
 	if (!kobj)
 		return -EINVAL;
 	if (!kobj->parent)
 		return -EINVAL;
+
+	devpath = kobject_get_path(kobj, GFP_KERNEL);
+	if (!devpath) {
+		error = -ENOMEM;
+		goto out;
+	}
+	devpath_string = kmalloc(strlen(devpath) + 15, GFP_KERNEL);
+	if (!devpath_string) {
+		error = -ENOMEM;
+		goto out;
+	}
+	sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
+	envp[0] = devpath_string;
+	envp[1] = NULL;
+	/* Note : if we want to send the new name alone, not the full path,
+	 * we could probably use kobject_name(kobj); */
+
 	error = sysfs_rename_dir(kobj, kobj->parent->dentry, new_name);
+
+	/* This function is mostly/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(kobj, KOBJ_MOVE, envp);
+
+out:
+	kfree(devpath_string);
+	kfree(devpath);
 	kobject_put(kobj);
 
 	return error;
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 221a64a..e441ec7 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -424,6 +424,17 @@ static int netdev_uevent(struct device *d, char **envp,
 	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;
 }
-- 
1.5.1.2

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 13/46] Driver core: notify userspace of network devic..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 14/46] Driver core: suppress uevents via filter, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 15/46] Driver core: switch firmware_class to uevent_s..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 16/46] uevent: use add_uevent_var() instead of open c..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 17/46] Driver core: add suspend() and resume() to str..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 18/46] Kobject: kobject_uevent.c: Collapse unnecessar..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 19/46] kobject: kobject_add() reference leak, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 20/46] Driver core: remove use of rwsem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 21/46] SCSI: use the proper semaphore to protect the ..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 22/46] USB: remove use of the bus rwsem, as it doesn'..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 23/46] PNP: stop using the subsystem rwsem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 24/46] Input: serio - do not touch bus's rwsem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 25/46] Input: gameport - do not touch bus's rwsem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 26/46] IDE: remove rwsem use from ide-proc core, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 27/46] IEEE1394: remove rwsem use from ieee1394 core, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 28/46] PHY: remove rwsem use from phy core, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
Re: [PATCH 28/46] PHY: remove rwsem use from phy core, Andy Fleming, (Fri Apr 27, 5:11 pm)
[PATCH 29/46] qeth: Remove usage of subsys.rwsem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 30/46] kobject core: remove rwsem from struct subsystem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 31/46] Driver core: make uevent-environment available..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 32/46] Driver core: warn when userspace writes to the..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 33/46] kobject: Comment and warning fixes to kobject.c, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 34/46] the overdue removal of the mount/umount uevents, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 35/46] debugfs: Add debugfs_create_u64(), Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 36/46] driver core: bus_add_driver should return an e..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 37/46] Driver core: use mutex instead of semaphore in..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 38/46] sysfs: bin.c printk fix, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 39/46] s390: cio: Delay uevents for subchannels, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 40/46] device_schedule_callback() needs a module refe..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 41/46] security: prevent permission checking of file ..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 42/46] define platform wakeup hook, use in pci_enable..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 43/46] s2ram: add arch irq disable/enable hooks, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 44/46] mod_sysfs_setup() doesn't return errno when ko..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 45/46] drivers/base/attribute_container.c: use mutex ..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 46/46] dev_dbg: check dev_dbg() arguments, Greg Kroah-Hartman, (Fri Apr 27, 2:54 pm)