From: Patrick Donnelly Date: Wed, 11 Nov 2020 19:29:12 +0000 (-0800) Subject: test/libcephfs: test truncate on rdonly fd X-Git-Tag: v14.2.17~27^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=180e63fa1bcdd95701c5ef6e09783fe05c5c4a33;p=ceph.git test/libcephfs: test truncate on rdonly fd Fixes: https://tracker.ceph.com/issues/48202 Signed-off-by: Patrick Donnelly (cherry picked from commit 2b41ddf343e8e314dc60fae0d5f4e007ce3857e4) Conflicts: src/test/libcephfs/test.cc - rewrite a trivial string + int concatenation to eliminate fmt::format --- diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index e4998d0a92c5..fb7292e342b2 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -76,6 +76,30 @@ TEST(LibCephFS, OpenEmptyComponent) { ceph_shutdown(cmount); } +TEST(LibCephFS, OpenReadTruncate) { + struct ceph_mount_info *cmount; + ASSERT_EQ(0, ceph_create(&cmount, NULL)); + ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL)); + ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); + ASSERT_EQ(0, ceph_mount(cmount, "/")); + + auto path = "test_open_rdt_" + std::to_string(getpid()); + int fd = ceph_open(cmount, path.c_str(), O_WRONLY|O_CREAT, 0666); + ASSERT_LE(0, fd); + + auto data = std::string("hello world"); + ASSERT_EQ(ceph_write(cmount, fd, data.c_str(), data.size(), 0), (int)data.size()); + ASSERT_EQ(0, ceph_close(cmount, fd)); + + fd = ceph_open(cmount, path.c_str(), O_RDONLY, 0); + ASSERT_LE(0, fd); + ASSERT_EQ(ceph_ftruncate(cmount, fd, 0), -EBADF); + ASSERT_EQ(ceph_ftruncate(cmount, fd, 1), -EBADF); + ASSERT_EQ(0, ceph_close(cmount, fd)); + + ceph_shutdown(cmount); +} + TEST(LibCephFS, OpenReadWrite) { struct ceph_mount_info *cmount; ASSERT_EQ(0, ceph_create(&cmount, NULL));