Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Devices

Notices

Reply
 
Thread Tools Search this Thread
Old 11-08-2020, 06:45 AM   #16
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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.
kovidgoyal is offline   Reply With Quote
Old 11-08-2020, 06:51 AM   #17
yorikk
Member
yorikk began at the beginning.
 
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...
yorikk is offline   Reply With Quote
Advert
Old 11-08-2020, 07:15 AM   #18
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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()
kovidgoyal is offline   Reply With Quote
Old 11-08-2020, 07:33 AM   #19
yorikk
Member
yorikk began at the beginning.
 
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.
yorikk is offline   Reply With Quote
Old 11-08-2020, 07:49 AM   #20
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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?
kovidgoyal is offline   Reply With Quote
Advert
Old 11-08-2020, 11:29 AM   #21
yorikk
Member
yorikk began at the beginning.
 
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.

yorikk is offline   Reply With Quote
Old 11-08-2020, 11:36 AM   #22
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
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?
PeterT is offline   Reply With Quote
Old 11-08-2020, 11:42 AM   #23
yorikk
Member
yorikk began at the beginning.
 
Posts: 16
Karma: 10
Join Date: Nov 2020
Device: amazon kindle
Quote:
Originally Posted by PeterT View Post
Why not have a custom udev entry for your Kindle that has the optins you need just for that device?
It's possible (already done) but who know how many Kindle users mount it with default options, leading to this very unusual bug ?

Linux && Kindle && os.system("sync &")

or Linux && Kindle && !/flush/ in mount options && os.system("sync &")
yorikk is offline   Reply With Quote
Old 11-08-2020, 12:26 PM   #24
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
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......
PeterT is offline   Reply With Quote
Old 11-08-2020, 05:10 PM   #25
yorikk
Member
yorikk began at the beginning.
 
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
yorikk is offline   Reply With Quote
Old 11-08-2020, 09:19 PM   #26
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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.
kovidgoyal is offline   Reply With Quote
Old 01-01-2021, 02:52 PM   #27
Debuk
Junior Member
Debuk began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Jan 2021
Device: Kindle
Unhappy

Quote:
Originally Posted by PeterT View Post
But you're the only Kindle user reporting this issue......
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
The calibre version (3.39.1, from Debian) is prior to the utime fix, but the kernel version is also prior to 4.19.50, so this system [em]shouldn't[/em] be affected. And in fact, the one-liner
Code:
python -c "p = '/run/media/kovid/Kindle/driveinfo.calibre'; f = open(p, 'r+b'); import os; os.fsync(f.fileno());"
doesn't disconnect it (NB: "import os" is missing in the code), yet something is disconnecting it after every calibre book transfer. Maybe not fsync related, after all, since commenting the two fsync() calls (plus restarting calibre, obviously) didn't help.
Debuk is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 01:28 AM.


MobileRead.com is a privately owned, operated and funded community.