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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



- Total size is size of each individual device times number of devices
- Stripe unit is in bytes, not sectors
- Round total device size down to a muliple of the stripe size

Signed-off-by: Jim Rees <rees@xxxxxxxxx>
---
 utils/blkmapd/dm-device.c |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)

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++) {
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux