graysky2 / anything-sync-daemon

Symlinks and syncs user specified dirs to RAM thus reducing HDD/SDD calls and speeding-up the system.
https://wiki.archlinux.org/index.php/Anything-sync-daemon
MIT License
349 stars 44 forks source link

Syncing target dir to lower dir is undefined behavior #23

Closed ivashov closed 9 years ago

ivashov commented 9 years ago

https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt says:

Changes to the underlying filesystems while part of a mounted overlay filesystem are not allowed

but the asd script does just that at line 254.

may be this UB is related to the "Soukyuuv" user's issue in this thread: https://bbs.archlinux.org/viewtopic.php?id=139141&p=11

graysky2 commented 9 years ago

Not sure what to make of that. Is it meaning that users should avoid them or that the software avoids them.

graysky2 commented 9 years ago

@ivashov

Any thoughts?

ivashov commented 9 years ago

I think backup dir and overlayfs' lower dir should be separate directories. lower dir should not be changed while asd is active (according to kernel.org documentation).

On asd start: 1) Rename initial directory into lowerdir (that with "-backup_asd" suffix) 2) copy lowerdir into backup dir 3) Mount overlayfs into tmpfs

Before asd shutdown: 1) sync tmpfs dir into backup dir (this action also is being performed by cron every hour) 2) unmount overlayfs 3) rename backup dir into initial directory name 4) delete lower dir

graysky2 commented 9 years ago

I will check it out... my hands a bit full right now. If you would be kind enough to send a PR that would be welcomed :wink:

graysky2 commented 9 years ago

Well, if this is indeed the problem, at somepoint (first resync) the lowerdir will need to be written in its entirety so the resync can write back to it.

graysky2 commented 9 years ago

@ivashov - Thank for you pointing out this issue (affecting psd as well). Please try asd from my unstable branch which should fix it. NOTE- Make sure you stop asd before you install the new code. If you're running Arch, below is a PKGBUILD and corresponding asd.install for you to use:

https://gist.github.com/graysky2/5090466288c67bb49f25 https://gist.github.com/graysky2/d9c875be683305affe85