MT#55283 split up table open and init

Rename the "noop" method to "init" and split up the function to open the
table into two parts. Open the control file first, then do the mmap(),
then init other things, then finally call the init method.

Change-Id: I832f6e90fbec4375e3e19ed6e72d7cce78488e9e
pull/1826/head
Richard Fuchs 2 years ago
parent e08c46a358
commit 7e8acd6102

@ -68,22 +68,29 @@ static void kernel_free(void *p, size_t len) {
static int kernel_open_table(unsigned int id) {
char s[64];
int saved_errno;
int fd;
struct rtpengine_command_noop cmd;
ssize_t ret;
sprintf(s, PREFIX "/%u/control", id);
fd = open(s, O_RDWR | O_TRUNC);
if (fd == -1)
return -1;
cmd.cmd = REMG_NOOP;
return fd;
}
bool kernel_init_table(void) {
if (!kernel.is_open)
return true;
struct rtpengine_command_init cmd;
ssize_t ret;
cmd.cmd = REMG_INIT;
cmd.noop = (struct rtpengine_noop_info) {
cmd.init = (struct rtpengine_init_info) {
.last_cmd = __REMG_LAST,
.msg_size = {
[REMG_NOOP] = sizeof(struct rtpengine_command_noop),
[REMG_INIT] = sizeof(struct rtpengine_command_init),
[REMG_ADD_TARGET] = sizeof(struct rtpengine_command_add_target),
[REMG_DEL_TARGET_STATS] = sizeof(struct rtpengine_command_del_target_stats),
[REMG_ADD_DESTINATION] = sizeof(struct rtpengine_command_destination),
@ -97,17 +104,11 @@ static int kernel_open_table(unsigned int id) {
},
};
ret = write(fd, &cmd, sizeof(cmd));
ret = write(kernel.fd, &cmd, sizeof(cmd));
if (ret <= 0)
goto fail;
return fd;
return false;
fail:
saved_errno = errno;
close(fd);
errno = saved_errno;
return -1;
return true;
}
bool kernel_setup_table(unsigned int id) {

@ -1301,6 +1301,8 @@ static void init_everything(void) {
abort();
codecs_init();
janus_init();
if (!kernel_init_table())
die("Kernel module version mismatch or other fatal error");
}

@ -31,6 +31,7 @@ TYPED_GQUEUE(kernel, struct rtpengine_list_entry)
bool kernel_setup_table(unsigned int);
bool kernel_init_table(void);
void kernel_shutdown_table(void);
void kernel_add_stream(struct rtpengine_target_info *);

@ -3793,7 +3793,7 @@ out:
static const size_t min_req_sizes[__REMG_LAST] = {
[REMG_NOOP] = sizeof(struct rtpengine_command_noop),
[REMG_INIT] = sizeof(struct rtpengine_command_init),
[REMG_ADD_TARGET] = sizeof(struct rtpengine_command_add_target),
[REMG_DEL_TARGET_STATS] = sizeof(struct rtpengine_command_del_target_stats),
[REMG_ADD_DESTINATION] = sizeof(struct rtpengine_command_destination),
@ -3807,7 +3807,7 @@ static const size_t min_req_sizes[__REMG_LAST] = {
};
static const size_t max_req_sizes[__REMG_LAST] = {
[REMG_NOOP] = sizeof(struct rtpengine_command_noop),
[REMG_INIT] = sizeof(struct rtpengine_command_init),
[REMG_ADD_TARGET] = sizeof(struct rtpengine_command_add_target),
[REMG_DEL_TARGET_STATS] = sizeof(struct rtpengine_command_del_target_stats),
[REMG_ADD_DESTINATION] = sizeof(struct rtpengine_command_destination),
@ -3838,7 +3838,7 @@ static inline ssize_t proc_control_read_write(struct file *file, char __user *ub
int i;
union {
struct rtpengine_command_noop *noop;
struct rtpengine_command_init *init;
struct rtpengine_command_add_target *add_target;
struct rtpengine_command_del_target *del_target;
struct rtpengine_command_del_target_stats *del_target_stats;
@ -3910,11 +3910,11 @@ static inline ssize_t proc_control_read_write(struct file *file, char __user *ub
err = 0;
switch (cmd) {
case REMG_NOOP:
if (msg.noop->noop.last_cmd != __REMG_LAST)
case REMG_INIT:
if (msg.init->init.last_cmd != __REMG_LAST)
err = -ERANGE;
for (i = 0; i < __REMG_LAST; i++)
if (msg.noop->noop.msg_size[i] != min_req_sizes[i])
if (msg.init->init.msg_size[i] != min_req_sizes[i])
err = -EMSGSIZE;
break;

@ -182,7 +182,7 @@ struct rtpengine_stats_info {
};
enum rtpengine_command {
REMG_NOOP = 1,
REMG_INIT = 1,
REMG_ADD_TARGET,
REMG_ADD_DESTINATION,
REMG_ADD_CALL,
@ -197,7 +197,7 @@ enum rtpengine_command {
__REMG_LAST
};
struct rtpengine_noop_info {
struct rtpengine_init_info {
int last_cmd;
size_t msg_size[__REMG_LAST];
};
@ -210,9 +210,9 @@ struct rtpengine_send_packet_info {
unsigned char data[];
};
struct rtpengine_command_noop {
struct rtpengine_command_init {
enum rtpengine_command cmd;
struct rtpengine_noop_info noop;
struct rtpengine_init_info init;
};
struct rtpengine_command_add_target {

Loading…
Cancel
Save