1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

cleanup: dmeventd improve _handle_request

Let the compiler resolve cmd lookup and leave it to optimize it as it
needs.
This commit is contained in:
Zdenek Kabelac 2014-04-18 14:45:45 +02:00
parent 0927605ec3
commit 78c6dea48e

View File

@ -1447,34 +1447,35 @@ static int _client_write(struct dm_event_fifos *fifos,
static int _handle_request(struct dm_event_daemon_message *msg, static int _handle_request(struct dm_event_daemon_message *msg,
struct message_data *message_data) struct message_data *message_data)
{ {
static struct request { switch (msg->cmd) {
unsigned int cmd; case DM_EVENT_CMD_REGISTER_FOR_EVENT:
int (*f)(struct message_data *); return _register_for_event(message_data);
} requests[] = { case DM_EVENT_CMD_UNREGISTER_FOR_EVENT:
{ DM_EVENT_CMD_REGISTER_FOR_EVENT, _register_for_event}, return _unregister_for_event(message_data);
{ DM_EVENT_CMD_UNREGISTER_FOR_EVENT, _unregister_for_event}, case DM_EVENT_CMD_GET_REGISTERED_DEVICE:
{ DM_EVENT_CMD_GET_REGISTERED_DEVICE, _get_registered_device}, return _get_registered_device(message_data);
{ DM_EVENT_CMD_GET_NEXT_REGISTERED_DEVICE, case DM_EVENT_CMD_GET_NEXT_REGISTERED_DEVICE:
_get_next_registered_device}, return _get_next_registered_device(message_data);
{ DM_EVENT_CMD_SET_TIMEOUT, _set_timeout}, case DM_EVENT_CMD_SET_TIMEOUT:
{ DM_EVENT_CMD_GET_TIMEOUT, _get_timeout}, return _set_timeout(message_data);
{ DM_EVENT_CMD_ACTIVE, _active}, case DM_EVENT_CMD_GET_TIMEOUT:
{ DM_EVENT_CMD_GET_STATUS, _get_status}, return _get_timeout(message_data);
/* dmeventd parameters of running dmeventd, case DM_EVENT_CMD_ACTIVE:
* returns 'pid=<pid> daemon=<no/yes> exec_method=<direct/systemd>' return _active(message_data);
* pid - pidfile of running dmeventd case DM_EVENT_CMD_GET_STATUS:
* daemon - running as a daemon or not (foreground)? return _get_status(message_data);
* exec_method - "direct" if executed directly or /* dmeventd parameters of running dmeventd,
* "systemd" if executed via systemd * returns 'pid=<pid> daemon=<no/yes> exec_method=<direct/systemd>'
*/ * pid - pidfile of running dmeventd
{ DM_EVENT_CMD_GET_PARAMETERS, _get_parameters}, * daemon - running as a daemon or not (foreground)?
}, *req; * exec_method - "direct" if executed directly or
* "systemd" if executed via systemd
for (req = requests; req < requests + DM_ARRAY_SIZE(requests); ++req) */
if (req->cmd == msg->cmd) case DM_EVENT_CMD_GET_PARAMETERS:
return req->f(message_data); return _get_parameters(message_data);
default:
return -EINVAL; return -EINVAL;
}
} }
/* Process a request passed from the communication thread. */ /* Process a request passed from the communication thread. */