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> |
| 33 | |
| 34 | #include "internal.h" |
| 35 | #include "nfs4filelayout.h" |
| 36 | |
| 37 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD |
| 38 | |
| 39 | /* |
| 40 | * Data server cache |
| 41 | * |
| 42 | * Data servers can be mapped to different device ids. |
| 43 | * nfs4_pnfs_ds reference counting |
| 44 | * - set to 1 on allocation |
| 45 | * - incremented when a device id maps a data server already in the cache. |
| 46 | * - decremented when deviceid is removed from the cache. |
| 47 | */ |
| 48 | DEFINE_SPINLOCK(nfs4_ds_cache_lock); |
| 49 | static LIST_HEAD(nfs4_data_server_cache); |
| 50 | |
| 51 | /* Debug routines */ |
| 52 | void |
| 53 | print_ds(struct nfs4_pnfs_ds *ds) |
| 54 | { |
| 55 | if (ds == NULL) { |
| 56 | printk("%s NULL device\n", __func__); |
| 57 | return; |
| 58 | } |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 59 | printk(" ds %s\n" |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 60 | " ref count %d\n" |
| 61 | " client %p\n" |
| 62 | " cl_exchange_flags %x\n", |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 63 | ds->ds_remotestr, |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 64 | atomic_read(&ds->ds_count), ds->ds_clp, |
| 65 | ds->ds_clp ? ds->ds_clp->cl_exchange_flags : 0); |
| 66 | } |
| 67 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 68 | /* nfs4_ds_cache_lock is held */ |
| 69 | static struct nfs4_pnfs_ds * |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 70 | _data_server_lookup_locked(struct sockaddr *addr, size_t addrlen) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 71 | { |
| 72 | struct nfs4_pnfs_ds *ds; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 73 | struct sockaddr_in *a, *b; |
| 74 | struct sockaddr_in6 *a6, *b6; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 75 | |
| 76 | list_for_each_entry(ds, &nfs4_data_server_cache, ds_node) { |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 77 | if (addr->sa_family != ds->ds_addr.ss_family) |
| 78 | continue; |
| 79 | |
| 80 | switch (addr->sa_family) { |
| 81 | case AF_INET: |
| 82 | a = (struct sockaddr_in *)addr; |
| 83 | b = (struct sockaddr_in *)&ds->ds_addr; |
| 84 | |
| 85 | if (a->sin_addr.s_addr == b->sin_addr.s_addr && |
| 86 | a->sin_port == b->sin_port) |
| 87 | return ds; |
| 88 | break; |
| 89 | |
| 90 | case AF_INET6: |
| 91 | a6 = (struct sockaddr_in6 *)addr; |
| 92 | b6 = (struct sockaddr_in6 *)&ds->ds_addr; |
| 93 | |
| 94 | /* LINKLOCAL addresses must have matching scope_id */ |
| 95 | if (ipv6_addr_scope(&a6->sin6_addr) == |
| 96 | IPV6_ADDR_SCOPE_LINKLOCAL && |
| 97 | a6->sin6_scope_id != b6->sin6_scope_id) |
| 98 | continue; |
| 99 | |
| 100 | if (ipv6_addr_equal(&a6->sin6_addr, &b6->sin6_addr) && |
| 101 | a6->sin6_port == b6->sin6_port) |
| 102 | return ds; |
| 103 | break; |
| 104 | |
| 105 | default: |
| 106 | dprintk("%s: unhandled address family: %u\n", |
| 107 | __func__, addr->sa_family); |
| 108 | return NULL; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | return NULL; |
| 112 | } |
| 113 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 114 | /* |
| 115 | * Create an rpc connection to the nfs4_pnfs_ds data server |
| 116 | * Currently only support IPv4 |
| 117 | */ |
| 118 | static int |
| 119 | nfs4_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds) |
| 120 | { |
| 121 | struct nfs_client *clp; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 122 | int status = 0; |
| 123 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 124 | dprintk("--> %s addr %s au_flavor %d\n", __func__, ds->ds_remotestr, |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 125 | mds_srv->nfs_client->cl_rpcclient->cl_auth->au_flavor); |
| 126 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 127 | clp = nfs4_set_ds_client(mds_srv->nfs_client, |
| 128 | (struct sockaddr *)&ds->ds_addr, |
| 129 | ds->ds_addrlen, IPPROTO_TCP); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 130 | if (IS_ERR(clp)) { |
| 131 | status = PTR_ERR(clp); |
| 132 | goto out; |
| 133 | } |
| 134 | |
| 135 | if ((clp->cl_exchange_flags & EXCHGID4_FLAG_MASK_PNFS) != 0) { |
| 136 | if (!is_ds_client(clp)) { |
| 137 | status = -ENODEV; |
| 138 | goto out_put; |
| 139 | } |
| 140 | ds->ds_clp = clp; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 141 | dprintk("%s [existing] server=%s\n", __func__, |
| 142 | ds->ds_remotestr); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 143 | goto out; |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Do not set NFS_CS_CHECK_LEASE_TIME instead set the DS lease to |
| 148 | * be equal to the MDS lease. Renewal is scheduled in create_session. |
| 149 | */ |
| 150 | spin_lock(&mds_srv->nfs_client->cl_lock); |
| 151 | clp->cl_lease_time = mds_srv->nfs_client->cl_lease_time; |
| 152 | spin_unlock(&mds_srv->nfs_client->cl_lock); |
| 153 | clp->cl_last_renewal = jiffies; |
| 154 | |
| 155 | /* New nfs_client */ |
| 156 | status = nfs4_init_ds_session(clp); |
| 157 | if (status) |
| 158 | goto out_put; |
| 159 | |
| 160 | ds->ds_clp = clp; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 161 | dprintk("%s [new] addr: %s\n", __func__, ds->ds_remotestr); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 162 | out: |
| 163 | return status; |
| 164 | out_put: |
| 165 | nfs_put_client(clp); |
| 166 | goto out; |
| 167 | } |
| 168 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 169 | static void |
| 170 | destroy_ds(struct nfs4_pnfs_ds *ds) |
| 171 | { |
| 172 | dprintk("--> %s\n", __func__); |
| 173 | ifdebug(FACILITY) |
| 174 | print_ds(ds); |
| 175 | |
| 176 | if (ds->ds_clp) |
| 177 | nfs_put_client(ds->ds_clp); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 178 | kfree(ds->ds_remotestr); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 179 | kfree(ds); |
| 180 | } |
| 181 | |
Benny Halevy | 1775bc3 | 2011-05-20 13:47:33 +0200 | [diff] [blame] | 182 | void |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 183 | nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr) |
| 184 | { |
| 185 | struct nfs4_pnfs_ds *ds; |
| 186 | int i; |
| 187 | |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 188 | nfs4_print_deviceid(&dsaddr->id_node.deviceid); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 189 | |
| 190 | for (i = 0; i < dsaddr->ds_num; i++) { |
| 191 | ds = dsaddr->ds_list[i]; |
| 192 | if (ds != NULL) { |
| 193 | if (atomic_dec_and_lock(&ds->ds_count, |
| 194 | &nfs4_ds_cache_lock)) { |
| 195 | list_del_init(&ds->ds_node); |
| 196 | spin_unlock(&nfs4_ds_cache_lock); |
| 197 | destroy_ds(ds); |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | kfree(dsaddr->stripe_indices); |
| 202 | kfree(dsaddr); |
| 203 | } |
| 204 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 205 | /* |
| 206 | * Create a string with a human readable address and port to avoid |
| 207 | * complicated setup around many dprinks. |
| 208 | */ |
| 209 | static char * |
| 210 | nfs4_pnfs_remotestr(struct sockaddr *ds_addr, gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 211 | { |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 212 | char buf[INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN]; |
| 213 | char *remotestr; |
| 214 | char *startsep = ""; |
| 215 | char *endsep = ""; |
| 216 | size_t len; |
| 217 | uint16_t port; |
| 218 | |
| 219 | switch (ds_addr->sa_family) { |
| 220 | case AF_INET: |
| 221 | port = ((struct sockaddr_in *)ds_addr)->sin_port; |
| 222 | break; |
| 223 | case AF_INET6: |
| 224 | startsep = "["; |
| 225 | endsep = "]"; |
| 226 | port = ((struct sockaddr_in6 *)ds_addr)->sin6_port; |
| 227 | break; |
| 228 | default: |
| 229 | dprintk("%s: Unknown address family %u\n", |
| 230 | __func__, ds_addr->sa_family); |
| 231 | return NULL; |
| 232 | } |
| 233 | |
| 234 | if (!rpc_ntop((struct sockaddr *)ds_addr, buf, sizeof(buf))) { |
| 235 | dprintk("%s: error printing addr\n", __func__); |
| 236 | return NULL; |
| 237 | } |
| 238 | |
| 239 | len = strlen(buf) + strlen(startsep) + strlen(endsep) + 1 + 5 + 1; |
| 240 | remotestr = kzalloc(len, gfp_flags); |
| 241 | |
| 242 | if (unlikely(!remotestr)) { |
| 243 | dprintk("%s: couldn't alloc remotestr\n", __func__); |
| 244 | return NULL; |
| 245 | } |
| 246 | |
| 247 | snprintf(remotestr, len, "%s%s%s:%u", |
| 248 | startsep, buf, endsep, ntohs(port)); |
| 249 | |
| 250 | return remotestr; |
| 251 | } |
| 252 | |
| 253 | static struct nfs4_pnfs_ds * |
| 254 | nfs4_pnfs_ds_add(struct sockaddr *addr, size_t addrlen, gfp_t gfp_flags) |
| 255 | { |
| 256 | struct nfs4_pnfs_ds *tmp_ds, *ds = NULL; |
| 257 | char *remotestr; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 258 | |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 259 | ds = kzalloc(sizeof(*tmp_ds), gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 260 | if (!ds) |
| 261 | goto out; |
| 262 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 263 | /* this is only used for debugging, so it's ok if its NULL */ |
| 264 | remotestr = nfs4_pnfs_remotestr(addr, gfp_flags); |
| 265 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 266 | spin_lock(&nfs4_ds_cache_lock); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 267 | tmp_ds = _data_server_lookup_locked(addr, addrlen); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 268 | if (tmp_ds == NULL) { |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 269 | memcpy(&ds->ds_addr, addr, addrlen); |
| 270 | ds->ds_addrlen = addrlen; |
| 271 | ds->ds_remotestr = remotestr; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 272 | atomic_set(&ds->ds_count, 1); |
| 273 | INIT_LIST_HEAD(&ds->ds_node); |
| 274 | ds->ds_clp = NULL; |
| 275 | list_add(&ds->ds_node, &nfs4_data_server_cache); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 276 | dprintk("%s add new data server %s\n", __func__, |
| 277 | ds->ds_remotestr); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 278 | } else { |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 279 | kfree(remotestr); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 280 | kfree(ds); |
| 281 | atomic_inc(&tmp_ds->ds_count); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 282 | dprintk("%s data server %s found, inc'ed ds_count to %d\n", |
| 283 | __func__, tmp_ds->ds_remotestr, |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 284 | atomic_read(&tmp_ds->ds_count)); |
| 285 | ds = tmp_ds; |
| 286 | } |
| 287 | spin_unlock(&nfs4_ds_cache_lock); |
| 288 | out: |
| 289 | return ds; |
| 290 | } |
| 291 | |
| 292 | /* |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 293 | * Currently only supports ipv4, ipv6 and one multi-path address. |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 294 | */ |
| 295 | static struct nfs4_pnfs_ds * |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 296 | decode_and_add_ds(struct xdr_stream *streamp, struct inode *inode, gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 297 | { |
| 298 | struct nfs4_pnfs_ds *ds = NULL; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 299 | char *buf, *portstr; |
| 300 | struct sockaddr_storage ss; |
| 301 | size_t sslen; |
| 302 | u32 port; |
| 303 | int nlen, rlen; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 304 | int tmp[2]; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 305 | __be32 *p; |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 306 | char *netid, *match_netid; |
| 307 | size_t match_netid_len; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 308 | |
| 309 | /* r_netid */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 310 | p = xdr_inline_decode(streamp, 4); |
| 311 | if (unlikely(!p)) |
| 312 | goto out_err; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 313 | nlen = be32_to_cpup(p++); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 314 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 315 | p = xdr_inline_decode(streamp, nlen); |
| 316 | if (unlikely(!p)) |
| 317 | goto out_err; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 318 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 319 | netid = kmalloc(nlen+1, gfp_flags); |
| 320 | if (unlikely(!netid)) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 321 | goto out_err; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 322 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 323 | netid[nlen] = '\0'; |
| 324 | memcpy(netid, p, nlen); |
| 325 | |
| 326 | /* 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] | 327 | p = xdr_inline_decode(streamp, 4); |
| 328 | if (unlikely(!p)) |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 329 | goto out_free_netid; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 330 | rlen = be32_to_cpup(p); |
| 331 | |
| 332 | p = xdr_inline_decode(streamp, rlen); |
| 333 | if (unlikely(!p)) |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 334 | goto out_free_netid; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 335 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 336 | /* port is ".ABC.DEF", 8 chars max */ |
| 337 | if (rlen > INET6_ADDRSTRLEN + IPV6_SCOPE_ID_LEN + 8) { |
Jesper Juhl | ad3d2ee | 2011-01-17 18:41:50 +0000 | [diff] [blame] | 338 | dprintk("%s: Invalid address, length %d\n", __func__, |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 339 | rlen); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 340 | goto out_free_netid; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 341 | } |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 342 | buf = kmalloc(rlen + 1, gfp_flags); |
Stanislav Fomichev | b9f8105 | 2011-02-05 23:13:01 +0000 | [diff] [blame] | 343 | if (!buf) { |
| 344 | dprintk("%s: Not enough memory\n", __func__); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 345 | goto out_free_netid; |
Stanislav Fomichev | b9f8105 | 2011-02-05 23:13:01 +0000 | [diff] [blame] | 346 | } |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 347 | buf[rlen] = '\0'; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 348 | memcpy(buf, p, rlen); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 349 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 350 | /* replace port '.' with '-' */ |
| 351 | portstr = strrchr(buf, '.'); |
| 352 | if (!portstr) { |
| 353 | dprintk("%s: Failed finding expected dot in port\n", |
| 354 | __func__); |
| 355 | goto out_free_buf; |
| 356 | } |
| 357 | *portstr = '-'; |
| 358 | |
| 359 | /* find '.' between address and port */ |
| 360 | portstr = strrchr(buf, '.'); |
| 361 | if (!portstr) { |
| 362 | dprintk("%s: Failed finding expected dot between address and " |
| 363 | "port\n", __func__); |
| 364 | goto out_free_buf; |
| 365 | } |
| 366 | *portstr = '\0'; |
| 367 | |
| 368 | if (!rpc_pton(buf, portstr-buf, (struct sockaddr *)&ss, sizeof(ss))) { |
| 369 | dprintk("%s: Error parsing address %s\n", __func__, buf); |
| 370 | goto out_free_buf; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 371 | } |
| 372 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 373 | portstr++; |
| 374 | sscanf(portstr, "%d-%d", &tmp[0], &tmp[1]); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 375 | port = htons((tmp[0] << 8) | (tmp[1])); |
| 376 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 377 | switch (ss.ss_family) { |
| 378 | case AF_INET: |
| 379 | ((struct sockaddr_in *)&ss)->sin_port = port; |
| 380 | sslen = sizeof(struct sockaddr_in); |
| 381 | match_netid = "tcp"; |
| 382 | match_netid_len = 3; |
| 383 | break; |
| 384 | |
| 385 | case AF_INET6: |
| 386 | ((struct sockaddr_in6 *)&ss)->sin6_port = port; |
| 387 | sslen = sizeof(struct sockaddr_in6); |
| 388 | match_netid = "tcp6"; |
| 389 | match_netid_len = 4; |
| 390 | break; |
| 391 | |
| 392 | default: |
| 393 | dprintk("%s: unsupported address family: %u\n", |
| 394 | __func__, ss.ss_family); |
| 395 | goto out_free_buf; |
| 396 | } |
| 397 | |
| 398 | if (nlen != match_netid_len || strncmp(netid, match_netid, nlen)) { |
| 399 | dprintk("%s: ERROR: r_netid \"%s\" != \"%s\"\n", |
| 400 | __func__, netid, match_netid); |
| 401 | goto out_free_buf; |
| 402 | } |
| 403 | |
| 404 | ds = nfs4_pnfs_ds_add((struct sockaddr *)&ss, sslen, gfp_flags); |
| 405 | dprintk("%s: Added DS %s\n", __func__, ds->ds_remotestr); |
| 406 | out_free_buf: |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 407 | kfree(buf); |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 408 | out_free_netid: |
| 409 | kfree(netid); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 410 | out_err: |
| 411 | return ds; |
| 412 | } |
| 413 | |
| 414 | /* Decode opaque device data and return the result */ |
| 415 | static struct nfs4_file_layout_dsaddr* |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 416 | decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 417 | { |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 418 | int i; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 419 | u32 cnt, num; |
| 420 | u8 *indexp; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 421 | __be32 *p; |
| 422 | u8 *stripe_indices; |
| 423 | u8 max_stripe_index; |
| 424 | struct nfs4_file_layout_dsaddr *dsaddr = NULL; |
| 425 | struct xdr_stream stream; |
Benny Halevy | f7da7a1 | 2011-05-19 14:16:47 -0400 | [diff] [blame] | 426 | struct xdr_buf buf; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 427 | struct page *scratch; |
| 428 | |
| 429 | /* set up xdr stream */ |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 430 | scratch = alloc_page(gfp_flags); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 431 | if (!scratch) |
| 432 | goto out_err; |
| 433 | |
Benny Halevy | f7da7a1 | 2011-05-19 14:16:47 -0400 | [diff] [blame] | 434 | xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 435 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 436 | |
| 437 | /* Get the stripe count (number of stripe index) */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 438 | p = xdr_inline_decode(&stream, 4); |
| 439 | if (unlikely(!p)) |
| 440 | goto out_err_free_scratch; |
| 441 | |
| 442 | cnt = be32_to_cpup(p); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 443 | dprintk("%s stripe count %d\n", __func__, cnt); |
| 444 | if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) { |
| 445 | printk(KERN_WARNING "%s: stripe count %d greater than " |
| 446 | "supported maximum %d\n", __func__, |
| 447 | cnt, NFS4_PNFS_MAX_STRIPE_CNT); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 448 | goto out_err_free_scratch; |
| 449 | } |
| 450 | |
| 451 | /* read stripe indices */ |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 452 | stripe_indices = kcalloc(cnt, sizeof(u8), gfp_flags); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 453 | if (!stripe_indices) |
| 454 | goto out_err_free_scratch; |
| 455 | |
| 456 | p = xdr_inline_decode(&stream, cnt << 2); |
| 457 | if (unlikely(!p)) |
| 458 | goto out_err_free_stripe_indices; |
| 459 | |
| 460 | indexp = &stripe_indices[0]; |
| 461 | max_stripe_index = 0; |
| 462 | for (i = 0; i < cnt; i++) { |
| 463 | *indexp = be32_to_cpup(p++); |
| 464 | max_stripe_index = max(max_stripe_index, *indexp); |
| 465 | indexp++; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /* Check the multipath list count */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 469 | p = xdr_inline_decode(&stream, 4); |
| 470 | if (unlikely(!p)) |
| 471 | goto out_err_free_stripe_indices; |
| 472 | |
| 473 | num = be32_to_cpup(p); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 474 | dprintk("%s ds_num %u\n", __func__, num); |
| 475 | if (num > NFS4_PNFS_MAX_MULTI_CNT) { |
| 476 | printk(KERN_WARNING "%s: multipath count %d greater than " |
| 477 | "supported maximum %d\n", __func__, |
| 478 | num, NFS4_PNFS_MAX_MULTI_CNT); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 479 | goto out_err_free_stripe_indices; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 480 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 481 | |
| 482 | /* validate stripe indices are all < num */ |
| 483 | if (max_stripe_index >= num) { |
| 484 | printk(KERN_WARNING "%s: stripe index %u >= num ds %u\n", |
| 485 | __func__, max_stripe_index, num); |
| 486 | goto out_err_free_stripe_indices; |
| 487 | } |
| 488 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 489 | dsaddr = kzalloc(sizeof(*dsaddr) + |
| 490 | (sizeof(struct nfs4_pnfs_ds *) * (num - 1)), |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 491 | gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 492 | if (!dsaddr) |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 493 | goto out_err_free_stripe_indices; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 494 | |
| 495 | dsaddr->stripe_count = cnt; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 496 | dsaddr->stripe_indices = stripe_indices; |
| 497 | stripe_indices = NULL; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 498 | dsaddr->ds_num = num; |
Benny Halevy | 1775bc3 | 2011-05-20 13:47:33 +0200 | [diff] [blame] | 499 | nfs4_init_deviceid_node(&dsaddr->id_node, |
| 500 | NFS_SERVER(ino)->pnfs_curr_ld, |
| 501 | NFS_SERVER(ino)->nfs_client, |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 502 | &pdev->dev_id); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 503 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 504 | for (i = 0; i < dsaddr->ds_num; i++) { |
| 505 | int j; |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 506 | u32 mp_count; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 507 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 508 | p = xdr_inline_decode(&stream, 4); |
| 509 | if (unlikely(!p)) |
| 510 | goto out_err_free_deviceid; |
| 511 | |
| 512 | mp_count = be32_to_cpup(p); /* multipath count */ |
| 513 | if (mp_count > 1) { |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 514 | printk(KERN_WARNING |
| 515 | "%s: Multipath count %d not supported, " |
| 516 | "skipping all greater than 1\n", __func__, |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 517 | mp_count); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 518 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 519 | for (j = 0; j < mp_count; j++) { |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 520 | if (j == 0) { |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 521 | dsaddr->ds_list[i] = decode_and_add_ds(&stream, |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 522 | ino, gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 523 | if (dsaddr->ds_list[i] == NULL) |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 524 | goto out_err_free_deviceid; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 525 | } else { |
| 526 | u32 len; |
| 527 | /* skip extra multipath */ |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 528 | |
| 529 | /* read len, skip */ |
| 530 | p = xdr_inline_decode(&stream, 4); |
| 531 | if (unlikely(!p)) |
| 532 | goto out_err_free_deviceid; |
| 533 | len = be32_to_cpup(p); |
| 534 | |
| 535 | p = xdr_inline_decode(&stream, len); |
| 536 | if (unlikely(!p)) |
| 537 | goto out_err_free_deviceid; |
| 538 | |
| 539 | /* read len, skip */ |
| 540 | p = xdr_inline_decode(&stream, 4); |
| 541 | if (unlikely(!p)) |
| 542 | goto out_err_free_deviceid; |
| 543 | len = be32_to_cpup(p); |
| 544 | |
| 545 | p = xdr_inline_decode(&stream, len); |
| 546 | if (unlikely(!p)) |
| 547 | goto out_err_free_deviceid; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | } |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 551 | |
| 552 | __free_page(scratch); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 553 | return dsaddr; |
| 554 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 555 | out_err_free_deviceid: |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 556 | nfs4_fl_free_deviceid(dsaddr); |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 557 | /* stripe_indicies was part of dsaddr */ |
| 558 | goto out_err_free_scratch; |
| 559 | out_err_free_stripe_indices: |
| 560 | kfree(stripe_indices); |
| 561 | out_err_free_scratch: |
| 562 | __free_page(scratch); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 563 | out_err: |
| 564 | dprintk("%s ERROR: returning NULL\n", __func__); |
| 565 | return NULL; |
| 566 | } |
| 567 | |
| 568 | /* |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 569 | * Decode the opaque device specified in 'dev' and add it to the cache of |
| 570 | * available devices. |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 571 | */ |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 572 | static struct nfs4_file_layout_dsaddr * |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 573 | decode_and_add_device(struct inode *inode, struct pnfs_device *dev, gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 574 | { |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 575 | struct nfs4_deviceid_node *d; |
| 576 | struct nfs4_file_layout_dsaddr *n, *new; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 577 | |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 578 | new = decode_device(inode, dev, gfp_flags); |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 579 | if (!new) { |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 580 | printk(KERN_WARNING "%s: Could not decode or add device\n", |
| 581 | __func__); |
| 582 | return NULL; |
| 583 | } |
| 584 | |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 585 | d = nfs4_insert_deviceid_node(&new->id_node); |
| 586 | n = container_of(d, struct nfs4_file_layout_dsaddr, id_node); |
| 587 | if (n != new) { |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 588 | nfs4_fl_free_deviceid(new); |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 589 | return n; |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 590 | } |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 591 | |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 592 | return new; |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | /* |
| 596 | * Retrieve the information for dev_id, add it to the list |
| 597 | * of available devices, and return it. |
| 598 | */ |
| 599 | struct nfs4_file_layout_dsaddr * |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 600 | get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id, gfp_t gfp_flags) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 601 | { |
| 602 | struct pnfs_device *pdev = NULL; |
| 603 | u32 max_resp_sz; |
| 604 | int max_pages; |
| 605 | struct page **pages = NULL; |
| 606 | struct nfs4_file_layout_dsaddr *dsaddr = NULL; |
| 607 | int rc, i; |
| 608 | struct nfs_server *server = NFS_SERVER(inode); |
| 609 | |
| 610 | /* |
| 611 | * Use the session max response size as the basis for setting |
| 612 | * GETDEVICEINFO's maxcount |
| 613 | */ |
| 614 | max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 615 | max_pages = max_resp_sz >> PAGE_SHIFT; |
| 616 | dprintk("%s inode %p max_resp_sz %u max_pages %d\n", |
| 617 | __func__, inode, max_resp_sz, max_pages); |
| 618 | |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 619 | pdev = kzalloc(sizeof(struct pnfs_device), gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 620 | if (pdev == NULL) |
| 621 | return NULL; |
| 622 | |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 623 | pages = kzalloc(max_pages * sizeof(struct page *), gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 624 | if (pages == NULL) { |
| 625 | kfree(pdev); |
| 626 | return NULL; |
| 627 | } |
| 628 | for (i = 0; i < max_pages; i++) { |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 629 | pages[i] = alloc_page(gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 630 | if (!pages[i]) |
| 631 | goto out_free; |
| 632 | } |
| 633 | |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 634 | memcpy(&pdev->dev_id, dev_id, sizeof(*dev_id)); |
| 635 | pdev->layout_type = LAYOUT_NFSV4_1_FILES; |
| 636 | pdev->pages = pages; |
| 637 | pdev->pgbase = 0; |
| 638 | pdev->pglen = PAGE_SIZE * max_pages; |
| 639 | pdev->mincount = 0; |
| 640 | |
| 641 | rc = nfs4_proc_getdeviceinfo(server, pdev); |
| 642 | dprintk("%s getdevice info returns %d\n", __func__, rc); |
| 643 | if (rc) |
| 644 | goto out_free; |
| 645 | |
| 646 | /* |
| 647 | * Found new device, need to decode it and then add it to the |
| 648 | * list of known devices for this mountpoint. |
| 649 | */ |
Trond Myklebust | a75b9df | 2011-05-11 18:00:51 -0400 | [diff] [blame] | 650 | dsaddr = decode_and_add_device(inode, pdev, gfp_flags); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 651 | out_free: |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 652 | for (i = 0; i < max_pages; i++) |
| 653 | __free_page(pages[i]); |
| 654 | kfree(pages); |
| 655 | kfree(pdev); |
| 656 | dprintk("<-- %s dsaddr %p\n", __func__, dsaddr); |
| 657 | return dsaddr; |
| 658 | } |
| 659 | |
Christoph Hellwig | ea8eecd | 2011-03-01 01:34:21 +0000 | [diff] [blame] | 660 | void |
| 661 | nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr) |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 662 | { |
Benny Halevy | 1775bc3 | 2011-05-20 13:47:33 +0200 | [diff] [blame] | 663 | nfs4_put_deviceid_node(&dsaddr->id_node); |
Andy Adamson | 16b374c | 2010-10-20 00:18:04 -0400 | [diff] [blame] | 664 | } |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 665 | |
| 666 | /* |
| 667 | * Want res = (offset - layout->pattern_offset)/ layout->stripe_unit |
| 668 | * Then: ((res + fsi) % dsaddr->stripe_count) |
| 669 | */ |
| 670 | u32 |
| 671 | nfs4_fl_calc_j_index(struct pnfs_layout_segment *lseg, loff_t offset) |
| 672 | { |
| 673 | struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); |
| 674 | u64 tmp; |
| 675 | |
| 676 | tmp = offset - flseg->pattern_offset; |
| 677 | do_div(tmp, flseg->stripe_unit); |
| 678 | tmp += flseg->first_stripe_index; |
| 679 | return do_div(tmp, flseg->dsaddr->stripe_count); |
| 680 | } |
| 681 | |
| 682 | u32 |
| 683 | nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j) |
| 684 | { |
| 685 | return FILELAYOUT_LSEG(lseg)->dsaddr->stripe_indices[j]; |
| 686 | } |
| 687 | |
| 688 | struct nfs_fh * |
| 689 | nfs4_fl_select_ds_fh(struct pnfs_layout_segment *lseg, u32 j) |
| 690 | { |
| 691 | struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); |
| 692 | u32 i; |
| 693 | |
| 694 | if (flseg->stripe_type == STRIPE_SPARSE) { |
| 695 | if (flseg->num_fh == 1) |
| 696 | i = 0; |
| 697 | else if (flseg->num_fh == 0) |
| 698 | /* Use the MDS OPEN fh set in nfs_read_rpcsetup */ |
| 699 | return NULL; |
| 700 | else |
| 701 | i = nfs4_fl_calc_ds_index(lseg, j); |
| 702 | } else |
| 703 | i = j; |
| 704 | return flseg->fh_array[i]; |
| 705 | } |
| 706 | |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 707 | static void |
| 708 | filelayout_mark_devid_negative(struct nfs4_file_layout_dsaddr *dsaddr, |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 709 | int err, const char *ds_remotestr) |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 710 | { |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 711 | u32 *p = (u32 *)&dsaddr->id_node.deviceid; |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 712 | |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 713 | printk(KERN_ERR "NFS: data server %s connection error %d." |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 714 | " Deviceid [%x%x%x%x] marked out of use.\n", |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 715 | ds_remotestr, err, p[0], p[1], p[2], p[3]); |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 716 | |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 717 | spin_lock(&nfs4_ds_cache_lock); |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 718 | dsaddr->flags |= NFS4_DEVICE_ID_NEG_ENTRY; |
Benny Halevy | a1eaecb | 2011-05-19 22:14:47 -0400 | [diff] [blame] | 719 | spin_unlock(&nfs4_ds_cache_lock); |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 722 | struct nfs4_pnfs_ds * |
| 723 | nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx) |
| 724 | { |
| 725 | struct nfs4_file_layout_dsaddr *dsaddr = FILELAYOUT_LSEG(lseg)->dsaddr; |
| 726 | struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx]; |
| 727 | |
| 728 | if (ds == NULL) { |
| 729 | printk(KERN_ERR "%s: No data server for offset index %d\n", |
| 730 | __func__, ds_idx); |
| 731 | return NULL; |
| 732 | } |
| 733 | |
| 734 | if (!ds->ds_clp) { |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 735 | struct nfs_server *s = NFS_SERVER(lseg->pls_layout->plh_inode); |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 736 | int err; |
| 737 | |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 738 | if (dsaddr->flags & NFS4_DEVICE_ID_NEG_ENTRY) { |
| 739 | /* Already tried to connect, don't try again */ |
| 740 | dprintk("%s Deviceid marked out of use\n", __func__); |
| 741 | return NULL; |
| 742 | } |
| 743 | err = nfs4_ds_connect(s, ds); |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 744 | if (err) { |
Andy Adamson | 568e8c4 | 2011-03-01 01:34:22 +0000 | [diff] [blame] | 745 | filelayout_mark_devid_negative(dsaddr, err, |
Weston Andros Adamson | c9895cb | 2011-05-31 18:48:56 -0400 | [diff] [blame^] | 746 | ds->ds_remotestr); |
Fred Isaman | cfe7f41 | 2011-03-01 01:34:18 +0000 | [diff] [blame] | 747 | return NULL; |
| 748 | } |
| 749 | } |
| 750 | return ds; |
| 751 | } |