Add support for block disk resize notification
Subsystems (7)
cover Add support for block disk resize notification
Allow block/genhd to notify user space about disk size changes using a new helper disk_set_capacity(), which is a wrapper on top of set_capacity(). disk_set_capacity() will only notify if the current capacity or the target capacity is not zero.
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.
Testing:
1. I did some basic testing with an NVME device, by resizing it in the backend and ensured that udevd received the event.
NOTE: After these changes, the notification might happen before revalidate disk, where as it occured later before.
Balbir Singh (5):
block/genhd: Notify udev about capacity change drivers/block/virtio_blk.c: Convert to use disk_set_capacity drivers/block/xen-blkfront.c: Convert to use disk_set_capacity drivers/nvme/host/core.c: Convert to use disk_set_capacity drivers/scsi/sd.c: Convert to use disk_set_capacity
block/genhd.c | 19 +++++++++++++++++++ drivers/block/virtio_blk.c | 4 +--- drivers/block/xen-blkfront.c | 5 +---- drivers/nvme/host/core.c | 2 +- drivers/scsi/sd.c | 2 +- include/linux/genhd.h | 1 + 6 files changed, 24 insertions(+), 9 deletions(-)
Signature · 1 line
2.16.5
PATCH RESEND 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 disk_set_capacity(), which is a wrapper on top of set_capacity(). disk_set_capacity() will only notify via udev if the current capacity or the target capacity is not zero.
--- block/genhd.c | 19 +++++++++++++++++++ include/linux/genhd.h | 1 + 2 files changed, 20 insertions(+)
block/genhd.c +19 -0
@@ -46,6 +46,25 @@ 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 disk_set_capacity (struct gendisk *disk,sector_t size) +{ +sector_t capacity =get_capacity (disk); + +set_capacity (disk, size); +if (capacity !=0 && size !=0 ) { +char *envp[] = {"RESIZE=1" ,NULL }; + +kobject_uevent_env (&disk_to_dev (disk)->kobj,KOBJ_CHANGE , envp); + } +} + +EXPORT_SYMBOL_GPL (disk_set_capacity); + +void part_inc_in_flight (struct request_queue *q,struct hd_struct *part,int rw) {if (queue_is_mq (q))
include/linux/genhd.h +1 -0
@@ -449,6 +449,7 @@ 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 disk_set_capacity (struct gendisk *disk,sector_t size);extern unsigned int disk_clear_events (struct gendisk *disk,unsigned int mask);/* drivers/char/random.c */
Signature · 7 lines
2.16.5 _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [resend v1 1/5] block/genhd: Notify udev about capacity change
Quoted 9 lines · Balbir Singh
Allow block/genhd to notify user space (via udev) about disk size changes using a new helper
disk_set_capacity(), which is a wrapper on top ofset_capacity().disk_set_capacity()will only notify via udev if the current capacity or the target capacity is not zero.Suggested-by Christoph Hellwig<[email protected]>Signed-off-by Someswarudu Sangaraju<[email protected]>Signed-off-by Balbir Singh<[email protected]>---
Since disk_set_capacity(() is on the same line as set_capacity() we should follow the same convention, which is :-
1. Avoid exporting symbol.
2. Mark new function in-line.
Unless there is a very specific reason for breaking the pattern.
Why not this (totally untested but easy convey above comment) on the top of this patch ?
# git diff
block/genhd.c +0 -13
@@ -46,25 +46,6 @@ 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 disk_set_capacity (struct gendisk *disk,sector_t size) -{ -sector_t capacity =get_capacity (disk); - -set_capacity (disk, size); -if (capacity !=0 && size !=0 ) { -char *envp[] = {"RESIZE=1" ,NULL }; - - kobject_uevent_env(&disk_to_dev(disk)->kobj,
KOBJ_CHANGE, envp);
- }
-}
-
-EXPORT_SYMBOL_GPL(disk_set_capacity);
-
-
void part_inc_in_flight(struct request_queue *q, struct hd_struct
*part, int rw)
{
if (queue_is_mq(q))include/linux/genhd.h +0 -0
@@ -469,6 +469,22 @@ static inline void set_capacity(struct gendisk
*disk, sector_t size)
disk->part0.nr_sects = size;
}
+/*
+ * Set disk capacity and notify if the size is not currently
+ * zero and will not be set to zero
+ */
+static inline void disk_set_capacity(struct gendisk *disk, sector_t size) +{
+ sector_t capacity = get_capacity(disk);
+
+ set_capacity(disk, size);
+ if (capacity != 0 && size != 0) {
+ char *envp[] = { "RESIZE=1", NULL };
+
+ kobject_uevent_env(&disk_to_dev(disk)->kobj,KOBJ_CHANGE, envp);
+ }
+}
+
#ifdef CONFIG_SOLARIS_X86_PARTITION
Re: [resend v1 1/5] block/genhd: Notify udev about capacity change
Quoted 11 lines · Chaitanya Kulkarni
Quoted 9 lines · Balbir Singh
Allow block/genhd to notify user space (via udev) about disk size changes using a new helper
disk_set_capacity(), which is a wrapper on top ofset_capacity().disk_set_capacity()will only notify via udev if the current capacity or the target capacity is not zero.Suggested-by Christoph Hellwig<[email protected]>Signed-off-by Someswarudu Sangaraju<[email protected]>Signed-off-by Balbir Singh<[email protected]>---
Quoted 8 lines
Since disk_set_capacity(() is on the same line as
set_capacity()we should follow the same convention, which is :-1. Avoid exporting symbol.
2. Mark new function in-line.Unless there is a very specific reason for breaking the pattern.
I don't see the benefit of marking it as inline. I expect this code to be potentially expanded to provide callbacks into file system code for expansion (something you brought up), marking it as inline might be a limitation.
I'd rather not clutter the headers with this code, but I am open to what the maintainers think as well.
Balbir Singh.
Re: [resend v1 1/5] block/genhd: Notify udev about capacity change
Quoted 12 lines · Balbir
Quoted 8 lines
Quoted 8 lines
Since disk_set_capacity(() is on the same line as
set_capacity()we should follow the same convention, which is :-1. Avoid exporting symbol.
2. Mark new function in-line.Unless there is a very specific reason for breaking the pattern.
I don't see the benefit of marking it as inline. I expect this code to be potentially expanded to provide callbacks into file system code for expansion (something you brought up), marking it as inline might be a limitation.
That can be done as a prep patch when framework is ready.
Quoted 3 lines
I'd rather not clutter the headers with this code, but I am open to what the maintainers think as well.
Okay.
Quoted 3 lines
Balbir Singh.
[email protected]
maintainerRe: [resend v1 1/5] block/genhd: Notify udev about capacity change
In reply to Chaitanya KulkarniQuoted 7 lines · Chaitanya Kulkarni
Since disk_set_capacity(() is on the same line as
set_capacity()we should follow the same convention, which is :-1. Avoid exporting symbol.
2. Mark new function in-line.Unless there is a very specific reason for breaking the pattern.
Why would we mark it as inline? It isn't by any means in the fast path, and there are no easy opportunities for constant propagation, so the only thing that would do is increase the code size.
Re: [resend v1 1/5] block/genhd: Notify udev about capacity change
In reply to Balbir SinghHi Balbir,
Quoted 4 lines
Allow block/genhd to notify user space (via udev) about disk size changes using a new helper
disk_set_capacity(), which is a wrapper on top ofset_capacity().disk_set_capacity()will only notify via udev if the current capacity or the target capacity is not zero.
I know set_capacity() is called all over the place making it a bit of a pain to audit. Is that the reason you introduced a new function instead of just emitting the event in set_capacity()?
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Re: [resend v1 1/5] block/genhd: Notify udev about capacity change
Quoted 11 lines · Martin K. Petersen
Hi Balbir,
Quoted 4 lines
Allow block/genhd to notify user space (via udev) about disk size changes using a new helper
disk_set_capacity(), which is a wrapper on top ofset_capacity().disk_set_capacity()will only notify via udev if the current capacity or the target capacity is not zero.I know
set_capacity()is called all over the place making it a bit of a pain to audit. Is that the reason you introduced a new function instead of just emitting the event inset_capacity()?
I did this to avoid having to enforce that set_capacity() implied a notification. Largely to control the impact of the change by default.
Balbir Singh.
Re: [resend v1 1/5] block/genhd: Notify udev about capacity change
Balbir,
Quoted 2 lines
I did this to avoid having to enforce that
set_capacity()implied a notification. Largely to control the impact of the change by default.
What I thought. I'm OK with set_capacity_and_notify(), btw.
Signature · 6 lines
Martin K. Petersen Oracle Linux Engineering _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
[email protected]
maintainerRe: [resend v1 1/5] block/genhd: Notify udev about capacity change
Quoted 7 lines · Martin K. Petersen
Balbir,
Quoted 2 lines
I did this to avoid having to enforce that
set_capacity()implied a notification. Largely to control the impact of the change by default.What I thought. I'm OK with
set_capacity_and_notify(), btw.
To some extent it might make sense to always notify from set_capacity and have a set_capacity_nonotify if we don't want to notify, as in general we probably should notify unless we have a good reason not to.
Re: [resend v1 1/5] block/genhd: Notify udev about capacity change
Quoted 4 lines · On Wed, 2020-01-08 at 16:04 +0100, [email protected] wrote:
Quoted 3 lines · Martin K. Petersen
Balbir,
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I did this to avoid having to enforce that
set_capacity()implied a notification. Largely to control the impact of the change by default.What I thought. I'm OK with
set_capacity_and_notify(), btw.To some extent it might make sense to always notify from
set_capacityand have aset_capacity_nonotifyif we don't want to notify, as in general we probably should notify unless we have a good reason not to.
I am not sure if this is the right path, since with the new interface, we'll now have revalidate disk bits built into the function (see the comments from Bob earlier). I'd be happier converting interfaces a few at a time, A quick grep found over 100 references and I am not even sure how many of them are resizable without hotplug in/out on the fly. Hence, I limited myself to the small subset, I could consider expanding it later based on the need and their ability to resize on the fly
Balbir Singh.
PATCH RESEND 2/5 drivers/block/virtio_blk.c: Convert to use disk_set_capacity
In reply to Balbir Singhblock/genhd provides disk_set_capacity() for sending RESIZE notifications via uevents.
--- drivers/block/virtio_blk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/block/virtio_blk.c +1 -3
@@ -479,18 +479,16 @@ static void virtblk_update_capacity(struct virtio_blk *vblk, bool resize) cap_str_10, cap_str_2); -set_capacity (vblk->disk, capacity); +disk_set_capacity (vblk->disk, capacity); }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)
Signature · 1 line
2.16.5
PATCH RESEND 3/5 drivers/block/xen-blkfront.c: Convert to use disk_set_capacity
In reply to Balbir Singhblock/genhd provides disk_set_capacity() for sending RESIZE notifications via uevents.
--- drivers/block/xen-blkfront.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/block/xen-blkfront.c +1 -4
@@ -2337,7 +2337,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;switch (info->connected) {
@@ -2352,10 +2351,8 @@ static void blkfront_connect(struct blkfront_info *info)return ;printk (KERN_INFO "Setting capacity to %Lu\n" , sectors); -set_capacity (info->gd, sectors); +disk_set_capacity (info->gd, sectors);revalidate_disk (info->gd); -kobject_uevent_env (&disk_to_dev (info->gd)->kobj, -KOBJ_CHANGE , envp);return ;case BLKIF_STATE_SUSPENDED :
Signature · 1 line
2.16.5
PATCH RESEND 4/5 drivers/nvme/host/core.c: Convert to use disk_set_capacity
In reply to Balbir Singhblock/genhd provides disk_set_capacity() for sending RESIZE notifications via uevents. This notification is newly added to NVME devices
--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -1
@@ -1808,7 +1808,7 @@ static void nvme_update_disk_info(struct gendisk *disk, ns->lba_shift > PAGE_SHIFT) capacity =0 ; -set_capacity (disk, capacity); +disk_set_capacity (disk, capacity);nvme_config_discard (disk, ns);nvme_config_write_zeroes (disk, ns);
Signature · 1 line
2.16.5
Re: [resend v1 4/5] drivers/nvme/host/core.c: Convert to use disk_set_capacity
Quick question here if user executes nvme ns-rescan /dev/nvme1 will following code result in triggering uevent(s) for the namespace(s( for which there is no change in the size ?
If so is that an expected behavior ?
Quoted 23 lines · Balbir Singh
block/genhd provides
disk_set_capacity()for sending RESIZE notifications via uevents. This notification is newly added to NVME devicesSigned-off-by Balbir Singh <[email protected]>--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/nvme/host/core.c +1
-1@@ -1808,7 +1808,7 @@ static void nvme_update_disk_info(struct gendisk *disk, ns->lba_shift > PAGE_SHIFT) capacity =0 ; -set_capacity (disk, capacity); +disk_set_capacity (disk, capacity);nvme_config_discard (disk, ns);nvme_config_write_zeroes (disk, ns);
Re: [resend v1 4/5] drivers/nvme/host/core.c: Convert to use disk_set_capacity
Quoted 6 lines · Chaitanya Kulkarni
Quick question here if user executes nvme ns-rescan
/dev/nvme1will following code result in triggering uevent(s) for the namespace(s( for which there is no change in the size ?If so is that an expected behavior ?
My old code had a check to see if old_capacity != new_capacity as well. I can redo those bits if needed.
The expected behaviour is not clear, but the functionality is not broken, user space should be able to deal with a resize event where the previous capacity == new capacity IMHO.
Balbir Singh.
Quoted 29 lines · Balbir Singh
Quoted 26 lines
block/genhd provides
disk_set_capacity()for sending RESIZE notifications via uevents. This notification is newly added to NVME devicesSigned-off-by Balbir Singh <[email protected]>--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/nvme/host/core.c +1
-1@@ -1808,7 +1808,7 @@ static void nvme_update_disk_info(struct gendisk *disk, ns->lba_shift > PAGE_SHIFT) capacity =0 ; -set_capacity (disk, capacity); +disk_set_capacity (disk, capacity);nvme_config_discard(disk, ns); nvme_config_write_zeroes(disk, ns);
[email protected]
maintainerRe: [resend v1 4/5] drivers/nvme/host/core.c: Convert to use disk_set_capacity
Quoted 8 lines · Balbir
Quoted 6 lines · Chaitanya Kulkarni
Quick question here if user executes nvme ns-rescan
/dev/nvme1will following code result in triggering uevent(s) for the namespace(s( for which there is no change in the size ?If so is that an expected behavior ?
Quoted 6 lines
My old code had a check to see if
old_capacity!=new_capacityas well. I can redo those bits if needed.The expected behaviour is not clear, but the functionality is not broken, user space should be able to deal with a resize event where the previous capacity == new capacity IMHO.
I think it makes sense to not bother with a notification unless there is an actual change.
Re: [resend v1 4/5] drivers/nvme/host/core.c: Convert to use disk_set_capacity
Christoph,
Quoted 6 lines
Quoted 3 lines
The expected behaviour is not clear, but the functionality is not broken, user space should be able to deal with a resize event where the previous capacity == new capacity IMHO.
I think it makes sense to not bother with a notification unless there is an actual change.
I agree.
Signature · 6 lines
Martin K. Petersen Oracle Linux Engineering _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [resend v1 4/5] drivers/nvme/host/core.c: Convert to use disk_set_capacity
Quoted 11 lines · Martin K. Petersen
Christoph,
Quoted 6 lines
Quoted 3 lines
The expected behaviour is not clear, but the functionality is not broken, user space should be able to deal with a resize event where the previous capacity == new capacity IMHO.
I think it makes sense to not bother with a notification unless there is an actual change.
I agree.
Yes, absolutely.
Re: [resend v1 4/5] drivers/nvme/host/core.c: Convert to use disk_set_capacity
In reply to [email protected]Quoted 12 lines · On Wed, 2020-01-08 at 16:04 +0100, [email protected] wrote:
Quoted 11 lines · Balbir
Quoted 6 lines · Chaitanya Kulkarni
Quick question here if user executes nvme ns-rescan
/dev/nvme1will following code result in triggering uevent(s) for the namespace(s( for which there is no change in the size ?If so is that an expected behavior ?
My old code had a check to see if
old_capacity!=new_capacityas well. I can redo those bits if needed.
Quoted 8 lines
Quoted 5 lines
The expected behaviour is not clear, but the functionality is not broken, user
space should be able to deal with a resize event where the previous capacity
== new capacity IMHO.I think it makes sense to not bother with a notification unless there is an actual change.
[Sorry for the delayed response, just back from LCA]
Agreed!
Balbir Singh
PATCH RESEND 5/5 drivers/scsi/sd.c: Convert to use disk_set_capacity
In reply to Balbir Singhblock/genhd provides disk_set_capacity() for sending RESIZE notifications via uevents. This notification is newly added to scsi sd.
--- drivers/scsi/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/sd.c +1 -1
@@ -3184,7 +3184,7 @@ static int sd_revalidate_disk(struct gendisk *disk) sdkp->first_scan =0 ; -set_capacity (disk,logical_to_sectors (sdp, sdkp->capacity)); +disk_set_capacity (disk,logical_to_sectors (sdp, sdkp->capacity));sd_config_write_same (sdkp);kfree (buffer);
Signature · 1 line
2.16.5
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
Quoted 3 lines · Balbir Singh
block/genhd provides
disk_set_capacity()for sending RESIZE notifications via uevents. This notification is newly added to scsi sd.
nit :-
The above commit messages in this series are looking odd from the ones we have in the tree and is it possible to fold it in two lines ?
[Can be done at the time of applying series.]
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
Quoted 5 lines · Chaitanya Kulkarni
Quoted 3 lines · Balbir Singh
block/genhd provides
disk_set_capacity()for sending RESIZE notifications via uevents. This notification is newly added to scsi sd.
Quoted 8 lines
nit :-
The above commit messages in this series are looking odd from the ones we have in the tree and is it possible to fold it in two lines ?
[Can be done at the time of applying series.]
Sounds good! I'll request the maintainer or repost if needed
Balbir Singh.
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
In reply to Balbir SinghBalbir,
drivers/scsi/sd.c static int sd_revalidate_disk(struct gendisk *disk) · line 3189
Quoted 12 lines
drivers/scsi/sd.c +1
-1@@ -3184,7 +3184,7 @@ static int sd_revalidate_disk(struct gendisk *disk) sdkp->first_scan =0 ; -set_capacity (disk,logical_to_sectors (sdp, sdkp->capacity)); +disk_set_capacity (disk,logical_to_sectors (sdp, sdkp->capacity));sd_config_write_same (sdkp);kfree (buffer);
We already emit an SDEV_EVT_CAPACITY_CHANGE_REPORTED event if device capacity changes. However, this event does not automatically cause revalidation.
Signature · 6 lines
Martin K. Petersen Oracle Linux Engineering _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
Quoted 13 lines · Martin K. Petersen
Balbir,
Quoted 11 lines
drivers/scsi/sd.c +0
-1@@ -3184,7 +3184,7 @@ static int sd_revalidate_disk(struct gendisk *disk) sdkp->first_scan =0 ; -set_capacity (disk,logical_to_sectors (sdp, sdkp- >capacity));
Quoted 8 lines
drivers/scsi/sd.c static int sd_revalidate_disk(struct gendisk *disk) · line 3189
Quoted 4 lines
drivers/scsi/sd.c +1
-0+disk_set_capacity (disk,logical_to_sectors (sdp, sdkp- >capacity));drivers/scsi/sd.c +0
-0sd_config_write_same (sdkp);kfree (buffer);We already emit an
SDEV_EVT_CAPACITY_CHANGE_REPORTEDevent if device capacity changes. However, this event does not automatically cause revalidation.
Which I seem to remember was a deliberate choice: some change capacities occur because the path goes passive and default values get installed.
James
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
James,
Quoted 7 lines
Quoted 3 lines
We already emit an
SDEV_EVT_CAPACITY_CHANGE_REPORTEDevent if device capacity changes. However, this event does not automatically cause revalidation.Which I seem to remember was a deliberate choice: some change capacities occur because the path goes passive and default values get installed.
Yep, it's very tricky territory.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
Quoted 6 lines · Martin K. Petersen
James,
Quoted 4 lines
Quoted 3 lines
We already emit an
SDEV_EVT_CAPACITY_CHANGE_REPORTEDevent if device capacity changes. However, this event does not automatically cause revalidation.
Quoted 6 lines
Quoted 3 lines
Which I seem to remember was a deliberate choice: some change capacities occur because the path goes passive and default values get installed.
Yep, it's very tricky territory.
Yes, there are some storage arrays that refuse a READ CAPACITY command in certain ALUA states so you can't get the new capacity anyway.
It might be nice to improve this, though, there are some cases now where we set the capacity to zero when we revalidate and can't get the value.
-Ewan
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
Ewan,
Quoted 3 lines
Yes, there are some storage arrays that refuse a READ CAPACITY command in certain ALUA states so you can't get the new capacity anyway.
Yep. And some devices will temporarily return a capacity of 0xFFFFFFFF... If we were to trigger a filesystem resize, the results would be disastrous.
Quoted 3 lines
It might be nice to improve this, though, there are some cases now where we set the capacity to zero when we revalidate and can't get the value.
If you have a test case, let's fix it.
Signature · 6 lines
Martin K. Petersen Oracle Linux Engineering _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
Quoted 10 lines · Martin K. Petersen
Ewan,
Quoted 3 lines
Yes, there are some storage arrays that refuse a READ CAPACITY command in certain ALUA states so you can't get the new capacity anyway.
Yep. And some devices will temporarily return a capacity of
0xFFFFFFFF... If we were to trigger a filesystem resize, the results would be disastrous.
Quoted 6 lines
Quoted 3 lines
It might be nice to improve this, though, there are some cases now where we set the capacity to zero when we revalidate and can't get the value.
If you have a test case, let's fix it.
This happens with NVMe fabric devices, I thought. I'll check.
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
In reply to Martin K. PetersenQuoted 10 lines · Martin K. Petersen
Balbir,
Quoted 8 lines
drivers/scsi/sd.c +0
-0@@ -3184,7 +3184,7 @@ static int sd_revalidate_disk(struct gendisk *disk) sdkp->first_scan =0 ;
Quoted 9 lines
drivers/scsi/sd.c static int sd_revalidate_disk(struct gendisk *disk) · line 3189
Quoted 4 lines
drivers/scsi/sd.c +1
-1-set_capacity (disk,logical_to_sectors (sdp, sdkp->capacity)); +disk_set_capacity (disk,logical_to_sectors (sdp, sdkp->capacity));sd_config_write_same (sdkp);kfree (buffer);We already emit an
SDEV_EVT_CAPACITY_CHANGE_REPORTEDevent if device capacity changes. However, this event does not automatically cause revalidation.
The proposed idea is to not reinforce revalidation, unless explictly specified (in the thread before Bob Liu had suggestions). The goal is to notify user space of changes via RESIZE. SCSI sd can opt out of this IOW, I can remove this if you feel SDEV_EVT_CAPACITY_CHANGE_REPORTED is sufficient for current use cases.
Balbir Singh.
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
Balbir,
Quoted 9 lines
Quoted 3 lines
We already emit an
SDEV_EVT_CAPACITY_CHANGE_REPORTEDevent if device capacity changes. However, this event does not automatically cause revalidation.The proposed idea is to not reinforce revalidation, unless explictly specified (in the thread before Bob Liu had suggestions). The goal is to notify user space of changes via RESIZE. SCSI sd can opt out of this IOW, I can remove this if you feel
SDEV_EVT_CAPACITY_CHANGE_REPORTEDis sufficient for current use cases.
I have no particular objection to the code change. I was just observing that in the context of sd.c, RESIZE=1 is more of a "your request to resize was successful" notification due to the requirement of an explicit userland action in case a device reports a capacity change.
Signature · 6 lines
Martin K. Petersen Oracle Linux Engineering _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
Quoted 12 lines · Martin K. Petersen
Balbir,
Quoted 9 lines
Quoted 3 lines
We already emit an
SDEV_EVT_CAPACITY_CHANGE_REPORTEDevent if device capacity changes. However, this event does not automatically cause revalidation.The proposed idea is to not reinforce revalidation, unless explictly specified (in the thread before Bob Liu had suggestions). The goal is to notify user space of changes via RESIZE. SCSI sd can opt out of this IOW, I can remove this if you feel
SDEV_EVT_CAPACITY_CHANGE_REPORTEDis sufficient for current use cases.
Quoted 5 lines
I have no particular objection to the code change. I was just observing that in the context of
sd.c, RESIZE=1 is more of a "your request to resize was successful" notification due to the requirement of an explicit userland action in case a device reports a capacity change.
That is true, yes I agree with your observation.
Balbir Singh.
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
In reply to Martin K. PetersenQuoted 11 lines · Martin K. Petersen
Balbir,
Quoted 9 lines
Quoted 3 lines
We already emit an
SDEV_EVT_CAPACITY_CHANGE_REPORTEDevent if device capacity changes. However, this event does not automatically cause revalidation.The proposed idea is to not reinforce revalidation, unless explictly specified (in the thread before Bob Liu had suggestions). The goal is to notify user space of changes via RESIZE. SCSI sd can opt out of this IOW, I can remove this if you feel
SDEV_EVT_CAPACITY_CHANGE_REPORTEDis sufficient for current use cases.
Remember that this event is generated because of a Unit Attention from the device. We are only passing on this indication to udev. It basically allows automation without having to scrape the log file. We don't proactively look. e.g. in the case of SCSI unless you have commands being sent to the device to return the UA status you won't hear about it.
Quoted 6 lines
I have no particular objection to the code change. I was just observing that in the context of
sd.c, RESIZE=1 is more of a "your request to resize was successful" notification due to the requirement of an explicit userland action in case a device reports a capacity change.
Christoph Hellwig
maintainerRe: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
In reply to Martin K. PetersenQuoted 11 lines · Martin K. Petersen
Balbir,
Quoted 8 lines
drivers/scsi/sd.c +0
-0@@ -3184,7 +3184,7 @@ static int sd_revalidate_disk(struct gendisk *disk) sdkp->first_scan =0 ;
Quoted 8 lines
drivers/scsi/sd.c static int sd_revalidate_disk(struct gendisk *disk) · line 3189
Quoted 4 lines
drivers/scsi/sd.c +1
-1-set_capacity (disk,logical_to_sectors (sdp, sdkp->capacity)); +disk_set_capacity (disk,logical_to_sectors (sdp, sdkp->capacity));sd_config_write_same (sdkp);kfree (buffer);We already emit an
SDEV_EVT_CAPACITY_CHANGE_REPORTEDevent if device capacity changes. However, this event does not automatically cause revalidation.
Who is looking at these sdev specific events? (And who is looking at the virtio/xenblk ones?) It makes a lot of sense to have one event supported by all devices. But don't ask me which one would be the best..
Re: [resend v1 5/5] drivers/scsi/sd.c: Convert to use disk_set_capacity
Christoph,
Quoted 7 lines
Quoted 3 lines
We already emit an
SDEV_EVT_CAPACITY_CHANGE_REPORTEDevent if device capacity changes. However, this event does not automatically cause revalidation.Who is looking at these sdev specific events? (And who is looking at the virtio/xenblk ones?) It makes a lot of sense to have one event supported by all devices. But don't ask me which one would be the best..
Users typically have site-specific udev rules or similar. There is no standard entity handling these events. Sadly.
I'm all for standardizing on RESIZE=1. However, we can't really get rid of the emitting existing SDEV* event without breaking existing setups.
Signature · 6 lines
Martin K. Petersen Oracle Linux Engineering _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 5 lines · Balbir Singh
Allow block/genhd to notify user space about disk size changes using a new helper
disk_set_capacity(), which is a wrapper on top ofset_capacity().disk_set_capacity()will only notify if the current capacity or the target capacity is not zero.
set_capacity_and_notify() may be a more straightforward name.
Quoted 12 lines
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.
Quoted 7 lines
Testing:
1. I did some basic testing with an NVME device, by resizing it in the backend and ensured that udevd received the event.NOTE: After these changes, the notification might happen before revalidate disk, where as it occured later before.
It's better not to change original behavior.
How about something like:
+void set_capacity_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 != 0 && size != 0) {
char *envp[] = { "RESIZE=1", NULL };
kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp);
}
}Quoted 15 lines
Balbir Singh (5):
block/genhd: Notify udev about capacity changedrivers/block/virtio_blk.c: Convert to usedisk_set_capacitydrivers/block/xen-blkfront.c: Convert to usedisk_set_capacitydrivers/nvme/host/core.c: Convert to usedisk_set_capacitydrivers/scsi/sd.c: Convert to usedisk_set_capacityblock/genhd.c | 19 +++++++++++++++++++ drivers/block/virtio_blk.c | 4 +--- drivers/block/xen-blkfront.c | 5 +---- drivers/nvme/host/core.c | 2 +- drivers/scsi/sd.c | 2 +- include/linux/genhd.h | 1 + 6 files changed, 24 insertions(+), 9 deletions(-)
Quoted 9 lines · Bob Liu
Quoted 5 lines · Balbir Singh
Allow block/genhd to notify user space about disk size changes using a new helper
disk_set_capacity(), which is a wrapper on top ofset_capacity().disk_set_capacity()will only notify if the current capacity or the target capacity is not zero.
set_capacity_and_notify()may be a more straightforward name.
Yes, agreed.
Quoted 30 lines
Quoted 12 lines
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.
Quoted 7 lines
Testing:
1. I did some basic testing with an NVME device, by resizing it in the backend and ensured that udevd received the event.NOTE: After these changes, the notification might happen before revalidate disk, where as it occured later before.
It's better not to change original behavior.
How about something like:+void
set_capacity_and_notify(struct gendisk *disk, sector_t size, bool revalidate){ sector_t capacity = get_capacity(disk); set_capacity(disk, size);
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (revalidate) + revalidate_disk(disk);
Do you see a concern with the notification going out before revalidate_disk? I could keep the behaviour and come up with a suitable name
revalidate_disk_and_notify() (set_capacity is a part of the revalidation process), or feel free to suggest a better name
Thanks,
Balbir Singh
Bob Liu
Reviewed-byQuoted 41 lines · Balbir
Quoted 9 lines · Bob Liu
Quoted 5 lines · Balbir Singh
Allow block/genhd to notify user space about disk size changes using a new helper
disk_set_capacity(), which is a wrapper on top ofset_capacity().disk_set_capacity()will only notify if the current capacity or the target capacity is not zero.
set_capacity_and_notify()may be a more straightforward name.Yes, agreed.
Quoted 28 lines
Quoted 12 lines
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.
Quoted 7 lines
Testing:
1. I did some basic testing with an NVME device, by resizing it in the backend and ensured that udevd received the event.NOTE: After these changes, the notification might happen before revalidate disk, where as it occured later before.
It's better not to change original behavior.
How about something like:+void
set_capacity_and_notify(struct gendisk *disk, sector_t size, bool revalidate){ sector_t capacity = get_capacity(disk);
Quoted 6 lines
Review
Quoted 4 lines
set_capacity(disk, size);(quoted diff) +2
-0+ if (revalidate) + revalidate_disk(disk);Do you see a concern with the notification going out before
revalidate_disk?
Not aware any, but keep the original behavior is safer especial when not must change..
Quoted 5 lines
I could keep the behaviour and come up with a suitable name
revalidate_disk_and_notify()(set_capacityis a part of the revalidation process), or feel free to suggest a better name
Feel free to add my reviewed-by next version in this series.
Quoted 3 lines
Thanks,
Balbir Singh
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme