Skip to content

Commit c567552

Browse files
committed
NFS: Add READ_PLUS data segment support
This patch adds client support for decoding a single NFS4_CONTENT_DATA segment returned by the server. This is the simplest implementation possible, since it does not account for any hole segments in the reply. Signed-off-by: Anna Schumaker <[email protected]>
1 parent a14a635 commit c567552

File tree

7 files changed

+187
-5
lines changed

7 files changed

+187
-5
lines changed

fs/nfs/nfs42xdr.c

+141
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@
4545
#define encode_deallocate_maxsz (op_encode_hdr_maxsz + \
4646
encode_fallocate_maxsz)
4747
#define decode_deallocate_maxsz (op_decode_hdr_maxsz)
48+
#define encode_read_plus_maxsz (op_encode_hdr_maxsz + \
49+
encode_stateid_maxsz + 3)
50+
#define NFS42_READ_PLUS_SEGMENT_SIZE (1 /* data_content4 */ + \
51+
2 /* data_info4.di_offset */ + \
52+
2 /* data_info4.di_length */)
53+
#define decode_read_plus_maxsz (op_decode_hdr_maxsz + \
54+
1 /* rpr_eof */ + \
55+
1 /* rpr_contents count */ + \
56+
NFS42_READ_PLUS_SEGMENT_SIZE)
4857
#define encode_seek_maxsz (op_encode_hdr_maxsz + \
4958
encode_stateid_maxsz + \
5059
2 /* offset */ + \
@@ -128,6 +137,14 @@
128137
decode_putfh_maxsz + \
129138
decode_deallocate_maxsz + \
130139
decode_getattr_maxsz)
140+
#define NFS4_enc_read_plus_sz (compound_encode_hdr_maxsz + \
141+
encode_sequence_maxsz + \
142+
encode_putfh_maxsz + \
143+
encode_read_plus_maxsz)
144+
#define NFS4_dec_read_plus_sz (compound_decode_hdr_maxsz + \
145+
decode_sequence_maxsz + \
146+
decode_putfh_maxsz + \
147+
decode_read_plus_maxsz)
131148
#define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
132149
encode_sequence_maxsz + \
133150
encode_putfh_maxsz + \
@@ -324,6 +341,16 @@ static void encode_deallocate(struct xdr_stream *xdr,
324341
encode_fallocate(xdr, args);
325342
}
326343

344+
static void encode_read_plus(struct xdr_stream *xdr,
345+
const struct nfs_pgio_args *args,
346+
struct compound_hdr *hdr)
347+
{
348+
encode_op_hdr(xdr, OP_READ_PLUS, decode_read_plus_maxsz, hdr);
349+
encode_nfs4_stateid(xdr, &args->stateid);
350+
encode_uint64(xdr, args->offset);
351+
encode_uint32(xdr, args->count);
352+
}
353+
327354
static void encode_seek(struct xdr_stream *xdr,
328355
const struct nfs42_seek_args *args,
329356
struct compound_hdr *hdr)
@@ -722,6 +749,28 @@ static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
722749
encode_nops(&hdr);
723750
}
724751

752+
/*
753+
* Encode READ_PLUS request
754+
*/
755+
static void nfs4_xdr_enc_read_plus(struct rpc_rqst *req,
756+
struct xdr_stream *xdr,
757+
const void *data)
758+
{
759+
const struct nfs_pgio_args *args = data;
760+
struct compound_hdr hdr = {
761+
.minorversion = nfs4_xdr_minorversion(&args->seq_args),
762+
};
763+
764+
encode_compound_hdr(xdr, req, &hdr);
765+
encode_sequence(xdr, &args->seq_args, &hdr);
766+
encode_putfh(xdr, args->fh, &hdr);
767+
encode_read_plus(xdr, args, &hdr);
768+
769+
rpc_prepare_reply_pages(req, args->pages, args->pgbase,
770+
args->count, hdr.replen);
771+
encode_nops(&hdr);
772+
}
773+
725774
/*
726775
* Encode SEEK request
727776
*/
@@ -970,6 +1019,71 @@ static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *re
9701019
return decode_op_hdr(xdr, OP_DEALLOCATE);
9711020
}
9721021

1022+
static int decode_read_plus_data(struct xdr_stream *xdr, struct nfs_pgio_res *res,
1023+
uint32_t *eof)
1024+
{
1025+
uint32_t count, recvd;
1026+
uint64_t offset;
1027+
__be32 *p;
1028+
1029+
p = xdr_inline_decode(xdr, 8 + 4);
1030+
if (unlikely(!p))
1031+
return -EIO;
1032+
1033+
p = xdr_decode_hyper(p, &offset);
1034+
count = be32_to_cpup(p);
1035+
recvd = xdr_read_pages(xdr, count);
1036+
res->count += recvd;
1037+
1038+
if (count > recvd) {
1039+
dprintk("NFS: server cheating in read reply: "
1040+
"count %u > recvd %u\n", count, recvd);
1041+
*eof = 0;
1042+
return 1;
1043+
}
1044+
1045+
return 0;
1046+
}
1047+
1048+
static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
1049+
{
1050+
uint32_t eof, segments, type;
1051+
int status;
1052+
__be32 *p;
1053+
1054+
status = decode_op_hdr(xdr, OP_READ_PLUS);
1055+
if (status)
1056+
return status;
1057+
1058+
p = xdr_inline_decode(xdr, 4 + 4);
1059+
if (unlikely(!p))
1060+
return -EIO;
1061+
1062+
eof = be32_to_cpup(p++);
1063+
segments = be32_to_cpup(p++);
1064+
if (segments == 0)
1065+
goto out;
1066+
1067+
p = xdr_inline_decode(xdr, 4);
1068+
if (unlikely(!p))
1069+
return -EIO;
1070+
1071+
type = be32_to_cpup(p++);
1072+
if (type == NFS4_CONTENT_DATA)
1073+
status = decode_read_plus_data(xdr, res, &eof);
1074+
else
1075+
return -EINVAL;
1076+
1077+
if (status)
1078+
return status;
1079+
if (segments > 1)
1080+
eof = 0;
1081+
1082+
out:
1083+
res->eof = eof;
1084+
return 0;
1085+
}
1086+
9731087
static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
9741088
{
9751089
int status;
@@ -1146,6 +1260,33 @@ static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
11461260
return status;
11471261
}
11481262

1263+
/*
1264+
* Decode READ_PLUS request
1265+
*/
1266+
static int nfs4_xdr_dec_read_plus(struct rpc_rqst *rqstp,
1267+
struct xdr_stream *xdr,
1268+
void *data)
1269+
{
1270+
struct nfs_pgio_res *res = data;
1271+
struct compound_hdr hdr;
1272+
int status;
1273+
1274+
status = decode_compound_hdr(xdr, &hdr);
1275+
if (status)
1276+
goto out;
1277+
status = decode_sequence(xdr, &res->seq_res, rqstp);
1278+
if (status)
1279+
goto out;
1280+
status = decode_putfh(xdr);
1281+
if (status)
1282+
goto out;
1283+
status = decode_read_plus(xdr, res);
1284+
if (!status)
1285+
status = res->count;
1286+
out:
1287+
return status;
1288+
}
1289+
11491290
/*
11501291
* Decode SEEK request
11511292
*/

fs/nfs/nfs4client.c

+2
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,8 @@ static int nfs4_server_common_setup(struct nfs_server *server,
10451045
server->caps |= server->nfs_client->cl_mvops->init_caps;
10461046
if (server->flags & NFS_MOUNT_NORDIRPLUS)
10471047
server->caps &= ~NFS_CAP_READDIRPLUS;
1048+
if (server->nfs_client->cl_proto == XPRT_TRANSPORT_RDMA)
1049+
server->caps &= ~NFS_CAP_READ_PLUS;
10481050
/*
10491051
* Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower
10501052
* authentication.

fs/nfs/nfs4proc.c

+40-3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070

7171
#include "nfs4trace.h"
7272

73+
#ifdef CONFIG_NFS_V4_2
74+
#include "nfs42.h"
75+
#endif /* CONFIG_NFS_V4_2 */
76+
7377
#define NFSDBG_FACILITY NFSDBG_PROC
7478

7579
#define NFS4_BITMASK_SZ 3
@@ -5272,28 +5276,60 @@ static bool nfs4_read_stateid_changed(struct rpc_task *task,
52725276
return true;
52735277
}
52745278

5275-
static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
5279+
static bool nfs4_read_plus_not_supported(struct rpc_task *task,
5280+
struct nfs_pgio_header *hdr)
52765281
{
5282+
struct nfs_server *server = NFS_SERVER(hdr->inode);
5283+
struct rpc_message *msg = &task->tk_msg;
52775284

5285+
if (msg->rpc_proc == &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS] &&
5286+
server->caps & NFS_CAP_READ_PLUS && task->tk_status == -ENOTSUPP) {
5287+
server->caps &= ~NFS_CAP_READ_PLUS;
5288+
msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
5289+
rpc_restart_call_prepare(task);
5290+
return true;
5291+
}
5292+
return false;
5293+
}
5294+
5295+
static int nfs4_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
5296+
{
52785297
dprintk("--> %s\n", __func__);
52795298

52805299
if (!nfs4_sequence_done(task, &hdr->res.seq_res))
52815300
return -EAGAIN;
52825301
if (nfs4_read_stateid_changed(task, &hdr->args))
52835302
return -EAGAIN;
5303+
if (nfs4_read_plus_not_supported(task, hdr))
5304+
return -EAGAIN;
52845305
if (task->tk_status > 0)
52855306
nfs_invalidate_atime(hdr->inode);
52865307
return hdr->pgio_done_cb ? hdr->pgio_done_cb(task, hdr) :
52875308
nfs4_read_done_cb(task, hdr);
52885309
}
52895310

5311+
#ifdef CONFIG_NFS_V4_2
5312+
static void nfs42_read_plus_support(struct nfs_server *server, struct rpc_message *msg)
5313+
{
5314+
if (server->caps & NFS_CAP_READ_PLUS)
5315+
msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ_PLUS];
5316+
else
5317+
msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
5318+
}
5319+
#else
5320+
static void nfs42_read_plus_support(struct nfs_server *server, struct rpc_message *msg)
5321+
{
5322+
msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
5323+
}
5324+
#endif /* CONFIG_NFS_V4_2 */
5325+
52905326
static void nfs4_proc_read_setup(struct nfs_pgio_header *hdr,
52915327
struct rpc_message *msg)
52925328
{
52935329
hdr->timestamp = jiffies;
52945330
if (!hdr->pgio_done_cb)
52955331
hdr->pgio_done_cb = nfs4_read_done_cb;
5296-
msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
5332+
nfs42_read_plus_support(NFS_SERVER(hdr->inode), msg);
52975333
nfs4_init_sequence(&hdr->args.seq_args, &hdr->res.seq_res, 0, 0);
52985334
}
52995335

@@ -10215,7 +10251,8 @@ static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = {
1021510251
| NFS_CAP_SEEK
1021610252
| NFS_CAP_LAYOUTSTATS
1021710253
| NFS_CAP_CLONE
10218-
| NFS_CAP_LAYOUTERROR,
10254+
| NFS_CAP_LAYOUTERROR
10255+
| NFS_CAP_READ_PLUS,
1021910256
.init_client = nfs41_init_client,
1022010257
.shutdown_client = nfs41_shutdown_client,
1022110258
.match_stateid = nfs41_match_stateid,

fs/nfs/nfs4xdr.c

+1
Original file line numberDiff line numberDiff line change
@@ -7615,6 +7615,7 @@ const struct rpc_procinfo nfs4_procedures[] = {
76157615
PROC42(SETXATTR, enc_setxattr, dec_setxattr),
76167616
PROC42(LISTXATTRS, enc_listxattrs, dec_listxattrs),
76177617
PROC42(REMOVEXATTR, enc_removexattr, dec_removexattr),
7618+
PROC42(READ_PLUS, enc_read_plus, dec_read_plus),
76187619
};
76197620

76207621
static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];

include/linux/nfs4.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,13 @@ enum {
551551

552552
NFSPROC4_CLNT_LOOKUPP,
553553
NFSPROC4_CLNT_LAYOUTERROR,
554-
555554
NFSPROC4_CLNT_COPY_NOTIFY,
556555

557556
NFSPROC4_CLNT_GETXATTR,
558557
NFSPROC4_CLNT_SETXATTR,
559558
NFSPROC4_CLNT_LISTXATTRS,
560559
NFSPROC4_CLNT_REMOVEXATTR,
560+
NFSPROC4_CLNT_READ_PLUS,
561561
};
562562

563563
/* nfs41 types */

include/linux/nfs_fs_sb.h

+1
Original file line numberDiff line numberDiff line change
@@ -287,5 +287,6 @@ struct nfs_server {
287287
#define NFS_CAP_LAYOUTERROR (1U << 26)
288288
#define NFS_CAP_COPY_NOTIFY (1U << 27)
289289
#define NFS_CAP_XATTR (1U << 28)
290+
#define NFS_CAP_READ_PLUS (1U << 29)
290291

291292
#endif

include/linux/nfs_xdr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ struct nfs_pgio_args {
657657
struct nfs_pgio_res {
658658
struct nfs4_sequence_res seq_res;
659659
struct nfs_fattr * fattr;
660-
__u32 count;
660+
__u64 count;
661661
__u32 op_status;
662662
union {
663663
struct {

0 commit comments

Comments
 (0)