Skip to content

Commit c8e3946

Browse files
authored
Merge pull request ceph#59725 from mchangir/mds-fallocate-return-EOPNOTSUPP-for-mode-0
client: return EOPNOTSUPP for fallocate with mode 0 Reviewed-by: Venky Shankar <[email protected]>
2 parents 28887e2 + 9244f0a commit c8e3946

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

PendingReleaseNotes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
there are alternative monitoring solutions, like `prometheus`, which is the most
4444
widely adopted among the Ceph user community.
4545

46+
* CephFS: EOPNOTSUPP (Operation not supported ) is now returned by the CephFS
47+
fuse client for `fallocate` for the default case (i.e. mode == 0) since
48+
CephFS does not support disk space reservation. The only flags supported are
49+
`FALLOC_FL_KEEP_SIZE` and `FALLOC_FL_PUNCH_HOLE`.
4650

4751
>=19.0.0
4852

qa/workunits/fs/misc/fallocate.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh -x
2+
3+
# fallocate with mode 0 should fail with EOPNOTSUPP
4+
set -e
5+
mkdir -p testdir
6+
cd testdir
7+
8+
expect_failure() {
9+
if "$@"; then return 1; else return 0; fi
10+
}
11+
12+
expect_failure fallocate -l 1M preallocated.txt
13+
rm -f preallocated.txt
14+
15+
cd ..
16+
rmdir testdir
17+
echo OK

src/client/Client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16234,7 +16234,7 @@ int Client::_fallocate(Fh *fh, int mode, int64_t offset, int64_t length)
1623416234
if (offset < 0 || length <= 0)
1623516235
return -CEPHFS_EINVAL;
1623616236

16237-
if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
16237+
if (mode == 0 || (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)))
1623816238
return -CEPHFS_EOPNOTSUPP;
1623916239

1624016240
if ((mode & FALLOC_FL_PUNCH_HOLE) && !(mode & FALLOC_FL_KEEP_SIZE))

src/pybind/cephfs/cephfs.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -923,12 +923,12 @@ cdef class LibCephFS(object):
923923
924924
:param fd: the file descriptor of the file to fallocate.
925925
:param mode: the flags determines the operation to be performed on the given
926-
range. default operation (0) allocate and initialize to zero
927-
the file in the byte range, and the file size will be changed
928-
if offset + length is greater than the file size. if the
929-
FALLOC_FL_KEEP_SIZE flag is specified in the mode, the file size
930-
will not be changed. if the FALLOC_FL_PUNCH_HOLE flag is specified
931-
in the mode, the operation is deallocate space and zero the byte range.
926+
range. default operation (0) is to return -EOPNOTSUPP since
927+
cephfs does not allocate disk blocks to provide write guarantees.
928+
if the FALLOC_FL_KEEP_SIZE flag is specified in the mode,
929+
the file size will not be changed. if the FALLOC_FL_PUNCH_HOLE
930+
flag is specified in the mode, the operation is deallocate
931+
space and zero the byte range.
932932
:param offset: the byte range starting.
933933
:param length: the length of the range.
934934
"""

src/test/pybind/test_cephfs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,10 @@ def test_ftruncate(testdir):
610610
def test_fallocate(testdir):
611611
fd = cephfs.open(b'/file-fallocate', 'w', 0o755)
612612
assert_raises(TypeError, cephfs.fallocate, b'/file-fallocate', 0, 10)
613-
cephfs.fallocate(fd, 0, 10)
613+
assert_raises(libcephfs.OperationNotSupported, cephfs.fallocate, fd, 0, 10)
614614
stat = cephfs.fsync(fd, 0)
615615
st = cephfs.fstat(fd)
616-
assert_equal(st.st_size, 10)
616+
assert_equal(st.st_size, 0)
617617
cephfs.close(fd)
618618
cephfs.unlink(b'/file-fallocate')
619619

0 commit comments

Comments
 (0)