From patchwork Tue Mar 17 19:07:37 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alasdair G Kergon X-Patchwork-Id: 12649 X-Patchwork-Delegate: agk@redhat.com 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 n2HJ7fN2005756 for ; Tue, 17 Mar 2009 19:07:41 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 980A0619FF6; Tue, 17 Mar 2009 15:07:41 -0400 (EDT) Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP id n2HJ7dTj000859 for ; Tue, 17 Mar 2009 15:07:40 -0400 Received: from agk.fab.redhat.com (agk.fab.redhat.com [10.33.0.19]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n2HJ7dm8012740 for ; Tue, 17 Mar 2009 15:07:39 -0400 Received: from agk by agk.fab.redhat.com with local (Exim 4.34) id 1LjedV-0004mc-CB for dm-devel@redhat.com; Tue, 17 Mar 2009 19:07:37 +0000 Date: Tue, 17 Mar 2009 19:07:37 +0000 From: Alasdair G Kergon To: dm-devel@redhat.com Message-ID: <20090317190737.GN3063@agk.fab.redhat.com> Mail-Followup-To: dm-devel@redhat.com Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.4.1i Organization: Red Hat UK Ltd. Registered in England and Wales, number 03798903. Registered Office: Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE. X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 X-loop: dm-devel@redhat.com Subject: [dm-devel] FW: [PATCH 2/3] check for completed exception after dropped lock 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 ----- Forwarded message from Mikulas Patocka ----- Date: Wed, 25 Feb 2009 12:58:10 -0500 (EST) From: Mikulas Patocka Subject: [PATCH 2/3] check for completed exception after dropped lock To: dm-devek@redhat.com cc: Alasdair G Kergon Move allocation of alloc_pending_exception to the caller. It is uncommon and bug-prone to drop a lock in a function that is called with the lock held, so this is moved up. Signed-off-by: Mikulas Patocka --- drivers/md/dm-snap.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel Index: linux-2.6.29-rc6-devel/drivers/md/dm-snap.c =================================================================== --- linux-2.6.29-rc6-devel.orig/drivers/md/dm-snap.c 2009-02-25 18:26:10.000000000 +0100 +++ linux-2.6.29-rc6-devel/drivers/md/dm-snap.c 2009-02-25 18:30:30.000000000 +0100 @@ -992,23 +992,10 @@ lookup_pending_exception(struct dm_snaps * this. */ static struct dm_snap_pending_exception * -__find_pending_exception(struct dm_snapshot *s, struct bio *bio) +__find_pending_exception(struct dm_snapshot *s, + struct dm_snap_pending_exception *pe, chunk_t chunk) { - struct dm_snap_pending_exception *pe, *pe2; - chunk_t chunk = sector_to_chunk(s, bio->bi_sector); - - /* - * Create a new pending exception, we don't want - * to hold the lock while we do this. - */ - up_write(&s->lock); - pe = alloc_pending_exception(s); - down_write(&s->lock); - - if (!s->valid) { - free_pending_exception(pe); - return NULL; - } + struct dm_snap_pending_exception *pe2; pe2 = lookup_pending_exception(s, chunk); if (pe2) { @@ -1083,7 +1070,17 @@ static int snapshot_map(struct dm_target if (bio_rw(bio) == WRITE) { pe = lookup_pending_exception(s, chunk); if (!pe) { - pe = __find_pending_exception(s, bio); + up_write(&s->lock); + pe = alloc_pending_exception(s); + down_write(&s->lock); + + if (!s->valid) { + free_pending_exception(pe); + r = -EIO; + goto out_unlock; + } + + pe = __find_pending_exception(s, pe, chunk); if (!pe) { __invalidate_snapshot(s, -ENOMEM); r = -EIO; @@ -1220,7 +1217,16 @@ static int __origin_write(struct list_he pe = lookup_pending_exception(snap, chunk); if (!pe) { - pe = __find_pending_exception(snap, bio); + up_write(&snap->lock); + pe = alloc_pending_exception(snap); + down_write(&snap->lock); + + if (!snap->valid) { + free_pending_exception(pe); + goto next_snapshot; + } + + pe = __find_pending_exception(snap, pe, chunk); if (!pe) { __invalidate_snapshot(snap, -ENOMEM); goto next_snapshot;