DEVELOPING 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. This documentation may be outdated. Sorry if it's so :(
  2. First of all, I recommend you to read the manpage
  3. with "man ./man/man1/clsync.1".
  4. After that, I recommend you to run command "make doc" and look at images
  5. "./doc/html/main_8c_a0ddf1224851353fc92bfbff6f499fa97_cgraph.png" and
  6. "./doc/html/sync_8c_a320ae70a547c80b9b3ae897f955b2862_icgraph.png"
  7. The syncing is proceeding on "exec_argv()" on this image. ;)
  8. Here's very short description of how the program works:
  9. Program execution starts with main() function in "main.c".
  10. In turn, main() sets default configuration and executes:
  11. - parse_arguments() to parse "argv"
  12. - main_rehash() to parse file with filter-rules
  13. - becomedaemon() to fork() to daemonize
  14. - and sync_run() of "sync.c" to proceed to syncing process
  15. First of all, sync_run prepares hashtables and other things to be used in
  16. future.. and then sync_run() executes:
  17. - sync_notify_init() to initialize file system monitoring kernel interface
  18. - sync_mark_walk() to mark all directories in the monitoring interface
  19. - sync_notify_loop() to run infinite loop of checking and processing of
  20. the program
  21. sync_notify_loop() runs sync_fanotify_loop() or sync_inotify_loop() depending
  22. on selected FS monitoring kernel interface ("inotify" or "fanotify"). However,
  23. at the moment fanotify is not supported, so we will suppose, that the
  24. sync_inotify_loop() is used.
  25. sync_inotify_loop() waits for events with sync_inotify_wait(), handling
  26. them with sync_inotify_handle() and executes sync_idle() to process
  27. background things.
  28. Waiting and handling the events is proceeded with using of 3 queues:
  29. 1.) for normal files and directories
  30. 2.) for big files
  31. 3.) for immidiate syncing
  32. To be able to do that, the events are separated and stored in 3 hashtables
  33. (indexes_p->fpath2ei_coll_ht[queue_id]).
  34. sync_inotify_handle() is:
  35. - managing watch descriptors
  36. - executes rules_check() to filter events, then aggregating them into
  37. "indexes_p->fpath2ei_ht"
  38. - marking and syncing newly created directories
  39. - executing sync_inotify_handle_dosync() for every event to queue the syncing
  40. sync_inotify_handle_dosync() is just executes sync_queuesync() with
  41. appropriate arguments to queue the syncing.
  42. When the execution will back to sync_inotify_loop() code it will proceed to
  43. sync_idle().
  44. sync_idle() executes _sync_exec_idle() to cleanup after previous executions
  45. of sync_exec_thread() and executes sync_idle_dosync_collectedevents() to
  46. process new events.
  47. sync_idle_dosync_collectedevents() prepares a lists of exclusion and inclusion
  48. to be synced and executes sync_idle_dosync_collectedevents_commitpart() to
  49. commit the lists. In turn, sync_idle_dosync_collectedevents_commitpart()
  50. executes sync_exec_thread() or sync_exec() depending on "argv" arguments.
  51. sync_exec_thread and sync_exec executes exec_argv that calls execvp to run
  52. external syncer process.
  53. The external syncer process is supposed to be rsync or any script that is able
  54. to handle with the task.