From patchwork Tue Nov 17 16:12:17 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 60704 Received: from hormel.redhat.com (hormel1.redhat.com [209.132.177.33]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nAHGClHQ001757 for ; Tue, 17 Nov 2009 16:12:47 GMT Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com [10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id DCDA861B123; Tue, 17 Nov 2009 11:12:32 -0500 (EST) Received: from int-mx02.intmail.prod.int.phx2.redhat.com (nat-pool.util.phx.redhat.com [10.8.5.200]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP id nAHGCSjC030018 for ; Tue, 17 Nov 2009 11:12:28 -0500 Received: from localhost (dhcp-100-19-150.bos.redhat.com [10.16.19.150]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAHGCRZb011094 for ; Tue, 17 Nov 2009 11:12:27 -0500 From: Mike Snitzer To: dm-devel@redhat.com Date: Tue, 17 Nov 2009 11:12:17 -0500 Message-Id: <1258474344-10886-6-git-send-email-snitzer@redhat.com> In-Reply-To: <1258474344-10886-1-git-send-email-snitzer@redhat.com> References: <1258474344-10886-1-git-send-email-snitzer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH v3 05/12] dm snapshot: do not allow more than one merging snapshot. X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.5 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 5fd7055..2a9fae9 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -561,6 +561,30 @@ out: return handover_snap; } +static struct dm_snapshot *find_merging_snapshot(struct block_device *origin) +{ + struct dm_snapshot *s, *merging_snap = NULL; + struct origin *o; + + down_read(&_origins_lock); + + o = __lookup_origin(origin); + if (!o) + goto out; + + list_for_each_entry(s, &o->snapshots, list) { + if (is_merge(s->ti)) { + merging_snap = s; + break; + } + } + +out: + up_read(&_origins_lock); + + return merging_snap; +} + #define min_not_zero(l, r) (((l) == 0) ? (r) : (((r) == 0) ? (l) : min(l, r))) /* @@ -732,6 +756,15 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) /* Does snapshot need exceptions handed over to it? */ handover_snap = find_snapshot_using_cow(s); if (handover_snap) { + if (is_merge(s->ti)) { + r = -EINVAL; + /* Do not allow more than one merging snapshot */ + if (find_merging_snapshot(s->origin->bdev)) { + ti->error = "A snapshot is already merging."; + goto bad_load_and_register; + } + } + down_write(&handover_snap->lock); if (handover_snap->is_handover_source) { up_write(&handover_snap->lock);