Skip to contentSkip to conversation

bdev: reset first_open when looping in __blkget_dev

PATCH In review Michal Suchanek 2 participants 2 messages Dec 17, 2019 – Dec 18, 2019 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bdev: reset first_open when looping in __blkget_dev

It is not clear that no other thread cannot open the block device when __blkget_dev drops it and loop to restart label. Reset first_open to false when looping.

---
 fs/block_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/block_dev.c +2 -1
index 69bf2fb6f7cd..17e1231d5246 100644
@@ -1560,7 +1560,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 	int ret;
 	int partno;
 	int perm = 0;
-	bool first_open = false;
+	bool first_open;
 
 	if (mode & FMODE_READ)
 		perm |= MAY_READ;
@@ -1580,6 +1580,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
  restart:
 
 	ret = -ENXIO;
+	first_open = false;
 	disk = bdev_get_gendisk(bdev, &partno);
 	if (!disk)
 		goto out;
Signature · 1 line
2.23.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Michal Suchanek

It is not clear that no other thread cannot open the block device when __blkget_dev drops it and loop to restart label. Reset first_open to false when looping.

Yeah, good catch. Thanks for the patch. You can add:

Honza

Quoted 28 lines
---
 fs/block_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/block_dev.c +2 -1
index 69bf2fb6f7cd..17e1231d5246 100644
@@ -1560,7 +1560,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 	int ret;
 	int partno;
 	int perm = 0;
-	bool first_open = false;
+	bool first_open;
 
 	if (mode & FMODE_READ)
 		perm |= MAY_READ;
@@ -1580,6 +1580,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
  restart:
 
 	ret = -ENXIO;
+	first_open = false;
 	disk = bdev_get_gendisk(bdev, &partno);
 	if (!disk)
 		goto out;
Signature · 1 line
2.23.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR