]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: add procession of SEEK_HOLE and SEEK_DATA in lseek. 33293/head
authorshenhang <shenhang@kuaishou.com>
Tue, 17 Sep 2019 02:55:21 +0000 (10:55 +0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Fri, 14 Feb 2020 04:47:30 +0000 (20:47 -0800)
Fixes: https://tracker.ceph.com/issues/42107
Signed-off-by: Shen Hang <harryshen18@gmail.com>
(cherry picked from commit 394720ca6b731e4698f1dbc7896d294363ecb466)

src/client/Client.cc

index 5fb2e8db3c73a18a7b0c42cf3f8b94720cf1872c..cf68e7b0ec4764e8c342052bbdc980c9c2ccffca 100644 (file)
@@ -8731,6 +8731,13 @@ loff_t Client::_lseek(Fh *f, loff_t offset, int whence)
   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) {
+      return r;
+    }
+  }
+
   switch (whence) {
   case SEEK_SET:
     pos = offset;
@@ -8741,12 +8748,26 @@ loff_t Client::_lseek(Fh *f, loff_t offset, int whence)
     break;
 
   case SEEK_END:
-    r = _getattr(in, CEPH_STAT_CAP_SIZE, f->actor_perms);
-    if (r < 0)
-      return r;
     pos = in->size + offset;
     break;
 
+  case SEEK_DATA:
+    if (offset < 0 || offset >= in->size) {
+      r = -ENXIO;
+      return offset; 
+    }
+    pos = offset;
+    break;
+
+  case SEEK_HOLE:
+    if (offset < 0 || offset >= in->size) {
+      r = -ENXIO;
+      pos = offset; 
+    } else {
+      pos = in->size;
+    }
+    break;
+
   default:
     ceph_abort();
   }