xfs_iops.c 31 KB

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