]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/libcephfs: add test for fsync on a write delegated inode
authorVenky Shankar <vshankar@redhat.com>
Mon, 29 Sep 2025 06:44:28 +0000 (06:44 +0000)
committerVenky Shankar <vshankar@redhat.com>
Tue, 30 Sep 2025 06:59:44 +0000 (06:59 +0000)
Signed-off-by: Venky Shankar <vshankar@redhat.com>
src/test/libcephfs/deleg.cc

index 6fb022846657c2a097c8b53fec259d7532b7925c..05e837ff02a675a6ec4c3471dbb5f1d62844bd2b 100644 (file)
@@ -408,3 +408,42 @@ TEST(LibCephFS, RecalledGetattr) {
   ceph_unmount(cmount1);
   ceph_release(cmount1);
 }
+
+TEST(LibCephFS, DelegTestWithWrite) {
+  struct ceph_mount_info *cmount1;
+  ASSERT_EQ(ceph_create(&cmount1, NULL), 0);
+  ASSERT_EQ(ceph_conf_read_file(cmount1, NULL), 0);
+  ASSERT_EQ(0, ceph_conf_parse_env(cmount1, NULL));
+  ASSERT_EQ(0, ceph_conf_set(cmount1, "client_oc", "0"));
+  ASSERT_EQ(ceph_mount(cmount1, "/"), 0);
+  ASSERT_EQ(set_default_deleg_timeout(cmount1), 0);
+
+  Inode *root, *file;
+  ASSERT_EQ(ceph_ll_lookup_root(cmount1, &root), 0);
+
+  char filename[32];
+  sprintf(filename, "delegtestwrite%x", getpid());
+
+  Fh *fh;
+  struct ceph_statx stx;
+  UserPerm *perms = ceph_mount_perms(cmount1);
+
+  ASSERT_EQ(ceph_ll_create(cmount1, root, filename, 0666,
+                          O_RDWR|O_CREAT|O_EXCL, &file, &fh, &stx, 0, 0, perms), 0);
+  ASSERT_EQ(ceph_ll_write(cmount1, fh, 0, sizeof(filename), filename),
+           static_cast<int>(sizeof(filename)));
+  ASSERT_EQ(ceph_ll_close(cmount1, fh), 0);
+
+  std::atomic_bool recalled(false);
+  ASSERT_EQ(ceph_ll_lookup(cmount1, root, filename, &file, &stx, 0, 0, perms), 0);
+  ASSERT_EQ(ceph_ll_open(cmount1, file, O_WRONLY, &fh, perms), 0);
+  ASSERT_EQ(ceph_ll_delegation_wait(cmount1, fh, CEPH_DELEGATION_WR, dummy_deleg_cb, &recalled), 0);
+  ASSERT_EQ(ceph_ll_write(cmount1, fh, 0, sizeof(filename), filename),
+           static_cast<int>(sizeof(filename)));
+  ASSERT_EQ(0, ceph_ll_fsync(cmount1, fh, false));
+  ASSERT_EQ(ceph_ll_close(cmount1, fh), 0);
+  ASSERT_EQ(0, ceph_ll_unlink(cmount1, root, filename, perms));
+
+  ceph_unmount(cmount1);
+  ceph_release(cmount1);
+}