From a06954837051eccf0952ec0b3ed2b7ffbed5792a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sat, 7 Nov 2015 12:51:14 +0000 Subject: [PATCH] [core] revert increase of temp file size back to 1MB, provide a configure option "server.upload-temp-file-size" instead (fixes #2680) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Stefan Bühler git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3050 152afb58-edef-0310-8abb-c4023f1b3aa9 --- NEWS | 1 + src/base.h | 1 + src/chunk.c | 20 ++++++++++++++------ src/chunk.h | 7 ++++--- src/configfile.c | 3 +++ src/connections.c | 5 ++++- 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 0b943ef6..af391340 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ NEWS * add force_assert for many allocations and function results * [mod_secdownload] use a hopefully constant time comparison to check hash (fixes #2679) * [config] check config option scope; warn if server option is given in conditional + * [core] revert increase of temp file size back to 1MB, provide a configure option "server.upload-temp-file-size" instead (fixes #2680) - 1.4.37 - 2015-08-30 * [mod_proxy] remove debug log line from error log (fixes #2659) diff --git a/src/base.h b/src/base.h index 87bacfca..4c748a57 100644 --- a/src/base.h +++ b/src/base.h @@ -508,6 +508,7 @@ typedef struct { buffer *network_backend; array *modules; array *upload_tempdirs; + unsigned int upload_temp_file_size; unsigned short max_worker; unsigned short max_fds; diff --git a/src/chunk.c b/src/chunk.c index 1a9b421f..c140ad21 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -332,9 +332,10 @@ void chunkqueue_use_memory(chunkqueue *cq, size_t len) { } } -void chunkqueue_set_tempdirs(chunkqueue *cq, array *tempdirs) { +void chunkqueue_set_tempdirs(chunkqueue *cq, array *tempdirs, unsigned int upload_temp_file_size) { force_assert(NULL != cq); cq->tempdirs = tempdirs; + cq->upload_temp_file_size = upload_temp_file_size; } void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len) { @@ -425,17 +426,24 @@ static chunk *chunkqueue_get_append_tempfile(chunkqueue *cq) { return c; } +/* default 1MB, upper limit 128MB */ +#define DEFAULT_TEMPFILE_SIZE (1 * 1024 * 1024) +#define MAX_TEMPFILE_SIZE (128 * 1024 * 1024) + static int chunkqueue_append_to_tempfile(server *srv, chunkqueue *dest, const char *mem, size_t len) { - /* copy everything to max MAX_TEMPFILE_SIZE sized tempfiles */ - static const off_t MAX_TEMPFILE_SIZE = 16 * 1024 * 1024; /* 16MB */ + /* copy everything to max max_tempfile_size sized tempfiles */ + const off_t max_tempfile_size + = (0 == dest->upload_temp_file_size) ? DEFAULT_TEMPFILE_SIZE + : (dest->upload_temp_file_size > MAX_TEMPFILE_SIZE) ? MAX_TEMPFILE_SIZE + : dest->upload_temp_file_size; chunk *dst_c = NULL; ssize_t written; /* * if the last chunk is - * - smaller than MAX_TEMPFILE_SIZE + * - smaller than max_tempfile_size * - not read yet (offset == 0) - * -> append to it (so it might actually become larger than MAX_TEMPFILE_SIZE) + * -> append to it (so it might actually become larger than max_tempfile_size) * otherwise * -> create a new chunk * @@ -449,7 +457,7 @@ static int chunkqueue_append_to_tempfile(server *srv, chunkqueue *dest, const ch /* ok, take the last chunk for our job */ dst_c = dest->last; - if (dest->last->file.length >= MAX_TEMPFILE_SIZE) { + if (dest->last->file.length >= max_tempfile_size) { /* the chunk is too large now, close it */ if (-1 != dst_c->file.fd) { close(dst_c->file.fd); diff --git a/src/chunk.h b/src/chunk.h index b263a3e1..cf313aad 100644 --- a/src/chunk.h +++ b/src/chunk.h @@ -41,13 +41,14 @@ typedef struct { chunk *unused; size_t unused_chunks; - array *tempdirs; + off_t bytes_in, bytes_out; - off_t bytes_in, bytes_out; + array *tempdirs; + unsigned int upload_temp_file_size; } chunkqueue; chunkqueue *chunkqueue_init(void); -void chunkqueue_set_tempdirs(chunkqueue *cq, array *tempdirs); +void chunkqueue_set_tempdirs(chunkqueue *cq, array *tempdirs, unsigned int upload_temp_file_size); void chunkqueue_append_file(chunkqueue *cq, buffer *fn, off_t offset, off_t len); /* copies "fn" */ void chunkqueue_append_mem(chunkqueue *cq, const char *mem, size_t len); /* copies memory */ void chunkqueue_append_buffer(chunkqueue *cq, buffer *mem); /* may reset "mem" */ diff --git a/src/configfile.c b/src/configfile.c index 4d14ae8c..72dabb70 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -107,6 +107,7 @@ static int config_insert(server *srv) { { "ssl.disable-client-renegotiation", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 65 */ { "ssl.honor-cipher-order", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 66 */ { "ssl.empty-fragments", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 67 */ + { "server.upload-temp-file-size", NULL, T_CONFIG_INT, T_CONFIG_SCOPE_SERVER }, /* 68 */ { "server.host", "use server.bind instead", @@ -169,6 +170,8 @@ static int config_insert(server *srv) { cv[52].destination = &(srv->srvconf.reject_expect_100_with_417); cv[55].destination = srv->srvconf.breakagelog_file; + cv[68].destination = &(srv->srvconf.upload_temp_file_size); + srv->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *)); force_assert(srv->config_storage); diff --git a/src/connections.c b/src/connections.c index 3b389f4a..1e225d92 100644 --- a/src/connections.c +++ b/src/connections.c @@ -689,7 +689,10 @@ connection *connection_init(server *srv) { con->write_queue = chunkqueue_init(); con->read_queue = chunkqueue_init(); con->request_content_queue = chunkqueue_init(); - chunkqueue_set_tempdirs(con->request_content_queue, srv->srvconf.upload_tempdirs); + chunkqueue_set_tempdirs( + con->request_content_queue, + srv->srvconf.upload_tempdirs, + srv->srvconf.upload_temp_file_size); con->request.headers = array_init(); con->response.headers = array_init();