Commit | Line | Data |
---|---|---|
1c6dcbe5 AS |
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 | ||
14 | static 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 | ||
f4ac1674 AS |
35 | static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, |
36 | loff_t offset, loff_t len) | |
37 | { | |
38 | struct inode *inode = file_inode(filep); | |
39 | struct nfs42_falloc_args args = { | |
40 | .falloc_fh = NFS_FH(inode), | |
41 | .falloc_offset = offset, | |
42 | .falloc_length = len, | |
43 | }; | |
44 | struct nfs42_falloc_res res; | |
45 | struct nfs_server *server = NFS_SERVER(inode); | |
46 | int status; | |
47 | ||
48 | msg->rpc_argp = &args; | |
49 | msg->rpc_resp = &res; | |
50 | ||
51 | status = nfs42_set_rw_stateid(&args.falloc_stateid, filep, FMODE_WRITE); | |
52 | if (status) | |
53 | return status; | |
54 | ||
55 | return nfs4_call_sync(server->client, server, msg, | |
56 | &args.seq_args, &res.seq_res, 0); | |
57 | } | |
58 | ||
59 | static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, | |
60 | loff_t offset, loff_t len) | |
61 | { | |
62 | struct nfs_server *server = NFS_SERVER(file_inode(filep)); | |
63 | struct nfs4_exception exception = { }; | |
64 | int err; | |
65 | ||
66 | do { | |
67 | err = _nfs42_proc_fallocate(msg, filep, offset, len); | |
68 | if (err == -ENOTSUPP) | |
69 | return -EOPNOTSUPP; | |
70 | err = nfs4_handle_exception(server, err, &exception); | |
71 | } while (exception.retry); | |
72 | ||
73 | return err; | |
74 | } | |
75 | ||
76 | int nfs42_proc_allocate(struct file *filep, loff_t offset, loff_t len) | |
77 | { | |
78 | struct rpc_message msg = { | |
79 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ALLOCATE], | |
80 | }; | |
81 | struct inode *inode = file_inode(filep); | |
82 | int err; | |
83 | ||
84 | if (!nfs_server_capable(inode, NFS_CAP_ALLOCATE)) | |
85 | return -EOPNOTSUPP; | |
86 | ||
87 | err = nfs42_proc_fallocate(&msg, filep, offset, len); | |
88 | if (err == -EOPNOTSUPP) | |
89 | NFS_SERVER(inode)->caps &= ~NFS_CAP_ALLOCATE; | |
90 | return err; | |
91 | } | |
92 | ||
1c6dcbe5 AS |
93 | loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence) |
94 | { | |
95 | struct inode *inode = file_inode(filep); | |
96 | struct nfs42_seek_args args = { | |
97 | .sa_fh = NFS_FH(inode), | |
98 | .sa_offset = offset, | |
99 | .sa_what = (whence == SEEK_HOLE) ? | |
100 | NFS4_CONTENT_HOLE : NFS4_CONTENT_DATA, | |
101 | }; | |
102 | struct nfs42_seek_res res; | |
103 | struct rpc_message msg = { | |
104 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEEK], | |
105 | .rpc_argp = &args, | |
106 | .rpc_resp = &res, | |
107 | }; | |
108 | struct nfs_server *server = NFS_SERVER(inode); | |
109 | int status; | |
110 | ||
878ffa9f | 111 | if (!nfs_server_capable(inode, NFS_CAP_SEEK)) |
1c6dcbe5 AS |
112 | return -ENOTSUPP; |
113 | ||
114 | status = nfs42_set_rw_stateid(&args.sa_stateid, filep, FMODE_READ); | |
115 | if (status) | |
116 | return status; | |
117 | ||
118 | nfs_wb_all(inode); | |
119 | status = nfs4_call_sync(server->client, server, &msg, | |
120 | &args.seq_args, &res.seq_res, 0); | |
121 | if (status == -ENOTSUPP) | |
122 | server->caps &= ~NFS_CAP_SEEK; | |
123 | if (status) | |
124 | return status; | |
125 | ||
126 | return vfs_setpos(filep, res.sr_offset, inode->i_sb->s_maxbytes); | |
127 | } |