]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
src/test: test async I/O with invalid/closed file handle
authorDhairya Parmar <dparmar@redhat.com>
Mon, 5 Feb 2024 13:38:10 +0000 (19:08 +0530)
committerDhairya Parmar <dparmar@redhat.com>
Sat, 17 Feb 2024 07:48:48 +0000 (13:18 +0530)
Fixes: https://tracker.ceph.com/issues/64313
Signed-off-by: Dhairya Parmar <dparmar@redhat.com>
src/test/client/nonblocking.cc

index 427bf0723ab7d5f3b55419351fac24d6cb93b70c..9b47291cff69e15785de8c54b5842dd37373fd08 100644 (file)
@@ -526,4 +526,88 @@ TEST_F(TestClient, LlreadvLlwritevZeroBytes) {
 
   client->ll_release(fh);
   ASSERT_EQ(0, client->ll_unlink(root, filename, myperm));
-}
\ No newline at end of file
+}
+
+TEST_F(TestClient, LlreadvLlwritevInvalidFileHandle) {
+  /* Test provding null or invalid file handle returns an error
+  as expected*/
+
+  Fh *fh_null = NULL;
+
+  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;
+
+  writefinish.reset(new C_SaferCond("test-nonblocking-writefinish-null-fh"));
+  readfinish.reset(new C_SaferCond("test-nonblocking-readfinish-null-fh"));
+
+  int64_t rc;
+  bufferlist bl;
+  ssize_t bytes_written = 0, bytes_read = 0;
+
+  rc = client->ll_preadv_pwritev(fh_null, iov_out, 2, 0, true,
+                                 writefinish.get(), nullptr);
+  ASSERT_EQ(rc, 0);
+  bytes_written = writefinish->wait();
+  ASSERT_EQ(bytes_written, -CEPHFS_EBADF);
+
+  rc = client->ll_preadv_pwritev(fh_null, iov_in, 2, 0, false,
+                                 readfinish.get(), &bl);
+  ASSERT_EQ(rc, 0);
+  bytes_read = readfinish->wait();
+  ASSERT_EQ(bytes_read, -CEPHFS_EBADF);
+  ASSERT_EQ(bl.length(), 0);
+
+  // test after closing the file handle
+  int mypid = getpid();
+  char filename[256];
+
+  client->unmount();
+  TearDown();
+  SetUp();
+
+  sprintf(filename, "test_llreadvllwritevinvalidfhfile%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_RDWR | O_CREAT | O_TRUNC,
+                                 &file, &fh, &stx, 0, 0, myperm));
+
+  client->ll_release(fh);
+  ASSERT_EQ(0, client->ll_unlink(root, filename, myperm));
+
+  writefinish.reset(new C_SaferCond("test-nonblocking-writefinish-invalid-fh"));
+  readfinish.reset(new C_SaferCond("test-nonblocking-readfinish-invalid-fh"));
+
+  rc = client->ll_preadv_pwritev(fh, iov_out, 2, 0, true, writefinish.get(),
+                                 nullptr);
+  ASSERT_EQ(rc, 0);
+  bytes_written = writefinish->wait();
+  ASSERT_EQ(bytes_written, -CEPHFS_EBADF);
+
+  rc = client->ll_preadv_pwritev(fh, iov_in, 2, 0, false, readfinish.get(),
+                                 &bl);
+  ASSERT_EQ(rc, 0);
+  bytes_read = readfinish->wait();
+  ASSERT_EQ(bytes_read, -CEPHFS_EBADF);
+  ASSERT_EQ(bl.length(), 0);
+}