This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master in repository sanlock.
commit 552c3d79790008ec83ab2342d316a18aaef75eb1 Author: David Teigland teigland@redhat.com AuthorDate: Wed Mar 19 15:44:31 2025 -0500
sanlock: return shared owner info for acquire2
return host_id/generation of the first/lowest host with a shared lock which is blocking an ex request. The returned timestamp is 0, which indicates the owner is holding a shared lock. --- src/cmd.c | 7 +++++-- src/main.c | 3 ++- src/resource.c | 24 +++++++++++++++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/src/cmd.c b/src/cmd.c index d4f6c8a..8556aa4 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -427,10 +427,10 @@ static void cmd_acquire(struct task *task, struct cmd_args *ca, uint32_t cmd) if (rv < 0) { switch (rv) { case -EEXIST: - case -EAGAIN: case -EBUSY: lvl = LOG_DEBUG; break; + case -EAGAIN: case SANLK_ACQUIRE_IDLIVE: case SANLK_ACQUIRE_OWNED: case SANLK_ACQUIRE_OTHER: @@ -439,7 +439,10 @@ static void cmd_acquire(struct task *task, struct cmd_args *ca, uint32_t cmd) (owner_host.host_id > 0) && (owner_host.host_id <= DEFAULT_MAX_HOSTS)) owner_host_send = 1; - lvl = com.quiet_fail ? LOG_DEBUG : LOG_ERR; + if (rv == -EAGAIN || com.quiet_fail) + lvl = LOG_DEBUG; + else + lvl = LOG_ERR; break; default: lvl = LOG_ERR; diff --git a/src/main.c b/src/main.c index 3afde14..22b908f 100644 --- a/src/main.c +++ b/src/main.c @@ -3525,7 +3525,8 @@ static int do_client(void) if (com.get_hosts && (owner.host_id || owner_name)) { log_tool("owner: host_id %llu generation %llu timestamp %llu state %s name %s", (unsigned long long)owner.host_id, (unsigned long long)owner.generation, - (unsigned long long)owner.timestamp, host_state_str(owner.flags), owner_name); + (unsigned long long)owner.timestamp, host_state_str(owner.flags), + owner_name ?: "none"); if (owner_name) free(owner_name); } diff --git a/src/resource.c b/src/resource.c index 88c33ab..41742a4 100644 --- a/src/resource.c +++ b/src/resource.c @@ -736,7 +736,9 @@ static int read_mode_block(struct task *task, struct token *token, }
static int clear_dead_shared(struct task *task, struct token *token, - int num_hosts, int *live_count) + int num_hosts, int *live_count, + uint64_t *first_live_host_id, + uint64_t *first_live_host_gen) { struct mode_block mb; uint64_t host_id; @@ -782,6 +784,11 @@ static int clear_dead_shared(struct task *task, struct token *token, log_token(token, "clear_dead_shared host_id %llu gen %llu alive", (unsigned long long)host_id, (unsigned long long)mb.generation); live++; + + if (live == 1 && first_live_host_id && first_live_host_gen) { + *first_live_host_id = host_id; + *first_live_host_gen = mb.generation; + } continue; }
@@ -1570,7 +1577,7 @@ static int convert_sh2ex_token(struct task *task, struct resource *r, struct tok goto do_mb; }
- rv = clear_dead_shared(task, token, leader.num_hosts, &live_count); + rv = clear_dead_shared(task, token, leader.num_hosts, &live_count, NULL, NULL); if (rv < 0) { log_errot(token, "convert_sh2ex clear_dead error %d", rv); /* Do on-disk release of owner. Keep token and SH mblock. */ @@ -1802,6 +1809,8 @@ int acquire_token(struct task *task, struct token *token, uint32_t cmd_flags, struct paxos_dblock dblock; struct resource *r; uint64_t acquire_lver = 0; + uint64_t first_live_host_id = 0; + uint64_t first_live_host_gen = 0; uint32_t new_num_hosts = 0; int sh_retries = 0; int live_count = 0; @@ -2128,7 +2137,8 @@ int acquire_token(struct task *task, struct token *token, uint32_t cmd_flags, * with SHARED mb is dead, we clear it, otherwise it's alive * and we count it in live_count. */ - rv = clear_dead_shared(task, token, leader.num_hosts, &live_count); + rv = clear_dead_shared(task, token, leader.num_hosts, &live_count, + &first_live_host_id, &first_live_host_gen); if (rv < 0) { log_errot(token, "acquire_token clear_dead_shared error %d", rv); release_token_opened(task, token); @@ -2146,6 +2156,14 @@ int acquire_token(struct task *task, struct token *token, uint32_t cmd_flags, log_errot(token, "acquire_token live_count release error %d", rv); return rv; } + + if (owner_host) { + owner_host->host_id = first_live_host_id; + owner_host->generation = first_live_host_gen; + owner_host->timestamp = 0; + owner_host->io_timeout = 0; + } + return -EAGAIN; }
sanlock-devel@lists.fedorahosted.org