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 | /* |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 46 | * Create an rpc connection to the nfs4_pnfs_ds data server |
Weston Andros Adamson | 35dbbc9 | 2011-06-01 16:32:21 -0400 | [diff] [blame] | 47 | * Currently only supports IPv4 and IPv6 addresses |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 48 | */ |
| 49 | static int |
| 50 | nfs4_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds) |
| 51 | { |
Weston Andros Adamson | 7e574f0 | 2011-05-31 18:48:58 -0400 | [diff] [blame] | 52 | struct nfs_client *clp = ERR_PTR(-EIO); |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 53 | struct nfs4_pnfs_ds_addr *da; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 54 | int status = 0; |
| 55 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 56 | dprintk("--> %s DS %s au_flavor %d\n", __func__, ds->ds_remotestr, |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 57 | mds_srv->nfs_client->cl_rpcclient->cl_auth->au_flavor); |
| 58 | |
Weston Andros Adamson | 7e574f0 | 2011-05-31 18:48:58 -0400 | [diff] [blame] | 59 | list_for_each_entry(da, &ds->ds_addrs, da_node) { |
| 60 | dprintk("%s: DS %s: trying address %s\n", |
| 61 | __func__, ds->ds_remotestr, da->da_remotestr); |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 62 | |
Weston Andros Adamson | 7e574f0 | 2011-05-31 18:48:58 -0400 | [diff] [blame] | 63 | clp = nfs4_set_ds_client(mds_srv->nfs_client, |
Andy Adamson | 98fc685 | 2012-04-27 17:53:45 -0400 | [diff] [blame] | 64 | (struct sockaddr *)&da->da_addr, |
| 65 | da->da_addrlen, IPPROTO_TCP, |
| 66 | dataserver_timeo, dataserver_retrans); |
Weston Andros Adamson | 7e574f0 | 2011-05-31 18:48:58 -0400 | [diff] [blame] | 67 | if (!IS_ERR(clp)) |
| 68 | break; |
| 69 | } |
| 70 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 71 | if (IS_ERR(clp)) { |
| 72 | status = PTR_ERR(clp); |
| 73 | goto out; |
| 74 | } |
| 75 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 76 | 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] | 77 | if (status) |
| 78 | goto out_put; |
| 79 | |
Trond Myklebust | acd65e5 | 2013-09-26 14:32:56 -0400 | [diff] [blame] | 80 | smp_wmb(); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 81 | ds->ds_clp = clp; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 82 | dprintk("%s [new] addr: %s\n", __func__, ds->ds_remotestr); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 83 | out: |
| 84 | return status; |
| 85 | out_put: |
| 86 | nfs_put_client(clp); |
| 87 | goto out; |
| 88 | } |
| 89 | |
Benny Halevy | 1775bc3 | 2011-05-20 13:47:33 +0200 | [diff] [blame] | 90 | void |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 91 | nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr) |
| 92 | { |
| 93 | struct nfs4_pnfs_ds *ds; |
| 94 | int i; |
| 95 | |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 96 | nfs4_print_deviceid(&dsaddr->id_node.deviceid); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 97 | |
| 98 | for (i = 0; i < dsaddr->ds_num; i++) { |
| 99 | ds = dsaddr->ds_list[i]; |
Peng Tao | 875ae06 | 2014-05-29 21:06:57 +0800 | [diff] [blame^] | 100 | if (ds != NULL) |
| 101 | nfs4_pnfs_ds_put(ds); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 102 | } |
| 103 | kfree(dsaddr->stripe_indices); |
| 104 | kfree(dsaddr); |
| 105 | } |
| 106 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 107 | /* |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 108 | * Currently only supports ipv4, ipv6 and one multi-path address. |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 109 | */ |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 110 | static struct nfs4_pnfs_ds_addr * |
Stanislav Kinsbursky | 1709427 | 2012-01-19 19:05:57 +0400 | [diff] [blame] | 111 | 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] | 112 | { |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 113 | struct nfs4_pnfs_ds_addr *da = NULL; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 114 | char *buf, *portstr; |
Dan Carpenter | 13fff2f | 2012-01-12 10:07:35 +0300 | [diff] [blame] | 115 | __be16 port; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 116 | int nlen, rlen; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 117 | int tmp[2]; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 118 | __be32 *p; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 119 | char *netid, *match_netid; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 120 | size_t len, match_netid_len; |
| 121 | char *startsep = ""; |
| 122 | char *endsep = ""; |
| 123 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 124 | |
| 125 | /* r_netid */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 126 | p = xdr_inline_decode(streamp, 4); |
| 127 | if (unlikely(!p)) |
| 128 | goto out_err; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 129 | nlen = be32_to_cpup(p++); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 130 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 131 | p = xdr_inline_decode(streamp, nlen); |
| 132 | if (unlikely(!p)) |
| 133 | goto out_err; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 134 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 135 | netid = kmalloc(nlen+1, gfp_flags); |
| 136 | if (unlikely(!netid)) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 137 | goto out_err; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 138 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 139 | netid[nlen] = '\0'; |
| 140 | memcpy(netid, p, nlen); |
| 141 | |
| 142 | /* 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] | 143 | p = xdr_inline_decode(streamp, 4); |
| 144 | if (unlikely(!p)) |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 145 | goto out_free_netid; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 146 | rlen = be32_to_cpup(p); |
| 147 | |
| 148 | p = xdr_inline_decode(streamp, rlen); |
| 149 | if (unlikely(!p)) |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 150 | goto out_free_netid; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 151 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 152 | /* port is ".ABC.DEF", 8 chars max */ |
| 153 | if (rlen > INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN + 8) { |
Jesper Juhl | ad3d2ee | 2011-01-17 18:41:50 +0000 | [diff] [blame] | 154 | dprintk("%s: Invalid address, length %d\n", __func__, |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 155 | rlen); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 156 | goto out_free_netid; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 157 | } |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 158 | buf = kmalloc(rlen + 1, gfp_flags); |
Stanislav Fomichev | b9f8105 | 2011-02-05 23:13:01 +0000 | [diff] [blame] | 159 | if (!buf) { |
| 160 | dprintk("%s: Not enough memory\n", __func__); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 161 | goto out_free_netid; |
Stanislav Fomichev | b9f8105 | 2011-02-05 23:13:01 +0000 | [diff] [blame] | 162 | } |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 163 | buf[rlen] = '\0'; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 164 | memcpy(buf, p, rlen); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 165 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 166 | /* replace port '.' with '-' */ |
| 167 | portstr = strrchr(buf, '.'); |
| 168 | if (!portstr) { |
| 169 | dprintk("%s: Failed finding expected dot in port\n", |
| 170 | __func__); |
| 171 | goto out_free_buf; |
| 172 | } |
| 173 | *portstr = '-'; |
| 174 | |
| 175 | /* find '.' between address and port */ |
| 176 | portstr = strrchr(buf, '.'); |
| 177 | if (!portstr) { |
| 178 | dprintk("%s: Failed finding expected dot between address and " |
| 179 | "port\n", __func__); |
| 180 | goto out_free_buf; |
| 181 | } |
| 182 | *portstr = '\0'; |
| 183 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 184 | da = kzalloc(sizeof(*da), gfp_flags); |
| 185 | if (unlikely(!da)) |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 186 | goto out_free_buf; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 187 | |
| 188 | INIT_LIST_HEAD(&da->da_node); |
| 189 | |
Stanislav Kinsbursky | 1709427 | 2012-01-19 19:05:57 +0400 | [diff] [blame] | 190 | 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] | 191 | sizeof(da->da_addr))) { |
| 192 | dprintk("%s: error parsing address %s\n", __func__, buf); |
| 193 | goto out_free_da; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 194 | } |
| 195 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 196 | portstr++; |
| 197 | sscanf(portstr, "%d-%d", &tmp[0], &tmp[1]); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 198 | port = htons((tmp[0] << 8) | (tmp[1])); |
| 199 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 200 | switch (da->da_addr.ss_family) { |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 201 | case AF_INET: |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 202 | ((struct sockaddr_in *)&da->da_addr)->sin_port = port; |
| 203 | da->da_addrlen = sizeof(struct sockaddr_in); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 204 | match_netid = "tcp"; |
| 205 | match_netid_len = 3; |
| 206 | break; |
| 207 | |
| 208 | case AF_INET6: |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 209 | ((struct sockaddr_in6 *)&da->da_addr)->sin6_port = port; |
| 210 | da->da_addrlen = sizeof(struct sockaddr_in6); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 211 | match_netid = "tcp6"; |
| 212 | match_netid_len = 4; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 213 | startsep = "["; |
| 214 | endsep = "]"; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 215 | break; |
| 216 | |
| 217 | default: |
| 218 | dprintk("%s: unsupported address family: %u\n", |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 219 | __func__, da->da_addr.ss_family); |
| 220 | goto out_free_da; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | if (nlen != match_netid_len || strncmp(netid, match_netid, nlen)) { |
| 224 | dprintk("%s: ERROR: r_netid \"%s\" != \"%s\"\n", |
| 225 | __func__, netid, match_netid); |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 226 | goto out_free_da; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 227 | } |
| 228 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 229 | /* save human readable address */ |
| 230 | len = strlen(startsep) + strlen(buf) + strlen(endsep) + 7; |
| 231 | da->da_remotestr = kzalloc(len, gfp_flags); |
| 232 | |
| 233 | /* NULL is ok, only used for dprintk */ |
| 234 | if (da->da_remotestr) |
| 235 | snprintf(da->da_remotestr, len, "%s%s%s:%u", startsep, |
| 236 | buf, endsep, ntohs(port)); |
| 237 | |
| 238 | dprintk("%s: Parsed DS addr %s\n", __func__, da->da_remotestr); |
| 239 | kfree(buf); |
| 240 | kfree(netid); |
| 241 | return da; |
| 242 | |
| 243 | out_free_da: |
| 244 | kfree(da); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 245 | out_free_buf: |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 246 | dprintk("%s: Error parsing DS addr: %s\n", __func__, buf); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 247 | kfree(buf); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame] | 248 | out_free_netid: |
| 249 | kfree(netid); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 250 | out_err: |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 251 | return NULL; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* Decode opaque device data and return the result */ |
Christoph Hellwig | 661373b | 2014-09-02 21:27:57 -0700 | [diff] [blame] | 255 | struct nfs4_file_layout_dsaddr * |
| 256 | nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev, |
| 257 | gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 258 | { |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 259 | int i; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 260 | u32 cnt, num; |
| 261 | u8 *indexp; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 262 | __be32 *p; |
| 263 | u8 *stripe_indices; |
| 264 | u8 max_stripe_index; |
| 265 | struct nfs4_file_layout_dsaddr *dsaddr = NULL; |
| 266 | struct xdr_stream stream; |
Benny Halevy | f7da7a1 | 2011-05-19 14:16:47 -0400 | [diff] [blame] | 267 | struct xdr_buf buf; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 268 | struct page *scratch; |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 269 | struct list_head dsaddrs; |
| 270 | struct nfs4_pnfs_ds_addr *da; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 271 | |
| 272 | /* set up xdr stream */ |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 273 | scratch = alloc_page(gfp_flags); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 274 | if (!scratch) |
| 275 | goto out_err; |
| 276 | |
Benny Halevy | f7da7a1 | 2011-05-19 14:16:47 -0400 | [diff] [blame] | 277 | xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 278 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 279 | |
| 280 | /* Get the stripe count (number of stripe index) */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 281 | p = xdr_inline_decode(&stream, 4); |
| 282 | if (unlikely(!p)) |
| 283 | goto out_err_free_scratch; |
| 284 | |
| 285 | cnt = be32_to_cpup(p); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 286 | dprintk("%s stripe count %d\n", __func__, cnt); |
| 287 | if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 288 | printk(KERN_WARNING "NFS: %s: stripe count %d greater than " |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 289 | "supported maximum %d\n", __func__, |
| 290 | cnt, NFS4_PNFS_MAX_STRIPE_CNT); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 291 | goto out_err_free_scratch; |
| 292 | } |
| 293 | |
| 294 | /* read stripe indices */ |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 295 | stripe_indices = kcalloc(cnt, sizeof(u8), gfp_flags); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 296 | if (!stripe_indices) |
| 297 | goto out_err_free_scratch; |
| 298 | |
| 299 | p = xdr_inline_decode(&stream, cnt << 2); |
| 300 | if (unlikely(!p)) |
| 301 | goto out_err_free_stripe_indices; |
| 302 | |
| 303 | indexp = &stripe_indices[0]; |
| 304 | max_stripe_index = 0; |
| 305 | for (i = 0; i < cnt; i++) { |
| 306 | *indexp = be32_to_cpup(p++); |
| 307 | max_stripe_index = max(max_stripe_index, *indexp); |
| 308 | indexp++; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | /* Check the multipath list count */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 312 | p = xdr_inline_decode(&stream, 4); |
| 313 | if (unlikely(!p)) |
| 314 | goto out_err_free_stripe_indices; |
| 315 | |
| 316 | num = be32_to_cpup(p); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 317 | dprintk("%s ds_num %u\n", __func__, num); |
| 318 | if (num > NFS4_PNFS_MAX_MULTI_CNT) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 319 | printk(KERN_WARNING "NFS: %s: multipath count %d greater than " |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 320 | "supported maximum %d\n", __func__, |
| 321 | num, NFS4_PNFS_MAX_MULTI_CNT); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 322 | goto out_err_free_stripe_indices; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 323 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 324 | |
| 325 | /* validate stripe indices are all < num */ |
| 326 | if (max_stripe_index >= num) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 327 | 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] | 328 | __func__, max_stripe_index, num); |
| 329 | goto out_err_free_stripe_indices; |
| 330 | } |
| 331 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 332 | dsaddr = kzalloc(sizeof(*dsaddr) + |
| 333 | (sizeof(struct nfs4_pnfs_ds *) * (num - 1)), |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 334 | gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 335 | if (!dsaddr) |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 336 | goto out_err_free_stripe_indices; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 337 | |
| 338 | dsaddr->stripe_count = cnt; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 339 | dsaddr->stripe_indices = stripe_indices; |
| 340 | stripe_indices = NULL; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 341 | dsaddr->ds_num = num; |
Christoph Hellwig | 661373b | 2014-09-02 21:27:57 -0700 | [diff] [blame] | 342 | nfs4_init_deviceid_node(&dsaddr->id_node, server, &pdev->dev_id); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 343 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 344 | INIT_LIST_HEAD(&dsaddrs); |
| 345 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 346 | for (i = 0; i < dsaddr->ds_num; i++) { |
| 347 | int j; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 348 | u32 mp_count; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 349 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 350 | p = xdr_inline_decode(&stream, 4); |
| 351 | if (unlikely(!p)) |
| 352 | goto out_err_free_deviceid; |
| 353 | |
| 354 | mp_count = be32_to_cpup(p); /* multipath count */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 355 | for (j = 0; j < mp_count; j++) { |
Christoph Hellwig | 661373b | 2014-09-02 21:27:57 -0700 | [diff] [blame] | 356 | da = decode_ds_addr(server->nfs_client->cl_net, |
Stanislav Kinsbursky | 1709427 | 2012-01-19 19:05:57 +0400 | [diff] [blame] | 357 | &stream, gfp_flags); |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 358 | if (da) |
| 359 | list_add_tail(&da->da_node, &dsaddrs); |
| 360 | } |
| 361 | if (list_empty(&dsaddrs)) { |
| 362 | dprintk("%s: no suitable DS addresses found\n", |
| 363 | __func__); |
| 364 | goto out_err_free_deviceid; |
| 365 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 366 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 367 | dsaddr->ds_list[i] = nfs4_pnfs_ds_add(&dsaddrs, gfp_flags); |
| 368 | if (!dsaddr->ds_list[i]) |
| 369 | goto out_err_drain_dsaddrs; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 370 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 371 | /* If DS was already in cache, free ds addrs */ |
| 372 | while (!list_empty(&dsaddrs)) { |
| 373 | da = list_first_entry(&dsaddrs, |
| 374 | struct nfs4_pnfs_ds_addr, |
| 375 | da_node); |
| 376 | list_del_init(&da->da_node); |
| 377 | kfree(da->da_remotestr); |
| 378 | kfree(da); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 379 | } |
| 380 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 381 | |
| 382 | __free_page(scratch); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 383 | return dsaddr; |
| 384 | |
Weston Andros Adamson | 14f9a60 | 2011-05-31 18:48:57 -0400 | [diff] [blame] | 385 | out_err_drain_dsaddrs: |
| 386 | while (!list_empty(&dsaddrs)) { |
| 387 | da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr, |
| 388 | da_node); |
| 389 | list_del_init(&da->da_node); |
| 390 | kfree(da->da_remotestr); |
| 391 | kfree(da); |
| 392 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 393 | out_err_free_deviceid: |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 394 | nfs4_fl_free_deviceid(dsaddr); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 395 | /* stripe_indicies was part of dsaddr */ |
| 396 | goto out_err_free_scratch; |
| 397 | out_err_free_stripe_indices: |
| 398 | kfree(stripe_indices); |
| 399 | out_err_free_scratch: |
| 400 | __free_page(scratch); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 401 | out_err: |
| 402 | dprintk("%s ERROR: returning NULL\n", __func__); |
| 403 | return NULL; |
| 404 | } |
| 405 | |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 406 | void |
| 407 | nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 408 | { |
Benny Halevy | 1775bc3 | 2011-05-20 13:47:33 +0200 | [diff] [blame] | 409 | nfs4_put_deviceid_node(&dsaddr->id_node); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 410 | } |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 411 | |
| 412 | /* |
| 413 | * Want res = (offset - layout->pattern_offset)/ layout->stripe_unit |
| 414 | * Then: ((res + fsi) % dsaddr->stripe_count) |
| 415 | */ |
| 416 | u32 |
| 417 | nfs4_fl_calc_j_index(struct pnfs_layout_segment *lseg, loff_t offset) |
| 418 | { |
| 419 | struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); |
| 420 | u64 tmp; |
| 421 | |
| 422 | tmp = offset - flseg->pattern_offset; |
| 423 | do_div(tmp, flseg->stripe_unit); |
| 424 | tmp += flseg->first_stripe_index; |
| 425 | return do_div(tmp, flseg->dsaddr->stripe_count); |
| 426 | } |
| 427 | |
| 428 | u32 |
| 429 | nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j) |
| 430 | { |
| 431 | return FILELAYOUT_LSEG(lseg)->dsaddr->stripe_indices[j]; |
| 432 | } |
| 433 | |
| 434 | struct nfs_fh * |
| 435 | nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j) |
| 436 | { |
| 437 | struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); |
| 438 | u32 i; |
| 439 | |
| 440 | if (flseg->stripe_type == STRIPE_SPARSE) { |
| 441 | if (flseg->num_fh == 1) |
| 442 | i = 0; |
| 443 | else if (flseg->num_fh == 0) |
| 444 | /* Use the MDS OPEN fh set in nfs_read_rpcsetup */ |
| 445 | return NULL; |
| 446 | else |
| 447 | i = nfs4_fl_calc_ds_index(lseg, j); |
| 448 | } else |
| 449 | i = j; |
| 450 | return flseg->fh_array[i]; |
| 451 | } |
| 452 | |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 453 | static void nfs4_wait_ds_connect(struct nfs4_pnfs_ds *ds) |
| 454 | { |
| 455 | might_sleep(); |
NeilBrown | 7431620 | 2014-07-07 15:16:04 +1000 | [diff] [blame] | 456 | wait_on_bit_action(&ds->ds_state, NFS4DS_CONNECTING, |
| 457 | nfs_wait_bit_killable, TASK_KILLABLE); |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds *ds) |
| 461 | { |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 462 | smp_mb__before_atomic(); |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 463 | clear_bit(NFS4DS_CONNECTING, &ds->ds_state); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 464 | smp_mb__after_atomic(); |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 465 | wake_up_bit(&ds->ds_state, NFS4DS_CONNECTING); |
| 466 | } |
| 467 | |
| 468 | |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 469 | struct nfs4_pnfs_ds * |
| 470 | nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx) |
| 471 | { |
| 472 | struct nfs4_file_layout_dsaddr *dsaddr = FILELAYOUT_LSEG(lseg)->dsaddr; |
| 473 | struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx]; |
Andy Adamson | 554d458 | 2012-04-27 17:53:42 -0400 | [diff] [blame] | 474 | struct nfs4_deviceid_node *devid = FILELAYOUT_DEVID_NODE(lseg); |
Trond Myklebust | 52b26a3 | 2013-09-26 14:08:36 -0400 | [diff] [blame] | 475 | struct nfs4_pnfs_ds *ret = ds; |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 476 | |
| 477 | if (ds == NULL) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 478 | 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] | 479 | __func__, ds_idx); |
Tom Haynes | f54bcf2 | 2014-12-11 15:34:59 -0500 | [diff] [blame] | 480 | pnfs_generic_mark_devid_invalid(devid); |
Trond Myklebust | 52b26a3 | 2013-09-26 14:08:36 -0400 | [diff] [blame] | 481 | goto out; |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 482 | } |
Trond Myklebust | acd65e5 | 2013-09-26 14:32:56 -0400 | [diff] [blame] | 483 | smp_rmb(); |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 484 | if (ds->ds_clp) |
Trond Myklebust | 52b26a3 | 2013-09-26 14:08:36 -0400 | [diff] [blame] | 485 | goto out_test_devid; |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 486 | |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 487 | if (test_and_set_bit(NFS4DS_CONNECTING, &ds->ds_state) == 0) { |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 488 | struct nfs_server *s = NFS_SERVER(lseg->pls_layout->plh_inode); |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 489 | int err; |
| 490 | |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 491 | err = nfs4_ds_connect(s, ds); |
Trond Myklebust | 52b26a3 | 2013-09-26 14:08:36 -0400 | [diff] [blame] | 492 | if (err) |
Trond Myklebust | 1dfed27 | 2012-09-18 19:51:12 -0400 | [diff] [blame] | 493 | nfs4_mark_deviceid_unavailable(devid); |
Andy Adamson | c23266d | 2013-05-08 16:21:18 -0400 | [diff] [blame] | 494 | nfs4_clear_ds_conn_bit(ds); |
| 495 | } else { |
| 496 | /* Either ds is connected, or ds is NULL */ |
| 497 | nfs4_wait_ds_connect(ds); |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 498 | } |
Trond Myklebust | 52b26a3 | 2013-09-26 14:08:36 -0400 | [diff] [blame] | 499 | out_test_devid: |
| 500 | if (filelayout_test_devid_unavailable(devid)) |
| 501 | ret = NULL; |
| 502 | out: |
| 503 | return ret; |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 504 | } |
Andy Adamson | 98fc685 | 2012-04-27 17:53:45 -0400 | [diff] [blame] | 505 | |
| 506 | module_param(dataserver_retrans, uint, 0644); |
| 507 | MODULE_PARM_DESC(dataserver_retrans, "The number of times the NFSv4.1 client " |
| 508 | "retries a request before it attempts further " |
| 509 | " recovery action."); |
| 510 | module_param(dataserver_timeo, uint, 0644); |
| 511 | MODULE_PARM_DESC(dataserver_timeo, "The time (in tenths of a second) the " |
| 512 | "NFSv4.1 client waits for a response from a " |
| 513 | " data server before it retries an NFS request."); |