resize.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * resize.c
  5. *
  6. * volume resize.
  7. * Inspired by ext3/resize.c.
  8. *
  9. * Copyright (C) 2007 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 <cluster/masklog.h>
  29. #include "ocfs2.h"
  30. #include "alloc.h"
  31. #include "dlmglue.h"
  32. #include "inode.h"
  33. #include "journal.h"
  34. #include "super.h"
  35. #include "sysfile.h"
  36. #include "uptodate.h"
  37. #include "ocfs2_trace.h"
  38. #include "buffer_head_io.h"
  39. #include "suballoc.h"
  40. #include "resize.h"
  41. /*
  42. * Check whether there are new backup superblocks exist
  43. * in the last group. If there are some, mark them or clear
  44. * them in the bitmap.
  45. *
  46. * Return how many backups we find in the last group.
  47. */
  48. static u16 ocfs2_calc_new_backup_super(struct inode *inode,
  49. struct ocfs2_group_desc *gd,
  50. int new_clusters,
  51. u32 first_new_cluster,
  52. u16 cl_cpg,
  53. u16 old_bg_clusters,
  54. int set)
  55. {
  56. int i;
  57. u16 backups = 0;
  58. u32 cluster, lgd_cluster;
  59. u64 blkno, gd_blkno, lgd_blkno = le64_to_cpu(gd->bg_blkno);
  60. for (i = 0; i < OCFS2_MAX_BACKUP_SUPERBLOCKS; i++) {
  61. blkno = ocfs2_backup_super_blkno(inode->i_sb, i);
  62. cluster = ocfs2_blocks_to_clusters(inode->i_sb, blkno);
  63. gd_blkno = ocfs2_which_cluster_group(inode, cluster);
  64. if (gd_blkno < lgd_blkno)
  65. continue;
  66. else if (gd_blkno > lgd_blkno)
  67. break;
  68. /* check if already done backup super */
  69. lgd_cluster = ocfs2_blocks_to_clusters(inode->i_sb, lgd_blkno);
  70. lgd_cluster += old_bg_clusters;
  71. if (lgd_cluster >= cluster)
  72. continue;
  73. if (set)
  74. ocfs2_set_bit(cluster % cl_cpg,
  75. (unsigned long *)gd->bg_bitmap);
  76. else
  77. ocfs2_clear_bit(cluster % cl_cpg,
  78. (unsigned long *)gd->bg_bitmap);
  79. backups++;
  80. }
  81. return backups;
  82. }
  83. static int ocfs2_update_last_group_and_inode(handle_t *handle,
  84. struct inode *bm_inode,
  85. struct buffer_head *bm_bh,
  86. struct buffer_head *group_bh,
  87. u32 first_new_cluster,
  88. int new_clusters)
  89. {
  90. int ret = 0;
  91. struct ocfs2_super *osb = OCFS2_SB(bm_inode->i_sb);
  92. struct ocfs2_dinode *fe = (struct ocfs2_dinode *) bm_bh->b_data;
  93. struct ocfs2_chain_list *cl = &fe->id2.i_chain;
  94. struct ocfs2_chain_rec *cr;
  95. struct ocfs2_group_desc *group;
  96. u16 chain, num_bits, backups = 0;
  97. u16 cl_bpc = le16_to_cpu(cl->cl_bpc);
  98. u16 cl_cpg = le16_to_cpu(cl->cl_cpg);
  99. u16 old_bg_clusters;
  100. trace_ocfs2_update_last_group_and_inode(new_clusters,
  101. first_new_cluster);
  102. ret = ocfs2_journal_access_gd(handle, INODE_CACHE(bm_inode),
  103. group_bh, OCFS2_JOURNAL_ACCESS_WRITE);
  104. if (ret < 0) {
  105. mlog_errno(ret);
  106. goto out;
  107. }
  108. group = (struct ocfs2_group_desc *)group_bh->b_data;
  109. old_bg_clusters = le16_to_cpu(group->bg_bits) / cl_bpc;
  110. /* update the group first. */
  111. num_bits = new_clusters * cl_bpc;
  112. le16_add_cpu(&group->bg_bits, num_bits);
  113. le16_add_cpu(&group->bg_free_bits_count, num_bits);
  114. /*
  115. * check whether there are some new backup superblocks exist in
  116. * this group and update the group bitmap accordingly.
  117. */
  118. if (OCFS2_HAS_COMPAT_FEATURE(osb->sb,
  119. OCFS2_FEATURE_COMPAT_BACKUP_SB)) {
  120. backups = ocfs2_calc_new_backup_super(bm_inode,
  121. group,
  122. new_clusters,
  123. first_new_cluster,
  124. cl_cpg, old_bg_clusters, 1);
  125. le16_add_cpu(&group->bg_free_bits_count, -1 * backups);
  126. }
  127. ocfs2_journal_dirty(handle, group_bh);
  128. /* update the inode accordingly. */
  129. ret = ocfs2_journal_access_di(handle, INODE_CACHE(bm_inode), bm_bh,
  130. OCFS2_JOURNAL_ACCESS_WRITE);
  131. if (ret < 0) {
  132. mlog_errno(ret);
  133. goto out_rollback;
  134. }
  135. chain = le16_to_cpu(group->bg_chain);
  136. cr = (&cl->cl_recs[chain]);
  137. le32_add_cpu(&cr->c_total, num_bits);
  138. le32_add_cpu(&cr->c_free, num_bits);
  139. le32_add_cpu(&fe->id1.bitmap1.i_total, num_bits);
  140. le32_add_cpu(&fe->i_clusters, new_clusters);
  141. if (backups) {
  142. le32_add_cpu(&cr->c_free, -1 * backups);
  143. le32_add_cpu(&fe->id1.bitmap1.i_used, backups);
  144. }
  145. spin_lock(&OCFS2_I(bm_inode)->ip_lock);
  146. OCFS2_I(bm_inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
  147. le64_add_cpu(&fe->i_size, new_clusters << osb->s_clustersize_bits);
  148. spin_unlock(&OCFS2_I(bm_inode)->ip_lock);
  149. i_size_write(bm_inode, le64_to_cpu(fe->i_size));
  150. ocfs2_journal_dirty(handle, bm_bh);
  151. out_rollback:
  152. if (ret < 0) {
  153. ocfs2_calc_new_backup_super(bm_inode,
  154. group,
  155. new_clusters,
  156. first_new_cluster,
  157. cl_cpg, old_bg_clusters, 0);
  158. le16_add_cpu(&group->bg_free_bits_count, backups);
  159. le16_add_cpu(&group->bg_bits, -1 * num_bits);
  160. le16_add_cpu(&group->bg_free_bits_count, -1 * num_bits);
  161. }
  162. out:
  163. if (ret)
  164. mlog_errno(ret);
  165. return ret;
  166. }
  167. static int update_backups(struct inode * inode, u32 clusters, char *data)
  168. {
  169. int i, ret = 0;
  170. u32 cluster;
  171. u64 blkno;
  172. struct buffer_head *backup = NULL;
  173. struct ocfs2_dinode *backup_di = NULL;
  174. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  175. /* calculate the real backups we need to update. */
  176. for (i = 0; i < OCFS2_MAX_BACKUP_SUPERBLOCKS; i++) {
  177. blkno = ocfs2_backup_super_blkno(inode->i_sb, i);
  178. cluster = ocfs2_blocks_to_clusters(inode->i_sb, blkno);
  179. if (cluster > clusters)
  180. break;
  181. ret = ocfs2_read_blocks_sync(osb, blkno, 1, &backup);
  182. if (ret < 0) {
  183. mlog_errno(ret);
  184. break;
  185. }
  186. memcpy(backup->b_data, data, inode->i_sb->s_blocksize);
  187. backup_di = (struct ocfs2_dinode *)backup->b_data;
  188. backup_di->i_blkno = cpu_to_le64(blkno);
  189. ret = ocfs2_write_super_or_backup(osb, backup);
  190. brelse(backup);
  191. backup = NULL;
  192. if (ret < 0) {
  193. mlog_errno(ret);
  194. break;
  195. }
  196. }
  197. return ret;
  198. }
  199. static void ocfs2_update_super_and_backups(struct inode *inode,
  200. int new_clusters)
  201. {
  202. int ret;
  203. u32 clusters = 0;
  204. struct buffer_head *super_bh = NULL;
  205. struct ocfs2_dinode *super_di = NULL;
  206. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  207. /*
  208. * update the superblock last.
  209. * It doesn't matter if the write failed.
  210. */
  211. ret = ocfs2_read_blocks_sync(osb, OCFS2_SUPER_BLOCK_BLKNO, 1,
  212. &super_bh);
  213. if (ret < 0) {
  214. mlog_errno(ret);
  215. goto out;
  216. }
  217. super_di = (struct ocfs2_dinode *)super_bh->b_data;
  218. le32_add_cpu(&super_di->i_clusters, new_clusters);
  219. clusters = le32_to_cpu(super_di->i_clusters);
  220. ret = ocfs2_write_super_or_backup(osb, super_bh);
  221. if (ret < 0) {
  222. mlog_errno(ret);
  223. goto out;
  224. }
  225. if (OCFS2_HAS_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_COMPAT_BACKUP_SB))
  226. ret = update_backups(inode, clusters, super_bh->b_data);
  227. out:
  228. brelse(super_bh);
  229. if (ret)
  230. printk(KERN_WARNING "ocfs2: Failed to update super blocks on %s"
  231. " during fs resize. This condition is not fatal,"
  232. " but fsck.ocfs2 should be run to fix it\n",
  233. osb->dev_str);
  234. return;
  235. }
  236. /*
  237. * Extend the filesystem to the new number of clusters specified. This entry
  238. * point is only used to extend the current filesystem to the end of the last
  239. * existing group.
  240. */
  241. int ocfs2_group_extend(struct inode * inode, int new_clusters)
  242. {
  243. int ret;
  244. handle_t *handle;
  245. struct buffer_head *main_bm_bh = NULL;
  246. struct buffer_head *group_bh = NULL;
  247. struct inode *main_bm_inode = NULL;
  248. struct ocfs2_dinode *fe = NULL;
  249. struct ocfs2_group_desc *group = NULL;
  250. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  251. u16 cl_bpc;
  252. u32 first_new_cluster;
  253. u64 lgd_blkno;
  254. if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
  255. return -EROFS;
  256. if (new_clusters < 0)
  257. return -EINVAL;
  258. else if (new_clusters == 0)
  259. return 0;
  260. main_bm_inode = ocfs2_get_system_file_inode(osb,
  261. GLOBAL_BITMAP_SYSTEM_INODE,
  262. OCFS2_INVALID_SLOT);
  263. if (!main_bm_inode) {
  264. ret = -EINVAL;
  265. mlog_errno(ret);
  266. goto out;
  267. }
  268. mutex_lock(&main_bm_inode->i_mutex);
  269. ret = ocfs2_inode_lock(main_bm_inode, &main_bm_bh, 1);
  270. if (ret < 0) {
  271. mlog_errno(ret);
  272. goto out_mutex;
  273. }
  274. fe = (struct ocfs2_dinode *)main_bm_bh->b_data;
  275. /* main_bm_bh is validated by inode read inside ocfs2_inode_lock(),
  276. * so any corruption is a code bug. */
  277. BUG_ON(!OCFS2_IS_VALID_DINODE(fe));
  278. if (le16_to_cpu(fe->id2.i_chain.cl_cpg) !=
  279. ocfs2_group_bitmap_size(osb->sb, 0,
  280. osb->s_feature_incompat) * 8) {
  281. mlog(ML_ERROR, "The disk is too old and small. "
  282. "Force to do offline resize.");
  283. ret = -EINVAL;
  284. goto out_unlock;
  285. }
  286. first_new_cluster = le32_to_cpu(fe->i_clusters);
  287. lgd_blkno = ocfs2_which_cluster_group(main_bm_inode,
  288. first_new_cluster - 1);
  289. ret = ocfs2_read_group_descriptor(main_bm_inode, fe, lgd_blkno,
  290. &group_bh);
  291. if (ret < 0) {
  292. mlog_errno(ret);
  293. goto out_unlock;
  294. }
  295. group = (struct ocfs2_group_desc *)group_bh->b_data;
  296. cl_bpc = le16_to_cpu(fe->id2.i_chain.cl_bpc);
  297. if (le16_to_cpu(group->bg_bits) / cl_bpc + new_clusters >
  298. le16_to_cpu(fe->id2.i_chain.cl_cpg)) {
  299. ret = -EINVAL;
  300. goto out_unlock;
  301. }
  302. trace_ocfs2_group_extend(
  303. (unsigned long long)le64_to_cpu(group->bg_blkno), new_clusters);
  304. handle = ocfs2_start_trans(osb, OCFS2_GROUP_EXTEND_CREDITS);
  305. if (IS_ERR(handle)) {
  306. mlog_errno(PTR_ERR(handle));
  307. ret = -EINVAL;
  308. goto out_unlock;
  309. }
  310. /* update the last group descriptor and inode. */
  311. ret = ocfs2_update_last_group_and_inode(handle, main_bm_inode,
  312. main_bm_bh, group_bh,
  313. first_new_cluster,
  314. new_clusters);
  315. if (ret) {
  316. mlog_errno(ret);
  317. goto out_commit;
  318. }
  319. ocfs2_update_super_and_backups(main_bm_inode, new_clusters);
  320. out_commit:
  321. ocfs2_commit_trans(osb, handle);
  322. out_unlock:
  323. brelse(group_bh);
  324. brelse(main_bm_bh);
  325. ocfs2_inode_unlock(main_bm_inode, 1);
  326. out_mutex:
  327. mutex_unlock(&main_bm_inode->i_mutex);
  328. iput(main_bm_inode);
  329. out:
  330. return ret;
  331. }
  332. static int ocfs2_check_new_group(struct inode *inode,
  333. struct ocfs2_dinode *di,
  334. struct ocfs2_new_group_input *input,
  335. struct buffer_head *group_bh)
  336. {
  337. int ret;
  338. struct ocfs2_group_desc *gd =
  339. (struct ocfs2_group_desc *)group_bh->b_data;
  340. u16 cl_bpc = le16_to_cpu(di->id2.i_chain.cl_bpc);
  341. ret = ocfs2_check_group_descriptor(inode->i_sb, di, group_bh);
  342. if (ret)
  343. goto out;
  344. ret = -EINVAL;
  345. if (le16_to_cpu(gd->bg_chain) != input->chain)
  346. mlog(ML_ERROR, "Group descriptor # %llu has bad chain %u "
  347. "while input has %u set.\n",
  348. (unsigned long long)le64_to_cpu(gd->bg_blkno),
  349. le16_to_cpu(gd->bg_chain), input->chain);
  350. else if (le16_to_cpu(gd->bg_bits) != input->clusters * cl_bpc)
  351. mlog(ML_ERROR, "Group descriptor # %llu has bit count %u but "
  352. "input has %u clusters set\n",
  353. (unsigned long long)le64_to_cpu(gd->bg_blkno),
  354. le16_to_cpu(gd->bg_bits), input->clusters);
  355. else if (le16_to_cpu(gd->bg_free_bits_count) != input->frees * cl_bpc)
  356. mlog(ML_ERROR, "Group descriptor # %llu has free bit count %u "
  357. "but it should have %u set\n",
  358. (unsigned long long)le64_to_cpu(gd->bg_blkno),
  359. le16_to_cpu(gd->bg_bits),
  360. input->frees * cl_bpc);
  361. else
  362. ret = 0;
  363. out:
  364. return ret;
  365. }
  366. static int ocfs2_verify_group_and_input(struct inode *inode,
  367. struct ocfs2_dinode *di,
  368. struct ocfs2_new_group_input *input,
  369. struct buffer_head *group_bh)
  370. {
  371. u16 cl_count = le16_to_cpu(di->id2.i_chain.cl_count);
  372. u16 cl_cpg = le16_to_cpu(di->id2.i_chain.cl_cpg);
  373. u16 next_free = le16_to_cpu(di->id2.i_chain.cl_next_free_rec);
  374. u32 cluster = ocfs2_blocks_to_clusters(inode->i_sb, input->group);
  375. u32 total_clusters = le32_to_cpu(di->i_clusters);
  376. int ret = -EINVAL;
  377. if (cluster < total_clusters)
  378. mlog(ML_ERROR, "add a group which is in the current volume.\n");
  379. else if (input->chain >= cl_count)
  380. mlog(ML_ERROR, "input chain exceeds the limit.\n");
  381. else if (next_free != cl_count && next_free != input->chain)
  382. mlog(ML_ERROR,
  383. "the add group should be in chain %u\n", next_free);
  384. else if (total_clusters + input->clusters < total_clusters)
  385. mlog(ML_ERROR, "add group's clusters overflow.\n");
  386. else if (input->clusters > cl_cpg)
  387. mlog(ML_ERROR, "the cluster exceeds the maximum of a group\n");
  388. else if (input->frees > input->clusters)
  389. mlog(ML_ERROR, "the free cluster exceeds the total clusters\n");
  390. else if (total_clusters % cl_cpg != 0)
  391. mlog(ML_ERROR,
  392. "the last group isn't full. Use group extend first.\n");
  393. else if (input->group != ocfs2_which_cluster_group(inode, cluster))
  394. mlog(ML_ERROR, "group blkno is invalid\n");
  395. else if ((ret = ocfs2_check_new_group(inode, di, input, group_bh)))
  396. mlog(ML_ERROR, "group descriptor check failed.\n");
  397. else
  398. ret = 0;
  399. return ret;
  400. }
  401. /* Add a new group descriptor to global_bitmap. */
  402. int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
  403. {
  404. int ret;
  405. handle_t *handle;
  406. struct buffer_head *main_bm_bh = NULL;
  407. struct inode *main_bm_inode = NULL;
  408. struct ocfs2_dinode *fe = NULL;
  409. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  410. struct buffer_head *group_bh = NULL;
  411. struct ocfs2_group_desc *group = NULL;
  412. struct ocfs2_chain_list *cl;
  413. struct ocfs2_chain_rec *cr;
  414. u16 cl_bpc;
  415. if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
  416. return -EROFS;
  417. main_bm_inode = ocfs2_get_system_file_inode(osb,
  418. GLOBAL_BITMAP_SYSTEM_INODE,
  419. OCFS2_INVALID_SLOT);
  420. if (!main_bm_inode) {
  421. ret = -EINVAL;
  422. mlog_errno(ret);
  423. goto out;
  424. }
  425. mutex_lock(&main_bm_inode->i_mutex);
  426. ret = ocfs2_inode_lock(main_bm_inode, &main_bm_bh, 1);
  427. if (ret < 0) {
  428. mlog_errno(ret);
  429. goto out_mutex;
  430. }
  431. fe = (struct ocfs2_dinode *)main_bm_bh->b_data;
  432. if (le16_to_cpu(fe->id2.i_chain.cl_cpg) !=
  433. ocfs2_group_bitmap_size(osb->sb, 0,
  434. osb->s_feature_incompat) * 8) {
  435. mlog(ML_ERROR, "The disk is too old and small."
  436. " Force to do offline resize.");
  437. ret = -EINVAL;
  438. goto out_unlock;
  439. }
  440. ret = ocfs2_read_blocks_sync(osb, input->group, 1, &group_bh);
  441. if (ret < 0) {
  442. mlog(ML_ERROR, "Can't read the group descriptor # %llu "
  443. "from the device.", (unsigned long long)input->group);
  444. goto out_unlock;
  445. }
  446. ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), group_bh);
  447. ret = ocfs2_verify_group_and_input(main_bm_inode, fe, input, group_bh);
  448. if (ret) {
  449. mlog_errno(ret);
  450. goto out_unlock;
  451. }
  452. trace_ocfs2_group_add((unsigned long long)input->group,
  453. input->chain, input->clusters, input->frees);
  454. handle = ocfs2_start_trans(osb, OCFS2_GROUP_ADD_CREDITS);
  455. if (IS_ERR(handle)) {
  456. mlog_errno(PTR_ERR(handle));
  457. ret = -EINVAL;
  458. goto out_unlock;
  459. }
  460. cl_bpc = le16_to_cpu(fe->id2.i_chain.cl_bpc);
  461. cl = &fe->id2.i_chain;
  462. cr = &cl->cl_recs[input->chain];
  463. ret = ocfs2_journal_access_gd(handle, INODE_CACHE(main_bm_inode),
  464. group_bh, OCFS2_JOURNAL_ACCESS_WRITE);
  465. if (ret < 0) {
  466. mlog_errno(ret);
  467. goto out_commit;
  468. }
  469. group = (struct ocfs2_group_desc *)group_bh->b_data;
  470. group->bg_next_group = cr->c_blkno;
  471. ocfs2_journal_dirty(handle, group_bh);
  472. ret = ocfs2_journal_access_di(handle, INODE_CACHE(main_bm_inode),
  473. main_bm_bh, OCFS2_JOURNAL_ACCESS_WRITE);
  474. if (ret < 0) {
  475. mlog_errno(ret);
  476. goto out_commit;
  477. }
  478. if (input->chain == le16_to_cpu(cl->cl_next_free_rec)) {
  479. le16_add_cpu(&cl->cl_next_free_rec, 1);
  480. memset(cr, 0, sizeof(struct ocfs2_chain_rec));
  481. }
  482. cr->c_blkno = cpu_to_le64(input->group);
  483. le32_add_cpu(&cr->c_total, input->clusters * cl_bpc);
  484. le32_add_cpu(&cr->c_free, input->frees * cl_bpc);
  485. le32_add_cpu(&fe->id1.bitmap1.i_total, input->clusters *cl_bpc);
  486. le32_add_cpu(&fe->id1.bitmap1.i_used,
  487. (input->clusters - input->frees) * cl_bpc);
  488. le32_add_cpu(&fe->i_clusters, input->clusters);
  489. ocfs2_journal_dirty(handle, main_bm_bh);
  490. spin_lock(&OCFS2_I(main_bm_inode)->ip_lock);
  491. OCFS2_I(main_bm_inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
  492. le64_add_cpu(&fe->i_size, input->clusters << osb->s_clustersize_bits);
  493. spin_unlock(&OCFS2_I(main_bm_inode)->ip_lock);
  494. i_size_write(main_bm_inode, le64_to_cpu(fe->i_size));
  495. ocfs2_update_super_and_backups(main_bm_inode, input->clusters);
  496. out_commit:
  497. ocfs2_commit_trans(osb, handle);
  498. out_unlock:
  499. brelse(group_bh);
  500. brelse(main_bm_bh);
  501. ocfs2_inode_unlock(main_bm_inode, 1);
  502. out_mutex:
  503. mutex_unlock(&main_bm_inode->i_mutex);
  504. iput(main_bm_inode);
  505. out:
  506. return ret;
  507. }