blob: 6d5c6bbec41613db654d59e38055649f92a2651f [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehousef2741d92011-05-13 12:11:17 +01003 * Copyright (C) 2004-2011 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>
Steven Whitehouse194c0112011-05-09 14:06:38 +010021#include <linux/security.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000022#include <asm/uaccess.h>
23
24#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050025#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000026#include "acl.h"
27#include "bmap.h"
28#include "dir.h"
Steven Whitehouse307cf6e2009-08-26 18:51:04 +010029#include "xattr.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000030#include "glock.h"
31#include "inode.h"
32#include "meta_io.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000033#include "quota.h"
34#include "rgrp.h"
35#include "trans.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050036#include "util.h"
Steven Whitehouseb2760582008-10-14 16:05:55 +010037#include "super.h"
Steven Whitehouse194c0112011-05-09 14:06:38 +010038#include "glops.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000039
Bob Petersonff342452015-03-27 08:25:41 -050040struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr)
Steven Whitehouse194c0112011-05-09 14:06:38 +010041{
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -050042 struct inode *inode;
43
44repeat:
45 inode = ilookup(sb, no_addr);
46 if (!inode)
47 return inode;
48 if (is_bad_inode(inode)) {
49 iput(inode);
50 goto repeat;
51 }
52 return inode;
53}
54
55static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr)
56{
57 struct inode *inode;
58
59repeat:
60 inode = iget_locked(sb, no_addr);
61 if (!inode)
62 return inode;
63 if (is_bad_inode(inode)) {
64 iput(inode);
65 goto repeat;
66 }
67 GFS2_I(inode)->i_no_addr = no_addr;
68 return inode;
Steven Whitehouse194c0112011-05-09 14:06:38 +010069}
70
71/**
72 * gfs2_set_iop - Sets inode operations
73 * @inode: The inode with correct i_mode filled in
74 *
75 * GFS2 lookup code fills in vfs inode contents based on info obtained
76 * from directory entry inside gfs2_inode_lookup().
77 */
78
79static void gfs2_set_iop(struct inode *inode)
80{
81 struct gfs2_sbd *sdp = GFS2_SB(inode);
82 umode_t mode = inode->i_mode;
83
84 if (S_ISREG(mode)) {
85 inode->i_op = &gfs2_file_iops;
86 if (gfs2_localflocks(sdp))
87 inode->i_fop = &gfs2_file_fops_nolock;
88 else
89 inode->i_fop = &gfs2_file_fops;
90 } else if (S_ISDIR(mode)) {
91 inode->i_op = &gfs2_dir_iops;
92 if (gfs2_localflocks(sdp))
93 inode->i_fop = &gfs2_dir_fops_nolock;
94 else
95 inode->i_fop = &gfs2_dir_fops;
96 } else if (S_ISLNK(mode)) {
97 inode->i_op = &gfs2_symlink_iops;
98 } else {
99 inode->i_op = &gfs2_file_iops;
100 init_special_inode(inode, inode->i_mode, inode->i_rdev);
101 }
102}
103
104/**
105 * gfs2_inode_lookup - Lookup an inode
106 * @sb: The super block
Steven Whitehouse194c0112011-05-09 14:06:38 +0100107 * @type: The type of the inode
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500108 * @no_addr: The inode number
109 * @no_formal_ino: The inode generation number
110 * @blktype: Requested block type (GFS2_BLKST_DINODE or GFS2_BLKST_UNLINKED;
111 * GFS2_BLKST_FREE do indicate not to verify)
112 *
113 * If @type is DT_UNKNOWN, the inode type is fetched from disk.
114 *
115 * If @blktype is anything other than GFS2_BLKST_FREE (which is used as a
116 * placeholder because it doesn't otherwise make sense), the on-disk block type
117 * is verified to be @blktype.
Steven Whitehouse194c0112011-05-09 14:06:38 +0100118 *
119 * Returns: A VFS inode, or an error
120 */
121
122struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500123 u64 no_addr, u64 no_formal_ino,
124 unsigned int blktype)
Steven Whitehouse194c0112011-05-09 14:06:38 +0100125{
126 struct inode *inode;
127 struct gfs2_inode *ip;
128 struct gfs2_glock *io_gl = NULL;
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500129 struct gfs2_holder i_gh;
130 bool unlock = false;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100131 int error;
132
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500133 inode = gfs2_iget(sb, no_addr);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100134 if (!inode)
Steven Whitehouseac3beb62014-01-16 10:31:13 +0000135 return ERR_PTR(-ENOMEM);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100136
Bob Petersone97321f2016-04-12 16:14:26 -0400137 ip = GFS2_I(inode);
Bob Petersone97321f2016-04-12 16:14:26 -0400138
Steven Whitehouse194c0112011-05-09 14:06:38 +0100139 if (inode->i_state & I_NEW) {
140 struct gfs2_sbd *sdp = GFS2_SB(inode);
141 ip->i_no_formal_ino = no_formal_ino;
142
143 error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
144 if (unlikely(error))
145 goto fail;
146 ip->i_gl->gl_object = ip;
147
148 error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
149 if (unlikely(error))
150 goto fail_put;
151
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500152 if (type == DT_UNKNOWN || blktype != GFS2_BLKST_FREE) {
153 /*
154 * The GL_SKIP flag indicates to skip reading the inode
155 * block. We read the inode with gfs2_inode_refresh
156 * after possibly checking the block type.
157 */
158 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE,
159 GL_SKIP, &i_gh);
160 if (error)
161 goto fail_put;
162 unlock = true;
163
164 if (blktype != GFS2_BLKST_FREE) {
165 error = gfs2_check_blk_type(sdp, no_addr,
166 blktype);
167 if (error)
168 goto fail_put;
169 }
170 }
171
Steven Whitehouse194c0112011-05-09 14:06:38 +0100172 set_bit(GIF_INVALID, &ip->i_flags);
173 error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
174 if (unlikely(error))
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500175 goto fail_put;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100176
177 ip->i_iopen_gh.gh_gl->gl_object = ip;
178 gfs2_glock_put(io_gl);
179 io_gl = NULL;
180
181 if (type == DT_UNKNOWN) {
182 /* Inode glock must be locked already */
183 error = gfs2_inode_refresh(GFS2_I(inode));
184 if (error)
185 goto fail_refresh;
186 } else {
187 inode->i_mode = DT2IF(type);
188 }
189
190 gfs2_set_iop(inode);
191 unlock_new_inode(inode);
192 }
193
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500194 if (unlock)
195 gfs2_glock_dq_uninit(&i_gh);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100196 return inode;
197
198fail_refresh:
Bob Petersona6a4d982013-05-29 11:51:52 -0400199 ip->i_iopen_gh.gh_flags |= GL_NOCACHE;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100200 ip->i_iopen_gh.gh_gl->gl_object = NULL;
Bob Peterson86d067a2015-12-07 15:10:42 -0600201 gfs2_glock_dq_wait(&ip->i_iopen_gh);
202 gfs2_holder_uninit(&ip->i_iopen_gh);
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500203fail_put:
Steven Whitehouse194c0112011-05-09 14:06:38 +0100204 if (io_gl)
205 gfs2_glock_put(io_gl);
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500206 if (unlock)
207 gfs2_glock_dq_uninit(&i_gh);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100208 ip->i_gl->gl_object = NULL;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100209fail:
210 iget_failed(inode);
211 return ERR_PTR(error);
212}
213
214struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
215 u64 *no_formal_ino, unsigned int blktype)
216{
217 struct super_block *sb = sdp->sd_vfs;
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500218 struct inode *inode;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100219 int error;
220
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500221 inode = gfs2_inode_lookup(sb, DT_UNKNOWN, no_addr, 0, blktype);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100222 if (IS_ERR(inode))
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500223 return inode;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100224
225 /* Two extra checks for NFS only */
226 if (no_formal_ino) {
227 error = -ESTALE;
228 if (GFS2_I(inode)->i_no_formal_ino != *no_formal_ino)
229 goto fail_iput;
230
231 error = -EIO;
232 if (GFS2_I(inode)->i_diskflags & GFS2_DIF_SYSTEM)
233 goto fail_iput;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100234 }
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500235 return inode;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100236
Steven Whitehouse194c0112011-05-09 14:06:38 +0100237fail_iput:
238 iput(inode);
Andreas Gruenbacher3ce37b22016-06-14 12:22:27 -0500239 return ERR_PTR(error);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100240}
241
242
243struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
244{
245 struct qstr qstr;
246 struct inode *inode;
247 gfs2_str2qstr(&qstr, name);
248 inode = gfs2_lookupi(dip, &qstr, 1);
249 /* gfs2_lookupi has inconsistent callers: vfs
250 * related routines expect NULL for no entry found,
251 * gfs2_lookup_simple callers expect ENOENT
252 * and do not check for NULL.
253 */
254 if (inode == NULL)
255 return ERR_PTR(-ENOENT);
256 else
257 return inode;
258}
259
260
261/**
262 * gfs2_lookupi - Look up a filename in a directory and return its inode
263 * @d_gh: An initialized holder for the directory glock
264 * @name: The name of the inode to look for
265 * @is_root: If 1, ignore the caller's permissions
266 * @i_gh: An uninitialized holder for the new inode glock
267 *
268 * This can be called via the VFS filldir function when NFS is doing
269 * a readdirplus and the inode which its intending to stat isn't
270 * already in cache. In this case we must not take the directory glock
271 * again, since the readdir call will have already taken that lock.
272 *
273 * Returns: errno
274 */
275
276struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
277 int is_root)
278{
279 struct super_block *sb = dir->i_sb;
280 struct gfs2_inode *dip = GFS2_I(dir);
281 struct gfs2_holder d_gh;
282 int error = 0;
283 struct inode *inode = NULL;
284 int unlock = 0;
285
286 if (!name->len || name->len > GFS2_FNAMESIZE)
287 return ERR_PTR(-ENAMETOOLONG);
288
289 if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) ||
290 (name->len == 2 && memcmp(name->name, "..", 2) == 0 &&
David Howells2b0143b2015-03-17 22:25:59 +0000291 dir == d_inode(sb->s_root))) {
Steven Whitehouse194c0112011-05-09 14:06:38 +0100292 igrab(dir);
293 return dir;
294 }
295
296 if (gfs2_glock_is_locked_by_me(dip->i_gl) == NULL) {
297 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
298 if (error)
299 return ERR_PTR(error);
300 unlock = 1;
301 }
302
303 if (!is_root) {
Al Viro10556cb2011-06-20 19:28:19 -0400304 error = gfs2_permission(dir, MAY_EXEC);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100305 if (error)
306 goto out;
307 }
308
Steven Whitehouse5a00f3c2013-06-11 13:45:29 +0100309 inode = gfs2_dir_search(dir, name, false);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100310 if (IS_ERR(inode))
311 error = PTR_ERR(inode);
312out:
313 if (unlock)
314 gfs2_glock_dq_uninit(&d_gh);
315 if (error == -ENOENT)
316 return NULL;
317 return inode ? inode : ERR_PTR(error);
318}
319
320/**
321 * create_ok - OK to create a new on-disk inode here?
322 * @dip: Directory in which dinode is to be created
323 * @name: Name of new dinode
324 * @mode:
325 *
326 * Returns: errno
327 */
328
329static int create_ok(struct gfs2_inode *dip, const struct qstr *name,
Al Viro175a4eb2011-07-26 03:30:54 -0400330 umode_t mode)
Steven Whitehouse194c0112011-05-09 14:06:38 +0100331{
332 int error;
333
Al Viro10556cb2011-06-20 19:28:19 -0400334 error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100335 if (error)
336 return error;
337
338 /* Don't create entries in an unlinked directory */
339 if (!dip->i_inode.i_nlink)
340 return -ENOENT;
341
Steven Whitehouse194c0112011-05-09 14:06:38 +0100342 if (dip->i_entries == (u32)-1)
343 return -EFBIG;
344 if (S_ISDIR(mode) && dip->i_inode.i_nlink == (u32)-1)
345 return -EMLINK;
346
347 return 0;
348}
349
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000350static void munge_mode_uid_gid(const struct gfs2_inode *dip,
351 struct inode *inode)
Steven Whitehouse194c0112011-05-09 14:06:38 +0100352{
353 if (GFS2_SB(&dip->i_inode)->sd_args.ar_suiddir &&
Eric W. Biederman6b24c0d2013-01-31 21:56:13 -0800354 (dip->i_inode.i_mode & S_ISUID) &&
355 !uid_eq(dip->i_inode.i_uid, GLOBAL_ROOT_UID)) {
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000356 if (S_ISDIR(inode->i_mode))
357 inode->i_mode |= S_ISUID;
Eric W. Biederman6b24c0d2013-01-31 21:56:13 -0800358 else if (!uid_eq(dip->i_inode.i_uid, current_fsuid()))
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000359 inode->i_mode &= ~07111;
360 inode->i_uid = dip->i_inode.i_uid;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100361 } else
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000362 inode->i_uid = current_fsuid();
Steven Whitehouse194c0112011-05-09 14:06:38 +0100363
364 if (dip->i_inode.i_mode & S_ISGID) {
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000365 if (S_ISDIR(inode->i_mode))
366 inode->i_mode |= S_ISGID;
367 inode->i_gid = dip->i_inode.i_gid;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100368 } else
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000369 inode->i_gid = current_fsgid();
Steven Whitehouse194c0112011-05-09 14:06:38 +0100370}
371
Steven Whitehouseb2c8b3e2014-02-04 15:45:11 +0000372static int alloc_dinode(struct gfs2_inode *ip, u32 flags, unsigned *dblocks)
Steven Whitehouse194c0112011-05-09 14:06:38 +0100373{
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000374 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
Steven Whitehouseb2c8b3e2014-02-04 15:45:11 +0000375 struct gfs2_alloc_parms ap = { .target = *dblocks, .aflags = flags, };
Steven Whitehouse194c0112011-05-09 14:06:38 +0100376 int error;
377
Abhi Dasb8fbf472015-03-18 12:03:41 -0500378 error = gfs2_quota_lock_check(ip, &ap);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100379 if (error)
380 goto out;
381
Steven Whitehouse7b9cff42013-10-02 11:13:25 +0100382 error = gfs2_inplace_reserve(ip, &ap);
Steven Whitehousefd4b4e02013-02-26 16:15:20 +0000383 if (error)
384 goto out_quota;
385
Steven Whitehouseb2c8b3e2014-02-04 15:45:11 +0000386 error = gfs2_trans_begin(sdp, (*dblocks * RES_RG_BIT) + RES_STATFS + RES_QUOTA, 0);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100387 if (error)
388 goto out_ipreserv;
389
Steven Whitehouseb2c8b3e2014-02-04 15:45:11 +0000390 error = gfs2_alloc_blocks(ip, &ip->i_no_addr, dblocks, 1, &ip->i_generation);
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000391 ip->i_no_formal_ino = ip->i_generation;
392 ip->i_inode.i_ino = ip->i_no_addr;
393 ip->i_goal = ip->i_no_addr;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100394
395 gfs2_trans_end(sdp);
396
397out_ipreserv:
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000398 gfs2_inplace_release(ip);
Steven Whitehousefd4b4e02013-02-26 16:15:20 +0000399out_quota:
400 gfs2_quota_unlock(ip);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100401out:
Steven Whitehouse194c0112011-05-09 14:06:38 +0100402 return error;
403}
404
Steven Whitehousef2741d92011-05-13 12:11:17 +0100405static void gfs2_init_dir(struct buffer_head *dibh,
406 const struct gfs2_inode *parent)
Steven Whitehousee2d0a132011-05-13 09:55:55 +0100407{
408 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
409 struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
410
411 gfs2_qstr2dirent(&gfs2_qdot, GFS2_DIRENT_SIZE(gfs2_qdot.len), dent);
412 dent->de_inum = di->di_num; /* already GFS2 endian */
413 dent->de_type = cpu_to_be16(DT_DIR);
414
415 dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
416 gfs2_qstr2dirent(&gfs2_qdotdot, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
417 gfs2_inum_out(parent, dent);
418 dent->de_type = cpu_to_be16(DT_DIR);
419
420}
421
Steven Whitehouse194c0112011-05-09 14:06:38 +0100422/**
Steven Whitehouseb2c8b3e2014-02-04 15:45:11 +0000423 * gfs2_init_xattr - Initialise an xattr block for a new inode
424 * @ip: The inode in question
425 *
426 * This sets up an empty xattr block for a new inode, ready to
427 * take any ACLs, LSM xattrs, etc.
428 */
429
430static void gfs2_init_xattr(struct gfs2_inode *ip)
431{
432 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
433 struct buffer_head *bh;
434 struct gfs2_ea_header *ea;
435
436 bh = gfs2_meta_new(ip->i_gl, ip->i_eattr);
437 gfs2_trans_add_meta(ip->i_gl, bh);
438 gfs2_metatype_set(bh, GFS2_METATYPE_EA, GFS2_FORMAT_EA);
439 gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header));
440
441 ea = GFS2_EA_BH2FIRST(bh);
442 ea->ea_rec_len = cpu_to_be32(sdp->sd_jbsize);
443 ea->ea_type = GFS2_EATYPE_UNUSED;
444 ea->ea_flags = GFS2_EAFLAG_LAST;
445
446 brelse(bh);
447}
448
449/**
Steven Whitehouse194c0112011-05-09 14:06:38 +0100450 * init_dinode - Fill in a new dinode structure
Steven Whitehousef2741d92011-05-13 12:11:17 +0100451 * @dip: The directory this inode is being created in
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000452 * @ip: The inode
Steven Whitehousef2741d92011-05-13 12:11:17 +0100453 * @symname: The symlink destination (if a symlink)
Steven Whitehousef2741d92011-05-13 12:11:17 +0100454 * @bhp: The buffer head (returned to caller)
Steven Whitehouse194c0112011-05-09 14:06:38 +0100455 *
456 */
457
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000458static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip,
Steven Whitehouse79ba7482013-03-01 09:29:12 +0000459 const char *symname)
Steven Whitehouse194c0112011-05-09 14:06:38 +0100460{
Steven Whitehouse194c0112011-05-09 14:06:38 +0100461 struct gfs2_dinode *di;
462 struct buffer_head *dibh;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100463
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000464 dibh = gfs2_meta_new(ip->i_gl, ip->i_no_addr);
Steven Whitehouse350a9b02012-12-14 12:36:02 +0000465 gfs2_trans_add_meta(ip->i_gl, dibh);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100466 di = (struct gfs2_dinode *)dibh->b_data;
Steven Whitehouse79ba7482013-03-01 09:29:12 +0000467 gfs2_dinode_out(ip, di);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100468
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000469 di->di_major = cpu_to_be32(MAJOR(ip->i_inode.i_rdev));
470 di->di_minor = cpu_to_be32(MINOR(ip->i_inode.i_rdev));
Steven Whitehouse194c0112011-05-09 14:06:38 +0100471 di->__pad1 = 0;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100472 di->__pad2 = 0;
473 di->__pad3 = 0;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100474 memset(&di->__pad4, 0, sizeof(di->__pad4));
Steven Whitehouse194c0112011-05-09 14:06:38 +0100475 memset(&di->di_reserved, 0, sizeof(di->di_reserved));
Steven Whitehouse79ba7482013-03-01 09:29:12 +0000476 gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
Steven Whitehouse160b4022011-05-13 10:34:59 +0100477
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000478 switch(ip->i_inode.i_mode & S_IFMT) {
Steven Whitehouse160b4022011-05-13 10:34:59 +0100479 case S_IFDIR:
Steven Whitehousee2d0a132011-05-13 09:55:55 +0100480 gfs2_init_dir(dibh, dip);
Steven Whitehouse160b4022011-05-13 10:34:59 +0100481 break;
482 case S_IFLNK:
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000483 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname, ip->i_inode.i_size);
Steven Whitehouse160b4022011-05-13 10:34:59 +0100484 break;
Steven Whitehousee2d0a132011-05-13 09:55:55 +0100485 }
486
Steven Whitehouse194c0112011-05-09 14:06:38 +0100487 set_buffer_uptodate(dibh);
Steven Whitehouse79ba7482013-03-01 09:29:12 +0000488 brelse(dibh);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100489}
490
Steven Whitehouse534cf9c2014-01-06 12:03:05 +0000491/**
492 * gfs2_trans_da_blocks - Calculate number of blocks to link inode
493 * @dip: The directory we are linking into
494 * @da: The dir add information
495 * @nr_inodes: The number of inodes involved
496 *
497 * This calculate the number of blocks we need to reserve in a
498 * transaction to link @nr_inodes into a directory. In most cases
499 * @nr_inodes will be 2 (the directory plus the inode being linked in)
500 * but in case of rename, 4 may be required.
501 *
502 * Returns: Number of blocks
503 */
504
505static unsigned gfs2_trans_da_blks(const struct gfs2_inode *dip,
506 const struct gfs2_diradd *da,
507 unsigned nr_inodes)
508{
509 return da->nr_blocks + gfs2_rg_blocks(dip, da->nr_blocks) +
510 (nr_inodes * RES_DINODE) + RES_QUOTA + RES_STATFS;
511}
512
Steven Whitehouse194c0112011-05-09 14:06:38 +0100513static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +0000514 struct gfs2_inode *ip, struct gfs2_diradd *da)
Steven Whitehouse194c0112011-05-09 14:06:38 +0100515{
516 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +0000517 struct gfs2_alloc_parms ap = { .target = da->nr_blocks, };
Steven Whitehouse194c0112011-05-09 14:06:38 +0100518 int error;
519
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +0000520 if (da->nr_blocks) {
Abhi Dasb8fbf472015-03-18 12:03:41 -0500521 error = gfs2_quota_lock_check(dip, &ap);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100522 if (error)
523 goto fail_quota_locks;
524
Steven Whitehouse7b9cff42013-10-02 11:13:25 +0100525 error = gfs2_inplace_reserve(dip, &ap);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100526 if (error)
527 goto fail_quota_locks;
528
Steven Whitehouse534cf9c2014-01-06 12:03:05 +0000529 error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(dip, da, 2), 0);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100530 if (error)
531 goto fail_ipreserv;
532 } else {
533 error = gfs2_trans_begin(sdp, RES_LEAF + 2 * RES_DINODE, 0);
534 if (error)
535 goto fail_quota_locks;
536 }
537
Steven Whitehouse2b47dad2014-01-06 12:49:43 +0000538 error = gfs2_dir_add(&dip->i_inode, name, ip, da);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100539
Steven Whitehouse194c0112011-05-09 14:06:38 +0100540 gfs2_trans_end(sdp);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100541fail_ipreserv:
Steven Whitehousefd4b4e02013-02-26 16:15:20 +0000542 gfs2_inplace_release(dip);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100543fail_quota_locks:
544 gfs2_quota_unlock(dip);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100545 return error;
546}
547
H Hartley Sweeten46cc1e52011-09-23 15:51:32 -0700548static int gfs2_initxattrs(struct inode *inode, const struct xattr *xattr_array,
Mimi Zohar9d8f13b2011-06-06 15:29:25 -0400549 void *fs_info)
550{
551 const struct xattr *xattr;
552 int err = 0;
553
554 for (xattr = xattr_array; xattr->name != NULL; xattr++) {
555 err = __gfs2_xattr_set(inode, xattr->name, xattr->value,
556 xattr->value_len, 0,
557 GFS2_EATYPE_SECURITY);
558 if (err < 0)
559 break;
560 }
561 return err;
562}
563
Steven Whitehouse194c0112011-05-09 14:06:38 +0100564/**
Steven Whitehousef2741d92011-05-13 12:11:17 +0100565 * gfs2_create_inode - Create a new inode
566 * @dir: The parent directory
567 * @dentry: The new dentry
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100568 * @file: If non-NULL, the file which is being opened
Steven Whitehousef2741d92011-05-13 12:11:17 +0100569 * @mode: The permissions on the new inode
570 * @dev: For device nodes, this is the device number
571 * @symname: For symlinks, this is the link destination
572 * @size: The initial size of the inode (ignored for directories)
Steven Whitehouse194c0112011-05-09 14:06:38 +0100573 *
Steven Whitehousef2741d92011-05-13 12:11:17 +0100574 * Returns: 0 on success, or error code
Steven Whitehouse194c0112011-05-09 14:06:38 +0100575 */
576
Steven Whitehousef2741d92011-05-13 12:11:17 +0100577static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100578 struct file *file,
Al Viro175a4eb2011-07-26 03:30:54 -0400579 umode_t mode, dev_t dev, const char *symname,
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100580 unsigned int size, int excl, int *opened)
Steven Whitehouse194c0112011-05-09 14:06:38 +0100581{
Steven Whitehousef2741d92011-05-13 12:11:17 +0100582 const struct qstr *name = &dentry->d_name;
Christoph Hellwige01580b2013-12-20 05:16:52 -0800583 struct posix_acl *default_acl, *acl;
Steven Whitehousef2741d92011-05-13 12:11:17 +0100584 struct gfs2_holder ghs[2];
Steven Whitehouse194c0112011-05-09 14:06:38 +0100585 struct inode *inode = NULL;
Bob Peterson8e2e0042012-07-19 08:12:40 -0400586 struct gfs2_inode *dip = GFS2_I(dir), *ip;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100587 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
Bob Petersona4923862015-12-07 16:24:27 -0600588 struct gfs2_glock *io_gl = NULL;
Bob Peterson783013c2015-12-04 10:19:14 -0600589 int error, free_vfs_inode = 1;
Steven Whitehouse9dbe9612012-10-31 10:37:10 +0000590 u32 aflags = 0;
Steven Whitehouseb2c8b3e2014-02-04 15:45:11 +0000591 unsigned blocks = 1;
Bob Peterson19aeb5a2014-09-29 08:52:04 -0400592 struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, };
Steven Whitehouse194c0112011-05-09 14:06:38 +0100593
594 if (!name->len || name->len > GFS2_FNAMESIZE)
Steven Whitehousef2741d92011-05-13 12:11:17 +0100595 return -ENAMETOOLONG;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100596
Bob Petersonb54e9a02015-10-26 10:40:28 -0500597 error = gfs2_rsqa_alloc(dip);
Bob Peterson0a305e42012-06-06 11:17:59 +0100598 if (error)
599 return error;
600
Steven Whitehousefd4b4e02013-02-26 16:15:20 +0000601 error = gfs2_rindex_update(sdp);
602 if (error)
603 return error;
604
Steven Whitehousef2741d92011-05-13 12:11:17 +0100605 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100606 if (error)
607 goto fail;
608
609 error = create_ok(dip, name, mode);
610 if (error)
611 goto fail_gunlock;
612
Steven Whitehouse5a00f3c2013-06-11 13:45:29 +0100613 inode = gfs2_dir_search(dir, &dentry->d_name, !S_ISREG(mode) || excl);
614 error = PTR_ERR(inode);
615 if (!IS_ERR(inode)) {
Al Viro571a4b52014-11-19 19:34:49 +0000616 if (S_ISDIR(inode->i_mode)) {
617 iput(inode);
618 inode = ERR_PTR(-EISDIR);
619 goto fail_gunlock;
620 }
Al Viro44bb31b2014-11-19 19:35:24 +0000621 d_instantiate(dentry, inode);
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100622 error = 0;
Miklos Szeredi0d0d1102013-09-16 14:52:00 +0200623 if (file) {
Al Viro44bb31b2014-11-19 19:35:24 +0000624 if (S_ISREG(inode->i_mode))
Miklos Szeredi5ca1db42013-09-23 13:21:04 +0100625 error = finish_open(file, dentry, gfs2_open_common, opened);
Al Viro44bb31b2014-11-19 19:35:24 +0000626 else
627 error = finish_no_open(file, NULL);
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100628 }
Steven Whitehouse5a00f3c2013-06-11 13:45:29 +0100629 gfs2_glock_dq_uninit(ghs);
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100630 return error;
Steven Whitehouse5a00f3c2013-06-11 13:45:29 +0100631 } else if (error != -ENOENT) {
632 goto fail_gunlock;
633 }
634
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +0000635 error = gfs2_diradd_alloc_required(dir, name, &da);
Steven Whitehousefd4b4e02013-02-26 16:15:20 +0000636 if (error < 0)
637 goto fail_gunlock;
638
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000639 inode = new_inode(sdp->sd_vfs);
Steven Whitehousefd4b4e02013-02-26 16:15:20 +0000640 error = -ENOMEM;
641 if (!inode)
642 goto fail_gunlock;
643
Christoph Hellwige01580b2013-12-20 05:16:52 -0800644 error = posix_acl_create(dir, &mode, &default_acl, &acl);
645 if (error)
Bob Peterson783013c2015-12-04 10:19:14 -0600646 goto fail_gunlock;
Christoph Hellwige01580b2013-12-20 05:16:52 -0800647
Bob Peterson8e2e0042012-07-19 08:12:40 -0400648 ip = GFS2_I(inode);
Bob Petersonb54e9a02015-10-26 10:40:28 -0500649 error = gfs2_rsqa_alloc(ip);
Steven Whitehouseff7f4cb2012-09-10 10:03:50 +0100650 if (error)
Christoph Hellwige01580b2013-12-20 05:16:52 -0800651 goto fail_free_acls;
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000652
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000653 inode->i_mode = mode;
Steven Whitehouse79ba7482013-03-01 09:29:12 +0000654 set_nlink(inode, S_ISDIR(mode) ? 2 : 1);
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000655 inode->i_rdev = dev;
656 inode->i_size = size;
Steven Whitehousefd4b4e02013-02-26 16:15:20 +0000657 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
Steven Whitehouse28fb3022013-02-26 19:09:35 +0000658 gfs2_set_inode_blocks(inode, 1);
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000659 munge_mode_uid_gid(dip, inode);
Abhi Das00a158b2014-09-18 21:40:28 -0500660 check_and_update_goal(dip);
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000661 ip->i_goal = dip->i_goal;
Steven Whitehouse28fb3022013-02-26 19:09:35 +0000662 ip->i_diskflags = 0;
663 ip->i_eattr = 0;
664 ip->i_height = 0;
665 ip->i_depth = 0;
666 ip->i_entries = 0;
667
668 switch(mode & S_IFMT) {
669 case S_IFREG:
670 if ((dip->i_diskflags & GFS2_DIF_INHERIT_JDATA) ||
671 gfs2_tune_get(sdp, gt_new_files_jdata))
672 ip->i_diskflags |= GFS2_DIF_JDATA;
673 gfs2_set_aops(inode);
674 break;
675 case S_IFDIR:
676 ip->i_diskflags |= (dip->i_diskflags & GFS2_DIF_INHERIT_JDATA);
677 ip->i_diskflags |= GFS2_DIF_JDATA;
678 ip->i_entries = 2;
679 break;
680 }
Abhi Dasacc546f2015-11-10 15:07:26 -0600681
682 /* Force SYSTEM flag on all files and subdirs of a SYSTEM directory */
683 if (dip->i_diskflags & GFS2_DIF_SYSTEM)
684 ip->i_diskflags |= GFS2_DIF_SYSTEM;
685
Steven Whitehouse28fb3022013-02-26 19:09:35 +0000686 gfs2_set_inode_flags(inode);
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000687
David Howells2b0143b2015-03-17 22:25:59 +0000688 if ((GFS2_I(d_inode(sdp->sd_root_dir)) == dip) ||
Steven Whitehouse9dbe9612012-10-31 10:37:10 +0000689 (dip->i_diskflags & GFS2_DIF_TOPDIR))
690 aflags |= GFS2_AF_ORLOV;
691
Steven Whitehouseb2c8b3e2014-02-04 15:45:11 +0000692 if (default_acl || acl)
693 blocks++;
694
695 error = alloc_dinode(ip, aflags, &blocks);
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000696 if (error)
697 goto fail_free_inode;
698
Steven Whitehouseb2c8b3e2014-02-04 15:45:11 +0000699 gfs2_set_inode_blocks(inode, blocks);
700
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000701 error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
702 if (error)
703 goto fail_free_inode;
704
Bob Peterson1e2d9d42012-11-21 09:56:00 -0500705 ip->i_gl->gl_object = ip;
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000706 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1);
707 if (error)
708 goto fail_free_inode;
709
Steven Whitehouseb2c8b3e2014-02-04 15:45:11 +0000710 error = gfs2_trans_begin(sdp, blocks, 0);
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000711 if (error)
Steven Whitehouseff7f4cb2012-09-10 10:03:50 +0100712 goto fail_gunlock2;
Bob Peterson0a305e42012-06-06 11:17:59 +0100713
Steven Whitehouseb2c8b3e2014-02-04 15:45:11 +0000714 if (blocks > 1) {
715 ip->i_eattr = ip->i_no_addr + 1;
716 gfs2_init_xattr(ip);
717 }
Steven Whitehouse79ba7482013-03-01 09:29:12 +0000718 init_dinode(dip, ip, symname);
Steven Whitehousefd4b4e02013-02-26 16:15:20 +0000719 gfs2_trans_end(sdp);
720
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000721 error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
722 if (error)
723 goto fail_gunlock2;
724
Bob Petersona4923862015-12-07 16:24:27 -0600725 BUG_ON(test_and_set_bit(GLF_INODE_CREATING, &io_gl->gl_flags));
726
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000727 error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
728 if (error)
729 goto fail_gunlock2;
730
731 ip->i_iopen_gh.gh_gl->gl_object = ip;
732 gfs2_glock_put(io_gl);
733 gfs2_set_iop(inode);
734 insert_inode_hash(inode);
735
Bob Peterson783013c2015-12-04 10:19:14 -0600736 free_vfs_inode = 0; /* After this point, the inode is no longer
737 considered free. Any failures need to undo
738 the gfs2 structures. */
Christoph Hellwige01580b2013-12-20 05:16:52 -0800739 if (default_acl) {
Al Viro1a39ba92016-05-13 03:59:17 +0200740 error = __gfs2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
Christoph Hellwige01580b2013-12-20 05:16:52 -0800741 posix_acl_release(default_acl);
742 }
743 if (acl) {
744 if (!error)
Al Viro1a39ba92016-05-13 03:59:17 +0200745 error = __gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
Christoph Hellwige01580b2013-12-20 05:16:52 -0800746 posix_acl_release(acl);
747 }
748
Steven Whitehouse194c0112011-05-09 14:06:38 +0100749 if (error)
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000750 goto fail_gunlock3;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100751
Bob Petersonf45dc262014-03-19 09:37:00 -0400752 error = security_inode_init_security(&ip->i_inode, &dip->i_inode, name,
753 &gfs2_initxattrs, NULL);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100754 if (error)
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000755 goto fail_gunlock3;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100756
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +0000757 error = link_dinode(dip, name, ip, &da);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100758 if (error)
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000759 goto fail_gunlock3;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100760
Steven Whitehouse79ba7482013-03-01 09:29:12 +0000761 mark_inode_dirty(inode);
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100762 d_instantiate(dentry, inode);
Miklos Szeredic5bf8fe2013-09-16 14:52:03 +0200763 if (file) {
764 *opened |= FILE_CREATED;
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100765 error = finish_open(file, dentry, gfs2_open_common, opened);
Miklos Szeredic5bf8fe2013-09-16 14:52:03 +0200766 }
Steven Whitehouse28fb3022013-02-26 19:09:35 +0000767 gfs2_glock_dq_uninit(ghs);
768 gfs2_glock_dq_uninit(ghs + 1);
Bob Petersona4923862015-12-07 16:24:27 -0600769 clear_bit(GLF_INODE_CREATING, &io_gl->gl_flags);
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100770 return error;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100771
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000772fail_gunlock3:
Bob Peterson783013c2015-12-04 10:19:14 -0600773 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
774 gfs2_glock_put(io_gl);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100775fail_gunlock2:
Bob Petersona4923862015-12-07 16:24:27 -0600776 if (io_gl)
777 clear_bit(GLF_INODE_CREATING, &io_gl->gl_flags);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100778 gfs2_glock_dq_uninit(ghs + 1);
Steven Whitehousec9aecf72012-10-31 10:30:22 +0000779fail_free_inode:
780 if (ip->i_gl)
781 gfs2_glock_put(ip->i_gl);
Bob Petersonb54e9a02015-10-26 10:40:28 -0500782 gfs2_rsqa_delete(ip, NULL);
Christoph Hellwige01580b2013-12-20 05:16:52 -0800783fail_free_acls:
784 if (default_acl)
785 posix_acl_release(default_acl);
786 if (acl)
787 posix_acl_release(acl);
Steven Whitehouse194c0112011-05-09 14:06:38 +0100788fail_gunlock:
Steven Whitehouse2b47dad2014-01-06 12:49:43 +0000789 gfs2_dir_no_add(&da);
Steven Whitehousef2741d92011-05-13 12:11:17 +0100790 gfs2_glock_dq_uninit(ghs);
Steven Whitehouse40ac2182011-08-02 13:17:27 +0100791 if (inode && !IS_ERR(inode)) {
Steven Whitehouse79ba7482013-03-01 09:29:12 +0000792 clear_nlink(inode);
Abhi Das05978802014-03-31 10:33:17 -0500793 if (!free_vfs_inode)
794 mark_inode_dirty(inode);
795 set_bit(free_vfs_inode ? GIF_FREE_VFS_INODE : GIF_ALLOC_FAILED,
796 &GFS2_I(inode)->i_flags);
Steven Whitehouse40ac2182011-08-02 13:17:27 +0100797 iput(inode);
798 }
Steven Whitehouse194c0112011-05-09 14:06:38 +0100799fail:
Steven Whitehousef2741d92011-05-13 12:11:17 +0100800 return error;
Steven Whitehouse194c0112011-05-09 14:06:38 +0100801}
Steven Whitehousef2741d92011-05-13 12:11:17 +0100802
David Teiglandb3b94fa2006-01-16 16:50:04 +0000803/**
804 * gfs2_create - Create a file
805 * @dir: The directory in which to create the file
806 * @dentry: The dentry of the new file
807 * @mode: The mode of the new file
808 *
809 * Returns: errno
810 */
811
812static int gfs2_create(struct inode *dir, struct dentry *dentry,
Al Viroebfc3b42012-06-10 18:05:36 -0400813 umode_t mode, bool excl)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000814{
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100815 return gfs2_create_inode(dir, dentry, NULL, S_IFREG | mode, 0, NULL, 0, excl, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000816}
817
818/**
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100819 * __gfs2_lookup - Look up a filename in a directory and return its inode
David Teiglandb3b94fa2006-01-16 16:50:04 +0000820 * @dir: The directory inode
821 * @dentry: The dentry of the new inode
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100822 * @file: File to be opened
823 * @opened: atomic_open flags
David Teiglandb3b94fa2006-01-16 16:50:04 +0000824 *
David Teiglandb3b94fa2006-01-16 16:50:04 +0000825 *
826 * Returns: errno
827 */
828
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100829static struct dentry *__gfs2_lookup(struct inode *dir, struct dentry *dentry,
830 struct file *file, int *opened)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000831{
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100832 struct inode *inode;
833 struct dentry *d;
834 struct gfs2_holder gh;
835 struct gfs2_glock *gl;
836 int error;
837
838 inode = gfs2_lookupi(dir, &dentry->d_name, 0);
Benjamin Coddington7b7a9112014-09-10 14:09:20 -0400839 if (inode == NULL) {
840 d_add(dentry, NULL);
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100841 return NULL;
Benjamin Coddington7b7a9112014-09-10 14:09:20 -0400842 }
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100843 if (IS_ERR(inode))
844 return ERR_CAST(inode);
845
846 gl = GFS2_I(inode)->i_gl;
847 error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
848 if (error) {
849 iput(inode);
850 return ERR_PTR(error);
Steven Whitehouse9656b2c2008-01-08 08:14:30 +0000851 }
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100852
853 d = d_splice_alias(inode, dentry);
J. Bruce Fieldsd57b9c92014-01-16 13:51:07 -0500854 if (IS_ERR(d)) {
J. Bruce Fieldsd57b9c92014-01-16 13:51:07 -0500855 gfs2_glock_dq_uninit(&gh);
856 return d;
857 }
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100858 if (file && S_ISREG(inode->i_mode))
859 error = finish_open(file, dentry, gfs2_open_common, opened);
860
861 gfs2_glock_dq_uninit(&gh);
Miklos Szeredi5ca1db42013-09-23 13:21:04 +0100862 if (error) {
863 dput(d);
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100864 return ERR_PTR(error);
Miklos Szeredi5ca1db42013-09-23 13:21:04 +0100865 }
Steven Whitehouse6d4ade92013-06-14 11:17:15 +0100866 return d;
867}
868
869static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
870 unsigned flags)
871{
872 return __gfs2_lookup(dir, dentry, NULL, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000873}
874
875/**
876 * gfs2_link - Link to a file
877 * @old_dentry: The inode to link
878 * @dir: Add link to this directory
879 * @dentry: The name of the link
880 *
881 * Link the inode in "old_dentry" into the directory "dir" with the
882 * name in "dentry".
883 *
884 * Returns: errno
885 */
886
887static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
888 struct dentry *dentry)
889{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400890 struct gfs2_inode *dip = GFS2_I(dir);
891 struct gfs2_sbd *sdp = GFS2_SB(dir);
David Howells2b0143b2015-03-17 22:25:59 +0000892 struct inode *inode = d_inode(old_dentry);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400893 struct gfs2_inode *ip = GFS2_I(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000894 struct gfs2_holder ghs[2];
Steven Whitehouse2baee032011-05-09 12:08:36 +0100895 struct buffer_head *dibh;
Bob Peterson19aeb5a2014-09-29 08:52:04 -0400896 struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, };
David Teiglandb3b94fa2006-01-16 16:50:04 +0000897 int error;
898
Steven Whitehouseb60623c2006-11-01 12:22:46 -0500899 if (S_ISDIR(inode->i_mode))
David Teiglandb3b94fa2006-01-16 16:50:04 +0000900 return -EPERM;
901
Bob Petersonb54e9a02015-10-26 10:40:28 -0500902 error = gfs2_rsqa_alloc(dip);
Bob Peterson0a305e42012-06-06 11:17:59 +0100903 if (error)
904 return error;
905
David Teiglandb3b94fa2006-01-16 16:50:04 +0000906 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
907 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
908
Bob Peterson72dbf472008-08-12 13:39:29 -0500909 error = gfs2_glock_nq(ghs); /* parent */
David Teiglandb3b94fa2006-01-16 16:50:04 +0000910 if (error)
Bob Peterson72dbf472008-08-12 13:39:29 -0500911 goto out_parent;
912
913 error = gfs2_glock_nq(ghs + 1); /* child */
914 if (error)
915 goto out_child;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000916
Steven Whitehoused192a8e2011-05-05 12:35:40 +0100917 error = -ENOENT;
918 if (inode->i_nlink == 0)
919 goto out_gunlock;
920
Al Viro10556cb2011-06-20 19:28:19 -0400921 error = gfs2_permission(dir, MAY_WRITE | MAY_EXEC);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000922 if (error)
923 goto out_gunlock;
924
Steven Whitehousedbb7cae2007-05-15 15:37:50 +0100925 error = gfs2_dir_check(dir, &dentry->d_name, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000926 switch (error) {
927 case -ENOENT:
928 break;
929 case 0:
930 error = -EEXIST;
931 default:
932 goto out_gunlock;
933 }
934
935 error = -EINVAL;
Steven Whitehouse4f561102006-11-01 14:04:17 -0500936 if (!dip->i_inode.i_nlink)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000937 goto out_gunlock;
938 error = -EFBIG;
Steven Whitehousead6203f2008-11-03 13:59:19 +0000939 if (dip->i_entries == (u32)-1)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000940 goto out_gunlock;
941 error = -EPERM;
942 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
943 goto out_gunlock;
944 error = -EINVAL;
Steven Whitehouse4f561102006-11-01 14:04:17 -0500945 if (!ip->i_inode.i_nlink)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000946 goto out_gunlock;
947 error = -EMLINK;
Steven Whitehouse4f561102006-11-01 14:04:17 -0500948 if (ip->i_inode.i_nlink == (u32)-1)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000949 goto out_gunlock;
950
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +0000951 error = gfs2_diradd_alloc_required(dir, &dentry->d_name, &da);
Steven Whitehousec7526662006-03-20 12:30:04 -0500952 if (error < 0)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000953 goto out_gunlock;
954
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +0000955 if (da.nr_blocks) {
956 struct gfs2_alloc_parms ap = { .target = da.nr_blocks, };
Abhi Dasb8fbf472015-03-18 12:03:41 -0500957 error = gfs2_quota_lock_check(dip, &ap);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000958 if (error)
Bob Peterson5407e242012-05-18 09:28:23 -0400959 goto out_gunlock;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000960
Steven Whitehouse7b9cff42013-10-02 11:13:25 +0100961 error = gfs2_inplace_reserve(dip, &ap);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000962 if (error)
963 goto out_gunlock_q;
964
Steven Whitehouse534cf9c2014-01-06 12:03:05 +0000965 error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(dip, &da, 2), 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000966 if (error)
967 goto out_ipres;
968 } else {
969 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
970 if (error)
971 goto out_ipres;
972 }
973
Steven Whitehouse2baee032011-05-09 12:08:36 +0100974 error = gfs2_meta_inode_buffer(ip, &dibh);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000975 if (error)
976 goto out_end_trans;
977
Steven Whitehouse2b47dad2014-01-06 12:49:43 +0000978 error = gfs2_dir_add(dir, &dentry->d_name, ip, &da);
Steven Whitehouse2baee032011-05-09 12:08:36 +0100979 if (error)
980 goto out_brelse;
David Teiglandb3b94fa2006-01-16 16:50:04 +0000981
Steven Whitehouse350a9b02012-12-14 12:36:02 +0000982 gfs2_trans_add_meta(ip->i_gl, dibh);
Steven Whitehouse2baee032011-05-09 12:08:36 +0100983 inc_nlink(&ip->i_inode);
984 ip->i_inode.i_ctime = CURRENT_TIME;
Steven Whitehouseab9bbda2011-08-15 14:20:36 +0100985 ihold(inode);
986 d_instantiate(dentry, inode);
987 mark_inode_dirty(inode);
Steven Whitehouse2baee032011-05-09 12:08:36 +0100988
989out_brelse:
990 brelse(dibh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400991out_end_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000992 gfs2_trans_end(sdp);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400993out_ipres:
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +0000994 if (da.nr_blocks)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000995 gfs2_inplace_release(dip);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400996out_gunlock_q:
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +0000997 if (da.nr_blocks)
David Teiglandb3b94fa2006-01-16 16:50:04 +0000998 gfs2_quota_unlock(dip);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -0400999out_gunlock:
Steven Whitehouse2b47dad2014-01-06 12:49:43 +00001000 gfs2_dir_no_add(&da);
Bob Peterson72dbf472008-08-12 13:39:29 -05001001 gfs2_glock_dq(ghs + 1);
1002out_child:
1003 gfs2_glock_dq(ghs);
1004out_parent:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001005 gfs2_holder_uninit(ghs);
1006 gfs2_holder_uninit(ghs + 1);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001007 return error;
1008}
1009
Steven Whitehouse87ec2172009-05-22 10:54:50 +01001010/*
1011 * gfs2_unlink_ok - check to see that a inode is still in a directory
1012 * @dip: the directory
1013 * @name: the name of the file
1014 * @ip: the inode
1015 *
1016 * Assumes that the lock on (at least) @dip is held.
1017 *
1018 * Returns: 0 if the parent/child relationship is correct, errno if it isn't
1019 */
1020
1021static int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
1022 const struct gfs2_inode *ip)
1023{
1024 int error;
1025
1026 if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode))
1027 return -EPERM;
1028
1029 if ((dip->i_inode.i_mode & S_ISVTX) &&
Eric W. Biederman6b24c0d2013-01-31 21:56:13 -08001030 !uid_eq(dip->i_inode.i_uid, current_fsuid()) &&
1031 !uid_eq(ip->i_inode.i_uid, current_fsuid()) && !capable(CAP_FOWNER))
Steven Whitehouse87ec2172009-05-22 10:54:50 +01001032 return -EPERM;
1033
1034 if (IS_APPEND(&dip->i_inode))
1035 return -EPERM;
1036
Al Viro10556cb2011-06-20 19:28:19 -04001037 error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
Steven Whitehouse87ec2172009-05-22 10:54:50 +01001038 if (error)
1039 return error;
1040
Fabian Frederick37975f12014-10-09 22:49:21 +02001041 return gfs2_dir_check(&dip->i_inode, name, ip);
Steven Whitehouse87ec2172009-05-22 10:54:50 +01001042}
1043
David Teiglandb3b94fa2006-01-16 16:50:04 +00001044/**
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001045 * gfs2_unlink_inode - Removes an inode from its parent dir and unlinks it
1046 * @dip: The parent directory
1047 * @name: The name of the entry in the parent directory
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001048 * @inode: The inode to be removed
1049 *
1050 * Called with all the locks and in a transaction. This will only be
1051 * called for a directory after it has been checked to ensure it is empty.
1052 *
1053 * Returns: 0 on success, or an error
1054 */
1055
1056static int gfs2_unlink_inode(struct gfs2_inode *dip,
Bob Peterson4327a9b2012-11-12 13:03:29 -05001057 const struct dentry *dentry)
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001058{
David Howells2b0143b2015-03-17 22:25:59 +00001059 struct inode *inode = d_inode(dentry);
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001060 struct gfs2_inode *ip = GFS2_I(inode);
1061 int error;
1062
1063 error = gfs2_dir_del(dip, dentry);
1064 if (error)
1065 return error;
1066
1067 ip->i_entries = 0;
1068 inode->i_ctime = CURRENT_TIME;
1069 if (S_ISDIR(inode->i_mode))
1070 clear_nlink(inode);
1071 else
1072 drop_nlink(inode);
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001073 mark_inode_dirty(inode);
1074 if (inode->i_nlink == 0)
1075 gfs2_unlink_di(inode);
1076 return 0;
1077}
1078
1079
1080/**
1081 * gfs2_unlink - Unlink an inode (this does rmdir as well)
1082 * @dir: The inode of the directory containing the inode to unlink
David Teiglandb3b94fa2006-01-16 16:50:04 +00001083 * @dentry: The file itself
1084 *
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001085 * This routine uses the type of the inode as a flag to figure out
1086 * whether this is an unlink or an rmdir.
David Teiglandb3b94fa2006-01-16 16:50:04 +00001087 *
1088 * Returns: errno
1089 */
1090
1091static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
1092{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001093 struct gfs2_inode *dip = GFS2_I(dir);
1094 struct gfs2_sbd *sdp = GFS2_SB(dir);
David Howells2b0143b2015-03-17 22:25:59 +00001095 struct inode *inode = d_inode(dentry);
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001096 struct gfs2_inode *ip = GFS2_I(inode);
Russell Cattelanddee7602007-01-29 17:13:44 -06001097 struct gfs2_holder ghs[3];
1098 struct gfs2_rgrpd *rgd;
Bob Peterson5e2f7d62012-04-04 22:11:16 -04001099 int error;
1100
1101 error = gfs2_rindex_update(sdp);
1102 if (error)
1103 return error;
1104
1105 error = -EROFS;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001106
Russell Cattelanddee7602007-01-29 17:13:44 -06001107 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
1108 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
1109
Steven Whitehouse66fc0612012-02-08 12:58:32 +00001110 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr, 1);
Steven Whitehousea365fbf2012-02-24 15:09:14 +00001111 if (!rgd)
Steven Whitehouse87654892011-11-08 14:04:20 +00001112 goto out_inodes;
Steven Whitehousea365fbf2012-02-24 15:09:14 +00001113
Russell Cattelanddee7602007-01-29 17:13:44 -06001114 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
1115
1116
Steven Whitehouse8497a462007-08-26 14:23:56 +01001117 error = gfs2_glock_nq(ghs); /* parent */
David Teiglandb3b94fa2006-01-16 16:50:04 +00001118 if (error)
Steven Whitehouse8497a462007-08-26 14:23:56 +01001119 goto out_parent;
1120
1121 error = gfs2_glock_nq(ghs + 1); /* child */
1122 if (error)
1123 goto out_child;
1124
Steven Whitehoused192a8e2011-05-05 12:35:40 +01001125 error = -ENOENT;
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001126 if (inode->i_nlink == 0)
Steven Whitehoused192a8e2011-05-05 12:35:40 +01001127 goto out_rgrp;
1128
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001129 if (S_ISDIR(inode->i_mode)) {
1130 error = -ENOTEMPTY;
1131 if (ip->i_entries > 2 || inode->i_nlink > 2)
1132 goto out_rgrp;
1133 }
1134
Steven Whitehouse8497a462007-08-26 14:23:56 +01001135 error = gfs2_glock_nq(ghs + 2); /* rgrp */
1136 if (error)
1137 goto out_rgrp;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001138
1139 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
1140 if (error)
Bob Peterson72dbf472008-08-12 13:39:29 -05001141 goto out_gunlock;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001142
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001143 error = gfs2_trans_begin(sdp, 2*RES_DINODE + 3*RES_LEAF + RES_RG_BIT, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001144 if (error)
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001145 goto out_end_trans;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001146
Bob Peterson4327a9b2012-11-12 13:03:29 -05001147 error = gfs2_unlink_inode(dip, dentry);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001148
1149out_end_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001150 gfs2_trans_end(sdp);
Bob Peterson72dbf472008-08-12 13:39:29 -05001151out_gunlock:
Steven Whitehouse8497a462007-08-26 14:23:56 +01001152 gfs2_glock_dq(ghs + 2);
1153out_rgrp:
Steven Whitehouse8497a462007-08-26 14:23:56 +01001154 gfs2_glock_dq(ghs + 1);
1155out_child:
Steven Whitehouse8497a462007-08-26 14:23:56 +01001156 gfs2_glock_dq(ghs);
1157out_parent:
Steven Whitehouse87654892011-11-08 14:04:20 +00001158 gfs2_holder_uninit(ghs + 2);
1159out_inodes:
1160 gfs2_holder_uninit(ghs + 1);
Steven Whitehouse8497a462007-08-26 14:23:56 +01001161 gfs2_holder_uninit(ghs);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001162 return error;
1163}
1164
1165/**
1166 * gfs2_symlink - Create a symlink
1167 * @dir: The directory to create the symlink in
1168 * @dentry: The dentry to put the symlink in
1169 * @symname: The thing which the link points to
1170 *
1171 * Returns: errno
1172 */
1173
1174static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
1175 const char *symname)
1176{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001177 struct gfs2_sbd *sdp = GFS2_SB(dir);
Steven Whitehouse160b4022011-05-13 10:34:59 +01001178 unsigned int size;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001179
David Teiglandb3b94fa2006-01-16 16:50:04 +00001180 size = strlen(symname);
1181 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
1182 return -ENAMETOOLONG;
1183
Steven Whitehouse6d4ade92013-06-14 11:17:15 +01001184 return gfs2_create_inode(dir, dentry, NULL, S_IFLNK | S_IRWXUGO, 0, symname, size, 0, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001185}
1186
1187/**
1188 * gfs2_mkdir - Make a directory
1189 * @dir: The parent directory of the new one
1190 * @dentry: The dentry of the new directory
1191 * @mode: The mode of the new directory
1192 *
1193 * Returns: errno
1194 */
1195
Al Viro18bb1db2011-07-26 01:41:39 -04001196static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
David Teiglandb3b94fa2006-01-16 16:50:04 +00001197{
Steven Whitehouse28fb3022013-02-26 19:09:35 +00001198 struct gfs2_sbd *sdp = GFS2_SB(dir);
1199 unsigned dsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
Steven Whitehouse6d4ade92013-06-14 11:17:15 +01001200 return gfs2_create_inode(dir, dentry, NULL, S_IFDIR | mode, 0, NULL, dsize, 0, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001201}
1202
1203/**
David Teiglandb3b94fa2006-01-16 16:50:04 +00001204 * gfs2_mknod - Make a special file
1205 * @dir: The directory in which the special file will reside
1206 * @dentry: The dentry of the special file
1207 * @mode: The mode of the special file
Steven Whitehousef2741d92011-05-13 12:11:17 +01001208 * @dev: The device specification of the special file
David Teiglandb3b94fa2006-01-16 16:50:04 +00001209 *
1210 */
1211
Al Viro1a67aaf2011-07-26 01:52:52 -04001212static int gfs2_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
David Teiglandb3b94fa2006-01-16 16:50:04 +00001213 dev_t dev)
1214{
Steven Whitehouse6d4ade92013-06-14 11:17:15 +01001215 return gfs2_create_inode(dir, dentry, NULL, mode, dev, NULL, 0, 0, NULL);
1216}
1217
1218/**
1219 * gfs2_atomic_open - Atomically open a file
1220 * @dir: The directory
1221 * @dentry: The proposed new entry
1222 * @file: The proposed new struct file
1223 * @flags: open flags
1224 * @mode: File mode
1225 * @opened: Flag to say whether the file has been opened or not
1226 *
1227 * Returns: error code or 0 for success
1228 */
1229
1230static int gfs2_atomic_open(struct inode *dir, struct dentry *dentry,
Antonio Ospite86fbca42015-05-01 12:54:38 -05001231 struct file *file, unsigned flags,
1232 umode_t mode, int *opened)
Steven Whitehouse6d4ade92013-06-14 11:17:15 +01001233{
1234 struct dentry *d;
1235 bool excl = !!(flags & O_EXCL);
1236
Al Viro4d93bc32014-09-12 18:21:05 -04001237 if (!d_unhashed(dentry))
1238 goto skip_lookup;
1239
Steven Whitehouse6d4ade92013-06-14 11:17:15 +01001240 d = __gfs2_lookup(dir, dentry, file, opened);
1241 if (IS_ERR(d))
1242 return PTR_ERR(d);
Miklos Szeredi5ca1db42013-09-23 13:21:04 +01001243 if (d != NULL)
1244 dentry = d;
David Howells2b0143b2015-03-17 22:25:59 +00001245 if (d_really_is_positive(dentry)) {
Al Viroec7d8792014-11-19 19:35:58 +00001246 if (!(*opened & FILE_OPENED))
1247 return finish_no_open(file, d);
Miklos Szeredi5ca1db42013-09-23 13:21:04 +01001248 dput(d);
Steven Whitehouse6d4ade92013-06-14 11:17:15 +01001249 return 0;
1250 }
1251
Miklos Szeredi5ca1db42013-09-23 13:21:04 +01001252 BUG_ON(d != NULL);
Al Viro4d93bc32014-09-12 18:21:05 -04001253
1254skip_lookup:
Steven Whitehouse6d4ade92013-06-14 11:17:15 +01001255 if (!(flags & O_CREAT))
1256 return -ENOENT;
1257
1258 return gfs2_create_inode(dir, dentry, file, S_IFREG | mode, 0, NULL, 0, excl, opened);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001259}
1260
Steven Whitehouse0188d6c2008-08-26 09:38:26 +01001261/*
1262 * gfs2_ok_to_move - check if it's ok to move a directory to another directory
1263 * @this: move this
1264 * @to: to here
1265 *
1266 * Follow @to back to the root and make sure we don't encounter @this
1267 * Assumes we already hold the rename lock.
1268 *
1269 * Returns: errno
1270 */
1271
1272static int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to)
1273{
1274 struct inode *dir = &to->i_inode;
1275 struct super_block *sb = dir->i_sb;
1276 struct inode *tmp;
Steven Whitehouse0188d6c2008-08-26 09:38:26 +01001277 int error = 0;
1278
Steven Whitehouse0188d6c2008-08-26 09:38:26 +01001279 igrab(dir);
1280
1281 for (;;) {
1282 if (dir == &this->i_inode) {
1283 error = -EINVAL;
1284 break;
1285 }
David Howells2b0143b2015-03-17 22:25:59 +00001286 if (dir == d_inode(sb->s_root)) {
Steven Whitehouse0188d6c2008-08-26 09:38:26 +01001287 error = 0;
1288 break;
1289 }
1290
Steven Whitehouse8d123582010-09-17 12:30:23 +01001291 tmp = gfs2_lookupi(dir, &gfs2_qdotdot, 1);
Abhi Das48f8f712014-03-12 03:41:44 -05001292 if (!tmp) {
1293 error = -ENOENT;
1294 break;
1295 }
Steven Whitehouse0188d6c2008-08-26 09:38:26 +01001296 if (IS_ERR(tmp)) {
1297 error = PTR_ERR(tmp);
1298 break;
1299 }
1300
1301 iput(dir);
1302 dir = tmp;
1303 }
1304
1305 iput(dir);
1306
1307 return error;
1308}
1309
David Teiglandb3b94fa2006-01-16 16:50:04 +00001310/**
Benjamin Marzinskia63b7bb2015-05-05 12:12:19 -05001311 * update_moved_ino - Update an inode that's being moved
1312 * @ip: The inode being moved
1313 * @ndip: The parent directory of the new filename
1314 * @dir_rename: True of ip is a directory
1315 *
1316 * Returns: errno
1317 */
1318
1319static int update_moved_ino(struct gfs2_inode *ip, struct gfs2_inode *ndip,
1320 int dir_rename)
1321{
1322 int error;
1323 struct buffer_head *dibh;
1324
1325 if (dir_rename)
1326 return gfs2_dir_mvino(ip, &gfs2_qdotdot, ndip, DT_DIR);
1327
1328 error = gfs2_meta_inode_buffer(ip, &dibh);
1329 if (error)
1330 return error;
1331 ip->i_inode.i_ctime = CURRENT_TIME;
1332 gfs2_trans_add_meta(ip->i_gl, dibh);
1333 gfs2_dinode_out(ip, dibh->b_data);
1334 brelse(dibh);
1335 return 0;
1336}
1337
1338
1339/**
David Teiglandb3b94fa2006-01-16 16:50:04 +00001340 * gfs2_rename - Rename a file
1341 * @odir: Parent directory of old file name
1342 * @odentry: The old dentry of the file
1343 * @ndir: Parent directory of new file name
1344 * @ndentry: The new dentry of the file
1345 *
1346 * Returns: errno
1347 */
1348
1349static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1350 struct inode *ndir, struct dentry *ndentry)
1351{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001352 struct gfs2_inode *odip = GFS2_I(odir);
1353 struct gfs2_inode *ndip = GFS2_I(ndir);
David Howells2b0143b2015-03-17 22:25:59 +00001354 struct gfs2_inode *ip = GFS2_I(d_inode(odentry));
David Teiglandb3b94fa2006-01-16 16:50:04 +00001355 struct gfs2_inode *nip = NULL;
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001356 struct gfs2_sbd *sdp = GFS2_SB(odir);
Steven Whitehouse8339ee52011-08-31 16:38:29 +01001357 struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, };
Russell Cattelanddee7602007-01-29 17:13:44 -06001358 struct gfs2_rgrpd *nrgd;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001359 unsigned int num_gh;
1360 int dir_rename = 0;
Bob Peterson19aeb5a2014-09-29 08:52:04 -04001361 struct gfs2_diradd da = { .nr_blocks = 0, .save_loc = 0, };
David Teiglandb3b94fa2006-01-16 16:50:04 +00001362 unsigned int x;
1363 int error;
1364
David Howells2b0143b2015-03-17 22:25:59 +00001365 if (d_really_is_positive(ndentry)) {
1366 nip = GFS2_I(d_inode(ndentry));
David Teiglandb3b94fa2006-01-16 16:50:04 +00001367 if (ip == nip)
1368 return 0;
1369 }
1370
Bob Peterson5e2f7d62012-04-04 22:11:16 -04001371 error = gfs2_rindex_update(sdp);
1372 if (error)
1373 return error;
1374
Bob Petersonb54e9a02015-10-26 10:40:28 -05001375 error = gfs2_rsqa_alloc(ndip);
Bob Peterson0a305e42012-06-06 11:17:59 +01001376 if (error)
1377 return error;
1378
Steven Whitehouse0188d6c2008-08-26 09:38:26 +01001379 if (odip != ndip) {
1380 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE,
1381 0, &r_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001382 if (error)
1383 goto out;
1384
Steven Whitehouse0188d6c2008-08-26 09:38:26 +01001385 if (S_ISDIR(ip->i_inode.i_mode)) {
1386 dir_rename = 1;
Benjamin Marzinskia63b7bb2015-05-05 12:12:19 -05001387 /* don't move a directory into its subdir */
Steven Whitehouse0188d6c2008-08-26 09:38:26 +01001388 error = gfs2_ok_to_move(ip, ndip);
1389 if (error)
1390 goto out_gunlock_r;
1391 }
David Teiglandb3b94fa2006-01-16 16:50:04 +00001392 }
1393
Steven Whitehoused9d1ca32006-06-21 15:38:17 -04001394 num_gh = 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001395 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
Steven Whitehoused9d1ca32006-06-21 15:38:17 -04001396 if (odip != ndip) {
1397 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
1398 num_gh++;
1399 }
1400 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
1401 num_gh++;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001402
Steven Whitehoused9d1ca32006-06-21 15:38:17 -04001403 if (nip) {
1404 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
1405 num_gh++;
Russell Cattelanddee7602007-01-29 17:13:44 -06001406 /* grab the resource lock for unlink flag twiddling
1407 * this is the case of the target file already existing
1408 * so we unlink before doing the rename
1409 */
Steven Whitehouse66fc0612012-02-08 12:58:32 +00001410 nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr, 1);
Russell Cattelanddee7602007-01-29 17:13:44 -06001411 if (nrgd)
1412 gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
Steven Whitehoused9d1ca32006-06-21 15:38:17 -04001413 }
David Teiglandb3b94fa2006-01-16 16:50:04 +00001414
Bob Peterson72dbf472008-08-12 13:39:29 -05001415 for (x = 0; x < num_gh; x++) {
1416 error = gfs2_glock_nq(ghs + x);
1417 if (error)
1418 goto out_gunlock;
1419 }
David Teiglandb3b94fa2006-01-16 16:50:04 +00001420
Steven Whitehoused192a8e2011-05-05 12:35:40 +01001421 error = -ENOENT;
1422 if (ip->i_inode.i_nlink == 0)
1423 goto out_gunlock;
1424
David Teiglandb3b94fa2006-01-16 16:50:04 +00001425 /* Check out the old directory */
1426
1427 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
1428 if (error)
1429 goto out_gunlock;
1430
1431 /* Check out the new directory */
1432
1433 if (nip) {
1434 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
1435 if (error)
1436 goto out_gunlock;
1437
Steven Whitehoused192a8e2011-05-05 12:35:40 +01001438 if (nip->i_inode.i_nlink == 0) {
1439 error = -EAGAIN;
1440 goto out_gunlock;
1441 }
1442
Steven Whitehouseb60623c2006-11-01 12:22:46 -05001443 if (S_ISDIR(nip->i_inode.i_mode)) {
Steven Whitehousead6203f2008-11-03 13:59:19 +00001444 if (nip->i_entries < 2) {
Steven Whitehouse94fb7632011-05-09 13:36:10 +01001445 gfs2_consist_inode(nip);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001446 error = -EIO;
1447 goto out_gunlock;
1448 }
Steven Whitehousead6203f2008-11-03 13:59:19 +00001449 if (nip->i_entries > 2) {
David Teiglandb3b94fa2006-01-16 16:50:04 +00001450 error = -ENOTEMPTY;
1451 goto out_gunlock;
1452 }
1453 }
1454 } else {
Al Viro10556cb2011-06-20 19:28:19 -04001455 error = gfs2_permission(ndir, MAY_WRITE | MAY_EXEC);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001456 if (error)
1457 goto out_gunlock;
1458
Steven Whitehousedbb7cae2007-05-15 15:37:50 +01001459 error = gfs2_dir_check(ndir, &ndentry->d_name, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001460 switch (error) {
1461 case -ENOENT:
1462 error = 0;
1463 break;
1464 case 0:
1465 error = -EEXIST;
1466 default:
1467 goto out_gunlock;
1468 };
1469
1470 if (odip != ndip) {
Steven Whitehouse4f561102006-11-01 14:04:17 -05001471 if (!ndip->i_inode.i_nlink) {
Steven Whitehoused192a8e2011-05-05 12:35:40 +01001472 error = -ENOENT;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001473 goto out_gunlock;
1474 }
Steven Whitehousead6203f2008-11-03 13:59:19 +00001475 if (ndip->i_entries == (u32)-1) {
David Teiglandb3b94fa2006-01-16 16:50:04 +00001476 error = -EFBIG;
1477 goto out_gunlock;
1478 }
Steven Whitehouseb60623c2006-11-01 12:22:46 -05001479 if (S_ISDIR(ip->i_inode.i_mode) &&
Steven Whitehouse4f561102006-11-01 14:04:17 -05001480 ndip->i_inode.i_nlink == (u32)-1) {
David Teiglandb3b94fa2006-01-16 16:50:04 +00001481 error = -EMLINK;
1482 goto out_gunlock;
1483 }
1484 }
1485 }
1486
1487 /* Check out the dir to be renamed */
1488
1489 if (dir_rename) {
David Howells2b0143b2015-03-17 22:25:59 +00001490 error = gfs2_permission(d_inode(odentry), MAY_WRITE);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001491 if (error)
1492 goto out_gunlock;
1493 }
1494
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +00001495 if (nip == NULL) {
1496 error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name, &da);
1497 if (error)
1498 goto out_gunlock;
1499 }
David Teiglandb3b94fa2006-01-16 16:50:04 +00001500
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +00001501 if (da.nr_blocks) {
1502 struct gfs2_alloc_parms ap = { .target = da.nr_blocks, };
Abhi Dasb8fbf472015-03-18 12:03:41 -05001503 error = gfs2_quota_lock_check(ndip, &ap);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001504 if (error)
Bob Peterson5407e242012-05-18 09:28:23 -04001505 goto out_gunlock;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001506
Steven Whitehouse7b9cff42013-10-02 11:13:25 +01001507 error = gfs2_inplace_reserve(ndip, &ap);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001508 if (error)
1509 goto out_gunlock_q;
1510
Steven Whitehouse534cf9c2014-01-06 12:03:05 +00001511 error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(ndip, &da, 4) +
1512 4 * RES_LEAF + 4, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001513 if (error)
1514 goto out_ipreserv;
1515 } else {
1516 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
S. Wendy Cheng87d21e02007-01-18 16:07:03 -05001517 5 * RES_LEAF + 4, 0);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001518 if (error)
1519 goto out_gunlock;
1520 }
1521
1522 /* Remove the target file, if it exists */
1523
Bob Peterson4327a9b2012-11-12 13:03:29 -05001524 if (nip)
1525 error = gfs2_unlink_inode(ndip, ndentry);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001526
Benjamin Marzinskia63b7bb2015-05-05 12:12:19 -05001527 error = update_moved_ino(ip, ndip, dir_rename);
1528 if (error)
1529 goto out_end_trans;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001530
Steven Whitehouse855d23c2011-05-09 16:42:37 +01001531 error = gfs2_dir_del(odip, odentry);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001532 if (error)
1533 goto out_end_trans;
1534
Steven Whitehouse2b47dad2014-01-06 12:49:43 +00001535 error = gfs2_dir_add(ndir, &ndentry->d_name, ip, &da);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001536 if (error)
1537 goto out_end_trans;
1538
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001539out_end_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001540 gfs2_trans_end(sdp);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001541out_ipreserv:
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +00001542 if (da.nr_blocks)
David Teiglandb3b94fa2006-01-16 16:50:04 +00001543 gfs2_inplace_release(ndip);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001544out_gunlock_q:
Steven Whitehouse3c1c0ae2014-01-06 11:28:41 +00001545 if (da.nr_blocks)
David Teiglandb3b94fa2006-01-16 16:50:04 +00001546 gfs2_quota_unlock(ndip);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001547out_gunlock:
Steven Whitehouse2b47dad2014-01-06 12:49:43 +00001548 gfs2_dir_no_add(&da);
Bob Peterson72dbf472008-08-12 13:39:29 -05001549 while (x--) {
1550 gfs2_glock_dq(ghs + x);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001551 gfs2_holder_uninit(ghs + x);
Bob Peterson72dbf472008-08-12 13:39:29 -05001552 }
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001553out_gunlock_r:
Steven Whitehouse0188d6c2008-08-26 09:38:26 +01001554 if (r_gh.gh_gl)
David Teiglandb3b94fa2006-01-16 16:50:04 +00001555 gfs2_glock_dq_uninit(&r_gh);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001556out:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001557 return error;
1558}
1559
1560/**
Benjamin Marzinskia63b7bb2015-05-05 12:12:19 -05001561 * gfs2_exchange - exchange two files
1562 * @odir: Parent directory of old file name
1563 * @odentry: The old dentry of the file
1564 * @ndir: Parent directory of new file name
1565 * @ndentry: The new dentry of the file
1566 * @flags: The rename flags
1567 *
1568 * Returns: errno
1569 */
1570
1571static int gfs2_exchange(struct inode *odir, struct dentry *odentry,
1572 struct inode *ndir, struct dentry *ndentry,
1573 unsigned int flags)
1574{
1575 struct gfs2_inode *odip = GFS2_I(odir);
1576 struct gfs2_inode *ndip = GFS2_I(ndir);
1577 struct gfs2_inode *oip = GFS2_I(odentry->d_inode);
1578 struct gfs2_inode *nip = GFS2_I(ndentry->d_inode);
1579 struct gfs2_sbd *sdp = GFS2_SB(odir);
1580 struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, };
1581 unsigned int num_gh;
1582 unsigned int x;
1583 umode_t old_mode = oip->i_inode.i_mode;
1584 umode_t new_mode = nip->i_inode.i_mode;
1585 int error;
1586
1587 error = gfs2_rindex_update(sdp);
1588 if (error)
1589 return error;
1590
1591 if (odip != ndip) {
1592 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE,
1593 0, &r_gh);
1594 if (error)
1595 goto out;
1596
1597 if (S_ISDIR(old_mode)) {
1598 /* don't move a directory into its subdir */
1599 error = gfs2_ok_to_move(oip, ndip);
1600 if (error)
1601 goto out_gunlock_r;
1602 }
1603
1604 if (S_ISDIR(new_mode)) {
1605 /* don't move a directory into its subdir */
1606 error = gfs2_ok_to_move(nip, odip);
1607 if (error)
1608 goto out_gunlock_r;
1609 }
1610 }
1611
1612 num_gh = 1;
1613 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
1614 if (odip != ndip) {
1615 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
1616 num_gh++;
1617 }
1618 gfs2_holder_init(oip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
1619 num_gh++;
1620
1621 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
1622 num_gh++;
1623
1624 for (x = 0; x < num_gh; x++) {
1625 error = gfs2_glock_nq(ghs + x);
1626 if (error)
1627 goto out_gunlock;
1628 }
1629
1630 error = -ENOENT;
1631 if (oip->i_inode.i_nlink == 0 || nip->i_inode.i_nlink == 0)
1632 goto out_gunlock;
1633
1634 error = gfs2_unlink_ok(odip, &odentry->d_name, oip);
1635 if (error)
1636 goto out_gunlock;
1637 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
1638 if (error)
1639 goto out_gunlock;
1640
1641 if (S_ISDIR(old_mode)) {
1642 error = gfs2_permission(odentry->d_inode, MAY_WRITE);
1643 if (error)
1644 goto out_gunlock;
1645 }
1646 if (S_ISDIR(new_mode)) {
1647 error = gfs2_permission(ndentry->d_inode, MAY_WRITE);
1648 if (error)
1649 goto out_gunlock;
1650 }
1651 error = gfs2_trans_begin(sdp, 4 * RES_DINODE + 4 * RES_LEAF, 0);
1652 if (error)
1653 goto out_gunlock;
1654
1655 error = update_moved_ino(oip, ndip, S_ISDIR(old_mode));
1656 if (error)
1657 goto out_end_trans;
1658
1659 error = update_moved_ino(nip, odip, S_ISDIR(new_mode));
1660 if (error)
1661 goto out_end_trans;
1662
1663 error = gfs2_dir_mvino(ndip, &ndentry->d_name, oip,
1664 IF2DT(old_mode));
1665 if (error)
1666 goto out_end_trans;
1667
1668 error = gfs2_dir_mvino(odip, &odentry->d_name, nip,
1669 IF2DT(new_mode));
1670 if (error)
1671 goto out_end_trans;
1672
1673 if (odip != ndip) {
1674 if (S_ISDIR(new_mode) && !S_ISDIR(old_mode)) {
1675 inc_nlink(&odip->i_inode);
1676 drop_nlink(&ndip->i_inode);
1677 } else if (S_ISDIR(old_mode) && !S_ISDIR(new_mode)) {
1678 inc_nlink(&ndip->i_inode);
1679 drop_nlink(&odip->i_inode);
1680 }
1681 }
1682 mark_inode_dirty(&ndip->i_inode);
1683 if (odip != ndip)
1684 mark_inode_dirty(&odip->i_inode);
1685
1686out_end_trans:
1687 gfs2_trans_end(sdp);
1688out_gunlock:
1689 while (x--) {
1690 gfs2_glock_dq(ghs + x);
1691 gfs2_holder_uninit(ghs + x);
1692 }
1693out_gunlock_r:
1694 if (r_gh.gh_gl)
1695 gfs2_glock_dq_uninit(&r_gh);
1696out:
1697 return error;
1698}
1699
1700static int gfs2_rename2(struct inode *odir, struct dentry *odentry,
1701 struct inode *ndir, struct dentry *ndentry,
1702 unsigned int flags)
1703{
1704 flags &= ~RENAME_NOREPLACE;
1705
1706 if (flags & ~RENAME_EXCHANGE)
1707 return -EINVAL;
1708
1709 if (flags & RENAME_EXCHANGE)
1710 return gfs2_exchange(odir, odentry, ndir, ndentry, flags);
1711
1712 return gfs2_rename(odir, odentry, ndir, ndentry);
1713}
1714
1715/**
Al Viro6b255392015-11-17 10:20:54 -05001716 * gfs2_get_link - Follow a symbolic link
David Teiglandb3b94fa2006-01-16 16:50:04 +00001717 * @dentry: The dentry of the link
Al Viro6b255392015-11-17 10:20:54 -05001718 * @inode: The inode of the link
Al Virofceef392015-12-29 15:58:39 -05001719 * @done: destructor for return value
David Teiglandb3b94fa2006-01-16 16:50:04 +00001720 *
Al Viroc177c2a2010-01-14 00:59:16 -05001721 * This can handle symlinks of any size.
David Teiglandb3b94fa2006-01-16 16:50:04 +00001722 *
1723 * Returns: 0 on success or error code
1724 */
1725
Al Viro6b255392015-11-17 10:20:54 -05001726static const char *gfs2_get_link(struct dentry *dentry,
Al Virofceef392015-12-29 15:58:39 -05001727 struct inode *inode,
1728 struct delayed_call *done)
David Teiglandb3b94fa2006-01-16 16:50:04 +00001729{
Al Viro6b255392015-11-17 10:20:54 -05001730 struct gfs2_inode *ip = GFS2_I(inode);
Al Viroc177c2a2010-01-14 00:59:16 -05001731 struct gfs2_holder i_gh;
1732 struct buffer_head *dibh;
Steven Whitehouse160b4022011-05-13 10:34:59 +01001733 unsigned int size;
Al Viroc177c2a2010-01-14 00:59:16 -05001734 char *buf;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001735 int error;
1736
Al Viro6b255392015-11-17 10:20:54 -05001737 if (!dentry)
1738 return ERR_PTR(-ECHILD);
1739
Al Viroc177c2a2010-01-14 00:59:16 -05001740 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
1741 error = gfs2_glock_nq(&i_gh);
1742 if (error) {
1743 gfs2_holder_uninit(&i_gh);
Al Viro680baac2015-05-02 13:32:22 -04001744 return ERR_PTR(error);
Al Viroc177c2a2010-01-14 00:59:16 -05001745 }
David Teiglandb3b94fa2006-01-16 16:50:04 +00001746
Steven Whitehousea2e0f792010-08-11 09:53:11 +01001747 size = (unsigned int)i_size_read(&ip->i_inode);
1748 if (size == 0) {
Al Viroc177c2a2010-01-14 00:59:16 -05001749 gfs2_consist_inode(ip);
1750 buf = ERR_PTR(-EIO);
1751 goto out;
1752 }
1753
1754 error = gfs2_meta_inode_buffer(ip, &dibh);
1755 if (error) {
1756 buf = ERR_PTR(error);
1757 goto out;
1758 }
1759
Steven Whitehouse160b4022011-05-13 10:34:59 +01001760 buf = kzalloc(size + 1, GFP_NOFS);
Al Viroc177c2a2010-01-14 00:59:16 -05001761 if (!buf)
1762 buf = ERR_PTR(-ENOMEM);
1763 else
Steven Whitehouse160b4022011-05-13 10:34:59 +01001764 memcpy(buf, dibh->b_data + sizeof(struct gfs2_dinode), size);
Al Viroc177c2a2010-01-14 00:59:16 -05001765 brelse(dibh);
1766out:
1767 gfs2_glock_dq_uninit(&i_gh);
Al Viro680baac2015-05-02 13:32:22 -04001768 if (!IS_ERR(buf))
Al Virofceef392015-12-29 15:58:39 -05001769 set_delayed_call(done, kfree_link, buf);
Al Viro680baac2015-05-02 13:32:22 -04001770 return buf;
Al Viroc177c2a2010-01-14 00:59:16 -05001771}
1772
David Teiglandb3b94fa2006-01-16 16:50:04 +00001773/**
1774 * gfs2_permission -
Steven Whitehouse75d5cfb2011-01-19 09:42:40 +00001775 * @inode: The inode
1776 * @mask: The mask to be tested
1777 * @flags: Indicates whether this is an RCU path walk or not
David Teiglandb3b94fa2006-01-16 16:50:04 +00001778 *
Steven Whitehouse300c7d72006-11-27 09:55:28 -05001779 * This may be called from the VFS directly, or from within GFS2 with the
1780 * inode locked, so we look to see if the glock is already locked and only
1781 * lock the glock if its not already been done.
1782 *
David Teiglandb3b94fa2006-01-16 16:50:04 +00001783 * Returns: errno
1784 */
1785
Al Viro10556cb2011-06-20 19:28:19 -04001786int gfs2_permission(struct inode *inode, int mask)
David Teiglandb3b94fa2006-01-16 16:50:04 +00001787{
Nick Pigginb74c79e2011-01-07 17:49:58 +11001788 struct gfs2_inode *ip;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001789 struct gfs2_holder i_gh;
1790 int error;
Steven Whitehouse300c7d72006-11-27 09:55:28 -05001791 int unlock = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001792
Nick Pigginb74c79e2011-01-07 17:49:58 +11001793
1794 ip = GFS2_I(inode);
Steven Whitehouse7afd88d2008-02-22 16:07:18 +00001795 if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
Benjamin Marzinski2e60d762014-11-13 20:42:04 -06001796 if (mask & MAY_NOT_BLOCK)
1797 return -ECHILD;
1798 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
1799 if (error)
1800 return error;
1801 unlock = 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001802 }
1803
Miklos Szeredif58ba882008-07-02 21:12:01 +02001804 if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode))
1805 error = -EACCES;
1806 else
Al Viro2830ba72011-06-20 19:16:29 -04001807 error = generic_permission(inode, mask);
Steven Whitehouse300c7d72006-11-27 09:55:28 -05001808 if (unlock)
1809 gfs2_glock_dq_uninit(&i_gh);
1810
David Teiglandb3b94fa2006-01-16 16:50:04 +00001811 return error;
1812}
1813
Steven Whitehouseab9bbda2011-08-15 14:20:36 +01001814static int __gfs2_setattr_simple(struct inode *inode, struct iattr *attr)
Steven Whitehouse194c0112011-05-09 14:06:38 +01001815{
Steven Whitehouse194c0112011-05-09 14:06:38 +01001816 setattr_copy(inode, attr);
1817 mark_inode_dirty(inode);
Steven Whitehouse194c0112011-05-09 14:06:38 +01001818 return 0;
1819}
1820
1821/**
1822 * gfs2_setattr_simple -
1823 * @ip:
1824 * @attr:
1825 *
1826 * Returns: errno
1827 */
1828
Steven Whitehouseab9bbda2011-08-15 14:20:36 +01001829int gfs2_setattr_simple(struct inode *inode, struct iattr *attr)
Steven Whitehouse194c0112011-05-09 14:06:38 +01001830{
1831 int error;
1832
1833 if (current->journal_info)
Steven Whitehouseab9bbda2011-08-15 14:20:36 +01001834 return __gfs2_setattr_simple(inode, attr);
Steven Whitehouse194c0112011-05-09 14:06:38 +01001835
Steven Whitehouseab9bbda2011-08-15 14:20:36 +01001836 error = gfs2_trans_begin(GFS2_SB(inode), RES_DINODE, 0);
Steven Whitehouse194c0112011-05-09 14:06:38 +01001837 if (error)
1838 return error;
1839
Steven Whitehouseab9bbda2011-08-15 14:20:36 +01001840 error = __gfs2_setattr_simple(inode, attr);
1841 gfs2_trans_end(GFS2_SB(inode));
Steven Whitehouse194c0112011-05-09 14:06:38 +01001842 return error;
1843}
1844
David Teiglandb3b94fa2006-01-16 16:50:04 +00001845static int setattr_chown(struct inode *inode, struct iattr *attr)
1846{
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001847 struct gfs2_inode *ip = GFS2_I(inode);
1848 struct gfs2_sbd *sdp = GFS2_SB(inode);
Eric W. Biederman7c06b5d2013-01-31 20:27:54 -08001849 kuid_t ouid, nuid;
1850 kgid_t ogid, ngid;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001851 int error;
Abhi Dasb8fbf472015-03-18 12:03:41 -05001852 struct gfs2_alloc_parms ap;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001853
Steven Whitehouse2933f922006-11-01 13:23:29 -05001854 ouid = inode->i_uid;
1855 ogid = inode->i_gid;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001856 nuid = attr->ia_uid;
1857 ngid = attr->ia_gid;
1858
Eric W. Biederman6b24c0d2013-01-31 21:56:13 -08001859 if (!(attr->ia_valid & ATTR_UID) || uid_eq(ouid, nuid))
Eric W. Biedermanf4108a62013-01-31 17:49:26 -08001860 ouid = nuid = NO_UID_QUOTA_CHANGE;
Eric W. Biederman6b24c0d2013-01-31 21:56:13 -08001861 if (!(attr->ia_valid & ATTR_GID) || gid_eq(ogid, ngid))
Eric W. Biedermanf4108a62013-01-31 17:49:26 -08001862 ogid = ngid = NO_GID_QUOTA_CHANGE;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001863
Bob Petersonb54e9a02015-10-26 10:40:28 -05001864 error = gfs2_rsqa_alloc(ip);
Bob Peterson62e96cf2014-01-06 17:16:01 -05001865 if (error)
1866 goto out;
1867
1868 error = gfs2_rindex_update(sdp);
1869 if (error)
1870 goto out;
1871
1872 error = gfs2_quota_lock(ip, nuid, ngid);
1873 if (error)
1874 goto out;
1875
Abhi Dasb8fbf472015-03-18 12:03:41 -05001876 ap.target = gfs2_get_inode_blocks(&ip->i_inode);
1877
Eric W. Biederman6b24c0d2013-01-31 21:56:13 -08001878 if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) ||
1879 !gid_eq(ogid, NO_GID_QUOTA_CHANGE)) {
Abhi Dasb8fbf472015-03-18 12:03:41 -05001880 error = gfs2_quota_check(ip, nuid, ngid, &ap);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001881 if (error)
1882 goto out_gunlock_q;
1883 }
1884
1885 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
1886 if (error)
1887 goto out_gunlock_q;
1888
Steven Whitehouseab9bbda2011-08-15 14:20:36 +01001889 error = gfs2_setattr_simple(inode, attr);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001890 if (error)
1891 goto out_end_trans;
1892
Eric W. Biederman6b24c0d2013-01-31 21:56:13 -08001893 if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) ||
1894 !gid_eq(ogid, NO_GID_QUOTA_CHANGE)) {
Abhi Das39a72582015-06-02 11:02:24 -05001895 gfs2_quota_change(ip, -(s64)ap.target, ouid, ogid);
Abhi Dasb8fbf472015-03-18 12:03:41 -05001896 gfs2_quota_change(ip, ap.target, nuid, ngid);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001897 }
1898
Steven Whitehousea91ea692006-09-04 12:04:26 -04001899out_end_trans:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001900 gfs2_trans_end(sdp);
Steven Whitehousea91ea692006-09-04 12:04:26 -04001901out_gunlock_q:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001902 gfs2_quota_unlock(ip);
Bob Peterson62e96cf2014-01-06 17:16:01 -05001903out:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001904 return error;
1905}
1906
1907/**
1908 * gfs2_setattr - Change attributes on an inode
1909 * @dentry: The dentry which is changing
1910 * @attr: The structure describing the change
1911 *
1912 * The VFS layer wants to change one or more of an inodes attributes. Write
1913 * that change out to disk.
1914 *
1915 * Returns: errno
1916 */
1917
1918static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
1919{
David Howells2b0143b2015-03-17 22:25:59 +00001920 struct inode *inode = d_inode(dentry);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001921 struct gfs2_inode *ip = GFS2_I(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001922 struct gfs2_holder i_gh;
1923 int error;
1924
Bob Petersonb54e9a02015-10-26 10:40:28 -05001925 error = gfs2_rsqa_alloc(ip);
Bob Peterson0a305e42012-06-06 11:17:59 +01001926 if (error)
1927 return error;
1928
David Teiglandb3b94fa2006-01-16 16:50:04 +00001929 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
1930 if (error)
1931 return error;
1932
1933 error = -EPERM;
1934 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1935 goto out;
1936
1937 error = inode_change_ok(inode, attr);
1938 if (error)
1939 goto out;
1940
1941 if (attr->ia_valid & ATTR_SIZE)
Steven Whitehouseff8f33c2010-08-11 09:37:53 +01001942 error = gfs2_setattr_size(inode, attr->ia_size);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001943 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1944 error = setattr_chown(inode, attr);
Christoph Hellwige01580b2013-12-20 05:16:52 -08001945 else {
Steven Whitehouseab9bbda2011-08-15 14:20:36 +01001946 error = gfs2_setattr_simple(inode, attr);
Christoph Hellwige01580b2013-12-20 05:16:52 -08001947 if (!error && attr->ia_valid & ATTR_MODE)
1948 error = posix_acl_chmod(inode, inode->i_mode);
1949 }
David Teiglandb3b94fa2006-01-16 16:50:04 +00001950
Steven Whitehousea91ea692006-09-04 12:04:26 -04001951out:
David Teiglandb3b94fa2006-01-16 16:50:04 +00001952 if (!error)
1953 mark_inode_dirty(inode);
Steven Whitehouseab9bbda2011-08-15 14:20:36 +01001954 gfs2_glock_dq_uninit(&i_gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001955 return error;
1956}
1957
1958/**
1959 * gfs2_getattr - Read out an inode's attributes
Steven Whitehouse26c1a572006-09-04 15:32:10 -04001960 * @mnt: The vfsmount the inode is being accessed from
David Teiglandb3b94fa2006-01-16 16:50:04 +00001961 * @dentry: The dentry to stat
1962 * @stat: The inode's stats
1963 *
Steven Whitehousedcf3dd82006-11-27 10:12:05 -05001964 * This may be called from the VFS directly, or from within GFS2 with the
1965 * inode locked, so we look to see if the glock is already locked and only
1966 * lock the glock if its not already been done. Note that its the NFS
1967 * readdirplus operation which causes this to be called (from filldir)
1968 * with the glock already held.
1969 *
David Teiglandb3b94fa2006-01-16 16:50:04 +00001970 * Returns: errno
1971 */
1972
1973static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1974 struct kstat *stat)
1975{
David Howells2b0143b2015-03-17 22:25:59 +00001976 struct inode *inode = d_inode(dentry);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -04001977 struct gfs2_inode *ip = GFS2_I(inode);
David Teiglandb3b94fa2006-01-16 16:50:04 +00001978 struct gfs2_holder gh;
1979 int error;
Steven Whitehousedcf3dd82006-11-27 10:12:05 -05001980 int unlock = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001981
Steven Whitehouse7afd88d2008-02-22 16:07:18 +00001982 if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
Benjamin Marzinski2e60d762014-11-13 20:42:04 -06001983 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1984 if (error)
1985 return error;
1986 unlock = 1;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001987 }
1988
Steven Whitehousedcf3dd82006-11-27 10:12:05 -05001989 generic_fillattr(inode, stat);
Steven Whitehoused7c103d2007-01-25 17:14:59 +00001990 if (unlock)
Steven Whitehousedcf3dd82006-11-27 10:12:05 -05001991 gfs2_glock_dq_uninit(&gh);
1992
1993 return 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +00001994}
1995
Steven Whitehousee9079cc2008-10-14 14:43:29 +01001996static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
1997 u64 start, u64 len)
1998{
1999 struct gfs2_inode *ip = GFS2_I(inode);
2000 struct gfs2_holder gh;
2001 int ret;
2002
2003 ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC);
2004 if (ret)
2005 return ret;
2006
Al Viro59551022016-01-22 15:40:57 -05002007 inode_lock(inode);
Steven Whitehousee9079cc2008-10-14 14:43:29 +01002008
2009 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
2010 if (ret)
2011 goto out;
2012
2013 if (gfs2_is_stuffed(ip)) {
2014 u64 phys = ip->i_no_addr << inode->i_blkbits;
2015 u64 size = i_size_read(inode);
2016 u32 flags = FIEMAP_EXTENT_LAST|FIEMAP_EXTENT_NOT_ALIGNED|
2017 FIEMAP_EXTENT_DATA_INLINE;
2018 phys += sizeof(struct gfs2_dinode);
2019 phys += start;
2020 if (start + len > size)
2021 len = size - start;
2022 if (start < size)
2023 ret = fiemap_fill_next_extent(fieinfo, start, phys,
2024 len, flags);
2025 if (ret == 1)
2026 ret = 0;
2027 } else {
2028 ret = __generic_block_fiemap(inode, fieinfo, start, len,
2029 gfs2_block_map);
2030 }
2031
2032 gfs2_glock_dq_uninit(&gh);
2033out:
Al Viro59551022016-01-22 15:40:57 -05002034 inode_unlock(inode);
Steven Whitehousee9079cc2008-10-14 14:43:29 +01002035 return ret;
2036}
2037
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -08002038const struct inode_operations gfs2_file_iops = {
Al Viroe6305c42008-07-15 21:03:57 -04002039 .permission = gfs2_permission,
David Teiglandb3b94fa2006-01-16 16:50:04 +00002040 .setattr = gfs2_setattr,
2041 .getattr = gfs2_getattr,
Al Viro1a39ba92016-05-13 03:59:17 +02002042 .setxattr = generic_setxattr,
2043 .getxattr = generic_getxattr,
David Teiglandb3b94fa2006-01-16 16:50:04 +00002044 .listxattr = gfs2_listxattr,
Al Viro1a39ba92016-05-13 03:59:17 +02002045 .removexattr = generic_removexattr,
Steven Whitehousee9079cc2008-10-14 14:43:29 +01002046 .fiemap = gfs2_fiemap,
Christoph Hellwig4e34e712011-07-23 17:37:31 +02002047 .get_acl = gfs2_get_acl,
Christoph Hellwige01580b2013-12-20 05:16:52 -08002048 .set_acl = gfs2_set_acl,
David Teiglandb3b94fa2006-01-16 16:50:04 +00002049};
2050
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -08002051const struct inode_operations gfs2_dir_iops = {
David Teiglandb3b94fa2006-01-16 16:50:04 +00002052 .create = gfs2_create,
2053 .lookup = gfs2_lookup,
2054 .link = gfs2_link,
2055 .unlink = gfs2_unlink,
2056 .symlink = gfs2_symlink,
2057 .mkdir = gfs2_mkdir,
Steven Whitehouse855d23c2011-05-09 16:42:37 +01002058 .rmdir = gfs2_unlink,
David Teiglandb3b94fa2006-01-16 16:50:04 +00002059 .mknod = gfs2_mknod,
Benjamin Marzinskia63b7bb2015-05-05 12:12:19 -05002060 .rename2 = gfs2_rename2,
Al Viroe6305c42008-07-15 21:03:57 -04002061 .permission = gfs2_permission,
David Teiglandb3b94fa2006-01-16 16:50:04 +00002062 .setattr = gfs2_setattr,
2063 .getattr = gfs2_getattr,
Al Viro1a39ba92016-05-13 03:59:17 +02002064 .setxattr = generic_setxattr,
2065 .getxattr = generic_getxattr,
David Teiglandb3b94fa2006-01-16 16:50:04 +00002066 .listxattr = gfs2_listxattr,
Al Viro1a39ba92016-05-13 03:59:17 +02002067 .removexattr = generic_removexattr,
Steven Whitehousee9079cc2008-10-14 14:43:29 +01002068 .fiemap = gfs2_fiemap,
Christoph Hellwig4e34e712011-07-23 17:37:31 +02002069 .get_acl = gfs2_get_acl,
Christoph Hellwige01580b2013-12-20 05:16:52 -08002070 .set_acl = gfs2_set_acl,
Steven Whitehouse6d4ade92013-06-14 11:17:15 +01002071 .atomic_open = gfs2_atomic_open,
David Teiglandb3b94fa2006-01-16 16:50:04 +00002072};
2073
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -08002074const struct inode_operations gfs2_symlink_iops = {
Al Viroc177c2a2010-01-14 00:59:16 -05002075 .readlink = generic_readlink,
Al Viro6b255392015-11-17 10:20:54 -05002076 .get_link = gfs2_get_link,
Al Viroe6305c42008-07-15 21:03:57 -04002077 .permission = gfs2_permission,
David Teiglandb3b94fa2006-01-16 16:50:04 +00002078 .setattr = gfs2_setattr,
2079 .getattr = gfs2_getattr,
Al Viro1a39ba92016-05-13 03:59:17 +02002080 .setxattr = generic_setxattr,
2081 .getxattr = generic_getxattr,
David Teiglandb3b94fa2006-01-16 16:50:04 +00002082 .listxattr = gfs2_listxattr,
Al Viro1a39ba92016-05-13 03:59:17 +02002083 .removexattr = generic_removexattr,
Steven Whitehousee9079cc2008-10-14 14:43:29 +01002084 .fiemap = gfs2_fiemap,
David Teiglandb3b94fa2006-01-16 16:50:04 +00002085};
2086