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>
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) {