Skip to content

Commit

Permalink
ocfs2: don't use handle for locking in allocation functions
Browse files Browse the repository at this point in the history
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: Mark Fasheh <mark.fasheh@oracle.com>
  • Loading branch information
Mark Fasheh committed Dec 2, 2006
1 parent 8d5596c commit da5cbf2
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 152 deletions.
14 changes: 3 additions & 11 deletions fs/ocfs2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -428,16 +421,15 @@ 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);
goto bail;
}
}

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);
Expand All @@ -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;
Expand Down
19 changes: 3 additions & 16 deletions fs/ocfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -480,21 +473,15 @@ 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);
goto leave;
}
}

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);
Expand All @@ -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;
Expand Down
26 changes: 6 additions & 20 deletions fs/ocfs2/localalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion fs/ocfs2/localalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
26 changes: 6 additions & 20 deletions fs/ocfs2/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -378,15 +371,15 @@ 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);
goto leave;
}
}

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;
Expand Down Expand Up @@ -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);
Expand All @@ -1665,15 +1651,15 @@ 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);
goto bail;
}
}

handle = ocfs2_start_trans(osb, handle, credits);
handle = ocfs2_start_trans(osb, NULL, credits);
if (IS_ERR(handle)) {
status = PTR_ERR(handle);
handle = NULL;
Expand Down
Loading

0 comments on commit da5cbf2

Please sign in to comment.