[rh7] nbd: fix how we set bd_invalidated

Submitted by Andrey Ryabinin on Oct. 31, 2019, 11:54 a.m.

Details

Message ID 20191031115405.20414-1-aryabinin@virtuozzo.com
State New
Series "nbd: fix how we set bd_invalidated"
Headers show

Commit Message

Andrey Ryabinin Oct. 31, 2019, 11:54 a.m.
From: Josef Bacik <jbacik@fb.com>

bd_invalidated is kind of a pain wrt partitions as it really only
triggers the partition rescan if it is set after bd_ops->open() runs, so
setting it when we reset the device isn't useful.  We also sporadically
would still have partitions left over in some disconnect cases, so fix
this by always setting bd_invalidated on open if there's no
configuration or if we've had a disconnect action happen, that way the
partition table gets invalidated and rescanned properly.

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

https://jira.sw.ru/browse/PSBM-98994
(cherry picked from commit fe1f9e6659ca6124f500a0f829202c7c902fab0c)
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 drivers/block/nbd.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 726b940b0fe6..f110cb1c82f1 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -820,10 +820,6 @@  static void nbd_bdev_reset(struct block_device *bdev)
 		return;
 	set_device_ro(bdev, false);
 	bdev->bd_inode->i_size = 0;
-	if (max_part > 0) {
-		blkdev_reread_part(bdev);
-		bdev->bd_invalidated = 1;
-	}
 }
 
 static void nbd_parse_flags(struct nbd_device *nbd, struct block_device *bdev)
@@ -1102,6 +1098,9 @@  static int nbd_open(struct block_device *bdev, fmode_t mode)
 		}
 		refcount_set(&nbd->config_refs, 1);
 		mutex_unlock(&nbd->config_lock);
+		bdev->bd_invalidated = 1;
+	} else if (nbd_disconnected(nbd->config)) {
+		bdev->bd_invalidated = 1;
 	}
 out:
 	mutex_unlock(&nbd_index_mutex);

Comments

Andrey Ryabinin Oct. 31, 2019, 11:54 a.m.
On 10/31/19 2:54 PM, Andrey Ryabinin wrote:
> From: Josef Bacik <jbacik@fb.com>
> 
> bd_invalidated is kind of a pain wrt partitions as it really only
> triggers the partition rescan if it is set after bd_ops->open() runs, so
> setting it when we reset the device isn't useful.  We also sporadically
> would still have partitions left over in some disconnect cases, so fix
> this by always setting bd_invalidated on open if there's no
> configuration or if we've had a disconnect action happen, that way the
> partition table gets invalidated and rescanned properly.
> 
> Signed-off-by: Josef Bacik <jbacik@fb.com>
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> 
> https://jira.sw.ru/browse/PSBM-98994

https://jira.sw.ru/browse/PSBM-98887

> (cherry picked from commit fe1f9e6659ca6124f500a0f829202c7c902fab0c)
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> ---
>  drivers/block/nbd.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index 726b940b0fe6..f110cb1c82f1 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -820,10 +820,6 @@ static void nbd_bdev_reset(struct block_device *bdev)
>  		return;
>  	set_device_ro(bdev, false);
>  	bdev->bd_inode->i_size = 0;
> -	if (max_part > 0) {
> -		blkdev_reread_part(bdev);
> -		bdev->bd_invalidated = 1;
> -	}
>  }
>  
>  static void nbd_parse_flags(struct nbd_device *nbd, struct block_device *bdev)
> @@ -1102,6 +1098,9 @@ static int nbd_open(struct block_device *bdev, fmode_t mode)
>  		}
>  		refcount_set(&nbd->config_refs, 1);
>  		mutex_unlock(&nbd->config_lock);
> +		bdev->bd_invalidated = 1;
> +	} else if (nbd_disconnected(nbd->config)) {
> +		bdev->bd_invalidated = 1;
>  	}
>  out:
>  	mutex_unlock(&nbd_index_mutex);
>