diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-14 04:47:28 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-14 04:47:28 +0000 |
| commit | ee511881b33a60b47a9a0f9d5b16341c7020af01 (patch) | |
| tree | f76595c2629c4b25d84f855e1a044db69e67ce18 /util/nvmutil | |
| parent | 05b39d2ff23398026168f2e866201ae7e009330d (diff) | |
util/nvmutil: optimise fsync / write check
write all at once, then sync all at once,
then verify all at once.
this increases the chancce that all data
gets written first, in the case of power
less, because fsync may take a while on
some systems.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 2f6de8aa..780ab430 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -332,7 +332,7 @@ static void check_bin(size_t a, const char *a_name); */ static void rw_gbe_file_part(size_t p, int rw_type, const char *rw_type_str); -static void verify_gbe_bin_write(size_t p); +static void check_written_part(size_t p); static u8 *gbe_mem_offset(size_t part, const char *f_op); static off_t gbe_file_offset(size_t part, const char *f_op); static off_t gbe_x_offset(size_t part, const char *f_op, @@ -675,9 +675,21 @@ main(int argc, char *argv[]) run_cmd(cmd_index); - if (command[cmd_index].flags == O_RDWR) + if (command[cmd_index].flags == O_RDWR) { write_gbe_file(); + /* + * We may otherwise read from + * cache, so we must sync. + */ + if (fsync(gbe_fd) == -1) + err(errno, "%s: fsync (pre-verification)", + fname); + + check_written_part(0); + check_written_part(1); + } + close_files(); return EXIT_SUCCESS; @@ -1521,36 +1533,25 @@ rw_gbe_file_part(size_t p, int rw_type, if ((size_t)r != gbe_rw_size) err(EIO, "%s: partial %s: part %lu", fname, rw_type_str, (ulong)p); - - /* - * Next, we read back what was written, - * to ensure that it was done correctly. - * NOTE: using "pad" (only cat uses it) - */ - if (rw_type == IO_PWRITE) - verify_gbe_bin_write(p); } static void -verify_gbe_bin_write(size_t p) +check_written_part(size_t p) { ssize_t r; - size_t gbe_rw_size = command[cmd_index].rw_size; + size_t gbe_rw_size; u8 *mem_offset; off_t file_offset; + if (!part_modified[p]) + return; + + gbe_rw_size = command[cmd_index].rw_size; + /* invert not needed for pwrite */ mem_offset = gbe_mem_offset(p, "pwrite"); file_offset = (off_t)gbe_file_offset(p, "pwrite"); - /* - * We may otherwise read from - * cache, so we must sync. - */ - if (fsync(gbe_fd) == -1) - err(errno, "%s: fsync: part %lu (post-verification)", - fname, (ulong)p); - r = rw_gbe_file_exact(gbe_fd, pad, gbe_rw_size, file_offset, IO_PREAD); |
