]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
src/test: test async I/O with read only file
authorDhairya Parmar <dparmar@redhat.com>
Wed, 6 Dec 2023 09:48:55 +0000 (15:18 +0530)
committerDhairya Parmar <dparmar@redhat.com>
Tue, 30 Jan 2024 09:20:56 +0000 (14:50 +0530)
Fixes: https://tracker.ceph.com/issues/63648
Signed-off-by: Dhairya Parmar <dparmar@redhat.com>
src/test/client/nonblocking.cc

index c50d299ec8488bb695e6a876489f159ff29eb13e..4b689dd868794d26a93c99bf12f1be16b2726b73 100644 (file)
@@ -271,4 +271,67 @@ TEST_F(TestClient, LlreadvLlwritevOPathFileHandle) {
 
   client->ll_release(fh);
   ASSERT_EQ(0, client->ll_unlink(root, filename, myperm));
-}
\ No newline at end of file
+}
+
+TEST_F(TestClient, LlreadvLlwritevReadOnlyFile) {
+  /* Test async I/O with read only file*/
+
+  int mypid = getpid();
+  char filename[256];
+
+  client->unmount();
+  TearDown();
+  SetUp();
+
+  sprintf(filename, "test_llreadvllwritevreadonlyfile%u", mypid);
+
+  Inode *root, *file;
+  root = client->get_root();
+  ASSERT_NE(root, (Inode *)NULL);
+
+  Fh *fh;
+  struct ceph_statx stx;
+
+  ASSERT_EQ(0, client->ll_createx(root, filename, 0666,
+          O_RDONLY | O_CREAT | O_TRUNC,
+          &file, &fh, &stx, 0, 0, myperm));
+
+  char out_buf_0[] = "hello ";
+  char out_buf_1[] = "world\n";
+  struct iovec iov_out[2] = {
+    {out_buf_0, sizeof(out_buf_0)},
+    {out_buf_1, sizeof(out_buf_1)},
+  };
+
+  char in_buf_0[sizeof(out_buf_0)];
+  char in_buf_1[sizeof(out_buf_1)];
+  struct iovec iov_in[2] = {
+    {in_buf_0, sizeof(in_buf_0)},
+    {in_buf_1, sizeof(in_buf_1)},
+  };
+
+  std::unique_ptr<C_SaferCond> writefinish = nullptr;
+  std::unique_ptr<C_SaferCond> readfinish = nullptr;
+
+  int64_t rc;
+  bufferlist bl;
+
+  writefinish.reset(new C_SaferCond("test-nonblocking-writefinish-read-only"));
+  readfinish.reset(new C_SaferCond("test-nonblocking-readfinish-read-only"));
+
+  rc = client->ll_preadv_pwritev(fh, iov_out, 2, 0, true, writefinish.get(),
+                                 nullptr);
+  ASSERT_EQ(rc, 0);
+  rc = writefinish->wait();
+  ASSERT_EQ(rc, -CEPHFS_EBADF);
+
+  rc = client->ll_preadv_pwritev(fh, iov_in, 2, 0, false, readfinish.get(),
+                                 &bl);
+  ASSERT_EQ(rc, 0);
+  rc = readfinish->wait();
+  ASSERT_EQ(rc, 0);
+  ASSERT_EQ(bl.length(), 0);
+
+  client->ll_release(fh);
+  ASSERT_EQ(0, client->ll_unlink(root, filename, myperm));
+}