| 1 | |
| 2 | |
| 3 | * Module for pnfs flexfile layout driver.
|
| 4 | *
|
| 5 | * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
|
| 6 | *
|
| 7 | * Tao Peng <[email protected]>
|
| 8 |
|
| 9 |
|
| 10 | #include <linux/nfs_fs.h>
|
| 11 | #include <linux/nfs_mount.h>
|
| 12 | #include <linux/nfs_page.h>
|
| 13 | #include <linux/module.h>
|
| 14 | #include <linux/file.h>
|
| 15 | #include <linux/sched/mm.h>
|
| 16 |
|
| 17 | #include <linux/sunrpc/metrics.h>
|
| 18 |
|
| 19 | #include "flexfilelayout.h"
|
| 20 | #include "../nfs4session.h"
|
| 21 | #include "../nfs4idmap.h"
|
| 22 | #include "../internal.h"
|
| 23 | #include "../delegation.h"
|
| 24 | #include "../nfs4trace.h"
|
| 25 | #include "../iostat.h"
|
| 26 | #include "../nfs.h"
|
| 27 | #include "../nfs42.h"
|
| 28 |
|
| 29 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD
|
| 30 |
|
| 31 | #define FF_LAYOUT_POLL_RETRY_MAX (15*HZ)
|
| 32 | #define FF_LAYOUTRETURN_MAXERR 20
|
| 33 |
|
| 34 | enum nfs4_ff_op_type {
|
| 35 | NFS4_FF_OP_LAYOUTSTATS,
|
| 36 | NFS4_FF_OP_LAYOUTRETURN,
|
| 37 | };
|
| 38 |
|
| 39 | static unsigned short io_maxretrans;
|
| 40 |
|
| 41 | static const struct pnfs_commit_ops ff_layout_commit_ops;
|
| 42 | static void ff_layout_read_record_layoutstats_done(struct rpc_task *task,
|
| 43 | struct nfs_pgio_header *hdr);
|
| 44 | static int
|
| 45 | ff_layout_mirror_prepare_stats(struct pnfs_layout_hdr *lo,
|
| 46 | struct nfs42_layoutstat_devinfo *devinfo,
|
| 47 | int dev_limit, enum nfs4_ff_op_type type);
|
| 48 | static void ff_layout_encode_ff_layoutupdate(struct xdr_stream *xdr,
|
| 49 | const struct nfs42_layoutstat_devinfo *devinfo,
|
| 50 | struct nfs4_ff_layout_ds_stripe *dss_info);
|
| 51 |
|
| 52 | static struct pnfs_layout_hdr *
|
| 53 | ff_layout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
|
| 54 | {
|
| 55 | struct nfs4_flexfile_layout *ffl;
|
| 56 |
|
| 57 | ffl = kzalloc_obj(*ffl, gfp_flags);
|
| 58 | if (ffl) {
|
| 59 | pnfs_init_ds_commit_info(&ffl->commit_info);
|
| 60 | INIT_LIST_HEAD(&ffl->error_list);
|
| 61 | INIT_LIST_HEAD(&ffl->mirrors);
|
| 62 | ffl->last_report_time = ktime_get();
|
| 63 | ffl->commit_info.ops = &ff_layout_commit_ops;
|
| 64 | return &ffl->generic_hdr;
|
| 65 | } else
|
| 66 | return NULL;
|
| 67 | }
|
| 68 |
|
| 69 | static void
|
| 70 | ff_layout_free_layout_hdr(struct pnfs_layout_hdr *lo)
|
| 71 | {
|
| 72 | struct nfs4_flexfile_layout *ffl = FF_LAYOUT_FROM_HDR(lo);
|
| 73 | struct nfs4_ff_layout_ds_err *err, *n;
|
| 74 |
|
| 75 | list_for_each_entry_safe(err, n, &ffl->error_list, list) {
|
| 76 | list_del(&err->list);
|
| 77 | kfree(err);
|
| 78 | }
|
| 79 | kfree_rcu(ffl, generic_hdr.plh_rcu);
|
| 80 | }
|
| 81 |
|
| 82 | static int decode_pnfs_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
|
| 83 | {
|
| 84 | __be32 *p;
|
| 85 |
|
| 86 | p = xdr_inline_decode(xdr, NFS4_STATEID_SIZE);
|
| 87 | if (unlikely(p == NULL))
|
| 88 | return -ENOBUFS;
|
| 89 | stateid->type = NFS4_PNFS_DS_STATEID_TYPE;
|
| 90 | memcpy(stateid->data, p, NFS4_STATEID_SIZE);
|
| 91 | dprintk("%s: stateid id= [%x%x%x%x]\n", __func__,
|
| 92 | p[0], p[1], p[2], p[3]);
|
| 93 | return 0;
|
| 94 | }
|
| 95 |
|
| 96 | static int decode_deviceid(struct xdr_stream *xdr, struct nfs4_deviceid *devid)
|
| 97 | {
|
| 98 | __be32 *p;
|
| 99 |
|
| 100 | p = xdr_inline_decode(xdr, NFS4_DEVICEID4_SIZE);
|
| 101 | if (unlikely(!p))
|
| 102 | return -ENOBUFS;
|
| 103 | memcpy(devid, p, NFS4_DEVICEID4_SIZE);
|
| 104 | nfs4_print_deviceid(devid);
|
| 105 | return 0;
|
| 106 | }
|
| 107 |
|
| 108 | static int decode_nfs_fh(struct xdr_stream *xdr, struct nfs_fh *fh)
|
| 109 | {
|
| 110 | __be32 *p;
|
| 111 |
|
| 112 | p = xdr_inline_decode(xdr, 4);
|
| 113 | if (unlikely(!p))
|
| 114 | return -ENOBUFS;
|
| 115 | fh->size = be32_to_cpup(p++);
|
| 116 | if (fh->size > NFS_MAXFHSIZE) {
|
| 117 | printk(KERN_ERR "NFS flexfiles: Too big fh received %d\n",
|
| 118 | fh->size);
|
| 119 | return -EOVERFLOW;
|
| 120 | }
|
| 121 |
|
| 122 | p = xdr_inline_decode(xdr, fh->size);
|
| 123 | if (unlikely(!p))
|
| 124 | return -ENOBUFS;
|
| 125 | memcpy(&fh->data, p, fh->size);
|
| 126 | dprintk("%s: fh len %d\n", __func__, fh->size);
|
| 127 |
|
| 128 | return 0;
|
| 129 | }
|
| 130 |
|
| 131 | |
| 132 | * Currently only stringified uids and gids are accepted.
|
| 133 | * I.e., kerberos is not supported to the DSes, so no pricipals.
|
| 134 | *
|
| 135 | * That means that one common function will suffice, but when
|
| 136 | * principals are added, this should be split to accomodate
|
| 137 | * calls to both nfs_map_name_to_uid() and nfs_map_group_to_gid().
|
| 138 |
|
| 139 | static int
|
| 140 | decode_name(struct xdr_stream *xdr, u32 *id)
|
| 141 | {
|
| 142 | __be32 *p;
|
| 143 | int len;
|
| 144 |
|
| 145 |
|
| 146 | p = xdr_inline_decode(xdr, 4);
|
| 147 | if (unlikely(!p))
|
| 148 | return -ENOBUFS;
|
| 149 | len = be32_to_cpup(p++);
|
| 150 | if (len < 0)
|
| 151 | return -EINVAL;
|
| 152 |
|
| 153 | dprintk("%s: len %u\n", __func__, len);
|
| 154 |
|
| 155 |
|
| 156 | p = xdr_inline_decode(xdr, len);
|
| 157 | if (unlikely(!p))
|
| 158 | return -ENOBUFS;
|
| 159 |
|
| 160 | if (!nfs_map_string_to_numeric((char *)p, len, id))
|
| 161 | return -EINVAL;
|
| 162 |
|
| 163 | return 0;
|
| 164 | }
|
| 165 |
|
| 166 | static struct nfsd_file *
|
| 167 | ff_local_open_fh(struct pnfs_layout_segment *lseg, u32 ds_idx, u32 dss_id,
|
| 168 | struct nfs_client *clp, const struct cred *cred,
|
| 169 | struct nfs_fh *fh, fmode_t mode)
|
| 170 | {
|
| 171 | #if IS_ENABLED(CONFIG_NFS_LOCALIO)
|
| 172 | struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx);
|
| 173 |
|
| 174 | return nfs_local_open_fh(clp, cred, fh, &mirror->dss[dss_id].nfl, mode);
|
| 175 | #else
|
| 176 | return NULL;
|
| 177 | #endif
|
| 178 | }
|
| 179 |
|
| 180 | static bool ff_dss_match_fh(const struct nfs4_ff_layout_ds_stripe *dss1,
|
| 181 | const struct nfs4_ff_layout_ds_stripe *dss2)
|
| 182 | {
|
| 183 | int i, j;
|
| 184 |
|
| 185 | if (dss1->fh_versions_cnt != dss2->fh_versions_cnt)
|
| 186 | return false;
|
| 187 |
|
| 188 | for (i = 0; i < dss1->fh_versions_cnt; i++) {
|
| 189 | bool found_fh = false;
|
| 190 | for (j = 0; j < dss2->fh_versions_cnt; j++) {
|
| 191 | if (nfs_compare_fh(&dss1->fh_versions[i],
|
| 192 | &dss2->fh_versions[j]) == 0) {
|
| 193 | found_fh = true;
|
| 194 | break;
|
| 195 | }
|
| 196 | }
|
| 197 | if (!found_fh)
|
| 198 | return false;
|
| 199 | }
|
| 200 | return true;
|
| 201 | }
|
| 202 |
|
| 203 | static bool ff_mirror_match_fh(const struct nfs4_ff_layout_mirror *m1,
|
| 204 | const struct nfs4_ff_layout_mirror *m2)
|
| 205 | {
|
| 206 | u32 dss_id;
|
| 207 |
|
| 208 | if (m1->dss_count != m2->dss_count)
|
| 209 | return false;
|
| 210 |
|
| 211 | for (dss_id = 0; dss_id < m1->dss_count; dss_id++)
|
| 212 | if (!ff_dss_match_fh(&m1->dss[dss_id], &m2->dss[dss_id]))
|
| 213 | return false;
|
| 214 |
|
| 215 | return true;
|
| 216 | }
|
| 217 |
|
| 218 | static bool ff_mirror_match_devid(const struct nfs4_ff_layout_mirror *m1,
|
| 219 | const struct nfs4_ff_layout_mirror *m2)
|
| 220 | {
|
| 221 | u32 dss_id;
|
| 222 |
|
| 223 | if (m1->dss_count != m2->dss_count)
|
| 224 | return false;
|
| 225 |
|
| 226 | for (dss_id = 0; dss_id < m1->dss_count; dss_id++)
|
| 227 | if (memcmp(&m1->dss[dss_id].devid,
|
| 228 | &m2->dss[dss_id].devid,
|
| 229 | sizeof(m1->dss[dss_id].devid)) != 0)
|
| 230 | return false;
|
| 231 |
|
| 232 | return true;
|
| 233 | }
|
| 234 |
|
| 235 | static struct nfs4_ff_layout_mirror *
|
| 236 | ff_layout_add_mirror(struct pnfs_layout_hdr *lo,
|
| 237 | struct nfs4_ff_layout_mirror *mirror)
|
| 238 | {
|
| 239 | struct nfs4_flexfile_layout *ff_layout = FF_LAYOUT_FROM_HDR(lo);
|
| 240 | struct nfs4_ff_layout_mirror *pos;
|
| 241 | struct inode *inode = lo->plh_inode;
|
| 242 |
|
| 243 | spin_lock(&inode->i_lock);
|
| 244 | list_for_each_entry(pos, &ff_layout->mirrors, mirrors) {
|
| 245 | if (!ff_mirror_match_devid(mirror, pos))
|
| 246 | continue;
|
| 247 | if (!ff_mirror_match_fh(mirror, pos))
|
| 248 | continue;
|
| 249 | if (refcount_inc_not_zero(&pos->ref)) {
|
| 250 | spin_unlock(&inode->i_lock);
|
| 251 | return pos;
|
| 252 | }
|
| 253 | }
|
| 254 | list_add(&mirror->mirrors, &ff_layout->mirrors);
|
| 255 | mirror->layout = lo;
|
| 256 | spin_unlock(&inode->i_lock);
|
| 257 | return mirror;
|
| 258 | }
|
| 259 |
|
| 260 | static void
|
| 261 | ff_layout_remove_mirror(struct nfs4_ff_layout_mirror *mirror)
|
| 262 | {
|
| 263 | struct inode *inode;
|
| 264 | if (mirror->layout == NULL)
|
| 265 | return;
|
| 266 | inode = mirror->layout->plh_inode;
|
| 267 | spin_lock(&inode->i_lock);
|
| 268 | list_del(&mirror->mirrors);
|
| 269 | spin_unlock(&inode->i_lock);
|
| 270 | mirror->layout = NULL;
|
| 271 | }
|
| 272 |
|
| 273 | static struct nfs4_ff_layout_mirror *ff_layout_alloc_mirror(u32 dss_count,
|
| 274 | gfp_t gfp_flags)
|
| 275 | {
|
| 276 | struct nfs4_ff_layout_mirror *mirror;
|
| 277 |
|
| 278 | mirror = kzalloc_obj(*mirror, gfp_flags);
|
| 279 | if (mirror == NULL)
|
| 280 | return NULL;
|
| 281 |
|
| 282 | spin_lock_init(&mirror->lock);
|
| 283 | refcount_set(&mirror->ref, 1);
|
| 284 | INIT_LIST_HEAD(&mirror->mirrors);
|
| 285 |
|
| 286 | mirror->dss_count = dss_count;
|
| 287 | mirror->dss =
|
| 288 | kzalloc_objs(struct nfs4_ff_layout_ds_stripe, dss_count,
|
| 289 | gfp_flags);
|
| 290 | if (mirror->dss == NULL) {
|
| 291 | kfree(mirror);
|
| 292 | return NULL;
|
| 293 | }
|
| 294 |
|
| 295 | for (u32 dss_id = 0; dss_id < mirror->dss_count; dss_id++)
|
| 296 | nfs_localio_file_init(&mirror->dss[dss_id].nfl);
|
| 297 |
|
| 298 | return mirror;
|
| 299 | }
|
| 300 |
|
| 301 | static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror *mirror)
|
| 302 | {
|
| 303 | const struct cred *cred;
|
| 304 | u32 dss_id;
|
| 305 |
|
| 306 | ff_layout_remove_mirror(mirror);
|
| 307 |
|
| 308 | for (dss_id = 0; dss_id < mirror->dss_count; dss_id++) {
|
| 309 | kfree(mirror->dss[dss_id].fh_versions);
|
| 310 | cred = rcu_access_pointer(mirror->dss[dss_id].ro_cred);
|
| 311 | put_cred(cred);
|
| 312 | cred = rcu_access_pointer(mirror->dss[dss_id].rw_cred);
|
| 313 | put_cred(cred);
|
| 314 | nfs_close_local_fh(&mirror->dss[dss_id].nfl);
|
| 315 | nfs4_ff_layout_put_deviceid(mirror->dss[dss_id].mirror_ds);
|
| 316 | }
|
| 317 |
|
| 318 | kfree(mirror->dss);
|
| 319 | kfree(mirror);
|
| 320 | }
|
| 321 |
|
| 322 | static void ff_layout_put_mirror(struct nfs4_ff_layout_mirror *mirror)
|
| 323 | {
|
| 324 | if (mirror != NULL && refcount_dec_and_test(&mirror->ref))
|
| 325 | ff_layout_free_mirror(mirror);
|
| 326 | }
|
| 327 |
|
| 328 | static void ff_layout_free_mirror_array(struct nfs4_ff_layout_segment *fls)
|
| 329 | {
|
| 330 | u32 i;
|
| 331 |
|
| 332 | for (i = 0; i < fls->mirror_array_cnt; i++)
|
| 333 | ff_layout_put_mirror(fls->mirror_array[i]);
|
| 334 | }
|
| 335 |
|
| 336 | static void _ff_layout_free_lseg(struct nfs4_ff_layout_segment *fls)
|
| 337 | {
|
| 338 | if (fls) {
|
| 339 | ff_layout_free_mirror_array(fls);
|
| 340 | kfree(fls);
|
| 341 | }
|
| 342 | }
|
| 343 |
|
| 344 | static bool
|
| 345 | ff_lseg_match_mirrors(struct pnfs_layout_segment *l1,
|
| 346 | struct pnfs_layout_segment *l2)
|
| 347 | {
|
| 348 | const struct nfs4_ff_layout_segment *fl1 = FF_LAYOUT_LSEG(l1);
|
| 349 | const struct nfs4_ff_layout_segment *fl2 = FF_LAYOUT_LSEG(l2);
|
| 350 | u32 i;
|
| 351 |
|
| 352 | if (fl1->mirror_array_cnt != fl2->mirror_array_cnt)
|
| 353 | return false;
|
| 354 | for (i = 0; i < fl1->mirror_array_cnt; i++) {
|
| 355 | if (fl1->mirror_array[i] != fl2->mirror_array[i])
|
| 356 | return false;
|
| 357 | }
|
| 358 | return true;
|
| 359 | }
|
| 360 |
|
| 361 | static bool
|
| 362 | ff_lseg_range_is_after(const struct pnfs_layout_range *l1,
|
| 363 | const struct pnfs_layout_range *l2)
|
| 364 | {
|
| 365 | u64 end1, end2;
|
| 366 |
|
| 367 | if (l1->iomode != l2->iomode)
|
| 368 | return l1->iomode != IOMODE_READ;
|
| 369 | end1 = pnfs_calc_offset_end(l1->offset, l1->length);
|
| 370 | end2 = pnfs_calc_offset_end(l2->offset, l2->length);
|
| 371 | if (end1 < l2->offset)
|
| 372 | return false;
|
| 373 | if (end2 < l1->offset)
|
| 374 | return true;
|
| 375 | return l2->offset <= l1->offset;
|
| 376 | }
|
| 377 |
|
| 378 | static bool
|
| 379 | ff_lseg_merge(struct pnfs_layout_segment *new,
|
| 380 | struct pnfs_layout_segment *old)
|
| 381 | {
|
| 382 | u64 new_end, old_end;
|
| 383 |
|
| 384 | if (test_bit(NFS_LSEG_LAYOUTRETURN, &old->pls_flags))
|
| 385 | return false;
|
| 386 | if (new->pls_range.iomode != old->pls_range.iomode)
|
| 387 | return false;
|
| 388 | old_end = pnfs_calc_offset_end(old->pls_range.offset,
|
| 389 | old->pls_range.length);
|
| 390 | if (old_end < new->pls_range.offset)
|
| 391 | return false;
|
| 392 | new_end = pnfs_calc_offset_end(new->pls_range.offset,
|
| 393 | new->pls_range.length);
|
| 394 | if (new_end < old->pls_range.offset)
|
| 395 | return false;
|
| 396 | if (!ff_lseg_match_mirrors(new, old))
|
| 397 | return false;
|
| 398 |
|
| 399 |
|
| 400 | if (new_end < old_end)
|
| 401 | new_end = old_end;
|
| 402 | if (new->pls_range.offset < old->pls_range.offset)
|
| 403 | new->pls_range.offset = old->pls_range.offset;
|
| 404 | new->pls_range.length = pnfs_calc_offset_length(new->pls_range.offset,
|
| 405 | new_end);
|
| 406 | if (test_bit(NFS_LSEG_ROC, &old->pls_flags))
|
| 407 | set_bit(NFS_LSEG_ROC, &new->pls_flags);
|
| 408 | return true;
|
| 409 | }
|
| 410 |
|
| 411 | static void
|
| 412 | ff_layout_add_lseg(struct pnfs_layout_hdr *lo,
|
| 413 | struct pnfs_layout_segment *lseg,
|
| 414 | struct list_head *free_me)
|
| 415 | {
|
| 416 | pnfs_generic_layout_insert_lseg(lo, lseg,
|
| 417 | ff_lseg_range_is_after,
|
| 418 | ff_lseg_merge,
|
| 419 | free_me);
|
| 420 | }
|
| 421 |
|
| 422 | static u32 ff_mirror_efficiency_sum(const struct nfs4_ff_layout_mirror *mirror)
|
| 423 | {
|
| 424 | u32 dss_id, sum = 0;
|
| 425 |
|
| 426 | for (dss_id = 0; dss_id < mirror->dss_count; dss_id++)
|
| 427 | sum += mirror->dss[dss_id].efficiency;
|
| 428 |
|
| 429 | return sum;
|
| 430 | }
|
| 431 |
|
| 432 | static void ff_layout_sort_mirrors(struct nfs4_ff_layout_segment *fls)
|
| 433 | {
|
| 434 | int i, j;
|
| 435 |
|
| 436 | for (i = 0; i < fls->mirror_array_cnt - 1; i++) {
|
| 437 | for (j = i + 1; j < fls->mirror_array_cnt; j++)
|
| 438 | if (ff_mirror_efficiency_sum(fls->mirror_array[i]) <
|
| 439 | ff_mirror_efficiency_sum(fls->mirror_array[j]))
|
| 440 | swap(fls->mirror_array[i],
|
| 441 | fls->mirror_array[j]);
|
| 442 | }
|
| 443 | }
|
| 444 |
|
| 445 | static struct pnfs_layout_segment *
|
| 446 | ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
|
| 447 | struct nfs4_layoutget_res *lgr,
|
| 448 | gfp_t gfp_flags)
|
| 449 | {
|
| 450 | struct pnfs_layout_segment *ret;
|
| 451 | struct nfs4_ff_layout_segment *fls = NULL;
|
| 452 | struct xdr_stream stream;
|
| 453 | struct xdr_buf buf;
|
| 454 | struct folio *scratch;
|
| 455 | u64 stripe_unit;
|
| 456 | u32 mirror_array_cnt;
|
| 457 | __be32 *p;
|
| 458 | int i, rc;
|
| 459 | struct nfs4_ff_layout_ds_stripe *dss_info;
|
| 460 |
|
| 461 | dprintk("--> %s\n", __func__);
|
| 462 | scratch = folio_alloc(gfp_flags, 0);
|
| 463 | if (!scratch)
|
| 464 | return ERR_PTR(-ENOMEM);
|
| 465 |
|
| 466 | xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages,
|
| 467 | lgr->layoutp->len);
|
| 468 | xdr_set_scratch_folio(&stream, scratch);
|
| 469 |
|
| 470 |
|
| 471 | rc = -EIO;
|
| 472 | p = xdr_inline_decode(&stream, 8 + 4);
|
| 473 | if (!p)
|
| 474 | goto out_err_free;
|
| 475 |
|
| 476 | p = xdr_decode_hyper(p, &stripe_unit);
|
| 477 | mirror_array_cnt = be32_to_cpup(p++);
|
| 478 | dprintk("%s: stripe_unit=%llu mirror_array_cnt=%u\n", __func__,
|
| 479 | stripe_unit, mirror_array_cnt);
|
| 480 |
|
| 481 | if (mirror_array_cnt > NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT ||
|
| 482 | mirror_array_cnt == 0)
|
| 483 | goto out_err_free;
|
| 484 |
|
| 485 | rc = -ENOMEM;
|
| 486 | fls = kzalloc_flex(*fls, mirror_array, mirror_array_cnt, gfp_flags);
|
| 487 | if (!fls)
|
| 488 | goto out_err_free;
|
| 489 |
|
| 490 | fls->mirror_array_cnt = mirror_array_cnt;
|
| 491 | fls->stripe_unit = stripe_unit;
|
| 492 |
|
| 493 | u32 dss_count = 0;
|
| 494 | for (i = 0; i < fls->mirror_array_cnt; i++) {
|
| 495 | struct nfs4_ff_layout_mirror *mirror;
|
| 496 | struct cred *kcred;
|
| 497 | const struct cred __rcu *cred;
|
| 498 | kuid_t uid;
|
| 499 | kgid_t gid;
|
| 500 | u32 fh_count, id;
|
| 501 | int j, dss_id;
|
| 502 |
|
| 503 | rc = -EIO;
|
| 504 | p = xdr_inline_decode(&stream, 4);
|
| 505 | if (!p)
|
| 506 | goto out_err_free;
|
| 507 |
|
| 508 | |
| 509 | if (dss_count == 0)
|
| 510 | dss_count = be32_to_cpup(p);
|
| 511 | else if (dss_count != be32_to_cpup(p))
|
| 512 | goto out_err_free;
|
| 513 |
|
| 514 | if (dss_count > NFS4_FLEXFILE_LAYOUT_MAX_STRIPE_CNT ||
|
| 515 | dss_count == 0)
|
| 516 | goto out_err_free;
|
| 517 |
|
| 518 | if (dss_count > 1 && stripe_unit == 0)
|
| 519 | goto out_err_free;
|
| 520 |
|
| 521 | fls->mirror_array[i] = ff_layout_alloc_mirror(dss_count, gfp_flags);
|
| 522 | if (fls->mirror_array[i] == NULL) {
|
| 523 | rc = -ENOMEM;
|
| 524 | goto out_err_free;
|
| 525 | }
|
| 526 |
|
| 527 | for (dss_id = 0; dss_id < dss_count; dss_id++) {
|
| 528 | dss_info = &fls->mirror_array[i]->dss[dss_id];
|
| 529 | dss_info->mirror = fls->mirror_array[i];
|
| 530 |
|
| 531 |
|
| 532 | rc = decode_deviceid(&stream, &dss_info->devid);
|
| 533 | if (rc)
|
| 534 | goto out_err_free;
|
| 535 |
|
| 536 |
|
| 537 | rc = -EIO;
|
| 538 | p = xdr_inline_decode(&stream, 4);
|
| 539 | if (!p)
|
| 540 | goto out_err_free;
|
| 541 | dss_info->efficiency = be32_to_cpup(p);
|
| 542 |
|
| 543 |
|
| 544 | rc = decode_pnfs_stateid(&stream, &dss_info->stateid);
|
| 545 | if (rc)
|
| 546 | goto out_err_free;
|
| 547 |
|
| 548 |
|
| 549 | rc = -EIO;
|
| 550 | p = xdr_inline_decode(&stream, 4);
|
| 551 | if (!p)
|
| 552 | goto out_err_free;
|
| 553 | fh_count = be32_to_cpup(p);
|
| 554 | if (fh_count == 0) {
|
| 555 | rc = -EINVAL;
|
| 556 | goto out_err_free;
|
| 557 | }
|
| 558 |
|
| 559 | dss_info->fh_versions =
|
| 560 | kzalloc_objs(struct nfs_fh, fh_count, gfp_flags);
|
| 561 | if (dss_info->fh_versions == NULL) {
|
| 562 | rc = -ENOMEM;
|
| 563 | goto out_err_free;
|
| 564 | }
|
| 565 |
|
| 566 | for (j = 0; j < fh_count; j++) {
|
| 567 | rc = decode_nfs_fh(&stream,
|
| 568 | &dss_info->fh_versions[j]);
|
| 569 | if (rc)
|
| 570 | goto out_err_free;
|
| 571 | }
|
| 572 |
|
| 573 | dss_info->fh_versions_cnt = fh_count;
|
| 574 |
|
| 575 |
|
| 576 | rc = decode_name(&stream, &id);
|
| 577 | if (rc)
|
| 578 | goto out_err_free;
|
| 579 |
|
| 580 | uid = make_kuid(&init_user_ns, id);
|
| 581 |
|
| 582 |
|
| 583 | rc = decode_name(&stream, &id);
|
| 584 | if (rc)
|
| 585 | goto out_err_free;
|
| 586 |
|
| 587 | gid = make_kgid(&init_user_ns, id);
|
| 588 |
|
| 589 | if (gfp_flags & __GFP_FS)
|
| 590 | kcred = prepare_kernel_cred(&init_task);
|
| 591 | else {
|
| 592 | unsigned int nofs_flags = memalloc_nofs_save();
|
| 593 |
|
| 594 | kcred = prepare_kernel_cred(&init_task);
|
| 595 | memalloc_nofs_restore(nofs_flags);
|
| 596 | }
|
| 597 | rc = -ENOMEM;
|
| 598 | if (!kcred)
|
| 599 | goto out_err_free;
|
| 600 | kcred->fsuid = uid;
|
| 601 | kcred->fsgid = gid;
|
| 602 | cred = RCU_INITIALIZER(kcred);
|
| 603 |
|
| 604 | if (lgr->range.iomode == IOMODE_READ)
|
| 605 | rcu_assign_pointer(dss_info->ro_cred, cred);
|
| 606 | else
|
| 607 | rcu_assign_pointer(dss_info->rw_cred, cred);
|
| 608 | }
|
| 609 |
|
| 610 | mirror = ff_layout_add_mirror(lh, fls->mirror_array[i]);
|
| 611 | if (mirror != fls->mirror_array[i]) {
|
| 612 | for (dss_id = 0; dss_id < dss_count; dss_id++) {
|
| 613 | dss_info = &fls->mirror_array[i]->dss[dss_id];
|
| 614 |
|
| 615 | if (lgr->range.iomode == IOMODE_READ) {
|
| 616 | cred = xchg(&mirror->dss[dss_id].ro_cred,
|
| 617 | dss_info->ro_cred);
|
| 618 | rcu_assign_pointer(dss_info->ro_cred, cred);
|
| 619 | } else {
|
| 620 | cred = xchg(&mirror->dss[dss_id].rw_cred,
|
| 621 | dss_info->rw_cred);
|
| 622 | rcu_assign_pointer(dss_info->rw_cred, cred);
|
| 623 | }
|
| 624 | }
|
| 625 | ff_layout_free_mirror(fls->mirror_array[i]);
|
| 626 | fls->mirror_array[i] = mirror;
|
| 627 | }
|
| 628 |
|
| 629 | dprintk("%s: iomode %s uid %u gid %u\n", __func__,
|
| 630 | lgr->range.iomode == IOMODE_READ ? "READ" : "RW",
|
| 631 | from_kuid(&init_user_ns, uid),
|
| 632 | from_kgid(&init_user_ns, gid));
|
| 633 | }
|
| 634 |
|
| 635 | p = xdr_inline_decode(&stream, 4);
|
| 636 | if (!p)
|
| 637 | goto out_sort_mirrors;
|
| 638 | fls->flags = be32_to_cpup(p);
|
| 639 | if (fls->flags & FF_FLAGS_NO_IO_THRU_MDS)
|
| 640 | set_bit(NFS4_FF_HDR_NO_IO_THRU_MDS,
|
| 641 | &FF_LAYOUT_FROM_HDR(lh)->flags);
|
| 642 |
|
| 643 | p = xdr_inline_decode(&stream, 4);
|
| 644 | if (!p)
|
| 645 | goto out_sort_mirrors;
|
| 646 | for (i=0; i < fls->mirror_array_cnt; i++)
|
| 647 | fls->mirror_array[i]->report_interval = be32_to_cpup(p);
|
| 648 |
|
| 649 | out_sort_mirrors:
|
| 650 | ff_layout_sort_mirrors(fls);
|
| 651 | ret = &fls->generic_hdr;
|
| 652 | dprintk("<-- %s (success)\n", __func__);
|
| 653 | out_free_page:
|
| 654 | folio_put(scratch);
|
| 655 | return ret;
|
| 656 | out_err_free:
|
| 657 | _ff_layout_free_lseg(fls);
|
| 658 | ret = ERR_PTR(rc);
|
| 659 | dprintk("<-- %s (%d)\n", __func__, rc);
|
| 660 | goto out_free_page;
|
| 661 | }
|
| 662 |
|
| 663 | static void
|
| 664 | ff_layout_free_lseg(struct pnfs_layout_segment *lseg)
|
| 665 | {
|
| 666 | struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
|
| 667 |
|
| 668 | dprintk("--> %s\n", __func__);
|
| 669 |
|
| 670 | if (lseg->pls_range.iomode == IOMODE_RW) {
|
| 671 | struct nfs4_flexfile_layout *ffl;
|
| 672 | struct inode *inode;
|
| 673 |
|
| 674 | ffl = FF_LAYOUT_FROM_HDR(lseg->pls_layout);
|
| 675 | inode = ffl->generic_hdr.plh_inode;
|
| 676 | spin_lock(&inode->i_lock);
|
| 677 | pnfs_generic_ds_cinfo_release_lseg(&ffl->commit_info, lseg);
|
| 678 | spin_unlock(&inode->i_lock);
|
| 679 | }
|
| 680 | _ff_layout_free_lseg(fls);
|
| 681 | }
|
| 682 |
|
| 683 | static u32 calc_commit_idx(struct pnfs_layout_segment *lseg,
|
| 684 | u32 mirror_idx, u32 dss_id)
|
| 685 | {
|
| 686 | struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg);
|
| 687 |
|
| 688 | return (mirror_idx * flseg->mirror_array[0]->dss_count) + dss_id;
|
| 689 | }
|
| 690 |
|
| 691 | static u32 calc_mirror_idx_from_commit(struct pnfs_layout_segment *lseg,
|
| 692 | u32 commit_index)
|
| 693 | {
|
| 694 | return commit_index / FF_LAYOUT_LSEG(lseg)->mirror_array[0]->dss_count;
|
| 695 | }
|
| 696 |
|
| 697 | static u32 calc_dss_id_from_commit(struct pnfs_layout_segment *lseg,
|
| 698 | u32 commit_index)
|
| 699 | {
|
| 700 | return commit_index % FF_LAYOUT_LSEG(lseg)->mirror_array[0]->dss_count;
|
| 701 | }
|
| 702 |
|
| 703 | static void
|
| 704 | nfs4_ff_start_busy_timer(struct nfs4_ff_busy_timer *timer, ktime_t now)
|
| 705 | {
|
| 706 |
|
| 707 | if (atomic_inc_return(&timer->n_ops) == 1) {
|
| 708 | timer->start_time = now;
|
| 709 | }
|
| 710 | }
|
| 711 |
|
| 712 | static ktime_t
|
| 713 | nfs4_ff_end_busy_timer(struct nfs4_ff_busy_timer *timer, ktime_t now)
|
| 714 | {
|
| 715 | ktime_t start;
|
| 716 |
|
| 717 | if (atomic_dec_return(&timer->n_ops) < 0)
|
| 718 | WARN_ON_ONCE(1);
|
| 719 |
|
| 720 | start = timer->start_time;
|
| 721 | timer->start_time = now;
|
| 722 | return ktime_sub(now, start);
|
| 723 | }
|
| 724 |
|
| 725 | static bool
|
| 726 | nfs4_ff_layoutstat_start_io(struct nfs4_ff_layout_mirror *mirror,
|
| 727 | u32 dss_id,
|
| 728 | struct nfs4_ff_layoutstat *layoutstat,
|
| 729 | ktime_t now)
|
| 730 | {
|
| 731 | s64 report_interval = FF_LAYOUTSTATS_REPORT_INTERVAL;
|
| 732 | struct nfs4_flexfile_layout *ffl = FF_LAYOUT_FROM_HDR(mirror->layout);
|
| 733 |
|
| 734 | nfs4_ff_start_busy_timer(&layoutstat->busy_timer, now);
|
| 735 | if (!mirror->dss[dss_id].start_time)
|
| 736 | mirror->dss[dss_id].start_time = now;
|
| 737 | if (mirror->report_interval != 0)
|
| 738 | report_interval = (s64)mirror->report_interval * 1000LL;
|
| 739 | else if (layoutstats_timer != 0)
|
| 740 | report_interval = (s64)layoutstats_timer * 1000LL;
|
| 741 | if (ktime_to_ms(ktime_sub(now, ffl->last_report_time)) >=
|
| 742 | report_interval) {
|
| 743 | ffl->last_report_time = now;
|
| 744 | return true;
|
| 745 | }
|
| 746 |
|
| 747 | return false;
|
| 748 | }
|
| 749 |
|
| 750 | static void
|
| 751 | nfs4_ff_layout_stat_io_update_requested(struct nfs4_ff_layoutstat *layoutstat,
|
| 752 | __u64 requested)
|
| 753 | {
|
| 754 | struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat;
|
| 755 |
|
| 756 | iostat->ops_requested++;
|
| 757 | iostat->bytes_requested += requested;
|
| 758 | }
|
| 759 |
|
| 760 | static void
|
| 761 | nfs4_ff_layout_stat_io_update_completed(struct nfs4_ff_layoutstat *layoutstat,
|
| 762 | __u64 requested,
|
| 763 | __u64 completed,
|
| 764 | ktime_t time_completed,
|
| 765 | ktime_t time_started)
|
| 766 | {
|
| 767 | struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat;
|
| 768 | ktime_t completion_time = ktime_sub(time_completed, time_started);
|
| 769 | ktime_t timer;
|
| 770 |
|
| 771 | iostat->ops_completed++;
|
| 772 | iostat->bytes_completed += completed;
|
| 773 | iostat->bytes_not_delivered += requested - completed;
|
| 774 |
|
| 775 | timer = nfs4_ff_end_busy_timer(&layoutstat->busy_timer, time_completed);
|
| 776 | iostat->total_busy_time =
|
| 777 | ktime_add(iostat->total_busy_time, timer);
|
| 778 | iostat->aggregate_completion_time =
|
| 779 | ktime_add(iostat->aggregate_completion_time,
|
| 780 | completion_time);
|
| 781 | }
|
| 782 |
|
| 783 | static void
|
| 784 | nfs4_ff_layout_stat_io_start_read(struct inode *inode,
|
| 785 | struct nfs4_ff_layout_mirror *mirror,
|
| 786 | u32 dss_id,
|
| 787 | __u64 requested, ktime_t now)
|
| 788 | {
|
| 789 | bool report;
|
| 790 |
|
| 791 | spin_lock(&mirror->lock);
|
| 792 | report = nfs4_ff_layoutstat_start_io(
|
| 793 | mirror, dss_id, &mirror->dss[dss_id].read_stat, now);
|
| 794 | nfs4_ff_layout_stat_io_update_requested(
|
| 795 | &mirror->dss[dss_id].read_stat, requested);
|
| 796 | set_bit(NFS4_FF_MIRROR_STAT_AVAIL, &mirror->flags);
|
| 797 | spin_unlock(&mirror->lock);
|
| 798 |
|
| 799 | if (report)
|
| 800 | pnfs_report_layoutstat(inode, nfs_io_gfp_mask());
|
| 801 | }
|
| 802 |
|
| 803 | static void
|
| 804 | nfs4_ff_layout_stat_io_end_read(struct rpc_task *task,
|
| 805 | struct nfs4_ff_layout_mirror *mirror,
|
| 806 | u32 dss_id,
|
| 807 | __u64 requested,
|
| 808 | __u64 completed)
|
| 809 | {
|
| 810 | spin_lock(&mirror->lock);
|
| 811 | nfs4_ff_layout_stat_io_update_completed(&mirror->dss[dss_id].read_stat,
|
| 812 | requested, completed,
|
| 813 | ktime_get(), task->tk_start);
|
| 814 | set_bit(NFS4_FF_MIRROR_STAT_AVAIL, &mirror->flags);
|
| 815 | spin_unlock(&mirror->lock);
|
| 816 | }
|
| 817 |
|
| 818 | static void
|
| 819 | nfs4_ff_layout_stat_io_start_write(struct inode *inode,
|
| 820 | struct nfs4_ff_layout_mirror *mirror,
|
| 821 | u32 dss_id,
|
| 822 | __u64 requested, ktime_t now)
|
| 823 | {
|
| 824 | bool report;
|
| 825 |
|
| 826 | spin_lock(&mirror->lock);
|
| 827 | report = nfs4_ff_layoutstat_start_io(
|
| 828 | mirror,
|
| 829 | dss_id,
|
| 830 | &mirror->dss[dss_id].write_stat,
|
| 831 | now);
|
| 832 | nfs4_ff_layout_stat_io_update_requested(
|
| 833 | &mirror->dss[dss_id].write_stat,
|
| 834 | requested);
|
| 835 | set_bit(NFS4_FF_MIRROR_STAT_AVAIL, &mirror->flags);
|
| 836 | spin_unlock(&mirror->lock);
|
| 837 |
|
| 838 | if (report)
|
| 839 | pnfs_report_layoutstat(inode, nfs_io_gfp_mask());
|
| 840 | }
|
| 841 |
|
| 842 | static void
|
| 843 | nfs4_ff_layout_stat_io_end_write(struct rpc_task *task,
|
| 844 | struct nfs4_ff_layout_mirror *mirror,
|
| 845 | u32 dss_id,
|
| 846 | __u64 requested,
|
| 847 | __u64 completed,
|
| 848 | enum nfs3_stable_how committed)
|
| 849 | {
|
| 850 | if (committed == NFS_UNSTABLE)
|
| 851 | requested = completed = 0;
|
| 852 |
|
| 853 | spin_lock(&mirror->lock);
|
| 854 | nfs4_ff_layout_stat_io_update_completed(&mirror->dss[dss_id].write_stat,
|
| 855 | requested, completed, ktime_get(), task->tk_start);
|
| 856 | set_bit(NFS4_FF_MIRROR_STAT_AVAIL, &mirror->flags);
|
| 857 | spin_unlock(&mirror->lock);
|
| 858 | }
|
| 859 |
|
| 860 | static void
|
| 861 | ff_layout_mark_ds_unreachable(struct pnfs_layout_segment *lseg, u32 idx, u32 dss_id)
|
| 862 | {
|
| 863 | struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx, dss_id);
|
| 864 |
|
| 865 | if (devid)
|
| 866 | nfs4_mark_deviceid_unavailable(devid);
|
| 867 | }
|
| 868 |
|
| 869 | static void
|
| 870 | ff_layout_mark_ds_reachable(struct pnfs_layout_segment *lseg, u32 idx, u32 dss_id)
|
| 871 | {
|
| 872 | struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx, dss_id);
|
| 873 |
|
| 874 | if (devid)
|
| 875 | nfs4_mark_deviceid_available(devid);
|
| 876 | }
|
| 877 |
|
| 878 | static struct nfs4_pnfs_ds *
|
| 879 | ff_layout_choose_ds_for_read(struct pnfs_layout_segment *lseg,
|
| 880 | u32 start_idx, u32 *best_idx,
|
| 881 | u32 offset, u32 *dss_id,
|
| 882 | bool check_device)
|
| 883 | {
|
| 884 | struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg);
|
| 885 | struct nfs4_ff_layout_mirror *mirror;
|
| 886 | struct nfs4_pnfs_ds *ds = ERR_PTR(-EAGAIN);
|
| 887 | u32 idx;
|
| 888 |
|
| 889 |
|
| 890 | for (idx = start_idx; idx < fls->mirror_array_cnt; idx++) {
|
| 891 | mirror = FF_LAYOUT_COMP(lseg, idx);
|
| 892 | *dss_id = nfs4_ff_layout_calc_dss_id(
|
| 893 | fls->stripe_unit,
|
| 894 | fls->mirror_array[idx]->dss_count,
|
| 895 | offset);
|
| 896 | ds = nfs4_ff_layout_prepare_ds(lseg, mirror, *dss_id, false);
|
| 897 | if (IS_ERR(ds))
|
| 898 | continue;
|
| 899 |
|
| 900 | if (check_device &&
|
| 901 | nfs4_test_deviceid_unavailable(&mirror->dss[*dss_id].mirror_ds->id_node)) {
|
| 902 | |
| 903 | ds = ERR_PTR(-EINVAL);
|
| 904 | continue;
|
| 905 | }
|
| 906 |
|
| 907 | *best_idx = idx;
|
| 908 | break;
|
| 909 | }
|
| 910 |
|
| 911 | return ds;
|
| 912 | }
|
| 913 |
|
| 914 | static struct nfs4_pnfs_ds *
|
| 915 | ff_layout_choose_any_ds_for_read(struct pnfs_layout_segment *lseg,
|
| 916 | u32 start_idx, u32 *best_idx,
|
| 917 | u32 offset, u32 *dss_id)
|
| 918 | {
|
| 919 | return ff_layout_choose_ds_for_read(lseg, start_idx, best_idx,
|
| 920 | offset, dss_id, false);
|
| 921 | }
|
| 922 |
|
| 923 | static struct nfs4_pnfs_ds *
|
| 924 | ff_layout_choose_valid_ds_for_read(struct pnfs_layout_segment *lseg,
|
| 925 | u32 start_idx, u32 *best_idx,
|
| 926 | u32 offset, u32 *dss_id)
|
| 927 | {
|
| 928 | return ff_layout_choose_ds_for_read(lseg, start_idx, best_idx,
|
| 929 | offset, dss_id, true);
|
| 930 | }
|
| 931 |
|
| 932 | static struct nfs4_pnfs_ds *
|
| 933 | ff_layout_choose_best_ds_for_read(struct pnfs_layout_segment *lseg,
|
| 934 | u32 start_idx, u32 *best_idx,
|
| 935 | u32 offset, u32 *dss_id)
|
| 936 | {
|
| 937 | struct nfs4_pnfs_ds *ds;
|
| 938 |
|
| 939 | ds = ff_layout_choose_valid_ds_for_read(lseg, start_idx, best_idx,
|
| 940 | offset, dss_id);
|
| 941 | if (!IS_ERR(ds))
|
| 942 | return ds;
|
| 943 | return ff_layout_choose_any_ds_for_read(lseg, start_idx, best_idx,
|
| 944 | offset, dss_id);
|
| 945 | }
|
| 946 |
|
| 947 | static struct nfs4_pnfs_ds *
|
| 948 | ff_layout_get_ds_for_read(struct nfs_pageio_descriptor *pgio,
|
| 949 | u32 *best_idx,
|
| 950 | u32 offset,
|
| 951 | u32 *dss_id)
|
| 952 | {
|
| 953 | struct pnfs_layout_segment *lseg = pgio->pg_lseg;
|
| 954 | struct nfs4_pnfs_ds *ds;
|
| 955 |
|
| 956 | ds = ff_layout_choose_best_ds_for_read(lseg, pgio->pg_mirror_idx,
|
| 957 | best_idx, offset, dss_id);
|
| 958 | if (!IS_ERR(ds) || !pgio->pg_mirror_idx)
|
| 959 | return ds;
|
| 960 | return ff_layout_choose_best_ds_for_read(lseg, 0, best_idx,
|
| 961 | offset, dss_id);
|
| 962 | }
|
| 963 |
|
| 964 | static void
|
| 965 | ff_layout_pg_get_read(struct nfs_pageio_descriptor *pgio,
|
| 966 | struct nfs_page *req,
|
| 967 | bool strict_iomode)
|
| 968 | {
|
| 969 | pnfs_put_lseg(pgio->pg_lseg);
|
| 970 | pgio->pg_lseg =
|
| 971 | pnfs_update_layout(pgio->pg_inode, nfs_req_openctx(req),
|
| 972 | req_offset(req), req->wb_bytes, IOMODE_READ,
|
| 973 | strict_iomode, nfs_io_gfp_mask());
|
| 974 | if (IS_ERR(pgio->pg_lseg)) {
|
| 975 | pgio->pg_error = PTR_ERR(pgio->pg_lseg);
|
| 976 | pgio->pg_lseg = NULL;
|
| 977 | }
|
| 978 | }
|
| 979 |
|
| 980 | static bool
|
| 981 | ff_layout_lseg_is_striped(const struct nfs4_ff_layout_segment *fls)
|
| 982 | {
|
| 983 | return fls->mirror_array[0]->dss_count > 1;
|
| 984 | }
|
| 985 |
|
| 986 | |
| 987 | * ff_layout_pg_test(). Called by nfs_can_coalesce_requests()
|
| 988 | *
|
| 989 | * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
|
| 990 | * of bytes (maximum @req->wb_bytes) that can be coalesced.
|
| 991 |
|
| 992 | static size_t
|
| 993 | ff_layout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
|
| 994 | struct nfs_page *req)
|
| 995 | {
|
| 996 | unsigned int size;
|
| 997 | u64 p_stripe, r_stripe;
|
| 998 | u32 stripe_offset;
|
| 999 | u64 segment_offset = pgio->pg_lseg->pls_range.offset;
|
| 1000 | u32 stripe_unit = FF_LAYOUT_LSEG(pgio->pg_lseg)->stripe_unit;
|
| 1001 |
|
| 1002 |
|
| 1003 | size = pnfs_generic_pg_test(pgio, prev, req);
|
| 1004 | if (!size)
|
| 1005 | return 0;
|
| 1006 | else if (!ff_layout_lseg_is_striped(FF_LAYOUT_LSEG(pgio->pg_lseg)))
|
| 1007 | return size;
|
| 1008 |
|
| 1009 |
|
| 1010 | if (prev) {
|
| 1011 | p_stripe = (u64)req_offset(prev) - segment_offset;
|
| 1012 | r_stripe = (u64)req_offset(req) - segment_offset;
|
| 1013 | do_div(p_stripe, stripe_unit);
|
| 1014 | do_div(r_stripe, stripe_unit);
|
| 1015 |
|
| 1016 | if (p_stripe != r_stripe)
|
| 1017 | return 0;
|
| 1018 | }
|
| 1019 |
|
| 1020 |
|
| 1021 | div_u64_rem((u64)req_offset(req) - segment_offset,
|
| 1022 | stripe_unit,
|
| 1023 | &stripe_offset);
|
| 1024 | WARN_ON_ONCE(stripe_offset > stripe_unit);
|
| 1025 | if (stripe_offset >= stripe_unit)
|
| 1026 | return 0;
|
| 1027 | return min(stripe_unit - (unsigned int)stripe_offset, size);
|
| 1028 | }
|
| 1029 |
|
| 1030 | static void
|
| 1031 | ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
|
| 1032 | struct nfs_page *req)
|
| 1033 | {
|
| 1034 | struct nfs_pgio_mirror *pgm;
|
| 1035 | struct nfs4_ff_layout_mirror *mirror;
|
| 1036 | struct nfs4_pnfs_ds *ds;
|
| 1037 | u32 ds_idx, dss_id;
|
| 1038 |
|
| 1039 | if (NFS_SERVER(pgio->pg_inode)->flags &
|
| 1040 | (NFS_MOUNT_SOFT|NFS_MOUNT_SOFTERR))
|
| 1041 | pgio->pg_maxretrans = io_maxretrans;
|
| 1042 | retry:
|
| 1043 | pnfs_generic_pg_check_layout(pgio, req);
|
| 1044 |
|
| 1045 | if (!pgio->pg_lseg) {
|
| 1046 | ff_layout_pg_get_read(pgio, req, false);
|
| 1047 | if (!pgio->pg_lseg)
|
| 1048 | goto out_nolseg;
|
| 1049 | }
|
| 1050 | if (ff_layout_avoid_read_on_rw(pgio->pg_lseg)) {
|
| 1051 | ff_layout_pg_get_read(pgio, req, true);
|
| 1052 | if (!pgio->pg_lseg)
|
| 1053 | goto out_nolseg;
|
| 1054 | }
|
| 1055 |
|
| 1056 | req->wb_nio = 0;
|
| 1057 |
|
| 1058 | ds = ff_layout_get_ds_for_read(pgio, &ds_idx,
|
| 1059 | req_offset(req), &dss_id);
|
| 1060 | if (IS_ERR(ds)) {
|
| 1061 | if (!ff_layout_no_fallback_to_mds(pgio->pg_lseg))
|
| 1062 | goto out_mds;
|
| 1063 | pnfs_generic_pg_cleanup(pgio);
|
| 1064 |
|
| 1065 | ssleep(1);
|
| 1066 | goto retry;
|
| 1067 | }
|
| 1068 |
|
| 1069 | mirror = FF_LAYOUT_COMP(pgio->pg_lseg, ds_idx);
|
| 1070 | pgm = &pgio->pg_mirrors[0];
|
| 1071 | pgm->pg_bsize = mirror->dss[dss_id].mirror_ds->ds_versions[0].rsize;
|
| 1072 |
|
| 1073 | pgio->pg_mirror_idx = ds_idx;
|
| 1074 | return;
|
| 1075 | out_nolseg:
|
| 1076 | if (pgio->pg_error < 0) {
|
| 1077 | if (pgio->pg_error != -EAGAIN)
|
| 1078 | return;
|
| 1079 |
|
| 1080 | if (pgio->pg_maxretrans && req->wb_nio++ > pgio->pg_maxretrans) {
|
| 1081 | if (NFS_SERVER(pgio->pg_inode)->flags & NFS_MOUNT_SOFTERR)
|
| 1082 | pgio->pg_error = -ETIMEDOUT;
|
| 1083 | else
|
| 1084 | pgio->pg_error = -EIO;
|
| 1085 | return;
|
| 1086 | }
|
| 1087 | pgio->pg_error = 0;
|
| 1088 |
|
| 1089 | ssleep(1);
|
| 1090 | goto retry;
|
| 1091 | }
|
| 1092 | out_mds:
|
| 1093 | trace_pnfs_mds_fallback_pg_init_read(pgio->pg_inode,
|
| 1094 | 0, NFS4_MAX_UINT64, IOMODE_READ,
|
| 1095 | NFS_I(pgio->pg_inode)->layout,
|
| 1096 | pgio->pg_lseg);
|
| 1097 | pgio->pg_maxretrans = 0;
|
| 1098 | nfs_pageio_reset_read_mds(pgio);
|
| 1099 | }
|
| 1100 |
|
| 1101 | static void
|
| 1102 | ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio,
|
| 1103 | struct nfs_page *req)
|
| 1104 | {
|
| 1105 | struct nfs4_ff_layout_mirror *mirror;
|
| 1106 | struct nfs_pgio_mirror *pgm;
|
| 1107 | struct nfs4_pnfs_ds *ds;
|
| 1108 | u32 i, dss_id;
|
| 1109 |
|
| 1110 | retry:
|
| 1111 | pnfs_generic_pg_check_layout(pgio, req);
|
| 1112 | if (!pgio->pg_lseg) {
|
| 1113 | pgio->pg_lseg =
|
| 1114 | pnfs_update_layout(pgio->pg_inode, nfs_req_openctx(req),
|
| 1115 | req_offset(req), req->wb_bytes,
|
| 1116 | IOMODE_RW, false, nfs_io_gfp_mask());
|
| 1117 | if (IS_ERR(pgio->pg_lseg)) {
|
| 1118 | pgio->pg_error = PTR_ERR(pgio->pg_lseg);
|
| 1119 | pgio->pg_lseg = NULL;
|
| 1120 | return;
|
| 1121 | }
|
| 1122 | }
|
| 1123 |
|
| 1124 | if (pgio->pg_lseg == NULL)
|
| 1125 | goto out_mds;
|
| 1126 |
|
| 1127 |
|
| 1128 | if (pgio->pg_mirror_count != FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg))
|
| 1129 | goto out_eagain;
|
| 1130 |
|
| 1131 | for (i = 0; i < pgio->pg_mirror_count; i++) {
|
| 1132 | mirror = FF_LAYOUT_COMP(pgio->pg_lseg, i);
|
| 1133 | dss_id = nfs4_ff_layout_calc_dss_id(
|
| 1134 | FF_LAYOUT_LSEG(pgio->pg_lseg)->stripe_unit,
|
| 1135 | mirror->dss_count,
|
| 1136 | req_offset(req));
|
| 1137 | ds = nfs4_ff_layout_prepare_ds(pgio->pg_lseg, mirror,
|
| 1138 | dss_id, true);
|
| 1139 | if (IS_ERR(ds)) {
|
| 1140 | if (!ff_layout_no_fallback_to_mds(pgio->pg_lseg))
|
| 1141 | goto out_mds;
|
| 1142 | pnfs_generic_pg_cleanup(pgio);
|
| 1143 |
|
| 1144 | ssleep(1);
|
| 1145 | goto retry;
|
| 1146 | }
|
| 1147 | pgm = &pgio->pg_mirrors[i];
|
| 1148 | pgm->pg_bsize = mirror->dss[dss_id].mirror_ds->ds_versions[0].wsize;
|
| 1149 | }
|
| 1150 |
|
| 1151 | if (NFS_SERVER(pgio->pg_inode)->flags &
|
| 1152 | (NFS_MOUNT_SOFT|NFS_MOUNT_SOFTERR))
|
| 1153 | pgio->pg_maxretrans = io_maxretrans;
|
| 1154 | return;
|
| 1155 | out_eagain:
|
| 1156 | pnfs_generic_pg_cleanup(pgio);
|
| 1157 | pgio->pg_error = -EAGAIN;
|
| 1158 | return;
|
| 1159 | out_mds:
|
| 1160 | trace_pnfs_mds_fallback_pg_init_write(pgio->pg_inode,
|
| 1161 | 0, NFS4_MAX_UINT64, IOMODE_RW,
|
| 1162 | NFS_I(pgio->pg_inode)->layout,
|
| 1163 | pgio->pg_lseg);
|
| 1164 | pgio->pg_maxretrans = 0;
|
| 1165 | nfs_pageio_reset_write_mds(pgio);
|
| 1166 | pgio->pg_error = -EAGAIN;
|
| 1167 | }
|
| 1168 |
|
| 1169 | static unsigned int
|
| 1170 | ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio,
|
| 1171 | struct nfs_page *req)
|
| 1172 | {
|
| 1173 | if (!pgio->pg_lseg) {
|
| 1174 | pgio->pg_lseg =
|
| 1175 | pnfs_update_layout(pgio->pg_inode, nfs_req_openctx(req),
|
| 1176 | req_offset(req), req->wb_bytes,
|
| 1177 | IOMODE_RW, false, nfs_io_gfp_mask());
|
| 1178 | if (IS_ERR(pgio->pg_lseg)) {
|
| 1179 | pgio->pg_error = PTR_ERR(pgio->pg_lseg);
|
| 1180 | pgio->pg_lseg = NULL;
|
| 1181 | goto out;
|
| 1182 | }
|
| 1183 | }
|
| 1184 | if (pgio->pg_lseg)
|
| 1185 | return FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg);
|
| 1186 |
|
| 1187 | trace_pnfs_mds_fallback_pg_get_mirror_count(pgio->pg_inode,
|
| 1188 | 0, NFS4_MAX_UINT64, IOMODE_RW,
|
| 1189 | NFS_I(pgio->pg_inode)->layout,
|
| 1190 | pgio->pg_lseg);
|
| 1191 | if (NFS_I(pgio->pg_inode)->layout &&
|
| 1192 | ff_layout_hdr_no_fallback_to_mds(NFS_I(pgio->pg_inode)->layout)) {
|
| 1193 | |
| 1194 | * FF_FLAGS_NO_IO_THRU_MDS: no current lseg but the server's
|
| 1195 | * policy forbids MDS fallback. Surface -EAGAIN so writeback
|
| 1196 | * retries rather than silently issuing the WRITE via MDS.
|
| 1197 |
|
| 1198 | pgio->pg_error = -EAGAIN;
|
| 1199 | goto out;
|
| 1200 | }
|
| 1201 |
|
| 1202 | nfs_pageio_reset_write_mds(pgio);
|
| 1203 | out:
|
| 1204 | return 1;
|
| 1205 | }
|
| 1206 |
|
| 1207 | static u32
|
| 1208 | ff_layout_pg_set_mirror_write(struct nfs_pageio_descriptor *desc, u32 idx)
|
| 1209 | {
|
| 1210 | u32 old = desc->pg_mirror_idx;
|
| 1211 |
|
| 1212 | desc->pg_mirror_idx = idx;
|
| 1213 | return old;
|
| 1214 | }
|
| 1215 |
|
| 1216 | static struct nfs_pgio_mirror *
|
| 1217 | ff_layout_pg_get_mirror_write(struct nfs_pageio_descriptor *desc, u32 idx)
|
| 1218 | {
|
| 1219 | return &desc->pg_mirrors[idx];
|
| 1220 | }
|
| 1221 |
|
| 1222 | static const struct nfs_pageio_ops ff_layout_pg_read_ops = {
|
| 1223 | .pg_init = ff_layout_pg_init_read,
|
| 1224 | .pg_test = ff_layout_pg_test,
|
| 1225 | .pg_doio = pnfs_generic_pg_readpages,
|
| 1226 | .pg_cleanup = pnfs_generic_pg_cleanup,
|
| 1227 | };
|
| 1228 |
|
| 1229 | static const struct nfs_pageio_ops ff_layout_pg_write_ops = {
|
| 1230 | .pg_init = ff_layout_pg_init_write,
|
| 1231 | .pg_test = ff_layout_pg_test,
|
| 1232 | .pg_doio = pnfs_generic_pg_writepages,
|
| 1233 | .pg_get_mirror_count = ff_layout_pg_get_mirror_count_write,
|
| 1234 | .pg_cleanup = pnfs_generic_pg_cleanup,
|
| 1235 | .pg_get_mirror = ff_layout_pg_get_mirror_write,
|
| 1236 | .pg_set_mirror = ff_layout_pg_set_mirror_write,
|
| 1237 | };
|
| 1238 |
|
| 1239 | static void ff_layout_reset_write(struct nfs_pgio_header *hdr, bool retry_pnfs)
|
| 1240 | {
|
| 1241 | struct rpc_task *task = &hdr->task;
|
| 1242 |
|
| 1243 | pnfs_layoutcommit_inode(hdr->inode, false);
|
| 1244 |
|
| 1245 | if (retry_pnfs) {
|
| 1246 | dprintk("%s Reset task %5u for i/o through pNFS "
|
| 1247 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
|
| 1248 | hdr->task.tk_pid,
|
| 1249 | hdr->inode->i_sb->s_id,
|
| 1250 | (unsigned long long)hdr->inode->i_ino,
|
| 1251 | hdr->args.count,
|
| 1252 | (unsigned long long)hdr->args.offset);
|
| 1253 |
|
| 1254 | hdr->completion_ops->reschedule_io(hdr);
|
| 1255 | return;
|
| 1256 | }
|
| 1257 |
|
| 1258 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
|
| 1259 | dprintk("%s Reset task %5u for i/o through MDS "
|
| 1260 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
|
| 1261 | hdr->task.tk_pid,
|
| 1262 | hdr->inode->i_sb->s_id,
|
| 1263 | (unsigned long long)hdr->inode->i_ino,
|
| 1264 | hdr->args.count,
|
| 1265 | (unsigned long long)hdr->args.offset);
|
| 1266 |
|
| 1267 | trace_pnfs_mds_fallback_write_done(hdr->inode,
|
| 1268 | hdr->args.offset, hdr->args.count,
|
| 1269 | IOMODE_RW, NFS_I(hdr->inode)->layout,
|
| 1270 | hdr->lseg);
|
| 1271 | task->tk_status = pnfs_write_done_resend_to_mds(hdr);
|
| 1272 | }
|
| 1273 | }
|
| 1274 |
|
| 1275 | static void ff_layout_resend_pnfs_read(struct nfs_pgio_header *hdr)
|
| 1276 | {
|
| 1277 | u32 idx = hdr->pgio_mirror_idx + 1;
|
| 1278 | u32 new_idx = 0;
|
| 1279 | u32 dss_id = 0;
|
| 1280 | struct nfs4_pnfs_ds *ds;
|
| 1281 |
|
| 1282 | ds = ff_layout_choose_any_ds_for_read(hdr->lseg, idx, &new_idx,
|
| 1283 | hdr->args.offset, &dss_id);
|
| 1284 | if (IS_ERR(ds))
|
| 1285 | pnfs_error_mark_layout_for_return(hdr->inode, hdr->lseg);
|
| 1286 | else
|
| 1287 | ff_layout_send_layouterror(hdr->lseg);
|
| 1288 | pnfs_read_resend_pnfs(hdr, new_idx);
|
| 1289 | }
|
| 1290 |
|
| 1291 | static void ff_layout_reset_read(struct nfs_pgio_header *hdr)
|
| 1292 | {
|
| 1293 | struct rpc_task *task = &hdr->task;
|
| 1294 |
|
| 1295 | pnfs_layoutcommit_inode(hdr->inode, false);
|
| 1296 | pnfs_error_mark_layout_for_return(hdr->inode, hdr->lseg);
|
| 1297 |
|
| 1298 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
|
| 1299 | dprintk("%s Reset task %5u for i/o through MDS "
|
| 1300 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
|
| 1301 | hdr->task.tk_pid,
|
| 1302 | hdr->inode->i_sb->s_id,
|
| 1303 | (unsigned long long)hdr->inode->i_ino,
|
| 1304 | hdr->args.count,
|
| 1305 | (unsigned long long)hdr->args.offset);
|
| 1306 |
|
| 1307 | trace_pnfs_mds_fallback_read_done(hdr->inode,
|
| 1308 | hdr->args.offset, hdr->args.count,
|
| 1309 | IOMODE_READ, NFS_I(hdr->inode)->layout,
|
| 1310 | hdr->lseg);
|
| 1311 | task->tk_status = pnfs_read_done_resend_to_mds(hdr);
|
| 1312 | }
|
| 1313 | }
|
| 1314 |
|
| 1315 | static int ff_layout_async_handle_error_v4(struct rpc_task *task,
|
| 1316 | u32 op_status,
|
| 1317 | struct nfs4_state *state,
|
| 1318 | struct nfs_client *clp,
|
| 1319 | struct pnfs_layout_segment *lseg,
|
| 1320 | u32 idx, u32 dss_id)
|
| 1321 | {
|
| 1322 | struct pnfs_layout_hdr *lo = lseg->pls_layout;
|
| 1323 | struct inode *inode = lo->plh_inode;
|
| 1324 | struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx, dss_id);
|
| 1325 | struct nfs4_slot_table *tbl = nfs4_has_session(clp) ?
|
| 1326 | &clp->cl_session->fc_slot_table : clp->cl_slot_tbl;
|
| 1327 |
|
| 1328 | switch (op_status) {
|
| 1329 | case NFS4_OK:
|
| 1330 | case NFS4ERR_NXIO:
|
| 1331 | break;
|
| 1332 | case NFSERR_PERM:
|
| 1333 | if (!task->tk_xprt)
|
| 1334 | break;
|
| 1335 | xprt_force_disconnect(task->tk_xprt);
|
| 1336 | goto out_retry;
|
| 1337 | case NFS4ERR_BADSESSION:
|
| 1338 | case NFS4ERR_BADSLOT:
|
| 1339 | case NFS4ERR_BAD_HIGH_SLOT:
|
| 1340 | case NFS4ERR_DEADSESSION:
|
| 1341 | case NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
|
| 1342 | case NFS4ERR_SEQ_FALSE_RETRY:
|
| 1343 | case NFS4ERR_SEQ_MISORDERED:
|
| 1344 | dprintk("%s ERROR %d, Reset session. Exchangeid "
|
| 1345 | "flags 0x%x\n", __func__, task->tk_status,
|
| 1346 | clp->cl_exchange_flags);
|
| 1347 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
|
| 1348 | goto out_retry;
|
| 1349 | case NFS4ERR_DELAY:
|
| 1350 | nfs_inc_stats(lseg->pls_layout->plh_inode, NFSIOS_DELAY);
|
| 1351 | fallthrough;
|
| 1352 | case NFS4ERR_GRACE:
|
| 1353 | rpc_delay(task, FF_LAYOUT_POLL_RETRY_MAX);
|
| 1354 | goto out_retry;
|
| 1355 | case NFS4ERR_RETRY_UNCACHED_REP:
|
| 1356 | goto out_retry;
|
| 1357 |
|
| 1358 | case NFS4ERR_PNFS_NO_LAYOUT:
|
| 1359 | case NFS4ERR_STALE:
|
| 1360 | case NFS4ERR_BADHANDLE:
|
| 1361 | case NFS4ERR_ISDIR:
|
| 1362 | case NFS4ERR_FHEXPIRED:
|
| 1363 | case NFS4ERR_WRONG_TYPE:
|
| 1364 | dprintk("%s Invalid layout error %d\n", __func__,
|
| 1365 | task->tk_status);
|
| 1366 | |
| 1367 | * Destroy layout so new i/o will get a new layout.
|
| 1368 | * Layout will not be destroyed until all current lseg
|
| 1369 | * references are put. Mark layout as invalid to resend failed
|
| 1370 | * i/o and all i/o waiting on the slot table to the MDS until
|
| 1371 | * layout is destroyed and a new valid layout is obtained.
|
| 1372 |
|
| 1373 | pnfs_destroy_layout(NFS_I(inode));
|
| 1374 | rpc_wake_up(&tbl->slot_tbl_waitq);
|
| 1375 | goto reset;
|
| 1376 | default:
|
| 1377 | break;
|
| 1378 | }
|
| 1379 |
|
| 1380 | switch (task->tk_status) {
|
| 1381 |
|
| 1382 | case -ENETDOWN:
|
| 1383 | case -ENETUNREACH:
|
| 1384 | if (test_bit(NFS_CS_NETUNREACH_FATAL, &clp->cl_flags))
|
| 1385 | return -NFS4ERR_FATAL_IOERROR;
|
| 1386 | fallthrough;
|
| 1387 | case -ECONNREFUSED:
|
| 1388 | case -EHOSTDOWN:
|
| 1389 | case -EHOSTUNREACH:
|
| 1390 | case -EIO:
|
| 1391 | case -ETIMEDOUT:
|
| 1392 | case -EPIPE:
|
| 1393 | case -EPROTO:
|
| 1394 | case -ENODEV:
|
| 1395 | dprintk("%s DS connection error %d\n", __func__,
|
| 1396 | task->tk_status);
|
| 1397 | nfs4_delete_deviceid(devid->ld, devid->nfs_client,
|
| 1398 | &devid->deviceid);
|
| 1399 | rpc_wake_up(&tbl->slot_tbl_waitq);
|
| 1400 | break;
|
| 1401 | default:
|
| 1402 | break;
|
| 1403 | }
|
| 1404 |
|
| 1405 | if (ff_layout_avoid_mds_available_ds(lseg))
|
| 1406 | return -NFS4ERR_RESET_TO_PNFS;
|
| 1407 | reset:
|
| 1408 | dprintk("%s Retry through MDS. Error %d\n", __func__,
|
| 1409 | task->tk_status);
|
| 1410 | return -NFS4ERR_RESET_TO_MDS;
|
| 1411 |
|
| 1412 | out_retry:
|
| 1413 | task->tk_status = 0;
|
| 1414 | return -EAGAIN;
|
| 1415 | }
|
| 1416 |
|
| 1417 |
|
| 1418 | static int ff_layout_async_handle_error_v3(struct rpc_task *task,
|
| 1419 | u32 op_status,
|
| 1420 | struct nfs_client *clp,
|
| 1421 | struct pnfs_layout_segment *lseg,
|
| 1422 | u32 idx, u32 dss_id)
|
| 1423 | {
|
| 1424 | struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx, dss_id);
|
| 1425 |
|
| 1426 | switch (op_status) {
|
| 1427 | case NFS_OK:
|
| 1428 | case NFSERR_NXIO:
|
| 1429 | break;
|
| 1430 | case NFSERR_PERM:
|
| 1431 | if (!task->tk_xprt)
|
| 1432 | break;
|
| 1433 | xprt_force_disconnect(task->tk_xprt);
|
| 1434 | goto out_retry;
|
| 1435 | case NFSERR_ACCES:
|
| 1436 | case NFSERR_BADHANDLE:
|
| 1437 | case NFSERR_FBIG:
|
| 1438 | case NFSERR_IO:
|
| 1439 | case NFSERR_NOSPC:
|
| 1440 | case NFSERR_ROFS:
|
| 1441 | case NFSERR_STALE:
|
| 1442 | goto out_reset_to_pnfs;
|
| 1443 | case NFSERR_JUKEBOX:
|
| 1444 | nfs_inc_stats(lseg->pls_layout->plh_inode, NFSIOS_DELAY);
|
| 1445 | goto out_retry;
|
| 1446 | default:
|
| 1447 | break;
|
| 1448 | }
|
| 1449 |
|
| 1450 | switch (task->tk_status) {
|
| 1451 |
|
| 1452 | case -EACCES:
|
| 1453 | case -ESTALE:
|
| 1454 | case -EISDIR:
|
| 1455 | case -EBADHANDLE:
|
| 1456 | case -ELOOP:
|
| 1457 | case -ENOSPC:
|
| 1458 | break;
|
| 1459 | case -EJUKEBOX:
|
| 1460 | nfs_inc_stats(lseg->pls_layout->plh_inode, NFSIOS_DELAY);
|
| 1461 | goto out_retry;
|
| 1462 | case -ENETDOWN:
|
| 1463 | case -ENETUNREACH:
|
| 1464 | if (test_bit(NFS_CS_NETUNREACH_FATAL, &clp->cl_flags))
|
| 1465 | return -NFS4ERR_FATAL_IOERROR;
|
| 1466 | fallthrough;
|
| 1467 | default:
|
| 1468 | dprintk("%s DS connection error %d\n", __func__,
|
| 1469 | task->tk_status);
|
| 1470 | nfs4_delete_deviceid(devid->ld, devid->nfs_client,
|
| 1471 | &devid->deviceid);
|
| 1472 | }
|
| 1473 | out_reset_to_pnfs:
|
| 1474 |
|
| 1475 | return -NFS4ERR_RESET_TO_PNFS;
|
| 1476 | out_retry:
|
| 1477 | task->tk_status = 0;
|
| 1478 | rpc_restart_call_prepare(task);
|
| 1479 | rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
|
| 1480 | return -EAGAIN;
|
| 1481 | }
|
| 1482 |
|
| 1483 | static int ff_layout_async_handle_error(struct rpc_task *task,
|
| 1484 | u32 op_status,
|
| 1485 | struct nfs4_state *state,
|
| 1486 | struct nfs_client *clp,
|
| 1487 | struct pnfs_layout_segment *lseg,
|
| 1488 | u32 idx, u32 dss_id)
|
| 1489 | {
|
| 1490 | int vers = clp->cl_nfs_mod->rpc_vers->number;
|
| 1491 |
|
| 1492 | if (task->tk_status >= 0) {
|
| 1493 | ff_layout_mark_ds_reachable(lseg, idx, dss_id);
|
| 1494 | return 0;
|
| 1495 | }
|
| 1496 |
|
| 1497 |
|
| 1498 | if (!pnfs_is_valid_lseg(lseg))
|
| 1499 | return -NFS4ERR_RESET_TO_PNFS;
|
| 1500 |
|
| 1501 | switch (vers) {
|
| 1502 | case 3:
|
| 1503 | return ff_layout_async_handle_error_v3(task, op_status, clp,
|
| 1504 | lseg, idx, dss_id);
|
| 1505 | case 4:
|
| 1506 | return ff_layout_async_handle_error_v4(task, op_status, state,
|
| 1507 | clp, lseg, idx, dss_id);
|
| 1508 | default:
|
| 1509 |
|
| 1510 | WARN_ON_ONCE(1);
|
| 1511 | return 0;
|
| 1512 | }
|
| 1513 | }
|
| 1514 |
|
| 1515 | static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg,
|
| 1516 | u32 idx, u32 dss_id, u64 offset, u64 length,
|
| 1517 | u32 *op_status, int opnum, int error)
|
| 1518 | {
|
| 1519 | struct nfs4_ff_layout_mirror *mirror;
|
| 1520 | u32 status = *op_status;
|
| 1521 | int err;
|
| 1522 |
|
| 1523 | if (status == 0) {
|
| 1524 | switch (error) {
|
| 1525 | case -ETIMEDOUT:
|
| 1526 | case -EPFNOSUPPORT:
|
| 1527 | case -EPROTONOSUPPORT:
|
| 1528 | case -EOPNOTSUPP:
|
| 1529 | case -EINVAL:
|
| 1530 | case -ECONNREFUSED:
|
| 1531 | case -ECONNRESET:
|
| 1532 | case -EHOSTDOWN:
|
| 1533 | case -EHOSTUNREACH:
|
| 1534 | case -ENETDOWN:
|
| 1535 | case -ENETUNREACH:
|
| 1536 | case -EADDRINUSE:
|
| 1537 | case -ENOBUFS:
|
| 1538 | case -EPIPE:
|
| 1539 | case -EPERM:
|
| 1540 | case -EPROTO:
|
| 1541 | case -ENODEV:
|
| 1542 | *op_status = status = NFS4ERR_NXIO;
|
| 1543 | break;
|
| 1544 | case -EACCES:
|
| 1545 | *op_status = status = NFS4ERR_ACCESS;
|
| 1546 | break;
|
| 1547 | case -ECANCELED:
|
| 1548 | |
| 1549 | * In-flight I/O we cancelled to return a recalled or
|
| 1550 | * revoked layout. Report it as a failure to reach the
|
| 1551 | * device (NFS4ERR_NXIO), like the transport errors
|
| 1552 | * above, so the server can reconcile the affected mirror
|
| 1553 | * instance. We aborted the I/O ourselves rather than
|
| 1554 | * observe the device fail, so don't condemn it below.
|
| 1555 |
|
| 1556 | *op_status = status = NFS4ERR_NXIO;
|
| 1557 | break;
|
| 1558 | default:
|
| 1559 | return;
|
| 1560 | }
|
| 1561 | }
|
| 1562 |
|
| 1563 | mirror = FF_LAYOUT_COMP(lseg, idx);
|
| 1564 | err = ff_layout_track_ds_error(FF_LAYOUT_FROM_HDR(lseg->pls_layout),
|
| 1565 | mirror, dss_id, offset, length, status, opnum,
|
| 1566 | nfs_io_gfp_mask());
|
| 1567 |
|
| 1568 | |
| 1569 | * I/O we cancelled ourselves to return a recalled or revoked layout
|
| 1570 | * is reported above so the server can reconcile the mirror, but we
|
| 1571 | * have no evidence the device is at fault: don't mark it unreachable
|
| 1572 | * or force a return.
|
| 1573 |
|
| 1574 | if (error == -ECANCELED)
|
| 1575 | goto out;
|
| 1576 |
|
| 1577 | switch (status) {
|
| 1578 | case NFS4ERR_DELAY:
|
| 1579 | case NFS4ERR_GRACE:
|
| 1580 | case NFS4ERR_PERM:
|
| 1581 | break;
|
| 1582 | case NFS4ERR_NXIO:
|
| 1583 | ff_layout_mark_ds_unreachable(lseg, idx, dss_id);
|
| 1584 | |
| 1585 | * Don't return the layout if this is a read and we still
|
| 1586 | * have layouts to try
|
| 1587 |
|
| 1588 | if (opnum == OP_READ)
|
| 1589 | break;
|
| 1590 | fallthrough;
|
| 1591 | default:
|
| 1592 | pnfs_error_mark_layout_for_return(lseg->pls_layout->plh_inode,
|
| 1593 | lseg);
|
| 1594 | }
|
| 1595 |
|
| 1596 | out:
|
| 1597 | dprintk("%s: err %d op %d status %u\n", __func__, err, opnum, status);
|
| 1598 | }
|
| 1599 |
|
| 1600 |
|
| 1601 | static int ff_layout_read_done_cb(struct rpc_task *task,
|
| 1602 | struct nfs_pgio_header *hdr)
|
| 1603 | {
|
| 1604 | struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(hdr->lseg);
|
| 1605 | u32 dss_id = nfs4_ff_layout_calc_dss_id(
|
| 1606 | flseg->stripe_unit,
|
| 1607 | flseg->mirror_array[hdr->pgio_mirror_idx]->dss_count,
|
| 1608 | hdr->args.offset);
|
| 1609 | int err;
|
| 1610 |
|
| 1611 | if (task->tk_status < 0) {
|
| 1612 | ff_layout_io_track_ds_error(hdr->lseg,
|
| 1613 | hdr->pgio_mirror_idx, dss_id,
|
| 1614 | hdr->args.offset, hdr->args.count,
|
| 1615 | &hdr->res.op_status, OP_READ,
|
| 1616 | task->tk_status);
|
| 1617 | trace_ff_layout_read_error(hdr, task->tk_status);
|
| 1618 | }
|
| 1619 |
|
| 1620 | err = ff_layout_async_handle_error(task, hdr->res.op_status,
|
| 1621 | hdr->args.context->state,
|
| 1622 | hdr->ds_clp, hdr->lseg,
|
| 1623 | hdr->pgio_mirror_idx,
|
| 1624 | dss_id);
|
| 1625 |
|
| 1626 | trace_nfs4_pnfs_read(hdr, err);
|
| 1627 | clear_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags);
|
| 1628 | clear_bit(NFS_IOHDR_RESEND_MDS, &hdr->flags);
|
| 1629 | switch (err) {
|
| 1630 | case -NFS4ERR_RESET_TO_PNFS:
|
| 1631 | set_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags);
|
| 1632 | return task->tk_status;
|
| 1633 | case -NFS4ERR_RESET_TO_MDS:
|
| 1634 | set_bit(NFS_IOHDR_RESEND_MDS, &hdr->flags);
|
| 1635 | return task->tk_status;
|
| 1636 | case -EAGAIN:
|
| 1637 | goto out_eagain;
|
| 1638 | case -NFS4ERR_FATAL_IOERROR:
|
| 1639 | task->tk_status = -EIO;
|
| 1640 | return 0;
|
| 1641 | }
|
| 1642 |
|
| 1643 | return 0;
|
| 1644 | out_eagain:
|
| 1645 | rpc_restart_call_prepare(task);
|
| 1646 | return -EAGAIN;
|
| 1647 | }
|
| 1648 |
|
| 1649 | static bool
|
| 1650 | ff_layout_need_layoutcommit(struct pnfs_layout_segment *lseg)
|
| 1651 | {
|
| 1652 | return !(FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_LAYOUTCOMMIT);
|
| 1653 | }
|
| 1654 |
|
| 1655 | |
| 1656 | * We reference the rpc_cred of the first WRITE that triggers the need for
|
| 1657 | * a LAYOUTCOMMIT, and use it to send the layoutcommit compound.
|
| 1658 | * rfc5661 is not clear about which credential should be used.
|
| 1659 | *
|
| 1660 | * Flexlayout client should treat DS replied FILE_SYNC as DATA_SYNC, so
|
| 1661 | * to follow http://www.rfc-editor.org/errata_search.php?rfc=5661&eid=2751
|
| 1662 | * we always send layoutcommit after DS writes.
|
| 1663 |
|
| 1664 | static void
|
| 1665 | ff_layout_set_layoutcommit(struct inode *inode,
|
| 1666 | struct pnfs_layout_segment *lseg,
|
| 1667 | loff_t end_offset)
|
| 1668 | {
|
| 1669 | if (!ff_layout_need_layoutcommit(lseg))
|
| 1670 | return;
|
| 1671 |
|
| 1672 | pnfs_set_layoutcommit(inode, lseg, end_offset);
|
| 1673 | dprintk("%s inode %llu pls_end_pos %llu\n", __func__, inode->i_ino,
|
| 1674 | (unsigned long long) NFS_I(inode)->layout->plh_lwb);
|
| 1675 | }
|
| 1676 |
|
| 1677 | static void ff_layout_read_record_layoutstats_start(struct rpc_task *task,
|
| 1678 | struct nfs_pgio_header *hdr)
|
| 1679 | {
|
| 1680 | struct nfs4_ff_layout_mirror *mirror;
|
| 1681 | u32 dss_id;
|
| 1682 |
|
| 1683 | if (test_and_set_bit(NFS_IOHDR_STAT, &hdr->flags))
|
| 1684 | return;
|
| 1685 |
|
| 1686 | mirror = FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx);
|
| 1687 | dss_id = nfs4_ff_layout_calc_dss_id(
|
| 1688 | FF_LAYOUT_LSEG(hdr->lseg)->stripe_unit,
|
| 1689 | mirror->dss_count,
|
| 1690 | hdr->args.offset);
|
| 1691 |
|
| 1692 | nfs4_ff_layout_stat_io_start_read(
|
| 1693 | hdr->inode,
|
| 1694 | mirror,
|
| 1695 | dss_id,
|
| 1696 | hdr->args.count,
|
| 1697 | task->tk_start);
|
| 1698 | }
|
| 1699 |
|
| 1700 | static void ff_layout_read_record_layoutstats_done(struct rpc_task *task,
|
| 1701 | struct nfs_pgio_header *hdr)
|
| 1702 | {
|
| 1703 | struct nfs4_ff_layout_mirror *mirror;
|
| 1704 | u32 dss_id;
|
| 1705 |
|
| 1706 | if (!test_and_clear_bit(NFS_IOHDR_STAT, &hdr->flags))
|
| 1707 | return;
|
| 1708 |
|
| 1709 | mirror = FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx);
|
| 1710 | dss_id = nfs4_ff_layout_calc_dss_id(
|
| 1711 | FF_LAYOUT_LSEG(hdr->lseg)->stripe_unit,
|
| 1712 | mirror->dss_count,
|
| 1713 | hdr->args.offset);
|
| 1714 |
|
| 1715 | nfs4_ff_layout_stat_io_end_read(
|
| 1716 | task,
|
| 1717 | mirror,
|
| 1718 | dss_id,
|
| 1719 | hdr->args.count,
|
| 1720 | hdr->res.count);
|
| 1721 | set_bit(NFS_LSEG_LAYOUTRETURN, &hdr->lseg->pls_flags);
|
| 1722 | }
|
| 1723 |
|
| 1724 | static int ff_layout_read_prepare_common(struct rpc_task *task,
|
| 1725 | struct nfs_pgio_header *hdr)
|
| 1726 | {
|
| 1727 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
|
| 1728 | rpc_exit(task, -EIO);
|
| 1729 | return -EIO;
|
| 1730 | }
|
| 1731 |
|
| 1732 | if (!pnfs_is_valid_lseg(hdr->lseg)) {
|
| 1733 | rpc_exit(task, -EAGAIN);
|
| 1734 | return -EAGAIN;
|
| 1735 | }
|
| 1736 |
|
| 1737 | ff_layout_read_record_layoutstats_start(task, hdr);
|
| 1738 | return 0;
|
| 1739 | }
|
| 1740 |
|
| 1741 | |
| 1742 | * Call ops for the async read/write cases
|
| 1743 | * In the case of dense layouts, the offset needs to be reset to its
|
| 1744 | * original value.
|
| 1745 |
|
| 1746 | static void ff_layout_read_prepare_v3(struct rpc_task *task, void *data)
|
| 1747 | {
|
| 1748 | struct nfs_pgio_header *hdr = data;
|
| 1749 |
|
| 1750 | if (ff_layout_read_prepare_common(task, hdr))
|
| 1751 | return;
|
| 1752 |
|
| 1753 | rpc_call_start(task);
|
| 1754 | }
|
| 1755 |
|
| 1756 | static void ff_layout_read_prepare_v4(struct rpc_task *task, void *data)
|
| 1757 | {
|
| 1758 | struct nfs_pgio_header *hdr = data;
|
| 1759 |
|
| 1760 | if (nfs4_setup_sequence(hdr->ds_clp,
|
| 1761 | &hdr->args.seq_args,
|
| 1762 | &hdr->res.seq_res,
|
| 1763 | task))
|
| 1764 | return;
|
| 1765 |
|
| 1766 | ff_layout_read_prepare_common(task, hdr);
|
| 1767 | }
|
| 1768 |
|
| 1769 | static void ff_layout_read_call_done(struct rpc_task *task, void *data)
|
| 1770 | {
|
| 1771 | struct nfs_pgio_header *hdr = data;
|
| 1772 |
|
| 1773 | if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
|
| 1774 | task->tk_status == 0) {
|
| 1775 | nfs4_sequence_done(task, &hdr->res.seq_res);
|
| 1776 | return;
|
| 1777 | }
|
| 1778 |
|
| 1779 |
|
| 1780 | hdr->mds_ops->rpc_call_done(task, hdr);
|
| 1781 | }
|
| 1782 |
|
| 1783 | static void ff_layout_read_count_stats(struct rpc_task *task, void *data)
|
| 1784 | {
|
| 1785 | struct nfs_pgio_header *hdr = data;
|
| 1786 |
|
| 1787 | ff_layout_read_record_layoutstats_done(task, hdr);
|
| 1788 | rpc_count_iostats_metrics(task,
|
| 1789 | &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_READ]);
|
| 1790 | }
|
| 1791 |
|
| 1792 | static void ff_layout_read_release(void *data)
|
| 1793 | {
|
| 1794 | struct nfs_pgio_header *hdr = data;
|
| 1795 |
|
| 1796 | ff_layout_read_record_layoutstats_done(&hdr->task, hdr);
|
| 1797 | if (test_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags))
|
| 1798 | ff_layout_resend_pnfs_read(hdr);
|
| 1799 | else if (test_bit(NFS_IOHDR_RESEND_MDS, &hdr->flags))
|
| 1800 | ff_layout_reset_read(hdr);
|
| 1801 | pnfs_generic_rw_release(data);
|
| 1802 | }
|
| 1803 |
|
| 1804 |
|
| 1805 | static int ff_layout_write_done_cb(struct rpc_task *task,
|
| 1806 | struct nfs_pgio_header *hdr)
|
| 1807 | {
|
| 1808 | struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(hdr->lseg);
|
| 1809 | u32 dss_id = nfs4_ff_layout_calc_dss_id(
|
| 1810 | flseg->stripe_unit,
|
| 1811 | flseg->mirror_array[hdr->pgio_mirror_idx]->dss_count,
|
| 1812 | hdr->args.offset);
|
| 1813 | loff_t end_offs = 0;
|
| 1814 | int err;
|
| 1815 |
|
| 1816 | if (task->tk_status < 0) {
|
| 1817 | ff_layout_io_track_ds_error(hdr->lseg,
|
| 1818 | hdr->pgio_mirror_idx, dss_id,
|
| 1819 | hdr->args.offset, hdr->args.count,
|
| 1820 | &hdr->res.op_status, OP_WRITE,
|
| 1821 | task->tk_status);
|
| 1822 | trace_ff_layout_write_error(hdr, task->tk_status);
|
| 1823 | }
|
| 1824 |
|
| 1825 | err = ff_layout_async_handle_error(task, hdr->res.op_status,
|
| 1826 | hdr->args.context->state,
|
| 1827 | hdr->ds_clp, hdr->lseg,
|
| 1828 | hdr->pgio_mirror_idx,
|
| 1829 | dss_id);
|
| 1830 |
|
| 1831 | trace_nfs4_pnfs_write(hdr, err);
|
| 1832 | clear_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags);
|
| 1833 | clear_bit(NFS_IOHDR_RESEND_MDS, &hdr->flags);
|
| 1834 | switch (err) {
|
| 1835 | case -NFS4ERR_RESET_TO_PNFS:
|
| 1836 | set_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags);
|
| 1837 | return task->tk_status;
|
| 1838 | case -NFS4ERR_RESET_TO_MDS:
|
| 1839 | set_bit(NFS_IOHDR_RESEND_MDS, &hdr->flags);
|
| 1840 | return task->tk_status;
|
| 1841 | case -EAGAIN:
|
| 1842 | return -EAGAIN;
|
| 1843 | case -NFS4ERR_FATAL_IOERROR:
|
| 1844 | task->tk_status = -EIO;
|
| 1845 | return 0;
|
| 1846 | }
|
| 1847 |
|
| 1848 | if (hdr->res.verf->committed == NFS_FILE_SYNC ||
|
| 1849 | hdr->res.verf->committed == NFS_DATA_SYNC)
|
| 1850 | end_offs = hdr->mds_offset + (loff_t)hdr->res.count;
|
| 1851 |
|
| 1852 |
|
| 1853 | ff_layout_set_layoutcommit(hdr->inode, hdr->lseg, end_offs);
|
| 1854 |
|
| 1855 |
|
| 1856 | hdr->fattr.valid = 0;
|
| 1857 | if (task->tk_status >= 0)
|
| 1858 | nfs_writeback_update_inode(hdr);
|
| 1859 |
|
| 1860 | return 0;
|
| 1861 | }
|
| 1862 |
|
| 1863 | static int ff_layout_commit_done_cb(struct rpc_task *task,
|
| 1864 | struct nfs_commit_data *data)
|
| 1865 | {
|
| 1866 | int err;
|
| 1867 | u32 idx = calc_mirror_idx_from_commit(data->lseg, data->ds_commit_index);
|
| 1868 | u32 dss_id = calc_dss_id_from_commit(data->lseg, data->ds_commit_index);
|
| 1869 |
|
| 1870 | if (task->tk_status < 0) {
|
| 1871 | ff_layout_io_track_ds_error(data->lseg, idx, dss_id,
|
| 1872 | data->args.offset, data->args.count,
|
| 1873 | &data->res.op_status, OP_COMMIT,
|
| 1874 | task->tk_status);
|
| 1875 | trace_ff_layout_commit_error(data, task->tk_status);
|
| 1876 | }
|
| 1877 |
|
| 1878 | err = ff_layout_async_handle_error(task, data->res.op_status,
|
| 1879 | NULL, data->ds_clp, data->lseg, idx,
|
| 1880 | dss_id);
|
| 1881 |
|
| 1882 | trace_nfs4_pnfs_commit_ds(data, err);
|
| 1883 | switch (err) {
|
| 1884 | case -NFS4ERR_RESET_TO_PNFS:
|
| 1885 | pnfs_generic_prepare_to_resend_writes(data);
|
| 1886 | return -EAGAIN;
|
| 1887 | case -NFS4ERR_RESET_TO_MDS:
|
| 1888 | pnfs_generic_prepare_to_resend_writes(data);
|
| 1889 | return -EAGAIN;
|
| 1890 | case -EAGAIN:
|
| 1891 | rpc_restart_call_prepare(task);
|
| 1892 | return -EAGAIN;
|
| 1893 | case -NFS4ERR_FATAL_IOERROR:
|
| 1894 | task->tk_status = -EIO;
|
| 1895 | return 0;
|
| 1896 | }
|
| 1897 |
|
| 1898 | ff_layout_set_layoutcommit(data->inode, data->lseg, data->lwb);
|
| 1899 | return 0;
|
| 1900 | }
|
| 1901 |
|
| 1902 | static void ff_layout_write_record_layoutstats_start(struct rpc_task *task,
|
| 1903 | struct nfs_pgio_header *hdr)
|
| 1904 | {
|
| 1905 | struct nfs4_ff_layout_mirror *mirror;
|
| 1906 | u32 dss_id;
|
| 1907 |
|
| 1908 | if (test_and_set_bit(NFS_IOHDR_STAT, &hdr->flags))
|
| 1909 | return;
|
| 1910 |
|
| 1911 | mirror = FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx);
|
| 1912 | dss_id = nfs4_ff_layout_calc_dss_id(
|
| 1913 | FF_LAYOUT_LSEG(hdr->lseg)->stripe_unit,
|
| 1914 | mirror->dss_count,
|
| 1915 | hdr->args.offset);
|
| 1916 |
|
| 1917 | nfs4_ff_layout_stat_io_start_write(
|
| 1918 | hdr->inode,
|
| 1919 | mirror,
|
| 1920 | dss_id,
|
| 1921 | hdr->args.count,
|
| 1922 | task->tk_start);
|
| 1923 | }
|
| 1924 |
|
| 1925 | static void ff_layout_write_record_layoutstats_done(struct rpc_task *task,
|
| 1926 | struct nfs_pgio_header *hdr)
|
| 1927 | {
|
| 1928 | struct nfs4_ff_layout_mirror *mirror;
|
| 1929 | u32 dss_id;
|
| 1930 |
|
| 1931 | if (!test_and_clear_bit(NFS_IOHDR_STAT, &hdr->flags))
|
| 1932 | return;
|
| 1933 |
|
| 1934 | mirror = FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx);
|
| 1935 | dss_id = nfs4_ff_layout_calc_dss_id(
|
| 1936 | FF_LAYOUT_LSEG(hdr->lseg)->stripe_unit,
|
| 1937 | mirror->dss_count,
|
| 1938 | hdr->args.offset);
|
| 1939 |
|
| 1940 | nfs4_ff_layout_stat_io_end_write(
|
| 1941 | task,
|
| 1942 | mirror,
|
| 1943 | dss_id,
|
| 1944 | hdr->args.count,
|
| 1945 | hdr->res.count,
|
| 1946 | hdr->res.verf->committed);
|
| 1947 | set_bit(NFS_LSEG_LAYOUTRETURN, &hdr->lseg->pls_flags);
|
| 1948 | }
|
| 1949 |
|
| 1950 | static int ff_layout_write_prepare_common(struct rpc_task *task,
|
| 1951 | struct nfs_pgio_header *hdr)
|
| 1952 | {
|
| 1953 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
|
| 1954 | rpc_exit(task, -EIO);
|
| 1955 | return -EIO;
|
| 1956 | }
|
| 1957 |
|
| 1958 | if (!pnfs_is_valid_lseg(hdr->lseg)) {
|
| 1959 | rpc_exit(task, -EAGAIN);
|
| 1960 | return -EAGAIN;
|
| 1961 | }
|
| 1962 |
|
| 1963 | ff_layout_write_record_layoutstats_start(task, hdr);
|
| 1964 | return 0;
|
| 1965 | }
|
| 1966 |
|
| 1967 | static void ff_layout_write_prepare_v3(struct rpc_task *task, void *data)
|
| 1968 | {
|
| 1969 | struct nfs_pgio_header *hdr = data;
|
| 1970 |
|
| 1971 | if (ff_layout_write_prepare_common(task, hdr))
|
| 1972 | return;
|
| 1973 |
|
| 1974 | rpc_call_start(task);
|
| 1975 | }
|
| 1976 |
|
| 1977 | static void ff_layout_write_prepare_v4(struct rpc_task *task, void *data)
|
| 1978 | {
|
| 1979 | struct nfs_pgio_header *hdr = data;
|
| 1980 |
|
| 1981 | if (nfs4_setup_sequence(hdr->ds_clp,
|
| 1982 | &hdr->args.seq_args,
|
| 1983 | &hdr->res.seq_res,
|
| 1984 | task))
|
| 1985 | return;
|
| 1986 |
|
| 1987 | ff_layout_write_prepare_common(task, hdr);
|
| 1988 | }
|
| 1989 |
|
| 1990 | static void ff_layout_write_call_done(struct rpc_task *task, void *data)
|
| 1991 | {
|
| 1992 | struct nfs_pgio_header *hdr = data;
|
| 1993 |
|
| 1994 | if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
|
| 1995 | task->tk_status == 0) {
|
| 1996 | nfs4_sequence_done(task, &hdr->res.seq_res);
|
| 1997 | return;
|
| 1998 | }
|
| 1999 |
|
| 2000 |
|
| 2001 | hdr->mds_ops->rpc_call_done(task, hdr);
|
| 2002 | }
|
| 2003 |
|
| 2004 | static void ff_layout_write_count_stats(struct rpc_task *task, void *data)
|
| 2005 | {
|
| 2006 | struct nfs_pgio_header *hdr = data;
|
| 2007 |
|
| 2008 | ff_layout_write_record_layoutstats_done(task, hdr);
|
| 2009 | rpc_count_iostats_metrics(task,
|
| 2010 | &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_WRITE]);
|
| 2011 | }
|
| 2012 |
|
| 2013 | static void ff_layout_write_release(void *data)
|
| 2014 | {
|
| 2015 | struct nfs_pgio_header *hdr = data;
|
| 2016 |
|
| 2017 | ff_layout_write_record_layoutstats_done(&hdr->task, hdr);
|
| 2018 | if (test_bit(NFS_IOHDR_RESEND_PNFS, &hdr->flags)) {
|
| 2019 | ff_layout_send_layouterror(hdr->lseg);
|
| 2020 | ff_layout_reset_write(hdr, true);
|
| 2021 | } else if (test_bit(NFS_IOHDR_RESEND_MDS, &hdr->flags))
|
| 2022 | ff_layout_reset_write(hdr, false);
|
| 2023 | pnfs_generic_rw_release(data);
|
| 2024 | }
|
| 2025 |
|
| 2026 | static void ff_layout_commit_record_layoutstats_start(struct rpc_task *task,
|
| 2027 | struct nfs_commit_data *cdata)
|
| 2028 | {
|
| 2029 | u32 idx, dss_id;
|
| 2030 |
|
| 2031 | if (test_and_set_bit(NFS_IOHDR_STAT, &cdata->flags))
|
| 2032 | return;
|
| 2033 |
|
| 2034 | idx = calc_mirror_idx_from_commit(cdata->lseg, cdata->ds_commit_index);
|
| 2035 | dss_id = calc_dss_id_from_commit(cdata->lseg, cdata->ds_commit_index);
|
| 2036 | nfs4_ff_layout_stat_io_start_write(cdata->inode,
|
| 2037 | FF_LAYOUT_COMP(cdata->lseg, idx),
|
| 2038 | dss_id,
|
| 2039 | 0, task->tk_start);
|
| 2040 | }
|
| 2041 |
|
| 2042 | static void ff_layout_commit_record_layoutstats_done(struct rpc_task *task,
|
| 2043 | struct nfs_commit_data *cdata)
|
| 2044 | {
|
| 2045 | struct nfs_page *req;
|
| 2046 | __u64 count = 0;
|
| 2047 | u32 idx, dss_id;
|
| 2048 |
|
| 2049 | if (!test_and_clear_bit(NFS_IOHDR_STAT, &cdata->flags))
|
| 2050 | return;
|
| 2051 |
|
| 2052 | if (task->tk_status == 0) {
|
| 2053 | list_for_each_entry(req, &cdata->pages, wb_list)
|
| 2054 | count += req->wb_bytes;
|
| 2055 | }
|
| 2056 |
|
| 2057 | idx = calc_mirror_idx_from_commit(cdata->lseg, cdata->ds_commit_index);
|
| 2058 | dss_id = calc_dss_id_from_commit(cdata->lseg, cdata->ds_commit_index);
|
| 2059 | nfs4_ff_layout_stat_io_end_write(task,
|
| 2060 | FF_LAYOUT_COMP(cdata->lseg, idx),
|
| 2061 | dss_id,
|
| 2062 | count, count, NFS_FILE_SYNC);
|
| 2063 | set_bit(NFS_LSEG_LAYOUTRETURN, &cdata->lseg->pls_flags);
|
| 2064 | }
|
| 2065 |
|
| 2066 | static int ff_layout_commit_prepare_common(struct rpc_task *task,
|
| 2067 | struct nfs_commit_data *cdata)
|
| 2068 | {
|
| 2069 | if (!pnfs_is_valid_lseg(cdata->lseg)) {
|
| 2070 | rpc_exit(task, -EAGAIN);
|
| 2071 | return -EAGAIN;
|
| 2072 | }
|
| 2073 |
|
| 2074 | ff_layout_commit_record_layoutstats_start(task, cdata);
|
| 2075 | return 0;
|
| 2076 | }
|
| 2077 |
|
| 2078 | static void ff_layout_commit_prepare_v3(struct rpc_task *task, void *data)
|
| 2079 | {
|
| 2080 | if (ff_layout_commit_prepare_common(task, data))
|
| 2081 | return;
|
| 2082 |
|
| 2083 | rpc_call_start(task);
|
| 2084 | }
|
| 2085 |
|
| 2086 | static void ff_layout_commit_prepare_v4(struct rpc_task *task, void *data)
|
| 2087 | {
|
| 2088 | struct nfs_commit_data *wdata = data;
|
| 2089 |
|
| 2090 | if (nfs4_setup_sequence(wdata->ds_clp,
|
| 2091 | &wdata->args.seq_args,
|
| 2092 | &wdata->res.seq_res,
|
| 2093 | task))
|
| 2094 | return;
|
| 2095 | ff_layout_commit_prepare_common(task, data);
|
| 2096 | }
|
| 2097 |
|
| 2098 | static void ff_layout_commit_done(struct rpc_task *task, void *data)
|
| 2099 | {
|
| 2100 | pnfs_generic_write_commit_done(task, data);
|
| 2101 | }
|
| 2102 |
|
| 2103 | static void ff_layout_commit_count_stats(struct rpc_task *task, void *data)
|
| 2104 | {
|
| 2105 | struct nfs_commit_data *cdata = data;
|
| 2106 |
|
| 2107 | ff_layout_commit_record_layoutstats_done(task, cdata);
|
| 2108 | rpc_count_iostats_metrics(task,
|
| 2109 | &NFS_CLIENT(cdata->inode)->cl_metrics[NFSPROC4_CLNT_COMMIT]);
|
| 2110 | }
|
| 2111 |
|
| 2112 | static void ff_layout_commit_release(void *data)
|
| 2113 | {
|
| 2114 | struct nfs_commit_data *cdata = data;
|
| 2115 |
|
| 2116 | ff_layout_commit_record_layoutstats_done(&cdata->task, cdata);
|
| 2117 | pnfs_generic_commit_release(data);
|
| 2118 | }
|
| 2119 |
|
| 2120 | static const struct rpc_call_ops ff_layout_read_call_ops_v3 = {
|
| 2121 | .rpc_call_prepare = ff_layout_read_prepare_v3,
|
| 2122 | .rpc_call_done = ff_layout_read_call_done,
|
| 2123 | .rpc_count_stats = ff_layout_read_count_stats,
|
| 2124 | .rpc_release = ff_layout_read_release,
|
| 2125 | };
|
| 2126 |
|
| 2127 | static const struct rpc_call_ops ff_layout_read_call_ops_v4 = {
|
| 2128 | .rpc_call_prepare = ff_layout_read_prepare_v4,
|
| 2129 | .rpc_call_done = ff_layout_read_call_done,
|
| 2130 | .rpc_count_stats = ff_layout_read_count_stats,
|
| 2131 | .rpc_release = ff_layout_read_release,
|
| 2132 | };
|
| 2133 |
|
| 2134 | static const struct rpc_call_ops ff_layout_write_call_ops_v3 = {
|
| 2135 | .rpc_call_prepare = ff_layout_write_prepare_v3,
|
| 2136 | .rpc_call_done = ff_layout_write_call_done,
|
| 2137 | .rpc_count_stats = ff_layout_write_count_stats,
|
| 2138 | .rpc_release = ff_layout_write_release,
|
| 2139 | };
|
| 2140 |
|
| 2141 | static const struct rpc_call_ops ff_layout_write_call_ops_v4 = {
|
| 2142 | .rpc_call_prepare = ff_layout_write_prepare_v4,
|
| 2143 | .rpc_call_done = ff_layout_write_call_done,
|
| 2144 | .rpc_count_stats = ff_layout_write_count_stats,
|
| 2145 | .rpc_release = ff_layout_write_release,
|
| 2146 | };
|
| 2147 |
|
| 2148 | static const struct rpc_call_ops ff_layout_commit_call_ops_v3 = {
|
| 2149 | .rpc_call_prepare = ff_layout_commit_prepare_v3,
|
| 2150 | .rpc_call_done = ff_layout_commit_done,
|
| 2151 | .rpc_count_stats = ff_layout_commit_count_stats,
|
| 2152 | .rpc_release = ff_layout_commit_release,
|
| 2153 | };
|
| 2154 |
|
| 2155 | static const struct rpc_call_ops ff_layout_commit_call_ops_v4 = {
|
| 2156 | .rpc_call_prepare = ff_layout_commit_prepare_v4,
|
| 2157 | .rpc_call_done = ff_layout_commit_done,
|
| 2158 | .rpc_count_stats = ff_layout_commit_count_stats,
|
| 2159 | .rpc_release = ff_layout_commit_release,
|
| 2160 | };
|
| 2161 |
|
| 2162 | static enum pnfs_try_status
|
| 2163 | ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
|
| 2164 | {
|
| 2165 | struct pnfs_layout_segment *lseg = hdr->lseg;
|
| 2166 | struct nfs4_pnfs_ds *ds;
|
| 2167 | struct rpc_clnt *ds_clnt;
|
| 2168 | struct nfsd_file *localio;
|
| 2169 | struct nfs4_ff_layout_mirror *mirror;
|
| 2170 | const struct cred *ds_cred;
|
| 2171 | loff_t offset = hdr->args.offset;
|
| 2172 | u32 idx = hdr->pgio_mirror_idx;
|
| 2173 | int vers;
|
| 2174 | struct nfs_fh *fh;
|
| 2175 | u32 dss_id;
|
| 2176 | bool ds_fatal_error = false;
|
| 2177 |
|
| 2178 | dprintk("--> %s ino %llu pgbase %u req %zu@%llu\n",
|
| 2179 | __func__, hdr->inode->i_ino,
|
| 2180 | hdr->args.pgbase, (size_t)hdr->args.count, offset);
|
| 2181 |
|
| 2182 | mirror = FF_LAYOUT_COMP(lseg, idx);
|
| 2183 | dss_id = nfs4_ff_layout_calc_dss_id(
|
| 2184 | FF_LAYOUT_LSEG(lseg)->stripe_unit,
|
| 2185 | mirror->dss_count,
|
| 2186 | offset);
|
| 2187 | ds = nfs4_ff_layout_prepare_ds(lseg, mirror, dss_id, false);
|
| 2188 | if (IS_ERR(ds)) {
|
| 2189 | ds_fatal_error = nfs_error_is_fatal(PTR_ERR(ds));
|
| 2190 | goto out_failed;
|
| 2191 | }
|
| 2192 |
|
| 2193 | ds_clnt = nfs4_ff_find_or_create_ds_client(mirror, ds->ds_clp,
|
| 2194 | hdr->inode, dss_id);
|
| 2195 | if (IS_ERR(ds_clnt))
|
| 2196 | goto out_failed;
|
| 2197 |
|
| 2198 | ds_cred = ff_layout_get_ds_cred(mirror, &lseg->pls_range, hdr->cred, dss_id);
|
| 2199 | if (!ds_cred)
|
| 2200 | goto out_failed;
|
| 2201 |
|
| 2202 | vers = nfs4_ff_layout_ds_version(mirror, dss_id);
|
| 2203 |
|
| 2204 | dprintk("%s USE DS: %s cl_count %d vers %d\n", __func__,
|
| 2205 | ds->ds_remotestr, refcount_read(&ds->ds_clp->cl_count), vers);
|
| 2206 |
|
| 2207 | hdr->pgio_done_cb = ff_layout_read_done_cb;
|
| 2208 | refcount_inc(&ds->ds_clp->cl_count);
|
| 2209 | hdr->ds_clp = ds->ds_clp;
|
| 2210 | fh = nfs4_ff_layout_select_ds_fh(mirror, dss_id);
|
| 2211 | if (fh)
|
| 2212 | hdr->args.fh = fh;
|
| 2213 |
|
| 2214 | nfs4_ff_layout_select_ds_stateid(mirror, dss_id, &hdr->args.stateid);
|
| 2215 |
|
| 2216 | |
| 2217 | * Note that if we ever decide to split across DSes,
|
| 2218 | * then we may need to handle dense-like offsets.
|
| 2219 |
|
| 2220 | hdr->args.offset = offset;
|
| 2221 | hdr->mds_offset = offset;
|
| 2222 |
|
| 2223 |
|
| 2224 | localio = ff_local_open_fh(lseg, idx, dss_id, ds->ds_clp, ds_cred, fh,
|
| 2225 | FMODE_READ);
|
| 2226 | if (localio) {
|
| 2227 | hdr->task.tk_start = ktime_get();
|
| 2228 | ff_layout_read_record_layoutstats_start(&hdr->task, hdr);
|
| 2229 | }
|
| 2230 |
|
| 2231 |
|
| 2232 | nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
|
| 2233 | vers == 3 ? &ff_layout_read_call_ops_v3 :
|
| 2234 | &ff_layout_read_call_ops_v4,
|
| 2235 | 0, RPC_TASK_SOFTCONN, localio);
|
| 2236 | put_cred(ds_cred);
|
| 2237 | return PNFS_ATTEMPTED;
|
| 2238 |
|
| 2239 | out_failed:
|
| 2240 | if (ff_layout_avoid_mds_available_ds(lseg) && !ds_fatal_error)
|
| 2241 | return PNFS_TRY_AGAIN;
|
| 2242 | if (ff_layout_no_fallback_to_mds(lseg)) {
|
| 2243 | |
| 2244 | * FF_FLAGS_NO_IO_THRU_MDS: force fresh LAYOUTGET,
|
| 2245 | * never fall through to MDS I/O.
|
| 2246 |
|
| 2247 | pnfs_error_mark_layout_for_return(hdr->inode, lseg);
|
| 2248 | return PNFS_TRY_AGAIN;
|
| 2249 | }
|
| 2250 | trace_pnfs_mds_fallback_read_pagelist(hdr->inode,
|
| 2251 | hdr->args.offset, hdr->args.count,
|
| 2252 | IOMODE_READ, NFS_I(hdr->inode)->layout, lseg);
|
| 2253 | return PNFS_NOT_ATTEMPTED;
|
| 2254 | }
|
| 2255 |
|
| 2256 |
|
| 2257 | static enum pnfs_try_status
|
| 2258 | ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
|
| 2259 | {
|
| 2260 | struct pnfs_layout_segment *lseg = hdr->lseg;
|
| 2261 | struct nfs4_pnfs_ds *ds;
|
| 2262 | struct rpc_clnt *ds_clnt;
|
| 2263 | struct nfsd_file *localio;
|
| 2264 | struct nfs4_ff_layout_mirror *mirror;
|
| 2265 | const struct cred *ds_cred;
|
| 2266 | loff_t offset = hdr->args.offset;
|
| 2267 | int vers;
|
| 2268 | struct nfs_fh *fh;
|
| 2269 | u32 idx = hdr->pgio_mirror_idx;
|
| 2270 | u32 dss_id;
|
| 2271 | bool ds_fatal_error = false;
|
| 2272 |
|
| 2273 | mirror = FF_LAYOUT_COMP(lseg, idx);
|
| 2274 | dss_id = nfs4_ff_layout_calc_dss_id(
|
| 2275 | FF_LAYOUT_LSEG(lseg)->stripe_unit,
|
| 2276 | mirror->dss_count,
|
| 2277 | offset);
|
| 2278 | ds = nfs4_ff_layout_prepare_ds(lseg, mirror, dss_id, true);
|
| 2279 | if (IS_ERR(ds)) {
|
| 2280 | ds_fatal_error = nfs_error_is_fatal(PTR_ERR(ds));
|
| 2281 | goto out_failed;
|
| 2282 | }
|
| 2283 |
|
| 2284 | ds_clnt = nfs4_ff_find_or_create_ds_client(mirror, ds->ds_clp,
|
| 2285 | hdr->inode, dss_id);
|
| 2286 | if (IS_ERR(ds_clnt))
|
| 2287 | goto out_failed;
|
| 2288 |
|
| 2289 | ds_cred = ff_layout_get_ds_cred(mirror, &lseg->pls_range, hdr->cred, dss_id);
|
| 2290 | if (!ds_cred)
|
| 2291 | goto out_failed;
|
| 2292 |
|
| 2293 | vers = nfs4_ff_layout_ds_version(mirror, dss_id);
|
| 2294 |
|
| 2295 | dprintk("%s ino %llu sync %d req %zu@%llu DS: %s cl_count %d vers %d\n",
|
| 2296 | __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count,
|
| 2297 | offset, ds->ds_remotestr, refcount_read(&ds->ds_clp->cl_count),
|
| 2298 | vers);
|
| 2299 |
|
| 2300 | hdr->pgio_done_cb = ff_layout_write_done_cb;
|
| 2301 | refcount_inc(&ds->ds_clp->cl_count);
|
| 2302 | hdr->ds_clp = ds->ds_clp;
|
| 2303 | hdr->ds_commit_idx = calc_commit_idx(lseg, idx, dss_id);
|
| 2304 | fh = nfs4_ff_layout_select_ds_fh(mirror, dss_id);
|
| 2305 | if (fh)
|
| 2306 | hdr->args.fh = fh;
|
| 2307 |
|
| 2308 | nfs4_ff_layout_select_ds_stateid(mirror, dss_id, &hdr->args.stateid);
|
| 2309 |
|
| 2310 | |
| 2311 | * Note that if we ever decide to split across DSes,
|
| 2312 | * then we may need to handle dense-like offsets.
|
| 2313 |
|
| 2314 | hdr->args.offset = offset;
|
| 2315 |
|
| 2316 |
|
| 2317 | localio = ff_local_open_fh(lseg, idx, dss_id, ds->ds_clp, ds_cred, fh,
|
| 2318 | FMODE_READ|FMODE_WRITE);
|
| 2319 | if (localio) {
|
| 2320 | hdr->task.tk_start = ktime_get();
|
| 2321 | ff_layout_write_record_layoutstats_start(&hdr->task, hdr);
|
| 2322 | }
|
| 2323 |
|
| 2324 |
|
| 2325 | nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
|
| 2326 | vers == 3 ? &ff_layout_write_call_ops_v3 :
|
| 2327 | &ff_layout_write_call_ops_v4,
|
| 2328 | sync, RPC_TASK_SOFTCONN, localio);
|
| 2329 | put_cred(ds_cred);
|
| 2330 | return PNFS_ATTEMPTED;
|
| 2331 |
|
| 2332 | out_failed:
|
| 2333 | if (ff_layout_avoid_mds_available_ds(lseg) && !ds_fatal_error)
|
| 2334 | return PNFS_TRY_AGAIN;
|
| 2335 | if (ff_layout_no_fallback_to_mds(lseg)) {
|
| 2336 | |
| 2337 | * FF_FLAGS_NO_IO_THRU_MDS: force fresh LAYOUTGET,
|
| 2338 | * never fall through to MDS I/O.
|
| 2339 |
|
| 2340 | pnfs_error_mark_layout_for_return(hdr->inode, lseg);
|
| 2341 | return PNFS_TRY_AGAIN;
|
| 2342 | }
|
| 2343 | trace_pnfs_mds_fallback_write_pagelist(hdr->inode,
|
| 2344 | hdr->args.offset, hdr->args.count,
|
| 2345 | IOMODE_RW, NFS_I(hdr->inode)->layout, lseg);
|
| 2346 | return PNFS_NOT_ATTEMPTED;
|
| 2347 | }
|
| 2348 |
|
| 2349 | static struct nfs_fh *
|
| 2350 | select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i, u32 dss_id)
|
| 2351 | {
|
| 2352 | struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg);
|
| 2353 |
|
| 2354 | |
| 2355 | * for the DS.
|
| 2356 |
|
| 2357 | return &flseg->mirror_array[i]->dss[dss_id].fh_versions[0];
|
| 2358 | }
|
| 2359 |
|
| 2360 | static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
|
| 2361 | {
|
| 2362 | struct pnfs_layout_segment *lseg = data->lseg;
|
| 2363 | struct nfs4_pnfs_ds *ds;
|
| 2364 | struct rpc_clnt *ds_clnt;
|
| 2365 | struct nfsd_file *localio;
|
| 2366 | struct nfs4_ff_layout_mirror *mirror;
|
| 2367 | const struct cred *ds_cred;
|
| 2368 | u32 idx, dss_id;
|
| 2369 | int vers, ret;
|
| 2370 | struct nfs_fh *fh;
|
| 2371 |
|
| 2372 | if (!lseg || !(pnfs_is_valid_lseg(lseg) ||
|
| 2373 | test_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags)))
|
| 2374 | goto out_err;
|
| 2375 |
|
| 2376 | idx = calc_mirror_idx_from_commit(lseg, data->ds_commit_index);
|
| 2377 | mirror = FF_LAYOUT_COMP(lseg, idx);
|
| 2378 | dss_id = calc_dss_id_from_commit(lseg, data->ds_commit_index);
|
| 2379 | ds = nfs4_ff_layout_prepare_ds(lseg, mirror, dss_id, true);
|
| 2380 | if (IS_ERR(ds))
|
| 2381 | goto out_err;
|
| 2382 |
|
| 2383 | ds_clnt = nfs4_ff_find_or_create_ds_client(mirror, ds->ds_clp,
|
| 2384 | data->inode, dss_id);
|
| 2385 | if (IS_ERR(ds_clnt))
|
| 2386 | goto out_err;
|
| 2387 |
|
| 2388 | ds_cred = ff_layout_get_ds_cred(mirror, &lseg->pls_range, data->cred, dss_id);
|
| 2389 | if (!ds_cred)
|
| 2390 | goto out_err;
|
| 2391 |
|
| 2392 | vers = nfs4_ff_layout_ds_version(mirror, dss_id);
|
| 2393 |
|
| 2394 | dprintk("%s ino %llu, how %d cl_count %d vers %d\n", __func__,
|
| 2395 | data->inode->i_ino, how, refcount_read(&ds->ds_clp->cl_count),
|
| 2396 | vers);
|
| 2397 | data->commit_done_cb = ff_layout_commit_done_cb;
|
| 2398 | data->cred = ds_cred;
|
| 2399 | refcount_inc(&ds->ds_clp->cl_count);
|
| 2400 | data->ds_clp = ds->ds_clp;
|
| 2401 | fh = select_ds_fh_from_commit(lseg, idx, dss_id);
|
| 2402 | if (fh)
|
| 2403 | data->args.fh = fh;
|
| 2404 |
|
| 2405 |
|
| 2406 | localio = ff_local_open_fh(lseg, idx, dss_id, ds->ds_clp, ds_cred, fh,
|
| 2407 | FMODE_READ|FMODE_WRITE);
|
| 2408 | if (localio) {
|
| 2409 | data->task.tk_start = ktime_get();
|
| 2410 | ff_layout_commit_record_layoutstats_start(&data->task, data);
|
| 2411 | }
|
| 2412 |
|
| 2413 | ret = nfs_initiate_commit(ds_clnt, data, ds->ds_clp->rpc_ops,
|
| 2414 | vers == 3 ? &ff_layout_commit_call_ops_v3 :
|
| 2415 | &ff_layout_commit_call_ops_v4,
|
| 2416 | how, RPC_TASK_SOFTCONN, localio);
|
| 2417 | put_cred(ds_cred);
|
| 2418 | return ret;
|
| 2419 | out_err:
|
| 2420 | pnfs_generic_prepare_to_resend_writes(data);
|
| 2421 | pnfs_generic_commit_release(data);
|
| 2422 | return -EAGAIN;
|
| 2423 | }
|
| 2424 |
|
| 2425 | static int
|
| 2426 | ff_layout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
|
| 2427 | int how, struct nfs_commit_info *cinfo)
|
| 2428 | {
|
| 2429 | return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo,
|
| 2430 | ff_layout_initiate_commit);
|
| 2431 | }
|
| 2432 |
|
| 2433 | static bool ff_layout_match_rw(const struct rpc_task *task,
|
| 2434 | const struct nfs_pgio_header *hdr,
|
| 2435 | const struct pnfs_layout_segment *lseg)
|
| 2436 | {
|
| 2437 | return hdr->lseg == lseg;
|
| 2438 | }
|
| 2439 |
|
| 2440 | static bool ff_layout_match_commit(const struct rpc_task *task,
|
| 2441 | const struct nfs_commit_data *cdata,
|
| 2442 | const struct pnfs_layout_segment *lseg)
|
| 2443 | {
|
| 2444 | return cdata->lseg == lseg;
|
| 2445 | }
|
| 2446 |
|
| 2447 | static bool ff_layout_match_io(const struct rpc_task *task, const void *data)
|
| 2448 | {
|
| 2449 | const struct rpc_call_ops *ops = task->tk_ops;
|
| 2450 |
|
| 2451 | if (ops == &ff_layout_read_call_ops_v3 ||
|
| 2452 | ops == &ff_layout_read_call_ops_v4 ||
|
| 2453 | ops == &ff_layout_write_call_ops_v3 ||
|
| 2454 | ops == &ff_layout_write_call_ops_v4)
|
| 2455 | return ff_layout_match_rw(task, task->tk_calldata, data);
|
| 2456 | if (ops == &ff_layout_commit_call_ops_v3 ||
|
| 2457 | ops == &ff_layout_commit_call_ops_v4)
|
| 2458 | return ff_layout_match_commit(task, task->tk_calldata, data);
|
| 2459 | return false;
|
| 2460 | }
|
| 2461 |
|
| 2462 | static void ff_layout_cancel_io(struct pnfs_layout_segment *lseg)
|
| 2463 | {
|
| 2464 | struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg);
|
| 2465 | struct nfs4_ff_layout_mirror *mirror;
|
| 2466 | struct nfs4_ff_layout_ds *mirror_ds;
|
| 2467 | struct nfs4_pnfs_ds *ds;
|
| 2468 | struct nfs_client *ds_clp;
|
| 2469 | struct rpc_clnt *clnt;
|
| 2470 | u32 idx, dss_id;
|
| 2471 |
|
| 2472 | for (idx = 0; idx < flseg->mirror_array_cnt; idx++) {
|
| 2473 | mirror = flseg->mirror_array[idx];
|
| 2474 | for (dss_id = 0; dss_id < mirror->dss_count; dss_id++) {
|
| 2475 | mirror_ds = mirror->dss[dss_id].mirror_ds;
|
| 2476 | if (IS_ERR_OR_NULL(mirror_ds))
|
| 2477 | continue;
|
| 2478 | ds = mirror->dss[dss_id].mirror_ds->ds;
|
| 2479 | if (!ds)
|
| 2480 | continue;
|
| 2481 | ds_clp = ds->ds_clp;
|
| 2482 | if (!ds_clp)
|
| 2483 | continue;
|
| 2484 | clnt = ds_clp->cl_rpcclient;
|
| 2485 | if (!clnt)
|
| 2486 | continue;
|
| 2487 | if (!rpc_cancel_tasks(clnt, -ECANCELED,
|
| 2488 | ff_layout_match_io, lseg))
|
| 2489 | continue;
|
| 2490 | rpc_clnt_disconnect(clnt);
|
| 2491 | }
|
| 2492 | }
|
| 2493 | }
|
| 2494 |
|
| 2495 | static struct pnfs_ds_commit_info *
|
| 2496 | ff_layout_get_ds_info(struct inode *inode)
|
| 2497 | {
|
| 2498 | struct pnfs_layout_hdr *layout = NFS_I(inode)->layout;
|
| 2499 |
|
| 2500 | if (layout == NULL)
|
| 2501 | return NULL;
|
| 2502 |
|
| 2503 | return &FF_LAYOUT_FROM_HDR(layout)->commit_info;
|
| 2504 | }
|
| 2505 |
|
| 2506 | static void
|
| 2507 | ff_layout_setup_ds_info(struct pnfs_ds_commit_info *fl_cinfo,
|
| 2508 | struct pnfs_layout_segment *lseg)
|
| 2509 | {
|
| 2510 | struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg);
|
| 2511 | struct inode *inode = lseg->pls_layout->plh_inode;
|
| 2512 | struct pnfs_commit_array *array, *new;
|
| 2513 | u32 size = flseg->mirror_array_cnt * flseg->mirror_array[0]->dss_count;
|
| 2514 |
|
| 2515 | new = pnfs_alloc_commit_array(size,
|
| 2516 | nfs_io_gfp_mask());
|
| 2517 | if (new) {
|
| 2518 | spin_lock(&inode->i_lock);
|
| 2519 | array = pnfs_add_commit_array(fl_cinfo, new, lseg);
|
| 2520 | spin_unlock(&inode->i_lock);
|
| 2521 | if (array != new)
|
| 2522 | pnfs_free_commit_array(new);
|
| 2523 | }
|
| 2524 | }
|
| 2525 |
|
| 2526 | static void
|
| 2527 | ff_layout_release_ds_info(struct pnfs_ds_commit_info *fl_cinfo,
|
| 2528 | struct inode *inode)
|
| 2529 | {
|
| 2530 | spin_lock(&inode->i_lock);
|
| 2531 | pnfs_generic_ds_cinfo_destroy(fl_cinfo);
|
| 2532 | spin_unlock(&inode->i_lock);
|
| 2533 | }
|
| 2534 |
|
| 2535 | static void
|
| 2536 | ff_layout_free_deviceid_node(struct nfs4_deviceid_node *d)
|
| 2537 | {
|
| 2538 | nfs4_ff_layout_free_deviceid(container_of(d, struct nfs4_ff_layout_ds,
|
| 2539 | id_node));
|
| 2540 | }
|
| 2541 |
|
| 2542 | static int ff_layout_encode_ioerr(struct xdr_stream *xdr,
|
| 2543 | const struct nfs4_layoutreturn_args *args,
|
| 2544 | const struct nfs4_flexfile_layoutreturn_args *ff_args)
|
| 2545 | {
|
| 2546 | __be32 *start;
|
| 2547 |
|
| 2548 | start = xdr_reserve_space(xdr, 4);
|
| 2549 | if (unlikely(!start))
|
| 2550 | return -E2BIG;
|
| 2551 |
|
| 2552 | *start = cpu_to_be32(ff_args->num_errors);
|
| 2553 |
|
| 2554 | return ff_layout_encode_ds_ioerr(xdr, &ff_args->errors);
|
| 2555 | }
|
| 2556 |
|
| 2557 | static void
|
| 2558 | ff_layout_encode_ff_iostat_head(struct xdr_stream *xdr,
|
| 2559 | const nfs4_stateid *stateid,
|
| 2560 | const struct nfs42_layoutstat_devinfo *devinfo)
|
| 2561 | {
|
| 2562 | __be32 *p;
|
| 2563 |
|
| 2564 | p = xdr_reserve_space(xdr, 8 + 8);
|
| 2565 | p = xdr_encode_hyper(p, devinfo->offset);
|
| 2566 | p = xdr_encode_hyper(p, devinfo->length);
|
| 2567 | encode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
|
| 2568 | p = xdr_reserve_space(xdr, 4*8);
|
| 2569 | p = xdr_encode_hyper(p, devinfo->read_count);
|
| 2570 | p = xdr_encode_hyper(p, devinfo->read_bytes);
|
| 2571 | p = xdr_encode_hyper(p, devinfo->write_count);
|
| 2572 | p = xdr_encode_hyper(p, devinfo->write_bytes);
|
| 2573 | encode_opaque_fixed(xdr, devinfo->dev_id.data, NFS4_DEVICEID4_SIZE);
|
| 2574 | }
|
| 2575 |
|
| 2576 | static void
|
| 2577 | ff_layout_encode_ff_iostat(struct xdr_stream *xdr,
|
| 2578 | const nfs4_stateid *stateid,
|
| 2579 | const struct nfs42_layoutstat_devinfo *devinfo)
|
| 2580 | {
|
| 2581 | ff_layout_encode_ff_iostat_head(xdr, stateid, devinfo);
|
| 2582 | ff_layout_encode_ff_layoutupdate(xdr, devinfo,
|
| 2583 | devinfo->ld_private.data);
|
| 2584 | }
|
| 2585 |
|
| 2586 |
|
| 2587 | static void ff_layout_encode_iostats_array(struct xdr_stream *xdr,
|
| 2588 | const struct nfs4_layoutreturn_args *args,
|
| 2589 | struct nfs4_flexfile_layoutreturn_args *ff_args)
|
| 2590 | {
|
| 2591 | __be32 *p;
|
| 2592 | int i;
|
| 2593 |
|
| 2594 | p = xdr_reserve_space(xdr, 4);
|
| 2595 | *p = cpu_to_be32(ff_args->num_dev);
|
| 2596 | for (i = 0; i < ff_args->num_dev; i++)
|
| 2597 | ff_layout_encode_ff_iostat(xdr,
|
| 2598 | &args->layout->plh_stateid,
|
| 2599 | &ff_args->devinfo[i]);
|
| 2600 | }
|
| 2601 |
|
| 2602 | static void
|
| 2603 | ff_layout_free_iostats_array(struct nfs42_layoutstat_devinfo *devinfo,
|
| 2604 | unsigned int num_entries)
|
| 2605 | {
|
| 2606 | unsigned int i;
|
| 2607 |
|
| 2608 | for (i = 0; i < num_entries; i++) {
|
| 2609 | if (!devinfo[i].ld_private.ops)
|
| 2610 | continue;
|
| 2611 | if (!devinfo[i].ld_private.ops->free)
|
| 2612 | continue;
|
| 2613 | devinfo[i].ld_private.ops->free(&devinfo[i].ld_private);
|
| 2614 | }
|
| 2615 | }
|
| 2616 |
|
| 2617 | static struct nfs4_deviceid_node *
|
| 2618 | ff_layout_alloc_deviceid_node(struct nfs_server *server,
|
| 2619 | struct pnfs_device *pdev, gfp_t gfp_flags)
|
| 2620 | {
|
| 2621 | struct nfs4_ff_layout_ds *dsaddr;
|
| 2622 |
|
| 2623 | dsaddr = nfs4_ff_alloc_deviceid_node(server, pdev, gfp_flags);
|
| 2624 | if (!dsaddr)
|
| 2625 | return NULL;
|
| 2626 | return &dsaddr->id_node;
|
| 2627 | }
|
| 2628 |
|
| 2629 | static void
|
| 2630 | ff_layout_encode_layoutreturn(struct xdr_stream *xdr,
|
| 2631 | const void *voidargs,
|
| 2632 | const struct nfs4_xdr_opaque_data *ff_opaque)
|
| 2633 | {
|
| 2634 | const struct nfs4_layoutreturn_args *args = voidargs;
|
| 2635 | struct nfs4_flexfile_layoutreturn_args *ff_args = ff_opaque->data;
|
| 2636 | struct xdr_buf tmp_buf = {
|
| 2637 | .head = {
|
| 2638 | [0] = {
|
| 2639 | .iov_base = page_address(ff_args->pages[0]),
|
| 2640 | },
|
| 2641 | },
|
| 2642 | .buflen = PAGE_SIZE,
|
| 2643 | };
|
| 2644 | struct xdr_stream tmp_xdr;
|
| 2645 | __be32 *start;
|
| 2646 |
|
| 2647 | dprintk("%s: Begin\n", __func__);
|
| 2648 |
|
| 2649 | xdr_init_encode(&tmp_xdr, &tmp_buf, NULL, NULL);
|
| 2650 |
|
| 2651 | ff_layout_encode_ioerr(&tmp_xdr, args, ff_args);
|
| 2652 | ff_layout_encode_iostats_array(&tmp_xdr, args, ff_args);
|
| 2653 |
|
| 2654 | start = xdr_reserve_space(xdr, 4);
|
| 2655 | *start = cpu_to_be32(tmp_buf.len);
|
| 2656 | xdr_write_pages(xdr, ff_args->pages, 0, tmp_buf.len);
|
| 2657 |
|
| 2658 | dprintk("%s: Return\n", __func__);
|
| 2659 | }
|
| 2660 |
|
| 2661 | static void
|
| 2662 | ff_layout_free_layoutreturn(struct nfs4_xdr_opaque_data *args)
|
| 2663 | {
|
| 2664 | struct nfs4_flexfile_layoutreturn_args *ff_args;
|
| 2665 |
|
| 2666 | if (!args->data)
|
| 2667 | return;
|
| 2668 | ff_args = args->data;
|
| 2669 | args->data = NULL;
|
| 2670 |
|
| 2671 | ff_layout_free_ds_ioerr(&ff_args->errors);
|
| 2672 | ff_layout_free_iostats_array(ff_args->devinfo, ff_args->num_dev);
|
| 2673 |
|
| 2674 | put_page(ff_args->pages[0]);
|
| 2675 | kfree(ff_args);
|
| 2676 | }
|
| 2677 |
|
| 2678 | static const struct nfs4_xdr_opaque_ops layoutreturn_ops = {
|
| 2679 | .encode = ff_layout_encode_layoutreturn,
|
| 2680 | .free = ff_layout_free_layoutreturn,
|
| 2681 | };
|
| 2682 |
|
| 2683 | static int
|
| 2684 | ff_layout_prepare_layoutreturn(struct nfs4_layoutreturn_args *args)
|
| 2685 | {
|
| 2686 | struct nfs4_flexfile_layoutreturn_args *ff_args;
|
| 2687 | struct nfs4_flexfile_layout *ff_layout = FF_LAYOUT_FROM_HDR(args->layout);
|
| 2688 |
|
| 2689 | ff_args = kmalloc_obj(*ff_args, nfs_io_gfp_mask());
|
| 2690 | if (!ff_args)
|
| 2691 | goto out_nomem;
|
| 2692 | ff_args->pages[0] = alloc_page(nfs_io_gfp_mask());
|
| 2693 | if (!ff_args->pages[0])
|
| 2694 | goto out_nomem_free;
|
| 2695 |
|
| 2696 | INIT_LIST_HEAD(&ff_args->errors);
|
| 2697 | ff_args->num_errors = ff_layout_fetch_ds_ioerr(args->layout,
|
| 2698 | &args->range, &ff_args->errors,
|
| 2699 | FF_LAYOUTRETURN_MAXERR);
|
| 2700 |
|
| 2701 | spin_lock(&args->inode->i_lock);
|
| 2702 | ff_args->num_dev = ff_layout_mirror_prepare_stats(
|
| 2703 | &ff_layout->generic_hdr, &ff_args->devinfo[0],
|
| 2704 | ARRAY_SIZE(ff_args->devinfo), NFS4_FF_OP_LAYOUTRETURN);
|
| 2705 | spin_unlock(&args->inode->i_lock);
|
| 2706 |
|
| 2707 | args->ld_private->ops = &layoutreturn_ops;
|
| 2708 | args->ld_private->data = ff_args;
|
| 2709 | return 0;
|
| 2710 | out_nomem_free:
|
| 2711 | kfree(ff_args);
|
| 2712 | out_nomem:
|
| 2713 | return -ENOMEM;
|
| 2714 | }
|
| 2715 |
|
| 2716 | #ifdef CONFIG_NFS_V4_2
|
| 2717 | void
|
| 2718 | ff_layout_send_layouterror(struct pnfs_layout_segment *lseg)
|
| 2719 | {
|
| 2720 | struct pnfs_layout_hdr *lo = lseg->pls_layout;
|
| 2721 | struct nfs42_layout_error *errors;
|
| 2722 | LIST_HEAD(head);
|
| 2723 |
|
| 2724 | if (!nfs_server_capable(lo->plh_inode, NFS_CAP_LAYOUTERROR))
|
| 2725 | return;
|
| 2726 | ff_layout_fetch_ds_ioerr(lo, &lseg->pls_range, &head, -1);
|
| 2727 | if (list_empty(&head))
|
| 2728 | return;
|
| 2729 |
|
| 2730 | errors = kmalloc_objs(*errors, NFS42_LAYOUTERROR_MAX, nfs_io_gfp_mask());
|
| 2731 | if (errors != NULL) {
|
| 2732 | const struct nfs4_ff_layout_ds_err *pos;
|
| 2733 | size_t n = 0;
|
| 2734 |
|
| 2735 | list_for_each_entry(pos, &head, list) {
|
| 2736 | errors[n].offset = pos->offset;
|
| 2737 | errors[n].length = pos->length;
|
| 2738 | nfs4_stateid_copy(&errors[n].stateid, &pos->stateid);
|
| 2739 | errors[n].errors[0].dev_id = pos->deviceid;
|
| 2740 | errors[n].errors[0].status = pos->status;
|
| 2741 | errors[n].errors[0].opnum = pos->opnum;
|
| 2742 | n++;
|
| 2743 | if (!list_is_last(&pos->list, &head) &&
|
| 2744 | n < NFS42_LAYOUTERROR_MAX)
|
| 2745 | continue;
|
| 2746 | if (nfs42_proc_layouterror(lseg, errors, n) < 0)
|
| 2747 | break;
|
| 2748 | n = 0;
|
| 2749 | }
|
| 2750 | kfree(errors);
|
| 2751 | }
|
| 2752 | ff_layout_free_ds_ioerr(&head);
|
| 2753 | }
|
| 2754 | #else
|
| 2755 | void
|
| 2756 | ff_layout_send_layouterror(struct pnfs_layout_segment *lseg)
|
| 2757 | {
|
| 2758 | }
|
| 2759 | #endif
|
| 2760 |
|
| 2761 | static int
|
| 2762 | ff_layout_ntop4(const struct sockaddr *sap, char *buf, const size_t buflen)
|
| 2763 | {
|
| 2764 | const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
|
| 2765 |
|
| 2766 | return snprintf(buf, buflen, "%pI4", &sin->sin_addr);
|
| 2767 | }
|
| 2768 |
|
| 2769 | static size_t
|
| 2770 | ff_layout_ntop6_noscopeid(const struct sockaddr *sap, char *buf,
|
| 2771 | const int buflen)
|
| 2772 | {
|
| 2773 | const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
|
| 2774 | const struct in6_addr *addr = &sin6->sin6_addr;
|
| 2775 |
|
| 2776 | |
| 2777 | * RFC 4291, Section 2.2.2
|
| 2778 | *
|
| 2779 | * Shorthanded ANY address
|
| 2780 |
|
| 2781 | if (ipv6_addr_any(addr))
|
| 2782 | return snprintf(buf, buflen, "::");
|
| 2783 |
|
| 2784 | |
| 2785 | * RFC 4291, Section 2.2.2
|
| 2786 | *
|
| 2787 | * Shorthanded loopback address
|
| 2788 |
|
| 2789 | if (ipv6_addr_loopback(addr))
|
| 2790 | return snprintf(buf, buflen, "::1");
|
| 2791 |
|
| 2792 | |
| 2793 | * RFC 4291, Section 2.2.3
|
| 2794 | *
|
| 2795 | * Special presentation address format for mapped v4
|
| 2796 | * addresses.
|
| 2797 |
|
| 2798 | if (ipv6_addr_v4mapped(addr))
|
| 2799 | return snprintf(buf, buflen, "::ffff:%pI4",
|
| 2800 | &addr->s6_addr32[3]);
|
| 2801 |
|
| 2802 | |
| 2803 | * RFC 4291, Section 2.2.1
|
| 2804 |
|
| 2805 | return snprintf(buf, buflen, "%pI6c", addr);
|
| 2806 | }
|
| 2807 |
|
| 2808 |
|
| 2809 | static void
|
| 2810 | ff_layout_encode_netaddr(struct xdr_stream *xdr, struct nfs4_pnfs_ds_addr *da)
|
| 2811 | {
|
| 2812 | struct sockaddr *sap = (struct sockaddr *)&da->da_addr;
|
| 2813 | char portbuf[RPCBIND_MAXUADDRPLEN];
|
| 2814 | char addrbuf[RPCBIND_MAXUADDRLEN];
|
| 2815 | unsigned short port;
|
| 2816 | int len, netid_len;
|
| 2817 | __be32 *p;
|
| 2818 |
|
| 2819 | switch (sap->sa_family) {
|
| 2820 | case AF_INET:
|
| 2821 | if (ff_layout_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0)
|
| 2822 | return;
|
| 2823 | port = ntohs(((struct sockaddr_in *)sap)->sin_port);
|
| 2824 | break;
|
| 2825 | case AF_INET6:
|
| 2826 | if (ff_layout_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0)
|
| 2827 | return;
|
| 2828 | port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
|
| 2829 | break;
|
| 2830 | default:
|
| 2831 | WARN_ON_ONCE(1);
|
| 2832 | return;
|
| 2833 | }
|
| 2834 |
|
| 2835 | snprintf(portbuf, sizeof(portbuf), ".%u.%u", port >> 8, port & 0xff);
|
| 2836 | len = strlcat(addrbuf, portbuf, sizeof(addrbuf));
|
| 2837 |
|
| 2838 | netid_len = strlen(da->da_netid);
|
| 2839 | p = xdr_reserve_space(xdr, 4 + netid_len);
|
| 2840 | xdr_encode_opaque(p, da->da_netid, netid_len);
|
| 2841 |
|
| 2842 | p = xdr_reserve_space(xdr, 4 + len);
|
| 2843 | xdr_encode_opaque(p, addrbuf, len);
|
| 2844 | }
|
| 2845 |
|
| 2846 | static void
|
| 2847 | ff_layout_encode_nfstime(struct xdr_stream *xdr,
|
| 2848 | ktime_t t)
|
| 2849 | {
|
| 2850 | struct timespec64 ts;
|
| 2851 | __be32 *p;
|
| 2852 |
|
| 2853 | p = xdr_reserve_space(xdr, 12);
|
| 2854 | ts = ktime_to_timespec64(t);
|
| 2855 | p = xdr_encode_hyper(p, ts.tv_sec);
|
| 2856 | *p++ = cpu_to_be32(ts.tv_nsec);
|
| 2857 | }
|
| 2858 |
|
| 2859 | static void
|
| 2860 | ff_layout_encode_io_latency(struct xdr_stream *xdr,
|
| 2861 | struct nfs4_ff_io_stat *stat)
|
| 2862 | {
|
| 2863 | __be32 *p;
|
| 2864 |
|
| 2865 | p = xdr_reserve_space(xdr, 5 * 8);
|
| 2866 | p = xdr_encode_hyper(p, stat->ops_requested);
|
| 2867 | p = xdr_encode_hyper(p, stat->bytes_requested);
|
| 2868 | p = xdr_encode_hyper(p, stat->ops_completed);
|
| 2869 | p = xdr_encode_hyper(p, stat->bytes_completed);
|
| 2870 | p = xdr_encode_hyper(p, stat->bytes_not_delivered);
|
| 2871 | ff_layout_encode_nfstime(xdr, stat->total_busy_time);
|
| 2872 | ff_layout_encode_nfstime(xdr, stat->aggregate_completion_time);
|
| 2873 | }
|
| 2874 |
|
| 2875 | static void
|
| 2876 | ff_layout_encode_ff_layoutupdate(struct xdr_stream *xdr,
|
| 2877 | const struct nfs42_layoutstat_devinfo *devinfo,
|
| 2878 | struct nfs4_ff_layout_ds_stripe *dss_info)
|
| 2879 | {
|
| 2880 | struct nfs4_pnfs_ds_addr *da;
|
| 2881 | struct nfs4_pnfs_ds *ds = dss_info->mirror_ds->ds;
|
| 2882 | struct nfs_fh *fh = &dss_info->fh_versions[0];
|
| 2883 | __be32 *p;
|
| 2884 |
|
| 2885 | da = list_first_entry(&ds->ds_addrs, struct nfs4_pnfs_ds_addr, da_node);
|
| 2886 | dprintk("%s: DS %s: encoding address %s\n",
|
| 2887 | __func__, ds->ds_remotestr, da->da_remotestr);
|
| 2888 |
|
| 2889 | ff_layout_encode_netaddr(xdr, da);
|
| 2890 |
|
| 2891 | p = xdr_reserve_space(xdr, 4 + fh->size);
|
| 2892 | xdr_encode_opaque(p, fh->data, fh->size);
|
| 2893 |
|
| 2894 | spin_lock(&dss_info->mirror->lock);
|
| 2895 | ff_layout_encode_io_latency(xdr,
|
| 2896 | &dss_info->read_stat.io_stat);
|
| 2897 |
|
| 2898 | ff_layout_encode_io_latency(xdr,
|
| 2899 | &dss_info->write_stat.io_stat);
|
| 2900 | spin_unlock(&dss_info->mirror->lock);
|
| 2901 |
|
| 2902 | ff_layout_encode_nfstime(xdr,
|
| 2903 | ktime_sub(ktime_get(),
|
| 2904 | dss_info->start_time));
|
| 2905 |
|
| 2906 | p = xdr_reserve_space(xdr, 4);
|
| 2907 | *p = cpu_to_be32(false);
|
| 2908 | }
|
| 2909 |
|
| 2910 | static void
|
| 2911 | ff_layout_encode_layoutstats(struct xdr_stream *xdr, const void *args,
|
| 2912 | const struct nfs4_xdr_opaque_data *opaque)
|
| 2913 | {
|
| 2914 | struct nfs42_layoutstat_devinfo *devinfo = container_of(opaque,
|
| 2915 | struct nfs42_layoutstat_devinfo, ld_private);
|
| 2916 | __be32 *start;
|
| 2917 |
|
| 2918 |
|
| 2919 | start = xdr_reserve_space(xdr, 4);
|
| 2920 | ff_layout_encode_ff_layoutupdate(xdr, devinfo, opaque->data);
|
| 2921 |
|
| 2922 | *start = cpu_to_be32((xdr->p - start - 1) * 4);
|
| 2923 | }
|
| 2924 |
|
| 2925 | static void
|
| 2926 | ff_layout_free_layoutstats(struct nfs4_xdr_opaque_data *opaque)
|
| 2927 | {
|
| 2928 | struct nfs4_ff_layout_ds_stripe *dss_info = opaque->data;
|
| 2929 | struct nfs4_ff_layout_mirror *mirror = dss_info->mirror;
|
| 2930 |
|
| 2931 | ff_layout_put_mirror(mirror);
|
| 2932 | }
|
| 2933 |
|
| 2934 | static const struct nfs4_xdr_opaque_ops layoutstat_ops = {
|
| 2935 | .encode = ff_layout_encode_layoutstats,
|
| 2936 | .free = ff_layout_free_layoutstats,
|
| 2937 | };
|
| 2938 |
|
| 2939 | static int
|
| 2940 | ff_layout_mirror_prepare_stats(struct pnfs_layout_hdr *lo,
|
| 2941 | struct nfs42_layoutstat_devinfo *devinfo,
|
| 2942 | int dev_limit, enum nfs4_ff_op_type type)
|
| 2943 | {
|
| 2944 | struct nfs4_flexfile_layout *ff_layout = FF_LAYOUT_FROM_HDR(lo);
|
| 2945 | struct nfs4_ff_layout_mirror *mirror;
|
| 2946 | struct nfs4_ff_layout_ds_stripe *dss_info;
|
| 2947 | struct nfs4_deviceid_node *dev;
|
| 2948 | int i = 0, dss_id;
|
| 2949 |
|
| 2950 | list_for_each_entry(mirror, &ff_layout->mirrors, mirrors) {
|
| 2951 | for (dss_id = 0; dss_id < mirror->dss_count; ++dss_id) {
|
| 2952 | dss_info = &mirror->dss[dss_id];
|
| 2953 | if (i >= dev_limit)
|
| 2954 | break;
|
| 2955 | if (IS_ERR_OR_NULL(dss_info->mirror_ds))
|
| 2956 | continue;
|
| 2957 | if (!test_and_clear_bit(NFS4_FF_MIRROR_STAT_AVAIL,
|
| 2958 | &mirror->flags) &&
|
| 2959 | type != NFS4_FF_OP_LAYOUTRETURN)
|
| 2960 | continue;
|
| 2961 |
|
| 2962 | if (!refcount_inc_not_zero(&mirror->ref))
|
| 2963 | continue;
|
| 2964 | dev = &dss_info->mirror_ds->id_node;
|
| 2965 | memcpy(&devinfo->dev_id,
|
| 2966 | &dev->deviceid,
|
| 2967 | NFS4_DEVICEID4_SIZE);
|
| 2968 | devinfo->offset = 0;
|
| 2969 | devinfo->length = NFS4_MAX_UINT64;
|
| 2970 | spin_lock(&mirror->lock);
|
| 2971 | devinfo->read_count =
|
| 2972 | dss_info->read_stat.io_stat.ops_completed;
|
| 2973 | devinfo->read_bytes =
|
| 2974 | dss_info->read_stat.io_stat.bytes_completed;
|
| 2975 | devinfo->write_count =
|
| 2976 | dss_info->write_stat.io_stat.ops_completed;
|
| 2977 | devinfo->write_bytes =
|
| 2978 | dss_info->write_stat.io_stat.bytes_completed;
|
| 2979 | spin_unlock(&mirror->lock);
|
| 2980 | devinfo->layout_type = LAYOUT_FLEX_FILES;
|
| 2981 | devinfo->ld_private.ops = &layoutstat_ops;
|
| 2982 | devinfo->ld_private.data = &mirror->dss[dss_id];
|
| 2983 |
|
| 2984 | devinfo++;
|
| 2985 | i++;
|
| 2986 | }
|
| 2987 | }
|
| 2988 | return i;
|
| 2989 | }
|
| 2990 |
|
| 2991 | static int ff_layout_prepare_layoutstats(struct nfs42_layoutstat_args *args)
|
| 2992 | {
|
| 2993 | struct pnfs_layout_hdr *lo;
|
| 2994 | struct nfs4_flexfile_layout *ff_layout;
|
| 2995 | const int dev_count = PNFS_LAYOUTSTATS_MAXDEV;
|
| 2996 |
|
| 2997 |
|
| 2998 | args->devinfo = kmalloc_objs(*args->devinfo, dev_count,
|
| 2999 | nfs_io_gfp_mask());
|
| 3000 | if (!args->devinfo)
|
| 3001 | return -ENOMEM;
|
| 3002 |
|
| 3003 | spin_lock(&args->inode->i_lock);
|
| 3004 | lo = NFS_I(args->inode)->layout;
|
| 3005 | if (lo && pnfs_layout_is_valid(lo)) {
|
| 3006 | ff_layout = FF_LAYOUT_FROM_HDR(lo);
|
| 3007 | args->num_dev = ff_layout_mirror_prepare_stats(
|
| 3008 | &ff_layout->generic_hdr, &args->devinfo[0], dev_count,
|
| 3009 | NFS4_FF_OP_LAYOUTSTATS);
|
| 3010 | } else
|
| 3011 | args->num_dev = 0;
|
| 3012 | spin_unlock(&args->inode->i_lock);
|
| 3013 | if (!args->num_dev) {
|
| 3014 | kfree(args->devinfo);
|
| 3015 | args->devinfo = NULL;
|
| 3016 | return -ENOENT;
|
| 3017 | }
|
| 3018 |
|
| 3019 | return 0;
|
| 3020 | }
|
| 3021 |
|
| 3022 | static int
|
| 3023 | ff_layout_set_layoutdriver(struct nfs_server *server,
|
| 3024 | const struct nfs_fh *dummy)
|
| 3025 | {
|
| 3026 | #if IS_ENABLED(CONFIG_NFS_V4_2)
|
| 3027 | server->caps |= NFS_CAP_LAYOUTSTATS | NFS_CAP_REBOOT_LAYOUTRETURN;
|
| 3028 | #endif
|
| 3029 | return 0;
|
| 3030 | }
|
| 3031 |
|
| 3032 | static const struct pnfs_commit_ops ff_layout_commit_ops = {
|
| 3033 | .setup_ds_info = ff_layout_setup_ds_info,
|
| 3034 | .release_ds_info = ff_layout_release_ds_info,
|
| 3035 | .mark_request_commit = pnfs_layout_mark_request_commit,
|
| 3036 | .clear_request_commit = pnfs_generic_clear_request_commit,
|
| 3037 | .scan_commit_lists = pnfs_generic_scan_commit_lists,
|
| 3038 | .recover_commit_reqs = pnfs_generic_recover_commit_reqs,
|
| 3039 | .commit_pagelist = ff_layout_commit_pagelist,
|
| 3040 | };
|
| 3041 |
|
| 3042 | static struct pnfs_layoutdriver_type flexfilelayout_type = {
|
| 3043 | .id = LAYOUT_FLEX_FILES,
|
| 3044 | .name = "LAYOUT_FLEX_FILES",
|
| 3045 | .owner = THIS_MODULE,
|
| 3046 | .flags = PNFS_LAYOUTGET_ON_OPEN,
|
| 3047 | .max_layoutget_response = 4096,
|
| 3048 | .set_layoutdriver = ff_layout_set_layoutdriver,
|
| 3049 | .alloc_layout_hdr = ff_layout_alloc_layout_hdr,
|
| 3050 | .free_layout_hdr = ff_layout_free_layout_hdr,
|
| 3051 | .alloc_lseg = ff_layout_alloc_lseg,
|
| 3052 | .free_lseg = ff_layout_free_lseg,
|
| 3053 | .add_lseg = ff_layout_add_lseg,
|
| 3054 | .pg_read_ops = &ff_layout_pg_read_ops,
|
| 3055 | .pg_write_ops = &ff_layout_pg_write_ops,
|
| 3056 | .get_ds_info = ff_layout_get_ds_info,
|
| 3057 | .free_deviceid_node = ff_layout_free_deviceid_node,
|
| 3058 | .read_pagelist = ff_layout_read_pagelist,
|
| 3059 | .write_pagelist = ff_layout_write_pagelist,
|
| 3060 | .alloc_deviceid_node = ff_layout_alloc_deviceid_node,
|
| 3061 | .prepare_layoutreturn = ff_layout_prepare_layoutreturn,
|
| 3062 | .sync = pnfs_nfs_generic_sync,
|
| 3063 | .prepare_layoutstats = ff_layout_prepare_layoutstats,
|
| 3064 | .cancel_io = ff_layout_cancel_io,
|
| 3065 | };
|
| 3066 |
|
| 3067 | static int __init nfs4flexfilelayout_init(void)
|
| 3068 | {
|
| 3069 | printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Registering...\n",
|
| 3070 | __func__);
|
| 3071 | return pnfs_register_layoutdriver(&flexfilelayout_type);
|
| 3072 | }
|
| 3073 |
|
| 3074 | static void __exit nfs4flexfilelayout_exit(void)
|
| 3075 | {
|
| 3076 | printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Unregistering...\n",
|
| 3077 | __func__);
|
| 3078 | pnfs_unregister_layoutdriver(&flexfilelayout_type);
|
| 3079 | }
|
| 3080 |
|
| 3081 | MODULE_ALIAS("nfs-layouttype4-4");
|
| 3082 |
|
| 3083 | MODULE_LICENSE("GPL");
|
| 3084 | MODULE_DESCRIPTION("The NFSv4 flexfile layout driver");
|
| 3085 |
|
| 3086 | module_init(nfs4flexfilelayout_init);
|
| 3087 | module_exit(nfs4flexfilelayout_exit);
|
| 3088 |
|
| 3089 | module_param(io_maxretrans, ushort, 0644);
|
| 3090 | MODULE_PARM_DESC(io_maxretrans, "The number of times the NFSv4.1 client "
|
| 3091 | "retries an I/O request before returning an error. ");
|