From cfbc80a4fdc8bcdb877fa8fb63411296fc72b84f Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Mon, 19 Aug 2024 10:03:23 +0000 Subject: [PATCH] client: calls to _ll_fh_exists() should hold client_lock Credit to Brad Hubbard for grabbing the stack trace. Fixes: https://tracker.ceph.com/issues/67565 Signed-off-by: Venky Shankar (cherry picked from commit c37ad2b43738e5f07904cd272cc5417eb617dfa3) --- src/client/Client.cc | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 8dc5208e5c9d..ea13bf600b24 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -15133,6 +15133,10 @@ int Client::ll_read(Fh *fh, loff_t off, loff_t len, bufferlist *bl) return -CEPHFS_ENOTCONN; } + /* We can't return bytes written larger than INT_MAX, clamp len to that */ + len = std::min(len, (loff_t)INT_MAX); + + std::scoped_lock lock(client_lock); if (fh == NULL || !_ll_fh_exists(fh)) { ldout(cct, 3) << "(fh)" << fh << " is invalid" << dendl; return -CEPHFS_EBADF; @@ -15144,10 +15148,6 @@ int Client::ll_read(Fh *fh, loff_t off, loff_t len, bufferlist *bl) tout(cct) << off << std::endl; tout(cct) << len << std::endl; - /* We can't return bytes written larger than INT_MAX, clamp len to that */ - len = std::min(len, (loff_t)INT_MAX); - std::scoped_lock lock(client_lock); - int r = _read(fh, off, len, bl); ldout(cct, 3) << "ll_read " << fh << " " << off << "~" << len << " = " << r << dendl; @@ -15278,6 +15278,10 @@ int Client::ll_write(Fh *fh, loff_t off, loff_t len, const char *data) return -CEPHFS_ENOTCONN; } + /* We can't return bytes written larger than INT_MAX, clamp len to that */ + len = std::min(len, (loff_t)INT_MAX); + + std::scoped_lock lock(client_lock); if (fh == NULL || !_ll_fh_exists(fh)) { ldout(cct, 3) << "(fh)" << fh << " is invalid" << dendl; return -CEPHFS_EBADF; @@ -15290,10 +15294,6 @@ int Client::ll_write(Fh *fh, loff_t off, loff_t len, const char *data) tout(cct) << off << std::endl; tout(cct) << len << std::endl; - /* We can't return bytes written larger than INT_MAX, clamp len to that */ - len = std::min(len, (loff_t)INT_MAX); - std::scoped_lock lock(client_lock); - int r = _write(fh, off, len, data, NULL, 0); ldout(cct, 3) << "ll_write " << fh << " " << off << "~" << len << " = " << r << dendl; @@ -15307,12 +15307,11 @@ int64_t Client::ll_writev(struct Fh *fh, const struct iovec *iov, int iovcnt, in return -CEPHFS_ENOTCONN; } + std::scoped_lock cl(client_lock); if (fh == NULL || !_ll_fh_exists(fh)) { ldout(cct, 3) << "(fh)" << fh << " is invalid" << dendl; return -CEPHFS_EBADF; } - - std::scoped_lock cl(client_lock); return _preadv_pwritev_locked(fh, iov, iovcnt, off, true, false); } @@ -15323,12 +15322,11 @@ int64_t Client::ll_readv(struct Fh *fh, const struct iovec *iov, int iovcnt, int return -CEPHFS_ENOTCONN; } + std::scoped_lock cl(client_lock); if (fh == NULL || !_ll_fh_exists(fh)) { ldout(cct, 3) << "(fh)" << fh << " is invalid" << dendl; return -CEPHFS_EBADF; } - - std::scoped_lock cl(client_lock); return _preadv_pwritev_locked(fh, iov, iovcnt, off, false, false); } -- 2.47.3