Skip to contentSkip to conversation

block: change the hash used for looking up block devices

PATCH In review Christoph Hellwig 2 participants 3 messages Sep 27, 2020 – Sep 29, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: change the hash used for looking up block devices

Adding the minor to the major creates tons of pointless conflicts. Just use the dev_t itself, which is 32-bits and thus is guaranteed to fit into ino_t.

---
 fs/block_dev.c | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)
fs/block_dev.c +1 -24
index 6b9d19ffa5af7b..da7d4868057632 100644
@@ -870,35 +870,12 @@ void __init bdev_cache_init(void)
 	blockdev_superblock = bd_mnt->mnt_sb;   /* For writeback */
 }
 
-/*
- * Most likely _very_ bad one - but then it's hardly critical for small
- * /dev and can be fixed when somebody will need really large one.
- * Keep in mind that it will be fed through icache hash function too.
- */
-static inline unsigned long hash(dev_t dev)
-{
-	return MAJOR(dev)+MINOR(dev);
-}
-
-static int bdev_test(struct inode *inode, void *data)
-{
-	return BDEV_I(inode)->bdev.bd_dev == *(dev_t *)data;
-}
-
-static int bdev_set(struct inode *inode, void *data)
-{
-	BDEV_I(inode)->bdev.bd_dev = *(dev_t *)data;
-	return 0;
-}
-
 struct block_device *bdget(dev_t dev)
 {
 	struct block_device *bdev;
 	struct inode *inode;
 
-	inode = iget5_locked(blockdev_superblock, hash(dev),
-			bdev_test, bdev_set, &dev);
-
+	inode = iget_locked(blockdev_superblock, dev);
 	if (!inode)
 		return NULL;
 
Signature · 1 line
2.28.0
#1 lore raw
Quoted 39 lines · Christoph Hellwig

Adding the minor to the major creates tons of pointless conflicts. Just use the dev_t itself, which is 32-bits and thus is guaranteed to fit into ino_t.

---
 fs/block_dev.c | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)
fs/block_dev.c +0 -21
index 6b9d19ffa5af7b..da7d4868057632 100644
@@ -870,35 +870,12 @@ void __init bdev_cache_init(void)
 	blockdev_superblock = bd_mnt->mnt_sb;   /* For writeback */
 }
 
-/*
- * Most likely _very_ bad one - but then it's hardly critical for small
- * /dev and can be fixed when somebody will need really large one.
- * Keep in mind that it will be fed through icache hash function too.
- */
-static inline unsigned long hash(dev_t dev)
-{
-	return MAJOR(dev)+MINOR(dev);
-}
-
-static int bdev_test(struct inode *inode, void *data)
-{
-	return BDEV_I(inode)->bdev.bd_dev == *(dev_t *)data;
-}
-
-static int bdev_set(struct inode *inode, void *data)
-{
-	BDEV_I(inode)->bdev.bd_dev = *(dev_t *)data;
-	return 0;
-}
-
 struct block_device *bdget(dev_t dev)

fs/block_dev.c void __init bdev_cache_init(void) · line 880

Quoted 10 lines
fs/block_dev.c +1 -3
 {
 	struct block_device *bdev;
 	struct inode *inode;
 
-	inode = iget5_locked(blockdev_superblock, hash(dev),
-			bdev_test, bdev_set, &dev);
-
+	inode = iget_locked(blockdev_superblock, dev);
 	if (!inode)
 		return NULL;

Doesn't ->bd_dev still need to be set somewhere?

- Eric

#2 lore raw
Quoted 1 line · Eric Biggers

Doesn't ->bd_dev still need to be set somewhere?

Yes. This was fixed in the next patch in my series which isn't quite ready..