Skip to content

Commit

Permalink
client: switch to unique_lock to avoid use the client_lock directly
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 Sep 24, 2020
1 parent 1eec274 commit 525a4e8
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/client/Client.cc
Expand Up @@ -8416,7 +8416,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 @@ -8453,9 +8453,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 @@ -8486,9 +8486,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 @@ -8553,9 +8553,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 @@ -9754,8 +9754,9 @@ int Client::pwritev(int fd, const struct iovec *iov, int iovcnt, int64_t offset)
}

int64_t Client::_preadv_pwritev_locked(Fh *fh, const struct iovec *iov,
unsigned iovcnt, int64_t offset, bool write,
bool clamp_to_int)
unsigned iovcnt, int64_t offset,
bool write, bool clamp_to_int,
std::unique_lock<ceph::mutex> &cl)
{
#if defined(__linux__) && defined(O_PATH)
if (fh->flags & O_PATH)
Expand Down Expand Up @@ -9785,7 +9786,6 @@ int64_t Client::_preadv_pwritev_locked(Fh *fh, const struct iovec *iov,
if (r <= 0)
return r;

std::unique_lock cl{client_lock, std::adopt_lock};
cl.unlock();
auto iter = bl.cbegin();
for (unsigned j = 0, resid = r; j < iovcnt && resid > 0; j++) {
Expand All @@ -9799,7 +9799,6 @@ int64_t Client::_preadv_pwritev_locked(Fh *fh, const struct iovec *iov,
/* iter is self-updating */
}
cl.lock();
cl.release();
return r;
}
}
Expand All @@ -9813,11 +9812,11 @@ int Client::_preadv_pwritev(int fd, const struct iovec *iov, unsigned iovcnt, in
tout(cct) << fd << std::endl;
tout(cct) << offset << std::endl;

std::scoped_lock lock(client_lock);
std::unique_lock cl{client_lock};
Fh *fh = get_filehandle(fd);
if (!fh)
return -EBADF;
return _preadv_pwritev_locked(fh, iov, iovcnt, offset, write, true);
return _preadv_pwritev_locked(fh, iov, iovcnt, offset, write, true, cl);
}

int64_t Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf,
Expand Down Expand Up @@ -13848,8 +13847,8 @@ int64_t Client::ll_writev(struct Fh *fh, const struct iovec *iov, int iovcnt, in
if (!mref_reader.is_state_satisfied())
return -ENOTCONN;

std::scoped_lock lock(client_lock);
return _preadv_pwritev_locked(fh, iov, iovcnt, off, true, false);
std::unique_lock cl{client_lock};
return _preadv_pwritev_locked(fh, iov, iovcnt, off, true, false, cl);
}

int64_t Client::ll_readv(struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off)
Expand All @@ -13858,8 +13857,8 @@ int64_t Client::ll_readv(struct Fh *fh, const struct iovec *iov, int iovcnt, int
if (!mref_reader.is_state_satisfied())
return -ENOTCONN;

std::scoped_lock lock(client_lock);
return _preadv_pwritev_locked(fh, iov, iovcnt, off, false, false);
std::unique_lock cl{client_lock};
return _preadv_pwritev_locked(fh, iov, iovcnt, off, false, false, cl);
}

int Client::ll_flush(Fh *fh)
Expand Down

0 comments on commit 525a4e8

Please sign in to comment.