mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-16 13:16:47 +02:00
util/nvmutil: implement zero-byte r/w timeout
Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+14
-11
@@ -1461,6 +1461,9 @@ rw_file_once(int fd, uint8_t *mem, size_t len,
|
|||||||
off_t off, int rw_type, size_t rc)
|
off_t off, int rw_type, size_t rc)
|
||||||
{
|
{
|
||||||
ssize_t rv;
|
ssize_t rv;
|
||||||
|
size_t retries_on_zero = 0;
|
||||||
|
size_t max_retries = 10;
|
||||||
|
|
||||||
read_again:
|
read_again:
|
||||||
rv = do_rw(fd, mem + rc, len - rc, off + rc, rw_type);
|
rv = do_rw(fd, mem + rc, len - rc, off + rc, rw_type);
|
||||||
|
|
||||||
@@ -1479,17 +1482,17 @@ read_again:
|
|||||||
*/
|
*/
|
||||||
if ((size_t)rv > (len - rc) /* Prevent overflow */
|
if ((size_t)rv > (len - rc) /* Prevent overflow */
|
||||||
|| rv == 0) { /* Prevent infinite 0-byte loop */
|
|| rv == 0) { /* Prevent infinite 0-byte loop */
|
||||||
/*
|
if (rv == 0) {
|
||||||
* TODO: handle rv == 0 this way:
|
/*
|
||||||
* re-try a finite number of times,
|
* Fault tolerance against infinite
|
||||||
* based on a counter, that resets
|
* zero-byte loop: re-try a finite
|
||||||
* on a non-zero read but then returns
|
* number of times. This mitigates
|
||||||
* like below if the counter reaches
|
* otherwise OK but slow filesystems
|
||||||
* the limit. This will retain the
|
* e.g. NFS or slow media.
|
||||||
* current safety, while increasing
|
*/
|
||||||
* robustness e.g. on unreliable NFS
|
if (retries_on_zero++ < max_retries)
|
||||||
* shares or really slow media.
|
goto read_again;
|
||||||
*/
|
}
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user