From patchwork Wed Jan 28 20:42:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schumaker, Anna" X-Patchwork-Id: 5731141 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 46BC59F38B for ; Wed, 28 Jan 2015 21:36:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4F0B32024D for ; Wed, 28 Jan 2015 21:36:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30A0C201DD for ; Wed, 28 Jan 2015 21:36:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754865AbbA1VgM (ORCPT ); Wed, 28 Jan 2015 16:36:12 -0500 Received: from mx142.netapp.com ([216.240.21.19]:27516 "EHLO mx142.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761452AbbA1UnE (ORCPT ); Wed, 28 Jan 2015 15:43:04 -0500 X-IronPort-AV: E=Sophos;i="5.09,482,1418112000"; d="scan'208";a="18371885" Received: from vmwexchts02-prd.hq.netapp.com ([10.122.105.23]) by mx142-out.netapp.com with ESMTP; 28 Jan 2015 12:43:02 -0800 Received: from smtp2.corp.netapp.com (10.57.159.114) by VMWEXCHTS02-PRD.hq.netapp.com (10.122.105.23) with Microsoft SMTP Server id 15.0.995.29; Wed, 28 Jan 2015 12:43:02 -0800 Received: from davros.com ([10.63.237.113]) by smtp2.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id t0SKgwdF024534; Wed, 28 Jan 2015 12:43:01 -0800 (PST) From: To: CC: Subject: [PATCH v2 3/4] NFSD: Add READ_PLUS support for hole segments Date: Wed, 28 Jan 2015 15:42:56 -0500 Message-ID: <1422477777-27933-4-git-send-email-Anna.Schumaker@Netapp.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1422477777-27933-1-git-send-email-Anna.Schumaker@Netapp.com> References: <1422477777-27933-1-git-send-email-Anna.Schumaker@Netapp.com> MIME-Version: 1.0 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=unavailable 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 From: Anna Schumaker This patch adds support for returning NFS4_CONTENT_HOLE segments to the client. I did notice a race condition where the same offset can be reported as both a hole and as data, and this patch gets around this without a lock by encoding questionable regions as data. Signed-off-by: Anna Schumaker --- fs/nfsd/nfs4proc.c | 4 ++-- fs/nfsd/nfs4xdr.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index fdf9ce3..3db34ee 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -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); } diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 480b07f..c85e658 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -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: