Merge pull request #59725 from mchangir/mds-fallocate-return-EOPNOTSUPP-for-mode-0

client: return EOPNOTSUPP for fallocate with mode 0

Reviewed-by: Venky Shankar <vshankar@redhat.com>
This commit is contained in:
Venky Shankar 2024-11-04 14:54:59 +05:30 committed by GitHub
commit c8e3946117
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 9 deletions

View File

@ -43,6 +43,10 @@
there are alternative monitoring solutions, like `prometheus`, which is the most
widely adopted among the Ceph user community.
* CephFS: EOPNOTSUPP (Operation not supported ) is now returned by the CephFS
fuse client for `fallocate` for the default case (i.e. mode == 0) since
CephFS does not support disk space reservation. The only flags supported are
`FALLOC_FL_KEEP_SIZE` and `FALLOC_FL_PUNCH_HOLE`.
>=19.0.0

View File

@ -0,0 +1,17 @@
#!/bin/sh -x
# fallocate with mode 0 should fail with EOPNOTSUPP
set -e
mkdir -p testdir
cd testdir
expect_failure() {
if "$@"; then return 1; else return 0; fi
}
expect_failure fallocate -l 1M preallocated.txt
rm -f preallocated.txt
cd ..
rmdir testdir
echo OK

View File

@ -16234,7 +16234,7 @@ int Client::_fallocate(Fh *fh, int mode, int64_t offset, int64_t length)
if (offset < 0 || length <= 0)
return -CEPHFS_EINVAL;
if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
if (mode == 0 || (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)))
return -CEPHFS_EOPNOTSUPP;
if ((mode & FALLOC_FL_PUNCH_HOLE) && !(mode & FALLOC_FL_KEEP_SIZE))

View File

@ -923,12 +923,12 @@ cdef class LibCephFS(object):
:param fd: the file descriptor of the file to fallocate.
:param mode: the flags determines the operation to be performed on the given
range. default operation (0) allocate and initialize to zero
the file in the byte range, and the file size will be changed
if offset + length is greater than the file size. if the
FALLOC_FL_KEEP_SIZE flag is specified in the mode, the file size
will not be changed. if the FALLOC_FL_PUNCH_HOLE flag is specified
in the mode, the operation is deallocate space and zero the byte range.
range. default operation (0) is to return -EOPNOTSUPP since
cephfs does not allocate disk blocks to provide write guarantees.
if the FALLOC_FL_KEEP_SIZE flag is specified in the mode,
the file size will not be changed. if the FALLOC_FL_PUNCH_HOLE
flag is specified in the mode, the operation is deallocate
space and zero the byte range.
:param offset: the byte range starting.
:param length: the length of the range.
"""

View File

@ -610,10 +610,10 @@ def test_ftruncate(testdir):
def test_fallocate(testdir):
fd = cephfs.open(b'/file-fallocate', 'w', 0o755)
assert_raises(TypeError, cephfs.fallocate, b'/file-fallocate', 0, 10)
cephfs.fallocate(fd, 0, 10)
assert_raises(libcephfs.OperationNotSupported, cephfs.fallocate, fd, 0, 10)
stat = cephfs.fsync(fd, 0)
st = cephfs.fstat(fd)
assert_equal(st.st_size, 10)
assert_equal(st.st_size, 0)
cephfs.close(fd)
cephfs.unlink(b'/file-fallocate')