hal/hald/linux hald_helper.h,1.3,1.4 osspec.c,1.41,1.42

Kay Sievers kay at freedesktop.org
Tue Sep 14 05:26:26 PDT 2004


Update of /cvs/hal/hal/hald/linux
In directory gabe:/tmp/cvs-serv2334/hald/linux

Modified Files:
	hald_helper.h osspec.c 
Log Message:
2004-09-14  Kay Sievers  <kay.sievers at vrfy.org>

        Change Hotplug handling to better match the kernel. The next kernel
        version will have a u64 hotplug sequence number starting at 1.
        We can't be sure, that an ACTION != "add" is everytime a "remove" event,
        change that to pass the action string around instead of the flag.

        * hald/linux/hald_helper.h:
        * hald/linux/osspec.c:
        * tools/linux/hal_dev.c:
        * tools/linux/hal_hotplug.c:
        Change the hal_message structure to carry the u64 sequence number
        and the ACTION as a string. Change message type to an enum. Rename
        devnode to devname to match the udev name.
        Use the u64 sequence number and change the logic not to rely on
        negative numbers. The first sequence number will never be 0 in the
        kernel, so we use it if we don't get one from udev.



Index: hald_helper.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux/hald_helper.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- hald_helper.h	26 Aug 2004 22:16:17 -0000	1.3
+++ hald_helper.h	14 Sep 2004 12:26:24 -0000	1.4
@@ -30,15 +30,20 @@
 #define HALD_HELPER_SOCKET_PATH "/var/run/hal/hotplug_socket"
 #define HALD_HELPER_STRLEN 256
 
+enum hald_msg_type {
+	HALD_HOTPLUG,
+	HALD_DEVD,
+};
+
 struct hald_helper_msg
 {
-	unsigned int magic;                    /**< magic */
-	int is_hotplug_or_dev;                 /**< 1 if hotplug msg, 0 if device msg */
-	int is_add;                            /**< 1 if add, 0 if remove */
-	int seqnum;                            /**< Sequence number (may be -1 if for dev if udev has no support) */
-	char subsystem[HALD_HELPER_STRLEN];    /**< subsystem e.g. usb, pci (only for hotplug msg) */
-	char sysfs_path[HALD_HELPER_STRLEN];   /**< path into sysfs without sysfs mountpoint, e.g. /block/sda */
-	char device_node[HALD_HELPER_STRLEN];  /**< fully qualified path of device node (only for device msg) */
+	unsigned int magic;			/**< magic */
+	enum hald_msg_type type;		/**< hotplug or device node name message */
+	unsigned long long seqnum;		/**< Sequence number (may be 0 if for dev if udev has no support) */
+	char action[HALD_HELPER_STRLEN];	/**< hotplug action */
+	char subsystem[HALD_HELPER_STRLEN];	/**< subsystem e.g. usb, pci (only for hotplug msg) */
+	char sysfs_path[HALD_HELPER_STRLEN];	/**< path into sysfs without sysfs mountpoint, e.g. /block/sda */
+	char device_name[HALD_HELPER_STRLEN];	/**< absolute path of device node (only for device msg) */
 };
 
 #endif /* HALD_HELPER_H */

Index: osspec.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/osspec.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- osspec.c	13 Sep 2004 15:45:01 -0000	1.41
+++ osspec.c	14 Sep 2004 12:26:24 -0000	1.42
@@ -117,8 +117,8 @@
 
 static void hotplug_sem_up (void);
 static void hotplug_sem_down (void);
-static void hald_helper_hotplug (gboolean is_add, int seqnum, char *subsystem, char *sysfs_path);
-static void hald_helper_device_node (gboolean is_add, int seqnum, char *subsystem, char *sysfs_path, char *device_node);
+static void hald_helper_hotplug (gchar *action, guint64 seqnum, gchar *subsystem, gchar *sysfs_path);
+static void hald_helper_device_name (gchar *action, guint64 seqnum, gchar *subsystem, gchar *sysfs_path, gchar *device_name);
 static gboolean hald_helper_data (GIOChannel *source, GIOCondition condition, gpointer user_data);
 
 static HalDevice *add_device (const char *sysfs_path, const char *subsystem);
@@ -1145,17 +1145,17 @@
 
 
 static void
-hald_helper_hotplug (gboolean is_add, int seqnum, gchar *subsystem, gchar *sysfs_path)
+hald_helper_hotplug (gchar *action, guint64 seqnum, gchar *subsystem, gchar *sysfs_path)
 {
 	HalDevice *d = NULL;
 	char sysfs_path_full[SYSFS_PATH_MAX];
 
 	snprintf (sysfs_path_full, SYSFS_PATH_MAX, "%s%s", sysfs_mount_path, sysfs_path);
 
-	HAL_INFO (("%s, SEQNUM=%d subsystem=%s sysfs_path=%s",
-		   (is_add ? "add" : "rem"), seqnum, subsystem, sysfs_path_full));
+	HAL_INFO (("action=%s seqnum=%llu subsystem=%s sysfs_path=%s",
+		   action, seqnum, subsystem, sysfs_path_full));
 
-	if (is_add) {
+	if (strcmp(action, "add") == 0)  {
 		d = add_device (sysfs_path_full, subsystem);
 
 		/* if device is not already added, disable hotplug processing 
@@ -1181,7 +1181,7 @@
 				HAL_ERROR (("d is NULL!"));
 			}
 		}
-	} else {
+	} else if (strcmp(action, "remove") == 0){
 		d = rem_device (sysfs_path_full, subsystem);
 		/* if device is not already removed, disable hotplug processing 
 		 * and enable it again when the device has processed all the
@@ -1203,16 +1203,16 @@
 }
 
 static void
-hald_helper_device_node (gboolean is_add, int seqnum, gchar *subsystem, gchar *sysfs_path, gchar *device_node)
+hald_helper_device_name (gchar *action, guint64 seqnum, gchar *subsystem, gchar *sysfs_path, gchar *device_name)
 {
 	char sysfs_path_full[SYSFS_PATH_MAX];
 
 	snprintf (sysfs_path_full, SYSFS_PATH_MAX, "%s%s", sysfs_mount_path, sysfs_path);
 
-	HAL_INFO (("entering %s, Seqnum=%d  subsystem=%s devpath=%s devnode=%s",
-		   (is_add ? "add" : "rem"), seqnum, subsystem, sysfs_path, device_node));
+	HAL_INFO (("action=%s, seqnum=%llu  subsystem=%s devpath=%s devname=%s",
+		   action, seqnum, subsystem, sysfs_path, device_name));
 
-	if (is_add ) {
+	if (strcmp(action, "add") == 0) {
 
 		/* When udev gives the SEQNUM this can be synchronous. */
 		hal_device_store_match_key_value_string_async (
@@ -1220,13 +1220,13 @@
 			".udev.sysfs_path",
 			sysfs_path_full,
 			udev_node_created_cb, 
-			g_strdup (device_node), /* will be freed in udev_node_created_cb */
+			g_strdup (device_name), /* will be freed in udev_node_created_cb */
 			HAL_LINUX_HOTPLUG_TIMEOUT);
 	}
 
 	g_free (subsystem);
 	g_free (sysfs_path);
-	g_free (device_node);
+	g_free (device_name);
 }
 
 
@@ -1234,7 +1234,7 @@
 static GList *hotplug_queue = NULL;
 
 /** Last hotplug sequence number */
-static gint last_hotplug_seqnum = -1;
+static guint64 last_hotplug_seqnum = 0;
 
 /** Hotplug semaphore */
 static gint hotplug_counter = 0;
@@ -1266,7 +1266,7 @@
 		if (msg->seqnum == last_hotplug_seqnum + 1) {
 			/* yup, found it */
 			last_hotplug_seqnum = msg->seqnum;
-			hald_helper_hotplug (msg->is_add, msg->seqnum, g_strdup (msg->subsystem), 
+			hald_helper_hotplug (msg->action, msg->seqnum, g_strdup (msg->subsystem), 
 					     g_strdup (msg->sysfs_path));
 			g_free (msg);
 			hotplug_queue = g_list_delete_link (hotplug_queue, i);
@@ -1322,8 +1322,7 @@
 	GList *i;
 	struct hald_helper_msg *msg;
 
-	last_hotplug_seqnum = G_MAXINT;
-	/* find the seqnum we should start with */
+	/* find the lowest seqnum we should start with */
 	for (i = hotplug_queue; i != NULL; i = g_list_next (i)) {
 		msg = (struct hald_helper_msg *) i->data;
 		if (msg->seqnum < last_hotplug_seqnum)
@@ -1331,7 +1330,7 @@
 	}
 	--last_hotplug_seqnum;
 
-	HAL_INFO (("Starting with SEQNUM=%d", last_hotplug_seqnum+1));
+	HAL_INFO (("Starting with SEQNUM=%llu", last_hotplug_seqnum+1));
 
 	hotplug_sem_down ();
 
@@ -1388,53 +1387,53 @@
 		goto out;
 	}
 
-	if (!msg.is_hotplug_or_dev) {
-		/* device events doesn't have seqnum on them, however udev also respect sequence numbers */
-		hald_helper_device_node (msg.is_add, msg.seqnum, g_strdup (msg.subsystem), g_strdup (msg.sysfs_path), 
-					 g_strdup (msg.device_node));
-		goto out;
-	}
+	switch (msg.type) {
+	case HALD_DEVD:
+		hald_helper_device_name (msg.action, msg.seqnum, g_strdup (msg.subsystem),
+					 g_strdup (msg.sysfs_path), g_strdup (msg.device_name));
+		break;
+	case HALD_HOTPLUG:
+		/* need to process hotplug events in proper sequence */
 
-	/* need to process hotplug events in proper sequence */
+		/*HAL_INFO (("Before reordering, SEQNUM=%d, last_hotplug_seqnum=%llu, subsystem=%s, sysfs=%s",
+		  msg.seqnum, last_hotplug_seqnum, msg.subsystem, msg.sysfs_path));*/
 
-	/*HAL_INFO (("Before reordering, SEQNUM=%d, last_hotplug_seqnum=%d, subsystem=%s, sysfs=%s", 
-	  msg.seqnum, last_hotplug_seqnum, msg.subsystem, msg.sysfs_path));*/
+		if (last_hotplug_seqnum == 0 ) {
+			/* gotta start somewhere; however sleep some time to allow
+			 * some more hotplug events to propagate so we know where
+			 * we're at.
+			 *
+			 * @todo TODO: read SEQNUM from sysfs
+			 */
 
-	if (last_hotplug_seqnum == -1 ) {
-		/* gotta start somewhere; however sleep some time to allow  
-		 * some more hotplug events to propagate so we know where
-		 * we're at.
-		 *
-		 * @todo TODO FIXME XXX: The kernel should probably export the last sent SEQNUM in sysfs
-		 */
+			HAL_WARNING (("First SEQNUM=%llu; sleeping 2500ms to get a few more events", msg.seqnum));
 
-		HAL_WARNING (("First SEQNUM=%d; sleeping 2500ms to get a few more events", msg.seqnum));
+			hotplug_sem_up ();
+			g_timeout_add (2500, hald_helper_first_hotplug_event, NULL);
 
-		hotplug_sem_up ();
-		g_timeout_add (2500, hald_helper_first_hotplug_event, NULL);
+			/* so we only setup one timer */
+			last_hotplug_seqnum = msg.seqnum;
+		}
 
-		/* so we only setup one timer */
-		last_hotplug_seqnum = -2;
-	}
+		if (msg.seqnum < last_hotplug_seqnum) {
+			/* yikes, this means were started during a hotplug */
+			HAL_WARNING (("Got SEQNUM=%d, but last_hotplug_seqnum=%llu", msg.seqnum, last_hotplug_seqnum));
 
-	if (msg.seqnum < last_hotplug_seqnum) {
-		/* yikes, this means were started during a hotplug */
-		HAL_WARNING (("Got SEQNUM=%d, but last_hotplug_seqnum=%d", msg.seqnum, last_hotplug_seqnum));
+			/* have to process immediately other we may deadlock due to
+			 * the hotplug semaphore */
+			hald_helper_hotplug (msg.action, msg.seqnum, g_strdup (msg.subsystem), 
+					     g_strdup (msg.sysfs_path));
+			/* still need to process the queue though */
+			hald_helper_hotplug_process_queue ();
+			goto out;
+		}
 
-		/* have to process immediately other we may deadlock due to
-		 * the hotplug semaphore */
-		hald_helper_hotplug (msg.is_add, msg.seqnum, g_strdup (msg.subsystem), 
-				     g_strdup (msg.sysfs_path));
-		/* still need to process the queue though */
+		/* Queue up this hotplug event and process the queue */
+		HAL_INFO (("Queing up seqnum=%llu, sysfspath=%s, subsys=%s", msg.seqnum, msg.sysfs_path, msg.subsystem));
+		hotplug_queue = g_list_append (hotplug_queue, g_memdup (&msg, sizeof (struct hald_helper_msg)));
 		hald_helper_hotplug_process_queue ();
-		goto out;
+		break;
 	}
-
-	/* Queue up this hotplug event and process the queue */
-	HAL_INFO (("Queing up seqnum=%d, sysfspath=%s, subsys=%s", msg.seqnum, msg.sysfs_path, msg.subsystem));
-	hotplug_queue = g_list_append (hotplug_queue, g_memdup (&msg, sizeof (struct hald_helper_msg)));
-	hald_helper_hotplug_process_queue ();
-
 out:
 	return TRUE;
 }




More information about the hal-commit mailing list