xfs_rename.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #include "xfs.h"
  33. #include "xfs_macros.h"
  34. #include "xfs_types.h"
  35. #include "xfs_inum.h"
  36. #include "xfs_log.h"
  37. #include "xfs_trans.h"
  38. #include "xfs_sb.h"
  39. #include "xfs_dir.h"
  40. #include "xfs_dir2.h"
  41. #include "xfs_dmapi.h"
  42. #include "xfs_mount.h"
  43. #include "xfs_bmap_btree.h"
  44. #include "xfs_attr_sf.h"
  45. #include "xfs_dir_sf.h"
  46. #include "xfs_dir2_sf.h"
  47. #include "xfs_dinode.h"
  48. #include "xfs_inode_item.h"
  49. #include "xfs_inode.h"
  50. #include "xfs_bmap.h"
  51. #include "xfs_error.h"
  52. #include "xfs_quota.h"
  53. #include "xfs_refcache.h"
  54. #include "xfs_utils.h"
  55. #include "xfs_trans_space.h"
  56. #include "xfs_da_btree.h"
  57. #include "xfs_dir_leaf.h"
  58. /*
  59. * Given an array of up to 4 inode pointers, unlock the pointed to inodes.
  60. * If there are fewer than 4 entries in the array, the empty entries will
  61. * be at the end and will have NULL pointers in them.
  62. */
  63. STATIC void
  64. xfs_rename_unlock4(
  65. xfs_inode_t **i_tab,
  66. uint lock_mode)
  67. {
  68. int i;
  69. xfs_iunlock(i_tab[0], lock_mode);
  70. for (i = 1; i < 4; i++) {
  71. if (i_tab[i] == NULL) {
  72. break;
  73. }
  74. /*
  75. * Watch out for duplicate entries in the table.
  76. */
  77. if (i_tab[i] != i_tab[i-1]) {
  78. xfs_iunlock(i_tab[i], lock_mode);
  79. }
  80. }
  81. }
  82. #ifdef DEBUG
  83. int xfs_rename_skip, xfs_rename_nskip;
  84. #endif
  85. /*
  86. * The following routine will acquire the locks required for a rename
  87. * operation. The code understands the semantics of renames and will
  88. * validate that name1 exists under dp1 & that name2 may or may not
  89. * exist under dp2.
  90. *
  91. * We are renaming dp1/name1 to dp2/name2.
  92. *
  93. * Return ENOENT if dp1 does not exist, other lookup errors, or 0 for success.
  94. */
  95. STATIC int
  96. xfs_lock_for_rename(
  97. xfs_inode_t *dp1, /* old (source) directory inode */
  98. xfs_inode_t *dp2, /* new (target) directory inode */
  99. vname_t *vname1,/* old entry name */
  100. vname_t *vname2,/* new entry name */
  101. xfs_inode_t **ipp1, /* inode of old entry */
  102. xfs_inode_t **ipp2, /* inode of new entry, if it
  103. already exists, NULL otherwise. */
  104. xfs_inode_t **i_tab,/* array of inode returned, sorted */
  105. int *num_inodes) /* number of inodes in array */
  106. {
  107. xfs_inode_t *ip1, *ip2, *temp;
  108. xfs_ino_t inum1, inum2;
  109. int error;
  110. int i, j;
  111. uint lock_mode;
  112. int diff_dirs = (dp1 != dp2);
  113. ip2 = NULL;
  114. /*
  115. * First, find out the current inums of the entries so that we
  116. * can determine the initial locking order. We'll have to
  117. * sanity check stuff after all the locks have been acquired
  118. * to see if we still have the right inodes, directories, etc.
  119. */
  120. lock_mode = xfs_ilock_map_shared(dp1);
  121. error = xfs_get_dir_entry(vname1, &ip1);
  122. if (error) {
  123. xfs_iunlock_map_shared(dp1, lock_mode);
  124. return error;
  125. }
  126. inum1 = ip1->i_ino;
  127. ASSERT(ip1);
  128. ITRACE(ip1);
  129. /*
  130. * Unlock dp1 and lock dp2 if they are different.
  131. */
  132. if (diff_dirs) {
  133. xfs_iunlock_map_shared(dp1, lock_mode);
  134. lock_mode = xfs_ilock_map_shared(dp2);
  135. }
  136. error = xfs_dir_lookup_int(XFS_ITOBHV(dp2), lock_mode,
  137. vname2, &inum2, &ip2);
  138. if (error == ENOENT) { /* target does not need to exist. */
  139. inum2 = 0;
  140. } else if (error) {
  141. /*
  142. * If dp2 and dp1 are the same, the next line unlocks dp1.
  143. * Got it?
  144. */
  145. xfs_iunlock_map_shared(dp2, lock_mode);
  146. IRELE (ip1);
  147. return error;
  148. } else {
  149. ITRACE(ip2);
  150. }
  151. /*
  152. * i_tab contains a list of pointers to inodes. We initialize
  153. * the table here & we'll sort it. We will then use it to
  154. * order the acquisition of the inode locks.
  155. *
  156. * Note that the table may contain duplicates. e.g., dp1 == dp2.
  157. */
  158. i_tab[0] = dp1;
  159. i_tab[1] = dp2;
  160. i_tab[2] = ip1;
  161. if (inum2 == 0) {
  162. *num_inodes = 3;
  163. i_tab[3] = NULL;
  164. } else {
  165. *num_inodes = 4;
  166. i_tab[3] = ip2;
  167. }
  168. /*
  169. * Sort the elements via bubble sort. (Remember, there are at
  170. * most 4 elements to sort, so this is adequate.)
  171. */
  172. for (i=0; i < *num_inodes; i++) {
  173. for (j=1; j < *num_inodes; j++) {
  174. if (i_tab[j]->i_ino < i_tab[j-1]->i_ino) {
  175. temp = i_tab[j];
  176. i_tab[j] = i_tab[j-1];
  177. i_tab[j-1] = temp;
  178. }
  179. }
  180. }
  181. /*
  182. * We have dp2 locked. If it isn't first, unlock it.
  183. * If it is first, tell xfs_lock_inodes so it can skip it
  184. * when locking. if dp1 == dp2, xfs_lock_inodes will skip both
  185. * since they are equal. xfs_lock_inodes needs all these inodes
  186. * so that it can unlock and retry if there might be a dead-lock
  187. * potential with the log.
  188. */
  189. if (i_tab[0] == dp2 && lock_mode == XFS_ILOCK_SHARED) {
  190. #ifdef DEBUG
  191. xfs_rename_skip++;
  192. #endif
  193. xfs_lock_inodes(i_tab, *num_inodes, 1, XFS_ILOCK_SHARED);
  194. } else {
  195. #ifdef DEBUG
  196. xfs_rename_nskip++;
  197. #endif
  198. xfs_iunlock_map_shared(dp2, lock_mode);
  199. xfs_lock_inodes(i_tab, *num_inodes, 0, XFS_ILOCK_SHARED);
  200. }
  201. /*
  202. * Set the return value. Null out any unused entries in i_tab.
  203. */
  204. *ipp1 = *ipp2 = NULL;
  205. for (i=0; i < *num_inodes; i++) {
  206. if (i_tab[i]->i_ino == inum1) {
  207. *ipp1 = i_tab[i];
  208. }
  209. if (i_tab[i]->i_ino == inum2) {
  210. *ipp2 = i_tab[i];
  211. }
  212. }
  213. for (;i < 4; i++) {
  214. i_tab[i] = NULL;
  215. }
  216. return 0;
  217. }
  218. int rename_which_error_return = 0;
  219. /*
  220. * xfs_rename
  221. */
  222. int
  223. xfs_rename(
  224. bhv_desc_t *src_dir_bdp,
  225. vname_t *src_vname,
  226. vnode_t *target_dir_vp,
  227. vname_t *target_vname,
  228. cred_t *credp)
  229. {
  230. xfs_trans_t *tp;
  231. xfs_inode_t *src_dp, *target_dp, *src_ip, *target_ip;
  232. xfs_mount_t *mp;
  233. int new_parent; /* moving to a new dir */
  234. int src_is_directory; /* src_name is a directory */
  235. int error;
  236. xfs_bmap_free_t free_list;
  237. xfs_fsblock_t first_block;
  238. int cancel_flags;
  239. int committed;
  240. xfs_inode_t *inodes[4];
  241. int target_ip_dropped = 0; /* dropped target_ip link? */
  242. vnode_t *src_dir_vp;
  243. bhv_desc_t *target_dir_bdp;
  244. int spaceres;
  245. int target_link_zero = 0;
  246. int num_inodes;
  247. char *src_name = VNAME(src_vname);
  248. char *target_name = VNAME(target_vname);
  249. int src_namelen = VNAMELEN(src_vname);
  250. int target_namelen = VNAMELEN(target_vname);
  251. src_dir_vp = BHV_TO_VNODE(src_dir_bdp);
  252. vn_trace_entry(src_dir_vp, "xfs_rename", (inst_t *)__return_address);
  253. vn_trace_entry(target_dir_vp, "xfs_rename", (inst_t *)__return_address);
  254. /*
  255. * Find the XFS behavior descriptor for the target directory
  256. * vnode since it was not handed to us.
  257. */
  258. target_dir_bdp = vn_bhv_lookup_unlocked(VN_BHV_HEAD(target_dir_vp),
  259. &xfs_vnodeops);
  260. if (target_dir_bdp == NULL) {
  261. return XFS_ERROR(EXDEV);
  262. }
  263. src_dp = XFS_BHVTOI(src_dir_bdp);
  264. target_dp = XFS_BHVTOI(target_dir_bdp);
  265. mp = src_dp->i_mount;
  266. if (DM_EVENT_ENABLED(src_dir_vp->v_vfsp, src_dp, DM_EVENT_RENAME) ||
  267. DM_EVENT_ENABLED(target_dir_vp->v_vfsp,
  268. target_dp, DM_EVENT_RENAME)) {
  269. error = XFS_SEND_NAMESP(mp, DM_EVENT_RENAME,
  270. src_dir_vp, DM_RIGHT_NULL,
  271. target_dir_vp, DM_RIGHT_NULL,
  272. src_name, target_name,
  273. 0, 0, 0);
  274. if (error) {
  275. return error;
  276. }
  277. }
  278. /* Return through std_return after this point. */
  279. /*
  280. * Lock all the participating inodes. Depending upon whether
  281. * the target_name exists in the target directory, and
  282. * whether the target directory is the same as the source
  283. * directory, we can lock from 2 to 4 inodes.
  284. * xfs_lock_for_rename() will return ENOENT if src_name
  285. * does not exist in the source directory.
  286. */
  287. tp = NULL;
  288. error = xfs_lock_for_rename(src_dp, target_dp, src_vname,
  289. target_vname, &src_ip, &target_ip, inodes,
  290. &num_inodes);
  291. if (error) {
  292. rename_which_error_return = __LINE__;
  293. /*
  294. * We have nothing locked, no inode references, and
  295. * no transaction, so just get out.
  296. */
  297. goto std_return;
  298. }
  299. ASSERT(src_ip != NULL);
  300. if ((src_ip->i_d.di_mode & S_IFMT) == S_IFDIR) {
  301. /*
  302. * Check for link count overflow on target_dp
  303. */
  304. if (target_ip == NULL && (src_dp != target_dp) &&
  305. target_dp->i_d.di_nlink >= XFS_MAXLINK) {
  306. rename_which_error_return = __LINE__;
  307. error = XFS_ERROR(EMLINK);
  308. xfs_rename_unlock4(inodes, XFS_ILOCK_SHARED);
  309. goto rele_return;
  310. }
  311. }
  312. new_parent = (src_dp != target_dp);
  313. src_is_directory = ((src_ip->i_d.di_mode & S_IFMT) == S_IFDIR);
  314. /*
  315. * Drop the locks on our inodes so that we can start the transaction.
  316. */
  317. xfs_rename_unlock4(inodes, XFS_ILOCK_SHARED);
  318. XFS_BMAP_INIT(&free_list, &first_block);
  319. tp = xfs_trans_alloc(mp, XFS_TRANS_RENAME);
  320. cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
  321. spaceres = XFS_RENAME_SPACE_RES(mp, target_namelen);
  322. error = xfs_trans_reserve(tp, spaceres, XFS_RENAME_LOG_RES(mp), 0,
  323. XFS_TRANS_PERM_LOG_RES, XFS_RENAME_LOG_COUNT);
  324. if (error == ENOSPC) {
  325. spaceres = 0;
  326. error = xfs_trans_reserve(tp, 0, XFS_RENAME_LOG_RES(mp), 0,
  327. XFS_TRANS_PERM_LOG_RES, XFS_RENAME_LOG_COUNT);
  328. }
  329. if (error) {
  330. rename_which_error_return = __LINE__;
  331. xfs_trans_cancel(tp, 0);
  332. goto rele_return;
  333. }
  334. /*
  335. * Attach the dquots to the inodes
  336. */
  337. if ((error = XFS_QM_DQVOPRENAME(mp, inodes))) {
  338. xfs_trans_cancel(tp, cancel_flags);
  339. rename_which_error_return = __LINE__;
  340. goto rele_return;
  341. }
  342. /*
  343. * Reacquire the inode locks we dropped above.
  344. */
  345. xfs_lock_inodes(inodes, num_inodes, 0, XFS_ILOCK_EXCL);
  346. /*
  347. * Join all the inodes to the transaction. From this point on,
  348. * we can rely on either trans_commit or trans_cancel to unlock
  349. * them. Note that we need to add a vnode reference to the
  350. * directories since trans_commit & trans_cancel will decrement
  351. * them when they unlock the inodes. Also, we need to be careful
  352. * not to add an inode to the transaction more than once.
  353. */
  354. VN_HOLD(src_dir_vp);
  355. xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL);
  356. if (new_parent) {
  357. VN_HOLD(target_dir_vp);
  358. xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL);
  359. }
  360. if ((src_ip != src_dp) && (src_ip != target_dp)) {
  361. xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL);
  362. }
  363. if ((target_ip != NULL) &&
  364. (target_ip != src_ip) &&
  365. (target_ip != src_dp) &&
  366. (target_ip != target_dp)) {
  367. xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL);
  368. }
  369. /*
  370. * Set up the target.
  371. */
  372. if (target_ip == NULL) {
  373. /*
  374. * If there's no space reservation, check the entry will
  375. * fit before actually inserting it.
  376. */
  377. if (spaceres == 0 &&
  378. (error = XFS_DIR_CANENTER(mp, tp, target_dp, target_name,
  379. target_namelen))) {
  380. rename_which_error_return = __LINE__;
  381. goto error_return;
  382. }
  383. /*
  384. * If target does not exist and the rename crosses
  385. * directories, adjust the target directory link count
  386. * to account for the ".." reference from the new entry.
  387. */
  388. error = XFS_DIR_CREATENAME(mp, tp, target_dp, target_name,
  389. target_namelen, src_ip->i_ino,
  390. &first_block, &free_list, spaceres);
  391. if (error == ENOSPC) {
  392. rename_which_error_return = __LINE__;
  393. goto error_return;
  394. }
  395. if (error) {
  396. rename_which_error_return = __LINE__;
  397. goto abort_return;
  398. }
  399. xfs_ichgtime(target_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
  400. if (new_parent && src_is_directory) {
  401. error = xfs_bumplink(tp, target_dp);
  402. if (error) {
  403. rename_which_error_return = __LINE__;
  404. goto abort_return;
  405. }
  406. }
  407. } else { /* target_ip != NULL */
  408. /*
  409. * If target exists and it's a directory, check that both
  410. * target and source are directories and that target can be
  411. * destroyed, or that neither is a directory.
  412. */
  413. if ((target_ip->i_d.di_mode & S_IFMT) == S_IFDIR) {
  414. /*
  415. * Make sure target dir is empty.
  416. */
  417. if (!(XFS_DIR_ISEMPTY(target_ip->i_mount, target_ip)) ||
  418. (target_ip->i_d.di_nlink > 2)) {
  419. error = XFS_ERROR(EEXIST);
  420. rename_which_error_return = __LINE__;
  421. goto error_return;
  422. }
  423. }
  424. /*
  425. * Link the source inode under the target name.
  426. * If the source inode is a directory and we are moving
  427. * it across directories, its ".." entry will be
  428. * inconsistent until we replace that down below.
  429. *
  430. * In case there is already an entry with the same
  431. * name at the destination directory, remove it first.
  432. */
  433. error = XFS_DIR_REPLACE(mp, tp, target_dp, target_name,
  434. target_namelen, src_ip->i_ino, &first_block,
  435. &free_list, spaceres);
  436. if (error) {
  437. rename_which_error_return = __LINE__;
  438. goto abort_return;
  439. }
  440. xfs_ichgtime(target_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
  441. /*
  442. * Decrement the link count on the target since the target
  443. * dir no longer points to it.
  444. */
  445. error = xfs_droplink(tp, target_ip);
  446. if (error) {
  447. rename_which_error_return = __LINE__;
  448. goto abort_return;
  449. }
  450. target_ip_dropped = 1;
  451. if (src_is_directory) {
  452. /*
  453. * Drop the link from the old "." entry.
  454. */
  455. error = xfs_droplink(tp, target_ip);
  456. if (error) {
  457. rename_which_error_return = __LINE__;
  458. goto abort_return;
  459. }
  460. }
  461. /* Do this test while we still hold the locks */
  462. target_link_zero = (target_ip)->i_d.di_nlink==0;
  463. } /* target_ip != NULL */
  464. /*
  465. * Remove the source.
  466. */
  467. if (new_parent && src_is_directory) {
  468. /*
  469. * Rewrite the ".." entry to point to the new
  470. * directory.
  471. */
  472. error = XFS_DIR_REPLACE(mp, tp, src_ip, "..", 2,
  473. target_dp->i_ino, &first_block,
  474. &free_list, spaceres);
  475. ASSERT(error != EEXIST);
  476. if (error) {
  477. rename_which_error_return = __LINE__;
  478. goto abort_return;
  479. }
  480. xfs_ichgtime(src_ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
  481. } else {
  482. /*
  483. * We always want to hit the ctime on the source inode.
  484. * We do it in the if clause above for the 'new_parent &&
  485. * src_is_directory' case, and here we get all the other
  486. * cases. This isn't strictly required by the standards
  487. * since the source inode isn't really being changed,
  488. * but old unix file systems did it and some incremental
  489. * backup programs won't work without it.
  490. */
  491. xfs_ichgtime(src_ip, XFS_ICHGTIME_CHG);
  492. }
  493. /*
  494. * Adjust the link count on src_dp. This is necessary when
  495. * renaming a directory, either within one parent when
  496. * the target existed, or across two parent directories.
  497. */
  498. if (src_is_directory && (new_parent || target_ip != NULL)) {
  499. /*
  500. * Decrement link count on src_directory since the
  501. * entry that's moved no longer points to it.
  502. */
  503. error = xfs_droplink(tp, src_dp);
  504. if (error) {
  505. rename_which_error_return = __LINE__;
  506. goto abort_return;
  507. }
  508. }
  509. error = XFS_DIR_REMOVENAME(mp, tp, src_dp, src_name, src_namelen,
  510. src_ip->i_ino, &first_block, &free_list, spaceres);
  511. if (error) {
  512. rename_which_error_return = __LINE__;
  513. goto abort_return;
  514. }
  515. xfs_ichgtime(src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
  516. /*
  517. * Update the generation counts on all the directory inodes
  518. * that we're modifying.
  519. */
  520. src_dp->i_gen++;
  521. xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE);
  522. if (new_parent) {
  523. target_dp->i_gen++;
  524. xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE);
  525. }
  526. /*
  527. * If there was a target inode, take an extra reference on
  528. * it here so that it doesn't go to xfs_inactive() from
  529. * within the commit.
  530. */
  531. if (target_ip != NULL) {
  532. IHOLD(target_ip);
  533. }
  534. /*
  535. * If this is a synchronous mount, make sure that the
  536. * rename transaction goes to disk before returning to
  537. * the user.
  538. */
  539. if (mp->m_flags & (XFS_MOUNT_WSYNC|XFS_MOUNT_DIRSYNC)) {
  540. xfs_trans_set_sync(tp);
  541. }
  542. /*
  543. * Take refs. for vop_link_removed calls below. No need to worry
  544. * about directory refs. because the caller holds them.
  545. *
  546. * Do holds before the xfs_bmap_finish since it might rele them down
  547. * to zero.
  548. */
  549. if (target_ip_dropped)
  550. IHOLD(target_ip);
  551. IHOLD(src_ip);
  552. error = xfs_bmap_finish(&tp, &free_list, first_block, &committed);
  553. if (error) {
  554. xfs_bmap_cancel(&free_list);
  555. xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES |
  556. XFS_TRANS_ABORT));
  557. if (target_ip != NULL) {
  558. IRELE(target_ip);
  559. }
  560. if (target_ip_dropped) {
  561. IRELE(target_ip);
  562. }
  563. IRELE(src_ip);
  564. goto std_return;
  565. }
  566. /*
  567. * trans_commit will unlock src_ip, target_ip & decrement
  568. * the vnode references.
  569. */
  570. error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
  571. if (target_ip != NULL) {
  572. xfs_refcache_purge_ip(target_ip);
  573. IRELE(target_ip);
  574. }
  575. /*
  576. * Let interposed file systems know about removed links.
  577. */
  578. if (target_ip_dropped) {
  579. VOP_LINK_REMOVED(XFS_ITOV(target_ip), target_dir_vp,
  580. target_link_zero);
  581. IRELE(target_ip);
  582. }
  583. FSC_NOTIFY_NAME_CHANGED(XFS_ITOV(src_ip));
  584. IRELE(src_ip);
  585. /* Fall through to std_return with error = 0 or errno from
  586. * xfs_trans_commit */
  587. std_return:
  588. if (DM_EVENT_ENABLED(src_dir_vp->v_vfsp, src_dp, DM_EVENT_POSTRENAME) ||
  589. DM_EVENT_ENABLED(target_dir_vp->v_vfsp,
  590. target_dp, DM_EVENT_POSTRENAME)) {
  591. (void) XFS_SEND_NAMESP (mp, DM_EVENT_POSTRENAME,
  592. src_dir_vp, DM_RIGHT_NULL,
  593. target_dir_vp, DM_RIGHT_NULL,
  594. src_name, target_name,
  595. 0, error, 0);
  596. }
  597. return error;
  598. abort_return:
  599. cancel_flags |= XFS_TRANS_ABORT;
  600. /* FALLTHROUGH */
  601. error_return:
  602. xfs_bmap_cancel(&free_list);
  603. xfs_trans_cancel(tp, cancel_flags);
  604. goto std_return;
  605. rele_return:
  606. IRELE(src_ip);
  607. if (target_ip != NULL) {
  608. IRELE(target_ip);
  609. }
  610. goto std_return;
  611. }