}
}
+static int ceph_ll_delegation_wait(struct ceph_mount_info *cmount, Fh *fh,
+ unsigned cmd, ceph_deleg_cb_t cb, void *priv)
+{
+ int ret, retry = 0;
+
+ /* Wait 10s at most */
+ do {
+ ret = ceph_ll_delegation(cmount, fh, cmd, cb, priv);
+ usleep(10000);
+ } while (ret == -EAGAIN && retry++ < 1000);
+
+ return ret;
+}
+
static int set_default_deleg_timeout(struct ceph_mount_info *cmount)
{
uint32_t session_timeout = ceph_get_cap_return_timeout(cmount);
sprintf(filename, "deleg.rwrw.%x", getpid());
ASSERT_EQ(ceph_ll_create(cmount, root, filename, 0666,
O_RDWR|O_CREAT|O_EXCL, &file, &fh, &stx, 0, 0, perms), 0);
- ASSERT_EQ(ceph_ll_delegation(cmount, fh, CEPH_DELEGATION_WR, dummy_deleg_cb, &recalled), 0);
+ ASSERT_EQ(ceph_ll_delegation_wait(cmount, fh, CEPH_DELEGATION_WR, dummy_deleg_cb, &recalled), 0);
std::thread breaker1(open_breaker_func, tcmount, filename, O_RDWR, &opened);
wait_for_atomic_bool(recalled);
sprintf(filename, "deleg.rorw.%x", getpid());
ASSERT_EQ(ceph_ll_create(cmount, root, filename, 0666,
O_RDWR|O_CREAT|O_EXCL, &file, &fh, &stx, 0, 0, perms), 0);
- ASSERT_EQ(ceph_ll_delegation(cmount, fh, CEPH_DELEGATION_WR, dummy_deleg_cb, &recalled), 0);
+ ASSERT_EQ(ceph_ll_delegation_wait(cmount, fh, CEPH_DELEGATION_WR, dummy_deleg_cb, &recalled), 0);
std::thread breaker2(open_breaker_func, tcmount, filename, O_RDONLY, &opened);
wait_for_atomic_bool(recalled);
ASSERT_EQ(opened.load(), false);
ASSERT_EQ(ceph_ll_create(cmount, root, filename, 0666,
O_RDONLY|O_CREAT|O_EXCL, &file, &fh, &stx, 0, 0, perms), 0);
recalled.store(false);
- ASSERT_EQ(ceph_ll_delegation(cmount, fh, CEPH_DELEGATION_RD, dummy_deleg_cb, &recalled), 0);
+ ASSERT_EQ(ceph_ll_delegation_wait(cmount, fh, CEPH_DELEGATION_RD, dummy_deleg_cb, &recalled), 0);
std::thread breaker3(open_breaker_func, tcmount, filename, O_RDONLY, &opened);
breaker3.join();
ASSERT_EQ(recalled.load(), false);
sprintf(newname, "deleg.new.%x", getpid());
ASSERT_EQ(ceph_ll_create(cmount, root, filename, 0666,
O_RDWR|O_CREAT|O_EXCL, &file, &fh, &stx, 0, 0, perms), 0);
- ASSERT_EQ(ceph_ll_delegation(cmount, fh, CEPH_DELEGATION_WR, dummy_deleg_cb, &recalled), 0);
+ ASSERT_EQ(ceph_ll_delegation_wait(cmount, fh, CEPH_DELEGATION_WR, dummy_deleg_cb, &recalled), 0);
std::thread breaker5(namespace_breaker_func, tcmount, DelegTestLink, filename, newname);
wait_for_atomic_bool(recalled);
ASSERT_EQ(ceph_ll_delegation(cmount, fh, CEPH_DELEGATION_NONE, dummy_deleg_cb, &recalled), 0);
recalled.store(false);
ASSERT_EQ(ceph_ll_create(cmount, root, filename, 0666,
O_RDWR|O_CREAT|O_EXCL, &file, &fh, &stx, 0, 0, perms), 0);
- ASSERT_EQ(ceph_ll_delegation(cmount, fh, CEPH_DELEGATION_WR, dummy_deleg_cb, &recalled), 0);
+ ASSERT_EQ(ceph_ll_delegation_wait(cmount, fh, CEPH_DELEGATION_WR, dummy_deleg_cb, &recalled), 0);
std::thread breaker6(namespace_breaker_func, tcmount, DelegTestRename, filename, newname);
wait_for_atomic_bool(recalled);
ASSERT_EQ(ceph_ll_delegation(cmount, fh, CEPH_DELEGATION_NONE, dummy_deleg_cb, &recalled), 0);
recalled.store(false);
ASSERT_EQ(ceph_ll_create(cmount, root, filename, 0666,
O_RDWR|O_CREAT|O_EXCL, &file, &fh, &stx, 0, 0, perms), 0);
- ASSERT_EQ(ceph_ll_delegation(cmount, fh, CEPH_DELEGATION_WR, dummy_deleg_cb, &recalled), 0);
+ ASSERT_EQ(ceph_ll_delegation_wait(cmount, fh, CEPH_DELEGATION_WR, dummy_deleg_cb, &recalled), 0);
std::thread breaker7(namespace_breaker_func, tcmount, DelegTestUnlink, filename, nullptr);
wait_for_atomic_bool(recalled);
ASSERT_EQ(ceph_ll_delegation(cmount, fh, CEPH_DELEGATION_NONE, dummy_deleg_cb, &recalled), 0);
ASSERT_EQ(ceph_ll_open(cmount, file, O_RDONLY, &fh, perms), 0);
std::atomic_bool recalled(false);
- ASSERT_EQ(ceph_ll_delegation(cmount, fh, CEPH_DELEGATION_RD, dummy_deleg_cb, &recalled), 0);
+ ASSERT_EQ(ceph_ll_delegation_wait(cmount, fh, CEPH_DELEGATION_RD, dummy_deleg_cb, &recalled), 0);
std::atomic_bool opened(false);
std::thread breaker1(open_breaker_func, nullptr, filename, O_RDWR, &opened);
breaker1.join();
/* Break delegation */
std::atomic_bool recalled(false);
- ASSERT_EQ(ceph_ll_delegation(cmount2, fh, CEPH_DELEGATION_RD, dummy_deleg_cb, &recalled), 0);
+ ASSERT_EQ(ceph_ll_delegation_wait(cmount2, fh, CEPH_DELEGATION_RD, dummy_deleg_cb, &recalled), 0);
ASSERT_EQ(ceph_ll_read(cmount2, fh, 0, sizeof(filename), filename),
static_cast<int>(sizeof(filename)));
ASSERT_EQ(ceph_ll_getattr(cmount2, file, &stx, CEPH_STATX_ALL_STATS, 0, perms), 0);