RFC: Do we want a new igt_write() function?
Peter Senna Tschudin
peter.senna at linux.intel.com
Mon Jan 20 13:39:16 UTC 2025
Dear List,
I find myself wanting to repeat some small variation of a write function
that retries on recoverable errors and that aborts on unrecoverable errors.
Is the idea of an igt_write() function a welcome addition to lib/igt_core?
Something like:
#define MAX_WRITE_RETRIES 5
/**
* igt_write - Writes the buffer to the file descriptor retrying when possible.
* @fd: The file descriptor to write to.
* @buf: Pointer to the data to write.
* @count: Total number of bytes to write.
*
* Returns the total number of bytes written on success, or -1 on failure.
*/
ssize_t igt_write(int fd, const void *buf, size_t count) {
const char *ptr = buf;
size_t remaining = count;
ssize_t written;
int retries = 0;
while (remaining > 0) {
written = write(fd, ptr, remaining);
if (written > 0) {
ptr += written;
remaining -= written;
} else if (written == -1) {
if (errno == EINTR || errno == EAGAIN) {
/* Retry for recoverable errors */
if (++retries > MAX_WRITE_RETRIES) {
igt_err("igt_write: Exceeded retry limit\n");
return -1;
}
continue;
} else {
/* Log unrecoverable error */
igt_err("igt_write: unrecoverable write error");
return -1;
}
}
}
return count;
}
Thanks,
Peter
More information about the igt-dev
mailing list