@@ -1607,8 +1607,8 @@ static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op
{
u32 maxcount = svc_max_payload(rqstp);
u32 rlen = min(op->u.read.rd_length, maxcount);
- /* extra xdr space for encoding read plus segments. */
- u32 xdr = 4;
+ /* enough extra xdr space for encoding either a hole or data segment. */
+ u32 xdr = 5;
return (op_encode_hdr_size + 2 + xdr + XDR_QUADLEN(rlen)) * sizeof(__be32);
}
@@ -3803,7 +3803,7 @@ nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
static __be32
nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp, struct nfsd4_read *read,
- struct file *file)
+ struct file *file, loff_t hole_pos)
{
__be32 *p, err;
unsigned long maxcount;
@@ -3817,6 +3817,7 @@ nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp, struct nfsd4_read *r
maxcount = svc_max_payload(resp->rqstp);
maxcount = min_t(unsigned long, maxcount, (xdr->buf->buflen - xdr->buf->len));
maxcount = min_t(unsigned long, maxcount, read->rd_length);
+ maxcount = min_t(unsigned long, maxcount, hole_pos - read->rd_offset);
err = nfsd4_encode_readv(resp, read, file, &maxcount);
@@ -3829,6 +3830,22 @@ nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp, struct nfsd4_read *r
}
static __be32
+nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp, struct nfsd4_read *read,
+ struct file *file, loff_t data_pos)
+{
+ __be32 *p;
+ unsigned long maxcount = data_pos - read->rd_offset;
+
+ p = xdr_reserve_space(&resp->xdr, 4 + 8 + 8);
+ *p++ = cpu_to_be32(NFS4_CONTENT_HOLE);
+ p = xdr_encode_hyper(p, read->rd_offset);
+ p = xdr_encode_hyper(p, maxcount);
+
+ read->rd_offset += maxcount;
+ return nfs_ok;
+}
+
+static __be32
nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
struct nfsd4_read *read)
{
@@ -3836,6 +3853,7 @@ nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
struct file *file = read->rd_filp;
int starting_len = xdr->buf->len;
struct raparms *ra;
+ loff_t hole_pos, data_pos;
__be32 *p;
__be32 err;
u32 eof, segments = 0;
@@ -3856,10 +3874,20 @@ nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
goto err_truncate;
}
- if (read->rd_offset >= i_size_read(file_inode(file)))
+ hole_pos = vfs_llseek(read->rd_filp, read->rd_offset, SEEK_HOLE);
+ if (hole_pos == -ENXIO)
goto out_encode;
- err = nfsd4_encode_read_plus_data(resp, read, file);
+ data_pos = vfs_llseek(read->rd_filp, read->rd_offset, SEEK_DATA);
+ if (data_pos == -ENXIO)
+ data_pos = i_size_read(file_inode(file));
+
+ if ((data_pos == read->rd_offset) && (hole_pos > data_pos))
+ err = nfsd4_encode_read_plus_data(resp, read, file, hole_pos);
+ else if ((hole_pos == read->rd_offset) && (data_pos > hole_pos))
+ err = nfsd4_encode_read_plus_hole(resp, read, file, data_pos);
+ else /* The file probably changed on us between seeks. */
+ err = nfsd4_encode_read_plus_data(resp, read, file, i_size_read(file_inode(file)));
segments++;
out_encode: