xfs_trans.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643
  1. /*
  2. * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
  3. * Copyright (C) 2010 Red Hat, Inc.
  4. * All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it would be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "xfs.h"
  20. #include "xfs_fs.h"
  21. #include "xfs_types.h"
  22. #include "xfs_log.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_mount.h"
  27. #include "xfs_error.h"
  28. #include "xfs_da_btree.h"
  29. #include "xfs_bmap_btree.h"
  30. #include "xfs_alloc_btree.h"
  31. #include "xfs_ialloc_btree.h"
  32. #include "xfs_dinode.h"
  33. #include "xfs_inode.h"
  34. #include "xfs_btree.h"
  35. #include "xfs_ialloc.h"
  36. #include "xfs_alloc.h"
  37. #include "xfs_extent_busy.h"
  38. #include "xfs_bmap.h"
  39. #include "xfs_quota.h"
  40. #include "xfs_qm.h"
  41. #include "xfs_trans_priv.h"
  42. #include "xfs_trans_space.h"
  43. #include "xfs_inode_item.h"
  44. #include "xfs_log_priv.h"
  45. #include "xfs_buf_item.h"
  46. #include "xfs_trace.h"
  47. kmem_zone_t *xfs_trans_zone;
  48. kmem_zone_t *xfs_log_item_desc_zone;
  49. /*
  50. * A buffer has a format structure overhead in the log in addition
  51. * to the data, so we need to take this into account when reserving
  52. * space in a transaction for a buffer. Round the space required up
  53. * to a multiple of 128 bytes so that we don't change the historical
  54. * reservation that has been used for this overhead.
  55. */
  56. STATIC uint
  57. xfs_buf_log_overhead(void)
  58. {
  59. return round_up(sizeof(struct xlog_op_header) +
  60. sizeof(struct xfs_buf_log_format), 128);
  61. }
  62. /*
  63. * Calculate out transaction log reservation per item in bytes.
  64. *
  65. * The nbufs argument is used to indicate the number of items that
  66. * will be changed in a transaction. size is used to tell how many
  67. * bytes should be reserved per item.
  68. */
  69. STATIC uint
  70. xfs_calc_buf_res(
  71. uint nbufs,
  72. uint size)
  73. {
  74. return nbufs * (size + xfs_buf_log_overhead());
  75. }
  76. /*
  77. * Various log reservation values.
  78. *
  79. * These are based on the size of the file system block because that is what
  80. * most transactions manipulate. Each adds in an additional 128 bytes per
  81. * item logged to try to account for the overhead of the transaction mechanism.
  82. *
  83. * Note: Most of the reservations underestimate the number of allocation
  84. * groups into which they could free extents in the xfs_bmap_finish() call.
  85. * This is because the number in the worst case is quite high and quite
  86. * unusual. In order to fix this we need to change xfs_bmap_finish() to free
  87. * extents in only a single AG at a time. This will require changes to the
  88. * EFI code as well, however, so that the EFI for the extents not freed is
  89. * logged again in each transaction. See SGI PV #261917.
  90. *
  91. * Reservation functions here avoid a huge stack in xfs_trans_init due to
  92. * register overflow from temporaries in the calculations.
  93. */
  94. /*
  95. * In a write transaction we can allocate a maximum of 2
  96. * extents. This gives:
  97. * the inode getting the new extents: inode size
  98. * the inode's bmap btree: max depth * block size
  99. * the agfs of the ags from which the extents are allocated: 2 * sector
  100. * the superblock free block counter: sector size
  101. * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
  102. * And the bmap_finish transaction can free bmap blocks in a join:
  103. * the agfs of the ags containing the blocks: 2 * sector size
  104. * the agfls of the ags containing the blocks: 2 * sector size
  105. * the super block free block counter: sector size
  106. * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
  107. */
  108. STATIC uint
  109. xfs_calc_write_reservation(
  110. struct xfs_mount *mp)
  111. {
  112. return XFS_DQUOT_LOGRES(mp) +
  113. MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
  114. xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
  115. XFS_FSB_TO_B(mp, 1)) +
  116. xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
  117. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
  118. XFS_FSB_TO_B(mp, 1))),
  119. (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
  120. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
  121. XFS_FSB_TO_B(mp, 1))));
  122. }
  123. /*
  124. * In truncating a file we free up to two extents at once. We can modify:
  125. * the inode being truncated: inode size
  126. * the inode's bmap btree: (max depth + 1) * block size
  127. * And the bmap_finish transaction can free the blocks and bmap blocks:
  128. * the agf for each of the ags: 4 * sector size
  129. * the agfl for each of the ags: 4 * sector size
  130. * the super block to reflect the freed blocks: sector size
  131. * worst case split in allocation btrees per extent assuming 4 extents:
  132. * 4 exts * 2 trees * (2 * max depth - 1) * block size
  133. * the inode btree: max depth * blocksize
  134. * the allocation btrees: 2 trees * (max depth - 1) * block size
  135. */
  136. STATIC uint
  137. xfs_calc_itruncate_reservation(
  138. struct xfs_mount *mp)
  139. {
  140. return XFS_DQUOT_LOGRES(mp) +
  141. MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
  142. xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) + 1,
  143. XFS_FSB_TO_B(mp, 1))),
  144. (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
  145. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
  146. XFS_FSB_TO_B(mp, 1)) +
  147. xfs_calc_buf_res(5, 0) +
  148. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
  149. XFS_FSB_TO_B(mp, 1)) +
  150. xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) +
  151. mp->m_in_maxlevels, 0)));
  152. }
  153. /*
  154. * In renaming a files we can modify:
  155. * the four inodes involved: 4 * inode size
  156. * the two directory btrees: 2 * (max depth + v2) * dir block size
  157. * the two directory bmap btrees: 2 * max depth * block size
  158. * And the bmap_finish transaction can free dir and bmap blocks (two sets
  159. * of bmap blocks) giving:
  160. * the agf for the ags in which the blocks live: 3 * sector size
  161. * the agfl for the ags in which the blocks live: 3 * sector size
  162. * the superblock for the free block count: sector size
  163. * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size
  164. */
  165. STATIC uint
  166. xfs_calc_rename_reservation(
  167. struct xfs_mount *mp)
  168. {
  169. return XFS_DQUOT_LOGRES(mp) +
  170. MAX((xfs_calc_buf_res(4, mp->m_sb.sb_inodesize) +
  171. xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp),
  172. XFS_FSB_TO_B(mp, 1))),
  173. (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) +
  174. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 3),
  175. XFS_FSB_TO_B(mp, 1))));
  176. }
  177. /*
  178. * For creating a link to an inode:
  179. * the parent directory inode: inode size
  180. * the linked inode: inode size
  181. * the directory btree could split: (max depth + v2) * dir block size
  182. * the directory bmap btree could join or split: (max depth + v2) * blocksize
  183. * And the bmap_finish transaction can free some bmap blocks giving:
  184. * the agf for the ag in which the blocks live: sector size
  185. * the agfl for the ag in which the blocks live: sector size
  186. * the superblock for the free block count: sector size
  187. * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
  188. */
  189. STATIC uint
  190. xfs_calc_link_reservation(
  191. struct xfs_mount *mp)
  192. {
  193. return XFS_DQUOT_LOGRES(mp) +
  194. MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
  195. xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
  196. XFS_FSB_TO_B(mp, 1))),
  197. (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
  198. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
  199. XFS_FSB_TO_B(mp, 1))));
  200. }
  201. /*
  202. * For removing a directory entry we can modify:
  203. * the parent directory inode: inode size
  204. * the removed inode: inode size
  205. * the directory btree could join: (max depth + v2) * dir block size
  206. * the directory bmap btree could join or split: (max depth + v2) * blocksize
  207. * And the bmap_finish transaction can free the dir and bmap blocks giving:
  208. * the agf for the ag in which the blocks live: 2 * sector size
  209. * the agfl for the ag in which the blocks live: 2 * sector size
  210. * the superblock for the free block count: sector size
  211. * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
  212. */
  213. STATIC uint
  214. xfs_calc_remove_reservation(
  215. struct xfs_mount *mp)
  216. {
  217. return XFS_DQUOT_LOGRES(mp) +
  218. MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
  219. xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
  220. XFS_FSB_TO_B(mp, 1))),
  221. (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
  222. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
  223. XFS_FSB_TO_B(mp, 1))));
  224. }
  225. /*
  226. * For symlink we can modify:
  227. * the parent directory inode: inode size
  228. * the new inode: inode size
  229. * the inode btree entry: 1 block
  230. * the directory btree: (max depth + v2) * dir block size
  231. * the directory inode's bmap btree: (max depth + v2) * block size
  232. * the blocks for the symlink: 1 kB
  233. * Or in the first xact we allocate some inodes giving:
  234. * the agi and agf of the ag getting the new inodes: 2 * sectorsize
  235. * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
  236. * the inode btree: max depth * blocksize
  237. * the allocation btrees: 2 trees * (2 * max depth - 1) * block size
  238. */
  239. STATIC uint
  240. xfs_calc_symlink_reservation(
  241. struct xfs_mount *mp)
  242. {
  243. return XFS_DQUOT_LOGRES(mp) +
  244. MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
  245. xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
  246. xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
  247. XFS_FSB_TO_B(mp, 1)) +
  248. xfs_calc_buf_res(1, 1024)),
  249. (xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
  250. xfs_calc_buf_res(XFS_IALLOC_BLOCKS(mp),
  251. XFS_FSB_TO_B(mp, 1)) +
  252. xfs_calc_buf_res(mp->m_in_maxlevels,
  253. XFS_FSB_TO_B(mp, 1)) +
  254. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
  255. XFS_FSB_TO_B(mp, 1))));
  256. }
  257. /*
  258. * For create we can modify:
  259. * the parent directory inode: inode size
  260. * the new inode: inode size
  261. * the inode btree entry: block size
  262. * the superblock for the nlink flag: sector size
  263. * the directory btree: (max depth + v2) * dir block size
  264. * the directory inode's bmap btree: (max depth + v2) * block size
  265. * Or in the first xact we allocate some inodes giving:
  266. * the agi and agf of the ag getting the new inodes: 2 * sectorsize
  267. * the superblock for the nlink flag: sector size
  268. * the inode blocks allocated: XFS_IALLOC_BLOCKS * blocksize
  269. * the inode btree: max depth * blocksize
  270. * the allocation btrees: 2 trees * (max depth - 1) * block size
  271. */
  272. STATIC uint
  273. xfs_calc_create_reservation(
  274. struct xfs_mount *mp)
  275. {
  276. return XFS_DQUOT_LOGRES(mp) +
  277. MAX((xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
  278. xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
  279. (uint)XFS_FSB_TO_B(mp, 1) +
  280. xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
  281. XFS_FSB_TO_B(mp, 1))),
  282. (xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
  283. mp->m_sb.sb_sectsize +
  284. xfs_calc_buf_res(XFS_IALLOC_BLOCKS(mp),
  285. XFS_FSB_TO_B(mp, 1)) +
  286. xfs_calc_buf_res(mp->m_in_maxlevels,
  287. XFS_FSB_TO_B(mp, 1)) +
  288. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
  289. XFS_FSB_TO_B(mp, 1))));
  290. }
  291. /*
  292. * Making a new directory is the same as creating a new file.
  293. */
  294. STATIC uint
  295. xfs_calc_mkdir_reservation(
  296. struct xfs_mount *mp)
  297. {
  298. return xfs_calc_create_reservation(mp);
  299. }
  300. /*
  301. * In freeing an inode we can modify:
  302. * the inode being freed: inode size
  303. * the super block free inode counter: sector size
  304. * the agi hash list and counters: sector size
  305. * the inode btree entry: block size
  306. * the on disk inode before ours in the agi hash list: inode cluster size
  307. * the inode btree: max depth * blocksize
  308. * the allocation btrees: 2 trees * (max depth - 1) * block size
  309. */
  310. STATIC uint
  311. xfs_calc_ifree_reservation(
  312. struct xfs_mount *mp)
  313. {
  314. return XFS_DQUOT_LOGRES(mp) +
  315. xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
  316. xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
  317. xfs_calc_buf_res(1, XFS_FSB_TO_B(mp, 1)) +
  318. MAX((__uint16_t)XFS_FSB_TO_B(mp, 1),
  319. XFS_INODE_CLUSTER_SIZE(mp)) +
  320. xfs_calc_buf_res(1, 0) +
  321. xfs_calc_buf_res(2 + XFS_IALLOC_BLOCKS(mp) +
  322. mp->m_in_maxlevels, 0) +
  323. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
  324. XFS_FSB_TO_B(mp, 1));
  325. }
  326. /*
  327. * When only changing the inode we log the inode and possibly the superblock
  328. * We also add a bit of slop for the transaction stuff.
  329. */
  330. STATIC uint
  331. xfs_calc_ichange_reservation(
  332. struct xfs_mount *mp)
  333. {
  334. return XFS_DQUOT_LOGRES(mp) +
  335. mp->m_sb.sb_inodesize +
  336. mp->m_sb.sb_sectsize +
  337. 512;
  338. }
  339. /*
  340. * Growing the data section of the filesystem.
  341. * superblock
  342. * agi and agf
  343. * allocation btrees
  344. */
  345. STATIC uint
  346. xfs_calc_growdata_reservation(
  347. struct xfs_mount *mp)
  348. {
  349. return xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) +
  350. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
  351. XFS_FSB_TO_B(mp, 1));
  352. }
  353. /*
  354. * Growing the rt section of the filesystem.
  355. * In the first set of transactions (ALLOC) we allocate space to the
  356. * bitmap or summary files.
  357. * superblock: sector size
  358. * agf of the ag from which the extent is allocated: sector size
  359. * bmap btree for bitmap/summary inode: max depth * blocksize
  360. * bitmap/summary inode: inode size
  361. * allocation btrees for 1 block alloc: 2 * (2 * maxdepth - 1) * blocksize
  362. */
  363. STATIC uint
  364. xfs_calc_growrtalloc_reservation(
  365. struct xfs_mount *mp)
  366. {
  367. return xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
  368. xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK),
  369. XFS_FSB_TO_B(mp, 1)) +
  370. xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
  371. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
  372. XFS_FSB_TO_B(mp, 1));
  373. }
  374. /*
  375. * Growing the rt section of the filesystem.
  376. * In the second set of transactions (ZERO) we zero the new metadata blocks.
  377. * one bitmap/summary block: blocksize
  378. */
  379. STATIC uint
  380. xfs_calc_growrtzero_reservation(
  381. struct xfs_mount *mp)
  382. {
  383. return xfs_calc_buf_res(1, mp->m_sb.sb_blocksize);
  384. }
  385. /*
  386. * Growing the rt section of the filesystem.
  387. * In the third set of transactions (FREE) we update metadata without
  388. * allocating any new blocks.
  389. * superblock: sector size
  390. * bitmap inode: inode size
  391. * summary inode: inode size
  392. * one bitmap block: blocksize
  393. * summary blocks: new summary size
  394. */
  395. STATIC uint
  396. xfs_calc_growrtfree_reservation(
  397. struct xfs_mount *mp)
  398. {
  399. return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
  400. xfs_calc_buf_res(2, mp->m_sb.sb_inodesize) +
  401. xfs_calc_buf_res(1, mp->m_sb.sb_blocksize) +
  402. xfs_calc_buf_res(1, mp->m_rsumsize);
  403. }
  404. /*
  405. * Logging the inode modification timestamp on a synchronous write.
  406. * inode
  407. */
  408. STATIC uint
  409. xfs_calc_swrite_reservation(
  410. struct xfs_mount *mp)
  411. {
  412. return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize);
  413. }
  414. /*
  415. * Logging the inode mode bits when writing a setuid/setgid file
  416. * inode
  417. */
  418. STATIC uint
  419. xfs_calc_writeid_reservation(xfs_mount_t *mp)
  420. {
  421. return xfs_calc_buf_res(1, mp->m_sb.sb_inodesize);
  422. }
  423. /*
  424. * Converting the inode from non-attributed to attributed.
  425. * the inode being converted: inode size
  426. * agf block and superblock (for block allocation)
  427. * the new block (directory sized)
  428. * bmap blocks for the new directory block
  429. * allocation btrees
  430. */
  431. STATIC uint
  432. xfs_calc_addafork_reservation(
  433. struct xfs_mount *mp)
  434. {
  435. return XFS_DQUOT_LOGRES(mp) +
  436. xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
  437. xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) +
  438. xfs_calc_buf_res(1, mp->m_dirblksize) +
  439. xfs_calc_buf_res(XFS_DAENTER_BMAP1B(mp, XFS_DATA_FORK) + 1,
  440. XFS_FSB_TO_B(mp, 1)) +
  441. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 1),
  442. XFS_FSB_TO_B(mp, 1));
  443. }
  444. /*
  445. * Removing the attribute fork of a file
  446. * the inode being truncated: inode size
  447. * the inode's bmap btree: max depth * block size
  448. * And the bmap_finish transaction can free the blocks and bmap blocks:
  449. * the agf for each of the ags: 4 * sector size
  450. * the agfl for each of the ags: 4 * sector size
  451. * the super block to reflect the freed blocks: sector size
  452. * worst case split in allocation btrees per extent assuming 4 extents:
  453. * 4 exts * 2 trees * (2 * max depth - 1) * block size
  454. */
  455. STATIC uint
  456. xfs_calc_attrinval_reservation(
  457. struct xfs_mount *mp)
  458. {
  459. return MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
  460. xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK),
  461. XFS_FSB_TO_B(mp, 1))),
  462. (xfs_calc_buf_res(9, mp->m_sb.sb_sectsize) +
  463. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 4),
  464. XFS_FSB_TO_B(mp, 1))));
  465. }
  466. /*
  467. * Setting an attribute.
  468. * the inode getting the attribute
  469. * the superblock for allocations
  470. * the agfs extents are allocated from
  471. * the attribute btree * max depth
  472. * the inode allocation btree
  473. * Since attribute transaction space is dependent on the size of the attribute,
  474. * the calculation is done partially at mount time and partially at runtime.
  475. */
  476. STATIC uint
  477. xfs_calc_attrset_reservation(
  478. struct xfs_mount *mp)
  479. {
  480. return XFS_DQUOT_LOGRES(mp) +
  481. xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
  482. xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) +
  483. xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1));
  484. }
  485. /*
  486. * Removing an attribute.
  487. * the inode: inode size
  488. * the attribute btree could join: max depth * block size
  489. * the inode bmap btree could join or split: max depth * block size
  490. * And the bmap_finish transaction can free the attr blocks freed giving:
  491. * the agf for the ag in which the blocks live: 2 * sector size
  492. * the agfl for the ag in which the blocks live: 2 * sector size
  493. * the superblock for the free block count: sector size
  494. * the allocation btrees: 2 exts * 2 trees * (2 * max depth - 1) * block size
  495. */
  496. STATIC uint
  497. xfs_calc_attrrm_reservation(
  498. struct xfs_mount *mp)
  499. {
  500. return XFS_DQUOT_LOGRES(mp) +
  501. MAX((xfs_calc_buf_res(1, mp->m_sb.sb_inodesize) +
  502. xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH,
  503. XFS_FSB_TO_B(mp, 1)) +
  504. (uint)XFS_FSB_TO_B(mp,
  505. XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) +
  506. xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)),
  507. (xfs_calc_buf_res(5, mp->m_sb.sb_sectsize) +
  508. xfs_calc_buf_res(XFS_ALLOCFREE_LOG_COUNT(mp, 2),
  509. XFS_FSB_TO_B(mp, 1))));
  510. }
  511. /*
  512. * Clearing a bad agino number in an agi hash bucket.
  513. */
  514. STATIC uint
  515. xfs_calc_clear_agi_bucket_reservation(
  516. struct xfs_mount *mp)
  517. {
  518. return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
  519. }
  520. /*
  521. * Clearing the quotaflags in the superblock.
  522. * the super block for changing quota flags: sector size
  523. */
  524. STATIC uint
  525. xfs_calc_qm_sbchange_reservation(
  526. struct xfs_mount *mp)
  527. {
  528. return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
  529. }
  530. /*
  531. * Adjusting quota limits.
  532. * the xfs_disk_dquot_t: sizeof(struct xfs_disk_dquot)
  533. */
  534. STATIC uint
  535. xfs_calc_qm_setqlim_reservation(
  536. struct xfs_mount *mp)
  537. {
  538. return xfs_calc_buf_res(1, sizeof(struct xfs_disk_dquot));
  539. }
  540. /*
  541. * Allocating quota on disk if needed.
  542. * the write transaction log space: XFS_WRITE_LOG_RES(mp)
  543. * the unit of quota allocation: one system block size
  544. */
  545. STATIC uint
  546. xfs_calc_qm_dqalloc_reservation(
  547. struct xfs_mount *mp)
  548. {
  549. return XFS_WRITE_LOG_RES(mp) +
  550. xfs_calc_buf_res(1,
  551. XFS_FSB_TO_B(mp, XFS_DQUOT_CLUSTER_SIZE_FSB) - 1);
  552. }
  553. /*
  554. * Turning off quotas.
  555. * the xfs_qoff_logitem_t: sizeof(struct xfs_qoff_logitem) * 2
  556. * the superblock for the quota flags: sector size
  557. */
  558. STATIC uint
  559. xfs_calc_qm_quotaoff_reservation(
  560. struct xfs_mount *mp)
  561. {
  562. return sizeof(struct xfs_qoff_logitem) * 2 +
  563. xfs_calc_buf_res(1, mp->m_sb.sb_sectsize);
  564. }
  565. /*
  566. * Initialize the precomputed transaction reservation values
  567. * in the mount structure.
  568. */
  569. void
  570. xfs_trans_init(
  571. struct xfs_mount *mp)
  572. {
  573. struct xfs_trans_reservations *resp = &mp->m_reservations;
  574. resp->tr_write = xfs_calc_write_reservation(mp);
  575. resp->tr_itruncate = xfs_calc_itruncate_reservation(mp);
  576. resp->tr_rename = xfs_calc_rename_reservation(mp);
  577. resp->tr_link = xfs_calc_link_reservation(mp);
  578. resp->tr_remove = xfs_calc_remove_reservation(mp);
  579. resp->tr_symlink = xfs_calc_symlink_reservation(mp);
  580. resp->tr_create = xfs_calc_create_reservation(mp);
  581. resp->tr_mkdir = xfs_calc_mkdir_reservation(mp);
  582. resp->tr_ifree = xfs_calc_ifree_reservation(mp);
  583. resp->tr_ichange = xfs_calc_ichange_reservation(mp);
  584. resp->tr_growdata = xfs_calc_growdata_reservation(mp);
  585. resp->tr_swrite = xfs_calc_swrite_reservation(mp);
  586. resp->tr_writeid = xfs_calc_writeid_reservation(mp);
  587. resp->tr_addafork = xfs_calc_addafork_reservation(mp);
  588. resp->tr_attrinval = xfs_calc_attrinval_reservation(mp);
  589. resp->tr_attrset = xfs_calc_attrset_reservation(mp);
  590. resp->tr_attrrm = xfs_calc_attrrm_reservation(mp);
  591. resp->tr_clearagi = xfs_calc_clear_agi_bucket_reservation(mp);
  592. resp->tr_growrtalloc = xfs_calc_growrtalloc_reservation(mp);
  593. resp->tr_growrtzero = xfs_calc_growrtzero_reservation(mp);
  594. resp->tr_growrtfree = xfs_calc_growrtfree_reservation(mp);
  595. resp->tr_qm_sbchange = xfs_calc_qm_sbchange_reservation(mp);
  596. resp->tr_qm_setqlim = xfs_calc_qm_setqlim_reservation(mp);
  597. resp->tr_qm_dqalloc = xfs_calc_qm_dqalloc_reservation(mp);
  598. resp->tr_qm_quotaoff = xfs_calc_qm_quotaoff_reservation(mp);
  599. }
  600. /*
  601. * This routine is called to allocate a transaction structure.
  602. * The type parameter indicates the type of the transaction. These
  603. * are enumerated in xfs_trans.h.
  604. *
  605. * Dynamically allocate the transaction structure from the transaction
  606. * zone, initialize it, and return it to the caller.
  607. */
  608. xfs_trans_t *
  609. xfs_trans_alloc(
  610. xfs_mount_t *mp,
  611. uint type)
  612. {
  613. xfs_trans_t *tp;
  614. sb_start_intwrite(mp->m_super);
  615. tp = _xfs_trans_alloc(mp, type, KM_SLEEP);
  616. tp->t_flags |= XFS_TRANS_FREEZE_PROT;
  617. return tp;
  618. }
  619. xfs_trans_t *
  620. _xfs_trans_alloc(
  621. xfs_mount_t *mp,
  622. uint type,
  623. xfs_km_flags_t memflags)
  624. {
  625. xfs_trans_t *tp;
  626. WARN_ON(mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE);
  627. atomic_inc(&mp->m_active_trans);
  628. tp = kmem_zone_zalloc(xfs_trans_zone, memflags);
  629. tp->t_magic = XFS_TRANS_MAGIC;
  630. tp->t_type = type;
  631. tp->t_mountp = mp;
  632. INIT_LIST_HEAD(&tp->t_items);
  633. INIT_LIST_HEAD(&tp->t_busy);
  634. return tp;
  635. }
  636. /*
  637. * Free the transaction structure. If there is more clean up
  638. * to do when the structure is freed, add it here.
  639. */
  640. STATIC void
  641. xfs_trans_free(
  642. struct xfs_trans *tp)
  643. {
  644. xfs_extent_busy_sort(&tp->t_busy);
  645. xfs_extent_busy_clear(tp->t_mountp, &tp->t_busy, false);
  646. atomic_dec(&tp->t_mountp->m_active_trans);
  647. if (tp->t_flags & XFS_TRANS_FREEZE_PROT)
  648. sb_end_intwrite(tp->t_mountp->m_super);
  649. xfs_trans_free_dqinfo(tp);
  650. kmem_zone_free(xfs_trans_zone, tp);
  651. }
  652. /*
  653. * This is called to create a new transaction which will share the
  654. * permanent log reservation of the given transaction. The remaining
  655. * unused block and rt extent reservations are also inherited. This
  656. * implies that the original transaction is no longer allowed to allocate
  657. * blocks. Locks and log items, however, are no inherited. They must
  658. * be added to the new transaction explicitly.
  659. */
  660. xfs_trans_t *
  661. xfs_trans_dup(
  662. xfs_trans_t *tp)
  663. {
  664. xfs_trans_t *ntp;
  665. ntp = kmem_zone_zalloc(xfs_trans_zone, KM_SLEEP);
  666. /*
  667. * Initialize the new transaction structure.
  668. */
  669. ntp->t_magic = XFS_TRANS_MAGIC;
  670. ntp->t_type = tp->t_type;
  671. ntp->t_mountp = tp->t_mountp;
  672. INIT_LIST_HEAD(&ntp->t_items);
  673. INIT_LIST_HEAD(&ntp->t_busy);
  674. ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
  675. ASSERT(tp->t_ticket != NULL);
  676. ntp->t_flags = XFS_TRANS_PERM_LOG_RES |
  677. (tp->t_flags & XFS_TRANS_RESERVE) |
  678. (tp->t_flags & XFS_TRANS_FREEZE_PROT);
  679. /* We gave our writer reference to the new transaction */
  680. tp->t_flags &= ~XFS_TRANS_FREEZE_PROT;
  681. ntp->t_ticket = xfs_log_ticket_get(tp->t_ticket);
  682. ntp->t_blk_res = tp->t_blk_res - tp->t_blk_res_used;
  683. tp->t_blk_res = tp->t_blk_res_used;
  684. ntp->t_rtx_res = tp->t_rtx_res - tp->t_rtx_res_used;
  685. tp->t_rtx_res = tp->t_rtx_res_used;
  686. ntp->t_pflags = tp->t_pflags;
  687. xfs_trans_dup_dqinfo(tp, ntp);
  688. atomic_inc(&tp->t_mountp->m_active_trans);
  689. return ntp;
  690. }
  691. /*
  692. * This is called to reserve free disk blocks and log space for the
  693. * given transaction. This must be done before allocating any resources
  694. * within the transaction.
  695. *
  696. * This will return ENOSPC if there are not enough blocks available.
  697. * It will sleep waiting for available log space.
  698. * The only valid value for the flags parameter is XFS_RES_LOG_PERM, which
  699. * is used by long running transactions. If any one of the reservations
  700. * fails then they will all be backed out.
  701. *
  702. * This does not do quota reservations. That typically is done by the
  703. * caller afterwards.
  704. */
  705. int
  706. xfs_trans_reserve(
  707. xfs_trans_t *tp,
  708. uint blocks,
  709. uint logspace,
  710. uint rtextents,
  711. uint flags,
  712. uint logcount)
  713. {
  714. int error = 0;
  715. int rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
  716. /* Mark this thread as being in a transaction */
  717. current_set_flags_nested(&tp->t_pflags, PF_FSTRANS);
  718. /*
  719. * Attempt to reserve the needed disk blocks by decrementing
  720. * the number needed from the number available. This will
  721. * fail if the count would go below zero.
  722. */
  723. if (blocks > 0) {
  724. error = xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS,
  725. -((int64_t)blocks), rsvd);
  726. if (error != 0) {
  727. current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
  728. return (XFS_ERROR(ENOSPC));
  729. }
  730. tp->t_blk_res += blocks;
  731. }
  732. /*
  733. * Reserve the log space needed for this transaction.
  734. */
  735. if (logspace > 0) {
  736. bool permanent = false;
  737. ASSERT(tp->t_log_res == 0 || tp->t_log_res == logspace);
  738. ASSERT(tp->t_log_count == 0 || tp->t_log_count == logcount);
  739. if (flags & XFS_TRANS_PERM_LOG_RES) {
  740. tp->t_flags |= XFS_TRANS_PERM_LOG_RES;
  741. permanent = true;
  742. } else {
  743. ASSERT(tp->t_ticket == NULL);
  744. ASSERT(!(tp->t_flags & XFS_TRANS_PERM_LOG_RES));
  745. }
  746. if (tp->t_ticket != NULL) {
  747. ASSERT(flags & XFS_TRANS_PERM_LOG_RES);
  748. error = xfs_log_regrant(tp->t_mountp, tp->t_ticket);
  749. } else {
  750. error = xfs_log_reserve(tp->t_mountp, logspace,
  751. logcount, &tp->t_ticket,
  752. XFS_TRANSACTION, permanent,
  753. tp->t_type);
  754. }
  755. if (error)
  756. goto undo_blocks;
  757. tp->t_log_res = logspace;
  758. tp->t_log_count = logcount;
  759. }
  760. /*
  761. * Attempt to reserve the needed realtime extents by decrementing
  762. * the number needed from the number available. This will
  763. * fail if the count would go below zero.
  764. */
  765. if (rtextents > 0) {
  766. error = xfs_mod_incore_sb(tp->t_mountp, XFS_SBS_FREXTENTS,
  767. -((int64_t)rtextents), rsvd);
  768. if (error) {
  769. error = XFS_ERROR(ENOSPC);
  770. goto undo_log;
  771. }
  772. tp->t_rtx_res += rtextents;
  773. }
  774. return 0;
  775. /*
  776. * Error cases jump to one of these labels to undo any
  777. * reservations which have already been performed.
  778. */
  779. undo_log:
  780. if (logspace > 0) {
  781. int log_flags;
  782. if (flags & XFS_TRANS_PERM_LOG_RES) {
  783. log_flags = XFS_LOG_REL_PERM_RESERV;
  784. } else {
  785. log_flags = 0;
  786. }
  787. xfs_log_done(tp->t_mountp, tp->t_ticket, NULL, log_flags);
  788. tp->t_ticket = NULL;
  789. tp->t_log_res = 0;
  790. tp->t_flags &= ~XFS_TRANS_PERM_LOG_RES;
  791. }
  792. undo_blocks:
  793. if (blocks > 0) {
  794. xfs_icsb_modify_counters(tp->t_mountp, XFS_SBS_FDBLOCKS,
  795. (int64_t)blocks, rsvd);
  796. tp->t_blk_res = 0;
  797. }
  798. current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
  799. return error;
  800. }
  801. /*
  802. * Record the indicated change to the given field for application
  803. * to the file system's superblock when the transaction commits.
  804. * For now, just store the change in the transaction structure.
  805. *
  806. * Mark the transaction structure to indicate that the superblock
  807. * needs to be updated before committing.
  808. *
  809. * Because we may not be keeping track of allocated/free inodes and
  810. * used filesystem blocks in the superblock, we do not mark the
  811. * superblock dirty in this transaction if we modify these fields.
  812. * We still need to update the transaction deltas so that they get
  813. * applied to the incore superblock, but we don't want them to
  814. * cause the superblock to get locked and logged if these are the
  815. * only fields in the superblock that the transaction modifies.
  816. */
  817. void
  818. xfs_trans_mod_sb(
  819. xfs_trans_t *tp,
  820. uint field,
  821. int64_t delta)
  822. {
  823. uint32_t flags = (XFS_TRANS_DIRTY|XFS_TRANS_SB_DIRTY);
  824. xfs_mount_t *mp = tp->t_mountp;
  825. switch (field) {
  826. case XFS_TRANS_SB_ICOUNT:
  827. tp->t_icount_delta += delta;
  828. if (xfs_sb_version_haslazysbcount(&mp->m_sb))
  829. flags &= ~XFS_TRANS_SB_DIRTY;
  830. break;
  831. case XFS_TRANS_SB_IFREE:
  832. tp->t_ifree_delta += delta;
  833. if (xfs_sb_version_haslazysbcount(&mp->m_sb))
  834. flags &= ~XFS_TRANS_SB_DIRTY;
  835. break;
  836. case XFS_TRANS_SB_FDBLOCKS:
  837. /*
  838. * Track the number of blocks allocated in the
  839. * transaction. Make sure it does not exceed the
  840. * number reserved.
  841. */
  842. if (delta < 0) {
  843. tp->t_blk_res_used += (uint)-delta;
  844. ASSERT(tp->t_blk_res_used <= tp->t_blk_res);
  845. }
  846. tp->t_fdblocks_delta += delta;
  847. if (xfs_sb_version_haslazysbcount(&mp->m_sb))
  848. flags &= ~XFS_TRANS_SB_DIRTY;
  849. break;
  850. case XFS_TRANS_SB_RES_FDBLOCKS:
  851. /*
  852. * The allocation has already been applied to the
  853. * in-core superblock's counter. This should only
  854. * be applied to the on-disk superblock.
  855. */
  856. ASSERT(delta < 0);
  857. tp->t_res_fdblocks_delta += delta;
  858. if (xfs_sb_version_haslazysbcount(&mp->m_sb))
  859. flags &= ~XFS_TRANS_SB_DIRTY;
  860. break;
  861. case XFS_TRANS_SB_FREXTENTS:
  862. /*
  863. * Track the number of blocks allocated in the
  864. * transaction. Make sure it does not exceed the
  865. * number reserved.
  866. */
  867. if (delta < 0) {
  868. tp->t_rtx_res_used += (uint)-delta;
  869. ASSERT(tp->t_rtx_res_used <= tp->t_rtx_res);
  870. }
  871. tp->t_frextents_delta += delta;
  872. break;
  873. case XFS_TRANS_SB_RES_FREXTENTS:
  874. /*
  875. * The allocation has already been applied to the
  876. * in-core superblock's counter. This should only
  877. * be applied to the on-disk superblock.
  878. */
  879. ASSERT(delta < 0);
  880. tp->t_res_frextents_delta += delta;
  881. break;
  882. case XFS_TRANS_SB_DBLOCKS:
  883. ASSERT(delta > 0);
  884. tp->t_dblocks_delta += delta;
  885. break;
  886. case XFS_TRANS_SB_AGCOUNT:
  887. ASSERT(delta > 0);
  888. tp->t_agcount_delta += delta;
  889. break;
  890. case XFS_TRANS_SB_IMAXPCT:
  891. tp->t_imaxpct_delta += delta;
  892. break;
  893. case XFS_TRANS_SB_REXTSIZE:
  894. tp->t_rextsize_delta += delta;
  895. break;
  896. case XFS_TRANS_SB_RBMBLOCKS:
  897. tp->t_rbmblocks_delta += delta;
  898. break;
  899. case XFS_TRANS_SB_RBLOCKS:
  900. tp->t_rblocks_delta += delta;
  901. break;
  902. case XFS_TRANS_SB_REXTENTS:
  903. tp->t_rextents_delta += delta;
  904. break;
  905. case XFS_TRANS_SB_REXTSLOG:
  906. tp->t_rextslog_delta += delta;
  907. break;
  908. default:
  909. ASSERT(0);
  910. return;
  911. }
  912. tp->t_flags |= flags;
  913. }
  914. /*
  915. * xfs_trans_apply_sb_deltas() is called from the commit code
  916. * to bring the superblock buffer into the current transaction
  917. * and modify it as requested by earlier calls to xfs_trans_mod_sb().
  918. *
  919. * For now we just look at each field allowed to change and change
  920. * it if necessary.
  921. */
  922. STATIC void
  923. xfs_trans_apply_sb_deltas(
  924. xfs_trans_t *tp)
  925. {
  926. xfs_dsb_t *sbp;
  927. xfs_buf_t *bp;
  928. int whole = 0;
  929. bp = xfs_trans_getsb(tp, tp->t_mountp, 0);
  930. sbp = XFS_BUF_TO_SBP(bp);
  931. /*
  932. * Check that superblock mods match the mods made to AGF counters.
  933. */
  934. ASSERT((tp->t_fdblocks_delta + tp->t_res_fdblocks_delta) ==
  935. (tp->t_ag_freeblks_delta + tp->t_ag_flist_delta +
  936. tp->t_ag_btree_delta));
  937. /*
  938. * Only update the superblock counters if we are logging them
  939. */
  940. if (!xfs_sb_version_haslazysbcount(&(tp->t_mountp->m_sb))) {
  941. if (tp->t_icount_delta)
  942. be64_add_cpu(&sbp->sb_icount, tp->t_icount_delta);
  943. if (tp->t_ifree_delta)
  944. be64_add_cpu(&sbp->sb_ifree, tp->t_ifree_delta);
  945. if (tp->t_fdblocks_delta)
  946. be64_add_cpu(&sbp->sb_fdblocks, tp->t_fdblocks_delta);
  947. if (tp->t_res_fdblocks_delta)
  948. be64_add_cpu(&sbp->sb_fdblocks, tp->t_res_fdblocks_delta);
  949. }
  950. if (tp->t_frextents_delta)
  951. be64_add_cpu(&sbp->sb_frextents, tp->t_frextents_delta);
  952. if (tp->t_res_frextents_delta)
  953. be64_add_cpu(&sbp->sb_frextents, tp->t_res_frextents_delta);
  954. if (tp->t_dblocks_delta) {
  955. be64_add_cpu(&sbp->sb_dblocks, tp->t_dblocks_delta);
  956. whole = 1;
  957. }
  958. if (tp->t_agcount_delta) {
  959. be32_add_cpu(&sbp->sb_agcount, tp->t_agcount_delta);
  960. whole = 1;
  961. }
  962. if (tp->t_imaxpct_delta) {
  963. sbp->sb_imax_pct += tp->t_imaxpct_delta;
  964. whole = 1;
  965. }
  966. if (tp->t_rextsize_delta) {
  967. be32_add_cpu(&sbp->sb_rextsize, tp->t_rextsize_delta);
  968. whole = 1;
  969. }
  970. if (tp->t_rbmblocks_delta) {
  971. be32_add_cpu(&sbp->sb_rbmblocks, tp->t_rbmblocks_delta);
  972. whole = 1;
  973. }
  974. if (tp->t_rblocks_delta) {
  975. be64_add_cpu(&sbp->sb_rblocks, tp->t_rblocks_delta);
  976. whole = 1;
  977. }
  978. if (tp->t_rextents_delta) {
  979. be64_add_cpu(&sbp->sb_rextents, tp->t_rextents_delta);
  980. whole = 1;
  981. }
  982. if (tp->t_rextslog_delta) {
  983. sbp->sb_rextslog += tp->t_rextslog_delta;
  984. whole = 1;
  985. }
  986. if (whole)
  987. /*
  988. * Log the whole thing, the fields are noncontiguous.
  989. */
  990. xfs_trans_log_buf(tp, bp, 0, sizeof(xfs_dsb_t) - 1);
  991. else
  992. /*
  993. * Since all the modifiable fields are contiguous, we
  994. * can get away with this.
  995. */
  996. xfs_trans_log_buf(tp, bp, offsetof(xfs_dsb_t, sb_icount),
  997. offsetof(xfs_dsb_t, sb_frextents) +
  998. sizeof(sbp->sb_frextents) - 1);
  999. }
  1000. /*
  1001. * xfs_trans_unreserve_and_mod_sb() is called to release unused reservations
  1002. * and apply superblock counter changes to the in-core superblock. The
  1003. * t_res_fdblocks_delta and t_res_frextents_delta fields are explicitly NOT
  1004. * applied to the in-core superblock. The idea is that that has already been
  1005. * done.
  1006. *
  1007. * This is done efficiently with a single call to xfs_mod_incore_sb_batch().
  1008. * However, we have to ensure that we only modify each superblock field only
  1009. * once because the application of the delta values may not be atomic. That can
  1010. * lead to ENOSPC races occurring if we have two separate modifcations of the
  1011. * free space counter to put back the entire reservation and then take away
  1012. * what we used.
  1013. *
  1014. * If we are not logging superblock counters, then the inode allocated/free and
  1015. * used block counts are not updated in the on disk superblock. In this case,
  1016. * XFS_TRANS_SB_DIRTY will not be set when the transaction is updated but we
  1017. * still need to update the incore superblock with the changes.
  1018. */
  1019. void
  1020. xfs_trans_unreserve_and_mod_sb(
  1021. xfs_trans_t *tp)
  1022. {
  1023. xfs_mod_sb_t msb[9]; /* If you add cases, add entries */
  1024. xfs_mod_sb_t *msbp;
  1025. xfs_mount_t *mp = tp->t_mountp;
  1026. /* REFERENCED */
  1027. int error;
  1028. int rsvd;
  1029. int64_t blkdelta = 0;
  1030. int64_t rtxdelta = 0;
  1031. int64_t idelta = 0;
  1032. int64_t ifreedelta = 0;
  1033. msbp = msb;
  1034. rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0;
  1035. /* calculate deltas */
  1036. if (tp->t_blk_res > 0)
  1037. blkdelta = tp->t_blk_res;
  1038. if ((tp->t_fdblocks_delta != 0) &&
  1039. (xfs_sb_version_haslazysbcount(&mp->m_sb) ||
  1040. (tp->t_flags & XFS_TRANS_SB_DIRTY)))
  1041. blkdelta += tp->t_fdblocks_delta;
  1042. if (tp->t_rtx_res > 0)
  1043. rtxdelta = tp->t_rtx_res;
  1044. if ((tp->t_frextents_delta != 0) &&
  1045. (tp->t_flags & XFS_TRANS_SB_DIRTY))
  1046. rtxdelta += tp->t_frextents_delta;
  1047. if (xfs_sb_version_haslazysbcount(&mp->m_sb) ||
  1048. (tp->t_flags & XFS_TRANS_SB_DIRTY)) {
  1049. idelta = tp->t_icount_delta;
  1050. ifreedelta = tp->t_ifree_delta;
  1051. }
  1052. /* apply the per-cpu counters */
  1053. if (blkdelta) {
  1054. error = xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS,
  1055. blkdelta, rsvd);
  1056. if (error)
  1057. goto out;
  1058. }
  1059. if (idelta) {
  1060. error = xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT,
  1061. idelta, rsvd);
  1062. if (error)
  1063. goto out_undo_fdblocks;
  1064. }
  1065. if (ifreedelta) {
  1066. error = xfs_icsb_modify_counters(mp, XFS_SBS_IFREE,
  1067. ifreedelta, rsvd);
  1068. if (error)
  1069. goto out_undo_icount;
  1070. }
  1071. /* apply remaining deltas */
  1072. if (rtxdelta != 0) {
  1073. msbp->msb_field = XFS_SBS_FREXTENTS;
  1074. msbp->msb_delta = rtxdelta;
  1075. msbp++;
  1076. }
  1077. if (tp->t_flags & XFS_TRANS_SB_DIRTY) {
  1078. if (tp->t_dblocks_delta != 0) {
  1079. msbp->msb_field = XFS_SBS_DBLOCKS;
  1080. msbp->msb_delta = tp->t_dblocks_delta;
  1081. msbp++;
  1082. }
  1083. if (tp->t_agcount_delta != 0) {
  1084. msbp->msb_field = XFS_SBS_AGCOUNT;
  1085. msbp->msb_delta = tp->t_agcount_delta;
  1086. msbp++;
  1087. }
  1088. if (tp->t_imaxpct_delta != 0) {
  1089. msbp->msb_field = XFS_SBS_IMAX_PCT;
  1090. msbp->msb_delta = tp->t_imaxpct_delta;
  1091. msbp++;
  1092. }
  1093. if (tp->t_rextsize_delta != 0) {
  1094. msbp->msb_field = XFS_SBS_REXTSIZE;
  1095. msbp->msb_delta = tp->t_rextsize_delta;
  1096. msbp++;
  1097. }
  1098. if (tp->t_rbmblocks_delta != 0) {
  1099. msbp->msb_field = XFS_SBS_RBMBLOCKS;
  1100. msbp->msb_delta = tp->t_rbmblocks_delta;
  1101. msbp++;
  1102. }
  1103. if (tp->t_rblocks_delta != 0) {
  1104. msbp->msb_field = XFS_SBS_RBLOCKS;
  1105. msbp->msb_delta = tp->t_rblocks_delta;
  1106. msbp++;
  1107. }
  1108. if (tp->t_rextents_delta != 0) {
  1109. msbp->msb_field = XFS_SBS_REXTENTS;
  1110. msbp->msb_delta = tp->t_rextents_delta;
  1111. msbp++;
  1112. }
  1113. if (tp->t_rextslog_delta != 0) {
  1114. msbp->msb_field = XFS_SBS_REXTSLOG;
  1115. msbp->msb_delta = tp->t_rextslog_delta;
  1116. msbp++;
  1117. }
  1118. }
  1119. /*
  1120. * If we need to change anything, do it.
  1121. */
  1122. if (msbp > msb) {
  1123. error = xfs_mod_incore_sb_batch(tp->t_mountp, msb,
  1124. (uint)(msbp - msb), rsvd);
  1125. if (error)
  1126. goto out_undo_ifreecount;
  1127. }
  1128. return;
  1129. out_undo_ifreecount:
  1130. if (ifreedelta)
  1131. xfs_icsb_modify_counters(mp, XFS_SBS_IFREE, -ifreedelta, rsvd);
  1132. out_undo_icount:
  1133. if (idelta)
  1134. xfs_icsb_modify_counters(mp, XFS_SBS_ICOUNT, -idelta, rsvd);
  1135. out_undo_fdblocks:
  1136. if (blkdelta)
  1137. xfs_icsb_modify_counters(mp, XFS_SBS_FDBLOCKS, -blkdelta, rsvd);
  1138. out:
  1139. ASSERT(error == 0);
  1140. return;
  1141. }
  1142. /*
  1143. * Add the given log item to the transaction's list of log items.
  1144. *
  1145. * The log item will now point to its new descriptor with its li_desc field.
  1146. */
  1147. void
  1148. xfs_trans_add_item(
  1149. struct xfs_trans *tp,
  1150. struct xfs_log_item *lip)
  1151. {
  1152. struct xfs_log_item_desc *lidp;
  1153. ASSERT(lip->li_mountp == tp->t_mountp);
  1154. ASSERT(lip->li_ailp == tp->t_mountp->m_ail);
  1155. lidp = kmem_zone_zalloc(xfs_log_item_desc_zone, KM_SLEEP | KM_NOFS);
  1156. lidp->lid_item = lip;
  1157. lidp->lid_flags = 0;
  1158. list_add_tail(&lidp->lid_trans, &tp->t_items);
  1159. lip->li_desc = lidp;
  1160. }
  1161. STATIC void
  1162. xfs_trans_free_item_desc(
  1163. struct xfs_log_item_desc *lidp)
  1164. {
  1165. list_del_init(&lidp->lid_trans);
  1166. kmem_zone_free(xfs_log_item_desc_zone, lidp);
  1167. }
  1168. /*
  1169. * Unlink and free the given descriptor.
  1170. */
  1171. void
  1172. xfs_trans_del_item(
  1173. struct xfs_log_item *lip)
  1174. {
  1175. xfs_trans_free_item_desc(lip->li_desc);
  1176. lip->li_desc = NULL;
  1177. }
  1178. /*
  1179. * Unlock all of the items of a transaction and free all the descriptors
  1180. * of that transaction.
  1181. */
  1182. void
  1183. xfs_trans_free_items(
  1184. struct xfs_trans *tp,
  1185. xfs_lsn_t commit_lsn,
  1186. int flags)
  1187. {
  1188. struct xfs_log_item_desc *lidp, *next;
  1189. list_for_each_entry_safe(lidp, next, &tp->t_items, lid_trans) {
  1190. struct xfs_log_item *lip = lidp->lid_item;
  1191. lip->li_desc = NULL;
  1192. if (commit_lsn != NULLCOMMITLSN)
  1193. IOP_COMMITTING(lip, commit_lsn);
  1194. if (flags & XFS_TRANS_ABORT)
  1195. lip->li_flags |= XFS_LI_ABORTED;
  1196. IOP_UNLOCK(lip);
  1197. xfs_trans_free_item_desc(lidp);
  1198. }
  1199. }
  1200. static inline void
  1201. xfs_log_item_batch_insert(
  1202. struct xfs_ail *ailp,
  1203. struct xfs_ail_cursor *cur,
  1204. struct xfs_log_item **log_items,
  1205. int nr_items,
  1206. xfs_lsn_t commit_lsn)
  1207. {
  1208. int i;
  1209. spin_lock(&ailp->xa_lock);
  1210. /* xfs_trans_ail_update_bulk drops ailp->xa_lock */
  1211. xfs_trans_ail_update_bulk(ailp, cur, log_items, nr_items, commit_lsn);
  1212. for (i = 0; i < nr_items; i++)
  1213. IOP_UNPIN(log_items[i], 0);
  1214. }
  1215. /*
  1216. * Bulk operation version of xfs_trans_committed that takes a log vector of
  1217. * items to insert into the AIL. This uses bulk AIL insertion techniques to
  1218. * minimise lock traffic.
  1219. *
  1220. * If we are called with the aborted flag set, it is because a log write during
  1221. * a CIL checkpoint commit has failed. In this case, all the items in the
  1222. * checkpoint have already gone through IOP_COMMITED and IOP_UNLOCK, which
  1223. * means that checkpoint commit abort handling is treated exactly the same
  1224. * as an iclog write error even though we haven't started any IO yet. Hence in
  1225. * this case all we need to do is IOP_COMMITTED processing, followed by an
  1226. * IOP_UNPIN(aborted) call.
  1227. *
  1228. * The AIL cursor is used to optimise the insert process. If commit_lsn is not
  1229. * at the end of the AIL, the insert cursor avoids the need to walk
  1230. * the AIL to find the insertion point on every xfs_log_item_batch_insert()
  1231. * call. This saves a lot of needless list walking and is a net win, even
  1232. * though it slightly increases that amount of AIL lock traffic to set it up
  1233. * and tear it down.
  1234. */
  1235. void
  1236. xfs_trans_committed_bulk(
  1237. struct xfs_ail *ailp,
  1238. struct xfs_log_vec *log_vector,
  1239. xfs_lsn_t commit_lsn,
  1240. int aborted)
  1241. {
  1242. #define LOG_ITEM_BATCH_SIZE 32
  1243. struct xfs_log_item *log_items[LOG_ITEM_BATCH_SIZE];
  1244. struct xfs_log_vec *lv;
  1245. struct xfs_ail_cursor cur;
  1246. int i = 0;
  1247. spin_lock(&ailp->xa_lock);
  1248. xfs_trans_ail_cursor_last(ailp, &cur, commit_lsn);
  1249. spin_unlock(&ailp->xa_lock);
  1250. /* unpin all the log items */
  1251. for (lv = log_vector; lv; lv = lv->lv_next ) {
  1252. struct xfs_log_item *lip = lv->lv_item;
  1253. xfs_lsn_t item_lsn;
  1254. if (aborted)
  1255. lip->li_flags |= XFS_LI_ABORTED;
  1256. item_lsn = IOP_COMMITTED(lip, commit_lsn);
  1257. /* item_lsn of -1 means the item needs no further processing */
  1258. if (XFS_LSN_CMP(item_lsn, (xfs_lsn_t)-1) == 0)
  1259. continue;
  1260. /*
  1261. * if we are aborting the operation, no point in inserting the
  1262. * object into the AIL as we are in a shutdown situation.
  1263. */
  1264. if (aborted) {
  1265. ASSERT(XFS_FORCED_SHUTDOWN(ailp->xa_mount));
  1266. IOP_UNPIN(lip, 1);
  1267. continue;
  1268. }
  1269. if (item_lsn != commit_lsn) {
  1270. /*
  1271. * Not a bulk update option due to unusual item_lsn.
  1272. * Push into AIL immediately, rechecking the lsn once
  1273. * we have the ail lock. Then unpin the item. This does
  1274. * not affect the AIL cursor the bulk insert path is
  1275. * using.
  1276. */
  1277. spin_lock(&ailp->xa_lock);
  1278. if (XFS_LSN_CMP(item_lsn, lip->li_lsn) > 0)
  1279. xfs_trans_ail_update(ailp, lip, item_lsn);
  1280. else
  1281. spin_unlock(&ailp->xa_lock);
  1282. IOP_UNPIN(lip, 0);
  1283. continue;
  1284. }
  1285. /* Item is a candidate for bulk AIL insert. */
  1286. log_items[i++] = lv->lv_item;
  1287. if (i >= LOG_ITEM_BATCH_SIZE) {
  1288. xfs_log_item_batch_insert(ailp, &cur, log_items,
  1289. LOG_ITEM_BATCH_SIZE, commit_lsn);
  1290. i = 0;
  1291. }
  1292. }
  1293. /* make sure we insert the remainder! */
  1294. if (i)
  1295. xfs_log_item_batch_insert(ailp, &cur, log_items, i, commit_lsn);
  1296. spin_lock(&ailp->xa_lock);
  1297. xfs_trans_ail_cursor_done(ailp, &cur);
  1298. spin_unlock(&ailp->xa_lock);
  1299. }
  1300. /*
  1301. * Commit the given transaction to the log.
  1302. *
  1303. * XFS disk error handling mechanism is not based on a typical
  1304. * transaction abort mechanism. Logically after the filesystem
  1305. * gets marked 'SHUTDOWN', we can't let any new transactions
  1306. * be durable - ie. committed to disk - because some metadata might
  1307. * be inconsistent. In such cases, this returns an error, and the
  1308. * caller may assume that all locked objects joined to the transaction
  1309. * have already been unlocked as if the commit had succeeded.
  1310. * Do not reference the transaction structure after this call.
  1311. */
  1312. int
  1313. xfs_trans_commit(
  1314. struct xfs_trans *tp,
  1315. uint flags)
  1316. {
  1317. struct xfs_mount *mp = tp->t_mountp;
  1318. xfs_lsn_t commit_lsn = -1;
  1319. int error = 0;
  1320. int log_flags = 0;
  1321. int sync = tp->t_flags & XFS_TRANS_SYNC;
  1322. /*
  1323. * Determine whether this commit is releasing a permanent
  1324. * log reservation or not.
  1325. */
  1326. if (flags & XFS_TRANS_RELEASE_LOG_RES) {
  1327. ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
  1328. log_flags = XFS_LOG_REL_PERM_RESERV;
  1329. }
  1330. /*
  1331. * If there is nothing to be logged by the transaction,
  1332. * then unlock all of the items associated with the
  1333. * transaction and free the transaction structure.
  1334. * Also make sure to return any reserved blocks to
  1335. * the free pool.
  1336. */
  1337. if (!(tp->t_flags & XFS_TRANS_DIRTY))
  1338. goto out_unreserve;
  1339. if (XFS_FORCED_SHUTDOWN(mp)) {
  1340. error = XFS_ERROR(EIO);
  1341. goto out_unreserve;
  1342. }
  1343. ASSERT(tp->t_ticket != NULL);
  1344. /*
  1345. * If we need to update the superblock, then do it now.
  1346. */
  1347. if (tp->t_flags & XFS_TRANS_SB_DIRTY)
  1348. xfs_trans_apply_sb_deltas(tp);
  1349. xfs_trans_apply_dquot_deltas(tp);
  1350. error = xfs_log_commit_cil(mp, tp, &commit_lsn, flags);
  1351. if (error == ENOMEM) {
  1352. xfs_force_shutdown(mp, SHUTDOWN_LOG_IO_ERROR);
  1353. error = XFS_ERROR(EIO);
  1354. goto out_unreserve;
  1355. }
  1356. current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
  1357. xfs_trans_free(tp);
  1358. /*
  1359. * If the transaction needs to be synchronous, then force the
  1360. * log out now and wait for it.
  1361. */
  1362. if (sync) {
  1363. if (!error) {
  1364. error = _xfs_log_force_lsn(mp, commit_lsn,
  1365. XFS_LOG_SYNC, NULL);
  1366. }
  1367. XFS_STATS_INC(xs_trans_sync);
  1368. } else {
  1369. XFS_STATS_INC(xs_trans_async);
  1370. }
  1371. return error;
  1372. out_unreserve:
  1373. xfs_trans_unreserve_and_mod_sb(tp);
  1374. /*
  1375. * It is indeed possible for the transaction to be not dirty but
  1376. * the dqinfo portion to be. All that means is that we have some
  1377. * (non-persistent) quota reservations that need to be unreserved.
  1378. */
  1379. xfs_trans_unreserve_and_mod_dquots(tp);
  1380. if (tp->t_ticket) {
  1381. commit_lsn = xfs_log_done(mp, tp->t_ticket, NULL, log_flags);
  1382. if (commit_lsn == -1 && !error)
  1383. error = XFS_ERROR(EIO);
  1384. }
  1385. current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
  1386. xfs_trans_free_items(tp, NULLCOMMITLSN, error ? XFS_TRANS_ABORT : 0);
  1387. xfs_trans_free(tp);
  1388. XFS_STATS_INC(xs_trans_empty);
  1389. return error;
  1390. }
  1391. /*
  1392. * Unlock all of the transaction's items and free the transaction.
  1393. * The transaction must not have modified any of its items, because
  1394. * there is no way to restore them to their previous state.
  1395. *
  1396. * If the transaction has made a log reservation, make sure to release
  1397. * it as well.
  1398. */
  1399. void
  1400. xfs_trans_cancel(
  1401. xfs_trans_t *tp,
  1402. int flags)
  1403. {
  1404. int log_flags;
  1405. xfs_mount_t *mp = tp->t_mountp;
  1406. /*
  1407. * See if the caller is being too lazy to figure out if
  1408. * the transaction really needs an abort.
  1409. */
  1410. if ((flags & XFS_TRANS_ABORT) && !(tp->t_flags & XFS_TRANS_DIRTY))
  1411. flags &= ~XFS_TRANS_ABORT;
  1412. /*
  1413. * See if the caller is relying on us to shut down the
  1414. * filesystem. This happens in paths where we detect
  1415. * corruption and decide to give up.
  1416. */
  1417. if ((tp->t_flags & XFS_TRANS_DIRTY) && !XFS_FORCED_SHUTDOWN(mp)) {
  1418. XFS_ERROR_REPORT("xfs_trans_cancel", XFS_ERRLEVEL_LOW, mp);
  1419. xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
  1420. }
  1421. #ifdef DEBUG
  1422. if (!(flags & XFS_TRANS_ABORT) && !XFS_FORCED_SHUTDOWN(mp)) {
  1423. struct xfs_log_item_desc *lidp;
  1424. list_for_each_entry(lidp, &tp->t_items, lid_trans)
  1425. ASSERT(!(lidp->lid_item->li_type == XFS_LI_EFD));
  1426. }
  1427. #endif
  1428. xfs_trans_unreserve_and_mod_sb(tp);
  1429. xfs_trans_unreserve_and_mod_dquots(tp);
  1430. if (tp->t_ticket) {
  1431. if (flags & XFS_TRANS_RELEASE_LOG_RES) {
  1432. ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
  1433. log_flags = XFS_LOG_REL_PERM_RESERV;
  1434. } else {
  1435. log_flags = 0;
  1436. }
  1437. xfs_log_done(mp, tp->t_ticket, NULL, log_flags);
  1438. }
  1439. /* mark this thread as no longer being in a transaction */
  1440. current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS);
  1441. xfs_trans_free_items(tp, NULLCOMMITLSN, flags);
  1442. xfs_trans_free(tp);
  1443. }
  1444. /*
  1445. * Roll from one trans in the sequence of PERMANENT transactions to
  1446. * the next: permanent transactions are only flushed out when
  1447. * committed with XFS_TRANS_RELEASE_LOG_RES, but we still want as soon
  1448. * as possible to let chunks of it go to the log. So we commit the
  1449. * chunk we've been working on and get a new transaction to continue.
  1450. */
  1451. int
  1452. xfs_trans_roll(
  1453. struct xfs_trans **tpp,
  1454. struct xfs_inode *dp)
  1455. {
  1456. struct xfs_trans *trans;
  1457. unsigned int logres, count;
  1458. int error;
  1459. /*
  1460. * Ensure that the inode is always logged.
  1461. */
  1462. trans = *tpp;
  1463. xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
  1464. /*
  1465. * Copy the critical parameters from one trans to the next.
  1466. */
  1467. logres = trans->t_log_res;
  1468. count = trans->t_log_count;
  1469. *tpp = xfs_trans_dup(trans);
  1470. /*
  1471. * Commit the current transaction.
  1472. * If this commit failed, then it'd just unlock those items that
  1473. * are not marked ihold. That also means that a filesystem shutdown
  1474. * is in progress. The caller takes the responsibility to cancel
  1475. * the duplicate transaction that gets returned.
  1476. */
  1477. error = xfs_trans_commit(trans, 0);
  1478. if (error)
  1479. return (error);
  1480. trans = *tpp;
  1481. /*
  1482. * transaction commit worked ok so we can drop the extra ticket
  1483. * reference that we gained in xfs_trans_dup()
  1484. */
  1485. xfs_log_ticket_put(trans->t_ticket);
  1486. /*
  1487. * Reserve space in the log for th next transaction.
  1488. * This also pushes items in the "AIL", the list of logged items,
  1489. * out to disk if they are taking up space at the tail of the log
  1490. * that we want to use. This requires that either nothing be locked
  1491. * across this call, or that anything that is locked be logged in
  1492. * the prior and the next transactions.
  1493. */
  1494. error = xfs_trans_reserve(trans, 0, logres, 0,
  1495. XFS_TRANS_PERM_LOG_RES, count);
  1496. /*
  1497. * Ensure that the inode is in the new transaction and locked.
  1498. */
  1499. if (error)
  1500. return error;
  1501. xfs_trans_ijoin(trans, dp, 0);
  1502. return 0;
  1503. }