blob: e103b05dc777382e58bcc02071d9c67af7833889 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
19#include "xfs_fs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110020#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110022#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "xfs_trans.h"
24#include "xfs_sb.h"
25#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_dir2.h"
27#include "xfs_alloc.h"
28#include "xfs_dmapi.h"
29#include "xfs_quota.h"
30#include "xfs_mount.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "xfs_bmap_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110032#include "xfs_alloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "xfs_ialloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_dir2_sf.h"
Nathan Scotta844f452005-11-02 14:38:42 +110035#include "xfs_attr_sf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "xfs_dinode.h"
37#include "xfs_inode.h"
38#include "xfs_bmap.h"
Nathan Scotta844f452005-11-02 14:38:42 +110039#include "xfs_btree.h"
40#include "xfs_ialloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "xfs_rtalloc.h"
42#include "xfs_error.h"
43#include "xfs_itable.h"
44#include "xfs_rw.h"
45#include "xfs_acl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include "xfs_attr.h"
47#include "xfs_buf_item.h"
48#include "xfs_utils.h"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100049#include "xfs_vnodeops.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Randy Dunlap16f7e0f2006-01-11 12:17:46 -080051#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/xattr.h>
53#include <linux/namei.h>
Nathan Scott446ada42006-01-11 15:35:44 +110054#include <linux/security.h>
David Chinner3ed65262007-11-23 16:29:25 +110055#include <linux/falloc.h>
Eric Sandeenf35642e2008-11-28 14:23:35 +110056#include <linux/fiemap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Nathan Scott4aeb6642005-11-02 11:43:58 +110058/*
Christoph Hellwig42fe2b12006-01-11 15:35:17 +110059 * Bring the atime in the XFS inode uptodate.
60 * Used before logging the inode to disk or when the Linux inode goes away.
61 */
62void
63xfs_synchronize_atime(
64 xfs_inode_t *ip)
65{
David Chinner01651642008-08-13 15:45:15 +100066 struct inode *inode = VFS_I(ip);
Christoph Hellwig42fe2b12006-01-11 15:35:17 +110067
David Chinnerbf904242008-10-30 17:36:14 +110068 if (!(inode->i_state & I_CLEAR)) {
Christoph Hellwigaf048192008-03-06 13:46:43 +110069 ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec;
70 ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec;
Christoph Hellwig42fe2b12006-01-11 15:35:17 +110071 }
72}
73
74/*
David Chinnerbf904242008-10-30 17:36:14 +110075 * If the linux inode is valid, mark it dirty.
David Chinner5d51eff2007-11-23 16:29:18 +110076 * Used when commiting a dirty inode into a transaction so that
77 * the inode will get written back by the linux code
78 */
79void
80xfs_mark_inode_dirty_sync(
81 xfs_inode_t *ip)
82{
David Chinner01651642008-08-13 15:45:15 +100083 struct inode *inode = VFS_I(ip);
David Chinner5d51eff2007-11-23 16:29:18 +110084
David Chinnerbf904242008-10-30 17:36:14 +110085 if (!(inode->i_state & (I_WILL_FREE|I_FREEING|I_CLEAR)))
Christoph Hellwigaf048192008-03-06 13:46:43 +110086 mark_inode_dirty_sync(inode);
David Chinner5d51eff2007-11-23 16:29:18 +110087}
88
89/*
Nathan Scott4aeb6642005-11-02 11:43:58 +110090 * Change the requested timestamp in the given inode.
91 * We don't lock across timestamp updates, and we don't log them but
92 * we do record the fact that there is dirty information in core.
Nathan Scott4aeb6642005-11-02 11:43:58 +110093 */
94void
95xfs_ichgtime(
96 xfs_inode_t *ip,
97 int flags)
98{
David Chinnere4f75292008-08-13 16:00:45 +100099 struct inode *inode = VFS_I(ip);
Nathan Scott4aeb6642005-11-02 11:43:58 +1100100 timespec_t tv;
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000101 int sync_it = 0;
Nathan Scott4aeb6642005-11-02 11:43:58 +1100102
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000103 tv = current_fs_time(inode->i_sb);
104
105 if ((flags & XFS_ICHGTIME_MOD) &&
106 !timespec_equal(&inode->i_mtime, &tv)) {
Nathan Scott4aeb6642005-11-02 11:43:58 +1100107 inode->i_mtime = tv;
108 ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
109 ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000110 sync_it = 1;
Nathan Scott4aeb6642005-11-02 11:43:58 +1100111 }
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000112 if ((flags & XFS_ICHGTIME_CHG) &&
113 !timespec_equal(&inode->i_ctime, &tv)) {
Nathan Scott4aeb6642005-11-02 11:43:58 +1100114 inode->i_ctime = tv;
115 ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
116 ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000117 sync_it = 1;
Nathan Scott4aeb6642005-11-02 11:43:58 +1100118 }
119
120 /*
121 * We update the i_update_core field _after_ changing
122 * the timestamps in order to coordinate properly with
123 * xfs_iflush() so that we don't lose timestamp updates.
124 * This keeps us from having to hold the inode lock
125 * while doing this. We use the SYNCHRONIZE macro to
126 * ensure that the compiler does not reorder the update
127 * of i_update_core above the timestamp updates above.
128 */
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000129 if (sync_it) {
130 SYNCHRONIZE();
131 ip->i_update_core = 1;
David Chinner94b97e32008-10-30 17:21:30 +1100132 xfs_mark_inode_dirty_sync(ip);
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000133 }
Nathan Scott4aeb6642005-11-02 11:43:58 +1100134}
135
136/*
Nathan Scott446ada42006-01-11 15:35:44 +1100137 * Hook in SELinux. This is not quite correct yet, what we really need
138 * here (as we do for default ACLs) is a mechanism by which creation of
139 * these attrs can be journalled at inode creation time (along with the
140 * inode, of course, such that log replay can't cause these to be lost).
141 */
142STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100143xfs_init_security(
Christoph Hellwigaf048192008-03-06 13:46:43 +1100144 struct inode *inode,
Nathan Scott446ada42006-01-11 15:35:44 +1100145 struct inode *dir)
146{
Christoph Hellwigaf048192008-03-06 13:46:43 +1100147 struct xfs_inode *ip = XFS_I(inode);
Nathan Scott446ada42006-01-11 15:35:44 +1100148 size_t length;
149 void *value;
150 char *name;
151 int error;
152
Christoph Hellwigaf048192008-03-06 13:46:43 +1100153 error = security_inode_init_security(inode, dir, &name,
154 &value, &length);
Nathan Scott446ada42006-01-11 15:35:44 +1100155 if (error) {
156 if (error == -EOPNOTSUPP)
157 return 0;
158 return -error;
159 }
160
Christoph Hellwigaf048192008-03-06 13:46:43 +1100161 error = xfs_attr_set(ip, name, value, length, ATTR_SECURE);
Nathan Scott446ada42006-01-11 15:35:44 +1100162
163 kfree(name);
164 kfree(value);
165 return error;
166}
167
Barry Naujok556b8b12008-04-10 12:22:07 +1000168static void
169xfs_dentry_to_name(
170 struct xfs_name *namep,
171 struct dentry *dentry)
172{
173 namep->name = dentry->d_name.name;
174 namep->len = dentry->d_name.len;
175}
176
David Chinner7989cb82007-02-10 18:34:56 +1100177STATIC void
Nathan Scott416c6d52006-03-14 14:00:51 +1100178xfs_cleanup_inode(
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000179 struct inode *dir,
Christoph Hellwigaf048192008-03-06 13:46:43 +1100180 struct inode *inode,
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000181 struct dentry *dentry)
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100182{
Barry Naujok556b8b12008-04-10 12:22:07 +1000183 struct xfs_name teardown;
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100184
185 /* Oh, the horror.
Nathan Scott220b5282006-03-14 13:33:36 +1100186 * If we can't add the ACL or we fail in
Nathan Scott416c6d52006-03-14 14:00:51 +1100187 * xfs_init_security we must back out.
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100188 * ENOSPC can hit here, among other things.
189 */
Barry Naujok556b8b12008-04-10 12:22:07 +1000190 xfs_dentry_to_name(&teardown, dentry);
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100191
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000192 xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
Christoph Hellwigaf048192008-03-06 13:46:43 +1100193 iput(inode);
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100194}
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100197xfs_vn_mknod(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 struct inode *dir,
199 struct dentry *dentry,
200 int mode,
201 dev_t rdev)
202{
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100203 struct inode *inode;
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100204 struct xfs_inode *ip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 xfs_acl_t *default_acl = NULL;
Barry Naujok556b8b12008-04-10 12:22:07 +1000206 struct xfs_name name;
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000207 int (*test_default_acl)(struct inode *) = _ACL_DEFAULT_EXISTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 int error;
209
210 /*
211 * Irix uses Missed'em'V split, but doesn't want to see
212 * the upper 5 bits of (14bit) major.
213 */
Christoph Hellwig517b5e82009-02-09 08:38:02 +0100214 if (S_ISCHR(mode) || S_ISBLK(mode)) {
215 if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
216 return -EINVAL;
217 rdev = sysv_encode_dev(rdev);
218 } else {
219 rdev = 0;
220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100222 if (test_default_acl && test_default_acl(dir)) {
Nathan Scott220b5282006-03-14 13:33:36 +1100223 if (!_ACL_ALLOC(default_acl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 return -ENOMEM;
Nathan Scott220b5282006-03-14 13:33:36 +1100225 }
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100226 if (!_ACL_GET_DEFAULT(dir, default_acl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 _ACL_FREE(default_acl);
228 default_acl = NULL;
229 }
230 }
231
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100232 if (IS_POSIXACL(dir) && !default_acl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 mode &= ~current->fs->umask;
234
Christoph Hellwig517b5e82009-02-09 08:38:02 +0100235 xfs_dentry_to_name(&name, dentry);
236 error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip, NULL);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100237 if (unlikely(error))
238 goto out_free_acl;
Nathan Scott446ada42006-01-11 15:35:44 +1100239
David Chinner01651642008-08-13 15:45:15 +1000240 inode = VFS_I(ip);
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100241
242 error = xfs_init_security(inode, dir);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100243 if (unlikely(error))
244 goto out_cleanup_inode;
245
246 if (default_acl) {
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100247 error = _ACL_INHERIT(inode, mode, default_acl);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100248 if (unlikely(error))
249 goto out_cleanup_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 _ACL_FREE(default_acl);
251 }
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100254 d_instantiate(dentry, inode);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100255 return -error;
256
257 out_cleanup_inode:
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000258 xfs_cleanup_inode(dir, inode, dentry);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100259 out_free_acl:
260 if (default_acl)
261 _ACL_FREE(default_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 return -error;
263}
264
265STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100266xfs_vn_create(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 struct inode *dir,
268 struct dentry *dentry,
269 int mode,
270 struct nameidata *nd)
271{
Nathan Scott416c6d52006-03-14 14:00:51 +1100272 return xfs_vn_mknod(dir, dentry, mode, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274
275STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100276xfs_vn_mkdir(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 struct inode *dir,
278 struct dentry *dentry,
279 int mode)
280{
Nathan Scott416c6d52006-03-14 14:00:51 +1100281 return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
284STATIC struct dentry *
Nathan Scott416c6d52006-03-14 14:00:51 +1100285xfs_vn_lookup(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 struct inode *dir,
287 struct dentry *dentry,
288 struct nameidata *nd)
289{
Christoph Hellwigef1f5e72008-03-06 13:46:25 +1100290 struct xfs_inode *cip;
Barry Naujok556b8b12008-04-10 12:22:07 +1000291 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 int error;
293
294 if (dentry->d_name.len >= MAXNAMELEN)
295 return ERR_PTR(-ENAMETOOLONG);
296
Barry Naujok556b8b12008-04-10 12:22:07 +1000297 xfs_dentry_to_name(&name, dentry);
Barry Naujok384f3ce2008-05-21 16:58:22 +1000298 error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
Nathan Scott67fcaa72006-06-09 17:00:52 +1000299 if (unlikely(error)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 if (unlikely(error != ENOENT))
301 return ERR_PTR(-error);
302 d_add(dentry, NULL);
303 return NULL;
304 }
305
David Chinner01651642008-08-13 15:45:15 +1000306 return d_splice_alias(VFS_I(cip), dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
Barry Naujok384f3ce2008-05-21 16:58:22 +1000309STATIC struct dentry *
310xfs_vn_ci_lookup(
311 struct inode *dir,
312 struct dentry *dentry,
313 struct nameidata *nd)
314{
315 struct xfs_inode *ip;
316 struct xfs_name xname;
317 struct xfs_name ci_name;
318 struct qstr dname;
319 int error;
320
321 if (dentry->d_name.len >= MAXNAMELEN)
322 return ERR_PTR(-ENAMETOOLONG);
323
324 xfs_dentry_to_name(&xname, dentry);
325 error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name);
326 if (unlikely(error)) {
327 if (unlikely(error != ENOENT))
328 return ERR_PTR(-error);
Barry Naujok866d5dc2008-05-22 17:21:40 +1000329 /*
330 * call d_add(dentry, NULL) here when d_drop_negative_children
331 * is called in xfs_vn_mknod (ie. allow negative dentries
332 * with CI filesystems).
333 */
Barry Naujok384f3ce2008-05-21 16:58:22 +1000334 return NULL;
335 }
336
337 /* if exact match, just splice and exit */
338 if (!ci_name.name)
David Chinner01651642008-08-13 15:45:15 +1000339 return d_splice_alias(VFS_I(ip), dentry);
Barry Naujok384f3ce2008-05-21 16:58:22 +1000340
341 /* else case-insensitive match... */
342 dname.name = ci_name.name;
343 dname.len = ci_name.len;
Christoph Hellwige45b5902008-08-07 23:49:07 +0200344 dentry = d_add_ci(dentry, VFS_I(ip), &dname);
Barry Naujok384f3ce2008-05-21 16:58:22 +1000345 kmem_free(ci_name.name);
346 return dentry;
347}
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100350xfs_vn_link(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 struct dentry *old_dentry,
352 struct inode *dir,
353 struct dentry *dentry)
354{
Christoph Hellwigd9424b32008-12-03 12:20:27 +0100355 struct inode *inode = old_dentry->d_inode;
Barry Naujok556b8b12008-04-10 12:22:07 +1000356 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 int error;
358
Barry Naujok556b8b12008-04-10 12:22:07 +1000359 xfs_dentry_to_name(&name, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Barry Naujok556b8b12008-04-10 12:22:07 +1000361 error = xfs_link(XFS_I(dir), XFS_I(inode), &name);
Christoph Hellwigd9424b32008-12-03 12:20:27 +0100362 if (unlikely(error))
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100363 return -error;
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100364
Christoph Hellwigd9424b32008-12-03 12:20:27 +0100365 atomic_inc(&inode->i_count);
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100366 d_instantiate(dentry, inode);
367 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
370STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100371xfs_vn_unlink(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 struct inode *dir,
373 struct dentry *dentry)
374{
Barry Naujok556b8b12008-04-10 12:22:07 +1000375 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 int error;
377
Barry Naujok556b8b12008-04-10 12:22:07 +1000378 xfs_dentry_to_name(&name, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Christoph Hellwige5700702008-06-23 13:25:25 +1000380 error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
381 if (error)
382 return error;
383
384 /*
385 * With unlink, the VFS makes the dentry "negative": no inode,
386 * but still hashed. This is incompatible with case-insensitive
387 * mode, so invalidate (unhash) the dentry in CI-mode.
388 */
389 if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
390 d_invalidate(dentry);
391 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392}
393
394STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100395xfs_vn_symlink(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 struct inode *dir,
397 struct dentry *dentry,
398 const char *symname)
399{
Christoph Hellwig3937be52008-03-06 13:46:19 +1100400 struct inode *inode;
401 struct xfs_inode *cip = NULL;
Barry Naujok556b8b12008-04-10 12:22:07 +1000402 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 int error;
Christoph Hellwig3e5daf02007-10-11 18:09:12 +1000404 mode_t mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Christoph Hellwig3e5daf02007-10-11 18:09:12 +1000406 mode = S_IFLNK |
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000407 (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
Barry Naujok556b8b12008-04-10 12:22:07 +1000408 xfs_dentry_to_name(&name, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Barry Naujok556b8b12008-04-10 12:22:07 +1000410 error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip, NULL);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100411 if (unlikely(error))
412 goto out;
413
David Chinner01651642008-08-13 15:45:15 +1000414 inode = VFS_I(cip);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100415
416 error = xfs_init_security(inode, dir);
417 if (unlikely(error))
418 goto out_cleanup_inode;
419
420 d_instantiate(dentry, inode);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100421 return 0;
422
423 out_cleanup_inode:
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000424 xfs_cleanup_inode(dir, inode, dentry);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100425 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 return -error;
427}
428
429STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100430xfs_vn_rename(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 struct inode *odir,
432 struct dentry *odentry,
433 struct inode *ndir,
434 struct dentry *ndentry)
435{
436 struct inode *new_inode = ndentry->d_inode;
Barry Naujok556b8b12008-04-10 12:22:07 +1000437 struct xfs_name oname;
438 struct xfs_name nname;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Barry Naujok556b8b12008-04-10 12:22:07 +1000440 xfs_dentry_to_name(&oname, odentry);
441 xfs_dentry_to_name(&nname, ndentry);
442
Christoph Hellwige5700702008-06-23 13:25:25 +1000443 return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
Christoph Hellwigcfa853e2008-04-22 17:34:06 +1000444 XFS_I(ndir), &nname, new_inode ?
445 XFS_I(new_inode) : NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
448/*
449 * careful here - this function can get called recursively, so
450 * we need to be very careful about how much stack we use.
451 * uio is kmalloced for this reason...
452 */
Al Viro008b1502005-08-20 00:17:39 +0100453STATIC void *
Nathan Scott416c6d52006-03-14 14:00:51 +1100454xfs_vn_follow_link(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 struct dentry *dentry,
456 struct nameidata *nd)
457{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 char *link;
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000459 int error = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Panagiotis Issarisf52720c2006-09-27 01:49:39 -0700461 link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000462 if (!link)
463 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000465 error = -xfs_readlink(XFS_I(dentry->d_inode), link);
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000466 if (unlikely(error))
467 goto out_kfree;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 nd_set_link(nd, link);
Al Viro008b1502005-08-20 00:17:39 +0100470 return NULL;
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000471
472 out_kfree:
473 kfree(link);
474 out_err:
475 nd_set_link(nd, ERR_PTR(error));
476 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
Nathan Scottcde410a2005-09-05 11:47:01 +1000479STATIC void
Nathan Scott416c6d52006-03-14 14:00:51 +1100480xfs_vn_put_link(
Nathan Scottcde410a2005-09-05 11:47:01 +1000481 struct dentry *dentry,
482 struct nameidata *nd,
483 void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
Nathan Scottcde410a2005-09-05 11:47:01 +1000485 char *s = nd_get_link(nd);
486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 if (!IS_ERR(s))
488 kfree(s);
489}
490
491#ifdef CONFIG_XFS_POSIX_ACL
492STATIC int
Christoph Hellwig45767582008-02-05 12:13:24 +1100493xfs_check_acl(
494 struct inode *inode,
495 int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Christoph Hellwig45767582008-02-05 12:13:24 +1100497 struct xfs_inode *ip = XFS_I(inode);
498 int error;
499
500 xfs_itrace_entry(ip);
501
502 if (XFS_IFORK_Q(ip)) {
503 error = xfs_acl_iaccess(ip, mask, NULL);
504 if (error != -1)
505 return -error;
506 }
507
508 return -EAGAIN;
509}
510
511STATIC int
512xfs_vn_permission(
513 struct inode *inode,
Al Viroe6305c42008-07-15 21:03:57 -0400514 int mask)
Christoph Hellwig45767582008-02-05 12:13:24 +1100515{
516 return generic_permission(inode, mask, xfs_check_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518#else
Nathan Scott416c6d52006-03-14 14:00:51 +1100519#define xfs_vn_permission NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#endif
521
522STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100523xfs_vn_getattr(
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000524 struct vfsmount *mnt,
525 struct dentry *dentry,
526 struct kstat *stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000528 struct inode *inode = dentry->d_inode;
529 struct xfs_inode *ip = XFS_I(inode);
530 struct xfs_mount *mp = ip->i_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000532 xfs_itrace_entry(ip);
533
534 if (XFS_FORCED_SHUTDOWN(mp))
535 return XFS_ERROR(EIO);
536
537 stat->size = XFS_ISIZE(ip);
538 stat->dev = inode->i_sb->s_dev;
539 stat->mode = ip->i_d.di_mode;
540 stat->nlink = ip->i_d.di_nlink;
541 stat->uid = ip->i_d.di_uid;
542 stat->gid = ip->i_d.di_gid;
543 stat->ino = ip->i_ino;
544#if XFS_BIG_INUMS
545 stat->ino += mp->m_inoadd;
546#endif
547 stat->atime = inode->i_atime;
548 stat->mtime.tv_sec = ip->i_d.di_mtime.t_sec;
549 stat->mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
550 stat->ctime.tv_sec = ip->i_d.di_ctime.t_sec;
551 stat->ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
552 stat->blocks =
553 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
554
555
556 switch (inode->i_mode & S_IFMT) {
557 case S_IFBLK:
558 case S_IFCHR:
559 stat->blksize = BLKDEV_IOSIZE;
560 stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
561 sysv_minor(ip->i_df.if_u2.if_rdev));
562 break;
563 default:
Eric Sandeen71ddabb2007-11-23 16:29:42 +1100564 if (XFS_IS_REALTIME_INODE(ip)) {
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000565 /*
566 * If the file blocks are being allocated from a
567 * realtime volume, then return the inode's realtime
568 * extent size or the realtime volume's extent size.
569 */
570 stat->blksize =
571 xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
572 } else
573 stat->blksize = xfs_preferred_iosize(mp);
574 stat->rdev = 0;
575 break;
Nathan Scott69e23b92006-09-28 11:01:22 +1000576 }
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000577
578 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579}
580
581STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100582xfs_vn_setattr(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 struct dentry *dentry,
Christoph Hellwig0f285c82008-07-18 17:13:28 +1000584 struct iattr *iattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585{
Christoph Hellwigea5a3dc82008-10-30 18:27:48 +1100586 return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
588
David Chinnerd87dd632008-04-10 12:21:46 +1000589/*
590 * block_truncate_page can return an error, but we can't propagate it
591 * at all here. Leave a complaint + stack trace in the syslog because
592 * this could be bad. If it is bad, we need to propagate the error further.
593 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594STATIC void
Nathan Scott416c6d52006-03-14 14:00:51 +1100595xfs_vn_truncate(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 struct inode *inode)
597{
David Chinnerd87dd632008-04-10 12:21:46 +1000598 int error;
599 error = block_truncate_page(inode->i_mapping, inode->i_size,
600 xfs_get_blocks);
601 WARN_ON(error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
603
David Chinner3ed65262007-11-23 16:29:25 +1100604STATIC long
605xfs_vn_fallocate(
606 struct inode *inode,
607 int mode,
608 loff_t offset,
609 loff_t len)
610{
611 long error;
612 loff_t new_size = 0;
613 xfs_flock64_t bf;
614 xfs_inode_t *ip = XFS_I(inode);
615
616 /* preallocation on directories not yet supported */
617 error = -ENODEV;
618 if (S_ISDIR(inode->i_mode))
619 goto out_error;
620
621 bf.l_whence = 0;
622 bf.l_start = offset;
623 bf.l_len = len;
624
625 xfs_ilock(ip, XFS_IOLOCK_EXCL);
626 error = xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf,
Christoph Hellwigea5a3dc82008-10-30 18:27:48 +1100627 0, XFS_ATTR_NOLOCK);
David Chinner3ed65262007-11-23 16:29:25 +1100628 if (!error && !(mode & FALLOC_FL_KEEP_SIZE) &&
629 offset + len > i_size_read(inode))
630 new_size = offset + len;
631
632 /* Change file size if needed */
633 if (new_size) {
Christoph Hellwig0f285c82008-07-18 17:13:28 +1000634 struct iattr iattr;
David Chinner3ed65262007-11-23 16:29:25 +1100635
Christoph Hellwig0f285c82008-07-18 17:13:28 +1000636 iattr.ia_valid = ATTR_SIZE;
637 iattr.ia_size = new_size;
Christoph Hellwigea5a3dc82008-10-30 18:27:48 +1100638 error = xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK);
David Chinner3ed65262007-11-23 16:29:25 +1100639 }
640
641 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
642out_error:
643 return error;
644}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Eric Sandeenf35642e2008-11-28 14:23:35 +1100646#define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR)
647
648/*
649 * Call fiemap helper to fill in user data.
650 * Returns positive errors to xfs_getbmap.
651 */
652STATIC int
653xfs_fiemap_format(
654 void **arg,
655 struct getbmapx *bmv,
656 int *full)
657{
658 int error;
659 struct fiemap_extent_info *fieinfo = *arg;
660 u32 fiemap_flags = 0;
661 u64 logical, physical, length;
662
663 /* Do nothing for a hole */
664 if (bmv->bmv_block == -1LL)
665 return 0;
666
667 logical = BBTOB(bmv->bmv_offset);
668 physical = BBTOB(bmv->bmv_block);
669 length = BBTOB(bmv->bmv_length);
670
671 if (bmv->bmv_oflags & BMV_OF_PREALLOC)
672 fiemap_flags |= FIEMAP_EXTENT_UNWRITTEN;
673 else if (bmv->bmv_oflags & BMV_OF_DELALLOC) {
674 fiemap_flags |= FIEMAP_EXTENT_DELALLOC;
675 physical = 0; /* no block yet */
676 }
677 if (bmv->bmv_oflags & BMV_OF_LAST)
678 fiemap_flags |= FIEMAP_EXTENT_LAST;
679
680 error = fiemap_fill_next_extent(fieinfo, logical, physical,
681 length, fiemap_flags);
682 if (error > 0) {
683 error = 0;
684 *full = 1; /* user array now full */
685 }
686
687 return -error;
688}
689
690STATIC int
691xfs_vn_fiemap(
692 struct inode *inode,
693 struct fiemap_extent_info *fieinfo,
694 u64 start,
695 u64 length)
696{
697 xfs_inode_t *ip = XFS_I(inode);
698 struct getbmapx bm;
699 int error;
700
701 error = fiemap_check_flags(fieinfo, XFS_FIEMAP_FLAGS);
702 if (error)
703 return error;
704
705 /* Set up bmap header for xfs internal routine */
706 bm.bmv_offset = BTOBB(start);
707 /* Special case for whole file */
708 if (length == FIEMAP_MAX_OFFSET)
709 bm.bmv_length = -1LL;
710 else
711 bm.bmv_length = BTOBB(length);
712
713 /* our formatter will tell xfs_getbmap when to stop. */
714 bm.bmv_count = MAXEXTNUM;
715 bm.bmv_iflags = BMV_IF_PREALLOC;
716 if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR)
717 bm.bmv_iflags |= BMV_IF_ATTRFORK;
718 if (!(fieinfo->fi_flags & FIEMAP_FLAG_SYNC))
719 bm.bmv_iflags |= BMV_IF_DELALLOC;
720
721 error = xfs_getbmap(ip, &bm, xfs_fiemap_format, fieinfo);
722 if (error)
723 return -error;
724
725 return 0;
726}
727
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000728static const struct inode_operations xfs_inode_operations = {
Nathan Scott416c6d52006-03-14 14:00:51 +1100729 .permission = xfs_vn_permission,
730 .truncate = xfs_vn_truncate,
731 .getattr = xfs_vn_getattr,
732 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000733 .setxattr = generic_setxattr,
734 .getxattr = generic_getxattr,
735 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +1100736 .listxattr = xfs_vn_listxattr,
David Chinner3ed65262007-11-23 16:29:25 +1100737 .fallocate = xfs_vn_fallocate,
Eric Sandeenf35642e2008-11-28 14:23:35 +1100738 .fiemap = xfs_vn_fiemap,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739};
740
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000741static const struct inode_operations xfs_dir_inode_operations = {
Nathan Scott416c6d52006-03-14 14:00:51 +1100742 .create = xfs_vn_create,
743 .lookup = xfs_vn_lookup,
744 .link = xfs_vn_link,
745 .unlink = xfs_vn_unlink,
746 .symlink = xfs_vn_symlink,
747 .mkdir = xfs_vn_mkdir,
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000748 /*
749 * Yes, XFS uses the same method for rmdir and unlink.
750 *
751 * There are some subtile differences deeper in the code,
752 * but we use S_ISDIR to check for those.
753 */
754 .rmdir = xfs_vn_unlink,
Nathan Scott416c6d52006-03-14 14:00:51 +1100755 .mknod = xfs_vn_mknod,
756 .rename = xfs_vn_rename,
757 .permission = xfs_vn_permission,
758 .getattr = xfs_vn_getattr,
759 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000760 .setxattr = generic_setxattr,
761 .getxattr = generic_getxattr,
762 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +1100763 .listxattr = xfs_vn_listxattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764};
765
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000766static const struct inode_operations xfs_dir_ci_inode_operations = {
Barry Naujok384f3ce2008-05-21 16:58:22 +1000767 .create = xfs_vn_create,
768 .lookup = xfs_vn_ci_lookup,
769 .link = xfs_vn_link,
770 .unlink = xfs_vn_unlink,
771 .symlink = xfs_vn_symlink,
772 .mkdir = xfs_vn_mkdir,
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000773 /*
774 * Yes, XFS uses the same method for rmdir and unlink.
775 *
776 * There are some subtile differences deeper in the code,
777 * but we use S_ISDIR to check for those.
778 */
779 .rmdir = xfs_vn_unlink,
Barry Naujok384f3ce2008-05-21 16:58:22 +1000780 .mknod = xfs_vn_mknod,
781 .rename = xfs_vn_rename,
782 .permission = xfs_vn_permission,
783 .getattr = xfs_vn_getattr,
784 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000785 .setxattr = generic_setxattr,
786 .getxattr = generic_getxattr,
787 .removexattr = generic_removexattr,
Barry Naujok384f3ce2008-05-21 16:58:22 +1000788 .listxattr = xfs_vn_listxattr,
Barry Naujok384f3ce2008-05-21 16:58:22 +1000789};
790
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000791static const struct inode_operations xfs_symlink_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .readlink = generic_readlink,
Nathan Scott416c6d52006-03-14 14:00:51 +1100793 .follow_link = xfs_vn_follow_link,
794 .put_link = xfs_vn_put_link,
795 .permission = xfs_vn_permission,
796 .getattr = xfs_vn_getattr,
797 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000798 .setxattr = generic_setxattr,
799 .getxattr = generic_getxattr,
800 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +1100801 .listxattr = xfs_vn_listxattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802};
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000803
804STATIC void
805xfs_diflags_to_iflags(
806 struct inode *inode,
807 struct xfs_inode *ip)
808{
809 if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
810 inode->i_flags |= S_IMMUTABLE;
811 else
812 inode->i_flags &= ~S_IMMUTABLE;
813 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
814 inode->i_flags |= S_APPEND;
815 else
816 inode->i_flags &= ~S_APPEND;
817 if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
818 inode->i_flags |= S_SYNC;
819 else
820 inode->i_flags &= ~S_SYNC;
821 if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
822 inode->i_flags |= S_NOATIME;
823 else
824 inode->i_flags &= ~S_NOATIME;
825}
826
827/*
828 * Initialize the Linux inode, set up the operation vectors and
829 * unlock the inode.
830 *
831 * When reading existing inodes from disk this is called directly
832 * from xfs_iget, when creating a new inode it is called from
833 * xfs_ialloc after setting up the inode.
David Chinnerbf904242008-10-30 17:36:14 +1100834 *
835 * We are always called with an uninitialised linux inode here.
836 * We need to initialise the necessary fields and take a reference
837 * on it.
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000838 */
839void
840xfs_setup_inode(
841 struct xfs_inode *ip)
842{
David Chinnerbf904242008-10-30 17:36:14 +1100843 struct inode *inode = &ip->i_vnode;
844
845 inode->i_ino = ip->i_ino;
846 inode->i_state = I_NEW|I_LOCK;
847 inode_add_to_lists(ip->i_mount->m_super, inode);
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000848
849 inode->i_mode = ip->i_d.di_mode;
850 inode->i_nlink = ip->i_d.di_nlink;
851 inode->i_uid = ip->i_d.di_uid;
852 inode->i_gid = ip->i_d.di_gid;
853
854 switch (inode->i_mode & S_IFMT) {
855 case S_IFBLK:
856 case S_IFCHR:
857 inode->i_rdev =
858 MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
859 sysv_minor(ip->i_df.if_u2.if_rdev));
860 break;
861 default:
862 inode->i_rdev = 0;
863 break;
864 }
865
866 inode->i_generation = ip->i_d.di_gen;
867 i_size_write(inode, ip->i_d.di_size);
868 inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
869 inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
870 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
871 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
872 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
873 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
874 xfs_diflags_to_iflags(inode, ip);
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000875
876 switch (inode->i_mode & S_IFMT) {
877 case S_IFREG:
878 inode->i_op = &xfs_inode_operations;
879 inode->i_fop = &xfs_file_operations;
880 inode->i_mapping->a_ops = &xfs_address_space_operations;
881 break;
882 case S_IFDIR:
883 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
884 inode->i_op = &xfs_dir_ci_inode_operations;
885 else
886 inode->i_op = &xfs_dir_inode_operations;
887 inode->i_fop = &xfs_dir_file_operations;
888 break;
889 case S_IFLNK:
890 inode->i_op = &xfs_symlink_inode_operations;
891 if (!(ip->i_df.if_flags & XFS_IFINLINE))
892 inode->i_mapping->a_ops = &xfs_address_space_operations;
893 break;
894 default:
895 inode->i_op = &xfs_inode_operations;
896 init_special_inode(inode, inode->i_mode, inode->i_rdev);
897 break;
898 }
899
900 xfs_iflags_clear(ip, XFS_INEW);
901 barrier();
902
903 unlock_new_inode(inode);
904}