]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
dm snapshot: lock snapshot while supplying status
authorMikulas Patocka <mpatocka@redhat.com>
Fri, 16 Oct 2009 22:18:16 +0000 (23:18 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 10 Nov 2009 00:22:06 +0000 (16:22 -0800)
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@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/md/dm-snap.c

index 53f4063f7ea4dfe0490d7b2d54be922136023220..b9dd22ce47d425d4769945a69a52da8c38b7dc61 100644 (file)
@@ -1147,6 +1147,8 @@ static int snapshot_status(struct dm_target *ti, status_type_t type,
        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_target *ti, status_type_t type,
                break;
        }
 
+       up_write(&snap->lock);
+
        return 0;
 }