Skip to content

Commit

Permalink
pNFS/flexfiles: Ensure we have enough buffer for layoutreturn
Browse files Browse the repository at this point in the history
The flexfiles client can piggyback both layout errors and layoutstats
as part of the layoutreturn. Both these payloads can get large, with
20 layout error entries taking up about 1.2K, and 4 layoutstats entries
taking up another 1K.
This patch allows a maximum payload of 4k by allocating a full page.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
  • Loading branch information
Trond Myklebust committed Dec 10, 2016
1 parent 5ba6a09 commit d915211
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
32 changes: 26 additions & 6 deletions fs/nfs/flexfilelayout/flexfilelayout.c
Original file line number Diff line number Diff line change
Expand Up @@ -2049,16 +2049,28 @@ ff_layout_encode_layoutreturn(struct xdr_stream *xdr,
{
const struct nfs4_layoutreturn_args *args = voidargs;
struct nfs4_flexfile_layoutreturn_args *ff_args = ff_opaque->data;
struct xdr_buf tmp_buf = {
.head = {
[0] = {
.iov_base = page_address(ff_args->pages[0]),
},
},
.buflen = PAGE_SIZE,
};
struct xdr_stream tmp_xdr;
__be32 *start;

dprintk("%s: Begin\n", __func__);
start = xdr_reserve_space(xdr, 4);
BUG_ON(!start);

ff_layout_encode_ioerr(xdr, args, ff_args);
ff_layout_encode_iostats_array(xdr, args, ff_args);
xdr_init_encode(&tmp_xdr, &tmp_buf, NULL);

ff_layout_encode_ioerr(&tmp_xdr, args, ff_args);
ff_layout_encode_iostats_array(&tmp_xdr, args, ff_args);

start = xdr_reserve_space(xdr, 4);
*start = cpu_to_be32(tmp_buf.len);
xdr_write_pages(xdr, ff_args->pages, 0, tmp_buf.len);

*start = cpu_to_be32((xdr->p - start - 1) * 4);
dprintk("%s: Return\n", __func__);
}

Expand All @@ -2075,6 +2087,7 @@ ff_layout_free_layoutreturn(struct nfs4_xdr_opaque_data *args)
ff_layout_free_ds_ioerr(&ff_args->errors);
ff_layout_free_iostats_array(ff_args->devinfo, ff_args->num_dev);

put_page(ff_args->pages[0]);
kfree(ff_args);
}

Expand All @@ -2091,7 +2104,10 @@ ff_layout_prepare_layoutreturn(struct nfs4_layoutreturn_args *args)

ff_args = kmalloc(sizeof(*ff_args), GFP_KERNEL);
if (!ff_args)
return -ENOMEM;
goto out_nomem;
ff_args->pages[0] = alloc_page(GFP_KERNEL);
if (!ff_args->pages[0])
goto out_nomem_free;

INIT_LIST_HEAD(&ff_args->errors);
ff_args->num_errors = ff_layout_fetch_ds_ioerr(args->layout,
Expand All @@ -2106,6 +2122,10 @@ ff_layout_prepare_layoutreturn(struct nfs4_layoutreturn_args *args)
args->ld_private->ops = &layoutreturn_ops;
args->ld_private->data = ff_args;
return 0;
out_nomem_free:
kfree(ff_args);
out_nomem:
return -ENOMEM;
}

static int
Expand Down
1 change: 1 addition & 0 deletions fs/nfs/flexfilelayout/flexfilelayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct nfs4_flexfile_layoutreturn_args {
struct nfs42_layoutstat_devinfo devinfo[FF_LAYOUTSTATS_MAXDEV];
unsigned int num_errors;
unsigned int num_dev;
struct page *pages[1];
};

static inline struct nfs4_flexfile_layout *
Expand Down

0 comments on commit d915211

Please sign in to comment.