xfs_iops.c 30 KB

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