Commit da5cbf2f authored by Mark Fasheh's avatar Mark Fasheh

ocfs2: don't use handle for locking in allocation functions

Instead we record our state on the allocation context structure which all
callers already know about and lifetime correctly. This means the
reservation functions don't need a handle passed in any more, and we can
also take it off the alloc context.
Signed-off-by: default avatarMark Fasheh <mark.fasheh@oracle.com>
parent 8d5596c6
......@@ -409,13 +409,6 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
mlog(0, "extending dir %llu (i_size = %lld)\n",
(unsigned long long)OCFS2_I(dir)->ip_blkno, dir_i_size);
handle = ocfs2_alloc_handle(osb);
if (handle == NULL) {
status = -ENOMEM;
mlog_errno(status);
goto bail;
}
/* dir->i_size is always block aligned. */
spin_lock(&OCFS2_I(dir)->ip_lock);
if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) {
......@@ -428,8 +421,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
}
if (!num_free_extents) {
status = ocfs2_reserve_new_metadata(osb, handle,
fe, &meta_ac);
status = ocfs2_reserve_new_metadata(osb, fe, &meta_ac);
if (status < 0) {
if (status != -ENOSPC)
mlog_errno(status);
......@@ -437,7 +429,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
}
}
status = ocfs2_reserve_clusters(osb, handle, 1, &data_ac);
status = ocfs2_reserve_clusters(osb, 1, &data_ac);
if (status < 0) {
if (status != -ENOSPC)
mlog_errno(status);
......@@ -450,7 +442,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
credits = OCFS2_SIMPLE_DIR_EXTEND_CREDITS;
}
handle = ocfs2_start_trans(osb, handle, credits);
handle = ocfs2_start_trans(osb, NULL, credits);
if (IS_ERR(handle)) {
status = PTR_ERR(handle);
handle = NULL;
......
......@@ -463,13 +463,6 @@ static int ocfs2_extend_allocation(struct inode *inode,
(unsigned long long)OCFS2_I(inode)->ip_blkno, i_size_read(inode),
fe->i_clusters, clusters_to_add);
handle = ocfs2_alloc_handle(osb);
if (handle == NULL) {
status = -ENOMEM;
mlog_errno(status);
goto leave;
}
num_free_extents = ocfs2_num_free_extents(osb,
inode,
fe);
......@@ -480,10 +473,7 @@ static int ocfs2_extend_allocation(struct inode *inode,
}
if (!num_free_extents) {
status = ocfs2_reserve_new_metadata(osb,
handle,
fe,
&meta_ac);
status = ocfs2_reserve_new_metadata(osb, fe, &meta_ac);
if (status < 0) {
if (status != -ENOSPC)
mlog_errno(status);
......@@ -491,10 +481,7 @@ static int ocfs2_extend_allocation(struct inode *inode,
}
}
status = ocfs2_reserve_clusters(osb,
handle,
clusters_to_add,
&data_ac);
status = ocfs2_reserve_clusters(osb, clusters_to_add, &data_ac);
if (status < 0) {
if (status != -ENOSPC)
mlog_errno(status);
......@@ -509,7 +496,7 @@ static int ocfs2_extend_allocation(struct inode *inode,
drop_alloc_sem = 1;
credits = ocfs2_calc_extend_credits(osb->sb, fe, clusters_to_add);
handle = ocfs2_start_trans(osb, handle, credits);
handle = ocfs2_start_trans(osb, NULL, credits);
if (IS_ERR(handle)) {
status = PTR_ERR(handle);
handle = NULL;
......
......@@ -64,7 +64,6 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
struct buffer_head *main_bm_bh);
static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
struct ocfs2_journal_handle *handle,
struct ocfs2_alloc_context **ac,
struct inode **bitmap_inode,
struct buffer_head **bitmap_bh);
......@@ -448,7 +447,6 @@ int ocfs2_complete_local_alloc_recovery(struct ocfs2_super *osb,
* our own in order to shift windows.
*/
int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
struct ocfs2_journal_handle *passed_handle,
u32 bits_wanted,
struct ocfs2_alloc_context *ac)
{
......@@ -459,9 +457,7 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
mlog_entry_void();
BUG_ON(!passed_handle);
BUG_ON(!ac);
BUG_ON(passed_handle->k_handle);
local_alloc_inode =
ocfs2_get_system_file_inode(osb,
......@@ -472,7 +468,11 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
mlog_errno(status);
goto bail;
}
ocfs2_handle_add_inode(passed_handle, local_alloc_inode);
mutex_lock(&local_alloc_inode->i_mutex);
ac->ac_inode = local_alloc_inode;
ac->ac_which = OCFS2_AC_USE_LOCAL;
if (osb->local_alloc_state != OCFS2_LA_ENABLED) {
status = -ENOSPC;
......@@ -511,14 +511,10 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
}
}
ac->ac_inode = igrab(local_alloc_inode);
get_bh(osb->local_alloc_bh);
ac->ac_bh = osb->local_alloc_bh;
ac->ac_which = OCFS2_AC_USE_LOCAL;
status = 0;
bail:
if (local_alloc_inode)
iput(local_alloc_inode);
mlog_exit(status);
return status;
......@@ -774,7 +770,6 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
}
static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
struct ocfs2_journal_handle *handle,
struct ocfs2_alloc_context **ac,
struct inode **bitmap_inode,
struct buffer_head **bitmap_bh)
......@@ -788,7 +783,6 @@ static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
goto bail;
}
(*ac)->ac_handle = handle;
(*ac)->ac_bits_wanted = ocfs2_local_alloc_window_bits(osb);
status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac);
......@@ -891,16 +885,8 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
mlog_entry_void();
handle = ocfs2_alloc_handle(osb);
if (!handle) {
status = -ENOMEM;
mlog_errno(status);
goto bail;
}
/* This will lock the main bitmap for us. */
status = ocfs2_local_alloc_reserve_for_window(osb,
handle,
&ac,
&main_bm_inode,
&main_bm_bh);
......@@ -910,7 +896,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
goto bail;
}
handle = ocfs2_start_trans(osb, handle, OCFS2_WINDOW_MOVE_CREDITS);
handle = ocfs2_start_trans(osb, NULL, OCFS2_WINDOW_MOVE_CREDITS);
if (IS_ERR(handle)) {
status = PTR_ERR(handle);
handle = NULL;
......
......@@ -42,7 +42,6 @@ int ocfs2_alloc_should_use_local(struct ocfs2_super *osb,
struct ocfs2_alloc_context;
int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
struct ocfs2_journal_handle *passed_handle,
u32 bits_wanted,
struct ocfs2_alloc_context *ac);
......
......@@ -334,13 +334,6 @@ static int ocfs2_mknod(struct inode *dir,
return status;
}
handle = ocfs2_alloc_handle(osb);
if (handle == NULL) {
status = -ENOMEM;
mlog_errno(status);
goto leave;
}
if (S_ISDIR(mode) && (dir->i_nlink >= OCFS2_LINK_MAX)) {
status = -EMLINK;
goto leave;
......@@ -368,7 +361,7 @@ static int ocfs2_mknod(struct inode *dir,
}
/* reserve an inode spot */
status = ocfs2_reserve_new_inode(osb, handle, &inode_ac);
status = ocfs2_reserve_new_inode(osb, &inode_ac);
if (status < 0) {
if (status != -ENOSPC)
mlog_errno(status);
......@@ -378,7 +371,7 @@ static int ocfs2_mknod(struct inode *dir,
/* are we making a directory? If so, reserve a cluster for his
* 1st extent. */
if (S_ISDIR(mode)) {
status = ocfs2_reserve_clusters(osb, handle, 1, &data_ac);
status = ocfs2_reserve_clusters(osb, 1, &data_ac);
if (status < 0) {
if (status != -ENOSPC)
mlog_errno(status);
......@@ -386,7 +379,7 @@ static int ocfs2_mknod(struct inode *dir,
}
}
handle = ocfs2_start_trans(osb, handle, OCFS2_MKNOD_CREDITS);
handle = ocfs2_start_trans(osb, NULL, OCFS2_MKNOD_CREDITS);
if (IS_ERR(handle)) {
status = PTR_ERR(handle);
handle = NULL;
......@@ -1649,14 +1642,7 @@ static int ocfs2_symlink(struct inode *dir,
goto bail;
}
handle = ocfs2_alloc_handle(osb);
if (handle == NULL) {
status = -ENOMEM;
mlog_errno(status);
goto bail;
}
status = ocfs2_reserve_new_inode(osb, handle, &inode_ac);
status = ocfs2_reserve_new_inode(osb, &inode_ac);
if (status < 0) {
if (status != -ENOSPC)
mlog_errno(status);
......@@ -1665,7 +1651,7 @@ static int ocfs2_symlink(struct inode *dir,
/* don't reserve bitmap space for fast symlinks. */
if (l > ocfs2_fast_symlink_chars(sb)) {
status = ocfs2_reserve_clusters(osb, handle, 1, &data_ac);
status = ocfs2_reserve_clusters(osb, 1, &data_ac);
if (status < 0) {
if (status != -ENOSPC)
mlog_errno(status);
......@@ -1673,7 +1659,7 @@ static int ocfs2_symlink(struct inode *dir,
}
}
handle = ocfs2_start_trans(osb, handle, credits);
handle = ocfs2_start_trans(osb, NULL, credits);
if (IS_ERR(handle)) {
status = PTR_ERR(handle);
handle = NULL;
......
This diff is collapsed.
......@@ -43,7 +43,6 @@ struct ocfs2_alloc_context {
#define OCFS2_AC_USE_INODE 3
#define OCFS2_AC_USE_META 4
u32 ac_which;
struct ocfs2_journal_handle *ac_handle;
/* these are used by the chain search */
u16 ac_chain;
......@@ -60,14 +59,11 @@ static inline int ocfs2_alloc_context_bits_left(struct ocfs2_alloc_context *ac)
}
int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
struct ocfs2_journal_handle *handle,
struct ocfs2_dinode *fe,
struct ocfs2_alloc_context **ac);
int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
struct ocfs2_journal_handle *handle,
struct ocfs2_alloc_context **ac);
int ocfs2_reserve_clusters(struct ocfs2_super *osb,
struct ocfs2_journal_handle *handle,
u32 bits_wanted,
struct ocfs2_alloc_context **ac);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment