cros_flash: Use oflag=direct in dd for better performance
Update the dd and sync command in CopyImageToDevice.
Use `oflag=direct` to bypass system buffer, which saves 5-10 seconds.
With `conv=fdatasync`, dd does sync before finish to ensure data physically
written to the device. We don't use `conv=fsync` because we don't need the
metadata from the original image file.
With `sync -d device`, we sync only file data to the specific device instead
of syncing the whole system to prevent halting for other I/O to finish.
BUG=None
TEST=`cros flash usb:// ...`
Change-Id: Id771a67c7e92e13b930859c81bc3c429e0ccd562
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1673768
Tested-by: Frank Huang <frankbozar@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Evan Green <evgreen@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/cli/flash_unittest.py b/cli/flash_unittest.py
index 0d02871..02cf06a 100644
--- a/cli/flash_unittest.py
+++ b/cli/flash_unittest.py
@@ -210,7 +210,7 @@
def testUsbImagerOperationCalled(self):
"""Test that flash.UsbImagerOperation is called when log level <= NOTICE."""
expected_cmd = ['dd', 'if=foo', 'of=bar', 'bs=4M', 'iflag=fullblock',
- 'oflag=sync']
+ 'oflag=direct', 'conv=fdatasync']
usb_imager = flash.USBImager('dummy_device', 'board', 'foo')
run_mock = self.PatchObject(flash.UsbImagerOperation, 'Run')
self.PatchObject(logging.Logger, 'getEffectiveLevel',
@@ -224,7 +224,7 @@
def testSudoRunCommandCalled(self):
"""Test that SudoRunCommand is called when log level > NOTICE."""
expected_cmd = ['dd', 'if=foo', 'of=bar', 'bs=4M', 'iflag=fullblock',
- 'oflag=sync']
+ 'oflag=direct', 'conv=fdatasync']
usb_imager = flash.USBImager('dummy_device', 'board', 'foo')
run_mock = self.PatchObject(cros_build_lib, 'SudoRunCommand')
self.PatchObject(logging.Logger, 'getEffectiveLevel',