This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master in repository sanlock.
commit ca86cb3a0a23db1df767b75c9cfcf5483c8a430b Author: David Teigland teigland@redhat.com AuthorDate: Thu Jun 26 11:29:10 2025 -0500
sanlock: add client init_host to initialize one delta lease
Add a client lib API for init_host. --- src/client.c | 50 +++++++++++++++++++++++++++++++++++ src/cmd.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 16 ++++++++++++ src/sanlock.8 | 8 ++++++ src/sanlock_admin.h | 10 +++++++ src/sanlock_internal.h | 1 + src/sanlock_sock.h | 1 + 7 files changed, 157 insertions(+)
diff --git a/src/client.c b/src/client.c index dc63c25..3483036 100644 --- a/src/client.c +++ b/src/client.c @@ -667,6 +667,56 @@ int sanlock_read_resource(struct sanlk_resource *res, uint32_t flags) return rv; }
+int sanlock_init_lockspace_host(struct sanlk_lockspace *ls, + char *our_host_name, + uint64_t generation, + uint64_t timestamp, + uint32_t flags, + uint32_t io_timeout) +{ + struct leader_record leader = { 0 }; + char name[NAME_ID_SIZE + 1] = { 0 }; + int rv, fd; + + if (!ls || !ls->name[0] || !ls->host_id_disk.path[0] || !ls->host_id) + return -EINVAL; + + leader.owner_generation = generation; + leader.timestamp = timestamp; + leader.owner_id = ls->host_id; + if (our_host_name) { + strncpy(name, our_host_name, NAME_ID_SIZE); + memcpy(leader.resource_name, name, NAME_ID_SIZE); + } + + rv = connect_socket(&fd); + if (rv < 0) + return rv; + + rv = send_header(fd, SM_CMD_INIT_LOCKSPACE_HOST, flags, + sizeof(struct sanlk_lockspace) + sizeof(struct leader_record), + 0, io_timeout); + if (rv < 0) + goto out; + + rv = send_data(fd, ls, sizeof(struct sanlk_lockspace), 0); + if (rv < 0) { + rv = -errno; + goto out; + } + + rv = send_data(fd, &leader, sizeof(struct leader_record), 0); + if (rv < 0) { + rv = -errno; + goto out; + } + + rv = recv_result(fd); + out: + close(fd); + return rv; +} + int sanlock_write_lockspace(struct sanlk_lockspace *ls, int max_hosts, uint32_t flags, uint32_t io_timeout) { diff --git a/src/cmd.c b/src/cmd.c index d0648bb..d5c7452 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1874,6 +1874,74 @@ static void cmd_read_resource_owners(struct task *task, struct cmd_args *ca, uin client_resume(ca->ci_in); }
+static void cmd_init_lockspace_host(struct task *task, struct cmd_args *ca, uint32_t cmd) +{ + struct sanlk_lockspace lockspace; + struct leader_record leader; + struct sync_disk sd; + int fd, rv, result; + int io_timeout = com.io_timeout; + + fd = client[ca->ci_in].fd; + + rv = recv_loop(fd, &lockspace, sizeof(struct sanlk_lockspace), MSG_WAITALL); + if (rv != sizeof(struct sanlk_lockspace)) { + log_error("cmd_init_lockspace_host %d,%d recv lockspace %d %d", + ca->ci_in, fd, rv, errno); + result = -ENOTCONN; + goto reply; + } + + rv = recv_loop(fd, &leader, sizeof(struct leader_record), MSG_WAITALL); + if (rv != sizeof(struct leader_record)) { + log_error("cmd_init_lockspace_host %d,%d recv leader %d %d", + ca->ci_in, fd, rv, errno); + result = -ENOTCONN; + goto reply; + } + + log_cmd(cmd, "cmd_init_lockspace_host %d,%d %.48s:%llu:%s:%llu 0x%x", + ca->ci_in, fd, lockspace.name, + (unsigned long long)lockspace.host_id, + lockspace.host_id_disk.path, + (unsigned long long)lockspace.host_id_disk.offset, + lockspace.flags); + + if (!lockspace.host_id_disk.path[0] || !lockspace.host_id) { + result = -EINVAL; + goto reply; + } + + memset(&sd, 0, sizeof(struct sync_disk)); + memcpy(&sd, &lockspace.host_id_disk, sizeof(struct sanlk_disk)); + sd.fd = -1; + + rv = open_disk(&sd); + if (rv < 0) { + result = -ENODEV; + goto reply; + } + + if (ca->header.data2) + io_timeout = ca->header.data2; + + result = delta_lease_init_host(task, &lockspace, + leader.resource_name[0] ? leader.resource_name : NULL, + leader.owner_generation, + leader.timestamp, + io_timeout, + &sd); + if (result == SANLK_OK) + result = 0; + + close_disks(&sd, 1); + reply: + log_cmd(cmd, "cmd_init_lockspace_host %d,%d done %d", ca->ci_in, fd, result); + + send_result(ca->ci_in, fd, &ca->header, result); + client_resume(ca->ci_in); +} + static void cmd_write_lockspace(struct task *task, struct cmd_args *ca, uint32_t cmd) { struct sanlk_lockspace lockspace; @@ -2264,6 +2332,9 @@ void call_cmd_thread(struct task *task, struct cmd_args *ca) case SM_CMD_ALIGN: cmd_align(task, ca, cmd); break; + case SM_CMD_INIT_LOCKSPACE_HOST: + cmd_init_lockspace_host(task, ca, cmd); + break; case SM_CMD_WRITE_LOCKSPACE: cmd_write_lockspace(task, ca, cmd); break; diff --git a/src/main.c b/src/main.c index f25ab22..6c1ef50 100644 --- a/src/main.c +++ b/src/main.c @@ -1378,6 +1378,7 @@ static void process_connection(int ci) case SM_CMD_WRITE_RESOURCE: case SM_CMD_READ_LOCKSPACE: case SM_CMD_READ_LOCKSPACE_HOST: + case SM_CMD_INIT_LOCKSPACE_HOST: case SM_CMD_READ_RESOURCE: case SM_CMD_READ_RESOURCE_OWNERS: case SM_CMD_SET_LVB: @@ -2310,6 +2311,7 @@ static void print_usage(void) printf("sanlock client log_dump\n"); printf("sanlock client shutdown [-f 0|1] [-w 0|1]\n"); printf("sanlock client init -s LOCKSPACE | -r RESOURCE [-z 0|1] [-Z 512|4096 -A 1M|2M|4M|8M]\n"); + printf("sanlock client init_host -s LOCKSPACE [-g <generation>] [-t <timestamp>] [ -e <name> ] [-Z 512|4096 -A 1M|2M|4M|8M]\n"); printf("sanlock client read -s LOCKSPACE | -r RESOURCE [-D]\n"); printf("sanlock client add_lockspace -s LOCKSPACE\n"); printf("sanlock client inq_lockspace -s LOCKSPACE\n"); @@ -2457,6 +2459,8 @@ static int read_command_line(int argc, char *argv[]) com.action = ACT_EXAMINE; else if (!strcmp(act, "align")) com.action = ACT_CLIENT_ALIGN; + else if (!strcmp(act, "init_host")) + com.action = ACT_CLIENT_INIT_HOST; else if (!strcmp(act, "init")) com.action = ACT_CLIENT_INIT; else if (!strcmp(act, "write")) @@ -3617,6 +3621,18 @@ static int do_client(void) } break;
+ case ACT_CLIENT_INIT_HOST: + log_tool("init_host"); + if (com.sector_size) + com.lockspace.flags |= sanlk_lsf_sector_size_to_flag(com.sector_size); + if (com.align_size) + com.lockspace.flags |= sanlk_lsf_align_size_to_flag(com.align_size); + rv = sanlock_init_lockspace_host(&com.lockspace, + com.our_host_name_opt[0] ? com.our_host_name_opt : NULL, + com.host_generation, com.timestamp, 0, com.io_timeout); + log_tool("init_host done %d", rv); + break; + case ACT_INQ_LOCKSPACE: log_tool("inq_lockspace"); rv = sanlock_inq_lockspace(&com.lockspace, 0); diff --git a/src/sanlock.8 b/src/sanlock.8 index 3cf093d..364b068 100644 --- a/src/sanlock.8 +++ b/src/sanlock.8 @@ -691,6 +691,14 @@ RESOURCE path and offset are required. The complete RESOURCE is printed. Add -D to print other details. (Also see sanlock direct read_leader.)
+.BR "sanlock client init_host -s" " LOCKSPACE" + +Tell the sanlock daemon to initialize a single delta lease on disk. +The host_id specified in the -s arg will be used, and written as the +lease owner. Optionally specify host name with -e, generation with -g, +and timestamp with -t. Use -Z to specify sector size. +(Also see sanlock direct init_host for more information.) + .BR "sanlock client add_lockspace -s" " LOCKSPACE"
Tell the sanlock daemon to acquire the specified host_id in the lockspace. diff --git a/src/sanlock_admin.h b/src/sanlock_admin.h index 93847f9..889ae5a 100644 --- a/src/sanlock_admin.h +++ b/src/sanlock_admin.h @@ -242,6 +242,16 @@ int sanlock_init(struct sanlk_lockspace *ls, int sanlock_write_lockspace(struct sanlk_lockspace *ls, int max_hosts, uint32_t flags, uint32_t io_timeout);
+/* + * initialize one host_id lease in the lockspace + */ +int sanlock_init_lockspace_host(struct sanlk_lockspace *ls, + char *our_host_name, + uint64_t generation, + uint64_t timestamp, + uint32_t flags, + uint32_t io_timeout); + /* * read one host's lockspace record from disk * diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h index 4418721..f41d438 100644 --- a/src/sanlock_internal.h +++ b/src/sanlock_internal.h @@ -482,6 +482,7 @@ enum { ACT_UPDATE, ACT_REBUILD, ACT_DIRECT_INIT_HOST, + ACT_CLIENT_INIT_HOST, ACT_READ, };
diff --git a/src/sanlock_sock.h b/src/sanlock_sock.h index dd97a5c..c99be6e 100644 --- a/src/sanlock_sock.h +++ b/src/sanlock_sock.h @@ -62,6 +62,7 @@ enum { SM_CMD_REBUILD_RINDEX = 40, SM_CMD_ACQUIRE2 = 41, SM_CMD_READ_LOCKSPACE_HOST = 42, + SM_CMD_INIT_LOCKSPACE_HOST = 43, };
#define SM_CB_GET_EVENT 1
sanlock-devel@lists.fedorahosted.org