Skip to content

Commit 704d4f6

Browse files
committed
Merge PR ceph#59300 into main
* refs/pull/59300/head: client: calls to _ll_fh_exists() should hold client_lock Reviewed-by: Xiubo Li <xiubli@redhat.com> Reviewed-by: Dhairya Parmar <dparmar@redhat.com>
2 parents f597caa + c37ad2b commit 704d4f6

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/client/Client.cc

+20-16
Original file line numberDiff line numberDiff line change
@@ -15836,6 +15836,10 @@ int Client::ll_read(Fh *fh, loff_t off, loff_t len, bufferlist *bl)
1583615836
return -CEPHFS_ENOTCONN;
1583715837
}
1583815838

15839+
/* We can't return bytes written larger than INT_MAX, clamp len to that */
15840+
len = std::min(len, (loff_t)INT_MAX);
15841+
15842+
std::scoped_lock lock(client_lock);
1583915843
if (fh == NULL || !_ll_fh_exists(fh)) {
1584015844
ldout(cct, 3) << "(fh)" << fh << " is invalid" << dendl;
1584115845
return -CEPHFS_EBADF;
@@ -15847,10 +15851,6 @@ int Client::ll_read(Fh *fh, loff_t off, loff_t len, bufferlist *bl)
1584715851
tout(cct) << off << std::endl;
1584815852
tout(cct) << len << std::endl;
1584915853

15850-
/* We can't return bytes written larger than INT_MAX, clamp len to that */
15851-
len = std::min(len, (loff_t)INT_MAX);
15852-
std::scoped_lock lock(client_lock);
15853-
1585415854
int r = _read(fh, off, len, bl);
1585515855
ldout(cct, 3) << "ll_read " << fh << " " << off << "~" << len << " = " << r
1585615856
<< dendl;
@@ -15981,6 +15981,10 @@ int Client::ll_write(Fh *fh, loff_t off, loff_t len, const char *data)
1598115981
return -CEPHFS_ENOTCONN;
1598215982
}
1598315983

15984+
/* We can't return bytes written larger than INT_MAX, clamp len to that */
15985+
len = std::min(len, (loff_t)INT_MAX);
15986+
15987+
std::scoped_lock lock(client_lock);
1598415988
if (fh == NULL || !_ll_fh_exists(fh)) {
1598515989
ldout(cct, 3) << "(fh)" << fh << " is invalid" << dendl;
1598615990
return -CEPHFS_EBADF;
@@ -15993,10 +15997,6 @@ int Client::ll_write(Fh *fh, loff_t off, loff_t len, const char *data)
1599315997
tout(cct) << off << std::endl;
1599415998
tout(cct) << len << std::endl;
1599515999

15996-
/* We can't return bytes written larger than INT_MAX, clamp len to that */
15997-
len = std::min(len, (loff_t)INT_MAX);
15998-
std::scoped_lock lock(client_lock);
15999-
1600016000
int r = _write(fh, off, len, data, NULL, 0);
1600116001
ldout(cct, 3) << "ll_write " << fh << " " << off << "~" << len << " = " << r
1600216002
<< dendl;
@@ -16010,12 +16010,11 @@ int64_t Client::ll_writev(struct Fh *fh, const struct iovec *iov, int iovcnt, in
1601016010
return -CEPHFS_ENOTCONN;
1601116011
}
1601216012

16013+
std::scoped_lock cl(client_lock);
1601316014
if (fh == NULL || !_ll_fh_exists(fh)) {
1601416015
ldout(cct, 3) << "(fh)" << fh << " is invalid" << dendl;
1601516016
return -CEPHFS_EBADF;
1601616017
}
16017-
16018-
std::scoped_lock cl(client_lock);
1601916018
return _preadv_pwritev_locked(fh, iov, iovcnt, off, true, false);
1602016019
}
1602116020

@@ -16026,12 +16025,11 @@ int64_t Client::ll_readv(struct Fh *fh, const struct iovec *iov, int iovcnt, int
1602616025
return -CEPHFS_ENOTCONN;
1602716026
}
1602816027

16028+
std::scoped_lock cl(client_lock);
1602916029
if (fh == NULL || !_ll_fh_exists(fh)) {
1603016030
ldout(cct, 3) << "(fh)" << fh << " is invalid" << dendl;
1603116031
return -CEPHFS_EBADF;
1603216032
}
16033-
16034-
std::scoped_lock cl(client_lock);
1603516033
return _preadv_pwritev_locked(fh, iov, iovcnt, off, false, false);
1603616034
}
1603716035

@@ -16054,18 +16052,24 @@ int64_t Client::ll_preadv_pwritev(struct Fh *fh, const struct iovec *iov,
1605416052
return retval;
1605516053
}
1605616054

16055+
retval = 0;
16056+
std::unique_lock cl(client_lock);
16057+
1605716058
if(fh == NULL || !_ll_fh_exists(fh)) {
1605816059
ldout(cct, 3) << "(fh)" << fh << " is invalid" << dendl;
1605916060
retval = -CEPHFS_EBADF;
16061+
}
16062+
16063+
if (retval != 0) {
1606016064
if (onfinish != nullptr) {
16065+
cl.unlock();
1606116066
onfinish->complete(retval);
16067+
cl.lock();
1606216068
retval = 0;
1606316069
}
1606416070
return retval;
1606516071
}
1606616072

16067-
std::scoped_lock cl(client_lock);
16068-
1606916073
retval = _preadv_pwritev_locked(fh, iov, iovcnt, offset, write, true,
1607016074
onfinish, bl, do_fsync, syncdataonly);
1607116075
/* There are two scenarios with each having two cases to handle here
@@ -16086,9 +16090,9 @@ int64_t Client::ll_preadv_pwritev(struct Fh *fh, const struct iovec *iov,
1608616090
if (retval < 0) {
1608716091
if (onfinish != nullptr) {
1608816092
//async io failed
16089-
client_lock.unlock();
16093+
cl.unlock();
1609016094
onfinish->complete(retval);
16091-
client_lock.lock();
16095+
cl.lock();
1609216096
/* async call should always return zero to caller and allow the
1609316097
caller to wait on callback for the actual errno/retval. */
1609416098
retval = 0;

0 commit comments

Comments
 (0)