mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-01-14 09:12:11 +03:00
mmap_seek: print error code and text on failure
If lseek() returns an unexpected error, it's useful to know the error code to help connect it to the trouble spot inside the module. Since the two seek functions should be basically identical, lift them into a single generic function. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Robert Evans <evansr@google.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Rob Norris <rob.norris@klarasystems.com> Closes #17843
This commit is contained in:
parent
3378a324df
commit
1956417b54
@ -47,25 +47,34 @@
|
||||
#endif
|
||||
|
||||
static void
|
||||
seek_data(int fd, off_t offset, off_t expected)
|
||||
seek_expect(int fd, off_t offset, int whence, off_t expect_offset)
|
||||
{
|
||||
off_t data_offset = lseek(fd, offset, SEEK_DATA);
|
||||
if (data_offset != expected) {
|
||||
fprintf(stderr, "lseek(fd, %d, SEEK_DATA) = %d (expected %d)\n",
|
||||
(int)offset, (int)data_offset, (int)expected);
|
||||
exit(2);
|
||||
}
|
||||
errno = 0;
|
||||
off_t seek_offset = lseek(fd, offset, whence);
|
||||
if (seek_offset == expect_offset)
|
||||
return;
|
||||
|
||||
int err = errno;
|
||||
fprintf(stderr, "lseek(fd, %ld, SEEK_%s) = %ld (expected %ld)",
|
||||
offset, (whence == SEEK_DATA ? "DATA" : "HOLE"),
|
||||
seek_offset, expect_offset);
|
||||
if (err != 0)
|
||||
fprintf(stderr, " (errno %d [%s])\n", err, strerror(err));
|
||||
else
|
||||
fputc('\n', stderr);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
static void
|
||||
static inline void
|
||||
seek_data(int fd, off_t offset, off_t expected)
|
||||
{
|
||||
seek_expect(fd, offset, SEEK_DATA, expected);
|
||||
}
|
||||
|
||||
static inline void
|
||||
seek_hole(int fd, off_t offset, off_t expected)
|
||||
{
|
||||
off_t hole_offset = lseek(fd, offset, SEEK_HOLE);
|
||||
if (hole_offset != expected) {
|
||||
fprintf(stderr, "lseek(fd, %d, SEEK_HOLE) = %d (expected %d)\n",
|
||||
(int)offset, (int)hole_offset, (int)expected);
|
||||
exit(2);
|
||||
}
|
||||
seek_expect(fd, offset, SEEK_HOLE, expected);
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Loading…
Reference in New Issue
Block a user