<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From: Alasdair G Kergon &lt;agk@redhat.com&gt;

This patch rearranges the snapshot_map code so that the functional
changes in the next patch are clearer.

The only functional change is to replace the existing read lock with
a write lock which the next patch needs.
---


Index: linux-2.6.14-rc2/drivers/md/dm-snap.c
===================================================================
--- linux-2.6.14-rc2.orig/drivers/md/dm-snap.c	2006-01-06 16:58:20.000000000 +0000
+++ linux-2.6.14-rc2/drivers/md/dm-snap.c	2006-01-06 17:23:44.000000000 +0000
@@ -807,42 +807,39 @@ static int snapshot_map(struct dm_target
 	 * flags so we should only get this if we are
 	 * writeable.
 	 */
-	if (bio_rw(bio) == WRITE) {
-
-		/* FIXME: should only take write lock if we need
-		 * to copy an exception */
-		down_write(&amp;s-&gt;lock);
-
-		/* If the block is already remapped - use that, else remap it */
-		e = lookup_exception(&amp;s-&gt;complete, chunk);
-		if (e) {
-			remap_exception(s, e, bio);
-			up_write(&amp;s-&gt;lock);
 
-		} else {
-			pe = __find_pending_exception(s, bio);
+	/* FIXME: should only take write lock if we need
+	 * to copy an exception */
+	down_write(&amp;s-&gt;lock);
 
-			if (!pe) {
-				if (s-&gt;store.drop_snapshot)
-					s-&gt;store.drop_snapshot(&amp;s-&gt;store);
-				s-&gt;valid = 0;
-				r = -EIO;
-				up_write(&amp;s-&gt;lock);
-			} else {
-				remap_exception(s, &amp;pe-&gt;e, bio);
-				bio_list_add(&amp;pe-&gt;snapshot_bios, bio);
+	/* If the block is already remapped - use that, else remap it */
+	e = lookup_exception(&amp;s-&gt;complete, chunk);
+	if (e) {
+		remap_exception(s, e, bio);
+		goto out_unlock;
+	}
 
-				if (!pe-&gt;started) {
-					/* this is protected by snap-&gt;lock */
-					pe-&gt;started = 1;
-					up_write(&amp;s-&gt;lock);
-					start_copy(pe);
-				} else
-					up_write(&amp;s-&gt;lock);
-				r = 0;
-			}
+	if (bio_rw(bio) == WRITE) {
+		pe = __find_pending_exception(s, bio);
+		if (!pe) {
+			if (s-&gt;store.drop_snapshot)
+				s-&gt;store.drop_snapshot(&amp;s-&gt;store);
+			s-&gt;valid = 0;
+			r = -EIO;
+			goto out_unlock;
 		}
 
+		remap_exception(s, &amp;pe-&gt;e, bio);
+		bio_list_add(&amp;pe-&gt;snapshot_bios, bio);
+
+		r = 0;
+		if (!pe-&gt;started) {
+			/* this is protected by snap-&gt;lock */
+			pe-&gt;started = 1;
+			up_write(&amp;s-&gt;lock);
+			start_copy(pe);
+			goto out;
+		}
 	} else {
 		/*
 		 * FIXME: this read path scares me because we
@@ -851,19 +848,12 @@ static int snapshot_map(struct dm_target
 		 * situation where this is wrong - ejt.
 		 */
 
-		/* Do reads */
-		down_read(&amp;s-&gt;lock);
-
-		/* See if it it has been remapped */
-		e = lookup_exception(&amp;s-&gt;complete, chunk);
-		if (e)
-			remap_exception(s, e, bio);
-		else
-			bio-&gt;bi_bdev = s-&gt;origin-&gt;bdev;
-
-		up_read(&amp;s-&gt;lock);
+		bio-&gt;bi_bdev = s-&gt;origin-&gt;bdev;
 	}
 
+ out_unlock:
+	up_write(&amp;s-&gt;lock);
+ out:
 	return r;
 }
 
</pre></body></html>