From patchwork Thu Jan 26 17:45:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 9539879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 18046604A0 for ; Thu, 26 Jan 2017 17:47:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEF0228174 for ; Thu, 26 Jan 2017 17:47:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE01A27F9F; Thu, 26 Jan 2017 17:47:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55CCB27F9F for ; Thu, 26 Jan 2017 17:47:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753881AbdAZRrB (ORCPT ); Thu, 26 Jan 2017 12:47:01 -0500 Received: from mx2.suse.de ([195.135.220.15]:53664 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753910AbdAZRrA (ORCPT ); Thu, 26 Jan 2017 12:47:00 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0AB5AAC08; Thu, 26 Jan 2017 17:45:54 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 348F91E06E5; Thu, 26 Jan 2017 18:45:53 +0100 (CET) From: Jan Kara To: linux-block@vger.kernel.org Cc: Christoph Hellwig , Jens Axboe , Dan Williams , Thiago Jung Bauermann , Laurent Dufour , Jan Kara Subject: [PATCH 1/4] block: Unhash block device inodes on gendisk destruction Date: Thu, 26 Jan 2017 18:45:29 +0100 Message-Id: <20170126174532.15189-2-jack@suse.cz> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170126174532.15189-1-jack@suse.cz> References: <20170126174532.15189-1-jack@suse.cz> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, block device inodes stay around after corresponding gendisk hash died until memory reclaim finds them and frees them. Since we will make block device inode pin the bdi, we want to free the block device inode as soon as the device goes away so that bdi does not stay around unnecessarily. Furthermore we need to avoid issues when new device with the same major,minor pair gets created since reusing the bdi structure would be rather difficult in this case. Unhashing block device inode on gendisk destruction nicely deals with these problems. Once last block device inode reference is dropped (which may be directly in del_gendisk()), the inode gets evicted. Furthermore if the major,minor pair gets reallocated, we are guaranteed to get new block device inode even if old block device inode is not yet evicted and thus we avoid issues with possible reuse of bdi. Signed-off-by: Jan Kara --- block/genhd.c | 2 ++ fs/block_dev.c | 15 +++++++++++++++ include/linux/fs.h | 1 + 3 files changed, 18 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index fcd6d4fae657..f2f22d0e8e14 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -648,6 +648,8 @@ void del_gendisk(struct gendisk *disk) disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE); while ((part = disk_part_iter_next(&piter))) { + bdev_unhash_inode(MKDEV(disk->major, + disk->first_minor + part->partno)); invalidate_partition(disk, part->partno); delete_partition(disk, part->partno); } diff --git a/fs/block_dev.c b/fs/block_dev.c index 5db5d1340d69..ed6a34be7a1e 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -954,6 +954,21 @@ static int bdev_set(struct inode *inode, void *data) static LIST_HEAD(all_bdevs); +/* + * If there is a bdev inode for this device, unhash it so that it gets evicted + * as soon as last inode reference is dropped. + */ +void bdev_unhash_inode(dev_t dev) +{ + struct inode *inode; + + inode = ilookup5(blockdev_superblock, hash(dev), bdev_test, &dev); + if (inode) { + remove_inode_hash(inode); + iput(inode); + } +} + struct block_device *bdget(dev_t dev) { struct block_device *bdev; diff --git a/include/linux/fs.h b/include/linux/fs.h index 2ba074328894..702cb6c50194 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2342,6 +2342,7 @@ extern struct kmem_cache *names_cachep; #ifdef CONFIG_BLOCK extern int register_blkdev(unsigned int, const char *); extern void unregister_blkdev(unsigned int, const char *); +extern void bdev_unhash_inode(dev_t dev); extern struct block_device *bdget(dev_t); extern struct block_device *bdgrab(struct block_device *bdev); extern void bd_set_size(struct block_device *, loff_t size);