hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/fs/nfs/dns_resolve.c
....@@ -22,7 +22,8 @@
2222 char *ip_addr = NULL;
2323 int ip_len;
2424
25
- ip_len = dns_query(NULL, name, namelen, NULL, &ip_addr, NULL);
25
+ ip_len = dns_query(net, NULL, name, namelen, NULL, &ip_addr, NULL,
26
+ false);
2627 if (ip_len > 0)
2728 ret = rpc_pton(net, ip_addr, ip_len, sa, salen);
2829 else
....@@ -38,7 +39,6 @@
3839 #include <linux/string.h>
3940 #include <linux/kmod.h>
4041 #include <linux/slab.h>
41
-#include <linux/module.h>
4242 #include <linux/socket.h>
4343 #include <linux/seq_file.h>
4444 #include <linux/inet.h>
....@@ -65,6 +65,7 @@
6565
6666 struct sockaddr_storage addr;
6767 size_t addrlen;
68
+ struct rcu_head rcu_head;
6869 };
6970
7071
....@@ -91,7 +92,7 @@
9192 key = container_of(ckey, struct nfs_dns_ent, h);
9293
9394 kfree(new->hostname);
94
- new->hostname = kstrndup(key->hostname, key->namelen, GFP_KERNEL);
95
+ new->hostname = kmemdup_nul(key->hostname, key->namelen, GFP_KERNEL);
9596 if (new->hostname) {
9697 new->namelen = key->namelen;
9798 nfs_dns_ent_update(cnew, ckey);
....@@ -101,13 +102,21 @@
101102 }
102103 }
103104
105
+static void nfs_dns_ent_free_rcu(struct rcu_head *head)
106
+{
107
+ struct nfs_dns_ent *item;
108
+
109
+ item = container_of(head, struct nfs_dns_ent, rcu_head);
110
+ kfree(item->hostname);
111
+ kfree(item);
112
+}
113
+
104114 static void nfs_dns_ent_put(struct kref *ref)
105115 {
106116 struct nfs_dns_ent *item;
107117
108118 item = container_of(ref, struct nfs_dns_ent, h.ref);
109
- kfree(item->hostname);
110
- kfree(item);
119
+ call_rcu(&item->rcu_head, nfs_dns_ent_free_rcu);
111120 }
112121
113122 static struct cache_head *nfs_dns_ent_alloc(void)
....@@ -142,12 +151,13 @@
142151 struct cache_head *ch)
143152 {
144153 struct nfs_dns_ent *key = container_of(ch, struct nfs_dns_ent, h);
145
- int ret;
146154
147
- ret = nfs_cache_upcall(cd, key->hostname);
148
- if (ret)
149
- ret = sunrpc_cache_pipe_upcall(cd, ch);
150
- return ret;
155
+ if (test_and_set_bit(CACHE_PENDING, &ch->flags))
156
+ return 0;
157
+ if (!nfs_cache_upcall(cd, key->hostname))
158
+ return 0;
159
+ clear_bit(CACHE_PENDING, &ch->flags);
160
+ return sunrpc_cache_pipe_upcall_timeout(cd, ch);
151161 }
152162
153163 static int nfs_dns_match(struct cache_head *ca,
....@@ -195,7 +205,7 @@
195205 {
196206 struct cache_head *ch;
197207
198
- ch = sunrpc_cache_lookup(cd,
208
+ ch = sunrpc_cache_lookup_rcu(cd,
199209 &key->h,
200210 nfs_dns_hash(key));
201211 if (!ch)