mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
util/nvmutil: loop EINTR on fsync
this improves reliability, making it more likely that data actually gets synced, since fsync can return -1 with EINTR, indicating that a re-try should be attempted. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+18
-5
@@ -484,6 +484,7 @@ int x_try_fdpath(const char *prefix,
|
|||||||
int fd, mode_t mode);
|
int fd, mode_t mode);
|
||||||
unsigned long x_conv_fd(char *buf,
|
unsigned long x_conv_fd(char *buf,
|
||||||
unsigned long n);
|
unsigned long n);
|
||||||
|
int x_i_fsync(int fd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sizes in bytes:
|
* Sizes in bytes:
|
||||||
@@ -1116,7 +1117,7 @@ copy_gbe(void)
|
|||||||
* fsync tmp gbe file, because we will compare
|
* fsync tmp gbe file, because we will compare
|
||||||
* its contents to what was read (for safety)
|
* its contents to what was read (for safety)
|
||||||
*/
|
*/
|
||||||
if (fsync(tmp_fd) == -1)
|
if (x_i_fsync(tmp_fd) == -1)
|
||||||
err(errno, "%s: fsync (tmpfile copy)", tname);
|
err(errno, "%s: fsync (tmpfile copy)", tname);
|
||||||
|
|
||||||
r = rw_file_exact(tmp_fd, bufcmp, gbe_file_size,
|
r = rw_file_exact(tmp_fd, bufcmp, gbe_file_size,
|
||||||
@@ -1810,7 +1811,7 @@ write_to_gbe_bin(void)
|
|||||||
* We may otherwise read from
|
* We may otherwise read from
|
||||||
* cache, so we must sync.
|
* cache, so we must sync.
|
||||||
*/
|
*/
|
||||||
if (fsync(tmp_fd) == -1)
|
if (x_i_fsync(tmp_fd) == -1)
|
||||||
err(errno, "%s: fsync (pre-verification)",
|
err(errno, "%s: fsync (pre-verification)",
|
||||||
tname);
|
tname);
|
||||||
|
|
||||||
@@ -2049,7 +2050,7 @@ gbe_mv(void)
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto ret_gbe_mv;
|
goto ret_gbe_mv;
|
||||||
|
|
||||||
if (fsync(dest_fd) == -1)
|
if (x_i_fsync(dest_fd) == -1)
|
||||||
goto ret_gbe_mv;
|
goto ret_gbe_mv;
|
||||||
|
|
||||||
if (x_i_close(dest_fd) == -1)
|
if (x_i_close(dest_fd) == -1)
|
||||||
@@ -2165,7 +2166,7 @@ fsync_dir(const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* sync file on disk */
|
/* sync file on disk */
|
||||||
if (fsync(dfd) == -1)
|
if (x_i_fsync(dfd) == -1)
|
||||||
goto err_fsync_dir;
|
goto err_fsync_dir;
|
||||||
|
|
||||||
if (x_i_close(dfd) == -1)
|
if (x_i_close(dfd) == -1)
|
||||||
@@ -3104,7 +3105,7 @@ x_i_rename(const char *src, const char *dst)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fsync(dfd);
|
x_i_fsync(dfd);
|
||||||
|
|
||||||
x_i_close(sfd);
|
x_i_close(sfd);
|
||||||
x_i_close(dfd);
|
x_i_close(dfd);
|
||||||
@@ -3233,3 +3234,15 @@ x_conv_fd(char *buf, unsigned long n)
|
|||||||
|
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
x_i_fsync(int fd)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
do {
|
||||||
|
r = fsync(fd);
|
||||||
|
} while (r == -1 && errno == EINTR);
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user