Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebff7b8b authored by lijiazi's avatar lijiazi
Browse files

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: default avatarlijiazi <lijiazi@xiaomi.com>
parent 615bf4ef
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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;