[Ocfs2-commits] rev 4 - trunk
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Nov 21 17:10:40 CST 2003
Author: manish
Date: 2003-11-21 17:10:37 -0600 (Fri, 21 Nov 2003)
New Revision: 4
Removed:
trunk/iosup.c
trunk/trans.c
Log:
Sync
Deleted: trunk/iosup.c
===================================================================
--- trunk/iosup.c 2003-11-20 00:57:28 UTC (rev 3)
+++ trunk/iosup.c 2003-11-21 23:10:37 UTC (rev 4)
@@ -1,826 +0,0 @@
-/*
- * ocfsiosup.c
- *
- * Read and write to disk
- *
- * Copyright (C) 2002 Oracle Corporation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have recieved a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
- *
- * Authors: Neeraj Goyal, Suchit Kaura, Kurt Hackel, Sunil Mushran,
- * Manish Singh, Wim Coekaerts, Mark Fasheh
- */
-
-#include "ocfs.h"
-#ifdef LINUX_2_5
-#include <linux/buffer_head.h>
-#else
-#include <linux/locks.h>
-#endif
-#include <linux/pagemap.h>
-
-/* Tracing */
-#define OCFS_DEBUG_CONTEXT OCFS_DEBUG_CONTEXT_IOSUP
-
-#if 0
-static int LinuxWriteForceDisk (ocfs_super * osb, void *Buffer, __u32 Length, __u64 Offset, bool Cached);
-static int LinuxReadForceDisk (ocfs_super * osb, void *Buffer, __u32 Length, __u64 Offset, bool Cached);
-
-/*
- * ocfs_submit_vol_metadata()
- *
- */
-int ocfs_submit_vol_metadata(ocfs_super *osb, ocfs_offset_map *map_buf, __u32 num)
-{
- int ret, i, j, nr;
- __u64 off, blk;
- __u32 len, tot;
- struct super_block *sb;
- struct buffer_head *bh;
- struct buffer_head **bhs = NULL;
- ocfs_blockdev dev;
-
- LOG_ENTRY ();
-
- sb = osb->sb;
- dev = OCFS_GET_BLOCKDEV(sb);
- ret = 0;
- tot=0;
-
- for (i=0; i<num; i++)
- tot += map_buf[i].length;
-
- if (tot==0)
- goto bail;
-
- if (tot % 512) {
- LOG_ERROR_STR("bad size!");
- ret = -EFAIL;
- goto bail;
- }
- tot >>= 9;
- if (tot > ((1024*128)/sizeof(bh))) {
- LOG_ERROR_ARGS ("getting write for %d blocks", tot);
- }
- bhs = kmalloc (tot * sizeof(bh), GFP_NOFS);
- if (bhs == NULL) {
- ret = -ENOMEM;
- LOG_TRACE_STR("cannot allocate bh mem");
- goto bail;
- }
-
- nr = 0;
- for (i=0; i<num; i++) {
- off = map_buf[i].actual_disk_off;
- len = map_buf[i].length;
- blk = off >> 9;
- for (j=0; j<(len>>9); j++) {
- bh = getblk (dev, blk++, 512);
- bhs[nr++] = bh;
- }
- }
- ll_rw_block (WRITE, nr, bhs);
-
- for (i = 0 ; i < nr ; i++) {
- bh = bhs[i];
- wait_on_buffer(bh);
- brelse(bh);
- }
-bail:
- if (bhs)
- kfree(bhs);
-
- LOG_EXIT_STATUS (ret);
- return ret;
-} /* ocfs_submit_vol_metadata */
-
-
-#if 0
-/*
- * LinuxWriteForceDisk()
- *
- */
-static int LinuxWriteForceDisk (ocfs_super * osb, void *Buffer, __u32 Length, __u64 Offset, bool Cached)
-{
- int status = 0;
- int nr, i;
- struct super_block *sb;
- __u64 blocknum;
- ocfs_blockdev dev;
- struct buffer_head *bh;
- struct buffer_head **bhs = NULL;
- char *kaddr;
-
- LOG_ENTRY_ARGS ("(0x%08x, 0x%08x, %u, %u.%u)\n", osb, Buffer, Length,
- HI (Offset), LO (Offset));
-
-#ifdef NO_CACHE
- Cached = false;
-#endif
-
- if (Length % 512) {
- LOG_ERROR_STATUS (status = -EFAIL);
- goto bail;
- }
-
- if (osb == NULL || osb->sb == NULL) {
- LOG_ERROR_STATUS (status = -EFAIL);
- goto bail;
- }
-
- sb = osb->sb;
- dev = OCFS_GET_BLOCKDEV(sb);
- if (Cached && Offset >= osb->vol_layout.data_start_off) {
- ocfs_create_log_extent_map(osb, Offset, (__u64)Length);
- }
-
- nr = (Length + 511) >> 9;
- if (nr > 256)
- LOG_TRACE_ARGS ("Getting write for %d blocks\n", nr);
- bhs = kmalloc (nr * sizeof(bh), GFP_KERNEL);
- if (bhs == NULL) {
- LOG_ERROR_STATUS (status = -ENOMEM);
- goto bail;
- }
-
- blocknum = Offset >> sb->s_blocksize_bits;
-
- if (blocknum == 0) {
- ocfs_vol_disk_hdr *hdr;
- LOG_TRACE_STR ("Blocknum is zero!!!");
- hdr = (ocfs_vol_disk_hdr *)Buffer;
- if (memcmp(hdr->signature, OCFS_VOLUME_SIGNATURE, strlen(OCFS_VOLUME_SIGNATURE)) != 0) {
- status = -EIO;
- LOG_ERROR_STR("WARNING! attempting to write non volume header to block 0");
- goto bail;
- }
- }
-
- /* build an array of bh's and prepare them for submit */
- for (i = 0 ; i < nr ; i++) {
- bh = getblk (dev, blocknum++, sb->s_blocksize);
- if (bh == NULL) {
- LOG_ERROR_STATUS (status = -EFAIL);
- goto bail;
- }
- lock_buffer(bh);
-
- /* if the new buffer is the same as the old buffer then don't bother doing anything
- * this is only the case for locks that we rewrite to disk
- * and are awlays 1 sector sized writes coming in
- */
- kaddr = kmap(bh->b_page);
-#ifdef NO_CACHE
- if (nr == 1 && Offset >= osb->vol_layout.data_start_off)
-#else
- if (Cached && nr == 1 && Offset >= osb->vol_layout.data_start_off)
-#endif
- {
- if (memcmp(kaddr + ((unsigned long)(bh)->b_data & ~PAGE_MASK), Buffer, 512) == 0) {
- kunmap(bh->b_page);
- unlock_buffer(bh);
- brelse(bh);
- goto bail;
- }
- }
- memcpy(kaddr + ((unsigned long)(bh)->b_data & ~PAGE_MASK), Buffer, 512);
- kunmap(bh->b_page);
-#ifdef LINUX_2_5
- set_buffer_uptodate(bh);
-#else
- mark_buffer_uptodate(bh, true);
-#endif
- mark_buffer_dirty(bh);
- unlock_buffer(bh);
- bhs[i] = bh;
- Buffer = (__u8 *) Buffer + sb->s_blocksize;
- }
-
- /* we do not do ll_rw_block if we are in Cached, 1 block, and above datastartoff */
- /* otherwise we always call ll_rw_block */
-
- if (!Cached || nr != 1 || Offset < osb->vol_layout.data_start_off)
- ll_rw_block (WRITE, nr, bhs);
-
- /* reap blocks */
- for (i = 0 ; i < nr ; i++) {
- bh = bhs[i];
- if (!Cached || ( nr != 1 || Offset < osb->vol_layout.data_start_off))
- wait_on_buffer(bh);
- brelse(bh);
- }
-
-
- bail:
- if (bhs)
- kfree(bhs);
-
- LOG_EXIT_STATUS (status);
- return status;
-} /* LinuxWriteForceDisk */
-#endif
-
-
-#if 0
-static int LinuxReadForceDisk (ocfs_super * osb, void *Buffer, __u32 Length, __u64 Offset, bool Cached)
-{
- int status = 0;
- struct super_block *sb;
- int nr, i;
- __u64 blocknum;
- ocfs_blockdev dev;
- struct buffer_head *bh;
- struct buffer_head **bhs = NULL;
- char *kaddr;
-
- LOG_ENTRY_ARGS ("(0x%08x, 0x%08x, %u, %u.%u)\n", osb, Buffer, Length,
- HI (Offset), LO (Offset));
-
-#ifdef NO_CACHE
- Cached = false;
-#endif
-
- if (Length % 512) {
- LOG_ERROR_STATUS (status = -EFAIL);
- goto bail;
- }
-
- if (osb == NULL || osb->sb == NULL) {
- LOG_ERROR_STATUS (status = -EFAIL);
- goto bail;
- }
-
- sb = osb->sb;
- dev = OCFS_GET_BLOCKDEV(sb);
-
- nr = (Length + 511) >> 9;
- bhs = kmalloc (nr * sizeof(bh), GFP_KERNEL);
- if (bhs == NULL) {
- LOG_ERROR_STATUS (status = -ENOMEM);
- goto bail;
- }
-
- blocknum = Offset >> sb->s_blocksize_bits;
-
- if (nr == 0) {
- LOG_TRACE_STR ("No buffers will be read!!!");
- LOG_TRACE_ARGS
- ("Len=%u Off=%u.%u numbuffers=%u blocknum=%u.%u\n", Length,
- HI (Offset), LO (Offset), nr, HI (blocknum),
- LO (blocknum));
- }
-
- for (i = 0 ; i < nr ; i++) {
- bh = getblk (dev, blocknum++, sb->s_blocksize);
- if (bh == NULL) {
- LOG_ERROR_STATUS (status = -EFAIL);
- goto bail;
- }
- bhs[i] = bh;
- if (!Cached || Offset < osb->vol_layout.data_start_off) {
- lock_buffer(bh);
- if (!buffer_dirty(bh))
-#ifdef LINUX_2_5
- clear_buffer_uptodate(bh);
-#else
- mark_buffer_uptodate(bh, false);
-#endif
- unlock_buffer(bh);
- }
- }
-
- ll_rw_block(READ, nr, bhs);
-
- for (i = 0; i < nr ; i++) {
- bh = bhs[i];
- wait_on_buffer(bh);
- lock_buffer(bh);
- kaddr = kmap(bh->b_page);
- memcpy(Buffer, kaddr + ((unsigned long)(bh)->b_data & ~PAGE_MASK), 512);
- kunmap(bh->b_page);
- unlock_buffer(bh);
- Buffer = (__u8 *) Buffer + sb->s_blocksize;
- brelse(bh);
- }
-
- bail:
- if (bhs)
- kfree(bhs);
-
- LOG_EXIT_STATUS (status);
- return status;
-
-} /* LinuxReadForceDisk */
-#endif
-
-#define OCFS_METADATA_LIMIT (7 * ONE_MEGA_BYTE)
-/*
- * ocfs_write_metadata()
- *
- */
-int ocfs_write_metadata (ocfs_super * osb, void *Buffer, __u32 Length, __u64 Offset)
-{
- int status = 0;
- __s64 tempVbo = 0;
- __s64 tempLbo = 0;
- bool bRet = false;
-
- LOG_ENTRY_ARGS ("(0x%08x, 0x%08x, %u, %u.%u)\n", osb, Buffer, Length,
- HI (Offset), LO (Offset));
- tempLbo = tempVbo = Offset;
-
- {
- int i = 0;
-
- while (((osb->needs_flush)) && (i < 3000)
- && (!osb->trans_in_progress)) {
- ocfs_sleep (100); /* 100ms */
- i++;
- }
- }
-
- ocfs_down_sem (&(osb->map_lock), true);
- bRet =
- ocfs_add_extent_map_entry (osb, &osb->metadata_map, tempVbo, tempLbo,
- (__u32) Length);
- if (!bRet) {
- ocfs_remove_extent_map_entry (osb, &osb->metadata_map, tempVbo,
- Length);
- bRet =
- ocfs_add_extent_map_entry (osb, &osb->metadata_map, tempVbo,
- tempLbo, (__u32) Length);
- }
-
- {
- __u32 runs, idx, length, tot = 0;
- __s64 v, l;
-
- runs = osb->metadata_map.count;
- for ( idx = 0; idx < runs; idx++ )
- {
- if(!ocfs_get_next_extent_map_entry(osb, &osb->metadata_map, idx, &v , &l, &length))
- {
- continue;
- }
- tot += length;
- }
-
- if(tot >= OCFS_METADATA_LIMIT) {
- osb->needs_flush = true;
- }
- }
-
- ocfs_up_sem (&(osb->map_lock));
-
- status = LinuxWriteForceDisk (osb, Buffer, Length, Offset, true);
- if (status < 0)
- LOG_ERROR_STATUS (status);
-
- LOG_EXIT_STATUS (status);
- return status;
-} /* ocfs_write_metadata */
-
-
-/*
- * ocfs_read_metadata()
- *
- */
-int ocfs_read_metadata (ocfs_super * osb, void *Buffer, __u32 Length, __u64 Offset)
-{
- int status = 0;
- __u32 num_runs = 0, idx;
- __s64 to_find = 0, found_foff = 0, found_doff = 0;
- __u32 tempLen = 0, num_md = 0, num_data = 0;
- __u32 rem, length, i = 0;
- bool free_data=false, free_md=false;
- ocfs_io_runs *data = NULL, *md = NULL;
-
- LOG_ENTRY_ARGS ("(0x%08x, 0x%08x, %u, %u.%u)\n", osb, Buffer, Length,
- HI (Offset), LO (Offset));
-
- /* try to use prealloc ioruns if available */
- ocfs_down_sem (&osb->osb_res, true);
- if (! OSB_PREALLOC_LOCK_TEST(osb, OSB_DATA_LOCK))
- {
- OSB_PREALLOC_LOCK_SET(osb, OSB_DATA_LOCK);
- data = osb->data_prealloc;
- }
- if (! OSB_PREALLOC_LOCK_TEST(osb, OSB_MD_LOCK))
- {
- OSB_PREALLOC_LOCK_SET(osb, OSB_MD_LOCK);
- md = osb->md_prealloc;
- }
- ocfs_up_sem(&osb->osb_res);
-
- if (data==NULL)
- {
- free_data=true;
- data = ocfs_malloc (IORUN_ALLOC_SIZE);
- if (data == NULL) {
- LOG_ERROR_STATUS (status = -ENOMEM);
- goto finally;
- }
- }
- if (md==NULL)
- {
- free_md=true;
- md = ocfs_malloc (IORUN_ALLOC_SIZE);
- if (md == NULL) {
- LOG_ERROR_STATUS (status -ENOMEM);
- goto finally;
- }
- }
-
- rem = Length;
- length = 0;
- to_find = Offset;
-
- {
- int i = 0;
-
- while (((osb->needs_flush)) && (i < 3000)
- && (!osb->trans_in_progress)) {
- ocfs_sleep (100); /* 100ms */
- i++;
- }
- }
-
- ocfs_down_sem (&(osb->map_lock), true);
- num_runs = osb->metadata_map.count;
- for (idx = 0; idx < num_runs; idx++) {
- bool rr;
- rr = ocfs_get_next_extent_map_entry (osb, &osb->metadata_map,
- idx, &found_foff, &found_doff, &tempLen);
- if (!rr)
- continue;
-
- length = tempLen;
-
- /* |***TO*FIND***| */
- /* |---FOUND---| */
- if (found_doff >= (to_find + rem))
- break;
-
- /* |***TO*FIND***| */
- /* |---FOUND---| */
- if (to_find >= (found_doff + length))
- continue;
- /* |***TO*FIND***| */
- /* |---FOUND-------------------| */
- if ((to_find >= found_doff) && ((to_find + rem) <= (found_doff + length))) {
- md[num_md].offset = to_find;
- md[num_md].disk_off = to_find;
- md[num_md].byte_cnt = rem;
- rem -= md[num_md].byte_cnt;
- to_find += md[num_md].byte_cnt;
- num_md++;
- break;
-
- }
- /* |***TO*FIND***|***or****| */
- /* |---FOUND---| */
- else if ((to_find < found_doff) && ((to_find + rem) > found_doff)) {
- data[num_data].offset = to_find;
- data[num_data].disk_off = to_find;
- data[num_data].byte_cnt = found_doff - to_find;
- rem -= data[num_data].byte_cnt;
- to_find += data[num_data].byte_cnt;
- num_data++;
-
- md[num_md].offset = found_doff;
- md[num_md].disk_off = found_doff;
- md[num_md].byte_cnt = (rem > length) ? length : rem;
-
- rem -= md[num_md].byte_cnt;
- to_find += md[num_md].byte_cnt;
- num_md++;
-
- if (rem > 0)
- continue;
- break;
- }
- /* |***TO*FIND***| */
- /* |---FOUND---| */
- else if ((to_find >= found_doff) && ((to_find + rem) > (found_doff + length))) {
- md[num_md].offset = to_find;
- md[num_md].disk_off = to_find;
- md[num_md].byte_cnt = length - (to_find - found_doff);
- rem -= md[num_md].byte_cnt;
- to_find += md[num_md].byte_cnt;
- num_md++;
- continue;
- }
- }
- ocfs_up_sem (&(osb->map_lock));
-
- if (rem > 0) {
- data[num_data].offset = to_find;
- data[num_data].disk_off = to_find;
- data[num_data].byte_cnt = rem;
- num_data++;
- }
-
- /* look for the specified offset in the map .if it exists then */
- /* do the read from cache, else go to disk. */
- for (i = 0; i < num_data; i++) {
- __u64 newOffset = 0;
- __u32 newLength = data[i].byte_cnt;
- __u32 diff;
-
- newOffset = data[i].disk_off;
- diff = (__u32) (newOffset - Offset);
-
- status =
- ocfs_read_force_disk (osb, (void *) ((__u8 *) Buffer + diff),
- newLength, newOffset);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
- }
-
- for (i = 0; i < num_md; i++) {
- __u64 newOffset = 0;
- __u32 diff;
- __u32 newLength = md[i].byte_cnt;
-
- newOffset = md[i].disk_off;
-
- diff = (__u32) (newOffset - Offset);
-
- status = LinuxReadForceDisk (osb, (void *) ((__u8 *) Buffer + diff),
- newLength, newOffset, true);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
- }
-
- finally:
- if (data && free_data) {
- ocfs_free (data);
- data = NULL;
- }
-
- if (md && free_md) {
- ocfs_free (md);
- md = NULL;
- }
-
- ocfs_down_sem (&osb->osb_res, true);
- if (!free_data && OSB_PREALLOC_LOCK_TEST(osb, OSB_DATA_LOCK))
- {
- OSB_PREALLOC_LOCK_CLEAR(osb, OSB_DATA_LOCK);
- }
- if (!free_md && OSB_PREALLOC_LOCK_TEST(osb, OSB_MD_LOCK))
- {
- OSB_PREALLOC_LOCK_CLEAR(osb, OSB_MD_LOCK);
- }
- ocfs_up_sem(&osb->osb_res);
-
- LOG_EXIT_STATUS (status);
- return (status);
-} /* ocfs_read_metadata */
-
-/*
- * ocfs_write_force_disk()
- *
- */
-int ocfs_write_force_disk (ocfs_super * osb, void *Buffer, __u32 Length, __u64 Offset)
-{
- return LinuxWriteForceDisk (osb, Buffer, Length, Offset, false);
-} /* ocfs_write_force_disk */
-
-/*
- * ocfs_write_disk()
- *
- */
-int ocfs_write_disk (ocfs_super * osb, void *Buffer, __u32 Length, __u64 Offset)
-{
- return LinuxWriteForceDisk (osb, Buffer, Length, Offset, false);
-} /* ocfs_write_disk */
-
-/*
- * ocfs_read_force_disk()
- *
- */
-int ocfs_read_force_disk (ocfs_super * osb, void *Buffer, __u32 Length, __u64 Offset)
-{
- return LinuxReadForceDisk (osb, Buffer, Length, Offset, false);
-} /* ocfs_read_force_disk */
-
-/*
- * ocfs_read_force_disk_ex()
- *
- */
-int ocfs_read_force_disk_ex (ocfs_super * osb, void **Buffer, __u32 AllocLen, __u32 ReadLen, __u64 Offset)
-{
- int status = 0;
-
- LOG_ENTRY ();
-
- if (*Buffer == NULL) {
- *Buffer = ocfs_malloc (AllocLen);
- if (*Buffer == NULL) {
- LOG_ERROR_STATUS (status = -ENOMEM);
- goto bail;
- }
- }
-
- status = ocfs_read_force_disk (osb, *Buffer, ReadLen, Offset);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto bail;
- }
-
- bail:
- LOG_EXIT_STATUS (status);
- return status;
-} /* ocfs_read_force_disk_ex */
-
-/*
- * ocfs_read_disk()
- *
- */
-int ocfs_read_disk (ocfs_super * osb, void *Buffer, __u32 Length, __u64 Offset)
-{
- if (Offset < osb->vol_layout.bitmap_off)
- return LinuxReadForceDisk (osb, Buffer, Length, Offset, false);
- return ocfs_read_metadata (osb, Buffer, Length, Offset);
-} /* ocfs_read_disk */
-
-/*
- * ocfs_read_disk_ex()
- *
- */
-int ocfs_read_disk_ex (ocfs_super * osb, void **Buffer, __u32 AllocLen, __u32 ReadLen, __u64 Offset)
-{
- int status = 0;
-
- LOG_ENTRY ();
-
- if (*Buffer == NULL) {
- *Buffer = ocfs_malloc (AllocLen);
- if (*Buffer == NULL) {
- LOG_ERROR_STATUS (status = -ENOMEM);
- goto bail;
- }
- }
-
- status = ocfs_read_disk (osb, *Buffer, ReadLen, Offset);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto bail;
- }
-
- bail:
- LOG_EXIT_STATUS (status);
- return status;
-} /* ocfs_read_disk_ex */
-#endif
-
-/* ALL THE '#if 0' added here by Mark to disable caching
- * ocfs_commit_cache()
- *
- */
-int ocfs_commit_cache (ocfs_super * osb, bool Flag)
-{
- int status = 0;
-
- LOG_ENTRY ();
-
- //ocfs_flush_cache (osb);
-
- //ocfs_sleep(500);
-
- ocfs_down_sem (&(osb->map_lock), true);
-#if 0
- status = ocfs_write_map_file (osb);
- if (status >= 0) {
-
- status = ocfs_process_log_file (osb, Flag);
- if (status < 0)
- LOG_ERROR_STATUS (status);
-#endif
- status = ocfs_extend_system_file (osb,
- (OCFS_FILE_VOL_LOG_FILE + osb->node_num),
- 0, NULL, NULL);
- if (status < 0)
- LOG_ERROR_STATUS (status);
-
- osb->log_file_size = 0;
-
- status = ocfs_extend_system_file (osb,
- (OCFS_FILE_VOL_META_DATA + osb->node_num),
- 0, NULL, NULL);
- if (status < 0)
- LOG_ERROR_STATUS (status);
-
- ocfs_extent_map_destroy (&osb->metadata_map);
- ocfs_extent_map_destroy (&osb->trans_map);
- ocfs_extent_map_init (&osb->metadata_map);
- ocfs_extent_map_init (&osb->trans_map);
-#if 0
- } else {
- if (status == -EWARNING)
- status = 0;
- else
- LOG_ERROR_STATUS (status);
- }
-#endif
- ocfs_up_sem (&(osb->map_lock));
-
-#if 0
- if (Flag)
- ocfs_commit_data(osb);
-#endif
-
- LOG_EXIT_STATUS (status);
- return status;
-} /* ocfs_commit_cache */
-
-#if 0
-/*
- * ocfs_read_file_entry()
- *
- * This function reads the File Entry from the disk.
- *
- * Returns 0 on success, < 0 on error
- */
-int ocfs_read_file_entry (ocfs_super * osb, ocfs_file_entry * FileEntry, __u64 DiskOffset)
-{
- int status = 0;
-
- LOG_ENTRY_ARGS ("(osb=%p, fileentry=%p, offset=%u.%u)\n", osb, FileEntry,
- HI (DiskOffset), LO (DiskOffset));
-
- OCFS_ASSERT (FileEntry);
- OCFS_ASSERT (osb);
-
- /* Size of File Entry is one sector */
- if (DiskOffset < osb->vol_layout.bitmap_off)
- status = LinuxReadForceDisk (osb, FileEntry, 512, DiskOffset, false);
- else
- status = ocfs_read_metadata (osb, FileEntry, 512, DiskOffset);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- }
-
- LOG_EXIT_STATUS (status);
- return (status);
-} /* ocfs_read_file_entry */
-
-
-/*
- * ocfs_write_file_entry()
- *
- * This function writes the File Entry to the disk.
- *
- * Returns 0 on success, < 0 on error
- */
-int ocfs_write_file_entry (ocfs_super * osb, ocfs_file_entry * FileEntry, __u64 Offset)
-{
- int status = 0;
-
- LOG_ENTRY ();
-
- OCFS_ASSERT (FileEntry);
- OCFS_ASSERT (osb);
-
- LOG_TRACE_ARGS ("File offset on the disk is %u.%u\n", HI (Offset),
- LO (Offset));
-
- /* size of File Entry is one sector */
- if ((DISK_LOCK_FILE_LOCK (FileEntry) == OCFS_DLM_ENABLE_CACHE_LOCK) &&
- (DISK_LOCK_CURRENT_MASTER (FileEntry) == osb->node_num) &&
- (Offset >= osb->vol_layout.bitmap_off)) {
- status =
- ocfs_write_metadata (osb, FileEntry, (__u32) osb->sect_size,
- Offset);
- } else {
- status =
- ocfs_write_disk (osb, FileEntry, (__u32) osb->sect_size,
- Offset);
- }
-
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- }
-
- LOG_EXIT_STATUS (status);
- return status;
-} /* ocfs_write_file_entry */
-#endif
Deleted: trunk/trans.c
===================================================================
--- trunk/trans.c 2003-11-20 00:57:28 UTC (rev 3)
+++ trunk/trans.c 2003-11-21 23:10:37 UTC (rev 4)
@@ -1,620 +0,0 @@
-/*
- * ocfsgentrans.c
- *
- * Logging and recovery for file system structures.
- *
- * Copyright (C) 2002 Oracle Corporation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have recieved a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
- *
- * Authors: Neeraj Goyal, Suchit Kaura, Kurt Hackel, Sunil Mushran,
- * Manish Singh, Wim Coekaerts, Mark Fasheh
- */
-
-
-
-/* We keep this file only so we can go back and look at the old
- * process_record or recover_vol when we need to. Once we're confident
- * that everything is as it should be, this file can be deleted. */
-
-
-
-#if 0
-#include <ocfs.h>
-
-/* Tracing */
-#define OCFS_DEBUG_CONTEXT OCFS_DEBUG_CONTEXT_TRANS
-
-/* COMMENT OUT REST OF FILE */
-
-/*
- * ocfs_process_record()
- *
- *
- * called by: ocfs_process_log()
- */
-static int ocfs_process_record (ocfs_super * osb, void *buffer)
-{
- int status = 0;
- ocfs_log_record *log_rec;
- ocfs_cleanup_record *clean_rec;
- struct buffer_head *fe_bh = NULL;
- struct buffer_head *lock_node_bh = NULL;
- __u8 *read_buf = NULL;
- __u32 node_num;
- ocfs_lock_res **lock_res_array = NULL;
-// ocfs_file_entry *fe = NULL;
-// ocfs_dir_node *lock_node = NULL;
-// __u32 index;
-// ocfs_extent_group *alloc_ext;
-// __u64 disk_off = 0;
-// __u32 num_upd;
-// __u32 i;
-// __u64 lock_id;
-// ocfs_lock_res *lock_res;
-// ocfs_lock_res *tmp_lockres;
-// int flags = 0;
-
- LOG_ENTRY_ARGS ("(0x%08x, 0x%08x)\n", osb, buffer);
-
- log_rec = (ocfs_log_record *) buffer;
- clean_rec = (ocfs_cleanup_record *) buffer;
-
- switch (log_rec->log_type) {
- case LOG_DELETE_ENTRY:
- /*
- ** Delete the entry from the dir node it was associated
- ** with. Now it can be reused.
- */
- status = ocfs_read_bh(osb, clean_rec->rec.del.ent_del,
- &fe_bh, 0);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- status = ocfs_read_bh(osb, clean_rec->rec.del.parent_dirnode_off, &lock_node_bh, 0);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- node_num = clean_rec->rec.del.node_num;
-
- /*
- ** Lock on directory shd be held by the node which
- ** either died or this node...
- */
- status = ocfs_del_file_entry (osb, fe_bh, lock_node_bh);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
- break;
-
- case LOG_FREE_BITMAP:
- status = ocfs_free_disk_bitmap (osb, buffer);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
- break;
-
- case LOG_TYPE_RECOVERY:
- /*
- ** This node was recovering another node and died.
- ** All locks in the function need to be recursive...
- */
- node_num = osb->node_recovering;
-
- status = old_ocfs_recover_vol (osb,
- log_rec->rec.recovery.node_num);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- /*
- ** Bad one. We should disable this
- ** volume and try and let somebody else
- ** do the recovery...
- */
- }
- osb->node_recovering = node_num;
- break;
-
-/* LOG_TYPE_DISK_ALLOC, LOG_DELETE_NEW_ENTRY and
- * LOG_MARK_DELETE_ENTRY are used in recover log only
- * and are therefore #ifdef'd out as we no longer
- * process that log.*/
-
-#if 0
- case LOG_TYPE_DISK_ALLOC:
- {
- switch (log_rec->rec.alloc.type) {
- case DISK_ALLOC_DIR_NODE:
- case DISK_ALLOC_EXTENT_NODE:
- status = ocfs_free_node_block (osb,
- log_rec->rec.alloc.file_off,
- log_rec->rec.alloc.length,
- log_rec->rec.alloc.node_num,
- log_rec->rec.alloc.type);
- break;
- default:
- break;
- }
- }
- break;
-
- case LOG_DELETE_NEW_ENTRY:
- status = ocfs_read_bh(osb, log_rec->rec.del.ent_del, &fe_bh, 0);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- status = ocfs_read_bh(osb, log_rec->rec.del.parent_dirnode_off, &lock_node_bh, 0);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- node_num = log_rec->rec.del.node_num;
-
- /*
- ** Lock on directory shd be held by the node which either
- ** died or this node...
- */
- status = ocfs_del_file_entry (osb, fe_bh, lock_node_bh);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
- break;
-
- case LOG_MARK_DELETE_ENTRY:
- status = ocfs_read_bh(osb, log_rec->rec.del.ent_del, &fe_bh, 0);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- if (log_rec->rec.del.flags & FLAG_RESET_VALID) {
- fe = (ocfs_file_entry *) OCFS_BH_GET_DATA(fe_bh);
- OCFS_SET_FLAG (fe->sync_flags, OCFS_SYNC_FLAG_VALID);
- flags = OCFS_FE_CACHE_FLAGS(osb, fe);
- OCFS_BH_PUT_DATA(fe_bh);
- fe = NULL;
-
- status = ocfs_write_bh(osb, fe_bh, flags);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- /* We are done... */
- status = 0;
- goto finally;
- }
-
- /*
- ** Read in the entry to be deleted. We are doing
- ** recovery on another node?
- ** What if we were in abort trans for this node???
- */
- node_num = log_rec->rec.del.node_num;
-
- fe = (ocfs_file_entry *) OCFS_BH_GET_DATA(fe_bh);
- /* This is recovery for a dead node */
- if (fe->sync_flags & OCFS_SYNC_FLAG_VALID) {
- OCFS_BH_PUT_DATA(fe_bh);
- fe = NULL;
- /* No recovery needed for the entry, let it stay */
- status = 0;
- goto finally;
- } else {
- OCFS_BH_PUT_DATA(fe_bh);
- fe = NULL;
- status = ocfs_delete_file_entry (osb, fe_bh,
- log_rec->rec.del.parent_dirnode_off,
- node_num);
- goto finally;
- }
- break;
-#endif
- default:
- break;
- }
-
-finally:
- if (fe_bh)
- brelse(fe_bh);
- if (lock_node_bh)
- brelse(lock_node_bh);
-
- ocfs_safefree (read_buf);
- ocfs_safefree (lock_res_array);
- LOG_EXIT_STATUS (status);
- return status;
-} /* ocfs_process_record */
-
-/*
- * old_ocfs_start_trans()
- *
- *
- * called by: ocfs_create_modify_file(), ocfs_set_rename_information()
- */
-int old_ocfs_start_trans (ocfs_super * osb)
-{
- LOG_ENTRY_ARGS ("(0x%08x)\n", osb);
-
- down (&osb->trans_lock);
- osb->curr_trans_id = osb->vol_node_map.largest_seq_num;
-
- if (osb->needs_flush) {
- int i=0;
- atomic_set (&osb->flush_event_woken, 1);
- wake_up (&osb->flush_event);
- while (osb->needs_flush && i<300) {
- ocfs_sleep (100); /* in ms */
- i++;
- }
- }
-
- osb->trans_in_progress = true;
-
- LOG_EXIT_STATUS (0);
- return 0;
-} /* old_ocfs_start_trans */
-
-/*
- * old_ocfs_commit_trans()
- *
- *
- * called by: ocfs_create_modify_file(), ocfs_set_rename_information()
- */
-int old_ocfs_commit_trans (ocfs_super * osb, __u64 trans_id)
-{
- int status = 0;
-// __u64 offset = 0;
-// __u32 log_type;
-
- LOG_ENTRY_ARGS ("(0x%08x, %u.%u)\n", osb, HI (trans_id), LO (trans_id));
-#if 0
- /* Log to the file for multiple transactions... */
- status = ocfs_extend_system_file (osb,
- (LOG_FILE_BASE_ID + osb->node_num), offset, NULL, NULL);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- log_type = LOG_CLEANUP;
-
- status = ocfs_process_log (osb, trans_id, osb->node_num, &log_type);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- status = ocfs_extend_system_file (osb,
- (CLEANUP_FILE_BASE_ID + osb->node_num), offset, NULL, NULL);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-#endif
- osb->curr_trans_id = -1;
-
-//finally:
- osb->trans_in_progress = false;
- up (&osb->trans_lock);
-
- LOG_EXIT_STATUS (status);
- return status;
-} /* old_ocfs_commit_trans */
-
-/*
- * old_ocfs_abort_trans()
- *
- *
- * called by: ocfs_create_modify_file(), ocfs_set_rename_information()
- */
-int old_ocfs_abort_trans (ocfs_super * osb, __u64 trans_id)
-{
- int status = 0;
-// __u64 offset = 0;
-// __u32 log_type;
-
- LOG_ENTRY_ARGS ("(0x%08x, %u.%u)\n", osb, HI (trans_id), LO (trans_id));
-#if 0
- /* Read the log file and free up stf... */
- log_type = LOG_RECOVER;
-
- status = ocfs_process_log (osb, trans_id, osb->node_num, &log_type);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- status = ocfs_extend_system_file (osb,
- (LOG_FILE_BASE_ID + osb->node_num), offset, NULL, NULL);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- status = ocfs_extend_system_file (osb,
- (CLEANUP_FILE_BASE_ID + osb->node_num), offset, NULL, NULL);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-#endif
- osb->curr_trans_id = -1;
-
-//finally:
- osb->trans_in_progress = false;
- up (&osb->trans_lock);
-
- LOG_EXIT_STATUS (status);
- return status;
-} /* old_ocfs_abort_trans */
-
-/*
- * ocfs_free_node_block()
- *
- */
-int ocfs_free_node_block (ocfs_super * osb, __u64 file_off, __u64 Length, __u32 NodeNum, __u32 Type)
-{
- int status = 0;
- int tmpstat;
- __u64 fileSize = 0;
- __u64 offset = 0;
- __u64 lockId = 0;
- __u64 allocSize = 0;
- ocfs_alloc_bm DirAllocBitmap;
- __u32 foundBit = -1;
- __u32 blockSize = 0;
- bool bLockAcquired = false;
- ocfs_lock_res *lockres = NULL;
- __u32 fileId = 0;
- struct buffer_head *bh = NULL;
- bool needs_uninit = false;
-
- LOG_ENTRY ();
-
- if (Type == DISK_ALLOC_DIR_NODE) {
- fileId = OCFS_FILE_DIR_ALLOC_BITMAP + NodeNum;
- blockSize = (__u32) osb->vol_layout.dir_node_size;
- } else if (Type == DISK_ALLOC_EXTENT_NODE) {
- fileId = OCFS_FILE_FILE_ALLOC_BITMAP + NodeNum;
- blockSize = (__u32) osb->vol_layout.file_node_size;
- }
-
- /* Allocate a block of size blocksize from the relevant file/bitmap */
-
- lockId = (fileId * OCFS_SECTOR_SIZE) + osb->vol_layout.root_int_off;
-
- /* Get a lock on the file */
- status = ocfs_acquire_lock (osb, lockId, OCFS_DLM_EXCLUSIVE_LOCK,
- FLAG_FILE_CREATE, &lockres, &bh);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto leave;
- }
- bLockAcquired = true;
-
- /* Read in the bitmap file for the dir alloc and look for the
- * required space, if found */
- status = ocfs_get_system_file_size (osb, fileId, &fileSize, &allocSize);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto leave;
- }
-
- /* shouldn't we be using fileSize in these instead? */
- ocfs_initialize_bitmap (&DirAllocBitmap, fileSize * 8, allocSize * 8);
- needs_uninit = true;
-
- /* TODO: Maybe offset should only be where we start caring,
- * and instead of allocSize, we should only read as much as we
- * need... */
- status = ocfs_read_system_file (osb, fileId, DirAllocBitmap.chunk,
- allocSize, offset);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto leave;
- }
-
- foundBit = (__u32) (file_off / blockSize);
- ocfs_clear_bits (&DirAllocBitmap, (__u32) foundBit, (__u32) Length);
-
- status = ocfs_write_system_file (osb, fileId, DirAllocBitmap.chunk, allocSize, offset);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto leave;
- }
-
- leave:
- if (needs_uninit)
- ocfs_uninitialize_bitmap(&DirAllocBitmap);
-
- if (bLockAcquired) {
- tmpstat = ocfs_release_lock (osb, lockId, OCFS_DLM_EXCLUSIVE_LOCK,
- FLAG_FILE_CREATE, lockres, bh);
- if (tmpstat < 0)
- LOG_ERROR_STATUS (tmpstat);
- }
-
- if (bh != NULL)
- brelse(bh);
-
- ocfs_put_lockres (lockres);
- LOG_EXIT_STATUS (0);
- return 0;
-} /* ocfs_free_node_block */
-
-/*
- * old_ocfs_recover_vol()
- *
- * called by: ocfs_process_record(), ocfs_disk_request_vote(),
- * ocfs_acquire_lock(), ocfs_check_volume(), ocfs_nm_thread()
- */
-int old_ocfs_recover_vol (ocfs_super * osb, __u64 node_num)
-{
- int status = 0;
-#if 0
- int tmpstat;
- bool recovery_lock = false;
- bool lock_acq = false;
- __u64 lock_id = 0;
- __u64 file_size = 0;
- __u64 alloc_size = 0;
- ocfs_lock_res *lock_res = NULL;
- __u32 log_type;
- __u64 trans_id = 0;
- __u64 cleanup_file_size = 0;
- __u32 file_id;
- struct buffer_head *bh = NULL;
-#endif
- LOG_ENTRY_ARGS ("(0x%08x, %u.%u)\n", osb, HI (node_num), LO (node_num));
- /* function disabled for now. We want to keep the code here
- * just so we have a record of what it used to do. */
-#if 0
- if (!IS_VALID_NODE_NUM(node_num)) {
- LOG_ERROR_STATUS (status = -EINVAL);
- goto finally;
- }
-
- /* Grab the local recovery resource to ensure no other thread comes */
- /* in from this node for recovery */
- ocfs_down_sem (&(osb->recovery_lock), true);
- recovery_lock = true;
-
- if (osb->node_recovering == node_num) {
- goto finally;
- }
-
- /* Now reset the publish sector to have the dirty bit not set... */
- status = ocfs_reset_publish (osb, node_num);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- file_id = (__u32) (LOG_FILE_BASE_ID + node_num);
-
- /* Read in the the recovery log */
- status = ocfs_get_system_file_size (osb, file_id, &file_size,
- &alloc_size);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- file_id = (__u32) (CLEANUP_FILE_BASE_ID + node_num);
- status = ocfs_get_system_file_size (osb, file_id, &cleanup_file_size,
- &alloc_size);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- if ((file_size == 0) && (cleanup_file_size == 0)) {
- /* Nothing to do so ... */
- /*
- ** Read the log file and go back to the last checkpoint,
- ** start of file for us. Read the logs for the transaction
- ** being recovered and un
- */
-
- osb->node_recovering = OCFS_INVALID_NODE_NUM;
- status = 0;
- goto finally;
- }
-
- osb->node_recovering = node_num;
- osb->vol_state = VOLUME_IN_RECOVERY;
-
- /*
- ** Grab the lock on the log file for the node which needs recovery,
- ** this ensures nobody else in the cluster process the recovery
- */
- lock_id = ((LOG_FILE_BASE_ID + node_num) * osb->sect_size) +
- osb->vol_layout.root_int_off;
-
- status = ocfs_acquire_lock (osb, lock_id, OCFS_DLM_EXCLUSIVE_LOCK,
- FLAG_FILE_CREATE, &lock_res, &bh);
- if (status < 0) {
- goto finally;
- }
-
- lock_acq = true;
- log_type = LOG_RECOVER;
-
- status = ocfs_process_log (osb, trans_id, node_num, &log_type);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
-
- /*
- ** If a cleanup file exists we should just reset the file size
- ** if we aborted the transaction otherwise process the cleanup file....
- */
- if (log_type == LOG_CLEANUP) {
- status = ocfs_process_log (osb, trans_id, node_num,
- &log_type);
- if (status < 0) {
- LOG_ERROR_STATUS (status);
- goto finally;
- }
- }
-
- /* Read the log file and go back to the last checkpoint, */
- /* start of file for us. Read the logs for the transaction */
- /* being recovered and un */
- osb->node_recovering = OCFS_INVALID_NODE_NUM;
-
- /* The vol state migh thave to turn inti flags... */
- osb->vol_state = VOLUME_ENABLED;
-
- if (recovery_lock) {
- ocfs_up_sem (&(osb->recovery_lock));
- recovery_lock = false;
- }
-
- finally:
- if (recovery_lock) {
- ocfs_up_sem (&(osb->recovery_lock));
- recovery_lock = false;
- }
-
- if (lock_acq) {
- tmpstat = ocfs_release_lock (osb, lock_id,
- OCFS_DLM_EXCLUSIVE_LOCK,
- FLAG_FILE_CREATE, lock_res, bh);
- if (tmpstat < 0)
- LOG_ERROR_STATUS (tmpstat);
- }
- if (bh)
- brelse(bh);
-
- ocfs_put_lockres (lock_res);
-#endif
- LOG_EXIT_STATUS (status);
- return (status);
-} /* old_ocfs_recover_vol */
-
-#endif /* COMMENT IT ALL OUT!!! */
More information about the Ocfs2-commits
mailing list