2009-08-19 15:12:27 -07:00
|
|
|
/*
|
|
|
|
* linux/fs/nfs/dns_resolve.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Trond Myklebust <Trond.Myklebust@netapp.com>
|
|
|
|
*
|
|
|
|
* Resolves DNS hostnames into valid ip addresses
|
|
|
|
*/
|
|
|
|
|
2010-08-11 01:37:53 -07:00
|
|
|
#ifdef CONFIG_NFS_USE_KERNEL_DNS
|
|
|
|
|
2012-07-30 13:05:25 -07:00
|
|
|
#include <linux/module.h>
|
2010-08-11 01:37:53 -07:00
|
|
|
#include <linux/sunrpc/clnt.h>
|
2013-02-04 10:50:00 -07:00
|
|
|
#include <linux/sunrpc/addr.h>
|
2010-08-11 01:37:53 -07:00
|
|
|
#include <linux/dns_resolver.h>
|
2012-03-11 10:11:00 -07:00
|
|
|
#include "dns_resolve.h"
|
2010-08-11 01:37:53 -07:00
|
|
|
|
2011-11-25 07:13:04 -07:00
|
|
|
ssize_t nfs_dns_resolve_name(struct net *net, char *name, size_t namelen,
|
2010-08-11 01:37:53 -07:00
|
|
|
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)
|
2012-01-26 04:11:33 -07:00
|
|
|
ret = rpc_pton(net, ip_addr, ip_len, sa, salen);
|
2010-08-11 01:37:53 -07:00
|
|
|
else
|
|
|
|
ret = -ESRCH;
|
|
|
|
kfree(ip_addr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2012-07-30 13:05:25 -07:00
|
|
|
#include <linux/module.h>
|
2009-08-19 15:12:27 -07:00
|
|
|
#include <linux/hash.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/kmod.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 01:04:11 -07:00
|
|
|
#include <linux/slab.h>
|
2009-08-19 15:12:27 -07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/socket.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/inet.h>
|
|
|
|
#include <linux/sunrpc/clnt.h>
|
2013-02-04 10:50:00 -07:00
|
|
|
#include <linux/sunrpc/addr.h>
|
2009-08-19 15:12:27 -07:00
|
|
|
#include <linux/sunrpc/cache.h>
|
|
|
|
#include <linux/sunrpc/svcauth.h>
|
2011-11-25 07:13:12 -07:00
|
|
|
#include <linux/sunrpc/rpc_pipe_fs.h>
|
2013-11-13 10:29:08 -07:00
|
|
|
#include <linux/nfs_fs.h>
|
2009-08-19 15:12:27 -07:00
|
|
|
|
2013-11-13 10:29:08 -07:00
|
|
|
#include "nfs4_fs.h"
|
2009-08-19 15:12:27 -07:00
|
|
|
#include "dns_resolve.h"
|
|
|
|
#include "cache_lib.h"
|
2011-11-25 07:13:04 -07:00
|
|
|
#include "netns.h"
|
2009-08-19 15:12:27 -07:00
|
|
|
|
|
|
|
#define NFS_DNS_HASHBITS 4
|
|
|
|
#define NFS_DNS_HASHTBL_SIZE (1 << NFS_DNS_HASHBITS)
|
|
|
|
|
|
|
|
struct nfs_dns_ent {
|
|
|
|
struct cache_head h;
|
|
|
|
|
|
|
|
char *hostname;
|
|
|
|
size_t namelen;
|
|
|
|
|
|
|
|
struct sockaddr_storage addr;
|
|
|
|
size_t addrlen;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-03-02 11:06:22 -07:00
|
|
|
static void nfs_dns_ent_update(struct cache_head *cnew,
|
|
|
|
struct cache_head *ckey)
|
|
|
|
{
|
|
|
|
struct nfs_dns_ent *new;
|
|
|
|
struct nfs_dns_ent *key;
|
|
|
|
|
|
|
|
new = container_of(cnew, struct nfs_dns_ent, h);
|
|
|
|
key = container_of(ckey, struct nfs_dns_ent, h);
|
|
|
|
|
|
|
|
memcpy(&new->addr, &key->addr, key->addrlen);
|
|
|
|
new->addrlen = key->addrlen;
|
|
|
|
}
|
|
|
|
|
2009-08-19 15:12:27 -07:00
|
|
|
static void nfs_dns_ent_init(struct cache_head *cnew,
|
|
|
|
struct cache_head *ckey)
|
|
|
|
{
|
|
|
|
struct nfs_dns_ent *new;
|
|
|
|
struct nfs_dns_ent *key;
|
|
|
|
|
|
|
|
new = container_of(cnew, struct nfs_dns_ent, h);
|
|
|
|
key = container_of(ckey, struct nfs_dns_ent, h);
|
|
|
|
|
|
|
|
kfree(new->hostname);
|
|
|
|
new->hostname = kstrndup(key->hostname, key->namelen, GFP_KERNEL);
|
|
|
|
if (new->hostname) {
|
|
|
|
new->namelen = key->namelen;
|
2010-03-02 11:06:22 -07:00
|
|
|
nfs_dns_ent_update(cnew, ckey);
|
2009-08-19 15:12:27 -07:00
|
|
|
} else {
|
|
|
|
new->namelen = 0;
|
|
|
|
new->addrlen = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nfs_dns_ent_put(struct kref *ref)
|
|
|
|
{
|
|
|
|
struct nfs_dns_ent *item;
|
|
|
|
|
|
|
|
item = container_of(ref, struct nfs_dns_ent, h.ref);
|
|
|
|
kfree(item->hostname);
|
|
|
|
kfree(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cache_head *nfs_dns_ent_alloc(void)
|
|
|
|
{
|
|
|
|
struct nfs_dns_ent *item = kmalloc(sizeof(*item), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (item != NULL) {
|
|
|
|
item->hostname = NULL;
|
|
|
|
item->namelen = 0;
|
|
|
|
item->addrlen = 0;
|
|
|
|
return &item->h;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned int nfs_dns_hash(const struct nfs_dns_ent *key)
|
|
|
|
{
|
|
|
|
return hash_str(key->hostname, NFS_DNS_HASHBITS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nfs_dns_request(struct cache_detail *cd,
|
|
|
|
struct cache_head *ch,
|
|
|
|
char **bpp, int *blen)
|
|
|
|
{
|
|
|
|
struct nfs_dns_ent *key = container_of(ch, struct nfs_dns_ent, h);
|
|
|
|
|
|
|
|
qword_add(bpp, blen, key->hostname);
|
|
|
|
(*bpp)[-1] = '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nfs_dns_upcall(struct cache_detail *cd,
|
|
|
|
struct cache_head *ch)
|
|
|
|
{
|
|
|
|
struct nfs_dns_ent *key = container_of(ch, struct nfs_dns_ent, h);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = nfs_cache_upcall(cd, key->hostname);
|
|
|
|
if (ret)
|
2013-02-04 04:02:55 -07:00
|
|
|
ret = sunrpc_cache_pipe_upcall(cd, ch);
|
2009-08-19 15:12:27 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nfs_dns_match(struct cache_head *ca,
|
|
|
|
struct cache_head *cb)
|
|
|
|
{
|
|
|
|
struct nfs_dns_ent *a;
|
|
|
|
struct nfs_dns_ent *b;
|
|
|
|
|
|
|
|
a = container_of(ca, struct nfs_dns_ent, h);
|
|
|
|
b = container_of(cb, struct nfs_dns_ent, h);
|
|
|
|
|
|
|
|
if (a->namelen == 0 || a->namelen != b->namelen)
|
|
|
|
return 0;
|
|
|
|
return memcmp(a->hostname, b->hostname, a->namelen) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nfs_dns_show(struct seq_file *m, struct cache_detail *cd,
|
|
|
|
struct cache_head *h)
|
|
|
|
{
|
|
|
|
struct nfs_dns_ent *item;
|
|
|
|
long ttl;
|
|
|
|
|
|
|
|
if (h == NULL) {
|
|
|
|
seq_puts(m, "# ip address hostname ttl\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
item = container_of(h, struct nfs_dns_ent, h);
|
2010-08-11 23:55:22 -07:00
|
|
|
ttl = item->h.expiry_time - seconds_since_boot();
|
2009-08-19 15:12:27 -07:00
|
|
|
if (ttl < 0)
|
|
|
|
ttl = 0;
|
|
|
|
|
|
|
|
if (!test_bit(CACHE_NEGATIVE, &h->flags)) {
|
|
|
|
char buf[INET6_ADDRSTRLEN+IPV6_SCOPE_ID_LEN+1];
|
|
|
|
|
|
|
|
rpc_ntop((struct sockaddr *)&item->addr, buf, sizeof(buf));
|
|
|
|
seq_printf(m, "%15s ", buf);
|
|
|
|
} else
|
|
|
|
seq_puts(m, "<none> ");
|
|
|
|
seq_printf(m, "%15s %ld\n", item->hostname, ttl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-03 13:54:01 -07:00
|
|
|
static struct nfs_dns_ent *nfs_dns_lookup(struct cache_detail *cd,
|
2009-08-19 15:12:27 -07:00
|
|
|
struct nfs_dns_ent *key)
|
|
|
|
{
|
|
|
|
struct cache_head *ch;
|
|
|
|
|
|
|
|
ch = sunrpc_cache_lookup(cd,
|
|
|
|
&key->h,
|
|
|
|
nfs_dns_hash(key));
|
|
|
|
if (!ch)
|
|
|
|
return NULL;
|
|
|
|
return container_of(ch, struct nfs_dns_ent, h);
|
|
|
|
}
|
|
|
|
|
2009-12-03 13:54:01 -07:00
|
|
|
static struct nfs_dns_ent *nfs_dns_update(struct cache_detail *cd,
|
2009-08-19 15:12:27 -07:00
|
|
|
struct nfs_dns_ent *new,
|
|
|
|
struct nfs_dns_ent *key)
|
|
|
|
{
|
|
|
|
struct cache_head *ch;
|
|
|
|
|
|
|
|
ch = sunrpc_cache_update(cd,
|
|
|
|
&new->h, &key->h,
|
|
|
|
nfs_dns_hash(key));
|
|
|
|
if (!ch)
|
|
|
|
return NULL;
|
|
|
|
return container_of(ch, struct nfs_dns_ent, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nfs_dns_parse(struct cache_detail *cd, char *buf, int buflen)
|
|
|
|
{
|
|
|
|
char buf1[NFS_DNS_HOSTNAME_MAXLEN+1];
|
|
|
|
struct nfs_dns_ent key, *item;
|
2012-10-30 18:16:01 -07:00
|
|
|
unsigned int ttl;
|
2009-08-19 15:12:27 -07:00
|
|
|
ssize_t len;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
if (buf[buflen-1] != '\n')
|
|
|
|
goto out;
|
|
|
|
buf[buflen-1] = '\0';
|
|
|
|
|
|
|
|
len = qword_get(&buf, buf1, sizeof(buf1));
|
|
|
|
if (len <= 0)
|
|
|
|
goto out;
|
2012-01-19 07:51:04 -07:00
|
|
|
key.addrlen = rpc_pton(cd->net, buf1, len,
|
2009-08-19 15:12:27 -07:00
|
|
|
(struct sockaddr *)&key.addr,
|
|
|
|
sizeof(key.addr));
|
|
|
|
|
|
|
|
len = qword_get(&buf, buf1, sizeof(buf1));
|
|
|
|
if (len <= 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
key.hostname = buf1;
|
|
|
|
key.namelen = len;
|
|
|
|
memset(&key.h, 0, sizeof(key.h));
|
|
|
|
|
2012-10-30 18:16:01 -07:00
|
|
|
if (get_uint(&buf, &ttl) < 0)
|
|
|
|
goto out;
|
2009-08-19 15:12:27 -07:00
|
|
|
if (ttl == 0)
|
|
|
|
goto out;
|
2010-08-11 23:55:22 -07:00
|
|
|
key.h.expiry_time = ttl + seconds_since_boot();
|
2009-08-19 15:12:27 -07:00
|
|
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
item = nfs_dns_lookup(cd, &key);
|
|
|
|
if (item == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (key.addrlen == 0)
|
|
|
|
set_bit(CACHE_NEGATIVE, &key.h.flags);
|
|
|
|
|
|
|
|
item = nfs_dns_update(cd, &key, item);
|
|
|
|
if (item == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cache_put(&item->h, cd);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_cache_lookup(struct cache_detail *cd,
|
|
|
|
struct nfs_dns_ent *key,
|
|
|
|
struct nfs_dns_ent **item,
|
|
|
|
struct nfs_cache_defer_req *dreq)
|
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
|
|
|
|
*item = nfs_dns_lookup(cd, key);
|
|
|
|
if (*item) {
|
|
|
|
ret = cache_check(cd, &(*item)->h, &dreq->req);
|
|
|
|
if (ret)
|
|
|
|
*item = NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_cache_lookup_nowait(struct cache_detail *cd,
|
|
|
|
struct nfs_dns_ent *key,
|
|
|
|
struct nfs_dns_ent **item)
|
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
|
|
|
|
*item = nfs_dns_lookup(cd, key);
|
|
|
|
if (!*item)
|
|
|
|
goto out_err;
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
if (!test_bit(CACHE_VALID, &(*item)->h.flags)
|
2010-08-11 23:55:22 -07:00
|
|
|
|| (*item)->h.expiry_time < seconds_since_boot()
|
2009-08-19 15:12:27 -07:00
|
|
|
|| cd->flush_time > (*item)->h.last_refresh)
|
|
|
|
goto out_put;
|
|
|
|
ret = -ENOENT;
|
|
|
|
if (test_bit(CACHE_NEGATIVE, &(*item)->h.flags))
|
|
|
|
goto out_put;
|
|
|
|
return 0;
|
|
|
|
out_put:
|
|
|
|
cache_put(&(*item)->h, cd);
|
|
|
|
out_err:
|
|
|
|
*item = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_cache_lookup_wait(struct cache_detail *cd,
|
|
|
|
struct nfs_dns_ent *key,
|
|
|
|
struct nfs_dns_ent **item)
|
|
|
|
{
|
|
|
|
struct nfs_cache_defer_req *dreq;
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
|
|
|
|
dreq = nfs_cache_defer_req_alloc();
|
|
|
|
if (!dreq)
|
|
|
|
goto out;
|
|
|
|
ret = do_cache_lookup(cd, key, item, dreq);
|
|
|
|
if (ret == -EAGAIN) {
|
|
|
|
ret = nfs_cache_wait_for_upcall(dreq);
|
|
|
|
if (!ret)
|
|
|
|
ret = do_cache_lookup_nowait(cd, key, item);
|
|
|
|
}
|
|
|
|
nfs_cache_defer_req_put(dreq);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-25 07:13:04 -07:00
|
|
|
ssize_t nfs_dns_resolve_name(struct net *net, char *name,
|
|
|
|
size_t namelen, struct sockaddr *sa, size_t salen)
|
2009-08-19 15:12:27 -07:00
|
|
|
{
|
|
|
|
struct nfs_dns_ent key = {
|
|
|
|
.hostname = name,
|
|
|
|
.namelen = namelen,
|
|
|
|
};
|
|
|
|
struct nfs_dns_ent *item = NULL;
|
|
|
|
ssize_t ret;
|
2011-11-25 07:13:04 -07:00
|
|
|
struct nfs_net *nn = net_generic(net, nfs_net_id);
|
2009-08-19 15:12:27 -07:00
|
|
|
|
2011-11-25 07:13:04 -07:00
|
|
|
ret = do_cache_lookup_wait(nn->nfs_dns_resolve, &key, &item);
|
2009-08-19 15:12:27 -07:00
|
|
|
if (ret == 0) {
|
|
|
|
if (salen >= item->addrlen) {
|
|
|
|
memcpy(sa, &item->addr, item->addrlen);
|
|
|
|
ret = item->addrlen;
|
|
|
|
} else
|
|
|
|
ret = -EOVERFLOW;
|
2011-11-25 07:13:04 -07:00
|
|
|
cache_put(&item->h, nn->nfs_dns_resolve);
|
2009-08-19 15:12:27 -07:00
|
|
|
} else if (ret == -ENOENT)
|
|
|
|
ret = -ESRCH;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-02-04 04:02:35 -07:00
|
|
|
static struct cache_detail nfs_dns_resolve_template = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.hash_size = NFS_DNS_HASHTBL_SIZE,
|
|
|
|
.name = "dns_resolve",
|
|
|
|
.cache_put = nfs_dns_ent_put,
|
|
|
|
.cache_upcall = nfs_dns_upcall,
|
2013-02-04 04:02:45 -07:00
|
|
|
.cache_request = nfs_dns_request,
|
2013-02-04 04:02:35 -07:00
|
|
|
.cache_parse = nfs_dns_parse,
|
|
|
|
.cache_show = nfs_dns_show,
|
|
|
|
.match = nfs_dns_match,
|
|
|
|
.init = nfs_dns_ent_init,
|
|
|
|
.update = nfs_dns_ent_update,
|
|
|
|
.alloc = nfs_dns_ent_alloc,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-11-25 07:13:04 -07:00
|
|
|
int nfs_dns_resolver_cache_init(struct net *net)
|
2009-08-19 15:12:27 -07:00
|
|
|
{
|
2013-02-04 04:02:35 -07:00
|
|
|
int err;
|
2011-11-25 07:13:04 -07:00
|
|
|
struct nfs_net *nn = net_generic(net, nfs_net_id);
|
|
|
|
|
2013-02-04 04:02:35 -07:00
|
|
|
nn->nfs_dns_resolve = cache_create_net(&nfs_dns_resolve_template, net);
|
|
|
|
if (IS_ERR(nn->nfs_dns_resolve))
|
|
|
|
return PTR_ERR(nn->nfs_dns_resolve);
|
|
|
|
|
|
|
|
err = nfs_cache_register_net(net, nn->nfs_dns_resolve);
|
2011-11-25 07:13:04 -07:00
|
|
|
if (err)
|
|
|
|
goto err_reg;
|
|
|
|
return 0;
|
2011-11-25 07:12:48 -07:00
|
|
|
|
2011-11-25 07:13:04 -07:00
|
|
|
err_reg:
|
2013-02-04 04:02:35 -07:00
|
|
|
cache_destroy_net(nn->nfs_dns_resolve, net);
|
2011-11-25 07:13:04 -07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nfs_dns_resolver_cache_destroy(struct net *net)
|
|
|
|
{
|
|
|
|
struct nfs_net *nn = net_generic(net, nfs_net_id);
|
|
|
|
|
2013-02-04 04:02:40 -07:00
|
|
|
nfs_cache_unregister_net(net, nn->nfs_dns_resolve);
|
2013-02-04 04:02:35 -07:00
|
|
|
cache_destroy_net(nn->nfs_dns_resolve, net);
|
2011-11-25 07:13:04 -07:00
|
|
|
}
|
|
|
|
|
2013-06-01 08:50:58 -07:00
|
|
|
static int nfs4_dns_net_init(struct net *net)
|
|
|
|
{
|
|
|
|
return nfs_dns_resolver_cache_init(net);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nfs4_dns_net_exit(struct net *net)
|
|
|
|
{
|
|
|
|
nfs_dns_resolver_cache_destroy(net);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations nfs4_dns_resolver_ops = {
|
|
|
|
.init = nfs4_dns_net_init,
|
|
|
|
.exit = nfs4_dns_net_exit,
|
|
|
|
};
|
|
|
|
|
2011-11-25 07:13:12 -07:00
|
|
|
static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
|
|
|
|
void *ptr)
|
|
|
|
{
|
|
|
|
struct super_block *sb = ptr;
|
|
|
|
struct net *net = sb->s_fs_info;
|
|
|
|
struct nfs_net *nn = net_generic(net, nfs_net_id);
|
|
|
|
struct cache_detail *cd = nn->nfs_dns_resolve;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (cd == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!try_module_get(THIS_MODULE))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case RPC_PIPEFS_MOUNT:
|
|
|
|
ret = nfs_cache_register_sb(sb, cd);
|
|
|
|
break;
|
|
|
|
case RPC_PIPEFS_UMOUNT:
|
|
|
|
nfs_cache_unregister_sb(sb, cd);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -ENOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
module_put(THIS_MODULE);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block nfs_dns_resolver_block = {
|
|
|
|
.notifier_call = rpc_pipefs_event,
|
|
|
|
};
|
|
|
|
|
2011-11-25 07:13:04 -07:00
|
|
|
int nfs_dns_resolver_init(void)
|
|
|
|
{
|
2013-06-01 08:50:58 -07:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = register_pernet_subsys(&nfs4_dns_resolver_ops);
|
|
|
|
if (err < 0)
|
|
|
|
goto out;
|
|
|
|
err = rpc_pipefs_notifier_register(&nfs_dns_resolver_block);
|
|
|
|
if (err < 0)
|
|
|
|
goto out1;
|
|
|
|
return 0;
|
|
|
|
out1:
|
|
|
|
unregister_pernet_subsys(&nfs4_dns_resolver_ops);
|
|
|
|
out:
|
|
|
|
return err;
|
2009-08-19 15:12:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nfs_dns_resolver_destroy(void)
|
|
|
|
{
|
2011-11-25 07:13:12 -07:00
|
|
|
rpc_pipefs_notifier_unregister(&nfs_dns_resolver_block);
|
2013-06-01 08:50:58 -07:00
|
|
|
unregister_pernet_subsys(&nfs4_dns_resolver_ops);
|
2009-08-19 15:12:27 -07:00
|
|
|
}
|
2010-08-11 01:37:53 -07:00
|
|
|
#endif
|