[Ocfs2-commits] mfasheh commits r1540 - branches/dlm-changes/src
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Oct 1 19:12:49 CDT 2004
Author: mfasheh
Date: 2004-10-01 19:12:47 -0500 (Fri, 01 Oct 2004)
New Revision: 1540
Modified:
branches/dlm-changes/src/alloc.c
branches/dlm-changes/src/alloc.h
branches/dlm-changes/src/localalloc.c
Log:
* make local alloc use the reserve/claim api.
* gets rid of ocfs_find_contiguous_space_from_bitmap
Modified: branches/dlm-changes/src/alloc.c
===================================================================
--- branches/dlm-changes/src/alloc.c 2004-10-01 22:32:04 UTC (rev 1539)
+++ branches/dlm-changes/src/alloc.c 2004-10-02 00:12:47 UTC (rev 1540)
@@ -114,11 +114,6 @@
static int ocfs_extent_contig(struct inode *inode, ocfs2_extent_rec *ext,
u64 blkno);
-static int ocfs_reserve_main_bitmap_bits(ocfs_super *osb,
- ocfs_journal_handle *handle,
- u32 bits_wanted,
- ocfs2_alloc_context *ac);
-
static int ocfs_claim_main_bitmap_bits(ocfs_super *osb,
ocfs_journal_handle *handle,
ocfs2_alloc_context *ac,
@@ -2936,10 +2931,10 @@
return(status);
}
-static int ocfs_reserve_main_bitmap_bits(ocfs_super *osb,
- ocfs_journal_handle *handle,
- u32 bits_wanted,
- ocfs2_alloc_context *ac)
+int ocfs_reserve_main_bitmap_bits(ocfs_super *osb,
+ ocfs_journal_handle *handle,
+ u32 bits_wanted,
+ ocfs2_alloc_context *ac)
{
int status = 0;
struct inode *bitmap_inode;
Modified: branches/dlm-changes/src/alloc.h
===================================================================
--- branches/dlm-changes/src/alloc.h 2004-10-01 22:32:04 UTC (rev 1539)
+++ branches/dlm-changes/src/alloc.h 2004-10-02 00:12:47 UTC (rev 1540)
@@ -106,4 +106,12 @@
*/
return(fe->id2.i_list.l_tree_depth + 2);
}
+
+/* This is for local alloc ONLY. Others should use the generic apis
+ * above. */
+int ocfs_reserve_main_bitmap_bits(ocfs_super *osb,
+ ocfs_journal_handle *handle,
+ u32 bits_wanted,
+ ocfs2_alloc_context *ac);
+
#endif /* OCFS2_ALLOC_H */
Modified: branches/dlm-changes/src/localalloc.c
===================================================================
--- branches/dlm-changes/src/localalloc.c 2004-10-01 22:32:04 UTC (rev 1539)
+++ branches/dlm-changes/src/localalloc.c 2004-10-02 00:12:47 UTC (rev 1540)
@@ -68,11 +68,6 @@
static void ocfs_clear_local_alloc(ocfs2_dinode *alloc);
-static int ocfs_local_alloc_new_window(ocfs_super *osb,
- struct buffer_head *lock_bh,
- struct inode *bm_inode,
- ocfs_journal_handle *handle);
-
static int ocfs_sync_local_from_shutdown(ocfs_super *osb,
ocfs_bitmap_free_head **f,
struct buffer_head *local_alloc_bh,
@@ -84,17 +79,19 @@
struct inode *main_bm_inode,
struct buffer_head *main_bm_bh);
+static int ocfs_local_alloc_reserve_for_window(ocfs_super *osb,
+ ocfs_journal_handle *handle,
+ ocfs2_alloc_context **ac,
+ struct inode **bitmap_inode,
+ struct buffer_head **bitmap_bh);
+
+static int ocfs_local_alloc_new_window(ocfs_super *osb,
+ ocfs_journal_handle *handle,
+ ocfs2_alloc_context *ac);
+
static int ocfs_local_alloc_slide_window(ocfs_super *osb,
struct inode * local_alloc_inode);
-static int ocfs_find_contiguous_space_from_bitmap(ocfs_super *osb,
- ocfs_journal_handle *handle,
- __u64 file_size,
- u32 *cluster_off,
- u32 *cluster_count,
- struct buffer_head *bh,
- struct inode *bitmap_inode);
-
/*
* ocfs_local_alloc_window_bits
*
@@ -624,12 +621,11 @@
*
* pass it the bitmap lock in lock_bh if you have it.
*/
-static int ocfs_local_alloc_new_window(ocfs_super *osb, struct buffer_head *lock_bh,
- struct inode *bm_inode,
- ocfs_journal_handle *handle)
+static int ocfs_local_alloc_new_window(ocfs_super *osb,
+ ocfs_journal_handle *handle,
+ ocfs2_alloc_context *ac)
{
int status = 0;
- __u64 alloc_bytes;
u32 cluster_off, cluster_count;
ocfs2_dinode *alloc = NULL;
@@ -640,18 +636,17 @@
LOG_TRACE_STR("asking me to alloc a new window over a"
" non-empty one");
- /* we try to use find_contig_space_from_bitmap here for now. */
- alloc_bytes = (u64)ocfs_local_alloc_window_bits(osb) << osb->s_clustersize_bits;
- LOG_TRACE_ARGS("Allocating %llu bytes (%u clusters) for a "
- "new window.\n", alloc_bytes,
+ LOG_TRACE_ARGS("Allocating %u clusters for a new window.\n",
ocfs_local_alloc_window_bits(osb));
-
- status = ocfs_find_contiguous_space_from_bitmap(osb, handle,
- alloc_bytes,
- &cluster_off,
- &cluster_count,
- lock_bh,
- bm_inode);
+ /* we used the main bitmap specific reserve function, but we
+ * set everything up nicely, so there's no reason why we can't
+ * use the generic claim. */
+ status = ocfs_claim_bits(osb,
+ handle,
+ ac,
+ ocfs_local_alloc_window_bits(osb),
+ &cluster_off,
+ &cluster_count);
if (status < 0) {
if (status != -ENOSPC)
LOG_ERROR_STATUS(status);
@@ -856,6 +851,49 @@
return(status);
} /* ocfs_sync_local_to_main */
+static int ocfs_local_alloc_reserve_for_window(ocfs_super *osb,
+ ocfs_journal_handle *handle,
+ ocfs2_alloc_context **ac,
+ struct inode **bitmap_inode,
+ struct buffer_head **bitmap_bh)
+{
+ int status;
+
+ *ac = kmalloc(sizeof(ocfs2_alloc_context), GFP_KERNEL);
+ if (!(*ac)) {
+ status = -ENOMEM;
+ LOG_ERROR_STATUS(status);
+ goto bail;
+ }
+ memset(*ac, 0, sizeof(ocfs2_alloc_context));
+ (*ac)->ac_handle = handle;
+
+ (*ac)->ac_bits_wanted = ocfs_local_alloc_window_bits(osb);
+ status = ocfs_reserve_main_bitmap_bits(osb,
+ handle,
+ (*ac)->ac_bits_wanted,
+ *ac);
+ if (status < 0) {
+ LOG_ERROR_STATUS(status);
+ goto bail;
+ }
+ (*ac)->ac_which = OCFS_AC_USE_MAIN;
+
+ *bitmap_inode = (*ac)->ac_inode;
+ igrab(*bitmap_inode);
+ *bitmap_bh = (*ac)->ac_bh;
+ get_bh(*bitmap_bh);
+ status = 0;
+bail:
+ if ((status < 0) && *ac) {
+ ocfs_free_alloc_context(*ac);
+ *ac = NULL;
+ }
+
+ LOG_EXIT_STATUS(status);
+ return(status);
+}
+
/* Note that we do *NOT* lock the local alloc inode here as
* it's been locked already for us. */
static int ocfs_local_alloc_slide_window(ocfs_super *osb,
@@ -867,6 +905,7 @@
ocfs_journal_handle *handle = NULL;
ocfs2_dinode *alloc;
ocfs2_dinode *alloc_copy = NULL;
+ ocfs2_alloc_context *ac = NULL;
LOG_ENTRY();
@@ -886,18 +925,17 @@
goto bail;
}
- /* Get the allocation lock here */
- status = ocfs_acquire_lock(osb, OCFS_LKM_EXMODE,
- 0, &main_bm_bh, main_bm_inode);
+ /* This will lock the main bitmap for us. */
+ status = ocfs_local_alloc_reserve_for_window(osb,
+ handle,
+ &ac,
+ &main_bm_inode,
+ &main_bm_bh);
if (status < 0) {
- main_bm_bh = NULL;
if (status != -EINTR)
LOG_ERROR_STATUS (status);
goto bail;
}
- ocfs_handle_add_lock(handle, OCFS_LKM_EXMODE,
- 0, main_bm_inode);
- ocfs_handle_add_inode(handle, main_bm_inode);
handle = ocfs_start_trans(osb, handle, OCFS_WINDOW_MOVE_CREDITS);
if (!handle) {
@@ -943,8 +981,7 @@
goto bail;
}
- status = ocfs_local_alloc_new_window(osb, main_bm_bh, main_bm_inode,
- handle);
+ status = ocfs_local_alloc_new_window(osb, handle, ac);
if (status < 0) {
if (status != -ENOSPC)
LOG_ERROR_STATUS(status);
@@ -967,125 +1004,10 @@
if (alloc_copy)
kfree(alloc_copy);
+ if (ac)
+ ocfs_free_alloc_context(ac);
+
LOG_EXIT_STATUS(status);
return(status);
}
-/*
- * ocfs_find_contiguous_space_from_bitmap()
- *
- * Used only from local alloc right now. Eventually will go away, so
- * don't add more callers to this function. Use the reserve / claim
- * apis instead as they'll even get you distcongiuous areas.
- *
- * TODO: The Bitmap stuff needs to be changed for handling more than 32 bits...
- * Although we can go upto 4k(clustersize) * 8 * 4M(max 32 bits for now...)
- *
- * Returns 0 on success, < 0 on error.
- */
-static int ocfs_find_contiguous_space_from_bitmap(ocfs_super *osb,
- ocfs_journal_handle *handle,
- __u64 file_size,
- u32 *cluster_off,
- u32 *cluster_count,
- struct buffer_head *bh,
- struct inode *bitmap_inode)
-{
- int status = 0, startbh, numblocks;
- u32 bitoffset = 0, num_clusters = 0;
- ocfs2_dinode *bm_lock;
- __u32 bitmapblocks; /* we only care about the valid blocks */
- __u32 free_bits;
-
- LOG_ENTRY ();
-
- OCFS_ASSERT(osb);
- OCFS_ASSERT(bh);
- OCFS_ASSERT(bitmap_inode);
- OCFS_ASSERT(handle);
-
- status = ocfs_journal_access(handle, bh, OCFS_JOURNAL_ACCESS_WRITE);
- if (status < 0) {
- LOG_ERROR_STATUS(status);
- goto leave;
- }
-
- bm_lock = (ocfs2_dinode *) bh->b_data;
-
- num_clusters = (u32) ((u64) (file_size + (osb->s_clustersize-1)) >>
- osb->s_clustersize_bits);
- if (num_clusters == 0) {
- LOG_ERROR_STR ("DISK_FULL?: num_clusters==0");
- status = 0;
- goto leave;
- }
-
- free_bits = le32_to_cpu(bm_lock->id1.bitmap1.i_total) -
- le32_to_cpu(bm_lock->id1.bitmap1.i_used);
-
- if (num_clusters > free_bits) {
- LOG_ERROR_ARGS("Disk Full: num_clusters=%u, free_bits=%u\n",
- num_clusters, free_bits);
- status = -ENOSPC;
- goto leave;
- }
-
- bitmapblocks =
- ocfs_blocks_for_bits(osb->sb,
- osb->cluster_bitmap.validbits);
-
- /* Ok, somewhat lame, but we submit the whole bitmap for reading here*/
- if (ocfs_read_bhs(osb, osb->bitmap_blkno << osb->sb->s_blocksize_bits,
- bitmapblocks << osb->sb->s_blocksize_bits,
- osb->cluster_bitmap.chunk, OCFS_BH_CACHED, bitmap_inode)) {
- LOG_ERROR_STATUS(-EIO);
- goto leave;
- }
-
- status = 0;
- status = ocfs_find_clear_bits (osb, &osb->cluster_bitmap,
- num_clusters, &bitoffset,
- NULL);
- if (status < 0) {
- osb->cluster_bitmap.failed++;
- LOG_TRACE_ARGS("Cannot allocate %u contiguous clusters "
- "for system file\n", num_clusters);
- status = -ENOSPC;
- goto leave;
- }
-
- LOG_TRACE_ARGS ("setting %u bits at bit offset=%u\n",
- num_clusters, bitoffset);
-
- ocfs_set_bits(osb->sb, handle, &osb->cluster_bitmap, bitoffset,
- num_clusters);
-
- /* Ok, write out the bitmap now. We optimize only by writing
- * out the bitmap blocks which have changed, and not all of
- * them like before. */
- numblocks = ocfs_bitmap_blocks_affected(osb->sb,
- bitoffset,
- num_clusters,
- &startbh);
-
- LOG_TRACE_ARGS("bitoffset = %u, num_clusters = %u, startbh = %u, numblocks = %u\n", bitoffset, num_clusters, startbh, numblocks);
-
- /* write the bitmap size info to the lock sector */
- bm_lock->id1.bitmap1.i_used =
- ocfs_count_bits(osb->sb, &osb->cluster_bitmap);
-
- status = ocfs_journal_dirty(handle, bh);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto leave;
- }
-
- *cluster_off = bitoffset;
- *cluster_count = num_clusters;
- status = 0;
-
-leave:
- LOG_EXIT_STATUS (status);
- return status;
-} /* ocfs_find_contiguous_space_from_bitmap */
-
More information about the Ocfs2-commits
mailing list