console-server: refactor pollfd management

Instead of the previous memory management of pollfd array,
with a fixed and flexible part and hardcoded indices,
provide two functions to request and release pollfds.

- console_server_request_pollfd
- console_server_release_pollfd

The pollfds are still in the same array but can be requested and
released by these functions now. struct console_server and
struct console now contain indices into that array of pollfds.

The benefit of this contribution is that the new interface provides a
clean allocator-like abstraction for requesting and releasing pollfds,
which will scale to multiple consoles and can be refactored or
unit-tested more easily in the future.

The previous implementation was tightly coupled to the single-console
use-case and the pollfds stored at hardcoded indices.

Change-Id: I93226699618130b175bffbeb4f71c20c91a7083a
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
3 files changed
tree: 4fec7925297e9d3862a41fd20ffacffdbe15e6e0
  1. conf/
  2. subprojects/
  3. test/
  4. .clang-format
  5. .clang-tidy
  6. .gitignore
  7. .travis.yml
  8. CHANGELOG.md
  9. config-internal.h
  10. config.c
  11. config.h
  12. console-client.c
  13. console-dbus.c
  14. console-server.c
  15. console-server.h
  16. console-socket.c
  17. LICENSE
  18. log-handler.c
  19. meson.build
  20. meson.options
  21. OWNERS
  22. README.md
  23. ringbuffer.c
  24. socket-handler.c
  25. tty-handler.c
  26. util.c
  27. util.h
README.md

To Build

To build this project, run the following shell commands:

meson setup build
meson compile -C build

To test:

meson test -C build

To Run Server

Running the server requires a serial port (e.g. /dev/ttyS0):

touch obmc-console.conf
./obmc-console-server --config obmc-console.conf ttyS0

To Connect Client

To connect to the server, simply run the client:

./obmc-console-client

To disconnect the client, use the standard ~. combination.

Underlying design

This shows how the host UART connection is abstracted within the BMC as a Unix domain socket.

               +---------------------------------------------------------------------------------------------+
               |                                                                                             |
               |       obmc-console-client       unix domain socket         obmc-console-server              |
               |                                                                                             |
               |     +----------------------+                           +------------------------+           |
               |     |   client.2200.conf   |  +---------------------+  | server.ttyVUART0.conf  |           |
           +---+--+  +----------------------+  |                     |  +------------------------+  +--------+-------+
Network    | 2200 +-->                      +->+ @obmc-console.host0 +<-+                        <--+ /dev/ttyVUART0 |   UARTs
           +---+--+  | console-id = "host0" |  |                     |  |  console-id = "host0"  |  +--------+-------+
               |     |                      |  +---------------------+  |                        |           |
               |     +----------------------+                           +------------------------+           |
               |                                                                                             |
               |                                                                                             |
               |                                                                                             |
               +---------------------------------------------------------------------------------------------+

This supports multiple independent consoles. The console-id is a unique portion for the unix domain socket created by the obmc-console-server instance. The server needs to know this because it needs to know what to name the pipe; the client needs to know it as it needs to form the abstract socket name to which to connect.