aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorAnna Schumaker <Anna.Schumaker@netapp.com>2014-09-26 13:58:48 -0400
committerTrond Myklebust <trond.myklebust@primarydata.com>2014-09-30 16:24:56 -0400
commit1c6dcbe5ceff81c2cf8d929646af675cd59fe7c0 (patch)
tree1e432e1decca1b3a6de427db31db5737d997a7f5 /fs/nfs
parent4a3a0ebad1360696125bf34d89de55d71c4d0eaa (diff)
NFS: Implement SEEK
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() if the server does not have SEEK support. Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/Makefile1
-rw-r--r--fs/nfs/inode.c2
-rw-r--r--fs/nfs/nfs42.h14
-rw-r--r--fs/nfs/nfs42proc.c69
-rw-r--r--fs/nfs/nfs42xdr.c98
-rw-r--r--fs/nfs/nfs4_fs.h3
-rw-r--r--fs/nfs/nfs4file.c25
-rw-r--r--fs/nfs/nfs4proc.c4
-rw-r--r--fs/nfs/nfs4xdr.c7
9 files changed, 221 insertions, 2 deletions
diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile
index 4782e0840dcc..04cb830fa09f 100644
--- a/fs/nfs/Makefile
+++ b/fs/nfs/Makefile
@@ -28,6 +28,7 @@ nfsv4-y := nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o nfs4super.o nfs4file.o
28nfsv4-$(CONFIG_NFS_USE_LEGACY_DNS) += cache_lib.o 28nfsv4-$(CONFIG_NFS_USE_LEGACY_DNS) += cache_lib.o
29nfsv4-$(CONFIG_SYSCTL) += nfs4sysctl.o 29nfsv4-$(CONFIG_SYSCTL) += nfs4sysctl.o
30nfsv4-$(CONFIG_NFS_V4_1) += pnfs.o pnfs_dev.o 30nfsv4-$(CONFIG_NFS_V4_1) += pnfs.o pnfs_dev.o
31nfsv4-$(CONFIG_NFS_V4_2) += nfs42proc.o
31 32
32obj-$(CONFIG_PNFS_FILE_LAYOUT) += filelayout/ 33obj-$(CONFIG_PNFS_FILE_LAYOUT) += filelayout/
33obj-$(CONFIG_PNFS_OBJLAYOUT) += objlayout/ 34obj-$(CONFIG_PNFS_OBJLAYOUT) += objlayout/
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 577a36f0a510..56d073ede3c7 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -716,6 +716,7 @@ struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx)
716 kfree(new); 716 kfree(new);
717 return res; 717 return res;
718} 718}
719EXPORT_SYMBOL_GPL(nfs_get_lock_context);
719 720
720void nfs_put_lock_context(struct nfs_lock_context *l_ctx) 721void nfs_put_lock_context(struct nfs_lock_context *l_ctx)
721{ 722{
@@ -728,6 +729,7 @@ void nfs_put_lock_context(struct nfs_lock_context *l_ctx)
728 spin_unlock(&inode->i_lock); 729 spin_unlock(&inode->i_lock);
729 kfree(l_ctx); 730 kfree(l_ctx);
730} 731}
732EXPORT_SYMBOL_GPL(nfs_put_lock_context);
731 733
732/** 734/**
733 * nfs_close_context - Common close_context() routine NFSv2/v3 735 * nfs_close_context - Common close_context() routine NFSv2/v3
diff --git a/fs/nfs/nfs42.h b/fs/nfs/nfs42.h
new file mode 100644
index 000000000000..d10333a197bf
--- /dev/null
+++ b/fs/nfs/nfs42.h
@@ -0,0 +1,14 @@
1/*
2 * Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com>
3 */
4
5#ifndef __LINUX_FS_NFS_NFS4_2_H
6#define __LINUX_FS_NFS_NFS4_2_H
7
8/* nfs4.2proc.c */
9loff_t nfs42_proc_llseek(struct file *, loff_t, int);
10
11/* nfs4.2xdr.h */
12extern struct rpc_procinfo nfs4_2_procedures[];
13
14#endif /* __LINUX_FS_NFS_NFS4_2_H */
diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c
new file mode 100644
index 000000000000..0886f1db5917
--- /dev/null
+++ b/fs/nfs/nfs42proc.c
@@ -0,0 +1,69 @@
1/*
2 * Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com>
3 */
4#include <linux/fs.h>
5#include <linux/sunrpc/sched.h>
6#include <linux/nfs.h>
7#include <linux/nfs3.h>
8#include <linux/nfs4.h>
9#include <linux/nfs_xdr.h>
10#include <linux/nfs_fs.h>
11#include "nfs4_fs.h"
12#include "nfs42.h"
13
14static int nfs42_set_rw_stateid(nfs4_stateid *dst, struct file *file,
15 fmode_t fmode)
16{
17 struct nfs_open_context *open;
18 struct nfs_lock_context *lock;
19 int ret;
20
21 open = get_nfs_open_context(nfs_file_open_context(file));
22 lock = nfs_get_lock_context(open);
23 if (IS_ERR(lock)) {
24 put_nfs_open_context(open);
25 return PTR_ERR(lock);
26 }
27
28 ret = nfs4_set_rw_stateid(dst, open, lock, fmode);
29
30 nfs_put_lock_context(lock);
31 put_nfs_open_context(open);
32 return ret;
33}
34
35loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
36{
37 struct inode *inode = file_inode(filep);
38 struct nfs42_seek_args args = {
39 .sa_fh = NFS_FH(inode),
40 .sa_offset = offset,
41 .sa_what = (whence == SEEK_HOLE) ?
42 NFS4_CONTENT_HOLE : NFS4_CONTENT_DATA,
43 };
44 struct nfs42_seek_res res;
45 struct rpc_message msg = {
46 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEEK],
47 .rpc_argp = &args,
48 .rpc_resp = &res,
49 };
50 struct nfs_server *server = NFS_SERVER(inode);
51 int status;
52
53 if (!(server->caps & NFS_CAP_SEEK))
54 return -ENOTSUPP;
55
56 status = nfs42_set_rw_stateid(&args.sa_stateid, filep, FMODE_READ);
57 if (status)
58 return status;
59
60 nfs_wb_all(inode);
61 status = nfs4_call_sync(server->client, server, &msg,
62 &args.seq_args, &res.seq_res, 0);
63 if (status == -ENOTSUPP)
64 server->caps &= ~NFS_CAP_SEEK;
65 if (status)
66 return status;
67
68 return vfs_setpos(filep, res.sr_offset, inode->i_sb->s_maxbytes);
69}
diff --git a/fs/nfs/nfs42xdr.c b/fs/nfs/nfs42xdr.c
new file mode 100644
index 000000000000..c90469b604b8
--- /dev/null
+++ b/fs/nfs/nfs42xdr.c
@@ -0,0 +1,98 @@
1/*
2 * Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com>
3 */
4#ifndef __LINUX_FS_NFS_NFS4_2XDR_H
5#define __LINUX_FS_NFS_NFS4_2XDR_H
6
7#define encode_seek_maxsz (op_encode_hdr_maxsz + \
8 encode_stateid_maxsz + \
9 2 /* offset */ + \
10 1 /* whence */)
11#define decode_seek_maxsz (op_decode_hdr_maxsz + \
12 1 /* eof */ + \
13 1 /* whence */ + \
14 2 /* offset */ + \
15 2 /* length */)
16
17#define NFS4_enc_seek_sz (compound_encode_hdr_maxsz + \
18 encode_putfh_maxsz + \
19 encode_seek_maxsz)
20#define NFS4_dec_seek_sz (compound_decode_hdr_maxsz + \
21 decode_putfh_maxsz + \
22 decode_seek_maxsz)
23
24
25static void encode_seek(struct xdr_stream *xdr,
26 struct nfs42_seek_args *args,
27 struct compound_hdr *hdr)
28{
29 encode_op_hdr(xdr, OP_SEEK, decode_seek_maxsz, hdr);
30 encode_nfs4_stateid(xdr, &args->sa_stateid);
31 encode_uint64(xdr, args->sa_offset);
32 encode_uint32(xdr, args->sa_what);
33}
34
35/*
36 * Encode SEEK request
37 */
38static void nfs4_xdr_enc_seek(struct rpc_rqst *req,
39 struct xdr_stream *xdr,
40 struct nfs42_seek_args *args)
41{
42 struct compound_hdr hdr = {
43 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
44 };
45
46 encode_compound_hdr(xdr, req, &hdr);
47 encode_sequence(xdr, &args->seq_args, &hdr);
48 encode_putfh(xdr, args->sa_fh, &hdr);
49 encode_seek(xdr, args, &hdr);
50 encode_nops(&hdr);
51}
52
53static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
54{
55 int status;
56 __be32 *p;
57
58 status = decode_op_hdr(xdr, OP_SEEK);
59 if (status)
60 return status;
61
62 p = xdr_inline_decode(xdr, 4 + 8);
63 if (unlikely(!p))
64 goto out_overflow;
65
66 res->sr_eof = be32_to_cpup(p++);
67 p = xdr_decode_hyper(p, &res->sr_offset);
68 return 0;
69
70out_overflow:
71 print_overflow_msg(__func__, xdr);
72 return -EIO;
73}
74
75/*
76 * Decode SEEK request
77 */
78static int nfs4_xdr_dec_seek(struct rpc_rqst *rqstp,
79 struct xdr_stream *xdr,
80 struct nfs42_seek_res *res)
81{
82 struct compound_hdr hdr;
83 int status;
84
85 status = decode_compound_hdr(xdr, &hdr);
86 if (status)
87 goto out;
88 status = decode_sequence(xdr, &res->seq_res, rqstp);
89 if (status)
90 goto out;
91 status = decode_putfh(xdr);
92 if (status)
93 goto out;
94 status = decode_seek(xdr, res);
95out:
96 return status;
97}
98#endif /* __LINUX_FS_NFS_NFS4_2XDR_H */
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 92193eddb41d..b6b518d18aa7 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -227,6 +227,9 @@ int nfs4_replace_transport(struct nfs_server *server,
227 const struct nfs4_fs_locations *locations); 227 const struct nfs4_fs_locations *locations);
228 228
229/* nfs4proc.c */ 229/* nfs4proc.c */
230extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *,
231 struct rpc_message *, struct nfs4_sequence_args *,
232 struct nfs4_sequence_res *, int);
230extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *); 233extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *);
231extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *); 234extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *);
232extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool); 235extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index a816f0627a6c..4dffa3a64731 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -8,6 +8,10 @@
8#include "fscache.h" 8#include "fscache.h"
9#include "pnfs.h" 9#include "pnfs.h"
10 10
11#ifdef CONFIG_NFS_V4_2
12#include "nfs42.h"
13#endif
14
11#define NFSDBG_FACILITY NFSDBG_FILE 15#define NFSDBG_FACILITY NFSDBG_FILE
12 16
13static int 17static int
@@ -115,8 +119,29 @@ nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
115 return ret; 119 return ret;
116} 120}
117 121
122#ifdef CONFIG_NFS_V4_2
123static loff_t nfs4_file_llseek(struct file *filep, loff_t offset, int whence)
124{
125 loff_t ret;
126
127 switch (whence) {
128 case SEEK_HOLE:
129 case SEEK_DATA:
130 ret = nfs42_proc_llseek(filep, offset, whence);
131 if (ret != -ENOTSUPP)
132 return ret;
133 default:
134 return nfs_file_llseek(filep, offset, whence);
135 }
136}
137#endif /* CONFIG_NFS_V4_2 */
138
118const struct file_operations nfs4_file_operations = { 139const struct file_operations nfs4_file_operations = {
140#ifdef CONFIG_NFS_V4_2
141 .llseek = nfs4_file_llseek,
142#else
119 .llseek = nfs_file_llseek, 143 .llseek = nfs_file_llseek,
144#endif
120 .read = new_sync_read, 145 .read = new_sync_read,
121 .write = new_sync_write, 146 .write = new_sync_write,
122 .read_iter = nfs_file_read, 147 .read_iter = nfs_file_read,
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 7dd8aca31c29..f3a59f1fb498 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -875,7 +875,6 @@ static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
875 return ret; 875 return ret;
876} 876}
877 877
878static
879int nfs4_call_sync(struct rpc_clnt *clnt, 878int nfs4_call_sync(struct rpc_clnt *clnt,
880 struct nfs_server *server, 879 struct nfs_server *server,
881 struct rpc_message *msg, 880 struct rpc_message *msg,
@@ -8429,7 +8428,8 @@ static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
8429 | NFS_CAP_CHANGE_ATTR 8428 | NFS_CAP_CHANGE_ATTR
8430 | NFS_CAP_POSIX_LOCK 8429 | NFS_CAP_POSIX_LOCK
8431 | NFS_CAP_STATEID_NFSV41 8430 | NFS_CAP_STATEID_NFSV41
8432 | NFS_CAP_ATOMIC_OPEN_V1, 8431 | NFS_CAP_ATOMIC_OPEN_V1
8432 | NFS_CAP_SEEK,
8433 .init_client = nfs41_init_client, 8433 .init_client = nfs41_init_client,
8434 .shutdown_client = nfs41_shutdown_client, 8434 .shutdown_client = nfs41_shutdown_client,
8435 .match_stateid = nfs41_match_stateid, 8435 .match_stateid = nfs41_match_stateid,
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index e13b59d8d9aa..949e8717118c 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -7427,6 +7427,10 @@ nfs4_stat_to_errno(int stat)
7427 return -stat; 7427 return -stat;
7428} 7428}
7429 7429
7430#ifdef CONFIG_NFS_V4_2
7431#include "nfs42xdr.c"
7432#endif /* CONFIG_NFS_V4_2 */
7433
7430#define PROC(proc, argtype, restype) \ 7434#define PROC(proc, argtype, restype) \
7431[NFSPROC4_CLNT_##proc] = { \ 7435[NFSPROC4_CLNT_##proc] = { \
7432 .p_proc = NFSPROC4_COMPOUND, \ 7436 .p_proc = NFSPROC4_COMPOUND, \
@@ -7495,6 +7499,9 @@ struct rpc_procinfo nfs4_procedures[] = {
7495 enc_bind_conn_to_session, dec_bind_conn_to_session), 7499 enc_bind_conn_to_session, dec_bind_conn_to_session),
7496 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid), 7500 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
7497#endif /* CONFIG_NFS_V4_1 */ 7501#endif /* CONFIG_NFS_V4_1 */
7502#ifdef CONFIG_NFS_V4_2
7503 PROC(SEEK, enc_seek, dec_seek),
7504#endif /* CONFIG_NFS_V4_2 */
7498}; 7505};
7499 7506
7500const struct rpc_version nfs_version4 = { 7507const struct rpc_version nfs_version4 = {