diff options
author | Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | 2011-02-28 06:33:56 -0500 |
---|---|---|
committer | Eric Van Hensbergen <ericvh@gmail.com> | 2011-03-15 10:57:37 -0400 |
commit | 17311779ac3dcd06f8ef727a06969c439e116a20 (patch) | |
tree | 7c8860d8f2b023223a7280b5a11e48ce935b5436 /fs/9p | |
parent | 2efda7998bbc50589d28f18fddfb0c44d412128e (diff) |
fs/9p: Add read write helper function
We add read write helper function here which will
be used later by the mmap patch
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
Diffstat (limited to 'fs/9p')
-rw-r--r-- | fs/9p/v9fs_vfs.h | 4 | ||||
-rw-r--r-- | fs/9p/vfs_file.c | 102 |
2 files changed, 64 insertions, 42 deletions
diff --git a/fs/9p/v9fs_vfs.h b/fs/9p/v9fs_vfs.h index e4d5540cbb70..c44aaa8bd2a3 100644 --- a/fs/9p/v9fs_vfs.h +++ b/fs/9p/v9fs_vfs.h | |||
@@ -64,8 +64,10 @@ void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat); | |||
64 | int v9fs_uflags2omode(int uflags, int extended); | 64 | int v9fs_uflags2omode(int uflags, int extended); |
65 | 65 | ||
66 | ssize_t v9fs_file_readn(struct file *, char *, char __user *, u32, u64); | 66 | ssize_t v9fs_file_readn(struct file *, char *, char __user *, u32, u64); |
67 | ssize_t v9fs_fid_readn(struct p9_fid *, char *, char __user *, u32, u64); | ||
67 | void v9fs_blank_wstat(struct p9_wstat *wstat); | 68 | void v9fs_blank_wstat(struct p9_wstat *wstat); |
68 | int v9fs_vfs_setattr_dotl(struct dentry *, struct iattr *); | 69 | int v9fs_vfs_setattr_dotl(struct dentry *, struct iattr *); |
69 | int v9fs_file_fsync_dotl(struct file *filp, int datasync); | 70 | int v9fs_file_fsync_dotl(struct file *filp, int datasync); |
70 | 71 | ssize_t v9fs_file_write_internal(struct inode *, struct p9_fid *, | |
72 | const char __user *, size_t, loff_t *, int); | ||
71 | #define P9_LOCK_TIMEOUT (30*HZ) | 73 | #define P9_LOCK_TIMEOUT (30*HZ) |
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index ce1eae48a127..6e1e8f43edac 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c | |||
@@ -323,25 +323,22 @@ out_err: | |||
323 | } | 323 | } |
324 | 324 | ||
325 | /** | 325 | /** |
326 | * v9fs_file_readn - read from a file | 326 | * v9fs_fid_readn - read from a fid |
327 | * @filp: file pointer to read | 327 | * @fid: fid to read |
328 | * @data: data buffer to read data into | 328 | * @data: data buffer to read data into |
329 | * @udata: user data buffer to read data into | 329 | * @udata: user data buffer to read data into |
330 | * @count: size of buffer | 330 | * @count: size of buffer |
331 | * @offset: offset at which to read data | 331 | * @offset: offset at which to read data |
332 | * | 332 | * |
333 | */ | 333 | */ |
334 | |||
335 | ssize_t | 334 | ssize_t |
336 | v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count, | 335 | v9fs_fid_readn(struct p9_fid *fid, char *data, char __user *udata, u32 count, |
337 | u64 offset) | 336 | u64 offset) |
338 | { | 337 | { |
339 | int n, total, size; | 338 | int n, total, size; |
340 | struct p9_fid *fid = filp->private_data; | ||
341 | 339 | ||
342 | P9_DPRINTK(P9_DEBUG_VFS, "fid %d offset %llu count %d\n", fid->fid, | 340 | P9_DPRINTK(P9_DEBUG_VFS, "fid %d offset %llu count %d\n", fid->fid, |
343 | (long long unsigned) offset, count); | 341 | (long long unsigned) offset, count); |
344 | |||
345 | n = 0; | 342 | n = 0; |
346 | total = 0; | 343 | total = 0; |
347 | size = fid->iounit ? fid->iounit : fid->clnt->msize - P9_IOHDRSZ; | 344 | size = fid->iounit ? fid->iounit : fid->clnt->msize - P9_IOHDRSZ; |
@@ -367,6 +364,22 @@ v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count, | |||
367 | } | 364 | } |
368 | 365 | ||
369 | /** | 366 | /** |
367 | * v9fs_file_readn - read from a file | ||
368 | * @filp: file pointer to read | ||
369 | * @data: data buffer to read data into | ||
370 | * @udata: user data buffer to read data into | ||
371 | * @count: size of buffer | ||
372 | * @offset: offset at which to read data | ||
373 | * | ||
374 | */ | ||
375 | ssize_t | ||
376 | v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count, | ||
377 | u64 offset) | ||
378 | { | ||
379 | return v9fs_fid_readn(filp->private_data, data, udata, count, offset); | ||
380 | } | ||
381 | |||
382 | /** | ||
370 | * v9fs_file_read - read from a file | 383 | * v9fs_file_read - read from a file |
371 | * @filp: file pointer to read | 384 | * @filp: file pointer to read |
372 | * @udata: user data buffer to read data into | 385 | * @udata: user data buffer to read data into |
@@ -398,45 +411,21 @@ v9fs_file_read(struct file *filp, char __user *udata, size_t count, | |||
398 | return ret; | 411 | return ret; |
399 | } | 412 | } |
400 | 413 | ||
401 | /** | 414 | ssize_t |
402 | * v9fs_file_write - write to a file | 415 | v9fs_file_write_internal(struct inode *inode, struct p9_fid *fid, |
403 | * @filp: file pointer to write | 416 | const char __user *data, size_t count, |
404 | * @data: data buffer to write data from | 417 | loff_t *offset, int invalidate) |
405 | * @count: size of buffer | ||
406 | * @offset: offset at which to write data | ||
407 | * | ||
408 | */ | ||
409 | |||
410 | static ssize_t | ||
411 | v9fs_file_write(struct file *filp, const char __user * data, | ||
412 | size_t count, loff_t * offset) | ||
413 | { | 418 | { |
414 | ssize_t retval; | ||
415 | size_t total = 0; | ||
416 | int n; | 419 | int n; |
417 | struct p9_fid *fid; | 420 | size_t total = 0; |
418 | struct p9_client *clnt; | 421 | struct p9_client *clnt; |
419 | struct inode *inode = filp->f_path.dentry->d_inode; | ||
420 | loff_t origin = *offset; | 422 | loff_t origin = *offset; |
421 | unsigned long pg_start, pg_end; | 423 | unsigned long pg_start, pg_end; |
422 | 424 | ||
423 | P9_DPRINTK(P9_DEBUG_VFS, "data %p count %d offset %x\n", data, | 425 | P9_DPRINTK(P9_DEBUG_VFS, "data %p count %d offset %x\n", data, |
424 | (int)count, (int)*offset); | 426 | (int)count, (int)*offset); |
425 | 427 | ||
426 | fid = filp->private_data; | ||
427 | clnt = fid->clnt; | 428 | clnt = fid->clnt; |
428 | |||
429 | retval = generic_write_checks(filp, &origin, &count, 0); | ||
430 | if (retval) | ||
431 | goto out; | ||
432 | |||
433 | retval = -EINVAL; | ||
434 | if ((ssize_t) count < 0) | ||
435 | goto out; | ||
436 | retval = 0; | ||
437 | if (!count) | ||
438 | goto out; | ||
439 | |||
440 | do { | 429 | do { |
441 | n = p9_client_write(fid, NULL, data+total, origin+total, count); | 430 | n = p9_client_write(fid, NULL, data+total, origin+total, count); |
442 | if (n <= 0) | 431 | if (n <= 0) |
@@ -445,7 +434,7 @@ v9fs_file_write(struct file *filp, const char __user * data, | |||
445 | total += n; | 434 | total += n; |
446 | } while (count > 0); | 435 | } while (count > 0); |
447 | 436 | ||
448 | if (total > 0) { | 437 | if (invalidate && (total > 0)) { |
449 | pg_start = origin >> PAGE_CACHE_SHIFT; | 438 | pg_start = origin >> PAGE_CACHE_SHIFT; |
450 | pg_end = (origin + total - 1) >> PAGE_CACHE_SHIFT; | 439 | pg_end = (origin + total - 1) >> PAGE_CACHE_SHIFT; |
451 | if (inode->i_mapping && inode->i_mapping->nrpages) | 440 | if (inode->i_mapping && inode->i_mapping->nrpages) |
@@ -455,11 +444,42 @@ v9fs_file_write(struct file *filp, const char __user * data, | |||
455 | i_size_write(inode, i_size_read(inode) + total); | 444 | i_size_write(inode, i_size_read(inode) + total); |
456 | inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9; | 445 | inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9; |
457 | } | 446 | } |
458 | |||
459 | if (n < 0) | 447 | if (n < 0) |
460 | retval = n; | 448 | return n; |
461 | else | 449 | |
462 | retval = total; | 450 | return total; |
451 | } | ||
452 | |||
453 | /** | ||
454 | * v9fs_file_write - write to a file | ||
455 | * @filp: file pointer to write | ||
456 | * @data: data buffer to write data from | ||
457 | * @count: size of buffer | ||
458 | * @offset: offset at which to write data | ||
459 | * | ||
460 | */ | ||
461 | static ssize_t | ||
462 | v9fs_file_write(struct file *filp, const char __user * data, | ||
463 | size_t count, loff_t *offset) | ||
464 | { | ||
465 | ssize_t retval = 0; | ||
466 | loff_t origin = *offset; | ||
467 | |||
468 | |||
469 | retval = generic_write_checks(filp, &origin, &count, 0); | ||
470 | if (retval) | ||
471 | goto out; | ||
472 | |||
473 | retval = -EINVAL; | ||
474 | if ((ssize_t) count < 0) | ||
475 | goto out; | ||
476 | retval = 0; | ||
477 | if (!count) | ||
478 | goto out; | ||
479 | |||
480 | return v9fs_file_write_internal(filp->f_path.dentry->d_inode, | ||
481 | filp->private_data, | ||
482 | data, count, offset, 1); | ||
463 | out: | 483 | out: |
464 | return retval; | 484 | return retval; |
465 | } | 485 | } |