mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-10-04 16:08:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1669d1887 | ||
|
|
095bd60f77 | ||
|
|
c3d33c90a0 | ||
|
|
4905b64f2e | ||
|
|
cfe1e9de7b | ||
|
|
82dcfd338d | ||
|
|
c696065d3c | ||
|
|
8746141afa | ||
|
|
e2b2a16b8c | ||
|
|
406daeb3ae | ||
|
|
acbc073c81 | ||
|
|
2ad23e95dd | ||
|
|
807259f25b | ||
|
|
4b06b2391c | ||
|
|
8c0adef6e7 | ||
|
|
52ea289283 | ||
|
|
bfb6e21e2a | ||
|
|
84d6f54ddd | ||
|
|
775afe1e86 | ||
|
|
cabb5f3e8e | ||
|
|
aae6413cb1 | ||
|
|
6666848ac3 | ||
|
|
c6f1911686 | ||
|
|
ef4ee87fed | ||
|
|
2a2f1a9928 | ||
|
|
f1caa39f51 | ||
|
|
536ffdcc79 | ||
|
|
d3313a39b7 | ||
|
|
89da4a97a6 | ||
|
|
3e41d5927a |
+70
-10
@@ -67,14 +67,19 @@ static int uwsgi_canon(request_rec *r, char *url)
|
||||
}
|
||||
url += sizeof(UWSGI_SCHEME); /* Keep slashes */
|
||||
|
||||
err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
|
||||
if (err) {
|
||||
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
||||
// is it a unix socket ?
|
||||
if (strlen(url) == 2) {
|
||||
*sport = 0;
|
||||
}
|
||||
else {
|
||||
err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
|
||||
if (err) {
|
||||
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
||||
"error parsing URL %s: %s", url, err);
|
||||
return HTTP_BAD_REQUEST;
|
||||
return HTTP_BAD_REQUEST;
|
||||
}
|
||||
apr_snprintf(sport, sizeof(sport), ":%u", port);
|
||||
}
|
||||
|
||||
apr_snprintf(sport, sizeof(sport), ":%u", port);
|
||||
|
||||
if (ap_strchr(host, ':')) { /* if literal IPv6 address */
|
||||
host = apr_pstrcat(r->pool, "[", host, "]", NULL);
|
||||
@@ -253,6 +258,43 @@ static request_rec *ap_proxy_make_fake_req(conn_rec *c, request_rec *r)
|
||||
|
||||
return rp;
|
||||
}
|
||||
|
||||
static apr_status_t ap_proxy_buckets_lifetime_transform(request_rec *r,
|
||||
apr_bucket_brigade *from, apr_bucket_brigade *to)
|
||||
{
|
||||
apr_bucket *e;
|
||||
apr_bucket *new;
|
||||
const char *data;
|
||||
apr_size_t bytes;
|
||||
apr_status_t rv = APR_SUCCESS;
|
||||
|
||||
apr_brigade_cleanup(to);
|
||||
for (e = APR_BRIGADE_FIRST(from);
|
||||
e != APR_BRIGADE_SENTINEL(from);
|
||||
e = APR_BUCKET_NEXT(e)) {
|
||||
if (!APR_BUCKET_IS_METADATA(e)) {
|
||||
apr_bucket_read(e, &data, &bytes, APR_BLOCK_READ);
|
||||
new = apr_bucket_transient_create(data, bytes, r->connection->bucket_alloc);
|
||||
APR_BRIGADE_INSERT_TAIL(to, new);
|
||||
}
|
||||
else if (APR_BUCKET_IS_FLUSH(e)) {
|
||||
new = apr_bucket_flush_create(r->connection->bucket_alloc);
|
||||
APR_BRIGADE_INSERT_TAIL(to, new);
|
||||
}
|
||||
else if (APR_BUCKET_IS_EOS(e)) {
|
||||
new = apr_bucket_eos_create(r->connection->bucket_alloc);
|
||||
APR_BRIGADE_INSERT_TAIL(to, new);
|
||||
}
|
||||
else {
|
||||
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00964)
|
||||
"Unhandled bucket type of type %s in"
|
||||
" proxy_buckets_lifetime_transform", e->type->name);
|
||||
apr_bucket_delete(e);
|
||||
rv = APR_EGENERAL;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -263,6 +305,7 @@ static int uwsgi_response(request_rec *r, proxy_conn_rec *backend, proxy_server_
|
||||
const char *buf;
|
||||
char *value, *end;
|
||||
int len;
|
||||
int backend_broke = 1;
|
||||
apr_status_t rc;
|
||||
conn_rec *c = r->connection;
|
||||
apr_off_t readbytes;
|
||||
@@ -274,6 +317,7 @@ static int uwsgi_response(request_rec *r, proxy_conn_rec *backend, proxy_server_
|
||||
rp->proxyreq = PROXYREQ_RESPONSE;
|
||||
|
||||
apr_bucket_brigade *bb = apr_brigade_create(r->pool, c->bucket_alloc);
|
||||
apr_bucket_brigade *pass_bb = apr_brigade_create(r->pool, c->bucket_alloc);
|
||||
|
||||
len = ap_getline(buffer, sizeof(buffer), rp, 1);
|
||||
|
||||
@@ -325,8 +369,8 @@ static int uwsgi_response(request_rec *r, proxy_conn_rec *backend, proxy_server_
|
||||
rv = ap_get_brigade(rp->input_filters, bb,
|
||||
AP_MODE_READBYTES, mode,
|
||||
conf->io_buffer_size);
|
||||
if (APR_STATUS_IS_EAGAIN(rv)
|
||||
|| (rv == APR_SUCCESS && APR_BRIGADE_EMPTY(bb))) {
|
||||
if (mode == APR_NONBLOCK_READ && (APR_STATUS_IS_EAGAIN(rv)
|
||||
|| (rv == APR_SUCCESS && APR_BRIGADE_EMPTY(bb)))) {
|
||||
e = apr_bucket_flush_create(c->bucket_alloc);
|
||||
APR_BRIGADE_INSERT_TAIL(bb, e);
|
||||
if (ap_pass_brigade(r->output_filters, bb) || c->aborted) {
|
||||
@@ -342,21 +386,37 @@ static int uwsgi_response(request_rec *r, proxy_conn_rec *backend, proxy_server_
|
||||
else if (rv != APR_SUCCESS) {
|
||||
ap_proxy_backend_broke(r, bb);
|
||||
ap_pass_brigade(r->output_filters, bb);
|
||||
backend_broke = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
mode = APR_NONBLOCK_READ;
|
||||
apr_brigade_length(bb, 0, &readbytes);
|
||||
backend->worker->s->read += readbytes;
|
||||
ap_pass_brigade(r->output_filters, bb);
|
||||
|
||||
if (APR_BRIGADE_EMPTY(bb)) {
|
||||
apr_brigade_cleanup(bb);
|
||||
break;
|
||||
}
|
||||
|
||||
ap_proxy_buckets_lifetime_transform(r, bb, pass_bb);
|
||||
|
||||
ap_pass_brigade(r->output_filters, pass_bb);
|
||||
apr_brigade_cleanup(bb);
|
||||
apr_brigade_cleanup(pass_bb);
|
||||
}
|
||||
|
||||
e = apr_bucket_eos_create(c->bucket_alloc);
|
||||
APR_BRIGADE_INSERT_TAIL(bb, e);
|
||||
ap_pass_brigade(r->output_filters, bb);
|
||||
|
||||
apr_brigade_cleanup(bb);
|
||||
|
||||
return OK;
|
||||
if (c->aborted || backend_broke) {
|
||||
return DONE;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int uwsgi_handler(request_rec *r, proxy_worker *worker,
|
||||
|
||||
+10
-1
@@ -128,7 +128,16 @@ int uwsgi_buffer_append_json(struct uwsgi_buffer *ub, char *buf, size_t len) {
|
||||
// need to escape \ and "
|
||||
size_t i;
|
||||
for(i=0;i<len;i++) {
|
||||
if (buf[i] == '"') {
|
||||
if (buf[i] == '\t') {
|
||||
if (uwsgi_buffer_append(ub, "\\t", 2)) return -1;
|
||||
}
|
||||
else if (buf[i] == '\n') {
|
||||
if (uwsgi_buffer_append(ub, "\\n", 2)) return -1;
|
||||
}
|
||||
else if (buf[i] == '\r') {
|
||||
if (uwsgi_buffer_append(ub, "\\r", 2)) return -1;
|
||||
}
|
||||
else if (buf[i] == '"') {
|
||||
if (uwsgi_buffer_append(ub, "\\\"", 2)) return -1;
|
||||
}
|
||||
else if (buf[i] == '\\') {
|
||||
|
||||
@@ -294,6 +294,26 @@ int uwsgi_logic_opt_if_not_plugin(char *key, char *value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_logic_opt_if_hostname(char *key, char *value) {
|
||||
|
||||
if (!strcmp(uwsgi.hostname, uwsgi.logic_opt_data)) {
|
||||
add_exported_option(key, uwsgi_substitute(value, "%(_)", uwsgi.logic_opt_data), 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_logic_opt_if_not_hostname(char *key, char *value) {
|
||||
|
||||
if (strcmp(uwsgi.hostname, uwsgi.logic_opt_data)) {
|
||||
add_exported_option(key, uwsgi_substitute(value, "%(_)", uwsgi.logic_opt_data), 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_count_options(struct uwsgi_option *uopt) {
|
||||
|
||||
struct uwsgi_option *aopt;
|
||||
|
||||
+12
-1
@@ -292,11 +292,18 @@ void uwsgi_spawn_daemon(struct uwsgi_daemon *ud) {
|
||||
uwsgi_close_all_sockets();
|
||||
uwsgi_close_all_fds();
|
||||
|
||||
if (ud->chdir) {
|
||||
if (chdir(ud->chdir)) {
|
||||
uwsgi_error("uwsgi_spawn_daemon()/chdir()");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__linux__) && !defined(OBSOLETE_LINUX_KERNEL) && defined(CLONE_NEWPID)
|
||||
if (ud->ns_pid) {
|
||||
// we need to create a new session
|
||||
if (setsid() < 0) {
|
||||
uwsgi_error("setsid()");
|
||||
uwsgi_error("uwsgi_spawn_daemon()/setsid()");
|
||||
exit(1);
|
||||
}
|
||||
// avoid the need to set stop_signal in attach-daemon2
|
||||
@@ -497,6 +504,7 @@ void uwsgi_opt_add_daemon2(char *opt, char *value, void *none) {
|
||||
char *d_uid = NULL;
|
||||
char *d_gid = NULL;
|
||||
char *d_ns_pid = NULL;
|
||||
char *d_chdir = NULL;
|
||||
|
||||
char *arg = uwsgi_str(value);
|
||||
|
||||
@@ -518,6 +526,7 @@ void uwsgi_opt_add_daemon2(char *opt, char *value, void *none) {
|
||||
"uid", &d_uid,
|
||||
"gid", &d_gid,
|
||||
"ns_pid", &d_ns_pid,
|
||||
"chdir", &d_chdir,
|
||||
NULL)) {
|
||||
uwsgi_log("invalid --%s keyval syntax\n", opt);
|
||||
exit(1);
|
||||
@@ -565,6 +574,8 @@ void uwsgi_opt_add_daemon2(char *opt, char *value, void *none) {
|
||||
#endif
|
||||
uwsgi_ud->ns_pid = d_ns_pid ? 1 : 0;
|
||||
|
||||
uwsgi_ud->chdir = d_chdir;
|
||||
|
||||
if (d_touch) {
|
||||
size_t i,rlen = 0;
|
||||
char **argv = uwsgi_split_quoted(d_touch, strlen(d_touch), ";", &rlen);
|
||||
|
||||
@@ -45,6 +45,14 @@ void uwsgi_403(struct wsgi_request *wsgi_req) {
|
||||
uwsgi_response_write_body_do(wsgi_req, "Forbidden", 9);
|
||||
}
|
||||
|
||||
void uwsgi_405(struct wsgi_request *wsgi_req) {
|
||||
if (uwsgi_response_prepare_headers(wsgi_req, "405 Method Not Allowed", 22)) return;
|
||||
if (uwsgi_response_add_connection_close(wsgi_req)) return;
|
||||
if (error_page(wsgi_req, uwsgi.error_page_403)) return;
|
||||
if (uwsgi_response_add_content_type(wsgi_req, "text/plain", 10)) return;
|
||||
uwsgi_response_write_body_do(wsgi_req, "Method Not Allowed", 18);
|
||||
}
|
||||
|
||||
void uwsgi_redirect_to_slash(struct wsgi_request *wsgi_req) {
|
||||
|
||||
char *redirect = NULL;
|
||||
|
||||
@@ -131,6 +131,7 @@ int uwsgi_master_fifo_manage(int fd) {
|
||||
}
|
||||
// fifo destroyed, recreate it
|
||||
else if (rlen == 0) {
|
||||
event_queue_del_fd(uwsgi.master_queue, uwsgi.master_fifo_fd, event_queue_read());
|
||||
close(fd);
|
||||
uwsgi.master_fifo_fd = uwsgi_master_fifo();
|
||||
event_queue_add_fd_read(uwsgi.master_queue, uwsgi.master_fifo_fd);
|
||||
|
||||
@@ -392,6 +392,26 @@ static char *uwsgi_scheme_call(char *url, size_t *size, int add_zero) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static char *uwsgi_scheme_callint(char *url, size_t *size, int add_zero) {
|
||||
int (*func)(void) = dlsym(RTLD_DEFAULT, url);
|
||||
if (!func) {
|
||||
uwsgi_log("unable to find symbol %s\n", url);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char *s = uwsgi_num2str(func());
|
||||
*size = strlen(s);
|
||||
if (add_zero) {
|
||||
*size += 1;
|
||||
}
|
||||
char *buffer = uwsgi_malloc(*size);
|
||||
memset(buffer, 0, *size);
|
||||
memcpy(buffer, s, strlen(s));
|
||||
free(s);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
static char *uwsgi_scheme_sym(char *url, size_t *size, int add_zero) {
|
||||
void *sym_start_ptr = NULL, *sym_end_ptr = NULL;
|
||||
@@ -1249,6 +1269,7 @@ void uwsgi_setup_schemes() {
|
||||
uwsgi_register_scheme("fd", uwsgi_scheme_fd);
|
||||
uwsgi_register_scheme("exec", uwsgi_scheme_exec);
|
||||
uwsgi_register_scheme("call", uwsgi_scheme_call);
|
||||
uwsgi_register_scheme("callint", uwsgi_scheme_callint);
|
||||
}
|
||||
|
||||
struct uwsgi_string_list *uwsgi_check_scheme(char *file) {
|
||||
|
||||
+36
-18
@@ -40,26 +40,44 @@ int uwsgi_master_check_reload(char **argv) {
|
||||
// check for chain reload
|
||||
void uwsgi_master_check_chain() {
|
||||
if (!uwsgi.status.chain_reloading) return;
|
||||
int i;
|
||||
int needed_procs = 0;
|
||||
for(i=1;i<=uwsgi.numproc;i++) {
|
||||
if (uwsgi.workers[i].pid > 0 && uwsgi.workers[i].cheaped == 0) {
|
||||
needed_procs++;
|
||||
}
|
||||
}
|
||||
if (uwsgi.status.chain_reloading > needed_procs) {
|
||||
uwsgi.status.chain_reloading = 0;
|
||||
uwsgi_log_verbose("chain reloading complete\n");
|
||||
}
|
||||
uwsgi_block_signal(SIGHUP);
|
||||
for(i=1;i<=uwsgi.numproc;i++) {
|
||||
// do not curse a worker until the old one is ready
|
||||
if (uwsgi.workers[i].accepting == 0) break;
|
||||
if (uwsgi.workers[i].pid > 0 && uwsgi.workers[i].cheaped == 0 && uwsgi.workers[i].cursed_at == 0 && i == uwsgi.status.chain_reloading) {
|
||||
uwsgi_curse(i, SIGHUP);
|
||||
break;
|
||||
|
||||
// we need to ensure the previous worker (if alive) is accepting new requests
|
||||
// before going on
|
||||
if (uwsgi.status.chain_reloading > 1) {
|
||||
struct uwsgi_worker *previous_worker = &uwsgi.workers[uwsgi.status.chain_reloading-1];
|
||||
// is the previous worker alive ?
|
||||
if (previous_worker->pid > 0 && !previous_worker->cheaped) {
|
||||
// the worker has been respawned but it is still not ready
|
||||
if (previous_worker->accepting == 0) {
|
||||
uwsgi_log_verbose("chain is still waiting for worker %d...\n", uwsgi.status.chain_reloading-1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if all the processes are recycled, the chain is over
|
||||
if (uwsgi.status.chain_reloading > uwsgi.numproc) {
|
||||
uwsgi.status.chain_reloading = 0;
|
||||
uwsgi_log_verbose("chain reloading complete\n");
|
||||
return;
|
||||
}
|
||||
|
||||
uwsgi_block_signal(SIGHUP);
|
||||
int i;
|
||||
for(i=uwsgi.status.chain_reloading;i<=uwsgi.numproc;i++) {
|
||||
struct uwsgi_worker *uw = &uwsgi.workers[i];
|
||||
if (uw->pid > 0 && !uw->cheaped && uw->accepting) {
|
||||
// the worker could have been already cursed
|
||||
if (uw->cursed_at == 0) {
|
||||
uwsgi_log_verbose("chain next victim is worker %d\n", i);
|
||||
uwsgi_curse(i, SIGHUP);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else {
|
||||
uwsgi.status.chain_reloading++;
|
||||
}
|
||||
}
|
||||
uwsgi_unblock_signal(SIGHUP);
|
||||
}
|
||||
|
||||
|
||||
@@ -1753,6 +1753,10 @@ static char *uwsgi_route_var_uwsgi(struct wsgi_request *wsgi_req, char *key, uin
|
||||
ret = uwsgi_num2str(uwsgi.shared->backlog);
|
||||
*vallen = strlen(ret);
|
||||
}
|
||||
else if (!uwsgi_strncmp(key, keylen, "rsize", 5)) {
|
||||
ret = uwsgi_64bit2str(wsgi_req->response_size);
|
||||
*vallen = strlen(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1072,6 +1072,12 @@ end:
|
||||
free(s2_sign);
|
||||
if (s2_check)
|
||||
free(s2_check);
|
||||
if (s2_sni_crt)
|
||||
free(s2_sni_crt);
|
||||
if (s2_sni_key)
|
||||
free(s2_sni_key);
|
||||
if (s2_sni_ca)
|
||||
free(s2_sni_ca);
|
||||
}
|
||||
|
||||
void uwsgi_subscribe_all(uint8_t cmd, int verbose) {
|
||||
|
||||
+5
-2
@@ -39,8 +39,8 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"socket", required_argument, 's', "bind to the specified UNIX/TCP socket using default protocol", uwsgi_opt_add_socket, NULL, 0},
|
||||
{"uwsgi-socket", required_argument, 's', "bind to the specified UNIX/TCP socket using uwsgi protocol", uwsgi_opt_add_socket, "uwsgi", 0},
|
||||
#ifdef UWSGI_SSL
|
||||
{"suwsgi-socket", required_argument, 's', "bind to the specified UNIX/TCP socket using uwsgi protocol over SSL", uwsgi_opt_add_ssl_socket, "suwsgi", 0},
|
||||
{"ssl-socket", required_argument, 's', "bind to the specified UNIX/TCP socket using uwsgi protocol over SSL", uwsgi_opt_add_ssl_socket, "suwsgi", 0},
|
||||
{"suwsgi-socket", required_argument, 0, "bind to the specified UNIX/TCP socket using uwsgi protocol over SSL", uwsgi_opt_add_ssl_socket, "suwsgi", 0},
|
||||
{"ssl-socket", required_argument, 0, "bind to the specified UNIX/TCP socket using uwsgi protocol over SSL", uwsgi_opt_add_ssl_socket, "suwsgi", 0},
|
||||
#endif
|
||||
|
||||
{"http-socket", required_argument, 0, "bind to the specified UNIX/TCP socket using HTTP protocol", uwsgi_opt_add_socket, "http", 0},
|
||||
@@ -120,6 +120,9 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"if-reload", no_argument, 0, "(opt logic) check for reload", uwsgi_opt_logic, (void *) uwsgi_logic_opt_if_reload, UWSGI_OPT_IMMEDIATE},
|
||||
{"if-not-reload", no_argument, 0, "(opt logic) check for reload", uwsgi_opt_logic, (void *) uwsgi_logic_opt_if_not_reload, UWSGI_OPT_IMMEDIATE},
|
||||
|
||||
{"if-hostname", required_argument, 0, "(opt logic) check for hostname", uwsgi_opt_logic, (void *) uwsgi_logic_opt_if_hostname, UWSGI_OPT_IMMEDIATE},
|
||||
{"if-not-hostname", required_argument, 0, "(opt logic) check for hostname", uwsgi_opt_logic, (void *) uwsgi_logic_opt_if_not_hostname, UWSGI_OPT_IMMEDIATE},
|
||||
|
||||
{"if-exists", required_argument, 0, "(opt logic) check for file/directory existance", uwsgi_opt_logic, (void *) uwsgi_logic_opt_if_exists, UWSGI_OPT_IMMEDIATE},
|
||||
{"if-not-exists", required_argument, 0, "(opt logic) check for file/directory existance", uwsgi_opt_logic, (void *) uwsgi_logic_opt_if_not_exists, UWSGI_OPT_IMMEDIATE},
|
||||
{"ifexists", required_argument, 0, "(opt logic) check for file/directory existance", uwsgi_opt_logic, (void *) uwsgi_logic_opt_if_exists, UWSGI_OPT_IMMEDIATE},
|
||||
|
||||
@@ -310,7 +310,6 @@ void corerouter_close_peer(struct uwsgi_corerouter *ucr, struct corerouter_peer
|
||||
}
|
||||
|
||||
if (peer->failed) {
|
||||
|
||||
if (peer->soopt) {
|
||||
if (!ucr->quiet)
|
||||
uwsgi_log("[uwsgi-%s] unable to connect() to node \"%.*s\" (%d retries): %s\n", ucr->short_name, (int) peer->instance_address_len, peer->instance_address, peer->retries, strerror(peer->soopt));
|
||||
|
||||
@@ -271,7 +271,7 @@ struct uwsgi_corerouter {
|
||||
char *resubscribe_bind;
|
||||
|
||||
size_t buffer_size;
|
||||
|
||||
int fallback_on_no_key;
|
||||
};
|
||||
|
||||
// a session is started when a client connect to the router
|
||||
|
||||
@@ -55,6 +55,7 @@ static struct uwsgi_option fastrouter_options[] = {
|
||||
{"fastrouter-resubscribe-bind", required_argument, 0, "bind to the specified address when re-subscribing", uwsgi_opt_set_str, &ufr.cr.resubscribe_bind, 0},
|
||||
|
||||
{"fastrouter-buffer-size", required_argument, 0, "set internal buffer size (default: page size)", uwsgi_opt_set_64bit, &ufr.cr.buffer_size, 0},
|
||||
{"fastrouter-fallback-on-no-key", no_argument, 0, "move to fallback node even if a subscription key is not found", uwsgi_opt_true, &ufr.cr.fallback_on_no_key, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
};
|
||||
|
||||
@@ -226,8 +227,15 @@ static ssize_t fr_recv_uwsgi_vars(struct corerouter_peer *main_peer) {
|
||||
return -1;
|
||||
|
||||
// check instance
|
||||
if (new_peer->instance_address_len == 0)
|
||||
if (new_peer->instance_address_len == 0) {
|
||||
if (ufr.cr.fallback_on_no_key) {
|
||||
new_peer->failed = 1;
|
||||
new_peer->can_retry = 1;
|
||||
corerouter_close_peer(&ufr.cr, new_peer);
|
||||
return len;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
new_peer->can_retry = 1;
|
||||
|
||||
|
||||
+18
-19
@@ -26,6 +26,8 @@ struct uwsgi_php {
|
||||
|
||||
struct uwsgi_string_list *exec_before;
|
||||
struct uwsgi_string_list *exec_after;
|
||||
|
||||
char *sapi_name;
|
||||
} uphp;
|
||||
|
||||
void uwsgi_opt_php_ini(char *opt, char *value, void *foobar) {
|
||||
@@ -58,6 +60,7 @@ struct uwsgi_option uwsgi_php_options[] = {
|
||||
{"php-exec-begin", required_argument, 0, "run specified php code before the requested script", uwsgi_opt_add_string_list, &uphp.exec_before, 0},
|
||||
{"php-exec-after", required_argument, 0, "run specified php code after the requested script", uwsgi_opt_add_string_list, &uphp.exec_after, 0},
|
||||
{"php-exec-end", required_argument, 0, "run specified php code after the requested script", uwsgi_opt_add_string_list, &uphp.exec_after, 0},
|
||||
{"php-sapi-name", required_argument, 0, "hack the sapi name (required for enabling zend opcode cache)", uwsgi_opt_set_str, &uphp.sapi_name, 0},
|
||||
UWSGI_END_OF_OPTIONS
|
||||
};
|
||||
|
||||
@@ -176,11 +179,11 @@ static void sapi_uwsgi_register_variables(zval *track_vars_array TSRMLS_DC)
|
||||
php_register_variable_safe("DOCUMENT_ROOT", wsgi_req->document_root, wsgi_req->document_root_len, track_vars_array TSRMLS_CC);
|
||||
|
||||
if (wsgi_req->path_info_len) {
|
||||
char *path_translated = ecalloc(1, (wsgi_req->file_len - wsgi_req->script_name_len) + wsgi_req->path_info_len + 1);
|
||||
char *path_translated = ecalloc(1, wsgi_req->file_len + wsgi_req->path_info_len + 1);
|
||||
|
||||
memcpy(path_translated, wsgi_req->file, (wsgi_req->file_len - wsgi_req->script_name_len));
|
||||
memcpy(path_translated + (wsgi_req->file_len - wsgi_req->script_name_len), wsgi_req->path_info, wsgi_req->path_info_len);
|
||||
php_register_variable_safe("PATH_TRANSLATED", path_translated, (wsgi_req->file_len - wsgi_req->script_name_len) + wsgi_req->path_info_len , track_vars_array TSRMLS_CC);
|
||||
memcpy(path_translated, wsgi_req->file, wsgi_req->file_len);
|
||||
memcpy(path_translated + wsgi_req->file_len, wsgi_req->path_info, wsgi_req->path_info_len);
|
||||
php_register_variable_safe("PATH_TRANSLATED", path_translated, wsgi_req->file_len + wsgi_req->path_info_len , track_vars_array TSRMLS_CC);
|
||||
}
|
||||
else {
|
||||
php_register_variable_safe("PATH_TRANSLATED", "", 0, track_vars_array TSRMLS_CC);
|
||||
@@ -578,8 +581,10 @@ int uwsgi_php_init(void) {
|
||||
}
|
||||
}
|
||||
|
||||
if (uphp.sapi_name) {
|
||||
uwsgi_sapi_module.name = uphp.sapi_name;
|
||||
}
|
||||
uwsgi_sapi_module.startup(&uwsgi_sapi_module);
|
||||
|
||||
uwsgi_log("PHP %s initialized\n", PHP_VERSION);
|
||||
|
||||
return 0;
|
||||
@@ -657,6 +662,9 @@ int uwsgi_php_request(struct wsgi_request *wsgi_req) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *orig_path_info = wsgi_req->path_info;
|
||||
uint16_t orig_path_info_len = wsgi_req->path_info_len;
|
||||
|
||||
if (uphp.docroot) {
|
||||
wsgi_req->document_root = uphp.docroot;
|
||||
}
|
||||
@@ -733,10 +741,6 @@ oldstyle:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char *orig_path_info = wsgi_req->path_info;
|
||||
uint16_t orig_path_info_len = wsgi_req->path_info_len;
|
||||
|
||||
if (path_info) {
|
||||
wsgi_req->path_info = path_info;
|
||||
wsgi_req->path_info_len = orig_path_info_len - (path_info - orig_path_info);
|
||||
@@ -846,24 +850,19 @@ secure2:
|
||||
}
|
||||
|
||||
secure3:
|
||||
|
||||
if (wsgi_req->document_root[wsgi_req->document_root_len-1] == '/') {
|
||||
wsgi_req->script_name = real_filename + (wsgi_req->document_root_len-1);
|
||||
wsgi_req->script_name = orig_path_info;
|
||||
if (path_info) {
|
||||
wsgi_req->script_name_len = path_info - orig_path_info;
|
||||
}
|
||||
else {
|
||||
wsgi_req->script_name = real_filename + wsgi_req->document_root_len;
|
||||
}
|
||||
|
||||
wsgi_req->script_name_len = strlen(wsgi_req->script_name);
|
||||
wsgi_req->script_name_len = orig_path_info_len;
|
||||
}
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("php filename = %s script_name = %.*s (%d) document_root = %.*s (%d)\n", real_filename, wsgi_req->script_name_len, wsgi_req->script_name, wsgi_req->script_name_len,
|
||||
wsgi_req->document_root_len, wsgi_req->document_root, wsgi_req->document_root_len);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
// now check for allowed paths and extensions
|
||||
|
||||
SG(request_info).request_uri = estrndup(wsgi_req->uri, wsgi_req->uri_len);
|
||||
|
||||
+492
-93
@@ -6,27 +6,55 @@ extern struct uwsgi_server uwsgi;
|
||||
/*
|
||||
|
||||
Author: Javier Guerra
|
||||
Author: Marcin Deranek
|
||||
Author: Roberto De Ioris
|
||||
|
||||
based on the uWSGI GlusterFS plugin by Roberto De Ioris
|
||||
|
||||
--rados-mount mountpoint=/foo,pool=unbit001,config=/etc/ceph.conf
|
||||
--rados-mount mountpoint=/foo,pool=unbit001,config=/etc/ceph.conf,timeout=30,allow_put=1,allow_delete=1
|
||||
|
||||
*/
|
||||
|
||||
struct uwsgi_plugin rados_plugin;
|
||||
|
||||
struct uwsgi_rados {
|
||||
// this structure is preallocated (only the pipe part is per-request)
|
||||
struct uwsgi_rados_io {
|
||||
int fds[2];
|
||||
// this is increased at every usage (in locked context)
|
||||
uint64_t rid;
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
// this structure is allocated for each async transaction
|
||||
struct uwsgi_rados_cb {
|
||||
// this is copied from the current uwsgi_rados_io->rid
|
||||
uint64_t rid;
|
||||
struct uwsgi_rados_io *urio;
|
||||
};
|
||||
|
||||
static struct uwsgi_rados {
|
||||
int timeout;
|
||||
struct uwsgi_string_list *mountpoints;
|
||||
struct uwsgi_rados_io *urio;
|
||||
} urados;
|
||||
|
||||
struct uwsgi_rados_mountpoint {
|
||||
rados_t cluster;
|
||||
char *mountpoint;
|
||||
char *config;
|
||||
char *pool;
|
||||
char *str_timeout;
|
||||
int timeout;
|
||||
char *allow_put;
|
||||
char *allow_delete;
|
||||
char *allow_mkcol;
|
||||
};
|
||||
|
||||
static struct uwsgi_option uwsgi_rados_options[] = {
|
||||
{"rados-mount", required_argument, 0, "virtual mount the specified rados volume in a uri", uwsgi_opt_add_string_list, &urados.mountpoints, UWSGI_OPT_MIME},
|
||||
{"rados-timeout", required_argument, 0, "timeout for async operations", uwsgi_opt_set_int, &urados.timeout, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
};
|
||||
|
||||
static int uwsgi_rados_read_sync(struct wsgi_request *wsgi_req, rados_ioctx_t *ctx, const char *key, size_t remains) {
|
||||
static int uwsgi_rados_read_sync(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, const char *key, size_t remains) {
|
||||
uint64_t off = 0;
|
||||
while(remains > 0) {
|
||||
char buf[8192];
|
||||
@@ -39,119 +67,354 @@ static int uwsgi_rados_read_sync(struct wsgi_request *wsgi_req, rados_ioctx_t *c
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
async read of a resource
|
||||
the uwsgi_rados_async_io structure is passed between threads
|
||||
the callback simply signal the main core about the availability of data
|
||||
*/
|
||||
struct uwsgi_rados_async_io {
|
||||
int fd[2];
|
||||
ssize_t rlen;
|
||||
};
|
||||
|
||||
// callback used to asynchronously signal the completion
|
||||
static void uwsgi_rados_read_async_cb(rados_completion_t comp, void *data) {
|
||||
struct uwsgi_rados_async_io *aio = (struct uwsgi_rados_async_io *) data;
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("[rados-cb] rlen = %d\n", rlen);
|
||||
#endif
|
||||
aio->rlen = rados_aio_get_return_value(comp);
|
||||
// signal the core
|
||||
if (write(aio->fd[1], "\1", 1) <= 0) {
|
||||
uwsgi_error("uwsgi_rados_read_async_cb()/write()");
|
||||
struct uwsgi_rados_cb *urcb = (struct uwsgi_rados_cb *) data;
|
||||
struct uwsgi_rados_io *urio = urcb->urio;
|
||||
|
||||
pthread_mutex_lock(&urio->mutex);
|
||||
if (urcb->rid != urio->rid) {
|
||||
uwsgi_log_verbose("[uwsgi-rados] callback %llu woke up too late\n", (unsigned long long) urcb->rid);
|
||||
}
|
||||
else {
|
||||
// signal the core
|
||||
if (write(urio->fds[1], "\1", 1) <= 0) {
|
||||
uwsgi_error("uwsgi_rados_read_async_cb()/write()");
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&urio->mutex);
|
||||
|
||||
free(urcb);
|
||||
}
|
||||
|
||||
|
||||
static int uwsgi_rados_read_async(struct wsgi_request *wsgi_req, rados_ioctx_t *ctx, const char *key, size_t remains) {
|
||||
uint64_t off = 0;
|
||||
char buf[8192];
|
||||
struct uwsgi_rados_async_io aio;
|
||||
static int uwsgi_rados_delete(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, char *key, int timeout) {
|
||||
if (uwsgi.async <= 1) {
|
||||
return rados_remove(ctx, key);
|
||||
}
|
||||
struct uwsgi_rados_io *urio = &urados.urio[wsgi_req->async_id];
|
||||
int ret = -1;
|
||||
if (pipe(aio.fd)) {
|
||||
uwsgi_error("uwsgi_rados_read_async()/pipe()");
|
||||
return -1;
|
||||
}
|
||||
aio.rlen = -1;
|
||||
rados_completion_t comp;
|
||||
if (rados_aio_create_completion(&aio, uwsgi_rados_read_async_cb, NULL, &comp) < 0) goto end;
|
||||
|
||||
while(remains > 0) {
|
||||
// trigger an async read
|
||||
if (rados_aio_read(ctx, key, comp, buf, 8192, off) < 0) goto end;
|
||||
// wait for the callback to be executed
|
||||
if (uwsgi.wait_read_hook(aio.fd[0], urados.timeout) <= 0) goto end;
|
||||
if (aio.rlen <= 0) goto end;
|
||||
if (uwsgi_response_write_body_do(wsgi_req, buf, aio.rlen)) goto end;
|
||||
remains -= aio.rlen;
|
||||
}
|
||||
ret = 0;
|
||||
// increase request counter
|
||||
pthread_mutex_lock(&urio->mutex);
|
||||
urio->rid++;
|
||||
pthread_mutex_unlock(&urio->mutex);
|
||||
|
||||
struct uwsgi_rados_cb *urcb = uwsgi_malloc(sizeof(struct uwsgi_rados_cb));
|
||||
// map the current request id to the callback
|
||||
urcb->rid = urio->rid;
|
||||
// map urio to the callback
|
||||
urcb->urio = urio;
|
||||
|
||||
rados_completion_t comp;
|
||||
// we use the safe cb here
|
||||
if (rados_aio_create_completion(urcb, NULL, uwsgi_rados_read_async_cb, &comp) < 0) {
|
||||
free(urcb);
|
||||
goto end;
|
||||
}
|
||||
if (rados_aio_remove(ctx, key, comp) < 0) {
|
||||
free(urcb);
|
||||
rados_aio_release(comp);
|
||||
goto end;
|
||||
}
|
||||
|
||||
// wait for the callback to be executed
|
||||
if (uwsgi.wait_read_hook(urio->fds[0], timeout) <= 0) {
|
||||
rados_aio_release(comp);
|
||||
goto end;
|
||||
}
|
||||
char ack = 1;
|
||||
if (read(urio->fds[0], &ack, 1) != 1) {
|
||||
rados_aio_release(comp);
|
||||
uwsgi_error("uwsgi_rados_delete()/read()");
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (rados_aio_is_safe_and_cb(comp)) {
|
||||
ret = rados_aio_get_return_value(comp);
|
||||
}
|
||||
rados_aio_release(comp);
|
||||
|
||||
end:
|
||||
rados_aio_release(&comp);
|
||||
close(aio.fd[0]);
|
||||
close(aio.fd[1]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int uwsgi_rados_put(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, char *key, int timeout) {
|
||||
struct uwsgi_rados_io *urio = &urados.urio[wsgi_req->async_id];
|
||||
size_t remains = wsgi_req->post_cl;
|
||||
uint64_t off = 0;
|
||||
while(remains > 0) {
|
||||
ssize_t body_len = 0;
|
||||
char *body = uwsgi_request_body_read(wsgi_req, UMIN(remains, 32768) , &body_len);
|
||||
if (!body || body == uwsgi.empty) goto error;
|
||||
if (uwsgi.async <= 1) {
|
||||
if (rados_write(ctx, key, body, body_len, off) <= 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// increase request counter
|
||||
pthread_mutex_lock(&urio->mutex);
|
||||
urio->rid++;
|
||||
pthread_mutex_unlock(&urio->mutex);
|
||||
|
||||
struct uwsgi_rados_cb *urcb = uwsgi_malloc(sizeof(struct uwsgi_rados_cb));
|
||||
// map the current request id to the callback
|
||||
urcb->rid = urio->rid;
|
||||
// map urio to the callback
|
||||
urcb->urio = urio;
|
||||
|
||||
rados_completion_t comp;
|
||||
// use safe for write
|
||||
if (rados_aio_create_completion(urcb, NULL, uwsgi_rados_read_async_cb, &comp) < 0) {
|
||||
free(urcb);
|
||||
goto error;
|
||||
}
|
||||
if (rados_aio_write(ctx, key, comp, body, body_len, off) < 0) {
|
||||
free(urcb);
|
||||
rados_aio_release(comp);
|
||||
goto error;
|
||||
}
|
||||
|
||||
// wait for the callback to be executed
|
||||
if (uwsgi.wait_read_hook(urio->fds[0], timeout) <= 0) {
|
||||
rados_aio_release(comp);
|
||||
goto error;
|
||||
}
|
||||
char ack = 1;
|
||||
if (read(urio->fds[0], &ack, 1) != 1) {
|
||||
rados_aio_release(comp);
|
||||
uwsgi_error("uwsgi_rados_read_async()/read()");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (rados_aio_is_safe_and_cb(comp)) {
|
||||
if (rados_aio_get_return_value(comp) < 0) {
|
||||
rados_aio_release(comp);
|
||||
goto error;
|
||||
}
|
||||
|
||||
}
|
||||
rados_aio_release(comp);
|
||||
}
|
||||
remains -= body_len;
|
||||
off += body_len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
// async stat
|
||||
static int uwsgi_rados_async_stat(struct uwsgi_rados_io *urio, rados_ioctx_t ctx, const char *key, uint64_t *stat_size, time_t *stat_mtime, int timeout) {
|
||||
int ret = -1;
|
||||
// increase request counter
|
||||
pthread_mutex_lock(&urio->mutex);
|
||||
urio->rid++;
|
||||
pthread_mutex_unlock(&urio->mutex);
|
||||
|
||||
struct uwsgi_rados_cb *urcb = uwsgi_malloc(sizeof(struct uwsgi_rados_cb));
|
||||
// map the current request id to the callback
|
||||
urcb->rid = urio->rid;
|
||||
// map urio to the callback
|
||||
urcb->urio = urio;
|
||||
|
||||
rados_completion_t comp;
|
||||
if (rados_aio_create_completion(urcb, uwsgi_rados_read_async_cb, NULL, &comp) < 0) {
|
||||
free(urcb);
|
||||
goto end;
|
||||
}
|
||||
if (rados_aio_stat(ctx, key, comp, stat_size, stat_mtime) < 0) {
|
||||
free(urcb);
|
||||
rados_aio_release(comp);
|
||||
goto end;
|
||||
}
|
||||
|
||||
// wait for the callback to be executed
|
||||
if (uwsgi.wait_read_hook(urio->fds[0], timeout) <= 0) {
|
||||
rados_aio_release(comp);
|
||||
goto end;
|
||||
}
|
||||
char ack = 1;
|
||||
if (read(urio->fds[0], &ack, 1) != 1) {
|
||||
rados_aio_release(comp);
|
||||
uwsgi_error("uwsgi_rados_read_async()/read()");
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (rados_aio_is_complete_and_cb(comp)) {
|
||||
ret = rados_aio_get_return_value(comp);
|
||||
}
|
||||
rados_aio_release(comp);
|
||||
|
||||
end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int uwsgi_rados_read_async(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, const char *key, size_t remains, int timeout) {
|
||||
uint64_t off = 0;
|
||||
int ret = -1;
|
||||
char buf[8192];
|
||||
|
||||
struct uwsgi_rados_io *urio = &urados.urio[wsgi_req->async_id];
|
||||
// increase request counter
|
||||
pthread_mutex_lock(&urio->mutex);
|
||||
urio->rid++;
|
||||
pthread_mutex_unlock(&urio->mutex);
|
||||
|
||||
while(remains > 0) {
|
||||
struct uwsgi_rados_cb *urcb = uwsgi_malloc(sizeof(struct uwsgi_rados_cb));
|
||||
// map the current request id to the callback
|
||||
urcb->rid = urio->rid;
|
||||
// map urio to the callback
|
||||
urcb->urio = urio;
|
||||
|
||||
|
||||
rados_completion_t comp;
|
||||
if (rados_aio_create_completion(urcb, uwsgi_rados_read_async_cb, NULL, &comp) < 0) {
|
||||
free(urcb);
|
||||
break;
|
||||
}
|
||||
// trigger an async read
|
||||
if (rados_aio_read(ctx, key, comp, buf, UMIN(remains, 8192), off) < 0) {
|
||||
free(urcb);
|
||||
rados_aio_release(comp);
|
||||
break;
|
||||
}
|
||||
// wait for the callback to be executed
|
||||
if (uwsgi.wait_read_hook(urio->fds[0], timeout) <= 0) {
|
||||
rados_aio_release(comp);
|
||||
break;
|
||||
}
|
||||
char ack = 1;
|
||||
if (read(urio->fds[0], &ack, 1) != 1) {
|
||||
rados_aio_release(comp);
|
||||
uwsgi_error("uwsgi_rados_read_async()/read()");
|
||||
break;
|
||||
}
|
||||
int rlen = -1;
|
||||
if (rados_aio_is_complete_and_cb(comp)) {
|
||||
rlen = rados_aio_get_return_value(comp);
|
||||
}
|
||||
rados_aio_release(comp);
|
||||
if (rlen <= 0) break;
|
||||
if (uwsgi_response_write_body_do(wsgi_req, buf, rlen)) break;
|
||||
remains -= rlen;
|
||||
off += rlen;
|
||||
}
|
||||
|
||||
if (remains == 0) ret = 0;
|
||||
|
||||
pthread_mutex_lock(&urio->mutex);
|
||||
// increase the counter again
|
||||
urio->rid++;
|
||||
pthread_mutex_unlock(&urio->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void uwsgi_rados_add_mountpoint(char *arg, size_t arg_len) {
|
||||
char *rad_mountpoint = NULL;
|
||||
char *rad_config = NULL;
|
||||
char *rad_poolname = NULL;
|
||||
struct uwsgi_rados_mountpoint *urmp = uwsgi_calloc(sizeof(struct uwsgi_rados_mountpoint));
|
||||
if (uwsgi_kvlist_parse(arg, arg_len, ',', '=',
|
||||
"mountpoint", &rad_mountpoint,
|
||||
"config", &rad_config,
|
||||
"pool", &rad_poolname,
|
||||
"mountpoint", &urmp->mountpoint,
|
||||
"config", &urmp->config,
|
||||
"pool", &urmp->pool,
|
||||
"timeout", &urmp->str_timeout,
|
||||
"allow_put", &urmp->allow_put,
|
||||
"allow_delete", &urmp->allow_delete,
|
||||
"allow_mkcol", &urmp->allow_mkcol,
|
||||
NULL)) {
|
||||
uwsgi_log("unable to parse rados mountpoint definition\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!rad_mountpoint|| !rad_poolname) {
|
||||
if (!urmp->mountpoint|| !urmp->pool) {
|
||||
uwsgi_log("[rados] mount requires a mountpoint, and a pool name.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (urmp->str_timeout) {
|
||||
urmp->timeout = atoi(urmp->str_timeout);
|
||||
}
|
||||
|
||||
time_t now = uwsgi_now();
|
||||
uwsgi_log("[rados] mounting %s ...\n", rad_mountpoint);
|
||||
uwsgi_log("[rados] mounting %s ...\n", urmp->mountpoint);
|
||||
|
||||
rados_t cluster;
|
||||
if (rados_create(&cluster, NULL) < 0) {
|
||||
uwsgi_error("Can't create Ceph cluster handle");
|
||||
uwsgi_error("can't create Ceph cluster handle");
|
||||
exit(1);
|
||||
}
|
||||
if (rad_config)
|
||||
uwsgi_log("Using Ceph conf:%s\n", rad_config);
|
||||
urmp->cluster = cluster;
|
||||
|
||||
if (urmp->config)
|
||||
uwsgi_log("using Ceph conf:%s\n", urmp->config);
|
||||
else
|
||||
uwsgi_log("Using default Ceph conf.\n");
|
||||
if (rados_conf_read_file(cluster, rad_config) < 0) {
|
||||
uwsgi_error("Can't configure Ceph cluster handle");
|
||||
uwsgi_log("using default Ceph conf.\n");
|
||||
|
||||
if (rados_conf_read_file(cluster, urmp->config) < 0) {
|
||||
uwsgi_error("can't configure Ceph cluster handle");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int timeout = urmp->timeout ? urmp->timeout : urados.timeout;
|
||||
char *timeout_str = uwsgi_num2str(timeout);
|
||||
|
||||
rados_conf_set(cluster, "client_mount_timeout", timeout_str);
|
||||
rados_conf_set(cluster, "rados_mon_op_timeout", timeout_str);
|
||||
rados_conf_set(cluster, "rados_osd_op_timeout", timeout_str);
|
||||
|
||||
free(timeout_str);
|
||||
|
||||
|
||||
if (rados_connect(cluster) < 0) {
|
||||
uwsgi_error("Can't connect with Ceph cluster");
|
||||
uwsgi_error("can't connect with Ceph cluster");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rados_ioctx_t ctx;
|
||||
uwsgi_log("Ceph pool: %s\n", rad_poolname);
|
||||
if (rados_ioctx_create(cluster, rad_poolname, &ctx) < 0) {
|
||||
uwsgi_error("Can't open rados pool")
|
||||
rados_shutdown(cluster);
|
||||
exit(1);
|
||||
|
||||
|
||||
void *ctx_ptr;
|
||||
|
||||
if (uwsgi.threads > 1) {
|
||||
int i;
|
||||
rados_ioctx_t *ctxes = uwsgi_calloc(sizeof(rados_ioctx_t) * uwsgi.threads);
|
||||
for(i=0;i<uwsgi.threads;i++) {
|
||||
if (rados_ioctx_create(cluster, urmp->pool, &ctxes[i]) < 0) {
|
||||
uwsgi_error("can't open rados pool")
|
||||
rados_shutdown(cluster);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
ctx_ptr = ctxes;
|
||||
}
|
||||
else {
|
||||
rados_ioctx_t ctx;
|
||||
if (rados_ioctx_create(cluster, urmp->pool, &ctx) < 0) {
|
||||
uwsgi_error("can't open rados pool")
|
||||
rados_shutdown(cluster);
|
||||
exit(1);
|
||||
}
|
||||
ctx_ptr = ctx;
|
||||
}
|
||||
|
||||
char fsid[37];
|
||||
rados_cluster_fsid(cluster, fsid, 37);
|
||||
uwsgi_log("connected to Ceph pool: %s on cluster %.*s\n", urmp->pool, 37, fsid);
|
||||
|
||||
int id = uwsgi_apps_cnt;
|
||||
struct uwsgi_app *ua = uwsgi_add_app(id, rados_plugin.modifier1, rad_mountpoint, strlen(rad_mountpoint), NULL, NULL);
|
||||
struct uwsgi_app *ua = uwsgi_add_app(id, rados_plugin.modifier1, urmp->mountpoint, strlen(urmp->mountpoint), NULL, NULL);
|
||||
if (!ua) {
|
||||
uwsgi_log("[rados] unable to mount %s\n", rad_mountpoint);
|
||||
uwsgi_log("[rados] unable to mount %s\n", urmp->mountpoint);
|
||||
rados_shutdown(cluster);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ua->responder0 = cluster;
|
||||
ua->responder1 = ctx;
|
||||
ua->responder0 = ctx_ptr;
|
||||
ua->responder1 = urmp;
|
||||
ua->started_at = now;
|
||||
ua->startup_time = uwsgi_now() - now;
|
||||
uwsgi_log("Rados app/mountpoint %d (%s) loaded in %d seconds at %p\n", id, rad_mountpoint, (int) ua->startup_time, ctx);
|
||||
uwsgi_log("Rados app/mountpoint %d (%s) loaded in %d seconds at %p\n", id, urmp->mountpoint, (int) ua->startup_time, ctx_ptr);
|
||||
}
|
||||
|
||||
// we translate the string list to an app representation
|
||||
@@ -166,6 +429,21 @@ static void uwsgi_rados_setup() {
|
||||
uwsgi_rados_add_mountpoint(usl->value, usl->len);
|
||||
usl = usl->next;
|
||||
}
|
||||
|
||||
// now initialize a pthread_mutex for each async core
|
||||
if (uwsgi.async > 1) {
|
||||
int i;
|
||||
urados.urio = uwsgi_calloc(sizeof(struct uwsgi_rados_io) * uwsgi.async);
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
urados.urio[i].fds[0] = -1;
|
||||
urados.urio[i].fds[1] = -1;
|
||||
if (pthread_mutex_init(&urados.urio[i].mutex, NULL)) {
|
||||
uwsgi_error("uwsgi_rados_setup()/pthread_mutex_init()");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int uwsgi_rados_request(struct wsgi_request *wsgi_req) {
|
||||
@@ -199,29 +477,146 @@ static int uwsgi_rados_request(struct wsgi_request *wsgi_req) {
|
||||
struct uwsgi_app *ua = &uwsgi_apps[wsgi_req->app_id];
|
||||
|
||||
if (wsgi_req->path_info_len > ua->mountpoint_len &&
|
||||
memcmp(wsgi_req->path_info, ua->mountpoint, ua->mountpoint_len) == 0)
|
||||
{
|
||||
memcmp(wsgi_req->path_info, ua->mountpoint, ua->mountpoint_len) == 0) {
|
||||
|
||||
memcpy(filename, wsgi_req->path_info+ua->mountpoint_len, wsgi_req->path_info_len-ua->mountpoint_len);
|
||||
filename[wsgi_req->path_info_len-ua->mountpoint_len] = 0;
|
||||
|
||||
} else {
|
||||
memcpy(filename, wsgi_req->path_info, wsgi_req->path_info_len);
|
||||
filename[wsgi_req->path_info_len] = 0;
|
||||
}
|
||||
filename[wsgi_req->path_info_len] = 0;
|
||||
|
||||
struct {
|
||||
uint64_t size;
|
||||
time_t mtime;
|
||||
} st;
|
||||
rados_ioctx_t ctx = ua->responder1;
|
||||
// in multithread mode the memory is different (as we need a ctx for each thread) !!!
|
||||
rados_ioctx_t ctx;
|
||||
if (uwsgi.threads > 1) {
|
||||
rados_ioctx_t *ctxes = (rados_ioctx_t *) ua->responder0;
|
||||
ctx = ctxes[wsgi_req->async_id];
|
||||
}
|
||||
else {
|
||||
ctx = (rados_ioctx_t) ua->responder0;
|
||||
}
|
||||
struct uwsgi_rados_mountpoint *urmp = (struct uwsgi_rados_mountpoint *) ua->responder1;
|
||||
uint64_t stat_size = 0;
|
||||
time_t stat_mtime = 0;
|
||||
|
||||
struct uwsgi_rados_io *urio = &urados.urio[wsgi_req->async_id];
|
||||
|
||||
if (uwsgi.async > 1) {
|
||||
// no need to lock here (the rid protect us)
|
||||
if (pipe(urio->fds)) {
|
||||
uwsgi_error("uwsgi_rados_read_async()/pipe()");
|
||||
uwsgi_500(wsgi_req);
|
||||
return UWSGI_OK;
|
||||
}
|
||||
}
|
||||
|
||||
int r = rados_stat(ctx, filename, &st.size, &st.mtime);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT)
|
||||
int ret = -1;
|
||||
int timeout = urmp->timeout ? urmp->timeout : urados.timeout;
|
||||
|
||||
if (!uwsgi_strncmp(wsgi_req->method, wsgi_req->method_len, "OPTIONS", 7)) {
|
||||
if (uwsgi_response_prepare_headers(wsgi_req, "200 OK", 6)) goto end;
|
||||
if (uwsgi_response_add_header(wsgi_req, "Dav", 3, "1", 1)) goto end;
|
||||
struct uwsgi_buffer *ub_allow = uwsgi_buffer_new(64);
|
||||
if (uwsgi_buffer_append(ub_allow, "OPTIONS, GET, HEAD", 18)) {
|
||||
uwsgi_buffer_destroy(ub_allow);
|
||||
goto end;
|
||||
}
|
||||
if (urmp->allow_put) {
|
||||
if (uwsgi_buffer_append(ub_allow, ", PUT", 5)) {
|
||||
uwsgi_buffer_destroy(ub_allow);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
if (urmp->allow_delete) {
|
||||
if (uwsgi_buffer_append(ub_allow, ", DELETE", 8)) {
|
||||
uwsgi_buffer_destroy(ub_allow);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
if (urmp->allow_mkcol) {
|
||||
if (uwsgi_buffer_append(ub_allow, ", MKCOL", 7)) {
|
||||
uwsgi_buffer_destroy(ub_allow);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
uwsgi_response_add_header(wsgi_req, "Allow", 5, ub_allow->buf, ub_allow->pos);
|
||||
uwsgi_buffer_destroy(ub_allow);
|
||||
goto end;
|
||||
}
|
||||
|
||||
// MKCOL does not require stat
|
||||
if (!uwsgi_strncmp(wsgi_req->method, wsgi_req->method_len, "MKCOL", 5)) {
|
||||
if (!urmp->allow_mkcol) {
|
||||
uwsgi_405(wsgi_req);
|
||||
goto end;
|
||||
}
|
||||
ret = rados_pool_create(urmp->cluster, filename);
|
||||
if (ret < 0) {
|
||||
if (ret == -EEXIST) {
|
||||
uwsgi_405(wsgi_req);
|
||||
}
|
||||
else {
|
||||
uwsgi_500(wsgi_req);
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
uwsgi_response_prepare_headers(wsgi_req, "201 Created", 11);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (uwsgi.async > 1) {
|
||||
ret = uwsgi_rados_async_stat(urio, ctx, filename, &stat_size, &stat_mtime, timeout);
|
||||
}
|
||||
else {
|
||||
ret = rados_stat(ctx, filename, &stat_size, &stat_mtime);
|
||||
}
|
||||
|
||||
// PUT AND MKCOL can be used for non-existent objects
|
||||
if (!uwsgi_strncmp(wsgi_req->method, wsgi_req->method_len, "PUT", 3)) {
|
||||
if (!urmp->allow_put) {
|
||||
uwsgi_405(wsgi_req);
|
||||
goto end;
|
||||
}
|
||||
if (ret == 0) {
|
||||
if (uwsgi_rados_delete(wsgi_req, ctx, filename, timeout)) {
|
||||
uwsgi_500(wsgi_req);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
if (uwsgi_rados_put(wsgi_req, ctx, filename, timeout)) {
|
||||
uwsgi_500(wsgi_req);
|
||||
goto end;
|
||||
}
|
||||
uwsgi_response_prepare_headers(wsgi_req, "201 Created", 11);
|
||||
goto end;
|
||||
}
|
||||
else if (ret < 0) {
|
||||
if (ret == -ENOENT)
|
||||
uwsgi_404(wsgi_req);
|
||||
else
|
||||
uwsgi_403(wsgi_req);
|
||||
return UWSGI_OK;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!uwsgi_strncmp(wsgi_req->method, wsgi_req->method_len, "DELETE", 6)) {
|
||||
if (!urmp->allow_delete) {
|
||||
uwsgi_405(wsgi_req);
|
||||
goto end;
|
||||
}
|
||||
if (uwsgi_rados_delete(wsgi_req, ctx, filename, timeout)) {
|
||||
uwsgi_403(wsgi_req);
|
||||
goto end;
|
||||
}
|
||||
uwsgi_response_prepare_headers(wsgi_req, "200 OK", 6);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (uwsgi_strncmp(wsgi_req->method, wsgi_req->method_len, "HEAD", 4) && uwsgi_strncmp(wsgi_req->method, wsgi_req->method_len, "GET", 3)) {
|
||||
uwsgi_405(wsgi_req);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
if (uwsgi_response_prepare_headers(wsgi_req, "200 OK", 6)) goto end;
|
||||
size_t mime_type_len = 0;
|
||||
@@ -230,14 +625,14 @@ static int uwsgi_rados_request(struct wsgi_request *wsgi_req) {
|
||||
if (uwsgi_response_add_content_type(wsgi_req, mime_type, mime_type_len)) goto end;
|
||||
}
|
||||
|
||||
if (uwsgi_response_add_last_modified(wsgi_req, (uint64_t) st.mtime)) goto end;
|
||||
if (uwsgi_response_add_content_length(wsgi_req, st.size)) goto end;
|
||||
if (uwsgi_response_add_last_modified(wsgi_req, (uint64_t) stat_mtime)) goto end;
|
||||
if (uwsgi_response_add_content_length(wsgi_req, stat_size)) goto end;
|
||||
|
||||
// skip body on HEAD
|
||||
if (uwsgi_strncmp(wsgi_req->method, wsgi_req->method_len, "HEAD", 4)) {
|
||||
size_t remains = st.size;
|
||||
size_t remains = stat_size;
|
||||
if (uwsgi.async > 1) {
|
||||
if (uwsgi_rados_read_async(wsgi_req, ctx, filename, remains)) goto end;
|
||||
if (uwsgi_rados_read_async(wsgi_req, ctx, filename, remains, timeout)) goto end;
|
||||
}
|
||||
else {
|
||||
if (uwsgi_rados_read_sync(wsgi_req, ctx, filename, remains)) goto end;
|
||||
@@ -245,6 +640,10 @@ static int uwsgi_rados_request(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
end:
|
||||
if (uwsgi.async > 1) {
|
||||
close(urio->fds[0]);
|
||||
close(urio->fds[1]);
|
||||
}
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -423,7 +423,7 @@ static int uwsgi_proto_http_parser(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
// mute on 0 len...
|
||||
if (wsgi_req->proto_parser_pos > 0) {
|
||||
uwsgi_log("uwsgi_proto_http_parser() -> client closed connection");
|
||||
uwsgi_log("uwsgi_proto_http_parser() -> client closed connection\n");
|
||||
}
|
||||
return -1;
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
|
||||
s.name = 'uwsgi'
|
||||
s.license = 'GPL-2'
|
||||
s.version = `python -c "import uwsgiconfig as uc; print uc.uwsgi_version"`.sub(/-dev-.*/,'')
|
||||
s.date = '2014-06-02'
|
||||
s.date = '2014-07-01'
|
||||
s.summary = "uWSGI"
|
||||
s.description = "The uWSGI server for Ruby/Rack"
|
||||
s.authors = ["Unbit"]
|
||||
|
||||
@@ -604,6 +604,8 @@ struct uwsgi_daemon {
|
||||
|
||||
int ns_pid;
|
||||
int throttle;
|
||||
|
||||
char *chdir;
|
||||
};
|
||||
|
||||
struct uwsgi_logger {
|
||||
@@ -3014,6 +3016,7 @@ void uwsgi_xml_config(char *, struct wsgi_request *, char *[]);
|
||||
void uwsgi_500(struct wsgi_request *);
|
||||
void uwsgi_403(struct wsgi_request *);
|
||||
void uwsgi_404(struct wsgi_request *);
|
||||
void uwsgi_405(struct wsgi_request *);
|
||||
void uwsgi_redirect_to_slash(struct wsgi_request *);
|
||||
|
||||
void manage_snmp(int, uint8_t *, int, struct sockaddr_in *);
|
||||
@@ -3790,6 +3793,8 @@ int uwsgi_logic_opt_if_reload(char *, char *);
|
||||
int uwsgi_logic_opt_if_not_reload(char *, char *);
|
||||
int uwsgi_logic_opt_if_plugin(char *, char *);
|
||||
int uwsgi_logic_opt_if_not_plugin(char *, char *);
|
||||
int uwsgi_logic_opt_if_hostname(char *, char *);
|
||||
int uwsgi_logic_opt_if_not_hostname(char *, char *);
|
||||
|
||||
|
||||
void uwsgi_opt_resolve(char *, char *, void *);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# uWSGI build system
|
||||
|
||||
uwsgi_version = '2.0.5.1'
|
||||
uwsgi_version = '2.0.6'
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
Reference in New Issue
Block a user