From 6e5d6e5da19acfa8ba2c9fcf81651d0894f83dda Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 4 Jun 2025 21:03:58 +0100 Subject: [PATCH] file: Add the filename (or equivalent) to error messages It helps to have this information when there's an error. It particularly helps in two cases: (1) You don't have access to the nbdkit command line. (2) The filename is derived from an export name passed by the client. (cherry picked from commit 7273bd829fc0d8e492786f8908d8ddc3d5399e06) --- plugins/file/file.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/plugins/file/file.c b/plugins/file/file.c index f96d8a8c..9ba61187 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -754,7 +754,7 @@ file_get_size (void *handle) r = device_size (h->fd, &h->statbuf); if (r == -1) { - nbdkit_error ("device_size: %m"); + nbdkit_error ("device_size: %s: %m", h->name); return -1; } return r; @@ -818,7 +818,7 @@ file_flush (void *handle, uint32_t flags) struct handle *h = handle; if (fdatasync (h->fd) == -1) { - nbdkit_error ("fdatasync: %m"); + nbdkit_error ("fdatasync: %s: %m", h->name); return -1; } @@ -839,11 +839,11 @@ 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: %m"); + nbdkit_error ("pread: %s: %m", h->name); return -1; } if (r == 0) { - nbdkit_error ("pread: unexpected end of file"); + nbdkit_error ("pread: %s: unexpected end of file", h->name); return -1; } buf += r; @@ -875,7 +875,7 @@ 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: %m"); + nbdkit_error ("pwrite: %s: %m", h->name); return -1; } buf += r; @@ -957,7 +957,7 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } if (!is_enotsup (errno)) { - nbdkit_error ("zero: %m"); + nbdkit_error ("zero: %s: %m", h->name); return -1; } @@ -993,7 +993,7 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } if (!is_enotsup (errno)) { - nbdkit_error ("zero: %m"); + nbdkit_error ("zero: %s: %m", h->name); return -1; } @@ -1001,7 +1001,7 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } else { if (!is_enotsup (errno)) { - nbdkit_error ("zero: %m"); + nbdkit_error ("zero: %s: %m", h->name); return -1; } @@ -1023,7 +1023,7 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } if (!is_enotsup (errno)) { - nbdkit_error ("zero: %m"); + nbdkit_error ("zero: %s: %m", h->name); return -1; } @@ -1051,14 +1051,14 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } if (!is_enotsup (errno)) { - nbdkit_error ("zero: %m"); + nbdkit_error ("zero: %s: %m", h->name); return -1; } h->can_fallocate = false; } else { if (!is_enotsup (errno)) { - nbdkit_error ("zero: %m"); + nbdkit_error ("zero: %s: %m", h->name); return -1; } @@ -1082,7 +1082,7 @@ file_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags) } if (errno != ENOTTY) { - nbdkit_error ("zero: %m"); + nbdkit_error ("zero: %s: %m", h->name); return -1; } @@ -1120,7 +1120,7 @@ file_trim (void *handle, uint32_t count, uint64_t offset, uint32_t flags) /* Trim is advisory; we don't care if it fails for anything other * than EIO or EPERM. */ if (errno == EPERM || errno == EIO) { - nbdkit_error ("fallocate: %m"); + nbdkit_error ("fallocate: %s: %m", h->name); return -1; } @@ -1241,7 +1241,7 @@ 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: %m"); + nbdkit_error ("posix_fadvise: %s: %m", h->name); return -1; } return 0; -- 2.47.1