Commit 9f0b5792 authored by Anna Schumaker's avatar Anna Schumaker Committed by J. Bruce Fields

NFSD: Encode a full READ_PLUS reply

Reply to the client with multiple hole and data segments. I use the
result of the first vfs_llseek() call for encoding as an optimization so
we don't have to immediately repeat the call. This also lets us encode
any remaining reply as data if we get an unexpected result while trying
to calculate a hole.
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
parent 278765ea
...@@ -4603,16 +4603,18 @@ nfsd4_encode_offload_status(struct nfsd4_compoundres *resp, __be32 nfserr, ...@@ -4603,16 +4603,18 @@ nfsd4_encode_offload_status(struct nfsd4_compoundres *resp, __be32 nfserr,
static __be32 static __be32
nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp, nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp,
struct nfsd4_read *read, struct nfsd4_read *read,
unsigned long *maxcount, u32 *eof) unsigned long *maxcount, u32 *eof,
loff_t *pos)
{ {
struct xdr_stream *xdr = &resp->xdr; struct xdr_stream *xdr = &resp->xdr;
struct file *file = read->rd_nf->nf_file; struct file *file = read->rd_nf->nf_file;
int starting_len = xdr->buf->len; int starting_len = xdr->buf->len;
loff_t hole_pos = vfs_llseek(file, read->rd_offset, SEEK_HOLE); loff_t hole_pos;
__be32 nfserr; __be32 nfserr;
__be32 *p, tmp; __be32 *p, tmp;
__be64 tmp64; __be64 tmp64;
hole_pos = pos ? *pos : vfs_llseek(file, read->rd_offset, SEEK_HOLE);
if (hole_pos > read->rd_offset) if (hole_pos > read->rd_offset)
*maxcount = min_t(unsigned long, *maxcount, hole_pos - read->rd_offset); *maxcount = min_t(unsigned long, *maxcount, hole_pos - read->rd_offset);
*maxcount = min_t(unsigned long, *maxcount, (xdr->buf->buflen - xdr->buf->len)); *maxcount = min_t(unsigned long, *maxcount, (xdr->buf->buflen - xdr->buf->len));
...@@ -4647,13 +4649,14 @@ nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp, ...@@ -4647,13 +4649,14 @@ nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp,
{ {
struct file *file = read->rd_nf->nf_file; struct file *file = read->rd_nf->nf_file;
loff_t data_pos = vfs_llseek(file, read->rd_offset, SEEK_DATA); loff_t data_pos = vfs_llseek(file, read->rd_offset, SEEK_DATA);
loff_t f_size = i_size_read(file_inode(file));
unsigned long count; unsigned long count;
__be32 *p; __be32 *p;
if (data_pos == -ENXIO) if (data_pos == -ENXIO)
data_pos = i_size_read(file_inode(file)); data_pos = f_size;
else if (data_pos <= read->rd_offset) else if (data_pos <= read->rd_offset || (data_pos < f_size && data_pos % PAGE_SIZE))
return nfserr_resource; return nfsd4_encode_read_plus_data(resp, read, maxcount, eof, &f_size);
count = data_pos - read->rd_offset; count = data_pos - read->rd_offset;
/* Content type, offset, byte count */ /* Content type, offset, byte count */
...@@ -4665,7 +4668,7 @@ nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp, ...@@ -4665,7 +4668,7 @@ nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp,
p = xdr_encode_hyper(p, read->rd_offset); p = xdr_encode_hyper(p, read->rd_offset);
p = xdr_encode_hyper(p, count); p = xdr_encode_hyper(p, count);
*eof = (read->rd_offset + count) >= i_size_read(file_inode(file)); *eof = (read->rd_offset + count) >= f_size;
*maxcount = min_t(unsigned long, count, *maxcount); *maxcount = min_t(unsigned long, count, *maxcount);
return nfs_ok; return nfs_ok;
} }
...@@ -4678,8 +4681,10 @@ nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr, ...@@ -4678,8 +4681,10 @@ nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
struct xdr_stream *xdr = &resp->xdr; struct xdr_stream *xdr = &resp->xdr;
struct file *file; struct file *file;
int starting_len = xdr->buf->len; int starting_len = xdr->buf->len;
int last_segment = xdr->buf->len;
int segments = 0; int segments = 0;
__be32 *p, tmp; __be32 *p, tmp;
bool is_data;
loff_t pos; loff_t pos;
u32 eof; u32 eof;
...@@ -4703,29 +4708,22 @@ nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr, ...@@ -4703,29 +4708,22 @@ nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
if (eof) if (eof)
goto out; goto out;
pos = vfs_llseek(file, read->rd_offset, SEEK_DATA); pos = vfs_llseek(file, read->rd_offset, SEEK_HOLE);
if (pos == -ENXIO) is_data = pos > read->rd_offset;
pos = i_size_read(file_inode(file));
else if (pos < 0)
pos = read->rd_offset;
if (pos == read->rd_offset) { while (count > 0 && !eof) {
maxcount = count; maxcount = count;
nfserr = nfsd4_encode_read_plus_data(resp, read, &maxcount, &eof); if (is_data)
if (nfserr) nfserr = nfsd4_encode_read_plus_data(resp, read, &maxcount, &eof,
goto out; segments == 0 ? &pos : NULL);
count -= maxcount; else
read->rd_offset += maxcount; nfserr = nfsd4_encode_read_plus_hole(resp, read, &maxcount, &eof);
segments++;
}
if (count > 0 && !eof) {
maxcount = count;
nfserr = nfsd4_encode_read_plus_hole(resp, read, &maxcount, &eof);
if (nfserr) if (nfserr)
goto out; goto out;
count -= maxcount; count -= maxcount;
read->rd_offset += maxcount; read->rd_offset += maxcount;
is_data = !is_data;
last_segment = xdr->buf->len;
segments++; segments++;
} }
...@@ -4737,7 +4735,10 @@ nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr, ...@@ -4737,7 +4735,10 @@ nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4); write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4);
tmp = htonl(segments); tmp = htonl(segments);
write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4);
nfserr = nfs_ok; if (nfserr) {
xdr_truncate_encode(xdr, last_segment);
nfserr = nfs_ok;
}
} }
return nfserr; return nfserr;
......
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