From aa40202fcd080ba3e3dda828cd4f9562ac3b4611 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Thu, 6 Feb 2020 12:00:07 -0500 Subject: [PATCH] client: fix error handling in lseek SEEK_HOLE/SEEK_DATA cases The error handling here looks quite wrong. If the offset represents an area outside the file, then we want to just return -ENXIO immediately. Fixes: https://tracker.ceph.com/issues/44021 Signed-off-by: Jeff Layton (cherry picked from commit 2ca8db71364698e05c3a6ac9a5aa4da5421a35bc) Conflicts: src/client/Client.cc - minor modification for nautilus code flow --- src/client/Client.cc | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index f6b1fad4ce510..d91f42b429d1b 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -8880,14 +8880,12 @@ loff_t Client::lseek(int fd, loff_t offset, int whence) loff_t Client::_lseek(Fh *f, loff_t offset, int whence) { Inode *in = f->inode.get(); - int r; loff_t pos = -1; if (whence == SEEK_END || whence == SEEK_DATA || whence == SEEK_HOLE) { - r = _getattr(in, CEPH_STAT_CAP_SIZE, f->actor_perms); - if (r < 0) { + int r = _getattr(in, CEPH_STAT_CAP_SIZE, f->actor_perms); + if (r < 0) return r; - } } switch (whence) { @@ -8904,20 +8902,15 @@ loff_t Client::_lseek(Fh *f, loff_t offset, int whence) break; case SEEK_DATA: - if (offset < 0 || offset >= in->size) { - r = -ENXIO; - return offset; - } + if (offset < 0 || offset >= in->size) + return -ENXIO; pos = offset; break; case SEEK_HOLE: - if (offset < 0 || offset >= in->size) { - r = -ENXIO; - pos = offset; - } else { - pos = in->size; - } + if (offset < 0 || offset >= in->size) + return -ENXIO; + pos = in->size; break; default: -- 2.39.5