suballoc.c 47 KB

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