Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Module for pnfs flexfile layout driver. |
| 3 | * |
| 4 | * Copyright (c) 2014, Primary Data, Inc. All rights reserved. |
| 5 | * |
| 6 | * Tao Peng <bergwolf@primarydata.com> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/nfs_fs.h> |
| 10 | #include <linux/nfs_page.h> |
| 11 | #include <linux/module.h> |
| 12 | |
| 13 | #include <linux/sunrpc/metrics.h> |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 14 | |
| 15 | #include "flexfilelayout.h" |
| 16 | #include "../nfs4session.h" |
Anna Schumaker | 40c64c2 | 2015-04-15 13:00:05 -0400 | [diff] [blame] | 17 | #include "../nfs4idmap.h" |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 18 | #include "../internal.h" |
| 19 | #include "../delegation.h" |
| 20 | #include "../nfs4trace.h" |
| 21 | #include "../iostat.h" |
| 22 | #include "../nfs.h" |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 23 | #include "../nfs42.h" |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 24 | |
| 25 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD |
| 26 | |
| 27 | #define FF_LAYOUT_POLL_RETRY_MAX (15*HZ) |
| 28 | |
| 29 | static struct pnfs_layout_hdr * |
| 30 | ff_layout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags) |
| 31 | { |
| 32 | struct nfs4_flexfile_layout *ffl; |
| 33 | |
| 34 | ffl = kzalloc(sizeof(*ffl), gfp_flags); |
| 35 | if (ffl) { |
| 36 | INIT_LIST_HEAD(&ffl->error_list); |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 37 | INIT_LIST_HEAD(&ffl->mirrors); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 38 | return &ffl->generic_hdr; |
| 39 | } else |
| 40 | return NULL; |
| 41 | } |
| 42 | |
| 43 | static void |
| 44 | ff_layout_free_layout_hdr(struct pnfs_layout_hdr *lo) |
| 45 | { |
| 46 | struct nfs4_ff_layout_ds_err *err, *n; |
| 47 | |
| 48 | list_for_each_entry_safe(err, n, &FF_LAYOUT_FROM_HDR(lo)->error_list, |
| 49 | list) { |
| 50 | list_del(&err->list); |
| 51 | kfree(err); |
| 52 | } |
| 53 | kfree(FF_LAYOUT_FROM_HDR(lo)); |
| 54 | } |
| 55 | |
| 56 | static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) |
| 57 | { |
| 58 | __be32 *p; |
| 59 | |
| 60 | p = xdr_inline_decode(xdr, NFS4_STATEID_SIZE); |
| 61 | if (unlikely(p == NULL)) |
| 62 | return -ENOBUFS; |
| 63 | memcpy(stateid, p, NFS4_STATEID_SIZE); |
| 64 | dprintk("%s: stateid id= [%x%x%x%x]\n", __func__, |
| 65 | p[0], p[1], p[2], p[3]); |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static int decode_deviceid(struct xdr_stream *xdr, struct nfs4_deviceid *devid) |
| 70 | { |
| 71 | __be32 *p; |
| 72 | |
| 73 | p = xdr_inline_decode(xdr, NFS4_DEVICEID4_SIZE); |
| 74 | if (unlikely(!p)) |
| 75 | return -ENOBUFS; |
| 76 | memcpy(devid, p, NFS4_DEVICEID4_SIZE); |
| 77 | nfs4_print_deviceid(devid); |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int decode_nfs_fh(struct xdr_stream *xdr, struct nfs_fh *fh) |
| 82 | { |
| 83 | __be32 *p; |
| 84 | |
| 85 | p = xdr_inline_decode(xdr, 4); |
| 86 | if (unlikely(!p)) |
| 87 | return -ENOBUFS; |
| 88 | fh->size = be32_to_cpup(p++); |
| 89 | if (fh->size > sizeof(struct nfs_fh)) { |
| 90 | printk(KERN_ERR "NFS flexfiles: Too big fh received %d\n", |
| 91 | fh->size); |
| 92 | return -EOVERFLOW; |
| 93 | } |
| 94 | /* fh.data */ |
| 95 | p = xdr_inline_decode(xdr, fh->size); |
| 96 | if (unlikely(!p)) |
| 97 | return -ENOBUFS; |
| 98 | memcpy(&fh->data, p, fh->size); |
| 99 | dprintk("%s: fh len %d\n", __func__, fh->size); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * Currently only stringified uids and gids are accepted. |
| 106 | * I.e., kerberos is not supported to the DSes, so no pricipals. |
| 107 | * |
| 108 | * That means that one common function will suffice, but when |
| 109 | * principals are added, this should be split to accomodate |
| 110 | * calls to both nfs_map_name_to_uid() and nfs_map_group_to_gid(). |
| 111 | */ |
| 112 | static int |
| 113 | decode_name(struct xdr_stream *xdr, u32 *id) |
| 114 | { |
| 115 | __be32 *p; |
| 116 | int len; |
| 117 | |
| 118 | /* opaque_length(4)*/ |
| 119 | p = xdr_inline_decode(xdr, 4); |
| 120 | if (unlikely(!p)) |
| 121 | return -ENOBUFS; |
| 122 | len = be32_to_cpup(p++); |
| 123 | if (len < 0) |
| 124 | return -EINVAL; |
| 125 | |
| 126 | dprintk("%s: len %u\n", __func__, len); |
| 127 | |
| 128 | /* opaque body */ |
| 129 | p = xdr_inline_decode(xdr, len); |
| 130 | if (unlikely(!p)) |
| 131 | return -ENOBUFS; |
| 132 | |
| 133 | if (!nfs_map_string_to_numeric((char *)p, len, id)) |
| 134 | return -EINVAL; |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 139 | static bool ff_mirror_match_fh(const struct nfs4_ff_layout_mirror *m1, |
| 140 | const struct nfs4_ff_layout_mirror *m2) |
| 141 | { |
| 142 | int i, j; |
| 143 | |
| 144 | if (m1->fh_versions_cnt != m2->fh_versions_cnt) |
| 145 | return false; |
| 146 | for (i = 0; i < m1->fh_versions_cnt; i++) { |
| 147 | bool found_fh = false; |
| 148 | for (j = 0; j < m2->fh_versions_cnt; i++) { |
| 149 | if (nfs_compare_fh(&m1->fh_versions[i], |
| 150 | &m2->fh_versions[j]) == 0) { |
| 151 | found_fh = true; |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | if (!found_fh) |
| 156 | return false; |
| 157 | } |
| 158 | return true; |
| 159 | } |
| 160 | |
| 161 | static struct nfs4_ff_layout_mirror * |
| 162 | ff_layout_add_mirror(struct pnfs_layout_hdr *lo, |
| 163 | struct nfs4_ff_layout_mirror *mirror) |
| 164 | { |
| 165 | struct nfs4_flexfile_layout *ff_layout = FF_LAYOUT_FROM_HDR(lo); |
| 166 | struct nfs4_ff_layout_mirror *pos; |
| 167 | struct inode *inode = lo->plh_inode; |
| 168 | |
| 169 | spin_lock(&inode->i_lock); |
| 170 | list_for_each_entry(pos, &ff_layout->mirrors, mirrors) { |
| 171 | if (mirror->mirror_ds != pos->mirror_ds) |
| 172 | continue; |
| 173 | if (!ff_mirror_match_fh(mirror, pos)) |
| 174 | continue; |
| 175 | if (atomic_inc_not_zero(&pos->ref)) { |
| 176 | spin_unlock(&inode->i_lock); |
| 177 | return pos; |
| 178 | } |
| 179 | } |
| 180 | list_add(&mirror->mirrors, &ff_layout->mirrors); |
| 181 | mirror->layout = lo; |
| 182 | spin_unlock(&inode->i_lock); |
| 183 | return mirror; |
| 184 | } |
| 185 | |
| 186 | void |
| 187 | ff_layout_remove_mirror(struct nfs4_ff_layout_mirror *mirror) |
| 188 | { |
| 189 | struct inode *inode; |
| 190 | if (mirror->layout == NULL) |
| 191 | return; |
| 192 | inode = mirror->layout->plh_inode; |
| 193 | spin_lock(&inode->i_lock); |
| 194 | list_del(&mirror->mirrors); |
| 195 | spin_unlock(&inode->i_lock); |
| 196 | mirror->layout = NULL; |
| 197 | } |
| 198 | |
Trond Myklebust | 28a0d72 | 2015-08-24 18:08:30 -0400 | [diff] [blame] | 199 | static struct nfs4_ff_layout_mirror *ff_layout_alloc_mirror(gfp_t gfp_flags) |
| 200 | { |
| 201 | struct nfs4_ff_layout_mirror *mirror; |
| 202 | |
| 203 | mirror = kzalloc(sizeof(*mirror), gfp_flags); |
| 204 | if (mirror != NULL) { |
| 205 | spin_lock_init(&mirror->lock); |
| 206 | atomic_set(&mirror->ref, 1); |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 207 | INIT_LIST_HEAD(&mirror->mirrors); |
Trond Myklebust | 28a0d72 | 2015-08-24 18:08:30 -0400 | [diff] [blame] | 208 | } |
| 209 | return mirror; |
| 210 | } |
| 211 | |
| 212 | static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror *mirror) |
| 213 | { |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 214 | ff_layout_remove_mirror(mirror); |
Trond Myklebust | 28a0d72 | 2015-08-24 18:08:30 -0400 | [diff] [blame] | 215 | kfree(mirror->fh_versions); |
| 216 | nfs4_ff_layout_put_deviceid(mirror->mirror_ds); |
| 217 | kfree(mirror); |
| 218 | } |
| 219 | |
| 220 | static void ff_layout_put_mirror(struct nfs4_ff_layout_mirror *mirror) |
| 221 | { |
| 222 | if (mirror != NULL && atomic_dec_and_test(&mirror->ref)) |
| 223 | ff_layout_free_mirror(mirror); |
| 224 | } |
| 225 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 226 | static void ff_layout_free_mirror_array(struct nfs4_ff_layout_segment *fls) |
| 227 | { |
| 228 | int i; |
| 229 | |
| 230 | if (fls->mirror_array) { |
| 231 | for (i = 0; i < fls->mirror_array_cnt; i++) { |
| 232 | /* normally mirror_ds is freed in |
| 233 | * .free_deviceid_node but we still do it here |
| 234 | * for .alloc_lseg error path */ |
Trond Myklebust | 28a0d72 | 2015-08-24 18:08:30 -0400 | [diff] [blame] | 235 | ff_layout_put_mirror(fls->mirror_array[i]); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 236 | } |
| 237 | kfree(fls->mirror_array); |
| 238 | fls->mirror_array = NULL; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | static int ff_layout_check_layout(struct nfs4_layoutget_res *lgr) |
| 243 | { |
| 244 | int ret = 0; |
| 245 | |
| 246 | dprintk("--> %s\n", __func__); |
| 247 | |
| 248 | /* FIXME: remove this check when layout segment support is added */ |
| 249 | if (lgr->range.offset != 0 || |
| 250 | lgr->range.length != NFS4_MAX_UINT64) { |
| 251 | dprintk("%s Only whole file layouts supported. Use MDS i/o\n", |
| 252 | __func__); |
| 253 | ret = -EINVAL; |
| 254 | } |
| 255 | |
| 256 | dprintk("--> %s returns %d\n", __func__, ret); |
| 257 | return ret; |
| 258 | } |
| 259 | |
| 260 | static void _ff_layout_free_lseg(struct nfs4_ff_layout_segment *fls) |
| 261 | { |
| 262 | if (fls) { |
| 263 | ff_layout_free_mirror_array(fls); |
| 264 | kfree(fls); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | static void ff_layout_sort_mirrors(struct nfs4_ff_layout_segment *fls) |
| 269 | { |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 270 | int i, j; |
| 271 | |
| 272 | for (i = 0; i < fls->mirror_array_cnt - 1; i++) { |
| 273 | for (j = i + 1; j < fls->mirror_array_cnt; j++) |
| 274 | if (fls->mirror_array[i]->efficiency < |
Fabian Frederick | 455b6ee | 2015-06-12 18:58:50 +0200 | [diff] [blame] | 275 | fls->mirror_array[j]->efficiency) |
| 276 | swap(fls->mirror_array[i], |
| 277 | fls->mirror_array[j]); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
| 281 | static struct pnfs_layout_segment * |
| 282 | ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh, |
| 283 | struct nfs4_layoutget_res *lgr, |
| 284 | gfp_t gfp_flags) |
| 285 | { |
| 286 | struct pnfs_layout_segment *ret; |
| 287 | struct nfs4_ff_layout_segment *fls = NULL; |
| 288 | struct xdr_stream stream; |
| 289 | struct xdr_buf buf; |
| 290 | struct page *scratch; |
| 291 | u64 stripe_unit; |
| 292 | u32 mirror_array_cnt; |
| 293 | __be32 *p; |
| 294 | int i, rc; |
| 295 | |
| 296 | dprintk("--> %s\n", __func__); |
| 297 | scratch = alloc_page(gfp_flags); |
| 298 | if (!scratch) |
| 299 | return ERR_PTR(-ENOMEM); |
| 300 | |
| 301 | xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, |
| 302 | lgr->layoutp->len); |
| 303 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); |
| 304 | |
| 305 | /* stripe unit and mirror_array_cnt */ |
| 306 | rc = -EIO; |
| 307 | p = xdr_inline_decode(&stream, 8 + 4); |
| 308 | if (!p) |
| 309 | goto out_err_free; |
| 310 | |
| 311 | p = xdr_decode_hyper(p, &stripe_unit); |
| 312 | mirror_array_cnt = be32_to_cpup(p++); |
| 313 | dprintk("%s: stripe_unit=%llu mirror_array_cnt=%u\n", __func__, |
| 314 | stripe_unit, mirror_array_cnt); |
| 315 | |
| 316 | if (mirror_array_cnt > NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT || |
| 317 | mirror_array_cnt == 0) |
| 318 | goto out_err_free; |
| 319 | |
| 320 | rc = -ENOMEM; |
| 321 | fls = kzalloc(sizeof(*fls), gfp_flags); |
| 322 | if (!fls) |
| 323 | goto out_err_free; |
| 324 | |
| 325 | fls->mirror_array_cnt = mirror_array_cnt; |
| 326 | fls->stripe_unit = stripe_unit; |
| 327 | fls->mirror_array = kcalloc(fls->mirror_array_cnt, |
| 328 | sizeof(fls->mirror_array[0]), gfp_flags); |
| 329 | if (fls->mirror_array == NULL) |
| 330 | goto out_err_free; |
| 331 | |
| 332 | for (i = 0; i < fls->mirror_array_cnt; i++) { |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 333 | struct nfs4_ff_layout_mirror *mirror; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 334 | struct nfs4_deviceid devid; |
| 335 | struct nfs4_deviceid_node *idnode; |
| 336 | u32 ds_count; |
| 337 | u32 fh_count; |
| 338 | int j; |
| 339 | |
| 340 | rc = -EIO; |
| 341 | p = xdr_inline_decode(&stream, 4); |
| 342 | if (!p) |
| 343 | goto out_err_free; |
| 344 | ds_count = be32_to_cpup(p); |
| 345 | |
| 346 | /* FIXME: allow for striping? */ |
| 347 | if (ds_count != 1) |
| 348 | goto out_err_free; |
| 349 | |
Trond Myklebust | 28a0d72 | 2015-08-24 18:08:30 -0400 | [diff] [blame] | 350 | fls->mirror_array[i] = ff_layout_alloc_mirror(gfp_flags); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 351 | if (fls->mirror_array[i] == NULL) { |
| 352 | rc = -ENOMEM; |
| 353 | goto out_err_free; |
| 354 | } |
| 355 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 356 | fls->mirror_array[i]->ds_count = ds_count; |
| 357 | |
| 358 | /* deviceid */ |
| 359 | rc = decode_deviceid(&stream, &devid); |
| 360 | if (rc) |
| 361 | goto out_err_free; |
| 362 | |
| 363 | idnode = nfs4_find_get_deviceid(NFS_SERVER(lh->plh_inode), |
| 364 | &devid, lh->plh_lc_cred, |
| 365 | gfp_flags); |
| 366 | /* |
| 367 | * upon success, mirror_ds is allocated by previous |
| 368 | * getdeviceinfo, or newly by .alloc_deviceid_node |
| 369 | * nfs4_find_get_deviceid failure is indeed getdeviceinfo falure |
| 370 | */ |
| 371 | if (idnode) |
| 372 | fls->mirror_array[i]->mirror_ds = |
| 373 | FF_LAYOUT_MIRROR_DS(idnode); |
| 374 | else |
| 375 | goto out_err_free; |
| 376 | |
| 377 | /* efficiency */ |
| 378 | rc = -EIO; |
| 379 | p = xdr_inline_decode(&stream, 4); |
| 380 | if (!p) |
| 381 | goto out_err_free; |
| 382 | fls->mirror_array[i]->efficiency = be32_to_cpup(p); |
| 383 | |
| 384 | /* stateid */ |
| 385 | rc = decode_stateid(&stream, &fls->mirror_array[i]->stateid); |
| 386 | if (rc) |
| 387 | goto out_err_free; |
| 388 | |
| 389 | /* fh */ |
| 390 | p = xdr_inline_decode(&stream, 4); |
| 391 | if (!p) |
| 392 | goto out_err_free; |
| 393 | fh_count = be32_to_cpup(p); |
| 394 | |
| 395 | fls->mirror_array[i]->fh_versions = |
| 396 | kzalloc(fh_count * sizeof(struct nfs_fh), |
| 397 | gfp_flags); |
| 398 | if (fls->mirror_array[i]->fh_versions == NULL) { |
| 399 | rc = -ENOMEM; |
| 400 | goto out_err_free; |
| 401 | } |
| 402 | |
| 403 | for (j = 0; j < fh_count; j++) { |
| 404 | rc = decode_nfs_fh(&stream, |
| 405 | &fls->mirror_array[i]->fh_versions[j]); |
| 406 | if (rc) |
| 407 | goto out_err_free; |
| 408 | } |
| 409 | |
| 410 | fls->mirror_array[i]->fh_versions_cnt = fh_count; |
| 411 | |
| 412 | /* user */ |
| 413 | rc = decode_name(&stream, &fls->mirror_array[i]->uid); |
| 414 | if (rc) |
| 415 | goto out_err_free; |
| 416 | |
| 417 | /* group */ |
| 418 | rc = decode_name(&stream, &fls->mirror_array[i]->gid); |
| 419 | if (rc) |
| 420 | goto out_err_free; |
| 421 | |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 422 | mirror = ff_layout_add_mirror(lh, fls->mirror_array[i]); |
| 423 | if (mirror != fls->mirror_array[i]) { |
| 424 | ff_layout_free_mirror(fls->mirror_array[i]); |
| 425 | fls->mirror_array[i] = mirror; |
| 426 | } |
| 427 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 428 | dprintk("%s: uid %d gid %d\n", __func__, |
| 429 | fls->mirror_array[i]->uid, |
| 430 | fls->mirror_array[i]->gid); |
| 431 | } |
| 432 | |
Trond Myklebust | c0f5f50 | 2015-06-26 14:51:32 -0400 | [diff] [blame] | 433 | p = xdr_inline_decode(&stream, 4); |
| 434 | if (p) |
| 435 | fls->flags = be32_to_cpup(p); |
| 436 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 437 | ff_layout_sort_mirrors(fls); |
| 438 | rc = ff_layout_check_layout(lgr); |
| 439 | if (rc) |
| 440 | goto out_err_free; |
| 441 | |
| 442 | ret = &fls->generic_hdr; |
| 443 | dprintk("<-- %s (success)\n", __func__); |
| 444 | out_free_page: |
| 445 | __free_page(scratch); |
| 446 | return ret; |
| 447 | out_err_free: |
| 448 | _ff_layout_free_lseg(fls); |
| 449 | ret = ERR_PTR(rc); |
| 450 | dprintk("<-- %s (%d)\n", __func__, rc); |
| 451 | goto out_free_page; |
| 452 | } |
| 453 | |
| 454 | static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout) |
| 455 | { |
| 456 | struct pnfs_layout_segment *lseg; |
| 457 | |
| 458 | list_for_each_entry(lseg, &layout->plh_segs, pls_list) |
| 459 | if (lseg->pls_range.iomode == IOMODE_RW) |
| 460 | return true; |
| 461 | |
| 462 | return false; |
| 463 | } |
| 464 | |
| 465 | static void |
| 466 | ff_layout_free_lseg(struct pnfs_layout_segment *lseg) |
| 467 | { |
| 468 | struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg); |
| 469 | int i; |
| 470 | |
| 471 | dprintk("--> %s\n", __func__); |
| 472 | |
| 473 | for (i = 0; i < fls->mirror_array_cnt; i++) { |
| 474 | if (fls->mirror_array[i]) { |
| 475 | nfs4_ff_layout_put_deviceid(fls->mirror_array[i]->mirror_ds); |
| 476 | fls->mirror_array[i]->mirror_ds = NULL; |
| 477 | if (fls->mirror_array[i]->cred) { |
| 478 | put_rpccred(fls->mirror_array[i]->cred); |
| 479 | fls->mirror_array[i]->cred = NULL; |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | if (lseg->pls_range.iomode == IOMODE_RW) { |
| 485 | struct nfs4_flexfile_layout *ffl; |
| 486 | struct inode *inode; |
| 487 | |
| 488 | ffl = FF_LAYOUT_FROM_HDR(lseg->pls_layout); |
| 489 | inode = ffl->generic_hdr.plh_inode; |
| 490 | spin_lock(&inode->i_lock); |
| 491 | if (!ff_layout_has_rw_segments(lseg->pls_layout)) { |
| 492 | ffl->commit_info.nbuckets = 0; |
| 493 | kfree(ffl->commit_info.buckets); |
| 494 | ffl->commit_info.buckets = NULL; |
| 495 | } |
| 496 | spin_unlock(&inode->i_lock); |
| 497 | } |
| 498 | _ff_layout_free_lseg(fls); |
| 499 | } |
| 500 | |
| 501 | /* Return 1 until we have multiple lsegs support */ |
| 502 | static int |
| 503 | ff_layout_get_lseg_count(struct nfs4_ff_layout_segment *fls) |
| 504 | { |
| 505 | return 1; |
| 506 | } |
| 507 | |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 508 | static void |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 509 | nfs4_ff_start_busy_timer(struct nfs4_ff_busy_timer *timer, ktime_t now) |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 510 | { |
Peng Tao | 9bbd9bb | 2015-06-26 09:45:49 +0800 | [diff] [blame] | 511 | /* first IO request? */ |
| 512 | if (atomic_inc_return(&timer->n_ops) == 1) { |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 513 | timer->start_time = now; |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
| 517 | static ktime_t |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 518 | nfs4_ff_end_busy_timer(struct nfs4_ff_busy_timer *timer, ktime_t now) |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 519 | { |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 520 | ktime_t start; |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 521 | |
Peng Tao | 9bbd9bb | 2015-06-26 09:45:49 +0800 | [diff] [blame] | 522 | if (atomic_dec_return(&timer->n_ops) < 0) |
| 523 | WARN_ON_ONCE(1); |
| 524 | |
Peng Tao | 9bbd9bb | 2015-06-26 09:45:49 +0800 | [diff] [blame] | 525 | start = timer->start_time; |
| 526 | timer->start_time = now; |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 527 | return ktime_sub(now, start); |
| 528 | } |
| 529 | |
Peng Tao | 97ba375 | 2015-06-23 19:52:04 +0800 | [diff] [blame] | 530 | static bool |
Peng Tao | d983803 | 2015-06-23 19:52:00 +0800 | [diff] [blame] | 531 | nfs4_ff_layoutstat_start_io(struct nfs4_ff_layout_mirror *mirror, |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 532 | struct nfs4_ff_layoutstat *layoutstat, |
| 533 | ktime_t now) |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 534 | { |
Peng Tao | d983803 | 2015-06-23 19:52:00 +0800 | [diff] [blame] | 535 | static const ktime_t notime = {0}; |
| 536 | |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 537 | nfs4_ff_start_busy_timer(&layoutstat->busy_timer, now); |
Peng Tao | 9bbd9bb | 2015-06-26 09:45:49 +0800 | [diff] [blame] | 538 | if (ktime_equal(mirror->start_time, notime)) |
| 539 | mirror->start_time = now; |
| 540 | if (ktime_equal(mirror->last_report_time, notime)) |
| 541 | mirror->last_report_time = now; |
Peng Tao | 97ba375 | 2015-06-23 19:52:04 +0800 | [diff] [blame] | 542 | if (ktime_to_ms(ktime_sub(now, mirror->last_report_time)) >= |
| 543 | FF_LAYOUTSTATS_REPORT_INTERVAL) { |
| 544 | mirror->last_report_time = now; |
| 545 | return true; |
| 546 | } |
| 547 | |
| 548 | return false; |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static void |
| 552 | nfs4_ff_layout_stat_io_update_requested(struct nfs4_ff_layoutstat *layoutstat, |
| 553 | __u64 requested) |
| 554 | { |
| 555 | struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat; |
| 556 | |
| 557 | iostat->ops_requested++; |
| 558 | iostat->bytes_requested += requested; |
| 559 | } |
| 560 | |
| 561 | static void |
| 562 | nfs4_ff_layout_stat_io_update_completed(struct nfs4_ff_layoutstat *layoutstat, |
| 563 | __u64 requested, |
| 564 | __u64 completed, |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 565 | ktime_t time_completed, |
| 566 | ktime_t time_started) |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 567 | { |
| 568 | struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat; |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 569 | ktime_t completion_time = ktime_sub(time_completed, time_started); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 570 | ktime_t timer; |
| 571 | |
| 572 | iostat->ops_completed++; |
| 573 | iostat->bytes_completed += completed; |
| 574 | iostat->bytes_not_delivered += requested - completed; |
| 575 | |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 576 | timer = nfs4_ff_end_busy_timer(&layoutstat->busy_timer, time_completed); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 577 | iostat->total_busy_time = |
| 578 | ktime_add(iostat->total_busy_time, timer); |
| 579 | iostat->aggregate_completion_time = |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 580 | ktime_add(iostat->aggregate_completion_time, |
| 581 | completion_time); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | static void |
Trond Myklebust | 0b7baf9 | 2015-08-24 18:22:28 -0400 | [diff] [blame] | 585 | nfs4_ff_layout_stat_io_start_read(struct inode *inode, |
| 586 | struct nfs4_ff_layout_mirror *mirror, |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 587 | __u64 requested, ktime_t now) |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 588 | { |
Peng Tao | 97ba375 | 2015-06-23 19:52:04 +0800 | [diff] [blame] | 589 | bool report; |
| 590 | |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 591 | spin_lock(&mirror->lock); |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 592 | report = nfs4_ff_layoutstat_start_io(mirror, &mirror->read_stat, now); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 593 | nfs4_ff_layout_stat_io_update_requested(&mirror->read_stat, requested); |
| 594 | spin_unlock(&mirror->lock); |
Peng Tao | 97ba375 | 2015-06-23 19:52:04 +0800 | [diff] [blame] | 595 | |
| 596 | if (report) |
Trond Myklebust | 0b7baf9 | 2015-08-24 18:22:28 -0400 | [diff] [blame] | 597 | pnfs_report_layoutstat(inode, GFP_KERNEL); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static void |
| 601 | nfs4_ff_layout_stat_io_end_read(struct rpc_task *task, |
| 602 | struct nfs4_ff_layout_mirror *mirror, |
| 603 | __u64 requested, |
| 604 | __u64 completed) |
| 605 | { |
| 606 | spin_lock(&mirror->lock); |
| 607 | nfs4_ff_layout_stat_io_update_completed(&mirror->read_stat, |
| 608 | requested, completed, |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 609 | ktime_get(), task->tk_start); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 610 | spin_unlock(&mirror->lock); |
| 611 | } |
| 612 | |
| 613 | static void |
Trond Myklebust | 0b7baf9 | 2015-08-24 18:22:28 -0400 | [diff] [blame] | 614 | nfs4_ff_layout_stat_io_start_write(struct inode *inode, |
| 615 | struct nfs4_ff_layout_mirror *mirror, |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 616 | __u64 requested, ktime_t now) |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 617 | { |
Peng Tao | 97ba375 | 2015-06-23 19:52:04 +0800 | [diff] [blame] | 618 | bool report; |
| 619 | |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 620 | spin_lock(&mirror->lock); |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 621 | report = nfs4_ff_layoutstat_start_io(mirror , &mirror->write_stat, now); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 622 | nfs4_ff_layout_stat_io_update_requested(&mirror->write_stat, requested); |
| 623 | spin_unlock(&mirror->lock); |
Peng Tao | 97ba375 | 2015-06-23 19:52:04 +0800 | [diff] [blame] | 624 | |
| 625 | if (report) |
Trond Myklebust | 0b7baf9 | 2015-08-24 18:22:28 -0400 | [diff] [blame] | 626 | pnfs_report_layoutstat(inode, GFP_NOIO); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | static void |
| 630 | nfs4_ff_layout_stat_io_end_write(struct rpc_task *task, |
| 631 | struct nfs4_ff_layout_mirror *mirror, |
| 632 | __u64 requested, |
| 633 | __u64 completed, |
| 634 | enum nfs3_stable_how committed) |
| 635 | { |
| 636 | if (committed == NFS_UNSTABLE) |
| 637 | requested = completed = 0; |
| 638 | |
| 639 | spin_lock(&mirror->lock); |
| 640 | nfs4_ff_layout_stat_io_update_completed(&mirror->write_stat, |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 641 | requested, completed, ktime_get(), task->tk_start); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 642 | spin_unlock(&mirror->lock); |
| 643 | } |
| 644 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 645 | static int |
| 646 | ff_layout_alloc_commit_info(struct pnfs_layout_segment *lseg, |
| 647 | struct nfs_commit_info *cinfo, |
| 648 | gfp_t gfp_flags) |
| 649 | { |
| 650 | struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg); |
| 651 | struct pnfs_commit_bucket *buckets; |
| 652 | int size; |
| 653 | |
| 654 | if (cinfo->ds->nbuckets != 0) { |
| 655 | /* This assumes there is only one RW lseg per file. |
| 656 | * To support multiple lseg per file, we need to |
| 657 | * change struct pnfs_commit_bucket to allow dynamic |
| 658 | * increasing nbuckets. |
| 659 | */ |
| 660 | return 0; |
| 661 | } |
| 662 | |
| 663 | size = ff_layout_get_lseg_count(fls) * FF_LAYOUT_MIRROR_COUNT(lseg); |
| 664 | |
| 665 | buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket), |
| 666 | gfp_flags); |
| 667 | if (!buckets) |
| 668 | return -ENOMEM; |
| 669 | else { |
| 670 | int i; |
| 671 | |
| 672 | spin_lock(cinfo->lock); |
| 673 | if (cinfo->ds->nbuckets != 0) |
| 674 | kfree(buckets); |
| 675 | else { |
| 676 | cinfo->ds->buckets = buckets; |
| 677 | cinfo->ds->nbuckets = size; |
| 678 | for (i = 0; i < size; i++) { |
| 679 | INIT_LIST_HEAD(&buckets[i].written); |
| 680 | INIT_LIST_HEAD(&buckets[i].committing); |
| 681 | /* mark direct verifier as unset */ |
| 682 | buckets[i].direct_verf.committed = |
| 683 | NFS_INVALID_STABLE_HOW; |
| 684 | } |
| 685 | } |
| 686 | spin_unlock(cinfo->lock); |
| 687 | return 0; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | static struct nfs4_pnfs_ds * |
| 692 | ff_layout_choose_best_ds_for_read(struct nfs_pageio_descriptor *pgio, |
| 693 | int *best_idx) |
| 694 | { |
| 695 | struct nfs4_ff_layout_segment *fls; |
| 696 | struct nfs4_pnfs_ds *ds; |
| 697 | int idx; |
| 698 | |
| 699 | fls = FF_LAYOUT_LSEG(pgio->pg_lseg); |
| 700 | /* mirrors are sorted by efficiency */ |
| 701 | for (idx = 0; idx < fls->mirror_array_cnt; idx++) { |
| 702 | ds = nfs4_ff_layout_prepare_ds(pgio->pg_lseg, idx, false); |
| 703 | if (ds) { |
| 704 | *best_idx = idx; |
| 705 | return ds; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | return NULL; |
| 710 | } |
| 711 | |
| 712 | static void |
| 713 | ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio, |
| 714 | struct nfs_page *req) |
| 715 | { |
| 716 | struct nfs_pgio_mirror *pgm; |
| 717 | struct nfs4_ff_layout_mirror *mirror; |
| 718 | struct nfs4_pnfs_ds *ds; |
| 719 | int ds_idx; |
| 720 | |
| 721 | /* Use full layout for now */ |
| 722 | if (!pgio->pg_lseg) |
| 723 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, |
| 724 | req->wb_context, |
| 725 | 0, |
| 726 | NFS4_MAX_UINT64, |
| 727 | IOMODE_READ, |
| 728 | GFP_KERNEL); |
| 729 | /* If no lseg, fall back to read through mds */ |
| 730 | if (pgio->pg_lseg == NULL) |
| 731 | goto out_mds; |
| 732 | |
| 733 | ds = ff_layout_choose_best_ds_for_read(pgio, &ds_idx); |
| 734 | if (!ds) |
| 735 | goto out_mds; |
| 736 | mirror = FF_LAYOUT_COMP(pgio->pg_lseg, ds_idx); |
| 737 | |
| 738 | pgio->pg_mirror_idx = ds_idx; |
| 739 | |
| 740 | /* read always uses only one mirror - idx 0 for pgio layer */ |
| 741 | pgm = &pgio->pg_mirrors[0]; |
| 742 | pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].rsize; |
| 743 | |
| 744 | return; |
| 745 | out_mds: |
| 746 | pnfs_put_lseg(pgio->pg_lseg); |
| 747 | pgio->pg_lseg = NULL; |
| 748 | nfs_pageio_reset_read_mds(pgio); |
| 749 | } |
| 750 | |
| 751 | static void |
| 752 | ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio, |
| 753 | struct nfs_page *req) |
| 754 | { |
| 755 | struct nfs4_ff_layout_mirror *mirror; |
| 756 | struct nfs_pgio_mirror *pgm; |
| 757 | struct nfs_commit_info cinfo; |
| 758 | struct nfs4_pnfs_ds *ds; |
| 759 | int i; |
| 760 | int status; |
| 761 | |
| 762 | if (!pgio->pg_lseg) |
| 763 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, |
| 764 | req->wb_context, |
| 765 | 0, |
| 766 | NFS4_MAX_UINT64, |
| 767 | IOMODE_RW, |
| 768 | GFP_NOFS); |
| 769 | /* If no lseg, fall back to write through mds */ |
| 770 | if (pgio->pg_lseg == NULL) |
| 771 | goto out_mds; |
| 772 | |
| 773 | nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq); |
| 774 | status = ff_layout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS); |
| 775 | if (status < 0) |
| 776 | goto out_mds; |
| 777 | |
| 778 | /* Use a direct mapping of ds_idx to pgio mirror_idx */ |
| 779 | if (WARN_ON_ONCE(pgio->pg_mirror_count != |
| 780 | FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg))) |
| 781 | goto out_mds; |
| 782 | |
| 783 | for (i = 0; i < pgio->pg_mirror_count; i++) { |
| 784 | ds = nfs4_ff_layout_prepare_ds(pgio->pg_lseg, i, true); |
| 785 | if (!ds) |
| 786 | goto out_mds; |
| 787 | pgm = &pgio->pg_mirrors[i]; |
| 788 | mirror = FF_LAYOUT_COMP(pgio->pg_lseg, i); |
| 789 | pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].wsize; |
| 790 | } |
| 791 | |
| 792 | return; |
| 793 | |
| 794 | out_mds: |
| 795 | pnfs_put_lseg(pgio->pg_lseg); |
| 796 | pgio->pg_lseg = NULL; |
| 797 | nfs_pageio_reset_write_mds(pgio); |
| 798 | } |
| 799 | |
| 800 | static unsigned int |
| 801 | ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio, |
| 802 | struct nfs_page *req) |
| 803 | { |
| 804 | if (!pgio->pg_lseg) |
| 805 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, |
| 806 | req->wb_context, |
| 807 | 0, |
| 808 | NFS4_MAX_UINT64, |
| 809 | IOMODE_RW, |
| 810 | GFP_NOFS); |
| 811 | if (pgio->pg_lseg) |
| 812 | return FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg); |
| 813 | |
| 814 | /* no lseg means that pnfs is not in use, so no mirroring here */ |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 815 | nfs_pageio_reset_write_mds(pgio); |
| 816 | return 1; |
| 817 | } |
| 818 | |
| 819 | static const struct nfs_pageio_ops ff_layout_pg_read_ops = { |
| 820 | .pg_init = ff_layout_pg_init_read, |
| 821 | .pg_test = pnfs_generic_pg_test, |
| 822 | .pg_doio = pnfs_generic_pg_readpages, |
| 823 | .pg_cleanup = pnfs_generic_pg_cleanup, |
| 824 | }; |
| 825 | |
| 826 | static const struct nfs_pageio_ops ff_layout_pg_write_ops = { |
| 827 | .pg_init = ff_layout_pg_init_write, |
| 828 | .pg_test = pnfs_generic_pg_test, |
| 829 | .pg_doio = pnfs_generic_pg_writepages, |
| 830 | .pg_get_mirror_count = ff_layout_pg_get_mirror_count_write, |
| 831 | .pg_cleanup = pnfs_generic_pg_cleanup, |
| 832 | }; |
| 833 | |
| 834 | static void ff_layout_reset_write(struct nfs_pgio_header *hdr, bool retry_pnfs) |
| 835 | { |
| 836 | struct rpc_task *task = &hdr->task; |
| 837 | |
| 838 | pnfs_layoutcommit_inode(hdr->inode, false); |
| 839 | |
| 840 | if (retry_pnfs) { |
| 841 | dprintk("%s Reset task %5u for i/o through pNFS " |
| 842 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__, |
| 843 | hdr->task.tk_pid, |
| 844 | hdr->inode->i_sb->s_id, |
| 845 | (unsigned long long)NFS_FILEID(hdr->inode), |
| 846 | hdr->args.count, |
| 847 | (unsigned long long)hdr->args.offset); |
| 848 | |
| 849 | if (!hdr->dreq) { |
| 850 | struct nfs_open_context *ctx; |
| 851 | |
| 852 | ctx = nfs_list_entry(hdr->pages.next)->wb_context; |
| 853 | set_bit(NFS_CONTEXT_RESEND_WRITES, &ctx->flags); |
| 854 | hdr->completion_ops->error_cleanup(&hdr->pages); |
| 855 | } else { |
| 856 | nfs_direct_set_resched_writes(hdr->dreq); |
| 857 | /* fake unstable write to let common nfs resend pages */ |
| 858 | hdr->verf.committed = NFS_UNSTABLE; |
Trond Myklebust | d620876 | 2015-06-26 15:37:58 -0400 | [diff] [blame] | 859 | hdr->good_bytes = hdr->args.count; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 860 | } |
| 861 | return; |
| 862 | } |
| 863 | |
| 864 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { |
| 865 | dprintk("%s Reset task %5u for i/o through MDS " |
| 866 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__, |
| 867 | hdr->task.tk_pid, |
| 868 | hdr->inode->i_sb->s_id, |
| 869 | (unsigned long long)NFS_FILEID(hdr->inode), |
| 870 | hdr->args.count, |
| 871 | (unsigned long long)hdr->args.offset); |
| 872 | |
| 873 | task->tk_status = pnfs_write_done_resend_to_mds(hdr); |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | static void ff_layout_reset_read(struct nfs_pgio_header *hdr) |
| 878 | { |
| 879 | struct rpc_task *task = &hdr->task; |
| 880 | |
| 881 | pnfs_layoutcommit_inode(hdr->inode, false); |
| 882 | |
| 883 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { |
| 884 | dprintk("%s Reset task %5u for i/o through MDS " |
| 885 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__, |
| 886 | hdr->task.tk_pid, |
| 887 | hdr->inode->i_sb->s_id, |
| 888 | (unsigned long long)NFS_FILEID(hdr->inode), |
| 889 | hdr->args.count, |
| 890 | (unsigned long long)hdr->args.offset); |
| 891 | |
| 892 | task->tk_status = pnfs_read_done_resend_to_mds(hdr); |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | static int ff_layout_async_handle_error_v4(struct rpc_task *task, |
| 897 | struct nfs4_state *state, |
| 898 | struct nfs_client *clp, |
| 899 | struct pnfs_layout_segment *lseg, |
| 900 | int idx) |
| 901 | { |
| 902 | struct pnfs_layout_hdr *lo = lseg->pls_layout; |
| 903 | struct inode *inode = lo->plh_inode; |
| 904 | struct nfs_server *mds_server = NFS_SERVER(inode); |
| 905 | |
| 906 | struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx); |
| 907 | struct nfs_client *mds_client = mds_server->nfs_client; |
| 908 | struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table; |
| 909 | |
| 910 | if (task->tk_status >= 0) |
| 911 | return 0; |
| 912 | |
| 913 | switch (task->tk_status) { |
| 914 | /* MDS state errors */ |
| 915 | case -NFS4ERR_DELEG_REVOKED: |
| 916 | case -NFS4ERR_ADMIN_REVOKED: |
| 917 | case -NFS4ERR_BAD_STATEID: |
| 918 | if (state == NULL) |
| 919 | break; |
| 920 | nfs_remove_bad_delegation(state->inode); |
| 921 | case -NFS4ERR_OPENMODE: |
| 922 | if (state == NULL) |
| 923 | break; |
| 924 | if (nfs4_schedule_stateid_recovery(mds_server, state) < 0) |
| 925 | goto out_bad_stateid; |
| 926 | goto wait_on_recovery; |
| 927 | case -NFS4ERR_EXPIRED: |
| 928 | if (state != NULL) { |
| 929 | if (nfs4_schedule_stateid_recovery(mds_server, state) < 0) |
| 930 | goto out_bad_stateid; |
| 931 | } |
| 932 | nfs4_schedule_lease_recovery(mds_client); |
| 933 | goto wait_on_recovery; |
| 934 | /* DS session errors */ |
| 935 | case -NFS4ERR_BADSESSION: |
| 936 | case -NFS4ERR_BADSLOT: |
| 937 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 938 | case -NFS4ERR_DEADSESSION: |
| 939 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 940 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 941 | case -NFS4ERR_SEQ_MISORDERED: |
| 942 | dprintk("%s ERROR %d, Reset session. Exchangeid " |
| 943 | "flags 0x%x\n", __func__, task->tk_status, |
| 944 | clp->cl_exchange_flags); |
| 945 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
| 946 | break; |
| 947 | case -NFS4ERR_DELAY: |
| 948 | case -NFS4ERR_GRACE: |
| 949 | rpc_delay(task, FF_LAYOUT_POLL_RETRY_MAX); |
| 950 | break; |
| 951 | case -NFS4ERR_RETRY_UNCACHED_REP: |
| 952 | break; |
| 953 | /* Invalidate Layout errors */ |
| 954 | case -NFS4ERR_PNFS_NO_LAYOUT: |
| 955 | case -ESTALE: /* mapped NFS4ERR_STALE */ |
| 956 | case -EBADHANDLE: /* mapped NFS4ERR_BADHANDLE */ |
| 957 | case -EISDIR: /* mapped NFS4ERR_ISDIR */ |
| 958 | case -NFS4ERR_FHEXPIRED: |
| 959 | case -NFS4ERR_WRONG_TYPE: |
| 960 | dprintk("%s Invalid layout error %d\n", __func__, |
| 961 | task->tk_status); |
| 962 | /* |
| 963 | * Destroy layout so new i/o will get a new layout. |
| 964 | * Layout will not be destroyed until all current lseg |
| 965 | * references are put. Mark layout as invalid to resend failed |
| 966 | * i/o and all i/o waiting on the slot table to the MDS until |
| 967 | * layout is destroyed and a new valid layout is obtained. |
| 968 | */ |
| 969 | pnfs_destroy_layout(NFS_I(inode)); |
| 970 | rpc_wake_up(&tbl->slot_tbl_waitq); |
| 971 | goto reset; |
| 972 | /* RPC connection errors */ |
| 973 | case -ECONNREFUSED: |
| 974 | case -EHOSTDOWN: |
| 975 | case -EHOSTUNREACH: |
| 976 | case -ENETUNREACH: |
| 977 | case -EIO: |
| 978 | case -ETIMEDOUT: |
| 979 | case -EPIPE: |
| 980 | dprintk("%s DS connection error %d\n", __func__, |
| 981 | task->tk_status); |
| 982 | nfs4_mark_deviceid_unavailable(devid); |
| 983 | rpc_wake_up(&tbl->slot_tbl_waitq); |
| 984 | /* fall through */ |
| 985 | default: |
| 986 | if (ff_layout_has_available_ds(lseg)) |
| 987 | return -NFS4ERR_RESET_TO_PNFS; |
| 988 | reset: |
| 989 | dprintk("%s Retry through MDS. Error %d\n", __func__, |
| 990 | task->tk_status); |
| 991 | return -NFS4ERR_RESET_TO_MDS; |
| 992 | } |
| 993 | out: |
| 994 | task->tk_status = 0; |
| 995 | return -EAGAIN; |
| 996 | out_bad_stateid: |
| 997 | task->tk_status = -EIO; |
| 998 | return 0; |
| 999 | wait_on_recovery: |
| 1000 | rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL); |
| 1001 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0) |
| 1002 | rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task); |
| 1003 | goto out; |
| 1004 | } |
| 1005 | |
| 1006 | /* Retry all errors through either pNFS or MDS except for -EJUKEBOX */ |
| 1007 | static int ff_layout_async_handle_error_v3(struct rpc_task *task, |
| 1008 | struct pnfs_layout_segment *lseg, |
| 1009 | int idx) |
| 1010 | { |
| 1011 | struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx); |
| 1012 | |
| 1013 | if (task->tk_status >= 0) |
| 1014 | return 0; |
| 1015 | |
| 1016 | if (task->tk_status != -EJUKEBOX) { |
| 1017 | dprintk("%s DS connection error %d\n", __func__, |
| 1018 | task->tk_status); |
| 1019 | nfs4_mark_deviceid_unavailable(devid); |
| 1020 | if (ff_layout_has_available_ds(lseg)) |
| 1021 | return -NFS4ERR_RESET_TO_PNFS; |
| 1022 | else |
| 1023 | return -NFS4ERR_RESET_TO_MDS; |
| 1024 | } |
| 1025 | |
| 1026 | if (task->tk_status == -EJUKEBOX) |
| 1027 | nfs_inc_stats(lseg->pls_layout->plh_inode, NFSIOS_DELAY); |
| 1028 | task->tk_status = 0; |
| 1029 | rpc_restart_call(task); |
| 1030 | rpc_delay(task, NFS_JUKEBOX_RETRY_TIME); |
| 1031 | return -EAGAIN; |
| 1032 | } |
| 1033 | |
| 1034 | static int ff_layout_async_handle_error(struct rpc_task *task, |
| 1035 | struct nfs4_state *state, |
| 1036 | struct nfs_client *clp, |
| 1037 | struct pnfs_layout_segment *lseg, |
| 1038 | int idx) |
| 1039 | { |
| 1040 | int vers = clp->cl_nfs_mod->rpc_vers->number; |
| 1041 | |
| 1042 | switch (vers) { |
| 1043 | case 3: |
| 1044 | return ff_layout_async_handle_error_v3(task, lseg, idx); |
| 1045 | case 4: |
| 1046 | return ff_layout_async_handle_error_v4(task, state, clp, |
| 1047 | lseg, idx); |
| 1048 | default: |
| 1049 | /* should never happen */ |
| 1050 | WARN_ON_ONCE(1); |
| 1051 | return 0; |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg, |
| 1056 | int idx, u64 offset, u64 length, |
Trond Myklebust | dd52128 | 2015-08-20 17:59:49 -0500 | [diff] [blame] | 1057 | u32 status, int opnum, int error) |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1058 | { |
| 1059 | struct nfs4_ff_layout_mirror *mirror; |
| 1060 | int err; |
| 1061 | |
Trond Myklebust | dd52128 | 2015-08-20 17:59:49 -0500 | [diff] [blame] | 1062 | if (status == 0) { |
| 1063 | switch (error) { |
| 1064 | case -ETIMEDOUT: |
| 1065 | case -EPFNOSUPPORT: |
| 1066 | case -EPROTONOSUPPORT: |
| 1067 | case -EOPNOTSUPP: |
| 1068 | case -ECONNREFUSED: |
| 1069 | case -ECONNRESET: |
| 1070 | case -EHOSTDOWN: |
| 1071 | case -EHOSTUNREACH: |
| 1072 | case -ENETUNREACH: |
| 1073 | case -EADDRINUSE: |
| 1074 | case -ENOBUFS: |
| 1075 | case -EPIPE: |
| 1076 | case -EPERM: |
| 1077 | status = NFS4ERR_NXIO; |
| 1078 | break; |
| 1079 | case -EACCES: |
| 1080 | status = NFS4ERR_ACCESS; |
| 1081 | break; |
| 1082 | default: |
| 1083 | return; |
| 1084 | } |
| 1085 | } |
| 1086 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1087 | mirror = FF_LAYOUT_COMP(lseg, idx); |
| 1088 | err = ff_layout_track_ds_error(FF_LAYOUT_FROM_HDR(lseg->pls_layout), |
| 1089 | mirror, offset, length, status, opnum, |
| 1090 | GFP_NOIO); |
| 1091 | dprintk("%s: err %d op %d status %u\n", __func__, err, opnum, status); |
| 1092 | } |
| 1093 | |
| 1094 | /* NFS_PROTO call done callback routines */ |
| 1095 | |
| 1096 | static int ff_layout_read_done_cb(struct rpc_task *task, |
| 1097 | struct nfs_pgio_header *hdr) |
| 1098 | { |
| 1099 | struct inode *inode; |
| 1100 | int err; |
| 1101 | |
| 1102 | trace_nfs4_pnfs_read(hdr, task->tk_status); |
Trond Myklebust | dd52128 | 2015-08-20 17:59:49 -0500 | [diff] [blame] | 1103 | if (task->tk_status < 0) |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1104 | ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx, |
| 1105 | hdr->args.offset, hdr->args.count, |
Trond Myklebust | dd52128 | 2015-08-20 17:59:49 -0500 | [diff] [blame] | 1106 | hdr->res.op_status, OP_READ, |
| 1107 | task->tk_status); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1108 | err = ff_layout_async_handle_error(task, hdr->args.context->state, |
| 1109 | hdr->ds_clp, hdr->lseg, |
| 1110 | hdr->pgio_mirror_idx); |
| 1111 | |
| 1112 | switch (err) { |
| 1113 | case -NFS4ERR_RESET_TO_PNFS: |
| 1114 | set_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, |
| 1115 | &hdr->lseg->pls_layout->plh_flags); |
| 1116 | pnfs_read_resend_pnfs(hdr); |
| 1117 | return task->tk_status; |
| 1118 | case -NFS4ERR_RESET_TO_MDS: |
| 1119 | inode = hdr->lseg->pls_layout->plh_inode; |
| 1120 | pnfs_error_mark_layout_for_return(inode, hdr->lseg); |
| 1121 | ff_layout_reset_read(hdr); |
| 1122 | return task->tk_status; |
| 1123 | case -EAGAIN: |
| 1124 | rpc_restart_call_prepare(task); |
| 1125 | return -EAGAIN; |
| 1126 | } |
| 1127 | |
| 1128 | return 0; |
| 1129 | } |
| 1130 | |
Trond Myklebust | c0f5f50 | 2015-06-26 14:51:32 -0400 | [diff] [blame] | 1131 | static bool |
| 1132 | ff_layout_need_layoutcommit(struct pnfs_layout_segment *lseg) |
| 1133 | { |
| 1134 | return !(FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_LAYOUTCOMMIT); |
| 1135 | } |
| 1136 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1137 | /* |
| 1138 | * We reference the rpc_cred of the first WRITE that triggers the need for |
| 1139 | * a LAYOUTCOMMIT, and use it to send the layoutcommit compound. |
| 1140 | * rfc5661 is not clear about which credential should be used. |
| 1141 | * |
| 1142 | * Flexlayout client should treat DS replied FILE_SYNC as DATA_SYNC, so |
| 1143 | * to follow http://www.rfc-editor.org/errata_search.php?rfc=5661&eid=2751 |
| 1144 | * we always send layoutcommit after DS writes. |
| 1145 | */ |
| 1146 | static void |
| 1147 | ff_layout_set_layoutcommit(struct nfs_pgio_header *hdr) |
| 1148 | { |
Trond Myklebust | c0f5f50 | 2015-06-26 14:51:32 -0400 | [diff] [blame] | 1149 | if (!ff_layout_need_layoutcommit(hdr->lseg)) |
| 1150 | return; |
| 1151 | |
Trond Myklebust | 67af761 | 2015-03-25 20:40:38 -0400 | [diff] [blame] | 1152 | pnfs_set_layoutcommit(hdr->inode, hdr->lseg, |
| 1153 | hdr->mds_offset + hdr->res.count); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1154 | dprintk("%s inode %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino, |
| 1155 | (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb); |
| 1156 | } |
| 1157 | |
| 1158 | static bool |
| 1159 | ff_layout_reset_to_mds(struct pnfs_layout_segment *lseg, int idx) |
| 1160 | { |
| 1161 | /* No mirroring for now */ |
| 1162 | struct nfs4_deviceid_node *node = FF_LAYOUT_DEVID_NODE(lseg, idx); |
| 1163 | |
| 1164 | return ff_layout_test_devid_unavailable(node); |
| 1165 | } |
| 1166 | |
| 1167 | static int ff_layout_read_prepare_common(struct rpc_task *task, |
| 1168 | struct nfs_pgio_header *hdr) |
| 1169 | { |
Trond Myklebust | 0b7baf9 | 2015-08-24 18:22:28 -0400 | [diff] [blame] | 1170 | nfs4_ff_layout_stat_io_start_read(hdr->inode, |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1171 | FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx), |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 1172 | hdr->args.count, |
| 1173 | task->tk_start); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1174 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1175 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) { |
| 1176 | rpc_exit(task, -EIO); |
| 1177 | return -EIO; |
| 1178 | } |
| 1179 | if (ff_layout_reset_to_mds(hdr->lseg, hdr->pgio_mirror_idx)) { |
| 1180 | dprintk("%s task %u reset io to MDS\n", __func__, task->tk_pid); |
| 1181 | if (ff_layout_has_available_ds(hdr->lseg)) |
| 1182 | pnfs_read_resend_pnfs(hdr); |
| 1183 | else |
| 1184 | ff_layout_reset_read(hdr); |
| 1185 | rpc_exit(task, 0); |
| 1186 | return -EAGAIN; |
| 1187 | } |
| 1188 | hdr->pgio_done_cb = ff_layout_read_done_cb; |
| 1189 | |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
| 1193 | /* |
| 1194 | * Call ops for the async read/write cases |
| 1195 | * In the case of dense layouts, the offset needs to be reset to its |
| 1196 | * original value. |
| 1197 | */ |
| 1198 | static void ff_layout_read_prepare_v3(struct rpc_task *task, void *data) |
| 1199 | { |
| 1200 | struct nfs_pgio_header *hdr = data; |
| 1201 | |
| 1202 | if (ff_layout_read_prepare_common(task, hdr)) |
| 1203 | return; |
| 1204 | |
| 1205 | rpc_call_start(task); |
| 1206 | } |
| 1207 | |
| 1208 | static int ff_layout_setup_sequence(struct nfs_client *ds_clp, |
| 1209 | struct nfs4_sequence_args *args, |
| 1210 | struct nfs4_sequence_res *res, |
| 1211 | struct rpc_task *task) |
| 1212 | { |
| 1213 | if (ds_clp->cl_session) |
| 1214 | return nfs41_setup_sequence(ds_clp->cl_session, |
| 1215 | args, |
| 1216 | res, |
| 1217 | task); |
| 1218 | return nfs40_setup_sequence(ds_clp->cl_slot_tbl, |
| 1219 | args, |
| 1220 | res, |
| 1221 | task); |
| 1222 | } |
| 1223 | |
| 1224 | static void ff_layout_read_prepare_v4(struct rpc_task *task, void *data) |
| 1225 | { |
| 1226 | struct nfs_pgio_header *hdr = data; |
| 1227 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1228 | if (ff_layout_setup_sequence(hdr->ds_clp, |
| 1229 | &hdr->args.seq_args, |
| 1230 | &hdr->res.seq_res, |
| 1231 | task)) |
| 1232 | return; |
| 1233 | |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1234 | if (ff_layout_read_prepare_common(task, hdr)) |
| 1235 | return; |
| 1236 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1237 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 1238 | hdr->args.lock_context, FMODE_READ) == -EIO) |
| 1239 | rpc_exit(task, -EIO); /* lost lock, terminate I/O */ |
| 1240 | } |
| 1241 | |
| 1242 | static void ff_layout_read_call_done(struct rpc_task *task, void *data) |
| 1243 | { |
| 1244 | struct nfs_pgio_header *hdr = data; |
| 1245 | |
| 1246 | dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status); |
| 1247 | |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1248 | nfs4_ff_layout_stat_io_end_read(task, |
| 1249 | FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx), |
| 1250 | hdr->args.count, hdr->res.count); |
| 1251 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1252 | if (test_bit(NFS_IOHDR_REDO, &hdr->flags) && |
| 1253 | task->tk_status == 0) { |
| 1254 | nfs4_sequence_done(task, &hdr->res.seq_res); |
| 1255 | return; |
| 1256 | } |
| 1257 | |
| 1258 | /* Note this may cause RPC to be resent */ |
| 1259 | hdr->mds_ops->rpc_call_done(task, hdr); |
| 1260 | } |
| 1261 | |
| 1262 | static void ff_layout_read_count_stats(struct rpc_task *task, void *data) |
| 1263 | { |
| 1264 | struct nfs_pgio_header *hdr = data; |
| 1265 | |
| 1266 | rpc_count_iostats_metrics(task, |
| 1267 | &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_READ]); |
| 1268 | } |
| 1269 | |
| 1270 | static int ff_layout_write_done_cb(struct rpc_task *task, |
| 1271 | struct nfs_pgio_header *hdr) |
| 1272 | { |
| 1273 | struct inode *inode; |
| 1274 | int err; |
| 1275 | |
| 1276 | trace_nfs4_pnfs_write(hdr, task->tk_status); |
Trond Myklebust | dd52128 | 2015-08-20 17:59:49 -0500 | [diff] [blame] | 1277 | if (task->tk_status < 0) |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1278 | ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx, |
| 1279 | hdr->args.offset, hdr->args.count, |
Trond Myklebust | dd52128 | 2015-08-20 17:59:49 -0500 | [diff] [blame] | 1280 | hdr->res.op_status, OP_WRITE, |
| 1281 | task->tk_status); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1282 | err = ff_layout_async_handle_error(task, hdr->args.context->state, |
| 1283 | hdr->ds_clp, hdr->lseg, |
| 1284 | hdr->pgio_mirror_idx); |
| 1285 | |
| 1286 | switch (err) { |
| 1287 | case -NFS4ERR_RESET_TO_PNFS: |
| 1288 | case -NFS4ERR_RESET_TO_MDS: |
| 1289 | inode = hdr->lseg->pls_layout->plh_inode; |
| 1290 | pnfs_error_mark_layout_for_return(inode, hdr->lseg); |
| 1291 | if (err == -NFS4ERR_RESET_TO_PNFS) { |
| 1292 | pnfs_set_retry_layoutget(hdr->lseg->pls_layout); |
| 1293 | ff_layout_reset_write(hdr, true); |
| 1294 | } else { |
| 1295 | pnfs_clear_retry_layoutget(hdr->lseg->pls_layout); |
| 1296 | ff_layout_reset_write(hdr, false); |
| 1297 | } |
| 1298 | return task->tk_status; |
| 1299 | case -EAGAIN: |
| 1300 | rpc_restart_call_prepare(task); |
| 1301 | return -EAGAIN; |
| 1302 | } |
| 1303 | |
| 1304 | if (hdr->res.verf->committed == NFS_FILE_SYNC || |
| 1305 | hdr->res.verf->committed == NFS_DATA_SYNC) |
| 1306 | ff_layout_set_layoutcommit(hdr); |
| 1307 | |
Peng Tao | 5420401 | 2015-08-22 06:40:00 +0800 | [diff] [blame] | 1308 | /* zero out fattr since we don't care DS attr at all */ |
| 1309 | hdr->fattr.valid = 0; |
Peng Tao | 69f230d | 2015-08-20 01:52:59 +0800 | [diff] [blame] | 1310 | if (task->tk_status >= 0) |
| 1311 | nfs_writeback_update_inode(hdr); |
| 1312 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1313 | return 0; |
| 1314 | } |
| 1315 | |
| 1316 | static int ff_layout_commit_done_cb(struct rpc_task *task, |
| 1317 | struct nfs_commit_data *data) |
| 1318 | { |
| 1319 | struct inode *inode; |
| 1320 | int err; |
| 1321 | |
| 1322 | trace_nfs4_pnfs_commit_ds(data, task->tk_status); |
Trond Myklebust | dd52128 | 2015-08-20 17:59:49 -0500 | [diff] [blame] | 1323 | if (task->tk_status < 0) |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1324 | ff_layout_io_track_ds_error(data->lseg, data->ds_commit_index, |
| 1325 | data->args.offset, data->args.count, |
Trond Myklebust | dd52128 | 2015-08-20 17:59:49 -0500 | [diff] [blame] | 1326 | data->res.op_status, OP_COMMIT, |
| 1327 | task->tk_status); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1328 | err = ff_layout_async_handle_error(task, NULL, data->ds_clp, |
| 1329 | data->lseg, data->ds_commit_index); |
| 1330 | |
| 1331 | switch (err) { |
| 1332 | case -NFS4ERR_RESET_TO_PNFS: |
| 1333 | case -NFS4ERR_RESET_TO_MDS: |
| 1334 | inode = data->lseg->pls_layout->plh_inode; |
| 1335 | pnfs_error_mark_layout_for_return(inode, data->lseg); |
| 1336 | if (err == -NFS4ERR_RESET_TO_PNFS) |
| 1337 | pnfs_set_retry_layoutget(data->lseg->pls_layout); |
| 1338 | else |
| 1339 | pnfs_clear_retry_layoutget(data->lseg->pls_layout); |
| 1340 | pnfs_generic_prepare_to_resend_writes(data); |
| 1341 | return -EAGAIN; |
| 1342 | case -EAGAIN: |
| 1343 | rpc_restart_call_prepare(task); |
| 1344 | return -EAGAIN; |
| 1345 | } |
| 1346 | |
Trond Myklebust | c0f5f50 | 2015-06-26 14:51:32 -0400 | [diff] [blame] | 1347 | if (data->verf.committed == NFS_UNSTABLE |
| 1348 | && ff_layout_need_layoutcommit(data->lseg)) |
Trond Myklebust | 67af761 | 2015-03-25 20:40:38 -0400 | [diff] [blame] | 1349 | pnfs_set_layoutcommit(data->inode, data->lseg, data->lwb); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1350 | |
| 1351 | return 0; |
| 1352 | } |
| 1353 | |
| 1354 | static int ff_layout_write_prepare_common(struct rpc_task *task, |
| 1355 | struct nfs_pgio_header *hdr) |
| 1356 | { |
Trond Myklebust | 0b7baf9 | 2015-08-24 18:22:28 -0400 | [diff] [blame] | 1357 | nfs4_ff_layout_stat_io_start_write(hdr->inode, |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1358 | FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx), |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 1359 | hdr->args.count, |
| 1360 | task->tk_start); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1361 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1362 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) { |
| 1363 | rpc_exit(task, -EIO); |
| 1364 | return -EIO; |
| 1365 | } |
| 1366 | |
| 1367 | if (ff_layout_reset_to_mds(hdr->lseg, hdr->pgio_mirror_idx)) { |
| 1368 | bool retry_pnfs; |
| 1369 | |
| 1370 | retry_pnfs = ff_layout_has_available_ds(hdr->lseg); |
| 1371 | dprintk("%s task %u reset io to %s\n", __func__, |
| 1372 | task->tk_pid, retry_pnfs ? "pNFS" : "MDS"); |
| 1373 | ff_layout_reset_write(hdr, retry_pnfs); |
| 1374 | rpc_exit(task, 0); |
| 1375 | return -EAGAIN; |
| 1376 | } |
| 1377 | |
| 1378 | return 0; |
| 1379 | } |
| 1380 | |
| 1381 | static void ff_layout_write_prepare_v3(struct rpc_task *task, void *data) |
| 1382 | { |
| 1383 | struct nfs_pgio_header *hdr = data; |
| 1384 | |
| 1385 | if (ff_layout_write_prepare_common(task, hdr)) |
| 1386 | return; |
| 1387 | |
| 1388 | rpc_call_start(task); |
| 1389 | } |
| 1390 | |
| 1391 | static void ff_layout_write_prepare_v4(struct rpc_task *task, void *data) |
| 1392 | { |
| 1393 | struct nfs_pgio_header *hdr = data; |
| 1394 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1395 | if (ff_layout_setup_sequence(hdr->ds_clp, |
| 1396 | &hdr->args.seq_args, |
| 1397 | &hdr->res.seq_res, |
| 1398 | task)) |
| 1399 | return; |
| 1400 | |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1401 | if (ff_layout_write_prepare_common(task, hdr)) |
| 1402 | return; |
| 1403 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1404 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
| 1405 | hdr->args.lock_context, FMODE_WRITE) == -EIO) |
| 1406 | rpc_exit(task, -EIO); /* lost lock, terminate I/O */ |
| 1407 | } |
| 1408 | |
| 1409 | static void ff_layout_write_call_done(struct rpc_task *task, void *data) |
| 1410 | { |
| 1411 | struct nfs_pgio_header *hdr = data; |
| 1412 | |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1413 | nfs4_ff_layout_stat_io_end_write(task, |
| 1414 | FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx), |
| 1415 | hdr->args.count, hdr->res.count, |
| 1416 | hdr->res.verf->committed); |
| 1417 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1418 | if (test_bit(NFS_IOHDR_REDO, &hdr->flags) && |
| 1419 | task->tk_status == 0) { |
| 1420 | nfs4_sequence_done(task, &hdr->res.seq_res); |
| 1421 | return; |
| 1422 | } |
| 1423 | |
| 1424 | /* Note this may cause RPC to be resent */ |
| 1425 | hdr->mds_ops->rpc_call_done(task, hdr); |
| 1426 | } |
| 1427 | |
| 1428 | static void ff_layout_write_count_stats(struct rpc_task *task, void *data) |
| 1429 | { |
| 1430 | struct nfs_pgio_header *hdr = data; |
| 1431 | |
| 1432 | rpc_count_iostats_metrics(task, |
| 1433 | &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_WRITE]); |
| 1434 | } |
| 1435 | |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1436 | static void ff_layout_commit_prepare_common(struct rpc_task *task, |
| 1437 | struct nfs_commit_data *cdata) |
| 1438 | { |
Trond Myklebust | 0b7baf9 | 2015-08-24 18:22:28 -0400 | [diff] [blame] | 1439 | nfs4_ff_layout_stat_io_start_write(cdata->inode, |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1440 | FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index), |
Trond Myklebust | e76d28d | 2015-08-20 13:12:51 -0500 | [diff] [blame] | 1441 | 0, task->tk_start); |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1442 | } |
| 1443 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1444 | static void ff_layout_commit_prepare_v3(struct rpc_task *task, void *data) |
| 1445 | { |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1446 | ff_layout_commit_prepare_common(task, data); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1447 | rpc_call_start(task); |
| 1448 | } |
| 1449 | |
| 1450 | static void ff_layout_commit_prepare_v4(struct rpc_task *task, void *data) |
| 1451 | { |
| 1452 | struct nfs_commit_data *wdata = data; |
| 1453 | |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1454 | if (ff_layout_setup_sequence(wdata->ds_clp, |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1455 | &wdata->args.seq_args, |
| 1456 | &wdata->res.seq_res, |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1457 | task)) |
| 1458 | return; |
| 1459 | ff_layout_commit_prepare_common(task, data); |
| 1460 | } |
| 1461 | |
| 1462 | static void ff_layout_commit_done(struct rpc_task *task, void *data) |
| 1463 | { |
| 1464 | struct nfs_commit_data *cdata = data; |
| 1465 | struct nfs_page *req; |
| 1466 | __u64 count = 0; |
| 1467 | |
| 1468 | if (task->tk_status == 0) { |
| 1469 | list_for_each_entry(req, &cdata->pages, wb_list) |
| 1470 | count += req->wb_bytes; |
| 1471 | } |
| 1472 | |
| 1473 | nfs4_ff_layout_stat_io_end_write(task, |
| 1474 | FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index), |
| 1475 | count, count, NFS_FILE_SYNC); |
| 1476 | |
| 1477 | pnfs_generic_write_commit_done(task, data); |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | static void ff_layout_commit_count_stats(struct rpc_task *task, void *data) |
| 1481 | { |
| 1482 | struct nfs_commit_data *cdata = data; |
| 1483 | |
| 1484 | rpc_count_iostats_metrics(task, |
| 1485 | &NFS_CLIENT(cdata->inode)->cl_metrics[NFSPROC4_CLNT_COMMIT]); |
| 1486 | } |
| 1487 | |
| 1488 | static const struct rpc_call_ops ff_layout_read_call_ops_v3 = { |
| 1489 | .rpc_call_prepare = ff_layout_read_prepare_v3, |
| 1490 | .rpc_call_done = ff_layout_read_call_done, |
| 1491 | .rpc_count_stats = ff_layout_read_count_stats, |
| 1492 | .rpc_release = pnfs_generic_rw_release, |
| 1493 | }; |
| 1494 | |
| 1495 | static const struct rpc_call_ops ff_layout_read_call_ops_v4 = { |
| 1496 | .rpc_call_prepare = ff_layout_read_prepare_v4, |
| 1497 | .rpc_call_done = ff_layout_read_call_done, |
| 1498 | .rpc_count_stats = ff_layout_read_count_stats, |
| 1499 | .rpc_release = pnfs_generic_rw_release, |
| 1500 | }; |
| 1501 | |
| 1502 | static const struct rpc_call_ops ff_layout_write_call_ops_v3 = { |
| 1503 | .rpc_call_prepare = ff_layout_write_prepare_v3, |
| 1504 | .rpc_call_done = ff_layout_write_call_done, |
| 1505 | .rpc_count_stats = ff_layout_write_count_stats, |
| 1506 | .rpc_release = pnfs_generic_rw_release, |
| 1507 | }; |
| 1508 | |
| 1509 | static const struct rpc_call_ops ff_layout_write_call_ops_v4 = { |
| 1510 | .rpc_call_prepare = ff_layout_write_prepare_v4, |
| 1511 | .rpc_call_done = ff_layout_write_call_done, |
| 1512 | .rpc_count_stats = ff_layout_write_count_stats, |
| 1513 | .rpc_release = pnfs_generic_rw_release, |
| 1514 | }; |
| 1515 | |
| 1516 | static const struct rpc_call_ops ff_layout_commit_call_ops_v3 = { |
| 1517 | .rpc_call_prepare = ff_layout_commit_prepare_v3, |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1518 | .rpc_call_done = ff_layout_commit_done, |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1519 | .rpc_count_stats = ff_layout_commit_count_stats, |
| 1520 | .rpc_release = pnfs_generic_commit_release, |
| 1521 | }; |
| 1522 | |
| 1523 | static const struct rpc_call_ops ff_layout_commit_call_ops_v4 = { |
| 1524 | .rpc_call_prepare = ff_layout_commit_prepare_v4, |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1525 | .rpc_call_done = ff_layout_commit_done, |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1526 | .rpc_count_stats = ff_layout_commit_count_stats, |
| 1527 | .rpc_release = pnfs_generic_commit_release, |
| 1528 | }; |
| 1529 | |
| 1530 | static enum pnfs_try_status |
| 1531 | ff_layout_read_pagelist(struct nfs_pgio_header *hdr) |
| 1532 | { |
| 1533 | struct pnfs_layout_segment *lseg = hdr->lseg; |
| 1534 | struct nfs4_pnfs_ds *ds; |
| 1535 | struct rpc_clnt *ds_clnt; |
| 1536 | struct rpc_cred *ds_cred; |
| 1537 | loff_t offset = hdr->args.offset; |
| 1538 | u32 idx = hdr->pgio_mirror_idx; |
| 1539 | int vers; |
| 1540 | struct nfs_fh *fh; |
| 1541 | |
| 1542 | dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n", |
| 1543 | __func__, hdr->inode->i_ino, |
| 1544 | hdr->args.pgbase, (size_t)hdr->args.count, offset); |
| 1545 | |
| 1546 | ds = nfs4_ff_layout_prepare_ds(lseg, idx, false); |
| 1547 | if (!ds) |
| 1548 | goto out_failed; |
| 1549 | |
| 1550 | ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp, |
| 1551 | hdr->inode); |
| 1552 | if (IS_ERR(ds_clnt)) |
| 1553 | goto out_failed; |
| 1554 | |
| 1555 | ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred); |
| 1556 | if (IS_ERR(ds_cred)) |
| 1557 | goto out_failed; |
| 1558 | |
| 1559 | vers = nfs4_ff_layout_ds_version(lseg, idx); |
| 1560 | |
| 1561 | dprintk("%s USE DS: %s cl_count %d vers %d\n", __func__, |
| 1562 | ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count), vers); |
| 1563 | |
| 1564 | atomic_inc(&ds->ds_clp->cl_count); |
| 1565 | hdr->ds_clp = ds->ds_clp; |
| 1566 | fh = nfs4_ff_layout_select_ds_fh(lseg, idx); |
| 1567 | if (fh) |
| 1568 | hdr->args.fh = fh; |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1569 | /* |
| 1570 | * Note that if we ever decide to split across DSes, |
| 1571 | * then we may need to handle dense-like offsets. |
| 1572 | */ |
| 1573 | hdr->args.offset = offset; |
| 1574 | hdr->mds_offset = offset; |
| 1575 | |
| 1576 | /* Perform an asynchronous read to ds */ |
| 1577 | nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, |
| 1578 | vers == 3 ? &ff_layout_read_call_ops_v3 : |
| 1579 | &ff_layout_read_call_ops_v4, |
| 1580 | 0, RPC_TASK_SOFTCONN); |
| 1581 | |
| 1582 | return PNFS_ATTEMPTED; |
| 1583 | |
| 1584 | out_failed: |
| 1585 | if (ff_layout_has_available_ds(lseg)) |
| 1586 | return PNFS_TRY_AGAIN; |
| 1587 | return PNFS_NOT_ATTEMPTED; |
| 1588 | } |
| 1589 | |
| 1590 | /* Perform async writes. */ |
| 1591 | static enum pnfs_try_status |
| 1592 | ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync) |
| 1593 | { |
| 1594 | struct pnfs_layout_segment *lseg = hdr->lseg; |
| 1595 | struct nfs4_pnfs_ds *ds; |
| 1596 | struct rpc_clnt *ds_clnt; |
| 1597 | struct rpc_cred *ds_cred; |
| 1598 | loff_t offset = hdr->args.offset; |
| 1599 | int vers; |
| 1600 | struct nfs_fh *fh; |
| 1601 | int idx = hdr->pgio_mirror_idx; |
| 1602 | |
| 1603 | ds = nfs4_ff_layout_prepare_ds(lseg, idx, true); |
| 1604 | if (!ds) |
| 1605 | return PNFS_NOT_ATTEMPTED; |
| 1606 | |
| 1607 | ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp, |
| 1608 | hdr->inode); |
| 1609 | if (IS_ERR(ds_clnt)) |
| 1610 | return PNFS_NOT_ATTEMPTED; |
| 1611 | |
| 1612 | ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred); |
| 1613 | if (IS_ERR(ds_cred)) |
| 1614 | return PNFS_NOT_ATTEMPTED; |
| 1615 | |
| 1616 | vers = nfs4_ff_layout_ds_version(lseg, idx); |
| 1617 | |
| 1618 | dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s cl_count %d vers %d\n", |
| 1619 | __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count, |
| 1620 | offset, ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count), |
| 1621 | vers); |
| 1622 | |
| 1623 | hdr->pgio_done_cb = ff_layout_write_done_cb; |
| 1624 | atomic_inc(&ds->ds_clp->cl_count); |
| 1625 | hdr->ds_clp = ds->ds_clp; |
| 1626 | hdr->ds_commit_idx = idx; |
| 1627 | fh = nfs4_ff_layout_select_ds_fh(lseg, idx); |
| 1628 | if (fh) |
| 1629 | hdr->args.fh = fh; |
| 1630 | |
| 1631 | /* |
| 1632 | * Note that if we ever decide to split across DSes, |
| 1633 | * then we may need to handle dense-like offsets. |
| 1634 | */ |
| 1635 | hdr->args.offset = offset; |
| 1636 | |
| 1637 | /* Perform an asynchronous write */ |
| 1638 | nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, |
| 1639 | vers == 3 ? &ff_layout_write_call_ops_v3 : |
| 1640 | &ff_layout_write_call_ops_v4, |
| 1641 | sync, RPC_TASK_SOFTCONN); |
| 1642 | return PNFS_ATTEMPTED; |
| 1643 | } |
| 1644 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1645 | static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i) |
| 1646 | { |
| 1647 | return i; |
| 1648 | } |
| 1649 | |
| 1650 | static struct nfs_fh * |
| 1651 | select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i) |
| 1652 | { |
| 1653 | struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg); |
| 1654 | |
| 1655 | /* FIXME: Assume that there is only one NFS version available |
| 1656 | * for the DS. |
| 1657 | */ |
| 1658 | return &flseg->mirror_array[i]->fh_versions[0]; |
| 1659 | } |
| 1660 | |
| 1661 | static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how) |
| 1662 | { |
| 1663 | struct pnfs_layout_segment *lseg = data->lseg; |
| 1664 | struct nfs4_pnfs_ds *ds; |
| 1665 | struct rpc_clnt *ds_clnt; |
| 1666 | struct rpc_cred *ds_cred; |
| 1667 | u32 idx; |
| 1668 | int vers; |
| 1669 | struct nfs_fh *fh; |
| 1670 | |
| 1671 | idx = calc_ds_index_from_commit(lseg, data->ds_commit_index); |
| 1672 | ds = nfs4_ff_layout_prepare_ds(lseg, idx, true); |
| 1673 | if (!ds) |
| 1674 | goto out_err; |
| 1675 | |
| 1676 | ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp, |
| 1677 | data->inode); |
| 1678 | if (IS_ERR(ds_clnt)) |
| 1679 | goto out_err; |
| 1680 | |
| 1681 | ds_cred = ff_layout_get_ds_cred(lseg, idx, data->cred); |
| 1682 | if (IS_ERR(ds_cred)) |
| 1683 | goto out_err; |
| 1684 | |
| 1685 | vers = nfs4_ff_layout_ds_version(lseg, idx); |
| 1686 | |
| 1687 | dprintk("%s ino %lu, how %d cl_count %d vers %d\n", __func__, |
| 1688 | data->inode->i_ino, how, atomic_read(&ds->ds_clp->cl_count), |
| 1689 | vers); |
| 1690 | data->commit_done_cb = ff_layout_commit_done_cb; |
| 1691 | data->cred = ds_cred; |
| 1692 | atomic_inc(&ds->ds_clp->cl_count); |
| 1693 | data->ds_clp = ds->ds_clp; |
| 1694 | fh = select_ds_fh_from_commit(lseg, data->ds_commit_index); |
| 1695 | if (fh) |
| 1696 | data->args.fh = fh; |
Trond Myklebust | abcb7bf | 2015-06-23 19:51:59 +0800 | [diff] [blame] | 1697 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1698 | return nfs_initiate_commit(ds_clnt, data, ds->ds_clp->rpc_ops, |
| 1699 | vers == 3 ? &ff_layout_commit_call_ops_v3 : |
| 1700 | &ff_layout_commit_call_ops_v4, |
| 1701 | how, RPC_TASK_SOFTCONN); |
| 1702 | out_err: |
| 1703 | pnfs_generic_prepare_to_resend_writes(data); |
| 1704 | pnfs_generic_commit_release(data); |
| 1705 | return -EAGAIN; |
| 1706 | } |
| 1707 | |
| 1708 | static int |
| 1709 | ff_layout_commit_pagelist(struct inode *inode, struct list_head *mds_pages, |
| 1710 | int how, struct nfs_commit_info *cinfo) |
| 1711 | { |
| 1712 | return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo, |
| 1713 | ff_layout_initiate_commit); |
| 1714 | } |
| 1715 | |
| 1716 | static struct pnfs_ds_commit_info * |
| 1717 | ff_layout_get_ds_info(struct inode *inode) |
| 1718 | { |
| 1719 | struct pnfs_layout_hdr *layout = NFS_I(inode)->layout; |
| 1720 | |
| 1721 | if (layout == NULL) |
| 1722 | return NULL; |
| 1723 | |
| 1724 | return &FF_LAYOUT_FROM_HDR(layout)->commit_info; |
| 1725 | } |
| 1726 | |
| 1727 | static void |
Trond Myklebust | fc87701 | 2015-03-09 17:25:14 -0400 | [diff] [blame] | 1728 | ff_layout_free_deviceid_node(struct nfs4_deviceid_node *d) |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 1729 | { |
| 1730 | nfs4_ff_layout_free_deviceid(container_of(d, struct nfs4_ff_layout_ds, |
| 1731 | id_node)); |
| 1732 | } |
| 1733 | |
| 1734 | static int ff_layout_encode_ioerr(struct nfs4_flexfile_layout *flo, |
| 1735 | struct xdr_stream *xdr, |
| 1736 | const struct nfs4_layoutreturn_args *args) |
| 1737 | { |
| 1738 | struct pnfs_layout_hdr *hdr = &flo->generic_hdr; |
| 1739 | __be32 *start; |
| 1740 | int count = 0, ret = 0; |
| 1741 | |
| 1742 | start = xdr_reserve_space(xdr, 4); |
| 1743 | if (unlikely(!start)) |
| 1744 | return -E2BIG; |
| 1745 | |
| 1746 | /* This assume we always return _ALL_ layouts */ |
| 1747 | spin_lock(&hdr->plh_inode->i_lock); |
| 1748 | ret = ff_layout_encode_ds_ioerr(flo, xdr, &count, &args->range); |
| 1749 | spin_unlock(&hdr->plh_inode->i_lock); |
| 1750 | |
| 1751 | *start = cpu_to_be32(count); |
| 1752 | |
| 1753 | return ret; |
| 1754 | } |
| 1755 | |
| 1756 | /* report nothing for now */ |
| 1757 | static void ff_layout_encode_iostats(struct nfs4_flexfile_layout *flo, |
| 1758 | struct xdr_stream *xdr, |
| 1759 | const struct nfs4_layoutreturn_args *args) |
| 1760 | { |
| 1761 | __be32 *p; |
| 1762 | |
| 1763 | p = xdr_reserve_space(xdr, 4); |
| 1764 | if (likely(p)) |
| 1765 | *p = cpu_to_be32(0); |
| 1766 | } |
| 1767 | |
| 1768 | static struct nfs4_deviceid_node * |
| 1769 | ff_layout_alloc_deviceid_node(struct nfs_server *server, |
| 1770 | struct pnfs_device *pdev, gfp_t gfp_flags) |
| 1771 | { |
| 1772 | struct nfs4_ff_layout_ds *dsaddr; |
| 1773 | |
| 1774 | dsaddr = nfs4_ff_alloc_deviceid_node(server, pdev, gfp_flags); |
| 1775 | if (!dsaddr) |
| 1776 | return NULL; |
| 1777 | return &dsaddr->id_node; |
| 1778 | } |
| 1779 | |
| 1780 | static void |
| 1781 | ff_layout_encode_layoutreturn(struct pnfs_layout_hdr *lo, |
| 1782 | struct xdr_stream *xdr, |
| 1783 | const struct nfs4_layoutreturn_args *args) |
| 1784 | { |
| 1785 | struct nfs4_flexfile_layout *flo = FF_LAYOUT_FROM_HDR(lo); |
| 1786 | __be32 *start; |
| 1787 | |
| 1788 | dprintk("%s: Begin\n", __func__); |
| 1789 | start = xdr_reserve_space(xdr, 4); |
| 1790 | BUG_ON(!start); |
| 1791 | |
| 1792 | if (ff_layout_encode_ioerr(flo, xdr, args)) |
| 1793 | goto out; |
| 1794 | |
| 1795 | ff_layout_encode_iostats(flo, xdr, args); |
| 1796 | out: |
| 1797 | *start = cpu_to_be32((xdr->p - start - 1) * 4); |
| 1798 | dprintk("%s: Return\n", __func__); |
| 1799 | } |
| 1800 | |
Peng Tao | 27c4306 | 2015-06-23 19:52:02 +0800 | [diff] [blame] | 1801 | static int |
| 1802 | ff_layout_ntop4(const struct sockaddr *sap, char *buf, const size_t buflen) |
| 1803 | { |
| 1804 | const struct sockaddr_in *sin = (struct sockaddr_in *)sap; |
| 1805 | |
| 1806 | return snprintf(buf, buflen, "%pI4", &sin->sin_addr); |
| 1807 | } |
| 1808 | |
| 1809 | static size_t |
| 1810 | ff_layout_ntop6_noscopeid(const struct sockaddr *sap, char *buf, |
| 1811 | const int buflen) |
| 1812 | { |
| 1813 | const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; |
| 1814 | const struct in6_addr *addr = &sin6->sin6_addr; |
| 1815 | |
| 1816 | /* |
| 1817 | * RFC 4291, Section 2.2.2 |
| 1818 | * |
| 1819 | * Shorthanded ANY address |
| 1820 | */ |
| 1821 | if (ipv6_addr_any(addr)) |
| 1822 | return snprintf(buf, buflen, "::"); |
| 1823 | |
| 1824 | /* |
| 1825 | * RFC 4291, Section 2.2.2 |
| 1826 | * |
| 1827 | * Shorthanded loopback address |
| 1828 | */ |
| 1829 | if (ipv6_addr_loopback(addr)) |
| 1830 | return snprintf(buf, buflen, "::1"); |
| 1831 | |
| 1832 | /* |
| 1833 | * RFC 4291, Section 2.2.3 |
| 1834 | * |
| 1835 | * Special presentation address format for mapped v4 |
| 1836 | * addresses. |
| 1837 | */ |
| 1838 | if (ipv6_addr_v4mapped(addr)) |
| 1839 | return snprintf(buf, buflen, "::ffff:%pI4", |
| 1840 | &addr->s6_addr32[3]); |
| 1841 | |
| 1842 | /* |
| 1843 | * RFC 4291, Section 2.2.1 |
| 1844 | */ |
| 1845 | return snprintf(buf, buflen, "%pI6c", addr); |
| 1846 | } |
| 1847 | |
| 1848 | /* Derived from rpc_sockaddr2uaddr */ |
| 1849 | static void |
| 1850 | ff_layout_encode_netaddr(struct xdr_stream *xdr, struct nfs4_pnfs_ds_addr *da) |
| 1851 | { |
| 1852 | struct sockaddr *sap = (struct sockaddr *)&da->da_addr; |
| 1853 | char portbuf[RPCBIND_MAXUADDRPLEN]; |
| 1854 | char addrbuf[RPCBIND_MAXUADDRLEN]; |
| 1855 | char *netid; |
| 1856 | unsigned short port; |
| 1857 | int len, netid_len; |
| 1858 | __be32 *p; |
| 1859 | |
| 1860 | switch (sap->sa_family) { |
| 1861 | case AF_INET: |
| 1862 | if (ff_layout_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0) |
| 1863 | return; |
| 1864 | port = ntohs(((struct sockaddr_in *)sap)->sin_port); |
| 1865 | netid = "tcp"; |
| 1866 | netid_len = 3; |
| 1867 | break; |
| 1868 | case AF_INET6: |
| 1869 | if (ff_layout_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0) |
| 1870 | return; |
| 1871 | port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port); |
| 1872 | netid = "tcp6"; |
| 1873 | netid_len = 4; |
| 1874 | break; |
| 1875 | default: |
| 1876 | /* we only support tcp and tcp6 */ |
| 1877 | WARN_ON_ONCE(1); |
| 1878 | return; |
| 1879 | } |
| 1880 | |
| 1881 | snprintf(portbuf, sizeof(portbuf), ".%u.%u", port >> 8, port & 0xff); |
| 1882 | len = strlcat(addrbuf, portbuf, sizeof(addrbuf)); |
| 1883 | |
| 1884 | p = xdr_reserve_space(xdr, 4 + netid_len); |
| 1885 | xdr_encode_opaque(p, netid, netid_len); |
| 1886 | |
| 1887 | p = xdr_reserve_space(xdr, 4 + len); |
| 1888 | xdr_encode_opaque(p, addrbuf, len); |
| 1889 | } |
| 1890 | |
| 1891 | static void |
| 1892 | ff_layout_encode_nfstime(struct xdr_stream *xdr, |
| 1893 | ktime_t t) |
| 1894 | { |
| 1895 | struct timespec64 ts; |
| 1896 | __be32 *p; |
| 1897 | |
| 1898 | p = xdr_reserve_space(xdr, 12); |
| 1899 | ts = ktime_to_timespec64(t); |
| 1900 | p = xdr_encode_hyper(p, ts.tv_sec); |
| 1901 | *p++ = cpu_to_be32(ts.tv_nsec); |
| 1902 | } |
| 1903 | |
| 1904 | static void |
| 1905 | ff_layout_encode_io_latency(struct xdr_stream *xdr, |
| 1906 | struct nfs4_ff_io_stat *stat) |
| 1907 | { |
| 1908 | __be32 *p; |
| 1909 | |
| 1910 | p = xdr_reserve_space(xdr, 5 * 8); |
| 1911 | p = xdr_encode_hyper(p, stat->ops_requested); |
| 1912 | p = xdr_encode_hyper(p, stat->bytes_requested); |
| 1913 | p = xdr_encode_hyper(p, stat->ops_completed); |
| 1914 | p = xdr_encode_hyper(p, stat->bytes_completed); |
| 1915 | p = xdr_encode_hyper(p, stat->bytes_not_delivered); |
| 1916 | ff_layout_encode_nfstime(xdr, stat->total_busy_time); |
| 1917 | ff_layout_encode_nfstime(xdr, stat->aggregate_completion_time); |
| 1918 | } |
| 1919 | |
| 1920 | static void |
| 1921 | ff_layout_encode_layoutstats(struct xdr_stream *xdr, |
| 1922 | struct nfs42_layoutstat_args *args, |
| 1923 | struct nfs42_layoutstat_devinfo *devinfo) |
| 1924 | { |
| 1925 | struct nfs4_ff_layout_mirror *mirror = devinfo->layout_private; |
| 1926 | struct nfs4_pnfs_ds_addr *da; |
| 1927 | struct nfs4_pnfs_ds *ds = mirror->mirror_ds->ds; |
| 1928 | struct nfs_fh *fh = &mirror->fh_versions[0]; |
| 1929 | __be32 *p, *start; |
| 1930 | |
| 1931 | da = list_first_entry(&ds->ds_addrs, struct nfs4_pnfs_ds_addr, da_node); |
| 1932 | dprintk("%s: DS %s: encoding address %s\n", |
| 1933 | __func__, ds->ds_remotestr, da->da_remotestr); |
| 1934 | /* layoutupdate length */ |
| 1935 | start = xdr_reserve_space(xdr, 4); |
| 1936 | /* netaddr4 */ |
| 1937 | ff_layout_encode_netaddr(xdr, da); |
| 1938 | /* nfs_fh4 */ |
| 1939 | p = xdr_reserve_space(xdr, 4 + fh->size); |
| 1940 | xdr_encode_opaque(p, fh->data, fh->size); |
| 1941 | /* ff_io_latency4 read */ |
| 1942 | spin_lock(&mirror->lock); |
| 1943 | ff_layout_encode_io_latency(xdr, &mirror->read_stat.io_stat); |
| 1944 | /* ff_io_latency4 write */ |
| 1945 | ff_layout_encode_io_latency(xdr, &mirror->write_stat.io_stat); |
| 1946 | spin_unlock(&mirror->lock); |
| 1947 | /* nfstime4 */ |
| 1948 | ff_layout_encode_nfstime(xdr, ktime_sub(ktime_get(), mirror->start_time)); |
| 1949 | /* bool */ |
| 1950 | p = xdr_reserve_space(xdr, 4); |
| 1951 | *p = cpu_to_be32(false); |
| 1952 | |
| 1953 | *start = cpu_to_be32((xdr->p - start - 1) * 4); |
| 1954 | } |
| 1955 | |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 1956 | static int |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1957 | ff_layout_mirror_prepare_stats(struct nfs42_layoutstat_args *args, |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 1958 | struct pnfs_layout_hdr *lo, |
| 1959 | int dev_limit) |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1960 | { |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 1961 | struct nfs4_flexfile_layout *ff_layout = FF_LAYOUT_FROM_HDR(lo); |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1962 | struct nfs4_ff_layout_mirror *mirror; |
| 1963 | struct nfs4_deviceid_node *dev; |
| 1964 | struct nfs42_layoutstat_devinfo *devinfo; |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 1965 | int i = 0; |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1966 | |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 1967 | list_for_each_entry(mirror, &ff_layout->mirrors, mirrors) { |
| 1968 | if (i >= dev_limit) |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1969 | break; |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 1970 | if (!mirror->mirror_ds) |
Peng Tao | 27c4306 | 2015-06-23 19:52:02 +0800 | [diff] [blame] | 1971 | continue; |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 1972 | /* mirror refcount put in cleanup_layoutstats */ |
| 1973 | if (!atomic_inc_not_zero(&mirror->ref)) |
| 1974 | continue; |
| 1975 | dev = &mirror->mirror_ds->id_node; |
| 1976 | devinfo = &args->devinfo[i]; |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1977 | memcpy(&devinfo->dev_id, &dev->deviceid, NFS4_DEVICEID4_SIZE); |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 1978 | devinfo->offset = 0; |
| 1979 | devinfo->length = NFS4_MAX_UINT64; |
Peng Tao | d099d7b | 2015-08-10 16:47:32 +0800 | [diff] [blame] | 1980 | devinfo->read_count = mirror->read_stat.io_stat.ops_completed; |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1981 | devinfo->read_bytes = mirror->read_stat.io_stat.bytes_completed; |
Peng Tao | d099d7b | 2015-08-10 16:47:32 +0800 | [diff] [blame] | 1982 | devinfo->write_count = mirror->write_stat.io_stat.ops_completed; |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1983 | devinfo->write_bytes = mirror->write_stat.io_stat.bytes_completed; |
| 1984 | devinfo->layout_type = LAYOUT_FLEX_FILES; |
Peng Tao | 27c4306 | 2015-06-23 19:52:02 +0800 | [diff] [blame] | 1985 | devinfo->layoutstats_encode = ff_layout_encode_layoutstats; |
| 1986 | devinfo->layout_private = mirror; |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1987 | |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 1988 | i++; |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1989 | } |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 1990 | return i; |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | static int |
| 1994 | ff_layout_prepare_layoutstats(struct nfs42_layoutstat_args *args) |
| 1995 | { |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 1996 | struct nfs4_flexfile_layout *ff_layout; |
| 1997 | struct nfs4_ff_layout_mirror *mirror; |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 1998 | int dev_count = 0; |
| 1999 | |
| 2000 | spin_lock(&args->inode->i_lock); |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 2001 | ff_layout = FF_LAYOUT_FROM_HDR(NFS_I(args->inode)->layout); |
| 2002 | list_for_each_entry(mirror, &ff_layout->mirrors, mirrors) { |
| 2003 | if (atomic_read(&mirror->ref) != 0) |
| 2004 | dev_count ++; |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 2005 | } |
| 2006 | spin_unlock(&args->inode->i_lock); |
| 2007 | /* For now, send at most PNFS_LAYOUTSTATS_MAXDEV statistics */ |
| 2008 | if (dev_count > PNFS_LAYOUTSTATS_MAXDEV) { |
| 2009 | dprintk("%s: truncating devinfo to limit (%d:%d)\n", |
| 2010 | __func__, dev_count, PNFS_LAYOUTSTATS_MAXDEV); |
| 2011 | dev_count = PNFS_LAYOUTSTATS_MAXDEV; |
| 2012 | } |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 2013 | args->devinfo = kmalloc_array(dev_count, sizeof(*args->devinfo), GFP_NOIO); |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 2014 | if (!args->devinfo) |
| 2015 | return -ENOMEM; |
| 2016 | |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 2017 | spin_lock(&args->inode->i_lock); |
Trond Myklebust | 266d12d | 2015-08-24 20:03:17 -0400 | [diff] [blame^] | 2018 | args->num_dev = ff_layout_mirror_prepare_stats(args, |
| 2019 | &ff_layout->generic_hdr, dev_count); |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 2020 | spin_unlock(&args->inode->i_lock); |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 2021 | |
| 2022 | return 0; |
| 2023 | } |
| 2024 | |
Peng Tao | 27c4306 | 2015-06-23 19:52:02 +0800 | [diff] [blame] | 2025 | static void |
| 2026 | ff_layout_cleanup_layoutstats(struct nfs42_layoutstat_data *data) |
| 2027 | { |
| 2028 | struct nfs4_ff_layout_mirror *mirror; |
| 2029 | int i; |
| 2030 | |
| 2031 | for (i = 0; i < data->args.num_dev; i++) { |
| 2032 | mirror = data->args.devinfo[i].layout_private; |
| 2033 | data->args.devinfo[i].layout_private = NULL; |
Trond Myklebust | 0b7baf9 | 2015-08-24 18:22:28 -0400 | [diff] [blame] | 2034 | ff_layout_put_mirror(mirror); |
Peng Tao | 27c4306 | 2015-06-23 19:52:02 +0800 | [diff] [blame] | 2035 | } |
| 2036 | } |
| 2037 | |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 2038 | static struct pnfs_layoutdriver_type flexfilelayout_type = { |
| 2039 | .id = LAYOUT_FLEX_FILES, |
| 2040 | .name = "LAYOUT_FLEX_FILES", |
| 2041 | .owner = THIS_MODULE, |
| 2042 | .alloc_layout_hdr = ff_layout_alloc_layout_hdr, |
| 2043 | .free_layout_hdr = ff_layout_free_layout_hdr, |
| 2044 | .alloc_lseg = ff_layout_alloc_lseg, |
| 2045 | .free_lseg = ff_layout_free_lseg, |
| 2046 | .pg_read_ops = &ff_layout_pg_read_ops, |
| 2047 | .pg_write_ops = &ff_layout_pg_write_ops, |
| 2048 | .get_ds_info = ff_layout_get_ds_info, |
Trond Myklebust | fc87701 | 2015-03-09 17:25:14 -0400 | [diff] [blame] | 2049 | .free_deviceid_node = ff_layout_free_deviceid_node, |
Tom Haynes | 338d00c | 2015-02-17 14:58:15 -0800 | [diff] [blame] | 2050 | .mark_request_commit = pnfs_layout_mark_request_commit, |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 2051 | .clear_request_commit = pnfs_generic_clear_request_commit, |
| 2052 | .scan_commit_lists = pnfs_generic_scan_commit_lists, |
| 2053 | .recover_commit_reqs = pnfs_generic_recover_commit_reqs, |
| 2054 | .commit_pagelist = ff_layout_commit_pagelist, |
| 2055 | .read_pagelist = ff_layout_read_pagelist, |
| 2056 | .write_pagelist = ff_layout_write_pagelist, |
| 2057 | .alloc_deviceid_node = ff_layout_alloc_deviceid_node, |
| 2058 | .encode_layoutreturn = ff_layout_encode_layoutreturn, |
Trond Myklebust | 5bb89b4 | 2015-03-25 14:14:42 -0400 | [diff] [blame] | 2059 | .sync = pnfs_nfs_generic_sync, |
Peng Tao | ad4dc53e | 2015-06-23 19:52:01 +0800 | [diff] [blame] | 2060 | .prepare_layoutstats = ff_layout_prepare_layoutstats, |
Peng Tao | 27c4306 | 2015-06-23 19:52:02 +0800 | [diff] [blame] | 2061 | .cleanup_layoutstats = ff_layout_cleanup_layoutstats, |
Tom Haynes | d67ae82 | 2014-12-11 17:02:04 -0500 | [diff] [blame] | 2062 | }; |
| 2063 | |
| 2064 | static int __init nfs4flexfilelayout_init(void) |
| 2065 | { |
| 2066 | printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Registering...\n", |
| 2067 | __func__); |
| 2068 | return pnfs_register_layoutdriver(&flexfilelayout_type); |
| 2069 | } |
| 2070 | |
| 2071 | static void __exit nfs4flexfilelayout_exit(void) |
| 2072 | { |
| 2073 | printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Unregistering...\n", |
| 2074 | __func__); |
| 2075 | pnfs_unregister_layoutdriver(&flexfilelayout_type); |
| 2076 | } |
| 2077 | |
| 2078 | MODULE_ALIAS("nfs-layouttype4-4"); |
| 2079 | |
| 2080 | MODULE_LICENSE("GPL"); |
| 2081 | MODULE_DESCRIPTION("The NFSv4 flexfile layout driver"); |
| 2082 | |
| 2083 | module_init(nfs4flexfilelayout_init); |
| 2084 | module_exit(nfs4flexfilelayout_exit); |