Merge pull request #6292 from dx9/wip-12406-res_nquery

rgw/rgw_resolve: fallback to res_query when res_nquery not implemented

Reviewed-by: Yehuda Sadeh <yehuda@redhat.com>
This commit is contained in:
Yehuda Sadeh 2015-11-24 12:09:10 -08:00
commit 53eda867bc
4 changed files with 38 additions and 7 deletions

View File

@ -83,6 +83,8 @@ CHECK_SYMBOL_EXISTS(__u8 "sys/types.h;linux/types.h" HAVE___U8)
CHECK_SYMBOL_EXISTS(__u64 "sys/types.h;linux/types.h" HAVE___U64)
CHECK_SYMBOL_EXISTS(__s64 "sys/types.h;linux/types.h" HAVE___S64)
CHECK_SYMBOL_EXISTS(res_nquery "resolv.h" HAVE_RES_NQUERY)
set(CEPH_MAN_DIR "share/man" CACHE STRING "Install location for man pages (relative to prefix).")
option(ENABLE_SHARED "build shared libraries" ON)
@ -210,6 +212,11 @@ option(WITH_RADOSGW "Rados Gateway is enabled" ON)
#option for CephFS
option(WITH_CEPHFS "CephFS is enabled" ON)
option(WITH_THREAD_SAFE_RES_QUERY "res_query is thread safe" OFF)
if(WITH_THREAD_SAFE_RES_QUERY)
set(HAVE_THREAD_SAFE_RES_QUERY 1 CACHE INTERNAL "Thread safe res_query supported.")
endif(WITH_THREAD_SAFE_RES_QUERY)
# Now create a useable config.h
configure_file(
${PROJECT_SOURCE_DIR}/src/include/config-h.in.cmake

View File

@ -342,6 +342,7 @@ if test x"$resolv_libs" != "xok"; then
fi
fi
AC_SUBST([RESOLV_LIBS])
AC_DEFINE(HAVE_RES_NQUERY, 1, [Define if you have res_nquery])
dnl check for libkeyutils on linux
KEYUTILS_LIB=""

View File

@ -237,4 +237,10 @@
#cmakedefine HAVE_GPERFTOOLS_MALLOC_EXTENSION_H
#cmakedefine HAVE_GPERFTOOLS_PROFILER_H
/* res_nquery is supported */
#cmakedefine HAVE_RES_NQUERY
/* res_query is thread safe */
#cmakedefine HAVE_THREAD_SAFE_RES_QUERY
#endif /* CONFIG_H */

View File

@ -18,12 +18,13 @@
#define dout_subsys ceph_subsys_rgw
class RGWDNSResolver {
list<res_state> states;
Mutex lock;
#ifdef HAVE_RES_NQUERY
list<res_state> states;
int get_state(res_state *ps);
void put_state(res_state s);
#endif
public:
~RGWDNSResolver();
@ -33,14 +34,16 @@ public:
RGWDNSResolver::~RGWDNSResolver()
{
#ifdef HAVE_RES_NQUERY
list<res_state>::iterator iter;
for (iter = states.begin(); iter != states.end(); ++iter) {
struct __res_state *s = *iter;
delete s;
}
#endif
}
#ifdef HAVE_RES_NQUERY
int RGWDNSResolver::get_state(res_state *ps)
{
lock.Lock();
@ -68,18 +71,19 @@ void RGWDNSResolver::put_state(res_state s)
Mutex::Locker l(lock);
states.push_back(s);
}
#endif
int RGWDNSResolver::resolve_cname(const string& hostname, string& cname, bool *found)
{
res_state res;
*found = false;
#ifdef HAVE_RES_NQUERY
res_state res;
int r = get_state(&res);
if (r < 0) {
return r;
}
#endif
int ret;
@ -91,7 +95,18 @@ int RGWDNSResolver::resolve_cname(const string& hostname, string& cname, bool *f
const char *origname = hostname.c_str();
unsigned char *pt, *answer;
unsigned char *answend;
int len = res_nquery(res, origname, C_IN, T_CNAME, buf, sizeof(buf));
int len;
#ifdef HAVE_RES_NQUERY
len = res_nquery(res, origname, C_IN, T_CNAME, buf, sizeof(buf));
#else
{
# ifndef HAVE_THREAD_SAFE_RES_QUERY
Mutex::Locker l(lock);
# endif
len = res_query(origname, C_IN, T_CNAME, buf, sizeof(buf));
}
#endif
if (len < 0) {
dout(20) << "res_query() failed" << dendl;
ret = 0;
@ -157,7 +172,9 @@ int RGWDNSResolver::resolve_cname(const string& hostname, string& cname, bool *f
*found = true;
ret = 0;
done:
#ifdef HAVE_RES_NQUERY
put_state(res);
#endif
return ret;
}