From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Sandeen Subject: [PATCH] block: return EBUSY from drop_partitions on mounted whole disk device Date: Wed, 05 Aug 2015 12:13:07 -0700 Message-ID: <55C26043.20002@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Cc: Jens Axboe To: "linux-fsdevel@vger.kernel.org" Return-path: Received: from mx1.redhat.com ([209.132.183.28]:60537 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751536AbbHETNI (ORCPT ); Wed, 5 Aug 2015 15:13:08 -0400 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: The BLKRRPART ioctl already fails today if any partition under the device is mounted. However, if we mkfs a whole disk and mount it, BLKRRPART happily proceeds down the invalidation path, which seems like a bad idea. Check whether the whole device is mounted by checking bd_super, and return -EBUSY if so. Signed-off-by: Eric Sandeen --- I don't know for sure if this is the right approach, but figure I'll ask in the form of a patch. ;) diff --git a/block/partition-generic.c b/block/partition-generic.c index 0d9e5f9..04f304c 100644 --- a/block/partition-generic.c +++ b/block/partition-generic.c @@ -397,7 +397,7 @@ static int drop_partitions(struct gendisk *disk, struct block_device *bdev) struct hd_struct *part; int res; - if (bdev->bd_part_count) + if (bdev->bd_super || bdev->bd_part_count) return -EBUSY; res = invalidate_partition(disk, 0); if (res)