update_engine: Add CachedFileDescriptor

Currently there are operations in the delta_performer which are not
efficient in writing into disk. For example BzipExtentWriter and
XZExtentWriter write in 16KB buffers which is not very efficient for
today's disks specially if we are writing with O_DSYNC flag. Another
problem is operations such as bspatch which write in very small number
of bytes in order of a few bytes to a few hundred bytes. Even though
bspatch open's its own file descriptor and currently have no O_DSYNC
added, writing in very small bytes into disk in general is not a good
idea for the purpose of the update engine.

This patch adds new wrapper for a FileDescriptor interface which caches
all the writes into a large buffer (like 1MB) and writes it into disk
when either a 'Flush' request comes or if the offset of the file has
been changed to a different position than what it is writing now. This
cached buffer can be wrapped around target_fd_ and every operation can
write into it. This centralizes all write oprerations through one file
descriptor and gives greater control on how writes should be performed.

BUG=chromium:762815
TEST=FEATURES="test" emerge-amd-generic update_engine; brillo_update_payload verify

Change-Id: I4911d917ec9362bf66c4dd2ed19d89440042733c
Reviewed-on: https://chromium-review.googlesource.com/674164
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
5 files changed
tree: 382abdddcea43068c8828241b3dabc9a8bbb603c
  1. .gitignore
  2. Android.mk
  3. CPPLINT.cfg
  4. MODULE_LICENSE_APACHE2
  5. NOTICE
  6. OWNERS
  7. PRESUBMIT.cfg
  8. PREUPLOAD.cfg
  9. UpdateEngine.conf
  10. WATCHLISTS
  11. binder_bindings/
  12. binder_service_android.cc
  13. binder_service_android.h
  14. binder_service_brillo.cc
  15. binder_service_brillo.h
  16. boot_control_android.cc
  17. boot_control_android.h
  18. boot_control_chromeos.cc
  19. boot_control_chromeos.h
  20. boot_control_chromeos_unittest.cc
  21. boot_control_recovery.cc
  22. boot_control_recovery.h
  23. boot_control_recovery_stub.cc
  24. certificate_checker.cc
  25. certificate_checker.h
  26. certificate_checker_unittest.cc
  27. chrome_browser_proxy_resolver.cc
  28. chrome_browser_proxy_resolver.h
  29. chrome_browser_proxy_resolver_unittest.cc
  30. client_library/
  31. common/
  32. common_service.cc
  33. common_service.h
  34. common_service_unittest.cc
  35. connection_manager.cc
  36. connection_manager.h
  37. connection_manager_android.cc
  38. connection_manager_android.h
  39. connection_manager_interface.h
  40. connection_manager_unittest.cc
  41. connection_utils.cc
  42. connection_utils.h
  43. daemon.cc
  44. daemon.h
  45. daemon_state_android.cc
  46. daemon_state_android.h
  47. daemon_state_interface.h
  48. dbus_bindings/
  49. dbus_connection.cc
  50. dbus_connection.h
  51. dbus_service.cc
  52. dbus_service.h
  53. dbus_test_utils.h
  54. fake_file_writer.h
  55. fake_p2p_manager.h
  56. fake_p2p_manager_configuration.h
  57. fake_shill_proxy.cc
  58. fake_shill_proxy.h
  59. fake_system_state.cc
  60. fake_system_state.h
  61. generate_pc_file.sh
  62. hardware_android.cc
  63. hardware_android.h
  64. hardware_chromeos.cc
  65. hardware_chromeos.h
  66. hardware_chromeos_unittest.cc
  67. image_properties.h
  68. image_properties_android.cc
  69. image_properties_chromeos.cc
  70. image_properties_chromeos_unittest.cc
  71. init/
  72. libcurl_http_fetcher.cc
  73. libcurl_http_fetcher.h
  74. libupdate_engine-client-test.pc.in
  75. libupdate_engine-client.pc.in
  76. local_coverage_rate
  77. main.cc
  78. metrics.cc
  79. metrics.h
  80. metrics_utils.cc
  81. metrics_utils.h
  82. metrics_utils_unittest.cc
  83. mock_certificate_checker.h
  84. mock_connection_manager.h
  85. mock_file_writer.h
  86. mock_omaha_request_params.h
  87. mock_p2p_manager.h
  88. mock_payload_state.h
  89. mock_power_manager.h
  90. mock_proxy_resolver.h
  91. mock_update_attempter.h
  92. network_selector.h
  93. network_selector_android.cc
  94. network_selector_android.h
  95. network_selector_interface.h
  96. network_selector_stub.cc
  97. network_selector_stub.h
  98. omaha_request_action.cc
  99. omaha_request_action.h
  100. omaha_request_action_unittest.cc
  101. omaha_request_params.cc
  102. omaha_request_params.h
  103. omaha_request_params_unittest.cc
  104. omaha_response.h
  105. omaha_response_handler_action.cc
  106. omaha_response_handler_action.h
  107. omaha_response_handler_action_unittest.cc
  108. omaha_utils.cc
  109. omaha_utils.h
  110. omaha_utils_unittest.cc
  111. p2p_manager.cc
  112. p2p_manager.h
  113. p2p_manager_unittest.cc
  114. parcelable_update_engine_status.cc
  115. parcelable_update_engine_status.h
  116. payload_consumer/
  117. payload_generator/
  118. payload_state.cc
  119. payload_state.h
  120. payload_state_interface.h
  121. payload_state_unittest.cc
  122. power_manager_android.cc
  123. power_manager_android.h
  124. power_manager_chromeos.cc
  125. power_manager_chromeos.h
  126. power_manager_interface.h
  127. proxy_resolver.cc
  128. proxy_resolver.h
  129. proxy_resolver_unittest.cc
  130. pylintrc
  131. real_system_state.cc
  132. real_system_state.h
  133. run_unittests
  134. sample_images/
  135. sample_omaha_v3_response.xml
  136. scripts/
  137. service_delegate_android_interface.h
  138. service_observer_interface.h
  139. shill_proxy.cc
  140. shill_proxy.h
  141. shill_proxy_interface.h
  142. sideload_main.cc
  143. system_state.h
  144. tar_bunzip2.gypi
  145. test_http_server.cc
  146. test_subprocess.cc
  147. testrunner.cc
  148. unittest_key.pem
  149. unittest_key2.pem
  150. update_attempter.cc
  151. update_attempter.h
  152. update_attempter_android.cc
  153. update_attempter_android.h
  154. update_attempter_unittest.cc
  155. update_engine-client.gyp
  156. update_engine.conf
  157. update_engine.gyp
  158. update_engine.rc
  159. update_engine_client.cc
  160. update_engine_client_android.cc
  161. update_manager/
  162. update_metadata.proto
  163. update_payload_key/
  164. update_status_utils.cc
  165. update_status_utils.h
  166. utils_android.cc
  167. utils_android.h