From ebff7b8b978639e0dfef828a005efa2bd5da746d Mon Sep 17 00:00:00 2001 From: lijiazi Date: Fri, 16 Jul 2021 16:25:31 +0800 Subject: [PATCH] fiemap: add fsync after write split file name If device abnormal restart during upgrade, update_engine just created split cow image file and wrote the name to xxx-cow-img.img. After restart, update_engine will report following err: 06-30 08:48:06.466 root 8918 8920 E gsid : Error removing image product_b-cow-img: File name too long That is because SplitFiemap::Create->DetermineMaximumFileSize open xxx-cow-img.img to get some info, then fsync and unlink this file. On device use f2fs, after restart, f2fs_recover_fsync_data will recover this file with inode block sync to ufs in following path: DetermineMaximumFileSize ->FiemapWriter::Open ->AllocateFile This make xxx-cow-img.img file content corruption. Update_engine call TryCancelUpdate to clean up the residual files of last upgrade, cannot read valid split file name from xxx-cow-img.img, then report err log mentioned above. Add fsync, f2fs can use correct inode to recover related files. This can reduce the probability of this issue. Test: abnormal restart when upgrade Change-Id: Iceb3e5604d90495350c5fb1fb3433732372f3fec Signed-off-by: lijiazi --- fs_mgr/libfiemap/split_fiemap_writer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/fs_mgr/libfiemap/split_fiemap_writer.cpp b/fs_mgr/libfiemap/split_fiemap_writer.cpp index 36bb3dfee..8457066fa 100644 --- a/fs_mgr/libfiemap/split_fiemap_writer.cpp +++ b/fs_mgr/libfiemap/split_fiemap_writer.cpp @@ -136,6 +136,7 @@ FiemapStatus SplitFiemap::Create(const std::string& file_path, uint64_t file_siz return FiemapStatus::FromErrno(errno); } } + fsync(fd.get()); // Unset this bit, so we don't unlink on destruction. out->creating_ = false;