Skip to content

Commit

Permalink
Merge pull request ceph#59725 from mchangir/mds-fallocate-return-EOPN…
Browse files Browse the repository at this point in the history
…OTSUPP-for-mode-0

client: return EOPNOTSUPP for fallocate with mode 0

Reviewed-by: Venky Shankar <[email protected]>
  • Loading branch information
vshankar authored Nov 4, 2024
2 parents 28887e2 + 9244f0a commit c8e3946
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
4 changes: 4 additions & 0 deletions PendingReleaseNotes
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions qa/workunits/fs/misc/fallocate.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/client/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 6 additions & 6 deletions src/pybind/cephfs/cephfs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
4 changes: 2 additions & 2 deletions src/test/pybind/test_cephfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit c8e3946

Please sign in to comment.