From e2b2a16b8ca8409c9320db348cee9937596311e8 Mon Sep 17 00:00:00 2001 From: Unbit Date: Fri, 27 Jun 2014 15:02:56 +0200 Subject: [PATCH] fixed sync rados behaviour --- plugins/rados/rados.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/rados/rados.c b/plugins/rados/rados.c index f1c7be45..e2644d95 100644 --- a/plugins/rados/rados.c +++ b/plugins/rados/rados.c @@ -53,7 +53,7 @@ static struct uwsgi_option uwsgi_rados_options[] = { {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]; @@ -87,7 +87,7 @@ static void uwsgi_rados_read_async_cb(rados_completion_t comp, void *data) { free(urcb); } -static int uwsgi_rados_delete(struct wsgi_request *wsgi_req, rados_ioctx_t *ctx, char *key, int timeout) { +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); } @@ -137,7 +137,7 @@ end: return ret; } -static int uwsgi_rados_put(struct wsgi_request *wsgi_req, rados_ioctx_t *ctx, char *key, int timeout) { +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; @@ -206,7 +206,7 @@ error: } // 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) { +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); @@ -251,7 +251,7 @@ 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) { +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]; @@ -369,10 +369,10 @@ static void uwsgi_rados_add_mountpoint(char *arg, size_t arg_len) { exit(1); } - rados_ioctx_t ctx; - void *ctx_ptr; uwsgi_log("Ceph pool: %s\n", urmp->pool); + void *ctx_ptr; + if (uwsgi.threads > 1) { int i; rados_ioctx_t *ctxes = uwsgi_calloc(sizeof(rados_ioctx_t) * uwsgi.threads); @@ -386,6 +386,7 @@ static void uwsgi_rados_add_mountpoint(char *arg, size_t arg_len) { 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); @@ -406,7 +407,7 @@ static void uwsgi_rados_add_mountpoint(char *arg, size_t arg_len) { 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, urmp->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 @@ -572,8 +573,10 @@ static int uwsgi_rados_request(struct wsgi_request *wsgi_req) { } end: - close(urio->fds[0]); - close(urio->fds[1]); + if (uwsgi.async > 1) { + close(urio->fds[0]); + close(urio->fds[1]); + } return UWSGI_OK; }