28 #include <linux/types.h>
57 u32 first_new_cluster,
67 blkno = ocfs2_backup_super_blkno(inode->
i_sb, i);
68 cluster = ocfs2_blocks_to_clusters(inode->
i_sb, blkno);
71 if (gd_blkno < lgd_blkno)
73 else if (gd_blkno > lgd_blkno)
88 static int ocfs2_update_last_group_and_inode(handle_t *
handle,
89 struct inode *bm_inode,
90 struct buffer_head *bm_bh,
91 struct buffer_head *group_bh,
92 u32 first_new_cluster,
105 trace_ocfs2_update_last_group_and_inode(new_clusters,
118 num_bits = new_clusters * cl_bpc;
119 le16_add_cpu(&
group->bg_bits, num_bits);
120 le16_add_cpu(&
group->bg_free_bits_count, num_bits);
128 backups = ocfs2_calc_new_backup_super(bm_inode,
133 le16_add_cpu(&
group->bg_free_bits_count, -1 * backups);
148 le32_add_cpu(&
cr->c_total, num_bits);
149 le32_add_cpu(&
cr->c_free, num_bits);
150 le32_add_cpu(&fe->
id1.
bitmap1.i_total, num_bits);
154 le32_add_cpu(&
cr->c_free, -1 * backups);
155 le32_add_cpu(&fe->
id1.
bitmap1.i_used, backups);
158 spin_lock(&OCFS2_I(bm_inode)->ip_lock);
161 spin_unlock(&OCFS2_I(bm_inode)->ip_lock);
168 ocfs2_calc_new_backup_super(bm_inode,
173 le16_add_cpu(&
group->bg_free_bits_count, backups);
174 le16_add_cpu(&
group->bg_bits, -1 * num_bits);
175 le16_add_cpu(&
group->bg_free_bits_count, -1 * num_bits);
183 static int update_backups(
struct inode * inode,
u32 clusters,
char *
data)
188 struct buffer_head *backup =
NULL;
194 blkno = ocfs2_backup_super_blkno(inode->
i_sb, i);
195 cluster = ocfs2_blocks_to_clusters(inode->
i_sb, blkno);
196 if (cluster > clusters)
205 memcpy(backup->b_data, data, inode->
i_sb->s_blocksize);
222 static void ocfs2_update_super_and_backups(
struct inode *inode,
227 struct buffer_head *super_bh =
NULL;
243 le32_add_cpu(&super_di->
i_clusters, new_clusters);
253 ret = update_backups(inode, clusters, super_bh->b_data);
259 " during fs resize. This condition is not fatal,"
260 " but fsck.ocfs2 should be run to fix it\n",
274 struct buffer_head *main_bm_bh =
NULL;
275 struct buffer_head *group_bh =
NULL;
276 struct inode *main_bm_inode =
NULL;
281 u32 first_new_cluster;
284 if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
287 if (new_clusters < 0)
289 else if (new_clusters == 0)
295 if (!main_bm_inode) {
316 ocfs2_group_bitmap_size(osb->
sb, 0,
319 "Force to do offline resize.");
326 first_new_cluster - 1);
344 trace_ocfs2_group_extend(
348 if (IS_ERR(handle)) {
355 ret = ocfs2_update_last_group_and_inode(handle, main_bm_inode,
356 main_bm_bh, group_bh,
364 ocfs2_update_super_and_backups(main_bm_inode, new_clusters);
382 static int ocfs2_check_new_group(
struct inode *inode,
385 struct buffer_head *group_bh)
398 mlog(
ML_ERROR,
"Group descriptor # %llu has bad chain %u "
399 "while input has %u set.\n",
403 mlog(
ML_ERROR,
"Group descriptor # %llu has bit count %u but "
404 "input has %u clusters set\n",
408 mlog(
ML_ERROR,
"Group descriptor # %llu has free bit count %u "
409 "but it should have %u set\n",
412 input->
frees * cl_bpc);
420 static int ocfs2_verify_group_and_input(
struct inode *inode,
423 struct buffer_head *group_bh)
428 u32 cluster = ocfs2_blocks_to_clusters(inode->
i_sb, input->
group);
432 if (cluster < total_clusters)
433 mlog(
ML_ERROR,
"add a group which is in the current volume.\n");
434 else if (input->
chain >= cl_count)
436 else if (next_free != cl_count && next_free != input->
chain)
438 "the add group should be in chain %u\n", next_free);
439 else if (total_clusters + input->
clusters < total_clusters)
442 mlog(
ML_ERROR,
"the cluster exceeds the maximum of a group\n");
444 mlog(
ML_ERROR,
"the free cluster exceeds the total clusters\n");
445 else if (total_clusters % cl_cpg != 0)
447 "the last group isn't full. Use group extend first.\n");
450 else if ((ret = ocfs2_check_new_group(inode, di, input, group_bh)))
463 struct buffer_head *main_bm_bh =
NULL;
464 struct inode *main_bm_inode =
NULL;
467 struct buffer_head *group_bh =
NULL;
473 if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
479 if (!main_bm_inode) {
496 ocfs2_group_bitmap_size(osb->
sb, 0,
499 " Force to do offline resize.");
506 mlog(
ML_ERROR,
"Can't read the group descriptor # %llu "
507 "from the device.", (
unsigned long long)input->
group);
513 ret = ocfs2_verify_group_and_input(main_bm_inode, fe, input, group_bh);
519 trace_ocfs2_group_add((
unsigned long long)input->
group,
523 if (IS_ERR(handle)) {
567 spin_lock(&OCFS2_I(main_bm_inode)->ip_lock);
570 spin_unlock(&OCFS2_I(main_bm_inode)->ip_lock);
573 ocfs2_update_super_and_backups(main_bm_inode, input->
clusters);