NFS: Use kernel DNS resolver [ver #2]
authorBryan Schumaker <bjschuma@netapp.com>
Wed, 11 Aug 2010 08:37:53 +0000 (09:37 +0100)
committerSteve French <sfrench@us.ibm.com>
Wed, 11 Aug 2010 17:11:28 +0000 (17:11 +0000)
Use the kernel DNS resolver to translate hostnames to IP addresses.  Create a
new config option to choose between the legacy DNS resolver and the new
resolver.

Signed-off-by: Bryan Schumaker <bjschuma@netapp.com>
Acked-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>
fs/nfs/Kconfig
fs/nfs/dns_resolve.c
fs/nfs/dns_resolve.h

index cc1bb33b59b8d919b64c3b8c2895c3b08c6d80f5..c5bbdca13ac2952e769b8f900f04c3b1afba6309 100644 (file)
@@ -100,3 +100,19 @@ config NFS_FSCACHE
        help
          Say Y here if you want NFS data to be cached locally on disc through
          the general filesystem cache manager
+
+config NFS_USE_LEGACY_DNS
+       bool "Use the legacy NFS DNS resolver"
+       depends on NFS_V4
+       help
+         The kernel now provides a method for translating a host name into an
+         IP address.  Select Y here if you would rather use your own DNS
+         resolver script.
+
+         If unsure, say N
+
+config NFS_USE_KERNEL_DNS
+       bool
+       depends on NFS_V4 && !NFS_USE_LEGACY_DNS
+       select DNS_RESOLVER
+       default y
index 76fd235d0024e1970d44044536d2d929c02b9256..dba50a5625db7987d1e4a757063f3a5412ff5928 100644 (file)
@@ -6,6 +6,29 @@
  * Resolves DNS hostnames into valid ip addresses
  */
 
+#ifdef CONFIG_NFS_USE_KERNEL_DNS
+
+#include <linux/sunrpc/clnt.h>
+#include <linux/dns_resolver.h>
+
+ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
+               struct sockaddr *sa, size_t salen)
+{
+       ssize_t ret;
+       char *ip_addr = NULL;
+       int ip_len;
+
+       ip_len = dns_query(NULL, name, namelen, NULL, &ip_addr, NULL);
+       if (ip_len > 0)
+               ret = rpc_pton(ip_addr, ip_len, sa, salen);
+       else
+               ret = -ESRCH;
+       kfree(ip_addr);
+       return ret;
+}
+
+#else
+
 #include <linux/hash.h>
 #include <linux/string.h>
 #include <linux/kmod.h>
@@ -346,3 +369,4 @@ void nfs_dns_resolver_destroy(void)
        nfs_cache_unregister(&nfs_dns_resolve);
 }
 
+#endif
index a3f0938babf7685360fcb43bf84e29c8fcfc8e5b..199bb5543a91ad3dfc1e03e2f85894f78661e4cb 100644 (file)
@@ -6,8 +6,20 @@
 
 #define NFS_DNS_HOSTNAME_MAXLEN        (128)
 
+
+#ifdef CONFIG_NFS_USE_KERNEL_DNS
+static inline int nfs_dns_resolver_init(void)
+{
+       return 0;
+}
+
+static inline void nfs_dns_resolver_destroy(void)
+{}
+#else
 extern int nfs_dns_resolver_init(void);
 extern void nfs_dns_resolver_destroy(void);
+#endif
+
 extern ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
                struct sockaddr *sa, size_t salen);