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

[dm-devel] [PATCH] lock snapshot when asking for status



Hi

This patch locks the snapshot when returning status --- it fixes a race 
when it would return invalid number of free chunks if someone 
simultaneously modifies it.

Mikulas

Hold the lock when processing the status.

On 32-bit computers with 64-bit chunk size, writes to the fields in the
exception store are not atomic and some invalid intermediate value can
be returned as the number of use chunks.

Signed-off-by: Mikulas Patocka <mpatocka redhat com>

---
 drivers/md/dm-snap.c |    4 ++++
 1 file changed, 4 insertions(+)

Index: linux-2.6.31-fast-new/drivers/md/dm-snap.c
===================================================================
--- linux-2.6.31-fast-new.orig/drivers/md/dm-snap.c	2009-10-09 04:00:28.000000000 +0200
+++ linux-2.6.31-fast-new/drivers/md/dm-snap.c	2009-10-09 04:26:36.000000000 +0200
@@ -1170,6 +1170,8 @@ static int snapshot_status(struct dm_tar
 	unsigned sz = 0;
 	struct dm_snapshot *snap = ti->private;
 
+	down_write(&snap->lock);
+
 	switch (type) {
 	case STATUSTYPE_INFO:
 		if (!snap->valid)
@@ -1201,6 +1203,8 @@ static int snapshot_status(struct dm_tar
 		break;
 	}
 
+	up_write(&snap->lock);
+
 	return 0;
 }
 


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