From: Jim Fehlig jfehlig@suse.com
With '-Wl,--no-undefined' added to the library link flags in src/Makefile, the following errors are observed
/usr/lib64/gcc/x86_64-suse-linux/15/../../../../x86_64-suse-linux/bin/ld: /tmp/cc3Oo4up.ltrans0.ltrans.o: in function `paxos_lease_acquire': /home/jfehlig/virt/pagure/sanlock/src/paxos_lease.c:1752:(.text+0xce7d): undefined reference to `set_id_bit' /usr/lib64/gcc/x86_64-suse-linux/15/../../../../x86_64-suse-linux/bin/ld: /tmp/cc3Oo4up.ltrans1.ltrans.o: in function `do_paxos_action': /home/jfehlig/virt/pagure/sanlock/src/direct.c:271:(.text+0x1e6a): undefined reference to `free_token' /usr/lib64/gcc/x86_64-suse-linux/15/../../../../x86_64-suse-linux/bin/ld: /home/jfehlig/virt/pagure/sanlock/src/direct.c:271:(.text+0x1faa): undefined reference to `free_token' /usr/lib64/gcc/x86_64-suse-linux/15/../../../../x86_64-suse-linux/bin/ld: /home/jfehlig/virt/pagure/sanlock/src/direct.c:271:(.text+0x20d1): undefined reference to `free_token' /usr/lib64/gcc/x86_64-suse-linux/15/../../../../x86_64-suse-linux/bin/ld: /home/jfehlig/virt/pagure/sanlock/src/direct.c:171:(.text+0x2168): undefined reference to `free_token' collect2: error: ld returned 1 exit status
Circular dependencies on set_id_bit and free_token were introduced by commit e68723c12a. This patch takes a simple approach to fixing this issue by moving the functions from the sanlock binary, to a new sanlock_internal.c file in the library.
Signed-off-by: Jim Fehlig jfehlig@suse.com ---
Perhaps not the best way to fix this, but thought it better to send a patch for discussion than simply complain :-).
src/Makefile | 3 ++- src/lockspace.c | 14 -------------- src/lockspace.h | 3 --- src/resource.c | 9 --------- src/resource.h | 1 - src/sanlock_internal.c | 32 ++++++++++++++++++++++++++++++++ src/sanlock_internal.h | 4 ++++ 7 files changed, 38 insertions(+), 28 deletions(-)
diff --git a/src/Makefile b/src/Makefile index e3ed69d..7dbb6da 100644 --- a/src/Makefile +++ b/src/Makefile @@ -57,7 +57,8 @@ LIB_ENTIRE_SOURCE = \ timeouts.c \ direct_lib.c \ monotime.c \ - env.c + env.c \ + sanlock_internal.c
LIB_CLIENT_SOURCE = \ client.c \ diff --git a/src/lockspace.c b/src/lockspace.c index a00a44d..6e6e2c7 100644 --- a/src/lockspace.c +++ b/src/lockspace.c @@ -237,20 +237,6 @@ static void clear_bit(int host_id, char *bitmap) } #endif
-void set_id_bit(int host_id, char *bitmap, char *c) -{ - char *byte = bitmap + ((host_id - 1) / 8); - unsigned int bit = (host_id - 1) % 8; - char mask; - - mask = 1 << bit; - - *byte |= mask; - - if (c) - *c = *byte; -} - /* FIXME: another copy in direct_lib.c */
int test_id_bit(int host_id, char *bitmap) diff --git a/src/lockspace.h b/src/lockspace.h index 18f2cf0..f21bc79 100644 --- a/src/lockspace.h +++ b/src/lockspace.h @@ -32,9 +32,6 @@ int host_status_set_bit(char *space_name, uint64_t host_id); /* no locks */ int test_id_bit(int host_id, char *bitmap);
-/* no locks */ -void set_id_bit(int host_id, char *bitmap, char *c); - /* locks sp */ int check_our_lease(struct space *sp, int *check_all, char *check_buf);
diff --git a/src/resource.c b/src/resource.c index c255df2..975f21f 100644 --- a/src/resource.c +++ b/src/resource.c @@ -62,15 +62,6 @@ static uint32_t resource_id_counter = 2; /* id 1 used for internal rindex lease
#define FREE_RES_COUNT 128
-void free_token(struct token *token) -{ - if (token->caw_dev_fd) - log_errot(token, "free_token leak caw_dev_fd %d", token->caw_dev_fd); - if (token->caw_data) - free(token->caw_data); - free(token); -} - /* * There's not much advantage to saving resource structs and reusing them again * when they are requested again. One advantage can be that the res_id remains diff --git a/src/resource.h b/src/resource.h index 5db54a1..d1fb7a0 100644 --- a/src/resource.h +++ b/src/resource.h @@ -25,7 +25,6 @@ int resource_orphan_count(char *space_name);
/* no locks */ void check_mode_block(struct token *token, uint64_t next_lver, int q, char *dblock); -void free_token(struct token *token);
/* locks resource_mutex */ int convert_token(struct task *task, struct sanlk_resource *res, struct token *cl_token, uint32_t cmd_flags); diff --git a/src/sanlock_internal.c b/src/sanlock_internal.c new file mode 100644 index 0000000..a40672c --- /dev/null +++ b/src/sanlock_internal.c @@ -0,0 +1,32 @@ +#include <stdint.h> +#include <stdlib.h> +#include <syslog.h> + +#include "sanlock_internal.h" +#include "log.h" + +/* Moved from resource.c to prevent circular dependency */ +void free_token(struct token *token) +{ + if (token->caw_dev_fd) + log_debug("free_token leak caw_dev_fd %d", token->caw_dev_fd); + if (token->caw_data) + free(token->caw_data); + free(token); +} + +/* Moved from lockspace.c to prevent circular dependency */ +void set_id_bit(int host_id, char *bitmap, char *c) +{ + char *byte = bitmap + ((host_id - 1) / 8); + unsigned int bit = (host_id - 1) % 8; + char mask; + + mask = 1 << bit; + + *byte |= mask; + + if (c) + *c = *byte; +} + diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h index 99f7250..52e5c22 100644 --- a/src/sanlock_internal.h +++ b/src/sanlock_internal.h @@ -509,6 +509,10 @@ void clear_cmd_debug(uint32_t cmd); /* main.c */ const char *host_state_str(uint32_t flags);
+/* sanlock_internal.c */ +void free_token(struct token *token); +void set_id_bit(int host_id, char *bitmap, char *c); + /* command line types and actions */
#define COM_DAEMON 1
sanlock-devel@lists.fedorahosted.org