This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit f135fb266e9122cec31527b2a60f253801916ee9
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Jan 8 16:50:43 2024 -0600
sanlock: save client_id in token and report in status and use in -C
When one process uses multiple registered connections there was no
way to see the association between tokens/resources and client
connections (client_id's) from the 'sanlock status -D' output.
The ci (client_id) is now reported for resources in in status -D.
A new option -C <client_id> is added for 'sanlock client release'
(and others) to use in place of -p <pid>. It was not possible
to release specific resources from the command line with -p when
a single process had multiple client connections.
---
src/cmd.c | 15 ++++----
src/main.c | 92 +++++++++++++++++++++++++++++++++++++-------------
src/resource.c | 10 +++---
src/sanlock.8 | 3 ++
src/sanlock_internal.h | 2 ++
src/sanlock_resource.h | 10 ++++++
6 files changed, 98 insertions(+), 34 deletions(-)
diff --git a/src/cmd.c b/src/cmd.c
index 64ee409..dda9ab8 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -404,6 +404,7 @@ static void cmd_acquire(struct task *task, struct cmd_args *ca, uint32_t cmd)
token->host_generation = spi.host_generation;
token->space_id = spi.space_id;
token->pid = cl_pid;
+ token->client_id = cl_ci;
token->io_timeout = spi.io_timeout;
token->sector_size = spi.sector_size; /* starting hint, may be changed */
token->align_size = spi.align_size; /* starting hint, may be changed */
@@ -2435,7 +2436,7 @@ static int print_state_lockspace(struct space *sp, char *str, const char *list_n
}
static int print_state_resource(struct resource *r, char *str, const char *list_name,
- uint32_t token_id)
+ int client_id, uint32_t token_id)
{
memset(str, 0, SANLK_STATE_MAXSTR);
@@ -2447,7 +2448,8 @@ static int print_state_resource(struct resource *r, char *str, const char *list_
"lver=%llu "
"reused=%u "
"res_id=%u "
- "token_id=%u",
+ "token_id=%u "
+ "ci=%d",
list_name,
r->flags,
r->sector_size,
@@ -2455,7 +2457,8 @@ static int print_state_resource(struct resource *r, char *str, const char *list_
(unsigned long long)r->leader.lver,
r->reused,
r->res_id,
- token_id);
+ token_id,
+ client_id);
return strlen(str) + 1;
}
@@ -2575,10 +2578,10 @@ static void send_state_lockspace(int fd, struct space *sp, const char *list_name
}
void send_state_resource(int fd, struct resource *r, const char *list_name,
- int pid, uint32_t token_id);
+ int pid, int client_id, uint32_t token_id);
void send_state_resource(int fd, struct resource *r, const char *list_name,
- int pid, uint32_t token_id)
+ int pid, int client_id, uint32_t token_id)
{
struct sanlk_state st;
char str[SANLK_STATE_MAXSTR];
@@ -2592,7 +2595,7 @@ void send_state_resource(int fd, struct resource *r, const char *list_name,
st.data64 = r->leader.lver;
memcpy(st.name, r->r.name, NAME_ID_SIZE);
- str_len = print_state_resource(r, str, list_name, token_id);
+ str_len = print_state_resource(r, str, list_name, client_id, token_id);
st.str_len = str_len;
diff --git a/src/main.c b/src/main.c
index 96ad50a..59e96a0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1100,7 +1100,8 @@ static void process_cmd_thread_registered(int ci_in, struct sm_header *h_recv)
struct cmd_args *ca;
struct client *cl;
int result = 0;
- int rv, i, ci_target;
+ int for_pid = -1, for_client_id = -1;
+ int rv, i, ci_target = -1;
ca = malloc(sizeof(struct cmd_args));
if (!ca) {
@@ -1109,31 +1110,43 @@ static void process_cmd_thread_registered(int ci_in, struct sm_header *h_recv)
}
if (h_recv->data2 != -1) {
- /* lease for another registered client with pid specified by data2 */
- ci_target = -1;
+ /* lease for another registered client with pid or client_id specified by data2 */
+
+ if (h_recv->cmd_flags & SANLK_FOR_CLIENT_ID)
+ for_client_id = h_recv->data2;
+ else
+ for_pid = h_recv->data2;
for (i = 0; i < client_size; i++) {
cl = &client[i];
pthread_mutex_lock(&cl->mutex);
- if (cl->pid != h_recv->data2) {
- pthread_mutex_unlock(&cl->mutex);
- continue;
+
+ if (for_pid > -1) {
+ if (cl->pid != for_pid) {
+ pthread_mutex_unlock(&cl->mutex);
+ continue;
+ }
+ } else if (for_client_id > -1) {
+ if (i != for_client_id) {
+ pthread_mutex_unlock(&cl->mutex);
+ continue;
+ }
}
+
ci_target = i;
break;
}
if (ci_target < 0) {
if (h_recv->cmd != SM_CMD_INQUIRE) {
- /* inquire can be used to check if a pid exists */
- log_error("cmd %d target pid %d not found",
- h_recv->cmd, h_recv->data2);
+ /* inquire can be used to check if a pid or client_id exists */
+ log_debug("cmd %d target %d not found", h_recv->cmd, h_recv->data2);
}
result = -ESRCH;
goto fail;
}
- log_client(ci_in, client[ci_in].fd, "process reg cmd %u target pid %d ci %d",
- h_recv->cmd, h_recv->data2, ci_target);
+ log_client(ci_in, client[ci_in].fd, "process reg cmd %u for target ci %d pid %d",
+ h_recv->cmd, ci_target, client[ci_target].pid);
} else {
/* lease for this registered client */
@@ -2170,10 +2183,10 @@ static void print_usage(void)
printf("sanlock client inq_lockspace -s LOCKSPACE\n");
printf("sanlock client rem_lockspace -s LOCKSPACE\n");
printf("sanlock client command -r RESOURCE -c <path> <args>\n");
- printf("sanlock client acquire -r RESOURCE -p <pid>\n");
- printf("sanlock client convert -r RESOURCE -p <pid>\n");
- printf("sanlock client release -r RESOURCE -p <pid>\n");
- printf("sanlock client inquire -p <pid>\n");
+ printf("sanlock client acquire -r RESOURCE -p|-C <id>\n");
+ printf("sanlock client convert -r RESOURCE -p|-C <id>\n");
+ printf("sanlock client release -r RESOURCE -p|-C <id>\n");
+ printf("sanlock client inquire -p|-C <id>\n");
printf("sanlock client request -r RESOURCE -f <force_mode>\n");
printf("sanlock client examine -r RESOURCE | -s LOCKSPACE\n");
printf("sanlock client format -x RINDEX [-Z 512|4096 -A 1M|2M|4M|8M]\n");
@@ -2486,6 +2499,9 @@ static int read_command_line(int argc, char *argv[])
case 'p':
com.pid = atoi(optionarg);
break;
+ case 'C':
+ com.cid = atoi(optionarg);
+ break;
case 'd':
com.he_data = strtoull(optionarg, NULL, 0);
break;
@@ -3198,6 +3214,7 @@ static int do_client(void)
char *res_state = NULL;
uint32_t flags = 0;
uint32_t config_cmd = 0;
+ int id = -1;
int i, fd;
int rv = 0;
@@ -3296,20 +3313,41 @@ static int do_client(void)
break;
case ACT_ACQUIRE:
- log_tool("acquire pid %d", com.pid);
+ if (com.pid > -1) {
+ log_tool("acquire pid %d", com.pid);
+ id = com.pid;
+ } else if (com.cid > -1) {
+ log_tool("acquire client_id %d", com.cid);
+ id = com.cid;
+ flags |= SANLK_FOR_CLIENT_ID;
+ }
flags |= com.orphan ? SANLK_ACQUIRE_ORPHAN : 0;
- rv = sanlock_acquire(-1, com.pid, flags, com.res_count, com.res_args, NULL);
+ rv = sanlock_acquire(-1, id, flags, com.res_count, com.res_args, NULL);
log_tool("acquire done %d", rv);
break;
case ACT_CONVERT:
- log_tool("convert pid %d", com.pid);
- rv = sanlock_convert(-1, com.pid, 0, com.res_args[0]);
+ if (com.pid > -1) {
+ log_tool("convert pid %d", com.pid);
+ id = com.pid;
+ } else if (com.cid > -1) {
+ log_tool("convert client_id %d", com.cid);
+ id = com.cid;
+ flags |= SANLK_FOR_CLIENT_ID;
+ }
+ rv = sanlock_convert(-1, id, flags, com.res_args[0]);
log_tool("convert done %d", rv);
break;
case ACT_RELEASE:
- log_tool("release pid %d", com.pid);
+ if (com.pid > -1) {
+ log_tool("release pid %d", com.pid);
+ id = com.pid;
+ } else if (com.cid > -1) {
+ log_tool("release client_id %d", com.cid);
+ id = com.cid;
+ flags |= SANLK_FOR_CLIENT_ID;
+ }
/*
* Odd case to specify: release all orphan resources for the named lockspace.
* Uses -s lockspace_name instead of using -r, but the function takes a
@@ -3328,13 +3366,20 @@ static int do_client(void)
}
flags |= com.orphan ? SANLK_REL_ORPHAN : 0;
flags |= com.all ? SANLK_REL_ALL: 0;
- rv = sanlock_release(-1, com.pid, flags, com.res_count, com.res_args);
+ rv = sanlock_release(-1, id, flags, com.res_count, com.res_args);
log_tool("release done %d", rv);
break;
case ACT_INQUIRE:
- log_tool("inquire pid %d", com.pid);
- rv = sanlock_inquire(-1, com.pid, 0, &com.res_count, &res_state);
+ if (com.pid > -1) {
+ log_tool("inquire pid %d", com.pid);
+ id = com.pid;
+ } else if (com.cid > -1) {
+ log_tool("inquire client_id %d", com.cid);
+ id = com.cid;
+ flags |= SANLK_FOR_CLIENT_ID;
+ }
+ rv = sanlock_inquire(-1, id, flags, &com.res_count, &res_state);
log_tool("inquire done %d res_count %d", rv, com.res_count);
if (rv < 0)
break;
@@ -3954,6 +3999,7 @@ int main(int argc, char *argv[])
com.write_init_io_timeout = DEFAULT_WRITE_INIT_IO_TIMEOUT;
com.aio_arg = DEFAULT_USE_AIO;
com.pid = -1;
+ com.cid = -1;
com.sh_retries = DEFAULT_SH_RETRIES;
com.quiet_fail = DEFAULT_QUIET_FAIL;
com.renewal_read_extend_sec_set = 0;
diff --git a/src/resource.c b/src/resource.c
index c1c49f9..cad8af5 100644
--- a/src/resource.c
+++ b/src/resource.c
@@ -35,7 +35,7 @@
#include "helper.h"
/* from cmd.c */
-void send_state_resource(int fd, struct resource *r, const char *list_name, int pid, uint32_t token_id);
+void send_state_resource(int fd, struct resource *r, const char *list_name, int pid, int client_id, uint32_t token_id);
/* from main.c */
int get_rand(int a, int b);
@@ -138,19 +138,19 @@ void send_state_resources(int fd)
pthread_mutex_lock(&resource_mutex);
list_for_each_entry(r, &resources_held, list) {
list_for_each_entry(token, &r->tokens, list)
- send_state_resource(fd, r, "held", token->pid, token->token_id);
+ send_state_resource(fd, r, "held", token->pid, token->client_id, token->token_id);
}
list_for_each_entry(r, &resources_add, list) {
list_for_each_entry(token, &r->tokens, list)
- send_state_resource(fd, r, "add", token->pid, token->token_id);
+ send_state_resource(fd, r, "add", token->pid, token->client_id, token->token_id);
}
list_for_each_entry(r, &resources_rem, list)
- send_state_resource(fd, r, "rem", r->pid, 0);
+ send_state_resource(fd, r, "rem", r->pid, 0, 0);
list_for_each_entry(r, &resources_orphan, list)
- send_state_resource(fd, r, "orphan", r->pid, 0);
+ send_state_resource(fd, r, "orphan", r->pid, 0, 0);
pthread_mutex_unlock(&resource_mutex);
}
diff --git a/src/sanlock.8 b/src/sanlock.8
index 5295bf5..6466689 100644
--- a/src/sanlock.8
+++ b/src/sanlock.8
@@ -726,6 +726,7 @@ Tell the sanlock daemon to acquire or release the specified resource lease
for the given pid. The pid must be registered with the sanlock daemon.
acquire can optionally take a versioned RESOURCE string RESOURCE:lver,
where lver is the version of the lease that must be acquired, or fail.
+Use -C in place of -p to specify client_id.
.BR "sanlock client convert -r" " RESOURCE " \
\fB-p\fP " " \fIpid\fP
@@ -735,12 +736,14 @@ lease for the given pid. If the existing mode is exclusive (default),
the mode of the lease can be converted to shared with RESOURCE:SH. If the
existing mode is shared, the mode of the lease can be converted to
exclusive with RESOURCE (no :SH suffix).
+Use -C in place of -p to specify client_id.
.BI "sanlock client inquire -p" " pid"
Print the resource leases held the given pid. The format is a versioned
RESOURCE string "RESOURCE:lver" where lver is the version of the lease
held.
+Use -C in place of -p to specify client_id.
.BR "sanlock client request -r" " RESOURCE " \
\fB-f\fP " " \fIforce_mode\fP
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 3e06e4f..a8ffdf5 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -105,6 +105,7 @@ struct token {
struct list_head list; /* resource->tokens */
struct resource *resource;
int pid;
+ int client_id;
uint32_t flags; /* be careful to avoid using this from different threads */
uint32_t token_id;
uint32_t res_id;
@@ -378,6 +379,7 @@ struct command_line {
char *gname; /* -G */
int gid; /* -G */
int pid; /* -p */
+ int cid; /* -C */
char sort_arg;
uint64_t host_id; /* -i */
uint64_t host_generation; /* -g */
diff --git a/src/sanlock_resource.h b/src/sanlock_resource.h
index 48e4489..ed27130 100644
--- a/src/sanlock_resource.h
+++ b/src/sanlock_resource.h
@@ -31,6 +31,8 @@
/* killpath flags */
#define SANLK_KILLPATH_PID 0x00000001
+#define SANLK_FOR_CLIENT_ID 0x00000010
+
/*
* acquire flags
*
@@ -57,6 +59,7 @@
#define SANLK_ACQUIRE_ORPHAN 0x00000002
#define SANLK_ACQUIRE_ORPHAN_ONLY 0x00000004
#define SANLK_ACQUIRE_OWNER_NOWAIT 0x00000008
+/* SANLK_FOR_CLIENT_ID 0x00000010 defined above */
/*
* release flags
@@ -87,6 +90,7 @@
#define SANLK_REL_ALL 0x00000001
#define SANLK_REL_RENAME 0x00000002
#define SANLK_REL_ORPHAN 0x00000004
+/* SANLK_FOR_CLIENT_ID 0x00000010 defined above */
/*
* convert flags
@@ -96,6 +100,12 @@
*/
#define SANLK_CONVERT_OWNER_NOWAIT 0x00000008 /* NB: value must match SANLK_ACQUIRE_OWNER_NOWAIT */
+/* SANLK_FOR_CLIENT_ID 0x00000010 defined above */
+
+/*
+ * inquire flags
+ */
+/* SANLK_FOR_CLIENT_ID 0x00000010 defined above */
/*
* request flags
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.