summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkilesh Kailash <akailash@google.com>2020-12-30 00:52:20 +0000
committerAkilesh Kailash <akailash@google.com>2020-12-30 00:53:06 +0000
commit92f927154d353f42357c3db2cdacbb0653847d65 (patch)
tree2275793e7a0b67f18b23666440c1fae22b6feb49
parentcc20ee09ceaff571c62ee03c730acc54c84a8560 (diff)
downloadbonito-92f927154d353f42357c3db2cdacbb0653847d65.tar.gz
fsync after block device writes
When markBoolSuccessful is invoked, we update the partition table. These writes should be synced before merge operation is resumed post OTA. If not, any crash before these writes are landed to backing storage will lead to incorrect switching of slots. BUG: 175711601 Test: Verify slot switching correctly after crash when merge in progress (on redbull) Signed-off-by: Akilesh Kailash <akailash@google.com> Change-Id: Icc4987e5e8fb1a4b55a0c8ca74c362c56dd9d0ed
-rw-r--r--gpt-utils/gpt-utils.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/gpt-utils/gpt-utils.cpp b/gpt-utils/gpt-utils.cpp
index 2a97f1b3..dfff86a0 100644
--- a/gpt-utils/gpt-utils.cpp
+++ b/gpt-utils/gpt-utils.cpp
@@ -157,11 +157,18 @@ static int blk_rw(int fd, int rw, int64_t offset, uint8_t *buf, unsigned len)
else
r = read(fd, buf, len);
- if (r < 0)
+ if (r < 0) {
fprintf(stderr, "block dev %s failed: %s\n", rw ? "write" : "read",
strerror(errno));
- else
- r = 0;
+ } else {
+ if (rw) {
+ r = fsync(fd);
+ if (r < 0)
+ fprintf(stderr, "fsync failed: %s\n", strerror(errno));
+ } else {
+ r = 0;
+ }
+ }
return r;
}