[dm-devel] Re: [lvm-devel] dm-crypt - some info, and a few development questions

Christophe Saout christophe at saout.de
Thu Jul 17 16:58:01 UTC 2003


Am Do, 2003-07-17 um 18.35 schrieb Joe Thornber:

> I'm working on the missing targets (snapshots and mirroring) already,
> also these two are *far* more complex than your crypto target will be.

Yes, that's why I said that time is a problem.

> Spend a day playing with dmsetup, and make sure you really understand
> how to write target types.  The best way to learn is to try and write
> a trivial target type, eg. a 'reverse' target that divides the device
> into chunks and then reverses their order, ie. the first logical chunk is
> stored in the last logical chunk of the device.  This should only take
> you ~150 lines of code (start with dm-linear.c and modify).

Yes, that was really easy. Especially because alle the bio handling and
even splitting is already done outside the target file, you just have to
specify the mapping. Hey, it's even working. If anyone wants to see it,
tell me. ;)

But I stumbled across this "nasty" function called mutiple in
dm-stripe.c. In the 2.5 kernel there is a macro defined in blkdev.h
called sector_div which handles divisions for the sector_t type
(basically a normal unsigned 32 bit division when sector_t is 32 bits
wide and a special 64 bit division using do_div when it is 64 bits wide
and you are on a 32 bit machine, that one is used when large block
devices are activated).

I think you can safely replace the use of multiple with sector_div.

What is this restriction that the sector count has to be a multiple of
the number of stripes for? Just that the allocated size on each device
is exactly the same?

--- dm-stripe.c.orig	2003-07-17 23:42:59.095996032 +0200
+++ dm-stripe.c	2003-07-17 23:44:05.737864928 +0200
@@ -64,30 +64,6 @@
 }
 
 /*
- * FIXME: Nasty function, only present because we can't link
- * against __moddi3 and __divdi3.
- *
- * returns a == b * n
- */
-static int multiple(sector_t a, sector_t b, sector_t *n)
-{
-	sector_t acc, prev, i;
-
-	*n = 0;
-	while (a >= b) {
-		for (acc = b, prev = 0, i = 1;
-		     acc <= a;
-		     prev = acc, acc <<= 1, i <<= 1)
-			;
-
-		a -= prev;
-		*n += i >> 1;
-	}
-
-	return a == 0;
-}
-
-/*
  * Construct a striped mapping.
  * <number of stripes> <chunk size (2^^n)> [<dev_path> <offset>]+
  */
@@ -126,7 +102,8 @@
 		return -EINVAL;
 	}
 
-	if (!multiple(ti->len, stripes, &width)) {
+	width = ti->len;
+	if (sector_div(width, stripes)) {
 		ti->error = "dm-stripe: Target length not divisable by "
 		    "number of stripes";
 		return -EINVAL;

--
Christophe Saout <christophe at saout.de>
Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html





More information about the dm-devel mailing list