08-05-2015, 07:03 AM | #1 |
Linux User
Posts: 2,279
Karma: 6123806
Join Date: Sep 2010
Location: Heidelberg, Germany
Device: none
|
Usb Debug
When the reader is connected to the computer, this hack will
- display a happy face if the Kobo umounted the filesystems properly. - display a sad face if it's still mounted even though it should not be. If you see a sad face, you might have filesystem corruption and/or still running processes doing the wrong thing. While the USB is connected it will keep checking state for about 5 minutes, so if some process is slow to free resources you will see a sad face first and it turns into a happy face. (But if the filesystem was mounted/used while it was still a sad face, there might still be corruption). A possible cause for the sad face will be stored in /tmp/UsbDebug.log After making this I found a bug in one of my own mods This is mainly to debug other mods that may behave incorrectly during a USB connection. I should also point out that this is by no means a complete check. It only considers obvious mounts; processes with open files or PWD; and libraries linked in by running programs. It does not cover loop devices, bind mounts, and more obscure ways to keep the filesystem busy. Update: Added a umount hook so it detects whether non-lazy umount would have worked or not. The debug info is now copied to .addons/usbdebug/ Hack can be uninstalled by creating .addons/usbdebug/uninstall Update: now also resolves offending fd names Update 20160918: fix for GloHD/KA1 Last edited by frostschutz; 09-19-2016 at 03:59 AM. |
08-05-2015, 01:34 PM | #2 |
BLAM!
Posts: 13,494
Karma: 26047188
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
I can't remember: doesn't Kobo ship an lsof binary? That would be my tool of choice for this kind of checks .
|
Advert | |
|
08-05-2015, 02:03 PM | #3 |
Linux User
Posts: 2,279
Karma: 6123806
Join Date: Sep 2010
Location: Heidelberg, Germany
Device: none
|
If you want to use lsof you'd have to use it before the lazy umount. It doesn't work afterwards since all processes using a lazily umounted filesystem are locked into virtual paths that don't exist.
I guess I could hook into umount in addition to what it's currently doing, so it can do some things before it just umount -l |
08-05-2015, 09:42 PM | #4 |
BLAM!
Posts: 13,494
Karma: 26047188
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
@frostschutz: Hmm, good point .
|
08-06-2015, 02:46 AM | #5 |
Linux User
Posts: 2,279
Karma: 6123806
Join Date: Sep 2010
Location: Heidelberg, Germany
Device: none
|
I'll improve it, with a umount hook that tries regular umount before lazy umount. If regular umount fails we know it is busy somehow, so that's something to fall back to even if my other checks can not find all reasons as to why it is busy.
Unfortunately the kernel does not make it easy to track filesystems that it is still using in read-write mode but not bound to any real VFS path. lazy umount is really really bad idea |
Advert | |
|
08-06-2015, 05:40 PM | #6 |
Linux User
Posts: 2,279
Karma: 6123806
Join Date: Sep 2010
Location: Heidelberg, Germany
Device: none
|
Updated it; it now puts the info in /mnt/onboard/.usbdebug/
and also can be uninstalled if you create /mnt/onboard/.usbdebug/uninstall sample output Code:
umount failure /mnt/onboard Thu Aug 6 23:41:31 CEST 2015 /proc/869/cwd 4096 8 41ed 0 0 b303 346 3 0 0 1438732800 1438794482 1438794482 4096 init(1)-+-adobehost-launc(832)---adobehost(833)---{QProcessManage}(844) |-autoshelf.sh(2455)-+-cat(2459) | `-dd(2460) |-dbus-daemon(524) |-dbus-daemon(523) |-fickel-launcher(917)---fickel(918) |-getty(529) |-hindenburg(525) |-inetd(531) |-nickel(526)-+-sh(2431)---usb(2432)---sleep(2453) | |-{FifoHardwareSt}(815) | |-{QEvdevTouchScr}(828) | |-{QProcessManage}(813) | |-{QThread}(824) | |-{QThread}(825) | |-{QThread}(829) | |-{QThread}(830) | |-{Qt HTTP thread}(925) | |-{Qt bearer thre}(826) | |-{nickel}(928) | `-{nickel}(930) |-screensaver.sh(702)-+-grep(858) | |-logread(857) | `-screensaver.sh(860) |-sickel(879) |-swapper(208) |-syslogd(821) |-udevd(495) |-usbdebug.sh(2457)---pstree(2768) `-webportal.sh(717)---httpd(869) Last edited by frostschutz; 08-06-2015 at 05:48 PM. |
08-06-2015, 07:38 PM | #7 |
Pain in the arse
Posts: 758
Karma: 77856
Join Date: Apr 2013
Device: Kobo Aura One, Kindle 4
|
It's more an educational tool, I guess
|
08-07-2015, 04:40 AM | #8 |
Linux User
Posts: 2,279
Karma: 6123806
Join Date: Sep 2010
Location: Heidelberg, Germany
Device: none
|
It's hard to debug such issues since everything seems like it should work — but then you get occasional data corruption or your mod stops working correctly after USB connection because suddenly its file handles are in data limbo…
Educational, certainly, for me anyway. I was not aware of the pitfalls of lazy umounting before. I've been using Linux for a long time but you still learn new things. |
08-12-2015, 12:54 PM | #9 |
Linux User
Posts: 2,279
Karma: 6123806
Join Date: Sep 2010
Location: Heidelberg, Germany
Device: none
|
When connecting USB while reading KEPUB, nickel still has open file handles to the .kepub file at the time it umounts. It frees them a few seconds later... so this is a "sad face turns into happy face" case.
Code:
umount failure /mnt/onboard Wed Aug 12 16:45:10 UTC 2015 /proc/1315/fd/32 2831262 5536 81ed 0 0 b303 73 1 0 0 1439337600 1439394562 1439394563 4096 /proc/1316/fd/32 2831262 5536 81ed 0 0 b303 73 1 0 0 1439337600 1439394562 1439394563 4096 /proc/1337/fd/32 2831262 5536 81ed 0 0 b303 73 1 0 0 1439337600 1439394562 1439394563 4096 /proc/516/fd/32 2831262 5536 81ed 0 0 b303 73 1 0 0 1439337600 1439394562 1439394563 4096 lr-x------ 1 root root 64 Aug 12 16:45 /proc/1315/fd/32 -> /.kobo/kepub/816d01e8-6501-43ec-9985-3dd7bdc7c55b lr-x------ 1 root root 64 Aug 12 16:45 /proc/1316/fd/32 -> /.kobo/kepub/816d01e8-6501-43ec-9985-3dd7bdc7c55b lr-x------ 1 root root 64 Aug 12 16:45 /proc/1337/fd/32 -> /.kobo/kepub/816d01e8-6501-43ec-9985-3dd7bdc7c55b lr-x------ 1 root root 64 Aug 12 16:45 /proc/516/fd/32 -> /.kobo/kepub/816d01e8-6501-43ec-9985-3dd7bdc7c55b init(1)-+-dbus-daemon(514) |-dbus-daemon(513) |-fickel-launcher(866)---fickel(867) |-getty(519) |-hindenburg(515) |-nickel(516)-+-sh(1315)---usb(1316)---sleep(1337) | |-{FifoHardwareSt}(788) | |-{QEvdevTouchScr}(803) | |-{QProcessManage}(786) | |-{QThread}(799) | |-{QThread}(800) | |-{QThread}(804) | |-{Qt HTTP thread}(874) | |-{Qt bearer thre}(801) | |-{Thread (pooled}(1291) | |-{nickel}(1277) | `-{nickel}(1278) |-sickel-launcher(797)---sickel(798) |-swapper(208) |-syslogd(795) |-udevd(491) `-usbdebug.sh(1339)---pstree(1579) It's probably not a problem in practice, since nickel frees it in the end (and UsbDebug runs quite early, it caught nickel's usb script sleeping so it might be a second before it loaded the storage module. Last edited by frostschutz; 08-12-2015 at 01:01 PM. |
09-18-2016, 01:58 PM | #10 |
Linux User
Posts: 2,279
Karma: 6123806
Join Date: Sep 2010
Location: Heidelberg, Germany
Device: none
|
Updated it to also work with GloHD/KA1 (same udev rule as my other mods).
Also moved .usbdebug to .addons/usbdebug. I found a way to do a more reliable check (using inotify umount which is called only when it's really umounted, not for lazy umounting) but I'm too lazy to implement, there's probably no demand for it. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Ctrl-Shft-R Debug vs calibre-debug -g | JimmXinu | Development | 3 | 11-20-2014 09:57 AM |
Debug question | robin58 | Calibre | 2 | 09-20-2012 02:16 PM |
Results of debug | hlhalliburton | Calibre | 1 | 06-07-2011 12:36 AM |
Calibre debug file | meme | Calibre | 7 | 02-01-2011 04:45 PM |
Development Debug on Device | mrspaceman | enTourage Archive | 0 | 09-02-2010 05:50 AM |