blob: e966f15f92eca964d4d2c53b61689bff37c097b6 [file] [log] [blame]
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -07001/*
2 * linux/fs/9p/vfs_file.c
3 *
4 * This file contians vfs file ops for 9P2000.
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
9 * This program is free software; you can redistribute it and/or modify
Eric Van Hensbergen42e8c502006-03-25 03:07:28 -080010 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070012 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to:
20 * Free Software Foundation
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02111-1301 USA
23 *
24 */
25
26#include <linux/module.h>
27#include <linux/errno.h>
28#include <linux/fs.h>
Al Viro914e2632006-10-18 13:55:46 -040029#include <linux/sched.h>
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070030#include <linux/file.h>
31#include <linux/stat.h>
32#include <linux/string.h>
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070033#include <linux/inet.h>
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070034#include <linux/list.h>
Abhishek Kulkarni637d0202009-09-22 11:34:05 -050035#include <linux/pagemap.h>
M. Mohan Kumara0990272010-09-27 11:34:24 +053036#include <linux/utsname.h>
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070037#include <asm/uaccess.h>
38#include <linux/idr.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050039#include <net/9p/9p.h>
40#include <net/9p/client.h>
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070041
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070042#include "v9fs.h"
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070043#include "v9fs_vfs.h"
44#include "fid.h"
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050045#include "cache.h"
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070046
47/**
48 * v9fs_file_open - open a file (or directory)
49 * @inode: inode to be opened
50 * @file: file being opened
51 *
52 */
53
54int v9fs_file_open(struct inode *inode, struct file *file)
55{
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -080056 int err;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050057 struct v9fs_session_info *v9ses;
58 struct p9_fid *fid;
59 int omode;
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070060
M. Mohan Kumaref565472010-06-22 19:47:50 +053061 P9_DPRINTK(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, file);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050062 v9ses = v9fs_inode2v9ses(inode);
M. Mohan Kumaref565472010-06-22 19:47:50 +053063 if (v9fs_proto_dotl(v9ses))
64 omode = file->f_flags;
65 else
66 omode = v9fs_uflags2omode(file->f_flags,
67 v9fs_proto_dotu(v9ses));
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050068 fid = file->private_data;
69 if (!fid) {
70 fid = v9fs_fid_clone(file->f_path.dentry);
71 if (IS_ERR(fid))
72 return PTR_ERR(fid);
73
74 err = p9_client_open(fid, omode);
Eric Van Hensbergen9523a842007-07-13 13:01:27 -050075 if (err < 0) {
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050076 p9_client_clunk(fid);
77 return err;
78 }
M. Mohan Kumaref565472010-06-22 19:47:50 +053079 if (file->f_flags & O_TRUNC) {
Abhishek Kulkarni7549ae32009-09-22 11:34:05 -050080 i_size_write(inode, 0);
Eric Van Hensbergen9523a842007-07-13 13:01:27 -050081 inode->i_blocks = 0;
82 }
M. Mohan Kumaref565472010-06-22 19:47:50 +053083 if ((file->f_flags & O_APPEND) &&
84 (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)))
Eric Van Hensbergen2e4bef42008-06-24 17:39:39 -050085 generic_file_llseek(file, 0, SEEK_END);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -080086 }
87
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050088 file->private_data = fid;
Aneesh Kumar K.V3cf387d2011-02-28 17:03:57 +053089 if (v9ses->cache && !inode->i_private) {
90 /*
91 * clone a fid and add it to inode->i_private
92 * we do it during open time instead of
93 * page dirty time via write_begin/page_mkwrite
94 * because we want write after unlink usecase
95 * to work.
96 */
97 fid = v9fs_writeback_fid(file->f_path.dentry);
98 if (IS_ERR(fid)) {
99 err = PTR_ERR(fid);
100 goto out_error;
101 }
102 inode->i_private = (void *) fid;
103 }
Aneesh Kumar K.V29236f42011-02-28 17:03:54 +0530104#ifdef CONFIG_9P_FSCACHE
Aneesh Kumar K.V46848de2011-02-28 17:03:55 +0530105 if (v9ses->cache)
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500106 v9fs_cache_inode_set_cookie(inode, file);
Aneesh Kumar K.V29236f42011-02-28 17:03:54 +0530107#endif
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700108 return 0;
Aneesh Kumar K.V3cf387d2011-02-28 17:03:57 +0530109out_error:
110 p9_client_clunk(file->private_data);
111 file->private_data = NULL;
112 return err;
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700113}
114
115/**
116 * v9fs_file_lock - lock a file (or directory)
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600117 * @filp: file to be locked
118 * @cmd: lock command
119 * @fl: file lock structure
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700120 *
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600121 * Bugs: this looks like a local only lock, we should extend into 9P
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700122 * by using open exclusive
123 */
124
125static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
126{
127 int res = 0;
Josef "Jeff" Sipekd6f787b2006-12-08 02:36:45 -0800128 struct inode *inode = filp->f_path.dentry->d_inode;
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700129
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500130 P9_DPRINTK(P9_DEBUG_VFS, "filp: %p lock: %p\n", filp, fl);
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700131
132 /* No mandatory locks */
Sachin Prabhuf78233d2010-03-13 09:03:55 -0600133 if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700134 return -ENOLCK;
135
136 if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
OGAWA Hirofumi28fd1292006-01-08 01:02:14 -0800137 filemap_write_and_wait(inode->i_mapping);
Andrew Mortonfc0ecff2007-02-10 01:45:39 -0800138 invalidate_mapping_pages(&inode->i_data, 0, -1);
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700139 }
140
141 return res;
142}
143
M. Mohan Kumara0990272010-09-27 11:34:24 +0530144static int v9fs_file_do_lock(struct file *filp, int cmd, struct file_lock *fl)
145{
146 struct p9_flock flock;
147 struct p9_fid *fid;
148 uint8_t status;
149 int res = 0;
150 unsigned char fl_type;
151
152 fid = filp->private_data;
153 BUG_ON(fid == NULL);
154
155 if ((fl->fl_flags & FL_POSIX) != FL_POSIX)
156 BUG();
157
158 res = posix_lock_file_wait(filp, fl);
159 if (res < 0)
160 goto out;
161
162 /* convert posix lock to p9 tlock args */
163 memset(&flock, 0, sizeof(flock));
164 flock.type = fl->fl_type;
165 flock.start = fl->fl_start;
166 if (fl->fl_end == OFFSET_MAX)
167 flock.length = 0;
168 else
169 flock.length = fl->fl_end - fl->fl_start + 1;
170 flock.proc_id = fl->fl_pid;
171 flock.client_id = utsname()->nodename;
172 if (IS_SETLKW(cmd))
173 flock.flags = P9_LOCK_FLAGS_BLOCK;
174
175 /*
176 * if its a blocked request and we get P9_LOCK_BLOCKED as the status
177 * for lock request, keep on trying
178 */
179 for (;;) {
180 res = p9_client_lock_dotl(fid, &flock, &status);
181 if (res < 0)
182 break;
183
184 if (status != P9_LOCK_BLOCKED)
185 break;
186 if (status == P9_LOCK_BLOCKED && !IS_SETLKW(cmd))
187 break;
188 schedule_timeout_interruptible(P9_LOCK_TIMEOUT);
189 }
190
191 /* map 9p status to VFS status */
192 switch (status) {
193 case P9_LOCK_SUCCESS:
194 res = 0;
195 break;
196 case P9_LOCK_BLOCKED:
197 res = -EAGAIN;
198 break;
199 case P9_LOCK_ERROR:
200 case P9_LOCK_GRACE:
201 res = -ENOLCK;
202 break;
203 default:
204 BUG();
205 }
206
207 /*
208 * incase server returned error for lock request, revert
209 * it locally
210 */
211 if (res < 0 && fl->fl_type != F_UNLCK) {
212 fl_type = fl->fl_type;
213 fl->fl_type = F_UNLCK;
214 res = posix_lock_file_wait(filp, fl);
215 fl->fl_type = fl_type;
216 }
217out:
218 return res;
219}
220
M. Mohan Kumar1d769cd2010-09-27 12:22:13 +0530221static int v9fs_file_getlock(struct file *filp, struct file_lock *fl)
222{
223 struct p9_getlock glock;
224 struct p9_fid *fid;
225 int res = 0;
226
227 fid = filp->private_data;
228 BUG_ON(fid == NULL);
229
230 posix_test_lock(filp, fl);
231 /*
232 * if we have a conflicting lock locally, no need to validate
233 * with server
234 */
235 if (fl->fl_type != F_UNLCK)
236 return res;
237
238 /* convert posix lock to p9 tgetlock args */
239 memset(&glock, 0, sizeof(glock));
240 glock.type = fl->fl_type;
241 glock.start = fl->fl_start;
242 if (fl->fl_end == OFFSET_MAX)
243 glock.length = 0;
244 else
245 glock.length = fl->fl_end - fl->fl_start + 1;
246 glock.proc_id = fl->fl_pid;
247 glock.client_id = utsname()->nodename;
248
249 res = p9_client_getlock_dotl(fid, &glock);
250 if (res < 0)
251 return res;
252 if (glock.type != F_UNLCK) {
253 fl->fl_type = glock.type;
254 fl->fl_start = glock.start;
255 if (glock.length == 0)
256 fl->fl_end = OFFSET_MAX;
257 else
258 fl->fl_end = glock.start + glock.length - 1;
259 fl->fl_pid = glock.proc_id;
260 } else
261 fl->fl_type = F_UNLCK;
262
263 return res;
264}
265
M. Mohan Kumara0990272010-09-27 11:34:24 +0530266/**
267 * v9fs_file_lock_dotl - lock a file (or directory)
268 * @filp: file to be locked
269 * @cmd: lock command
270 * @fl: file lock structure
271 *
272 */
273
274static int v9fs_file_lock_dotl(struct file *filp, int cmd, struct file_lock *fl)
275{
276 struct inode *inode = filp->f_path.dentry->d_inode;
277 int ret = -ENOLCK;
278
279 P9_DPRINTK(P9_DEBUG_VFS, "filp: %p cmd:%d lock: %p name: %s\n", filp,
280 cmd, fl, filp->f_path.dentry->d_name.name);
281
282 /* No mandatory locks */
283 if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
284 goto out_err;
285
286 if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
287 filemap_write_and_wait(inode->i_mapping);
288 invalidate_mapping_pages(&inode->i_data, 0, -1);
289 }
290
291 if (IS_SETLK(cmd) || IS_SETLKW(cmd))
292 ret = v9fs_file_do_lock(filp, cmd, fl);
M. Mohan Kumar1d769cd2010-09-27 12:22:13 +0530293 else if (IS_GETLK(cmd))
294 ret = v9fs_file_getlock(filp, fl);
M. Mohan Kumara0990272010-09-27 11:34:24 +0530295 else
296 ret = -EINVAL;
297out_err:
298 return ret;
299}
300
301/**
302 * v9fs_file_flock_dotl - lock a file
303 * @filp: file to be locked
304 * @cmd: lock command
305 * @fl: file lock structure
306 *
307 */
308
309static int v9fs_file_flock_dotl(struct file *filp, int cmd,
310 struct file_lock *fl)
311{
312 struct inode *inode = filp->f_path.dentry->d_inode;
313 int ret = -ENOLCK;
314
315 P9_DPRINTK(P9_DEBUG_VFS, "filp: %p cmd:%d lock: %p name: %s\n", filp,
316 cmd, fl, filp->f_path.dentry->d_name.name);
317
318 /* No mandatory locks */
319 if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
320 goto out_err;
321
322 if (!(fl->fl_flags & FL_FLOCK))
323 goto out_err;
324
325 if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
326 filemap_write_and_wait(inode->i_mapping);
327 invalidate_mapping_pages(&inode->i_data, 0, -1);
328 }
329 /* Convert flock to posix lock */
330 fl->fl_owner = (fl_owner_t)filp;
331 fl->fl_start = 0;
332 fl->fl_end = OFFSET_MAX;
333 fl->fl_flags |= FL_POSIX;
334 fl->fl_flags ^= FL_FLOCK;
335
336 if (IS_SETLK(cmd) | IS_SETLKW(cmd))
337 ret = v9fs_file_do_lock(filp, cmd, fl);
338 else
339 ret = -EINVAL;
340out_err:
341 return ret;
342}
343
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700344/**
Aneesh Kumar K.V17311772011-02-28 17:03:56 +0530345 * v9fs_fid_readn - read from a fid
346 * @fid: fid to read
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700347 * @data: data buffer to read data into
Eric Van Hensbergenfbedadc2008-10-13 20:36:16 -0500348 * @udata: user data buffer to read data into
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700349 * @count: size of buffer
350 * @offset: offset at which to read data
351 *
352 */
Eric Van Hensbergenfbedadc2008-10-13 20:36:16 -0500353ssize_t
Aneesh Kumar K.V17311772011-02-28 17:03:56 +0530354v9fs_fid_readn(struct p9_fid *fid, char *data, char __user *udata, u32 count,
Eric Van Hensbergenfbedadc2008-10-13 20:36:16 -0500355 u64 offset)
356{
M. Mohan Kumar97e84422010-06-04 11:59:07 +0000357 int n, total, size;
Eric Van Hensbergenfbedadc2008-10-13 20:36:16 -0500358
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500359 P9_DPRINTK(P9_DEBUG_VFS, "fid %d offset %llu count %d\n", fid->fid,
Aneesh Kumar K.V17311772011-02-28 17:03:56 +0530360 (long long unsigned) offset, count);
Eric Van Hensbergenfbedadc2008-10-13 20:36:16 -0500361 n = 0;
362 total = 0;
M. Mohan Kumar97e84422010-06-04 11:59:07 +0000363 size = fid->iounit ? fid->iounit : fid->clnt->msize - P9_IOHDRSZ;
Eric Van Hensbergenfbedadc2008-10-13 20:36:16 -0500364 do {
365 n = p9_client_read(fid, data, udata, offset, count);
366 if (n <= 0)
367 break;
368
369 if (data)
370 data += n;
371 if (udata)
372 udata += n;
373
374 offset += n;
375 count -= n;
376 total += n;
M. Mohan Kumar97e84422010-06-04 11:59:07 +0000377 } while (count > 0 && n == size);
Eric Van Hensbergenfbedadc2008-10-13 20:36:16 -0500378
379 if (n < 0)
380 total = n;
381
382 return total;
383}
384
385/**
Aneesh Kumar K.V17311772011-02-28 17:03:56 +0530386 * v9fs_file_readn - read from a file
387 * @filp: file pointer to read
388 * @data: data buffer to read data into
389 * @udata: user data buffer to read data into
390 * @count: size of buffer
391 * @offset: offset at which to read data
392 *
393 */
394ssize_t
395v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count,
396 u64 offset)
397{
398 return v9fs_fid_readn(filp->private_data, data, udata, count, offset);
399}
400
401/**
Eric Van Hensbergenfbedadc2008-10-13 20:36:16 -0500402 * v9fs_file_read - read from a file
403 * @filp: file pointer to read
404 * @udata: user data buffer to read data into
405 * @count: size of buffer
406 * @offset: offset at which to read data
407 *
408 */
409
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700410static ssize_t
Eric Van Hensbergenfbedadc2008-10-13 20:36:16 -0500411v9fs_file_read(struct file *filp, char __user *udata, size_t count,
Latchesar Ionkov19cba8a2005-10-11 08:29:03 -0700412 loff_t * offset)
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700413{
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500414 int ret;
415 struct p9_fid *fid;
M. Mohan Kumar97e84422010-06-04 11:59:07 +0000416 size_t size;
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700417
Eric Van Hensbergenea2e7992008-10-22 18:48:45 -0500418 P9_DPRINTK(P9_DEBUG_VFS, "count %zu offset %lld\n", count, *offset);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500419 fid = filp->private_data;
Eric Van Hensbergenfbedadc2008-10-13 20:36:16 -0500420
M. Mohan Kumar97e84422010-06-04 11:59:07 +0000421 size = fid->iounit ? fid->iounit : fid->clnt->msize - P9_IOHDRSZ;
422 if (count > size)
Eric Van Hensbergenfbedadc2008-10-13 20:36:16 -0500423 ret = v9fs_file_readn(filp, NULL, udata, count, *offset);
424 else
425 ret = p9_client_read(fid, NULL, udata, *offset, count);
426
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500427 if (ret > 0)
428 *offset += ret;
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700429
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500430 return ret;
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700431}
432
Aneesh Kumar K.V17311772011-02-28 17:03:56 +0530433ssize_t
434v9fs_file_write_internal(struct inode *inode, struct p9_fid *fid,
435 const char __user *data, size_t count,
436 loff_t *offset, int invalidate)
437{
438 int n;
439 size_t total = 0;
440 struct p9_client *clnt;
441 loff_t origin = *offset;
442 unsigned long pg_start, pg_end;
443
444 P9_DPRINTK(P9_DEBUG_VFS, "data %p count %d offset %x\n", data,
445 (int)count, (int)*offset);
446
447 clnt = fid->clnt;
448 do {
449 n = p9_client_write(fid, NULL, data+total, origin+total, count);
450 if (n <= 0)
451 break;
452 count -= n;
453 total += n;
454 } while (count > 0);
455
456 if (invalidate && (total > 0)) {
457 pg_start = origin >> PAGE_CACHE_SHIFT;
458 pg_end = (origin + total - 1) >> PAGE_CACHE_SHIFT;
459 if (inode->i_mapping && inode->i_mapping->nrpages)
460 invalidate_inode_pages2_range(inode->i_mapping,
461 pg_start, pg_end);
462 *offset += total;
463 i_size_write(inode, i_size_read(inode) + total);
464 inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
465 }
466 if (n < 0)
467 return n;
468
469 return total;
470}
471
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700472/**
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700473 * v9fs_file_write - write to a file
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600474 * @filp: file pointer to write
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700475 * @data: data buffer to write data from
476 * @count: size of buffer
477 * @offset: offset at which to write data
478 *
479 */
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700480static ssize_t
481v9fs_file_write(struct file *filp, const char __user * data,
Aneesh Kumar K.V17311772011-02-28 17:03:56 +0530482 size_t count, loff_t *offset)
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700483{
Aneesh Kumar K.V17311772011-02-28 17:03:56 +0530484 ssize_t retval = 0;
jvraofc0f2962010-03-08 22:07:02 +0000485 loff_t origin = *offset;
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700486
Eric Van Hensbergendfb0ec22008-10-13 20:36:16 -0500487
Harsh Prateek Bora3834b122010-08-03 11:55:40 +0000488 retval = generic_write_checks(filp, &origin, &count, 0);
489 if (retval)
490 goto out;
491
492 retval = -EINVAL;
493 if ((ssize_t) count < 0)
494 goto out;
495 retval = 0;
496 if (!count)
497 goto out;
498
Aneesh Kumar K.V17311772011-02-28 17:03:56 +0530499 return v9fs_file_write_internal(filp->f_path.dentry->d_inode,
500 filp->private_data,
501 data, count, offset, 1);
Harsh Prateek Bora3834b122010-08-03 11:55:40 +0000502out:
503 return retval;
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700504}
505
Christoph Hellwig7ea80852010-05-26 17:53:25 +0200506static int v9fs_file_fsync(struct file *filp, int datasync)
M. Mohan Kumar7a4439c2010-02-08 15:36:48 -0600507{
508 struct p9_fid *fid;
509 struct p9_wstat wstat;
510 int retval;
511
Christoph Hellwig7ea80852010-05-26 17:53:25 +0200512 P9_DPRINTK(P9_DEBUG_VFS, "filp %p datasync %x\n", filp, datasync);
M. Mohan Kumar7a4439c2010-02-08 15:36:48 -0600513
514 fid = filp->private_data;
515 v9fs_blank_wstat(&wstat);
516
517 retval = p9_client_wstat(fid, &wstat);
518 return retval;
519}
520
Venkateswararao Jujjuri (JV)b165d602010-10-22 10:13:12 -0700521int v9fs_file_fsync_dotl(struct file *filp, int datasync)
Venkateswararao Jujjuri (JV)920e65d2010-09-22 17:19:19 -0700522{
523 struct p9_fid *fid;
524 int retval;
525
526 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_file_fsync_dotl: filp %p datasync %x\n",
527 filp, datasync);
528
529 fid = filp->private_data;
530
Venkateswararao Jujjuri (JV)b165d602010-10-22 10:13:12 -0700531 retval = p9_client_fsync(fid, datasync);
Venkateswararao Jujjuri (JV)920e65d2010-09-22 17:19:19 -0700532 return retval;
533}
534
Aneesh Kumar K.V29236f42011-02-28 17:03:54 +0530535const struct file_operations v9fs_cached_file_operations = {
Eric Van Hensbergene03abc02007-02-11 13:21:39 -0600536 .llseek = generic_file_llseek,
537 .read = do_sync_read,
538 .aio_read = generic_file_aio_read,
539 .write = v9fs_file_write,
540 .open = v9fs_file_open,
541 .release = v9fs_dir_release,
542 .lock = v9fs_file_lock,
Eric Van Hensbergen14b88692008-02-06 19:25:05 -0600543 .mmap = generic_file_readonly_mmap,
M. Mohan Kumar7a4439c2010-02-08 15:36:48 -0600544 .fsync = v9fs_file_fsync,
Eric Van Hensbergene03abc02007-02-11 13:21:39 -0600545};
546
Aneesh Kumar K.V29236f42011-02-28 17:03:54 +0530547const struct file_operations v9fs_cached_file_operations_dotl = {
Venkateswararao Jujjuri (JV)b04faaf2010-09-22 16:30:52 -0700548 .llseek = generic_file_llseek,
549 .read = do_sync_read,
550 .aio_read = generic_file_aio_read,
551 .write = v9fs_file_write,
552 .open = v9fs_file_open,
553 .release = v9fs_dir_release,
M. Mohan Kumara0990272010-09-27 11:34:24 +0530554 .lock = v9fs_file_lock_dotl,
555 .flock = v9fs_file_flock_dotl,
Venkateswararao Jujjuri (JV)b04faaf2010-09-22 16:30:52 -0700556 .mmap = generic_file_readonly_mmap,
Venkateswararao Jujjuri (JV)920e65d2010-09-22 17:19:19 -0700557 .fsync = v9fs_file_fsync_dotl,
Venkateswararao Jujjuri (JV)b04faaf2010-09-22 16:30:52 -0700558};
559
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800560const struct file_operations v9fs_file_operations = {
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700561 .llseek = generic_file_llseek,
562 .read = v9fs_file_read,
563 .write = v9fs_file_write,
564 .open = v9fs_file_open,
565 .release = v9fs_dir_release,
566 .lock = v9fs_file_lock,
Eric Van Hensbergen14b88692008-02-06 19:25:05 -0600567 .mmap = generic_file_readonly_mmap,
M. Mohan Kumar7a4439c2010-02-08 15:36:48 -0600568 .fsync = v9fs_file_fsync,
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700569};
Sripathi Kodi9b6533c2010-03-25 12:41:54 +0000570
571const struct file_operations v9fs_file_operations_dotl = {
572 .llseek = generic_file_llseek,
573 .read = v9fs_file_read,
574 .write = v9fs_file_write,
575 .open = v9fs_file_open,
576 .release = v9fs_dir_release,
M. Mohan Kumara0990272010-09-27 11:34:24 +0530577 .lock = v9fs_file_lock_dotl,
578 .flock = v9fs_file_flock_dotl,
Sripathi Kodi9b6533c2010-03-25 12:41:54 +0000579 .mmap = generic_file_readonly_mmap,
Venkateswararao Jujjuri (JV)920e65d2010-09-22 17:19:19 -0700580 .fsync = v9fs_file_fsync_dotl,
Sripathi Kodi9b6533c2010-03-25 12:41:54 +0000581};