aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/gfs2/file.c')
-rw-r--r--fs/gfs2/file.c94
1 files changed, 55 insertions, 39 deletions
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
index ad0dc38d87ab..72c3866a7320 100644
--- a/fs/gfs2/file.c
+++ b/fs/gfs2/file.c
@@ -82,35 +82,28 @@ static loff_t gfs2_llseek(struct file *file, loff_t offset, int whence)
82} 82}
83 83
84/** 84/**
85 * gfs2_readdir - Read directory entries from a directory 85 * gfs2_readdir - Iterator for a directory
86 * @file: The directory to read from 86 * @file: The directory to read from
87 * @dirent: Buffer for dirents 87 * @ctx: What to feed directory entries to
88 * @filldir: Function used to do the copying
89 * 88 *
90 * Returns: errno 89 * Returns: errno
91 */ 90 */
92 91
93static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) 92static int gfs2_readdir(struct file *file, struct dir_context *ctx)
94{ 93{
95 struct inode *dir = file->f_mapping->host; 94 struct inode *dir = file->f_mapping->host;
96 struct gfs2_inode *dip = GFS2_I(dir); 95 struct gfs2_inode *dip = GFS2_I(dir);
97 struct gfs2_holder d_gh; 96 struct gfs2_holder d_gh;
98 u64 offset = file->f_pos;
99 int error; 97 int error;
100 98
101 gfs2_holder_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); 99 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
102 error = gfs2_glock_nq(&d_gh); 100 if (error)
103 if (error) {
104 gfs2_holder_uninit(&d_gh);
105 return error; 101 return error;
106 }
107 102
108 error = gfs2_dir_read(dir, &offset, dirent, filldir, &file->f_ra); 103 error = gfs2_dir_read(dir, ctx, &file->f_ra);
109 104
110 gfs2_glock_dq_uninit(&d_gh); 105 gfs2_glock_dq_uninit(&d_gh);
111 106
112 file->f_pos = offset;
113
114 return error; 107 return error;
115} 108}
116 109
@@ -538,21 +531,30 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
538} 531}
539 532
540/** 533/**
541 * gfs2_open - open a file 534 * gfs2_open_common - This is common to open and atomic_open
542 * @inode: the inode to open 535 * @inode: The inode being opened
543 * @file: the struct file for this opening 536 * @file: The file being opened
544 * 537 *
545 * Returns: errno 538 * This maybe called under a glock or not depending upon how it has
539 * been called. We must always be called under a glock for regular
540 * files, however. For other file types, it does not matter whether
541 * we hold the glock or not.
542 *
543 * Returns: Error code or 0 for success
546 */ 544 */
547 545
548static int gfs2_open(struct inode *inode, struct file *file) 546int gfs2_open_common(struct inode *inode, struct file *file)
549{ 547{
550 struct gfs2_inode *ip = GFS2_I(inode);
551 struct gfs2_holder i_gh;
552 struct gfs2_file *fp; 548 struct gfs2_file *fp;
553 int error; 549 int ret;
550
551 if (S_ISREG(inode->i_mode)) {
552 ret = generic_file_open(inode, file);
553 if (ret)
554 return ret;
555 }
554 556
555 fp = kzalloc(sizeof(struct gfs2_file), GFP_KERNEL); 557 fp = kzalloc(sizeof(struct gfs2_file), GFP_NOFS);
556 if (!fp) 558 if (!fp)
557 return -ENOMEM; 559 return -ENOMEM;
558 560
@@ -560,29 +562,43 @@ static int gfs2_open(struct inode *inode, struct file *file)
560 562
561 gfs2_assert_warn(GFS2_SB(inode), !file->private_data); 563 gfs2_assert_warn(GFS2_SB(inode), !file->private_data);
562 file->private_data = fp; 564 file->private_data = fp;
565 return 0;
566}
567
568/**
569 * gfs2_open - open a file
570 * @inode: the inode to open
571 * @file: the struct file for this opening
572 *
573 * After atomic_open, this function is only used for opening files
574 * which are already cached. We must still get the glock for regular
575 * files to ensure that we have the file size uptodate for the large
576 * file check which is in the common code. That is only an issue for
577 * regular files though.
578 *
579 * Returns: errno
580 */
581
582static int gfs2_open(struct inode *inode, struct file *file)
583{
584 struct gfs2_inode *ip = GFS2_I(inode);
585 struct gfs2_holder i_gh;
586 int error;
587 bool need_unlock = false;
563 588
564 if (S_ISREG(ip->i_inode.i_mode)) { 589 if (S_ISREG(ip->i_inode.i_mode)) {
565 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, 590 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY,
566 &i_gh); 591 &i_gh);
567 if (error) 592 if (error)
568 goto fail; 593 return error;
594 need_unlock = true;
595 }
569 596
570 if (!(file->f_flags & O_LARGEFILE) && 597 error = gfs2_open_common(inode, file);
571 i_size_read(inode) > MAX_NON_LFS) {
572 error = -EOVERFLOW;
573 goto fail_gunlock;
574 }
575 598
599 if (need_unlock)
576 gfs2_glock_dq_uninit(&i_gh); 600 gfs2_glock_dq_uninit(&i_gh);
577 }
578 601
579 return 0;
580
581fail_gunlock:
582 gfs2_glock_dq_uninit(&i_gh);
583fail:
584 file->private_data = NULL;
585 kfree(fp);
586 return error; 602 return error;
587} 603}
588 604
@@ -896,7 +912,7 @@ out_uninit:
896 * cluster; until we do, disable leases (by just returning -EINVAL), 912 * cluster; until we do, disable leases (by just returning -EINVAL),
897 * unless the administrator has requested purely local locking. 913 * unless the administrator has requested purely local locking.
898 * 914 *
899 * Locking: called under lock_flocks 915 * Locking: called under i_lock
900 * 916 *
901 * Returns: errno 917 * Returns: errno
902 */ 918 */
@@ -1048,7 +1064,7 @@ const struct file_operations gfs2_file_fops = {
1048}; 1064};
1049 1065
1050const struct file_operations gfs2_dir_fops = { 1066const struct file_operations gfs2_dir_fops = {
1051 .readdir = gfs2_readdir, 1067 .iterate = gfs2_readdir,
1052 .unlocked_ioctl = gfs2_ioctl, 1068 .unlocked_ioctl = gfs2_ioctl,
1053 .open = gfs2_open, 1069 .open = gfs2_open,
1054 .release = gfs2_release, 1070 .release = gfs2_release,
@@ -1078,7 +1094,7 @@ const struct file_operations gfs2_file_fops_nolock = {
1078}; 1094};
1079 1095
1080const struct file_operations gfs2_dir_fops_nolock = { 1096const struct file_operations gfs2_dir_fops_nolock = {
1081 .readdir = gfs2_readdir, 1097 .iterate = gfs2_readdir,
1082 .unlocked_ioctl = gfs2_ioctl, 1098 .unlocked_ioctl = gfs2_ioctl,
1083 .open = gfs2_open, 1099 .open = gfs2_open,
1084 .release = gfs2_release, 1100 .release = gfs2_release,