From patchwork Tue Aug 3 07:19:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kiyoshi Ueda X-Patchwork-Id: 116695 X-Patchwork-Delegate: agk@redhat.com Received: from mx02.colomx.prod.int.phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o737QAr5001732 for ; Tue, 3 Aug 2010 07:26:46 GMT Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx02.colomx.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o737NS4w022812; Tue, 3 Aug 2010 03:23:31 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o737NRA1004117 for ; Tue, 3 Aug 2010 03:23:27 -0400 Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.7]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o737NMWf008844; Tue, 3 Aug 2010 03:23:22 -0400 Received: from tyo202.gate.nec.co.jp (TYO202.gate.nec.co.jp [202.32.8.206]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o737NDQ6009559; Tue, 3 Aug 2010 03:23:14 -0400 Received: from mailgate3.nec.co.jp ([10.7.69.195]) by tyo202.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id o737NDiw025674; Tue, 3 Aug 2010 16:23:13 +0900 (JST) Received: (from root@localhost) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) id o737NCA06888; Tue, 3 Aug 2010 16:23:12 +0900 (JST) Received: from mail02.kamome.nec.co.jp (mail02.kamome.nec.co.jp [10.25.43.5]) by mailsv4.nec.co.jp (8.13.8/8.13.4) with ESMTP id o737NCcV000354; Tue, 3 Aug 2010 16:23:12 +0900 (JST) Received: from yonosuke.jp.nec.com ([10.26.220.15] [10.26.220.15]) by mail03.kamome.nec.co.jp with ESMTP id BT-MMP-414548; Tue, 3 Aug 2010 16:19:43 +0900 Received: from elcondor.linux.bs1.fc.nec.co.jp ([10.34.125.146] [10.34.125.146]) by mail.jp.nec.com with ESMTP; Tue, 3 Aug 2010 16:19:42 +0900 Message-ID: <4C57C30A.20101@ct.jp.nec.com> Date: Tue, 03 Aug 2010 16:19:38 +0900 From: Kiyoshi Ueda User-Agent: Thunderbird 2.0.0.23 (X11/20090825) MIME-Version: 1.0 To: Alasdair Kergon References: <4C0E19A0.1040804@ct.jp.nec.com> <4C0E1B08.7060201@ct.jp.nec.com> <20100723175901.GO19063@agk-dp.fab.redhat.com> In-Reply-To: <20100723175901.GO19063@agk-dp.fab.redhat.com> X-RedHat-Spam-Score: -0.002 (SPF_HELO_PASS,SPF_PASS) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Scanned-By: MIMEDefang 2.67 on 10.5.110.7 X-loop: dm-devel@redhat.com Cc: device-mapper development Subject: Re: [dm-devel] [PATCH 3/3] dm: separate device deletion from dm_put() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 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 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 03 Aug 2010 07:26:46 +0000 (UTC) Index: 2.6.35/drivers/md/dm-ioctl.c =================================================================== --- 2.6.35.orig/drivers/md/dm-ioctl.c +++ 2.6.35/drivers/md/dm-ioctl.c @@ -270,6 +270,10 @@ retry: up_write(&_hash_lock); dm_put(md); + if (likely(keep_open_devices)) + dm_destroy(md); + else + dm_destroy_nowait(md); /* * Some mapped devices may be using other mapped @@ -640,17 +644,19 @@ static int dev_create(struct dm_ioctl *p return r; r = dm_hash_insert(param->name, *param->uuid ? param->uuid : NULL, md); - if (r) - goto out; + if (r) { + dm_put(md); + dm_destroy(md); + return r; + } param->flags &= ~DM_INACTIVE_PRESENT_FLAG; __dev_status(md, param); -out: dm_put(md); - return r; + return 0; } /* @@ -744,6 +750,7 @@ static int dev_remove(struct dm_ioctl *p param->flags |= DM_UEVENT_GENERATED_FLAG; dm_put(md); + dm_destroy(md); return 0; } Index: 2.6.35/drivers/md/dm.c =================================================================== --- 2.6.35.orig/drivers/md/dm.c +++ 2.6.35/drivers/md/dm.c @@ -2176,6 +2176,7 @@ void dm_set_mdptr(struct mapped_device * void dm_get(struct mapped_device *md) { atomic_inc(&md->holders); + BUG_ON(test_bit(DMF_FREEING, &md->flags)); } const char *dm_device_name(struct mapped_device *md) @@ -2184,27 +2185,55 @@ const char *dm_device_name(struct mapped } EXPORT_SYMBOL_GPL(dm_device_name); -void dm_put(struct mapped_device *md) +static void __dm_destroy(struct mapped_device *md, bool wait) { struct dm_table *map; - BUG_ON(test_bit(DMF_FREEING, &md->flags)); + might_sleep(); - if (atomic_dec_and_lock(&md->holders, &_minor_lock)) { - map = dm_get_live_table(md); - idr_replace(&_minor_idr, MINOR_ALLOCED, - MINOR(disk_devt(dm_disk(md)))); - set_bit(DMF_FREEING, &md->flags); - spin_unlock(&_minor_lock); - if (!dm_suspended_md(md)) { - dm_table_presuspend_targets(map); - dm_table_postsuspend_targets(map); - } - dm_sysfs_exit(md); - dm_table_put(map); - dm_table_destroy(__unbind(md)); - free_dev(md); + spin_lock(&_minor_lock); + map = dm_get_live_table(md); + idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md)))); + set_bit(DMF_FREEING, &md->flags); + spin_unlock(&_minor_lock); + + if (!dm_suspended_md(md)) { + dm_table_presuspend_targets(map); + dm_table_postsuspend_targets(map); } + + /* + * Rare but there may be I/O requests still going to complete, + * for example. Wait for all references to disappear. + * No one shouldn't increment the reference count of the mapped_device, + * after the mapped_device becomes DMF_FREEING state. + */ + if (wait) { + while (atomic_read(&md->holders)) + msleep(1); + } else if (atomic_read(&md->holders)) + DMWARN("%s: Deleting mapped_device still in use! (%d users)", + dm_device_name(md), atomic_read(&md->holders)); + + dm_sysfs_exit(md); + dm_table_put(map); + dm_table_destroy(__unbind(md)); + free_dev(md); +} + +void dm_destroy(struct mapped_device *md) +{ + __dm_destroy(md, true); +} + +void dm_destroy_nowait(struct mapped_device *md) +{ + __dm_destroy(md, false); +} + +void dm_put(struct mapped_device *md) +{ + atomic_dec(&md->holders); } EXPORT_SYMBOL_GPL(dm_put); Index: 2.6.35/drivers/md/dm.h =================================================================== --- 2.6.35.orig/drivers/md/dm.h +++ 2.6.35/drivers/md/dm.h @@ -122,6 +122,11 @@ void dm_linear_exit(void); int dm_stripe_init(void); void dm_stripe_exit(void); +/* + * mapped_device operations + */ +void dm_destroy(struct mapped_device *md); +void dm_destroy_nowait(struct mapped_device *md); int dm_open_count(struct mapped_device *md); int dm_lock_for_deletion(struct mapped_device *md);