http://marc.theaimsgroup.com/?l=evms-devel&m=112887246404441&w=2 '[Evms-devel] [PATCH] 2.5.3 device-mapper input' - MARC
[prev in list] [next in list] [prev in thread] [next in thread] 

List:       evms-devel
Subject:    [Evms-devel] [PATCH] 2.5.3 device-mapper input
From:       
Date:       2005-10-09 15:22:10
Message-ID: 20051009142313.TJFF8556.aamta10-winn.ispmail.ntl.com () smtp ! ntlworld ! com
[Download message RAW]

Hi, Some of you may find this interesting
a patch against evms 2.5.3 to enable device-mapper devices for input into evms
This is useful for things such as layering evms on top of dmraid and dm-crypt without \
the need for loop back devices (I've tried this with dmraid and I think this should \
also work for dm-crypt) I'm posting this from a web-mail system at the moment so I \
hope the patch gets through okay

a better approach would probably be to have a seperate plugin to control the aspects \
of device-mapper raid / crypt within evms perhaps as some form of region layer but at \
the moment I'm trying to see if I can write a reiser4 plugin

only device mapper targets stated in the new config section will be picked up (no \
wildcards) devices will show up with a prefix of dm/
it's best to specify the entire disk target and let evms determine the seperate \
partitions for itself

it may even be possible to layer an evms volume on top of another evms volume \
(assuming your crazy enough to try) but I wouldn't advise it :)


-----------------------------------------
Email sent from www.ntlworld.com
Virus-checked using McAfee(R) Software 
Visit www.ntlworld.com/security for more information


["evms-2.5.3-userdm-0.1.patch" (text/x-patch)]

diff -Naur evms-2.5.3.org/doc/evms.conf evms-2.5.3/doc/evms.conf
--- evms-2.5.3.org/doc/evms.conf	2005-06-10 14:51:06.000000000 +0000
+++ evms-2.5.3/doc/evms.conf	2005-08-14 16:53:10.000000000 +0000
@@ -239,3 +239,22 @@
         device_size_prompt = yes
 }
 
+# User devmapper section
+# This allows us to use a device-mapper device directly as a disk
+# without the need for loopback
+# Be careful not to specify any targets that are created by evms
+# This can be useful for any devices created via dmraid or other means
+
+# In order for this to work "dm*" has to be in the list of includes
+
+devmapper {
+	# This needs to be set to yes to enable
+	#dm_user = yes
+	
+	# List of targets to discover as disks
+	# These are the target names as seen with "dmsetup ls"
+	# only specific targets can be used
+	# we need to avoid evms created targets
+	#dm_user_targets = [ raid1_device raid0_device ]
+}
+
diff -Naur evms-2.5.3.org/engine/dm-targets.c evms-2.5.3/engine/dm-targets.c
--- evms-2.5.3.org/engine/dm-targets.c	2005-05-25 22:16:42.000000000 +0000
+++ evms-2.5.3/engine/dm-targets.c	2005-08-14 16:53:10.000000000 +0000
@@ -800,28 +800,39 @@
  * Fill in a mirror target structure based on an ASCII table string of the form:
  *     []*  [: ]{2,}
  *
- * Currently, log_type will always be "core", num_log_params is 1, and
+ * Currently, log_type will always be "core", num_log_params is 1 or 2, and
  * log_params is chunk-size (in sectors).
  **/
 static int mirror_translate_params(dm_target_t *target)
 {
 	dm_target_mirror_t *mirror = target->data.mirror;
 	char *params = target->params;
-	int i, rc;
+	int i, rc, num_opts;
 
 	LOG_PROC_ENTRY();
 
-	/* Skip "core 1" at the start of the string. */
-	params = next_token(params);
+	/* Skip "core" at the start of the string. */
 	params = next_token(params);
 
-	rc = sscanf(params, "%u %u", &mirror->chunk_size, &mirror->num_mirrors);
+	/* get the number of options for core and the chunk size */
+	rc = sscanf(params, "%u %u", &num_opts, &mirror->chunk_size);
 	if (rc != 2) {
 		rc = EINVAL;
 		goto out;
 	}
-
 	params = next_token(params);
+
+	/* skip the options for core based on num_opts */
+	for (i = 0; i < num_opts; i++) {
+		params = next_token(params);
+	}
+
+	/* get the number of mirrors */
+	rc = sscanf(params, "%u", &mirror->num_mirrors);
+	if (rc != 1) {
+		rc = EINVAL;
+		goto out;
+	}
 	params = next_token(params);
 
 	for (i = 0; i < mirror->num_mirrors; i++) {
@@ -855,13 +866,33 @@
 static int mirror_pretranslate_params(char *params, u_int32_t *num_devs,
 				      u_int32_t *num_groups)
 {
-	int rc;
+	int rc, i, num_opts = 0;
+	char *num_devs_point;
 
 	LOG_PROC_ENTRY();
 
-	rc = sscanf(params, "%*s %*d %*u %u", num_devs);
+	/* The mirror target can have more than 1 option
+	this affects the location of the number of member disks */
+
+	rc = sscanf(params, "%*s %u", &num_opts);
+	if (rc != 1) {
+		rc = EINVAL;
+		goto out;
+	}
+
+	/* skip "core " */
+	num_devs_point = next_token(params);
+	num_devs_point = next_token(params);
+
+	/* skip the options for core based on num_opts */
+	for (i = 0; i < num_opts; i++) {
+		num_devs_point = next_token(params);
+	}
+
+	rc = sscanf(num_devs_point, "%u", num_devs);
 	rc = (rc != 1) ? EINVAL : 0;
 
+out:
 	LOG_PROC_EXIT_INT(rc);
 	return rc;
 }
diff -Naur evms-2.5.3.org/plugins/disk/localdskmgr.c evms-2.5.3/plugins/disk/localdskmgr.c
--- evms-2.5.3.org/plugins/disk/localdskmgr.c	2005-05-20 19:02:06.000000000 +0000
+++ evms-2.5.3/plugins/disk/localdskmgr.c	2005-08-14 17:01:57.000000000 +0000
@@ -1315,13 +1315,14 @@
 	rc = EngFncs->dm_get_targets(disk, &targets);
 	if (rc) {
 		LOG_ERROR("Error getting DM mapping for disk %s.\n", disk->name);
+		rc=0;
 		goto out;
 	}
 
 	/* Reject all non-multipath devices. */
 	if (targets->type != DM_TARGET_MULTIPATH) {
 		LOG_DEBUG("Disk %s is not a multipath device.\n", disk->name);
-		rc = EINVAL;
+		//rc = EINVAL;
 		goto out;
 	}
 
@@ -1382,6 +1383,98 @@
 }
 
 /**
+ * check_user_devicemapper
+ *
+ * Check if this disk is a User created DM device.
+ **/
+static int check_user_devicemapper(storage_object_t * disk)
+{
+	dm_device_list_t * dm_list, * dm_entry;
+	dm_target_t * targets = NULL;
+	local_disk_t * ld = disk->private_data;
+	int rc = 0, dm_user_targets_count = 0, i, dmup_len;
+	boolean user_dm_enable;
+	const char * const * dm_user_targets;
+	char * dm_user_prefix = "dm/";
+
+	LOG_ENTRY();
+
+	/* Get the list of active DM devices. */
+	dm_list = get_dm_device_list();
+	if (!dm_list) {
+		LOG_WARNING("Cannot get list of DM devices.\n");
+		goto out;
+	}
+
+	/* Search the DM list for an entry that matches this disk. */
+	dm_entry = find_disk_in_dm_devices(disk, dm_list);
+	if (!dm_entry) {
+		LOG_DEBUG("Disk %s is not a DM device.\n", disk->name);
+		goto out;
+	}
+
+	user_dm_enable = FALSE;
+	EngFncs->get_config_bool("devmapper.dm_user", &user_dm_enable);
+
+	EngFncs->get_config_string_array("devmapper.dm_user_targets",
+					 &dm_user_targets_count, &dm_user_targets);
+
+	if (user_dm_enable == FALSE) {
+		LOG_DEBUG("devmapper.dm_user not enabled.\n");
+		rc = EINVAL;
+		goto out;
+	}
+
+	/* search the named targets in the config for the DM name*/
+	user_dm_enable = FALSE;
+	for (i = 0; i < dm_user_targets_count; i++) {		
+		if (strncmp(dm_user_targets[i], dm_entry->name, EVMS_NAME_SIZE) == 0) {
+			user_dm_enable = TRUE;
+		}
+	}
+
+	if (user_dm_enable == FALSE) {
+		LOG_DEBUG("%s not found in devmapper.dm_user_targets.\n", dm_entry->name);
+		rc = EINVAL;
+		goto out;
+	}
+
+	/* Get the DM mapping for this disk. */
+	/* we can use this in the future if we need to, and it's good to check */
+	strncpy(disk->name, dm_entry->name, EVMS_NAME_SIZE);
+	rc = EngFncs->dm_get_targets(disk, &targets);
+	if (rc) {
+		LOG_ERROR("Error getting DM mapping for disk %s.\n", disk->name);
+		goto out;
+	}
+
+	/* Copy the DM name to this disk. */
+	dmup_len = strlen(dm_user_prefix);
+	LOG_DEBUG("Changing disk name from %s to %s%s.\n",
+		  disk->name, dm_user_prefix ,dm_entry->name);
+
+	strncpy(disk->name, dm_user_prefix, dmup_len);
+	strncpy((disk->name)+dmup_len, dm_entry->name, EVMS_NAME_SIZE-dmup_len);
+
+	/* Reject all multipath devices that
+	 * were created by other EVMS plugins.
+	 */
+	rc = check_multipath_name(disk);
+	if (rc) {
+		LOG_DEBUG("Multipath disk %s belongs to another EVMS plugin.\n",
+			  disk->name);
+		goto out;
+	}
+
+	ld->flags |= LD_FLAG_USERDM;
+
+out:
+	/*EngFncs->dm_deallocate_targets(targets); */
+	LOG_EXIT_INT(rc);
+	return rc;
+}
+
+/**
  * get_geometry
  *
  * Use the HDIO_GETGEO_BIG or HDIO_GETGEO ioctl to get the disk's geometry.
@@ -1445,6 +1538,7 @@
 	if (disk->dev_major == LOOP_MAJOR ||
 	    disk->dev_major == NBD_MAJOR ||
 	    disk->dev_major == DRBD_MAJOR ||
+		ld->flags & LD_FLAG_USERDM ||
 	    ld->flags & LD_FLAG_MULTIPATH) {
 		LOG_DEBUG("Creating fake geometry for disk %s.\n", disk->name);
 		disk->geometry.heads = 255;
@@ -1709,6 +1803,13 @@
 			continue;
 		}
 
+		/* Check for User created DM devices. */
+		rc = check_user_devicemapper(&working_disk);
+		if (rc) {
+			close_dev(&working_disk);
+			continue;
+		}
+
 		/* Get the disk's geometry. */
 		rc = get_geometry(&working_disk);
 		if (rc) {
diff -Naur evms-2.5.3.org/plugins/disk/localdskmgr.h evms-2.5.3/plugins/disk/localdskmgr.h
--- evms-2.5.3.org/plugins/disk/localdskmgr.h	2005-05-17 20:38:55.000000000 +0000
+++ evms-2.5.3/plugins/disk/localdskmgr.h	2005-08-14 16:53:10.000000000 +0000
@@ -80,6 +80,7 @@
 #define LD_FLAG_MULTIPATH	(1 << 0)
 #define LD_FLAG_IDE		(1 << 1)
 #define LD_FLAG_SCSI		(1 << 2)
+#define LD_FLAG_USERDM		(1 << 3)
 
 extern engine_functions_t *EngFncs;
 extern plugin_record_t    *my_plugin_record;

-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Evms-devel mailing list
Evms-devel@lists.sourceforge.net
To subscribe/unsubscribe, please visit:
https://lists.sourceforge.net/lists/listinfo/evms-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About MARC | Support MARC | Got a list to add? | Sponsored by 10East and KoreLogic