hal/hald/linux block_class_device.c,1.87,1.88 osspec.c,1.53,1.54

David Zeuthen david at freedesktop.org
Thu Dec 16 08:13:10 PST 2004


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

Modified Files:
	block_class_device.c osspec.c 
Log Message:
2004-12-16  David Zeuthen  <davidz at redhat.com>

	* hald/linux/volume_id/volume_id.c (sesame_skip_to_next_nonempty_line):
	New function
	(sesame_parse): New function
	(sesame_got_kv_pair): New function
	(probe_crypto_sesame): New function
	(volume_id_probe): Probe for sesame crypto metadata
	(volume_id_close): Free key/value pairs

	* hald/linux/volume_id/volume_id.h: Add the VOLUME_ID_CRYPTO usage type
	and VOLUME_ID_CRYPTO_SESAME filesystem type. Add the volume_id_kv_pair 
	structure

	* hald/linux/osspec.c (compute_coldplug_list): Also process other block
	devices

	* hald/linux/block_class_device.c (set_volume_id_values): Allow crypto
	and get properties from volume_id
	(block_class_visit): Add some code to figure out if /dev/dm-0 is really
	the cleartext device from a device backed by us.



Index: block_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/block_class_device.c,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -d -r1.87 -r1.88
--- block_class_device.c	14 Dec 2004 02:57:48 -0000	1.87
+++ block_class_device.c	16 Dec 2004 16:13:08 -0000	1.88
@@ -97,6 +97,9 @@
 	case VOLUME_ID_RAID:
 		usage = "raid";
 		break;
+	case VOLUME_ID_CRYPTO:
+		usage = "crypto";
+		break;
 	case VOLUME_ID_UNUSED:
 		hal_device_property_set_string (d, "info.product", "Volume (unused)");
 		usage = "unused";
@@ -125,6 +128,17 @@
 		hal_device_property_set_string (d, "info.product", product);
 		g_free (product);
 	}
+
+	if (vid->type != NULL && strlen (vid->type) > 0) {
+		char kv_key[256];
+		struct volume_id_kv_pair *pair;
+
+		for (pair = vid->kv_pairs; pair != NULL; pair = pair->next) {
+			
+			snprintf (kv_key, sizeof (kv_key), "volume.%s.%s", vid->type, pair->key);
+			hal_device_property_set_string (d, kv_key, pair->value);
+		}
+	}
 }
 
 static HalDevice *
@@ -161,8 +175,7 @@
 	int instance;
 	HalDevice *d;
 
-	/*HAL_INFO (("path = %s, classname = %s", 
-	  sysfs_path, self->sysfs_class_name));*/
+	/*HAL_INFO (("^^^^^ path = %s, classname = %s", sysfs_path, self->sysfs_class_name));*/
 
 	/* skip legacy floppies for now, until we get proper sysfs links to the
 	   platform device and switch over to merge floppies into that device.
@@ -256,6 +269,82 @@
 	 * and we reorder hotplug events)
 	 */
 	if (parent == NULL) {
+		unsigned int major;
+		unsigned int minor;
+		const char *last_elem;
+
+		major = 253; /* TODO: replace by devmapper constant */
+
+		last_elem = get_last_element (path);
+		if (sscanf (last_elem, "dm-%d", &minor) == 1) {
+			GDir *dir;
+
+
+			HAL_INFO (("path=%s is a device mapper dev, major/minor=%d/%d", path, major, minor));
+
+			/* Ugly hack to see if we're a sesame crypto device; should
+			 * be replaced by some ioctl or libdevmapper stuff by where
+			 * 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
+			 * dmsetup; e.g. the naming convention is 
+			 *
+			 *    sesame_crypto_<sesame_uuid>
+			 *
+			 * where <sesame_uuid> is the UUID encoded in the sesame
+			 * metadata.
+			 */
+
+			/* Ugly sleep of 0.5s here as well to allow dmsetup to do the mknod */
+			usleep (1000 * 1000 * 5 / 10);
+			
+			if ((dir = g_dir_open ("/dev/mapper", 0, NULL)) != NULL) {
+				const gchar *f;
+				char devpath[256];
+				struct stat statbuf;
+				
+				while ((f = g_dir_read_name (dir)) != NULL) {
+					char sesame_prefix[] = "sesame_crypto_";
+					const char *sesame_uuid;
+					
+					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) {
+							HalDevice *backing_volume;
+							
+							sesame_uuid = f + sizeof (sesame_prefix) - 1;
+							HAL_INFO (("found %s; sesame_uuid='%s'!", 
+								   devpath, sesame_uuid));
+							
+							backing_volume = hal_device_store_match_key_value_string (
+								hald_get_gdl (), 
+								"volume.crypto_sesame.uuid", 
+								sesame_uuid);
+							if (backing_volume != NULL) {
+								const char *backing_volume_stordev_udi;
+								backing_volume_stordev_udi = hal_device_property_get_string (backing_volume, "block.storage_device");
+								if (backing_volume_stordev_udi != NULL) {
+									parent = hal_device_store_find (hald_get_gdl (), backing_volume_stordev_udi);
+									if (parent != NULL) {
+										hal_device_property_set_string (d, "volume.crypto_sesame.clear.backing_volume", backing_volume->udi);
+										goto got_parent;
+									}
+								}
+							}
+							
+						}
+					}
+				}
+				g_dir_close (dir);
+			}
+		}
+
 		hal_device_store_remove (hald_get_tdl (), d);
 		d = NULL;
 		goto out;
@@ -270,6 +359,8 @@
 		}
 	}
 
+got_parent:
+
 	class_device_got_parent_device (hald_get_tdl (), parent, cad);
 
 out:

Index: osspec.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/osspec.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- osspec.c	14 Dec 2004 02:57:48 -0000	1.53
+++ osspec.c	16 Dec 2004 16:13:08 -0000	1.54
@@ -311,6 +311,9 @@
  */
 GHashTable *sysfs_to_block_map = NULL;
 
+GSList *sysfs_other_blockdevs = NULL;
+
+
 /** Mapping from sysfs path in /sys/class to class type
  *
  * Example:
@@ -378,6 +381,7 @@
 	const gchar *f1;
 	const gchar *f2;
 	GSList *coldplug_list = NULL;
+	GSList *i;
 
 	/* build bus map */
 	sysfs_to_bus_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
@@ -509,6 +513,13 @@
 			/*printf ("%s -> %s\n",  normalized_target, path);*/
 			g_free (target);
 			g_hash_table_insert (sysfs_to_block_map, normalized_target, g_strdup(path));
+		} else {
+			/* we're also interested in block devices without device links
+			 * for e.g. device mapper stuff such as /dev/dm-0 */
+			g_snprintf (path, SYSFS_PATH_MAX, "%s/block/%s", sysfs_mount_path, f);
+
+			sysfs_other_blockdevs = g_slist_append (sysfs_other_blockdevs, g_strdup (path));
+			/*printf ("other blockdev: %s\n", path);*/
 		}
 		
 	}
@@ -589,6 +600,14 @@
 	/* Then add all the class devices that doesn't sit in the /sys/devices tree */
 	g_hash_table_foreach (sysfs_to_class_map, compute_coldplug_visit_class_device, &coldplug_list);
 
+	/* Finally add all block devices without device links */
+	for (i = sysfs_other_blockdevs; i != NULL; i = i->next) {
+		const char *obpath = i->data;
+		coldplug_list = g_slist_append (coldplug_list, 
+						h_string_pair_new (g_strdup (obpath), g_strdup ("block")));
+	}
+	g_slist_free (sysfs_other_blockdevs);
+
 	g_hash_table_destroy (sysfs_to_bus_map);
 	g_hash_table_destroy (sysfs_to_class_in_devices_map);
 	g_hash_table_destroy (sysfs_to_block_map);




More information about the hal-commit mailing list