@@ -15779,8 +15779,14 @@ loff_t Client::ll_lseek(Fh *fh, loff_t offset, int whence)
1577915779int Client::ll_read (Fh *fh, loff_t off, loff_t len, bufferlist *bl)
1578015780{
1578115781 RWRef_t mref_reader (mount_state, CLIENT_MOUNTING);
15782- if (!mref_reader.is_state_satisfied ())
15782+ if (!mref_reader.is_state_satisfied ()) {
1578315783 return -CEPHFS_ENOTCONN;
15784+ }
15785+
15786+ if (fh == NULL || !_ll_fh_exists (fh)) {
15787+ ldout (cct, 3 ) << " (fh)" << fh << " is invalid" << dendl;
15788+ return -CEPHFS_EBADF;
15789+ }
1578415790
1578515791 ldout (cct, 3 ) << " ll_read " << fh << " " << fh->inode ->ino << " " << " " << off << " ~" << len << dendl;
1578615792 tout (cct) << " ll_read" << std::endl;
@@ -15917,17 +15923,23 @@ int Client::ll_commit_blocks(Inode *in,
1591715923
1591815924int Client::ll_write (Fh *fh, loff_t off, loff_t len, const char *data)
1591915925{
15926+ RWRef_t mref_reader (mount_state, CLIENT_MOUNTING);
15927+ if (!mref_reader.is_state_satisfied ()) {
15928+ return -CEPHFS_ENOTCONN;
15929+ }
15930+
15931+ if (fh == NULL || !_ll_fh_exists (fh)) {
15932+ ldout (cct, 3 ) << " (fh)" << fh << " is invalid" << dendl;
15933+ return -CEPHFS_EBADF;
15934+ }
15935+
1592015936 ldout (cct, 3 ) << " ll_write " << fh << " " << fh->inode ->ino << " " << off <<
1592115937 " ~" << len << dendl;
1592215938 tout (cct) << " ll_write" << std::endl;
1592315939 tout (cct) << (uintptr_t )fh << std::endl;
1592415940 tout (cct) << off << std::endl;
1592515941 tout (cct) << len << std::endl;
1592615942
15927- RWRef_t mref_reader (mount_state, CLIENT_MOUNTING);
15928- if (!mref_reader.is_state_satisfied ())
15929- return -CEPHFS_ENOTCONN;
15930-
1593115943 /* We can't return bytes written larger than INT_MAX, clamp len to that */
1593215944 len = std::min (len, (loff_t )INT_MAX);
1593315945 std::scoped_lock lock (client_lock);
@@ -15941,8 +15953,14 @@ int Client::ll_write(Fh *fh, loff_t off, loff_t len, const char *data)
1594115953int64_t Client::ll_writev (struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off)
1594215954{
1594315955 RWRef_t mref_reader (mount_state, CLIENT_MOUNTING);
15944- if (!mref_reader.is_state_satisfied ())
15956+ if (!mref_reader.is_state_satisfied ()) {
1594515957 return -CEPHFS_ENOTCONN;
15958+ }
15959+
15960+ if (fh == NULL || !_ll_fh_exists (fh)) {
15961+ ldout (cct, 3 ) << " (fh)" << fh << " is invalid" << dendl;
15962+ return -CEPHFS_EBADF;
15963+ }
1594615964
1594715965 std::scoped_lock cl (client_lock);
1594815966 return _preadv_pwritev_locked (fh, iov, iovcnt, off, true , false );
@@ -15951,8 +15969,14 @@ int64_t Client::ll_writev(struct Fh *fh, const struct iovec *iov, int iovcnt, in
1595115969int64_t Client::ll_readv (struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off)
1595215970{
1595315971 RWRef_t mref_reader (mount_state, CLIENT_MOUNTING);
15954- if (!mref_reader.is_state_satisfied ())
15972+ if (!mref_reader.is_state_satisfied ()) {
1595515973 return -CEPHFS_ENOTCONN;
15974+ }
15975+
15976+ if (fh == NULL || !_ll_fh_exists (fh)) {
15977+ ldout (cct, 3 ) << " (fh)" << fh << " is invalid" << dendl;
15978+ return -CEPHFS_EBADF;
15979+ }
1595615980
1595715981 std::scoped_lock cl (client_lock);
1595815982 return _preadv_pwritev_locked (fh, iov, iovcnt, off, false , false );
@@ -15963,23 +15987,34 @@ int64_t Client::ll_preadv_pwritev(struct Fh *fh, const struct iovec *iov,
1596315987 Context *onfinish, bufferlist *bl,
1596415988 bool do_fsync, bool syncdataonly)
1596515989{
15990+ int64_t retval = -1 ;
15991+
1596615992 RWRef_t mref_reader (mount_state, CLIENT_MOUNTING);
1596715993 if (!mref_reader.is_state_satisfied ()) {
15968- int64_t rc = -CEPHFS_ENOTCONN;
15994+ retval = -CEPHFS_ENOTCONN;
1596915995 if (onfinish != nullptr ) {
15970- onfinish->complete (rc );
15996+ onfinish->complete (retval );
1597115997 /* async call should always return zero to caller and allow the
1597215998 caller to wait on callback for the actual errno. */
15973- rc = 0 ;
15999+ retval = 0 ;
16000+ }
16001+ return retval;
16002+ }
16003+
16004+ if (fh == NULL || !_ll_fh_exists (fh)) {
16005+ ldout (cct, 3 ) << " (fh)" << fh << " is invalid" << dendl;
16006+ retval = -CEPHFS_EBADF;
16007+ if (onfinish != nullptr ) {
16008+ onfinish->complete (retval);
16009+ retval = 0 ;
1597416010 }
15975- return rc ;
16011+ return retval ;
1597616012 }
1597716013
1597816014 std::scoped_lock cl (client_lock);
1597916015
15980- int64_t retval = _preadv_pwritev_locked (fh, iov, iovcnt, offset, write,
15981- true , onfinish, bl, do_fsync,
15982- syncdataonly);
16016+ retval = _preadv_pwritev_locked (fh, iov, iovcnt, offset, write, true ,
16017+ onfinish, bl, do_fsync, syncdataonly);
1598316018 /* There are two scenarios with each having two cases to handle here
1598416019 1) async io
1598516020 1.a) r == 0:
0 commit comments