Skip to content

Commit

Permalink
Merge pull request #1341 from funny-falcon/rados_namespace
Browse files Browse the repository at this point in the history
plugin/rados: add ability to configure rados namespace
  • Loading branch information
unbit committed Aug 21, 2016
2 parents 49311b4 + 2630b08 commit 77a2c2c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
21 changes: 20 additions & 1 deletion plugins/rados/rados.c
Expand Up @@ -53,6 +53,7 @@ struct uwsgi_rados_mountpoint {
size_t buffer_size;
char *str_put_buffer_size;
size_t put_buffer_size;
char *namespace;
};

#define MIN_BUF_SIZE (8*1024)
Expand Down Expand Up @@ -159,7 +160,7 @@ static int uwsgi_rados_put(struct wsgi_request *wsgi_req, rados_ioctx_t ctx, cha
int ret;
const char* method;
int truncate = remains == 0;
#ifdef HAS_RADOS_POOL_REQUIRES_ALIGNMENT2
#ifdef HAS_RADOS_IOCTX_POOL_REQUIRES_ALIGNMENT2
if (!truncate && !rados_ioctx_pool_requires_alignment2(ctx, &ret) && ret) {
uint64_t alignment;
if (rados_ioctx_pool_required_alignment2(ctx, &alignment)) {
Expand Down Expand Up @@ -466,6 +467,7 @@ static void uwsgi_rados_add_mountpoint(char *arg, size_t arg_len) {
"username", &urmp->username,
"buffer_size", &urmp->str_buffer_size,
"put_buffer_size", &urmp->str_put_buffer_size,
"namespace", &urmp->namespace,
NULL)) {
uwsgi_log("unable to parse rados mountpoint definition\n");
exit(1);
Expand Down Expand Up @@ -506,6 +508,13 @@ static void uwsgi_rados_add_mountpoint(char *arg, size_t arg_len) {
urmp->put_buffer_size = urmp->buffer_size;
}

#ifndef HAS_RADOS_IOCTX_SET_NAMESPACE
if (urmp->namespace && strlen(urmp->namespace) > 0) {
uwsgi_error("[rados] unfortunately, librados too old to support namespaces");
exit(1);
}
#endif

time_t now = uwsgi_now();
uwsgi_log("[rados] mounting %s ...\n", urmp->mountpoint);

Expand Down Expand Up @@ -553,6 +562,11 @@ static void uwsgi_rados_add_mountpoint(char *arg, size_t arg_len) {
rados_shutdown(cluster);
exit(1);
}
#ifdef HAS_RADOS_IOCTX_SET_NAMESPACE
if (urmp->namespace) {
rados_ioctx_set_namespace(ctxes[i], urmp->namespace);
}
#endif
}
ctx_ptr = ctxes;
}
Expand All @@ -563,6 +577,11 @@ static void uwsgi_rados_add_mountpoint(char *arg, size_t arg_len) {
rados_shutdown(cluster);
exit(1);
}
#ifdef HAS_RADOS_IOCTX_SET_NAMESPACE
if (urmp->namespace) {
rados_ioctx_set_namespace(ctx, urmp->namespace);
}
#endif
ctx_ptr = ctx;
}

Expand Down
13 changes: 12 additions & 1 deletion plugins/rados/uwsgiplugin.py
Expand Up @@ -16,6 +16,17 @@
return 0;
}
""", LIBS=['-lrados'])
has_rados_ioctx_set_namespace = __main__.test_snippet("""
#include <rados/librados.h>
int main()
{
rados_ioctx_t ctx = NULL;
rados_ioctx_set_namespace(ctx, NULL);
return 0;
}
""", LIBS=['-lrados'])

if has_rados_ioctx_pool_requires_alignment2:
CFLAGS.append('-DHAS_RADOS_POOL_REQUIRES_ALIGNMENT2')
CFLAGS.append('-DHAS_RADOS_IOCTX_POOL_REQUIRES_ALIGNMENT2')
if has_rados_ioctx_set_namespace:
CFLAGS.append('-DHAS_RADOS_IOCTX_SET_NAMESPACE')

0 comments on commit 77a2c2c

Please sign in to comment.