[PATCH] hald: handle 'move' events for network devices

Bill Nottingham notting at redhat.com
Wed Oct 3 12:41:03 PDT 2007


udev emits 'move' events when network interfaces are renamed. This patch
adds support for hald to handle such events.

Bill
-------------- next part --------------
diff -ru hal-0.5.10/hald/linux/device.c hal-0.5.10-new/hald/linux/device.c
--- hal-0.5.10/hald/linux/device.c	2007-08-28 15:30:06.000000000 -0400
+++ hal-0.5.10-new/hald/linux/device.c	2007-10-03 15:36:15.000000000 -0400
@@ -582,6 +582,18 @@
 
 	return d;
 }
+
+static gboolean
+net_refresh (HalDevice *d)
+{
+	const gchar *path, *ifname;
+	
+	path = hal_device_property_get_string (d, "linux.sysfs_path");
+	ifname = hal_util_get_last_element (path);
+	hal_device_property_set_string (d, "net.interface", ifname);
+	return TRUE;
+}
+
 static const char *
 net_get_prober (HalDevice *d)
 {
@@ -3372,6 +3384,7 @@
 { 
 	.subsystem    = "net",
 	.add          = net_add,
+	.refresh      = net_refresh,
 	.get_prober   = net_get_prober,
 	.post_probing = net_post_probing,
 	.compute_udi  = net_compute_udi,
diff -ru hal-0.5.10/hald/linux/hotplug.c hal-0.5.10-new/hald/linux/hotplug.c
--- hal-0.5.10/hald/linux/hotplug.c	2007-08-31 11:30:19.000000000 -0400
+++ hal-0.5.10-new/hald/linux/hotplug.c	2007-10-03 15:28:07.000000000 -0400
@@ -88,6 +88,12 @@
 	d = hal_device_store_match_key_value_string (hald_get_gdl (),
 						     "linux.sysfs_path",
 						     hotplug_event->sysfs.sysfs_path);
+	
+	if (d == NULL && hotplug_event->action == HOTPLUG_ACTION_MOVE) {
+		d = hal_device_store_match_key_value_string(hald_get_gdl (),
+							    "linux.sysfs_path",
+							    hotplug_event->sysfs.sysfs_path_old);
+	}
 
 #if 0
 	/* we should refresh the device when we get "change" uevent */
@@ -176,6 +182,12 @@
                                                    hotplug_event->sysfs.sysfs_path,
                                                    d,
                                                    (void *) hotplug_event);
+		} else if (hotplug_event->action == HOTPLUG_ACTION_MOVE && d != NULL) {
+			hal_device_property_set_string (d, "linux.sysfs_path", hotplug_event->sysfs.sysfs_path);
+			hotplug_event_refresh_dev (hotplug_event->sysfs.subsystem,
+                                                   hotplug_event->sysfs.sysfs_path,
+                                                   d,
+                                                   (void *) hotplug_event);
 		} else {
 			hotplug_event_end ((void *) hotplug_event);
 		}
diff -ru hal-0.5.10/hald/linux/hotplug.h hal-0.5.10-new/hald/linux/hotplug.h
--- hal-0.5.10/hald/linux/hotplug.h	2007-07-26 14:00:28.000000000 -0400
+++ hal-0.5.10-new/hald/linux/hotplug.h	2007-10-03 14:51:59.000000000 -0400
@@ -37,6 +37,7 @@
 	HOTPLUG_ACTION_ONLINE,
 	HOTPLUG_ACTION_OFFLINE,
 	HOTPLUG_ACTION_CHANGE,
+	HOTPLUG_ACTION_MOVE
 } HotplugActionType;
 
 typedef enum {
@@ -63,6 +64,7 @@
 		struct {
 			char subsystem[HAL_NAME_MAX];		/* Kernel subsystem the device belongs to */
 			char sysfs_path[HAL_PATH_MAX];		/* Kernel device devpath */
+			char sysfs_path_old[HAL_PATH_MAX];	/* Old kernel device devpath (for 'move') */
 			char device_file[HAL_PATH_MAX];	        /* Device node for the device */
 			unsigned long long seqnum;		/* kernel uevent sequence number */
 			int net_ifindex;			/* Kernel ifindex for network devices */
diff -ru hal-0.5.10/hald/linux/osspec.c hal-0.5.10-new/hald/linux/osspec.c
--- hal-0.5.10/hald/linux/osspec.c	2007-08-28 15:17:48.000000000 -0400
+++ hal-0.5.10-new/hald/linux/osspec.c	2007-10-03 15:13:32.000000000 -0400
@@ -146,6 +146,16 @@
 
 			g_snprintf (hotplug_event->sysfs.sysfs_path, sizeof (hotplug_event->sysfs.sysfs_path),
 				    "/sys%s", &key[8]);
+		} else if (strncmp(key, "DEVPATH_OLD=", 12) == 0) {
+
+                        /* md devices are handled via looking at /proc/mdstat */
+                        if (g_str_has_prefix (key + 12, "/block/md")) {
+                                HAL_INFO (("skipping md event for %s", key + 8));
+                                goto invalid;
+                        }
+
+			g_snprintf (hotplug_event->sysfs.sysfs_path_old, sizeof (hotplug_event->sysfs.sysfs_path_old),
+				    "/sys%s", &key[12]);
 		} else if (strncmp(key, "SUBSYSTEM=", 10) == 0)
 			g_strlcpy (hotplug_event->sysfs.subsystem, &key[10], sizeof (hotplug_event->sysfs.subsystem));
 		else if (strncmp(key, "DEVNAME=", 8) == 0)
@@ -233,6 +243,13 @@
 		goto out;
 	}
 
+	if (strcmp (action, "move") == 0) {
+		hotplug_event->action = HOTPLUG_ACTION_MOVE;
+		hotplug_event_enqueue (hotplug_event);
+		hotplug_event_process_queue ();
+		goto out;
+	}
+
 	if (strcmp (action, "remove") == 0) {
 		hotplug_event->action = HOTPLUG_ACTION_REMOVE;
 		hotplug_event_enqueue (hotplug_event);


More information about the hal mailing list