History

NFSD: Update nfsd_cache_append() to use xdr_stream

When inserting a DRC-cached response into the reply buffer, ensure that the reply buffer's xdr_stream is updated properly. Otherwise the server will send a garbage response.

Chuck Lever committed 3 years ago

Commit 49cecd81 parent bc1b5ac1 file · +8 −15Browse files

Unified · Split

fs/nfsd/nfscache.c+8−15
@@ -640,24 +640,17 @@ void nfsd_cache_update(struct svc_rqst *rqstp, struct nfsd_cacherep *rp, · 639 unmodified lines
640640 return;
641641 }
642642
643−/*
644− * Copy cached reply to current reply buffer. Should always fit.
645− * FIXME as reply is in a page, we should just attach the page, and
646− * keep a refcount....
647− */
648643 static int
649644 nfsd_cache_append(struct svc_rqst *rqstp, struct kvec *data)
650645 {
651− struct kvec *vec = &rqstp->rq_res.head[0];
652−
653− if (vec->iov_len + data->iov_len > PAGE_SIZE) {
654− printk(KERN_WARNING "nfsd: cached reply too large (%zd).\n",
655− data->iov_len);
656− return 0;
657− }
658− memcpy((char*)vec->iov_base + vec->iov_len, data->iov_base, data->iov_len);
659− vec->iov_len += data->iov_len;
660− return 1;
646+ __be32 *p;
647+
648+ p = xdr_reserve_space(&rqstp->rq_res_stream, data->iov_len);
649+ if (unlikely(!p))
650+ return false;
651+ memcpy(p, data->iov_base, data->iov_len);
652+ xdr_commit_encode(&rqstp->rq_res_stream);
653+ return true;
661654 }
662655
663656 /*