xfs_iops.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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(MAXPATHLEN+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. struct vfsmount *mnt,
  425. struct dentry *dentry,
  426. struct kstat *stat)
  427. {
  428. struct inode *inode = d_inode(dentry);
  429. struct xfs_inode *ip = XFS_I(inode);
  430. struct xfs_mount *mp = ip->i_mount;
  431. trace_xfs_getattr(ip);
  432. if (XFS_FORCED_SHUTDOWN(mp))
  433. return -EIO;
  434. stat->size = XFS_ISIZE(ip);
  435. stat->dev = inode->i_sb->s_dev;
  436. stat->mode = inode->i_mode;
  437. stat->nlink = inode->i_nlink;
  438. stat->uid = inode->i_uid;
  439. stat->gid = inode->i_gid;
  440. stat->ino = ip->i_ino;
  441. stat->atime = inode->i_atime;
  442. stat->mtime = inode->i_mtime;
  443. stat->ctime = inode->i_ctime;
  444. stat->blocks =
  445. XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
  446. switch (inode->i_mode & S_IFMT) {
  447. case S_IFBLK:
  448. case S_IFCHR:
  449. stat->blksize = BLKDEV_IOSIZE;
  450. stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
  451. sysv_minor(ip->i_df.if_u2.if_rdev));
  452. break;
  453. default:
  454. if (XFS_IS_REALTIME_INODE(ip)) {
  455. /*
  456. * If the file blocks are being allocated from a
  457. * realtime volume, then return the inode's realtime
  458. * extent size or the realtime volume's extent size.
  459. */
  460. stat->blksize =
  461. xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
  462. } else
  463. stat->blksize = xfs_preferred_iosize(mp);
  464. stat->rdev = 0;
  465. break;
  466. }
  467. return 0;
  468. }
  469. static void
  470. xfs_setattr_mode(
  471. struct xfs_inode *ip,
  472. struct iattr *iattr)
  473. {
  474. struct inode *inode = VFS_I(ip);
  475. umode_t mode = iattr->ia_mode;
  476. ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
  477. inode->i_mode &= S_IFMT;
  478. inode->i_mode |= mode & ~S_IFMT;
  479. }
  480. void
  481. xfs_setattr_time(
  482. struct xfs_inode *ip,
  483. struct iattr *iattr)
  484. {
  485. struct inode *inode = VFS_I(ip);
  486. ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
  487. if (iattr->ia_valid & ATTR_ATIME)
  488. inode->i_atime = iattr->ia_atime;
  489. if (iattr->ia_valid & ATTR_CTIME)
  490. inode->i_ctime = iattr->ia_ctime;
  491. if (iattr->ia_valid & ATTR_MTIME)
  492. inode->i_mtime = iattr->ia_mtime;
  493. }
  494. static int
  495. xfs_vn_change_ok(
  496. struct dentry *dentry,
  497. struct iattr *iattr)
  498. {
  499. struct xfs_mount *mp = XFS_I(d_inode(dentry))->i_mount;
  500. if (mp->m_flags & XFS_MOUNT_RDONLY)
  501. return -EROFS;
  502. if (XFS_FORCED_SHUTDOWN(mp))
  503. return -EIO;
  504. return setattr_prepare(dentry, iattr);
  505. }
  506. /*
  507. * Set non-size attributes of an inode.
  508. *
  509. * Caution: The caller of this function is responsible for calling
  510. * setattr_prepare() or otherwise verifying the change is fine.
  511. */
  512. int
  513. xfs_setattr_nonsize(
  514. struct xfs_inode *ip,
  515. struct iattr *iattr,
  516. int flags)
  517. {
  518. xfs_mount_t *mp = ip->i_mount;
  519. struct inode *inode = VFS_I(ip);
  520. int mask = iattr->ia_valid;
  521. xfs_trans_t *tp;
  522. int error;
  523. kuid_t uid = GLOBAL_ROOT_UID, iuid = GLOBAL_ROOT_UID;
  524. kgid_t gid = GLOBAL_ROOT_GID, igid = GLOBAL_ROOT_GID;
  525. struct xfs_dquot *udqp = NULL, *gdqp = NULL;
  526. struct xfs_dquot *olddquot1 = NULL, *olddquot2 = NULL;
  527. ASSERT((mask & ATTR_SIZE) == 0);
  528. /*
  529. * If disk quotas is on, we make sure that the dquots do exist on disk,
  530. * before we start any other transactions. Trying to do this later
  531. * is messy. We don't care to take a readlock to look at the ids
  532. * in inode here, because we can't hold it across the trans_reserve.
  533. * If the IDs do change before we take the ilock, we're covered
  534. * because the i_*dquot fields will get updated anyway.
  535. */
  536. if (XFS_IS_QUOTA_ON(mp) && (mask & (ATTR_UID|ATTR_GID))) {
  537. uint qflags = 0;
  538. if ((mask & ATTR_UID) && XFS_IS_UQUOTA_ON(mp)) {
  539. uid = iattr->ia_uid;
  540. qflags |= XFS_QMOPT_UQUOTA;
  541. } else {
  542. uid = inode->i_uid;
  543. }
  544. if ((mask & ATTR_GID) && XFS_IS_GQUOTA_ON(mp)) {
  545. gid = iattr->ia_gid;
  546. qflags |= XFS_QMOPT_GQUOTA;
  547. } else {
  548. gid = inode->i_gid;
  549. }
  550. /*
  551. * We take a reference when we initialize udqp and gdqp,
  552. * so it is important that we never blindly double trip on
  553. * the same variable. See xfs_create() for an example.
  554. */
  555. ASSERT(udqp == NULL);
  556. ASSERT(gdqp == NULL);
  557. error = xfs_qm_vop_dqalloc(ip, xfs_kuid_to_uid(uid),
  558. xfs_kgid_to_gid(gid),
  559. xfs_get_projid(ip),
  560. qflags, &udqp, &gdqp, NULL);
  561. if (error)
  562. return error;
  563. }
  564. error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp);
  565. if (error)
  566. goto out_dqrele;
  567. xfs_ilock(ip, XFS_ILOCK_EXCL);
  568. xfs_trans_ijoin(tp, ip, 0);
  569. /*
  570. * Change file ownership. Must be the owner or privileged.
  571. */
  572. if (mask & (ATTR_UID|ATTR_GID)) {
  573. /*
  574. * These IDs could have changed since we last looked at them.
  575. * But, we're assured that if the ownership did change
  576. * while we didn't have the inode locked, inode's dquot(s)
  577. * would have changed also.
  578. */
  579. iuid = inode->i_uid;
  580. igid = inode->i_gid;
  581. gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
  582. uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
  583. /*
  584. * Do a quota reservation only if uid/gid is actually
  585. * going to change.
  586. */
  587. if (XFS_IS_QUOTA_RUNNING(mp) &&
  588. ((XFS_IS_UQUOTA_ON(mp) && !uid_eq(iuid, uid)) ||
  589. (XFS_IS_GQUOTA_ON(mp) && !gid_eq(igid, gid)))) {
  590. ASSERT(tp);
  591. error = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
  592. NULL, capable(CAP_FOWNER) ?
  593. XFS_QMOPT_FORCE_RES : 0);
  594. if (error) /* out of quota */
  595. goto out_cancel;
  596. }
  597. }
  598. /*
  599. * Change file ownership. Must be the owner or privileged.
  600. */
  601. if (mask & (ATTR_UID|ATTR_GID)) {
  602. /*
  603. * CAP_FSETID overrides the following restrictions:
  604. *
  605. * The set-user-ID and set-group-ID bits of a file will be
  606. * cleared upon successful return from chown()
  607. */
  608. if ((inode->i_mode & (S_ISUID|S_ISGID)) &&
  609. !capable(CAP_FSETID))
  610. inode->i_mode &= ~(S_ISUID|S_ISGID);
  611. /*
  612. * Change the ownerships and register quota modifications
  613. * in the transaction.
  614. */
  615. if (!uid_eq(iuid, uid)) {
  616. if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
  617. ASSERT(mask & ATTR_UID);
  618. ASSERT(udqp);
  619. olddquot1 = xfs_qm_vop_chown(tp, ip,
  620. &ip->i_udquot, udqp);
  621. }
  622. ip->i_d.di_uid = xfs_kuid_to_uid(uid);
  623. inode->i_uid = uid;
  624. }
  625. if (!gid_eq(igid, gid)) {
  626. if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_GQUOTA_ON(mp)) {
  627. ASSERT(xfs_sb_version_has_pquotino(&mp->m_sb) ||
  628. !XFS_IS_PQUOTA_ON(mp));
  629. ASSERT(mask & ATTR_GID);
  630. ASSERT(gdqp);
  631. olddquot2 = xfs_qm_vop_chown(tp, ip,
  632. &ip->i_gdquot, gdqp);
  633. }
  634. ip->i_d.di_gid = xfs_kgid_to_gid(gid);
  635. inode->i_gid = gid;
  636. }
  637. }
  638. if (mask & ATTR_MODE)
  639. xfs_setattr_mode(ip, iattr);
  640. if (mask & (ATTR_ATIME|ATTR_CTIME|ATTR_MTIME))
  641. xfs_setattr_time(ip, iattr);
  642. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  643. XFS_STATS_INC(mp, xs_ig_attrchg);
  644. if (mp->m_flags & XFS_MOUNT_WSYNC)
  645. xfs_trans_set_sync(tp);
  646. error = xfs_trans_commit(tp);
  647. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  648. /*
  649. * Release any dquot(s) the inode had kept before chown.
  650. */
  651. xfs_qm_dqrele(olddquot1);
  652. xfs_qm_dqrele(olddquot2);
  653. xfs_qm_dqrele(udqp);
  654. xfs_qm_dqrele(gdqp);
  655. if (error)
  656. return error;
  657. /*
  658. * XXX(hch): Updating the ACL entries is not atomic vs the i_mode
  659. * update. We could avoid this with linked transactions
  660. * and passing down the transaction pointer all the way
  661. * to attr_set. No previous user of the generic
  662. * Posix ACL code seems to care about this issue either.
  663. */
  664. if ((mask & ATTR_MODE) && !(flags & XFS_ATTR_NOACL)) {
  665. error = posix_acl_chmod(inode, inode->i_mode);
  666. if (error)
  667. return error;
  668. }
  669. return 0;
  670. out_cancel:
  671. xfs_trans_cancel(tp);
  672. out_dqrele:
  673. xfs_qm_dqrele(udqp);
  674. xfs_qm_dqrele(gdqp);
  675. return error;
  676. }
  677. int
  678. xfs_vn_setattr_nonsize(
  679. struct dentry *dentry,
  680. struct iattr *iattr)
  681. {
  682. struct xfs_inode *ip = XFS_I(d_inode(dentry));
  683. int error;
  684. trace_xfs_setattr(ip);
  685. error = xfs_vn_change_ok(dentry, iattr);
  686. if (error)
  687. return error;
  688. return xfs_setattr_nonsize(ip, iattr, 0);
  689. }
  690. /*
  691. * Truncate file. Must have write permission and not be a directory.
  692. *
  693. * Caution: The caller of this function is responsible for calling
  694. * setattr_prepare() or otherwise verifying the change is fine.
  695. */
  696. STATIC int
  697. xfs_setattr_size(
  698. struct xfs_inode *ip,
  699. struct iattr *iattr)
  700. {
  701. struct xfs_mount *mp = ip->i_mount;
  702. struct inode *inode = VFS_I(ip);
  703. xfs_off_t oldsize, newsize;
  704. struct xfs_trans *tp;
  705. int error;
  706. uint lock_flags = 0;
  707. bool did_zeroing = false;
  708. ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
  709. ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL));
  710. ASSERT(S_ISREG(inode->i_mode));
  711. ASSERT((iattr->ia_valid & (ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_ATIME_SET|
  712. ATTR_MTIME_SET|ATTR_KILL_PRIV|ATTR_TIMES_SET)) == 0);
  713. oldsize = inode->i_size;
  714. newsize = iattr->ia_size;
  715. /*
  716. * Short circuit the truncate case for zero length files.
  717. */
  718. if (newsize == 0 && oldsize == 0 && ip->i_d.di_nextents == 0) {
  719. if (!(iattr->ia_valid & (ATTR_CTIME|ATTR_MTIME)))
  720. return 0;
  721. /*
  722. * Use the regular setattr path to update the timestamps.
  723. */
  724. iattr->ia_valid &= ~ATTR_SIZE;
  725. return xfs_setattr_nonsize(ip, iattr, 0);
  726. }
  727. /*
  728. * Make sure that the dquots are attached to the inode.
  729. */
  730. error = xfs_qm_dqattach(ip, 0);
  731. if (error)
  732. return error;
  733. /*
  734. * Wait for all direct I/O to complete.
  735. */
  736. inode_dio_wait(inode);
  737. /*
  738. * File data changes must be complete before we start the transaction to
  739. * modify the inode. This needs to be done before joining the inode to
  740. * the transaction because the inode cannot be unlocked once it is a
  741. * part of the transaction.
  742. *
  743. * Start with zeroing any data beyond EOF that we may expose on file
  744. * extension, or zeroing out the rest of the block on a downward
  745. * truncate.
  746. */
  747. if (newsize > oldsize) {
  748. error = xfs_zero_eof(ip, newsize, oldsize, &did_zeroing);
  749. } else {
  750. error = iomap_truncate_page(inode, newsize, &did_zeroing,
  751. &xfs_iomap_ops);
  752. }
  753. if (error)
  754. return error;
  755. /*
  756. * We've already locked out new page faults, so now we can safely remove
  757. * pages from the page cache knowing they won't get refaulted until we
  758. * drop the XFS_MMAP_EXCL lock after the extent manipulations are
  759. * complete. The truncate_setsize() call also cleans partial EOF page
  760. * PTEs on extending truncates and hence ensures sub-page block size
  761. * filesystems are correctly handled, too.
  762. *
  763. * We have to do all the page cache truncate work outside the
  764. * transaction context as the "lock" order is page lock->log space
  765. * reservation as defined by extent allocation in the writeback path.
  766. * Hence a truncate can fail with ENOMEM from xfs_trans_alloc(), but
  767. * having already truncated the in-memory version of the file (i.e. made
  768. * user visible changes). There's not much we can do about this, except
  769. * to hope that the caller sees ENOMEM and retries the truncate
  770. * operation.
  771. *
  772. * And we update in-core i_size and truncate page cache beyond newsize
  773. * before writeback the [di_size, newsize] range, so we're guaranteed
  774. * not to write stale data past the new EOF on truncate down.
  775. */
  776. truncate_setsize(inode, newsize);
  777. /*
  778. * We are going to log the inode size change in this transaction so
  779. * any previous writes that are beyond the on disk EOF and the new
  780. * EOF that have not been written out need to be written here. If we
  781. * do not write the data out, we expose ourselves to the null files
  782. * problem. Note that this includes any block zeroing we did above;
  783. * otherwise those blocks may not be zeroed after a crash.
  784. */
  785. if (did_zeroing ||
  786. (newsize > ip->i_d.di_size && oldsize != ip->i_d.di_size)) {
  787. error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
  788. ip->i_d.di_size, newsize - 1);
  789. if (error)
  790. return error;
  791. }
  792. error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
  793. if (error)
  794. return error;
  795. lock_flags |= XFS_ILOCK_EXCL;
  796. xfs_ilock(ip, XFS_ILOCK_EXCL);
  797. xfs_trans_ijoin(tp, ip, 0);
  798. /*
  799. * Only change the c/mtime if we are changing the size or we are
  800. * explicitly asked to change it. This handles the semantic difference
  801. * between truncate() and ftruncate() as implemented in the VFS.
  802. *
  803. * The regular truncate() case without ATTR_CTIME and ATTR_MTIME is a
  804. * special case where we need to update the times despite not having
  805. * these flags set. For all other operations the VFS set these flags
  806. * explicitly if it wants a timestamp update.
  807. */
  808. if (newsize != oldsize &&
  809. !(iattr->ia_valid & (ATTR_CTIME | ATTR_MTIME))) {
  810. iattr->ia_ctime = iattr->ia_mtime =
  811. current_time(inode);
  812. iattr->ia_valid |= ATTR_CTIME | ATTR_MTIME;
  813. }
  814. /*
  815. * The first thing we do is set the size to new_size permanently on
  816. * disk. This way we don't have to worry about anyone ever being able
  817. * to look at the data being freed even in the face of a crash.
  818. * What we're getting around here is the case where we free a block, it
  819. * is allocated to another file, it is written to, and then we crash.
  820. * If the new data gets written to the file but the log buffers
  821. * containing the free and reallocation don't, then we'd end up with
  822. * garbage in the blocks being freed. As long as we make the new size
  823. * permanent before actually freeing any blocks it doesn't matter if
  824. * they get written to.
  825. */
  826. ip->i_d.di_size = newsize;
  827. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  828. if (newsize <= oldsize) {
  829. error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, newsize);
  830. if (error)
  831. goto out_trans_cancel;
  832. /*
  833. * Truncated "down", so we're removing references to old data
  834. * here - if we delay flushing for a long time, we expose
  835. * ourselves unduly to the notorious NULL files problem. So,
  836. * we mark this inode and flush it when the file is closed,
  837. * and do not wait the usual (long) time for writeout.
  838. */
  839. xfs_iflags_set(ip, XFS_ITRUNCATED);
  840. /* A truncate down always removes post-EOF blocks. */
  841. xfs_inode_clear_eofblocks_tag(ip);
  842. }
  843. if (iattr->ia_valid & ATTR_MODE)
  844. xfs_setattr_mode(ip, iattr);
  845. if (iattr->ia_valid & (ATTR_ATIME|ATTR_CTIME|ATTR_MTIME))
  846. xfs_setattr_time(ip, iattr);
  847. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  848. XFS_STATS_INC(mp, xs_ig_attrchg);
  849. if (mp->m_flags & XFS_MOUNT_WSYNC)
  850. xfs_trans_set_sync(tp);
  851. error = xfs_trans_commit(tp);
  852. out_unlock:
  853. if (lock_flags)
  854. xfs_iunlock(ip, lock_flags);
  855. return error;
  856. out_trans_cancel:
  857. xfs_trans_cancel(tp);
  858. goto out_unlock;
  859. }
  860. int
  861. xfs_vn_setattr_size(
  862. struct dentry *dentry,
  863. struct iattr *iattr)
  864. {
  865. struct xfs_inode *ip = XFS_I(d_inode(dentry));
  866. int error;
  867. trace_xfs_setattr(ip);
  868. error = xfs_vn_change_ok(dentry, iattr);
  869. if (error)
  870. return error;
  871. return xfs_setattr_size(ip, iattr);
  872. }
  873. STATIC int
  874. xfs_vn_setattr(
  875. struct dentry *dentry,
  876. struct iattr *iattr)
  877. {
  878. int error;
  879. if (iattr->ia_valid & ATTR_SIZE) {
  880. struct xfs_inode *ip = XFS_I(d_inode(dentry));
  881. uint iolock = XFS_IOLOCK_EXCL;
  882. xfs_ilock(ip, iolock);
  883. error = xfs_break_layouts(d_inode(dentry), &iolock, true);
  884. if (!error) {
  885. xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
  886. iolock |= XFS_MMAPLOCK_EXCL;
  887. error = xfs_vn_setattr_size(dentry, iattr);
  888. }
  889. xfs_iunlock(ip, iolock);
  890. } else {
  891. error = xfs_vn_setattr_nonsize(dentry, iattr);
  892. }
  893. return error;
  894. }
  895. STATIC int
  896. xfs_vn_update_time(
  897. struct inode *inode,
  898. struct timespec *now,
  899. int flags)
  900. {
  901. struct xfs_inode *ip = XFS_I(inode);
  902. struct xfs_mount *mp = ip->i_mount;
  903. struct xfs_trans *tp;
  904. int error;
  905. trace_xfs_update_time(ip);
  906. error = xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp);
  907. if (error)
  908. return error;
  909. xfs_ilock(ip, XFS_ILOCK_EXCL);
  910. if (flags & S_CTIME)
  911. inode->i_ctime = *now;
  912. if (flags & S_MTIME)
  913. inode->i_mtime = *now;
  914. if (flags & S_ATIME)
  915. inode->i_atime = *now;
  916. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  917. xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
  918. return xfs_trans_commit(tp);
  919. }
  920. STATIC int
  921. xfs_vn_fiemap(
  922. struct inode *inode,
  923. struct fiemap_extent_info *fieinfo,
  924. u64 start,
  925. u64 length)
  926. {
  927. int error;
  928. xfs_ilock(XFS_I(inode), XFS_IOLOCK_SHARED);
  929. if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) {
  930. fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR;
  931. error = iomap_fiemap(inode, fieinfo, start, length,
  932. &xfs_xattr_iomap_ops);
  933. } else {
  934. error = iomap_fiemap(inode, fieinfo, start, length,
  935. &xfs_iomap_ops);
  936. }
  937. xfs_iunlock(XFS_I(inode), XFS_IOLOCK_SHARED);
  938. return error;
  939. }
  940. STATIC int
  941. xfs_vn_tmpfile(
  942. struct inode *dir,
  943. struct dentry *dentry,
  944. umode_t mode)
  945. {
  946. return xfs_generic_create(dir, dentry, mode, 0, true);
  947. }
  948. static const struct inode_operations xfs_inode_operations = {
  949. .get_acl = xfs_get_acl,
  950. .set_acl = xfs_set_acl,
  951. .getattr = xfs_vn_getattr,
  952. .setattr = xfs_vn_setattr,
  953. .listxattr = xfs_vn_listxattr,
  954. .fiemap = xfs_vn_fiemap,
  955. .update_time = xfs_vn_update_time,
  956. };
  957. static const struct inode_operations xfs_dir_inode_operations = {
  958. .create = xfs_vn_create,
  959. .lookup = xfs_vn_lookup,
  960. .link = xfs_vn_link,
  961. .unlink = xfs_vn_unlink,
  962. .symlink = xfs_vn_symlink,
  963. .mkdir = xfs_vn_mkdir,
  964. /*
  965. * Yes, XFS uses the same method for rmdir and unlink.
  966. *
  967. * There are some subtile differences deeper in the code,
  968. * but we use S_ISDIR to check for those.
  969. */
  970. .rmdir = xfs_vn_unlink,
  971. .mknod = xfs_vn_mknod,
  972. .rename = xfs_vn_rename,
  973. .get_acl = xfs_get_acl,
  974. .set_acl = xfs_set_acl,
  975. .getattr = xfs_vn_getattr,
  976. .setattr = xfs_vn_setattr,
  977. .listxattr = xfs_vn_listxattr,
  978. .update_time = xfs_vn_update_time,
  979. .tmpfile = xfs_vn_tmpfile,
  980. };
  981. static const struct inode_operations xfs_dir_ci_inode_operations = {
  982. .create = xfs_vn_create,
  983. .lookup = xfs_vn_ci_lookup,
  984. .link = xfs_vn_link,
  985. .unlink = xfs_vn_unlink,
  986. .symlink = xfs_vn_symlink,
  987. .mkdir = xfs_vn_mkdir,
  988. /*
  989. * Yes, XFS uses the same method for rmdir and unlink.
  990. *
  991. * There are some subtile differences deeper in the code,
  992. * but we use S_ISDIR to check for those.
  993. */
  994. .rmdir = xfs_vn_unlink,
  995. .mknod = xfs_vn_mknod,
  996. .rename = xfs_vn_rename,
  997. .get_acl = xfs_get_acl,
  998. .set_acl = xfs_set_acl,
  999. .getattr = xfs_vn_getattr,
  1000. .setattr = xfs_vn_setattr,
  1001. .listxattr = xfs_vn_listxattr,
  1002. .update_time = xfs_vn_update_time,
  1003. .tmpfile = xfs_vn_tmpfile,
  1004. };
  1005. static const struct inode_operations xfs_symlink_inode_operations = {
  1006. .readlink = generic_readlink,
  1007. .get_link = xfs_vn_get_link,
  1008. .getattr = xfs_vn_getattr,
  1009. .setattr = xfs_vn_setattr,
  1010. .listxattr = xfs_vn_listxattr,
  1011. .update_time = xfs_vn_update_time,
  1012. };
  1013. static const struct inode_operations xfs_inline_symlink_inode_operations = {
  1014. .readlink = generic_readlink,
  1015. .get_link = xfs_vn_get_link_inline,
  1016. .getattr = xfs_vn_getattr,
  1017. .setattr = xfs_vn_setattr,
  1018. .listxattr = xfs_vn_listxattr,
  1019. .update_time = xfs_vn_update_time,
  1020. };
  1021. STATIC void
  1022. xfs_diflags_to_iflags(
  1023. struct inode *inode,
  1024. struct xfs_inode *ip)
  1025. {
  1026. uint16_t flags = ip->i_d.di_flags;
  1027. inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC |
  1028. S_NOATIME | S_DAX);
  1029. if (flags & XFS_DIFLAG_IMMUTABLE)
  1030. inode->i_flags |= S_IMMUTABLE;
  1031. if (flags & XFS_DIFLAG_APPEND)
  1032. inode->i_flags |= S_APPEND;
  1033. if (flags & XFS_DIFLAG_SYNC)
  1034. inode->i_flags |= S_SYNC;
  1035. if (flags & XFS_DIFLAG_NOATIME)
  1036. inode->i_flags |= S_NOATIME;
  1037. if (S_ISREG(inode->i_mode) &&
  1038. ip->i_mount->m_sb.sb_blocksize == PAGE_SIZE &&
  1039. !xfs_is_reflink_inode(ip) &&
  1040. (ip->i_mount->m_flags & XFS_MOUNT_DAX ||
  1041. ip->i_d.di_flags2 & XFS_DIFLAG2_DAX))
  1042. inode->i_flags |= S_DAX;
  1043. }
  1044. /*
  1045. * Initialize the Linux inode.
  1046. *
  1047. * When reading existing inodes from disk this is called directly from xfs_iget,
  1048. * when creating a new inode it is called from xfs_ialloc after setting up the
  1049. * inode. These callers have different criteria for clearing XFS_INEW, so leave
  1050. * it up to the caller to deal with unlocking the inode appropriately.
  1051. */
  1052. void
  1053. xfs_setup_inode(
  1054. struct xfs_inode *ip)
  1055. {
  1056. struct inode *inode = &ip->i_vnode;
  1057. gfp_t gfp_mask;
  1058. inode->i_ino = ip->i_ino;
  1059. inode->i_state = I_NEW;
  1060. inode_sb_list_add(inode);
  1061. /* make the inode look hashed for the writeback code */
  1062. hlist_add_fake(&inode->i_hash);
  1063. inode->i_uid = xfs_uid_to_kuid(ip->i_d.di_uid);
  1064. inode->i_gid = xfs_gid_to_kgid(ip->i_d.di_gid);
  1065. switch (inode->i_mode & S_IFMT) {
  1066. case S_IFBLK:
  1067. case S_IFCHR:
  1068. inode->i_rdev =
  1069. MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
  1070. sysv_minor(ip->i_df.if_u2.if_rdev));
  1071. break;
  1072. default:
  1073. inode->i_rdev = 0;
  1074. break;
  1075. }
  1076. i_size_write(inode, ip->i_d.di_size);
  1077. xfs_diflags_to_iflags(inode, ip);
  1078. if (S_ISDIR(inode->i_mode)) {
  1079. lockdep_set_class(&ip->i_lock.mr_lock, &xfs_dir_ilock_class);
  1080. ip->d_ops = ip->i_mount->m_dir_inode_ops;
  1081. } else {
  1082. ip->d_ops = ip->i_mount->m_nondir_inode_ops;
  1083. lockdep_set_class(&ip->i_lock.mr_lock, &xfs_nondir_ilock_class);
  1084. }
  1085. /*
  1086. * Ensure all page cache allocations are done from GFP_NOFS context to
  1087. * prevent direct reclaim recursion back into the filesystem and blowing
  1088. * stacks or deadlocking.
  1089. */
  1090. gfp_mask = mapping_gfp_mask(inode->i_mapping);
  1091. mapping_set_gfp_mask(inode->i_mapping, (gfp_mask & ~(__GFP_FS)));
  1092. /*
  1093. * If there is no attribute fork no ACL can exist on this inode,
  1094. * and it can't have any file capabilities attached to it either.
  1095. */
  1096. if (!XFS_IFORK_Q(ip)) {
  1097. inode_has_no_xattr(inode);
  1098. cache_no_acl(inode);
  1099. }
  1100. }
  1101. void
  1102. xfs_setup_iops(
  1103. struct xfs_inode *ip)
  1104. {
  1105. struct inode *inode = &ip->i_vnode;
  1106. switch (inode->i_mode & S_IFMT) {
  1107. case S_IFREG:
  1108. inode->i_op = &xfs_inode_operations;
  1109. inode->i_fop = &xfs_file_operations;
  1110. inode->i_mapping->a_ops = &xfs_address_space_operations;
  1111. break;
  1112. case S_IFDIR:
  1113. if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
  1114. inode->i_op = &xfs_dir_ci_inode_operations;
  1115. else
  1116. inode->i_op = &xfs_dir_inode_operations;
  1117. inode->i_fop = &xfs_dir_file_operations;
  1118. break;
  1119. case S_IFLNK:
  1120. if (ip->i_df.if_flags & XFS_IFINLINE)
  1121. inode->i_op = &xfs_inline_symlink_inode_operations;
  1122. else
  1123. inode->i_op = &xfs_symlink_inode_operations;
  1124. break;
  1125. default:
  1126. inode->i_op = &xfs_inode_operations;
  1127. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  1128. break;
  1129. }
  1130. }