diff mbox

[2/3] Fix calculation of stripe device and unit sizes

Message ID 6eae3b83b619dc3965e1c0fd1110df2db76b9183.1295627825.git.rees@umich.edu
State RFC, archived
Headers show

Commit Message

Jim Rees Jan. 21, 2011, 4:53 p.m. UTC
None
diff mbox

Patch

diff --git a/utils/blkmapd/dm-device.c b/utils/blkmapd/dm-device.c
index d720086..ee7d787 100644
--- a/utils/blkmapd/dm-device.c
+++ b/utils/blkmapd/dm-device.c
@@ -371,7 +371,7 @@  static int dm_device_exists(char *dev_name)
 /* TODO: check the value for DM_DEV_NAME_LEN, DM_TYPE_LEN, DM_PARAMS_LEN */
 uint64_t dm_device_create(struct bl_volume *vols, int num_vols)
 {
-	uint64_t size, dev = 0;
+	uint64_t size, stripe_unit, stripe_size, nstripes, dev = 0;
 	unsigned int count = dev_count;
 	int volnum, i, pos;
 	struct bl_volume *node;
@@ -416,11 +416,25 @@  uint64_t dm_device_create(struct bl_volume *vols, int num_vols)
 			if (!table)
 				goto out;
 			table->offset = 0;
-			table->size = node->bv_size;
+			stripe_unit = node->param.bv_stripe_unit << 9;
+			stripe_size = stripe_unit * node->bv_vol_n;
+			nstripes = node->bv_size * node->bv_vol_n / stripe_size;
+			/* Make sure total size is a multiple of stripe size */
+			size = node->bv_size * node->bv_vol_n;
+			if (size % stripe_size != 0) {
+				/* XXX Should this be an error? */
+				BL_LOG_WARNING(
+					"%s: %d units of %llu bytes is not a multiple of %lld stripe size\n",
+					__func__, node->bv_vol_n,
+					(long long unsigned) node->bv_size,
+					(long long unsigned) stripe_size);
+				size = nstripes * stripe_size;
+			}
+			table->size = size;
 			strcpy(table->target_type, "striped");
-			sprintf(table->params, "%d %lu %n", node->bv_vol_n,
-				node->param.bv_stripe_unit, &pos);
-			/* Repeatedly copy subdev to params */
+			sprintf(table->params, "%d %llu %n", node->bv_vol_n,
+				(long long unsigned) stripe_unit, &pos);
+			/* Copy subdev major:minor to params */
 			tmp = table->params + pos;
 			len = DM_PARAMS_LEN - pos;
 			for (i = 0; i < node->bv_vol_n; i++) {