]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: add procession of SEEK_HOLE and SEEK_DATA in lseek. 30416/head
authorshenhang <shenhang@kuaishou.com>
Tue, 17 Sep 2019 02:55:21 +0000 (10:55 +0800)
committershenhang <shenhang@kuaishou.com>
Tue, 1 Oct 2019 14:09:40 +0000 (22:09 +0800)
Fixes: https://tracker.ceph.com/issues/42107
Signed-off-by: Shen Hang <harryshen18@gmail.com>
src/client/Client.cc

index 23806511dddea3d52195216337200dddc5de50a3..9240e25c9e15ec7b36deda9603baea3befccedec 100644 (file)
@@ -8906,6 +8906,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;
@@ -8916,12 +8923,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();
   }