mtd: nand: omap2: show parent device structure in sysfs
[linux-2.6/btrfs-unstable.git] / fs / nfs / nfs42proc.c
blobd731bbf974aaf1d4bf695c2cb57a99cc586e0258
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 #include "iostat.h"
14 #include "pnfs.h"
15 #include "internal.h"
17 #define NFSDBG_FACILITY NFSDBG_PNFS
19 static int nfs42_set_rw_stateid(nfs4_stateid *dst, struct file *file,
20 fmode_t fmode)
22 struct nfs_open_context *open;
23 struct nfs_lock_context *lock;
24 int ret;
26 open = get_nfs_open_context(nfs_file_open_context(file));
27 lock = nfs_get_lock_context(open);
28 if (IS_ERR(lock)) {
29 put_nfs_open_context(open);
30 return PTR_ERR(lock);
33 ret = nfs4_set_rw_stateid(dst, open, lock, fmode);
35 nfs_put_lock_context(lock);
36 put_nfs_open_context(open);
37 return ret;
40 static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
41 loff_t offset, loff_t len)
43 struct inode *inode = file_inode(filep);
44 struct nfs_server *server = NFS_SERVER(inode);
45 struct nfs42_falloc_args args = {
46 .falloc_fh = NFS_FH(inode),
47 .falloc_offset = offset,
48 .falloc_length = len,
49 .falloc_bitmask = server->cache_consistency_bitmask,
51 struct nfs42_falloc_res res = {
52 .falloc_server = server,
54 int status;
56 msg->rpc_argp = &args;
57 msg->rpc_resp = &res;
59 status = nfs42_set_rw_stateid(&args.falloc_stateid, filep, FMODE_WRITE);
60 if (status)
61 return status;
63 res.falloc_fattr = nfs_alloc_fattr();
64 if (!res.falloc_fattr)
65 return -ENOMEM;
67 status = nfs4_call_sync(server->client, server, msg,
68 &args.seq_args, &res.seq_res, 0);
69 if (status == 0)
70 status = nfs_post_op_update_inode(inode, res.falloc_fattr);
72 kfree(res.falloc_fattr);
73 return status;
76 static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
77 loff_t offset, loff_t len)
79 struct nfs_server *server = NFS_SERVER(file_inode(filep));
80 struct nfs4_exception exception = { };
81 int err;
83 do {
84 err = _nfs42_proc_fallocate(msg, filep, offset, len);
85 if (err == -ENOTSUPP)
86 return -EOPNOTSUPP;
87 err = nfs4_handle_exception(server, err, &exception);
88 } while (exception.retry);
90 return err;
93 int nfs42_proc_allocate(struct file *filep, loff_t offset, loff_t len)
95 struct rpc_message msg = {
96 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ALLOCATE],
98 struct inode *inode = file_inode(filep);
99 int err;
101 if (!nfs_server_capable(inode, NFS_CAP_ALLOCATE))
102 return -EOPNOTSUPP;
104 mutex_lock(&inode->i_mutex);
106 err = nfs42_proc_fallocate(&msg, filep, offset, len);
107 if (err == -EOPNOTSUPP)
108 NFS_SERVER(inode)->caps &= ~NFS_CAP_ALLOCATE;
110 mutex_unlock(&inode->i_mutex);
111 return err;
114 int nfs42_proc_deallocate(struct file *filep, loff_t offset, loff_t len)
116 struct rpc_message msg = {
117 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DEALLOCATE],
119 struct inode *inode = file_inode(filep);
120 int err;
122 if (!nfs_server_capable(inode, NFS_CAP_DEALLOCATE))
123 return -EOPNOTSUPP;
125 nfs_wb_all(inode);
126 mutex_lock(&inode->i_mutex);
128 err = nfs42_proc_fallocate(&msg, filep, offset, len);
129 if (err == 0)
130 truncate_pagecache_range(inode, offset, (offset + len) -1);
131 if (err == -EOPNOTSUPP)
132 NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE;
134 mutex_unlock(&inode->i_mutex);
135 return err;
138 static loff_t _nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
140 struct inode *inode = file_inode(filep);
141 struct nfs42_seek_args args = {
142 .sa_fh = NFS_FH(inode),
143 .sa_offset = offset,
144 .sa_what = (whence == SEEK_HOLE) ?
145 NFS4_CONTENT_HOLE : NFS4_CONTENT_DATA,
147 struct nfs42_seek_res res;
148 struct rpc_message msg = {
149 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEEK],
150 .rpc_argp = &args,
151 .rpc_resp = &res,
153 struct nfs_server *server = NFS_SERVER(inode);
154 int status;
156 if (!nfs_server_capable(inode, NFS_CAP_SEEK))
157 return -ENOTSUPP;
159 status = nfs42_set_rw_stateid(&args.sa_stateid, filep, FMODE_READ);
160 if (status)
161 return status;
163 nfs_wb_all(inode);
164 status = nfs4_call_sync(server->client, server, &msg,
165 &args.seq_args, &res.seq_res, 0);
166 if (status == -ENOTSUPP)
167 server->caps &= ~NFS_CAP_SEEK;
168 if (status)
169 return status;
171 return vfs_setpos(filep, res.sr_offset, inode->i_sb->s_maxbytes);
174 loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
176 struct nfs_server *server = NFS_SERVER(file_inode(filep));
177 struct nfs4_exception exception = { };
178 int err;
180 do {
181 err = _nfs42_proc_llseek(filep, offset, whence);
182 if (err == -ENOTSUPP)
183 return -EOPNOTSUPP;
184 err = nfs4_handle_exception(server, err, &exception);
185 } while (exception.retry);
187 return err;
191 static void
192 nfs42_layoutstat_prepare(struct rpc_task *task, void *calldata)
194 struct nfs42_layoutstat_data *data = calldata;
195 struct nfs_server *server = NFS_SERVER(data->args.inode);
197 nfs41_setup_sequence(nfs4_get_session(server), &data->args.seq_args,
198 &data->res.seq_res, task);
201 static void
202 nfs42_layoutstat_done(struct rpc_task *task, void *calldata)
204 struct nfs42_layoutstat_data *data = calldata;
206 if (!nfs4_sequence_done(task, &data->res.seq_res))
207 return;
209 switch (task->tk_status) {
210 case 0:
211 break;
212 case -ENOTSUPP:
213 case -EOPNOTSUPP:
214 NFS_SERVER(data->inode)->caps &= ~NFS_CAP_LAYOUTSTATS;
215 default:
216 dprintk("%s server returns %d\n", __func__, task->tk_status);
220 static void
221 nfs42_layoutstat_release(void *calldata)
223 struct nfs42_layoutstat_data *data = calldata;
224 struct nfs_server *nfss = NFS_SERVER(data->args.inode);
226 if (nfss->pnfs_curr_ld->cleanup_layoutstats)
227 nfss->pnfs_curr_ld->cleanup_layoutstats(data);
229 pnfs_put_layout_hdr(NFS_I(data->args.inode)->layout);
230 smp_mb__before_atomic();
231 clear_bit(NFS_INO_LAYOUTSTATS, &NFS_I(data->args.inode)->flags);
232 smp_mb__after_atomic();
233 nfs_iput_and_deactive(data->inode);
234 kfree(data->args.devinfo);
235 kfree(data);
238 static const struct rpc_call_ops nfs42_layoutstat_ops = {
239 .rpc_call_prepare = nfs42_layoutstat_prepare,
240 .rpc_call_done = nfs42_layoutstat_done,
241 .rpc_release = nfs42_layoutstat_release,
244 int nfs42_proc_layoutstats_generic(struct nfs_server *server,
245 struct nfs42_layoutstat_data *data)
247 struct rpc_message msg = {
248 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTSTATS],
249 .rpc_argp = &data->args,
250 .rpc_resp = &data->res,
252 struct rpc_task_setup task_setup = {
253 .rpc_client = server->client,
254 .rpc_message = &msg,
255 .callback_ops = &nfs42_layoutstat_ops,
256 .callback_data = data,
257 .flags = RPC_TASK_ASYNC,
259 struct rpc_task *task;
261 data->inode = nfs_igrab_and_active(data->args.inode);
262 if (!data->inode) {
263 nfs42_layoutstat_release(data);
264 return -EAGAIN;
266 nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
267 task = rpc_run_task(&task_setup);
268 if (IS_ERR(task))
269 return PTR_ERR(task);
270 return 0;