@@ -526,4 +526,88 @@ TEST_F(TestClient, LlreadvLlwritevZeroBytes) {
526526
527527 client->ll_release (fh);
528528 ASSERT_EQ (0 , client->ll_unlink (root, filename, myperm));
529- }
529+ }
530+
531+ TEST_F (TestClient, LlreadvLlwritevInvalidFileHandle) {
532+ /* Test provding null or invalid file handle returns an error
533+ as expected*/
534+
535+ Fh *fh_null = NULL ;
536+
537+ char out_buf_0[] = " hello " ;
538+ char out_buf_1[] = " world\n " ;
539+ struct iovec iov_out[2 ] = {
540+ {out_buf_0, sizeof (out_buf_0)},
541+ {out_buf_1, sizeof (out_buf_1)},
542+ };
543+
544+ char in_buf_0[sizeof (out_buf_0)];
545+ char in_buf_1[sizeof (out_buf_1)];
546+ struct iovec iov_in[2 ] = {
547+ {in_buf_0, sizeof (in_buf_0)},
548+ {in_buf_1, sizeof (in_buf_1)},
549+ };
550+
551+ std::unique_ptr<C_SaferCond> writefinish = nullptr ;
552+ std::unique_ptr<C_SaferCond> readfinish = nullptr ;
553+
554+ writefinish.reset (new C_SaferCond (" test-nonblocking-writefinish-null-fh" ));
555+ readfinish.reset (new C_SaferCond (" test-nonblocking-readfinish-null-fh" ));
556+
557+ int64_t rc;
558+ bufferlist bl;
559+ ssize_t bytes_written = 0 , bytes_read = 0 ;
560+
561+ rc = client->ll_preadv_pwritev (fh_null, iov_out, 2 , 0 , true ,
562+ writefinish.get (), nullptr );
563+ ASSERT_EQ (rc, 0 );
564+ bytes_written = writefinish->wait ();
565+ ASSERT_EQ (bytes_written, -CEPHFS_EBADF);
566+
567+ rc = client->ll_preadv_pwritev (fh_null, iov_in, 2 , 0 , false ,
568+ readfinish.get (), &bl);
569+ ASSERT_EQ (rc, 0 );
570+ bytes_read = readfinish->wait ();
571+ ASSERT_EQ (bytes_read, -CEPHFS_EBADF);
572+ ASSERT_EQ (bl.length (), 0 );
573+
574+ // test after closing the file handle
575+ int mypid = getpid ();
576+ char filename[256 ];
577+
578+ client->unmount ();
579+ TearDown ();
580+ SetUp ();
581+
582+ sprintf (filename, " test_llreadvllwritevinvalidfhfile%u" , mypid);
583+
584+ Inode *root, *file;
585+ root = client->get_root ();
586+ ASSERT_NE (root, (Inode *)NULL );
587+
588+ Fh *fh;
589+ struct ceph_statx stx;
590+
591+ ASSERT_EQ (0 , client->ll_createx (root, filename, 0666 ,
592+ O_RDWR | O_CREAT | O_TRUNC,
593+ &file, &fh, &stx, 0 , 0 , myperm));
594+
595+ client->ll_release (fh);
596+ ASSERT_EQ (0 , client->ll_unlink (root, filename, myperm));
597+
598+ writefinish.reset (new C_SaferCond (" test-nonblocking-writefinish-invalid-fh" ));
599+ readfinish.reset (new C_SaferCond (" test-nonblocking-readfinish-invalid-fh" ));
600+
601+ rc = client->ll_preadv_pwritev (fh, iov_out, 2 , 0 , true , writefinish.get (),
602+ nullptr );
603+ ASSERT_EQ (rc, 0 );
604+ bytes_written = writefinish->wait ();
605+ ASSERT_EQ (bytes_written, -CEPHFS_EBADF);
606+
607+ rc = client->ll_preadv_pwritev (fh, iov_in, 2 , 0 , false , readfinish.get (),
608+ &bl);
609+ ASSERT_EQ (rc, 0 );
610+ bytes_read = readfinish->wait ();
611+ ASSERT_EQ (bytes_read, -CEPHFS_EBADF);
612+ ASSERT_EQ (bl.length (), 0 );
613+ }
0 commit comments