linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] Add support for block disk resize notification
@ 2020-03-13  5:30 Balbir Singh
  2020-03-13  5:30 ` [PATCH v3 1/5] block/genhd: Notify udev about capacity change Balbir Singh
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Balbir Singh @ 2020-03-13  5:30 UTC (permalink / raw)
  To: linux-kernel, linux-block, linux-nvme
  Cc: axboe, Chaitanya.Kulkarni, hch, Balbir Singh

Allow block/genhd to notify user space about disk size changes using a
new helper set_capacity_revalidate_and_notify(), which is a wrapper
on top of set_capacity(). set_capacity_revalidate_and_notify() will only notify
iff the current capacity or the target capacity is not zero and the
capacity really changes.

Background:

As a part of a patch to allow sending the RESIZE event on disk capacity
change, Christoph (hch@lst.de) requested that the patch be made generic
and the hacks for virtio block and xen block devices be removed and
merged via a generic helper.

This series consists of 5 changes. The first one adds the basic
support for changing the size and notifying. The follow up patches
are per block subsystem changes. Other block drivers can add their
changes as necessary on top of this series. Since not all devices
are resizable, the default was to add a new API and let users
slowly convert over as needed.

Testing:
1. I did some basic testing with an NVME device, by resizing it in
the backend and ensured that udevd received the event.


Changelog v3:
- Repost after rebasing
- Trim details of the subsystem/files in the subject
Changelog v2:
- Rename disk_set_capacity to set_capacity_revalidate_and_notify
- set_capacity_revalidate_and_notify can call revalidate disk
  if needed, a new bool parameter is passed (suggested by Bob Liu)

Balbir Singh (5):
  block/genhd: Notify udev about capacity change
  virtio_blk.c: Convert to use set_capacity_revalidate_and_notify
  xen-blkfront.c: Convert to use set_capacity_revalidate_and_notify
  nvme: Convert to use set_capacity_revalidate_and_notify
  scsi: Convert to use set_capacity_revalidate_and_notify

 block/genhd.c                | 24 ++++++++++++++++++++++++
 drivers/block/virtio_blk.c   |  5 +----
 drivers/block/xen-blkfront.c |  6 +-----
 drivers/nvme/host/core.c     |  2 +-
 drivers/scsi/sd.c            |  3 ++-
 include/linux/genhd.h        |  2 ++
 6 files changed, 31 insertions(+), 11 deletions(-)

-- 
2.16.6


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 1/5] block/genhd: Notify udev about capacity change
  2020-03-13  5:30 [PATCH v3 0/5] Add support for block disk resize notification Balbir Singh
@ 2020-03-13  5:30 ` Balbir Singh
  2020-03-13 11:09   ` Christoph Hellwig
  2020-03-13  5:30 ` [PATCH v3 2/5] virtio_blk.c: Convert to use set_capacity_revalidate_and_notify Balbir Singh
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Balbir Singh @ 2020-03-13  5:30 UTC (permalink / raw)
  To: linux-kernel, linux-block, linux-nvme
  Cc: axboe, Chaitanya.Kulkarni, hch, Balbir Singh, Someswarudu Sangaraju

Allow block/genhd to notify user space (via udev) about disk size changes
using a new helper set_capacity_revalidate_and_notify(), which is a wrapper
on top of set_capacity(). set_capacity_revalidate_and_notify() will only
notify via udev if the current capacity or the target capacity is not zero
and iff the capacity changes.

Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Someswarudu Sangaraju <ssomesh@amazon.com>
Signed-off-by: Balbir Singh <sblbir@amazon.com>
Reviewed-by: Bob Liu <bob.liu@oracle.com>
---
 block/genhd.c         | 24 ++++++++++++++++++++++++
 include/linux/genhd.h |  2 ++
 2 files changed, 26 insertions(+)

diff --git a/block/genhd.c b/block/genhd.c
index ff6268970ddc..6a60131baffa 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -46,6 +46,30 @@ static void disk_add_events(struct gendisk *disk);
 static void disk_del_events(struct gendisk *disk);
 static void disk_release_events(struct gendisk *disk);
 
+/*
+ * Set disk capacity and notify if the size is not currently
+ * zero and will not be set to zero
+ */
+void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
+					bool revalidate)
+{
+	sector_t capacity = get_capacity(disk);
+
+	set_capacity(disk, size);
+
+	if (revalidate)
+		revalidate_disk(disk);
+
+	if (capacity != size && capacity != 0 && size != 0) {
+		char *envp[] = { "RESIZE=1", NULL };
+
+		kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp);
+	}
+}
+
+EXPORT_SYMBOL_GPL(set_capacity_revalidate_and_notify);
+
+
 void part_inc_in_flight(struct request_queue *q, struct hd_struct *part, int rw)
 {
 	if (queue_is_mq(q))
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 6fbe58538ad6..f77f5095f20b 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -461,6 +461,8 @@ static inline int get_disk_ro(struct gendisk *disk)
 extern void disk_block_events(struct gendisk *disk);
 extern void disk_unblock_events(struct gendisk *disk);
 extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
+extern void set_capacity_revalidate_and_notify(struct gendisk *disk,
+			sector_t size, bool revalidate);
 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
 
 /* drivers/char/random.c */
-- 
2.16.6


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 2/5] virtio_blk.c: Convert to use set_capacity_revalidate_and_notify
  2020-03-13  5:30 [PATCH v3 0/5] Add support for block disk resize notification Balbir Singh
  2020-03-13  5:30 ` [PATCH v3 1/5] block/genhd: Notify udev about capacity change Balbir Singh
@ 2020-03-13  5:30 ` Balbir Singh
  2020-03-13 11:10   ` Christoph Hellwig
  2020-03-13  5:30 ` [PATCH v3 3/5] xen-blkfront.c: " Balbir Singh
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Balbir Singh @ 2020-03-13  5:30 UTC (permalink / raw)
  To: linux-kernel, linux-block, linux-nvme
  Cc: axboe, Chaitanya.Kulkarni, hch, Balbir Singh

block/genhd provides set_capacity_revalidate_and_notify() for sending RESIZE
notifications via uevents.

Signed-off-by: Balbir Singh <sblbir@amazon.com>
---
 drivers/block/virtio_blk.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 0736248999b0..f9b1e70f1b31 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -388,18 +388,15 @@ static void virtblk_update_capacity(struct virtio_blk *vblk, bool resize)
 		   cap_str_10,
 		   cap_str_2);
 
-	set_capacity(vblk->disk, capacity);
+	set_capacity_revalidate_and_notify(vblk->disk, capacity, true);
 }
 
 static void virtblk_config_changed_work(struct work_struct *work)
 {
 	struct virtio_blk *vblk =
 		container_of(work, struct virtio_blk, config_work);
-	char *envp[] = { "RESIZE=1", NULL };
 
 	virtblk_update_capacity(vblk, true);
-	revalidate_disk(vblk->disk);
-	kobject_uevent_env(&disk_to_dev(vblk->disk)->kobj, KOBJ_CHANGE, envp);
 }
 
 static void virtblk_config_changed(struct virtio_device *vdev)
-- 
2.16.6


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 3/5] xen-blkfront.c: Convert to use set_capacity_revalidate_and_notify
  2020-03-13  5:30 [PATCH v3 0/5] Add support for block disk resize notification Balbir Singh
  2020-03-13  5:30 ` [PATCH v3 1/5] block/genhd: Notify udev about capacity change Balbir Singh
  2020-03-13  5:30 ` [PATCH v3 2/5] virtio_blk.c: Convert to use set_capacity_revalidate_and_notify Balbir Singh
@ 2020-03-13  5:30 ` Balbir Singh
  2020-03-13 11:10   ` Christoph Hellwig
  2020-03-13  5:30 ` [PATCH v3 4/5] nvme: " Balbir Singh
  2020-03-13  5:30 ` [PATCH v3 5/5] scsi: " Balbir Singh
  4 siblings, 1 reply; 11+ messages in thread
From: Balbir Singh @ 2020-03-13  5:30 UTC (permalink / raw)
  To: linux-kernel, linux-block, linux-nvme
  Cc: axboe, Chaitanya.Kulkarni, hch, Balbir Singh

block/genhd provides set_capacity_revalidate_and_notify() for
sending RESIZE notifications via uevents.

Signed-off-by: Balbir Singh <sblbir@amazon.com>
---
 drivers/block/xen-blkfront.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 9df516a56bb2..915cf5b6388c 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -2338,7 +2338,6 @@ static void blkfront_connect(struct blkfront_info *info)
 	unsigned long sector_size;
 	unsigned int physical_sector_size;
 	unsigned int binfo;
-	char *envp[] = { "RESIZE=1", NULL };
 	int err, i;
 	struct blkfront_ring_info *rinfo;
 
@@ -2354,10 +2353,7 @@ static void blkfront_connect(struct blkfront_info *info)
 			return;
 		printk(KERN_INFO "Setting capacity to %Lu\n",
 		       sectors);
-		set_capacity(info->gd, sectors);
-		revalidate_disk(info->gd);
-		kobject_uevent_env(&disk_to_dev(info->gd)->kobj,
-				   KOBJ_CHANGE, envp);
+		set_capacity_revalidate_and_notify(info->gd, sectors, true);
 
 		return;
 	case BLKIF_STATE_SUSPENDED:
-- 
2.16.6


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 4/5] nvme: Convert to use set_capacity_revalidate_and_notify
  2020-03-13  5:30 [PATCH v3 0/5] Add support for block disk resize notification Balbir Singh
                   ` (2 preceding siblings ...)
  2020-03-13  5:30 ` [PATCH v3 3/5] xen-blkfront.c: " Balbir Singh
@ 2020-03-13  5:30 ` Balbir Singh
  2020-03-13 11:10   ` Christoph Hellwig
  2020-03-13  5:30 ` [PATCH v3 5/5] scsi: " Balbir Singh
  4 siblings, 1 reply; 11+ messages in thread
From: Balbir Singh @ 2020-03-13  5:30 UTC (permalink / raw)
  To: linux-kernel, linux-block, linux-nvme
  Cc: axboe, Chaitanya.Kulkarni, hch, Balbir Singh

block/genhd provides set_capacity_revalidate_and_notify() for
sending RESIZE notifications via uevents. This notification is
newly added to NVME devices

Signed-off-by: Balbir Singh <sblbir@amazon.com>
Acked-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
---
 drivers/nvme/host/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index a4d8c90ee7cc..41ad07f6a564 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1810,7 +1810,7 @@ static void nvme_update_disk_info(struct gendisk *disk,
 	    ns->lba_shift > PAGE_SHIFT)
 		capacity = 0;
 
-	set_capacity(disk, capacity);
+	set_capacity_revalidate_and_notify(disk, capacity, false);
 
 	nvme_config_discard(disk, ns);
 	nvme_config_write_zeroes(disk, ns);
-- 
2.16.6


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 5/5] scsi: Convert to use set_capacity_revalidate_and_notify
  2020-03-13  5:30 [PATCH v3 0/5] Add support for block disk resize notification Balbir Singh
                   ` (3 preceding siblings ...)
  2020-03-13  5:30 ` [PATCH v3 4/5] nvme: " Balbir Singh
@ 2020-03-13  5:30 ` Balbir Singh
  2020-03-13 11:11   ` Christoph Hellwig
  4 siblings, 1 reply; 11+ messages in thread
From: Balbir Singh @ 2020-03-13  5:30 UTC (permalink / raw)
  To: linux-kernel, linux-block, linux-nvme
  Cc: axboe, Chaitanya.Kulkarni, hch, Balbir Singh

block/genhd provides set_capacity_revalidate_and_notify() for sending RESIZE
notifications via uevents. This notification is newly added to scsi sd.

Signed-off-by: Balbir Singh <sblbir@amazon.com>
---
 drivers/scsi/sd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 8ca9299ffd36..707f47c0ec98 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3187,7 +3187,8 @@ static int sd_revalidate_disk(struct gendisk *disk)
 
 	sdkp->first_scan = 0;
 
-	set_capacity(disk, logical_to_sectors(sdp, sdkp->capacity));
+	set_capacity_revalidate_and_notify(disk,
+		logical_to_sectors(sdp, sdkp->capacity), false);
 	sd_config_write_same(sdkp);
 	kfree(buffer);
 
-- 
2.16.6


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/5] block/genhd: Notify udev about capacity change
  2020-03-13  5:30 ` [PATCH v3 1/5] block/genhd: Notify udev about capacity change Balbir Singh
@ 2020-03-13 11:09   ` Christoph Hellwig
  0 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2020-03-13 11:09 UTC (permalink / raw)
  To: Balbir Singh
  Cc: linux-kernel, linux-block, linux-nvme, axboe, Chaitanya.Kulkarni,
	hch, Someswarudu Sangaraju

On Fri, Mar 13, 2020 at 05:30:05AM +0000, Balbir Singh wrote:
> Allow block/genhd to notify user space (via udev) about disk size changes
> using a new helper set_capacity_revalidate_and_notify(), which is a wrapper
> on top of set_capacity(). set_capacity_revalidate_and_notify() will only
> notify via udev if the current capacity or the target capacity is not zero
> and iff the capacity changes.
> 
> Suggested-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Someswarudu Sangaraju <ssomesh@amazon.com>
> Signed-off-by: Balbir Singh <sblbir@amazon.com>
> Reviewed-by: Bob Liu <bob.liu@oracle.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 2/5] virtio_blk.c: Convert to use set_capacity_revalidate_and_notify
  2020-03-13  5:30 ` [PATCH v3 2/5] virtio_blk.c: Convert to use set_capacity_revalidate_and_notify Balbir Singh
@ 2020-03-13 11:10   ` Christoph Hellwig
  0 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2020-03-13 11:10 UTC (permalink / raw)
  To: Balbir Singh
  Cc: linux-kernel, linux-block, linux-nvme, axboe, Chaitanya.Kulkarni, hch

On Fri, Mar 13, 2020 at 05:30:06AM +0000, Balbir Singh wrote:
> block/genhd provides set_capacity_revalidate_and_notify() for sending RESIZE
> notifications via uevents.
> 
> Signed-off-by: Balbir Singh <sblbir@amazon.com>
> ---
>  drivers/block/virtio_blk.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 0736248999b0..f9b1e70f1b31 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -388,18 +388,15 @@ static void virtblk_update_capacity(struct virtio_blk *vblk, bool resize)
>  		   cap_str_10,
>  		   cap_str_2);
>  
> -	set_capacity(vblk->disk, capacity);
> +	set_capacity_revalidate_and_notify(vblk->disk, capacity, true);

Shouldn't the last argument be set to the resize argument passed to this
function?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 3/5] xen-blkfront.c: Convert to use set_capacity_revalidate_and_notify
  2020-03-13  5:30 ` [PATCH v3 3/5] xen-blkfront.c: " Balbir Singh
@ 2020-03-13 11:10   ` Christoph Hellwig
  0 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2020-03-13 11:10 UTC (permalink / raw)
  To: Balbir Singh
  Cc: linux-kernel, linux-block, linux-nvme, axboe, Chaitanya.Kulkarni, hch

On Fri, Mar 13, 2020 at 05:30:07AM +0000, Balbir Singh wrote:
> block/genhd provides set_capacity_revalidate_and_notify() for
> sending RESIZE notifications via uevents.
> 
> Signed-off-by: Balbir Singh <sblbir@amazon.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 4/5] nvme: Convert to use set_capacity_revalidate_and_notify
  2020-03-13  5:30 ` [PATCH v3 4/5] nvme: " Balbir Singh
@ 2020-03-13 11:10   ` Christoph Hellwig
  0 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2020-03-13 11:10 UTC (permalink / raw)
  To: Balbir Singh
  Cc: linux-kernel, linux-block, linux-nvme, axboe, Chaitanya.Kulkarni, hch

On Fri, Mar 13, 2020 at 05:30:08AM +0000, Balbir Singh wrote:
> block/genhd provides set_capacity_revalidate_and_notify() for
> sending RESIZE notifications via uevents. This notification is
> newly added to NVME devices
> 
> Signed-off-by: Balbir Singh <sblbir@amazon.com>
> Acked-by: Keith Busch <kbusch@kernel.org>
> Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 5/5] scsi: Convert to use set_capacity_revalidate_and_notify
  2020-03-13  5:30 ` [PATCH v3 5/5] scsi: " Balbir Singh
@ 2020-03-13 11:11   ` Christoph Hellwig
  0 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2020-03-13 11:11 UTC (permalink / raw)
  To: Balbir Singh
  Cc: linux-kernel, linux-block, linux-nvme, axboe, Chaitanya.Kulkarni, hch

On Fri, Mar 13, 2020 at 05:30:09AM +0000, Balbir Singh wrote:
> block/genhd provides set_capacity_revalidate_and_notify() for sending RESIZE
> notifications via uevents. This notification is newly added to scsi sd.
> 
> Signed-off-by: Balbir Singh <sblbir@amazon.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-03-13 11:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13  5:30 [PATCH v3 0/5] Add support for block disk resize notification Balbir Singh
2020-03-13  5:30 ` [PATCH v3 1/5] block/genhd: Notify udev about capacity change Balbir Singh
2020-03-13 11:09   ` Christoph Hellwig
2020-03-13  5:30 ` [PATCH v3 2/5] virtio_blk.c: Convert to use set_capacity_revalidate_and_notify Balbir Singh
2020-03-13 11:10   ` Christoph Hellwig
2020-03-13  5:30 ` [PATCH v3 3/5] xen-blkfront.c: " Balbir Singh
2020-03-13 11:10   ` Christoph Hellwig
2020-03-13  5:30 ` [PATCH v3 4/5] nvme: " Balbir Singh
2020-03-13 11:10   ` Christoph Hellwig
2020-03-13  5:30 ` [PATCH v3 5/5] scsi: " Balbir Singh
2020-03-13 11:11   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).