]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/libcephfs: test truncate on rdonly fd
authorPatrick Donnelly <pdonnell@redhat.com>
Wed, 11 Nov 2020 19:29:12 +0000 (11:29 -0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Wed, 11 Nov 2020 19:30:37 +0000 (11:30 -0800)
Fixes: https://tracker.ceph.com/issues/48202
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/test/libcephfs/test.cc

index dc4e627eeeee4f53e8a735fb78e545dea1e0f1ef..ef43e1087050aa89a5d9d113544bc611b1e310c7 100644 (file)
@@ -33,6 +33,7 @@
 #include <sys/xattr.h>
 #endif
 
+#include <fmt/format.h>
 #include <map>
 #include <vector>
 #include <thread>
@@ -80,6 +81,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 = fmt::format("test_open_rdt_{}", 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));