![]() |
#16 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,356
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Calling sync like that is a potentially *very* slow operation, especially if network filesystems are mounted. Why is your kernel taking two seconds to do writes? Fixing that seems like a much better way to go.
|
![]() |
![]() |
![]() |
#17 |
Member
![]() Posts: 16
Karma: 10
Join Date: Nov 2020
Device: amazon kindle
|
Please add utime() for other os.fsync (caused problem when books uploaded)
About slow sync..... Yes this may be a problem but: os.system("sync &") will do it in background w/o delays I'll try to find where is cache write delay is configured. But I'm sure there is default settings... |
![]() |
![]() |
Advert | |
|
![]() |
#18 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,356
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The other fsync's only code path is from put_file() in usbms/cli.py immeditely after doing it, the file is written to, so there is no need for an extra utime()
|
![]() |
![]() |
![]() |
#19 |
Member
![]() Posts: 16
Karma: 10
Join Date: Nov 2020
Device: amazon kindle
|
Found another way to fix the problem:
Mount vfat have "flush" option (but it's not enabled by default): flush If set, the filesystem will try to flush to disk more early than normal. Not set by default. When Kindle is mounted with this option, nothing is need to be changed in Calibre code. Cache update, books uploading is OK. But "sync /mnt/sdb1" still disconnect Kindle even with "flush" mount option. Anyway, on my Linux with default settings, there is 100% require both os.fsync() to be followed by utime and "sync" system command in Calibre. Kovid, please check your vfat mount options when Kindle is connected, for "flush" option (grep fat /proc/mounts). Maybe without this option you can easy repeat the problem. |
![]() |
![]() |
![]() |
#20 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,356
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Yes, there is flush, and that is a default mount setting chosen by Udisks2 for removable drives. How are you mounting your kindle?
|
![]() |
![]() |
Advert | |
|
![]() |
#21 |
Member
![]() Posts: 16
Karma: 10
Join Date: Nov 2020
Device: amazon kindle
|
My Kindle and other usb-flash devices is mounted by udev rule which is calling mount with default options (no flush).
Flush option making most of old usb-flash drives is extermly slow, so I prefer faster defaults. Kovid, if you can do something to fix Calibre with default mount, please please please do it. Both os.fsync() make "Linux-vs-Kindle-problems". I hope now you can repeat it on your system. ![]() |
![]() |
![]() |
![]() |
#22 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,528
Karma: 78910202
Join Date: Nov 2007
Location: Toronto
Device: Libra H2O, Libra Colour
|
Why not have a custom udev entry for your Kindle that has the optins you need just for that device?
|
![]() |
![]() |
![]() |
#23 | |
Member
![]() Posts: 16
Karma: 10
Join Date: Nov 2020
Device: amazon kindle
|
Quote:
Linux && Kindle && os.system("sync &") or Linux && Kindle && !/flush/ in mount options && os.system("sync &") |
|
![]() |
![]() |
![]() |
#24 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,528
Karma: 78910202
Join Date: Nov 2007
Location: Toronto
Device: Libra H2O, Libra Colour
|
But you're the only Kindle user reporting this issue......
|
![]() |
![]() |
![]() |
#25 |
Member
![]() Posts: 16
Karma: 10
Join Date: Nov 2020
Device: amazon kindle
|
SOLVED
Linux, Kindle, Calibre: I/O error vfat filesystem disconnect problem.
Any fresh Linux system without udisks2 may be affected by this bug. Solutions (any of 5 is ok): 1. Disable fsync for Kindle block device (sdb, etc): echo "write through" > /sys/block/DEVICE/queue/write_cache 2. Remount Kindle with "flush" option: mount -o remount,flush DEVICE MOUNTPOINT 3. Use udisks2 as automatic external device mount service (it use "flush" option by default) 4. Patch Calibre source files, comment 2 calls to os.fsync: /usr/lib/calibre/calibre/__init__.py /usr/lib/calibre/calibre/utils/filenames.py 5. Patch Calibre source files, add os.system("sync &") : /usr/lib/calibre/calibre/__init__.py: after: os.utime(fileobj.name, None) add: os.system("sync &") /usr/lib/calibre/calibre/utils/filenames.py: after: os.fsync(ans.fileno()) add: os.utime(os.path.join(cpath, fname), None) os.system("sync &") PS: Links to other topics related: https://bugzilla.kernel.org/show_bug.cgi?id=203973 https://bugs.launchpad.net/calibre/+bug/1834641 |
![]() |
![]() |
![]() |
#26 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,356
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Not using flush for removable storage devices is an *extremely* bad idea. It means it becomes much for likely there is data corruption if the device is accidentally removed, connection interrupted. I'm afraid I am not going to add special support for this to calibre. This bug is anyway a bug in the Kindle firmware/linux kernel, not calibre. Adding a utime() call after fsync is the extent of the workaround I am willing to implement for itin calibre.
|
![]() |
![]() |
![]() |
#27 |
Junior Member
![]() Posts: 1
Karma: 10
Join Date: Jan 2021
Device: Kindle
|
![]()
Joined here to say I am affected by this, too. Or by something somewhat similar, at least.
I was lucky to find this thread easily, since having to disconnect and reconnect the device for every book copied is not a proper experience. Thsnks yorikk for your analysis. At least I know there is something quite broken with Kindle firmware. I may be facing something different, though. ![]() udisk2 was already being used, but it isn't adding a flush option, it gets mounted with: Code:
rw,nosuid,nodev,noexec,relatime,sync,uid=<uid>,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro,uhelper=udisks2 Code:
python -c "p = '/run/media/kovid/Kindle/driveinfo.calibre'; f = open(p, 'r+b'); import os; os.fsync(f.fileno());" |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problem updateing calibre on linux to 2.46.0 | ThSpeck | Calibre | 5 | 12-16-2015 01:27 PM |
Calibre 2.2 causing premature Kindle 4 disconnect | rpspringuel | Devices | 9 | 09-21-2014 05:46 PM |
PDF problem in Calibre 1.10 on Linux Mint 15 | timberbeast | Library Management | 10 | 11-15-2013 11:47 AM |
Problem with calibre installation of linux mint | ajambi | Calibre | 2 | 01-06-2010 12:10 PM |
Calibre 0.6.27 starting problem (linux) | ferossan | Calibre | 4 | 12-11-2009 09:46 PM |