[24/99] dm snapshot: lock snapshot while supplying status

From: Greg KH
Date: Fri Nov 06 2009 - 17:40:42 EST


2.6.31-stable review patch. If anyone has any objections, please let us know.

------------------
From: Mikulas Patocka <mpatocka@xxxxxxxxxx>

commit 4c6fff445d7aa753957856278d4d93bcad6e2c14 upstream.

This patch locks the snapshot when returning status. It fixes a race
when it could return an invalid number of free chunks if someone
was simultaneously modifying it.

Signed-off-by: Mikulas Patocka <mpatocka@xxxxxxxxxx>
Signed-off-by: Alasdair G Kergon <agk@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxx>

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

--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -1147,6 +1147,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)
@@ -1178,6 +1180,8 @@ static int snapshot_status(struct dm_tar
break;
}

+ up_write(&snap->lock);
+
return 0;
}



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/