Skip to content

Commit 8f53d63

Browse files
committed
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 <[email protected]> Change-Id: Ibc2bbc1d75b031e4422429d606e6345d794cb44d
1 parent 1111c6a commit 8f53d63

6 files changed

+20
-40
lines changed

astlpc.c

-11
Original file line numberDiff line numberDiff line change
@@ -1307,11 +1307,6 @@ static int __mctp_astlpc_fileio_kcs_write(void *arg,
13071307
return rc == 1 ? 0 : -1;
13081308
}
13091309

1310-
int mctp_astlpc_get_fd(struct mctp_binding_astlpc *astlpc)
1311-
{
1312-
return astlpc->kcs_fd;
1313-
}
1314-
13151310
int mctp_astlpc_init_pollfd(struct mctp_binding_astlpc *astlpc,
13161311
struct pollfd *pollfd)
13171312
{
@@ -1364,12 +1359,6 @@ struct mctp_binding_astlpc *mctp_astlpc_init_fileio(void)
13641359
return NULL;
13651360
}
13661361

1367-
int mctp_astlpc_get_fd(struct mctp_binding_astlpc *astlpc __unused)
1368-
{
1369-
mctp_prlog(MCTP_LOG_ERR, "%s: Missing support for file IO", __func__);
1370-
return -1;
1371-
}
1372-
13731362
int mctp_astlpc_init_pollfd(struct mctp_binding_astlpc *astlpc __unused,
13741363
struct pollfd *pollfd __unused)
13751364
{

libmctp-astlpc.h

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ int mctp_astlpc_poll(struct mctp_binding_astlpc *astlpc);
4545

4646
/* fileio-based interface */
4747
struct mctp_binding_astlpc *mctp_astlpc_init_fileio(void);
48-
int mctp_astlpc_get_fd(struct mctp_binding_astlpc *astlpc);
4948

5049
struct pollfd;
5150
int mctp_astlpc_init_pollfd(struct mctp_binding_astlpc *astlpc,

libmctp-serial.h

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ void mctp_serial_destroy(struct mctp_binding_serial *serial);
1717
struct mctp_binding *mctp_binding_serial_core(struct mctp_binding_serial *b);
1818

1919
/* file-based IO */
20-
int mctp_serial_get_fd(struct mctp_binding_serial *serial);
21-
2220
struct pollfd;
2321
int mctp_serial_init_pollfd(struct mctp_binding_serial *serial,
2422
struct pollfd *pollfd);

serial.c

-5
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,6 @@ int mctp_serial_read(struct mctp_binding_serial *serial)
287287
return 0;
288288
}
289289

290-
int mctp_serial_get_fd(struct mctp_binding_serial *serial)
291-
{
292-
return serial->fd;
293-
}
294-
295290
int mctp_serial_init_pollfd(struct mctp_binding_serial *serial,
296291
struct pollfd *pollfd)
297292
{

utils/mctp-astlpc-daemon.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ int main(void)
7777
pollfds[0].fd = STDIN_FILENO;
7878
pollfds[0].events = POLLIN;
7979

80-
pollfds[1].fd = mctp_astlpc_get_fd(astlpc);
81-
pollfds[1].events = POLLIN;
80+
mctp_astlpc_init_pollfd(astlpc, &pollfds[1]);
8281

8382
rc = poll(pollfds, 2, -1);
8483
if (rc < 0)

utils/mctp-demux-daemon.c

+19-19
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@ static const mctp_eid_t local_eid_default = 8;
4444
static char sockname[] = "\0mctp-mux";
4545

4646
struct binding {
47-
const char *name;
48-
int (*init)(struct mctp *mctp, struct binding *binding,
49-
mctp_eid_t eid, int n_params,
50-
char * const * params);
51-
void (*destroy)(struct mctp *mctp, struct binding *binding);
52-
int (*get_fd)(struct binding *binding);
53-
int (*process)(struct binding *binding);
54-
void *data;
47+
const char *name;
48+
int (*init)(struct mctp *mctp, struct binding *binding, mctp_eid_t eid,
49+
int n_params, char *const *params);
50+
void (*destroy)(struct mctp *mctp, struct binding *binding);
51+
int (*init_pollfd)(struct binding *binding, struct pollfd *pollfd);
52+
int (*process)(struct binding *binding);
53+
void *data;
5554
};
5655

5756
struct client {
@@ -196,9 +195,10 @@ static int binding_serial_init(struct mctp *mctp, struct binding *binding,
196195
return 0;
197196
}
198197

199-
static int binding_serial_get_fd(struct binding *binding)
198+
static int binding_serial_init_pollfd(struct binding *binding,
199+
struct pollfd *pollfd)
200200
{
201-
return mctp_serial_get_fd(binding->data);
201+
return mctp_serial_init_pollfd(binding->data, pollfd);
202202
}
203203

204204
static int binding_serial_process(struct binding *binding)
@@ -238,9 +238,10 @@ static void binding_astlpc_destroy(struct mctp *mctp, struct binding *binding)
238238
mctp_astlpc_destroy(astlpc);
239239
}
240240

241-
static int binding_astlpc_get_fd(struct binding *binding)
241+
static int binding_astlpc_init_pollfd(struct binding *binding,
242+
struct pollfd *pollfd)
242243
{
243-
return mctp_astlpc_get_fd(binding->data);
244+
return mctp_astlpc_init_pollfd(binding->data, pollfd);
244245
}
245246

246247
static int binding_astlpc_process(struct binding *binding)
@@ -257,14 +258,14 @@ struct binding bindings[] = {
257258
.name = "serial",
258259
.init = binding_serial_init,
259260
.destroy = NULL,
260-
.get_fd = binding_serial_get_fd,
261+
.init_pollfd = binding_serial_init_pollfd,
261262
.process = binding_serial_process,
262263
},
263264
{
264265
.name = "astlpc",
265266
.init = binding_astlpc_init,
266267
.destroy = binding_astlpc_destroy,
267-
.get_fd = binding_astlpc_get_fd,
268+
.init_pollfd = binding_astlpc_init_pollfd,
268269
.process = binding_astlpc_process,
269270
}
270271
};
@@ -461,11 +462,7 @@ static int run_daemon(struct ctx *ctx)
461462

462463
ctx->pollfds = malloc(FD_NR * sizeof(struct pollfd));
463464

464-
if (ctx->binding->get_fd) {
465-
ctx->pollfds[FD_BINDING].fd =
466-
ctx->binding->get_fd(ctx->binding);
467-
ctx->pollfds[FD_BINDING].events = POLLIN;
468-
} else {
465+
if (!ctx->binding->init_pollfd) {
469466
ctx->pollfds[FD_BINDING].fd = -1;
470467
ctx->pollfds[FD_BINDING].events = 0;
471468
}
@@ -504,6 +501,9 @@ static int run_daemon(struct ctx *ctx)
504501
clients_changed = false;
505502
}
506503

504+
if (ctx->binding->init_pollfd)
505+
ctx->binding->init_pollfd(ctx->binding,
506+
&ctx->pollfds[FD_BINDING]);
507507
rc = poll(ctx->pollfds, ctx->n_clients + FD_NR, -1);
508508
if (rc < 0) {
509509
warn("poll failed");

0 commit comments

Comments
 (0)