[linux-lvm] [PATCH] snapshots on unaligned lvs

Chris Mason mason at suse.com
Thu Oct 11 18:16:36 UTC 2001


Hello everyone,

This patch fixes 1.0.1-rc4 to be able to take snapshots of unaligned
logical volumes (created by some of the betas).  It also fixes
a counting error in the loop in lvm_snapshot_COW.

Nothing fancy here, I just changed it to use the hard sector size
as the blocksize sent to brw_kiovec.  I've tested with beta7 and
rc4 logical volumes, additional testing is more than welcome.

-chris

--- 0.36/drivers/md/lvm-snap.c Thu, 11 Oct 2001 10:17:22 -0400 
+++ 0.36(w)/drivers/md/lvm-snap.c Thu, 11 Oct 2001 14:11:50 -0400 
@@ -326,6 +326,7 @@
 {
 	const char * reason;
 	unsigned long org_start, snap_start, snap_phys_dev, virt_start, pe_off;
+	unsigned long phys_start ;
 	int idx = lv_snap->lv_remap_ptr, chunk_size = lv_snap->lv_chunk_size;
 	struct kiobuf * iobuf;
 	unsigned long blocks[KIO_MAX_SECTORS];
@@ -360,8 +361,14 @@
 
 	iobuf = lv_snap->lv_iobuf;
 
-	blksize_org = lvm_get_blksize(org_phys_dev);
-	blksize_snap = lvm_get_blksize(snap_phys_dev);
+	blksize_org = get_hardsect_size(org_phys_dev);
+	blksize_snap = get_hardsect_size(snap_phys_dev);
+
+	/* org_start must not change, we use it later on to fill in the
+	** exception table
+	*/
+	phys_start = org_start ;
+
 	max_blksize = max(blksize_org, blksize_snap);
 	min_blksize = min(blksize_org, blksize_snap);
 	max_sectors = KIO_MAX_SECTORS * (min_blksize>>9);
@@ -376,7 +383,7 @@
 
 		iobuf->length = nr_sectors << 9;
 
-		if(!lvm_snapshot_prepare_blocks(blocks, org_start,
+		if(!lvm_snapshot_prepare_blocks(blocks, phys_start,
 						nr_sectors, blksize_org))
 			goto fail_prepare;
 
@@ -391,6 +398,9 @@
 		if (__brw_kiovec(WRITE, 1, &iobuf, snap_phys_dev, blocks,
 				 blksize_snap, lv_snap) != (nr_sectors<<9))
 			goto fail_raw_write;
+
+		phys_start += nr_sectors ;
+		snap_start += nr_sectors ;
 	}
 
 #ifdef DEBUG_SNAPSHOT
@@ -605,7 +615,7 @@
 	snap_phys_dev = lv_snap->lv_block_exception[idx].rdev_new;
 	snap_pe_start = lv_snap->lv_block_exception[idx - (idx % COW_entries_per_pe)].rsector_new - lv_snap->lv_chunk_size;
 
-	blksize_snap = lvm_get_blksize(snap_phys_dev);
+	blksize_snap = get_hardsect_size(snap_phys_dev);
 
         COW_entries_per_block = blksize_snap / sizeof(lv_COW_table_disk_t);
         idx_COW_table = idx % COW_entries_per_pe % COW_entries_per_block;
@@ -654,7 +664,7 @@
 			idx++;
 			snap_phys_dev = lv_snap->lv_block_exception[idx].rdev_new;
 			snap_pe_start = lv_snap->lv_block_exception[idx - (idx % COW_entries_per_pe)].rsector_new - lv_snap->lv_chunk_size;
-			blksize_snap = lvm_get_blksize(snap_phys_dev);
+			blksize_snap = get_hardsect_size(snap_phys_dev);
 			blocks[0] = snap_pe_start >> (blksize_snap >> 10);
 		} else blocks[0]++;
 







More information about the linux-lvm mailing list