Merge pull request #37153 from tchaikov/wip-46124

blk/kernel: use open file description lock if available

Reviewed-by: Igor Fedotov <ifedotov@suse.com>
Reviewed-by: Niklas Hambüchen <mail@nh2.me>
This commit is contained in:
Kefu Chai 2020-09-28 00:10:26 +08:00 committed by GitHub
commit bd7b6718be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 17 deletions

View File

@ -85,25 +85,36 @@ KernelDevice::KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv, ai
int KernelDevice::_lock()
{
dout(10) << __func__ << " " << fd_directs[WRITE_LIFE_NOT_SET] << dendl;
utime_t sleeptime;
sleeptime.set_from_double(cct->_conf->bdev_flock_retry_interval);
// When the block changes, systemd-udevd will open the block,
// read some information and close it. Then a failure occurs here.
// So we need to try again here.
for (int i = 0; i < cct->_conf->bdev_flock_retry + 1; i++) {
int r = ::flock(fd_directs[WRITE_LIFE_NOT_SET], LOCK_EX | LOCK_NB);
if (r < 0 && errno == EAGAIN) {
dout(1) << __func__ << " flock busy on " << path << dendl;
sleeptime.sleep();
} else if (r < 0) {
derr << __func__ << " flock failed on " << path << dendl;
break;
} else {
int fd = fd_directs[WRITE_LIFE_NOT_SET];
uint64_t nr_tries = 0;
for (;;) {
struct flock fl = { F_WRLCK,
SEEK_SET };
int r = ::fcntl(fd, F_OFD_SETLK, &fl);
if (r < 0) {
if (errno == EINVAL) {
r = ::flock(fd, LOCK_EX | LOCK_NB);
}
}
if (r == 0) {
return 0;
}
if (errno != EAGAIN) {
return -errno;
}
dout(1) << __func__ << " flock busy on " << path << dendl;
if (const uint64_t max_retry =
cct->_conf.get_val<uint64_t>("bdev_flock_retry");
max_retry > 0 && nr_tries++ == max_retry) {
return -EAGAIN;
}
double retry_interval =
cct->_conf.get_val<double>("bdev_flock_retry_interval");
std::this_thread::sleep_for(ceph::make_timespan(retry_interval));
}
return -errno;
}
int KernelDevice::open(const string& p)

View File

@ -897,8 +897,6 @@ OPTION(bdev_debug_aio_log_age, OPT_DOUBLE)
OPTION(bdev_nvme_unbind_from_kernel, OPT_BOOL)
OPTION(bdev_enable_discard, OPT_BOOL)
OPTION(bdev_async_discard, OPT_BOOL)
OPTION(bdev_flock_retry_interval, OPT_FLOAT)
OPTION(bdev_flock_retry, OPT_INT)
OPTION(objectstore_blackhole, OPT_BOOL)

View File

@ -4070,9 +4070,13 @@ std::vector<Option> get_global_options() {
.set_default(0.1)
.set_description("interval to retry the flock"),
Option("bdev_flock_retry", Option::TYPE_INT, Option::LEVEL_ADVANCED)
Option("bdev_flock_retry", Option::TYPE_UINT, Option::LEVEL_ADVANCED)
.set_default(3)
.set_description("times to retry the flock"),
.set_description("times to retry the flock")
.set_long_description(
"The number of times to retry on getting the block device lock. "
"Programs such as systemd-udevd may compete with Ceph for this lock. "
"0 means 'unlimited'."),
Option("bluefs_alloc_size", Option::TYPE_SIZE, Option::LEVEL_ADVANCED)
.set_default(1_M)