Alan Stern wrote:
> On Fri, 17 Dec 2004, Wakko Warner wrote:
> > I'd love to do this with my 2.4 boxen.  Any pointers on what to remove?
> 
> On Fri, 17 Dec 2004, Matthew Dharm wrote:
> 
> > Actually, the 2.4 SCSI core doesn't support hot-unplug very well.  So it's
> > more difficult than just changing usb-storage.
> 
> That may be.  But usb-storage seems to manage okay during rmmod, so maybe 
> it won't be so bad.
> 
> Wakko, what you need to change is all in the drivers/usb/storage/usb.c 
> source file.

I've done this and it appears to be working just fine for me.  Stupidly I
tested it on a machine I didn't want to crash, however, it worked.

I made the modifications as a configurable item.

Here's the patch.  I consider it experiemental since I don't have that much
knowledge of the usb-storage module.

diff -ru 2.4.26-orig/Documentation/Configure.help 
2.4.26-mod/Documentation/Configure.help
--- 2.4.26-orig/Documentation/Configure.help    Wed Apr 28 08:03:04 2004
+++ 2.4.26-mod/Documentation/Configure.help     Fri Jan 14 11:04:53 2005
@@ -15756,6 +15770,12 @@
 CONFIG_USB_STORAGE_DEBUG
   Say Y here in order to have the USB Mass Storage code generate
   verbose debugging messages.
+
+Do not remember unplugged devices
+CONFIG_USB_STORAGE_REMOVE_UNPLUGGED
+  Say Y here to remove USB mass storage devices when they are unplugged.
+
+  If unsure, say N.
 
 ISD-200 USB/ATA Bridge support
 CONFIG_USB_STORAGE_ISD200

diff -ru 2.4.26-orig/drivers/usb/Config.in 2.4.26-mod/drivers/usb/Config.in
--- 2.4.26-orig/drivers/usb/Config.in   Fri Apr  9 08:14:50 2004
+++ 2.4.26-mod/drivers/usb/Config.in    Fri Jan 14 11:01:47 2005
@@ -34,6 +34,7 @@
    fi
    dep_tristate '  USB Mass Storage support' CONFIG_USB_STORAGE $CONFIG_USB 
$CONFIG_SCSI
       dep_mbool '    USB Mass Storage verbose debug' CONFIG_USB_STORAGE_DEBUG 
$CONFIG_USB_STORAGE
+      dep_mbool '    Do not remember unplugged devices' 
CONFIG_USB_STORAGE_REMOVE_UNPLUGGED $CONFIG_USB_STORAGE
       dep_mbool '    Datafab MDCFE-B Compact Flash Reader support' 
CONFIG_USB_STORAGE_DATAFAB $CONFIG_USB_STORAGE $CONFIG_EXPERIMENTAL
       dep_mbool '    Freecom USB/ATAPI Bridge support' 
CONFIG_USB_STORAGE_FREECOM  $CONFIG_USB_STORAGE
       dep_mbool '    ISD-200 USB/ATA Bridge support' CONFIG_USB_STORAGE_ISD200 
$CONFIG_USB_STORAGE $CONFIG_IDE
diff -ru 2.4.26-orig/drivers/usb/storage/usb.c 
2.4.26-mod/drivers/usb/storage/usb.c
--- 2.4.26-orig/drivers/usb/storage/usb.c       Fri Apr  9 08:14:51 2004
+++ 2.4.26-mod/drivers/usb/storage/usb.c        Fri Jan 14 11:01:02 2005
@@ -700,6 +700,7 @@
         * We're looking for a device with a matching GUID that isn't
         * already on the system
         */
+#ifndef CONFIG_USB_STORAGE_REMOVE_UNPLUGGED
        ss = us_list;
        while ((ss != NULL) && 
               ((ss->pusb_dev) || !GUID_EQUAL(guid, ss->guid)))
@@ -749,6 +750,7 @@
                up(&(ss->dev_semaphore));
 
        } else { 
+#endif
                /* New device -- allocate memory and initialize */
                US_DEBUGP("New GUID " GUID_FORMAT "\n", GUID_ARGS(guid));
 
@@ -1034,7 +1036,9 @@
 
                /* release the data structure lock */
                up(&us_list_semaphore);
+#ifndef CONFIG_USB_STORAGE_REMOVE_UNPLUGGED
        }
+#endif
 
        printk(KERN_DEBUG 
               "WARNING: USB Mass Storage data integrity not assured\n");
@@ -1049,6 +1053,8 @@
 static void storage_disconnect(struct usb_device *dev, void *ptr)
 {
        struct us_data *ss = ptr;
+       struct us_data *next;
+       struct us_data *last;
        int result;
 
        US_DEBUGP("storage_disconnect() called\n");
@@ -1080,9 +1086,50 @@
        usb_free_urb(ss->current_urb);
        ss->current_urb = NULL;
 
+#ifndef CONFIG_USB_STORAGE_REMOVE_UNPLUGGED
        /* mark the device as gone */
        usb_dec_dev_use(ss->pusb_dev);
        ss->pusb_dev = NULL;
+#else
+       /* Deregister the scsi host for this device */
+       scsi_unregister_module(MODULE_SCSI_HA, &(ss->htmplt));
+
+       /* Search for this structure and remove it from the list
+        * since I don't understand the workings of this module, I feel
+        * it best to remove it here and free the memory used by it */
+       last = NULL;
+       next = us_list;
+       while ((next != NULL) && 
+              ((next->pusb_dev) || !GUID_EQUAL(ss->guid, next->guid))) {
+               last = next;
+               next = next->next;
+       }
+
+       /* If found, remove the link to it and free this one */
+       if (next != NULL) {
+               if (last == NULL)
+                       us_list = next->next;
+               else
+                       last->next = next->next;
+               
+               /* If there's extra data in the us_data structure then
+                * free that first */
+               if (next->extra) {
+                       /* call the destructor routine, if it exists */
+                       if (next->extra_destructor) {
+                               US_DEBUGP("-- calling extra_destructor()\n");
+                               next->extra_destructor(next->extra);
+                       }
+
+                       /* destroy the extra data */
+                       US_DEBUGP("-- freeing the data structure\n");
+                       kfree(next->extra);
+               }
+
+               /* free the structure itself */
+                kfree (next);
+       }
+#endif
 
        /* unlock access to the device data structure */
        up(&(ss->dev_semaphore));
@@ -1127,10 +1174,12 @@
         * the structures because of possible races with the /proc
         * interface
         */
+#ifndef CONFIG_USB_STORAGE_REMOVE_UNPLUGGED
        for (next = us_list; next; next = next->next) {
                US_DEBUGP("-- calling scsi_unregister_module()\n");
                scsi_unregister_module(MODULE_SCSI_HA, &(next->htmplt));
        }
+#endif
 
        /* While there are still structures, free them.  Note that we are
         * now race-free, since these structures can no longer be accessed


-- 
 Lab tests show that use of micro$oft causes cancer in lab animals


-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-users

Reply via email to