From patchwork Mon Oct 28 15:00:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan Schumaker X-Patchwork-Id: 3102841 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D8DBC9F431 for ; Mon, 28 Oct 2013 15:01:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6EA492024A for ; Mon, 28 Oct 2013 15:01:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F0629201B4 for ; Mon, 28 Oct 2013 15:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932335Ab3J1PAr (ORCPT ); Mon, 28 Oct 2013 11:00:47 -0400 Received: from mx11.netapp.com ([216.240.18.76]:7365 "EHLO mx11.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932677Ab3J1PAq (ORCPT ); Mon, 28 Oct 2013 11:00:46 -0400 X-IronPort-AV: E=Sophos;i="4.93,586,1378882800"; d="scan'208";a="66095823" Received: from vmwexceht02-prd.hq.netapp.com ([10.106.76.240]) by mx11-out.netapp.com with ESMTP; 28 Oct 2013 08:00:45 -0700 Received: from smtp1.corp.netapp.com (10.57.156.124) by VMWEXCEHT02-PRD.hq.netapp.com (10.106.76.240) with Microsoft SMTP Server id 14.3.123.3; Mon, 28 Oct 2013 08:00:46 -0700 Received: from davros.com (davros.ocarinaproject.vpn.netapp.com [10.63.231.232]) by smtp1.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id r9SF0ekU010068; Mon, 28 Oct 2013 08:00:44 -0700 (PDT) From: Anna Schumaker To: , Subject: [PATCH 3/3] NFS: Implement SEEK Date: Mon, 28 Oct 2013 11:00:18 -0400 Message-ID: <1382972418-2249-4-git-send-email-bjschuma@netapp.com> X-Mailer: git-send-email 1.8.4.1 In-Reply-To: <1382972418-2249-1-git-send-email-bjschuma@netapp.com> References: <1382972418-2249-1-git-send-email-bjschuma@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=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 The SEEK operation is used when an application makes an lseek call with either the SEEK_HOLE or SEEK_DATA flags set. I fall back on nfs_file_llseek() when other flags are set or in the NFS < 4.2 case. Signed-off-by: Anna Schumaker --- fs/nfs/nfs4_fs.h | 1 + fs/nfs/nfs4file.c | 38 +++++++++++++++++++++ fs/nfs/nfs4proc.c | 29 ++++++++++++++++ fs/nfs/nfs4xdr.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/nfs4.h | 1 + include/linux/nfs_xdr.h | 20 +++++++++++ 6 files changed, 180 insertions(+) diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index f52fc5f..badc1fa 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h @@ -355,6 +355,7 @@ nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp, #ifdef CONFIG_NFS_V4_2 int nfs42_proc_fallocate(struct nfs_server *, struct nfs42_write_plus_args *, struct nfs42_write_res *, struct rpc_cred *); +loff_t nfs42_proc_llseek(struct inode *, nfs4_stateid *, loff_t, int); #endif /* CONFIG_NFS_V4_2 */ extern const struct nfs4_minor_version_ops *nfs_v4_minor_ops[]; diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index caf0658..b88ba0c 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -218,10 +218,48 @@ static long nfs42_fallocate(struct file *file, int mode, loff_t offset, loff_t l err = nfs_wait_for_offload(&res); return err; } + +static loff_t nfs42_file_llseek(struct file *filep, loff_t offset, int whence) +{ + nfs4_stateid stateid; + struct nfs_open_context *ctx; + struct inode *inode = file_inode(filep); + loff_t pos; + + pos = nfs42_select_stateid(filep, &stateid, FMODE_READ | FMODE_WRITE, &ctx); + if (pos < 0) + return pos; + + nfs_wb_all(inode); + pos = nfs42_proc_llseek(inode, &stateid, offset, whence); + if (pos < 0) + return pos; + return vfs_setpos(filep, pos, inode->i_sb->s_maxbytes); +} + +static loff_t nfs4_file_llseek(struct file *filep, loff_t offset, int whence) +{ + struct nfs_server *server = NFS_SERVER(file_inode(filep)); + + if (server->nfs_client->cl_minorversion < 2) + return nfs_file_llseek(filep, offset, whence); + + switch (whence) { + case SEEK_HOLE: + case SEEK_DATA: + return nfs42_file_llseek(filep, offset, whence); + default: + return nfs_file_llseek(filep, offset, whence); + } +} #endif /* CONFIG_NFS_V4_2 */ const struct file_operations nfs4_file_operations = { +#ifdef CONFIG_NFS_V4_2 + .llseek = nfs4_file_llseek, +#else .llseek = nfs_file_llseek, +#endif .read = do_sync_read, .write = do_sync_write, .aio_read = nfs_file_read, diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 003bacb..79f1295 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -7865,6 +7865,35 @@ int nfs42_proc_fallocate(struct nfs_server *server, return err; } + +loff_t nfs42_proc_llseek(struct inode *inode, nfs4_stateid *stateid, + loff_t offset, int whence) +{ + struct nfs42_seek_args args = { + .sa_fh = NFS_FH(inode), + .sa_stateid = stateid, + .sa_offset = offset, + }; + struct nfs42_seek_res res; + struct rpc_message msg = { + .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEEK], + .rpc_argp = &args, + .rpc_resp = &res, + }; + struct nfs_server *server = NFS_SERVER(inode); + int status; + + if (whence == SEEK_HOLE) + args.sa_what = NFS4_CONTENT_HOLE; + else + args.sa_what = NFS4_CONTENT_DATA; + + status = nfs4_call_sync(server->client, server, &msg, + &args.seq_args, &res.seq_res, 0); + if (status) + return status; + return res.sr_offset; +} #endif /* CONFIG_NFS_V4_2 */ static bool nfs4_match_stateid(const nfs4_stateid *s1, diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 28e2fad..f7ced39 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -435,6 +435,10 @@ static int nfs4_stat_to_errno(int); 2 /* bytes written */ + \ 1 /* committed */ + \ XDR_QUADLEN(NFS4_VERIFIER_SIZE)) +#define encode_seek_maxsz (op_encode_hdr_maxsz + \ + XDR_QUADLEN(NFS4_STATEID_SIZE) + \ + 2 + 1) +#define decode_seek_maxsz (op_decode_hdr_maxsz + 1 + 1 + 5) #endif /* CONFIG_NFS_V4_2 */ #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */ @@ -903,6 +907,12 @@ EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead); #define NFS4_dec_write_plus_sz (compound_decode_hdr_maxsz + \ decode_putfh_maxsz + \ decode_write_plus_maxsz) +#define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \ + encode_putfh_maxsz + \ + encode_seek_maxsz) +#define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \ + decode_putfh_maxsz + \ + decode_seek_maxsz) #endif /* CONFIG_NFS_V4_2 */ static const umode_t nfs_type2fmt[] = { @@ -2104,6 +2114,16 @@ static void encode_write_plus(struct xdr_stream *xdr, encode_uint32(xdr, 1); encode_write_plus_hole(xdr, args); } + +static void encode_seek(struct xdr_stream *xdr, + struct nfs42_seek_args *args, + struct compound_hdr *hdr) +{ + encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr); + encode_nfs4_stateid(xdr, args->sa_stateid); + encode_uint64(xdr, args->sa_offset); + encode_uint32(xdr, args->sa_what); +} #endif /* CONFIG_NFS_V4_2 */ /* @@ -3071,6 +3091,25 @@ static void nfs4_xdr_enc_write_plus(struct rpc_rqst *req, encode_nops(&hdr); return; } + +/* + * Encode SEEK request + */ +static void nfs4_xdr_enc_seek(struct rpc_rqst *req, + struct xdr_stream *xdr, + struct nfs42_seek_args *args) +{ + struct compound_hdr hdr = { + .minorversion = nfs4_xdr_minorversion(&args->seq_args), + }; + + encode_compound_hdr(xdr, req, &hdr); + encode_sequence(xdr, &args->seq_args, &hdr); + encode_putfh(xdr, args->sa_fh, &hdr); + encode_seek(xdr, args, &hdr); + encode_nops(&hdr); + return; +} #endif /* CONFIG_NFS_V4_2 */ static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) @@ -6081,6 +6120,33 @@ static int decode_writeplus(struct xdr_stream *xdr, struct nfs42_write_res *res) return decode_write_response(xdr, res); } + +static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res) +{ + int status; + __be32 *p; + + status = decode_op_hdr(xdr, OP_SEEK); + if (status) + return status; + + p = xdr_inline_decode(xdr, 28); + if (unlikely(!p)) + goto out_overflow; + + res->sr_eof = be32_to_cpup(p++); + res->sr_whence = be32_to_cpup(p++); + p = xdr_decode_hyper(p, &res->sr_offset); + p = xdr_decode_hyper(p, &res->sr_length); + res->sr_allocated = be32_to_cpup(p); + return 0; + +out_overflow: + print_overflow_msg(__func__, xdr); + return -EIO; + + return 0; +} #endif /* CONFIG_NFS_V4_2 */ /* @@ -7320,6 +7386,30 @@ static int nfs4_xdr_dec_write_plus(struct rpc_rqst *rqstp, out: return status; } + +/* + * Decode SEEK request + */ +static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp, + struct xdr_stream *xdr, + struct nfs42_seek_res *res) +{ + struct compound_hdr hdr; + int status; + + status = decode_compound_hdr(xdr, &hdr); + if (status) + goto out; + status = decode_sequence(xdr, &res->seq_res, rqstp); + if (status) + goto out; + status = decode_putfh(xdr); + if (status) + goto out; + status = decode_seek(xdr, res); +out: + return status; +} #endif /* CONFIG_NFS_V4_2 */ /** @@ -7533,6 +7623,7 @@ struct rpc_procinfo nfs4_procedures[] = { #endif /* CONFIG_NFS_V4_1 */ #if defined(CONFIG_NFS_V4_2) PROC(WRITE_PLUS, enc_write_plus, dec_write_plus), + PROC(SEEK, enc_seek, dec_seek), #endif /* CONFIG_NFS_V4_2 */ }; diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h index 237016a..0d9033a 100644 --- a/include/linux/nfs4.h +++ b/include/linux/nfs4.h @@ -492,6 +492,7 @@ enum { /* nfs42 */ NFSPROC4_CLNT_WRITE_PLUS, + NFSPROC4_CLNT_SEEK, }; /* nfs41 types */ diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h index d8cbe5a..a46f803 100644 --- a/include/linux/nfs_xdr.h +++ b/include/linux/nfs_xdr.h @@ -1236,6 +1236,26 @@ struct nfs42_write_plus_args { u32 wp_allocated; }; +struct nfs42_seek_args { + struct nfs4_sequence_args seq_args; + + struct nfs_fh *sa_fh; + nfs4_stateid *sa_stateid; + u64 sa_offset; + u32 sa_what; +}; + +struct nfs42_seek_res { + struct nfs4_sequence_res seq_res; + unsigned int status; + + u32 sr_eof; + u32 sr_whence; + u64 sr_offset; + u64 sr_length; + u32 sr_allocated; +}; + struct nfs42_write_res { struct nfs4_sequence_res seq_res;