xfs_iops.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * 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.
  13. *
  14. * 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
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_shared.h"
  21. #include "xfs_format.h"
  22. #include "xfs_log_format.h"
  23. #include "xfs_trans_resv.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_mount.h"
  27. #include "xfs_da_format.h"
  28. #include "xfs_inode.h"
  29. #include "xfs_bmap.h"
  30. #include "xfs_bmap_util.h"
  31. #include "xfs_acl.h"
  32. #include "xfs_quota.h"
  33. #include "xfs_error.h"
  34. #include "xfs_attr.h"
  35. #include "xfs_trans.h"
  36. #include "xfs_trace.h"
  37. #include "xfs_icache.h"
  38. #include "xfs_symlink.h"
  39. #include "xfs_da_btree.h"
  40. #include "xfs_dir2_priv.h"
  41. #include "xfs_dinode.h"
  42. #include <linux/capability.h>
  43. #include <linux/xattr.h>
  44. #include <linux/namei.h>
  45. #include <linux/posix_acl.h>
  46. #include <linux/security.h>
  47. #include <linux/fiemap.h>
  48. #include <linux/slab.h>
  49. static int
  50. xfs_initxattrs(
  51. struct inode *inode,
  52. const struct xattr *xattr_array,
  53. void *fs_info)
  54. {
  55. const struct xattr *xattr;
  56. struct xfs_inode *ip = XFS_I(inode);
  57. int error = 0;
  58. for (xattr = xattr_array; xattr->name != NULL; xattr++) {
  59. error = xfs_attr_set(ip, xattr->name, xattr->value,
  60. xattr->value_len, ATTR_SECURE);
  61. if (error < 0)
  62. break;
  63. }
  64. return error;
  65. }
  66. /*
  67. * Hook in SELinux. This is not quite correct yet, what we really need
  68. * here (as we do for default ACLs) is a mechanism by which creation of
  69. * these attrs can be journalled at inode creation time (along with the
  70. * inode, of course, such that log replay can't cause these to be lost).
  71. */
  72. STATIC int
  73. xfs_init_security(
  74. struct inode *inode,
  75. struct inode *dir,
  76. const struct qstr *qstr)
  77. {
  78. return security_inode_init_security(inode, dir, qstr,
  79. &xfs_initxattrs, NULL);
  80. }
  81. static void
  82. xfs_dentry_to_name(
  83. struct xfs_name *namep,
  84. struct dentry *dentry,
  85. int mode)
  86. {
  87. namep->name = dentry->d_name.name;
  88. namep->len = dentry->d_name.len;
  89. namep->type = xfs_mode_to_ftype[(mode & S_IFMT) >> S_SHIFT];
  90. }
  91. STATIC void
  92. xfs_cleanup_inode(
  93. struct inode *dir,
  94. struct inode *inode,
  95. struct dentry *dentry)
  96. {
  97. struct xfs_name teardown;
  98. /* Oh, the horror.
  99. * If we can't add the ACL or we fail in
  100. * xfs_init_security we must back out.
  101. * ENOSPC can hit here, among other things.
  102. */
  103. xfs_dentry_to_name(&teardown, dentry, 0);
  104. xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
  105. iput(inode);
  106. }
  107. STATIC int
  108. xfs_vn_mknod(
  109. struct inode *dir,
  110. struct dentry *dentry,
  111. umode_t mode,
  112. dev_t rdev)
  113. {
  114. struct inode *inode;
  115. struct xfs_inode *ip = NULL;
  116. struct posix_acl *default_acl, *acl;
  117. struct xfs_name name;
  118. int error;
  119. /*
  120. * Irix uses Missed'em'V split, but doesn't want to see
  121. * the upper 5 bits of (14bit) major.
  122. */
  123. if (S_ISCHR(mode) || S_ISBLK(mode)) {
  124. if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
  125. return -EINVAL;
  126. rdev = sysv_encode_dev(rdev);
  127. } else {
  128. rdev = 0;
  129. }
  130. error = posix_acl_create(dir, &mode, &default_acl, &acl);
  131. if (error)
  132. return error;
  133. xfs_dentry_to_name(&name, dentry, mode);
  134. error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip);
  135. if (unlikely(error))
  136. goto out_free_acl;
  137. inode = VFS_I(ip);
  138. error = xfs_init_security(inode, dir, &dentry->d_name);
  139. if (unlikely(error))
  140. goto out_cleanup_inode;
  141. #ifdef CONFIG_XFS_POSIX_ACL
  142. if (default_acl) {
  143. error = xfs_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
  144. if (error)
  145. goto out_cleanup_inode;
  146. }
  147. if (acl) {
  148. error = xfs_set_acl(inode, acl, ACL_TYPE_ACCESS);
  149. if (error)
  150. goto out_cleanup_inode;
  151. }
  152. #endif
  153. d_instantiate(dentry, inode);
  154. out_free_acl:
  155. if (default_acl)
  156. posix_acl_release(default_acl);
  157. if (acl)
  158. posix_acl_release(acl);
  159. return -error;
  160. out_cleanup_inode:
  161. xfs_cleanup_inode(dir, inode, dentry);
  162. goto out_free_acl;
  163. }
  164. STATIC int
  165. xfs_vn_create(
  166. struct inode *dir,
  167. struct dentry *dentry,
  168. umode_t mode,
  169. bool flags)
  170. {
  171. return xfs_vn_mknod(dir, dentry, mode, 0);
  172. }
  173. STATIC int
  174. xfs_vn_mkdir(
  175. struct inode *dir,
  176. struct dentry *dentry,
  177. umode_t mode)
  178. {
  179. return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
  180. }
  181. STATIC struct dentry *
  182. xfs_vn_lookup(
  183. struct inode *dir,
  184. struct dentry *dentry,
  185. unsigned int flags)
  186. {
  187. struct xfs_inode *cip;
  188. struct xfs_name name;
  189. int error;
  190. if (dentry->d_name.len >= MAXNAMELEN)
  191. return ERR_PTR(-ENAMETOOLONG);
  192. xfs_dentry_to_name(&name, dentry, 0);
  193. error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
  194. if (unlikely(error)) {
  195. if (unlikely(error != ENOENT))
  196. return ERR_PTR(-error);
  197. d_add(dentry, NULL);
  198. return NULL;
  199. }
  200. return d_splice_alias(VFS_I(cip), dentry);
  201. }
  202. STATIC struct dentry *
  203. xfs_vn_ci_lookup(
  204. struct inode *dir,
  205. struct dentry *dentry,
  206. unsigned int flags)
  207. {
  208. struct xfs_inode *ip;
  209. struct xfs_name xname;
  210. struct xfs_name ci_name;
  211. struct qstr dname;
  212. int error;
  213. if (dentry->d_name.len >= MAXNAMELEN)
  214. return ERR_PTR(-ENAMETOOLONG);
  215. xfs_dentry_to_name(&xname, dentry, 0);
  216. error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name);
  217. if (unlikely(error)) {
  218. if (unlikely(error != ENOENT))
  219. return ERR_PTR(-error);
  220. /*
  221. * call d_add(dentry, NULL) here when d_drop_negative_children
  222. * is called in xfs_vn_mknod (ie. allow negative dentries
  223. * with CI filesystems).
  224. */
  225. return NULL;
  226. }
  227. /* if exact match, just splice and exit */
  228. if (!ci_name.name)
  229. return d_splice_alias(VFS_I(ip), dentry);
  230. /* else case-insensitive match... */
  231. dname.name = ci_name.name;
  232. dname.len = ci_name.len;
  233. dentry = d_add_ci(dentry, VFS_I(ip), &dname);
  234. kmem_free(ci_name.name);
  235. return dentry;
  236. }
  237. STATIC int
  238. xfs_vn_link(
  239. struct dentry *old_dentry,
  240. struct inode *dir,
  241. struct dentry *dentry)
  242. {
  243. struct inode *inode = old_dentry->d_inode;
  244. struct xfs_name name;
  245. int error;
  246. xfs_dentry_to_name(&name, dentry, inode->i_mode);
  247. error = xfs_link(XFS_I(dir), XFS_I(inode), &name);
  248. if (unlikely(error))
  249. return -error;
  250. ihold(inode);
  251. d_instantiate(dentry, inode);
  252. return 0;
  253. }
  254. STATIC int
  255. xfs_vn_unlink(
  256. struct inode *dir,
  257. struct dentry *dentry)
  258. {
  259. struct xfs_name name;
  260. int error;
  261. xfs_dentry_to_name(&name, dentry, 0);
  262. error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
  263. if (error)
  264. return error;
  265. /*
  266. * With unlink, the VFS makes the dentry "negative": no inode,
  267. * but still hashed. This is incompatible with case-insensitive
  268. * mode, so invalidate (unhash) the dentry in CI-mode.
  269. */
  270. if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
  271. d_invalidate(dentry);
  272. return 0;
  273. }
  274. STATIC int
  275. xfs_vn_symlink(
  276. struct inode *dir,
  277. struct dentry *dentry,
  278. const char *symname)
  279. {
  280. struct inode *inode;
  281. struct xfs_inode *cip = NULL;
  282. struct xfs_name name;
  283. int error;
  284. umode_t mode;
  285. mode = S_IFLNK |
  286. (irix_symlink_mode ? 0777 & ~current_umask() : S_IRWXUGO);
  287. xfs_dentry_to_name(&name, dentry, mode);
  288. error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip);
  289. if (unlikely(error))
  290. goto out;
  291. inode = VFS_I(cip);
  292. error = xfs_init_security(inode, dir, &dentry->d_name);
  293. if (unlikely(error))
  294. goto out_cleanup_inode;
  295. d_instantiate(dentry, inode);
  296. return 0;
  297. out_cleanup_inode:
  298. xfs_cleanup_inode(dir, inode, dentry);
  299. out:
  300. return -error;
  301. }
  302. STATIC int
  303. xfs_vn_rename(
  304. struct inode *odir,
  305. struct dentry *odentry,
  306. struct inode *ndir,
  307. struct dentry *ndentry)
  308. {
  309. struct inode *new_inode = ndentry->d_inode;
  310. struct xfs_name oname;
  311. struct xfs_name nname;
  312. xfs_dentry_to_name(&oname, odentry, 0);
  313. xfs_dentry_to_name(&nname, ndentry, odentry->d_inode->i_mode);
  314. return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
  315. XFS_I(ndir), &nname, new_inode ?
  316. XFS_I(new_inode) : NULL);
  317. }
  318. /*
  319. * careful here - this function can get called recursively, so
  320. * we need to be very careful about how much stack we use.
  321. * uio is kmalloced for this reason...
  322. */
  323. STATIC void *
  324. xfs_vn_follow_link(
  325. struct dentry *dentry,
  326. struct nameidata *nd)
  327. {
  328. char *link;
  329. int error = -ENOMEM;
  330. link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
  331. if (!link)
  332. goto out_err;
  333. error = -xfs_readlink(XFS_I(dentry->d_inode), link);
  334. if (unlikely(error))
  335. goto out_kfree;
  336. nd_set_link(nd, link);
  337. return NULL;
  338. out_kfree:
  339. kfree(link);
  340. out_err:
  341. nd_set_link(nd, ERR_PTR(error));
  342. return NULL;
  343. }
  344. STATIC int
  345. xfs_vn_getattr(
  346. struct vfsmount *mnt,
  347. struct dentry *dentry,
  348. struct kstat *stat)
  349. {
  350. struct inode *inode = dentry->d_inode;
  351. struct xfs_inode *ip = XFS_I(inode);
  352. struct xfs_mount *mp = ip->i_mount;
  353. trace_xfs_getattr(ip);
  354. if (XFS_FORCED_SHUTDOWN(mp))
  355. return -XFS_ERROR(EIO);
  356. stat->size = XFS_ISIZE(ip);
  357. stat->dev = inode->i_sb->s_dev;
  358. stat->mode = ip->i_d.di_mode;
  359. stat->nlink = ip->i_d.di_nlink;
  360. stat->uid = inode->i_uid;
  361. stat->gid = inode->i_gid;
  362. stat->ino = ip->i_ino;
  363. stat->atime = inode->i_atime;
  364. stat->mtime = inode->i_mtime;
  365. stat->ctime = inode->i_ctime;
  366. stat->blocks =
  367. XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
  368. switch (inode->i_mode & S_IFMT) {
  369. case S_IFBLK:
  370. case S_IFCHR:
  371. stat->blksize = BLKDEV_IOSIZE;
  372. stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
  373. sysv_minor(ip->i_df.if_u2.if_rdev));
  374. break;
  375. default:
  376. if (XFS_IS_REALTIME_INODE(ip)) {
  377. /*
  378. * If the file blocks are being allocated from a
  379. * realtime volume, then return the inode's realtime
  380. * extent size or the realtime volume's extent size.
  381. */
  382. stat->blksize =
  383. xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
  384. } else
  385. stat->blksize = xfs_preferred_iosize(mp);
  386. stat->rdev = 0;
  387. break;
  388. }
  389. return 0;
  390. }
  391. static void
  392. xfs_setattr_mode(
  393. struct xfs_inode *ip,
  394. struct iattr *iattr)
  395. {
  396. struct inode *inode = VFS_I(ip);
  397. umode_t mode = iattr->ia_mode;
  398. ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
  399. ip->i_d.di_mode &= S_IFMT;
  400. ip->i_d.di_mode |= mode & ~S_IFMT;
  401. inode->i_mode &= S_IFMT;
  402. inode->i_mode |= mode & ~S_IFMT;
  403. }
  404. static void
  405. xfs_setattr_time(
  406. struct xfs_inode *ip,
  407. struct iattr *iattr)
  408. {
  409. struct inode *inode = VFS_I(ip);
  410. ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
  411. if (iattr->ia_valid & ATTR_ATIME) {
  412. inode->i_atime = iattr->ia_atime;
  413. ip->i_d.di_atime.t_sec = iattr->ia_atime.tv_sec;
  414. ip->i_d.di_atime.t_nsec = iattr->ia_atime.tv_nsec;
  415. }
  416. if (iattr->ia_valid & ATTR_CTIME) {
  417. inode->i_ctime = iattr->ia_ctime;
  418. ip->i_d.di_ctime.t_sec = iattr->ia_ctime.tv_sec;
  419. ip->i_d.di_ctime.t_nsec = iattr->ia_ctime.tv_nsec;
  420. }
  421. if (iattr->ia_valid & ATTR_MTIME) {
  422. inode->i_mtime = iattr->ia_mtime;
  423. ip->i_d.di_mtime.t_sec = iattr->ia_mtime.tv_sec;
  424. ip->i_d.di_mtime.t_nsec = iattr->ia_mtime.tv_nsec;
  425. }
  426. }
  427. int
  428. xfs_setattr_nonsize(
  429. struct xfs_inode *ip,
  430. struct iattr *iattr,
  431. int flags)
  432. {
  433. xfs_mount_t *mp = ip->i_mount;
  434. struct inode *inode = VFS_I(ip);
  435. int mask = iattr->ia_valid;
  436. xfs_trans_t *tp;
  437. int error;
  438. kuid_t uid = GLOBAL_ROOT_UID, iuid = GLOBAL_ROOT_UID;
  439. kgid_t gid = GLOBAL_ROOT_GID, igid = GLOBAL_ROOT_GID;
  440. struct xfs_dquot *udqp = NULL, *gdqp = NULL;
  441. struct xfs_dquot *olddquot1 = NULL, *olddquot2 = NULL;
  442. trace_xfs_setattr(ip);
  443. /* If acls are being inherited, we already have this checked */
  444. if (!(flags & XFS_ATTR_NOACL)) {
  445. if (mp->m_flags & XFS_MOUNT_RDONLY)
  446. return XFS_ERROR(EROFS);
  447. if (XFS_FORCED_SHUTDOWN(mp))
  448. return XFS_ERROR(EIO);
  449. error = -inode_change_ok(inode, iattr);
  450. if (error)
  451. return XFS_ERROR(error);
  452. }
  453. ASSERT((mask & ATTR_SIZE) == 0);
  454. /*
  455. * If disk quotas is on, we make sure that the dquots do exist on disk,
  456. * before we start any other transactions. Trying to do this later
  457. * is messy. We don't care to take a readlock to look at the ids
  458. * in inode here, because we can't hold it across the trans_reserve.
  459. * If the IDs do change before we take the ilock, we're covered
  460. * because the i_*dquot fields will get updated anyway.
  461. */
  462. if (XFS_IS_QUOTA_ON(mp) && (mask & (ATTR_UID|ATTR_GID))) {
  463. uint qflags = 0;
  464. if ((mask & ATTR_UID) && XFS_IS_UQUOTA_ON(mp)) {
  465. uid = iattr->ia_uid;
  466. qflags |= XFS_QMOPT_UQUOTA;
  467. } else {
  468. uid = inode->i_uid;
  469. }
  470. if ((mask & ATTR_GID) && XFS_IS_GQUOTA_ON(mp)) {
  471. gid = iattr->ia_gid;
  472. qflags |= XFS_QMOPT_GQUOTA;
  473. } else {
  474. gid = inode->i_gid;
  475. }
  476. /*
  477. * We take a reference when we initialize udqp and gdqp,
  478. * so it is important that we never blindly double trip on
  479. * the same variable. See xfs_create() for an example.
  480. */
  481. ASSERT(udqp == NULL);
  482. ASSERT(gdqp == NULL);
  483. error = xfs_qm_vop_dqalloc(ip, xfs_kuid_to_uid(uid),
  484. xfs_kgid_to_gid(gid),
  485. xfs_get_projid(ip),
  486. qflags, &udqp, &gdqp, NULL);
  487. if (error)
  488. return error;
  489. }
  490. tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
  491. error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 0, 0);
  492. if (error)
  493. goto out_dqrele;
  494. xfs_ilock(ip, XFS_ILOCK_EXCL);
  495. /*
  496. * Change file ownership. Must be the owner or privileged.
  497. */
  498. if (mask & (ATTR_UID|ATTR_GID)) {
  499. /*
  500. * These IDs could have changed since we last looked at them.
  501. * But, we're assured that if the ownership did change
  502. * while we didn't have the inode locked, inode's dquot(s)
  503. * would have changed also.
  504. */
  505. iuid = inode->i_uid;
  506. igid = inode->i_gid;
  507. gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
  508. uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
  509. /*
  510. * Do a quota reservation only if uid/gid is actually
  511. * going to change.
  512. */
  513. if (XFS_IS_QUOTA_RUNNING(mp) &&
  514. ((XFS_IS_UQUOTA_ON(mp) && !uid_eq(iuid, uid)) ||
  515. (XFS_IS_GQUOTA_ON(mp) && !gid_eq(igid, gid)))) {
  516. ASSERT(tp);
  517. error = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
  518. NULL, capable(CAP_FOWNER) ?
  519. XFS_QMOPT_FORCE_RES : 0);
  520. if (error) /* out of quota */
  521. goto out_trans_cancel;
  522. }
  523. }
  524. xfs_trans_ijoin(tp, ip, 0);
  525. /*
  526. * Change file ownership. Must be the owner or privileged.
  527. */
  528. if (mask & (ATTR_UID|ATTR_GID)) {
  529. /*
  530. * CAP_FSETID overrides the following restrictions:
  531. *
  532. * The set-user-ID and set-group-ID bits of a file will be
  533. * cleared upon successful return from chown()
  534. */
  535. if ((ip->i_d.di_mode & (S_ISUID|S_ISGID)) &&
  536. !capable(CAP_FSETID))
  537. ip->i_d.di_mode &= ~(S_ISUID|S_ISGID);
  538. /*
  539. * Change the ownerships and register quota modifications
  540. * in the transaction.
  541. */
  542. if (!uid_eq(iuid, uid)) {
  543. if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
  544. ASSERT(mask & ATTR_UID);
  545. ASSERT(udqp);
  546. olddquot1 = xfs_qm_vop_chown(tp, ip,
  547. &ip->i_udquot, udqp);
  548. }
  549. ip->i_d.di_uid = xfs_kuid_to_uid(uid);
  550. inode->i_uid = uid;
  551. }
  552. if (!gid_eq(igid, gid)) {
  553. if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_GQUOTA_ON(mp)) {
  554. ASSERT(xfs_sb_version_has_pquotino(&mp->m_sb) ||
  555. !XFS_IS_PQUOTA_ON(mp));
  556. ASSERT(mask & ATTR_GID);
  557. ASSERT(gdqp);
  558. olddquot2 = xfs_qm_vop_chown(tp, ip,
  559. &ip->i_gdquot, gdqp);
  560. }
  561. ip->i_d.di_gid = xfs_kgid_to_gid(gid);
  562. inode->i_gid = gid;
  563. }
  564. }
  565. if (mask & ATTR_MODE)
  566. xfs_setattr_mode(ip, iattr);
  567. if (mask & (ATTR_ATIME|ATTR_CTIME|ATTR_MTIME))
  568. xfs_setattr_time(ip, iattr);
  569. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  570. XFS_STATS_INC(xs_ig_attrchg);
  571. if (mp->m_flags & XFS_MOUNT_WSYNC)
  572. xfs_trans_set_sync(tp);
  573. error = xfs_trans_commit(tp, 0);
  574. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  575. /*
  576. * Release any dquot(s) the inode had kept before chown.
  577. */
  578. xfs_qm_dqrele(olddquot1);
  579. xfs_qm_dqrele(olddquot2);
  580. xfs_qm_dqrele(udqp);
  581. xfs_qm_dqrele(gdqp);
  582. if (error)
  583. return XFS_ERROR(error);
  584. /*
  585. * XXX(hch): Updating the ACL entries is not atomic vs the i_mode
  586. * update. We could avoid this with linked transactions
  587. * and passing down the transaction pointer all the way
  588. * to attr_set. No previous user of the generic
  589. * Posix ACL code seems to care about this issue either.
  590. */
  591. if ((mask & ATTR_MODE) && !(flags & XFS_ATTR_NOACL)) {
  592. error = -posix_acl_chmod(inode, inode->i_mode);
  593. if (error)
  594. return XFS_ERROR(error);
  595. }
  596. return 0;
  597. out_trans_cancel:
  598. xfs_trans_cancel(tp, 0);
  599. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  600. out_dqrele:
  601. xfs_qm_dqrele(udqp);
  602. xfs_qm_dqrele(gdqp);
  603. return error;
  604. }
  605. /*
  606. * Truncate file. Must have write permission and not be a directory.
  607. */
  608. int
  609. xfs_setattr_size(
  610. struct xfs_inode *ip,
  611. struct iattr *iattr)
  612. {
  613. struct xfs_mount *mp = ip->i_mount;
  614. struct inode *inode = VFS_I(ip);
  615. int mask = iattr->ia_valid;
  616. xfs_off_t oldsize, newsize;
  617. struct xfs_trans *tp;
  618. int error;
  619. uint lock_flags = 0;
  620. uint commit_flags = 0;
  621. trace_xfs_setattr(ip);
  622. if (mp->m_flags & XFS_MOUNT_RDONLY)
  623. return XFS_ERROR(EROFS);
  624. if (XFS_FORCED_SHUTDOWN(mp))
  625. return XFS_ERROR(EIO);
  626. error = -inode_change_ok(inode, iattr);
  627. if (error)
  628. return XFS_ERROR(error);
  629. ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
  630. ASSERT(S_ISREG(ip->i_d.di_mode));
  631. ASSERT((mask & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET|
  632. ATTR_MTIME_SET|ATTR_KILL_PRIV|ATTR_TIMES_SET)) == 0);
  633. oldsize = inode->i_size;
  634. newsize = iattr->ia_size;
  635. /*
  636. * Short circuit the truncate case for zero length files.
  637. */
  638. if (newsize == 0 && oldsize == 0 && ip->i_d.di_nextents == 0) {
  639. if (!(mask & (ATTR_CTIME|ATTR_MTIME)))
  640. return 0;
  641. /*
  642. * Use the regular setattr path to update the timestamps.
  643. */
  644. iattr->ia_valid &= ~ATTR_SIZE;
  645. return xfs_setattr_nonsize(ip, iattr, 0);
  646. }
  647. /*
  648. * Make sure that the dquots are attached to the inode.
  649. */
  650. error = xfs_qm_dqattach(ip, 0);
  651. if (error)
  652. return error;
  653. /*
  654. * Now we can make the changes. Before we join the inode to the
  655. * transaction, take care of the part of the truncation that must be
  656. * done without the inode lock. This needs to be done before joining
  657. * the inode to the transaction, because the inode cannot be unlocked
  658. * once it is a part of the transaction.
  659. */
  660. if (newsize > oldsize) {
  661. /*
  662. * Do the first part of growing a file: zero any data in the
  663. * last block that is beyond the old EOF. We need to do this
  664. * before the inode is joined to the transaction to modify
  665. * i_size.
  666. */
  667. error = xfs_zero_eof(ip, newsize, oldsize);
  668. if (error)
  669. return error;
  670. }
  671. /*
  672. * We are going to log the inode size change in this transaction so
  673. * any previous writes that are beyond the on disk EOF and the new
  674. * EOF that have not been written out need to be written here. If we
  675. * do not write the data out, we expose ourselves to the null files
  676. * problem.
  677. *
  678. * Only flush from the on disk size to the smaller of the in memory
  679. * file size or the new size as that's the range we really care about
  680. * here and prevents waiting for other data not within the range we
  681. * care about here.
  682. */
  683. if (oldsize != ip->i_d.di_size && newsize > ip->i_d.di_size) {
  684. error = -filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
  685. ip->i_d.di_size, newsize);
  686. if (error)
  687. return error;
  688. }
  689. /*
  690. * Wait for all direct I/O to complete.
  691. */
  692. inode_dio_wait(inode);
  693. error = -block_truncate_page(inode->i_mapping, newsize, xfs_get_blocks);
  694. if (error)
  695. return error;
  696. tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_SIZE);
  697. error = xfs_trans_reserve(tp, &M_RES(mp)->tr_itruncate, 0, 0);
  698. if (error)
  699. goto out_trans_cancel;
  700. truncate_setsize(inode, newsize);
  701. commit_flags = XFS_TRANS_RELEASE_LOG_RES;
  702. lock_flags |= XFS_ILOCK_EXCL;
  703. xfs_ilock(ip, XFS_ILOCK_EXCL);
  704. xfs_trans_ijoin(tp, ip, 0);
  705. /*
  706. * Only change the c/mtime if we are changing the size or we are
  707. * explicitly asked to change it. This handles the semantic difference
  708. * between truncate() and ftruncate() as implemented in the VFS.
  709. *
  710. * The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a
  711. * special case where we need to update the times despite not having
  712. * these flags set. For all other operations the VFS set these flags
  713. * explicitly if it wants a timestamp update.
  714. */
  715. if (newsize != oldsize && (!(mask & (ATTR_CTIME | ATTR_MTIME)))) {
  716. iattr->ia_ctime = iattr->ia_mtime =
  717. current_fs_time(inode->i_sb);
  718. mask |= ATTR_CTIME | ATTR_MTIME;
  719. }
  720. /*
  721. * The first thing we do is set the size to new_size permanently on
  722. * disk. This way we don't have to worry about anyone ever being able
  723. * to look at the data being freed even in the face of a crash.
  724. * What we're getting around here is the case where we free a block, it
  725. * is allocated to another file, it is written to, and then we crash.
  726. * If the new data gets written to the file but the log buffers
  727. * containing the free and reallocation don't, then we'd end up with
  728. * garbage in the blocks being freed. As long as we make the new size
  729. * permanent before actually freeing any blocks it doesn't matter if
  730. * they get written to.
  731. */
  732. ip->i_d.di_size = newsize;
  733. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  734. if (newsize <= oldsize) {
  735. error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, newsize);
  736. if (error)
  737. goto out_trans_abort;
  738. /*
  739. * Truncated "down", so we're removing references to old data
  740. * here - if we delay flushing for a long time, we expose
  741. * ourselves unduly to the notorious NULL files problem. So,
  742. * we mark this inode and flush it when the file is closed,
  743. * and do not wait the usual (long) time for writeout.
  744. */
  745. xfs_iflags_set(ip, XFS_ITRUNCATED);
  746. /* A truncate down always removes post-EOF blocks. */
  747. xfs_inode_clear_eofblocks_tag(ip);
  748. }
  749. if (mask & ATTR_MODE)
  750. xfs_setattr_mode(ip, iattr);
  751. if (mask & (ATTR_ATIME|ATTR_CTIME|ATTR_MTIME))
  752. xfs_setattr_time(ip, iattr);
  753. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  754. XFS_STATS_INC(xs_ig_attrchg);
  755. if (mp->m_flags & XFS_MOUNT_WSYNC)
  756. xfs_trans_set_sync(tp);
  757. error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
  758. out_unlock:
  759. if (lock_flags)
  760. xfs_iunlock(ip, lock_flags);
  761. return error;
  762. out_trans_abort:
  763. commit_flags |= XFS_TRANS_ABORT;
  764. out_trans_cancel:
  765. xfs_trans_cancel(tp, commit_flags);
  766. goto out_unlock;
  767. }
  768. STATIC int
  769. xfs_vn_setattr(
  770. struct dentry *dentry,
  771. struct iattr *iattr)
  772. {
  773. struct xfs_inode *ip = XFS_I(dentry->d_inode);
  774. int error;
  775. if (iattr->ia_valid & ATTR_SIZE) {
  776. xfs_ilock(ip, XFS_IOLOCK_EXCL);
  777. error = xfs_setattr_size(ip, iattr);
  778. xfs_iunlock(ip, XFS_IOLOCK_EXCL);
  779. } else {
  780. error = xfs_setattr_nonsize(ip, iattr, 0);
  781. }
  782. return -error;
  783. }
  784. STATIC int
  785. xfs_vn_update_time(
  786. struct inode *inode,
  787. struct timespec *now,
  788. int flags)
  789. {
  790. struct xfs_inode *ip = XFS_I(inode);
  791. struct xfs_mount *mp = ip->i_mount;
  792. struct xfs_trans *tp;
  793. int error;
  794. trace_xfs_update_time(ip);
  795. tp = xfs_trans_alloc(mp, XFS_TRANS_FSYNC_TS);
  796. error = xfs_trans_reserve(tp, &M_RES(mp)->tr_fsyncts, 0, 0);
  797. if (error) {
  798. xfs_trans_cancel(tp, 0);
  799. return -error;
  800. }
  801. xfs_ilock(ip, XFS_ILOCK_EXCL);
  802. if (flags & S_CTIME) {
  803. inode->i_ctime = *now;
  804. ip->i_d.di_ctime.t_sec = (__int32_t)now->tv_sec;
  805. ip->i_d.di_ctime.t_nsec = (__int32_t)now->tv_nsec;
  806. }
  807. if (flags & S_MTIME) {
  808. inode->i_mtime = *now;
  809. ip->i_d.di_mtime.t_sec = (__int32_t)now->tv_sec;
  810. ip->i_d.di_mtime.t_nsec = (__int32_t)now->tv_nsec;
  811. }
  812. if (flags & S_ATIME) {
  813. inode->i_atime = *now;
  814. ip->i_d.di_atime.t_sec = (__int32_t)now->tv_sec;
  815. ip->i_d.di_atime.t_nsec = (__int32_t)now->tv_nsec;
  816. }
  817. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  818. xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
  819. return -xfs_trans_commit(tp, 0);
  820. }
  821. #define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR)
  822. /*
  823. * Call fiemap helper to fill in user data.
  824. * Returns positive errors to xfs_getbmap.
  825. */
  826. STATIC int
  827. xfs_fiemap_format(
  828. void **arg,
  829. struct getbmapx *bmv,
  830. int *full)
  831. {
  832. int error;
  833. struct fiemap_extent_info *fieinfo = *arg;
  834. u32 fiemap_flags = 0;
  835. u64 logical, physical, length;
  836. /* Do nothing for a hole */
  837. if (bmv->bmv_block == -1LL)
  838. return 0;
  839. logical = BBTOB(bmv->bmv_offset);
  840. physical = BBTOB(bmv->bmv_block);
  841. length = BBTOB(bmv->bmv_length);
  842. if (bmv->bmv_oflags & BMV_OF_PREALLOC)
  843. fiemap_flags |= FIEMAP_EXTENT_UNWRITTEN;
  844. else if (bmv->bmv_oflags & BMV_OF_DELALLOC) {
  845. fiemap_flags |= (FIEMAP_EXTENT_DELALLOC |
  846. FIEMAP_EXTENT_UNKNOWN);
  847. physical = 0; /* no block yet */
  848. }
  849. if (bmv->bmv_oflags & BMV_OF_LAST)
  850. fiemap_flags |= FIEMAP_EXTENT_LAST;
  851. error = fiemap_fill_next_extent(fieinfo, logical, physical,
  852. length, fiemap_flags);
  853. if (error > 0) {
  854. error = 0;
  855. *full = 1; /* user array now full */
  856. }
  857. return -error;
  858. }
  859. STATIC int
  860. xfs_vn_fiemap(
  861. struct inode *inode,
  862. struct fiemap_extent_info *fieinfo,
  863. u64 start,
  864. u64 length)
  865. {
  866. xfs_inode_t *ip = XFS_I(inode);
  867. struct getbmapx bm;
  868. int error;
  869. error = fiemap_check_flags(fieinfo, XFS_FIEMAP_FLAGS);
  870. if (error)
  871. return error;
  872. /* Set up bmap header for xfs internal routine */
  873. bm.bmv_offset = BTOBB(start);
  874. /* Special case for whole file */
  875. if (length == FIEMAP_MAX_OFFSET)
  876. bm.bmv_length = -1LL;
  877. else
  878. bm.bmv_length = BTOBB(length);
  879. /* We add one because in getbmap world count includes the header */
  880. bm.bmv_count = !fieinfo->fi_extents_max ? MAXEXTNUM :
  881. fieinfo->fi_extents_max + 1;
  882. bm.bmv_count = min_t(__s32, bm.bmv_count,
  883. (PAGE_SIZE * 16 / sizeof(struct getbmapx)));
  884. bm.bmv_iflags = BMV_IF_PREALLOC | BMV_IF_NO_HOLES;
  885. if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR)
  886. bm.bmv_iflags |= BMV_IF_ATTRFORK;
  887. if (!(fieinfo->fi_flags & FIEMAP_FLAG_SYNC))
  888. bm.bmv_iflags |= BMV_IF_DELALLOC;
  889. error = xfs_getbmap(ip, &bm, xfs_fiemap_format, fieinfo);
  890. if (error)
  891. return -error;
  892. return 0;
  893. }
  894. static const struct inode_operations xfs_inode_operations = {
  895. .get_acl = xfs_get_acl,
  896. .set_acl = xfs_set_acl,
  897. .getattr = xfs_vn_getattr,
  898. .setattr = xfs_vn_setattr,
  899. .setxattr = generic_setxattr,
  900. .getxattr = generic_getxattr,
  901. .removexattr = generic_removexattr,
  902. .listxattr = xfs_vn_listxattr,
  903. .fiemap = xfs_vn_fiemap,
  904. .update_time = xfs_vn_update_time,
  905. };
  906. static const struct inode_operations xfs_dir_inode_operations = {
  907. .create = xfs_vn_create,
  908. .lookup = xfs_vn_lookup,
  909. .link = xfs_vn_link,
  910. .unlink = xfs_vn_unlink,
  911. .symlink = xfs_vn_symlink,
  912. .mkdir = xfs_vn_mkdir,
  913. /*
  914. * Yes, XFS uses the same method for rmdir and unlink.
  915. *
  916. * There are some subtile differences deeper in the code,
  917. * but we use S_ISDIR to check for those.
  918. */
  919. .rmdir = xfs_vn_unlink,
  920. .mknod = xfs_vn_mknod,
  921. .rename = xfs_vn_rename,
  922. .get_acl = xfs_get_acl,
  923. .set_acl = xfs_set_acl,
  924. .getattr = xfs_vn_getattr,
  925. .setattr = xfs_vn_setattr,
  926. .setxattr = generic_setxattr,
  927. .getxattr = generic_getxattr,
  928. .removexattr = generic_removexattr,
  929. .listxattr = xfs_vn_listxattr,
  930. .update_time = xfs_vn_update_time,
  931. };
  932. static const struct inode_operations xfs_dir_ci_inode_operations = {
  933. .create = xfs_vn_create,
  934. .lookup = xfs_vn_ci_lookup,
  935. .link = xfs_vn_link,
  936. .unlink = xfs_vn_unlink,
  937. .symlink = xfs_vn_symlink,
  938. .mkdir = xfs_vn_mkdir,
  939. /*
  940. * Yes, XFS uses the same method for rmdir and unlink.
  941. *
  942. * There are some subtile differences deeper in the code,
  943. * but we use S_ISDIR to check for those.
  944. */
  945. .rmdir = xfs_vn_unlink,
  946. .mknod = xfs_vn_mknod,
  947. .rename = xfs_vn_rename,
  948. .get_acl = xfs_get_acl,
  949. .set_acl = xfs_set_acl,
  950. .getattr = xfs_vn_getattr,
  951. .setattr = xfs_vn_setattr,
  952. .setxattr = generic_setxattr,
  953. .getxattr = generic_getxattr,
  954. .removexattr = generic_removexattr,
  955. .listxattr = xfs_vn_listxattr,
  956. .update_time = xfs_vn_update_time,
  957. };
  958. static const struct inode_operations xfs_symlink_inode_operations = {
  959. .readlink = generic_readlink,
  960. .follow_link = xfs_vn_follow_link,
  961. .put_link = kfree_put_link,
  962. .getattr = xfs_vn_getattr,
  963. .setattr = xfs_vn_setattr,
  964. .setxattr = generic_setxattr,
  965. .getxattr = generic_getxattr,
  966. .removexattr = generic_removexattr,
  967. .listxattr = xfs_vn_listxattr,
  968. .update_time = xfs_vn_update_time,
  969. };
  970. STATIC void
  971. xfs_diflags_to_iflags(
  972. struct inode *inode,
  973. struct xfs_inode *ip)
  974. {
  975. if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
  976. inode->i_flags |= S_IMMUTABLE;
  977. else
  978. inode->i_flags &= ~S_IMMUTABLE;
  979. if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
  980. inode->i_flags |= S_APPEND;
  981. else
  982. inode->i_flags &= ~S_APPEND;
  983. if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
  984. inode->i_flags |= S_SYNC;
  985. else
  986. inode->i_flags &= ~S_SYNC;
  987. if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
  988. inode->i_flags |= S_NOATIME;
  989. else
  990. inode->i_flags &= ~S_NOATIME;
  991. }
  992. /*
  993. * Initialize the Linux inode, set up the operation vectors and
  994. * unlock the inode.
  995. *
  996. * When reading existing inodes from disk this is called directly
  997. * from xfs_iget, when creating a new inode it is called from
  998. * xfs_ialloc after setting up the inode.
  999. *
  1000. * We are always called with an uninitialised linux inode here.
  1001. * We need to initialise the necessary fields and take a reference
  1002. * on it.
  1003. */
  1004. void
  1005. xfs_setup_inode(
  1006. struct xfs_inode *ip)
  1007. {
  1008. struct inode *inode = &ip->i_vnode;
  1009. gfp_t gfp_mask;
  1010. inode->i_ino = ip->i_ino;
  1011. inode->i_state = I_NEW;
  1012. inode_sb_list_add(inode);
  1013. /* make the inode look hashed for the writeback code */
  1014. hlist_add_fake(&inode->i_hash);
  1015. inode->i_mode = ip->i_d.di_mode;
  1016. set_nlink(inode, ip->i_d.di_nlink);
  1017. inode->i_uid = xfs_uid_to_kuid(ip->i_d.di_uid);
  1018. inode->i_gid = xfs_gid_to_kgid(ip->i_d.di_gid);
  1019. switch (inode->i_mode & S_IFMT) {
  1020. case S_IFBLK:
  1021. case S_IFCHR:
  1022. inode->i_rdev =
  1023. MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
  1024. sysv_minor(ip->i_df.if_u2.if_rdev));
  1025. break;
  1026. default:
  1027. inode->i_rdev = 0;
  1028. break;
  1029. }
  1030. inode->i_generation = ip->i_d.di_gen;
  1031. i_size_write(inode, ip->i_d.di_size);
  1032. inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
  1033. inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
  1034. inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
  1035. inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
  1036. inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
  1037. inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
  1038. xfs_diflags_to_iflags(inode, ip);
  1039. ip->d_ops = ip->i_mount->m_nondir_inode_ops;
  1040. switch (inode->i_mode & S_IFMT) {
  1041. case S_IFREG:
  1042. inode->i_op = &xfs_inode_operations;
  1043. inode->i_fop = &xfs_file_operations;
  1044. inode->i_mapping->a_ops = &xfs_address_space_operations;
  1045. break;
  1046. case S_IFDIR:
  1047. if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
  1048. inode->i_op = &xfs_dir_ci_inode_operations;
  1049. else
  1050. inode->i_op = &xfs_dir_inode_operations;
  1051. inode->i_fop = &xfs_dir_file_operations;
  1052. ip->d_ops = ip->i_mount->m_dir_inode_ops;
  1053. break;
  1054. case S_IFLNK:
  1055. inode->i_op = &xfs_symlink_inode_operations;
  1056. if (!(ip->i_df.if_flags & XFS_IFINLINE))
  1057. inode->i_mapping->a_ops = &xfs_address_space_operations;
  1058. break;
  1059. default:
  1060. inode->i_op = &xfs_inode_operations;
  1061. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  1062. break;
  1063. }
  1064. /*
  1065. * Ensure all page cache allocations are done from GFP_NOFS context to
  1066. * prevent direct reclaim recursion back into the filesystem and blowing
  1067. * stacks or deadlocking.
  1068. */
  1069. gfp_mask = mapping_gfp_mask(inode->i_mapping);
  1070. mapping_set_gfp_mask(inode->i_mapping, (gfp_mask & ~(__GFP_FS)));
  1071. /*
  1072. * If there is no attribute fork no ACL can exist on this inode,
  1073. * and it can't have any file capabilities attached to it either.
  1074. */
  1075. if (!XFS_IFORK_Q(ip)) {
  1076. inode_has_no_xattr(inode);
  1077. cache_no_acl(inode);
  1078. }
  1079. xfs_iflags_clear(ip, XFS_INEW);
  1080. barrier();
  1081. unlock_new_inode(inode);
  1082. }