From patchwork Mon Nov 22 13:06:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8461DC433EF for ; Mon, 22 Nov 2021 13:06:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236818AbhKVNJi (ORCPT ); Mon, 22 Nov 2021 08:09:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229797AbhKVNJh (ORCPT ); Mon, 22 Nov 2021 08:09:37 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59C37C061574; Mon, 22 Nov 2021 05:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Ccka5rQ6de/9yVOud2vfe9/QGfdseu/Z+9MEbjFaZCw=; b=o1vAlUi/IVJuISaLEmFbXFqUi7 08hy1srLP2ztTlZFdsjEPuSp2jQeATLzKZd7AbNihi9JwA281EEmd6mhR81R/j2hdEqNlNWfpB0s0 slEapuCmWsOoXs0dMbYN/RvaKCY6unkioMJCQF7Rdsu45W18quHpjhH/KRlfSpYC+Cwl0b1YC4lGY DpW0bbdykmIerQJqa+RD4JTq2wPErFyPaE9cYO+5jL+eWpUn+XMS2leFzqjneOmptz075CvsCzoiO /lfMcXPjBuEIoqx3SslLXyghQmeQx/WbZrThsI/hithGBsKANXdJ6CyFENSvdRDE/JwEHPBM7ySGD W/N0fNoA==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91f-00CrqU-C5; Mon, 22 Nov 2021 13:06:28 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 01/14] block: move GENHD_FL_NATIVE_CAPACITY to disk->state Date: Mon, 22 Nov 2021 14:06:12 +0100 Message-Id: <20211122130625.1136848-2-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The flag to indicate an unlocked native capacity is dynamic state, not a driver capability flag, so move it to disk->state. Signed-off-by: Christoph Hellwig --- block/partitions/core.c | 15 ++++++--------- include/linux/genhd.h | 8 +------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/block/partitions/core.c b/block/partitions/core.c index 334b72ef1d73f..520292fee9339 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -527,18 +527,15 @@ int bdev_resize_partition(struct gendisk *disk, int partno, sector_t start, static bool disk_unlock_native_capacity(struct gendisk *disk) { - const struct block_device_operations *bdops = disk->fops; - - if (bdops->unlock_native_capacity && - !(disk->flags & GENHD_FL_NATIVE_CAPACITY)) { - printk(KERN_CONT "enabling native capacity\n"); - bdops->unlock_native_capacity(disk); - disk->flags |= GENHD_FL_NATIVE_CAPACITY; - return true; - } else { + if (!disk->fops->unlock_native_capacity || + test_and_set_bit(GD_NATIVE_CAPACITY, &disk->state)) { printk(KERN_CONT "truncated\n"); return false; } + + printk(KERN_CONT "enabling native capacity\n"); + disk->fops->unlock_native_capacity(disk); + return true; } void blk_drop_partitions(struct gendisk *disk) diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 74c4102631130..e490a71e5e9dd 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -60,12 +60,6 @@ struct partition_meta_info { * (``BLOCK_EXT_MAJOR``). * This affects the maximum number of partitions. * - * ``GENHD_FL_NATIVE_CAPACITY`` (0x0080): based on information in the - * partition table, the device's capacity has been extended to its - * native capacity; i.e. the device has hidden capacity used by one - * of the partitions (this is a flag used so that native capacity is - * only ever unlocked once). - * * ``GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE`` (0x0100): event polling is * blocked whenever a writer holds an exclusive lock. * @@ -86,7 +80,6 @@ struct partition_meta_info { #define GENHD_FL_CD 0x0008 #define GENHD_FL_SUPPRESS_PARTITION_INFO 0x0020 #define GENHD_FL_EXT_DEVT 0x0040 -#define GENHD_FL_NATIVE_CAPACITY 0x0080 #define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 0x0100 #define GENHD_FL_NO_PART_SCAN 0x0200 #define GENHD_FL_HIDDEN 0x0400 @@ -140,6 +133,7 @@ struct gendisk { #define GD_NEED_PART_SCAN 0 #define GD_READ_ONLY 1 #define GD_DEAD 2 +#define GD_NATIVE_CAPACITY 3 struct mutex open_mutex; /* open/close mutex */ unsigned open_partitions; /* number of open partitions */ From patchwork Mon Nov 22 13:06:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1DF3C433FE for ; Mon, 22 Nov 2021 13:06:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbhKVNJi (ORCPT ); Mon, 22 Nov 2021 08:09:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236291AbhKVNJi (ORCPT ); Mon, 22 Nov 2021 08:09:38 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAFC4C061714; Mon, 22 Nov 2021 05:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=b2GCEzlEc2/SFxBDjm4Bkw6Sh9Bf/eM8dFi6dn2Qq10=; b=YrQtuDoxGlmZInUMSmx6CSEWng XwfXpKwo1SrAJYX1KtiovUFTbuSjAlhc7L0hJVyFOrr9fHWMezGXhthTitjinu79ILe0IFqve1IPZ FV7SCaQko1bVge4DZSM0F9jOYrGF5sHHC7T0OUcxANOd+ugcdHH3e3YKa/MKMuSq1yEdISfcCWxBB 57WlYAyUPsJS9U8sUzrEI94KTD4xyH0Oe4oh2AQDd7LU+rXJqvn0L971fpliqKMIA4IVzvJMH+qWN 0CBWYVHYCSQZZh1orFGOTT44DQy70vAHLnDrtFCYzXMPautf5VzJImDk/DtNIbOVVSfc77FOFYW8Q ZNjRZcng==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91g-00Crqe-JH; Mon, 22 Nov 2021 13:06:29 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 02/14] block: move GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE to disk->event_flags Date: Mon, 22 Nov 2021 14:06:13 +0100 Message-Id: <20211122130625.1136848-3-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE is all about the event reporting mechanism, so move it to the event_flags field. Signed-off-by: Christoph Hellwig --- block/bdev.c | 2 +- drivers/block/paride/pcd.c | 2 +- drivers/scsi/sr.c | 5 +++-- include/linux/genhd.h | 6 ++---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index b4dab2fb6a746..cf29c6508bff2 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -837,7 +837,7 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder) * used in blkdev_get/put(). */ if ((mode & FMODE_WRITE) && !bdev->bd_write_holder && - (disk->flags & GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE)) { + (disk->event_flags & DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE)) { bdev->bd_write_holder = true; unblock_events = false; } diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c index f6b1d63e96e1b..430ee8004a514 100644 --- a/drivers/block/paride/pcd.c +++ b/drivers/block/paride/pcd.c @@ -928,8 +928,8 @@ static int pcd_init_unit(struct pcd_unit *cd, bool autoprobe, int port, disk->minors = 1; strcpy(disk->disk_name, cd->name); /* umm... */ disk->fops = &pcd_bdops; - disk->flags = GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE; disk->events = DISK_EVENT_MEDIA_CHANGE; + disk->event_flags = DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE; if (!pi_init(cd->pi, autoprobe, port, mode, unit, protocol, delay, pcd_buffer, PI_PCD, verbose, cd->name)) { diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 8e4af111c0787..be445dc35f2c7 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -684,9 +684,10 @@ static int sr_probe(struct device *dev) disk->minors = 1; sprintf(disk->disk_name, "sr%d", minor); disk->fops = &sr_bdops; - disk->flags = GENHD_FL_CD | GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE; + disk->flags = GENHD_FL_CD; disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST; - disk->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT; + disk->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT | + DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE; blk_queue_rq_timeout(sdev->request_queue, SR_TIMEOUT); diff --git a/include/linux/genhd.h b/include/linux/genhd.h index e490a71e5e9dd..c1136ff3c91fa 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -60,9 +60,6 @@ struct partition_meta_info { * (``BLOCK_EXT_MAJOR``). * This affects the maximum number of partitions. * - * ``GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE`` (0x0100): event polling is - * blocked whenever a writer holds an exclusive lock. - * * ``GENHD_FL_NO_PART_SCAN`` (0x0200): partition scanning is disabled. * Used for loop devices in their default settings and some MMC * devices. @@ -80,7 +77,6 @@ struct partition_meta_info { #define GENHD_FL_CD 0x0008 #define GENHD_FL_SUPPRESS_PARTITION_INFO 0x0020 #define GENHD_FL_EXT_DEVT 0x0040 -#define GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE 0x0100 #define GENHD_FL_NO_PART_SCAN 0x0200 #define GENHD_FL_HIDDEN 0x0400 @@ -94,6 +90,8 @@ enum { DISK_EVENT_FLAG_POLL = 1 << 0, /* Forward events to udev */ DISK_EVENT_FLAG_UEVENT = 1 << 1, + /* Block event polling when open for exclusive write */ + DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE = 1 << 2, }; struct disk_events; From patchwork Mon Nov 22 13:06:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F568C43217 for ; Mon, 22 Nov 2021 13:06:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238574AbhKVNJk (ORCPT ); Mon, 22 Nov 2021 08:09:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237621AbhKVNJj (ORCPT ); Mon, 22 Nov 2021 08:09:39 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5BFEC061574; Mon, 22 Nov 2021 05:06:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=57QTZnGVKq9NbT7DiGKAwuLNXVomZEhbRKBdt6qZkIw=; b=bbH5rY4FtCTelQeicdHvWKA4kP R0oN+d2DOWSNOaSU47FHyt/sQtbBcsGkpMvKLRhsmeDFKwi/srCEHCYDuBAAEsjlPj7t+ZdfwhwjF 0nWLmgR6mRx1cxNvwRZOdj/+vmBuJEWy6EO0EC8H12oZDjlbhc0TbPd223V6PeHGOauAOCljXH2v7 INuyh32LR0fxKHxaySG9CgGPy0Mcuowz47r9Y2i3KbpS4icRqN7bfH4m8EuT4OP6pJab5SnLlz9Xn DWtL795ZwcjKwS0YTa8M4MdrygchM2TuU5qPsVQJYlXE4/OenEuBW0N1oo+HlT7wei3idgTgrG+n+ OkSxrC/A==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91h-00Crql-Rg; Mon, 22 Nov 2021 13:06:30 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 03/14] block: remove GENHD_FL_CD Date: Mon, 22 Nov 2021 14:06:14 +0100 Message-Id: <20211122130625.1136848-4-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org GENHD_FL_CD marks a gendisk as a vaguely CD-ROM like device. Besides being used internally inside of sunvdc.c an xen-blkfront it is used by xen-blkback as a hint to claim a device exported to a guest is a CD-ROM like device. Just check for disk->cdi instead which is the right indicator for "real" CD-ROM or DVD drivers. This will miss the paravirtualized guest drivers, but those make little sense to report anyway. Signed-off-by: Christoph Hellwig --- drivers/block/sunvdc.c | 17 +++++++++-------- drivers/block/xen-blkback/xenbus.c | 2 +- drivers/block/xen-blkfront.c | 26 +++++++++++--------------- drivers/scsi/sr.c | 1 - include/linux/genhd.h | 5 ----- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c index 6f45a53f7cbf5..2157936de623c 100644 --- a/drivers/block/sunvdc.c +++ b/drivers/block/sunvdc.c @@ -143,8 +143,8 @@ static int vdc_getgeo(struct block_device *bdev, struct hd_geometry *geo) static int vdc_ioctl(struct block_device *bdev, fmode_t mode, unsigned command, unsigned long argument) { + struct vdc_port *port = bdev->bd_disk->private_data; int i; - struct gendisk *disk; switch (command) { case CDROMMULTISESSION: @@ -155,12 +155,15 @@ static int vdc_ioctl(struct block_device *bdev, fmode_t mode, return 0; case CDROM_GET_CAPABILITY: - disk = bdev->bd_disk; - - if (bdev->bd_disk && (disk->flags & GENHD_FL_CD)) + if (!vdc_version_supported(port, 1, 1)) + return -EINVAL; + switch (port->vdisk_mtype) { + case VD_MEDIA_TYPE_CD: + case VD_MEDIA_TYPE_DVD: return 0; - return -EINVAL; - + default: + return -EINVAL; + } default: pr_debug(PFX "ioctl %08x not supported\n", command); return -EINVAL; @@ -854,14 +857,12 @@ static int probe_disk(struct vdc_port *port) switch (port->vdisk_mtype) { case VD_MEDIA_TYPE_CD: pr_info(PFX "Virtual CDROM %s\n", port->disk_name); - g->flags |= GENHD_FL_CD; g->flags |= GENHD_FL_REMOVABLE; set_disk_ro(g, 1); break; case VD_MEDIA_TYPE_DVD: pr_info(PFX "Virtual DVD %s\n", port->disk_name); - g->flags |= GENHD_FL_CD; g->flags |= GENHD_FL_REMOVABLE; set_disk_ro(g, 1); break; diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 914587aabca0c..62125fd4af4a7 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -510,7 +510,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, } vbd->size = vbd_sz(vbd); - if (vbd->bdev->bd_disk->flags & GENHD_FL_CD || cdrom) + if (cdrom || disk_to_cdi(vbd->bdev->bd_disk)) vbd->type |= VDISK_CDROM; if (vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE) vbd->type |= VDISK_REMOVABLE; diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 8e3983e456f3c..700c765a759a1 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -198,6 +198,7 @@ struct blkfront_info struct gendisk *gd; u16 sector_size; unsigned int physical_sector_size; + unsigned long vdisk_info; int vdevice; blkif_vdev_t handle; enum blkif_state connected; @@ -505,6 +506,7 @@ static int blkif_getgeo(struct block_device *bd, struct hd_geometry *hg) static int blkif_ioctl(struct block_device *bdev, fmode_t mode, unsigned command, unsigned long argument) { + struct blkfront_info *info = bdev->bd_disk->private_data; int i; switch (command) { @@ -514,9 +516,9 @@ static int blkif_ioctl(struct block_device *bdev, fmode_t mode, return -EFAULT; return 0; case CDROM_GET_CAPABILITY: - if (bdev->bd_disk->flags & GENHD_FL_CD) - return 0; - return -EINVAL; + if (!(info->vdisk_info & VDISK_CDROM)) + return -EINVAL; + return 0; default: return -EINVAL; } @@ -1057,9 +1059,8 @@ static char *encode_disk_name(char *ptr, unsigned int n) } static int xlvbd_alloc_gendisk(blkif_sector_t capacity, - struct blkfront_info *info, - u16 vdisk_info, u16 sector_size, - unsigned int physical_sector_size) + struct blkfront_info *info, u16 sector_size, + unsigned int physical_sector_size) { struct gendisk *gd; int nr_minors = 1; @@ -1157,15 +1158,11 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity, xlvbd_flush(info); - if (vdisk_info & VDISK_READONLY) + if (info->vdisk_info & VDISK_READONLY) set_disk_ro(gd, 1); - - if (vdisk_info & VDISK_REMOVABLE) + if (info->vdisk_info & VDISK_REMOVABLE) gd->flags |= GENHD_FL_REMOVABLE; - if (vdisk_info & VDISK_CDROM) - gd->flags |= GENHD_FL_CD; - return 0; out_free_tag_set: @@ -2304,7 +2301,6 @@ static void blkfront_connect(struct blkfront_info *info) unsigned long long sectors; unsigned long sector_size; unsigned int physical_sector_size; - unsigned int binfo; int err, i; struct blkfront_ring_info *rinfo; @@ -2342,7 +2338,7 @@ static void blkfront_connect(struct blkfront_info *info) err = xenbus_gather(XBT_NIL, info->xbdev->otherend, "sectors", "%llu", §ors, - "info", "%u", &binfo, + "info", "%u", &info->vdisk_info, "sector-size", "%lu", §or_size, NULL); if (err) { @@ -2371,7 +2367,7 @@ static void blkfront_connect(struct blkfront_info *info) } } - err = xlvbd_alloc_gendisk(sectors, info, binfo, sector_size, + err = xlvbd_alloc_gendisk(sectors, info, sector_size, physical_sector_size); if (err) { xenbus_dev_fatal(info->xbdev, err, "xlvbd_add at %s", diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index be445dc35f2c7..6646797a7756e 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -684,7 +684,6 @@ static int sr_probe(struct device *dev) disk->minors = 1; sprintf(disk->disk_name, "sr%d", minor); disk->fops = &sr_bdops; - disk->flags = GENHD_FL_CD; disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST; disk->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT | DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE; diff --git a/include/linux/genhd.h b/include/linux/genhd.h index c1136ff3c91fa..74518c576fbb9 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -46,10 +46,6 @@ struct partition_meta_info { * Must not be set for devices which are removed entirely when the * media is removed. * - * ``GENHD_FL_CD`` (0x0008): the block device is a CD-ROM-style - * device. - * Affects responses to the ``CDROM_GET_CAPABILITY`` ioctl. - * * ``GENHD_FL_SUPPRESS_PARTITION_INFO`` (0x0020): don't include * partition information in ``/proc/partitions`` or in the output of * printk_all_partitions(). @@ -74,7 +70,6 @@ struct partition_meta_info { #define GENHD_FL_REMOVABLE 0x0001 /* 2 is unused (used to be GENHD_FL_DRIVERFS) */ /* 4 is unused (used to be GENHD_FL_MEDIA_CHANGE_NOTIFY) */ -#define GENHD_FL_CD 0x0008 #define GENHD_FL_SUPPRESS_PARTITION_INFO 0x0020 #define GENHD_FL_EXT_DEVT 0x0040 #define GENHD_FL_NO_PART_SCAN 0x0200 From patchwork Mon Nov 22 13:06:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30B61C4321E for ; Mon, 22 Nov 2021 13:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236225AbhKVNJq (ORCPT ); Mon, 22 Nov 2021 08:09:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238838AbhKVNJm (ORCPT ); Mon, 22 Nov 2021 08:09:42 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03B9BC06173E; Mon, 22 Nov 2021 05:06:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=YgoVvS/2icoWCylvgE0+nRzjiKPdxDKOpRTsYAzQ6aE=; b=OTq+XPZNKDNgiMNAI0enA9ucfh D8Gx4R8p63Cfw/HrfvqD0U9+FIH/L5qWHe0wLQGcCSLiY2aRTzN5f+3rk1uT2Bx7Uq5TK6/mjdcCA DtJk4oVUAIkfLk5CuDH4aqKVIoGwkPb9z/kI72wd0EjZGoPu6suhN8Sr2jZE/Km/5y7IDkGptmDCP sUkFaPY93L4nXxa5ZIWMzgGS3P7rZgz3qGAW1alqfp7CEFJy9yKhHxD64v6Z0w0uyMsM1lLIJ4q8a 4rZFpCNQLVYBCVX0oOBjmWDQ4VUdBOudvgIIuiKiu7sCepEtk28PP6LZrbd65tMgH7afnftytwpAR 6271JG1g==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91j-00Crqv-48; Mon, 22 Nov 2021 13:06:32 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 04/14] block: remove a dead check in show_partition Date: Mon, 22 Nov 2021 14:06:15 +0100 Message-Id: <20211122130625.1136848-5-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org disk_max_parts never returns 0 given that ->minors for devices not using the extended dev_t must be non-zero, and disk_max_parts always returns DISK_MAX_PARTS for the latter. Signed-off-by: Christoph Hellwig --- block/genhd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index c5392cc24d37e..b1c0f62505bf0 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -814,9 +814,7 @@ static int show_partition(struct seq_file *seqf, void *v) struct block_device *part; unsigned long idx; - /* Don't show non-partitionable removeable devices or empty devices */ - if (!get_capacity(sgp) || (!disk_max_parts(sgp) && - (sgp->flags & GENHD_FL_REMOVABLE))) + if (!get_capacity(sgp)) return 0; if (sgp->flags & GENHD_FL_SUPPRESS_PARTITION_INFO) return 0; From patchwork Mon Nov 22 13:06:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC21BC433F5 for ; Mon, 22 Nov 2021 13:06:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239346AbhKVNJq (ORCPT ); Mon, 22 Nov 2021 08:09:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238812AbhKVNJl (ORCPT ); Mon, 22 Nov 2021 08:09:41 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B581C061714; Mon, 22 Nov 2021 05:06:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=bAb+JD+ooWjn8lt6VBuD1QqrjOcpbK8moceL7wbn6hI=; b=pK1SCNUroNUE4I0Y0GqwVVwyIK cwJcCvRggKmybYx5Wet6+hLPQJ34tV6uULwJPH535pdnXh/qRAQV73V/QcYs1iLvMt0EZ3hb73ShM 16gU2szXGuNOJNgm70uItjvKzrcnKEkKyPD0G7irZaPkWsm2FRZ35ybwxQZQOSZH3w1pN26Tms3uS +b444edcwTgJ+5i1Y8SOpL9qtlHIuhIysU09J2JlhNmWR0VDbEFdv9POaXH51WW9+29g9e8iwizj9 W69epPFwvacRFvXLcExFzKbsKVHEGWf3kY4f/CDoKaogwvuFiozN15rdVQRB7cKAWptpxIDyQDv6u PjlHyK0w==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91k-00Crr8-CB; Mon, 22 Nov 2021 13:06:33 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 05/14] block: merge disk_scan_partitions and blkdev_reread_part Date: Mon, 22 Nov 2021 14:06:16 +0100 Message-Id: <20211122130625.1136848-6-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Unify the functionality that implements a partition rescan for a gendisk. Signed-off-by: Christoph Hellwig --- block/blk.h | 1 + block/genhd.c | 19 ++++++++++++------- block/ioctl.c | 31 +++++-------------------------- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/block/blk.h b/block/blk.h index 296e3010f8d65..cb436dd017ae8 100644 --- a/block/blk.h +++ b/block/blk.h @@ -449,6 +449,7 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio, unsigned int max_sectors, bool *same_page); struct request_queue *blk_alloc_queue(int node_id); +int disk_scan_partitions(struct gendisk *disk, fmode_t mode); int disk_alloc_events(struct gendisk *disk); void disk_add_events(struct gendisk *disk); diff --git a/block/genhd.c b/block/genhd.c index b1c0f62505bf0..0cf3d30429e14 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -372,17 +372,21 @@ void disk_uevent(struct gendisk *disk, enum kobject_action action) } EXPORT_SYMBOL_GPL(disk_uevent); -static void disk_scan_partitions(struct gendisk *disk) +int disk_scan_partitions(struct gendisk *disk, fmode_t mode) { struct block_device *bdev; - if (!get_capacity(disk) || !disk_part_scan_enabled(disk)) - return; + if (!disk_part_scan_enabled(disk)) + return -EINVAL; + if (disk->open_partitions) + return -EBUSY; set_bit(GD_NEED_PART_SCAN, &disk->state); - bdev = blkdev_get_by_dev(disk_devt(disk), FMODE_READ, NULL); - if (!IS_ERR(bdev)) - blkdev_put(bdev, FMODE_READ); + bdev = blkdev_get_by_dev(disk_devt(disk), mode, NULL); + if (IS_ERR(bdev)) + return PTR_ERR(bdev); + blkdev_put(bdev, mode); + return 0; } /** @@ -509,7 +513,8 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, goto out_unregister_bdi; bdev_add(disk->part0, ddev->devt); - disk_scan_partitions(disk); + if (get_capacity(disk)) + disk_scan_partitions(disk, FMODE_READ); /* * Announce the disk and partitions after all partitions are diff --git a/block/ioctl.c b/block/ioctl.c index 0a1d10ac2e1a5..4a86340133e46 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -82,31 +82,6 @@ static int compat_blkpg_ioctl(struct block_device *bdev, } #endif -static int blkdev_reread_part(struct block_device *bdev, fmode_t mode) -{ - struct block_device *tmp; - - if (!disk_part_scan_enabled(bdev->bd_disk) || bdev_is_partition(bdev)) - return -EINVAL; - if (!capable(CAP_SYS_ADMIN)) - return -EACCES; - if (bdev->bd_disk->open_partitions) - return -EBUSY; - - /* - * Reopen the device to revalidate the driver state and force a - * partition rescan. - */ - mode &= ~FMODE_EXCL; - set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state); - - tmp = blkdev_get_by_dev(bdev->bd_dev, mode, NULL); - if (IS_ERR(tmp)) - return PTR_ERR(tmp); - blkdev_put(tmp, mode); - return 0; -} - static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, unsigned long arg, unsigned long flags) { @@ -522,7 +497,11 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, bdev->bd_disk->bdi->ra_pages = (arg * 512) / PAGE_SIZE; return 0; case BLKRRPART: - return blkdev_reread_part(bdev, mode); + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + if (bdev_is_partition(bdev)) + return -EINVAL; + return disk_scan_partitions(bdev->bd_disk, mode & ~FMODE_EXCL); case BLKTRACESTART: case BLKTRACESTOP: case BLKTRACETEARDOWN: From patchwork Mon Nov 22 13:06:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2F06C433EF for ; Mon, 22 Nov 2021 13:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239381AbhKVNJr (ORCPT ); Mon, 22 Nov 2021 08:09:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239265AbhKVNJp (ORCPT ); Mon, 22 Nov 2021 08:09:45 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6339C061757; Mon, 22 Nov 2021 05:06:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=RnxT9MLIbwrL7zTzp+T1Jj9iUQuLQQquelWXy2jYrcA=; b=rkayGMc+sElBPGiHjWUjddrfpf VaHdkJxVvEBGQhMD1GBEu8dSOgQEvP+rwaboqEX8Nhw0Gk4nfUvsgqpM8jmvhhLDSlHwhhbdXSF7u 0jIAPHiL7x/EjEJY5WXp+tK97HecLWaL6oecxm6noqtYd9oBQ3AoH7tMTe6rqtESoY6z1cvw5NzBb 6+XN6ecXB6kxA3ANk/VReANZrupp1YsClYEVW29xQn0tsxvNAdefTXkD9pV8P3WTZ099VqngsTi2z nUiSSsuI1eIbzjfqT//obZhO/hM+pQ0ZSDTDtj0Jcue+i7+7mJlJZ3VN64XLRe2x1fD3MPwWYmu8k QCO6hIfQ==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91l-00CrrT-Om; Mon, 22 Nov 2021 13:06:34 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 06/14] block: rename GENHD_FL_NO_PART_SCAN to GENHD_FL_NO_PART Date: Mon, 22 Nov 2021 14:06:17 +0100 Message-Id: <20211122130625.1136848-7-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The GENHD_FL_NO_PART_SCAN controls more than just partitions canning, so rename it to GENHD_FL_NO_PART. Signed-off-by: Christoph Hellwig Acked-by: Ulf Hansson --- block/genhd.c | 2 +- drivers/block/loop.c | 8 ++++---- drivers/block/n64cart.c | 2 +- drivers/mmc/core/block.c | 4 ++-- include/linux/genhd.h | 13 ++++++------- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 0cf3d30429e14..b37925ed1d7e9 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -500,7 +500,7 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, * and don't bother scanning for partitions either. */ disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO; - disk->flags |= GENHD_FL_NO_PART_SCAN; + disk->flags |= GENHD_FL_NO_PART; } else { ret = bdi_register(disk->bdi, "%u:%u", disk->major, disk->first_minor); diff --git a/drivers/block/loop.c b/drivers/block/loop.c index a154cab6cd989..7219d98c6fb8a 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1061,7 +1061,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, lo->lo_flags |= LO_FLAGS_PARTSCAN; partscan = lo->lo_flags & LO_FLAGS_PARTSCAN; if (partscan) - lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN; + lo->lo_disk->flags &= ~GENHD_FL_NO_PART; loop_global_unlock(lo, is_loop); if (partscan) @@ -1191,7 +1191,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) mutex_lock(&lo->lo_mutex); lo->lo_flags = 0; if (!part_shift) - lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN; + lo->lo_disk->flags |= GENHD_FL_NO_PART; lo->lo_state = Lo_unbound; mutex_unlock(&lo->lo_mutex); @@ -1301,7 +1301,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) if (!err && (lo->lo_flags & LO_FLAGS_PARTSCAN) && !(prev_lo_flags & LO_FLAGS_PARTSCAN)) { - lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN; + lo->lo_disk->flags &= ~GENHD_FL_NO_PART; partscan = true; } out_unlock: @@ -2032,7 +2032,7 @@ static int loop_add(int i) * userspace tools. Parameters like this in general should be avoided. */ if (!part_shift) - disk->flags |= GENHD_FL_NO_PART_SCAN; + disk->flags |= GENHD_FL_NO_PART; disk->flags |= GENHD_FL_EXT_DEVT; atomic_set(&lo->lo_refcnt, 0); mutex_init(&lo->lo_mutex); diff --git a/drivers/block/n64cart.c b/drivers/block/n64cart.c index 78282f01f5813..4db9a8c244af5 100644 --- a/drivers/block/n64cart.c +++ b/drivers/block/n64cart.c @@ -136,7 +136,7 @@ static int __init n64cart_probe(struct platform_device *pdev) goto out; disk->first_minor = 0; - disk->flags = GENHD_FL_NO_PART_SCAN; + disk->flags = GENHD_FL_NO_PART; disk->fops = &n64cart_fops; disk->private_data = &pdev->dev; strcpy(disk->disk_name, "n64cart"); diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 90e1bcd03b46c..a71b3512c877a 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2397,8 +2397,8 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, set_disk_ro(md->disk, md->read_only || default_ro); md->disk->flags = GENHD_FL_EXT_DEVT; if (area_type & (MMC_BLK_DATA_AREA_RPMB | MMC_BLK_DATA_AREA_BOOT)) - md->disk->flags |= GENHD_FL_NO_PART_SCAN - | GENHD_FL_SUPPRESS_PARTITION_INFO; + md->disk->flags |= GENHD_FL_NO_PART | + GENHD_FL_SUPPRESS_PARTITION_INFO; /* * As discussed on lkml, GENHD_FL_REMOVABLE should: diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 74518c576fbb9..0b9be3df94898 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -56,15 +56,15 @@ struct partition_meta_info { * (``BLOCK_EXT_MAJOR``). * This affects the maximum number of partitions. * - * ``GENHD_FL_NO_PART_SCAN`` (0x0200): partition scanning is disabled. - * Used for loop devices in their default settings and some MMC - * devices. + * ``GENHD_FL_NO_PART`` (0x0200): partition support is disabled. + * The kernel will not scan for partitions from add_disk, and users + * can't add partitions manually. * * ``GENHD_FL_HIDDEN`` (0x0400): the block device is hidden; it * doesn't produce events, doesn't appear in sysfs, and doesn't have * an associated ``bdev``. * Implies ``GENHD_FL_SUPPRESS_PARTITION_INFO`` and - * ``GENHD_FL_NO_PART_SCAN``. + * ``GENHD_FL_NO_PART``. * Used for multipath devices. */ #define GENHD_FL_REMOVABLE 0x0001 @@ -72,7 +72,7 @@ struct partition_meta_info { /* 4 is unused (used to be GENHD_FL_MEDIA_CHANGE_NOTIFY) */ #define GENHD_FL_SUPPRESS_PARTITION_INFO 0x0020 #define GENHD_FL_EXT_DEVT 0x0040 -#define GENHD_FL_NO_PART_SCAN 0x0200 +#define GENHD_FL_NO_PART 0x0200 #define GENHD_FL_HIDDEN 0x0400 enum { @@ -180,8 +180,7 @@ static inline int disk_max_parts(struct gendisk *disk) static inline bool disk_part_scan_enabled(struct gendisk *disk) { - return disk_max_parts(disk) > 1 && - !(disk->flags & GENHD_FL_NO_PART_SCAN); + return disk_max_parts(disk) > 1 && !(disk->flags & GENHD_FL_NO_PART); } static inline dev_t disk_devt(struct gendisk *disk) From patchwork Mon Nov 22 13:06:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCD4DC28D13 for ; Mon, 22 Nov 2021 13:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237298AbhKVNJs (ORCPT ); Mon, 22 Nov 2021 08:09:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238762AbhKVNJp (ORCPT ); Mon, 22 Nov 2021 08:09:45 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35B38C061758; Mon, 22 Nov 2021 05:06:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=KhZX3vkQuaBjtE8mPyMM/mQikzUCttlaMjmvtv2/Lpc=; b=iNbNTB0mDFOoKY+kw6XhYKYu6m lqYw8q0ZZtdM4vJB85oS8zkBAeS51gfkCigc0y4ivhBMdKKsbNTTfsYeSAx5vIetJaRYEWeiyXxNv Os8kDMjdLvsFrjRYBUJs/tEn+YZo2oRdOcqkbtM3otlq5qR4uhhL1fkQCcm7RoRiNriBEg8cJDMad ccfQ8PRHCBptblzGpBkVzRaWlJsSOKCjv+sTYOD6Y/66DbtHqZCkJ+w0WdA2UXCcCHbM6n6wm+Ku7 QZKYwGJVusPwHKYOvWZn35ui/GgcZ5OrYKB6u2bkY8XdhvJxO1Gkm8Aj/61ZLDVEFcKu5W6U3JMTl Ls+zO6uw==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91m-00Crrs-VM; Mon, 22 Nov 2021 13:06:36 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 07/14] block: remove the GENHD_FL_HIDDEN check in blkdev_get_no_open Date: Mon, 22 Nov 2021 14:06:18 +0100 Message-Id: <20211122130625.1136848-8-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Hidden gendisks never hash the block device inode, so this can't happen. Signed-off-by: Christoph Hellwig --- block/bdev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index cf29c6508bff2..ae063041f2910 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -753,8 +753,7 @@ struct block_device *blkdev_get_no_open(dev_t dev) if (!bdev) return NULL; - if ((bdev->bd_disk->flags & GENHD_FL_HIDDEN) || - !try_module_get(bdev->bd_disk->fops->owner)) { + if (!try_module_get(bdev->bd_disk->fops->owner)) { put_device(&bdev->bd_device); return NULL; } From patchwork Mon Nov 22 13:06:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C26DC2BA4C for ; Mon, 22 Nov 2021 13:06:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239195AbhKVNJs (ORCPT ); Mon, 22 Nov 2021 08:09:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237621AbhKVNJp (ORCPT ); Mon, 22 Nov 2021 08:09:45 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68B8FC06175A; Mon, 22 Nov 2021 05:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=wBu+QTBVEM/yEVf/ZCvJYHC4Ubf7CB3x+fS1oP2AOrE=; b=OOwpbQuuEf6R6imRQwYYKWkoTF Wvaif1h/fvaUC3L3e9hNFnJyMK4KAQKYkQS7GN4xT36zgCRxDXM4dRGwZgXy9yXPOwNrbKeC4uDm/ HduGaDLOfvTfPIcJrOB8q9FrQPb0P9ydwyIrMkegtF2KK6c+bitUDf/YsvGaWEUy4gVeR3v2X2PG5 J38fY3glhfHPtLzNa6iZ+5u1GfxyK8sIefH3hIWejj8A+nL/VOY6d4VmeRxVQp3ttjsL0afD75O8B PbtlkfSQolqxyYfh+vV7f4XZWbxNBrtZNHJks0UAyZfRTgqjLuwGPQNIr5ORNSpDkKH3/IJHWDgcc vp0TNRRw==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91o-00Crs3-Hz; Mon, 22 Nov 2021 13:06:37 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 08/14] null_blk: don't suppress partitioning information Date: Mon, 22 Nov 2021 14:06:19 +0100 Message-Id: <20211122130625.1136848-9-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This manually reverts commit 27290b469051 ("null_blk: suppress invalid partition info"). The message in that commit log can't appearch as the flag is never checked during probing, and there is no good reason to treat null_blk special in /proc/partitions. Signed-off-by: Christoph Hellwig --- drivers/block/null_blk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 323af5c9c8026..eb17def1f265e 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -1850,7 +1850,7 @@ static int null_gendisk_register(struct nullb *nullb) set_capacity(disk, size); - disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO; + disk->flags |= GENHD_FL_EXT_DEVT; disk->major = null_major; disk->first_minor = nullb->index; disk->minors = 1; From patchwork Mon Nov 22 13:06:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF901C4321E for ; Mon, 22 Nov 2021 13:06:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239429AbhKVNJu (ORCPT ); Mon, 22 Nov 2021 08:09:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238838AbhKVNJr (ORCPT ); Mon, 22 Nov 2021 08:09:47 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A53F1C061714; Mon, 22 Nov 2021 05:06:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=McEuRrX09wHuglPPFck90vcSXRADf2rmkOluye4h1CE=; b=TDAgFDIA0aMGAzQCTsYQXZYZ7j bX4oCddnzfVg21AgNCuQNX7f1acQacffeLjB0y2iJaEUMQaHbZRxAlCxMu8vjgHDTiDW0jHgrYLW2 rfl3uu+7TXLcm+/v49L6/3GlyoogmNsYO+3C+T2HeiTfjwNzJFyHi8mhHYlurC5PgloREbMU3jgVy Yq047cX/ojvbg+mYRLDUBL42/txZI0bfflYu2X9qMWKk031TITOt4eMKd2WTUGNU3QFZf8YrPaFIP AmAM5boWoZ798bNhEOLenr6V9nacyhQHeJSVpXyeBuRIofh8F/PFTv+SZFIZd0oYxVFdOFFvwFQz9 W5j4Zmpg==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91p-00CrsF-QA; Mon, 22 Nov 2021 13:06:38 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 09/14] mmc: don't set GENHD_FL_SUPPRESS_PARTITION_INFO Date: Mon, 22 Nov 2021 14:06:20 +0100 Message-Id: <20211122130625.1136848-10-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This manually reverts 07b652cdbec3 ("mmc: card: Don't show eMMC RPMB and BOOT areas in /proc/partitions"). Based on the commit description that change was purely cosmetic. mmc is the last driver that sets this flag and thus prevents it from being removed. Signed-off-by: Christoph Hellwig Acked-by: Ulf Hansson --- drivers/mmc/core/block.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index a71b3512c877a..2dd93d49d822c 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2397,8 +2397,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, set_disk_ro(md->disk, md->read_only || default_ro); md->disk->flags = GENHD_FL_EXT_DEVT; if (area_type & (MMC_BLK_DATA_AREA_RPMB | MMC_BLK_DATA_AREA_BOOT)) - md->disk->flags |= GENHD_FL_NO_PART | - GENHD_FL_SUPPRESS_PARTITION_INFO; + md->disk->flags |= GENHD_FL_NO_PART; /* * As discussed on lkml, GENHD_FL_REMOVABLE should: From patchwork Mon Nov 22 13:06:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06812C43219 for ; Mon, 22 Nov 2021 13:06:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239302AbhKVNJt (ORCPT ); Mon, 22 Nov 2021 08:09:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239406AbhKVNJs (ORCPT ); Mon, 22 Nov 2021 08:09:48 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5758C061748; Mon, 22 Nov 2021 05:06:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=q3PVOIAHYBJ4Pu/hIso5FbosXqZhQg/OhzOOopnmGTA=; b=dpmNxZlLiFKHoB+08iMEBpEZ0g l/IEzILZASigrdC/Afyb20Zn981P334eRgjHgo8ZNPv+udEWxvvKfsTvFpB4I+hAEp3uwRodSeqLX nkbrNjQWi9HAkXkwGLHva8pGF6BewSTncOJiSbOhCCW315blnNvBy4gD5XwBEw5uNRleDWdGJyEQ5 BpFwF1hKlCVmTwu4Q2hHRcoPM+b4bqs7ZXGevU3sNJmud0qokXSqpR90P1q+JUXn5Xr1aa6Bl4pgy 8iaF9rJQw1uqn127IGVKDVG/DB22mxU3sn3pbPsfkSmQxlg6ywdlP6Fts9r8ToTSQay99nPwsp/2U j2CH9kzA==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91r-00CrsS-2h; Mon, 22 Nov 2021 13:06:39 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 10/14] block: remove GENHD_FL_SUPPRESS_PARTITION_INFO Date: Mon, 22 Nov 2021 14:06:21 +0100 Message-Id: <20211122130625.1136848-11-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This flag is not set directly anywhere and only inherited from GENHD_FL_HIDDEN. Just check for GENHD_FL_HIDDEN instead. Signed-off-by: Christoph Hellwig --- block/genhd.c | 11 +++-------- include/linux/genhd.h | 9 +-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index b37925ed1d7e9..09abd41249fd4 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -496,10 +496,8 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, if (disk->flags & GENHD_FL_HIDDEN) { /* - * Don't let hidden disks show up in /proc/partitions, - * and don't bother scanning for partitions either. + * Don't bother scanning for partitions. */ - disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO; disk->flags |= GENHD_FL_NO_PART; } else { ret = bdi_register(disk->bdi, "%u:%u", @@ -725,8 +723,7 @@ void __init printk_all_partitions(void) * Don't show empty devices or things that have been * suppressed */ - if (get_capacity(disk) == 0 || - (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO)) + if (get_capacity(disk) == 0 || (disk->flags & GENHD_FL_HIDDEN)) continue; /* @@ -819,9 +816,7 @@ static int show_partition(struct seq_file *seqf, void *v) struct block_device *part; unsigned long idx; - if (!get_capacity(sgp)) - return 0; - if (sgp->flags & GENHD_FL_SUPPRESS_PARTITION_INFO) + if (!get_capacity(sgp) || (sgp->flags & GENHD_FL_HIDDEN)) return 0; rcu_read_lock(); diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 0b9be3df94898..64a2f33ae9ea4 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -46,11 +46,6 @@ struct partition_meta_info { * Must not be set for devices which are removed entirely when the * media is removed. * - * ``GENHD_FL_SUPPRESS_PARTITION_INFO`` (0x0020): don't include - * partition information in ``/proc/partitions`` or in the output of - * printk_all_partitions(). - * Used for the null block device and some MMC devices. - * * ``GENHD_FL_EXT_DEVT`` (0x0040): the driver supports extended * dynamic ``dev_t``, i.e. it wants extended device numbers * (``BLOCK_EXT_MAJOR``). @@ -63,14 +58,12 @@ struct partition_meta_info { * ``GENHD_FL_HIDDEN`` (0x0400): the block device is hidden; it * doesn't produce events, doesn't appear in sysfs, and doesn't have * an associated ``bdev``. - * Implies ``GENHD_FL_SUPPRESS_PARTITION_INFO`` and - * ``GENHD_FL_NO_PART``. + * Implies ``GENHD_FL_NO_PART``. * Used for multipath devices. */ #define GENHD_FL_REMOVABLE 0x0001 /* 2 is unused (used to be GENHD_FL_DRIVERFS) */ /* 4 is unused (used to be GENHD_FL_MEDIA_CHANGE_NOTIFY) */ -#define GENHD_FL_SUPPRESS_PARTITION_INFO 0x0020 #define GENHD_FL_EXT_DEVT 0x0040 #define GENHD_FL_NO_PART 0x0200 #define GENHD_FL_HIDDEN 0x0400 From patchwork Mon Nov 22 13:06:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06F6EC433FE for ; Mon, 22 Nov 2021 13:06:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239431AbhKVNJv (ORCPT ); Mon, 22 Nov 2021 08:09:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237621AbhKVNJu (ORCPT ); Mon, 22 Nov 2021 08:09:50 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 723A9C061574; Mon, 22 Nov 2021 05:06:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=zI2tqBnb5FtHDN+RHJHV/hNwK8oDx0rf36kBp2GygCE=; b=lGJCzOFq+c75kCQD8+NR0dKm4U fpoqbOs3SiQ5sQFhbnAbjGFOAVvNYTrttUgZ/YsBciCnRmnvIzs+xjh3PjXeqi+vl7Y1lglowSsN0 6W1FqqTg9dJqIld49xFSb0w4ymeciOX5VKXoMGV+M3+0EsIB1uOc4G8w8JVzWeD8Gj/jpg5IHDJfY 1dxZaNamwleRpoga6ZS4KsMwYyrveCk6lh0GDL4EllMYOWgO1qOrwgOfo0VBiZxMxigG6BY0K5pHE /+dG6Pcu6mlCgolrDMXriPbkxssrtcXAO1UcuCqdbXDXZnI9mef3qTbWCWYnGXR/cQrTGM4ExEzAY Nw4rZHLQ==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91s-00Crsc-Ca; Mon, 22 Nov 2021 13:06:41 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 11/14] block: remove GENHD_FL_EXT_DEVT Date: Mon, 22 Nov 2021 14:06:22 +0100 Message-Id: <20211122130625.1136848-12-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org All modern drivers can support extra partitions using the extended dev_t. In fact except for the ioctl method drivers never even see partitions in normal operation. So remove the GENHD_FL_EXT_DEVT and allow extra partitions for all block devices that do support partitions, and require those that do not support partitions to explicit disallow them using GENHD_FL_NO_PART. Signed-off-by: Christoph Hellwig --- block/genhd.c | 6 +++--- block/partitions/core.c | 9 ++++----- drivers/block/amiflop.c | 1 + drivers/block/ataflop.c | 1 + drivers/block/brd.c | 1 - drivers/block/drbd/drbd_main.c | 1 + drivers/block/floppy.c | 1 + drivers/block/loop.c | 1 - drivers/block/null_blk/main.c | 1 - drivers/block/paride/pcd.c | 1 + drivers/block/paride/pf.c | 1 + drivers/block/pktcdvd.c | 2 +- drivers/block/ps3vram.c | 1 + drivers/block/rbd.c | 6 ++---- drivers/block/swim.c | 1 + drivers/block/swim3.c | 2 +- drivers/block/virtio_blk.c | 1 - drivers/block/z2ram.c | 1 + drivers/block/zram/zram_drv.c | 1 + drivers/cdrom/gdrom.c | 1 + drivers/md/dm.c | 1 + drivers/md/md.c | 5 ----- drivers/mmc/core/block.c | 1 - drivers/mtd/ubi/block.c | 1 + drivers/scsi/sd.c | 1 - drivers/scsi/sr.c | 1 + include/linux/genhd.h | 28 +++++----------------------- 27 files changed, 30 insertions(+), 48 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 09abd41249fd4..e9346fae48ad4 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -376,7 +376,7 @@ int disk_scan_partitions(struct gendisk *disk, fmode_t mode) { struct block_device *bdev; - if (!disk_part_scan_enabled(disk)) + if (disk->flags & GENHD_FL_NO_PART) return -EINVAL; if (disk->open_partitions) return -EBUSY; @@ -438,7 +438,6 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, return ret; disk->major = BLOCK_EXT_MAJOR; disk->first_minor = ret; - disk->flags |= GENHD_FL_EXT_DEVT; } ret = disk_alloc_events(disk); @@ -872,7 +871,8 @@ static ssize_t disk_ext_range_show(struct device *dev, { struct gendisk *disk = dev_to_disk(dev); - return sprintf(buf, "%d\n", disk_max_parts(disk)); + return sprintf(buf, "%d\n", + (disk->flags & GENHD_FL_NO_PART) ? 1 : DISK_MAX_PARTS); } static ssize_t disk_removable_show(struct device *dev, diff --git a/block/partitions/core.c b/block/partitions/core.c index 520292fee9339..c2a1635922b1c 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -98,13 +98,12 @@ static void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors) static struct parsed_partitions *allocate_partitions(struct gendisk *hd) { struct parsed_partitions *state; - int nr; + int nr = DISK_MAX_PARTS; state = kzalloc(sizeof(*state), GFP_KERNEL); if (!state) return NULL; - nr = disk_max_parts(hd); state->parts = vzalloc(array_size(nr, sizeof(state->parts[0]))); if (!state->parts) { kfree(state); @@ -326,7 +325,7 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, lockdep_assert_held(&disk->open_mutex); - if (partno >= disk_max_parts(disk)) + if (partno >= DISK_MAX_PARTS) return ERR_PTR(-EINVAL); /* @@ -604,7 +603,7 @@ static int blk_add_partitions(struct gendisk *disk) struct parsed_partitions *state; int ret = -EAGAIN, p; - if (!disk_part_scan_enabled(disk)) + if (disk->flags & GENHD_FL_NO_PART) return 0; state = check_partition(disk); @@ -687,7 +686,7 @@ int bdev_disk_changed(struct gendisk *disk, bool invalidate) * userspace for this particular setup. */ if (invalidate) { - if (disk_part_scan_enabled(disk) || + if (!(disk->flags & GENHD_FL_NO_PART) || !(disk->flags & GENHD_FL_REMOVABLE)) set_capacity(disk, 0); } diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c index bf5c124c5452a..1eec5113d0b5b 100644 --- a/drivers/block/amiflop.c +++ b/drivers/block/amiflop.c @@ -1790,6 +1790,7 @@ static int fd_alloc_disk(int drive, int system) disk->first_minor = drive + system; disk->minors = 1; disk->fops = &floppy_fops; + disk->flags |= GENHD_FL_NO_PART; disk->events = DISK_EVENT_MEDIA_CHANGE; if (system) sprintf(disk->disk_name, "fd%d_msdos", drive); diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index bf769e6e32fef..f3ff9babdb5cd 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c @@ -2000,6 +2000,7 @@ static int ataflop_alloc_disk(unsigned int drive, unsigned int type) disk->minors = 1; sprintf(disk->disk_name, "fd%d", drive); disk->fops = &floppy_fops; + disk->flags |= GENHD_FL_NO_PART; disk->events = DISK_EVENT_MEDIA_CHANGE; disk->private_data = &unit[drive]; set_capacity(disk, MAX_DISK_SIZE * 2); diff --git a/drivers/block/brd.c b/drivers/block/brd.c index a896ee175d863..8fe2e4289dae3 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -405,7 +405,6 @@ static int brd_alloc(int i) disk->minors = max_part; disk->fops = &brd_fops; disk->private_data = brd; - disk->flags = GENHD_FL_EXT_DEVT; strlcpy(disk->disk_name, buf, DISK_NAME_LEN); set_capacity(disk, rd_size * 2); diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c index 53ba2dddba6e6..07b3c6093e7db 100644 --- a/drivers/block/drbd/drbd_main.c +++ b/drivers/block/drbd/drbd_main.c @@ -2734,6 +2734,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig disk->first_minor = minor; disk->minors = 1; disk->fops = &drbd_ops; + disk->flags |= GENHD_FL_NO_PART; sprintf(disk->disk_name, "drbd%d", minor); disk->private_data = device; diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index c4267da716fe6..7f0a60c4079fd 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -4503,6 +4503,7 @@ static int floppy_alloc_disk(unsigned int drive, unsigned int type) disk->first_minor = TOMINOR(drive) | (type << 2); disk->minors = 1; disk->fops = &floppy_fops; + disk->flags |= GENHD_FL_NO_PART; disk->events = DISK_EVENT_MEDIA_CHANGE; if (type) sprintf(disk->disk_name, "fd%d_type%d", drive, type); diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 7219d98c6fb8a..0954ea8cf9e3b 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2033,7 +2033,6 @@ static int loop_add(int i) */ if (!part_shift) disk->flags |= GENHD_FL_NO_PART; - disk->flags |= GENHD_FL_EXT_DEVT; atomic_set(&lo->lo_refcnt, 0); mutex_init(&lo->lo_mutex); lo->lo_number = i; diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index eb17def1f265e..54f7d490f8ebb 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -1850,7 +1850,6 @@ static int null_gendisk_register(struct nullb *nullb) set_capacity(disk, size); - disk->flags |= GENHD_FL_EXT_DEVT; disk->major = null_major; disk->first_minor = nullb->index; disk->minors = 1; diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c index 430ee8004a514..255fd3d4b8a84 100644 --- a/drivers/block/paride/pcd.c +++ b/drivers/block/paride/pcd.c @@ -928,6 +928,7 @@ static int pcd_init_unit(struct pcd_unit *cd, bool autoprobe, int port, disk->minors = 1; strcpy(disk->disk_name, cd->name); /* umm... */ disk->fops = &pcd_bdops; + disk->flags |= GENHD_FL_NO_PART; disk->events = DISK_EVENT_MEDIA_CHANGE; disk->event_flags = DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE; diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c index bf8d0ef41a0a2..b84a6448a4f75 100644 --- a/drivers/block/paride/pf.c +++ b/drivers/block/paride/pf.c @@ -942,6 +942,7 @@ static int __init pf_init_unit(struct pf_unit *pf, bool autoprobe, int port, disk->minors = 1; strcpy(disk->disk_name, pf->name); disk->fops = &pf_fops; + disk->flags |= GENHD_FL_NO_PART; disk->events = DISK_EVENT_MEDIA_CHANGE; disk->private_data = pf; diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index b53f648302c15..3af0499857ecf 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2719,7 +2719,7 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev) disk->first_minor = idx; disk->minors = 1; disk->fops = &pktcdvd_ops; - disk->flags = GENHD_FL_REMOVABLE; + disk->flags = GENHD_FL_REMOVABLE | GENHD_FL_NO_PART; strcpy(disk->disk_name, pd->name); disk->private_data = pd; diff --git a/drivers/block/ps3vram.c b/drivers/block/ps3vram.c index c1876646a4cb9..4f90819e245e9 100644 --- a/drivers/block/ps3vram.c +++ b/drivers/block/ps3vram.c @@ -742,6 +742,7 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev) priv->gendisk = gendisk; gendisk->major = ps3vram_major; gendisk->minors = 1; + gendisk->flags |= GENHD_FL_NO_PART; gendisk->fops = &ps3vram_fops; gendisk->private_data = dev; strlcpy(gendisk->disk_name, DEVICE_NAME, sizeof(gendisk->disk_name)); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 953fa134cd3db..8f140da1efe30 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -4924,12 +4924,10 @@ static int rbd_init_disk(struct rbd_device *rbd_dev) rbd_dev->dev_id); disk->major = rbd_dev->major; disk->first_minor = rbd_dev->minor; - if (single_major) { + if (single_major) disk->minors = (1 << RBD_SINGLE_MAJOR_PART_SHIFT); - disk->flags |= GENHD_FL_EXT_DEVT; - } else { + else disk->minors = RBD_MINORS_PER_MAJOR; - } disk->fops = &rbd_bd_ops; disk->private_data = rbd_dev; diff --git a/drivers/block/swim.c b/drivers/block/swim.c index 821594cd13151..fef65a18d56fa 100644 --- a/drivers/block/swim.c +++ b/drivers/block/swim.c @@ -840,6 +840,7 @@ static int swim_floppy_init(struct swim_priv *swd) swd->unit[drive].disk->minors = 1; sprintf(swd->unit[drive].disk->disk_name, "fd%d", drive); swd->unit[drive].disk->fops = &floppy_fops; + swd->unit[drive].disk->flags |= GENHD_FL_NO_PART; swd->unit[drive].disk->events = DISK_EVENT_MEDIA_CHANGE; swd->unit[drive].disk->private_data = &swd->unit[drive]; set_capacity(swd->unit[drive].disk, 2880); diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c index 4b91c9aa58926..6c39f2c9f806d 100644 --- a/drivers/block/swim3.c +++ b/drivers/block/swim3.c @@ -1227,7 +1227,7 @@ static int swim3_attach(struct macio_dev *mdev, disk->fops = &floppy_fops; disk->private_data = fs; disk->events = DISK_EVENT_MEDIA_CHANGE; - disk->flags |= GENHD_FL_REMOVABLE; + disk->flags |= GENHD_FL_REMOVABLE | GENHD_FL_NO_PART; sprintf(disk->disk_name, "fd%d", floppy_count); set_capacity(disk, 2880); rc = add_disk(disk); diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 97bf051a50ced..5bb11a8b02652 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -843,7 +843,6 @@ static int virtblk_probe(struct virtio_device *vdev) vblk->disk->minors = 1 << PART_BITS; vblk->disk->private_data = vblk; vblk->disk->fops = &virtblk_fops; - vblk->disk->flags |= GENHD_FL_EXT_DEVT; vblk->index = index; /* configure queue flush support */ diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c index ccc52c935fafc..7a6ed83481b8d 100644 --- a/drivers/block/z2ram.c +++ b/drivers/block/z2ram.c @@ -327,6 +327,7 @@ static int z2ram_register_disk(int minor) disk->major = Z2RAM_MAJOR; disk->first_minor = minor; disk->minors = 1; + disk->flags |= GENHD_FL_NO_PART; disk->fops = &z2_fops; if (minor) sprintf(disk->disk_name, "z2ram%d", minor); diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 08d7953ec5f10..b4a6a832afe33 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1945,6 +1945,7 @@ static int zram_add(void) zram->disk->major = zram_major; zram->disk->first_minor = device_id; zram->disk->minors = 1; + zram->disk->flags |= GENHD_FL_NO_PART; zram->disk->fops = &zram_devops; zram->disk->private_data = zram; snprintf(zram->disk->disk_name, 16, "zram%d", device_id); diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c index d50cc1fd34d5f..faead41709bcd 100644 --- a/drivers/cdrom/gdrom.c +++ b/drivers/cdrom/gdrom.c @@ -719,6 +719,7 @@ static void probe_gdrom_setupdisk(void) gd.disk->major = gdrom_major; gd.disk->first_minor = 1; gd.disk->minors = 1; + gd.disk->flags |= GENHD_FL_NO_PART; strcpy(gd.disk->disk_name, GDROM_DEV_NAME); } diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 662742a310cbb..280918cdcabd3 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1778,6 +1778,7 @@ static struct mapped_device *alloc_dev(int minor) md->disk->major = _major; md->disk->first_minor = minor; md->disk->minors = 1; + md->disk->flags |= GENHD_FL_NO_PART; md->disk->fops = &dm_blk_dops; md->disk->queue = md->queue; md->disk->private_data = md; diff --git a/drivers/md/md.c b/drivers/md/md.c index 5111ed966947e..7fbf6f0ac01be 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5707,11 +5707,6 @@ static int md_alloc(dev_t dev, char *name) mddev->queue = disk->queue; blk_set_stacking_limits(&mddev->queue->limits); blk_queue_write_cache(mddev->queue, true, true); - /* Allow extended partitions. This makes the - * 'mdp' device redundant, but we can't really - * remove it now. - */ - disk->flags |= GENHD_FL_EXT_DEVT; disk->events |= DISK_EVENT_MEDIA_CHANGE; mddev->gendisk = disk; error = add_disk(disk); diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 2dd93d49d822c..5e0960560eab7 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2395,7 +2395,6 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, md->disk->private_data = md; md->parent = parent; set_disk_ro(md->disk, md->read_only || default_ro); - md->disk->flags = GENHD_FL_EXT_DEVT; if (area_type & (MMC_BLK_DATA_AREA_RPMB | MMC_BLK_DATA_AREA_BOOT)) md->disk->flags |= GENHD_FL_NO_PART; diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c index 302426ab30f8d..a78fdf3b30f7e 100644 --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c @@ -430,6 +430,7 @@ int ubiblock_create(struct ubi_volume_info *vi) ret = -ENODEV; goto out_cleanup_disk; } + gd->flags |= GENHD_FL_NO_PART; gd->private_data = dev; sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id); set_capacity(gd, disk_capacity); diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 65875a598d629..bba1f5dafd387 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3566,7 +3566,6 @@ static int sd_probe(struct device *dev) sd_revalidate_disk(gd); - gd->flags = GENHD_FL_EXT_DEVT; if (sdp->removable) { gd->flags |= GENHD_FL_REMOVABLE; gd->events |= DISK_EVENT_MEDIA_CHANGE; diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 6646797a7756e..cf093387e42a1 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -684,6 +684,7 @@ static int sr_probe(struct device *dev) disk->minors = 1; sprintf(disk->disk_name, "sr%d", minor); disk->fops = &sr_bdops; + disk->flags |= GENHD_FL_NO_PART; disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST; disk->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT | DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE; diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 64a2f33ae9ea4..b8ced80178d64 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -46,11 +46,6 @@ struct partition_meta_info { * Must not be set for devices which are removed entirely when the * media is removed. * - * ``GENHD_FL_EXT_DEVT`` (0x0040): the driver supports extended - * dynamic ``dev_t``, i.e. it wants extended device numbers - * (``BLOCK_EXT_MAJOR``). - * This affects the maximum number of partitions. - * * ``GENHD_FL_NO_PART`` (0x0200): partition support is disabled. * The kernel will not scan for partitions from add_disk, and users * can't add partitions manually. @@ -64,7 +59,6 @@ struct partition_meta_info { #define GENHD_FL_REMOVABLE 0x0001 /* 2 is unused (used to be GENHD_FL_DRIVERFS) */ /* 4 is unused (used to be GENHD_FL_MEDIA_CHANGE_NOTIFY) */ -#define GENHD_FL_EXT_DEVT 0x0040 #define GENHD_FL_NO_PART 0x0200 #define GENHD_FL_HIDDEN 0x0400 @@ -94,13 +88,13 @@ struct blk_integrity { }; struct gendisk { - /* major, first_minor and minors are input parameters only, - * don't use directly. Use disk_devt() and disk_max_parts(). + /* + * major/first_minor/minors should not be set by any new driver, the + * block core will take care of allocating them automatically. */ - int major; /* major number of driver */ + int major; int first_minor; - int minors; /* maximum number of minors, =1 for - * disks that can't be partitioned. */ + int minors; char disk_name[DISK_NAME_LEN]; /* name of major driver */ @@ -164,18 +158,6 @@ static inline bool disk_live(struct gendisk *disk) #define disk_to_cdi(disk) NULL #endif -static inline int disk_max_parts(struct gendisk *disk) -{ - if (disk->flags & GENHD_FL_EXT_DEVT) - return DISK_MAX_PARTS; - return disk->minors; -} - -static inline bool disk_part_scan_enabled(struct gendisk *disk) -{ - return disk_max_parts(disk) > 1 && !(disk->flags & GENHD_FL_NO_PART); -} - static inline dev_t disk_devt(struct gendisk *disk) { return MKDEV(disk->major, disk->first_minor); From patchwork Mon Nov 22 13:06:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02A83C2BA4C for ; Mon, 22 Nov 2021 13:06:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237621AbhKVNJw (ORCPT ); Mon, 22 Nov 2021 08:09:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239473AbhKVNJv (ORCPT ); Mon, 22 Nov 2021 08:09:51 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E28F5C061574; Mon, 22 Nov 2021 05:06:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=mjWk40L5MTwPTWbglDDHC/epyxkAS29x9jk3tEii7c8=; b=kmZEeN9i2ahXtj5UJEYNITDDfI 56RV45cOJly96iKQtfFgokvsAuWxAq30kODh+RW9H+yicHCk4Hnsey5oIrGrXTzgfNraZVSPh33ex dfNonVoPyj37avKW7rFH6FcDEFrDx63YZ59AONwRIDeWCwW4TYTf1q9/xpABC75AUqOjEz7gj1iuP s2GEzVCKZBztOo37DrSqLztorRmD5rjLkpXl7iyahoL36jpna8ic0yof5AkMzXezaTbClyjXGFeGE NjhJJdaWaGqeyol6NA3fs8bqR85LEfQAT2L8V4W9Bjsc0wx9TfsOJLk0RMVfcb93qWm+QzcGUiPCC 81zWKULg==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91t-00Crsl-NT; Mon, 22 Nov 2021 13:06:42 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 12/14] block: don't set GENHD_FL_NO_PART for hidden gendisks Date: Mon, 22 Nov 2021 14:06:23 +0100 Message-Id: <20211122130625.1136848-13-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Hidden gendisks can't be opened using blkdev_get_*, so we can't really reach any of the partition scanning paths or partitioning ioctls except for the initial partition scan from add_disk. Signed-off-by: Christoph Hellwig --- block/genhd.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index e9346fae48ad4..b1c194813e22f 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -376,7 +376,7 @@ int disk_scan_partitions(struct gendisk *disk, fmode_t mode) { struct block_device *bdev; - if (disk->flags & GENHD_FL_NO_PART) + if (disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN)) return -EINVAL; if (disk->open_partitions) return -EBUSY; @@ -493,12 +493,7 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, if (ret) goto out_put_slave_dir; - if (disk->flags & GENHD_FL_HIDDEN) { - /* - * Don't bother scanning for partitions. - */ - disk->flags |= GENHD_FL_NO_PART; - } else { + if (!(disk->flags & GENHD_FL_HIDDEN)) { ret = bdi_register(disk->bdi, "%u:%u", disk->major, disk->first_minor); if (ret) From patchwork Mon Nov 22 13:06:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D68DFC28D13 for ; Mon, 22 Nov 2021 13:06:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239542AbhKVNJx (ORCPT ); Mon, 22 Nov 2021 08:09:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239505AbhKVNJw (ORCPT ); Mon, 22 Nov 2021 08:09:52 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEEE3C061574; Mon, 22 Nov 2021 05:06:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=5Uyy5PbhZA8/zW/oA9H4mT4sKjL/uHAgooK2z96GrOM=; b=UcBDa9TdjfLH0zIqU872yu7Uzr u+zixTWPA1XCbeLZQwonFMZspRhn7i9dEDkudUleUe1myxK6HQtlphPwGOXqbzG1GIvq/LtTSF0Dt rT6pkuoUuuh9gPwvyHL6+0OP0SygwzOyMuB5L7bGShlEPnOMs71Hrzb4l3yqrqXayQmL5+KjMB+dw ZxDNXEM36wPRc3Jk8XsTXTbtkNNH0WFVwrW6Sj58ZJu4mwQcy7FWSvCyN7RcNt0M+jhDVGP7r9kBO J7LzBmqlsT319AbQoPEJUNu/g/up/npXhjPHCcXYOVCu17EVw5B6mviToAG6wTQ7lBBUYzbdut80Y 3YqyecoQ==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91v-00CrtQ-11; Mon, 22 Nov 2021 13:06:43 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 13/14] block: cleanup the GENHD_FL_* definitions Date: Mon, 22 Nov 2021 14:06:24 +0100 Message-Id: <20211122130625.1136848-14-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Switch to an enum and tidy up the documentation. Signed-off-by: Christoph Hellwig --- include/linux/genhd.h | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/include/linux/genhd.h b/include/linux/genhd.h index b8ced80178d64..6906a45bc761a 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -39,28 +39,24 @@ struct partition_meta_info { /** * DOC: genhd capability flags * - * ``GENHD_FL_REMOVABLE`` (0x0001): indicates that the block device - * gives access to removable media. - * When set, the device remains present even when media is not - * inserted. - * Must not be set for devices which are removed entirely when the + * ``GENHD_FL_REMOVABLE``: indicates that the block device gives access to + * removable media. When set, the device remains present even when media is not + * inserted. Shall not be set for devices which are removed entirely when the * media is removed. * - * ``GENHD_FL_NO_PART`` (0x0200): partition support is disabled. - * The kernel will not scan for partitions from add_disk, and users - * can't add partitions manually. + * ``GENHD_FL_HIDDEN``: the block device is hidden; it doesn't produce events, + * doesn't appear in sysfs, and can't be opened from userspace or using + * blkdev_get*. Used for the underlying components of multipath devices. + * + * ``GENHD_FL_NO_PART``: partition support is disabled. The kernel will not + * scan for partitions from add_disk, and users can't add partitions manually. * - * ``GENHD_FL_HIDDEN`` (0x0400): the block device is hidden; it - * doesn't produce events, doesn't appear in sysfs, and doesn't have - * an associated ``bdev``. - * Implies ``GENHD_FL_NO_PART``. - * Used for multipath devices. */ -#define GENHD_FL_REMOVABLE 0x0001 -/* 2 is unused (used to be GENHD_FL_DRIVERFS) */ -/* 4 is unused (used to be GENHD_FL_MEDIA_CHANGE_NOTIFY) */ -#define GENHD_FL_NO_PART 0x0200 -#define GENHD_FL_HIDDEN 0x0400 +enum { + GENHD_FL_REMOVABLE = 1 << 0, + GENHD_FL_HIDDEN = 1 << 1, + GENHD_FL_NO_PART = 1 << 2, +}; enum { DISK_EVENT_MEDIA_CHANGE = 1 << 0, /* media changed */ From patchwork Mon Nov 22 13:06:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12631935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B6D6C433F5 for ; Mon, 22 Nov 2021 13:06:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239406AbhKVNJz (ORCPT ); Mon, 22 Nov 2021 08:09:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239552AbhKVNJx (ORCPT ); Mon, 22 Nov 2021 08:09:53 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 495C6C06173E; Mon, 22 Nov 2021 05:06:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=aoQsvDG2YnMv/XYYmtyzLOIg2f6d5rmmgJX2H38TISs=; b=Wty6wdG6v7kGWP8c6JNLOk+6QZ Bw77JDYqzTHBxFPKgP/l04d2TH4eJEtBDgp/hvzEGY+9PYquUpDvaal1iKZalY4YsBZN+0l0seC5o fOUvpb4GZxJpJeTd7YAxhBP7Y/vgcQQq6N9J7YO4FVRucMs+dNyrefgJFjokyzaZHHZ9ZZT9OeDfT eHxTpDEzwftBNxD8M32Qq03Cwxq1/oM/z6/AGqsWJpP6BdvvKGlWYR4hKJExDpRmFMxMWRv2fFHRw lLO7LChXDTN/HyuPwItesa22pNn64yJTlSHkPt4bZFXA+MWPlh4fAi7sS4TdlrRtmv1fhoCwax6jy xla06ZSg==; Received: from [2001:4bb8:180:22b2:9649:4579:dcf9:9fb2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mp91w-00Crtb-AY; Mon, 22 Nov 2021 13:06:45 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ulf Hansson , linux-block@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org Subject: [PATCH 14/14] sr: set GENHD_FL_REMOVABLE earlier Date: Mon, 22 Nov 2021 14:06:25 +0100 Message-Id: <20211122130625.1136848-15-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122130625.1136848-1-hch@lst.de> References: <20211122130625.1136848-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Set up GENHD_FL_REMOVABLE together with the rest of the gendisk fields. Signed-off-by: Christoph Hellwig --- drivers/scsi/sr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index cf093387e42a1..411e2b01966e8 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -684,7 +684,7 @@ static int sr_probe(struct device *dev) disk->minors = 1; sprintf(disk->disk_name, "sr%d", minor); disk->fops = &sr_bdops; - disk->flags |= GENHD_FL_NO_PART; + disk->flags |= GENHD_FL_REMOVABLE | GENHD_FL_NO_PART; disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST; disk->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT | DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE; @@ -726,7 +726,6 @@ static int sr_probe(struct device *dev) blk_pm_runtime_init(sdev->request_queue, dev); dev_set_drvdata(dev, cd); - disk->flags |= GENHD_FL_REMOVABLE; sr_revalidate_disk(cd); error = device_add_disk(&sdev->sdev_gendev, disk, NULL);