From 98a67b65961adef7f61fa0cdc30178078fb14ff7 Mon Sep 17 00:00:00 2001 From: Milind Changire Date: Wed, 11 Sep 2024 15:39:21 +0530 Subject: [PATCH 1/4] client: return EOPNOTSUPP for fallocate with mode 0 Fixes: https://tracker.ceph.com/issues/68026 Signed-off-by: Milind Changire --- src/client/Client.cc | 2 +- src/pybind/cephfs/cephfs.pyx | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index f687264e167..21555d0d07c 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -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)) diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 793d88b9850..798ea3f902a 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -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. """ From ac34dd33099925172a7d95b267b11e6693cc5648 Mon Sep 17 00:00:00 2001 From: Milind Changire Date: Thu, 19 Sep 2024 09:54:20 +0530 Subject: [PATCH 2/4] PendingReleaseNotes: add note about fallocate mode 0 fallocate now returns EOPNOTSUPP for mode 0 Signed-off-by: Milind Changire --- PendingReleaseNotes | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PendingReleaseNotes b/PendingReleaseNotes index 2381800e8e8..9736a83ddb5 100644 --- a/PendingReleaseNotes +++ b/PendingReleaseNotes @@ -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 From b0690837f31f4d0d357a7d0f73b1f8d4b733b82a Mon Sep 17 00:00:00 2001 From: Milind Changire Date: Tue, 24 Sep 2024 14:06:10 +0530 Subject: [PATCH 3/4] qa: test fallocate fails in mode 0 Signed-off-by: Milind Changire --- qa/workunits/fs/misc/fallocate.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 qa/workunits/fs/misc/fallocate.sh diff --git a/qa/workunits/fs/misc/fallocate.sh b/qa/workunits/fs/misc/fallocate.sh new file mode 100755 index 00000000000..253e6cb7a37 --- /dev/null +++ b/qa/workunits/fs/misc/fallocate.sh @@ -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 From 9244f0a30309077e432b9487ce7b639175afdb1c Mon Sep 17 00:00:00 2001 From: Milind Changire Date: Mon, 30 Sep 2024 15:39:48 +0530 Subject: [PATCH 4/4] test/pybind: update to test_fallocate for mode 0 Signed-off-by: Milind Changire --- src/test/pybind/test_cephfs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/pybind/test_cephfs.py b/src/test/pybind/test_cephfs.py index 3761056efdf..577cb9e4171 100644 --- a/src/test/pybind/test_cephfs.py +++ b/src/test/pybind/test_cephfs.py @@ -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')