Adding "limits/shm" configuration validation and parsing.
This commit is contained in:
@@ -89,6 +89,9 @@ struct nxt_common_app_conf_s {
|
|||||||
nxt_conf_value_t *environment;
|
nxt_conf_value_t *environment;
|
||||||
|
|
||||||
nxt_conf_value_t *isolation;
|
nxt_conf_value_t *isolation;
|
||||||
|
nxt_conf_value_t *limits;
|
||||||
|
|
||||||
|
size_t shm_limit;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
nxt_external_app_conf_t external;
|
nxt_external_app_conf_t external;
|
||||||
|
|||||||
@@ -358,6 +358,11 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_app_limits_members[] = {
|
|||||||
NULL,
|
NULL,
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
|
{ nxt_string("shm"),
|
||||||
|
NXT_CONF_VLDT_INTEGER,
|
||||||
|
NULL,
|
||||||
|
NULL },
|
||||||
|
|
||||||
NXT_CONF_VLDT_END
|
NXT_CONF_VLDT_END
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -98,11 +98,11 @@ nxt_external_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
|
|||||||
"%s;%uD;"
|
"%s;%uD;"
|
||||||
"%PI,%ud,%d;"
|
"%PI,%ud,%d;"
|
||||||
"%PI,%ud,%d;"
|
"%PI,%ud,%d;"
|
||||||
"%d,%Z",
|
"%d,%z,%Z",
|
||||||
NXT_VERSION, my_port->process->init->stream,
|
NXT_VERSION, my_port->process->init->stream,
|
||||||
main_port->pid, main_port->id, main_port->pair[1],
|
main_port->pid, main_port->id, main_port->pair[1],
|
||||||
my_port->pid, my_port->id, my_port->pair[0],
|
my_port->pid, my_port->id, my_port->pair[0],
|
||||||
2);
|
2, conf->shm_limit);
|
||||||
|
|
||||||
if (nxt_slow_path(p == end)) {
|
if (nxt_slow_path(p == end)) {
|
||||||
nxt_alert(task, "internal error: buffer too small for NXT_UNIT_INIT");
|
nxt_alert(task, "internal error: buffer too small for NXT_UNIT_INIT");
|
||||||
|
|||||||
@@ -354,6 +354,7 @@ nxt_java_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
|
|||||||
java_init.callbacks.close_handler = nxt_java_close_handler;
|
java_init.callbacks.close_handler = nxt_java_close_handler;
|
||||||
java_init.request_data_size = sizeof(nxt_java_request_data_t);
|
java_init.request_data_size = sizeof(nxt_java_request_data_t);
|
||||||
java_init.data = &data;
|
java_init.data = &data;
|
||||||
|
java_init.shm_limit = conf->shm_limit;
|
||||||
|
|
||||||
ctx = nxt_unit_init(&java_init);
|
ctx = nxt_unit_init(&java_init);
|
||||||
if (nxt_slow_path(ctx == NULL)) {
|
if (nxt_slow_path(ctx == NULL)) {
|
||||||
|
|||||||
@@ -215,7 +215,24 @@ static nxt_conf_map_t nxt_common_app_conf[] = {
|
|||||||
nxt_string("isolation"),
|
nxt_string("isolation"),
|
||||||
NXT_CONF_MAP_PTR,
|
NXT_CONF_MAP_PTR,
|
||||||
offsetof(nxt_common_app_conf_t, isolation),
|
offsetof(nxt_common_app_conf_t, isolation),
|
||||||
}
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
nxt_string("limits"),
|
||||||
|
NXT_CONF_MAP_PTR,
|
||||||
|
offsetof(nxt_common_app_conf_t, limits),
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static nxt_conf_map_t nxt_common_app_limits_conf[] = {
|
||||||
|
{
|
||||||
|
nxt_string("shm"),
|
||||||
|
NXT_CONF_MAP_SIZE,
|
||||||
|
offsetof(nxt_common_app_conf_t, shm_limit),
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -381,6 +398,7 @@ nxt_port_main_start_worker_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
|
|||||||
|
|
||||||
app_conf.name.start = start;
|
app_conf.name.start = start;
|
||||||
app_conf.name.length = nxt_strlen(start);
|
app_conf.name.length = nxt_strlen(start);
|
||||||
|
app_conf.shm_limit = 100 * 1024 * 1024;
|
||||||
|
|
||||||
start += app_conf.name.length + 1;
|
start += app_conf.name.length + 1;
|
||||||
|
|
||||||
@@ -427,6 +445,18 @@ nxt_port_main_start_worker_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (app_conf.limits != NULL) {
|
||||||
|
ret = nxt_conf_map_object(mp, app_conf.limits,
|
||||||
|
nxt_common_app_limits_conf,
|
||||||
|
nxt_nitems(nxt_common_app_limits_conf),
|
||||||
|
&app_conf);
|
||||||
|
|
||||||
|
if (nxt_slow_path(ret != NXT_OK)) {
|
||||||
|
nxt_alert(task, "failed to map app limits received from router");
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = nxt_main_start_worker_process(task, task->thread->runtime,
|
ret = nxt_main_start_worker_process(task, task->thread->runtime,
|
||||||
&app_conf, msg->port_msg.stream);
|
&app_conf, msg->port_msg.stream);
|
||||||
|
|
||||||
|
|||||||
@@ -352,6 +352,7 @@ nxt_php_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
|
|||||||
nxt_fd_blocking(task, my_port->pair[0]);
|
nxt_fd_blocking(task, my_port->pair[0]);
|
||||||
|
|
||||||
php_init.log_fd = 2;
|
php_init.log_fd = 2;
|
||||||
|
php_init.shm_limit = conf->shm_limit;
|
||||||
|
|
||||||
unit_ctx = nxt_unit_init(&php_init);
|
unit_ctx = nxt_unit_init(&php_init);
|
||||||
if (nxt_slow_path(unit_ctx == NULL)) {
|
if (nxt_slow_path(unit_ctx == NULL)) {
|
||||||
|
|||||||
@@ -404,6 +404,7 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
|
|||||||
nxt_unit_default_init(task, &python_init);
|
nxt_unit_default_init(task, &python_init);
|
||||||
|
|
||||||
python_init.callbacks.request_handler = nxt_python_request_handler;
|
python_init.callbacks.request_handler = nxt_python_request_handler;
|
||||||
|
python_init.shm_limit = conf->shm_limit;
|
||||||
|
|
||||||
unit_ctx = nxt_unit_init(&python_init);
|
unit_ctx = nxt_unit_init(&python_init);
|
||||||
if (nxt_slow_path(unit_ctx == NULL)) {
|
if (nxt_slow_path(unit_ctx == NULL)) {
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ nxt_inline void nxt_unit_mmap_buf_insert_tail(nxt_unit_mmap_buf_t **prev,
|
|||||||
nxt_unit_mmap_buf_t *mmap_buf);
|
nxt_unit_mmap_buf_t *mmap_buf);
|
||||||
nxt_inline void nxt_unit_mmap_buf_unlink(nxt_unit_mmap_buf_t *mmap_buf);
|
nxt_inline void nxt_unit_mmap_buf_unlink(nxt_unit_mmap_buf_t *mmap_buf);
|
||||||
static int nxt_unit_read_env(nxt_unit_port_t *ready_port,
|
static int nxt_unit_read_env(nxt_unit_port_t *ready_port,
|
||||||
nxt_unit_port_t *read_port, int *log_fd, uint32_t *stream);
|
nxt_unit_port_t *read_port, int *log_fd, uint32_t *stream,
|
||||||
|
uint32_t *shm_limit);
|
||||||
static int nxt_unit_ready(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id,
|
static int nxt_unit_ready(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id,
|
||||||
uint32_t stream);
|
uint32_t stream);
|
||||||
static int nxt_unit_process_new_port(nxt_unit_ctx_t *ctx,
|
static int nxt_unit_process_new_port(nxt_unit_ctx_t *ctx,
|
||||||
@@ -240,6 +241,7 @@ struct nxt_unit_impl_s {
|
|||||||
nxt_unit_callbacks_t callbacks;
|
nxt_unit_callbacks_t callbacks;
|
||||||
|
|
||||||
uint32_t request_data_size;
|
uint32_t request_data_size;
|
||||||
|
uint32_t shm_mmap_limit;
|
||||||
|
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
|
|
||||||
@@ -306,7 +308,7 @@ nxt_unit_ctx_t *
|
|||||||
nxt_unit_init(nxt_unit_init_t *init)
|
nxt_unit_init(nxt_unit_init_t *init)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
uint32_t ready_stream;
|
uint32_t ready_stream, shm_limit;
|
||||||
nxt_unit_ctx_t *ctx;
|
nxt_unit_ctx_t *ctx;
|
||||||
nxt_unit_impl_t *lib;
|
nxt_unit_impl_t *lib;
|
||||||
nxt_unit_port_t ready_port, read_port;
|
nxt_unit_port_t ready_port, read_port;
|
||||||
@@ -329,12 +331,20 @@ nxt_unit_init(nxt_unit_init_t *init)
|
|||||||
ready_port.id.id);
|
ready_port.id.id);
|
||||||
nxt_unit_port_id_init(&read_port.id, read_port.id.pid,
|
nxt_unit_port_id_init(&read_port.id, read_port.id.pid,
|
||||||
read_port.id.id);
|
read_port.id.id);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
rc = nxt_unit_read_env(&ready_port, &read_port, &lib->log_fd,
|
rc = nxt_unit_read_env(&ready_port, &read_port, &lib->log_fd,
|
||||||
&ready_stream);
|
&ready_stream, &shm_limit);
|
||||||
if (nxt_slow_path(rc != NXT_UNIT_OK)) {
|
if (nxt_slow_path(rc != NXT_UNIT_OK)) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lib->shm_mmap_limit = (shm_limit + PORT_MMAP_DATA_SIZE - 1)
|
||||||
|
/ PORT_MMAP_DATA_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nxt_slow_path(lib->shm_mmap_limit < 1)) {
|
||||||
|
lib->shm_mmap_limit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lib->pid = read_port.id.pid;
|
lib->pid = read_port.id.pid;
|
||||||
@@ -399,6 +409,8 @@ nxt_unit_create(nxt_unit_init_t *init)
|
|||||||
lib->callbacks = init->callbacks;
|
lib->callbacks = init->callbacks;
|
||||||
|
|
||||||
lib->request_data_size = init->request_data_size;
|
lib->request_data_size = init->request_data_size;
|
||||||
|
lib->shm_mmap_limit = (init->shm_limit + PORT_MMAP_DATA_SIZE - 1)
|
||||||
|
/ PORT_MMAP_DATA_SIZE;
|
||||||
|
|
||||||
lib->processes.slot = NULL;
|
lib->processes.slot = NULL;
|
||||||
lib->ports.slot = NULL;
|
lib->ports.slot = NULL;
|
||||||
@@ -539,7 +551,7 @@ nxt_unit_mmap_buf_unlink(nxt_unit_mmap_buf_t *mmap_buf)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
nxt_unit_read_env(nxt_unit_port_t *ready_port, nxt_unit_port_t *read_port,
|
nxt_unit_read_env(nxt_unit_port_t *ready_port, nxt_unit_port_t *read_port,
|
||||||
int *log_fd, uint32_t *stream)
|
int *log_fd, uint32_t *stream, uint32_t *shm_limit)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
int ready_fd, read_fd;
|
int ready_fd, read_fd;
|
||||||
@@ -574,14 +586,14 @@ nxt_unit_read_env(nxt_unit_port_t *ready_port, nxt_unit_port_t *read_port,
|
|||||||
"%"PRIu32";"
|
"%"PRIu32";"
|
||||||
"%"PRId64",%"PRIu32",%d;"
|
"%"PRId64",%"PRIu32",%d;"
|
||||||
"%"PRId64",%"PRIu32",%d;"
|
"%"PRId64",%"PRIu32",%d;"
|
||||||
"%d",
|
"%d,%"PRIu32,
|
||||||
&ready_stream,
|
&ready_stream,
|
||||||
&ready_pid, &ready_id, &ready_fd,
|
&ready_pid, &ready_id, &ready_fd,
|
||||||
&read_pid, &read_id, &read_fd,
|
&read_pid, &read_id, &read_fd,
|
||||||
log_fd);
|
log_fd, shm_limit);
|
||||||
|
|
||||||
if (nxt_slow_path(rc != 8)) {
|
if (nxt_slow_path(rc != 9)) {
|
||||||
nxt_unit_alert(NULL, "failed to scan variables");
|
nxt_unit_alert(NULL, "failed to scan variables: %d", rc);
|
||||||
|
|
||||||
return NXT_UNIT_ERROR;
|
return NXT_UNIT_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ struct nxt_unit_init_s {
|
|||||||
int max_pending_requests;
|
int max_pending_requests;
|
||||||
|
|
||||||
uint32_t request_data_size;
|
uint32_t request_data_size;
|
||||||
|
uint32_t shm_limit;
|
||||||
|
|
||||||
nxt_unit_callbacks_t callbacks;
|
nxt_unit_callbacks_t callbacks;
|
||||||
|
|
||||||
|
|||||||
@@ -1156,6 +1156,7 @@ nxt_perl_psgi_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
|
|||||||
|
|
||||||
perl_init.callbacks.request_handler = nxt_perl_psgi_request_handler;
|
perl_init.callbacks.request_handler = nxt_perl_psgi_request_handler;
|
||||||
perl_init.data = &module;
|
perl_init.data = &module;
|
||||||
|
perl_init.shm_limit = conf->shm_limit;
|
||||||
|
|
||||||
unit_ctx = nxt_unit_init(&perl_init);
|
unit_ctx = nxt_unit_init(&perl_init);
|
||||||
if (nxt_slow_path(unit_ctx == NULL)) {
|
if (nxt_slow_path(unit_ctx == NULL)) {
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ nxt_ruby_init(nxt_task_t *task, nxt_common_app_conf_t *conf)
|
|||||||
nxt_unit_default_init(task, &ruby_unit_init);
|
nxt_unit_default_init(task, &ruby_unit_init);
|
||||||
|
|
||||||
ruby_unit_init.callbacks.request_handler = nxt_ruby_request_handler;
|
ruby_unit_init.callbacks.request_handler = nxt_ruby_request_handler;
|
||||||
|
ruby_unit_init.shm_limit = conf->shm_limit;
|
||||||
|
|
||||||
unit_ctx = nxt_unit_init(&ruby_unit_init);
|
unit_ctx = nxt_unit_init(&ruby_unit_init);
|
||||||
if (nxt_slow_path(unit_ctx == NULL)) {
|
if (nxt_slow_path(unit_ctx == NULL)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user