diff options
Diffstat (limited to 'fs/ocfs2/localalloc.c')
| -rw-r--r-- | fs/ocfs2/localalloc.c | 171 | 
1 files changed, 92 insertions, 79 deletions
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c index ec6adbf8f55..04401345562 100644 --- a/fs/ocfs2/localalloc.c +++ b/fs/ocfs2/localalloc.c @@ -29,7 +29,6 @@  #include <linux/highmem.h>  #include <linux/bitops.h> -#define MLOG_MASK_PREFIX ML_DISK_ALLOC  #include <cluster/masklog.h>  #include "ocfs2.h" @@ -43,6 +42,7 @@  #include "suballoc.h"  #include "super.h"  #include "sysfile.h" +#include "ocfs2_trace.h"  #include "buffer_head_io.h" @@ -201,8 +201,7 @@ void ocfs2_la_set_sizes(struct ocfs2_super *osb, int requested_mb)  	la_max_mb = ocfs2_clusters_to_megabytes(sb,  						ocfs2_local_alloc_size(sb) * 8); -	mlog(0, "requested: %dM, max: %uM, default: %uM\n", -	     requested_mb, la_max_mb, la_default_mb); +	trace_ocfs2_la_set_sizes(requested_mb, la_max_mb, la_default_mb);  	if (requested_mb == -1) {  		/* No user request - use defaults */ @@ -276,8 +275,8 @@ int ocfs2_alloc_should_use_local(struct ocfs2_super *osb, u64 bits)  	ret = 1;  bail: -	mlog(0, "state=%d, bits=%llu, la_bits=%d, ret=%d\n", -	     osb->local_alloc_state, (unsigned long long)bits, la_bits, ret); +	trace_ocfs2_alloc_should_use_local( +	     (unsigned long long)bits, osb->local_alloc_state, la_bits, ret);  	spin_unlock(&osb->osb_lock);  	return ret;  } @@ -291,8 +290,6 @@ int ocfs2_load_local_alloc(struct ocfs2_super *osb)  	struct inode *inode = NULL;  	struct ocfs2_local_alloc *la; -	mlog_entry_void(); -  	if (osb->local_alloc_bits == 0)  		goto bail; @@ -364,9 +361,10 @@ bail:  	if (inode)  		iput(inode); -	mlog(0, "Local alloc window bits = %d\n", osb->local_alloc_bits); +	trace_ocfs2_load_local_alloc(osb->local_alloc_bits); -	mlog_exit(status); +	if (status) +		mlog_errno(status);  	return status;  } @@ -388,8 +386,6 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)  	struct ocfs2_dinode *alloc_copy = NULL;  	struct ocfs2_dinode *alloc = NULL; -	mlog_entry_void(); -  	cancel_delayed_work(&osb->la_enable_wq);  	flush_workqueue(ocfs2_wq); @@ -480,10 +476,7 @@ out:  	if (local_alloc_inode)  		iput(local_alloc_inode); -	if (alloc_copy) -		kfree(alloc_copy); - -	mlog_exit_void(); +	kfree(alloc_copy);  }  /* @@ -502,7 +495,7 @@ int ocfs2_begin_local_alloc_recovery(struct ocfs2_super *osb,  	struct inode *inode = NULL;  	struct ocfs2_dinode *alloc; -	mlog_entry("(slot_num = %d)\n", slot_num); +	trace_ocfs2_begin_local_alloc_recovery(slot_num);  	*alloc_copy = NULL; @@ -540,7 +533,7 @@ int ocfs2_begin_local_alloc_recovery(struct ocfs2_super *osb,  		mlog_errno(status);  bail: -	if ((status < 0) && (*alloc_copy)) { +	if (status < 0) {  		kfree(*alloc_copy);  		*alloc_copy = NULL;  	} @@ -552,7 +545,8 @@ bail:  		iput(inode);  	} -	mlog_exit(status); +	if (status) +		mlog_errno(status);  	return status;  } @@ -570,8 +564,6 @@ int ocfs2_complete_local_alloc_recovery(struct ocfs2_super *osb,  	struct buffer_head *main_bm_bh = NULL;  	struct inode *main_bm_inode; -	mlog_entry_void(); -  	main_bm_inode = ocfs2_get_system_file_inode(osb,  						    GLOBAL_BITMAP_SYSTEM_INODE,  						    OCFS2_INVALID_SLOT); @@ -620,7 +612,8 @@ out_mutex:  out:  	if (!status)  		ocfs2_init_steal_slots(osb); -	mlog_exit(status); +	if (status) +		mlog_errno(status);  	return status;  } @@ -640,8 +633,6 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,  	struct inode *local_alloc_inode;  	unsigned int free_bits; -	mlog_entry_void(); -  	BUG_ON(!ac);  	local_alloc_inode = @@ -712,10 +703,6 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,  			goto bail;  	} -	if (ac->ac_max_block) -		mlog(0, "Calling in_range for max block %llu\n", -		     (unsigned long long)ac->ac_max_block); -  	ac->ac_inode = local_alloc_inode;  	/* We should never use localalloc from another slot */  	ac->ac_alloc_slot = osb->slot_num; @@ -729,10 +716,12 @@ bail:  		iput(local_alloc_inode);  	} -	mlog(0, "bits=%d, slot=%d, ret=%d\n", bits_wanted, osb->slot_num, -	     status); +	trace_ocfs2_reserve_local_alloc_bits( +		(unsigned long long)ac->ac_max_block, +		bits_wanted, osb->slot_num, status); -	mlog_exit(status); +	if (status) +		mlog_errno(status);  	return status;  } @@ -749,7 +738,6 @@ int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,  	struct ocfs2_dinode *alloc;  	struct ocfs2_local_alloc *la; -	mlog_entry_void();  	BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL);  	local_alloc_inode = ac->ac_inode; @@ -788,24 +776,61 @@ int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,  	ocfs2_journal_dirty(handle, osb->local_alloc_bh);  bail: -	mlog_exit(status); +	if (status) +		mlog_errno(status); +	return status; +} + +int ocfs2_free_local_alloc_bits(struct ocfs2_super *osb, +				handle_t *handle, +				struct ocfs2_alloc_context *ac, +				u32 bit_off, +				u32 num_bits) +{ +	int status, start; +	u32 clear_bits; +	struct inode *local_alloc_inode; +	void *bitmap; +	struct ocfs2_dinode *alloc; +	struct ocfs2_local_alloc *la; + +	BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL); + +	local_alloc_inode = ac->ac_inode; +	alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; +	la = OCFS2_LOCAL_ALLOC(alloc); + +	bitmap = la->la_bitmap; +	start = bit_off - le32_to_cpu(la->la_bm_off); +	clear_bits = num_bits; + +	status = ocfs2_journal_access_di(handle, +			INODE_CACHE(local_alloc_inode), +			osb->local_alloc_bh, +			OCFS2_JOURNAL_ACCESS_WRITE); +	if (status < 0) { +		mlog_errno(status); +		goto bail; +	} + +	while (clear_bits--) +		ocfs2_clear_bit(start++, bitmap); + +	le32_add_cpu(&alloc->id1.bitmap1.i_used, -num_bits); +	ocfs2_journal_dirty(handle, osb->local_alloc_bh); + +bail:  	return status;  }  static u32 ocfs2_local_alloc_count_bits(struct ocfs2_dinode *alloc)  { -	int i; -	u8 *buffer; -	u32 count = 0; +	u32 count;  	struct ocfs2_local_alloc *la = OCFS2_LOCAL_ALLOC(alloc); -	mlog_entry_void(); +	count = memweight(la->la_bitmap, le16_to_cpu(la->la_size)); -	buffer = la->la_bitmap; -	for (i = 0; i < le16_to_cpu(la->la_size); i++) -		count += hweight8(buffer[i]); - -	mlog_exit(count); +	trace_ocfs2_local_alloc_count_bits(count);  	return count;  } @@ -820,10 +845,7 @@ static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb,  	void *bitmap = NULL;  	struct ocfs2_reservation_map *resmap = &osb->osb_la_resmap; -	mlog_entry("(numbits wanted = %u)\n", *numbits); -  	if (!alloc->id1.bitmap1.i_total) { -		mlog(0, "No bits in my window!\n");  		bitoff = -1;  		goto bail;  	} @@ -883,8 +905,7 @@ static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb,  		}  	} -	mlog(0, "Exiting loop, bitoff = %d, numfound = %d\n", bitoff, -	     numfound); +	trace_ocfs2_local_alloc_find_clear_bits_search_bitmap(bitoff, numfound);  	if (numfound == *numbits)  		bitoff = startoff - numfound; @@ -895,7 +916,10 @@ bail:  	if (local_resv)  		ocfs2_resv_discard(resmap, resv); -	mlog_exit(bitoff); +	trace_ocfs2_local_alloc_find_clear_bits(*numbits, +		le32_to_cpu(alloc->id1.bitmap1.i_total), +		bitoff, numfound); +  	return bitoff;  } @@ -903,15 +927,12 @@ static void ocfs2_clear_local_alloc(struct ocfs2_dinode *alloc)  {  	struct ocfs2_local_alloc *la = OCFS2_LOCAL_ALLOC(alloc);  	int i; -	mlog_entry_void();  	alloc->id1.bitmap1.i_total = 0;  	alloc->id1.bitmap1.i_used = 0;  	la->la_bm_off = 0;  	for(i = 0; i < le16_to_cpu(la->la_size); i++)  		la->la_bitmap[i] = 0; - -	mlog_exit_void();  }  #if 0 @@ -952,18 +973,16 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,  	void *bitmap;  	struct ocfs2_local_alloc *la = OCFS2_LOCAL_ALLOC(alloc); -	mlog_entry("total = %u, used = %u\n", -		   le32_to_cpu(alloc->id1.bitmap1.i_total), -		   le32_to_cpu(alloc->id1.bitmap1.i_used)); +	trace_ocfs2_sync_local_to_main( +	     le32_to_cpu(alloc->id1.bitmap1.i_total), +	     le32_to_cpu(alloc->id1.bitmap1.i_used));  	if (!alloc->id1.bitmap1.i_total) { -		mlog(0, "nothing to sync!\n");  		goto bail;  	}  	if (le32_to_cpu(alloc->id1.bitmap1.i_used) ==  	    le32_to_cpu(alloc->id1.bitmap1.i_total)) { -		mlog(0, "all bits were taken!\n");  		goto bail;  	} @@ -985,8 +1004,7 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,  				ocfs2_clusters_to_blocks(osb->sb,  							 start - count); -			mlog(0, "freeing %u bits starting at local alloc bit " -			     "%u (la_start_blk = %llu, blkno = %llu)\n", +			trace_ocfs2_sync_local_to_main_free(  			     count, start - count,  			     (unsigned long long)la_start_blk,  			     (unsigned long long)blkno); @@ -1007,7 +1025,8 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,  	}  bail: -	mlog_exit(status); +	if (status) +		mlog_errno(status);  	return status;  } @@ -1105,7 +1124,7 @@ static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,  	}  retry_enospc: -	(*ac)->ac_bits_wanted = osb->local_alloc_default_bits; +	(*ac)->ac_bits_wanted = osb->local_alloc_bits;  	status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac);  	if (status == -ENOSPC) {  		if (ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_ENOSPC) == @@ -1132,7 +1151,8 @@ bail:  		*ac = NULL;  	} -	mlog_exit(status); +	if (status) +		mlog_errno(status);  	return status;  } @@ -1148,17 +1168,12 @@ static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb,  	struct ocfs2_dinode *alloc = NULL;  	struct ocfs2_local_alloc *la; -	mlog_entry_void(); -  	alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;  	la = OCFS2_LOCAL_ALLOC(alloc); -	if (alloc->id1.bitmap1.i_total) -		mlog(0, "asking me to alloc a new window over a non-empty " -		     "one\n"); - -	mlog(0, "Allocating %u clusters for a new window.\n", -	     osb->local_alloc_bits); +	trace_ocfs2_local_alloc_new_window( +		le32_to_cpu(alloc->id1.bitmap1.i_total), +		osb->local_alloc_bits);  	/* Instruct the allocation code to try the most recently used  	 * cluster group. We'll re-record the group used this pass @@ -1181,7 +1196,7 @@ retry_enospc:  		    OCFS2_LA_DISABLED)  			goto bail; -		ac->ac_bits_wanted = osb->local_alloc_default_bits; +		ac->ac_bits_wanted = osb->local_alloc_bits;  		status = ocfs2_claim_clusters(handle, ac,  					      osb->local_alloc_bits,  					      &cluster_off, @@ -1220,13 +1235,13 @@ retry_enospc:  	ocfs2_resmap_restart(&osb->osb_la_resmap, cluster_count,  			     OCFS2_LOCAL_ALLOC(alloc)->la_bitmap); -	mlog(0, "New window allocated:\n"); -	mlog(0, "window la_bm_off = %u\n", -	     OCFS2_LOCAL_ALLOC(alloc)->la_bm_off); -	mlog(0, "window bits = %u\n", le32_to_cpu(alloc->id1.bitmap1.i_total)); +	trace_ocfs2_local_alloc_new_window_result( +		OCFS2_LOCAL_ALLOC(alloc)->la_bm_off, +		le32_to_cpu(alloc->id1.bitmap1.i_total));  bail: -	mlog_exit(status); +	if (status) +		mlog_errno(status);  	return status;  } @@ -1243,8 +1258,6 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,  	struct ocfs2_dinode *alloc_copy = NULL;  	struct ocfs2_alloc_context *ac = NULL; -	mlog_entry_void(); -  	ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_SLIDE);  	/* This will lock the main bitmap for us. */ @@ -1318,13 +1331,13 @@ bail:  	if (main_bm_inode)  		iput(main_bm_inode); -	if (alloc_copy) -		kfree(alloc_copy); +	kfree(alloc_copy);  	if (ac)  		ocfs2_free_alloc_context(ac); -	mlog_exit(status); +	if (status) +		mlog_errno(status);  	return status;  }  | 
