Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * linux/fs/nfs/dns_resolve.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2009 Trond Myklebust <Trond.Myklebust@netapp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Resolves DNS hostnames into valid ip addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #ifdef CONFIG_NFS_USE_KERNEL_DNS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/sunrpc/addr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/dns_resolver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "dns_resolve.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) ssize_t nfs_dns_resolve_name(struct net *net, char *name, size_t namelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 		struct sockaddr *sa, size_t salen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	char *ip_addr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int ip_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	ip_len = dns_query(net, NULL, name, namelen, NULL, &ip_addr, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 			   false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	if (ip_len > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		ret = rpc_pton(net, ip_addr, ip_len, sa, salen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		ret = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	kfree(ip_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/kmod.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <linux/sunrpc/addr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <linux/sunrpc/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <linux/sunrpc/svcauth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include <linux/sunrpc/rpc_pipe_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include "nfs4_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #include "dns_resolve.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #include "cache_lib.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #include "netns.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define NFS_DNS_HASHBITS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define NFS_DNS_HASHTBL_SIZE (1 << NFS_DNS_HASHBITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) struct nfs_dns_ent {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct cache_head h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	char *hostname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	size_t namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct sockaddr_storage addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	size_t addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct rcu_head rcu_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static void nfs_dns_ent_update(struct cache_head *cnew,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		struct cache_head *ckey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct nfs_dns_ent *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct nfs_dns_ent *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	new = container_of(cnew, struct nfs_dns_ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	key = container_of(ckey, struct nfs_dns_ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	memcpy(&new->addr, &key->addr, key->addrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	new->addrlen = key->addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static void nfs_dns_ent_init(struct cache_head *cnew,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		struct cache_head *ckey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct nfs_dns_ent *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct nfs_dns_ent *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	new = container_of(cnew, struct nfs_dns_ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	key = container_of(ckey, struct nfs_dns_ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	kfree(new->hostname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	new->hostname = kmemdup_nul(key->hostname, key->namelen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (new->hostname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		new->namelen = key->namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		nfs_dns_ent_update(cnew, ckey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		new->namelen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		new->addrlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static void nfs_dns_ent_free_rcu(struct rcu_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct nfs_dns_ent *item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	item = container_of(head, struct nfs_dns_ent, rcu_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	kfree(item->hostname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	kfree(item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void nfs_dns_ent_put(struct kref *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct nfs_dns_ent *item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	item = container_of(ref, struct nfs_dns_ent, h.ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	call_rcu(&item->rcu_head, nfs_dns_ent_free_rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static struct cache_head *nfs_dns_ent_alloc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct nfs_dns_ent *item = kmalloc(sizeof(*item), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (item != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		item->hostname = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		item->namelen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		item->addrlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return &item->h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static unsigned int nfs_dns_hash(const struct nfs_dns_ent *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return hash_str(key->hostname, NFS_DNS_HASHBITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static void nfs_dns_request(struct cache_detail *cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		struct cache_head *ch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		char **bpp, int *blen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct nfs_dns_ent *key = container_of(ch, struct nfs_dns_ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	qword_add(bpp, blen, key->hostname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	(*bpp)[-1] = '\n';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int nfs_dns_upcall(struct cache_detail *cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		struct cache_head *ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct nfs_dns_ent *key = container_of(ch, struct nfs_dns_ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (test_and_set_bit(CACHE_PENDING, &ch->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (!nfs_cache_upcall(cd, key->hostname))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	clear_bit(CACHE_PENDING, &ch->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return sunrpc_cache_pipe_upcall_timeout(cd, ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int nfs_dns_match(struct cache_head *ca,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		struct cache_head *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct nfs_dns_ent *a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct nfs_dns_ent *b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	a = container_of(ca, struct nfs_dns_ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	b = container_of(cb, struct nfs_dns_ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (a->namelen == 0 || a->namelen != b->namelen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	return memcmp(a->hostname, b->hostname, a->namelen) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int nfs_dns_show(struct seq_file *m, struct cache_detail *cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		struct cache_head *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct nfs_dns_ent *item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	long ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (h == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		seq_puts(m, "# ip address      hostname        ttl\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	item = container_of(h, struct nfs_dns_ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	ttl = item->h.expiry_time - seconds_since_boot();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (ttl < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		ttl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (!test_bit(CACHE_NEGATIVE, &h->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		char buf[INET6_ADDRSTRLEN+IPV6_SCOPE_ID_LEN+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		rpc_ntop((struct sockaddr *)&item->addr, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		seq_printf(m, "%15s ", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		seq_puts(m, "<none>          ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	seq_printf(m, "%15s %ld\n", item->hostname, ttl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static struct nfs_dns_ent *nfs_dns_lookup(struct cache_detail *cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		struct nfs_dns_ent *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	struct cache_head *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	ch = sunrpc_cache_lookup_rcu(cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			&key->h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			nfs_dns_hash(key));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (!ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return container_of(ch, struct nfs_dns_ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static struct nfs_dns_ent *nfs_dns_update(struct cache_detail *cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		struct nfs_dns_ent *new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		struct nfs_dns_ent *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct cache_head *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	ch = sunrpc_cache_update(cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			&new->h, &key->h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			nfs_dns_hash(key));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (!ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return container_of(ch, struct nfs_dns_ent, h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static int nfs_dns_parse(struct cache_detail *cd, char *buf, int buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	char buf1[NFS_DNS_HOSTNAME_MAXLEN+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct nfs_dns_ent key, *item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	unsigned int ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	ssize_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (buf[buflen-1] != '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	buf[buflen-1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	len = qword_get(&buf, buf1, sizeof(buf1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	key.addrlen = rpc_pton(cd->net, buf1, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			(struct sockaddr *)&key.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			sizeof(key.addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	len = qword_get(&buf, buf1, sizeof(buf1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	key.hostname = buf1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	key.namelen = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	memset(&key.h, 0, sizeof(key.h));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (get_uint(&buf, &ttl) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (ttl == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	key.h.expiry_time = ttl + seconds_since_boot();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	item = nfs_dns_lookup(cd, &key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (item == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (key.addrlen == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		set_bit(CACHE_NEGATIVE, &key.h.flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	item = nfs_dns_update(cd, &key, item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (item == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	cache_put(&item->h, cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static int do_cache_lookup(struct cache_detail *cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		struct nfs_dns_ent *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		struct nfs_dns_ent **item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		struct nfs_cache_defer_req *dreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	*item = nfs_dns_lookup(cd, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (*item) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		ret = cache_check(cd, &(*item)->h, &dreq->req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			*item = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static int do_cache_lookup_nowait(struct cache_detail *cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		struct nfs_dns_ent *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		struct nfs_dns_ent **item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	*item = nfs_dns_lookup(cd, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (!*item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	ret = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (!test_bit(CACHE_VALID, &(*item)->h.flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			|| (*item)->h.expiry_time < seconds_since_boot()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			|| cd->flush_time > (*item)->h.last_refresh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (test_bit(CACHE_NEGATIVE, &(*item)->h.flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	cache_put(&(*item)->h, cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	*item = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static int do_cache_lookup_wait(struct cache_detail *cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		struct nfs_dns_ent *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		struct nfs_dns_ent **item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	struct nfs_cache_defer_req *dreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	dreq = nfs_cache_defer_req_alloc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (!dreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	ret = do_cache_lookup(cd, key, item, dreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	if (ret == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		ret = nfs_cache_wait_for_upcall(dreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			ret = do_cache_lookup_nowait(cd, key, item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	nfs_cache_defer_req_put(dreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ssize_t nfs_dns_resolve_name(struct net *net, char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		size_t namelen, struct sockaddr *sa, size_t salen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	struct nfs_dns_ent key = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		.hostname = name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		.namelen = namelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	struct nfs_dns_ent *item = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	struct nfs_net *nn = net_generic(net, nfs_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	ret = do_cache_lookup_wait(nn->nfs_dns_resolve, &key, &item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		if (salen >= item->addrlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			memcpy(sa, &item->addr, item->addrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			ret = item->addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			ret = -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		cache_put(&item->h, nn->nfs_dns_resolve);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	} else if (ret == -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		ret = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static struct cache_detail nfs_dns_resolve_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	.hash_size	= NFS_DNS_HASHTBL_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	.name		= "dns_resolve",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	.cache_put	= nfs_dns_ent_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	.cache_upcall	= nfs_dns_upcall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	.cache_request	= nfs_dns_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	.cache_parse	= nfs_dns_parse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	.cache_show	= nfs_dns_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	.match		= nfs_dns_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	.init		= nfs_dns_ent_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	.update		= nfs_dns_ent_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	.alloc		= nfs_dns_ent_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int nfs_dns_resolver_cache_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	struct nfs_net *nn = net_generic(net, nfs_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	nn->nfs_dns_resolve = cache_create_net(&nfs_dns_resolve_template, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	if (IS_ERR(nn->nfs_dns_resolve))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		return PTR_ERR(nn->nfs_dns_resolve);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	err = nfs_cache_register_net(net, nn->nfs_dns_resolve);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		goto err_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) err_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	cache_destroy_net(nn->nfs_dns_resolve, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) void nfs_dns_resolver_cache_destroy(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	struct nfs_net *nn = net_generic(net, nfs_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	nfs_cache_unregister_net(net, nn->nfs_dns_resolve);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	cache_destroy_net(nn->nfs_dns_resolve, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static int nfs4_dns_net_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	return nfs_dns_resolver_cache_init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static void nfs4_dns_net_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	nfs_dns_resolver_cache_destroy(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static struct pernet_operations nfs4_dns_resolver_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	.init = nfs4_dns_net_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	.exit = nfs4_dns_net_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			   void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	struct super_block *sb = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	struct net *net = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	struct nfs_net *nn = net_generic(net, nfs_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	struct cache_detail *cd = nn->nfs_dns_resolve;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	if (cd == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	if (!try_module_get(THIS_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	case RPC_PIPEFS_MOUNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		ret = nfs_cache_register_sb(sb, cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	case RPC_PIPEFS_UMOUNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		nfs_cache_unregister_sb(sb, cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		ret = -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) static struct notifier_block nfs_dns_resolver_block = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	.notifier_call	= rpc_pipefs_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) int nfs_dns_resolver_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	err = register_pernet_subsys(&nfs4_dns_resolver_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	err = rpc_pipefs_notifier_register(&nfs_dns_resolver_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	unregister_pernet_subsys(&nfs4_dns_resolver_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) void nfs_dns_resolver_destroy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	rpc_pipefs_notifier_unregister(&nfs_dns_resolver_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	unregister_pernet_subsys(&nfs4_dns_resolver_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) #endif