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