From 5d95d4dfe93f40ec00a2f0953747b06cd2af0a2a Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 15 Mar 2026 01:59:45 +0000 Subject: util/nvmutil: stricter return in pread we were returning if verified is not off, but we were not doing the check soon enough. now it's clearer: just after either a reset, or we found out offset doesn't match, we return sooner. otherwise, we read, and we verify again right after. in the old code, we verified twice in a row. this is just more optimal, for error handling. Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) (limited to 'util/nvmutil') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 55af4395..d510a9ea 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -2077,27 +2077,28 @@ real_pread_pwrite: * then another thread may have * changed it. Enabled if * off_reset is OFF_RESET. + * + * We do this *once*, on the theory + * that nothing is touching it now. */ - if (off != verified) { - if (!off_reset) - goto err_prw; + if (off_reset && off != verified) + lseek_loop(fd, off, SEEK_SET, + loop_eagain, loop_eintr); - /* - * Even if we allow to continue, - * we still need to reset the - * offset. If we can't, then - * we can't recover at all. - * - * However, we must preserve - * errno in that case, so - * just return immediately. - */ - if (lseek_loop(fd, off, SEEK_SET, - loop_eagain, loop_eintr) == (off_t)-1) + do { + if (off != verified) return -1; - } - do { + if (rw_type == IO_PREAD) + r = read(fd, mem, nrw); + else if (rw_type == IO_PWRITE) + r = write(fd, mem, nrw); + + if (rw_over_nrw(r, nrw) == -1) { + errno = EIO; + break; + } + /* * Verify again before I/O * (even with OFF_ERR) @@ -2118,19 +2119,6 @@ real_pread_pwrite: verified = lseek_loop(fd, (off_t)0, SEEK_CUR, loop_eagain, loop_eintr); - if (verified != off) - goto err_prw; - - if (rw_type == IO_PREAD) - r = read(fd, mem, nrw); - else if (rw_type == IO_PWRITE) - r = write(fd, mem, nrw); - - if (rw_over_nrw(r, nrw) == -1) { - errno = EIO; - break; - } - } while (r == -1 && (errno == try_err(loop_eintr, EINTR) || errno == try_err(loop_eagain, EAGAIN))); -- cgit v1.2.1