lkml.org 
[lkml]   [2009]   [Nov]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v4 07/13] dm snapshot: do not allow more than one merging snapshot.
Date
From: Mikulas Patocka <mpatocka@redhat.com>

Merging more than one snapshot is not supported.
__find_merging_snapshot() will find the merging snapshot for a given
origin device.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
---
drivers/md/dm-snap.c | 35 +++++++++++++++++++++++++++++++++--
1 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index b8838e7..f4e9aa6 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -332,9 +332,29 @@ out:
return count;
}

+static struct dm_snapshot *__find_merging_snapshot(struct block_device *origin)
+{
+ struct dm_snapshot *s, *merging_snap;
+ struct origin *o;
+
+ o = __lookup_origin(origin);
+ if (!o)
+ return NULL;
+
+ list_for_each_entry(s, &o->snapshots, list) {
+ if (is_merge(s->ti)) {
+ merging_snap = s;
+ break;
+ }
+ }
+
+ return merging_snap;
+}
+
static int __validate_exception_handover(struct dm_snapshot *snap)
{
struct dm_snapshot *snap_src = NULL, *snap_dest = NULL;
+ struct block_device *bdev = snap->origin->bdev;
int r = 0;

/* Does snapshot need exceptions handed over to it? */
@@ -346,8 +366,19 @@ static int __validate_exception_handover(struct dm_snapshot *snap)
goto out;
}

- if (snap_src)
+ if (snap_src) {
+ if (is_merge(snap->ti)) {
+ /* Do not allow more than one merging snapshot */
+ if (__find_merging_snapshot(bdev)) {
+ snap->ti->error = "A snapshot is already "
+ "merging.";
+ r = -EINVAL;
+ goto out;
+ }
+ }
+
r = 1;
+ }

out:
return r;
@@ -1325,7 +1356,7 @@ static int snapshot_merge_map(struct dm_target *ti, struct bio *bio,
bio->bi_bdev = s->origin->bdev;

if (bio_rw(bio) == WRITE) {
- up_write(&s->lock);
+ up_read(&s->lock);
return do_origin(s->origin, bio);
}

--
1.6.5.2


\
 
 \ /
  Last update: 2009-11-20 21:33    [W:0.074 / U:3.192 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site