suballoc.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * suballoc.c
  5. *
  6. * metadata alloc and free
  7. * Inspired by ext3 block groups.
  8. *
  9. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 2 of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public
  22. * License along with this program; if not, write to the
  23. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. * Boston, MA 021110-1307, USA.
  25. */
  26. #include <linux/fs.h>
  27. #include <linux/types.h>
  28. #include <linux/slab.h>
  29. #include <linux/highmem.h>
  30. #define MLOG_MASK_PREFIX ML_DISK_ALLOC
  31. #include <cluster/masklog.h>
  32. #include "ocfs2.h"
  33. #include "alloc.h"
  34. #include "dlmglue.h"
  35. #include "inode.h"
  36. #include "journal.h"
  37. #include "localalloc.h"
  38. #include "suballoc.h"
  39. #include "super.h"
  40. #include "sysfile.h"
  41. #include "uptodate.h"
  42. #include "buffer_head_io.h"
  43. static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg);
  44. static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe);
  45. static inline u16 ocfs2_find_victim_chain(struct ocfs2_chain_list *cl);
  46. static int ocfs2_block_group_fill(handle_t *handle,
  47. struct inode *alloc_inode,
  48. struct buffer_head *bg_bh,
  49. u64 group_blkno,
  50. u16 my_chain,
  51. struct ocfs2_chain_list *cl);
  52. static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
  53. struct inode *alloc_inode,
  54. struct buffer_head *bh);
  55. static int ocfs2_cluster_group_search(struct inode *inode,
  56. struct buffer_head *group_bh,
  57. u32 bits_wanted, u32 min_bits,
  58. u16 *bit_off, u16 *bits_found);
  59. static int ocfs2_block_group_search(struct inode *inode,
  60. struct buffer_head *group_bh,
  61. u32 bits_wanted, u32 min_bits,
  62. u16 *bit_off, u16 *bits_found);
  63. static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
  64. struct ocfs2_alloc_context *ac,
  65. handle_t *handle,
  66. u32 bits_wanted,
  67. u32 min_bits,
  68. u16 *bit_off,
  69. unsigned int *num_bits,
  70. u64 *bg_blkno);
  71. static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,
  72. int nr);
  73. static inline int ocfs2_block_group_set_bits(handle_t *handle,
  74. struct inode *alloc_inode,
  75. struct ocfs2_group_desc *bg,
  76. struct buffer_head *group_bh,
  77. unsigned int bit_off,
  78. unsigned int num_bits);
  79. static inline int ocfs2_block_group_clear_bits(handle_t *handle,
  80. struct inode *alloc_inode,
  81. struct ocfs2_group_desc *bg,
  82. struct buffer_head *group_bh,
  83. unsigned int bit_off,
  84. unsigned int num_bits);
  85. static int ocfs2_relink_block_group(handle_t *handle,
  86. struct inode *alloc_inode,
  87. struct buffer_head *fe_bh,
  88. struct buffer_head *bg_bh,
  89. struct buffer_head *prev_bg_bh,
  90. u16 chain);
  91. static inline int ocfs2_block_group_reasonably_empty(struct ocfs2_group_desc *bg,
  92. u32 wanted);
  93. static inline u32 ocfs2_desc_bitmap_to_cluster_off(struct inode *inode,
  94. u64 bg_blkno,
  95. u16 bg_bit_off);
  96. static inline void ocfs2_block_to_cluster_group(struct inode *inode,
  97. u64 data_blkno,
  98. u64 *bg_blkno,
  99. u16 *bg_bit_off);
  100. void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac)
  101. {
  102. struct inode *inode = ac->ac_inode;
  103. if (inode) {
  104. if (ac->ac_which != OCFS2_AC_USE_LOCAL)
  105. ocfs2_inode_unlock(inode, 1);
  106. mutex_unlock(&inode->i_mutex);
  107. iput(inode);
  108. }
  109. if (ac->ac_bh)
  110. brelse(ac->ac_bh);
  111. kfree(ac);
  112. }
  113. static u32 ocfs2_bits_per_group(struct ocfs2_chain_list *cl)
  114. {
  115. return (u32)le16_to_cpu(cl->cl_cpg) * (u32)le16_to_cpu(cl->cl_bpc);
  116. }
  117. /* somewhat more expensive than our other checks, so use sparingly. */
  118. int ocfs2_check_group_descriptor(struct super_block *sb,
  119. struct ocfs2_dinode *di,
  120. struct ocfs2_group_desc *gd)
  121. {
  122. unsigned int max_bits;
  123. if (!OCFS2_IS_VALID_GROUP_DESC(gd)) {
  124. OCFS2_RO_ON_INVALID_GROUP_DESC(sb, gd);
  125. return -EIO;
  126. }
  127. if (di->i_blkno != gd->bg_parent_dinode) {
  128. ocfs2_error(sb, "Group descriptor # %llu has bad parent "
  129. "pointer (%llu, expected %llu)",
  130. (unsigned long long)le64_to_cpu(gd->bg_blkno),
  131. (unsigned long long)le64_to_cpu(gd->bg_parent_dinode),
  132. (unsigned long long)le64_to_cpu(di->i_blkno));
  133. return -EIO;
  134. }
  135. max_bits = le16_to_cpu(di->id2.i_chain.cl_cpg) * le16_to_cpu(di->id2.i_chain.cl_bpc);
  136. if (le16_to_cpu(gd->bg_bits) > max_bits) {
  137. ocfs2_error(sb, "Group descriptor # %llu has bit count of %u",
  138. (unsigned long long)le64_to_cpu(gd->bg_blkno),
  139. le16_to_cpu(gd->bg_bits));
  140. return -EIO;
  141. }
  142. if (le16_to_cpu(gd->bg_chain) >=
  143. le16_to_cpu(di->id2.i_chain.cl_next_free_rec)) {
  144. ocfs2_error(sb, "Group descriptor # %llu has bad chain %u",
  145. (unsigned long long)le64_to_cpu(gd->bg_blkno),
  146. le16_to_cpu(gd->bg_chain));
  147. return -EIO;
  148. }
  149. if (le16_to_cpu(gd->bg_free_bits_count) > le16_to_cpu(gd->bg_bits)) {
  150. ocfs2_error(sb, "Group descriptor # %llu has bit count %u but "
  151. "claims that %u are free",
  152. (unsigned long long)le64_to_cpu(gd->bg_blkno),
  153. le16_to_cpu(gd->bg_bits),
  154. le16_to_cpu(gd->bg_free_bits_count));
  155. return -EIO;
  156. }
  157. if (le16_to_cpu(gd->bg_bits) > (8 * le16_to_cpu(gd->bg_size))) {
  158. ocfs2_error(sb, "Group descriptor # %llu has bit count %u but "
  159. "max bitmap bits of %u",
  160. (unsigned long long)le64_to_cpu(gd->bg_blkno),
  161. le16_to_cpu(gd->bg_bits),
  162. 8 * le16_to_cpu(gd->bg_size));
  163. return -EIO;
  164. }
  165. return 0;
  166. }
  167. static int ocfs2_block_group_fill(handle_t *handle,
  168. struct inode *alloc_inode,
  169. struct buffer_head *bg_bh,
  170. u64 group_blkno,
  171. u16 my_chain,
  172. struct ocfs2_chain_list *cl)
  173. {
  174. int status = 0;
  175. struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
  176. struct super_block * sb = alloc_inode->i_sb;
  177. mlog_entry_void();
  178. if (((unsigned long long) bg_bh->b_blocknr) != group_blkno) {
  179. ocfs2_error(alloc_inode->i_sb, "group block (%llu) != "
  180. "b_blocknr (%llu)",
  181. (unsigned long long)group_blkno,
  182. (unsigned long long) bg_bh->b_blocknr);
  183. status = -EIO;
  184. goto bail;
  185. }
  186. status = ocfs2_journal_access(handle,
  187. alloc_inode,
  188. bg_bh,
  189. OCFS2_JOURNAL_ACCESS_CREATE);
  190. if (status < 0) {
  191. mlog_errno(status);
  192. goto bail;
  193. }
  194. memset(bg, 0, sb->s_blocksize);
  195. strcpy(bg->bg_signature, OCFS2_GROUP_DESC_SIGNATURE);
  196. bg->bg_generation = cpu_to_le32(OCFS2_SB(sb)->fs_generation);
  197. bg->bg_size = cpu_to_le16(ocfs2_group_bitmap_size(sb));
  198. bg->bg_bits = cpu_to_le16(ocfs2_bits_per_group(cl));
  199. bg->bg_chain = cpu_to_le16(my_chain);
  200. bg->bg_next_group = cl->cl_recs[my_chain].c_blkno;
  201. bg->bg_parent_dinode = cpu_to_le64(OCFS2_I(alloc_inode)->ip_blkno);
  202. bg->bg_blkno = cpu_to_le64(group_blkno);
  203. /* set the 1st bit in the bitmap to account for the descriptor block */
  204. ocfs2_set_bit(0, (unsigned long *)bg->bg_bitmap);
  205. bg->bg_free_bits_count = cpu_to_le16(le16_to_cpu(bg->bg_bits) - 1);
  206. status = ocfs2_journal_dirty(handle, bg_bh);
  207. if (status < 0)
  208. mlog_errno(status);
  209. /* There is no need to zero out or otherwise initialize the
  210. * other blocks in a group - All valid FS metadata in a block
  211. * group stores the superblock fs_generation value at
  212. * allocation time. */
  213. bail:
  214. mlog_exit(status);
  215. return status;
  216. }
  217. static inline u16 ocfs2_find_smallest_chain(struct ocfs2_chain_list *cl)
  218. {
  219. u16 curr, best;
  220. best = curr = 0;
  221. while (curr < le16_to_cpu(cl->cl_count)) {
  222. if (le32_to_cpu(cl->cl_recs[best].c_total) >
  223. le32_to_cpu(cl->cl_recs[curr].c_total))
  224. best = curr;
  225. curr++;
  226. }
  227. return best;
  228. }
  229. /*
  230. * We expect the block group allocator to already be locked.
  231. */
  232. static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
  233. struct inode *alloc_inode,
  234. struct buffer_head *bh)
  235. {
  236. int status, credits;
  237. struct ocfs2_dinode *fe = (struct ocfs2_dinode *) bh->b_data;
  238. struct ocfs2_chain_list *cl;
  239. struct ocfs2_alloc_context *ac = NULL;
  240. handle_t *handle = NULL;
  241. u32 bit_off, num_bits;
  242. u16 alloc_rec;
  243. u64 bg_blkno;
  244. struct buffer_head *bg_bh = NULL;
  245. struct ocfs2_group_desc *bg;
  246. BUG_ON(ocfs2_is_cluster_bitmap(alloc_inode));
  247. mlog_entry_void();
  248. cl = &fe->id2.i_chain;
  249. status = ocfs2_reserve_clusters(osb,
  250. le16_to_cpu(cl->cl_cpg),
  251. &ac);
  252. if (status < 0) {
  253. if (status != -ENOSPC)
  254. mlog_errno(status);
  255. goto bail;
  256. }
  257. credits = ocfs2_calc_group_alloc_credits(osb->sb,
  258. le16_to_cpu(cl->cl_cpg));
  259. handle = ocfs2_start_trans(osb, credits);
  260. if (IS_ERR(handle)) {
  261. status = PTR_ERR(handle);
  262. handle = NULL;
  263. mlog_errno(status);
  264. goto bail;
  265. }
  266. status = ocfs2_claim_clusters(osb,
  267. handle,
  268. ac,
  269. le16_to_cpu(cl->cl_cpg),
  270. &bit_off,
  271. &num_bits);
  272. if (status < 0) {
  273. if (status != -ENOSPC)
  274. mlog_errno(status);
  275. goto bail;
  276. }
  277. alloc_rec = ocfs2_find_smallest_chain(cl);
  278. /* setup the group */
  279. bg_blkno = ocfs2_clusters_to_blocks(osb->sb, bit_off);
  280. mlog(0, "new descriptor, record %u, at block %llu\n",
  281. alloc_rec, (unsigned long long)bg_blkno);
  282. bg_bh = sb_getblk(osb->sb, bg_blkno);
  283. if (!bg_bh) {
  284. status = -EIO;
  285. mlog_errno(status);
  286. goto bail;
  287. }
  288. ocfs2_set_new_buffer_uptodate(alloc_inode, bg_bh);
  289. status = ocfs2_block_group_fill(handle,
  290. alloc_inode,
  291. bg_bh,
  292. bg_blkno,
  293. alloc_rec,
  294. cl);
  295. if (status < 0) {
  296. mlog_errno(status);
  297. goto bail;
  298. }
  299. bg = (struct ocfs2_group_desc *) bg_bh->b_data;
  300. status = ocfs2_journal_access(handle, alloc_inode,
  301. bh, OCFS2_JOURNAL_ACCESS_WRITE);
  302. if (status < 0) {
  303. mlog_errno(status);
  304. goto bail;
  305. }
  306. le32_add_cpu(&cl->cl_recs[alloc_rec].c_free,
  307. le16_to_cpu(bg->bg_free_bits_count));
  308. le32_add_cpu(&cl->cl_recs[alloc_rec].c_total, le16_to_cpu(bg->bg_bits));
  309. cl->cl_recs[alloc_rec].c_blkno = cpu_to_le64(bg_blkno);
  310. if (le16_to_cpu(cl->cl_next_free_rec) < le16_to_cpu(cl->cl_count))
  311. le16_add_cpu(&cl->cl_next_free_rec, 1);
  312. le32_add_cpu(&fe->id1.bitmap1.i_used, le16_to_cpu(bg->bg_bits) -
  313. le16_to_cpu(bg->bg_free_bits_count));
  314. le32_add_cpu(&fe->id1.bitmap1.i_total, le16_to_cpu(bg->bg_bits));
  315. le32_add_cpu(&fe->i_clusters, le16_to_cpu(cl->cl_cpg));
  316. status = ocfs2_journal_dirty(handle, bh);
  317. if (status < 0) {
  318. mlog_errno(status);
  319. goto bail;
  320. }
  321. spin_lock(&OCFS2_I(alloc_inode)->ip_lock);
  322. OCFS2_I(alloc_inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
  323. fe->i_size = cpu_to_le64(ocfs2_clusters_to_bytes(alloc_inode->i_sb,
  324. le32_to_cpu(fe->i_clusters)));
  325. spin_unlock(&OCFS2_I(alloc_inode)->ip_lock);
  326. i_size_write(alloc_inode, le64_to_cpu(fe->i_size));
  327. alloc_inode->i_blocks = ocfs2_inode_sector_count(alloc_inode);
  328. status = 0;
  329. bail:
  330. if (handle)
  331. ocfs2_commit_trans(osb, handle);
  332. if (ac)
  333. ocfs2_free_alloc_context(ac);
  334. if (bg_bh)
  335. brelse(bg_bh);
  336. mlog_exit(status);
  337. return status;
  338. }
  339. static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
  340. struct ocfs2_alloc_context *ac,
  341. int type,
  342. u32 slot)
  343. {
  344. int status;
  345. u32 bits_wanted = ac->ac_bits_wanted;
  346. struct inode *alloc_inode;
  347. struct buffer_head *bh = NULL;
  348. struct ocfs2_dinode *fe;
  349. u32 free_bits;
  350. mlog_entry_void();
  351. alloc_inode = ocfs2_get_system_file_inode(osb, type, slot);
  352. if (!alloc_inode) {
  353. mlog_errno(-EINVAL);
  354. return -EINVAL;
  355. }
  356. mutex_lock(&alloc_inode->i_mutex);
  357. status = ocfs2_inode_lock(alloc_inode, &bh, 1);
  358. if (status < 0) {
  359. mutex_unlock(&alloc_inode->i_mutex);
  360. iput(alloc_inode);
  361. mlog_errno(status);
  362. return status;
  363. }
  364. ac->ac_inode = alloc_inode;
  365. fe = (struct ocfs2_dinode *) bh->b_data;
  366. if (!OCFS2_IS_VALID_DINODE(fe)) {
  367. OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe);
  368. status = -EIO;
  369. goto bail;
  370. }
  371. if (!(fe->i_flags & cpu_to_le32(OCFS2_CHAIN_FL))) {
  372. ocfs2_error(alloc_inode->i_sb, "Invalid chain allocator %llu",
  373. (unsigned long long)le64_to_cpu(fe->i_blkno));
  374. status = -EIO;
  375. goto bail;
  376. }
  377. free_bits = le32_to_cpu(fe->id1.bitmap1.i_total) -
  378. le32_to_cpu(fe->id1.bitmap1.i_used);
  379. if (bits_wanted > free_bits) {
  380. /* cluster bitmap never grows */
  381. if (ocfs2_is_cluster_bitmap(alloc_inode)) {
  382. mlog(0, "Disk Full: wanted=%u, free_bits=%u\n",
  383. bits_wanted, free_bits);
  384. status = -ENOSPC;
  385. goto bail;
  386. }
  387. status = ocfs2_block_group_alloc(osb, alloc_inode, bh);
  388. if (status < 0) {
  389. if (status != -ENOSPC)
  390. mlog_errno(status);
  391. goto bail;
  392. }
  393. atomic_inc(&osb->alloc_stats.bg_extends);
  394. /* You should never ask for this much metadata */
  395. BUG_ON(bits_wanted >
  396. (le32_to_cpu(fe->id1.bitmap1.i_total)
  397. - le32_to_cpu(fe->id1.bitmap1.i_used)));
  398. }
  399. get_bh(bh);
  400. ac->ac_bh = bh;
  401. bail:
  402. if (bh)
  403. brelse(bh);
  404. mlog_exit(status);
  405. return status;
  406. }
  407. int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
  408. struct ocfs2_dinode *fe,
  409. struct ocfs2_alloc_context **ac)
  410. {
  411. int status;
  412. u32 slot;
  413. *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
  414. if (!(*ac)) {
  415. status = -ENOMEM;
  416. mlog_errno(status);
  417. goto bail;
  418. }
  419. (*ac)->ac_bits_wanted = ocfs2_extend_meta_needed(fe);
  420. (*ac)->ac_which = OCFS2_AC_USE_META;
  421. slot = osb->slot_num;
  422. (*ac)->ac_group_search = ocfs2_block_group_search;
  423. status = ocfs2_reserve_suballoc_bits(osb, (*ac),
  424. EXTENT_ALLOC_SYSTEM_INODE, slot);
  425. if (status < 0) {
  426. if (status != -ENOSPC)
  427. mlog_errno(status);
  428. goto bail;
  429. }
  430. status = 0;
  431. bail:
  432. if ((status < 0) && *ac) {
  433. ocfs2_free_alloc_context(*ac);
  434. *ac = NULL;
  435. }
  436. mlog_exit(status);
  437. return status;
  438. }
  439. int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
  440. struct ocfs2_alloc_context **ac)
  441. {
  442. int status;
  443. *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
  444. if (!(*ac)) {
  445. status = -ENOMEM;
  446. mlog_errno(status);
  447. goto bail;
  448. }
  449. (*ac)->ac_bits_wanted = 1;
  450. (*ac)->ac_which = OCFS2_AC_USE_INODE;
  451. (*ac)->ac_group_search = ocfs2_block_group_search;
  452. status = ocfs2_reserve_suballoc_bits(osb, *ac,
  453. INODE_ALLOC_SYSTEM_INODE,
  454. osb->slot_num);
  455. if (status < 0) {
  456. if (status != -ENOSPC)
  457. mlog_errno(status);
  458. goto bail;
  459. }
  460. status = 0;
  461. bail:
  462. if ((status < 0) && *ac) {
  463. ocfs2_free_alloc_context(*ac);
  464. *ac = NULL;
  465. }
  466. mlog_exit(status);
  467. return status;
  468. }
  469. /* local alloc code has to do the same thing, so rather than do this
  470. * twice.. */
  471. int ocfs2_reserve_cluster_bitmap_bits(struct ocfs2_super *osb,
  472. struct ocfs2_alloc_context *ac)
  473. {
  474. int status;
  475. ac->ac_which = OCFS2_AC_USE_MAIN;
  476. ac->ac_group_search = ocfs2_cluster_group_search;
  477. status = ocfs2_reserve_suballoc_bits(osb, ac,
  478. GLOBAL_BITMAP_SYSTEM_INODE,
  479. OCFS2_INVALID_SLOT);
  480. if (status < 0 && status != -ENOSPC) {
  481. mlog_errno(status);
  482. goto bail;
  483. }
  484. bail:
  485. return status;
  486. }
  487. /* Callers don't need to care which bitmap (local alloc or main) to
  488. * use so we figure it out for them, but unfortunately this clutters
  489. * things a bit. */
  490. int ocfs2_reserve_clusters(struct ocfs2_super *osb,
  491. u32 bits_wanted,
  492. struct ocfs2_alloc_context **ac)
  493. {
  494. int status;
  495. mlog_entry_void();
  496. *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
  497. if (!(*ac)) {
  498. status = -ENOMEM;
  499. mlog_errno(status);
  500. goto bail;
  501. }
  502. (*ac)->ac_bits_wanted = bits_wanted;
  503. status = -ENOSPC;
  504. if (ocfs2_alloc_should_use_local(osb, bits_wanted)) {
  505. status = ocfs2_reserve_local_alloc_bits(osb,
  506. bits_wanted,
  507. *ac);
  508. if ((status < 0) && (status != -ENOSPC)) {
  509. mlog_errno(status);
  510. goto bail;
  511. } else if (status == -ENOSPC) {
  512. /* reserve_local_bits will return enospc with
  513. * the local alloc inode still locked, so we
  514. * can change this safely here. */
  515. mlog(0, "Disabling local alloc\n");
  516. /* We set to OCFS2_LA_DISABLED so that umount
  517. * can clean up what's left of the local
  518. * allocation */
  519. osb->local_alloc_state = OCFS2_LA_DISABLED;
  520. }
  521. }
  522. if (status == -ENOSPC) {
  523. status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac);
  524. if (status < 0) {
  525. if (status != -ENOSPC)
  526. mlog_errno(status);
  527. goto bail;
  528. }
  529. }
  530. status = 0;
  531. bail:
  532. if ((status < 0) && *ac) {
  533. ocfs2_free_alloc_context(*ac);
  534. *ac = NULL;
  535. }
  536. mlog_exit(status);
  537. return status;
  538. }
  539. /*
  540. * More or less lifted from ext3. I'll leave their description below:
  541. *
  542. * "For ext3 allocations, we must not reuse any blocks which are
  543. * allocated in the bitmap buffer's "last committed data" copy. This
  544. * prevents deletes from freeing up the page for reuse until we have
  545. * committed the delete transaction.
  546. *
  547. * If we didn't do this, then deleting something and reallocating it as
  548. * data would allow the old block to be overwritten before the
  549. * transaction committed (because we force data to disk before commit).
  550. * This would lead to corruption if we crashed between overwriting the
  551. * data and committing the delete.
  552. *
  553. * @@@ We may want to make this allocation behaviour conditional on
  554. * data-writes at some point, and disable it for metadata allocations or
  555. * sync-data inodes."
  556. *
  557. * Note: OCFS2 already does this differently for metadata vs data
  558. * allocations, as those bitmaps are seperate and undo access is never
  559. * called on a metadata group descriptor.
  560. */
  561. static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,
  562. int nr)
  563. {
  564. struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
  565. if (ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap))
  566. return 0;
  567. if (!buffer_jbd(bg_bh) || !bh2jh(bg_bh)->b_committed_data)
  568. return 1;
  569. bg = (struct ocfs2_group_desc *) bh2jh(bg_bh)->b_committed_data;
  570. return !ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap);
  571. }
  572. static int ocfs2_block_group_find_clear_bits(struct ocfs2_super *osb,
  573. struct buffer_head *bg_bh,
  574. unsigned int bits_wanted,
  575. unsigned int total_bits,
  576. u16 *bit_off,
  577. u16 *bits_found)
  578. {
  579. void *bitmap;
  580. u16 best_offset, best_size;
  581. int offset, start, found, status = 0;
  582. struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
  583. if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
  584. OCFS2_RO_ON_INVALID_GROUP_DESC(osb->sb, bg);
  585. return -EIO;
  586. }
  587. found = start = best_offset = best_size = 0;
  588. bitmap = bg->bg_bitmap;
  589. while((offset = ocfs2_find_next_zero_bit(bitmap, total_bits, start)) != -1) {
  590. if (offset == total_bits)
  591. break;
  592. if (!ocfs2_test_bg_bit_allocatable(bg_bh, offset)) {
  593. /* We found a zero, but we can't use it as it
  594. * hasn't been put to disk yet! */
  595. found = 0;
  596. start = offset + 1;
  597. } else if (offset == start) {
  598. /* we found a zero */
  599. found++;
  600. /* move start to the next bit to test */
  601. start++;
  602. } else {
  603. /* got a zero after some ones */
  604. found = 1;
  605. start = offset + 1;
  606. }
  607. if (found > best_size) {
  608. best_size = found;
  609. best_offset = start - found;
  610. }
  611. /* we got everything we needed */
  612. if (found == bits_wanted) {
  613. /* mlog(0, "Found it all!\n"); */
  614. break;
  615. }
  616. }
  617. /* XXX: I think the first clause is equivalent to the second
  618. * - jlbec */
  619. if (found == bits_wanted) {
  620. *bit_off = start - found;
  621. *bits_found = found;
  622. } else if (best_size) {
  623. *bit_off = best_offset;
  624. *bits_found = best_size;
  625. } else {
  626. status = -ENOSPC;
  627. /* No error log here -- see the comment above
  628. * ocfs2_test_bg_bit_allocatable */
  629. }
  630. return status;
  631. }
  632. static inline int ocfs2_block_group_set_bits(handle_t *handle,
  633. struct inode *alloc_inode,
  634. struct ocfs2_group_desc *bg,
  635. struct buffer_head *group_bh,
  636. unsigned int bit_off,
  637. unsigned int num_bits)
  638. {
  639. int status;
  640. void *bitmap = bg->bg_bitmap;
  641. int journal_type = OCFS2_JOURNAL_ACCESS_WRITE;
  642. mlog_entry_void();
  643. if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
  644. OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
  645. status = -EIO;
  646. goto bail;
  647. }
  648. BUG_ON(le16_to_cpu(bg->bg_free_bits_count) < num_bits);
  649. mlog(0, "block_group_set_bits: off = %u, num = %u\n", bit_off,
  650. num_bits);
  651. if (ocfs2_is_cluster_bitmap(alloc_inode))
  652. journal_type = OCFS2_JOURNAL_ACCESS_UNDO;
  653. status = ocfs2_journal_access(handle,
  654. alloc_inode,
  655. group_bh,
  656. journal_type);
  657. if (status < 0) {
  658. mlog_errno(status);
  659. goto bail;
  660. }
  661. le16_add_cpu(&bg->bg_free_bits_count, -num_bits);
  662. while(num_bits--)
  663. ocfs2_set_bit(bit_off++, bitmap);
  664. status = ocfs2_journal_dirty(handle,
  665. group_bh);
  666. if (status < 0) {
  667. mlog_errno(status);
  668. goto bail;
  669. }
  670. bail:
  671. mlog_exit(status);
  672. return status;
  673. }
  674. /* find the one with the most empty bits */
  675. static inline u16 ocfs2_find_victim_chain(struct ocfs2_chain_list *cl)
  676. {
  677. u16 curr, best;
  678. BUG_ON(!cl->cl_next_free_rec);
  679. best = curr = 0;
  680. while (curr < le16_to_cpu(cl->cl_next_free_rec)) {
  681. if (le32_to_cpu(cl->cl_recs[curr].c_free) >
  682. le32_to_cpu(cl->cl_recs[best].c_free))
  683. best = curr;
  684. curr++;
  685. }
  686. BUG_ON(best >= le16_to_cpu(cl->cl_next_free_rec));
  687. return best;
  688. }
  689. static int ocfs2_relink_block_group(handle_t *handle,
  690. struct inode *alloc_inode,
  691. struct buffer_head *fe_bh,
  692. struct buffer_head *bg_bh,
  693. struct buffer_head *prev_bg_bh,
  694. u16 chain)
  695. {
  696. int status;
  697. /* there is a really tiny chance the journal calls could fail,
  698. * but we wouldn't want inconsistent blocks in *any* case. */
  699. u64 fe_ptr, bg_ptr, prev_bg_ptr;
  700. struct ocfs2_dinode *fe = (struct ocfs2_dinode *) fe_bh->b_data;
  701. struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
  702. struct ocfs2_group_desc *prev_bg = (struct ocfs2_group_desc *) prev_bg_bh->b_data;
  703. if (!OCFS2_IS_VALID_DINODE(fe)) {
  704. OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe);
  705. status = -EIO;
  706. goto out;
  707. }
  708. if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
  709. OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
  710. status = -EIO;
  711. goto out;
  712. }
  713. if (!OCFS2_IS_VALID_GROUP_DESC(prev_bg)) {
  714. OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, prev_bg);
  715. status = -EIO;
  716. goto out;
  717. }
  718. mlog(0, "Suballoc %llu, chain %u, move group %llu to top, prev = %llu\n",
  719. (unsigned long long)le64_to_cpu(fe->i_blkno), chain,
  720. (unsigned long long)le64_to_cpu(bg->bg_blkno),
  721. (unsigned long long)le64_to_cpu(prev_bg->bg_blkno));
  722. fe_ptr = le64_to_cpu(fe->id2.i_chain.cl_recs[chain].c_blkno);
  723. bg_ptr = le64_to_cpu(bg->bg_next_group);
  724. prev_bg_ptr = le64_to_cpu(prev_bg->bg_next_group);
  725. status = ocfs2_journal_access(handle, alloc_inode, prev_bg_bh,
  726. OCFS2_JOURNAL_ACCESS_WRITE);
  727. if (status < 0) {
  728. mlog_errno(status);
  729. goto out_rollback;
  730. }
  731. prev_bg->bg_next_group = bg->bg_next_group;
  732. status = ocfs2_journal_dirty(handle, prev_bg_bh);
  733. if (status < 0) {
  734. mlog_errno(status);
  735. goto out_rollback;
  736. }
  737. status = ocfs2_journal_access(handle, alloc_inode, bg_bh,
  738. OCFS2_JOURNAL_ACCESS_WRITE);
  739. if (status < 0) {
  740. mlog_errno(status);
  741. goto out_rollback;
  742. }
  743. bg->bg_next_group = fe->id2.i_chain.cl_recs[chain].c_blkno;
  744. status = ocfs2_journal_dirty(handle, bg_bh);
  745. if (status < 0) {
  746. mlog_errno(status);
  747. goto out_rollback;
  748. }
  749. status = ocfs2_journal_access(handle, alloc_inode, fe_bh,
  750. OCFS2_JOURNAL_ACCESS_WRITE);
  751. if (status < 0) {
  752. mlog_errno(status);
  753. goto out_rollback;
  754. }
  755. fe->id2.i_chain.cl_recs[chain].c_blkno = bg->bg_blkno;
  756. status = ocfs2_journal_dirty(handle, fe_bh);
  757. if (status < 0) {
  758. mlog_errno(status);
  759. goto out_rollback;
  760. }
  761. status = 0;
  762. out_rollback:
  763. if (status < 0) {
  764. fe->id2.i_chain.cl_recs[chain].c_blkno = cpu_to_le64(fe_ptr);
  765. bg->bg_next_group = cpu_to_le64(bg_ptr);
  766. prev_bg->bg_next_group = cpu_to_le64(prev_bg_ptr);
  767. }
  768. out:
  769. mlog_exit(status);
  770. return status;
  771. }
  772. static inline int ocfs2_block_group_reasonably_empty(struct ocfs2_group_desc *bg,
  773. u32 wanted)
  774. {
  775. return le16_to_cpu(bg->bg_free_bits_count) > wanted;
  776. }
  777. /* return 0 on success, -ENOSPC to keep searching and any other < 0
  778. * value on error. */
  779. static int ocfs2_cluster_group_search(struct inode *inode,
  780. struct buffer_head *group_bh,
  781. u32 bits_wanted, u32 min_bits,
  782. u16 *bit_off, u16 *bits_found)
  783. {
  784. int search = -ENOSPC;
  785. int ret;
  786. struct ocfs2_group_desc *gd = (struct ocfs2_group_desc *) group_bh->b_data;
  787. u16 tmp_off, tmp_found;
  788. unsigned int max_bits, gd_cluster_off;
  789. BUG_ON(!ocfs2_is_cluster_bitmap(inode));
  790. if (gd->bg_free_bits_count) {
  791. max_bits = le16_to_cpu(gd->bg_bits);
  792. /* Tail groups in cluster bitmaps which aren't cpg
  793. * aligned are prone to partial extention by a failed
  794. * fs resize. If the file system resize never got to
  795. * update the dinode cluster count, then we don't want
  796. * to trust any clusters past it, regardless of what
  797. * the group descriptor says. */
  798. gd_cluster_off = ocfs2_blocks_to_clusters(inode->i_sb,
  799. le64_to_cpu(gd->bg_blkno));
  800. if ((gd_cluster_off + max_bits) >
  801. OCFS2_I(inode)->ip_clusters) {
  802. max_bits = OCFS2_I(inode)->ip_clusters - gd_cluster_off;
  803. mlog(0, "Desc %llu, bg_bits %u, clusters %u, use %u\n",
  804. (unsigned long long)le64_to_cpu(gd->bg_blkno),
  805. le16_to_cpu(gd->bg_bits),
  806. OCFS2_I(inode)->ip_clusters, max_bits);
  807. }
  808. ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb),
  809. group_bh, bits_wanted,
  810. max_bits,
  811. &tmp_off, &tmp_found);
  812. if (ret)
  813. return ret;
  814. /* ocfs2_block_group_find_clear_bits() might
  815. * return success, but we still want to return
  816. * -ENOSPC unless it found the minimum number
  817. * of bits. */
  818. if (min_bits <= tmp_found) {
  819. *bit_off = tmp_off;
  820. *bits_found = tmp_found;
  821. search = 0; /* success */
  822. }
  823. }
  824. return search;
  825. }
  826. static int ocfs2_block_group_search(struct inode *inode,
  827. struct buffer_head *group_bh,
  828. u32 bits_wanted, u32 min_bits,
  829. u16 *bit_off, u16 *bits_found)
  830. {
  831. int ret = -ENOSPC;
  832. struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) group_bh->b_data;
  833. BUG_ON(min_bits != 1);
  834. BUG_ON(ocfs2_is_cluster_bitmap(inode));
  835. if (bg->bg_free_bits_count)
  836. ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb),
  837. group_bh, bits_wanted,
  838. le16_to_cpu(bg->bg_bits),
  839. bit_off, bits_found);
  840. return ret;
  841. }
  842. static int ocfs2_alloc_dinode_update_counts(struct inode *inode,
  843. handle_t *handle,
  844. struct buffer_head *di_bh,
  845. u32 num_bits,
  846. u16 chain)
  847. {
  848. int ret;
  849. u32 tmp_used;
  850. struct ocfs2_dinode *di = (struct ocfs2_dinode *) di_bh->b_data;
  851. struct ocfs2_chain_list *cl = (struct ocfs2_chain_list *) &di->id2.i_chain;
  852. ret = ocfs2_journal_access(handle, inode, di_bh,
  853. OCFS2_JOURNAL_ACCESS_WRITE);
  854. if (ret < 0) {
  855. mlog_errno(ret);
  856. goto out;
  857. }
  858. tmp_used = le32_to_cpu(di->id1.bitmap1.i_used);
  859. di->id1.bitmap1.i_used = cpu_to_le32(num_bits + tmp_used);
  860. le32_add_cpu(&cl->cl_recs[chain].c_free, -num_bits);
  861. ret = ocfs2_journal_dirty(handle, di_bh);
  862. if (ret < 0)
  863. mlog_errno(ret);
  864. out:
  865. return ret;
  866. }
  867. static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac,
  868. handle_t *handle,
  869. u32 bits_wanted,
  870. u32 min_bits,
  871. u16 *bit_off,
  872. unsigned int *num_bits,
  873. u64 gd_blkno,
  874. u16 *bits_left)
  875. {
  876. int ret;
  877. u16 found;
  878. struct buffer_head *group_bh = NULL;
  879. struct ocfs2_group_desc *gd;
  880. struct inode *alloc_inode = ac->ac_inode;
  881. ret = ocfs2_read_block(OCFS2_SB(alloc_inode->i_sb), gd_blkno,
  882. &group_bh, OCFS2_BH_CACHED, alloc_inode);
  883. if (ret < 0) {
  884. mlog_errno(ret);
  885. return ret;
  886. }
  887. gd = (struct ocfs2_group_desc *) group_bh->b_data;
  888. if (!OCFS2_IS_VALID_GROUP_DESC(gd)) {
  889. OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, gd);
  890. ret = -EIO;
  891. goto out;
  892. }
  893. ret = ac->ac_group_search(alloc_inode, group_bh, bits_wanted, min_bits,
  894. bit_off, &found);
  895. if (ret < 0) {
  896. if (ret != -ENOSPC)
  897. mlog_errno(ret);
  898. goto out;
  899. }
  900. *num_bits = found;
  901. ret = ocfs2_alloc_dinode_update_counts(alloc_inode, handle, ac->ac_bh,
  902. *num_bits,
  903. le16_to_cpu(gd->bg_chain));
  904. if (ret < 0) {
  905. mlog_errno(ret);
  906. goto out;
  907. }
  908. ret = ocfs2_block_group_set_bits(handle, alloc_inode, gd, group_bh,
  909. *bit_off, *num_bits);
  910. if (ret < 0)
  911. mlog_errno(ret);
  912. *bits_left = le16_to_cpu(gd->bg_free_bits_count);
  913. out:
  914. brelse(group_bh);
  915. return ret;
  916. }
  917. static int ocfs2_search_chain(struct ocfs2_alloc_context *ac,
  918. handle_t *handle,
  919. u32 bits_wanted,
  920. u32 min_bits,
  921. u16 *bit_off,
  922. unsigned int *num_bits,
  923. u64 *bg_blkno,
  924. u16 *bits_left)
  925. {
  926. int status;
  927. u16 chain, tmp_bits;
  928. u32 tmp_used;
  929. u64 next_group;
  930. struct inode *alloc_inode = ac->ac_inode;
  931. struct buffer_head *group_bh = NULL;
  932. struct buffer_head *prev_group_bh = NULL;
  933. struct ocfs2_dinode *fe = (struct ocfs2_dinode *) ac->ac_bh->b_data;
  934. struct ocfs2_chain_list *cl = (struct ocfs2_chain_list *) &fe->id2.i_chain;
  935. struct ocfs2_group_desc *bg;
  936. chain = ac->ac_chain;
  937. mlog(0, "trying to alloc %u bits from chain %u, inode %llu\n",
  938. bits_wanted, chain,
  939. (unsigned long long)OCFS2_I(alloc_inode)->ip_blkno);
  940. status = ocfs2_read_block(OCFS2_SB(alloc_inode->i_sb),
  941. le64_to_cpu(cl->cl_recs[chain].c_blkno),
  942. &group_bh, OCFS2_BH_CACHED, alloc_inode);
  943. if (status < 0) {
  944. mlog_errno(status);
  945. goto bail;
  946. }
  947. bg = (struct ocfs2_group_desc *) group_bh->b_data;
  948. status = ocfs2_check_group_descriptor(alloc_inode->i_sb, fe, bg);
  949. if (status) {
  950. mlog_errno(status);
  951. goto bail;
  952. }
  953. status = -ENOSPC;
  954. /* for now, the chain search is a bit simplistic. We just use
  955. * the 1st group with any empty bits. */
  956. while ((status = ac->ac_group_search(alloc_inode, group_bh,
  957. bits_wanted, min_bits, bit_off,
  958. &tmp_bits)) == -ENOSPC) {
  959. if (!bg->bg_next_group)
  960. break;
  961. if (prev_group_bh) {
  962. brelse(prev_group_bh);
  963. prev_group_bh = NULL;
  964. }
  965. next_group = le64_to_cpu(bg->bg_next_group);
  966. prev_group_bh = group_bh;
  967. group_bh = NULL;
  968. status = ocfs2_read_block(OCFS2_SB(alloc_inode->i_sb),
  969. next_group, &group_bh,
  970. OCFS2_BH_CACHED, alloc_inode);
  971. if (status < 0) {
  972. mlog_errno(status);
  973. goto bail;
  974. }
  975. bg = (struct ocfs2_group_desc *) group_bh->b_data;
  976. status = ocfs2_check_group_descriptor(alloc_inode->i_sb, fe, bg);
  977. if (status) {
  978. mlog_errno(status);
  979. goto bail;
  980. }
  981. }
  982. if (status < 0) {
  983. if (status != -ENOSPC)
  984. mlog_errno(status);
  985. goto bail;
  986. }
  987. mlog(0, "alloc succeeds: we give %u bits from block group %llu\n",
  988. tmp_bits, (unsigned long long)le64_to_cpu(bg->bg_blkno));
  989. *num_bits = tmp_bits;
  990. BUG_ON(*num_bits == 0);
  991. /*
  992. * Keep track of previous block descriptor read. When
  993. * we find a target, if we have read more than X
  994. * number of descriptors, and the target is reasonably
  995. * empty, relink him to top of his chain.
  996. *
  997. * We've read 0 extra blocks and only send one more to
  998. * the transaction, yet the next guy to search has a
  999. * much easier time.
  1000. *
  1001. * Do this *after* figuring out how many bits we're taking out
  1002. * of our target group.
  1003. */
  1004. if (ac->ac_allow_chain_relink &&
  1005. (prev_group_bh) &&
  1006. (ocfs2_block_group_reasonably_empty(bg, *num_bits))) {
  1007. status = ocfs2_relink_block_group(handle, alloc_inode,
  1008. ac->ac_bh, group_bh,
  1009. prev_group_bh, chain);
  1010. if (status < 0) {
  1011. mlog_errno(status);
  1012. goto bail;
  1013. }
  1014. }
  1015. /* Ok, claim our bits now: set the info on dinode, chainlist
  1016. * and then the group */
  1017. status = ocfs2_journal_access(handle,
  1018. alloc_inode,
  1019. ac->ac_bh,
  1020. OCFS2_JOURNAL_ACCESS_WRITE);
  1021. if (status < 0) {
  1022. mlog_errno(status);
  1023. goto bail;
  1024. }
  1025. tmp_used = le32_to_cpu(fe->id1.bitmap1.i_used);
  1026. fe->id1.bitmap1.i_used = cpu_to_le32(*num_bits + tmp_used);
  1027. le32_add_cpu(&cl->cl_recs[chain].c_free, -(*num_bits));
  1028. status = ocfs2_journal_dirty(handle,
  1029. ac->ac_bh);
  1030. if (status < 0) {
  1031. mlog_errno(status);
  1032. goto bail;
  1033. }
  1034. status = ocfs2_block_group_set_bits(handle,
  1035. alloc_inode,
  1036. bg,
  1037. group_bh,
  1038. *bit_off,
  1039. *num_bits);
  1040. if (status < 0) {
  1041. mlog_errno(status);
  1042. goto bail;
  1043. }
  1044. mlog(0, "Allocated %u bits from suballocator %llu\n", *num_bits,
  1045. (unsigned long long)le64_to_cpu(fe->i_blkno));
  1046. *bg_blkno = le64_to_cpu(bg->bg_blkno);
  1047. *bits_left = le16_to_cpu(bg->bg_free_bits_count);
  1048. bail:
  1049. if (group_bh)
  1050. brelse(group_bh);
  1051. if (prev_group_bh)
  1052. brelse(prev_group_bh);
  1053. mlog_exit(status);
  1054. return status;
  1055. }
  1056. /* will give out up to bits_wanted contiguous bits. */
  1057. static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
  1058. struct ocfs2_alloc_context *ac,
  1059. handle_t *handle,
  1060. u32 bits_wanted,
  1061. u32 min_bits,
  1062. u16 *bit_off,
  1063. unsigned int *num_bits,
  1064. u64 *bg_blkno)
  1065. {
  1066. int status;
  1067. u16 victim, i;
  1068. u16 bits_left = 0;
  1069. u64 hint_blkno = ac->ac_last_group;
  1070. struct ocfs2_chain_list *cl;
  1071. struct ocfs2_dinode *fe;
  1072. mlog_entry_void();
  1073. BUG_ON(ac->ac_bits_given >= ac->ac_bits_wanted);
  1074. BUG_ON(bits_wanted > (ac->ac_bits_wanted - ac->ac_bits_given));
  1075. BUG_ON(!ac->ac_bh);
  1076. fe = (struct ocfs2_dinode *) ac->ac_bh->b_data;
  1077. if (!OCFS2_IS_VALID_DINODE(fe)) {
  1078. OCFS2_RO_ON_INVALID_DINODE(osb->sb, fe);
  1079. status = -EIO;
  1080. goto bail;
  1081. }
  1082. if (le32_to_cpu(fe->id1.bitmap1.i_used) >=
  1083. le32_to_cpu(fe->id1.bitmap1.i_total)) {
  1084. ocfs2_error(osb->sb, "Chain allocator dinode %llu has %u used "
  1085. "bits but only %u total.",
  1086. (unsigned long long)le64_to_cpu(fe->i_blkno),
  1087. le32_to_cpu(fe->id1.bitmap1.i_used),
  1088. le32_to_cpu(fe->id1.bitmap1.i_total));
  1089. status = -EIO;
  1090. goto bail;
  1091. }
  1092. if (hint_blkno) {
  1093. /* Attempt to short-circuit the usual search mechanism
  1094. * by jumping straight to the most recently used
  1095. * allocation group. This helps us mantain some
  1096. * contiguousness across allocations. */
  1097. status = ocfs2_search_one_group(ac, handle, bits_wanted,
  1098. min_bits, bit_off, num_bits,
  1099. hint_blkno, &bits_left);
  1100. if (!status) {
  1101. /* Be careful to update *bg_blkno here as the
  1102. * caller is expecting it to be filled in, and
  1103. * ocfs2_search_one_group() won't do that for
  1104. * us. */
  1105. *bg_blkno = hint_blkno;
  1106. goto set_hint;
  1107. }
  1108. if (status < 0 && status != -ENOSPC) {
  1109. mlog_errno(status);
  1110. goto bail;
  1111. }
  1112. }
  1113. cl = (struct ocfs2_chain_list *) &fe->id2.i_chain;
  1114. victim = ocfs2_find_victim_chain(cl);
  1115. ac->ac_chain = victim;
  1116. ac->ac_allow_chain_relink = 1;
  1117. status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits, bit_off,
  1118. num_bits, bg_blkno, &bits_left);
  1119. if (!status)
  1120. goto set_hint;
  1121. if (status < 0 && status != -ENOSPC) {
  1122. mlog_errno(status);
  1123. goto bail;
  1124. }
  1125. mlog(0, "Search of victim chain %u came up with nothing, "
  1126. "trying all chains now.\n", victim);
  1127. /* If we didn't pick a good victim, then just default to
  1128. * searching each chain in order. Don't allow chain relinking
  1129. * because we only calculate enough journal credits for one
  1130. * relink per alloc. */
  1131. ac->ac_allow_chain_relink = 0;
  1132. for (i = 0; i < le16_to_cpu(cl->cl_next_free_rec); i ++) {
  1133. if (i == victim)
  1134. continue;
  1135. if (!cl->cl_recs[i].c_free)
  1136. continue;
  1137. ac->ac_chain = i;
  1138. status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits,
  1139. bit_off, num_bits, bg_blkno,
  1140. &bits_left);
  1141. if (!status)
  1142. break;
  1143. if (status < 0 && status != -ENOSPC) {
  1144. mlog_errno(status);
  1145. goto bail;
  1146. }
  1147. }
  1148. set_hint:
  1149. if (status != -ENOSPC) {
  1150. /* If the next search of this group is not likely to
  1151. * yield a suitable extent, then we reset the last
  1152. * group hint so as to not waste a disk read */
  1153. if (bits_left < min_bits)
  1154. ac->ac_last_group = 0;
  1155. else
  1156. ac->ac_last_group = *bg_blkno;
  1157. }
  1158. bail:
  1159. mlog_exit(status);
  1160. return status;
  1161. }
  1162. int ocfs2_claim_metadata(struct ocfs2_super *osb,
  1163. handle_t *handle,
  1164. struct ocfs2_alloc_context *ac,
  1165. u32 bits_wanted,
  1166. u16 *suballoc_bit_start,
  1167. unsigned int *num_bits,
  1168. u64 *blkno_start)
  1169. {
  1170. int status;
  1171. u64 bg_blkno;
  1172. BUG_ON(!ac);
  1173. BUG_ON(ac->ac_bits_wanted < (ac->ac_bits_given + bits_wanted));
  1174. BUG_ON(ac->ac_which != OCFS2_AC_USE_META);
  1175. status = ocfs2_claim_suballoc_bits(osb,
  1176. ac,
  1177. handle,
  1178. bits_wanted,
  1179. 1,
  1180. suballoc_bit_start,
  1181. num_bits,
  1182. &bg_blkno);
  1183. if (status < 0) {
  1184. mlog_errno(status);
  1185. goto bail;
  1186. }
  1187. atomic_inc(&osb->alloc_stats.bg_allocs);
  1188. *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
  1189. ac->ac_bits_given += (*num_bits);
  1190. status = 0;
  1191. bail:
  1192. mlog_exit(status);
  1193. return status;
  1194. }
  1195. int ocfs2_claim_new_inode(struct ocfs2_super *osb,
  1196. handle_t *handle,
  1197. struct ocfs2_alloc_context *ac,
  1198. u16 *suballoc_bit,
  1199. u64 *fe_blkno)
  1200. {
  1201. int status;
  1202. unsigned int num_bits;
  1203. u64 bg_blkno;
  1204. mlog_entry_void();
  1205. BUG_ON(!ac);
  1206. BUG_ON(ac->ac_bits_given != 0);
  1207. BUG_ON(ac->ac_bits_wanted != 1);
  1208. BUG_ON(ac->ac_which != OCFS2_AC_USE_INODE);
  1209. status = ocfs2_claim_suballoc_bits(osb,
  1210. ac,
  1211. handle,
  1212. 1,
  1213. 1,
  1214. suballoc_bit,
  1215. &num_bits,
  1216. &bg_blkno);
  1217. if (status < 0) {
  1218. mlog_errno(status);
  1219. goto bail;
  1220. }
  1221. atomic_inc(&osb->alloc_stats.bg_allocs);
  1222. BUG_ON(num_bits != 1);
  1223. *fe_blkno = bg_blkno + (u64) (*suballoc_bit);
  1224. ac->ac_bits_given++;
  1225. status = 0;
  1226. bail:
  1227. mlog_exit(status);
  1228. return status;
  1229. }
  1230. /* translate a group desc. blkno and it's bitmap offset into
  1231. * disk cluster offset. */
  1232. static inline u32 ocfs2_desc_bitmap_to_cluster_off(struct inode *inode,
  1233. u64 bg_blkno,
  1234. u16 bg_bit_off)
  1235. {
  1236. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  1237. u32 cluster = 0;
  1238. BUG_ON(!ocfs2_is_cluster_bitmap(inode));
  1239. if (bg_blkno != osb->first_cluster_group_blkno)
  1240. cluster = ocfs2_blocks_to_clusters(inode->i_sb, bg_blkno);
  1241. cluster += (u32) bg_bit_off;
  1242. return cluster;
  1243. }
  1244. /* given a cluster offset, calculate which block group it belongs to
  1245. * and return that block offset. */
  1246. u64 ocfs2_which_cluster_group(struct inode *inode, u32 cluster)
  1247. {
  1248. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  1249. u32 group_no;
  1250. BUG_ON(!ocfs2_is_cluster_bitmap(inode));
  1251. group_no = cluster / osb->bitmap_cpg;
  1252. if (!group_no)
  1253. return osb->first_cluster_group_blkno;
  1254. return ocfs2_clusters_to_blocks(inode->i_sb,
  1255. group_no * osb->bitmap_cpg);
  1256. }
  1257. /* given the block number of a cluster start, calculate which cluster
  1258. * group and descriptor bitmap offset that corresponds to. */
  1259. static inline void ocfs2_block_to_cluster_group(struct inode *inode,
  1260. u64 data_blkno,
  1261. u64 *bg_blkno,
  1262. u16 *bg_bit_off)
  1263. {
  1264. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  1265. u32 data_cluster = ocfs2_blocks_to_clusters(osb->sb, data_blkno);
  1266. BUG_ON(!ocfs2_is_cluster_bitmap(inode));
  1267. *bg_blkno = ocfs2_which_cluster_group(inode,
  1268. data_cluster);
  1269. if (*bg_blkno == osb->first_cluster_group_blkno)
  1270. *bg_bit_off = (u16) data_cluster;
  1271. else
  1272. *bg_bit_off = (u16) ocfs2_blocks_to_clusters(osb->sb,
  1273. data_blkno - *bg_blkno);
  1274. }
  1275. /*
  1276. * min_bits - minimum contiguous chunk from this total allocation we
  1277. * can handle. set to what we asked for originally for a full
  1278. * contig. allocation, set to '1' to indicate we can deal with extents
  1279. * of any size.
  1280. */
  1281. int __ocfs2_claim_clusters(struct ocfs2_super *osb,
  1282. handle_t *handle,
  1283. struct ocfs2_alloc_context *ac,
  1284. u32 min_clusters,
  1285. u32 max_clusters,
  1286. u32 *cluster_start,
  1287. u32 *num_clusters)
  1288. {
  1289. int status;
  1290. unsigned int bits_wanted = max_clusters;
  1291. u64 bg_blkno = 0;
  1292. u16 bg_bit_off;
  1293. mlog_entry_void();
  1294. BUG_ON(ac->ac_bits_given >= ac->ac_bits_wanted);
  1295. BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL
  1296. && ac->ac_which != OCFS2_AC_USE_MAIN);
  1297. if (ac->ac_which == OCFS2_AC_USE_LOCAL) {
  1298. status = ocfs2_claim_local_alloc_bits(osb,
  1299. handle,
  1300. ac,
  1301. bits_wanted,
  1302. cluster_start,
  1303. num_clusters);
  1304. if (!status)
  1305. atomic_inc(&osb->alloc_stats.local_data);
  1306. } else {
  1307. if (min_clusters > (osb->bitmap_cpg - 1)) {
  1308. /* The only paths asking for contiguousness
  1309. * should know about this already. */
  1310. mlog(ML_ERROR, "minimum allocation requested %u exceeds "
  1311. "group bitmap size %u!\n", min_clusters,
  1312. osb->bitmap_cpg);
  1313. status = -ENOSPC;
  1314. goto bail;
  1315. }
  1316. /* clamp the current request down to a realistic size. */
  1317. if (bits_wanted > (osb->bitmap_cpg - 1))
  1318. bits_wanted = osb->bitmap_cpg - 1;
  1319. status = ocfs2_claim_suballoc_bits(osb,
  1320. ac,
  1321. handle,
  1322. bits_wanted,
  1323. min_clusters,
  1324. &bg_bit_off,
  1325. num_clusters,
  1326. &bg_blkno);
  1327. if (!status) {
  1328. *cluster_start =
  1329. ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
  1330. bg_blkno,
  1331. bg_bit_off);
  1332. atomic_inc(&osb->alloc_stats.bitmap_data);
  1333. }
  1334. }
  1335. if (status < 0) {
  1336. if (status != -ENOSPC)
  1337. mlog_errno(status);
  1338. goto bail;
  1339. }
  1340. ac->ac_bits_given += *num_clusters;
  1341. bail:
  1342. mlog_exit(status);
  1343. return status;
  1344. }
  1345. int ocfs2_claim_clusters(struct ocfs2_super *osb,
  1346. handle_t *handle,
  1347. struct ocfs2_alloc_context *ac,
  1348. u32 min_clusters,
  1349. u32 *cluster_start,
  1350. u32 *num_clusters)
  1351. {
  1352. unsigned int bits_wanted = ac->ac_bits_wanted - ac->ac_bits_given;
  1353. return __ocfs2_claim_clusters(osb, handle, ac, min_clusters,
  1354. bits_wanted, cluster_start, num_clusters);
  1355. }
  1356. static inline int ocfs2_block_group_clear_bits(handle_t *handle,
  1357. struct inode *alloc_inode,
  1358. struct ocfs2_group_desc *bg,
  1359. struct buffer_head *group_bh,
  1360. unsigned int bit_off,
  1361. unsigned int num_bits)
  1362. {
  1363. int status;
  1364. unsigned int tmp;
  1365. int journal_type = OCFS2_JOURNAL_ACCESS_WRITE;
  1366. struct ocfs2_group_desc *undo_bg = NULL;
  1367. mlog_entry_void();
  1368. if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
  1369. OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
  1370. status = -EIO;
  1371. goto bail;
  1372. }
  1373. mlog(0, "off = %u, num = %u\n", bit_off, num_bits);
  1374. if (ocfs2_is_cluster_bitmap(alloc_inode))
  1375. journal_type = OCFS2_JOURNAL_ACCESS_UNDO;
  1376. status = ocfs2_journal_access(handle, alloc_inode, group_bh,
  1377. journal_type);
  1378. if (status < 0) {
  1379. mlog_errno(status);
  1380. goto bail;
  1381. }
  1382. if (ocfs2_is_cluster_bitmap(alloc_inode))
  1383. undo_bg = (struct ocfs2_group_desc *) bh2jh(group_bh)->b_committed_data;
  1384. tmp = num_bits;
  1385. while(tmp--) {
  1386. ocfs2_clear_bit((bit_off + tmp),
  1387. (unsigned long *) bg->bg_bitmap);
  1388. if (ocfs2_is_cluster_bitmap(alloc_inode))
  1389. ocfs2_set_bit(bit_off + tmp,
  1390. (unsigned long *) undo_bg->bg_bitmap);
  1391. }
  1392. le16_add_cpu(&bg->bg_free_bits_count, num_bits);
  1393. status = ocfs2_journal_dirty(handle, group_bh);
  1394. if (status < 0)
  1395. mlog_errno(status);
  1396. bail:
  1397. return status;
  1398. }
  1399. /*
  1400. * expects the suballoc inode to already be locked.
  1401. */
  1402. int ocfs2_free_suballoc_bits(handle_t *handle,
  1403. struct inode *alloc_inode,
  1404. struct buffer_head *alloc_bh,
  1405. unsigned int start_bit,
  1406. u64 bg_blkno,
  1407. unsigned int count)
  1408. {
  1409. int status = 0;
  1410. u32 tmp_used;
  1411. struct ocfs2_super *osb = OCFS2_SB(alloc_inode->i_sb);
  1412. struct ocfs2_dinode *fe = (struct ocfs2_dinode *) alloc_bh->b_data;
  1413. struct ocfs2_chain_list *cl = &fe->id2.i_chain;
  1414. struct buffer_head *group_bh = NULL;
  1415. struct ocfs2_group_desc *group;
  1416. mlog_entry_void();
  1417. if (!OCFS2_IS_VALID_DINODE(fe)) {
  1418. OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe);
  1419. status = -EIO;
  1420. goto bail;
  1421. }
  1422. BUG_ON((count + start_bit) > ocfs2_bits_per_group(cl));
  1423. mlog(0, "%llu: freeing %u bits from group %llu, starting at %u\n",
  1424. (unsigned long long)OCFS2_I(alloc_inode)->ip_blkno, count,
  1425. (unsigned long long)bg_blkno, start_bit);
  1426. status = ocfs2_read_block(osb, bg_blkno, &group_bh, OCFS2_BH_CACHED,
  1427. alloc_inode);
  1428. if (status < 0) {
  1429. mlog_errno(status);
  1430. goto bail;
  1431. }
  1432. group = (struct ocfs2_group_desc *) group_bh->b_data;
  1433. status = ocfs2_check_group_descriptor(alloc_inode->i_sb, fe, group);
  1434. if (status) {
  1435. mlog_errno(status);
  1436. goto bail;
  1437. }
  1438. BUG_ON((count + start_bit) > le16_to_cpu(group->bg_bits));
  1439. status = ocfs2_block_group_clear_bits(handle, alloc_inode,
  1440. group, group_bh,
  1441. start_bit, count);
  1442. if (status < 0) {
  1443. mlog_errno(status);
  1444. goto bail;
  1445. }
  1446. status = ocfs2_journal_access(handle, alloc_inode, alloc_bh,
  1447. OCFS2_JOURNAL_ACCESS_WRITE);
  1448. if (status < 0) {
  1449. mlog_errno(status);
  1450. goto bail;
  1451. }
  1452. le32_add_cpu(&cl->cl_recs[le16_to_cpu(group->bg_chain)].c_free,
  1453. count);
  1454. tmp_used = le32_to_cpu(fe->id1.bitmap1.i_used);
  1455. fe->id1.bitmap1.i_used = cpu_to_le32(tmp_used - count);
  1456. status = ocfs2_journal_dirty(handle, alloc_bh);
  1457. if (status < 0) {
  1458. mlog_errno(status);
  1459. goto bail;
  1460. }
  1461. bail:
  1462. if (group_bh)
  1463. brelse(group_bh);
  1464. mlog_exit(status);
  1465. return status;
  1466. }
  1467. int ocfs2_free_dinode(handle_t *handle,
  1468. struct inode *inode_alloc_inode,
  1469. struct buffer_head *inode_alloc_bh,
  1470. struct ocfs2_dinode *di)
  1471. {
  1472. u64 blk = le64_to_cpu(di->i_blkno);
  1473. u16 bit = le16_to_cpu(di->i_suballoc_bit);
  1474. u64 bg_blkno = ocfs2_which_suballoc_group(blk, bit);
  1475. return ocfs2_free_suballoc_bits(handle, inode_alloc_inode,
  1476. inode_alloc_bh, bit, bg_blkno, 1);
  1477. }
  1478. int ocfs2_free_clusters(handle_t *handle,
  1479. struct inode *bitmap_inode,
  1480. struct buffer_head *bitmap_bh,
  1481. u64 start_blk,
  1482. unsigned int num_clusters)
  1483. {
  1484. int status;
  1485. u16 bg_start_bit;
  1486. u64 bg_blkno;
  1487. struct ocfs2_dinode *fe;
  1488. /* You can't ever have a contiguous set of clusters
  1489. * bigger than a block group bitmap so we never have to worry
  1490. * about looping on them. */
  1491. mlog_entry_void();
  1492. /* This is expensive. We can safely remove once this stuff has
  1493. * gotten tested really well. */
  1494. BUG_ON(start_blk != ocfs2_clusters_to_blocks(bitmap_inode->i_sb, ocfs2_blocks_to_clusters(bitmap_inode->i_sb, start_blk)));
  1495. fe = (struct ocfs2_dinode *) bitmap_bh->b_data;
  1496. ocfs2_block_to_cluster_group(bitmap_inode, start_blk, &bg_blkno,
  1497. &bg_start_bit);
  1498. mlog(0, "want to free %u clusters starting at block %llu\n",
  1499. num_clusters, (unsigned long long)start_blk);
  1500. mlog(0, "bg_blkno = %llu, bg_start_bit = %u\n",
  1501. (unsigned long long)bg_blkno, bg_start_bit);
  1502. status = ocfs2_free_suballoc_bits(handle, bitmap_inode, bitmap_bh,
  1503. bg_start_bit, bg_blkno,
  1504. num_clusters);
  1505. if (status < 0)
  1506. mlog_errno(status);
  1507. mlog_exit(status);
  1508. return status;
  1509. }
  1510. static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg)
  1511. {
  1512. printk("Block Group:\n");
  1513. printk("bg_signature: %s\n", bg->bg_signature);
  1514. printk("bg_size: %u\n", bg->bg_size);
  1515. printk("bg_bits: %u\n", bg->bg_bits);
  1516. printk("bg_free_bits_count: %u\n", bg->bg_free_bits_count);
  1517. printk("bg_chain: %u\n", bg->bg_chain);
  1518. printk("bg_generation: %u\n", le32_to_cpu(bg->bg_generation));
  1519. printk("bg_next_group: %llu\n",
  1520. (unsigned long long)bg->bg_next_group);
  1521. printk("bg_parent_dinode: %llu\n",
  1522. (unsigned long long)bg->bg_parent_dinode);
  1523. printk("bg_blkno: %llu\n",
  1524. (unsigned long long)bg->bg_blkno);
  1525. }
  1526. static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe)
  1527. {
  1528. int i;
  1529. printk("Suballoc Inode %llu:\n", (unsigned long long)fe->i_blkno);
  1530. printk("i_signature: %s\n", fe->i_signature);
  1531. printk("i_size: %llu\n",
  1532. (unsigned long long)fe->i_size);
  1533. printk("i_clusters: %u\n", fe->i_clusters);
  1534. printk("i_generation: %u\n",
  1535. le32_to_cpu(fe->i_generation));
  1536. printk("id1.bitmap1.i_used: %u\n",
  1537. le32_to_cpu(fe->id1.bitmap1.i_used));
  1538. printk("id1.bitmap1.i_total: %u\n",
  1539. le32_to_cpu(fe->id1.bitmap1.i_total));
  1540. printk("id2.i_chain.cl_cpg: %u\n", fe->id2.i_chain.cl_cpg);
  1541. printk("id2.i_chain.cl_bpc: %u\n", fe->id2.i_chain.cl_bpc);
  1542. printk("id2.i_chain.cl_count: %u\n", fe->id2.i_chain.cl_count);
  1543. printk("id2.i_chain.cl_next_free_rec: %u\n",
  1544. fe->id2.i_chain.cl_next_free_rec);
  1545. for(i = 0; i < fe->id2.i_chain.cl_next_free_rec; i++) {
  1546. printk("fe->id2.i_chain.cl_recs[%d].c_free: %u\n", i,
  1547. fe->id2.i_chain.cl_recs[i].c_free);
  1548. printk("fe->id2.i_chain.cl_recs[%d].c_total: %u\n", i,
  1549. fe->id2.i_chain.cl_recs[i].c_total);
  1550. printk("fe->id2.i_chain.cl_recs[%d].c_blkno: %llu\n", i,
  1551. (unsigned long long)fe->id2.i_chain.cl_recs[i].c_blkno);
  1552. }
  1553. }