From patchwork Tue Apr 28 16:14:31 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikulas Patocka X-Patchwork-Id: 20484 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 n3SGEZCd027453 for ; Tue, 28 Apr 2009 16:14:35 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 5F78A61A182; Tue, 28 Apr 2009 12:14:35 -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 n3SGEX11014179 for ; Tue, 28 Apr 2009 12:14:34 -0400 Received: from hs20-bc2-1.build.redhat.com (hs20-bc2-1.build.redhat.com [10.10.28.34]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n3SGEVCc025200; Tue, 28 Apr 2009 12:14:32 -0400 Received: from hs20-bc2-1.build.redhat.com (localhost.localdomain [127.0.0.1]) by hs20-bc2-1.build.redhat.com (8.13.1/8.13.1) with ESMTP id n3SGEVaC022776; Tue, 28 Apr 2009 12:14:31 -0400 Received: from localhost (mpatocka@localhost) by hs20-bc2-1.build.redhat.com (8.13.1/8.13.1/Submit) with ESMTP id n3SGEV5O022770; Tue, 28 Apr 2009 12:14:31 -0400 X-Authentication-Warning: hs20-bc2-1.build.redhat.com: mpatocka owned process doing -bs Date: Tue, 28 Apr 2009 12:14:31 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@hs20-bc2-1.build.redhat.com To: Alasdair G Kergon In-Reply-To: Message-ID: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 2/2] dm-bdev-keep-bdev-always-referenced.patch 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 Always keep the reference to structure block_device. Reference to block_device is obtained with function bdget_disk (and is released with bdput. bdget_disk was called while the device was being suspended, in dm_suspend() --- however at this point, there could be another devices already suspended. bdget_disk can wait for IO and allocate memory and this could result in waiting for already suspended device, resulting in deadlock. It caused bug https://bugzilla.redhat.com/show_bug.cgi?id=179786 This patch changes the code so that it gets the reference to struct block_device when struct mapped_device is allocated and initialized in (alloc_dev) and drops the reference when it is destroyed in free_dev. Thus, there is no call to bdget_disk, while any device is suspended. Signed-off-by: Mikulas Patocka --- drivers/md/dm.c | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel Index: linux-2.6.30-rc2-devel/drivers/md/dm.c =================================================================== --- linux-2.6.30-rc2-devel.orig/drivers/md/dm.c 2009-04-15 16:24:19.000000000 +0200 +++ linux-2.6.30-rc2-devel/drivers/md/dm.c 2009-04-15 16:24:25.000000000 +0200 @@ -1183,6 +1183,10 @@ static struct mapped_device *alloc_dev(i if (!md->wq) goto bad_thread; + md->bdev = bdget_disk(md->disk, 0); + if (!md->bdev) + goto bad_bdev; + /* Populate the mapping, nobody knows we exist yet */ spin_lock(&_minor_lock); old_md = idr_replace(&_minor_idr, md, minor); @@ -1192,6 +1196,8 @@ static struct mapped_device *alloc_dev(i return md; +bad_bdev: + destroy_workqueue(md->wq); bad_thread: put_disk(md->disk); bad_disk: @@ -1217,10 +1223,8 @@ static void free_dev(struct mapped_devic { int minor = MINOR(disk_devt(md->disk)); - if (md->bdev) { - unlock_fs(md); - bdput(md->bdev); - } + unlock_fs(md); + bdput(md->bdev); destroy_workqueue(md->wq); mempool_destroy(md->tio_pool); mempool_destroy(md->io_pool); @@ -1280,8 +1284,7 @@ static int __bind(struct mapped_device * if (size != get_capacity(md->disk)) memset(&md->geometry, 0, sizeof(md->geometry)); - if (md->bdev) - __set_size(md, size); + __set_size(md, size); if (!size) { dm_table_destroy(t); @@ -1523,11 +1526,6 @@ int dm_swap_table(struct mapped_device * if (!dm_suspended(md)) goto out; - /* without bdev, the device size cannot be changed */ - if (!md->bdev) - if (get_capacity(md->disk) != dm_table_get_size(table)) - goto out; - __unbind(md); r = __bind(md, table); @@ -1606,13 +1604,6 @@ int dm_suspend(struct mapped_device *md, /* bdget() can stall if the pending I/Os are not flushed */ if (!noflush) { - md->bdev = bdget_disk(md->disk, 0); - if (!md->bdev) { - DMWARN("bdget failed in dm_suspend"); - r = -ENOMEM; - goto out; - } - /* * Flush I/O to the device. noflush supersedes do_lockfs, * because lock_fs() needs to flush I/Os. @@ -1678,11 +1669,6 @@ int dm_suspend(struct mapped_device *md, set_bit(DMF_SUSPENDED, &md->flags); out: - if (r && md->bdev) { - bdput(md->bdev); - md->bdev = NULL; - } - dm_table_put(map); out_unlock: @@ -1711,11 +1697,6 @@ int dm_resume(struct mapped_device *md) unlock_fs(md); - if (md->bdev) { - bdput(md->bdev); - md->bdev = NULL; - } - clear_bit(DMF_SUSPENDED, &md->flags); dm_table_unplug_all(map);