]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: fix error handling in lseek SEEK_HOLE/SEEK_DATA cases 34308/head
authorJeff Layton <jlayton@redhat.com>
Thu, 6 Feb 2020 17:00:07 +0000 (12:00 -0500)
committerVicente Cheng <freeze.bilsted@gmail.com>
Thu, 16 Apr 2020 06:14:04 +0000 (06:14 +0000)
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>
(cherry picked from commit 2ca8db71364698e05c3a6ac9a5aa4da5421a35bc)

Conflicts:
src/client/Client.cc
  - minor modification for nautilus code flow

src/client/Client.cc

index f6b1fad4ce5101200e8e3aac92c8395a21bf495b..d91f42b429d1b6178cd0e31c1a03b629e3984e54 100644 (file)
@@ -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: