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

[dm-devel] [PATCH] dm-snapshot.c: Don't read off the end of the origin device



An origin device may not be an exact multiple of the snapshot chunk size. If
this is the case, kcopyd may eventually try to read off the end of the origin
device, causing I/O errors and invalidation of the snapshot. This patch adds a
check in start_copy to check for this last partial-chunk on the origin, and
tells kcopyd to copy the correct size.

--- linux-2.4.21a/drivers/md/dm-snapshot.c	27 Mar 2003 15:52:35 -0000
+++ linux-2.4.21b/drivers/md/dm-snapshot.c	27 Jun 2003 18:46:25 -0000
@@ -714,14 +714,20 @@
 {
 	struct dm_snapshot *s = pe->snap;
 	struct kcopyd_region src, dest;
+	kdev_t dev = s->origin->dev;
+	int *sizes = blk_size[major(dev)];
+	sector_t dev_size = (sector_t)-1;
 
-	src.dev = s->origin->dev;
+	if (sizes && sizes[minor(dev)])
+		dev_size = sizes[minor(dev)] << 1;
+
+	src.dev = dev;
 	src.sector = chunk_to_sector(s, pe->e.old_chunk);
-	src.count = s->chunk_size;
+	src.count = min(s->chunk_size, dev_size - src.sector);
 
 	dest.dev = s->cow->dev;
 	dest.sector = chunk_to_sector(s, pe->e.new_chunk);
-	dest.count = s->chunk_size;
+	dest.count = src.count;
 
 	if (!pe->started) {
 		/* Hand over to kcopyd */




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