[PATCH] hald coldstart device mapper fix v1

W. Michael Petullo mike at flyn.org
Sat Mar 12 19:33:27 PST 2005


Hald's coldplug code currently creates hotplug events for device mapper
devices too early.  These events should be postponed until after all
other block devices have been processed.  This allows hald to assign a
parent to a device mapper device.

The attached patch addresses this issue.  In addition, this patch replaces
occurences of "sesame" with "luks."  Hald now expects LUKS devices to
be named like this:

/dev/mapper/luks_crypto_eb59030f-de81-4ae7-9628-2f4dfc852970

instead of this:

/dev/mapper/sesame_crypto_eb59030f-de81-4ae7-9628-2f4dfc852970

-- 
Mike

:wq
-------------- next part --------------
diff -u --recursive hal-cvs-vanilla/ChangeLog hal-cvs/ChangeLog
--- hal-cvs-vanilla/ChangeLog	2005-03-12 16:42:31.000000000 -0600
+++ hal-cvs/ChangeLog	2005-03-12 19:48:05.000000000 -0600
@@ -1,3 +1,10 @@
+2005-03-12  W. Michael Petullo  <mike at flyn.org>
+
+	* hald/linux2/blockdev.c: s/sesame/luks.
+
+	* hald/linux2/coldplug.c: Ensure that device mapper devices are
+	processed after all other block devices.
+
 2005-03-11  David Zeuthen  <davidz at redhat.com>
 
 	* hald/linux2/probing/probe-volume.c (main): Patch from Kay
diff -u --recursive hal-cvs-vanilla/hald/linux2/blockdev.c hal-cvs/hald/linux2/blockdev.c
--- hal-cvs-vanilla/hald/linux2/blockdev.c	2005-03-04 13:39:06.000000000 -0600
+++ hal-cvs/hald/linux2/blockdev.c	2005-03-12 17:30:03.000000000 -0600
@@ -453,10 +453,10 @@
 		* we can ask about the name for /dev/dm-0; as e.g. given by
 		* 'dmsetup info'
 		*
-		* Our assumption is that sesame-setup have invoked
+		* Our assumption is that luks-setup have invoked
 		* dmsetup; e.g. the naming convention is 
 		*
-		*    sesame_crypto_<luks_uuid>
+		*    luks_crypto_<luks_uuid>
 		*
 		* where <luks_uuid> is the UUID encoded in the luks
 		* metadata.
@@ -469,15 +469,15 @@
 			char devpath[256];
 			struct stat statbuf;
 			while ((f = g_dir_read_name (dir)) != NULL) {
-				char sesame_prefix[] = "sesame_crypto_";
+				char luks_prefix[] = "luks_crypto_";
 				HAL_INFO (("looking at /dev/mapper/%s", f));
 				g_snprintf (devpath, sizeof (devpath), "/dev/mapper/%s", f);
 				if (stat (devpath, &statbuf) == 0) {
 					if (S_ISBLK (statbuf.st_mode) && 
 					    MAJOR(statbuf.st_rdev) == major && 
 					    MINOR(statbuf.st_rdev) == minor &&
-					    strncmp (f, sesame_prefix, sizeof (sesame_prefix) - 1) == 0) {
-						luks_uuid = f + sizeof (sesame_prefix) - 1;
+					    strncmp (f, luks_prefix, sizeof (luks_prefix) - 1) == 0) {
+						luks_uuid = f + sizeof (luks_prefix) - 1;
 						HAL_INFO (("found %s; luks_uuid='%s'!", devpath, luks_uuid));
 						break;
 					}
@@ -510,7 +510,7 @@
 			parent = hal_device_store_find (hald_get_gdl (), backing_volume_stordev_udi);
 			if (parent != NULL) {
 				HAL_INFO (("parent='%s'!", parent->udi));
-				hal_device_property_set_string (device, "volume.crypto_sesame.clear.backing_volume", backing_volume->udi);
+				hal_device_property_set_string (device, "volume.crypto_luks.clear.backing_volume", backing_volume->udi);
 			}
 		}
 	}
diff -u --recursive hal-cvs-vanilla/hald/linux2/coldplug.c hal-cvs/hald/linux2/coldplug.c
--- hal-cvs-vanilla/hald/linux2/coldplug.c	2005-02-27 22:53:15.000000000 -0600
+++ hal-cvs/hald/linux2/coldplug.c	2005-03-12 19:23:12.000000000 -0600
@@ -50,6 +50,10 @@
 #include "coldplug.h"
 #include "hotplug.h"
 
+#define DMPREFIX "dm-"
+
+static gboolean
+coldplug_synthesize_block_event(const gchar *f);
 
 static void
 coldplug_compute_visit_device (const gchar *path, 
@@ -134,6 +138,14 @@
 	 */
 	GSList *sysfs_other_class_dev = NULL;
 
+	/* Device mapper devices that should be added after all other block devices
+	 *
+	 * Example:
+	 *
+	 * (/sys/block/dm-0)
+	 */
+	GSList *sysfs_dm_dev = NULL;
+
 	/* build bus map */
 	sysfs_to_bus_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 	g_snprintf (path, HAL_PATH_MAX, "%s/bus", get_hal_sysfs_path ());
@@ -305,74 +317,102 @@
 		goto error;
 	}
 	while ((f = g_dir_read_name (dir)) != NULL) {
-		GDir *dir1;
-		gsize flen;
-		HotplugEvent *hotplug_event;
-		gchar *target;
-		gchar *normalized_target;
+		if (g_str_has_prefix (f, DMPREFIX)) {
+			/* defer dm devices */
+			sysfs_dm_dev = g_slist_append(sysfs_dm_dev, g_strdup(f));
+			continue;
+		}
+		if (coldplug_synthesize_block_event(f) == FALSE)
+			goto error;
+	}
+	/* process all dm devices last so that their backing devices exist */
+	for (li = sysfs_dm_dev; li != NULL; li = g_slist_next (g_slist_next (li))) {
+		if (coldplug_synthesize_block_event(li->data) == FALSE)
+			goto error;
+		g_free (li->data);
+	}
+	g_slist_free (sysfs_dm_dev);
+	g_dir_close (dir);
+       
+	return TRUE;
+error:
+	HAL_ERROR (("Error building the orderered list of sysfs paths"));
+	return FALSE;
+}
 
-		g_snprintf (path, HAL_PATH_MAX, "%s/block/%s", get_hal_sysfs_path (), f);
+static gboolean
+coldplug_synthesize_block_event(const gchar *f)
+{
+	GDir *dir1;
+	gsize flen;
+	HotplugEvent *hotplug_event;
+	gchar *target;
+	gchar *normalized_target;
+	GError *err = NULL;
+	gchar path[HAL_PATH_MAX];
+	gchar path1[HAL_PATH_MAX];
+	const gchar *f1;
+
+	g_snprintf (path, HAL_PATH_MAX, "%s/block/%s", get_hal_sysfs_path (), f);
 #ifdef HAL_COLDPLUG_VERBOSE
-		printf ("block: %s (block)\n",  path);
+	printf ("block: %s (block)\n",  path);
 #endif
 
-		g_snprintf (path1, HAL_PATH_MAX, "%s/block/%s/device", get_hal_sysfs_path (), f);
-		if (((target = g_file_read_link (path1, NULL)) != NULL)) {
-			normalized_target = hal_util_get_normalized_path (path1, target);
-			g_free (target);
-		} else {
-			normalized_target = NULL;
-		}
+	g_snprintf (path1, HAL_PATH_MAX, "%s/block/%s/device", get_hal_sysfs_path (), f);
+	if (((target = g_file_read_link (path1, NULL)) != NULL)) {
+		normalized_target = hal_util_get_normalized_path (path1, target);
+		g_free (target);
+	} else {
+		normalized_target = NULL;
+	}
+
+	hotplug_event = g_new0 (HotplugEvent, 1);
+	hotplug_event->is_add = TRUE;
+	hotplug_event->type = HOTPLUG_EVENT_SYSFS;
+	g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem));
+	g_strlcpy (hotplug_event->sysfs.sysfs_path, path, sizeof (hotplug_event->sysfs.sysfs_path));
+	hal_util_get_device_file (path, hotplug_event->sysfs.device_file, sizeof (hotplug_event->sysfs.device_file));
+	if (normalized_target != NULL)
+		g_strlcpy (hotplug_event->sysfs.wait_for_sysfs_path, normalized_target, sizeof (hotplug_event->sysfs.wait_for_sysfs_path));
+	else
+		hotplug_event->sysfs.wait_for_sysfs_path[0] = '\0';
+	hotplug_event->sysfs.net_ifindex = -1;
+	hotplug_event_enqueue (hotplug_event);
+	g_free (normalized_target);
 
-		hotplug_event = g_new0 (HotplugEvent, 1);
-		hotplug_event->is_add = TRUE;
-		hotplug_event->type = HOTPLUG_EVENT_SYSFS;
-		g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem));
-		g_strlcpy (hotplug_event->sysfs.sysfs_path, path, sizeof (hotplug_event->sysfs.sysfs_path));
-		hal_util_get_device_file (path, hotplug_event->sysfs.device_file, sizeof (hotplug_event->sysfs.device_file));
-		if (normalized_target != NULL)
-			g_strlcpy (hotplug_event->sysfs.wait_for_sysfs_path, normalized_target, sizeof (hotplug_event->sysfs.wait_for_sysfs_path));
-		else
-			hotplug_event->sysfs.wait_for_sysfs_path[0] = '\0';
-		hotplug_event->sysfs.net_ifindex = -1;
-		hotplug_event_enqueue (hotplug_event);
-		g_free (normalized_target);
+	flen = strlen (f);
 
-		flen = strlen (f);
-
-		if ((dir1 = g_dir_open (path, 0, &err)) == NULL) {
-			HAL_ERROR (("Unable to open %s: %s", path, err->message));
-			g_error_free (err);
-			goto error;
-		}
-		while ((f1 = g_dir_read_name (dir1)) != NULL) {
-			if (strncmp (f, f1, flen) == 0) {
-				g_snprintf (path1, HAL_PATH_MAX, "%s/%s", path, f1);
+	if ((dir1 = g_dir_open (path, 0, &err)) == NULL) {
+		HAL_ERROR (("Unable to open %s: %s", path, err->message));
+		g_error_free (err);
+		goto error;
+	}
+	while ((f1 = g_dir_read_name (dir1)) != NULL) {
+		if (strncmp (f, f1, flen) == 0) {
+			g_snprintf (path1, HAL_PATH_MAX, "%s/%s", path, f1);
 #ifdef HAL_COLDPLUG_VERBOSE
-				printf ("block: %s (block)\n", path1);
+			printf ("block: %s (block)\n", path1);
 #endif
 
-				hotplug_event = g_new0 (HotplugEvent, 1);
-				hotplug_event->is_add = TRUE;
-				hotplug_event->type = HOTPLUG_EVENT_SYSFS;
-				g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem));
-				g_strlcpy (hotplug_event->sysfs.sysfs_path, path1, sizeof (hotplug_event->sysfs.sysfs_path));
-				g_strlcpy (hotplug_event->sysfs.wait_for_sysfs_path, path, sizeof (hotplug_event->sysfs.wait_for_sysfs_path));
-				hal_util_get_device_file (path1, hotplug_event->sysfs.device_file, sizeof (hotplug_event->sysfs.device_file));
-				hotplug_event->sysfs.net_ifindex = -1;
-				hotplug_event_enqueue (hotplug_event);
-			}
+			hotplug_event = g_new0 (HotplugEvent, 1);
+			hotplug_event->is_add = TRUE;
+			hotplug_event->type = HOTPLUG_EVENT_SYSFS;
+			g_strlcpy (hotplug_event->sysfs.subsystem, "block", sizeof (hotplug_event->sysfs.subsystem));
+			g_strlcpy (hotplug_event->sysfs.sysfs_path, path1, sizeof (hotplug_event->sysfs.sysfs_path));
+			g_strlcpy (hotplug_event->sysfs.wait_for_sysfs_path, path, sizeof (hotplug_event->sysfs.wait_for_sysfs_path));
+			hal_util_get_device_file (path1, hotplug_event->sysfs.device_file, sizeof (hotplug_event->sysfs.device_file));
+			hotplug_event->sysfs.net_ifindex = -1;
+			hotplug_event_enqueue (hotplug_event);
 		}
-		g_dir_close (dir1);		
 	}
-	g_dir_close (dir);
+	g_dir_close (dir1);		
        
 	return TRUE;
 error:
-	HAL_ERROR (("Error building the orderered list of sysfs paths"));
 	return FALSE;
 }
 
+
 static void
 coldplug_compute_visit_device (const gchar *path, 
 			       GHashTable *sysfs_to_bus_map, 
-------------- next part --------------
_______________________________________________
hal mailing list
hal at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/hal


More information about the Hal mailing list