]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - fs/ocfs2/alloc.c
ocfs2: Set suballoc_loc on allocated metadata.
[mirror_ubuntu-bionic-kernel.git] / fs / ocfs2 / alloc.c
index 2bbe1ecc08c060861acf366fd61dce1d2184e36d..479d2ecae340de69845f9ad77aeb59113e64e948 100644 (file)
@@ -1006,7 +1006,7 @@ static int ocfs2_create_new_meta_bhs(handle_t *handle,
        int count, status, i;
        u16 suballoc_bit_start;
        u32 num_got;
-       u64 first_blkno;
+       u64 suballoc_loc, first_blkno;
        struct ocfs2_super *osb =
                OCFS2_SB(ocfs2_metadata_cache_get_super(et->et_ci));
        struct ocfs2_extent_block *eb;
@@ -1015,10 +1015,10 @@ static int ocfs2_create_new_meta_bhs(handle_t *handle,
 
        count = 0;
        while (count < wanted) {
-               status = ocfs2_claim_metadata(osb,
-                                             handle,
+               status = ocfs2_claim_metadata(handle,
                                              meta_ac,
                                              wanted - count,
+                                             &suballoc_loc,
                                              &suballoc_bit_start,
                                              &num_got,
                                              &first_blkno);
@@ -1052,6 +1052,7 @@ static int ocfs2_create_new_meta_bhs(handle_t *handle,
                        eb->h_fs_generation = cpu_to_le32(osb->fs_generation);
                        eb->h_suballoc_slot =
                                cpu_to_le16(meta_ac->ac_alloc_slot);
+                       eb->h_suballoc_loc = cpu_to_le64(suballoc_loc);
                        eb->h_suballoc_bit = cpu_to_le16(suballoc_bit_start);
                        eb->h_list.l_count =
                                cpu_to_le16(ocfs2_extent_recs_per_eb(osb->sb));
@@ -1061,11 +1062,7 @@ static int ocfs2_create_new_meta_bhs(handle_t *handle,
 
                        /* We'll also be dirtied by the caller, so
                         * this isn't absolutely necessary. */
-                       status = ocfs2_journal_dirty(handle, bhs[i]);
-                       if (status < 0) {
-                               mlog_errno(status);
-                               goto bail;
-                       }
+                       ocfs2_journal_dirty(handle, bhs[i]);
                }
 
                count += num_got;
@@ -1129,8 +1126,7 @@ static int ocfs2_adjust_rightmost_branch(handle_t *handle,
                goto out;
        }
 
-       status = ocfs2_extend_trans(handle, path_num_items(path) +
-                                   handle->h_buffer_credits);
+       status = ocfs2_extend_trans(handle, path_num_items(path));
        if (status < 0) {
                mlog_errno(status);
                goto out;
@@ -1270,12 +1266,7 @@ static int ocfs2_add_branch(handle_t *handle,
                if (!eb_el->l_tree_depth)
                        new_last_eb_blk = le64_to_cpu(eb->h_blkno);
 
-               status = ocfs2_journal_dirty(handle, bh);
-               if (status < 0) {
-                       mlog_errno(status);
-                       goto bail;
-               }
-
+               ocfs2_journal_dirty(handle, bh);
                next_blkno = le64_to_cpu(eb->h_blkno);
        }
 
@@ -1321,17 +1312,10 @@ static int ocfs2_add_branch(handle_t *handle,
        eb = (struct ocfs2_extent_block *) (*last_eb_bh)->b_data;
        eb->h_next_leaf_blk = cpu_to_le64(new_last_eb_blk);
 
-       status = ocfs2_journal_dirty(handle, *last_eb_bh);
-       if (status < 0)
-               mlog_errno(status);
-       status = ocfs2_journal_dirty(handle, et->et_root_bh);
-       if (status < 0)
-               mlog_errno(status);
-       if (eb_bh) {
-               status = ocfs2_journal_dirty(handle, eb_bh);
-               if (status < 0)
-                       mlog_errno(status);
-       }
+       ocfs2_journal_dirty(handle, *last_eb_bh);
+       ocfs2_journal_dirty(handle, et->et_root_bh);
+       if (eb_bh)
+               ocfs2_journal_dirty(handle, eb_bh);
 
        /*
         * Some callers want to track the rightmost leaf so pass it
@@ -1399,11 +1383,7 @@ static int ocfs2_shift_tree_depth(handle_t *handle,
        for (i = 0; i < le16_to_cpu(root_el->l_next_free_rec); i++)
                eb_el->l_recs[i] = root_el->l_recs[i];
 
-       status = ocfs2_journal_dirty(handle, new_eb_bh);
-       if (status < 0) {
-               mlog_errno(status);
-               goto bail;
-       }
+       ocfs2_journal_dirty(handle, new_eb_bh);
 
        status = ocfs2_et_root_journal_access(handle, et,
                                              OCFS2_JOURNAL_ACCESS_WRITE);
@@ -1428,11 +1408,7 @@ static int ocfs2_shift_tree_depth(handle_t *handle,
        if (root_el->l_tree_depth == cpu_to_le16(1))
                ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno));
 
-       status = ocfs2_journal_dirty(handle, et->et_root_bh);
-       if (status < 0) {
-               mlog_errno(status);
-               goto bail;
-       }
+       ocfs2_journal_dirty(handle, et->et_root_bh);
 
        *ret_new_eb_bh = new_eb_bh;
        new_eb_bh = NULL;
@@ -2064,7 +2040,7 @@ static void ocfs2_complete_edge_insert(handle_t *handle,
                                       struct ocfs2_path *right_path,
                                       int subtree_index)
 {
-       int ret, i, idx;
+       int i, idx;
        struct ocfs2_extent_list *el, *left_el, *right_el;
        struct ocfs2_extent_rec *left_rec, *right_rec;
        struct buffer_head *root_bh = left_path->p_node[subtree_index].bh;
@@ -2102,13 +2078,8 @@ static void ocfs2_complete_edge_insert(handle_t *handle,
                ocfs2_adjust_adjacent_records(left_rec, left_el, right_rec,
                                              right_el);
 
-               ret = ocfs2_journal_dirty(handle, left_path->p_node[i].bh);
-               if (ret)
-                       mlog_errno(ret);
-
-               ret = ocfs2_journal_dirty(handle, right_path->p_node[i].bh);
-               if (ret)
-                       mlog_errno(ret);
+               ocfs2_journal_dirty(handle, left_path->p_node[i].bh);
+               ocfs2_journal_dirty(handle, right_path->p_node[i].bh);
 
                /*
                 * Setup our list pointers now so that the current
@@ -2132,9 +2103,7 @@ static void ocfs2_complete_edge_insert(handle_t *handle,
 
        root_bh = left_path->p_node[subtree_index].bh;
 
-       ret = ocfs2_journal_dirty(handle, root_bh);
-       if (ret)
-               mlog_errno(ret);
+       ocfs2_journal_dirty(handle, root_bh);
 }
 
 static int ocfs2_rotate_subtree_right(handle_t *handle,
@@ -2207,11 +2176,7 @@ static int ocfs2_rotate_subtree_right(handle_t *handle,
 
        ocfs2_create_empty_extent(right_el);
 
-       ret = ocfs2_journal_dirty(handle, right_leaf_bh);
-       if (ret) {
-               mlog_errno(ret);
-               goto out;
-       }
+       ocfs2_journal_dirty(handle, right_leaf_bh);
 
        /* Do the copy now. */
        i = le16_to_cpu(left_el->l_next_free_rec) - 1;
@@ -2230,11 +2195,7 @@ static int ocfs2_rotate_subtree_right(handle_t *handle,
        memset(&left_el->l_recs[0], 0, sizeof(struct ocfs2_extent_rec));
        le16_add_cpu(&left_el->l_next_free_rec, 1);
 
-       ret = ocfs2_journal_dirty(handle, left_leaf_bh);
-       if (ret) {
-               mlog_errno(ret);
-               goto out;
-       }
+       ocfs2_journal_dirty(handle, left_leaf_bh);
 
        ocfs2_complete_edge_insert(handle, left_path, right_path,
                                   subtree_index);
@@ -2327,20 +2288,14 @@ static int ocfs2_extend_rotate_transaction(handle_t *handle, int subtree_depth,
                                           int op_credits,
                                           struct ocfs2_path *path)
 {
-       int ret;
+       int ret = 0;
        int credits = (path->p_tree_depth - subtree_depth) * 2 + 1 + op_credits;
 
-       if (handle->h_buffer_credits < credits) {
+       if (handle->h_buffer_credits < credits)
                ret = ocfs2_extend_trans(handle,
                                         credits - handle->h_buffer_credits);
-               if (ret)
-                       return ret;
-
-               if (unlikely(handle->h_buffer_credits < credits))
-                       return ocfs2_extend_trans(handle, credits);
-       }
 
-       return 0;
+       return ret;
 }
 
 /*
@@ -2584,8 +2539,7 @@ static int ocfs2_update_edge_lengths(handle_t *handle,
         * records for all the bh in the path.
         * So we have to allocate extra credits and access them.
         */
-       ret = ocfs2_extend_trans(handle,
-                                handle->h_buffer_credits + subtree_index);
+       ret = ocfs2_extend_trans(handle, subtree_index);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -2823,12 +2777,8 @@ static int ocfs2_rotate_subtree_left(handle_t *handle,
                ocfs2_remove_empty_extent(right_leaf_el);
        }
 
-       ret = ocfs2_journal_dirty(handle, path_leaf_bh(left_path));
-       if (ret)
-               mlog_errno(ret);
-       ret = ocfs2_journal_dirty(handle, path_leaf_bh(right_path));
-       if (ret)
-               mlog_errno(ret);
+       ocfs2_journal_dirty(handle, path_leaf_bh(left_path));
+       ocfs2_journal_dirty(handle, path_leaf_bh(right_path));
 
        if (del_right_subtree) {
                ocfs2_unlink_subtree(handle, et, left_path, right_path,
@@ -2851,9 +2801,7 @@ static int ocfs2_rotate_subtree_left(handle_t *handle,
                if (right_has_empty)
                        ocfs2_remove_empty_extent(left_leaf_el);
 
-               ret = ocfs2_journal_dirty(handle, et_root_bh);
-               if (ret)
-                       mlog_errno(ret);
+               ocfs2_journal_dirty(handle, et_root_bh);
 
                *deleted = 1;
        } else
@@ -2962,10 +2910,7 @@ static int ocfs2_rotate_rightmost_leaf_left(handle_t *handle,
        }
 
        ocfs2_remove_empty_extent(el);
-
-       ret = ocfs2_journal_dirty(handle, bh);
-       if (ret)
-               mlog_errno(ret);
+       ocfs2_journal_dirty(handle, bh);
 
 out:
        return ret;
@@ -3506,15 +3451,9 @@ static int ocfs2_merge_rec_right(struct ocfs2_path *left_path,
 
        ocfs2_cleanup_merge(el, index);
 
-       ret = ocfs2_journal_dirty(handle, bh);
-       if (ret)
-               mlog_errno(ret);
-
+       ocfs2_journal_dirty(handle, bh);
        if (right_path) {
-               ret = ocfs2_journal_dirty(handle, path_leaf_bh(right_path));
-               if (ret)
-                       mlog_errno(ret);
-
+               ocfs2_journal_dirty(handle, path_leaf_bh(right_path));
                ocfs2_complete_edge_insert(handle, left_path, right_path,
                                           subtree_index);
        }
@@ -3683,14 +3622,9 @@ static int ocfs2_merge_rec_left(struct ocfs2_path *right_path,
 
        ocfs2_cleanup_merge(el, index);
 
-       ret = ocfs2_journal_dirty(handle, bh);
-       if (ret)
-               mlog_errno(ret);
-
+       ocfs2_journal_dirty(handle, bh);
        if (left_path) {
-               ret = ocfs2_journal_dirty(handle, path_leaf_bh(left_path));
-               if (ret)
-                       mlog_errno(ret);
+               ocfs2_journal_dirty(handle, path_leaf_bh(left_path));
 
                /*
                 * In the situation that the right_rec is empty and the extent
@@ -4016,10 +3950,7 @@ static void ocfs2_adjust_rightmost_records(handle_t *handle,
                le32_add_cpu(&rec->e_int_clusters,
                             -le32_to_cpu(rec->e_cpos));
 
-               ret = ocfs2_journal_dirty(handle, bh);
-               if (ret)
-                       mlog_errno(ret);
-
+               ocfs2_journal_dirty(handle, bh);
        }
 }
 
@@ -4203,17 +4134,13 @@ static int ocfs2_insert_path(handle_t *handle,
        struct buffer_head *leaf_bh = path_leaf_bh(right_path);
 
        if (left_path) {
-               int credits = handle->h_buffer_credits;
-
                /*
                 * There's a chance that left_path got passed back to
                 * us without being accounted for in the
                 * journal. Extend our transaction here to be sure we
                 * can change those blocks.
                 */
-               credits += left_path->p_tree_depth;
-
-               ret = ocfs2_extend_trans(handle, credits);
+               ret = ocfs2_extend_trans(handle, left_path->p_tree_depth);
                if (ret < 0) {
                        mlog_errno(ret);
                        goto out;
@@ -4251,17 +4178,13 @@ static int ocfs2_insert_path(handle_t *handle,
                 * dirty this for us.
                 */
                if (left_path)
-                       ret = ocfs2_journal_dirty(handle,
-                                                 path_leaf_bh(left_path));
-                       if (ret)
-                               mlog_errno(ret);
+                       ocfs2_journal_dirty(handle,
+                                           path_leaf_bh(left_path));
        } else
                ocfs2_insert_at_leaf(et, insert_rec, path_leaf_el(right_path),
                                     insert);
 
-       ret = ocfs2_journal_dirty(handle, leaf_bh);
-       if (ret)
-               mlog_errno(ret);
+       ocfs2_journal_dirty(handle, leaf_bh);
 
        if (left_path) {
                /*
@@ -4384,9 +4307,7 @@ out_update_clusters:
                ocfs2_et_update_clusters(et,
                                         le16_to_cpu(insert_rec->e_leaf_clusters));
 
-       ret = ocfs2_journal_dirty(handle, et->et_root_bh);
-       if (ret)
-               mlog_errno(ret);
+       ocfs2_journal_dirty(handle, et->et_root_bh);
 
 out:
        ocfs2_free_path(left_path);
@@ -4866,7 +4787,7 @@ int ocfs2_add_clusters_in_btree(handle_t *handle,
                goto leave;
        }
 
-       status = __ocfs2_claim_clusters(osb, handle, data_ac, 1,
+       status = __ocfs2_claim_clusters(handle, data_ac, 1,
                                        clusters_to_add, &bit_off, &num_bits);
        if (status < 0) {
                if (status != -ENOSPC)
@@ -4895,11 +4816,7 @@ int ocfs2_add_clusters_in_btree(handle_t *handle,
                goto leave;
        }
 
-       status = ocfs2_journal_dirty(handle, et->et_root_bh);
-       if (status < 0) {
-               mlog_errno(status);
-               goto leave;
-       }
+       ocfs2_journal_dirty(handle, et->et_root_bh);
 
        clusters_to_add -= num_bits;
        *logical_offset += num_bits;
@@ -5309,7 +5226,7 @@ static int ocfs2_split_tree(handle_t *handle, struct ocfs2_extent_tree *et,
                            int index, u32 new_range,
                            struct ocfs2_alloc_context *meta_ac)
 {
-       int ret, depth, credits = handle->h_buffer_credits;
+       int ret, depth, credits;
        struct buffer_head *last_eb_bh = NULL;
        struct ocfs2_extent_block *eb;
        struct ocfs2_extent_list *rightmost_el, *el;
@@ -5340,8 +5257,8 @@ static int ocfs2_split_tree(handle_t *handle, struct ocfs2_extent_tree *et,
        } else
                rightmost_el = path_leaf_el(path);
 
-       credits += path->p_tree_depth +
-                  ocfs2_extend_meta_needed(et->et_root_el);
+       credits = path->p_tree_depth +
+                 ocfs2_extend_meta_needed(et->et_root_el);
        ret = ocfs2_extend_trans(handle, credits);
        if (ret) {
                mlog_errno(ret);
@@ -5713,7 +5630,7 @@ int ocfs2_remove_btree_range(struct inode *inode,
                goto out;
        }
 
-       vfs_dq_free_space_nodirty(inode,
+       dquot_free_space_nodirty(inode,
                                  ocfs2_clusters_to_bytes(inode->i_sb, len));
 
        ret = ocfs2_remove_extent(handle, et, cpos, len, meta_ac, dealloc);
@@ -5724,11 +5641,7 @@ int ocfs2_remove_btree_range(struct inode *inode,
 
        ocfs2_et_update_clusters(et, -len);
 
-       ret = ocfs2_journal_dirty(handle, et->et_root_bh);
-       if (ret) {
-               mlog_errno(ret);
-               goto out_commit;
-       }
+       ocfs2_journal_dirty(handle, et->et_root_bh);
 
        ret = ocfs2_truncate_log_append(osb, handle, phys_blkno, len);
        if (ret)
@@ -5850,11 +5763,7 @@ int ocfs2_truncate_log_append(struct ocfs2_super *osb,
        }
        tl->tl_recs[index].t_clusters = cpu_to_le32(num_clusters);
 
-       status = ocfs2_journal_dirty(handle, tl_bh);
-       if (status < 0) {
-               mlog_errno(status);
-               goto bail;
-       }
+       ocfs2_journal_dirty(handle, tl_bh);
 
 bail:
        mlog_exit(status);
@@ -5893,11 +5802,7 @@ static int ocfs2_replay_truncate_records(struct ocfs2_super *osb,
 
                tl->tl_used = cpu_to_le16(i);
 
-               status = ocfs2_journal_dirty(handle, tl_bh);
-               if (status < 0) {
-                       mlog_errno(status);
-                       goto bail;
-               }
+               ocfs2_journal_dirty(handle, tl_bh);
 
                /* TODO: Perhaps we can calculate the bulk of the
                 * credits up front rather than extending like
@@ -6824,11 +6729,7 @@ find_tail_record:
                }
 
 delete:
-               ret = ocfs2_journal_dirty(handle, bh);
-               if (ret) {
-                       mlog_errno(ret);
-                       goto out;
-               }
+               ocfs2_journal_dirty(handle, bh);
 
                mlog(0, "extent list container %llu, after: record %d: "
                     "(%u, %u, %llu), next = %u.\n",
@@ -6936,7 +6837,7 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb,
                goto bail;
        }
 
-       vfs_dq_free_space_nodirty(inode,
+       dquot_free_space_nodirty(inode,
                        ocfs2_clusters_to_bytes(osb->sb, clusters_to_del));
        spin_lock(&OCFS2_I(inode)->ip_lock);
        OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters) -
@@ -6959,22 +6860,14 @@ static int ocfs2_do_truncate(struct ocfs2_super *osb,
        } else if (last_eb)
                fe->i_last_eb_blk = last_eb->h_blkno;
 
-       status = ocfs2_journal_dirty(handle, fe_bh);
-       if (status < 0) {
-               mlog_errno(status);
-               goto bail;
-       }
+       ocfs2_journal_dirty(handle, fe_bh);
 
        if (last_eb) {
                /* If there will be a new last extent block, then by
                 * definition, there cannot be any leaves to the right of
                 * him. */
                last_eb->h_next_leaf_blk = 0;
-               status = ocfs2_journal_dirty(handle, last_eb_bh);
-               if (status < 0) {
-                       mlog_errno(status);
-                       goto bail;
-               }
+               ocfs2_journal_dirty(handle, last_eb_bh);
        }
 
        if (delete_blk) {
@@ -7301,14 +7194,15 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
                unsigned int page_end;
                u64 phys;
 
-               if (vfs_dq_alloc_space_nodirty(inode,
-                                      ocfs2_clusters_to_bytes(osb->sb, 1))) {
-                       ret = -EDQUOT;
+               ret = dquot_alloc_space_nodirty(inode,
+                                      ocfs2_clusters_to_bytes(osb->sb, 1));
+               if (ret)
                        goto out_commit;
-               }
                did_quota = 1;
 
-               ret = ocfs2_claim_clusters(osb, handle, data_ac, 1, &bit_off,
+               data_ac->ac_resv = &OCFS2_I(inode)->ip_la_data_resv;
+
+               ret = ocfs2_claim_clusters(handle, data_ac, 1, &bit_off,
                                           &num);
                if (ret) {
                        mlog_errno(ret);
@@ -7381,7 +7275,7 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
 
 out_commit:
        if (ret < 0 && did_quota)
-               vfs_dq_free_space_nodirty(inode,
+               dquot_free_space_nodirty(inode,
                                          ocfs2_clusters_to_bytes(osb->sb, 1));
 
        ocfs2_commit_trans(osb, handle);