From patchwork Tue Mar 22 18:53:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "J. Bruce Fields" X-Patchwork-Id: 8644661 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CE9EDC0553 for ; Tue, 22 Mar 2016 18:53:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DC193202AE for ; Tue, 22 Mar 2016 18:53:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E3DDB20270 for ; Tue, 22 Mar 2016 18:53:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751285AbcCVSxk (ORCPT ); Tue, 22 Mar 2016 14:53:40 -0400 Received: from fieldses.org ([173.255.197.46]:35722 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751209AbcCVSxk (ORCPT ); Tue, 22 Mar 2016 14:53:40 -0400 Received: by fieldses.org (Postfix, from userid 2815) id 7BBE31EF9; Tue, 22 Mar 2016 14:53:36 -0400 (EDT) Date: Tue, 22 Mar 2016 14:53:36 -0400 From: "J. Bruce Fields" To: Benjamin Coddington Cc: Jeff Layton , linux-nfs@vger.kernel.org Subject: Re: [PATCH v2] nfsd: use short read rather than i_size to set eof Message-ID: <20160322185336.GD4083@fieldses.org> References: <20160321213655.GB807@fieldses.org> <82e4c7a9756b21a4645421d04735ccf491b4296a.1458571329.git.bcodding@redhat.com> <20160322164624.GB4083@fieldses.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160322164624.GB4083@fieldses.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Possibly overkill, but I think I'll fold in something like this if you don't see an objection. --b. commit 58e18a2a14a0 Author: J. Bruce Fields Date: Tue Mar 22 14:08:11 2016 -0400 nfsd: document read eof logic The choice of checks here is a little subtle, let's document this for posterity. Signed-off-by: J. Bruce Fields --- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c index 83c9abb33e8b..df0f0a86f21d 100644 --- a/fs/nfsd/nfs3proc.c +++ b/fs/nfsd/nfs3proc.c @@ -168,8 +168,7 @@ nfsd3_proc_read(struct svc_rqst *rqstp, struct nfsd3_readargs *argp, &resp->count); if (nfserr == 0) { struct inode *inode = d_inode(resp->fh.fh_dentry); - resp->eof = (cnt > resp->count) || - ((argp->offset + resp->count) >= inode->i_size); + resp->eof = nfsd_eof_on_read(cnt, resp->count, argp->offset, inode->i_size); } RETURN_STATUS(nfserr); diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 90232bd7e498..9df898ba648f 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3387,8 +3387,8 @@ static __be32 nfsd4_encode_splice_read( return nfserr; } - eof = (len > maxcount) || - ((read->rd_offset + maxcount >= d_inode(read->rd_fhp->fh_dentry)->i_size)); + eof = nfsd_eof_on_read(len, maxcount, read->rd_offset, + d_inode(read->rd_fhp->fh_dentry)->i_size); *(p++) = htonl(eof); *(p++) = htonl(maxcount); @@ -3465,8 +3465,8 @@ static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, return nfserr; xdr_truncate_encode(xdr, starting_len + 8 + ((maxcount+3)&~3)); - eof = (len > maxcount) || - ((read->rd_offset + maxcount >= d_inode(read->rd_fhp->fh_dentry)->i_size)); + eof = nfsd_eof_on_read(len, maxcount, read->rd_offset, + d_inode(read->rd_fhp->fh_dentry)->i_size); tmp = htonl(eof); write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4); diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h index c11ba316f23f..6244e073c137 100644 --- a/fs/nfsd/vfs.h +++ b/fs/nfsd/vfs.h @@ -139,4 +139,24 @@ static inline int nfsd_create_is_exclusive(int createmode) || createmode == NFS4_CREATE_EXCLUSIVE4_1; } +static inline bool nfsd_eof_on_read(long requested, long read, + loff_t offset, loff_t size) +{ + /* We assume a short read means eof: */ + if (requested > read) + return true; + /* + * A non-short read might also reach end of file. The spec + * still requires us to set eof in that case. + * + * Further operations may have modified the file size since + * the read, so the following check is not atomic with the read. + * The only case we've seen that cause a problem for a client + * is the case where the read returned a count of 0 without + * setting eof. That case was fixed by the addition of the + * above check. + */ + return (offset + read >= size); +} + #endif /* LINUX_NFSD_VFS_H */