From 5099c4ef5841c0f80a9ca1844d254ecce25d269b Mon Sep 17 00:00:00 2001 From: Dhairya Parmar Date: Tue, 20 Feb 2024 17:32:45 +0530 Subject: [PATCH] client: check for bad file handle in ll_preadv_pwritev Along with some minor adjustments to the code to make use of same int for all the ops. Fixes: https://tracker.ceph.com/issues/64313 Signed-off-by: Dhairya Parmar --- src/client/Client.cc | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 6ee5e742b9b2c..b999726e479a8 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -15942,23 +15942,34 @@ int64_t Client::ll_preadv_pwritev(struct Fh *fh, const struct iovec *iov, Context *onfinish, bufferlist *bl, bool do_fsync, bool syncdataonly) { + int64_t retval = -1; + RWRef_t mref_reader(mount_state, CLIENT_MOUNTING); if (!mref_reader.is_state_satisfied()) { - int64_t rc = -CEPHFS_ENOTCONN; + retval = -CEPHFS_ENOTCONN; if (onfinish != nullptr) { - onfinish->complete(rc); + onfinish->complete(retval); /* async call should always return zero to caller and allow the caller to wait on callback for the actual errno. */ - rc = 0; + retval = 0; + } + return retval; + } + + if(fh == NULL || !_ll_fh_exists(fh)) { + ldout(cct, 3) << "(fh)" << fh << " is invalid" << dendl; + retval = -CEPHFS_EBADF; + if (onfinish != nullptr) { + onfinish->complete(retval); + retval = 0; } - return rc; + return retval; } std::scoped_lock cl(client_lock); - int64_t retval = _preadv_pwritev_locked(fh, iov, iovcnt, offset, write, - true, onfinish, bl, do_fsync, - syncdataonly); + retval = _preadv_pwritev_locked(fh, iov, iovcnt, offset, write, true, + onfinish, bl, do_fsync, syncdataonly); /* There are two scenarios with each having two cases to handle here 1) async io 1.a) r == 0: -- 2.39.5