mctp-demux-daemon: Exploit binding mctp_*_init_pollfd() APIs
Once bindings are correctly implemented as async the daemon itself will
follow.
Finally, now they're unused, drop the mctp_*_get_fd() APIs as they're
strictly less powerful.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ibc2bbc1d75b031e4422429d606e6345d794cb44d
diff --git a/astlpc.c b/astlpc.c
index 4e9e349..b576ba7 100644
--- a/astlpc.c
+++ b/astlpc.c
@@ -1307,11 +1307,6 @@
return rc == 1 ? 0 : -1;
}
-int mctp_astlpc_get_fd(struct mctp_binding_astlpc *astlpc)
-{
- return astlpc->kcs_fd;
-}
-
int mctp_astlpc_init_pollfd(struct mctp_binding_astlpc *astlpc,
struct pollfd *pollfd)
{
@@ -1364,12 +1359,6 @@
return NULL;
}
-int mctp_astlpc_get_fd(struct mctp_binding_astlpc *astlpc __unused)
-{
- mctp_prlog(MCTP_LOG_ERR, "%s: Missing support for file IO", __func__);
- return -1;
-}
-
int mctp_astlpc_init_pollfd(struct mctp_binding_astlpc *astlpc __unused,
struct pollfd *pollfd __unused)
{
diff --git a/libmctp-astlpc.h b/libmctp-astlpc.h
index 243ddd7..ddc5395 100644
--- a/libmctp-astlpc.h
+++ b/libmctp-astlpc.h
@@ -45,7 +45,6 @@
/* fileio-based interface */
struct mctp_binding_astlpc *mctp_astlpc_init_fileio(void);
-int mctp_astlpc_get_fd(struct mctp_binding_astlpc *astlpc);
struct pollfd;
int mctp_astlpc_init_pollfd(struct mctp_binding_astlpc *astlpc,
diff --git a/libmctp-serial.h b/libmctp-serial.h
index 7d3d6cb..a8fc0b4 100644
--- a/libmctp-serial.h
+++ b/libmctp-serial.h
@@ -17,8 +17,6 @@
struct mctp_binding *mctp_binding_serial_core(struct mctp_binding_serial *b);
/* file-based IO */
-int mctp_serial_get_fd(struct mctp_binding_serial *serial);
-
struct pollfd;
int mctp_serial_init_pollfd(struct mctp_binding_serial *serial,
struct pollfd *pollfd);
diff --git a/serial.c b/serial.c
index b12fcfb..312744b 100644
--- a/serial.c
+++ b/serial.c
@@ -287,11 +287,6 @@
return 0;
}
-int mctp_serial_get_fd(struct mctp_binding_serial *serial)
-{
- return serial->fd;
-}
-
int mctp_serial_init_pollfd(struct mctp_binding_serial *serial,
struct pollfd *pollfd)
{
diff --git a/utils/mctp-astlpc-daemon.c b/utils/mctp-astlpc-daemon.c
index 3852bd4..f984eaf 100644
--- a/utils/mctp-astlpc-daemon.c
+++ b/utils/mctp-astlpc-daemon.c
@@ -77,8 +77,7 @@
pollfds[0].fd = STDIN_FILENO;
pollfds[0].events = POLLIN;
- pollfds[1].fd = mctp_astlpc_get_fd(astlpc);
- pollfds[1].events = POLLIN;
+ mctp_astlpc_init_pollfd(astlpc, &pollfds[1]);
rc = poll(pollfds, 2, -1);
if (rc < 0)
diff --git a/utils/mctp-demux-daemon.c b/utils/mctp-demux-daemon.c
index aeb2de0..c356769 100644
--- a/utils/mctp-demux-daemon.c
+++ b/utils/mctp-demux-daemon.c
@@ -44,14 +44,13 @@
static char sockname[] = "\0mctp-mux";
struct binding {
- const char *name;
- int (*init)(struct mctp *mctp, struct binding *binding,
- mctp_eid_t eid, int n_params,
- char * const * params);
- void (*destroy)(struct mctp *mctp, struct binding *binding);
- int (*get_fd)(struct binding *binding);
- int (*process)(struct binding *binding);
- void *data;
+ const char *name;
+ int (*init)(struct mctp *mctp, struct binding *binding, mctp_eid_t eid,
+ int n_params, char *const *params);
+ void (*destroy)(struct mctp *mctp, struct binding *binding);
+ int (*init_pollfd)(struct binding *binding, struct pollfd *pollfd);
+ int (*process)(struct binding *binding);
+ void *data;
};
struct client {
@@ -196,9 +195,10 @@
return 0;
}
-static int binding_serial_get_fd(struct binding *binding)
+static int binding_serial_init_pollfd(struct binding *binding,
+ struct pollfd *pollfd)
{
- return mctp_serial_get_fd(binding->data);
+ return mctp_serial_init_pollfd(binding->data, pollfd);
}
static int binding_serial_process(struct binding *binding)
@@ -238,9 +238,10 @@
mctp_astlpc_destroy(astlpc);
}
-static int binding_astlpc_get_fd(struct binding *binding)
+static int binding_astlpc_init_pollfd(struct binding *binding,
+ struct pollfd *pollfd)
{
- return mctp_astlpc_get_fd(binding->data);
+ return mctp_astlpc_init_pollfd(binding->data, pollfd);
}
static int binding_astlpc_process(struct binding *binding)
@@ -257,14 +258,14 @@
.name = "serial",
.init = binding_serial_init,
.destroy = NULL,
- .get_fd = binding_serial_get_fd,
+ .init_pollfd = binding_serial_init_pollfd,
.process = binding_serial_process,
},
{
.name = "astlpc",
.init = binding_astlpc_init,
.destroy = binding_astlpc_destroy,
- .get_fd = binding_astlpc_get_fd,
+ .init_pollfd = binding_astlpc_init_pollfd,
.process = binding_astlpc_process,
}
};
@@ -461,11 +462,7 @@
ctx->pollfds = malloc(FD_NR * sizeof(struct pollfd));
- if (ctx->binding->get_fd) {
- ctx->pollfds[FD_BINDING].fd =
- ctx->binding->get_fd(ctx->binding);
- ctx->pollfds[FD_BINDING].events = POLLIN;
- } else {
+ if (!ctx->binding->init_pollfd) {
ctx->pollfds[FD_BINDING].fd = -1;
ctx->pollfds[FD_BINDING].events = 0;
}
@@ -504,6 +501,9 @@
clients_changed = false;
}
+ if (ctx->binding->init_pollfd)
+ ctx->binding->init_pollfd(ctx->binding,
+ &ctx->pollfds[FD_BINDING]);
rc = poll(ctx->pollfds, ctx->n_clients + FD_NR, -1);
if (rc < 0) {
warn("poll failed");