Commit b276058371f5c2ad92f9f27373a72b219ed580ed
1 parent
e9079cce20
Exists in
master
and in
20 other branches
GFS2: Rationalise header files
Move the contents of some headers which contained very little into more sensible places, and remove the original header files. This should make it easier to find things. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Showing 14 changed files with 23 additions and 90 deletions Inline Diff
fs/gfs2/inode.c
1 | /* | 1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
3 | * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. | 3 | * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. |
4 | * | 4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | 5 | * This copyrighted material is made available to anyone wishing to use, |
6 | * modify, copy, or redistribute it subject to the terms and conditions | 6 | * modify, copy, or redistribute it subject to the terms and conditions |
7 | * of the GNU General Public License version 2. | 7 | * of the GNU General Public License version 2. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/sched.h> | 10 | #include <linux/sched.h> |
11 | #include <linux/slab.h> | 11 | #include <linux/slab.h> |
12 | #include <linux/spinlock.h> | 12 | #include <linux/spinlock.h> |
13 | #include <linux/completion.h> | 13 | #include <linux/completion.h> |
14 | #include <linux/buffer_head.h> | 14 | #include <linux/buffer_head.h> |
15 | #include <linux/posix_acl.h> | 15 | #include <linux/posix_acl.h> |
16 | #include <linux/sort.h> | 16 | #include <linux/sort.h> |
17 | #include <linux/gfs2_ondisk.h> | 17 | #include <linux/gfs2_ondisk.h> |
18 | #include <linux/crc32.h> | 18 | #include <linux/crc32.h> |
19 | #include <linux/lm_interface.h> | 19 | #include <linux/lm_interface.h> |
20 | #include <linux/security.h> | 20 | #include <linux/security.h> |
21 | #include <linux/time.h> | 21 | #include <linux/time.h> |
22 | 22 | ||
23 | #include "gfs2.h" | 23 | #include "gfs2.h" |
24 | #include "incore.h" | 24 | #include "incore.h" |
25 | #include "acl.h" | 25 | #include "acl.h" |
26 | #include "bmap.h" | 26 | #include "bmap.h" |
27 | #include "dir.h" | 27 | #include "dir.h" |
28 | #include "eattr.h" | 28 | #include "eattr.h" |
29 | #include "glock.h" | 29 | #include "glock.h" |
30 | #include "glops.h" | 30 | #include "glops.h" |
31 | #include "inode.h" | 31 | #include "inode.h" |
32 | #include "log.h" | 32 | #include "log.h" |
33 | #include "meta_io.h" | 33 | #include "meta_io.h" |
34 | #include "ops_address.h" | 34 | #include "ops_address.h" |
35 | #include "ops_inode.h" | ||
36 | #include "quota.h" | 35 | #include "quota.h" |
37 | #include "rgrp.h" | 36 | #include "rgrp.h" |
38 | #include "trans.h" | 37 | #include "trans.h" |
39 | #include "util.h" | 38 | #include "util.h" |
40 | 39 | ||
41 | struct gfs2_inum_range_host { | 40 | struct gfs2_inum_range_host { |
42 | u64 ir_start; | 41 | u64 ir_start; |
43 | u64 ir_length; | 42 | u64 ir_length; |
44 | }; | 43 | }; |
45 | 44 | ||
46 | static int iget_test(struct inode *inode, void *opaque) | 45 | static int iget_test(struct inode *inode, void *opaque) |
47 | { | 46 | { |
48 | struct gfs2_inode *ip = GFS2_I(inode); | 47 | struct gfs2_inode *ip = GFS2_I(inode); |
49 | u64 *no_addr = opaque; | 48 | u64 *no_addr = opaque; |
50 | 49 | ||
51 | if (ip->i_no_addr == *no_addr && test_bit(GIF_USER, &ip->i_flags)) | 50 | if (ip->i_no_addr == *no_addr && test_bit(GIF_USER, &ip->i_flags)) |
52 | return 1; | 51 | return 1; |
53 | 52 | ||
54 | return 0; | 53 | return 0; |
55 | } | 54 | } |
56 | 55 | ||
57 | static int iget_set(struct inode *inode, void *opaque) | 56 | static int iget_set(struct inode *inode, void *opaque) |
58 | { | 57 | { |
59 | struct gfs2_inode *ip = GFS2_I(inode); | 58 | struct gfs2_inode *ip = GFS2_I(inode); |
60 | u64 *no_addr = opaque; | 59 | u64 *no_addr = opaque; |
61 | 60 | ||
62 | inode->i_ino = (unsigned long)*no_addr; | 61 | inode->i_ino = (unsigned long)*no_addr; |
63 | ip->i_no_addr = *no_addr; | 62 | ip->i_no_addr = *no_addr; |
64 | set_bit(GIF_USER, &ip->i_flags); | 63 | set_bit(GIF_USER, &ip->i_flags); |
65 | return 0; | 64 | return 0; |
66 | } | 65 | } |
67 | 66 | ||
68 | struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr) | 67 | struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr) |
69 | { | 68 | { |
70 | unsigned long hash = (unsigned long)no_addr; | 69 | unsigned long hash = (unsigned long)no_addr; |
71 | return ilookup5(sb, hash, iget_test, &no_addr); | 70 | return ilookup5(sb, hash, iget_test, &no_addr); |
72 | } | 71 | } |
73 | 72 | ||
74 | static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr) | 73 | static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr) |
75 | { | 74 | { |
76 | unsigned long hash = (unsigned long)no_addr; | 75 | unsigned long hash = (unsigned long)no_addr; |
77 | return iget5_locked(sb, hash, iget_test, iget_set, &no_addr); | 76 | return iget5_locked(sb, hash, iget_test, iget_set, &no_addr); |
78 | } | 77 | } |
79 | 78 | ||
80 | struct gfs2_skip_data { | 79 | struct gfs2_skip_data { |
81 | u64 no_addr; | 80 | u64 no_addr; |
82 | int skipped; | 81 | int skipped; |
83 | }; | 82 | }; |
84 | 83 | ||
85 | static int iget_skip_test(struct inode *inode, void *opaque) | 84 | static int iget_skip_test(struct inode *inode, void *opaque) |
86 | { | 85 | { |
87 | struct gfs2_inode *ip = GFS2_I(inode); | 86 | struct gfs2_inode *ip = GFS2_I(inode); |
88 | struct gfs2_skip_data *data = opaque; | 87 | struct gfs2_skip_data *data = opaque; |
89 | 88 | ||
90 | if (ip->i_no_addr == data->no_addr && test_bit(GIF_USER, &ip->i_flags)){ | 89 | if (ip->i_no_addr == data->no_addr && test_bit(GIF_USER, &ip->i_flags)){ |
91 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)){ | 90 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)){ |
92 | data->skipped = 1; | 91 | data->skipped = 1; |
93 | return 0; | 92 | return 0; |
94 | } | 93 | } |
95 | return 1; | 94 | return 1; |
96 | } | 95 | } |
97 | return 0; | 96 | return 0; |
98 | } | 97 | } |
99 | 98 | ||
100 | static int iget_skip_set(struct inode *inode, void *opaque) | 99 | static int iget_skip_set(struct inode *inode, void *opaque) |
101 | { | 100 | { |
102 | struct gfs2_inode *ip = GFS2_I(inode); | 101 | struct gfs2_inode *ip = GFS2_I(inode); |
103 | struct gfs2_skip_data *data = opaque; | 102 | struct gfs2_skip_data *data = opaque; |
104 | 103 | ||
105 | if (data->skipped) | 104 | if (data->skipped) |
106 | return 1; | 105 | return 1; |
107 | inode->i_ino = (unsigned long)(data->no_addr); | 106 | inode->i_ino = (unsigned long)(data->no_addr); |
108 | ip->i_no_addr = data->no_addr; | 107 | ip->i_no_addr = data->no_addr; |
109 | set_bit(GIF_USER, &ip->i_flags); | 108 | set_bit(GIF_USER, &ip->i_flags); |
110 | return 0; | 109 | return 0; |
111 | } | 110 | } |
112 | 111 | ||
113 | static struct inode *gfs2_iget_skip(struct super_block *sb, | 112 | static struct inode *gfs2_iget_skip(struct super_block *sb, |
114 | u64 no_addr) | 113 | u64 no_addr) |
115 | { | 114 | { |
116 | struct gfs2_skip_data data; | 115 | struct gfs2_skip_data data; |
117 | unsigned long hash = (unsigned long)no_addr; | 116 | unsigned long hash = (unsigned long)no_addr; |
118 | 117 | ||
119 | data.no_addr = no_addr; | 118 | data.no_addr = no_addr; |
120 | data.skipped = 0; | 119 | data.skipped = 0; |
121 | return iget5_locked(sb, hash, iget_skip_test, iget_skip_set, &data); | 120 | return iget5_locked(sb, hash, iget_skip_test, iget_skip_set, &data); |
122 | } | 121 | } |
123 | 122 | ||
124 | /** | 123 | /** |
125 | * GFS2 lookup code fills in vfs inode contents based on info obtained | 124 | * GFS2 lookup code fills in vfs inode contents based on info obtained |
126 | * from directory entry inside gfs2_inode_lookup(). This has caused issues | 125 | * from directory entry inside gfs2_inode_lookup(). This has caused issues |
127 | * with NFS code path since its get_dentry routine doesn't have the relevant | 126 | * with NFS code path since its get_dentry routine doesn't have the relevant |
128 | * directory entry when gfs2_inode_lookup() is invoked. Part of the code | 127 | * directory entry when gfs2_inode_lookup() is invoked. Part of the code |
129 | * segment inside gfs2_inode_lookup code needs to get moved around. | 128 | * segment inside gfs2_inode_lookup code needs to get moved around. |
130 | * | 129 | * |
131 | * Clean up I_LOCK and I_NEW as well. | 130 | * Clean up I_LOCK and I_NEW as well. |
132 | **/ | 131 | **/ |
133 | 132 | ||
134 | void gfs2_set_iop(struct inode *inode) | 133 | void gfs2_set_iop(struct inode *inode) |
135 | { | 134 | { |
136 | struct gfs2_sbd *sdp = GFS2_SB(inode); | 135 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
137 | umode_t mode = inode->i_mode; | 136 | umode_t mode = inode->i_mode; |
138 | 137 | ||
139 | if (S_ISREG(mode)) { | 138 | if (S_ISREG(mode)) { |
140 | inode->i_op = &gfs2_file_iops; | 139 | inode->i_op = &gfs2_file_iops; |
141 | if (sdp->sd_args.ar_localflocks) | 140 | if (sdp->sd_args.ar_localflocks) |
142 | inode->i_fop = &gfs2_file_fops_nolock; | 141 | inode->i_fop = &gfs2_file_fops_nolock; |
143 | else | 142 | else |
144 | inode->i_fop = &gfs2_file_fops; | 143 | inode->i_fop = &gfs2_file_fops; |
145 | } else if (S_ISDIR(mode)) { | 144 | } else if (S_ISDIR(mode)) { |
146 | inode->i_op = &gfs2_dir_iops; | 145 | inode->i_op = &gfs2_dir_iops; |
147 | if (sdp->sd_args.ar_localflocks) | 146 | if (sdp->sd_args.ar_localflocks) |
148 | inode->i_fop = &gfs2_dir_fops_nolock; | 147 | inode->i_fop = &gfs2_dir_fops_nolock; |
149 | else | 148 | else |
150 | inode->i_fop = &gfs2_dir_fops; | 149 | inode->i_fop = &gfs2_dir_fops; |
151 | } else if (S_ISLNK(mode)) { | 150 | } else if (S_ISLNK(mode)) { |
152 | inode->i_op = &gfs2_symlink_iops; | 151 | inode->i_op = &gfs2_symlink_iops; |
153 | } else { | 152 | } else { |
154 | inode->i_op = &gfs2_file_iops; | 153 | inode->i_op = &gfs2_file_iops; |
155 | init_special_inode(inode, inode->i_mode, inode->i_rdev); | 154 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
156 | } | 155 | } |
157 | 156 | ||
158 | unlock_new_inode(inode); | 157 | unlock_new_inode(inode); |
159 | } | 158 | } |
160 | 159 | ||
161 | /** | 160 | /** |
162 | * gfs2_inode_lookup - Lookup an inode | 161 | * gfs2_inode_lookup - Lookup an inode |
163 | * @sb: The super block | 162 | * @sb: The super block |
164 | * @no_addr: The inode number | 163 | * @no_addr: The inode number |
165 | * @type: The type of the inode | 164 | * @type: The type of the inode |
166 | * @skip_freeing: set this not return an inode if it is currently being freed. | 165 | * @skip_freeing: set this not return an inode if it is currently being freed. |
167 | * | 166 | * |
168 | * Returns: A VFS inode, or an error | 167 | * Returns: A VFS inode, or an error |
169 | */ | 168 | */ |
170 | 169 | ||
171 | struct inode *gfs2_inode_lookup(struct super_block *sb, | 170 | struct inode *gfs2_inode_lookup(struct super_block *sb, |
172 | unsigned int type, | 171 | unsigned int type, |
173 | u64 no_addr, | 172 | u64 no_addr, |
174 | u64 no_formal_ino, int skip_freeing) | 173 | u64 no_formal_ino, int skip_freeing) |
175 | { | 174 | { |
176 | struct inode *inode; | 175 | struct inode *inode; |
177 | struct gfs2_inode *ip; | 176 | struct gfs2_inode *ip; |
178 | struct gfs2_glock *io_gl; | 177 | struct gfs2_glock *io_gl; |
179 | int error; | 178 | int error; |
180 | 179 | ||
181 | if (skip_freeing) | 180 | if (skip_freeing) |
182 | inode = gfs2_iget_skip(sb, no_addr); | 181 | inode = gfs2_iget_skip(sb, no_addr); |
183 | else | 182 | else |
184 | inode = gfs2_iget(sb, no_addr); | 183 | inode = gfs2_iget(sb, no_addr); |
185 | ip = GFS2_I(inode); | 184 | ip = GFS2_I(inode); |
186 | 185 | ||
187 | if (!inode) | 186 | if (!inode) |
188 | return ERR_PTR(-ENOBUFS); | 187 | return ERR_PTR(-ENOBUFS); |
189 | 188 | ||
190 | if (inode->i_state & I_NEW) { | 189 | if (inode->i_state & I_NEW) { |
191 | struct gfs2_sbd *sdp = GFS2_SB(inode); | 190 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
192 | ip->i_no_formal_ino = no_formal_ino; | 191 | ip->i_no_formal_ino = no_formal_ino; |
193 | 192 | ||
194 | error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl); | 193 | error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl); |
195 | if (unlikely(error)) | 194 | if (unlikely(error)) |
196 | goto fail; | 195 | goto fail; |
197 | ip->i_gl->gl_object = ip; | 196 | ip->i_gl->gl_object = ip; |
198 | 197 | ||
199 | error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl); | 198 | error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl); |
200 | if (unlikely(error)) | 199 | if (unlikely(error)) |
201 | goto fail_put; | 200 | goto fail_put; |
202 | 201 | ||
203 | set_bit(GIF_INVALID, &ip->i_flags); | 202 | set_bit(GIF_INVALID, &ip->i_flags); |
204 | error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh); | 203 | error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh); |
205 | if (unlikely(error)) | 204 | if (unlikely(error)) |
206 | goto fail_iopen; | 205 | goto fail_iopen; |
207 | ip->i_iopen_gh.gh_gl->gl_object = ip; | 206 | ip->i_iopen_gh.gh_gl->gl_object = ip; |
208 | 207 | ||
209 | gfs2_glock_put(io_gl); | 208 | gfs2_glock_put(io_gl); |
210 | 209 | ||
211 | if ((type == DT_UNKNOWN) && (no_formal_ino == 0)) | 210 | if ((type == DT_UNKNOWN) && (no_formal_ino == 0)) |
212 | goto gfs2_nfsbypass; | 211 | goto gfs2_nfsbypass; |
213 | 212 | ||
214 | inode->i_mode = DT2IF(type); | 213 | inode->i_mode = DT2IF(type); |
215 | 214 | ||
216 | /* | 215 | /* |
217 | * We must read the inode in order to work out its type in | 216 | * We must read the inode in order to work out its type in |
218 | * this case. Note that this doesn't happen often as we normally | 217 | * this case. Note that this doesn't happen often as we normally |
219 | * know the type beforehand. This code path only occurs during | 218 | * know the type beforehand. This code path only occurs during |
220 | * unlinked inode recovery (where it is safe to do this glock, | 219 | * unlinked inode recovery (where it is safe to do this glock, |
221 | * which is not true in the general case). | 220 | * which is not true in the general case). |
222 | */ | 221 | */ |
223 | if (type == DT_UNKNOWN) { | 222 | if (type == DT_UNKNOWN) { |
224 | struct gfs2_holder gh; | 223 | struct gfs2_holder gh; |
225 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); | 224 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
226 | if (unlikely(error)) | 225 | if (unlikely(error)) |
227 | goto fail_glock; | 226 | goto fail_glock; |
228 | /* Inode is now uptodate */ | 227 | /* Inode is now uptodate */ |
229 | gfs2_glock_dq_uninit(&gh); | 228 | gfs2_glock_dq_uninit(&gh); |
230 | } | 229 | } |
231 | 230 | ||
232 | gfs2_set_iop(inode); | 231 | gfs2_set_iop(inode); |
233 | } | 232 | } |
234 | 233 | ||
235 | gfs2_nfsbypass: | 234 | gfs2_nfsbypass: |
236 | return inode; | 235 | return inode; |
237 | fail_glock: | 236 | fail_glock: |
238 | gfs2_glock_dq(&ip->i_iopen_gh); | 237 | gfs2_glock_dq(&ip->i_iopen_gh); |
239 | fail_iopen: | 238 | fail_iopen: |
240 | gfs2_glock_put(io_gl); | 239 | gfs2_glock_put(io_gl); |
241 | fail_put: | 240 | fail_put: |
242 | ip->i_gl->gl_object = NULL; | 241 | ip->i_gl->gl_object = NULL; |
243 | gfs2_glock_put(ip->i_gl); | 242 | gfs2_glock_put(ip->i_gl); |
244 | fail: | 243 | fail: |
245 | iget_failed(inode); | 244 | iget_failed(inode); |
246 | return ERR_PTR(error); | 245 | return ERR_PTR(error); |
247 | } | 246 | } |
248 | 247 | ||
249 | static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf) | 248 | static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf) |
250 | { | 249 | { |
251 | struct gfs2_dinode_host *di = &ip->i_di; | 250 | struct gfs2_dinode_host *di = &ip->i_di; |
252 | const struct gfs2_dinode *str = buf; | 251 | const struct gfs2_dinode *str = buf; |
253 | struct timespec atime; | 252 | struct timespec atime; |
254 | u16 height, depth; | 253 | u16 height, depth; |
255 | 254 | ||
256 | if (unlikely(ip->i_no_addr != be64_to_cpu(str->di_num.no_addr))) | 255 | if (unlikely(ip->i_no_addr != be64_to_cpu(str->di_num.no_addr))) |
257 | goto corrupt; | 256 | goto corrupt; |
258 | ip->i_no_formal_ino = be64_to_cpu(str->di_num.no_formal_ino); | 257 | ip->i_no_formal_ino = be64_to_cpu(str->di_num.no_formal_ino); |
259 | ip->i_inode.i_mode = be32_to_cpu(str->di_mode); | 258 | ip->i_inode.i_mode = be32_to_cpu(str->di_mode); |
260 | ip->i_inode.i_rdev = 0; | 259 | ip->i_inode.i_rdev = 0; |
261 | switch (ip->i_inode.i_mode & S_IFMT) { | 260 | switch (ip->i_inode.i_mode & S_IFMT) { |
262 | case S_IFBLK: | 261 | case S_IFBLK: |
263 | case S_IFCHR: | 262 | case S_IFCHR: |
264 | ip->i_inode.i_rdev = MKDEV(be32_to_cpu(str->di_major), | 263 | ip->i_inode.i_rdev = MKDEV(be32_to_cpu(str->di_major), |
265 | be32_to_cpu(str->di_minor)); | 264 | be32_to_cpu(str->di_minor)); |
266 | break; | 265 | break; |
267 | }; | 266 | }; |
268 | 267 | ||
269 | ip->i_inode.i_uid = be32_to_cpu(str->di_uid); | 268 | ip->i_inode.i_uid = be32_to_cpu(str->di_uid); |
270 | ip->i_inode.i_gid = be32_to_cpu(str->di_gid); | 269 | ip->i_inode.i_gid = be32_to_cpu(str->di_gid); |
271 | /* | 270 | /* |
272 | * We will need to review setting the nlink count here in the | 271 | * We will need to review setting the nlink count here in the |
273 | * light of the forthcoming ro bind mount work. This is a reminder | 272 | * light of the forthcoming ro bind mount work. This is a reminder |
274 | * to do that. | 273 | * to do that. |
275 | */ | 274 | */ |
276 | ip->i_inode.i_nlink = be32_to_cpu(str->di_nlink); | 275 | ip->i_inode.i_nlink = be32_to_cpu(str->di_nlink); |
277 | di->di_size = be64_to_cpu(str->di_size); | 276 | di->di_size = be64_to_cpu(str->di_size); |
278 | i_size_write(&ip->i_inode, di->di_size); | 277 | i_size_write(&ip->i_inode, di->di_size); |
279 | gfs2_set_inode_blocks(&ip->i_inode, be64_to_cpu(str->di_blocks)); | 278 | gfs2_set_inode_blocks(&ip->i_inode, be64_to_cpu(str->di_blocks)); |
280 | atime.tv_sec = be64_to_cpu(str->di_atime); | 279 | atime.tv_sec = be64_to_cpu(str->di_atime); |
281 | atime.tv_nsec = be32_to_cpu(str->di_atime_nsec); | 280 | atime.tv_nsec = be32_to_cpu(str->di_atime_nsec); |
282 | if (timespec_compare(&ip->i_inode.i_atime, &atime) < 0) | 281 | if (timespec_compare(&ip->i_inode.i_atime, &atime) < 0) |
283 | ip->i_inode.i_atime = atime; | 282 | ip->i_inode.i_atime = atime; |
284 | ip->i_inode.i_mtime.tv_sec = be64_to_cpu(str->di_mtime); | 283 | ip->i_inode.i_mtime.tv_sec = be64_to_cpu(str->di_mtime); |
285 | ip->i_inode.i_mtime.tv_nsec = be32_to_cpu(str->di_mtime_nsec); | 284 | ip->i_inode.i_mtime.tv_nsec = be32_to_cpu(str->di_mtime_nsec); |
286 | ip->i_inode.i_ctime.tv_sec = be64_to_cpu(str->di_ctime); | 285 | ip->i_inode.i_ctime.tv_sec = be64_to_cpu(str->di_ctime); |
287 | ip->i_inode.i_ctime.tv_nsec = be32_to_cpu(str->di_ctime_nsec); | 286 | ip->i_inode.i_ctime.tv_nsec = be32_to_cpu(str->di_ctime_nsec); |
288 | 287 | ||
289 | ip->i_goal = be64_to_cpu(str->di_goal_meta); | 288 | ip->i_goal = be64_to_cpu(str->di_goal_meta); |
290 | di->di_generation = be64_to_cpu(str->di_generation); | 289 | di->di_generation = be64_to_cpu(str->di_generation); |
291 | 290 | ||
292 | di->di_flags = be32_to_cpu(str->di_flags); | 291 | di->di_flags = be32_to_cpu(str->di_flags); |
293 | gfs2_set_inode_flags(&ip->i_inode); | 292 | gfs2_set_inode_flags(&ip->i_inode); |
294 | height = be16_to_cpu(str->di_height); | 293 | height = be16_to_cpu(str->di_height); |
295 | if (unlikely(height > GFS2_MAX_META_HEIGHT)) | 294 | if (unlikely(height > GFS2_MAX_META_HEIGHT)) |
296 | goto corrupt; | 295 | goto corrupt; |
297 | ip->i_height = (u8)height; | 296 | ip->i_height = (u8)height; |
298 | 297 | ||
299 | depth = be16_to_cpu(str->di_depth); | 298 | depth = be16_to_cpu(str->di_depth); |
300 | if (unlikely(depth > GFS2_DIR_MAX_DEPTH)) | 299 | if (unlikely(depth > GFS2_DIR_MAX_DEPTH)) |
301 | goto corrupt; | 300 | goto corrupt; |
302 | ip->i_depth = (u8)depth; | 301 | ip->i_depth = (u8)depth; |
303 | di->di_entries = be32_to_cpu(str->di_entries); | 302 | di->di_entries = be32_to_cpu(str->di_entries); |
304 | 303 | ||
305 | di->di_eattr = be64_to_cpu(str->di_eattr); | 304 | di->di_eattr = be64_to_cpu(str->di_eattr); |
306 | if (S_ISREG(ip->i_inode.i_mode)) | 305 | if (S_ISREG(ip->i_inode.i_mode)) |
307 | gfs2_set_aops(&ip->i_inode); | 306 | gfs2_set_aops(&ip->i_inode); |
308 | 307 | ||
309 | return 0; | 308 | return 0; |
310 | corrupt: | 309 | corrupt: |
311 | if (gfs2_consist_inode(ip)) | 310 | if (gfs2_consist_inode(ip)) |
312 | gfs2_dinode_print(ip); | 311 | gfs2_dinode_print(ip); |
313 | return -EIO; | 312 | return -EIO; |
314 | } | 313 | } |
315 | 314 | ||
316 | /** | 315 | /** |
317 | * gfs2_inode_refresh - Refresh the incore copy of the dinode | 316 | * gfs2_inode_refresh - Refresh the incore copy of the dinode |
318 | * @ip: The GFS2 inode | 317 | * @ip: The GFS2 inode |
319 | * | 318 | * |
320 | * Returns: errno | 319 | * Returns: errno |
321 | */ | 320 | */ |
322 | 321 | ||
323 | int gfs2_inode_refresh(struct gfs2_inode *ip) | 322 | int gfs2_inode_refresh(struct gfs2_inode *ip) |
324 | { | 323 | { |
325 | struct buffer_head *dibh; | 324 | struct buffer_head *dibh; |
326 | int error; | 325 | int error; |
327 | 326 | ||
328 | error = gfs2_meta_inode_buffer(ip, &dibh); | 327 | error = gfs2_meta_inode_buffer(ip, &dibh); |
329 | if (error) | 328 | if (error) |
330 | return error; | 329 | return error; |
331 | 330 | ||
332 | if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), dibh, GFS2_METATYPE_DI)) { | 331 | if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), dibh, GFS2_METATYPE_DI)) { |
333 | brelse(dibh); | 332 | brelse(dibh); |
334 | return -EIO; | 333 | return -EIO; |
335 | } | 334 | } |
336 | 335 | ||
337 | error = gfs2_dinode_in(ip, dibh->b_data); | 336 | error = gfs2_dinode_in(ip, dibh->b_data); |
338 | brelse(dibh); | 337 | brelse(dibh); |
339 | clear_bit(GIF_INVALID, &ip->i_flags); | 338 | clear_bit(GIF_INVALID, &ip->i_flags); |
340 | 339 | ||
341 | return error; | 340 | return error; |
342 | } | 341 | } |
343 | 342 | ||
344 | int gfs2_dinode_dealloc(struct gfs2_inode *ip) | 343 | int gfs2_dinode_dealloc(struct gfs2_inode *ip) |
345 | { | 344 | { |
346 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | 345 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
347 | struct gfs2_alloc *al; | 346 | struct gfs2_alloc *al; |
348 | struct gfs2_rgrpd *rgd; | 347 | struct gfs2_rgrpd *rgd; |
349 | int error; | 348 | int error; |
350 | 349 | ||
351 | if (gfs2_get_inode_blocks(&ip->i_inode) != 1) { | 350 | if (gfs2_get_inode_blocks(&ip->i_inode) != 1) { |
352 | if (gfs2_consist_inode(ip)) | 351 | if (gfs2_consist_inode(ip)) |
353 | gfs2_dinode_print(ip); | 352 | gfs2_dinode_print(ip); |
354 | return -EIO; | 353 | return -EIO; |
355 | } | 354 | } |
356 | 355 | ||
357 | al = gfs2_alloc_get(ip); | 356 | al = gfs2_alloc_get(ip); |
358 | if (!al) | 357 | if (!al) |
359 | return -ENOMEM; | 358 | return -ENOMEM; |
360 | 359 | ||
361 | error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); | 360 | error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); |
362 | if (error) | 361 | if (error) |
363 | goto out; | 362 | goto out; |
364 | 363 | ||
365 | error = gfs2_rindex_hold(sdp, &al->al_ri_gh); | 364 | error = gfs2_rindex_hold(sdp, &al->al_ri_gh); |
366 | if (error) | 365 | if (error) |
367 | goto out_qs; | 366 | goto out_qs; |
368 | 367 | ||
369 | rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); | 368 | rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); |
370 | if (!rgd) { | 369 | if (!rgd) { |
371 | gfs2_consist_inode(ip); | 370 | gfs2_consist_inode(ip); |
372 | error = -EIO; | 371 | error = -EIO; |
373 | goto out_rindex_relse; | 372 | goto out_rindex_relse; |
374 | } | 373 | } |
375 | 374 | ||
376 | error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, | 375 | error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, |
377 | &al->al_rgd_gh); | 376 | &al->al_rgd_gh); |
378 | if (error) | 377 | if (error) |
379 | goto out_rindex_relse; | 378 | goto out_rindex_relse; |
380 | 379 | ||
381 | error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 1); | 380 | error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA, 1); |
382 | if (error) | 381 | if (error) |
383 | goto out_rg_gunlock; | 382 | goto out_rg_gunlock; |
384 | 383 | ||
385 | set_bit(GLF_DIRTY, &ip->i_gl->gl_flags); | 384 | set_bit(GLF_DIRTY, &ip->i_gl->gl_flags); |
386 | set_bit(GLF_LFLUSH, &ip->i_gl->gl_flags); | 385 | set_bit(GLF_LFLUSH, &ip->i_gl->gl_flags); |
387 | 386 | ||
388 | gfs2_free_di(rgd, ip); | 387 | gfs2_free_di(rgd, ip); |
389 | 388 | ||
390 | gfs2_trans_end(sdp); | 389 | gfs2_trans_end(sdp); |
391 | clear_bit(GLF_STICKY, &ip->i_gl->gl_flags); | 390 | clear_bit(GLF_STICKY, &ip->i_gl->gl_flags); |
392 | 391 | ||
393 | out_rg_gunlock: | 392 | out_rg_gunlock: |
394 | gfs2_glock_dq_uninit(&al->al_rgd_gh); | 393 | gfs2_glock_dq_uninit(&al->al_rgd_gh); |
395 | out_rindex_relse: | 394 | out_rindex_relse: |
396 | gfs2_glock_dq_uninit(&al->al_ri_gh); | 395 | gfs2_glock_dq_uninit(&al->al_ri_gh); |
397 | out_qs: | 396 | out_qs: |
398 | gfs2_quota_unhold(ip); | 397 | gfs2_quota_unhold(ip); |
399 | out: | 398 | out: |
400 | gfs2_alloc_put(ip); | 399 | gfs2_alloc_put(ip); |
401 | return error; | 400 | return error; |
402 | } | 401 | } |
403 | 402 | ||
404 | /** | 403 | /** |
405 | * gfs2_change_nlink - Change nlink count on inode | 404 | * gfs2_change_nlink - Change nlink count on inode |
406 | * @ip: The GFS2 inode | 405 | * @ip: The GFS2 inode |
407 | * @diff: The change in the nlink count required | 406 | * @diff: The change in the nlink count required |
408 | * | 407 | * |
409 | * Returns: errno | 408 | * Returns: errno |
410 | */ | 409 | */ |
411 | int gfs2_change_nlink(struct gfs2_inode *ip, int diff) | 410 | int gfs2_change_nlink(struct gfs2_inode *ip, int diff) |
412 | { | 411 | { |
413 | struct buffer_head *dibh; | 412 | struct buffer_head *dibh; |
414 | u32 nlink; | 413 | u32 nlink; |
415 | int error; | 414 | int error; |
416 | 415 | ||
417 | BUG_ON(diff != 1 && diff != -1); | 416 | BUG_ON(diff != 1 && diff != -1); |
418 | nlink = ip->i_inode.i_nlink + diff; | 417 | nlink = ip->i_inode.i_nlink + diff; |
419 | 418 | ||
420 | /* If we are reducing the nlink count, but the new value ends up being | 419 | /* If we are reducing the nlink count, but the new value ends up being |
421 | bigger than the old one, we must have underflowed. */ | 420 | bigger than the old one, we must have underflowed. */ |
422 | if (diff < 0 && nlink > ip->i_inode.i_nlink) { | 421 | if (diff < 0 && nlink > ip->i_inode.i_nlink) { |
423 | if (gfs2_consist_inode(ip)) | 422 | if (gfs2_consist_inode(ip)) |
424 | gfs2_dinode_print(ip); | 423 | gfs2_dinode_print(ip); |
425 | return -EIO; | 424 | return -EIO; |
426 | } | 425 | } |
427 | 426 | ||
428 | error = gfs2_meta_inode_buffer(ip, &dibh); | 427 | error = gfs2_meta_inode_buffer(ip, &dibh); |
429 | if (error) | 428 | if (error) |
430 | return error; | 429 | return error; |
431 | 430 | ||
432 | if (diff > 0) | 431 | if (diff > 0) |
433 | inc_nlink(&ip->i_inode); | 432 | inc_nlink(&ip->i_inode); |
434 | else | 433 | else |
435 | drop_nlink(&ip->i_inode); | 434 | drop_nlink(&ip->i_inode); |
436 | 435 | ||
437 | ip->i_inode.i_ctime = CURRENT_TIME; | 436 | ip->i_inode.i_ctime = CURRENT_TIME; |
438 | 437 | ||
439 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); | 438 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
440 | gfs2_dinode_out(ip, dibh->b_data); | 439 | gfs2_dinode_out(ip, dibh->b_data); |
441 | brelse(dibh); | 440 | brelse(dibh); |
442 | mark_inode_dirty(&ip->i_inode); | 441 | mark_inode_dirty(&ip->i_inode); |
443 | 442 | ||
444 | if (ip->i_inode.i_nlink == 0) | 443 | if (ip->i_inode.i_nlink == 0) |
445 | gfs2_unlink_di(&ip->i_inode); /* mark inode unlinked */ | 444 | gfs2_unlink_di(&ip->i_inode); /* mark inode unlinked */ |
446 | 445 | ||
447 | return error; | 446 | return error; |
448 | } | 447 | } |
449 | 448 | ||
450 | struct inode *gfs2_lookup_simple(struct inode *dip, const char *name) | 449 | struct inode *gfs2_lookup_simple(struct inode *dip, const char *name) |
451 | { | 450 | { |
452 | struct qstr qstr; | 451 | struct qstr qstr; |
453 | struct inode *inode; | 452 | struct inode *inode; |
454 | gfs2_str2qstr(&qstr, name); | 453 | gfs2_str2qstr(&qstr, name); |
455 | inode = gfs2_lookupi(dip, &qstr, 1); | 454 | inode = gfs2_lookupi(dip, &qstr, 1); |
456 | /* gfs2_lookupi has inconsistent callers: vfs | 455 | /* gfs2_lookupi has inconsistent callers: vfs |
457 | * related routines expect NULL for no entry found, | 456 | * related routines expect NULL for no entry found, |
458 | * gfs2_lookup_simple callers expect ENOENT | 457 | * gfs2_lookup_simple callers expect ENOENT |
459 | * and do not check for NULL. | 458 | * and do not check for NULL. |
460 | */ | 459 | */ |
461 | if (inode == NULL) | 460 | if (inode == NULL) |
462 | return ERR_PTR(-ENOENT); | 461 | return ERR_PTR(-ENOENT); |
463 | else | 462 | else |
464 | return inode; | 463 | return inode; |
465 | } | 464 | } |
466 | 465 | ||
467 | 466 | ||
468 | /** | 467 | /** |
469 | * gfs2_lookupi - Look up a filename in a directory and return its inode | 468 | * gfs2_lookupi - Look up a filename in a directory and return its inode |
470 | * @d_gh: An initialized holder for the directory glock | 469 | * @d_gh: An initialized holder for the directory glock |
471 | * @name: The name of the inode to look for | 470 | * @name: The name of the inode to look for |
472 | * @is_root: If 1, ignore the caller's permissions | 471 | * @is_root: If 1, ignore the caller's permissions |
473 | * @i_gh: An uninitialized holder for the new inode glock | 472 | * @i_gh: An uninitialized holder for the new inode glock |
474 | * | 473 | * |
475 | * This can be called via the VFS filldir function when NFS is doing | 474 | * This can be called via the VFS filldir function when NFS is doing |
476 | * a readdirplus and the inode which its intending to stat isn't | 475 | * a readdirplus and the inode which its intending to stat isn't |
477 | * already in cache. In this case we must not take the directory glock | 476 | * already in cache. In this case we must not take the directory glock |
478 | * again, since the readdir call will have already taken that lock. | 477 | * again, since the readdir call will have already taken that lock. |
479 | * | 478 | * |
480 | * Returns: errno | 479 | * Returns: errno |
481 | */ | 480 | */ |
482 | 481 | ||
483 | struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, | 482 | struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, |
484 | int is_root) | 483 | int is_root) |
485 | { | 484 | { |
486 | struct super_block *sb = dir->i_sb; | 485 | struct super_block *sb = dir->i_sb; |
487 | struct gfs2_inode *dip = GFS2_I(dir); | 486 | struct gfs2_inode *dip = GFS2_I(dir); |
488 | struct gfs2_holder d_gh; | 487 | struct gfs2_holder d_gh; |
489 | int error = 0; | 488 | int error = 0; |
490 | struct inode *inode = NULL; | 489 | struct inode *inode = NULL; |
491 | int unlock = 0; | 490 | int unlock = 0; |
492 | 491 | ||
493 | if (!name->len || name->len > GFS2_FNAMESIZE) | 492 | if (!name->len || name->len > GFS2_FNAMESIZE) |
494 | return ERR_PTR(-ENAMETOOLONG); | 493 | return ERR_PTR(-ENAMETOOLONG); |
495 | 494 | ||
496 | if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) || | 495 | if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) || |
497 | (name->len == 2 && memcmp(name->name, "..", 2) == 0 && | 496 | (name->len == 2 && memcmp(name->name, "..", 2) == 0 && |
498 | dir == sb->s_root->d_inode)) { | 497 | dir == sb->s_root->d_inode)) { |
499 | igrab(dir); | 498 | igrab(dir); |
500 | return dir; | 499 | return dir; |
501 | } | 500 | } |
502 | 501 | ||
503 | if (gfs2_glock_is_locked_by_me(dip->i_gl) == NULL) { | 502 | if (gfs2_glock_is_locked_by_me(dip->i_gl) == NULL) { |
504 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); | 503 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); |
505 | if (error) | 504 | if (error) |
506 | return ERR_PTR(error); | 505 | return ERR_PTR(error); |
507 | unlock = 1; | 506 | unlock = 1; |
508 | } | 507 | } |
509 | 508 | ||
510 | if (!is_root) { | 509 | if (!is_root) { |
511 | error = gfs2_permission(dir, MAY_EXEC); | 510 | error = gfs2_permission(dir, MAY_EXEC); |
512 | if (error) | 511 | if (error) |
513 | goto out; | 512 | goto out; |
514 | } | 513 | } |
515 | 514 | ||
516 | inode = gfs2_dir_search(dir, name); | 515 | inode = gfs2_dir_search(dir, name); |
517 | if (IS_ERR(inode)) | 516 | if (IS_ERR(inode)) |
518 | error = PTR_ERR(inode); | 517 | error = PTR_ERR(inode); |
519 | out: | 518 | out: |
520 | if (unlock) | 519 | if (unlock) |
521 | gfs2_glock_dq_uninit(&d_gh); | 520 | gfs2_glock_dq_uninit(&d_gh); |
522 | if (error == -ENOENT) | 521 | if (error == -ENOENT) |
523 | return NULL; | 522 | return NULL; |
524 | return inode ? inode : ERR_PTR(error); | 523 | return inode ? inode : ERR_PTR(error); |
525 | } | 524 | } |
526 | 525 | ||
527 | static void gfs2_inum_range_in(struct gfs2_inum_range_host *ir, const void *buf) | 526 | static void gfs2_inum_range_in(struct gfs2_inum_range_host *ir, const void *buf) |
528 | { | 527 | { |
529 | const struct gfs2_inum_range *str = buf; | 528 | const struct gfs2_inum_range *str = buf; |
530 | 529 | ||
531 | ir->ir_start = be64_to_cpu(str->ir_start); | 530 | ir->ir_start = be64_to_cpu(str->ir_start); |
532 | ir->ir_length = be64_to_cpu(str->ir_length); | 531 | ir->ir_length = be64_to_cpu(str->ir_length); |
533 | } | 532 | } |
534 | 533 | ||
535 | static void gfs2_inum_range_out(const struct gfs2_inum_range_host *ir, void *buf) | 534 | static void gfs2_inum_range_out(const struct gfs2_inum_range_host *ir, void *buf) |
536 | { | 535 | { |
537 | struct gfs2_inum_range *str = buf; | 536 | struct gfs2_inum_range *str = buf; |
538 | 537 | ||
539 | str->ir_start = cpu_to_be64(ir->ir_start); | 538 | str->ir_start = cpu_to_be64(ir->ir_start); |
540 | str->ir_length = cpu_to_be64(ir->ir_length); | 539 | str->ir_length = cpu_to_be64(ir->ir_length); |
541 | } | 540 | } |
542 | 541 | ||
543 | static int pick_formal_ino_1(struct gfs2_sbd *sdp, u64 *formal_ino) | 542 | static int pick_formal_ino_1(struct gfs2_sbd *sdp, u64 *formal_ino) |
544 | { | 543 | { |
545 | struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode); | 544 | struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode); |
546 | struct buffer_head *bh; | 545 | struct buffer_head *bh; |
547 | struct gfs2_inum_range_host ir; | 546 | struct gfs2_inum_range_host ir; |
548 | int error; | 547 | int error; |
549 | 548 | ||
550 | error = gfs2_trans_begin(sdp, RES_DINODE, 0); | 549 | error = gfs2_trans_begin(sdp, RES_DINODE, 0); |
551 | if (error) | 550 | if (error) |
552 | return error; | 551 | return error; |
553 | mutex_lock(&sdp->sd_inum_mutex); | 552 | mutex_lock(&sdp->sd_inum_mutex); |
554 | 553 | ||
555 | error = gfs2_meta_inode_buffer(ip, &bh); | 554 | error = gfs2_meta_inode_buffer(ip, &bh); |
556 | if (error) { | 555 | if (error) { |
557 | mutex_unlock(&sdp->sd_inum_mutex); | 556 | mutex_unlock(&sdp->sd_inum_mutex); |
558 | gfs2_trans_end(sdp); | 557 | gfs2_trans_end(sdp); |
559 | return error; | 558 | return error; |
560 | } | 559 | } |
561 | 560 | ||
562 | gfs2_inum_range_in(&ir, bh->b_data + sizeof(struct gfs2_dinode)); | 561 | gfs2_inum_range_in(&ir, bh->b_data + sizeof(struct gfs2_dinode)); |
563 | 562 | ||
564 | if (ir.ir_length) { | 563 | if (ir.ir_length) { |
565 | *formal_ino = ir.ir_start++; | 564 | *formal_ino = ir.ir_start++; |
566 | ir.ir_length--; | 565 | ir.ir_length--; |
567 | gfs2_trans_add_bh(ip->i_gl, bh, 1); | 566 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
568 | gfs2_inum_range_out(&ir, | 567 | gfs2_inum_range_out(&ir, |
569 | bh->b_data + sizeof(struct gfs2_dinode)); | 568 | bh->b_data + sizeof(struct gfs2_dinode)); |
570 | brelse(bh); | 569 | brelse(bh); |
571 | mutex_unlock(&sdp->sd_inum_mutex); | 570 | mutex_unlock(&sdp->sd_inum_mutex); |
572 | gfs2_trans_end(sdp); | 571 | gfs2_trans_end(sdp); |
573 | return 0; | 572 | return 0; |
574 | } | 573 | } |
575 | 574 | ||
576 | brelse(bh); | 575 | brelse(bh); |
577 | 576 | ||
578 | mutex_unlock(&sdp->sd_inum_mutex); | 577 | mutex_unlock(&sdp->sd_inum_mutex); |
579 | gfs2_trans_end(sdp); | 578 | gfs2_trans_end(sdp); |
580 | 579 | ||
581 | return 1; | 580 | return 1; |
582 | } | 581 | } |
583 | 582 | ||
584 | static int pick_formal_ino_2(struct gfs2_sbd *sdp, u64 *formal_ino) | 583 | static int pick_formal_ino_2(struct gfs2_sbd *sdp, u64 *formal_ino) |
585 | { | 584 | { |
586 | struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode); | 585 | struct gfs2_inode *ip = GFS2_I(sdp->sd_ir_inode); |
587 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_inum_inode); | 586 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_inum_inode); |
588 | struct gfs2_holder gh; | 587 | struct gfs2_holder gh; |
589 | struct buffer_head *bh; | 588 | struct buffer_head *bh; |
590 | struct gfs2_inum_range_host ir; | 589 | struct gfs2_inum_range_host ir; |
591 | int error; | 590 | int error; |
592 | 591 | ||
593 | error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); | 592 | error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
594 | if (error) | 593 | if (error) |
595 | return error; | 594 | return error; |
596 | 595 | ||
597 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0); | 596 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0); |
598 | if (error) | 597 | if (error) |
599 | goto out; | 598 | goto out; |
600 | mutex_lock(&sdp->sd_inum_mutex); | 599 | mutex_lock(&sdp->sd_inum_mutex); |
601 | 600 | ||
602 | error = gfs2_meta_inode_buffer(ip, &bh); | 601 | error = gfs2_meta_inode_buffer(ip, &bh); |
603 | if (error) | 602 | if (error) |
604 | goto out_end_trans; | 603 | goto out_end_trans; |
605 | 604 | ||
606 | gfs2_inum_range_in(&ir, bh->b_data + sizeof(struct gfs2_dinode)); | 605 | gfs2_inum_range_in(&ir, bh->b_data + sizeof(struct gfs2_dinode)); |
607 | 606 | ||
608 | if (!ir.ir_length) { | 607 | if (!ir.ir_length) { |
609 | struct buffer_head *m_bh; | 608 | struct buffer_head *m_bh; |
610 | u64 x, y; | 609 | u64 x, y; |
611 | __be64 z; | 610 | __be64 z; |
612 | 611 | ||
613 | error = gfs2_meta_inode_buffer(m_ip, &m_bh); | 612 | error = gfs2_meta_inode_buffer(m_ip, &m_bh); |
614 | if (error) | 613 | if (error) |
615 | goto out_brelse; | 614 | goto out_brelse; |
616 | 615 | ||
617 | z = *(__be64 *)(m_bh->b_data + sizeof(struct gfs2_dinode)); | 616 | z = *(__be64 *)(m_bh->b_data + sizeof(struct gfs2_dinode)); |
618 | x = y = be64_to_cpu(z); | 617 | x = y = be64_to_cpu(z); |
619 | ir.ir_start = x; | 618 | ir.ir_start = x; |
620 | ir.ir_length = GFS2_INUM_QUANTUM; | 619 | ir.ir_length = GFS2_INUM_QUANTUM; |
621 | x += GFS2_INUM_QUANTUM; | 620 | x += GFS2_INUM_QUANTUM; |
622 | if (x < y) | 621 | if (x < y) |
623 | gfs2_consist_inode(m_ip); | 622 | gfs2_consist_inode(m_ip); |
624 | z = cpu_to_be64(x); | 623 | z = cpu_to_be64(x); |
625 | gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1); | 624 | gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1); |
626 | *(__be64 *)(m_bh->b_data + sizeof(struct gfs2_dinode)) = z; | 625 | *(__be64 *)(m_bh->b_data + sizeof(struct gfs2_dinode)) = z; |
627 | 626 | ||
628 | brelse(m_bh); | 627 | brelse(m_bh); |
629 | } | 628 | } |
630 | 629 | ||
631 | *formal_ino = ir.ir_start++; | 630 | *formal_ino = ir.ir_start++; |
632 | ir.ir_length--; | 631 | ir.ir_length--; |
633 | 632 | ||
634 | gfs2_trans_add_bh(ip->i_gl, bh, 1); | 633 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
635 | gfs2_inum_range_out(&ir, bh->b_data + sizeof(struct gfs2_dinode)); | 634 | gfs2_inum_range_out(&ir, bh->b_data + sizeof(struct gfs2_dinode)); |
636 | 635 | ||
637 | out_brelse: | 636 | out_brelse: |
638 | brelse(bh); | 637 | brelse(bh); |
639 | out_end_trans: | 638 | out_end_trans: |
640 | mutex_unlock(&sdp->sd_inum_mutex); | 639 | mutex_unlock(&sdp->sd_inum_mutex); |
641 | gfs2_trans_end(sdp); | 640 | gfs2_trans_end(sdp); |
642 | out: | 641 | out: |
643 | gfs2_glock_dq_uninit(&gh); | 642 | gfs2_glock_dq_uninit(&gh); |
644 | return error; | 643 | return error; |
645 | } | 644 | } |
646 | 645 | ||
647 | static int pick_formal_ino(struct gfs2_sbd *sdp, u64 *inum) | 646 | static int pick_formal_ino(struct gfs2_sbd *sdp, u64 *inum) |
648 | { | 647 | { |
649 | int error; | 648 | int error; |
650 | 649 | ||
651 | error = pick_formal_ino_1(sdp, inum); | 650 | error = pick_formal_ino_1(sdp, inum); |
652 | if (error <= 0) | 651 | if (error <= 0) |
653 | return error; | 652 | return error; |
654 | 653 | ||
655 | error = pick_formal_ino_2(sdp, inum); | 654 | error = pick_formal_ino_2(sdp, inum); |
656 | 655 | ||
657 | return error; | 656 | return error; |
658 | } | 657 | } |
659 | 658 | ||
660 | /** | 659 | /** |
661 | * create_ok - OK to create a new on-disk inode here? | 660 | * create_ok - OK to create a new on-disk inode here? |
662 | * @dip: Directory in which dinode is to be created | 661 | * @dip: Directory in which dinode is to be created |
663 | * @name: Name of new dinode | 662 | * @name: Name of new dinode |
664 | * @mode: | 663 | * @mode: |
665 | * | 664 | * |
666 | * Returns: errno | 665 | * Returns: errno |
667 | */ | 666 | */ |
668 | 667 | ||
669 | static int create_ok(struct gfs2_inode *dip, const struct qstr *name, | 668 | static int create_ok(struct gfs2_inode *dip, const struct qstr *name, |
670 | unsigned int mode) | 669 | unsigned int mode) |
671 | { | 670 | { |
672 | int error; | 671 | int error; |
673 | 672 | ||
674 | error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC); | 673 | error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC); |
675 | if (error) | 674 | if (error) |
676 | return error; | 675 | return error; |
677 | 676 | ||
678 | /* Don't create entries in an unlinked directory */ | 677 | /* Don't create entries in an unlinked directory */ |
679 | if (!dip->i_inode.i_nlink) | 678 | if (!dip->i_inode.i_nlink) |
680 | return -EPERM; | 679 | return -EPERM; |
681 | 680 | ||
682 | error = gfs2_dir_check(&dip->i_inode, name, NULL); | 681 | error = gfs2_dir_check(&dip->i_inode, name, NULL); |
683 | switch (error) { | 682 | switch (error) { |
684 | case -ENOENT: | 683 | case -ENOENT: |
685 | error = 0; | 684 | error = 0; |
686 | break; | 685 | break; |
687 | case 0: | 686 | case 0: |
688 | return -EEXIST; | 687 | return -EEXIST; |
689 | default: | 688 | default: |
690 | return error; | 689 | return error; |
691 | } | 690 | } |
692 | 691 | ||
693 | if (dip->i_di.di_entries == (u32)-1) | 692 | if (dip->i_di.di_entries == (u32)-1) |
694 | return -EFBIG; | 693 | return -EFBIG; |
695 | if (S_ISDIR(mode) && dip->i_inode.i_nlink == (u32)-1) | 694 | if (S_ISDIR(mode) && dip->i_inode.i_nlink == (u32)-1) |
696 | return -EMLINK; | 695 | return -EMLINK; |
697 | 696 | ||
698 | return 0; | 697 | return 0; |
699 | } | 698 | } |
700 | 699 | ||
701 | static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode, | 700 | static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode, |
702 | unsigned int *uid, unsigned int *gid) | 701 | unsigned int *uid, unsigned int *gid) |
703 | { | 702 | { |
704 | if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir && | 703 | if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir && |
705 | (dip->i_inode.i_mode & S_ISUID) && dip->i_inode.i_uid) { | 704 | (dip->i_inode.i_mode & S_ISUID) && dip->i_inode.i_uid) { |
706 | if (S_ISDIR(*mode)) | 705 | if (S_ISDIR(*mode)) |
707 | *mode |= S_ISUID; | 706 | *mode |= S_ISUID; |
708 | else if (dip->i_inode.i_uid != current_fsuid()) | 707 | else if (dip->i_inode.i_uid != current_fsuid()) |
709 | *mode &= ~07111; | 708 | *mode &= ~07111; |
710 | *uid = dip->i_inode.i_uid; | 709 | *uid = dip->i_inode.i_uid; |
711 | } else | 710 | } else |
712 | *uid = current_fsuid(); | 711 | *uid = current_fsuid(); |
713 | 712 | ||
714 | if (dip->i_inode.i_mode & S_ISGID) { | 713 | if (dip->i_inode.i_mode & S_ISGID) { |
715 | if (S_ISDIR(*mode)) | 714 | if (S_ISDIR(*mode)) |
716 | *mode |= S_ISGID; | 715 | *mode |= S_ISGID; |
717 | *gid = dip->i_inode.i_gid; | 716 | *gid = dip->i_inode.i_gid; |
718 | } else | 717 | } else |
719 | *gid = current_fsgid(); | 718 | *gid = current_fsgid(); |
720 | } | 719 | } |
721 | 720 | ||
722 | static int alloc_dinode(struct gfs2_inode *dip, u64 *no_addr, u64 *generation) | 721 | static int alloc_dinode(struct gfs2_inode *dip, u64 *no_addr, u64 *generation) |
723 | { | 722 | { |
724 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); | 723 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); |
725 | int error; | 724 | int error; |
726 | 725 | ||
727 | if (gfs2_alloc_get(dip) == NULL) | 726 | if (gfs2_alloc_get(dip) == NULL) |
728 | return -ENOMEM; | 727 | return -ENOMEM; |
729 | 728 | ||
730 | dip->i_alloc->al_requested = RES_DINODE; | 729 | dip->i_alloc->al_requested = RES_DINODE; |
731 | error = gfs2_inplace_reserve(dip); | 730 | error = gfs2_inplace_reserve(dip); |
732 | if (error) | 731 | if (error) |
733 | goto out; | 732 | goto out; |
734 | 733 | ||
735 | error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS, 0); | 734 | error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS, 0); |
736 | if (error) | 735 | if (error) |
737 | goto out_ipreserv; | 736 | goto out_ipreserv; |
738 | 737 | ||
739 | *no_addr = gfs2_alloc_di(dip, generation); | 738 | *no_addr = gfs2_alloc_di(dip, generation); |
740 | 739 | ||
741 | gfs2_trans_end(sdp); | 740 | gfs2_trans_end(sdp); |
742 | 741 | ||
743 | out_ipreserv: | 742 | out_ipreserv: |
744 | gfs2_inplace_release(dip); | 743 | gfs2_inplace_release(dip); |
745 | out: | 744 | out: |
746 | gfs2_alloc_put(dip); | 745 | gfs2_alloc_put(dip); |
747 | return error; | 746 | return error; |
748 | } | 747 | } |
749 | 748 | ||
750 | /** | 749 | /** |
751 | * init_dinode - Fill in a new dinode structure | 750 | * init_dinode - Fill in a new dinode structure |
752 | * @dip: the directory this inode is being created in | 751 | * @dip: the directory this inode is being created in |
753 | * @gl: The glock covering the new inode | 752 | * @gl: The glock covering the new inode |
754 | * @inum: the inode number | 753 | * @inum: the inode number |
755 | * @mode: the file permissions | 754 | * @mode: the file permissions |
756 | * @uid: | 755 | * @uid: |
757 | * @gid: | 756 | * @gid: |
758 | * | 757 | * |
759 | */ | 758 | */ |
760 | 759 | ||
761 | static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, | 760 | static void init_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, |
762 | const struct gfs2_inum_host *inum, unsigned int mode, | 761 | const struct gfs2_inum_host *inum, unsigned int mode, |
763 | unsigned int uid, unsigned int gid, | 762 | unsigned int uid, unsigned int gid, |
764 | const u64 *generation, dev_t dev, struct buffer_head **bhp) | 763 | const u64 *generation, dev_t dev, struct buffer_head **bhp) |
765 | { | 764 | { |
766 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); | 765 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); |
767 | struct gfs2_dinode *di; | 766 | struct gfs2_dinode *di; |
768 | struct buffer_head *dibh; | 767 | struct buffer_head *dibh; |
769 | struct timespec tv = CURRENT_TIME; | 768 | struct timespec tv = CURRENT_TIME; |
770 | 769 | ||
771 | dibh = gfs2_meta_new(gl, inum->no_addr); | 770 | dibh = gfs2_meta_new(gl, inum->no_addr); |
772 | gfs2_trans_add_bh(gl, dibh, 1); | 771 | gfs2_trans_add_bh(gl, dibh, 1); |
773 | gfs2_metatype_set(dibh, GFS2_METATYPE_DI, GFS2_FORMAT_DI); | 772 | gfs2_metatype_set(dibh, GFS2_METATYPE_DI, GFS2_FORMAT_DI); |
774 | gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); | 773 | gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode)); |
775 | di = (struct gfs2_dinode *)dibh->b_data; | 774 | di = (struct gfs2_dinode *)dibh->b_data; |
776 | 775 | ||
777 | di->di_num.no_formal_ino = cpu_to_be64(inum->no_formal_ino); | 776 | di->di_num.no_formal_ino = cpu_to_be64(inum->no_formal_ino); |
778 | di->di_num.no_addr = cpu_to_be64(inum->no_addr); | 777 | di->di_num.no_addr = cpu_to_be64(inum->no_addr); |
779 | di->di_mode = cpu_to_be32(mode); | 778 | di->di_mode = cpu_to_be32(mode); |
780 | di->di_uid = cpu_to_be32(uid); | 779 | di->di_uid = cpu_to_be32(uid); |
781 | di->di_gid = cpu_to_be32(gid); | 780 | di->di_gid = cpu_to_be32(gid); |
782 | di->di_nlink = 0; | 781 | di->di_nlink = 0; |
783 | di->di_size = 0; | 782 | di->di_size = 0; |
784 | di->di_blocks = cpu_to_be64(1); | 783 | di->di_blocks = cpu_to_be64(1); |
785 | di->di_atime = di->di_mtime = di->di_ctime = cpu_to_be64(tv.tv_sec); | 784 | di->di_atime = di->di_mtime = di->di_ctime = cpu_to_be64(tv.tv_sec); |
786 | di->di_major = cpu_to_be32(MAJOR(dev)); | 785 | di->di_major = cpu_to_be32(MAJOR(dev)); |
787 | di->di_minor = cpu_to_be32(MINOR(dev)); | 786 | di->di_minor = cpu_to_be32(MINOR(dev)); |
788 | di->di_goal_meta = di->di_goal_data = cpu_to_be64(inum->no_addr); | 787 | di->di_goal_meta = di->di_goal_data = cpu_to_be64(inum->no_addr); |
789 | di->di_generation = cpu_to_be64(*generation); | 788 | di->di_generation = cpu_to_be64(*generation); |
790 | di->di_flags = 0; | 789 | di->di_flags = 0; |
791 | 790 | ||
792 | if (S_ISREG(mode)) { | 791 | if (S_ISREG(mode)) { |
793 | if ((dip->i_di.di_flags & GFS2_DIF_INHERIT_JDATA) || | 792 | if ((dip->i_di.di_flags & GFS2_DIF_INHERIT_JDATA) || |
794 | gfs2_tune_get(sdp, gt_new_files_jdata)) | 793 | gfs2_tune_get(sdp, gt_new_files_jdata)) |
795 | di->di_flags |= cpu_to_be32(GFS2_DIF_JDATA); | 794 | di->di_flags |= cpu_to_be32(GFS2_DIF_JDATA); |
796 | } else if (S_ISDIR(mode)) { | 795 | } else if (S_ISDIR(mode)) { |
797 | di->di_flags |= cpu_to_be32(dip->i_di.di_flags & | 796 | di->di_flags |= cpu_to_be32(dip->i_di.di_flags & |
798 | GFS2_DIF_INHERIT_JDATA); | 797 | GFS2_DIF_INHERIT_JDATA); |
799 | } | 798 | } |
800 | 799 | ||
801 | di->__pad1 = 0; | 800 | di->__pad1 = 0; |
802 | di->di_payload_format = cpu_to_be32(S_ISDIR(mode) ? GFS2_FORMAT_DE : 0); | 801 | di->di_payload_format = cpu_to_be32(S_ISDIR(mode) ? GFS2_FORMAT_DE : 0); |
803 | di->di_height = 0; | 802 | di->di_height = 0; |
804 | di->__pad2 = 0; | 803 | di->__pad2 = 0; |
805 | di->__pad3 = 0; | 804 | di->__pad3 = 0; |
806 | di->di_depth = 0; | 805 | di->di_depth = 0; |
807 | di->di_entries = 0; | 806 | di->di_entries = 0; |
808 | memset(&di->__pad4, 0, sizeof(di->__pad4)); | 807 | memset(&di->__pad4, 0, sizeof(di->__pad4)); |
809 | di->di_eattr = 0; | 808 | di->di_eattr = 0; |
810 | di->di_atime_nsec = cpu_to_be32(tv.tv_nsec); | 809 | di->di_atime_nsec = cpu_to_be32(tv.tv_nsec); |
811 | di->di_mtime_nsec = cpu_to_be32(tv.tv_nsec); | 810 | di->di_mtime_nsec = cpu_to_be32(tv.tv_nsec); |
812 | di->di_ctime_nsec = cpu_to_be32(tv.tv_nsec); | 811 | di->di_ctime_nsec = cpu_to_be32(tv.tv_nsec); |
813 | memset(&di->di_reserved, 0, sizeof(di->di_reserved)); | 812 | memset(&di->di_reserved, 0, sizeof(di->di_reserved)); |
814 | 813 | ||
815 | set_buffer_uptodate(dibh); | 814 | set_buffer_uptodate(dibh); |
816 | 815 | ||
817 | *bhp = dibh; | 816 | *bhp = dibh; |
818 | } | 817 | } |
819 | 818 | ||
820 | static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, | 819 | static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl, |
821 | unsigned int mode, const struct gfs2_inum_host *inum, | 820 | unsigned int mode, const struct gfs2_inum_host *inum, |
822 | const u64 *generation, dev_t dev, struct buffer_head **bhp) | 821 | const u64 *generation, dev_t dev, struct buffer_head **bhp) |
823 | { | 822 | { |
824 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); | 823 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); |
825 | unsigned int uid, gid; | 824 | unsigned int uid, gid; |
826 | int error; | 825 | int error; |
827 | 826 | ||
828 | munge_mode_uid_gid(dip, &mode, &uid, &gid); | 827 | munge_mode_uid_gid(dip, &mode, &uid, &gid); |
829 | if (!gfs2_alloc_get(dip)) | 828 | if (!gfs2_alloc_get(dip)) |
830 | return -ENOMEM; | 829 | return -ENOMEM; |
831 | 830 | ||
832 | error = gfs2_quota_lock(dip, uid, gid); | 831 | error = gfs2_quota_lock(dip, uid, gid); |
833 | if (error) | 832 | if (error) |
834 | goto out; | 833 | goto out; |
835 | 834 | ||
836 | error = gfs2_quota_check(dip, uid, gid); | 835 | error = gfs2_quota_check(dip, uid, gid); |
837 | if (error) | 836 | if (error) |
838 | goto out_quota; | 837 | goto out_quota; |
839 | 838 | ||
840 | error = gfs2_trans_begin(sdp, RES_DINODE + RES_QUOTA, 0); | 839 | error = gfs2_trans_begin(sdp, RES_DINODE + RES_QUOTA, 0); |
841 | if (error) | 840 | if (error) |
842 | goto out_quota; | 841 | goto out_quota; |
843 | 842 | ||
844 | init_dinode(dip, gl, inum, mode, uid, gid, generation, dev, bhp); | 843 | init_dinode(dip, gl, inum, mode, uid, gid, generation, dev, bhp); |
845 | gfs2_quota_change(dip, +1, uid, gid); | 844 | gfs2_quota_change(dip, +1, uid, gid); |
846 | gfs2_trans_end(sdp); | 845 | gfs2_trans_end(sdp); |
847 | 846 | ||
848 | out_quota: | 847 | out_quota: |
849 | gfs2_quota_unlock(dip); | 848 | gfs2_quota_unlock(dip); |
850 | out: | 849 | out: |
851 | gfs2_alloc_put(dip); | 850 | gfs2_alloc_put(dip); |
852 | return error; | 851 | return error; |
853 | } | 852 | } |
854 | 853 | ||
855 | static int link_dinode(struct gfs2_inode *dip, const struct qstr *name, | 854 | static int link_dinode(struct gfs2_inode *dip, const struct qstr *name, |
856 | struct gfs2_inode *ip) | 855 | struct gfs2_inode *ip) |
857 | { | 856 | { |
858 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); | 857 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); |
859 | struct gfs2_alloc *al; | 858 | struct gfs2_alloc *al; |
860 | int alloc_required; | 859 | int alloc_required; |
861 | struct buffer_head *dibh; | 860 | struct buffer_head *dibh; |
862 | int error; | 861 | int error; |
863 | 862 | ||
864 | al = gfs2_alloc_get(dip); | 863 | al = gfs2_alloc_get(dip); |
865 | if (!al) | 864 | if (!al) |
866 | return -ENOMEM; | 865 | return -ENOMEM; |
867 | 866 | ||
868 | error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); | 867 | error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); |
869 | if (error) | 868 | if (error) |
870 | goto fail; | 869 | goto fail; |
871 | 870 | ||
872 | error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name); | 871 | error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name); |
873 | if (alloc_required < 0) | 872 | if (alloc_required < 0) |
874 | goto fail_quota_locks; | 873 | goto fail_quota_locks; |
875 | if (alloc_required) { | 874 | if (alloc_required) { |
876 | error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid); | 875 | error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid); |
877 | if (error) | 876 | if (error) |
878 | goto fail_quota_locks; | 877 | goto fail_quota_locks; |
879 | 878 | ||
880 | al->al_requested = sdp->sd_max_dirres; | 879 | al->al_requested = sdp->sd_max_dirres; |
881 | 880 | ||
882 | error = gfs2_inplace_reserve(dip); | 881 | error = gfs2_inplace_reserve(dip); |
883 | if (error) | 882 | if (error) |
884 | goto fail_quota_locks; | 883 | goto fail_quota_locks; |
885 | 884 | ||
886 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + | 885 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
887 | al->al_rgd->rd_length + | 886 | al->al_rgd->rd_length + |
888 | 2 * RES_DINODE + | 887 | 2 * RES_DINODE + |
889 | RES_STATFS + RES_QUOTA, 0); | 888 | RES_STATFS + RES_QUOTA, 0); |
890 | if (error) | 889 | if (error) |
891 | goto fail_ipreserv; | 890 | goto fail_ipreserv; |
892 | } else { | 891 | } else { |
893 | error = gfs2_trans_begin(sdp, RES_LEAF + 2 * RES_DINODE, 0); | 892 | error = gfs2_trans_begin(sdp, RES_LEAF + 2 * RES_DINODE, 0); |
894 | if (error) | 893 | if (error) |
895 | goto fail_quota_locks; | 894 | goto fail_quota_locks; |
896 | } | 895 | } |
897 | 896 | ||
898 | error = gfs2_dir_add(&dip->i_inode, name, ip, IF2DT(ip->i_inode.i_mode)); | 897 | error = gfs2_dir_add(&dip->i_inode, name, ip, IF2DT(ip->i_inode.i_mode)); |
899 | if (error) | 898 | if (error) |
900 | goto fail_end_trans; | 899 | goto fail_end_trans; |
901 | 900 | ||
902 | error = gfs2_meta_inode_buffer(ip, &dibh); | 901 | error = gfs2_meta_inode_buffer(ip, &dibh); |
903 | if (error) | 902 | if (error) |
904 | goto fail_end_trans; | 903 | goto fail_end_trans; |
905 | ip->i_inode.i_nlink = 1; | 904 | ip->i_inode.i_nlink = 1; |
906 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); | 905 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
907 | gfs2_dinode_out(ip, dibh->b_data); | 906 | gfs2_dinode_out(ip, dibh->b_data); |
908 | brelse(dibh); | 907 | brelse(dibh); |
909 | return 0; | 908 | return 0; |
910 | 909 | ||
911 | fail_end_trans: | 910 | fail_end_trans: |
912 | gfs2_trans_end(sdp); | 911 | gfs2_trans_end(sdp); |
913 | 912 | ||
914 | fail_ipreserv: | 913 | fail_ipreserv: |
915 | if (dip->i_alloc->al_rgd) | 914 | if (dip->i_alloc->al_rgd) |
916 | gfs2_inplace_release(dip); | 915 | gfs2_inplace_release(dip); |
917 | 916 | ||
918 | fail_quota_locks: | 917 | fail_quota_locks: |
919 | gfs2_quota_unlock(dip); | 918 | gfs2_quota_unlock(dip); |
920 | 919 | ||
921 | fail: | 920 | fail: |
922 | gfs2_alloc_put(dip); | 921 | gfs2_alloc_put(dip); |
923 | return error; | 922 | return error; |
924 | } | 923 | } |
925 | 924 | ||
926 | static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip) | 925 | static int gfs2_security_init(struct gfs2_inode *dip, struct gfs2_inode *ip) |
927 | { | 926 | { |
928 | int err; | 927 | int err; |
929 | size_t len; | 928 | size_t len; |
930 | void *value; | 929 | void *value; |
931 | char *name; | 930 | char *name; |
932 | struct gfs2_ea_request er; | 931 | struct gfs2_ea_request er; |
933 | 932 | ||
934 | err = security_inode_init_security(&ip->i_inode, &dip->i_inode, | 933 | err = security_inode_init_security(&ip->i_inode, &dip->i_inode, |
935 | &name, &value, &len); | 934 | &name, &value, &len); |
936 | 935 | ||
937 | if (err) { | 936 | if (err) { |
938 | if (err == -EOPNOTSUPP) | 937 | if (err == -EOPNOTSUPP) |
939 | return 0; | 938 | return 0; |
940 | return err; | 939 | return err; |
941 | } | 940 | } |
942 | 941 | ||
943 | memset(&er, 0, sizeof(struct gfs2_ea_request)); | 942 | memset(&er, 0, sizeof(struct gfs2_ea_request)); |
944 | 943 | ||
945 | er.er_type = GFS2_EATYPE_SECURITY; | 944 | er.er_type = GFS2_EATYPE_SECURITY; |
946 | er.er_name = name; | 945 | er.er_name = name; |
947 | er.er_data = value; | 946 | er.er_data = value; |
948 | er.er_name_len = strlen(name); | 947 | er.er_name_len = strlen(name); |
949 | er.er_data_len = len; | 948 | er.er_data_len = len; |
950 | 949 | ||
951 | err = gfs2_ea_set_i(ip, &er); | 950 | err = gfs2_ea_set_i(ip, &er); |
952 | 951 | ||
953 | kfree(value); | 952 | kfree(value); |
954 | kfree(name); | 953 | kfree(name); |
955 | 954 | ||
956 | return err; | 955 | return err; |
957 | } | 956 | } |
958 | 957 | ||
959 | /** | 958 | /** |
960 | * gfs2_createi - Create a new inode | 959 | * gfs2_createi - Create a new inode |
961 | * @ghs: An array of two holders | 960 | * @ghs: An array of two holders |
962 | * @name: The name of the new file | 961 | * @name: The name of the new file |
963 | * @mode: the permissions on the new inode | 962 | * @mode: the permissions on the new inode |
964 | * | 963 | * |
965 | * @ghs[0] is an initialized holder for the directory | 964 | * @ghs[0] is an initialized holder for the directory |
966 | * @ghs[1] is the holder for the inode lock | 965 | * @ghs[1] is the holder for the inode lock |
967 | * | 966 | * |
968 | * If the return value is not NULL, the glocks on both the directory and the new | 967 | * If the return value is not NULL, the glocks on both the directory and the new |
969 | * file are held. A transaction has been started and an inplace reservation | 968 | * file are held. A transaction has been started and an inplace reservation |
970 | * is held, as well. | 969 | * is held, as well. |
971 | * | 970 | * |
972 | * Returns: An inode | 971 | * Returns: An inode |
973 | */ | 972 | */ |
974 | 973 | ||
975 | struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, | 974 | struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, |
976 | unsigned int mode, dev_t dev) | 975 | unsigned int mode, dev_t dev) |
977 | { | 976 | { |
978 | struct inode *inode = NULL; | 977 | struct inode *inode = NULL; |
979 | struct gfs2_inode *dip = ghs->gh_gl->gl_object; | 978 | struct gfs2_inode *dip = ghs->gh_gl->gl_object; |
980 | struct inode *dir = &dip->i_inode; | 979 | struct inode *dir = &dip->i_inode; |
981 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); | 980 | struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); |
982 | struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 }; | 981 | struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 }; |
983 | int error; | 982 | int error; |
984 | u64 generation; | 983 | u64 generation; |
985 | struct buffer_head *bh = NULL; | 984 | struct buffer_head *bh = NULL; |
986 | 985 | ||
987 | if (!name->len || name->len > GFS2_FNAMESIZE) | 986 | if (!name->len || name->len > GFS2_FNAMESIZE) |
988 | return ERR_PTR(-ENAMETOOLONG); | 987 | return ERR_PTR(-ENAMETOOLONG); |
989 | 988 | ||
990 | gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs); | 989 | gfs2_holder_reinit(LM_ST_EXCLUSIVE, 0, ghs); |
991 | error = gfs2_glock_nq(ghs); | 990 | error = gfs2_glock_nq(ghs); |
992 | if (error) | 991 | if (error) |
993 | goto fail; | 992 | goto fail; |
994 | 993 | ||
995 | error = create_ok(dip, name, mode); | 994 | error = create_ok(dip, name, mode); |
996 | if (error) | 995 | if (error) |
997 | goto fail_gunlock; | 996 | goto fail_gunlock; |
998 | 997 | ||
999 | error = pick_formal_ino(sdp, &inum.no_formal_ino); | 998 | error = pick_formal_ino(sdp, &inum.no_formal_ino); |
1000 | if (error) | 999 | if (error) |
1001 | goto fail_gunlock; | 1000 | goto fail_gunlock; |
1002 | 1001 | ||
1003 | error = alloc_dinode(dip, &inum.no_addr, &generation); | 1002 | error = alloc_dinode(dip, &inum.no_addr, &generation); |
1004 | if (error) | 1003 | if (error) |
1005 | goto fail_gunlock; | 1004 | goto fail_gunlock; |
1006 | 1005 | ||
1007 | error = gfs2_glock_nq_num(sdp, inum.no_addr, &gfs2_inode_glops, | 1006 | error = gfs2_glock_nq_num(sdp, inum.no_addr, &gfs2_inode_glops, |
1008 | LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1); | 1007 | LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1); |
1009 | if (error) | 1008 | if (error) |
1010 | goto fail_gunlock; | 1009 | goto fail_gunlock; |
1011 | 1010 | ||
1012 | error = make_dinode(dip, ghs[1].gh_gl, mode, &inum, &generation, dev, &bh); | 1011 | error = make_dinode(dip, ghs[1].gh_gl, mode, &inum, &generation, dev, &bh); |
1013 | if (error) | 1012 | if (error) |
1014 | goto fail_gunlock2; | 1013 | goto fail_gunlock2; |
1015 | 1014 | ||
1016 | inode = gfs2_inode_lookup(dir->i_sb, IF2DT(mode), | 1015 | inode = gfs2_inode_lookup(dir->i_sb, IF2DT(mode), |
1017 | inum.no_addr, | 1016 | inum.no_addr, |
1018 | inum.no_formal_ino, 0); | 1017 | inum.no_formal_ino, 0); |
1019 | if (IS_ERR(inode)) | 1018 | if (IS_ERR(inode)) |
1020 | goto fail_gunlock2; | 1019 | goto fail_gunlock2; |
1021 | 1020 | ||
1022 | error = gfs2_inode_refresh(GFS2_I(inode)); | 1021 | error = gfs2_inode_refresh(GFS2_I(inode)); |
1023 | if (error) | 1022 | if (error) |
1024 | goto fail_gunlock2; | 1023 | goto fail_gunlock2; |
1025 | 1024 | ||
1026 | error = gfs2_acl_create(dip, GFS2_I(inode)); | 1025 | error = gfs2_acl_create(dip, GFS2_I(inode)); |
1027 | if (error) | 1026 | if (error) |
1028 | goto fail_gunlock2; | 1027 | goto fail_gunlock2; |
1029 | 1028 | ||
1030 | error = gfs2_security_init(dip, GFS2_I(inode)); | 1029 | error = gfs2_security_init(dip, GFS2_I(inode)); |
1031 | if (error) | 1030 | if (error) |
1032 | goto fail_gunlock2; | 1031 | goto fail_gunlock2; |
1033 | 1032 | ||
1034 | error = link_dinode(dip, name, GFS2_I(inode)); | 1033 | error = link_dinode(dip, name, GFS2_I(inode)); |
1035 | if (error) | 1034 | if (error) |
1036 | goto fail_gunlock2; | 1035 | goto fail_gunlock2; |
1037 | 1036 | ||
1038 | if (bh) | 1037 | if (bh) |
1039 | brelse(bh); | 1038 | brelse(bh); |
1040 | return inode; | 1039 | return inode; |
1041 | 1040 | ||
1042 | fail_gunlock2: | 1041 | fail_gunlock2: |
1043 | gfs2_glock_dq_uninit(ghs + 1); | 1042 | gfs2_glock_dq_uninit(ghs + 1); |
1044 | if (inode && !IS_ERR(inode)) | 1043 | if (inode && !IS_ERR(inode)) |
1045 | iput(inode); | 1044 | iput(inode); |
1046 | fail_gunlock: | 1045 | fail_gunlock: |
1047 | gfs2_glock_dq(ghs); | 1046 | gfs2_glock_dq(ghs); |
1048 | fail: | 1047 | fail: |
1049 | if (bh) | 1048 | if (bh) |
1050 | brelse(bh); | 1049 | brelse(bh); |
1051 | return ERR_PTR(error); | 1050 | return ERR_PTR(error); |
1052 | } | 1051 | } |
1053 | 1052 | ||
1054 | /** | 1053 | /** |
1055 | * gfs2_rmdiri - Remove a directory | 1054 | * gfs2_rmdiri - Remove a directory |
1056 | * @dip: The parent directory of the directory to be removed | 1055 | * @dip: The parent directory of the directory to be removed |
1057 | * @name: The name of the directory to be removed | 1056 | * @name: The name of the directory to be removed |
1058 | * @ip: The GFS2 inode of the directory to be removed | 1057 | * @ip: The GFS2 inode of the directory to be removed |
1059 | * | 1058 | * |
1060 | * Assumes Glocks on dip and ip are held | 1059 | * Assumes Glocks on dip and ip are held |
1061 | * | 1060 | * |
1062 | * Returns: errno | 1061 | * Returns: errno |
1063 | */ | 1062 | */ |
1064 | 1063 | ||
1065 | int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name, | 1064 | int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name, |
1066 | struct gfs2_inode *ip) | 1065 | struct gfs2_inode *ip) |
1067 | { | 1066 | { |
1068 | struct qstr dotname; | 1067 | struct qstr dotname; |
1069 | int error; | 1068 | int error; |
1070 | 1069 | ||
1071 | if (ip->i_di.di_entries != 2) { | 1070 | if (ip->i_di.di_entries != 2) { |
1072 | if (gfs2_consist_inode(ip)) | 1071 | if (gfs2_consist_inode(ip)) |
1073 | gfs2_dinode_print(ip); | 1072 | gfs2_dinode_print(ip); |
1074 | return -EIO; | 1073 | return -EIO; |
1075 | } | 1074 | } |
1076 | 1075 | ||
1077 | error = gfs2_dir_del(dip, name); | 1076 | error = gfs2_dir_del(dip, name); |
1078 | if (error) | 1077 | if (error) |
1079 | return error; | 1078 | return error; |
1080 | 1079 | ||
1081 | error = gfs2_change_nlink(dip, -1); | 1080 | error = gfs2_change_nlink(dip, -1); |
1082 | if (error) | 1081 | if (error) |
1083 | return error; | 1082 | return error; |
1084 | 1083 | ||
1085 | gfs2_str2qstr(&dotname, "."); | 1084 | gfs2_str2qstr(&dotname, "."); |
1086 | error = gfs2_dir_del(ip, &dotname); | 1085 | error = gfs2_dir_del(ip, &dotname); |
1087 | if (error) | 1086 | if (error) |
1088 | return error; | 1087 | return error; |
1089 | 1088 | ||
1090 | gfs2_str2qstr(&dotname, ".."); | 1089 | gfs2_str2qstr(&dotname, ".."); |
1091 | error = gfs2_dir_del(ip, &dotname); | 1090 | error = gfs2_dir_del(ip, &dotname); |
1092 | if (error) | 1091 | if (error) |
1093 | return error; | 1092 | return error; |
1094 | 1093 | ||
1095 | /* It looks odd, but it really should be done twice */ | 1094 | /* It looks odd, but it really should be done twice */ |
1096 | error = gfs2_change_nlink(ip, -1); | 1095 | error = gfs2_change_nlink(ip, -1); |
1097 | if (error) | 1096 | if (error) |
1098 | return error; | 1097 | return error; |
1099 | 1098 | ||
1100 | error = gfs2_change_nlink(ip, -1); | 1099 | error = gfs2_change_nlink(ip, -1); |
1101 | if (error) | 1100 | if (error) |
1102 | return error; | 1101 | return error; |
1103 | 1102 | ||
1104 | return error; | 1103 | return error; |
1105 | } | 1104 | } |
1106 | 1105 | ||
1107 | /* | 1106 | /* |
1108 | * gfs2_unlink_ok - check to see that a inode is still in a directory | 1107 | * gfs2_unlink_ok - check to see that a inode is still in a directory |
1109 | * @dip: the directory | 1108 | * @dip: the directory |
1110 | * @name: the name of the file | 1109 | * @name: the name of the file |
1111 | * @ip: the inode | 1110 | * @ip: the inode |
1112 | * | 1111 | * |
1113 | * Assumes that the lock on (at least) @dip is held. | 1112 | * Assumes that the lock on (at least) @dip is held. |
1114 | * | 1113 | * |
1115 | * Returns: 0 if the parent/child relationship is correct, errno if it isn't | 1114 | * Returns: 0 if the parent/child relationship is correct, errno if it isn't |
1116 | */ | 1115 | */ |
1117 | 1116 | ||
1118 | int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name, | 1117 | int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name, |
1119 | const struct gfs2_inode *ip) | 1118 | const struct gfs2_inode *ip) |
1120 | { | 1119 | { |
1121 | int error; | 1120 | int error; |
1122 | 1121 | ||
1123 | if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode)) | 1122 | if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode)) |
1124 | return -EPERM; | 1123 | return -EPERM; |
1125 | 1124 | ||
1126 | if ((dip->i_inode.i_mode & S_ISVTX) && | 1125 | if ((dip->i_inode.i_mode & S_ISVTX) && |
1127 | dip->i_inode.i_uid != current_fsuid() && | 1126 | dip->i_inode.i_uid != current_fsuid() && |
1128 | ip->i_inode.i_uid != current_fsuid() && !capable(CAP_FOWNER)) | 1127 | ip->i_inode.i_uid != current_fsuid() && !capable(CAP_FOWNER)) |
1129 | return -EPERM; | 1128 | return -EPERM; |
1130 | 1129 | ||
1131 | if (IS_APPEND(&dip->i_inode)) | 1130 | if (IS_APPEND(&dip->i_inode)) |
1132 | return -EPERM; | 1131 | return -EPERM; |
1133 | 1132 | ||
1134 | error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC); | 1133 | error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC); |
1135 | if (error) | 1134 | if (error) |
1136 | return error; | 1135 | return error; |
1137 | 1136 | ||
1138 | error = gfs2_dir_check(&dip->i_inode, name, ip); | 1137 | error = gfs2_dir_check(&dip->i_inode, name, ip); |
1139 | if (error) | 1138 | if (error) |
1140 | return error; | 1139 | return error; |
1141 | 1140 | ||
1142 | return 0; | 1141 | return 0; |
1143 | } | 1142 | } |
1144 | 1143 | ||
1145 | /** | 1144 | /** |
1146 | * gfs2_readlinki - return the contents of a symlink | 1145 | * gfs2_readlinki - return the contents of a symlink |
1147 | * @ip: the symlink's inode | 1146 | * @ip: the symlink's inode |
1148 | * @buf: a pointer to the buffer to be filled | 1147 | * @buf: a pointer to the buffer to be filled |
1149 | * @len: a pointer to the length of @buf | 1148 | * @len: a pointer to the length of @buf |
1150 | * | 1149 | * |
1151 | * If @buf is too small, a piece of memory is kmalloc()ed and needs | 1150 | * If @buf is too small, a piece of memory is kmalloc()ed and needs |
1152 | * to be freed by the caller. | 1151 | * to be freed by the caller. |
1153 | * | 1152 | * |
1154 | * Returns: errno | 1153 | * Returns: errno |
1155 | */ | 1154 | */ |
1156 | 1155 | ||
1157 | int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len) | 1156 | int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len) |
1158 | { | 1157 | { |
1159 | struct gfs2_holder i_gh; | 1158 | struct gfs2_holder i_gh; |
1160 | struct buffer_head *dibh; | 1159 | struct buffer_head *dibh; |
1161 | unsigned int x; | 1160 | unsigned int x; |
1162 | int error; | 1161 | int error; |
1163 | 1162 | ||
1164 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); | 1163 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); |
1165 | error = gfs2_glock_nq(&i_gh); | 1164 | error = gfs2_glock_nq(&i_gh); |
1166 | if (error) { | 1165 | if (error) { |
1167 | gfs2_holder_uninit(&i_gh); | 1166 | gfs2_holder_uninit(&i_gh); |
1168 | return error; | 1167 | return error; |
1169 | } | 1168 | } |
1170 | 1169 | ||
1171 | if (!ip->i_di.di_size) { | 1170 | if (!ip->i_di.di_size) { |
1172 | gfs2_consist_inode(ip); | 1171 | gfs2_consist_inode(ip); |
1173 | error = -EIO; | 1172 | error = -EIO; |
1174 | goto out; | 1173 | goto out; |
1175 | } | 1174 | } |
1176 | 1175 | ||
1177 | error = gfs2_meta_inode_buffer(ip, &dibh); | 1176 | error = gfs2_meta_inode_buffer(ip, &dibh); |
1178 | if (error) | 1177 | if (error) |
1179 | goto out; | 1178 | goto out; |
1180 | 1179 | ||
1181 | x = ip->i_di.di_size + 1; | 1180 | x = ip->i_di.di_size + 1; |
1182 | if (x > *len) { | 1181 | if (x > *len) { |
1183 | *buf = kmalloc(x, GFP_NOFS); | 1182 | *buf = kmalloc(x, GFP_NOFS); |
1184 | if (!*buf) { | 1183 | if (!*buf) { |
1185 | error = -ENOMEM; | 1184 | error = -ENOMEM; |
1186 | goto out_brelse; | 1185 | goto out_brelse; |
1187 | } | 1186 | } |
1188 | } | 1187 | } |
1189 | 1188 | ||
1190 | memcpy(*buf, dibh->b_data + sizeof(struct gfs2_dinode), x); | 1189 | memcpy(*buf, dibh->b_data + sizeof(struct gfs2_dinode), x); |
1191 | *len = x; | 1190 | *len = x; |
1192 | 1191 | ||
1193 | out_brelse: | 1192 | out_brelse: |
1194 | brelse(dibh); | 1193 | brelse(dibh); |
1195 | out: | 1194 | out: |
1196 | gfs2_glock_dq_uninit(&i_gh); | 1195 | gfs2_glock_dq_uninit(&i_gh); |
1197 | return error; | 1196 | return error; |
1198 | } | 1197 | } |
1199 | 1198 | ||
1200 | static int | 1199 | static int |
1201 | __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) | 1200 | __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) |
1202 | { | 1201 | { |
1203 | struct buffer_head *dibh; | 1202 | struct buffer_head *dibh; |
1204 | int error; | 1203 | int error; |
1205 | 1204 | ||
1206 | error = gfs2_meta_inode_buffer(ip, &dibh); | 1205 | error = gfs2_meta_inode_buffer(ip, &dibh); |
1207 | if (!error) { | 1206 | if (!error) { |
1208 | error = inode_setattr(&ip->i_inode, attr); | 1207 | error = inode_setattr(&ip->i_inode, attr); |
1209 | gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error); | 1208 | gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error); |
1210 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); | 1209 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
1211 | gfs2_dinode_out(ip, dibh->b_data); | 1210 | gfs2_dinode_out(ip, dibh->b_data); |
1212 | brelse(dibh); | 1211 | brelse(dibh); |
1213 | } | 1212 | } |
1214 | return error; | 1213 | return error; |
1215 | } | 1214 | } |
1216 | 1215 | ||
1217 | /** | 1216 | /** |
1218 | * gfs2_setattr_simple - | 1217 | * gfs2_setattr_simple - |
1219 | * @ip: | 1218 | * @ip: |
1220 | * @attr: | 1219 | * @attr: |
1221 | * | 1220 | * |
1222 | * Called with a reference on the vnode. | 1221 | * Called with a reference on the vnode. |
1223 | * | 1222 | * |
1224 | * Returns: errno | 1223 | * Returns: errno |
1225 | */ | 1224 | */ |
1226 | 1225 | ||
1227 | int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) | 1226 | int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr) |
1228 | { | 1227 | { |
1229 | int error; | 1228 | int error; |
1230 | 1229 | ||
1231 | if (current->journal_info) | 1230 | if (current->journal_info) |
1232 | return __gfs2_setattr_simple(ip, attr); | 1231 | return __gfs2_setattr_simple(ip, attr); |
1233 | 1232 | ||
1234 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE, 0); | 1233 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE, 0); |
1235 | if (error) | 1234 | if (error) |
1236 | return error; | 1235 | return error; |
1237 | 1236 | ||
1238 | error = __gfs2_setattr_simple(ip, attr); | 1237 | error = __gfs2_setattr_simple(ip, attr); |
1239 | gfs2_trans_end(GFS2_SB(&ip->i_inode)); | 1238 | gfs2_trans_end(GFS2_SB(&ip->i_inode)); |
1240 | return error; | 1239 | return error; |
1241 | } | 1240 | } |
1242 | 1241 | ||
1243 | void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf) | 1242 | void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf) |
1244 | { | 1243 | { |
1245 | const struct gfs2_dinode_host *di = &ip->i_di; | 1244 | const struct gfs2_dinode_host *di = &ip->i_di; |
1246 | struct gfs2_dinode *str = buf; | 1245 | struct gfs2_dinode *str = buf; |
1247 | 1246 | ||
1248 | str->di_header.mh_magic = cpu_to_be32(GFS2_MAGIC); | 1247 | str->di_header.mh_magic = cpu_to_be32(GFS2_MAGIC); |
1249 | str->di_header.mh_type = cpu_to_be32(GFS2_METATYPE_DI); | 1248 | str->di_header.mh_type = cpu_to_be32(GFS2_METATYPE_DI); |
1250 | str->di_header.__pad0 = 0; | 1249 | str->di_header.__pad0 = 0; |
1251 | str->di_header.mh_format = cpu_to_be32(GFS2_FORMAT_DI); | 1250 | str->di_header.mh_format = cpu_to_be32(GFS2_FORMAT_DI); |
1252 | str->di_header.__pad1 = 0; | 1251 | str->di_header.__pad1 = 0; |
1253 | str->di_num.no_addr = cpu_to_be64(ip->i_no_addr); | 1252 | str->di_num.no_addr = cpu_to_be64(ip->i_no_addr); |
1254 | str->di_num.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino); | 1253 | str->di_num.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino); |
1255 | str->di_mode = cpu_to_be32(ip->i_inode.i_mode); | 1254 | str->di_mode = cpu_to_be32(ip->i_inode.i_mode); |
1256 | str->di_uid = cpu_to_be32(ip->i_inode.i_uid); | 1255 | str->di_uid = cpu_to_be32(ip->i_inode.i_uid); |
1257 | str->di_gid = cpu_to_be32(ip->i_inode.i_gid); | 1256 | str->di_gid = cpu_to_be32(ip->i_inode.i_gid); |
1258 | str->di_nlink = cpu_to_be32(ip->i_inode.i_nlink); | 1257 | str->di_nlink = cpu_to_be32(ip->i_inode.i_nlink); |
1259 | str->di_size = cpu_to_be64(di->di_size); | 1258 | str->di_size = cpu_to_be64(di->di_size); |
1260 | str->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode)); | 1259 | str->di_blocks = cpu_to_be64(gfs2_get_inode_blocks(&ip->i_inode)); |
1261 | str->di_atime = cpu_to_be64(ip->i_inode.i_atime.tv_sec); | 1260 | str->di_atime = cpu_to_be64(ip->i_inode.i_atime.tv_sec); |
1262 | str->di_mtime = cpu_to_be64(ip->i_inode.i_mtime.tv_sec); | 1261 | str->di_mtime = cpu_to_be64(ip->i_inode.i_mtime.tv_sec); |
1263 | str->di_ctime = cpu_to_be64(ip->i_inode.i_ctime.tv_sec); | 1262 | str->di_ctime = cpu_to_be64(ip->i_inode.i_ctime.tv_sec); |
1264 | 1263 | ||
1265 | str->di_goal_meta = cpu_to_be64(ip->i_goal); | 1264 | str->di_goal_meta = cpu_to_be64(ip->i_goal); |
1266 | str->di_goal_data = cpu_to_be64(ip->i_goal); | 1265 | str->di_goal_data = cpu_to_be64(ip->i_goal); |
1267 | str->di_generation = cpu_to_be64(di->di_generation); | 1266 | str->di_generation = cpu_to_be64(di->di_generation); |
1268 | 1267 | ||
1269 | str->di_flags = cpu_to_be32(di->di_flags); | 1268 | str->di_flags = cpu_to_be32(di->di_flags); |
1270 | str->di_height = cpu_to_be16(ip->i_height); | 1269 | str->di_height = cpu_to_be16(ip->i_height); |
1271 | str->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) && | 1270 | str->di_payload_format = cpu_to_be32(S_ISDIR(ip->i_inode.i_mode) && |
1272 | !(ip->i_di.di_flags & GFS2_DIF_EXHASH) ? | 1271 | !(ip->i_di.di_flags & GFS2_DIF_EXHASH) ? |
1273 | GFS2_FORMAT_DE : 0); | 1272 | GFS2_FORMAT_DE : 0); |
1274 | str->di_depth = cpu_to_be16(ip->i_depth); | 1273 | str->di_depth = cpu_to_be16(ip->i_depth); |
1275 | str->di_entries = cpu_to_be32(di->di_entries); | 1274 | str->di_entries = cpu_to_be32(di->di_entries); |
1276 | 1275 | ||
1277 | str->di_eattr = cpu_to_be64(di->di_eattr); | 1276 | str->di_eattr = cpu_to_be64(di->di_eattr); |
1278 | str->di_atime_nsec = cpu_to_be32(ip->i_inode.i_atime.tv_nsec); | 1277 | str->di_atime_nsec = cpu_to_be32(ip->i_inode.i_atime.tv_nsec); |
1279 | str->di_mtime_nsec = cpu_to_be32(ip->i_inode.i_mtime.tv_nsec); | 1278 | str->di_mtime_nsec = cpu_to_be32(ip->i_inode.i_mtime.tv_nsec); |
1280 | str->di_ctime_nsec = cpu_to_be32(ip->i_inode.i_ctime.tv_nsec); | 1279 | str->di_ctime_nsec = cpu_to_be32(ip->i_inode.i_ctime.tv_nsec); |
1281 | } | 1280 | } |
1282 | 1281 | ||
1283 | void gfs2_dinode_print(const struct gfs2_inode *ip) | 1282 | void gfs2_dinode_print(const struct gfs2_inode *ip) |
1284 | { | 1283 | { |
1285 | const struct gfs2_dinode_host *di = &ip->i_di; | 1284 | const struct gfs2_dinode_host *di = &ip->i_di; |
1286 | 1285 | ||
1287 | printk(KERN_INFO " no_formal_ino = %llu\n", | 1286 | printk(KERN_INFO " no_formal_ino = %llu\n", |
1288 | (unsigned long long)ip->i_no_formal_ino); | 1287 | (unsigned long long)ip->i_no_formal_ino); |
1289 | printk(KERN_INFO " no_addr = %llu\n", | 1288 | printk(KERN_INFO " no_addr = %llu\n", |
1290 | (unsigned long long)ip->i_no_addr); | 1289 | (unsigned long long)ip->i_no_addr); |
1291 | printk(KERN_INFO " di_size = %llu\n", (unsigned long long)di->di_size); | 1290 | printk(KERN_INFO " di_size = %llu\n", (unsigned long long)di->di_size); |
1292 | printk(KERN_INFO " blocks = %llu\n", | 1291 | printk(KERN_INFO " blocks = %llu\n", |
1293 | (unsigned long long)gfs2_get_inode_blocks(&ip->i_inode)); | 1292 | (unsigned long long)gfs2_get_inode_blocks(&ip->i_inode)); |
1294 | printk(KERN_INFO " i_goal = %llu\n", | 1293 | printk(KERN_INFO " i_goal = %llu\n", |
1295 | (unsigned long long)ip->i_goal); | 1294 | (unsigned long long)ip->i_goal); |
1296 | printk(KERN_INFO " di_flags = 0x%.8X\n", di->di_flags); | 1295 | printk(KERN_INFO " di_flags = 0x%.8X\n", di->di_flags); |
1297 | printk(KERN_INFO " i_height = %u\n", ip->i_height); | 1296 | printk(KERN_INFO " i_height = %u\n", ip->i_height); |
1298 | printk(KERN_INFO " i_depth = %u\n", ip->i_depth); | 1297 | printk(KERN_INFO " i_depth = %u\n", ip->i_depth); |
1299 | printk(KERN_INFO " di_entries = %u\n", di->di_entries); | 1298 | printk(KERN_INFO " di_entries = %u\n", di->di_entries); |
1300 | printk(KERN_INFO " di_eattr = %llu\n", | 1299 | printk(KERN_INFO " di_eattr = %llu\n", |
1301 | (unsigned long long)di->di_eattr); | 1300 | (unsigned long long)di->di_eattr); |
1302 | } | 1301 | } |
1303 | 1302 | ||
1304 | 1303 |
fs/gfs2/inode.h
1 | /* | 1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
4 | * | 4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | 5 | * This copyrighted material is made available to anyone wishing to use, |
6 | * modify, copy, or redistribute it subject to the terms and conditions | 6 | * modify, copy, or redistribute it subject to the terms and conditions |
7 | * of the GNU General Public License version 2. | 7 | * of the GNU General Public License version 2. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #ifndef __INODE_DOT_H__ | 10 | #ifndef __INODE_DOT_H__ |
11 | #define __INODE_DOT_H__ | 11 | #define __INODE_DOT_H__ |
12 | 12 | ||
13 | #include <linux/fs.h> | ||
13 | #include "util.h" | 14 | #include "util.h" |
14 | 15 | ||
15 | static inline int gfs2_is_stuffed(const struct gfs2_inode *ip) | 16 | static inline int gfs2_is_stuffed(const struct gfs2_inode *ip) |
16 | { | 17 | { |
17 | return !ip->i_height; | 18 | return !ip->i_height; |
18 | } | 19 | } |
19 | 20 | ||
20 | static inline int gfs2_is_jdata(const struct gfs2_inode *ip) | 21 | static inline int gfs2_is_jdata(const struct gfs2_inode *ip) |
21 | { | 22 | { |
22 | return ip->i_di.di_flags & GFS2_DIF_JDATA; | 23 | return ip->i_di.di_flags & GFS2_DIF_JDATA; |
23 | } | 24 | } |
24 | 25 | ||
25 | static inline int gfs2_is_writeback(const struct gfs2_inode *ip) | 26 | static inline int gfs2_is_writeback(const struct gfs2_inode *ip) |
26 | { | 27 | { |
27 | const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | 28 | const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
28 | return (sdp->sd_args.ar_data == GFS2_DATA_WRITEBACK) && !gfs2_is_jdata(ip); | 29 | return (sdp->sd_args.ar_data == GFS2_DATA_WRITEBACK) && !gfs2_is_jdata(ip); |
29 | } | 30 | } |
30 | 31 | ||
31 | static inline int gfs2_is_ordered(const struct gfs2_inode *ip) | 32 | static inline int gfs2_is_ordered(const struct gfs2_inode *ip) |
32 | { | 33 | { |
33 | const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | 34 | const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
34 | return (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) && !gfs2_is_jdata(ip); | 35 | return (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) && !gfs2_is_jdata(ip); |
35 | } | 36 | } |
36 | 37 | ||
37 | static inline int gfs2_is_dir(const struct gfs2_inode *ip) | 38 | static inline int gfs2_is_dir(const struct gfs2_inode *ip) |
38 | { | 39 | { |
39 | return S_ISDIR(ip->i_inode.i_mode); | 40 | return S_ISDIR(ip->i_inode.i_mode); |
40 | } | 41 | } |
41 | 42 | ||
42 | static inline void gfs2_set_inode_blocks(struct inode *inode, u64 blocks) | 43 | static inline void gfs2_set_inode_blocks(struct inode *inode, u64 blocks) |
43 | { | 44 | { |
44 | inode->i_blocks = blocks << | 45 | inode->i_blocks = blocks << |
45 | (GFS2_SB(inode)->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT); | 46 | (GFS2_SB(inode)->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT); |
46 | } | 47 | } |
47 | 48 | ||
48 | static inline u64 gfs2_get_inode_blocks(const struct inode *inode) | 49 | static inline u64 gfs2_get_inode_blocks(const struct inode *inode) |
49 | { | 50 | { |
50 | return inode->i_blocks >> | 51 | return inode->i_blocks >> |
51 | (GFS2_SB(inode)->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT); | 52 | (GFS2_SB(inode)->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT); |
52 | } | 53 | } |
53 | 54 | ||
54 | static inline void gfs2_add_inode_blocks(struct inode *inode, s64 change) | 55 | static inline void gfs2_add_inode_blocks(struct inode *inode, s64 change) |
55 | { | 56 | { |
56 | gfs2_assert(GFS2_SB(inode), (change >= 0 || inode->i_blocks > -change)); | 57 | gfs2_assert(GFS2_SB(inode), (change >= 0 || inode->i_blocks > -change)); |
57 | change *= (GFS2_SB(inode)->sd_sb.sb_bsize/GFS2_BASIC_BLOCK); | 58 | change *= (GFS2_SB(inode)->sd_sb.sb_bsize/GFS2_BASIC_BLOCK); |
58 | inode->i_blocks += change; | 59 | inode->i_blocks += change; |
59 | } | 60 | } |
60 | 61 | ||
61 | static inline int gfs2_check_inum(const struct gfs2_inode *ip, u64 no_addr, | 62 | static inline int gfs2_check_inum(const struct gfs2_inode *ip, u64 no_addr, |
62 | u64 no_formal_ino) | 63 | u64 no_formal_ino) |
63 | { | 64 | { |
64 | return ip->i_no_addr == no_addr && ip->i_no_formal_ino == no_formal_ino; | 65 | return ip->i_no_addr == no_addr && ip->i_no_formal_ino == no_formal_ino; |
65 | } | 66 | } |
66 | 67 | ||
67 | static inline void gfs2_inum_out(const struct gfs2_inode *ip, | 68 | static inline void gfs2_inum_out(const struct gfs2_inode *ip, |
68 | struct gfs2_dirent *dent) | 69 | struct gfs2_dirent *dent) |
69 | { | 70 | { |
70 | dent->de_inum.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino); | 71 | dent->de_inum.no_formal_ino = cpu_to_be64(ip->i_no_formal_ino); |
71 | dent->de_inum.no_addr = cpu_to_be64(ip->i_no_addr); | 72 | dent->de_inum.no_addr = cpu_to_be64(ip->i_no_addr); |
72 | } | 73 | } |
73 | 74 | ||
74 | 75 | ||
75 | void gfs2_set_iop(struct inode *inode); | 76 | void gfs2_set_iop(struct inode *inode); |
76 | struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned type, | 77 | struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned type, |
77 | u64 no_addr, u64 no_formal_ino, | 78 | u64 no_addr, u64 no_formal_ino, |
78 | int skip_freeing); | 79 | int skip_freeing); |
79 | struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr); | 80 | struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr); |
80 | 81 | ||
81 | int gfs2_inode_refresh(struct gfs2_inode *ip); | 82 | int gfs2_inode_refresh(struct gfs2_inode *ip); |
82 | 83 | ||
83 | int gfs2_dinode_dealloc(struct gfs2_inode *inode); | 84 | int gfs2_dinode_dealloc(struct gfs2_inode *inode); |
84 | int gfs2_change_nlink(struct gfs2_inode *ip, int diff); | 85 | int gfs2_change_nlink(struct gfs2_inode *ip, int diff); |
85 | struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, | 86 | struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, |
86 | int is_root); | 87 | int is_root); |
87 | struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, | 88 | struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, |
88 | unsigned int mode, dev_t dev); | 89 | unsigned int mode, dev_t dev); |
89 | int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name, | 90 | int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name, |
90 | struct gfs2_inode *ip); | 91 | struct gfs2_inode *ip); |
91 | int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name, | 92 | int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name, |
92 | const struct gfs2_inode *ip); | 93 | const struct gfs2_inode *ip); |
93 | int gfs2_permission(struct inode *inode, int mask); | 94 | int gfs2_permission(struct inode *inode, int mask); |
94 | int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len); | 95 | int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len); |
95 | int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr); | 96 | int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr); |
96 | struct inode *gfs2_lookup_simple(struct inode *dip, const char *name); | 97 | struct inode *gfs2_lookup_simple(struct inode *dip, const char *name); |
97 | void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf); | 98 | void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf); |
98 | void gfs2_dinode_print(const struct gfs2_inode *ip); | 99 | void gfs2_dinode_print(const struct gfs2_inode *ip); |
100 | |||
101 | extern const struct inode_operations gfs2_file_iops; | ||
102 | extern const struct inode_operations gfs2_dir_iops; | ||
103 | extern const struct inode_operations gfs2_symlink_iops; | ||
104 | extern const struct file_operations gfs2_file_fops; | ||
105 | extern const struct file_operations gfs2_dir_fops; | ||
106 | extern const struct file_operations gfs2_file_fops_nolock; | ||
107 | extern const struct file_operations gfs2_dir_fops_nolock; | ||
108 | |||
109 | extern void gfs2_set_inode_flags(struct inode *inode); | ||
99 | 110 | ||
100 | #endif /* __INODE_DOT_H__ */ | 111 | #endif /* __INODE_DOT_H__ */ |
101 | 112 | ||
102 | 113 |
fs/gfs2/main.c
1 | /* | 1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
4 | * | 4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | 5 | * This copyrighted material is made available to anyone wishing to use, |
6 | * modify, copy, or redistribute it subject to the terms and conditions | 6 | * modify, copy, or redistribute it subject to the terms and conditions |
7 | * of the GNU General Public License version 2. | 7 | * of the GNU General Public License version 2. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
11 | #include <linux/spinlock.h> | 11 | #include <linux/spinlock.h> |
12 | #include <linux/completion.h> | 12 | #include <linux/completion.h> |
13 | #include <linux/buffer_head.h> | 13 | #include <linux/buffer_head.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/gfs2_ondisk.h> | 16 | #include <linux/gfs2_ondisk.h> |
17 | #include <linux/lm_interface.h> | 17 | #include <linux/lm_interface.h> |
18 | #include <asm/atomic.h> | 18 | #include <asm/atomic.h> |
19 | 19 | ||
20 | #include "gfs2.h" | 20 | #include "gfs2.h" |
21 | #include "incore.h" | 21 | #include "incore.h" |
22 | #include "ops_fstype.h" | 22 | #include "super.h" |
23 | #include "sys.h" | 23 | #include "sys.h" |
24 | #include "util.h" | 24 | #include "util.h" |
25 | #include "glock.h" | 25 | #include "glock.h" |
26 | 26 | ||
27 | static void gfs2_init_inode_once(void *foo) | 27 | static void gfs2_init_inode_once(void *foo) |
28 | { | 28 | { |
29 | struct gfs2_inode *ip = foo; | 29 | struct gfs2_inode *ip = foo; |
30 | 30 | ||
31 | inode_init_once(&ip->i_inode); | 31 | inode_init_once(&ip->i_inode); |
32 | init_rwsem(&ip->i_rw_mutex); | 32 | init_rwsem(&ip->i_rw_mutex); |
33 | ip->i_alloc = NULL; | 33 | ip->i_alloc = NULL; |
34 | } | 34 | } |
35 | 35 | ||
36 | static void gfs2_init_glock_once(void *foo) | 36 | static void gfs2_init_glock_once(void *foo) |
37 | { | 37 | { |
38 | struct gfs2_glock *gl = foo; | 38 | struct gfs2_glock *gl = foo; |
39 | 39 | ||
40 | INIT_HLIST_NODE(&gl->gl_list); | 40 | INIT_HLIST_NODE(&gl->gl_list); |
41 | spin_lock_init(&gl->gl_spin); | 41 | spin_lock_init(&gl->gl_spin); |
42 | INIT_LIST_HEAD(&gl->gl_holders); | 42 | INIT_LIST_HEAD(&gl->gl_holders); |
43 | gl->gl_lvb = NULL; | 43 | gl->gl_lvb = NULL; |
44 | atomic_set(&gl->gl_lvb_count, 0); | 44 | atomic_set(&gl->gl_lvb_count, 0); |
45 | INIT_LIST_HEAD(&gl->gl_reclaim); | 45 | INIT_LIST_HEAD(&gl->gl_reclaim); |
46 | INIT_LIST_HEAD(&gl->gl_ail_list); | 46 | INIT_LIST_HEAD(&gl->gl_ail_list); |
47 | atomic_set(&gl->gl_ail_count, 0); | 47 | atomic_set(&gl->gl_ail_count, 0); |
48 | } | 48 | } |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * init_gfs2_fs - Register GFS2 as a filesystem | 51 | * init_gfs2_fs - Register GFS2 as a filesystem |
52 | * | 52 | * |
53 | * Returns: 0 on success, error code on failure | 53 | * Returns: 0 on success, error code on failure |
54 | */ | 54 | */ |
55 | 55 | ||
56 | static int __init init_gfs2_fs(void) | 56 | static int __init init_gfs2_fs(void) |
57 | { | 57 | { |
58 | int error; | 58 | int error; |
59 | 59 | ||
60 | error = gfs2_sys_init(); | 60 | error = gfs2_sys_init(); |
61 | if (error) | 61 | if (error) |
62 | return error; | 62 | return error; |
63 | 63 | ||
64 | error = gfs2_glock_init(); | 64 | error = gfs2_glock_init(); |
65 | if (error) | 65 | if (error) |
66 | goto fail; | 66 | goto fail; |
67 | 67 | ||
68 | error = -ENOMEM; | 68 | error = -ENOMEM; |
69 | gfs2_glock_cachep = kmem_cache_create("gfs2_glock", | 69 | gfs2_glock_cachep = kmem_cache_create("gfs2_glock", |
70 | sizeof(struct gfs2_glock), | 70 | sizeof(struct gfs2_glock), |
71 | 0, 0, | 71 | 0, 0, |
72 | gfs2_init_glock_once); | 72 | gfs2_init_glock_once); |
73 | if (!gfs2_glock_cachep) | 73 | if (!gfs2_glock_cachep) |
74 | goto fail; | 74 | goto fail; |
75 | 75 | ||
76 | gfs2_inode_cachep = kmem_cache_create("gfs2_inode", | 76 | gfs2_inode_cachep = kmem_cache_create("gfs2_inode", |
77 | sizeof(struct gfs2_inode), | 77 | sizeof(struct gfs2_inode), |
78 | 0, SLAB_RECLAIM_ACCOUNT| | 78 | 0, SLAB_RECLAIM_ACCOUNT| |
79 | SLAB_MEM_SPREAD, | 79 | SLAB_MEM_SPREAD, |
80 | gfs2_init_inode_once); | 80 | gfs2_init_inode_once); |
81 | if (!gfs2_inode_cachep) | 81 | if (!gfs2_inode_cachep) |
82 | goto fail; | 82 | goto fail; |
83 | 83 | ||
84 | gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata", | 84 | gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata", |
85 | sizeof(struct gfs2_bufdata), | 85 | sizeof(struct gfs2_bufdata), |
86 | 0, 0, NULL); | 86 | 0, 0, NULL); |
87 | if (!gfs2_bufdata_cachep) | 87 | if (!gfs2_bufdata_cachep) |
88 | goto fail; | 88 | goto fail; |
89 | 89 | ||
90 | gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd", | 90 | gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd", |
91 | sizeof(struct gfs2_rgrpd), | 91 | sizeof(struct gfs2_rgrpd), |
92 | 0, 0, NULL); | 92 | 0, 0, NULL); |
93 | if (!gfs2_rgrpd_cachep) | 93 | if (!gfs2_rgrpd_cachep) |
94 | goto fail; | 94 | goto fail; |
95 | 95 | ||
96 | error = register_filesystem(&gfs2_fs_type); | 96 | error = register_filesystem(&gfs2_fs_type); |
97 | if (error) | 97 | if (error) |
98 | goto fail; | 98 | goto fail; |
99 | 99 | ||
100 | error = register_filesystem(&gfs2meta_fs_type); | 100 | error = register_filesystem(&gfs2meta_fs_type); |
101 | if (error) | 101 | if (error) |
102 | goto fail_unregister; | 102 | goto fail_unregister; |
103 | 103 | ||
104 | gfs2_register_debugfs(); | 104 | gfs2_register_debugfs(); |
105 | 105 | ||
106 | printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__); | 106 | printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__); |
107 | 107 | ||
108 | return 0; | 108 | return 0; |
109 | 109 | ||
110 | fail_unregister: | 110 | fail_unregister: |
111 | unregister_filesystem(&gfs2_fs_type); | 111 | unregister_filesystem(&gfs2_fs_type); |
112 | fail: | 112 | fail: |
113 | gfs2_glock_exit(); | 113 | gfs2_glock_exit(); |
114 | 114 | ||
115 | if (gfs2_rgrpd_cachep) | 115 | if (gfs2_rgrpd_cachep) |
116 | kmem_cache_destroy(gfs2_rgrpd_cachep); | 116 | kmem_cache_destroy(gfs2_rgrpd_cachep); |
117 | 117 | ||
118 | if (gfs2_bufdata_cachep) | 118 | if (gfs2_bufdata_cachep) |
119 | kmem_cache_destroy(gfs2_bufdata_cachep); | 119 | kmem_cache_destroy(gfs2_bufdata_cachep); |
120 | 120 | ||
121 | if (gfs2_inode_cachep) | 121 | if (gfs2_inode_cachep) |
122 | kmem_cache_destroy(gfs2_inode_cachep); | 122 | kmem_cache_destroy(gfs2_inode_cachep); |
123 | 123 | ||
124 | if (gfs2_glock_cachep) | 124 | if (gfs2_glock_cachep) |
125 | kmem_cache_destroy(gfs2_glock_cachep); | 125 | kmem_cache_destroy(gfs2_glock_cachep); |
126 | 126 | ||
127 | gfs2_sys_uninit(); | 127 | gfs2_sys_uninit(); |
128 | return error; | 128 | return error; |
129 | } | 129 | } |
130 | 130 | ||
131 | /** | 131 | /** |
132 | * exit_gfs2_fs - Unregister the file system | 132 | * exit_gfs2_fs - Unregister the file system |
133 | * | 133 | * |
134 | */ | 134 | */ |
135 | 135 | ||
136 | static void __exit exit_gfs2_fs(void) | 136 | static void __exit exit_gfs2_fs(void) |
137 | { | 137 | { |
138 | gfs2_glock_exit(); | 138 | gfs2_glock_exit(); |
139 | gfs2_unregister_debugfs(); | 139 | gfs2_unregister_debugfs(); |
140 | unregister_filesystem(&gfs2_fs_type); | 140 | unregister_filesystem(&gfs2_fs_type); |
141 | unregister_filesystem(&gfs2meta_fs_type); | 141 | unregister_filesystem(&gfs2meta_fs_type); |
142 | 142 | ||
143 | kmem_cache_destroy(gfs2_rgrpd_cachep); | 143 | kmem_cache_destroy(gfs2_rgrpd_cachep); |
144 | kmem_cache_destroy(gfs2_bufdata_cachep); | 144 | kmem_cache_destroy(gfs2_bufdata_cachep); |
145 | kmem_cache_destroy(gfs2_inode_cachep); | 145 | kmem_cache_destroy(gfs2_inode_cachep); |
146 | kmem_cache_destroy(gfs2_glock_cachep); | 146 | kmem_cache_destroy(gfs2_glock_cachep); |
147 | 147 | ||
148 | gfs2_sys_uninit(); | 148 | gfs2_sys_uninit(); |
149 | } | 149 | } |
150 | 150 | ||
151 | MODULE_DESCRIPTION("Global File System"); | 151 | MODULE_DESCRIPTION("Global File System"); |
152 | MODULE_AUTHOR("Red Hat, Inc."); | 152 | MODULE_AUTHOR("Red Hat, Inc."); |
153 | MODULE_LICENSE("GPL"); | 153 | MODULE_LICENSE("GPL"); |
154 | 154 | ||
155 | module_init(init_gfs2_fs); | 155 | module_init(init_gfs2_fs); |
156 | module_exit(exit_gfs2_fs); | 156 | module_exit(exit_gfs2_fs); |
157 | 157 | ||
158 | 158 |
fs/gfs2/ops_dentry.c
1 | /* | 1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
4 | * | 4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | 5 | * This copyrighted material is made available to anyone wishing to use, |
6 | * modify, copy, or redistribute it subject to the terms and conditions | 6 | * modify, copy, or redistribute it subject to the terms and conditions |
7 | * of the GNU General Public License version 2. | 7 | * of the GNU General Public License version 2. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
11 | #include <linux/spinlock.h> | 11 | #include <linux/spinlock.h> |
12 | #include <linux/completion.h> | 12 | #include <linux/completion.h> |
13 | #include <linux/buffer_head.h> | 13 | #include <linux/buffer_head.h> |
14 | #include <linux/gfs2_ondisk.h> | 14 | #include <linux/gfs2_ondisk.h> |
15 | #include <linux/crc32.h> | 15 | #include <linux/crc32.h> |
16 | #include <linux/lm_interface.h> | 16 | #include <linux/lm_interface.h> |
17 | 17 | ||
18 | #include "gfs2.h" | 18 | #include "gfs2.h" |
19 | #include "incore.h" | 19 | #include "incore.h" |
20 | #include "dir.h" | 20 | #include "dir.h" |
21 | #include "glock.h" | 21 | #include "glock.h" |
22 | #include "ops_dentry.h" | 22 | #include "super.h" |
23 | #include "util.h" | 23 | #include "util.h" |
24 | #include "inode.h" | 24 | #include "inode.h" |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * gfs2_drevalidate - Check directory lookup consistency | 27 | * gfs2_drevalidate - Check directory lookup consistency |
28 | * @dentry: the mapping to check | 28 | * @dentry: the mapping to check |
29 | * @nd: | 29 | * @nd: |
30 | * | 30 | * |
31 | * Check to make sure the lookup necessary to arrive at this inode from its | 31 | * Check to make sure the lookup necessary to arrive at this inode from its |
32 | * parent is still good. | 32 | * parent is still good. |
33 | * | 33 | * |
34 | * Returns: 1 if the dentry is ok, 0 if it isn't | 34 | * Returns: 1 if the dentry is ok, 0 if it isn't |
35 | */ | 35 | */ |
36 | 36 | ||
37 | static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) | 37 | static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd) |
38 | { | 38 | { |
39 | struct dentry *parent = dget_parent(dentry); | 39 | struct dentry *parent = dget_parent(dentry); |
40 | struct gfs2_sbd *sdp = GFS2_SB(parent->d_inode); | 40 | struct gfs2_sbd *sdp = GFS2_SB(parent->d_inode); |
41 | struct gfs2_inode *dip = GFS2_I(parent->d_inode); | 41 | struct gfs2_inode *dip = GFS2_I(parent->d_inode); |
42 | struct inode *inode = dentry->d_inode; | 42 | struct inode *inode = dentry->d_inode; |
43 | struct gfs2_holder d_gh; | 43 | struct gfs2_holder d_gh; |
44 | struct gfs2_inode *ip = NULL; | 44 | struct gfs2_inode *ip = NULL; |
45 | int error; | 45 | int error; |
46 | int had_lock = 0; | 46 | int had_lock = 0; |
47 | 47 | ||
48 | if (inode) { | 48 | if (inode) { |
49 | if (is_bad_inode(inode)) | 49 | if (is_bad_inode(inode)) |
50 | goto invalid; | 50 | goto invalid; |
51 | ip = GFS2_I(inode); | 51 | ip = GFS2_I(inode); |
52 | } | 52 | } |
53 | 53 | ||
54 | if (sdp->sd_args.ar_localcaching) | 54 | if (sdp->sd_args.ar_localcaching) |
55 | goto valid; | 55 | goto valid; |
56 | 56 | ||
57 | had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL); | 57 | had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL); |
58 | if (!had_lock) { | 58 | if (!had_lock) { |
59 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); | 59 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); |
60 | if (error) | 60 | if (error) |
61 | goto fail; | 61 | goto fail; |
62 | } | 62 | } |
63 | 63 | ||
64 | error = gfs2_dir_check(parent->d_inode, &dentry->d_name, ip); | 64 | error = gfs2_dir_check(parent->d_inode, &dentry->d_name, ip); |
65 | switch (error) { | 65 | switch (error) { |
66 | case 0: | 66 | case 0: |
67 | if (!inode) | 67 | if (!inode) |
68 | goto invalid_gunlock; | 68 | goto invalid_gunlock; |
69 | break; | 69 | break; |
70 | case -ENOENT: | 70 | case -ENOENT: |
71 | if (!inode) | 71 | if (!inode) |
72 | goto valid_gunlock; | 72 | goto valid_gunlock; |
73 | goto invalid_gunlock; | 73 | goto invalid_gunlock; |
74 | default: | 74 | default: |
75 | goto fail_gunlock; | 75 | goto fail_gunlock; |
76 | } | 76 | } |
77 | 77 | ||
78 | valid_gunlock: | 78 | valid_gunlock: |
79 | if (!had_lock) | 79 | if (!had_lock) |
80 | gfs2_glock_dq_uninit(&d_gh); | 80 | gfs2_glock_dq_uninit(&d_gh); |
81 | valid: | 81 | valid: |
82 | dput(parent); | 82 | dput(parent); |
83 | return 1; | 83 | return 1; |
84 | 84 | ||
85 | invalid_gunlock: | 85 | invalid_gunlock: |
86 | if (!had_lock) | 86 | if (!had_lock) |
87 | gfs2_glock_dq_uninit(&d_gh); | 87 | gfs2_glock_dq_uninit(&d_gh); |
88 | invalid: | 88 | invalid: |
89 | if (inode && S_ISDIR(inode->i_mode)) { | 89 | if (inode && S_ISDIR(inode->i_mode)) { |
90 | if (have_submounts(dentry)) | 90 | if (have_submounts(dentry)) |
91 | goto valid; | 91 | goto valid; |
92 | shrink_dcache_parent(dentry); | 92 | shrink_dcache_parent(dentry); |
93 | } | 93 | } |
94 | d_drop(dentry); | 94 | d_drop(dentry); |
95 | dput(parent); | 95 | dput(parent); |
96 | return 0; | 96 | return 0; |
97 | 97 | ||
98 | fail_gunlock: | 98 | fail_gunlock: |
99 | gfs2_glock_dq_uninit(&d_gh); | 99 | gfs2_glock_dq_uninit(&d_gh); |
100 | fail: | 100 | fail: |
101 | dput(parent); | 101 | dput(parent); |
102 | return 0; | 102 | return 0; |
103 | } | 103 | } |
104 | 104 | ||
105 | static int gfs2_dhash(struct dentry *dentry, struct qstr *str) | 105 | static int gfs2_dhash(struct dentry *dentry, struct qstr *str) |
106 | { | 106 | { |
107 | str->hash = gfs2_disk_hash(str->name, str->len); | 107 | str->hash = gfs2_disk_hash(str->name, str->len); |
108 | return 0; | 108 | return 0; |
109 | } | 109 | } |
110 | 110 | ||
111 | struct dentry_operations gfs2_dops = { | 111 | struct dentry_operations gfs2_dops = { |
112 | .d_revalidate = gfs2_drevalidate, | 112 | .d_revalidate = gfs2_drevalidate, |
113 | .d_hash = gfs2_dhash, | 113 | .d_hash = gfs2_dhash, |
114 | }; | 114 | }; |
115 | 115 | ||
116 | 116 |
fs/gfs2/ops_dentry.h
1 | /* | File was deleted | |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | ||
3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. | ||
4 | * | ||
5 | * This copyrighted material is made available to anyone wishing to use, | ||
6 | * modify, copy, or redistribute it subject to the terms and conditions | ||
7 | * of the GNU General Public License version 2. | ||
8 | */ | ||
9 | |||
10 | #ifndef __OPS_DENTRY_DOT_H__ | ||
11 | #define __OPS_DENTRY_DOT_H__ | ||
12 | |||
13 | #include <linux/dcache.h> | ||
14 | |||
15 | extern struct dentry_operations gfs2_dops; | ||
16 | |||
17 | #endif /* __OPS_DENTRY_DOT_H__ */ | ||
18 | 1 | /* |
fs/gfs2/ops_export.c
1 | /* | 1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
4 | * | 4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | 5 | * This copyrighted material is made available to anyone wishing to use, |
6 | * modify, copy, or redistribute it subject to the terms and conditions | 6 | * modify, copy, or redistribute it subject to the terms and conditions |
7 | * of the GNU General Public License version 2. | 7 | * of the GNU General Public License version 2. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
11 | #include <linux/spinlock.h> | 11 | #include <linux/spinlock.h> |
12 | #include <linux/completion.h> | 12 | #include <linux/completion.h> |
13 | #include <linux/buffer_head.h> | 13 | #include <linux/buffer_head.h> |
14 | #include <linux/exportfs.h> | 14 | #include <linux/exportfs.h> |
15 | #include <linux/gfs2_ondisk.h> | 15 | #include <linux/gfs2_ondisk.h> |
16 | #include <linux/crc32.h> | 16 | #include <linux/crc32.h> |
17 | #include <linux/lm_interface.h> | 17 | #include <linux/lm_interface.h> |
18 | 18 | ||
19 | #include "gfs2.h" | 19 | #include "gfs2.h" |
20 | #include "incore.h" | 20 | #include "incore.h" |
21 | #include "dir.h" | 21 | #include "dir.h" |
22 | #include "glock.h" | 22 | #include "glock.h" |
23 | #include "glops.h" | 23 | #include "glops.h" |
24 | #include "inode.h" | 24 | #include "inode.h" |
25 | #include "ops_dentry.h" | 25 | #include "super.h" |
26 | #include "ops_fstype.h" | ||
27 | #include "rgrp.h" | 26 | #include "rgrp.h" |
28 | #include "util.h" | 27 | #include "util.h" |
29 | 28 | ||
30 | #define GFS2_SMALL_FH_SIZE 4 | 29 | #define GFS2_SMALL_FH_SIZE 4 |
31 | #define GFS2_LARGE_FH_SIZE 8 | 30 | #define GFS2_LARGE_FH_SIZE 8 |
32 | #define GFS2_OLD_FH_SIZE 10 | 31 | #define GFS2_OLD_FH_SIZE 10 |
33 | 32 | ||
34 | static int gfs2_encode_fh(struct dentry *dentry, __u32 *p, int *len, | 33 | static int gfs2_encode_fh(struct dentry *dentry, __u32 *p, int *len, |
35 | int connectable) | 34 | int connectable) |
36 | { | 35 | { |
37 | __be32 *fh = (__force __be32 *)p; | 36 | __be32 *fh = (__force __be32 *)p; |
38 | struct inode *inode = dentry->d_inode; | 37 | struct inode *inode = dentry->d_inode; |
39 | struct super_block *sb = inode->i_sb; | 38 | struct super_block *sb = inode->i_sb; |
40 | struct gfs2_inode *ip = GFS2_I(inode); | 39 | struct gfs2_inode *ip = GFS2_I(inode); |
41 | 40 | ||
42 | if (*len < GFS2_SMALL_FH_SIZE || | 41 | if (*len < GFS2_SMALL_FH_SIZE || |
43 | (connectable && *len < GFS2_LARGE_FH_SIZE)) | 42 | (connectable && *len < GFS2_LARGE_FH_SIZE)) |
44 | return 255; | 43 | return 255; |
45 | 44 | ||
46 | fh[0] = cpu_to_be32(ip->i_no_formal_ino >> 32); | 45 | fh[0] = cpu_to_be32(ip->i_no_formal_ino >> 32); |
47 | fh[1] = cpu_to_be32(ip->i_no_formal_ino & 0xFFFFFFFF); | 46 | fh[1] = cpu_to_be32(ip->i_no_formal_ino & 0xFFFFFFFF); |
48 | fh[2] = cpu_to_be32(ip->i_no_addr >> 32); | 47 | fh[2] = cpu_to_be32(ip->i_no_addr >> 32); |
49 | fh[3] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF); | 48 | fh[3] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF); |
50 | *len = GFS2_SMALL_FH_SIZE; | 49 | *len = GFS2_SMALL_FH_SIZE; |
51 | 50 | ||
52 | if (!connectable || inode == sb->s_root->d_inode) | 51 | if (!connectable || inode == sb->s_root->d_inode) |
53 | return *len; | 52 | return *len; |
54 | 53 | ||
55 | spin_lock(&dentry->d_lock); | 54 | spin_lock(&dentry->d_lock); |
56 | inode = dentry->d_parent->d_inode; | 55 | inode = dentry->d_parent->d_inode; |
57 | ip = GFS2_I(inode); | 56 | ip = GFS2_I(inode); |
58 | igrab(inode); | 57 | igrab(inode); |
59 | spin_unlock(&dentry->d_lock); | 58 | spin_unlock(&dentry->d_lock); |
60 | 59 | ||
61 | fh[4] = cpu_to_be32(ip->i_no_formal_ino >> 32); | 60 | fh[4] = cpu_to_be32(ip->i_no_formal_ino >> 32); |
62 | fh[5] = cpu_to_be32(ip->i_no_formal_ino & 0xFFFFFFFF); | 61 | fh[5] = cpu_to_be32(ip->i_no_formal_ino & 0xFFFFFFFF); |
63 | fh[6] = cpu_to_be32(ip->i_no_addr >> 32); | 62 | fh[6] = cpu_to_be32(ip->i_no_addr >> 32); |
64 | fh[7] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF); | 63 | fh[7] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF); |
65 | *len = GFS2_LARGE_FH_SIZE; | 64 | *len = GFS2_LARGE_FH_SIZE; |
66 | 65 | ||
67 | iput(inode); | 66 | iput(inode); |
68 | 67 | ||
69 | return *len; | 68 | return *len; |
70 | } | 69 | } |
71 | 70 | ||
72 | struct get_name_filldir { | 71 | struct get_name_filldir { |
73 | struct gfs2_inum_host inum; | 72 | struct gfs2_inum_host inum; |
74 | char *name; | 73 | char *name; |
75 | }; | 74 | }; |
76 | 75 | ||
77 | static int get_name_filldir(void *opaque, const char *name, int length, | 76 | static int get_name_filldir(void *opaque, const char *name, int length, |
78 | loff_t offset, u64 inum, unsigned int type) | 77 | loff_t offset, u64 inum, unsigned int type) |
79 | { | 78 | { |
80 | struct get_name_filldir *gnfd = opaque; | 79 | struct get_name_filldir *gnfd = opaque; |
81 | 80 | ||
82 | if (inum != gnfd->inum.no_addr) | 81 | if (inum != gnfd->inum.no_addr) |
83 | return 0; | 82 | return 0; |
84 | 83 | ||
85 | memcpy(gnfd->name, name, length); | 84 | memcpy(gnfd->name, name, length); |
86 | gnfd->name[length] = 0; | 85 | gnfd->name[length] = 0; |
87 | 86 | ||
88 | return 1; | 87 | return 1; |
89 | } | 88 | } |
90 | 89 | ||
91 | static int gfs2_get_name(struct dentry *parent, char *name, | 90 | static int gfs2_get_name(struct dentry *parent, char *name, |
92 | struct dentry *child) | 91 | struct dentry *child) |
93 | { | 92 | { |
94 | struct inode *dir = parent->d_inode; | 93 | struct inode *dir = parent->d_inode; |
95 | struct inode *inode = child->d_inode; | 94 | struct inode *inode = child->d_inode; |
96 | struct gfs2_inode *dip, *ip; | 95 | struct gfs2_inode *dip, *ip; |
97 | struct get_name_filldir gnfd; | 96 | struct get_name_filldir gnfd; |
98 | struct gfs2_holder gh; | 97 | struct gfs2_holder gh; |
99 | u64 offset = 0; | 98 | u64 offset = 0; |
100 | int error; | 99 | int error; |
101 | 100 | ||
102 | if (!dir) | 101 | if (!dir) |
103 | return -EINVAL; | 102 | return -EINVAL; |
104 | 103 | ||
105 | if (!S_ISDIR(dir->i_mode) || !inode) | 104 | if (!S_ISDIR(dir->i_mode) || !inode) |
106 | return -EINVAL; | 105 | return -EINVAL; |
107 | 106 | ||
108 | dip = GFS2_I(dir); | 107 | dip = GFS2_I(dir); |
109 | ip = GFS2_I(inode); | 108 | ip = GFS2_I(inode); |
110 | 109 | ||
111 | *name = 0; | 110 | *name = 0; |
112 | gnfd.inum.no_addr = ip->i_no_addr; | 111 | gnfd.inum.no_addr = ip->i_no_addr; |
113 | gnfd.inum.no_formal_ino = ip->i_no_formal_ino; | 112 | gnfd.inum.no_formal_ino = ip->i_no_formal_ino; |
114 | gnfd.name = name; | 113 | gnfd.name = name; |
115 | 114 | ||
116 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &gh); | 115 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &gh); |
117 | if (error) | 116 | if (error) |
118 | return error; | 117 | return error; |
119 | 118 | ||
120 | error = gfs2_dir_read(dir, &offset, &gnfd, get_name_filldir); | 119 | error = gfs2_dir_read(dir, &offset, &gnfd, get_name_filldir); |
121 | 120 | ||
122 | gfs2_glock_dq_uninit(&gh); | 121 | gfs2_glock_dq_uninit(&gh); |
123 | 122 | ||
124 | if (!error && !*name) | 123 | if (!error && !*name) |
125 | error = -ENOENT; | 124 | error = -ENOENT; |
126 | 125 | ||
127 | return error; | 126 | return error; |
128 | } | 127 | } |
129 | 128 | ||
130 | static struct dentry *gfs2_get_parent(struct dentry *child) | 129 | static struct dentry *gfs2_get_parent(struct dentry *child) |
131 | { | 130 | { |
132 | struct qstr dotdot; | 131 | struct qstr dotdot; |
133 | struct dentry *dentry; | 132 | struct dentry *dentry; |
134 | 133 | ||
135 | /* | 134 | /* |
136 | * XXX(hch): it would be a good idea to keep this around as a | 135 | * XXX(hch): it would be a good idea to keep this around as a |
137 | * static variable. | 136 | * static variable. |
138 | */ | 137 | */ |
139 | gfs2_str2qstr(&dotdot, ".."); | 138 | gfs2_str2qstr(&dotdot, ".."); |
140 | 139 | ||
141 | dentry = d_obtain_alias(gfs2_lookupi(child->d_inode, &dotdot, 1)); | 140 | dentry = d_obtain_alias(gfs2_lookupi(child->d_inode, &dotdot, 1)); |
142 | if (!IS_ERR(dentry)) | 141 | if (!IS_ERR(dentry)) |
143 | dentry->d_op = &gfs2_dops; | 142 | dentry->d_op = &gfs2_dops; |
144 | return dentry; | 143 | return dentry; |
145 | } | 144 | } |
146 | 145 | ||
147 | static struct dentry *gfs2_get_dentry(struct super_block *sb, | 146 | static struct dentry *gfs2_get_dentry(struct super_block *sb, |
148 | struct gfs2_inum_host *inum) | 147 | struct gfs2_inum_host *inum) |
149 | { | 148 | { |
150 | struct gfs2_sbd *sdp = sb->s_fs_info; | 149 | struct gfs2_sbd *sdp = sb->s_fs_info; |
151 | struct gfs2_holder i_gh, ri_gh, rgd_gh; | 150 | struct gfs2_holder i_gh, ri_gh, rgd_gh; |
152 | struct gfs2_rgrpd *rgd; | 151 | struct gfs2_rgrpd *rgd; |
153 | struct inode *inode; | 152 | struct inode *inode; |
154 | struct dentry *dentry; | 153 | struct dentry *dentry; |
155 | int error; | 154 | int error; |
156 | 155 | ||
157 | /* System files? */ | 156 | /* System files? */ |
158 | 157 | ||
159 | inode = gfs2_ilookup(sb, inum->no_addr); | 158 | inode = gfs2_ilookup(sb, inum->no_addr); |
160 | if (inode) { | 159 | if (inode) { |
161 | if (GFS2_I(inode)->i_no_formal_ino != inum->no_formal_ino) { | 160 | if (GFS2_I(inode)->i_no_formal_ino != inum->no_formal_ino) { |
162 | iput(inode); | 161 | iput(inode); |
163 | return ERR_PTR(-ESTALE); | 162 | return ERR_PTR(-ESTALE); |
164 | } | 163 | } |
165 | goto out_inode; | 164 | goto out_inode; |
166 | } | 165 | } |
167 | 166 | ||
168 | error = gfs2_glock_nq_num(sdp, inum->no_addr, &gfs2_inode_glops, | 167 | error = gfs2_glock_nq_num(sdp, inum->no_addr, &gfs2_inode_glops, |
169 | LM_ST_SHARED, LM_FLAG_ANY, &i_gh); | 168 | LM_ST_SHARED, LM_FLAG_ANY, &i_gh); |
170 | if (error) | 169 | if (error) |
171 | return ERR_PTR(error); | 170 | return ERR_PTR(error); |
172 | 171 | ||
173 | error = gfs2_rindex_hold(sdp, &ri_gh); | 172 | error = gfs2_rindex_hold(sdp, &ri_gh); |
174 | if (error) | 173 | if (error) |
175 | goto fail; | 174 | goto fail; |
176 | 175 | ||
177 | error = -EINVAL; | 176 | error = -EINVAL; |
178 | rgd = gfs2_blk2rgrpd(sdp, inum->no_addr); | 177 | rgd = gfs2_blk2rgrpd(sdp, inum->no_addr); |
179 | if (!rgd) | 178 | if (!rgd) |
180 | goto fail_rindex; | 179 | goto fail_rindex; |
181 | 180 | ||
182 | error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_SHARED, 0, &rgd_gh); | 181 | error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_SHARED, 0, &rgd_gh); |
183 | if (error) | 182 | if (error) |
184 | goto fail_rindex; | 183 | goto fail_rindex; |
185 | 184 | ||
186 | error = -ESTALE; | 185 | error = -ESTALE; |
187 | if (gfs2_get_block_type(rgd, inum->no_addr) != GFS2_BLKST_DINODE) | 186 | if (gfs2_get_block_type(rgd, inum->no_addr) != GFS2_BLKST_DINODE) |
188 | goto fail_rgd; | 187 | goto fail_rgd; |
189 | 188 | ||
190 | gfs2_glock_dq_uninit(&rgd_gh); | 189 | gfs2_glock_dq_uninit(&rgd_gh); |
191 | gfs2_glock_dq_uninit(&ri_gh); | 190 | gfs2_glock_dq_uninit(&ri_gh); |
192 | 191 | ||
193 | inode = gfs2_inode_lookup(sb, DT_UNKNOWN, | 192 | inode = gfs2_inode_lookup(sb, DT_UNKNOWN, |
194 | inum->no_addr, | 193 | inum->no_addr, |
195 | 0, 0); | 194 | 0, 0); |
196 | if (IS_ERR(inode)) { | 195 | if (IS_ERR(inode)) { |
197 | error = PTR_ERR(inode); | 196 | error = PTR_ERR(inode); |
198 | goto fail; | 197 | goto fail; |
199 | } | 198 | } |
200 | 199 | ||
201 | error = gfs2_inode_refresh(GFS2_I(inode)); | 200 | error = gfs2_inode_refresh(GFS2_I(inode)); |
202 | if (error) { | 201 | if (error) { |
203 | iput(inode); | 202 | iput(inode); |
204 | goto fail; | 203 | goto fail; |
205 | } | 204 | } |
206 | 205 | ||
207 | /* Pick up the works we bypass in gfs2_inode_lookup */ | 206 | /* Pick up the works we bypass in gfs2_inode_lookup */ |
208 | if (inode->i_state & I_NEW) | 207 | if (inode->i_state & I_NEW) |
209 | gfs2_set_iop(inode); | 208 | gfs2_set_iop(inode); |
210 | 209 | ||
211 | if (GFS2_I(inode)->i_no_formal_ino != inum->no_formal_ino) { | 210 | if (GFS2_I(inode)->i_no_formal_ino != inum->no_formal_ino) { |
212 | iput(inode); | 211 | iput(inode); |
213 | goto fail; | 212 | goto fail; |
214 | } | 213 | } |
215 | 214 | ||
216 | error = -EIO; | 215 | error = -EIO; |
217 | if (GFS2_I(inode)->i_di.di_flags & GFS2_DIF_SYSTEM) { | 216 | if (GFS2_I(inode)->i_di.di_flags & GFS2_DIF_SYSTEM) { |
218 | iput(inode); | 217 | iput(inode); |
219 | goto fail; | 218 | goto fail; |
220 | } | 219 | } |
221 | 220 | ||
222 | gfs2_glock_dq_uninit(&i_gh); | 221 | gfs2_glock_dq_uninit(&i_gh); |
223 | 222 | ||
224 | out_inode: | 223 | out_inode: |
225 | dentry = d_obtain_alias(inode); | 224 | dentry = d_obtain_alias(inode); |
226 | if (!IS_ERR(dentry)) | 225 | if (!IS_ERR(dentry)) |
227 | dentry->d_op = &gfs2_dops; | 226 | dentry->d_op = &gfs2_dops; |
228 | return dentry; | 227 | return dentry; |
229 | 228 | ||
230 | fail_rgd: | 229 | fail_rgd: |
231 | gfs2_glock_dq_uninit(&rgd_gh); | 230 | gfs2_glock_dq_uninit(&rgd_gh); |
232 | 231 | ||
233 | fail_rindex: | 232 | fail_rindex: |
234 | gfs2_glock_dq_uninit(&ri_gh); | 233 | gfs2_glock_dq_uninit(&ri_gh); |
235 | 234 | ||
236 | fail: | 235 | fail: |
237 | gfs2_glock_dq_uninit(&i_gh); | 236 | gfs2_glock_dq_uninit(&i_gh); |
238 | return ERR_PTR(error); | 237 | return ERR_PTR(error); |
239 | } | 238 | } |
240 | 239 | ||
241 | static struct dentry *gfs2_fh_to_dentry(struct super_block *sb, struct fid *fid, | 240 | static struct dentry *gfs2_fh_to_dentry(struct super_block *sb, struct fid *fid, |
242 | int fh_len, int fh_type) | 241 | int fh_len, int fh_type) |
243 | { | 242 | { |
244 | struct gfs2_inum_host this; | 243 | struct gfs2_inum_host this; |
245 | __be32 *fh = (__force __be32 *)fid->raw; | 244 | __be32 *fh = (__force __be32 *)fid->raw; |
246 | 245 | ||
247 | switch (fh_type) { | 246 | switch (fh_type) { |
248 | case GFS2_SMALL_FH_SIZE: | 247 | case GFS2_SMALL_FH_SIZE: |
249 | case GFS2_LARGE_FH_SIZE: | 248 | case GFS2_LARGE_FH_SIZE: |
250 | case GFS2_OLD_FH_SIZE: | 249 | case GFS2_OLD_FH_SIZE: |
251 | this.no_formal_ino = ((u64)be32_to_cpu(fh[0])) << 32; | 250 | this.no_formal_ino = ((u64)be32_to_cpu(fh[0])) << 32; |
252 | this.no_formal_ino |= be32_to_cpu(fh[1]); | 251 | this.no_formal_ino |= be32_to_cpu(fh[1]); |
253 | this.no_addr = ((u64)be32_to_cpu(fh[2])) << 32; | 252 | this.no_addr = ((u64)be32_to_cpu(fh[2])) << 32; |
254 | this.no_addr |= be32_to_cpu(fh[3]); | 253 | this.no_addr |= be32_to_cpu(fh[3]); |
255 | return gfs2_get_dentry(sb, &this); | 254 | return gfs2_get_dentry(sb, &this); |
256 | default: | 255 | default: |
257 | return NULL; | 256 | return NULL; |
258 | } | 257 | } |
259 | } | 258 | } |
260 | 259 | ||
261 | static struct dentry *gfs2_fh_to_parent(struct super_block *sb, struct fid *fid, | 260 | static struct dentry *gfs2_fh_to_parent(struct super_block *sb, struct fid *fid, |
262 | int fh_len, int fh_type) | 261 | int fh_len, int fh_type) |
263 | { | 262 | { |
264 | struct gfs2_inum_host parent; | 263 | struct gfs2_inum_host parent; |
265 | __be32 *fh = (__force __be32 *)fid->raw; | 264 | __be32 *fh = (__force __be32 *)fid->raw; |
266 | 265 | ||
267 | switch (fh_type) { | 266 | switch (fh_type) { |
268 | case GFS2_LARGE_FH_SIZE: | 267 | case GFS2_LARGE_FH_SIZE: |
269 | case GFS2_OLD_FH_SIZE: | 268 | case GFS2_OLD_FH_SIZE: |
270 | parent.no_formal_ino = ((u64)be32_to_cpu(fh[4])) << 32; | 269 | parent.no_formal_ino = ((u64)be32_to_cpu(fh[4])) << 32; |
271 | parent.no_formal_ino |= be32_to_cpu(fh[5]); | 270 | parent.no_formal_ino |= be32_to_cpu(fh[5]); |
272 | parent.no_addr = ((u64)be32_to_cpu(fh[6])) << 32; | 271 | parent.no_addr = ((u64)be32_to_cpu(fh[6])) << 32; |
273 | parent.no_addr |= be32_to_cpu(fh[7]); | 272 | parent.no_addr |= be32_to_cpu(fh[7]); |
274 | return gfs2_get_dentry(sb, &parent); | 273 | return gfs2_get_dentry(sb, &parent); |
275 | default: | 274 | default: |
276 | return NULL; | 275 | return NULL; |
277 | } | 276 | } |
278 | } | 277 | } |
279 | 278 | ||
280 | const struct export_operations gfs2_export_ops = { | 279 | const struct export_operations gfs2_export_ops = { |
281 | .encode_fh = gfs2_encode_fh, | 280 | .encode_fh = gfs2_encode_fh, |
282 | .fh_to_dentry = gfs2_fh_to_dentry, | 281 | .fh_to_dentry = gfs2_fh_to_dentry, |
283 | .fh_to_parent = gfs2_fh_to_parent, | 282 | .fh_to_parent = gfs2_fh_to_parent, |
284 | .get_name = gfs2_get_name, | 283 | .get_name = gfs2_get_name, |
285 | .get_parent = gfs2_get_parent, | 284 | .get_parent = gfs2_get_parent, |
286 | }; | 285 | }; |
287 | 286 | ||
288 | 287 |
fs/gfs2/ops_file.c
1 | /* | 1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
4 | * | 4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | 5 | * This copyrighted material is made available to anyone wishing to use, |
6 | * modify, copy, or redistribute it subject to the terms and conditions | 6 | * modify, copy, or redistribute it subject to the terms and conditions |
7 | * of the GNU General Public License version 2. | 7 | * of the GNU General Public License version 2. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
11 | #include <linux/spinlock.h> | 11 | #include <linux/spinlock.h> |
12 | #include <linux/completion.h> | 12 | #include <linux/completion.h> |
13 | #include <linux/buffer_head.h> | 13 | #include <linux/buffer_head.h> |
14 | #include <linux/pagemap.h> | 14 | #include <linux/pagemap.h> |
15 | #include <linux/uio.h> | 15 | #include <linux/uio.h> |
16 | #include <linux/blkdev.h> | 16 | #include <linux/blkdev.h> |
17 | #include <linux/mm.h> | 17 | #include <linux/mm.h> |
18 | #include <linux/mount.h> | 18 | #include <linux/mount.h> |
19 | #include <linux/fs.h> | 19 | #include <linux/fs.h> |
20 | #include <linux/gfs2_ondisk.h> | 20 | #include <linux/gfs2_ondisk.h> |
21 | #include <linux/ext2_fs.h> | 21 | #include <linux/ext2_fs.h> |
22 | #include <linux/crc32.h> | 22 | #include <linux/crc32.h> |
23 | #include <linux/lm_interface.h> | 23 | #include <linux/lm_interface.h> |
24 | #include <linux/writeback.h> | 24 | #include <linux/writeback.h> |
25 | #include <asm/uaccess.h> | 25 | #include <asm/uaccess.h> |
26 | 26 | ||
27 | #include "gfs2.h" | 27 | #include "gfs2.h" |
28 | #include "incore.h" | 28 | #include "incore.h" |
29 | #include "bmap.h" | 29 | #include "bmap.h" |
30 | #include "dir.h" | 30 | #include "dir.h" |
31 | #include "glock.h" | 31 | #include "glock.h" |
32 | #include "glops.h" | 32 | #include "glops.h" |
33 | #include "inode.h" | 33 | #include "inode.h" |
34 | #include "log.h" | 34 | #include "log.h" |
35 | #include "meta_io.h" | 35 | #include "meta_io.h" |
36 | #include "quota.h" | 36 | #include "quota.h" |
37 | #include "rgrp.h" | 37 | #include "rgrp.h" |
38 | #include "trans.h" | 38 | #include "trans.h" |
39 | #include "util.h" | 39 | #include "util.h" |
40 | #include "eaops.h" | 40 | #include "eaops.h" |
41 | #include "ops_address.h" | 41 | #include "ops_address.h" |
42 | #include "ops_inode.h" | ||
43 | 42 | ||
44 | /** | 43 | /** |
45 | * gfs2_llseek - seek to a location in a file | 44 | * gfs2_llseek - seek to a location in a file |
46 | * @file: the file | 45 | * @file: the file |
47 | * @offset: the offset | 46 | * @offset: the offset |
48 | * @origin: Where to seek from (SEEK_SET, SEEK_CUR, or SEEK_END) | 47 | * @origin: Where to seek from (SEEK_SET, SEEK_CUR, or SEEK_END) |
49 | * | 48 | * |
50 | * SEEK_END requires the glock for the file because it references the | 49 | * SEEK_END requires the glock for the file because it references the |
51 | * file's size. | 50 | * file's size. |
52 | * | 51 | * |
53 | * Returns: The new offset, or errno | 52 | * Returns: The new offset, or errno |
54 | */ | 53 | */ |
55 | 54 | ||
56 | static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) | 55 | static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) |
57 | { | 56 | { |
58 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); | 57 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); |
59 | struct gfs2_holder i_gh; | 58 | struct gfs2_holder i_gh; |
60 | loff_t error; | 59 | loff_t error; |
61 | 60 | ||
62 | if (origin == 2) { | 61 | if (origin == 2) { |
63 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, | 62 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, |
64 | &i_gh); | 63 | &i_gh); |
65 | if (!error) { | 64 | if (!error) { |
66 | error = generic_file_llseek_unlocked(file, offset, origin); | 65 | error = generic_file_llseek_unlocked(file, offset, origin); |
67 | gfs2_glock_dq_uninit(&i_gh); | 66 | gfs2_glock_dq_uninit(&i_gh); |
68 | } | 67 | } |
69 | } else | 68 | } else |
70 | error = generic_file_llseek_unlocked(file, offset, origin); | 69 | error = generic_file_llseek_unlocked(file, offset, origin); |
71 | 70 | ||
72 | return error; | 71 | return error; |
73 | } | 72 | } |
74 | 73 | ||
75 | /** | 74 | /** |
76 | * gfs2_readdir - Read directory entries from a directory | 75 | * gfs2_readdir - Read directory entries from a directory |
77 | * @file: The directory to read from | 76 | * @file: The directory to read from |
78 | * @dirent: Buffer for dirents | 77 | * @dirent: Buffer for dirents |
79 | * @filldir: Function used to do the copying | 78 | * @filldir: Function used to do the copying |
80 | * | 79 | * |
81 | * Returns: errno | 80 | * Returns: errno |
82 | */ | 81 | */ |
83 | 82 | ||
84 | static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) | 83 | static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) |
85 | { | 84 | { |
86 | struct inode *dir = file->f_mapping->host; | 85 | struct inode *dir = file->f_mapping->host; |
87 | struct gfs2_inode *dip = GFS2_I(dir); | 86 | struct gfs2_inode *dip = GFS2_I(dir); |
88 | struct gfs2_holder d_gh; | 87 | struct gfs2_holder d_gh; |
89 | u64 offset = file->f_pos; | 88 | u64 offset = file->f_pos; |
90 | int error; | 89 | int error; |
91 | 90 | ||
92 | gfs2_holder_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); | 91 | gfs2_holder_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); |
93 | error = gfs2_glock_nq(&d_gh); | 92 | error = gfs2_glock_nq(&d_gh); |
94 | if (error) { | 93 | if (error) { |
95 | gfs2_holder_uninit(&d_gh); | 94 | gfs2_holder_uninit(&d_gh); |
96 | return error; | 95 | return error; |
97 | } | 96 | } |
98 | 97 | ||
99 | error = gfs2_dir_read(dir, &offset, dirent, filldir); | 98 | error = gfs2_dir_read(dir, &offset, dirent, filldir); |
100 | 99 | ||
101 | gfs2_glock_dq_uninit(&d_gh); | 100 | gfs2_glock_dq_uninit(&d_gh); |
102 | 101 | ||
103 | file->f_pos = offset; | 102 | file->f_pos = offset; |
104 | 103 | ||
105 | return error; | 104 | return error; |
106 | } | 105 | } |
107 | 106 | ||
108 | /** | 107 | /** |
109 | * fsflags_cvt | 108 | * fsflags_cvt |
110 | * @table: A table of 32 u32 flags | 109 | * @table: A table of 32 u32 flags |
111 | * @val: a 32 bit value to convert | 110 | * @val: a 32 bit value to convert |
112 | * | 111 | * |
113 | * This function can be used to convert between fsflags values and | 112 | * This function can be used to convert between fsflags values and |
114 | * GFS2's own flags values. | 113 | * GFS2's own flags values. |
115 | * | 114 | * |
116 | * Returns: the converted flags | 115 | * Returns: the converted flags |
117 | */ | 116 | */ |
118 | static u32 fsflags_cvt(const u32 *table, u32 val) | 117 | static u32 fsflags_cvt(const u32 *table, u32 val) |
119 | { | 118 | { |
120 | u32 res = 0; | 119 | u32 res = 0; |
121 | while(val) { | 120 | while(val) { |
122 | if (val & 1) | 121 | if (val & 1) |
123 | res |= *table; | 122 | res |= *table; |
124 | table++; | 123 | table++; |
125 | val >>= 1; | 124 | val >>= 1; |
126 | } | 125 | } |
127 | return res; | 126 | return res; |
128 | } | 127 | } |
129 | 128 | ||
130 | static const u32 fsflags_to_gfs2[32] = { | 129 | static const u32 fsflags_to_gfs2[32] = { |
131 | [3] = GFS2_DIF_SYNC, | 130 | [3] = GFS2_DIF_SYNC, |
132 | [4] = GFS2_DIF_IMMUTABLE, | 131 | [4] = GFS2_DIF_IMMUTABLE, |
133 | [5] = GFS2_DIF_APPENDONLY, | 132 | [5] = GFS2_DIF_APPENDONLY, |
134 | [7] = GFS2_DIF_NOATIME, | 133 | [7] = GFS2_DIF_NOATIME, |
135 | [12] = GFS2_DIF_EXHASH, | 134 | [12] = GFS2_DIF_EXHASH, |
136 | [14] = GFS2_DIF_INHERIT_JDATA, | 135 | [14] = GFS2_DIF_INHERIT_JDATA, |
137 | }; | 136 | }; |
138 | 137 | ||
139 | static const u32 gfs2_to_fsflags[32] = { | 138 | static const u32 gfs2_to_fsflags[32] = { |
140 | [gfs2fl_Sync] = FS_SYNC_FL, | 139 | [gfs2fl_Sync] = FS_SYNC_FL, |
141 | [gfs2fl_Immutable] = FS_IMMUTABLE_FL, | 140 | [gfs2fl_Immutable] = FS_IMMUTABLE_FL, |
142 | [gfs2fl_AppendOnly] = FS_APPEND_FL, | 141 | [gfs2fl_AppendOnly] = FS_APPEND_FL, |
143 | [gfs2fl_NoAtime] = FS_NOATIME_FL, | 142 | [gfs2fl_NoAtime] = FS_NOATIME_FL, |
144 | [gfs2fl_ExHash] = FS_INDEX_FL, | 143 | [gfs2fl_ExHash] = FS_INDEX_FL, |
145 | [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL, | 144 | [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL, |
146 | }; | 145 | }; |
147 | 146 | ||
148 | static int gfs2_get_flags(struct file *filp, u32 __user *ptr) | 147 | static int gfs2_get_flags(struct file *filp, u32 __user *ptr) |
149 | { | 148 | { |
150 | struct inode *inode = filp->f_path.dentry->d_inode; | 149 | struct inode *inode = filp->f_path.dentry->d_inode; |
151 | struct gfs2_inode *ip = GFS2_I(inode); | 150 | struct gfs2_inode *ip = GFS2_I(inode); |
152 | struct gfs2_holder gh; | 151 | struct gfs2_holder gh; |
153 | int error; | 152 | int error; |
154 | u32 fsflags; | 153 | u32 fsflags; |
155 | 154 | ||
156 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &gh); | 155 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &gh); |
157 | error = gfs2_glock_nq(&gh); | 156 | error = gfs2_glock_nq(&gh); |
158 | if (error) | 157 | if (error) |
159 | return error; | 158 | return error; |
160 | 159 | ||
161 | fsflags = fsflags_cvt(gfs2_to_fsflags, ip->i_di.di_flags); | 160 | fsflags = fsflags_cvt(gfs2_to_fsflags, ip->i_di.di_flags); |
162 | if (!S_ISDIR(inode->i_mode) && ip->i_di.di_flags & GFS2_DIF_JDATA) | 161 | if (!S_ISDIR(inode->i_mode) && ip->i_di.di_flags & GFS2_DIF_JDATA) |
163 | fsflags |= FS_JOURNAL_DATA_FL; | 162 | fsflags |= FS_JOURNAL_DATA_FL; |
164 | if (put_user(fsflags, ptr)) | 163 | if (put_user(fsflags, ptr)) |
165 | error = -EFAULT; | 164 | error = -EFAULT; |
166 | 165 | ||
167 | gfs2_glock_dq(&gh); | 166 | gfs2_glock_dq(&gh); |
168 | gfs2_holder_uninit(&gh); | 167 | gfs2_holder_uninit(&gh); |
169 | return error; | 168 | return error; |
170 | } | 169 | } |
171 | 170 | ||
172 | void gfs2_set_inode_flags(struct inode *inode) | 171 | void gfs2_set_inode_flags(struct inode *inode) |
173 | { | 172 | { |
174 | struct gfs2_inode *ip = GFS2_I(inode); | 173 | struct gfs2_inode *ip = GFS2_I(inode); |
175 | struct gfs2_dinode_host *di = &ip->i_di; | 174 | struct gfs2_dinode_host *di = &ip->i_di; |
176 | unsigned int flags = inode->i_flags; | 175 | unsigned int flags = inode->i_flags; |
177 | 176 | ||
178 | flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC); | 177 | flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC); |
179 | if (di->di_flags & GFS2_DIF_IMMUTABLE) | 178 | if (di->di_flags & GFS2_DIF_IMMUTABLE) |
180 | flags |= S_IMMUTABLE; | 179 | flags |= S_IMMUTABLE; |
181 | if (di->di_flags & GFS2_DIF_APPENDONLY) | 180 | if (di->di_flags & GFS2_DIF_APPENDONLY) |
182 | flags |= S_APPEND; | 181 | flags |= S_APPEND; |
183 | if (di->di_flags & GFS2_DIF_NOATIME) | 182 | if (di->di_flags & GFS2_DIF_NOATIME) |
184 | flags |= S_NOATIME; | 183 | flags |= S_NOATIME; |
185 | if (di->di_flags & GFS2_DIF_SYNC) | 184 | if (di->di_flags & GFS2_DIF_SYNC) |
186 | flags |= S_SYNC; | 185 | flags |= S_SYNC; |
187 | inode->i_flags = flags; | 186 | inode->i_flags = flags; |
188 | } | 187 | } |
189 | 188 | ||
190 | /* Flags that can be set by user space */ | 189 | /* Flags that can be set by user space */ |
191 | #define GFS2_FLAGS_USER_SET (GFS2_DIF_JDATA| \ | 190 | #define GFS2_FLAGS_USER_SET (GFS2_DIF_JDATA| \ |
192 | GFS2_DIF_IMMUTABLE| \ | 191 | GFS2_DIF_IMMUTABLE| \ |
193 | GFS2_DIF_APPENDONLY| \ | 192 | GFS2_DIF_APPENDONLY| \ |
194 | GFS2_DIF_NOATIME| \ | 193 | GFS2_DIF_NOATIME| \ |
195 | GFS2_DIF_SYNC| \ | 194 | GFS2_DIF_SYNC| \ |
196 | GFS2_DIF_SYSTEM| \ | 195 | GFS2_DIF_SYSTEM| \ |
197 | GFS2_DIF_INHERIT_JDATA) | 196 | GFS2_DIF_INHERIT_JDATA) |
198 | 197 | ||
199 | /** | 198 | /** |
200 | * gfs2_set_flags - set flags on an inode | 199 | * gfs2_set_flags - set flags on an inode |
201 | * @inode: The inode | 200 | * @inode: The inode |
202 | * @flags: The flags to set | 201 | * @flags: The flags to set |
203 | * @mask: Indicates which flags are valid | 202 | * @mask: Indicates which flags are valid |
204 | * | 203 | * |
205 | */ | 204 | */ |
206 | static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) | 205 | static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) |
207 | { | 206 | { |
208 | struct inode *inode = filp->f_path.dentry->d_inode; | 207 | struct inode *inode = filp->f_path.dentry->d_inode; |
209 | struct gfs2_inode *ip = GFS2_I(inode); | 208 | struct gfs2_inode *ip = GFS2_I(inode); |
210 | struct gfs2_sbd *sdp = GFS2_SB(inode); | 209 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
211 | struct buffer_head *bh; | 210 | struct buffer_head *bh; |
212 | struct gfs2_holder gh; | 211 | struct gfs2_holder gh; |
213 | int error; | 212 | int error; |
214 | u32 new_flags, flags; | 213 | u32 new_flags, flags; |
215 | 214 | ||
216 | error = mnt_want_write(filp->f_path.mnt); | 215 | error = mnt_want_write(filp->f_path.mnt); |
217 | if (error) | 216 | if (error) |
218 | return error; | 217 | return error; |
219 | 218 | ||
220 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); | 219 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
221 | if (error) | 220 | if (error) |
222 | goto out_drop_write; | 221 | goto out_drop_write; |
223 | 222 | ||
224 | flags = ip->i_di.di_flags; | 223 | flags = ip->i_di.di_flags; |
225 | new_flags = (flags & ~mask) | (reqflags & mask); | 224 | new_flags = (flags & ~mask) | (reqflags & mask); |
226 | if ((new_flags ^ flags) == 0) | 225 | if ((new_flags ^ flags) == 0) |
227 | goto out; | 226 | goto out; |
228 | 227 | ||
229 | error = -EINVAL; | 228 | error = -EINVAL; |
230 | if ((new_flags ^ flags) & ~GFS2_FLAGS_USER_SET) | 229 | if ((new_flags ^ flags) & ~GFS2_FLAGS_USER_SET) |
231 | goto out; | 230 | goto out; |
232 | 231 | ||
233 | error = -EPERM; | 232 | error = -EPERM; |
234 | if (IS_IMMUTABLE(inode) && (new_flags & GFS2_DIF_IMMUTABLE)) | 233 | if (IS_IMMUTABLE(inode) && (new_flags & GFS2_DIF_IMMUTABLE)) |
235 | goto out; | 234 | goto out; |
236 | if (IS_APPEND(inode) && (new_flags & GFS2_DIF_APPENDONLY)) | 235 | if (IS_APPEND(inode) && (new_flags & GFS2_DIF_APPENDONLY)) |
237 | goto out; | 236 | goto out; |
238 | if (((new_flags ^ flags) & GFS2_DIF_IMMUTABLE) && | 237 | if (((new_flags ^ flags) & GFS2_DIF_IMMUTABLE) && |
239 | !capable(CAP_LINUX_IMMUTABLE)) | 238 | !capable(CAP_LINUX_IMMUTABLE)) |
240 | goto out; | 239 | goto out; |
241 | if (!IS_IMMUTABLE(inode)) { | 240 | if (!IS_IMMUTABLE(inode)) { |
242 | error = gfs2_permission(inode, MAY_WRITE); | 241 | error = gfs2_permission(inode, MAY_WRITE); |
243 | if (error) | 242 | if (error) |
244 | goto out; | 243 | goto out; |
245 | } | 244 | } |
246 | if ((flags ^ new_flags) & GFS2_DIF_JDATA) { | 245 | if ((flags ^ new_flags) & GFS2_DIF_JDATA) { |
247 | if (flags & GFS2_DIF_JDATA) | 246 | if (flags & GFS2_DIF_JDATA) |
248 | gfs2_log_flush(sdp, ip->i_gl); | 247 | gfs2_log_flush(sdp, ip->i_gl); |
249 | error = filemap_fdatawrite(inode->i_mapping); | 248 | error = filemap_fdatawrite(inode->i_mapping); |
250 | if (error) | 249 | if (error) |
251 | goto out; | 250 | goto out; |
252 | error = filemap_fdatawait(inode->i_mapping); | 251 | error = filemap_fdatawait(inode->i_mapping); |
253 | if (error) | 252 | if (error) |
254 | goto out; | 253 | goto out; |
255 | } | 254 | } |
256 | error = gfs2_trans_begin(sdp, RES_DINODE, 0); | 255 | error = gfs2_trans_begin(sdp, RES_DINODE, 0); |
257 | if (error) | 256 | if (error) |
258 | goto out; | 257 | goto out; |
259 | error = gfs2_meta_inode_buffer(ip, &bh); | 258 | error = gfs2_meta_inode_buffer(ip, &bh); |
260 | if (error) | 259 | if (error) |
261 | goto out_trans_end; | 260 | goto out_trans_end; |
262 | gfs2_trans_add_bh(ip->i_gl, bh, 1); | 261 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
263 | ip->i_di.di_flags = new_flags; | 262 | ip->i_di.di_flags = new_flags; |
264 | gfs2_dinode_out(ip, bh->b_data); | 263 | gfs2_dinode_out(ip, bh->b_data); |
265 | brelse(bh); | 264 | brelse(bh); |
266 | gfs2_set_inode_flags(inode); | 265 | gfs2_set_inode_flags(inode); |
267 | gfs2_set_aops(inode); | 266 | gfs2_set_aops(inode); |
268 | out_trans_end: | 267 | out_trans_end: |
269 | gfs2_trans_end(sdp); | 268 | gfs2_trans_end(sdp); |
270 | out: | 269 | out: |
271 | gfs2_glock_dq_uninit(&gh); | 270 | gfs2_glock_dq_uninit(&gh); |
272 | out_drop_write: | 271 | out_drop_write: |
273 | mnt_drop_write(filp->f_path.mnt); | 272 | mnt_drop_write(filp->f_path.mnt); |
274 | return error; | 273 | return error; |
275 | } | 274 | } |
276 | 275 | ||
277 | static int gfs2_set_flags(struct file *filp, u32 __user *ptr) | 276 | static int gfs2_set_flags(struct file *filp, u32 __user *ptr) |
278 | { | 277 | { |
279 | struct inode *inode = filp->f_path.dentry->d_inode; | 278 | struct inode *inode = filp->f_path.dentry->d_inode; |
280 | u32 fsflags, gfsflags; | 279 | u32 fsflags, gfsflags; |
281 | if (get_user(fsflags, ptr)) | 280 | if (get_user(fsflags, ptr)) |
282 | return -EFAULT; | 281 | return -EFAULT; |
283 | gfsflags = fsflags_cvt(fsflags_to_gfs2, fsflags); | 282 | gfsflags = fsflags_cvt(fsflags_to_gfs2, fsflags); |
284 | if (!S_ISDIR(inode->i_mode)) { | 283 | if (!S_ISDIR(inode->i_mode)) { |
285 | if (gfsflags & GFS2_DIF_INHERIT_JDATA) | 284 | if (gfsflags & GFS2_DIF_INHERIT_JDATA) |
286 | gfsflags ^= (GFS2_DIF_JDATA | GFS2_DIF_INHERIT_JDATA); | 285 | gfsflags ^= (GFS2_DIF_JDATA | GFS2_DIF_INHERIT_JDATA); |
287 | return do_gfs2_set_flags(filp, gfsflags, ~0); | 286 | return do_gfs2_set_flags(filp, gfsflags, ~0); |
288 | } | 287 | } |
289 | return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA); | 288 | return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA); |
290 | } | 289 | } |
291 | 290 | ||
292 | static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | 291 | static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
293 | { | 292 | { |
294 | switch(cmd) { | 293 | switch(cmd) { |
295 | case FS_IOC_GETFLAGS: | 294 | case FS_IOC_GETFLAGS: |
296 | return gfs2_get_flags(filp, (u32 __user *)arg); | 295 | return gfs2_get_flags(filp, (u32 __user *)arg); |
297 | case FS_IOC_SETFLAGS: | 296 | case FS_IOC_SETFLAGS: |
298 | return gfs2_set_flags(filp, (u32 __user *)arg); | 297 | return gfs2_set_flags(filp, (u32 __user *)arg); |
299 | } | 298 | } |
300 | return -ENOTTY; | 299 | return -ENOTTY; |
301 | } | 300 | } |
302 | 301 | ||
303 | /** | 302 | /** |
304 | * gfs2_allocate_page_backing - Use bmap to allocate blocks | 303 | * gfs2_allocate_page_backing - Use bmap to allocate blocks |
305 | * @page: The (locked) page to allocate backing for | 304 | * @page: The (locked) page to allocate backing for |
306 | * | 305 | * |
307 | * We try to allocate all the blocks required for the page in | 306 | * We try to allocate all the blocks required for the page in |
308 | * one go. This might fail for various reasons, so we keep | 307 | * one go. This might fail for various reasons, so we keep |
309 | * trying until all the blocks to back this page are allocated. | 308 | * trying until all the blocks to back this page are allocated. |
310 | * If some of the blocks are already allocated, thats ok too. | 309 | * If some of the blocks are already allocated, thats ok too. |
311 | */ | 310 | */ |
312 | 311 | ||
313 | static int gfs2_allocate_page_backing(struct page *page) | 312 | static int gfs2_allocate_page_backing(struct page *page) |
314 | { | 313 | { |
315 | struct inode *inode = page->mapping->host; | 314 | struct inode *inode = page->mapping->host; |
316 | struct buffer_head bh; | 315 | struct buffer_head bh; |
317 | unsigned long size = PAGE_CACHE_SIZE; | 316 | unsigned long size = PAGE_CACHE_SIZE; |
318 | u64 lblock = page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits); | 317 | u64 lblock = page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits); |
319 | 318 | ||
320 | do { | 319 | do { |
321 | bh.b_state = 0; | 320 | bh.b_state = 0; |
322 | bh.b_size = size; | 321 | bh.b_size = size; |
323 | gfs2_block_map(inode, lblock, &bh, 1); | 322 | gfs2_block_map(inode, lblock, &bh, 1); |
324 | if (!buffer_mapped(&bh)) | 323 | if (!buffer_mapped(&bh)) |
325 | return -EIO; | 324 | return -EIO; |
326 | size -= bh.b_size; | 325 | size -= bh.b_size; |
327 | lblock += (bh.b_size >> inode->i_blkbits); | 326 | lblock += (bh.b_size >> inode->i_blkbits); |
328 | } while(size > 0); | 327 | } while(size > 0); |
329 | return 0; | 328 | return 0; |
330 | } | 329 | } |
331 | 330 | ||
332 | /** | 331 | /** |
333 | * gfs2_page_mkwrite - Make a shared, mmap()ed, page writable | 332 | * gfs2_page_mkwrite - Make a shared, mmap()ed, page writable |
334 | * @vma: The virtual memory area | 333 | * @vma: The virtual memory area |
335 | * @page: The page which is about to become writable | 334 | * @page: The page which is about to become writable |
336 | * | 335 | * |
337 | * When the page becomes writable, we need to ensure that we have | 336 | * When the page becomes writable, we need to ensure that we have |
338 | * blocks allocated on disk to back that page. | 337 | * blocks allocated on disk to back that page. |
339 | */ | 338 | */ |
340 | 339 | ||
341 | static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct page *page) | 340 | static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct page *page) |
342 | { | 341 | { |
343 | struct inode *inode = vma->vm_file->f_path.dentry->d_inode; | 342 | struct inode *inode = vma->vm_file->f_path.dentry->d_inode; |
344 | struct gfs2_inode *ip = GFS2_I(inode); | 343 | struct gfs2_inode *ip = GFS2_I(inode); |
345 | struct gfs2_sbd *sdp = GFS2_SB(inode); | 344 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
346 | unsigned long last_index; | 345 | unsigned long last_index; |
347 | u64 pos = page->index << (PAGE_CACHE_SIZE - inode->i_blkbits); | 346 | u64 pos = page->index << (PAGE_CACHE_SIZE - inode->i_blkbits); |
348 | unsigned int data_blocks, ind_blocks, rblocks; | 347 | unsigned int data_blocks, ind_blocks, rblocks; |
349 | int alloc_required = 0; | 348 | int alloc_required = 0; |
350 | struct gfs2_holder gh; | 349 | struct gfs2_holder gh; |
351 | struct gfs2_alloc *al; | 350 | struct gfs2_alloc *al; |
352 | int ret; | 351 | int ret; |
353 | 352 | ||
354 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); | 353 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
355 | ret = gfs2_glock_nq(&gh); | 354 | ret = gfs2_glock_nq(&gh); |
356 | if (ret) | 355 | if (ret) |
357 | goto out; | 356 | goto out; |
358 | 357 | ||
359 | set_bit(GIF_SW_PAGED, &ip->i_flags); | 358 | set_bit(GIF_SW_PAGED, &ip->i_flags); |
360 | gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks); | 359 | gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks); |
361 | ret = gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE, &alloc_required); | 360 | ret = gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE, &alloc_required); |
362 | if (ret || !alloc_required) | 361 | if (ret || !alloc_required) |
363 | goto out_unlock; | 362 | goto out_unlock; |
364 | ret = -ENOMEM; | 363 | ret = -ENOMEM; |
365 | al = gfs2_alloc_get(ip); | 364 | al = gfs2_alloc_get(ip); |
366 | if (al == NULL) | 365 | if (al == NULL) |
367 | goto out_unlock; | 366 | goto out_unlock; |
368 | 367 | ||
369 | ret = gfs2_quota_lock_check(ip); | 368 | ret = gfs2_quota_lock_check(ip); |
370 | if (ret) | 369 | if (ret) |
371 | goto out_alloc_put; | 370 | goto out_alloc_put; |
372 | al->al_requested = data_blocks + ind_blocks; | 371 | al->al_requested = data_blocks + ind_blocks; |
373 | ret = gfs2_inplace_reserve(ip); | 372 | ret = gfs2_inplace_reserve(ip); |
374 | if (ret) | 373 | if (ret) |
375 | goto out_quota_unlock; | 374 | goto out_quota_unlock; |
376 | 375 | ||
377 | rblocks = RES_DINODE + ind_blocks; | 376 | rblocks = RES_DINODE + ind_blocks; |
378 | if (gfs2_is_jdata(ip)) | 377 | if (gfs2_is_jdata(ip)) |
379 | rblocks += data_blocks ? data_blocks : 1; | 378 | rblocks += data_blocks ? data_blocks : 1; |
380 | if (ind_blocks || data_blocks) | 379 | if (ind_blocks || data_blocks) |
381 | rblocks += RES_STATFS + RES_QUOTA; | 380 | rblocks += RES_STATFS + RES_QUOTA; |
382 | ret = gfs2_trans_begin(sdp, rblocks, 0); | 381 | ret = gfs2_trans_begin(sdp, rblocks, 0); |
383 | if (ret) | 382 | if (ret) |
384 | goto out_trans_fail; | 383 | goto out_trans_fail; |
385 | 384 | ||
386 | lock_page(page); | 385 | lock_page(page); |
387 | ret = -EINVAL; | 386 | ret = -EINVAL; |
388 | last_index = ip->i_inode.i_size >> PAGE_CACHE_SHIFT; | 387 | last_index = ip->i_inode.i_size >> PAGE_CACHE_SHIFT; |
389 | if (page->index > last_index) | 388 | if (page->index > last_index) |
390 | goto out_unlock_page; | 389 | goto out_unlock_page; |
391 | ret = 0; | 390 | ret = 0; |
392 | if (!PageUptodate(page) || page->mapping != ip->i_inode.i_mapping) | 391 | if (!PageUptodate(page) || page->mapping != ip->i_inode.i_mapping) |
393 | goto out_unlock_page; | 392 | goto out_unlock_page; |
394 | if (gfs2_is_stuffed(ip)) { | 393 | if (gfs2_is_stuffed(ip)) { |
395 | ret = gfs2_unstuff_dinode(ip, page); | 394 | ret = gfs2_unstuff_dinode(ip, page); |
396 | if (ret) | 395 | if (ret) |
397 | goto out_unlock_page; | 396 | goto out_unlock_page; |
398 | } | 397 | } |
399 | ret = gfs2_allocate_page_backing(page); | 398 | ret = gfs2_allocate_page_backing(page); |
400 | 399 | ||
401 | out_unlock_page: | 400 | out_unlock_page: |
402 | unlock_page(page); | 401 | unlock_page(page); |
403 | gfs2_trans_end(sdp); | 402 | gfs2_trans_end(sdp); |
404 | out_trans_fail: | 403 | out_trans_fail: |
405 | gfs2_inplace_release(ip); | 404 | gfs2_inplace_release(ip); |
406 | out_quota_unlock: | 405 | out_quota_unlock: |
407 | gfs2_quota_unlock(ip); | 406 | gfs2_quota_unlock(ip); |
408 | out_alloc_put: | 407 | out_alloc_put: |
409 | gfs2_alloc_put(ip); | 408 | gfs2_alloc_put(ip); |
410 | out_unlock: | 409 | out_unlock: |
411 | gfs2_glock_dq(&gh); | 410 | gfs2_glock_dq(&gh); |
412 | out: | 411 | out: |
413 | gfs2_holder_uninit(&gh); | 412 | gfs2_holder_uninit(&gh); |
414 | return ret; | 413 | return ret; |
415 | } | 414 | } |
416 | 415 | ||
417 | static struct vm_operations_struct gfs2_vm_ops = { | 416 | static struct vm_operations_struct gfs2_vm_ops = { |
418 | .fault = filemap_fault, | 417 | .fault = filemap_fault, |
419 | .page_mkwrite = gfs2_page_mkwrite, | 418 | .page_mkwrite = gfs2_page_mkwrite, |
420 | }; | 419 | }; |
421 | 420 | ||
422 | 421 | ||
423 | /** | 422 | /** |
424 | * gfs2_mmap - | 423 | * gfs2_mmap - |
425 | * @file: The file to map | 424 | * @file: The file to map |
426 | * @vma: The VMA which described the mapping | 425 | * @vma: The VMA which described the mapping |
427 | * | 426 | * |
428 | * Returns: 0 or error code | 427 | * Returns: 0 or error code |
429 | */ | 428 | */ |
430 | 429 | ||
431 | static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) | 430 | static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) |
432 | { | 431 | { |
433 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); | 432 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); |
434 | struct gfs2_holder i_gh; | 433 | struct gfs2_holder i_gh; |
435 | int error; | 434 | int error; |
436 | 435 | ||
437 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); | 436 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); |
438 | error = gfs2_glock_nq(&i_gh); | 437 | error = gfs2_glock_nq(&i_gh); |
439 | if (error) { | 438 | if (error) { |
440 | gfs2_holder_uninit(&i_gh); | 439 | gfs2_holder_uninit(&i_gh); |
441 | return error; | 440 | return error; |
442 | } | 441 | } |
443 | 442 | ||
444 | vma->vm_ops = &gfs2_vm_ops; | 443 | vma->vm_ops = &gfs2_vm_ops; |
445 | 444 | ||
446 | gfs2_glock_dq_uninit(&i_gh); | 445 | gfs2_glock_dq_uninit(&i_gh); |
447 | 446 | ||
448 | return error; | 447 | return error; |
449 | } | 448 | } |
450 | 449 | ||
451 | /** | 450 | /** |
452 | * gfs2_open - open a file | 451 | * gfs2_open - open a file |
453 | * @inode: the inode to open | 452 | * @inode: the inode to open |
454 | * @file: the struct file for this opening | 453 | * @file: the struct file for this opening |
455 | * | 454 | * |
456 | * Returns: errno | 455 | * Returns: errno |
457 | */ | 456 | */ |
458 | 457 | ||
459 | static int gfs2_open(struct inode *inode, struct file *file) | 458 | static int gfs2_open(struct inode *inode, struct file *file) |
460 | { | 459 | { |
461 | struct gfs2_inode *ip = GFS2_I(inode); | 460 | struct gfs2_inode *ip = GFS2_I(inode); |
462 | struct gfs2_holder i_gh; | 461 | struct gfs2_holder i_gh; |
463 | struct gfs2_file *fp; | 462 | struct gfs2_file *fp; |
464 | int error; | 463 | int error; |
465 | 464 | ||
466 | fp = kzalloc(sizeof(struct gfs2_file), GFP_KERNEL); | 465 | fp = kzalloc(sizeof(struct gfs2_file), GFP_KERNEL); |
467 | if (!fp) | 466 | if (!fp) |
468 | return -ENOMEM; | 467 | return -ENOMEM; |
469 | 468 | ||
470 | mutex_init(&fp->f_fl_mutex); | 469 | mutex_init(&fp->f_fl_mutex); |
471 | 470 | ||
472 | gfs2_assert_warn(GFS2_SB(inode), !file->private_data); | 471 | gfs2_assert_warn(GFS2_SB(inode), !file->private_data); |
473 | file->private_data = fp; | 472 | file->private_data = fp; |
474 | 473 | ||
475 | if (S_ISREG(ip->i_inode.i_mode)) { | 474 | if (S_ISREG(ip->i_inode.i_mode)) { |
476 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, | 475 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, |
477 | &i_gh); | 476 | &i_gh); |
478 | if (error) | 477 | if (error) |
479 | goto fail; | 478 | goto fail; |
480 | 479 | ||
481 | if (!(file->f_flags & O_LARGEFILE) && | 480 | if (!(file->f_flags & O_LARGEFILE) && |
482 | ip->i_di.di_size > MAX_NON_LFS) { | 481 | ip->i_di.di_size > MAX_NON_LFS) { |
483 | error = -EOVERFLOW; | 482 | error = -EOVERFLOW; |
484 | goto fail_gunlock; | 483 | goto fail_gunlock; |
485 | } | 484 | } |
486 | 485 | ||
487 | gfs2_glock_dq_uninit(&i_gh); | 486 | gfs2_glock_dq_uninit(&i_gh); |
488 | } | 487 | } |
489 | 488 | ||
490 | return 0; | 489 | return 0; |
491 | 490 | ||
492 | fail_gunlock: | 491 | fail_gunlock: |
493 | gfs2_glock_dq_uninit(&i_gh); | 492 | gfs2_glock_dq_uninit(&i_gh); |
494 | fail: | 493 | fail: |
495 | file->private_data = NULL; | 494 | file->private_data = NULL; |
496 | kfree(fp); | 495 | kfree(fp); |
497 | return error; | 496 | return error; |
498 | } | 497 | } |
499 | 498 | ||
500 | /** | 499 | /** |
501 | * gfs2_close - called to close a struct file | 500 | * gfs2_close - called to close a struct file |
502 | * @inode: the inode the struct file belongs to | 501 | * @inode: the inode the struct file belongs to |
503 | * @file: the struct file being closed | 502 | * @file: the struct file being closed |
504 | * | 503 | * |
505 | * Returns: errno | 504 | * Returns: errno |
506 | */ | 505 | */ |
507 | 506 | ||
508 | static int gfs2_close(struct inode *inode, struct file *file) | 507 | static int gfs2_close(struct inode *inode, struct file *file) |
509 | { | 508 | { |
510 | struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; | 509 | struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; |
511 | struct gfs2_file *fp; | 510 | struct gfs2_file *fp; |
512 | 511 | ||
513 | fp = file->private_data; | 512 | fp = file->private_data; |
514 | file->private_data = NULL; | 513 | file->private_data = NULL; |
515 | 514 | ||
516 | if (gfs2_assert_warn(sdp, fp)) | 515 | if (gfs2_assert_warn(sdp, fp)) |
517 | return -EIO; | 516 | return -EIO; |
518 | 517 | ||
519 | kfree(fp); | 518 | kfree(fp); |
520 | 519 | ||
521 | return 0; | 520 | return 0; |
522 | } | 521 | } |
523 | 522 | ||
524 | /** | 523 | /** |
525 | * gfs2_fsync - sync the dirty data for a file (across the cluster) | 524 | * gfs2_fsync - sync the dirty data for a file (across the cluster) |
526 | * @file: the file that points to the dentry (we ignore this) | 525 | * @file: the file that points to the dentry (we ignore this) |
527 | * @dentry: the dentry that points to the inode to sync | 526 | * @dentry: the dentry that points to the inode to sync |
528 | * | 527 | * |
529 | * The VFS will flush "normal" data for us. We only need to worry | 528 | * The VFS will flush "normal" data for us. We only need to worry |
530 | * about metadata here. For journaled data, we just do a log flush | 529 | * about metadata here. For journaled data, we just do a log flush |
531 | * as we can't avoid it. Otherwise we can just bale out if datasync | 530 | * as we can't avoid it. Otherwise we can just bale out if datasync |
532 | * is set. For stuffed inodes we must flush the log in order to | 531 | * is set. For stuffed inodes we must flush the log in order to |
533 | * ensure that all data is on disk. | 532 | * ensure that all data is on disk. |
534 | * | 533 | * |
535 | * The call to write_inode_now() is there to write back metadata and | 534 | * The call to write_inode_now() is there to write back metadata and |
536 | * the inode itself. It does also try and write the data, but thats | 535 | * the inode itself. It does also try and write the data, but thats |
537 | * (hopefully) a no-op due to the VFS having already called filemap_fdatawrite() | 536 | * (hopefully) a no-op due to the VFS having already called filemap_fdatawrite() |
538 | * for us. | 537 | * for us. |
539 | * | 538 | * |
540 | * Returns: errno | 539 | * Returns: errno |
541 | */ | 540 | */ |
542 | 541 | ||
543 | static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) | 542 | static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) |
544 | { | 543 | { |
545 | struct inode *inode = dentry->d_inode; | 544 | struct inode *inode = dentry->d_inode; |
546 | int sync_state = inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC); | 545 | int sync_state = inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC); |
547 | int ret = 0; | 546 | int ret = 0; |
548 | 547 | ||
549 | if (gfs2_is_jdata(GFS2_I(inode))) { | 548 | if (gfs2_is_jdata(GFS2_I(inode))) { |
550 | gfs2_log_flush(GFS2_SB(inode), GFS2_I(inode)->i_gl); | 549 | gfs2_log_flush(GFS2_SB(inode), GFS2_I(inode)->i_gl); |
551 | return 0; | 550 | return 0; |
552 | } | 551 | } |
553 | 552 | ||
554 | if (sync_state != 0) { | 553 | if (sync_state != 0) { |
555 | if (!datasync) | 554 | if (!datasync) |
556 | ret = write_inode_now(inode, 0); | 555 | ret = write_inode_now(inode, 0); |
557 | 556 | ||
558 | if (gfs2_is_stuffed(GFS2_I(inode))) | 557 | if (gfs2_is_stuffed(GFS2_I(inode))) |
559 | gfs2_log_flush(GFS2_SB(inode), GFS2_I(inode)->i_gl); | 558 | gfs2_log_flush(GFS2_SB(inode), GFS2_I(inode)->i_gl); |
560 | } | 559 | } |
561 | 560 | ||
562 | return ret; | 561 | return ret; |
563 | } | 562 | } |
564 | 563 | ||
565 | /** | 564 | /** |
566 | * gfs2_setlease - acquire/release a file lease | 565 | * gfs2_setlease - acquire/release a file lease |
567 | * @file: the file pointer | 566 | * @file: the file pointer |
568 | * @arg: lease type | 567 | * @arg: lease type |
569 | * @fl: file lock | 568 | * @fl: file lock |
570 | * | 569 | * |
571 | * Returns: errno | 570 | * Returns: errno |
572 | */ | 571 | */ |
573 | 572 | ||
574 | static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl) | 573 | static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl) |
575 | { | 574 | { |
576 | struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); | 575 | struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); |
577 | 576 | ||
578 | /* | 577 | /* |
579 | * We don't currently have a way to enforce a lease across the whole | 578 | * We don't currently have a way to enforce a lease across the whole |
580 | * cluster; until we do, disable leases (by just returning -EINVAL), | 579 | * cluster; until we do, disable leases (by just returning -EINVAL), |
581 | * unless the administrator has requested purely local locking. | 580 | * unless the administrator has requested purely local locking. |
582 | */ | 581 | */ |
583 | if (!sdp->sd_args.ar_localflocks) | 582 | if (!sdp->sd_args.ar_localflocks) |
584 | return -EINVAL; | 583 | return -EINVAL; |
585 | return generic_setlease(file, arg, fl); | 584 | return generic_setlease(file, arg, fl); |
586 | } | 585 | } |
587 | 586 | ||
588 | static int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, | 587 | static int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name, |
589 | struct file *file, struct file_lock *fl) | 588 | struct file *file, struct file_lock *fl) |
590 | { | 589 | { |
591 | int error = -EIO; | 590 | int error = -EIO; |
592 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | 591 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
593 | error = sdp->sd_lockstruct.ls_ops->lm_plock_get( | 592 | error = sdp->sd_lockstruct.ls_ops->lm_plock_get( |
594 | sdp->sd_lockstruct.ls_lockspace, name, file, fl); | 593 | sdp->sd_lockstruct.ls_lockspace, name, file, fl); |
595 | return error; | 594 | return error; |
596 | } | 595 | } |
597 | 596 | ||
598 | static int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name, | 597 | static int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name, |
599 | struct file *file, int cmd, struct file_lock *fl) | 598 | struct file *file, int cmd, struct file_lock *fl) |
600 | { | 599 | { |
601 | int error = -EIO; | 600 | int error = -EIO; |
602 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | 601 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
603 | error = sdp->sd_lockstruct.ls_ops->lm_plock( | 602 | error = sdp->sd_lockstruct.ls_ops->lm_plock( |
604 | sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl); | 603 | sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl); |
605 | return error; | 604 | return error; |
606 | } | 605 | } |
607 | 606 | ||
608 | static int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name, | 607 | static int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name, |
609 | struct file *file, struct file_lock *fl) | 608 | struct file *file, struct file_lock *fl) |
610 | { | 609 | { |
611 | int error = -EIO; | 610 | int error = -EIO; |
612 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | 611 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
613 | error = sdp->sd_lockstruct.ls_ops->lm_punlock( | 612 | error = sdp->sd_lockstruct.ls_ops->lm_punlock( |
614 | sdp->sd_lockstruct.ls_lockspace, name, file, fl); | 613 | sdp->sd_lockstruct.ls_lockspace, name, file, fl); |
615 | return error; | 614 | return error; |
616 | } | 615 | } |
617 | 616 | ||
618 | /** | 617 | /** |
619 | * gfs2_lock - acquire/release a posix lock on a file | 618 | * gfs2_lock - acquire/release a posix lock on a file |
620 | * @file: the file pointer | 619 | * @file: the file pointer |
621 | * @cmd: either modify or retrieve lock state, possibly wait | 620 | * @cmd: either modify or retrieve lock state, possibly wait |
622 | * @fl: type and range of lock | 621 | * @fl: type and range of lock |
623 | * | 622 | * |
624 | * Returns: errno | 623 | * Returns: errno |
625 | */ | 624 | */ |
626 | 625 | ||
627 | static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl) | 626 | static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl) |
628 | { | 627 | { |
629 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); | 628 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); |
630 | struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); | 629 | struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); |
631 | struct lm_lockname name = | 630 | struct lm_lockname name = |
632 | { .ln_number = ip->i_no_addr, | 631 | { .ln_number = ip->i_no_addr, |
633 | .ln_type = LM_TYPE_PLOCK }; | 632 | .ln_type = LM_TYPE_PLOCK }; |
634 | 633 | ||
635 | if (!(fl->fl_flags & FL_POSIX)) | 634 | if (!(fl->fl_flags & FL_POSIX)) |
636 | return -ENOLCK; | 635 | return -ENOLCK; |
637 | if (__mandatory_lock(&ip->i_inode)) | 636 | if (__mandatory_lock(&ip->i_inode)) |
638 | return -ENOLCK; | 637 | return -ENOLCK; |
639 | 638 | ||
640 | if (cmd == F_CANCELLK) { | 639 | if (cmd == F_CANCELLK) { |
641 | /* Hack: */ | 640 | /* Hack: */ |
642 | cmd = F_SETLK; | 641 | cmd = F_SETLK; |
643 | fl->fl_type = F_UNLCK; | 642 | fl->fl_type = F_UNLCK; |
644 | } | 643 | } |
645 | if (IS_GETLK(cmd)) | 644 | if (IS_GETLK(cmd)) |
646 | return gfs2_lm_plock_get(sdp, &name, file, fl); | 645 | return gfs2_lm_plock_get(sdp, &name, file, fl); |
647 | else if (fl->fl_type == F_UNLCK) | 646 | else if (fl->fl_type == F_UNLCK) |
648 | return gfs2_lm_punlock(sdp, &name, file, fl); | 647 | return gfs2_lm_punlock(sdp, &name, file, fl); |
649 | else | 648 | else |
650 | return gfs2_lm_plock(sdp, &name, file, cmd, fl); | 649 | return gfs2_lm_plock(sdp, &name, file, cmd, fl); |
651 | } | 650 | } |
652 | 651 | ||
653 | static int do_flock(struct file *file, int cmd, struct file_lock *fl) | 652 | static int do_flock(struct file *file, int cmd, struct file_lock *fl) |
654 | { | 653 | { |
655 | struct gfs2_file *fp = file->private_data; | 654 | struct gfs2_file *fp = file->private_data; |
656 | struct gfs2_holder *fl_gh = &fp->f_fl_gh; | 655 | struct gfs2_holder *fl_gh = &fp->f_fl_gh; |
657 | struct gfs2_inode *ip = GFS2_I(file->f_path.dentry->d_inode); | 656 | struct gfs2_inode *ip = GFS2_I(file->f_path.dentry->d_inode); |
658 | struct gfs2_glock *gl; | 657 | struct gfs2_glock *gl; |
659 | unsigned int state; | 658 | unsigned int state; |
660 | int flags; | 659 | int flags; |
661 | int error = 0; | 660 | int error = 0; |
662 | 661 | ||
663 | state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; | 662 | state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; |
664 | flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY) | GL_EXACT | GL_NOCACHE; | 663 | flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY) | GL_EXACT | GL_NOCACHE; |
665 | 664 | ||
666 | mutex_lock(&fp->f_fl_mutex); | 665 | mutex_lock(&fp->f_fl_mutex); |
667 | 666 | ||
668 | gl = fl_gh->gh_gl; | 667 | gl = fl_gh->gh_gl; |
669 | if (gl) { | 668 | if (gl) { |
670 | if (fl_gh->gh_state == state) | 669 | if (fl_gh->gh_state == state) |
671 | goto out; | 670 | goto out; |
672 | flock_lock_file_wait(file, | 671 | flock_lock_file_wait(file, |
673 | &(struct file_lock){.fl_type = F_UNLCK}); | 672 | &(struct file_lock){.fl_type = F_UNLCK}); |
674 | gfs2_glock_dq_wait(fl_gh); | 673 | gfs2_glock_dq_wait(fl_gh); |
675 | gfs2_holder_reinit(state, flags, fl_gh); | 674 | gfs2_holder_reinit(state, flags, fl_gh); |
676 | } else { | 675 | } else { |
677 | error = gfs2_glock_get(GFS2_SB(&ip->i_inode), ip->i_no_addr, | 676 | error = gfs2_glock_get(GFS2_SB(&ip->i_inode), ip->i_no_addr, |
678 | &gfs2_flock_glops, CREATE, &gl); | 677 | &gfs2_flock_glops, CREATE, &gl); |
679 | if (error) | 678 | if (error) |
680 | goto out; | 679 | goto out; |
681 | gfs2_holder_init(gl, state, flags, fl_gh); | 680 | gfs2_holder_init(gl, state, flags, fl_gh); |
682 | gfs2_glock_put(gl); | 681 | gfs2_glock_put(gl); |
683 | } | 682 | } |
684 | error = gfs2_glock_nq(fl_gh); | 683 | error = gfs2_glock_nq(fl_gh); |
685 | if (error) { | 684 | if (error) { |
686 | gfs2_holder_uninit(fl_gh); | 685 | gfs2_holder_uninit(fl_gh); |
687 | if (error == GLR_TRYFAILED) | 686 | if (error == GLR_TRYFAILED) |
688 | error = -EAGAIN; | 687 | error = -EAGAIN; |
689 | } else { | 688 | } else { |
690 | error = flock_lock_file_wait(file, fl); | 689 | error = flock_lock_file_wait(file, fl); |
691 | gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error); | 690 | gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error); |
692 | } | 691 | } |
693 | 692 | ||
694 | out: | 693 | out: |
695 | mutex_unlock(&fp->f_fl_mutex); | 694 | mutex_unlock(&fp->f_fl_mutex); |
696 | return error; | 695 | return error; |
697 | } | 696 | } |
698 | 697 | ||
699 | static void do_unflock(struct file *file, struct file_lock *fl) | 698 | static void do_unflock(struct file *file, struct file_lock *fl) |
700 | { | 699 | { |
701 | struct gfs2_file *fp = file->private_data; | 700 | struct gfs2_file *fp = file->private_data; |
702 | struct gfs2_holder *fl_gh = &fp->f_fl_gh; | 701 | struct gfs2_holder *fl_gh = &fp->f_fl_gh; |
703 | 702 | ||
704 | mutex_lock(&fp->f_fl_mutex); | 703 | mutex_lock(&fp->f_fl_mutex); |
705 | flock_lock_file_wait(file, fl); | 704 | flock_lock_file_wait(file, fl); |
706 | if (fl_gh->gh_gl) | 705 | if (fl_gh->gh_gl) |
707 | gfs2_glock_dq_uninit(fl_gh); | 706 | gfs2_glock_dq_uninit(fl_gh); |
708 | mutex_unlock(&fp->f_fl_mutex); | 707 | mutex_unlock(&fp->f_fl_mutex); |
709 | } | 708 | } |
710 | 709 | ||
711 | /** | 710 | /** |
712 | * gfs2_flock - acquire/release a flock lock on a file | 711 | * gfs2_flock - acquire/release a flock lock on a file |
713 | * @file: the file pointer | 712 | * @file: the file pointer |
714 | * @cmd: either modify or retrieve lock state, possibly wait | 713 | * @cmd: either modify or retrieve lock state, possibly wait |
715 | * @fl: type and range of lock | 714 | * @fl: type and range of lock |
716 | * | 715 | * |
717 | * Returns: errno | 716 | * Returns: errno |
718 | */ | 717 | */ |
719 | 718 | ||
720 | static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) | 719 | static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) |
721 | { | 720 | { |
722 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); | 721 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); |
723 | 722 | ||
724 | if (!(fl->fl_flags & FL_FLOCK)) | 723 | if (!(fl->fl_flags & FL_FLOCK)) |
725 | return -ENOLCK; | 724 | return -ENOLCK; |
726 | if (__mandatory_lock(&ip->i_inode)) | 725 | if (__mandatory_lock(&ip->i_inode)) |
727 | return -ENOLCK; | 726 | return -ENOLCK; |
728 | 727 | ||
729 | if (fl->fl_type == F_UNLCK) { | 728 | if (fl->fl_type == F_UNLCK) { |
730 | do_unflock(file, fl); | 729 | do_unflock(file, fl); |
731 | return 0; | 730 | return 0; |
732 | } else { | 731 | } else { |
733 | return do_flock(file, cmd, fl); | 732 | return do_flock(file, cmd, fl); |
734 | } | 733 | } |
735 | } | 734 | } |
736 | 735 | ||
737 | const struct file_operations gfs2_file_fops = { | 736 | const struct file_operations gfs2_file_fops = { |
738 | .llseek = gfs2_llseek, | 737 | .llseek = gfs2_llseek, |
739 | .read = do_sync_read, | 738 | .read = do_sync_read, |
740 | .aio_read = generic_file_aio_read, | 739 | .aio_read = generic_file_aio_read, |
741 | .write = do_sync_write, | 740 | .write = do_sync_write, |
742 | .aio_write = generic_file_aio_write, | 741 | .aio_write = generic_file_aio_write, |
743 | .unlocked_ioctl = gfs2_ioctl, | 742 | .unlocked_ioctl = gfs2_ioctl, |
744 | .mmap = gfs2_mmap, | 743 | .mmap = gfs2_mmap, |
745 | .open = gfs2_open, | 744 | .open = gfs2_open, |
746 | .release = gfs2_close, | 745 | .release = gfs2_close, |
747 | .fsync = gfs2_fsync, | 746 | .fsync = gfs2_fsync, |
748 | .lock = gfs2_lock, | 747 | .lock = gfs2_lock, |
749 | .flock = gfs2_flock, | 748 | .flock = gfs2_flock, |
750 | .splice_read = generic_file_splice_read, | 749 | .splice_read = generic_file_splice_read, |
751 | .splice_write = generic_file_splice_write, | 750 | .splice_write = generic_file_splice_write, |
752 | .setlease = gfs2_setlease, | 751 | .setlease = gfs2_setlease, |
753 | }; | 752 | }; |
754 | 753 | ||
755 | const struct file_operations gfs2_dir_fops = { | 754 | const struct file_operations gfs2_dir_fops = { |
756 | .readdir = gfs2_readdir, | 755 | .readdir = gfs2_readdir, |
757 | .unlocked_ioctl = gfs2_ioctl, | 756 | .unlocked_ioctl = gfs2_ioctl, |
758 | .open = gfs2_open, | 757 | .open = gfs2_open, |
759 | .release = gfs2_close, | 758 | .release = gfs2_close, |
760 | .fsync = gfs2_fsync, | 759 | .fsync = gfs2_fsync, |
761 | .lock = gfs2_lock, | 760 | .lock = gfs2_lock, |
762 | .flock = gfs2_flock, | 761 | .flock = gfs2_flock, |
763 | }; | 762 | }; |
764 | 763 | ||
765 | const struct file_operations gfs2_file_fops_nolock = { | 764 | const struct file_operations gfs2_file_fops_nolock = { |
766 | .llseek = gfs2_llseek, | 765 | .llseek = gfs2_llseek, |
767 | .read = do_sync_read, | 766 | .read = do_sync_read, |
768 | .aio_read = generic_file_aio_read, | 767 | .aio_read = generic_file_aio_read, |
769 | .write = do_sync_write, | 768 | .write = do_sync_write, |
770 | .aio_write = generic_file_aio_write, | 769 | .aio_write = generic_file_aio_write, |
771 | .unlocked_ioctl = gfs2_ioctl, | 770 | .unlocked_ioctl = gfs2_ioctl, |
772 | .mmap = gfs2_mmap, | 771 | .mmap = gfs2_mmap, |
773 | .open = gfs2_open, | 772 | .open = gfs2_open, |
774 | .release = gfs2_close, | 773 | .release = gfs2_close, |
775 | .fsync = gfs2_fsync, | 774 | .fsync = gfs2_fsync, |
776 | .splice_read = generic_file_splice_read, | 775 | .splice_read = generic_file_splice_read, |
777 | .splice_write = generic_file_splice_write, | 776 | .splice_write = generic_file_splice_write, |
778 | .setlease = gfs2_setlease, | 777 | .setlease = gfs2_setlease, |
779 | }; | 778 | }; |
780 | 779 | ||
781 | const struct file_operations gfs2_dir_fops_nolock = { | 780 | const struct file_operations gfs2_dir_fops_nolock = { |
782 | .readdir = gfs2_readdir, | 781 | .readdir = gfs2_readdir, |
783 | .unlocked_ioctl = gfs2_ioctl, | 782 | .unlocked_ioctl = gfs2_ioctl, |
784 | .open = gfs2_open, | 783 | .open = gfs2_open, |
785 | .release = gfs2_close, | 784 | .release = gfs2_close, |
786 | .fsync = gfs2_fsync, | 785 | .fsync = gfs2_fsync, |
787 | }; | 786 | }; |
788 | 787 | ||
789 | 788 |
fs/gfs2/ops_fstype.c
1 | /* | 1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
3 | * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. | 3 | * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. |
4 | * | 4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | 5 | * This copyrighted material is made available to anyone wishing to use, |
6 | * modify, copy, or redistribute it subject to the terms and conditions | 6 | * modify, copy, or redistribute it subject to the terms and conditions |
7 | * of the GNU General Public License version 2. | 7 | * of the GNU General Public License version 2. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/sched.h> | 10 | #include <linux/sched.h> |
11 | #include <linux/slab.h> | 11 | #include <linux/slab.h> |
12 | #include <linux/spinlock.h> | 12 | #include <linux/spinlock.h> |
13 | #include <linux/completion.h> | 13 | #include <linux/completion.h> |
14 | #include <linux/buffer_head.h> | 14 | #include <linux/buffer_head.h> |
15 | #include <linux/blkdev.h> | 15 | #include <linux/blkdev.h> |
16 | #include <linux/kthread.h> | 16 | #include <linux/kthread.h> |
17 | #include <linux/namei.h> | 17 | #include <linux/namei.h> |
18 | #include <linux/mount.h> | 18 | #include <linux/mount.h> |
19 | #include <linux/gfs2_ondisk.h> | 19 | #include <linux/gfs2_ondisk.h> |
20 | #include <linux/lm_interface.h> | 20 | #include <linux/lm_interface.h> |
21 | 21 | ||
22 | #include "gfs2.h" | 22 | #include "gfs2.h" |
23 | #include "incore.h" | 23 | #include "incore.h" |
24 | #include "bmap.h" | 24 | #include "bmap.h" |
25 | #include "daemon.h" | 25 | #include "daemon.h" |
26 | #include "glock.h" | 26 | #include "glock.h" |
27 | #include "glops.h" | 27 | #include "glops.h" |
28 | #include "inode.h" | 28 | #include "inode.h" |
29 | #include "mount.h" | 29 | #include "mount.h" |
30 | #include "ops_fstype.h" | ||
31 | #include "ops_dentry.h" | ||
32 | #include "ops_super.h" | ||
33 | #include "recovery.h" | 30 | #include "recovery.h" |
34 | #include "rgrp.h" | 31 | #include "rgrp.h" |
35 | #include "super.h" | 32 | #include "super.h" |
36 | #include "sys.h" | 33 | #include "sys.h" |
37 | #include "util.h" | 34 | #include "util.h" |
38 | #include "log.h" | 35 | #include "log.h" |
39 | 36 | ||
40 | #define DO 0 | 37 | #define DO 0 |
41 | #define UNDO 1 | 38 | #define UNDO 1 |
42 | 39 | ||
43 | static const u32 gfs2_old_fs_formats[] = { | 40 | static const u32 gfs2_old_fs_formats[] = { |
44 | 0 | 41 | 0 |
45 | }; | 42 | }; |
46 | 43 | ||
47 | static const u32 gfs2_old_multihost_formats[] = { | 44 | static const u32 gfs2_old_multihost_formats[] = { |
48 | 0 | 45 | 0 |
49 | }; | 46 | }; |
50 | 47 | ||
51 | /** | 48 | /** |
52 | * gfs2_tune_init - Fill a gfs2_tune structure with default values | 49 | * gfs2_tune_init - Fill a gfs2_tune structure with default values |
53 | * @gt: tune | 50 | * @gt: tune |
54 | * | 51 | * |
55 | */ | 52 | */ |
56 | 53 | ||
57 | static void gfs2_tune_init(struct gfs2_tune *gt) | 54 | static void gfs2_tune_init(struct gfs2_tune *gt) |
58 | { | 55 | { |
59 | spin_lock_init(>->gt_spin); | 56 | spin_lock_init(>->gt_spin); |
60 | 57 | ||
61 | gt->gt_demote_secs = 300; | 58 | gt->gt_demote_secs = 300; |
62 | gt->gt_incore_log_blocks = 1024; | 59 | gt->gt_incore_log_blocks = 1024; |
63 | gt->gt_log_flush_secs = 60; | 60 | gt->gt_log_flush_secs = 60; |
64 | gt->gt_recoverd_secs = 60; | 61 | gt->gt_recoverd_secs = 60; |
65 | gt->gt_logd_secs = 1; | 62 | gt->gt_logd_secs = 1; |
66 | gt->gt_quotad_secs = 5; | 63 | gt->gt_quotad_secs = 5; |
67 | gt->gt_quota_simul_sync = 64; | 64 | gt->gt_quota_simul_sync = 64; |
68 | gt->gt_quota_warn_period = 10; | 65 | gt->gt_quota_warn_period = 10; |
69 | gt->gt_quota_scale_num = 1; | 66 | gt->gt_quota_scale_num = 1; |
70 | gt->gt_quota_scale_den = 1; | 67 | gt->gt_quota_scale_den = 1; |
71 | gt->gt_quota_cache_secs = 300; | 68 | gt->gt_quota_cache_secs = 300; |
72 | gt->gt_quota_quantum = 60; | 69 | gt->gt_quota_quantum = 60; |
73 | gt->gt_new_files_jdata = 0; | 70 | gt->gt_new_files_jdata = 0; |
74 | gt->gt_max_readahead = 1 << 18; | 71 | gt->gt_max_readahead = 1 << 18; |
75 | gt->gt_stall_secs = 600; | 72 | gt->gt_stall_secs = 600; |
76 | gt->gt_complain_secs = 10; | 73 | gt->gt_complain_secs = 10; |
77 | gt->gt_statfs_quantum = 30; | 74 | gt->gt_statfs_quantum = 30; |
78 | gt->gt_statfs_slow = 0; | 75 | gt->gt_statfs_slow = 0; |
79 | } | 76 | } |
80 | 77 | ||
81 | static struct gfs2_sbd *init_sbd(struct super_block *sb) | 78 | static struct gfs2_sbd *init_sbd(struct super_block *sb) |
82 | { | 79 | { |
83 | struct gfs2_sbd *sdp; | 80 | struct gfs2_sbd *sdp; |
84 | 81 | ||
85 | sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL); | 82 | sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL); |
86 | if (!sdp) | 83 | if (!sdp) |
87 | return NULL; | 84 | return NULL; |
88 | 85 | ||
89 | sb->s_fs_info = sdp; | 86 | sb->s_fs_info = sdp; |
90 | sdp->sd_vfs = sb; | 87 | sdp->sd_vfs = sb; |
91 | 88 | ||
92 | gfs2_tune_init(&sdp->sd_tune); | 89 | gfs2_tune_init(&sdp->sd_tune); |
93 | 90 | ||
94 | INIT_LIST_HEAD(&sdp->sd_reclaim_list); | 91 | INIT_LIST_HEAD(&sdp->sd_reclaim_list); |
95 | spin_lock_init(&sdp->sd_reclaim_lock); | 92 | spin_lock_init(&sdp->sd_reclaim_lock); |
96 | init_waitqueue_head(&sdp->sd_reclaim_wq); | 93 | init_waitqueue_head(&sdp->sd_reclaim_wq); |
97 | 94 | ||
98 | mutex_init(&sdp->sd_inum_mutex); | 95 | mutex_init(&sdp->sd_inum_mutex); |
99 | spin_lock_init(&sdp->sd_statfs_spin); | 96 | spin_lock_init(&sdp->sd_statfs_spin); |
100 | 97 | ||
101 | spin_lock_init(&sdp->sd_rindex_spin); | 98 | spin_lock_init(&sdp->sd_rindex_spin); |
102 | mutex_init(&sdp->sd_rindex_mutex); | 99 | mutex_init(&sdp->sd_rindex_mutex); |
103 | INIT_LIST_HEAD(&sdp->sd_rindex_list); | 100 | INIT_LIST_HEAD(&sdp->sd_rindex_list); |
104 | INIT_LIST_HEAD(&sdp->sd_rindex_mru_list); | 101 | INIT_LIST_HEAD(&sdp->sd_rindex_mru_list); |
105 | 102 | ||
106 | INIT_LIST_HEAD(&sdp->sd_jindex_list); | 103 | INIT_LIST_HEAD(&sdp->sd_jindex_list); |
107 | spin_lock_init(&sdp->sd_jindex_spin); | 104 | spin_lock_init(&sdp->sd_jindex_spin); |
108 | mutex_init(&sdp->sd_jindex_mutex); | 105 | mutex_init(&sdp->sd_jindex_mutex); |
109 | 106 | ||
110 | INIT_LIST_HEAD(&sdp->sd_quota_list); | 107 | INIT_LIST_HEAD(&sdp->sd_quota_list); |
111 | spin_lock_init(&sdp->sd_quota_spin); | 108 | spin_lock_init(&sdp->sd_quota_spin); |
112 | mutex_init(&sdp->sd_quota_mutex); | 109 | mutex_init(&sdp->sd_quota_mutex); |
113 | 110 | ||
114 | spin_lock_init(&sdp->sd_log_lock); | 111 | spin_lock_init(&sdp->sd_log_lock); |
115 | 112 | ||
116 | INIT_LIST_HEAD(&sdp->sd_log_le_buf); | 113 | INIT_LIST_HEAD(&sdp->sd_log_le_buf); |
117 | INIT_LIST_HEAD(&sdp->sd_log_le_revoke); | 114 | INIT_LIST_HEAD(&sdp->sd_log_le_revoke); |
118 | INIT_LIST_HEAD(&sdp->sd_log_le_rg); | 115 | INIT_LIST_HEAD(&sdp->sd_log_le_rg); |
119 | INIT_LIST_HEAD(&sdp->sd_log_le_databuf); | 116 | INIT_LIST_HEAD(&sdp->sd_log_le_databuf); |
120 | INIT_LIST_HEAD(&sdp->sd_log_le_ordered); | 117 | INIT_LIST_HEAD(&sdp->sd_log_le_ordered); |
121 | 118 | ||
122 | mutex_init(&sdp->sd_log_reserve_mutex); | 119 | mutex_init(&sdp->sd_log_reserve_mutex); |
123 | INIT_LIST_HEAD(&sdp->sd_ail1_list); | 120 | INIT_LIST_HEAD(&sdp->sd_ail1_list); |
124 | INIT_LIST_HEAD(&sdp->sd_ail2_list); | 121 | INIT_LIST_HEAD(&sdp->sd_ail2_list); |
125 | 122 | ||
126 | init_rwsem(&sdp->sd_log_flush_lock); | 123 | init_rwsem(&sdp->sd_log_flush_lock); |
127 | atomic_set(&sdp->sd_log_in_flight, 0); | 124 | atomic_set(&sdp->sd_log_in_flight, 0); |
128 | init_waitqueue_head(&sdp->sd_log_flush_wait); | 125 | init_waitqueue_head(&sdp->sd_log_flush_wait); |
129 | 126 | ||
130 | INIT_LIST_HEAD(&sdp->sd_revoke_list); | 127 | INIT_LIST_HEAD(&sdp->sd_revoke_list); |
131 | 128 | ||
132 | mutex_init(&sdp->sd_freeze_lock); | 129 | mutex_init(&sdp->sd_freeze_lock); |
133 | 130 | ||
134 | return sdp; | 131 | return sdp; |
135 | } | 132 | } |
136 | 133 | ||
137 | 134 | ||
138 | /** | 135 | /** |
139 | * gfs2_check_sb - Check superblock | 136 | * gfs2_check_sb - Check superblock |
140 | * @sdp: the filesystem | 137 | * @sdp: the filesystem |
141 | * @sb: The superblock | 138 | * @sb: The superblock |
142 | * @silent: Don't print a message if the check fails | 139 | * @silent: Don't print a message if the check fails |
143 | * | 140 | * |
144 | * Checks the version code of the FS is one that we understand how to | 141 | * Checks the version code of the FS is one that we understand how to |
145 | * read and that the sizes of the various on-disk structures have not | 142 | * read and that the sizes of the various on-disk structures have not |
146 | * changed. | 143 | * changed. |
147 | */ | 144 | */ |
148 | 145 | ||
149 | static int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb_host *sb, int silent) | 146 | static int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb_host *sb, int silent) |
150 | { | 147 | { |
151 | unsigned int x; | 148 | unsigned int x; |
152 | 149 | ||
153 | if (sb->sb_magic != GFS2_MAGIC || | 150 | if (sb->sb_magic != GFS2_MAGIC || |
154 | sb->sb_type != GFS2_METATYPE_SB) { | 151 | sb->sb_type != GFS2_METATYPE_SB) { |
155 | if (!silent) | 152 | if (!silent) |
156 | printk(KERN_WARNING "GFS2: not a GFS2 filesystem\n"); | 153 | printk(KERN_WARNING "GFS2: not a GFS2 filesystem\n"); |
157 | return -EINVAL; | 154 | return -EINVAL; |
158 | } | 155 | } |
159 | 156 | ||
160 | /* If format numbers match exactly, we're done. */ | 157 | /* If format numbers match exactly, we're done. */ |
161 | 158 | ||
162 | if (sb->sb_fs_format == GFS2_FORMAT_FS && | 159 | if (sb->sb_fs_format == GFS2_FORMAT_FS && |
163 | sb->sb_multihost_format == GFS2_FORMAT_MULTI) | 160 | sb->sb_multihost_format == GFS2_FORMAT_MULTI) |
164 | return 0; | 161 | return 0; |
165 | 162 | ||
166 | if (sb->sb_fs_format != GFS2_FORMAT_FS) { | 163 | if (sb->sb_fs_format != GFS2_FORMAT_FS) { |
167 | for (x = 0; gfs2_old_fs_formats[x]; x++) | 164 | for (x = 0; gfs2_old_fs_formats[x]; x++) |
168 | if (gfs2_old_fs_formats[x] == sb->sb_fs_format) | 165 | if (gfs2_old_fs_formats[x] == sb->sb_fs_format) |
169 | break; | 166 | break; |
170 | 167 | ||
171 | if (!gfs2_old_fs_formats[x]) { | 168 | if (!gfs2_old_fs_formats[x]) { |
172 | printk(KERN_WARNING | 169 | printk(KERN_WARNING |
173 | "GFS2: code version (%u, %u) is incompatible " | 170 | "GFS2: code version (%u, %u) is incompatible " |
174 | "with ondisk format (%u, %u)\n", | 171 | "with ondisk format (%u, %u)\n", |
175 | GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, | 172 | GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, |
176 | sb->sb_fs_format, sb->sb_multihost_format); | 173 | sb->sb_fs_format, sb->sb_multihost_format); |
177 | printk(KERN_WARNING | 174 | printk(KERN_WARNING |
178 | "GFS2: I don't know how to upgrade this FS\n"); | 175 | "GFS2: I don't know how to upgrade this FS\n"); |
179 | return -EINVAL; | 176 | return -EINVAL; |
180 | } | 177 | } |
181 | } | 178 | } |
182 | 179 | ||
183 | if (sb->sb_multihost_format != GFS2_FORMAT_MULTI) { | 180 | if (sb->sb_multihost_format != GFS2_FORMAT_MULTI) { |
184 | for (x = 0; gfs2_old_multihost_formats[x]; x++) | 181 | for (x = 0; gfs2_old_multihost_formats[x]; x++) |
185 | if (gfs2_old_multihost_formats[x] == | 182 | if (gfs2_old_multihost_formats[x] == |
186 | sb->sb_multihost_format) | 183 | sb->sb_multihost_format) |
187 | break; | 184 | break; |
188 | 185 | ||
189 | if (!gfs2_old_multihost_formats[x]) { | 186 | if (!gfs2_old_multihost_formats[x]) { |
190 | printk(KERN_WARNING | 187 | printk(KERN_WARNING |
191 | "GFS2: code version (%u, %u) is incompatible " | 188 | "GFS2: code version (%u, %u) is incompatible " |
192 | "with ondisk format (%u, %u)\n", | 189 | "with ondisk format (%u, %u)\n", |
193 | GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, | 190 | GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, |
194 | sb->sb_fs_format, sb->sb_multihost_format); | 191 | sb->sb_fs_format, sb->sb_multihost_format); |
195 | printk(KERN_WARNING | 192 | printk(KERN_WARNING |
196 | "GFS2: I don't know how to upgrade this FS\n"); | 193 | "GFS2: I don't know how to upgrade this FS\n"); |
197 | return -EINVAL; | 194 | return -EINVAL; |
198 | } | 195 | } |
199 | } | 196 | } |
200 | 197 | ||
201 | if (!sdp->sd_args.ar_upgrade) { | 198 | if (!sdp->sd_args.ar_upgrade) { |
202 | printk(KERN_WARNING | 199 | printk(KERN_WARNING |
203 | "GFS2: code version (%u, %u) is incompatible " | 200 | "GFS2: code version (%u, %u) is incompatible " |
204 | "with ondisk format (%u, %u)\n", | 201 | "with ondisk format (%u, %u)\n", |
205 | GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, | 202 | GFS2_FORMAT_FS, GFS2_FORMAT_MULTI, |
206 | sb->sb_fs_format, sb->sb_multihost_format); | 203 | sb->sb_fs_format, sb->sb_multihost_format); |
207 | printk(KERN_INFO | 204 | printk(KERN_INFO |
208 | "GFS2: Use the \"upgrade\" mount option to upgrade " | 205 | "GFS2: Use the \"upgrade\" mount option to upgrade " |
209 | "the FS\n"); | 206 | "the FS\n"); |
210 | printk(KERN_INFO "GFS2: See the manual for more details\n"); | 207 | printk(KERN_INFO "GFS2: See the manual for more details\n"); |
211 | return -EINVAL; | 208 | return -EINVAL; |
212 | } | 209 | } |
213 | 210 | ||
214 | return 0; | 211 | return 0; |
215 | } | 212 | } |
216 | 213 | ||
217 | static void end_bio_io_page(struct bio *bio, int error) | 214 | static void end_bio_io_page(struct bio *bio, int error) |
218 | { | 215 | { |
219 | struct page *page = bio->bi_private; | 216 | struct page *page = bio->bi_private; |
220 | 217 | ||
221 | if (!error) | 218 | if (!error) |
222 | SetPageUptodate(page); | 219 | SetPageUptodate(page); |
223 | else | 220 | else |
224 | printk(KERN_WARNING "gfs2: error %d reading superblock\n", error); | 221 | printk(KERN_WARNING "gfs2: error %d reading superblock\n", error); |
225 | unlock_page(page); | 222 | unlock_page(page); |
226 | } | 223 | } |
227 | 224 | ||
228 | static void gfs2_sb_in(struct gfs2_sb_host *sb, const void *buf) | 225 | static void gfs2_sb_in(struct gfs2_sb_host *sb, const void *buf) |
229 | { | 226 | { |
230 | const struct gfs2_sb *str = buf; | 227 | const struct gfs2_sb *str = buf; |
231 | 228 | ||
232 | sb->sb_magic = be32_to_cpu(str->sb_header.mh_magic); | 229 | sb->sb_magic = be32_to_cpu(str->sb_header.mh_magic); |
233 | sb->sb_type = be32_to_cpu(str->sb_header.mh_type); | 230 | sb->sb_type = be32_to_cpu(str->sb_header.mh_type); |
234 | sb->sb_format = be32_to_cpu(str->sb_header.mh_format); | 231 | sb->sb_format = be32_to_cpu(str->sb_header.mh_format); |
235 | sb->sb_fs_format = be32_to_cpu(str->sb_fs_format); | 232 | sb->sb_fs_format = be32_to_cpu(str->sb_fs_format); |
236 | sb->sb_multihost_format = be32_to_cpu(str->sb_multihost_format); | 233 | sb->sb_multihost_format = be32_to_cpu(str->sb_multihost_format); |
237 | sb->sb_bsize = be32_to_cpu(str->sb_bsize); | 234 | sb->sb_bsize = be32_to_cpu(str->sb_bsize); |
238 | sb->sb_bsize_shift = be32_to_cpu(str->sb_bsize_shift); | 235 | sb->sb_bsize_shift = be32_to_cpu(str->sb_bsize_shift); |
239 | sb->sb_master_dir.no_addr = be64_to_cpu(str->sb_master_dir.no_addr); | 236 | sb->sb_master_dir.no_addr = be64_to_cpu(str->sb_master_dir.no_addr); |
240 | sb->sb_master_dir.no_formal_ino = be64_to_cpu(str->sb_master_dir.no_formal_ino); | 237 | sb->sb_master_dir.no_formal_ino = be64_to_cpu(str->sb_master_dir.no_formal_ino); |
241 | sb->sb_root_dir.no_addr = be64_to_cpu(str->sb_root_dir.no_addr); | 238 | sb->sb_root_dir.no_addr = be64_to_cpu(str->sb_root_dir.no_addr); |
242 | sb->sb_root_dir.no_formal_ino = be64_to_cpu(str->sb_root_dir.no_formal_ino); | 239 | sb->sb_root_dir.no_formal_ino = be64_to_cpu(str->sb_root_dir.no_formal_ino); |
243 | 240 | ||
244 | memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN); | 241 | memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN); |
245 | memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN); | 242 | memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN); |
246 | } | 243 | } |
247 | 244 | ||
248 | /** | 245 | /** |
249 | * gfs2_read_super - Read the gfs2 super block from disk | 246 | * gfs2_read_super - Read the gfs2 super block from disk |
250 | * @sdp: The GFS2 super block | 247 | * @sdp: The GFS2 super block |
251 | * @sector: The location of the super block | 248 | * @sector: The location of the super block |
252 | * @error: The error code to return | 249 | * @error: The error code to return |
253 | * | 250 | * |
254 | * This uses the bio functions to read the super block from disk | 251 | * This uses the bio functions to read the super block from disk |
255 | * because we want to be 100% sure that we never read cached data. | 252 | * because we want to be 100% sure that we never read cached data. |
256 | * A super block is read twice only during each GFS2 mount and is | 253 | * A super block is read twice only during each GFS2 mount and is |
257 | * never written to by the filesystem. The first time its read no | 254 | * never written to by the filesystem. The first time its read no |
258 | * locks are held, and the only details which are looked at are those | 255 | * locks are held, and the only details which are looked at are those |
259 | * relating to the locking protocol. Once locking is up and working, | 256 | * relating to the locking protocol. Once locking is up and working, |
260 | * the sb is read again under the lock to establish the location of | 257 | * the sb is read again under the lock to establish the location of |
261 | * the master directory (contains pointers to journals etc) and the | 258 | * the master directory (contains pointers to journals etc) and the |
262 | * root directory. | 259 | * root directory. |
263 | * | 260 | * |
264 | * Returns: 0 on success or error | 261 | * Returns: 0 on success or error |
265 | */ | 262 | */ |
266 | 263 | ||
267 | static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector) | 264 | static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector) |
268 | { | 265 | { |
269 | struct super_block *sb = sdp->sd_vfs; | 266 | struct super_block *sb = sdp->sd_vfs; |
270 | struct gfs2_sb *p; | 267 | struct gfs2_sb *p; |
271 | struct page *page; | 268 | struct page *page; |
272 | struct bio *bio; | 269 | struct bio *bio; |
273 | 270 | ||
274 | page = alloc_page(GFP_NOFS); | 271 | page = alloc_page(GFP_NOFS); |
275 | if (unlikely(!page)) | 272 | if (unlikely(!page)) |
276 | return -ENOBUFS; | 273 | return -ENOBUFS; |
277 | 274 | ||
278 | ClearPageUptodate(page); | 275 | ClearPageUptodate(page); |
279 | ClearPageDirty(page); | 276 | ClearPageDirty(page); |
280 | lock_page(page); | 277 | lock_page(page); |
281 | 278 | ||
282 | bio = bio_alloc(GFP_NOFS, 1); | 279 | bio = bio_alloc(GFP_NOFS, 1); |
283 | if (unlikely(!bio)) { | 280 | if (unlikely(!bio)) { |
284 | __free_page(page); | 281 | __free_page(page); |
285 | return -ENOBUFS; | 282 | return -ENOBUFS; |
286 | } | 283 | } |
287 | 284 | ||
288 | bio->bi_sector = sector * (sb->s_blocksize >> 9); | 285 | bio->bi_sector = sector * (sb->s_blocksize >> 9); |
289 | bio->bi_bdev = sb->s_bdev; | 286 | bio->bi_bdev = sb->s_bdev; |
290 | bio_add_page(bio, page, PAGE_SIZE, 0); | 287 | bio_add_page(bio, page, PAGE_SIZE, 0); |
291 | 288 | ||
292 | bio->bi_end_io = end_bio_io_page; | 289 | bio->bi_end_io = end_bio_io_page; |
293 | bio->bi_private = page; | 290 | bio->bi_private = page; |
294 | submit_bio(READ_SYNC | (1 << BIO_RW_META), bio); | 291 | submit_bio(READ_SYNC | (1 << BIO_RW_META), bio); |
295 | wait_on_page_locked(page); | 292 | wait_on_page_locked(page); |
296 | bio_put(bio); | 293 | bio_put(bio); |
297 | if (!PageUptodate(page)) { | 294 | if (!PageUptodate(page)) { |
298 | __free_page(page); | 295 | __free_page(page); |
299 | return -EIO; | 296 | return -EIO; |
300 | } | 297 | } |
301 | p = kmap(page); | 298 | p = kmap(page); |
302 | gfs2_sb_in(&sdp->sd_sb, p); | 299 | gfs2_sb_in(&sdp->sd_sb, p); |
303 | kunmap(page); | 300 | kunmap(page); |
304 | __free_page(page); | 301 | __free_page(page); |
305 | return 0; | 302 | return 0; |
306 | } | 303 | } |
307 | /** | 304 | /** |
308 | * gfs2_read_sb - Read super block | 305 | * gfs2_read_sb - Read super block |
309 | * @sdp: The GFS2 superblock | 306 | * @sdp: The GFS2 superblock |
310 | * @gl: the glock for the superblock (assumed to be held) | 307 | * @gl: the glock for the superblock (assumed to be held) |
311 | * @silent: Don't print message if mount fails | 308 | * @silent: Don't print message if mount fails |
312 | * | 309 | * |
313 | */ | 310 | */ |
314 | 311 | ||
315 | static int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) | 312 | static int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) |
316 | { | 313 | { |
317 | u32 hash_blocks, ind_blocks, leaf_blocks; | 314 | u32 hash_blocks, ind_blocks, leaf_blocks; |
318 | u32 tmp_blocks; | 315 | u32 tmp_blocks; |
319 | unsigned int x; | 316 | unsigned int x; |
320 | int error; | 317 | int error; |
321 | 318 | ||
322 | error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); | 319 | error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); |
323 | if (error) { | 320 | if (error) { |
324 | if (!silent) | 321 | if (!silent) |
325 | fs_err(sdp, "can't read superblock\n"); | 322 | fs_err(sdp, "can't read superblock\n"); |
326 | return error; | 323 | return error; |
327 | } | 324 | } |
328 | 325 | ||
329 | error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); | 326 | error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); |
330 | if (error) | 327 | if (error) |
331 | return error; | 328 | return error; |
332 | 329 | ||
333 | sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - | 330 | sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - |
334 | GFS2_BASIC_BLOCK_SHIFT; | 331 | GFS2_BASIC_BLOCK_SHIFT; |
335 | sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; | 332 | sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; |
336 | sdp->sd_diptrs = (sdp->sd_sb.sb_bsize - | 333 | sdp->sd_diptrs = (sdp->sd_sb.sb_bsize - |
337 | sizeof(struct gfs2_dinode)) / sizeof(u64); | 334 | sizeof(struct gfs2_dinode)) / sizeof(u64); |
338 | sdp->sd_inptrs = (sdp->sd_sb.sb_bsize - | 335 | sdp->sd_inptrs = (sdp->sd_sb.sb_bsize - |
339 | sizeof(struct gfs2_meta_header)) / sizeof(u64); | 336 | sizeof(struct gfs2_meta_header)) / sizeof(u64); |
340 | sdp->sd_jbsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header); | 337 | sdp->sd_jbsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header); |
341 | sdp->sd_hash_bsize = sdp->sd_sb.sb_bsize / 2; | 338 | sdp->sd_hash_bsize = sdp->sd_sb.sb_bsize / 2; |
342 | sdp->sd_hash_bsize_shift = sdp->sd_sb.sb_bsize_shift - 1; | 339 | sdp->sd_hash_bsize_shift = sdp->sd_sb.sb_bsize_shift - 1; |
343 | sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(u64); | 340 | sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(u64); |
344 | sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize - | 341 | sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize - |
345 | sizeof(struct gfs2_meta_header)) / | 342 | sizeof(struct gfs2_meta_header)) / |
346 | sizeof(struct gfs2_quota_change); | 343 | sizeof(struct gfs2_quota_change); |
347 | 344 | ||
348 | /* Compute maximum reservation required to add a entry to a directory */ | 345 | /* Compute maximum reservation required to add a entry to a directory */ |
349 | 346 | ||
350 | hash_blocks = DIV_ROUND_UP(sizeof(u64) * (1 << GFS2_DIR_MAX_DEPTH), | 347 | hash_blocks = DIV_ROUND_UP(sizeof(u64) * (1 << GFS2_DIR_MAX_DEPTH), |
351 | sdp->sd_jbsize); | 348 | sdp->sd_jbsize); |
352 | 349 | ||
353 | ind_blocks = 0; | 350 | ind_blocks = 0; |
354 | for (tmp_blocks = hash_blocks; tmp_blocks > sdp->sd_diptrs;) { | 351 | for (tmp_blocks = hash_blocks; tmp_blocks > sdp->sd_diptrs;) { |
355 | tmp_blocks = DIV_ROUND_UP(tmp_blocks, sdp->sd_inptrs); | 352 | tmp_blocks = DIV_ROUND_UP(tmp_blocks, sdp->sd_inptrs); |
356 | ind_blocks += tmp_blocks; | 353 | ind_blocks += tmp_blocks; |
357 | } | 354 | } |
358 | 355 | ||
359 | leaf_blocks = 2 + GFS2_DIR_MAX_DEPTH; | 356 | leaf_blocks = 2 + GFS2_DIR_MAX_DEPTH; |
360 | 357 | ||
361 | sdp->sd_max_dirres = hash_blocks + ind_blocks + leaf_blocks; | 358 | sdp->sd_max_dirres = hash_blocks + ind_blocks + leaf_blocks; |
362 | 359 | ||
363 | sdp->sd_heightsize[0] = sdp->sd_sb.sb_bsize - | 360 | sdp->sd_heightsize[0] = sdp->sd_sb.sb_bsize - |
364 | sizeof(struct gfs2_dinode); | 361 | sizeof(struct gfs2_dinode); |
365 | sdp->sd_heightsize[1] = sdp->sd_sb.sb_bsize * sdp->sd_diptrs; | 362 | sdp->sd_heightsize[1] = sdp->sd_sb.sb_bsize * sdp->sd_diptrs; |
366 | for (x = 2;; x++) { | 363 | for (x = 2;; x++) { |
367 | u64 space, d; | 364 | u64 space, d; |
368 | u32 m; | 365 | u32 m; |
369 | 366 | ||
370 | space = sdp->sd_heightsize[x - 1] * sdp->sd_inptrs; | 367 | space = sdp->sd_heightsize[x - 1] * sdp->sd_inptrs; |
371 | d = space; | 368 | d = space; |
372 | m = do_div(d, sdp->sd_inptrs); | 369 | m = do_div(d, sdp->sd_inptrs); |
373 | 370 | ||
374 | if (d != sdp->sd_heightsize[x - 1] || m) | 371 | if (d != sdp->sd_heightsize[x - 1] || m) |
375 | break; | 372 | break; |
376 | sdp->sd_heightsize[x] = space; | 373 | sdp->sd_heightsize[x] = space; |
377 | } | 374 | } |
378 | sdp->sd_max_height = x; | 375 | sdp->sd_max_height = x; |
379 | sdp->sd_heightsize[x] = ~0; | 376 | sdp->sd_heightsize[x] = ~0; |
380 | gfs2_assert(sdp, sdp->sd_max_height <= GFS2_MAX_META_HEIGHT); | 377 | gfs2_assert(sdp, sdp->sd_max_height <= GFS2_MAX_META_HEIGHT); |
381 | 378 | ||
382 | sdp->sd_jheightsize[0] = sdp->sd_sb.sb_bsize - | 379 | sdp->sd_jheightsize[0] = sdp->sd_sb.sb_bsize - |
383 | sizeof(struct gfs2_dinode); | 380 | sizeof(struct gfs2_dinode); |
384 | sdp->sd_jheightsize[1] = sdp->sd_jbsize * sdp->sd_diptrs; | 381 | sdp->sd_jheightsize[1] = sdp->sd_jbsize * sdp->sd_diptrs; |
385 | for (x = 2;; x++) { | 382 | for (x = 2;; x++) { |
386 | u64 space, d; | 383 | u64 space, d; |
387 | u32 m; | 384 | u32 m; |
388 | 385 | ||
389 | space = sdp->sd_jheightsize[x - 1] * sdp->sd_inptrs; | 386 | space = sdp->sd_jheightsize[x - 1] * sdp->sd_inptrs; |
390 | d = space; | 387 | d = space; |
391 | m = do_div(d, sdp->sd_inptrs); | 388 | m = do_div(d, sdp->sd_inptrs); |
392 | 389 | ||
393 | if (d != sdp->sd_jheightsize[x - 1] || m) | 390 | if (d != sdp->sd_jheightsize[x - 1] || m) |
394 | break; | 391 | break; |
395 | sdp->sd_jheightsize[x] = space; | 392 | sdp->sd_jheightsize[x] = space; |
396 | } | 393 | } |
397 | sdp->sd_max_jheight = x; | 394 | sdp->sd_max_jheight = x; |
398 | sdp->sd_jheightsize[x] = ~0; | 395 | sdp->sd_jheightsize[x] = ~0; |
399 | gfs2_assert(sdp, sdp->sd_max_jheight <= GFS2_MAX_META_HEIGHT); | 396 | gfs2_assert(sdp, sdp->sd_max_jheight <= GFS2_MAX_META_HEIGHT); |
400 | 397 | ||
401 | return 0; | 398 | return 0; |
402 | } | 399 | } |
403 | 400 | ||
404 | static int init_names(struct gfs2_sbd *sdp, int silent) | 401 | static int init_names(struct gfs2_sbd *sdp, int silent) |
405 | { | 402 | { |
406 | char *proto, *table; | 403 | char *proto, *table; |
407 | int error = 0; | 404 | int error = 0; |
408 | 405 | ||
409 | proto = sdp->sd_args.ar_lockproto; | 406 | proto = sdp->sd_args.ar_lockproto; |
410 | table = sdp->sd_args.ar_locktable; | 407 | table = sdp->sd_args.ar_locktable; |
411 | 408 | ||
412 | /* Try to autodetect */ | 409 | /* Try to autodetect */ |
413 | 410 | ||
414 | if (!proto[0] || !table[0]) { | 411 | if (!proto[0] || !table[0]) { |
415 | error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); | 412 | error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift); |
416 | if (error) | 413 | if (error) |
417 | return error; | 414 | return error; |
418 | 415 | ||
419 | error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); | 416 | error = gfs2_check_sb(sdp, &sdp->sd_sb, silent); |
420 | if (error) | 417 | if (error) |
421 | goto out; | 418 | goto out; |
422 | 419 | ||
423 | if (!proto[0]) | 420 | if (!proto[0]) |
424 | proto = sdp->sd_sb.sb_lockproto; | 421 | proto = sdp->sd_sb.sb_lockproto; |
425 | if (!table[0]) | 422 | if (!table[0]) |
426 | table = sdp->sd_sb.sb_locktable; | 423 | table = sdp->sd_sb.sb_locktable; |
427 | } | 424 | } |
428 | 425 | ||
429 | if (!table[0]) | 426 | if (!table[0]) |
430 | table = sdp->sd_vfs->s_id; | 427 | table = sdp->sd_vfs->s_id; |
431 | 428 | ||
432 | strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN); | 429 | strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN); |
433 | strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN); | 430 | strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN); |
434 | 431 | ||
435 | table = sdp->sd_table_name; | 432 | table = sdp->sd_table_name; |
436 | while ((table = strchr(table, '/'))) | 433 | while ((table = strchr(table, '/'))) |
437 | *table = '_'; | 434 | *table = '_'; |
438 | 435 | ||
439 | out: | 436 | out: |
440 | return error; | 437 | return error; |
441 | } | 438 | } |
442 | 439 | ||
443 | static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, | 440 | static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh, |
444 | int undo) | 441 | int undo) |
445 | { | 442 | { |
446 | struct task_struct *p; | 443 | struct task_struct *p; |
447 | int error = 0; | 444 | int error = 0; |
448 | 445 | ||
449 | if (undo) | 446 | if (undo) |
450 | goto fail_trans; | 447 | goto fail_trans; |
451 | 448 | ||
452 | for (sdp->sd_glockd_num = 0; | 449 | for (sdp->sd_glockd_num = 0; |
453 | sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd; | 450 | sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd; |
454 | sdp->sd_glockd_num++) { | 451 | sdp->sd_glockd_num++) { |
455 | p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd"); | 452 | p = kthread_run(gfs2_glockd, sdp, "gfs2_glockd"); |
456 | error = IS_ERR(p); | 453 | error = IS_ERR(p); |
457 | if (error) { | 454 | if (error) { |
458 | fs_err(sdp, "can't start glockd thread: %d\n", error); | 455 | fs_err(sdp, "can't start glockd thread: %d\n", error); |
459 | goto fail; | 456 | goto fail; |
460 | } | 457 | } |
461 | sdp->sd_glockd_process[sdp->sd_glockd_num] = p; | 458 | sdp->sd_glockd_process[sdp->sd_glockd_num] = p; |
462 | } | 459 | } |
463 | 460 | ||
464 | error = gfs2_glock_nq_num(sdp, | 461 | error = gfs2_glock_nq_num(sdp, |
465 | GFS2_MOUNT_LOCK, &gfs2_nondisk_glops, | 462 | GFS2_MOUNT_LOCK, &gfs2_nondisk_glops, |
466 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE, | 463 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE, |
467 | mount_gh); | 464 | mount_gh); |
468 | if (error) { | 465 | if (error) { |
469 | fs_err(sdp, "can't acquire mount glock: %d\n", error); | 466 | fs_err(sdp, "can't acquire mount glock: %d\n", error); |
470 | goto fail; | 467 | goto fail; |
471 | } | 468 | } |
472 | 469 | ||
473 | error = gfs2_glock_nq_num(sdp, | 470 | error = gfs2_glock_nq_num(sdp, |
474 | GFS2_LIVE_LOCK, &gfs2_nondisk_glops, | 471 | GFS2_LIVE_LOCK, &gfs2_nondisk_glops, |
475 | LM_ST_SHARED, | 472 | LM_ST_SHARED, |
476 | LM_FLAG_NOEXP | GL_EXACT, | 473 | LM_FLAG_NOEXP | GL_EXACT, |
477 | &sdp->sd_live_gh); | 474 | &sdp->sd_live_gh); |
478 | if (error) { | 475 | if (error) { |
479 | fs_err(sdp, "can't acquire live glock: %d\n", error); | 476 | fs_err(sdp, "can't acquire live glock: %d\n", error); |
480 | goto fail_mount; | 477 | goto fail_mount; |
481 | } | 478 | } |
482 | 479 | ||
483 | error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops, | 480 | error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops, |
484 | CREATE, &sdp->sd_rename_gl); | 481 | CREATE, &sdp->sd_rename_gl); |
485 | if (error) { | 482 | if (error) { |
486 | fs_err(sdp, "can't create rename glock: %d\n", error); | 483 | fs_err(sdp, "can't create rename glock: %d\n", error); |
487 | goto fail_live; | 484 | goto fail_live; |
488 | } | 485 | } |
489 | 486 | ||
490 | error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops, | 487 | error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops, |
491 | CREATE, &sdp->sd_trans_gl); | 488 | CREATE, &sdp->sd_trans_gl); |
492 | if (error) { | 489 | if (error) { |
493 | fs_err(sdp, "can't create transaction glock: %d\n", error); | 490 | fs_err(sdp, "can't create transaction glock: %d\n", error); |
494 | goto fail_rename; | 491 | goto fail_rename; |
495 | } | 492 | } |
496 | set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags); | 493 | set_bit(GLF_STICKY, &sdp->sd_trans_gl->gl_flags); |
497 | 494 | ||
498 | return 0; | 495 | return 0; |
499 | 496 | ||
500 | fail_trans: | 497 | fail_trans: |
501 | gfs2_glock_put(sdp->sd_trans_gl); | 498 | gfs2_glock_put(sdp->sd_trans_gl); |
502 | fail_rename: | 499 | fail_rename: |
503 | gfs2_glock_put(sdp->sd_rename_gl); | 500 | gfs2_glock_put(sdp->sd_rename_gl); |
504 | fail_live: | 501 | fail_live: |
505 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); | 502 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); |
506 | fail_mount: | 503 | fail_mount: |
507 | gfs2_glock_dq_uninit(mount_gh); | 504 | gfs2_glock_dq_uninit(mount_gh); |
508 | fail: | 505 | fail: |
509 | while (sdp->sd_glockd_num--) | 506 | while (sdp->sd_glockd_num--) |
510 | kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); | 507 | kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); |
511 | 508 | ||
512 | return error; | 509 | return error; |
513 | } | 510 | } |
514 | 511 | ||
515 | static int gfs2_lookup_root(struct super_block *sb, struct dentry **dptr, | 512 | static int gfs2_lookup_root(struct super_block *sb, struct dentry **dptr, |
516 | u64 no_addr, const char *name) | 513 | u64 no_addr, const char *name) |
517 | { | 514 | { |
518 | struct gfs2_sbd *sdp = sb->s_fs_info; | 515 | struct gfs2_sbd *sdp = sb->s_fs_info; |
519 | struct dentry *dentry; | 516 | struct dentry *dentry; |
520 | struct inode *inode; | 517 | struct inode *inode; |
521 | 518 | ||
522 | inode = gfs2_inode_lookup(sb, DT_DIR, no_addr, 0, 0); | 519 | inode = gfs2_inode_lookup(sb, DT_DIR, no_addr, 0, 0); |
523 | if (IS_ERR(inode)) { | 520 | if (IS_ERR(inode)) { |
524 | fs_err(sdp, "can't read in %s inode: %ld\n", name, PTR_ERR(inode)); | 521 | fs_err(sdp, "can't read in %s inode: %ld\n", name, PTR_ERR(inode)); |
525 | return PTR_ERR(inode); | 522 | return PTR_ERR(inode); |
526 | } | 523 | } |
527 | dentry = d_alloc_root(inode); | 524 | dentry = d_alloc_root(inode); |
528 | if (!dentry) { | 525 | if (!dentry) { |
529 | fs_err(sdp, "can't alloc %s dentry\n", name); | 526 | fs_err(sdp, "can't alloc %s dentry\n", name); |
530 | iput(inode); | 527 | iput(inode); |
531 | return -ENOMEM; | 528 | return -ENOMEM; |
532 | } | 529 | } |
533 | dentry->d_op = &gfs2_dops; | 530 | dentry->d_op = &gfs2_dops; |
534 | *dptr = dentry; | 531 | *dptr = dentry; |
535 | return 0; | 532 | return 0; |
536 | } | 533 | } |
537 | 534 | ||
538 | static int init_sb(struct gfs2_sbd *sdp, int silent) | 535 | static int init_sb(struct gfs2_sbd *sdp, int silent) |
539 | { | 536 | { |
540 | struct super_block *sb = sdp->sd_vfs; | 537 | struct super_block *sb = sdp->sd_vfs; |
541 | struct gfs2_holder sb_gh; | 538 | struct gfs2_holder sb_gh; |
542 | u64 no_addr; | 539 | u64 no_addr; |
543 | int ret; | 540 | int ret; |
544 | 541 | ||
545 | ret = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops, | 542 | ret = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops, |
546 | LM_ST_SHARED, 0, &sb_gh); | 543 | LM_ST_SHARED, 0, &sb_gh); |
547 | if (ret) { | 544 | if (ret) { |
548 | fs_err(sdp, "can't acquire superblock glock: %d\n", ret); | 545 | fs_err(sdp, "can't acquire superblock glock: %d\n", ret); |
549 | return ret; | 546 | return ret; |
550 | } | 547 | } |
551 | 548 | ||
552 | ret = gfs2_read_sb(sdp, sb_gh.gh_gl, silent); | 549 | ret = gfs2_read_sb(sdp, sb_gh.gh_gl, silent); |
553 | if (ret) { | 550 | if (ret) { |
554 | fs_err(sdp, "can't read superblock: %d\n", ret); | 551 | fs_err(sdp, "can't read superblock: %d\n", ret); |
555 | goto out; | 552 | goto out; |
556 | } | 553 | } |
557 | 554 | ||
558 | /* Set up the buffer cache and SB for real */ | 555 | /* Set up the buffer cache and SB for real */ |
559 | if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) { | 556 | if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) { |
560 | ret = -EINVAL; | 557 | ret = -EINVAL; |
561 | fs_err(sdp, "FS block size (%u) is too small for device " | 558 | fs_err(sdp, "FS block size (%u) is too small for device " |
562 | "block size (%u)\n", | 559 | "block size (%u)\n", |
563 | sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev)); | 560 | sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev)); |
564 | goto out; | 561 | goto out; |
565 | } | 562 | } |
566 | if (sdp->sd_sb.sb_bsize > PAGE_SIZE) { | 563 | if (sdp->sd_sb.sb_bsize > PAGE_SIZE) { |
567 | ret = -EINVAL; | 564 | ret = -EINVAL; |
568 | fs_err(sdp, "FS block size (%u) is too big for machine " | 565 | fs_err(sdp, "FS block size (%u) is too big for machine " |
569 | "page size (%u)\n", | 566 | "page size (%u)\n", |
570 | sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE); | 567 | sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE); |
571 | goto out; | 568 | goto out; |
572 | } | 569 | } |
573 | sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); | 570 | sb_set_blocksize(sb, sdp->sd_sb.sb_bsize); |
574 | 571 | ||
575 | /* Get the root inode */ | 572 | /* Get the root inode */ |
576 | no_addr = sdp->sd_sb.sb_root_dir.no_addr; | 573 | no_addr = sdp->sd_sb.sb_root_dir.no_addr; |
577 | ret = gfs2_lookup_root(sb, &sdp->sd_root_dir, no_addr, "root"); | 574 | ret = gfs2_lookup_root(sb, &sdp->sd_root_dir, no_addr, "root"); |
578 | if (ret) | 575 | if (ret) |
579 | goto out; | 576 | goto out; |
580 | 577 | ||
581 | /* Get the master inode */ | 578 | /* Get the master inode */ |
582 | no_addr = sdp->sd_sb.sb_master_dir.no_addr; | 579 | no_addr = sdp->sd_sb.sb_master_dir.no_addr; |
583 | ret = gfs2_lookup_root(sb, &sdp->sd_master_dir, no_addr, "master"); | 580 | ret = gfs2_lookup_root(sb, &sdp->sd_master_dir, no_addr, "master"); |
584 | if (ret) { | 581 | if (ret) { |
585 | dput(sdp->sd_root_dir); | 582 | dput(sdp->sd_root_dir); |
586 | goto out; | 583 | goto out; |
587 | } | 584 | } |
588 | sb->s_root = dget(sdp->sd_args.ar_meta ? sdp->sd_master_dir : sdp->sd_root_dir); | 585 | sb->s_root = dget(sdp->sd_args.ar_meta ? sdp->sd_master_dir : sdp->sd_root_dir); |
589 | out: | 586 | out: |
590 | gfs2_glock_dq_uninit(&sb_gh); | 587 | gfs2_glock_dq_uninit(&sb_gh); |
591 | return ret; | 588 | return ret; |
592 | } | 589 | } |
593 | 590 | ||
594 | /** | 591 | /** |
595 | * map_journal_extents - create a reusable "extent" mapping from all logical | 592 | * map_journal_extents - create a reusable "extent" mapping from all logical |
596 | * blocks to all physical blocks for the given journal. This will save | 593 | * blocks to all physical blocks for the given journal. This will save |
597 | * us time when writing journal blocks. Most journals will have only one | 594 | * us time when writing journal blocks. Most journals will have only one |
598 | * extent that maps all their logical blocks. That's because gfs2.mkfs | 595 | * extent that maps all their logical blocks. That's because gfs2.mkfs |
599 | * arranges the journal blocks sequentially to maximize performance. | 596 | * arranges the journal blocks sequentially to maximize performance. |
600 | * So the extent would map the first block for the entire file length. | 597 | * So the extent would map the first block for the entire file length. |
601 | * However, gfs2_jadd can happen while file activity is happening, so | 598 | * However, gfs2_jadd can happen while file activity is happening, so |
602 | * those journals may not be sequential. Less likely is the case where | 599 | * those journals may not be sequential. Less likely is the case where |
603 | * the users created their own journals by mounting the metafs and | 600 | * the users created their own journals by mounting the metafs and |
604 | * laying it out. But it's still possible. These journals might have | 601 | * laying it out. But it's still possible. These journals might have |
605 | * several extents. | 602 | * several extents. |
606 | * | 603 | * |
607 | * TODO: This should be done in bigger chunks rather than one block at a time, | 604 | * TODO: This should be done in bigger chunks rather than one block at a time, |
608 | * but since it's only done at mount time, I'm not worried about the | 605 | * but since it's only done at mount time, I'm not worried about the |
609 | * time it takes. | 606 | * time it takes. |
610 | */ | 607 | */ |
611 | static int map_journal_extents(struct gfs2_sbd *sdp) | 608 | static int map_journal_extents(struct gfs2_sbd *sdp) |
612 | { | 609 | { |
613 | struct gfs2_jdesc *jd = sdp->sd_jdesc; | 610 | struct gfs2_jdesc *jd = sdp->sd_jdesc; |
614 | unsigned int lb; | 611 | unsigned int lb; |
615 | u64 db, prev_db; /* logical block, disk block, prev disk block */ | 612 | u64 db, prev_db; /* logical block, disk block, prev disk block */ |
616 | struct gfs2_inode *ip = GFS2_I(jd->jd_inode); | 613 | struct gfs2_inode *ip = GFS2_I(jd->jd_inode); |
617 | struct gfs2_journal_extent *jext = NULL; | 614 | struct gfs2_journal_extent *jext = NULL; |
618 | struct buffer_head bh; | 615 | struct buffer_head bh; |
619 | int rc = 0; | 616 | int rc = 0; |
620 | 617 | ||
621 | prev_db = 0; | 618 | prev_db = 0; |
622 | 619 | ||
623 | for (lb = 0; lb < ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; lb++) { | 620 | for (lb = 0; lb < ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; lb++) { |
624 | bh.b_state = 0; | 621 | bh.b_state = 0; |
625 | bh.b_blocknr = 0; | 622 | bh.b_blocknr = 0; |
626 | bh.b_size = 1 << ip->i_inode.i_blkbits; | 623 | bh.b_size = 1 << ip->i_inode.i_blkbits; |
627 | rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0); | 624 | rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0); |
628 | db = bh.b_blocknr; | 625 | db = bh.b_blocknr; |
629 | if (rc || !db) { | 626 | if (rc || !db) { |
630 | printk(KERN_INFO "GFS2 journal mapping error %d: lb=" | 627 | printk(KERN_INFO "GFS2 journal mapping error %d: lb=" |
631 | "%u db=%llu\n", rc, lb, (unsigned long long)db); | 628 | "%u db=%llu\n", rc, lb, (unsigned long long)db); |
632 | break; | 629 | break; |
633 | } | 630 | } |
634 | if (!prev_db || db != prev_db + 1) { | 631 | if (!prev_db || db != prev_db + 1) { |
635 | jext = kzalloc(sizeof(struct gfs2_journal_extent), | 632 | jext = kzalloc(sizeof(struct gfs2_journal_extent), |
636 | GFP_KERNEL); | 633 | GFP_KERNEL); |
637 | if (!jext) { | 634 | if (!jext) { |
638 | printk(KERN_INFO "GFS2 error: out of memory " | 635 | printk(KERN_INFO "GFS2 error: out of memory " |
639 | "mapping journal extents.\n"); | 636 | "mapping journal extents.\n"); |
640 | rc = -ENOMEM; | 637 | rc = -ENOMEM; |
641 | break; | 638 | break; |
642 | } | 639 | } |
643 | jext->dblock = db; | 640 | jext->dblock = db; |
644 | jext->lblock = lb; | 641 | jext->lblock = lb; |
645 | jext->blocks = 1; | 642 | jext->blocks = 1; |
646 | list_add_tail(&jext->extent_list, &jd->extent_list); | 643 | list_add_tail(&jext->extent_list, &jd->extent_list); |
647 | } else { | 644 | } else { |
648 | jext->blocks++; | 645 | jext->blocks++; |
649 | } | 646 | } |
650 | prev_db = db; | 647 | prev_db = db; |
651 | } | 648 | } |
652 | return rc; | 649 | return rc; |
653 | } | 650 | } |
654 | 651 | ||
655 | static void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp) | 652 | static void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp) |
656 | { | 653 | { |
657 | if (!sdp->sd_lockstruct.ls_ops->lm_others_may_mount) | 654 | if (!sdp->sd_lockstruct.ls_ops->lm_others_may_mount) |
658 | return; | 655 | return; |
659 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | 656 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
660 | sdp->sd_lockstruct.ls_ops->lm_others_may_mount( | 657 | sdp->sd_lockstruct.ls_ops->lm_others_may_mount( |
661 | sdp->sd_lockstruct.ls_lockspace); | 658 | sdp->sd_lockstruct.ls_lockspace); |
662 | } | 659 | } |
663 | 660 | ||
664 | static int init_journal(struct gfs2_sbd *sdp, int undo) | 661 | static int init_journal(struct gfs2_sbd *sdp, int undo) |
665 | { | 662 | { |
666 | struct inode *master = sdp->sd_master_dir->d_inode; | 663 | struct inode *master = sdp->sd_master_dir->d_inode; |
667 | struct gfs2_holder ji_gh; | 664 | struct gfs2_holder ji_gh; |
668 | struct task_struct *p; | 665 | struct task_struct *p; |
669 | struct gfs2_inode *ip; | 666 | struct gfs2_inode *ip; |
670 | int jindex = 1; | 667 | int jindex = 1; |
671 | int error = 0; | 668 | int error = 0; |
672 | 669 | ||
673 | if (undo) { | 670 | if (undo) { |
674 | jindex = 0; | 671 | jindex = 0; |
675 | goto fail_recoverd; | 672 | goto fail_recoverd; |
676 | } | 673 | } |
677 | 674 | ||
678 | sdp->sd_jindex = gfs2_lookup_simple(master, "jindex"); | 675 | sdp->sd_jindex = gfs2_lookup_simple(master, "jindex"); |
679 | if (IS_ERR(sdp->sd_jindex)) { | 676 | if (IS_ERR(sdp->sd_jindex)) { |
680 | fs_err(sdp, "can't lookup journal index: %d\n", error); | 677 | fs_err(sdp, "can't lookup journal index: %d\n", error); |
681 | return PTR_ERR(sdp->sd_jindex); | 678 | return PTR_ERR(sdp->sd_jindex); |
682 | } | 679 | } |
683 | ip = GFS2_I(sdp->sd_jindex); | 680 | ip = GFS2_I(sdp->sd_jindex); |
684 | set_bit(GLF_STICKY, &ip->i_gl->gl_flags); | 681 | set_bit(GLF_STICKY, &ip->i_gl->gl_flags); |
685 | 682 | ||
686 | /* Load in the journal index special file */ | 683 | /* Load in the journal index special file */ |
687 | 684 | ||
688 | error = gfs2_jindex_hold(sdp, &ji_gh); | 685 | error = gfs2_jindex_hold(sdp, &ji_gh); |
689 | if (error) { | 686 | if (error) { |
690 | fs_err(sdp, "can't read journal index: %d\n", error); | 687 | fs_err(sdp, "can't read journal index: %d\n", error); |
691 | goto fail; | 688 | goto fail; |
692 | } | 689 | } |
693 | 690 | ||
694 | error = -EINVAL; | 691 | error = -EINVAL; |
695 | if (!gfs2_jindex_size(sdp)) { | 692 | if (!gfs2_jindex_size(sdp)) { |
696 | fs_err(sdp, "no journals!\n"); | 693 | fs_err(sdp, "no journals!\n"); |
697 | goto fail_jindex; | 694 | goto fail_jindex; |
698 | } | 695 | } |
699 | 696 | ||
700 | if (sdp->sd_args.ar_spectator) { | 697 | if (sdp->sd_args.ar_spectator) { |
701 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0); | 698 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0); |
702 | atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); | 699 | atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); |
703 | } else { | 700 | } else { |
704 | if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) { | 701 | if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) { |
705 | fs_err(sdp, "can't mount journal #%u\n", | 702 | fs_err(sdp, "can't mount journal #%u\n", |
706 | sdp->sd_lockstruct.ls_jid); | 703 | sdp->sd_lockstruct.ls_jid); |
707 | fs_err(sdp, "there are only %u journals (0 - %u)\n", | 704 | fs_err(sdp, "there are only %u journals (0 - %u)\n", |
708 | gfs2_jindex_size(sdp), | 705 | gfs2_jindex_size(sdp), |
709 | gfs2_jindex_size(sdp) - 1); | 706 | gfs2_jindex_size(sdp) - 1); |
710 | goto fail_jindex; | 707 | goto fail_jindex; |
711 | } | 708 | } |
712 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid); | 709 | sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid); |
713 | 710 | ||
714 | error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid, | 711 | error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid, |
715 | &gfs2_journal_glops, | 712 | &gfs2_journal_glops, |
716 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP, | 713 | LM_ST_EXCLUSIVE, LM_FLAG_NOEXP, |
717 | &sdp->sd_journal_gh); | 714 | &sdp->sd_journal_gh); |
718 | if (error) { | 715 | if (error) { |
719 | fs_err(sdp, "can't acquire journal glock: %d\n", error); | 716 | fs_err(sdp, "can't acquire journal glock: %d\n", error); |
720 | goto fail_jindex; | 717 | goto fail_jindex; |
721 | } | 718 | } |
722 | 719 | ||
723 | ip = GFS2_I(sdp->sd_jdesc->jd_inode); | 720 | ip = GFS2_I(sdp->sd_jdesc->jd_inode); |
724 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, | 721 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, |
725 | LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE, | 722 | LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE, |
726 | &sdp->sd_jinode_gh); | 723 | &sdp->sd_jinode_gh); |
727 | if (error) { | 724 | if (error) { |
728 | fs_err(sdp, "can't acquire journal inode glock: %d\n", | 725 | fs_err(sdp, "can't acquire journal inode glock: %d\n", |
729 | error); | 726 | error); |
730 | goto fail_journal_gh; | 727 | goto fail_journal_gh; |
731 | } | 728 | } |
732 | 729 | ||
733 | error = gfs2_jdesc_check(sdp->sd_jdesc); | 730 | error = gfs2_jdesc_check(sdp->sd_jdesc); |
734 | if (error) { | 731 | if (error) { |
735 | fs_err(sdp, "my journal (%u) is bad: %d\n", | 732 | fs_err(sdp, "my journal (%u) is bad: %d\n", |
736 | sdp->sd_jdesc->jd_jid, error); | 733 | sdp->sd_jdesc->jd_jid, error); |
737 | goto fail_jinode_gh; | 734 | goto fail_jinode_gh; |
738 | } | 735 | } |
739 | atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); | 736 | atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks); |
740 | 737 | ||
741 | /* Map the extents for this journal's blocks */ | 738 | /* Map the extents for this journal's blocks */ |
742 | map_journal_extents(sdp); | 739 | map_journal_extents(sdp); |
743 | } | 740 | } |
744 | 741 | ||
745 | if (sdp->sd_lockstruct.ls_first) { | 742 | if (sdp->sd_lockstruct.ls_first) { |
746 | unsigned int x; | 743 | unsigned int x; |
747 | for (x = 0; x < sdp->sd_journals; x++) { | 744 | for (x = 0; x < sdp->sd_journals; x++) { |
748 | error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x)); | 745 | error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x)); |
749 | if (error) { | 746 | if (error) { |
750 | fs_err(sdp, "error recovering journal %u: %d\n", | 747 | fs_err(sdp, "error recovering journal %u: %d\n", |
751 | x, error); | 748 | x, error); |
752 | goto fail_jinode_gh; | 749 | goto fail_jinode_gh; |
753 | } | 750 | } |
754 | } | 751 | } |
755 | 752 | ||
756 | gfs2_lm_others_may_mount(sdp); | 753 | gfs2_lm_others_may_mount(sdp); |
757 | } else if (!sdp->sd_args.ar_spectator) { | 754 | } else if (!sdp->sd_args.ar_spectator) { |
758 | error = gfs2_recover_journal(sdp->sd_jdesc); | 755 | error = gfs2_recover_journal(sdp->sd_jdesc); |
759 | if (error) { | 756 | if (error) { |
760 | fs_err(sdp, "error recovering my journal: %d\n", error); | 757 | fs_err(sdp, "error recovering my journal: %d\n", error); |
761 | goto fail_jinode_gh; | 758 | goto fail_jinode_gh; |
762 | } | 759 | } |
763 | } | 760 | } |
764 | 761 | ||
765 | set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags); | 762 | set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags); |
766 | gfs2_glock_dq_uninit(&ji_gh); | 763 | gfs2_glock_dq_uninit(&ji_gh); |
767 | jindex = 0; | 764 | jindex = 0; |
768 | 765 | ||
769 | p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd"); | 766 | p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd"); |
770 | error = IS_ERR(p); | 767 | error = IS_ERR(p); |
771 | if (error) { | 768 | if (error) { |
772 | fs_err(sdp, "can't start recoverd thread: %d\n", error); | 769 | fs_err(sdp, "can't start recoverd thread: %d\n", error); |
773 | goto fail_jinode_gh; | 770 | goto fail_jinode_gh; |
774 | } | 771 | } |
775 | sdp->sd_recoverd_process = p; | 772 | sdp->sd_recoverd_process = p; |
776 | 773 | ||
777 | return 0; | 774 | return 0; |
778 | 775 | ||
779 | fail_recoverd: | 776 | fail_recoverd: |
780 | kthread_stop(sdp->sd_recoverd_process); | 777 | kthread_stop(sdp->sd_recoverd_process); |
781 | fail_jinode_gh: | 778 | fail_jinode_gh: |
782 | if (!sdp->sd_args.ar_spectator) | 779 | if (!sdp->sd_args.ar_spectator) |
783 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); | 780 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); |
784 | fail_journal_gh: | 781 | fail_journal_gh: |
785 | if (!sdp->sd_args.ar_spectator) | 782 | if (!sdp->sd_args.ar_spectator) |
786 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); | 783 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); |
787 | fail_jindex: | 784 | fail_jindex: |
788 | gfs2_jindex_free(sdp); | 785 | gfs2_jindex_free(sdp); |
789 | if (jindex) | 786 | if (jindex) |
790 | gfs2_glock_dq_uninit(&ji_gh); | 787 | gfs2_glock_dq_uninit(&ji_gh); |
791 | fail: | 788 | fail: |
792 | iput(sdp->sd_jindex); | 789 | iput(sdp->sd_jindex); |
793 | return error; | 790 | return error; |
794 | } | 791 | } |
795 | 792 | ||
796 | 793 | ||
797 | static int init_inodes(struct gfs2_sbd *sdp, int undo) | 794 | static int init_inodes(struct gfs2_sbd *sdp, int undo) |
798 | { | 795 | { |
799 | int error = 0; | 796 | int error = 0; |
800 | struct gfs2_inode *ip; | 797 | struct gfs2_inode *ip; |
801 | struct inode *master = sdp->sd_master_dir->d_inode; | 798 | struct inode *master = sdp->sd_master_dir->d_inode; |
802 | 799 | ||
803 | if (undo) | 800 | if (undo) |
804 | goto fail_qinode; | 801 | goto fail_qinode; |
805 | 802 | ||
806 | error = init_journal(sdp, undo); | 803 | error = init_journal(sdp, undo); |
807 | if (error) | 804 | if (error) |
808 | goto fail; | 805 | goto fail; |
809 | 806 | ||
810 | /* Read in the master inode number inode */ | 807 | /* Read in the master inode number inode */ |
811 | sdp->sd_inum_inode = gfs2_lookup_simple(master, "inum"); | 808 | sdp->sd_inum_inode = gfs2_lookup_simple(master, "inum"); |
812 | if (IS_ERR(sdp->sd_inum_inode)) { | 809 | if (IS_ERR(sdp->sd_inum_inode)) { |
813 | error = PTR_ERR(sdp->sd_inum_inode); | 810 | error = PTR_ERR(sdp->sd_inum_inode); |
814 | fs_err(sdp, "can't read in inum inode: %d\n", error); | 811 | fs_err(sdp, "can't read in inum inode: %d\n", error); |
815 | goto fail_journal; | 812 | goto fail_journal; |
816 | } | 813 | } |
817 | 814 | ||
818 | 815 | ||
819 | /* Read in the master statfs inode */ | 816 | /* Read in the master statfs inode */ |
820 | sdp->sd_statfs_inode = gfs2_lookup_simple(master, "statfs"); | 817 | sdp->sd_statfs_inode = gfs2_lookup_simple(master, "statfs"); |
821 | if (IS_ERR(sdp->sd_statfs_inode)) { | 818 | if (IS_ERR(sdp->sd_statfs_inode)) { |
822 | error = PTR_ERR(sdp->sd_statfs_inode); | 819 | error = PTR_ERR(sdp->sd_statfs_inode); |
823 | fs_err(sdp, "can't read in statfs inode: %d\n", error); | 820 | fs_err(sdp, "can't read in statfs inode: %d\n", error); |
824 | goto fail_inum; | 821 | goto fail_inum; |
825 | } | 822 | } |
826 | 823 | ||
827 | /* Read in the resource index inode */ | 824 | /* Read in the resource index inode */ |
828 | sdp->sd_rindex = gfs2_lookup_simple(master, "rindex"); | 825 | sdp->sd_rindex = gfs2_lookup_simple(master, "rindex"); |
829 | if (IS_ERR(sdp->sd_rindex)) { | 826 | if (IS_ERR(sdp->sd_rindex)) { |
830 | error = PTR_ERR(sdp->sd_rindex); | 827 | error = PTR_ERR(sdp->sd_rindex); |
831 | fs_err(sdp, "can't get resource index inode: %d\n", error); | 828 | fs_err(sdp, "can't get resource index inode: %d\n", error); |
832 | goto fail_statfs; | 829 | goto fail_statfs; |
833 | } | 830 | } |
834 | ip = GFS2_I(sdp->sd_rindex); | 831 | ip = GFS2_I(sdp->sd_rindex); |
835 | set_bit(GLF_STICKY, &ip->i_gl->gl_flags); | 832 | set_bit(GLF_STICKY, &ip->i_gl->gl_flags); |
836 | sdp->sd_rindex_uptodate = 0; | 833 | sdp->sd_rindex_uptodate = 0; |
837 | 834 | ||
838 | /* Read in the quota inode */ | 835 | /* Read in the quota inode */ |
839 | sdp->sd_quota_inode = gfs2_lookup_simple(master, "quota"); | 836 | sdp->sd_quota_inode = gfs2_lookup_simple(master, "quota"); |
840 | if (IS_ERR(sdp->sd_quota_inode)) { | 837 | if (IS_ERR(sdp->sd_quota_inode)) { |
841 | error = PTR_ERR(sdp->sd_quota_inode); | 838 | error = PTR_ERR(sdp->sd_quota_inode); |
842 | fs_err(sdp, "can't get quota file inode: %d\n", error); | 839 | fs_err(sdp, "can't get quota file inode: %d\n", error); |
843 | goto fail_rindex; | 840 | goto fail_rindex; |
844 | } | 841 | } |
845 | return 0; | 842 | return 0; |
846 | 843 | ||
847 | fail_qinode: | 844 | fail_qinode: |
848 | iput(sdp->sd_quota_inode); | 845 | iput(sdp->sd_quota_inode); |
849 | fail_rindex: | 846 | fail_rindex: |
850 | gfs2_clear_rgrpd(sdp); | 847 | gfs2_clear_rgrpd(sdp); |
851 | iput(sdp->sd_rindex); | 848 | iput(sdp->sd_rindex); |
852 | fail_statfs: | 849 | fail_statfs: |
853 | iput(sdp->sd_statfs_inode); | 850 | iput(sdp->sd_statfs_inode); |
854 | fail_inum: | 851 | fail_inum: |
855 | iput(sdp->sd_inum_inode); | 852 | iput(sdp->sd_inum_inode); |
856 | fail_journal: | 853 | fail_journal: |
857 | init_journal(sdp, UNDO); | 854 | init_journal(sdp, UNDO); |
858 | fail: | 855 | fail: |
859 | return error; | 856 | return error; |
860 | } | 857 | } |
861 | 858 | ||
862 | static int init_per_node(struct gfs2_sbd *sdp, int undo) | 859 | static int init_per_node(struct gfs2_sbd *sdp, int undo) |
863 | { | 860 | { |
864 | struct inode *pn = NULL; | 861 | struct inode *pn = NULL; |
865 | char buf[30]; | 862 | char buf[30]; |
866 | int error = 0; | 863 | int error = 0; |
867 | struct gfs2_inode *ip; | 864 | struct gfs2_inode *ip; |
868 | struct inode *master = sdp->sd_master_dir->d_inode; | 865 | struct inode *master = sdp->sd_master_dir->d_inode; |
869 | 866 | ||
870 | if (sdp->sd_args.ar_spectator) | 867 | if (sdp->sd_args.ar_spectator) |
871 | return 0; | 868 | return 0; |
872 | 869 | ||
873 | if (undo) | 870 | if (undo) |
874 | goto fail_qc_gh; | 871 | goto fail_qc_gh; |
875 | 872 | ||
876 | pn = gfs2_lookup_simple(master, "per_node"); | 873 | pn = gfs2_lookup_simple(master, "per_node"); |
877 | if (IS_ERR(pn)) { | 874 | if (IS_ERR(pn)) { |
878 | error = PTR_ERR(pn); | 875 | error = PTR_ERR(pn); |
879 | fs_err(sdp, "can't find per_node directory: %d\n", error); | 876 | fs_err(sdp, "can't find per_node directory: %d\n", error); |
880 | return error; | 877 | return error; |
881 | } | 878 | } |
882 | 879 | ||
883 | sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid); | 880 | sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid); |
884 | sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf); | 881 | sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf); |
885 | if (IS_ERR(sdp->sd_ir_inode)) { | 882 | if (IS_ERR(sdp->sd_ir_inode)) { |
886 | error = PTR_ERR(sdp->sd_ir_inode); | 883 | error = PTR_ERR(sdp->sd_ir_inode); |
887 | fs_err(sdp, "can't find local \"ir\" file: %d\n", error); | 884 | fs_err(sdp, "can't find local \"ir\" file: %d\n", error); |
888 | goto fail; | 885 | goto fail; |
889 | } | 886 | } |
890 | 887 | ||
891 | sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid); | 888 | sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid); |
892 | sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf); | 889 | sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf); |
893 | if (IS_ERR(sdp->sd_sc_inode)) { | 890 | if (IS_ERR(sdp->sd_sc_inode)) { |
894 | error = PTR_ERR(sdp->sd_sc_inode); | 891 | error = PTR_ERR(sdp->sd_sc_inode); |
895 | fs_err(sdp, "can't find local \"sc\" file: %d\n", error); | 892 | fs_err(sdp, "can't find local \"sc\" file: %d\n", error); |
896 | goto fail_ir_i; | 893 | goto fail_ir_i; |
897 | } | 894 | } |
898 | 895 | ||
899 | sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid); | 896 | sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid); |
900 | sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf); | 897 | sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf); |
901 | if (IS_ERR(sdp->sd_qc_inode)) { | 898 | if (IS_ERR(sdp->sd_qc_inode)) { |
902 | error = PTR_ERR(sdp->sd_qc_inode); | 899 | error = PTR_ERR(sdp->sd_qc_inode); |
903 | fs_err(sdp, "can't find local \"qc\" file: %d\n", error); | 900 | fs_err(sdp, "can't find local \"qc\" file: %d\n", error); |
904 | goto fail_ut_i; | 901 | goto fail_ut_i; |
905 | } | 902 | } |
906 | 903 | ||
907 | iput(pn); | 904 | iput(pn); |
908 | pn = NULL; | 905 | pn = NULL; |
909 | 906 | ||
910 | ip = GFS2_I(sdp->sd_ir_inode); | 907 | ip = GFS2_I(sdp->sd_ir_inode); |
911 | error = gfs2_glock_nq_init(ip->i_gl, | 908 | error = gfs2_glock_nq_init(ip->i_gl, |
912 | LM_ST_EXCLUSIVE, 0, | 909 | LM_ST_EXCLUSIVE, 0, |
913 | &sdp->sd_ir_gh); | 910 | &sdp->sd_ir_gh); |
914 | if (error) { | 911 | if (error) { |
915 | fs_err(sdp, "can't lock local \"ir\" file: %d\n", error); | 912 | fs_err(sdp, "can't lock local \"ir\" file: %d\n", error); |
916 | goto fail_qc_i; | 913 | goto fail_qc_i; |
917 | } | 914 | } |
918 | 915 | ||
919 | ip = GFS2_I(sdp->sd_sc_inode); | 916 | ip = GFS2_I(sdp->sd_sc_inode); |
920 | error = gfs2_glock_nq_init(ip->i_gl, | 917 | error = gfs2_glock_nq_init(ip->i_gl, |
921 | LM_ST_EXCLUSIVE, 0, | 918 | LM_ST_EXCLUSIVE, 0, |
922 | &sdp->sd_sc_gh); | 919 | &sdp->sd_sc_gh); |
923 | if (error) { | 920 | if (error) { |
924 | fs_err(sdp, "can't lock local \"sc\" file: %d\n", error); | 921 | fs_err(sdp, "can't lock local \"sc\" file: %d\n", error); |
925 | goto fail_ir_gh; | 922 | goto fail_ir_gh; |
926 | } | 923 | } |
927 | 924 | ||
928 | ip = GFS2_I(sdp->sd_qc_inode); | 925 | ip = GFS2_I(sdp->sd_qc_inode); |
929 | error = gfs2_glock_nq_init(ip->i_gl, | 926 | error = gfs2_glock_nq_init(ip->i_gl, |
930 | LM_ST_EXCLUSIVE, 0, | 927 | LM_ST_EXCLUSIVE, 0, |
931 | &sdp->sd_qc_gh); | 928 | &sdp->sd_qc_gh); |
932 | if (error) { | 929 | if (error) { |
933 | fs_err(sdp, "can't lock local \"qc\" file: %d\n", error); | 930 | fs_err(sdp, "can't lock local \"qc\" file: %d\n", error); |
934 | goto fail_ut_gh; | 931 | goto fail_ut_gh; |
935 | } | 932 | } |
936 | 933 | ||
937 | return 0; | 934 | return 0; |
938 | 935 | ||
939 | fail_qc_gh: | 936 | fail_qc_gh: |
940 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); | 937 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); |
941 | fail_ut_gh: | 938 | fail_ut_gh: |
942 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); | 939 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); |
943 | fail_ir_gh: | 940 | fail_ir_gh: |
944 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); | 941 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); |
945 | fail_qc_i: | 942 | fail_qc_i: |
946 | iput(sdp->sd_qc_inode); | 943 | iput(sdp->sd_qc_inode); |
947 | fail_ut_i: | 944 | fail_ut_i: |
948 | iput(sdp->sd_sc_inode); | 945 | iput(sdp->sd_sc_inode); |
949 | fail_ir_i: | 946 | fail_ir_i: |
950 | iput(sdp->sd_ir_inode); | 947 | iput(sdp->sd_ir_inode); |
951 | fail: | 948 | fail: |
952 | if (pn) | 949 | if (pn) |
953 | iput(pn); | 950 | iput(pn); |
954 | return error; | 951 | return error; |
955 | } | 952 | } |
956 | 953 | ||
957 | static int init_threads(struct gfs2_sbd *sdp, int undo) | 954 | static int init_threads(struct gfs2_sbd *sdp, int undo) |
958 | { | 955 | { |
959 | struct task_struct *p; | 956 | struct task_struct *p; |
960 | int error = 0; | 957 | int error = 0; |
961 | 958 | ||
962 | if (undo) | 959 | if (undo) |
963 | goto fail_quotad; | 960 | goto fail_quotad; |
964 | 961 | ||
965 | sdp->sd_log_flush_time = jiffies; | 962 | sdp->sd_log_flush_time = jiffies; |
966 | sdp->sd_jindex_refresh_time = jiffies; | 963 | sdp->sd_jindex_refresh_time = jiffies; |
967 | 964 | ||
968 | p = kthread_run(gfs2_logd, sdp, "gfs2_logd"); | 965 | p = kthread_run(gfs2_logd, sdp, "gfs2_logd"); |
969 | error = IS_ERR(p); | 966 | error = IS_ERR(p); |
970 | if (error) { | 967 | if (error) { |
971 | fs_err(sdp, "can't start logd thread: %d\n", error); | 968 | fs_err(sdp, "can't start logd thread: %d\n", error); |
972 | return error; | 969 | return error; |
973 | } | 970 | } |
974 | sdp->sd_logd_process = p; | 971 | sdp->sd_logd_process = p; |
975 | 972 | ||
976 | sdp->sd_statfs_sync_time = jiffies; | 973 | sdp->sd_statfs_sync_time = jiffies; |
977 | sdp->sd_quota_sync_time = jiffies; | 974 | sdp->sd_quota_sync_time = jiffies; |
978 | 975 | ||
979 | p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad"); | 976 | p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad"); |
980 | error = IS_ERR(p); | 977 | error = IS_ERR(p); |
981 | if (error) { | 978 | if (error) { |
982 | fs_err(sdp, "can't start quotad thread: %d\n", error); | 979 | fs_err(sdp, "can't start quotad thread: %d\n", error); |
983 | goto fail; | 980 | goto fail; |
984 | } | 981 | } |
985 | sdp->sd_quotad_process = p; | 982 | sdp->sd_quotad_process = p; |
986 | 983 | ||
987 | return 0; | 984 | return 0; |
988 | 985 | ||
989 | 986 | ||
990 | fail_quotad: | 987 | fail_quotad: |
991 | kthread_stop(sdp->sd_quotad_process); | 988 | kthread_stop(sdp->sd_quotad_process); |
992 | fail: | 989 | fail: |
993 | kthread_stop(sdp->sd_logd_process); | 990 | kthread_stop(sdp->sd_logd_process); |
994 | return error; | 991 | return error; |
995 | } | 992 | } |
996 | 993 | ||
997 | /** | 994 | /** |
998 | * gfs2_lm_mount - mount a locking protocol | 995 | * gfs2_lm_mount - mount a locking protocol |
999 | * @sdp: the filesystem | 996 | * @sdp: the filesystem |
1000 | * @args: mount arguements | 997 | * @args: mount arguements |
1001 | * @silent: if 1, don't complain if the FS isn't a GFS2 fs | 998 | * @silent: if 1, don't complain if the FS isn't a GFS2 fs |
1002 | * | 999 | * |
1003 | * Returns: errno | 1000 | * Returns: errno |
1004 | */ | 1001 | */ |
1005 | 1002 | ||
1006 | static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent) | 1003 | static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent) |
1007 | { | 1004 | { |
1008 | char *proto = sdp->sd_proto_name; | 1005 | char *proto = sdp->sd_proto_name; |
1009 | char *table = sdp->sd_table_name; | 1006 | char *table = sdp->sd_table_name; |
1010 | int flags = LM_MFLAG_CONV_NODROP; | 1007 | int flags = LM_MFLAG_CONV_NODROP; |
1011 | int error; | 1008 | int error; |
1012 | 1009 | ||
1013 | if (sdp->sd_args.ar_spectator) | 1010 | if (sdp->sd_args.ar_spectator) |
1014 | flags |= LM_MFLAG_SPECTATOR; | 1011 | flags |= LM_MFLAG_SPECTATOR; |
1015 | 1012 | ||
1016 | fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table); | 1013 | fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table); |
1017 | 1014 | ||
1018 | error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata, | 1015 | error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata, |
1019 | gfs2_glock_cb, sdp, | 1016 | gfs2_glock_cb, sdp, |
1020 | GFS2_MIN_LVB_SIZE, flags, | 1017 | GFS2_MIN_LVB_SIZE, flags, |
1021 | &sdp->sd_lockstruct, &sdp->sd_kobj); | 1018 | &sdp->sd_lockstruct, &sdp->sd_kobj); |
1022 | if (error) { | 1019 | if (error) { |
1023 | fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n", | 1020 | fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n", |
1024 | proto, table, sdp->sd_args.ar_hostdata); | 1021 | proto, table, sdp->sd_args.ar_hostdata); |
1025 | goto out; | 1022 | goto out; |
1026 | } | 1023 | } |
1027 | 1024 | ||
1028 | if (gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_ops) || | 1025 | if (gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_ops) || |
1029 | gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lvb_size >= | 1026 | gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lvb_size >= |
1030 | GFS2_MIN_LVB_SIZE)) { | 1027 | GFS2_MIN_LVB_SIZE)) { |
1031 | gfs2_unmount_lockproto(&sdp->sd_lockstruct); | 1028 | gfs2_unmount_lockproto(&sdp->sd_lockstruct); |
1032 | goto out; | 1029 | goto out; |
1033 | } | 1030 | } |
1034 | 1031 | ||
1035 | if (sdp->sd_args.ar_spectator) | 1032 | if (sdp->sd_args.ar_spectator) |
1036 | snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table); | 1033 | snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table); |
1037 | else | 1034 | else |
1038 | snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table, | 1035 | snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table, |
1039 | sdp->sd_lockstruct.ls_jid); | 1036 | sdp->sd_lockstruct.ls_jid); |
1040 | 1037 | ||
1041 | fs_info(sdp, "Joined cluster. Now mounting FS...\n"); | 1038 | fs_info(sdp, "Joined cluster. Now mounting FS...\n"); |
1042 | 1039 | ||
1043 | if ((sdp->sd_lockstruct.ls_flags & LM_LSFLAG_LOCAL) && | 1040 | if ((sdp->sd_lockstruct.ls_flags & LM_LSFLAG_LOCAL) && |
1044 | !sdp->sd_args.ar_ignore_local_fs) { | 1041 | !sdp->sd_args.ar_ignore_local_fs) { |
1045 | sdp->sd_args.ar_localflocks = 1; | 1042 | sdp->sd_args.ar_localflocks = 1; |
1046 | sdp->sd_args.ar_localcaching = 1; | 1043 | sdp->sd_args.ar_localcaching = 1; |
1047 | } | 1044 | } |
1048 | 1045 | ||
1049 | out: | 1046 | out: |
1050 | return error; | 1047 | return error; |
1051 | } | 1048 | } |
1052 | 1049 | ||
1053 | void gfs2_lm_unmount(struct gfs2_sbd *sdp) | 1050 | void gfs2_lm_unmount(struct gfs2_sbd *sdp) |
1054 | { | 1051 | { |
1055 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) | 1052 | if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
1056 | gfs2_unmount_lockproto(&sdp->sd_lockstruct); | 1053 | gfs2_unmount_lockproto(&sdp->sd_lockstruct); |
1057 | } | 1054 | } |
1058 | 1055 | ||
1059 | /** | 1056 | /** |
1060 | * fill_super - Read in superblock | 1057 | * fill_super - Read in superblock |
1061 | * @sb: The VFS superblock | 1058 | * @sb: The VFS superblock |
1062 | * @data: Mount options | 1059 | * @data: Mount options |
1063 | * @silent: Don't complain if it's not a GFS2 filesystem | 1060 | * @silent: Don't complain if it's not a GFS2 filesystem |
1064 | * | 1061 | * |
1065 | * Returns: errno | 1062 | * Returns: errno |
1066 | */ | 1063 | */ |
1067 | 1064 | ||
1068 | static int fill_super(struct super_block *sb, void *data, int silent) | 1065 | static int fill_super(struct super_block *sb, void *data, int silent) |
1069 | { | 1066 | { |
1070 | struct gfs2_sbd *sdp; | 1067 | struct gfs2_sbd *sdp; |
1071 | struct gfs2_holder mount_gh; | 1068 | struct gfs2_holder mount_gh; |
1072 | int error; | 1069 | int error; |
1073 | 1070 | ||
1074 | sdp = init_sbd(sb); | 1071 | sdp = init_sbd(sb); |
1075 | if (!sdp) { | 1072 | if (!sdp) { |
1076 | printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n"); | 1073 | printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n"); |
1077 | return -ENOMEM; | 1074 | return -ENOMEM; |
1078 | } | 1075 | } |
1079 | 1076 | ||
1080 | error = gfs2_mount_args(sdp, (char *)data, 0); | 1077 | error = gfs2_mount_args(sdp, (char *)data, 0); |
1081 | if (error) { | 1078 | if (error) { |
1082 | printk(KERN_WARNING "GFS2: can't parse mount arguments\n"); | 1079 | printk(KERN_WARNING "GFS2: can't parse mount arguments\n"); |
1083 | goto fail; | 1080 | goto fail; |
1084 | } | 1081 | } |
1085 | 1082 | ||
1086 | sb->s_magic = GFS2_MAGIC; | 1083 | sb->s_magic = GFS2_MAGIC; |
1087 | sb->s_op = &gfs2_super_ops; | 1084 | sb->s_op = &gfs2_super_ops; |
1088 | sb->s_export_op = &gfs2_export_ops; | 1085 | sb->s_export_op = &gfs2_export_ops; |
1089 | sb->s_time_gran = 1; | 1086 | sb->s_time_gran = 1; |
1090 | sb->s_maxbytes = MAX_LFS_FILESIZE; | 1087 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
1091 | 1088 | ||
1092 | /* Set up the buffer cache and fill in some fake block size values | 1089 | /* Set up the buffer cache and fill in some fake block size values |
1093 | to allow us to read-in the on-disk superblock. */ | 1090 | to allow us to read-in the on-disk superblock. */ |
1094 | sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK); | 1091 | sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK); |
1095 | sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits; | 1092 | sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits; |
1096 | sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - | 1093 | sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - |
1097 | GFS2_BASIC_BLOCK_SHIFT; | 1094 | GFS2_BASIC_BLOCK_SHIFT; |
1098 | sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; | 1095 | sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; |
1099 | 1096 | ||
1100 | error = init_names(sdp, silent); | 1097 | error = init_names(sdp, silent); |
1101 | if (error) | 1098 | if (error) |
1102 | goto fail; | 1099 | goto fail; |
1103 | 1100 | ||
1104 | gfs2_create_debugfs_file(sdp); | 1101 | gfs2_create_debugfs_file(sdp); |
1105 | 1102 | ||
1106 | error = gfs2_sys_fs_add(sdp); | 1103 | error = gfs2_sys_fs_add(sdp); |
1107 | if (error) | 1104 | if (error) |
1108 | goto fail; | 1105 | goto fail; |
1109 | 1106 | ||
1110 | error = gfs2_lm_mount(sdp, silent); | 1107 | error = gfs2_lm_mount(sdp, silent); |
1111 | if (error) | 1108 | if (error) |
1112 | goto fail_sys; | 1109 | goto fail_sys; |
1113 | 1110 | ||
1114 | error = init_locking(sdp, &mount_gh, DO); | 1111 | error = init_locking(sdp, &mount_gh, DO); |
1115 | if (error) | 1112 | if (error) |
1116 | goto fail_lm; | 1113 | goto fail_lm; |
1117 | 1114 | ||
1118 | error = init_sb(sdp, silent); | 1115 | error = init_sb(sdp, silent); |
1119 | if (error) | 1116 | if (error) |
1120 | goto fail_locking; | 1117 | goto fail_locking; |
1121 | 1118 | ||
1122 | error = init_inodes(sdp, DO); | 1119 | error = init_inodes(sdp, DO); |
1123 | if (error) | 1120 | if (error) |
1124 | goto fail_sb; | 1121 | goto fail_sb; |
1125 | 1122 | ||
1126 | error = init_per_node(sdp, DO); | 1123 | error = init_per_node(sdp, DO); |
1127 | if (error) | 1124 | if (error) |
1128 | goto fail_inodes; | 1125 | goto fail_inodes; |
1129 | 1126 | ||
1130 | error = gfs2_statfs_init(sdp); | 1127 | error = gfs2_statfs_init(sdp); |
1131 | if (error) { | 1128 | if (error) { |
1132 | fs_err(sdp, "can't initialize statfs subsystem: %d\n", error); | 1129 | fs_err(sdp, "can't initialize statfs subsystem: %d\n", error); |
1133 | goto fail_per_node; | 1130 | goto fail_per_node; |
1134 | } | 1131 | } |
1135 | 1132 | ||
1136 | error = init_threads(sdp, DO); | 1133 | error = init_threads(sdp, DO); |
1137 | if (error) | 1134 | if (error) |
1138 | goto fail_per_node; | 1135 | goto fail_per_node; |
1139 | 1136 | ||
1140 | if (!(sb->s_flags & MS_RDONLY)) { | 1137 | if (!(sb->s_flags & MS_RDONLY)) { |
1141 | error = gfs2_make_fs_rw(sdp); | 1138 | error = gfs2_make_fs_rw(sdp); |
1142 | if (error) { | 1139 | if (error) { |
1143 | fs_err(sdp, "can't make FS RW: %d\n", error); | 1140 | fs_err(sdp, "can't make FS RW: %d\n", error); |
1144 | goto fail_threads; | 1141 | goto fail_threads; |
1145 | } | 1142 | } |
1146 | } | 1143 | } |
1147 | 1144 | ||
1148 | gfs2_glock_dq_uninit(&mount_gh); | 1145 | gfs2_glock_dq_uninit(&mount_gh); |
1149 | 1146 | ||
1150 | return 0; | 1147 | return 0; |
1151 | 1148 | ||
1152 | fail_threads: | 1149 | fail_threads: |
1153 | init_threads(sdp, UNDO); | 1150 | init_threads(sdp, UNDO); |
1154 | fail_per_node: | 1151 | fail_per_node: |
1155 | init_per_node(sdp, UNDO); | 1152 | init_per_node(sdp, UNDO); |
1156 | fail_inodes: | 1153 | fail_inodes: |
1157 | init_inodes(sdp, UNDO); | 1154 | init_inodes(sdp, UNDO); |
1158 | fail_sb: | 1155 | fail_sb: |
1159 | if (sdp->sd_root_dir) | 1156 | if (sdp->sd_root_dir) |
1160 | dput(sdp->sd_root_dir); | 1157 | dput(sdp->sd_root_dir); |
1161 | if (sdp->sd_master_dir) | 1158 | if (sdp->sd_master_dir) |
1162 | dput(sdp->sd_master_dir); | 1159 | dput(sdp->sd_master_dir); |
1163 | sb->s_root = NULL; | 1160 | sb->s_root = NULL; |
1164 | fail_locking: | 1161 | fail_locking: |
1165 | init_locking(sdp, &mount_gh, UNDO); | 1162 | init_locking(sdp, &mount_gh, UNDO); |
1166 | fail_lm: | 1163 | fail_lm: |
1167 | gfs2_gl_hash_clear(sdp); | 1164 | gfs2_gl_hash_clear(sdp); |
1168 | gfs2_lm_unmount(sdp); | 1165 | gfs2_lm_unmount(sdp); |
1169 | while (invalidate_inodes(sb)) | 1166 | while (invalidate_inodes(sb)) |
1170 | yield(); | 1167 | yield(); |
1171 | fail_sys: | 1168 | fail_sys: |
1172 | gfs2_sys_fs_del(sdp); | 1169 | gfs2_sys_fs_del(sdp); |
1173 | fail: | 1170 | fail: |
1174 | gfs2_delete_debugfs_file(sdp); | 1171 | gfs2_delete_debugfs_file(sdp); |
1175 | kfree(sdp); | 1172 | kfree(sdp); |
1176 | sb->s_fs_info = NULL; | 1173 | sb->s_fs_info = NULL; |
1177 | return error; | 1174 | return error; |
1178 | } | 1175 | } |
1179 | 1176 | ||
1180 | static int gfs2_get_sb(struct file_system_type *fs_type, int flags, | 1177 | static int gfs2_get_sb(struct file_system_type *fs_type, int flags, |
1181 | const char *dev_name, void *data, struct vfsmount *mnt) | 1178 | const char *dev_name, void *data, struct vfsmount *mnt) |
1182 | { | 1179 | { |
1183 | return get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt); | 1180 | return get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt); |
1184 | } | 1181 | } |
1185 | 1182 | ||
1186 | static struct super_block *get_gfs2_sb(const char *dev_name) | 1183 | static struct super_block *get_gfs2_sb(const char *dev_name) |
1187 | { | 1184 | { |
1188 | struct super_block *sb; | 1185 | struct super_block *sb; |
1189 | struct nameidata nd; | 1186 | struct nameidata nd; |
1190 | int error; | 1187 | int error; |
1191 | 1188 | ||
1192 | error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd); | 1189 | error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd); |
1193 | if (error) { | 1190 | if (error) { |
1194 | printk(KERN_WARNING "GFS2: path_lookup on %s returned error %d\n", | 1191 | printk(KERN_WARNING "GFS2: path_lookup on %s returned error %d\n", |
1195 | dev_name, error); | 1192 | dev_name, error); |
1196 | return NULL; | 1193 | return NULL; |
1197 | } | 1194 | } |
1198 | sb = nd.path.dentry->d_inode->i_sb; | 1195 | sb = nd.path.dentry->d_inode->i_sb; |
1199 | if (sb && (sb->s_type == &gfs2_fs_type)) | 1196 | if (sb && (sb->s_type == &gfs2_fs_type)) |
1200 | atomic_inc(&sb->s_active); | 1197 | atomic_inc(&sb->s_active); |
1201 | else | 1198 | else |
1202 | sb = NULL; | 1199 | sb = NULL; |
1203 | path_put(&nd.path); | 1200 | path_put(&nd.path); |
1204 | return sb; | 1201 | return sb; |
1205 | } | 1202 | } |
1206 | 1203 | ||
1207 | static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags, | 1204 | static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags, |
1208 | const char *dev_name, void *data, struct vfsmount *mnt) | 1205 | const char *dev_name, void *data, struct vfsmount *mnt) |
1209 | { | 1206 | { |
1210 | struct super_block *sb = NULL; | 1207 | struct super_block *sb = NULL; |
1211 | struct gfs2_sbd *sdp; | 1208 | struct gfs2_sbd *sdp; |
1212 | 1209 | ||
1213 | sb = get_gfs2_sb(dev_name); | 1210 | sb = get_gfs2_sb(dev_name); |
1214 | if (!sb) { | 1211 | if (!sb) { |
1215 | printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n"); | 1212 | printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n"); |
1216 | return -ENOENT; | 1213 | return -ENOENT; |
1217 | } | 1214 | } |
1218 | sdp = sb->s_fs_info; | 1215 | sdp = sb->s_fs_info; |
1219 | mnt->mnt_sb = sb; | 1216 | mnt->mnt_sb = sb; |
1220 | mnt->mnt_root = dget(sdp->sd_master_dir); | 1217 | mnt->mnt_root = dget(sdp->sd_master_dir); |
1221 | return 0; | 1218 | return 0; |
1222 | } | 1219 | } |
1223 | 1220 | ||
1224 | static void gfs2_kill_sb(struct super_block *sb) | 1221 | static void gfs2_kill_sb(struct super_block *sb) |
1225 | { | 1222 | { |
1226 | struct gfs2_sbd *sdp = sb->s_fs_info; | 1223 | struct gfs2_sbd *sdp = sb->s_fs_info; |
1227 | if (sdp) { | 1224 | if (sdp) { |
1228 | gfs2_meta_syncfs(sdp); | 1225 | gfs2_meta_syncfs(sdp); |
1229 | dput(sdp->sd_root_dir); | 1226 | dput(sdp->sd_root_dir); |
1230 | dput(sdp->sd_master_dir); | 1227 | dput(sdp->sd_master_dir); |
1231 | sdp->sd_root_dir = NULL; | 1228 | sdp->sd_root_dir = NULL; |
1232 | sdp->sd_master_dir = NULL; | 1229 | sdp->sd_master_dir = NULL; |
1233 | } | 1230 | } |
1234 | shrink_dcache_sb(sb); | 1231 | shrink_dcache_sb(sb); |
1235 | kill_block_super(sb); | 1232 | kill_block_super(sb); |
1236 | if (sdp) | 1233 | if (sdp) |
1237 | gfs2_delete_debugfs_file(sdp); | 1234 | gfs2_delete_debugfs_file(sdp); |
1238 | } | 1235 | } |
1239 | 1236 | ||
1240 | struct file_system_type gfs2_fs_type = { | 1237 | struct file_system_type gfs2_fs_type = { |
1241 | .name = "gfs2", | 1238 | .name = "gfs2", |
1242 | .fs_flags = FS_REQUIRES_DEV, | 1239 | .fs_flags = FS_REQUIRES_DEV, |
1243 | .get_sb = gfs2_get_sb, | 1240 | .get_sb = gfs2_get_sb, |
1244 | .kill_sb = gfs2_kill_sb, | 1241 | .kill_sb = gfs2_kill_sb, |
1245 | .owner = THIS_MODULE, | 1242 | .owner = THIS_MODULE, |
1246 | }; | 1243 | }; |
1247 | 1244 | ||
1248 | struct file_system_type gfs2meta_fs_type = { | 1245 | struct file_system_type gfs2meta_fs_type = { |
1249 | .name = "gfs2meta", | 1246 | .name = "gfs2meta", |
1250 | .fs_flags = FS_REQUIRES_DEV, | 1247 | .fs_flags = FS_REQUIRES_DEV, |
1251 | .get_sb = gfs2_get_sb_meta, | 1248 | .get_sb = gfs2_get_sb_meta, |
1252 | .owner = THIS_MODULE, | 1249 | .owner = THIS_MODULE, |
1253 | }; | 1250 | }; |
1254 | 1251 | ||
1255 | 1252 |
fs/gfs2/ops_fstype.h
1 | /* | File was deleted | |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | ||
3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. | ||
4 | * | ||
5 | * This copyrighted material is made available to anyone wishing to use, | ||
6 | * modify, copy, or redistribute it subject to the terms and conditions | ||
7 | * of the GNU General Public License version 2. | ||
8 | */ | ||
9 | |||
10 | #ifndef __OPS_FSTYPE_DOT_H__ | ||
11 | #define __OPS_FSTYPE_DOT_H__ | ||
12 | |||
13 | #include <linux/fs.h> | ||
14 | |||
15 | extern struct file_system_type gfs2_fs_type; | ||
16 | extern struct file_system_type gfs2meta_fs_type; | ||
17 | extern const struct export_operations gfs2_export_ops; | ||
18 | |||
19 | #endif /* __OPS_FSTYPE_DOT_H__ */ | ||
20 | 1 | /* |
fs/gfs2/ops_inode.c
1 | /* | 1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
4 | * | 4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | 5 | * This copyrighted material is made available to anyone wishing to use, |
6 | * modify, copy, or redistribute it subject to the terms and conditions | 6 | * modify, copy, or redistribute it subject to the terms and conditions |
7 | * of the GNU General Public License version 2. | 7 | * of the GNU General Public License version 2. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
11 | #include <linux/spinlock.h> | 11 | #include <linux/spinlock.h> |
12 | #include <linux/completion.h> | 12 | #include <linux/completion.h> |
13 | #include <linux/buffer_head.h> | 13 | #include <linux/buffer_head.h> |
14 | #include <linux/namei.h> | 14 | #include <linux/namei.h> |
15 | #include <linux/utsname.h> | 15 | #include <linux/utsname.h> |
16 | #include <linux/mm.h> | 16 | #include <linux/mm.h> |
17 | #include <linux/xattr.h> | 17 | #include <linux/xattr.h> |
18 | #include <linux/posix_acl.h> | 18 | #include <linux/posix_acl.h> |
19 | #include <linux/gfs2_ondisk.h> | 19 | #include <linux/gfs2_ondisk.h> |
20 | #include <linux/crc32.h> | 20 | #include <linux/crc32.h> |
21 | #include <linux/lm_interface.h> | 21 | #include <linux/lm_interface.h> |
22 | #include <linux/fiemap.h> | 22 | #include <linux/fiemap.h> |
23 | #include <asm/uaccess.h> | 23 | #include <asm/uaccess.h> |
24 | 24 | ||
25 | #include "gfs2.h" | 25 | #include "gfs2.h" |
26 | #include "incore.h" | 26 | #include "incore.h" |
27 | #include "acl.h" | 27 | #include "acl.h" |
28 | #include "bmap.h" | 28 | #include "bmap.h" |
29 | #include "dir.h" | 29 | #include "dir.h" |
30 | #include "eaops.h" | 30 | #include "eaops.h" |
31 | #include "eattr.h" | 31 | #include "eattr.h" |
32 | #include "glock.h" | 32 | #include "glock.h" |
33 | #include "inode.h" | 33 | #include "inode.h" |
34 | #include "meta_io.h" | 34 | #include "meta_io.h" |
35 | #include "ops_dentry.h" | ||
36 | #include "ops_inode.h" | ||
37 | #include "quota.h" | 35 | #include "quota.h" |
38 | #include "rgrp.h" | 36 | #include "rgrp.h" |
39 | #include "trans.h" | 37 | #include "trans.h" |
40 | #include "util.h" | 38 | #include "util.h" |
39 | #include "super.h" | ||
41 | 40 | ||
42 | /** | 41 | /** |
43 | * gfs2_create - Create a file | 42 | * gfs2_create - Create a file |
44 | * @dir: The directory in which to create the file | 43 | * @dir: The directory in which to create the file |
45 | * @dentry: The dentry of the new file | 44 | * @dentry: The dentry of the new file |
46 | * @mode: The mode of the new file | 45 | * @mode: The mode of the new file |
47 | * | 46 | * |
48 | * Returns: errno | 47 | * Returns: errno |
49 | */ | 48 | */ |
50 | 49 | ||
51 | static int gfs2_create(struct inode *dir, struct dentry *dentry, | 50 | static int gfs2_create(struct inode *dir, struct dentry *dentry, |
52 | int mode, struct nameidata *nd) | 51 | int mode, struct nameidata *nd) |
53 | { | 52 | { |
54 | struct gfs2_inode *dip = GFS2_I(dir); | 53 | struct gfs2_inode *dip = GFS2_I(dir); |
55 | struct gfs2_sbd *sdp = GFS2_SB(dir); | 54 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
56 | struct gfs2_holder ghs[2]; | 55 | struct gfs2_holder ghs[2]; |
57 | struct inode *inode; | 56 | struct inode *inode; |
58 | 57 | ||
59 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); | 58 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
60 | 59 | ||
61 | for (;;) { | 60 | for (;;) { |
62 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0); | 61 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0); |
63 | if (!IS_ERR(inode)) { | 62 | if (!IS_ERR(inode)) { |
64 | gfs2_trans_end(sdp); | 63 | gfs2_trans_end(sdp); |
65 | if (dip->i_alloc->al_rgd) | 64 | if (dip->i_alloc->al_rgd) |
66 | gfs2_inplace_release(dip); | 65 | gfs2_inplace_release(dip); |
67 | gfs2_quota_unlock(dip); | 66 | gfs2_quota_unlock(dip); |
68 | gfs2_alloc_put(dip); | 67 | gfs2_alloc_put(dip); |
69 | gfs2_glock_dq_uninit_m(2, ghs); | 68 | gfs2_glock_dq_uninit_m(2, ghs); |
70 | mark_inode_dirty(inode); | 69 | mark_inode_dirty(inode); |
71 | break; | 70 | break; |
72 | } else if (PTR_ERR(inode) != -EEXIST || | 71 | } else if (PTR_ERR(inode) != -EEXIST || |
73 | (nd && nd->flags & LOOKUP_EXCL)) { | 72 | (nd && nd->flags & LOOKUP_EXCL)) { |
74 | gfs2_holder_uninit(ghs); | 73 | gfs2_holder_uninit(ghs); |
75 | return PTR_ERR(inode); | 74 | return PTR_ERR(inode); |
76 | } | 75 | } |
77 | 76 | ||
78 | inode = gfs2_lookupi(dir, &dentry->d_name, 0); | 77 | inode = gfs2_lookupi(dir, &dentry->d_name, 0); |
79 | if (inode) { | 78 | if (inode) { |
80 | if (!IS_ERR(inode)) { | 79 | if (!IS_ERR(inode)) { |
81 | gfs2_holder_uninit(ghs); | 80 | gfs2_holder_uninit(ghs); |
82 | break; | 81 | break; |
83 | } else { | 82 | } else { |
84 | gfs2_holder_uninit(ghs); | 83 | gfs2_holder_uninit(ghs); |
85 | return PTR_ERR(inode); | 84 | return PTR_ERR(inode); |
86 | } | 85 | } |
87 | } | 86 | } |
88 | } | 87 | } |
89 | 88 | ||
90 | d_instantiate(dentry, inode); | 89 | d_instantiate(dentry, inode); |
91 | 90 | ||
92 | return 0; | 91 | return 0; |
93 | } | 92 | } |
94 | 93 | ||
95 | /** | 94 | /** |
96 | * gfs2_lookup - Look up a filename in a directory and return its inode | 95 | * gfs2_lookup - Look up a filename in a directory and return its inode |
97 | * @dir: The directory inode | 96 | * @dir: The directory inode |
98 | * @dentry: The dentry of the new inode | 97 | * @dentry: The dentry of the new inode |
99 | * @nd: passed from Linux VFS, ignored by us | 98 | * @nd: passed from Linux VFS, ignored by us |
100 | * | 99 | * |
101 | * Called by the VFS layer. Lock dir and call gfs2_lookupi() | 100 | * Called by the VFS layer. Lock dir and call gfs2_lookupi() |
102 | * | 101 | * |
103 | * Returns: errno | 102 | * Returns: errno |
104 | */ | 103 | */ |
105 | 104 | ||
106 | static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, | 105 | static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, |
107 | struct nameidata *nd) | 106 | struct nameidata *nd) |
108 | { | 107 | { |
109 | struct inode *inode = NULL; | 108 | struct inode *inode = NULL; |
110 | 109 | ||
111 | dentry->d_op = &gfs2_dops; | 110 | dentry->d_op = &gfs2_dops; |
112 | 111 | ||
113 | inode = gfs2_lookupi(dir, &dentry->d_name, 0); | 112 | inode = gfs2_lookupi(dir, &dentry->d_name, 0); |
114 | if (inode && IS_ERR(inode)) | 113 | if (inode && IS_ERR(inode)) |
115 | return ERR_CAST(inode); | 114 | return ERR_CAST(inode); |
116 | 115 | ||
117 | if (inode) { | 116 | if (inode) { |
118 | struct gfs2_glock *gl = GFS2_I(inode)->i_gl; | 117 | struct gfs2_glock *gl = GFS2_I(inode)->i_gl; |
119 | struct gfs2_holder gh; | 118 | struct gfs2_holder gh; |
120 | int error; | 119 | int error; |
121 | error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); | 120 | error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); |
122 | if (error) { | 121 | if (error) { |
123 | iput(inode); | 122 | iput(inode); |
124 | return ERR_PTR(error); | 123 | return ERR_PTR(error); |
125 | } | 124 | } |
126 | gfs2_glock_dq_uninit(&gh); | 125 | gfs2_glock_dq_uninit(&gh); |
127 | return d_splice_alias(inode, dentry); | 126 | return d_splice_alias(inode, dentry); |
128 | } | 127 | } |
129 | d_add(dentry, inode); | 128 | d_add(dentry, inode); |
130 | 129 | ||
131 | return NULL; | 130 | return NULL; |
132 | } | 131 | } |
133 | 132 | ||
134 | /** | 133 | /** |
135 | * gfs2_link - Link to a file | 134 | * gfs2_link - Link to a file |
136 | * @old_dentry: The inode to link | 135 | * @old_dentry: The inode to link |
137 | * @dir: Add link to this directory | 136 | * @dir: Add link to this directory |
138 | * @dentry: The name of the link | 137 | * @dentry: The name of the link |
139 | * | 138 | * |
140 | * Link the inode in "old_dentry" into the directory "dir" with the | 139 | * Link the inode in "old_dentry" into the directory "dir" with the |
141 | * name in "dentry". | 140 | * name in "dentry". |
142 | * | 141 | * |
143 | * Returns: errno | 142 | * Returns: errno |
144 | */ | 143 | */ |
145 | 144 | ||
146 | static int gfs2_link(struct dentry *old_dentry, struct inode *dir, | 145 | static int gfs2_link(struct dentry *old_dentry, struct inode *dir, |
147 | struct dentry *dentry) | 146 | struct dentry *dentry) |
148 | { | 147 | { |
149 | struct gfs2_inode *dip = GFS2_I(dir); | 148 | struct gfs2_inode *dip = GFS2_I(dir); |
150 | struct gfs2_sbd *sdp = GFS2_SB(dir); | 149 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
151 | struct inode *inode = old_dentry->d_inode; | 150 | struct inode *inode = old_dentry->d_inode; |
152 | struct gfs2_inode *ip = GFS2_I(inode); | 151 | struct gfs2_inode *ip = GFS2_I(inode); |
153 | struct gfs2_holder ghs[2]; | 152 | struct gfs2_holder ghs[2]; |
154 | int alloc_required; | 153 | int alloc_required; |
155 | int error; | 154 | int error; |
156 | 155 | ||
157 | if (S_ISDIR(inode->i_mode)) | 156 | if (S_ISDIR(inode->i_mode)) |
158 | return -EPERM; | 157 | return -EPERM; |
159 | 158 | ||
160 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); | 159 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
161 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); | 160 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); |
162 | 161 | ||
163 | error = gfs2_glock_nq(ghs); /* parent */ | 162 | error = gfs2_glock_nq(ghs); /* parent */ |
164 | if (error) | 163 | if (error) |
165 | goto out_parent; | 164 | goto out_parent; |
166 | 165 | ||
167 | error = gfs2_glock_nq(ghs + 1); /* child */ | 166 | error = gfs2_glock_nq(ghs + 1); /* child */ |
168 | if (error) | 167 | if (error) |
169 | goto out_child; | 168 | goto out_child; |
170 | 169 | ||
171 | error = gfs2_permission(dir, MAY_WRITE | MAY_EXEC); | 170 | error = gfs2_permission(dir, MAY_WRITE | MAY_EXEC); |
172 | if (error) | 171 | if (error) |
173 | goto out_gunlock; | 172 | goto out_gunlock; |
174 | 173 | ||
175 | error = gfs2_dir_check(dir, &dentry->d_name, NULL); | 174 | error = gfs2_dir_check(dir, &dentry->d_name, NULL); |
176 | switch (error) { | 175 | switch (error) { |
177 | case -ENOENT: | 176 | case -ENOENT: |
178 | break; | 177 | break; |
179 | case 0: | 178 | case 0: |
180 | error = -EEXIST; | 179 | error = -EEXIST; |
181 | default: | 180 | default: |
182 | goto out_gunlock; | 181 | goto out_gunlock; |
183 | } | 182 | } |
184 | 183 | ||
185 | error = -EINVAL; | 184 | error = -EINVAL; |
186 | if (!dip->i_inode.i_nlink) | 185 | if (!dip->i_inode.i_nlink) |
187 | goto out_gunlock; | 186 | goto out_gunlock; |
188 | error = -EFBIG; | 187 | error = -EFBIG; |
189 | if (dip->i_di.di_entries == (u32)-1) | 188 | if (dip->i_di.di_entries == (u32)-1) |
190 | goto out_gunlock; | 189 | goto out_gunlock; |
191 | error = -EPERM; | 190 | error = -EPERM; |
192 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) | 191 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
193 | goto out_gunlock; | 192 | goto out_gunlock; |
194 | error = -EINVAL; | 193 | error = -EINVAL; |
195 | if (!ip->i_inode.i_nlink) | 194 | if (!ip->i_inode.i_nlink) |
196 | goto out_gunlock; | 195 | goto out_gunlock; |
197 | error = -EMLINK; | 196 | error = -EMLINK; |
198 | if (ip->i_inode.i_nlink == (u32)-1) | 197 | if (ip->i_inode.i_nlink == (u32)-1) |
199 | goto out_gunlock; | 198 | goto out_gunlock; |
200 | 199 | ||
201 | alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name); | 200 | alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name); |
202 | if (error < 0) | 201 | if (error < 0) |
203 | goto out_gunlock; | 202 | goto out_gunlock; |
204 | error = 0; | 203 | error = 0; |
205 | 204 | ||
206 | if (alloc_required) { | 205 | if (alloc_required) { |
207 | struct gfs2_alloc *al = gfs2_alloc_get(dip); | 206 | struct gfs2_alloc *al = gfs2_alloc_get(dip); |
208 | if (!al) { | 207 | if (!al) { |
209 | error = -ENOMEM; | 208 | error = -ENOMEM; |
210 | goto out_gunlock; | 209 | goto out_gunlock; |
211 | } | 210 | } |
212 | 211 | ||
213 | error = gfs2_quota_lock_check(dip); | 212 | error = gfs2_quota_lock_check(dip); |
214 | if (error) | 213 | if (error) |
215 | goto out_alloc; | 214 | goto out_alloc; |
216 | 215 | ||
217 | al->al_requested = sdp->sd_max_dirres; | 216 | al->al_requested = sdp->sd_max_dirres; |
218 | 217 | ||
219 | error = gfs2_inplace_reserve(dip); | 218 | error = gfs2_inplace_reserve(dip); |
220 | if (error) | 219 | if (error) |
221 | goto out_gunlock_q; | 220 | goto out_gunlock_q; |
222 | 221 | ||
223 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + | 222 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
224 | al->al_rgd->rd_length + | 223 | al->al_rgd->rd_length + |
225 | 2 * RES_DINODE + RES_STATFS + | 224 | 2 * RES_DINODE + RES_STATFS + |
226 | RES_QUOTA, 0); | 225 | RES_QUOTA, 0); |
227 | if (error) | 226 | if (error) |
228 | goto out_ipres; | 227 | goto out_ipres; |
229 | } else { | 228 | } else { |
230 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0); | 229 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0); |
231 | if (error) | 230 | if (error) |
232 | goto out_ipres; | 231 | goto out_ipres; |
233 | } | 232 | } |
234 | 233 | ||
235 | error = gfs2_dir_add(dir, &dentry->d_name, ip, IF2DT(inode->i_mode)); | 234 | error = gfs2_dir_add(dir, &dentry->d_name, ip, IF2DT(inode->i_mode)); |
236 | if (error) | 235 | if (error) |
237 | goto out_end_trans; | 236 | goto out_end_trans; |
238 | 237 | ||
239 | error = gfs2_change_nlink(ip, +1); | 238 | error = gfs2_change_nlink(ip, +1); |
240 | 239 | ||
241 | out_end_trans: | 240 | out_end_trans: |
242 | gfs2_trans_end(sdp); | 241 | gfs2_trans_end(sdp); |
243 | out_ipres: | 242 | out_ipres: |
244 | if (alloc_required) | 243 | if (alloc_required) |
245 | gfs2_inplace_release(dip); | 244 | gfs2_inplace_release(dip); |
246 | out_gunlock_q: | 245 | out_gunlock_q: |
247 | if (alloc_required) | 246 | if (alloc_required) |
248 | gfs2_quota_unlock(dip); | 247 | gfs2_quota_unlock(dip); |
249 | out_alloc: | 248 | out_alloc: |
250 | if (alloc_required) | 249 | if (alloc_required) |
251 | gfs2_alloc_put(dip); | 250 | gfs2_alloc_put(dip); |
252 | out_gunlock: | 251 | out_gunlock: |
253 | gfs2_glock_dq(ghs + 1); | 252 | gfs2_glock_dq(ghs + 1); |
254 | out_child: | 253 | out_child: |
255 | gfs2_glock_dq(ghs); | 254 | gfs2_glock_dq(ghs); |
256 | out_parent: | 255 | out_parent: |
257 | gfs2_holder_uninit(ghs); | 256 | gfs2_holder_uninit(ghs); |
258 | gfs2_holder_uninit(ghs + 1); | 257 | gfs2_holder_uninit(ghs + 1); |
259 | if (!error) { | 258 | if (!error) { |
260 | atomic_inc(&inode->i_count); | 259 | atomic_inc(&inode->i_count); |
261 | d_instantiate(dentry, inode); | 260 | d_instantiate(dentry, inode); |
262 | mark_inode_dirty(inode); | 261 | mark_inode_dirty(inode); |
263 | } | 262 | } |
264 | return error; | 263 | return error; |
265 | } | 264 | } |
266 | 265 | ||
267 | /** | 266 | /** |
268 | * gfs2_unlink - Unlink a file | 267 | * gfs2_unlink - Unlink a file |
269 | * @dir: The inode of the directory containing the file to unlink | 268 | * @dir: The inode of the directory containing the file to unlink |
270 | * @dentry: The file itself | 269 | * @dentry: The file itself |
271 | * | 270 | * |
272 | * Unlink a file. Call gfs2_unlinki() | 271 | * Unlink a file. Call gfs2_unlinki() |
273 | * | 272 | * |
274 | * Returns: errno | 273 | * Returns: errno |
275 | */ | 274 | */ |
276 | 275 | ||
277 | static int gfs2_unlink(struct inode *dir, struct dentry *dentry) | 276 | static int gfs2_unlink(struct inode *dir, struct dentry *dentry) |
278 | { | 277 | { |
279 | struct gfs2_inode *dip = GFS2_I(dir); | 278 | struct gfs2_inode *dip = GFS2_I(dir); |
280 | struct gfs2_sbd *sdp = GFS2_SB(dir); | 279 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
281 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); | 280 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); |
282 | struct gfs2_holder ghs[3]; | 281 | struct gfs2_holder ghs[3]; |
283 | struct gfs2_rgrpd *rgd; | 282 | struct gfs2_rgrpd *rgd; |
284 | struct gfs2_holder ri_gh; | 283 | struct gfs2_holder ri_gh; |
285 | int error; | 284 | int error; |
286 | 285 | ||
287 | error = gfs2_rindex_hold(sdp, &ri_gh); | 286 | error = gfs2_rindex_hold(sdp, &ri_gh); |
288 | if (error) | 287 | if (error) |
289 | return error; | 288 | return error; |
290 | 289 | ||
291 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); | 290 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
292 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); | 291 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); |
293 | 292 | ||
294 | rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); | 293 | rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); |
295 | gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2); | 294 | gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2); |
296 | 295 | ||
297 | 296 | ||
298 | error = gfs2_glock_nq(ghs); /* parent */ | 297 | error = gfs2_glock_nq(ghs); /* parent */ |
299 | if (error) | 298 | if (error) |
300 | goto out_parent; | 299 | goto out_parent; |
301 | 300 | ||
302 | error = gfs2_glock_nq(ghs + 1); /* child */ | 301 | error = gfs2_glock_nq(ghs + 1); /* child */ |
303 | if (error) | 302 | if (error) |
304 | goto out_child; | 303 | goto out_child; |
305 | 304 | ||
306 | error = gfs2_glock_nq(ghs + 2); /* rgrp */ | 305 | error = gfs2_glock_nq(ghs + 2); /* rgrp */ |
307 | if (error) | 306 | if (error) |
308 | goto out_rgrp; | 307 | goto out_rgrp; |
309 | 308 | ||
310 | error = gfs2_unlink_ok(dip, &dentry->d_name, ip); | 309 | error = gfs2_unlink_ok(dip, &dentry->d_name, ip); |
311 | if (error) | 310 | if (error) |
312 | goto out_gunlock; | 311 | goto out_gunlock; |
313 | 312 | ||
314 | error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0); | 313 | error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0); |
315 | if (error) | 314 | if (error) |
316 | goto out_rgrp; | 315 | goto out_rgrp; |
317 | 316 | ||
318 | error = gfs2_dir_del(dip, &dentry->d_name); | 317 | error = gfs2_dir_del(dip, &dentry->d_name); |
319 | if (error) | 318 | if (error) |
320 | goto out_end_trans; | 319 | goto out_end_trans; |
321 | 320 | ||
322 | error = gfs2_change_nlink(ip, -1); | 321 | error = gfs2_change_nlink(ip, -1); |
323 | 322 | ||
324 | out_end_trans: | 323 | out_end_trans: |
325 | gfs2_trans_end(sdp); | 324 | gfs2_trans_end(sdp); |
326 | out_gunlock: | 325 | out_gunlock: |
327 | gfs2_glock_dq(ghs + 2); | 326 | gfs2_glock_dq(ghs + 2); |
328 | out_rgrp: | 327 | out_rgrp: |
329 | gfs2_holder_uninit(ghs + 2); | 328 | gfs2_holder_uninit(ghs + 2); |
330 | gfs2_glock_dq(ghs + 1); | 329 | gfs2_glock_dq(ghs + 1); |
331 | out_child: | 330 | out_child: |
332 | gfs2_holder_uninit(ghs + 1); | 331 | gfs2_holder_uninit(ghs + 1); |
333 | gfs2_glock_dq(ghs); | 332 | gfs2_glock_dq(ghs); |
334 | out_parent: | 333 | out_parent: |
335 | gfs2_holder_uninit(ghs); | 334 | gfs2_holder_uninit(ghs); |
336 | gfs2_glock_dq_uninit(&ri_gh); | 335 | gfs2_glock_dq_uninit(&ri_gh); |
337 | return error; | 336 | return error; |
338 | } | 337 | } |
339 | 338 | ||
340 | /** | 339 | /** |
341 | * gfs2_symlink - Create a symlink | 340 | * gfs2_symlink - Create a symlink |
342 | * @dir: The directory to create the symlink in | 341 | * @dir: The directory to create the symlink in |
343 | * @dentry: The dentry to put the symlink in | 342 | * @dentry: The dentry to put the symlink in |
344 | * @symname: The thing which the link points to | 343 | * @symname: The thing which the link points to |
345 | * | 344 | * |
346 | * Returns: errno | 345 | * Returns: errno |
347 | */ | 346 | */ |
348 | 347 | ||
349 | static int gfs2_symlink(struct inode *dir, struct dentry *dentry, | 348 | static int gfs2_symlink(struct inode *dir, struct dentry *dentry, |
350 | const char *symname) | 349 | const char *symname) |
351 | { | 350 | { |
352 | struct gfs2_inode *dip = GFS2_I(dir), *ip; | 351 | struct gfs2_inode *dip = GFS2_I(dir), *ip; |
353 | struct gfs2_sbd *sdp = GFS2_SB(dir); | 352 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
354 | struct gfs2_holder ghs[2]; | 353 | struct gfs2_holder ghs[2]; |
355 | struct inode *inode; | 354 | struct inode *inode; |
356 | struct buffer_head *dibh; | 355 | struct buffer_head *dibh; |
357 | int size; | 356 | int size; |
358 | int error; | 357 | int error; |
359 | 358 | ||
360 | /* Must be stuffed with a null terminator for gfs2_follow_link() */ | 359 | /* Must be stuffed with a null terminator for gfs2_follow_link() */ |
361 | size = strlen(symname); | 360 | size = strlen(symname); |
362 | if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1) | 361 | if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1) |
363 | return -ENAMETOOLONG; | 362 | return -ENAMETOOLONG; |
364 | 363 | ||
365 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); | 364 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
366 | 365 | ||
367 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0); | 366 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0); |
368 | if (IS_ERR(inode)) { | 367 | if (IS_ERR(inode)) { |
369 | gfs2_holder_uninit(ghs); | 368 | gfs2_holder_uninit(ghs); |
370 | return PTR_ERR(inode); | 369 | return PTR_ERR(inode); |
371 | } | 370 | } |
372 | 371 | ||
373 | ip = ghs[1].gh_gl->gl_object; | 372 | ip = ghs[1].gh_gl->gl_object; |
374 | 373 | ||
375 | ip->i_di.di_size = size; | 374 | ip->i_di.di_size = size; |
376 | 375 | ||
377 | error = gfs2_meta_inode_buffer(ip, &dibh); | 376 | error = gfs2_meta_inode_buffer(ip, &dibh); |
378 | 377 | ||
379 | if (!gfs2_assert_withdraw(sdp, !error)) { | 378 | if (!gfs2_assert_withdraw(sdp, !error)) { |
380 | gfs2_dinode_out(ip, dibh->b_data); | 379 | gfs2_dinode_out(ip, dibh->b_data); |
381 | memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname, | 380 | memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname, |
382 | size); | 381 | size); |
383 | brelse(dibh); | 382 | brelse(dibh); |
384 | } | 383 | } |
385 | 384 | ||
386 | gfs2_trans_end(sdp); | 385 | gfs2_trans_end(sdp); |
387 | if (dip->i_alloc->al_rgd) | 386 | if (dip->i_alloc->al_rgd) |
388 | gfs2_inplace_release(dip); | 387 | gfs2_inplace_release(dip); |
389 | gfs2_quota_unlock(dip); | 388 | gfs2_quota_unlock(dip); |
390 | gfs2_alloc_put(dip); | 389 | gfs2_alloc_put(dip); |
391 | 390 | ||
392 | gfs2_glock_dq_uninit_m(2, ghs); | 391 | gfs2_glock_dq_uninit_m(2, ghs); |
393 | 392 | ||
394 | d_instantiate(dentry, inode); | 393 | d_instantiate(dentry, inode); |
395 | mark_inode_dirty(inode); | 394 | mark_inode_dirty(inode); |
396 | 395 | ||
397 | return 0; | 396 | return 0; |
398 | } | 397 | } |
399 | 398 | ||
400 | /** | 399 | /** |
401 | * gfs2_mkdir - Make a directory | 400 | * gfs2_mkdir - Make a directory |
402 | * @dir: The parent directory of the new one | 401 | * @dir: The parent directory of the new one |
403 | * @dentry: The dentry of the new directory | 402 | * @dentry: The dentry of the new directory |
404 | * @mode: The mode of the new directory | 403 | * @mode: The mode of the new directory |
405 | * | 404 | * |
406 | * Returns: errno | 405 | * Returns: errno |
407 | */ | 406 | */ |
408 | 407 | ||
409 | static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) | 408 | static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
410 | { | 409 | { |
411 | struct gfs2_inode *dip = GFS2_I(dir), *ip; | 410 | struct gfs2_inode *dip = GFS2_I(dir), *ip; |
412 | struct gfs2_sbd *sdp = GFS2_SB(dir); | 411 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
413 | struct gfs2_holder ghs[2]; | 412 | struct gfs2_holder ghs[2]; |
414 | struct inode *inode; | 413 | struct inode *inode; |
415 | struct buffer_head *dibh; | 414 | struct buffer_head *dibh; |
416 | int error; | 415 | int error; |
417 | 416 | ||
418 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); | 417 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
419 | 418 | ||
420 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0); | 419 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0); |
421 | if (IS_ERR(inode)) { | 420 | if (IS_ERR(inode)) { |
422 | gfs2_holder_uninit(ghs); | 421 | gfs2_holder_uninit(ghs); |
423 | return PTR_ERR(inode); | 422 | return PTR_ERR(inode); |
424 | } | 423 | } |
425 | 424 | ||
426 | ip = ghs[1].gh_gl->gl_object; | 425 | ip = ghs[1].gh_gl->gl_object; |
427 | 426 | ||
428 | ip->i_inode.i_nlink = 2; | 427 | ip->i_inode.i_nlink = 2; |
429 | ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode); | 428 | ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode); |
430 | ip->i_di.di_flags |= GFS2_DIF_JDATA; | 429 | ip->i_di.di_flags |= GFS2_DIF_JDATA; |
431 | ip->i_di.di_entries = 2; | 430 | ip->i_di.di_entries = 2; |
432 | 431 | ||
433 | error = gfs2_meta_inode_buffer(ip, &dibh); | 432 | error = gfs2_meta_inode_buffer(ip, &dibh); |
434 | 433 | ||
435 | if (!gfs2_assert_withdraw(sdp, !error)) { | 434 | if (!gfs2_assert_withdraw(sdp, !error)) { |
436 | struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data; | 435 | struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data; |
437 | struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1); | 436 | struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1); |
438 | struct qstr str; | 437 | struct qstr str; |
439 | 438 | ||
440 | gfs2_str2qstr(&str, "."); | 439 | gfs2_str2qstr(&str, "."); |
441 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); | 440 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
442 | gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent); | 441 | gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent); |
443 | dent->de_inum = di->di_num; /* already GFS2 endian */ | 442 | dent->de_inum = di->di_num; /* already GFS2 endian */ |
444 | dent->de_type = cpu_to_be16(DT_DIR); | 443 | dent->de_type = cpu_to_be16(DT_DIR); |
445 | di->di_entries = cpu_to_be32(1); | 444 | di->di_entries = cpu_to_be32(1); |
446 | 445 | ||
447 | gfs2_str2qstr(&str, ".."); | 446 | gfs2_str2qstr(&str, ".."); |
448 | dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1)); | 447 | dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1)); |
449 | gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent); | 448 | gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent); |
450 | 449 | ||
451 | gfs2_inum_out(dip, dent); | 450 | gfs2_inum_out(dip, dent); |
452 | dent->de_type = cpu_to_be16(DT_DIR); | 451 | dent->de_type = cpu_to_be16(DT_DIR); |
453 | 452 | ||
454 | gfs2_dinode_out(ip, di); | 453 | gfs2_dinode_out(ip, di); |
455 | 454 | ||
456 | brelse(dibh); | 455 | brelse(dibh); |
457 | } | 456 | } |
458 | 457 | ||
459 | error = gfs2_change_nlink(dip, +1); | 458 | error = gfs2_change_nlink(dip, +1); |
460 | gfs2_assert_withdraw(sdp, !error); /* dip already pinned */ | 459 | gfs2_assert_withdraw(sdp, !error); /* dip already pinned */ |
461 | 460 | ||
462 | gfs2_trans_end(sdp); | 461 | gfs2_trans_end(sdp); |
463 | if (dip->i_alloc->al_rgd) | 462 | if (dip->i_alloc->al_rgd) |
464 | gfs2_inplace_release(dip); | 463 | gfs2_inplace_release(dip); |
465 | gfs2_quota_unlock(dip); | 464 | gfs2_quota_unlock(dip); |
466 | gfs2_alloc_put(dip); | 465 | gfs2_alloc_put(dip); |
467 | 466 | ||
468 | gfs2_glock_dq_uninit_m(2, ghs); | 467 | gfs2_glock_dq_uninit_m(2, ghs); |
469 | 468 | ||
470 | d_instantiate(dentry, inode); | 469 | d_instantiate(dentry, inode); |
471 | mark_inode_dirty(inode); | 470 | mark_inode_dirty(inode); |
472 | 471 | ||
473 | return 0; | 472 | return 0; |
474 | } | 473 | } |
475 | 474 | ||
476 | /** | 475 | /** |
477 | * gfs2_rmdir - Remove a directory | 476 | * gfs2_rmdir - Remove a directory |
478 | * @dir: The parent directory of the directory to be removed | 477 | * @dir: The parent directory of the directory to be removed |
479 | * @dentry: The dentry of the directory to remove | 478 | * @dentry: The dentry of the directory to remove |
480 | * | 479 | * |
481 | * Remove a directory. Call gfs2_rmdiri() | 480 | * Remove a directory. Call gfs2_rmdiri() |
482 | * | 481 | * |
483 | * Returns: errno | 482 | * Returns: errno |
484 | */ | 483 | */ |
485 | 484 | ||
486 | static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) | 485 | static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) |
487 | { | 486 | { |
488 | struct gfs2_inode *dip = GFS2_I(dir); | 487 | struct gfs2_inode *dip = GFS2_I(dir); |
489 | struct gfs2_sbd *sdp = GFS2_SB(dir); | 488 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
490 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); | 489 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); |
491 | struct gfs2_holder ghs[3]; | 490 | struct gfs2_holder ghs[3]; |
492 | struct gfs2_rgrpd *rgd; | 491 | struct gfs2_rgrpd *rgd; |
493 | struct gfs2_holder ri_gh; | 492 | struct gfs2_holder ri_gh; |
494 | int error; | 493 | int error; |
495 | 494 | ||
496 | error = gfs2_rindex_hold(sdp, &ri_gh); | 495 | error = gfs2_rindex_hold(sdp, &ri_gh); |
497 | if (error) | 496 | if (error) |
498 | return error; | 497 | return error; |
499 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); | 498 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
500 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); | 499 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); |
501 | 500 | ||
502 | rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); | 501 | rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); |
503 | gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2); | 502 | gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2); |
504 | 503 | ||
505 | error = gfs2_glock_nq(ghs); /* parent */ | 504 | error = gfs2_glock_nq(ghs); /* parent */ |
506 | if (error) | 505 | if (error) |
507 | goto out_parent; | 506 | goto out_parent; |
508 | 507 | ||
509 | error = gfs2_glock_nq(ghs + 1); /* child */ | 508 | error = gfs2_glock_nq(ghs + 1); /* child */ |
510 | if (error) | 509 | if (error) |
511 | goto out_child; | 510 | goto out_child; |
512 | 511 | ||
513 | error = gfs2_glock_nq(ghs + 2); /* rgrp */ | 512 | error = gfs2_glock_nq(ghs + 2); /* rgrp */ |
514 | if (error) | 513 | if (error) |
515 | goto out_rgrp; | 514 | goto out_rgrp; |
516 | 515 | ||
517 | error = gfs2_unlink_ok(dip, &dentry->d_name, ip); | 516 | error = gfs2_unlink_ok(dip, &dentry->d_name, ip); |
518 | if (error) | 517 | if (error) |
519 | goto out_gunlock; | 518 | goto out_gunlock; |
520 | 519 | ||
521 | if (ip->i_di.di_entries < 2) { | 520 | if (ip->i_di.di_entries < 2) { |
522 | if (gfs2_consist_inode(ip)) | 521 | if (gfs2_consist_inode(ip)) |
523 | gfs2_dinode_print(ip); | 522 | gfs2_dinode_print(ip); |
524 | error = -EIO; | 523 | error = -EIO; |
525 | goto out_gunlock; | 524 | goto out_gunlock; |
526 | } | 525 | } |
527 | if (ip->i_di.di_entries > 2) { | 526 | if (ip->i_di.di_entries > 2) { |
528 | error = -ENOTEMPTY; | 527 | error = -ENOTEMPTY; |
529 | goto out_gunlock; | 528 | goto out_gunlock; |
530 | } | 529 | } |
531 | 530 | ||
532 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0); | 531 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0); |
533 | if (error) | 532 | if (error) |
534 | goto out_gunlock; | 533 | goto out_gunlock; |
535 | 534 | ||
536 | error = gfs2_rmdiri(dip, &dentry->d_name, ip); | 535 | error = gfs2_rmdiri(dip, &dentry->d_name, ip); |
537 | 536 | ||
538 | gfs2_trans_end(sdp); | 537 | gfs2_trans_end(sdp); |
539 | 538 | ||
540 | out_gunlock: | 539 | out_gunlock: |
541 | gfs2_glock_dq(ghs + 2); | 540 | gfs2_glock_dq(ghs + 2); |
542 | out_rgrp: | 541 | out_rgrp: |
543 | gfs2_holder_uninit(ghs + 2); | 542 | gfs2_holder_uninit(ghs + 2); |
544 | gfs2_glock_dq(ghs + 1); | 543 | gfs2_glock_dq(ghs + 1); |
545 | out_child: | 544 | out_child: |
546 | gfs2_holder_uninit(ghs + 1); | 545 | gfs2_holder_uninit(ghs + 1); |
547 | gfs2_glock_dq(ghs); | 546 | gfs2_glock_dq(ghs); |
548 | out_parent: | 547 | out_parent: |
549 | gfs2_holder_uninit(ghs); | 548 | gfs2_holder_uninit(ghs); |
550 | gfs2_glock_dq_uninit(&ri_gh); | 549 | gfs2_glock_dq_uninit(&ri_gh); |
551 | return error; | 550 | return error; |
552 | } | 551 | } |
553 | 552 | ||
554 | /** | 553 | /** |
555 | * gfs2_mknod - Make a special file | 554 | * gfs2_mknod - Make a special file |
556 | * @dir: The directory in which the special file will reside | 555 | * @dir: The directory in which the special file will reside |
557 | * @dentry: The dentry of the special file | 556 | * @dentry: The dentry of the special file |
558 | * @mode: The mode of the special file | 557 | * @mode: The mode of the special file |
559 | * @rdev: The device specification of the special file | 558 | * @rdev: The device specification of the special file |
560 | * | 559 | * |
561 | */ | 560 | */ |
562 | 561 | ||
563 | static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, | 562 | static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, |
564 | dev_t dev) | 563 | dev_t dev) |
565 | { | 564 | { |
566 | struct gfs2_inode *dip = GFS2_I(dir); | 565 | struct gfs2_inode *dip = GFS2_I(dir); |
567 | struct gfs2_sbd *sdp = GFS2_SB(dir); | 566 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
568 | struct gfs2_holder ghs[2]; | 567 | struct gfs2_holder ghs[2]; |
569 | struct inode *inode; | 568 | struct inode *inode; |
570 | 569 | ||
571 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); | 570 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
572 | 571 | ||
573 | inode = gfs2_createi(ghs, &dentry->d_name, mode, dev); | 572 | inode = gfs2_createi(ghs, &dentry->d_name, mode, dev); |
574 | if (IS_ERR(inode)) { | 573 | if (IS_ERR(inode)) { |
575 | gfs2_holder_uninit(ghs); | 574 | gfs2_holder_uninit(ghs); |
576 | return PTR_ERR(inode); | 575 | return PTR_ERR(inode); |
577 | } | 576 | } |
578 | 577 | ||
579 | gfs2_trans_end(sdp); | 578 | gfs2_trans_end(sdp); |
580 | if (dip->i_alloc->al_rgd) | 579 | if (dip->i_alloc->al_rgd) |
581 | gfs2_inplace_release(dip); | 580 | gfs2_inplace_release(dip); |
582 | gfs2_quota_unlock(dip); | 581 | gfs2_quota_unlock(dip); |
583 | gfs2_alloc_put(dip); | 582 | gfs2_alloc_put(dip); |
584 | 583 | ||
585 | gfs2_glock_dq_uninit_m(2, ghs); | 584 | gfs2_glock_dq_uninit_m(2, ghs); |
586 | 585 | ||
587 | d_instantiate(dentry, inode); | 586 | d_instantiate(dentry, inode); |
588 | mark_inode_dirty(inode); | 587 | mark_inode_dirty(inode); |
589 | 588 | ||
590 | return 0; | 589 | return 0; |
591 | } | 590 | } |
592 | 591 | ||
593 | /* | 592 | /* |
594 | * gfs2_ok_to_move - check if it's ok to move a directory to another directory | 593 | * gfs2_ok_to_move - check if it's ok to move a directory to another directory |
595 | * @this: move this | 594 | * @this: move this |
596 | * @to: to here | 595 | * @to: to here |
597 | * | 596 | * |
598 | * Follow @to back to the root and make sure we don't encounter @this | 597 | * Follow @to back to the root and make sure we don't encounter @this |
599 | * Assumes we already hold the rename lock. | 598 | * Assumes we already hold the rename lock. |
600 | * | 599 | * |
601 | * Returns: errno | 600 | * Returns: errno |
602 | */ | 601 | */ |
603 | 602 | ||
604 | static int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) | 603 | static int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) |
605 | { | 604 | { |
606 | struct inode *dir = &to->i_inode; | 605 | struct inode *dir = &to->i_inode; |
607 | struct super_block *sb = dir->i_sb; | 606 | struct super_block *sb = dir->i_sb; |
608 | struct inode *tmp; | 607 | struct inode *tmp; |
609 | struct qstr dotdot; | 608 | struct qstr dotdot; |
610 | int error = 0; | 609 | int error = 0; |
611 | 610 | ||
612 | gfs2_str2qstr(&dotdot, ".."); | 611 | gfs2_str2qstr(&dotdot, ".."); |
613 | 612 | ||
614 | igrab(dir); | 613 | igrab(dir); |
615 | 614 | ||
616 | for (;;) { | 615 | for (;;) { |
617 | if (dir == &this->i_inode) { | 616 | if (dir == &this->i_inode) { |
618 | error = -EINVAL; | 617 | error = -EINVAL; |
619 | break; | 618 | break; |
620 | } | 619 | } |
621 | if (dir == sb->s_root->d_inode) { | 620 | if (dir == sb->s_root->d_inode) { |
622 | error = 0; | 621 | error = 0; |
623 | break; | 622 | break; |
624 | } | 623 | } |
625 | 624 | ||
626 | tmp = gfs2_lookupi(dir, &dotdot, 1); | 625 | tmp = gfs2_lookupi(dir, &dotdot, 1); |
627 | if (IS_ERR(tmp)) { | 626 | if (IS_ERR(tmp)) { |
628 | error = PTR_ERR(tmp); | 627 | error = PTR_ERR(tmp); |
629 | break; | 628 | break; |
630 | } | 629 | } |
631 | 630 | ||
632 | iput(dir); | 631 | iput(dir); |
633 | dir = tmp; | 632 | dir = tmp; |
634 | } | 633 | } |
635 | 634 | ||
636 | iput(dir); | 635 | iput(dir); |
637 | 636 | ||
638 | return error; | 637 | return error; |
639 | } | 638 | } |
640 | 639 | ||
641 | /** | 640 | /** |
642 | * gfs2_rename - Rename a file | 641 | * gfs2_rename - Rename a file |
643 | * @odir: Parent directory of old file name | 642 | * @odir: Parent directory of old file name |
644 | * @odentry: The old dentry of the file | 643 | * @odentry: The old dentry of the file |
645 | * @ndir: Parent directory of new file name | 644 | * @ndir: Parent directory of new file name |
646 | * @ndentry: The new dentry of the file | 645 | * @ndentry: The new dentry of the file |
647 | * | 646 | * |
648 | * Returns: errno | 647 | * Returns: errno |
649 | */ | 648 | */ |
650 | 649 | ||
651 | static int gfs2_rename(struct inode *odir, struct dentry *odentry, | 650 | static int gfs2_rename(struct inode *odir, struct dentry *odentry, |
652 | struct inode *ndir, struct dentry *ndentry) | 651 | struct inode *ndir, struct dentry *ndentry) |
653 | { | 652 | { |
654 | struct gfs2_inode *odip = GFS2_I(odir); | 653 | struct gfs2_inode *odip = GFS2_I(odir); |
655 | struct gfs2_inode *ndip = GFS2_I(ndir); | 654 | struct gfs2_inode *ndip = GFS2_I(ndir); |
656 | struct gfs2_inode *ip = GFS2_I(odentry->d_inode); | 655 | struct gfs2_inode *ip = GFS2_I(odentry->d_inode); |
657 | struct gfs2_inode *nip = NULL; | 656 | struct gfs2_inode *nip = NULL; |
658 | struct gfs2_sbd *sdp = GFS2_SB(odir); | 657 | struct gfs2_sbd *sdp = GFS2_SB(odir); |
659 | struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, }; | 658 | struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, }; |
660 | struct gfs2_rgrpd *nrgd; | 659 | struct gfs2_rgrpd *nrgd; |
661 | unsigned int num_gh; | 660 | unsigned int num_gh; |
662 | int dir_rename = 0; | 661 | int dir_rename = 0; |
663 | int alloc_required; | 662 | int alloc_required; |
664 | unsigned int x; | 663 | unsigned int x; |
665 | int error; | 664 | int error; |
666 | 665 | ||
667 | if (ndentry->d_inode) { | 666 | if (ndentry->d_inode) { |
668 | nip = GFS2_I(ndentry->d_inode); | 667 | nip = GFS2_I(ndentry->d_inode); |
669 | if (ip == nip) | 668 | if (ip == nip) |
670 | return 0; | 669 | return 0; |
671 | } | 670 | } |
672 | 671 | ||
673 | 672 | ||
674 | if (odip != ndip) { | 673 | if (odip != ndip) { |
675 | error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, | 674 | error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, |
676 | 0, &r_gh); | 675 | 0, &r_gh); |
677 | if (error) | 676 | if (error) |
678 | goto out; | 677 | goto out; |
679 | 678 | ||
680 | if (S_ISDIR(ip->i_inode.i_mode)) { | 679 | if (S_ISDIR(ip->i_inode.i_mode)) { |
681 | dir_rename = 1; | 680 | dir_rename = 1; |
682 | /* don't move a dirctory into it's subdir */ | 681 | /* don't move a dirctory into it's subdir */ |
683 | error = gfs2_ok_to_move(ip, ndip); | 682 | error = gfs2_ok_to_move(ip, ndip); |
684 | if (error) | 683 | if (error) |
685 | goto out_gunlock_r; | 684 | goto out_gunlock_r; |
686 | } | 685 | } |
687 | } | 686 | } |
688 | 687 | ||
689 | num_gh = 1; | 688 | num_gh = 1; |
690 | gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); | 689 | gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
691 | if (odip != ndip) { | 690 | if (odip != ndip) { |
692 | gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); | 691 | gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); |
693 | num_gh++; | 692 | num_gh++; |
694 | } | 693 | } |
695 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); | 694 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); |
696 | num_gh++; | 695 | num_gh++; |
697 | 696 | ||
698 | if (nip) { | 697 | if (nip) { |
699 | gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); | 698 | gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); |
700 | num_gh++; | 699 | num_gh++; |
701 | /* grab the resource lock for unlink flag twiddling | 700 | /* grab the resource lock for unlink flag twiddling |
702 | * this is the case of the target file already existing | 701 | * this is the case of the target file already existing |
703 | * so we unlink before doing the rename | 702 | * so we unlink before doing the rename |
704 | */ | 703 | */ |
705 | nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr); | 704 | nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr); |
706 | if (nrgd) | 705 | if (nrgd) |
707 | gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++); | 706 | gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++); |
708 | } | 707 | } |
709 | 708 | ||
710 | for (x = 0; x < num_gh; x++) { | 709 | for (x = 0; x < num_gh; x++) { |
711 | error = gfs2_glock_nq(ghs + x); | 710 | error = gfs2_glock_nq(ghs + x); |
712 | if (error) | 711 | if (error) |
713 | goto out_gunlock; | 712 | goto out_gunlock; |
714 | } | 713 | } |
715 | 714 | ||
716 | /* Check out the old directory */ | 715 | /* Check out the old directory */ |
717 | 716 | ||
718 | error = gfs2_unlink_ok(odip, &odentry->d_name, ip); | 717 | error = gfs2_unlink_ok(odip, &odentry->d_name, ip); |
719 | if (error) | 718 | if (error) |
720 | goto out_gunlock; | 719 | goto out_gunlock; |
721 | 720 | ||
722 | /* Check out the new directory */ | 721 | /* Check out the new directory */ |
723 | 722 | ||
724 | if (nip) { | 723 | if (nip) { |
725 | error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip); | 724 | error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip); |
726 | if (error) | 725 | if (error) |
727 | goto out_gunlock; | 726 | goto out_gunlock; |
728 | 727 | ||
729 | if (S_ISDIR(nip->i_inode.i_mode)) { | 728 | if (S_ISDIR(nip->i_inode.i_mode)) { |
730 | if (nip->i_di.di_entries < 2) { | 729 | if (nip->i_di.di_entries < 2) { |
731 | if (gfs2_consist_inode(nip)) | 730 | if (gfs2_consist_inode(nip)) |
732 | gfs2_dinode_print(nip); | 731 | gfs2_dinode_print(nip); |
733 | error = -EIO; | 732 | error = -EIO; |
734 | goto out_gunlock; | 733 | goto out_gunlock; |
735 | } | 734 | } |
736 | if (nip->i_di.di_entries > 2) { | 735 | if (nip->i_di.di_entries > 2) { |
737 | error = -ENOTEMPTY; | 736 | error = -ENOTEMPTY; |
738 | goto out_gunlock; | 737 | goto out_gunlock; |
739 | } | 738 | } |
740 | } | 739 | } |
741 | } else { | 740 | } else { |
742 | error = gfs2_permission(ndir, MAY_WRITE | MAY_EXEC); | 741 | error = gfs2_permission(ndir, MAY_WRITE | MAY_EXEC); |
743 | if (error) | 742 | if (error) |
744 | goto out_gunlock; | 743 | goto out_gunlock; |
745 | 744 | ||
746 | error = gfs2_dir_check(ndir, &ndentry->d_name, NULL); | 745 | error = gfs2_dir_check(ndir, &ndentry->d_name, NULL); |
747 | switch (error) { | 746 | switch (error) { |
748 | case -ENOENT: | 747 | case -ENOENT: |
749 | error = 0; | 748 | error = 0; |
750 | break; | 749 | break; |
751 | case 0: | 750 | case 0: |
752 | error = -EEXIST; | 751 | error = -EEXIST; |
753 | default: | 752 | default: |
754 | goto out_gunlock; | 753 | goto out_gunlock; |
755 | }; | 754 | }; |
756 | 755 | ||
757 | if (odip != ndip) { | 756 | if (odip != ndip) { |
758 | if (!ndip->i_inode.i_nlink) { | 757 | if (!ndip->i_inode.i_nlink) { |
759 | error = -EINVAL; | 758 | error = -EINVAL; |
760 | goto out_gunlock; | 759 | goto out_gunlock; |
761 | } | 760 | } |
762 | if (ndip->i_di.di_entries == (u32)-1) { | 761 | if (ndip->i_di.di_entries == (u32)-1) { |
763 | error = -EFBIG; | 762 | error = -EFBIG; |
764 | goto out_gunlock; | 763 | goto out_gunlock; |
765 | } | 764 | } |
766 | if (S_ISDIR(ip->i_inode.i_mode) && | 765 | if (S_ISDIR(ip->i_inode.i_mode) && |
767 | ndip->i_inode.i_nlink == (u32)-1) { | 766 | ndip->i_inode.i_nlink == (u32)-1) { |
768 | error = -EMLINK; | 767 | error = -EMLINK; |
769 | goto out_gunlock; | 768 | goto out_gunlock; |
770 | } | 769 | } |
771 | } | 770 | } |
772 | } | 771 | } |
773 | 772 | ||
774 | /* Check out the dir to be renamed */ | 773 | /* Check out the dir to be renamed */ |
775 | 774 | ||
776 | if (dir_rename) { | 775 | if (dir_rename) { |
777 | error = gfs2_permission(odentry->d_inode, MAY_WRITE); | 776 | error = gfs2_permission(odentry->d_inode, MAY_WRITE); |
778 | if (error) | 777 | if (error) |
779 | goto out_gunlock; | 778 | goto out_gunlock; |
780 | } | 779 | } |
781 | 780 | ||
782 | alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name); | 781 | alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name); |
783 | if (error < 0) | 782 | if (error < 0) |
784 | goto out_gunlock; | 783 | goto out_gunlock; |
785 | error = 0; | 784 | error = 0; |
786 | 785 | ||
787 | if (alloc_required) { | 786 | if (alloc_required) { |
788 | struct gfs2_alloc *al = gfs2_alloc_get(ndip); | 787 | struct gfs2_alloc *al = gfs2_alloc_get(ndip); |
789 | if (!al) { | 788 | if (!al) { |
790 | error = -ENOMEM; | 789 | error = -ENOMEM; |
791 | goto out_gunlock; | 790 | goto out_gunlock; |
792 | } | 791 | } |
793 | 792 | ||
794 | error = gfs2_quota_lock_check(ndip); | 793 | error = gfs2_quota_lock_check(ndip); |
795 | if (error) | 794 | if (error) |
796 | goto out_alloc; | 795 | goto out_alloc; |
797 | 796 | ||
798 | al->al_requested = sdp->sd_max_dirres; | 797 | al->al_requested = sdp->sd_max_dirres; |
799 | 798 | ||
800 | error = gfs2_inplace_reserve(ndip); | 799 | error = gfs2_inplace_reserve(ndip); |
801 | if (error) | 800 | if (error) |
802 | goto out_gunlock_q; | 801 | goto out_gunlock_q; |
803 | 802 | ||
804 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + | 803 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
805 | al->al_rgd->rd_length + | 804 | al->al_rgd->rd_length + |
806 | 4 * RES_DINODE + 4 * RES_LEAF + | 805 | 4 * RES_DINODE + 4 * RES_LEAF + |
807 | RES_STATFS + RES_QUOTA + 4, 0); | 806 | RES_STATFS + RES_QUOTA + 4, 0); |
808 | if (error) | 807 | if (error) |
809 | goto out_ipreserv; | 808 | goto out_ipreserv; |
810 | } else { | 809 | } else { |
811 | error = gfs2_trans_begin(sdp, 4 * RES_DINODE + | 810 | error = gfs2_trans_begin(sdp, 4 * RES_DINODE + |
812 | 5 * RES_LEAF + 4, 0); | 811 | 5 * RES_LEAF + 4, 0); |
813 | if (error) | 812 | if (error) |
814 | goto out_gunlock; | 813 | goto out_gunlock; |
815 | } | 814 | } |
816 | 815 | ||
817 | /* Remove the target file, if it exists */ | 816 | /* Remove the target file, if it exists */ |
818 | 817 | ||
819 | if (nip) { | 818 | if (nip) { |
820 | if (S_ISDIR(nip->i_inode.i_mode)) | 819 | if (S_ISDIR(nip->i_inode.i_mode)) |
821 | error = gfs2_rmdiri(ndip, &ndentry->d_name, nip); | 820 | error = gfs2_rmdiri(ndip, &ndentry->d_name, nip); |
822 | else { | 821 | else { |
823 | error = gfs2_dir_del(ndip, &ndentry->d_name); | 822 | error = gfs2_dir_del(ndip, &ndentry->d_name); |
824 | if (error) | 823 | if (error) |
825 | goto out_end_trans; | 824 | goto out_end_trans; |
826 | error = gfs2_change_nlink(nip, -1); | 825 | error = gfs2_change_nlink(nip, -1); |
827 | } | 826 | } |
828 | if (error) | 827 | if (error) |
829 | goto out_end_trans; | 828 | goto out_end_trans; |
830 | } | 829 | } |
831 | 830 | ||
832 | if (dir_rename) { | 831 | if (dir_rename) { |
833 | struct qstr name; | 832 | struct qstr name; |
834 | gfs2_str2qstr(&name, ".."); | 833 | gfs2_str2qstr(&name, ".."); |
835 | 834 | ||
836 | error = gfs2_change_nlink(ndip, +1); | 835 | error = gfs2_change_nlink(ndip, +1); |
837 | if (error) | 836 | if (error) |
838 | goto out_end_trans; | 837 | goto out_end_trans; |
839 | error = gfs2_change_nlink(odip, -1); | 838 | error = gfs2_change_nlink(odip, -1); |
840 | if (error) | 839 | if (error) |
841 | goto out_end_trans; | 840 | goto out_end_trans; |
842 | 841 | ||
843 | error = gfs2_dir_mvino(ip, &name, ndip, DT_DIR); | 842 | error = gfs2_dir_mvino(ip, &name, ndip, DT_DIR); |
844 | if (error) | 843 | if (error) |
845 | goto out_end_trans; | 844 | goto out_end_trans; |
846 | } else { | 845 | } else { |
847 | struct buffer_head *dibh; | 846 | struct buffer_head *dibh; |
848 | error = gfs2_meta_inode_buffer(ip, &dibh); | 847 | error = gfs2_meta_inode_buffer(ip, &dibh); |
849 | if (error) | 848 | if (error) |
850 | goto out_end_trans; | 849 | goto out_end_trans; |
851 | ip->i_inode.i_ctime = CURRENT_TIME; | 850 | ip->i_inode.i_ctime = CURRENT_TIME; |
852 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); | 851 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
853 | gfs2_dinode_out(ip, dibh->b_data); | 852 | gfs2_dinode_out(ip, dibh->b_data); |
854 | brelse(dibh); | 853 | brelse(dibh); |
855 | } | 854 | } |
856 | 855 | ||
857 | error = gfs2_dir_del(odip, &odentry->d_name); | 856 | error = gfs2_dir_del(odip, &odentry->d_name); |
858 | if (error) | 857 | if (error) |
859 | goto out_end_trans; | 858 | goto out_end_trans; |
860 | 859 | ||
861 | error = gfs2_dir_add(ndir, &ndentry->d_name, ip, IF2DT(ip->i_inode.i_mode)); | 860 | error = gfs2_dir_add(ndir, &ndentry->d_name, ip, IF2DT(ip->i_inode.i_mode)); |
862 | if (error) | 861 | if (error) |
863 | goto out_end_trans; | 862 | goto out_end_trans; |
864 | 863 | ||
865 | out_end_trans: | 864 | out_end_trans: |
866 | gfs2_trans_end(sdp); | 865 | gfs2_trans_end(sdp); |
867 | out_ipreserv: | 866 | out_ipreserv: |
868 | if (alloc_required) | 867 | if (alloc_required) |
869 | gfs2_inplace_release(ndip); | 868 | gfs2_inplace_release(ndip); |
870 | out_gunlock_q: | 869 | out_gunlock_q: |
871 | if (alloc_required) | 870 | if (alloc_required) |
872 | gfs2_quota_unlock(ndip); | 871 | gfs2_quota_unlock(ndip); |
873 | out_alloc: | 872 | out_alloc: |
874 | if (alloc_required) | 873 | if (alloc_required) |
875 | gfs2_alloc_put(ndip); | 874 | gfs2_alloc_put(ndip); |
876 | out_gunlock: | 875 | out_gunlock: |
877 | while (x--) { | 876 | while (x--) { |
878 | gfs2_glock_dq(ghs + x); | 877 | gfs2_glock_dq(ghs + x); |
879 | gfs2_holder_uninit(ghs + x); | 878 | gfs2_holder_uninit(ghs + x); |
880 | } | 879 | } |
881 | out_gunlock_r: | 880 | out_gunlock_r: |
882 | if (r_gh.gh_gl) | 881 | if (r_gh.gh_gl) |
883 | gfs2_glock_dq_uninit(&r_gh); | 882 | gfs2_glock_dq_uninit(&r_gh); |
884 | out: | 883 | out: |
885 | return error; | 884 | return error; |
886 | } | 885 | } |
887 | 886 | ||
888 | /** | 887 | /** |
889 | * gfs2_readlink - Read the value of a symlink | 888 | * gfs2_readlink - Read the value of a symlink |
890 | * @dentry: the symlink | 889 | * @dentry: the symlink |
891 | * @buf: the buffer to read the symlink data into | 890 | * @buf: the buffer to read the symlink data into |
892 | * @size: the size of the buffer | 891 | * @size: the size of the buffer |
893 | * | 892 | * |
894 | * Returns: errno | 893 | * Returns: errno |
895 | */ | 894 | */ |
896 | 895 | ||
897 | static int gfs2_readlink(struct dentry *dentry, char __user *user_buf, | 896 | static int gfs2_readlink(struct dentry *dentry, char __user *user_buf, |
898 | int user_size) | 897 | int user_size) |
899 | { | 898 | { |
900 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); | 899 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); |
901 | char array[GFS2_FAST_NAME_SIZE], *buf = array; | 900 | char array[GFS2_FAST_NAME_SIZE], *buf = array; |
902 | unsigned int len = GFS2_FAST_NAME_SIZE; | 901 | unsigned int len = GFS2_FAST_NAME_SIZE; |
903 | int error; | 902 | int error; |
904 | 903 | ||
905 | error = gfs2_readlinki(ip, &buf, &len); | 904 | error = gfs2_readlinki(ip, &buf, &len); |
906 | if (error) | 905 | if (error) |
907 | return error; | 906 | return error; |
908 | 907 | ||
909 | if (user_size > len - 1) | 908 | if (user_size > len - 1) |
910 | user_size = len - 1; | 909 | user_size = len - 1; |
911 | 910 | ||
912 | if (copy_to_user(user_buf, buf, user_size)) | 911 | if (copy_to_user(user_buf, buf, user_size)) |
913 | error = -EFAULT; | 912 | error = -EFAULT; |
914 | else | 913 | else |
915 | error = user_size; | 914 | error = user_size; |
916 | 915 | ||
917 | if (buf != array) | 916 | if (buf != array) |
918 | kfree(buf); | 917 | kfree(buf); |
919 | 918 | ||
920 | return error; | 919 | return error; |
921 | } | 920 | } |
922 | 921 | ||
923 | /** | 922 | /** |
924 | * gfs2_follow_link - Follow a symbolic link | 923 | * gfs2_follow_link - Follow a symbolic link |
925 | * @dentry: The dentry of the link | 924 | * @dentry: The dentry of the link |
926 | * @nd: Data that we pass to vfs_follow_link() | 925 | * @nd: Data that we pass to vfs_follow_link() |
927 | * | 926 | * |
928 | * This can handle symlinks of any size. It is optimised for symlinks | 927 | * This can handle symlinks of any size. It is optimised for symlinks |
929 | * under GFS2_FAST_NAME_SIZE. | 928 | * under GFS2_FAST_NAME_SIZE. |
930 | * | 929 | * |
931 | * Returns: 0 on success or error code | 930 | * Returns: 0 on success or error code |
932 | */ | 931 | */ |
933 | 932 | ||
934 | static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) | 933 | static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) |
935 | { | 934 | { |
936 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); | 935 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); |
937 | char array[GFS2_FAST_NAME_SIZE], *buf = array; | 936 | char array[GFS2_FAST_NAME_SIZE], *buf = array; |
938 | unsigned int len = GFS2_FAST_NAME_SIZE; | 937 | unsigned int len = GFS2_FAST_NAME_SIZE; |
939 | int error; | 938 | int error; |
940 | 939 | ||
941 | error = gfs2_readlinki(ip, &buf, &len); | 940 | error = gfs2_readlinki(ip, &buf, &len); |
942 | if (!error) { | 941 | if (!error) { |
943 | error = vfs_follow_link(nd, buf); | 942 | error = vfs_follow_link(nd, buf); |
944 | if (buf != array) | 943 | if (buf != array) |
945 | kfree(buf); | 944 | kfree(buf); |
946 | } | 945 | } |
947 | 946 | ||
948 | return ERR_PTR(error); | 947 | return ERR_PTR(error); |
949 | } | 948 | } |
950 | 949 | ||
951 | /** | 950 | /** |
952 | * gfs2_permission - | 951 | * gfs2_permission - |
953 | * @inode: | 952 | * @inode: |
954 | * @mask: | 953 | * @mask: |
955 | * @nd: passed from Linux VFS, ignored by us | 954 | * @nd: passed from Linux VFS, ignored by us |
956 | * | 955 | * |
957 | * This may be called from the VFS directly, or from within GFS2 with the | 956 | * This may be called from the VFS directly, or from within GFS2 with the |
958 | * inode locked, so we look to see if the glock is already locked and only | 957 | * inode locked, so we look to see if the glock is already locked and only |
959 | * lock the glock if its not already been done. | 958 | * lock the glock if its not already been done. |
960 | * | 959 | * |
961 | * Returns: errno | 960 | * Returns: errno |
962 | */ | 961 | */ |
963 | 962 | ||
964 | int gfs2_permission(struct inode *inode, int mask) | 963 | int gfs2_permission(struct inode *inode, int mask) |
965 | { | 964 | { |
966 | struct gfs2_inode *ip = GFS2_I(inode); | 965 | struct gfs2_inode *ip = GFS2_I(inode); |
967 | struct gfs2_holder i_gh; | 966 | struct gfs2_holder i_gh; |
968 | int error; | 967 | int error; |
969 | int unlock = 0; | 968 | int unlock = 0; |
970 | 969 | ||
971 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { | 970 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { |
972 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); | 971 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); |
973 | if (error) | 972 | if (error) |
974 | return error; | 973 | return error; |
975 | unlock = 1; | 974 | unlock = 1; |
976 | } | 975 | } |
977 | 976 | ||
978 | if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode)) | 977 | if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode)) |
979 | error = -EACCES; | 978 | error = -EACCES; |
980 | else | 979 | else |
981 | error = generic_permission(inode, mask, gfs2_check_acl); | 980 | error = generic_permission(inode, mask, gfs2_check_acl); |
982 | if (unlock) | 981 | if (unlock) |
983 | gfs2_glock_dq_uninit(&i_gh); | 982 | gfs2_glock_dq_uninit(&i_gh); |
984 | 983 | ||
985 | return error; | 984 | return error; |
986 | } | 985 | } |
987 | 986 | ||
988 | static int setattr_size(struct inode *inode, struct iattr *attr) | 987 | static int setattr_size(struct inode *inode, struct iattr *attr) |
989 | { | 988 | { |
990 | struct gfs2_inode *ip = GFS2_I(inode); | 989 | struct gfs2_inode *ip = GFS2_I(inode); |
991 | struct gfs2_sbd *sdp = GFS2_SB(inode); | 990 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
992 | int error; | 991 | int error; |
993 | 992 | ||
994 | if (attr->ia_size != ip->i_di.di_size) { | 993 | if (attr->ia_size != ip->i_di.di_size) { |
995 | error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); | 994 | error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); |
996 | if (error) | 995 | if (error) |
997 | return error; | 996 | return error; |
998 | error = vmtruncate(inode, attr->ia_size); | 997 | error = vmtruncate(inode, attr->ia_size); |
999 | gfs2_trans_end(sdp); | 998 | gfs2_trans_end(sdp); |
1000 | if (error) | 999 | if (error) |
1001 | return error; | 1000 | return error; |
1002 | } | 1001 | } |
1003 | 1002 | ||
1004 | error = gfs2_truncatei(ip, attr->ia_size); | 1003 | error = gfs2_truncatei(ip, attr->ia_size); |
1005 | if (error && (inode->i_size != ip->i_di.di_size)) | 1004 | if (error && (inode->i_size != ip->i_di.di_size)) |
1006 | i_size_write(inode, ip->i_di.di_size); | 1005 | i_size_write(inode, ip->i_di.di_size); |
1007 | 1006 | ||
1008 | return error; | 1007 | return error; |
1009 | } | 1008 | } |
1010 | 1009 | ||
1011 | static int setattr_chown(struct inode *inode, struct iattr *attr) | 1010 | static int setattr_chown(struct inode *inode, struct iattr *attr) |
1012 | { | 1011 | { |
1013 | struct gfs2_inode *ip = GFS2_I(inode); | 1012 | struct gfs2_inode *ip = GFS2_I(inode); |
1014 | struct gfs2_sbd *sdp = GFS2_SB(inode); | 1013 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
1015 | struct buffer_head *dibh; | 1014 | struct buffer_head *dibh; |
1016 | u32 ouid, ogid, nuid, ngid; | 1015 | u32 ouid, ogid, nuid, ngid; |
1017 | int error; | 1016 | int error; |
1018 | 1017 | ||
1019 | ouid = inode->i_uid; | 1018 | ouid = inode->i_uid; |
1020 | ogid = inode->i_gid; | 1019 | ogid = inode->i_gid; |
1021 | nuid = attr->ia_uid; | 1020 | nuid = attr->ia_uid; |
1022 | ngid = attr->ia_gid; | 1021 | ngid = attr->ia_gid; |
1023 | 1022 | ||
1024 | if (!(attr->ia_valid & ATTR_UID) || ouid == nuid) | 1023 | if (!(attr->ia_valid & ATTR_UID) || ouid == nuid) |
1025 | ouid = nuid = NO_QUOTA_CHANGE; | 1024 | ouid = nuid = NO_QUOTA_CHANGE; |
1026 | if (!(attr->ia_valid & ATTR_GID) || ogid == ngid) | 1025 | if (!(attr->ia_valid & ATTR_GID) || ogid == ngid) |
1027 | ogid = ngid = NO_QUOTA_CHANGE; | 1026 | ogid = ngid = NO_QUOTA_CHANGE; |
1028 | 1027 | ||
1029 | if (!gfs2_alloc_get(ip)) | 1028 | if (!gfs2_alloc_get(ip)) |
1030 | return -ENOMEM; | 1029 | return -ENOMEM; |
1031 | 1030 | ||
1032 | error = gfs2_quota_lock(ip, nuid, ngid); | 1031 | error = gfs2_quota_lock(ip, nuid, ngid); |
1033 | if (error) | 1032 | if (error) |
1034 | goto out_alloc; | 1033 | goto out_alloc; |
1035 | 1034 | ||
1036 | if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { | 1035 | if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { |
1037 | error = gfs2_quota_check(ip, nuid, ngid); | 1036 | error = gfs2_quota_check(ip, nuid, ngid); |
1038 | if (error) | 1037 | if (error) |
1039 | goto out_gunlock_q; | 1038 | goto out_gunlock_q; |
1040 | } | 1039 | } |
1041 | 1040 | ||
1042 | error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0); | 1041 | error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0); |
1043 | if (error) | 1042 | if (error) |
1044 | goto out_gunlock_q; | 1043 | goto out_gunlock_q; |
1045 | 1044 | ||
1046 | error = gfs2_meta_inode_buffer(ip, &dibh); | 1045 | error = gfs2_meta_inode_buffer(ip, &dibh); |
1047 | if (error) | 1046 | if (error) |
1048 | goto out_end_trans; | 1047 | goto out_end_trans; |
1049 | 1048 | ||
1050 | error = inode_setattr(inode, attr); | 1049 | error = inode_setattr(inode, attr); |
1051 | gfs2_assert_warn(sdp, !error); | 1050 | gfs2_assert_warn(sdp, !error); |
1052 | 1051 | ||
1053 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); | 1052 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
1054 | gfs2_dinode_out(ip, dibh->b_data); | 1053 | gfs2_dinode_out(ip, dibh->b_data); |
1055 | brelse(dibh); | 1054 | brelse(dibh); |
1056 | 1055 | ||
1057 | if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { | 1056 | if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { |
1058 | u64 blocks = gfs2_get_inode_blocks(&ip->i_inode); | 1057 | u64 blocks = gfs2_get_inode_blocks(&ip->i_inode); |
1059 | gfs2_quota_change(ip, -blocks, ouid, ogid); | 1058 | gfs2_quota_change(ip, -blocks, ouid, ogid); |
1060 | gfs2_quota_change(ip, blocks, nuid, ngid); | 1059 | gfs2_quota_change(ip, blocks, nuid, ngid); |
1061 | } | 1060 | } |
1062 | 1061 | ||
1063 | out_end_trans: | 1062 | out_end_trans: |
1064 | gfs2_trans_end(sdp); | 1063 | gfs2_trans_end(sdp); |
1065 | out_gunlock_q: | 1064 | out_gunlock_q: |
1066 | gfs2_quota_unlock(ip); | 1065 | gfs2_quota_unlock(ip); |
1067 | out_alloc: | 1066 | out_alloc: |
1068 | gfs2_alloc_put(ip); | 1067 | gfs2_alloc_put(ip); |
1069 | return error; | 1068 | return error; |
1070 | } | 1069 | } |
1071 | 1070 | ||
1072 | /** | 1071 | /** |
1073 | * gfs2_setattr - Change attributes on an inode | 1072 | * gfs2_setattr - Change attributes on an inode |
1074 | * @dentry: The dentry which is changing | 1073 | * @dentry: The dentry which is changing |
1075 | * @attr: The structure describing the change | 1074 | * @attr: The structure describing the change |
1076 | * | 1075 | * |
1077 | * The VFS layer wants to change one or more of an inodes attributes. Write | 1076 | * The VFS layer wants to change one or more of an inodes attributes. Write |
1078 | * that change out to disk. | 1077 | * that change out to disk. |
1079 | * | 1078 | * |
1080 | * Returns: errno | 1079 | * Returns: errno |
1081 | */ | 1080 | */ |
1082 | 1081 | ||
1083 | static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) | 1082 | static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) |
1084 | { | 1083 | { |
1085 | struct inode *inode = dentry->d_inode; | 1084 | struct inode *inode = dentry->d_inode; |
1086 | struct gfs2_inode *ip = GFS2_I(inode); | 1085 | struct gfs2_inode *ip = GFS2_I(inode); |
1087 | struct gfs2_holder i_gh; | 1086 | struct gfs2_holder i_gh; |
1088 | int error; | 1087 | int error; |
1089 | 1088 | ||
1090 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); | 1089 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); |
1091 | if (error) | 1090 | if (error) |
1092 | return error; | 1091 | return error; |
1093 | 1092 | ||
1094 | error = -EPERM; | 1093 | error = -EPERM; |
1095 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) | 1094 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
1096 | goto out; | 1095 | goto out; |
1097 | 1096 | ||
1098 | error = inode_change_ok(inode, attr); | 1097 | error = inode_change_ok(inode, attr); |
1099 | if (error) | 1098 | if (error) |
1100 | goto out; | 1099 | goto out; |
1101 | 1100 | ||
1102 | if (attr->ia_valid & ATTR_SIZE) | 1101 | if (attr->ia_valid & ATTR_SIZE) |
1103 | error = setattr_size(inode, attr); | 1102 | error = setattr_size(inode, attr); |
1104 | else if (attr->ia_valid & (ATTR_UID | ATTR_GID)) | 1103 | else if (attr->ia_valid & (ATTR_UID | ATTR_GID)) |
1105 | error = setattr_chown(inode, attr); | 1104 | error = setattr_chown(inode, attr); |
1106 | else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode)) | 1105 | else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode)) |
1107 | error = gfs2_acl_chmod(ip, attr); | 1106 | error = gfs2_acl_chmod(ip, attr); |
1108 | else | 1107 | else |
1109 | error = gfs2_setattr_simple(ip, attr); | 1108 | error = gfs2_setattr_simple(ip, attr); |
1110 | 1109 | ||
1111 | out: | 1110 | out: |
1112 | gfs2_glock_dq_uninit(&i_gh); | 1111 | gfs2_glock_dq_uninit(&i_gh); |
1113 | if (!error) | 1112 | if (!error) |
1114 | mark_inode_dirty(inode); | 1113 | mark_inode_dirty(inode); |
1115 | return error; | 1114 | return error; |
1116 | } | 1115 | } |
1117 | 1116 | ||
1118 | /** | 1117 | /** |
1119 | * gfs2_getattr - Read out an inode's attributes | 1118 | * gfs2_getattr - Read out an inode's attributes |
1120 | * @mnt: The vfsmount the inode is being accessed from | 1119 | * @mnt: The vfsmount the inode is being accessed from |
1121 | * @dentry: The dentry to stat | 1120 | * @dentry: The dentry to stat |
1122 | * @stat: The inode's stats | 1121 | * @stat: The inode's stats |
1123 | * | 1122 | * |
1124 | * This may be called from the VFS directly, or from within GFS2 with the | 1123 | * This may be called from the VFS directly, or from within GFS2 with the |
1125 | * inode locked, so we look to see if the glock is already locked and only | 1124 | * inode locked, so we look to see if the glock is already locked and only |
1126 | * lock the glock if its not already been done. Note that its the NFS | 1125 | * lock the glock if its not already been done. Note that its the NFS |
1127 | * readdirplus operation which causes this to be called (from filldir) | 1126 | * readdirplus operation which causes this to be called (from filldir) |
1128 | * with the glock already held. | 1127 | * with the glock already held. |
1129 | * | 1128 | * |
1130 | * Returns: errno | 1129 | * Returns: errno |
1131 | */ | 1130 | */ |
1132 | 1131 | ||
1133 | static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, | 1132 | static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, |
1134 | struct kstat *stat) | 1133 | struct kstat *stat) |
1135 | { | 1134 | { |
1136 | struct inode *inode = dentry->d_inode; | 1135 | struct inode *inode = dentry->d_inode; |
1137 | struct gfs2_inode *ip = GFS2_I(inode); | 1136 | struct gfs2_inode *ip = GFS2_I(inode); |
1138 | struct gfs2_holder gh; | 1137 | struct gfs2_holder gh; |
1139 | int error; | 1138 | int error; |
1140 | int unlock = 0; | 1139 | int unlock = 0; |
1141 | 1140 | ||
1142 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { | 1141 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { |
1143 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); | 1142 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); |
1144 | if (error) | 1143 | if (error) |
1145 | return error; | 1144 | return error; |
1146 | unlock = 1; | 1145 | unlock = 1; |
1147 | } | 1146 | } |
1148 | 1147 | ||
1149 | generic_fillattr(inode, stat); | 1148 | generic_fillattr(inode, stat); |
1150 | if (unlock) | 1149 | if (unlock) |
1151 | gfs2_glock_dq_uninit(&gh); | 1150 | gfs2_glock_dq_uninit(&gh); |
1152 | 1151 | ||
1153 | return 0; | 1152 | return 0; |
1154 | } | 1153 | } |
1155 | 1154 | ||
1156 | static int gfs2_setxattr(struct dentry *dentry, const char *name, | 1155 | static int gfs2_setxattr(struct dentry *dentry, const char *name, |
1157 | const void *data, size_t size, int flags) | 1156 | const void *data, size_t size, int flags) |
1158 | { | 1157 | { |
1159 | struct inode *inode = dentry->d_inode; | 1158 | struct inode *inode = dentry->d_inode; |
1160 | struct gfs2_ea_request er; | 1159 | struct gfs2_ea_request er; |
1161 | 1160 | ||
1162 | memset(&er, 0, sizeof(struct gfs2_ea_request)); | 1161 | memset(&er, 0, sizeof(struct gfs2_ea_request)); |
1163 | er.er_type = gfs2_ea_name2type(name, &er.er_name); | 1162 | er.er_type = gfs2_ea_name2type(name, &er.er_name); |
1164 | if (er.er_type == GFS2_EATYPE_UNUSED) | 1163 | if (er.er_type == GFS2_EATYPE_UNUSED) |
1165 | return -EOPNOTSUPP; | 1164 | return -EOPNOTSUPP; |
1166 | er.er_data = (char *)data; | 1165 | er.er_data = (char *)data; |
1167 | er.er_name_len = strlen(er.er_name); | 1166 | er.er_name_len = strlen(er.er_name); |
1168 | er.er_data_len = size; | 1167 | er.er_data_len = size; |
1169 | er.er_flags = flags; | 1168 | er.er_flags = flags; |
1170 | 1169 | ||
1171 | gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE)); | 1170 | gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE)); |
1172 | 1171 | ||
1173 | return gfs2_ea_set(GFS2_I(inode), &er); | 1172 | return gfs2_ea_set(GFS2_I(inode), &er); |
1174 | } | 1173 | } |
1175 | 1174 | ||
1176 | static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, | 1175 | static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, |
1177 | void *data, size_t size) | 1176 | void *data, size_t size) |
1178 | { | 1177 | { |
1179 | struct gfs2_ea_request er; | 1178 | struct gfs2_ea_request er; |
1180 | 1179 | ||
1181 | memset(&er, 0, sizeof(struct gfs2_ea_request)); | 1180 | memset(&er, 0, sizeof(struct gfs2_ea_request)); |
1182 | er.er_type = gfs2_ea_name2type(name, &er.er_name); | 1181 | er.er_type = gfs2_ea_name2type(name, &er.er_name); |
1183 | if (er.er_type == GFS2_EATYPE_UNUSED) | 1182 | if (er.er_type == GFS2_EATYPE_UNUSED) |
1184 | return -EOPNOTSUPP; | 1183 | return -EOPNOTSUPP; |
1185 | er.er_data = data; | 1184 | er.er_data = data; |
1186 | er.er_name_len = strlen(er.er_name); | 1185 | er.er_name_len = strlen(er.er_name); |
1187 | er.er_data_len = size; | 1186 | er.er_data_len = size; |
1188 | 1187 | ||
1189 | return gfs2_ea_get(GFS2_I(dentry->d_inode), &er); | 1188 | return gfs2_ea_get(GFS2_I(dentry->d_inode), &er); |
1190 | } | 1189 | } |
1191 | 1190 | ||
1192 | static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) | 1191 | static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) |
1193 | { | 1192 | { |
1194 | struct gfs2_ea_request er; | 1193 | struct gfs2_ea_request er; |
1195 | 1194 | ||
1196 | memset(&er, 0, sizeof(struct gfs2_ea_request)); | 1195 | memset(&er, 0, sizeof(struct gfs2_ea_request)); |
1197 | er.er_data = (size) ? buffer : NULL; | 1196 | er.er_data = (size) ? buffer : NULL; |
1198 | er.er_data_len = size; | 1197 | er.er_data_len = size; |
1199 | 1198 | ||
1200 | return gfs2_ea_list(GFS2_I(dentry->d_inode), &er); | 1199 | return gfs2_ea_list(GFS2_I(dentry->d_inode), &er); |
1201 | } | 1200 | } |
1202 | 1201 | ||
1203 | static int gfs2_removexattr(struct dentry *dentry, const char *name) | 1202 | static int gfs2_removexattr(struct dentry *dentry, const char *name) |
1204 | { | 1203 | { |
1205 | struct gfs2_ea_request er; | 1204 | struct gfs2_ea_request er; |
1206 | 1205 | ||
1207 | memset(&er, 0, sizeof(struct gfs2_ea_request)); | 1206 | memset(&er, 0, sizeof(struct gfs2_ea_request)); |
1208 | er.er_type = gfs2_ea_name2type(name, &er.er_name); | 1207 | er.er_type = gfs2_ea_name2type(name, &er.er_name); |
1209 | if (er.er_type == GFS2_EATYPE_UNUSED) | 1208 | if (er.er_type == GFS2_EATYPE_UNUSED) |
1210 | return -EOPNOTSUPP; | 1209 | return -EOPNOTSUPP; |
1211 | er.er_name_len = strlen(er.er_name); | 1210 | er.er_name_len = strlen(er.er_name); |
1212 | 1211 | ||
1213 | return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er); | 1212 | return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er); |
1214 | } | 1213 | } |
1215 | 1214 | ||
1216 | static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | 1215 | static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
1217 | u64 start, u64 len) | 1216 | u64 start, u64 len) |
1218 | { | 1217 | { |
1219 | struct gfs2_inode *ip = GFS2_I(inode); | 1218 | struct gfs2_inode *ip = GFS2_I(inode); |
1220 | struct gfs2_holder gh; | 1219 | struct gfs2_holder gh; |
1221 | int ret; | 1220 | int ret; |
1222 | 1221 | ||
1223 | ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC); | 1222 | ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC); |
1224 | if (ret) | 1223 | if (ret) |
1225 | return ret; | 1224 | return ret; |
1226 | 1225 | ||
1227 | mutex_lock(&inode->i_mutex); | 1226 | mutex_lock(&inode->i_mutex); |
1228 | 1227 | ||
1229 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh); | 1228 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh); |
1230 | if (ret) | 1229 | if (ret) |
1231 | goto out; | 1230 | goto out; |
1232 | 1231 | ||
1233 | if (gfs2_is_stuffed(ip)) { | 1232 | if (gfs2_is_stuffed(ip)) { |
1234 | u64 phys = ip->i_no_addr << inode->i_blkbits; | 1233 | u64 phys = ip->i_no_addr << inode->i_blkbits; |
1235 | u64 size = i_size_read(inode); | 1234 | u64 size = i_size_read(inode); |
1236 | u32 flags = FIEMAP_EXTENT_LAST|FIEMAP_EXTENT_NOT_ALIGNED| | 1235 | u32 flags = FIEMAP_EXTENT_LAST|FIEMAP_EXTENT_NOT_ALIGNED| |
1237 | FIEMAP_EXTENT_DATA_INLINE; | 1236 | FIEMAP_EXTENT_DATA_INLINE; |
1238 | phys += sizeof(struct gfs2_dinode); | 1237 | phys += sizeof(struct gfs2_dinode); |
1239 | phys += start; | 1238 | phys += start; |
1240 | if (start + len > size) | 1239 | if (start + len > size) |
1241 | len = size - start; | 1240 | len = size - start; |
1242 | if (start < size) | 1241 | if (start < size) |
1243 | ret = fiemap_fill_next_extent(fieinfo, start, phys, | 1242 | ret = fiemap_fill_next_extent(fieinfo, start, phys, |
1244 | len, flags); | 1243 | len, flags); |
1245 | if (ret == 1) | 1244 | if (ret == 1) |
1246 | ret = 0; | 1245 | ret = 0; |
1247 | } else { | 1246 | } else { |
1248 | ret = __generic_block_fiemap(inode, fieinfo, start, len, | 1247 | ret = __generic_block_fiemap(inode, fieinfo, start, len, |
1249 | gfs2_block_map); | 1248 | gfs2_block_map); |
1250 | } | 1249 | } |
1251 | 1250 | ||
1252 | gfs2_glock_dq_uninit(&gh); | 1251 | gfs2_glock_dq_uninit(&gh); |
1253 | out: | 1252 | out: |
1254 | mutex_unlock(&inode->i_mutex); | 1253 | mutex_unlock(&inode->i_mutex); |
1255 | return ret; | 1254 | return ret; |
1256 | } | 1255 | } |
1257 | 1256 | ||
1258 | const struct inode_operations gfs2_file_iops = { | 1257 | const struct inode_operations gfs2_file_iops = { |
1259 | .permission = gfs2_permission, | 1258 | .permission = gfs2_permission, |
1260 | .setattr = gfs2_setattr, | 1259 | .setattr = gfs2_setattr, |
1261 | .getattr = gfs2_getattr, | 1260 | .getattr = gfs2_getattr, |
1262 | .setxattr = gfs2_setxattr, | 1261 | .setxattr = gfs2_setxattr, |
1263 | .getxattr = gfs2_getxattr, | 1262 | .getxattr = gfs2_getxattr, |
1264 | .listxattr = gfs2_listxattr, | 1263 | .listxattr = gfs2_listxattr, |
1265 | .removexattr = gfs2_removexattr, | 1264 | .removexattr = gfs2_removexattr, |
1266 | .fiemap = gfs2_fiemap, | 1265 | .fiemap = gfs2_fiemap, |
1267 | }; | 1266 | }; |
1268 | 1267 | ||
1269 | const struct inode_operations gfs2_dir_iops = { | 1268 | const struct inode_operations gfs2_dir_iops = { |
1270 | .create = gfs2_create, | 1269 | .create = gfs2_create, |
1271 | .lookup = gfs2_lookup, | 1270 | .lookup = gfs2_lookup, |
1272 | .link = gfs2_link, | 1271 | .link = gfs2_link, |
1273 | .unlink = gfs2_unlink, | 1272 | .unlink = gfs2_unlink, |
1274 | .symlink = gfs2_symlink, | 1273 | .symlink = gfs2_symlink, |
1275 | .mkdir = gfs2_mkdir, | 1274 | .mkdir = gfs2_mkdir, |
1276 | .rmdir = gfs2_rmdir, | 1275 | .rmdir = gfs2_rmdir, |
1277 | .mknod = gfs2_mknod, | 1276 | .mknod = gfs2_mknod, |
1278 | .rename = gfs2_rename, | 1277 | .rename = gfs2_rename, |
1279 | .permission = gfs2_permission, | 1278 | .permission = gfs2_permission, |
1280 | .setattr = gfs2_setattr, | 1279 | .setattr = gfs2_setattr, |
1281 | .getattr = gfs2_getattr, | 1280 | .getattr = gfs2_getattr, |
1282 | .setxattr = gfs2_setxattr, | 1281 | .setxattr = gfs2_setxattr, |
1283 | .getxattr = gfs2_getxattr, | 1282 | .getxattr = gfs2_getxattr, |
1284 | .listxattr = gfs2_listxattr, | 1283 | .listxattr = gfs2_listxattr, |
1285 | .removexattr = gfs2_removexattr, | 1284 | .removexattr = gfs2_removexattr, |
1286 | .fiemap = gfs2_fiemap, | 1285 | .fiemap = gfs2_fiemap, |
1287 | }; | 1286 | }; |
1288 | 1287 | ||
1289 | const struct inode_operations gfs2_symlink_iops = { | 1288 | const struct inode_operations gfs2_symlink_iops = { |
1290 | .readlink = gfs2_readlink, | 1289 | .readlink = gfs2_readlink, |
1291 | .follow_link = gfs2_follow_link, | 1290 | .follow_link = gfs2_follow_link, |
1292 | .permission = gfs2_permission, | 1291 | .permission = gfs2_permission, |
1293 | .setattr = gfs2_setattr, | 1292 | .setattr = gfs2_setattr, |
1294 | .getattr = gfs2_getattr, | 1293 | .getattr = gfs2_getattr, |
1295 | .setxattr = gfs2_setxattr, | 1294 | .setxattr = gfs2_setxattr, |
1296 | .getxattr = gfs2_getxattr, | 1295 | .getxattr = gfs2_getxattr, |
1297 | .listxattr = gfs2_listxattr, | 1296 | .listxattr = gfs2_listxattr, |
1298 | .removexattr = gfs2_removexattr, | 1297 | .removexattr = gfs2_removexattr, |
1299 | .fiemap = gfs2_fiemap, | 1298 | .fiemap = gfs2_fiemap, |
1300 | }; | 1299 | }; |
1301 | 1300 |
fs/gfs2/ops_inode.h
1 | /* | File was deleted | |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | ||
3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. | ||
4 | * | ||
5 | * This copyrighted material is made available to anyone wishing to use, | ||
6 | * modify, copy, or redistribute it subject to the terms and conditions | ||
7 | * of the GNU General Public License version 2. | ||
8 | */ | ||
9 | |||
10 | #ifndef __OPS_INODE_DOT_H__ | ||
11 | #define __OPS_INODE_DOT_H__ | ||
12 | |||
13 | #include <linux/fs.h> | ||
14 | |||
15 | extern const struct inode_operations gfs2_file_iops; | ||
16 | extern const struct inode_operations gfs2_dir_iops; | ||
17 | extern const struct inode_operations gfs2_symlink_iops; | ||
18 | extern const struct file_operations gfs2_file_fops; | ||
19 | extern const struct file_operations gfs2_dir_fops; | ||
20 | extern const struct file_operations gfs2_file_fops_nolock; | ||
21 | extern const struct file_operations gfs2_dir_fops_nolock; | ||
22 | |||
23 | extern void gfs2_set_inode_flags(struct inode *inode); | ||
24 | |||
25 | #endif /* __OPS_INODE_DOT_H__ */ | ||
26 | 1 | /* |
fs/gfs2/ops_super.c
1 | /* | 1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
3 | * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. | 3 | * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. |
4 | * | 4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | 5 | * This copyrighted material is made available to anyone wishing to use, |
6 | * modify, copy, or redistribute it subject to the terms and conditions | 6 | * modify, copy, or redistribute it subject to the terms and conditions |
7 | * of the GNU General Public License version 2. | 7 | * of the GNU General Public License version 2. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/sched.h> | 10 | #include <linux/sched.h> |
11 | #include <linux/slab.h> | 11 | #include <linux/slab.h> |
12 | #include <linux/spinlock.h> | 12 | #include <linux/spinlock.h> |
13 | #include <linux/completion.h> | 13 | #include <linux/completion.h> |
14 | #include <linux/buffer_head.h> | 14 | #include <linux/buffer_head.h> |
15 | #include <linux/statfs.h> | 15 | #include <linux/statfs.h> |
16 | #include <linux/seq_file.h> | 16 | #include <linux/seq_file.h> |
17 | #include <linux/mount.h> | 17 | #include <linux/mount.h> |
18 | #include <linux/kthread.h> | 18 | #include <linux/kthread.h> |
19 | #include <linux/delay.h> | 19 | #include <linux/delay.h> |
20 | #include <linux/gfs2_ondisk.h> | 20 | #include <linux/gfs2_ondisk.h> |
21 | #include <linux/crc32.h> | 21 | #include <linux/crc32.h> |
22 | #include <linux/lm_interface.h> | 22 | #include <linux/lm_interface.h> |
23 | #include <linux/time.h> | 23 | #include <linux/time.h> |
24 | 24 | ||
25 | #include "gfs2.h" | 25 | #include "gfs2.h" |
26 | #include "incore.h" | 26 | #include "incore.h" |
27 | #include "glock.h" | 27 | #include "glock.h" |
28 | #include "inode.h" | 28 | #include "inode.h" |
29 | #include "log.h" | 29 | #include "log.h" |
30 | #include "mount.h" | 30 | #include "mount.h" |
31 | #include "ops_super.h" | ||
32 | #include "quota.h" | 31 | #include "quota.h" |
33 | #include "recovery.h" | 32 | #include "recovery.h" |
34 | #include "rgrp.h" | 33 | #include "rgrp.h" |
35 | #include "super.h" | 34 | #include "super.h" |
36 | #include "sys.h" | 35 | #include "sys.h" |
37 | #include "util.h" | 36 | #include "util.h" |
38 | #include "trans.h" | 37 | #include "trans.h" |
39 | #include "dir.h" | 38 | #include "dir.h" |
40 | #include "eattr.h" | 39 | #include "eattr.h" |
41 | #include "bmap.h" | 40 | #include "bmap.h" |
42 | #include "meta_io.h" | 41 | #include "meta_io.h" |
43 | 42 | ||
44 | /** | 43 | /** |
45 | * gfs2_write_inode - Make sure the inode is stable on the disk | 44 | * gfs2_write_inode - Make sure the inode is stable on the disk |
46 | * @inode: The inode | 45 | * @inode: The inode |
47 | * @sync: synchronous write flag | 46 | * @sync: synchronous write flag |
48 | * | 47 | * |
49 | * Returns: errno | 48 | * Returns: errno |
50 | */ | 49 | */ |
51 | 50 | ||
52 | static int gfs2_write_inode(struct inode *inode, int sync) | 51 | static int gfs2_write_inode(struct inode *inode, int sync) |
53 | { | 52 | { |
54 | struct gfs2_inode *ip = GFS2_I(inode); | 53 | struct gfs2_inode *ip = GFS2_I(inode); |
55 | struct gfs2_sbd *sdp = GFS2_SB(inode); | 54 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
56 | struct gfs2_holder gh; | 55 | struct gfs2_holder gh; |
57 | struct buffer_head *bh; | 56 | struct buffer_head *bh; |
58 | struct timespec atime; | 57 | struct timespec atime; |
59 | struct gfs2_dinode *di; | 58 | struct gfs2_dinode *di; |
60 | int ret = 0; | 59 | int ret = 0; |
61 | 60 | ||
62 | /* Check this is a "normal" inode, etc */ | 61 | /* Check this is a "normal" inode, etc */ |
63 | if (!test_bit(GIF_USER, &ip->i_flags) || | 62 | if (!test_bit(GIF_USER, &ip->i_flags) || |
64 | (current->flags & PF_MEMALLOC)) | 63 | (current->flags & PF_MEMALLOC)) |
65 | return 0; | 64 | return 0; |
66 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); | 65 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
67 | if (ret) | 66 | if (ret) |
68 | goto do_flush; | 67 | goto do_flush; |
69 | ret = gfs2_trans_begin(sdp, RES_DINODE, 0); | 68 | ret = gfs2_trans_begin(sdp, RES_DINODE, 0); |
70 | if (ret) | 69 | if (ret) |
71 | goto do_unlock; | 70 | goto do_unlock; |
72 | ret = gfs2_meta_inode_buffer(ip, &bh); | 71 | ret = gfs2_meta_inode_buffer(ip, &bh); |
73 | if (ret == 0) { | 72 | if (ret == 0) { |
74 | di = (struct gfs2_dinode *)bh->b_data; | 73 | di = (struct gfs2_dinode *)bh->b_data; |
75 | atime.tv_sec = be64_to_cpu(di->di_atime); | 74 | atime.tv_sec = be64_to_cpu(di->di_atime); |
76 | atime.tv_nsec = be32_to_cpu(di->di_atime_nsec); | 75 | atime.tv_nsec = be32_to_cpu(di->di_atime_nsec); |
77 | if (timespec_compare(&inode->i_atime, &atime) > 0) { | 76 | if (timespec_compare(&inode->i_atime, &atime) > 0) { |
78 | gfs2_trans_add_bh(ip->i_gl, bh, 1); | 77 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
79 | gfs2_dinode_out(ip, bh->b_data); | 78 | gfs2_dinode_out(ip, bh->b_data); |
80 | } | 79 | } |
81 | brelse(bh); | 80 | brelse(bh); |
82 | } | 81 | } |
83 | gfs2_trans_end(sdp); | 82 | gfs2_trans_end(sdp); |
84 | do_unlock: | 83 | do_unlock: |
85 | gfs2_glock_dq_uninit(&gh); | 84 | gfs2_glock_dq_uninit(&gh); |
86 | do_flush: | 85 | do_flush: |
87 | if (sync != 0) | 86 | if (sync != 0) |
88 | gfs2_log_flush(GFS2_SB(inode), ip->i_gl); | 87 | gfs2_log_flush(GFS2_SB(inode), ip->i_gl); |
89 | return ret; | 88 | return ret; |
90 | } | 89 | } |
91 | 90 | ||
92 | /** | 91 | /** |
93 | * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one | 92 | * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one |
94 | * @sdp: the filesystem | 93 | * @sdp: the filesystem |
95 | * | 94 | * |
96 | * Returns: errno | 95 | * Returns: errno |
97 | */ | 96 | */ |
98 | 97 | ||
99 | static int gfs2_make_fs_ro(struct gfs2_sbd *sdp) | 98 | static int gfs2_make_fs_ro(struct gfs2_sbd *sdp) |
100 | { | 99 | { |
101 | struct gfs2_holder t_gh; | 100 | struct gfs2_holder t_gh; |
102 | int error; | 101 | int error; |
103 | 102 | ||
104 | gfs2_quota_sync(sdp); | 103 | gfs2_quota_sync(sdp); |
105 | gfs2_statfs_sync(sdp); | 104 | gfs2_statfs_sync(sdp); |
106 | 105 | ||
107 | error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE, | 106 | error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE, |
108 | &t_gh); | 107 | &t_gh); |
109 | if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) | 108 | if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) |
110 | return error; | 109 | return error; |
111 | 110 | ||
112 | gfs2_meta_syncfs(sdp); | 111 | gfs2_meta_syncfs(sdp); |
113 | gfs2_log_shutdown(sdp); | 112 | gfs2_log_shutdown(sdp); |
114 | 113 | ||
115 | clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); | 114 | clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); |
116 | 115 | ||
117 | if (t_gh.gh_gl) | 116 | if (t_gh.gh_gl) |
118 | gfs2_glock_dq_uninit(&t_gh); | 117 | gfs2_glock_dq_uninit(&t_gh); |
119 | 118 | ||
120 | gfs2_quota_cleanup(sdp); | 119 | gfs2_quota_cleanup(sdp); |
121 | 120 | ||
122 | return error; | 121 | return error; |
123 | } | 122 | } |
124 | 123 | ||
125 | /** | 124 | /** |
126 | * gfs2_put_super - Unmount the filesystem | 125 | * gfs2_put_super - Unmount the filesystem |
127 | * @sb: The VFS superblock | 126 | * @sb: The VFS superblock |
128 | * | 127 | * |
129 | */ | 128 | */ |
130 | 129 | ||
131 | static void gfs2_put_super(struct super_block *sb) | 130 | static void gfs2_put_super(struct super_block *sb) |
132 | { | 131 | { |
133 | struct gfs2_sbd *sdp = sb->s_fs_info; | 132 | struct gfs2_sbd *sdp = sb->s_fs_info; |
134 | int error; | 133 | int error; |
135 | 134 | ||
136 | /* Unfreeze the filesystem, if we need to */ | 135 | /* Unfreeze the filesystem, if we need to */ |
137 | 136 | ||
138 | mutex_lock(&sdp->sd_freeze_lock); | 137 | mutex_lock(&sdp->sd_freeze_lock); |
139 | if (sdp->sd_freeze_count) | 138 | if (sdp->sd_freeze_count) |
140 | gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); | 139 | gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); |
141 | mutex_unlock(&sdp->sd_freeze_lock); | 140 | mutex_unlock(&sdp->sd_freeze_lock); |
142 | 141 | ||
143 | kthread_stop(sdp->sd_quotad_process); | 142 | kthread_stop(sdp->sd_quotad_process); |
144 | kthread_stop(sdp->sd_logd_process); | 143 | kthread_stop(sdp->sd_logd_process); |
145 | kthread_stop(sdp->sd_recoverd_process); | 144 | kthread_stop(sdp->sd_recoverd_process); |
146 | while (sdp->sd_glockd_num--) | 145 | while (sdp->sd_glockd_num--) |
147 | kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); | 146 | kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]); |
148 | 147 | ||
149 | if (!(sb->s_flags & MS_RDONLY)) { | 148 | if (!(sb->s_flags & MS_RDONLY)) { |
150 | error = gfs2_make_fs_ro(sdp); | 149 | error = gfs2_make_fs_ro(sdp); |
151 | if (error) | 150 | if (error) |
152 | gfs2_io_error(sdp); | 151 | gfs2_io_error(sdp); |
153 | } | 152 | } |
154 | /* At this point, we're through modifying the disk */ | 153 | /* At this point, we're through modifying the disk */ |
155 | 154 | ||
156 | /* Release stuff */ | 155 | /* Release stuff */ |
157 | 156 | ||
158 | iput(sdp->sd_jindex); | 157 | iput(sdp->sd_jindex); |
159 | iput(sdp->sd_inum_inode); | 158 | iput(sdp->sd_inum_inode); |
160 | iput(sdp->sd_statfs_inode); | 159 | iput(sdp->sd_statfs_inode); |
161 | iput(sdp->sd_rindex); | 160 | iput(sdp->sd_rindex); |
162 | iput(sdp->sd_quota_inode); | 161 | iput(sdp->sd_quota_inode); |
163 | 162 | ||
164 | gfs2_glock_put(sdp->sd_rename_gl); | 163 | gfs2_glock_put(sdp->sd_rename_gl); |
165 | gfs2_glock_put(sdp->sd_trans_gl); | 164 | gfs2_glock_put(sdp->sd_trans_gl); |
166 | 165 | ||
167 | if (!sdp->sd_args.ar_spectator) { | 166 | if (!sdp->sd_args.ar_spectator) { |
168 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); | 167 | gfs2_glock_dq_uninit(&sdp->sd_journal_gh); |
169 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); | 168 | gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); |
170 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); | 169 | gfs2_glock_dq_uninit(&sdp->sd_ir_gh); |
171 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); | 170 | gfs2_glock_dq_uninit(&sdp->sd_sc_gh); |
172 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); | 171 | gfs2_glock_dq_uninit(&sdp->sd_qc_gh); |
173 | iput(sdp->sd_ir_inode); | 172 | iput(sdp->sd_ir_inode); |
174 | iput(sdp->sd_sc_inode); | 173 | iput(sdp->sd_sc_inode); |
175 | iput(sdp->sd_qc_inode); | 174 | iput(sdp->sd_qc_inode); |
176 | } | 175 | } |
177 | 176 | ||
178 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); | 177 | gfs2_glock_dq_uninit(&sdp->sd_live_gh); |
179 | gfs2_clear_rgrpd(sdp); | 178 | gfs2_clear_rgrpd(sdp); |
180 | gfs2_jindex_free(sdp); | 179 | gfs2_jindex_free(sdp); |
181 | /* Take apart glock structures and buffer lists */ | 180 | /* Take apart glock structures and buffer lists */ |
182 | gfs2_gl_hash_clear(sdp); | 181 | gfs2_gl_hash_clear(sdp); |
183 | /* Unmount the locking protocol */ | 182 | /* Unmount the locking protocol */ |
184 | gfs2_lm_unmount(sdp); | 183 | gfs2_lm_unmount(sdp); |
185 | 184 | ||
186 | /* At this point, we're through participating in the lockspace */ | 185 | /* At this point, we're through participating in the lockspace */ |
187 | gfs2_sys_fs_del(sdp); | 186 | gfs2_sys_fs_del(sdp); |
188 | kfree(sdp); | 187 | kfree(sdp); |
189 | } | 188 | } |
190 | 189 | ||
191 | /** | 190 | /** |
192 | * gfs2_write_super | 191 | * gfs2_write_super |
193 | * @sb: the superblock | 192 | * @sb: the superblock |
194 | * | 193 | * |
195 | */ | 194 | */ |
196 | 195 | ||
197 | static void gfs2_write_super(struct super_block *sb) | 196 | static void gfs2_write_super(struct super_block *sb) |
198 | { | 197 | { |
199 | sb->s_dirt = 0; | 198 | sb->s_dirt = 0; |
200 | } | 199 | } |
201 | 200 | ||
202 | /** | 201 | /** |
203 | * gfs2_sync_fs - sync the filesystem | 202 | * gfs2_sync_fs - sync the filesystem |
204 | * @sb: the superblock | 203 | * @sb: the superblock |
205 | * | 204 | * |
206 | * Flushes the log to disk. | 205 | * Flushes the log to disk. |
207 | */ | 206 | */ |
208 | 207 | ||
209 | static int gfs2_sync_fs(struct super_block *sb, int wait) | 208 | static int gfs2_sync_fs(struct super_block *sb, int wait) |
210 | { | 209 | { |
211 | sb->s_dirt = 0; | 210 | sb->s_dirt = 0; |
212 | if (wait && sb->s_fs_info) | 211 | if (wait && sb->s_fs_info) |
213 | gfs2_log_flush(sb->s_fs_info, NULL); | 212 | gfs2_log_flush(sb->s_fs_info, NULL); |
214 | return 0; | 213 | return 0; |
215 | } | 214 | } |
216 | 215 | ||
217 | /** | 216 | /** |
218 | * gfs2_write_super_lockfs - prevent further writes to the filesystem | 217 | * gfs2_write_super_lockfs - prevent further writes to the filesystem |
219 | * @sb: the VFS structure for the filesystem | 218 | * @sb: the VFS structure for the filesystem |
220 | * | 219 | * |
221 | */ | 220 | */ |
222 | 221 | ||
223 | static void gfs2_write_super_lockfs(struct super_block *sb) | 222 | static void gfs2_write_super_lockfs(struct super_block *sb) |
224 | { | 223 | { |
225 | struct gfs2_sbd *sdp = sb->s_fs_info; | 224 | struct gfs2_sbd *sdp = sb->s_fs_info; |
226 | int error; | 225 | int error; |
227 | 226 | ||
228 | if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) | 227 | if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) |
229 | return; | 228 | return; |
230 | 229 | ||
231 | for (;;) { | 230 | for (;;) { |
232 | error = gfs2_freeze_fs(sdp); | 231 | error = gfs2_freeze_fs(sdp); |
233 | if (!error) | 232 | if (!error) |
234 | break; | 233 | break; |
235 | 234 | ||
236 | switch (error) { | 235 | switch (error) { |
237 | case -EBUSY: | 236 | case -EBUSY: |
238 | fs_err(sdp, "waiting for recovery before freeze\n"); | 237 | fs_err(sdp, "waiting for recovery before freeze\n"); |
239 | break; | 238 | break; |
240 | 239 | ||
241 | default: | 240 | default: |
242 | fs_err(sdp, "error freezing FS: %d\n", error); | 241 | fs_err(sdp, "error freezing FS: %d\n", error); |
243 | break; | 242 | break; |
244 | } | 243 | } |
245 | 244 | ||
246 | fs_err(sdp, "retrying...\n"); | 245 | fs_err(sdp, "retrying...\n"); |
247 | msleep(1000); | 246 | msleep(1000); |
248 | } | 247 | } |
249 | } | 248 | } |
250 | 249 | ||
251 | /** | 250 | /** |
252 | * gfs2_unlockfs - reallow writes to the filesystem | 251 | * gfs2_unlockfs - reallow writes to the filesystem |
253 | * @sb: the VFS structure for the filesystem | 252 | * @sb: the VFS structure for the filesystem |
254 | * | 253 | * |
255 | */ | 254 | */ |
256 | 255 | ||
257 | static void gfs2_unlockfs(struct super_block *sb) | 256 | static void gfs2_unlockfs(struct super_block *sb) |
258 | { | 257 | { |
259 | gfs2_unfreeze_fs(sb->s_fs_info); | 258 | gfs2_unfreeze_fs(sb->s_fs_info); |
260 | } | 259 | } |
261 | 260 | ||
262 | /** | 261 | /** |
263 | * gfs2_statfs - Gather and return stats about the filesystem | 262 | * gfs2_statfs - Gather and return stats about the filesystem |
264 | * @sb: The superblock | 263 | * @sb: The superblock |
265 | * @statfsbuf: The buffer | 264 | * @statfsbuf: The buffer |
266 | * | 265 | * |
267 | * Returns: 0 on success or error code | 266 | * Returns: 0 on success or error code |
268 | */ | 267 | */ |
269 | 268 | ||
270 | static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf) | 269 | static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf) |
271 | { | 270 | { |
272 | struct super_block *sb = dentry->d_inode->i_sb; | 271 | struct super_block *sb = dentry->d_inode->i_sb; |
273 | struct gfs2_sbd *sdp = sb->s_fs_info; | 272 | struct gfs2_sbd *sdp = sb->s_fs_info; |
274 | struct gfs2_statfs_change_host sc; | 273 | struct gfs2_statfs_change_host sc; |
275 | int error; | 274 | int error; |
276 | 275 | ||
277 | if (gfs2_tune_get(sdp, gt_statfs_slow)) | 276 | if (gfs2_tune_get(sdp, gt_statfs_slow)) |
278 | error = gfs2_statfs_slow(sdp, &sc); | 277 | error = gfs2_statfs_slow(sdp, &sc); |
279 | else | 278 | else |
280 | error = gfs2_statfs_i(sdp, &sc); | 279 | error = gfs2_statfs_i(sdp, &sc); |
281 | 280 | ||
282 | if (error) | 281 | if (error) |
283 | return error; | 282 | return error; |
284 | 283 | ||
285 | buf->f_type = GFS2_MAGIC; | 284 | buf->f_type = GFS2_MAGIC; |
286 | buf->f_bsize = sdp->sd_sb.sb_bsize; | 285 | buf->f_bsize = sdp->sd_sb.sb_bsize; |
287 | buf->f_blocks = sc.sc_total; | 286 | buf->f_blocks = sc.sc_total; |
288 | buf->f_bfree = sc.sc_free; | 287 | buf->f_bfree = sc.sc_free; |
289 | buf->f_bavail = sc.sc_free; | 288 | buf->f_bavail = sc.sc_free; |
290 | buf->f_files = sc.sc_dinodes + sc.sc_free; | 289 | buf->f_files = sc.sc_dinodes + sc.sc_free; |
291 | buf->f_ffree = sc.sc_free; | 290 | buf->f_ffree = sc.sc_free; |
292 | buf->f_namelen = GFS2_FNAMESIZE; | 291 | buf->f_namelen = GFS2_FNAMESIZE; |
293 | 292 | ||
294 | return 0; | 293 | return 0; |
295 | } | 294 | } |
296 | 295 | ||
297 | /** | 296 | /** |
298 | * gfs2_remount_fs - called when the FS is remounted | 297 | * gfs2_remount_fs - called when the FS is remounted |
299 | * @sb: the filesystem | 298 | * @sb: the filesystem |
300 | * @flags: the remount flags | 299 | * @flags: the remount flags |
301 | * @data: extra data passed in (not used right now) | 300 | * @data: extra data passed in (not used right now) |
302 | * | 301 | * |
303 | * Returns: errno | 302 | * Returns: errno |
304 | */ | 303 | */ |
305 | 304 | ||
306 | static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) | 305 | static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) |
307 | { | 306 | { |
308 | struct gfs2_sbd *sdp = sb->s_fs_info; | 307 | struct gfs2_sbd *sdp = sb->s_fs_info; |
309 | int error; | 308 | int error; |
310 | 309 | ||
311 | error = gfs2_mount_args(sdp, data, 1); | 310 | error = gfs2_mount_args(sdp, data, 1); |
312 | if (error) | 311 | if (error) |
313 | return error; | 312 | return error; |
314 | 313 | ||
315 | if (sdp->sd_args.ar_spectator) | 314 | if (sdp->sd_args.ar_spectator) |
316 | *flags |= MS_RDONLY; | 315 | *flags |= MS_RDONLY; |
317 | else { | 316 | else { |
318 | if (*flags & MS_RDONLY) { | 317 | if (*flags & MS_RDONLY) { |
319 | if (!(sb->s_flags & MS_RDONLY)) | 318 | if (!(sb->s_flags & MS_RDONLY)) |
320 | error = gfs2_make_fs_ro(sdp); | 319 | error = gfs2_make_fs_ro(sdp); |
321 | } else if (!(*flags & MS_RDONLY) && | 320 | } else if (!(*flags & MS_RDONLY) && |
322 | (sb->s_flags & MS_RDONLY)) { | 321 | (sb->s_flags & MS_RDONLY)) { |
323 | error = gfs2_make_fs_rw(sdp); | 322 | error = gfs2_make_fs_rw(sdp); |
324 | } | 323 | } |
325 | } | 324 | } |
326 | 325 | ||
327 | return error; | 326 | return error; |
328 | } | 327 | } |
329 | 328 | ||
330 | /** | 329 | /** |
331 | * gfs2_drop_inode - Drop an inode (test for remote unlink) | 330 | * gfs2_drop_inode - Drop an inode (test for remote unlink) |
332 | * @inode: The inode to drop | 331 | * @inode: The inode to drop |
333 | * | 332 | * |
334 | * If we've received a callback on an iopen lock then its because a | 333 | * If we've received a callback on an iopen lock then its because a |
335 | * remote node tried to deallocate the inode but failed due to this node | 334 | * remote node tried to deallocate the inode but failed due to this node |
336 | * still having the inode open. Here we mark the link count zero | 335 | * still having the inode open. Here we mark the link count zero |
337 | * since we know that it must have reached zero if the GLF_DEMOTE flag | 336 | * since we know that it must have reached zero if the GLF_DEMOTE flag |
338 | * is set on the iopen glock. If we didn't do a disk read since the | 337 | * is set on the iopen glock. If we didn't do a disk read since the |
339 | * remote node removed the final link then we might otherwise miss | 338 | * remote node removed the final link then we might otherwise miss |
340 | * this event. This check ensures that this node will deallocate the | 339 | * this event. This check ensures that this node will deallocate the |
341 | * inode's blocks, or alternatively pass the baton on to another | 340 | * inode's blocks, or alternatively pass the baton on to another |
342 | * node for later deallocation. | 341 | * node for later deallocation. |
343 | */ | 342 | */ |
344 | 343 | ||
345 | static void gfs2_drop_inode(struct inode *inode) | 344 | static void gfs2_drop_inode(struct inode *inode) |
346 | { | 345 | { |
347 | struct gfs2_inode *ip = GFS2_I(inode); | 346 | struct gfs2_inode *ip = GFS2_I(inode); |
348 | 347 | ||
349 | if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) { | 348 | if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) { |
350 | struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl; | 349 | struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl; |
351 | if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags)) | 350 | if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags)) |
352 | clear_nlink(inode); | 351 | clear_nlink(inode); |
353 | } | 352 | } |
354 | generic_drop_inode(inode); | 353 | generic_drop_inode(inode); |
355 | } | 354 | } |
356 | 355 | ||
357 | /** | 356 | /** |
358 | * gfs2_clear_inode - Deallocate an inode when VFS is done with it | 357 | * gfs2_clear_inode - Deallocate an inode when VFS is done with it |
359 | * @inode: The VFS inode | 358 | * @inode: The VFS inode |
360 | * | 359 | * |
361 | */ | 360 | */ |
362 | 361 | ||
363 | static void gfs2_clear_inode(struct inode *inode) | 362 | static void gfs2_clear_inode(struct inode *inode) |
364 | { | 363 | { |
365 | struct gfs2_inode *ip = GFS2_I(inode); | 364 | struct gfs2_inode *ip = GFS2_I(inode); |
366 | 365 | ||
367 | /* This tells us its a "real" inode and not one which only | 366 | /* This tells us its a "real" inode and not one which only |
368 | * serves to contain an address space (see rgrp.c, meta_io.c) | 367 | * serves to contain an address space (see rgrp.c, meta_io.c) |
369 | * which therefore doesn't have its own glocks. | 368 | * which therefore doesn't have its own glocks. |
370 | */ | 369 | */ |
371 | if (test_bit(GIF_USER, &ip->i_flags)) { | 370 | if (test_bit(GIF_USER, &ip->i_flags)) { |
372 | ip->i_gl->gl_object = NULL; | 371 | ip->i_gl->gl_object = NULL; |
373 | gfs2_glock_schedule_for_reclaim(ip->i_gl); | 372 | gfs2_glock_schedule_for_reclaim(ip->i_gl); |
374 | gfs2_glock_put(ip->i_gl); | 373 | gfs2_glock_put(ip->i_gl); |
375 | ip->i_gl = NULL; | 374 | ip->i_gl = NULL; |
376 | if (ip->i_iopen_gh.gh_gl) { | 375 | if (ip->i_iopen_gh.gh_gl) { |
377 | ip->i_iopen_gh.gh_gl->gl_object = NULL; | 376 | ip->i_iopen_gh.gh_gl->gl_object = NULL; |
378 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); | 377 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); |
379 | } | 378 | } |
380 | } | 379 | } |
381 | } | 380 | } |
382 | 381 | ||
383 | static int is_ancestor(const struct dentry *d1, const struct dentry *d2) | 382 | static int is_ancestor(const struct dentry *d1, const struct dentry *d2) |
384 | { | 383 | { |
385 | do { | 384 | do { |
386 | if (d1 == d2) | 385 | if (d1 == d2) |
387 | return 1; | 386 | return 1; |
388 | d1 = d1->d_parent; | 387 | d1 = d1->d_parent; |
389 | } while (!IS_ROOT(d1)); | 388 | } while (!IS_ROOT(d1)); |
390 | return 0; | 389 | return 0; |
391 | } | 390 | } |
392 | 391 | ||
393 | /** | 392 | /** |
394 | * gfs2_show_options - Show mount options for /proc/mounts | 393 | * gfs2_show_options - Show mount options for /proc/mounts |
395 | * @s: seq_file structure | 394 | * @s: seq_file structure |
396 | * @mnt: vfsmount | 395 | * @mnt: vfsmount |
397 | * | 396 | * |
398 | * Returns: 0 on success or error code | 397 | * Returns: 0 on success or error code |
399 | */ | 398 | */ |
400 | 399 | ||
401 | static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) | 400 | static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt) |
402 | { | 401 | { |
403 | struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info; | 402 | struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info; |
404 | struct gfs2_args *args = &sdp->sd_args; | 403 | struct gfs2_args *args = &sdp->sd_args; |
405 | 404 | ||
406 | if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir)) | 405 | if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir)) |
407 | seq_printf(s, ",meta"); | 406 | seq_printf(s, ",meta"); |
408 | if (args->ar_lockproto[0]) | 407 | if (args->ar_lockproto[0]) |
409 | seq_printf(s, ",lockproto=%s", args->ar_lockproto); | 408 | seq_printf(s, ",lockproto=%s", args->ar_lockproto); |
410 | if (args->ar_locktable[0]) | 409 | if (args->ar_locktable[0]) |
411 | seq_printf(s, ",locktable=%s", args->ar_locktable); | 410 | seq_printf(s, ",locktable=%s", args->ar_locktable); |
412 | if (args->ar_hostdata[0]) | 411 | if (args->ar_hostdata[0]) |
413 | seq_printf(s, ",hostdata=%s", args->ar_hostdata); | 412 | seq_printf(s, ",hostdata=%s", args->ar_hostdata); |
414 | if (args->ar_spectator) | 413 | if (args->ar_spectator) |
415 | seq_printf(s, ",spectator"); | 414 | seq_printf(s, ",spectator"); |
416 | if (args->ar_ignore_local_fs) | 415 | if (args->ar_ignore_local_fs) |
417 | seq_printf(s, ",ignore_local_fs"); | 416 | seq_printf(s, ",ignore_local_fs"); |
418 | if (args->ar_localflocks) | 417 | if (args->ar_localflocks) |
419 | seq_printf(s, ",localflocks"); | 418 | seq_printf(s, ",localflocks"); |
420 | if (args->ar_localcaching) | 419 | if (args->ar_localcaching) |
421 | seq_printf(s, ",localcaching"); | 420 | seq_printf(s, ",localcaching"); |
422 | if (args->ar_debug) | 421 | if (args->ar_debug) |
423 | seq_printf(s, ",debug"); | 422 | seq_printf(s, ",debug"); |
424 | if (args->ar_upgrade) | 423 | if (args->ar_upgrade) |
425 | seq_printf(s, ",upgrade"); | 424 | seq_printf(s, ",upgrade"); |
426 | if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT) | 425 | if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT) |
427 | seq_printf(s, ",num_glockd=%u", args->ar_num_glockd); | 426 | seq_printf(s, ",num_glockd=%u", args->ar_num_glockd); |
428 | if (args->ar_posix_acl) | 427 | if (args->ar_posix_acl) |
429 | seq_printf(s, ",acl"); | 428 | seq_printf(s, ",acl"); |
430 | if (args->ar_quota != GFS2_QUOTA_DEFAULT) { | 429 | if (args->ar_quota != GFS2_QUOTA_DEFAULT) { |
431 | char *state; | 430 | char *state; |
432 | switch (args->ar_quota) { | 431 | switch (args->ar_quota) { |
433 | case GFS2_QUOTA_OFF: | 432 | case GFS2_QUOTA_OFF: |
434 | state = "off"; | 433 | state = "off"; |
435 | break; | 434 | break; |
436 | case GFS2_QUOTA_ACCOUNT: | 435 | case GFS2_QUOTA_ACCOUNT: |
437 | state = "account"; | 436 | state = "account"; |
438 | break; | 437 | break; |
439 | case GFS2_QUOTA_ON: | 438 | case GFS2_QUOTA_ON: |
440 | state = "on"; | 439 | state = "on"; |
441 | break; | 440 | break; |
442 | default: | 441 | default: |
443 | state = "unknown"; | 442 | state = "unknown"; |
444 | break; | 443 | break; |
445 | } | 444 | } |
446 | seq_printf(s, ",quota=%s", state); | 445 | seq_printf(s, ",quota=%s", state); |
447 | } | 446 | } |
448 | if (args->ar_suiddir) | 447 | if (args->ar_suiddir) |
449 | seq_printf(s, ",suiddir"); | 448 | seq_printf(s, ",suiddir"); |
450 | if (args->ar_data != GFS2_DATA_DEFAULT) { | 449 | if (args->ar_data != GFS2_DATA_DEFAULT) { |
451 | char *state; | 450 | char *state; |
452 | switch (args->ar_data) { | 451 | switch (args->ar_data) { |
453 | case GFS2_DATA_WRITEBACK: | 452 | case GFS2_DATA_WRITEBACK: |
454 | state = "writeback"; | 453 | state = "writeback"; |
455 | break; | 454 | break; |
456 | case GFS2_DATA_ORDERED: | 455 | case GFS2_DATA_ORDERED: |
457 | state = "ordered"; | 456 | state = "ordered"; |
458 | break; | 457 | break; |
459 | default: | 458 | default: |
460 | state = "unknown"; | 459 | state = "unknown"; |
461 | break; | 460 | break; |
462 | } | 461 | } |
463 | seq_printf(s, ",data=%s", state); | 462 | seq_printf(s, ",data=%s", state); |
464 | } | 463 | } |
465 | 464 | ||
466 | return 0; | 465 | return 0; |
467 | } | 466 | } |
468 | 467 | ||
469 | /* | 468 | /* |
470 | * We have to (at the moment) hold the inodes main lock to cover | 469 | * We have to (at the moment) hold the inodes main lock to cover |
471 | * the gap between unlocking the shared lock on the iopen lock and | 470 | * the gap between unlocking the shared lock on the iopen lock and |
472 | * taking the exclusive lock. I'd rather do a shared -> exclusive | 471 | * taking the exclusive lock. I'd rather do a shared -> exclusive |
473 | * conversion on the iopen lock, but we can change that later. This | 472 | * conversion on the iopen lock, but we can change that later. This |
474 | * is safe, just less efficient. | 473 | * is safe, just less efficient. |
475 | */ | 474 | */ |
476 | 475 | ||
477 | static void gfs2_delete_inode(struct inode *inode) | 476 | static void gfs2_delete_inode(struct inode *inode) |
478 | { | 477 | { |
479 | struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; | 478 | struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; |
480 | struct gfs2_inode *ip = GFS2_I(inode); | 479 | struct gfs2_inode *ip = GFS2_I(inode); |
481 | struct gfs2_holder gh; | 480 | struct gfs2_holder gh; |
482 | int error; | 481 | int error; |
483 | 482 | ||
484 | if (!test_bit(GIF_USER, &ip->i_flags)) | 483 | if (!test_bit(GIF_USER, &ip->i_flags)) |
485 | goto out; | 484 | goto out; |
486 | 485 | ||
487 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); | 486 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
488 | if (unlikely(error)) { | 487 | if (unlikely(error)) { |
489 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); | 488 | gfs2_glock_dq_uninit(&ip->i_iopen_gh); |
490 | goto out; | 489 | goto out; |
491 | } | 490 | } |
492 | 491 | ||
493 | gfs2_glock_dq_wait(&ip->i_iopen_gh); | 492 | gfs2_glock_dq_wait(&ip->i_iopen_gh); |
494 | gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh); | 493 | gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh); |
495 | error = gfs2_glock_nq(&ip->i_iopen_gh); | 494 | error = gfs2_glock_nq(&ip->i_iopen_gh); |
496 | if (error) | 495 | if (error) |
497 | goto out_uninit; | 496 | goto out_uninit; |
498 | 497 | ||
499 | if (S_ISDIR(inode->i_mode) && | 498 | if (S_ISDIR(inode->i_mode) && |
500 | (ip->i_di.di_flags & GFS2_DIF_EXHASH)) { | 499 | (ip->i_di.di_flags & GFS2_DIF_EXHASH)) { |
501 | error = gfs2_dir_exhash_dealloc(ip); | 500 | error = gfs2_dir_exhash_dealloc(ip); |
502 | if (error) | 501 | if (error) |
503 | goto out_unlock; | 502 | goto out_unlock; |
504 | } | 503 | } |
505 | 504 | ||
506 | if (ip->i_di.di_eattr) { | 505 | if (ip->i_di.di_eattr) { |
507 | error = gfs2_ea_dealloc(ip); | 506 | error = gfs2_ea_dealloc(ip); |
508 | if (error) | 507 | if (error) |
509 | goto out_unlock; | 508 | goto out_unlock; |
510 | } | 509 | } |
511 | 510 | ||
512 | if (!gfs2_is_stuffed(ip)) { | 511 | if (!gfs2_is_stuffed(ip)) { |
513 | error = gfs2_file_dealloc(ip); | 512 | error = gfs2_file_dealloc(ip); |
514 | if (error) | 513 | if (error) |
515 | goto out_unlock; | 514 | goto out_unlock; |
516 | } | 515 | } |
517 | 516 | ||
518 | error = gfs2_dinode_dealloc(ip); | 517 | error = gfs2_dinode_dealloc(ip); |
519 | if (error) | 518 | if (error) |
520 | goto out_unlock; | 519 | goto out_unlock; |
521 | 520 | ||
522 | error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); | 521 | error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks); |
523 | if (error) | 522 | if (error) |
524 | goto out_unlock; | 523 | goto out_unlock; |
525 | /* Needs to be done before glock release & also in a transaction */ | 524 | /* Needs to be done before glock release & also in a transaction */ |
526 | truncate_inode_pages(&inode->i_data, 0); | 525 | truncate_inode_pages(&inode->i_data, 0); |
527 | gfs2_trans_end(sdp); | 526 | gfs2_trans_end(sdp); |
528 | 527 | ||
529 | out_unlock: | 528 | out_unlock: |
530 | gfs2_glock_dq(&ip->i_iopen_gh); | 529 | gfs2_glock_dq(&ip->i_iopen_gh); |
531 | out_uninit: | 530 | out_uninit: |
532 | gfs2_holder_uninit(&ip->i_iopen_gh); | 531 | gfs2_holder_uninit(&ip->i_iopen_gh); |
533 | gfs2_glock_dq_uninit(&gh); | 532 | gfs2_glock_dq_uninit(&gh); |
534 | if (error && error != GLR_TRYFAILED) | 533 | if (error && error != GLR_TRYFAILED) |
535 | fs_warn(sdp, "gfs2_delete_inode: %d\n", error); | 534 | fs_warn(sdp, "gfs2_delete_inode: %d\n", error); |
536 | out: | 535 | out: |
537 | truncate_inode_pages(&inode->i_data, 0); | 536 | truncate_inode_pages(&inode->i_data, 0); |
538 | clear_inode(inode); | 537 | clear_inode(inode); |
539 | } | 538 | } |
540 | 539 | ||
541 | static struct inode *gfs2_alloc_inode(struct super_block *sb) | 540 | static struct inode *gfs2_alloc_inode(struct super_block *sb) |
542 | { | 541 | { |
543 | struct gfs2_inode *ip; | 542 | struct gfs2_inode *ip; |
544 | 543 | ||
545 | ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL); | 544 | ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL); |
546 | if (ip) { | 545 | if (ip) { |
547 | ip->i_flags = 0; | 546 | ip->i_flags = 0; |
548 | ip->i_gl = NULL; | 547 | ip->i_gl = NULL; |
549 | } | 548 | } |
550 | return &ip->i_inode; | 549 | return &ip->i_inode; |
551 | } | 550 | } |
552 | 551 | ||
553 | static void gfs2_destroy_inode(struct inode *inode) | 552 | static void gfs2_destroy_inode(struct inode *inode) |
554 | { | 553 | { |
555 | kmem_cache_free(gfs2_inode_cachep, inode); | 554 | kmem_cache_free(gfs2_inode_cachep, inode); |
556 | } | 555 | } |
557 | 556 | ||
558 | const struct super_operations gfs2_super_ops = { | 557 | const struct super_operations gfs2_super_ops = { |
559 | .alloc_inode = gfs2_alloc_inode, | 558 | .alloc_inode = gfs2_alloc_inode, |
560 | .destroy_inode = gfs2_destroy_inode, | 559 | .destroy_inode = gfs2_destroy_inode, |
561 | .write_inode = gfs2_write_inode, | 560 | .write_inode = gfs2_write_inode, |
562 | .delete_inode = gfs2_delete_inode, | 561 | .delete_inode = gfs2_delete_inode, |
563 | .put_super = gfs2_put_super, | 562 | .put_super = gfs2_put_super, |
564 | .write_super = gfs2_write_super, | 563 | .write_super = gfs2_write_super, |
565 | .sync_fs = gfs2_sync_fs, | 564 | .sync_fs = gfs2_sync_fs, |
566 | .write_super_lockfs = gfs2_write_super_lockfs, | 565 | .write_super_lockfs = gfs2_write_super_lockfs, |
567 | .unlockfs = gfs2_unlockfs, | 566 | .unlockfs = gfs2_unlockfs, |
568 | .statfs = gfs2_statfs, | 567 | .statfs = gfs2_statfs, |
569 | .remount_fs = gfs2_remount_fs, | 568 | .remount_fs = gfs2_remount_fs, |
570 | .clear_inode = gfs2_clear_inode, | 569 | .clear_inode = gfs2_clear_inode, |
571 | .drop_inode = gfs2_drop_inode, | 570 | .drop_inode = gfs2_drop_inode, |
572 | .show_options = gfs2_show_options, | 571 | .show_options = gfs2_show_options, |
573 | }; | 572 | }; |
574 | 573 | ||
575 | 574 |
fs/gfs2/ops_super.h
1 | /* | File was deleted | |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | ||
3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. | ||
4 | * | ||
5 | * This copyrighted material is made available to anyone wishing to use, | ||
6 | * modify, copy, or redistribute it subject to the terms and conditions | ||
7 | * of the GNU General Public License version 2. | ||
8 | */ | ||
9 | |||
10 | #ifndef __OPS_SUPER_DOT_H__ | ||
11 | #define __OPS_SUPER_DOT_H__ | ||
12 | |||
13 | #include <linux/fs.h> | ||
14 | |||
15 | extern const struct super_operations gfs2_super_ops; | ||
16 | |||
17 | #endif /* __OPS_SUPER_DOT_H__ */ | ||
18 | 1 | /* |
fs/gfs2/super.h
1 | /* | 1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
4 | * | 4 | * |
5 | * This copyrighted material is made available to anyone wishing to use, | 5 | * This copyrighted material is made available to anyone wishing to use, |
6 | * modify, copy, or redistribute it subject to the terms and conditions | 6 | * modify, copy, or redistribute it subject to the terms and conditions |
7 | * of the GNU General Public License version 2. | 7 | * of the GNU General Public License version 2. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #ifndef __SUPER_DOT_H__ | 10 | #ifndef __SUPER_DOT_H__ |
11 | #define __SUPER_DOT_H__ | 11 | #define __SUPER_DOT_H__ |
12 | 12 | ||
13 | #include <linux/fs.h> | ||
14 | #include <linux/dcache.h> | ||
13 | #include "incore.h" | 15 | #include "incore.h" |
14 | 16 | ||
15 | void gfs2_lm_unmount(struct gfs2_sbd *sdp); | 17 | void gfs2_lm_unmount(struct gfs2_sbd *sdp); |
16 | 18 | ||
17 | static inline unsigned int gfs2_jindex_size(struct gfs2_sbd *sdp) | 19 | static inline unsigned int gfs2_jindex_size(struct gfs2_sbd *sdp) |
18 | { | 20 | { |
19 | unsigned int x; | 21 | unsigned int x; |
20 | spin_lock(&sdp->sd_jindex_spin); | 22 | spin_lock(&sdp->sd_jindex_spin); |
21 | x = sdp->sd_journals; | 23 | x = sdp->sd_journals; |
22 | spin_unlock(&sdp->sd_jindex_spin); | 24 | spin_unlock(&sdp->sd_jindex_spin); |
23 | return x; | 25 | return x; |
24 | } | 26 | } |
25 | 27 | ||
26 | int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh); | 28 | int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh); |
27 | void gfs2_jindex_free(struct gfs2_sbd *sdp); | 29 | void gfs2_jindex_free(struct gfs2_sbd *sdp); |
28 | 30 | ||
29 | struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid); | 31 | struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid); |
30 | void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid); | 32 | void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid); |
31 | struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp); | 33 | struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp); |
32 | int gfs2_jdesc_check(struct gfs2_jdesc *jd); | 34 | int gfs2_jdesc_check(struct gfs2_jdesc *jd); |
33 | 35 | ||
34 | int gfs2_lookup_in_master_dir(struct gfs2_sbd *sdp, char *filename, | 36 | int gfs2_lookup_in_master_dir(struct gfs2_sbd *sdp, char *filename, |
35 | struct gfs2_inode **ipp); | 37 | struct gfs2_inode **ipp); |
36 | 38 | ||
37 | int gfs2_make_fs_rw(struct gfs2_sbd *sdp); | 39 | int gfs2_make_fs_rw(struct gfs2_sbd *sdp); |
38 | 40 | ||
39 | int gfs2_statfs_init(struct gfs2_sbd *sdp); | 41 | int gfs2_statfs_init(struct gfs2_sbd *sdp); |
40 | void gfs2_statfs_change(struct gfs2_sbd *sdp, | 42 | void gfs2_statfs_change(struct gfs2_sbd *sdp, |
41 | s64 total, s64 free, s64 dinodes); | 43 | s64 total, s64 free, s64 dinodes); |
42 | int gfs2_statfs_sync(struct gfs2_sbd *sdp); | 44 | int gfs2_statfs_sync(struct gfs2_sbd *sdp); |
43 | int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc); | 45 | int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc); |
44 | int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc); | 46 | int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc); |
45 | 47 | ||
46 | int gfs2_freeze_fs(struct gfs2_sbd *sdp); | 48 | int gfs2_freeze_fs(struct gfs2_sbd *sdp); |
47 | void gfs2_unfreeze_fs(struct gfs2_sbd *sdp); | 49 | void gfs2_unfreeze_fs(struct gfs2_sbd *sdp); |
50 | |||
51 | extern struct file_system_type gfs2_fs_type; | ||
52 | extern struct file_system_type gfs2meta_fs_type; | ||
53 | extern const struct export_operations gfs2_export_ops; | ||
54 | extern const struct super_operations gfs2_super_ops; | ||
55 | extern struct dentry_operations gfs2_dops; | ||
48 | 56 | ||
49 | #endif /* __SUPER_DOT_H__ */ | 57 | #endif /* __SUPER_DOT_H__ */ |
50 | 58 | ||
51 | 59 |