blob: cb06cc4d0003166031931e98ea2b5728cd6fd244 [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"
Dave Chinner70a9883c2013-10-23 10:36:05 +110020#include "xfs_shared.h"
Dave Chinner239880e2013-10-23 10:50:10 +110021#include "xfs_format.h"
22#include "xfs_log_format.h"
23#include "xfs_trans_resv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "xfs_sb.h"
25#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_mount.h"
Dave Chinner57062782013-10-15 09:17:51 +110027#include "xfs_da_format.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include "xfs_inode.h"
29#include "xfs_bmap.h"
Dave Chinner68988112013-08-12 20:49:42 +100030#include "xfs_bmap_util.h"
Dave Chinner239880e2013-10-23 10:50:10 +110031#include "xfs_acl.h"
Dave Chinner239880e2013-10-23 10:50:10 +110032#include "xfs_quota.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "xfs_error.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_attr.h"
Dave Chinner239880e2013-10-23 10:50:10 +110035#include "xfs_trans.h"
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000036#include "xfs_trace.h"
Brian Foster27b52862012-11-06 09:50:38 -050037#include "xfs_icache.h"
Dave Chinnerc24b5df2013-08-12 20:49:45 +100038#include "xfs_symlink.h"
Dave Chinner0cb97762013-08-12 20:50:09 +100039#include "xfs_da_btree.h"
Dave Chinner0cb97762013-08-12 20:50:09 +100040#include "xfs_dir2_priv.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110041#include "xfs_dinode.h"
Zhi Yong Wu99b64362013-12-18 08:22:40 +080042#include "xfs_trans_space.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Randy Dunlap16f7e0f2006-01-11 12:17:46 -080044#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/xattr.h>
46#include <linux/namei.h>
Christoph Hellwigef14f0c2009-06-10 17:07:47 +020047#include <linux/posix_acl.h>
Nathan Scott446ada42006-01-11 15:35:44 +110048#include <linux/security.h>
Eric Sandeenf35642e2008-11-28 14:23:35 +110049#include <linux/fiemap.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090050#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Dave Chinner8d2a5e62012-03-07 04:50:19 +000052static int
53xfs_initxattrs(
54 struct inode *inode,
55 const struct xattr *xattr_array,
56 void *fs_info)
Mimi Zohar9d8f13b2011-06-06 15:29:25 -040057{
Dave Chinner8d2a5e62012-03-07 04:50:19 +000058 const struct xattr *xattr;
59 struct xfs_inode *ip = XFS_I(inode);
60 int error = 0;
Mimi Zohar9d8f13b2011-06-06 15:29:25 -040061
62 for (xattr = xattr_array; xattr->name != NULL; xattr++) {
63 error = xfs_attr_set(ip, xattr->name, xattr->value,
64 xattr->value_len, ATTR_SECURE);
65 if (error < 0)
66 break;
67 }
68 return error;
69}
70
David Chinner5d51eff2007-11-23 16:29:18 +110071/*
Nathan Scott446ada42006-01-11 15:35:44 +110072 * Hook in SELinux. This is not quite correct yet, what we really need
73 * here (as we do for default ACLs) is a mechanism by which creation of
74 * these attrs can be journalled at inode creation time (along with the
75 * inode, of course, such that log replay can't cause these to be lost).
76 */
Mimi Zohar9d8f13b2011-06-06 15:29:25 -040077
Nathan Scott446ada42006-01-11 15:35:44 +110078STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +110079xfs_init_security(
Christoph Hellwigaf048192008-03-06 13:46:43 +110080 struct inode *inode,
Eric Paris2a7dba32011-02-01 11:05:39 -050081 struct inode *dir,
82 const struct qstr *qstr)
Nathan Scott446ada42006-01-11 15:35:44 +110083{
Mimi Zohar9d8f13b2011-06-06 15:29:25 -040084 return security_inode_init_security(inode, dir, qstr,
85 &xfs_initxattrs, NULL);
Nathan Scott446ada42006-01-11 15:35:44 +110086}
87
Barry Naujok556b8b12008-04-10 12:22:07 +100088static void
89xfs_dentry_to_name(
90 struct xfs_name *namep,
Dave Chinner0cb97762013-08-12 20:50:09 +100091 struct dentry *dentry,
92 int mode)
Barry Naujok556b8b12008-04-10 12:22:07 +100093{
94 namep->name = dentry->d_name.name;
95 namep->len = dentry->d_name.len;
Dave Chinner0cb97762013-08-12 20:50:09 +100096 namep->type = xfs_mode_to_ftype[(mode & S_IFMT) >> S_SHIFT];
Barry Naujok556b8b12008-04-10 12:22:07 +100097}
98
David Chinner7989cb82007-02-10 18:34:56 +110099STATIC void
Nathan Scott416c6d52006-03-14 14:00:51 +1100100xfs_cleanup_inode(
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000101 struct inode *dir,
Christoph Hellwigaf048192008-03-06 13:46:43 +1100102 struct inode *inode,
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000103 struct dentry *dentry)
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100104{
Barry Naujok556b8b12008-04-10 12:22:07 +1000105 struct xfs_name teardown;
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100106
107 /* Oh, the horror.
Nathan Scott220b5282006-03-14 13:33:36 +1100108 * If we can't add the ACL or we fail in
Nathan Scott416c6d52006-03-14 14:00:51 +1100109 * xfs_init_security we must back out.
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100110 * ENOSPC can hit here, among other things.
111 */
Dave Chinner0cb97762013-08-12 20:50:09 +1000112 xfs_dentry_to_name(&teardown, dentry, 0);
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100113
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000114 xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
Christoph Hellwigaf048192008-03-06 13:46:43 +1100115 iput(inode);
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100116}
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100119xfs_vn_mknod(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 struct inode *dir,
121 struct dentry *dentry,
Al Viro1a67aaf2011-07-26 01:52:52 -0400122 umode_t mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 dev_t rdev)
124{
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100125 struct inode *inode;
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100126 struct xfs_inode *ip = NULL;
Christoph Hellwigef14f0c2009-06-10 17:07:47 +0200127 struct posix_acl *default_acl = NULL;
Barry Naujok556b8b12008-04-10 12:22:07 +1000128 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 int error;
130
131 /*
132 * Irix uses Missed'em'V split, but doesn't want to see
133 * the upper 5 bits of (14bit) major.
134 */
Christoph Hellwig517b5e82009-02-09 08:38:02 +0100135 if (S_ISCHR(mode) || S_ISBLK(mode)) {
136 if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
137 return -EINVAL;
138 rdev = sysv_encode_dev(rdev);
139 } else {
140 rdev = 0;
141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Christoph Hellwigef14f0c2009-06-10 17:07:47 +0200143 if (IS_POSIXACL(dir)) {
144 default_acl = xfs_get_acl(dir, ACL_TYPE_DEFAULT);
145 if (IS_ERR(default_acl))
Al Viroc46a1312011-06-05 11:12:31 +0000146 return PTR_ERR(default_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Christoph Hellwige83f1eb2009-06-12 11:19:11 -0400148 if (!default_acl)
149 mode &= ~current_umask();
Christoph Hellwigef14f0c2009-06-10 17:07:47 +0200150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Dave Chinner0cb97762013-08-12 20:50:09 +1000152 xfs_dentry_to_name(&name, dentry, mode);
Christoph Hellwig6c77b0e2010-10-06 18:41:17 +0000153 error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100154 if (unlikely(error))
155 goto out_free_acl;
Nathan Scott446ada42006-01-11 15:35:44 +1100156
David Chinner01651642008-08-13 15:45:15 +1000157 inode = VFS_I(ip);
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100158
Eric Paris2a7dba32011-02-01 11:05:39 -0500159 error = xfs_init_security(inode, dir, &dentry->d_name);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100160 if (unlikely(error))
161 goto out_cleanup_inode;
162
163 if (default_acl) {
Christoph Hellwigef14f0c2009-06-10 17:07:47 +0200164 error = -xfs_inherit_acl(inode, default_acl);
Al Viro826cae22011-07-23 03:10:32 -0400165 default_acl = NULL;
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100166 if (unlikely(error))
167 goto out_cleanup_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100171 d_instantiate(dentry, inode);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100172 return -error;
173
174 out_cleanup_inode:
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000175 xfs_cleanup_inode(dir, inode, dentry);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100176 out_free_acl:
Christoph Hellwigef14f0c2009-06-10 17:07:47 +0200177 posix_acl_release(default_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return -error;
179}
180
181STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100182xfs_vn_create(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 struct inode *dir,
184 struct dentry *dentry,
Al Viro4acdaf22011-07-26 01:42:34 -0400185 umode_t mode,
Al Viroebfc3b42012-06-10 18:05:36 -0400186 bool flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
Nathan Scott416c6d52006-03-14 14:00:51 +1100188 return xfs_vn_mknod(dir, dentry, mode, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
191STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100192xfs_vn_mkdir(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 struct inode *dir,
194 struct dentry *dentry,
Al Viro18bb1db2011-07-26 01:41:39 -0400195 umode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Nathan Scott416c6d52006-03-14 14:00:51 +1100197 return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
200STATIC struct dentry *
Nathan Scott416c6d52006-03-14 14:00:51 +1100201xfs_vn_lookup(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 struct inode *dir,
203 struct dentry *dentry,
Al Viro00cd8dd2012-06-10 17:13:09 -0400204 unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Christoph Hellwigef1f5e72008-03-06 13:46:25 +1100206 struct xfs_inode *cip;
Barry Naujok556b8b12008-04-10 12:22:07 +1000207 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 int error;
209
210 if (dentry->d_name.len >= MAXNAMELEN)
211 return ERR_PTR(-ENAMETOOLONG);
212
Dave Chinner0cb97762013-08-12 20:50:09 +1000213 xfs_dentry_to_name(&name, dentry, 0);
Barry Naujok384f3ce2008-05-21 16:58:22 +1000214 error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
Nathan Scott67fcaa72006-06-09 17:00:52 +1000215 if (unlikely(error)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 if (unlikely(error != ENOENT))
217 return ERR_PTR(-error);
218 d_add(dentry, NULL);
219 return NULL;
220 }
221
David Chinner01651642008-08-13 15:45:15 +1000222 return d_splice_alias(VFS_I(cip), dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Barry Naujok384f3ce2008-05-21 16:58:22 +1000225STATIC struct dentry *
226xfs_vn_ci_lookup(
227 struct inode *dir,
228 struct dentry *dentry,
Al Viro00cd8dd2012-06-10 17:13:09 -0400229 unsigned int flags)
Barry Naujok384f3ce2008-05-21 16:58:22 +1000230{
231 struct xfs_inode *ip;
232 struct xfs_name xname;
233 struct xfs_name ci_name;
234 struct qstr dname;
235 int error;
236
237 if (dentry->d_name.len >= MAXNAMELEN)
238 return ERR_PTR(-ENAMETOOLONG);
239
Dave Chinner0cb97762013-08-12 20:50:09 +1000240 xfs_dentry_to_name(&xname, dentry, 0);
Barry Naujok384f3ce2008-05-21 16:58:22 +1000241 error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name);
242 if (unlikely(error)) {
243 if (unlikely(error != ENOENT))
244 return ERR_PTR(-error);
Barry Naujok866d5dc2008-05-22 17:21:40 +1000245 /*
246 * call d_add(dentry, NULL) here when d_drop_negative_children
247 * is called in xfs_vn_mknod (ie. allow negative dentries
248 * with CI filesystems).
249 */
Barry Naujok384f3ce2008-05-21 16:58:22 +1000250 return NULL;
251 }
252
253 /* if exact match, just splice and exit */
254 if (!ci_name.name)
David Chinner01651642008-08-13 15:45:15 +1000255 return d_splice_alias(VFS_I(ip), dentry);
Barry Naujok384f3ce2008-05-21 16:58:22 +1000256
257 /* else case-insensitive match... */
258 dname.name = ci_name.name;
259 dname.len = ci_name.len;
Christoph Hellwige45b5902008-08-07 23:49:07 +0200260 dentry = d_add_ci(dentry, VFS_I(ip), &dname);
Barry Naujok384f3ce2008-05-21 16:58:22 +1000261 kmem_free(ci_name.name);
262 return dentry;
263}
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100266xfs_vn_link(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 struct dentry *old_dentry,
268 struct inode *dir,
269 struct dentry *dentry)
270{
Christoph Hellwigd9424b32008-12-03 12:20:27 +0100271 struct inode *inode = old_dentry->d_inode;
Barry Naujok556b8b12008-04-10 12:22:07 +1000272 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 int error;
274
Dave Chinner0cb97762013-08-12 20:50:09 +1000275 xfs_dentry_to_name(&name, dentry, inode->i_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Barry Naujok556b8b12008-04-10 12:22:07 +1000277 error = xfs_link(XFS_I(dir), XFS_I(inode), &name);
Christoph Hellwigd9424b32008-12-03 12:20:27 +0100278 if (unlikely(error))
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100279 return -error;
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100280
Al Viro7de9c6ee2010-10-23 11:11:40 -0400281 ihold(inode);
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100282 d_instantiate(dentry, inode);
283 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284}
285
286STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100287xfs_vn_unlink(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 struct inode *dir,
289 struct dentry *dentry)
290{
Barry Naujok556b8b12008-04-10 12:22:07 +1000291 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 int error;
293
Dave Chinner0cb97762013-08-12 20:50:09 +1000294 xfs_dentry_to_name(&name, dentry, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Christoph Hellwige5700702008-06-23 13:25:25 +1000296 error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
297 if (error)
298 return error;
299
300 /*
301 * With unlink, the VFS makes the dentry "negative": no inode,
302 * but still hashed. This is incompatible with case-insensitive
303 * mode, so invalidate (unhash) the dentry in CI-mode.
304 */
305 if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
306 d_invalidate(dentry);
307 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308}
309
310STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100311xfs_vn_symlink(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 struct inode *dir,
313 struct dentry *dentry,
314 const char *symname)
315{
Christoph Hellwig3937be52008-03-06 13:46:19 +1100316 struct inode *inode;
317 struct xfs_inode *cip = NULL;
Barry Naujok556b8b12008-04-10 12:22:07 +1000318 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 int error;
Al Viro576b1d62011-07-26 02:50:15 -0400320 umode_t mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Christoph Hellwig3e5daf02007-10-11 18:09:12 +1000322 mode = S_IFLNK |
Al Viroce3b0f82009-03-29 19:08:22 -0400323 (irix_symlink_mode ? 0777 & ~current_umask() : S_IRWXUGO);
Dave Chinner0cb97762013-08-12 20:50:09 +1000324 xfs_dentry_to_name(&name, dentry, mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Christoph Hellwig6c77b0e2010-10-06 18:41:17 +0000326 error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100327 if (unlikely(error))
328 goto out;
329
David Chinner01651642008-08-13 15:45:15 +1000330 inode = VFS_I(cip);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100331
Eric Paris2a7dba32011-02-01 11:05:39 -0500332 error = xfs_init_security(inode, dir, &dentry->d_name);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100333 if (unlikely(error))
334 goto out_cleanup_inode;
335
336 d_instantiate(dentry, inode);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100337 return 0;
338
339 out_cleanup_inode:
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000340 xfs_cleanup_inode(dir, inode, dentry);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100341 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 return -error;
343}
344
345STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100346xfs_vn_rename(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 struct inode *odir,
348 struct dentry *odentry,
349 struct inode *ndir,
350 struct dentry *ndentry)
351{
352 struct inode *new_inode = ndentry->d_inode;
Barry Naujok556b8b12008-04-10 12:22:07 +1000353 struct xfs_name oname;
354 struct xfs_name nname;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Dave Chinner0cb97762013-08-12 20:50:09 +1000356 xfs_dentry_to_name(&oname, odentry, 0);
357 xfs_dentry_to_name(&nname, ndentry, odentry->d_inode->i_mode);
Barry Naujok556b8b12008-04-10 12:22:07 +1000358
Christoph Hellwige5700702008-06-23 13:25:25 +1000359 return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
Christoph Hellwigcfa853e2008-04-22 17:34:06 +1000360 XFS_I(ndir), &nname, new_inode ?
Dave Chinner0cb97762013-08-12 20:50:09 +1000361 XFS_I(new_inode) : NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
364/*
365 * careful here - this function can get called recursively, so
366 * we need to be very careful about how much stack we use.
367 * uio is kmalloced for this reason...
368 */
Al Viro008b1502005-08-20 00:17:39 +0100369STATIC void *
Nathan Scott416c6d52006-03-14 14:00:51 +1100370xfs_vn_follow_link(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 struct dentry *dentry,
372 struct nameidata *nd)
373{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 char *link;
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000375 int error = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Panagiotis Issarisf52720c2006-09-27 01:49:39 -0700377 link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000378 if (!link)
379 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000381 error = -xfs_readlink(XFS_I(dentry->d_inode), link);
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000382 if (unlikely(error))
383 goto out_kfree;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 nd_set_link(nd, link);
Al Viro008b1502005-08-20 00:17:39 +0100386 return NULL;
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000387
388 out_kfree:
389 kfree(link);
390 out_err:
391 nd_set_link(nd, ERR_PTR(error));
392 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
394
Nathan Scottcde410a2005-09-05 11:47:01 +1000395STATIC void
Nathan Scott416c6d52006-03-14 14:00:51 +1100396xfs_vn_put_link(
Nathan Scottcde410a2005-09-05 11:47:01 +1000397 struct dentry *dentry,
398 struct nameidata *nd,
399 void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
Nathan Scottcde410a2005-09-05 11:47:01 +1000401 char *s = nd_get_link(nd);
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 if (!IS_ERR(s))
404 kfree(s);
405}
406
Christoph Hellwig45767582008-02-05 12:13:24 +1100407STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100408xfs_vn_getattr(
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000409 struct vfsmount *mnt,
410 struct dentry *dentry,
411 struct kstat *stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000413 struct inode *inode = dentry->d_inode;
414 struct xfs_inode *ip = XFS_I(inode);
415 struct xfs_mount *mp = ip->i_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Christoph Hellwigcca28fb2010-06-24 11:57:09 +1000417 trace_xfs_getattr(ip);
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000418
419 if (XFS_FORCED_SHUTDOWN(mp))
Mitsuo Hayasakaed322012011-09-17 13:38:38 +0000420 return -XFS_ERROR(EIO);
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000421
422 stat->size = XFS_ISIZE(ip);
423 stat->dev = inode->i_sb->s_dev;
424 stat->mode = ip->i_d.di_mode;
425 stat->nlink = ip->i_d.di_nlink;
Dwight Engen7aab1b22013-08-15 14:08:01 -0400426 stat->uid = inode->i_uid;
427 stat->gid = inode->i_gid;
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000428 stat->ino = ip->i_ino;
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000429 stat->atime = inode->i_atime;
Christoph Hellwigf9581b12009-10-06 20:29:26 +0000430 stat->mtime = inode->i_mtime;
431 stat->ctime = inode->i_ctime;
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000432 stat->blocks =
433 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
434
435
436 switch (inode->i_mode & S_IFMT) {
437 case S_IFBLK:
438 case S_IFCHR:
439 stat->blksize = BLKDEV_IOSIZE;
440 stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
441 sysv_minor(ip->i_df.if_u2.if_rdev));
442 break;
443 default:
Eric Sandeen71ddabb2007-11-23 16:29:42 +1100444 if (XFS_IS_REALTIME_INODE(ip)) {
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000445 /*
446 * If the file blocks are being allocated from a
447 * realtime volume, then return the inode's realtime
448 * extent size or the realtime volume's extent size.
449 */
450 stat->blksize =
451 xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
452 } else
453 stat->blksize = xfs_preferred_iosize(mp);
454 stat->rdev = 0;
455 break;
Nathan Scott69e23b92006-09-28 11:01:22 +1000456 }
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000457
458 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
Dave Chinner56c19e82013-05-27 16:38:25 +1000461static void
462xfs_setattr_mode(
Dave Chinner56c19e82013-05-27 16:38:25 +1000463 struct xfs_inode *ip,
464 struct iattr *iattr)
465{
Christoph Hellwig0c3d88d2013-11-18 05:10:40 -0800466 struct inode *inode = VFS_I(ip);
467 umode_t mode = iattr->ia_mode;
Dave Chinner56c19e82013-05-27 16:38:25 +1000468
Dave Chinner56c19e82013-05-27 16:38:25 +1000469 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
470
Dave Chinner56c19e82013-05-27 16:38:25 +1000471 ip->i_d.di_mode &= S_IFMT;
472 ip->i_d.di_mode |= mode & ~S_IFMT;
473
474 inode->i_mode &= S_IFMT;
475 inode->i_mode |= mode & ~S_IFMT;
476}
477
Christoph Hellwigc91c46c2013-11-18 05:10:52 -0800478static void
479xfs_setattr_time(
480 struct xfs_inode *ip,
481 struct iattr *iattr)
482{
483 struct inode *inode = VFS_I(ip);
484
485 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
486
487 if (iattr->ia_valid & ATTR_ATIME) {
488 inode->i_atime = iattr->ia_atime;
489 ip->i_d.di_atime.t_sec = iattr->ia_atime.tv_sec;
490 ip->i_d.di_atime.t_nsec = iattr->ia_atime.tv_nsec;
491 }
492 if (iattr->ia_valid & ATTR_CTIME) {
493 inode->i_ctime = iattr->ia_ctime;
494 ip->i_d.di_ctime.t_sec = iattr->ia_ctime.tv_sec;
495 ip->i_d.di_ctime.t_nsec = iattr->ia_ctime.tv_nsec;
496 }
497 if (iattr->ia_valid & ATTR_MTIME) {
498 inode->i_mtime = iattr->ia_mtime;
499 ip->i_d.di_mtime.t_sec = iattr->ia_mtime.tv_sec;
500 ip->i_d.di_mtime.t_nsec = iattr->ia_mtime.tv_nsec;
501 }
502}
503
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200504int
505xfs_setattr_nonsize(
506 struct xfs_inode *ip,
507 struct iattr *iattr,
508 int flags)
509{
510 xfs_mount_t *mp = ip->i_mount;
511 struct inode *inode = VFS_I(ip);
512 int mask = iattr->ia_valid;
513 xfs_trans_t *tp;
514 int error;
Dwight Engen7aab1b22013-08-15 14:08:01 -0400515 kuid_t uid = GLOBAL_ROOT_UID, iuid = GLOBAL_ROOT_UID;
516 kgid_t gid = GLOBAL_ROOT_GID, igid = GLOBAL_ROOT_GID;
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200517 struct xfs_dquot *udqp = NULL, *gdqp = NULL;
518 struct xfs_dquot *olddquot1 = NULL, *olddquot2 = NULL;
519
520 trace_xfs_setattr(ip);
521
Carlos Maiolino42c49d72013-06-21 14:45:53 -0300522 /* If acls are being inherited, we already have this checked */
523 if (!(flags & XFS_ATTR_NOACL)) {
524 if (mp->m_flags & XFS_MOUNT_RDONLY)
525 return XFS_ERROR(EROFS);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200526
Carlos Maiolino42c49d72013-06-21 14:45:53 -0300527 if (XFS_FORCED_SHUTDOWN(mp))
528 return XFS_ERROR(EIO);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200529
Carlos Maiolino42c49d72013-06-21 14:45:53 -0300530 error = -inode_change_ok(inode, iattr);
531 if (error)
532 return XFS_ERROR(error);
533 }
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200534
535 ASSERT((mask & ATTR_SIZE) == 0);
536
537 /*
538 * If disk quotas is on, we make sure that the dquots do exist on disk,
539 * before we start any other transactions. Trying to do this later
540 * is messy. We don't care to take a readlock to look at the ids
541 * in inode here, because we can't hold it across the trans_reserve.
542 * If the IDs do change before we take the ilock, we're covered
543 * because the i_*dquot fields will get updated anyway.
544 */
545 if (XFS_IS_QUOTA_ON(mp) && (mask & (ATTR_UID|ATTR_GID))) {
546 uint qflags = 0;
547
548 if ((mask & ATTR_UID) && XFS_IS_UQUOTA_ON(mp)) {
549 uid = iattr->ia_uid;
550 qflags |= XFS_QMOPT_UQUOTA;
551 } else {
Dwight Engen7aab1b22013-08-15 14:08:01 -0400552 uid = inode->i_uid;
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200553 }
554 if ((mask & ATTR_GID) && XFS_IS_GQUOTA_ON(mp)) {
555 gid = iattr->ia_gid;
556 qflags |= XFS_QMOPT_GQUOTA;
557 } else {
Dwight Engen7aab1b22013-08-15 14:08:01 -0400558 gid = inode->i_gid;
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200559 }
560
561 /*
562 * We take a reference when we initialize udqp and gdqp,
563 * so it is important that we never blindly double trip on
564 * the same variable. See xfs_create() for an example.
565 */
566 ASSERT(udqp == NULL);
567 ASSERT(gdqp == NULL);
Dwight Engen7aab1b22013-08-15 14:08:01 -0400568 error = xfs_qm_vop_dqalloc(ip, xfs_kuid_to_uid(uid),
569 xfs_kgid_to_gid(gid),
570 xfs_get_projid(ip),
571 qflags, &udqp, &gdqp, NULL);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200572 if (error)
573 return error;
574 }
575
576 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
Jie Liu3d3c8b52013-08-12 20:49:59 +1000577 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 0, 0);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200578 if (error)
579 goto out_dqrele;
580
581 xfs_ilock(ip, XFS_ILOCK_EXCL);
582
583 /*
584 * Change file ownership. Must be the owner or privileged.
585 */
586 if (mask & (ATTR_UID|ATTR_GID)) {
587 /*
588 * These IDs could have changed since we last looked at them.
589 * But, we're assured that if the ownership did change
590 * while we didn't have the inode locked, inode's dquot(s)
591 * would have changed also.
592 */
Dwight Engen7aab1b22013-08-15 14:08:01 -0400593 iuid = inode->i_uid;
594 igid = inode->i_gid;
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200595 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
596 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
597
598 /*
599 * Do a quota reservation only if uid/gid is actually
600 * going to change.
601 */
602 if (XFS_IS_QUOTA_RUNNING(mp) &&
Dwight Engen7aab1b22013-08-15 14:08:01 -0400603 ((XFS_IS_UQUOTA_ON(mp) && !uid_eq(iuid, uid)) ||
604 (XFS_IS_GQUOTA_ON(mp) && !gid_eq(igid, gid)))) {
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200605 ASSERT(tp);
606 error = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
Chandra Seetharaman92f8ff72013-07-11 00:00:40 -0500607 NULL, capable(CAP_FOWNER) ?
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200608 XFS_QMOPT_FORCE_RES : 0);
609 if (error) /* out of quota */
610 goto out_trans_cancel;
611 }
612 }
613
Christoph Hellwigddc34152011-09-19 15:00:54 +0000614 xfs_trans_ijoin(tp, ip, 0);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200615
616 /*
617 * Change file ownership. Must be the owner or privileged.
618 */
619 if (mask & (ATTR_UID|ATTR_GID)) {
620 /*
621 * CAP_FSETID overrides the following restrictions:
622 *
623 * The set-user-ID and set-group-ID bits of a file will be
624 * cleared upon successful return from chown()
625 */
626 if ((ip->i_d.di_mode & (S_ISUID|S_ISGID)) &&
627 !capable(CAP_FSETID))
628 ip->i_d.di_mode &= ~(S_ISUID|S_ISGID);
629
630 /*
631 * Change the ownerships and register quota modifications
632 * in the transaction.
633 */
Dwight Engen7aab1b22013-08-15 14:08:01 -0400634 if (!uid_eq(iuid, uid)) {
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200635 if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
636 ASSERT(mask & ATTR_UID);
637 ASSERT(udqp);
638 olddquot1 = xfs_qm_vop_chown(tp, ip,
639 &ip->i_udquot, udqp);
640 }
Dwight Engen7aab1b22013-08-15 14:08:01 -0400641 ip->i_d.di_uid = xfs_kuid_to_uid(uid);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200642 inode->i_uid = uid;
643 }
Dwight Engen7aab1b22013-08-15 14:08:01 -0400644 if (!gid_eq(igid, gid)) {
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200645 if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_GQUOTA_ON(mp)) {
Jie Liu5a01dd52013-11-26 21:38:34 +0800646 ASSERT(xfs_sb_version_has_pquotino(&mp->m_sb) ||
647 !XFS_IS_PQUOTA_ON(mp));
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200648 ASSERT(mask & ATTR_GID);
649 ASSERT(gdqp);
650 olddquot2 = xfs_qm_vop_chown(tp, ip,
651 &ip->i_gdquot, gdqp);
652 }
Dwight Engen7aab1b22013-08-15 14:08:01 -0400653 ip->i_d.di_gid = xfs_kgid_to_gid(gid);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200654 inode->i_gid = gid;
655 }
656 }
657
Dave Chinner56c19e82013-05-27 16:38:25 +1000658 if (mask & ATTR_MODE)
Christoph Hellwig0c3d88d2013-11-18 05:10:40 -0800659 xfs_setattr_mode(ip, iattr);
Christoph Hellwigc91c46c2013-11-18 05:10:52 -0800660 if (mask & (ATTR_ATIME|ATTR_CTIME|ATTR_MTIME))
661 xfs_setattr_time(ip, iattr);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200662
663 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
664
665 XFS_STATS_INC(xs_ig_attrchg);
666
667 if (mp->m_flags & XFS_MOUNT_WSYNC)
668 xfs_trans_set_sync(tp);
669 error = xfs_trans_commit(tp, 0);
670
671 xfs_iunlock(ip, XFS_ILOCK_EXCL);
672
673 /*
674 * Release any dquot(s) the inode had kept before chown.
675 */
676 xfs_qm_dqrele(olddquot1);
677 xfs_qm_dqrele(olddquot2);
678 xfs_qm_dqrele(udqp);
679 xfs_qm_dqrele(gdqp);
680
681 if (error)
682 return XFS_ERROR(error);
683
684 /*
685 * XXX(hch): Updating the ACL entries is not atomic vs the i_mode
686 * update. We could avoid this with linked transactions
687 * and passing down the transaction pointer all the way
688 * to attr_set. No previous user of the generic
689 * Posix ACL code seems to care about this issue either.
690 */
691 if ((mask & ATTR_MODE) && !(flags & XFS_ATTR_NOACL)) {
692 error = -xfs_acl_chmod(inode);
693 if (error)
694 return XFS_ERROR(error);
695 }
696
697 return 0;
698
699out_trans_cancel:
700 xfs_trans_cancel(tp, 0);
701 xfs_iunlock(ip, XFS_ILOCK_EXCL);
702out_dqrele:
703 xfs_qm_dqrele(udqp);
704 xfs_qm_dqrele(gdqp);
705 return error;
706}
707
708/*
709 * Truncate file. Must have write permission and not be a directory.
710 */
711int
712xfs_setattr_size(
713 struct xfs_inode *ip,
Christoph Hellwig76ca4c22013-10-14 07:09:35 -0700714 struct iattr *iattr)
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200715{
716 struct xfs_mount *mp = ip->i_mount;
717 struct inode *inode = VFS_I(ip);
718 int mask = iattr->ia_valid;
Christoph Hellwig673e8e52011-12-18 20:00:04 +0000719 xfs_off_t oldsize, newsize;
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200720 struct xfs_trans *tp;
721 int error;
Christoph Hellwigf38996f2012-03-27 10:34:48 -0400722 uint lock_flags = 0;
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200723 uint commit_flags = 0;
724
725 trace_xfs_setattr(ip);
726
727 if (mp->m_flags & XFS_MOUNT_RDONLY)
728 return XFS_ERROR(EROFS);
729
730 if (XFS_FORCED_SHUTDOWN(mp))
731 return XFS_ERROR(EIO);
732
733 error = -inode_change_ok(inode, iattr);
734 if (error)
735 return XFS_ERROR(error);
736
Christoph Hellwig76ca4c22013-10-14 07:09:35 -0700737 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200738 ASSERT(S_ISREG(ip->i_d.di_mode));
Dave Chinner56c19e82013-05-27 16:38:25 +1000739 ASSERT((mask & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET|
740 ATTR_MTIME_SET|ATTR_KILL_PRIV|ATTR_TIMES_SET)) == 0);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200741
Christoph Hellwigce7ae1512011-12-18 20:00:11 +0000742 oldsize = inode->i_size;
Christoph Hellwig673e8e52011-12-18 20:00:04 +0000743 newsize = iattr->ia_size;
744
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200745 /*
746 * Short circuit the truncate case for zero length files.
747 */
Christoph Hellwig673e8e52011-12-18 20:00:04 +0000748 if (newsize == 0 && oldsize == 0 && ip->i_d.di_nextents == 0) {
Christoph Hellwig681b1202011-07-08 14:34:26 +0200749 if (!(mask & (ATTR_CTIME|ATTR_MTIME)))
Christoph Hellwig76ca4c22013-10-14 07:09:35 -0700750 return 0;
Christoph Hellwig681b1202011-07-08 14:34:26 +0200751
752 /*
753 * Use the regular setattr path to update the timestamps.
754 */
Christoph Hellwig681b1202011-07-08 14:34:26 +0200755 iattr->ia_valid &= ~ATTR_SIZE;
756 return xfs_setattr_nonsize(ip, iattr, 0);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200757 }
758
759 /*
760 * Make sure that the dquots are attached to the inode.
761 */
Christoph Hellwigf38996f2012-03-27 10:34:48 -0400762 error = xfs_qm_dqattach(ip, 0);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200763 if (error)
Christoph Hellwig76ca4c22013-10-14 07:09:35 -0700764 return error;
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200765
766 /*
767 * Now we can make the changes. Before we join the inode to the
768 * transaction, take care of the part of the truncation that must be
769 * done without the inode lock. This needs to be done before joining
770 * the inode to the transaction, because the inode cannot be unlocked
771 * once it is a part of the transaction.
772 */
Christoph Hellwig673e8e52011-12-18 20:00:04 +0000773 if (newsize > oldsize) {
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200774 /*
775 * Do the first part of growing a file: zero any data in the
776 * last block that is beyond the old EOF. We need to do this
777 * before the inode is joined to the transaction to modify
778 * i_size.
779 */
Christoph Hellwig673e8e52011-12-18 20:00:04 +0000780 error = xfs_zero_eof(ip, newsize, oldsize);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200781 if (error)
Christoph Hellwig76ca4c22013-10-14 07:09:35 -0700782 return error;
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200783 }
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200784
785 /*
786 * We are going to log the inode size change in this transaction so
787 * any previous writes that are beyond the on disk EOF and the new
788 * EOF that have not been written out need to be written here. If we
789 * do not write the data out, we expose ourselves to the null files
790 * problem.
791 *
792 * Only flush from the on disk size to the smaller of the in memory
793 * file size or the new size as that's the range we really care about
794 * here and prevents waiting for other data not within the range we
795 * care about here.
796 */
Christoph Hellwig673e8e52011-12-18 20:00:04 +0000797 if (oldsize != ip->i_d.di_size && newsize > ip->i_d.di_size) {
Dave Chinner4bc1ea62012-11-12 22:53:56 +1100798 error = -filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
799 ip->i_d.di_size, newsize);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200800 if (error)
Christoph Hellwig76ca4c22013-10-14 07:09:35 -0700801 return error;
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200802 }
803
804 /*
Christoph Hellwig4a06fd22011-08-23 08:28:13 +0000805 * Wait for all direct I/O to complete.
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200806 */
Christoph Hellwig4a06fd22011-08-23 08:28:13 +0000807 inode_dio_wait(inode);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200808
Christoph Hellwig673e8e52011-12-18 20:00:04 +0000809 error = -block_truncate_page(inode->i_mapping, newsize, xfs_get_blocks);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200810 if (error)
Christoph Hellwig76ca4c22013-10-14 07:09:35 -0700811 return error;
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200812
813 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_SIZE);
Jie Liu3d3c8b52013-08-12 20:49:59 +1000814 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_itruncate, 0, 0);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200815 if (error)
816 goto out_trans_cancel;
817
Christoph Hellwig673e8e52011-12-18 20:00:04 +0000818 truncate_setsize(inode, newsize);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200819
820 commit_flags = XFS_TRANS_RELEASE_LOG_RES;
821 lock_flags |= XFS_ILOCK_EXCL;
822
823 xfs_ilock(ip, XFS_ILOCK_EXCL);
824
Christoph Hellwigddc34152011-09-19 15:00:54 +0000825 xfs_trans_ijoin(tp, ip, 0);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200826
827 /*
828 * Only change the c/mtime if we are changing the size or we are
829 * explicitly asked to change it. This handles the semantic difference
830 * between truncate() and ftruncate() as implemented in the VFS.
831 *
832 * The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a
833 * special case where we need to update the times despite not having
834 * these flags set. For all other operations the VFS set these flags
835 * explicitly if it wants a timestamp update.
836 */
Christoph Hellwig673e8e52011-12-18 20:00:04 +0000837 if (newsize != oldsize && (!(mask & (ATTR_CTIME | ATTR_MTIME)))) {
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200838 iattr->ia_ctime = iattr->ia_mtime =
839 current_fs_time(inode->i_sb);
840 mask |= ATTR_CTIME | ATTR_MTIME;
841 }
842
Christoph Hellwig673e8e52011-12-18 20:00:04 +0000843 /*
844 * The first thing we do is set the size to new_size permanently on
845 * disk. This way we don't have to worry about anyone ever being able
846 * to look at the data being freed even in the face of a crash.
847 * What we're getting around here is the case where we free a block, it
848 * is allocated to another file, it is written to, and then we crash.
849 * If the new data gets written to the file but the log buffers
850 * containing the free and reallocation don't, then we'd end up with
851 * garbage in the blocks being freed. As long as we make the new size
852 * permanent before actually freeing any blocks it doesn't matter if
853 * they get written to.
854 */
855 ip->i_d.di_size = newsize;
Christoph Hellwig673e8e52011-12-18 20:00:04 +0000856 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
857
858 if (newsize <= oldsize) {
859 error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, newsize);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200860 if (error)
861 goto out_trans_abort;
862
863 /*
864 * Truncated "down", so we're removing references to old data
865 * here - if we delay flushing for a long time, we expose
866 * ourselves unduly to the notorious NULL files problem. So,
867 * we mark this inode and flush it when the file is closed,
868 * and do not wait the usual (long) time for writeout.
869 */
870 xfs_iflags_set(ip, XFS_ITRUNCATED);
Brian Foster27b52862012-11-06 09:50:38 -0500871
872 /* A truncate down always removes post-EOF blocks. */
873 xfs_inode_clear_eofblocks_tag(ip);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200874 }
875
Dave Chinner56c19e82013-05-27 16:38:25 +1000876 if (mask & ATTR_MODE)
Christoph Hellwig0c3d88d2013-11-18 05:10:40 -0800877 xfs_setattr_mode(ip, iattr);
Christoph Hellwigc91c46c2013-11-18 05:10:52 -0800878 if (mask & (ATTR_ATIME|ATTR_CTIME|ATTR_MTIME))
879 xfs_setattr_time(ip, iattr);
Christoph Hellwigc4ed4242011-07-08 14:34:23 +0200880
881 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
882
883 XFS_STATS_INC(xs_ig_attrchg);
884
885 if (mp->m_flags & XFS_MOUNT_WSYNC)
886 xfs_trans_set_sync(tp);
887
888 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
889out_unlock:
890 if (lock_flags)
891 xfs_iunlock(ip, lock_flags);
892 return error;
893
894out_trans_abort:
895 commit_flags |= XFS_TRANS_ABORT;
896out_trans_cancel:
897 xfs_trans_cancel(tp, commit_flags);
898 goto out_unlock;
899}
900
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100902xfs_vn_setattr(
Christoph Hellwig76ca4c22013-10-14 07:09:35 -0700903 struct dentry *dentry,
904 struct iattr *iattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Christoph Hellwig76ca4c22013-10-14 07:09:35 -0700906 struct xfs_inode *ip = XFS_I(dentry->d_inode);
907 int error;
908
909 if (iattr->ia_valid & ATTR_SIZE) {
910 xfs_ilock(ip, XFS_IOLOCK_EXCL);
911 error = xfs_setattr_size(ip, iattr);
912 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
913 } else {
914 error = xfs_setattr_nonsize(ip, iattr, 0);
915 }
916
917 return -error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918}
919
Christoph Hellwig69ff2822012-06-06 17:01:28 -0400920STATIC int
921xfs_vn_update_time(
922 struct inode *inode,
923 struct timespec *now,
924 int flags)
925{
926 struct xfs_inode *ip = XFS_I(inode);
927 struct xfs_mount *mp = ip->i_mount;
928 struct xfs_trans *tp;
929 int error;
930
931 trace_xfs_update_time(ip);
932
933 tp = xfs_trans_alloc(mp, XFS_TRANS_FSYNC_TS);
Jie Liu3d3c8b52013-08-12 20:49:59 +1000934 error = xfs_trans_reserve(tp, &M_RES(mp)->tr_fsyncts, 0, 0);
Christoph Hellwig69ff2822012-06-06 17:01:28 -0400935 if (error) {
936 xfs_trans_cancel(tp, 0);
937 return -error;
938 }
939
940 xfs_ilock(ip, XFS_ILOCK_EXCL);
941 if (flags & S_CTIME) {
942 inode->i_ctime = *now;
943 ip->i_d.di_ctime.t_sec = (__int32_t)now->tv_sec;
944 ip->i_d.di_ctime.t_nsec = (__int32_t)now->tv_nsec;
945 }
946 if (flags & S_MTIME) {
947 inode->i_mtime = *now;
948 ip->i_d.di_mtime.t_sec = (__int32_t)now->tv_sec;
949 ip->i_d.di_mtime.t_nsec = (__int32_t)now->tv_nsec;
950 }
951 if (flags & S_ATIME) {
952 inode->i_atime = *now;
953 ip->i_d.di_atime.t_sec = (__int32_t)now->tv_sec;
954 ip->i_d.di_atime.t_nsec = (__int32_t)now->tv_nsec;
955 }
956 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
957 xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
958 return -xfs_trans_commit(tp, 0);
959}
960
Eric Sandeenf35642e2008-11-28 14:23:35 +1100961#define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR)
962
963/*
964 * Call fiemap helper to fill in user data.
965 * Returns positive errors to xfs_getbmap.
966 */
967STATIC int
968xfs_fiemap_format(
969 void **arg,
970 struct getbmapx *bmv,
971 int *full)
972{
973 int error;
974 struct fiemap_extent_info *fieinfo = *arg;
975 u32 fiemap_flags = 0;
976 u64 logical, physical, length;
977
978 /* Do nothing for a hole */
979 if (bmv->bmv_block == -1LL)
980 return 0;
981
982 logical = BBTOB(bmv->bmv_offset);
983 physical = BBTOB(bmv->bmv_block);
984 length = BBTOB(bmv->bmv_length);
985
986 if (bmv->bmv_oflags & BMV_OF_PREALLOC)
987 fiemap_flags |= FIEMAP_EXTENT_UNWRITTEN;
988 else if (bmv->bmv_oflags & BMV_OF_DELALLOC) {
Jie Liu635c4d02013-06-06 06:24:01 -0700989 fiemap_flags |= (FIEMAP_EXTENT_DELALLOC |
990 FIEMAP_EXTENT_UNKNOWN);
Eric Sandeenf35642e2008-11-28 14:23:35 +1100991 physical = 0; /* no block yet */
992 }
993 if (bmv->bmv_oflags & BMV_OF_LAST)
994 fiemap_flags |= FIEMAP_EXTENT_LAST;
995
996 error = fiemap_fill_next_extent(fieinfo, logical, physical,
997 length, fiemap_flags);
998 if (error > 0) {
999 error = 0;
1000 *full = 1; /* user array now full */
1001 }
1002
1003 return -error;
1004}
1005
1006STATIC int
1007xfs_vn_fiemap(
1008 struct inode *inode,
1009 struct fiemap_extent_info *fieinfo,
1010 u64 start,
1011 u64 length)
1012{
1013 xfs_inode_t *ip = XFS_I(inode);
1014 struct getbmapx bm;
1015 int error;
1016
1017 error = fiemap_check_flags(fieinfo, XFS_FIEMAP_FLAGS);
1018 if (error)
1019 return error;
1020
1021 /* Set up bmap header for xfs internal routine */
1022 bm.bmv_offset = BTOBB(start);
1023 /* Special case for whole file */
1024 if (length == FIEMAP_MAX_OFFSET)
1025 bm.bmv_length = -1LL;
1026 else
1027 bm.bmv_length = BTOBB(length);
1028
Eric Sandeen97db39a2009-07-26 21:52:01 -05001029 /* We add one because in getbmap world count includes the header */
Tao Ma2d1ff3c2010-04-29 15:13:56 +10001030 bm.bmv_count = !fieinfo->fi_extents_max ? MAXEXTNUM :
1031 fieinfo->fi_extents_max + 1;
1032 bm.bmv_count = min_t(__s32, bm.bmv_count,
1033 (PAGE_SIZE * 16 / sizeof(struct getbmapx)));
Tao Ma9af25462010-08-30 02:44:03 +00001034 bm.bmv_iflags = BMV_IF_PREALLOC | BMV_IF_NO_HOLES;
Eric Sandeenf35642e2008-11-28 14:23:35 +11001035 if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR)
1036 bm.bmv_iflags |= BMV_IF_ATTRFORK;
1037 if (!(fieinfo->fi_flags & FIEMAP_FLAG_SYNC))
1038 bm.bmv_iflags |= BMV_IF_DELALLOC;
1039
1040 error = xfs_getbmap(ip, &bm, xfs_fiemap_format, fieinfo);
1041 if (error)
1042 return -error;
1043
1044 return 0;
1045}
1046
Zhi Yong Wu99b64362013-12-18 08:22:40 +08001047STATIC int
1048xfs_vn_tmpfile(
1049 struct inode *dir,
1050 struct dentry *dentry,
1051 umode_t mode)
1052{
1053 int error;
1054
1055 error = xfs_create_tmpfile(XFS_I(dir), dentry, mode);
1056
1057 return -error;
1058}
1059
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001060static const struct inode_operations xfs_inode_operations = {
Christoph Hellwig4e34e712011-07-23 17:37:31 +02001061 .get_acl = xfs_get_acl,
Nathan Scott416c6d52006-03-14 14:00:51 +11001062 .getattr = xfs_vn_getattr,
1063 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001064 .setxattr = generic_setxattr,
1065 .getxattr = generic_getxattr,
1066 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +11001067 .listxattr = xfs_vn_listxattr,
Eric Sandeenf35642e2008-11-28 14:23:35 +11001068 .fiemap = xfs_vn_fiemap,
Christoph Hellwig69ff2822012-06-06 17:01:28 -04001069 .update_time = xfs_vn_update_time,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070};
1071
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001072static const struct inode_operations xfs_dir_inode_operations = {
Nathan Scott416c6d52006-03-14 14:00:51 +11001073 .create = xfs_vn_create,
1074 .lookup = xfs_vn_lookup,
1075 .link = xfs_vn_link,
1076 .unlink = xfs_vn_unlink,
1077 .symlink = xfs_vn_symlink,
1078 .mkdir = xfs_vn_mkdir,
Christoph Hellwig8f112e32008-06-23 13:25:17 +10001079 /*
1080 * Yes, XFS uses the same method for rmdir and unlink.
1081 *
1082 * There are some subtile differences deeper in the code,
1083 * but we use S_ISDIR to check for those.
1084 */
1085 .rmdir = xfs_vn_unlink,
Nathan Scott416c6d52006-03-14 14:00:51 +11001086 .mknod = xfs_vn_mknod,
1087 .rename = xfs_vn_rename,
Christoph Hellwig4e34e712011-07-23 17:37:31 +02001088 .get_acl = xfs_get_acl,
Nathan Scott416c6d52006-03-14 14:00:51 +11001089 .getattr = xfs_vn_getattr,
1090 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001091 .setxattr = generic_setxattr,
1092 .getxattr = generic_getxattr,
1093 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +11001094 .listxattr = xfs_vn_listxattr,
Christoph Hellwig69ff2822012-06-06 17:01:28 -04001095 .update_time = xfs_vn_update_time,
Zhi Yong Wu99b64362013-12-18 08:22:40 +08001096 .tmpfile = xfs_vn_tmpfile,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097};
1098
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001099static const struct inode_operations xfs_dir_ci_inode_operations = {
Barry Naujok384f3ce2008-05-21 16:58:22 +10001100 .create = xfs_vn_create,
1101 .lookup = xfs_vn_ci_lookup,
1102 .link = xfs_vn_link,
1103 .unlink = xfs_vn_unlink,
1104 .symlink = xfs_vn_symlink,
1105 .mkdir = xfs_vn_mkdir,
Christoph Hellwig8f112e32008-06-23 13:25:17 +10001106 /*
1107 * Yes, XFS uses the same method for rmdir and unlink.
1108 *
1109 * There are some subtile differences deeper in the code,
1110 * but we use S_ISDIR to check for those.
1111 */
1112 .rmdir = xfs_vn_unlink,
Barry Naujok384f3ce2008-05-21 16:58:22 +10001113 .mknod = xfs_vn_mknod,
1114 .rename = xfs_vn_rename,
Christoph Hellwig4e34e712011-07-23 17:37:31 +02001115 .get_acl = xfs_get_acl,
Barry Naujok384f3ce2008-05-21 16:58:22 +10001116 .getattr = xfs_vn_getattr,
1117 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001118 .setxattr = generic_setxattr,
1119 .getxattr = generic_getxattr,
1120 .removexattr = generic_removexattr,
Barry Naujok384f3ce2008-05-21 16:58:22 +10001121 .listxattr = xfs_vn_listxattr,
Christoph Hellwig69ff2822012-06-06 17:01:28 -04001122 .update_time = xfs_vn_update_time,
Zhi Yong Wu99b64362013-12-18 08:22:40 +08001123 .tmpfile = xfs_vn_tmpfile,
Barry Naujok384f3ce2008-05-21 16:58:22 +10001124};
1125
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001126static const struct inode_operations xfs_symlink_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 .readlink = generic_readlink,
Nathan Scott416c6d52006-03-14 14:00:51 +11001128 .follow_link = xfs_vn_follow_link,
1129 .put_link = xfs_vn_put_link,
Christoph Hellwig4e34e712011-07-23 17:37:31 +02001130 .get_acl = xfs_get_acl,
Nathan Scott416c6d52006-03-14 14:00:51 +11001131 .getattr = xfs_vn_getattr,
1132 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +10001133 .setxattr = generic_setxattr,
1134 .getxattr = generic_getxattr,
1135 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +11001136 .listxattr = xfs_vn_listxattr,
Christoph Hellwig69ff2822012-06-06 17:01:28 -04001137 .update_time = xfs_vn_update_time,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138};
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001139
1140STATIC void
1141xfs_diflags_to_iflags(
1142 struct inode *inode,
1143 struct xfs_inode *ip)
1144{
1145 if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
1146 inode->i_flags |= S_IMMUTABLE;
1147 else
1148 inode->i_flags &= ~S_IMMUTABLE;
1149 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
1150 inode->i_flags |= S_APPEND;
1151 else
1152 inode->i_flags &= ~S_APPEND;
1153 if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
1154 inode->i_flags |= S_SYNC;
1155 else
1156 inode->i_flags &= ~S_SYNC;
1157 if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
1158 inode->i_flags |= S_NOATIME;
1159 else
1160 inode->i_flags &= ~S_NOATIME;
1161}
1162
1163/*
1164 * Initialize the Linux inode, set up the operation vectors and
1165 * unlock the inode.
1166 *
1167 * When reading existing inodes from disk this is called directly
1168 * from xfs_iget, when creating a new inode it is called from
1169 * xfs_ialloc after setting up the inode.
David Chinnerbf904242008-10-30 17:36:14 +11001170 *
1171 * We are always called with an uninitialised linux inode here.
1172 * We need to initialise the necessary fields and take a reference
1173 * on it.
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001174 */
1175void
1176xfs_setup_inode(
1177 struct xfs_inode *ip)
1178{
David Chinnerbf904242008-10-30 17:36:14 +11001179 struct inode *inode = &ip->i_vnode;
Dave Chinnerad22c7a2013-10-29 22:11:57 +11001180 gfp_t gfp_mask;
David Chinnerbf904242008-10-30 17:36:14 +11001181
1182 inode->i_ino = ip->i_ino;
Christoph Hellwigeaff8072009-12-17 14:25:01 +01001183 inode->i_state = I_NEW;
Christoph Hellwig646ec462010-10-23 07:15:32 -04001184
1185 inode_sb_list_add(inode);
Christoph Hellwigc6f6cd02010-11-06 11:43:08 +00001186 /* make the inode look hashed for the writeback code */
1187 hlist_add_fake(&inode->i_hash);
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001188
1189 inode->i_mode = ip->i_d.di_mode;
Miklos Szeredibfe86842011-10-28 14:13:29 +02001190 set_nlink(inode, ip->i_d.di_nlink);
Dwight Engen7aab1b22013-08-15 14:08:01 -04001191 inode->i_uid = xfs_uid_to_kuid(ip->i_d.di_uid);
1192 inode->i_gid = xfs_gid_to_kgid(ip->i_d.di_gid);
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001193
1194 switch (inode->i_mode & S_IFMT) {
1195 case S_IFBLK:
1196 case S_IFCHR:
1197 inode->i_rdev =
1198 MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
1199 sysv_minor(ip->i_df.if_u2.if_rdev));
1200 break;
1201 default:
1202 inode->i_rdev = 0;
1203 break;
1204 }
1205
1206 inode->i_generation = ip->i_d.di_gen;
1207 i_size_write(inode, ip->i_d.di_size);
1208 inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
1209 inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
1210 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
1211 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
1212 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
1213 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
1214 xfs_diflags_to_iflags(inode, ip);
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001215
Dave Chinner4bceb182013-10-29 22:11:51 +11001216 ip->d_ops = ip->i_mount->m_nondir_inode_ops;
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001217 switch (inode->i_mode & S_IFMT) {
1218 case S_IFREG:
1219 inode->i_op = &xfs_inode_operations;
1220 inode->i_fop = &xfs_file_operations;
1221 inode->i_mapping->a_ops = &xfs_address_space_operations;
1222 break;
1223 case S_IFDIR:
1224 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
1225 inode->i_op = &xfs_dir_ci_inode_operations;
1226 else
1227 inode->i_op = &xfs_dir_inode_operations;
1228 inode->i_fop = &xfs_dir_file_operations;
Dave Chinner32c54832013-10-29 22:11:46 +11001229 ip->d_ops = ip->i_mount->m_dir_inode_ops;
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001230 break;
1231 case S_IFLNK:
1232 inode->i_op = &xfs_symlink_inode_operations;
1233 if (!(ip->i_df.if_flags & XFS_IFINLINE))
1234 inode->i_mapping->a_ops = &xfs_address_space_operations;
1235 break;
1236 default:
1237 inode->i_op = &xfs_inode_operations;
1238 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1239 break;
1240 }
1241
Christoph Hellwig510792e2011-07-26 15:07:29 +00001242 /*
Dave Chinnerad22c7a2013-10-29 22:11:57 +11001243 * Ensure all page cache allocations are done from GFP_NOFS context to
1244 * prevent direct reclaim recursion back into the filesystem and blowing
1245 * stacks or deadlocking.
1246 */
1247 gfp_mask = mapping_gfp_mask(inode->i_mapping);
1248 mapping_set_gfp_mask(inode->i_mapping, (gfp_mask & ~(__GFP_FS)));
1249
1250 /*
Christoph Hellwig510792e2011-07-26 15:07:29 +00001251 * If there is no attribute fork no ACL can exist on this inode,
1252 * and it can't have any file capabilities attached to it either.
1253 */
1254 if (!XFS_IFORK_Q(ip)) {
1255 inode_has_no_xattr(inode);
Christoph Hellwig6311b102011-07-23 17:36:50 +02001256 cache_no_acl(inode);
Christoph Hellwig510792e2011-07-26 15:07:29 +00001257 }
Christoph Hellwig6311b102011-07-23 17:36:50 +02001258
Christoph Hellwig41be8be2008-08-13 16:23:13 +10001259 xfs_iflags_clear(ip, XFS_INEW);
1260 barrier();
1261
1262 unlock_new_inode(inode);
1263}