Commit 29662fa6 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Trond Myklebust

pnfs/blocklayout: calculate layoutupdate size correctly

We need to include the first u32 for the number of entries.  Add a helper
for the calculation instead of opencoding it so that it's in one place.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
parent 18e3b739
...@@ -462,6 +462,12 @@ ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start, ...@@ -462,6 +462,12 @@ ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start,
return err; return err;
} }
static size_t ext_tree_layoutupdate_size(size_t count)
{
return sizeof(__be32) /* number of entries */ +
BL_EXTENT_SIZE * count;
}
static void ext_tree_free_commitdata(struct nfs4_layoutcommit_args *arg, static void ext_tree_free_commitdata(struct nfs4_layoutcommit_args *arg,
size_t buffer_size) size_t buffer_size)
{ {
...@@ -489,7 +495,7 @@ static int ext_tree_encode_commit(struct pnfs_block_layout *bl, __be32 *p, ...@@ -489,7 +495,7 @@ static int ext_tree_encode_commit(struct pnfs_block_layout *bl, __be32 *p,
continue; continue;
(*count)++; (*count)++;
if (*count * BL_EXTENT_SIZE > buffer_size) { if (ext_tree_layoutupdate_size(*count) > buffer_size) {
/* keep counting.. */ /* keep counting.. */
ret = -ENOSPC; ret = -ENOSPC;
continue; continue;
...@@ -530,7 +536,7 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg) ...@@ -530,7 +536,7 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg)
if (unlikely(ret)) { if (unlikely(ret)) {
ext_tree_free_commitdata(arg, buffer_size); ext_tree_free_commitdata(arg, buffer_size);
buffer_size = sizeof(__be32) + BL_EXTENT_SIZE * count; buffer_size = ext_tree_layoutupdate_size(count);
count = 0; count = 0;
arg->layoutupdate_pages = arg->layoutupdate_pages =
...@@ -549,7 +555,7 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg) ...@@ -549,7 +555,7 @@ ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg)
} }
*start_p = cpu_to_be32(count); *start_p = cpu_to_be32(count);
arg->layoutupdate_len = sizeof(__be32) + BL_EXTENT_SIZE * count; arg->layoutupdate_len = ext_tree_layoutupdate_size(count);
if (unlikely(arg->layoutupdate_pages != &arg->layoutupdate_page)) { if (unlikely(arg->layoutupdate_pages != &arg->layoutupdate_page)) {
__be32 *p = start_p; __be32 *p = start_p;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment