suballoc.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  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 exceeds "
  1311. "group bitmap size!");
  1312. status = -ENOSPC;
  1313. goto bail;
  1314. }
  1315. /* clamp the current request down to a realistic size. */
  1316. if (bits_wanted > (osb->bitmap_cpg - 1))
  1317. bits_wanted = osb->bitmap_cpg - 1;
  1318. status = ocfs2_claim_suballoc_bits(osb,
  1319. ac,
  1320. handle,
  1321. bits_wanted,
  1322. min_clusters,
  1323. &bg_bit_off,
  1324. num_clusters,
  1325. &bg_blkno);
  1326. if (!status) {
  1327. *cluster_start =
  1328. ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
  1329. bg_blkno,
  1330. bg_bit_off);
  1331. atomic_inc(&osb->alloc_stats.bitmap_data);
  1332. }
  1333. }
  1334. if (status < 0) {
  1335. if (status != -ENOSPC)
  1336. mlog_errno(status);
  1337. goto bail;
  1338. }
  1339. ac->ac_bits_given += *num_clusters;
  1340. bail:
  1341. mlog_exit(status);
  1342. return status;
  1343. }
  1344. int ocfs2_claim_clusters(struct ocfs2_super *osb,
  1345. handle_t *handle,
  1346. struct ocfs2_alloc_context *ac,
  1347. u32 min_clusters,
  1348. u32 *cluster_start,
  1349. u32 *num_clusters)
  1350. {
  1351. unsigned int bits_wanted = ac->ac_bits_wanted - ac->ac_bits_given;
  1352. return __ocfs2_claim_clusters(osb, handle, ac, min_clusters,
  1353. bits_wanted, cluster_start, num_clusters);
  1354. }
  1355. static inline int ocfs2_block_group_clear_bits(handle_t *handle,
  1356. struct inode *alloc_inode,
  1357. struct ocfs2_group_desc *bg,
  1358. struct buffer_head *group_bh,
  1359. unsigned int bit_off,
  1360. unsigned int num_bits)
  1361. {
  1362. int status;
  1363. unsigned int tmp;
  1364. int journal_type = OCFS2_JOURNAL_ACCESS_WRITE;
  1365. struct ocfs2_group_desc *undo_bg = NULL;
  1366. mlog_entry_void();
  1367. if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
  1368. OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
  1369. status = -EIO;
  1370. goto bail;
  1371. }
  1372. mlog(0, "off = %u, num = %u\n", bit_off, num_bits);
  1373. if (ocfs2_is_cluster_bitmap(alloc_inode))
  1374. journal_type = OCFS2_JOURNAL_ACCESS_UNDO;
  1375. status = ocfs2_journal_access(handle, alloc_inode, group_bh,
  1376. journal_type);
  1377. if (status < 0) {
  1378. mlog_errno(status);
  1379. goto bail;
  1380. }
  1381. if (ocfs2_is_cluster_bitmap(alloc_inode))
  1382. undo_bg = (struct ocfs2_group_desc *) bh2jh(group_bh)->b_committed_data;
  1383. tmp = num_bits;
  1384. while(tmp--) {
  1385. ocfs2_clear_bit((bit_off + tmp),
  1386. (unsigned long *) bg->bg_bitmap);
  1387. if (ocfs2_is_cluster_bitmap(alloc_inode))
  1388. ocfs2_set_bit(bit_off + tmp,
  1389. (unsigned long *) undo_bg->bg_bitmap);
  1390. }
  1391. le16_add_cpu(&bg->bg_free_bits_count, num_bits);
  1392. status = ocfs2_journal_dirty(handle, group_bh);
  1393. if (status < 0)
  1394. mlog_errno(status);
  1395. bail:
  1396. return status;
  1397. }
  1398. /*
  1399. * expects the suballoc inode to already be locked.
  1400. */
  1401. int ocfs2_free_suballoc_bits(handle_t *handle,
  1402. struct inode *alloc_inode,
  1403. struct buffer_head *alloc_bh,
  1404. unsigned int start_bit,
  1405. u64 bg_blkno,
  1406. unsigned int count)
  1407. {
  1408. int status = 0;
  1409. u32 tmp_used;
  1410. struct ocfs2_super *osb = OCFS2_SB(alloc_inode->i_sb);
  1411. struct ocfs2_dinode *fe = (struct ocfs2_dinode *) alloc_bh->b_data;
  1412. struct ocfs2_chain_list *cl = &fe->id2.i_chain;
  1413. struct buffer_head *group_bh = NULL;
  1414. struct ocfs2_group_desc *group;
  1415. mlog_entry_void();
  1416. if (!OCFS2_IS_VALID_DINODE(fe)) {
  1417. OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe);
  1418. status = -EIO;
  1419. goto bail;
  1420. }
  1421. BUG_ON((count + start_bit) > ocfs2_bits_per_group(cl));
  1422. mlog(0, "%llu: freeing %u bits from group %llu, starting at %u\n",
  1423. (unsigned long long)OCFS2_I(alloc_inode)->ip_blkno, count,
  1424. (unsigned long long)bg_blkno, start_bit);
  1425. status = ocfs2_read_block(osb, bg_blkno, &group_bh, OCFS2_BH_CACHED,
  1426. alloc_inode);
  1427. if (status < 0) {
  1428. mlog_errno(status);
  1429. goto bail;
  1430. }
  1431. group = (struct ocfs2_group_desc *) group_bh->b_data;
  1432. status = ocfs2_check_group_descriptor(alloc_inode->i_sb, fe, group);
  1433. if (status) {
  1434. mlog_errno(status);
  1435. goto bail;
  1436. }
  1437. BUG_ON((count + start_bit) > le16_to_cpu(group->bg_bits));
  1438. status = ocfs2_block_group_clear_bits(handle, alloc_inode,
  1439. group, group_bh,
  1440. start_bit, count);
  1441. if (status < 0) {
  1442. mlog_errno(status);
  1443. goto bail;
  1444. }
  1445. status = ocfs2_journal_access(handle, alloc_inode, alloc_bh,
  1446. OCFS2_JOURNAL_ACCESS_WRITE);
  1447. if (status < 0) {
  1448. mlog_errno(status);
  1449. goto bail;
  1450. }
  1451. le32_add_cpu(&cl->cl_recs[le16_to_cpu(group->bg_chain)].c_free,
  1452. count);
  1453. tmp_used = le32_to_cpu(fe->id1.bitmap1.i_used);
  1454. fe->id1.bitmap1.i_used = cpu_to_le32(tmp_used - count);
  1455. status = ocfs2_journal_dirty(handle, alloc_bh);
  1456. if (status < 0) {
  1457. mlog_errno(status);
  1458. goto bail;
  1459. }
  1460. bail:
  1461. if (group_bh)
  1462. brelse(group_bh);
  1463. mlog_exit(status);
  1464. return status;
  1465. }
  1466. int ocfs2_free_dinode(handle_t *handle,
  1467. struct inode *inode_alloc_inode,
  1468. struct buffer_head *inode_alloc_bh,
  1469. struct ocfs2_dinode *di)
  1470. {
  1471. u64 blk = le64_to_cpu(di->i_blkno);
  1472. u16 bit = le16_to_cpu(di->i_suballoc_bit);
  1473. u64 bg_blkno = ocfs2_which_suballoc_group(blk, bit);
  1474. return ocfs2_free_suballoc_bits(handle, inode_alloc_inode,
  1475. inode_alloc_bh, bit, bg_blkno, 1);
  1476. }
  1477. int ocfs2_free_clusters(handle_t *handle,
  1478. struct inode *bitmap_inode,
  1479. struct buffer_head *bitmap_bh,
  1480. u64 start_blk,
  1481. unsigned int num_clusters)
  1482. {
  1483. int status;
  1484. u16 bg_start_bit;
  1485. u64 bg_blkno;
  1486. struct ocfs2_dinode *fe;
  1487. /* You can't ever have a contiguous set of clusters
  1488. * bigger than a block group bitmap so we never have to worry
  1489. * about looping on them. */
  1490. mlog_entry_void();
  1491. /* This is expensive. We can safely remove once this stuff has
  1492. * gotten tested really well. */
  1493. BUG_ON(start_blk != ocfs2_clusters_to_blocks(bitmap_inode->i_sb, ocfs2_blocks_to_clusters(bitmap_inode->i_sb, start_blk)));
  1494. fe = (struct ocfs2_dinode *) bitmap_bh->b_data;
  1495. ocfs2_block_to_cluster_group(bitmap_inode, start_blk, &bg_blkno,
  1496. &bg_start_bit);
  1497. mlog(0, "want to free %u clusters starting at block %llu\n",
  1498. num_clusters, (unsigned long long)start_blk);
  1499. mlog(0, "bg_blkno = %llu, bg_start_bit = %u\n",
  1500. (unsigned long long)bg_blkno, bg_start_bit);
  1501. status = ocfs2_free_suballoc_bits(handle, bitmap_inode, bitmap_bh,
  1502. bg_start_bit, bg_blkno,
  1503. num_clusters);
  1504. if (status < 0)
  1505. mlog_errno(status);
  1506. mlog_exit(status);
  1507. return status;
  1508. }
  1509. static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg)
  1510. {
  1511. printk("Block Group:\n");
  1512. printk("bg_signature: %s\n", bg->bg_signature);
  1513. printk("bg_size: %u\n", bg->bg_size);
  1514. printk("bg_bits: %u\n", bg->bg_bits);
  1515. printk("bg_free_bits_count: %u\n", bg->bg_free_bits_count);
  1516. printk("bg_chain: %u\n", bg->bg_chain);
  1517. printk("bg_generation: %u\n", le32_to_cpu(bg->bg_generation));
  1518. printk("bg_next_group: %llu\n",
  1519. (unsigned long long)bg->bg_next_group);
  1520. printk("bg_parent_dinode: %llu\n",
  1521. (unsigned long long)bg->bg_parent_dinode);
  1522. printk("bg_blkno: %llu\n",
  1523. (unsigned long long)bg->bg_blkno);
  1524. }
  1525. static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe)
  1526. {
  1527. int i;
  1528. printk("Suballoc Inode %llu:\n", (unsigned long long)fe->i_blkno);
  1529. printk("i_signature: %s\n", fe->i_signature);
  1530. printk("i_size: %llu\n",
  1531. (unsigned long long)fe->i_size);
  1532. printk("i_clusters: %u\n", fe->i_clusters);
  1533. printk("i_generation: %u\n",
  1534. le32_to_cpu(fe->i_generation));
  1535. printk("id1.bitmap1.i_used: %u\n",
  1536. le32_to_cpu(fe->id1.bitmap1.i_used));
  1537. printk("id1.bitmap1.i_total: %u\n",
  1538. le32_to_cpu(fe->id1.bitmap1.i_total));
  1539. printk("id2.i_chain.cl_cpg: %u\n", fe->id2.i_chain.cl_cpg);
  1540. printk("id2.i_chain.cl_bpc: %u\n", fe->id2.i_chain.cl_bpc);
  1541. printk("id2.i_chain.cl_count: %u\n", fe->id2.i_chain.cl_count);
  1542. printk("id2.i_chain.cl_next_free_rec: %u\n",
  1543. fe->id2.i_chain.cl_next_free_rec);
  1544. for(i = 0; i < fe->id2.i_chain.cl_next_free_rec; i++) {
  1545. printk("fe->id2.i_chain.cl_recs[%d].c_free: %u\n", i,
  1546. fe->id2.i_chain.cl_recs[i].c_free);
  1547. printk("fe->id2.i_chain.cl_recs[%d].c_total: %u\n", i,
  1548. fe->id2.i_chain.cl_recs[i].c_total);
  1549. printk("fe->id2.i_chain.cl_recs[%d].c_blkno: %llu\n", i,
  1550. (unsigned long long)fe->id2.i_chain.cl_recs[i].c_blkno);
  1551. }
  1552. }