]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - fs/ocfs2/dir.c
ocfs2: Free block to the right block group.
[mirror_ubuntu-bionic-kernel.git] / fs / ocfs2 / dir.c
index 28c3ec2387962b380e61c4b50258e15d399f92bb..3fea52d0efd325b15cbf3e84d998635761d0b455 100644 (file)
@@ -1194,7 +1194,7 @@ static int __ocfs2_delete_entry(handle_t *handle, struct inode *dir,
                        else
                                de->inode = 0;
                        dir->i_version++;
-                       status = ocfs2_journal_dirty(handle, bh);
+                       ocfs2_journal_dirty(handle, bh);
                        goto bail;
                }
                i += le16_to_cpu(de->rec_len);
@@ -1752,7 +1752,7 @@ int __ocfs2_add_entry(handle_t *handle,
                                ocfs2_recalc_free_list(dir, handle, lookup);
 
                        dir->i_version++;
-                       status = ocfs2_journal_dirty(handle, insert_bh);
+                       ocfs2_journal_dirty(handle, insert_bh);
                        retval = 0;
                        goto bail;
                }
@@ -2297,12 +2297,7 @@ static int ocfs2_fill_new_dir_id(struct ocfs2_super *osb,
        }
 
        ocfs2_fill_initial_dirents(inode, parent, data->id_data, size);
-
        ocfs2_journal_dirty(handle, di_bh);
-       if (ret) {
-               mlog_errno(ret);
-               goto out;
-       }
 
        i_size_write(inode, size);
        inode->i_nlink = 2;
@@ -2366,11 +2361,7 @@ static int ocfs2_fill_new_dir_el(struct ocfs2_super *osb,
                ocfs2_init_dir_trailer(inode, new_bh, size);
        }
 
-       status = ocfs2_journal_dirty(handle, new_bh);
-       if (status < 0) {
-               mlog_errno(status);
-               goto bail;
-       }
+       ocfs2_journal_dirty(handle, new_bh);
 
        i_size_write(inode, inode->i_sb->s_blocksize);
        inode->i_nlink = 2;
@@ -2404,15 +2395,15 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,
        int ret;
        struct ocfs2_dinode *di = (struct ocfs2_dinode *) di_bh->b_data;
        u16 dr_suballoc_bit;
-       u64 dr_blkno;
+       u64 suballoc_loc, dr_blkno;
        unsigned int num_bits;
        struct buffer_head *dx_root_bh = NULL;
        struct ocfs2_dx_root_block *dx_root;
        struct ocfs2_dir_block_trailer *trailer =
                ocfs2_trailer_from_bh(dirdata_bh, dir->i_sb);
 
-       ret = ocfs2_claim_metadata(osb, handle, meta_ac, 1, &dr_suballoc_bit,
-                                  &num_bits, &dr_blkno);
+       ret = ocfs2_claim_metadata(handle, meta_ac, 1, &suballoc_loc,
+                                  &dr_suballoc_bit, &num_bits, &dr_blkno);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -2439,7 +2430,8 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,
        dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data;
        memset(dx_root, 0, osb->sb->s_blocksize);
        strcpy(dx_root->dr_signature, OCFS2_DX_ROOT_SIGNATURE);
-       dx_root->dr_suballoc_slot = cpu_to_le16(osb->slot_num);
+       dx_root->dr_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot);
+       dx_root->dr_suballoc_loc = cpu_to_le64(suballoc_loc);
        dx_root->dr_suballoc_bit = cpu_to_le16(dr_suballoc_bit);
        dx_root->dr_fs_generation = cpu_to_le32(osb->fs_generation);
        dx_root->dr_blkno = cpu_to_le64(dr_blkno);
@@ -2458,10 +2450,7 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,
                dx_root->dr_list.l_count =
                        cpu_to_le16(ocfs2_extent_recs_per_dx_root(osb->sb));
        }
-
-       ret = ocfs2_journal_dirty(handle, dx_root_bh);
-       if (ret)
-               mlog_errno(ret);
+       ocfs2_journal_dirty(handle, dx_root_bh);
 
        ret = ocfs2_journal_access_di(handle, INODE_CACHE(dir), di_bh,
                                      OCFS2_JOURNAL_ACCESS_CREATE);
@@ -2475,9 +2464,7 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,
        OCFS2_I(dir)->ip_dyn_features |= OCFS2_INDEXED_DIR_FL;
        di->i_dyn_features = cpu_to_le16(OCFS2_I(dir)->ip_dyn_features);
 
-       ret = ocfs2_journal_dirty(handle, di_bh);
-       if (ret)
-               mlog_errno(ret);
+       ocfs2_journal_dirty(handle, di_bh);
 
        *ret_dx_root_bh = dx_root_bh;
        dx_root_bh = NULL;
@@ -2558,7 +2545,7 @@ static int __ocfs2_dx_dir_new_cluster(struct inode *dir,
         * chance of contiguousness as the directory grows in number
         * of entries.
         */
-       ret = __ocfs2_claim_clusters(osb, handle, data_ac, 1, 1, &phys, &num);
+       ret = __ocfs2_claim_clusters(handle, data_ac, 1, 1, &phys, &num);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -2964,12 +2951,10 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
                goto out;
        }
 
-       if (vfs_dq_alloc_space_nodirty(dir,
-                               ocfs2_clusters_to_bytes(osb->sb,
-                                                       alloc + dx_alloc))) {
-               ret = -EDQUOT;
+       ret = dquot_alloc_space_nodirty(dir,
+               ocfs2_clusters_to_bytes(osb->sb, alloc + dx_alloc));
+       if (ret)
                goto out_commit;
-       }
        did_quota = 1;
 
        if (ocfs2_supports_indexed_dirs(osb) && !dx_inline) {
@@ -2993,7 +2978,9 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
         * if we only get one now, that's enough to continue. The rest
         * will be claimed after the conversion to extents.
         */
-       ret = ocfs2_claim_clusters(osb, handle, data_ac, 1, &bit_off, &len);
+       if (ocfs2_dir_resv_allowed(osb))
+               data_ac->ac_resv = &oi->ip_la_data_resv;
+       ret = ocfs2_claim_clusters(handle, data_ac, 1, &bit_off, &len);
        if (ret) {
                mlog_errno(ret);
                goto out_commit;
@@ -3036,11 +3023,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
                ocfs2_init_dir_trailer(dir, dirdata_bh, i);
        }
 
-       ret = ocfs2_journal_dirty(handle, dirdata_bh);
-       if (ret) {
-               mlog_errno(ret);
-               goto out_commit;
-       }
+       ocfs2_journal_dirty(handle, dirdata_bh);
 
        if (ocfs2_supports_indexed_dirs(osb) && !dx_inline) {
                /*
@@ -3106,11 +3089,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
         */
        dir->i_blocks = ocfs2_inode_sector_count(dir);
 
-       ret = ocfs2_journal_dirty(handle, di_bh);
-       if (ret) {
-               mlog_errno(ret);
-               goto out_commit;
-       }
+       ocfs2_journal_dirty(handle, di_bh);
 
        if (ocfs2_supports_indexed_dirs(osb)) {
                ret = ocfs2_dx_dir_attach_index(osb, handle, dir, di_bh,
@@ -3140,7 +3119,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
         * pass. Claim the 2nd cluster as a separate extent.
         */
        if (alloc > len) {
-               ret = ocfs2_claim_clusters(osb, handle, data_ac, 1, &bit_off,
+               ret = ocfs2_claim_clusters(handle, data_ac, 1, &bit_off,
                                           &len);
                if (ret) {
                        mlog_errno(ret);
@@ -3178,7 +3157,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
 
 out_commit:
        if (ret < 0 && did_quota)
-               vfs_dq_free_space_nodirty(dir, bytes_allocated);
+               dquot_free_space_nodirty(dir, bytes_allocated);
 
        ocfs2_commit_trans(osb, handle);
 
@@ -3221,11 +3200,10 @@ static int ocfs2_do_extend_dir(struct super_block *sb,
        if (extend) {
                u32 offset = OCFS2_I(dir)->ip_clusters;
 
-               if (vfs_dq_alloc_space_nodirty(dir,
-                                       ocfs2_clusters_to_bytes(sb, 1))) {
-                       status = -EDQUOT;
+               status = dquot_alloc_space_nodirty(dir,
+                                       ocfs2_clusters_to_bytes(sb, 1));
+               if (status)
                        goto bail;
-               }
                did_quota = 1;
 
                status = ocfs2_add_inode_data(OCFS2_SB(sb), dir, &offset,
@@ -3254,7 +3232,7 @@ static int ocfs2_do_extend_dir(struct super_block *sb,
        status = 0;
 bail:
        if (did_quota && status < 0)
-               vfs_dq_free_space_nodirty(dir, ocfs2_clusters_to_bytes(sb, 1));
+               dquot_free_space_nodirty(dir, ocfs2_clusters_to_bytes(sb, 1));
        mlog_exit(status);
        return status;
 }
@@ -3372,6 +3350,9 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
                        goto bail;
                }
 
+               if (ocfs2_dir_resv_allowed(osb))
+                       data_ac->ac_resv = &OCFS2_I(dir)->ip_la_data_resv;
+
                credits = ocfs2_calc_extend_credits(sb, el, 1);
        } else {
                spin_unlock(&OCFS2_I(dir)->ip_lock);
@@ -3426,11 +3407,7 @@ do_extend:
        } else {
                de->rec_len = cpu_to_le16(sb->s_blocksize);
        }
-       status = ocfs2_journal_dirty(handle, new_bh);
-       if (status < 0) {
-               mlog_errno(status);
-               goto bail;
-       }
+       ocfs2_journal_dirty(handle, new_bh);
 
        dir_i_size += dir->i_sb->s_blocksize;
        i_size_write(dir, dir_i_size);
@@ -3889,11 +3866,10 @@ static int ocfs2_dx_dir_rebalance(struct ocfs2_super *osb, struct inode *dir,
                goto out;
        }
 
-       if (vfs_dq_alloc_space_nodirty(dir,
-                                      ocfs2_clusters_to_bytes(dir->i_sb, 1))) {
-               ret = -EDQUOT;
+       ret = dquot_alloc_space_nodirty(dir,
+                                      ocfs2_clusters_to_bytes(dir->i_sb, 1));
+       if (ret)
                goto out_commit;
-       }
        did_quota = 1;
 
        ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), dx_leaf_bh,
@@ -3910,11 +3886,7 @@ static int ocfs2_dx_dir_rebalance(struct ocfs2_super *osb, struct inode *dir,
             sizeof(struct ocfs2_dx_entry), dx_leaf_sort_cmp,
             dx_leaf_sort_swap);
 
-       ret = ocfs2_journal_dirty(handle, dx_leaf_bh);
-       if (ret) {
-               mlog_errno(ret);
-               goto out_commit;
-       }
+       ocfs2_journal_dirty(handle, dx_leaf_bh);
 
        ret = ocfs2_dx_dir_find_leaf_split(dx_leaf, leaf_cpos, insert_hash,
                                           &split_hash);
@@ -3983,7 +3955,7 @@ static int ocfs2_dx_dir_rebalance(struct ocfs2_super *osb, struct inode *dir,
 
 out_commit:
        if (ret < 0 && did_quota)
-               vfs_dq_free_space_nodirty(dir,
+               dquot_free_space_nodirty(dir,
                                ocfs2_clusters_to_bytes(dir->i_sb, 1));
 
        ocfs2_commit_trans(osb, handle);
@@ -4165,11 +4137,10 @@ static int ocfs2_expand_inline_dx_root(struct inode *dir,
                goto out;
        }
 
-       if (vfs_dq_alloc_space_nodirty(dir,
-                                      ocfs2_clusters_to_bytes(osb->sb, 1))) {
-               ret = -EDQUOT;
+       ret = dquot_alloc_space_nodirty(dir,
+                                      ocfs2_clusters_to_bytes(osb->sb, 1));
+       if (ret)
                goto out_commit;
-       }
        did_quota = 1;
 
        /*
@@ -4229,7 +4200,7 @@ static int ocfs2_expand_inline_dx_root(struct inode *dir,
 
 out_commit:
        if (ret < 0 && did_quota)
-               vfs_dq_free_space_nodirty(dir,
+               dquot_free_space_nodirty(dir,
                                          ocfs2_clusters_to_bytes(dir->i_sb, 1));
 
        ocfs2_commit_trans(osb, handle);
@@ -4495,7 +4466,10 @@ static int ocfs2_dx_dir_remove_index(struct inode *dir,
 
        blk = le64_to_cpu(dx_root->dr_blkno);
        bit = le16_to_cpu(dx_root->dr_suballoc_bit);
-       bg_blkno = ocfs2_which_suballoc_group(blk, bit);
+       if (dx_root->dr_suballoc_loc)
+               bg_blkno = le64_to_cpu(dx_root->dr_suballoc_loc);
+       else
+               bg_blkno = ocfs2_which_suballoc_group(blk, bit);
        ret = ocfs2_free_suballoc_bits(handle, dx_alloc_inode, dx_alloc_bh,
                                       bit, bg_blkno, 1);
        if (ret)