xfs_iops.c 32 KB

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