2020-02-25 20:02:50

by Singh, Balbir

[permalink] [raw]
Subject: [PATCH v2 0/5] Add support for block disk resize notification

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 ([email protected]) 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 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
drivers/block/virtio_blk.c: Convert to use
set_capacity_revalidate_and_notify
drivers/block/xen-blkfront.c: Convert to use
set_capacity_revalidate_and_notify
drivers/nvme/host/core.c: Convert to use
set_capacity_revalidate_and_notify
drivers/scsi/sd.c: 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


2020-02-25 20:03:07

by Singh, Balbir

[permalink] [raw]
Subject: [PATCH v2 5/5] drivers/scsi/sd.c: Convert to use set_capacity_revalidate_and_notify

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 <[email protected]>
---
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

2020-02-25 20:03:48

by Singh, Balbir

[permalink] [raw]
Subject: [PATCH v2 4/5] drivers/nvme/host/core.c: Convert to use set_capacity_revalidate_and_notify

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 <[email protected]>
---
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 ada59df642d2..4699388c5260 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

2020-02-25 20:03:54

by Singh, Balbir

[permalink] [raw]
Subject: [PATCH v2 1/5] block/genhd: Notify udev about capacity change

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 <[email protected]>
Signed-off-by: Someswarudu Sangaraju <[email protected]>
Signed-off-by: Balbir Singh <[email protected]>
Reviewed-by: Bob Liu <[email protected]>
---
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

2020-02-26 18:09:49

by Keith Busch

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] drivers/nvme/host/core.c: Convert to use set_capacity_revalidate_and_notify

On Tue, Feb 25, 2020 at 08:01:28PM +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 <[email protected]>

Patch looks fine. Please change the commit subject prefix to just "nvme:"
to match the local style and for length constraints (the committer may
do this if they want).

Acked-by: Keith Busch <[email protected]>

2020-02-27 22:32:33

by Singh, Balbir

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] drivers/nvme/host/core.c: Convert to use set_capacity_revalidate_and_notify

On Thu, 2020-02-27 at 03:08 +0900, Keith Busch wrote:
> On Tue, Feb 25, 2020 at 08:01:28PM +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 <[email protected]>
>
> Patch looks fine. Please change the commit subject prefix to just "nvme:"
> to match the local style and for length constraints (the committer may
> do this if they want).
>
> Acked-by: Keith Busch <[email protected]>

Sure thanks! Yes, that makes sense.

Balbir Singh.

2020-03-03 04:05:50

by Singh, Balbir

[permalink] [raw]
Subject: Re: [PATCH v2 0/5] Add support for block disk resize notification

On Tue, 2020-02-25 at 20:01 +0000, Balbir Singh wrote:
> 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 ([email protected]) 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 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)
>

Ping? It's not an urgent patchset, I am happy to wait if nothing else is
needed.

Balbir Singh

2020-03-12 14:08:06

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH v2 0/5] Add support for block disk resize notification

On 3/2/20 9:03 PM, Singh, Balbir wrote:
> On Tue, 2020-02-25 at 20:01 +0000, Balbir Singh wrote:
>> 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 ([email protected]) 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 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)
>>
>
> Ping? It's not an urgent patchset, I am happy to wait if nothing else is
> needed.

It doesn't apply to the 5.7 branches, can you resend against for-5.7/block?

--
Jens Axboe

2020-03-12 22:53:21

by Singh, Balbir

[permalink] [raw]
Subject: Re: [PATCH v2 0/5] Add support for block disk resize notification

On Thu, 2020-03-12 at 08:06 -0600, Jens Axboe wrote:
>
> On 3/2/20 9:03 PM, Singh, Balbir wrote:
> > On Tue, 2020-02-25 at 20:01 +0000, Balbir Singh wrote:
> > > 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 ([email protected]) 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 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)
> > >
> >
> > Ping? It's not an urgent patchset, I am happy to wait if nothing else is
> > needed.
>
> It doesn't apply to the 5.7 branches, can you resend against for-5.7/block?
>

Thanks, I'll take a look. I used the latest next (next-20200312) and rebased
on it. I got a three way merge success on xen-blkfront

Using index info to reconstruct a base tree...
M drivers/block/xen-blkfront.c
Falling back to patching base and 3-way merge...

I presume you are running into the same thing.

I will resend the patches on top of next shortly

Balbir