mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
NFSD: Simplify READ_PLUS
Chuck had suggested reverting READ_PLUS so it returns a single DATA segment covering the requested read range. This prepares the server for a future "sparse read" function so support can easily be added without needing to rip out the old READ_PLUS code at the same time. Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
This commit is contained in:
parent
b7b275e60b
commit
eeadcb7579
1 changed files with 32 additions and 107 deletions
|
@ -4767,79 +4767,37 @@ 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,
|
|
||||||
loff_t *pos)
|
|
||||||
{
|
{
|
||||||
struct xdr_stream *xdr = resp->xdr;
|
bool splice_ok = test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags);
|
||||||
struct file *file = read->rd_nf->nf_file;
|
struct file *file = read->rd_nf->nf_file;
|
||||||
int starting_len = xdr->buf->len;
|
struct xdr_stream *xdr = resp->xdr;
|
||||||
loff_t hole_pos;
|
unsigned long maxcount;
|
||||||
__be32 nfserr;
|
__be32 nfserr, *p;
|
||||||
__be32 *p, tmp;
|
|
||||||
__be64 tmp64;
|
|
||||||
|
|
||||||
hole_pos = pos ? *pos : vfs_llseek(file, read->rd_offset, SEEK_HOLE);
|
|
||||||
if (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));
|
|
||||||
|
|
||||||
/* Content type, offset, byte count */
|
/* Content type, offset, byte count */
|
||||||
p = xdr_reserve_space(xdr, 4 + 8 + 4);
|
p = xdr_reserve_space(xdr, 4 + 8 + 4);
|
||||||
if (!p)
|
if (!p)
|
||||||
return nfserr_resource;
|
return nfserr_io;
|
||||||
|
if (resp->xdr->buf->page_len && splice_ok) {
|
||||||
read->rd_vlen = xdr_reserve_space_vec(xdr, resp->rqstp->rq_vec, *maxcount);
|
WARN_ON_ONCE(splice_ok);
|
||||||
if (read->rd_vlen < 0)
|
return nfserr_serverfault;
|
||||||
return nfserr_resource;
|
|
||||||
|
|
||||||
nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset,
|
|
||||||
resp->rqstp->rq_vec, read->rd_vlen, maxcount, eof);
|
|
||||||
if (nfserr)
|
|
||||||
return nfserr;
|
|
||||||
xdr_truncate_encode(xdr, starting_len + 16 + xdr_align_size(*maxcount));
|
|
||||||
|
|
||||||
tmp = htonl(NFS4_CONTENT_DATA);
|
|
||||||
write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4);
|
|
||||||
tmp64 = cpu_to_be64(read->rd_offset);
|
|
||||||
write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp64, 8);
|
|
||||||
tmp = htonl(*maxcount);
|
|
||||||
write_bytes_to_xdr_buf(xdr->buf, starting_len + 12, &tmp, 4);
|
|
||||||
|
|
||||||
tmp = xdr_zero;
|
|
||||||
write_bytes_to_xdr_buf(xdr->buf, starting_len + 16 + *maxcount, &tmp,
|
|
||||||
xdr_pad_size(*maxcount));
|
|
||||||
return nfs_ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static __be32
|
maxcount = min_t(unsigned long, read->rd_length,
|
||||||
nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp,
|
(xdr->buf->buflen - xdr->buf->len));
|
||||||
struct nfsd4_read *read,
|
|
||||||
unsigned long *maxcount, u32 *eof)
|
|
||||||
{
|
|
||||||
struct file *file = read->rd_nf->nf_file;
|
|
||||||
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;
|
|
||||||
__be32 *p;
|
|
||||||
|
|
||||||
if (data_pos == -ENXIO)
|
if (file->f_op->splice_read && splice_ok)
|
||||||
data_pos = f_size;
|
nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount);
|
||||||
else if (data_pos <= read->rd_offset || (data_pos < f_size && data_pos % PAGE_SIZE))
|
else
|
||||||
return nfsd4_encode_read_plus_data(resp, read, maxcount, eof, &f_size);
|
nfserr = nfsd4_encode_readv(resp, read, file, maxcount);
|
||||||
count = data_pos - read->rd_offset;
|
if (nfserr)
|
||||||
|
return nfserr;
|
||||||
|
|
||||||
/* Content type, offset, byte count */
|
*p++ = cpu_to_be32(NFS4_CONTENT_DATA);
|
||||||
p = xdr_reserve_space(resp->xdr, 4 + 8 + 8);
|
|
||||||
if (!p)
|
|
||||||
return nfserr_resource;
|
|
||||||
|
|
||||||
*p++ = htonl(NFS4_CONTENT_HOLE);
|
|
||||||
p = xdr_encode_hyper(p, read->rd_offset);
|
p = xdr_encode_hyper(p, read->rd_offset);
|
||||||
p = xdr_encode_hyper(p, count);
|
*p = cpu_to_be32(read->rd_length);
|
||||||
|
|
||||||
*eof = (read->rd_offset + count) >= f_size;
|
|
||||||
*maxcount = min_t(unsigned long, count, *maxcount);
|
|
||||||
return nfs_ok;
|
return nfs_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4847,69 +4805,36 @@ static __be32
|
||||||
nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
|
nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
|
||||||
struct nfsd4_read *read)
|
struct nfsd4_read *read)
|
||||||
{
|
{
|
||||||
unsigned long maxcount, count;
|
struct file *file = read->rd_nf->nf_file;
|
||||||
struct xdr_stream *xdr = resp->xdr;
|
struct xdr_stream *xdr = resp->xdr;
|
||||||
struct file *file;
|
|
||||||
int starting_len = xdr->buf->len;
|
int starting_len = xdr->buf->len;
|
||||||
int last_segment = xdr->buf->len;
|
u32 segments = 0;
|
||||||
int segments = 0;
|
__be32 *p;
|
||||||
__be32 *p, tmp;
|
|
||||||
bool is_data;
|
|
||||||
loff_t pos;
|
|
||||||
u32 eof;
|
|
||||||
|
|
||||||
if (nfserr)
|
if (nfserr)
|
||||||
return nfserr;
|
return nfserr;
|
||||||
file = read->rd_nf->nf_file;
|
|
||||||
|
|
||||||
/* eof flag, segment count */
|
/* eof flag, segment count */
|
||||||
p = xdr_reserve_space(xdr, 4 + 4);
|
p = xdr_reserve_space(xdr, 4 + 4);
|
||||||
if (!p)
|
if (!p)
|
||||||
return nfserr_resource;
|
return nfserr_io;
|
||||||
xdr_commit_encode(xdr);
|
xdr_commit_encode(xdr);
|
||||||
|
|
||||||
maxcount = min_t(unsigned long, read->rd_length,
|
read->rd_eof = read->rd_offset >= i_size_read(file_inode(file));
|
||||||
(xdr->buf->buflen - xdr->buf->len));
|
if (read->rd_eof)
|
||||||
count = maxcount;
|
|
||||||
|
|
||||||
eof = read->rd_offset >= i_size_read(file_inode(file));
|
|
||||||
if (eof)
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
pos = vfs_llseek(file, read->rd_offset, SEEK_HOLE);
|
nfserr = nfsd4_encode_read_plus_data(resp, read);
|
||||||
is_data = pos > read->rd_offset;
|
if (nfserr) {
|
||||||
|
xdr_truncate_encode(xdr, starting_len);
|
||||||
while (count > 0 && !eof) {
|
return nfserr;
|
||||||
maxcount = count;
|
|
||||||
if (is_data)
|
|
||||||
nfserr = nfsd4_encode_read_plus_data(resp, read, &maxcount, &eof,
|
|
||||||
segments == 0 ? &pos : NULL);
|
|
||||||
else
|
|
||||||
nfserr = nfsd4_encode_read_plus_hole(resp, read, &maxcount, &eof);
|
|
||||||
if (nfserr)
|
|
||||||
goto out;
|
|
||||||
count -= maxcount;
|
|
||||||
read->rd_offset += maxcount;
|
|
||||||
is_data = !is_data;
|
|
||||||
last_segment = xdr->buf->len;
|
|
||||||
segments++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
segments++;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (nfserr && segments == 0)
|
p = xdr_encode_bool(p, read->rd_eof);
|
||||||
xdr_truncate_encode(xdr, starting_len);
|
*p = cpu_to_be32(segments);
|
||||||
else {
|
|
||||||
if (nfserr) {
|
|
||||||
xdr_truncate_encode(xdr, last_segment);
|
|
||||||
nfserr = nfs_ok;
|
|
||||||
eof = 0;
|
|
||||||
}
|
|
||||||
tmp = htonl(eof);
|
|
||||||
write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4);
|
|
||||||
tmp = htonl(segments);
|
|
||||||
write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nfserr;
|
return nfserr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue