xfs_iops.c 31 KB

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