]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
client: fix error handling in lseek SEEK_HOLE/SEEK_DATA cases
authorJeff Layton <jlayton@redhat.com>
Thu, 6 Feb 2020 17:00:07 +0000 (12:00 -0500)
committerJeff Layton <jlayton@redhat.com>
Mon, 24 Feb 2020 19:39:12 +0000 (11:39 -0800)
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 <jlayton@redhat.com>
src/client/Client.cc

index 737bfabe67f71329496ffa4f5cffd6acee964ed3..b55973a03222711d08e7f77f41cb48dbd4ffb4d4 100644 (file)
@@ -8907,7 +8907,6 @@ 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;
   bool whence_check = false;
   loff_t pos = -1;
 
@@ -8930,10 +8929,9 @@ loff_t Client::_lseek(Fh *f, loff_t offset, int whence)
   }
 
   if (whence_check) {
-    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) {
@@ -8951,22 +8949,17 @@ loff_t Client::_lseek(Fh *f, loff_t offset, int whence)
 
 #ifdef SEEK_DATA
   case SEEK_DATA:
-    if (offset < 0 || static_cast<uint64_t>(offset) >= in->size) {
-      r = -ENXIO;
-      return offset; 
-    }
+    if (offset < 0 || static_cast<uint64_t>(offset) >= in->size)
+      return -ENXIO;
     pos = offset;
     break;
 #endif
 
 #ifdef SEEK_HOLE
   case SEEK_HOLE:
-    if (offset < 0 || static_cast<uint64_t>(offset) >= in->size) {
-      r = -ENXIO;
-      pos = offset; 
-    } else {
-      pos = in->size;
-    }
+    if (offset < 0 || static_cast<uint64_t>(offset) >= in->size)
+      return -ENXIO;
+    pos = in->size;
     break;
 #endif