From 53f5fa4e1f560475dadbefc1f00e0f3d2ca84ca0 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 4dec4bd9..8018b294 100644 --- a/plugins/file/file.c +++ b/plugins/file/file.c @@ -797,7 +797,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; @@ -883,7 +883,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; } @@ -904,11 +904,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; @@ -940,7 +940,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; @@ -1022,7 +1022,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; } @@ -1058,7 +1058,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; } @@ -1066,7 +1066,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; } @@ -1088,7 +1088,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; } @@ -1116,14 +1116,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; } @@ -1147,7 +1147,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; } @@ -1185,7 +1185,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; } @@ -1306,7 +1306,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