Skip to contentSkip to conversation

Problem with usb-storage and /dev/sd?

DISCUSSION Bodo Eggert 5 participants 8 messages Aug 12, 2005 – Aug 14, 2005 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 7 lines · Horst von Brand
Quoted 6 lines · DervishD

* Pete Zaitcev <[email protected]> dixit:

Quoted 5 lines · DervishD
Quoted 4 lines

I'm not using hotplug currently so... how can I make the USB
subsystem to assign always the same /dev/sd? entry to my USB Mass storage devices? [...]

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

You cannot. Just mount by label or something...

Mounting by label won't work, the problem is the /dev entry,
which changes every time.

That's why you should mount by label...

Which label will a random USB stick have?

Signature · 2 lines
Ich danke GMX dafür, die Verwendung meiner Adressen mittels per SPF
verbreiteten Lügen zu sabotieren.
#3 lore raw
Quoted 1 line · Bodo Eggert

Which label will a random USB stick have?

GUID, I presume. Ask Andries Brouwer, he hacked on that, IIRC. Actually msdos has on-disk format for user-settable labels in the way analoguous to tune2fs -L label. I just do not know if our implementation recognizes them.

-- Pete

#4 lore raw

Hi Pete :)

* Pete Zaitcev <[email protected]> dixit:

Quoted 5 lines
Quoted 1 line

Which label will a random USB stick have?

GUID, I presume. Ask Andries Brouwer, he hacked on that, IIRC. Actually msdos has on-disk format for user-settable labels in the way analoguous to tune2fs -L label. I just do not know if our implementation recognizes them.

My vfat's in my MP3 player and the USB stick doesn't have a
label, at least not one usable by 'mount' (which only uses ext2/3 labels and xfs labels AFAIK).

Raúl Núñez de Arenas Coronado

Signature · 3 lines
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...
#5 lore raw
In reply to Pete Zaitcev
Quoted 5 lines · Pete Zaitcev
Quoted 1 line · Bodo Eggert

Which label will a random USB stick have?

GUID, I presume.

A global unique ID won't work out to make all USB mass storage devices appear under a common mountpoint, especially if it is recreated while "formating" it.

Signature · 1 line
The enemy diversion you have been ignoring will be the main attack. 
#6 lore raw
Quoted 10 lines · Bodo Eggert
Quoted 5 lines · Pete Zaitcev
Quoted 1 line · Bodo Eggert

Which label will a random USB stick have?

GUID, I presume.

A global unique ID won't work out to make all USB mass storage devices appear under a common mountpoint, especially if it is recreated while "formating" it.

That is correct, but not what Dervish wanted. He wanted to mount them on separate pre-assigned mount points. If you want all of them to mount on the same place, just use /dev/sda1!

-- Pete

#7 lore raw

Hi Pete :)

* Pete Zaitcev <[email protected]> dixit:

Quoted 6 lines
Quoted 3 lines

A global unique ID won't work out to make all USB mass storage devices appear under a common mountpoint, especially if it is recreated while "formating" it.

That is correct, but not what Dervish wanted. He wanted to mount them on separate pre-assigned mount points. If you want all of them to mount on the same place, just use /dev/sda1!

That's not possible. sd_mod will assign different devices for
different USB gadgets, and that's my problem in the first case!. If I plug my USB-whatever, it gets assigned /dev/sda1 (for the first partition, I mean). If I unplug it and, after that, I plug any other USB device, it gets assigned /dev/sdb1, etc. Don't know if the culprit is usb-storage or sd_mod :? The problem is that I cannot know about which device was assigned (at least in 2.4.x) so I can modify fstab or even mount it.

Raúl Núñez de Arenas Coronado

Signature · 3 lines
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...
#8 lore raw

Hi Raul,

Quoted 10 lines · DervishD

Hi Pete :)

* Pete Zaitcev <[email protected]> dixit:

Quoted 6 lines
Quoted 3 lines

A global unique ID won't work out to make all USB mass storage devices appear under a common mountpoint, especially if it is recreated while "formating" it.

That is correct, but not what Dervish wanted. He wanted to mount them on separate pre-assigned mount points. If you want all of them to mount on the same place, just use /dev/sda1!

Quoted 8 lines

That's not possible. sd_mod will assign different devices for
different USB gadgets, and that's my problem in the first case!. If I plug my USB-whatever, it gets assigned /dev/sda1 (for the first partition, I mean). If I unplug it and, after that, I plug any other USB device, it gets assigned /dev/sdb1, etc. Don't know if the culprit is usb-storage or sd_mod :? The problem is that I cannot know about which device was assigned (at least in 2.4.x) so I can modify fstab or even mount it.

I've been suffering from the same problem for a long time until I found a patch from Erik Andersen which automatically unregisters the sd device once you unplug the USB device. It has changed my life :-)

Here it is for 2.4. I even wonder why we would not put this into mainline, since having orphan devices brings nothing but confusion.

Regards,
Willy

----

This patch has been in use locally for quite some time now and makes working with USB and 1394 mass-storage devices in 2.4.x a much less painful experience. When devices are plugged in, they are automagically connected up to the scsi subsystem without the need to rescan all scsi busses or echo things into /proc/scsi/scsi. When devices are unplugged, they are automagically removed from the scsi subsystem, instead of hanging around registered but with no media actually present.

-Erik

--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--

drivers/usb/storage/usb.c +11 -0
@@ -744,6 +744,11 @@
 		/* unlock the device pointers */
 		up(&(ss->dev_semaphore));
 
+		/* Try to re-connect ourselves to the SCSI subsystem */
+		if (scsi_add_single_device(ss->host, 0, 0, 0))
+		    printk(KERN_WARNING "Unable to connect USB device to the SCSI subsystem\n");
+		else
+		    printk(KERN_WARNING "USB device connected to the SCSI subsystem\n");
 	} else { 
 		/* New device -- allocate memory and initialize */
 		US_DEBUGP("New GUID " GUID_FORMAT "\n", GUID_ARGS(guid));
@@ -1057,6 +1062,12 @@
 	/* lock access to the device data structure */
 	down(&(ss->dev_semaphore));
 
+	/* Try to un-hook ourselves from the SCSI subsystem */
+	if (scsi_remove_single_device(ss->host, 0, 0, 0))
+	    printk(KERN_WARNING "Unable to disconnect USB device from the SCSI subsystem\n");
+	else
+	    printk(KERN_WARNING "USB device disconnected from the SCSI subsystem\n");
+
 	/* release the IRQ, if we have one */
 	if (ss->irq_urb) {
 		US_DEBUGP("-- releasing irq URB\n");
drivers/ieee1394/sbp2.c +1 -1
@@ -231,7 +231,7 @@
  * enable this define to make use of it. This provides better hotplug
  * support. The mentioned patch is not part of the kernel proper though,
  * because it is considered somewhat of a hack. */
-//#define SBP2_USE_SCSI_ADDREM_HACK
+#define SBP2_USE_SCSI_ADDREM_HACK
 
 
 /*
drivers/scsi/scsi_syms.c +6 -0
@@ -104,3 +104,9 @@
 extern int scsi_delete_timer(Scsi_Cmnd *);
 EXPORT_SYMBOL(scsi_add_timer);
 EXPORT_SYMBOL(scsi_delete_timer);
+
+/* Support for hot plugging and unplugging devices -- safe for
+ * ieee1394 or USB devices, but probably not for normal SCSI... */
+EXPORT_SYMBOL(scsi_add_single_device);
+EXPORT_SYMBOL(scsi_remove_single_device);
+
drivers/scsi/hosts.h +7 -0
@@ -535,6 +535,13 @@
 int scsi_register_device(struct Scsi_Device_Template * sdpnt);
 void scsi_deregister_device(struct Scsi_Device_Template * tpnt);
 
+/* Support for hot plugging and unplugging devices -- safe for
+ * ieee1394 or USB devices, but probably not for normal SCSI... */
+extern int scsi_add_single_device(struct Scsi_Host *shpnt,
+	int channel, int id, int lun);
+extern int scsi_remove_single_device(struct Scsi_Host *shpnt,
+	int channel, int id, int lun);
+
 /* These are used by loadable modules */
 extern int scsi_register_module(int, void *);
 extern int scsi_unregister_module(int, void *);
drivers/scsi/scsi.c +159 -85

284 lines not on this page · raw message

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Quoted 12 lines

Raúl Núñez de Arenas Coronado

Signature · 8 lines
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#9 lore raw

Hi Willy :)

* Willy Tarreau <[email protected]> dixit:

Quoted 11 lines
Quoted 8 lines

That's not possible. sd_mod will assign different devices for
different USB gadgets, and that's my problem in the first case!. If I plug my USB-whatever, it gets assigned /dev/sda1 (for the first partition, I mean). If I unplug it and, after that, I plug any other USB device, it gets assigned /dev/sdb1, etc. Don't know if the culprit is usb-storage or sd_mod :? The problem is that I cannot know about which device was assigned (at least in 2.4.x) so I can modify fstab or even mount it.

I've been suffering from the same problem for a long time until I found a patch from Erik Andersen which automatically unregisters the sd device once you unplug the USB device. It has changed my life :-)

Thanks! Unfortunately, it solves only half of my problem. If I
plug *two* USB storage devices, the second will fail (well, it won't be assigned the correct device). The perfect solution is to always use the same dev entry for the same USB device, but I need sysfs for that (AFAIK), just like udev does.

Quoted 2 lines

Here it is for 2.4. I even wonder why we would not put this into mainline, since having orphan devices brings nothing but confusion.

Don't know :????

Raúl Núñez de Arenas Coronado

Signature · 3 lines
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...