<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">To: Andrew Morton &lt;akpm@osdl.org&gt;
Cc: linux-kernel@vger.kernel.org, Mark McLoughlin &lt;markmc@redhat.com&gt;
Subject: [PATCH 07/25] dm snapshot: tidy snapshot_map

This patch rearranges the snapshot_map code so that the functional
changes in subsequent patches are clearer.
 
The only functional change is to replace the existing read lock with
a write lock which the next patch needs.

Signed-off-by: Alasdair G Kergon &lt;agk@redhat.com&gt;
 
Index: linux-2.6.18-rc7/drivers/md/dm-snap.c
===================================================================
--- linux-2.6.18-rc7.orig/drivers/md/dm-snap.c	2006-10-13 17:10:08.000000000 +0100
+++ linux-2.6.18-rc7/drivers/md/dm-snap.c	2006-10-13 17:10:10.000000000 +0100
@@ -851,7 +851,6 @@ static int snapshot_map(struct dm_target
 {
 	struct exception *e;
 	struct dm_snapshot *s = (struct dm_snapshot *) ti-&gt;private;
-	int copy_needed = 0;
 	int r = 1;
 	chunk_t chunk;
 	struct pending_exception *pe = NULL;
@@ -866,29 +865,28 @@ static int snapshot_map(struct dm_target
 	if (unlikely(bio_barrier(bio)))
 		return -EOPNOTSUPP;
 
+	/* FIXME: should only take write lock if we need
+	 * to copy an exception */
+	down_write(&amp;s-&gt;lock);
+
+	if (!s-&gt;valid) {
+		r = -EIO;
+		goto out_unlock;
+	}
+
+	/* 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;
+	}
+
 	/*
 	 * Write to snapshot - higher level takes care of RW/RO
 	 * 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 (!s-&gt;valid) {
-			r = -EIO;
-			goto out_unlock;
-		}
-
-		/* 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;
-		}
-
 		pe = __find_pending_exception(s, bio);
 		if (!pe) {
 			__invalidate_snapshot(s, pe, -ENOMEM);
@@ -899,45 +897,27 @@ static int snapshot_map(struct dm_target
 		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;
-			copy_needed = 1;
-		}
-
-		r = 0;
-
- out_unlock:
-		up_write(&amp;s-&gt;lock);
-
-		if (copy_needed)
+			up_write(&amp;s-&gt;lock);
 			start_copy(pe);
-	} else {
+			goto out;
+		}
+	} else
 		/*
 		 * FIXME: this read path scares me because we
 		 * always use the origin when we have a pending
 		 * exception.  However I can't think of a
 		 * situation where this is wrong - ejt.
 		 */
+		bio-&gt;bi_bdev = s-&gt;origin-&gt;bdev;
 
-		/* Do reads */
-		down_read(&amp;s-&gt;lock);
-
-		if (!s-&gt;valid) {
-			up_read(&amp;s-&gt;lock);
-			return -EIO;
-		}
-
-		/* 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);
-	}
-
+ out_unlock:
+	up_write(&amp;s-&gt;lock);
+ out:
 	return r;
 }
 
</pre></body></html>