aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2010-12-14 09:55:20 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2010-12-16 12:37:21 -0500
commit661ad4239a51a2169a366a227c68cf3b654ab936 (patch)
treefef0e74f914c07b5031bc080a997fac650863591
parentf796f8b3ae292abb9cb2931e8db6fc1d69bba09d (diff)
NFS: Replace old NFSv2 decoder functions with xdr_stream-based ones
Clean up. Remove unused legacy result decoder functions, and any now unused decoder helper functions. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Tested-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
-rw-r--r--fs/nfs/nfs2xdr.c253
1 files changed, 4 insertions, 249 deletions
diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
index 827d1b8ad55b..ae751163da8b 100644
--- a/fs/nfs/nfs2xdr.c
+++ b/fs/nfs/nfs2xdr.c
@@ -91,15 +91,6 @@ static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
91/* 91/*
92 * Common NFS XDR functions as inlines 92 * Common NFS XDR functions as inlines
93 */ 93 */
94static inline __be32 *
95xdr_decode_fhandle(__be32 *p, struct nfs_fh *fhandle)
96{
97 /* NFSv2 handles have a fixed length */
98 fhandle->size = NFS2_FHSIZE;
99 memcpy(fhandle->data, p, NFS2_FHSIZE);
100 return p + XDR_QUADLEN(NFS2_FHSIZE);
101}
102
103static inline __be32* 94static inline __be32*
104xdr_decode_time(__be32 *p, struct timespec *timep) 95xdr_decode_time(__be32 *p, struct timespec *timep)
105{ 96{
@@ -642,48 +633,6 @@ static int nfs2_xdr_enc_readargs(struct rpc_rqst *req, __be32 *p,
642} 633}
643 634
644/* 635/*
645 * Decode READ reply
646 */
647static int
648nfs_xdr_readres(struct rpc_rqst *req, __be32 *p, struct nfs_readres *res)
649{
650 struct kvec *iov = req->rq_rcv_buf.head;
651 size_t hdrlen;
652 u32 count, recvd;
653 int status;
654
655 if ((status = ntohl(*p++)))
656 return nfs_stat_to_errno(status);
657 p = xdr_decode_fattr(p, res->fattr);
658
659 count = ntohl(*p++);
660 res->eof = 0;
661 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
662 if (iov->iov_len < hdrlen) {
663 dprintk("NFS: READ reply header overflowed:"
664 "length %Zu > %Zu\n", hdrlen, iov->iov_len);
665 return -errno_NFSERR_IO;
666 } else if (iov->iov_len != hdrlen) {
667 dprintk("NFS: READ header is short. iovec will be shifted.\n");
668 xdr_shift_buf(&req->rq_rcv_buf, iov->iov_len - hdrlen);
669 }
670
671 recvd = req->rq_rcv_buf.len - hdrlen;
672 if (count > recvd) {
673 dprintk("NFS: server cheating in read reply: "
674 "count %u > recvd %u\n", count, recvd);
675 count = recvd;
676 }
677
678 dprintk("RPC: readres OK count %u\n", count);
679 if (count < res->count)
680 res->count = count;
681
682 return count;
683}
684
685
686/*
687 * 2.2.9. writeargs 636 * 2.2.9. writeargs
688 * 637 *
689 * struct writeargs { 638 * struct writeargs {
@@ -848,105 +797,11 @@ static int nfs2_xdr_enc_readdirargs(struct rpc_rqst *req, __be32 *p,
848} 797}
849 798
850/* 799/*
851 * Decode the result of a readdir call. 800 * NFSv2 XDR decode functions
852 * We're not really decoding anymore, we just leave the buffer untouched 801 *
853 * and only check that it is syntactically correct. 802 * NFSv2 result types are defined in section 2.2 of RFC 1094:
854 * The real decoding happens in nfs_decode_entry below, called directly 803 * "NFS: Network File System Protocol Specification".
855 * from nfs_readdir for each entry.
856 */
857static int
858nfs_xdr_readdirres(struct rpc_rqst *req, __be32 *p, void *dummy)
859{
860 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
861 struct kvec *iov = rcvbuf->head;
862 struct page **page;
863 size_t hdrlen;
864 unsigned int pglen, recvd;
865 int status;
866
867 if ((status = ntohl(*p++)))
868 return nfs_stat_to_errno(status);
869
870 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
871 if (iov->iov_len < hdrlen) {
872 dprintk("NFS: READDIR reply header overflowed:"
873 "length %Zu > %Zu\n", hdrlen, iov->iov_len);
874 return -errno_NFSERR_IO;
875 } else if (iov->iov_len != hdrlen) {
876 dprintk("NFS: READDIR header is short. iovec will be shifted.\n");
877 xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen);
878 }
879
880 pglen = rcvbuf->page_len;
881 recvd = rcvbuf->len - hdrlen;
882 if (pglen > recvd)
883 pglen = recvd;
884 page = rcvbuf->pages;
885 return pglen;
886}
887
888__be32 *
889nfs_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_server *server, int plus)
890{
891 __be32 *p;
892 p = xdr_inline_decode(xdr, 4);
893 if (unlikely(!p))
894 goto out_overflow;
895 if (!ntohl(*p++)) {
896 p = xdr_inline_decode(xdr, 4);
897 if (unlikely(!p))
898 goto out_overflow;
899 if (!ntohl(*p++))
900 return ERR_PTR(-EAGAIN);
901 entry->eof = 1;
902 return ERR_PTR(-EBADCOOKIE);
903 }
904
905 p = xdr_inline_decode(xdr, 8);
906 if (unlikely(!p))
907 goto out_overflow;
908
909 entry->ino = ntohl(*p++);
910 entry->len = ntohl(*p++);
911
912 p = xdr_inline_decode(xdr, entry->len + 4);
913 if (unlikely(!p))
914 goto out_overflow;
915 entry->name = (const char *) p;
916 p += XDR_QUADLEN(entry->len);
917 entry->prev_cookie = entry->cookie;
918 entry->cookie = ntohl(*p++);
919
920 entry->d_type = DT_UNKNOWN;
921
922 p = xdr_inline_peek(xdr, 8);
923 if (p != NULL)
924 entry->eof = !p[0] && p[1];
925 else
926 entry->eof = 0;
927
928 return p;
929
930out_overflow:
931 print_overflow_msg(__func__, xdr);
932 return ERR_PTR(-EAGAIN);
933}
934
935/*
936 * NFS XDR decode functions
937 */
938/*
939 * Decode simple status reply
940 */ 804 */
941static int
942nfs_xdr_stat(struct rpc_rqst *req, __be32 *p, void *dummy)
943{
944 int status;
945
946 if ((status = ntohl(*p++)) != 0)
947 status = nfs_stat_to_errno(status);
948 return status;
949}
950 805
951static int nfs2_xdr_dec_stat(struct rpc_rqst *req, __be32 *p, 806static int nfs2_xdr_dec_stat(struct rpc_rqst *req, __be32 *p,
952 void *__unused) 807 void *__unused)
@@ -967,21 +822,6 @@ out_default:
967 return nfs_stat_to_errno(status); 822 return nfs_stat_to_errno(status);
968} 823}
969 824
970/*
971 * Decode attrstat reply
972 * GETATTR, SETATTR, WRITE
973 */
974static int
975nfs_xdr_attrstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr)
976{
977 int status;
978
979 if ((status = ntohl(*p++)))
980 return nfs_stat_to_errno(status);
981 xdr_decode_fattr(p, fattr);
982 return 0;
983}
984
985static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, __be32 *p, 825static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, __be32 *p,
986 struct nfs_fattr *result) 826 struct nfs_fattr *result)
987{ 827{
@@ -991,22 +831,6 @@ static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, __be32 *p,
991 return decode_attrstat(&xdr, result); 831 return decode_attrstat(&xdr, result);
992} 832}
993 833
994/*
995 * Decode diropres reply
996 * LOOKUP, CREATE, MKDIR
997 */
998static int
999nfs_xdr_diropres(struct rpc_rqst *req, __be32 *p, struct nfs_diropok *res)
1000{
1001 int status;
1002
1003 if ((status = ntohl(*p++)))
1004 return nfs_stat_to_errno(status);
1005 p = xdr_decode_fhandle(p, res->fh);
1006 xdr_decode_fattr(p, res->fattr);
1007 return 0;
1008}
1009
1010static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, __be32 *p, 834static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, __be32 *p,
1011 struct nfs_diropok *result) 835 struct nfs_diropok *result)
1012{ 836{
@@ -1017,46 +841,6 @@ static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, __be32 *p,
1017} 841}
1018 842
1019/* 843/*
1020 * Decode READLINK reply
1021 */
1022static int
1023nfs_xdr_readlinkres(struct rpc_rqst *req, __be32 *p, void *dummy)
1024{
1025 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
1026 struct kvec *iov = rcvbuf->head;
1027 size_t hdrlen;
1028 u32 len, recvd;
1029 int status;
1030
1031 if ((status = ntohl(*p++)))
1032 return nfs_stat_to_errno(status);
1033 /* Convert length of symlink */
1034 len = ntohl(*p++);
1035 if (len >= rcvbuf->page_len) {
1036 dprintk("nfs: server returned giant symlink!\n");
1037 return -ENAMETOOLONG;
1038 }
1039 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
1040 if (iov->iov_len < hdrlen) {
1041 dprintk("NFS: READLINK reply header overflowed:"
1042 "length %Zu > %Zu\n", hdrlen, iov->iov_len);
1043 return -errno_NFSERR_IO;
1044 } else if (iov->iov_len != hdrlen) {
1045 dprintk("NFS: READLINK header is short. iovec will be shifted.\n");
1046 xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen);
1047 }
1048 recvd = req->rq_rcv_buf.len - hdrlen;
1049 if (recvd < len) {
1050 dprintk("NFS: server cheating in readlink reply: "
1051 "count %u > recvd %u\n", len, recvd);
1052 return -EIO;
1053 }
1054
1055 xdr_terminate_string(rcvbuf, len);
1056 return 0;
1057}
1058
1059/*
1060 * 2.2.6. readlinkres 844 * 2.2.6. readlinkres
1061 * 845 *
1062 * union readlinkres switch (stat status) { 846 * union readlinkres switch (stat status) {
@@ -1120,16 +904,6 @@ out_default:
1120 return nfs_stat_to_errno(status); 904 return nfs_stat_to_errno(status);
1121} 905}
1122 906
1123/*
1124 * Decode WRITE reply
1125 */
1126static int
1127nfs_xdr_writeres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res)
1128{
1129 res->verf->committed = NFS_FILE_SYNC;
1130 return nfs_xdr_attrstat(req, p, res->fattr);
1131}
1132
1133static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, __be32 *p, 907static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, __be32 *p,
1134 struct nfs_writeres *result) 908 struct nfs_writeres *result)
1135{ 909{
@@ -1275,25 +1049,6 @@ out_default:
1275} 1049}
1276 1050
1277/* 1051/*
1278 * Decode STATFS reply
1279 */
1280static int
1281nfs_xdr_statfsres(struct rpc_rqst *req, __be32 *p, struct nfs2_fsstat *res)
1282{
1283 int status;
1284
1285 if ((status = ntohl(*p++)))
1286 return nfs_stat_to_errno(status);
1287
1288 res->tsize = ntohl(*p++);
1289 res->bsize = ntohl(*p++);
1290 res->blocks = ntohl(*p++);
1291 res->bfree = ntohl(*p++);
1292 res->bavail = ntohl(*p++);
1293 return 0;
1294}
1295
1296/*
1297 * 2.2.18. statfsres 1052 * 2.2.18. statfsres
1298 * 1053 *
1299 * union statfsres (stat status) { 1054 * union statfsres (stat status) {