diff options
Diffstat (limited to 'fs/ocfs2/file.c')
-rw-r--r-- | fs/ocfs2/file.c | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 432e5f3c4784..caefd571782e 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c | |||
@@ -51,6 +51,7 @@ | |||
51 | #include "inode.h" | 51 | #include "inode.h" |
52 | #include "ioctl.h" | 52 | #include "ioctl.h" |
53 | #include "journal.h" | 53 | #include "journal.h" |
54 | #include "locks.h" | ||
54 | #include "mmap.h" | 55 | #include "mmap.h" |
55 | #include "suballoc.h" | 56 | #include "suballoc.h" |
56 | #include "super.h" | 57 | #include "super.h" |
@@ -63,6 +64,35 @@ static int ocfs2_sync_inode(struct inode *inode) | |||
63 | return sync_mapping_buffers(inode->i_mapping); | 64 | return sync_mapping_buffers(inode->i_mapping); |
64 | } | 65 | } |
65 | 66 | ||
67 | static int ocfs2_init_file_private(struct inode *inode, struct file *file) | ||
68 | { | ||
69 | struct ocfs2_file_private *fp; | ||
70 | |||
71 | fp = kzalloc(sizeof(struct ocfs2_file_private), GFP_KERNEL); | ||
72 | if (!fp) | ||
73 | return -ENOMEM; | ||
74 | |||
75 | fp->fp_file = file; | ||
76 | mutex_init(&fp->fp_mutex); | ||
77 | ocfs2_file_lock_res_init(&fp->fp_flock, fp); | ||
78 | file->private_data = fp; | ||
79 | |||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | static void ocfs2_free_file_private(struct inode *inode, struct file *file) | ||
84 | { | ||
85 | struct ocfs2_file_private *fp = file->private_data; | ||
86 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
87 | |||
88 | if (fp) { | ||
89 | ocfs2_simple_drop_lockres(osb, &fp->fp_flock); | ||
90 | ocfs2_lock_res_free(&fp->fp_flock); | ||
91 | kfree(fp); | ||
92 | file->private_data = NULL; | ||
93 | } | ||
94 | } | ||
95 | |||
66 | static int ocfs2_file_open(struct inode *inode, struct file *file) | 96 | static int ocfs2_file_open(struct inode *inode, struct file *file) |
67 | { | 97 | { |
68 | int status; | 98 | int status; |
@@ -89,7 +119,18 @@ static int ocfs2_file_open(struct inode *inode, struct file *file) | |||
89 | 119 | ||
90 | oi->ip_open_count++; | 120 | oi->ip_open_count++; |
91 | spin_unlock(&oi->ip_lock); | 121 | spin_unlock(&oi->ip_lock); |
92 | status = 0; | 122 | |
123 | status = ocfs2_init_file_private(inode, file); | ||
124 | if (status) { | ||
125 | /* | ||
126 | * We want to set open count back if we're failing the | ||
127 | * open. | ||
128 | */ | ||
129 | spin_lock(&oi->ip_lock); | ||
130 | oi->ip_open_count--; | ||
131 | spin_unlock(&oi->ip_lock); | ||
132 | } | ||
133 | |||
93 | leave: | 134 | leave: |
94 | mlog_exit(status); | 135 | mlog_exit(status); |
95 | return status; | 136 | return status; |
@@ -108,11 +149,24 @@ static int ocfs2_file_release(struct inode *inode, struct file *file) | |||
108 | oi->ip_flags &= ~OCFS2_INODE_OPEN_DIRECT; | 149 | oi->ip_flags &= ~OCFS2_INODE_OPEN_DIRECT; |
109 | spin_unlock(&oi->ip_lock); | 150 | spin_unlock(&oi->ip_lock); |
110 | 151 | ||
152 | ocfs2_free_file_private(inode, file); | ||
153 | |||
111 | mlog_exit(0); | 154 | mlog_exit(0); |
112 | 155 | ||
113 | return 0; | 156 | return 0; |
114 | } | 157 | } |
115 | 158 | ||
159 | static int ocfs2_dir_open(struct inode *inode, struct file *file) | ||
160 | { | ||
161 | return ocfs2_init_file_private(inode, file); | ||
162 | } | ||
163 | |||
164 | static int ocfs2_dir_release(struct inode *inode, struct file *file) | ||
165 | { | ||
166 | ocfs2_free_file_private(inode, file); | ||
167 | return 0; | ||
168 | } | ||
169 | |||
116 | static int ocfs2_sync_file(struct file *file, | 170 | static int ocfs2_sync_file(struct file *file, |
117 | struct dentry *dentry, | 171 | struct dentry *dentry, |
118 | int datasync) | 172 | int datasync) |
@@ -2191,6 +2245,7 @@ const struct file_operations ocfs2_fops = { | |||
2191 | #ifdef CONFIG_COMPAT | 2245 | #ifdef CONFIG_COMPAT |
2192 | .compat_ioctl = ocfs2_compat_ioctl, | 2246 | .compat_ioctl = ocfs2_compat_ioctl, |
2193 | #endif | 2247 | #endif |
2248 | .flock = ocfs2_flock, | ||
2194 | .splice_read = ocfs2_file_splice_read, | 2249 | .splice_read = ocfs2_file_splice_read, |
2195 | .splice_write = ocfs2_file_splice_write, | 2250 | .splice_write = ocfs2_file_splice_write, |
2196 | }; | 2251 | }; |
@@ -2199,8 +2254,11 @@ const struct file_operations ocfs2_dops = { | |||
2199 | .read = generic_read_dir, | 2254 | .read = generic_read_dir, |
2200 | .readdir = ocfs2_readdir, | 2255 | .readdir = ocfs2_readdir, |
2201 | .fsync = ocfs2_sync_file, | 2256 | .fsync = ocfs2_sync_file, |
2257 | .release = ocfs2_dir_release, | ||
2258 | .open = ocfs2_dir_open, | ||
2202 | .ioctl = ocfs2_ioctl, | 2259 | .ioctl = ocfs2_ioctl, |
2203 | #ifdef CONFIG_COMPAT | 2260 | #ifdef CONFIG_COMPAT |
2204 | .compat_ioctl = ocfs2_compat_ioctl, | 2261 | .compat_ioctl = ocfs2_compat_ioctl, |
2205 | #endif | 2262 | #endif |
2263 | .flock = ocfs2_flock, | ||
2206 | }; | 2264 | }; |