From b900adc55ce2609faf0b8acb62ab88507cddee42 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 23 Oct 2015 14:11:53 +1100 Subject: [PATCH] ctdb-daemon: Separate prototypes for system specific functions This groups function prototypes for system specific functions in common/system.h and removes them from ctdb_private.h. Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/client/ctdb_client.c | 1 + ctdb/common/ctdb_fork.c | 1 + ctdb/common/ctdb_io.c | 2 + ctdb/common/ctdb_util.c | 1 + ctdb/common/system.h | 66 +++++++++++++++++++++++++++++ ctdb/common/system_aix.c | 1 + ctdb/common/system_common.c | 2 + ctdb/common/system_freebsd.c | 1 + ctdb/common/system_gnu.c | 1 + ctdb/common/system_kfreebsd.c | 1 + ctdb/common/system_linux.c | 2 + ctdb/common/system_util.c | 2 + ctdb/include/ctdb_private.h | 35 --------------- ctdb/server/ctdb_call.c | 1 + ctdb/server/ctdb_daemon.c | 1 + ctdb/server/ctdb_event_helper.c | 1 + ctdb/server/ctdb_lock.c | 1 + ctdb/server/ctdb_lock_helper.c | 1 + ctdb/server/ctdb_logging.c | 1 + ctdb/server/ctdb_logging_file.c | 1 + ctdb/server/ctdb_ltdb_server.c | 1 + ctdb/server/ctdb_monitor.c | 1 + ctdb/server/ctdb_recover.c | 2 +- ctdb/server/ctdb_recoverd.c | 1 + ctdb/server/ctdb_takeover.c | 1 + ctdb/server/ctdb_traverse.c | 1 + ctdb/server/ctdb_update_record.c | 1 + ctdb/server/ctdb_vacuum.c | 1 + ctdb/server/ctdbd.c | 1 + ctdb/server/eventscript.c | 1 + ctdb/tcp/tcp_connect.c | 1 + ctdb/tests/src/ctdb_porting_tests.c | 1 + ctdb/tools/ctdb.c | 1 + ctdb/utils/pmda/pmda_ctdb.c | 1 + 34 files changed, 102 insertions(+), 36 deletions(-) create mode 100644 ctdb/common/system.h diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c index b8e7e104187..f0fbea40bc2 100644 --- a/ctdb/client/ctdb_client.c +++ b/ctdb/client/ctdb_client.c @@ -29,6 +29,7 @@ #include "../include/ctdb_private.h" #include "lib/util/dlinklist.h" #include "common/reqid.h" +#include "common/system.h" /* allocate a packet for use in client<->daemon communication diff --git a/ctdb/common/ctdb_fork.c b/ctdb/common/ctdb_fork.c index 8d38150de13..336bc8ee134 100644 --- a/ctdb/common/ctdb_fork.c +++ b/ctdb/common/ctdb_fork.c @@ -22,6 +22,7 @@ #include "../include/ctdb_client.h" #include "../include/ctdb_private.h" #include "../common/rb_tree.h" +#include "common/system.h" void ctdb_set_child_info(TALLOC_CTX *mem_ctx, const char *child_name_fmt, ...) { diff --git a/ctdb/common/ctdb_io.c b/ctdb/common/ctdb_io.c index 53486f43da6..2318364439a 100644 --- a/ctdb/common/ctdb_io.c +++ b/ctdb/common/ctdb_io.c @@ -29,6 +29,8 @@ #include "../include/ctdb_client.h" #include +#include "common/system.h" + #define QUEUE_BUFFER_SIZE (16*1024) /* structures for packet queueing - see common/ctdb_io.c */ diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c index 2864834a253..474ebfa9faf 100644 --- a/ctdb/common/ctdb_util.c +++ b/ctdb/common/ctdb_util.c @@ -24,6 +24,7 @@ #include "system/wait.h" #include "../include/ctdb_private.h" #include "common/reqid.h" +#include "common/system.h" /* return error string for last error diff --git a/ctdb/common/system.h b/ctdb/common/system.h new file mode 100644 index 00000000000..8df87cdf49b --- /dev/null +++ b/ctdb/common/system.h @@ -0,0 +1,66 @@ +/* + System specific code + + Copyright (C) Amitay Isaacs 2015 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#ifndef __CTDB_SYSTEM_H__ +#define __CTDB_SYSTEM_H__ + +/* From system_common.c */ + +uint32_t uint16_checksum(uint16_t *data, size_t n); +bool ctdb_sys_have_ip(ctdb_sock_addr *_addr); +char *ctdb_sys_find_ifname(ctdb_sock_addr *addr); + +/* From system_.c */ + +int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface); +int ctdb_sys_send_tcp(const ctdb_sock_addr *dest, + const ctdb_sock_addr *src, + uint32_t seq, uint32_t ack, int rst); +int ctdb_sys_open_capture_socket(const char *iface, void **private_data); +int ctdb_sys_close_capture_socket(void *private_data); +int ctdb_sys_read_tcp_packet(int s, void *private_data, + ctdb_sock_addr *src, ctdb_sock_addr *dst, + uint32_t *ack_seq, uint32_t *seq); +bool ctdb_sys_check_iface_exists(const char *iface); +int ctdb_get_peer_pid(const int fd, pid_t *peer_pid); +int ctdb_set_process_name(const char *name); + +/* From system_util.c */ + +bool set_scheduler(void); +void reset_scheduler(void); +void set_nonblocking(int fd); +void set_close_on_exec(int fd); + +bool parse_ipv4(const char *s, unsigned port, struct sockaddr_in *sin); +bool parse_ip(const char *addr, const char *ifaces, unsigned port, + ctdb_sock_addr *saddr); +bool parse_ip_mask(const char *str, const char *ifaces, ctdb_sock_addr *addr, + unsigned *mask); +bool parse_ip_port(const char *addr, ctdb_sock_addr *saddr); + +void lockdown_memory(bool valgrinding); + +int mkdir_p(const char *dir, int mode); +void mkdir_p_or_die(const char *dir, int mode); + +ssize_t sys_read(int fd, void *buf, size_t count); +ssize_t sys_write(int fd, const void *buf, size_t count); + +#endif /* __CTDB_SYSTEM_H__ */ diff --git a/ctdb/common/system_aix.c b/ctdb/common/system_aix.c index a98d3820567..59ee87185f6 100644 --- a/ctdb/common/system_aix.c +++ b/ctdb/common/system_aix.c @@ -31,6 +31,7 @@ #include #include +#include "common/system.h" #if 0 diff --git a/ctdb/common/system_common.c b/ctdb/common/system_common.c index 899f3b56beb..1e0a095ec8c 100644 --- a/ctdb/common/system_common.c +++ b/ctdb/common/system_common.c @@ -23,6 +23,8 @@ #include "ctdb_private.h" +#include "common/system.h" + /* uint16 checksum for n bytes */ diff --git a/ctdb/common/system_freebsd.c b/ctdb/common/system_freebsd.c index c5a816bf7af..e132e5ce493 100644 --- a/ctdb/common/system_freebsd.c +++ b/ctdb/common/system_freebsd.c @@ -34,6 +34,7 @@ #include #include +#include "common/system.h" #ifndef ETHERTYPE_IP6 #define ETHERTYPE_IP6 0x86dd diff --git a/ctdb/common/system_gnu.c b/ctdb/common/system_gnu.c index bf8f43c4868..7921655b5c7 100644 --- a/ctdb/common/system_gnu.c +++ b/ctdb/common/system_gnu.c @@ -33,6 +33,7 @@ #include #include +#include "common/system.h" #ifndef ETHERTYPE_IP6 #define ETHERTYPE_IP6 0x86dd diff --git a/ctdb/common/system_kfreebsd.c b/ctdb/common/system_kfreebsd.c index de7c8911c89..dd7f71a6af2 100644 --- a/ctdb/common/system_kfreebsd.c +++ b/ctdb/common/system_kfreebsd.c @@ -33,6 +33,7 @@ #include #include +#include "common/system.h" #ifndef ETHERTYPE_IP6 #define ETHERTYPE_IP6 0x86dd diff --git a/ctdb/common/system_linux.c b/ctdb/common/system_linux.c index 79d1a83ff10..bca928dc2f2 100644 --- a/ctdb/common/system_linux.c +++ b/ctdb/common/system_linux.c @@ -30,6 +30,8 @@ #include #include +#include "common/system.h" + #ifndef ETHERTYPE_IP6 #define ETHERTYPE_IP6 0x86dd #endif diff --git a/ctdb/common/system_util.c b/ctdb/common/system_util.c index 663df6e6b57..088d86b449c 100644 --- a/ctdb/common/system_util.c +++ b/ctdb/common/system_util.c @@ -26,6 +26,8 @@ #include "ctdb_private.h" +#include "common/system.h" + #if HAVE_SCHED_H #include #endif diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 74a155c8c1a..18e9a556ca5 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -1010,8 +1010,6 @@ void ctdb_call_resend_all(struct ctdb_context *ctdb); void ctdb_node_dead(struct ctdb_node *node); void ctdb_node_connected(struct ctdb_node *node); bool ctdb_blocking_freeze(struct ctdb_context *ctdb); -bool set_scheduler(void); -void reset_scheduler(void); struct tevent_signal *ctdb_init_sigchld(struct ctdb_context *ctdb); void ctdb_track_child(struct ctdb_context *ctdb, pid_t pid); @@ -1099,17 +1097,6 @@ int ctdb_ctrl_set_iface_link(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, const struct ctdb_control_iface_info *info); -/* from takeover/system.c */ -uint32_t uint16_checksum(uint16_t *data, size_t n); -int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface); -bool ctdb_sys_have_ip(ctdb_sock_addr *addr); -char *ctdb_sys_find_ifname(ctdb_sock_addr *addr); -bool ctdb_sys_check_iface_exists(const char *iface); -int ctdb_get_peer_pid(const int fd, pid_t *peer_pid); -int ctdb_sys_send_tcp(const ctdb_sock_addr *dest, - const ctdb_sock_addr *src, - uint32_t seq, uint32_t ack, int rst); - /* Details of a byte range lock */ struct ctdb_lock_info { ino_t inode; @@ -1118,8 +1105,6 @@ struct ctdb_lock_info { bool read_only; }; -int ctdb_set_process_name(const char *name); - typedef void (*client_async_callback)(struct ctdb_context *ctdb, uint32_t node_pnn, int32_t res, TDB_DATA outdata, void *callback_data); int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses); @@ -1153,9 +1138,6 @@ int ctdb_event_script_callback(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(6,7); void ctdb_release_all_ips(struct ctdb_context *ctdb); -void set_nonblocking(int fd); -void set_close_on_exec(int fd); - bool ctdb_recovery_have_lock(struct ctdb_context *ctdb); bool ctdb_recovery_lock(struct ctdb_context *ctdb); void ctdb_recovery_unlock(struct ctdb_context *ctdb); @@ -1182,16 +1164,6 @@ int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_tunable *tunables); -bool parse_ip_mask(const char *s, const char *iface, ctdb_sock_addr *addr, unsigned *mask); -bool parse_ip_port(const char *s, ctdb_sock_addr *addr); -bool parse_ip(const char *s, const char *iface, unsigned port, ctdb_sock_addr *addr); -bool parse_ipv4(const char *s, unsigned port, struct sockaddr_in *sin); - - -int ctdb_sys_open_capture_socket(const char *iface, void **private_data); -int ctdb_sys_close_capture_socket(void *private_data); -int ctdb_sys_read_tcp_packet(int s, void *private_data, ctdb_sock_addr *src, ctdb_sock_addr *dst, uint32_t *ack_seq, uint32_t *seq); - int ctdb_ctrl_killtcp(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, @@ -1267,7 +1239,6 @@ int32_t ctdb_control_db_get_health(struct ctdb_context *ctdb, int32_t ctdb_monitoring_mode(struct ctdb_context *ctdb); bool ctdb_stopped_monitoring(struct ctdb_context *ctdb); int ctdb_set_child_logging(struct ctdb_context *ctdb); -void lockdown_memory(bool valgrinding); struct client_async_data { enum ctdb_controls opcode; @@ -1491,10 +1462,4 @@ struct lock_request *ctdb_lock_alldb(TALLOC_CTX *mem_ctx, void (*callback)(void *, bool), void *private_data); -int mkdir_p(const char *dir, int mode); -void mkdir_p_or_die(const char *dir, int mode); - -ssize_t sys_read(int fd, void *buf, size_t count); -ssize_t sys_write(int fd, const void *buf, size_t count); - #endif diff --git a/ctdb/server/ctdb_call.c b/ctdb/server/ctdb_call.c index e767bf72c0e..cecdce294c4 100644 --- a/ctdb/server/ctdb_call.c +++ b/ctdb/server/ctdb_call.c @@ -28,6 +28,7 @@ #include "../include/ctdb_private.h" #include "../common/rb_tree.h" #include "common/reqid.h" +#include "common/system.h" struct ctdb_sticky_record { struct ctdb_context *ctdb; diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c index 0287a67649b..f7798671abe 100644 --- a/ctdb/server/ctdb_daemon.c +++ b/ctdb/server/ctdb_daemon.c @@ -30,6 +30,7 @@ #include "../common/rb_tree.h" #include #include "common/reqid.h" +#include "common/system.h" struct ctdb_client_pid_list { struct ctdb_client_pid_list *next, *prev; diff --git a/ctdb/server/ctdb_event_helper.c b/ctdb/server/ctdb_event_helper.c index a1b53188225..7d24820d6df 100644 --- a/ctdb/server/ctdb_event_helper.c +++ b/ctdb/server/ctdb_event_helper.c @@ -20,6 +20,7 @@ #include "includes.h" #include "system/filesys.h" #include "ctdb_private.h" +#include "common/system.h" static char *progname = NULL; diff --git a/ctdb/server/ctdb_lock.c b/ctdb/server/ctdb_lock.c index d8d4f5a6e3c..104ebcd97f4 100644 --- a/ctdb/server/ctdb_lock.c +++ b/ctdb/server/ctdb_lock.c @@ -25,6 +25,7 @@ #include "lib/tdb_wrap/tdb_wrap.h" #include "system/filesys.h" #include "lib/util/dlinklist.h" +#include "common/system.h" /* * Non-blocking Locking API diff --git a/ctdb/server/ctdb_lock_helper.c b/ctdb/server/ctdb_lock_helper.c index 7a09ecf3c70..c48a925bd95 100644 --- a/ctdb/server/ctdb_lock_helper.c +++ b/ctdb/server/ctdb_lock_helper.c @@ -21,6 +21,7 @@ #include "tdb.h" #include "system/filesys.h" #include "ctdb_private.h" +#include "common/system.h" static char *progname = NULL; diff --git a/ctdb/server/ctdb_logging.c b/ctdb/server/ctdb_logging.c index 129bdc9e7f6..b2e8a6ec447 100644 --- a/ctdb/server/ctdb_logging.c +++ b/ctdb/server/ctdb_logging.c @@ -25,6 +25,7 @@ #include "system/filesys.h" #include "lib/util/debug.h" #include "lib/util/dlinklist.h" +#include "common/system.h" struct ctdb_log_backend { struct ctdb_log_backend *prev, *next; diff --git a/ctdb/server/ctdb_logging_file.c b/ctdb/server/ctdb_logging_file.c index f931b4a8b83..24a4167f6ea 100644 --- a/ctdb/server/ctdb_logging_file.c +++ b/ctdb/server/ctdb_logging_file.c @@ -23,6 +23,7 @@ #include "system/time.h" #include "system/filesys.h" #include "lib/util/time_basic.h" +#include "common/system.h" #define CTDB_LOG_FILE_PREFIX "file" diff --git a/ctdb/server/ctdb_ltdb_server.c b/ctdb/server/ctdb_ltdb_server.c index 3386bba2c3e..5e4128bd326 100644 --- a/ctdb/server/ctdb_ltdb_server.c +++ b/ctdb/server/ctdb_ltdb_server.c @@ -29,6 +29,7 @@ #include "lib/util/dlinklist.h" #include #include "common/reqid.h" +#include "common/system.h" #define PERSISTENT_HEALTH_TDB "persistent_health.tdb" diff --git a/ctdb/server/ctdb_monitor.c b/ctdb/server/ctdb_monitor.c index edaae48ff8e..493e55a02ae 100644 --- a/ctdb/server/ctdb_monitor.c +++ b/ctdb/server/ctdb_monitor.c @@ -22,6 +22,7 @@ #include "system/filesys.h" #include "system/wait.h" #include "../include/ctdb_private.h" +#include "common/system.h" struct ctdb_monitor_state { uint32_t monitoring_mode; diff --git a/ctdb/server/ctdb_recover.c b/ctdb/server/ctdb_recover.c index b57aa8ef7c8..6ec66ded31f 100644 --- a/ctdb/server/ctdb_recover.c +++ b/ctdb/server/ctdb_recover.c @@ -26,7 +26,7 @@ #include "../include/ctdb_private.h" #include "lib/util/dlinklist.h" #include "lib/tdb_wrap/tdb_wrap.h" - +#include "common/system.h" int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata) diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index e945d51f2eb..61658c633e4 100644 --- a/ctdb/server/ctdb_recoverd.c +++ b/ctdb/server/ctdb_recoverd.c @@ -28,6 +28,7 @@ #include "../include/ctdb_private.h" #include "lib/tdb_wrap/tdb_wrap.h" #include "lib/util/dlinklist.h" +#include "common/system.h" /* List of SRVID requests that need to be processed */ diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 098cfe734f1..d1330f1ff37 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -27,6 +27,7 @@ #include "../include/ctdb_private.h" #include "../common/rb_tree.h" #include "common/reqid.h" +#include "common/system.h" #define TAKEOVER_TIMEOUT() timeval_current_ofs(ctdb->tunable.takeover_timeout,0) diff --git a/ctdb/server/ctdb_traverse.c b/ctdb/server/ctdb_traverse.c index 88528c52676..3b7eae80a6c 100644 --- a/ctdb/server/ctdb_traverse.c +++ b/ctdb/server/ctdb_traverse.c @@ -25,6 +25,7 @@ #include "../include/ctdb_private.h" #include "lib/util/dlinklist.h" #include "common/reqid.h" +#include "common/system.h" typedef void (*ctdb_traverse_fn_t)(void *private_data, TDB_DATA key, TDB_DATA data); diff --git a/ctdb/server/ctdb_update_record.c b/ctdb/server/ctdb_update_record.c index 418bbb10e1c..3b5ea689730 100644 --- a/ctdb/server/ctdb_update_record.c +++ b/ctdb/server/ctdb_update_record.c @@ -22,6 +22,7 @@ #include "lib/tdb_wrap/tdb_wrap.h" #include "tdb.h" #include "ctdb_private.h" +#include "common/system.h" struct ctdb_persistent_write_state { struct ctdb_db_context *ctdb_db; diff --git a/ctdb/server/ctdb_vacuum.c b/ctdb/server/ctdb_vacuum.c index d678ff98ab3..39eed0b74e5 100644 --- a/ctdb/server/ctdb_vacuum.c +++ b/ctdb/server/ctdb_vacuum.c @@ -29,6 +29,7 @@ #include "lib/util/dlinklist.h" #include "../include/ctdb_private.h" #include "../common/rb_tree.h" +#include "common/system.h" #define TIMELIMIT() timeval_current_ofs(10, 0) diff --git a/ctdb/server/ctdbd.c b/ctdb/server/ctdbd.c index ac289c6f2d4..aebbc041ad1 100644 --- a/ctdb/server/ctdbd.c +++ b/ctdb/server/ctdbd.c @@ -26,6 +26,7 @@ #include "cmdline.h" #include "../include/ctdb_private.h" #include "common/reqid.h" +#include "common/system.h" static struct { const char *nlist; diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 49619b27063..b1b77cd1cdd 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -26,6 +26,7 @@ #include "../include/ctdb_private.h" #include "../common/rb_tree.h" #include "lib/util/dlinklist.h" +#include "common/system.h" static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *p); diff --git a/ctdb/tcp/tcp_connect.c b/ctdb/tcp/tcp_connect.c index 93049232d62..5935bf44665 100644 --- a/ctdb/tcp/tcp_connect.c +++ b/ctdb/tcp/tcp_connect.c @@ -23,6 +23,7 @@ #include "system/network.h" #include "system/filesys.h" #include "../include/ctdb_private.h" +#include "common/system.h" #include "ctdb_tcp.h" /* diff --git a/ctdb/tests/src/ctdb_porting_tests.c b/ctdb/tests/src/ctdb_porting_tests.c index a4dda1930d0..c8e268f58a1 100644 --- a/ctdb/tests/src/ctdb_porting_tests.c +++ b/ctdb/tests/src/ctdb_porting_tests.c @@ -22,6 +22,7 @@ #include "system/filesys.h" #include "popt.h" #include "cmdline.h" +#include "common/system.h" static struct { const char *socketname; diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 013a484cc5f..5e676f72179 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -31,6 +31,7 @@ #include "../common/rb_tree.h" #include "lib/tdb_wrap/tdb_wrap.h" #include "lib/util/dlinklist.h" +#include "common/system.h" #define ERR_TIMEOUT 20 /* timed out trying to reach node */ #define ERR_NONODE 21 /* node does not exist */ diff --git a/ctdb/utils/pmda/pmda_ctdb.c b/ctdb/utils/pmda/pmda_ctdb.c index 114584423ae..f1a90c48b86 100644 --- a/ctdb/utils/pmda/pmda_ctdb.c +++ b/ctdb/utils/pmda/pmda_ctdb.c @@ -26,6 +26,7 @@ #include "ctdb_private.h" #include "ctdb_protocol.h" #include "domain.h" +#include "common/system.h" /* * CTDB PMDA