mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-19 12:12:16 +00:00
DM: Add write sync in fwrite
An immediate reset or power down will cause a loss of write content. The cause is the data write to disk is at cache within a short time window before it's synced to storage media. An explicit fsync() forces to sync the data to storage to prevent the data loss of such immediate reset. Signed-off-by: Huang Yang <yang.huang@intel.com> Signed-off-by: duminx <minx.du@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
96372ed09c
commit
0621b24819
@ -29,6 +29,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <openssl/hmac.h>
|
#include <openssl/hmac.h>
|
||||||
#include <openssl/opensslv.h>
|
#include <openssl/opensslv.h>
|
||||||
|
|
||||||
@ -168,10 +169,17 @@ static int file_write(FILE *fp, const void *buf, size_t size, off_t offset)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The flow of file writing sync should be:
|
||||||
|
C lib caches--->fflush--->disk caches--->fsync--->disk */
|
||||||
if (fflush(fp) < 0) {
|
if (fflush(fp) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fsync(fileno(fp)) < 0) {
|
||||||
|
DPRINTF(("%s: fsync failed\n", __func__));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user