diff mbox

[v5,06/13] dm snapshot: do not allow more than one merging snapshot.

Message ID 1259893434-10792-7-git-send-email-snitzer@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Alasdair Kergon
Headers show

Commit Message

Mike Snitzer Dec. 4, 2009, 2:23 a.m. UTC
None
diff mbox

Patch

diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index c232460..a0ac29f 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -331,9 +331,29 @@  out:
 	return count;
 }
 
+static struct dm_snapshot *__find_merging_snapshot(struct block_device *origin)
+{
+	struct dm_snapshot *s, *merging_snap = NULL;
+	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? */
@@ -345,8 +365,22 @@  static int __validate_exception_handover(struct dm_snapshot *snap)
 		goto out;
 	}
 
-	if (snap_src)
+	if (snap_src) {
+		/* This snapshot is a handover destination */
+		if (!is_merge(snap->ti)) {
+			r = 1;
+			goto out;
+		}
+
+		/* 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;