[dm-devel] [PATCH] lock snapshot when asking for status
Mikulas Patocka
mpatocka at redhat.com
Fri Oct 9 02:47:23 UTC 2009
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 at 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;
}
More information about the dm-devel
mailing list