Skip to content

Commit

Permalink
Move shmem to an extern
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed Oct 21, 2021
1 parent e25ae96 commit 391d106
Show file tree
Hide file tree
Showing 24 changed files with 749 additions and 507 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Copyright (C) 2020 Red Hat
Copyright (C) 2021 Red Hat

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Expand Down
3 changes: 2 additions & 1 deletion doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ See a [sample](./etc/pgprtdbg.conf) configuration for running `pgprtdbg` on `loc
| host | | String | Yes | The bind address for pgprtdbg |
| port | | Int | Yes | The bind port for pgprtdbg |
| output | | String | Yes | The output location |
| unix_socket_dir | | String | No | The Unix Domain Socket directory |
| log_type | console | String | No | The logging type (console, file) |
| log_path | pgprtdbg.log | String | No | The log file location |
| output_sockets | off | Bool | No | Output socket descriptors |
| libev | `auto` | String | No | Select the [libev](http://software.schmorp.de/pkg/libev.html) backend to use. Valid options: `auto`, `select`, `poll`, `epoll`, `linuxaio`, `iouring`, `devpoll` and `port` |
| buffer_size | 65535 | Int | No | The network buffer size (`SO_RCVBUF` and `SO_SNDBUF`) |
| keep_alive | on | Bool | No | Have `SO_KEEPALIVE` on sockets |
| nodelay | on | Bool | No | Have `TCP_NODELAY` on sockets |
| nodelay | off | Bool | No | Have `TCP_NODELAY` on sockets |
| backlog | 4 | Int | No | The backlog for `listen()` |

## Server section
Expand Down
12 changes: 4 additions & 8 deletions src/include/configuration.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Red Hat
* Copyright (C) 2021 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -37,29 +37,25 @@ extern "C" {

/**
* Initialize the configuration structure
* @param shmem The shared memory segment
* @param size The size of the configuration
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_init_configuration(void* shmem, size_t size);
pgprtdbg_init_configuration(void);

/**
* Read the configuration from a file
* @param filename The file name
* @param shmem The shared memory segment
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_read_configuration(char* filename, void* shmem);
pgprtdbg_read_configuration(char* filename);

/**
* Validate the configuration
* @param filename The file name
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_validate_configuration(void* shmem);
pgprtdbg_validate_configuration(void);

#ifdef __cplusplus
}
Expand Down
20 changes: 7 additions & 13 deletions src/include/logging.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Red Hat
* Copyright (C) 2021 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -40,50 +40,44 @@ extern "C" {

/**
* Start the logging system
* @param shmem The shared memory segment
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_start_logging(void* shmem);
pgprtdbg_start_logging(void);

/**
* Stop the logging system
* @param shmem The shared memory segment
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_stop_logging(void* shmem);
pgprtdbg_stop_logging(void);

/**
* Lock the log
* @param shmem The shared memory segment
*/
void
pgprtdbg_log_lock(void* shmem);
pgprtdbg_log_lock(void);

/**
* Unlock the log
* @param shmem The shared memory segment
*/
void
pgprtdbg_log_unlock(void* shmem);
pgprtdbg_log_unlock(void);

/**
* Log a line
* @param shmem The shared memory segment
* @param fmt The string format
*/
void
pgprtdbg_log_line(void* shmem, char* fmt, ...);
pgprtdbg_log_line(char* fmt, ...);

/**
* Log a data segment
* @param shmem The shared memory segment
* @param data The data
* @param size The sie of the data
*/
void
pgprtdbg_log_mem(void* shmem, void* data, size_t size);
pgprtdbg_log_mem(void* data, size_t size);

#ifdef __cplusplus
}
Expand Down
5 changes: 2 additions & 3 deletions src/include/memory.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Red Hat
* Copyright (C) 2021 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -39,10 +39,9 @@ extern "C" {

/**
* Initialize a memory segment for the process local message structure
* @param shmem The shared memory segment
*/
void
pgprtdbg_memory_init(void* shmem);
pgprtdbg_memory_init(void);

/**
* Get the message structure
Expand Down
2 changes: 1 addition & 1 deletion src/include/message.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Red Hat
* Copyright (C) 2021 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down
35 changes: 21 additions & 14 deletions src/include/network.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Red Hat
* Copyright (C) 2021 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -40,58 +40,65 @@ extern "C" {
* Bind sockets for a host
* @param hostname The host name
* @param port The port number
* @param shmem The shared memory segment
* @param fds The resulting descriptors
* @param length The resulting length of descriptors
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_bind(const char* hostname, int port, void* shmem, int** fds, int* length);
pgprtdbg_bind(const char* hostname, int port, int** fds, int* length);

/**
* Connect to a host
* @param shmem The shared memory segment
* @param hostname The host name
* @param port The port number
* @param fd The resulting descriptor
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_connect(void* shmem, const char* hostname, int port, int* fd);
pgprtdbg_connect(const char* hostname, int port, int* fd);

/**
* Shutdown a descriptor
* Disconnect from a descriptor
* @param fd The descriptor
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_shutdown(int fd);
pgprtdbg_disconnect(int fd);

/**
* Disconnect from a descriptor
* @param fd The descriptor
* Bind a Unix Domain Socket
* @param directory The directory
* @param file The file
* @param fd The resulting descriptor
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_disconnect(int fd);
pgprtdbg_bind_unix_socket(const char* directory, const char* file, int* fd);

/**
* Remove Unix Domain Socket directory
* @param directory The directory
* @param file The file
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_remove_unix_socket(const char* directory, const char* file);

/**
* Apply TCP/NODELAY to a descriptor
* @param fd The descriptor
* @param shmem The shared memory segment
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_tcp_nodelay(int fd, void* shmem);
pgprtdbg_tcp_nodelay(int fd);

/**
* Set the configured socket buffer size to a descriptor
* @param fd The descriptor
* @param shmem The shared memory segment
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_socket_buffers(int fd, void* shmem);
pgprtdbg_socket_buffers(int fd);

#ifdef __cplusplus
}
Expand Down
18 changes: 8 additions & 10 deletions src/include/pgprtdbg.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Red Hat
* Copyright (C) 2021 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -58,6 +58,11 @@ extern "C" {
#define likely(x) __builtin_expect (!!(x), 1)
#define unlikely(x) __builtin_expect (!!(x), 0)

/**
* The shared memory segment
*/
extern void* shmem;

/** @struct
* Defines a server
*/
Expand All @@ -82,6 +87,8 @@ struct configuration

bool output_sockets; /**< Output socket identifiers */

char unix_socket_dir[MISC_LENGTH]; /**< The directory for the Unix Domain Socket */

int log_type; /**< The logging type */
char log_path[MISC_LENGTH]; /**< The logging path */
atomic_schar log_lock; /**< The logging lock */
Expand Down Expand Up @@ -109,15 +116,6 @@ struct message
void* data; /**< The message data */
} __attribute__ ((aligned (64)));

/** @struct
* Defines the signal structure
*/
struct signal_info
{
struct ev_signal signal; /**< The libev base type */
void* shmem; /**< The shared memory segment */
};

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/include/pipeline.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Red Hat
* Copyright (C) 2021 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down
8 changes: 3 additions & 5 deletions src/include/protocol.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Red Hat
* Copyright (C) 2021 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -41,21 +41,19 @@ extern "C" {
* Decode a message from the client
* @param from The from socket
* @param to The to socket
* @param shmem The shared memory segment
* @param msg The message
*/
void
pgprtdbg_client(int from, int to, void* shmem, struct message* msg);
pgprtdbg_client(int from, int to, struct message* msg);

/**
* Decode a message from the server
* @param from The from socket
* @param to The to socket
* @param shmem The shared memory segment
* @param msg The message
*/
void
pgprtdbg_server(int from, int to, void* shmem, struct message* msg);
pgprtdbg_server(int from, int to, struct message* msg);

#ifdef __cplusplus
}
Expand Down
9 changes: 4 additions & 5 deletions src/include/shmem.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Red Hat
* Copyright (C) 2021 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -38,19 +38,18 @@ extern "C" {
/**
* Create a shared memory segment
* @param size The size of the segment
* @return The pointer to the segment
* @return The result
*/
void*
int
pgprtdbg_create_shared_memory(size_t size);

/**
* Destroy a shared memory segment
* @param shmem The shared memory segment
* @param size The size
* @return 0 upon success, otherwise 1
*/
int
pgprtdbg_destroy_shared_memory(void* shmem, size_t size);
pgprtdbg_destroy_shared_memory(size_t size);

#ifdef __cplusplus
}
Expand Down
8 changes: 3 additions & 5 deletions src/include/utils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Red Hat
* Copyright (C) 2021 Red Hat
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -111,19 +111,17 @@ pgprtdbg_write_string(void* data, char* s);

/**
* Print the available libev engines
* @param shmem The shared memory segment
*/
void
pgprtdbg_libev_engines(void* shmem);
pgprtdbg_libev_engines(void);

/**
* Get the constant for a libev engine
* @param shmem The shared memory segment
* @param engine The name of the engine
* @return The constant
*/
unsigned int
pgprtdbg_libev(void* shmem, char* engine);
pgprtdbg_libev(char* engine);

/**
* Get the name for a libev engine
Expand Down
Loading

0 comments on commit 391d106

Please sign in to comment.