bdev: Refresh bdev size for disks without partitioning
Subsystems (2)
Jan Kara
reviewercover bdev: Refresh bdev size for disks without partitioning
Hello,
I've been debugging for quite a long time strange issues with encrypted DVDs not being readable on Linux (bko#194965). In the end I've tracked down the problem to the fact that block device size is not updated when the media is inserted in case the DVD device is already open. This is IMO a bug in block device code as the size gets properly update in case the device has partition scanning enabled. The following series fixes the problem by refreshing disk size on each open even for devices with partition scanning disabled.
Honza
Jan Kara
reviewerPATCH 1/2 bdev: Factor out bdev revalidation into a common helper
Factor out code handling revalidation of bdev on disk change into a common helper.
--- fs/block_dev.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
fs/block_dev.c +14 -12
@@ -1512,6 +1512,14 @@ EXPORT_SYMBOL(bd_set_size);static void __blkdev_put (struct block_device *bdev,fmode_t mode,int for_part); +static void bdev_disk_changed (struct block_device *bdev,bool invalidate) +{ +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev); +} +/* * bd_mutex locking: *
@@ -1594,12 +1602,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)* The latter is necessary to prevent ghost * partitions on a removed medium. */ -if (bdev->bd_invalidated) { -if (!ret) -rescan_partitions (disk, bdev); -else if (ret == -ENOMEDIUM ) -invalidate_partitions (disk, bdev); - } +if (bdev->bd_invalidated && + (!ret || ret == -ENOMEDIUM )) +bdev_disk_changed (bdev, ret == -ENOMEDIUM );if (ret) goto out_clear;
@@ -1632,12 +1637,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)if (bdev->bd_disk->fops->open) ret = bdev->bd_disk->fops->open (bdev, mode);/* the same as first opener case, read comment there */ -if (bdev->bd_invalidated) { -if (!ret) -rescan_partitions (bdev->bd_disk, bdev); -else if (ret == -ENOMEDIUM ) -invalidate_partitions (bdev->bd_disk, bdev); - } +if (bdev->bd_invalidated && + (!ret || ret == -ENOMEDIUM )) +bdev_disk_changed (bdev, ret == -ENOMEDIUM );if (ret) goto out_unlock_bdev; }
Signature · 1 line
2.16.4
Re: [PATCH 1/2] bdev: Factor out bdev revalidation into a common helper
Quoted 30 lines · Jan Kara
Factor out code handling revalidation of bdev on disk change into a common helper.
Signed-off-by Jan Kara <[email protected]>--- fs/block_dev.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)fs/block_dev.c +8
-0@@ -1512,6 +1512,14 @@ EXPORT_SYMBOL(bd_set_size);static void __blkdev_put (struct block_device *bdev,fmode_t mode,int for_part); +static void bdev_disk_changed (struct block_device *bdev,bool invalidate) +{ +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev); +} +/* * bd_mutex locking: * @@ -1594,12 +1602,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)* The latter is necessary to prevent ghost * partitions on a removed medium.
fs/block_dev.c static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) · line 1607
Quoted 10 lines
fs/block_dev.c +3
-6*/ -if (bdev->bd_invalidated) { -if (!ret) -rescan_partitions (disk, bdev); -else if (ret == -ENOMEDIUM ) -invalidate_partitions (disk, bdev); - } +if (bdev->bd_invalidated && + (!ret || ret == -ENOMEDIUM )) +bdev_disk_changed (bdev, ret == -ENOMEDIUM );
This is a little confusing since from its name, bdev_disk_changed() seem to imply that a new disk is present but this is called only if bdev is invalidated... What about calling this simply bdev_revalidate_disk(), since rescan_partitions() will call the disk revalidate method.
Also, it seems to me that this function could be used without the complex "if ()" condition by slightly modifying it:
static void bdev_revalidate_disk(struct block_device *bdev,
bool invalidate)
{
if (bdev->bd_invalidated && invalidate)
invalidate_partitions(bdev->bd_disk, bdev);
else
rescan_partitions(bdev->bd_disk, bdev);
}Otherwise, this all looks fine to me.
Quoted 20 lines
fs/block_dev.c +3
-6if (ret) goto out_clear;@@ -1632,12 +1637,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)if (bdev->bd_disk->fops->open) ret = bdev->bd_disk->fops->open (bdev, mode);/* the same as first opener case, read comment there */ -if (bdev->bd_invalidated) { -if (!ret) -rescan_partitions (bdev->bd_disk, bdev); -else if (ret == -ENOMEDIUM ) -invalidate_partitions (bdev->bd_disk, bdev); - } +if (bdev->bd_invalidated && + (!ret || ret == -ENOMEDIUM )) +bdev_disk_changed (bdev, ret == -ENOMEDIUM );if (ret) goto out_unlock_bdev; }
Signature · 2 lines
Damien Le Moal Western Digital Research
Jan Kara
reviewerRe: [PATCH 1/2] bdev: Factor out bdev revalidation into a common helper
Quoted 38 lines · Damien Le Moal
Quoted 37 lines · Jan Kara
Factor out code handling revalidation of bdev on disk change into a common helper.
Signed-off-by Jan Kara <[email protected]>--- fs/block_dev.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)fs/block_dev.c +8
-6@@ -1512,6 +1512,14 @@ EXPORT_SYMBOL(bd_set_size);static void __blkdev_put (struct block_device *bdev,fmode_t mode,int for_part); +static void bdev_disk_changed (struct block_device *bdev,bool invalidate) +{ +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev); +} +/* * bd_mutex locking: * @@ -1594,12 +1602,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)* The latter is necessary to prevent ghost * partitions on a removed medium. */ -if (bdev->bd_invalidated) { -if (!ret) -rescan_partitions (disk, bdev); -else if (ret == -ENOMEDIUM ) -invalidate_partitions (disk, bdev); - }
Quoted 8 lines
fs/block_dev.c static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) · line 1607
Quoted 3 lines
fs/block_dev.c +3
-0+if (bdev->bd_invalidated && + (!ret || ret == -ENOMEDIUM )) +bdev_disk_changed (bdev, ret == -ENOMEDIUM );This is a little confusing since from its name,
bdev_disk_changed()seem to imply that a new disk is present but this is called only if bdev is invalidated... What about calling this simplybdev_revalidate_disk(), sincerescan_partitions()will call the disk revalidate method.
Honestly, the whole disk revalidation code is confusing to me :) I had to draw a graph of which function calls which to understand what's going on in that code and I think it could really use some refactoring. But that's besides current point :)
Your "only if bdev is invalidated" is true but not actually a full story. ->bd_invalidated effectively gets set only through check_disk_change(). All other places that end up calling flush_disk() clear bd_invalidated shortly afterwards. So the function I've created is a direct counterpart to check_disk_change() that just needs to happen after the device is successfully open. I wanted to express that in the name - hence bdev_disk_changed(). So yes, bdev_disk_changed() should be called exactly when the new disk is present. It is bd_invalidated that is actually misnamed.
Now I'm not really tied to bdev_disk_changed(). bdev_revalidate_disk() seems a bit confusing to me though because the disk has actually been already revalidated in check_disk_change() and the function won't revalidate the disk for devices with partition scan disabled.
Quoted 5 lines
Also, it seems to me that this function could be used without the complex "if ()" condition by slightly modifying it:
static void bdev_revalidate_disk(struct
block_device*bdev,
bool invalidate)
Quoted 8 lines
{ if (bdev->bd_invalidated && invalidate) invalidate_partitions(bdev->bd_disk, bdev); else rescan_partitions(bdev->bd_disk, bdev); }Otherwise, this all looks fine to me.
Well, but you don't want to call rescan_partitions() if bd_invalidated is not set. But yes, we could move bd_invalidated check into bdev_disk_changed(), but then it would seem less clear why this function is getting called. This ties somewhat to the discussion above. Hum, I guess if we call the function just bdev_revalidate(), the name won't be confusing and it would then make sense to move the bd_invalidated condition in there.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 1/2] bdev: Factor out bdev revalidation into a common helper
Quoted 48 lines · Jan Kara
Quoted 38 lines · Damien Le Moal
Quoted 37 lines · Jan Kara
Factor out code handling revalidation of bdev on disk change into a common helper.
Signed-off-by Jan Kara <[email protected]>--- fs/block_dev.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)fs/block_dev.c +8
-6@@ -1512,6 +1512,14 @@ EXPORT_SYMBOL(bd_set_size);static void __blkdev_put (struct block_device *bdev,fmode_t mode,int for_part); +static void bdev_disk_changed (struct block_device *bdev,bool invalidate) +{ +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev); +} +/* * bd_mutex locking: * @@ -1594,12 +1602,9 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)* The latter is necessary to prevent ghost * partitions on a removed medium. */ -if (bdev->bd_invalidated) { -if (!ret) -rescan_partitions (disk, bdev); -else if (ret == -ENOMEDIUM ) -invalidate_partitions (disk, bdev); - }Quoted 8 lines
fs/block_dev.c static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) · line 1607
Quoted 3 lines
fs/block_dev.c +3
-0+if (bdev->bd_invalidated && + (!ret || ret == -ENOMEDIUM )) +bdev_disk_changed (bdev, ret == -ENOMEDIUM );This is a little confusing since from its name,
bdev_disk_changed()seem to imply that a new disk is present but this is called only if bdev is invalidated... What about calling this simplybdev_revalidate_disk(), sincerescan_partitions()will call the disk revalidate method.
Quoted 4 lines
Honestly, the whole disk revalidation code is confusing to me :) I had to draw a graph of which function calls which to understand what's going on in that code and I think it could really use some refactoring. But that's besides current point :)
OK. I guess I got confused too...
Quoted 10 lines
Your "only if bdev is invalidated" is true but not actually a full story. ->bd_invalidated effectively gets set only through
check_disk_change(). All other places that end up callingflush_disk()clearbd_invalidatedshortly afterwards. So the function I've created is a direct counterpart tocheck_disk_change()that just needs to happen after the device is successfully open. I wanted to express that in the name - hencebdev_disk_changed(). So yes,bdev_disk_changed()should be called exactly when the new disk is present. It isbd_invalidatedthat is actually misnamed.
Got it.
Quoted 17 lines
Now I'm not really tied to
bdev_disk_changed().bdev_revalidate_disk()seems a bit confusing to me though because the disk has actually been already revalidated incheck_disk_change()and the function won't revalidate the disk for devices with partition scan disabled.>Quoted 12 lines
Also, it seems to me that this function could be used without the complex "if ()" condition by slightly modifying it:
static void bdev_revalidate_disk(struct
block_device*bdev,
bool invalidate){ if (bdev->bd_invalidated && invalidate) invalidate_partitions(bdev->bd_disk, bdev); else rescan_partitions(bdev->bd_disk, bdev); }
Quoted 8 lines
Quoted 1 line
Otherwise, this all looks fine to me.
Well, but you don't want to call
rescan_partitions()ifbd_invalidatedis not set. But yes, we could movebd_invalidatedcheck intobdev_disk_changed(), but then it would seem less clear why this function is getting called. This ties somewhat to the discussion above. Hum, I guess if we call the function justbdev_revalidate(), the name won't be confusing and it would then make sense to move thebd_invalidatedcondition in there.
Indeed, we don't want another partition scan. Missed that one. For the function name, since the goal is to revalidate only the bdev capacity, what about bdev_revalidate_capacity() then ? But looking at the code and seeing the partitions functions calls does not clarify things though. Oh well, keep the name you proposed and we can cleanup everything with a refactor :)
Cheers.
Signature · 2 lines
Damien Le Moal Western Digital Research
Jan Kara
reviewerPATCH 2/2 bdev: Refresh bdev size for disks without partitioning
In reply to Jan KaraCurrently, block device size in not updated on second and further open for block devices where partition scan is disabled. This is particularly annoying for example for DVD drives as that means block device size does not get updated once the media is inserted into a drive if the device is already open when inserting the media. This is actually always the case for example when pktcdvd is in use.
Fix the problem by revalidating block device size on every open even for devices with partition scan disabled.
--- fs/block_dev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
fs/block_dev.c +10 -9
@@ -1403,11 +1403,7 @@ static void flush_disk(struct block_device *bdev, bool kill_dirty)"resized disk %s\n" , bdev->bd_disk ? bdev->bd_disk->disk_name : ""); } - -if (!bdev->bd_disk) -return ; -if (disk_part_scan_enabled (bdev->bd_disk)) - bdev->bd_invalidated =1 ; + bdev->bd_invalidated =1 ; }/**
@@ -1514,10 +1510,15 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);static void bdev_disk_changed (struct block_device *bdev,bool invalidate) { -if (invalidate) -invalidate_partitions (bdev->bd_disk, bdev); -else -rescan_partitions (bdev->bd_disk, bdev); +if (disk_part_scan_enabled (bdev->bd_disk)) { +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev); + }else { +check_disk_size_change (bdev->bd_disk, bdev, !invalidate); + bdev->bd_invalidated =0 ; + } }/*
Signature · 1 line
2.16.4
Quoted 35 lines · Jan Kara
Currently, block device size in not updated on second and further open for block devices where partition scan is disabled. This is particularly annoying for example for DVD drives as that means block device size does not get updated once the media is inserted into a drive if the device is already open when inserting the media. This is actually always the case for example when pktcdvd is in use.
Fix the problem by revalidating block device size on every open even for devices with partition scan disabled.
Signed-off-by Jan Kara <[email protected]>--- fs/block_dev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)fs/block_dev.c +1
-5@@ -1403,11 +1403,7 @@ static void flush_disk(struct block_device *bdev, bool kill_dirty)"resized disk %s\n" , bdev->bd_disk ? bdev->bd_disk->disk_name : ""); } - -if (!bdev->bd_disk) -return ; -if (disk_part_scan_enabled (bdev->bd_disk)) - bdev->bd_invalidated =1 ; + bdev->bd_invalidated =1 ; }/** @@ -1514,10 +1510,15 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);static void bdev_disk_changed (struct block_device *bdev,bool invalidate)
fs/block_dev.c static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); · line 1517
Quoted 10 lines
fs/block_dev.c +5
-4{ -if (invalidate) -invalidate_partitions (bdev->bd_disk, bdev); -else -rescan_partitions (bdev->bd_disk, bdev); +if (disk_part_scan_enabled (bdev->bd_disk)) { +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev);
Maybe use the new common helper to replace above.
Thanks,
Guoqing
Quoted 7 lines
fs/block_dev.c +4
-0+ }else { +check_disk_size_change (bdev->bd_disk, bdev, !invalidate); + bdev->bd_invalidated =0 ; + } }/*
Jan Kara
reviewerQuoted 40 lines · Guoqing Jiang
Quoted 37 lines · Jan Kara
Currently, block device size in not updated on second and further open for block devices where partition scan is disabled. This is particularly annoying for example for DVD drives as that means block device size does not get updated once the media is inserted into a drive if the device is already open when inserting the media. This is actually always the case for example when pktcdvd is in use.
Fix the problem by revalidating block device size on every open even for devices with partition scan disabled.
Signed-off-by Jan Kara <[email protected]>--- fs/block_dev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)fs/block_dev.c +1
-8@@ -1403,11 +1403,7 @@ static void flush_disk(struct block_device *bdev, bool kill_dirty)"resized disk %s\n" , bdev->bd_disk ? bdev->bd_disk->disk_name : ""); } - -if (!bdev->bd_disk) -return ; -if (disk_part_scan_enabled (bdev->bd_disk)) - bdev->bd_invalidated =1 ; + bdev->bd_invalidated =1 ; }/** @@ -1514,10 +1510,15 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);static void bdev_disk_changed (struct block_device *bdev,bool invalidate) { -if (invalidate) -invalidate_partitions (bdev->bd_disk, bdev); -else
Quoted 8 lines
fs/block_dev.c static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); · line 1517
Quoted 6 lines
fs/block_dev.c +5
-1-rescan_partitions (bdev->bd_disk, bdev); +if (disk_part_scan_enabled (bdev->bd_disk)) { +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev);Maybe use the new common helper to replace above.
What do you mean exactly? Because there's only this place that has the code pattern here...
Honza
Quoted 7 lines
Quoted 6 lines
fs/block_dev.c +4
-0+ }else { +check_disk_size_change (bdev->bd_disk, bdev, !invalidate); + bdev->bd_invalidated =0 ; + } }/*
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 47 lines · Jan Kara
Quoted 38 lines · Guoqing Jiang
Quoted 36 lines · Jan Kara
Currently, block device size in not updated on second and further open for block devices where partition scan is disabled. This is particularly annoying for example for DVD drives as that means block device size does not get updated once the media is inserted into a drive if the device is already open when inserting the media. This is actually always the case for example when pktcdvd is in use.
Fix the problem by revalidating block device size on every open even for devices with partition scan disabled.
Signed-off-by Jan Kara <[email protected]>--- fs/block_dev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)fs/block_dev.c +1
-7@@ -1403,11 +1403,7 @@ static void flush_disk(struct block_device *bdev, bool kill_dirty)"resized disk %s\n" , bdev->bd_disk ? bdev->bd_disk->disk_name : ""); } - -if (!bdev->bd_disk) -return ; -if (disk_part_scan_enabled (bdev->bd_disk)) - bdev->bd_invalidated =1 ; + bdev->bd_invalidated =1 ; }/** @@ -1514,10 +1510,15 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);static void bdev_disk_changed (struct block_device *bdev,bool invalidate) { -if (invalidate) -invalidate_partitions (bdev->bd_disk, bdev);Quoted 8 lines
fs/block_dev.c static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); · line 1517
Quoted 7 lines
fs/block_dev.c +5
-2-else -rescan_partitions (bdev->bd_disk, bdev); +if (disk_part_scan_enabled (bdev->bd_disk)) { +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev);Maybe use the new common helper to replace above.
Quoted 2 lines
What do you mean exactly? Because there's only this place that has the code pattern here...
The above looks same as the new function.
+static void bdev_disk_changed(struct block_device *bdev, bool invalidate) +{
+ if (invalidate)
+ invalidate_partitions(bdev->bd_disk, bdev);
+ else
+ rescan_partitions(bdev->bd_disk, bdev);
+}
So maybe just call it in the 'if' branch, am I misunderstand something?
static void bdev_disk_changed(struct block_device *bdev, bool invalidate)
{
if (disk_part_scan_enabled(bdev->bd_disk))
bdev_disk_changed(bdev, invalidate)
else {
check_disk_size_change(bdev->bd_disk, bdev, !invalidate);
bdev->bd_invalidated = 0;
}
}Thanks,
Guoqing
Quoted 12 lines · Guoqing Jiang
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
static void
bdev_disk_changed(struct block_device *bdev, bool invalidate)
{
- if (invalidate)
-invalidate_partitions(bdev->bd_disk, bdev);
- else
-rescan_partitions(bdev->bd_disk, bdev);
+ if (disk_part_scan_enabled(bdev->bd_disk)) {
+ if (invalidate)
+invalidate_partitions(bdev->bd_disk, bdev); + else
+rescan_partitions(bdev->bd_disk, bdev);
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Maybe use the new common helper to replace above.
What do you mean exactly? Because there's only this place that has the code
pattern here...The above looks same as the new function.
The above is changed in the new bdev_disk_changed() function. Patch 1/2 factors out the pattern and this patch changes the behaviour
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Quoted 13 lines · Johannes Thumshirn
Quoted 12 lines · Guoqing Jiang
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
static void bdev_disk_changed(struct
block_device*bdev, bool
invalidate)
{
- if (invalidate)
-invalidate_partitions(bdev->bd_disk, bdev);
- else
-rescan_partitions(bdev->bd_disk, bdev);
+ if (disk_part_scan_enabled(bdev->bd_disk)) {
+ if (invalidate)
+invalidate_partitions(bdev->bd_disk, bdev); + else
+rescan_partitions(bdev->bd_disk, bdev);
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Maybe use the new common helper to replace above.
What do you mean exactly? Because there's only this place that has the code
pattern here...The above looks same as the new function.
The above is changed in the new
bdev_disk_changed()function. Patch 1/2 factors out the pattern and this patch changes the behaviour
Oops, yes, sorry for the noise.
Thanks,
Guoqing
Jan Kara
reviewerQuoted 63 lines · Guoqing Jiang
Quoted 47 lines · Jan Kara
Quoted 38 lines · Guoqing Jiang
Quoted 36 lines · Jan Kara
Currently, block device size in not updated on second and further open for block devices where partition scan is disabled. This is particularly annoying for example for DVD drives as that means block device size does not get updated once the media is inserted into a drive if the device is already open when inserting the media. This is actually always the case for example when pktcdvd is in use.
Fix the problem by revalidating block device size on every open even for devices with partition scan disabled.
Signed-off-by Jan Kara <[email protected]>--- fs/block_dev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)fs/block_dev.c +1
-7@@ -1403,11 +1403,7 @@ static void flush_disk(struct block_device *bdev, bool kill_dirty)"resized disk %s\n" , bdev->bd_disk ? bdev->bd_disk->disk_name : ""); } - -if (!bdev->bd_disk) -return ; -if (disk_part_scan_enabled (bdev->bd_disk)) - bdev->bd_invalidated =1 ; + bdev->bd_invalidated =1 ; }/** @@ -1514,10 +1510,15 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);static void bdev_disk_changed (struct block_device *bdev,bool invalidate) { -if (invalidate) -invalidate_partitions (bdev->bd_disk, bdev);Quoted 8 lines
fs/block_dev.c static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); · line 1517
Quoted 7 lines
fs/block_dev.c +5
-2-else -rescan_partitions (bdev->bd_disk, bdev); +if (disk_part_scan_enabled (bdev->bd_disk)) { +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev);Maybe use the new common helper to replace above.
Quoted 2 lines
What do you mean exactly? Because there's only this place that has the code pattern here...
The above looks same as the new function.
fs/block_dev.c +7
-0+static void bdev_disk_changed (struct block_device *bdev,bool invalidate) +{ +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev); +}
Quoted 1 line
So maybe just call it in the 'if' branch, am I misunderstand something?
I think you misparsed the diff ;) The code that you mention as duplicated just gets reindented by the patch.
Quoted 9 lines
static void
bdev_disk_changed(struct block_device *bdev, bool invalidate){ if (disk_part_scan_enabled(bdev->bd_disk)) bdev_disk_changed(bdev, invalidate) else { check_disk_size_change(bdev->bd_disk, bdev, !invalidate); bdev->bd_invalidated = 0; } }
This has infinite recursion in it - you call bdev_disk_changed() from bdev_disk_changed().
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 74 lines · Jan Kara
Quoted 60 lines · Guoqing Jiang
Quoted 46 lines · Jan Kara
Quoted 37 lines · Guoqing Jiang
Quoted 36 lines · Jan Kara
Currently, block device size in not updated on second and further open for block devices where partition scan is disabled. This is particularly annoying for example for DVD drives as that means block device size does not get updated once the media is inserted into a drive if the device is already open when inserting the media. This is actually always the case for example when pktcdvd is in use.
Fix the problem by revalidating block device size on every open even for devices with partition scan disabled.
Signed-off-by Jan Kara <[email protected]>--- fs/block_dev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)fs/block_dev.c +1
-7@@ -1403,11 +1403,7 @@ static void flush_disk(struct block_device *bdev, bool kill_dirty)"resized disk %s\n" , bdev->bd_disk ? bdev->bd_disk->disk_name : ""); } - -if (!bdev->bd_disk) -return ; -if (disk_part_scan_enabled (bdev->bd_disk)) - bdev->bd_invalidated =1 ; + bdev->bd_invalidated =1 ; }/** @@ -1514,10 +1510,15 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);static void bdev_disk_changed (struct block_device *bdev,bool invalidate) { -if (invalidate) -invalidate_partitions (bdev->bd_disk, bdev);Quoted 8 lines
fs/block_dev.c static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); · line 1517
Quoted 7 lines
fs/block_dev.c +5
-2-else -rescan_partitions (bdev->bd_disk, bdev); +if (disk_part_scan_enabled (bdev->bd_disk)) { +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev);Maybe use the new common helper to replace above.
Quoted 2 lines
What do you mean exactly? Because there's only this place that has the code pattern here...
The above looks same as the new function.
fs/block_dev.c +7
-0+static void bdev_disk_changed (struct block_device *bdev,bool invalidate) +{ +if (invalidate) +invalidate_partitions (bdev->bd_disk, bdev); +else +rescan_partitions (bdev->bd_disk, bdev); +}Quoted 1 line
So maybe just call it in the 'if' branch, am I misunderstand something?
I think you misparsed the diff ;) The code that you mention as duplicated just gets reindented by the patch.
Quoted 9 lines
static void
bdev_disk_changed(struct block_device *bdev, bool invalidate){ if (disk_part_scan_enabled(bdev->bd_disk)) bdev_disk_changed(bdev, invalidate) else { check_disk_size_change(bdev->bd_disk, bdev, !invalidate); bdev->bd_invalidated = 0; } }
Quoted 2 lines
This has infinite recursion in it - you call
bdev_disk_changed()frombdev_disk_changed().
Right :-[, I need some coffee to refresh, sorry for the noise.
BRs,
Guoqing
Jens Axboe
maintainerQuoted 9 lines · Jan Kara
Hello,
I've been debugging for quite a long time strange issues with encrypted DVDs not being readable on Linux (bko#194965). In the end I've tracked down the problem to the fact that block device size is not updated when the media is inserted in case the DVD device is already open. This is IMO a bug in block device code as the size gets properly update in case the device has partition scanning enabled. The following series fixes the problem by refreshing disk size on each open even for devices with partition scanning disabled.
It's really confusing to have different behavior for partition vs whole device. This series looks good to me, the size change code is really hard to follow.
I don't see any serious objections here, I'm going to queue this up for 5.4.
Signature · 1 line
Jens Axboe
Jan Kara
reviewerQuoted 11 lines · Jens Axboe
Quoted 9 lines · Jan Kara
Hello,
I've been debugging for quite a long time strange issues with encrypted DVDs not being readable on Linux (bko#194965). In the end I've tracked down the problem to the fact that block device size is not updated when the media is inserted in case the DVD device is already open. This is IMO a bug in block device code as the size gets properly update in case the device has partition scanning enabled. The following series fixes the problem by refreshing disk size on each open even for devices with partition scanning disabled.
Quoted 5 lines
It's really confusing to have different behavior for partition vs whole device. This series looks good to me, the size change code is really hard to follow.
I don't see any serious objections here, I'm going to queue this up for 5.4.
Thanks Jens! I'll look into refactoring the size change / revalidation code so that it's easier to understand what's going on...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 2 lines · Jan Kara
Thanks Jens! I'll look into refactoring the size change / revalidation code so that it's easier to understand what's going on...
I actualy have a series for this. I've started rebasing it on top of you work and will need to do some testing. My current WIP is here:
http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/partition-cleanup
Jan Kara
reviewerQuoted 8 lines · Christoph Hellwig
Quoted 2 lines · Jan Kara
Thanks Jens! I'll look into refactoring the size change / revalidation code so that it's easier to understand what's going on...
I actualy have a series for this. I've started rebasing it on top of you work and will need to do some testing. My current WIP is here:
http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/partition-cleanup
Cool. Thanks for that! Skimming over the series it looks good to me. The only remaining thing I wanted to look into is bdev->bd_invalidated handling. Because the only thing it actually indicates in practice is that DISK_EVENT_MEDIA_CHANGE was set in check_disk_change(). All the other call chains end up clearing bdev->bd_invalidated before it has any effect. And that just looks very cryptic to me... So my plan was to at least move the setting of bdev->bd_invalidated to check_disk_change() and rename it to something saner if I cannot come up with anything better for propagating the information from check_disk_change() to __blkdev_get().
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR