blob: 1005f9eb456e03dffead851fa546275d004a0b22 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
David Teiglandb3b94fa2006-01-16 16:50:04 +000010#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>
David Teiglandb3b94fa2006-01-16 16:50:04 +000015#include <linux/mm.h>
16#include <linux/xattr.h>
17#include <linux/posix_acl.h>
Steven Whitehouse5c676f62006-02-27 17:23:27 -050018#include <linux/gfs2_ondisk.h>
Steven Whitehouse71b86f52006-03-28 14:14:04 -050019#include <linux/crc32.h>
Steven Whitehousee9079cc2008-10-14 14:43:29 +010020#include <linux/fiemap.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000021#include <asm/uaccess.h>
22
23#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050024#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000025#include "acl.h"
26#include "bmap.h"
27#include "dir.h"
Steven Whitehouse307cf6e2009-08-26 18:51:04 +010028#include "xattr.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000029#include "glock.h"
30#include "inode.h"
31#include "meta_io.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000032#include "quota.h"
33#include "rgrp.h"
34#include "trans.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050035#include "util.h"
Steven Whitehouseb2760582008-10-14 16:05:55 +010036#include "super.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000037
38/**
39 * gfs2_create - Create a file
40 * @dir: The directory in which to create the file
41 * @dentry: The dentry of the new file
42 * @mode: The mode of the new file
43 *
44 * Returns: errno
45 */
46
47static int gfs2_create(struct inode *dir, struct dentry *dentry,
48 int mode, struct nameidata *nd)
49{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -040050 struct gfs2_inode *dip = GFS2_I(dir);
51 struct gfs2_sbd *sdp = GFS2_SB(dir);
David Teiglandb3b94fa2006-01-16 16:50:04 +000052 struct gfs2_holder ghs[2];
53 struct inode *inode;
David Teiglandb3b94fa2006-01-16 16:50:04 +000054
David Teiglandb3b94fa2006-01-16 16:50:04 +000055 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
56
57 for (;;) {
Steven Whitehousee7f14f42006-10-31 21:45:08 -050058 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0);
Steven Whitehouse7359a192006-02-13 12:27:43 +000059 if (!IS_ERR(inode)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +000060 gfs2_trans_end(sdp);
Steven Whitehouse6dbd8222008-01-10 15:18:55 +000061 if (dip->i_alloc->al_rgd)
David Teiglandb3b94fa2006-01-16 16:50:04 +000062 gfs2_inplace_release(dip);
63 gfs2_quota_unlock(dip);
64 gfs2_alloc_put(dip);
65 gfs2_glock_dq_uninit_m(2, ghs);
Steven Whitehouse3a8476d2006-06-19 09:10:39 -040066 mark_inode_dirty(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +000067 break;
Steven Whitehouse7359a192006-02-13 12:27:43 +000068 } else if (PTR_ERR(inode) != -EEXIST ||
Al Viro35165862008-08-05 03:00:49 -040069 (nd && nd->flags & LOOKUP_EXCL)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +000070 gfs2_holder_uninit(ghs);
Steven Whitehouse7359a192006-02-13 12:27:43 +000071 return PTR_ERR(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +000072 }
73
Al Viroa569c712008-07-23 14:42:05 -040074 inode = gfs2_lookupi(dir, &dentry->d_name, 0);
Steven Whitehousec7526662006-03-20 12:30:04 -050075 if (inode) {
76 if (!IS_ERR(inode)) {
Steven Whitehousec7526662006-03-20 12:30:04 -050077 gfs2_holder_uninit(ghs);
78 break;
79 } else {
80 gfs2_holder_uninit(ghs);
81 return PTR_ERR(inode);
82 }
David Teiglandb3b94fa2006-01-16 16:50:04 +000083 }
84 }
85
David Teiglandb3b94fa2006-01-16 16:50:04 +000086 d_instantiate(dentry, inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +000087
88 return 0;
89}
90
91/**
92 * gfs2_lookup - Look up a filename in a directory and return its inode
93 * @dir: The directory inode
94 * @dentry: The dentry of the new inode
95 * @nd: passed from Linux VFS, ignored by us
96 *
97 * Called by the VFS layer. Lock dir and call gfs2_lookupi()
98 *
99 * Returns: errno
100 */
101
102static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
103 struct nameidata *nd)
104{
David Teiglandb3b94fa2006-01-16 16:50:04 +0000105 struct inode *inode = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000106
Al Viroa569c712008-07-23 14:42:05 -0400107 inode = gfs2_lookupi(dir, &dentry->d_name, 0);
Steven Whitehousec7526662006-03-20 12:30:04 -0500108 if (inode && IS_ERR(inode))
David Howellse231c2e2008-02-07 00:15:26 -0800109 return ERR_CAST(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000110
Steven Whitehouse9656b2c2008-01-08 08:14:30 +0000111 if (inode) {
112 struct gfs2_glock *gl = GFS2_I(inode)->i_gl;
113 struct gfs2_holder gh;
114 int error;
115 error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
116 if (error) {
117 iput(inode);
118 return ERR_PTR(error);
119 }
120 gfs2_glock_dq_uninit(&gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000121 return d_splice_alias(inode, dentry);
Steven Whitehouse9656b2c2008-01-08 08:14:30 +0000122 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000123 d_add(dentry, inode);
124
125 return NULL;
126}
127
128/**
129 * gfs2_link - Link to a file
130 * @old_dentry: The inode to link
131 * @dir: Add link to this directory
132 * @dentry: The name of the link
133 *
134 * Link the inode in "old_dentry" into the directory "dir" with the
135 * name in "dentry".
136 *
137 * Returns: errno
138 */
139
140static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
141 struct dentry *dentry)
142{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400143 struct gfs2_inode *dip = GFS2_I(dir);
144 struct gfs2_sbd *sdp = GFS2_SB(dir);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000145 struct inode *inode = old_dentry->d_inode;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400146 struct gfs2_inode *ip = GFS2_I(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000147 struct gfs2_holder ghs[2];
148 int alloc_required;
149 int error;
150
Steven Whitehouseb60623c2006-11-01 12:22:46 -0500151 if (S_ISDIR(inode->i_mode))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000152 return -EPERM;
153
154 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
155 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
156
Bob Peterson72dbf472008-08-12 13:39:29 -0500157 error = gfs2_glock_nq(ghs); /* parent */
David Teiglandb3b94fa2006-01-16 16:50:04 +0000158 if (error)
Bob Peterson72dbf472008-08-12 13:39:29 -0500159 goto out_parent;
160
161 error = gfs2_glock_nq(ghs + 1); /* child */
162 if (error)
163 goto out_child;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000164
Steven Whitehoused192a8e2011-05-05 12:35:40 +0100165 error = -ENOENT;
166 if (inode->i_nlink == 0)
167 goto out_gunlock;
168
Nick Pigginb74c79e2011-01-07 17:49:58 +1100169 error = gfs2_permission(dir, MAY_WRITE | MAY_EXEC, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000170 if (error)
171 goto out_gunlock;
172
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100173 error = gfs2_dir_check(dir, &dentry->d_name, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000174 switch (error) {
175 case -ENOENT:
176 break;
177 case 0:
178 error = -EEXIST;
179 default:
180 goto out_gunlock;
181 }
182
183 error = -EINVAL;
Steven Whitehouse4f561102006-11-01 14:04:17 -0500184 if (!dip->i_inode.i_nlink)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000185 goto out_gunlock;
186 error = -EFBIG;
Steven Whitehousead6203f2008-11-03 13:59:19 +0000187 if (dip->i_entries == (u32)-1)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000188 goto out_gunlock;
189 error = -EPERM;
190 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
191 goto out_gunlock;
192 error = -EINVAL;
Steven Whitehouse4f561102006-11-01 14:04:17 -0500193 if (!ip->i_inode.i_nlink)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000194 goto out_gunlock;
195 error = -EMLINK;
Steven Whitehouse4f561102006-11-01 14:04:17 -0500196 if (ip->i_inode.i_nlink == (u32)-1)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000197 goto out_gunlock;
198
Steven Whitehousec7526662006-03-20 12:30:04 -0500199 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
200 if (error < 0)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000201 goto out_gunlock;
Steven Whitehousec7526662006-03-20 12:30:04 -0500202 error = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000203
204 if (alloc_required) {
205 struct gfs2_alloc *al = gfs2_alloc_get(dip);
Cyrill Gorcunov182fe5a2008-03-03 21:54:21 +0300206 if (!al) {
207 error = -ENOMEM;
208 goto out_gunlock;
209 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000210
Steven Whitehoused82661d2008-03-10 15:34:50 +0000211 error = gfs2_quota_lock_check(dip);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000212 if (error)
213 goto out_alloc;
214
David Teiglandb3b94fa2006-01-16 16:50:04 +0000215 al->al_requested = sdp->sd_max_dirres;
216
217 error = gfs2_inplace_reserve(dip);
218 if (error)
219 goto out_gunlock_q;
220
Steven Whitehouse1b502592006-05-18 14:10:52 -0400221 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
Benjamin Marzinskibf97b672010-09-27 16:00:04 -0500222 gfs2_rg_blocks(al) +
David Teiglandb3b94fa2006-01-16 16:50:04 +0000223 2 * RES_DINODE + RES_STATFS +
224 RES_QUOTA, 0);
225 if (error)
226 goto out_ipres;
227 } else {
228 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
229 if (error)
230 goto out_ipres;
231 }
232
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100233 error = gfs2_dir_add(dir, &dentry->d_name, ip, IF2DT(inode->i_mode));
David Teiglandb3b94fa2006-01-16 16:50:04 +0000234 if (error)
235 goto out_end_trans;
236
237 error = gfs2_change_nlink(ip, +1);
238
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400239out_end_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000240 gfs2_trans_end(sdp);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400241out_ipres:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000242 if (alloc_required)
243 gfs2_inplace_release(dip);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400244out_gunlock_q:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000245 if (alloc_required)
246 gfs2_quota_unlock(dip);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400247out_alloc:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000248 if (alloc_required)
249 gfs2_alloc_put(dip);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400250out_gunlock:
Bob Peterson72dbf472008-08-12 13:39:29 -0500251 gfs2_glock_dq(ghs + 1);
252out_child:
253 gfs2_glock_dq(ghs);
254out_parent:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000255 gfs2_holder_uninit(ghs);
256 gfs2_holder_uninit(ghs + 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000257 if (!error) {
Al Viro7de9c6ee2010-10-23 11:11:40 -0400258 ihold(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000259 d_instantiate(dentry, inode);
260 mark_inode_dirty(inode);
261 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000262 return error;
263}
264
Steven Whitehouse87ec2172009-05-22 10:54:50 +0100265/*
266 * gfs2_unlink_ok - check to see that a inode is still in a directory
267 * @dip: the directory
268 * @name: the name of the file
269 * @ip: the inode
270 *
271 * Assumes that the lock on (at least) @dip is held.
272 *
273 * Returns: 0 if the parent/child relationship is correct, errno if it isn't
274 */
275
276static int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
277 const struct gfs2_inode *ip)
278{
279 int error;
280
281 if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode))
282 return -EPERM;
283
284 if ((dip->i_inode.i_mode & S_ISVTX) &&
285 dip->i_inode.i_uid != current_fsuid() &&
286 ip->i_inode.i_uid != current_fsuid() && !capable(CAP_FOWNER))
287 return -EPERM;
288
289 if (IS_APPEND(&dip->i_inode))
290 return -EPERM;
291
Nick Pigginb74c79e2011-01-07 17:49:58 +1100292 error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC, 0);
Steven Whitehouse87ec2172009-05-22 10:54:50 +0100293 if (error)
294 return error;
295
296 error = gfs2_dir_check(&dip->i_inode, name, ip);
297 if (error)
298 return error;
299
300 return 0;
301}
302
David Teiglandb3b94fa2006-01-16 16:50:04 +0000303/**
304 * gfs2_unlink - Unlink a file
305 * @dir: The inode of the directory containing the file to unlink
306 * @dentry: The file itself
307 *
308 * Unlink a file. Call gfs2_unlinki()
309 *
310 * Returns: errno
311 */
312
313static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
314{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400315 struct gfs2_inode *dip = GFS2_I(dir);
316 struct gfs2_sbd *sdp = GFS2_SB(dir);
317 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
Russell Cattelanddee7602007-01-29 17:13:44 -0600318 struct gfs2_holder ghs[3];
319 struct gfs2_rgrpd *rgd;
320 struct gfs2_holder ri_gh;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000321 int error;
322
Russell Cattelanddee7602007-01-29 17:13:44 -0600323 error = gfs2_rindex_hold(sdp, &ri_gh);
324 if (error)
325 return error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000326
Russell Cattelanddee7602007-01-29 17:13:44 -0600327 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
328 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
329
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100330 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
Russell Cattelanddee7602007-01-29 17:13:44 -0600331 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
332
333
Steven Whitehouse8497a462007-08-26 14:23:56 +0100334 error = gfs2_glock_nq(ghs); /* parent */
David Teiglandb3b94fa2006-01-16 16:50:04 +0000335 if (error)
Steven Whitehouse8497a462007-08-26 14:23:56 +0100336 goto out_parent;
337
338 error = gfs2_glock_nq(ghs + 1); /* child */
339 if (error)
340 goto out_child;
341
Steven Whitehoused192a8e2011-05-05 12:35:40 +0100342 error = -ENOENT;
343 if (ip->i_inode.i_nlink == 0)
344 goto out_rgrp;
345
Steven Whitehouse8497a462007-08-26 14:23:56 +0100346 error = gfs2_glock_nq(ghs + 2); /* rgrp */
347 if (error)
348 goto out_rgrp;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000349
350 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
351 if (error)
Bob Peterson72dbf472008-08-12 13:39:29 -0500352 goto out_gunlock;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000353
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400354 error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000355 if (error)
Roel Kluincd012072009-08-22 19:26:42 +0200356 goto out_gunlock;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000357
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400358 error = gfs2_dir_del(dip, &dentry->d_name);
359 if (error)
360 goto out_end_trans;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000361
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400362 error = gfs2_change_nlink(ip, -1);
363
364out_end_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000365 gfs2_trans_end(sdp);
Bob Peterson72dbf472008-08-12 13:39:29 -0500366out_gunlock:
Steven Whitehouse8497a462007-08-26 14:23:56 +0100367 gfs2_glock_dq(ghs + 2);
368out_rgrp:
Russell Cattelanddee7602007-01-29 17:13:44 -0600369 gfs2_holder_uninit(ghs + 2);
Steven Whitehouse8497a462007-08-26 14:23:56 +0100370 gfs2_glock_dq(ghs + 1);
371out_child:
372 gfs2_holder_uninit(ghs + 1);
373 gfs2_glock_dq(ghs);
374out_parent:
375 gfs2_holder_uninit(ghs);
Russell Cattelanddee7602007-01-29 17:13:44 -0600376 gfs2_glock_dq_uninit(&ri_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000377 return error;
378}
379
380/**
381 * gfs2_symlink - Create a symlink
382 * @dir: The directory to create the symlink in
383 * @dentry: The dentry to put the symlink in
384 * @symname: The thing which the link points to
385 *
386 * Returns: errno
387 */
388
389static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
390 const char *symname)
391{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400392 struct gfs2_inode *dip = GFS2_I(dir), *ip;
393 struct gfs2_sbd *sdp = GFS2_SB(dir);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000394 struct gfs2_holder ghs[2];
395 struct inode *inode;
396 struct buffer_head *dibh;
397 int size;
398 int error;
399
David Teiglandb3b94fa2006-01-16 16:50:04 +0000400 /* Must be stuffed with a null terminator for gfs2_follow_link() */
401 size = strlen(symname);
402 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
403 return -ENAMETOOLONG;
404
405 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
406
Steven Whitehousee7f14f42006-10-31 21:45:08 -0500407 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0);
Steven Whitehouse7359a192006-02-13 12:27:43 +0000408 if (IS_ERR(inode)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000409 gfs2_holder_uninit(ghs);
Steven Whitehouse7359a192006-02-13 12:27:43 +0000410 return PTR_ERR(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000411 }
412
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500413 ip = ghs[1].gh_gl->gl_object;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000414
Steven Whitehouse5cf32522009-03-31 16:06:27 +0100415 i_size_write(inode, size);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000416
417 error = gfs2_meta_inode_buffer(ip, &dibh);
418
419 if (!gfs2_assert_withdraw(sdp, !error)) {
Steven Whitehouse539e5d62006-10-31 15:07:05 -0500420 gfs2_dinode_out(ip, dibh->b_data);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000421 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
422 size);
423 brelse(dibh);
424 }
425
426 gfs2_trans_end(sdp);
Steven Whitehouse6dbd8222008-01-10 15:18:55 +0000427 if (dip->i_alloc->al_rgd)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000428 gfs2_inplace_release(dip);
429 gfs2_quota_unlock(dip);
430 gfs2_alloc_put(dip);
431
432 gfs2_glock_dq_uninit_m(2, ghs);
433
David Teiglandb3b94fa2006-01-16 16:50:04 +0000434 d_instantiate(dentry, inode);
435 mark_inode_dirty(inode);
436
437 return 0;
438}
439
440/**
441 * gfs2_mkdir - Make a directory
442 * @dir: The parent directory of the new one
443 * @dentry: The dentry of the new directory
444 * @mode: The mode of the new directory
445 *
446 * Returns: errno
447 */
448
449static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
450{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400451 struct gfs2_inode *dip = GFS2_I(dir), *ip;
452 struct gfs2_sbd *sdp = GFS2_SB(dir);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000453 struct gfs2_holder ghs[2];
454 struct inode *inode;
455 struct buffer_head *dibh;
456 int error;
457
David Teiglandb3b94fa2006-01-16 16:50:04 +0000458 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
459
Steven Whitehousee7f14f42006-10-31 21:45:08 -0500460 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0);
Steven Whitehouse7359a192006-02-13 12:27:43 +0000461 if (IS_ERR(inode)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000462 gfs2_holder_uninit(ghs);
Steven Whitehouse7359a192006-02-13 12:27:43 +0000463 return PTR_ERR(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000464 }
465
Steven Whitehouse5c676f62006-02-27 17:23:27 -0500466 ip = ghs[1].gh_gl->gl_object;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000467
Steven Whitehouse4f561102006-11-01 14:04:17 -0500468 ip->i_inode.i_nlink = 2;
Steven Whitehousea2e0f792010-08-11 09:53:11 +0100469 i_size_write(inode, sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode));
Steven Whitehouse383f01f2008-11-04 10:05:22 +0000470 ip->i_diskflags |= GFS2_DIF_JDATA;
Steven Whitehousead6203f2008-11-03 13:59:19 +0000471 ip->i_entries = 2;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000472
473 error = gfs2_meta_inode_buffer(ip, &dibh);
474
475 if (!gfs2_assert_withdraw(sdp, !error)) {
476 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
Steven Whitehousec7526662006-03-20 12:30:04 -0500477 struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000478
Steven Whitehousec7526662006-03-20 12:30:04 -0500479 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
Steven Whitehouse8d123582010-09-17 12:30:23 +0100480 gfs2_qstr2dirent(&gfs2_qdot, GFS2_DIRENT_SIZE(gfs2_qdot.len), dent);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000481 dent->de_inum = di->di_num; /* already GFS2 endian */
Steven Whitehouse7ecdb702006-10-03 21:03:35 -0400482 dent->de_type = cpu_to_be16(DT_DIR);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000483 di->di_entries = cpu_to_be32(1);
484
Steven Whitehousec7526662006-03-20 12:30:04 -0500485 dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
Steven Whitehouse8d123582010-09-17 12:30:23 +0100486 gfs2_qstr2dirent(&gfs2_qdotdot, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000487
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100488 gfs2_inum_out(dip, dent);
Steven Whitehouse7ecdb702006-10-03 21:03:35 -0400489 dent->de_type = cpu_to_be16(DT_DIR);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000490
Steven Whitehouse539e5d62006-10-31 15:07:05 -0500491 gfs2_dinode_out(ip, di);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000492
493 brelse(dibh);
494 }
495
496 error = gfs2_change_nlink(dip, +1);
497 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
498
499 gfs2_trans_end(sdp);
Steven Whitehouse6dbd8222008-01-10 15:18:55 +0000500 if (dip->i_alloc->al_rgd)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000501 gfs2_inplace_release(dip);
502 gfs2_quota_unlock(dip);
503 gfs2_alloc_put(dip);
504
505 gfs2_glock_dq_uninit_m(2, ghs);
506
David Teiglandb3b94fa2006-01-16 16:50:04 +0000507 d_instantiate(dentry, inode);
508 mark_inode_dirty(inode);
509
510 return 0;
511}
512
513/**
Steven Whitehouse2286dbf2009-05-22 10:45:09 +0100514 * gfs2_rmdiri - Remove a directory
515 * @dip: The parent directory of the directory to be removed
516 * @name: The name of the directory to be removed
517 * @ip: The GFS2 inode of the directory to be removed
518 *
519 * Assumes Glocks on dip and ip are held
520 *
521 * Returns: errno
522 */
523
524static int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name,
525 struct gfs2_inode *ip)
526{
Steven Whitehouse2286dbf2009-05-22 10:45:09 +0100527 int error;
528
529 if (ip->i_entries != 2) {
530 if (gfs2_consist_inode(ip))
531 gfs2_dinode_print(ip);
532 return -EIO;
533 }
534
535 error = gfs2_dir_del(dip, name);
536 if (error)
537 return error;
538
539 error = gfs2_change_nlink(dip, -1);
540 if (error)
541 return error;
542
Steven Whitehouse8d123582010-09-17 12:30:23 +0100543 error = gfs2_dir_del(ip, &gfs2_qdot);
Steven Whitehouse2286dbf2009-05-22 10:45:09 +0100544 if (error)
545 return error;
546
Steven Whitehouse8d123582010-09-17 12:30:23 +0100547 error = gfs2_dir_del(ip, &gfs2_qdotdot);
Steven Whitehouse2286dbf2009-05-22 10:45:09 +0100548 if (error)
549 return error;
550
551 /* It looks odd, but it really should be done twice */
552 error = gfs2_change_nlink(ip, -1);
553 if (error)
554 return error;
555
556 error = gfs2_change_nlink(ip, -1);
557 if (error)
558 return error;
559
560 return error;
561}
562
563/**
David Teiglandb3b94fa2006-01-16 16:50:04 +0000564 * gfs2_rmdir - Remove a directory
565 * @dir: The parent directory of the directory to be removed
566 * @dentry: The dentry of the directory to remove
567 *
568 * Remove a directory. Call gfs2_rmdiri()
569 *
570 * Returns: errno
571 */
572
573static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
574{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400575 struct gfs2_inode *dip = GFS2_I(dir);
576 struct gfs2_sbd *sdp = GFS2_SB(dir);
577 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
Russell Cattelanddee7602007-01-29 17:13:44 -0600578 struct gfs2_holder ghs[3];
579 struct gfs2_rgrpd *rgd;
580 struct gfs2_holder ri_gh;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000581 int error;
582
Russell Cattelanddee7602007-01-29 17:13:44 -0600583 error = gfs2_rindex_hold(sdp, &ri_gh);
584 if (error)
585 return error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000586 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
587 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
588
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100589 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
Russell Cattelanddee7602007-01-29 17:13:44 -0600590 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
591
Bob Peterson72dbf472008-08-12 13:39:29 -0500592 error = gfs2_glock_nq(ghs); /* parent */
David Teiglandb3b94fa2006-01-16 16:50:04 +0000593 if (error)
Bob Peterson72dbf472008-08-12 13:39:29 -0500594 goto out_parent;
595
596 error = gfs2_glock_nq(ghs + 1); /* child */
597 if (error)
598 goto out_child;
599
Steven Whitehoused192a8e2011-05-05 12:35:40 +0100600 error = -ENOENT;
601 if (ip->i_inode.i_nlink == 0)
602 goto out_rgrp;
603
Bob Peterson72dbf472008-08-12 13:39:29 -0500604 error = gfs2_glock_nq(ghs + 2); /* rgrp */
605 if (error)
606 goto out_rgrp;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000607
608 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
609 if (error)
610 goto out_gunlock;
611
Steven Whitehousead6203f2008-11-03 13:59:19 +0000612 if (ip->i_entries < 2) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000613 if (gfs2_consist_inode(ip))
Steven Whitehouse4cc14f02006-10-31 19:00:24 -0500614 gfs2_dinode_print(ip);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000615 error = -EIO;
616 goto out_gunlock;
617 }
Steven Whitehousead6203f2008-11-03 13:59:19 +0000618 if (ip->i_entries > 2) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000619 error = -ENOTEMPTY;
620 goto out_gunlock;
621 }
622
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400623 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000624 if (error)
625 goto out_gunlock;
626
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400627 error = gfs2_rmdiri(dip, &dentry->d_name, ip);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000628
629 gfs2_trans_end(sdp);
630
Steven Whitehousea91ea692006-09-04 12:04:26 -0400631out_gunlock:
Bob Peterson72dbf472008-08-12 13:39:29 -0500632 gfs2_glock_dq(ghs + 2);
633out_rgrp:
Russell Cattelanddee7602007-01-29 17:13:44 -0600634 gfs2_holder_uninit(ghs + 2);
Bob Peterson72dbf472008-08-12 13:39:29 -0500635 gfs2_glock_dq(ghs + 1);
636out_child:
637 gfs2_holder_uninit(ghs + 1);
638 gfs2_glock_dq(ghs);
639out_parent:
640 gfs2_holder_uninit(ghs);
Russell Cattelanddee7602007-01-29 17:13:44 -0600641 gfs2_glock_dq_uninit(&ri_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000642 return error;
643}
644
645/**
646 * gfs2_mknod - Make a special file
647 * @dir: The directory in which the special file will reside
648 * @dentry: The dentry of the special file
649 * @mode: The mode of the special file
650 * @rdev: The device specification of the special file
651 *
652 */
653
654static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
655 dev_t dev)
656{
Steven Whitehousee7f14f42006-10-31 21:45:08 -0500657 struct gfs2_inode *dip = GFS2_I(dir);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400658 struct gfs2_sbd *sdp = GFS2_SB(dir);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000659 struct gfs2_holder ghs[2];
660 struct inode *inode;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000661
662 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
663
Steven Whitehousee7f14f42006-10-31 21:45:08 -0500664 inode = gfs2_createi(ghs, &dentry->d_name, mode, dev);
Steven Whitehouse7359a192006-02-13 12:27:43 +0000665 if (IS_ERR(inode)) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000666 gfs2_holder_uninit(ghs);
Steven Whitehouse7359a192006-02-13 12:27:43 +0000667 return PTR_ERR(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000668 }
669
David Teiglandb3b94fa2006-01-16 16:50:04 +0000670 gfs2_trans_end(sdp);
Steven Whitehouse6dbd8222008-01-10 15:18:55 +0000671 if (dip->i_alloc->al_rgd)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000672 gfs2_inplace_release(dip);
673 gfs2_quota_unlock(dip);
674 gfs2_alloc_put(dip);
675
676 gfs2_glock_dq_uninit_m(2, ghs);
677
David Teiglandb3b94fa2006-01-16 16:50:04 +0000678 d_instantiate(dentry, inode);
679 mark_inode_dirty(inode);
680
681 return 0;
682}
683
Steven Whitehouse0188d6c2008-08-26 09:38:26 +0100684/*
685 * gfs2_ok_to_move - check if it's ok to move a directory to another directory
686 * @this: move this
687 * @to: to here
688 *
689 * Follow @to back to the root and make sure we don't encounter @this
690 * Assumes we already hold the rename lock.
691 *
692 * Returns: errno
693 */
694
695static int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to)
696{
697 struct inode *dir = &to->i_inode;
698 struct super_block *sb = dir->i_sb;
699 struct inode *tmp;
Steven Whitehouse0188d6c2008-08-26 09:38:26 +0100700 int error = 0;
701
Steven Whitehouse0188d6c2008-08-26 09:38:26 +0100702 igrab(dir);
703
704 for (;;) {
705 if (dir == &this->i_inode) {
706 error = -EINVAL;
707 break;
708 }
709 if (dir == sb->s_root->d_inode) {
710 error = 0;
711 break;
712 }
713
Steven Whitehouse8d123582010-09-17 12:30:23 +0100714 tmp = gfs2_lookupi(dir, &gfs2_qdotdot, 1);
Steven Whitehouse0188d6c2008-08-26 09:38:26 +0100715 if (IS_ERR(tmp)) {
716 error = PTR_ERR(tmp);
717 break;
718 }
719
720 iput(dir);
721 dir = tmp;
722 }
723
724 iput(dir);
725
726 return error;
727}
728
David Teiglandb3b94fa2006-01-16 16:50:04 +0000729/**
730 * gfs2_rename - Rename a file
731 * @odir: Parent directory of old file name
732 * @odentry: The old dentry of the file
733 * @ndir: Parent directory of new file name
734 * @ndentry: The new dentry of the file
735 *
736 * Returns: errno
737 */
738
739static int gfs2_rename(struct inode *odir, struct dentry *odentry,
740 struct inode *ndir, struct dentry *ndentry)
741{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400742 struct gfs2_inode *odip = GFS2_I(odir);
743 struct gfs2_inode *ndip = GFS2_I(ndir);
744 struct gfs2_inode *ip = GFS2_I(odentry->d_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000745 struct gfs2_inode *nip = NULL;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400746 struct gfs2_sbd *sdp = GFS2_SB(odir);
Bob Peterson462903412010-09-30 10:34:00 -0400747 struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, }, ri_gh;
Russell Cattelanddee7602007-01-29 17:13:44 -0600748 struct gfs2_rgrpd *nrgd;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000749 unsigned int num_gh;
750 int dir_rename = 0;
Steven Whitehouse24b977b2009-12-09 13:55:12 +0000751 int alloc_required = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000752 unsigned int x;
753 int error;
754
David Teiglandb3b94fa2006-01-16 16:50:04 +0000755 if (ndentry->d_inode) {
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400756 nip = GFS2_I(ndentry->d_inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000757 if (ip == nip)
758 return 0;
759 }
760
Bob Peterson462903412010-09-30 10:34:00 -0400761 error = gfs2_rindex_hold(sdp, &ri_gh);
762 if (error)
763 return error;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000764
Steven Whitehouse0188d6c2008-08-26 09:38:26 +0100765 if (odip != ndip) {
766 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE,
767 0, &r_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000768 if (error)
769 goto out;
770
Steven Whitehouse0188d6c2008-08-26 09:38:26 +0100771 if (S_ISDIR(ip->i_inode.i_mode)) {
772 dir_rename = 1;
773 /* don't move a dirctory into it's subdir */
774 error = gfs2_ok_to_move(ip, ndip);
775 if (error)
776 goto out_gunlock_r;
777 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000778 }
779
Steven Whitehoused9d1ca32006-06-21 15:38:17 -0400780 num_gh = 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000781 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
Steven Whitehoused9d1ca32006-06-21 15:38:17 -0400782 if (odip != ndip) {
783 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
784 num_gh++;
785 }
786 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
787 num_gh++;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000788
Steven Whitehoused9d1ca32006-06-21 15:38:17 -0400789 if (nip) {
790 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
791 num_gh++;
Russell Cattelanddee7602007-01-29 17:13:44 -0600792 /* grab the resource lock for unlink flag twiddling
793 * this is the case of the target file already existing
794 * so we unlink before doing the rename
795 */
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100796 nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr);
Russell Cattelanddee7602007-01-29 17:13:44 -0600797 if (nrgd)
798 gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
Steven Whitehoused9d1ca32006-06-21 15:38:17 -0400799 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000800
Bob Peterson72dbf472008-08-12 13:39:29 -0500801 for (x = 0; x < num_gh; x++) {
802 error = gfs2_glock_nq(ghs + x);
803 if (error)
804 goto out_gunlock;
805 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000806
Steven Whitehoused192a8e2011-05-05 12:35:40 +0100807 error = -ENOENT;
808 if (ip->i_inode.i_nlink == 0)
809 goto out_gunlock;
810
David Teiglandb3b94fa2006-01-16 16:50:04 +0000811 /* Check out the old directory */
812
813 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
814 if (error)
815 goto out_gunlock;
816
817 /* Check out the new directory */
818
819 if (nip) {
820 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
821 if (error)
822 goto out_gunlock;
823
Steven Whitehoused192a8e2011-05-05 12:35:40 +0100824 if (nip->i_inode.i_nlink == 0) {
825 error = -EAGAIN;
826 goto out_gunlock;
827 }
828
Steven Whitehouseb60623c2006-11-01 12:22:46 -0500829 if (S_ISDIR(nip->i_inode.i_mode)) {
Steven Whitehousead6203f2008-11-03 13:59:19 +0000830 if (nip->i_entries < 2) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000831 if (gfs2_consist_inode(nip))
Steven Whitehouse4cc14f02006-10-31 19:00:24 -0500832 gfs2_dinode_print(nip);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000833 error = -EIO;
834 goto out_gunlock;
835 }
Steven Whitehousead6203f2008-11-03 13:59:19 +0000836 if (nip->i_entries > 2) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000837 error = -ENOTEMPTY;
838 goto out_gunlock;
839 }
840 }
841 } else {
Nick Pigginb74c79e2011-01-07 17:49:58 +1100842 error = gfs2_permission(ndir, MAY_WRITE | MAY_EXEC, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000843 if (error)
844 goto out_gunlock;
845
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100846 error = gfs2_dir_check(ndir, &ndentry->d_name, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000847 switch (error) {
848 case -ENOENT:
849 error = 0;
850 break;
851 case 0:
852 error = -EEXIST;
853 default:
854 goto out_gunlock;
855 };
856
857 if (odip != ndip) {
Steven Whitehouse4f561102006-11-01 14:04:17 -0500858 if (!ndip->i_inode.i_nlink) {
Steven Whitehoused192a8e2011-05-05 12:35:40 +0100859 error = -ENOENT;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000860 goto out_gunlock;
861 }
Steven Whitehousead6203f2008-11-03 13:59:19 +0000862 if (ndip->i_entries == (u32)-1) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000863 error = -EFBIG;
864 goto out_gunlock;
865 }
Steven Whitehouseb60623c2006-11-01 12:22:46 -0500866 if (S_ISDIR(ip->i_inode.i_mode) &&
Steven Whitehouse4f561102006-11-01 14:04:17 -0500867 ndip->i_inode.i_nlink == (u32)-1) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000868 error = -EMLINK;
869 goto out_gunlock;
870 }
871 }
872 }
873
874 /* Check out the dir to be renamed */
875
876 if (dir_rename) {
Nick Pigginb74c79e2011-01-07 17:49:58 +1100877 error = gfs2_permission(odentry->d_inode, MAY_WRITE, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000878 if (error)
879 goto out_gunlock;
880 }
881
Steven Whitehouse24b977b2009-12-09 13:55:12 +0000882 if (nip == NULL)
883 alloc_required = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
884 error = alloc_required;
Steven Whitehousec7526662006-03-20 12:30:04 -0500885 if (error < 0)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000886 goto out_gunlock;
Steven Whitehousec7526662006-03-20 12:30:04 -0500887 error = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000888
889 if (alloc_required) {
890 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
Cyrill Gorcunov182fe5a2008-03-03 21:54:21 +0300891 if (!al) {
892 error = -ENOMEM;
893 goto out_gunlock;
894 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000895
Steven Whitehoused82661d2008-03-10 15:34:50 +0000896 error = gfs2_quota_lock_check(ndip);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000897 if (error)
898 goto out_alloc;
899
David Teiglandb3b94fa2006-01-16 16:50:04 +0000900 al->al_requested = sdp->sd_max_dirres;
901
Bob Peterson462903412010-09-30 10:34:00 -0400902 error = gfs2_inplace_reserve_ri(ndip);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000903 if (error)
904 goto out_gunlock_q;
905
Steven Whitehousefe1bded2006-04-18 10:09:15 -0400906 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
Benjamin Marzinskibf97b672010-09-27 16:00:04 -0500907 gfs2_rg_blocks(al) +
David Teiglandb3b94fa2006-01-16 16:50:04 +0000908 4 * RES_DINODE + 4 * RES_LEAF +
S. Wendy Cheng87d21e02007-01-18 16:07:03 -0500909 RES_STATFS + RES_QUOTA + 4, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000910 if (error)
911 goto out_ipreserv;
912 } else {
913 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
S. Wendy Cheng87d21e02007-01-18 16:07:03 -0500914 5 * RES_LEAF + 4, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000915 if (error)
916 goto out_gunlock;
917 }
918
919 /* Remove the target file, if it exists */
920
921 if (nip) {
Steven Whitehouseb60623c2006-11-01 12:22:46 -0500922 if (S_ISDIR(nip->i_inode.i_mode))
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400923 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
924 else {
925 error = gfs2_dir_del(ndip, &ndentry->d_name);
926 if (error)
927 goto out_end_trans;
S. Wendy Cheng87d21e02007-01-18 16:07:03 -0500928 error = gfs2_change_nlink(nip, -1);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400929 }
David Teiglandb3b94fa2006-01-16 16:50:04 +0000930 if (error)
931 goto out_end_trans;
932 }
933
934 if (dir_rename) {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000935 error = gfs2_change_nlink(ndip, +1);
936 if (error)
937 goto out_end_trans;
938 error = gfs2_change_nlink(odip, -1);
939 if (error)
940 goto out_end_trans;
941
Steven Whitehouse8d123582010-09-17 12:30:23 +0100942 error = gfs2_dir_mvino(ip, &gfs2_qdotdot, ndip, DT_DIR);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000943 if (error)
944 goto out_end_trans;
945 } else {
946 struct buffer_head *dibh;
947 error = gfs2_meta_inode_buffer(ip, &dibh);
948 if (error)
949 goto out_end_trans;
Steven Whitehouse4bd91ba2007-06-05 09:39:18 +0100950 ip->i_inode.i_ctime = CURRENT_TIME;
Steven Whitehoused4e9c4c2006-01-18 11:19:28 +0000951 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
Steven Whitehouse539e5d62006-10-31 15:07:05 -0500952 gfs2_dinode_out(ip, dibh->b_data);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000953 brelse(dibh);
954 }
955
956 error = gfs2_dir_del(odip, &odentry->d_name);
957 if (error)
958 goto out_end_trans;
959
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100960 error = gfs2_dir_add(ndir, &ndentry->d_name, ip, IF2DT(ip->i_inode.i_mode));
David Teiglandb3b94fa2006-01-16 16:50:04 +0000961 if (error)
962 goto out_end_trans;
963
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400964out_end_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000965 gfs2_trans_end(sdp);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400966out_ipreserv:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000967 if (alloc_required)
968 gfs2_inplace_release(ndip);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400969out_gunlock_q:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000970 if (alloc_required)
971 gfs2_quota_unlock(ndip);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400972out_alloc:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000973 if (alloc_required)
974 gfs2_alloc_put(ndip);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400975out_gunlock:
Bob Peterson72dbf472008-08-12 13:39:29 -0500976 while (x--) {
977 gfs2_glock_dq(ghs + x);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000978 gfs2_holder_uninit(ghs + x);
Bob Peterson72dbf472008-08-12 13:39:29 -0500979 }
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400980out_gunlock_r:
Steven Whitehouse0188d6c2008-08-26 09:38:26 +0100981 if (r_gh.gh_gl)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000982 gfs2_glock_dq_uninit(&r_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400983out:
Bob Peterson462903412010-09-30 10:34:00 -0400984 gfs2_glock_dq_uninit(&ri_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000985 return error;
986}
987
988/**
David Teiglandb3b94fa2006-01-16 16:50:04 +0000989 * gfs2_follow_link - Follow a symbolic link
990 * @dentry: The dentry of the link
991 * @nd: Data that we pass to vfs_follow_link()
992 *
Al Viroc177c2a2010-01-14 00:59:16 -0500993 * This can handle symlinks of any size.
David Teiglandb3b94fa2006-01-16 16:50:04 +0000994 *
995 * Returns: 0 on success or error code
996 */
997
998static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
999{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001000 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
Al Viroc177c2a2010-01-14 00:59:16 -05001001 struct gfs2_holder i_gh;
1002 struct buffer_head *dibh;
Steven Whitehousea2e0f792010-08-11 09:53:11 +01001003 unsigned int x, size;
Al Viroc177c2a2010-01-14 00:59:16 -05001004 char *buf;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001005 int error;
1006
Al Viroc177c2a2010-01-14 00:59:16 -05001007 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
1008 error = gfs2_glock_nq(&i_gh);
1009 if (error) {
1010 gfs2_holder_uninit(&i_gh);
1011 nd_set_link(nd, ERR_PTR(error));
1012 return NULL;
1013 }
David Teiglandb3b94fa2006-01-16 16:50:04 +00001014
Steven Whitehousea2e0f792010-08-11 09:53:11 +01001015 size = (unsigned int)i_size_read(&ip->i_inode);
1016 if (size == 0) {
Al Viroc177c2a2010-01-14 00:59:16 -05001017 gfs2_consist_inode(ip);
1018 buf = ERR_PTR(-EIO);
1019 goto out;
1020 }
1021
1022 error = gfs2_meta_inode_buffer(ip, &dibh);
1023 if (error) {
1024 buf = ERR_PTR(error);
1025 goto out;
1026 }
1027
Steven Whitehousea2e0f792010-08-11 09:53:11 +01001028 x = size + 1;
Al Viroc177c2a2010-01-14 00:59:16 -05001029 buf = kmalloc(x, GFP_NOFS);
1030 if (!buf)
1031 buf = ERR_PTR(-ENOMEM);
1032 else
1033 memcpy(buf, dibh->b_data + sizeof(struct gfs2_dinode), x);
1034 brelse(dibh);
1035out:
1036 gfs2_glock_dq_uninit(&i_gh);
1037 nd_set_link(nd, buf);
1038 return NULL;
1039}
1040
1041static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
1042{
1043 char *s = nd_get_link(nd);
1044 if (!IS_ERR(s))
1045 kfree(s);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001046}
1047
1048/**
1049 * gfs2_permission -
Steven Whitehouse75d5cfb2011-01-19 09:42:40 +00001050 * @inode: The inode
1051 * @mask: The mask to be tested
1052 * @flags: Indicates whether this is an RCU path walk or not
David Teiglandb3b94fa2006-01-16 16:50:04 +00001053 *
Steven Whitehouse300c7d72006-11-27 09:55:28 -05001054 * This may be called from the VFS directly, or from within GFS2 with the
1055 * inode locked, so we look to see if the glock is already locked and only
1056 * lock the glock if its not already been done.
1057 *
David Teiglandb3b94fa2006-01-16 16:50:04 +00001058 * Returns: errno
1059 */
1060
Nick Pigginb74c79e2011-01-07 17:49:58 +11001061int gfs2_permission(struct inode *inode, int mask, unsigned int flags)
David Teiglandb3b94fa2006-01-16 16:50:04 +00001062{
Nick Pigginb74c79e2011-01-07 17:49:58 +11001063 struct gfs2_inode *ip;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001064 struct gfs2_holder i_gh;
1065 int error;
Steven Whitehouse300c7d72006-11-27 09:55:28 -05001066 int unlock = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001067
Nick Pigginb74c79e2011-01-07 17:49:58 +11001068
1069 ip = GFS2_I(inode);
Steven Whitehouse7afd88d2008-02-22 16:07:18 +00001070 if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
Steven Whitehouse75d5cfb2011-01-19 09:42:40 +00001071 if (flags & IPERM_FLAG_RCU)
1072 return -ECHILD;
Steven Whitehouse300c7d72006-11-27 09:55:28 -05001073 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
1074 if (error)
1075 return error;
1076 unlock = 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001077 }
1078
Miklos Szeredif58ba882008-07-02 21:12:01 +02001079 if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode))
1080 error = -EACCES;
1081 else
Nick Pigginb74c79e2011-01-07 17:49:58 +11001082 error = generic_permission(inode, mask, flags, gfs2_check_acl);
Steven Whitehouse300c7d72006-11-27 09:55:28 -05001083 if (unlock)
1084 gfs2_glock_dq_uninit(&i_gh);
1085
David Teiglandb3b94fa2006-01-16 16:50:04 +00001086 return error;
1087}
1088
David Teiglandb3b94fa2006-01-16 16:50:04 +00001089static int setattr_chown(struct inode *inode, struct iattr *attr)
1090{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001091 struct gfs2_inode *ip = GFS2_I(inode);
1092 struct gfs2_sbd *sdp = GFS2_SB(inode);
Steven Whitehousecd915492006-09-04 12:49:07 -04001093 u32 ouid, ogid, nuid, ngid;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001094 int error;
1095
Steven Whitehouse2933f922006-11-01 13:23:29 -05001096 ouid = inode->i_uid;
1097 ogid = inode->i_gid;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001098 nuid = attr->ia_uid;
1099 ngid = attr->ia_gid;
1100
1101 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
1102 ouid = nuid = NO_QUOTA_CHANGE;
1103 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
1104 ogid = ngid = NO_QUOTA_CHANGE;
1105
Cyrill Gorcunov182fe5a2008-03-03 21:54:21 +03001106 if (!gfs2_alloc_get(ip))
1107 return -ENOMEM;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001108
1109 error = gfs2_quota_lock(ip, nuid, ngid);
1110 if (error)
1111 goto out_alloc;
1112
1113 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
1114 error = gfs2_quota_check(ip, nuid, ngid);
1115 if (error)
1116 goto out_gunlock_q;
1117 }
1118
1119 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
1120 if (error)
1121 goto out_gunlock_q;
1122
Steven Whitehouse2ae51ed2010-11-10 15:14:57 +00001123 error = gfs2_setattr_simple(ip, attr);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001124 if (error)
1125 goto out_end_trans;
1126
David Teiglandb3b94fa2006-01-16 16:50:04 +00001127 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
Steven Whitehouse77658aa2008-02-12 14:17:27 +00001128 u64 blocks = gfs2_get_inode_blocks(&ip->i_inode);
1129 gfs2_quota_change(ip, -blocks, ouid, ogid);
1130 gfs2_quota_change(ip, blocks, nuid, ngid);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001131 }
1132
Steven Whitehousea91ea692006-09-04 12:04:26 -04001133out_end_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001134 gfs2_trans_end(sdp);
Steven Whitehousea91ea692006-09-04 12:04:26 -04001135out_gunlock_q:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001136 gfs2_quota_unlock(ip);
Steven Whitehousea91ea692006-09-04 12:04:26 -04001137out_alloc:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001138 gfs2_alloc_put(ip);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001139 return error;
1140}
1141
1142/**
1143 * gfs2_setattr - Change attributes on an inode
1144 * @dentry: The dentry which is changing
1145 * @attr: The structure describing the change
1146 *
1147 * The VFS layer wants to change one or more of an inodes attributes. Write
1148 * that change out to disk.
1149 *
1150 * Returns: errno
1151 */
1152
1153static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
1154{
1155 struct inode *inode = dentry->d_inode;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001156 struct gfs2_inode *ip = GFS2_I(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001157 struct gfs2_holder i_gh;
1158 int error;
1159
David Teiglandb3b94fa2006-01-16 16:50:04 +00001160 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
1161 if (error)
1162 return error;
1163
1164 error = -EPERM;
1165 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1166 goto out;
1167
1168 error = inode_change_ok(inode, attr);
1169 if (error)
1170 goto out;
1171
1172 if (attr->ia_valid & ATTR_SIZE)
Steven Whitehouseff8f33c2010-08-11 09:37:53 +01001173 error = gfs2_setattr_size(inode, attr->ia_size);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001174 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1175 error = setattr_chown(inode, attr);
1176 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1177 error = gfs2_acl_chmod(ip, attr);
1178 else
1179 error = gfs2_setattr_simple(ip, attr);
1180
Steven Whitehousea91ea692006-09-04 12:04:26 -04001181out:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001182 gfs2_glock_dq_uninit(&i_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001183 if (!error)
1184 mark_inode_dirty(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001185 return error;
1186}
1187
1188/**
1189 * gfs2_getattr - Read out an inode's attributes
Steven Whitehouse26c1a572006-09-04 15:32:10 -04001190 * @mnt: The vfsmount the inode is being accessed from
David Teiglandb3b94fa2006-01-16 16:50:04 +00001191 * @dentry: The dentry to stat
1192 * @stat: The inode's stats
1193 *
Steven Whitehousedcf3dd82006-11-27 10:12:05 -05001194 * This may be called from the VFS directly, or from within GFS2 with the
1195 * inode locked, so we look to see if the glock is already locked and only
1196 * lock the glock if its not already been done. Note that its the NFS
1197 * readdirplus operation which causes this to be called (from filldir)
1198 * with the glock already held.
1199 *
David Teiglandb3b94fa2006-01-16 16:50:04 +00001200 * Returns: errno
1201 */
1202
1203static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1204 struct kstat *stat)
1205{
1206 struct inode *inode = dentry->d_inode;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001207 struct gfs2_inode *ip = GFS2_I(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001208 struct gfs2_holder gh;
1209 int error;
Steven Whitehousedcf3dd82006-11-27 10:12:05 -05001210 int unlock = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001211
Steven Whitehouse7afd88d2008-02-22 16:07:18 +00001212 if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
Steven Whitehousedcf3dd82006-11-27 10:12:05 -05001213 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1214 if (error)
1215 return error;
1216 unlock = 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001217 }
1218
Steven Whitehousedcf3dd82006-11-27 10:12:05 -05001219 generic_fillattr(inode, stat);
Steven Whitehoused7c103d2007-01-25 17:14:59 +00001220 if (unlock)
Steven Whitehousedcf3dd82006-11-27 10:12:05 -05001221 gfs2_glock_dq_uninit(&gh);
1222
1223 return 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001224}
1225
1226static int gfs2_setxattr(struct dentry *dentry, const char *name,
1227 const void *data, size_t size, int flags)
1228{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001229 struct inode *inode = dentry->d_inode;
Steven Whitehouse40b78a32009-08-26 18:41:32 +01001230 struct gfs2_inode *ip = GFS2_I(inode);
1231 struct gfs2_holder gh;
1232 int ret;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001233
Steven Whitehouse40b78a32009-08-26 18:41:32 +01001234 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
1235 ret = gfs2_glock_nq(&gh);
1236 if (ret == 0) {
1237 ret = generic_setxattr(dentry, name, data, size, flags);
1238 gfs2_glock_dq(&gh);
1239 }
1240 gfs2_holder_uninit(&gh);
1241 return ret;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001242}
1243
1244static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1245 void *data, size_t size)
1246{
Steven Whitehouse40b78a32009-08-26 18:41:32 +01001247 struct inode *inode = dentry->d_inode;
1248 struct gfs2_inode *ip = GFS2_I(inode);
1249 struct gfs2_holder gh;
1250 int ret;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001251
Steven Whitehouse40b78a32009-08-26 18:41:32 +01001252 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1253 ret = gfs2_glock_nq(&gh);
1254 if (ret == 0) {
1255 ret = generic_getxattr(dentry, name, data, size);
1256 gfs2_glock_dq(&gh);
1257 }
1258 gfs2_holder_uninit(&gh);
1259 return ret;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001260}
1261
1262static int gfs2_removexattr(struct dentry *dentry, const char *name)
1263{
Steven Whitehouse40b78a32009-08-26 18:41:32 +01001264 struct inode *inode = dentry->d_inode;
1265 struct gfs2_inode *ip = GFS2_I(inode);
1266 struct gfs2_holder gh;
1267 int ret;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001268
Steven Whitehouse40b78a32009-08-26 18:41:32 +01001269 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
1270 ret = gfs2_glock_nq(&gh);
1271 if (ret == 0) {
1272 ret = generic_removexattr(dentry, name);
1273 gfs2_glock_dq(&gh);
1274 }
1275 gfs2_holder_uninit(&gh);
1276 return ret;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001277}
1278
Steven Whitehousee9079cc2008-10-14 14:43:29 +01001279static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
1280 u64 start, u64 len)
1281{
1282 struct gfs2_inode *ip = GFS2_I(inode);
1283 struct gfs2_holder gh;
1284 int ret;
1285
1286 ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC);
1287 if (ret)
1288 return ret;
1289
1290 mutex_lock(&inode->i_mutex);
1291
1292 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
1293 if (ret)
1294 goto out;
1295
1296 if (gfs2_is_stuffed(ip)) {
1297 u64 phys = ip->i_no_addr << inode->i_blkbits;
1298 u64 size = i_size_read(inode);
1299 u32 flags = FIEMAP_EXTENT_LAST|FIEMAP_EXTENT_NOT_ALIGNED|
1300 FIEMAP_EXTENT_DATA_INLINE;
1301 phys += sizeof(struct gfs2_dinode);
1302 phys += start;
1303 if (start + len > size)
1304 len = size - start;
1305 if (start < size)
1306 ret = fiemap_fill_next_extent(fieinfo, start, phys,
1307 len, flags);
1308 if (ret == 1)
1309 ret = 0;
1310 } else {
1311 ret = __generic_block_fiemap(inode, fieinfo, start, len,
1312 gfs2_block_map);
1313 }
1314
1315 gfs2_glock_dq_uninit(&gh);
1316out:
1317 mutex_unlock(&inode->i_mutex);
1318 return ret;
1319}
1320
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -08001321const struct inode_operations gfs2_file_iops = {
Al Viroe6305c42008-07-15 21:03:57 -04001322 .permission = gfs2_permission,
David Teiglandb3b94fa2006-01-16 16:50:04 +00001323 .setattr = gfs2_setattr,
1324 .getattr = gfs2_getattr,
1325 .setxattr = gfs2_setxattr,
1326 .getxattr = gfs2_getxattr,
1327 .listxattr = gfs2_listxattr,
1328 .removexattr = gfs2_removexattr,
Steven Whitehousee9079cc2008-10-14 14:43:29 +01001329 .fiemap = gfs2_fiemap,
David Teiglandb3b94fa2006-01-16 16:50:04 +00001330};
1331
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -08001332const struct inode_operations gfs2_dir_iops = {
David Teiglandb3b94fa2006-01-16 16:50:04 +00001333 .create = gfs2_create,
1334 .lookup = gfs2_lookup,
1335 .link = gfs2_link,
1336 .unlink = gfs2_unlink,
1337 .symlink = gfs2_symlink,
1338 .mkdir = gfs2_mkdir,
1339 .rmdir = gfs2_rmdir,
1340 .mknod = gfs2_mknod,
1341 .rename = gfs2_rename,
Al Viroe6305c42008-07-15 21:03:57 -04001342 .permission = gfs2_permission,
David Teiglandb3b94fa2006-01-16 16:50:04 +00001343 .setattr = gfs2_setattr,
1344 .getattr = gfs2_getattr,
1345 .setxattr = gfs2_setxattr,
1346 .getxattr = gfs2_getxattr,
1347 .listxattr = gfs2_listxattr,
1348 .removexattr = gfs2_removexattr,
Steven Whitehousee9079cc2008-10-14 14:43:29 +01001349 .fiemap = gfs2_fiemap,
David Teiglandb3b94fa2006-01-16 16:50:04 +00001350};
1351
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -08001352const struct inode_operations gfs2_symlink_iops = {
Al Viroc177c2a2010-01-14 00:59:16 -05001353 .readlink = generic_readlink,
David Teiglandb3b94fa2006-01-16 16:50:04 +00001354 .follow_link = gfs2_follow_link,
Al Viroc177c2a2010-01-14 00:59:16 -05001355 .put_link = gfs2_put_link,
Al Viroe6305c42008-07-15 21:03:57 -04001356 .permission = gfs2_permission,
David Teiglandb3b94fa2006-01-16 16:50:04 +00001357 .setattr = gfs2_setattr,
1358 .getattr = gfs2_getattr,
1359 .setxattr = gfs2_setxattr,
1360 .getxattr = gfs2_getxattr,
1361 .listxattr = gfs2_listxattr,
1362 .removexattr = gfs2_removexattr,
Steven Whitehousee9079cc2008-10-14 14:43:29 +01001363 .fiemap = gfs2_fiemap,
David Teiglandb3b94fa2006-01-16 16:50:04 +00001364};
1365