Skip to content

Commit

Permalink
client: do more check for the client_lock
Browse files Browse the repository at this point in the history
Fixes: https://tracker.ceph.com/issues/47039
Signed-off-by: Xiubo Li <xiubli@redhat.com>
  • Loading branch information
lxbsz committed Aug 20, 2020
1 parent 49a46ad commit 9fdcb9a
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/client/Client.cc
Expand Up @@ -5785,6 +5785,8 @@ int Client::authenticate()

int Client::fetch_fsmap(bool user)
{
ceph_assert(ceph_mutex_is_locked_by_me(client_lock));

// Retrieve FSMap to enable looking up daemon addresses. We need FSMap
// rather than MDSMap because no one MDSMap contains all the daemons, and
// a `tell` can address any daemon.
Expand Down Expand Up @@ -8362,7 +8364,7 @@ int Client::readdir_r_cb(dir_result_t *d, add_dirent_cb_t cb, void *p,
if (!mref_reader.is_state_satisfied())
return -ENOTCONN;

std::scoped_lock lock(client_lock);
std::unique_lock cl(client_lock);

dir_result_t *dirp = static_cast<dir_result_t*>(d);

Expand Down Expand Up @@ -8399,9 +8401,9 @@ int Client::readdir_r_cb(dir_result_t *d, add_dirent_cb_t cb, void *p,
_ll_get(inode);
}

client_lock.unlock();
cl.unlock();
r = cb(p, &de, &stx, next_off, inode);
client_lock.lock();
cl.lock();
if (r < 0)
return r;

Expand Down Expand Up @@ -8432,9 +8434,9 @@ int Client::readdir_r_cb(dir_result_t *d, add_dirent_cb_t cb, void *p,
_ll_get(inode);
}

client_lock.unlock();
cl.unlock();
r = cb(p, &de, &stx, next_off, inode);
client_lock.lock();
cl.lock();
if (r < 0)
return r;

Expand Down Expand Up @@ -8499,9 +8501,9 @@ int Client::readdir_r_cb(dir_result_t *d, add_dirent_cb_t cb, void *p,
_ll_get(inode);
}

client_lock.unlock();
cl.unlock();
r = cb(p, &de, &stx, next_off, inode); // _next_ offset
client_lock.lock();
cl.lock();

ldout(cct, 15) << " de " << de.d_name << " off " << hex << next_off - 1 << dec
<< " = " << r << dendl;
Expand Down Expand Up @@ -9377,6 +9379,8 @@ int Client::preadv(int fd, const struct iovec *iov, int iovcnt, loff_t offset)

int64_t Client::_read(Fh *f, int64_t offset, uint64_t size, bufferlist *bl)
{
ceph_assert(ceph_mutex_is_locked_by_me(client_lock));

int want, have = 0;
bool movepos = false;
std::unique_ptr<C_SaferCond> onuninline;
Expand Down Expand Up @@ -9533,6 +9537,8 @@ void Client::C_Readahead::finish(int r) {

int Client::_read_async(Fh *f, uint64_t off, uint64_t len, bufferlist *bl)
{
ceph_assert(ceph_mutex_is_locked_by_me(client_lock));

const auto& conf = cct->_conf;
Inode *in = f->inode.get();

Expand Down Expand Up @@ -9767,6 +9773,8 @@ int Client::_preadv_pwritev(int fd, const struct iovec *iov, unsigned iovcnt, in
int64_t Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf,
const struct iovec *iov, int iovcnt)
{
ceph_assert(ceph_mutex_is_locked_by_me(client_lock));

uint64_t fpos = 0;

if ((uint64_t)(offset+size) > mdsmap->get_max_filesize()) //too large!
Expand Down Expand Up @@ -10079,6 +10087,8 @@ int Client::fsync(int fd, bool syncdataonly)

int Client::_fsync(Inode *in, bool syncdataonly)
{
ceph_assert(ceph_mutex_is_locked_by_me(client_lock));

int r = 0;
std::unique_ptr<C_SaferCond> object_cacher_completion = nullptr;
ceph_tid_t flush_tid = 0;
Expand Down Expand Up @@ -10771,6 +10781,8 @@ int Client::test_dentry_handling(bool can_invalidate)

int Client::_sync_fs()
{
ceph_assert(ceph_mutex_is_locked_by_me(client_lock));

ldout(cct, 10) << __func__ << dendl;

// flush file data
Expand Down Expand Up @@ -13845,6 +13857,8 @@ int Client::ll_sync_inode(Inode *in, bool syncdataonly)

int Client::_fallocate(Fh *fh, int mode, int64_t offset, int64_t length)
{
ceph_assert(ceph_mutex_is_locked_by_me(client_lock));

if (offset < 0 || length <= 0)
return -EINVAL;

Expand Down Expand Up @@ -14556,6 +14570,8 @@ enum {

int Client::check_pool_perm(Inode *in, int need)
{
ceph_assert(ceph_mutex_is_locked_by_me(client_lock));

if (!cct->_conf->client_check_pool_perm)
return 0;

Expand Down

0 comments on commit 9fdcb9a

Please sign in to comment.