Skip to content

Commit

Permalink
ceph: Add support for rados_create2() API.
Browse files Browse the repository at this point in the history
We currently use the rados_create() API call but there is also
the more flexible rados_create2() API. This patch adds support
for this other API. Based on the LIBRADOS_VERSION_CODE we
determine if the API is available. We check if we are being
compiled on a platform with a API version lower then 0.68.0
as that is the first version where the new usable version of
rados_create2 with the 4 flags is available. This was verified
by checking the git repo of CEPH and looking for the moment the
new API calls was extended to the 4 argument version and then
searching back in the history for the first bump of the
LIBRADOS_VER_MINOR or LIBRADOS_VER_EXTRA.
  • Loading branch information
Marco van Wieringen committed Feb 11, 2016
1 parent 9c43f8d commit 0547899
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 5 deletions.
64 changes: 61 additions & 3 deletions src/stored/backends/rados_device.c
@@ -1,8 +1,8 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2014-2014 Planets Communications B.V.
Copyright (C) 2014-2014 Bareos GmbH & Co. KG
Copyright (C) 2014-2016 Planets Communications B.V.
Copyright (C) 2014-2016 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -39,6 +39,8 @@ enum device_option_type {
argument_conffile,
argument_poolname,
argument_clientid,
argument_clustername,
argument_username,
argument_striped,
argument_stripe_unit,
argument_stripe_count
Expand All @@ -53,7 +55,12 @@ struct device_option {
static device_option device_options[] = {
{ "conffile=", argument_conffile, 9 },
{ "poolname=", argument_poolname, 9 },
#if LIBRADOS_VERSION_CODE < 17408
{ "clientid=", argument_clientid, 9 },
#else
{ "clustername=", argument_clustername, 12 },
{ "username=", argument_username, 9 },
#endif
#ifdef HAVE_RADOS_STRIPER
{ "striped", argument_striped, 7 },
{ "stripe_unit=", argument_stripe_unit, 11 },
Expand Down Expand Up @@ -102,10 +109,21 @@ int rados_device::d_open(const char *pathname, int flags, int mode)
m_rados_conffile = bp + device_options[i].compare_size;
done = true;
break;
#if LIBRADOS_VERSION_CODE < 17408
case argument_clientid:
m_rados_clientid = bp + device_options[i].compare_size;
done = true;
break;
#else
case argument_clustername:
m_rados_clustername = bp + device_options[i].compare_size;
done = true;
break;
case argument_username:
m_rados_username = bp + device_options[i].compare_size;
done = true;
break;
#endif
case argument_poolname:
m_rados_poolname = bp + device_options[i].compare_size;
done = true;
Expand Down Expand Up @@ -145,10 +163,20 @@ int rados_device::d_open(const char *pathname, int flags, int mode)
goto bail_out;
}

#if LIBRADOS_VERSION_CODE < 17408
if (!m_rados_clientid) {
Mmsg0(errmsg, _("No client id configured defaulting to %s\n"), DEFAULT_CLIENTID);
Mmsg1(errmsg, _("No client id configured defaulting to %s\n"), DEFAULT_CLIENTID);
m_rados_clientid = bstrdup(DEFAULT_CLIENTID);
}
#else
if (!m_rados_clustername) {
m_rados_clustername = bstrdup(DEFAULT_CLUSTERNAME);
}
if (!m_rados_username) {
Mmsg1(errmsg, _("No username configured defaulting to %s\n"), DEFAULT_USERNAME);
m_rados_username = bstrdup(DEFAULT_USERNAME);
}
#endif

if (!m_rados_poolname) {
Mmsg0(errmsg, _("No rados pool configured\n"));
Expand All @@ -158,7 +186,19 @@ int rados_device::d_open(const char *pathname, int flags, int mode)
}

if (!m_cluster_initialized) {
#if LIBRADOS_VERSION_CODE >= 17408
uint64_t rados_flags = 0;
#endif

/*
* Use for versions lower then 0.69.1 the old rados_create() and
* for later version rados_create2() calls.
*/
#if LIBRADOS_VERSION_CODE < 17408
status = rados_create(&m_cluster, m_rados_clientid);
#else
status = rados_create2(&m_cluster, m_rados_clustername, m_rados_username, rados_flags);
#endif
if (status < 0) {
Mmsg1(errmsg, _("Unable to create RADOS cluster: ERR=%s\n"), be.bstrerror(-status));
Emsg0(M_FATAL, 0, errmsg);
Expand Down Expand Up @@ -469,6 +509,19 @@ rados_device::~rados_device()
m_cluster_initialized = false;
}

#if LIBRADOS_VERSION_CODE < 17408
if (m_rados_clientid) {
free(m_rados_clientid);
}
#else
if (m_rados_clustername) {
free(m_rados_clustername);
}
if (m_rados_username) {
free(m_rados_username);
}
#endif

if (m_rados_configstring) {
free(m_rados_configstring);
}
Expand All @@ -479,7 +532,12 @@ rados_device::rados_device()
m_rados_configstring = NULL;
m_rados_conffile = NULL;
m_rados_poolname = NULL;
#if LIBRADOS_VERSION_CODE < 17408
m_rados_clientid = NULL;
#else
m_rados_clustername = NULL;
m_rados_username = NULL;
#endif
m_cluster_initialized = false;
m_ctx = NULL;
#ifdef HAVE_RADOS_STRIPER
Expand Down
17 changes: 15 additions & 2 deletions src/stored/backends/rados_device.h
@@ -1,8 +1,8 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2014-2014 Planets Communications B.V.
Copyright (C) 2014-2014 Bareos GmbH & Co. KG
Copyright (C) 2014-2016 Planets Communications B.V.
Copyright (C) 2014-2016 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -34,14 +34,27 @@
#include <radosstriper/libradosstriper.h>
#endif

/*
* Use for versions lower then 0.68.0 of the API the old format and otherwise the new one.
*/
#if LIBRADOS_VERSION_CODE < 17408
#define DEFAULT_CLIENTID "admin"
#else
#define DEFAULT_CLUSTERNAME "ceph"
#define DEFAULT_USERNAME "client.admin"
#endif

class rados_device: public DEVICE {
private:
char *m_rados_configstring;
char *m_rados_conffile;
char *m_rados_poolname;
#if LIBRADOS_VERSION_CODE < 17408
char *m_rados_clientid;
#else
char *m_rados_clustername;
char *m_rados_username;
#endif
bool m_cluster_initialized;
#ifdef HAVE_RADOS_STRIPER
bool m_stripe_volume;
Expand Down

0 comments on commit 0547899

Please sign in to comment.