This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
The following commit(s) were added to refs/heads/master by this push:
new 87d0108 sanlock: add new sanlock_read_lockspace_host function
87d0108 is described below
commit 87d0108254beefdc02c3916ee920aeddb73017ae
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Apr 16 11:51:49 2025 -0500
sanlock: add new sanlock_read_lockspace_host function
which returns sanlk_host fields (except for flags)
---
src/client.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/cmd.c | 16 +++++++-----
src/delta_lease.c | 10 ++++++--
src/delta_lease.h | 2 +-
src/main.c | 18 +++++++++++++-
src/sanlock_admin.h | 7 ++++++
src/sanlock_sock.h | 1 +
7 files changed, 115 insertions(+), 10 deletions(-)
diff --git a/src/client.c b/src/client.c
index 88b4817..dc63c25 100644
--- a/src/client.c
+++ b/src/client.c
@@ -471,6 +471,77 @@ int sanlock_align(struct sanlk_disk *disk)
return rv;
}
+int sanlock_read_lockspace_host(struct sanlk_lockspace *ls, uint32_t flags, uint32_t *io_timeout,
+ struct sanlk_host *hs)
+{
+ struct sm_header h;
+ int rv, fd;
+
+ if (!ls || !ls->host_id_disk.path[0])
+ return -EINVAL;
+
+ rv = connect_socket(&fd);
+ if (rv < 0)
+ return rv;
+
+ rv = send_header(fd, SM_CMD_READ_LOCKSPACE_HOST, flags,
+ sizeof(struct sanlk_lockspace),
+ 0, 0);
+ if (rv < 0)
+ goto out;
+
+ rv = send_data(fd, ls, sizeof(struct sanlk_lockspace), 0);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ memset(&h, 0, sizeof(h));
+
+ rv = recv_data(fd, &h, sizeof(h), MSG_WAITALL);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ if (rv != sizeof(h)) {
+ rv = -1;
+ goto out;
+ }
+
+ rv = (int)h.data;
+ if (rv < 0)
+ goto out;
+
+ rv = recv_data(fd, ls, sizeof(struct sanlk_lockspace), MSG_WAITALL);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ if (rv != sizeof(struct sanlk_lockspace)) {
+ rv = -1;
+ goto out;
+ }
+
+ rv = recv_data(fd, hs, sizeof(struct sanlk_host), MSG_WAITALL);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ if (rv != sizeof(struct sanlk_host)) {
+ rv = -1;
+ goto out;
+ }
+
+ *io_timeout = h.data2;
+ rv = (int)h.data;
+ out:
+ close(fd);
+ return rv;
+}
+
int sanlock_read_lockspace(struct sanlk_lockspace *ls, uint32_t flags, uint32_t *io_timeout)
{
struct sm_header h;
diff --git a/src/cmd.c b/src/cmd.c
index 8cf8813..f81be56 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -1578,11 +1578,12 @@ static void cmd_read_lockspace(struct task *task, struct cmd_args *ca, uint32_t
{
struct sm_header h;
struct sanlk_lockspace lockspace;
+ struct sanlk_host host = { 0 };
struct sync_disk sd;
uint64_t host_id;
+ int with_host = (cmd == SM_CMD_READ_LOCKSPACE_HOST);
int sector_size = 0;
int align_size = 0;
- int io_timeout = 0;
int fd, rv, result;
fd = client[ca->ci_in].fd;
@@ -1600,7 +1601,8 @@ static void cmd_read_lockspace(struct task *task, struct cmd_args *ca, uint32_t
else
host_id = lockspace.host_id;
- log_cmd(cmd, "cmd_read_lockspace %d,%d %llu %s:%llu",
+ log_cmd(cmd, "cmd_read_lockspace%s %d,%d %llu %s:%llu",
+ with_host ? "_host" : "",
ca->ci_in, fd,
(unsigned long long)host_id,
lockspace.host_id_disk.path,
@@ -1635,24 +1637,25 @@ static void cmd_read_lockspace(struct task *task, struct cmd_args *ca, uint32_t
}
}
- /* sets ls->name and io_timeout */
result = delta_read_lockspace(task, &sd, sector_size, align_size, host_id, &lockspace,
- com.io_timeout, &io_timeout);
+ com.io_timeout, &host);
if (result == SANLK_OK)
result = 0;
out_close:
close_disks(&sd, 1);
reply:
- log_cmd(cmd, "cmd_read_lockspace %d,%d done %d", ca->ci_in, fd, result);
+ log_cmd(cmd, "cmd_read_lockspace%s %d,%d done %d", with_host ? "_host" : "", ca->ci_in, fd, result);
memcpy(&h, &ca->header, sizeof(struct sm_header));
h.version = SM_PROTO;
h.data = result;
- h.data2 = io_timeout;
+ h.data2 = host.io_timeout;
h.length = sizeof(h) + sizeof(lockspace);
send_all(fd, &h, sizeof(h), MSG_NOSIGNAL);
send_all(fd, &lockspace, sizeof(lockspace), MSG_NOSIGNAL);
+ if (with_host)
+ send_all(fd, &host, sizeof(host), MSG_NOSIGNAL);
client_resume(ca->ci_in);
}
@@ -2261,6 +2264,7 @@ void call_cmd_thread(struct task *task, struct cmd_args *ca)
cmd_write_resource(task, ca, cmd);
break;
case SM_CMD_READ_LOCKSPACE:
+ case SM_CMD_READ_LOCKSPACE_HOST:
cmd_read_lockspace(task, ca, cmd);
break;
case SM_CMD_READ_RESOURCE:
diff --git a/src/delta_lease.c b/src/delta_lease.c
index 33ab385..cc93f27 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -154,7 +154,7 @@ int delta_read_lockspace(struct task *task,
uint64_t host_id,
struct sanlk_lockspace *ls,
int io_timeout,
- int *io_timeout_ret)
+ struct sanlk_host *hs)
{
struct leader_record leader_end;
struct leader_record leader;
@@ -192,7 +192,6 @@ int delta_read_lockspace(struct task *task,
if (error == SANLK_OK) {
memcpy(ls->name, leader.space_name, SANLK_NAME_LEN);
ls->host_id = host_id;
- *io_timeout_ret = leader.io_timeout;
align_size = leader_align_size_from_flag(leader.flags);
if (!align_size)
@@ -204,6 +203,13 @@ int delta_read_lockspace(struct task *task,
ls->flags |= sanlk_lsf_sector_size_to_flag(leader.sector_size);
ls->flags |= sanlk_lsf_align_size_to_flag(align_size);
+
+ if (hs) {
+ hs->host_id = leader.owner_id;
+ hs->generation = leader.owner_generation;
+ hs->timestamp = leader.timestamp;
+ hs->io_timeout = leader.io_timeout;
+ }
}
return error;
diff --git a/src/delta_lease.h b/src/delta_lease.h
index 3128a0f..c3030a4 100644
--- a/src/delta_lease.h
+++ b/src/delta_lease.h
@@ -67,7 +67,7 @@ int delta_read_lockspace(struct task *task,
uint64_t host_id,
struct sanlk_lockspace *ls,
int io_timeout,
- int *io_timeout_ret);
+ struct sanlk_host *hs);
int delta_read_lockspace_sizes(struct task *task,
struct sync_disk *disk,
diff --git a/src/main.c b/src/main.c
index e13f3de..6cf5930 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1377,6 +1377,7 @@ static void process_connection(int ci)
case SM_CMD_WRITE_LOCKSPACE:
case SM_CMD_WRITE_RESOURCE:
case SM_CMD_READ_LOCKSPACE:
+ case SM_CMD_READ_LOCKSPACE_HOST:
case SM_CMD_READ_RESOURCE:
case SM_CMD_READ_RESOURCE_OWNERS:
case SM_CMD_SET_LVB:
@@ -2837,6 +2838,8 @@ const char *cmd_num_to_str(int cmd)
return "write_resource";
case SM_CMD_READ_LOCKSPACE:
return "read_lockspace";
+ case SM_CMD_READ_LOCKSPACE_HOST:
+ return "read_lockspace_host";
case SM_CMD_READ_RESOURCE:
return "read_resource";
case SM_CMD_SET_LVB:
@@ -2926,6 +2929,8 @@ uint32_t cmd_str_to_num(const char *str)
return SM_CMD_WRITE_RESOURCE;
if (!strcmp(str, "read_lockspace"))
return SM_CMD_READ_LOCKSPACE;
+ if (!strcmp(str, "read_lockspace_host"))
+ return SM_CMD_READ_LOCKSPACE_HOST;
if (!strcmp(str, "read_resource"))
return SM_CMD_READ_RESOURCE;
if (!strcmp(str, "set_lvb"))
@@ -3334,6 +3339,7 @@ static int do_client_gets(void)
static int do_client_read(void)
{
+ struct sanlk_host host;
struct sanlk_host *hss = NULL, *hs;
char *res_str = NULL;
uint32_t io_timeout = 0;
@@ -3345,7 +3351,10 @@ static int do_client_read(void)
if (com.align_size)
com.lockspace.flags |= sanlk_lsf_align_size_to_flag(com.align_size);
- rv = sanlock_read_lockspace(&com.lockspace, 0, &io_timeout);
+ if (!com.get_hosts)
+ rv = sanlock_read_lockspace(&com.lockspace, 0, &io_timeout);
+ else
+ rv = sanlock_read_lockspace_host(&com.lockspace, 0, &io_timeout, &host);
} else {
if (com.sector_size)
com.res_args[0]->flags |= sanlk_res_sector_size_to_flag(com.sector_size);
@@ -3376,6 +3385,12 @@ static int do_client_read(void)
log_tool("sector_size %d", sanlk_lsf_sector_flag_to_size(com.lockspace.flags));
log_tool("align_size %d", sanlk_lsf_align_flag_to_size(com.lockspace.flags));
}
+ if (com.debug && com.get_hosts) {
+ log_tool("host_id %llu", (unsigned long long)host.host_id);
+ log_tool("generation %llu", (unsigned long long)host.generation);
+ log_tool("timestamp %llu", (unsigned long long)host.timestamp);
+ log_tool("flags 0x%x", host.flags);
+ }
goto out;
}
@@ -4296,6 +4311,7 @@ int main(int argc, char *argv[])
clear_cmd_debug(SM_CMD_GET_LOCKSPACES);
clear_cmd_debug(SM_CMD_GET_HOSTS);
clear_cmd_debug(SM_CMD_READ_LOCKSPACE);
+ clear_cmd_debug(SM_CMD_READ_LOCKSPACE_HOST);
clear_cmd_debug(SM_CMD_READ_RESOURCE);
clear_cmd_debug(SM_CMD_READ_RESOURCE_OWNERS);
clear_cmd_debug(SM_CMD_WRITE_RESOURCE);
diff --git a/src/sanlock_admin.h b/src/sanlock_admin.h
index 0711a84..b12c191 100644
--- a/src/sanlock_admin.h
+++ b/src/sanlock_admin.h
@@ -258,11 +258,18 @@ int sanlock_write_lockspace(struct sanlk_lockspace *ls, int max_hosts,
*
* on success, zero is returned and
* io_timeout and the entire sanlk_lockspace struct are written to
+ *
+ * For sanlock_read_lockspace_host(), the host fields are returned
+ * except for flags.
*/
int sanlock_read_lockspace(struct sanlk_lockspace *ls,
uint32_t flags, uint32_t *io_timeout);
+int sanlock_read_lockspace_host(struct sanlk_lockspace *ls,
+ uint32_t flags, uint32_t *io_timeout,
+ struct sanlk_host *hs);
+
/*
* format a resource lease area on disk
*
diff --git a/src/sanlock_sock.h b/src/sanlock_sock.h
index 10ad24b..dd97a5c 100644
--- a/src/sanlock_sock.h
+++ b/src/sanlock_sock.h
@@ -61,6 +61,7 @@ enum {
SM_CMD_DELETE_RESOURCE = 39,
SM_CMD_REBUILD_RINDEX = 40,
SM_CMD_ACQUIRE2 = 41,
+ SM_CMD_READ_LOCKSPACE_HOST = 42,
};
#define SM_CB_GET_EVENT 1
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.