Skip to contentSkip to conversation

bdi: register sysfs bdi device only once per queue

PATCH Kay Sievers 4 participants 6 messages Nov 3, 2008 – Nov 7, 2008

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

Andrew, can you pick this up this please?

Thanks,
Kay

From: Kay Sievers <[email protected]>
Subject: bdi: register sysfs bdi device only once per queue

Devices which share the same queue, like floppies and mtd devices, get registered multiple times in the bdi interface, but bdi accounts only the last registered device of the devices sharing one queue.

On remove, all earlier registered devices leak, stay around in sysfs, and cause "duplicate filename" errors if the devices are re-created.

This prevents the creation of multiple bdi interfaces per queue, and the bdi device will carry the dev_t name of the block device which is the first one registered, of the pool of devices using the same queue.

---

mm/backing-dev.c +3 -0
index f2e574d..e6676e5 100644
@@ -176,6 +176,9 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent,
 	int ret = 0;
 	struct device *dev;
 
+	if (bdi->dev)
+		goto exit;
+
 	va_start(args, fmt);
 	dev = device_create_vargs(bdi_class, parent, MKDEV(0, 0), bdi, fmt, args);
 	va_end(args);
#1 lore raw
Quoted 6 lines · Kay Sievers

Andrew, can you pick this up this please?

Thanks,
Kay

Quoted 6 lines

From: Kay Sievers <[email protected]>
Subject: bdi: register sysfs bdi device only once per queue

Devices which share the same queue, like floppies and mtd devices, get registered multiple times in the bdi interface, but bdi accounts only the last registered device of the devices sharing one queue.

David, is there any reason the mtd devices do this?

Quoted 19 lines

On remove, all earlier registered devices leak, stay around in sysfs, and cause "duplicate filename" errors if the devices are re-created.

This prevents the creation of multiple bdi interfaces per queue, and the bdi device will carry the dev_t name of the block device which is the first one registered, of the pool of devices using the same queue.

---

mm/backing-dev.c +0 -0
index f2e574d..e6676e5 100644

mm/backing-dev.c int bdi_register(struct backing_dev_info *bdi, struct device *parent, · line 184

Quoted 9 lines
mm/backing-dev.c +3 -0
@@ -176,6 +176,9 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent,
 	int ret = 0;
 	struct device *dev;
 
+	if (bdi->dev)
+		goto exit;
+
 	va_start(args, fmt);
 	dev = device_create_vargs(bdi_class, parent, MKDEV(0, 0), bdi, fmt, args);
 	va_end(args);

Would it make sense to make it print something like, please fix me?

maintainer
#2 lore raw
Quoted 7 lines · On Mon, 03 Nov 2008 17:08:50 +0100 Peter Zijlstra <[email protected]> wrote:
Quoted 6 lines · Kay Sievers

Andrew, can you pick this up this please?

Thanks,
Kay

Quoted 8 lines
Quoted 6 lines

From: Kay Sievers <[email protected]>
Subject: bdi: register sysfs bdi device only once per queue

Devices which share the same queue, like floppies and mtd devices, get registered multiple times in the bdi interface, but bdi accounts only the last registered device of the devices sharing one queue.

David, is there any reason the mtd devices do this?

[tap tap - is this thing turned on?]

Quoted 22 lines
Quoted 22 lines

On remove, all earlier registered devices leak, stay around in sysfs, and cause "duplicate filename" errors if the devices are re-created.

This prevents the creation of multiple bdi interfaces per queue, and the bdi device will carry the dev_t name of the block device which is the first one registered, of the pool of devices using the same queue.

---

mm/backing-dev.c +0 -0
index f2e574d..e6676e5 100644
@@ -176,6 +176,9 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent,
 	int ret = 0;
 	struct device *dev;
 
Quoted 8 lines

mm/backing-dev.c int bdi_register(struct backing_dev_info *bdi, struct device *parent, · line 184

Quoted 6 lines
mm/backing-dev.c +3 -0
+	if (bdi->dev)
+		goto exit;
+
 	va_start(args, fmt);
 	dev = device_create_vargs(bdi_class, parent, MKDEV(0, 0), bdi, fmt, args);
 	va_end(args);

Would it make sense to make it print something like, please fix me?

Yes, I think it would.

mm/backing-dev.c renamed from mm/backing-dev.c~bdi-register-sysfs-bdi-device-only-once-per-queue-fix +1 -1
@@ -176,7 +176,7 @@ int bdi_register(struct backing_dev_info
 	int ret = 0;
 	struct device *dev;
 
-	if (bdi->dev)
+	if (WARN_ON(bdi->dev))
 		goto exit;
 
 	va_start(args, fmt);

_

It's a bit cheeky to add a known-to-trigger WARN_ON into -rc4 but if we don't do this then the issue will just get swept under the carpet.

#3 lore raw
Quoted 7 lines · Andrew Morton
Quoted 5 lines
Quoted 3 lines

Devices which share the same queue, like floppies and mtd devices, get registered multiple times in the bdi interface, but bdi accounts only the last registered device of the devices sharing one queue.

David, is there any reason the mtd devices do this?

[tap tap - is this thing turned on?]

No particular reason. It's been done that way since the dawn of time, when it was perfectly normal. Nobody's yet bothered to change that, when changing the rules.

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#4 lore raw
Quoted 5 lines · David Woodhouse
Quoted 4 lines · Andrew Morton
Quoted 4 lines
Quoted 3 lines

Devices which share the same queue, like floppies and mtd devices, get registered multiple times in the bdi interface, but bdi accounts only the last registered device of the devices sharing one queue.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

David, is there any reason the mtd devices do this?

[tap tap - is this thing turned on?]

No particular reason. It's been done that way since the dawn of time, when it was perfectly normal. Nobody's yet bothered to change that, when changing the rules.

I don't think it ever made sense, or was intended that way, but yeah it didn't really matter in any substantial way.

I can remember touching some mtd stuff back when I did the per-bdi-writeback stuff, but I can't seem to recall all the details.

Might be time to stare at the mtd code a bit...

#5 lore raw
In reply to David Woodhouse
Quoted 5 lines · David Woodhouse
Quoted 4 lines · Andrew Morton
Quoted 4 lines
Quoted 3 lines

Devices which share the same queue, like floppies and mtd devices, get registered multiple times in the bdi interface, but bdi accounts only the last registered device of the devices sharing one queue.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

David, is there any reason the mtd devices do this?

[tap tap - is this thing turned on?]

No particular reason. It's been done that way since the dawn of time, when it was perfectly normal. Nobody's yet bothered to change that, when changing the rules.

It looks to be the consequence of using one queue for a bunch of devices (which seems odd), and its all tied into this translation layer which starts a thread per queue.

Do you want me to rip this up and make it do one queue/thread per device? - seems invasive...