Commit | Line | Data |
---|---|---|
b3b94faa DT |
1 | /* |
2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | |
3a8a9a10 | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
b3b94faa DT |
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 | |
e9fc2aa0 | 7 | * of the GNU General Public License version 2. |
b3b94faa DT |
8 | */ |
9 | ||
b3b94faa DT |
10 | #include <linux/slab.h> |
11 | #include <linux/spinlock.h> | |
12 | #include <linux/completion.h> | |
13 | #include <linux/buffer_head.h> | |
14 | #include <linux/namei.h> | |
b3b94faa DT |
15 | #include <linux/mm.h> |
16 | #include <linux/xattr.h> | |
17 | #include <linux/posix_acl.h> | |
5c676f6d | 18 | #include <linux/gfs2_ondisk.h> |
71b86f56 | 19 | #include <linux/crc32.h> |
e9079cce | 20 | #include <linux/fiemap.h> |
3921120e BM |
21 | #include <linux/swap.h> |
22 | #include <linux/falloc.h> | |
b3b94faa DT |
23 | #include <asm/uaccess.h> |
24 | ||
25 | #include "gfs2.h" | |
5c676f6d | 26 | #include "incore.h" |
b3b94faa DT |
27 | #include "acl.h" |
28 | #include "bmap.h" | |
29 | #include "dir.h" | |
307cf6e6 | 30 | #include "xattr.h" |
b3b94faa DT |
31 | #include "glock.h" |
32 | #include "inode.h" | |
33 | #include "meta_io.h" | |
b3b94faa DT |
34 | #include "quota.h" |
35 | #include "rgrp.h" | |
36 | #include "trans.h" | |
5c676f6d | 37 | #include "util.h" |
b2760583 | 38 | #include "super.h" |
b3b94faa DT |
39 | |
40 | /** | |
41 | * gfs2_create - Create a file | |
42 | * @dir: The directory in which to create the file | |
43 | * @dentry: The dentry of the new file | |
44 | * @mode: The mode of the new file | |
45 | * | |
46 | * Returns: errno | |
47 | */ | |
48 | ||
49 | static int gfs2_create(struct inode *dir, struct dentry *dentry, | |
50 | int mode, struct nameidata *nd) | |
51 | { | |
feaa7bba SW |
52 | struct gfs2_inode *dip = GFS2_I(dir); |
53 | struct gfs2_sbd *sdp = GFS2_SB(dir); | |
b3b94faa DT |
54 | struct gfs2_holder ghs[2]; |
55 | struct inode *inode; | |
b3b94faa | 56 | |
b3b94faa DT |
57 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
58 | ||
59 | for (;;) { | |
e7f14f4d | 60 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0); |
7359a19c | 61 | if (!IS_ERR(inode)) { |
b3b94faa | 62 | gfs2_trans_end(sdp); |
6dbd8224 | 63 | if (dip->i_alloc->al_rgd) |
b3b94faa DT |
64 | gfs2_inplace_release(dip); |
65 | gfs2_quota_unlock(dip); | |
66 | gfs2_alloc_put(dip); | |
67 | gfs2_glock_dq_uninit_m(2, ghs); | |
3a8476dd | 68 | mark_inode_dirty(inode); |
b3b94faa | 69 | break; |
7359a19c | 70 | } else if (PTR_ERR(inode) != -EEXIST || |
3516586a | 71 | (nd && nd->flags & LOOKUP_EXCL)) { |
b3b94faa | 72 | gfs2_holder_uninit(ghs); |
7359a19c | 73 | return PTR_ERR(inode); |
b3b94faa DT |
74 | } |
75 | ||
a569c711 | 76 | inode = gfs2_lookupi(dir, &dentry->d_name, 0); |
c752666c SW |
77 | if (inode) { |
78 | if (!IS_ERR(inode)) { | |
c752666c SW |
79 | gfs2_holder_uninit(ghs); |
80 | break; | |
81 | } else { | |
82 | gfs2_holder_uninit(ghs); | |
83 | return PTR_ERR(inode); | |
84 | } | |
b3b94faa DT |
85 | } |
86 | } | |
87 | ||
b3b94faa | 88 | d_instantiate(dentry, inode); |
b3b94faa DT |
89 | |
90 | return 0; | |
91 | } | |
92 | ||
93 | /** | |
94 | * gfs2_lookup - Look up a filename in a directory and return its inode | |
95 | * @dir: The directory inode | |
96 | * @dentry: The dentry of the new inode | |
97 | * @nd: passed from Linux VFS, ignored by us | |
98 | * | |
99 | * Called by the VFS layer. Lock dir and call gfs2_lookupi() | |
100 | * | |
101 | * Returns: errno | |
102 | */ | |
103 | ||
104 | static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry, | |
105 | struct nameidata *nd) | |
106 | { | |
b3b94faa | 107 | struct inode *inode = NULL; |
b3b94faa | 108 | |
a569c711 | 109 | inode = gfs2_lookupi(dir, &dentry->d_name, 0); |
c752666c | 110 | if (inode && IS_ERR(inode)) |
e231c2ee | 111 | return ERR_CAST(inode); |
b3b94faa | 112 | |
9656b2c1 SW |
113 | if (inode) { |
114 | struct gfs2_glock *gl = GFS2_I(inode)->i_gl; | |
115 | struct gfs2_holder gh; | |
116 | int error; | |
117 | error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); | |
118 | if (error) { | |
119 | iput(inode); | |
120 | return ERR_PTR(error); | |
121 | } | |
122 | gfs2_glock_dq_uninit(&gh); | |
b3b94faa | 123 | return d_splice_alias(inode, dentry); |
9656b2c1 | 124 | } |
b3b94faa DT |
125 | d_add(dentry, inode); |
126 | ||
127 | return NULL; | |
128 | } | |
129 | ||
130 | /** | |
131 | * gfs2_link - Link to a file | |
132 | * @old_dentry: The inode to link | |
133 | * @dir: Add link to this directory | |
134 | * @dentry: The name of the link | |
135 | * | |
136 | * Link the inode in "old_dentry" into the directory "dir" with the | |
137 | * name in "dentry". | |
138 | * | |
139 | * Returns: errno | |
140 | */ | |
141 | ||
142 | static int gfs2_link(struct dentry *old_dentry, struct inode *dir, | |
143 | struct dentry *dentry) | |
144 | { | |
feaa7bba SW |
145 | struct gfs2_inode *dip = GFS2_I(dir); |
146 | struct gfs2_sbd *sdp = GFS2_SB(dir); | |
b3b94faa | 147 | struct inode *inode = old_dentry->d_inode; |
feaa7bba | 148 | struct gfs2_inode *ip = GFS2_I(inode); |
b3b94faa DT |
149 | struct gfs2_holder ghs[2]; |
150 | int alloc_required; | |
151 | int error; | |
152 | ||
b60623c2 | 153 | if (S_ISDIR(inode->i_mode)) |
b3b94faa DT |
154 | return -EPERM; |
155 | ||
156 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); | |
157 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); | |
158 | ||
72dbf479 BP |
159 | error = gfs2_glock_nq(ghs); /* parent */ |
160 | if (error) | |
161 | goto out_parent; | |
162 | ||
163 | error = gfs2_glock_nq(ghs + 1); /* child */ | |
b3b94faa | 164 | if (error) |
72dbf479 | 165 | goto out_child; |
b3b94faa | 166 | |
b74c79e9 | 167 | error = gfs2_permission(dir, MAY_WRITE | MAY_EXEC, 0); |
b3b94faa DT |
168 | if (error) |
169 | goto out_gunlock; | |
170 | ||
dbb7cae2 | 171 | error = gfs2_dir_check(dir, &dentry->d_name, NULL); |
b3b94faa DT |
172 | switch (error) { |
173 | case -ENOENT: | |
174 | break; | |
175 | case 0: | |
176 | error = -EEXIST; | |
177 | default: | |
178 | goto out_gunlock; | |
179 | } | |
180 | ||
181 | error = -EINVAL; | |
4f56110a | 182 | if (!dip->i_inode.i_nlink) |
b3b94faa DT |
183 | goto out_gunlock; |
184 | error = -EFBIG; | |
ad6203f2 | 185 | if (dip->i_entries == (u32)-1) |
b3b94faa DT |
186 | goto out_gunlock; |
187 | error = -EPERM; | |
188 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) | |
189 | goto out_gunlock; | |
190 | error = -EINVAL; | |
4f56110a | 191 | if (!ip->i_inode.i_nlink) |
b3b94faa DT |
192 | goto out_gunlock; |
193 | error = -EMLINK; | |
4f56110a | 194 | if (ip->i_inode.i_nlink == (u32)-1) |
b3b94faa DT |
195 | goto out_gunlock; |
196 | ||
c752666c SW |
197 | alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name); |
198 | if (error < 0) | |
b3b94faa | 199 | goto out_gunlock; |
c752666c | 200 | error = 0; |
b3b94faa DT |
201 | |
202 | if (alloc_required) { | |
203 | struct gfs2_alloc *al = gfs2_alloc_get(dip); | |
182fe5ab CG |
204 | if (!al) { |
205 | error = -ENOMEM; | |
206 | goto out_gunlock; | |
207 | } | |
b3b94faa | 208 | |
d82661d9 | 209 | error = gfs2_quota_lock_check(dip); |
b3b94faa DT |
210 | if (error) |
211 | goto out_alloc; | |
212 | ||
b3b94faa DT |
213 | al->al_requested = sdp->sd_max_dirres; |
214 | ||
215 | error = gfs2_inplace_reserve(dip); | |
216 | if (error) | |
217 | goto out_gunlock_q; | |
218 | ||
1b50259b | 219 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
bf97b673 | 220 | gfs2_rg_blocks(al) + |
b3b94faa DT |
221 | 2 * RES_DINODE + RES_STATFS + |
222 | RES_QUOTA, 0); | |
223 | if (error) | |
224 | goto out_ipres; | |
225 | } else { | |
226 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0); | |
227 | if (error) | |
228 | goto out_ipres; | |
229 | } | |
230 | ||
dbb7cae2 | 231 | error = gfs2_dir_add(dir, &dentry->d_name, ip, IF2DT(inode->i_mode)); |
b3b94faa DT |
232 | if (error) |
233 | goto out_end_trans; | |
234 | ||
235 | error = gfs2_change_nlink(ip, +1); | |
236 | ||
feaa7bba | 237 | out_end_trans: |
b3b94faa | 238 | gfs2_trans_end(sdp); |
feaa7bba | 239 | out_ipres: |
b3b94faa DT |
240 | if (alloc_required) |
241 | gfs2_inplace_release(dip); | |
feaa7bba | 242 | out_gunlock_q: |
b3b94faa DT |
243 | if (alloc_required) |
244 | gfs2_quota_unlock(dip); | |
feaa7bba | 245 | out_alloc: |
b3b94faa DT |
246 | if (alloc_required) |
247 | gfs2_alloc_put(dip); | |
feaa7bba | 248 | out_gunlock: |
72dbf479 BP |
249 | gfs2_glock_dq(ghs + 1); |
250 | out_child: | |
251 | gfs2_glock_dq(ghs); | |
252 | out_parent: | |
b3b94faa DT |
253 | gfs2_holder_uninit(ghs); |
254 | gfs2_holder_uninit(ghs + 1); | |
b3b94faa | 255 | if (!error) { |
7de9c6ee | 256 | ihold(inode); |
b3b94faa DT |
257 | d_instantiate(dentry, inode); |
258 | mark_inode_dirty(inode); | |
259 | } | |
b3b94faa DT |
260 | return error; |
261 | } | |
262 | ||
87ec2174 SW |
263 | /* |
264 | * gfs2_unlink_ok - check to see that a inode is still in a directory | |
265 | * @dip: the directory | |
266 | * @name: the name of the file | |
267 | * @ip: the inode | |
268 | * | |
269 | * Assumes that the lock on (at least) @dip is held. | |
270 | * | |
271 | * Returns: 0 if the parent/child relationship is correct, errno if it isn't | |
272 | */ | |
273 | ||
274 | static int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name, | |
275 | const struct gfs2_inode *ip) | |
276 | { | |
277 | int error; | |
278 | ||
279 | if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode)) | |
280 | return -EPERM; | |
281 | ||
282 | if ((dip->i_inode.i_mode & S_ISVTX) && | |
283 | dip->i_inode.i_uid != current_fsuid() && | |
284 | ip->i_inode.i_uid != current_fsuid() && !capable(CAP_FOWNER)) | |
285 | return -EPERM; | |
286 | ||
287 | if (IS_APPEND(&dip->i_inode)) | |
288 | return -EPERM; | |
289 | ||
b74c79e9 | 290 | error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC, 0); |
87ec2174 SW |
291 | if (error) |
292 | return error; | |
293 | ||
294 | error = gfs2_dir_check(&dip->i_inode, name, ip); | |
295 | if (error) | |
296 | return error; | |
297 | ||
298 | return 0; | |
299 | } | |
300 | ||
b3b94faa DT |
301 | /** |
302 | * gfs2_unlink - Unlink a file | |
303 | * @dir: The inode of the directory containing the file to unlink | |
304 | * @dentry: The file itself | |
305 | * | |
306 | * Unlink a file. Call gfs2_unlinki() | |
307 | * | |
308 | * Returns: errno | |
309 | */ | |
310 | ||
311 | static int gfs2_unlink(struct inode *dir, struct dentry *dentry) | |
312 | { | |
feaa7bba SW |
313 | struct gfs2_inode *dip = GFS2_I(dir); |
314 | struct gfs2_sbd *sdp = GFS2_SB(dir); | |
315 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); | |
ddee7608 RC |
316 | struct gfs2_holder ghs[3]; |
317 | struct gfs2_rgrpd *rgd; | |
318 | struct gfs2_holder ri_gh; | |
b3b94faa DT |
319 | int error; |
320 | ||
ddee7608 RC |
321 | error = gfs2_rindex_hold(sdp, &ri_gh); |
322 | if (error) | |
323 | return error; | |
324 | ||
b3b94faa | 325 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
ddee7608 | 326 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); |
b3b94faa | 327 | |
dbb7cae2 | 328 | rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); |
ddee7608 RC |
329 | gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2); |
330 | ||
331 | ||
8497a46e | 332 | error = gfs2_glock_nq(ghs); /* parent */ |
b3b94faa | 333 | if (error) |
8497a46e SW |
334 | goto out_parent; |
335 | ||
336 | error = gfs2_glock_nq(ghs + 1); /* child */ | |
337 | if (error) | |
338 | goto out_child; | |
339 | ||
340 | error = gfs2_glock_nq(ghs + 2); /* rgrp */ | |
341 | if (error) | |
342 | goto out_rgrp; | |
b3b94faa DT |
343 | |
344 | error = gfs2_unlink_ok(dip, &dentry->d_name, ip); | |
345 | if (error) | |
72dbf479 | 346 | goto out_gunlock; |
b3b94faa | 347 | |
feaa7bba | 348 | error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0); |
b3b94faa | 349 | if (error) |
cd012075 | 350 | goto out_gunlock; |
b3b94faa | 351 | |
feaa7bba SW |
352 | error = gfs2_dir_del(dip, &dentry->d_name); |
353 | if (error) | |
354 | goto out_end_trans; | |
b3b94faa | 355 | |
feaa7bba | 356 | error = gfs2_change_nlink(ip, -1); |
b3b94faa | 357 | |
feaa7bba SW |
358 | out_end_trans: |
359 | gfs2_trans_end(sdp); | |
72dbf479 | 360 | out_gunlock: |
8497a46e SW |
361 | gfs2_glock_dq(ghs + 2); |
362 | out_rgrp: | |
ddee7608 | 363 | gfs2_holder_uninit(ghs + 2); |
8497a46e SW |
364 | gfs2_glock_dq(ghs + 1); |
365 | out_child: | |
366 | gfs2_holder_uninit(ghs + 1); | |
367 | gfs2_glock_dq(ghs); | |
368 | out_parent: | |
369 | gfs2_holder_uninit(ghs); | |
ddee7608 | 370 | gfs2_glock_dq_uninit(&ri_gh); |
b3b94faa DT |
371 | return error; |
372 | } | |
373 | ||
374 | /** | |
375 | * gfs2_symlink - Create a symlink | |
376 | * @dir: The directory to create the symlink in | |
377 | * @dentry: The dentry to put the symlink in | |
378 | * @symname: The thing which the link points to | |
379 | * | |
380 | * Returns: errno | |
381 | */ | |
382 | ||
383 | static int gfs2_symlink(struct inode *dir, struct dentry *dentry, | |
384 | const char *symname) | |
385 | { | |
feaa7bba SW |
386 | struct gfs2_inode *dip = GFS2_I(dir), *ip; |
387 | struct gfs2_sbd *sdp = GFS2_SB(dir); | |
b3b94faa DT |
388 | struct gfs2_holder ghs[2]; |
389 | struct inode *inode; | |
390 | struct buffer_head *dibh; | |
391 | int size; | |
392 | int error; | |
393 | ||
b3b94faa DT |
394 | /* Must be stuffed with a null terminator for gfs2_follow_link() */ |
395 | size = strlen(symname); | |
396 | if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1) | |
397 | return -ENAMETOOLONG; | |
398 | ||
399 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); | |
400 | ||
e7f14f4d | 401 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0); |
7359a19c | 402 | if (IS_ERR(inode)) { |
b3b94faa | 403 | gfs2_holder_uninit(ghs); |
7359a19c | 404 | return PTR_ERR(inode); |
b3b94faa DT |
405 | } |
406 | ||
5c676f6d | 407 | ip = ghs[1].gh_gl->gl_object; |
b3b94faa | 408 | |
5cf32524 | 409 | i_size_write(inode, size); |
b3b94faa DT |
410 | |
411 | error = gfs2_meta_inode_buffer(ip, &dibh); | |
412 | ||
413 | if (!gfs2_assert_withdraw(sdp, !error)) { | |
539e5d6b | 414 | gfs2_dinode_out(ip, dibh->b_data); |
b3b94faa DT |
415 | memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname, |
416 | size); | |
417 | brelse(dibh); | |
418 | } | |
419 | ||
420 | gfs2_trans_end(sdp); | |
6dbd8224 | 421 | if (dip->i_alloc->al_rgd) |
b3b94faa DT |
422 | gfs2_inplace_release(dip); |
423 | gfs2_quota_unlock(dip); | |
424 | gfs2_alloc_put(dip); | |
425 | ||
426 | gfs2_glock_dq_uninit_m(2, ghs); | |
427 | ||
b3b94faa DT |
428 | d_instantiate(dentry, inode); |
429 | mark_inode_dirty(inode); | |
430 | ||
431 | return 0; | |
432 | } | |
433 | ||
434 | /** | |
435 | * gfs2_mkdir - Make a directory | |
436 | * @dir: The parent directory of the new one | |
437 | * @dentry: The dentry of the new directory | |
438 | * @mode: The mode of the new directory | |
439 | * | |
440 | * Returns: errno | |
441 | */ | |
442 | ||
443 | static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |
444 | { | |
feaa7bba SW |
445 | struct gfs2_inode *dip = GFS2_I(dir), *ip; |
446 | struct gfs2_sbd *sdp = GFS2_SB(dir); | |
b3b94faa DT |
447 | struct gfs2_holder ghs[2]; |
448 | struct inode *inode; | |
449 | struct buffer_head *dibh; | |
450 | int error; | |
451 | ||
b3b94faa DT |
452 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); |
453 | ||
e7f14f4d | 454 | inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0); |
7359a19c | 455 | if (IS_ERR(inode)) { |
b3b94faa | 456 | gfs2_holder_uninit(ghs); |
7359a19c | 457 | return PTR_ERR(inode); |
b3b94faa DT |
458 | } |
459 | ||
5c676f6d | 460 | ip = ghs[1].gh_gl->gl_object; |
b3b94faa | 461 | |
4f56110a | 462 | ip->i_inode.i_nlink = 2; |
a2e0f799 | 463 | i_size_write(inode, sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)); |
383f01fb | 464 | ip->i_diskflags |= GFS2_DIF_JDATA; |
ad6203f2 | 465 | ip->i_entries = 2; |
b3b94faa DT |
466 | |
467 | error = gfs2_meta_inode_buffer(ip, &dibh); | |
468 | ||
469 | if (!gfs2_assert_withdraw(sdp, !error)) { | |
470 | struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data; | |
c752666c | 471 | struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1); |
b3b94faa | 472 | |
c752666c | 473 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
8d123585 | 474 | gfs2_qstr2dirent(&gfs2_qdot, GFS2_DIRENT_SIZE(gfs2_qdot.len), dent); |
b3b94faa | 475 | dent->de_inum = di->di_num; /* already GFS2 endian */ |
7ecdb70a | 476 | dent->de_type = cpu_to_be16(DT_DIR); |
b3b94faa DT |
477 | di->di_entries = cpu_to_be32(1); |
478 | ||
c752666c | 479 | dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1)); |
8d123585 | 480 | gfs2_qstr2dirent(&gfs2_qdotdot, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent); |
b3b94faa | 481 | |
dbb7cae2 | 482 | gfs2_inum_out(dip, dent); |
7ecdb70a | 483 | dent->de_type = cpu_to_be16(DT_DIR); |
b3b94faa | 484 | |
539e5d6b | 485 | gfs2_dinode_out(ip, di); |
b3b94faa DT |
486 | |
487 | brelse(dibh); | |
488 | } | |
489 | ||
490 | error = gfs2_change_nlink(dip, +1); | |
491 | gfs2_assert_withdraw(sdp, !error); /* dip already pinned */ | |
492 | ||
493 | gfs2_trans_end(sdp); | |
6dbd8224 | 494 | if (dip->i_alloc->al_rgd) |
b3b94faa DT |
495 | gfs2_inplace_release(dip); |
496 | gfs2_quota_unlock(dip); | |
497 | gfs2_alloc_put(dip); | |
498 | ||
499 | gfs2_glock_dq_uninit_m(2, ghs); | |
500 | ||
b3b94faa DT |
501 | d_instantiate(dentry, inode); |
502 | mark_inode_dirty(inode); | |
503 | ||
504 | return 0; | |
505 | } | |
506 | ||
2286dbfa SW |
507 | /** |
508 | * gfs2_rmdiri - Remove a directory | |
509 | * @dip: The parent directory of the directory to be removed | |
510 | * @name: The name of the directory to be removed | |
511 | * @ip: The GFS2 inode of the directory to be removed | |
512 | * | |
513 | * Assumes Glocks on dip and ip are held | |
514 | * | |
515 | * Returns: errno | |
516 | */ | |
517 | ||
518 | static int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name, | |
519 | struct gfs2_inode *ip) | |
520 | { | |
2286dbfa SW |
521 | int error; |
522 | ||
523 | if (ip->i_entries != 2) { | |
524 | if (gfs2_consist_inode(ip)) | |
525 | gfs2_dinode_print(ip); | |
526 | return -EIO; | |
527 | } | |
528 | ||
529 | error = gfs2_dir_del(dip, name); | |
530 | if (error) | |
531 | return error; | |
532 | ||
533 | error = gfs2_change_nlink(dip, -1); | |
534 | if (error) | |
535 | return error; | |
536 | ||
8d123585 | 537 | error = gfs2_dir_del(ip, &gfs2_qdot); |
2286dbfa SW |
538 | if (error) |
539 | return error; | |
540 | ||
8d123585 | 541 | error = gfs2_dir_del(ip, &gfs2_qdotdot); |
2286dbfa SW |
542 | if (error) |
543 | return error; | |
544 | ||
545 | /* It looks odd, but it really should be done twice */ | |
546 | error = gfs2_change_nlink(ip, -1); | |
547 | if (error) | |
548 | return error; | |
549 | ||
550 | error = gfs2_change_nlink(ip, -1); | |
551 | if (error) | |
552 | return error; | |
553 | ||
554 | return error; | |
555 | } | |
556 | ||
b3b94faa DT |
557 | /** |
558 | * gfs2_rmdir - Remove a directory | |
559 | * @dir: The parent directory of the directory to be removed | |
560 | * @dentry: The dentry of the directory to remove | |
561 | * | |
562 | * Remove a directory. Call gfs2_rmdiri() | |
563 | * | |
564 | * Returns: errno | |
565 | */ | |
566 | ||
567 | static int gfs2_rmdir(struct inode *dir, struct dentry *dentry) | |
568 | { | |
feaa7bba SW |
569 | struct gfs2_inode *dip = GFS2_I(dir); |
570 | struct gfs2_sbd *sdp = GFS2_SB(dir); | |
571 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); | |
ddee7608 RC |
572 | struct gfs2_holder ghs[3]; |
573 | struct gfs2_rgrpd *rgd; | |
574 | struct gfs2_holder ri_gh; | |
b3b94faa DT |
575 | int error; |
576 | ||
ddee7608 RC |
577 | error = gfs2_rindex_hold(sdp, &ri_gh); |
578 | if (error) | |
579 | return error; | |
b3b94faa DT |
580 | gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
581 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); | |
582 | ||
dbb7cae2 | 583 | rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); |
ddee7608 RC |
584 | gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2); |
585 | ||
72dbf479 BP |
586 | error = gfs2_glock_nq(ghs); /* parent */ |
587 | if (error) | |
588 | goto out_parent; | |
589 | ||
590 | error = gfs2_glock_nq(ghs + 1); /* child */ | |
b3b94faa | 591 | if (error) |
72dbf479 BP |
592 | goto out_child; |
593 | ||
594 | error = gfs2_glock_nq(ghs + 2); /* rgrp */ | |
595 | if (error) | |
596 | goto out_rgrp; | |
b3b94faa DT |
597 | |
598 | error = gfs2_unlink_ok(dip, &dentry->d_name, ip); | |
599 | if (error) | |
600 | goto out_gunlock; | |
601 | ||
ad6203f2 | 602 | if (ip->i_entries < 2) { |
b3b94faa | 603 | if (gfs2_consist_inode(ip)) |
4cc14f0b | 604 | gfs2_dinode_print(ip); |
b3b94faa DT |
605 | error = -EIO; |
606 | goto out_gunlock; | |
607 | } | |
ad6203f2 | 608 | if (ip->i_entries > 2) { |
b3b94faa DT |
609 | error = -ENOTEMPTY; |
610 | goto out_gunlock; | |
611 | } | |
612 | ||
feaa7bba | 613 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0); |
b3b94faa DT |
614 | if (error) |
615 | goto out_gunlock; | |
616 | ||
feaa7bba | 617 | error = gfs2_rmdiri(dip, &dentry->d_name, ip); |
b3b94faa DT |
618 | |
619 | gfs2_trans_end(sdp); | |
620 | ||
a91ea69f | 621 | out_gunlock: |
72dbf479 BP |
622 | gfs2_glock_dq(ghs + 2); |
623 | out_rgrp: | |
ddee7608 | 624 | gfs2_holder_uninit(ghs + 2); |
72dbf479 BP |
625 | gfs2_glock_dq(ghs + 1); |
626 | out_child: | |
627 | gfs2_holder_uninit(ghs + 1); | |
628 | gfs2_glock_dq(ghs); | |
629 | out_parent: | |
630 | gfs2_holder_uninit(ghs); | |
ddee7608 | 631 | gfs2_glock_dq_uninit(&ri_gh); |
b3b94faa DT |
632 | return error; |
633 | } | |
634 | ||
635 | /** | |
636 | * gfs2_mknod - Make a special file | |
637 | * @dir: The directory in which the special file will reside | |
638 | * @dentry: The dentry of the special file | |
639 | * @mode: The mode of the special file | |
640 | * @rdev: The device specification of the special file | |
641 | * | |
642 | */ | |
643 | ||
644 | static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, | |
645 | dev_t dev) | |
646 | { | |
e7f14f4d | 647 | struct gfs2_inode *dip = GFS2_I(dir); |
feaa7bba | 648 | struct gfs2_sbd *sdp = GFS2_SB(dir); |
b3b94faa DT |
649 | struct gfs2_holder ghs[2]; |
650 | struct inode *inode; | |
b3b94faa DT |
651 | |
652 | gfs2_holder_init(dip->i_gl, 0, 0, ghs); | |
653 | ||
e7f14f4d | 654 | inode = gfs2_createi(ghs, &dentry->d_name, mode, dev); |
7359a19c | 655 | if (IS_ERR(inode)) { |
b3b94faa | 656 | gfs2_holder_uninit(ghs); |
7359a19c | 657 | return PTR_ERR(inode); |
b3b94faa DT |
658 | } |
659 | ||
b3b94faa | 660 | gfs2_trans_end(sdp); |
6dbd8224 | 661 | if (dip->i_alloc->al_rgd) |
b3b94faa DT |
662 | gfs2_inplace_release(dip); |
663 | gfs2_quota_unlock(dip); | |
664 | gfs2_alloc_put(dip); | |
665 | ||
666 | gfs2_glock_dq_uninit_m(2, ghs); | |
667 | ||
b3b94faa DT |
668 | d_instantiate(dentry, inode); |
669 | mark_inode_dirty(inode); | |
670 | ||
671 | return 0; | |
672 | } | |
673 | ||
0188d6c5 SW |
674 | /* |
675 | * gfs2_ok_to_move - check if it's ok to move a directory to another directory | |
676 | * @this: move this | |
677 | * @to: to here | |
678 | * | |
679 | * Follow @to back to the root and make sure we don't encounter @this | |
680 | * Assumes we already hold the rename lock. | |
681 | * | |
682 | * Returns: errno | |
683 | */ | |
684 | ||
685 | static int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to) | |
686 | { | |
687 | struct inode *dir = &to->i_inode; | |
688 | struct super_block *sb = dir->i_sb; | |
689 | struct inode *tmp; | |
0188d6c5 SW |
690 | int error = 0; |
691 | ||
0188d6c5 SW |
692 | igrab(dir); |
693 | ||
694 | for (;;) { | |
695 | if (dir == &this->i_inode) { | |
696 | error = -EINVAL; | |
697 | break; | |
698 | } | |
699 | if (dir == sb->s_root->d_inode) { | |
700 | error = 0; | |
701 | break; | |
702 | } | |
703 | ||
8d123585 | 704 | tmp = gfs2_lookupi(dir, &gfs2_qdotdot, 1); |
0188d6c5 SW |
705 | if (IS_ERR(tmp)) { |
706 | error = PTR_ERR(tmp); | |
707 | break; | |
708 | } | |
709 | ||
710 | iput(dir); | |
711 | dir = tmp; | |
712 | } | |
713 | ||
714 | iput(dir); | |
715 | ||
716 | return error; | |
717 | } | |
718 | ||
b3b94faa DT |
719 | /** |
720 | * gfs2_rename - Rename a file | |
721 | * @odir: Parent directory of old file name | |
722 | * @odentry: The old dentry of the file | |
723 | * @ndir: Parent directory of new file name | |
724 | * @ndentry: The new dentry of the file | |
725 | * | |
726 | * Returns: errno | |
727 | */ | |
728 | ||
729 | static int gfs2_rename(struct inode *odir, struct dentry *odentry, | |
730 | struct inode *ndir, struct dentry *ndentry) | |
731 | { | |
feaa7bba SW |
732 | struct gfs2_inode *odip = GFS2_I(odir); |
733 | struct gfs2_inode *ndip = GFS2_I(ndir); | |
734 | struct gfs2_inode *ip = GFS2_I(odentry->d_inode); | |
b3b94faa | 735 | struct gfs2_inode *nip = NULL; |
feaa7bba | 736 | struct gfs2_sbd *sdp = GFS2_SB(odir); |
46290341 | 737 | struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, }, ri_gh; |
ddee7608 | 738 | struct gfs2_rgrpd *nrgd; |
b3b94faa DT |
739 | unsigned int num_gh; |
740 | int dir_rename = 0; | |
24b977b5 | 741 | int alloc_required = 0; |
b3b94faa DT |
742 | unsigned int x; |
743 | int error; | |
744 | ||
b3b94faa | 745 | if (ndentry->d_inode) { |
feaa7bba | 746 | nip = GFS2_I(ndentry->d_inode); |
b3b94faa DT |
747 | if (ip == nip) |
748 | return 0; | |
749 | } | |
750 | ||
46290341 BP |
751 | error = gfs2_rindex_hold(sdp, &ri_gh); |
752 | if (error) | |
753 | return error; | |
b3b94faa | 754 | |
0188d6c5 SW |
755 | if (odip != ndip) { |
756 | error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, | |
757 | 0, &r_gh); | |
b3b94faa DT |
758 | if (error) |
759 | goto out; | |
760 | ||
0188d6c5 SW |
761 | if (S_ISDIR(ip->i_inode.i_mode)) { |
762 | dir_rename = 1; | |
763 | /* don't move a dirctory into it's subdir */ | |
764 | error = gfs2_ok_to_move(ip, ndip); | |
765 | if (error) | |
766 | goto out_gunlock_r; | |
767 | } | |
b3b94faa DT |
768 | } |
769 | ||
d9d1ca30 | 770 | num_gh = 1; |
b3b94faa | 771 | gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); |
d9d1ca30 SW |
772 | if (odip != ndip) { |
773 | gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); | |
774 | num_gh++; | |
775 | } | |
776 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); | |
777 | num_gh++; | |
b3b94faa | 778 | |
d9d1ca30 SW |
779 | if (nip) { |
780 | gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh); | |
781 | num_gh++; | |
ddee7608 RC |
782 | /* grab the resource lock for unlink flag twiddling |
783 | * this is the case of the target file already existing | |
784 | * so we unlink before doing the rename | |
785 | */ | |
dbb7cae2 | 786 | nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr); |
ddee7608 RC |
787 | if (nrgd) |
788 | gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++); | |
d9d1ca30 | 789 | } |
b3b94faa | 790 | |
72dbf479 BP |
791 | for (x = 0; x < num_gh; x++) { |
792 | error = gfs2_glock_nq(ghs + x); | |
793 | if (error) | |
794 | goto out_gunlock; | |
795 | } | |
b3b94faa DT |
796 | |
797 | /* Check out the old directory */ | |
798 | ||
799 | error = gfs2_unlink_ok(odip, &odentry->d_name, ip); | |
800 | if (error) | |
801 | goto out_gunlock; | |
802 | ||
803 | /* Check out the new directory */ | |
804 | ||
805 | if (nip) { | |
806 | error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip); | |
807 | if (error) | |
808 | goto out_gunlock; | |
809 | ||
b60623c2 | 810 | if (S_ISDIR(nip->i_inode.i_mode)) { |
ad6203f2 | 811 | if (nip->i_entries < 2) { |
b3b94faa | 812 | if (gfs2_consist_inode(nip)) |
4cc14f0b | 813 | gfs2_dinode_print(nip); |
b3b94faa DT |
814 | error = -EIO; |
815 | goto out_gunlock; | |
816 | } | |
ad6203f2 | 817 | if (nip->i_entries > 2) { |
b3b94faa DT |
818 | error = -ENOTEMPTY; |
819 | goto out_gunlock; | |
820 | } | |
821 | } | |
822 | } else { | |
b74c79e9 | 823 | error = gfs2_permission(ndir, MAY_WRITE | MAY_EXEC, 0); |
b3b94faa DT |
824 | if (error) |
825 | goto out_gunlock; | |
826 | ||
dbb7cae2 | 827 | error = gfs2_dir_check(ndir, &ndentry->d_name, NULL); |
b3b94faa DT |
828 | switch (error) { |
829 | case -ENOENT: | |
830 | error = 0; | |
831 | break; | |
832 | case 0: | |
833 | error = -EEXIST; | |
834 | default: | |
835 | goto out_gunlock; | |
836 | }; | |
837 | ||
838 | if (odip != ndip) { | |
4f56110a | 839 | if (!ndip->i_inode.i_nlink) { |
b3b94faa DT |
840 | error = -EINVAL; |
841 | goto out_gunlock; | |
842 | } | |
ad6203f2 | 843 | if (ndip->i_entries == (u32)-1) { |
b3b94faa DT |
844 | error = -EFBIG; |
845 | goto out_gunlock; | |
846 | } | |
b60623c2 | 847 | if (S_ISDIR(ip->i_inode.i_mode) && |
4f56110a | 848 | ndip->i_inode.i_nlink == (u32)-1) { |
b3b94faa DT |
849 | error = -EMLINK; |
850 | goto out_gunlock; | |
851 | } | |
852 | } | |
853 | } | |
854 | ||
855 | /* Check out the dir to be renamed */ | |
856 | ||
857 | if (dir_rename) { | |
b74c79e9 | 858 | error = gfs2_permission(odentry->d_inode, MAY_WRITE, 0); |
b3b94faa DT |
859 | if (error) |
860 | goto out_gunlock; | |
861 | } | |
862 | ||
24b977b5 SW |
863 | if (nip == NULL) |
864 | alloc_required = gfs2_diradd_alloc_required(ndir, &ndentry->d_name); | |
865 | error = alloc_required; | |
c752666c | 866 | if (error < 0) |
b3b94faa | 867 | goto out_gunlock; |
c752666c | 868 | error = 0; |
b3b94faa DT |
869 | |
870 | if (alloc_required) { | |
871 | struct gfs2_alloc *al = gfs2_alloc_get(ndip); | |
182fe5ab CG |
872 | if (!al) { |
873 | error = -ENOMEM; | |
874 | goto out_gunlock; | |
875 | } | |
b3b94faa | 876 | |
d82661d9 | 877 | error = gfs2_quota_lock_check(ndip); |
b3b94faa DT |
878 | if (error) |
879 | goto out_alloc; | |
880 | ||
b3b94faa DT |
881 | al->al_requested = sdp->sd_max_dirres; |
882 | ||
46290341 | 883 | error = gfs2_inplace_reserve_ri(ndip); |
b3b94faa DT |
884 | if (error) |
885 | goto out_gunlock_q; | |
886 | ||
fe1bdedc | 887 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
bf97b673 | 888 | gfs2_rg_blocks(al) + |
b3b94faa | 889 | 4 * RES_DINODE + 4 * RES_LEAF + |
87d21e07 | 890 | RES_STATFS + RES_QUOTA + 4, 0); |
b3b94faa DT |
891 | if (error) |
892 | goto out_ipreserv; | |
893 | } else { | |
894 | error = gfs2_trans_begin(sdp, 4 * RES_DINODE + | |
87d21e07 | 895 | 5 * RES_LEAF + 4, 0); |
b3b94faa DT |
896 | if (error) |
897 | goto out_gunlock; | |
898 | } | |
899 | ||
900 | /* Remove the target file, if it exists */ | |
901 | ||
902 | if (nip) { | |
b60623c2 | 903 | if (S_ISDIR(nip->i_inode.i_mode)) |
feaa7bba SW |
904 | error = gfs2_rmdiri(ndip, &ndentry->d_name, nip); |
905 | else { | |
906 | error = gfs2_dir_del(ndip, &ndentry->d_name); | |
907 | if (error) | |
908 | goto out_end_trans; | |
87d21e07 | 909 | error = gfs2_change_nlink(nip, -1); |
feaa7bba | 910 | } |
b3b94faa DT |
911 | if (error) |
912 | goto out_end_trans; | |
913 | } | |
914 | ||
915 | if (dir_rename) { | |
b3b94faa DT |
916 | error = gfs2_change_nlink(ndip, +1); |
917 | if (error) | |
918 | goto out_end_trans; | |
919 | error = gfs2_change_nlink(odip, -1); | |
920 | if (error) | |
921 | goto out_end_trans; | |
922 | ||
8d123585 | 923 | error = gfs2_dir_mvino(ip, &gfs2_qdotdot, ndip, DT_DIR); |
b3b94faa DT |
924 | if (error) |
925 | goto out_end_trans; | |
926 | } else { | |
927 | struct buffer_head *dibh; | |
928 | error = gfs2_meta_inode_buffer(ip, &dibh); | |
929 | if (error) | |
930 | goto out_end_trans; | |
4bd91ba1 | 931 | ip->i_inode.i_ctime = CURRENT_TIME; |
d4e9c4c3 | 932 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
539e5d6b | 933 | gfs2_dinode_out(ip, dibh->b_data); |
b3b94faa DT |
934 | brelse(dibh); |
935 | } | |
936 | ||
937 | error = gfs2_dir_del(odip, &odentry->d_name); | |
938 | if (error) | |
939 | goto out_end_trans; | |
940 | ||
dbb7cae2 | 941 | error = gfs2_dir_add(ndir, &ndentry->d_name, ip, IF2DT(ip->i_inode.i_mode)); |
b3b94faa DT |
942 | if (error) |
943 | goto out_end_trans; | |
944 | ||
feaa7bba | 945 | out_end_trans: |
b3b94faa | 946 | gfs2_trans_end(sdp); |
feaa7bba | 947 | out_ipreserv: |
b3b94faa DT |
948 | if (alloc_required) |
949 | gfs2_inplace_release(ndip); | |
feaa7bba | 950 | out_gunlock_q: |
b3b94faa DT |
951 | if (alloc_required) |
952 | gfs2_quota_unlock(ndip); | |
feaa7bba | 953 | out_alloc: |
b3b94faa DT |
954 | if (alloc_required) |
955 | gfs2_alloc_put(ndip); | |
feaa7bba | 956 | out_gunlock: |
72dbf479 BP |
957 | while (x--) { |
958 | gfs2_glock_dq(ghs + x); | |
b3b94faa | 959 | gfs2_holder_uninit(ghs + x); |
72dbf479 | 960 | } |
feaa7bba | 961 | out_gunlock_r: |
0188d6c5 | 962 | if (r_gh.gh_gl) |
b3b94faa | 963 | gfs2_glock_dq_uninit(&r_gh); |
feaa7bba | 964 | out: |
46290341 | 965 | gfs2_glock_dq_uninit(&ri_gh); |
b3b94faa DT |
966 | return error; |
967 | } | |
968 | ||
536baf02 | 969 | /** |
c177c2ac AV |
970 | * gfs2_follow_link - Follow a symbolic link |
971 | * @dentry: The dentry of the link | |
972 | * @nd: Data that we pass to vfs_follow_link() | |
536baf02 | 973 | * |
c177c2ac | 974 | * This can handle symlinks of any size. |
536baf02 | 975 | * |
c177c2ac | 976 | * Returns: 0 on success or error code |
536baf02 SW |
977 | */ |
978 | ||
c177c2ac | 979 | static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) |
536baf02 | 980 | { |
c177c2ac | 981 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); |
536baf02 SW |
982 | struct gfs2_holder i_gh; |
983 | struct buffer_head *dibh; | |
a2e0f799 | 984 | unsigned int x, size; |
c177c2ac | 985 | char *buf; |
536baf02 SW |
986 | int error; |
987 | ||
988 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); | |
989 | error = gfs2_glock_nq(&i_gh); | |
990 | if (error) { | |
991 | gfs2_holder_uninit(&i_gh); | |
c177c2ac AV |
992 | nd_set_link(nd, ERR_PTR(error)); |
993 | return NULL; | |
536baf02 SW |
994 | } |
995 | ||
a2e0f799 SW |
996 | size = (unsigned int)i_size_read(&ip->i_inode); |
997 | if (size == 0) { | |
536baf02 | 998 | gfs2_consist_inode(ip); |
c177c2ac | 999 | buf = ERR_PTR(-EIO); |
536baf02 SW |
1000 | goto out; |
1001 | } | |
1002 | ||
1003 | error = gfs2_meta_inode_buffer(ip, &dibh); | |
c177c2ac AV |
1004 | if (error) { |
1005 | buf = ERR_PTR(error); | |
536baf02 | 1006 | goto out; |
536baf02 SW |
1007 | } |
1008 | ||
a2e0f799 | 1009 | x = size + 1; |
c177c2ac AV |
1010 | buf = kmalloc(x, GFP_NOFS); |
1011 | if (!buf) | |
1012 | buf = ERR_PTR(-ENOMEM); | |
1013 | else | |
1014 | memcpy(buf, dibh->b_data + sizeof(struct gfs2_dinode), x); | |
536baf02 SW |
1015 | brelse(dibh); |
1016 | out: | |
1017 | gfs2_glock_dq_uninit(&i_gh); | |
c177c2ac AV |
1018 | nd_set_link(nd, buf); |
1019 | return NULL; | |
b3b94faa DT |
1020 | } |
1021 | ||
c177c2ac | 1022 | static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p) |
b3b94faa | 1023 | { |
c177c2ac AV |
1024 | char *s = nd_get_link(nd); |
1025 | if (!IS_ERR(s)) | |
1026 | kfree(s); | |
b3b94faa DT |
1027 | } |
1028 | ||
1029 | /** | |
1030 | * gfs2_permission - | |
1031 | * @inode: | |
1032 | * @mask: | |
1033 | * @nd: passed from Linux VFS, ignored by us | |
1034 | * | |
300c7d75 SW |
1035 | * This may be called from the VFS directly, or from within GFS2 with the |
1036 | * inode locked, so we look to see if the glock is already locked and only | |
1037 | * lock the glock if its not already been done. | |
1038 | * | |
b3b94faa DT |
1039 | * Returns: errno |
1040 | */ | |
1041 | ||
b74c79e9 | 1042 | int gfs2_permission(struct inode *inode, int mask, unsigned int flags) |
b3b94faa | 1043 | { |
b74c79e9 | 1044 | struct gfs2_inode *ip; |
b3b94faa DT |
1045 | struct gfs2_holder i_gh; |
1046 | int error; | |
300c7d75 | 1047 | int unlock = 0; |
b3b94faa | 1048 | |
b74c79e9 NP |
1049 | if (flags & IPERM_FLAG_RCU) |
1050 | return -ECHILD; | |
1051 | ||
1052 | ip = GFS2_I(inode); | |
7afd88d9 | 1053 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { |
300c7d75 SW |
1054 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); |
1055 | if (error) | |
1056 | return error; | |
1057 | unlock = 1; | |
1058 | } | |
b3b94faa | 1059 | |
f58ba889 MS |
1060 | if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode)) |
1061 | error = -EACCES; | |
1062 | else | |
b74c79e9 | 1063 | error = generic_permission(inode, mask, flags, gfs2_check_acl); |
300c7d75 | 1064 | if (unlock) |
b3b94faa | 1065 | gfs2_glock_dq_uninit(&i_gh); |
b3b94faa DT |
1066 | |
1067 | return error; | |
1068 | } | |
1069 | ||
b3b94faa DT |
1070 | static int setattr_chown(struct inode *inode, struct iattr *attr) |
1071 | { | |
feaa7bba SW |
1072 | struct gfs2_inode *ip = GFS2_I(inode); |
1073 | struct gfs2_sbd *sdp = GFS2_SB(inode); | |
cd915493 | 1074 | u32 ouid, ogid, nuid, ngid; |
b3b94faa DT |
1075 | int error; |
1076 | ||
2933f925 SW |
1077 | ouid = inode->i_uid; |
1078 | ogid = inode->i_gid; | |
b3b94faa DT |
1079 | nuid = attr->ia_uid; |
1080 | ngid = attr->ia_gid; | |
1081 | ||
1082 | if (!(attr->ia_valid & ATTR_UID) || ouid == nuid) | |
1083 | ouid = nuid = NO_QUOTA_CHANGE; | |
1084 | if (!(attr->ia_valid & ATTR_GID) || ogid == ngid) | |
1085 | ogid = ngid = NO_QUOTA_CHANGE; | |
1086 | ||
182fe5ab CG |
1087 | if (!gfs2_alloc_get(ip)) |
1088 | return -ENOMEM; | |
b3b94faa DT |
1089 | |
1090 | error = gfs2_quota_lock(ip, nuid, ngid); | |
1091 | if (error) | |
1092 | goto out_alloc; | |
1093 | ||
1094 | if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { | |
1095 | error = gfs2_quota_check(ip, nuid, ngid); | |
1096 | if (error) | |
1097 | goto out_gunlock_q; | |
1098 | } | |
1099 | ||
1100 | error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0); | |
1101 | if (error) | |
1102 | goto out_gunlock_q; | |
1103 | ||
2ae51ed7 | 1104 | error = gfs2_setattr_simple(ip, attr); |
b3b94faa DT |
1105 | if (error) |
1106 | goto out_end_trans; | |
1107 | ||
b3b94faa | 1108 | if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { |
77658aad SW |
1109 | u64 blocks = gfs2_get_inode_blocks(&ip->i_inode); |
1110 | gfs2_quota_change(ip, -blocks, ouid, ogid); | |
1111 | gfs2_quota_change(ip, blocks, nuid, ngid); | |
b3b94faa DT |
1112 | } |
1113 | ||
a91ea69f | 1114 | out_end_trans: |
b3b94faa | 1115 | gfs2_trans_end(sdp); |
a91ea69f | 1116 | out_gunlock_q: |
b3b94faa | 1117 | gfs2_quota_unlock(ip); |
a91ea69f | 1118 | out_alloc: |
b3b94faa | 1119 | gfs2_alloc_put(ip); |
b3b94faa DT |
1120 | return error; |
1121 | } | |
1122 | ||
1123 | /** | |
1124 | * gfs2_setattr - Change attributes on an inode | |
1125 | * @dentry: The dentry which is changing | |
1126 | * @attr: The structure describing the change | |
1127 | * | |
1128 | * The VFS layer wants to change one or more of an inodes attributes. Write | |
1129 | * that change out to disk. | |
1130 | * | |
1131 | * Returns: errno | |
1132 | */ | |
1133 | ||
1134 | static int gfs2_setattr(struct dentry *dentry, struct iattr *attr) | |
1135 | { | |
1136 | struct inode *inode = dentry->d_inode; | |
feaa7bba | 1137 | struct gfs2_inode *ip = GFS2_I(inode); |
b3b94faa DT |
1138 | struct gfs2_holder i_gh; |
1139 | int error; | |
1140 | ||
b3b94faa DT |
1141 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); |
1142 | if (error) | |
1143 | return error; | |
1144 | ||
1145 | error = -EPERM; | |
1146 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) | |
1147 | goto out; | |
1148 | ||
1149 | error = inode_change_ok(inode, attr); | |
1150 | if (error) | |
1151 | goto out; | |
1152 | ||
1153 | if (attr->ia_valid & ATTR_SIZE) | |
ff8f33c8 | 1154 | error = gfs2_setattr_size(inode, attr->ia_size); |
b3b94faa DT |
1155 | else if (attr->ia_valid & (ATTR_UID | ATTR_GID)) |
1156 | error = setattr_chown(inode, attr); | |
1157 | else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode)) | |
1158 | error = gfs2_acl_chmod(ip, attr); | |
1159 | else | |
1160 | error = gfs2_setattr_simple(ip, attr); | |
1161 | ||
a91ea69f | 1162 | out: |
b3b94faa | 1163 | gfs2_glock_dq_uninit(&i_gh); |
b3b94faa DT |
1164 | if (!error) |
1165 | mark_inode_dirty(inode); | |
b3b94faa DT |
1166 | return error; |
1167 | } | |
1168 | ||
1169 | /** | |
1170 | * gfs2_getattr - Read out an inode's attributes | |
26c1a574 | 1171 | * @mnt: The vfsmount the inode is being accessed from |
b3b94faa DT |
1172 | * @dentry: The dentry to stat |
1173 | * @stat: The inode's stats | |
1174 | * | |
dcf3dd85 SW |
1175 | * This may be called from the VFS directly, or from within GFS2 with the |
1176 | * inode locked, so we look to see if the glock is already locked and only | |
1177 | * lock the glock if its not already been done. Note that its the NFS | |
1178 | * readdirplus operation which causes this to be called (from filldir) | |
1179 | * with the glock already held. | |
1180 | * | |
b3b94faa DT |
1181 | * Returns: errno |
1182 | */ | |
1183 | ||
1184 | static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, | |
1185 | struct kstat *stat) | |
1186 | { | |
1187 | struct inode *inode = dentry->d_inode; | |
feaa7bba | 1188 | struct gfs2_inode *ip = GFS2_I(inode); |
b3b94faa DT |
1189 | struct gfs2_holder gh; |
1190 | int error; | |
dcf3dd85 | 1191 | int unlock = 0; |
b3b94faa | 1192 | |
7afd88d9 | 1193 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { |
dcf3dd85 SW |
1194 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); |
1195 | if (error) | |
1196 | return error; | |
1197 | unlock = 1; | |
b3b94faa DT |
1198 | } |
1199 | ||
dcf3dd85 | 1200 | generic_fillattr(inode, stat); |
d7c103d0 | 1201 | if (unlock) |
dcf3dd85 SW |
1202 | gfs2_glock_dq_uninit(&gh); |
1203 | ||
1204 | return 0; | |
b3b94faa DT |
1205 | } |
1206 | ||
1207 | static int gfs2_setxattr(struct dentry *dentry, const char *name, | |
1208 | const void *data, size_t size, int flags) | |
1209 | { | |
feaa7bba | 1210 | struct inode *inode = dentry->d_inode; |
40b78a32 SW |
1211 | struct gfs2_inode *ip = GFS2_I(inode); |
1212 | struct gfs2_holder gh; | |
1213 | int ret; | |
b3b94faa | 1214 | |
40b78a32 SW |
1215 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
1216 | ret = gfs2_glock_nq(&gh); | |
1217 | if (ret == 0) { | |
1218 | ret = generic_setxattr(dentry, name, data, size, flags); | |
1219 | gfs2_glock_dq(&gh); | |
1220 | } | |
1221 | gfs2_holder_uninit(&gh); | |
1222 | return ret; | |
b3b94faa DT |
1223 | } |
1224 | ||
1225 | static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name, | |
1226 | void *data, size_t size) | |
1227 | { | |
40b78a32 SW |
1228 | struct inode *inode = dentry->d_inode; |
1229 | struct gfs2_inode *ip = GFS2_I(inode); | |
1230 | struct gfs2_holder gh; | |
1231 | int ret; | |
b3b94faa | 1232 | |
40b78a32 SW |
1233 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); |
1234 | ret = gfs2_glock_nq(&gh); | |
1235 | if (ret == 0) { | |
1236 | ret = generic_getxattr(dentry, name, data, size); | |
1237 | gfs2_glock_dq(&gh); | |
1238 | } | |
1239 | gfs2_holder_uninit(&gh); | |
1240 | return ret; | |
b3b94faa DT |
1241 | } |
1242 | ||
1243 | static int gfs2_removexattr(struct dentry *dentry, const char *name) | |
1244 | { | |
40b78a32 SW |
1245 | struct inode *inode = dentry->d_inode; |
1246 | struct gfs2_inode *ip = GFS2_I(inode); | |
1247 | struct gfs2_holder gh; | |
1248 | int ret; | |
b3b94faa | 1249 | |
40b78a32 SW |
1250 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
1251 | ret = gfs2_glock_nq(&gh); | |
1252 | if (ret == 0) { | |
1253 | ret = generic_removexattr(dentry, name); | |
1254 | gfs2_glock_dq(&gh); | |
1255 | } | |
1256 | gfs2_holder_uninit(&gh); | |
1257 | return ret; | |
b3b94faa DT |
1258 | } |
1259 | ||
3921120e BM |
1260 | static void empty_write_end(struct page *page, unsigned from, |
1261 | unsigned to) | |
1262 | { | |
1263 | struct gfs2_inode *ip = GFS2_I(page->mapping->host); | |
1264 | ||
1265 | page_zero_new_buffers(page, from, to); | |
1266 | flush_dcache_page(page); | |
1267 | mark_page_accessed(page); | |
1268 | ||
1269 | if (!gfs2_is_writeback(ip)) | |
1270 | gfs2_page_add_databufs(ip, page, from, to); | |
1271 | ||
1272 | block_commit_write(page, from, to); | |
1273 | } | |
1274 | ||
1275 | ||
1276 | static int write_empty_blocks(struct page *page, unsigned from, unsigned to) | |
1277 | { | |
1278 | unsigned start, end, next; | |
1279 | struct buffer_head *bh, *head; | |
1280 | int error; | |
1281 | ||
1282 | if (!page_has_buffers(page)) { | |
ebdec241 | 1283 | error = __block_write_begin(page, from, to - from, gfs2_block_map); |
3921120e BM |
1284 | if (unlikely(error)) |
1285 | return error; | |
1286 | ||
1287 | empty_write_end(page, from, to); | |
1288 | return 0; | |
1289 | } | |
1290 | ||
1291 | bh = head = page_buffers(page); | |
1292 | next = end = 0; | |
1293 | while (next < from) { | |
1294 | next += bh->b_size; | |
1295 | bh = bh->b_this_page; | |
1296 | } | |
1297 | start = next; | |
1298 | do { | |
1299 | next += bh->b_size; | |
1300 | if (buffer_mapped(bh)) { | |
1301 | if (end) { | |
ebdec241 | 1302 | error = __block_write_begin(page, start, end - start, |
3921120e BM |
1303 | gfs2_block_map); |
1304 | if (unlikely(error)) | |
1305 | return error; | |
1306 | empty_write_end(page, start, end); | |
1307 | end = 0; | |
1308 | } | |
1309 | start = next; | |
1310 | } | |
1311 | else | |
1312 | end = next; | |
1313 | bh = bh->b_this_page; | |
1314 | } while (next < to); | |
1315 | ||
1316 | if (end) { | |
ebdec241 | 1317 | error = __block_write_begin(page, start, end - start, gfs2_block_map); |
3921120e BM |
1318 | if (unlikely(error)) |
1319 | return error; | |
1320 | empty_write_end(page, start, end); | |
1321 | } | |
1322 | ||
1323 | return 0; | |
1324 | } | |
1325 | ||
1326 | static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len, | |
1327 | int mode) | |
1328 | { | |
1329 | struct gfs2_inode *ip = GFS2_I(inode); | |
1330 | struct buffer_head *dibh; | |
1331 | int error; | |
1332 | u64 start = offset >> PAGE_CACHE_SHIFT; | |
1333 | unsigned int start_offset = offset & ~PAGE_CACHE_MASK; | |
1334 | u64 end = (offset + len - 1) >> PAGE_CACHE_SHIFT; | |
1335 | pgoff_t curr; | |
1336 | struct page *page; | |
1337 | unsigned int end_offset = (offset + len) & ~PAGE_CACHE_MASK; | |
1338 | unsigned int from, to; | |
1339 | ||
1340 | if (!end_offset) | |
1341 | end_offset = PAGE_CACHE_SIZE; | |
1342 | ||
1343 | error = gfs2_meta_inode_buffer(ip, &dibh); | |
1344 | if (unlikely(error)) | |
1345 | goto out; | |
1346 | ||
1347 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); | |
1348 | ||
1349 | if (gfs2_is_stuffed(ip)) { | |
1350 | error = gfs2_unstuff_dinode(ip, NULL); | |
1351 | if (unlikely(error)) | |
1352 | goto out; | |
1353 | } | |
1354 | ||
1355 | curr = start; | |
1356 | offset = start << PAGE_CACHE_SHIFT; | |
1357 | from = start_offset; | |
1358 | to = PAGE_CACHE_SIZE; | |
1359 | while (curr <= end) { | |
1360 | page = grab_cache_page_write_begin(inode->i_mapping, curr, | |
1361 | AOP_FLAG_NOFS); | |
1362 | if (unlikely(!page)) { | |
1363 | error = -ENOMEM; | |
1364 | goto out; | |
1365 | } | |
1366 | ||
1367 | if (curr == end) | |
1368 | to = end_offset; | |
1369 | error = write_empty_blocks(page, from, to); | |
1370 | if (!error && offset + to > inode->i_size && | |
1371 | !(mode & FALLOC_FL_KEEP_SIZE)) { | |
1372 | i_size_write(inode, offset + to); | |
1373 | } | |
1374 | unlock_page(page); | |
1375 | page_cache_release(page); | |
1376 | if (error) | |
1377 | goto out; | |
1378 | curr++; | |
1379 | offset += PAGE_CACHE_SIZE; | |
1380 | from = 0; | |
1381 | } | |
1382 | ||
1383 | gfs2_dinode_out(ip, dibh->b_data); | |
1384 | mark_inode_dirty(inode); | |
1385 | ||
1386 | brelse(dibh); | |
1387 | ||
1388 | out: | |
1389 | return error; | |
1390 | } | |
1391 | ||
1392 | static void calc_max_reserv(struct gfs2_inode *ip, loff_t max, loff_t *len, | |
1393 | unsigned int *data_blocks, unsigned int *ind_blocks) | |
1394 | { | |
1395 | const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | |
1396 | unsigned int max_blocks = ip->i_alloc->al_rgd->rd_free_clone; | |
1397 | unsigned int tmp, max_data = max_blocks - 3 * (sdp->sd_max_height - 1); | |
1398 | ||
1399 | for (tmp = max_data; tmp > sdp->sd_diptrs;) { | |
1400 | tmp = DIV_ROUND_UP(tmp, sdp->sd_inptrs); | |
1401 | max_data -= tmp; | |
1402 | } | |
1403 | /* This calculation isn't the exact reverse of gfs2_write_calc_reserve, | |
fe08d5a8 | 1404 | so it might end up with fewer data blocks */ |
3921120e BM |
1405 | if (max_data <= *data_blocks) |
1406 | return; | |
1407 | *data_blocks = max_data; | |
1408 | *ind_blocks = max_blocks - max_data; | |
1409 | *len = ((loff_t)max_data - 3) << sdp->sd_sb.sb_bsize_shift; | |
1410 | if (*len > max) { | |
1411 | *len = max; | |
1412 | gfs2_write_calc_reserv(ip, max, data_blocks, ind_blocks); | |
1413 | } | |
1414 | } | |
1415 | ||
1416 | static long gfs2_fallocate(struct inode *inode, int mode, loff_t offset, | |
1417 | loff_t len) | |
1418 | { | |
1419 | struct gfs2_sbd *sdp = GFS2_SB(inode); | |
1420 | struct gfs2_inode *ip = GFS2_I(inode); | |
1421 | unsigned int data_blocks = 0, ind_blocks = 0, rblocks; | |
1422 | loff_t bytes, max_bytes; | |
1423 | struct gfs2_alloc *al; | |
1424 | int error; | |
1425 | loff_t next = (offset + len - 1) >> sdp->sd_sb.sb_bsize_shift; | |
1426 | next = (next + 1) << sdp->sd_sb.sb_bsize_shift; | |
1427 | ||
9ecf639a JB |
1428 | /* We only support the FALLOC_FL_KEEP_SIZE mode */ |
1429 | if (mode && (mode != FALLOC_FL_KEEP_SIZE)) | |
1430 | return -EOPNOTSUPP; | |
1431 | ||
3921120e BM |
1432 | offset = (offset >> sdp->sd_sb.sb_bsize_shift) << |
1433 | sdp->sd_sb.sb_bsize_shift; | |
1434 | ||
1435 | len = next - offset; | |
1436 | bytes = sdp->sd_max_rg_data * sdp->sd_sb.sb_bsize / 2; | |
1437 | if (!bytes) | |
1438 | bytes = UINT_MAX; | |
1439 | ||
1440 | gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &ip->i_gh); | |
1441 | error = gfs2_glock_nq(&ip->i_gh); | |
1442 | if (unlikely(error)) | |
1443 | goto out_uninit; | |
1444 | ||
1445 | if (!gfs2_write_alloc_required(ip, offset, len)) | |
1446 | goto out_unlock; | |
1447 | ||
1448 | while (len > 0) { | |
1449 | if (len < bytes) | |
1450 | bytes = len; | |
1451 | al = gfs2_alloc_get(ip); | |
1452 | if (!al) { | |
1453 | error = -ENOMEM; | |
1454 | goto out_unlock; | |
1455 | } | |
1456 | ||
1457 | error = gfs2_quota_lock_check(ip); | |
1458 | if (error) | |
1459 | goto out_alloc_put; | |
1460 | ||
1461 | retry: | |
1462 | gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks); | |
1463 | ||
1464 | al->al_requested = data_blocks + ind_blocks; | |
1465 | error = gfs2_inplace_reserve(ip); | |
1466 | if (error) { | |
1467 | if (error == -ENOSPC && bytes > sdp->sd_sb.sb_bsize) { | |
1468 | bytes >>= 1; | |
1469 | goto retry; | |
1470 | } | |
1471 | goto out_qunlock; | |
1472 | } | |
1473 | max_bytes = bytes; | |
1474 | calc_max_reserv(ip, len, &max_bytes, &data_blocks, &ind_blocks); | |
1475 | al->al_requested = data_blocks + ind_blocks; | |
1476 | ||
1477 | rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA + | |
bf97b673 | 1478 | RES_RG_HDR + gfs2_rg_blocks(al); |
3921120e BM |
1479 | if (gfs2_is_jdata(ip)) |
1480 | rblocks += data_blocks ? data_blocks : 1; | |
1481 | ||
1482 | error = gfs2_trans_begin(sdp, rblocks, | |
1483 | PAGE_CACHE_SIZE/sdp->sd_sb.sb_bsize); | |
1484 | if (error) | |
1485 | goto out_trans_fail; | |
1486 | ||
1487 | error = fallocate_chunk(inode, offset, max_bytes, mode); | |
1488 | gfs2_trans_end(sdp); | |
1489 | ||
1490 | if (error) | |
1491 | goto out_trans_fail; | |
1492 | ||
1493 | len -= max_bytes; | |
1494 | offset += max_bytes; | |
1495 | gfs2_inplace_release(ip); | |
1496 | gfs2_quota_unlock(ip); | |
1497 | gfs2_alloc_put(ip); | |
1498 | } | |
1499 | goto out_unlock; | |
1500 | ||
1501 | out_trans_fail: | |
1502 | gfs2_inplace_release(ip); | |
1503 | out_qunlock: | |
1504 | gfs2_quota_unlock(ip); | |
1505 | out_alloc_put: | |
1506 | gfs2_alloc_put(ip); | |
1507 | out_unlock: | |
1508 | gfs2_glock_dq(&ip->i_gh); | |
1509 | out_uninit: | |
1510 | gfs2_holder_uninit(&ip->i_gh); | |
1511 | return error; | |
1512 | } | |
1513 | ||
1514 | ||
e9079cce SW |
1515 | static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
1516 | u64 start, u64 len) | |
1517 | { | |
1518 | struct gfs2_inode *ip = GFS2_I(inode); | |
1519 | struct gfs2_holder gh; | |
1520 | int ret; | |
1521 | ||
1522 | ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC); | |
1523 | if (ret) | |
1524 | return ret; | |
1525 | ||
1526 | mutex_lock(&inode->i_mutex); | |
1527 | ||
1528 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh); | |
1529 | if (ret) | |
1530 | goto out; | |
1531 | ||
1532 | if (gfs2_is_stuffed(ip)) { | |
1533 | u64 phys = ip->i_no_addr << inode->i_blkbits; | |
1534 | u64 size = i_size_read(inode); | |
1535 | u32 flags = FIEMAP_EXTENT_LAST|FIEMAP_EXTENT_NOT_ALIGNED| | |
1536 | FIEMAP_EXTENT_DATA_INLINE; | |
1537 | phys += sizeof(struct gfs2_dinode); | |
1538 | phys += start; | |
1539 | if (start + len > size) | |
1540 | len = size - start; | |
1541 | if (start < size) | |
1542 | ret = fiemap_fill_next_extent(fieinfo, start, phys, | |
1543 | len, flags); | |
1544 | if (ret == 1) | |
1545 | ret = 0; | |
1546 | } else { | |
1547 | ret = __generic_block_fiemap(inode, fieinfo, start, len, | |
1548 | gfs2_block_map); | |
1549 | } | |
1550 | ||
1551 | gfs2_glock_dq_uninit(&gh); | |
1552 | out: | |
1553 | mutex_unlock(&inode->i_mutex); | |
1554 | return ret; | |
1555 | } | |
1556 | ||
92e1d5be | 1557 | const struct inode_operations gfs2_file_iops = { |
e6305c43 | 1558 | .permission = gfs2_permission, |
b3b94faa DT |
1559 | .setattr = gfs2_setattr, |
1560 | .getattr = gfs2_getattr, | |
1561 | .setxattr = gfs2_setxattr, | |
1562 | .getxattr = gfs2_getxattr, | |
1563 | .listxattr = gfs2_listxattr, | |
1564 | .removexattr = gfs2_removexattr, | |
3921120e | 1565 | .fallocate = gfs2_fallocate, |
e9079cce | 1566 | .fiemap = gfs2_fiemap, |
b3b94faa DT |
1567 | }; |
1568 | ||
92e1d5be | 1569 | const struct inode_operations gfs2_dir_iops = { |
b3b94faa DT |
1570 | .create = gfs2_create, |
1571 | .lookup = gfs2_lookup, | |
1572 | .link = gfs2_link, | |
1573 | .unlink = gfs2_unlink, | |
1574 | .symlink = gfs2_symlink, | |
1575 | .mkdir = gfs2_mkdir, | |
1576 | .rmdir = gfs2_rmdir, | |
1577 | .mknod = gfs2_mknod, | |
1578 | .rename = gfs2_rename, | |
e6305c43 | 1579 | .permission = gfs2_permission, |
b3b94faa DT |
1580 | .setattr = gfs2_setattr, |
1581 | .getattr = gfs2_getattr, | |
1582 | .setxattr = gfs2_setxattr, | |
1583 | .getxattr = gfs2_getxattr, | |
1584 | .listxattr = gfs2_listxattr, | |
1585 | .removexattr = gfs2_removexattr, | |
e9079cce | 1586 | .fiemap = gfs2_fiemap, |
b3b94faa DT |
1587 | }; |
1588 | ||
92e1d5be | 1589 | const struct inode_operations gfs2_symlink_iops = { |
c177c2ac | 1590 | .readlink = generic_readlink, |
b3b94faa | 1591 | .follow_link = gfs2_follow_link, |
c177c2ac | 1592 | .put_link = gfs2_put_link, |
e6305c43 | 1593 | .permission = gfs2_permission, |
b3b94faa DT |
1594 | .setattr = gfs2_setattr, |
1595 | .getattr = gfs2_getattr, | |
1596 | .setxattr = gfs2_setxattr, | |
1597 | .getxattr = gfs2_getxattr, | |
1598 | .listxattr = gfs2_listxattr, | |
1599 | .removexattr = gfs2_removexattr, | |
e9079cce | 1600 | .fiemap = gfs2_fiemap, |
b3b94faa DT |
1601 | }; |
1602 |