From 451c15fcb72e09afba499f188eb6e03ced49b1ca Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 28 Oct 2021 00:41:55 -0700 Subject: [PATCH] cp: attempt to work around ZFS bug * src/copy.c (infer_scantype): Attempt a partial workaround for a Linux file system bug (see Bug#51433). --- src/copy.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/copy.c b/src/copy.c index cb9018f93..6f4566d9f 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1097,6 +1097,16 @@ infer_scantype (int fd, struct stat const *sb, #ifdef SEEK_HOLE scan_inference->ext_start = lseek (fd, 0, SEEK_DATA); + + /* If lseek fails with ENXIO, it may be a Linux file system bug + . Try to work around it by + fdatasyncing the input and then retrying the lseek. */ + if (scan_inference->ext_start < 0 && errno == ENXIO) + { + fdatasync (fd); + scan_inference->ext_start = lseek (fd, 0, SEEK_DATA); + } + if (0 <= scan_inference->ext_start) return LSEEK_SCANTYPE; else if (errno != EINVAL && !is_ENOTSUP (errno)) -- 2.31.1