From: Sage Weil Date: Fri, 11 Mar 2016 16:02:58 +0000 (-0500) Subject: os/filestore: fix punch hole usage in _zero X-Git-Tag: v10.1.0~114^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=400975b09ec4cc46b86cb2216727324e869a3a9b;p=ceph.git os/filestore: fix punch hole usage in _zero 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 --- diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index d6d97728de4a4..fea8618b85176 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -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) {