From 84362587e5bb53e113c65d9876cf5b3c39174bab Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 4 Jun 2025 21:15:26 +0100 Subject: [PATCH] file: Add offset/count to error messages Although the same information is available in debug logs, if verbose messages (-v) are not used then the information is lost. As it might be useful occasionally, ensure it is captured in errors. (cherry picked from commit 253574354252f4a77e2df0769b721e76f1777651) --- plugins/file/file.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/plugins/file/file.c b/plugins/file/file.c index 2bba7e77..ef40b400 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -904,7 +904,8 @@ file_pread (void *handle, void *buf, uint32_t count, uint64_t offset, while (count > 0) { ssize_t r = pread (h->fd, buf, count, offset); if (r == -1) { - nbdkit_error ("pread: %s: %m", h->name); + nbdkit_error ("pread: %s: offset=%" PRIu64 ", count=%" PRIu32 ": %m", + h->name, offset, count); return -1; } if (r == 0) { @@ -939,7 +940,8 @@ file_pwrite (void *handle, const void *buf, uint32_t count, uint64_t offset, while (count > 0) { ssize_t r = pwrite (h->fd, buf, count, offset); if (r == -1) { - nbdkit_error ("pwrite: %s: %m", h->name); + nbdkit_error ("pwrite: %s: offset=%" PRIu64 ", count=%" PRIu32 ": %m", + h->name, offset, count); return -1; } buf += r; @@ -1021,7 +1023,8 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } if (!is_enotsup (errno)) { - nbdkit_error ("zero: %s: %m", h->name); + nbdkit_error ("zero: %s: offset=%" PRIu64 ", count=%" PRIu32 ": %m", + h->name, offset, count); return -1; } @@ -1057,7 +1060,8 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } if (!is_enotsup (errno)) { - nbdkit_error ("zero: %s: %m", h->name); + nbdkit_error ("zero: %s: offset=%" PRIu64 ", count=%" PRIu32 ": %m", + h->name, offset, count); return -1; } @@ -1065,7 +1069,8 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } else { if (!is_enotsup (errno)) { - nbdkit_error ("zero: %s: %m", h->name); + nbdkit_error ("zero: %s: offset=%" PRIu64 ", count=%" PRIu32 ": %m", + h->name, offset, count); return -1; } @@ -1087,7 +1092,8 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } if (!is_enotsup (errno)) { - nbdkit_error ("zero: %s: %m", h->name); + nbdkit_error ("zero: %s: offset=%" PRIu64 ", count=%" PRIu32 ": %m", + h->name, offset, count); return -1; } @@ -1115,14 +1121,16 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } if (!is_enotsup (errno)) { - nbdkit_error ("zero: %s: %m", h->name); + nbdkit_error ("zero: %s: offset=%" PRIu64 ", count=%" PRIu32 ": %m", + h->name, offset, count); return -1; } h->can_fallocate = false; } else { if (!is_enotsup (errno)) { - nbdkit_error ("zero: %s: %m", h->name); + nbdkit_error ("zero: %s: offset=%" PRIu64 ", count=%" PRIu32 ":%m", + h->name, offset, count); return -1; } @@ -1146,7 +1154,8 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } if (errno != ENOTTY) { - nbdkit_error ("zero: %s: %m", h->name); + nbdkit_error ("zero: %s: offset=%" PRIu64 ", count=%" PRIu32 ": %m", + h->name, offset, count); return -1; } @@ -1183,7 +1192,9 @@ file_trim (void *handle, uint32_t count, uint64_t offset, uint32_t flags) offset, count); if (r == -1) { if (!is_enotsup (errno)) { - nbdkit_error ("fallocate: %s: %m", h->name); + nbdkit_error ("fallocate: %s: offset=%" PRIu64 ", count=%" PRIu32 ":" + " %m", + h->name, offset, count); return -1; } @@ -1322,7 +1333,9 @@ file_cache (void *handle, uint32_t count, uint64_t offset, uint32_t flags) r = posix_fadvise (h->fd, offset, count, POSIX_FADV_WILLNEED); if (r) { errno = r; - nbdkit_error ("posix_fadvise: %s: %m", h->name); + nbdkit_error ("posix_fadvise: %s: offset=%" PRIu64 ", count=%" PRIu32 ":" + " %m", + h->name, offset, count); return -1; } return 0; -- 2.47.1