]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/filestore: fix punch hole usage in _zero
authorSage Weil <sage@redhat.com>
Fri, 11 Mar 2016 16:02:58 +0000 (11:02 -0500)
committerSage Weil <sage@redhat.com>
Fri, 11 Mar 2016 16:02:58 +0000 (11:02 -0500)
If we punch a hole that extends past EOF, ObjectStore semantics are
that the file size is also extended.  Do that.

Note that this bug was hidden before because we weren't passing
KEEP_SIZE to fallocate until 7bd95b595fddb8a4e618a2c7df1ba04eccf0829d
and the fallocate was *always* failing with EOPNOTSUPP (making us fall
back to writing actual zeros).

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/filestore/FileStore.cc

index d6d97728de4a48892f455b4045c844c06713307d..fea8618b85176f0eadbec8d72c758961dc885057 100644 (file)
@@ -3249,10 +3249,29 @@ int FileStore::_zero(const coll_t& cid, const ghobject_t& oid, uint64_t offset,
     goto out;
   }
 
+  struct stat st;
+  ret = ::fstat(**fd, &st);
+  if (ret < 0) {
+    ret = -errno;
+    lfn_close(fd);
+    goto out;
+  }
+
   // first try fallocate
   ret = fallocate(**fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, offset, len);
-  if (ret < 0)
+  if (ret < 0) {
     ret = -errno;
+  } else {
+    // ensure we extent file size, if needed
+    if (offset + len > st.st_size) {
+      ret = ::ftruncate(**fd, offset + len);
+      if (ret < 0) {
+       ret = -errno;
+       lfn_close(fd);
+       goto out;
+      }
+    }
+  }
   lfn_close(fd);
 
   if (ret >= 0 && m_filestore_sloppy_crc) {