Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Device operations for the pnfs nfs4 file layout driver. |
| 3 | * |
| 4 | * Copyright (c) 2002 |
| 5 | * The Regents of the University of Michigan |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * Dean Hildebrand <dhildebz@umich.edu> |
| 9 | * Garth Goodson <Garth.Goodson@netapp.com> |
| 10 | * |
| 11 | * Permission is granted to use, copy, create derivative works, and |
| 12 | * redistribute this software and such derivative works for any purpose, |
| 13 | * so long as the name of the University of Michigan is not used in |
| 14 | * any advertising or publicity pertaining to the use or distribution |
| 15 | * of this software without specific, written prior authorization. If |
| 16 | * the above copyright notice or any other identification of the |
| 17 | * University of Michigan is included in any copy of any portion of |
| 18 | * this software, then the disclaimer below must also be included. |
| 19 | * |
| 20 | * This software is provided as is, without representation or warranty |
| 21 | * of any kind either express or implied, including without limitation |
| 22 | * the implied warranties of merchantability, fitness for a particular |
| 23 | * purpose, or noninfringement. The Regents of the University of |
| 24 | * Michigan shall not be liable for any damages, including special, |
| 25 | * indirect, incidental, or consequential damages, with respect to any |
| 26 | * claim arising out of or in connection with the use of the software, |
| 27 | * even if it has been or is hereafter advised of the possibility of |
| 28 | * such damages. |
| 29 | */ |
| 30 | |
| 31 | #include <linux/nfs_fs.h> |
| 32 | #include <linux/vmalloc.h> |
Andy Adamson | 98fc685 | 2012-04-27 17:53:45 -0400 | [diff] [blame] | 33 | #include <linux/module.h> |
Jeff Layton | 5976687 | 2013-02-04 12:50:00 -0500 | [diff] [blame] | 34 | #include <linux/sunrpc/addr.h> |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 35 | |
Tom Haynes | b596872 | 2014-05-12 14:35:52 -0700 | [diff] [blame] | 36 | #include "../internal.h" |
| 37 | #include "../nfs4session.h" |
| 38 | #include "filelayout.h" |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 39 | |
| 40 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD |
| 41 | |
Andy Adamson | 98fc685 | 2012-04-27 17:53:45 -0400 | [diff] [blame] | 42 | static unsigned int dataserver_timeo = NFS4_DEF_DS_TIMEO; |
| 43 | static unsigned int dataserver_retrans = NFS4_DEF_DS_RETRANS; |
| 44 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 45 | /* |
| 46 | * Data server cache |
| 47 | * |
| 48 | * Data servers can be mapped to different device ids. |
| 49 | * nfs4_pnfs_ds reference counting |
| 50 | * - set to 1 on allocation |
| 51 | * - incremented when a device id maps a data server already in the cache. |
| 52 | * - decremented when deviceid is removed from the cache. |
| 53 | */ |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 54 | static DEFINE_SPINLOCK(nfs4_ds_cache_lock); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 55 | static LIST_HEAD(nfs4_data_server_cache); |
| 56 | |
| 57 | /* Debug routines */ |
| 58 | void |
| 59 | print_ds(struct nfs4_pnfs_ds *ds) |
| 60 | { |
| 61 | if (ds == NULL) { |
| 62 | printk("%s NULL device\n", __func__); |
| 63 | return; |
| 64 | } |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 65 | printk(" ds %s\n" |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 66 | " ref count %d\n" |
| 67 | " client %p\n" |
| 68 | " cl_exchange_flags %x\n", |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 69 | ds->ds_remotestr, |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 70 | atomic_read(&ds->ds_count), ds->ds_clp, |
| 71 | ds->ds_clp ? ds->ds_clp->cl_exchange_flags : 0); |
| 72 | } |
| 73 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 74 | static bool |
| 75 | same_sockaddr(struct sockaddr *addr1, struct sockaddr *addr2) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 76 | { |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 77 | struct sockaddr_in *a, *b; |
| 78 | struct sockaddr_in6 *a6, *b6; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 79 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 80 | if (addr1->sa_family != addr2->sa_family) |
| 81 | return false; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 82 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 83 | switch (addr1->sa_family) { |
| 84 | case AF_INET: |
| 85 | a = (struct sockaddr_in *)addr1; |
| 86 | b = (struct sockaddr_in *)addr2; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 87 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 88 | if (a->sin_addr.s_addr == b->sin_addr.s_addr && |
| 89 | a->sin_port == b->sin_port) |
| 90 | return true; |
| 91 | break; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 92 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 93 | case AF_INET6: |
| 94 | a6 = (struct sockaddr_in6 *)addr1; |
| 95 | b6 = (struct sockaddr_in6 *)addr2; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 96 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 97 | /* LINKLOCAL addresses must have matching scope_id */ |
Alexander Aring | a8c2275 | 2013-12-21 05:39:04 +0100 | [diff] [blame] | 98 | if (ipv6_addr_src_scope(&a6->sin6_addr) == |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 99 | IPV6_ADDR_SCOPE_LINKLOCAL && |
| 100 | a6->sin6_scope_id != b6->sin6_scope_id) |
| 101 | return false; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 102 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 103 | if (ipv6_addr_equal(&a6->sin6_addr, &b6->sin6_addr) && |
| 104 | a6->sin6_port == b6->sin6_port) |
| 105 | return true; |
| 106 | break; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 107 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 108 | default: |
| 109 | dprintk("%s: unhandled address family: %u\n", |
| 110 | __func__, addr1->sa_family); |
| 111 | return false; |
| 112 | } |
| 113 | |
| 114 | return false; |
| 115 | } |
| 116 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 117 | static bool |
Weston Andros Adamson | 2d3fe01 | 2012-02-03 15:45:40 -0500 | [diff] [blame] | 118 | _same_data_server_addrs_locked(const struct list_head *dsaddrs1, |
| 119 | const struct list_head *dsaddrs2) |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 120 | { |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 121 | struct nfs4_pnfs_ds_addr *da1, *da2; |
| 122 | |
Weston Andros Adamson | 2d3fe01 | 2012-02-03 15:45:40 -0500 | [diff] [blame] | 123 | /* step through both lists, comparing as we go */ |
| 124 | for (da1 = list_first_entry(dsaddrs1, typeof(*da1), da_node), |
| 125 | da2 = list_first_entry(dsaddrs2, typeof(*da2), da_node); |
| 126 | da1 != NULL && da2 != NULL; |
| 127 | da1 = list_entry(da1->da_node.next, typeof(*da1), da_node), |
| 128 | da2 = list_entry(da2->da_node.next, typeof(*da2), da_node)) { |
| 129 | if (!same_sockaddr((struct sockaddr *)&da1->da_addr, |
| 130 | (struct sockaddr *)&da2->da_addr)) |
| 131 | return false; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 132 | } |
Weston Andros Adamson | 2d3fe01 | 2012-02-03 15:45:40 -0500 | [diff] [blame] | 133 | if (da1 == NULL && da2 == NULL) |
| 134 | return true; |
| 135 | |
| 136 | return false; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 137 | } |
| 138 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 139 | /* |
Weston Andros Adamson | 2d3fe01 | 2012-02-03 15:45:40 -0500 | [diff] [blame] | 140 | * Lookup DS by addresses. nfs4_ds_cache_lock is held |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 141 | */ |
Weston Andros Adamson | 2d3fe01 | 2012-02-03 15:45:40 -0500 | [diff] [blame] | 142 | static struct nfs4_pnfs_ds * |
| 143 | _data_server_lookup_locked(const struct list_head *dsaddrs) |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 144 | { |
Weston Andros Adamson | 2d3fe01 | 2012-02-03 15:45:40 -0500 | [diff] [blame] | 145 | struct nfs4_pnfs_ds *ds; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 146 | |
Weston Andros Adamson | 2d3fe01 | 2012-02-03 15:45:40 -0500 | [diff] [blame] | 147 | list_for_each_entry(ds, &nfs4_data_server_cache, ds_node) |
| 148 | if (_same_data_server_addrs_locked(&ds->ds_addrs, dsaddrs)) |
| 149 | return ds; |
| 150 | return NULL; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 154 | * Create an rpc connection to the nfs4_pnfs_ds data server |
Weston Andros Adamson | 35dbbc9 | 2011-06-01 16:32:21 -0400 | [diff] [blame] | 155 | * Currently only supports IPv4 and IPv6 addresses |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 156 | */ |
| 157 | static int |
| 158 | nfs4_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds) |
| 159 | { |
Weston Andros Adamson | 7e574f0 | 2011-05-31 18:48:58 -0400 | [diff] [blame] | 160 | struct nfs_client *clp = ERR_PTR(-EIO); |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 161 | struct nfs4_pnfs_ds_addr *da; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 162 | int status = 0; |
| 163 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 164 | dprintk("--> %s DS %s au_flavor %d\n", __func__, ds->ds_remotestr, |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 165 | mds_srv->nfs_client->cl_rpcclient->cl_auth->au_flavor); |
| 166 | |
Weston Andros Adamson | 7e574f0 | 2011-05-31 18:48:58 -0400 | [diff] [blame] | 167 | list_for_each_entry(da, &ds->ds_addrs, da_node) { |
| 168 | dprintk("%s: DS %s: trying address %s\n", |
| 169 | __func__, ds->ds_remotestr, da->da_remotestr); |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 170 | |
Weston Andros Adamson | 7e574f0 | 2011-05-31 18:48:58 -0400 | [diff] [blame] | 171 | clp = nfs4_set_ds_client(mds_srv->nfs_client, |
Andy Adamson | 98fc685 | 2012-04-27 17:53:45 -0400 | [diff] [blame] | 172 | (struct sockaddr *)&da->da_addr, |
| 173 | da->da_addrlen, IPPROTO_TCP, |
| 174 | dataserver_timeo, dataserver_retrans); |
Weston Andros Adamson | 7e574f0 | 2011-05-31 18:48:58 -0400 | [diff] [blame] | 175 | if (!IS_ERR(clp)) |
| 176 | break; |
| 177 | } |
| 178 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 179 | if (IS_ERR(clp)) { |
| 180 | status = PTR_ERR(clp); |
| 181 | goto out; |
| 182 | } |
| 183 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 184 | status = nfs4_init_ds_session(clp, mds_srv->nfs_client->cl_lease_time); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 185 | if (status) |
| 186 | goto out_put; |
| 187 | |
Trond Myklebust | acd65e5 | 2013-09-26 14:32:56 -0400 | [diff] [blame] | 188 | smp_wmb(); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 189 | ds->ds_clp = clp; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 190 | dprintk("%s [new] addr: %s\n", __func__, ds->ds_remotestr); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 191 | out: |
| 192 | return status; |
| 193 | out_put: |
| 194 | nfs_put_client(clp); |
| 195 | goto out; |
| 196 | } |
| 197 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 198 | static void |
| 199 | destroy_ds(struct nfs4_pnfs_ds *ds) |
| 200 | { |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 201 | struct nfs4_pnfs_ds_addr *da; |
| 202 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 203 | dprintk("--> %s\n", __func__); |
| 204 | ifdebug(FACILITY) |
| 205 | print_ds(ds); |
| 206 | |
| 207 | if (ds->ds_clp) |
| 208 | nfs_put_client(ds->ds_clp); |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 209 | |
| 210 | while (!list_empty(&ds->ds_addrs)) { |
| 211 | da = list_first_entry(&ds->ds_addrs, |
| 212 | struct nfs4_pnfs_ds_addr, |
| 213 | da_node); |
| 214 | list_del_init(&da->da_node); |
| 215 | kfree(da->da_remotestr); |
| 216 | kfree(da); |
| 217 | } |
| 218 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 219 | kfree(ds->ds_remotestr); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 220 | kfree(ds); |
| 221 | } |
| 222 | |
Benny Halevy | 1775bc3 | 2011-05-20 13:47:33 +0200 | [diff] [blame] | 223 | void |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 224 | nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr) |
| 225 | { |
| 226 | struct nfs4_pnfs_ds *ds; |
| 227 | int i; |
| 228 | |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 229 | nfs4_print_deviceid(&dsaddr->id_node.deviceid); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 230 | |
| 231 | for (i = 0; i < dsaddr->ds_num; i++) { |
| 232 | ds = dsaddr->ds_list[i]; |
| 233 | if (ds != NULL) { |
| 234 | if (atomic_dec_and_lock(&ds->ds_count, |
| 235 | &nfs4_ds_cache_lock)) { |
| 236 | list_del_init(&ds->ds_node); |
| 237 | spin_unlock(&nfs4_ds_cache_lock); |
| 238 | destroy_ds(ds); |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | kfree(dsaddr->stripe_indices); |
| 243 | kfree(dsaddr); |
| 244 | } |
| 245 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 246 | /* |
| 247 | * Create a string with a human readable address and port to avoid |
| 248 | * complicated setup around many dprinks. |
| 249 | */ |
| 250 | static char * |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 251 | nfs4_pnfs_remotestr(struct list_head *dsaddrs, gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 252 | { |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 253 | struct nfs4_pnfs_ds_addr *da; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 254 | char *remotestr; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 255 | size_t len; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 256 | char *p; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 257 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 258 | len = 3; /* '{', '}' and eol */ |
| 259 | list_for_each_entry(da, dsaddrs, da_node) { |
| 260 | len += strlen(da->da_remotestr) + 1; /* string plus comma */ |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 261 | } |
| 262 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 263 | remotestr = kzalloc(len, gfp_flags); |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 264 | if (!remotestr) |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 265 | return NULL; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 266 | |
| 267 | p = remotestr; |
| 268 | *(p++) = '{'; |
| 269 | len--; |
| 270 | list_for_each_entry(da, dsaddrs, da_node) { |
| 271 | size_t ll = strlen(da->da_remotestr); |
| 272 | |
| 273 | if (ll > len) |
| 274 | goto out_err; |
| 275 | |
| 276 | memcpy(p, da->da_remotestr, ll); |
| 277 | p += ll; |
| 278 | len -= ll; |
| 279 | |
| 280 | if (len < 1) |
| 281 | goto out_err; |
| 282 | (*p++) = ','; |
| 283 | len--; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 284 | } |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 285 | if (len < 2) |
| 286 | goto out_err; |
| 287 | *(p++) = '}'; |
| 288 | *p = '\0'; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 289 | return remotestr; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 290 | out_err: |
| 291 | kfree(remotestr); |
| 292 | return NULL; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static struct nfs4_pnfs_ds * |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 296 | nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags) |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 297 | { |
| 298 | struct nfs4_pnfs_ds *tmp_ds, *ds = NULL; |
| 299 | char *remotestr; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 300 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 301 | if (list_empty(dsaddrs)) { |
| 302 | dprintk("%s: no addresses defined\n", __func__); |
| 303 | goto out; |
| 304 | } |
| 305 | |
| 306 | ds = kzalloc(sizeof(*ds), gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 307 | if (!ds) |
| 308 | goto out; |
| 309 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 310 | /* this is only used for debugging, so it's ok if its NULL */ |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 311 | remotestr = nfs4_pnfs_remotestr(dsaddrs, gfp_flags); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 312 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 313 | spin_lock(&nfs4_ds_cache_lock); |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 314 | tmp_ds = _data_server_lookup_locked(dsaddrs); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 315 | if (tmp_ds == NULL) { |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 316 | INIT_LIST_HEAD(&ds->ds_addrs); |
| 317 | list_splice_init(dsaddrs, &ds->ds_addrs); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 318 | ds->ds_remotestr = remotestr; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 319 | atomic_set(&ds->ds_count, 1); |
| 320 | INIT_LIST_HEAD(&ds->ds_node); |
| 321 | ds->ds_clp = NULL; |
| 322 | list_add(&ds->ds_node, &nfs4_data_server_cache); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 323 | dprintk("%s add new data server %s\n", __func__, |
| 324 | ds->ds_remotestr); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 325 | } else { |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 326 | kfree(remotestr); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 327 | kfree(ds); |
| 328 | atomic_inc(&tmp_ds->ds_count); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 329 | dprintk("%s data server %s found, inc'ed ds_count to %d\n", |
| 330 | __func__, tmp_ds->ds_remotestr, |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 331 | atomic_read(&tmp_ds->ds_count)); |
| 332 | ds = tmp_ds; |
| 333 | } |
| 334 | spin_unlock(&nfs4_ds_cache_lock); |
| 335 | out: |
| 336 | return ds; |
| 337 | } |
| 338 | |
| 339 | /* |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 340 | * Currently only supports ipv4, ipv6 and one multi-path address. |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 341 | */ |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 342 | static struct nfs4_pnfs_ds_addr * |
Stanislav Kinsbursky | 1709427 | 2012-01-19 19:05:57 +0400 | [diff] [blame] | 343 | decode_ds_addr(struct net *net, struct xdr_stream *streamp, gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 344 | { |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 345 | struct nfs4_pnfs_ds_addr *da = NULL; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 346 | char *buf, *portstr; |
Dan Carpenter | 13fff2f | 2012-01-12 10:07:35 +0300 | [diff] [blame] | 347 | __be16 port; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 348 | int nlen, rlen; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 349 | int tmp[2]; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 350 | __be32 *p; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 351 | char *netid, *match_netid; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 352 | size_t len, match_netid_len; |
| 353 | char *startsep = ""; |
| 354 | char *endsep = ""; |
| 355 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 356 | |
| 357 | /* r_netid */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 358 | p = xdr_inline_decode(streamp, 4); |
| 359 | if (unlikely(!p)) |
| 360 | goto out_err; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 361 | nlen = be32_to_cpup(p++); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 362 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 363 | p = xdr_inline_decode(streamp, nlen); |
| 364 | if (unlikely(!p)) |
| 365 | goto out_err; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 366 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 367 | netid = kmalloc(nlen+1, gfp_flags); |
| 368 | if (unlikely(!netid)) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 369 | goto out_err; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 370 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 371 | netid[nlen] = '\0'; |
| 372 | memcpy(netid, p, nlen); |
| 373 | |
| 374 | /* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 375 | p = xdr_inline_decode(streamp, 4); |
| 376 | if (unlikely(!p)) |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 377 | goto out_free_netid; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 378 | rlen = be32_to_cpup(p); |
| 379 | |
| 380 | p = xdr_inline_decode(streamp, rlen); |
| 381 | if (unlikely(!p)) |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 382 | goto out_free_netid; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 383 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 384 | /* port is ".ABC.DEF", 8 chars max */ |
| 385 | if (rlen > INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN + 8) { |
Jesper Juhl | ad3d2ee | 2011-01-17 18:41:50 +0000 | [diff] [blame] | 386 | dprintk("%s: Invalid address, length %d\n", __func__, |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 387 | rlen); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 388 | goto out_free_netid; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 389 | } |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 390 | buf = kmalloc(rlen + 1, gfp_flags); |
Stanislav Fomichev | b9f8105 | 2011-02-05 23:13:01 +0000 | [diff] [blame] | 391 | if (!buf) { |
| 392 | dprintk("%s: Not enough memory\n", __func__); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 393 | goto out_free_netid; |
Stanislav Fomichev | b9f8105 | 2011-02-05 23:13:01 +0000 | [diff] [blame] | 394 | } |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 395 | buf[rlen] = '\0'; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 396 | memcpy(buf, p, rlen); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 397 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 398 | /* replace port '.' with '-' */ |
| 399 | portstr = strrchr(buf, '.'); |
| 400 | if (!portstr) { |
| 401 | dprintk("%s: Failed finding expected dot in port\n", |
| 402 | __func__); |
| 403 | goto out_free_buf; |
| 404 | } |
| 405 | *portstr = '-'; |
| 406 | |
| 407 | /* find '.' between address and port */ |
| 408 | portstr = strrchr(buf, '.'); |
| 409 | if (!portstr) { |
| 410 | dprintk("%s: Failed finding expected dot between address and " |
| 411 | "port\n", __func__); |
| 412 | goto out_free_buf; |
| 413 | } |
| 414 | *portstr = '\0'; |
| 415 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 416 | da = kzalloc(sizeof(*da), gfp_flags); |
| 417 | if (unlikely(!da)) |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 418 | goto out_free_buf; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 419 | |
| 420 | INIT_LIST_HEAD(&da->da_node); |
| 421 | |
Stanislav Kinsbursky | 1709427 | 2012-01-19 19:05:57 +0400 | [diff] [blame] | 422 | if (!rpc_pton(net, buf, portstr-buf, (struct sockaddr *)&da->da_addr, |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 423 | sizeof(da->da_addr))) { |
| 424 | dprintk("%s: error parsing address %s\n", __func__, buf); |
| 425 | goto out_free_da; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 426 | } |
| 427 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 428 | portstr++; |
| 429 | sscanf(portstr, "%d-%d", &tmp[0], &tmp[1]); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 430 | port = htons((tmp[0] << 8) | (tmp[1])); |
| 431 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 432 | switch (da->da_addr.ss_family) { |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 433 | case AF_INET: |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 434 | ((struct sockaddr_in *)&da->da_addr)->sin_port = port; |
| 435 | da->da_addrlen = sizeof(struct sockaddr_in); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 436 | match_netid = "tcp"; |
| 437 | match_netid_len = 3; |
| 438 | break; |
| 439 | |
| 440 | case AF_INET6: |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 441 | ((struct sockaddr_in6 *)&da->da_addr)->sin6_port = port; |
| 442 | da->da_addrlen = sizeof(struct sockaddr_in6); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 443 | match_netid = "tcp6"; |
| 444 | match_netid_len = 4; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 445 | startsep = "["; |
| 446 | endsep = "]"; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 447 | break; |
| 448 | |
| 449 | default: |
| 450 | dprintk("%s: unsupported address family: %u\n", |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 451 | __func__, da->da_addr.ss_family); |
| 452 | goto out_free_da; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | if (nlen != match_netid_len || strncmp(netid, match_netid, nlen)) { |
| 456 | dprintk("%s: ERROR: r_netid \"%s\" != \"%s\"\n", |
| 457 | __func__, netid, match_netid); |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 458 | goto out_free_da; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 459 | } |
| 460 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 461 | /* save human readable address */ |
| 462 | len = strlen(startsep) + strlen(buf) + strlen(endsep) + 7; |
| 463 | da->da_remotestr = kzalloc(len, gfp_flags); |
| 464 | |
| 465 | /* NULL is ok, only used for dprintk */ |
| 466 | if (da->da_remotestr) |
| 467 | snprintf(da->da_remotestr, len, "%s%s%s:%u", startsep, |
| 468 | buf, endsep, ntohs(port)); |
| 469 | |
| 470 | dprintk("%s: Parsed DS addr %s\n", __func__, da->da_remotestr); |
| 471 | kfree(buf); |
| 472 | kfree(netid); |
| 473 | return da; |
| 474 | |
| 475 | out_free_da: |
| 476 | kfree(da); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 477 | out_free_buf: |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 478 | dprintk("%s: Error parsing DS addr: %s\n", __func__, buf); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 479 | kfree(buf); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 480 | out_free_netid: |
| 481 | kfree(netid); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 482 | out_err: |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 483 | return NULL; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /* Decode opaque device data and return the result */ |
Christoph Hellwig | 661373b | 2014-09-02 21:27:57 -0700 | [diff] [blame^] | 487 | struct nfs4_file_layout_dsaddr * |
| 488 | nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, |
| 489 | gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 490 | { |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 491 | int i; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 492 | u32 cnt, num; |
| 493 | u8 *indexp; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 494 | __be32 *p; |
| 495 | u8 *stripe_indices; |
| 496 | u8 max_stripe_index; |
| 497 | struct nfs4_file_layout_dsaddr *dsaddr = NULL; |
| 498 | struct xdr_stream stream; |
Benny Halevy | f7da7a1 | 2011-05-19 14:16:47 -0400 | [diff] [blame] | 499 | struct xdr_buf buf; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 500 | struct page *scratch; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 501 | struct list_head dsaddrs; |
| 502 | struct nfs4_pnfs_ds_addr *da; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 503 | |
| 504 | /* set up xdr stream */ |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 505 | scratch = alloc_page(gfp_flags); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 506 | if (!scratch) |
| 507 | goto out_err; |
| 508 | |
Benny Halevy | f7da7a1 | 2011-05-19 14:16:47 -0400 | [diff] [blame] | 509 | xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 510 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 511 | |
| 512 | /* Get the stripe count (number of stripe index) */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 513 | p = xdr_inline_decode(&stream, 4); |
| 514 | if (unlikely(!p)) |
| 515 | goto out_err_free_scratch; |
| 516 | |
| 517 | cnt = be32_to_cpup(p); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 518 | dprintk("%s stripe count %d\n", __func__, cnt); |
| 519 | if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 520 | printk(KERN_WARNING "NFS: %s: stripe count %d greater than " |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 521 | "supported maximum %d\n", __func__, |
| 522 | cnt, NFS4_PNFS_MAX_STRIPE_CNT); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 523 | goto out_err_free_scratch; |
| 524 | } |
| 525 | |
| 526 | /* read stripe indices */ |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 527 | stripe_indices = kcalloc(cnt, sizeof(u8), gfp_flags); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 528 | if (!stripe_indices) |
| 529 | goto out_err_free_scratch; |
| 530 | |
| 531 | p = xdr_inline_decode(&stream, cnt << 2); |
| 532 | if (unlikely(!p)) |
| 533 | goto out_err_free_stripe_indices; |
| 534 | |
| 535 | indexp = &stripe_indices[0]; |
| 536 | max_stripe_index = 0; |
| 537 | for (i = 0; i < cnt; i++) { |
| 538 | *indexp = be32_to_cpup(p++); |
| 539 | max_stripe_index = max(max_stripe_index, *indexp); |
| 540 | indexp++; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /* Check the multipath list count */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 544 | p = xdr_inline_decode(&stream, 4); |
| 545 | if (unlikely(!p)) |
| 546 | goto out_err_free_stripe_indices; |
| 547 | |
| 548 | num = be32_to_cpup(p); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 549 | dprintk("%s ds_num %u\n", __func__, num); |
| 550 | if (num > NFS4_PNFS_MAX_MULTI_CNT) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 551 | printk(KERN_WARNING "NFS: %s: multipath count %d greater than " |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 552 | "supported maximum %d\n", __func__, |
| 553 | num, NFS4_PNFS_MAX_MULTI_CNT); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 554 | goto out_err_free_stripe_indices; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 555 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 556 | |
| 557 | /* validate stripe indices are all < num */ |
| 558 | if (max_stripe_index >= num) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 559 | printk(KERN_WARNING "NFS: %s: stripe index %u >= num ds %u\n", |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 560 | __func__, max_stripe_index, num); |
| 561 | goto out_err_free_stripe_indices; |
| 562 | } |
| 563 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 564 | dsaddr = kzalloc(sizeof(*dsaddr) + |
| 565 | (sizeof(struct nfs4_pnfs_ds *) * (num - 1)), |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 566 | gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 567 | if (!dsaddr) |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 568 | goto out_err_free_stripe_indices; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 569 | |
| 570 | dsaddr->stripe_count = cnt; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 571 | dsaddr->stripe_indices = stripe_indices; |
| 572 | stripe_indices = NULL; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 573 | dsaddr->ds_num = num; |
Christoph Hellwig | 661373b | 2014-09-02 21:27:57 -0700 | [diff] [blame^] | 574 | nfs4_init_deviceid_node(&dsaddr->id_node, server, &pdev->dev_id); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 575 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 576 | INIT_LIST_HEAD(&dsaddrs); |
| 577 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 578 | for (i = 0; i < dsaddr->ds_num; i++) { |
| 579 | int j; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 580 | u32 mp_count; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 581 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 582 | p = xdr_inline_decode(&stream, 4); |
| 583 | if (unlikely(!p)) |
| 584 | goto out_err_free_deviceid; |
| 585 | |
| 586 | mp_count = be32_to_cpup(p); /* multipath count */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 587 | for (j = 0; j < mp_count; j++) { |
Christoph Hellwig | 661373b | 2014-09-02 21:27:57 -0700 | [diff] [blame^] | 588 | da = decode_ds_addr(server->nfs_client->cl_net, |
Stanislav Kinsbursky | 1709427 | 2012-01-19 19:05:57 +0400 | [diff] [blame] | 589 | &stream, gfp_flags); |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 590 | if (da) |
| 591 | list_add_tail(&da->da_node, &dsaddrs); |
| 592 | } |
| 593 | if (list_empty(&dsaddrs)) { |
| 594 | dprintk("%s: no suitable DS addresses found\n", |
| 595 | __func__); |
| 596 | goto out_err_free_deviceid; |
| 597 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 598 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 599 | dsaddr->ds_list[i] = nfs4_pnfs_ds_add(&dsaddrs, gfp_flags); |
| 600 | if (!dsaddr->ds_list[i]) |
| 601 | goto out_err_drain_dsaddrs; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 602 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 603 | /* If DS was already in cache, free ds addrs */ |
| 604 | while (!list_empty(&dsaddrs)) { |
| 605 | da = list_first_entry(&dsaddrs, |
| 606 | struct nfs4_pnfs_ds_addr, |
| 607 | da_node); |
| 608 | list_del_init(&da->da_node); |
| 609 | kfree(da->da_remotestr); |
| 610 | kfree(da); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 611 | } |
| 612 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 613 | |
| 614 | __free_page(scratch); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 615 | return dsaddr; |
| 616 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 617 | out_err_drain_dsaddrs: |
| 618 | while (!list_empty(&dsaddrs)) { |
| 619 | da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr, |
| 620 | da_node); |
| 621 | list_del_init(&da->da_node); |
| 622 | kfree(da->da_remotestr); |
| 623 | kfree(da); |
| 624 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 625 | out_err_free_deviceid: |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 626 | nfs4_fl_free_deviceid(dsaddr); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 627 | /* stripe_indicies was part of dsaddr */ |
| 628 | goto out_err_free_scratch; |
| 629 | out_err_free_stripe_indices: |
| 630 | kfree(stripe_indices); |
| 631 | out_err_free_scratch: |
| 632 | __free_page(scratch); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 633 | out_err: |
| 634 | dprintk("%s ERROR: returning NULL\n", __func__); |
| 635 | return NULL; |
| 636 | } |
| 637 | |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 638 | void |
| 639 | nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 640 | { |
Benny Halevy | 1775bc3 | 2011-05-20 13:47:33 +0200 | [diff] [blame] | 641 | nfs4_put_deviceid_node(&dsaddr->id_node); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 642 | } |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 643 | |
| 644 | /* |
| 645 | * Want res = (offset - layout->pattern_offset)/ layout->stripe_unit |
| 646 | * Then: ((res + fsi) % dsaddr->stripe_count) |
| 647 | */ |
| 648 | u32 |
| 649 | nfs4_fl_calc_j_index(struct pnfs_layout_segment *lseg, loff_t offset) |
| 650 | { |
| 651 | struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); |
| 652 | u64 tmp; |
| 653 | |
| 654 | tmp = offset - flseg->pattern_offset; |
| 655 | do_div(tmp, flseg->stripe_unit); |
| 656 | tmp += flseg->first_stripe_index; |
| 657 | return do_div(tmp, flseg->dsaddr->stripe_count); |
| 658 | } |
| 659 | |
| 660 | u32 |
| 661 | nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j) |
| 662 | { |
| 663 | return FILELAYOUT_LSEG(lseg)->dsaddr->stripe_indices[j]; |
| 664 | } |
| 665 | |
| 666 | struct nfs_fh * |
| 667 | nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j) |
| 668 | { |
| 669 | struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); |
| 670 | u32 i; |
| 671 | |
| 672 | if (flseg->stripe_type == STRIPE_SPARSE) { |
| 673 | if (flseg->num_fh == 1) |
| 674 | i = 0; |
| 675 | else if (flseg->num_fh == 0) |
| 676 | /* Use the MDS OPEN fh set in nfs_read_rpcsetup */ |
| 677 | return NULL; |
| 678 | else |
| 679 | i = nfs4_fl_calc_ds_index(lseg, j); |
| 680 | } else |
| 681 | i = j; |
| 682 | return flseg->fh_array[i]; |
| 683 | } |
| 684 | |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 685 | static void nfs4_wait_ds_connect(struct nfs4_pnfs_ds *ds) |
| 686 | { |
| 687 | might_sleep(); |
NeilBrown | 7431620 | 2014-07-07 15:16:04 +1000 | [diff] [blame] | 688 | wait_on_bit_action(&ds->ds_state, NFS4DS_CONNECTING, |
| 689 | nfs_wait_bit_killable, TASK_KILLABLE); |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds *ds) |
| 693 | { |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 694 | smp_mb__before_atomic(); |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 695 | clear_bit(NFS4DS_CONNECTING, &ds->ds_state); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 696 | smp_mb__after_atomic(); |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 697 | wake_up_bit(&ds->ds_state, NFS4DS_CONNECTING); |
| 698 | } |
| 699 | |
| 700 | |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 701 | struct nfs4_pnfs_ds * |
| 702 | nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx) |
| 703 | { |
| 704 | struct nfs4_file_layout_dsaddr *dsaddr = FILELAYOUT_LSEG(lseg)->dsaddr; |
| 705 | struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx]; |
Andy Adamson | 554d458 | 2012-04-27 17:53:42 -0400 | [diff] [blame] | 706 | struct nfs4_deviceid_node *devid = FILELAYOUT_DEVID_NODE(lseg); |
Trond Myklebust | 52b26a3 | 2013-09-26 14:08:36 -0400 | [diff] [blame] | 707 | struct nfs4_pnfs_ds *ret = ds; |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 708 | |
| 709 | if (ds == NULL) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 710 | printk(KERN_ERR "NFS: %s: No data server for offset index %d\n", |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 711 | __func__, ds_idx); |
Trond Myklebust | 1dfed27 | 2012-09-18 19:51:12 -0400 | [diff] [blame] | 712 | filelayout_mark_devid_invalid(devid); |
Trond Myklebust | 52b26a3 | 2013-09-26 14:08:36 -0400 | [diff] [blame] | 713 | goto out; |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 714 | } |
Trond Myklebust | acd65e5 | 2013-09-26 14:32:56 -0400 | [diff] [blame] | 715 | smp_rmb(); |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 716 | if (ds->ds_clp) |
Trond Myklebust | 52b26a3 | 2013-09-26 14:08:36 -0400 | [diff] [blame] | 717 | goto out_test_devid; |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 718 | |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 719 | if (test_and_set_bit(NFS4DS_CONNECTING, &ds->ds_state) == 0) { |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 720 | struct nfs_server *s = NFS_SERVER(lseg->pls_layout->plh_inode); |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 721 | int err; |
| 722 | |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 723 | err = nfs4_ds_connect(s, ds); |
Trond Myklebust | 52b26a3 | 2013-09-26 14:08:36 -0400 | [diff] [blame] | 724 | if (err) |
Trond Myklebust | 1dfed27 | 2012-09-18 19:51:12 -0400 | [diff] [blame] | 725 | nfs4_mark_deviceid_unavailable(devid); |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 726 | nfs4_clear_ds_conn_bit(ds); |
| 727 | } else { |
| 728 | /* Either ds is connected, or ds is NULL */ |
| 729 | nfs4_wait_ds_connect(ds); |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 730 | } |
Trond Myklebust | 52b26a3 | 2013-09-26 14:08:36 -0400 | [diff] [blame] | 731 | out_test_devid: |
| 732 | if (filelayout_test_devid_unavailable(devid)) |
| 733 | ret = NULL; |
| 734 | out: |
| 735 | return ret; |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 736 | } |
Andy Adamson | 98fc685 | 2012-04-27 17:53:45 -0400 | [diff] [blame] | 737 | |
| 738 | module_param(dataserver_retrans, uint, 0644); |
| 739 | MODULE_PARM_DESC(dataserver_retrans, "The number of times the NFSv4.1 client " |
| 740 | "retries a request before it attempts further " |
| 741 | " recovery action."); |
| 742 | module_param(dataserver_timeo, uint, 0644); |
| 743 | MODULE_PARM_DESC(dataserver_timeo, "The time (in tenths of a second) the " |
| 744 | "NFSv4.1 client waits for a response from a " |
| 745 | " data server before it retries an NFS request."); |